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 if (SvREADONLY(PL_linestr))
666 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
667 s = SvPV_const(PL_linestr, len);
668 if (!len || s[len-1] != ';') {
669 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
670 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
671 sv_catpvs(PL_linestr, "\n;");
673 SvTEMP_off(PL_linestr);
674 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
675 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
676 PL_last_lop = PL_last_uni = NULL;
682 * Finalizer for lexing operations. Must be called when the parser is
683 * done with the lexer.
690 PL_doextract = FALSE;
695 * This subroutine has nothing to do with tilting, whether at windmills
696 * or pinball tables. Its name is short for "increment line". It
697 * increments the current line number in CopLINE(PL_curcop) and checks
698 * to see whether the line starts with a comment of the form
699 * # line 500 "foo.pm"
700 * If so, it sets the current line number and file to the values in the comment.
704 S_incline(pTHX_ char *s)
712 CopLINE_inc(PL_curcop);
715 while (SPACE_OR_TAB(*s))
717 if (strnEQ(s, "line", 4))
721 if (SPACE_OR_TAB(*s))
725 while (SPACE_OR_TAB(*s))
733 while (SPACE_OR_TAB(*s))
735 if (*s == '"' && (t = strchr(s+1, '"'))) {
745 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
747 if (*e != '\n' && *e != '\0')
748 return; /* false alarm */
754 const char * const cf = CopFILE(PL_curcop);
755 STRLEN tmplen = cf ? strlen(cf) : 0;
756 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
757 /* must copy *{"::_<(eval N)[oldfilename:L]"}
758 * to *{"::_<newfilename"} */
759 char smallbuf[256], smallbuf2[256];
760 char *tmpbuf, *tmpbuf2;
762 STRLEN tmplen2 = strlen(s);
763 if (tmplen + 3 < sizeof smallbuf)
766 Newx(tmpbuf, tmplen + 3, char);
767 if (tmplen2 + 3 < sizeof smallbuf2)
770 Newx(tmpbuf2, tmplen2 + 3, char);
771 tmpbuf[0] = tmpbuf2[0] = '_';
772 tmpbuf[1] = tmpbuf2[1] = '<';
773 memcpy(tmpbuf + 2, cf, ++tmplen);
774 memcpy(tmpbuf2 + 2, s, ++tmplen2);
776 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
778 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
780 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
781 /* adjust ${"::_<newfilename"} to store the new file name */
782 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
783 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
784 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
786 if (tmpbuf != smallbuf) Safefree(tmpbuf);
787 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
790 CopFILE_free(PL_curcop);
791 CopFILE_set(PL_curcop, s);
794 CopLINE_set(PL_curcop, atoi(n)-1);
798 /* skip space before PL_thistoken */
801 S_skipspace0(pTHX_ register char *s)
808 PL_thiswhite = newSVpvs("");
809 sv_catsv(PL_thiswhite, PL_skipwhite);
810 sv_free(PL_skipwhite);
813 PL_realtokenstart = s - SvPVX(PL_linestr);
817 /* skip space after PL_thistoken */
820 S_skipspace1(pTHX_ register char *s)
822 const char *start = s;
823 I32 startoff = start - SvPVX(PL_linestr);
828 start = SvPVX(PL_linestr) + startoff;
829 if (!PL_thistoken && PL_realtokenstart >= 0) {
830 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
831 PL_thistoken = newSVpvn(tstart, start - tstart);
833 PL_realtokenstart = -1;
836 PL_nextwhite = newSVpvs("");
837 sv_catsv(PL_nextwhite, PL_skipwhite);
838 sv_free(PL_skipwhite);
845 S_skipspace2(pTHX_ register char *s, SV **svp)
848 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
849 const I32 startoff = s - SvPVX(PL_linestr);
852 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
853 if (!PL_madskills || !svp)
855 start = SvPVX(PL_linestr) + startoff;
856 if (!PL_thistoken && PL_realtokenstart >= 0) {
857 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
858 PL_thistoken = newSVpvn(tstart, start - tstart);
859 PL_realtokenstart = -1;
864 sv_setsv(*svp, PL_skipwhite);
865 sv_free(PL_skipwhite);
875 * Called to gobble the appropriate amount and type of whitespace.
876 * Skips comments as well.
880 S_skipspace(pTHX_ register char *s)
885 int startoff = s - SvPVX(PL_linestr);
888 sv_free(PL_skipwhite);
893 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
894 while (s < PL_bufend && SPACE_OR_TAB(*s))
904 SSize_t oldprevlen, oldoldprevlen;
905 SSize_t oldloplen = 0, oldunilen = 0;
906 while (s < PL_bufend && isSPACE(*s)) {
907 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
912 if (s < PL_bufend && *s == '#') {
913 while (s < PL_bufend && *s != '\n')
917 if (PL_in_eval && !PL_rsfp) {
924 /* only continue to recharge the buffer if we're at the end
925 * of the buffer, we're not reading from a source filter, and
926 * we're in normal lexing mode
928 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
929 PL_lex_state == LEX_FORMLINE)
936 /* try to recharge the buffer */
938 curoff = s - SvPVX(PL_linestr);
941 if ((s = filter_gets(PL_linestr, PL_rsfp,
942 (prevlen = SvCUR(PL_linestr)))) == NULL)
945 if (PL_madskills && curoff != startoff) {
947 PL_skipwhite = newSVpvs("");
948 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
952 /* mustn't throw out old stuff yet if madpropping */
953 SvCUR(PL_linestr) = curoff;
954 s = SvPVX(PL_linestr) + curoff;
956 if (curoff && s[-1] == '\n')
960 /* end of file. Add on the -p or -n magic */
961 /* XXX these shouldn't really be added here, can't set PL_faketokens */
965 ";}continue{print or die qq(-p destination: $!\\n);}");
968 ";}continue{print or die qq(-p destination: $!\\n);}");
970 PL_minus_n = PL_minus_p = 0;
972 else if (PL_minus_n) {
974 sv_catpvn(PL_linestr, ";}", 2);
976 sv_setpvn(PL_linestr, ";}", 2);
982 sv_catpvn(PL_linestr,";", 1);
984 sv_setpvn(PL_linestr,";", 1);
987 /* reset variables for next time we lex */
988 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
994 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
995 PL_last_lop = PL_last_uni = NULL;
997 /* Close the filehandle. Could be from -P preprocessor,
998 * STDIN, or a regular file. If we were reading code from
999 * STDIN (because the commandline held no -e or filename)
1000 * then we don't close it, we reset it so the code can
1001 * read from STDIN too.
1004 if (PL_preprocess && !PL_in_eval)
1005 (void)PerlProc_pclose(PL_rsfp);
1006 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1007 PerlIO_clearerr(PL_rsfp);
1009 (void)PerlIO_close(PL_rsfp);
1014 /* not at end of file, so we only read another line */
1015 /* make corresponding updates to old pointers, for yyerror() */
1016 oldprevlen = PL_oldbufptr - PL_bufend;
1017 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1019 oldunilen = PL_last_uni - PL_bufend;
1021 oldloplen = PL_last_lop - PL_bufend;
1022 PL_linestart = PL_bufptr = s + prevlen;
1023 PL_bufend = s + SvCUR(PL_linestr);
1025 PL_oldbufptr = s + oldprevlen;
1026 PL_oldoldbufptr = s + oldoldprevlen;
1028 PL_last_uni = s + oldunilen;
1030 PL_last_lop = s + oldloplen;
1033 /* debugger active and we're not compiling the debugger code,
1034 * so store the line into the debugger's array of lines
1036 if (PERLDB_LINE && PL_curstash != PL_debstash) {
1037 SV * const sv = newSV(0);
1039 sv_upgrade(sv, SVt_PVMG);
1040 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
1043 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
1051 PL_skipwhite = newSVpvs("");
1052 curoff = s - SvPVX(PL_linestr);
1053 if (curoff - startoff)
1054 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1063 * Check the unary operators to ensure there's no ambiguity in how they're
1064 * used. An ambiguous piece of code would be:
1066 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1067 * the +5 is its argument.
1077 if (PL_oldoldbufptr != PL_last_uni)
1079 while (isSPACE(*PL_last_uni))
1082 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1084 if ((t = strchr(s, '(')) && t < PL_bufptr)
1087 if (ckWARN_d(WARN_AMBIGUOUS)){
1088 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1089 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1090 (int)(s - PL_last_uni), PL_last_uni);
1095 * LOP : macro to build a list operator. Its behaviour has been replaced
1096 * with a subroutine, S_lop() for which LOP is just another name.
1099 #define LOP(f,x) return lop(f,x,s)
1103 * Build a list operator (or something that might be one). The rules:
1104 * - if we have a next token, then it's a list operator [why?]
1105 * - if the next thing is an opening paren, then it's a function
1106 * - else it's a list operator
1110 S_lop(pTHX_ I32 f, int x, char *s)
1117 PL_last_lop = PL_oldbufptr;
1118 PL_last_lop_op = (OPCODE)f;
1121 return REPORT(LSTOP);
1124 return REPORT(LSTOP);
1127 return REPORT(FUNC);
1130 return REPORT(FUNC);
1132 return REPORT(LSTOP);
1138 * Sets up for an eventual force_next(). start_force(0) basically does
1139 * an unshift, while start_force(-1) does a push. yylex removes items
1144 S_start_force(pTHX_ int where)
1148 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1149 where = PL_lasttoke;
1150 assert(PL_curforce < 0 || PL_curforce == where);
1151 if (PL_curforce != where) {
1152 for (i = PL_lasttoke; i > where; --i) {
1153 PL_nexttoke[i] = PL_nexttoke[i-1];
1157 if (PL_curforce < 0) /* in case of duplicate start_force() */
1158 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1159 PL_curforce = where;
1162 curmad('^', newSVpvs(""));
1163 CURMAD('_', PL_nextwhite);
1168 S_curmad(pTHX_ char slot, SV *sv)
1174 if (PL_curforce < 0)
1175 where = &PL_thismad;
1177 where = &PL_nexttoke[PL_curforce].next_mad;
1180 sv_setpvn(sv, "", 0);
1183 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1185 else if (PL_encoding) {
1186 sv_recode_to_utf8(sv, PL_encoding);
1191 /* keep a slot open for the head of the list? */
1192 if (slot != '_' && *where && (*where)->mad_key == '^') {
1193 (*where)->mad_key = slot;
1194 sv_free((*where)->mad_val);
1195 (*where)->mad_val = (void*)sv;
1198 addmad(newMADsv(slot, sv), where, 0);
1201 # define start_force(where) NOOP
1202 # define curmad(slot, sv) NOOP
1207 * When the lexer realizes it knows the next token (for instance,
1208 * it is reordering tokens for the parser) then it can call S_force_next
1209 * to know what token to return the next time the lexer is called. Caller
1210 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1211 * and possibly PL_expect to ensure the lexer handles the token correctly.
1215 S_force_next(pTHX_ I32 type)
1219 if (PL_curforce < 0)
1220 start_force(PL_lasttoke);
1221 PL_nexttoke[PL_curforce].next_type = type;
1222 if (PL_lex_state != LEX_KNOWNEXT)
1223 PL_lex_defer = PL_lex_state;
1224 PL_lex_state = LEX_KNOWNEXT;
1225 PL_lex_expect = PL_expect;
1228 PL_nexttype[PL_nexttoke] = type;
1230 if (PL_lex_state != LEX_KNOWNEXT) {
1231 PL_lex_defer = PL_lex_state;
1232 PL_lex_expect = PL_expect;
1233 PL_lex_state = LEX_KNOWNEXT;
1239 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1242 SV * const sv = newSVpvn(start,len);
1243 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1250 * When the lexer knows the next thing is a word (for instance, it has
1251 * just seen -> and it knows that the next char is a word char, then
1252 * it calls S_force_word to stick the next word into the PL_next lookahead.
1255 * char *start : buffer position (must be within PL_linestr)
1256 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
1257 * int check_keyword : if true, Perl checks to make sure the word isn't
1258 * a keyword (do this if the word is a label, e.g. goto FOO)
1259 * int allow_pack : if true, : characters will also be allowed (require,
1260 * use, etc. do this)
1261 * int allow_initial_tick : used by the "sub" lexer only.
1265 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1271 start = SKIPSPACE1(start);
1273 if (isIDFIRST_lazy_if(s,UTF) ||
1274 (allow_pack && *s == ':') ||
1275 (allow_initial_tick && *s == '\'') )
1277 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1278 if (check_keyword && keyword(PL_tokenbuf, len, 0))
1280 start_force(PL_curforce);
1282 curmad('X', newSVpvn(start,s-start));
1283 if (token == METHOD) {
1288 PL_expect = XOPERATOR;
1291 NEXTVAL_NEXTTOKE.opval
1292 = (OP*)newSVOP(OP_CONST,0,
1293 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1294 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1302 * Called when the lexer wants $foo *foo &foo etc, but the program
1303 * text only contains the "foo" portion. The first argument is a pointer
1304 * to the "foo", and the second argument is the type symbol to prefix.
1305 * Forces the next token to be a "WORD".
1306 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1310 S_force_ident(pTHX_ register const char *s, int kind)
1314 const STRLEN len = strlen(s);
1315 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1316 start_force(PL_curforce);
1317 NEXTVAL_NEXTTOKE.opval = o;
1320 o->op_private = OPpCONST_ENTERED;
1321 /* XXX see note in pp_entereval() for why we forgo typo
1322 warnings if the symbol must be introduced in an eval.
1324 gv_fetchpvn_flags(s, len,
1325 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1327 kind == '$' ? SVt_PV :
1328 kind == '@' ? SVt_PVAV :
1329 kind == '%' ? SVt_PVHV :
1337 Perl_str_to_version(pTHX_ SV *sv)
1342 const char *start = SvPV_const(sv,len);
1343 const char * const end = start + len;
1344 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1345 while (start < end) {
1349 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1354 retval += ((NV)n)/nshift;
1363 * Forces the next token to be a version number.
1364 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1365 * and if "guessing" is TRUE, then no new token is created (and the caller
1366 * must use an alternative parsing method).
1370 S_force_version(pTHX_ char *s, int guessing)
1376 I32 startoff = s - SvPVX(PL_linestr);
1385 while (isDIGIT(*d) || *d == '_' || *d == '.')
1389 start_force(PL_curforce);
1390 curmad('X', newSVpvn(s,d-s));
1393 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1395 s = scan_num(s, &yylval);
1396 version = yylval.opval;
1397 ver = cSVOPx(version)->op_sv;
1398 if (SvPOK(ver) && !SvNIOK(ver)) {
1399 SvUPGRADE(ver, SVt_PVNV);
1400 SvNV_set(ver, str_to_version(ver));
1401 SvNOK_on(ver); /* hint that it is a version */
1404 else if (guessing) {
1407 sv_free(PL_nextwhite); /* let next token collect whitespace */
1409 s = SvPVX(PL_linestr) + startoff;
1417 if (PL_madskills && !version) {
1418 sv_free(PL_nextwhite); /* let next token collect whitespace */
1420 s = SvPVX(PL_linestr) + startoff;
1423 /* NOTE: The parser sees the package name and the VERSION swapped */
1424 start_force(PL_curforce);
1425 NEXTVAL_NEXTTOKE.opval = version;
1433 * Tokenize a quoted string passed in as an SV. It finds the next
1434 * chunk, up to end of string or a backslash. It may make a new
1435 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1440 S_tokeq(pTHX_ SV *sv)
1444 register char *send;
1452 s = SvPV_force(sv, len);
1453 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1456 while (s < send && *s != '\\')
1461 if ( PL_hints & HINT_NEW_STRING ) {
1462 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1468 if (s + 1 < send && (s[1] == '\\'))
1469 s++; /* all that, just for this */
1474 SvCUR_set(sv, d - SvPVX_const(sv));
1476 if ( PL_hints & HINT_NEW_STRING )
1477 return new_constant(NULL, 0, "q", sv, pv, "q");
1482 * Now come three functions related to double-quote context,
1483 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1484 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1485 * interact with PL_lex_state, and create fake ( ... ) argument lists
1486 * to handle functions and concatenation.
1487 * They assume that whoever calls them will be setting up a fake
1488 * join call, because each subthing puts a ',' after it. This lets
1491 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1493 * (I'm not sure whether the spurious commas at the end of lcfirst's
1494 * arguments and join's arguments are created or not).
1499 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1501 * Pattern matching will set PL_lex_op to the pattern-matching op to
1502 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1504 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1506 * Everything else becomes a FUNC.
1508 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1509 * had an OP_CONST or OP_READLINE). This just sets us up for a
1510 * call to S_sublex_push().
1514 S_sublex_start(pTHX)
1517 register const I32 op_type = yylval.ival;
1519 if (op_type == OP_NULL) {
1520 yylval.opval = PL_lex_op;
1524 if (op_type == OP_CONST || op_type == OP_READLINE) {
1525 SV *sv = tokeq(PL_lex_stuff);
1527 if (SvTYPE(sv) == SVt_PVIV) {
1528 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1530 const char * const p = SvPV_const(sv, len);
1531 SV * const nsv = newSVpvn(p, len);
1537 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1538 PL_lex_stuff = NULL;
1539 /* Allow <FH> // "foo" */
1540 if (op_type == OP_READLINE)
1541 PL_expect = XTERMORDORDOR;
1544 else if (op_type == OP_BACKTICK && PL_lex_op) {
1545 /* readpipe() vas overriden */
1546 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1547 yylval.opval = PL_lex_op;
1549 PL_lex_stuff = NULL;
1553 PL_sublex_info.super_state = PL_lex_state;
1554 PL_sublex_info.sub_inwhat = op_type;
1555 PL_sublex_info.sub_op = PL_lex_op;
1556 PL_lex_state = LEX_INTERPPUSH;
1560 yylval.opval = PL_lex_op;
1570 * Create a new scope to save the lexing state. The scope will be
1571 * ended in S_sublex_done. Returns a '(', starting the function arguments
1572 * to the uc, lc, etc. found before.
1573 * Sets PL_lex_state to LEX_INTERPCONCAT.
1582 PL_lex_state = PL_sublex_info.super_state;
1583 SAVEI32(PL_lex_dojoin);
1584 SAVEI32(PL_lex_brackets);
1585 SAVEI32(PL_lex_casemods);
1586 SAVEI32(PL_lex_starts);
1587 SAVEI32(PL_lex_state);
1588 SAVEVPTR(PL_lex_inpat);
1589 SAVEI32(PL_lex_inwhat);
1590 SAVECOPLINE(PL_curcop);
1591 SAVEPPTR(PL_bufptr);
1592 SAVEPPTR(PL_bufend);
1593 SAVEPPTR(PL_oldbufptr);
1594 SAVEPPTR(PL_oldoldbufptr);
1595 SAVEPPTR(PL_last_lop);
1596 SAVEPPTR(PL_last_uni);
1597 SAVEPPTR(PL_linestart);
1598 SAVESPTR(PL_linestr);
1599 SAVEGENERICPV(PL_lex_brackstack);
1600 SAVEGENERICPV(PL_lex_casestack);
1602 PL_linestr = PL_lex_stuff;
1603 PL_lex_stuff = NULL;
1605 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1606 = SvPVX(PL_linestr);
1607 PL_bufend += SvCUR(PL_linestr);
1608 PL_last_lop = PL_last_uni = NULL;
1609 SAVEFREESV(PL_linestr);
1611 PL_lex_dojoin = FALSE;
1612 PL_lex_brackets = 0;
1613 Newx(PL_lex_brackstack, 120, char);
1614 Newx(PL_lex_casestack, 12, char);
1615 PL_lex_casemods = 0;
1616 *PL_lex_casestack = '\0';
1618 PL_lex_state = LEX_INTERPCONCAT;
1619 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1621 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1622 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1623 PL_lex_inpat = PL_sublex_info.sub_op;
1625 PL_lex_inpat = NULL;
1632 * Restores lexer state after a S_sublex_push.
1639 if (!PL_lex_starts++) {
1640 SV * const sv = newSVpvs("");
1641 if (SvUTF8(PL_linestr))
1643 PL_expect = XOPERATOR;
1644 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1648 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1649 PL_lex_state = LEX_INTERPCASEMOD;
1653 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1654 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1655 PL_linestr = PL_lex_repl;
1657 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1658 PL_bufend += SvCUR(PL_linestr);
1659 PL_last_lop = PL_last_uni = NULL;
1660 SAVEFREESV(PL_linestr);
1661 PL_lex_dojoin = FALSE;
1662 PL_lex_brackets = 0;
1663 PL_lex_casemods = 0;
1664 *PL_lex_casestack = '\0';
1666 if (SvEVALED(PL_lex_repl)) {
1667 PL_lex_state = LEX_INTERPNORMAL;
1669 /* we don't clear PL_lex_repl here, so that we can check later
1670 whether this is an evalled subst; that means we rely on the
1671 logic to ensure sublex_done() is called again only via the
1672 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1675 PL_lex_state = LEX_INTERPCONCAT;
1685 PL_endwhite = newSVpvs("");
1686 sv_catsv(PL_endwhite, PL_thiswhite);
1690 sv_setpvn(PL_thistoken,"",0);
1692 PL_realtokenstart = -1;
1696 PL_bufend = SvPVX(PL_linestr);
1697 PL_bufend += SvCUR(PL_linestr);
1698 PL_expect = XOPERATOR;
1699 PL_sublex_info.sub_inwhat = 0;
1707 Extracts a pattern, double-quoted string, or transliteration. This
1710 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
1711 processing a pattern (PL_lex_inpat is true), a transliteration
1712 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
1714 Returns a pointer to the character scanned up to. If this is
1715 advanced from the start pointer supplied (i.e. if anything was
1716 successfully parsed), will leave an OP for the substring scanned
1717 in yylval. Caller must intuit reason for not parsing further
1718 by looking at the next characters herself.
1722 double-quoted style: \r and \n
1723 regexp special ones: \D \s
1726 case and quoting: \U \Q \E
1727 stops on @ and $, but not for $ as tail anchor
1729 In transliterations:
1730 characters are VERY literal, except for - not at the start or end
1731 of the string, which indicates a range. If the range is in bytes,
1732 scan_const expands the range to the full set of intermediate
1733 characters. If the range is in utf8, the hyphen is replaced with
1734 a certain range mark which will be handled by pmtrans() in op.c.
1736 In double-quoted strings:
1738 double-quoted style: \r and \n
1740 deprecated backrefs: \1 (in substitution replacements)
1741 case and quoting: \U \Q \E
1744 scan_const does *not* construct ops to handle interpolated strings.
1745 It stops processing as soon as it finds an embedded $ or @ variable
1746 and leaves it to the caller to work out what's going on.
1748 embedded arrays (whether in pattern or not) could be:
1749 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1751 $ in double-quoted strings must be the symbol of an embedded scalar.
1753 $ in pattern could be $foo or could be tail anchor. Assumption:
1754 it's a tail anchor if $ is the last thing in the string, or if it's
1755 followed by one of "()| \r\n\t"
1757 \1 (backreferences) are turned into $1
1759 The structure of the code is
1760 while (there's a character to process) {
1761 handle transliteration ranges
1762 skip regexp comments /(?#comment)/ and codes /(?{code})/
1763 skip #-initiated comments in //x patterns
1764 check for embedded arrays
1765 check for embedded scalars
1767 leave intact backslashes from leaveit (below)
1768 deprecate \1 in substitution replacements
1769 handle string-changing backslashes \l \U \Q \E, etc.
1770 switch (what was escaped) {
1771 handle \- in a transliteration (becomes a literal -)
1772 handle \132 (octal characters)
1773 handle \x15 and \x{1234} (hex characters)
1774 handle \N{name} (named characters)
1775 handle \cV (control characters)
1776 handle printf-style backslashes (\f, \r, \n, etc)
1778 } (end if backslash)
1779 } (end while character to read)
1784 S_scan_const(pTHX_ char *start)
1787 register char *send = PL_bufend; /* end of the constant */
1788 SV *sv = newSV(send - start); /* sv for the constant */
1789 register char *s = start; /* start of the constant */
1790 register char *d = SvPVX(sv); /* destination for copies */
1791 bool dorange = FALSE; /* are we in a translit range? */
1792 bool didrange = FALSE; /* did we just finish a range? */
1793 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1794 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1797 UV literal_endpoint = 0;
1798 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
1801 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1802 /* If we are doing a trans and we know we want UTF8 set expectation */
1803 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1804 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1808 while (s < send || dorange) {
1809 /* get transliterations out of the way (they're most literal) */
1810 if (PL_lex_inwhat == OP_TRANS) {
1811 /* expand a range A-Z to the full set of characters. AIE! */
1813 I32 i; /* current expanded character */
1814 I32 min; /* first character in range */
1815 I32 max; /* last character in range */
1826 char * const c = (char*)utf8_hop((U8*)d, -1);
1830 *c = (char)UTF_TO_NATIVE(0xff);
1831 /* mark the range as done, and continue */
1837 i = d - SvPVX_const(sv); /* remember current offset */
1840 SvLEN(sv) + (has_utf8 ?
1841 (512 - UTF_CONTINUATION_MARK +
1844 /* How many two-byte within 0..255: 128 in UTF-8,
1845 * 96 in UTF-8-mod. */
1847 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1849 d = SvPVX(sv) + i; /* refresh d after realloc */
1853 for (j = 0; j <= 1; j++) {
1854 char * const c = (char*)utf8_hop((U8*)d, -1);
1855 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
1861 max = (U8)0xff; /* only to \xff */
1862 uvmax = uv; /* \x{100} to uvmax */
1864 d = c; /* eat endpoint chars */
1869 d -= 2; /* eat the first char and the - */
1870 min = (U8)*d; /* first char in range */
1871 max = (U8)d[1]; /* last char in range */
1878 "Invalid range \"%c-%c\" in transliteration operator",
1879 (char)min, (char)max);
1883 if (literal_endpoint == 2 &&
1884 ((isLOWER(min) && isLOWER(max)) ||
1885 (isUPPER(min) && isUPPER(max)))) {
1887 for (i = min; i <= max; i++)
1889 *d++ = NATIVE_TO_NEED(has_utf8,i);
1891 for (i = min; i <= max; i++)
1893 *d++ = NATIVE_TO_NEED(has_utf8,i);
1898 for (i = min; i <= max; i++)
1901 const U8 ch = (U8)NATIVE_TO_UTF(i);
1902 if (UNI_IS_INVARIANT(ch))
1905 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
1906 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
1915 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
1917 *d++ = (char)UTF_TO_NATIVE(0xff);
1919 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
1923 /* mark the range as done, and continue */
1927 literal_endpoint = 0;
1932 /* range begins (ignore - as first or last char) */
1933 else if (*s == '-' && s+1 < send && s != start) {
1935 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1942 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1952 literal_endpoint = 0;
1953 native_range = TRUE;
1958 /* if we get here, we're not doing a transliteration */
1960 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1961 except for the last char, which will be done separately. */
1962 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1964 while (s+1 < send && *s != ')')
1965 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1967 else if (s[2] == '{' /* This should match regcomp.c */
1968 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1971 char *regparse = s + (s[2] == '{' ? 3 : 4);
1974 while (count && (c = *regparse)) {
1975 if (c == '\\' && regparse[1])
1983 if (*regparse != ')')
1984 regparse--; /* Leave one char for continuation. */
1985 while (s < regparse)
1986 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1990 /* likewise skip #-initiated comments in //x patterns */
1991 else if (*s == '#' && PL_lex_inpat &&
1992 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1993 while (s+1 < send && *s != '\n')
1994 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1997 /* check for embedded arrays
1998 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2000 else if (*s == '@' && s[1]) {
2001 if (isALNUM_lazy_if(s+1,UTF))
2003 if (strchr(":'{$", s[1]))
2005 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2006 break; /* in regexp, neither @+ nor @- are interpolated */
2009 /* check for embedded scalars. only stop if we're sure it's a
2012 else if (*s == '$') {
2013 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
2015 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
2016 break; /* in regexp, $ might be tail anchor */
2019 /* End of else if chain - OP_TRANS rejoin rest */
2022 if (*s == '\\' && s+1 < send) {
2025 /* deprecate \1 in strings and substitution replacements */
2026 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2027 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2029 if (ckWARN(WARN_SYNTAX))
2030 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2035 /* string-change backslash escapes */
2036 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2040 /* skip any other backslash escapes in a pattern */
2041 else if (PL_lex_inpat) {
2042 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2043 goto default_action;
2046 /* if we get here, it's either a quoted -, or a digit */
2049 /* quoted - in transliterations */
2051 if (PL_lex_inwhat == OP_TRANS) {
2058 if ((isALPHA(*s) || isDIGIT(*s)) &&
2060 Perl_warner(aTHX_ packWARN(WARN_MISC),
2061 "Unrecognized escape \\%c passed through",
2063 /* default action is to copy the quoted character */
2064 goto default_action;
2067 /* \132 indicates an octal constant */
2068 case '0': case '1': case '2': case '3':
2069 case '4': case '5': case '6': case '7':
2073 uv = grok_oct(s, &len, &flags, NULL);
2076 goto NUM_ESCAPE_INSERT;
2078 /* \x24 indicates a hex constant */
2082 char* const e = strchr(s, '}');
2083 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2084 PERL_SCAN_DISALLOW_PREFIX;
2089 yyerror("Missing right brace on \\x{}");
2093 uv = grok_hex(s, &len, &flags, NULL);
2099 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2100 uv = grok_hex(s, &len, &flags, NULL);
2106 /* Insert oct or hex escaped character.
2107 * There will always enough room in sv since such
2108 * escapes will be longer than any UTF-8 sequence
2109 * they can end up as. */
2111 /* We need to map to chars to ASCII before doing the tests
2114 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2115 if (!has_utf8 && uv > 255) {
2116 /* Might need to recode whatever we have
2117 * accumulated so far if it contains any
2120 * (Can't we keep track of that and avoid
2121 * this rescan? --jhi)
2125 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2126 if (!NATIVE_IS_INVARIANT(*c)) {
2131 const STRLEN offset = d - SvPVX_const(sv);
2133 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2137 while (src >= (const U8 *)SvPVX_const(sv)) {
2138 if (!NATIVE_IS_INVARIANT(*src)) {
2139 const U8 ch = NATIVE_TO_ASCII(*src);
2140 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2141 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2151 if (has_utf8 || uv > 255) {
2152 d = (char*)uvchr_to_utf8((U8*)d, uv);
2154 if (PL_lex_inwhat == OP_TRANS &&
2155 PL_sublex_info.sub_op) {
2156 PL_sublex_info.sub_op->op_private |=
2157 (PL_lex_repl ? OPpTRANS_FROM_UTF
2161 if (uv > 255 && !dorange)
2162 native_range = FALSE;
2174 /* \N{LATIN SMALL LETTER A} is a named character */
2178 char* e = strchr(s, '}');
2185 yyerror("Missing right brace on \\N{}");
2189 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2191 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2192 PERL_SCAN_DISALLOW_PREFIX;
2195 uv = grok_hex(s, &len, &flags, NULL);
2196 if ( e > s && len != (STRLEN)(e - s) ) {
2200 goto NUM_ESCAPE_INSERT;
2202 res = newSVpvn(s + 1, e - s - 1);
2203 type = newSVpvn(s - 2,e - s + 3);
2204 res = new_constant( NULL, 0, "charnames",
2205 res, NULL, SvPVX(type) );
2208 sv_utf8_upgrade(res);
2209 str = SvPV_const(res,len);
2210 #ifdef EBCDIC_NEVER_MIND
2211 /* charnames uses pack U and that has been
2212 * recently changed to do the below uni->native
2213 * mapping, so this would be redundant (and wrong,
2214 * the code point would be doubly converted).
2215 * But leave this in just in case the pack U change
2216 * gets revoked, but the semantics is still
2217 * desireable for charnames. --jhi */
2219 UV uv = utf8_to_uvchr((const U8*)str, 0);
2222 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2224 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2225 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2226 str = SvPV_const(res, len);
2230 if (!has_utf8 && SvUTF8(res)) {
2231 const char * const ostart = SvPVX_const(sv);
2232 SvCUR_set(sv, d - ostart);
2235 sv_utf8_upgrade(sv);
2236 /* this just broke our allocation above... */
2237 SvGROW(sv, (STRLEN)(send - start));
2238 d = SvPVX(sv) + SvCUR(sv);
2241 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2242 const char * const odest = SvPVX_const(sv);
2244 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2245 d = SvPVX(sv) + (d - odest);
2249 native_range = FALSE; /* \N{} is guessed to be Unicode */
2251 Copy(str, d, len, char);
2258 yyerror("Missing braces on \\N{}");
2261 /* \c is a control character */
2270 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2273 yyerror("Missing control char name in \\c");
2277 /* printf-style backslashes, formfeeds, newlines, etc */
2279 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2282 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2285 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2288 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2291 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2294 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2297 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2303 } /* end if (backslash) */
2310 /* If we started with encoded form, or already know we want it
2311 and then encode the next character */
2312 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2314 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2315 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2318 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2319 const STRLEN off = d - SvPVX_const(sv);
2320 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2322 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2325 if (uv > 255 && !dorange)
2326 native_range = FALSE;
2330 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2332 } /* while loop to process each character */
2334 /* terminate the string and set up the sv */
2336 SvCUR_set(sv, d - SvPVX_const(sv));
2337 if (SvCUR(sv) >= SvLEN(sv))
2338 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2341 if (PL_encoding && !has_utf8) {
2342 sv_recode_to_utf8(sv, PL_encoding);
2348 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2349 PL_sublex_info.sub_op->op_private |=
2350 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2354 /* shrink the sv if we allocated more than we used */
2355 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2356 SvPV_shrink_to_cur(sv);
2359 /* return the substring (via yylval) only if we parsed anything */
2360 if (s > PL_bufptr) {
2361 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2362 sv = new_constant(start, s - start,
2363 (const char *)(PL_lex_inpat ? "qr" : "q"),
2366 (( PL_lex_inwhat == OP_TRANS
2368 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2371 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2378 * Returns TRUE if there's more to the expression (e.g., a subscript),
2381 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2383 * ->[ and ->{ return TRUE
2384 * { and [ outside a pattern are always subscripts, so return TRUE
2385 * if we're outside a pattern and it's not { or [, then return FALSE
2386 * if we're in a pattern and the first char is a {
2387 * {4,5} (any digits around the comma) returns FALSE
2388 * if we're in a pattern and the first char is a [
2390 * [SOMETHING] has a funky algorithm to decide whether it's a
2391 * character class or not. It has to deal with things like
2392 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2393 * anything else returns TRUE
2396 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2399 S_intuit_more(pTHX_ register char *s)
2402 if (PL_lex_brackets)
2404 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2406 if (*s != '{' && *s != '[')
2411 /* In a pattern, so maybe we have {n,m}. */
2428 /* On the other hand, maybe we have a character class */
2431 if (*s == ']' || *s == '^')
2434 /* this is terrifying, and it works */
2435 int weight = 2; /* let's weigh the evidence */
2437 unsigned char un_char = 255, last_un_char;
2438 const char * const send = strchr(s,']');
2439 char tmpbuf[sizeof PL_tokenbuf * 4];
2441 if (!send) /* has to be an expression */
2444 Zero(seen,256,char);
2447 else if (isDIGIT(*s)) {
2449 if (isDIGIT(s[1]) && s[2] == ']')
2455 for (; s < send; s++) {
2456 last_un_char = un_char;
2457 un_char = (unsigned char)*s;
2462 weight -= seen[un_char] * 10;
2463 if (isALNUM_lazy_if(s+1,UTF)) {
2465 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2466 len = (int)strlen(tmpbuf);
2467 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2472 else if (*s == '$' && s[1] &&
2473 strchr("[#!%*<>()-=",s[1])) {
2474 if (/*{*/ strchr("])} =",s[2]))
2483 if (strchr("wds]",s[1]))
2485 else if (seen[(U8)'\''] || seen[(U8)'"'])
2487 else if (strchr("rnftbxcav",s[1]))
2489 else if (isDIGIT(s[1])) {
2491 while (s[1] && isDIGIT(s[1]))
2501 if (strchr("aA01! ",last_un_char))
2503 if (strchr("zZ79~",s[1]))
2505 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2506 weight -= 5; /* cope with negative subscript */
2509 if (!isALNUM(last_un_char)
2510 && !(last_un_char == '$' || last_un_char == '@'
2511 || last_un_char == '&')
2512 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2517 if (keyword(tmpbuf, d - tmpbuf, 0))
2520 if (un_char == last_un_char + 1)
2522 weight -= seen[un_char];
2527 if (weight >= 0) /* probably a character class */
2537 * Does all the checking to disambiguate
2539 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2540 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2542 * First argument is the stuff after the first token, e.g. "bar".
2544 * Not a method if bar is a filehandle.
2545 * Not a method if foo is a subroutine prototyped to take a filehandle.
2546 * Not a method if it's really "Foo $bar"
2547 * Method if it's "foo $bar"
2548 * Not a method if it's really "print foo $bar"
2549 * Method if it's really "foo package::" (interpreted as package->foo)
2550 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2551 * Not a method if bar is a filehandle or package, but is quoted with
2556 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2559 char *s = start + (*start == '$');
2560 char tmpbuf[sizeof PL_tokenbuf];
2568 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2572 const char *proto = SvPVX_const(cv);
2583 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2584 /* start is the beginning of the possible filehandle/object,
2585 * and s is the end of it
2586 * tmpbuf is a copy of it
2589 if (*start == '$') {
2590 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2593 len = start - SvPVX(PL_linestr);
2597 start = SvPVX(PL_linestr) + len;
2601 return *s == '(' ? FUNCMETH : METHOD;
2603 if (!keyword(tmpbuf, len, 0)) {
2604 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2608 soff = s - SvPVX(PL_linestr);
2612 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2613 if (indirgv && GvCVu(indirgv))
2615 /* filehandle or package name makes it a method */
2616 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2618 soff = s - SvPVX(PL_linestr);
2621 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2622 return 0; /* no assumptions -- "=>" quotes bearword */
2624 start_force(PL_curforce);
2625 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2626 newSVpvn(tmpbuf,len));
2627 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2629 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2634 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2636 return *s == '(' ? FUNCMETH : METHOD;
2644 * Return a string of Perl code to load the debugger. If PERL5DB
2645 * is set, it will return the contents of that, otherwise a
2646 * compile-time require of perl5db.pl.
2654 const char * const pdb = PerlEnv_getenv("PERL5DB");
2658 SETERRNO(0,SS_NORMAL);
2659 return "BEGIN { require 'perl5db.pl' }";
2665 /* Encoded script support. filter_add() effectively inserts a
2666 * 'pre-processing' function into the current source input stream.
2667 * Note that the filter function only applies to the current source file
2668 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2670 * The datasv parameter (which may be NULL) can be used to pass
2671 * private data to this instance of the filter. The filter function
2672 * can recover the SV using the FILTER_DATA macro and use it to
2673 * store private buffers and state information.
2675 * The supplied datasv parameter is upgraded to a PVIO type
2676 * and the IoDIRP/IoANY field is used to store the function pointer,
2677 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2678 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2679 * private use must be set using malloc'd pointers.
2683 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2689 if (!PL_rsfp_filters)
2690 PL_rsfp_filters = newAV();
2693 SvUPGRADE(datasv, SVt_PVIO);
2694 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2695 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2696 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2697 FPTR2DPTR(void *, IoANY(datasv)),
2698 SvPV_nolen(datasv)));
2699 av_unshift(PL_rsfp_filters, 1);
2700 av_store(PL_rsfp_filters, 0, datasv) ;
2705 /* Delete most recently added instance of this filter function. */
2707 Perl_filter_del(pTHX_ filter_t funcp)
2713 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2714 FPTR2DPTR(void*, funcp)));
2716 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2718 /* if filter is on top of stack (usual case) just pop it off */
2719 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2720 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2721 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2722 IoANY(datasv) = (void *)NULL;
2723 sv_free(av_pop(PL_rsfp_filters));
2727 /* we need to search for the correct entry and clear it */
2728 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2732 /* Invoke the idxth filter function for the current rsfp. */
2733 /* maxlen 0 = read one text line */
2735 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2740 /* This API is bad. It should have been using unsigned int for maxlen.
2741 Not sure if we want to change the API, but if not we should sanity
2742 check the value here. */
2743 const unsigned int correct_length
2752 if (!PL_rsfp_filters)
2754 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2755 /* Provide a default input filter to make life easy. */
2756 /* Note that we append to the line. This is handy. */
2757 DEBUG_P(PerlIO_printf(Perl_debug_log,
2758 "filter_read %d: from rsfp\n", idx));
2759 if (correct_length) {
2762 const int old_len = SvCUR(buf_sv);
2764 /* ensure buf_sv is large enough */
2765 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2766 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2767 correct_length)) <= 0) {
2768 if (PerlIO_error(PL_rsfp))
2769 return -1; /* error */
2771 return 0 ; /* end of file */
2773 SvCUR_set(buf_sv, old_len + len) ;
2776 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2777 if (PerlIO_error(PL_rsfp))
2778 return -1; /* error */
2780 return 0 ; /* end of file */
2783 return SvCUR(buf_sv);
2785 /* Skip this filter slot if filter has been deleted */
2786 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2787 DEBUG_P(PerlIO_printf(Perl_debug_log,
2788 "filter_read %d: skipped (filter deleted)\n",
2790 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2792 /* Get function pointer hidden within datasv */
2793 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2794 DEBUG_P(PerlIO_printf(Perl_debug_log,
2795 "filter_read %d: via function %p (%s)\n",
2796 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2797 /* Call function. The function is expected to */
2798 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2799 /* Return: <0:error, =0:eof, >0:not eof */
2800 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2804 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2807 #ifdef PERL_CR_FILTER
2808 if (!PL_rsfp_filters) {
2809 filter_add(S_cr_textfilter,NULL);
2812 if (PL_rsfp_filters) {
2814 SvCUR_set(sv, 0); /* start with empty line */
2815 if (FILTER_READ(0, sv, 0) > 0)
2816 return ( SvPVX(sv) ) ;
2821 return (sv_gets(sv, fp, append));
2825 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2830 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2834 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2835 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2837 return GvHV(gv); /* Foo:: */
2840 /* use constant CLASS => 'MyClass' */
2841 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2842 if (gv && GvCV(gv)) {
2843 SV * const sv = cv_const_sv(GvCV(gv));
2845 pkgname = SvPV_nolen_const(sv);
2848 return gv_stashpv(pkgname, FALSE);
2852 * S_readpipe_override
2853 * Check whether readpipe() is overriden, and generates the appropriate
2854 * optree, provided sublex_start() is called afterwards.
2857 S_readpipe_override()
2860 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
2861 yylval.ival = OP_BACKTICK;
2863 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
2865 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
2866 && (gv_readpipe = *gvp) != (GV*)&PL_sv_undef
2867 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
2869 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
2870 append_elem(OP_LIST,
2871 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
2872 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
2882 * The intent of this yylex wrapper is to minimize the changes to the
2883 * tokener when we aren't interested in collecting madprops. It remains
2884 * to be seen how successful this strategy will be...
2891 char *s = PL_bufptr;
2893 /* make sure PL_thiswhite is initialized */
2897 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2898 if (PL_pending_ident)
2899 return S_pending_ident(aTHX);
2901 /* previous token ate up our whitespace? */
2902 if (!PL_lasttoke && PL_nextwhite) {
2903 PL_thiswhite = PL_nextwhite;
2907 /* isolate the token, and figure out where it is without whitespace */
2908 PL_realtokenstart = -1;
2912 assert(PL_curforce < 0);
2914 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2915 if (!PL_thistoken) {
2916 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2917 PL_thistoken = newSVpvs("");
2919 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2920 PL_thistoken = newSVpvn(tstart, s - tstart);
2923 if (PL_thismad) /* install head */
2924 CURMAD('X', PL_thistoken);
2927 /* last whitespace of a sublex? */
2928 if (optype == ')' && PL_endwhite) {
2929 CURMAD('X', PL_endwhite);
2934 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
2935 if (!PL_thiswhite && !PL_endwhite && !optype) {
2936 sv_free(PL_thistoken);
2941 /* put off final whitespace till peg */
2942 if (optype == ';' && !PL_rsfp) {
2943 PL_nextwhite = PL_thiswhite;
2946 else if (PL_thisopen) {
2947 CURMAD('q', PL_thisopen);
2949 sv_free(PL_thistoken);
2953 /* Store actual token text as madprop X */
2954 CURMAD('X', PL_thistoken);
2958 /* add preceding whitespace as madprop _ */
2959 CURMAD('_', PL_thiswhite);
2963 /* add quoted material as madprop = */
2964 CURMAD('=', PL_thisstuff);
2968 /* add terminating quote as madprop Q */
2969 CURMAD('Q', PL_thisclose);
2973 /* special processing based on optype */
2977 /* opval doesn't need a TOKEN since it can already store mp */
2988 append_madprops(PL_thismad, yylval.opval, 0);
2996 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3005 /* remember any fake bracket that lexer is about to discard */
3006 if (PL_lex_brackets == 1 &&
3007 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3010 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3013 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3014 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3017 break; /* don't bother looking for trailing comment */
3026 /* attach a trailing comment to its statement instead of next token */
3030 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3032 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3034 if (*s == '\n' || *s == '#') {
3035 while (s < PL_bufend && *s != '\n')
3039 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3040 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3057 /* Create new token struct. Note: opvals return early above. */
3058 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
3065 S_tokenize_use(pTHX_ int is_use, char *s) {
3067 if (PL_expect != XSTATE)
3068 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3069 is_use ? "use" : "no"));
3071 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3072 s = force_version(s, TRUE);
3073 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3074 start_force(PL_curforce);
3075 NEXTVAL_NEXTTOKE.opval = NULL;
3078 else if (*s == 'v') {
3079 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3080 s = force_version(s, FALSE);
3084 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3085 s = force_version(s, FALSE);
3087 yylval.ival = is_use;
3091 static const char* const exp_name[] =
3092 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3093 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3100 Works out what to call the token just pulled out of the input
3101 stream. The yacc parser takes care of taking the ops we return and
3102 stitching them into a tree.
3108 if read an identifier
3109 if we're in a my declaration
3110 croak if they tried to say my($foo::bar)
3111 build the ops for a my() declaration
3112 if it's an access to a my() variable
3113 are we in a sort block?
3114 croak if my($a); $a <=> $b
3115 build ops for access to a my() variable
3116 if in a dq string, and they've said @foo and we can't find @foo
3118 build ops for a bareword
3119 if we already built the token before, use it.
3124 #pragma segment Perl_yylex
3130 register char *s = PL_bufptr;
3135 /* orig_keyword, gvp, and gv are initialized here because
3136 * jump to the label just_a_word_zero can bypass their
3137 * initialization later. */
3138 I32 orig_keyword = 0;
3143 SV* tmp = newSVpvs("");
3144 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3145 (IV)CopLINE(PL_curcop),
3146 lex_state_names[PL_lex_state],
3147 exp_name[PL_expect],
3148 pv_display(tmp, s, strlen(s), 0, 60));
3151 /* check if there's an identifier for us to look at */
3152 if (PL_pending_ident)
3153 return REPORT(S_pending_ident(aTHX));
3155 /* no identifier pending identification */
3157 switch (PL_lex_state) {
3159 case LEX_NORMAL: /* Some compilers will produce faster */
3160 case LEX_INTERPNORMAL: /* code if we comment these out. */
3164 /* when we've already built the next token, just pull it out of the queue */
3168 yylval = PL_nexttoke[PL_lasttoke].next_val;
3170 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3171 PL_nexttoke[PL_lasttoke].next_mad = 0;
3172 if (PL_thismad && PL_thismad->mad_key == '_') {
3173 PL_thiswhite = (SV*)PL_thismad->mad_val;
3174 PL_thismad->mad_val = 0;
3175 mad_free(PL_thismad);
3180 PL_lex_state = PL_lex_defer;
3181 PL_expect = PL_lex_expect;
3182 PL_lex_defer = LEX_NORMAL;
3183 if (!PL_nexttoke[PL_lasttoke].next_type)
3188 yylval = PL_nextval[PL_nexttoke];
3190 PL_lex_state = PL_lex_defer;
3191 PL_expect = PL_lex_expect;
3192 PL_lex_defer = LEX_NORMAL;
3196 /* FIXME - can these be merged? */
3197 return(PL_nexttoke[PL_lasttoke].next_type);
3199 return REPORT(PL_nexttype[PL_nexttoke]);
3202 /* interpolated case modifiers like \L \U, including \Q and \E.
3203 when we get here, PL_bufptr is at the \
3205 case LEX_INTERPCASEMOD:
3207 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3208 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3210 /* handle \E or end of string */
3211 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3213 if (PL_lex_casemods) {
3214 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3215 PL_lex_casestack[PL_lex_casemods] = '\0';
3217 if (PL_bufptr != PL_bufend
3218 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3220 PL_lex_state = LEX_INTERPCONCAT;
3223 PL_thistoken = newSVpvs("\\E");
3229 while (PL_bufptr != PL_bufend &&
3230 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3232 PL_thiswhite = newSVpvs("");
3233 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3237 if (PL_bufptr != PL_bufend)
3240 PL_lex_state = LEX_INTERPCONCAT;
3244 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3245 "### Saw case modifier\n"); });
3247 if (s[1] == '\\' && s[2] == 'E') {
3250 PL_thiswhite = newSVpvs("");
3251 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3254 PL_lex_state = LEX_INTERPCONCAT;
3259 if (!PL_madskills) /* when just compiling don't need correct */
3260 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3261 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3262 if ((*s == 'L' || *s == 'U') &&
3263 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3264 PL_lex_casestack[--PL_lex_casemods] = '\0';
3267 if (PL_lex_casemods > 10)
3268 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3269 PL_lex_casestack[PL_lex_casemods++] = *s;
3270 PL_lex_casestack[PL_lex_casemods] = '\0';
3271 PL_lex_state = LEX_INTERPCONCAT;
3272 start_force(PL_curforce);
3273 NEXTVAL_NEXTTOKE.ival = 0;
3275 start_force(PL_curforce);
3277 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3279 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3281 NEXTVAL_NEXTTOKE.ival = OP_LC;
3283 NEXTVAL_NEXTTOKE.ival = OP_UC;
3285 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3287 Perl_croak(aTHX_ "panic: yylex");
3289 SV* const tmpsv = newSVpvs("");
3290 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3296 if (PL_lex_starts) {
3302 sv_free(PL_thistoken);
3303 PL_thistoken = newSVpvs("");
3306 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3307 if (PL_lex_casemods == 1 && PL_lex_inpat)
3316 case LEX_INTERPPUSH:
3317 return REPORT(sublex_push());
3319 case LEX_INTERPSTART:
3320 if (PL_bufptr == PL_bufend)
3321 return REPORT(sublex_done());
3322 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3323 "### Interpolated variable\n"); });
3325 PL_lex_dojoin = (*PL_bufptr == '@');
3326 PL_lex_state = LEX_INTERPNORMAL;
3327 if (PL_lex_dojoin) {
3328 start_force(PL_curforce);
3329 NEXTVAL_NEXTTOKE.ival = 0;
3331 start_force(PL_curforce);
3332 force_ident("\"", '$');
3333 start_force(PL_curforce);
3334 NEXTVAL_NEXTTOKE.ival = 0;
3336 start_force(PL_curforce);
3337 NEXTVAL_NEXTTOKE.ival = 0;
3339 start_force(PL_curforce);
3340 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3343 if (PL_lex_starts++) {
3348 sv_free(PL_thistoken);
3349 PL_thistoken = newSVpvs("");
3352 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3353 if (!PL_lex_casemods && PL_lex_inpat)
3360 case LEX_INTERPENDMAYBE:
3361 if (intuit_more(PL_bufptr)) {
3362 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3368 if (PL_lex_dojoin) {
3369 PL_lex_dojoin = FALSE;
3370 PL_lex_state = LEX_INTERPCONCAT;
3374 sv_free(PL_thistoken);
3375 PL_thistoken = newSVpvs("");
3380 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3381 && SvEVALED(PL_lex_repl))
3383 if (PL_bufptr != PL_bufend)
3384 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3388 case LEX_INTERPCONCAT:
3390 if (PL_lex_brackets)
3391 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3393 if (PL_bufptr == PL_bufend)
3394 return REPORT(sublex_done());
3396 if (SvIVX(PL_linestr) == '\'') {
3397 SV *sv = newSVsv(PL_linestr);
3400 else if ( PL_hints & HINT_NEW_RE )
3401 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3402 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3406 s = scan_const(PL_bufptr);
3408 PL_lex_state = LEX_INTERPCASEMOD;
3410 PL_lex_state = LEX_INTERPSTART;
3413 if (s != PL_bufptr) {
3414 start_force(PL_curforce);
3416 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3418 NEXTVAL_NEXTTOKE = yylval;
3421 if (PL_lex_starts++) {
3425 sv_free(PL_thistoken);
3426 PL_thistoken = newSVpvs("");
3429 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3430 if (!PL_lex_casemods && PL_lex_inpat)
3443 PL_lex_state = LEX_NORMAL;
3444 s = scan_formline(PL_bufptr);
3445 if (!PL_lex_formbrack)
3451 PL_oldoldbufptr = PL_oldbufptr;
3457 sv_free(PL_thistoken);
3460 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3464 if (isIDFIRST_lazy_if(s,UTF))
3466 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3469 goto fake_eof; /* emulate EOF on ^D or ^Z */
3478 if (PL_lex_brackets) {
3479 yyerror((const char *)
3481 ? "Format not terminated"
3482 : "Missing right curly or square bracket"));
3484 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3485 "### Tokener got EOF\n");
3489 if (s++ < PL_bufend)
3490 goto retry; /* ignore stray nulls */
3493 if (!PL_in_eval && !PL_preambled) {
3494 PL_preambled = TRUE;
3499 sv_setpv(PL_linestr,incl_perldb());
3500 if (SvCUR(PL_linestr))
3501 sv_catpvs(PL_linestr,";");
3503 while(AvFILLp(PL_preambleav) >= 0) {
3504 SV *tmpsv = av_shift(PL_preambleav);
3505 sv_catsv(PL_linestr, tmpsv);
3506 sv_catpvs(PL_linestr, ";");
3509 sv_free((SV*)PL_preambleav);
3510 PL_preambleav = NULL;
3512 if (PL_minus_n || PL_minus_p) {
3513 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3515 sv_catpvs(PL_linestr,"chomp;");
3518 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3519 || *PL_splitstr == '"')
3520 && strchr(PL_splitstr + 1, *PL_splitstr))
3521 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3523 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3524 bytes can be used as quoting characters. :-) */
3525 const char *splits = PL_splitstr;
3526 sv_catpvs(PL_linestr, "our @F=split(q\0");
3529 if (*splits == '\\')
3530 sv_catpvn(PL_linestr, splits, 1);
3531 sv_catpvn(PL_linestr, splits, 1);
3532 } while (*splits++);
3533 /* This loop will embed the trailing NUL of
3534 PL_linestr as the last thing it does before
3536 sv_catpvs(PL_linestr, ");");
3540 sv_catpvs(PL_linestr,"our @F=split(' ');");
3544 sv_catpvs(PL_linestr,"use feature ':5.10';");
3545 sv_catpvs(PL_linestr, "\n");
3546 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3547 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3548 PL_last_lop = PL_last_uni = NULL;
3549 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3550 SV * const sv = newSV(0);
3552 sv_upgrade(sv, SVt_PVMG);
3553 sv_setsv(sv,PL_linestr);
3556 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3561 bof = PL_rsfp ? TRUE : FALSE;
3562 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3565 PL_realtokenstart = -1;
3568 if (PL_preprocess && !PL_in_eval)
3569 (void)PerlProc_pclose(PL_rsfp);
3570 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3571 PerlIO_clearerr(PL_rsfp);
3573 (void)PerlIO_close(PL_rsfp);
3575 PL_doextract = FALSE;
3577 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3582 sv_setpv(PL_linestr,
3585 ? ";}continue{print;}" : ";}"));
3586 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3587 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3588 PL_last_lop = PL_last_uni = NULL;
3589 PL_minus_n = PL_minus_p = 0;
3592 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3593 PL_last_lop = PL_last_uni = NULL;
3594 sv_setpvn(PL_linestr,"",0);
3595 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3597 /* If it looks like the start of a BOM or raw UTF-16,
3598 * check if it in fact is. */
3604 #ifdef PERLIO_IS_STDIO
3605 # ifdef __GNU_LIBRARY__
3606 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3607 # define FTELL_FOR_PIPE_IS_BROKEN
3611 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3612 # define FTELL_FOR_PIPE_IS_BROKEN
3617 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3618 /* This loses the possibility to detect the bof
3619 * situation on perl -P when the libc5 is being used.
3620 * Workaround? Maybe attach some extra state to PL_rsfp?
3623 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3625 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3628 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3629 s = swallow_bom((U8*)s);
3633 /* Incest with pod. */
3636 sv_catsv(PL_thiswhite, PL_linestr);
3638 if (*s == '=' && strnEQ(s, "=cut", 4)) {
3639 sv_setpvn(PL_linestr, "", 0);
3640 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3641 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3642 PL_last_lop = PL_last_uni = NULL;
3643 PL_doextract = FALSE;
3647 } while (PL_doextract);
3648 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3649 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3650 SV * const sv = newSV(0);
3652 sv_upgrade(sv, SVt_PVMG);
3653 sv_setsv(sv,PL_linestr);
3656 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3658 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3659 PL_last_lop = PL_last_uni = NULL;
3660 if (CopLINE(PL_curcop) == 1) {
3661 while (s < PL_bufend && isSPACE(*s))
3663 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3667 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3671 if (*s == '#' && *(s+1) == '!')
3673 #ifdef ALTERNATE_SHEBANG
3675 static char const as[] = ALTERNATE_SHEBANG;
3676 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3677 d = s + (sizeof(as) - 1);
3679 #endif /* ALTERNATE_SHEBANG */
3688 while (*d && !isSPACE(*d))
3692 #ifdef ARG_ZERO_IS_SCRIPT
3693 if (ipathend > ipath) {
3695 * HP-UX (at least) sets argv[0] to the script name,
3696 * which makes $^X incorrect. And Digital UNIX and Linux,
3697 * at least, set argv[0] to the basename of the Perl
3698 * interpreter. So, having found "#!", we'll set it right.
3700 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3702 assert(SvPOK(x) || SvGMAGICAL(x));
3703 if (sv_eq(x, CopFILESV(PL_curcop))) {
3704 sv_setpvn(x, ipath, ipathend - ipath);
3710 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3711 const char * const lstart = SvPV_const(x,llen);
3713 bstart += blen - llen;
3714 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3715 sv_setpvn(x, ipath, ipathend - ipath);
3720 TAINT_NOT; /* $^X is always tainted, but that's OK */
3722 #endif /* ARG_ZERO_IS_SCRIPT */
3727 d = instr(s,"perl -");
3729 d = instr(s,"perl");
3731 /* avoid getting into infinite loops when shebang
3732 * line contains "Perl" rather than "perl" */
3734 for (d = ipathend-4; d >= ipath; --d) {
3735 if ((*d == 'p' || *d == 'P')
3736 && !ibcmp(d, "perl", 4))
3746 #ifdef ALTERNATE_SHEBANG
3748 * If the ALTERNATE_SHEBANG on this system starts with a
3749 * character that can be part of a Perl expression, then if
3750 * we see it but not "perl", we're probably looking at the
3751 * start of Perl code, not a request to hand off to some
3752 * other interpreter. Similarly, if "perl" is there, but
3753 * not in the first 'word' of the line, we assume the line
3754 * contains the start of the Perl program.
3756 if (d && *s != '#') {
3757 const char *c = ipath;
3758 while (*c && !strchr("; \t\r\n\f\v#", *c))
3761 d = NULL; /* "perl" not in first word; ignore */
3763 *s = '#'; /* Don't try to parse shebang line */
3765 #endif /* ALTERNATE_SHEBANG */
3766 #ifndef MACOS_TRADITIONAL
3771 !instr(s,"indir") &&
3772 instr(PL_origargv[0],"perl"))
3779 while (s < PL_bufend && isSPACE(*s))
3781 if (s < PL_bufend) {
3782 Newxz(newargv,PL_origargc+3,char*);
3784 while (s < PL_bufend && !isSPACE(*s))
3787 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3790 newargv = PL_origargv;
3793 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3795 Perl_croak(aTHX_ "Can't exec %s", ipath);
3799 while (*d && !isSPACE(*d))
3801 while (SPACE_OR_TAB(*d))
3805 const bool switches_done = PL_doswitches;
3806 const U32 oldpdb = PL_perldb;
3807 const bool oldn = PL_minus_n;
3808 const bool oldp = PL_minus_p;
3811 if (*d == 'M' || *d == 'm' || *d == 'C') {
3812 const char * const m = d;
3813 while (*d && !isSPACE(*d))
3815 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3818 d = moreswitches(d);
3820 if (PL_doswitches && !switches_done) {
3821 int argc = PL_origargc;
3822 char **argv = PL_origargv;
3825 } while (argc && argv[0][0] == '-' && argv[0][1]);
3826 init_argv_symbols(argc,argv);
3828 if ((PERLDB_LINE && !oldpdb) ||
3829 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3830 /* if we have already added "LINE: while (<>) {",
3831 we must not do it again */
3833 sv_setpvn(PL_linestr, "", 0);
3834 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3835 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3836 PL_last_lop = PL_last_uni = NULL;
3837 PL_preambled = FALSE;
3839 (void)gv_fetchfile(PL_origfilename);
3846 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3848 PL_lex_state = LEX_FORMLINE;
3853 #ifdef PERL_STRICT_CR
3854 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3856 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3858 case ' ': case '\t': case '\f': case 013:
3859 #ifdef MACOS_TRADITIONAL
3863 PL_realtokenstart = -1;
3872 PL_realtokenstart = -1;
3876 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3877 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3878 /* handle eval qq[#line 1 "foo"\n ...] */
3879 CopLINE_dec(PL_curcop);
3882 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3884 if (!PL_in_eval || PL_rsfp)
3889 while (d < PL_bufend && *d != '\n')
3893 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3894 Perl_croak(aTHX_ "panic: input overflow");
3897 PL_thiswhite = newSVpvn(s, d - s);
3902 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3904 PL_lex_state = LEX_FORMLINE;
3910 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3911 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3914 TOKEN(PEG); /* make sure any #! line is accessible */
3919 /* if (PL_madskills && PL_lex_formbrack) { */
3921 while (d < PL_bufend && *d != '\n')
3925 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3926 Perl_croak(aTHX_ "panic: input overflow");
3927 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3929 PL_thiswhite = newSVpvs("");
3930 if (CopLINE(PL_curcop) == 1) {
3931 sv_setpvn(PL_thiswhite, "", 0);
3934 sv_catpvn(PL_thiswhite, s, d - s);
3948 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3956 while (s < PL_bufend && SPACE_OR_TAB(*s))
3959 if (strnEQ(s,"=>",2)) {
3960 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3961 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
3962 OPERATOR('-'); /* unary minus */
3964 PL_last_uni = PL_oldbufptr;
3966 case 'r': ftst = OP_FTEREAD; break;
3967 case 'w': ftst = OP_FTEWRITE; break;
3968 case 'x': ftst = OP_FTEEXEC; break;
3969 case 'o': ftst = OP_FTEOWNED; break;
3970 case 'R': ftst = OP_FTRREAD; break;
3971 case 'W': ftst = OP_FTRWRITE; break;
3972 case 'X': ftst = OP_FTREXEC; break;
3973 case 'O': ftst = OP_FTROWNED; break;
3974 case 'e': ftst = OP_FTIS; break;
3975 case 'z': ftst = OP_FTZERO; break;
3976 case 's': ftst = OP_FTSIZE; break;
3977 case 'f': ftst = OP_FTFILE; break;
3978 case 'd': ftst = OP_FTDIR; break;
3979 case 'l': ftst = OP_FTLINK; break;
3980 case 'p': ftst = OP_FTPIPE; break;
3981 case 'S': ftst = OP_FTSOCK; break;
3982 case 'u': ftst = OP_FTSUID; break;
3983 case 'g': ftst = OP_FTSGID; break;
3984 case 'k': ftst = OP_FTSVTX; break;
3985 case 'b': ftst = OP_FTBLK; break;
3986 case 'c': ftst = OP_FTCHR; break;
3987 case 't': ftst = OP_FTTTY; break;
3988 case 'T': ftst = OP_FTTEXT; break;
3989 case 'B': ftst = OP_FTBINARY; break;
3990 case 'M': case 'A': case 'C':
3991 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
3993 case 'M': ftst = OP_FTMTIME; break;
3994 case 'A': ftst = OP_FTATIME; break;
3995 case 'C': ftst = OP_FTCTIME; break;
4003 PL_last_lop_op = (OPCODE)ftst;
4004 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4005 "### Saw file test %c\n", (int)tmp);
4010 /* Assume it was a minus followed by a one-letter named
4011 * subroutine call (or a -bareword), then. */
4012 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4013 "### '-%c' looked like a file test but was not\n",
4020 const char tmp = *s++;
4023 if (PL_expect == XOPERATOR)
4028 else if (*s == '>') {
4031 if (isIDFIRST_lazy_if(s,UTF)) {
4032 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4040 if (PL_expect == XOPERATOR)
4043 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4045 OPERATOR('-'); /* unary minus */
4051 const char tmp = *s++;
4054 if (PL_expect == XOPERATOR)
4059 if (PL_expect == XOPERATOR)
4062 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4069 if (PL_expect != XOPERATOR) {
4070 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4071 PL_expect = XOPERATOR;
4072 force_ident(PL_tokenbuf, '*');
4085 if (PL_expect == XOPERATOR) {
4089 PL_tokenbuf[0] = '%';
4090 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
4091 if (!PL_tokenbuf[1]) {
4094 PL_pending_ident = '%';
4105 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
4106 && FEATURE_IS_ENABLED("~~"))
4113 const char tmp = *s++;
4119 goto just_a_word_zero_gv;
4122 switch (PL_expect) {
4128 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4130 PL_bufptr = s; /* update in case we back off */
4136 PL_expect = XTERMBLOCK;
4139 stuffstart = s - SvPVX(PL_linestr) - 1;
4143 while (isIDFIRST_lazy_if(s,UTF)) {
4146 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4147 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4148 if (tmp < 0) tmp = -tmp;
4163 sv = newSVpvn(s, len);
4165 d = scan_str(d,TRUE,TRUE);
4167 /* MUST advance bufptr here to avoid bogus
4168 "at end of line" context messages from yyerror().
4170 PL_bufptr = s + len;
4171 yyerror("Unterminated attribute parameter in attribute list");
4175 return REPORT(0); /* EOF indicator */
4179 sv_catsv(sv, PL_lex_stuff);
4180 attrs = append_elem(OP_LIST, attrs,
4181 newSVOP(OP_CONST, 0, sv));
4182 SvREFCNT_dec(PL_lex_stuff);
4183 PL_lex_stuff = NULL;
4186 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4188 if (PL_in_my == KEY_our) {
4190 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4192 /* skip to avoid loading attributes.pm */
4194 deprecate(":unique");
4197 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4200 /* NOTE: any CV attrs applied here need to be part of
4201 the CVf_BUILTIN_ATTRS define in cv.h! */
4202 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4204 CvLVALUE_on(PL_compcv);
4206 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4208 CvLOCKED_on(PL_compcv);
4210 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4212 CvMETHOD_on(PL_compcv);
4214 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4216 CvASSERTION_on(PL_compcv);
4218 /* After we've set the flags, it could be argued that
4219 we don't need to do the attributes.pm-based setting
4220 process, and shouldn't bother appending recognized
4221 flags. To experiment with that, uncomment the
4222 following "else". (Note that's already been
4223 uncommented. That keeps the above-applied built-in
4224 attributes from being intercepted (and possibly
4225 rejected) by a package's attribute routines, but is
4226 justified by the performance win for the common case
4227 of applying only built-in attributes.) */
4229 attrs = append_elem(OP_LIST, attrs,
4230 newSVOP(OP_CONST, 0,
4234 if (*s == ':' && s[1] != ':')
4237 break; /* require real whitespace or :'s */
4238 /* XXX losing whitespace on sequential attributes here */
4242 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4243 if (*s != ';' && *s != '}' && *s != tmp
4244 && (tmp != '=' || *s != ')')) {
4245 const char q = ((*s == '\'') ? '"' : '\'');
4246 /* If here for an expression, and parsed no attrs, back
4248 if (tmp == '=' && !attrs) {
4252 /* MUST advance bufptr here to avoid bogus "at end of line"
4253 context messages from yyerror().
4256 yyerror( (const char *)
4258 ? Perl_form(aTHX_ "Invalid separator character "
4259 "%c%c%c in attribute list", q, *s, q)
4260 : "Unterminated attribute list" ) );
4268 start_force(PL_curforce);
4269 NEXTVAL_NEXTTOKE.opval = attrs;
4270 CURMAD('_', PL_nextwhite);
4275 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4276 (s - SvPVX(PL_linestr)) - stuffstart);
4284 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4285 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4293 const char tmp = *s++;
4298 const char tmp = *s++;
4306 if (PL_lex_brackets <= 0)
4307 yyerror("Unmatched right square bracket");
4310 if (PL_lex_state == LEX_INTERPNORMAL) {
4311 if (PL_lex_brackets == 0) {
4312 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4313 PL_lex_state = LEX_INTERPEND;
4320 if (PL_lex_brackets > 100) {
4321 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4323 switch (PL_expect) {
4325 if (PL_lex_formbrack) {
4329 if (PL_oldoldbufptr == PL_last_lop)
4330 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4332 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4333 OPERATOR(HASHBRACK);
4335 while (s < PL_bufend && SPACE_OR_TAB(*s))
4338 PL_tokenbuf[0] = '\0';
4339 if (d < PL_bufend && *d == '-') {
4340 PL_tokenbuf[0] = '-';
4342 while (d < PL_bufend && SPACE_OR_TAB(*d))
4345 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4346 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4348 while (d < PL_bufend && SPACE_OR_TAB(*d))
4351 const char minus = (PL_tokenbuf[0] == '-');
4352 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4360 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4365 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4370 if (PL_oldoldbufptr == PL_last_lop)
4371 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4373 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4376 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4378 /* This hack is to get the ${} in the message. */
4380 yyerror("syntax error");
4383 OPERATOR(HASHBRACK);
4385 /* This hack serves to disambiguate a pair of curlies
4386 * as being a block or an anon hash. Normally, expectation
4387 * determines that, but in cases where we're not in a
4388 * position to expect anything in particular (like inside
4389 * eval"") we have to resolve the ambiguity. This code
4390 * covers the case where the first term in the curlies is a
4391 * quoted string. Most other cases need to be explicitly
4392 * disambiguated by prepending a "+" before the opening
4393 * curly in order to force resolution as an anon hash.
4395 * XXX should probably propagate the outer expectation
4396 * into eval"" to rely less on this hack, but that could
4397 * potentially break current behavior of eval"".
4401 if (*s == '\'' || *s == '"' || *s == '`') {
4402 /* common case: get past first string, handling escapes */
4403 for (t++; t < PL_bufend && *t != *s;)
4404 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4408 else if (*s == 'q') {
4411 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4414 /* skip q//-like construct */
4416 char open, close, term;
4419 while (t < PL_bufend && isSPACE(*t))
4421 /* check for q => */
4422 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4423 OPERATOR(HASHBRACK);
4427 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4431 for (t++; t < PL_bufend; t++) {
4432 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4434 else if (*t == open)
4438 for (t++; t < PL_bufend; t++) {
4439 if (*t == '\\' && t+1 < PL_bufend)
4441 else if (*t == close && --brackets <= 0)
4443 else if (*t == open)
4450 /* skip plain q word */
4451 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4454 else if (isALNUM_lazy_if(t,UTF)) {
4456 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4459 while (t < PL_bufend && isSPACE(*t))
4461 /* if comma follows first term, call it an anon hash */
4462 /* XXX it could be a comma expression with loop modifiers */
4463 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4464 || (*t == '=' && t[1] == '>')))
4465 OPERATOR(HASHBRACK);
4466 if (PL_expect == XREF)
4469 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4475 yylval.ival = CopLINE(PL_curcop);
4476 if (isSPACE(*s) || *s == '#')
4477 PL_copline = NOLINE; /* invalidate current command line number */
4482 if (PL_lex_brackets <= 0)
4483 yyerror("Unmatched right curly bracket");
4485 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4486 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4487 PL_lex_formbrack = 0;
4488 if (PL_lex_state == LEX_INTERPNORMAL) {
4489 if (PL_lex_brackets == 0) {
4490 if (PL_expect & XFAKEBRACK) {
4491 PL_expect &= XENUMMASK;
4492 PL_lex_state = LEX_INTERPEND;
4497 PL_thiswhite = newSVpvs("");
4498 sv_catpvn(PL_thiswhite,"}",1);
4501 return yylex(); /* ignore fake brackets */
4503 if (*s == '-' && s[1] == '>')
4504 PL_lex_state = LEX_INTERPENDMAYBE;
4505 else if (*s != '[' && *s != '{')
4506 PL_lex_state = LEX_INTERPEND;
4509 if (PL_expect & XFAKEBRACK) {
4510 PL_expect &= XENUMMASK;
4512 return yylex(); /* ignore fake brackets */
4514 start_force(PL_curforce);
4516 curmad('X', newSVpvn(s-1,1));
4517 CURMAD('_', PL_thiswhite);
4522 PL_thistoken = newSVpvs("");
4530 if (PL_expect == XOPERATOR) {
4531 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4532 && isIDFIRST_lazy_if(s,UTF))
4534 CopLINE_dec(PL_curcop);
4535 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4536 CopLINE_inc(PL_curcop);
4541 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4543 PL_expect = XOPERATOR;
4544 force_ident(PL_tokenbuf, '&');
4548 yylval.ival = (OPpENTERSUB_AMPER<<8);
4560 const char tmp = *s++;
4567 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4568 && strchr("+-*/%.^&|<",tmp))
4569 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4570 "Reversed %c= operator",(int)tmp);
4572 if (PL_expect == XSTATE && isALPHA(tmp) &&
4573 (s == PL_linestart+1 || s[-2] == '\n') )
4575 if (PL_in_eval && !PL_rsfp) {
4580 if (strnEQ(s,"=cut",4)) {
4596 PL_thiswhite = newSVpvs("");
4597 sv_catpvn(PL_thiswhite, PL_linestart,
4598 PL_bufend - PL_linestart);
4602 PL_doextract = TRUE;
4606 if (PL_lex_brackets < PL_lex_formbrack) {
4608 #ifdef PERL_STRICT_CR
4609 while (SPACE_OR_TAB(*t))
4611 while (SPACE_OR_TAB(*t) || *t == '\r')
4614 if (*t == '\n' || *t == '#') {
4625 const char tmp = *s++;
4627 /* was this !=~ where !~ was meant?
4628 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4630 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4631 const char *t = s+1;
4633 while (t < PL_bufend && isSPACE(*t))
4636 if (*t == '/' || *t == '?' ||
4637 ((*t == 'm' || *t == 's' || *t == 'y')
4638 && !isALNUM(t[1])) ||
4639 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4640 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4641 "!=~ should be !~");
4651 if (PL_expect != XOPERATOR) {
4652 if (s[1] != '<' && !strchr(s,'>'))
4655 s = scan_heredoc(s);
4657 s = scan_inputsymbol(s);
4658 TERM(sublex_start());
4664 SHop(OP_LEFT_SHIFT);
4678 const char tmp = *s++;
4680 SHop(OP_RIGHT_SHIFT);
4681 else if (tmp == '=')
4690 if (PL_expect == XOPERATOR) {
4691 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4693 deprecate_old(commaless_variable_list);
4694 return REPORT(','); /* grandfather non-comma-format format */
4698 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4699 PL_tokenbuf[0] = '@';
4700 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4701 sizeof PL_tokenbuf - 1, FALSE);
4702 if (PL_expect == XOPERATOR)
4703 no_op("Array length", s);
4704 if (!PL_tokenbuf[1])
4706 PL_expect = XOPERATOR;
4707 PL_pending_ident = '#';
4711 PL_tokenbuf[0] = '$';
4712 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4713 sizeof PL_tokenbuf - 1, FALSE);
4714 if (PL_expect == XOPERATOR)
4716 if (!PL_tokenbuf[1]) {
4718 yyerror("Final $ should be \\$ or $name");
4722 /* This kludge not intended to be bulletproof. */
4723 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4724 yylval.opval = newSVOP(OP_CONST, 0,
4725 newSViv(CopARYBASE_get(&PL_compiling)));
4726 yylval.opval->op_private = OPpCONST_ARYBASE;
4732 const char tmp = *s;
4733 if (PL_lex_state == LEX_NORMAL)
4736 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4737 && intuit_more(s)) {
4739 PL_tokenbuf[0] = '@';
4740 if (ckWARN(WARN_SYNTAX)) {
4743 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4746 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4747 while (t < PL_bufend && *t != ']')
4749 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4750 "Multidimensional syntax %.*s not supported",
4751 (int)((t - PL_bufptr) + 1), PL_bufptr);
4755 else if (*s == '{') {
4757 PL_tokenbuf[0] = '%';
4758 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4759 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4761 char tmpbuf[sizeof PL_tokenbuf];
4764 } while (isSPACE(*t));
4765 if (isIDFIRST_lazy_if(t,UTF)) {
4767 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4771 if (*t == ';' && get_cv(tmpbuf, FALSE))
4772 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4773 "You need to quote \"%s\"",
4780 PL_expect = XOPERATOR;
4781 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4782 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4783 if (!islop || PL_last_lop_op == OP_GREPSTART)
4784 PL_expect = XOPERATOR;
4785 else if (strchr("$@\"'`q", *s))
4786 PL_expect = XTERM; /* e.g. print $fh "foo" */
4787 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4788 PL_expect = XTERM; /* e.g. print $fh &sub */
4789 else if (isIDFIRST_lazy_if(s,UTF)) {
4790 char tmpbuf[sizeof PL_tokenbuf];
4792 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4793 if ((t2 = keyword(tmpbuf, len, 0))) {
4794 /* binary operators exclude handle interpretations */
4806 PL_expect = XTERM; /* e.g. print $fh length() */
4811 PL_expect = XTERM; /* e.g. print $fh subr() */
4814 else if (isDIGIT(*s))
4815 PL_expect = XTERM; /* e.g. print $fh 3 */
4816 else if (*s == '.' && isDIGIT(s[1]))
4817 PL_expect = XTERM; /* e.g. print $fh .3 */
4818 else if ((*s == '?' || *s == '-' || *s == '+')
4819 && !isSPACE(s[1]) && s[1] != '=')
4820 PL_expect = XTERM; /* e.g. print $fh -1 */
4821 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4823 PL_expect = XTERM; /* e.g. print $fh /.../
4824 XXX except DORDOR operator
4826 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4828 PL_expect = XTERM; /* print $fh <<"EOF" */
4831 PL_pending_ident = '$';
4835 if (PL_expect == XOPERATOR)
4837 PL_tokenbuf[0] = '@';
4838 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4839 if (!PL_tokenbuf[1]) {
4842 if (PL_lex_state == LEX_NORMAL)
4844 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4846 PL_tokenbuf[0] = '%';
4848 /* Warn about @ where they meant $. */
4849 if (*s == '[' || *s == '{') {
4850 if (ckWARN(WARN_SYNTAX)) {
4851 const char *t = s + 1;
4852 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4854 if (*t == '}' || *t == ']') {
4856 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4857 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4858 "Scalar value %.*s better written as $%.*s",
4859 (int)(t-PL_bufptr), PL_bufptr,
4860 (int)(t-PL_bufptr-1), PL_bufptr+1);
4865 PL_pending_ident = '@';
4868 case '/': /* may be division, defined-or, or pattern */
4869 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4873 case '?': /* may either be conditional or pattern */
4874 if(PL_expect == XOPERATOR) {
4882 /* A // operator. */
4892 /* Disable warning on "study /blah/" */
4893 if (PL_oldoldbufptr == PL_last_uni
4894 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4895 || memNE(PL_last_uni, "study", 5)
4896 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4899 s = scan_pat(s,OP_MATCH);
4900 TERM(sublex_start());
4904 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4905 #ifdef PERL_STRICT_CR
4908 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4910 && (s == PL_linestart || s[-1] == '\n') )
4912 PL_lex_formbrack = 0;
4916 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4922 yylval.ival = OPf_SPECIAL;
4928 if (PL_expect != XOPERATOR)
4933 case '0': case '1': case '2': case '3': case '4':
4934 case '5': case '6': case '7': case '8': case '9':
4935 s = scan_num(s, &yylval);
4936 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
4937 if (PL_expect == XOPERATOR)
4942 s = scan_str(s,!!PL_madskills,FALSE);
4943 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4944 if (PL_expect == XOPERATOR) {
4945 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4947 deprecate_old(commaless_variable_list);
4948 return REPORT(','); /* grandfather non-comma-format format */
4955 yylval.ival = OP_CONST;
4956 TERM(sublex_start());
4959 s = scan_str(s,!!PL_madskills,FALSE);
4960 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4961 if (PL_expect == XOPERATOR) {
4962 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4964 deprecate_old(commaless_variable_list);
4965 return REPORT(','); /* grandfather non-comma-format format */
4972 yylval.ival = OP_CONST;
4973 /* FIXME. I think that this can be const if char *d is replaced by
4974 more localised variables. */
4975 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4976 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4977 yylval.ival = OP_STRINGIFY;
4981 TERM(sublex_start());
4984 s = scan_str(s,!!PL_madskills,FALSE);
4985 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
4986 if (PL_expect == XOPERATOR)
4987 no_op("Backticks",s);
4990 S_readpipe_override();
4991 TERM(sublex_start());
4995 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
4996 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
4998 if (PL_expect == XOPERATOR)
4999 no_op("Backslash",s);
5003 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
5004 char *start = s + 2;
5005 while (isDIGIT(*start) || *start == '_')
5007 if (*start == '.' && isDIGIT(start[1])) {
5008 s = scan_num(s, &yylval);
5011 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
5012 else if (!isALPHA(*start) && (PL_expect == XTERM
5013 || PL_expect == XREF || PL_expect == XSTATE
5014 || PL_expect == XTERMORDORDOR)) {
5015 /* XXX Use gv_fetchpvn rather than stomping on a const string */
5016 const char c = *start;
5019 gv = gv_fetchpv(s, 0, SVt_PVCV);
5022 s = scan_num(s, &yylval);
5029 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5071 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5073 /* Some keywords can be followed by any delimiter, including ':' */
5074 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5075 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5076 (PL_tokenbuf[0] == 'q' &&
5077 strchr("qwxr", PL_tokenbuf[1])))));
5079 /* x::* is just a word, unless x is "CORE" */
5080 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5084 while (d < PL_bufend && isSPACE(*d))
5085 d++; /* no comments skipped here, or s### is misparsed */
5087 /* Is this a label? */
5088 if (!tmp && PL_expect == XSTATE
5089 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5091 yylval.pval = savepv(PL_tokenbuf);
5096 /* Check for keywords */
5097 tmp = keyword(PL_tokenbuf, len, 0);
5099 /* Is this a word before a => operator? */
5100 if (*d == '=' && d[1] == '>') {
5103 = (OP*)newSVOP(OP_CONST, 0,
5104 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5105 yylval.opval->op_private = OPpCONST_BARE;
5109 if (tmp < 0) { /* second-class keyword? */
5110 GV *ogv = NULL; /* override (winner) */
5111 GV *hgv = NULL; /* hidden (loser) */
5112 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5114 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5117 if (GvIMPORTED_CV(gv))
5119 else if (! CvMETHOD(cv))
5123 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5124 (gv = *gvp) != (GV*)&PL_sv_undef &&
5125 GvCVu(gv) && GvIMPORTED_CV(gv))
5132 tmp = 0; /* overridden by import or by GLOBAL */
5135 && -tmp==KEY_lock /* XXX generalizable kludge */
5137 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
5139 tmp = 0; /* any sub overrides "weak" keyword */
5141 else { /* no override */
5143 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5144 Perl_warner(aTHX_ packWARN(WARN_MISC),
5145 "dump() better written as CORE::dump()");
5149 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5150 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5151 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5152 "Ambiguous call resolved as CORE::%s(), %s",
5153 GvENAME(hgv), "qualify as such or use &");
5160 default: /* not a keyword */
5161 /* Trade off - by using this evil construction we can pull the
5162 variable gv into the block labelled keylookup. If not, then
5163 we have to give it function scope so that the goto from the
5164 earlier ':' case doesn't bypass the initialisation. */
5166 just_a_word_zero_gv:
5174 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5177 SV *nextPL_nextwhite = 0;
5181 /* Get the rest if it looks like a package qualifier */
5183 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5185 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5188 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5189 *s == '\'' ? "'" : "::");
5194 if (PL_expect == XOPERATOR) {
5195 if (PL_bufptr == PL_linestart) {
5196 CopLINE_dec(PL_curcop);
5197 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5198 CopLINE_inc(PL_curcop);
5201 no_op("Bareword",s);
5204 /* Look for a subroutine with this name in current package,
5205 unless name is "Foo::", in which case Foo is a bearword
5206 (and a package name). */
5208 if (len > 2 && !PL_madskills &&
5209 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5211 if (ckWARN(WARN_BAREWORD)
5212 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5213 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5214 "Bareword \"%s\" refers to nonexistent package",
5217 PL_tokenbuf[len] = '\0';
5223 /* Mustn't actually add anything to a symbol table.
5224 But also don't want to "initialise" any placeholder
5225 constants that might already be there into full
5226 blown PVGVs with attached PVCV. */
5227 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5228 GV_NOADD_NOINIT, SVt_PVCV);
5233 /* if we saw a global override before, get the right name */
5236 sv = newSVpvs("CORE::GLOBAL::");
5237 sv_catpv(sv,PL_tokenbuf);
5240 /* If len is 0, newSVpv does strlen(), which is correct.
5241 If len is non-zero, then it will be the true length,
5242 and so the scalar will be created correctly. */
5243 sv = newSVpv(PL_tokenbuf,len);
5246 if (PL_madskills && !PL_thistoken) {
5247 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5248 PL_thistoken = newSVpv(start,s - start);
5249 PL_realtokenstart = s - SvPVX(PL_linestr);
5253 /* Presume this is going to be a bareword of some sort. */
5256 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5257 yylval.opval->op_private = OPpCONST_BARE;
5258 /* UTF-8 package name? */
5259 if (UTF && !IN_BYTES &&
5260 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5263 /* And if "Foo::", then that's what it certainly is. */
5268 /* Do the explicit type check so that we don't need to force
5269 the initialisation of the symbol table to have a real GV.
5270 Beware - gv may not really be a PVGV, cv may not really be
5271 a PVCV, (because of the space optimisations that gv_init
5272 understands) But they're true if for this symbol there is
5273 respectively a typeglob and a subroutine.
5275 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5276 /* Real typeglob, so get the real subroutine: */
5278 /* A proxy for a subroutine in this package? */
5279 : SvOK(gv) ? (CV *) gv : NULL)
5282 /* See if it's the indirect object for a list operator. */
5284 if (PL_oldoldbufptr &&
5285 PL_oldoldbufptr < PL_bufptr &&
5286 (PL_oldoldbufptr == PL_last_lop
5287 || PL_oldoldbufptr == PL_last_uni) &&
5288 /* NO SKIPSPACE BEFORE HERE! */
5289 (PL_expect == XREF ||
5290 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5292 bool immediate_paren = *s == '(';
5294 /* (Now we can afford to cross potential line boundary.) */
5295 s = SKIPSPACE2(s,nextPL_nextwhite);
5297 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5300 /* Two barewords in a row may indicate method call. */
5302 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5303 (tmp = intuit_method(s, gv, cv)))
5306 /* If not a declared subroutine, it's an indirect object. */
5307 /* (But it's an indir obj regardless for sort.) */
5308 /* Also, if "_" follows a filetest operator, it's a bareword */
5311 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5313 (PL_last_lop_op != OP_MAPSTART &&
5314 PL_last_lop_op != OP_GREPSTART))))
5315 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5316 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5319 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5324 PL_expect = XOPERATOR;
5327 s = SKIPSPACE2(s,nextPL_nextwhite);
5328 PL_nextwhite = nextPL_nextwhite;
5333 /* Is this a word before a => operator? */
5334 if (*s == '=' && s[1] == '>' && !pkgname) {
5336 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5337 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5338 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5342 /* If followed by a paren, it's certainly a subroutine. */
5347 while (SPACE_OR_TAB(*d))
5349 if (*d == ')' && (sv = gv_const_sv(gv))) {
5353 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5354 sv_catpvn(PL_thistoken, par, s - par);
5356 sv_free(PL_nextwhite);
5366 PL_nextwhite = PL_thiswhite;
5369 start_force(PL_curforce);
5371 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5372 PL_expect = XOPERATOR;
5375 PL_nextwhite = nextPL_nextwhite;
5376 curmad('X', PL_thistoken);
5377 PL_thistoken = newSVpvs("");
5385 /* If followed by var or block, call it a method (unless sub) */
5387 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5388 PL_last_lop = PL_oldbufptr;
5389 PL_last_lop_op = OP_METHOD;
5393 /* If followed by a bareword, see if it looks like indir obj. */
5396 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5397 && (tmp = intuit_method(s, gv, cv)))
5400 /* Not a method, so call it a subroutine (if defined) */
5403 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5404 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5405 "Ambiguous use of -%s resolved as -&%s()",
5406 PL_tokenbuf, PL_tokenbuf);
5407 /* Check for a constant sub */
5408 if ((sv = gv_const_sv(gv))) {
5410 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5411 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5412 yylval.opval->op_private = 0;
5416 /* Resolve to GV now. */
5417 if (SvTYPE(gv) != SVt_PVGV) {
5418 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5419 assert (SvTYPE(gv) == SVt_PVGV);
5420 /* cv must have been some sort of placeholder, so
5421 now needs replacing with a real code reference. */
5425 op_free(yylval.opval);
5426 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5427 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5428 PL_last_lop = PL_oldbufptr;
5429 PL_last_lop_op = OP_ENTERSUB;
5430 /* Is there a prototype? */
5438 const char *proto = SvPV_const((SV*)cv, protolen);
5441 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
5443 while (*proto == ';')
5445 if (*proto == '&' && *s == '{') {
5446 sv_setpv(PL_subname,
5449 "__ANON__" : "__ANON__::__ANON__"));
5456 PL_nextwhite = PL_thiswhite;
5459 start_force(PL_curforce);
5460 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5463 PL_nextwhite = nextPL_nextwhite;
5464 curmad('X', PL_thistoken);
5465 PL_thistoken = newSVpvs("");
5472 /* Guess harder when madskills require "best effort". */
5473 if (PL_madskills && (!gv || !GvCVu(gv))) {
5474 int probable_sub = 0;
5475 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5477 else if (isALPHA(*s)) {
5481 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5482 if (!keyword(tmpbuf, tmplen, 0))
5485 while (d < PL_bufend && isSPACE(*d))
5487 if (*d == '=' && d[1] == '>')
5492 gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5493 op_free(yylval.opval);
5494 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5495 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5496 PL_last_lop = PL_oldbufptr;
5497 PL_last_lop_op = OP_ENTERSUB;
5498 PL_nextwhite = PL_thiswhite;
5500 start_force(PL_curforce);
5501 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5503 PL_nextwhite = nextPL_nextwhite;
5504 curmad('X', PL_thistoken);
5505 PL_thistoken = newSVpvs("");
5510 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5517 /* Call it a bare word */
5519 if (PL_hints & HINT_STRICT_SUBS)
5520 yylval.opval->op_private |= OPpCONST_STRICT;
5523 if (lastchar != '-') {
5524 if (ckWARN(WARN_RESERVED)) {
5528 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
5529 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5536 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5537 && ckWARN_d(WARN_AMBIGUOUS)) {
5538 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5539 "Operator or semicolon missing before %c%s",
5540 lastchar, PL_tokenbuf);
5541 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5542 "Ambiguous use of %c resolved as operator %c",
5543 lastchar, lastchar);
5549 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5550 newSVpv(CopFILE(PL_curcop),0));
5554 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5555 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5558 case KEY___PACKAGE__:
5559 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5561 ? newSVhek(HvNAME_HEK(PL_curstash))
5568 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5569 const char *pname = "main";
5570 if (PL_tokenbuf[2] == 'D')
5571 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5572 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5576 GvIOp(gv) = newIO();
5577 IoIFP(GvIOp(gv)) = PL_rsfp;
5578 #if defined(HAS_FCNTL) && defined(F_SETFD)
5580 const int fd = PerlIO_fileno(PL_rsfp);
5581 fcntl(fd,F_SETFD,fd >= 3);
5584 /* Mark this internal pseudo-handle as clean */
5585 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5587 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5588 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5589 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5591 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5592 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5593 /* if the script was opened in binmode, we need to revert
5594 * it to text mode for compatibility; but only iff it has CRs
5595 * XXX this is a questionable hack at best. */
5596 if (PL_bufend-PL_bufptr > 2
5597 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5600 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5601 loc = PerlIO_tell(PL_rsfp);
5602 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5605 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5607 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5608 #endif /* NETWARE */
5609 #ifdef PERLIO_IS_STDIO /* really? */
5610 # if defined(__BORLANDC__)
5611 /* XXX see note in do_binmode() */
5612 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5616 PerlIO_seek(PL_rsfp, loc, 0);
5620 #ifdef PERLIO_LAYERS
5623 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5624 else if (PL_encoding) {
5631 XPUSHs(PL_encoding);
5633 call_method("name", G_SCALAR);
5637 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5638 Perl_form(aTHX_ ":encoding(%"SVf")",
5647 if (PL_realtokenstart >= 0) {
5648 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5650 PL_endwhite = newSVpvs("");
5651 sv_catsv(PL_endwhite, PL_thiswhite);
5653 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5654 PL_realtokenstart = -1;
5656 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5657 SvCUR(PL_endwhite))) != Nullch) ;
5672 if (PL_expect == XSTATE) {
5679 if (*s == ':' && s[1] == ':') {
5682 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5683 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5684 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5687 else if (tmp == KEY_require || tmp == KEY_do)
5688 /* that's a way to remember we saw "CORE::" */
5701 LOP(OP_ACCEPT,XTERM);
5707 LOP(OP_ATAN2,XTERM);
5713 LOP(OP_BINMODE,XTERM);
5716 LOP(OP_BLESS,XTERM);
5725 /* When 'use switch' is in effect, continue has a dual
5726 life as a control operator. */
5728 if (!FEATURE_IS_ENABLED("switch"))
5731 /* We have to disambiguate the two senses of
5732 "continue". If the next token is a '{' then
5733 treat it as the start of a continue block;
5734 otherwise treat it as a control operator.
5746 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5763 if (!PL_cryptseen) {
5764 PL_cryptseen = TRUE;
5768 LOP(OP_CRYPT,XTERM);
5771 LOP(OP_CHMOD,XTERM);
5774 LOP(OP_CHOWN,XTERM);
5777 LOP(OP_CONNECT,XTERM);
5796 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5797 if (orig_keyword == KEY_do) {
5806 PL_hints |= HINT_BLOCK_SCOPE;
5816 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5817 LOP(OP_DBMOPEN,XTERM);
5823 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5830 yylval.ival = CopLINE(PL_curcop);
5846 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5847 UNIBRACK(OP_ENTEREVAL);
5865 case KEY_endhostent:
5871 case KEY_endservent:
5874 case KEY_endprotoent:
5885 yylval.ival = CopLINE(PL_curcop);
5887 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5890 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5893 if ((PL_bufend - p) >= 3 &&
5894 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5896 else if ((PL_bufend - p) >= 4 &&
5897 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5900 if (isIDFIRST_lazy_if(p,UTF)) {
5901 p = scan_ident(p, PL_bufend,
5902 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5906 Perl_croak(aTHX_ "Missing $ on loop variable");
5908 s = SvPVX(PL_linestr) + soff;
5914 LOP(OP_FORMLINE,XTERM);
5920 LOP(OP_FCNTL,XTERM);
5926 LOP(OP_FLOCK,XTERM);
5935 LOP(OP_GREPSTART, XREF);
5938 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5953 case KEY_getpriority:
5954 LOP(OP_GETPRIORITY,XTERM);
5956 case KEY_getprotobyname:
5959 case KEY_getprotobynumber:
5960 LOP(OP_GPBYNUMBER,XTERM);
5962 case KEY_getprotoent:
5974 case KEY_getpeername:
5975 UNI(OP_GETPEERNAME);
5977 case KEY_gethostbyname:
5980 case KEY_gethostbyaddr:
5981 LOP(OP_GHBYADDR,XTERM);
5983 case KEY_gethostent:
5986 case KEY_getnetbyname:
5989 case KEY_getnetbyaddr:
5990 LOP(OP_GNBYADDR,XTERM);
5995 case KEY_getservbyname:
5996 LOP(OP_GSBYNAME,XTERM);
5998 case KEY_getservbyport:
5999 LOP(OP_GSBYPORT,XTERM);
6001 case KEY_getservent:
6004 case KEY_getsockname:
6005 UNI(OP_GETSOCKNAME);
6007 case KEY_getsockopt:
6008 LOP(OP_GSOCKOPT,XTERM);
6023 yylval.ival = CopLINE(PL_curcop);
6034 yylval.ival = CopLINE(PL_curcop);
6038 LOP(OP_INDEX,XTERM);
6044 LOP(OP_IOCTL,XTERM);
6056 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6088 LOP(OP_LISTEN,XTERM);
6097 s = scan_pat(s,OP_MATCH);
6098 TERM(sublex_start());
6101 LOP(OP_MAPSTART, XREF);
6104 LOP(OP_MKDIR,XTERM);
6107 LOP(OP_MSGCTL,XTERM);
6110 LOP(OP_MSGGET,XTERM);
6113 LOP(OP_MSGRCV,XTERM);
6116 LOP(OP_MSGSND,XTERM);
6123 if (isIDFIRST_lazy_if(s,UTF)) {
6127 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6128 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6130 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6131 if (!PL_in_my_stash) {
6134 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6138 if (PL_madskills) { /* just add type to declarator token */
6139 sv_catsv(PL_thistoken, PL_nextwhite);
6141 sv_catpvn(PL_thistoken, start, s - start);
6149 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6156 s = tokenize_use(0, s);
6160 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6167 if (isIDFIRST_lazy_if(s,UTF)) {
6169 for (d = s; isALNUM_lazy_if(d,UTF);)
6171 for (t=d; isSPACE(*t);)
6173 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6175 && !(t[0] == '=' && t[1] == '>')
6177 int parms_len = (int)(d-s);
6178 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6179 "Precedence problem: open %.*s should be open(%.*s)",
6180 parms_len, s, parms_len, s);
6186 yylval.ival = OP_OR;
6196 LOP(OP_OPEN_DIR,XTERM);
6199 checkcomma(s,PL_tokenbuf,"filehandle");
6203 checkcomma(s,PL_tokenbuf,"filehandle");
6222 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6226 LOP(OP_PIPE_OP,XTERM);
6229 s = scan_str(s,!!PL_madskills,FALSE);
6232 yylval.ival = OP_CONST;
6233 TERM(sublex_start());
6239 s = scan_str(s,!!PL_madskills,FALSE);
6242 PL_expect = XOPERATOR;
6244 if (SvCUR(PL_lex_stuff)) {
6247 d = SvPV_force(PL_lex_stuff, len);
6249 for (; isSPACE(*d) && len; --len, ++d)
6254 if (!warned && ckWARN(WARN_QW)) {
6255 for (; !isSPACE(*d) && len; --len, ++d) {
6257 Perl_warner(aTHX_ packWARN(WARN_QW),
6258 "Possible attempt to separate words with commas");
6261 else if (*d == '#') {
6262 Perl_warner(aTHX_ packWARN(WARN_QW),
6263 "Possible attempt to put comments in qw() list");
6269 for (; !isSPACE(*d) && len; --len, ++d)
6272 sv = newSVpvn(b, d-b);
6273 if (DO_UTF8(PL_lex_stuff))
6275 words = append_elem(OP_LIST, words,
6276 newSVOP(OP_CONST, 0, tokeq(sv)));
6280 start_force(PL_curforce);
6281 NEXTVAL_NEXTTOKE.opval = words;
6286 SvREFCNT_dec(PL_lex_stuff);
6287 PL_lex_stuff = NULL;
6293 s = scan_str(s,!!PL_madskills,FALSE);
6296 yylval.ival = OP_STRINGIFY;
6297 if (SvIVX(PL_lex_stuff) == '\'')
6298 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6299 TERM(sublex_start());
6302 s = scan_pat(s,OP_QR);
6303 TERM(sublex_start());
6306 s = scan_str(s,!!PL_madskills,FALSE);
6309 S_readpipe_override();
6310 TERM(sublex_start());
6318 s = force_version(s, FALSE);
6320 else if (*s != 'v' || !isDIGIT(s[1])
6321 || (s = force_version(s, TRUE), *s == 'v'))
6323 *PL_tokenbuf = '\0';
6324 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6325 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6326 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6328 yyerror("<> should be quotes");
6330 if (orig_keyword == KEY_require) {
6338 PL_last_uni = PL_oldbufptr;
6339 PL_last_lop_op = OP_REQUIRE;
6341 return REPORT( (int)REQUIRE );
6347 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6351 LOP(OP_RENAME,XTERM);
6360 LOP(OP_RINDEX,XTERM);
6370 UNIDOR(OP_READLINE);
6383 LOP(OP_REVERSE,XTERM);
6386 UNIDOR(OP_READLINK);
6394 TERM(sublex_start());
6396 TOKEN(1); /* force error */
6399 checkcomma(s,PL_tokenbuf,"filehandle");
6409 LOP(OP_SELECT,XTERM);
6415 LOP(OP_SEMCTL,XTERM);
6418 LOP(OP_SEMGET,XTERM);
6421 LOP(OP_SEMOP,XTERM);
6427 LOP(OP_SETPGRP,XTERM);
6429 case KEY_setpriority:
6430 LOP(OP_SETPRIORITY,XTERM);
6432 case KEY_sethostent:
6438 case KEY_setservent:
6441 case KEY_setprotoent:
6451 LOP(OP_SEEKDIR,XTERM);
6453 case KEY_setsockopt:
6454 LOP(OP_SSOCKOPT,XTERM);
6460 LOP(OP_SHMCTL,XTERM);
6463 LOP(OP_SHMGET,XTERM);
6466 LOP(OP_SHMREAD,XTERM);
6469 LOP(OP_SHMWRITE,XTERM);
6472 LOP(OP_SHUTDOWN,XTERM);
6481 LOP(OP_SOCKET,XTERM);
6483 case KEY_socketpair:
6484 LOP(OP_SOCKPAIR,XTERM);
6487 checkcomma(s,PL_tokenbuf,"subroutine name");
6489 if (*s == ';' || *s == ')') /* probably a close */
6490 Perl_croak(aTHX_ "sort is now a reserved word");
6492 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6496 LOP(OP_SPLIT,XTERM);
6499 LOP(OP_SPRINTF,XTERM);
6502 LOP(OP_SPLICE,XTERM);
6517 LOP(OP_SUBSTR,XTERM);
6523 char tmpbuf[sizeof PL_tokenbuf];
6524 SSize_t tboffset = 0;
6525 expectation attrful;
6526 bool have_name, have_proto;
6527 const int key = tmp;
6532 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6533 SV *subtoken = newSVpvn(tstart, s - tstart);
6537 s = SKIPSPACE2(s,tmpwhite);
6542 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6543 (*s == ':' && s[1] == ':'))
6550 attrful = XATTRBLOCK;
6551 /* remember buffer pos'n for later force_word */
6552 tboffset = s - PL_oldbufptr;
6553 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6556 nametoke = newSVpvn(s, d - s);
6558 if (strchr(tmpbuf, ':'))
6559 sv_setpv(PL_subname, tmpbuf);
6561 sv_setsv(PL_subname,PL_curstname);
6562 sv_catpvs(PL_subname,"::");
6563 sv_catpvn(PL_subname,tmpbuf,len);
6570 CURMAD('X', nametoke);
6571 CURMAD('_', tmpwhite);
6572 (void) force_word(PL_oldbufptr + tboffset, WORD,
6575 s = SKIPSPACE2(d,tmpwhite);
6582 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6583 PL_expect = XTERMBLOCK;
6584 attrful = XATTRTERM;
6585 sv_setpvn(PL_subname,"?",1);
6589 if (key == KEY_format) {
6591 PL_lex_formbrack = PL_lex_brackets + 1;
6593 PL_thistoken = subtoken;
6597 (void) force_word(PL_oldbufptr + tboffset, WORD,
6603 /* Look for a prototype */
6606 bool bad_proto = FALSE;
6607 const bool warnsyntax = ckWARN(WARN_SYNTAX);
6609 s = scan_str(s,!!PL_madskills,FALSE);
6611 Perl_croak(aTHX_ "Prototype not terminated");
6612 /* strip spaces and check for bad characters */
6613 d = SvPVX(PL_lex_stuff);
6615 for (p = d; *p; ++p) {
6618 if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
6624 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6625 "Illegal character in prototype for %"SVf" : %s",
6626 (void*)PL_subname, d);
6627 SvCUR_set(PL_lex_stuff, tmp);
6632 CURMAD('q', PL_thisopen);
6633 CURMAD('_', tmpwhite);
6634 CURMAD('=', PL_thisstuff);
6635 CURMAD('Q', PL_thisclose);
6636 NEXTVAL_NEXTTOKE.opval =
6637 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6638 PL_lex_stuff = Nullsv;
6641 s = SKIPSPACE2(s,tmpwhite);
6649 if (*s == ':' && s[1] != ':')
6650 PL_expect = attrful;
6651 else if (*s != '{' && key == KEY_sub) {
6653 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6655 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, (void*)PL_subname);
6662 curmad('^', newSVpvs(""));
6663 CURMAD('_', tmpwhite);
6667 PL_thistoken = subtoken;
6670 NEXTVAL_NEXTTOKE.opval =
6671 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6672 PL_lex_stuff = NULL;
6677 sv_setpv(PL_subname,
6679 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
6683 (void) force_word(PL_oldbufptr + tboffset, WORD,
6693 LOP(OP_SYSTEM,XREF);
6696 LOP(OP_SYMLINK,XTERM);
6699 LOP(OP_SYSCALL,XTERM);
6702 LOP(OP_SYSOPEN,XTERM);
6705 LOP(OP_SYSSEEK,XTERM);
6708 LOP(OP_SYSREAD,XTERM);
6711 LOP(OP_SYSWRITE,XTERM);
6715 TERM(sublex_start());
6736 LOP(OP_TRUNCATE,XTERM);
6748 yylval.ival = CopLINE(PL_curcop);
6752 yylval.ival = CopLINE(PL_curcop);
6756 LOP(OP_UNLINK,XTERM);
6762 LOP(OP_UNPACK,XTERM);
6765 LOP(OP_UTIME,XTERM);
6771 LOP(OP_UNSHIFT,XTERM);
6774 s = tokenize_use(1, s);
6784 yylval.ival = CopLINE(PL_curcop);
6788 yylval.ival = CopLINE(PL_curcop);
6792 PL_hints |= HINT_BLOCK_SCOPE;
6799 LOP(OP_WAITPID,XTERM);
6808 ctl_l[0] = toCTRL('L');
6810 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6813 /* Make sure $^L is defined */
6814 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6819 if (PL_expect == XOPERATOR)
6825 yylval.ival = OP_XOR;
6830 TERM(sublex_start());
6835 #pragma segment Main
6839 S_pending_ident(pTHX)
6844 /* pit holds the identifier we read and pending_ident is reset */
6845 char pit = PL_pending_ident;
6846 PL_pending_ident = 0;
6848 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6849 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6850 "### Pending identifier '%s'\n", PL_tokenbuf); });
6852 /* if we're in a my(), we can't allow dynamics here.
6853 $foo'bar has already been turned into $foo::bar, so
6854 just check for colons.
6856 if it's a legal name, the OP is a PADANY.
6859 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6860 if (strchr(PL_tokenbuf,':'))
6861 yyerror(Perl_form(aTHX_ "No package name allowed for "
6862 "variable %s in \"our\"",
6864 tmp = allocmy(PL_tokenbuf);
6867 if (strchr(PL_tokenbuf,':'))
6868 yyerror(Perl_form(aTHX_ PL_no_myglob,
6869 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6871 yylval.opval = newOP(OP_PADANY, 0);
6872 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6878 build the ops for accesses to a my() variable.
6880 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6881 then used in a comparison. This catches most, but not
6882 all cases. For instance, it catches
6883 sort { my($a); $a <=> $b }
6885 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6886 (although why you'd do that is anyone's guess).
6889 if (!strchr(PL_tokenbuf,':')) {
6891 tmp = pad_findmy(PL_tokenbuf);
6892 if (tmp != NOT_IN_PAD) {
6893 /* might be an "our" variable" */
6894 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6895 /* build ops for a bareword */
6896 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6897 HEK * const stashname = HvNAME_HEK(stash);
6898 SV * const sym = newSVhek(stashname);
6899 sv_catpvs(sym, "::");
6900 sv_catpv(sym, PL_tokenbuf+1);
6901 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6902 yylval.opval->op_private = OPpCONST_ENTERED;
6905 ? (GV_ADDMULTI | GV_ADDINEVAL)
6908 ((PL_tokenbuf[0] == '$') ? SVt_PV
6909 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6914 /* if it's a sort block and they're naming $a or $b */
6915 if (PL_last_lop_op == OP_SORT &&
6916 PL_tokenbuf[0] == '$' &&
6917 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6920 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6921 d < PL_bufend && *d != '\n';
6924 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6925 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6931 yylval.opval = newOP(OP_PADANY, 0);
6932 yylval.opval->op_targ = tmp;
6938 Whine if they've said @foo in a doublequoted string,
6939 and @foo isn't a variable we can find in the symbol
6942 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6943 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6944 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6945 && ckWARN(WARN_AMBIGUOUS))
6947 /* Downgraded from fatal to warning 20000522 mjd */
6948 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6949 "Possible unintended interpolation of %s in string",
6954 /* build ops for a bareword */
6955 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6956 yylval.opval->op_private = OPpCONST_ENTERED;
6959 /* If the identifier refers to a stash, don't autovivify it.
6960 * Change 24660 had the side effect of causing symbol table
6961 * hashes to always be defined, even if they were freshly
6962 * created and the only reference in the entire program was
6963 * the single statement with the defined %foo::bar:: test.
6964 * It appears that all code in the wild doing this actually
6965 * wants to know whether sub-packages have been loaded, so
6966 * by avoiding auto-vivifying symbol tables, we ensure that
6967 * defined %foo::bar:: continues to be false, and the existing
6968 * tests still give the expected answers, even though what
6969 * they're actually testing has now changed subtly.
6971 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6973 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
6974 ((PL_tokenbuf[0] == '$') ? SVt_PV
6975 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6981 * The following code was generated by perl_keyword.pl.
6985 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
6990 case 1: /* 5 tokens of length 1 */
7022 case 2: /* 18 tokens of length 2 */
7168 case 3: /* 29 tokens of length 3 */
7172 if (name[1] == 'N' &&
7235 if (name[1] == 'i' &&
7257 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7275 if (name[1] == 'o' &&
7284 if (name[1] == 'e' &&
7293 if (name[1] == 'n' &&
7302 if (name[1] == 'o' &&
7311 if (name[1] == 'a' &&
7320 if (name[1] == 'o' &&
7382 if (name[1] == 'e' &&
7396 return (all_keywords || FEATURE_IS_ENABLED("say") ? -KEY_say : 0);
7422 if (name[1] == 'i' &&
7431 if (name[1] == 's' &&
7440 if (name[1] == 'e' &&
7449 if (name[1] == 'o' &&
7461 case 4: /* 41 tokens of length 4 */
7465 if (name[1] == 'O' &&
7475 if (name[1] == 'N' &&
7485 if (name[1] == 'i' &&
7495 if (name[1] == 'h' &&
7505 if (name[1] == 'u' &&
7518 if (name[2] == 'c' &&
7527 if (name[2] == 's' &&
7536 if (name[2] == 'a' &&
7572 if (name[1] == 'o' &&
7585 if (name[2] == 't' &&
7594 if (name[2] == 'o' &&
7603 if (name[2] == 't' &&
7612 if (name[2] == 'e' &&
7625 if (name[1] == 'o' &&
7638 if (name[2] == 'y' &&
7647 if (name[2] == 'l' &&
7663 if (name[2] == 's' &&
7672 if (name[2] == 'n' &&
7681 if (name[2] == 'c' &&
7694 if (name[1] == 'e' &&
7704 if (name[1] == 'p' &&
7717 if (name[2] == 'c' &&
7726 if (name[2] == 'p' &&
7735 if (name[2] == 's' &&
7751 if (name[2] == 'n' &&
7821 if (name[2] == 'r' &&
7830 if (name[2] == 'r' &&
7839 if (name[2] == 'a' &&
7855 if (name[2] == 'l' &&
7917 if (name[2] == 'e' &&
7920 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7933 case 5: /* 39 tokens of length 5 */
7937 if (name[1] == 'E' &&
7948 if (name[1] == 'H' &&
7962 if (name[2] == 'a' &&
7972 if (name[2] == 'a' &&
7989 if (name[2] == 'e' &&
7999 if (name[2] == 'e' &&
8003 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
8019 if (name[3] == 'i' &&
8028 if (name[3] == 'o' &&
8064 if (name[2] == 'o' &&
8074 if (name[2] == 'y' &&
8088 if (name[1] == 'l' &&
8102 if (name[2] == 'n' &&
8112 if (name[2] == 'o' &&
8126 if (name[1] == 'i' &&
8131 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8140 if (name[2] == 'd' &&
8150 if (name[2] == 'c' &&
8167 if (name[2] == 'c' &&
8177 if (name[2] == 't' &&
8191 if (name[1] == 'k' &&
8202 if (name[1] == 'r' &&
8216 if (name[2] == 's' &&
8226 if (name[2] == 'd' &&
8243 if (name[2] == 'm' &&
8253 if (name[2] == 'i' &&
8263 if (name[2] == 'e' &&
8273 if (name[2] == 'l' &&
8283 if (name[2] == 'a' &&
8296 if (name[3] == 't' &&
8299 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8305 if (name[3] == 'd' &&
8322 if (name[1] == 'i' &&
8336 if (name[2] == 'a' &&
8349 if (name[3] == 'e' &&
8384 if (name[2] == 'i' &&
8401 if (name[2] == 'i' &&
8411 if (name[2] == 'i' &&
8428 case 6: /* 33 tokens of length 6 */
8432 if (name[1] == 'c' &&
8447 if (name[2] == 'l' &&
8458 if (name[2] == 'r' &&
8473 if (name[1] == 'e' &&
8488 if (name[2] == 's' &&
8493 if(ckWARN_d(WARN_SYNTAX))
8494 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8500 if (name[2] == 'i' &&
8518 if (name[2] == 'l' &&
8529 if (name[2] == 'r' &&
8544 if (name[1] == 'm' &&
8559 if (name[2] == 'n' &&
8570 if (name[2] == 's' &&
8585 if (name[1] == 's' &&
8591 if (name[4] == 't' &&
8600 if (name[4] == 'e' &&
8609 if (name[4] == 'c' &&
8618 if (name[4] == 'n' &&
8634 if (name[1] == 'r' &&
8652 if (name[3] == 'a' &&
8662 if (name[3] == 'u' &&
8676 if (name[2] == 'n' &&
8694 if (name[2] == 'a' &&
8708 if (name[3] == 'e' &&
8721 if (name[4] == 't' &&
8730 if (name[4] == 'e' &&
8752 if (name[4] == 't' &&
8761 if (name[4] == 'e' &&
8777 if (name[2] == 'c' &&
8788 if (name[2] == 'l' &&
8799 if (name[2] == 'b' &&
8810 if (name[2] == 's' &&
8833 if (name[4] == 's' &&
8842 if (name[4] == 'n' &&
8855 if (name[3] == 'a' &&
8872 if (name[1] == 'a' &&
8887 case 7: /* 29 tokens of length 7 */
8891 if (name[1] == 'E' &&
8904 if (name[1] == '_' &&
8917 if (name[1] == 'i' &&
8924 return -KEY_binmode;
8930 if (name[1] == 'o' &&
8937 return -KEY_connect;
8946 if (name[2] == 'm' &&
8952 return -KEY_dbmopen;
8963 if (name[4] == 'u' &&
8967 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
8973 if (name[4] == 'n' &&
8994 if (name[1] == 'o' &&
9007 if (name[1] == 'e' &&
9014 if (name[5] == 'r' &&
9017 return -KEY_getpgrp;
9023 if (name[5] == 'i' &&
9026 return -KEY_getppid;
9039 if (name[1] == 'c' &&
9046 return -KEY_lcfirst;
9052 if (name[1] == 'p' &&
9059 return -KEY_opendir;
9065 if (name[1] == 'a' &&
9083 if (name[3] == 'd' &&
9088 return -KEY_readdir;
9094 if (name[3] == 'u' &&
9105 if (name[3] == 'e' &&
9110 return -KEY_reverse;
9129 if (name[3] == 'k' &&
9134 return -KEY_seekdir;
9140 if (name[3] == 'p' &&
9145 return -KEY_setpgrp;
9155 if (name[2] == 'm' &&
9161 return -KEY_shmread;
9167 if (name[2] == 'r' &&
9173 return -KEY_sprintf;
9182 if (name[3] == 'l' &&
9187 return -KEY_symlink;
9196 if (name[4] == 'a' &&
9200 return -KEY_syscall;
9206 if (name[4] == 'p' &&
9210 return -KEY_sysopen;
9216 if (name[4] == 'e' &&
9220 return -KEY_sysread;
9226 if (name[4] == 'e' &&
9230 return -KEY_sysseek;
9248 if (name[1] == 'e' &&
9255 return -KEY_telldir;
9264 if (name[2] == 'f' &&
9270 return -KEY_ucfirst;
9276 if (name[2] == 's' &&
9282 return -KEY_unshift;
9292 if (name[1] == 'a' &&
9299 return -KEY_waitpid;
9308 case 8: /* 26 tokens of length 8 */
9312 if (name[1] == 'U' &&
9320 return KEY_AUTOLOAD;
9331 if (name[3] == 'A' &&
9337 return KEY___DATA__;
9343 if (name[3] == 'I' &&
9349 return -KEY___FILE__;
9355 if (name[3] == 'I' &&
9361 return -KEY___LINE__;
9377 if (name[2] == 'o' &&
9384 return -KEY_closedir;
9390 if (name[2] == 'n' &&
9397 return -KEY_continue;
9407 if (name[1] == 'b' &&
9415 return -KEY_dbmclose;
9421 if (name[1] == 'n' &&
9427 if (name[4] == 'r' &&
9432 return -KEY_endgrent;
9438 if (name[4] == 'w' &&
9443 return -KEY_endpwent;
9456 if (name[1] == 'o' &&
9464 return -KEY_formline;
9470 if (name[1] == 'e' &&
9481 if (name[6] == 'n' &&
9484 return -KEY_getgrent;
9490 if (name[6] == 'i' &&
9493 return -KEY_getgrgid;
9499 if (name[6] == 'a' &&
9502 return -KEY_getgrnam;
9515 if (name[4] == 'o' &&
9520 return -KEY_getlogin;
9531 if (name[6] == 'n' &&
9534 return -KEY_getpwent;
9540 if (name[6] == 'a' &&
9543 return -KEY_getpwnam;
9549 if (name[6] == 'i' &&
9552 return -KEY_getpwuid;
9572 if (name[1] == 'e' &&
9579 if (name[5] == 'i' &&
9586 return -KEY_readline;
9591 return -KEY_readlink;
9602 if (name[5] == 'i' &&
9606 return -KEY_readpipe;
9627 if (name[4] == 'r' &&
9632 return -KEY_setgrent;
9638 if (name[4] == 'w' &&
9643 return -KEY_setpwent;
9659 if (name[3] == 'w' &&
9665 return -KEY_shmwrite;
9671 if (name[3] == 't' &&
9677 return -KEY_shutdown;
9687 if (name[2] == 's' &&
9694 return -KEY_syswrite;
9704 if (name[1] == 'r' &&
9712 return -KEY_truncate;
9721 case 9: /* 9 tokens of length 9 */
9725 if (name[1] == 'N' &&
9734 return KEY_UNITCHECK;
9740 if (name[1] == 'n' &&
9749 return -KEY_endnetent;
9755 if (name[1] == 'e' &&
9764 return -KEY_getnetent;
9770 if (name[1] == 'o' &&
9779 return -KEY_localtime;
9785 if (name[1] == 'r' &&
9794 return KEY_prototype;
9800 if (name[1] == 'u' &&
9809 return -KEY_quotemeta;
9815 if (name[1] == 'e' &&
9824 return -KEY_rewinddir;
9830 if (name[1] == 'e' &&
9839 return -KEY_setnetent;
9845 if (name[1] == 'a' &&
9854 return -KEY_wantarray;
9863 case 10: /* 9 tokens of length 10 */
9867 if (name[1] == 'n' &&
9873 if (name[4] == 'o' &&
9880 return -KEY_endhostent;
9886 if (name[4] == 'e' &&
9893 return -KEY_endservent;
9906 if (name[1] == 'e' &&
9912 if (name[4] == 'o' &&
9919 return -KEY_gethostent;
9928 if (name[5] == 'r' &&
9934 return -KEY_getservent;
9940 if (name[5] == 'c' &&
9946 return -KEY_getsockopt;
9971 if (name[4] == 'o' &&
9978 return -KEY_sethostent;
9987 if (name[5] == 'r' &&
9993 return -KEY_setservent;
9999 if (name[5] == 'c' &&
10005 return -KEY_setsockopt;
10022 if (name[2] == 'c' &&
10031 return -KEY_socketpair;
10044 case 11: /* 8 tokens of length 11 */
10048 if (name[1] == '_' &&
10058 { /* __PACKAGE__ */
10059 return -KEY___PACKAGE__;
10065 if (name[1] == 'n' &&
10075 { /* endprotoent */
10076 return -KEY_endprotoent;
10082 if (name[1] == 'e' &&
10091 if (name[5] == 'e' &&
10097 { /* getpeername */
10098 return -KEY_getpeername;
10107 if (name[6] == 'o' &&
10112 { /* getpriority */
10113 return -KEY_getpriority;
10119 if (name[6] == 't' &&
10124 { /* getprotoent */
10125 return -KEY_getprotoent;
10139 if (name[4] == 'o' &&
10146 { /* getsockname */
10147 return -KEY_getsockname;
10160 if (name[1] == 'e' &&
10168 if (name[6] == 'o' &&
10173 { /* setpriority */
10174 return -KEY_setpriority;
10180 if (name[6] == 't' &&
10185 { /* setprotoent */
10186 return -KEY_setprotoent;
10202 case 12: /* 2 tokens of length 12 */
10203 if (name[0] == 'g' &&
10215 if (name[9] == 'd' &&
10218 { /* getnetbyaddr */
10219 return -KEY_getnetbyaddr;
10225 if (name[9] == 'a' &&
10228 { /* getnetbyname */
10229 return -KEY_getnetbyname;
10241 case 13: /* 4 tokens of length 13 */
10242 if (name[0] == 'g' &&
10249 if (name[4] == 'o' &&
10258 if (name[10] == 'd' &&
10261 { /* gethostbyaddr */
10262 return -KEY_gethostbyaddr;
10268 if (name[10] == 'a' &&
10271 { /* gethostbyname */
10272 return -KEY_gethostbyname;
10285 if (name[4] == 'e' &&
10294 if (name[10] == 'a' &&
10297 { /* getservbyname */
10298 return -KEY_getservbyname;
10304 if (name[10] == 'o' &&
10307 { /* getservbyport */
10308 return -KEY_getservbyport;
10327 case 14: /* 1 tokens of length 14 */
10328 if (name[0] == 'g' &&
10342 { /* getprotobyname */
10343 return -KEY_getprotobyname;
10348 case 16: /* 1 tokens of length 16 */
10349 if (name[0] == 'g' &&
10365 { /* getprotobynumber */
10366 return -KEY_getprotobynumber;
10380 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10384 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10385 if (ckWARN(WARN_SYNTAX)) {
10388 for (w = s+2; *w && level; w++) {
10391 else if (*w == ')')
10394 while (isSPACE(*w))
10396 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
10397 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10398 "%s (...) interpreted as function",name);
10401 while (s < PL_bufend && isSPACE(*s))
10405 while (s < PL_bufend && isSPACE(*s))
10407 if (isIDFIRST_lazy_if(s,UTF)) {
10408 const char * const w = s++;
10409 while (isALNUM_lazy_if(s,UTF))
10411 while (s < PL_bufend && isSPACE(*s))
10415 if (keyword(w, s - w, 0))
10418 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10419 if (gv && GvCVu(gv))
10421 Perl_croak(aTHX_ "No comma allowed after %s", what);
10426 /* Either returns sv, or mortalizes sv and returns a new SV*.
10427 Best used as sv=new_constant(..., sv, ...).
10428 If s, pv are NULL, calls subroutine with one argument,
10429 and type is used with error messages only. */
10432 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10436 HV * const table = GvHV(PL_hintgv); /* ^H */
10440 const char *why1 = "", *why2 = "", *why3 = "";
10442 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10445 why2 = (const char *)
10446 (strEQ(key,"charnames")
10447 ? "(possibly a missing \"use charnames ...\")"
10449 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10450 (type ? type: "undef"), why2);
10452 /* This is convoluted and evil ("goto considered harmful")
10453 * but I do not understand the intricacies of all the different
10454 * failure modes of %^H in here. The goal here is to make
10455 * the most probable error message user-friendly. --jhi */
10460 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10461 (type ? type: "undef"), why1, why2, why3);
10463 yyerror(SvPVX_const(msg));
10467 cvp = hv_fetch(table, key, strlen(key), FALSE);
10468 if (!cvp || !SvOK(*cvp)) {
10471 why3 = "} is not defined";
10474 sv_2mortal(sv); /* Parent created it permanently */
10477 pv = sv_2mortal(newSVpvn(s, len));
10479 typesv = sv_2mortal(newSVpv(type, 0));
10481 typesv = &PL_sv_undef;
10483 PUSHSTACKi(PERLSI_OVERLOAD);
10495 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10499 /* Check the eval first */
10500 if (!PL_in_eval && SvTRUE(ERRSV)) {
10501 sv_catpvs(ERRSV, "Propagated");
10502 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10504 res = SvREFCNT_inc_simple(sv);
10508 SvREFCNT_inc_simple_void(res);
10517 why1 = "Call to &{$^H{";
10519 why3 = "}} did not return a defined value";
10527 /* Returns a NUL terminated string, with the length of the string written to
10531 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10534 register char *d = dest;
10535 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10538 Perl_croak(aTHX_ ident_too_long);
10539 if (isALNUM(*s)) /* UTF handled below */
10541 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10546 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10550 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10551 char *t = s + UTF8SKIP(s);
10553 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10557 Perl_croak(aTHX_ ident_too_long);
10558 Copy(s, d, len, char);
10571 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10574 char *bracket = NULL;
10576 register char *d = dest;
10577 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10582 while (isDIGIT(*s)) {
10584 Perl_croak(aTHX_ ident_too_long);
10591 Perl_croak(aTHX_ ident_too_long);
10592 if (isALNUM(*s)) /* UTF handled below */
10594 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10599 else if (*s == ':' && s[1] == ':') {
10603 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10604 char *t = s + UTF8SKIP(s);
10605 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10607 if (d + (t - s) > e)
10608 Perl_croak(aTHX_ ident_too_long);
10609 Copy(s, d, t - s, char);
10620 if (PL_lex_state != LEX_NORMAL)
10621 PL_lex_state = LEX_INTERPENDMAYBE;
10624 if (*s == '$' && s[1] &&
10625 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10638 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10643 if (isSPACE(s[-1])) {
10645 const char ch = *s++;
10646 if (!SPACE_OR_TAB(ch)) {
10652 if (isIDFIRST_lazy_if(d,UTF)) {
10656 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10657 end += UTF8SKIP(end);
10658 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10659 end += UTF8SKIP(end);
10661 Copy(s, d, end - s, char);
10666 while ((isALNUM(*s) || *s == ':') && d < e)
10669 Perl_croak(aTHX_ ident_too_long);
10672 while (s < send && SPACE_OR_TAB(*s))
10674 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10675 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10676 const char * const brack =
10678 ((*s == '[') ? "[...]" : "{...}");
10679 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10680 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10681 funny, dest, brack, funny, dest, brack);
10684 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10688 /* Handle extended ${^Foo} variables
10689 * 1999-02-27 mjd-perl-patch@plover.com */
10690 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10694 while (isALNUM(*s) && d < e) {
10698 Perl_croak(aTHX_ ident_too_long);
10703 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10704 PL_lex_state = LEX_INTERPEND;
10707 if (PL_lex_state == LEX_NORMAL) {
10708 if (ckWARN(WARN_AMBIGUOUS) &&
10709 (keyword(dest, d - dest, 0) || get_cv(dest, FALSE)))
10713 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10714 "Ambiguous use of %c{%s} resolved to %c%s",
10715 funny, dest, funny, dest);
10720 s = bracket; /* let the parser handle it */
10724 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10725 PL_lex_state = LEX_INTERPEND;
10730 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10732 PERL_UNUSED_CONTEXT;
10735 else if (ch == 'g')
10736 *pmfl |= PMf_GLOBAL;
10737 else if (ch == 'c')
10738 *pmfl |= PMf_CONTINUE;
10739 else if (ch == 'o')
10741 else if (ch == 'm')
10742 *pmfl |= PMf_MULTILINE;
10743 else if (ch == 's')
10744 *pmfl |= PMf_SINGLELINE;
10745 else if (ch == 'x')
10746 *pmfl |= PMf_EXTENDED;
10750 S_scan_pat(pTHX_ char *start, I32 type)
10754 char *s = scan_str(start,!!PL_madskills,FALSE);
10755 const char * const valid_flags =
10756 (const char *)((type == OP_QR) ? "iomsx" : "iogcmsx");
10763 const char * const delimiter = skipspace(start);
10767 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10768 : "Search pattern not terminated" ));
10771 pm = (PMOP*)newPMOP(type, 0);
10772 if (PL_multi_open == '?')
10773 pm->op_pmflags |= PMf_ONCE;
10777 while (*s && strchr(valid_flags, *s))
10778 pmflag(&pm->op_pmflags,*s++);
10780 if (PL_madskills && modstart != s) {
10781 SV* tmptoken = newSVpvn(modstart, s - modstart);
10782 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10785 /* issue a warning if /c is specified,but /g is not */
10786 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10787 && ckWARN(WARN_REGEXP))
10789 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
10792 pm->op_pmpermflags = pm->op_pmflags;
10794 PL_lex_op = (OP*)pm;
10795 yylval.ival = OP_MATCH;
10800 S_scan_subst(pTHX_ char *start)
10811 yylval.ival = OP_NULL;
10813 s = scan_str(start,!!PL_madskills,FALSE);
10816 Perl_croak(aTHX_ "Substitution pattern not terminated");
10818 if (s[-1] == PL_multi_open)
10821 if (PL_madskills) {
10822 CURMAD('q', PL_thisopen);
10823 CURMAD('_', PL_thiswhite);
10824 CURMAD('E', PL_thisstuff);
10825 CURMAD('Q', PL_thisclose);
10826 PL_realtokenstart = s - SvPVX(PL_linestr);
10830 first_start = PL_multi_start;
10831 s = scan_str(s,!!PL_madskills,FALSE);
10833 if (PL_lex_stuff) {
10834 SvREFCNT_dec(PL_lex_stuff);
10835 PL_lex_stuff = NULL;
10837 Perl_croak(aTHX_ "Substitution replacement not terminated");
10839 PL_multi_start = first_start; /* so whole substitution is taken together */
10841 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10844 if (PL_madskills) {
10845 CURMAD('z', PL_thisopen);
10846 CURMAD('R', PL_thisstuff);
10847 CURMAD('Z', PL_thisclose);
10857 else if (strchr("iogcmsx", *s))
10858 pmflag(&pm->op_pmflags,*s++);
10864 if (PL_madskills) {
10866 curmad('m', newSVpvn(modstart, s - modstart));
10867 append_madprops(PL_thismad, (OP*)pm, 0);
10871 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10872 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10876 SV * const repl = newSVpvs("");
10878 PL_sublex_info.super_bufptr = s;
10879 PL_sublex_info.super_bufend = PL_bufend;
10881 pm->op_pmflags |= PMf_EVAL;
10883 sv_catpv(repl, (const char *)(es ? "eval " : "do "));
10884 sv_catpvs(repl, "{");
10885 sv_catsv(repl, PL_lex_repl);
10886 if (strchr(SvPVX(PL_lex_repl), '#'))
10887 sv_catpvs(repl, "\n");
10888 sv_catpvs(repl, "}");
10890 SvREFCNT_dec(PL_lex_repl);
10891 PL_lex_repl = repl;
10894 pm->op_pmpermflags = pm->op_pmflags;
10895 PL_lex_op = (OP*)pm;
10896 yylval.ival = OP_SUBST;
10901 S_scan_trans(pTHX_ char *start)
10914 yylval.ival = OP_NULL;
10916 s = scan_str(start,!!PL_madskills,FALSE);
10918 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10920 if (s[-1] == PL_multi_open)
10923 if (PL_madskills) {
10924 CURMAD('q', PL_thisopen);
10925 CURMAD('_', PL_thiswhite);
10926 CURMAD('E', PL_thisstuff);
10927 CURMAD('Q', PL_thisclose);
10928 PL_realtokenstart = s - SvPVX(PL_linestr);
10932 s = scan_str(s,!!PL_madskills,FALSE);
10934 if (PL_lex_stuff) {
10935 SvREFCNT_dec(PL_lex_stuff);
10936 PL_lex_stuff = NULL;
10938 Perl_croak(aTHX_ "Transliteration replacement not terminated");
10940 if (PL_madskills) {
10941 CURMAD('z', PL_thisopen);
10942 CURMAD('R', PL_thisstuff);
10943 CURMAD('Z', PL_thisclose);
10946 complement = del = squash = 0;
10953 complement = OPpTRANS_COMPLEMENT;
10956 del = OPpTRANS_DELETE;
10959 squash = OPpTRANS_SQUASH;
10968 Newx(tbl, complement&&!del?258:256, short);
10969 o = newPVOP(OP_TRANS, 0, (char*)tbl);
10970 o->op_private &= ~OPpTRANS_ALL;
10971 o->op_private |= del|squash|complement|
10972 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10973 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
10976 yylval.ival = OP_TRANS;
10979 if (PL_madskills) {
10981 curmad('m', newSVpvn(modstart, s - modstart));
10982 append_madprops(PL_thismad, o, 0);
10991 S_scan_heredoc(pTHX_ register char *s)
10995 I32 op_type = OP_SCALAR;
10999 const char *found_newline;
11003 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
11005 I32 stuffstart = s - SvPVX(PL_linestr);
11008 PL_realtokenstart = -1;
11013 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
11017 while (SPACE_OR_TAB(*peek))
11019 if (*peek == '`' || *peek == '\'' || *peek =='"') {
11022 s = delimcpy(d, e, s, PL_bufend, term, &len);
11032 if (!isALNUM_lazy_if(s,UTF))
11033 deprecate_old("bare << to mean <<\"\"");
11034 for (; isALNUM_lazy_if(s,UTF); s++) {
11039 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
11040 Perl_croak(aTHX_ "Delimiter for here document is too long");
11043 len = d - PL_tokenbuf;
11046 if (PL_madskills) {
11047 tstart = PL_tokenbuf + !outer;
11048 PL_thisclose = newSVpvn(tstart, len - !outer);
11049 tstart = SvPVX(PL_linestr) + stuffstart;
11050 PL_thisopen = newSVpvn(tstart, s - tstart);
11051 stuffstart = s - SvPVX(PL_linestr);
11054 #ifndef PERL_STRICT_CR
11055 d = strchr(s, '\r');
11057 char * const olds = s;
11059 while (s < PL_bufend) {
11065 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11074 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11081 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11082 herewas = newSVpvn(s,PL_bufend-s);
11086 herewas = newSVpvn(s-1,found_newline-s+1);
11089 herewas = newSVpvn(s,found_newline-s);
11093 if (PL_madskills) {
11094 tstart = SvPVX(PL_linestr) + stuffstart;
11096 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11098 PL_thisstuff = newSVpvn(tstart, s - tstart);
11101 s += SvCUR(herewas);
11104 stuffstart = s - SvPVX(PL_linestr);
11110 tmpstr = newSV(79);
11111 sv_upgrade(tmpstr, SVt_PVIV);
11112 if (term == '\'') {
11113 op_type = OP_CONST;
11114 SvIV_set(tmpstr, -1);
11116 else if (term == '`') {
11117 op_type = OP_BACKTICK;
11118 SvIV_set(tmpstr, '\\');
11122 PL_multi_start = CopLINE(PL_curcop);
11123 PL_multi_open = PL_multi_close = '<';
11124 term = *PL_tokenbuf;
11125 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11126 char * const bufptr = PL_sublex_info.super_bufptr;
11127 char * const bufend = PL_sublex_info.super_bufend;
11128 char * const olds = s - SvCUR(herewas);
11129 s = strchr(bufptr, '\n');
11133 while (s < bufend &&
11134 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11136 CopLINE_inc(PL_curcop);
11139 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11140 missingterm(PL_tokenbuf);
11142 sv_setpvn(herewas,bufptr,d-bufptr+1);
11143 sv_setpvn(tmpstr,d+1,s-d);
11145 sv_catpvn(herewas,s,bufend-s);
11146 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11153 while (s < PL_bufend &&
11154 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11156 CopLINE_inc(PL_curcop);
11158 if (s >= PL_bufend) {
11159 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11160 missingterm(PL_tokenbuf);
11162 sv_setpvn(tmpstr,d+1,s-d);
11164 if (PL_madskills) {
11166 sv_catpvn(PL_thisstuff, d + 1, s - d);
11168 PL_thisstuff = newSVpvn(d + 1, s - d);
11169 stuffstart = s - SvPVX(PL_linestr);
11173 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11175 sv_catpvn(herewas,s,PL_bufend-s);
11176 sv_setsv(PL_linestr,herewas);
11177 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11178 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11179 PL_last_lop = PL_last_uni = NULL;
11182 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11183 while (s >= PL_bufend) { /* multiple line string? */
11185 if (PL_madskills) {
11186 tstart = SvPVX(PL_linestr) + stuffstart;
11188 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11190 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11194 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11195 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11196 missingterm(PL_tokenbuf);
11199 stuffstart = s - SvPVX(PL_linestr);
11201 CopLINE_inc(PL_curcop);
11202 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11203 PL_last_lop = PL_last_uni = NULL;
11204 #ifndef PERL_STRICT_CR
11205 if (PL_bufend - PL_linestart >= 2) {
11206 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11207 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11209 PL_bufend[-2] = '\n';
11211 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11213 else if (PL_bufend[-1] == '\r')
11214 PL_bufend[-1] = '\n';
11216 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11217 PL_bufend[-1] = '\n';
11219 if (PERLDB_LINE && PL_curstash != PL_debstash) {
11220 SV * const sv = newSV(0);
11222 sv_upgrade(sv, SVt_PVMG);
11223 sv_setsv(sv,PL_linestr);
11224 (void)SvIOK_on(sv);
11226 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop),sv);
11228 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11229 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11230 *(SvPVX(PL_linestr) + off ) = ' ';
11231 sv_catsv(PL_linestr,herewas);
11232 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11233 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11237 sv_catsv(tmpstr,PL_linestr);
11242 PL_multi_end = CopLINE(PL_curcop);
11243 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11244 SvPV_shrink_to_cur(tmpstr);
11246 SvREFCNT_dec(herewas);
11248 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11250 else if (PL_encoding)
11251 sv_recode_to_utf8(tmpstr, PL_encoding);
11253 PL_lex_stuff = tmpstr;
11254 yylval.ival = op_type;
11258 /* scan_inputsymbol
11259 takes: current position in input buffer
11260 returns: new position in input buffer
11261 side-effects: yylval and lex_op are set.
11266 <FH> read from filehandle
11267 <pkg::FH> read from package qualified filehandle
11268 <pkg'FH> read from package qualified filehandle
11269 <$fh> read from filehandle in $fh
11270 <*.h> filename glob
11275 S_scan_inputsymbol(pTHX_ char *start)
11278 register char *s = start; /* current position in buffer */
11282 char *d = PL_tokenbuf; /* start of temp holding space */
11283 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11285 end = strchr(s, '\n');
11288 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11290 /* die if we didn't have space for the contents of the <>,
11291 or if it didn't end, or if we see a newline
11294 if (len >= (I32)sizeof PL_tokenbuf)
11295 Perl_croak(aTHX_ "Excessively long <> operator");
11297 Perl_croak(aTHX_ "Unterminated <> operator");
11302 Remember, only scalar variables are interpreted as filehandles by
11303 this code. Anything more complex (e.g., <$fh{$num}>) will be
11304 treated as a glob() call.
11305 This code makes use of the fact that except for the $ at the front,
11306 a scalar variable and a filehandle look the same.
11308 if (*d == '$' && d[1]) d++;
11310 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11311 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11314 /* If we've tried to read what we allow filehandles to look like, and
11315 there's still text left, then it must be a glob() and not a getline.
11316 Use scan_str to pull out the stuff between the <> and treat it
11317 as nothing more than a string.
11320 if (d - PL_tokenbuf != len) {
11321 yylval.ival = OP_GLOB;
11323 s = scan_str(start,!!PL_madskills,FALSE);
11325 Perl_croak(aTHX_ "Glob not terminated");
11329 bool readline_overriden = FALSE;
11332 /* we're in a filehandle read situation */
11335 /* turn <> into <ARGV> */
11337 Copy("ARGV",d,5,char);
11339 /* Check whether readline() is overriden */
11340 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11342 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11344 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11345 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
11346 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11347 readline_overriden = TRUE;
11349 /* if <$fh>, create the ops to turn the variable into a
11353 /* try to find it in the pad for this block, otherwise find
11354 add symbol table ops
11356 const PADOFFSET tmp = pad_findmy(d);
11357 if (tmp != NOT_IN_PAD) {
11358 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11359 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11360 HEK * const stashname = HvNAME_HEK(stash);
11361 SV * const sym = sv_2mortal(newSVhek(stashname));
11362 sv_catpvs(sym, "::");
11363 sv_catpv(sym, d+1);
11368 OP * const o = newOP(OP_PADSV, 0);
11370 PL_lex_op = readline_overriden
11371 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11372 append_elem(OP_LIST, o,
11373 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11374 : (OP*)newUNOP(OP_READLINE, 0, o);
11383 ? (GV_ADDMULTI | GV_ADDINEVAL)
11386 PL_lex_op = readline_overriden
11387 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11388 append_elem(OP_LIST,
11389 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11390 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11391 : (OP*)newUNOP(OP_READLINE, 0,
11392 newUNOP(OP_RV2SV, 0,
11393 newGVOP(OP_GV, 0, gv)));
11395 if (!readline_overriden)
11396 PL_lex_op->op_flags |= OPf_SPECIAL;
11397 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11398 yylval.ival = OP_NULL;
11401 /* If it's none of the above, it must be a literal filehandle
11402 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11404 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11405 PL_lex_op = readline_overriden
11406 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11407 append_elem(OP_LIST,
11408 newGVOP(OP_GV, 0, gv),
11409 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11410 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11411 yylval.ival = OP_NULL;
11420 takes: start position in buffer
11421 keep_quoted preserve \ on the embedded delimiter(s)
11422 keep_delims preserve the delimiters around the string
11423 returns: position to continue reading from buffer
11424 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11425 updates the read buffer.
11427 This subroutine pulls a string out of the input. It is called for:
11428 q single quotes q(literal text)
11429 ' single quotes 'literal text'
11430 qq double quotes qq(interpolate $here please)
11431 " double quotes "interpolate $here please"
11432 qx backticks qx(/bin/ls -l)
11433 ` backticks `/bin/ls -l`
11434 qw quote words @EXPORT_OK = qw( func() $spam )
11435 m// regexp match m/this/
11436 s/// regexp substitute s/this/that/
11437 tr/// string transliterate tr/this/that/
11438 y/// string transliterate y/this/that/
11439 ($*@) sub prototypes sub foo ($)
11440 (stuff) sub attr parameters sub foo : attr(stuff)
11441 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11443 In most of these cases (all but <>, patterns and transliterate)
11444 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11445 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11446 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11449 It skips whitespace before the string starts, and treats the first
11450 character as the delimiter. If the delimiter is one of ([{< then
11451 the corresponding "close" character )]}> is used as the closing
11452 delimiter. It allows quoting of delimiters, and if the string has
11453 balanced delimiters ([{<>}]) it allows nesting.
11455 On success, the SV with the resulting string is put into lex_stuff or,
11456 if that is already non-NULL, into lex_repl. The second case occurs only
11457 when parsing the RHS of the special constructs s/// and tr/// (y///).
11458 For convenience, the terminating delimiter character is stuffed into
11463 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11466 SV *sv; /* scalar value: string */
11467 const char *tmps; /* temp string, used for delimiter matching */
11468 register char *s = start; /* current position in the buffer */
11469 register char term; /* terminating character */
11470 register char *to; /* current position in the sv's data */
11471 I32 brackets = 1; /* bracket nesting level */
11472 bool has_utf8 = FALSE; /* is there any utf8 content? */
11473 I32 termcode; /* terminating char. code */
11474 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11475 STRLEN termlen; /* length of terminating string */
11476 char *last = NULL; /* last position for nesting bracket */
11482 /* skip space before the delimiter */
11488 if (PL_realtokenstart >= 0) {
11489 stuffstart = PL_realtokenstart;
11490 PL_realtokenstart = -1;
11493 stuffstart = start - SvPVX(PL_linestr);
11495 /* mark where we are, in case we need to report errors */
11498 /* after skipping whitespace, the next character is the terminator */
11501 termcode = termstr[0] = term;
11505 termcode = utf8_to_uvchr((U8*)s, &termlen);
11506 Copy(s, termstr, termlen, U8);
11507 if (!UTF8_IS_INVARIANT(term))
11511 /* mark where we are */
11512 PL_multi_start = CopLINE(PL_curcop);
11513 PL_multi_open = term;
11515 /* find corresponding closing delimiter */
11516 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11517 termcode = termstr[0] = term = tmps[5];
11519 PL_multi_close = term;
11521 /* create a new SV to hold the contents. 79 is the SV's initial length.
11522 What a random number. */
11524 sv_upgrade(sv, SVt_PVIV);
11525 SvIV_set(sv, termcode);
11526 (void)SvPOK_only(sv); /* validate pointer */
11528 /* move past delimiter and try to read a complete string */
11530 sv_catpvn(sv, s, termlen);
11533 tstart = SvPVX(PL_linestr) + stuffstart;
11534 if (!PL_thisopen && !keep_delims) {
11535 PL_thisopen = newSVpvn(tstart, s - tstart);
11536 stuffstart = s - SvPVX(PL_linestr);
11540 if (PL_encoding && !UTF) {
11544 int offset = s - SvPVX_const(PL_linestr);
11545 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11546 &offset, (char*)termstr, termlen);
11547 const char * const ns = SvPVX_const(PL_linestr) + offset;
11548 char * const svlast = SvEND(sv) - 1;
11550 for (; s < ns; s++) {
11551 if (*s == '\n' && !PL_rsfp)
11552 CopLINE_inc(PL_curcop);
11555 goto read_more_line;
11557 /* handle quoted delimiters */
11558 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11560 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11562 if ((svlast-1 - t) % 2) {
11563 if (!keep_quoted) {
11564 *(svlast-1) = term;
11566 SvCUR_set(sv, SvCUR(sv) - 1);
11571 if (PL_multi_open == PL_multi_close) {
11579 for (t = w = last; t < svlast; w++, t++) {
11580 /* At here, all closes are "was quoted" one,
11581 so we don't check PL_multi_close. */
11583 if (!keep_quoted && *(t+1) == PL_multi_open)
11588 else if (*t == PL_multi_open)
11596 SvCUR_set(sv, w - SvPVX_const(sv));
11599 if (--brackets <= 0)
11604 if (!keep_delims) {
11605 SvCUR_set(sv, SvCUR(sv) - 1);
11611 /* extend sv if need be */
11612 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11613 /* set 'to' to the next character in the sv's string */
11614 to = SvPVX(sv)+SvCUR(sv);
11616 /* if open delimiter is the close delimiter read unbridle */
11617 if (PL_multi_open == PL_multi_close) {
11618 for (; s < PL_bufend; s++,to++) {
11619 /* embedded newlines increment the current line number */
11620 if (*s == '\n' && !PL_rsfp)
11621 CopLINE_inc(PL_curcop);
11622 /* handle quoted delimiters */
11623 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11624 if (!keep_quoted && s[1] == term)
11626 /* any other quotes are simply copied straight through */
11630 /* terminate when run out of buffer (the for() condition), or
11631 have found the terminator */
11632 else if (*s == term) {
11635 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11638 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11644 /* if the terminator isn't the same as the start character (e.g.,
11645 matched brackets), we have to allow more in the quoting, and
11646 be prepared for nested brackets.
11649 /* read until we run out of string, or we find the terminator */
11650 for (; s < PL_bufend; s++,to++) {
11651 /* embedded newlines increment the line count */
11652 if (*s == '\n' && !PL_rsfp)
11653 CopLINE_inc(PL_curcop);
11654 /* backslashes can escape the open or closing characters */
11655 if (*s == '\\' && s+1 < PL_bufend) {
11656 if (!keep_quoted &&
11657 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11662 /* allow nested opens and closes */
11663 else if (*s == PL_multi_close && --brackets <= 0)
11665 else if (*s == PL_multi_open)
11667 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11672 /* terminate the copied string and update the sv's end-of-string */
11674 SvCUR_set(sv, to - SvPVX_const(sv));
11677 * this next chunk reads more into the buffer if we're not done yet
11681 break; /* handle case where we are done yet :-) */
11683 #ifndef PERL_STRICT_CR
11684 if (to - SvPVX_const(sv) >= 2) {
11685 if ((to[-2] == '\r' && to[-1] == '\n') ||
11686 (to[-2] == '\n' && to[-1] == '\r'))
11690 SvCUR_set(sv, to - SvPVX_const(sv));
11692 else if (to[-1] == '\r')
11695 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11700 /* if we're out of file, or a read fails, bail and reset the current
11701 line marker so we can report where the unterminated string began
11704 if (PL_madskills) {
11705 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11707 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11709 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11713 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11715 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11721 /* we read a line, so increment our line counter */
11722 CopLINE_inc(PL_curcop);
11724 /* update debugger info */
11725 if (PERLDB_LINE && PL_curstash != PL_debstash) {
11726 SV * const line_sv = newSV(0);
11728 sv_upgrade(line_sv, SVt_PVMG);
11729 sv_setsv(line_sv,PL_linestr);
11730 (void)SvIOK_on(line_sv);
11731 SvIV_set(line_sv, 0);
11732 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop), line_sv);
11735 /* having changed the buffer, we must update PL_bufend */
11736 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11737 PL_last_lop = PL_last_uni = NULL;
11740 /* at this point, we have successfully read the delimited string */
11742 if (!PL_encoding || UTF) {
11744 if (PL_madskills) {
11745 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11746 const int len = s - start;
11748 sv_catpvn(PL_thisstuff, tstart, len);
11750 PL_thisstuff = newSVpvn(tstart, len);
11751 if (!PL_thisclose && !keep_delims)
11752 PL_thisclose = newSVpvn(s,termlen);
11757 sv_catpvn(sv, s, termlen);
11762 if (PL_madskills) {
11763 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11764 const int len = s - tstart - termlen;
11766 sv_catpvn(PL_thisstuff, tstart, len);
11768 PL_thisstuff = newSVpvn(tstart, len);
11769 if (!PL_thisclose && !keep_delims)
11770 PL_thisclose = newSVpvn(s - termlen,termlen);
11774 if (has_utf8 || PL_encoding)
11777 PL_multi_end = CopLINE(PL_curcop);
11779 /* if we allocated too much space, give some back */
11780 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11781 SvLEN_set(sv, SvCUR(sv) + 1);
11782 SvPV_renew(sv, SvLEN(sv));
11785 /* decide whether this is the first or second quoted string we've read
11798 takes: pointer to position in buffer
11799 returns: pointer to new position in buffer
11800 side-effects: builds ops for the constant in yylval.op
11802 Read a number in any of the formats that Perl accepts:
11804 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11805 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11808 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11810 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11813 If it reads a number without a decimal point or an exponent, it will
11814 try converting the number to an integer and see if it can do so
11815 without loss of precision.
11819 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11822 register const char *s = start; /* current position in buffer */
11823 register char *d; /* destination in temp buffer */
11824 register char *e; /* end of temp buffer */
11825 NV nv; /* number read, as a double */
11826 SV *sv = NULL; /* place to put the converted number */
11827 bool floatit; /* boolean: int or float? */
11828 const char *lastub = NULL; /* position of last underbar */
11829 static char const number_too_long[] = "Number too long";
11831 /* We use the first character to decide what type of number this is */
11835 Perl_croak(aTHX_ "panic: scan_num");
11837 /* if it starts with a 0, it could be an octal number, a decimal in
11838 0.13 disguise, or a hexadecimal number, or a binary number. */
11842 u holds the "number so far"
11843 shift the power of 2 of the base
11844 (hex == 4, octal == 3, binary == 1)
11845 overflowed was the number more than we can hold?
11847 Shift is used when we add a digit. It also serves as an "are
11848 we in octal/hex/binary?" indicator to disallow hex characters
11849 when in octal mode.
11854 bool overflowed = FALSE;
11855 bool just_zero = TRUE; /* just plain 0 or binary number? */
11856 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11857 static const char* const bases[5] =
11858 { "", "binary", "", "octal", "hexadecimal" };
11859 static const char* const Bases[5] =
11860 { "", "Binary", "", "Octal", "Hexadecimal" };
11861 static const char* const maxima[5] =
11863 "0b11111111111111111111111111111111",
11867 const char *base, *Base, *max;
11869 /* check for hex */
11874 } else if (s[1] == 'b') {
11879 /* check for a decimal in disguise */
11880 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11882 /* so it must be octal */
11889 if (ckWARN(WARN_SYNTAX))
11890 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11891 "Misplaced _ in number");
11895 base = bases[shift];
11896 Base = Bases[shift];
11897 max = maxima[shift];
11899 /* read the rest of the number */
11901 /* x is used in the overflow test,
11902 b is the digit we're adding on. */
11907 /* if we don't mention it, we're done */
11911 /* _ are ignored -- but warned about if consecutive */
11913 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11914 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11915 "Misplaced _ in number");
11919 /* 8 and 9 are not octal */
11920 case '8': case '9':
11922 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11926 case '2': case '3': case '4':
11927 case '5': case '6': case '7':
11929 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11932 case '0': case '1':
11933 b = *s++ & 15; /* ASCII digit -> value of digit */
11937 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11938 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11939 /* make sure they said 0x */
11942 b = (*s++ & 7) + 9;
11944 /* Prepare to put the digit we have onto the end
11945 of the number so far. We check for overflows.
11951 x = u << shift; /* make room for the digit */
11953 if ((x >> shift) != u
11954 && !(PL_hints & HINT_NEW_BINARY)) {
11957 if (ckWARN_d(WARN_OVERFLOW))
11958 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11959 "Integer overflow in %s number",
11962 u = x | b; /* add the digit to the end */
11965 n *= nvshift[shift];
11966 /* If an NV has not enough bits in its
11967 * mantissa to represent an UV this summing of
11968 * small low-order numbers is a waste of time
11969 * (because the NV cannot preserve the
11970 * low-order bits anyway): we could just
11971 * remember when did we overflow and in the
11972 * end just multiply n by the right
11980 /* if we get here, we had success: make a scalar value from
11985 /* final misplaced underbar check */
11986 if (s[-1] == '_') {
11987 if (ckWARN(WARN_SYNTAX))
11988 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11993 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
11994 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11995 "%s number > %s non-portable",
12001 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
12002 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12003 "%s number > %s non-portable",
12008 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
12009 sv = new_constant(start, s - start, "integer",
12011 else if (PL_hints & HINT_NEW_BINARY)
12012 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
12017 handle decimal numbers.
12018 we're also sent here when we read a 0 as the first digit
12020 case '1': case '2': case '3': case '4': case '5':
12021 case '6': case '7': case '8': case '9': case '.':
12024 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
12027 /* read next group of digits and _ and copy into d */
12028 while (isDIGIT(*s) || *s == '_') {
12029 /* skip underscores, checking for misplaced ones
12033 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12034 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12035 "Misplaced _ in number");
12039 /* check for end of fixed-length buffer */
12041 Perl_croak(aTHX_ number_too_long);
12042 /* if we're ok, copy the character */
12047 /* final misplaced underbar check */
12048 if (lastub && s == lastub + 1) {
12049 if (ckWARN(WARN_SYNTAX))
12050 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12053 /* read a decimal portion if there is one. avoid
12054 3..5 being interpreted as the number 3. followed
12057 if (*s == '.' && s[1] != '.') {
12062 if (ckWARN(WARN_SYNTAX))
12063 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12064 "Misplaced _ in number");
12068 /* copy, ignoring underbars, until we run out of digits.
12070 for (; isDIGIT(*s) || *s == '_'; s++) {
12071 /* fixed length buffer check */
12073 Perl_croak(aTHX_ number_too_long);
12075 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12076 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12077 "Misplaced _ in number");
12083 /* fractional part ending in underbar? */
12084 if (s[-1] == '_') {
12085 if (ckWARN(WARN_SYNTAX))
12086 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12087 "Misplaced _ in number");
12089 if (*s == '.' && isDIGIT(s[1])) {
12090 /* oops, it's really a v-string, but without the "v" */
12096 /* read exponent part, if present */
12097 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12101 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12102 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12104 /* stray preinitial _ */
12106 if (ckWARN(WARN_SYNTAX))
12107 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12108 "Misplaced _ in number");
12112 /* allow positive or negative exponent */
12113 if (*s == '+' || *s == '-')
12116 /* stray initial _ */
12118 if (ckWARN(WARN_SYNTAX))
12119 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12120 "Misplaced _ in number");
12124 /* read digits of exponent */
12125 while (isDIGIT(*s) || *s == '_') {
12128 Perl_croak(aTHX_ number_too_long);
12132 if (((lastub && s == lastub + 1) ||
12133 (!isDIGIT(s[1]) && s[1] != '_'))
12134 && ckWARN(WARN_SYNTAX))
12135 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12136 "Misplaced _ in number");
12143 /* make an sv from the string */
12147 We try to do an integer conversion first if no characters
12148 indicating "float" have been found.
12153 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12155 if (flags == IS_NUMBER_IN_UV) {
12157 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12160 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12161 if (uv <= (UV) IV_MIN)
12162 sv_setiv(sv, -(IV)uv);
12169 /* terminate the string */
12171 nv = Atof(PL_tokenbuf);
12175 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12176 (PL_hints & HINT_NEW_INTEGER) )
12177 sv = new_constant(PL_tokenbuf,
12180 (floatit ? "float" : "integer"),
12184 /* if it starts with a v, it could be a v-string */
12187 sv = newSV(5); /* preallocate storage space */
12188 s = scan_vstring(s,sv);
12192 /* make the op for the constant and return */
12195 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12197 lvalp->opval = NULL;
12203 S_scan_formline(pTHX_ register char *s)
12206 register char *eol;
12208 SV * const stuff = newSVpvs("");
12209 bool needargs = FALSE;
12210 bool eofmt = FALSE;
12212 char *tokenstart = s;
12215 if (PL_madskills) {
12216 savewhite = PL_thiswhite;
12221 while (!needargs) {
12224 #ifdef PERL_STRICT_CR
12225 while (SPACE_OR_TAB(*t))
12228 while (SPACE_OR_TAB(*t) || *t == '\r')
12231 if (*t == '\n' || t == PL_bufend) {
12236 if (PL_in_eval && !PL_rsfp) {
12237 eol = (char *) memchr(s,'\n',PL_bufend-s);
12242 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12244 for (t = s; t < eol; t++) {
12245 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12247 goto enough; /* ~~ must be first line in formline */
12249 if (*t == '@' || *t == '^')
12253 sv_catpvn(stuff, s, eol-s);
12254 #ifndef PERL_STRICT_CR
12255 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12256 char *end = SvPVX(stuff) + SvCUR(stuff);
12259 SvCUR_set(stuff, SvCUR(stuff) - 1);
12269 if (PL_madskills) {
12271 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12273 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12276 s = filter_gets(PL_linestr, PL_rsfp, 0);
12278 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12280 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12282 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12283 PL_last_lop = PL_last_uni = NULL;
12292 if (SvCUR(stuff)) {
12295 PL_lex_state = LEX_NORMAL;
12296 start_force(PL_curforce);
12297 NEXTVAL_NEXTTOKE.ival = 0;
12301 PL_lex_state = LEX_FORMLINE;
12303 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12305 else if (PL_encoding)
12306 sv_recode_to_utf8(stuff, PL_encoding);
12308 start_force(PL_curforce);
12309 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12311 start_force(PL_curforce);
12312 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12316 SvREFCNT_dec(stuff);
12318 PL_lex_formbrack = 0;
12322 if (PL_madskills) {
12324 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12326 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12327 PL_thiswhite = savewhite;
12339 PL_cshlen = strlen(PL_cshname);
12341 #if defined(USE_ITHREADS)
12342 PERL_UNUSED_CONTEXT;
12348 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12351 const I32 oldsavestack_ix = PL_savestack_ix;
12352 CV* const outsidecv = PL_compcv;
12355 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12357 SAVEI32(PL_subline);
12358 save_item(PL_subname);
12359 SAVESPTR(PL_compcv);
12361 PL_compcv = (CV*)newSV(0);
12362 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12363 CvFLAGS(PL_compcv) |= flags;
12365 PL_subline = CopLINE(PL_curcop);
12366 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12367 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12368 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12370 return oldsavestack_ix;
12374 #pragma segment Perl_yylex
12377 Perl_yywarn(pTHX_ const char *s)
12380 PL_in_eval |= EVAL_WARNONLY;
12382 PL_in_eval &= ~EVAL_WARNONLY;
12387 Perl_yyerror(pTHX_ const char *s)
12390 const char *where = NULL;
12391 const char *context = NULL;
12395 if (!yychar || (yychar == ';' && !PL_rsfp))
12397 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12398 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12399 PL_oldbufptr != PL_bufptr) {
12402 The code below is removed for NetWare because it abends/crashes on NetWare
12403 when the script has error such as not having the closing quotes like:
12404 if ($var eq "value)
12405 Checking of white spaces is anyway done in NetWare code.
12408 while (isSPACE(*PL_oldoldbufptr))
12411 context = PL_oldoldbufptr;
12412 contlen = PL_bufptr - PL_oldoldbufptr;
12414 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12415 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12418 The code below is removed for NetWare because it abends/crashes on NetWare
12419 when the script has error such as not having the closing quotes like:
12420 if ($var eq "value)
12421 Checking of white spaces is anyway done in NetWare code.
12424 while (isSPACE(*PL_oldbufptr))
12427 context = PL_oldbufptr;
12428 contlen = PL_bufptr - PL_oldbufptr;
12430 else if (yychar > 255)
12431 where = "next token ???";
12432 else if (yychar == -2) { /* YYEMPTY */
12433 if (PL_lex_state == LEX_NORMAL ||
12434 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12435 where = "at end of line";
12436 else if (PL_lex_inpat)
12437 where = "within pattern";
12439 where = "within string";
12442 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12444 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12445 else if (isPRINT_LC(yychar))
12446 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12448 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12449 where = SvPVX_const(where_sv);
12451 msg = sv_2mortal(newSVpv(s, 0));
12452 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12453 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12455 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12457 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12458 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12459 Perl_sv_catpvf(aTHX_ msg,
12460 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12461 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12464 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12465 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, (void*)msg);
12468 if (PL_error_count >= 10) {
12469 if (PL_in_eval && SvCUR(ERRSV))
12470 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12471 (void*)ERRSV, OutCopFILE(PL_curcop));
12473 Perl_croak(aTHX_ "%s has too many errors.\n",
12474 OutCopFILE(PL_curcop));
12477 PL_in_my_stash = NULL;
12481 #pragma segment Main
12485 S_swallow_bom(pTHX_ U8 *s)
12488 const STRLEN slen = SvCUR(PL_linestr);
12491 if (s[1] == 0xFE) {
12492 /* UTF-16 little-endian? (or UTF32-LE?) */
12493 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12494 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12495 #ifndef PERL_NO_UTF16_FILTER
12496 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12499 if (PL_bufend > (char*)s) {
12503 filter_add(utf16rev_textfilter, NULL);
12504 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12505 utf16_to_utf8_reversed(s, news,
12506 PL_bufend - (char*)s - 1,
12508 sv_setpvn(PL_linestr, (const char*)news, newlen);
12510 s = (U8*)SvPVX(PL_linestr);
12511 Copy(news, s, newlen, U8);
12515 SvUTF8_on(PL_linestr);
12516 s = (U8*)SvPVX(PL_linestr);
12518 /* FIXME - is this a general bug fix? */
12521 PL_bufend = SvPVX(PL_linestr) + newlen;
12524 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12529 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12530 #ifndef PERL_NO_UTF16_FILTER
12531 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12534 if (PL_bufend > (char *)s) {
12538 filter_add(utf16_textfilter, NULL);
12539 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12540 utf16_to_utf8(s, news,
12541 PL_bufend - (char*)s,
12543 sv_setpvn(PL_linestr, (const char*)news, newlen);
12545 SvUTF8_on(PL_linestr);
12546 s = (U8*)SvPVX(PL_linestr);
12547 PL_bufend = SvPVX(PL_linestr) + newlen;
12550 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12555 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12556 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12557 s += 3; /* UTF-8 */
12563 if (s[2] == 0xFE && s[3] == 0xFF) {
12564 /* UTF-32 big-endian */
12565 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12568 else if (s[2] == 0 && s[3] != 0) {
12571 * are a good indicator of UTF-16BE. */
12572 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12578 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12579 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12580 s += 4; /* UTF-8 */
12586 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12589 * are a good indicator of UTF-16LE. */
12590 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12599 * Restore a source filter.
12603 restore_rsfp(pTHX_ void *f)
12606 PerlIO * const fp = (PerlIO*)f;
12608 if (PL_rsfp == PerlIO_stdin())
12609 PerlIO_clearerr(PL_rsfp);
12610 else if (PL_rsfp && (PL_rsfp != fp))
12611 PerlIO_close(PL_rsfp);
12615 #ifndef PERL_NO_UTF16_FILTER
12617 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12620 const STRLEN old = SvCUR(sv);
12621 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12622 DEBUG_P(PerlIO_printf(Perl_debug_log,
12623 "utf16_textfilter(%p): %d %d (%d)\n",
12624 FPTR2DPTR(void *, utf16_textfilter),
12625 idx, maxlen, (int) count));
12629 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12630 Copy(SvPVX_const(sv), tmps, old, char);
12631 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12632 SvCUR(sv) - old, &newlen);
12633 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12635 DEBUG_P({sv_dump(sv);});
12640 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12643 const STRLEN old = SvCUR(sv);
12644 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12645 DEBUG_P(PerlIO_printf(Perl_debug_log,
12646 "utf16rev_textfilter(%p): %d %d (%d)\n",
12647 FPTR2DPTR(void *, utf16rev_textfilter),
12648 idx, maxlen, (int) count));
12652 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12653 Copy(SvPVX_const(sv), tmps, old, char);
12654 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12655 SvCUR(sv) - old, &newlen);
12656 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12658 DEBUG_P({ sv_dump(sv); });
12664 Returns a pointer to the next character after the parsed
12665 vstring, as well as updating the passed in sv.
12667 Function must be called like
12670 s = scan_vstring(s,sv);
12672 The sv should already be large enough to store the vstring
12673 passed in, for performance reasons.
12678 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12681 const char *pos = s;
12682 const char *start = s;
12683 if (*pos == 'v') pos++; /* get past 'v' */
12684 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12686 if ( *pos != '.') {
12687 /* this may not be a v-string if followed by => */
12688 const char *next = pos;
12689 while (next < PL_bufend && isSPACE(*next))
12691 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12692 /* return string not v-string */
12693 sv_setpvn(sv,(char *)s,pos-s);
12694 return (char *)pos;
12698 if (!isALPHA(*pos)) {
12699 U8 tmpbuf[UTF8_MAXBYTES+1];
12702 s++; /* get past 'v' */
12704 sv_setpvn(sv, "", 0);
12707 /* this is atoi() that tolerates underscores */
12710 const char *end = pos;
12712 while (--end >= s) {
12714 const UV orev = rev;
12715 rev += (*end - '0') * mult;
12717 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12718 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12719 "Integer overflow in decimal number");
12723 if (rev > 0x7FFFFFFF)
12724 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12726 /* Append native character for the rev point */
12727 tmpend = uvchr_to_utf8(tmpbuf, rev);
12728 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12729 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12731 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12737 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12741 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12749 * c-indentation-style: bsd
12750 * c-basic-offset: 4
12751 * indent-tabs-mode: t
12754 * ex: set ts=8 sts=4 sw=4 noet: