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
15 * This file is the lexer for Perl. It's closely linked to the
18 * The main routine is yylex(), which returns the next token.
22 #define PERL_IN_TOKE_C
25 #define yychar PL_yychar
26 #define yylval PL_yylval
28 static char ident_too_long[] = "Identifier too long";
30 static void restore_rsfp(pTHXo_ void *f);
32 #define XFAKEBRACK 128
35 /*#define UTF (SvUTF8(PL_linestr) && !(PL_hints & HINT_BYTE))*/
36 #define UTF (PL_hints & HINT_UTF8)
38 /* In variables name $^X, these are the legal values for X.
39 * 1999-02-27 mjd-perl-patch@plover.com */
40 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
42 /* LEX_* are values for PL_lex_state, the state of the lexer.
43 * They are arranged oddly so that the guard on the switch statement
44 * can get by with a single comparison (if the compiler is smart enough).
47 /* #define LEX_NOTPARSING 11 is done in perl.h. */
50 #define LEX_INTERPNORMAL 9
51 #define LEX_INTERPCASEMOD 8
52 #define LEX_INTERPPUSH 7
53 #define LEX_INTERPSTART 6
54 #define LEX_INTERPEND 5
55 #define LEX_INTERPENDMAYBE 4
56 #define LEX_INTERPCONCAT 3
57 #define LEX_INTERPCONST 2
58 #define LEX_FORMLINE 1
59 #define LEX_KNOWNEXT 0
68 /* XXX If this causes problems, set i_unistd=undef in the hint file. */
70 # include <unistd.h> /* Needed for execv() */
79 YYSTYPE* yylval_pointer = NULL;
80 int* yychar_pointer = NULL;
83 # define yylval (*yylval_pointer)
84 # define yychar (*yychar_pointer)
85 # define PERL_YYLEX_PARAM yylval_pointer,yychar_pointer
87 # define yylex() Perl_yylex(aTHX_ yylval_pointer, yychar_pointer)
92 /* CLINE is a macro that ensures PL_copline has a sane value */
97 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
100 * Convenience functions to return different tokens and prime the
101 * lexer for the next token. They all take an argument.
103 * TOKEN : generic token (used for '(', DOLSHARP, etc)
104 * OPERATOR : generic operator
105 * AOPERATOR : assignment operator
106 * PREBLOCK : beginning the block after an if, while, foreach, ...
107 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
108 * PREREF : *EXPR where EXPR is not a simple identifier
109 * TERM : expression term
110 * LOOPX : loop exiting command (goto, last, dump, etc)
111 * FTST : file test operator
112 * FUN0 : zero-argument function
113 * FUN1 : not used, except for not, which isn't a UNIOP
114 * BOop : bitwise or or xor
116 * SHop : shift operator
117 * PWop : power operator
118 * PMop : pattern-matching operator
119 * Aop : addition-level operator
120 * Mop : multiplication-level operator
121 * Eop : equality-testing operator
122 * Rop : relational operator <= != gt
124 * Also see LOP and lop() below.
127 #define TOKEN(retval) return (PL_bufptr = s,(int)retval)
128 #define OPERATOR(retval) return (PL_expect = XTERM,PL_bufptr = s,(int)retval)
129 #define AOPERATOR(retval) return ao((PL_expect = XTERM,PL_bufptr = s,(int)retval))
130 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s,(int)retval)
131 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s,(int)retval)
132 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s,(int)retval)
133 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR,PL_bufptr = s,(int)retval)
134 #define LOOPX(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LOOPEX)
135 #define FTST(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)UNIOP)
136 #define FUN0(f) return(yylval.ival = f,PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC0)
137 #define FUN1(f) return(yylval.ival = f,PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC1)
138 #define BOop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)BITOROP))
139 #define BAop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)BITANDOP))
140 #define SHop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)SHIFTOP))
141 #define PWop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)POWOP))
142 #define PMop(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)MATCHOP)
143 #define Aop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)ADDOP))
144 #define Mop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)MULOP))
145 #define Eop(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)EQOP)
146 #define Rop(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)RELOP)
148 /* This bit of chicanery makes a unary function followed by
149 * a parenthesis into a function with one argument, highest precedence.
151 #define UNI(f) return(yylval.ival = f, \
154 PL_last_uni = PL_oldbufptr, \
155 PL_last_lop_op = f, \
156 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
158 #define UNIBRACK(f) return(yylval.ival = f, \
160 PL_last_uni = PL_oldbufptr, \
161 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
163 /* grandfather return to old style */
164 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
169 * This subroutine detects &&= and ||= and turns an ANDAND or OROR
170 * into an OP_ANDASSIGN or OP_ORASSIGN
174 S_ao(pTHX_ int toketype)
176 if (*PL_bufptr == '=') {
178 if (toketype == ANDAND)
179 yylval.ival = OP_ANDASSIGN;
180 else if (toketype == OROR)
181 yylval.ival = OP_ORASSIGN;
189 * When Perl expects an operator and finds something else, no_op
190 * prints the warning. It always prints "<something> found where
191 * operator expected. It prints "Missing semicolon on previous line?"
192 * if the surprise occurs at the start of the line. "do you need to
193 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
194 * where the compiler doesn't know if foo is a method call or a function.
195 * It prints "Missing operator before end of line" if there's nothing
196 * after the missing operator, or "... before <...>" if there is something
197 * after the missing operator.
201 S_no_op(pTHX_ char *what, char *s)
203 char *oldbp = PL_bufptr;
204 bool is_first = (PL_oldbufptr == PL_linestart);
212 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
214 Perl_warn(aTHX_ "\t(Missing semicolon on previous line?)\n");
215 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
217 for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
218 if (t < PL_bufptr && isSPACE(*t))
219 Perl_warn(aTHX_ "\t(Do you need to predeclare %.*s?)\n",
220 t - PL_oldoldbufptr, PL_oldoldbufptr);
223 Perl_warn(aTHX_ "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
229 * Complain about missing quote/regexp/heredoc terminator.
230 * If it's called with (char *)NULL then it cauterizes the line buffer.
231 * If we're in a delimited string and the delimiter is a control
232 * character, it's reformatted into a two-char sequence like ^C.
237 S_missingterm(pTHX_ char *s)
242 char *nl = strrchr(s,'\n');
248 iscntrl(PL_multi_close)
250 PL_multi_close < 32 || PL_multi_close == 127
254 tmpbuf[1] = toCTRL(PL_multi_close);
260 *tmpbuf = PL_multi_close;
264 q = strchr(s,'"') ? '\'' : '"';
265 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
273 Perl_deprecate(pTHX_ char *s)
276 if (ckWARN(WARN_DEPRECATED))
277 Perl_warner(aTHX_ WARN_DEPRECATED, "Use of %s is deprecated", s);
282 * Deprecate a comma-less variable list.
288 deprecate("comma-less variable list");
292 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
293 * utf16-to-utf8-reversed.
296 #ifdef PERL_CR_FILTER
300 register char *s = SvPVX(sv);
301 register char *e = s + SvCUR(sv);
302 /* outer loop optimized to do nothing if there are no CR-LFs */
304 if (*s++ == '\r' && *s == '\n') {
305 /* hit a CR-LF, need to copy the rest */
306 register char *d = s - 1;
309 if (*s == '\r' && s[1] == '\n')
320 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
322 I32 count = FILTER_READ(idx+1, sv, maxlen);
323 if (count > 0 && !maxlen)
330 S_utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
332 I32 count = FILTER_READ(idx+1, sv, maxlen);
336 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
337 tend = utf16_to_utf8((U16*)SvPVX(sv), tmps, SvCUR(sv));
338 sv_usepvn(sv, (char*)tmps, tend - tmps);
345 S_utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
347 I32 count = FILTER_READ(idx+1, sv, maxlen);
351 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
352 tend = utf16_to_utf8_reversed((U16*)SvPVX(sv), tmps, SvCUR(sv));
353 sv_usepvn(sv, (char*)tmps, tend - tmps);
361 * Initialize variables. Uses the Perl save_stack to save its state (for
362 * recursive calls to the parser).
366 Perl_lex_start(pTHX_ SV *line)
372 SAVEI32(PL_lex_dojoin);
373 SAVEI32(PL_lex_brackets);
374 SAVEI32(PL_lex_casemods);
375 SAVEI32(PL_lex_starts);
376 SAVEI32(PL_lex_state);
377 SAVEVPTR(PL_lex_inpat);
378 SAVEI32(PL_lex_inwhat);
379 SAVECOPLINE(PL_curcop);
382 SAVEPPTR(PL_oldbufptr);
383 SAVEPPTR(PL_oldoldbufptr);
384 SAVEPPTR(PL_linestart);
385 SAVESPTR(PL_linestr);
386 SAVEPPTR(PL_lex_brackstack);
387 SAVEPPTR(PL_lex_casestack);
388 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
389 SAVESPTR(PL_lex_stuff);
390 SAVEI32(PL_lex_defer);
391 SAVEI32(PL_sublex_info.sub_inwhat);
392 SAVESPTR(PL_lex_repl);
394 SAVEINT(PL_lex_expect);
396 PL_lex_state = LEX_NORMAL;
400 New(899, PL_lex_brackstack, 120, char);
401 New(899, PL_lex_casestack, 12, char);
402 SAVEFREEPV(PL_lex_brackstack);
403 SAVEFREEPV(PL_lex_casestack);
405 *PL_lex_casestack = '\0';
408 PL_lex_stuff = Nullsv;
409 PL_lex_repl = Nullsv;
412 PL_sublex_info.sub_inwhat = 0;
414 if (SvREADONLY(PL_linestr))
415 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
416 s = SvPV(PL_linestr, len);
417 if (len && s[len-1] != ';') {
418 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
419 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
420 sv_catpvn(PL_linestr, "\n;", 2);
422 SvTEMP_off(PL_linestr);
423 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
424 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
426 PL_rs = newSVpvn("\n", 1);
432 * Finalizer for lexing operations. Must be called when the parser is
433 * done with the lexer.
439 PL_doextract = FALSE;
444 * This subroutine has nothing to do with tilting, whether at windmills
445 * or pinball tables. Its name is short for "increment line". It
446 * increments the current line number in CopLINE(PL_curcop) and checks
447 * to see whether the line starts with a comment of the form
448 * # line 500 "foo.pm"
449 * If so, it sets the current line number and file to the values in the comment.
453 S_incline(pTHX_ char *s)
461 CopLINE_inc(PL_curcop);
464 while (*s == ' ' || *s == '\t') s++;
465 if (strnEQ(s, "line ", 5)) {
474 while (*s == ' ' || *s == '\t')
476 if (*s == '"' && (t = strchr(s+1, '"')))
480 return; /* false alarm */
481 for (t = s; !isSPACE(*t); t++) ;
486 CopFILE_set(PL_curcop, s);
488 CopLINE_set(PL_curcop, atoi(n)-1);
493 * Called to gobble the appropriate amount and type of whitespace.
494 * Skips comments as well.
498 S_skipspace(pTHX_ register char *s)
501 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
502 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
508 SSize_t oldprevlen, oldoldprevlen;
509 SSize_t oldloplen, oldunilen;
510 while (s < PL_bufend && isSPACE(*s)) {
511 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
516 if (s < PL_bufend && *s == '#') {
517 while (s < PL_bufend && *s != '\n')
521 if (PL_in_eval && !PL_rsfp) {
528 /* only continue to recharge the buffer if we're at the end
529 * of the buffer, we're not reading from a source filter, and
530 * we're in normal lexing mode
532 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
533 PL_lex_state == LEX_FORMLINE)
536 /* try to recharge the buffer */
537 if ((s = filter_gets(PL_linestr, PL_rsfp,
538 (prevlen = SvCUR(PL_linestr)))) == Nullch)
540 /* end of file. Add on the -p or -n magic */
541 if (PL_minus_n || PL_minus_p) {
542 sv_setpv(PL_linestr,PL_minus_p ?
543 ";}continue{print or die qq(-p destination: $!\\n)" :
545 sv_catpv(PL_linestr,";}");
546 PL_minus_n = PL_minus_p = 0;
549 sv_setpv(PL_linestr,";");
551 /* reset variables for next time we lex */
552 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
554 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
556 /* Close the filehandle. Could be from -P preprocessor,
557 * STDIN, or a regular file. If we were reading code from
558 * STDIN (because the commandline held no -e or filename)
559 * then we don't close it, we reset it so the code can
560 * read from STDIN too.
563 if (PL_preprocess && !PL_in_eval)
564 (void)PerlProc_pclose(PL_rsfp);
565 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
566 PerlIO_clearerr(PL_rsfp);
568 (void)PerlIO_close(PL_rsfp);
573 /* not at end of file, so we only read another line */
574 /* make corresponding updates to old pointers, for yyerror() */
575 oldprevlen = PL_oldbufptr - PL_bufend;
576 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
578 oldunilen = PL_last_uni - PL_bufend;
580 oldloplen = PL_last_lop - PL_bufend;
581 PL_linestart = PL_bufptr = s + prevlen;
582 PL_bufend = s + SvCUR(PL_linestr);
584 PL_oldbufptr = s + oldprevlen;
585 PL_oldoldbufptr = s + oldoldprevlen;
587 PL_last_uni = s + oldunilen;
589 PL_last_lop = s + oldloplen;
592 /* debugger active and we're not compiling the debugger code,
593 * so store the line into the debugger's array of lines
595 if (PERLDB_LINE && PL_curstash != PL_debstash) {
596 SV *sv = NEWSV(85,0);
598 sv_upgrade(sv, SVt_PVMG);
599 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
600 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
607 * Check the unary operators to ensure there's no ambiguity in how they're
608 * used. An ambiguous piece of code would be:
610 * This doesn't mean rand() + 5. Because rand() is a unary operator,
611 * the +5 is its argument.
621 if (PL_oldoldbufptr != PL_last_uni)
623 while (isSPACE(*PL_last_uni))
625 for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
626 if ((t = strchr(s, '(')) && t < PL_bufptr)
628 if (ckWARN_d(WARN_AMBIGUOUS)){
631 Perl_warner(aTHX_ WARN_AMBIGUOUS,
632 "Warning: Use of \"%s\" without parens is ambiguous",
638 /* workaround to replace the UNI() macro with a function. Only the
639 * hints/uts.sh file mentions this. Other comments elsewhere in the
640 * source indicate Microport Unix might need it too.
646 #define UNI(f) return uni(f,s)
649 S_uni(pTHX_ I32 f, char *s)
654 PL_last_uni = PL_oldbufptr;
665 #endif /* CRIPPLED_CC */
668 * LOP : macro to build a list operator. Its behaviour has been replaced
669 * with a subroutine, S_lop() for which LOP is just another name.
672 #define LOP(f,x) return lop(f,x,s)
676 * Build a list operator (or something that might be one). The rules:
677 * - if we have a next token, then it's a list operator [why?]
678 * - if the next thing is an opening paren, then it's a function
679 * - else it's a list operator
683 S_lop(pTHX_ I32 f, int x, char *s)
690 PL_last_lop = PL_oldbufptr;
705 * When the lexer realizes it knows the next token (for instance,
706 * it is reordering tokens for the parser) then it can call S_force_next
707 * to know what token to return the next time the lexer is called. Caller
708 * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer
709 * handles the token correctly.
713 S_force_next(pTHX_ I32 type)
715 PL_nexttype[PL_nexttoke] = type;
717 if (PL_lex_state != LEX_KNOWNEXT) {
718 PL_lex_defer = PL_lex_state;
719 PL_lex_expect = PL_expect;
720 PL_lex_state = LEX_KNOWNEXT;
726 * When the lexer knows the next thing is a word (for instance, it has
727 * just seen -> and it knows that the next char is a word char, then
728 * it calls S_force_word to stick the next word into the PL_next lookahead.
731 * char *start : buffer position (must be within PL_linestr)
732 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
733 * int check_keyword : if true, Perl checks to make sure the word isn't
734 * a keyword (do this if the word is a label, e.g. goto FOO)
735 * int allow_pack : if true, : characters will also be allowed (require,
737 * int allow_initial_tick : used by the "sub" lexer only.
741 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
746 start = skipspace(start);
748 if (isIDFIRST_lazy_if(s,UTF) ||
749 (allow_pack && *s == ':') ||
750 (allow_initial_tick && *s == '\'') )
752 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
753 if (check_keyword && keyword(PL_tokenbuf, len))
755 if (token == METHOD) {
760 PL_expect = XOPERATOR;
763 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(PL_tokenbuf,0));
764 PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
772 * Called when the lexer wants $foo *foo &foo etc, but the program
773 * text only contains the "foo" portion. The first argument is a pointer
774 * to the "foo", and the second argument is the type symbol to prefix.
775 * Forces the next token to be a "WORD".
776 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
780 S_force_ident(pTHX_ register char *s, int kind)
783 OP* o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
784 PL_nextval[PL_nexttoke].opval = o;
787 dTHR; /* just for in_eval */
788 o->op_private = OPpCONST_ENTERED;
789 /* XXX see note in pp_entereval() for why we forgo typo
790 warnings if the symbol must be introduced in an eval.
792 gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
793 kind == '$' ? SVt_PV :
794 kind == '@' ? SVt_PVAV :
795 kind == '%' ? SVt_PVHV :
804 * Forces the next token to be a version number.
808 S_force_version(pTHX_ char *s)
810 OP *version = Nullop;
814 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
818 for (; isDIGIT(*d) || *d == '_' || *d == '.'; d++);
819 if ((*d == ';' || isSPACE(*d)) && *(skipspace(d)) != ',') {
821 /* real VERSION number -- GBARR */
822 version = yylval.opval;
826 /* NOTE: The parser sees the package name and the VERSION swapped */
827 PL_nextval[PL_nexttoke].opval = version;
835 * Tokenize a quoted string passed in as an SV. It finds the next
836 * chunk, up to end of string or a backslash. It may make a new
837 * SV containing that chunk (if HINT_NEW_STRING is on). It also
842 S_tokeq(pTHX_ SV *sv)
853 s = SvPV_force(sv, len);
857 while (s < send && *s != '\\')
862 if ( PL_hints & HINT_NEW_STRING )
863 pv = sv_2mortal(newSVpvn(SvPVX(pv), len));
866 if (s + 1 < send && (s[1] == '\\'))
867 s++; /* all that, just for this */
872 SvCUR_set(sv, d - SvPVX(sv));
874 if ( PL_hints & HINT_NEW_STRING )
875 return new_constant(NULL, 0, "q", sv, pv, "q");
880 * Now come three functions related to double-quote context,
881 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
882 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
883 * interact with PL_lex_state, and create fake ( ... ) argument lists
884 * to handle functions and concatenation.
885 * They assume that whoever calls them will be setting up a fake
886 * join call, because each subthing puts a ',' after it. This lets
889 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
891 * (I'm not sure whether the spurious commas at the end of lcfirst's
892 * arguments and join's arguments are created or not).
897 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
899 * Pattern matching will set PL_lex_op to the pattern-matching op to
900 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
902 * OP_CONST and OP_READLINE are easy--just make the new op and return.
904 * Everything else becomes a FUNC.
906 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
907 * had an OP_CONST or OP_READLINE). This just sets us up for a
908 * call to S_sublex_push().
914 register I32 op_type = yylval.ival;
916 if (op_type == OP_NULL) {
917 yylval.opval = PL_lex_op;
921 if (op_type == OP_CONST || op_type == OP_READLINE) {
922 SV *sv = tokeq(PL_lex_stuff);
924 if (SvTYPE(sv) == SVt_PVIV) {
925 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
931 nsv = newSVpvn(p, len);
935 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
936 PL_lex_stuff = Nullsv;
940 PL_sublex_info.super_state = PL_lex_state;
941 PL_sublex_info.sub_inwhat = op_type;
942 PL_sublex_info.sub_op = PL_lex_op;
943 PL_lex_state = LEX_INTERPPUSH;
947 yylval.opval = PL_lex_op;
957 * Create a new scope to save the lexing state. The scope will be
958 * ended in S_sublex_done. Returns a '(', starting the function arguments
959 * to the uc, lc, etc. found before.
960 * Sets PL_lex_state to LEX_INTERPCONCAT.
969 PL_lex_state = PL_sublex_info.super_state;
970 SAVEI32(PL_lex_dojoin);
971 SAVEI32(PL_lex_brackets);
972 SAVEI32(PL_lex_casemods);
973 SAVEI32(PL_lex_starts);
974 SAVEI32(PL_lex_state);
975 SAVEVPTR(PL_lex_inpat);
976 SAVEI32(PL_lex_inwhat);
977 SAVECOPLINE(PL_curcop);
979 SAVEPPTR(PL_oldbufptr);
980 SAVEPPTR(PL_oldoldbufptr);
981 SAVEPPTR(PL_linestart);
982 SAVESPTR(PL_linestr);
983 SAVEPPTR(PL_lex_brackstack);
984 SAVEPPTR(PL_lex_casestack);
986 PL_linestr = PL_lex_stuff;
987 PL_lex_stuff = Nullsv;
989 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
991 PL_bufend += SvCUR(PL_linestr);
992 SAVEFREESV(PL_linestr);
994 PL_lex_dojoin = FALSE;
996 New(899, PL_lex_brackstack, 120, char);
997 New(899, PL_lex_casestack, 12, char);
998 SAVEFREEPV(PL_lex_brackstack);
999 SAVEFREEPV(PL_lex_casestack);
1000 PL_lex_casemods = 0;
1001 *PL_lex_casestack = '\0';
1003 PL_lex_state = LEX_INTERPCONCAT;
1004 CopLINE_set(PL_curcop, PL_multi_start);
1006 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1007 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1008 PL_lex_inpat = PL_sublex_info.sub_op;
1010 PL_lex_inpat = Nullop;
1017 * Restores lexer state after a S_sublex_push.
1023 if (!PL_lex_starts++) {
1024 PL_expect = XOPERATOR;
1025 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpvn("",0));
1029 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1030 PL_lex_state = LEX_INTERPCASEMOD;
1034 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1035 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1036 PL_linestr = PL_lex_repl;
1038 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1039 PL_bufend += SvCUR(PL_linestr);
1040 SAVEFREESV(PL_linestr);
1041 PL_lex_dojoin = FALSE;
1042 PL_lex_brackets = 0;
1043 PL_lex_casemods = 0;
1044 *PL_lex_casestack = '\0';
1046 if (SvEVALED(PL_lex_repl)) {
1047 PL_lex_state = LEX_INTERPNORMAL;
1049 /* we don't clear PL_lex_repl here, so that we can check later
1050 whether this is an evalled subst; that means we rely on the
1051 logic to ensure sublex_done() is called again only via the
1052 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1055 PL_lex_state = LEX_INTERPCONCAT;
1056 PL_lex_repl = Nullsv;
1062 PL_bufend = SvPVX(PL_linestr);
1063 PL_bufend += SvCUR(PL_linestr);
1064 PL_expect = XOPERATOR;
1065 PL_sublex_info.sub_inwhat = 0;
1073 Extracts a pattern, double-quoted string, or transliteration. This
1076 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1077 processing a pattern (PL_lex_inpat is true), a transliteration
1078 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1080 Returns a pointer to the character scanned up to. Iff this is
1081 advanced from the start pointer supplied (ie if anything was
1082 successfully parsed), will leave an OP for the substring scanned
1083 in yylval. Caller must intuit reason for not parsing further
1084 by looking at the next characters herself.
1088 double-quoted style: \r and \n
1089 regexp special ones: \D \s
1091 backrefs: \1 (deprecated in substitution replacements)
1092 case and quoting: \U \Q \E
1093 stops on @ and $, but not for $ as tail anchor
1095 In transliterations:
1096 characters are VERY literal, except for - not at the start or end
1097 of the string, which indicates a range. scan_const expands the
1098 range to the full set of intermediate characters.
1100 In double-quoted strings:
1102 double-quoted style: \r and \n
1104 backrefs: \1 (deprecated)
1105 case and quoting: \U \Q \E
1108 scan_const does *not* construct ops to handle interpolated strings.
1109 It stops processing as soon as it finds an embedded $ or @ variable
1110 and leaves it to the caller to work out what's going on.
1112 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @:foo.
1114 $ in pattern could be $foo or could be tail anchor. Assumption:
1115 it's a tail anchor if $ is the last thing in the string, or if it's
1116 followed by one of ")| \n\t"
1118 \1 (backreferences) are turned into $1
1120 The structure of the code is
1121 while (there's a character to process) {
1122 handle transliteration ranges
1123 skip regexp comments
1124 skip # initiated comments in //x patterns
1125 check for embedded @foo
1126 check for embedded scalars
1128 leave intact backslashes from leave (below)
1129 deprecate \1 in strings and sub replacements
1130 handle string-changing backslashes \l \U \Q \E, etc.
1131 switch (what was escaped) {
1132 handle - in a transliteration (becomes a literal -)
1133 handle \132 octal characters
1134 handle 0x15 hex characters
1135 handle \cV (control V)
1136 handle printf backslashes (\f, \r, \n, etc)
1138 } (end if backslash)
1139 } (end while character to read)
1144 S_scan_const(pTHX_ char *start)
1146 register char *send = PL_bufend; /* end of the constant */
1147 SV *sv = NEWSV(93, send - start); /* sv for the constant */
1148 register char *s = start; /* start of the constant */
1149 register char *d = SvPVX(sv); /* destination for copies */
1150 bool dorange = FALSE; /* are we in a translit range? */
1151 bool has_utf = FALSE; /* embedded \x{} */
1153 I32 utf = (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op)
1154 ? (PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF))
1156 I32 thisutf = (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op)
1157 ? (PL_sublex_info.sub_op->op_private & (PL_lex_repl ?
1158 OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF))
1160 const char *leaveit = /* set of acceptably-backslashed characters */
1162 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxcz0123456789[{]} \t\n\r\f\v#"
1165 while (s < send || dorange) {
1166 /* get transliterations out of the way (they're most literal) */
1167 if (PL_lex_inwhat == OP_TRANS) {
1168 /* expand a range A-Z to the full set of characters. AIE! */
1170 I32 i; /* current expanded character */
1171 I32 min; /* first character in range */
1172 I32 max; /* last character in range */
1174 i = d - SvPVX(sv); /* remember current offset */
1175 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1176 d = SvPVX(sv) + i; /* refresh d after realloc */
1177 d -= 2; /* eat the first char and the - */
1179 min = (U8)*d; /* first char in range */
1180 max = (U8)d[1]; /* last char in range */
1183 if ((isLOWER(min) && isLOWER(max)) ||
1184 (isUPPER(min) && isUPPER(max))) {
1186 for (i = min; i <= max; i++)
1190 for (i = min; i <= max; i++)
1197 for (i = min; i <= max; i++)
1200 /* mark the range as done, and continue */
1205 /* range begins (ignore - as first or last char) */
1206 else if (*s == '-' && s+1 < send && s != start) {
1208 *d++ = (char)0xff; /* use illegal utf8 byte--see pmtrans */
1217 /* if we get here, we're not doing a transliteration */
1219 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1220 except for the last char, which will be done separately. */
1221 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1223 while (s < send && *s != ')')
1225 } else if (s[2] == '{'
1226 || s[2] == 'p' && s[3] == '{') { /* This should march regcomp.c */
1228 char *regparse = s + (s[2] == '{' ? 3 : 4);
1231 while (count && (c = *regparse)) {
1232 if (c == '\\' && regparse[1])
1240 if (*regparse != ')') {
1241 regparse--; /* Leave one char for continuation. */
1242 yyerror("Sequence (?{...}) not terminated or not {}-balanced");
1244 while (s < regparse)
1249 /* likewise skip #-initiated comments in //x patterns */
1250 else if (*s == '#' && PL_lex_inpat &&
1251 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1252 while (s+1 < send && *s != '\n')
1256 /* check for embedded arrays (@foo, @:foo, @'foo, @{foo}, @$foo) */
1257 else if (*s == '@' && s[1]
1258 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$", s[1])))
1261 /* check for embedded scalars. only stop if we're sure it's a
1264 else if (*s == '$') {
1265 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1267 if (s + 1 < send && !strchr("()| \n\t", s[1]))
1268 break; /* in regexp, $ might be tail anchor */
1271 /* (now in tr/// code again) */
1273 if (*s & 0x80 && thisutf) {
1274 dTHR; /* only for ckWARN */
1275 if (ckWARN(WARN_UTF8)) {
1276 (void)utf8_to_uv((U8*)s, &len); /* could cvt latin-1 to utf8 here... */
1285 has_utf = TRUE; /* assume valid utf8 */
1289 if (*s == '\\' && s+1 < send) {
1292 /* some backslashes we leave behind */
1293 if (*leaveit && *s && strchr(leaveit, *s)) {
1299 /* deprecate \1 in strings and substitution replacements */
1300 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1301 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1303 dTHR; /* only for ckWARN */
1304 if (ckWARN(WARN_SYNTAX))
1305 Perl_warner(aTHX_ WARN_SYNTAX, "\\%c better written as $%c", *s, *s);
1310 /* string-change backslash escapes */
1311 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1316 /* if we get here, it's either a quoted -, or a digit */
1319 /* quoted - in transliterations */
1321 if (PL_lex_inwhat == OP_TRANS) {
1329 if (ckWARN(WARN_UNSAFE) && isALPHA(*s))
1330 Perl_warner(aTHX_ WARN_UNSAFE,
1331 "Unrecognized escape \\%c passed through",
1333 /* default action is to copy the quoted character */
1338 /* \132 indicates an octal constant */
1339 case '0': case '1': case '2': case '3':
1340 case '4': case '5': case '6': case '7':
1341 *d++ = (char)scan_oct(s, 3, &len);
1345 /* \x24 indicates a hex constant */
1349 char* e = strchr(s, '}');
1352 yyerror("Missing right brace on \\x{}");
1355 /* note: utf always shorter than hex */
1356 d = (char*)uv_to_utf8((U8*)d,
1357 (UV)scan_hex(s + 1, e - s - 1, &len));
1362 UV uv = (UV)scan_hex(s, 2, &len);
1363 if (utf && PL_lex_inwhat == OP_TRANS &&
1364 utf != (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF))
1366 d = (char*)uv_to_utf8((U8*)d, uv); /* doing a CU or UC */
1370 if (uv >= 127 && UTF) {
1372 if (ckWARN(WARN_UTF8))
1373 Perl_warner(aTHX_ WARN_UTF8,
1374 "\\x%.*s will produce malformed UTF-8 character; use \\x{%.*s} for that",
1375 (int)len,s,(int)len,s);
1383 /* \N{latin small letter a} is a named character */
1387 char* e = strchr(s, '}');
1396 yyerror("Missing right brace on \\N{}");
1400 res = newSVpvn(s + 1, e - s - 1);
1401 res = new_constant( Nullch, 0, "charnames",
1402 res, Nullsv, "\\N{...}" );
1403 str = SvPV(res,len);
1404 if (len > e - s + 4) {
1405 char *odest = SvPVX(sv);
1407 SvGROW(sv, (SvCUR(sv) + len - (e - s + 4)));
1408 d = SvPVX(sv) + (d - odest);
1410 Copy(str, d, len, char);
1417 yyerror("Missing braces on \\N{}");
1420 /* \c is a control character */
1434 /* printf-style backslashes, formfeeds, newlines, etc */
1452 *d++ = '\047'; /* CP 1047 */
1455 *d++ = '\057'; /* CP 1047 */
1469 } /* end if (backslash) */
1472 } /* while loop to process each character */
1474 /* terminate the string and set up the sv */
1476 SvCUR_set(sv, d - SvPVX(sv));
1481 /* shrink the sv if we allocated more than we used */
1482 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1483 SvLEN_set(sv, SvCUR(sv) + 1);
1484 Renew(SvPVX(sv), SvLEN(sv), char);
1487 /* return the substring (via yylval) only if we parsed anything */
1488 if (s > PL_bufptr) {
1489 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1490 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1492 ( PL_lex_inwhat == OP_TRANS
1494 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1497 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1504 * Returns TRUE if there's more to the expression (e.g., a subscript),
1507 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
1509 * ->[ and ->{ return TRUE
1510 * { and [ outside a pattern are always subscripts, so return TRUE
1511 * if we're outside a pattern and it's not { or [, then return FALSE
1512 * if we're in a pattern and the first char is a {
1513 * {4,5} (any digits around the comma) returns FALSE
1514 * if we're in a pattern and the first char is a [
1516 * [SOMETHING] has a funky algorithm to decide whether it's a
1517 * character class or not. It has to deal with things like
1518 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
1519 * anything else returns TRUE
1522 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1525 S_intuit_more(pTHX_ register char *s)
1527 if (PL_lex_brackets)
1529 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1531 if (*s != '{' && *s != '[')
1536 /* In a pattern, so maybe we have {n,m}. */
1553 /* On the other hand, maybe we have a character class */
1556 if (*s == ']' || *s == '^')
1559 /* this is terrifying, and it works */
1560 int weight = 2; /* let's weigh the evidence */
1562 unsigned char un_char = 255, last_un_char;
1563 char *send = strchr(s,']');
1564 char tmpbuf[sizeof PL_tokenbuf * 4];
1566 if (!send) /* has to be an expression */
1569 Zero(seen,256,char);
1572 else if (isDIGIT(*s)) {
1574 if (isDIGIT(s[1]) && s[2] == ']')
1580 for (; s < send; s++) {
1581 last_un_char = un_char;
1582 un_char = (unsigned char)*s;
1587 weight -= seen[un_char] * 10;
1588 if (isALNUM_lazy_if(s+1,UTF)) {
1589 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
1590 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
1595 else if (*s == '$' && s[1] &&
1596 strchr("[#!%*<>()-=",s[1])) {
1597 if (/*{*/ strchr("])} =",s[2]))
1606 if (strchr("wds]",s[1]))
1608 else if (seen['\''] || seen['"'])
1610 else if (strchr("rnftbxcav",s[1]))
1612 else if (isDIGIT(s[1])) {
1614 while (s[1] && isDIGIT(s[1]))
1624 if (strchr("aA01! ",last_un_char))
1626 if (strchr("zZ79~",s[1]))
1628 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
1629 weight -= 5; /* cope with negative subscript */
1632 if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) &&
1633 isALPHA(*s) && s[1] && isALPHA(s[1])) {
1638 if (keyword(tmpbuf, d - tmpbuf))
1641 if (un_char == last_un_char + 1)
1643 weight -= seen[un_char];
1648 if (weight >= 0) /* probably a character class */
1658 * Does all the checking to disambiguate
1660 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
1661 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
1663 * First argument is the stuff after the first token, e.g. "bar".
1665 * Not a method if bar is a filehandle.
1666 * Not a method if foo is a subroutine prototyped to take a filehandle.
1667 * Not a method if it's really "Foo $bar"
1668 * Method if it's "foo $bar"
1669 * Not a method if it's really "print foo $bar"
1670 * Method if it's really "foo package::" (interpreted as package->foo)
1671 * Not a method if bar is known to be a subroutne ("sub bar; foo bar")
1672 * Not a method if bar is a filehandle or package, but is quoted with
1677 S_intuit_method(pTHX_ char *start, GV *gv)
1679 char *s = start + (*start == '$');
1680 char tmpbuf[sizeof PL_tokenbuf];
1688 if ((cv = GvCVu(gv))) {
1689 char *proto = SvPVX(cv);
1699 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
1700 /* start is the beginning of the possible filehandle/object,
1701 * and s is the end of it
1702 * tmpbuf is a copy of it
1705 if (*start == '$') {
1706 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
1711 return *s == '(' ? FUNCMETH : METHOD;
1713 if (!keyword(tmpbuf, len)) {
1714 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
1719 indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
1720 if (indirgv && GvCVu(indirgv))
1722 /* filehandle or package name makes it a method */
1723 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
1725 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
1726 return 0; /* no assumptions -- "=>" quotes bearword */
1728 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
1729 newSVpvn(tmpbuf,len));
1730 PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
1734 return *s == '(' ? FUNCMETH : METHOD;
1742 * Return a string of Perl code to load the debugger. If PERL5DB
1743 * is set, it will return the contents of that, otherwise a
1744 * compile-time require of perl5db.pl.
1751 char *pdb = PerlEnv_getenv("PERL5DB");
1755 SETERRNO(0,SS$_NORMAL);
1756 return "BEGIN { require 'perl5db.pl' }";
1762 /* Encoded script support. filter_add() effectively inserts a
1763 * 'pre-processing' function into the current source input stream.
1764 * Note that the filter function only applies to the current source file
1765 * (e.g., it will not affect files 'require'd or 'use'd by this one).
1767 * The datasv parameter (which may be NULL) can be used to pass
1768 * private data to this instance of the filter. The filter function
1769 * can recover the SV using the FILTER_DATA macro and use it to
1770 * store private buffers and state information.
1772 * The supplied datasv parameter is upgraded to a PVIO type
1773 * and the IoDIRP field is used to store the function pointer,
1774 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
1775 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
1776 * private use must be set using malloc'd pointers.
1780 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
1785 if (!PL_rsfp_filters)
1786 PL_rsfp_filters = newAV();
1788 datasv = NEWSV(255,0);
1789 if (!SvUPGRADE(datasv, SVt_PVIO))
1790 Perl_die(aTHX_ "Can't upgrade filter_add data to SVt_PVIO");
1791 IoDIRP(datasv) = (DIR*)funcp; /* stash funcp into spare field */
1792 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
1793 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
1794 funcp, SvPV_nolen(datasv)));
1795 av_unshift(PL_rsfp_filters, 1);
1796 av_store(PL_rsfp_filters, 0, datasv) ;
1801 /* Delete most recently added instance of this filter function. */
1803 Perl_filter_del(pTHX_ filter_t funcp)
1806 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", funcp));
1807 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
1809 /* if filter is on top of stack (usual case) just pop it off */
1810 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
1811 if (IoDIRP(datasv) == (DIR*)funcp) {
1812 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
1813 IoDIRP(datasv) = (DIR*)NULL;
1814 sv_free(av_pop(PL_rsfp_filters));
1818 /* we need to search for the correct entry and clear it */
1819 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
1823 /* Invoke the n'th filter function for the current rsfp. */
1825 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
1828 /* 0 = read one text line */
1833 if (!PL_rsfp_filters)
1835 if (idx > AvFILLp(PL_rsfp_filters)){ /* Any more filters? */
1836 /* Provide a default input filter to make life easy. */
1837 /* Note that we append to the line. This is handy. */
1838 DEBUG_P(PerlIO_printf(Perl_debug_log,
1839 "filter_read %d: from rsfp\n", idx));
1843 int old_len = SvCUR(buf_sv) ;
1845 /* ensure buf_sv is large enough */
1846 SvGROW(buf_sv, old_len + maxlen) ;
1847 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
1848 if (PerlIO_error(PL_rsfp))
1849 return -1; /* error */
1851 return 0 ; /* end of file */
1853 SvCUR_set(buf_sv, old_len + len) ;
1856 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
1857 if (PerlIO_error(PL_rsfp))
1858 return -1; /* error */
1860 return 0 ; /* end of file */
1863 return SvCUR(buf_sv);
1865 /* Skip this filter slot if filter has been deleted */
1866 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef){
1867 DEBUG_P(PerlIO_printf(Perl_debug_log,
1868 "filter_read %d: skipped (filter deleted)\n",
1870 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
1872 /* Get function pointer hidden within datasv */
1873 funcp = (filter_t)IoDIRP(datasv);
1874 DEBUG_P(PerlIO_printf(Perl_debug_log,
1875 "filter_read %d: via function %p (%s)\n",
1876 idx, funcp, SvPV_nolen(datasv)));
1877 /* Call function. The function is expected to */
1878 /* call "FILTER_READ(idx+1, buf_sv)" first. */
1879 /* Return: <0:error, =0:eof, >0:not eof */
1880 return (*funcp)(aTHXo_ idx, buf_sv, maxlen);
1884 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
1886 #ifdef PERL_CR_FILTER
1887 if (!PL_rsfp_filters) {
1888 filter_add(S_cr_textfilter,NULL);
1891 if (PL_rsfp_filters) {
1894 SvCUR_set(sv, 0); /* start with empty line */
1895 if (FILTER_READ(0, sv, 0) > 0)
1896 return ( SvPVX(sv) ) ;
1901 return (sv_gets(sv, fp, append));
1906 static char* exp_name[] =
1907 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
1908 "ATTRTERM", "TERMBLOCK"
1915 Works out what to call the token just pulled out of the input
1916 stream. The yacc parser takes care of taking the ops we return and
1917 stitching them into a tree.
1923 if read an identifier
1924 if we're in a my declaration
1925 croak if they tried to say my($foo::bar)
1926 build the ops for a my() declaration
1927 if it's an access to a my() variable
1928 are we in a sort block?
1929 croak if my($a); $a <=> $b
1930 build ops for access to a my() variable
1931 if in a dq string, and they've said @foo and we can't find @foo
1933 build ops for a bareword
1934 if we already built the token before, use it.
1938 #ifdef USE_PURE_BISON
1939 Perl_yylex(pTHX_ YYSTYPE *lvalp, int *lcharp)
1952 #ifdef USE_PURE_BISON
1953 yylval_pointer = lvalp;
1954 yychar_pointer = lcharp;
1957 /* check if there's an identifier for us to look at */
1958 if (PL_pending_ident) {
1959 /* pit holds the identifier we read and pending_ident is reset */
1960 char pit = PL_pending_ident;
1961 PL_pending_ident = 0;
1963 /* if we're in a my(), we can't allow dynamics here.
1964 $foo'bar has already been turned into $foo::bar, so
1965 just check for colons.
1967 if it's a legal name, the OP is a PADANY.
1970 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
1971 if (strchr(PL_tokenbuf,':'))
1972 yyerror(Perl_form(aTHX_ "No package name allowed for "
1973 "variable %s in \"our\"",
1975 tmp = pad_allocmy(PL_tokenbuf);
1978 if (strchr(PL_tokenbuf,':'))
1979 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
1981 yylval.opval = newOP(OP_PADANY, 0);
1982 yylval.opval->op_targ = pad_allocmy(PL_tokenbuf);
1988 build the ops for accesses to a my() variable.
1990 Deny my($a) or my($b) in a sort block, *if* $a or $b is
1991 then used in a comparison. This catches most, but not
1992 all cases. For instance, it catches
1993 sort { my($a); $a <=> $b }
1995 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
1996 (although why you'd do that is anyone's guess).
1999 if (!strchr(PL_tokenbuf,':')) {
2001 /* Check for single character per-thread SVs */
2002 if (PL_tokenbuf[0] == '$' && PL_tokenbuf[2] == '\0'
2003 && !isALPHA(PL_tokenbuf[1]) /* Rule out obvious non-threadsvs */
2004 && (tmp = find_threadsv(&PL_tokenbuf[1])) != NOT_IN_PAD)
2006 yylval.opval = newOP(OP_THREADSV, 0);
2007 yylval.opval->op_targ = tmp;
2010 #endif /* USE_THREADS */
2011 if ((tmp = pad_findmy(PL_tokenbuf)) != NOT_IN_PAD) {
2012 SV *namesv = AvARRAY(PL_comppad_name)[tmp];
2013 /* might be an "our" variable" */
2014 if (SvFLAGS(namesv) & SVpad_OUR) {
2015 /* build ops for a bareword */
2016 SV *sym = newSVpv(HvNAME(GvSTASH(namesv)),0);
2017 sv_catpvn(sym, "::", 2);
2018 sv_catpv(sym, PL_tokenbuf+1);
2019 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
2020 yylval.opval->op_private = OPpCONST_ENTERED;
2021 gv_fetchpv(SvPVX(sym),
2023 ? (GV_ADDMULTI | GV_ADDINEVAL)
2026 ((PL_tokenbuf[0] == '$') ? SVt_PV
2027 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
2032 /* if it's a sort block and they're naming $a or $b */
2033 if (PL_last_lop_op == OP_SORT &&
2034 PL_tokenbuf[0] == '$' &&
2035 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
2038 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
2039 d < PL_bufend && *d != '\n';
2042 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
2043 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
2049 yylval.opval = newOP(OP_PADANY, 0);
2050 yylval.opval->op_targ = tmp;
2056 Whine if they've said @foo in a doublequoted string,
2057 and @foo isn't a variable we can find in the symbol
2060 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
2061 GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
2062 if (!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
2063 yyerror(Perl_form(aTHX_ "In string, %s now must be written as \\%s",
2064 PL_tokenbuf, PL_tokenbuf));
2067 /* build ops for a bareword */
2068 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
2069 yylval.opval->op_private = OPpCONST_ENTERED;
2070 gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
2071 ((PL_tokenbuf[0] == '$') ? SVt_PV
2072 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
2077 /* no identifier pending identification */
2079 switch (PL_lex_state) {
2081 case LEX_NORMAL: /* Some compilers will produce faster */
2082 case LEX_INTERPNORMAL: /* code if we comment these out. */
2086 /* when we've already built the next token, just pull it out of the queue */
2089 yylval = PL_nextval[PL_nexttoke];
2091 PL_lex_state = PL_lex_defer;
2092 PL_expect = PL_lex_expect;
2093 PL_lex_defer = LEX_NORMAL;
2095 return(PL_nexttype[PL_nexttoke]);
2097 /* interpolated case modifiers like \L \U, including \Q and \E.
2098 when we get here, PL_bufptr is at the \
2100 case LEX_INTERPCASEMOD:
2102 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2103 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2105 /* handle \E or end of string */
2106 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2110 if (PL_lex_casemods) {
2111 oldmod = PL_lex_casestack[--PL_lex_casemods];
2112 PL_lex_casestack[PL_lex_casemods] = '\0';
2114 if (PL_bufptr != PL_bufend && strchr("LUQ", oldmod)) {
2116 PL_lex_state = LEX_INTERPCONCAT;
2120 if (PL_bufptr != PL_bufend)
2122 PL_lex_state = LEX_INTERPCONCAT;
2127 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2128 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
2129 if (strchr("LU", *s) &&
2130 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U')))
2132 PL_lex_casestack[--PL_lex_casemods] = '\0';
2135 if (PL_lex_casemods > 10) {
2136 char* newlb = Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2137 if (newlb != PL_lex_casestack) {
2139 PL_lex_casestack = newlb;
2142 PL_lex_casestack[PL_lex_casemods++] = *s;
2143 PL_lex_casestack[PL_lex_casemods] = '\0';
2144 PL_lex_state = LEX_INTERPCONCAT;
2145 PL_nextval[PL_nexttoke].ival = 0;
2148 PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2150 PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2152 PL_nextval[PL_nexttoke].ival = OP_LC;
2154 PL_nextval[PL_nexttoke].ival = OP_UC;
2156 PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2158 Perl_croak(aTHX_ "panic: yylex");
2161 if (PL_lex_starts) {
2170 case LEX_INTERPPUSH:
2171 return sublex_push();
2173 case LEX_INTERPSTART:
2174 if (PL_bufptr == PL_bufend)
2175 return sublex_done();
2177 PL_lex_dojoin = (*PL_bufptr == '@');
2178 PL_lex_state = LEX_INTERPNORMAL;
2179 if (PL_lex_dojoin) {
2180 PL_nextval[PL_nexttoke].ival = 0;
2183 PL_nextval[PL_nexttoke].opval = newOP(OP_THREADSV, 0);
2184 PL_nextval[PL_nexttoke].opval->op_targ = find_threadsv("\"");
2185 force_next(PRIVATEREF);
2187 force_ident("\"", '$');
2188 #endif /* USE_THREADS */
2189 PL_nextval[PL_nexttoke].ival = 0;
2191 PL_nextval[PL_nexttoke].ival = 0;
2193 PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
2196 if (PL_lex_starts++) {
2202 case LEX_INTERPENDMAYBE:
2203 if (intuit_more(PL_bufptr)) {
2204 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
2210 if (PL_lex_dojoin) {
2211 PL_lex_dojoin = FALSE;
2212 PL_lex_state = LEX_INTERPCONCAT;
2215 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2216 && SvEVALED(PL_lex_repl))
2218 if (PL_bufptr != PL_bufend)
2219 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2220 PL_lex_repl = Nullsv;
2223 case LEX_INTERPCONCAT:
2225 if (PL_lex_brackets)
2226 Perl_croak(aTHX_ "panic: INTERPCONCAT");
2228 if (PL_bufptr == PL_bufend)
2229 return sublex_done();
2231 if (SvIVX(PL_linestr) == '\'') {
2232 SV *sv = newSVsv(PL_linestr);
2235 else if ( PL_hints & HINT_NEW_RE )
2236 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2237 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2241 s = scan_const(PL_bufptr);
2243 PL_lex_state = LEX_INTERPCASEMOD;
2245 PL_lex_state = LEX_INTERPSTART;
2248 if (s != PL_bufptr) {
2249 PL_nextval[PL_nexttoke] = yylval;
2252 if (PL_lex_starts++)
2262 PL_lex_state = LEX_NORMAL;
2263 s = scan_formline(PL_bufptr);
2264 if (!PL_lex_formbrack)
2270 PL_oldoldbufptr = PL_oldbufptr;
2273 PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at %s\n",
2274 exp_name[PL_expect], s);
2280 if (isIDFIRST_lazy_if(s,UTF))
2282 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2285 goto fake_eof; /* emulate EOF on ^D or ^Z */
2290 if (PL_lex_brackets)
2291 yyerror("Missing right curly or square bracket");
2294 if (s++ < PL_bufend)
2295 goto retry; /* ignore stray nulls */
2298 if (!PL_in_eval && !PL_preambled) {
2299 PL_preambled = TRUE;
2300 sv_setpv(PL_linestr,incl_perldb());
2301 if (SvCUR(PL_linestr))
2302 sv_catpv(PL_linestr,";");
2304 while(AvFILLp(PL_preambleav) >= 0) {
2305 SV *tmpsv = av_shift(PL_preambleav);
2306 sv_catsv(PL_linestr, tmpsv);
2307 sv_catpv(PL_linestr, ";");
2310 sv_free((SV*)PL_preambleav);
2311 PL_preambleav = NULL;
2313 if (PL_minus_n || PL_minus_p) {
2314 sv_catpv(PL_linestr, "LINE: while (<>) {");
2316 sv_catpv(PL_linestr,"chomp;");
2318 GV* gv = gv_fetchpv("::F", TRUE, SVt_PVAV);
2320 GvIMPORTED_AV_on(gv);
2322 if (strchr("/'\"", *PL_splitstr)
2323 && strchr(PL_splitstr + 1, *PL_splitstr))
2324 Perl_sv_catpvf(aTHX_ PL_linestr, "@F=split(%s);", PL_splitstr);
2327 s = "'~#\200\1'"; /* surely one char is unused...*/
2328 while (s[1] && strchr(PL_splitstr, *s)) s++;
2330 Perl_sv_catpvf(aTHX_ PL_linestr, "@F=split(%s%c",
2331 "q" + (delim == '\''), delim);
2332 for (s = PL_splitstr; *s; s++) {
2334 sv_catpvn(PL_linestr, "\\", 1);
2335 sv_catpvn(PL_linestr, s, 1);
2337 Perl_sv_catpvf(aTHX_ PL_linestr, "%c);", delim);
2341 sv_catpv(PL_linestr,"@F=split(' ');");
2344 sv_catpv(PL_linestr, "\n");
2345 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2346 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2347 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2348 SV *sv = NEWSV(85,0);
2350 sv_upgrade(sv, SVt_PVMG);
2351 sv_setsv(sv,PL_linestr);
2352 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2357 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2360 if (PL_preprocess && !PL_in_eval)
2361 (void)PerlProc_pclose(PL_rsfp);
2362 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2363 PerlIO_clearerr(PL_rsfp);
2365 (void)PerlIO_close(PL_rsfp);
2367 PL_doextract = FALSE;
2369 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2370 sv_setpv(PL_linestr,PL_minus_p ? ";}continue{print" : "");
2371 sv_catpv(PL_linestr,";}");
2372 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2373 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2374 PL_minus_n = PL_minus_p = 0;
2377 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2378 sv_setpv(PL_linestr,"");
2379 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
2382 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
2383 PL_doextract = FALSE;
2385 /* Incest with pod. */
2386 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2387 sv_setpv(PL_linestr, "");
2388 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2389 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2390 PL_doextract = FALSE;
2394 } while (PL_doextract);
2395 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2396 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2397 SV *sv = NEWSV(85,0);
2399 sv_upgrade(sv, SVt_PVMG);
2400 sv_setsv(sv,PL_linestr);
2401 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2403 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2404 if (CopLINE(PL_curcop) == 1) {
2405 while (s < PL_bufend && isSPACE(*s))
2407 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2411 if (*s == '#' && *(s+1) == '!')
2413 #ifdef ALTERNATE_SHEBANG
2415 static char as[] = ALTERNATE_SHEBANG;
2416 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2417 d = s + (sizeof(as) - 1);
2419 #endif /* ALTERNATE_SHEBANG */
2428 while (*d && !isSPACE(*d))
2432 #ifdef ARG_ZERO_IS_SCRIPT
2433 if (ipathend > ipath) {
2435 * HP-UX (at least) sets argv[0] to the script name,
2436 * which makes $^X incorrect. And Digital UNIX and Linux,
2437 * at least, set argv[0] to the basename of the Perl
2438 * interpreter. So, having found "#!", we'll set it right.
2440 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV));
2441 assert(SvPOK(x) || SvGMAGICAL(x));
2442 if (sv_eq(x, CopFILESV(PL_curcop))) {
2443 sv_setpvn(x, ipath, ipathend - ipath);
2446 TAINT_NOT; /* $^X is always tainted, but that's OK */
2448 #endif /* ARG_ZERO_IS_SCRIPT */
2453 d = instr(s,"perl -");
2455 d = instr(s,"perl");
2457 /* avoid getting into infinite loops when shebang
2458 * line contains "Perl" rather than "perl" */
2460 for (d = ipathend-4; d >= ipath; --d) {
2461 if ((*d == 'p' || *d == 'P')
2462 && !ibcmp(d, "perl", 4))
2472 #ifdef ALTERNATE_SHEBANG
2474 * If the ALTERNATE_SHEBANG on this system starts with a
2475 * character that can be part of a Perl expression, then if
2476 * we see it but not "perl", we're probably looking at the
2477 * start of Perl code, not a request to hand off to some
2478 * other interpreter. Similarly, if "perl" is there, but
2479 * not in the first 'word' of the line, we assume the line
2480 * contains the start of the Perl program.
2482 if (d && *s != '#') {
2484 while (*c && !strchr("; \t\r\n\f\v#", *c))
2487 d = Nullch; /* "perl" not in first word; ignore */
2489 *s = '#'; /* Don't try to parse shebang line */
2491 #endif /* ALTERNATE_SHEBANG */
2496 !instr(s,"indir") &&
2497 instr(PL_origargv[0],"perl"))
2503 while (s < PL_bufend && isSPACE(*s))
2505 if (s < PL_bufend) {
2506 Newz(899,newargv,PL_origargc+3,char*);
2508 while (s < PL_bufend && !isSPACE(*s))
2511 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2514 newargv = PL_origargv;
2516 PerlProc_execv(ipath, newargv);
2517 Perl_croak(aTHX_ "Can't exec %s", ipath);
2520 U32 oldpdb = PL_perldb;
2521 bool oldn = PL_minus_n;
2522 bool oldp = PL_minus_p;
2524 while (*d && !isSPACE(*d)) d++;
2525 while (*d == ' ' || *d == '\t') d++;
2529 if (*d == 'M' || *d == 'm') {
2531 while (*d && !isSPACE(*d)) d++;
2532 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2535 d = moreswitches(d);
2537 if (PERLDB_LINE && !oldpdb ||
2538 ( PL_minus_n || PL_minus_p ) && !(oldn || oldp) )
2539 /* if we have already added "LINE: while (<>) {",
2540 we must not do it again */
2542 sv_setpv(PL_linestr, "");
2543 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2544 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2545 PL_preambled = FALSE;
2547 (void)gv_fetchfile(PL_origfilename);
2554 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2556 PL_lex_state = LEX_FORMLINE;
2561 #ifdef PERL_STRICT_CR
2562 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
2564 "(Maybe you didn't strip carriage returns after a network transfer?)\n");
2566 case ' ': case '\t': case '\f': case 013:
2571 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
2573 while (s < d && *s != '\n')
2578 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2580 PL_lex_state = LEX_FORMLINE;
2590 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2595 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2598 if (strnEQ(s,"=>",2)) {
2599 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
2600 OPERATOR('-'); /* unary minus */
2602 PL_last_uni = PL_oldbufptr;
2603 PL_last_lop_op = OP_FTEREAD; /* good enough */
2605 case 'r': FTST(OP_FTEREAD);
2606 case 'w': FTST(OP_FTEWRITE);
2607 case 'x': FTST(OP_FTEEXEC);
2608 case 'o': FTST(OP_FTEOWNED);
2609 case 'R': FTST(OP_FTRREAD);
2610 case 'W': FTST(OP_FTRWRITE);
2611 case 'X': FTST(OP_FTREXEC);
2612 case 'O': FTST(OP_FTROWNED);
2613 case 'e': FTST(OP_FTIS);
2614 case 'z': FTST(OP_FTZERO);
2615 case 's': FTST(OP_FTSIZE);
2616 case 'f': FTST(OP_FTFILE);
2617 case 'd': FTST(OP_FTDIR);
2618 case 'l': FTST(OP_FTLINK);
2619 case 'p': FTST(OP_FTPIPE);
2620 case 'S': FTST(OP_FTSOCK);
2621 case 'u': FTST(OP_FTSUID);
2622 case 'g': FTST(OP_FTSGID);
2623 case 'k': FTST(OP_FTSVTX);
2624 case 'b': FTST(OP_FTBLK);
2625 case 'c': FTST(OP_FTCHR);
2626 case 't': FTST(OP_FTTTY);
2627 case 'T': FTST(OP_FTTEXT);
2628 case 'B': FTST(OP_FTBINARY);
2629 case 'M': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTMTIME);
2630 case 'A': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTATIME);
2631 case 'C': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTCTIME);
2633 Perl_croak(aTHX_ "Unrecognized file test: -%c", (int)tmp);
2640 if (PL_expect == XOPERATOR)
2645 else if (*s == '>') {
2648 if (isIDFIRST_lazy_if(s,UTF)) {
2649 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
2657 if (PL_expect == XOPERATOR)
2660 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2662 OPERATOR('-'); /* unary minus */
2669 if (PL_expect == XOPERATOR)
2674 if (PL_expect == XOPERATOR)
2677 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2683 if (PL_expect != XOPERATOR) {
2684 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
2685 PL_expect = XOPERATOR;
2686 force_ident(PL_tokenbuf, '*');
2699 if (PL_expect == XOPERATOR) {
2703 PL_tokenbuf[0] = '%';
2704 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
2705 if (!PL_tokenbuf[1]) {
2707 yyerror("Final % should be \\% or %name");
2710 PL_pending_ident = '%';
2729 switch (PL_expect) {
2732 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
2734 PL_bufptr = s; /* update in case we back off */
2740 PL_expect = XTERMBLOCK;
2744 while (isIDFIRST_lazy_if(s,UTF)) {
2745 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
2746 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
2747 if (tmp < 0) tmp = -tmp;
2762 d = scan_str(d,TRUE,TRUE);
2765 SvREFCNT_dec(PL_lex_stuff);
2766 PL_lex_stuff = Nullsv;
2768 /* MUST advance bufptr here to avoid bogus
2769 "at end of line" context messages from yyerror().
2771 PL_bufptr = s + len;
2772 yyerror("Unterminated attribute parameter in attribute list");
2775 return 0; /* EOF indicator */
2779 SV *sv = newSVpvn(s, len);
2780 sv_catsv(sv, PL_lex_stuff);
2781 attrs = append_elem(OP_LIST, attrs,
2782 newSVOP(OP_CONST, 0, sv));
2783 SvREFCNT_dec(PL_lex_stuff);
2784 PL_lex_stuff = Nullsv;
2787 attrs = append_elem(OP_LIST, attrs,
2788 newSVOP(OP_CONST, 0,
2792 if (*s == ':' && s[1] != ':')
2795 break; /* require real whitespace or :'s */
2797 tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
2798 if (*s != ';' && *s != tmp && (tmp != '=' || *s != ')')) {
2799 char q = ((*s == '\'') ? '"' : '\'');
2800 /* If here for an expression, and parsed no attrs, back off. */
2801 if (tmp == '=' && !attrs) {
2805 /* MUST advance bufptr here to avoid bogus "at end of line"
2806 context messages from yyerror().
2810 yyerror("Unterminated attribute list");
2812 yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
2820 PL_nextval[PL_nexttoke].opval = attrs;
2828 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
2829 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
2834 if (CopLINE(PL_curcop) < PL_copline)
2835 PL_copline = CopLINE(PL_curcop);
2846 if (PL_lex_brackets <= 0)
2847 yyerror("Unmatched right square bracket");
2850 if (PL_lex_state == LEX_INTERPNORMAL) {
2851 if (PL_lex_brackets == 0) {
2852 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
2853 PL_lex_state = LEX_INTERPEND;
2860 if (PL_lex_brackets > 100) {
2861 char* newlb = Renew(PL_lex_brackstack, PL_lex_brackets + 1, char);
2862 if (newlb != PL_lex_brackstack) {
2864 PL_lex_brackstack = newlb;
2867 switch (PL_expect) {
2869 if (PL_lex_formbrack) {
2873 if (PL_oldoldbufptr == PL_last_lop)
2874 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
2876 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
2877 OPERATOR(HASHBRACK);
2879 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2882 PL_tokenbuf[0] = '\0';
2883 if (d < PL_bufend && *d == '-') {
2884 PL_tokenbuf[0] = '-';
2886 while (d < PL_bufend && (*d == ' ' || *d == '\t'))
2889 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
2890 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
2892 while (d < PL_bufend && (*d == ' ' || *d == '\t'))
2895 char minus = (PL_tokenbuf[0] == '-');
2896 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
2904 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
2909 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
2914 if (PL_oldoldbufptr == PL_last_lop)
2915 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
2917 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
2920 OPERATOR(HASHBRACK);
2921 /* This hack serves to disambiguate a pair of curlies
2922 * as being a block or an anon hash. Normally, expectation
2923 * determines that, but in cases where we're not in a
2924 * position to expect anything in particular (like inside
2925 * eval"") we have to resolve the ambiguity. This code
2926 * covers the case where the first term in the curlies is a
2927 * quoted string. Most other cases need to be explicitly
2928 * disambiguated by prepending a `+' before the opening
2929 * curly in order to force resolution as an anon hash.
2931 * XXX should probably propagate the outer expectation
2932 * into eval"" to rely less on this hack, but that could
2933 * potentially break current behavior of eval"".
2937 if (*s == '\'' || *s == '"' || *s == '`') {
2938 /* common case: get past first string, handling escapes */
2939 for (t++; t < PL_bufend && *t != *s;)
2940 if (*t++ == '\\' && (*t == '\\' || *t == *s))
2944 else if (*s == 'q') {
2947 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
2951 char open, close, term;
2954 while (t < PL_bufend && isSPACE(*t))
2958 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
2962 for (t++; t < PL_bufend; t++) {
2963 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
2965 else if (*t == open)
2969 for (t++; t < PL_bufend; t++) {
2970 if (*t == '\\' && t+1 < PL_bufend)
2972 else if (*t == close && --brackets <= 0)
2974 else if (*t == open)
2980 else if (isALNUM_lazy_if(t,UTF)) {
2982 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
2985 while (t < PL_bufend && isSPACE(*t))
2987 /* if comma follows first term, call it an anon hash */
2988 /* XXX it could be a comma expression with loop modifiers */
2989 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
2990 || (*t == '=' && t[1] == '>')))
2991 OPERATOR(HASHBRACK);
2992 if (PL_expect == XREF)
2995 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3001 yylval.ival = CopLINE(PL_curcop);
3002 if (isSPACE(*s) || *s == '#')
3003 PL_copline = NOLINE; /* invalidate current command line number */
3008 if (PL_lex_brackets <= 0)
3009 yyerror("Unmatched right curly bracket");
3011 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3012 if (PL_lex_brackets < PL_lex_formbrack)
3013 PL_lex_formbrack = 0;
3014 if (PL_lex_state == LEX_INTERPNORMAL) {
3015 if (PL_lex_brackets == 0) {
3016 if (PL_expect & XFAKEBRACK) {
3017 PL_expect &= XENUMMASK;
3018 PL_lex_state = LEX_INTERPEND;
3020 return yylex(); /* ignore fake brackets */
3022 if (*s == '-' && s[1] == '>')
3023 PL_lex_state = LEX_INTERPENDMAYBE;
3024 else if (*s != '[' && *s != '{')
3025 PL_lex_state = LEX_INTERPEND;
3028 if (PL_expect & XFAKEBRACK) {
3029 PL_expect &= XENUMMASK;
3031 return yylex(); /* ignore fake brackets */
3041 if (PL_expect == XOPERATOR) {
3042 if (ckWARN(WARN_SEMICOLON)
3043 && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart)
3045 CopLINE_dec(PL_curcop);
3046 Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi);
3047 CopLINE_inc(PL_curcop);
3052 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3054 PL_expect = XOPERATOR;
3055 force_ident(PL_tokenbuf, '&');
3059 yylval.ival = (OPpENTERSUB_AMPER<<8);
3078 if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
3079 Perl_warner(aTHX_ WARN_SYNTAX, "Reversed %c= operator",(int)tmp);
3081 if (PL_expect == XSTATE && isALPHA(tmp) &&
3082 (s == PL_linestart+1 || s[-2] == '\n') )
3084 if (PL_in_eval && !PL_rsfp) {
3089 if (strnEQ(s,"=cut",4)) {
3103 PL_doextract = TRUE;
3106 if (PL_lex_brackets < PL_lex_formbrack) {
3108 #ifdef PERL_STRICT_CR
3109 for (t = s; *t == ' ' || *t == '\t'; t++) ;
3111 for (t = s; *t == ' ' || *t == '\t' || *t == '\r'; t++) ;
3113 if (*t == '\n' || *t == '#') {
3131 if (PL_expect != XOPERATOR) {
3132 if (s[1] != '<' && !strchr(s,'>'))
3135 s = scan_heredoc(s);
3137 s = scan_inputsymbol(s);
3138 TERM(sublex_start());
3143 SHop(OP_LEFT_SHIFT);
3157 SHop(OP_RIGHT_SHIFT);
3166 if (PL_expect == XOPERATOR) {
3167 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3170 return ','; /* grandfather non-comma-format format */
3174 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3175 PL_tokenbuf[0] = '@';
3176 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3177 sizeof PL_tokenbuf - 1, FALSE);
3178 if (PL_expect == XOPERATOR)
3179 no_op("Array length", s);
3180 if (!PL_tokenbuf[1])
3182 PL_expect = XOPERATOR;
3183 PL_pending_ident = '#';
3187 PL_tokenbuf[0] = '$';
3188 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3189 sizeof PL_tokenbuf - 1, FALSE);
3190 if (PL_expect == XOPERATOR)
3192 if (!PL_tokenbuf[1]) {
3194 yyerror("Final $ should be \\$ or $name");
3198 /* This kludge not intended to be bulletproof. */
3199 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3200 yylval.opval = newSVOP(OP_CONST, 0,
3201 newSViv((IV)PL_compiling.cop_arybase));
3202 yylval.opval->op_private = OPpCONST_ARYBASE;
3208 if (PL_lex_state == LEX_NORMAL)
3211 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3214 PL_tokenbuf[0] = '@';
3215 if (ckWARN(WARN_SYNTAX)) {
3217 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3220 PL_bufptr = skipspace(PL_bufptr);
3221 while (t < PL_bufend && *t != ']')
3223 Perl_warner(aTHX_ WARN_SYNTAX,
3224 "Multidimensional syntax %.*s not supported",
3225 (t - PL_bufptr) + 1, PL_bufptr);
3229 else if (*s == '{') {
3230 PL_tokenbuf[0] = '%';
3231 if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") &&
3232 (t = strchr(s, '}')) && (t = strchr(t, '=')))
3234 char tmpbuf[sizeof PL_tokenbuf];
3236 for (t++; isSPACE(*t); t++) ;
3237 if (isIDFIRST_lazy_if(t,UTF)) {
3238 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3239 for (; isSPACE(*t); t++) ;
3240 if (*t == ';' && get_cv(tmpbuf, FALSE))
3241 Perl_warner(aTHX_ WARN_SYNTAX,
3242 "You need to quote \"%s\"", tmpbuf);
3248 PL_expect = XOPERATOR;
3249 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3250 bool islop = (PL_last_lop == PL_oldoldbufptr);
3251 if (!islop || PL_last_lop_op == OP_GREPSTART)
3252 PL_expect = XOPERATOR;
3253 else if (strchr("$@\"'`q", *s))
3254 PL_expect = XTERM; /* e.g. print $fh "foo" */
3255 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3256 PL_expect = XTERM; /* e.g. print $fh &sub */
3257 else if (isIDFIRST_lazy_if(s,UTF)) {
3258 char tmpbuf[sizeof PL_tokenbuf];
3259 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3260 if (tmp = keyword(tmpbuf, len)) {
3261 /* binary operators exclude handle interpretations */
3273 PL_expect = XTERM; /* e.g. print $fh length() */
3278 GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
3279 if (gv && GvCVu(gv))
3280 PL_expect = XTERM; /* e.g. print $fh subr() */
3283 else if (isDIGIT(*s))
3284 PL_expect = XTERM; /* e.g. print $fh 3 */
3285 else if (*s == '.' && isDIGIT(s[1]))
3286 PL_expect = XTERM; /* e.g. print $fh .3 */
3287 else if (strchr("/?-+", *s) && !isSPACE(s[1]) && s[1] != '=')
3288 PL_expect = XTERM; /* e.g. print $fh -1 */
3289 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3290 PL_expect = XTERM; /* print $fh <<"EOF" */
3292 PL_pending_ident = '$';
3296 if (PL_expect == XOPERATOR)
3298 PL_tokenbuf[0] = '@';
3299 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3300 if (!PL_tokenbuf[1]) {
3302 yyerror("Final @ should be \\@ or @name");
3305 if (PL_lex_state == LEX_NORMAL)
3307 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3309 PL_tokenbuf[0] = '%';
3311 /* Warn about @ where they meant $. */
3312 if (ckWARN(WARN_SYNTAX)) {
3313 if (*s == '[' || *s == '{') {
3315 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3317 if (*t == '}' || *t == ']') {
3319 PL_bufptr = skipspace(PL_bufptr);
3320 Perl_warner(aTHX_ WARN_SYNTAX,
3321 "Scalar value %.*s better written as $%.*s",
3322 t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3327 PL_pending_ident = '@';
3330 case '/': /* may either be division or pattern */
3331 case '?': /* may either be conditional or pattern */
3332 if (PL_expect != XOPERATOR) {
3333 /* Disable warning on "study /blah/" */
3334 if (PL_oldoldbufptr == PL_last_uni
3335 && (*PL_last_uni != 's' || s - PL_last_uni < 5
3336 || memNE(PL_last_uni, "study", 5)
3337 || isALNUM_lazy_if(PL_last_uni+5,UTF)))
3339 s = scan_pat(s,OP_MATCH);
3340 TERM(sublex_start());
3348 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3349 #ifdef PERL_STRICT_CR
3352 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3354 && (s == PL_linestart || s[-1] == '\n') )
3356 PL_lex_formbrack = 0;
3360 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3366 yylval.ival = OPf_SPECIAL;
3372 if (PL_expect != XOPERATOR)
3377 case '0': case '1': case '2': case '3': case '4':
3378 case '5': case '6': case '7': case '8': case '9':
3380 if (PL_expect == XOPERATOR)
3385 s = scan_str(s,FALSE,FALSE);
3386 if (PL_expect == XOPERATOR) {
3387 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3390 return ','; /* grandfather non-comma-format format */
3396 missingterm((char*)0);
3397 yylval.ival = OP_CONST;
3398 TERM(sublex_start());
3401 s = scan_str(s,FALSE,FALSE);
3402 if (PL_expect == XOPERATOR) {
3403 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3406 return ','; /* grandfather non-comma-format format */
3412 missingterm((char*)0);
3413 yylval.ival = OP_CONST;
3414 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3415 if (*d == '$' || *d == '@' || *d == '\\' || *d & 0x80) {
3416 yylval.ival = OP_STRINGIFY;
3420 TERM(sublex_start());
3423 s = scan_str(s,FALSE,FALSE);
3424 if (PL_expect == XOPERATOR)
3425 no_op("Backticks",s);
3427 missingterm((char*)0);
3428 yylval.ival = OP_BACKTICK;
3430 TERM(sublex_start());
3434 if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s))
3435 Perl_warner(aTHX_ WARN_SYNTAX,"Can't use \\%c to mean $%c in expression",
3437 if (PL_expect == XOPERATOR)
3438 no_op("Backslash",s);
3442 if (isDIGIT(s[1]) && PL_expect == XTERM) {
3446 while (isDIGIT(*start))
3448 if (*start == '.' && isDIGIT(start[1])) {
3455 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
3495 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3497 /* Some keywords can be followed by any delimiter, including ':' */
3498 tmp = (len == 1 && strchr("msyq", PL_tokenbuf[0]) ||
3499 len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
3500 (PL_tokenbuf[0] == 'q' &&
3501 strchr("qwxr", PL_tokenbuf[1]))));
3503 /* x::* is just a word, unless x is "CORE" */
3504 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
3508 while (d < PL_bufend && isSPACE(*d))
3509 d++; /* no comments skipped here, or s### is misparsed */
3511 /* Is this a label? */
3512 if (!tmp && PL_expect == XSTATE
3513 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
3515 yylval.pval = savepv(PL_tokenbuf);
3520 /* Check for keywords */
3521 tmp = keyword(PL_tokenbuf, len);
3523 /* Is this a word before a => operator? */
3524 if (strnEQ(d,"=>",2)) {
3526 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf,0));
3527 yylval.opval->op_private = OPpCONST_BARE;
3531 if (tmp < 0) { /* second-class keyword? */
3532 GV *ogv = Nullgv; /* override (winner) */
3533 GV *hgv = Nullgv; /* hidden (loser) */
3534 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
3536 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
3539 if (GvIMPORTED_CV(gv))
3541 else if (! CvMETHOD(cv))
3545 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
3546 (gv = *gvp) != (GV*)&PL_sv_undef &&
3547 GvCVu(gv) && GvIMPORTED_CV(gv))
3553 tmp = 0; /* overridden by import or by GLOBAL */
3556 && -tmp==KEY_lock /* XXX generalizable kludge */
3558 && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
3560 tmp = 0; /* any sub overrides "weak" keyword */
3562 else { /* no override */
3566 if (ckWARN(WARN_AMBIGUOUS) && hgv
3567 && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
3568 Perl_warner(aTHX_ WARN_AMBIGUOUS,
3569 "Ambiguous call resolved as CORE::%s(), %s",
3570 GvENAME(hgv), "qualify as such or use &");
3577 default: /* not a keyword */
3580 char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
3582 /* Get the rest if it looks like a package qualifier */
3584 if (*s == '\'' || *s == ':' && s[1] == ':') {
3586 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
3589 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
3590 *s == '\'' ? "'" : "::");
3594 if (PL_expect == XOPERATOR) {
3595 if (PL_bufptr == PL_linestart) {
3596 CopLINE_dec(PL_curcop);
3597 Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi);
3598 CopLINE_inc(PL_curcop);
3601 no_op("Bareword",s);
3604 /* Look for a subroutine with this name in current package,
3605 unless name is "Foo::", in which case Foo is a bearword
3606 (and a package name). */
3609 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
3611 if (ckWARN(WARN_UNSAFE) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
3612 Perl_warner(aTHX_ WARN_UNSAFE,
3613 "Bareword \"%s\" refers to nonexistent package",
3616 PL_tokenbuf[len] = '\0';
3623 gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
3626 /* if we saw a global override before, get the right name */
3629 sv = newSVpvn("CORE::GLOBAL::",14);
3630 sv_catpv(sv,PL_tokenbuf);
3633 sv = newSVpv(PL_tokenbuf,0);
3635 /* Presume this is going to be a bareword of some sort. */
3638 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3639 yylval.opval->op_private = OPpCONST_BARE;
3641 /* And if "Foo::", then that's what it certainly is. */
3646 /* See if it's the indirect object for a list operator. */
3648 if (PL_oldoldbufptr &&
3649 PL_oldoldbufptr < PL_bufptr &&
3650 (PL_oldoldbufptr == PL_last_lop
3651 || PL_oldoldbufptr == PL_last_uni) &&
3652 /* NO SKIPSPACE BEFORE HERE! */
3653 (PL_expect == XREF ||
3654 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
3656 bool immediate_paren = *s == '(';
3658 /* (Now we can afford to cross potential line boundary.) */
3661 /* Two barewords in a row may indicate method call. */
3663 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv)))
3666 /* If not a declared subroutine, it's an indirect object. */
3667 /* (But it's an indir obj regardless for sort.) */
3669 if ((PL_last_lop_op == OP_SORT ||
3670 (!immediate_paren && (!gv || !GvCVu(gv)))) &&
3671 (PL_last_lop_op != OP_MAPSTART &&
3672 PL_last_lop_op != OP_GREPSTART))
3674 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
3679 /* If followed by a paren, it's certainly a subroutine. */
3681 PL_expect = XOPERATOR;
3685 if (gv && GvCVu(gv)) {
3686 for (d = s + 1; *d == ' ' || *d == '\t'; d++) ;
3687 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
3692 PL_nextval[PL_nexttoke].opval = yylval.opval;
3693 PL_expect = XOPERATOR;
3699 /* If followed by var or block, call it a method (unless sub) */
3701 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
3702 PL_last_lop = PL_oldbufptr;
3703 PL_last_lop_op = OP_METHOD;
3707 /* If followed by a bareword, see if it looks like indir obj. */
3709 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp = intuit_method(s,gv)))
3712 /* Not a method, so call it a subroutine (if defined) */
3714 if (gv && GvCVu(gv)) {
3716 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
3717 Perl_warner(aTHX_ WARN_AMBIGUOUS,
3718 "Ambiguous use of -%s resolved as -&%s()",
3719 PL_tokenbuf, PL_tokenbuf);
3720 /* Check for a constant sub */
3722 if ((sv = cv_const_sv(cv))) {
3724 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
3725 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
3726 yylval.opval->op_private = 0;
3730 /* Resolve to GV now. */
3731 op_free(yylval.opval);
3732 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
3733 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
3734 PL_last_lop = PL_oldbufptr;
3735 PL_last_lop_op = OP_ENTERSUB;
3736 /* Is there a prototype? */
3739 char *proto = SvPV((SV*)cv, len);
3742 if (strEQ(proto, "$"))
3744 if (*proto == '&' && *s == '{') {
3745 sv_setpv(PL_subname,"__ANON__");
3749 PL_nextval[PL_nexttoke].opval = yylval.opval;
3755 /* Call it a bare word */
3757 if (PL_hints & HINT_STRICT_SUBS)
3758 yylval.opval->op_private |= OPpCONST_STRICT;
3761 if (ckWARN(WARN_RESERVED)) {
3762 if (lastchar != '-') {
3763 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
3765 Perl_warner(aTHX_ WARN_RESERVED, PL_warn_reserved,
3772 if (lastchar && strchr("*%&", lastchar) && ckWARN_d(WARN_AMBIGUOUS)) {
3773 Perl_warner(aTHX_ WARN_AMBIGUOUS,
3774 "Operator or semicolon missing before %c%s",
3775 lastchar, PL_tokenbuf);
3776 Perl_warner(aTHX_ WARN_AMBIGUOUS,
3777 "Ambiguous use of %c resolved as operator %c",
3778 lastchar, lastchar);
3784 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3785 newSVpv(CopFILE(PL_curcop),0));
3789 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3790 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
3793 case KEY___PACKAGE__:
3794 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3796 ? newSVsv(PL_curstname)
3805 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
3806 char *pname = "main";
3807 if (PL_tokenbuf[2] == 'D')
3808 pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash);
3809 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);
3812 GvIOp(gv) = newIO();
3813 IoIFP(GvIOp(gv)) = PL_rsfp;
3814 #if defined(HAS_FCNTL) && defined(F_SETFD)
3816 int fd = PerlIO_fileno(PL_rsfp);
3817 fcntl(fd,F_SETFD,fd >= 3);
3820 /* Mark this internal pseudo-handle as clean */
3821 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
3823 IoTYPE(GvIOp(gv)) = '|';
3824 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
3825 IoTYPE(GvIOp(gv)) = '-';
3827 IoTYPE(GvIOp(gv)) = '<';
3828 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
3829 /* if the script was opened in binmode, we need to revert
3830 * it to text mode for compatibility; but only iff it has CRs
3831 * XXX this is a questionable hack at best. */
3832 if (PL_bufend-PL_bufptr > 2
3833 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
3836 if (IoTYPE(GvIOp(gv)) == '<') {
3837 loc = PerlIO_tell(PL_rsfp);
3838 (void)PerlIO_seek(PL_rsfp, 0L, 0);
3840 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
3841 #if defined(__BORLANDC__)
3842 /* XXX see note in do_binmode() */
3843 ((FILE*)PL_rsfp)->flags |= _F_BIN;
3846 PerlIO_seek(PL_rsfp, loc, 0);
3861 if (PL_expect == XSTATE) {
3868 if (*s == ':' && s[1] == ':') {
3871 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3872 tmp = keyword(PL_tokenbuf, len);
3886 LOP(OP_ACCEPT,XTERM);
3892 LOP(OP_ATAN2,XTERM);
3901 LOP(OP_BLESS,XTERM);
3910 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
3927 if (!PL_cryptseen) {
3928 PL_cryptseen = TRUE;
3932 LOP(OP_CRYPT,XTERM);
3935 if (ckWARN(WARN_OCTAL)) {
3936 for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ;
3937 if (*d != '0' && isDIGIT(*d))
3938 Perl_warner(aTHX_ WARN_OCTAL,
3939 "chmod: mode argument is missing initial 0");
3941 LOP(OP_CHMOD,XTERM);
3944 LOP(OP_CHOWN,XTERM);
3947 LOP(OP_CONNECT,XTERM);
3963 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3967 PL_hints |= HINT_BLOCK_SCOPE;
3977 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
3978 LOP(OP_DBMOPEN,XTERM);
3984 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3991 yylval.ival = CopLINE(PL_curcop);
4005 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4006 UNIBRACK(OP_ENTEREVAL);
4021 case KEY_endhostent:
4027 case KEY_endservent:
4030 case KEY_endprotoent:
4041 yylval.ival = CopLINE(PL_curcop);
4043 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4045 if ((PL_bufend - p) >= 3 &&
4046 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4048 else if ((PL_bufend - p) >= 4 &&
4049 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4052 if (isIDFIRST_lazy_if(p,UTF)) {
4053 p = scan_ident(p, PL_bufend,
4054 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4058 Perl_croak(aTHX_ "Missing $ on loop variable");
4063 LOP(OP_FORMLINE,XTERM);
4069 LOP(OP_FCNTL,XTERM);
4075 LOP(OP_FLOCK,XTERM);
4084 LOP(OP_GREPSTART, XREF);
4087 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4102 case KEY_getpriority:
4103 LOP(OP_GETPRIORITY,XTERM);
4105 case KEY_getprotobyname:
4108 case KEY_getprotobynumber:
4109 LOP(OP_GPBYNUMBER,XTERM);
4111 case KEY_getprotoent:
4123 case KEY_getpeername:
4124 UNI(OP_GETPEERNAME);
4126 case KEY_gethostbyname:
4129 case KEY_gethostbyaddr:
4130 LOP(OP_GHBYADDR,XTERM);
4132 case KEY_gethostent:
4135 case KEY_getnetbyname:
4138 case KEY_getnetbyaddr:
4139 LOP(OP_GNBYADDR,XTERM);
4144 case KEY_getservbyname:
4145 LOP(OP_GSBYNAME,XTERM);
4147 case KEY_getservbyport:
4148 LOP(OP_GSBYPORT,XTERM);
4150 case KEY_getservent:
4153 case KEY_getsockname:
4154 UNI(OP_GETSOCKNAME);
4156 case KEY_getsockopt:
4157 LOP(OP_GSOCKOPT,XTERM);
4179 yylval.ival = CopLINE(PL_curcop);
4183 LOP(OP_INDEX,XTERM);
4189 LOP(OP_IOCTL,XTERM);
4201 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4233 LOP(OP_LISTEN,XTERM);
4242 s = scan_pat(s,OP_MATCH);
4243 TERM(sublex_start());
4246 LOP(OP_MAPSTART, XREF);
4249 LOP(OP_MKDIR,XTERM);
4252 LOP(OP_MSGCTL,XTERM);
4255 LOP(OP_MSGGET,XTERM);
4258 LOP(OP_MSGRCV,XTERM);
4261 LOP(OP_MSGSND,XTERM);
4267 if (isIDFIRST_lazy_if(s,UTF)) {
4268 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4269 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4271 PL_in_my_stash = gv_stashpv(PL_tokenbuf, FALSE);
4272 if (!PL_in_my_stash) {
4275 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4283 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4290 if (PL_expect != XSTATE)
4291 yyerror("\"no\" not allowed in expression");
4292 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4293 s = force_version(s);
4298 if (*s == '(' || (s = skipspace(s), *s == '('))
4305 if (isIDFIRST_lazy_if(s,UTF)) {
4307 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
4309 if (strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_AMBIGUOUS))
4310 Perl_warner(aTHX_ WARN_AMBIGUOUS,
4311 "Precedence problem: open %.*s should be open(%.*s)",
4317 yylval.ival = OP_OR;
4327 LOP(OP_OPEN_DIR,XTERM);
4330 checkcomma(s,PL_tokenbuf,"filehandle");
4334 checkcomma(s,PL_tokenbuf,"filehandle");
4353 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4357 LOP(OP_PIPE_OP,XTERM);
4360 s = scan_str(s,FALSE,FALSE);
4362 missingterm((char*)0);
4363 yylval.ival = OP_CONST;
4364 TERM(sublex_start());
4370 s = scan_str(s,FALSE,FALSE);
4372 missingterm((char*)0);
4374 if (SvCUR(PL_lex_stuff)) {
4377 d = SvPV_force(PL_lex_stuff, len);
4379 for (; isSPACE(*d) && len; --len, ++d) ;
4382 if (!warned && ckWARN(WARN_SYNTAX)) {
4383 for (; !isSPACE(*d) && len; --len, ++d) {
4385 Perl_warner(aTHX_ WARN_SYNTAX,
4386 "Possible attempt to separate words with commas");
4389 else if (*d == '#') {
4390 Perl_warner(aTHX_ WARN_SYNTAX,
4391 "Possible attempt to put comments in qw() list");
4397 for (; !isSPACE(*d) && len; --len, ++d) ;
4399 words = append_elem(OP_LIST, words,
4400 newSVOP(OP_CONST, 0, newSVpvn(b, d-b)));
4404 PL_nextval[PL_nexttoke].opval = words;
4409 SvREFCNT_dec(PL_lex_stuff);
4410 PL_lex_stuff = Nullsv;
4415 s = scan_str(s,FALSE,FALSE);
4417 missingterm((char*)0);
4418 yylval.ival = OP_STRINGIFY;
4419 if (SvIVX(PL_lex_stuff) == '\'')
4420 SvIVX(PL_lex_stuff) = 0; /* qq'$foo' should intepolate */
4421 TERM(sublex_start());
4424 s = scan_pat(s,OP_QR);
4425 TERM(sublex_start());
4428 s = scan_str(s,FALSE,FALSE);
4430 missingterm((char*)0);
4431 yylval.ival = OP_BACKTICK;
4433 TERM(sublex_start());
4440 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
4441 s = force_version(s);
4444 *PL_tokenbuf = '\0';
4445 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4446 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
4447 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
4449 yyerror("<> should be quotes");
4457 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4461 LOP(OP_RENAME,XTERM);
4470 LOP(OP_RINDEX,XTERM);
4493 LOP(OP_REVERSE,XTERM);
4504 TERM(sublex_start());
4506 TOKEN(1); /* force error */
4515 LOP(OP_SELECT,XTERM);
4521 LOP(OP_SEMCTL,XTERM);
4524 LOP(OP_SEMGET,XTERM);
4527 LOP(OP_SEMOP,XTERM);
4533 LOP(OP_SETPGRP,XTERM);
4535 case KEY_setpriority:
4536 LOP(OP_SETPRIORITY,XTERM);
4538 case KEY_sethostent:
4544 case KEY_setservent:
4547 case KEY_setprotoent:
4557 LOP(OP_SEEKDIR,XTERM);
4559 case KEY_setsockopt:
4560 LOP(OP_SSOCKOPT,XTERM);
4566 LOP(OP_SHMCTL,XTERM);
4569 LOP(OP_SHMGET,XTERM);
4572 LOP(OP_SHMREAD,XTERM);
4575 LOP(OP_SHMWRITE,XTERM);
4578 LOP(OP_SHUTDOWN,XTERM);
4587 LOP(OP_SOCKET,XTERM);
4589 case KEY_socketpair:
4590 LOP(OP_SOCKPAIR,XTERM);
4593 checkcomma(s,PL_tokenbuf,"subroutine name");
4595 if (*s == ';' || *s == ')') /* probably a close */
4596 Perl_croak(aTHX_ "sort is now a reserved word");
4598 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4602 LOP(OP_SPLIT,XTERM);
4605 LOP(OP_SPRINTF,XTERM);
4608 LOP(OP_SPLICE,XTERM);
4623 LOP(OP_SUBSTR,XTERM);
4629 char tmpbuf[sizeof PL_tokenbuf];
4631 expectation attrful;
4632 bool have_name, have_proto;
4637 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
4638 (*s == ':' && s[1] == ':'))
4641 attrful = XATTRBLOCK;
4642 /* remember buffer pos'n for later force_word */
4643 tboffset = s - PL_oldbufptr;
4644 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4645 if (strchr(tmpbuf, ':'))
4646 sv_setpv(PL_subname, tmpbuf);
4648 sv_setsv(PL_subname,PL_curstname);
4649 sv_catpvn(PL_subname,"::",2);
4650 sv_catpvn(PL_subname,tmpbuf,len);
4657 Perl_croak(aTHX_ "Missing name in \"my sub\"");
4658 PL_expect = XTERMBLOCK;
4659 attrful = XATTRTERM;
4660 sv_setpv(PL_subname,"?");
4664 if (key == KEY_format) {
4666 PL_lex_formbrack = PL_lex_brackets + 1;
4668 (void) force_word(PL_oldbufptr + tboffset, WORD,
4673 /* Look for a prototype */
4677 s = scan_str(s,FALSE,FALSE);
4680 SvREFCNT_dec(PL_lex_stuff);
4681 PL_lex_stuff = Nullsv;
4682 Perl_croak(aTHX_ "Prototype not terminated");
4685 d = SvPVX(PL_lex_stuff);
4687 for (p = d; *p; ++p) {
4692 SvCUR(PL_lex_stuff) = tmp;
4700 if (*s == ':' && s[1] != ':')
4701 PL_expect = attrful;
4704 PL_nextval[PL_nexttoke].opval =
4705 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
4706 PL_lex_stuff = Nullsv;
4710 sv_setpv(PL_subname,"__ANON__");
4713 (void) force_word(PL_oldbufptr + tboffset, WORD,
4722 LOP(OP_SYSTEM,XREF);
4725 LOP(OP_SYMLINK,XTERM);
4728 LOP(OP_SYSCALL,XTERM);
4731 LOP(OP_SYSOPEN,XTERM);
4734 LOP(OP_SYSSEEK,XTERM);
4737 LOP(OP_SYSREAD,XTERM);
4740 LOP(OP_SYSWRITE,XTERM);
4744 TERM(sublex_start());
4765 LOP(OP_TRUNCATE,XTERM);
4777 yylval.ival = CopLINE(PL_curcop);
4781 yylval.ival = CopLINE(PL_curcop);
4785 LOP(OP_UNLINK,XTERM);
4791 LOP(OP_UNPACK,XTERM);
4794 LOP(OP_UTIME,XTERM);
4797 if (ckWARN(WARN_OCTAL)) {
4798 for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ;
4799 if (*d != '0' && isDIGIT(*d))
4800 Perl_warner(aTHX_ WARN_OCTAL,
4801 "umask: argument is missing initial 0");
4806 LOP(OP_UNSHIFT,XTERM);
4809 if (PL_expect != XSTATE)
4810 yyerror("\"use\" not allowed in expression");
4812 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
4813 s = force_version(s);
4814 if (*s == ';' || (s = skipspace(s), *s == ';')) {
4815 PL_nextval[PL_nexttoke].opval = Nullop;
4820 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4821 s = force_version(s);
4833 yylval.ival = CopLINE(PL_curcop);
4837 PL_hints |= HINT_BLOCK_SCOPE;
4844 LOP(OP_WAITPID,XTERM);
4852 static char ctl_l[2];
4854 if (ctl_l[0] == '\0')
4855 ctl_l[0] = toCTRL('L');
4856 gv_fetchpv(ctl_l,TRUE, SVt_PV);
4859 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
4864 if (PL_expect == XOPERATOR)
4870 yylval.ival = OP_XOR;
4875 TERM(sublex_start());
4881 Perl_keyword(pTHX_ register char *d, I32 len)
4886 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
4887 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
4888 if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__;
4889 if (strEQ(d,"__DATA__")) return KEY___DATA__;
4890 if (strEQ(d,"__END__")) return KEY___END__;
4894 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
4899 if (strEQ(d,"and")) return -KEY_and;
4900 if (strEQ(d,"abs")) return -KEY_abs;
4903 if (strEQ(d,"alarm")) return -KEY_alarm;
4904 if (strEQ(d,"atan2")) return -KEY_atan2;
4907 if (strEQ(d,"accept")) return -KEY_accept;
4912 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
4915 if (strEQ(d,"bless")) return -KEY_bless;
4916 if (strEQ(d,"bind")) return -KEY_bind;
4917 if (strEQ(d,"binmode")) return -KEY_binmode;
4920 if (strEQ(d,"CORE")) return -KEY_CORE;
4921 if (strEQ(d,"CHECK")) return KEY_CHECK;
4926 if (strEQ(d,"cmp")) return -KEY_cmp;
4927 if (strEQ(d,"chr")) return -KEY_chr;
4928 if (strEQ(d,"cos")) return -KEY_cos;
4931 if (strEQ(d,"chop")) return KEY_chop;
4934 if (strEQ(d,"close")) return -KEY_close;
4935 if (strEQ(d,"chdir")) return -KEY_chdir;
4936 if (strEQ(d,"chomp")) return KEY_chomp;
4937 if (strEQ(d,"chmod")) return -KEY_chmod;
4938 if (strEQ(d,"chown")) return -KEY_chown;
4939 if (strEQ(d,"crypt")) return -KEY_crypt;
4942 if (strEQ(d,"chroot")) return -KEY_chroot;
4943 if (strEQ(d,"caller")) return -KEY_caller;
4946 if (strEQ(d,"connect")) return -KEY_connect;
4949 if (strEQ(d,"closedir")) return -KEY_closedir;
4950 if (strEQ(d,"continue")) return -KEY_continue;
4955 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
4960 if (strEQ(d,"do")) return KEY_do;
4963 if (strEQ(d,"die")) return -KEY_die;
4966 if (strEQ(d,"dump")) return -KEY_dump;
4969 if (strEQ(d,"delete")) return KEY_delete;
4972 if (strEQ(d,"defined")) return KEY_defined;
4973 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
4976 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
4981 if (strEQ(d,"EQ")) { deprecate(d); return -KEY_eq;}
4982 if (strEQ(d,"END")) return KEY_END;
4987 if (strEQ(d,"eq")) return -KEY_eq;
4990 if (strEQ(d,"eof")) return -KEY_eof;
4991 if (strEQ(d,"exp")) return -KEY_exp;
4994 if (strEQ(d,"else")) return KEY_else;
4995 if (strEQ(d,"exit")) return -KEY_exit;
4996 if (strEQ(d,"eval")) return KEY_eval;
4997 if (strEQ(d,"exec")) return -KEY_exec;
4998 if (strEQ(d,"each")) return KEY_each;
5001 if (strEQ(d,"elsif")) return KEY_elsif;
5004 if (strEQ(d,"exists")) return KEY_exists;
5005 if (strEQ(d,"elseif")) Perl_warn(aTHX_ "elseif should be elsif");
5008 if (strEQ(d,"endgrent")) return -KEY_endgrent;
5009 if (strEQ(d,"endpwent")) return -KEY_endpwent;
5012 if (strEQ(d,"endnetent")) return -KEY_endnetent;
5015 if (strEQ(d,"endhostent")) return -KEY_endhostent;
5016 if (strEQ(d,"endservent")) return -KEY_endservent;
5019 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
5026 if (strEQ(d,"for")) return KEY_for;
5029 if (strEQ(d,"fork")) return -KEY_fork;
5032 if (strEQ(d,"fcntl")) return -KEY_fcntl;
5033 if (strEQ(d,"flock")) return -KEY_flock;
5036 if (strEQ(d,"format")) return KEY_format;
5037 if (strEQ(d,"fileno")) return -KEY_fileno;
5040 if (strEQ(d,"foreach")) return KEY_foreach;
5043 if (strEQ(d,"formline")) return -KEY_formline;
5049 if (strEQ(d,"GT")) { deprecate(d); return -KEY_gt;}
5050 if (strEQ(d,"GE")) { deprecate(d); return -KEY_ge;}
5054 if (strnEQ(d,"get",3)) {
5059 if (strEQ(d,"ppid")) return -KEY_getppid;
5060 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
5063 if (strEQ(d,"pwent")) return -KEY_getpwent;
5064 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
5065 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
5068 if (strEQ(d,"peername")) return -KEY_getpeername;
5069 if (strEQ(d,"protoent")) return -KEY_getprotoent;
5070 if (strEQ(d,"priority")) return -KEY_getpriority;
5073 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
5076 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
5080 else if (*d == 'h') {
5081 if (strEQ(d,"hostbyname")) return -KEY_gethostbyname;
5082 if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr;
5083 if (strEQ(d,"hostent")) return -KEY_gethostent;
5085 else if (*d == 'n') {
5086 if (strEQ(d,"netbyname")) return -KEY_getnetbyname;
5087 if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr;
5088 if (strEQ(d,"netent")) return -KEY_getnetent;
5090 else if (*d == 's') {
5091 if (strEQ(d,"servbyname")) return -KEY_getservbyname;
5092 if (strEQ(d,"servbyport")) return -KEY_getservbyport;
5093 if (strEQ(d,"servent")) return -KEY_getservent;
5094 if (strEQ(d,"sockname")) return -KEY_getsockname;
5095 if (strEQ(d,"sockopt")) return -KEY_getsockopt;
5097 else if (*d == 'g') {
5098 if (strEQ(d,"grent")) return -KEY_getgrent;
5099 if (strEQ(d,"grnam")) return -KEY_getgrnam;
5100 if (strEQ(d,"grgid")) return -KEY_getgrgid;
5102 else if (*d == 'l') {
5103 if (strEQ(d,"login")) return -KEY_getlogin;
5105 else if (strEQ(d,"c")) return -KEY_getc;
5110 if (strEQ(d,"gt")) return -KEY_gt;
5111 if (strEQ(d,"ge")) return -KEY_ge;
5114 if (strEQ(d,"grep")) return KEY_grep;
5115 if (strEQ(d,"goto")) return KEY_goto;
5116 if (strEQ(d,"glob")) return KEY_glob;
5119 if (strEQ(d,"gmtime")) return -KEY_gmtime;
5124 if (strEQ(d,"hex")) return -KEY_hex;
5127 if (strEQ(d,"INIT")) return KEY_INIT;
5132 if (strEQ(d,"if")) return KEY_if;
5135 if (strEQ(d,"int")) return -KEY_int;
5138 if (strEQ(d,"index")) return -KEY_index;
5139 if (strEQ(d,"ioctl")) return -KEY_ioctl;
5144 if (strEQ(d,"join")) return -KEY_join;
5148 if (strEQ(d,"keys")) return KEY_keys;
5149 if (strEQ(d,"kill")) return -KEY_kill;
5154 if (strEQ(d,"LT")) { deprecate(d); return -KEY_lt;}
5155 if (strEQ(d,"LE")) { deprecate(d); return -KEY_le;}
5161 if (strEQ(d,"lt")) return -KEY_lt;
5162 if (strEQ(d,"le")) return -KEY_le;
5163 if (strEQ(d,"lc")) return -KEY_lc;
5166 if (strEQ(d,"log")) return -KEY_log;
5169 if (strEQ(d,"last")) return KEY_last;
5170 if (strEQ(d,"link")) return -KEY_link;
5171 if (strEQ(d,"lock")) return -KEY_lock;
5174 if (strEQ(d,"local")) return KEY_local;
5175 if (strEQ(d,"lstat")) return -KEY_lstat;
5178 if (strEQ(d,"length")) return -KEY_length;
5179 if (strEQ(d,"listen")) return -KEY_listen;
5182 if (strEQ(d,"lcfirst")) return -KEY_lcfirst;
5185 if (strEQ(d,"localtime")) return -KEY_localtime;
5191 case 1: return KEY_m;
5193 if (strEQ(d,"my")) return KEY_my;
5196 if (strEQ(d,"map")) return KEY_map;
5199 if (strEQ(d,"mkdir")) return -KEY_mkdir;
5202 if (strEQ(d,"msgctl")) return -KEY_msgctl;
5203 if (strEQ(d,"msgget")) return -KEY_msgget;
5204 if (strEQ(d,"msgrcv")) return -KEY_msgrcv;
5205 if (strEQ(d,"msgsnd")) return -KEY_msgsnd;
5210 if (strEQ(d,"NE")) { deprecate(d); return -KEY_ne;}
5213 if (strEQ(d,"next")) return KEY_next;
5214 if (strEQ(d,"ne")) return -KEY_ne;
5215 if (strEQ(d,"not")) return -KEY_not;
5216 if (strEQ(d,"no")) return KEY_no;
5221 if (strEQ(d,"or")) return -KEY_or;
5224 if (strEQ(d,"ord")) return -KEY_ord;
5225 if (strEQ(d,"oct")) return -KEY_oct;
5226 if (strEQ(d,"our")) return KEY_our;
5229 if (strEQ(d,"open")) return -KEY_open;
5232 if (strEQ(d,"opendir")) return -KEY_opendir;
5239 if (strEQ(d,"pop")) return KEY_pop;
5240 if (strEQ(d,"pos")) return KEY_pos;
5243 if (strEQ(d,"push")) return KEY_push;
5244 if (strEQ(d,"pack")) return -KEY_pack;
5245 if (strEQ(d,"pipe")) return -KEY_pipe;
5248 if (strEQ(d,"print")) return KEY_print;
5251 if (strEQ(d,"printf")) return KEY_printf;
5254 if (strEQ(d,"package")) return KEY_package;
5257 if (strEQ(d,"prototype")) return KEY_prototype;
5262 if (strEQ(d,"q")) return KEY_q;
5263 if (strEQ(d,"qr")) return KEY_qr;
5264 if (strEQ(d,"qq")) return KEY_qq;
5265 if (strEQ(d,"qw")) return KEY_qw;
5266 if (strEQ(d,"qx")) return KEY_qx;
5268 else if (strEQ(d,"quotemeta")) return -KEY_quotemeta;
5273 if (strEQ(d,"ref")) return -KEY_ref;
5276 if (strEQ(d,"read")) return -KEY_read;
5277 if (strEQ(d,"rand")) return -KEY_rand;
5278 if (strEQ(d,"recv")) return -KEY_recv;
5279 if (strEQ(d,"redo")) return KEY_redo;
5282 if (strEQ(d,"rmdir")) return -KEY_rmdir;
5283 if (strEQ(d,"reset")) return -KEY_reset;
5286 if (strEQ(d,"return")) return KEY_return;
5287 if (strEQ(d,"rename")) return -KEY_rename;
5288 if (strEQ(d,"rindex")) return -KEY_rindex;
5291 if (strEQ(d,"require")) return -KEY_require;
5292 if (strEQ(d,"reverse")) return -KEY_reverse;
5293 if (strEQ(d,"readdir")) return -KEY_readdir;
5296 if (strEQ(d,"readlink")) return -KEY_readlink;
5297 if (strEQ(d,"readline")) return -KEY_readline;
5298 if (strEQ(d,"readpipe")) return -KEY_readpipe;
5301 if (strEQ(d,"rewinddir")) return -KEY_rewinddir;
5307 case 0: return KEY_s;
5309 if (strEQ(d,"scalar")) return KEY_scalar;
5314 if (strEQ(d,"seek")) return -KEY_seek;
5315 if (strEQ(d,"send")) return -KEY_send;
5318 if (strEQ(d,"semop")) return -KEY_semop;
5321 if (strEQ(d,"select")) return -KEY_select;
5322 if (strEQ(d,"semctl")) return -KEY_semctl;
5323 if (strEQ(d,"semget")) return -KEY_semget;
5326 if (strEQ(d,"setpgrp")) return -KEY_setpgrp;
5327 if (strEQ(d,"seekdir")) return -KEY_seekdir;
5330 if (strEQ(d,"setpwent")) return -KEY_setpwent;
5331 if (strEQ(d,"setgrent")) return -KEY_setgrent;
5334 if (strEQ(d,"setnetent")) return -KEY_setnetent;
5337 if (strEQ(d,"setsockopt")) return -KEY_setsockopt;
5338 if (strEQ(d,"sethostent")) return -KEY_sethostent;
5339 if (strEQ(d,"setservent")) return -KEY_setservent;
5342 if (strEQ(d,"setpriority")) return -KEY_setpriority;
5343 if (strEQ(d,"setprotoent")) return -KEY_setprotoent;
5350 if (strEQ(d,"shift")) return KEY_shift;
5353 if (strEQ(d,"shmctl")) return -KEY_shmctl;
5354 if (strEQ(d,"shmget")) return -KEY_shmget;
5357 if (strEQ(d,"shmread")) return -KEY_shmread;
5360 if (strEQ(d,"shmwrite")) return -KEY_shmwrite;
5361 if (strEQ(d,"shutdown")) return -KEY_shutdown;
5366 if (strEQ(d,"sin")) return -KEY_sin;
5369 if (strEQ(d,"sleep")) return -KEY_sleep;
5372 if (strEQ(d,"sort")) return KEY_sort;
5373 if (strEQ(d,"socket")) return -KEY_socket;
5374 if (strEQ(d,"socketpair")) return -KEY_socketpair;
5377 if (strEQ(d,"split")) return KEY_split;
5378 if (strEQ(d,"sprintf")) return -KEY_sprintf;
5379 if (strEQ(d,"splice")) return KEY_splice;
5382 if (strEQ(d,"sqrt")) return -KEY_sqrt;
5385 if (strEQ(d,"srand")) return -KEY_srand;
5388 if (strEQ(d,"stat")) return -KEY_stat;
5389 if (strEQ(d,"study")) return KEY_study;
5392 if (strEQ(d,"substr")) return -KEY_substr;
5393 if (strEQ(d,"sub")) return KEY_sub;
5398 if (strEQ(d,"system")) return -KEY_system;
5401 if (strEQ(d,"symlink")) return -KEY_symlink;
5402 if (strEQ(d,"syscall")) return -KEY_syscall;
5403 if (strEQ(d,"sysopen")) return -KEY_sysopen;
5404 if (strEQ(d,"sysread")) return -KEY_sysread;
5405 if (strEQ(d,"sysseek")) return -KEY_sysseek;
5408 if (strEQ(d,"syswrite")) return -KEY_syswrite;
5417 if (strEQ(d,"tr")) return KEY_tr;
5420 if (strEQ(d,"tie")) return KEY_tie;
5423 if (strEQ(d,"tell")) return -KEY_tell;
5424 if (strEQ(d,"tied")) return KEY_tied;
5425 if (strEQ(d,"time")) return -KEY_time;
5428 if (strEQ(d,"times")) return -KEY_times;
5431 if (strEQ(d,"telldir")) return -KEY_telldir;
5434 if (strEQ(d,"truncate")) return -KEY_truncate;
5441 if (strEQ(d,"uc")) return -KEY_uc;
5444 if (strEQ(d,"use")) return KEY_use;
5447 if (strEQ(d,"undef")) return KEY_undef;
5448 if (strEQ(d,"until")) return KEY_until;
5449 if (strEQ(d,"untie")) return KEY_untie;
5450 if (strEQ(d,"utime")) return -KEY_utime;
5451 if (strEQ(d,"umask")) return -KEY_umask;
5454 if (strEQ(d,"unless")) return KEY_unless;
5455 if (strEQ(d,"unpack")) return -KEY_unpack;
5456 if (strEQ(d,"unlink")) return -KEY_unlink;
5459 if (strEQ(d,"unshift")) return KEY_unshift;
5460 if (strEQ(d,"ucfirst")) return -KEY_ucfirst;
5465 if (strEQ(d,"values")) return -KEY_values;
5466 if (strEQ(d,"vec")) return -KEY_vec;
5471 if (strEQ(d,"warn")) return -KEY_warn;
5472 if (strEQ(d,"wait")) return -KEY_wait;
5475 if (strEQ(d,"while")) return KEY_while;
5476 if (strEQ(d,"write")) return -KEY_write;
5479 if (strEQ(d,"waitpid")) return -KEY_waitpid;
5482 if (strEQ(d,"wantarray")) return -KEY_wantarray;
5487 if (len == 1) return -KEY_x;
5488 if (strEQ(d,"xor")) return -KEY_xor;
5491 if (len == 1) return KEY_y;
5500 S_checkcomma(pTHX_ register char *s, char *name, char *what)
5504 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
5505 dTHR; /* only for ckWARN */
5506 if (ckWARN(WARN_SYNTAX)) {
5508 for (w = s+2; *w && level; w++) {
5515 for (; *w && isSPACE(*w); w++) ;
5516 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
5517 Perl_warner(aTHX_ WARN_SYNTAX,
5518 "%s (...) interpreted as function",name);
5521 while (s < PL_bufend && isSPACE(*s))
5525 while (s < PL_bufend && isSPACE(*s))
5527 if (isIDFIRST_lazy_if(s,UTF)) {
5529 while (isALNUM_lazy_if(s,UTF))
5531 while (s < PL_bufend && isSPACE(*s))
5536 kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
5540 Perl_croak(aTHX_ "No comma allowed after %s", what);
5545 /* Either returns sv, or mortalizes sv and returns a new SV*.
5546 Best used as sv=new_constant(..., sv, ...).
5547 If s, pv are NULL, calls subroutine with one argument,
5548 and type is used with error messages only. */
5551 S_new_constant(pTHX_ char *s, STRLEN len, const char *key, SV *sv, SV *pv,
5555 HV *table = GvHV(PL_hintgv); /* ^H */
5559 const char *why, *why1, *why2;
5561 if (!(PL_hints & HINT_LOCALIZE_HH)) {
5564 why = "%^H is not localized";
5568 msg = Perl_newSVpvf(aTHX_ "constant(%s): %s%s%s",
5569 (type ? type: "undef"), why1, why2, why);
5570 yyerror(SvPVX(msg));
5575 why = "%^H is not defined";
5578 cvp = hv_fetch(table, key, strlen(key), FALSE);
5579 if (!cvp || !SvOK(*cvp)) {
5580 why = "} is not defined";
5585 sv_2mortal(sv); /* Parent created it permanently */
5588 pv = sv_2mortal(newSVpvn(s, len));
5590 typesv = sv_2mortal(newSVpv(type, 0));
5592 typesv = &PL_sv_undef;
5594 PUSHSTACKi(PERLSI_OVERLOAD);
5607 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
5611 /* Check the eval first */
5612 if (!PL_in_eval && SvTRUE(ERRSV))
5615 sv_catpv(ERRSV, "Propagated");
5616 yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */
5618 res = SvREFCNT_inc(sv);
5622 (void)SvREFCNT_inc(res);
5631 why = "}} did not return a defined value";
5632 why1 = "Call to &{$^H{";
5642 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
5644 register char *d = dest;
5645 register char *e = d + destlen - 3; /* two-character token, ending NUL */
5648 Perl_croak(aTHX_ ident_too_long);
5649 if (isALNUM(*s)) /* UTF handled below */
5651 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
5656 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
5660 else if (UTF && *(U8*)s >= 0xc0 && isALNUM_utf8((U8*)s)) {
5661 char *t = s + UTF8SKIP(s);
5662 while (*t & 0x80 && is_utf8_mark((U8*)t))
5664 if (d + (t - s) > e)
5665 Perl_croak(aTHX_ ident_too_long);
5666 Copy(s, d, t - s, char);
5679 S_scan_ident(pTHX_ register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni)
5689 e = d + destlen - 3; /* two-character token, ending NUL */
5691 while (isDIGIT(*s)) {
5693 Perl_croak(aTHX_ ident_too_long);
5700 Perl_croak(aTHX_ ident_too_long);
5701 if (isALNUM(*s)) /* UTF handled below */
5703 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
5708 else if (*s == ':' && s[1] == ':') {
5712 else if (UTF && *(U8*)s >= 0xc0 && isALNUM_utf8((U8*)s)) {
5713 char *t = s + UTF8SKIP(s);
5714 while (*t & 0x80 && is_utf8_mark((U8*)t))
5716 if (d + (t - s) > e)
5717 Perl_croak(aTHX_ ident_too_long);
5718 Copy(s, d, t - s, char);
5729 if (PL_lex_state != LEX_NORMAL)
5730 PL_lex_state = LEX_INTERPENDMAYBE;
5733 if (*s == '$' && s[1] &&
5734 (isALNUM_lazy_if(s+1,UTF) || strchr("${", s[1]) || strnEQ(s+1,"::",2)) )
5747 if (*d == '^' && *s && isCONTROLVAR(*s)) {
5752 if (isSPACE(s[-1])) {
5755 if (ch != ' ' && ch != '\t') {
5761 if (isIDFIRST_lazy_if(d,UTF)) {
5765 while (e < send && isALNUM_lazy_if(e,UTF) || *e == ':') {
5767 while (e < send && *e & 0x80 && is_utf8_mark((U8*)e))
5770 Copy(s, d, e - s, char);
5775 while ((isALNUM(*s) || *s == ':') && d < e)
5778 Perl_croak(aTHX_ ident_too_long);
5781 while (s < send && (*s == ' ' || *s == '\t')) s++;
5782 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
5783 dTHR; /* only for ckWARN */
5784 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
5785 const char *brack = *s == '[' ? "[...]" : "{...}";
5786 Perl_warner(aTHX_ WARN_AMBIGUOUS,
5787 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
5788 funny, dest, brack, funny, dest, brack);
5791 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
5795 /* Handle extended ${^Foo} variables
5796 * 1999-02-27 mjd-perl-patch@plover.com */
5797 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
5801 while (isALNUM(*s) && d < e) {
5805 Perl_croak(aTHX_ ident_too_long);
5810 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets)
5811 PL_lex_state = LEX_INTERPEND;
5814 if (PL_lex_state == LEX_NORMAL) {
5815 dTHR; /* only for ckWARN */
5816 if (ckWARN(WARN_AMBIGUOUS) &&
5817 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
5819 Perl_warner(aTHX_ WARN_AMBIGUOUS,
5820 "Ambiguous use of %c{%s} resolved to %c%s",
5821 funny, dest, funny, dest);
5826 s = bracket; /* let the parser handle it */
5830 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
5831 PL_lex_state = LEX_INTERPEND;
5836 Perl_pmflag(pTHX_ U16 *pmfl, int ch)
5841 *pmfl |= PMf_GLOBAL;
5843 *pmfl |= PMf_CONTINUE;
5847 *pmfl |= PMf_MULTILINE;
5849 *pmfl |= PMf_SINGLELINE;
5851 *pmfl |= PMf_EXTENDED;
5855 S_scan_pat(pTHX_ char *start, I32 type)
5860 s = scan_str(start,FALSE,FALSE);
5863 SvREFCNT_dec(PL_lex_stuff);
5864 PL_lex_stuff = Nullsv;
5865 Perl_croak(aTHX_ "Search pattern not terminated");
5868 pm = (PMOP*)newPMOP(type, 0);
5869 if (PL_multi_open == '?')
5870 pm->op_pmflags |= PMf_ONCE;
5872 while (*s && strchr("iomsx", *s))
5873 pmflag(&pm->op_pmflags,*s++);
5876 while (*s && strchr("iogcmsx", *s))
5877 pmflag(&pm->op_pmflags,*s++);
5879 pm->op_pmpermflags = pm->op_pmflags;
5881 PL_lex_op = (OP*)pm;
5882 yylval.ival = OP_MATCH;
5887 S_scan_subst(pTHX_ char *start)
5894 yylval.ival = OP_NULL;
5896 s = scan_str(start,FALSE,FALSE);
5900 SvREFCNT_dec(PL_lex_stuff);
5901 PL_lex_stuff = Nullsv;
5902 Perl_croak(aTHX_ "Substitution pattern not terminated");
5905 if (s[-1] == PL_multi_open)
5908 first_start = PL_multi_start;
5909 s = scan_str(s,FALSE,FALSE);
5912 SvREFCNT_dec(PL_lex_stuff);
5913 PL_lex_stuff = Nullsv;
5915 SvREFCNT_dec(PL_lex_repl);
5916 PL_lex_repl = Nullsv;
5917 Perl_croak(aTHX_ "Substitution replacement not terminated");
5919 PL_multi_start = first_start; /* so whole substitution is taken together */
5921 pm = (PMOP*)newPMOP(OP_SUBST, 0);
5927 else if (strchr("iogcmsx", *s))
5928 pmflag(&pm->op_pmflags,*s++);
5935 PL_sublex_info.super_bufptr = s;
5936 PL_sublex_info.super_bufend = PL_bufend;
5938 pm->op_pmflags |= PMf_EVAL;
5939 repl = newSVpvn("",0);
5941 sv_catpv(repl, es ? "eval " : "do ");
5942 sv_catpvn(repl, "{ ", 2);
5943 sv_catsv(repl, PL_lex_repl);
5944 sv_catpvn(repl, " };", 2);
5946 SvREFCNT_dec(PL_lex_repl);
5950 pm->op_pmpermflags = pm->op_pmflags;
5951 PL_lex_op = (OP*)pm;
5952 yylval.ival = OP_SUBST;
5957 S_scan_trans(pTHX_ char *start)
5968 yylval.ival = OP_NULL;
5970 s = scan_str(start,FALSE,FALSE);
5973 SvREFCNT_dec(PL_lex_stuff);
5974 PL_lex_stuff = Nullsv;
5975 Perl_croak(aTHX_ "Transliteration pattern not terminated");
5977 if (s[-1] == PL_multi_open)
5980 s = scan_str(s,FALSE,FALSE);
5983 SvREFCNT_dec(PL_lex_stuff);
5984 PL_lex_stuff = Nullsv;
5986 SvREFCNT_dec(PL_lex_repl);
5987 PL_lex_repl = Nullsv;
5988 Perl_croak(aTHX_ "Transliteration replacement not terminated");
5992 o = newSVOP(OP_TRANS, 0, 0);
5993 utf8 = OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF;
5996 New(803,tbl,256,short);
5997 o = newPVOP(OP_TRANS, 0, (char*)tbl);
6001 complement = del = squash = 0;
6002 while (strchr("cdsCU", *s)) {
6004 complement = OPpTRANS_COMPLEMENT;
6006 del = OPpTRANS_DELETE;
6008 squash = OPpTRANS_SQUASH;
6013 utf8 &= ~OPpTRANS_FROM_UTF;
6015 utf8 |= OPpTRANS_FROM_UTF;
6019 utf8 &= ~OPpTRANS_TO_UTF;
6021 utf8 |= OPpTRANS_TO_UTF;
6024 Perl_croak(aTHX_ "Too many /C and /U options");
6029 o->op_private = del|squash|complement|utf8;
6032 yylval.ival = OP_TRANS;
6037 S_scan_heredoc(pTHX_ register char *s)
6041 I32 op_type = OP_SCALAR;
6048 int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
6052 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
6055 for (peek = s; *peek == ' ' || *peek == '\t'; peek++) ;
6056 if (*peek && strchr("`'\"",*peek)) {
6059 s = delimcpy(d, e, s, PL_bufend, term, &len);
6069 if (!isALNUM_lazy_if(s,UTF))
6070 deprecate("bare << to mean <<\"\"");
6071 for (; isALNUM_lazy_if(s,UTF); s++) {
6076 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
6077 Perl_croak(aTHX_ "Delimiter for here document is too long");
6080 len = d - PL_tokenbuf;
6081 #ifndef PERL_STRICT_CR
6082 d = strchr(s, '\r');
6086 while (s < PL_bufend) {
6092 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
6101 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
6106 if (outer || !(d=ninstr(s,PL_bufend,d,d+1)))
6107 herewas = newSVpvn(s,PL_bufend-s);
6109 s--, herewas = newSVpvn(s,d-s);
6110 s += SvCUR(herewas);
6112 tmpstr = NEWSV(87,79);
6113 sv_upgrade(tmpstr, SVt_PVIV);
6118 else if (term == '`') {
6119 op_type = OP_BACKTICK;
6120 SvIVX(tmpstr) = '\\';
6124 PL_multi_start = CopLINE(PL_curcop);
6125 PL_multi_open = PL_multi_close = '<';
6126 term = *PL_tokenbuf;
6127 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
6128 char *bufptr = PL_sublex_info.super_bufptr;
6129 char *bufend = PL_sublex_info.super_bufend;
6130 char *olds = s - SvCUR(herewas);
6131 s = strchr(bufptr, '\n');
6135 while (s < bufend &&
6136 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
6138 CopLINE_inc(PL_curcop);
6141 CopLINE_set(PL_curcop, PL_multi_start);
6142 missingterm(PL_tokenbuf);
6144 sv_setpvn(herewas,bufptr,d-bufptr+1);
6145 sv_setpvn(tmpstr,d+1,s-d);
6147 sv_catpvn(herewas,s,bufend-s);
6148 (void)strcpy(bufptr,SvPVX(herewas));
6155 while (s < PL_bufend &&
6156 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
6158 CopLINE_inc(PL_curcop);
6160 if (s >= PL_bufend) {
6161 CopLINE_set(PL_curcop, PL_multi_start);
6162 missingterm(PL_tokenbuf);
6164 sv_setpvn(tmpstr,d+1,s-d);
6166 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
6168 sv_catpvn(herewas,s,PL_bufend-s);
6169 sv_setsv(PL_linestr,herewas);
6170 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
6171 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6174 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
6175 while (s >= PL_bufend) { /* multiple line string? */
6177 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
6178 CopLINE_set(PL_curcop, PL_multi_start);
6179 missingterm(PL_tokenbuf);
6181 CopLINE_inc(PL_curcop);
6182 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6183 #ifndef PERL_STRICT_CR
6184 if (PL_bufend - PL_linestart >= 2) {
6185 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
6186 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
6188 PL_bufend[-2] = '\n';
6190 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
6192 else if (PL_bufend[-1] == '\r')
6193 PL_bufend[-1] = '\n';
6195 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
6196 PL_bufend[-1] = '\n';
6198 if (PERLDB_LINE && PL_curstash != PL_debstash) {
6199 SV *sv = NEWSV(88,0);
6201 sv_upgrade(sv, SVt_PVMG);
6202 sv_setsv(sv,PL_linestr);
6203 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
6205 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
6208 sv_catsv(PL_linestr,herewas);
6209 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6213 sv_catsv(tmpstr,PL_linestr);
6218 PL_multi_end = CopLINE(PL_curcop);
6219 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
6220 SvLEN_set(tmpstr, SvCUR(tmpstr) + 1);
6221 Renew(SvPVX(tmpstr), SvLEN(tmpstr), char);
6223 SvREFCNT_dec(herewas);
6224 PL_lex_stuff = tmpstr;
6225 yylval.ival = op_type;
6230 takes: current position in input buffer
6231 returns: new position in input buffer
6232 side-effects: yylval and lex_op are set.
6237 <FH> read from filehandle
6238 <pkg::FH> read from package qualified filehandle
6239 <pkg'FH> read from package qualified filehandle
6240 <$fh> read from filehandle in $fh
6246 S_scan_inputsymbol(pTHX_ char *start)
6248 register char *s = start; /* current position in buffer */
6254 d = PL_tokenbuf; /* start of temp holding space */
6255 e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
6256 end = strchr(s, '\n');
6259 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
6261 /* die if we didn't have space for the contents of the <>,
6262 or if it didn't end, or if we see a newline
6265 if (len >= sizeof PL_tokenbuf)
6266 Perl_croak(aTHX_ "Excessively long <> operator");
6268 Perl_croak(aTHX_ "Unterminated <> operator");
6273 Remember, only scalar variables are interpreted as filehandles by
6274 this code. Anything more complex (e.g., <$fh{$num}>) will be
6275 treated as a glob() call.
6276 This code makes use of the fact that except for the $ at the front,
6277 a scalar variable and a filehandle look the same.
6279 if (*d == '$' && d[1]) d++;
6281 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
6282 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
6285 /* If we've tried to read what we allow filehandles to look like, and
6286 there's still text left, then it must be a glob() and not a getline.
6287 Use scan_str to pull out the stuff between the <> and treat it
6288 as nothing more than a string.
6291 if (d - PL_tokenbuf != len) {
6292 yylval.ival = OP_GLOB;
6294 s = scan_str(start,FALSE,FALSE);
6296 Perl_croak(aTHX_ "Glob not terminated");
6300 /* we're in a filehandle read situation */
6303 /* turn <> into <ARGV> */
6305 (void)strcpy(d,"ARGV");
6307 /* if <$fh>, create the ops to turn the variable into a
6313 /* try to find it in the pad for this block, otherwise find
6314 add symbol table ops
6316 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
6317 OP *o = newOP(OP_PADSV, 0);
6319 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, o);
6322 GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV);
6323 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0,
6324 newUNOP(OP_RV2SV, 0,
6325 newGVOP(OP_GV, 0, gv)));
6327 PL_lex_op->op_flags |= OPf_SPECIAL;
6328 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
6329 yylval.ival = OP_NULL;
6332 /* If it's none of the above, it must be a literal filehandle
6333 (<Foo::BAR> or <FOO>) so build a simple readline OP */
6335 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
6336 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
6337 yylval.ival = OP_NULL;
6346 takes: start position in buffer
6347 keep_quoted preserve \ on the embedded delimiter(s)
6348 keep_delims preserve the delimiters around the string
6349 returns: position to continue reading from buffer
6350 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
6351 updates the read buffer.
6353 This subroutine pulls a string out of the input. It is called for:
6354 q single quotes q(literal text)
6355 ' single quotes 'literal text'
6356 qq double quotes qq(interpolate $here please)
6357 " double quotes "interpolate $here please"
6358 qx backticks qx(/bin/ls -l)
6359 ` backticks `/bin/ls -l`
6360 qw quote words @EXPORT_OK = qw( func() $spam )
6361 m// regexp match m/this/
6362 s/// regexp substitute s/this/that/
6363 tr/// string transliterate tr/this/that/
6364 y/// string transliterate y/this/that/
6365 ($*@) sub prototypes sub foo ($)
6366 (stuff) sub attr parameters sub foo : attr(stuff)
6367 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
6369 In most of these cases (all but <>, patterns and transliterate)
6370 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
6371 calls scan_str(). s/// makes yylex() call scan_subst() which calls
6372 scan_str(). tr/// and y/// make yylex() call scan_trans() which
6375 It skips whitespace before the string starts, and treats the first
6376 character as the delimiter. If the delimiter is one of ([{< then
6377 the corresponding "close" character )]}> is used as the closing
6378 delimiter. It allows quoting of delimiters, and if the string has
6379 balanced delimiters ([{<>}]) it allows nesting.
6381 The lexer always reads these strings into lex_stuff, except in the
6382 case of the operators which take *two* arguments (s/// and tr///)
6383 when it checks to see if lex_stuff is full (presumably with the 1st
6384 arg to s or tr) and if so puts the string into lex_repl.
6389 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
6392 SV *sv; /* scalar value: string */
6393 char *tmps; /* temp string, used for delimiter matching */
6394 register char *s = start; /* current position in the buffer */
6395 register char term; /* terminating character */
6396 register char *to; /* current position in the sv's data */
6397 I32 brackets = 1; /* bracket nesting level */
6398 bool has_utf = FALSE; /* is there any utf8 content? */
6400 /* skip space before the delimiter */
6404 /* mark where we are, in case we need to report errors */
6407 /* after skipping whitespace, the next character is the terminator */
6409 if ((term & 0x80) && UTF)
6412 /* mark where we are */
6413 PL_multi_start = CopLINE(PL_curcop);
6414 PL_multi_open = term;
6416 /* find corresponding closing delimiter */
6417 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
6419 PL_multi_close = term;
6421 /* create a new SV to hold the contents. 87 is leak category, I'm
6422 assuming. 79 is the SV's initial length. What a random number. */
6424 sv_upgrade(sv, SVt_PVIV);
6426 (void)SvPOK_only(sv); /* validate pointer */
6428 /* move past delimiter and try to read a complete string */
6430 sv_catpvn(sv, s, 1);
6433 /* extend sv if need be */
6434 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
6435 /* set 'to' to the next character in the sv's string */
6436 to = SvPVX(sv)+SvCUR(sv);
6438 /* if open delimiter is the close delimiter read unbridle */
6439 if (PL_multi_open == PL_multi_close) {
6440 for (; s < PL_bufend; s++,to++) {
6441 /* embedded newlines increment the current line number */
6442 if (*s == '\n' && !PL_rsfp)
6443 CopLINE_inc(PL_curcop);
6444 /* handle quoted delimiters */
6445 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
6446 if (!keep_quoted && s[1] == term)
6448 /* any other quotes are simply copied straight through */
6452 /* terminate when run out of buffer (the for() condition), or
6453 have found the terminator */
6454 else if (*s == term)
6456 else if (!has_utf && (*s & 0x80) && UTF)
6462 /* if the terminator isn't the same as the start character (e.g.,
6463 matched brackets), we have to allow more in the quoting, and
6464 be prepared for nested brackets.
6467 /* read until we run out of string, or we find the terminator */
6468 for (; s < PL_bufend; s++,to++) {
6469 /* embedded newlines increment the line count */
6470 if (*s == '\n' && !PL_rsfp)
6471 CopLINE_inc(PL_curcop);
6472 /* backslashes can escape the open or closing characters */
6473 if (*s == '\\' && s+1 < PL_bufend) {
6475 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
6480 /* allow nested opens and closes */
6481 else if (*s == PL_multi_close && --brackets <= 0)
6483 else if (*s == PL_multi_open)
6485 else if (!has_utf && (*s & 0x80) && UTF)
6490 /* terminate the copied string and update the sv's end-of-string */
6492 SvCUR_set(sv, to - SvPVX(sv));
6495 * this next chunk reads more into the buffer if we're not done yet
6499 break; /* handle case where we are done yet :-) */
6501 #ifndef PERL_STRICT_CR
6502 if (to - SvPVX(sv) >= 2) {
6503 if ((to[-2] == '\r' && to[-1] == '\n') ||
6504 (to[-2] == '\n' && to[-1] == '\r'))
6508 SvCUR_set(sv, to - SvPVX(sv));
6510 else if (to[-1] == '\r')
6513 else if (to - SvPVX(sv) == 1 && to[-1] == '\r')
6517 /* if we're out of file, or a read fails, bail and reset the current
6518 line marker so we can report where the unterminated string began
6521 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
6523 CopLINE_set(PL_curcop, PL_multi_start);
6526 /* we read a line, so increment our line counter */
6527 CopLINE_inc(PL_curcop);
6529 /* update debugger info */
6530 if (PERLDB_LINE && PL_curstash != PL_debstash) {
6531 SV *sv = NEWSV(88,0);
6533 sv_upgrade(sv, SVt_PVMG);
6534 sv_setsv(sv,PL_linestr);
6535 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
6538 /* having changed the buffer, we must update PL_bufend */
6539 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6542 /* at this point, we have successfully read the delimited string */
6545 sv_catpvn(sv, s, 1);
6548 PL_multi_end = CopLINE(PL_curcop);
6551 /* if we allocated too much space, give some back */
6552 if (SvCUR(sv) + 5 < SvLEN(sv)) {
6553 SvLEN_set(sv, SvCUR(sv) + 1);
6554 Renew(SvPVX(sv), SvLEN(sv), char);
6557 /* decide whether this is the first or second quoted string we've read
6570 takes: pointer to position in buffer
6571 returns: pointer to new position in buffer
6572 side-effects: builds ops for the constant in yylval.op
6574 Read a number in any of the formats that Perl accepts:
6576 0(x[0-7A-F]+)|([0-7]+)|(b[01])
6577 [\d_]+(\.[\d_]*)?[Ee](\d+)
6579 Underbars (_) are allowed in decimal numbers. If -w is on,
6580 underbars before a decimal point must be at three digit intervals.
6582 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
6585 If it reads a number without a decimal point or an exponent, it will
6586 try converting the number to an integer and see if it can do so
6587 without loss of precision.
6591 Perl_scan_num(pTHX_ char *start)
6593 register char *s = start; /* current position in buffer */
6594 register char *d; /* destination in temp buffer */
6595 register char *e; /* end of temp buffer */
6596 IV tryiv; /* used to see if it can be an IV */
6597 NV value; /* number read, as a double */
6598 SV *sv = Nullsv; /* place to put the converted number */
6599 bool floatit; /* boolean: int or float? */
6600 char *lastub = 0; /* position of last underbar */
6601 static char number_too_long[] = "Number too long";
6603 /* We use the first character to decide what type of number this is */
6607 Perl_croak(aTHX_ "panic: scan_num");
6609 /* if it starts with a 0, it could be an octal number, a decimal in
6610 0.13 disguise, or a hexadecimal number, or a binary number. */
6614 u holds the "number so far"
6615 shift the power of 2 of the base
6616 (hex == 4, octal == 3, binary == 1)
6617 overflowed was the number more than we can hold?
6619 Shift is used when we add a digit. It also serves as an "are
6620 we in octal/hex/binary?" indicator to disallow hex characters
6627 bool overflowed = FALSE;
6628 static NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
6629 static char* bases[5] = { "", "binary", "", "octal",
6631 static char* Bases[5] = { "", "Binary", "", "Octal",
6633 static char *maxima[5] = { "",
6634 "0b11111111111111111111111111111111",
6638 char *base, *Base, *max;
6644 } else if (s[1] == 'b') {
6648 /* check for a decimal in disguise */
6649 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
6651 /* so it must be octal */
6655 base = bases[shift];
6656 Base = Bases[shift];
6657 max = maxima[shift];
6659 /* read the rest of the number */
6661 /* x is used in the overflow test,
6662 b is the digit we're adding on. */
6667 /* if we don't mention it, we're done */
6676 /* 8 and 9 are not octal */
6679 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
6683 case '2': case '3': case '4':
6684 case '5': case '6': case '7':
6686 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
6690 b = *s++ & 15; /* ASCII digit -> value of digit */
6694 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
6695 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
6696 /* make sure they said 0x */
6701 /* Prepare to put the digit we have onto the end
6702 of the number so far. We check for overflows.
6707 x = u << shift; /* make room for the digit */
6709 if ((x >> shift) != u
6710 && !(PL_hints & HINT_NEW_BINARY)) {
6714 if (ckWARN_d(WARN_OVERFLOW))
6715 Perl_warner(aTHX_ WARN_OVERFLOW,
6716 "Integer overflow in %s number",
6719 u = x | b; /* add the digit to the end */
6722 n *= nvshift[shift];
6723 /* If an NV has not enough bits in its
6724 * mantissa to represent an UV this summing of
6725 * small low-order numbers is a waste of time
6726 * (because the NV cannot preserve the
6727 * low-order bits anyway): we could just
6728 * remember when did we overflow and in the
6729 * end just multiply n by the right
6737 /* if we get here, we had success: make a scalar value from
6744 if (ckWARN(WARN_PORTABLE) && n > 4294967295.0)
6745 Perl_warner(aTHX_ WARN_PORTABLE,
6746 "%s number > %s non-portable",
6753 if (ckWARN(WARN_PORTABLE) && u > 0xffffffff)
6754 Perl_warner(aTHX_ WARN_PORTABLE,
6755 "%s number > %s non-portable",
6760 if (PL_hints & HINT_NEW_BINARY)
6761 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
6766 handle decimal numbers.
6767 we're also sent here when we read a 0 as the first digit
6769 case '1': case '2': case '3': case '4': case '5':
6770 case '6': case '7': case '8': case '9': case '.':
6773 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
6776 /* read next group of digits and _ and copy into d */
6777 while (isDIGIT(*s) || *s == '_') {
6778 /* skip underscores, checking for misplaced ones
6782 dTHR; /* only for ckWARN */
6783 if (ckWARN(WARN_SYNTAX) && lastub && s - lastub != 3)
6784 Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number");
6788 /* check for end of fixed-length buffer */
6790 Perl_croak(aTHX_ number_too_long);
6791 /* if we're ok, copy the character */
6796 /* final misplaced underbar check */
6797 if (lastub && s - lastub != 3) {
6799 if (ckWARN(WARN_SYNTAX))
6800 Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number");
6803 /* read a decimal portion if there is one. avoid
6804 3..5 being interpreted as the number 3. followed
6807 if (*s == '.' && s[1] != '.') {
6811 /* copy, ignoring underbars, until we run out of
6812 digits. Note: no misplaced underbar checks!
6814 for (; isDIGIT(*s) || *s == '_'; s++) {
6815 /* fixed length buffer check */
6817 Perl_croak(aTHX_ number_too_long);
6823 /* read exponent part, if present */
6824 if (*s && strchr("eE",*s) && strchr("+-0123456789",s[1])) {
6828 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
6829 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
6831 /* allow positive or negative exponent */
6832 if (*s == '+' || *s == '-')
6835 /* read digits of exponent (no underbars :-) */
6836 while (isDIGIT(*s)) {
6838 Perl_croak(aTHX_ number_too_long);
6843 /* terminate the string */
6846 /* make an sv from the string */
6849 value = Atof(PL_tokenbuf);
6852 See if we can make do with an integer value without loss of
6853 precision. We use I_V to cast to an int, because some
6854 compilers have issues. Then we try casting it back and see
6855 if it was the same. We only do this if we know we
6856 specifically read an integer.
6858 Note: if floatit is true, then we don't need to do the
6862 if (!floatit && (NV)tryiv == value)
6863 sv_setiv(sv, tryiv);
6865 sv_setnv(sv, value);
6866 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
6867 (PL_hints & HINT_NEW_INTEGER) )
6868 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
6869 (floatit ? "float" : "integer"),
6872 /* if it starts with a v, it could be a version number */
6877 while (isDIGIT(*pos))
6879 if (*pos == '.' && isDIGIT(pos[1])) {
6884 s++; /* get past 'v' */
6887 SvUPGRADE(sv, SVt_PVNV);
6888 sv_setpvn(sv, "", 0);
6891 if (*s == '0' && isDIGIT(s[1]))
6892 yyerror("Octal number in vector unsupported");
6895 while (isDIGIT(*pos))
6898 tmpend = uv_to_utf8(tmpbuf, rev);
6900 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
6902 SvNVX(sv) += (NV)rev/nshift;
6904 } while (*pos == '.' && isDIGIT(pos[1]));
6906 if (*s == '0' && isDIGIT(s[1]))
6907 yyerror("Octal number in vector unsupported");
6910 tmpend = uv_to_utf8(tmpbuf, rev);
6912 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
6914 SvNVX(sv) += (NV)rev/nshift;
6925 /* make the op for the constant and return */
6928 yylval.opval = newSVOP(OP_CONST, 0, sv);
6930 yylval.opval = Nullop;
6936 S_scan_formline(pTHX_ register char *s)
6941 SV *stuff = newSVpvn("",0);
6942 bool needargs = FALSE;
6945 if (*s == '.' || *s == '}') {
6947 #ifdef PERL_STRICT_CR
6948 for (t = s+1;*t == ' ' || *t == '\t'; t++) ;
6950 for (t = s+1;*t == ' ' || *t == '\t' || *t == '\r'; t++) ;
6952 if (*t == '\n' || t == PL_bufend)
6955 if (PL_in_eval && !PL_rsfp) {
6956 eol = strchr(s,'\n');
6961 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6963 for (t = s; t < eol; t++) {
6964 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
6966 goto enough; /* ~~ must be first line in formline */
6968 if (*t == '@' || *t == '^')
6971 sv_catpvn(stuff, s, eol-s);
6972 #ifndef PERL_STRICT_CR
6973 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
6974 char *end = SvPVX(stuff) + SvCUR(stuff);
6983 s = filter_gets(PL_linestr, PL_rsfp, 0);
6984 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
6985 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
6988 yyerror("Format not terminated");
6998 PL_lex_state = LEX_NORMAL;
6999 PL_nextval[PL_nexttoke].ival = 0;
7003 PL_lex_state = LEX_FORMLINE;
7004 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
7006 PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
7010 SvREFCNT_dec(stuff);
7011 PL_lex_formbrack = 0;
7022 PL_cshlen = strlen(PL_cshname);
7027 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
7030 I32 oldsavestack_ix = PL_savestack_ix;
7031 CV* outsidecv = PL_compcv;
7035 assert(SvTYPE(PL_compcv) == SVt_PVCV);
7037 SAVEI32(PL_subline);
7038 save_item(PL_subname);
7041 SAVESPTR(PL_comppad_name);
7042 SAVESPTR(PL_compcv);
7043 SAVEI32(PL_comppad_name_fill);
7044 SAVEI32(PL_min_intro_pending);
7045 SAVEI32(PL_max_intro_pending);
7046 SAVEI32(PL_pad_reset_pending);
7048 PL_compcv = (CV*)NEWSV(1104,0);
7049 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
7050 CvFLAGS(PL_compcv) |= flags;
7052 PL_comppad = newAV();
7053 av_push(PL_comppad, Nullsv);
7054 PL_curpad = AvARRAY(PL_comppad);
7055 PL_comppad_name = newAV();
7056 PL_comppad_name_fill = 0;
7057 PL_min_intro_pending = 0;
7059 PL_subline = CopLINE(PL_curcop);
7061 av_store(PL_comppad_name, 0, newSVpvn("@_", 2));
7062 PL_curpad[0] = (SV*)newAV();
7063 SvPADMY_on(PL_curpad[0]); /* XXX Needed? */
7064 #endif /* USE_THREADS */
7066 comppadlist = newAV();
7067 AvREAL_off(comppadlist);
7068 av_store(comppadlist, 0, (SV*)PL_comppad_name);
7069 av_store(comppadlist, 1, (SV*)PL_comppad);
7071 CvPADLIST(PL_compcv) = comppadlist;
7072 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
7074 CvOWNER(PL_compcv) = 0;
7075 New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
7076 MUTEX_INIT(CvMUTEXP(PL_compcv));
7077 #endif /* USE_THREADS */
7079 return oldsavestack_ix;
7083 Perl_yywarn(pTHX_ char *s)
7086 PL_in_eval |= EVAL_WARNONLY;
7088 PL_in_eval &= ~EVAL_WARNONLY;
7093 Perl_yyerror(pTHX_ char *s)
7097 char *context = NULL;
7101 if (!yychar || (yychar == ';' && !PL_rsfp))
7103 else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 &&
7104 PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) {
7105 while (isSPACE(*PL_oldoldbufptr))
7107 context = PL_oldoldbufptr;
7108 contlen = PL_bufptr - PL_oldoldbufptr;
7110 else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 &&
7111 PL_oldbufptr != PL_bufptr) {
7112 while (isSPACE(*PL_oldbufptr))
7114 context = PL_oldbufptr;
7115 contlen = PL_bufptr - PL_oldbufptr;
7117 else if (yychar > 255)
7118 where = "next token ???";
7119 else if ((yychar & 127) == 127) {
7120 if (PL_lex_state == LEX_NORMAL ||
7121 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
7122 where = "at end of line";
7123 else if (PL_lex_inpat)
7124 where = "within pattern";
7126 where = "within string";
7129 SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
7131 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
7132 else if (isPRINT_LC(yychar))
7133 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
7135 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
7136 where = SvPVX(where_sv);
7138 msg = sv_2mortal(newSVpv(s, 0));
7139 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
7140 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
7142 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
7144 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
7145 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
7146 Perl_sv_catpvf(aTHX_ msg,
7147 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
7148 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
7151 if (PL_in_eval & EVAL_WARNONLY)
7152 Perl_warn(aTHX_ "%"SVf, msg);
7155 if (PL_error_count >= 10)
7156 Perl_croak(aTHX_ "%s has too many errors.\n", CopFILE(PL_curcop));
7158 PL_in_my_stash = Nullhv;
7169 * Restore a source filter.
7173 restore_rsfp(pTHXo_ void *f)
7175 PerlIO *fp = (PerlIO*)f;
7177 if (PL_rsfp == PerlIO_stdin())
7178 PerlIO_clearerr(PL_rsfp);
7179 else if (PL_rsfp && (PL_rsfp != fp))
7180 PerlIO_close(PL_rsfp);