3 * Copyright (c) 1991-1999, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "It all comes from here, the stench and the peril." --Frodo
18 static void check_uni _((void));
19 static void force_next _((I32 type));
20 static char *force_version _((char *start));
21 static char *force_word _((char *start, int token, int check_keyword, int allow_pack, int allow_tick));
22 static SV *tokeq _((SV *sv));
23 static char *scan_const _((char *start));
24 static char *scan_formline _((char *s));
25 static char *scan_heredoc _((char *s));
26 static char *scan_ident _((char *s, char *send, char *dest, STRLEN destlen,
28 static char *scan_inputsymbol _((char *start));
29 static char *scan_pat _((char *start, I32 type));
30 static char *scan_str _((char *start));
31 static char *scan_subst _((char *start));
32 static char *scan_trans _((char *start));
33 static char *scan_word _((char *s, char *dest, STRLEN destlen,
34 int allow_package, STRLEN *slp));
35 static char *skipspace _((char *s));
36 static void checkcomma _((char *s, char *name, char *what));
37 static void force_ident _((char *s, int kind));
38 static void incline _((char *s));
39 static int intuit_method _((char *s, GV *gv));
40 static int intuit_more _((char *s));
41 static I32 lop _((I32 f, expectation x, char *s));
42 static void missingterm _((char *s));
43 static void no_op _((char *what, char *s));
44 static void set_csh _((void));
45 static I32 sublex_done _((void));
46 static I32 sublex_push _((void));
47 static I32 sublex_start _((void));
49 static int uni _((I32 f, char *s));
51 static char * filter_gets _((SV *sv, PerlIO *fp, STRLEN append));
52 static void restore_rsfp _((void *f));
53 static SV *new_constant _((char *s, STRLEN len, char *key, SV *sv, SV *pv, char *type));
54 static void restore_expect _((void *e));
55 static void restore_lex_expect _((void *e));
57 static char *PL_super_bufptr;
58 static char *PL_super_bufend;
59 #endif /* PERL_OBJECT */
61 static char ident_too_long[] = "Identifier too long";
63 /* The following are arranged oddly so that the guard on the switch statement
64 * can get by with a single comparison (if the compiler is smart enough).
67 /* #define LEX_NOTPARSING 11 is done in perl.h. */
70 #define LEX_INTERPNORMAL 9
71 #define LEX_INTERPCASEMOD 8
72 #define LEX_INTERPPUSH 7
73 #define LEX_INTERPSTART 6
74 #define LEX_INTERPEND 5
75 #define LEX_INTERPENDMAYBE 4
76 #define LEX_INTERPCONCAT 3
77 #define LEX_INTERPCONST 2
78 #define LEX_FORMLINE 1
79 #define LEX_KNOWNEXT 0
88 /* XXX If this causes problems, set i_unistd=undef in the hint file. */
90 # include <unistd.h> /* Needed for execv() */
103 #define CLINE (PL_copline = (PL_curcop->cop_line < PL_copline ? PL_curcop->cop_line : PL_copline))
105 #define TOKEN(retval) return (PL_bufptr = s,(int)retval)
106 #define OPERATOR(retval) return (PL_expect = XTERM,PL_bufptr = s,(int)retval)
107 #define AOPERATOR(retval) return ao((PL_expect = XTERM,PL_bufptr = s,(int)retval))
108 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s,(int)retval)
109 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s,(int)retval)
110 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s,(int)retval)
111 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR,PL_bufptr = s,(int)retval)
112 #define LOOPX(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LOOPEX)
113 #define FTST(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)UNIOP)
114 #define FUN0(f) return(yylval.ival = f,PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC0)
115 #define FUN1(f) return(yylval.ival = f,PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC1)
116 #define BOop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)BITOROP))
117 #define BAop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)BITANDOP))
118 #define SHop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)SHIFTOP))
119 #define PWop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)POWOP))
120 #define PMop(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)MATCHOP)
121 #define Aop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)ADDOP))
122 #define Mop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)MULOP))
123 #define Eop(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)EQOP)
124 #define Rop(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)RELOP)
126 /* This bit of chicanery makes a unary function followed by
127 * a parenthesis into a function with one argument, highest precedence.
129 #define UNI(f) return(yylval.ival = f, \
132 PL_last_uni = PL_oldbufptr, \
133 PL_last_lop_op = f, \
134 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
136 #define UNIBRACK(f) return(yylval.ival = f, \
138 PL_last_uni = PL_oldbufptr, \
139 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
141 /* grandfather return to old style */
142 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
147 if (*PL_bufptr == '=') {
149 if (toketype == ANDAND)
150 yylval.ival = OP_ANDASSIGN;
151 else if (toketype == OROR)
152 yylval.ival = OP_ORASSIGN;
159 no_op(char *what, char *s)
161 char *oldbp = PL_bufptr;
162 bool is_first = (PL_oldbufptr == PL_linestart);
165 yywarn(form("%s found where operator expected", what));
167 warn("\t(Missing semicolon on previous line?)\n");
168 else if (PL_oldoldbufptr && isIDFIRST(*PL_oldoldbufptr)) {
170 for (t = PL_oldoldbufptr; *t && (isALNUM(*t) || *t == ':'); t++) ;
171 if (t < PL_bufptr && isSPACE(*t))
172 warn("\t(Do you need to predeclare %.*s?)\n",
173 t - PL_oldoldbufptr, PL_oldoldbufptr);
177 warn("\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
187 char *nl = strrchr(s,'\n');
193 iscntrl(PL_multi_close)
195 PL_multi_close < 32 || PL_multi_close == 127
199 tmpbuf[1] = toCTRL(PL_multi_close);
205 *tmpbuf = PL_multi_close;
209 q = strchr(s,'"') ? '\'' : '"';
210 croak("Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
217 warn("Use of %s is deprecated", s);
223 deprecate("comma-less variable list");
229 win32_textfilter(int idx, SV *sv, int maxlen)
231 I32 count = FILTER_READ(idx+1, sv, maxlen);
232 if (count > 0 && !maxlen)
233 win32_strip_return(sv);
246 SAVEI32(PL_lex_dojoin);
247 SAVEI32(PL_lex_brackets);
248 SAVEI32(PL_lex_fakebrack);
249 SAVEI32(PL_lex_casemods);
250 SAVEI32(PL_lex_starts);
251 SAVEI32(PL_lex_state);
252 SAVESPTR(PL_lex_inpat);
253 SAVEI32(PL_lex_inwhat);
254 SAVEI16(PL_curcop->cop_line);
257 SAVEPPTR(PL_oldbufptr);
258 SAVEPPTR(PL_oldoldbufptr);
259 SAVEPPTR(PL_linestart);
260 SAVESPTR(PL_linestr);
261 SAVEPPTR(PL_lex_brackstack);
262 SAVEPPTR(PL_lex_casestack);
263 SAVEDESTRUCTOR(restore_rsfp, PL_rsfp);
264 SAVESPTR(PL_lex_stuff);
265 SAVEI32(PL_lex_defer);
266 SAVESPTR(PL_lex_repl);
267 SAVEDESTRUCTOR(restore_expect, PL_tokenbuf + PL_expect); /* encode as pointer */
268 SAVEDESTRUCTOR(restore_lex_expect, PL_tokenbuf + PL_expect);
270 PL_lex_state = LEX_NORMAL;
274 PL_lex_fakebrack = 0;
275 New(899, PL_lex_brackstack, 120, char);
276 New(899, PL_lex_casestack, 12, char);
277 SAVEFREEPV(PL_lex_brackstack);
278 SAVEFREEPV(PL_lex_casestack);
280 *PL_lex_casestack = '\0';
283 PL_lex_stuff = Nullsv;
284 PL_lex_repl = Nullsv;
288 if (SvREADONLY(PL_linestr))
289 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
290 s = SvPV(PL_linestr, len);
291 if (len && s[len-1] != ';') {
292 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
293 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
294 sv_catpvn(PL_linestr, "\n;", 2);
296 SvTEMP_off(PL_linestr);
297 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
298 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
300 PL_rs = newSVpv("\n", 1);
307 PL_doextract = FALSE;
311 restore_rsfp(void *f)
313 PerlIO *fp = (PerlIO*)f;
315 if (PL_rsfp == PerlIO_stdin())
316 PerlIO_clearerr(PL_rsfp);
317 else if (PL_rsfp && (PL_rsfp != fp))
318 PerlIO_close(PL_rsfp);
323 restore_expect(void *e)
325 /* a safe way to store a small integer in a pointer */
326 PL_expect = (expectation)((char *)e - PL_tokenbuf);
330 restore_lex_expect(void *e)
332 /* a safe way to store a small integer in a pointer */
333 PL_lex_expect = (expectation)((char *)e - PL_tokenbuf);
345 PL_curcop->cop_line++;
348 while (*s == ' ' || *s == '\t') s++;
349 if (strnEQ(s, "line ", 5)) {
358 while (*s == ' ' || *s == '\t')
360 if (*s == '"' && (t = strchr(s+1, '"')))
364 return; /* false alarm */
365 for (t = s; !isSPACE(*t); t++) ;
370 PL_curcop->cop_filegv = gv_fetchfile(s);
372 PL_curcop->cop_filegv = gv_fetchfile(PL_origfilename);
374 PL_curcop->cop_line = atoi(n)-1;
378 skipspace(register char *s)
381 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
382 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
388 while (s < PL_bufend && isSPACE(*s)) {
389 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
392 if (s < PL_bufend && *s == '#') {
393 while (s < PL_bufend && *s != '\n')
397 if (PL_in_eval && !PL_rsfp) {
403 if (s < PL_bufend || !PL_rsfp || PL_lex_state != LEX_NORMAL)
405 if ((s = filter_gets(PL_linestr, PL_rsfp, (prevlen = SvCUR(PL_linestr)))) == Nullch) {
406 if (PL_minus_n || PL_minus_p) {
407 sv_setpv(PL_linestr,PL_minus_p ?
408 ";}continue{print or die qq(-p destination: $!\\n)" :
410 sv_catpv(PL_linestr,";}");
411 PL_minus_n = PL_minus_p = 0;
414 sv_setpv(PL_linestr,";");
415 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
416 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
417 if (PL_preprocess && !PL_in_eval)
418 (void)PerlProc_pclose(PL_rsfp);
419 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
420 PerlIO_clearerr(PL_rsfp);
422 (void)PerlIO_close(PL_rsfp);
426 PL_linestart = PL_bufptr = s + prevlen;
427 PL_bufend = s + SvCUR(PL_linestr);
430 if (PERLDB_LINE && PL_curstash != PL_debstash) {
431 SV *sv = NEWSV(85,0);
433 sv_upgrade(sv, SVt_PVMG);
434 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
435 av_store(GvAV(PL_curcop->cop_filegv),(I32)PL_curcop->cop_line,sv);
446 if (PL_oldoldbufptr != PL_last_uni)
448 while (isSPACE(*PL_last_uni))
450 for (s = PL_last_uni; isALNUM(*s) || *s == '-'; s++) ;
451 if ((t = strchr(s, '(')) && t < PL_bufptr)
455 warn("Warning: Use of \"%s\" without parens is ambiguous", PL_last_uni);
462 #define UNI(f) return uni(f,s)
470 PL_last_uni = PL_oldbufptr;
481 #endif /* CRIPPLED_CC */
483 #define LOP(f,x) return lop(f,x,s)
486 lop(I32 f, expectation x, char *s)
493 PL_last_lop = PL_oldbufptr;
509 PL_nexttype[PL_nexttoke] = type;
511 if (PL_lex_state != LEX_KNOWNEXT) {
512 PL_lex_defer = PL_lex_state;
513 PL_lex_expect = PL_expect;
514 PL_lex_state = LEX_KNOWNEXT;
519 force_word(register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
524 start = skipspace(start);
527 (allow_pack && *s == ':') ||
528 (allow_initial_tick && *s == '\'') )
530 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
531 if (check_keyword && keyword(PL_tokenbuf, len))
533 if (token == METHOD) {
538 PL_expect = XOPERATOR;
543 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(PL_tokenbuf,0));
544 PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
551 force_ident(register char *s, int kind)
554 OP* o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
555 PL_nextval[PL_nexttoke].opval = o;
558 dTHR; /* just for in_eval */
559 o->op_private = OPpCONST_ENTERED;
560 /* XXX see note in pp_entereval() for why we forgo typo
561 warnings if the symbol must be introduced in an eval.
563 gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
564 kind == '$' ? SVt_PV :
565 kind == '@' ? SVt_PVAV :
566 kind == '%' ? SVt_PVHV :
574 force_version(char *s)
576 OP *version = Nullop;
580 /* default VERSION number -- GBARR */
585 for( d=s, c = 1; isDIGIT(*d) || *d == '_' || (*d == '.' && c--); d++);
586 if((*d == ';' || isSPACE(*d)) && *(skipspace(d)) != ',') {
588 /* real VERSION number -- GBARR */
589 version = yylval.opval;
593 /* NOTE: The parser sees the package name and the VERSION swapped */
594 PL_nextval[PL_nexttoke].opval = version;
612 s = SvPV_force(sv, len);
616 while (s < send && *s != '\\')
621 if ( PL_hints & HINT_NEW_STRING )
622 pv = sv_2mortal(newSVpv(SvPVX(pv), len));
625 if (s + 1 < send && (s[1] == '\\'))
626 s++; /* all that, just for this */
631 SvCUR_set(sv, d - SvPVX(sv));
633 if ( PL_hints & HINT_NEW_STRING )
634 return new_constant(NULL, 0, "q", sv, pv, "q");
641 register I32 op_type = yylval.ival;
643 if (op_type == OP_NULL) {
644 yylval.opval = PL_lex_op;
648 if (op_type == OP_CONST || op_type == OP_READLINE) {
649 SV *sv = tokeq(PL_lex_stuff);
651 if (SvTYPE(sv) == SVt_PVIV) {
652 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
658 nsv = newSVpv(p, len);
662 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
663 PL_lex_stuff = Nullsv;
667 PL_sublex_info.super_state = PL_lex_state;
668 PL_sublex_info.sub_inwhat = op_type;
669 PL_sublex_info.sub_op = PL_lex_op;
670 PL_lex_state = LEX_INTERPPUSH;
674 yylval.opval = PL_lex_op;
688 PL_lex_state = PL_sublex_info.super_state;
689 SAVEI32(PL_lex_dojoin);
690 SAVEI32(PL_lex_brackets);
691 SAVEI32(PL_lex_fakebrack);
692 SAVEI32(PL_lex_casemods);
693 SAVEI32(PL_lex_starts);
694 SAVEI32(PL_lex_state);
695 SAVESPTR(PL_lex_inpat);
696 SAVEI32(PL_lex_inwhat);
697 SAVEI16(PL_curcop->cop_line);
699 SAVEPPTR(PL_oldbufptr);
700 SAVEPPTR(PL_oldoldbufptr);
701 SAVEPPTR(PL_linestart);
702 SAVESPTR(PL_linestr);
703 SAVEPPTR(PL_lex_brackstack);
704 SAVEPPTR(PL_lex_casestack);
706 PL_linestr = PL_lex_stuff;
707 PL_lex_stuff = Nullsv;
709 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
710 PL_bufend += SvCUR(PL_linestr);
711 SAVEFREESV(PL_linestr);
713 PL_lex_dojoin = FALSE;
715 PL_lex_fakebrack = 0;
716 New(899, PL_lex_brackstack, 120, char);
717 New(899, PL_lex_casestack, 12, char);
718 SAVEFREEPV(PL_lex_brackstack);
719 SAVEFREEPV(PL_lex_casestack);
721 *PL_lex_casestack = '\0';
723 PL_lex_state = LEX_INTERPCONCAT;
724 PL_curcop->cop_line = PL_multi_start;
726 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
727 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
728 PL_lex_inpat = PL_sublex_info.sub_op;
730 PL_lex_inpat = Nullop;
738 if (!PL_lex_starts++) {
739 PL_expect = XOPERATOR;
740 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv("",0));
744 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
745 PL_lex_state = LEX_INTERPCASEMOD;
749 /* Is there a right-hand side to take care of? */
750 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
751 PL_linestr = PL_lex_repl;
753 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
754 PL_bufend += SvCUR(PL_linestr);
755 SAVEFREESV(PL_linestr);
756 PL_lex_dojoin = FALSE;
758 PL_lex_fakebrack = 0;
760 *PL_lex_casestack = '\0';
762 if (SvCOMPILED(PL_lex_repl)) {
763 PL_lex_state = LEX_INTERPNORMAL;
767 PL_lex_state = LEX_INTERPCONCAT;
768 PL_lex_repl = Nullsv;
773 PL_bufend = SvPVX(PL_linestr);
774 PL_bufend += SvCUR(PL_linestr);
775 PL_expect = XOPERATOR;
783 Extracts a pattern, double-quoted string, or transliteration. This
786 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
787 processing a pattern (PL_lex_inpat is true), a transliteration
788 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
790 Returns a pointer to the character scanned up to. Iff this is
791 advanced from the start pointer supplied (ie if anything was
792 successfully parsed), will leave an OP for the substring scanned
793 in yylval. Caller must intuit reason for not parsing further
794 by looking at the next characters herself.
798 double-quoted style: \r and \n
799 regexp special ones: \D \s
801 backrefs: \1 (deprecated in substitution replacements)
802 case and quoting: \U \Q \E
803 stops on @ and $, but not for $ as tail anchor
806 characters are VERY literal, except for - not at the start or end
807 of the string, which indicates a range. scan_const expands the
808 range to the full set of intermediate characters.
810 In double-quoted strings:
812 double-quoted style: \r and \n
814 backrefs: \1 (deprecated)
815 case and quoting: \U \Q \E
818 scan_const does *not* construct ops to handle interpolated strings.
819 It stops processing as soon as it finds an embedded $ or @ variable
820 and leaves it to the caller to work out what's going on.
822 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @:foo.
824 $ in pattern could be $foo or could be tail anchor. Assumption:
825 it's a tail anchor if $ is the last thing in the string, or if it's
826 followed by one of ")| \n\t"
828 \1 (backreferences) are turned into $1
830 The structure of the code is
831 while (there's a character to process) {
832 handle transliteration ranges
834 skip # initiated comments in //x patterns
835 check for embedded @foo
836 check for embedded scalars
838 leave intact backslashes from leave (below)
839 deprecate \1 in strings and sub replacements
840 handle string-changing backslashes \l \U \Q \E, etc.
841 switch (what was escaped) {
842 handle - in a transliteration (becomes a literal -)
843 handle \132 octal characters
844 handle 0x15 hex characters
845 handle \cV (control V)
846 handle printf backslashes (\f, \r, \n, etc)
849 } (end while character to read)
854 scan_const(char *start)
856 register char *send = PL_bufend; /* end of the constant */
857 SV *sv = NEWSV(93, send - start); /* sv for the constant */
858 register char *s = start; /* start of the constant */
859 register char *d = SvPVX(sv); /* destination for copies */
860 bool dorange = FALSE; /* are we in a translit range? */
863 /* leaveit is the set of acceptably-backslashed characters */
866 ? "\\.^$@AGZdDwWsSbB+*?|()-nrtfeaxcz0123456789[{]} \t\n\r\f\v#"
869 while (s < send || dorange) {
870 /* get transliterations out of the way (they're most literal) */
871 if (PL_lex_inwhat == OP_TRANS) {
872 /* expand a range A-Z to the full set of characters. AIE! */
874 I32 i; /* current expanded character */
875 I32 min; /* first character in range */
876 I32 max; /* last character in range */
878 i = d - SvPVX(sv); /* remember current offset */
879 SvGROW(sv, SvLEN(sv) + 256); /* expand the sv -- there'll never be more'n 256 chars in a range for it to grow by */
880 d = SvPVX(sv) + i; /* restore d after the grow potentially has changed the ptr */
881 d -= 2; /* eat the first char and the - */
883 min = (U8)*d; /* first char in range */
884 max = (U8)d[1]; /* last char in range */
887 if ((isLOWER(min) && isLOWER(max)) ||
888 (isUPPER(min) && isUPPER(max))) {
890 for (i = min; i <= max; i++)
894 for (i = min; i <= max; i++)
901 for (i = min; i <= max; i++)
904 /* mark the range as done, and continue */
909 /* range begins (ignore - as first or last char) */
910 else if (*s == '-' && s+1 < send && s != start) {
916 /* if we get here, we're not doing a transliteration */
918 /* skip for regexp comments /(?#comment)/ */
919 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
921 while (s < send && *s != ')')
923 } else if (s[2] == '{') { /* This should march regcomp.c */
925 char *regparse = s + 3;
928 while (count && (c = *regparse)) {
929 if (c == '\\' && regparse[1])
937 if (*regparse == ')')
940 yyerror("Sequence (?{...}) not terminated or not {}-balanced");
941 while (s < regparse && *s != ')')
946 /* likewise skip #-initiated comments in //x patterns */
947 else if (*s == '#' && PL_lex_inpat &&
948 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
949 while (s+1 < send && *s != '\n')
953 /* check for embedded arrays (@foo, @:foo, @'foo, @{foo}, @$foo) */
954 else if (*s == '@' && s[1] && (isALNUM(s[1]) || strchr(":'{$", s[1])))
957 /* check for embedded scalars. only stop if we're sure it's a
960 else if (*s == '$') {
961 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
963 if (s + 1 < send && !strchr("()| \n\t", s[1]))
964 break; /* in regexp, $ might be tail anchor */
968 if (*s == '\\' && s+1 < send) {
971 /* some backslashes we leave behind */
972 if (*s && strchr(leaveit, *s)) {
978 /* deprecate \1 in strings and substitution replacements */
979 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
980 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
983 warn("\\%c better written as $%c", *s, *s);
988 /* string-change backslash escapes */
989 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
994 /* if we get here, it's either a quoted -, or a digit */
997 /* quoted - in transliterations */
999 if (PL_lex_inwhat == OP_TRANS) {
1004 /* default action is to copy the quoted character */
1009 /* \132 indicates an octal constant */
1010 case '0': case '1': case '2': case '3':
1011 case '4': case '5': case '6': case '7':
1012 *d++ = scan_oct(s, 3, &len);
1016 /* \x24 indicates a hex constant */
1018 *d++ = scan_hex(++s, 2, &len);
1022 /* \c is a control character */
1036 /* printf-style backslashes, formfeeds, newlines, etc */
1062 } /* end if (backslash) */
1065 } /* while loop to process each character */
1067 /* terminate the string and set up the sv */
1069 SvCUR_set(sv, d - SvPVX(sv));
1072 /* shrink the sv if we allocated more than we used */
1073 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1074 SvLEN_set(sv, SvCUR(sv) + 1);
1075 Renew(SvPVX(sv), SvLEN(sv), char);
1078 /* return the substring (via yylval) only if we parsed anything */
1079 if (s > PL_bufptr) {
1080 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1081 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1083 ( PL_lex_inwhat == OP_TRANS
1085 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1088 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1094 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1096 intuit_more(register char *s)
1098 if (PL_lex_brackets)
1100 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1102 if (*s != '{' && *s != '[')
1107 /* In a pattern, so maybe we have {n,m}. */
1124 /* On the other hand, maybe we have a character class */
1127 if (*s == ']' || *s == '^')
1130 int weight = 2; /* let's weigh the evidence */
1132 unsigned char un_char = 255, last_un_char;
1133 char *send = strchr(s,']');
1134 char tmpbuf[sizeof PL_tokenbuf * 4];
1136 if (!send) /* has to be an expression */
1139 Zero(seen,256,char);
1142 else if (isDIGIT(*s)) {
1144 if (isDIGIT(s[1]) && s[2] == ']')
1150 for (; s < send; s++) {
1151 last_un_char = un_char;
1152 un_char = (unsigned char)*s;
1157 weight -= seen[un_char] * 10;
1158 if (isALNUM(s[1])) {
1159 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
1160 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
1165 else if (*s == '$' && s[1] &&
1166 strchr("[#!%*<>()-=",s[1])) {
1167 if (/*{*/ strchr("])} =",s[2]))
1176 if (strchr("wds]",s[1]))
1178 else if (seen['\''] || seen['"'])
1180 else if (strchr("rnftbxcav",s[1]))
1182 else if (isDIGIT(s[1])) {
1184 while (s[1] && isDIGIT(s[1]))
1194 if (strchr("aA01! ",last_un_char))
1196 if (strchr("zZ79~",s[1]))
1198 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
1199 weight -= 5; /* cope with negative subscript */
1202 if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) &&
1203 isALPHA(*s) && s[1] && isALPHA(s[1])) {
1208 if (keyword(tmpbuf, d - tmpbuf))
1211 if (un_char == last_un_char + 1)
1213 weight -= seen[un_char];
1218 if (weight >= 0) /* probably a character class */
1226 intuit_method(char *start, GV *gv)
1228 char *s = start + (*start == '$');
1229 char tmpbuf[sizeof PL_tokenbuf];
1237 if ((cv = GvCVu(gv))) {
1238 char *proto = SvPVX(cv);
1248 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
1249 if (*start == '$') {
1250 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
1255 return *s == '(' ? FUNCMETH : METHOD;
1257 if (!keyword(tmpbuf, len)) {
1258 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
1263 indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
1264 if (indirgv && GvCVu(indirgv))
1266 /* filehandle or package name makes it a method */
1267 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
1269 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
1270 return 0; /* no assumptions -- "=>" quotes bearword */
1272 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
1274 PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
1278 return *s == '(' ? FUNCMETH : METHOD;
1288 char *pdb = PerlEnv_getenv("PERL5DB");
1292 SETERRNO(0,SS$_NORMAL);
1293 return "BEGIN { require 'perl5db.pl' }";
1299 /* Encoded script support. filter_add() effectively inserts a
1300 * 'pre-processing' function into the current source input stream.
1301 * Note that the filter function only applies to the current source file
1302 * (e.g., it will not affect files 'require'd or 'use'd by this one).
1304 * The datasv parameter (which may be NULL) can be used to pass
1305 * private data to this instance of the filter. The filter function
1306 * can recover the SV using the FILTER_DATA macro and use it to
1307 * store private buffers and state information.
1309 * The supplied datasv parameter is upgraded to a PVIO type
1310 * and the IoDIRP field is used to store the function pointer.
1311 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
1312 * private use must be set using malloc'd pointers.
1315 static int filter_debug = 0;
1319 filter_add(filter_t funcp, SV *datasv)
1321 if (!funcp){ /* temporary handy debugging hack to be deleted */
1322 filter_debug = atoi((char*)datasv);
1325 if (!PL_rsfp_filters)
1326 PL_rsfp_filters = newAV();
1328 datasv = NEWSV(255,0);
1329 if (!SvUPGRADE(datasv, SVt_PVIO))
1330 die("Can't upgrade filter_add data to SVt_PVIO");
1331 IoDIRP(datasv) = (DIR*)funcp; /* stash funcp into spare field */
1334 warn("filter_add func %p (%s)", funcp, SvPV(datasv,n_a));
1336 av_unshift(PL_rsfp_filters, 1);
1337 av_store(PL_rsfp_filters, 0, datasv) ;
1342 /* Delete most recently added instance of this filter function. */
1344 filter_del(filter_t funcp)
1347 warn("filter_del func %p", funcp);
1348 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
1350 /* if filter is on top of stack (usual case) just pop it off */
1351 if (IoDIRP(FILTER_DATA(AvFILLp(PL_rsfp_filters))) == (DIR*)funcp){
1352 sv_free(av_pop(PL_rsfp_filters));
1356 /* we need to search for the correct entry and clear it */
1357 die("filter_del can only delete in reverse order (currently)");
1361 /* Invoke the n'th filter function for the current rsfp. */
1363 filter_read(int idx, SV *buf_sv, int maxlen)
1366 /* 0 = read one text line */
1371 if (!PL_rsfp_filters)
1373 if (idx > AvFILLp(PL_rsfp_filters)){ /* Any more filters? */
1374 /* Provide a default input filter to make life easy. */
1375 /* Note that we append to the line. This is handy. */
1377 warn("filter_read %d: from rsfp\n", idx);
1381 int old_len = SvCUR(buf_sv) ;
1383 /* ensure buf_sv is large enough */
1384 SvGROW(buf_sv, old_len + maxlen) ;
1385 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
1386 if (PerlIO_error(PL_rsfp))
1387 return -1; /* error */
1389 return 0 ; /* end of file */
1391 SvCUR_set(buf_sv, old_len + len) ;
1394 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
1395 if (PerlIO_error(PL_rsfp))
1396 return -1; /* error */
1398 return 0 ; /* end of file */
1401 return SvCUR(buf_sv);
1403 /* Skip this filter slot if filter has been deleted */
1404 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef){
1406 warn("filter_read %d: skipped (filter deleted)\n", idx);
1407 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
1409 /* Get function pointer hidden within datasv */
1410 funcp = (filter_t)IoDIRP(datasv);
1413 warn("filter_read %d: via function %p (%s)\n",
1414 idx, funcp, SvPV(datasv,n_a));
1416 /* Call function. The function is expected to */
1417 /* call "FILTER_READ(idx+1, buf_sv)" first. */
1418 /* Return: <0:error, =0:eof, >0:not eof */
1419 return (*funcp)(PERL_OBJECT_THIS_ idx, buf_sv, maxlen);
1423 filter_gets(register SV *sv, register PerlIO *fp, STRLEN append)
1426 if (!PL_rsfp_filters) {
1427 filter_add(win32_textfilter,NULL);
1430 if (PL_rsfp_filters) {
1433 SvCUR_set(sv, 0); /* start with empty line */
1434 if (FILTER_READ(0, sv, 0) > 0)
1435 return ( SvPVX(sv) ) ;
1440 return (sv_gets(sv, fp, append));
1445 static char* exp_name[] =
1446 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "TERMBLOCK" };
1449 EXT int yychar; /* last token */
1454 Works out what to call the token just pulled out of the input
1455 stream. The yacc parser takes care of taking the ops we return and
1456 stitching them into a tree.
1462 if read an identifier
1463 if we're in a my declaration
1464 croak if they tried to say my($foo::bar)
1465 build the ops for a my() declaration
1466 if it's an access to a my() variable
1467 are we in a sort block?
1468 croak if my($a); $a <=> $b
1469 build ops for access to a my() variable
1470 if in a dq string, and they've said @foo and we can't find @foo
1472 build ops for a bareword
1473 if we already built the token before, use it.
1487 /* check if there's an identifier for us to look at */
1488 if (PL_pending_ident) {
1489 /* pit holds the identifier we read and pending_ident is reset */
1490 char pit = PL_pending_ident;
1491 PL_pending_ident = 0;
1493 /* if we're in a my(), we can't allow dynamics here.
1494 $foo'bar has already been turned into $foo::bar, so
1495 just check for colons.
1497 if it's a legal name, the OP is a PADANY.
1500 if (strchr(PL_tokenbuf,':'))
1501 croak(no_myglob,PL_tokenbuf);
1503 yylval.opval = newOP(OP_PADANY, 0);
1504 yylval.opval->op_targ = pad_allocmy(PL_tokenbuf);
1509 build the ops for accesses to a my() variable.
1511 Deny my($a) or my($b) in a sort block, *if* $a or $b is
1512 then used in a comparison. This catches most, but not
1513 all cases. For instance, it catches
1514 sort { my($a); $a <=> $b }
1516 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
1517 (although why you'd do that is anyone's guess).
1520 if (!strchr(PL_tokenbuf,':')) {
1522 /* Check for single character per-thread SVs */
1523 if (PL_tokenbuf[0] == '$' && PL_tokenbuf[2] == '\0'
1524 && !isALPHA(PL_tokenbuf[1]) /* Rule out obvious non-threadsvs */
1525 && (tmp = find_threadsv(&PL_tokenbuf[1])) != NOT_IN_PAD)
1527 yylval.opval = newOP(OP_THREADSV, 0);
1528 yylval.opval->op_targ = tmp;
1531 #endif /* USE_THREADS */
1532 if ((tmp = pad_findmy(PL_tokenbuf)) != NOT_IN_PAD) {
1533 /* if it's a sort block and they're naming $a or $b */
1534 if (PL_last_lop_op == OP_SORT &&
1535 PL_tokenbuf[0] == '$' &&
1536 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
1539 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
1540 d < PL_bufend && *d != '\n';
1543 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
1544 croak("Can't use \"my %s\" in sort comparison",
1550 yylval.opval = newOP(OP_PADANY, 0);
1551 yylval.opval->op_targ = tmp;
1557 Whine if they've said @foo in a doublequoted string,
1558 and @foo isn't a variable we can find in the symbol
1561 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
1562 GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
1563 if (!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
1564 yyerror(form("In string, %s now must be written as \\%s",
1565 PL_tokenbuf, PL_tokenbuf));
1568 /* build ops for a bareword */
1569 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
1570 yylval.opval->op_private = OPpCONST_ENTERED;
1571 gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
1572 ((PL_tokenbuf[0] == '$') ? SVt_PV
1573 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
1578 /* no identifier pending identification */
1580 switch (PL_lex_state) {
1582 case LEX_NORMAL: /* Some compilers will produce faster */
1583 case LEX_INTERPNORMAL: /* code if we comment these out. */
1587 /* when we're already built the next token, just pull it out the queue */
1590 yylval = PL_nextval[PL_nexttoke];
1592 PL_lex_state = PL_lex_defer;
1593 PL_expect = PL_lex_expect;
1594 PL_lex_defer = LEX_NORMAL;
1596 return(PL_nexttype[PL_nexttoke]);
1598 /* interpolated case modifiers like \L \U, including \Q and \E.
1599 when we get here, PL_bufptr is at the \
1601 case LEX_INTERPCASEMOD:
1603 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
1604 croak("panic: INTERPCASEMOD");
1606 /* handle \E or end of string */
1607 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
1611 if (PL_lex_casemods) {
1612 oldmod = PL_lex_casestack[--PL_lex_casemods];
1613 PL_lex_casestack[PL_lex_casemods] = '\0';
1615 if (PL_bufptr != PL_bufend && strchr("LUQ", oldmod)) {
1617 PL_lex_state = LEX_INTERPCONCAT;
1621 if (PL_bufptr != PL_bufend)
1623 PL_lex_state = LEX_INTERPCONCAT;
1628 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
1629 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
1630 if (strchr("LU", *s) &&
1631 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U')))
1633 PL_lex_casestack[--PL_lex_casemods] = '\0';
1636 if (PL_lex_casemods > 10) {
1637 char* newlb = Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
1638 if (newlb != PL_lex_casestack) {
1640 PL_lex_casestack = newlb;
1643 PL_lex_casestack[PL_lex_casemods++] = *s;
1644 PL_lex_casestack[PL_lex_casemods] = '\0';
1645 PL_lex_state = LEX_INTERPCONCAT;
1646 PL_nextval[PL_nexttoke].ival = 0;
1649 PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
1651 PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
1653 PL_nextval[PL_nexttoke].ival = OP_LC;
1655 PL_nextval[PL_nexttoke].ival = OP_UC;
1657 PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
1659 croak("panic: yylex");
1662 if (PL_lex_starts) {
1671 case LEX_INTERPPUSH:
1672 return sublex_push();
1674 case LEX_INTERPSTART:
1675 if (PL_bufptr == PL_bufend)
1676 return sublex_done();
1678 PL_lex_dojoin = (*PL_bufptr == '@');
1679 PL_lex_state = LEX_INTERPNORMAL;
1680 if (PL_lex_dojoin) {
1681 PL_nextval[PL_nexttoke].ival = 0;
1684 PL_nextval[PL_nexttoke].opval = newOP(OP_THREADSV, 0);
1685 PL_nextval[PL_nexttoke].opval->op_targ = find_threadsv("\"");
1686 force_next(PRIVATEREF);
1688 force_ident("\"", '$');
1689 #endif /* USE_THREADS */
1690 PL_nextval[PL_nexttoke].ival = 0;
1692 PL_nextval[PL_nexttoke].ival = 0;
1694 PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
1697 if (PL_lex_starts++) {
1703 case LEX_INTERPENDMAYBE:
1704 if (intuit_more(PL_bufptr)) {
1705 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
1711 if (PL_lex_dojoin) {
1712 PL_lex_dojoin = FALSE;
1713 PL_lex_state = LEX_INTERPCONCAT;
1717 case LEX_INTERPCONCAT:
1719 if (PL_lex_brackets)
1720 croak("panic: INTERPCONCAT");
1722 if (PL_bufptr == PL_bufend)
1723 return sublex_done();
1725 if (SvIVX(PL_linestr) == '\'') {
1726 SV *sv = newSVsv(PL_linestr);
1729 else if ( PL_hints & HINT_NEW_RE )
1730 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
1731 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1735 s = scan_const(PL_bufptr);
1737 PL_lex_state = LEX_INTERPCASEMOD;
1739 PL_lex_state = LEX_INTERPSTART;
1742 if (s != PL_bufptr) {
1743 PL_nextval[PL_nexttoke] = yylval;
1746 if (PL_lex_starts++)
1756 PL_lex_state = LEX_NORMAL;
1757 s = scan_formline(PL_bufptr);
1758 if (!PL_lex_formbrack)
1764 PL_oldoldbufptr = PL_oldbufptr;
1767 PerlIO_printf(PerlIO_stderr(), "### Tokener expecting %s at %s\n", exp_name[PL_expect], s);
1773 croak("Unrecognized character \\%03o", *s & 255);
1776 goto fake_eof; /* emulate EOF on ^D or ^Z */
1781 if (PL_lex_brackets)
1782 yyerror("Missing right bracket");
1785 if (s++ < PL_bufend)
1786 goto retry; /* ignore stray nulls */
1789 if (!PL_in_eval && !PL_preambled) {
1790 PL_preambled = TRUE;
1791 sv_setpv(PL_linestr,incl_perldb());
1792 if (SvCUR(PL_linestr))
1793 sv_catpv(PL_linestr,";");
1795 while(AvFILLp(PL_preambleav) >= 0) {
1796 SV *tmpsv = av_shift(PL_preambleav);
1797 sv_catsv(PL_linestr, tmpsv);
1798 sv_catpv(PL_linestr, ";");
1801 sv_free((SV*)PL_preambleav);
1802 PL_preambleav = NULL;
1804 if (PL_minus_n || PL_minus_p) {
1805 sv_catpv(PL_linestr, "LINE: while (<>) {");
1807 sv_catpv(PL_linestr,"chomp;");
1809 GV* gv = gv_fetchpv("::F", TRUE, SVt_PVAV);
1811 GvIMPORTED_AV_on(gv);
1813 if (strchr("/'\"", *PL_splitstr)
1814 && strchr(PL_splitstr + 1, *PL_splitstr))
1815 sv_catpvf(PL_linestr, "@F=split(%s);", PL_splitstr);
1818 s = "'~#\200\1'"; /* surely one char is unused...*/
1819 while (s[1] && strchr(PL_splitstr, *s)) s++;
1821 sv_catpvf(PL_linestr, "@F=split(%s%c",
1822 "q" + (delim == '\''), delim);
1823 for (s = PL_splitstr; *s; s++) {
1825 sv_catpvn(PL_linestr, "\\", 1);
1826 sv_catpvn(PL_linestr, s, 1);
1828 sv_catpvf(PL_linestr, "%c);", delim);
1832 sv_catpv(PL_linestr,"@F=split(' ');");
1835 sv_catpv(PL_linestr, "\n");
1836 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
1837 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1838 if (PERLDB_LINE && PL_curstash != PL_debstash) {
1839 SV *sv = NEWSV(85,0);
1841 sv_upgrade(sv, SVt_PVMG);
1842 sv_setsv(sv,PL_linestr);
1843 av_store(GvAV(PL_curcop->cop_filegv),(I32)PL_curcop->cop_line,sv);
1848 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
1851 if (PL_preprocess && !PL_in_eval)
1852 (void)PerlProc_pclose(PL_rsfp);
1853 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
1854 PerlIO_clearerr(PL_rsfp);
1856 (void)PerlIO_close(PL_rsfp);
1858 PL_doextract = FALSE;
1860 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
1861 sv_setpv(PL_linestr,PL_minus_p ? ";}continue{print" : "");
1862 sv_catpv(PL_linestr,";}");
1863 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
1864 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1865 PL_minus_n = PL_minus_p = 0;
1868 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
1869 sv_setpv(PL_linestr,"");
1870 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
1873 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
1874 PL_doextract = FALSE;
1876 /* Incest with pod. */
1877 if (*s == '=' && strnEQ(s, "=cut", 4)) {
1878 sv_setpv(PL_linestr, "");
1879 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
1880 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1881 PL_doextract = FALSE;
1885 } while (PL_doextract);
1886 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
1887 if (PERLDB_LINE && PL_curstash != PL_debstash) {
1888 SV *sv = NEWSV(85,0);
1890 sv_upgrade(sv, SVt_PVMG);
1891 sv_setsv(sv,PL_linestr);
1892 av_store(GvAV(PL_curcop->cop_filegv),(I32)PL_curcop->cop_line,sv);
1894 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1895 if (PL_curcop->cop_line == 1) {
1896 while (s < PL_bufend && isSPACE(*s))
1898 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
1902 if (*s == '#' && *(s+1) == '!')
1904 #ifdef ALTERNATE_SHEBANG
1906 static char as[] = ALTERNATE_SHEBANG;
1907 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
1908 d = s + (sizeof(as) - 1);
1910 #endif /* ALTERNATE_SHEBANG */
1919 while (*d && !isSPACE(*d))
1923 #ifdef ARG_ZERO_IS_SCRIPT
1924 if (ipathend > ipath) {
1926 * HP-UX (at least) sets argv[0] to the script name,
1927 * which makes $^X incorrect. And Digital UNIX and Linux,
1928 * at least, set argv[0] to the basename of the Perl
1929 * interpreter. So, having found "#!", we'll set it right.
1931 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV));
1932 assert(SvPOK(x) || SvGMAGICAL(x));
1933 if (sv_eq(x, GvSV(PL_curcop->cop_filegv))) {
1934 sv_setpvn(x, ipath, ipathend - ipath);
1937 TAINT_NOT; /* $^X is always tainted, but that's OK */
1939 #endif /* ARG_ZERO_IS_SCRIPT */
1944 d = instr(s,"perl -");
1946 d = instr(s,"perl");
1947 #ifdef ALTERNATE_SHEBANG
1949 * If the ALTERNATE_SHEBANG on this system starts with a
1950 * character that can be part of a Perl expression, then if
1951 * we see it but not "perl", we're probably looking at the
1952 * start of Perl code, not a request to hand off to some
1953 * other interpreter. Similarly, if "perl" is there, but
1954 * not in the first 'word' of the line, we assume the line
1955 * contains the start of the Perl program.
1957 if (d && *s != '#') {
1959 while (*c && !strchr("; \t\r\n\f\v#", *c))
1962 d = Nullch; /* "perl" not in first word; ignore */
1964 *s = '#'; /* Don't try to parse shebang line */
1966 #endif /* ALTERNATE_SHEBANG */
1971 !instr(s,"indir") &&
1972 instr(PL_origargv[0],"perl"))
1978 while (s < PL_bufend && isSPACE(*s))
1980 if (s < PL_bufend) {
1981 Newz(899,newargv,PL_origargc+3,char*);
1983 while (s < PL_bufend && !isSPACE(*s))
1986 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
1989 newargv = PL_origargv;
1991 PerlProc_execv(ipath, newargv);
1992 croak("Can't exec %s", ipath);
1995 U32 oldpdb = PL_perldb;
1996 bool oldn = PL_minus_n;
1997 bool oldp = PL_minus_p;
1999 while (*d && !isSPACE(*d)) d++;
2000 while (*d == ' ' || *d == '\t') d++;
2004 if (*d == 'M' || *d == 'm') {
2006 while (*d && !isSPACE(*d)) d++;
2007 croak("Too late for \"-%.*s\" option",
2010 d = moreswitches(d);
2012 if (PERLDB_LINE && !oldpdb ||
2013 ( PL_minus_n || PL_minus_p ) && !(oldn || oldp) )
2014 /* if we have already added "LINE: while (<>) {",
2015 we must not do it again */
2017 sv_setpv(PL_linestr, "");
2018 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2019 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2020 PL_preambled = FALSE;
2022 (void)gv_fetchfile(PL_origfilename);
2029 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2031 PL_lex_state = LEX_FORMLINE;
2036 #ifdef PERL_STRICT_CR
2037 warn("Illegal character \\%03o (carriage return)", '\r');
2039 "(Maybe you didn't strip carriage returns after a network transfer?)\n");
2041 case ' ': case '\t': case '\f': case 013:
2046 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
2048 while (s < d && *s != '\n')
2053 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2055 PL_lex_state = LEX_FORMLINE;
2065 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2070 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2073 if (strnEQ(s,"=>",2)) {
2074 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
2075 OPERATOR('-'); /* unary minus */
2077 PL_last_uni = PL_oldbufptr;
2078 PL_last_lop_op = OP_FTEREAD; /* good enough */
2080 case 'r': FTST(OP_FTEREAD);
2081 case 'w': FTST(OP_FTEWRITE);
2082 case 'x': FTST(OP_FTEEXEC);
2083 case 'o': FTST(OP_FTEOWNED);
2084 case 'R': FTST(OP_FTRREAD);
2085 case 'W': FTST(OP_FTRWRITE);
2086 case 'X': FTST(OP_FTREXEC);
2087 case 'O': FTST(OP_FTROWNED);
2088 case 'e': FTST(OP_FTIS);
2089 case 'z': FTST(OP_FTZERO);
2090 case 's': FTST(OP_FTSIZE);
2091 case 'f': FTST(OP_FTFILE);
2092 case 'd': FTST(OP_FTDIR);
2093 case 'l': FTST(OP_FTLINK);
2094 case 'p': FTST(OP_FTPIPE);
2095 case 'S': FTST(OP_FTSOCK);
2096 case 'u': FTST(OP_FTSUID);
2097 case 'g': FTST(OP_FTSGID);
2098 case 'k': FTST(OP_FTSVTX);
2099 case 'b': FTST(OP_FTBLK);
2100 case 'c': FTST(OP_FTCHR);
2101 case 't': FTST(OP_FTTTY);
2102 case 'T': FTST(OP_FTTEXT);
2103 case 'B': FTST(OP_FTBINARY);
2104 case 'M': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTMTIME);
2105 case 'A': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTATIME);
2106 case 'C': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTCTIME);
2108 croak("Unrecognized file test: -%c", (int)tmp);
2115 if (PL_expect == XOPERATOR)
2120 else if (*s == '>') {
2123 if (isIDFIRST(*s)) {
2124 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
2132 if (PL_expect == XOPERATOR)
2135 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2137 OPERATOR('-'); /* unary minus */
2144 if (PL_expect == XOPERATOR)
2149 if (PL_expect == XOPERATOR)
2152 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2158 if (PL_expect != XOPERATOR) {
2159 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
2160 PL_expect = XOPERATOR;
2161 force_ident(PL_tokenbuf, '*');
2174 if (PL_expect == XOPERATOR) {
2178 PL_tokenbuf[0] = '%';
2179 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
2180 if (!PL_tokenbuf[1]) {
2182 yyerror("Final % should be \\% or %name");
2185 PL_pending_ident = '%';
2207 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
2208 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
2213 if (PL_curcop->cop_line < PL_copline)
2214 PL_copline = PL_curcop->cop_line;
2225 if (PL_lex_brackets <= 0)
2226 yyerror("Unmatched right bracket");
2229 if (PL_lex_state == LEX_INTERPNORMAL) {
2230 if (PL_lex_brackets == 0) {
2231 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
2232 PL_lex_state = LEX_INTERPEND;
2239 if (PL_lex_brackets > 100) {
2240 char* newlb = Renew(PL_lex_brackstack, PL_lex_brackets + 1, char);
2241 if (newlb != PL_lex_brackstack) {
2243 PL_lex_brackstack = newlb;
2246 switch (PL_expect) {
2248 if (PL_lex_formbrack) {
2252 if (PL_oldoldbufptr == PL_last_lop)
2253 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
2255 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
2256 OPERATOR(HASHBRACK);
2258 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2261 PL_tokenbuf[0] = '\0';
2262 if (d < PL_bufend && *d == '-') {
2263 PL_tokenbuf[0] = '-';
2265 while (d < PL_bufend && (*d == ' ' || *d == '\t'))
2268 if (d < PL_bufend && isIDFIRST(*d)) {
2269 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
2271 while (d < PL_bufend && (*d == ' ' || *d == '\t'))
2274 char minus = (PL_tokenbuf[0] == '-');
2275 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
2282 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
2286 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
2291 if (PL_oldoldbufptr == PL_last_lop)
2292 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
2294 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
2297 OPERATOR(HASHBRACK);
2298 /* This hack serves to disambiguate a pair of curlies
2299 * as being a block or an anon hash. Normally, expectation
2300 * determines that, but in cases where we're not in a
2301 * position to expect anything in particular (like inside
2302 * eval"") we have to resolve the ambiguity. This code
2303 * covers the case where the first term in the curlies is a
2304 * quoted string. Most other cases need to be explicitly
2305 * disambiguated by prepending a `+' before the opening
2306 * curly in order to force resolution as an anon hash.
2308 * XXX should probably propagate the outer expectation
2309 * into eval"" to rely less on this hack, but that could
2310 * potentially break current behavior of eval"".
2314 if (*s == '\'' || *s == '"' || *s == '`') {
2315 /* common case: get past first string, handling escapes */
2316 for (t++; t < PL_bufend && *t != *s;)
2317 if (*t++ == '\\' && (*t == '\\' || *t == *s))
2321 else if (*s == 'q') {
2324 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
2325 && !isALNUM(*t)))) {
2327 char open, close, term;
2330 while (t < PL_bufend && isSPACE(*t))
2334 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
2338 for (t++; t < PL_bufend; t++) {
2339 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
2341 else if (*t == open)
2345 for (t++; t < PL_bufend; t++) {
2346 if (*t == '\\' && t+1 < PL_bufend)
2348 else if (*t == close && --brackets <= 0)
2350 else if (*t == open)
2356 else if (isALPHA(*s)) {
2357 for (t++; t < PL_bufend && isALNUM(*t); t++) ;
2359 while (t < PL_bufend && isSPACE(*t))
2361 /* if comma follows first term, call it an anon hash */
2362 /* XXX it could be a comma expression with loop modifiers */
2363 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
2364 || (*t == '=' && t[1] == '>')))
2365 OPERATOR(HASHBRACK);
2366 if (PL_expect == XREF)
2369 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
2375 yylval.ival = PL_curcop->cop_line;
2376 if (isSPACE(*s) || *s == '#')
2377 PL_copline = NOLINE; /* invalidate current command line number */
2382 if (PL_lex_brackets <= 0)
2383 yyerror("Unmatched right bracket");
2385 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
2386 if (PL_lex_brackets < PL_lex_formbrack)
2387 PL_lex_formbrack = 0;
2388 if (PL_lex_state == LEX_INTERPNORMAL) {
2389 if (PL_lex_brackets == 0) {
2390 if (PL_lex_fakebrack) {
2391 PL_lex_state = LEX_INTERPEND;
2393 return yylex(); /* ignore fake brackets */
2395 if (*s == '-' && s[1] == '>')
2396 PL_lex_state = LEX_INTERPENDMAYBE;
2397 else if (*s != '[' && *s != '{')
2398 PL_lex_state = LEX_INTERPEND;
2401 if (PL_lex_brackets < PL_lex_fakebrack) {
2403 PL_lex_fakebrack = 0;
2404 return yylex(); /* ignore fake brackets */
2414 if (PL_expect == XOPERATOR) {
2415 if (PL_dowarn && isALPHA(*s) && PL_bufptr == PL_linestart) {
2416 PL_curcop->cop_line--;
2418 PL_curcop->cop_line++;
2423 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
2425 PL_expect = XOPERATOR;
2426 force_ident(PL_tokenbuf, '&');
2430 yylval.ival = (OPpENTERSUB_AMPER<<8);
2449 if (PL_dowarn && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
2450 warn("Reversed %c= operator",(int)tmp);
2452 if (PL_expect == XSTATE && isALPHA(tmp) &&
2453 (s == PL_linestart+1 || s[-2] == '\n') )
2455 if (PL_in_eval && !PL_rsfp) {
2460 if (strnEQ(s,"=cut",4)) {
2474 PL_doextract = TRUE;
2477 if (PL_lex_brackets < PL_lex_formbrack) {
2479 #ifdef PERL_STRICT_CR
2480 for (t = s; *t == ' ' || *t == '\t'; t++) ;
2482 for (t = s; *t == ' ' || *t == '\t' || *t == '\r'; t++) ;
2484 if (*t == '\n' || *t == '#') {
2502 if (PL_expect != XOPERATOR) {
2503 if (s[1] != '<' && !strchr(s,'>'))
2506 s = scan_heredoc(s);
2508 s = scan_inputsymbol(s);
2509 TERM(sublex_start());
2514 SHop(OP_LEFT_SHIFT);
2528 SHop(OP_RIGHT_SHIFT);
2537 if (PL_expect == XOPERATOR) {
2538 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
2541 return ','; /* grandfather non-comma-format format */
2545 if (s[1] == '#' && (isALPHA(s[2]) || strchr("_{$:", s[2]))) {
2546 if (PL_expect == XOPERATOR)
2547 no_op("Array length", PL_bufptr);
2548 PL_tokenbuf[0] = '@';
2549 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
2551 if (!PL_tokenbuf[1])
2553 PL_expect = XOPERATOR;
2554 PL_pending_ident = '#';
2558 if (PL_expect == XOPERATOR)
2559 no_op("Scalar", PL_bufptr);
2560 PL_tokenbuf[0] = '$';
2561 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
2562 if (!PL_tokenbuf[1]) {
2564 yyerror("Final $ should be \\$ or $name");
2568 /* This kludge not intended to be bulletproof. */
2569 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
2570 yylval.opval = newSVOP(OP_CONST, 0,
2571 newSViv((IV)PL_compiling.cop_arybase));
2572 yylval.opval->op_private = OPpCONST_ARYBASE;
2577 if (PL_lex_state == LEX_NORMAL)
2580 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
2583 PL_tokenbuf[0] = '@';
2586 isSPACE(*t) || isALNUM(*t) || *t == '$';
2589 PL_bufptr = skipspace(PL_bufptr);
2590 while (t < PL_bufend && *t != ']')
2592 warn("Multidimensional syntax %.*s not supported",
2593 (t - PL_bufptr) + 1, PL_bufptr);
2597 else if (*s == '{') {
2598 PL_tokenbuf[0] = '%';
2599 if (PL_dowarn && strEQ(PL_tokenbuf+1, "SIG") &&
2600 (t = strchr(s, '}')) && (t = strchr(t, '=')))
2602 char tmpbuf[sizeof PL_tokenbuf];
2604 for (t++; isSPACE(*t); t++) ;
2605 if (isIDFIRST(*t)) {
2606 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
2607 for (; isSPACE(*t); t++) ;
2608 if (*t == ';' && perl_get_cv(tmpbuf, FALSE))
2609 warn("You need to quote \"%s\"", tmpbuf);
2615 PL_expect = XOPERATOR;
2616 if (PL_lex_state == LEX_NORMAL && isSPACE(*d)) {
2617 bool islop = (PL_last_lop == PL_oldoldbufptr);
2618 if (!islop || PL_last_lop_op == OP_GREPSTART)
2619 PL_expect = XOPERATOR;
2620 else if (strchr("$@\"'`q", *s))
2621 PL_expect = XTERM; /* e.g. print $fh "foo" */
2622 else if (strchr("&*<%", *s) && isIDFIRST(s[1]))
2623 PL_expect = XTERM; /* e.g. print $fh &sub */
2624 else if (isIDFIRST(*s)) {
2625 char tmpbuf[sizeof PL_tokenbuf];
2626 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2627 if (tmp = keyword(tmpbuf, len)) {
2628 /* binary operators exclude handle interpretations */
2640 PL_expect = XTERM; /* e.g. print $fh length() */
2645 GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2646 if (gv && GvCVu(gv))
2647 PL_expect = XTERM; /* e.g. print $fh subr() */
2650 else if (isDIGIT(*s))
2651 PL_expect = XTERM; /* e.g. print $fh 3 */
2652 else if (*s == '.' && isDIGIT(s[1]))
2653 PL_expect = XTERM; /* e.g. print $fh .3 */
2654 else if (strchr("/?-+", *s) && !isSPACE(s[1]) && s[1] != '=')
2655 PL_expect = XTERM; /* e.g. print $fh -1 */
2656 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
2657 PL_expect = XTERM; /* print $fh <<"EOF" */
2659 PL_pending_ident = '$';
2663 if (PL_expect == XOPERATOR)
2665 PL_tokenbuf[0] = '@';
2666 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
2667 if (!PL_tokenbuf[1]) {
2669 yyerror("Final @ should be \\@ or @name");
2672 if (PL_lex_state == LEX_NORMAL)
2674 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
2676 PL_tokenbuf[0] = '%';
2678 /* Warn about @ where they meant $. */
2680 if (*s == '[' || *s == '{') {
2682 while (*t && (isALNUM(*t) || strchr(" \t$#+-'\"", *t)))
2684 if (*t == '}' || *t == ']') {
2686 PL_bufptr = skipspace(PL_bufptr);
2687 warn("Scalar value %.*s better written as $%.*s",
2688 t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
2693 PL_pending_ident = '@';
2696 case '/': /* may either be division or pattern */
2697 case '?': /* may either be conditional or pattern */
2698 if (PL_expect != XOPERATOR) {
2699 /* Disable warning on "study /blah/" */
2700 if (PL_oldoldbufptr == PL_last_uni
2701 && (*PL_last_uni != 's' || s - PL_last_uni < 5
2702 || memNE(PL_last_uni, "study", 5) || isALNUM(PL_last_uni[5])))
2704 s = scan_pat(s,OP_MATCH);
2705 TERM(sublex_start());
2713 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
2714 #ifdef PERL_STRICT_CR
2717 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
2719 && (s == PL_linestart || s[-1] == '\n') )
2721 PL_lex_formbrack = 0;
2725 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
2731 yylval.ival = OPf_SPECIAL;
2737 if (PL_expect != XOPERATOR)
2742 case '0': case '1': case '2': case '3': case '4':
2743 case '5': case '6': case '7': case '8': case '9':
2745 if (PL_expect == XOPERATOR)
2751 if (PL_expect == XOPERATOR) {
2752 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
2755 return ','; /* grandfather non-comma-format format */
2761 missingterm((char*)0);
2762 yylval.ival = OP_CONST;
2763 TERM(sublex_start());
2767 if (PL_expect == XOPERATOR) {
2768 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
2771 return ','; /* grandfather non-comma-format format */
2777 missingterm((char*)0);
2778 yylval.ival = OP_CONST;
2779 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
2780 if (*d == '$' || *d == '@' || *d == '\\') {
2781 yylval.ival = OP_STRINGIFY;
2785 TERM(sublex_start());
2789 if (PL_expect == XOPERATOR)
2790 no_op("Backticks",s);
2792 missingterm((char*)0);
2793 yylval.ival = OP_BACKTICK;
2795 TERM(sublex_start());
2799 if (PL_dowarn && PL_lex_inwhat && isDIGIT(*s))
2800 warn("Can't use \\%c to mean $%c in expression", *s, *s);
2801 if (PL_expect == XOPERATOR)
2802 no_op("Backslash",s);
2806 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
2846 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
2848 /* Some keywords can be followed by any delimiter, including ':' */
2849 tmp = (len == 1 && strchr("msyq", PL_tokenbuf[0]) ||
2850 len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
2851 (PL_tokenbuf[0] == 'q' &&
2852 strchr("qwxr", PL_tokenbuf[1]))));
2854 /* x::* is just a word, unless x is "CORE" */
2855 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
2859 while (d < PL_bufend && isSPACE(*d))
2860 d++; /* no comments skipped here, or s### is misparsed */
2862 /* Is this a label? */
2863 if (!tmp && PL_expect == XSTATE
2864 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
2866 yylval.pval = savepv(PL_tokenbuf);
2871 /* Check for keywords */
2872 tmp = keyword(PL_tokenbuf, len);
2874 /* Is this a word before a => operator? */
2875 if (strnEQ(d,"=>",2)) {
2877 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf,0));
2878 yylval.opval->op_private = OPpCONST_BARE;
2882 if (tmp < 0) { /* second-class keyword? */
2883 GV *ogv = Nullgv; /* override (winner) */
2884 GV *hgv = Nullgv; /* hidden (loser) */
2885 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
2887 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
2890 if (GvIMPORTED_CV(gv))
2892 else if (! CvMETHOD(cv))
2896 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
2897 (gv = *gvp) != (GV*)&PL_sv_undef &&
2898 GvCVu(gv) && GvIMPORTED_CV(gv))
2904 tmp = 0; /* overridden by import or by GLOBAL */
2907 && -tmp==KEY_lock /* XXX generalizable kludge */
2908 && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
2910 tmp = 0; /* any sub overrides "weak" keyword */
2912 else { /* no override */
2916 if (PL_dowarn && hgv
2917 && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
2918 warn("Ambiguous call resolved as CORE::%s(), %s",
2919 GvENAME(hgv), "qualify as such or use &");
2926 default: /* not a keyword */
2929 char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
2931 /* Get the rest if it looks like a package qualifier */
2933 if (*s == '\'' || *s == ':' && s[1] == ':') {
2935 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
2938 croak("Bad name after %s%s", PL_tokenbuf,
2939 *s == '\'' ? "'" : "::");
2943 if (PL_expect == XOPERATOR) {
2944 if (PL_bufptr == PL_linestart) {
2945 PL_curcop->cop_line--;
2947 PL_curcop->cop_line++;
2950 no_op("Bareword",s);
2953 /* Look for a subroutine with this name in current package,
2954 unless name is "Foo::", in which case Foo is a bearword
2955 (and a package name). */
2958 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
2960 if (PL_dowarn && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
2961 warn("Bareword \"%s\" refers to nonexistent package",
2964 PL_tokenbuf[len] = '\0';
2971 gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
2974 /* if we saw a global override before, get the right name */
2977 sv = newSVpv("CORE::GLOBAL::",14);
2978 sv_catpv(sv,PL_tokenbuf);
2981 sv = newSVpv(PL_tokenbuf,0);
2983 /* Presume this is going to be a bareword of some sort. */
2986 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2987 yylval.opval->op_private = OPpCONST_BARE;
2989 /* And if "Foo::", then that's what it certainly is. */
2994 /* See if it's the indirect object for a list operator. */
2996 if (PL_oldoldbufptr &&
2997 PL_oldoldbufptr < PL_bufptr &&
2998 (PL_oldoldbufptr == PL_last_lop || PL_oldoldbufptr == PL_last_uni) &&
2999 /* NO SKIPSPACE BEFORE HERE! */
3001 || ((opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF
3002 || (PL_last_lop_op == OP_ENTERSUB
3004 && PL_last_proto[PL_last_proto[0] == ';' ? 1 : 0] == '*')) )
3006 bool immediate_paren = *s == '(';
3008 /* (Now we can afford to cross potential line boundary.) */
3011 /* Two barewords in a row may indicate method call. */
3013 if ((isALPHA(*s) || *s == '$') && (tmp=intuit_method(s,gv)))
3016 /* If not a declared subroutine, it's an indirect object. */
3017 /* (But it's an indir obj regardless for sort.) */
3019 if ((PL_last_lop_op == OP_SORT ||
3020 (!immediate_paren && (!gv || !GvCVu(gv))) ) &&
3021 (PL_last_lop_op != OP_MAPSTART && PL_last_lop_op != OP_GREPSTART)){
3022 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
3027 /* If followed by a paren, it's certainly a subroutine. */
3029 PL_expect = XOPERATOR;
3033 if (gv && GvCVu(gv)) {
3035 if ((cv = GvCV(gv)) && SvPOK(cv))
3036 PL_last_proto = SvPV((SV*)cv, n_a);
3037 for (d = s + 1; *d == ' ' || *d == '\t'; d++) ;
3038 if (*d == ')' && (sv = cv_const_sv(cv))) {
3043 PL_nextval[PL_nexttoke].opval = yylval.opval;
3044 PL_expect = XOPERATOR;
3047 PL_last_lop_op = OP_ENTERSUB;
3051 /* If followed by var or block, call it a method (unless sub) */
3053 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
3054 PL_last_lop = PL_oldbufptr;
3055 PL_last_lop_op = OP_METHOD;
3059 /* If followed by a bareword, see if it looks like indir obj. */
3061 if ((isALPHA(*s) || *s == '$') && (tmp = intuit_method(s,gv)))
3064 /* Not a method, so call it a subroutine (if defined) */
3066 if (gv && GvCVu(gv)) {
3068 if (lastchar == '-')
3069 warn("Ambiguous use of -%s resolved as -&%s()",
3070 PL_tokenbuf, PL_tokenbuf);
3071 PL_last_lop = PL_oldbufptr;
3072 PL_last_lop_op = OP_ENTERSUB;
3073 /* Check for a constant sub */
3075 if ((sv = cv_const_sv(cv))) {
3077 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
3078 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
3079 yylval.opval->op_private = 0;
3083 /* Resolve to GV now. */
3084 op_free(yylval.opval);
3085 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
3086 PL_last_lop_op = OP_ENTERSUB;
3087 /* Is there a prototype? */
3090 PL_last_proto = SvPV((SV*)cv, len);
3093 if (strEQ(PL_last_proto, "$"))
3095 if (*PL_last_proto == '&' && *s == '{') {
3096 sv_setpv(PL_subname,"__ANON__");
3100 PL_last_proto = NULL;
3101 PL_nextval[PL_nexttoke].opval = yylval.opval;
3107 if (PL_hints & HINT_STRICT_SUBS &&
3110 PL_last_lop_op != OP_TRUNCATE && /* S/F prototype in opcode.pl */
3111 PL_last_lop_op != OP_ACCEPT &&
3112 PL_last_lop_op != OP_PIPE_OP &&
3113 PL_last_lop_op != OP_SOCKPAIR &&
3114 !(PL_last_lop_op == OP_ENTERSUB
3116 && PL_last_proto[PL_last_proto[0] == ';' ? 1 : 0] == '*'))
3119 "Bareword \"%s\" not allowed while \"strict subs\" in use",
3124 /* Call it a bare word */
3128 if (lastchar != '-') {
3129 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
3131 warn(warn_reserved, PL_tokenbuf);
3136 if (lastchar && strchr("*%&", lastchar)) {
3137 warn("Operator or semicolon missing before %c%s",
3138 lastchar, PL_tokenbuf);
3139 warn("Ambiguous use of %c resolved as operator %c",
3140 lastchar, lastchar);
3146 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3147 newSVsv(GvSV(PL_curcop->cop_filegv)));
3151 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3152 newSVpvf("%ld", (long)PL_curcop->cop_line));
3155 case KEY___PACKAGE__:
3156 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3158 ? newSVsv(PL_curstname)
3167 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
3168 char *pname = "main";
3169 if (PL_tokenbuf[2] == 'D')
3170 pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash);
3171 gv = gv_fetchpv(form("%s::DATA", pname), TRUE, SVt_PVIO);
3174 GvIOp(gv) = newIO();
3175 IoIFP(GvIOp(gv)) = PL_rsfp;
3176 #if defined(HAS_FCNTL) && defined(F_SETFD)
3178 int fd = PerlIO_fileno(PL_rsfp);
3179 fcntl(fd,F_SETFD,fd >= 3);
3182 /* Mark this internal pseudo-handle as clean */
3183 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
3185 IoTYPE(GvIOp(gv)) = '|';
3186 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
3187 IoTYPE(GvIOp(gv)) = '-';
3189 IoTYPE(GvIOp(gv)) = '<';
3200 if (PL_expect == XSTATE) {
3207 if (*s == ':' && s[1] == ':') {
3210 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3211 tmp = keyword(PL_tokenbuf, len);
3225 LOP(OP_ACCEPT,XTERM);
3231 LOP(OP_ATAN2,XTERM);
3240 LOP(OP_BLESS,XTERM);
3249 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
3266 if (!PL_cryptseen++)
3269 LOP(OP_CRYPT,XTERM);
3273 for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ;
3274 if (*d != '0' && isDIGIT(*d))
3275 yywarn("chmod: mode argument is missing initial 0");
3277 LOP(OP_CHMOD,XTERM);
3280 LOP(OP_CHOWN,XTERM);
3283 LOP(OP_CONNECT,XTERM);
3299 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3303 PL_hints |= HINT_BLOCK_SCOPE;
3313 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
3314 LOP(OP_DBMOPEN,XTERM);
3320 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3327 yylval.ival = PL_curcop->cop_line;
3341 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
3342 UNIBRACK(OP_ENTEREVAL);
3357 case KEY_endhostent:
3363 case KEY_endservent:
3366 case KEY_endprotoent:
3377 yylval.ival = PL_curcop->cop_line;
3379 if (PL_expect == XSTATE && isIDFIRST(*s)) {
3381 if ((PL_bufend - p) >= 3 &&
3382 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
3386 croak("Missing $ on loop variable");
3391 LOP(OP_FORMLINE,XTERM);
3397 LOP(OP_FCNTL,XTERM);
3403 LOP(OP_FLOCK,XTERM);
3412 LOP(OP_GREPSTART, *s == '(' ? XTERM : XREF);
3415 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3430 case KEY_getpriority:
3431 LOP(OP_GETPRIORITY,XTERM);
3433 case KEY_getprotobyname:
3436 case KEY_getprotobynumber:
3437 LOP(OP_GPBYNUMBER,XTERM);
3439 case KEY_getprotoent:
3451 case KEY_getpeername:
3452 UNI(OP_GETPEERNAME);
3454 case KEY_gethostbyname:
3457 case KEY_gethostbyaddr:
3458 LOP(OP_GHBYADDR,XTERM);
3460 case KEY_gethostent:
3463 case KEY_getnetbyname:
3466 case KEY_getnetbyaddr:
3467 LOP(OP_GNBYADDR,XTERM);
3472 case KEY_getservbyname:
3473 LOP(OP_GSBYNAME,XTERM);
3475 case KEY_getservbyport:
3476 LOP(OP_GSBYPORT,XTERM);
3478 case KEY_getservent:
3481 case KEY_getsockname:
3482 UNI(OP_GETSOCKNAME);
3484 case KEY_getsockopt:
3485 LOP(OP_GSOCKOPT,XTERM);
3507 yylval.ival = PL_curcop->cop_line;
3511 LOP(OP_INDEX,XTERM);
3517 LOP(OP_IOCTL,XTERM);
3529 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3560 LOP(OP_LISTEN,XTERM);
3569 s = scan_pat(s,OP_MATCH);
3570 TERM(sublex_start());
3573 LOP(OP_MAPSTART,XREF);
3576 LOP(OP_MKDIR,XTERM);
3579 LOP(OP_MSGCTL,XTERM);
3582 LOP(OP_MSGGET,XTERM);
3585 LOP(OP_MSGRCV,XTERM);
3588 LOP(OP_MSGSND,XTERM);
3593 if (isIDFIRST(*s)) {
3594 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
3595 PL_in_my_stash = gv_stashpv(PL_tokenbuf, FALSE);
3596 if (!PL_in_my_stash) {
3599 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
3606 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3613 if (PL_expect != XSTATE)
3614 yyerror("\"no\" not allowed in expression");
3615 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3616 s = force_version(s);
3625 if (isIDFIRST(*s)) {
3627 for (d = s; isALNUM(*d); d++) ;
3629 if (strchr("|&*+-=!?:.", *t))
3630 warn("Precedence problem: open %.*s should be open(%.*s)",
3636 yylval.ival = OP_OR;
3646 LOP(OP_OPEN_DIR,XTERM);
3649 checkcomma(s,PL_tokenbuf,"filehandle");
3653 checkcomma(s,PL_tokenbuf,"filehandle");
3672 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3676 LOP(OP_PIPE_OP,XTERM);
3681 missingterm((char*)0);
3682 yylval.ival = OP_CONST;
3683 TERM(sublex_start());
3691 missingterm((char*)0);
3692 if (PL_dowarn && SvLEN(PL_lex_stuff)) {
3693 d = SvPV_force(PL_lex_stuff, len);
3694 for (; len; --len, ++d) {
3696 warn("Possible attempt to separate words with commas");
3700 warn("Possible attempt to put comments in qw() list");
3706 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, tokeq(PL_lex_stuff));
3707 PL_lex_stuff = Nullsv;
3710 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(" ",1));
3713 yylval.ival = OP_SPLIT;
3717 PL_last_lop = PL_oldbufptr;
3718 PL_last_lop_op = OP_SPLIT;
3724 missingterm((char*)0);
3725 yylval.ival = OP_STRINGIFY;
3726 if (SvIVX(PL_lex_stuff) == '\'')
3727 SvIVX(PL_lex_stuff) = 0; /* qq'$foo' should intepolate */
3728 TERM(sublex_start());
3731 s = scan_pat(s,OP_QR);
3732 TERM(sublex_start());
3737 missingterm((char*)0);
3738 yylval.ival = OP_BACKTICK;
3740 TERM(sublex_start());
3746 *PL_tokenbuf = '\0';
3747 s = force_word(s,WORD,TRUE,TRUE,FALSE);
3748 if (isIDFIRST(*PL_tokenbuf))
3749 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
3751 yyerror("<> should be quotes");
3758 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3762 LOP(OP_RENAME,XTERM);
3771 LOP(OP_RINDEX,XTERM);
3794 LOP(OP_REVERSE,XTERM);
3805 TERM(sublex_start());
3807 TOKEN(1); /* force error */
3816 LOP(OP_SELECT,XTERM);
3822 LOP(OP_SEMCTL,XTERM);
3825 LOP(OP_SEMGET,XTERM);
3828 LOP(OP_SEMOP,XTERM);
3834 LOP(OP_SETPGRP,XTERM);
3836 case KEY_setpriority:
3837 LOP(OP_SETPRIORITY,XTERM);
3839 case KEY_sethostent:
3845 case KEY_setservent:
3848 case KEY_setprotoent:
3858 LOP(OP_SEEKDIR,XTERM);
3860 case KEY_setsockopt:
3861 LOP(OP_SSOCKOPT,XTERM);
3867 LOP(OP_SHMCTL,XTERM);
3870 LOP(OP_SHMGET,XTERM);
3873 LOP(OP_SHMREAD,XTERM);
3876 LOP(OP_SHMWRITE,XTERM);
3879 LOP(OP_SHUTDOWN,XTERM);
3888 LOP(OP_SOCKET,XTERM);
3890 case KEY_socketpair:
3891 LOP(OP_SOCKPAIR,XTERM);
3894 checkcomma(s,PL_tokenbuf,"subroutine name");
3896 if (*s == ';' || *s == ')') /* probably a close */
3897 croak("sort is now a reserved word");
3899 s = force_word(s,WORD,TRUE,TRUE,FALSE);
3903 LOP(OP_SPLIT,XTERM);
3906 LOP(OP_SPRINTF,XTERM);
3909 LOP(OP_SPLICE,XTERM);
3925 LOP(OP_SUBSTR,XTERM);
3932 if (isIDFIRST(*s) || *s == '\'' || *s == ':') {
3933 char tmpbuf[sizeof PL_tokenbuf];
3935 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3936 if (strchr(tmpbuf, ':'))
3937 sv_setpv(PL_subname, tmpbuf);
3939 sv_setsv(PL_subname,PL_curstname);
3940 sv_catpvn(PL_subname,"::",2);
3941 sv_catpvn(PL_subname,tmpbuf,len);
3943 s = force_word(s,WORD,FALSE,TRUE,TRUE);
3947 PL_expect = XTERMBLOCK;
3948 sv_setpv(PL_subname,"?");
3951 if (tmp == KEY_format) {
3954 PL_lex_formbrack = PL_lex_brackets + 1;
3958 /* Look for a prototype */
3965 SvREFCNT_dec(PL_lex_stuff);
3966 PL_lex_stuff = Nullsv;
3967 croak("Prototype not terminated");
3970 d = SvPVX(PL_lex_stuff);
3972 for (p = d; *p; ++p) {
3977 SvCUR(PL_lex_stuff) = tmp;
3980 PL_nextval[1] = PL_nextval[0];
3981 PL_nexttype[1] = PL_nexttype[0];
3982 PL_nextval[0].opval = (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
3983 PL_nexttype[0] = THING;
3984 if (PL_nexttoke == 1) {
3985 PL_lex_defer = PL_lex_state;
3986 PL_lex_expect = PL_expect;
3987 PL_lex_state = LEX_KNOWNEXT;
3989 PL_lex_stuff = Nullsv;
3992 if (*SvPV(PL_subname,n_a) == '?') {
3993 sv_setpv(PL_subname,"__ANON__");
4000 LOP(OP_SYSTEM,XREF);
4003 LOP(OP_SYMLINK,XTERM);
4006 LOP(OP_SYSCALL,XTERM);
4009 LOP(OP_SYSOPEN,XTERM);
4012 LOP(OP_SYSSEEK,XTERM);
4015 LOP(OP_SYSREAD,XTERM);
4018 LOP(OP_SYSWRITE,XTERM);
4022 TERM(sublex_start());
4043 LOP(OP_TRUNCATE,XTERM);
4055 yylval.ival = PL_curcop->cop_line;
4059 yylval.ival = PL_curcop->cop_line;
4063 LOP(OP_UNLINK,XTERM);
4069 LOP(OP_UNPACK,XTERM);
4072 LOP(OP_UTIME,XTERM);
4076 for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ;
4077 if (*d != '0' && isDIGIT(*d))
4078 yywarn("umask: argument is missing initial 0");
4083 LOP(OP_UNSHIFT,XTERM);
4086 if (PL_expect != XSTATE)
4087 yyerror("\"use\" not allowed in expression");
4090 s = force_version(s);
4091 if(*s == ';' || (s = skipspace(s), *s == ';')) {
4092 PL_nextval[PL_nexttoke].opval = Nullop;
4097 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4098 s = force_version(s);
4111 yylval.ival = PL_curcop->cop_line;
4115 PL_hints |= HINT_BLOCK_SCOPE;
4122 LOP(OP_WAITPID,XTERM);
4130 static char ctl_l[2];
4132 if (ctl_l[0] == '\0')
4133 ctl_l[0] = toCTRL('L');
4134 gv_fetchpv(ctl_l,TRUE, SVt_PV);
4137 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
4142 if (PL_expect == XOPERATOR)
4148 yylval.ival = OP_XOR;
4153 TERM(sublex_start());
4159 keyword(register char *d, I32 len)
4164 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
4165 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
4166 if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__;
4167 if (strEQ(d,"__DATA__")) return KEY___DATA__;
4168 if (strEQ(d,"__END__")) return KEY___END__;
4172 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
4177 if (strEQ(d,"and")) return -KEY_and;
4178 if (strEQ(d,"abs")) return -KEY_abs;
4181 if (strEQ(d,"alarm")) return -KEY_alarm;
4182 if (strEQ(d,"atan2")) return -KEY_atan2;
4185 if (strEQ(d,"accept")) return -KEY_accept;
4190 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
4193 if (strEQ(d,"bless")) return -KEY_bless;
4194 if (strEQ(d,"bind")) return -KEY_bind;
4195 if (strEQ(d,"binmode")) return -KEY_binmode;
4198 if (strEQ(d,"CORE")) return -KEY_CORE;
4203 if (strEQ(d,"cmp")) return -KEY_cmp;
4204 if (strEQ(d,"chr")) return -KEY_chr;
4205 if (strEQ(d,"cos")) return -KEY_cos;
4208 if (strEQ(d,"chop")) return KEY_chop;
4211 if (strEQ(d,"close")) return -KEY_close;
4212 if (strEQ(d,"chdir")) return -KEY_chdir;
4213 if (strEQ(d,"chomp")) return KEY_chomp;
4214 if (strEQ(d,"chmod")) return -KEY_chmod;
4215 if (strEQ(d,"chown")) return -KEY_chown;
4216 if (strEQ(d,"crypt")) return -KEY_crypt;
4219 if (strEQ(d,"chroot")) return -KEY_chroot;
4220 if (strEQ(d,"caller")) return -KEY_caller;
4223 if (strEQ(d,"connect")) return -KEY_connect;
4226 if (strEQ(d,"closedir")) return -KEY_closedir;
4227 if (strEQ(d,"continue")) return -KEY_continue;
4232 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
4237 if (strEQ(d,"do")) return KEY_do;
4240 if (strEQ(d,"die")) return -KEY_die;
4243 if (strEQ(d,"dump")) return -KEY_dump;
4246 if (strEQ(d,"delete")) return KEY_delete;
4249 if (strEQ(d,"defined")) return KEY_defined;
4250 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
4253 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
4258 if (strEQ(d,"EQ")) { deprecate(d); return -KEY_eq;}
4259 if (strEQ(d,"END")) return KEY_END;
4264 if (strEQ(d,"eq")) return -KEY_eq;
4267 if (strEQ(d,"eof")) return -KEY_eof;
4268 if (strEQ(d,"exp")) return -KEY_exp;
4271 if (strEQ(d,"else")) return KEY_else;
4272 if (strEQ(d,"exit")) return -KEY_exit;
4273 if (strEQ(d,"eval")) return KEY_eval;
4274 if (strEQ(d,"exec")) return -KEY_exec;
4275 if (strEQ(d,"each")) return KEY_each;
4278 if (strEQ(d,"elsif")) return KEY_elsif;
4281 if (strEQ(d,"exists")) return KEY_exists;
4282 if (strEQ(d,"elseif")) warn("elseif should be elsif");
4285 if (strEQ(d,"endgrent")) return -KEY_endgrent;
4286 if (strEQ(d,"endpwent")) return -KEY_endpwent;
4289 if (strEQ(d,"endnetent")) return -KEY_endnetent;
4292 if (strEQ(d,"endhostent")) return -KEY_endhostent;
4293 if (strEQ(d,"endservent")) return -KEY_endservent;
4296 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
4303 if (strEQ(d,"for")) return KEY_for;
4306 if (strEQ(d,"fork")) return -KEY_fork;
4309 if (strEQ(d,"fcntl")) return -KEY_fcntl;
4310 if (strEQ(d,"flock")) return -KEY_flock;
4313 if (strEQ(d,"format")) return KEY_format;
4314 if (strEQ(d,"fileno")) return -KEY_fileno;
4317 if (strEQ(d,"foreach")) return KEY_foreach;
4320 if (strEQ(d,"formline")) return -KEY_formline;
4326 if (strEQ(d,"GT")) { deprecate(d); return -KEY_gt;}
4327 if (strEQ(d,"GE")) { deprecate(d); return -KEY_ge;}
4331 if (strnEQ(d,"get",3)) {
4336 if (strEQ(d,"ppid")) return -KEY_getppid;
4337 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
4340 if (strEQ(d,"pwent")) return -KEY_getpwent;
4341 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
4342 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
4345 if (strEQ(d,"peername")) return -KEY_getpeername;
4346 if (strEQ(d,"protoent")) return -KEY_getprotoent;
4347 if (strEQ(d,"priority")) return -KEY_getpriority;
4350 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
4353 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
4357 else if (*d == 'h') {
4358 if (strEQ(d,"hostbyname")) return -KEY_gethostbyname;
4359 if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr;
4360 if (strEQ(d,"hostent")) return -KEY_gethostent;
4362 else if (*d == 'n') {
4363 if (strEQ(d,"netbyname")) return -KEY_getnetbyname;
4364 if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr;
4365 if (strEQ(d,"netent")) return -KEY_getnetent;
4367 else if (*d == 's') {
4368 if (strEQ(d,"servbyname")) return -KEY_getservbyname;
4369 if (strEQ(d,"servbyport")) return -KEY_getservbyport;
4370 if (strEQ(d,"servent")) return -KEY_getservent;
4371 if (strEQ(d,"sockname")) return -KEY_getsockname;
4372 if (strEQ(d,"sockopt")) return -KEY_getsockopt;
4374 else if (*d == 'g') {
4375 if (strEQ(d,"grent")) return -KEY_getgrent;
4376 if (strEQ(d,"grnam")) return -KEY_getgrnam;
4377 if (strEQ(d,"grgid")) return -KEY_getgrgid;
4379 else if (*d == 'l') {
4380 if (strEQ(d,"login")) return -KEY_getlogin;
4382 else if (strEQ(d,"c")) return -KEY_getc;
4387 if (strEQ(d,"gt")) return -KEY_gt;
4388 if (strEQ(d,"ge")) return -KEY_ge;
4391 if (strEQ(d,"grep")) return KEY_grep;
4392 if (strEQ(d,"goto")) return KEY_goto;
4393 if (strEQ(d,"glob")) return KEY_glob;
4396 if (strEQ(d,"gmtime")) return -KEY_gmtime;
4401 if (strEQ(d,"hex")) return -KEY_hex;
4404 if (strEQ(d,"INIT")) return KEY_INIT;
4409 if (strEQ(d,"if")) return KEY_if;
4412 if (strEQ(d,"int")) return -KEY_int;
4415 if (strEQ(d,"index")) return -KEY_index;
4416 if (strEQ(d,"ioctl")) return -KEY_ioctl;
4421 if (strEQ(d,"join")) return -KEY_join;
4425 if (strEQ(d,"keys")) return KEY_keys;
4426 if (strEQ(d,"kill")) return -KEY_kill;
4431 if (strEQ(d,"LT")) { deprecate(d); return -KEY_lt;}
4432 if (strEQ(d,"LE")) { deprecate(d); return -KEY_le;}
4438 if (strEQ(d,"lt")) return -KEY_lt;
4439 if (strEQ(d,"le")) return -KEY_le;
4440 if (strEQ(d,"lc")) return -KEY_lc;
4443 if (strEQ(d,"log")) return -KEY_log;
4446 if (strEQ(d,"last")) return KEY_last;
4447 if (strEQ(d,"link")) return -KEY_link;
4448 if (strEQ(d,"lock")) return -KEY_lock;
4451 if (strEQ(d,"local")) return KEY_local;
4452 if (strEQ(d,"lstat")) return -KEY_lstat;
4455 if (strEQ(d,"length")) return -KEY_length;
4456 if (strEQ(d,"listen")) return -KEY_listen;
4459 if (strEQ(d,"lcfirst")) return -KEY_lcfirst;
4462 if (strEQ(d,"localtime")) return -KEY_localtime;
4468 case 1: return KEY_m;
4470 if (strEQ(d,"my")) return KEY_my;
4473 if (strEQ(d,"map")) return KEY_map;
4476 if (strEQ(d,"mkdir")) return -KEY_mkdir;
4479 if (strEQ(d,"msgctl")) return -KEY_msgctl;
4480 if (strEQ(d,"msgget")) return -KEY_msgget;
4481 if (strEQ(d,"msgrcv")) return -KEY_msgrcv;
4482 if (strEQ(d,"msgsnd")) return -KEY_msgsnd;
4487 if (strEQ(d,"NE")) { deprecate(d); return -KEY_ne;}
4490 if (strEQ(d,"next")) return KEY_next;
4491 if (strEQ(d,"ne")) return -KEY_ne;
4492 if (strEQ(d,"not")) return -KEY_not;
4493 if (strEQ(d,"no")) return KEY_no;
4498 if (strEQ(d,"or")) return -KEY_or;
4501 if (strEQ(d,"ord")) return -KEY_ord;
4502 if (strEQ(d,"oct")) return -KEY_oct;
4503 if (strEQ(d,"our")) { deprecate("reserved word \"our\"");
4507 if (strEQ(d,"open")) return -KEY_open;
4510 if (strEQ(d,"opendir")) return -KEY_opendir;
4517 if (strEQ(d,"pop")) return KEY_pop;
4518 if (strEQ(d,"pos")) return KEY_pos;
4521 if (strEQ(d,"push")) return KEY_push;
4522 if (strEQ(d,"pack")) return -KEY_pack;
4523 if (strEQ(d,"pipe")) return -KEY_pipe;
4526 if (strEQ(d,"print")) return KEY_print;
4529 if (strEQ(d,"printf")) return KEY_printf;
4532 if (strEQ(d,"package")) return KEY_package;
4535 if (strEQ(d,"prototype")) return KEY_prototype;
4540 if (strEQ(d,"q")) return KEY_q;
4541 if (strEQ(d,"qr")) return KEY_qr;
4542 if (strEQ(d,"qq")) return KEY_qq;
4543 if (strEQ(d,"qw")) return KEY_qw;
4544 if (strEQ(d,"qx")) return KEY_qx;
4546 else if (strEQ(d,"quotemeta")) return -KEY_quotemeta;
4551 if (strEQ(d,"ref")) return -KEY_ref;
4554 if (strEQ(d,"read")) return -KEY_read;
4555 if (strEQ(d,"rand")) return -KEY_rand;
4556 if (strEQ(d,"recv")) return -KEY_recv;
4557 if (strEQ(d,"redo")) return KEY_redo;
4560 if (strEQ(d,"rmdir")) return -KEY_rmdir;
4561 if (strEQ(d,"reset")) return -KEY_reset;
4564 if (strEQ(d,"return")) return KEY_return;
4565 if (strEQ(d,"rename")) return -KEY_rename;
4566 if (strEQ(d,"rindex")) return -KEY_rindex;
4569 if (strEQ(d,"require")) return -KEY_require;
4570 if (strEQ(d,"reverse")) return -KEY_reverse;
4571 if (strEQ(d,"readdir")) return -KEY_readdir;
4574 if (strEQ(d,"readlink")) return -KEY_readlink;
4575 if (strEQ(d,"readline")) return -KEY_readline;
4576 if (strEQ(d,"readpipe")) return -KEY_readpipe;
4579 if (strEQ(d,"rewinddir")) return -KEY_rewinddir;
4585 case 0: return KEY_s;
4587 if (strEQ(d,"scalar")) return KEY_scalar;
4592 if (strEQ(d,"seek")) return -KEY_seek;
4593 if (strEQ(d,"send")) return -KEY_send;
4596 if (strEQ(d,"semop")) return -KEY_semop;
4599 if (strEQ(d,"select")) return -KEY_select;
4600 if (strEQ(d,"semctl")) return -KEY_semctl;
4601 if (strEQ(d,"semget")) return -KEY_semget;
4604 if (strEQ(d,"setpgrp")) return -KEY_setpgrp;
4605 if (strEQ(d,"seekdir")) return -KEY_seekdir;
4608 if (strEQ(d,"setpwent")) return -KEY_setpwent;
4609 if (strEQ(d,"setgrent")) return -KEY_setgrent;
4612 if (strEQ(d,"setnetent")) return -KEY_setnetent;
4615 if (strEQ(d,"setsockopt")) return -KEY_setsockopt;
4616 if (strEQ(d,"sethostent")) return -KEY_sethostent;
4617 if (strEQ(d,"setservent")) return -KEY_setservent;
4620 if (strEQ(d,"setpriority")) return -KEY_setpriority;
4621 if (strEQ(d,"setprotoent")) return -KEY_setprotoent;
4628 if (strEQ(d,"shift")) return KEY_shift;
4631 if (strEQ(d,"shmctl")) return -KEY_shmctl;
4632 if (strEQ(d,"shmget")) return -KEY_shmget;
4635 if (strEQ(d,"shmread")) return -KEY_shmread;
4638 if (strEQ(d,"shmwrite")) return -KEY_shmwrite;
4639 if (strEQ(d,"shutdown")) return -KEY_shutdown;
4644 if (strEQ(d,"sin")) return -KEY_sin;
4647 if (strEQ(d,"sleep")) return -KEY_sleep;
4650 if (strEQ(d,"sort")) return KEY_sort;
4651 if (strEQ(d,"socket")) return -KEY_socket;
4652 if (strEQ(d,"socketpair")) return -KEY_socketpair;
4655 if (strEQ(d,"split")) return KEY_split;
4656 if (strEQ(d,"sprintf")) return -KEY_sprintf;
4657 if (strEQ(d,"splice")) return KEY_splice;
4660 if (strEQ(d,"sqrt")) return -KEY_sqrt;
4663 if (strEQ(d,"srand")) return -KEY_srand;
4666 if (strEQ(d,"stat")) return -KEY_stat;
4667 if (strEQ(d,"study")) return KEY_study;
4670 if (strEQ(d,"substr")) return -KEY_substr;
4671 if (strEQ(d,"sub")) return KEY_sub;
4676 if (strEQ(d,"system")) return -KEY_system;
4679 if (strEQ(d,"symlink")) return -KEY_symlink;
4680 if (strEQ(d,"syscall")) return -KEY_syscall;
4681 if (strEQ(d,"sysopen")) return -KEY_sysopen;
4682 if (strEQ(d,"sysread")) return -KEY_sysread;
4683 if (strEQ(d,"sysseek")) return -KEY_sysseek;
4686 if (strEQ(d,"syswrite")) return -KEY_syswrite;
4695 if (strEQ(d,"tr")) return KEY_tr;
4698 if (strEQ(d,"tie")) return KEY_tie;
4701 if (strEQ(d,"tell")) return -KEY_tell;
4702 if (strEQ(d,"tied")) return KEY_tied;
4703 if (strEQ(d,"time")) return -KEY_time;
4706 if (strEQ(d,"times")) return -KEY_times;
4709 if (strEQ(d,"telldir")) return -KEY_telldir;
4712 if (strEQ(d,"truncate")) return -KEY_truncate;
4719 if (strEQ(d,"uc")) return -KEY_uc;
4722 if (strEQ(d,"use")) return KEY_use;
4725 if (strEQ(d,"undef")) return KEY_undef;
4726 if (strEQ(d,"until")) return KEY_until;
4727 if (strEQ(d,"untie")) return KEY_untie;
4728 if (strEQ(d,"utime")) return -KEY_utime;
4729 if (strEQ(d,"umask")) return -KEY_umask;
4732 if (strEQ(d,"unless")) return KEY_unless;
4733 if (strEQ(d,"unpack")) return -KEY_unpack;
4734 if (strEQ(d,"unlink")) return -KEY_unlink;
4737 if (strEQ(d,"unshift")) return KEY_unshift;
4738 if (strEQ(d,"ucfirst")) return -KEY_ucfirst;
4743 if (strEQ(d,"values")) return -KEY_values;
4744 if (strEQ(d,"vec")) return -KEY_vec;
4749 if (strEQ(d,"warn")) return -KEY_warn;
4750 if (strEQ(d,"wait")) return -KEY_wait;
4753 if (strEQ(d,"while")) return KEY_while;
4754 if (strEQ(d,"write")) return -KEY_write;
4757 if (strEQ(d,"waitpid")) return -KEY_waitpid;
4760 if (strEQ(d,"wantarray")) return -KEY_wantarray;
4765 if (len == 1) return -KEY_x;
4766 if (strEQ(d,"xor")) return -KEY_xor;
4769 if (len == 1) return KEY_y;
4778 checkcomma(register char *s, char *name, char *what)
4782 if (PL_dowarn && *s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
4784 for (w = s+2; *w && level; w++) {
4791 for (; *w && isSPACE(*w); w++) ;
4792 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
4793 warn("%s (...) interpreted as function",name);
4795 while (s < PL_bufend && isSPACE(*s))
4799 while (s < PL_bufend && isSPACE(*s))
4801 if (isIDFIRST(*s)) {
4805 while (s < PL_bufend && isSPACE(*s))
4810 kw = keyword(w, s - w) || perl_get_cv(w, FALSE) != 0;
4814 croak("No comma allowed after %s", what);
4820 new_constant(char *s, STRLEN len, char *key, SV *sv, SV *pv, char *type)
4823 HV *table = GvHV(PL_hintgv); /* ^H */
4826 bool oldcatch = CATCH_GET;
4832 yyerror("%^H is not defined");
4835 cvp = hv_fetch(table, key, strlen(key), FALSE);
4836 if (!cvp || !SvOK(*cvp)) {
4837 sprintf(buf,"$^H{%s} is not defined", key);
4841 sv_2mortal(sv); /* Parent created it permanently */
4844 pv = sv_2mortal(newSVpv(s, len));
4846 typesv = sv_2mortal(newSVpv(type, 0));
4848 typesv = &PL_sv_undef;
4850 Zero(&myop, 1, BINOP);
4851 myop.op_last = (OP *) &myop;
4852 myop.op_next = Nullop;
4853 myop.op_flags = OPf_WANT_SCALAR | OPf_STACKED;
4855 PUSHSTACKi(PERLSI_OVERLOAD);
4858 PL_op = (OP *) &myop;
4859 if (PERLDB_SUB && PL_curstash != PL_debstash)
4860 PL_op->op_private |= OPpENTERSUB_DB;
4871 if (PL_op = pp_entersub(ARGS))
4878 CATCH_SET(oldcatch);
4882 sprintf(buf,"Call to &{$^H{%s}} did not return a defined value", key);
4885 return SvREFCNT_inc(res);
4889 scan_word(register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
4891 register char *d = dest;
4892 register char *e = d + destlen - 3; /* two-character token, ending NUL */
4895 croak(ident_too_long);
4898 else if (*s == '\'' && allow_package && isIDFIRST(s[1])) {
4903 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
4916 scan_ident(register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni)
4923 if (PL_lex_brackets == 0)
4924 PL_lex_fakebrack = 0;
4928 e = d + destlen - 3; /* two-character token, ending NUL */
4930 while (isDIGIT(*s)) {
4932 croak(ident_too_long);
4939 croak(ident_too_long);
4942 else if (*s == '\'' && isIDFIRST(s[1])) {
4947 else if (*s == ':' && s[1] == ':') {
4958 if (PL_lex_state != LEX_NORMAL)
4959 PL_lex_state = LEX_INTERPENDMAYBE;
4962 if (*s == '$' && s[1] &&
4963 (isALNUM(s[1]) || strchr("${", s[1]) || strnEQ(s+1,"::",2)) )
4965 if (isDIGIT(s[1]) && PL_lex_state == LEX_INTERPNORMAL)
4966 deprecate("\"$$<digit>\" to mean \"${$}<digit>\"");
4979 if (*d == '^' && *s && (isUPPER(*s) || strchr("[\\]^_?", *s))) {
4984 if (isSPACE(s[-1])) {
4987 if (ch != ' ' && ch != '\t') {
4993 if (isIDFIRST(*d)) {
4995 while (isALNUM(*s) || *s == ':')
4998 while (s < send && (*s == ' ' || *s == '\t')) s++;
4999 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
5000 if (PL_dowarn && keyword(dest, d - dest)) {
5001 char *brack = *s == '[' ? "[...]" : "{...}";
5002 warn("Ambiguous use of %c{%s%s} resolved to %c%s%s",
5003 funny, dest, brack, funny, dest, brack);
5005 PL_lex_fakebrack = PL_lex_brackets+1;
5007 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5013 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets)
5014 PL_lex_state = LEX_INTERPEND;
5017 if (PL_dowarn && PL_lex_state == LEX_NORMAL &&
5018 (keyword(dest, d - dest) || perl_get_cv(dest, FALSE)))
5019 warn("Ambiguous use of %c{%s} resolved to %c%s",
5020 funny, dest, funny, dest);
5023 s = bracket; /* let the parser handle it */
5027 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
5028 PL_lex_state = LEX_INTERPEND;
5032 void pmflag(U16 *pmfl, int ch)
5037 *pmfl |= PMf_GLOBAL;
5039 *pmfl |= PMf_CONTINUE;
5043 *pmfl |= PMf_MULTILINE;
5045 *pmfl |= PMf_SINGLELINE;
5047 *pmfl |= PMf_EXTENDED;
5051 scan_pat(char *start, I32 type)
5056 s = scan_str(start);
5059 SvREFCNT_dec(PL_lex_stuff);
5060 PL_lex_stuff = Nullsv;
5061 croak("Search pattern not terminated");
5064 pm = (PMOP*)newPMOP(type, 0);
5065 if (PL_multi_open == '?')
5066 pm->op_pmflags |= PMf_ONCE;
5068 while (*s && strchr("iomsx", *s))
5069 pmflag(&pm->op_pmflags,*s++);
5072 while (*s && strchr("iogcmsx", *s))
5073 pmflag(&pm->op_pmflags,*s++);
5075 pm->op_pmpermflags = pm->op_pmflags;
5077 PL_lex_op = (OP*)pm;
5078 yylval.ival = OP_MATCH;
5083 scan_subst(char *start)
5090 yylval.ival = OP_NULL;
5092 s = scan_str(start);
5096 SvREFCNT_dec(PL_lex_stuff);
5097 PL_lex_stuff = Nullsv;
5098 croak("Substitution pattern not terminated");
5101 if (s[-1] == PL_multi_open)
5104 first_start = PL_multi_start;
5108 SvREFCNT_dec(PL_lex_stuff);
5109 PL_lex_stuff = Nullsv;
5111 SvREFCNT_dec(PL_lex_repl);
5112 PL_lex_repl = Nullsv;
5113 croak("Substitution replacement not terminated");
5115 PL_multi_start = first_start; /* so whole substitution is taken together */
5117 pm = (PMOP*)newPMOP(OP_SUBST, 0);
5123 else if (strchr("iogcmsx", *s))
5124 pmflag(&pm->op_pmflags,*s++);
5131 PL_super_bufptr = s;
5132 PL_super_bufend = PL_bufend;
5134 pm->op_pmflags |= PMf_EVAL;
5135 repl = newSVpv("",0);
5137 sv_catpv(repl, es ? "eval " : "do ");
5138 sv_catpvn(repl, "{ ", 2);
5139 sv_catsv(repl, PL_lex_repl);
5140 sv_catpvn(repl, " };", 2);
5141 SvCOMPILED_on(repl);
5142 SvREFCNT_dec(PL_lex_repl);
5146 pm->op_pmpermflags = pm->op_pmflags;
5147 PL_lex_op = (OP*)pm;
5148 yylval.ival = OP_SUBST;
5153 scan_trans(char *start)
5162 yylval.ival = OP_NULL;
5164 s = scan_str(start);
5167 SvREFCNT_dec(PL_lex_stuff);
5168 PL_lex_stuff = Nullsv;
5169 croak("Transliteration pattern not terminated");
5171 if (s[-1] == PL_multi_open)
5177 SvREFCNT_dec(PL_lex_stuff);
5178 PL_lex_stuff = Nullsv;
5180 SvREFCNT_dec(PL_lex_repl);
5181 PL_lex_repl = Nullsv;
5182 croak("Transliteration replacement not terminated");
5185 New(803,tbl,256,short);
5186 o = newPVOP(OP_TRANS, 0, (char*)tbl);
5188 complement = Delete = squash = 0;
5189 while (*s == 'c' || *s == 'd' || *s == 's') {
5191 complement = OPpTRANS_COMPLEMENT;
5193 Delete = OPpTRANS_DELETE;
5195 squash = OPpTRANS_SQUASH;
5198 o->op_private = Delete|squash|complement;
5201 yylval.ival = OP_TRANS;
5206 scan_heredoc(register char *s)
5210 I32 op_type = OP_SCALAR;
5217 int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
5221 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
5224 for (peek = s; *peek == ' ' || *peek == '\t'; peek++) ;
5225 if (*peek && strchr("`'\"",*peek)) {
5228 s = delimcpy(d, e, s, PL_bufend, term, &len);
5239 deprecate("bare << to mean <<\"\"");
5240 for (; isALNUM(*s); s++) {
5245 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
5246 croak("Delimiter for here document is too long");
5249 len = d - PL_tokenbuf;
5250 #ifndef PERL_STRICT_CR
5251 d = strchr(s, '\r');
5255 while (s < PL_bufend) {
5261 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
5270 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
5275 if (outer || !(d=ninstr(s,PL_bufend,d,d+1)))
5276 herewas = newSVpv(s,PL_bufend-s);
5278 s--, herewas = newSVpv(s,d-s);
5279 s += SvCUR(herewas);
5281 tmpstr = NEWSV(87,79);
5282 sv_upgrade(tmpstr, SVt_PVIV);
5287 else if (term == '`') {
5288 op_type = OP_BACKTICK;
5289 SvIVX(tmpstr) = '\\';
5293 PL_multi_start = PL_curcop->cop_line;
5294 PL_multi_open = PL_multi_close = '<';
5295 term = *PL_tokenbuf;
5296 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
5297 char *bufptr = PL_super_bufptr;
5298 char *bufend = PL_super_bufend;
5299 char *olds = s - SvCUR(herewas);
5300 s = strchr(bufptr, '\n');
5304 while (s < bufend &&
5305 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
5307 PL_curcop->cop_line++;
5310 PL_curcop->cop_line = PL_multi_start;
5311 missingterm(PL_tokenbuf);
5313 sv_setpvn(herewas,bufptr,d-bufptr+1);
5314 sv_setpvn(tmpstr,d+1,s-d);
5316 sv_catpvn(herewas,s,bufend-s);
5317 (void)strcpy(bufptr,SvPVX(herewas));
5324 while (s < PL_bufend &&
5325 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
5327 PL_curcop->cop_line++;
5329 if (s >= PL_bufend) {
5330 PL_curcop->cop_line = PL_multi_start;
5331 missingterm(PL_tokenbuf);
5333 sv_setpvn(tmpstr,d+1,s-d);
5335 PL_curcop->cop_line++; /* the preceding stmt passes a newline */
5337 sv_catpvn(herewas,s,PL_bufend-s);
5338 sv_setsv(PL_linestr,herewas);
5339 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
5340 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
5343 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
5344 while (s >= PL_bufend) { /* multiple line string? */
5346 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
5347 PL_curcop->cop_line = PL_multi_start;
5348 missingterm(PL_tokenbuf);
5350 PL_curcop->cop_line++;
5351 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
5352 #ifndef PERL_STRICT_CR
5353 if (PL_bufend - PL_linestart >= 2) {
5354 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
5355 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
5357 PL_bufend[-2] = '\n';
5359 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
5361 else if (PL_bufend[-1] == '\r')
5362 PL_bufend[-1] = '\n';
5364 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
5365 PL_bufend[-1] = '\n';
5367 if (PERLDB_LINE && PL_curstash != PL_debstash) {
5368 SV *sv = NEWSV(88,0);
5370 sv_upgrade(sv, SVt_PVMG);
5371 sv_setsv(sv,PL_linestr);
5372 av_store(GvAV(PL_curcop->cop_filegv),
5373 (I32)PL_curcop->cop_line,sv);
5375 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
5378 sv_catsv(PL_linestr,herewas);
5379 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
5383 sv_catsv(tmpstr,PL_linestr);
5388 PL_multi_end = PL_curcop->cop_line;
5389 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
5390 SvLEN_set(tmpstr, SvCUR(tmpstr) + 1);
5391 Renew(SvPVX(tmpstr), SvLEN(tmpstr), char);
5393 SvREFCNT_dec(herewas);
5394 PL_lex_stuff = tmpstr;
5395 yylval.ival = op_type;
5400 takes: current position in input buffer
5401 returns: new position in input buffer
5402 side-effects: yylval and lex_op are set.
5407 <FH> read from filehandle
5408 <pkg::FH> read from package qualified filehandle
5409 <pkg'FH> read from package qualified filehandle
5410 <$fh> read from filehandle in $fh
5416 scan_inputsymbol(char *start)
5418 register char *s = start; /* current position in buffer */
5423 d = PL_tokenbuf; /* start of temp holding space */
5424 e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
5425 s = delimcpy(d, e, s + 1, PL_bufend, '>', &len); /* extract until > */
5427 /* die if we didn't have space for the contents of the <>,
5431 if (len >= sizeof PL_tokenbuf)
5432 croak("Excessively long <> operator");
5434 croak("Unterminated <> operator");
5439 Remember, only scalar variables are interpreted as filehandles by
5440 this code. Anything more complex (e.g., <$fh{$num}>) will be
5441 treated as a glob() call.
5442 This code makes use of the fact that except for the $ at the front,
5443 a scalar variable and a filehandle look the same.
5445 if (*d == '$' && d[1]) d++;
5447 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
5448 while (*d && (isALNUM(*d) || *d == '\'' || *d == ':'))
5451 /* If we've tried to read what we allow filehandles to look like, and
5452 there's still text left, then it must be a glob() and not a getline.
5453 Use scan_str to pull out the stuff between the <> and treat it
5454 as nothing more than a string.
5457 if (d - PL_tokenbuf != len) {
5458 yylval.ival = OP_GLOB;
5460 s = scan_str(start);
5462 croak("Glob not terminated");
5466 /* we're in a filehandle read situation */
5469 /* turn <> into <ARGV> */
5471 (void)strcpy(d,"ARGV");
5473 /* if <$fh>, create the ops to turn the variable into a
5479 /* try to find it in the pad for this block, otherwise find
5480 add symbol table ops
5482 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
5483 OP *o = newOP(OP_PADSV, 0);
5485 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, newUNOP(OP_RV2GV, 0, o));
5488 GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV);
5489 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0,
5490 newUNOP(OP_RV2GV, 0,
5491 newUNOP(OP_RV2SV, 0,
5492 newGVOP(OP_GV, 0, gv))));
5494 /* we created the ops in lex_op, so make yylval.ival a null op */
5495 yylval.ival = OP_NULL;
5498 /* If it's none of the above, it must be a literal filehandle
5499 (<Foo::BAR> or <FOO>) so build a simple readline OP */
5501 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
5502 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
5503 yylval.ival = OP_NULL;
5512 takes: start position in buffer
5513 returns: position to continue reading from buffer
5514 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
5515 updates the read buffer.
5517 This subroutine pulls a string out of the input. It is called for:
5518 q single quotes q(literal text)
5519 ' single quotes 'literal text'
5520 qq double quotes qq(interpolate $here please)
5521 " double quotes "interpolate $here please"
5522 qx backticks qx(/bin/ls -l)
5523 ` backticks `/bin/ls -l`
5524 qw quote words @EXPORT_OK = qw( func() $spam )
5525 m// regexp match m/this/
5526 s/// regexp substitute s/this/that/
5527 tr/// string transliterate tr/this/that/
5528 y/// string transliterate y/this/that/
5529 ($*@) sub prototypes sub foo ($)
5530 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
5532 In most of these cases (all but <>, patterns and transliterate)
5533 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
5534 calls scan_str(). s/// makes yylex() call scan_subst() which calls
5535 scan_str(). tr/// and y/// make yylex() call scan_trans() which
5538 It skips whitespace before the string starts, and treats the first
5539 character as the delimiter. If the delimiter is one of ([{< then
5540 the corresponding "close" character )]}> is used as the closing
5541 delimiter. It allows quoting of delimiters, and if the string has
5542 balanced delimiters ([{<>}]) it allows nesting.
5544 The lexer always reads these strings into lex_stuff, except in the
5545 case of the operators which take *two* arguments (s/// and tr///)
5546 when it checks to see if lex_stuff is full (presumably with the 1st
5547 arg to s or tr) and if so puts the string into lex_repl.
5552 scan_str(char *start)
5555 SV *sv; /* scalar value: string */
5556 char *tmps; /* temp string, used for delimiter matching */
5557 register char *s = start; /* current position in the buffer */
5558 register char term; /* terminating character */
5559 register char *to; /* current position in the sv's data */
5560 I32 brackets = 1; /* bracket nesting level */
5562 /* skip space before the delimiter */
5566 /* mark where we are, in case we need to report errors */
5569 /* after skipping whitespace, the next character is the terminator */
5571 /* mark where we are */
5572 PL_multi_start = PL_curcop->cop_line;
5573 PL_multi_open = term;
5575 /* find corresponding closing delimiter */
5576 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
5578 PL_multi_close = term;
5580 /* create a new SV to hold the contents. 87 is leak category, I'm
5581 assuming. 79 is the SV's initial length. What a random number. */
5583 sv_upgrade(sv, SVt_PVIV);
5585 (void)SvPOK_only(sv); /* validate pointer */
5587 /* move past delimiter and try to read a complete string */
5590 /* extend sv if need be */
5591 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
5592 /* set 'to' to the next character in the sv's string */
5593 to = SvPVX(sv)+SvCUR(sv);
5595 /* if open delimiter is the close delimiter read unbridle */
5596 if (PL_multi_open == PL_multi_close) {
5597 for (; s < PL_bufend; s++,to++) {
5598 /* embedded newlines increment the current line number */
5599 if (*s == '\n' && !PL_rsfp)
5600 PL_curcop->cop_line++;
5601 /* handle quoted delimiters */
5602 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
5605 /* any other quotes are simply copied straight through */
5609 /* terminate when run out of buffer (the for() condition), or
5610 have found the terminator */
5611 else if (*s == term)
5617 /* if the terminator isn't the same as the start character (e.g.,
5618 matched brackets), we have to allow more in the quoting, and
5619 be prepared for nested brackets.
5622 /* read until we run out of string, or we find the terminator */
5623 for (; s < PL_bufend; s++,to++) {
5624 /* embedded newlines increment the line count */
5625 if (*s == '\n' && !PL_rsfp)
5626 PL_curcop->cop_line++;
5627 /* backslashes can escape the open or closing characters */
5628 if (*s == '\\' && s+1 < PL_bufend) {
5629 if ((s[1] == PL_multi_open) || (s[1] == PL_multi_close))
5634 /* allow nested opens and closes */
5635 else if (*s == PL_multi_close && --brackets <= 0)
5637 else if (*s == PL_multi_open)
5642 /* terminate the copied string and update the sv's end-of-string */
5644 SvCUR_set(sv, to - SvPVX(sv));
5647 * this next chunk reads more into the buffer if we're not done yet
5650 if (s < PL_bufend) break; /* handle case where we are done yet :-) */
5652 #ifndef PERL_STRICT_CR
5653 if (to - SvPVX(sv) >= 2) {
5654 if ((to[-2] == '\r' && to[-1] == '\n') ||
5655 (to[-2] == '\n' && to[-1] == '\r'))
5659 SvCUR_set(sv, to - SvPVX(sv));
5661 else if (to[-1] == '\r')
5664 else if (to - SvPVX(sv) == 1 && to[-1] == '\r')
5668 /* if we're out of file, or a read fails, bail and reset the current
5669 line marker so we can report where the unterminated string began
5672 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
5674 PL_curcop->cop_line = PL_multi_start;
5677 /* we read a line, so increment our line counter */
5678 PL_curcop->cop_line++;
5680 /* update debugger info */
5681 if (PERLDB_LINE && PL_curstash != PL_debstash) {
5682 SV *sv = NEWSV(88,0);
5684 sv_upgrade(sv, SVt_PVMG);
5685 sv_setsv(sv,PL_linestr);
5686 av_store(GvAV(PL_curcop->cop_filegv),
5687 (I32)PL_curcop->cop_line, sv);
5690 /* having changed the buffer, we must update PL_bufend */
5691 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
5694 /* at this point, we have successfully read the delimited string */
5696 PL_multi_end = PL_curcop->cop_line;
5699 /* if we allocated too much space, give some back */
5700 if (SvCUR(sv) + 5 < SvLEN(sv)) {
5701 SvLEN_set(sv, SvCUR(sv) + 1);
5702 Renew(SvPVX(sv), SvLEN(sv), char);
5705 /* decide whether this is the first or second quoted string we've read
5718 takes: pointer to position in buffer
5719 returns: pointer to new position in buffer
5720 side-effects: builds ops for the constant in yylval.op
5722 Read a number in any of the formats that Perl accepts:
5724 0(x[0-7A-F]+)|([0-7]+)
5725 [\d_]+(\.[\d_]*)?[Ee](\d+)
5727 Underbars (_) are allowed in decimal numbers. If -w is on,
5728 underbars before a decimal point must be at three digit intervals.
5730 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
5733 If it reads a number without a decimal point or an exponent, it will
5734 try converting the number to an integer and see if it can do so
5735 without loss of precision.
5739 scan_num(char *start)
5741 register char *s = start; /* current position in buffer */
5742 register char *d; /* destination in temp buffer */
5743 register char *e; /* end of temp buffer */
5744 I32 tryiv; /* used to see if it can be an int */
5745 double value; /* number read, as a double */
5746 SV *sv; /* place to put the converted number */
5747 I32 floatit; /* boolean: int or float? */
5748 char *lastub = 0; /* position of last underbar */
5749 static char number_too_long[] = "Number too long";
5751 /* We use the first character to decide what type of number this is */
5755 croak("panic: scan_num");
5757 /* if it starts with a 0, it could be an octal number, a decimal in
5758 0.13 disguise, or a hexadecimal number.
5763 u holds the "number so far"
5764 shift the power of 2 of the base (hex == 4, octal == 3)
5765 overflowed was the number more than we can hold?
5767 Shift is used when we add a digit. It also serves as an "are
5768 we in octal or hex?" indicator to disallow hex characters when
5773 bool overflowed = FALSE;
5780 /* check for a decimal in disguise */
5781 else if (s[1] == '.')
5783 /* so it must be octal */
5788 /* read the rest of the octal number */
5790 UV n, b; /* n is used in the overflow test, b is the digit we're adding on */
5794 /* if we don't mention it, we're done */
5803 /* 8 and 9 are not octal */
5806 yyerror("Illegal octal digit");
5810 case '0': case '1': case '2': case '3': case '4':
5811 case '5': case '6': case '7':
5812 b = *s++ & 15; /* ASCII digit -> value of digit */
5816 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
5817 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
5818 /* make sure they said 0x */
5823 /* Prepare to put the digit we have onto the end
5824 of the number so far. We check for overflows.
5828 n = u << shift; /* make room for the digit */
5829 if (!overflowed && (n >> shift) != u
5830 && !(PL_hints & HINT_NEW_BINARY)) {
5831 warn("Integer overflow in %s number",
5832 (shift == 4) ? "hex" : "octal");
5835 u = n | b; /* add the digit to the end */
5840 /* if we get here, we had success: make a scalar value from
5846 if ( PL_hints & HINT_NEW_BINARY)
5847 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
5852 handle decimal numbers.
5853 we're also sent here when we read a 0 as the first digit
5855 case '1': case '2': case '3': case '4': case '5':
5856 case '6': case '7': case '8': case '9': case '.':
5859 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
5862 /* read next group of digits and _ and copy into d */
5863 while (isDIGIT(*s) || *s == '_') {
5864 /* skip underscores, checking for misplaced ones
5868 if (PL_dowarn && lastub && s - lastub != 3)
5869 warn("Misplaced _ in number");
5873 /* check for end of fixed-length buffer */
5875 croak(number_too_long);
5876 /* if we're ok, copy the character */
5881 /* final misplaced underbar check */
5882 if (PL_dowarn && lastub && s - lastub != 3)
5883 warn("Misplaced _ in number");
5885 /* read a decimal portion if there is one. avoid
5886 3..5 being interpreted as the number 3. followed
5889 if (*s == '.' && s[1] != '.') {
5893 /* copy, ignoring underbars, until we run out of
5894 digits. Note: no misplaced underbar checks!
5896 for (; isDIGIT(*s) || *s == '_'; s++) {
5897 /* fixed length buffer check */
5899 croak(number_too_long);
5905 /* read exponent part, if present */
5906 if (*s && strchr("eE",*s) && strchr("+-0123456789",s[1])) {
5910 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
5911 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
5913 /* allow positive or negative exponent */
5914 if (*s == '+' || *s == '-')
5917 /* read digits of exponent (no underbars :-) */
5918 while (isDIGIT(*s)) {
5920 croak(number_too_long);
5925 /* terminate the string */
5928 /* make an sv from the string */
5930 /* reset numeric locale in case we were earlier left in Swaziland */
5931 SET_NUMERIC_STANDARD();
5932 value = atof(PL_tokenbuf);
5935 See if we can make do with an integer value without loss of
5936 precision. We use I_V to cast to an int, because some
5937 compilers have issues. Then we try casting it back and see
5938 if it was the same. We only do this if we know we
5939 specifically read an integer.
5941 Note: if floatit is true, then we don't need to do the
5945 if (!floatit && (double)tryiv == value)
5946 sv_setiv(sv, tryiv);
5948 sv_setnv(sv, value);
5949 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) : (PL_hints & HINT_NEW_INTEGER) )
5950 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
5951 (floatit ? "float" : "integer"), sv, Nullsv, NULL);
5955 /* make the op for the constant and return */
5957 yylval.opval = newSVOP(OP_CONST, 0, sv);
5963 scan_formline(register char *s)
5968 SV *stuff = newSVpv("",0);
5969 bool needargs = FALSE;
5972 if (*s == '.' || *s == '}') {
5974 #ifdef PERL_STRICT_CR
5975 for (t = s+1;*t == ' ' || *t == '\t'; t++) ;
5977 for (t = s+1;*t == ' ' || *t == '\t' || *t == '\r'; t++) ;
5979 if (*t == '\n' || t == PL_bufend)
5982 if (PL_in_eval && !PL_rsfp) {
5983 eol = strchr(s,'\n');
5988 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
5990 for (t = s; t < eol; t++) {
5991 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
5993 goto enough; /* ~~ must be first line in formline */
5995 if (*t == '@' || *t == '^')
5998 sv_catpvn(stuff, s, eol-s);
6002 s = filter_gets(PL_linestr, PL_rsfp, 0);
6003 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
6004 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
6007 yyerror("Format not terminated");
6017 PL_lex_state = LEX_NORMAL;
6018 PL_nextval[PL_nexttoke].ival = 0;
6022 PL_lex_state = LEX_FORMLINE;
6023 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
6025 PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
6029 SvREFCNT_dec(stuff);
6030 PL_lex_formbrack = 0;
6041 PL_cshlen = strlen(PL_cshname);
6046 start_subparse(I32 is_format, U32 flags)
6049 I32 oldsavestack_ix = PL_savestack_ix;
6050 CV* outsidecv = PL_compcv;
6054 assert(SvTYPE(PL_compcv) == SVt_PVCV);
6056 save_I32(&PL_subline);
6057 save_item(PL_subname);
6059 SAVESPTR(PL_curpad);
6060 SAVESPTR(PL_comppad);
6061 SAVESPTR(PL_comppad_name);
6062 SAVESPTR(PL_compcv);
6063 SAVEI32(PL_comppad_name_fill);
6064 SAVEI32(PL_min_intro_pending);
6065 SAVEI32(PL_max_intro_pending);
6066 SAVEI32(PL_pad_reset_pending);
6068 PL_compcv = (CV*)NEWSV(1104,0);
6069 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
6070 CvFLAGS(PL_compcv) |= flags;
6072 PL_comppad = newAV();
6073 av_push(PL_comppad, Nullsv);
6074 PL_curpad = AvARRAY(PL_comppad);
6075 PL_comppad_name = newAV();
6076 PL_comppad_name_fill = 0;
6077 PL_min_intro_pending = 0;
6079 PL_subline = PL_curcop->cop_line;
6081 av_store(PL_comppad_name, 0, newSVpv("@_", 2));
6082 PL_curpad[0] = (SV*)newAV();
6083 SvPADMY_on(PL_curpad[0]); /* XXX Needed? */
6084 #endif /* USE_THREADS */
6086 comppadlist = newAV();
6087 AvREAL_off(comppadlist);
6088 av_store(comppadlist, 0, (SV*)PL_comppad_name);
6089 av_store(comppadlist, 1, (SV*)PL_comppad);
6091 CvPADLIST(PL_compcv) = comppadlist;
6092 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
6094 CvOWNER(PL_compcv) = 0;
6095 New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
6096 MUTEX_INIT(CvMUTEXP(PL_compcv));
6097 #endif /* USE_THREADS */
6099 return oldsavestack_ix;
6118 char *context = NULL;
6122 if (!yychar || (yychar == ';' && !PL_rsfp))
6124 else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 &&
6125 PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) {
6126 while (isSPACE(*PL_oldoldbufptr))
6128 context = PL_oldoldbufptr;
6129 contlen = PL_bufptr - PL_oldoldbufptr;
6131 else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 &&
6132 PL_oldbufptr != PL_bufptr) {
6133 while (isSPACE(*PL_oldbufptr))
6135 context = PL_oldbufptr;
6136 contlen = PL_bufptr - PL_oldbufptr;
6138 else if (yychar > 255)
6139 where = "next token ???";
6140 else if ((yychar & 127) == 127) {
6141 if (PL_lex_state == LEX_NORMAL ||
6142 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
6143 where = "at end of line";
6144 else if (PL_lex_inpat)
6145 where = "within pattern";
6147 where = "within string";
6150 SV *where_sv = sv_2mortal(newSVpv("next char ", 0));
6152 sv_catpvf(where_sv, "^%c", toCTRL(yychar));
6153 else if (isPRINT_LC(yychar))
6154 sv_catpvf(where_sv, "%c", yychar);
6156 sv_catpvf(where_sv, "\\%03o", yychar & 255);
6157 where = SvPVX(where_sv);
6159 msg = sv_2mortal(newSVpv(s, 0));
6160 sv_catpvf(msg, " at %_ line %ld, ",
6161 GvSV(PL_curcop->cop_filegv), (long)PL_curcop->cop_line);
6163 sv_catpvf(msg, "near \"%.*s\"\n", contlen, context);
6165 sv_catpvf(msg, "%s\n", where);
6166 if (PL_multi_start < PL_multi_end && (U32)(PL_curcop->cop_line - PL_multi_end) <= 1) {
6168 " (Might be a runaway multi-line %c%c string starting on line %ld)\n",
6169 (int)PL_multi_open,(int)PL_multi_close,(long)PL_multi_start);
6174 else if (PL_in_eval)
6175 sv_catsv(ERRSV, msg);
6177 PerlIO_write(PerlIO_stderr(), SvPVX(msg), SvCUR(msg));
6178 if (++PL_error_count >= 10)
6179 croak("%_ has too many errors.\n", GvSV(PL_curcop->cop_filegv));
6181 PL_in_my_stash = Nullhv;