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);
31 static void restore_expect(pTHXo_ void *e);
32 static void restore_lex_expect(pTHXo_ void *e);
34 #define UTF (PL_hints & HINT_UTF8)
36 * Note: we try to be careful never to call the isXXX_utf8() functions
37 * unless we're pretty sure we've seen the beginning of a UTF-8 character
38 * (that is, the two high bits are set). Otherwise we risk loading in the
39 * heavy-duty SWASHINIT and SWASHGET routines unnecessarily.
41 #define isIDFIRST_lazy(p) ((!UTF || (*((U8*)p) < 0xc0)) \
43 : isIDFIRST_utf8((U8*)p))
44 #define isALNUM_lazy(p) ((!UTF || (*((U8*)p) < 0xc0)) \
46 : isALNUM_utf8((U8*)p))
48 /* In variables name $^X, these are the legal values for X.
49 * 1999-02-27 mjd-perl-patch@plover.com */
50 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
52 /* On MacOS, respect nonbreaking spaces */
53 #ifdef MACOS_TRADITIONAL
54 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
56 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
59 /* LEX_* are values for PL_lex_state, the state of the lexer.
60 * They are arranged oddly so that the guard on the switch statement
61 * can get by with a single comparison (if the compiler is smart enough).
64 /* #define LEX_NOTPARSING 11 is done in perl.h. */
67 #define LEX_INTERPNORMAL 9
68 #define LEX_INTERPCASEMOD 8
69 #define LEX_INTERPPUSH 7
70 #define LEX_INTERPSTART 6
71 #define LEX_INTERPEND 5
72 #define LEX_INTERPENDMAYBE 4
73 #define LEX_INTERPCONCAT 3
74 #define LEX_INTERPCONST 2
75 #define LEX_FORMLINE 1
76 #define LEX_KNOWNEXT 0
85 /* XXX If this causes problems, set i_unistd=undef in the hint file. */
87 # include <unistd.h> /* Needed for execv() */
96 YYSTYPE* yylval_pointer = NULL;
97 int* yychar_pointer = NULL;
100 # define yylval (*yylval_pointer)
101 # define yychar (*yychar_pointer)
102 # define PERL_YYLEX_PARAM yylval_pointer,yychar_pointer
104 # define yylex() Perl_yylex(aTHX_ yylval_pointer, yychar_pointer)
107 #include "keywords.h"
109 /* CLINE is a macro that ensures PL_copline has a sane value */
114 #define CLINE (PL_copline = (PL_curcop->cop_line < PL_copline ? PL_curcop->cop_line : PL_copline))
117 * Convenience functions to return different tokens and prime the
118 * lexer for the next token. They all take an argument.
120 * TOKEN : generic token (used for '(', DOLSHARP, etc)
121 * OPERATOR : generic operator
122 * AOPERATOR : assignment operator
123 * PREBLOCK : beginning the block after an if, while, foreach, ...
124 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
125 * PREREF : *EXPR where EXPR is not a simple identifier
126 * TERM : expression term
127 * LOOPX : loop exiting command (goto, last, dump, etc)
128 * FTST : file test operator
129 * FUN0 : zero-argument function
130 * FUN1 : not used, except for not, which isn't a UNIOP
131 * BOop : bitwise or or xor
133 * SHop : shift operator
134 * PWop : power operator
135 * PMop : pattern-matching operator
136 * Aop : addition-level operator
137 * Mop : multiplication-level operator
138 * Eop : equality-testing operator
139 * Rop : relational operator <= != gt
141 * Also see LOP and lop() below.
144 #define TOKEN(retval) return (PL_bufptr = s,(int)retval)
145 #define OPERATOR(retval) return (PL_expect = XTERM,PL_bufptr = s,(int)retval)
146 #define AOPERATOR(retval) return ao((PL_expect = XTERM,PL_bufptr = s,(int)retval))
147 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s,(int)retval)
148 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s,(int)retval)
149 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s,(int)retval)
150 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR,PL_bufptr = s,(int)retval)
151 #define LOOPX(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LOOPEX)
152 #define FTST(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)UNIOP)
153 #define FUN0(f) return(yylval.ival = f,PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC0)
154 #define FUN1(f) return(yylval.ival = f,PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC1)
155 #define BOop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)BITOROP))
156 #define BAop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)BITANDOP))
157 #define SHop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)SHIFTOP))
158 #define PWop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)POWOP))
159 #define PMop(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)MATCHOP)
160 #define Aop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)ADDOP))
161 #define Mop(f) return ao((yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)MULOP))
162 #define Eop(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)EQOP)
163 #define Rop(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)RELOP)
165 /* This bit of chicanery makes a unary function followed by
166 * a parenthesis into a function with one argument, highest precedence.
168 #define UNI(f) return(yylval.ival = f, \
171 PL_last_uni = PL_oldbufptr, \
172 PL_last_lop_op = f, \
173 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
175 #define UNIBRACK(f) return(yylval.ival = f, \
177 PL_last_uni = PL_oldbufptr, \
178 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
180 /* grandfather return to old style */
181 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
186 * This subroutine detects &&= and ||= and turns an ANDAND or OROR
187 * into an OP_ANDASSIGN or OP_ORASSIGN
191 S_ao(pTHX_ int toketype)
193 if (*PL_bufptr == '=') {
195 if (toketype == ANDAND)
196 yylval.ival = OP_ANDASSIGN;
197 else if (toketype == OROR)
198 yylval.ival = OP_ORASSIGN;
206 * When Perl expects an operator and finds something else, no_op
207 * prints the warning. It always prints "<something> found where
208 * operator expected. It prints "Missing semicolon on previous line?"
209 * if the surprise occurs at the start of the line. "do you need to
210 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
211 * where the compiler doesn't know if foo is a method call or a function.
212 * It prints "Missing operator before end of line" if there's nothing
213 * after the missing operator, or "... before <...>" if there is something
214 * after the missing operator.
218 S_no_op(pTHX_ char *what, char *s)
220 char *oldbp = PL_bufptr;
221 bool is_first = (PL_oldbufptr == PL_linestart);
229 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
231 Perl_warn(aTHX_ "\t(Missing semicolon on previous line?)\n");
232 else if (PL_oldoldbufptr && isIDFIRST_lazy(PL_oldoldbufptr)) {
234 for (t = PL_oldoldbufptr; *t && (isALNUM_lazy(t) || *t == ':'); t++) ;
235 if (t < PL_bufptr && isSPACE(*t))
236 Perl_warn(aTHX_ "\t(Do you need to predeclare %.*s?)\n",
237 t - PL_oldoldbufptr, PL_oldoldbufptr);
240 Perl_warn(aTHX_ "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
246 * Complain about missing quote/regexp/heredoc terminator.
247 * If it's called with (char *)NULL then it cauterizes the line buffer.
248 * If we're in a delimited string and the delimiter is a control
249 * character, it's reformatted into a two-char sequence like ^C.
254 S_missingterm(pTHX_ char *s)
259 char *nl = strrchr(s,'\n');
265 iscntrl(PL_multi_close)
267 PL_multi_close < 32 || PL_multi_close == 127
271 tmpbuf[1] = toCTRL(PL_multi_close);
277 *tmpbuf = PL_multi_close;
281 q = strchr(s,'"') ? '\'' : '"';
282 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
290 Perl_deprecate(pTHX_ char *s)
293 if (ckWARN(WARN_DEPRECATED))
294 Perl_warner(aTHX_ WARN_DEPRECATED, "Use of %s is deprecated", s);
299 * Deprecate a comma-less variable list.
305 deprecate("comma-less variable list");
309 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
310 * utf16-to-utf8-reversed.
316 S_win32_textfilter(pTHX_ int idx, SV *sv, int maxlen)
318 I32 count = FILTER_READ(idx+1, sv, maxlen);
319 if (count > 0 && !maxlen)
320 win32_strip_return(sv);
326 S_utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
328 I32 count = FILTER_READ(idx+1, sv, maxlen);
332 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
333 tend = utf16_to_utf8((U16*)SvPVX(sv), tmps, SvCUR(sv));
334 sv_usepvn(sv, (char*)tmps, tend - tmps);
341 S_utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
343 I32 count = FILTER_READ(idx+1, sv, maxlen);
347 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
348 tend = utf16_to_utf8_reversed((U16*)SvPVX(sv), tmps, SvCUR(sv));
349 sv_usepvn(sv, (char*)tmps, tend - tmps);
357 * Initialize variables. Uses the Perl save_stack to save its state (for
358 * recursive calls to the parser).
362 Perl_lex_start(pTHX_ SV *line)
368 SAVEI32(PL_lex_dojoin);
369 SAVEI32(PL_lex_brackets);
370 SAVEI32(PL_lex_fakebrack);
371 SAVEI32(PL_lex_casemods);
372 SAVEI32(PL_lex_starts);
373 SAVEI32(PL_lex_state);
374 SAVESPTR(PL_lex_inpat);
375 SAVEI32(PL_lex_inwhat);
376 SAVEI16(PL_curcop->cop_line);
379 SAVEPPTR(PL_oldbufptr);
380 SAVEPPTR(PL_oldoldbufptr);
381 SAVEPPTR(PL_linestart);
382 SAVESPTR(PL_linestr);
383 SAVEPPTR(PL_lex_brackstack);
384 SAVEPPTR(PL_lex_casestack);
385 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
386 SAVESPTR(PL_lex_stuff);
387 SAVEI32(PL_lex_defer);
388 SAVEI32(PL_sublex_info.sub_inwhat);
389 SAVESPTR(PL_lex_repl);
390 SAVEDESTRUCTOR_X(restore_expect, PL_tokenbuf + PL_expect); /* encode as pointer */
391 SAVEDESTRUCTOR_X(restore_lex_expect, PL_tokenbuf + PL_expect);
393 PL_lex_state = LEX_NORMAL;
397 PL_lex_fakebrack = 0;
398 New(899, PL_lex_brackstack, 120, char);
399 New(899, PL_lex_casestack, 12, char);
400 SAVEFREEPV(PL_lex_brackstack);
401 SAVEFREEPV(PL_lex_casestack);
403 *PL_lex_casestack = '\0';
406 PL_lex_stuff = Nullsv;
407 PL_lex_repl = Nullsv;
410 PL_sublex_info.sub_inwhat = 0;
412 if (SvREADONLY(PL_linestr))
413 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
414 s = SvPV(PL_linestr, len);
415 if (len && s[len-1] != ';') {
416 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
417 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
418 sv_catpvn(PL_linestr, "\n;", 2);
420 SvTEMP_off(PL_linestr);
421 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
422 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
424 PL_rs = newSVpvn("\n", 1);
430 * Finalizer for lexing operations. Must be called when the parser is
431 * done with the lexer.
437 PL_doextract = FALSE;
442 * This subroutine has nothing to do with tilting, whether at windmills
443 * or pinball tables. Its name is short for "increment line". It
444 * increments the current line number in PL_curcop->cop_line and checks
445 * to see whether the line starts with a comment of the form
446 * # line 500 "foo.pm"
447 * If so, it sets the current line number and file to the values in the comment.
451 S_incline(pTHX_ char *s)
459 #ifdef MACOS_TRADITIONAL
460 MACPERL_DO_ASYNC_TASKS();
462 PL_curcop->cop_line++;
465 while (SPACE_OR_TAB(*s)) s++;
466 if (strnEQ(s, "line ", 5)) {
475 while (SPACE_OR_TAB(*s))
477 if (*s == '"' && (t = strchr(s+1, '"')))
481 return; /* false alarm */
482 for (t = s; !isSPACE(*t); t++) ;
487 PL_curcop->cop_filegv = gv_fetchfile(s);
489 PL_curcop->cop_filegv = gv_fetchfile(PL_origfilename);
491 PL_curcop->cop_line = atoi(n)-1;
496 * Called to gobble the appropriate amount and type of whitespace.
497 * Skips comments as well.
501 S_skipspace(pTHX_ register char *s)
504 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
505 while (s < PL_bufend && SPACE_OR_TAB(*s))
511 SSize_t oldprevlen, oldoldprevlen;
512 SSize_t oldloplen, oldunilen;
513 while (s < PL_bufend && isSPACE(*s)) {
514 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
519 if (s < PL_bufend && *s == '#') {
520 while (s < PL_bufend && *s != '\n')
524 if (PL_in_eval && !PL_rsfp) {
531 /* only continue to recharge the buffer if we're at the end
532 * of the buffer, we're not reading from a source filter, and
533 * we're in normal lexing mode
535 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
536 PL_lex_state == LEX_FORMLINE)
539 /* try to recharge the buffer */
540 if ((s = filter_gets(PL_linestr, PL_rsfp,
541 (prevlen = SvCUR(PL_linestr)))) == Nullch)
543 /* end of file. Add on the -p or -n magic */
544 if (PL_minus_n || PL_minus_p) {
545 sv_setpv(PL_linestr,PL_minus_p ?
546 ";}continue{print or die qq(-p destination: $!\\n)" :
548 sv_catpv(PL_linestr,";}");
549 PL_minus_n = PL_minus_p = 0;
552 sv_setpv(PL_linestr,";");
554 /* reset variables for next time we lex */
555 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
557 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
559 /* Close the filehandle. Could be from -P preprocessor,
560 * STDIN, or a regular file. If we were reading code from
561 * STDIN (because the commandline held no -e or filename)
562 * then we don't close it, we reset it so the code can
563 * read from STDIN too.
566 if (PL_preprocess && !PL_in_eval)
567 (void)PerlProc_pclose(PL_rsfp);
568 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
569 PerlIO_clearerr(PL_rsfp);
571 (void)PerlIO_close(PL_rsfp);
576 /* not at end of file, so we only read another line */
577 /* make corresponding updates to old pointers, for yyerror() */
578 oldprevlen = PL_oldbufptr - PL_bufend;
579 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
581 oldunilen = PL_last_uni - PL_bufend;
583 oldloplen = PL_last_lop - PL_bufend;
584 PL_linestart = PL_bufptr = s + prevlen;
585 PL_bufend = s + SvCUR(PL_linestr);
587 PL_oldbufptr = s + oldprevlen;
588 PL_oldoldbufptr = s + oldoldprevlen;
590 PL_last_uni = s + oldunilen;
592 PL_last_lop = s + oldloplen;
595 /* debugger active and we're not compiling the debugger code,
596 * so store the line into the debugger's array of lines
598 if (PERLDB_LINE && PL_curstash != PL_debstash) {
599 SV *sv = NEWSV(85,0);
601 sv_upgrade(sv, SVt_PVMG);
602 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
603 av_store(GvAV(PL_curcop->cop_filegv),(I32)PL_curcop->cop_line,sv);
610 * Check the unary operators to ensure there's no ambiguity in how they're
611 * used. An ambiguous piece of code would be:
613 * This doesn't mean rand() + 5. Because rand() is a unary operator,
614 * the +5 is its argument.
624 if (PL_oldoldbufptr != PL_last_uni)
626 while (isSPACE(*PL_last_uni))
628 for (s = PL_last_uni; isALNUM_lazy(s) || *s == '-'; s++) ;
629 if ((t = strchr(s, '(')) && t < PL_bufptr)
631 if (ckWARN_d(WARN_AMBIGUOUS)){
634 Perl_warner(aTHX_ WARN_AMBIGUOUS,
635 "Warning: Use of \"%s\" without parens is ambiguous",
641 /* workaround to replace the UNI() macro with a function. Only the
642 * hints/uts.sh file mentions this. Other comments elsewhere in the
643 * source indicate Microport Unix might need it too.
649 #define UNI(f) return uni(f,s)
652 S_uni(pTHX_ I32 f, char *s)
657 PL_last_uni = PL_oldbufptr;
668 #endif /* CRIPPLED_CC */
671 * LOP : macro to build a list operator. Its behaviour has been replaced
672 * with a subroutine, S_lop() for which LOP is just another name.
675 #define LOP(f,x) return lop(f,x,s)
679 * Build a list operator (or something that might be one). The rules:
680 * - if we have a next token, then it's a list operator [why?]
681 * - if the next thing is an opening paren, then it's a function
682 * - else it's a list operator
686 S_lop(pTHX_ I32 f, expectation x, char *s)
693 PL_last_lop = PL_oldbufptr;
708 * When the lexer realizes it knows the next token (for instance,
709 * it is reordering tokens for the parser) then it can call S_force_next
710 * to know what token to return the next time the lexer is called. Caller
711 * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer
712 * handles the token correctly.
716 S_force_next(pTHX_ I32 type)
718 PL_nexttype[PL_nexttoke] = type;
720 if (PL_lex_state != LEX_KNOWNEXT) {
721 PL_lex_defer = PL_lex_state;
722 PL_lex_expect = PL_expect;
723 PL_lex_state = LEX_KNOWNEXT;
729 * When the lexer knows the next thing is a word (for instance, it has
730 * just seen -> and it knows that the next char is a word char, then
731 * it calls S_force_word to stick the next word into the PL_next lookahead.
734 * char *start : buffer position (must be within PL_linestr)
735 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
736 * int check_keyword : if true, Perl checks to make sure the word isn't
737 * a keyword (do this if the word is a label, e.g. goto FOO)
738 * int allow_pack : if true, : characters will also be allowed (require,
740 * int allow_initial_tick : used by the "sub" lexer only.
744 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
749 start = skipspace(start);
751 if (isIDFIRST_lazy(s) ||
752 (allow_pack && *s == ':') ||
753 (allow_initial_tick && *s == '\'') )
755 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
756 if (check_keyword && keyword(PL_tokenbuf, len))
758 if (token == METHOD) {
763 PL_expect = XOPERATOR;
766 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(PL_tokenbuf,0));
767 PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
775 * Called when the lexer wants $foo *foo &foo etc, but the program
776 * text only contains the "foo" portion. The first argument is a pointer
777 * to the "foo", and the second argument is the type symbol to prefix.
778 * Forces the next token to be a "WORD".
779 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
783 S_force_ident(pTHX_ register char *s, int kind)
786 OP* o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
787 PL_nextval[PL_nexttoke].opval = o;
790 dTHR; /* just for in_eval */
791 o->op_private = OPpCONST_ENTERED;
792 /* XXX see note in pp_entereval() for why we forgo typo
793 warnings if the symbol must be introduced in an eval.
795 gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
796 kind == '$' ? SVt_PV :
797 kind == '@' ? SVt_PVAV :
798 kind == '%' ? SVt_PVHV :
807 * Forces the next token to be a version number.
811 S_force_version(pTHX_ char *s)
813 OP *version = Nullop;
817 /* default VERSION number -- GBARR */
822 for( d=s, c = 1; isDIGIT(*d) || *d == '_' || (*d == '.' && c--); d++);
823 if((*d == ';' || isSPACE(*d)) && *(skipspace(d)) != ',') {
825 /* real VERSION number -- GBARR */
826 version = yylval.opval;
830 /* NOTE: The parser sees the package name and the VERSION swapped */
831 PL_nextval[PL_nexttoke].opval = version;
839 * Tokenize a quoted string passed in as an SV. It finds the next
840 * chunk, up to end of string or a backslash. It may make a new
841 * SV containing that chunk (if HINT_NEW_STRING is on). It also
846 S_tokeq(pTHX_ SV *sv)
857 s = SvPV_force(sv, len);
861 while (s < send && *s != '\\')
866 if ( PL_hints & HINT_NEW_STRING )
867 pv = sv_2mortal(newSVpvn(SvPVX(pv), len));
870 if (s + 1 < send && (s[1] == '\\'))
871 s++; /* all that, just for this */
876 SvCUR_set(sv, d - SvPVX(sv));
878 if ( PL_hints & HINT_NEW_STRING )
879 return new_constant(NULL, 0, "q", sv, pv, "q");
884 * Now come three functions related to double-quote context,
885 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
886 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
887 * interact with PL_lex_state, and create fake ( ... ) argument lists
888 * to handle functions and concatenation.
889 * They assume that whoever calls them will be setting up a fake
890 * join call, because each subthing puts a ',' after it. This lets
893 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
895 * (I'm not sure whether the spurious commas at the end of lcfirst's
896 * arguments and join's arguments are created or not).
901 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
903 * Pattern matching will set PL_lex_op to the pattern-matching op to
904 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
906 * OP_CONST and OP_READLINE are easy--just make the new op and return.
908 * Everything else becomes a FUNC.
910 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
911 * had an OP_CONST or OP_READLINE). This just sets us up for a
912 * call to S_sublex_push().
918 register I32 op_type = yylval.ival;
920 if (op_type == OP_NULL) {
921 yylval.opval = PL_lex_op;
925 if (op_type == OP_CONST || op_type == OP_READLINE) {
926 SV *sv = tokeq(PL_lex_stuff);
928 if (SvTYPE(sv) == SVt_PVIV) {
929 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
935 nsv = newSVpvn(p, len);
939 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
940 PL_lex_stuff = Nullsv;
944 PL_sublex_info.super_state = PL_lex_state;
945 PL_sublex_info.sub_inwhat = op_type;
946 PL_sublex_info.sub_op = PL_lex_op;
947 PL_lex_state = LEX_INTERPPUSH;
951 yylval.opval = PL_lex_op;
961 * Create a new scope to save the lexing state. The scope will be
962 * ended in S_sublex_done. Returns a '(', starting the function arguments
963 * to the uc, lc, etc. found before.
964 * Sets PL_lex_state to LEX_INTERPCONCAT.
973 PL_lex_state = PL_sublex_info.super_state;
974 SAVEI32(PL_lex_dojoin);
975 SAVEI32(PL_lex_brackets);
976 SAVEI32(PL_lex_fakebrack);
977 SAVEI32(PL_lex_casemods);
978 SAVEI32(PL_lex_starts);
979 SAVEI32(PL_lex_state);
980 SAVESPTR(PL_lex_inpat);
981 SAVEI32(PL_lex_inwhat);
982 SAVEI16(PL_curcop->cop_line);
984 SAVEPPTR(PL_oldbufptr);
985 SAVEPPTR(PL_oldoldbufptr);
986 SAVEPPTR(PL_linestart);
987 SAVESPTR(PL_linestr);
988 SAVEPPTR(PL_lex_brackstack);
989 SAVEPPTR(PL_lex_casestack);
991 PL_linestr = PL_lex_stuff;
992 PL_lex_stuff = Nullsv;
994 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
996 PL_bufend += SvCUR(PL_linestr);
997 SAVEFREESV(PL_linestr);
999 PL_lex_dojoin = FALSE;
1000 PL_lex_brackets = 0;
1001 PL_lex_fakebrack = 0;
1002 New(899, PL_lex_brackstack, 120, char);
1003 New(899, PL_lex_casestack, 12, char);
1004 SAVEFREEPV(PL_lex_brackstack);
1005 SAVEFREEPV(PL_lex_casestack);
1006 PL_lex_casemods = 0;
1007 *PL_lex_casestack = '\0';
1009 PL_lex_state = LEX_INTERPCONCAT;
1010 PL_curcop->cop_line = PL_multi_start;
1012 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1013 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1014 PL_lex_inpat = PL_sublex_info.sub_op;
1016 PL_lex_inpat = Nullop;
1023 * Restores lexer state after a S_sublex_push.
1029 if (!PL_lex_starts++) {
1030 PL_expect = XOPERATOR;
1031 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpvn("",0));
1035 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1036 PL_lex_state = LEX_INTERPCASEMOD;
1040 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1041 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1042 PL_linestr = PL_lex_repl;
1044 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1045 PL_bufend += SvCUR(PL_linestr);
1046 SAVEFREESV(PL_linestr);
1047 PL_lex_dojoin = FALSE;
1048 PL_lex_brackets = 0;
1049 PL_lex_fakebrack = 0;
1050 PL_lex_casemods = 0;
1051 *PL_lex_casestack = '\0';
1053 if (SvEVALED(PL_lex_repl)) {
1054 PL_lex_state = LEX_INTERPNORMAL;
1056 /* we don't clear PL_lex_repl here, so that we can check later
1057 whether this is an evalled subst; that means we rely on the
1058 logic to ensure sublex_done() is called again only via the
1059 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1062 PL_lex_state = LEX_INTERPCONCAT;
1063 PL_lex_repl = Nullsv;
1069 PL_bufend = SvPVX(PL_linestr);
1070 PL_bufend += SvCUR(PL_linestr);
1071 PL_expect = XOPERATOR;
1072 PL_sublex_info.sub_inwhat = 0;
1080 Extracts a pattern, double-quoted string, or transliteration. This
1083 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1084 processing a pattern (PL_lex_inpat is true), a transliteration
1085 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1087 Returns a pointer to the character scanned up to. Iff this is
1088 advanced from the start pointer supplied (ie if anything was
1089 successfully parsed), will leave an OP for the substring scanned
1090 in yylval. Caller must intuit reason for not parsing further
1091 by looking at the next characters herself.
1095 double-quoted style: \r and \n
1096 regexp special ones: \D \s
1098 backrefs: \1 (deprecated in substitution replacements)
1099 case and quoting: \U \Q \E
1100 stops on @ and $, but not for $ as tail anchor
1102 In transliterations:
1103 characters are VERY literal, except for - not at the start or end
1104 of the string, which indicates a range. scan_const expands the
1105 range to the full set of intermediate characters.
1107 In double-quoted strings:
1109 double-quoted style: \r and \n
1111 backrefs: \1 (deprecated)
1112 case and quoting: \U \Q \E
1115 scan_const does *not* construct ops to handle interpolated strings.
1116 It stops processing as soon as it finds an embedded $ or @ variable
1117 and leaves it to the caller to work out what's going on.
1119 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @:foo.
1121 $ in pattern could be $foo or could be tail anchor. Assumption:
1122 it's a tail anchor if $ is the last thing in the string, or if it's
1123 followed by one of ")| \n\t"
1125 \1 (backreferences) are turned into $1
1127 The structure of the code is
1128 while (there's a character to process) {
1129 handle transliteration ranges
1130 skip regexp comments
1131 skip # initiated comments in //x patterns
1132 check for embedded @foo
1133 check for embedded scalars
1135 leave intact backslashes from leave (below)
1136 deprecate \1 in strings and sub replacements
1137 handle string-changing backslashes \l \U \Q \E, etc.
1138 switch (what was escaped) {
1139 handle - in a transliteration (becomes a literal -)
1140 handle \132 octal characters
1141 handle 0x15 hex characters
1142 handle \cV (control V)
1143 handle printf backslashes (\f, \r, \n, etc)
1145 } (end if backslash)
1146 } (end while character to read)
1151 S_scan_const(pTHX_ char *start)
1153 register char *send = PL_bufend; /* end of the constant */
1154 SV *sv = NEWSV(93, send - start); /* sv for the constant */
1155 register char *s = start; /* start of the constant */
1156 register char *d = SvPVX(sv); /* destination for copies */
1157 bool dorange = FALSE; /* are we in a translit range? */
1159 I32 utf = (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op)
1160 ? (PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF))
1162 I32 thisutf = (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op)
1163 ? (PL_sublex_info.sub_op->op_private & (PL_lex_repl ?
1164 OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF))
1166 const char *leaveit = /* set of acceptably-backslashed characters */
1168 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxcz0123456789[{]} \t\n\r\f\v#"
1171 while (s < send || dorange) {
1172 /* get transliterations out of the way (they're most literal) */
1173 if (PL_lex_inwhat == OP_TRANS) {
1174 /* expand a range A-Z to the full set of characters. AIE! */
1176 I32 i; /* current expanded character */
1177 I32 min; /* first character in range */
1178 I32 max; /* last character in range */
1180 i = d - SvPVX(sv); /* remember current offset */
1181 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1182 d = SvPVX(sv) + i; /* refresh d after realloc */
1183 d -= 2; /* eat the first char and the - */
1185 min = (U8)*d; /* first char in range */
1186 max = (U8)d[1]; /* last char in range */
1189 if ((isLOWER(min) && isLOWER(max)) ||
1190 (isUPPER(min) && isUPPER(max))) {
1192 for (i = min; i <= max; i++)
1196 for (i = min; i <= max; i++)
1203 for (i = min; i <= max; i++)
1206 /* mark the range as done, and continue */
1211 /* range begins (ignore - as first or last char) */
1212 else if (*s == '-' && s+1 < send && s != start) {
1214 *d++ = (char)0xff; /* use illegal utf8 byte--see pmtrans */
1223 /* if we get here, we're not doing a transliteration */
1225 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1226 except for the last char, which will be done separately. */
1227 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1229 while (s < send && *s != ')')
1231 } else if (s[2] == '{'
1232 || s[2] == 'p' && s[3] == '{') { /* This should march regcomp.c */
1234 char *regparse = s + (s[2] == '{' ? 3 : 4);
1237 while (count && (c = *regparse)) {
1238 if (c == '\\' && regparse[1])
1246 if (*regparse != ')') {
1247 regparse--; /* Leave one char for continuation. */
1248 yyerror("Sequence (?{...}) not terminated or not {}-balanced");
1250 while (s < regparse)
1255 /* likewise skip #-initiated comments in //x patterns */
1256 else if (*s == '#' && PL_lex_inpat &&
1257 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1258 while (s+1 < send && *s != '\n')
1262 /* check for embedded arrays (@foo, @:foo, @'foo, @{foo}, @$foo) */
1263 else if (*s == '@' && s[1] && (isALNUM_lazy(s+1) || strchr(":'{$", s[1])))
1266 /* check for embedded scalars. only stop if we're sure it's a
1269 else if (*s == '$') {
1270 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1272 if (s + 1 < send && !strchr("()| \n\t", s[1]))
1273 break; /* in regexp, $ might be tail anchor */
1276 /* (now in tr/// code again) */
1278 if (*s & 0x80 && thisutf) {
1279 dTHR; /* only for ckWARN */
1280 if (ckWARN(WARN_UTF8)) {
1281 (void)utf8_to_uv((U8*)s, &len); /* could cvt latin-1 to utf8 here... */
1291 if (*s == '\\' && s+1 < send) {
1294 /* some backslashes we leave behind */
1295 if (*leaveit && *s && strchr(leaveit, *s)) {
1301 /* deprecate \1 in strings and substitution replacements */
1302 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1303 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1305 dTHR; /* only for ckWARN */
1306 if (ckWARN(WARN_SYNTAX))
1307 Perl_warner(aTHX_ WARN_SYNTAX, "\\%c better written as $%c", *s, *s);
1312 /* string-change backslash escapes */
1313 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1318 /* if we get here, it's either a quoted -, or a digit */
1321 /* quoted - in transliterations */
1323 if (PL_lex_inwhat == OP_TRANS) {
1331 if (ckWARN(WARN_UNSAFE) && isALPHA(*s))
1332 Perl_warner(aTHX_ WARN_UNSAFE,
1333 "Unrecognized escape \\%c passed through",
1335 /* default action is to copy the quoted character */
1340 /* \132 indicates an octal constant */
1341 case '0': case '1': case '2': case '3':
1342 case '4': case '5': case '6': case '7':
1343 *d++ = (char)scan_oct(s, 3, &len);
1347 /* \x24 indicates a hex constant */
1351 char* e = strchr(s, '}');
1354 yyerror("Missing right brace on \\x{}");
1359 if (ckWARN(WARN_UTF8))
1360 Perl_warner(aTHX_ WARN_UTF8,
1361 "Use of \\x{} without utf8 declaration");
1363 /* note: utf always shorter than hex */
1364 d = (char*)uv_to_utf8((U8*)d,
1365 (UV)scan_hex(s + 1, e - s - 1, &len));
1369 UV uv = (UV)scan_hex(s, 2, &len);
1370 if (utf && PL_lex_inwhat == OP_TRANS &&
1371 utf != (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF))
1373 d = (char*)uv_to_utf8((U8*)d, uv); /* doing a CU or UC */
1376 if (uv >= 127 && UTF) {
1378 if (ckWARN(WARN_UTF8))
1379 Perl_warner(aTHX_ WARN_UTF8,
1380 "\\x%.*s will produce malformed UTF-8 character; use \\x{%.*s} for that",
1389 /* \N{latin small letter a} is a named character */
1393 char* e = strchr(s, '}');
1402 yyerror("Missing right brace on \\N{}");
1406 res = newSVpvn(s + 1, e - s - 1);
1407 res = new_constant( Nullch, 0, "charnames",
1408 res, Nullsv, "\\N{...}" );
1409 str = SvPV(res,len);
1410 if (len > e - s + 4) {
1411 char *odest = SvPVX(sv);
1413 SvGROW(sv, (SvCUR(sv) + len - (e - s + 4)));
1414 d = SvPVX(sv) + (d - odest);
1416 Copy(str, d, len, char);
1423 yyerror("Missing braces on \\N{}");
1426 /* \c is a control character */
1440 /* printf-style backslashes, formfeeds, newlines, etc */
1458 *d++ = '\047'; /* CP 1047 */
1461 *d++ = '\057'; /* CP 1047 */
1475 } /* end if (backslash) */
1478 } /* while loop to process each character */
1480 /* terminate the string and set up the sv */
1482 SvCUR_set(sv, d - SvPVX(sv));
1485 /* shrink the sv if we allocated more than we used */
1486 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1487 SvLEN_set(sv, SvCUR(sv) + 1);
1488 Renew(SvPVX(sv), SvLEN(sv), char);
1491 /* return the substring (via yylval) only if we parsed anything */
1492 if (s > PL_bufptr) {
1493 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1494 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1496 ( PL_lex_inwhat == OP_TRANS
1498 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1501 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1508 * Returns TRUE if there's more to the expression (e.g., a subscript),
1511 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
1513 * ->[ and ->{ return TRUE
1514 * { and [ outside a pattern are always subscripts, so return TRUE
1515 * if we're outside a pattern and it's not { or [, then return FALSE
1516 * if we're in a pattern and the first char is a {
1517 * {4,5} (any digits around the comma) returns FALSE
1518 * if we're in a pattern and the first char is a [
1520 * [SOMETHING] has a funky algorithm to decide whether it's a
1521 * character class or not. It has to deal with things like
1522 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
1523 * anything else returns TRUE
1526 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1529 S_intuit_more(pTHX_ register char *s)
1531 if (PL_lex_brackets)
1533 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1535 if (*s != '{' && *s != '[')
1540 /* In a pattern, so maybe we have {n,m}. */
1557 /* On the other hand, maybe we have a character class */
1560 if (*s == ']' || *s == '^')
1563 /* this is terrifying, and it works */
1564 int weight = 2; /* let's weigh the evidence */
1566 unsigned char un_char = 255, last_un_char;
1567 char *send = strchr(s,']');
1568 char tmpbuf[sizeof PL_tokenbuf * 4];
1570 if (!send) /* has to be an expression */
1573 Zero(seen,256,char);
1576 else if (isDIGIT(*s)) {
1578 if (isDIGIT(s[1]) && s[2] == ']')
1584 for (; s < send; s++) {
1585 last_un_char = un_char;
1586 un_char = (unsigned char)*s;
1591 weight -= seen[un_char] * 10;
1592 if (isALNUM_lazy(s+1)) {
1593 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
1594 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
1599 else if (*s == '$' && s[1] &&
1600 strchr("[#!%*<>()-=",s[1])) {
1601 if (/*{*/ strchr("])} =",s[2]))
1610 if (strchr("wds]",s[1]))
1612 else if (seen['\''] || seen['"'])
1614 else if (strchr("rnftbxcav",s[1]))
1616 else if (isDIGIT(s[1])) {
1618 while (s[1] && isDIGIT(s[1]))
1628 if (strchr("aA01! ",last_un_char))
1630 if (strchr("zZ79~",s[1]))
1632 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
1633 weight -= 5; /* cope with negative subscript */
1636 if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) &&
1637 isALPHA(*s) && s[1] && isALPHA(s[1])) {
1642 if (keyword(tmpbuf, d - tmpbuf))
1645 if (un_char == last_un_char + 1)
1647 weight -= seen[un_char];
1652 if (weight >= 0) /* probably a character class */
1662 * Does all the checking to disambiguate
1664 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
1665 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
1667 * First argument is the stuff after the first token, e.g. "bar".
1669 * Not a method if bar is a filehandle.
1670 * Not a method if foo is a subroutine prototyped to take a filehandle.
1671 * Not a method if it's really "Foo $bar"
1672 * Method if it's "foo $bar"
1673 * Not a method if it's really "print foo $bar"
1674 * Method if it's really "foo package::" (interpreted as package->foo)
1675 * Not a method if bar is known to be a subroutne ("sub bar; foo bar")
1676 * Not a method if bar is a filehandle or package, but is quotd with
1681 S_intuit_method(pTHX_ char *start, GV *gv)
1683 char *s = start + (*start == '$');
1684 char tmpbuf[sizeof PL_tokenbuf];
1692 if ((cv = GvCVu(gv))) {
1693 char *proto = SvPVX(cv);
1703 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
1704 /* start is the beginning of the possible filehandle/object,
1705 * and s is the end of it
1706 * tmpbuf is a copy of it
1709 if (*start == '$') {
1710 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
1715 return *s == '(' ? FUNCMETH : METHOD;
1717 if (!keyword(tmpbuf, len)) {
1718 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
1723 indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
1724 if (indirgv && GvCVu(indirgv))
1726 /* filehandle or package name makes it a method */
1727 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
1729 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
1730 return 0; /* no assumptions -- "=>" quotes bearword */
1732 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
1733 newSVpvn(tmpbuf,len));
1734 PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
1738 return *s == '(' ? FUNCMETH : METHOD;
1746 * Return a string of Perl code to load the debugger. If PERL5DB
1747 * is set, it will return the contents of that, otherwise a
1748 * compile-time require of perl5db.pl.
1755 char *pdb = PerlEnv_getenv("PERL5DB");
1759 SETERRNO(0,SS$_NORMAL);
1760 return "BEGIN { require 'perl5db.pl' }";
1766 /* Encoded script support. filter_add() effectively inserts a
1767 * 'pre-processing' function into the current source input stream.
1768 * Note that the filter function only applies to the current source file
1769 * (e.g., it will not affect files 'require'd or 'use'd by this one).
1771 * The datasv parameter (which may be NULL) can be used to pass
1772 * private data to this instance of the filter. The filter function
1773 * can recover the SV using the FILTER_DATA macro and use it to
1774 * store private buffers and state information.
1776 * The supplied datasv parameter is upgraded to a PVIO type
1777 * and the IoDIRP field is used to store the function pointer.
1778 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
1779 * private use must be set using malloc'd pointers.
1783 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
1788 if (!PL_rsfp_filters)
1789 PL_rsfp_filters = newAV();
1791 datasv = NEWSV(255,0);
1792 if (!SvUPGRADE(datasv, SVt_PVIO))
1793 Perl_die(aTHX_ "Can't upgrade filter_add data to SVt_PVIO");
1794 IoDIRP(datasv) = (DIR*)funcp; /* stash funcp into spare field */
1795 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
1796 funcp, SvPV_nolen(datasv)));
1797 av_unshift(PL_rsfp_filters, 1);
1798 av_store(PL_rsfp_filters, 0, datasv) ;
1803 /* Delete most recently added instance of this filter function. */
1805 Perl_filter_del(pTHX_ filter_t funcp)
1807 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", funcp));
1808 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
1810 /* if filter is on top of stack (usual case) just pop it off */
1811 if (IoDIRP(FILTER_DATA(AvFILLp(PL_rsfp_filters))) == (DIR*)funcp){
1812 IoDIRP(FILTER_DATA(AvFILLp(PL_rsfp_filters))) = NULL;
1813 sv_free(av_pop(PL_rsfp_filters));
1817 /* we need to search for the correct entry and clear it */
1818 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
1822 /* Invoke the n'th filter function for the current rsfp. */
1824 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
1827 /* 0 = read one text line */
1832 if (!PL_rsfp_filters)
1834 if (idx > AvFILLp(PL_rsfp_filters)){ /* Any more filters? */
1835 /* Provide a default input filter to make life easy. */
1836 /* Note that we append to the line. This is handy. */
1837 DEBUG_P(PerlIO_printf(Perl_debug_log,
1838 "filter_read %d: from rsfp\n", idx));
1842 int old_len = SvCUR(buf_sv) ;
1844 /* ensure buf_sv is large enough */
1845 SvGROW(buf_sv, old_len + maxlen) ;
1846 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
1847 if (PerlIO_error(PL_rsfp))
1848 return -1; /* error */
1850 return 0 ; /* end of file */
1852 SvCUR_set(buf_sv, old_len + len) ;
1855 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
1856 if (PerlIO_error(PL_rsfp))
1857 return -1; /* error */
1859 return 0 ; /* end of file */
1862 return SvCUR(buf_sv);
1864 /* Skip this filter slot if filter has been deleted */
1865 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef){
1866 DEBUG_P(PerlIO_printf(Perl_debug_log,
1867 "filter_read %d: skipped (filter deleted)\n",
1869 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
1871 /* Get function pointer hidden within datasv */
1872 funcp = (filter_t)IoDIRP(datasv);
1873 DEBUG_P(PerlIO_printf(Perl_debug_log,
1874 "filter_read %d: via function %p (%s)\n",
1875 idx, funcp, SvPV_nolen(datasv)));
1876 /* Call function. The function is expected to */
1877 /* call "FILTER_READ(idx+1, buf_sv)" first. */
1878 /* Return: <0:error, =0:eof, >0:not eof */
1879 return (*funcp)(aTHXo_ idx, buf_sv, maxlen);
1883 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
1886 if (!PL_rsfp_filters) {
1887 filter_add(win32_textfilter,NULL);
1890 if (PL_rsfp_filters) {
1893 SvCUR_set(sv, 0); /* start with empty line */
1894 if (FILTER_READ(0, sv, 0) > 0)
1895 return ( SvPVX(sv) ) ;
1900 return (sv_gets(sv, fp, append));
1905 static char* exp_name[] =
1906 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
1907 "ATTRTERM", "TERMBLOCK"
1914 Works out what to call the token just pulled out of the input
1915 stream. The yacc parser takes care of taking the ops we return and
1916 stitching them into a tree.
1922 if read an identifier
1923 if we're in a my declaration
1924 croak if they tried to say my($foo::bar)
1925 build the ops for a my() declaration
1926 if it's an access to a my() variable
1927 are we in a sort block?
1928 croak if my($a); $a <=> $b
1929 build ops for access to a my() variable
1930 if in a dq string, and they've said @foo and we can't find @foo
1932 build ops for a bareword
1933 if we already built the token before, use it.
1937 #ifdef USE_PURE_BISON
1938 Perl_yylex(pTHX_ YYSTYPE *lvalp, int *lcharp)
1951 #ifdef USE_PURE_BISON
1952 yylval_pointer = lvalp;
1953 yychar_pointer = lcharp;
1956 /* check if there's an identifier for us to look at */
1957 if (PL_pending_ident) {
1958 /* pit holds the identifier we read and pending_ident is reset */
1959 char pit = PL_pending_ident;
1960 PL_pending_ident = 0;
1962 /* if we're in a my(), we can't allow dynamics here.
1963 $foo'bar has already been turned into $foo::bar, so
1964 just check for colons.
1966 if it's a legal name, the OP is a PADANY.
1969 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
1970 tmp = pad_allocmy(PL_tokenbuf);
1973 if (strchr(PL_tokenbuf,':'))
1974 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
1976 yylval.opval = newOP(OP_PADANY, 0);
1977 yylval.opval->op_targ = pad_allocmy(PL_tokenbuf);
1983 build the ops for accesses to a my() variable.
1985 Deny my($a) or my($b) in a sort block, *if* $a or $b is
1986 then used in a comparison. This catches most, but not
1987 all cases. For instance, it catches
1988 sort { my($a); $a <=> $b }
1990 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
1991 (although why you'd do that is anyone's guess).
1994 if (!strchr(PL_tokenbuf,':')) {
1996 /* Check for single character per-thread SVs */
1997 if (PL_tokenbuf[0] == '$' && PL_tokenbuf[2] == '\0'
1998 && !isALPHA(PL_tokenbuf[1]) /* Rule out obvious non-threadsvs */
1999 && (tmp = find_threadsv(&PL_tokenbuf[1])) != NOT_IN_PAD)
2001 yylval.opval = newOP(OP_THREADSV, 0);
2002 yylval.opval->op_targ = tmp;
2005 #endif /* USE_THREADS */
2006 if ((tmp = pad_findmy(PL_tokenbuf)) != NOT_IN_PAD) {
2007 /* might be an "our" variable" */
2008 if (SvFLAGS(AvARRAY(PL_comppad_name)[tmp]) & SVpad_OUR) {
2009 /* build ops for a bareword */
2010 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
2011 yylval.opval->op_private = OPpCONST_ENTERED;
2012 gv_fetchpv(PL_tokenbuf+1,
2014 ? (GV_ADDMULTI | GV_ADDINEVAL | GV_ADDOUR)
2017 ((PL_tokenbuf[0] == '$') ? SVt_PV
2018 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
2023 /* if it's a sort block and they're naming $a or $b */
2024 if (PL_last_lop_op == OP_SORT &&
2025 PL_tokenbuf[0] == '$' &&
2026 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
2029 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
2030 d < PL_bufend && *d != '\n';
2033 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
2034 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
2040 yylval.opval = newOP(OP_PADANY, 0);
2041 yylval.opval->op_targ = tmp;
2047 Whine if they've said @foo in a doublequoted string,
2048 and @foo isn't a variable we can find in the symbol
2051 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
2052 GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
2053 if (!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
2054 yyerror(Perl_form(aTHX_ "In string, %s now must be written as \\%s",
2055 PL_tokenbuf, PL_tokenbuf));
2058 /* build ops for a bareword */
2059 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
2060 yylval.opval->op_private = OPpCONST_ENTERED;
2061 gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
2062 ((PL_tokenbuf[0] == '$') ? SVt_PV
2063 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
2068 /* no identifier pending identification */
2070 switch (PL_lex_state) {
2072 case LEX_NORMAL: /* Some compilers will produce faster */
2073 case LEX_INTERPNORMAL: /* code if we comment these out. */
2077 /* when we've already built the next token, just pull it out of the queue */
2080 yylval = PL_nextval[PL_nexttoke];
2082 PL_lex_state = PL_lex_defer;
2083 PL_expect = PL_lex_expect;
2084 PL_lex_defer = LEX_NORMAL;
2086 return(PL_nexttype[PL_nexttoke]);
2088 /* interpolated case modifiers like \L \U, including \Q and \E.
2089 when we get here, PL_bufptr is at the \
2091 case LEX_INTERPCASEMOD:
2093 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2094 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2096 /* handle \E or end of string */
2097 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2101 if (PL_lex_casemods) {
2102 oldmod = PL_lex_casestack[--PL_lex_casemods];
2103 PL_lex_casestack[PL_lex_casemods] = '\0';
2105 if (PL_bufptr != PL_bufend && strchr("LUQ", oldmod)) {
2107 PL_lex_state = LEX_INTERPCONCAT;
2111 if (PL_bufptr != PL_bufend)
2113 PL_lex_state = LEX_INTERPCONCAT;
2118 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2119 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
2120 if (strchr("LU", *s) &&
2121 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U')))
2123 PL_lex_casestack[--PL_lex_casemods] = '\0';
2126 if (PL_lex_casemods > 10) {
2127 char* newlb = Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2128 if (newlb != PL_lex_casestack) {
2130 PL_lex_casestack = newlb;
2133 PL_lex_casestack[PL_lex_casemods++] = *s;
2134 PL_lex_casestack[PL_lex_casemods] = '\0';
2135 PL_lex_state = LEX_INTERPCONCAT;
2136 PL_nextval[PL_nexttoke].ival = 0;
2139 PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2141 PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2143 PL_nextval[PL_nexttoke].ival = OP_LC;
2145 PL_nextval[PL_nexttoke].ival = OP_UC;
2147 PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2149 Perl_croak(aTHX_ "panic: yylex");
2152 if (PL_lex_starts) {
2161 case LEX_INTERPPUSH:
2162 return sublex_push();
2164 case LEX_INTERPSTART:
2165 if (PL_bufptr == PL_bufend)
2166 return sublex_done();
2168 PL_lex_dojoin = (*PL_bufptr == '@');
2169 PL_lex_state = LEX_INTERPNORMAL;
2170 if (PL_lex_dojoin) {
2171 PL_nextval[PL_nexttoke].ival = 0;
2174 PL_nextval[PL_nexttoke].opval = newOP(OP_THREADSV, 0);
2175 PL_nextval[PL_nexttoke].opval->op_targ = find_threadsv("\"");
2176 force_next(PRIVATEREF);
2178 force_ident("\"", '$');
2179 #endif /* USE_THREADS */
2180 PL_nextval[PL_nexttoke].ival = 0;
2182 PL_nextval[PL_nexttoke].ival = 0;
2184 PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
2187 if (PL_lex_starts++) {
2193 case LEX_INTERPENDMAYBE:
2194 if (intuit_more(PL_bufptr)) {
2195 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
2201 if (PL_lex_dojoin) {
2202 PL_lex_dojoin = FALSE;
2203 PL_lex_state = LEX_INTERPCONCAT;
2206 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2207 && SvEVALED(PL_lex_repl))
2209 if (PL_bufptr != PL_bufend)
2210 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2211 PL_lex_repl = Nullsv;
2214 case LEX_INTERPCONCAT:
2216 if (PL_lex_brackets)
2217 Perl_croak(aTHX_ "panic: INTERPCONCAT");
2219 if (PL_bufptr == PL_bufend)
2220 return sublex_done();
2222 if (SvIVX(PL_linestr) == '\'') {
2223 SV *sv = newSVsv(PL_linestr);
2226 else if ( PL_hints & HINT_NEW_RE )
2227 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2228 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2232 s = scan_const(PL_bufptr);
2234 PL_lex_state = LEX_INTERPCASEMOD;
2236 PL_lex_state = LEX_INTERPSTART;
2239 if (s != PL_bufptr) {
2240 PL_nextval[PL_nexttoke] = yylval;
2243 if (PL_lex_starts++)
2253 PL_lex_state = LEX_NORMAL;
2254 s = scan_formline(PL_bufptr);
2255 if (!PL_lex_formbrack)
2261 PL_oldoldbufptr = PL_oldbufptr;
2264 PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at %s\n",
2265 exp_name[PL_expect], s);
2271 if (isIDFIRST_lazy(s))
2273 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2276 goto fake_eof; /* emulate EOF on ^D or ^Z */
2281 if (PL_lex_brackets)
2282 yyerror("Missing right curly or square bracket");
2285 if (s++ < PL_bufend)
2286 goto retry; /* ignore stray nulls */
2289 if (!PL_in_eval && !PL_preambled) {
2290 PL_preambled = TRUE;
2291 sv_setpv(PL_linestr,incl_perldb());
2292 if (SvCUR(PL_linestr))
2293 sv_catpv(PL_linestr,";");
2295 while(AvFILLp(PL_preambleav) >= 0) {
2296 SV *tmpsv = av_shift(PL_preambleav);
2297 sv_catsv(PL_linestr, tmpsv);
2298 sv_catpv(PL_linestr, ";");
2301 sv_free((SV*)PL_preambleav);
2302 PL_preambleav = NULL;
2304 if (PL_minus_n || PL_minus_p) {
2305 sv_catpv(PL_linestr, "LINE: while (<>) {");
2307 sv_catpv(PL_linestr,"chomp;");
2309 GV* gv = gv_fetchpv("::F", TRUE, SVt_PVAV);
2311 GvIMPORTED_AV_on(gv);
2313 if (strchr("/'\"", *PL_splitstr)
2314 && strchr(PL_splitstr + 1, *PL_splitstr))
2315 Perl_sv_catpvf(aTHX_ PL_linestr, "@F=split(%s);", PL_splitstr);
2318 s = "'~#\200\1'"; /* surely one char is unused...*/
2319 while (s[1] && strchr(PL_splitstr, *s)) s++;
2321 Perl_sv_catpvf(aTHX_ PL_linestr, "@F=split(%s%c",
2322 "q" + (delim == '\''), delim);
2323 for (s = PL_splitstr; *s; s++) {
2325 sv_catpvn(PL_linestr, "\\", 1);
2326 sv_catpvn(PL_linestr, s, 1);
2328 Perl_sv_catpvf(aTHX_ PL_linestr, "%c);", delim);
2332 sv_catpv(PL_linestr,"@F=split(' ');");
2335 sv_catpv(PL_linestr, "\n");
2336 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2337 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2338 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2339 SV *sv = NEWSV(85,0);
2341 sv_upgrade(sv, SVt_PVMG);
2342 sv_setsv(sv,PL_linestr);
2343 av_store(GvAV(PL_curcop->cop_filegv),(I32)PL_curcop->cop_line,sv);
2348 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2351 if (PL_preprocess && !PL_in_eval)
2352 (void)PerlProc_pclose(PL_rsfp);
2353 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2354 PerlIO_clearerr(PL_rsfp);
2356 (void)PerlIO_close(PL_rsfp);
2358 PL_doextract = FALSE;
2360 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2361 sv_setpv(PL_linestr,PL_minus_p ? ";}continue{print" : "");
2362 sv_catpv(PL_linestr,";}");
2363 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2364 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2365 PL_minus_n = PL_minus_p = 0;
2368 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2369 sv_setpv(PL_linestr,"");
2370 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
2373 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
2374 PL_doextract = FALSE;
2376 /* Incest with pod. */
2377 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2378 sv_setpv(PL_linestr, "");
2379 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2380 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2381 PL_doextract = FALSE;
2385 } while (PL_doextract);
2386 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2387 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2388 SV *sv = NEWSV(85,0);
2390 sv_upgrade(sv, SVt_PVMG);
2391 sv_setsv(sv,PL_linestr);
2392 av_store(GvAV(PL_curcop->cop_filegv),(I32)PL_curcop->cop_line,sv);
2394 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2395 if (PL_curcop->cop_line == 1) {
2396 while (s < PL_bufend && isSPACE(*s))
2398 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2402 if (*s == '#' && *(s+1) == '!')
2404 #ifdef ALTERNATE_SHEBANG
2406 static char as[] = ALTERNATE_SHEBANG;
2407 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2408 d = s + (sizeof(as) - 1);
2410 #endif /* ALTERNATE_SHEBANG */
2419 while (*d && !isSPACE(*d))
2423 #ifdef ARG_ZERO_IS_SCRIPT
2424 if (ipathend > ipath) {
2426 * HP-UX (at least) sets argv[0] to the script name,
2427 * which makes $^X incorrect. And Digital UNIX and Linux,
2428 * at least, set argv[0] to the basename of the Perl
2429 * interpreter. So, having found "#!", we'll set it right.
2431 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV));
2432 assert(SvPOK(x) || SvGMAGICAL(x));
2433 if (sv_eq(x, GvSV(PL_curcop->cop_filegv))) {
2434 sv_setpvn(x, ipath, ipathend - ipath);
2437 TAINT_NOT; /* $^X is always tainted, but that's OK */
2439 #endif /* ARG_ZERO_IS_SCRIPT */
2444 d = instr(s,"perl -");
2446 d = instr(s,"perl");
2448 /* avoid getting into infinite loops when shebang
2449 * line contains "Perl" rather than "perl" */
2451 for (d = ipathend-4; d >= ipath; --d) {
2452 if ((*d == 'p' || *d == 'P')
2453 && !ibcmp(d, "perl", 4))
2463 #ifdef ALTERNATE_SHEBANG
2465 * If the ALTERNATE_SHEBANG on this system starts with a
2466 * character that can be part of a Perl expression, then if
2467 * we see it but not "perl", we're probably looking at the
2468 * start of Perl code, not a request to hand off to some
2469 * other interpreter. Similarly, if "perl" is there, but
2470 * not in the first 'word' of the line, we assume the line
2471 * contains the start of the Perl program.
2473 if (d && *s != '#') {
2475 while (*c && !strchr("; \t\r\n\f\v#", *c))
2478 d = Nullch; /* "perl" not in first word; ignore */
2480 *s = '#'; /* Don't try to parse shebang line */
2482 #endif /* ALTERNATE_SHEBANG */
2483 #ifndef MACOS_TRADITIONAL
2488 !instr(s,"indir") &&
2489 instr(PL_origargv[0],"perl"))
2495 while (s < PL_bufend && isSPACE(*s))
2497 if (s < PL_bufend) {
2498 Newz(899,newargv,PL_origargc+3,char*);
2500 while (s < PL_bufend && !isSPACE(*s))
2503 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2506 newargv = PL_origargv;
2508 PerlProc_execv(ipath, newargv);
2509 Perl_croak(aTHX_ "Can't exec %s", ipath);
2513 U32 oldpdb = PL_perldb;
2514 bool oldn = PL_minus_n;
2515 bool oldp = PL_minus_p;
2517 while (*d && !isSPACE(*d)) d++;
2518 while (SPACE_OR_TAB(*d)) d++;
2522 if (*d == 'M' || *d == 'm') {
2524 while (*d && !isSPACE(*d)) d++;
2525 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2528 d = moreswitches(d);
2530 if (PERLDB_LINE && !oldpdb ||
2531 ( PL_minus_n || PL_minus_p ) && !(oldn || oldp) )
2532 /* if we have already added "LINE: while (<>) {",
2533 we must not do it again */
2535 sv_setpv(PL_linestr, "");
2536 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2537 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2538 PL_preambled = FALSE;
2540 (void)gv_fetchfile(PL_origfilename);
2547 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2549 PL_lex_state = LEX_FORMLINE;
2554 #ifdef PERL_STRICT_CR
2555 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
2557 "(Maybe you didn't strip carriage returns after a network transfer?)\n");
2559 case ' ': case '\t': case '\f': case 013:
2560 #ifdef MACOS_TRADITIONAL
2567 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
2569 while (s < d && *s != '\n')
2574 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2576 PL_lex_state = LEX_FORMLINE;
2586 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2591 while (s < PL_bufend && SPACE_OR_TAB(*s))
2594 if (strnEQ(s,"=>",2)) {
2595 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
2596 OPERATOR('-'); /* unary minus */
2598 PL_last_uni = PL_oldbufptr;
2599 PL_last_lop_op = OP_FTEREAD; /* good enough */
2601 case 'r': FTST(OP_FTEREAD);
2602 case 'w': FTST(OP_FTEWRITE);
2603 case 'x': FTST(OP_FTEEXEC);
2604 case 'o': FTST(OP_FTEOWNED);
2605 case 'R': FTST(OP_FTRREAD);
2606 case 'W': FTST(OP_FTRWRITE);
2607 case 'X': FTST(OP_FTREXEC);
2608 case 'O': FTST(OP_FTROWNED);
2609 case 'e': FTST(OP_FTIS);
2610 case 'z': FTST(OP_FTZERO);
2611 case 's': FTST(OP_FTSIZE);
2612 case 'f': FTST(OP_FTFILE);
2613 case 'd': FTST(OP_FTDIR);
2614 case 'l': FTST(OP_FTLINK);
2615 case 'p': FTST(OP_FTPIPE);
2616 case 'S': FTST(OP_FTSOCK);
2617 case 'u': FTST(OP_FTSUID);
2618 case 'g': FTST(OP_FTSGID);
2619 case 'k': FTST(OP_FTSVTX);
2620 case 'b': FTST(OP_FTBLK);
2621 case 'c': FTST(OP_FTCHR);
2622 case 't': FTST(OP_FTTTY);
2623 case 'T': FTST(OP_FTTEXT);
2624 case 'B': FTST(OP_FTBINARY);
2625 case 'M': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTMTIME);
2626 case 'A': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTATIME);
2627 case 'C': gv_fetchpv("\024",TRUE, SVt_PV); FTST(OP_FTCTIME);
2629 Perl_croak(aTHX_ "Unrecognized file test: -%c", (int)tmp);
2636 if (PL_expect == XOPERATOR)
2641 else if (*s == '>') {
2644 if (isIDFIRST_lazy(s)) {
2645 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
2653 if (PL_expect == XOPERATOR)
2656 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2658 OPERATOR('-'); /* unary minus */
2665 if (PL_expect == XOPERATOR)
2670 if (PL_expect == XOPERATOR)
2673 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2679 if (PL_expect != XOPERATOR) {
2680 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
2681 PL_expect = XOPERATOR;
2682 force_ident(PL_tokenbuf, '*');
2695 if (PL_expect == XOPERATOR) {
2699 PL_tokenbuf[0] = '%';
2700 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
2701 if (!PL_tokenbuf[1]) {
2703 yyerror("Final % should be \\% or %name");
2706 PL_pending_ident = '%';
2725 switch (PL_expect) {
2728 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
2730 PL_bufptr = s; /* update in case we back off */
2736 PL_expect = XTERMBLOCK;
2740 while (isIDFIRST_lazy(s)) {
2741 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
2743 d = scan_str(d,TRUE,TRUE);
2746 SvREFCNT_dec(PL_lex_stuff);
2747 PL_lex_stuff = Nullsv;
2749 /* MUST advance bufptr here to avoid bogus
2750 "at end of line" context messages from yyerror().
2752 PL_bufptr = s + len;
2753 yyerror("Unterminated attribute parameter in attribute list");
2756 return 0; /* EOF indicator */
2760 SV *sv = newSVpvn(s, len);
2761 sv_catsv(sv, PL_lex_stuff);
2762 attrs = append_elem(OP_LIST, attrs,
2763 newSVOP(OP_CONST, 0, sv));
2764 SvREFCNT_dec(PL_lex_stuff);
2765 PL_lex_stuff = Nullsv;
2768 attrs = append_elem(OP_LIST, attrs,
2769 newSVOP(OP_CONST, 0,
2776 tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}' for vi */
2777 if (*s != ';' && *s != tmp) {
2778 char q = ((*s == '\'') ? '"' : '\'');
2779 /* If here for an expression, and parsed no attrs, back off. */
2780 if (tmp == '=' && !attrs) {
2784 /* MUST advance bufptr here to avoid bogus "at end of line"
2785 context messages from yyerror().
2789 yyerror("Unterminated attribute list");
2791 yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
2798 PL_nextval[PL_nexttoke].opval = attrs;
2806 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
2807 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
2812 if (PL_curcop->cop_line < PL_copline)
2813 PL_copline = PL_curcop->cop_line;
2824 if (PL_lex_brackets <= 0)
2825 yyerror("Unmatched right square bracket");
2828 if (PL_lex_state == LEX_INTERPNORMAL) {
2829 if (PL_lex_brackets == 0) {
2830 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
2831 PL_lex_state = LEX_INTERPEND;
2838 if (PL_lex_brackets > 100) {
2839 char* newlb = Renew(PL_lex_brackstack, PL_lex_brackets + 1, char);
2840 if (newlb != PL_lex_brackstack) {
2842 PL_lex_brackstack = newlb;
2845 switch (PL_expect) {
2847 if (PL_lex_formbrack) {
2851 if (PL_oldoldbufptr == PL_last_lop)
2852 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
2854 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
2855 OPERATOR(HASHBRACK);
2857 while (s < PL_bufend && SPACE_OR_TAB(*s))
2860 PL_tokenbuf[0] = '\0';
2861 if (d < PL_bufend && *d == '-') {
2862 PL_tokenbuf[0] = '-';
2864 while (d < PL_bufend && SPACE_OR_TAB(*d))
2867 if (d < PL_bufend && isIDFIRST_lazy(d)) {
2868 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
2870 while (d < PL_bufend && SPACE_OR_TAB(*d))
2873 char minus = (PL_tokenbuf[0] == '-');
2874 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
2882 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
2887 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
2892 if (PL_oldoldbufptr == PL_last_lop)
2893 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
2895 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
2898 OPERATOR(HASHBRACK);
2899 /* This hack serves to disambiguate a pair of curlies
2900 * as being a block or an anon hash. Normally, expectation
2901 * determines that, but in cases where we're not in a
2902 * position to expect anything in particular (like inside
2903 * eval"") we have to resolve the ambiguity. This code
2904 * covers the case where the first term in the curlies is a
2905 * quoted string. Most other cases need to be explicitly
2906 * disambiguated by prepending a `+' before the opening
2907 * curly in order to force resolution as an anon hash.
2909 * XXX should probably propagate the outer expectation
2910 * into eval"" to rely less on this hack, but that could
2911 * potentially break current behavior of eval"".
2915 if (*s == '\'' || *s == '"' || *s == '`') {
2916 /* common case: get past first string, handling escapes */
2917 for (t++; t < PL_bufend && *t != *s;)
2918 if (*t++ == '\\' && (*t == '\\' || *t == *s))
2922 else if (*s == 'q') {
2925 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
2926 && !isALNUM(*t)))) {
2928 char open, close, term;
2931 while (t < PL_bufend && isSPACE(*t))
2935 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
2939 for (t++; t < PL_bufend; t++) {
2940 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
2942 else if (*t == open)
2946 for (t++; t < PL_bufend; t++) {
2947 if (*t == '\\' && t+1 < PL_bufend)
2949 else if (*t == close && --brackets <= 0)
2951 else if (*t == open)
2957 else if (isIDFIRST_lazy(s)) {
2958 for (t++; t < PL_bufend && isALNUM_lazy(t); t++) ;
2960 while (t < PL_bufend && isSPACE(*t))
2962 /* if comma follows first term, call it an anon hash */
2963 /* XXX it could be a comma expression with loop modifiers */
2964 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
2965 || (*t == '=' && t[1] == '>')))
2966 OPERATOR(HASHBRACK);
2967 if (PL_expect == XREF)
2970 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
2976 yylval.ival = PL_curcop->cop_line;
2977 if (isSPACE(*s) || *s == '#')
2978 PL_copline = NOLINE; /* invalidate current command line number */
2983 if (PL_lex_brackets <= 0)
2984 yyerror("Unmatched right curly bracket");
2986 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
2987 if (PL_lex_brackets < PL_lex_formbrack)
2988 PL_lex_formbrack = 0;
2989 if (PL_lex_state == LEX_INTERPNORMAL) {
2990 if (PL_lex_brackets == 0) {
2991 if (PL_lex_fakebrack) {
2992 PL_lex_state = LEX_INTERPEND;
2994 return yylex(); /* ignore fake brackets */
2996 if (*s == '-' && s[1] == '>')
2997 PL_lex_state = LEX_INTERPENDMAYBE;
2998 else if (*s != '[' && *s != '{')
2999 PL_lex_state = LEX_INTERPEND;
3002 if (PL_lex_brackets < PL_lex_fakebrack) {
3004 PL_lex_fakebrack = 0;
3005 return yylex(); /* ignore fake brackets */
3015 if (PL_expect == XOPERATOR) {
3016 if (ckWARN(WARN_SEMICOLON) && isIDFIRST_lazy(s) && PL_bufptr == PL_linestart) {
3017 PL_curcop->cop_line--;
3018 Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi);
3019 PL_curcop->cop_line++;
3024 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3026 PL_expect = XOPERATOR;
3027 force_ident(PL_tokenbuf, '&');
3031 yylval.ival = (OPpENTERSUB_AMPER<<8);
3050 if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
3051 Perl_warner(aTHX_ WARN_SYNTAX, "Reversed %c= operator",(int)tmp);
3053 if (PL_expect == XSTATE && isALPHA(tmp) &&
3054 (s == PL_linestart+1 || s[-2] == '\n') )
3056 if (PL_in_eval && !PL_rsfp) {
3061 if (strnEQ(s,"=cut",4)) {
3075 PL_doextract = TRUE;
3078 if (PL_lex_brackets < PL_lex_formbrack) {
3080 #ifdef PERL_STRICT_CR
3081 for (t = s; SPACE_OR_TAB(*t); t++) ;
3083 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3085 if (*t == '\n' || *t == '#') {
3103 if (PL_expect != XOPERATOR) {
3104 if (s[1] != '<' && !strchr(s,'>'))
3107 s = scan_heredoc(s);
3109 s = scan_inputsymbol(s);
3110 TERM(sublex_start());
3115 SHop(OP_LEFT_SHIFT);
3129 SHop(OP_RIGHT_SHIFT);
3138 if (PL_expect == XOPERATOR) {
3139 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3142 return ','; /* grandfather non-comma-format format */
3146 if (s[1] == '#' && (isIDFIRST_lazy(s+2) || strchr("{$:+-", s[2]))) {
3147 PL_tokenbuf[0] = '@';
3148 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3149 sizeof PL_tokenbuf - 1, FALSE);
3150 if (PL_expect == XOPERATOR)
3151 no_op("Array length", s);
3152 if (!PL_tokenbuf[1])
3154 PL_expect = XOPERATOR;
3155 PL_pending_ident = '#';
3159 PL_tokenbuf[0] = '$';
3160 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3161 sizeof PL_tokenbuf - 1, FALSE);
3162 if (PL_expect == XOPERATOR)
3164 if (!PL_tokenbuf[1]) {
3166 yyerror("Final $ should be \\$ or $name");
3170 /* This kludge not intended to be bulletproof. */
3171 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3172 yylval.opval = newSVOP(OP_CONST, 0,
3173 newSViv((IV)PL_compiling.cop_arybase));
3174 yylval.opval->op_private = OPpCONST_ARYBASE;
3180 if (PL_lex_state == LEX_NORMAL)
3183 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3186 PL_tokenbuf[0] = '@';
3187 if (ckWARN(WARN_SYNTAX)) {
3189 isSPACE(*t) || isALNUM_lazy(t) || *t == '$';
3192 PL_bufptr = skipspace(PL_bufptr);
3193 while (t < PL_bufend && *t != ']')
3195 Perl_warner(aTHX_ WARN_SYNTAX,
3196 "Multidimensional syntax %.*s not supported",
3197 (t - PL_bufptr) + 1, PL_bufptr);
3201 else if (*s == '{') {
3202 PL_tokenbuf[0] = '%';
3203 if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") &&
3204 (t = strchr(s, '}')) && (t = strchr(t, '=')))
3206 char tmpbuf[sizeof PL_tokenbuf];
3208 for (t++; isSPACE(*t); t++) ;
3209 if (isIDFIRST_lazy(t)) {
3210 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3211 for (; isSPACE(*t); t++) ;
3212 if (*t == ';' && get_cv(tmpbuf, FALSE))
3213 Perl_warner(aTHX_ WARN_SYNTAX,
3214 "You need to quote \"%s\"", tmpbuf);
3220 PL_expect = XOPERATOR;
3221 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3222 bool islop = (PL_last_lop == PL_oldoldbufptr);
3223 if (!islop || PL_last_lop_op == OP_GREPSTART)
3224 PL_expect = XOPERATOR;
3225 else if (strchr("$@\"'`q", *s))
3226 PL_expect = XTERM; /* e.g. print $fh "foo" */
3227 else if (strchr("&*<%", *s) && isIDFIRST_lazy(s+1))
3228 PL_expect = XTERM; /* e.g. print $fh &sub */
3229 else if (isIDFIRST_lazy(s)) {
3230 char tmpbuf[sizeof PL_tokenbuf];
3231 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3232 if (tmp = keyword(tmpbuf, len)) {
3233 /* binary operators exclude handle interpretations */
3245 PL_expect = XTERM; /* e.g. print $fh length() */
3250 GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
3251 if (gv && GvCVu(gv))
3252 PL_expect = XTERM; /* e.g. print $fh subr() */
3255 else if (isDIGIT(*s))
3256 PL_expect = XTERM; /* e.g. print $fh 3 */
3257 else if (*s == '.' && isDIGIT(s[1]))
3258 PL_expect = XTERM; /* e.g. print $fh .3 */
3259 else if (strchr("/?-+", *s) && !isSPACE(s[1]) && s[1] != '=')
3260 PL_expect = XTERM; /* e.g. print $fh -1 */
3261 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3262 PL_expect = XTERM; /* print $fh <<"EOF" */
3264 PL_pending_ident = '$';
3268 if (PL_expect == XOPERATOR)
3270 PL_tokenbuf[0] = '@';
3271 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3272 if (!PL_tokenbuf[1]) {
3274 yyerror("Final @ should be \\@ or @name");
3277 if (PL_lex_state == LEX_NORMAL)
3279 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3281 PL_tokenbuf[0] = '%';
3283 /* Warn about @ where they meant $. */
3284 if (ckWARN(WARN_SYNTAX)) {
3285 if (*s == '[' || *s == '{') {
3287 while (*t && (isALNUM_lazy(t) || strchr(" \t$#+-'\"", *t)))
3289 if (*t == '}' || *t == ']') {
3291 PL_bufptr = skipspace(PL_bufptr);
3292 Perl_warner(aTHX_ WARN_SYNTAX,
3293 "Scalar value %.*s better written as $%.*s",
3294 t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3299 PL_pending_ident = '@';
3302 case '/': /* may either be division or pattern */
3303 case '?': /* may either be conditional or pattern */
3304 if (PL_expect != XOPERATOR) {
3305 /* Disable warning on "study /blah/" */
3306 if (PL_oldoldbufptr == PL_last_uni
3307 && (*PL_last_uni != 's' || s - PL_last_uni < 5
3308 || memNE(PL_last_uni, "study", 5) || isALNUM_lazy(PL_last_uni+5)))
3310 s = scan_pat(s,OP_MATCH);
3311 TERM(sublex_start());
3319 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3320 #ifdef PERL_STRICT_CR
3323 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3325 && (s == PL_linestart || s[-1] == '\n') )
3327 PL_lex_formbrack = 0;
3331 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3337 yylval.ival = OPf_SPECIAL;
3343 if (PL_expect != XOPERATOR)
3348 case '0': case '1': case '2': case '3': case '4':
3349 case '5': case '6': case '7': case '8': case '9':
3351 if (PL_expect == XOPERATOR)
3356 s = scan_str(s,FALSE,FALSE);
3357 if (PL_expect == XOPERATOR) {
3358 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3361 return ','; /* grandfather non-comma-format format */
3367 missingterm((char*)0);
3368 yylval.ival = OP_CONST;
3369 TERM(sublex_start());
3372 s = scan_str(s,FALSE,FALSE);
3373 if (PL_expect == XOPERATOR) {
3374 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3377 return ','; /* grandfather non-comma-format format */
3383 missingterm((char*)0);
3384 yylval.ival = OP_CONST;
3385 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3386 if (*d == '$' || *d == '@' || *d == '\\' || *d & 0x80) {
3387 yylval.ival = OP_STRINGIFY;
3391 TERM(sublex_start());
3394 s = scan_str(s,FALSE,FALSE);
3395 if (PL_expect == XOPERATOR)
3396 no_op("Backticks",s);
3398 missingterm((char*)0);
3399 yylval.ival = OP_BACKTICK;
3401 TERM(sublex_start());
3405 if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s))
3406 Perl_warner(aTHX_ WARN_SYNTAX,"Can't use \\%c to mean $%c in expression",
3408 if (PL_expect == XOPERATOR)
3409 no_op("Backslash",s);
3413 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
3453 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3455 /* Some keywords can be followed by any delimiter, including ':' */
3456 tmp = (len == 1 && strchr("msyq", PL_tokenbuf[0]) ||
3457 len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
3458 (PL_tokenbuf[0] == 'q' &&
3459 strchr("qwxr", PL_tokenbuf[1]))));
3461 /* x::* is just a word, unless x is "CORE" */
3462 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
3466 while (d < PL_bufend && isSPACE(*d))
3467 d++; /* no comments skipped here, or s### is misparsed */
3469 /* Is this a label? */
3470 if (!tmp && PL_expect == XSTATE
3471 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
3473 yylval.pval = savepv(PL_tokenbuf);
3478 /* Check for keywords */
3479 tmp = keyword(PL_tokenbuf, len);
3481 /* Is this a word before a => operator? */
3482 if (strnEQ(d,"=>",2)) {
3484 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf,0));
3485 yylval.opval->op_private = OPpCONST_BARE;
3489 if (tmp < 0) { /* second-class keyword? */
3490 GV *ogv = Nullgv; /* override (winner) */
3491 GV *hgv = Nullgv; /* hidden (loser) */
3492 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
3494 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
3497 if (GvIMPORTED_CV(gv))
3499 else if (! CvMETHOD(cv))
3503 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
3504 (gv = *gvp) != (GV*)&PL_sv_undef &&
3505 GvCVu(gv) && GvIMPORTED_CV(gv))
3511 tmp = 0; /* overridden by import or by GLOBAL */
3514 && -tmp==KEY_lock /* XXX generalizable kludge */
3515 && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
3517 tmp = 0; /* any sub overrides "weak" keyword */
3519 else { /* no override */
3523 if (ckWARN(WARN_AMBIGUOUS) && hgv
3524 && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
3525 Perl_warner(aTHX_ WARN_AMBIGUOUS,
3526 "Ambiguous call resolved as CORE::%s(), %s",
3527 GvENAME(hgv), "qualify as such or use &");
3534 default: /* not a keyword */
3537 char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
3539 /* Get the rest if it looks like a package qualifier */
3541 if (*s == '\'' || *s == ':' && s[1] == ':') {
3543 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
3546 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
3547 *s == '\'' ? "'" : "::");
3551 if (PL_expect == XOPERATOR) {
3552 if (PL_bufptr == PL_linestart) {
3553 PL_curcop->cop_line--;
3554 Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi);
3555 PL_curcop->cop_line++;
3558 no_op("Bareword",s);
3561 /* Look for a subroutine with this name in current package,
3562 unless name is "Foo::", in which case Foo is a bearword
3563 (and a package name). */
3566 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
3568 if (ckWARN(WARN_UNSAFE) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
3569 Perl_warner(aTHX_ WARN_UNSAFE,
3570 "Bareword \"%s\" refers to nonexistent package",
3573 PL_tokenbuf[len] = '\0';
3580 gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
3583 /* if we saw a global override before, get the right name */
3586 sv = newSVpvn("CORE::GLOBAL::",14);
3587 sv_catpv(sv,PL_tokenbuf);
3590 sv = newSVpv(PL_tokenbuf,0);
3592 /* Presume this is going to be a bareword of some sort. */
3595 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3596 yylval.opval->op_private = OPpCONST_BARE;
3598 /* And if "Foo::", then that's what it certainly is. */
3603 /* See if it's the indirect object for a list operator. */
3605 if (PL_oldoldbufptr &&
3606 PL_oldoldbufptr < PL_bufptr &&
3607 (PL_oldoldbufptr == PL_last_lop
3608 || PL_oldoldbufptr == PL_last_uni) &&
3609 /* NO SKIPSPACE BEFORE HERE! */
3610 (PL_expect == XREF ||
3611 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
3613 bool immediate_paren = *s == '(';
3615 /* (Now we can afford to cross potential line boundary.) */
3618 /* Two barewords in a row may indicate method call. */
3620 if ((isIDFIRST_lazy(s) || *s == '$') && (tmp=intuit_method(s,gv)))
3623 /* If not a declared subroutine, it's an indirect object. */
3624 /* (But it's an indir obj regardless for sort.) */
3626 if ((PL_last_lop_op == OP_SORT ||
3627 (!immediate_paren && (!gv || !GvCVu(gv)))) &&
3628 (PL_last_lop_op != OP_MAPSTART &&
3629 PL_last_lop_op != OP_GREPSTART))
3631 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
3636 /* If followed by a paren, it's certainly a subroutine. */
3638 PL_expect = XOPERATOR;
3642 if (gv && GvCVu(gv)) {
3643 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
3644 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
3649 PL_nextval[PL_nexttoke].opval = yylval.opval;
3650 PL_expect = XOPERATOR;
3656 /* If followed by var or block, call it a method (unless sub) */
3658 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
3659 PL_last_lop = PL_oldbufptr;
3660 PL_last_lop_op = OP_METHOD;
3664 /* If followed by a bareword, see if it looks like indir obj. */
3666 if ((isIDFIRST_lazy(s) || *s == '$') && (tmp = intuit_method(s,gv)))
3669 /* Not a method, so call it a subroutine (if defined) */
3671 if (gv && GvCVu(gv)) {
3673 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
3674 Perl_warner(aTHX_ WARN_AMBIGUOUS,
3675 "Ambiguous use of -%s resolved as -&%s()",
3676 PL_tokenbuf, PL_tokenbuf);
3677 /* Check for a constant sub */
3679 if ((sv = cv_const_sv(cv))) {
3681 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
3682 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
3683 yylval.opval->op_private = 0;
3687 /* Resolve to GV now. */
3688 op_free(yylval.opval);
3689 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
3690 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
3691 PL_last_lop = PL_oldbufptr;
3692 PL_last_lop_op = OP_ENTERSUB;
3693 /* Is there a prototype? */
3696 char *proto = SvPV((SV*)cv, len);
3699 if (strEQ(proto, "$"))
3701 if (*proto == '&' && *s == '{') {
3702 sv_setpv(PL_subname,"__ANON__");
3706 PL_nextval[PL_nexttoke].opval = yylval.opval;
3712 /* Call it a bare word */
3714 if (PL_hints & HINT_STRICT_SUBS)
3715 yylval.opval->op_private |= OPpCONST_STRICT;
3718 if (ckWARN(WARN_RESERVED)) {
3719 if (lastchar != '-') {
3720 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
3722 Perl_warner(aTHX_ WARN_RESERVED, PL_warn_reserved,
3729 if (lastchar && strchr("*%&", lastchar) && ckWARN_d(WARN_AMBIGUOUS)) {
3730 Perl_warner(aTHX_ WARN_AMBIGUOUS,
3731 "Operator or semicolon missing before %c%s",
3732 lastchar, PL_tokenbuf);
3733 Perl_warner(aTHX_ WARN_AMBIGUOUS,
3734 "Ambiguous use of %c resolved as operator %c",
3735 lastchar, lastchar);
3741 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3742 newSVsv(GvSV(PL_curcop->cop_filegv)));
3746 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3747 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)PL_curcop->cop_line));
3750 case KEY___PACKAGE__:
3751 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3753 ? newSVsv(PL_curstname)
3762 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
3763 char *pname = "main";
3764 if (PL_tokenbuf[2] == 'D')
3765 pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash);
3766 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);
3769 GvIOp(gv) = newIO();
3770 IoIFP(GvIOp(gv)) = PL_rsfp;
3771 #if defined(HAS_FCNTL) && defined(F_SETFD)
3773 int fd = PerlIO_fileno(PL_rsfp);
3774 fcntl(fd,F_SETFD,fd >= 3);
3777 /* Mark this internal pseudo-handle as clean */
3778 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
3780 IoTYPE(GvIOp(gv)) = '|';
3781 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
3782 IoTYPE(GvIOp(gv)) = '-';
3784 IoTYPE(GvIOp(gv)) = '<';
3795 if (PL_expect == XSTATE) {
3802 if (*s == ':' && s[1] == ':') {
3805 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3806 tmp = keyword(PL_tokenbuf, len);
3820 LOP(OP_ACCEPT,XTERM);
3826 LOP(OP_ATAN2,XTERM);
3835 LOP(OP_BLESS,XTERM);
3844 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
3861 if (!PL_cryptseen) {
3862 PL_cryptseen = TRUE;
3866 LOP(OP_CRYPT,XTERM);
3869 if (ckWARN(WARN_OCTAL)) {
3870 for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ;
3871 if (*d != '0' && isDIGIT(*d))
3872 Perl_warner(aTHX_ WARN_OCTAL,
3873 "chmod: mode argument is missing initial 0");
3875 LOP(OP_CHMOD,XTERM);
3878 LOP(OP_CHOWN,XTERM);
3881 LOP(OP_CONNECT,XTERM);
3897 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3901 PL_hints |= HINT_BLOCK_SCOPE;
3911 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
3912 LOP(OP_DBMOPEN,XTERM);
3918 s = force_word(s,WORD,TRUE,FALSE,FALSE);
3925 yylval.ival = PL_curcop->cop_line;
3939 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
3940 UNIBRACK(OP_ENTEREVAL);
3955 case KEY_endhostent:
3961 case KEY_endservent:
3964 case KEY_endprotoent:
3975 yylval.ival = PL_curcop->cop_line;
3977 if (PL_expect == XSTATE && isIDFIRST_lazy(s)) {
3979 if ((PL_bufend - p) >= 3 &&
3980 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
3982 else if ((PL_bufend - p) >= 4 &&
3983 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
3986 if (isIDFIRST_lazy(p)) {
3987 p = scan_ident(p, PL_bufend,
3988 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3992 Perl_croak(aTHX_ "Missing $ on loop variable");
3997 LOP(OP_FORMLINE,XTERM);
4003 LOP(OP_FCNTL,XTERM);
4009 LOP(OP_FLOCK,XTERM);
4018 LOP(OP_GREPSTART, *s == '(' ? XTERM : XREF);
4021 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4036 case KEY_getpriority:
4037 LOP(OP_GETPRIORITY,XTERM);
4039 case KEY_getprotobyname:
4042 case KEY_getprotobynumber:
4043 LOP(OP_GPBYNUMBER,XTERM);
4045 case KEY_getprotoent:
4057 case KEY_getpeername:
4058 UNI(OP_GETPEERNAME);
4060 case KEY_gethostbyname:
4063 case KEY_gethostbyaddr:
4064 LOP(OP_GHBYADDR,XTERM);
4066 case KEY_gethostent:
4069 case KEY_getnetbyname:
4072 case KEY_getnetbyaddr:
4073 LOP(OP_GNBYADDR,XTERM);
4078 case KEY_getservbyname:
4079 LOP(OP_GSBYNAME,XTERM);
4081 case KEY_getservbyport:
4082 LOP(OP_GSBYPORT,XTERM);
4084 case KEY_getservent:
4087 case KEY_getsockname:
4088 UNI(OP_GETSOCKNAME);
4090 case KEY_getsockopt:
4091 LOP(OP_GSOCKOPT,XTERM);
4113 yylval.ival = PL_curcop->cop_line;
4117 LOP(OP_INDEX,XTERM);
4123 LOP(OP_IOCTL,XTERM);
4135 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4167 LOP(OP_LISTEN,XTERM);
4176 s = scan_pat(s,OP_MATCH);
4177 TERM(sublex_start());
4180 LOP(OP_MAPSTART, *s == '(' ? XTERM : XREF);
4183 LOP(OP_MKDIR,XTERM);
4186 LOP(OP_MSGCTL,XTERM);
4189 LOP(OP_MSGGET,XTERM);
4192 LOP(OP_MSGRCV,XTERM);
4195 LOP(OP_MSGSND,XTERM);
4201 if (isIDFIRST_lazy(s)) {
4202 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4203 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4205 PL_in_my_stash = gv_stashpv(PL_tokenbuf, FALSE);
4206 if (!PL_in_my_stash) {
4209 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4217 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4224 if (PL_expect != XSTATE)
4225 yyerror("\"no\" not allowed in expression");
4226 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4227 s = force_version(s);
4232 if (*s == '(' || (s = skipspace(s), *s == '('))
4239 if (isIDFIRST_lazy(s)) {
4241 for (d = s; isALNUM_lazy(d); d++) ;
4243 if (strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_AMBIGUOUS))
4244 Perl_warner(aTHX_ WARN_AMBIGUOUS,
4245 "Precedence problem: open %.*s should be open(%.*s)",
4251 yylval.ival = OP_OR;
4261 LOP(OP_OPEN_DIR,XTERM);
4264 checkcomma(s,PL_tokenbuf,"filehandle");
4268 checkcomma(s,PL_tokenbuf,"filehandle");
4287 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4291 LOP(OP_PIPE_OP,XTERM);
4294 s = scan_str(s,FALSE,FALSE);
4296 missingterm((char*)0);
4297 yylval.ival = OP_CONST;
4298 TERM(sublex_start());
4304 s = scan_str(s,FALSE,FALSE);
4306 missingterm((char*)0);
4308 if (SvCUR(PL_lex_stuff)) {
4311 d = SvPV_force(PL_lex_stuff, len);
4313 for (; isSPACE(*d) && len; --len, ++d) ;
4316 if (!warned && ckWARN(WARN_SYNTAX)) {
4317 for (; !isSPACE(*d) && len; --len, ++d) {
4319 Perl_warner(aTHX_ WARN_SYNTAX,
4320 "Possible attempt to separate words with commas");
4323 else if (*d == '#') {
4324 Perl_warner(aTHX_ WARN_SYNTAX,
4325 "Possible attempt to put comments in qw() list");
4331 for (; !isSPACE(*d) && len; --len, ++d) ;
4333 words = append_elem(OP_LIST, words,
4334 newSVOP(OP_CONST, 0, newSVpvn(b, d-b)));
4338 PL_nextval[PL_nexttoke].opval = words;
4343 SvREFCNT_dec(PL_lex_stuff);
4344 PL_lex_stuff = Nullsv;
4349 s = scan_str(s,FALSE,FALSE);
4351 missingterm((char*)0);
4352 yylval.ival = OP_STRINGIFY;
4353 if (SvIVX(PL_lex_stuff) == '\'')
4354 SvIVX(PL_lex_stuff) = 0; /* qq'$foo' should intepolate */
4355 TERM(sublex_start());
4358 s = scan_pat(s,OP_QR);
4359 TERM(sublex_start());
4362 s = scan_str(s,FALSE,FALSE);
4364 missingterm((char*)0);
4365 yylval.ival = OP_BACKTICK;
4367 TERM(sublex_start());
4373 *PL_tokenbuf = '\0';
4374 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4375 if (isIDFIRST_lazy(PL_tokenbuf))
4376 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
4378 yyerror("<> should be quotes");
4385 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4389 LOP(OP_RENAME,XTERM);
4398 LOP(OP_RINDEX,XTERM);