3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "It all comes from here, the stench and the peril." --Frodo
16 * This file is the lexer for Perl. It's closely linked to the
19 * The main routine is yylex(), which returns the next token.
23 #define PERL_IN_TOKE_C
26 #define yychar (*PL_yycharp)
27 #define yylval (*PL_yylvalp)
29 static const char ident_too_long[] = "Identifier too long";
30 static const char commaless_variable_list[] = "comma-less variable list";
32 static void restore_rsfp(pTHX_ void *f);
33 #ifndef PERL_NO_UTF16_FILTER
34 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
35 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
39 # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
40 # define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
42 # define CURMAD(slot,sv)
43 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
46 #define XFAKEBRACK 128
49 #ifdef USE_UTF8_SCRIPTS
50 # define UTF (!IN_BYTES)
52 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
55 /* In variables named $^X, these are the legal values for X.
56 * 1999-02-27 mjd-perl-patch@plover.com */
57 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
59 /* On MacOS, respect nonbreaking spaces */
60 #ifdef MACOS_TRADITIONAL
61 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
63 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
66 /* LEX_* are values for PL_lex_state, the state of the lexer.
67 * They are arranged oddly so that the guard on the switch statement
68 * can get by with a single comparison (if the compiler is smart enough).
71 /* #define LEX_NOTPARSING 11 is done in perl.h. */
73 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
74 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
75 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
76 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
77 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
79 /* at end of code, eg "$x" followed by: */
80 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
81 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
83 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
84 string or after \E, $foo, etc */
85 #define LEX_INTERPCONST 2 /* NOT USED */
86 #define LEX_FORMLINE 1 /* expecting a format line */
87 #define LEX_KNOWNEXT 0 /* next token known; just return it */
91 static const char* const lex_state_names[] = {
110 #include "keywords.h"
112 /* CLINE is a macro that ensures PL_copline has a sane value */
117 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
120 # define SKIPSPACE0(s) skipspace0(s)
121 # define SKIPSPACE1(s) skipspace1(s)
122 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
123 # define PEEKSPACE(s) skipspace2(s,0)
125 # define SKIPSPACE0(s) skipspace(s)
126 # define SKIPSPACE1(s) skipspace(s)
127 # define SKIPSPACE2(s,tsv) skipspace(s)
128 # define PEEKSPACE(s) skipspace(s)
132 * Convenience functions to return different tokens and prime the
133 * lexer for the next token. They all take an argument.
135 * TOKEN : generic token (used for '(', DOLSHARP, etc)
136 * OPERATOR : generic operator
137 * AOPERATOR : assignment operator
138 * PREBLOCK : beginning the block after an if, while, foreach, ...
139 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
140 * PREREF : *EXPR where EXPR is not a simple identifier
141 * TERM : expression term
142 * LOOPX : loop exiting command (goto, last, dump, etc)
143 * FTST : file test operator
144 * FUN0 : zero-argument function
145 * FUN1 : not used, except for not, which isn't a UNIOP
146 * BOop : bitwise or or xor
148 * SHop : shift operator
149 * PWop : power operator
150 * PMop : pattern-matching operator
151 * Aop : addition-level operator
152 * Mop : multiplication-level operator
153 * Eop : equality-testing operator
154 * Rop : relational operator <= != gt
156 * Also see LOP and lop() below.
159 #ifdef DEBUGGING /* Serve -DT. */
160 # define REPORT(retval) tokereport((I32)retval)
162 # define REPORT(retval) (retval)
165 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
166 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
167 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
168 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
169 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
170 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
171 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
172 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
173 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
174 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
175 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
176 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
177 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
178 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
179 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
180 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
181 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
182 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
183 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
184 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
186 /* This bit of chicanery makes a unary function followed by
187 * a parenthesis into a function with one argument, highest precedence.
188 * The UNIDOR macro is for unary functions that can be followed by the //
189 * operator (such as C<shift // 0>).
191 #define UNI2(f,x) { \
195 PL_last_uni = PL_oldbufptr; \
196 PL_last_lop_op = f; \
198 return REPORT( (int)FUNC1 ); \
200 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
202 #define UNI(f) UNI2(f,XTERM)
203 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
205 #define UNIBRACK(f) { \
208 PL_last_uni = PL_oldbufptr; \
210 return REPORT( (int)FUNC1 ); \
212 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
215 /* grandfather return to old style */
216 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
220 /* how to interpret the yylval associated with the token */
224 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
230 static struct debug_tokens {
232 enum token_type type;
234 } const debug_tokens[] =
236 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
237 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
238 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
239 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
240 { ARROW, TOKENTYPE_NONE, "ARROW" },
241 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
242 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
243 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
244 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
245 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
246 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
247 { DO, TOKENTYPE_NONE, "DO" },
248 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
249 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
250 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
251 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
252 { ELSE, TOKENTYPE_NONE, "ELSE" },
253 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
254 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
255 { FOR, TOKENTYPE_IVAL, "FOR" },
256 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
257 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
258 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
259 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
260 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
261 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
262 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
263 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
264 { IF, TOKENTYPE_IVAL, "IF" },
265 { LABEL, TOKENTYPE_PVAL, "LABEL" },
266 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
267 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
268 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
269 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
270 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
271 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
272 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
273 { MY, TOKENTYPE_IVAL, "MY" },
274 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
275 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
276 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
277 { OROP, TOKENTYPE_IVAL, "OROP" },
278 { OROR, TOKENTYPE_NONE, "OROR" },
279 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
280 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
281 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
282 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
283 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
284 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
285 { PREINC, TOKENTYPE_NONE, "PREINC" },
286 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
287 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
288 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
289 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
290 { SUB, TOKENTYPE_NONE, "SUB" },
291 { THING, TOKENTYPE_OPVAL, "THING" },
292 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
293 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
294 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
295 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
296 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
297 { USE, TOKENTYPE_IVAL, "USE" },
298 { WHEN, TOKENTYPE_IVAL, "WHEN" },
299 { WHILE, TOKENTYPE_IVAL, "WHILE" },
300 { WORD, TOKENTYPE_OPVAL, "WORD" },
301 { 0, TOKENTYPE_NONE, NULL }
304 /* dump the returned token in rv, plus any optional arg in yylval */
307 S_tokereport(pTHX_ I32 rv)
311 const char *name = NULL;
312 enum token_type type = TOKENTYPE_NONE;
313 const struct debug_tokens *p;
314 SV* const report = newSVpvs("<== ");
316 for (p = debug_tokens; p->token; p++) {
317 if (p->token == (int)rv) {
324 Perl_sv_catpv(aTHX_ report, name);
325 else if ((char)rv > ' ' && (char)rv < '~')
326 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
328 sv_catpvs(report, "EOF");
330 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
333 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
336 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
338 case TOKENTYPE_OPNUM:
339 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
340 PL_op_name[yylval.ival]);
343 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
345 case TOKENTYPE_OPVAL:
347 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
348 PL_op_name[yylval.opval->op_type]);
349 if (yylval.opval->op_type == OP_CONST) {
350 Perl_sv_catpvf(aTHX_ report, " %s",
351 SvPEEK(cSVOPx_sv(yylval.opval)));
356 sv_catpvs(report, "(opval=null)");
359 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
365 /* print the buffer with suitable escapes */
368 S_printbuf(pTHX_ const char* fmt, const char* s)
370 SV* const tmp = newSVpvs("");
371 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
380 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
381 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
385 S_ao(pTHX_ int toketype)
388 if (*PL_bufptr == '=') {
390 if (toketype == ANDAND)
391 yylval.ival = OP_ANDASSIGN;
392 else if (toketype == OROR)
393 yylval.ival = OP_ORASSIGN;
394 else if (toketype == DORDOR)
395 yylval.ival = OP_DORASSIGN;
403 * When Perl expects an operator and finds something else, no_op
404 * prints the warning. It always prints "<something> found where
405 * operator expected. It prints "Missing semicolon on previous line?"
406 * if the surprise occurs at the start of the line. "do you need to
407 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
408 * where the compiler doesn't know if foo is a method call or a function.
409 * It prints "Missing operator before end of line" if there's nothing
410 * after the missing operator, or "... before <...>" if there is something
411 * after the missing operator.
415 S_no_op(pTHX_ const char *what, char *s)
418 char * const oldbp = PL_bufptr;
419 const bool is_first = (PL_oldbufptr == PL_linestart);
425 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
426 if (ckWARN_d(WARN_SYNTAX)) {
428 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
429 "\t(Missing semicolon on previous line?)\n");
430 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
432 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
434 if (t < PL_bufptr && isSPACE(*t))
435 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
436 "\t(Do you need to predeclare %.*s?)\n",
437 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
441 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
442 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
450 * Complain about missing quote/regexp/heredoc terminator.
451 * If it's called with NULL then it cauterizes the line buffer.
452 * If we're in a delimited string and the delimiter is a control
453 * character, it's reformatted into a two-char sequence like ^C.
458 S_missingterm(pTHX_ char *s)
464 char * const nl = strrchr(s,'\n');
470 iscntrl(PL_multi_close)
472 PL_multi_close < 32 || PL_multi_close == 127
476 tmpbuf[1] = (char)toCTRL(PL_multi_close);
481 *tmpbuf = (char)PL_multi_close;
485 q = strchr(s,'"') ? '\'' : '"';
486 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
489 #define FEATURE_IS_ENABLED(name) \
490 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
491 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
493 * S_feature_is_enabled
494 * Check whether the named feature is enabled.
497 S_feature_is_enabled(pTHX_ const char *name, STRLEN namelen)
500 HV * const hinthv = GvHV(PL_hintgv);
501 char he_name[32] = "feature_";
502 (void) my_strlcpy(&he_name[8], name, 24);
504 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
512 Perl_deprecate(pTHX_ const char *s)
514 if (ckWARN(WARN_DEPRECATED))
515 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
519 Perl_deprecate_old(pTHX_ const char *s)
521 /* This function should NOT be called for any new deprecated warnings */
522 /* Use Perl_deprecate instead */
524 /* It is here to maintain backward compatibility with the pre-5.8 */
525 /* warnings category hierarchy. The "deprecated" category used to */
526 /* live under the "syntax" category. It is now a top-level category */
527 /* in its own right. */
529 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
530 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
531 "Use of %s is deprecated", s);
535 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
536 * utf16-to-utf8-reversed.
539 #ifdef PERL_CR_FILTER
543 register const char *s = SvPVX_const(sv);
544 register const char * const e = s + SvCUR(sv);
545 /* outer loop optimized to do nothing if there are no CR-LFs */
547 if (*s++ == '\r' && *s == '\n') {
548 /* hit a CR-LF, need to copy the rest */
549 register char *d = s - 1;
552 if (*s == '\r' && s[1] == '\n')
563 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
565 const I32 count = FILTER_READ(idx+1, sv, maxlen);
566 if (count > 0 && !maxlen)
574 * Initialize variables. Uses the Perl save_stack to save its state (for
575 * recursive calls to the parser).
579 Perl_lex_start(pTHX_ SV *line)
585 SAVEI32(PL_lex_dojoin);
586 SAVEI32(PL_lex_brackets);
587 SAVEI32(PL_lex_casemods);
588 SAVEI32(PL_lex_starts);
589 SAVEI32(PL_lex_state);
590 SAVEVPTR(PL_lex_inpat);
591 SAVEI32(PL_lex_inwhat);
593 if (PL_lex_state == LEX_KNOWNEXT) {
594 I32 toke = PL_lasttoke;
595 while (--toke >= 0) {
596 SAVEI32(PL_nexttoke[toke].next_type);
597 SAVEVPTR(PL_nexttoke[toke].next_val);
599 SAVEVPTR(PL_nexttoke[toke].next_mad);
601 SAVEI32(PL_lasttoke);
604 SAVESPTR(PL_thistoken);
605 SAVESPTR(PL_thiswhite);
606 SAVESPTR(PL_nextwhite);
607 SAVESPTR(PL_thisopen);
608 SAVESPTR(PL_thisclose);
609 SAVESPTR(PL_thisstuff);
610 SAVEVPTR(PL_thismad);
611 SAVEI32(PL_realtokenstart);
612 SAVEI32(PL_faketokens);
614 SAVEI32(PL_curforce);
616 if (PL_lex_state == LEX_KNOWNEXT) {
617 I32 toke = PL_nexttoke;
618 while (--toke >= 0) {
619 SAVEI32(PL_nexttype[toke]);
620 SAVEVPTR(PL_nextval[toke]);
622 SAVEI32(PL_nexttoke);
625 SAVECOPLINE(PL_curcop);
628 SAVEPPTR(PL_oldbufptr);
629 SAVEPPTR(PL_oldoldbufptr);
630 SAVEPPTR(PL_last_lop);
631 SAVEPPTR(PL_last_uni);
632 SAVEPPTR(PL_linestart);
633 SAVESPTR(PL_linestr);
634 SAVEGENERICPV(PL_lex_brackstack);
635 SAVEGENERICPV(PL_lex_casestack);
636 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
637 SAVESPTR(PL_lex_stuff);
638 SAVEI32(PL_lex_defer);
639 SAVEI32(PL_sublex_info.sub_inwhat);
640 SAVESPTR(PL_lex_repl);
642 SAVEINT(PL_lex_expect);
644 PL_lex_state = LEX_NORMAL;
648 Newx(PL_lex_brackstack, 120, char);
649 Newx(PL_lex_casestack, 12, char);
651 *PL_lex_casestack = '\0';
663 PL_sublex_info.sub_inwhat = 0;
665 s = SvPV_const(PL_linestr, len);
666 if (SvREADONLY(PL_linestr) || !len || s[len-1] != ';') {
667 PL_linestr = sv_2mortal(len ? newSVsv(PL_linestr) : newSVpvn(s, 0));
668 if (!len || s[len-1] != ';')
669 sv_catpvs(PL_linestr, "\n;");
671 SvTEMP_off(PL_linestr);
672 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
673 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
674 PL_last_lop = PL_last_uni = NULL;
680 * Finalizer for lexing operations. Must be called when the parser is
681 * done with the lexer.
688 PL_doextract = FALSE;
693 * This subroutine has nothing to do with tilting, whether at windmills
694 * or pinball tables. Its name is short for "increment line". It
695 * increments the current line number in CopLINE(PL_curcop) and checks
696 * to see whether the line starts with a comment of the form
697 * # line 500 "foo.pm"
698 * If so, it sets the current line number and file to the values in the comment.
702 S_incline(pTHX_ char *s)
710 CopLINE_inc(PL_curcop);
713 while (SPACE_OR_TAB(*s))
715 if (strnEQ(s, "line", 4))
719 if (SPACE_OR_TAB(*s))
723 while (SPACE_OR_TAB(*s))
731 while (SPACE_OR_TAB(*s))
733 if (*s == '"' && (t = strchr(s+1, '"'))) {
743 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
745 if (*e != '\n' && *e != '\0')
746 return; /* false alarm */
752 const char * const cf = CopFILE(PL_curcop);
753 STRLEN tmplen = cf ? strlen(cf) : 0;
754 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
755 /* must copy *{"::_<(eval N)[oldfilename:L]"}
756 * to *{"::_<newfilename"} */
757 char smallbuf[256], smallbuf2[256];
758 char *tmpbuf, *tmpbuf2;
760 STRLEN tmplen2 = strlen(s);
761 if (tmplen + 3 < sizeof smallbuf)
764 Newx(tmpbuf, tmplen + 3, char);
765 if (tmplen2 + 3 < sizeof smallbuf2)
768 Newx(tmpbuf2, tmplen2 + 3, char);
769 tmpbuf[0] = tmpbuf2[0] = '_';
770 tmpbuf[1] = tmpbuf2[1] = '<';
771 memcpy(tmpbuf + 2, cf, ++tmplen);
772 memcpy(tmpbuf2 + 2, s, ++tmplen2);
774 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
776 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
778 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
779 /* adjust ${"::_<newfilename"} to store the new file name */
780 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
781 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
782 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
785 if (tmpbuf != smallbuf) Safefree(tmpbuf);
786 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
789 CopFILE_free(PL_curcop);
790 CopFILE_set(PL_curcop, s);
793 CopLINE_set(PL_curcop, atoi(n)-1);
797 /* skip space before PL_thistoken */
800 S_skipspace0(pTHX_ register char *s)
807 PL_thiswhite = newSVpvs("");
808 sv_catsv(PL_thiswhite, PL_skipwhite);
809 sv_free(PL_skipwhite);
812 PL_realtokenstart = s - SvPVX(PL_linestr);
816 /* skip space after PL_thistoken */
819 S_skipspace1(pTHX_ register char *s)
821 const char *start = s;
822 I32 startoff = start - SvPVX(PL_linestr);
827 start = SvPVX(PL_linestr) + startoff;
828 if (!PL_thistoken && PL_realtokenstart >= 0) {
829 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
830 PL_thistoken = newSVpvn(tstart, start - tstart);
832 PL_realtokenstart = -1;
835 PL_nextwhite = newSVpvs("");
836 sv_catsv(PL_nextwhite, PL_skipwhite);
837 sv_free(PL_skipwhite);
844 S_skipspace2(pTHX_ register char *s, SV **svp)
847 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
848 const I32 startoff = s - SvPVX(PL_linestr);
851 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
852 if (!PL_madskills || !svp)
854 start = SvPVX(PL_linestr) + startoff;
855 if (!PL_thistoken && PL_realtokenstart >= 0) {
856 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
857 PL_thistoken = newSVpvn(tstart, start - tstart);
858 PL_realtokenstart = -1;
863 sv_setsv(*svp, PL_skipwhite);
864 sv_free(PL_skipwhite);
873 S_update_debugger_info_pv(pTHX_ const char *buf, STRLEN len)
875 AV *av = CopFILEAVx(PL_curcop);
877 SV * const sv = newSV(0);
878 sv_upgrade(sv, SVt_PVMG);
879 sv_setpvn(sv, buf, len);
882 av_store(av, (I32)CopLINE(PL_curcop), sv);
887 S_update_debugger_info_sv(pTHX_ SV *orig_sv)
889 AV *av = CopFILEAVx(PL_curcop);
891 SV * const sv = newSV(0);
892 sv_upgrade(sv, SVt_PVMG);
893 sv_setsv(sv, orig_sv);
896 av_store(av, (I32)CopLINE(PL_curcop), sv);
902 * Called to gobble the appropriate amount and type of whitespace.
903 * Skips comments as well.
907 S_skipspace(pTHX_ register char *s)
912 int startoff = s - SvPVX(PL_linestr);
915 sv_free(PL_skipwhite);
920 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
921 while (s < PL_bufend && SPACE_OR_TAB(*s))
931 SSize_t oldprevlen, oldoldprevlen;
932 SSize_t oldloplen = 0, oldunilen = 0;
933 while (s < PL_bufend && isSPACE(*s)) {
934 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
939 if (s < PL_bufend && *s == '#') {
940 while (s < PL_bufend && *s != '\n')
944 if (PL_in_eval && !PL_rsfp) {
951 /* only continue to recharge the buffer if we're at the end
952 * of the buffer, we're not reading from a source filter, and
953 * we're in normal lexing mode
955 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
956 PL_lex_state == LEX_FORMLINE)
963 /* try to recharge the buffer */
965 curoff = s - SvPVX(PL_linestr);
968 if ((s = filter_gets(PL_linestr, PL_rsfp,
969 (prevlen = SvCUR(PL_linestr)))) == NULL)
972 if (PL_madskills && curoff != startoff) {
974 PL_skipwhite = newSVpvs("");
975 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
979 /* mustn't throw out old stuff yet if madpropping */
980 SvCUR(PL_linestr) = curoff;
981 s = SvPVX(PL_linestr) + curoff;
983 if (curoff && s[-1] == '\n')
987 /* end of file. Add on the -p or -n magic */
988 /* XXX these shouldn't really be added here, can't set PL_faketokens */
992 ";}continue{print or die qq(-p destination: $!\\n);}");
995 ";}continue{print or die qq(-p destination: $!\\n);}");
997 PL_minus_n = PL_minus_p = 0;
999 else if (PL_minus_n) {
1001 sv_catpvn(PL_linestr, ";}", 2);
1003 sv_setpvn(PL_linestr, ";}", 2);
1009 sv_catpvn(PL_linestr,";", 1);
1011 sv_setpvn(PL_linestr,";", 1);
1014 /* reset variables for next time we lex */
1015 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
1021 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1022 PL_last_lop = PL_last_uni = NULL;
1024 /* Close the filehandle. Could be from -P preprocessor,
1025 * STDIN, or a regular file. If we were reading code from
1026 * STDIN (because the commandline held no -e or filename)
1027 * then we don't close it, we reset it so the code can
1028 * read from STDIN too.
1031 if (PL_preprocess && !PL_in_eval)
1032 (void)PerlProc_pclose(PL_rsfp);
1033 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1034 PerlIO_clearerr(PL_rsfp);
1036 (void)PerlIO_close(PL_rsfp);
1041 /* not at end of file, so we only read another line */
1042 /* make corresponding updates to old pointers, for yyerror() */
1043 oldprevlen = PL_oldbufptr - PL_bufend;
1044 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1046 oldunilen = PL_last_uni - PL_bufend;
1048 oldloplen = PL_last_lop - PL_bufend;
1049 PL_linestart = PL_bufptr = s + prevlen;
1050 PL_bufend = s + SvCUR(PL_linestr);
1052 PL_oldbufptr = s + oldprevlen;
1053 PL_oldoldbufptr = s + oldoldprevlen;
1055 PL_last_uni = s + oldunilen;
1057 PL_last_lop = s + oldloplen;
1060 /* debugger active and we're not compiling the debugger code,
1061 * so store the line into the debugger's array of lines
1063 if (PERLDB_LINE && PL_curstash != PL_debstash)
1064 update_debugger_info_pv(PL_bufptr, PL_bufend - PL_bufptr);
1071 PL_skipwhite = newSVpvs("");
1072 curoff = s - SvPVX(PL_linestr);
1073 if (curoff - startoff)
1074 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1083 * Check the unary operators to ensure there's no ambiguity in how they're
1084 * used. An ambiguous piece of code would be:
1086 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1087 * the +5 is its argument.
1097 if (PL_oldoldbufptr != PL_last_uni)
1099 while (isSPACE(*PL_last_uni))
1102 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1104 if ((t = strchr(s, '(')) && t < PL_bufptr)
1107 if (ckWARN_d(WARN_AMBIGUOUS)){
1108 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1109 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1110 (int)(s - PL_last_uni), PL_last_uni);
1115 * LOP : macro to build a list operator. Its behaviour has been replaced
1116 * with a subroutine, S_lop() for which LOP is just another name.
1119 #define LOP(f,x) return lop(f,x,s)
1123 * Build a list operator (or something that might be one). The rules:
1124 * - if we have a next token, then it's a list operator [why?]
1125 * - if the next thing is an opening paren, then it's a function
1126 * - else it's a list operator
1130 S_lop(pTHX_ I32 f, int x, char *s)
1137 PL_last_lop = PL_oldbufptr;
1138 PL_last_lop_op = (OPCODE)f;
1141 return REPORT(LSTOP);
1144 return REPORT(LSTOP);
1147 return REPORT(FUNC);
1150 return REPORT(FUNC);
1152 return REPORT(LSTOP);
1158 * Sets up for an eventual force_next(). start_force(0) basically does
1159 * an unshift, while start_force(-1) does a push. yylex removes items
1164 S_start_force(pTHX_ int where)
1168 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1169 where = PL_lasttoke;
1170 assert(PL_curforce < 0 || PL_curforce == where);
1171 if (PL_curforce != where) {
1172 for (i = PL_lasttoke; i > where; --i) {
1173 PL_nexttoke[i] = PL_nexttoke[i-1];
1177 if (PL_curforce < 0) /* in case of duplicate start_force() */
1178 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1179 PL_curforce = where;
1182 curmad('^', newSVpvs(""));
1183 CURMAD('_', PL_nextwhite);
1188 S_curmad(pTHX_ char slot, SV *sv)
1194 if (PL_curforce < 0)
1195 where = &PL_thismad;
1197 where = &PL_nexttoke[PL_curforce].next_mad;
1200 sv_setpvn(sv, "", 0);
1203 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1205 else if (PL_encoding) {
1206 sv_recode_to_utf8(sv, PL_encoding);
1211 /* keep a slot open for the head of the list? */
1212 if (slot != '_' && *where && (*where)->mad_key == '^') {
1213 (*where)->mad_key = slot;
1214 sv_free((*where)->mad_val);
1215 (*where)->mad_val = (void*)sv;
1218 addmad(newMADsv(slot, sv), where, 0);
1221 # define start_force(where) NOOP
1222 # define curmad(slot, sv) NOOP
1227 * When the lexer realizes it knows the next token (for instance,
1228 * it is reordering tokens for the parser) then it can call S_force_next
1229 * to know what token to return the next time the lexer is called. Caller
1230 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1231 * and possibly PL_expect to ensure the lexer handles the token correctly.
1235 S_force_next(pTHX_ I32 type)
1239 if (PL_curforce < 0)
1240 start_force(PL_lasttoke);
1241 PL_nexttoke[PL_curforce].next_type = type;
1242 if (PL_lex_state != LEX_KNOWNEXT)
1243 PL_lex_defer = PL_lex_state;
1244 PL_lex_state = LEX_KNOWNEXT;
1245 PL_lex_expect = PL_expect;
1248 PL_nexttype[PL_nexttoke] = type;
1250 if (PL_lex_state != LEX_KNOWNEXT) {
1251 PL_lex_defer = PL_lex_state;
1252 PL_lex_expect = PL_expect;
1253 PL_lex_state = LEX_KNOWNEXT;
1259 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1262 SV * const sv = newSVpvn(start,len);
1263 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1270 * When the lexer knows the next thing is a word (for instance, it has
1271 * just seen -> and it knows that the next char is a word char, then
1272 * it calls S_force_word to stick the next word into the PL_next lookahead.
1275 * char *start : buffer position (must be within PL_linestr)
1276 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
1277 * int check_keyword : if true, Perl checks to make sure the word isn't
1278 * a keyword (do this if the word is a label, e.g. goto FOO)
1279 * int allow_pack : if true, : characters will also be allowed (require,
1280 * use, etc. do this)
1281 * int allow_initial_tick : used by the "sub" lexer only.
1285 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1291 start = SKIPSPACE1(start);
1293 if (isIDFIRST_lazy_if(s,UTF) ||
1294 (allow_pack && *s == ':') ||
1295 (allow_initial_tick && *s == '\'') )
1297 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1298 if (check_keyword && keyword(PL_tokenbuf, len, 0))
1300 start_force(PL_curforce);
1302 curmad('X', newSVpvn(start,s-start));
1303 if (token == METHOD) {
1308 PL_expect = XOPERATOR;
1311 NEXTVAL_NEXTTOKE.opval
1312 = (OP*)newSVOP(OP_CONST,0,
1313 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1314 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1322 * Called when the lexer wants $foo *foo &foo etc, but the program
1323 * text only contains the "foo" portion. The first argument is a pointer
1324 * to the "foo", and the second argument is the type symbol to prefix.
1325 * Forces the next token to be a "WORD".
1326 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1330 S_force_ident(pTHX_ register const char *s, int kind)
1334 const STRLEN len = strlen(s);
1335 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1336 start_force(PL_curforce);
1337 NEXTVAL_NEXTTOKE.opval = o;
1340 o->op_private = OPpCONST_ENTERED;
1341 /* XXX see note in pp_entereval() for why we forgo typo
1342 warnings if the symbol must be introduced in an eval.
1344 gv_fetchpvn_flags(s, len,
1345 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1347 kind == '$' ? SVt_PV :
1348 kind == '@' ? SVt_PVAV :
1349 kind == '%' ? SVt_PVHV :
1357 Perl_str_to_version(pTHX_ SV *sv)
1362 const char *start = SvPV_const(sv,len);
1363 const char * const end = start + len;
1364 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1365 while (start < end) {
1369 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1374 retval += ((NV)n)/nshift;
1383 * Forces the next token to be a version number.
1384 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1385 * and if "guessing" is TRUE, then no new token is created (and the caller
1386 * must use an alternative parsing method).
1390 S_force_version(pTHX_ char *s, int guessing)
1396 I32 startoff = s - SvPVX(PL_linestr);
1405 while (isDIGIT(*d) || *d == '_' || *d == '.')
1409 start_force(PL_curforce);
1410 curmad('X', newSVpvn(s,d-s));
1413 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1415 s = scan_num(s, &yylval);
1416 version = yylval.opval;
1417 ver = cSVOPx(version)->op_sv;
1418 if (SvPOK(ver) && !SvNIOK(ver)) {
1419 SvUPGRADE(ver, SVt_PVNV);
1420 SvNV_set(ver, str_to_version(ver));
1421 SvNOK_on(ver); /* hint that it is a version */
1424 else if (guessing) {
1427 sv_free(PL_nextwhite); /* let next token collect whitespace */
1429 s = SvPVX(PL_linestr) + startoff;
1437 if (PL_madskills && !version) {
1438 sv_free(PL_nextwhite); /* let next token collect whitespace */
1440 s = SvPVX(PL_linestr) + startoff;
1443 /* NOTE: The parser sees the package name and the VERSION swapped */
1444 start_force(PL_curforce);
1445 NEXTVAL_NEXTTOKE.opval = version;
1453 * Tokenize a quoted string passed in as an SV. It finds the next
1454 * chunk, up to end of string or a backslash. It may make a new
1455 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1460 S_tokeq(pTHX_ SV *sv)
1464 register char *send;
1472 s = SvPV_force(sv, len);
1473 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1476 while (s < send && *s != '\\')
1481 if ( PL_hints & HINT_NEW_STRING ) {
1482 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1488 if (s + 1 < send && (s[1] == '\\'))
1489 s++; /* all that, just for this */
1494 SvCUR_set(sv, d - SvPVX_const(sv));
1496 if ( PL_hints & HINT_NEW_STRING )
1497 return new_constant(NULL, 0, "q", sv, pv, "q");
1502 * Now come three functions related to double-quote context,
1503 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1504 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1505 * interact with PL_lex_state, and create fake ( ... ) argument lists
1506 * to handle functions and concatenation.
1507 * They assume that whoever calls them will be setting up a fake
1508 * join call, because each subthing puts a ',' after it. This lets
1511 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1513 * (I'm not sure whether the spurious commas at the end of lcfirst's
1514 * arguments and join's arguments are created or not).
1519 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1521 * Pattern matching will set PL_lex_op to the pattern-matching op to
1522 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1524 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1526 * Everything else becomes a FUNC.
1528 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1529 * had an OP_CONST or OP_READLINE). This just sets us up for a
1530 * call to S_sublex_push().
1534 S_sublex_start(pTHX)
1537 register const I32 op_type = yylval.ival;
1539 if (op_type == OP_NULL) {
1540 yylval.opval = PL_lex_op;
1544 if (op_type == OP_CONST || op_type == OP_READLINE) {
1545 SV *sv = tokeq(PL_lex_stuff);
1547 if (SvTYPE(sv) == SVt_PVIV) {
1548 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1550 const char * const p = SvPV_const(sv, len);
1551 SV * const nsv = newSVpvn(p, len);
1557 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1558 PL_lex_stuff = NULL;
1559 /* Allow <FH> // "foo" */
1560 if (op_type == OP_READLINE)
1561 PL_expect = XTERMORDORDOR;
1564 else if (op_type == OP_BACKTICK && PL_lex_op) {
1565 /* readpipe() vas overriden */
1566 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1567 yylval.opval = PL_lex_op;
1569 PL_lex_stuff = NULL;
1573 PL_sublex_info.super_state = PL_lex_state;
1574 PL_sublex_info.sub_inwhat = op_type;
1575 PL_sublex_info.sub_op = PL_lex_op;
1576 PL_lex_state = LEX_INTERPPUSH;
1580 yylval.opval = PL_lex_op;
1590 * Create a new scope to save the lexing state. The scope will be
1591 * ended in S_sublex_done. Returns a '(', starting the function arguments
1592 * to the uc, lc, etc. found before.
1593 * Sets PL_lex_state to LEX_INTERPCONCAT.
1602 PL_lex_state = PL_sublex_info.super_state;
1603 SAVEI32(PL_lex_dojoin);
1604 SAVEI32(PL_lex_brackets);
1605 SAVEI32(PL_lex_casemods);
1606 SAVEI32(PL_lex_starts);
1607 SAVEI32(PL_lex_state);
1608 SAVEVPTR(PL_lex_inpat);
1609 SAVEI32(PL_lex_inwhat);
1610 SAVECOPLINE(PL_curcop);
1611 SAVEPPTR(PL_bufptr);
1612 SAVEPPTR(PL_bufend);
1613 SAVEPPTR(PL_oldbufptr);
1614 SAVEPPTR(PL_oldoldbufptr);
1615 SAVEPPTR(PL_last_lop);
1616 SAVEPPTR(PL_last_uni);
1617 SAVEPPTR(PL_linestart);
1618 SAVESPTR(PL_linestr);
1619 SAVEGENERICPV(PL_lex_brackstack);
1620 SAVEGENERICPV(PL_lex_casestack);
1622 PL_linestr = PL_lex_stuff;
1623 PL_lex_stuff = NULL;
1625 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1626 = SvPVX(PL_linestr);
1627 PL_bufend += SvCUR(PL_linestr);
1628 PL_last_lop = PL_last_uni = NULL;
1629 SAVEFREESV(PL_linestr);
1631 PL_lex_dojoin = FALSE;
1632 PL_lex_brackets = 0;
1633 Newx(PL_lex_brackstack, 120, char);
1634 Newx(PL_lex_casestack, 12, char);
1635 PL_lex_casemods = 0;
1636 *PL_lex_casestack = '\0';
1638 PL_lex_state = LEX_INTERPCONCAT;
1639 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1641 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1642 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1643 PL_lex_inpat = PL_sublex_info.sub_op;
1645 PL_lex_inpat = NULL;
1652 * Restores lexer state after a S_sublex_push.
1659 if (!PL_lex_starts++) {
1660 SV * const sv = newSVpvs("");
1661 if (SvUTF8(PL_linestr))
1663 PL_expect = XOPERATOR;
1664 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1668 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1669 PL_lex_state = LEX_INTERPCASEMOD;
1673 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1674 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1675 PL_linestr = PL_lex_repl;
1677 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1678 PL_bufend += SvCUR(PL_linestr);
1679 PL_last_lop = PL_last_uni = NULL;
1680 SAVEFREESV(PL_linestr);
1681 PL_lex_dojoin = FALSE;
1682 PL_lex_brackets = 0;
1683 PL_lex_casemods = 0;
1684 *PL_lex_casestack = '\0';
1686 if (SvEVALED(PL_lex_repl)) {
1687 PL_lex_state = LEX_INTERPNORMAL;
1689 /* we don't clear PL_lex_repl here, so that we can check later
1690 whether this is an evalled subst; that means we rely on the
1691 logic to ensure sublex_done() is called again only via the
1692 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1695 PL_lex_state = LEX_INTERPCONCAT;
1705 PL_endwhite = newSVpvs("");
1706 sv_catsv(PL_endwhite, PL_thiswhite);
1710 sv_setpvn(PL_thistoken,"",0);
1712 PL_realtokenstart = -1;
1716 PL_bufend = SvPVX(PL_linestr);
1717 PL_bufend += SvCUR(PL_linestr);
1718 PL_expect = XOPERATOR;
1719 PL_sublex_info.sub_inwhat = 0;
1727 Extracts a pattern, double-quoted string, or transliteration. This
1730 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
1731 processing a pattern (PL_lex_inpat is true), a transliteration
1732 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
1734 Returns a pointer to the character scanned up to. If this is
1735 advanced from the start pointer supplied (i.e. if anything was
1736 successfully parsed), will leave an OP for the substring scanned
1737 in yylval. Caller must intuit reason for not parsing further
1738 by looking at the next characters herself.
1742 double-quoted style: \r and \n
1743 regexp special ones: \D \s
1746 case and quoting: \U \Q \E
1747 stops on @ and $, but not for $ as tail anchor
1749 In transliterations:
1750 characters are VERY literal, except for - not at the start or end
1751 of the string, which indicates a range. If the range is in bytes,
1752 scan_const expands the range to the full set of intermediate
1753 characters. If the range is in utf8, the hyphen is replaced with
1754 a certain range mark which will be handled by pmtrans() in op.c.
1756 In double-quoted strings:
1758 double-quoted style: \r and \n
1760 deprecated backrefs: \1 (in substitution replacements)
1761 case and quoting: \U \Q \E
1764 scan_const does *not* construct ops to handle interpolated strings.
1765 It stops processing as soon as it finds an embedded $ or @ variable
1766 and leaves it to the caller to work out what's going on.
1768 embedded arrays (whether in pattern or not) could be:
1769 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1771 $ in double-quoted strings must be the symbol of an embedded scalar.
1773 $ in pattern could be $foo or could be tail anchor. Assumption:
1774 it's a tail anchor if $ is the last thing in the string, or if it's
1775 followed by one of "()| \r\n\t"
1777 \1 (backreferences) are turned into $1
1779 The structure of the code is
1780 while (there's a character to process) {
1781 handle transliteration ranges
1782 skip regexp comments /(?#comment)/ and codes /(?{code})/
1783 skip #-initiated comments in //x patterns
1784 check for embedded arrays
1785 check for embedded scalars
1787 leave intact backslashes from leaveit (below)
1788 deprecate \1 in substitution replacements
1789 handle string-changing backslashes \l \U \Q \E, etc.
1790 switch (what was escaped) {
1791 handle \- in a transliteration (becomes a literal -)
1792 handle \132 (octal characters)
1793 handle \x15 and \x{1234} (hex characters)
1794 handle \N{name} (named characters)
1795 handle \cV (control characters)
1796 handle printf-style backslashes (\f, \r, \n, etc)
1798 } (end if backslash)
1799 } (end while character to read)
1804 S_scan_const(pTHX_ char *start)
1807 register char *send = PL_bufend; /* end of the constant */
1808 SV *sv = newSV(send - start); /* sv for the constant */
1809 register char *s = start; /* start of the constant */
1810 register char *d = SvPVX(sv); /* destination for copies */
1811 bool dorange = FALSE; /* are we in a translit range? */
1812 bool didrange = FALSE; /* did we just finish a range? */
1813 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1814 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1817 UV literal_endpoint = 0;
1818 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
1821 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1822 /* If we are doing a trans and we know we want UTF8 set expectation */
1823 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1824 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1828 while (s < send || dorange) {
1829 /* get transliterations out of the way (they're most literal) */
1830 if (PL_lex_inwhat == OP_TRANS) {
1831 /* expand a range A-Z to the full set of characters. AIE! */
1833 I32 i; /* current expanded character */
1834 I32 min; /* first character in range */
1835 I32 max; /* last character in range */
1846 char * const c = (char*)utf8_hop((U8*)d, -1);
1850 *c = (char)UTF_TO_NATIVE(0xff);
1851 /* mark the range as done, and continue */
1857 i = d - SvPVX_const(sv); /* remember current offset */
1860 SvLEN(sv) + (has_utf8 ?
1861 (512 - UTF_CONTINUATION_MARK +
1864 /* How many two-byte within 0..255: 128 in UTF-8,
1865 * 96 in UTF-8-mod. */
1867 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1869 d = SvPVX(sv) + i; /* refresh d after realloc */
1873 for (j = 0; j <= 1; j++) {
1874 char * const c = (char*)utf8_hop((U8*)d, -1);
1875 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
1881 max = (U8)0xff; /* only to \xff */
1882 uvmax = uv; /* \x{100} to uvmax */
1884 d = c; /* eat endpoint chars */
1889 d -= 2; /* eat the first char and the - */
1890 min = (U8)*d; /* first char in range */
1891 max = (U8)d[1]; /* last char in range */
1898 "Invalid range \"%c-%c\" in transliteration operator",
1899 (char)min, (char)max);
1903 if (literal_endpoint == 2 &&
1904 ((isLOWER(min) && isLOWER(max)) ||
1905 (isUPPER(min) && isUPPER(max)))) {
1907 for (i = min; i <= max; i++)
1909 *d++ = NATIVE_TO_NEED(has_utf8,i);
1911 for (i = min; i <= max; i++)
1913 *d++ = NATIVE_TO_NEED(has_utf8,i);
1918 for (i = min; i <= max; i++)
1921 const U8 ch = (U8)NATIVE_TO_UTF(i);
1922 if (UNI_IS_INVARIANT(ch))
1925 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
1926 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
1935 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
1937 *d++ = (char)UTF_TO_NATIVE(0xff);
1939 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
1943 /* mark the range as done, and continue */
1947 literal_endpoint = 0;
1952 /* range begins (ignore - as first or last char) */
1953 else if (*s == '-' && s+1 < send && s != start) {
1955 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1962 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1972 literal_endpoint = 0;
1973 native_range = TRUE;
1978 /* if we get here, we're not doing a transliteration */
1980 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1981 except for the last char, which will be done separately. */
1982 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1984 while (s+1 < send && *s != ')')
1985 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1987 else if (s[2] == '{' /* This should match regcomp.c */
1988 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1991 char *regparse = s + (s[2] == '{' ? 3 : 4);
1994 while (count && (c = *regparse)) {
1995 if (c == '\\' && regparse[1])
2003 if (*regparse != ')')
2004 regparse--; /* Leave one char for continuation. */
2005 while (s < regparse)
2006 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2010 /* likewise skip #-initiated comments in //x patterns */
2011 else if (*s == '#' && PL_lex_inpat &&
2012 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2013 while (s+1 < send && *s != '\n')
2014 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2017 /* check for embedded arrays
2018 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2020 else if (*s == '@' && s[1]) {
2021 if (isALNUM_lazy_if(s+1,UTF))
2023 if (strchr(":'{$", s[1]))
2025 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2026 break; /* in regexp, neither @+ nor @- are interpolated */
2029 /* check for embedded scalars. only stop if we're sure it's a
2032 else if (*s == '$') {
2033 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
2035 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
2036 break; /* in regexp, $ might be tail anchor */
2039 /* End of else if chain - OP_TRANS rejoin rest */
2042 if (*s == '\\' && s+1 < send) {
2045 /* deprecate \1 in strings and substitution replacements */
2046 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2047 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2049 if (ckWARN(WARN_SYNTAX))
2050 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2055 /* string-change backslash escapes */
2056 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2060 /* skip any other backslash escapes in a pattern */
2061 else if (PL_lex_inpat) {
2062 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2063 goto default_action;
2066 /* if we get here, it's either a quoted -, or a digit */
2069 /* quoted - in transliterations */
2071 if (PL_lex_inwhat == OP_TRANS) {
2078 if ((isALPHA(*s) || isDIGIT(*s)) &&
2080 Perl_warner(aTHX_ packWARN(WARN_MISC),
2081 "Unrecognized escape \\%c passed through",
2083 /* default action is to copy the quoted character */
2084 goto default_action;
2087 /* \132 indicates an octal constant */
2088 case '0': case '1': case '2': case '3':
2089 case '4': case '5': case '6': case '7':
2093 uv = grok_oct(s, &len, &flags, NULL);
2096 goto NUM_ESCAPE_INSERT;
2098 /* \x24 indicates a hex constant */
2102 char* const e = strchr(s, '}');
2103 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2104 PERL_SCAN_DISALLOW_PREFIX;
2109 yyerror("Missing right brace on \\x{}");
2113 uv = grok_hex(s, &len, &flags, NULL);
2119 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2120 uv = grok_hex(s, &len, &flags, NULL);
2126 /* Insert oct or hex escaped character.
2127 * There will always enough room in sv since such
2128 * escapes will be longer than any UTF-8 sequence
2129 * they can end up as. */
2131 /* We need to map to chars to ASCII before doing the tests
2134 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2135 if (!has_utf8 && uv > 255) {
2136 /* Might need to recode whatever we have
2137 * accumulated so far if it contains any
2140 * (Can't we keep track of that and avoid
2141 * this rescan? --jhi)
2145 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2146 if (!NATIVE_IS_INVARIANT(*c)) {
2151 const STRLEN offset = d - SvPVX_const(sv);
2153 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2157 while (src >= (const U8 *)SvPVX_const(sv)) {
2158 if (!NATIVE_IS_INVARIANT(*src)) {
2159 const U8 ch = NATIVE_TO_ASCII(*src);
2160 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2161 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2171 if (has_utf8 || uv > 255) {
2172 d = (char*)uvchr_to_utf8((U8*)d, uv);
2174 if (PL_lex_inwhat == OP_TRANS &&
2175 PL_sublex_info.sub_op) {
2176 PL_sublex_info.sub_op->op_private |=
2177 (PL_lex_repl ? OPpTRANS_FROM_UTF
2181 if (uv > 255 && !dorange)
2182 native_range = FALSE;
2194 /* \N{LATIN SMALL LETTER A} is a named character */
2198 char* e = strchr(s, '}');
2205 yyerror("Missing right brace on \\N{}");
2209 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2211 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2212 PERL_SCAN_DISALLOW_PREFIX;
2215 uv = grok_hex(s, &len, &flags, NULL);
2216 if ( e > s && len != (STRLEN)(e - s) ) {
2220 goto NUM_ESCAPE_INSERT;
2222 res = newSVpvn(s + 1, e - s - 1);
2223 type = newSVpvn(s - 2,e - s + 3);
2224 res = new_constant( NULL, 0, "charnames",
2225 res, NULL, SvPVX(type) );
2228 sv_utf8_upgrade(res);
2229 str = SvPV_const(res,len);
2230 #ifdef EBCDIC_NEVER_MIND
2231 /* charnames uses pack U and that has been
2232 * recently changed to do the below uni->native
2233 * mapping, so this would be redundant (and wrong,
2234 * the code point would be doubly converted).
2235 * But leave this in just in case the pack U change
2236 * gets revoked, but the semantics is still
2237 * desireable for charnames. --jhi */
2239 UV uv = utf8_to_uvchr((const U8*)str, 0);
2242 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2244 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2245 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2246 str = SvPV_const(res, len);
2250 if (!has_utf8 && SvUTF8(res)) {
2251 const char * const ostart = SvPVX_const(sv);
2252 SvCUR_set(sv, d - ostart);
2255 sv_utf8_upgrade(sv);
2256 /* this just broke our allocation above... */
2257 SvGROW(sv, (STRLEN)(send - start));
2258 d = SvPVX(sv) + SvCUR(sv);
2261 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2262 const char * const odest = SvPVX_const(sv);
2264 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2265 d = SvPVX(sv) + (d - odest);
2269 native_range = FALSE; /* \N{} is guessed to be Unicode */
2271 Copy(str, d, len, char);
2278 yyerror("Missing braces on \\N{}");
2281 /* \c is a control character */
2290 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2293 yyerror("Missing control char name in \\c");
2297 /* printf-style backslashes, formfeeds, newlines, etc */
2299 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2302 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2305 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2308 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2311 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2314 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2317 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2323 } /* end if (backslash) */
2330 /* If we started with encoded form, or already know we want it
2331 and then encode the next character */
2332 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2334 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2335 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2338 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2339 const STRLEN off = d - SvPVX_const(sv);
2340 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2342 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2345 if (uv > 255 && !dorange)
2346 native_range = FALSE;
2350 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2352 } /* while loop to process each character */
2354 /* terminate the string and set up the sv */
2356 SvCUR_set(sv, d - SvPVX_const(sv));
2357 if (SvCUR(sv) >= SvLEN(sv))
2358 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2361 if (PL_encoding && !has_utf8) {
2362 sv_recode_to_utf8(sv, PL_encoding);
2368 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2369 PL_sublex_info.sub_op->op_private |=
2370 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2374 /* shrink the sv if we allocated more than we used */
2375 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2376 SvPV_shrink_to_cur(sv);
2379 /* return the substring (via yylval) only if we parsed anything */
2380 if (s > PL_bufptr) {
2381 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2382 sv = new_constant(start, s - start,
2383 (const char *)(PL_lex_inpat ? "qr" : "q"),
2386 (( PL_lex_inwhat == OP_TRANS
2388 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2391 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2398 * Returns TRUE if there's more to the expression (e.g., a subscript),
2401 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2403 * ->[ and ->{ return TRUE
2404 * { and [ outside a pattern are always subscripts, so return TRUE
2405 * if we're outside a pattern and it's not { or [, then return FALSE
2406 * if we're in a pattern and the first char is a {
2407 * {4,5} (any digits around the comma) returns FALSE
2408 * if we're in a pattern and the first char is a [
2410 * [SOMETHING] has a funky algorithm to decide whether it's a
2411 * character class or not. It has to deal with things like
2412 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2413 * anything else returns TRUE
2416 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2419 S_intuit_more(pTHX_ register char *s)
2422 if (PL_lex_brackets)
2424 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2426 if (*s != '{' && *s != '[')
2431 /* In a pattern, so maybe we have {n,m}. */
2448 /* On the other hand, maybe we have a character class */
2451 if (*s == ']' || *s == '^')
2454 /* this is terrifying, and it works */
2455 int weight = 2; /* let's weigh the evidence */
2457 unsigned char un_char = 255, last_un_char;
2458 const char * const send = strchr(s,']');
2459 char tmpbuf[sizeof PL_tokenbuf * 4];
2461 if (!send) /* has to be an expression */
2464 Zero(seen,256,char);
2467 else if (isDIGIT(*s)) {
2469 if (isDIGIT(s[1]) && s[2] == ']')
2475 for (; s < send; s++) {
2476 last_un_char = un_char;
2477 un_char = (unsigned char)*s;
2482 weight -= seen[un_char] * 10;
2483 if (isALNUM_lazy_if(s+1,UTF)) {
2485 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2486 len = (int)strlen(tmpbuf);
2487 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2492 else if (*s == '$' && s[1] &&
2493 strchr("[#!%*<>()-=",s[1])) {
2494 if (/*{*/ strchr("])} =",s[2]))
2503 if (strchr("wds]",s[1]))
2505 else if (seen[(U8)'\''] || seen[(U8)'"'])
2507 else if (strchr("rnftbxcav",s[1]))
2509 else if (isDIGIT(s[1])) {
2511 while (s[1] && isDIGIT(s[1]))
2521 if (strchr("aA01! ",last_un_char))
2523 if (strchr("zZ79~",s[1]))
2525 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2526 weight -= 5; /* cope with negative subscript */
2529 if (!isALNUM(last_un_char)
2530 && !(last_un_char == '$' || last_un_char == '@'
2531 || last_un_char == '&')
2532 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2537 if (keyword(tmpbuf, d - tmpbuf, 0))
2540 if (un_char == last_un_char + 1)
2542 weight -= seen[un_char];
2547 if (weight >= 0) /* probably a character class */
2557 * Does all the checking to disambiguate
2559 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2560 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2562 * First argument is the stuff after the first token, e.g. "bar".
2564 * Not a method if bar is a filehandle.
2565 * Not a method if foo is a subroutine prototyped to take a filehandle.
2566 * Not a method if it's really "Foo $bar"
2567 * Method if it's "foo $bar"
2568 * Not a method if it's really "print foo $bar"
2569 * Method if it's really "foo package::" (interpreted as package->foo)
2570 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2571 * Not a method if bar is a filehandle or package, but is quoted with
2576 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2579 char *s = start + (*start == '$');
2580 char tmpbuf[sizeof PL_tokenbuf];
2588 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2592 const char *proto = SvPVX_const(cv);
2603 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2604 /* start is the beginning of the possible filehandle/object,
2605 * and s is the end of it
2606 * tmpbuf is a copy of it
2609 if (*start == '$') {
2610 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2613 len = start - SvPVX(PL_linestr);
2617 start = SvPVX(PL_linestr) + len;
2621 return *s == '(' ? FUNCMETH : METHOD;
2623 if (!keyword(tmpbuf, len, 0)) {
2624 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2628 soff = s - SvPVX(PL_linestr);
2632 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2633 if (indirgv && GvCVu(indirgv))
2635 /* filehandle or package name makes it a method */
2636 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2638 soff = s - SvPVX(PL_linestr);
2641 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2642 return 0; /* no assumptions -- "=>" quotes bearword */
2644 start_force(PL_curforce);
2645 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2646 newSVpvn(tmpbuf,len));
2647 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2649 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2654 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2656 return *s == '(' ? FUNCMETH : METHOD;
2664 * Return a string of Perl code to load the debugger. If PERL5DB
2665 * is set, it will return the contents of that, otherwise a
2666 * compile-time require of perl5db.pl.
2674 const char * const pdb = PerlEnv_getenv("PERL5DB");
2678 SETERRNO(0,SS_NORMAL);
2679 return "BEGIN { require 'perl5db.pl' }";
2685 /* Encoded script support. filter_add() effectively inserts a
2686 * 'pre-processing' function into the current source input stream.
2687 * Note that the filter function only applies to the current source file
2688 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2690 * The datasv parameter (which may be NULL) can be used to pass
2691 * private data to this instance of the filter. The filter function
2692 * can recover the SV using the FILTER_DATA macro and use it to
2693 * store private buffers and state information.
2695 * The supplied datasv parameter is upgraded to a PVIO type
2696 * and the IoDIRP/IoANY field is used to store the function pointer,
2697 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2698 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2699 * private use must be set using malloc'd pointers.
2703 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2709 if (!PL_rsfp_filters)
2710 PL_rsfp_filters = newAV();
2713 SvUPGRADE(datasv, SVt_PVIO);
2714 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2715 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2716 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2717 FPTR2DPTR(void *, IoANY(datasv)),
2718 SvPV_nolen(datasv)));
2719 av_unshift(PL_rsfp_filters, 1);
2720 av_store(PL_rsfp_filters, 0, datasv) ;
2725 /* Delete most recently added instance of this filter function. */
2727 Perl_filter_del(pTHX_ filter_t funcp)
2733 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2734 FPTR2DPTR(void*, funcp)));
2736 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2738 /* if filter is on top of stack (usual case) just pop it off */
2739 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2740 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2741 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2742 IoANY(datasv) = (void *)NULL;
2743 sv_free(av_pop(PL_rsfp_filters));
2747 /* we need to search for the correct entry and clear it */
2748 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2752 /* Invoke the idxth filter function for the current rsfp. */
2753 /* maxlen 0 = read one text line */
2755 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2760 /* This API is bad. It should have been using unsigned int for maxlen.
2761 Not sure if we want to change the API, but if not we should sanity
2762 check the value here. */
2763 const unsigned int correct_length
2772 if (!PL_rsfp_filters)
2774 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2775 /* Provide a default input filter to make life easy. */
2776 /* Note that we append to the line. This is handy. */
2777 DEBUG_P(PerlIO_printf(Perl_debug_log,
2778 "filter_read %d: from rsfp\n", idx));
2779 if (correct_length) {
2782 const int old_len = SvCUR(buf_sv);
2784 /* ensure buf_sv is large enough */
2785 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2786 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2787 correct_length)) <= 0) {
2788 if (PerlIO_error(PL_rsfp))
2789 return -1; /* error */
2791 return 0 ; /* end of file */
2793 SvCUR_set(buf_sv, old_len + len) ;
2796 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2797 if (PerlIO_error(PL_rsfp))
2798 return -1; /* error */
2800 return 0 ; /* end of file */
2803 return SvCUR(buf_sv);
2805 /* Skip this filter slot if filter has been deleted */
2806 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2807 DEBUG_P(PerlIO_printf(Perl_debug_log,
2808 "filter_read %d: skipped (filter deleted)\n",
2810 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2812 /* Get function pointer hidden within datasv */
2813 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2814 DEBUG_P(PerlIO_printf(Perl_debug_log,
2815 "filter_read %d: via function %p (%s)\n",
2816 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2817 /* Call function. The function is expected to */
2818 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2819 /* Return: <0:error, =0:eof, >0:not eof */
2820 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2824 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2827 #ifdef PERL_CR_FILTER
2828 if (!PL_rsfp_filters) {
2829 filter_add(S_cr_textfilter,NULL);
2832 if (PL_rsfp_filters) {
2834 SvCUR_set(sv, 0); /* start with empty line */
2835 if (FILTER_READ(0, sv, 0) > 0)
2836 return ( SvPVX(sv) ) ;
2841 return (sv_gets(sv, fp, append));
2845 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2850 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2854 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2855 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2857 return GvHV(gv); /* Foo:: */
2860 /* use constant CLASS => 'MyClass' */
2861 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2862 if (gv && GvCV(gv)) {
2863 SV * const sv = cv_const_sv(GvCV(gv));
2865 pkgname = SvPV_nolen_const(sv);
2868 return gv_stashpv(pkgname, FALSE);
2872 * S_readpipe_override
2873 * Check whether readpipe() is overriden, and generates the appropriate
2874 * optree, provided sublex_start() is called afterwards.
2877 S_readpipe_override(pTHX)
2880 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
2881 yylval.ival = OP_BACKTICK;
2883 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
2885 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
2886 && (gv_readpipe = *gvp) != (GV*)&PL_sv_undef
2887 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
2889 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
2890 append_elem(OP_LIST,
2891 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
2892 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
2902 * The intent of this yylex wrapper is to minimize the changes to the
2903 * tokener when we aren't interested in collecting madprops. It remains
2904 * to be seen how successful this strategy will be...
2911 char *s = PL_bufptr;
2913 /* make sure PL_thiswhite is initialized */
2917 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2918 if (PL_pending_ident)
2919 return S_pending_ident(aTHX);
2921 /* previous token ate up our whitespace? */
2922 if (!PL_lasttoke && PL_nextwhite) {
2923 PL_thiswhite = PL_nextwhite;
2927 /* isolate the token, and figure out where it is without whitespace */
2928 PL_realtokenstart = -1;
2932 assert(PL_curforce < 0);
2934 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2935 if (!PL_thistoken) {
2936 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2937 PL_thistoken = newSVpvs("");
2939 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2940 PL_thistoken = newSVpvn(tstart, s - tstart);
2943 if (PL_thismad) /* install head */
2944 CURMAD('X', PL_thistoken);
2947 /* last whitespace of a sublex? */
2948 if (optype == ')' && PL_endwhite) {
2949 CURMAD('X', PL_endwhite);
2954 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
2955 if (!PL_thiswhite && !PL_endwhite && !optype) {
2956 sv_free(PL_thistoken);
2961 /* put off final whitespace till peg */
2962 if (optype == ';' && !PL_rsfp) {
2963 PL_nextwhite = PL_thiswhite;
2966 else if (PL_thisopen) {
2967 CURMAD('q', PL_thisopen);
2969 sv_free(PL_thistoken);
2973 /* Store actual token text as madprop X */
2974 CURMAD('X', PL_thistoken);
2978 /* add preceding whitespace as madprop _ */
2979 CURMAD('_', PL_thiswhite);
2983 /* add quoted material as madprop = */
2984 CURMAD('=', PL_thisstuff);
2988 /* add terminating quote as madprop Q */
2989 CURMAD('Q', PL_thisclose);
2993 /* special processing based on optype */
2997 /* opval doesn't need a TOKEN since it can already store mp */
3008 append_madprops(PL_thismad, yylval.opval, 0);
3016 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3025 /* remember any fake bracket that lexer is about to discard */
3026 if (PL_lex_brackets == 1 &&
3027 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3030 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3033 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3034 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3037 break; /* don't bother looking for trailing comment */
3046 /* attach a trailing comment to its statement instead of next token */
3050 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3052 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3054 if (*s == '\n' || *s == '#') {
3055 while (s < PL_bufend && *s != '\n')
3059 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3060 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3077 /* Create new token struct. Note: opvals return early above. */
3078 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
3085 S_tokenize_use(pTHX_ int is_use, char *s) {
3087 if (PL_expect != XSTATE)
3088 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3089 is_use ? "use" : "no"));
3091 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3092 s = force_version(s, TRUE);
3093 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3094 start_force(PL_curforce);
3095 NEXTVAL_NEXTTOKE.opval = NULL;
3098 else if (*s == 'v') {
3099 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3100 s = force_version(s, FALSE);
3104 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3105 s = force_version(s, FALSE);
3107 yylval.ival = is_use;
3111 static const char* const exp_name[] =
3112 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3113 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3120 Works out what to call the token just pulled out of the input
3121 stream. The yacc parser takes care of taking the ops we return and
3122 stitching them into a tree.
3128 if read an identifier
3129 if we're in a my declaration
3130 croak if they tried to say my($foo::bar)
3131 build the ops for a my() declaration
3132 if it's an access to a my() variable
3133 are we in a sort block?
3134 croak if my($a); $a <=> $b
3135 build ops for access to a my() variable
3136 if in a dq string, and they've said @foo and we can't find @foo
3138 build ops for a bareword
3139 if we already built the token before, use it.
3144 #pragma segment Perl_yylex
3150 register char *s = PL_bufptr;
3155 /* orig_keyword, gvp, and gv are initialized here because
3156 * jump to the label just_a_word_zero can bypass their
3157 * initialization later. */
3158 I32 orig_keyword = 0;
3163 SV* tmp = newSVpvs("");
3164 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3165 (IV)CopLINE(PL_curcop),
3166 lex_state_names[PL_lex_state],
3167 exp_name[PL_expect],
3168 pv_display(tmp, s, strlen(s), 0, 60));
3171 /* check if there's an identifier for us to look at */
3172 if (PL_pending_ident)
3173 return REPORT(S_pending_ident(aTHX));
3175 /* no identifier pending identification */
3177 switch (PL_lex_state) {
3179 case LEX_NORMAL: /* Some compilers will produce faster */
3180 case LEX_INTERPNORMAL: /* code if we comment these out. */
3184 /* when we've already built the next token, just pull it out of the queue */
3188 yylval = PL_nexttoke[PL_lasttoke].next_val;
3190 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3191 PL_nexttoke[PL_lasttoke].next_mad = 0;
3192 if (PL_thismad && PL_thismad->mad_key == '_') {
3193 PL_thiswhite = (SV*)PL_thismad->mad_val;
3194 PL_thismad->mad_val = 0;
3195 mad_free(PL_thismad);
3200 PL_lex_state = PL_lex_defer;
3201 PL_expect = PL_lex_expect;
3202 PL_lex_defer = LEX_NORMAL;
3203 if (!PL_nexttoke[PL_lasttoke].next_type)
3208 yylval = PL_nextval[PL_nexttoke];
3210 PL_lex_state = PL_lex_defer;
3211 PL_expect = PL_lex_expect;
3212 PL_lex_defer = LEX_NORMAL;
3216 /* FIXME - can these be merged? */
3217 return(PL_nexttoke[PL_lasttoke].next_type);
3219 return REPORT(PL_nexttype[PL_nexttoke]);
3222 /* interpolated case modifiers like \L \U, including \Q and \E.
3223 when we get here, PL_bufptr is at the \
3225 case LEX_INTERPCASEMOD:
3227 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3228 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3230 /* handle \E or end of string */
3231 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3233 if (PL_lex_casemods) {
3234 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3235 PL_lex_casestack[PL_lex_casemods] = '\0';
3237 if (PL_bufptr != PL_bufend
3238 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3240 PL_lex_state = LEX_INTERPCONCAT;
3243 PL_thistoken = newSVpvs("\\E");
3249 while (PL_bufptr != PL_bufend &&
3250 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3252 PL_thiswhite = newSVpvs("");
3253 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3257 if (PL_bufptr != PL_bufend)
3260 PL_lex_state = LEX_INTERPCONCAT;
3264 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3265 "### Saw case modifier\n"); });
3267 if (s[1] == '\\' && s[2] == 'E') {
3270 PL_thiswhite = newSVpvs("");
3271 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3274 PL_lex_state = LEX_INTERPCONCAT;
3279 if (!PL_madskills) /* when just compiling don't need correct */
3280 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3281 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3282 if ((*s == 'L' || *s == 'U') &&
3283 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3284 PL_lex_casestack[--PL_lex_casemods] = '\0';
3287 if (PL_lex_casemods > 10)
3288 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3289 PL_lex_casestack[PL_lex_casemods++] = *s;
3290 PL_lex_casestack[PL_lex_casemods] = '\0';
3291 PL_lex_state = LEX_INTERPCONCAT;
3292 start_force(PL_curforce);
3293 NEXTVAL_NEXTTOKE.ival = 0;
3295 start_force(PL_curforce);
3297 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3299 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3301 NEXTVAL_NEXTTOKE.ival = OP_LC;
3303 NEXTVAL_NEXTTOKE.ival = OP_UC;
3305 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3307 Perl_croak(aTHX_ "panic: yylex");
3309 SV* const tmpsv = newSVpvs("");
3310 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3316 if (PL_lex_starts) {
3322 sv_free(PL_thistoken);
3323 PL_thistoken = newSVpvs("");
3326 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3327 if (PL_lex_casemods == 1 && PL_lex_inpat)
3336 case LEX_INTERPPUSH:
3337 return REPORT(sublex_push());
3339 case LEX_INTERPSTART:
3340 if (PL_bufptr == PL_bufend)
3341 return REPORT(sublex_done());
3342 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3343 "### Interpolated variable\n"); });
3345 PL_lex_dojoin = (*PL_bufptr == '@');
3346 PL_lex_state = LEX_INTERPNORMAL;
3347 if (PL_lex_dojoin) {
3348 start_force(PL_curforce);
3349 NEXTVAL_NEXTTOKE.ival = 0;
3351 start_force(PL_curforce);
3352 force_ident("\"", '$');
3353 start_force(PL_curforce);
3354 NEXTVAL_NEXTTOKE.ival = 0;
3356 start_force(PL_curforce);
3357 NEXTVAL_NEXTTOKE.ival = 0;
3359 start_force(PL_curforce);
3360 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3363 if (PL_lex_starts++) {
3368 sv_free(PL_thistoken);
3369 PL_thistoken = newSVpvs("");
3372 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3373 if (!PL_lex_casemods && PL_lex_inpat)
3380 case LEX_INTERPENDMAYBE:
3381 if (intuit_more(PL_bufptr)) {
3382 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3388 if (PL_lex_dojoin) {
3389 PL_lex_dojoin = FALSE;
3390 PL_lex_state = LEX_INTERPCONCAT;
3394 sv_free(PL_thistoken);
3395 PL_thistoken = newSVpvs("");
3400 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3401 && SvEVALED(PL_lex_repl))
3403 if (PL_bufptr != PL_bufend)
3404 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3408 case LEX_INTERPCONCAT:
3410 if (PL_lex_brackets)
3411 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3413 if (PL_bufptr == PL_bufend)
3414 return REPORT(sublex_done());
3416 if (SvIVX(PL_linestr) == '\'') {
3417 SV *sv = newSVsv(PL_linestr);
3420 else if ( PL_hints & HINT_NEW_RE )
3421 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3422 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3426 s = scan_const(PL_bufptr);
3428 PL_lex_state = LEX_INTERPCASEMOD;
3430 PL_lex_state = LEX_INTERPSTART;
3433 if (s != PL_bufptr) {
3434 start_force(PL_curforce);
3436 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3438 NEXTVAL_NEXTTOKE = yylval;
3441 if (PL_lex_starts++) {
3445 sv_free(PL_thistoken);
3446 PL_thistoken = newSVpvs("");
3449 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3450 if (!PL_lex_casemods && PL_lex_inpat)
3463 PL_lex_state = LEX_NORMAL;
3464 s = scan_formline(PL_bufptr);
3465 if (!PL_lex_formbrack)
3471 PL_oldoldbufptr = PL_oldbufptr;
3477 sv_free(PL_thistoken);
3480 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3484 if (isIDFIRST_lazy_if(s,UTF))
3486 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3489 goto fake_eof; /* emulate EOF on ^D or ^Z */
3498 if (PL_lex_brackets) {
3499 yyerror((const char *)
3501 ? "Format not terminated"
3502 : "Missing right curly or square bracket"));
3504 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3505 "### Tokener got EOF\n");
3509 if (s++ < PL_bufend)
3510 goto retry; /* ignore stray nulls */
3513 if (!PL_in_eval && !PL_preambled) {
3514 PL_preambled = TRUE;
3519 sv_setpv(PL_linestr,incl_perldb());
3520 if (SvCUR(PL_linestr))
3521 sv_catpvs(PL_linestr,";");
3523 while(AvFILLp(PL_preambleav) >= 0) {
3524 SV *tmpsv = av_shift(PL_preambleav);
3525 sv_catsv(PL_linestr, tmpsv);
3526 sv_catpvs(PL_linestr, ";");
3529 sv_free((SV*)PL_preambleav);
3530 PL_preambleav = NULL;
3532 if (PL_minus_n || PL_minus_p) {
3533 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3535 sv_catpvs(PL_linestr,"chomp;");
3538 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3539 || *PL_splitstr == '"')
3540 && strchr(PL_splitstr + 1, *PL_splitstr))
3541 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3543 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3544 bytes can be used as quoting characters. :-) */
3545 const char *splits = PL_splitstr;
3546 sv_catpvs(PL_linestr, "our @F=split(q\0");
3549 if (*splits == '\\')
3550 sv_catpvn(PL_linestr, splits, 1);
3551 sv_catpvn(PL_linestr, splits, 1);
3552 } while (*splits++);
3553 /* This loop will embed the trailing NUL of
3554 PL_linestr as the last thing it does before
3556 sv_catpvs(PL_linestr, ");");
3560 sv_catpvs(PL_linestr,"our @F=split(' ');");
3564 sv_catpvs(PL_linestr,"use feature ':5.10';");
3565 sv_catpvs(PL_linestr, "\n");
3566 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3567 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3568 PL_last_lop = PL_last_uni = NULL;
3569 if (PERLDB_LINE && PL_curstash != PL_debstash)
3570 update_debugger_info_sv(PL_linestr);
3574 bof = PL_rsfp ? TRUE : FALSE;
3575 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3578 PL_realtokenstart = -1;
3581 if (PL_preprocess && !PL_in_eval)
3582 (void)PerlProc_pclose(PL_rsfp);
3583 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3584 PerlIO_clearerr(PL_rsfp);
3586 (void)PerlIO_close(PL_rsfp);
3588 PL_doextract = FALSE;
3590 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3595 sv_setpv(PL_linestr,
3598 ? ";}continue{print;}" : ";}"));
3599 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3600 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3601 PL_last_lop = PL_last_uni = NULL;
3602 PL_minus_n = PL_minus_p = 0;
3605 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3606 PL_last_lop = PL_last_uni = NULL;
3607 sv_setpvn(PL_linestr,"",0);
3608 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3610 /* If it looks like the start of a BOM or raw UTF-16,
3611 * check if it in fact is. */
3617 #ifdef PERLIO_IS_STDIO
3618 # ifdef __GNU_LIBRARY__
3619 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3620 # define FTELL_FOR_PIPE_IS_BROKEN
3624 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3625 # define FTELL_FOR_PIPE_IS_BROKEN
3630 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3631 /* This loses the possibility to detect the bof
3632 * situation on perl -P when the libc5 is being used.
3633 * Workaround? Maybe attach some extra state to PL_rsfp?
3636 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3638 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3641 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3642 s = swallow_bom((U8*)s);
3646 /* Incest with pod. */
3649 sv_catsv(PL_thiswhite, PL_linestr);
3651 if (*s == '=' && strnEQ(s, "=cut", 4)) {
3652 sv_setpvn(PL_linestr, "", 0);
3653 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3654 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3655 PL_last_lop = PL_last_uni = NULL;
3656 PL_doextract = FALSE;
3660 } while (PL_doextract);
3661 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3662 if (PERLDB_LINE && PL_curstash != PL_debstash)
3663 update_debugger_info_sv(PL_linestr);
3664 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3665 PL_last_lop = PL_last_uni = NULL;
3666 if (CopLINE(PL_curcop) == 1) {
3667 while (s < PL_bufend && isSPACE(*s))
3669 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3673 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3677 if (*s == '#' && *(s+1) == '!')
3679 #ifdef ALTERNATE_SHEBANG
3681 static char const as[] = ALTERNATE_SHEBANG;
3682 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3683 d = s + (sizeof(as) - 1);
3685 #endif /* ALTERNATE_SHEBANG */
3694 while (*d && !isSPACE(*d))
3698 #ifdef ARG_ZERO_IS_SCRIPT
3699 if (ipathend > ipath) {
3701 * HP-UX (at least) sets argv[0] to the script name,
3702 * which makes $^X incorrect. And Digital UNIX and Linux,
3703 * at least, set argv[0] to the basename of the Perl
3704 * interpreter. So, having found "#!", we'll set it right.
3706 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3708 assert(SvPOK(x) || SvGMAGICAL(x));
3709 if (sv_eq(x, CopFILESV(PL_curcop))) {
3710 sv_setpvn(x, ipath, ipathend - ipath);
3716 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3717 const char * const lstart = SvPV_const(x,llen);
3719 bstart += blen - llen;
3720 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3721 sv_setpvn(x, ipath, ipathend - ipath);
3726 TAINT_NOT; /* $^X is always tainted, but that's OK */
3728 #endif /* ARG_ZERO_IS_SCRIPT */
3733 d = instr(s,"perl -");
3735 d = instr(s,"perl");
3737 /* avoid getting into infinite loops when shebang
3738 * line contains "Perl" rather than "perl" */
3740 for (d = ipathend-4; d >= ipath; --d) {
3741 if ((*d == 'p' || *d == 'P')
3742 && !ibcmp(d, "perl", 4))
3752 #ifdef ALTERNATE_SHEBANG
3754 * If the ALTERNATE_SHEBANG on this system starts with a
3755 * character that can be part of a Perl expression, then if
3756 * we see it but not "perl", we're probably looking at the
3757 * start of Perl code, not a request to hand off to some
3758 * other interpreter. Similarly, if "perl" is there, but
3759 * not in the first 'word' of the line, we assume the line
3760 * contains the start of the Perl program.
3762 if (d && *s != '#') {
3763 const char *c = ipath;
3764 while (*c && !strchr("; \t\r\n\f\v#", *c))
3767 d = NULL; /* "perl" not in first word; ignore */
3769 *s = '#'; /* Don't try to parse shebang line */
3771 #endif /* ALTERNATE_SHEBANG */
3772 #ifndef MACOS_TRADITIONAL
3777 !instr(s,"indir") &&
3778 instr(PL_origargv[0],"perl"))
3785 while (s < PL_bufend && isSPACE(*s))
3787 if (s < PL_bufend) {
3788 Newxz(newargv,PL_origargc+3,char*);
3790 while (s < PL_bufend && !isSPACE(*s))
3793 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3796 newargv = PL_origargv;
3799 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3801 Perl_croak(aTHX_ "Can't exec %s", ipath);
3805 while (*d && !isSPACE(*d))
3807 while (SPACE_OR_TAB(*d))
3811 const bool switches_done = PL_doswitches;
3812 const U32 oldpdb = PL_perldb;
3813 const bool oldn = PL_minus_n;
3814 const bool oldp = PL_minus_p;
3817 if (*d == 'M' || *d == 'm' || *d == 'C') {
3818 const char * const m = d;
3819 while (*d && !isSPACE(*d))
3821 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3824 d = moreswitches(d);
3826 if (PL_doswitches && !switches_done) {
3827 int argc = PL_origargc;
3828 char **argv = PL_origargv;
3831 } while (argc && argv[0][0] == '-' && argv[0][1]);
3832 init_argv_symbols(argc,argv);
3834 if ((PERLDB_LINE && !oldpdb) ||
3835 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3836 /* if we have already added "LINE: while (<>) {",
3837 we must not do it again */
3839 sv_setpvn(PL_linestr, "", 0);
3840 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3841 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3842 PL_last_lop = PL_last_uni = NULL;
3843 PL_preambled = FALSE;
3845 (void)gv_fetchfile(PL_origfilename);
3852 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3854 PL_lex_state = LEX_FORMLINE;
3859 #ifdef PERL_STRICT_CR
3860 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3862 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3864 case ' ': case '\t': case '\f': case 013:
3865 #ifdef MACOS_TRADITIONAL
3869 PL_realtokenstart = -1;
3878 PL_realtokenstart = -1;
3882 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3883 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3884 /* handle eval qq[#line 1 "foo"\n ...] */
3885 CopLINE_dec(PL_curcop);
3888 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3890 if (!PL_in_eval || PL_rsfp)
3895 while (d < PL_bufend && *d != '\n')
3899 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3900 Perl_croak(aTHX_ "panic: input overflow");
3903 PL_thiswhite = newSVpvn(s, d - s);
3908 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3910 PL_lex_state = LEX_FORMLINE;
3916 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3917 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3920 TOKEN(PEG); /* make sure any #! line is accessible */
3925 /* if (PL_madskills && PL_lex_formbrack) { */
3927 while (d < PL_bufend && *d != '\n')
3931 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3932 Perl_croak(aTHX_ "panic: input overflow");
3933 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3935 PL_thiswhite = newSVpvs("");
3936 if (CopLINE(PL_curcop) == 1) {
3937 sv_setpvn(PL_thiswhite, "", 0);
3940 sv_catpvn(PL_thiswhite, s, d - s);
3954 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3962 while (s < PL_bufend && SPACE_OR_TAB(*s))
3965 if (strnEQ(s,"=>",2)) {
3966 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3967 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
3968 OPERATOR('-'); /* unary minus */
3970 PL_last_uni = PL_oldbufptr;
3972 case 'r': ftst = OP_FTEREAD; break;
3973 case 'w': ftst = OP_FTEWRITE; break;
3974 case 'x': ftst = OP_FTEEXEC; break;
3975 case 'o': ftst = OP_FTEOWNED; break;
3976 case 'R': ftst = OP_FTRREAD; break;
3977 case 'W': ftst = OP_FTRWRITE; break;
3978 case 'X': ftst = OP_FTREXEC; break;
3979 case 'O': ftst = OP_FTROWNED; break;
3980 case 'e': ftst = OP_FTIS; break;
3981 case 'z': ftst = OP_FTZERO; break;
3982 case 's': ftst = OP_FTSIZE; break;
3983 case 'f': ftst = OP_FTFILE; break;
3984 case 'd': ftst = OP_FTDIR; break;
3985 case 'l': ftst = OP_FTLINK; break;
3986 case 'p': ftst = OP_FTPIPE; break;
3987 case 'S': ftst = OP_FTSOCK; break;
3988 case 'u': ftst = OP_FTSUID; break;
3989 case 'g': ftst = OP_FTSGID; break;
3990 case 'k': ftst = OP_FTSVTX; break;
3991 case 'b': ftst = OP_FTBLK; break;
3992 case 'c': ftst = OP_FTCHR; break;
3993 case 't': ftst = OP_FTTTY; break;
3994 case 'T': ftst = OP_FTTEXT; break;
3995 case 'B': ftst = OP_FTBINARY; break;
3996 case 'M': case 'A': case 'C':
3997 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
3999 case 'M': ftst = OP_FTMTIME; break;
4000 case 'A': ftst = OP_FTATIME; break;
4001 case 'C': ftst = OP_FTCTIME; break;
4009 PL_last_lop_op = (OPCODE)ftst;
4010 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4011 "### Saw file test %c\n", (int)tmp);
4016 /* Assume it was a minus followed by a one-letter named
4017 * subroutine call (or a -bareword), then. */
4018 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4019 "### '-%c' looked like a file test but was not\n",
4026 const char tmp = *s++;
4029 if (PL_expect == XOPERATOR)
4034 else if (*s == '>') {
4037 if (isIDFIRST_lazy_if(s,UTF)) {
4038 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4046 if (PL_expect == XOPERATOR)
4049 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4051 OPERATOR('-'); /* unary minus */
4057 const char tmp = *s++;
4060 if (PL_expect == XOPERATOR)
4065 if (PL_expect == XOPERATOR)
4068 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4075 if (PL_expect != XOPERATOR) {
4076 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4077 PL_expect = XOPERATOR;
4078 force_ident(PL_tokenbuf, '*');
4091 if (PL_expect == XOPERATOR) {
4095 PL_tokenbuf[0] = '%';
4096 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
4097 if (!PL_tokenbuf[1]) {
4100 PL_pending_ident = '%';
4111 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
4112 && FEATURE_IS_ENABLED("~~"))
4119 const char tmp = *s++;
4125 goto just_a_word_zero_gv;
4128 switch (PL_expect) {
4134 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4136 PL_bufptr = s; /* update in case we back off */
4142 PL_expect = XTERMBLOCK;
4145 stuffstart = s - SvPVX(PL_linestr) - 1;
4149 while (isIDFIRST_lazy_if(s,UTF)) {
4152 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4153 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4154 if (tmp < 0) tmp = -tmp;
4169 sv = newSVpvn(s, len);
4171 d = scan_str(d,TRUE,TRUE);
4173 /* MUST advance bufptr here to avoid bogus
4174 "at end of line" context messages from yyerror().
4176 PL_bufptr = s + len;
4177 yyerror("Unterminated attribute parameter in attribute list");
4181 return REPORT(0); /* EOF indicator */
4185 sv_catsv(sv, PL_lex_stuff);
4186 attrs = append_elem(OP_LIST, attrs,
4187 newSVOP(OP_CONST, 0, sv));
4188 SvREFCNT_dec(PL_lex_stuff);
4189 PL_lex_stuff = NULL;
4192 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4194 if (PL_in_my == KEY_our) {
4196 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4198 /* skip to avoid loading attributes.pm */
4200 deprecate(":unique");
4203 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4206 /* NOTE: any CV attrs applied here need to be part of
4207 the CVf_BUILTIN_ATTRS define in cv.h! */
4208 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4210 CvLVALUE_on(PL_compcv);
4212 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4214 CvLOCKED_on(PL_compcv);
4216 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4218 CvMETHOD_on(PL_compcv);
4220 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4222 CvASSERTION_on(PL_compcv);
4224 /* After we've set the flags, it could be argued that
4225 we don't need to do the attributes.pm-based setting
4226 process, and shouldn't bother appending recognized
4227 flags. To experiment with that, uncomment the
4228 following "else". (Note that's already been
4229 uncommented. That keeps the above-applied built-in
4230 attributes from being intercepted (and possibly
4231 rejected) by a package's attribute routines, but is
4232 justified by the performance win for the common case
4233 of applying only built-in attributes.) */
4235 attrs = append_elem(OP_LIST, attrs,
4236 newSVOP(OP_CONST, 0,
4240 if (*s == ':' && s[1] != ':')
4243 break; /* require real whitespace or :'s */
4244 /* XXX losing whitespace on sequential attributes here */
4248 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4249 if (*s != ';' && *s != '}' && *s != tmp
4250 && (tmp != '=' || *s != ')')) {
4251 const char q = ((*s == '\'') ? '"' : '\'');
4252 /* If here for an expression, and parsed no attrs, back
4254 if (tmp == '=' && !attrs) {
4258 /* MUST advance bufptr here to avoid bogus "at end of line"
4259 context messages from yyerror().
4262 yyerror( (const char *)
4264 ? Perl_form(aTHX_ "Invalid separator character "
4265 "%c%c%c in attribute list", q, *s, q)
4266 : "Unterminated attribute list" ) );
4274 start_force(PL_curforce);
4275 NEXTVAL_NEXTTOKE.opval = attrs;
4276 CURMAD('_', PL_nextwhite);
4281 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4282 (s - SvPVX(PL_linestr)) - stuffstart);
4290 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4291 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4299 const char tmp = *s++;
4304 const char tmp = *s++;
4312 if (PL_lex_brackets <= 0)
4313 yyerror("Unmatched right square bracket");
4316 if (PL_lex_state == LEX_INTERPNORMAL) {
4317 if (PL_lex_brackets == 0) {
4318 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4319 PL_lex_state = LEX_INTERPEND;
4326 if (PL_lex_brackets > 100) {
4327 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4329 switch (PL_expect) {
4331 if (PL_lex_formbrack) {
4335 if (PL_oldoldbufptr == PL_last_lop)
4336 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4338 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4339 OPERATOR(HASHBRACK);
4341 while (s < PL_bufend && SPACE_OR_TAB(*s))
4344 PL_tokenbuf[0] = '\0';
4345 if (d < PL_bufend && *d == '-') {
4346 PL_tokenbuf[0] = '-';
4348 while (d < PL_bufend && SPACE_OR_TAB(*d))
4351 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4352 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4354 while (d < PL_bufend && SPACE_OR_TAB(*d))
4357 const char minus = (PL_tokenbuf[0] == '-');
4358 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4366 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4371 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4376 if (PL_oldoldbufptr == PL_last_lop)
4377 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4379 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4382 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4384 /* This hack is to get the ${} in the message. */
4386 yyerror("syntax error");
4389 OPERATOR(HASHBRACK);
4391 /* This hack serves to disambiguate a pair of curlies
4392 * as being a block or an anon hash. Normally, expectation
4393 * determines that, but in cases where we're not in a
4394 * position to expect anything in particular (like inside
4395 * eval"") we have to resolve the ambiguity. This code
4396 * covers the case where the first term in the curlies is a
4397 * quoted string. Most other cases need to be explicitly
4398 * disambiguated by prepending a "+" before the opening
4399 * curly in order to force resolution as an anon hash.
4401 * XXX should probably propagate the outer expectation
4402 * into eval"" to rely less on this hack, but that could
4403 * potentially break current behavior of eval"".
4407 if (*s == '\'' || *s == '"' || *s == '`') {
4408 /* common case: get past first string, handling escapes */
4409 for (t++; t < PL_bufend && *t != *s;)
4410 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4414 else if (*s == 'q') {
4417 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4420 /* skip q//-like construct */
4422 char open, close, term;
4425 while (t < PL_bufend && isSPACE(*t))
4427 /* check for q => */
4428 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4429 OPERATOR(HASHBRACK);
4433 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4437 for (t++; t < PL_bufend; t++) {
4438 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4440 else if (*t == open)
4444 for (t++; t < PL_bufend; t++) {
4445 if (*t == '\\' && t+1 < PL_bufend)
4447 else if (*t == close && --brackets <= 0)
4449 else if (*t == open)
4456 /* skip plain q word */
4457 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4460 else if (isALNUM_lazy_if(t,UTF)) {
4462 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4465 while (t < PL_bufend && isSPACE(*t))
4467 /* if comma follows first term, call it an anon hash */
4468 /* XXX it could be a comma expression with loop modifiers */
4469 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4470 || (*t == '=' && t[1] == '>')))
4471 OPERATOR(HASHBRACK);
4472 if (PL_expect == XREF)
4475 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4481 yylval.ival = CopLINE(PL_curcop);
4482 if (isSPACE(*s) || *s == '#')
4483 PL_copline = NOLINE; /* invalidate current command line number */
4488 if (PL_lex_brackets <= 0)
4489 yyerror("Unmatched right curly bracket");
4491 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4492 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4493 PL_lex_formbrack = 0;
4494 if (PL_lex_state == LEX_INTERPNORMAL) {
4495 if (PL_lex_brackets == 0) {
4496 if (PL_expect & XFAKEBRACK) {
4497 PL_expect &= XENUMMASK;
4498 PL_lex_state = LEX_INTERPEND;
4503 PL_thiswhite = newSVpvs("");
4504 sv_catpvn(PL_thiswhite,"}",1);
4507 return yylex(); /* ignore fake brackets */
4509 if (*s == '-' && s[1] == '>')
4510 PL_lex_state = LEX_INTERPENDMAYBE;
4511 else if (*s != '[' && *s != '{')
4512 PL_lex_state = LEX_INTERPEND;
4515 if (PL_expect & XFAKEBRACK) {
4516 PL_expect &= XENUMMASK;
4518 return yylex(); /* ignore fake brackets */
4520 start_force(PL_curforce);
4522 curmad('X', newSVpvn(s-1,1));
4523 CURMAD('_', PL_thiswhite);
4528 PL_thistoken = newSVpvs("");
4536 if (PL_expect == XOPERATOR) {
4537 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4538 && isIDFIRST_lazy_if(s,UTF))
4540 CopLINE_dec(PL_curcop);
4541 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4542 CopLINE_inc(PL_curcop);
4547 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4549 PL_expect = XOPERATOR;
4550 force_ident(PL_tokenbuf, '&');
4554 yylval.ival = (OPpENTERSUB_AMPER<<8);
4566 const char tmp = *s++;
4573 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4574 && strchr("+-*/%.^&|<",tmp))
4575 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4576 "Reversed %c= operator",(int)tmp);
4578 if (PL_expect == XSTATE && isALPHA(tmp) &&
4579 (s == PL_linestart+1 || s[-2] == '\n') )
4581 if (PL_in_eval && !PL_rsfp) {
4586 if (strnEQ(s,"=cut",4)) {
4602 PL_thiswhite = newSVpvs("");
4603 sv_catpvn(PL_thiswhite, PL_linestart,
4604 PL_bufend - PL_linestart);
4608 PL_doextract = TRUE;
4612 if (PL_lex_brackets < PL_lex_formbrack) {
4614 #ifdef PERL_STRICT_CR
4615 while (SPACE_OR_TAB(*t))
4617 while (SPACE_OR_TAB(*t) || *t == '\r')
4620 if (*t == '\n' || *t == '#') {
4631 const char tmp = *s++;
4633 /* was this !=~ where !~ was meant?
4634 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4636 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4637 const char *t = s+1;
4639 while (t < PL_bufend && isSPACE(*t))
4642 if (*t == '/' || *t == '?' ||
4643 ((*t == 'm' || *t == 's' || *t == 'y')
4644 && !isALNUM(t[1])) ||
4645 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4646 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4647 "!=~ should be !~");
4657 if (PL_expect != XOPERATOR) {
4658 if (s[1] != '<' && !strchr(s,'>'))
4661 s = scan_heredoc(s);
4663 s = scan_inputsymbol(s);
4664 TERM(sublex_start());
4670 SHop(OP_LEFT_SHIFT);
4684 const char tmp = *s++;
4686 SHop(OP_RIGHT_SHIFT);
4687 else if (tmp == '=')
4696 if (PL_expect == XOPERATOR) {
4697 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4699 deprecate_old(commaless_variable_list);
4700 return REPORT(','); /* grandfather non-comma-format format */
4704 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4705 PL_tokenbuf[0] = '@';
4706 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4707 sizeof PL_tokenbuf - 1, FALSE);
4708 if (PL_expect == XOPERATOR)
4709 no_op("Array length", s);
4710 if (!PL_tokenbuf[1])
4712 PL_expect = XOPERATOR;
4713 PL_pending_ident = '#';
4717 PL_tokenbuf[0] = '$';
4718 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4719 sizeof PL_tokenbuf - 1, FALSE);
4720 if (PL_expect == XOPERATOR)
4722 if (!PL_tokenbuf[1]) {
4724 yyerror("Final $ should be \\$ or $name");
4728 /* This kludge not intended to be bulletproof. */
4729 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4730 yylval.opval = newSVOP(OP_CONST, 0,
4731 newSViv(CopARYBASE_get(&PL_compiling)));
4732 yylval.opval->op_private = OPpCONST_ARYBASE;
4738 const char tmp = *s;
4739 if (PL_lex_state == LEX_NORMAL)
4742 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4743 && intuit_more(s)) {
4745 PL_tokenbuf[0] = '@';
4746 if (ckWARN(WARN_SYNTAX)) {
4749 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4752 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4753 while (t < PL_bufend && *t != ']')
4755 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4756 "Multidimensional syntax %.*s not supported",
4757 (int)((t - PL_bufptr) + 1), PL_bufptr);
4761 else if (*s == '{') {
4763 PL_tokenbuf[0] = '%';
4764 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4765 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4767 char tmpbuf[sizeof PL_tokenbuf];
4770 } while (isSPACE(*t));
4771 if (isIDFIRST_lazy_if(t,UTF)) {
4773 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4777 if (*t == ';' && get_cv(tmpbuf, FALSE))
4778 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4779 "You need to quote \"%s\"",
4786 PL_expect = XOPERATOR;
4787 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4788 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4789 if (!islop || PL_last_lop_op == OP_GREPSTART)
4790 PL_expect = XOPERATOR;
4791 else if (strchr("$@\"'`q", *s))
4792 PL_expect = XTERM; /* e.g. print $fh "foo" */
4793 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4794 PL_expect = XTERM; /* e.g. print $fh &sub */
4795 else if (isIDFIRST_lazy_if(s,UTF)) {
4796 char tmpbuf[sizeof PL_tokenbuf];
4798 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4799 if ((t2 = keyword(tmpbuf, len, 0))) {
4800 /* binary operators exclude handle interpretations */
4812 PL_expect = XTERM; /* e.g. print $fh length() */
4817 PL_expect = XTERM; /* e.g. print $fh subr() */
4820 else if (isDIGIT(*s))
4821 PL_expect = XTERM; /* e.g. print $fh 3 */
4822 else if (*s == '.' && isDIGIT(s[1]))
4823 PL_expect = XTERM; /* e.g. print $fh .3 */
4824 else if ((*s == '?' || *s == '-' || *s == '+')
4825 && !isSPACE(s[1]) && s[1] != '=')
4826 PL_expect = XTERM; /* e.g. print $fh -1 */
4827 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4829 PL_expect = XTERM; /* e.g. print $fh /.../
4830 XXX except DORDOR operator
4832 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4834 PL_expect = XTERM; /* print $fh <<"EOF" */
4837 PL_pending_ident = '$';
4841 if (PL_expect == XOPERATOR)
4843 PL_tokenbuf[0] = '@';
4844 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4845 if (!PL_tokenbuf[1]) {
4848 if (PL_lex_state == LEX_NORMAL)
4850 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4852 PL_tokenbuf[0] = '%';
4854 /* Warn about @ where they meant $. */
4855 if (*s == '[' || *s == '{') {
4856 if (ckWARN(WARN_SYNTAX)) {
4857 const char *t = s + 1;
4858 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4860 if (*t == '}' || *t == ']') {
4862 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4863 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4864 "Scalar value %.*s better written as $%.*s",
4865 (int)(t-PL_bufptr), PL_bufptr,
4866 (int)(t-PL_bufptr-1), PL_bufptr+1);
4871 PL_pending_ident = '@';
4874 case '/': /* may be division, defined-or, or pattern */
4875 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4879 case '?': /* may either be conditional or pattern */
4880 if(PL_expect == XOPERATOR) {
4888 /* A // operator. */
4898 /* Disable warning on "study /blah/" */
4899 if (PL_oldoldbufptr == PL_last_uni
4900 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4901 || memNE(PL_last_uni, "study", 5)
4902 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4905 s = scan_pat(s,OP_MATCH);
4906 TERM(sublex_start());
4910 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4911 #ifdef PERL_STRICT_CR
4914 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4916 && (s == PL_linestart || s[-1] == '\n') )
4918 PL_lex_formbrack = 0;
4922 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4928 yylval.ival = OPf_SPECIAL;
4934 if (PL_expect != XOPERATOR)
4939 case '0': case '1': case '2': case '3': case '4':
4940 case '5': case '6': case '7': case '8': case '9':
4941 s = scan_num(s, &yylval);
4942 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
4943 if (PL_expect == XOPERATOR)
4948 s = scan_str(s,!!PL_madskills,FALSE);
4949 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4950 if (PL_expect == XOPERATOR) {
4951 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4953 deprecate_old(commaless_variable_list);
4954 return REPORT(','); /* grandfather non-comma-format format */
4961 yylval.ival = OP_CONST;
4962 TERM(sublex_start());
4965 s = scan_str(s,!!PL_madskills,FALSE);
4966 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4967 if (PL_expect == XOPERATOR) {
4968 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4970 deprecate_old(commaless_variable_list);
4971 return REPORT(','); /* grandfather non-comma-format format */
4978 yylval.ival = OP_CONST;
4979 /* FIXME. I think that this can be const if char *d is replaced by
4980 more localised variables. */
4981 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4982 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4983 yylval.ival = OP_STRINGIFY;
4987 TERM(sublex_start());
4990 s = scan_str(s,!!PL_madskills,FALSE);
4991 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
4992 if (PL_expect == XOPERATOR)
4993 no_op("Backticks",s);
4996 readpipe_override();
4997 TERM(sublex_start());
5001 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
5002 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5004 if (PL_expect == XOPERATOR)
5005 no_op("Backslash",s);
5009 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
5010 char *start = s + 2;
5011 while (isDIGIT(*start) || *start == '_')
5013 if (*start == '.' && isDIGIT(start[1])) {
5014 s = scan_num(s, &yylval);
5017 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
5018 else if (!isALPHA(*start) && (PL_expect == XTERM
5019 || PL_expect == XREF || PL_expect == XSTATE
5020 || PL_expect == XTERMORDORDOR)) {
5021 /* XXX Use gv_fetchpvn rather than stomping on a const string */
5022 const char c = *start;
5025 gv = gv_fetchpv(s, 0, SVt_PVCV);
5028 s = scan_num(s, &yylval);
5035 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5077 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5079 /* Some keywords can be followed by any delimiter, including ':' */
5080 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5081 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5082 (PL_tokenbuf[0] == 'q' &&
5083 strchr("qwxr", PL_tokenbuf[1])))));
5085 /* x::* is just a word, unless x is "CORE" */
5086 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5090 while (d < PL_bufend && isSPACE(*d))
5091 d++; /* no comments skipped here, or s### is misparsed */
5093 /* Is this a label? */
5094 if (!tmp && PL_expect == XSTATE
5095 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5097 yylval.pval = savepv(PL_tokenbuf);
5102 /* Check for keywords */
5103 tmp = keyword(PL_tokenbuf, len, 0);
5105 /* Is this a word before a => operator? */
5106 if (*d == '=' && d[1] == '>') {
5109 = (OP*)newSVOP(OP_CONST, 0,
5110 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5111 yylval.opval->op_private = OPpCONST_BARE;
5115 if (tmp < 0) { /* second-class keyword? */
5116 GV *ogv = NULL; /* override (winner) */
5117 GV *hgv = NULL; /* hidden (loser) */
5118 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5120 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5123 if (GvIMPORTED_CV(gv))
5125 else if (! CvMETHOD(cv))
5129 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5130 (gv = *gvp) != (GV*)&PL_sv_undef &&
5131 GvCVu(gv) && GvIMPORTED_CV(gv))
5138 tmp = 0; /* overridden by import or by GLOBAL */
5141 && -tmp==KEY_lock /* XXX generalizable kludge */
5143 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
5145 tmp = 0; /* any sub overrides "weak" keyword */
5147 else { /* no override */
5149 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5150 Perl_warner(aTHX_ packWARN(WARN_MISC),
5151 "dump() better written as CORE::dump()");
5155 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5156 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5157 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5158 "Ambiguous call resolved as CORE::%s(), %s",
5159 GvENAME(hgv), "qualify as such or use &");
5166 default: /* not a keyword */
5167 /* Trade off - by using this evil construction we can pull the
5168 variable gv into the block labelled keylookup. If not, then
5169 we have to give it function scope so that the goto from the
5170 earlier ':' case doesn't bypass the initialisation. */
5172 just_a_word_zero_gv:
5180 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5183 SV *nextPL_nextwhite = 0;
5187 /* Get the rest if it looks like a package qualifier */
5189 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5191 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5194 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5195 *s == '\'' ? "'" : "::");
5200 if (PL_expect == XOPERATOR) {
5201 if (PL_bufptr == PL_linestart) {
5202 CopLINE_dec(PL_curcop);
5203 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5204 CopLINE_inc(PL_curcop);
5207 no_op("Bareword",s);
5210 /* Look for a subroutine with this name in current package,
5211 unless name is "Foo::", in which case Foo is a bearword
5212 (and a package name). */
5214 if (len > 2 && !PL_madskills &&
5215 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5217 if (ckWARN(WARN_BAREWORD)
5218 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5219 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5220 "Bareword \"%s\" refers to nonexistent package",
5223 PL_tokenbuf[len] = '\0';
5229 /* Mustn't actually add anything to a symbol table.
5230 But also don't want to "initialise" any placeholder
5231 constants that might already be there into full
5232 blown PVGVs with attached PVCV. */
5233 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5234 GV_NOADD_NOINIT, SVt_PVCV);
5239 /* if we saw a global override before, get the right name */
5242 sv = newSVpvs("CORE::GLOBAL::");
5243 sv_catpv(sv,PL_tokenbuf);
5246 /* If len is 0, newSVpv does strlen(), which is correct.
5247 If len is non-zero, then it will be the true length,
5248 and so the scalar will be created correctly. */
5249 sv = newSVpv(PL_tokenbuf,len);
5252 if (PL_madskills && !PL_thistoken) {
5253 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5254 PL_thistoken = newSVpv(start,s - start);
5255 PL_realtokenstart = s - SvPVX(PL_linestr);
5259 /* Presume this is going to be a bareword of some sort. */
5262 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5263 yylval.opval->op_private = OPpCONST_BARE;
5264 /* UTF-8 package name? */
5265 if (UTF && !IN_BYTES &&
5266 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5269 /* And if "Foo::", then that's what it certainly is. */
5274 /* Do the explicit type check so that we don't need to force
5275 the initialisation of the symbol table to have a real GV.
5276 Beware - gv may not really be a PVGV, cv may not really be
5277 a PVCV, (because of the space optimisations that gv_init
5278 understands) But they're true if for this symbol there is
5279 respectively a typeglob and a subroutine.
5281 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5282 /* Real typeglob, so get the real subroutine: */
5284 /* A proxy for a subroutine in this package? */
5285 : SvOK(gv) ? (CV *) gv : NULL)
5288 /* See if it's the indirect object for a list operator. */
5290 if (PL_oldoldbufptr &&
5291 PL_oldoldbufptr < PL_bufptr &&
5292 (PL_oldoldbufptr == PL_last_lop
5293 || PL_oldoldbufptr == PL_last_uni) &&
5294 /* NO SKIPSPACE BEFORE HERE! */
5295 (PL_expect == XREF ||
5296 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5298 bool immediate_paren = *s == '(';
5300 /* (Now we can afford to cross potential line boundary.) */
5301 s = SKIPSPACE2(s,nextPL_nextwhite);
5303 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5306 /* Two barewords in a row may indicate method call. */
5308 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5309 (tmp = intuit_method(s, gv, cv)))
5312 /* If not a declared subroutine, it's an indirect object. */
5313 /* (But it's an indir obj regardless for sort.) */
5314 /* Also, if "_" follows a filetest operator, it's a bareword */
5317 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5319 (PL_last_lop_op != OP_MAPSTART &&
5320 PL_last_lop_op != OP_GREPSTART))))
5321 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5322 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5325 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5330 PL_expect = XOPERATOR;
5333 s = SKIPSPACE2(s,nextPL_nextwhite);
5334 PL_nextwhite = nextPL_nextwhite;
5339 /* Is this a word before a => operator? */
5340 if (*s == '=' && s[1] == '>' && !pkgname) {
5342 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5343 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5344 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5348 /* If followed by a paren, it's certainly a subroutine. */
5353 while (SPACE_OR_TAB(*d))
5355 if (*d == ')' && (sv = gv_const_sv(gv))) {
5359 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5360 sv_catpvn(PL_thistoken, par, s - par);
5362 sv_free(PL_nextwhite);
5372 PL_nextwhite = PL_thiswhite;
5375 start_force(PL_curforce);
5377 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5378 PL_expect = XOPERATOR;
5381 PL_nextwhite = nextPL_nextwhite;
5382 curmad('X', PL_thistoken);
5383 PL_thistoken = newSVpvs("");
5391 /* If followed by var or block, call it a method (unless sub) */
5393 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5394 PL_last_lop = PL_oldbufptr;
5395 PL_last_lop_op = OP_METHOD;
5399 /* If followed by a bareword, see if it looks like indir obj. */
5402 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5403 && (tmp = intuit_method(s, gv, cv)))
5406 /* Not a method, so call it a subroutine (if defined) */
5409 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5410 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5411 "Ambiguous use of -%s resolved as -&%s()",
5412 PL_tokenbuf, PL_tokenbuf);
5413 /* Check for a constant sub */
5414 if ((sv = gv_const_sv(gv))) {
5416 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5417 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5418 yylval.opval->op_private = 0;
5422 /* Resolve to GV now. */
5423 if (SvTYPE(gv) != SVt_PVGV) {
5424 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5425 assert (SvTYPE(gv) == SVt_PVGV);
5426 /* cv must have been some sort of placeholder, so
5427 now needs replacing with a real code reference. */
5431 op_free(yylval.opval);
5432 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5433 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5434 PL_last_lop = PL_oldbufptr;
5435 PL_last_lop_op = OP_ENTERSUB;
5436 /* Is there a prototype? */
5444 const char *proto = SvPV_const((SV*)cv, protolen);
5447 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
5449 while (*proto == ';')
5451 if (*proto == '&' && *s == '{') {
5452 sv_setpv(PL_subname,
5455 "__ANON__" : "__ANON__::__ANON__"));
5462 PL_nextwhite = PL_thiswhite;
5465 start_force(PL_curforce);
5466 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5469 PL_nextwhite = nextPL_nextwhite;
5470 curmad('X', PL_thistoken);
5471 PL_thistoken = newSVpvs("");
5478 /* Guess harder when madskills require "best effort". */
5479 if (PL_madskills && (!gv || !GvCVu(gv))) {
5480 int probable_sub = 0;
5481 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5483 else if (isALPHA(*s)) {
5487 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5488 if (!keyword(tmpbuf, tmplen, 0))
5491 while (d < PL_bufend && isSPACE(*d))
5493 if (*d == '=' && d[1] == '>')
5498 gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5499 op_free(yylval.opval);
5500 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5501 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5502 PL_last_lop = PL_oldbufptr;
5503 PL_last_lop_op = OP_ENTERSUB;
5504 PL_nextwhite = PL_thiswhite;
5506 start_force(PL_curforce);
5507 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5509 PL_nextwhite = nextPL_nextwhite;
5510 curmad('X', PL_thistoken);
5511 PL_thistoken = newSVpvs("");
5516 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5523 /* Call it a bare word */
5525 if (PL_hints & HINT_STRICT_SUBS)
5526 yylval.opval->op_private |= OPpCONST_STRICT;
5529 if (lastchar != '-') {
5530 if (ckWARN(WARN_RESERVED)) {
5534 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
5535 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5542 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5543 && ckWARN_d(WARN_AMBIGUOUS)) {
5544 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5545 "Operator or semicolon missing before %c%s",
5546 lastchar, PL_tokenbuf);
5547 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5548 "Ambiguous use of %c resolved as operator %c",
5549 lastchar, lastchar);
5555 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5556 newSVpv(CopFILE(PL_curcop),0));
5560 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5561 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5564 case KEY___PACKAGE__:
5565 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5567 ? newSVhek(HvNAME_HEK(PL_curstash))
5574 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5575 const char *pname = "main";
5576 if (PL_tokenbuf[2] == 'D')
5577 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5578 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5582 GvIOp(gv) = newIO();
5583 IoIFP(GvIOp(gv)) = PL_rsfp;
5584 #if defined(HAS_FCNTL) && defined(F_SETFD)
5586 const int fd = PerlIO_fileno(PL_rsfp);
5587 fcntl(fd,F_SETFD,fd >= 3);
5590 /* Mark this internal pseudo-handle as clean */
5591 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5593 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5594 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5595 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5597 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5598 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5599 /* if the script was opened in binmode, we need to revert
5600 * it to text mode for compatibility; but only iff it has CRs
5601 * XXX this is a questionable hack at best. */
5602 if (PL_bufend-PL_bufptr > 2
5603 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5606 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5607 loc = PerlIO_tell(PL_rsfp);
5608 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5611 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5613 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5614 #endif /* NETWARE */
5615 #ifdef PERLIO_IS_STDIO /* really? */
5616 # if defined(__BORLANDC__)
5617 /* XXX see note in do_binmode() */
5618 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5622 PerlIO_seek(PL_rsfp, loc, 0);
5626 #ifdef PERLIO_LAYERS
5629 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5630 else if (PL_encoding) {
5637 XPUSHs(PL_encoding);
5639 call_method("name", G_SCALAR);
5643 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5644 Perl_form(aTHX_ ":encoding(%"SVf")",
5653 if (PL_realtokenstart >= 0) {
5654 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5656 PL_endwhite = newSVpvs("");
5657 sv_catsv(PL_endwhite, PL_thiswhite);
5659 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5660 PL_realtokenstart = -1;
5662 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5663 SvCUR(PL_endwhite))) != Nullch) ;
5678 if (PL_expect == XSTATE) {
5685 if (*s == ':' && s[1] == ':') {
5688 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5689 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5690 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5693 else if (tmp == KEY_require || tmp == KEY_do)
5694 /* that's a way to remember we saw "CORE::" */
5707 LOP(OP_ACCEPT,XTERM);
5713 LOP(OP_ATAN2,XTERM);
5719 LOP(OP_BINMODE,XTERM);
5722 LOP(OP_BLESS,XTERM);
5731 /* When 'use switch' is in effect, continue has a dual
5732 life as a control operator. */
5734 if (!FEATURE_IS_ENABLED("switch"))
5737 /* We have to disambiguate the two senses of
5738 "continue". If the next token is a '{' then
5739 treat it as the start of a continue block;
5740 otherwise treat it as a control operator.
5752 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5769 if (!PL_cryptseen) {
5770 PL_cryptseen = TRUE;
5774 LOP(OP_CRYPT,XTERM);
5777 LOP(OP_CHMOD,XTERM);
5780 LOP(OP_CHOWN,XTERM);
5783 LOP(OP_CONNECT,XTERM);
5802 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5803 if (orig_keyword == KEY_do) {
5812 PL_hints |= HINT_BLOCK_SCOPE;
5822 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5823 LOP(OP_DBMOPEN,XTERM);
5829 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5836 yylval.ival = CopLINE(PL_curcop);
5852 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5853 UNIBRACK(OP_ENTEREVAL);
5871 case KEY_endhostent:
5877 case KEY_endservent:
5880 case KEY_endprotoent:
5891 yylval.ival = CopLINE(PL_curcop);
5893 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5896 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5899 if ((PL_bufend - p) >= 3 &&
5900 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5902 else if ((PL_bufend - p) >= 4 &&
5903 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5906 if (isIDFIRST_lazy_if(p,UTF)) {
5907 p = scan_ident(p, PL_bufend,
5908 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5912 Perl_croak(aTHX_ "Missing $ on loop variable");
5914 s = SvPVX(PL_linestr) + soff;
5920 LOP(OP_FORMLINE,XTERM);
5926 LOP(OP_FCNTL,XTERM);
5932 LOP(OP_FLOCK,XTERM);
5941 LOP(OP_GREPSTART, XREF);
5944 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5959 case KEY_getpriority:
5960 LOP(OP_GETPRIORITY,XTERM);
5962 case KEY_getprotobyname:
5965 case KEY_getprotobynumber:
5966 LOP(OP_GPBYNUMBER,XTERM);
5968 case KEY_getprotoent:
5980 case KEY_getpeername:
5981 UNI(OP_GETPEERNAME);
5983 case KEY_gethostbyname:
5986 case KEY_gethostbyaddr:
5987 LOP(OP_GHBYADDR,XTERM);
5989 case KEY_gethostent:
5992 case KEY_getnetbyname:
5995 case KEY_getnetbyaddr:
5996 LOP(OP_GNBYADDR,XTERM);
6001 case KEY_getservbyname:
6002 LOP(OP_GSBYNAME,XTERM);
6004 case KEY_getservbyport:
6005 LOP(OP_GSBYPORT,XTERM);
6007 case KEY_getservent:
6010 case KEY_getsockname:
6011 UNI(OP_GETSOCKNAME);
6013 case KEY_getsockopt:
6014 LOP(OP_GSOCKOPT,XTERM);
6029 yylval.ival = CopLINE(PL_curcop);
6040 yylval.ival = CopLINE(PL_curcop);
6044 LOP(OP_INDEX,XTERM);
6050 LOP(OP_IOCTL,XTERM);
6062 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6094 LOP(OP_LISTEN,XTERM);
6103 s = scan_pat(s,OP_MATCH);
6104 TERM(sublex_start());
6107 LOP(OP_MAPSTART, XREF);
6110 LOP(OP_MKDIR,XTERM);
6113 LOP(OP_MSGCTL,XTERM);
6116 LOP(OP_MSGGET,XTERM);
6119 LOP(OP_MSGRCV,XTERM);
6122 LOP(OP_MSGSND,XTERM);
6129 if (isIDFIRST_lazy_if(s,UTF)) {
6133 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6134 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6136 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6137 if (!PL_in_my_stash) {
6140 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6144 if (PL_madskills) { /* just add type to declarator token */
6145 sv_catsv(PL_thistoken, PL_nextwhite);
6147 sv_catpvn(PL_thistoken, start, s - start);
6155 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6162 s = tokenize_use(0, s);
6166 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6173 if (isIDFIRST_lazy_if(s,UTF)) {
6175 for (d = s; isALNUM_lazy_if(d,UTF);)
6177 for (t=d; isSPACE(*t);)
6179 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6181 && !(t[0] == '=' && t[1] == '>')
6183 int parms_len = (int)(d-s);
6184 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6185 "Precedence problem: open %.*s should be open(%.*s)",
6186 parms_len, s, parms_len, s);
6192 yylval.ival = OP_OR;
6202 LOP(OP_OPEN_DIR,XTERM);
6205 checkcomma(s,PL_tokenbuf,"filehandle");
6209 checkcomma(s,PL_tokenbuf,"filehandle");
6228 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6232 LOP(OP_PIPE_OP,XTERM);
6235 s = scan_str(s,!!PL_madskills,FALSE);
6238 yylval.ival = OP_CONST;
6239 TERM(sublex_start());
6245 s = scan_str(s,!!PL_madskills,FALSE);
6248 PL_expect = XOPERATOR;
6250 if (SvCUR(PL_lex_stuff)) {
6253 d = SvPV_force(PL_lex_stuff, len);
6255 for (; isSPACE(*d) && len; --len, ++d)
6260 if (!warned && ckWARN(WARN_QW)) {
6261 for (; !isSPACE(*d) && len; --len, ++d) {
6263 Perl_warner(aTHX_ packWARN(WARN_QW),
6264 "Possible attempt to separate words with commas");
6267 else if (*d == '#') {
6268 Perl_warner(aTHX_ packWARN(WARN_QW),
6269 "Possible attempt to put comments in qw() list");
6275 for (; !isSPACE(*d) && len; --len, ++d)
6278 sv = newSVpvn(b, d-b);
6279 if (DO_UTF8(PL_lex_stuff))
6281 words = append_elem(OP_LIST, words,
6282 newSVOP(OP_CONST, 0, tokeq(sv)));
6286 start_force(PL_curforce);
6287 NEXTVAL_NEXTTOKE.opval = words;
6292 SvREFCNT_dec(PL_lex_stuff);
6293 PL_lex_stuff = NULL;
6299 s = scan_str(s,!!PL_madskills,FALSE);
6302 yylval.ival = OP_STRINGIFY;
6303 if (SvIVX(PL_lex_stuff) == '\'')
6304 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6305 TERM(sublex_start());
6308 s = scan_pat(s,OP_QR);
6309 TERM(sublex_start());
6312 s = scan_str(s,!!PL_madskills,FALSE);
6315 readpipe_override();
6316 TERM(sublex_start());
6324 s = force_version(s, FALSE);
6326 else if (*s != 'v' || !isDIGIT(s[1])
6327 || (s = force_version(s, TRUE), *s == 'v'))
6329 *PL_tokenbuf = '\0';
6330 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6331 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6332 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6334 yyerror("<> should be quotes");
6336 if (orig_keyword == KEY_require) {
6344 PL_last_uni = PL_oldbufptr;
6345 PL_last_lop_op = OP_REQUIRE;
6347 return REPORT( (int)REQUIRE );
6353 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6357 LOP(OP_RENAME,XTERM);
6366 LOP(OP_RINDEX,XTERM);
6376 UNIDOR(OP_READLINE);
6389 LOP(OP_REVERSE,XTERM);
6392 UNIDOR(OP_READLINK);
6400 TERM(sublex_start());
6402 TOKEN(1); /* force error */
6405 checkcomma(s,PL_tokenbuf,"filehandle");
6415 LOP(OP_SELECT,XTERM);
6421 LOP(OP_SEMCTL,XTERM);
6424 LOP(OP_SEMGET,XTERM);
6427 LOP(OP_SEMOP,XTERM);
6433 LOP(OP_SETPGRP,XTERM);
6435 case KEY_setpriority:
6436 LOP(OP_SETPRIORITY,XTERM);
6438 case KEY_sethostent:
6444 case KEY_setservent:
6447 case KEY_setprotoent:
6457 LOP(OP_SEEKDIR,XTERM);
6459 case KEY_setsockopt:
6460 LOP(OP_SSOCKOPT,XTERM);
6466 LOP(OP_SHMCTL,XTERM);
6469 LOP(OP_SHMGET,XTERM);
6472 LOP(OP_SHMREAD,XTERM);
6475 LOP(OP_SHMWRITE,XTERM);
6478 LOP(OP_SHUTDOWN,XTERM);
6487 LOP(OP_SOCKET,XTERM);
6489 case KEY_socketpair:
6490 LOP(OP_SOCKPAIR,XTERM);
6493 checkcomma(s,PL_tokenbuf,"subroutine name");
6495 if (*s == ';' || *s == ')') /* probably a close */
6496 Perl_croak(aTHX_ "sort is now a reserved word");
6498 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6502 LOP(OP_SPLIT,XTERM);
6505 LOP(OP_SPRINTF,XTERM);
6508 LOP(OP_SPLICE,XTERM);
6523 LOP(OP_SUBSTR,XTERM);
6529 char tmpbuf[sizeof PL_tokenbuf];
6530 SSize_t tboffset = 0;
6531 expectation attrful;
6532 bool have_name, have_proto;
6533 const int key = tmp;
6538 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6539 SV *subtoken = newSVpvn(tstart, s - tstart);
6543 s = SKIPSPACE2(s,tmpwhite);
6548 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6549 (*s == ':' && s[1] == ':'))
6556 attrful = XATTRBLOCK;
6557 /* remember buffer pos'n for later force_word */
6558 tboffset = s - PL_oldbufptr;
6559 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6562 nametoke = newSVpvn(s, d - s);
6564 if (strchr(tmpbuf, ':'))
6565 sv_setpv(PL_subname, tmpbuf);
6567 sv_setsv(PL_subname,PL_curstname);
6568 sv_catpvs(PL_subname,"::");
6569 sv_catpvn(PL_subname,tmpbuf,len);
6576 CURMAD('X', nametoke);
6577 CURMAD('_', tmpwhite);
6578 (void) force_word(PL_oldbufptr + tboffset, WORD,
6581 s = SKIPSPACE2(d,tmpwhite);
6588 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6589 PL_expect = XTERMBLOCK;
6590 attrful = XATTRTERM;
6591 sv_setpvn(PL_subname,"?",1);
6595 if (key == KEY_format) {
6597 PL_lex_formbrack = PL_lex_brackets + 1;
6599 PL_thistoken = subtoken;
6603 (void) force_word(PL_oldbufptr + tboffset, WORD,
6609 /* Look for a prototype */
6612 bool bad_proto = FALSE;
6613 const bool warnsyntax = ckWARN(WARN_SYNTAX);
6615 s = scan_str(s,!!PL_madskills,FALSE);
6617 Perl_croak(aTHX_ "Prototype not terminated");
6618 /* strip spaces and check for bad characters */
6619 d = SvPVX(PL_lex_stuff);
6621 for (p = d; *p; ++p) {
6624 if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
6630 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6631 "Illegal character in prototype for %"SVf" : %s",
6632 (void*)PL_subname, d);
6633 SvCUR_set(PL_lex_stuff, tmp);
6638 CURMAD('q', PL_thisopen);
6639 CURMAD('_', tmpwhite);
6640 CURMAD('=', PL_thisstuff);
6641 CURMAD('Q', PL_thisclose);
6642 NEXTVAL_NEXTTOKE.opval =
6643 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6644 PL_lex_stuff = Nullsv;
6647 s = SKIPSPACE2(s,tmpwhite);
6655 if (*s == ':' && s[1] != ':')
6656 PL_expect = attrful;
6657 else if (*s != '{' && key == KEY_sub) {
6659 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6661 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, (void*)PL_subname);
6668 curmad('^', newSVpvs(""));
6669 CURMAD('_', tmpwhite);
6673 PL_thistoken = subtoken;
6676 NEXTVAL_NEXTTOKE.opval =
6677 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6678 PL_lex_stuff = NULL;
6683 sv_setpv(PL_subname,
6685 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
6689 (void) force_word(PL_oldbufptr + tboffset, WORD,
6699 LOP(OP_SYSTEM,XREF);
6702 LOP(OP_SYMLINK,XTERM);
6705 LOP(OP_SYSCALL,XTERM);
6708 LOP(OP_SYSOPEN,XTERM);
6711 LOP(OP_SYSSEEK,XTERM);
6714 LOP(OP_SYSREAD,XTERM);
6717 LOP(OP_SYSWRITE,XTERM);
6721 TERM(sublex_start());
6742 LOP(OP_TRUNCATE,XTERM);
6754 yylval.ival = CopLINE(PL_curcop);
6758 yylval.ival = CopLINE(PL_curcop);
6762 LOP(OP_UNLINK,XTERM);
6768 LOP(OP_UNPACK,XTERM);
6771 LOP(OP_UTIME,XTERM);
6777 LOP(OP_UNSHIFT,XTERM);
6780 s = tokenize_use(1, s);
6790 yylval.ival = CopLINE(PL_curcop);
6794 yylval.ival = CopLINE(PL_curcop);
6798 PL_hints |= HINT_BLOCK_SCOPE;
6805 LOP(OP_WAITPID,XTERM);
6814 ctl_l[0] = toCTRL('L');
6816 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6819 /* Make sure $^L is defined */
6820 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6825 if (PL_expect == XOPERATOR)
6831 yylval.ival = OP_XOR;
6836 TERM(sublex_start());
6841 #pragma segment Main
6845 S_pending_ident(pTHX)
6850 /* pit holds the identifier we read and pending_ident is reset */
6851 char pit = PL_pending_ident;
6852 PL_pending_ident = 0;
6854 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6855 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6856 "### Pending identifier '%s'\n", PL_tokenbuf); });
6858 /* if we're in a my(), we can't allow dynamics here.
6859 $foo'bar has already been turned into $foo::bar, so
6860 just check for colons.
6862 if it's a legal name, the OP is a PADANY.
6865 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6866 if (strchr(PL_tokenbuf,':'))
6867 yyerror(Perl_form(aTHX_ "No package name allowed for "
6868 "variable %s in \"our\"",
6870 tmp = allocmy(PL_tokenbuf);
6873 if (strchr(PL_tokenbuf,':'))
6874 yyerror(Perl_form(aTHX_ PL_no_myglob,
6875 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6877 yylval.opval = newOP(OP_PADANY, 0);
6878 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6884 build the ops for accesses to a my() variable.
6886 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6887 then used in a comparison. This catches most, but not
6888 all cases. For instance, it catches
6889 sort { my($a); $a <=> $b }
6891 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6892 (although why you'd do that is anyone's guess).
6895 if (!strchr(PL_tokenbuf,':')) {
6897 tmp = pad_findmy(PL_tokenbuf);
6898 if (tmp != NOT_IN_PAD) {
6899 /* might be an "our" variable" */
6900 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6901 /* build ops for a bareword */
6902 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6903 HEK * const stashname = HvNAME_HEK(stash);
6904 SV * const sym = newSVhek(stashname);
6905 sv_catpvs(sym, "::");
6906 sv_catpv(sym, PL_tokenbuf+1);
6907 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6908 yylval.opval->op_private = OPpCONST_ENTERED;
6911 ? (GV_ADDMULTI | GV_ADDINEVAL)
6914 ((PL_tokenbuf[0] == '$') ? SVt_PV
6915 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6920 /* if it's a sort block and they're naming $a or $b */
6921 if (PL_last_lop_op == OP_SORT &&
6922 PL_tokenbuf[0] == '$' &&
6923 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6926 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6927 d < PL_bufend && *d != '\n';
6930 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6931 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6937 yylval.opval = newOP(OP_PADANY, 0);
6938 yylval.opval->op_targ = tmp;
6944 Whine if they've said @foo in a doublequoted string,
6945 and @foo isn't a variable we can find in the symbol
6948 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6949 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6950 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6951 && ckWARN(WARN_AMBIGUOUS))
6953 /* Downgraded from fatal to warning 20000522 mjd */
6954 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6955 "Possible unintended interpolation of %s in string",
6960 /* build ops for a bareword */
6961 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6962 yylval.opval->op_private = OPpCONST_ENTERED;
6965 /* If the identifier refers to a stash, don't autovivify it.
6966 * Change 24660 had the side effect of causing symbol table
6967 * hashes to always be defined, even if they were freshly
6968 * created and the only reference in the entire program was
6969 * the single statement with the defined %foo::bar:: test.
6970 * It appears that all code in the wild doing this actually
6971 * wants to know whether sub-packages have been loaded, so
6972 * by avoiding auto-vivifying symbol tables, we ensure that
6973 * defined %foo::bar:: continues to be false, and the existing
6974 * tests still give the expected answers, even though what
6975 * they're actually testing has now changed subtly.
6977 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6979 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
6980 ((PL_tokenbuf[0] == '$') ? SVt_PV
6981 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6987 * The following code was generated by perl_keyword.pl.
6991 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
6996 case 1: /* 5 tokens of length 1 */
7028 case 2: /* 18 tokens of length 2 */
7174 case 3: /* 29 tokens of length 3 */
7178 if (name[1] == 'N' &&
7241 if (name[1] == 'i' &&
7263 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7281 if (name[1] == 'o' &&
7290 if (name[1] == 'e' &&
7299 if (name[1] == 'n' &&
7308 if (name[1] == 'o' &&
7317 if (name[1] == 'a' &&
7326 if (name[1] == 'o' &&
7388 if (name[1] == 'e' &&
7402 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
7428 if (name[1] == 'i' &&
7437 if (name[1] == 's' &&
7446 if (name[1] == 'e' &&
7455 if (name[1] == 'o' &&
7467 case 4: /* 41 tokens of length 4 */
7471 if (name[1] == 'O' &&
7481 if (name[1] == 'N' &&
7491 if (name[1] == 'i' &&
7501 if (name[1] == 'h' &&
7511 if (name[1] == 'u' &&
7524 if (name[2] == 'c' &&
7533 if (name[2] == 's' &&
7542 if (name[2] == 'a' &&
7578 if (name[1] == 'o' &&
7591 if (name[2] == 't' &&
7600 if (name[2] == 'o' &&
7609 if (name[2] == 't' &&
7618 if (name[2] == 'e' &&
7631 if (name[1] == 'o' &&
7644 if (name[2] == 'y' &&
7653 if (name[2] == 'l' &&
7669 if (name[2] == 's' &&
7678 if (name[2] == 'n' &&
7687 if (name[2] == 'c' &&
7700 if (name[1] == 'e' &&
7710 if (name[1] == 'p' &&
7723 if (name[2] == 'c' &&
7732 if (name[2] == 'p' &&
7741 if (name[2] == 's' &&
7757 if (name[2] == 'n' &&
7827 if (name[2] == 'r' &&
7836 if (name[2] == 'r' &&
7845 if (name[2] == 'a' &&
7861 if (name[2] == 'l' &&
7923 if (name[2] == 'e' &&
7926 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7939 case 5: /* 39 tokens of length 5 */
7943 if (name[1] == 'E' &&
7954 if (name[1] == 'H' &&
7968 if (name[2] == 'a' &&
7978 if (name[2] == 'a' &&
7995 if (name[2] == 'e' &&
8005 if (name[2] == 'e' &&
8009 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
8025 if (name[3] == 'i' &&
8034 if (name[3] == 'o' &&
8070 if (name[2] == 'o' &&
8080 if (name[2] == 'y' &&
8094 if (name[1] == 'l' &&
8108 if (name[2] == 'n' &&
8118 if (name[2] == 'o' &&
8132 if (name[1] == 'i' &&
8137 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8146 if (name[2] == 'd' &&
8156 if (name[2] == 'c' &&
8173 if (name[2] == 'c' &&
8183 if (name[2] == 't' &&
8197 if (name[1] == 'k' &&
8208 if (name[1] == 'r' &&
8222 if (name[2] == 's' &&
8232 if (name[2] == 'd' &&
8249 if (name[2] == 'm' &&
8259 if (name[2] == 'i' &&
8269 if (name[2] == 'e' &&
8279 if (name[2] == 'l' &&
8289 if (name[2] == 'a' &&
8302 if (name[3] == 't' &&
8305 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8311 if (name[3] == 'd' &&
8328 if (name[1] == 'i' &&
8342 if (name[2] == 'a' &&
8355 if (name[3] == 'e' &&
8390 if (name[2] == 'i' &&
8407 if (name[2] == 'i' &&
8417 if (name[2] == 'i' &&
8434 case 6: /* 33 tokens of length 6 */
8438 if (name[1] == 'c' &&
8453 if (name[2] == 'l' &&
8464 if (name[2] == 'r' &&
8479 if (name[1] == 'e' &&
8494 if (name[2] == 's' &&
8499 if(ckWARN_d(WARN_SYNTAX))
8500 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8506 if (name[2] == 'i' &&
8524 if (name[2] == 'l' &&
8535 if (name[2] == 'r' &&
8550 if (name[1] == 'm' &&
8565 if (name[2] == 'n' &&
8576 if (name[2] == 's' &&
8591 if (name[1] == 's' &&
8597 if (name[4] == 't' &&
8606 if (name[4] == 'e' &&
8615 if (name[4] == 'c' &&
8624 if (name[4] == 'n' &&
8640 if (name[1] == 'r' &&
8658 if (name[3] == 'a' &&
8668 if (name[3] == 'u' &&
8682 if (name[2] == 'n' &&
8700 if (name[2] == 'a' &&
8714 if (name[3] == 'e' &&
8727 if (name[4] == 't' &&
8736 if (name[4] == 'e' &&
8758 if (name[4] == 't' &&
8767 if (name[4] == 'e' &&
8783 if (name[2] == 'c' &&
8794 if (name[2] == 'l' &&
8805 if (name[2] == 'b' &&
8816 if (name[2] == 's' &&
8839 if (name[4] == 's' &&
8848 if (name[4] == 'n' &&
8861 if (name[3] == 'a' &&
8878 if (name[1] == 'a' &&
8893 case 7: /* 29 tokens of length 7 */
8897 if (name[1] == 'E' &&
8910 if (name[1] == '_' &&
8923 if (name[1] == 'i' &&
8930 return -KEY_binmode;
8936 if (name[1] == 'o' &&
8943 return -KEY_connect;
8952 if (name[2] == 'm' &&
8958 return -KEY_dbmopen;
8969 if (name[4] == 'u' &&
8973 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
8979 if (name[4] == 'n' &&
9000 if (name[1] == 'o' &&
9013 if (name[1] == 'e' &&
9020 if (name[5] == 'r' &&
9023 return -KEY_getpgrp;
9029 if (name[5] == 'i' &&
9032 return -KEY_getppid;
9045 if (name[1] == 'c' &&
9052 return -KEY_lcfirst;
9058 if (name[1] == 'p' &&
9065 return -KEY_opendir;
9071 if (name[1] == 'a' &&
9089 if (name[3] == 'd' &&
9094 return -KEY_readdir;
9100 if (name[3] == 'u' &&
9111 if (name[3] == 'e' &&
9116 return -KEY_reverse;
9135 if (name[3] == 'k' &&
9140 return -KEY_seekdir;
9146 if (name[3] == 'p' &&
9151 return -KEY_setpgrp;
9161 if (name[2] == 'm' &&
9167 return -KEY_shmread;
9173 if (name[2] == 'r' &&
9179 return -KEY_sprintf;
9188 if (name[3] == 'l' &&
9193 return -KEY_symlink;
9202 if (name[4] == 'a' &&
9206 return -KEY_syscall;
9212 if (name[4] == 'p' &&
9216 return -KEY_sysopen;
9222 if (name[4] == 'e' &&
9226 return -KEY_sysread;
9232 if (name[4] == 'e' &&
9236 return -KEY_sysseek;
9254 if (name[1] == 'e' &&
9261 return -KEY_telldir;
9270 if (name[2] == 'f' &&
9276 return -KEY_ucfirst;
9282 if (name[2] == 's' &&
9288 return -KEY_unshift;
9298 if (name[1] == 'a' &&
9305 return -KEY_waitpid;
9314 case 8: /* 26 tokens of length 8 */
9318 if (name[1] == 'U' &&
9326 return KEY_AUTOLOAD;
9337 if (name[3] == 'A' &&
9343 return KEY___DATA__;
9349 if (name[3] == 'I' &&
9355 return -KEY___FILE__;
9361 if (name[3] == 'I' &&
9367 return -KEY___LINE__;
9383 if (name[2] == 'o' &&
9390 return -KEY_closedir;
9396 if (name[2] == 'n' &&
9403 return -KEY_continue;
9413 if (name[1] == 'b' &&
9421 return -KEY_dbmclose;
9427 if (name[1] == 'n' &&
9433 if (name[4] == 'r' &&
9438 return -KEY_endgrent;
9444 if (name[4] == 'w' &&
9449 return -KEY_endpwent;
9462 if (name[1] == 'o' &&
9470 return -KEY_formline;
9476 if (name[1] == 'e' &&
9487 if (name[6] == 'n' &&
9490 return -KEY_getgrent;
9496 if (name[6] == 'i' &&
9499 return -KEY_getgrgid;
9505 if (name[6] == 'a' &&
9508 return -KEY_getgrnam;
9521 if (name[4] == 'o' &&
9526 return -KEY_getlogin;
9537 if (name[6] == 'n' &&
9540 return -KEY_getpwent;
9546 if (name[6] == 'a' &&
9549 return -KEY_getpwnam;
9555 if (name[6] == 'i' &&
9558 return -KEY_getpwuid;
9578 if (name[1] == 'e' &&
9585 if (name[5] == 'i' &&
9592 return -KEY_readline;
9597 return -KEY_readlink;
9608 if (name[5] == 'i' &&
9612 return -KEY_readpipe;
9633 if (name[4] == 'r' &&
9638 return -KEY_setgrent;
9644 if (name[4] == 'w' &&
9649 return -KEY_setpwent;
9665 if (name[3] == 'w' &&
9671 return -KEY_shmwrite;
9677 if (name[3] == 't' &&
9683 return -KEY_shutdown;
9693 if (name[2] == 's' &&
9700 return -KEY_syswrite;
9710 if (name[1] == 'r' &&
9718 return -KEY_truncate;
9727 case 9: /* 9 tokens of length 9 */
9731 if (name[1] == 'N' &&
9740 return KEY_UNITCHECK;
9746 if (name[1] == 'n' &&
9755 return -KEY_endnetent;
9761 if (name[1] == 'e' &&
9770 return -KEY_getnetent;
9776 if (name[1] == 'o' &&
9785 return -KEY_localtime;
9791 if (name[1] == 'r' &&
9800 return KEY_prototype;
9806 if (name[1] == 'u' &&
9815 return -KEY_quotemeta;
9821 if (name[1] == 'e' &&
9830 return -KEY_rewinddir;
9836 if (name[1] == 'e' &&
9845 return -KEY_setnetent;
9851 if (name[1] == 'a' &&
9860 return -KEY_wantarray;
9869 case 10: /* 9 tokens of length 10 */
9873 if (name[1] == 'n' &&
9879 if (name[4] == 'o' &&
9886 return -KEY_endhostent;
9892 if (name[4] == 'e' &&
9899 return -KEY_endservent;
9912 if (name[1] == 'e' &&
9918 if (name[4] == 'o' &&
9925 return -KEY_gethostent;
9934 if (name[5] == 'r' &&
9940 return -KEY_getservent;
9946 if (name[5] == 'c' &&
9952 return -KEY_getsockopt;
9977 if (name[4] == 'o' &&
9984 return -KEY_sethostent;
9993 if (name[5] == 'r' &&
9999 return -KEY_setservent;
10005 if (name[5] == 'c' &&
10011 return -KEY_setsockopt;
10028 if (name[2] == 'c' &&
10037 return -KEY_socketpair;
10050 case 11: /* 8 tokens of length 11 */
10054 if (name[1] == '_' &&
10064 { /* __PACKAGE__ */
10065 return -KEY___PACKAGE__;
10071 if (name[1] == 'n' &&
10081 { /* endprotoent */
10082 return -KEY_endprotoent;
10088 if (name[1] == 'e' &&
10097 if (name[5] == 'e' &&
10103 { /* getpeername */
10104 return -KEY_getpeername;
10113 if (name[6] == 'o' &&
10118 { /* getpriority */
10119 return -KEY_getpriority;
10125 if (name[6] == 't' &&
10130 { /* getprotoent */
10131 return -KEY_getprotoent;
10145 if (name[4] == 'o' &&
10152 { /* getsockname */
10153 return -KEY_getsockname;
10166 if (name[1] == 'e' &&
10174 if (name[6] == 'o' &&
10179 { /* setpriority */
10180 return -KEY_setpriority;
10186 if (name[6] == 't' &&
10191 { /* setprotoent */
10192 return -KEY_setprotoent;
10208 case 12: /* 2 tokens of length 12 */
10209 if (name[0] == 'g' &&
10221 if (name[9] == 'd' &&
10224 { /* getnetbyaddr */
10225 return -KEY_getnetbyaddr;
10231 if (name[9] == 'a' &&
10234 { /* getnetbyname */
10235 return -KEY_getnetbyname;
10247 case 13: /* 4 tokens of length 13 */
10248 if (name[0] == 'g' &&
10255 if (name[4] == 'o' &&
10264 if (name[10] == 'd' &&
10267 { /* gethostbyaddr */
10268 return -KEY_gethostbyaddr;
10274 if (name[10] == 'a' &&
10277 { /* gethostbyname */
10278 return -KEY_gethostbyname;
10291 if (name[4] == 'e' &&
10300 if (name[10] == 'a' &&
10303 { /* getservbyname */
10304 return -KEY_getservbyname;
10310 if (name[10] == 'o' &&
10313 { /* getservbyport */
10314 return -KEY_getservbyport;
10333 case 14: /* 1 tokens of length 14 */
10334 if (name[0] == 'g' &&
10348 { /* getprotobyname */
10349 return -KEY_getprotobyname;
10354 case 16: /* 1 tokens of length 16 */
10355 if (name[0] == 'g' &&
10371 { /* getprotobynumber */
10372 return -KEY_getprotobynumber;
10386 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10390 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10391 if (ckWARN(WARN_SYNTAX)) {
10394 for (w = s+2; *w && level; w++) {
10397 else if (*w == ')')
10400 while (isSPACE(*w))
10402 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
10403 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10404 "%s (...) interpreted as function",name);
10407 while (s < PL_bufend && isSPACE(*s))
10411 while (s < PL_bufend && isSPACE(*s))
10413 if (isIDFIRST_lazy_if(s,UTF)) {
10414 const char * const w = s++;
10415 while (isALNUM_lazy_if(s,UTF))
10417 while (s < PL_bufend && isSPACE(*s))
10421 if (keyword(w, s - w, 0))
10424 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10425 if (gv && GvCVu(gv))
10427 Perl_croak(aTHX_ "No comma allowed after %s", what);
10432 /* Either returns sv, or mortalizes sv and returns a new SV*.
10433 Best used as sv=new_constant(..., sv, ...).
10434 If s, pv are NULL, calls subroutine with one argument,
10435 and type is used with error messages only. */
10438 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10442 HV * const table = GvHV(PL_hintgv); /* ^H */
10446 const char *why1 = "", *why2 = "", *why3 = "";
10448 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10451 why2 = (const char *)
10452 (strEQ(key,"charnames")
10453 ? "(possibly a missing \"use charnames ...\")"
10455 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10456 (type ? type: "undef"), why2);
10458 /* This is convoluted and evil ("goto considered harmful")
10459 * but I do not understand the intricacies of all the different
10460 * failure modes of %^H in here. The goal here is to make
10461 * the most probable error message user-friendly. --jhi */
10466 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10467 (type ? type: "undef"), why1, why2, why3);
10469 yyerror(SvPVX_const(msg));
10473 cvp = hv_fetch(table, key, strlen(key), FALSE);
10474 if (!cvp || !SvOK(*cvp)) {
10477 why3 = "} is not defined";
10480 sv_2mortal(sv); /* Parent created it permanently */
10483 pv = sv_2mortal(newSVpvn(s, len));
10485 typesv = sv_2mortal(newSVpv(type, 0));
10487 typesv = &PL_sv_undef;
10489 PUSHSTACKi(PERLSI_OVERLOAD);
10501 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10505 /* Check the eval first */
10506 if (!PL_in_eval && SvTRUE(ERRSV)) {
10507 sv_catpvs(ERRSV, "Propagated");
10508 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10510 res = SvREFCNT_inc_simple(sv);
10514 SvREFCNT_inc_simple_void(res);
10523 why1 = "Call to &{$^H{";
10525 why3 = "}} did not return a defined value";
10533 /* Returns a NUL terminated string, with the length of the string written to
10537 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10540 register char *d = dest;
10541 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10544 Perl_croak(aTHX_ ident_too_long);
10545 if (isALNUM(*s)) /* UTF handled below */
10547 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10552 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10556 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10557 char *t = s + UTF8SKIP(s);
10559 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10563 Perl_croak(aTHX_ ident_too_long);
10564 Copy(s, d, len, char);
10577 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10580 char *bracket = NULL;
10582 register char *d = dest;
10583 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10588 while (isDIGIT(*s)) {
10590 Perl_croak(aTHX_ ident_too_long);
10597 Perl_croak(aTHX_ ident_too_long);
10598 if (isALNUM(*s)) /* UTF handled below */
10600 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10605 else if (*s == ':' && s[1] == ':') {
10609 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10610 char *t = s + UTF8SKIP(s);
10611 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10613 if (d + (t - s) > e)
10614 Perl_croak(aTHX_ ident_too_long);
10615 Copy(s, d, t - s, char);
10626 if (PL_lex_state != LEX_NORMAL)
10627 PL_lex_state = LEX_INTERPENDMAYBE;
10630 if (*s == '$' && s[1] &&
10631 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10644 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10649 if (isSPACE(s[-1])) {
10651 const char ch = *s++;
10652 if (!SPACE_OR_TAB(ch)) {
10658 if (isIDFIRST_lazy_if(d,UTF)) {
10662 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10663 end += UTF8SKIP(end);
10664 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10665 end += UTF8SKIP(end);
10667 Copy(s, d, end - s, char);
10672 while ((isALNUM(*s) || *s == ':') && d < e)
10675 Perl_croak(aTHX_ ident_too_long);
10678 while (s < send && SPACE_OR_TAB(*s))
10680 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10681 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10682 const char * const brack =
10684 ((*s == '[') ? "[...]" : "{...}");
10685 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10686 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10687 funny, dest, brack, funny, dest, brack);
10690 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10694 /* Handle extended ${^Foo} variables
10695 * 1999-02-27 mjd-perl-patch@plover.com */
10696 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10700 while (isALNUM(*s) && d < e) {
10704 Perl_croak(aTHX_ ident_too_long);
10709 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10710 PL_lex_state = LEX_INTERPEND;
10713 if (PL_lex_state == LEX_NORMAL) {
10714 if (ckWARN(WARN_AMBIGUOUS) &&
10715 (keyword(dest, d - dest, 0) || get_cv(dest, FALSE)))
10719 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10720 "Ambiguous use of %c{%s} resolved to %c%s",
10721 funny, dest, funny, dest);
10726 s = bracket; /* let the parser handle it */
10730 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10731 PL_lex_state = LEX_INTERPEND;
10736 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10738 PERL_UNUSED_CONTEXT;
10741 else if (ch == 'g')
10742 *pmfl |= PMf_GLOBAL;
10743 else if (ch == 'c')
10744 *pmfl |= PMf_CONTINUE;
10745 else if (ch == 'o')
10747 else if (ch == 'm')
10748 *pmfl |= PMf_MULTILINE;
10749 else if (ch == 's')
10750 *pmfl |= PMf_SINGLELINE;
10751 else if (ch == 'x')
10752 *pmfl |= PMf_EXTENDED;
10756 S_scan_pat(pTHX_ char *start, I32 type)
10760 char *s = scan_str(start,!!PL_madskills,FALSE);
10761 const char * const valid_flags =
10762 (const char *)((type == OP_QR) ? "iomsx" : "iogcmsx");
10769 const char * const delimiter = skipspace(start);
10773 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10774 : "Search pattern not terminated" ));
10777 pm = (PMOP*)newPMOP(type, 0);
10778 if (PL_multi_open == '?')
10779 pm->op_pmflags |= PMf_ONCE;
10783 while (*s && strchr(valid_flags, *s))
10784 pmflag(&pm->op_pmflags,*s++);
10786 if (PL_madskills && modstart != s) {
10787 SV* tmptoken = newSVpvn(modstart, s - modstart);
10788 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10791 /* issue a warning if /c is specified,but /g is not */
10792 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10793 && ckWARN(WARN_REGEXP))
10795 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
10798 pm->op_pmpermflags = pm->op_pmflags;
10800 PL_lex_op = (OP*)pm;
10801 yylval.ival = OP_MATCH;
10806 S_scan_subst(pTHX_ char *start)
10817 yylval.ival = OP_NULL;
10819 s = scan_str(start,!!PL_madskills,FALSE);
10822 Perl_croak(aTHX_ "Substitution pattern not terminated");
10824 if (s[-1] == PL_multi_open)
10827 if (PL_madskills) {
10828 CURMAD('q', PL_thisopen);
10829 CURMAD('_', PL_thiswhite);
10830 CURMAD('E', PL_thisstuff);
10831 CURMAD('Q', PL_thisclose);
10832 PL_realtokenstart = s - SvPVX(PL_linestr);
10836 first_start = PL_multi_start;
10837 s = scan_str(s,!!PL_madskills,FALSE);
10839 if (PL_lex_stuff) {
10840 SvREFCNT_dec(PL_lex_stuff);
10841 PL_lex_stuff = NULL;
10843 Perl_croak(aTHX_ "Substitution replacement not terminated");
10845 PL_multi_start = first_start; /* so whole substitution is taken together */
10847 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10850 if (PL_madskills) {
10851 CURMAD('z', PL_thisopen);
10852 CURMAD('R', PL_thisstuff);
10853 CURMAD('Z', PL_thisclose);
10863 else if (strchr("iogcmsx", *s))
10864 pmflag(&pm->op_pmflags,*s++);
10870 if (PL_madskills) {
10872 curmad('m', newSVpvn(modstart, s - modstart));
10873 append_madprops(PL_thismad, (OP*)pm, 0);
10877 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10878 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10882 SV * const repl = newSVpvs("");
10884 PL_sublex_info.super_bufptr = s;
10885 PL_sublex_info.super_bufend = PL_bufend;
10887 pm->op_pmflags |= PMf_EVAL;
10889 sv_catpv(repl, (const char *)(es ? "eval " : "do "));
10890 sv_catpvs(repl, "{");
10891 sv_catsv(repl, PL_lex_repl);
10892 if (strchr(SvPVX(PL_lex_repl), '#'))
10893 sv_catpvs(repl, "\n");
10894 sv_catpvs(repl, "}");
10896 SvREFCNT_dec(PL_lex_repl);
10897 PL_lex_repl = repl;
10900 pm->op_pmpermflags = pm->op_pmflags;
10901 PL_lex_op = (OP*)pm;
10902 yylval.ival = OP_SUBST;
10907 S_scan_trans(pTHX_ char *start)
10920 yylval.ival = OP_NULL;
10922 s = scan_str(start,!!PL_madskills,FALSE);
10924 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10926 if (s[-1] == PL_multi_open)
10929 if (PL_madskills) {
10930 CURMAD('q', PL_thisopen);
10931 CURMAD('_', PL_thiswhite);
10932 CURMAD('E', PL_thisstuff);
10933 CURMAD('Q', PL_thisclose);
10934 PL_realtokenstart = s - SvPVX(PL_linestr);
10938 s = scan_str(s,!!PL_madskills,FALSE);
10940 if (PL_lex_stuff) {
10941 SvREFCNT_dec(PL_lex_stuff);
10942 PL_lex_stuff = NULL;
10944 Perl_croak(aTHX_ "Transliteration replacement not terminated");
10946 if (PL_madskills) {
10947 CURMAD('z', PL_thisopen);
10948 CURMAD('R', PL_thisstuff);
10949 CURMAD('Z', PL_thisclose);
10952 complement = del = squash = 0;
10959 complement = OPpTRANS_COMPLEMENT;
10962 del = OPpTRANS_DELETE;
10965 squash = OPpTRANS_SQUASH;
10974 Newx(tbl, complement&&!del?258:256, short);
10975 o = newPVOP(OP_TRANS, 0, (char*)tbl);
10976 o->op_private &= ~OPpTRANS_ALL;
10977 o->op_private |= del|squash|complement|
10978 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10979 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
10982 yylval.ival = OP_TRANS;
10985 if (PL_madskills) {
10987 curmad('m', newSVpvn(modstart, s - modstart));
10988 append_madprops(PL_thismad, o, 0);
10997 S_scan_heredoc(pTHX_ register char *s)
11001 I32 op_type = OP_SCALAR;
11005 const char *found_newline;
11009 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
11011 I32 stuffstart = s - SvPVX(PL_linestr);
11014 PL_realtokenstart = -1;
11019 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
11023 while (SPACE_OR_TAB(*peek))
11025 if (*peek == '`' || *peek == '\'' || *peek =='"') {
11028 s = delimcpy(d, e, s, PL_bufend, term, &len);
11038 if (!isALNUM_lazy_if(s,UTF))
11039 deprecate_old("bare << to mean <<\"\"");
11040 for (; isALNUM_lazy_if(s,UTF); s++) {
11045 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
11046 Perl_croak(aTHX_ "Delimiter for here document is too long");
11049 len = d - PL_tokenbuf;
11052 if (PL_madskills) {
11053 tstart = PL_tokenbuf + !outer;
11054 PL_thisclose = newSVpvn(tstart, len - !outer);
11055 tstart = SvPVX(PL_linestr) + stuffstart;
11056 PL_thisopen = newSVpvn(tstart, s - tstart);
11057 stuffstart = s - SvPVX(PL_linestr);
11060 #ifndef PERL_STRICT_CR
11061 d = strchr(s, '\r');
11063 char * const olds = s;
11065 while (s < PL_bufend) {
11071 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11080 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11087 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11088 herewas = newSVpvn(s,PL_bufend-s);
11092 herewas = newSVpvn(s-1,found_newline-s+1);
11095 herewas = newSVpvn(s,found_newline-s);
11099 if (PL_madskills) {
11100 tstart = SvPVX(PL_linestr) + stuffstart;
11102 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11104 PL_thisstuff = newSVpvn(tstart, s - tstart);
11107 s += SvCUR(herewas);
11110 stuffstart = s - SvPVX(PL_linestr);
11116 tmpstr = newSV(79);
11117 sv_upgrade(tmpstr, SVt_PVIV);
11118 if (term == '\'') {
11119 op_type = OP_CONST;
11120 SvIV_set(tmpstr, -1);
11122 else if (term == '`') {
11123 op_type = OP_BACKTICK;
11124 SvIV_set(tmpstr, '\\');
11128 PL_multi_start = CopLINE(PL_curcop);
11129 PL_multi_open = PL_multi_close = '<';
11130 term = *PL_tokenbuf;
11131 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11132 char * const bufptr = PL_sublex_info.super_bufptr;
11133 char * const bufend = PL_sublex_info.super_bufend;
11134 char * const olds = s - SvCUR(herewas);
11135 s = strchr(bufptr, '\n');
11139 while (s < bufend &&
11140 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11142 CopLINE_inc(PL_curcop);
11145 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11146 missingterm(PL_tokenbuf);
11148 sv_setpvn(herewas,bufptr,d-bufptr+1);
11149 sv_setpvn(tmpstr,d+1,s-d);
11151 sv_catpvn(herewas,s,bufend-s);
11152 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11159 while (s < PL_bufend &&
11160 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11162 CopLINE_inc(PL_curcop);
11164 if (s >= PL_bufend) {
11165 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11166 missingterm(PL_tokenbuf);
11168 sv_setpvn(tmpstr,d+1,s-d);
11170 if (PL_madskills) {
11172 sv_catpvn(PL_thisstuff, d + 1, s - d);
11174 PL_thisstuff = newSVpvn(d + 1, s - d);
11175 stuffstart = s - SvPVX(PL_linestr);
11179 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11181 sv_catpvn(herewas,s,PL_bufend-s);
11182 sv_setsv(PL_linestr,herewas);
11183 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11184 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11185 PL_last_lop = PL_last_uni = NULL;
11188 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11189 while (s >= PL_bufend) { /* multiple line string? */
11191 if (PL_madskills) {
11192 tstart = SvPVX(PL_linestr) + stuffstart;
11194 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11196 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11200 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11201 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11202 missingterm(PL_tokenbuf);
11205 stuffstart = s - SvPVX(PL_linestr);
11207 CopLINE_inc(PL_curcop);
11208 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11209 PL_last_lop = PL_last_uni = NULL;
11210 #ifndef PERL_STRICT_CR
11211 if (PL_bufend - PL_linestart >= 2) {
11212 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11213 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11215 PL_bufend[-2] = '\n';
11217 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11219 else if (PL_bufend[-1] == '\r')
11220 PL_bufend[-1] = '\n';
11222 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11223 PL_bufend[-1] = '\n';
11225 if (PERLDB_LINE && PL_curstash != PL_debstash)
11226 update_debugger_info_sv(PL_linestr);
11227 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11228 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11229 *(SvPVX(PL_linestr) + off ) = ' ';
11230 sv_catsv(PL_linestr,herewas);
11231 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11232 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11236 sv_catsv(tmpstr,PL_linestr);
11241 PL_multi_end = CopLINE(PL_curcop);
11242 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11243 SvPV_shrink_to_cur(tmpstr);
11245 SvREFCNT_dec(herewas);
11247 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11249 else if (PL_encoding)
11250 sv_recode_to_utf8(tmpstr, PL_encoding);
11252 PL_lex_stuff = tmpstr;
11253 yylval.ival = op_type;
11257 /* scan_inputsymbol
11258 takes: current position in input buffer
11259 returns: new position in input buffer
11260 side-effects: yylval and lex_op are set.
11265 <FH> read from filehandle
11266 <pkg::FH> read from package qualified filehandle
11267 <pkg'FH> read from package qualified filehandle
11268 <$fh> read from filehandle in $fh
11269 <*.h> filename glob
11274 S_scan_inputsymbol(pTHX_ char *start)
11277 register char *s = start; /* current position in buffer */
11281 char *d = PL_tokenbuf; /* start of temp holding space */
11282 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11284 end = strchr(s, '\n');
11287 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11289 /* die if we didn't have space for the contents of the <>,
11290 or if it didn't end, or if we see a newline
11293 if (len >= (I32)sizeof PL_tokenbuf)
11294 Perl_croak(aTHX_ "Excessively long <> operator");
11296 Perl_croak(aTHX_ "Unterminated <> operator");
11301 Remember, only scalar variables are interpreted as filehandles by
11302 this code. Anything more complex (e.g., <$fh{$num}>) will be
11303 treated as a glob() call.
11304 This code makes use of the fact that except for the $ at the front,
11305 a scalar variable and a filehandle look the same.
11307 if (*d == '$' && d[1]) d++;
11309 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11310 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11313 /* If we've tried to read what we allow filehandles to look like, and
11314 there's still text left, then it must be a glob() and not a getline.
11315 Use scan_str to pull out the stuff between the <> and treat it
11316 as nothing more than a string.
11319 if (d - PL_tokenbuf != len) {
11320 yylval.ival = OP_GLOB;
11322 s = scan_str(start,!!PL_madskills,FALSE);
11324 Perl_croak(aTHX_ "Glob not terminated");
11328 bool readline_overriden = FALSE;
11331 /* we're in a filehandle read situation */
11334 /* turn <> into <ARGV> */
11336 Copy("ARGV",d,5,char);
11338 /* Check whether readline() is overriden */
11339 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11341 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11343 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11344 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
11345 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11346 readline_overriden = TRUE;
11348 /* if <$fh>, create the ops to turn the variable into a
11352 /* try to find it in the pad for this block, otherwise find
11353 add symbol table ops
11355 const PADOFFSET tmp = pad_findmy(d);
11356 if (tmp != NOT_IN_PAD) {
11357 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11358 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11359 HEK * const stashname = HvNAME_HEK(stash);
11360 SV * const sym = sv_2mortal(newSVhek(stashname));
11361 sv_catpvs(sym, "::");
11362 sv_catpv(sym, d+1);
11367 OP * const o = newOP(OP_PADSV, 0);
11369 PL_lex_op = readline_overriden
11370 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11371 append_elem(OP_LIST, o,
11372 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11373 : (OP*)newUNOP(OP_READLINE, 0, o);
11382 ? (GV_ADDMULTI | GV_ADDINEVAL)
11385 PL_lex_op = readline_overriden
11386 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11387 append_elem(OP_LIST,
11388 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11389 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11390 : (OP*)newUNOP(OP_READLINE, 0,
11391 newUNOP(OP_RV2SV, 0,
11392 newGVOP(OP_GV, 0, gv)));
11394 if (!readline_overriden)
11395 PL_lex_op->op_flags |= OPf_SPECIAL;
11396 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11397 yylval.ival = OP_NULL;
11400 /* If it's none of the above, it must be a literal filehandle
11401 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11403 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11404 PL_lex_op = readline_overriden
11405 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11406 append_elem(OP_LIST,
11407 newGVOP(OP_GV, 0, gv),
11408 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11409 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11410 yylval.ival = OP_NULL;
11419 takes: start position in buffer
11420 keep_quoted preserve \ on the embedded delimiter(s)
11421 keep_delims preserve the delimiters around the string
11422 returns: position to continue reading from buffer
11423 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11424 updates the read buffer.
11426 This subroutine pulls a string out of the input. It is called for:
11427 q single quotes q(literal text)
11428 ' single quotes 'literal text'
11429 qq double quotes qq(interpolate $here please)
11430 " double quotes "interpolate $here please"
11431 qx backticks qx(/bin/ls -l)
11432 ` backticks `/bin/ls -l`
11433 qw quote words @EXPORT_OK = qw( func() $spam )
11434 m// regexp match m/this/
11435 s/// regexp substitute s/this/that/
11436 tr/// string transliterate tr/this/that/
11437 y/// string transliterate y/this/that/
11438 ($*@) sub prototypes sub foo ($)
11439 (stuff) sub attr parameters sub foo : attr(stuff)
11440 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11442 In most of these cases (all but <>, patterns and transliterate)
11443 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11444 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11445 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11448 It skips whitespace before the string starts, and treats the first
11449 character as the delimiter. If the delimiter is one of ([{< then
11450 the corresponding "close" character )]}> is used as the closing
11451 delimiter. It allows quoting of delimiters, and if the string has
11452 balanced delimiters ([{<>}]) it allows nesting.
11454 On success, the SV with the resulting string is put into lex_stuff or,
11455 if that is already non-NULL, into lex_repl. The second case occurs only
11456 when parsing the RHS of the special constructs s/// and tr/// (y///).
11457 For convenience, the terminating delimiter character is stuffed into
11462 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11465 SV *sv; /* scalar value: string */
11466 const char *tmps; /* temp string, used for delimiter matching */
11467 register char *s = start; /* current position in the buffer */
11468 register char term; /* terminating character */
11469 register char *to; /* current position in the sv's data */
11470 I32 brackets = 1; /* bracket nesting level */
11471 bool has_utf8 = FALSE; /* is there any utf8 content? */
11472 I32 termcode; /* terminating char. code */
11473 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11474 STRLEN termlen; /* length of terminating string */
11475 int last_off = 0; /* last position for nesting bracket */
11481 /* skip space before the delimiter */
11487 if (PL_realtokenstart >= 0) {
11488 stuffstart = PL_realtokenstart;
11489 PL_realtokenstart = -1;
11492 stuffstart = start - SvPVX(PL_linestr);
11494 /* mark where we are, in case we need to report errors */
11497 /* after skipping whitespace, the next character is the terminator */
11500 termcode = termstr[0] = term;
11504 termcode = utf8_to_uvchr((U8*)s, &termlen);
11505 Copy(s, termstr, termlen, U8);
11506 if (!UTF8_IS_INVARIANT(term))
11510 /* mark where we are */
11511 PL_multi_start = CopLINE(PL_curcop);
11512 PL_multi_open = term;
11514 /* find corresponding closing delimiter */
11515 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11516 termcode = termstr[0] = term = tmps[5];
11518 PL_multi_close = term;
11520 /* create a new SV to hold the contents. 79 is the SV's initial length.
11521 What a random number. */
11523 sv_upgrade(sv, SVt_PVIV);
11524 SvIV_set(sv, termcode);
11525 (void)SvPOK_only(sv); /* validate pointer */
11527 /* move past delimiter and try to read a complete string */
11529 sv_catpvn(sv, s, termlen);
11532 tstart = SvPVX(PL_linestr) + stuffstart;
11533 if (!PL_thisopen && !keep_delims) {
11534 PL_thisopen = newSVpvn(tstart, s - tstart);
11535 stuffstart = s - SvPVX(PL_linestr);
11539 if (PL_encoding && !UTF) {
11543 int offset = s - SvPVX_const(PL_linestr);
11544 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11545 &offset, (char*)termstr, termlen);
11546 const char * const ns = SvPVX_const(PL_linestr) + offset;
11547 char * const svlast = SvEND(sv) - 1;
11549 for (; s < ns; s++) {
11550 if (*s == '\n' && !PL_rsfp)
11551 CopLINE_inc(PL_curcop);
11554 goto read_more_line;
11556 /* handle quoted delimiters */
11557 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11559 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11561 if ((svlast-1 - t) % 2) {
11562 if (!keep_quoted) {
11563 *(svlast-1) = term;
11565 SvCUR_set(sv, SvCUR(sv) - 1);
11570 if (PL_multi_open == PL_multi_close) {
11576 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
11577 /* At here, all closes are "was quoted" one,
11578 so we don't check PL_multi_close. */
11580 if (!keep_quoted && *(t+1) == PL_multi_open)
11585 else if (*t == PL_multi_open)
11593 SvCUR_set(sv, w - SvPVX_const(sv));
11595 last_off = w - SvPVX(sv);
11596 if (--brackets <= 0)
11601 if (!keep_delims) {
11602 SvCUR_set(sv, SvCUR(sv) - 1);
11608 /* extend sv if need be */
11609 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11610 /* set 'to' to the next character in the sv's string */
11611 to = SvPVX(sv)+SvCUR(sv);
11613 /* if open delimiter is the close delimiter read unbridle */
11614 if (PL_multi_open == PL_multi_close) {
11615 for (; s < PL_bufend; s++,to++) {
11616 /* embedded newlines increment the current line number */
11617 if (*s == '\n' && !PL_rsfp)
11618 CopLINE_inc(PL_curcop);
11619 /* handle quoted delimiters */
11620 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11621 if (!keep_quoted && s[1] == term)
11623 /* any other quotes are simply copied straight through */
11627 /* terminate when run out of buffer (the for() condition), or
11628 have found the terminator */
11629 else if (*s == term) {
11632 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11635 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11641 /* if the terminator isn't the same as the start character (e.g.,
11642 matched brackets), we have to allow more in the quoting, and
11643 be prepared for nested brackets.
11646 /* read until we run out of string, or we find the terminator */
11647 for (; s < PL_bufend; s++,to++) {
11648 /* embedded newlines increment the line count */
11649 if (*s == '\n' && !PL_rsfp)
11650 CopLINE_inc(PL_curcop);
11651 /* backslashes can escape the open or closing characters */
11652 if (*s == '\\' && s+1 < PL_bufend) {
11653 if (!keep_quoted &&
11654 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11659 /* allow nested opens and closes */
11660 else if (*s == PL_multi_close && --brackets <= 0)
11662 else if (*s == PL_multi_open)
11664 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11669 /* terminate the copied string and update the sv's end-of-string */
11671 SvCUR_set(sv, to - SvPVX_const(sv));
11674 * this next chunk reads more into the buffer if we're not done yet
11678 break; /* handle case where we are done yet :-) */
11680 #ifndef PERL_STRICT_CR
11681 if (to - SvPVX_const(sv) >= 2) {
11682 if ((to[-2] == '\r' && to[-1] == '\n') ||
11683 (to[-2] == '\n' && to[-1] == '\r'))
11687 SvCUR_set(sv, to - SvPVX_const(sv));
11689 else if (to[-1] == '\r')
11692 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11697 /* if we're out of file, or a read fails, bail and reset the current
11698 line marker so we can report where the unterminated string began
11701 if (PL_madskills) {
11702 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11704 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11706 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11710 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11712 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11718 /* we read a line, so increment our line counter */
11719 CopLINE_inc(PL_curcop);
11721 /* update debugger info */
11722 if (PERLDB_LINE && PL_curstash != PL_debstash)
11723 update_debugger_info_sv(PL_linestr);
11725 /* having changed the buffer, we must update PL_bufend */
11726 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11727 PL_last_lop = PL_last_uni = NULL;
11730 /* at this point, we have successfully read the delimited string */
11732 if (!PL_encoding || UTF) {
11734 if (PL_madskills) {
11735 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11736 const int len = s - tstart;
11738 sv_catpvn(PL_thisstuff, tstart, len);
11740 PL_thisstuff = newSVpvn(tstart, len);
11741 if (!PL_thisclose && !keep_delims)
11742 PL_thisclose = newSVpvn(s,termlen);
11747 sv_catpvn(sv, s, termlen);
11752 if (PL_madskills) {
11753 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11754 const int len = s - tstart - termlen;
11756 sv_catpvn(PL_thisstuff, tstart, len);
11758 PL_thisstuff = newSVpvn(tstart, len);
11759 if (!PL_thisclose && !keep_delims)
11760 PL_thisclose = newSVpvn(s - termlen,termlen);
11764 if (has_utf8 || PL_encoding)
11767 PL_multi_end = CopLINE(PL_curcop);
11769 /* if we allocated too much space, give some back */
11770 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11771 SvLEN_set(sv, SvCUR(sv) + 1);
11772 SvPV_renew(sv, SvLEN(sv));
11775 /* decide whether this is the first or second quoted string we've read
11788 takes: pointer to position in buffer
11789 returns: pointer to new position in buffer
11790 side-effects: builds ops for the constant in yylval.op
11792 Read a number in any of the formats that Perl accepts:
11794 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11795 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11798 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11800 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11803 If it reads a number without a decimal point or an exponent, it will
11804 try converting the number to an integer and see if it can do so
11805 without loss of precision.
11809 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11812 register const char *s = start; /* current position in buffer */
11813 register char *d; /* destination in temp buffer */
11814 register char *e; /* end of temp buffer */
11815 NV nv; /* number read, as a double */
11816 SV *sv = NULL; /* place to put the converted number */
11817 bool floatit; /* boolean: int or float? */
11818 const char *lastub = NULL; /* position of last underbar */
11819 static char const number_too_long[] = "Number too long";
11821 /* We use the first character to decide what type of number this is */
11825 Perl_croak(aTHX_ "panic: scan_num");
11827 /* if it starts with a 0, it could be an octal number, a decimal in
11828 0.13 disguise, or a hexadecimal number, or a binary number. */
11832 u holds the "number so far"
11833 shift the power of 2 of the base
11834 (hex == 4, octal == 3, binary == 1)
11835 overflowed was the number more than we can hold?
11837 Shift is used when we add a digit. It also serves as an "are
11838 we in octal/hex/binary?" indicator to disallow hex characters
11839 when in octal mode.
11844 bool overflowed = FALSE;
11845 bool just_zero = TRUE; /* just plain 0 or binary number? */
11846 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11847 static const char* const bases[5] =
11848 { "", "binary", "", "octal", "hexadecimal" };
11849 static const char* const Bases[5] =
11850 { "", "Binary", "", "Octal", "Hexadecimal" };
11851 static const char* const maxima[5] =
11853 "0b11111111111111111111111111111111",
11857 const char *base, *Base, *max;
11859 /* check for hex */
11864 } else if (s[1] == 'b') {
11869 /* check for a decimal in disguise */
11870 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11872 /* so it must be octal */
11879 if (ckWARN(WARN_SYNTAX))
11880 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11881 "Misplaced _ in number");
11885 base = bases[shift];
11886 Base = Bases[shift];
11887 max = maxima[shift];
11889 /* read the rest of the number */
11891 /* x is used in the overflow test,
11892 b is the digit we're adding on. */
11897 /* if we don't mention it, we're done */
11901 /* _ are ignored -- but warned about if consecutive */
11903 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11904 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11905 "Misplaced _ in number");
11909 /* 8 and 9 are not octal */
11910 case '8': case '9':
11912 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11916 case '2': case '3': case '4':
11917 case '5': case '6': case '7':
11919 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11922 case '0': case '1':
11923 b = *s++ & 15; /* ASCII digit -> value of digit */
11927 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11928 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11929 /* make sure they said 0x */
11932 b = (*s++ & 7) + 9;
11934 /* Prepare to put the digit we have onto the end
11935 of the number so far. We check for overflows.
11941 x = u << shift; /* make room for the digit */
11943 if ((x >> shift) != u
11944 && !(PL_hints & HINT_NEW_BINARY)) {
11947 if (ckWARN_d(WARN_OVERFLOW))
11948 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11949 "Integer overflow in %s number",
11952 u = x | b; /* add the digit to the end */
11955 n *= nvshift[shift];
11956 /* If an NV has not enough bits in its
11957 * mantissa to represent an UV this summing of
11958 * small low-order numbers is a waste of time
11959 * (because the NV cannot preserve the
11960 * low-order bits anyway): we could just
11961 * remember when did we overflow and in the
11962 * end just multiply n by the right
11970 /* if we get here, we had success: make a scalar value from
11975 /* final misplaced underbar check */
11976 if (s[-1] == '_') {
11977 if (ckWARN(WARN_SYNTAX))
11978 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11983 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
11984 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11985 "%s number > %s non-portable",
11991 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
11992 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11993 "%s number > %s non-portable",
11998 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
11999 sv = new_constant(start, s - start, "integer",
12001 else if (PL_hints & HINT_NEW_BINARY)
12002 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
12007 handle decimal numbers.
12008 we're also sent here when we read a 0 as the first digit
12010 case '1': case '2': case '3': case '4': case '5':
12011 case '6': case '7': case '8': case '9': case '.':
12014 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
12017 /* read next group of digits and _ and copy into d */
12018 while (isDIGIT(*s) || *s == '_') {
12019 /* skip underscores, checking for misplaced ones
12023 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12024 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12025 "Misplaced _ in number");
12029 /* check for end of fixed-length buffer */
12031 Perl_croak(aTHX_ number_too_long);
12032 /* if we're ok, copy the character */
12037 /* final misplaced underbar check */
12038 if (lastub && s == lastub + 1) {
12039 if (ckWARN(WARN_SYNTAX))
12040 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12043 /* read a decimal portion if there is one. avoid
12044 3..5 being interpreted as the number 3. followed
12047 if (*s == '.' && s[1] != '.') {
12052 if (ckWARN(WARN_SYNTAX))
12053 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12054 "Misplaced _ in number");
12058 /* copy, ignoring underbars, until we run out of digits.
12060 for (; isDIGIT(*s) || *s == '_'; s++) {
12061 /* fixed length buffer check */
12063 Perl_croak(aTHX_ number_too_long);
12065 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12066 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12067 "Misplaced _ in number");
12073 /* fractional part ending in underbar? */
12074 if (s[-1] == '_') {
12075 if (ckWARN(WARN_SYNTAX))
12076 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12077 "Misplaced _ in number");
12079 if (*s == '.' && isDIGIT(s[1])) {
12080 /* oops, it's really a v-string, but without the "v" */
12086 /* read exponent part, if present */
12087 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12091 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12092 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12094 /* stray preinitial _ */
12096 if (ckWARN(WARN_SYNTAX))
12097 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12098 "Misplaced _ in number");
12102 /* allow positive or negative exponent */
12103 if (*s == '+' || *s == '-')
12106 /* stray initial _ */
12108 if (ckWARN(WARN_SYNTAX))
12109 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12110 "Misplaced _ in number");
12114 /* read digits of exponent */
12115 while (isDIGIT(*s) || *s == '_') {
12118 Perl_croak(aTHX_ number_too_long);
12122 if (((lastub && s == lastub + 1) ||
12123 (!isDIGIT(s[1]) && s[1] != '_'))
12124 && ckWARN(WARN_SYNTAX))
12125 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12126 "Misplaced _ in number");
12133 /* make an sv from the string */
12137 We try to do an integer conversion first if no characters
12138 indicating "float" have been found.
12143 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12145 if (flags == IS_NUMBER_IN_UV) {
12147 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12150 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12151 if (uv <= (UV) IV_MIN)
12152 sv_setiv(sv, -(IV)uv);
12159 /* terminate the string */
12161 nv = Atof(PL_tokenbuf);
12165 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12166 (PL_hints & HINT_NEW_INTEGER) )
12167 sv = new_constant(PL_tokenbuf,
12170 (floatit ? "float" : "integer"),
12174 /* if it starts with a v, it could be a v-string */
12177 sv = newSV(5); /* preallocate storage space */
12178 s = scan_vstring(s,sv);
12182 /* make the op for the constant and return */
12185 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12187 lvalp->opval = NULL;
12193 S_scan_formline(pTHX_ register char *s)
12196 register char *eol;
12198 SV * const stuff = newSVpvs("");
12199 bool needargs = FALSE;
12200 bool eofmt = FALSE;
12202 char *tokenstart = s;
12205 if (PL_madskills) {
12206 savewhite = PL_thiswhite;
12211 while (!needargs) {
12214 #ifdef PERL_STRICT_CR
12215 while (SPACE_OR_TAB(*t))
12218 while (SPACE_OR_TAB(*t) || *t == '\r')
12221 if (*t == '\n' || t == PL_bufend) {
12226 if (PL_in_eval && !PL_rsfp) {
12227 eol = (char *) memchr(s,'\n',PL_bufend-s);
12232 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12234 for (t = s; t < eol; t++) {
12235 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12237 goto enough; /* ~~ must be first line in formline */
12239 if (*t == '@' || *t == '^')
12243 sv_catpvn(stuff, s, eol-s);
12244 #ifndef PERL_STRICT_CR
12245 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12246 char *end = SvPVX(stuff) + SvCUR(stuff);
12249 SvCUR_set(stuff, SvCUR(stuff) - 1);
12259 if (PL_madskills) {
12261 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12263 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12266 s = filter_gets(PL_linestr, PL_rsfp, 0);
12268 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12270 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12272 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12273 PL_last_lop = PL_last_uni = NULL;
12282 if (SvCUR(stuff)) {
12285 PL_lex_state = LEX_NORMAL;
12286 start_force(PL_curforce);
12287 NEXTVAL_NEXTTOKE.ival = 0;
12291 PL_lex_state = LEX_FORMLINE;
12293 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12295 else if (PL_encoding)
12296 sv_recode_to_utf8(stuff, PL_encoding);
12298 start_force(PL_curforce);
12299 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12301 start_force(PL_curforce);
12302 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12306 SvREFCNT_dec(stuff);
12308 PL_lex_formbrack = 0;
12312 if (PL_madskills) {
12314 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12316 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12317 PL_thiswhite = savewhite;
12329 PL_cshlen = strlen(PL_cshname);
12331 #if defined(USE_ITHREADS)
12332 PERL_UNUSED_CONTEXT;
12338 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12341 const I32 oldsavestack_ix = PL_savestack_ix;
12342 CV* const outsidecv = PL_compcv;
12345 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12347 SAVEI32(PL_subline);
12348 save_item(PL_subname);
12349 SAVESPTR(PL_compcv);
12351 PL_compcv = (CV*)newSV(0);
12352 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12353 CvFLAGS(PL_compcv) |= flags;
12355 PL_subline = CopLINE(PL_curcop);
12356 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12357 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12358 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12360 return oldsavestack_ix;
12364 #pragma segment Perl_yylex
12367 Perl_yywarn(pTHX_ const char *s)
12370 PL_in_eval |= EVAL_WARNONLY;
12372 PL_in_eval &= ~EVAL_WARNONLY;
12377 Perl_yyerror(pTHX_ const char *s)
12380 const char *where = NULL;
12381 const char *context = NULL;
12385 if (!yychar || (yychar == ';' && !PL_rsfp))
12387 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12388 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12389 PL_oldbufptr != PL_bufptr) {
12392 The code below is removed for NetWare because it abends/crashes on NetWare
12393 when the script has error such as not having the closing quotes like:
12394 if ($var eq "value)
12395 Checking of white spaces is anyway done in NetWare code.
12398 while (isSPACE(*PL_oldoldbufptr))
12401 context = PL_oldoldbufptr;
12402 contlen = PL_bufptr - PL_oldoldbufptr;
12404 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12405 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12408 The code below is removed for NetWare because it abends/crashes on NetWare
12409 when the script has error such as not having the closing quotes like:
12410 if ($var eq "value)
12411 Checking of white spaces is anyway done in NetWare code.
12414 while (isSPACE(*PL_oldbufptr))
12417 context = PL_oldbufptr;
12418 contlen = PL_bufptr - PL_oldbufptr;
12420 else if (yychar > 255)
12421 where = "next token ???";
12422 else if (yychar == -2) { /* YYEMPTY */
12423 if (PL_lex_state == LEX_NORMAL ||
12424 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12425 where = "at end of line";
12426 else if (PL_lex_inpat)
12427 where = "within pattern";
12429 where = "within string";
12432 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12434 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12435 else if (isPRINT_LC(yychar))
12436 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12438 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12439 where = SvPVX_const(where_sv);
12441 msg = sv_2mortal(newSVpv(s, 0));
12442 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12443 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12445 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12447 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12448 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12449 Perl_sv_catpvf(aTHX_ msg,
12450 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12451 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12454 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12455 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, (void*)msg);
12458 if (PL_error_count >= 10) {
12459 if (PL_in_eval && SvCUR(ERRSV))
12460 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12461 (void*)ERRSV, OutCopFILE(PL_curcop));
12463 Perl_croak(aTHX_ "%s has too many errors.\n",
12464 OutCopFILE(PL_curcop));
12467 PL_in_my_stash = NULL;
12471 #pragma segment Main
12475 S_swallow_bom(pTHX_ U8 *s)
12478 const STRLEN slen = SvCUR(PL_linestr);
12481 if (s[1] == 0xFE) {
12482 /* UTF-16 little-endian? (or UTF32-LE?) */
12483 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12484 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12485 #ifndef PERL_NO_UTF16_FILTER
12486 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12489 if (PL_bufend > (char*)s) {
12493 filter_add(utf16rev_textfilter, NULL);
12494 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12495 utf16_to_utf8_reversed(s, news,
12496 PL_bufend - (char*)s - 1,
12498 sv_setpvn(PL_linestr, (const char*)news, newlen);
12500 s = (U8*)SvPVX(PL_linestr);
12501 Copy(news, s, newlen, U8);
12505 SvUTF8_on(PL_linestr);
12506 s = (U8*)SvPVX(PL_linestr);
12508 /* FIXME - is this a general bug fix? */
12511 PL_bufend = SvPVX(PL_linestr) + newlen;
12514 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12519 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12520 #ifndef PERL_NO_UTF16_FILTER
12521 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12524 if (PL_bufend > (char *)s) {
12528 filter_add(utf16_textfilter, NULL);
12529 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12530 utf16_to_utf8(s, news,
12531 PL_bufend - (char*)s,
12533 sv_setpvn(PL_linestr, (const char*)news, newlen);
12535 SvUTF8_on(PL_linestr);
12536 s = (U8*)SvPVX(PL_linestr);
12537 PL_bufend = SvPVX(PL_linestr) + newlen;
12540 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12545 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12546 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12547 s += 3; /* UTF-8 */
12553 if (s[2] == 0xFE && s[3] == 0xFF) {
12554 /* UTF-32 big-endian */
12555 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12558 else if (s[2] == 0 && s[3] != 0) {
12561 * are a good indicator of UTF-16BE. */
12562 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12568 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12569 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12570 s += 4; /* UTF-8 */
12576 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12579 * are a good indicator of UTF-16LE. */
12580 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12589 * Restore a source filter.
12593 restore_rsfp(pTHX_ void *f)
12596 PerlIO * const fp = (PerlIO*)f;
12598 if (PL_rsfp == PerlIO_stdin())
12599 PerlIO_clearerr(PL_rsfp);
12600 else if (PL_rsfp && (PL_rsfp != fp))
12601 PerlIO_close(PL_rsfp);
12605 #ifndef PERL_NO_UTF16_FILTER
12607 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12610 const STRLEN old = SvCUR(sv);
12611 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12612 DEBUG_P(PerlIO_printf(Perl_debug_log,
12613 "utf16_textfilter(%p): %d %d (%d)\n",
12614 FPTR2DPTR(void *, utf16_textfilter),
12615 idx, maxlen, (int) count));
12619 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12620 Copy(SvPVX_const(sv), tmps, old, char);
12621 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12622 SvCUR(sv) - old, &newlen);
12623 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12625 DEBUG_P({sv_dump(sv);});
12630 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12633 const STRLEN old = SvCUR(sv);
12634 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12635 DEBUG_P(PerlIO_printf(Perl_debug_log,
12636 "utf16rev_textfilter(%p): %d %d (%d)\n",
12637 FPTR2DPTR(void *, utf16rev_textfilter),
12638 idx, maxlen, (int) count));
12642 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12643 Copy(SvPVX_const(sv), tmps, old, char);
12644 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12645 SvCUR(sv) - old, &newlen);
12646 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12648 DEBUG_P({ sv_dump(sv); });
12654 Returns a pointer to the next character after the parsed
12655 vstring, as well as updating the passed in sv.
12657 Function must be called like
12660 s = scan_vstring(s,sv);
12662 The sv should already be large enough to store the vstring
12663 passed in, for performance reasons.
12668 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12671 const char *pos = s;
12672 const char *start = s;
12673 if (*pos == 'v') pos++; /* get past 'v' */
12674 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12676 if ( *pos != '.') {
12677 /* this may not be a v-string if followed by => */
12678 const char *next = pos;
12679 while (next < PL_bufend && isSPACE(*next))
12681 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12682 /* return string not v-string */
12683 sv_setpvn(sv,(char *)s,pos-s);
12684 return (char *)pos;
12688 if (!isALPHA(*pos)) {
12689 U8 tmpbuf[UTF8_MAXBYTES+1];
12692 s++; /* get past 'v' */
12694 sv_setpvn(sv, "", 0);
12697 /* this is atoi() that tolerates underscores */
12700 const char *end = pos;
12702 while (--end >= s) {
12704 const UV orev = rev;
12705 rev += (*end - '0') * mult;
12707 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12708 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12709 "Integer overflow in decimal number");
12713 if (rev > 0x7FFFFFFF)
12714 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12716 /* Append native character for the rev point */
12717 tmpend = uvchr_to_utf8(tmpbuf, rev);
12718 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12719 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12721 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12727 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12731 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12739 * c-indentation-style: bsd
12740 * c-basic-offset: 4
12741 * indent-tabs-mode: t
12744 * ex: set ts=8 sts=4 sw=4 noet: