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 yylval (PL_parser->yylval)
28 static const char ident_too_long[] = "Identifier too long";
29 static const char commaless_variable_list[] = "comma-less variable list";
31 static void restore_rsfp(pTHX_ void *f);
32 #ifndef PERL_NO_UTF16_FILTER
33 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
34 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
38 # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
39 # define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
41 # define CURMAD(slot,sv)
42 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
45 #define XFAKEBRACK 128
48 #ifdef USE_UTF8_SCRIPTS
49 # define UTF (!IN_BYTES)
51 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
54 /* In variables named $^X, these are the legal values for X.
55 * 1999-02-27 mjd-perl-patch@plover.com */
56 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
58 /* On MacOS, respect nonbreaking spaces */
59 #ifdef MACOS_TRADITIONAL
60 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
62 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
65 /* LEX_* are values for PL_lex_state, the state of the lexer.
66 * They are arranged oddly so that the guard on the switch statement
67 * can get by with a single comparison (if the compiler is smart enough).
70 /* #define LEX_NOTPARSING 11 is done in perl.h. */
72 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
73 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
74 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
75 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
76 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
78 /* at end of code, eg "$x" followed by: */
79 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
80 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
82 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
83 string or after \E, $foo, etc */
84 #define LEX_INTERPCONST 2 /* NOT USED */
85 #define LEX_FORMLINE 1 /* expecting a format line */
86 #define LEX_KNOWNEXT 0 /* next token known; just return it */
90 static const char* const lex_state_names[] = {
109 #include "keywords.h"
111 /* CLINE is a macro that ensures PL_copline has a sane value */
116 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
119 # define SKIPSPACE0(s) skipspace0(s)
120 # define SKIPSPACE1(s) skipspace1(s)
121 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
122 # define PEEKSPACE(s) skipspace2(s,0)
124 # define SKIPSPACE0(s) skipspace(s)
125 # define SKIPSPACE1(s) skipspace(s)
126 # define SKIPSPACE2(s,tsv) skipspace(s)
127 # define PEEKSPACE(s) skipspace(s)
131 * Convenience functions to return different tokens and prime the
132 * lexer for the next token. They all take an argument.
134 * TOKEN : generic token (used for '(', DOLSHARP, etc)
135 * OPERATOR : generic operator
136 * AOPERATOR : assignment operator
137 * PREBLOCK : beginning the block after an if, while, foreach, ...
138 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
139 * PREREF : *EXPR where EXPR is not a simple identifier
140 * TERM : expression term
141 * LOOPX : loop exiting command (goto, last, dump, etc)
142 * FTST : file test operator
143 * FUN0 : zero-argument function
144 * FUN1 : not used, except for not, which isn't a UNIOP
145 * BOop : bitwise or or xor
147 * SHop : shift operator
148 * PWop : power operator
149 * PMop : pattern-matching operator
150 * Aop : addition-level operator
151 * Mop : multiplication-level operator
152 * Eop : equality-testing operator
153 * Rop : relational operator <= != gt
155 * Also see LOP and lop() below.
158 #ifdef DEBUGGING /* Serve -DT. */
159 # define REPORT(retval) tokereport((I32)retval)
161 # define REPORT(retval) (retval)
164 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
165 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
166 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
167 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
168 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
169 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
170 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
171 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
172 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
173 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
174 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
175 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
176 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
177 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
178 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
179 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
180 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
181 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
182 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
183 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
185 /* This bit of chicanery makes a unary function followed by
186 * a parenthesis into a function with one argument, highest precedence.
187 * The UNIDOR macro is for unary functions that can be followed by the //
188 * operator (such as C<shift // 0>).
190 #define UNI2(f,x) { \
194 PL_last_uni = PL_oldbufptr; \
195 PL_last_lop_op = f; \
197 return REPORT( (int)FUNC1 ); \
199 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
201 #define UNI(f) UNI2(f,XTERM)
202 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
204 #define UNIBRACK(f) { \
207 PL_last_uni = PL_oldbufptr; \
209 return REPORT( (int)FUNC1 ); \
211 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
214 /* grandfather return to old style */
215 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
219 /* how to interpret the yylval associated with the token */
223 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
229 static struct debug_tokens {
231 enum token_type type;
233 } const debug_tokens[] =
235 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
236 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
237 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
238 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
239 { ARROW, TOKENTYPE_NONE, "ARROW" },
240 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
241 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
242 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
243 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
244 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
245 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
246 { DO, TOKENTYPE_NONE, "DO" },
247 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
248 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
249 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
250 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
251 { ELSE, TOKENTYPE_NONE, "ELSE" },
252 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
253 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
254 { FOR, TOKENTYPE_IVAL, "FOR" },
255 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
256 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
257 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
258 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
259 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
260 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
261 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
262 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
263 { IF, TOKENTYPE_IVAL, "IF" },
264 { LABEL, TOKENTYPE_PVAL, "LABEL" },
265 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
266 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
267 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
268 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
269 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
270 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
271 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
272 { MY, TOKENTYPE_IVAL, "MY" },
273 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
274 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
275 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
276 { OROP, TOKENTYPE_IVAL, "OROP" },
277 { OROR, TOKENTYPE_NONE, "OROR" },
278 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
279 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
280 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
281 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
282 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
283 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
284 { PREINC, TOKENTYPE_NONE, "PREINC" },
285 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
286 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
287 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
288 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
289 { SUB, TOKENTYPE_NONE, "SUB" },
290 { THING, TOKENTYPE_OPVAL, "THING" },
291 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
292 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
293 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
294 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
295 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
296 { USE, TOKENTYPE_IVAL, "USE" },
297 { WHEN, TOKENTYPE_IVAL, "WHEN" },
298 { WHILE, TOKENTYPE_IVAL, "WHILE" },
299 { WORD, TOKENTYPE_OPVAL, "WORD" },
300 { 0, TOKENTYPE_NONE, NULL }
303 /* dump the returned token in rv, plus any optional arg in yylval */
306 S_tokereport(pTHX_ I32 rv)
310 const char *name = NULL;
311 enum token_type type = TOKENTYPE_NONE;
312 const struct debug_tokens *p;
313 SV* const report = newSVpvs("<== ");
315 for (p = debug_tokens; p->token; p++) {
316 if (p->token == (int)rv) {
323 Perl_sv_catpv(aTHX_ report, name);
324 else if ((char)rv > ' ' && (char)rv < '~')
325 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
327 sv_catpvs(report, "EOF");
329 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
332 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
335 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
337 case TOKENTYPE_OPNUM:
338 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
339 PL_op_name[yylval.ival]);
342 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
344 case TOKENTYPE_OPVAL:
346 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
347 PL_op_name[yylval.opval->op_type]);
348 if (yylval.opval->op_type == OP_CONST) {
349 Perl_sv_catpvf(aTHX_ report, " %s",
350 SvPEEK(cSVOPx_sv(yylval.opval)));
355 sv_catpvs(report, "(opval=null)");
358 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
364 /* print the buffer with suitable escapes */
367 S_printbuf(pTHX_ const char* fmt, const char* s)
369 SV* const tmp = newSVpvs("");
370 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
379 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
380 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
384 S_ao(pTHX_ int toketype)
387 if (*PL_bufptr == '=') {
389 if (toketype == ANDAND)
390 yylval.ival = OP_ANDASSIGN;
391 else if (toketype == OROR)
392 yylval.ival = OP_ORASSIGN;
393 else if (toketype == DORDOR)
394 yylval.ival = OP_DORASSIGN;
402 * When Perl expects an operator and finds something else, no_op
403 * prints the warning. It always prints "<something> found where
404 * operator expected. It prints "Missing semicolon on previous line?"
405 * if the surprise occurs at the start of the line. "do you need to
406 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
407 * where the compiler doesn't know if foo is a method call or a function.
408 * It prints "Missing operator before end of line" if there's nothing
409 * after the missing operator, or "... before <...>" if there is something
410 * after the missing operator.
414 S_no_op(pTHX_ const char *what, char *s)
417 char * const oldbp = PL_bufptr;
418 const bool is_first = (PL_oldbufptr == PL_linestart);
424 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
425 if (ckWARN_d(WARN_SYNTAX)) {
427 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
428 "\t(Missing semicolon on previous line?)\n");
429 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
431 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
433 if (t < PL_bufptr && isSPACE(*t))
434 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
435 "\t(Do you need to predeclare %.*s?)\n",
436 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
440 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
441 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
449 * Complain about missing quote/regexp/heredoc terminator.
450 * If it's called with NULL then it cauterizes the line buffer.
451 * If we're in a delimited string and the delimiter is a control
452 * character, it's reformatted into a two-char sequence like ^C.
457 S_missingterm(pTHX_ char *s)
463 char * const nl = strrchr(s,'\n');
469 iscntrl(PL_multi_close)
471 PL_multi_close < 32 || PL_multi_close == 127
475 tmpbuf[1] = (char)toCTRL(PL_multi_close);
480 *tmpbuf = (char)PL_multi_close;
484 q = strchr(s,'"') ? '\'' : '"';
485 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
488 #define FEATURE_IS_ENABLED(name) \
489 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
490 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
492 * S_feature_is_enabled
493 * Check whether the named feature is enabled.
496 S_feature_is_enabled(pTHX_ const char *name, STRLEN namelen)
499 HV * const hinthv = GvHV(PL_hintgv);
500 char he_name[32] = "feature_";
501 (void) my_strlcpy(&he_name[8], name, 24);
503 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
511 Perl_deprecate(pTHX_ const char *s)
513 if (ckWARN(WARN_DEPRECATED))
514 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
518 Perl_deprecate_old(pTHX_ const char *s)
520 /* This function should NOT be called for any new deprecated warnings */
521 /* Use Perl_deprecate instead */
523 /* It is here to maintain backward compatibility with the pre-5.8 */
524 /* warnings category hierarchy. The "deprecated" category used to */
525 /* live under the "syntax" category. It is now a top-level category */
526 /* in its own right. */
528 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
529 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
530 "Use of %s is deprecated", s);
534 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
535 * utf16-to-utf8-reversed.
538 #ifdef PERL_CR_FILTER
542 register const char *s = SvPVX_const(sv);
543 register const char * const e = s + SvCUR(sv);
544 /* outer loop optimized to do nothing if there are no CR-LFs */
546 if (*s++ == '\r' && *s == '\n') {
547 /* hit a CR-LF, need to copy the rest */
548 register char *d = s - 1;
551 if (*s == '\r' && s[1] == '\n')
562 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
564 const I32 count = FILTER_READ(idx+1, sv, maxlen);
565 if (count > 0 && !maxlen)
573 * Initialize variables. Uses the Perl save_stack to save its state (for
574 * recursive calls to the parser).
578 Perl_lex_start(pTHX_ SV *line)
584 SAVEI32(PL_lex_dojoin);
585 SAVEI32(PL_lex_brackets);
586 SAVEI32(PL_lex_casemods);
587 SAVEI32(PL_lex_starts);
588 SAVEI32(PL_lex_state);
589 SAVEVPTR(PL_lex_inpat);
590 SAVEI32(PL_lex_inwhat);
592 if (PL_lex_state == LEX_KNOWNEXT) {
593 I32 toke = PL_lasttoke;
594 while (--toke >= 0) {
595 SAVEI32(PL_nexttoke[toke].next_type);
596 SAVEVPTR(PL_nexttoke[toke].next_val);
598 SAVEVPTR(PL_nexttoke[toke].next_mad);
600 SAVEI32(PL_lasttoke);
603 SAVESPTR(PL_thistoken);
604 SAVESPTR(PL_thiswhite);
605 SAVESPTR(PL_nextwhite);
606 SAVESPTR(PL_thisopen);
607 SAVESPTR(PL_thisclose);
608 SAVESPTR(PL_thisstuff);
609 SAVEVPTR(PL_thismad);
610 SAVEI32(PL_realtokenstart);
611 SAVEI32(PL_faketokens);
613 SAVEI32(PL_curforce);
615 if (PL_lex_state == LEX_KNOWNEXT) {
616 I32 toke = PL_nexttoke;
617 while (--toke >= 0) {
618 SAVEI32(PL_nexttype[toke]);
619 SAVEVPTR(PL_nextval[toke]);
621 SAVEI32(PL_nexttoke);
624 SAVECOPLINE(PL_curcop);
627 SAVEPPTR(PL_oldbufptr);
628 SAVEPPTR(PL_oldoldbufptr);
629 SAVEPPTR(PL_last_lop);
630 SAVEPPTR(PL_last_uni);
631 SAVEPPTR(PL_linestart);
632 SAVESPTR(PL_linestr);
633 SAVEGENERICPV(PL_lex_brackstack);
634 SAVEGENERICPV(PL_lex_casestack);
635 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
636 SAVESPTR(PL_lex_stuff);
637 SAVEI32(PL_lex_defer);
638 SAVEI32(PL_sublex_info.sub_inwhat);
639 SAVESPTR(PL_lex_repl);
641 SAVEINT(PL_lex_expect);
643 PL_lex_state = LEX_NORMAL;
647 Newx(PL_lex_brackstack, 120, char);
648 Newx(PL_lex_casestack, 12, char);
650 *PL_lex_casestack = '\0';
662 PL_sublex_info.sub_inwhat = 0;
663 s = SvPV_const(line, len);
664 if (SvREADONLY(line) || !len || s[len-1] != ';') {
665 PL_linestr = len ? newSVsv(line) : newSVpvn(s, 0);
666 if (!len || s[len-1] != ';')
667 sv_catpvs(PL_linestr, "\n;");
670 SvREFCNT_inc_simple_void_NN(line);
673 /* PL_linestr needs to survive until end of scope, not just the next
674 FREETMPS. See changes 17505 and 17546 which fixed the symptoms only. */
675 SAVEFREESV(PL_linestr);
676 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
677 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
678 PL_last_lop = PL_last_uni = NULL;
684 * Finalizer for lexing operations. Must be called when the parser is
685 * done with the lexer.
692 PL_doextract = FALSE;
697 * This subroutine has nothing to do with tilting, whether at windmills
698 * or pinball tables. Its name is short for "increment line". It
699 * increments the current line number in CopLINE(PL_curcop) and checks
700 * to see whether the line starts with a comment of the form
701 * # line 500 "foo.pm"
702 * If so, it sets the current line number and file to the values in the comment.
706 S_incline(pTHX_ char *s)
714 CopLINE_inc(PL_curcop);
717 while (SPACE_OR_TAB(*s))
719 if (strnEQ(s, "line", 4))
723 if (SPACE_OR_TAB(*s))
727 while (SPACE_OR_TAB(*s))
735 while (SPACE_OR_TAB(*s))
737 if (*s == '"' && (t = strchr(s+1, '"'))) {
747 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
749 if (*e != '\n' && *e != '\0')
750 return; /* false alarm */
756 const char * const cf = CopFILE(PL_curcop);
757 STRLEN tmplen = cf ? strlen(cf) : 0;
758 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
759 /* must copy *{"::_<(eval N)[oldfilename:L]"}
760 * to *{"::_<newfilename"} */
761 char smallbuf[256], smallbuf2[256];
762 char *tmpbuf, *tmpbuf2;
764 STRLEN tmplen2 = strlen(s);
765 if (tmplen + 3 < sizeof smallbuf)
768 Newx(tmpbuf, tmplen + 3, char);
769 if (tmplen2 + 3 < sizeof smallbuf2)
772 Newx(tmpbuf2, tmplen2 + 3, char);
773 tmpbuf[0] = tmpbuf2[0] = '_';
774 tmpbuf[1] = tmpbuf2[1] = '<';
775 memcpy(tmpbuf + 2, cf, ++tmplen);
776 memcpy(tmpbuf2 + 2, s, ++tmplen2);
778 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
780 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
782 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
783 /* adjust ${"::_<newfilename"} to store the new file name */
784 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
785 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
786 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
789 if (tmpbuf != smallbuf) Safefree(tmpbuf);
790 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
793 CopFILE_free(PL_curcop);
794 CopFILE_set(PL_curcop, s);
797 CopLINE_set(PL_curcop, atoi(n)-1);
801 /* skip space before PL_thistoken */
804 S_skipspace0(pTHX_ register char *s)
811 PL_thiswhite = newSVpvs("");
812 sv_catsv(PL_thiswhite, PL_skipwhite);
813 sv_free(PL_skipwhite);
816 PL_realtokenstart = s - SvPVX(PL_linestr);
820 /* skip space after PL_thistoken */
823 S_skipspace1(pTHX_ register char *s)
825 const char *start = s;
826 I32 startoff = start - SvPVX(PL_linestr);
831 start = SvPVX(PL_linestr) + startoff;
832 if (!PL_thistoken && PL_realtokenstart >= 0) {
833 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
834 PL_thistoken = newSVpvn(tstart, start - tstart);
836 PL_realtokenstart = -1;
839 PL_nextwhite = newSVpvs("");
840 sv_catsv(PL_nextwhite, PL_skipwhite);
841 sv_free(PL_skipwhite);
848 S_skipspace2(pTHX_ register char *s, SV **svp)
851 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
852 const I32 startoff = s - SvPVX(PL_linestr);
855 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
856 if (!PL_madskills || !svp)
858 start = SvPVX(PL_linestr) + startoff;
859 if (!PL_thistoken && PL_realtokenstart >= 0) {
860 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
861 PL_thistoken = newSVpvn(tstart, start - tstart);
862 PL_realtokenstart = -1;
867 sv_setsv(*svp, PL_skipwhite);
868 sv_free(PL_skipwhite);
877 S_update_debugger_info_pv(pTHX_ const char *buf, STRLEN len)
879 AV *av = CopFILEAVx(PL_curcop);
881 SV * const sv = newSV(0);
882 sv_upgrade(sv, SVt_PVMG);
883 sv_setpvn(sv, buf, len);
886 av_store(av, (I32)CopLINE(PL_curcop), sv);
891 S_update_debugger_info_sv(pTHX_ SV *orig_sv)
893 AV *av = CopFILEAVx(PL_curcop);
895 SV * const sv = newSV(0);
896 sv_upgrade(sv, SVt_PVMG);
897 sv_setsv(sv, orig_sv);
900 av_store(av, (I32)CopLINE(PL_curcop), sv);
906 * Called to gobble the appropriate amount and type of whitespace.
907 * Skips comments as well.
911 S_skipspace(pTHX_ register char *s)
916 int startoff = s - SvPVX(PL_linestr);
919 sv_free(PL_skipwhite);
924 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
925 while (s < PL_bufend && SPACE_OR_TAB(*s))
935 SSize_t oldprevlen, oldoldprevlen;
936 SSize_t oldloplen = 0, oldunilen = 0;
937 while (s < PL_bufend && isSPACE(*s)) {
938 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
943 if (s < PL_bufend && *s == '#') {
944 while (s < PL_bufend && *s != '\n')
948 if (PL_in_eval && !PL_rsfp) {
955 /* only continue to recharge the buffer if we're at the end
956 * of the buffer, we're not reading from a source filter, and
957 * we're in normal lexing mode
959 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
960 PL_lex_state == LEX_FORMLINE)
967 /* try to recharge the buffer */
969 curoff = s - SvPVX(PL_linestr);
972 if ((s = filter_gets(PL_linestr, PL_rsfp,
973 (prevlen = SvCUR(PL_linestr)))) == NULL)
976 if (PL_madskills && curoff != startoff) {
978 PL_skipwhite = newSVpvs("");
979 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
983 /* mustn't throw out old stuff yet if madpropping */
984 SvCUR(PL_linestr) = curoff;
985 s = SvPVX(PL_linestr) + curoff;
987 if (curoff && s[-1] == '\n')
991 /* end of file. Add on the -p or -n magic */
992 /* XXX these shouldn't really be added here, can't set PL_faketokens */
996 ";}continue{print or die qq(-p destination: $!\\n);}");
999 ";}continue{print or die qq(-p destination: $!\\n);}");
1001 PL_minus_n = PL_minus_p = 0;
1003 else if (PL_minus_n) {
1005 sv_catpvn(PL_linestr, ";}", 2);
1007 sv_setpvn(PL_linestr, ";}", 2);
1013 sv_catpvn(PL_linestr,";", 1);
1015 sv_setpvn(PL_linestr,";", 1);
1018 /* reset variables for next time we lex */
1019 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
1025 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1026 PL_last_lop = PL_last_uni = NULL;
1028 /* Close the filehandle. Could be from -P preprocessor,
1029 * STDIN, or a regular file. If we were reading code from
1030 * STDIN (because the commandline held no -e or filename)
1031 * then we don't close it, we reset it so the code can
1032 * read from STDIN too.
1035 if (PL_preprocess && !PL_in_eval)
1036 (void)PerlProc_pclose(PL_rsfp);
1037 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1038 PerlIO_clearerr(PL_rsfp);
1040 (void)PerlIO_close(PL_rsfp);
1045 /* not at end of file, so we only read another line */
1046 /* make corresponding updates to old pointers, for yyerror() */
1047 oldprevlen = PL_oldbufptr - PL_bufend;
1048 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1050 oldunilen = PL_last_uni - PL_bufend;
1052 oldloplen = PL_last_lop - PL_bufend;
1053 PL_linestart = PL_bufptr = s + prevlen;
1054 PL_bufend = s + SvCUR(PL_linestr);
1056 PL_oldbufptr = s + oldprevlen;
1057 PL_oldoldbufptr = s + oldoldprevlen;
1059 PL_last_uni = s + oldunilen;
1061 PL_last_lop = s + oldloplen;
1064 /* debugger active and we're not compiling the debugger code,
1065 * so store the line into the debugger's array of lines
1067 if (PERLDB_LINE && PL_curstash != PL_debstash)
1068 update_debugger_info_pv(PL_bufptr, PL_bufend - PL_bufptr);
1075 PL_skipwhite = newSVpvs("");
1076 curoff = s - SvPVX(PL_linestr);
1077 if (curoff - startoff)
1078 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1087 * Check the unary operators to ensure there's no ambiguity in how they're
1088 * used. An ambiguous piece of code would be:
1090 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1091 * the +5 is its argument.
1101 if (PL_oldoldbufptr != PL_last_uni)
1103 while (isSPACE(*PL_last_uni))
1106 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1108 if ((t = strchr(s, '(')) && t < PL_bufptr)
1111 if (ckWARN_d(WARN_AMBIGUOUS)){
1112 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1113 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1114 (int)(s - PL_last_uni), PL_last_uni);
1119 * LOP : macro to build a list operator. Its behaviour has been replaced
1120 * with a subroutine, S_lop() for which LOP is just another name.
1123 #define LOP(f,x) return lop(f,x,s)
1127 * Build a list operator (or something that might be one). The rules:
1128 * - if we have a next token, then it's a list operator [why?]
1129 * - if the next thing is an opening paren, then it's a function
1130 * - else it's a list operator
1134 S_lop(pTHX_ I32 f, int x, char *s)
1141 PL_last_lop = PL_oldbufptr;
1142 PL_last_lop_op = (OPCODE)f;
1145 return REPORT(LSTOP);
1148 return REPORT(LSTOP);
1151 return REPORT(FUNC);
1154 return REPORT(FUNC);
1156 return REPORT(LSTOP);
1162 * Sets up for an eventual force_next(). start_force(0) basically does
1163 * an unshift, while start_force(-1) does a push. yylex removes items
1168 S_start_force(pTHX_ int where)
1172 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1173 where = PL_lasttoke;
1174 assert(PL_curforce < 0 || PL_curforce == where);
1175 if (PL_curforce != where) {
1176 for (i = PL_lasttoke; i > where; --i) {
1177 PL_nexttoke[i] = PL_nexttoke[i-1];
1181 if (PL_curforce < 0) /* in case of duplicate start_force() */
1182 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1183 PL_curforce = where;
1186 curmad('^', newSVpvs(""));
1187 CURMAD('_', PL_nextwhite);
1192 S_curmad(pTHX_ char slot, SV *sv)
1198 if (PL_curforce < 0)
1199 where = &PL_thismad;
1201 where = &PL_nexttoke[PL_curforce].next_mad;
1204 sv_setpvn(sv, "", 0);
1207 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1209 else if (PL_encoding) {
1210 sv_recode_to_utf8(sv, PL_encoding);
1215 /* keep a slot open for the head of the list? */
1216 if (slot != '_' && *where && (*where)->mad_key == '^') {
1217 (*where)->mad_key = slot;
1218 sv_free((*where)->mad_val);
1219 (*where)->mad_val = (void*)sv;
1222 addmad(newMADsv(slot, sv), where, 0);
1225 # define start_force(where) NOOP
1226 # define curmad(slot, sv) NOOP
1231 * When the lexer realizes it knows the next token (for instance,
1232 * it is reordering tokens for the parser) then it can call S_force_next
1233 * to know what token to return the next time the lexer is called. Caller
1234 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1235 * and possibly PL_expect to ensure the lexer handles the token correctly.
1239 S_force_next(pTHX_ I32 type)
1243 if (PL_curforce < 0)
1244 start_force(PL_lasttoke);
1245 PL_nexttoke[PL_curforce].next_type = type;
1246 if (PL_lex_state != LEX_KNOWNEXT)
1247 PL_lex_defer = PL_lex_state;
1248 PL_lex_state = LEX_KNOWNEXT;
1249 PL_lex_expect = PL_expect;
1252 PL_nexttype[PL_nexttoke] = type;
1254 if (PL_lex_state != LEX_KNOWNEXT) {
1255 PL_lex_defer = PL_lex_state;
1256 PL_lex_expect = PL_expect;
1257 PL_lex_state = LEX_KNOWNEXT;
1263 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1266 SV * const sv = newSVpvn(start,len);
1267 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1274 * When the lexer knows the next thing is a word (for instance, it has
1275 * just seen -> and it knows that the next char is a word char, then
1276 * it calls S_force_word to stick the next word into the PL_next lookahead.
1279 * char *start : buffer position (must be within PL_linestr)
1280 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
1281 * int check_keyword : if true, Perl checks to make sure the word isn't
1282 * a keyword (do this if the word is a label, e.g. goto FOO)
1283 * int allow_pack : if true, : characters will also be allowed (require,
1284 * use, etc. do this)
1285 * int allow_initial_tick : used by the "sub" lexer only.
1289 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1295 start = SKIPSPACE1(start);
1297 if (isIDFIRST_lazy_if(s,UTF) ||
1298 (allow_pack && *s == ':') ||
1299 (allow_initial_tick && *s == '\'') )
1301 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1302 if (check_keyword && keyword(PL_tokenbuf, len, 0))
1304 start_force(PL_curforce);
1306 curmad('X', newSVpvn(start,s-start));
1307 if (token == METHOD) {
1312 PL_expect = XOPERATOR;
1315 NEXTVAL_NEXTTOKE.opval
1316 = (OP*)newSVOP(OP_CONST,0,
1317 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1318 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1326 * Called when the lexer wants $foo *foo &foo etc, but the program
1327 * text only contains the "foo" portion. The first argument is a pointer
1328 * to the "foo", and the second argument is the type symbol to prefix.
1329 * Forces the next token to be a "WORD".
1330 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1334 S_force_ident(pTHX_ register const char *s, int kind)
1338 const STRLEN len = strlen(s);
1339 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1340 start_force(PL_curforce);
1341 NEXTVAL_NEXTTOKE.opval = o;
1344 o->op_private = OPpCONST_ENTERED;
1345 /* XXX see note in pp_entereval() for why we forgo typo
1346 warnings if the symbol must be introduced in an eval.
1348 gv_fetchpvn_flags(s, len,
1349 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1351 kind == '$' ? SVt_PV :
1352 kind == '@' ? SVt_PVAV :
1353 kind == '%' ? SVt_PVHV :
1361 Perl_str_to_version(pTHX_ SV *sv)
1366 const char *start = SvPV_const(sv,len);
1367 const char * const end = start + len;
1368 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1369 while (start < end) {
1373 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1378 retval += ((NV)n)/nshift;
1387 * Forces the next token to be a version number.
1388 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1389 * and if "guessing" is TRUE, then no new token is created (and the caller
1390 * must use an alternative parsing method).
1394 S_force_version(pTHX_ char *s, int guessing)
1400 I32 startoff = s - SvPVX(PL_linestr);
1409 while (isDIGIT(*d) || *d == '_' || *d == '.')
1413 start_force(PL_curforce);
1414 curmad('X', newSVpvn(s,d-s));
1417 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1419 s = scan_num(s, &yylval);
1420 version = yylval.opval;
1421 ver = cSVOPx(version)->op_sv;
1422 if (SvPOK(ver) && !SvNIOK(ver)) {
1423 SvUPGRADE(ver, SVt_PVNV);
1424 SvNV_set(ver, str_to_version(ver));
1425 SvNOK_on(ver); /* hint that it is a version */
1428 else if (guessing) {
1431 sv_free(PL_nextwhite); /* let next token collect whitespace */
1433 s = SvPVX(PL_linestr) + startoff;
1441 if (PL_madskills && !version) {
1442 sv_free(PL_nextwhite); /* let next token collect whitespace */
1444 s = SvPVX(PL_linestr) + startoff;
1447 /* NOTE: The parser sees the package name and the VERSION swapped */
1448 start_force(PL_curforce);
1449 NEXTVAL_NEXTTOKE.opval = version;
1457 * Tokenize a quoted string passed in as an SV. It finds the next
1458 * chunk, up to end of string or a backslash. It may make a new
1459 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1464 S_tokeq(pTHX_ SV *sv)
1468 register char *send;
1476 s = SvPV_force(sv, len);
1477 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1480 while (s < send && *s != '\\')
1485 if ( PL_hints & HINT_NEW_STRING ) {
1486 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1492 if (s + 1 < send && (s[1] == '\\'))
1493 s++; /* all that, just for this */
1498 SvCUR_set(sv, d - SvPVX_const(sv));
1500 if ( PL_hints & HINT_NEW_STRING )
1501 return new_constant(NULL, 0, "q", sv, pv, "q");
1506 * Now come three functions related to double-quote context,
1507 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1508 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1509 * interact with PL_lex_state, and create fake ( ... ) argument lists
1510 * to handle functions and concatenation.
1511 * They assume that whoever calls them will be setting up a fake
1512 * join call, because each subthing puts a ',' after it. This lets
1515 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1517 * (I'm not sure whether the spurious commas at the end of lcfirst's
1518 * arguments and join's arguments are created or not).
1523 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1525 * Pattern matching will set PL_lex_op to the pattern-matching op to
1526 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1528 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1530 * Everything else becomes a FUNC.
1532 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1533 * had an OP_CONST or OP_READLINE). This just sets us up for a
1534 * call to S_sublex_push().
1538 S_sublex_start(pTHX)
1541 register const I32 op_type = yylval.ival;
1543 if (op_type == OP_NULL) {
1544 yylval.opval = PL_lex_op;
1548 if (op_type == OP_CONST || op_type == OP_READLINE) {
1549 SV *sv = tokeq(PL_lex_stuff);
1551 if (SvTYPE(sv) == SVt_PVIV) {
1552 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1554 const char * const p = SvPV_const(sv, len);
1555 SV * const nsv = newSVpvn(p, len);
1561 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1562 PL_lex_stuff = NULL;
1563 /* Allow <FH> // "foo" */
1564 if (op_type == OP_READLINE)
1565 PL_expect = XTERMORDORDOR;
1568 else if (op_type == OP_BACKTICK && PL_lex_op) {
1569 /* readpipe() vas overriden */
1570 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1571 yylval.opval = PL_lex_op;
1573 PL_lex_stuff = NULL;
1577 PL_sublex_info.super_state = PL_lex_state;
1578 PL_sublex_info.sub_inwhat = op_type;
1579 PL_sublex_info.sub_op = PL_lex_op;
1580 PL_lex_state = LEX_INTERPPUSH;
1584 yylval.opval = PL_lex_op;
1594 * Create a new scope to save the lexing state. The scope will be
1595 * ended in S_sublex_done. Returns a '(', starting the function arguments
1596 * to the uc, lc, etc. found before.
1597 * Sets PL_lex_state to LEX_INTERPCONCAT.
1606 PL_lex_state = PL_sublex_info.super_state;
1607 SAVEI32(PL_lex_dojoin);
1608 SAVEI32(PL_lex_brackets);
1609 SAVEI32(PL_lex_casemods);
1610 SAVEI32(PL_lex_starts);
1611 SAVEI32(PL_lex_state);
1612 SAVEVPTR(PL_lex_inpat);
1613 SAVEI32(PL_lex_inwhat);
1614 SAVECOPLINE(PL_curcop);
1615 SAVEPPTR(PL_bufptr);
1616 SAVEPPTR(PL_bufend);
1617 SAVEPPTR(PL_oldbufptr);
1618 SAVEPPTR(PL_oldoldbufptr);
1619 SAVEPPTR(PL_last_lop);
1620 SAVEPPTR(PL_last_uni);
1621 SAVEPPTR(PL_linestart);
1622 SAVESPTR(PL_linestr);
1623 SAVEGENERICPV(PL_lex_brackstack);
1624 SAVEGENERICPV(PL_lex_casestack);
1626 PL_linestr = PL_lex_stuff;
1627 PL_lex_stuff = NULL;
1629 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1630 = SvPVX(PL_linestr);
1631 PL_bufend += SvCUR(PL_linestr);
1632 PL_last_lop = PL_last_uni = NULL;
1633 SAVEFREESV(PL_linestr);
1635 PL_lex_dojoin = FALSE;
1636 PL_lex_brackets = 0;
1637 Newx(PL_lex_brackstack, 120, char);
1638 Newx(PL_lex_casestack, 12, char);
1639 PL_lex_casemods = 0;
1640 *PL_lex_casestack = '\0';
1642 PL_lex_state = LEX_INTERPCONCAT;
1643 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1645 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1646 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1647 PL_lex_inpat = PL_sublex_info.sub_op;
1649 PL_lex_inpat = NULL;
1656 * Restores lexer state after a S_sublex_push.
1663 if (!PL_lex_starts++) {
1664 SV * const sv = newSVpvs("");
1665 if (SvUTF8(PL_linestr))
1667 PL_expect = XOPERATOR;
1668 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1672 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1673 PL_lex_state = LEX_INTERPCASEMOD;
1677 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1678 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1679 PL_linestr = PL_lex_repl;
1681 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1682 PL_bufend += SvCUR(PL_linestr);
1683 PL_last_lop = PL_last_uni = NULL;
1684 SAVEFREESV(PL_linestr);
1685 PL_lex_dojoin = FALSE;
1686 PL_lex_brackets = 0;
1687 PL_lex_casemods = 0;
1688 *PL_lex_casestack = '\0';
1690 if (SvEVALED(PL_lex_repl)) {
1691 PL_lex_state = LEX_INTERPNORMAL;
1693 /* we don't clear PL_lex_repl here, so that we can check later
1694 whether this is an evalled subst; that means we rely on the
1695 logic to ensure sublex_done() is called again only via the
1696 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1699 PL_lex_state = LEX_INTERPCONCAT;
1709 PL_endwhite = newSVpvs("");
1710 sv_catsv(PL_endwhite, PL_thiswhite);
1714 sv_setpvn(PL_thistoken,"",0);
1716 PL_realtokenstart = -1;
1720 PL_bufend = SvPVX(PL_linestr);
1721 PL_bufend += SvCUR(PL_linestr);
1722 PL_expect = XOPERATOR;
1723 PL_sublex_info.sub_inwhat = 0;
1731 Extracts a pattern, double-quoted string, or transliteration. This
1734 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
1735 processing a pattern (PL_lex_inpat is true), a transliteration
1736 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
1738 Returns a pointer to the character scanned up to. If this is
1739 advanced from the start pointer supplied (i.e. if anything was
1740 successfully parsed), will leave an OP for the substring scanned
1741 in yylval. Caller must intuit reason for not parsing further
1742 by looking at the next characters herself.
1746 double-quoted style: \r and \n
1747 regexp special ones: \D \s
1750 case and quoting: \U \Q \E
1751 stops on @ and $, but not for $ as tail anchor
1753 In transliterations:
1754 characters are VERY literal, except for - not at the start or end
1755 of the string, which indicates a range. If the range is in bytes,
1756 scan_const expands the range to the full set of intermediate
1757 characters. If the range is in utf8, the hyphen is replaced with
1758 a certain range mark which will be handled by pmtrans() in op.c.
1760 In double-quoted strings:
1762 double-quoted style: \r and \n
1764 deprecated backrefs: \1 (in substitution replacements)
1765 case and quoting: \U \Q \E
1768 scan_const does *not* construct ops to handle interpolated strings.
1769 It stops processing as soon as it finds an embedded $ or @ variable
1770 and leaves it to the caller to work out what's going on.
1772 embedded arrays (whether in pattern or not) could be:
1773 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1775 $ in double-quoted strings must be the symbol of an embedded scalar.
1777 $ in pattern could be $foo or could be tail anchor. Assumption:
1778 it's a tail anchor if $ is the last thing in the string, or if it's
1779 followed by one of "()| \r\n\t"
1781 \1 (backreferences) are turned into $1
1783 The structure of the code is
1784 while (there's a character to process) {
1785 handle transliteration ranges
1786 skip regexp comments /(?#comment)/ and codes /(?{code})/
1787 skip #-initiated comments in //x patterns
1788 check for embedded arrays
1789 check for embedded scalars
1791 leave intact backslashes from leaveit (below)
1792 deprecate \1 in substitution replacements
1793 handle string-changing backslashes \l \U \Q \E, etc.
1794 switch (what was escaped) {
1795 handle \- in a transliteration (becomes a literal -)
1796 handle \132 (octal characters)
1797 handle \x15 and \x{1234} (hex characters)
1798 handle \N{name} (named characters)
1799 handle \cV (control characters)
1800 handle printf-style backslashes (\f, \r, \n, etc)
1802 } (end if backslash)
1803 } (end while character to read)
1808 S_scan_const(pTHX_ char *start)
1811 register char *send = PL_bufend; /* end of the constant */
1812 SV *sv = newSV(send - start); /* sv for the constant */
1813 register char *s = start; /* start of the constant */
1814 register char *d = SvPVX(sv); /* destination for copies */
1815 bool dorange = FALSE; /* are we in a translit range? */
1816 bool didrange = FALSE; /* did we just finish a range? */
1817 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1818 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1821 UV literal_endpoint = 0;
1822 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
1825 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1826 /* If we are doing a trans and we know we want UTF8 set expectation */
1827 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1828 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1832 while (s < send || dorange) {
1833 /* get transliterations out of the way (they're most literal) */
1834 if (PL_lex_inwhat == OP_TRANS) {
1835 /* expand a range A-Z to the full set of characters. AIE! */
1837 I32 i; /* current expanded character */
1838 I32 min; /* first character in range */
1839 I32 max; /* last character in range */
1850 char * const c = (char*)utf8_hop((U8*)d, -1);
1854 *c = (char)UTF_TO_NATIVE(0xff);
1855 /* mark the range as done, and continue */
1861 i = d - SvPVX_const(sv); /* remember current offset */
1864 SvLEN(sv) + (has_utf8 ?
1865 (512 - UTF_CONTINUATION_MARK +
1868 /* How many two-byte within 0..255: 128 in UTF-8,
1869 * 96 in UTF-8-mod. */
1871 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1873 d = SvPVX(sv) + i; /* refresh d after realloc */
1877 for (j = 0; j <= 1; j++) {
1878 char * const c = (char*)utf8_hop((U8*)d, -1);
1879 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
1885 max = (U8)0xff; /* only to \xff */
1886 uvmax = uv; /* \x{100} to uvmax */
1888 d = c; /* eat endpoint chars */
1893 d -= 2; /* eat the first char and the - */
1894 min = (U8)*d; /* first char in range */
1895 max = (U8)d[1]; /* last char in range */
1902 "Invalid range \"%c-%c\" in transliteration operator",
1903 (char)min, (char)max);
1907 if (literal_endpoint == 2 &&
1908 ((isLOWER(min) && isLOWER(max)) ||
1909 (isUPPER(min) && isUPPER(max)))) {
1911 for (i = min; i <= max; i++)
1913 *d++ = NATIVE_TO_NEED(has_utf8,i);
1915 for (i = min; i <= max; i++)
1917 *d++ = NATIVE_TO_NEED(has_utf8,i);
1922 for (i = min; i <= max; i++)
1925 const U8 ch = (U8)NATIVE_TO_UTF(i);
1926 if (UNI_IS_INVARIANT(ch))
1929 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
1930 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
1939 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
1941 *d++ = (char)UTF_TO_NATIVE(0xff);
1943 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
1947 /* mark the range as done, and continue */
1951 literal_endpoint = 0;
1956 /* range begins (ignore - as first or last char) */
1957 else if (*s == '-' && s+1 < send && s != start) {
1959 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1966 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1976 literal_endpoint = 0;
1977 native_range = TRUE;
1982 /* if we get here, we're not doing a transliteration */
1984 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1985 except for the last char, which will be done separately. */
1986 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1988 while (s+1 < send && *s != ')')
1989 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1991 else if (s[2] == '{' /* This should match regcomp.c */
1992 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1995 char *regparse = s + (s[2] == '{' ? 3 : 4);
1998 while (count && (c = *regparse)) {
1999 if (c == '\\' && regparse[1])
2007 if (*regparse != ')')
2008 regparse--; /* Leave one char for continuation. */
2009 while (s < regparse)
2010 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2014 /* likewise skip #-initiated comments in //x patterns */
2015 else if (*s == '#' && PL_lex_inpat &&
2016 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2017 while (s+1 < send && *s != '\n')
2018 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2021 /* check for embedded arrays
2022 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2024 else if (*s == '@' && s[1]) {
2025 if (isALNUM_lazy_if(s+1,UTF))
2027 if (strchr(":'{$", s[1]))
2029 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2030 break; /* in regexp, neither @+ nor @- are interpolated */
2033 /* check for embedded scalars. only stop if we're sure it's a
2036 else if (*s == '$') {
2037 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
2039 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
2040 break; /* in regexp, $ might be tail anchor */
2043 /* End of else if chain - OP_TRANS rejoin rest */
2046 if (*s == '\\' && s+1 < send) {
2049 /* deprecate \1 in strings and substitution replacements */
2050 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2051 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2053 if (ckWARN(WARN_SYNTAX))
2054 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2059 /* string-change backslash escapes */
2060 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2064 /* skip any other backslash escapes in a pattern */
2065 else if (PL_lex_inpat) {
2066 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2067 goto default_action;
2070 /* if we get here, it's either a quoted -, or a digit */
2073 /* quoted - in transliterations */
2075 if (PL_lex_inwhat == OP_TRANS) {
2082 if ((isALPHA(*s) || isDIGIT(*s)) &&
2084 Perl_warner(aTHX_ packWARN(WARN_MISC),
2085 "Unrecognized escape \\%c passed through",
2087 /* default action is to copy the quoted character */
2088 goto default_action;
2091 /* \132 indicates an octal constant */
2092 case '0': case '1': case '2': case '3':
2093 case '4': case '5': case '6': case '7':
2097 uv = grok_oct(s, &len, &flags, NULL);
2100 goto NUM_ESCAPE_INSERT;
2102 /* \x24 indicates a hex constant */
2106 char* const e = strchr(s, '}');
2107 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2108 PERL_SCAN_DISALLOW_PREFIX;
2113 yyerror("Missing right brace on \\x{}");
2117 uv = grok_hex(s, &len, &flags, NULL);
2123 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2124 uv = grok_hex(s, &len, &flags, NULL);
2130 /* Insert oct or hex escaped character.
2131 * There will always enough room in sv since such
2132 * escapes will be longer than any UTF-8 sequence
2133 * they can end up as. */
2135 /* We need to map to chars to ASCII before doing the tests
2138 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2139 if (!has_utf8 && uv > 255) {
2140 /* Might need to recode whatever we have
2141 * accumulated so far if it contains any
2144 * (Can't we keep track of that and avoid
2145 * this rescan? --jhi)
2149 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2150 if (!NATIVE_IS_INVARIANT(*c)) {
2155 const STRLEN offset = d - SvPVX_const(sv);
2157 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2161 while (src >= (const U8 *)SvPVX_const(sv)) {
2162 if (!NATIVE_IS_INVARIANT(*src)) {
2163 const U8 ch = NATIVE_TO_ASCII(*src);
2164 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2165 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2175 if (has_utf8 || uv > 255) {
2176 d = (char*)uvchr_to_utf8((U8*)d, uv);
2178 if (PL_lex_inwhat == OP_TRANS &&
2179 PL_sublex_info.sub_op) {
2180 PL_sublex_info.sub_op->op_private |=
2181 (PL_lex_repl ? OPpTRANS_FROM_UTF
2185 if (uv > 255 && !dorange)
2186 native_range = FALSE;
2198 /* \N{LATIN SMALL LETTER A} is a named character */
2202 char* e = strchr(s, '}');
2209 yyerror("Missing right brace on \\N{}");
2213 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2215 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2216 PERL_SCAN_DISALLOW_PREFIX;
2219 uv = grok_hex(s, &len, &flags, NULL);
2220 if ( e > s && len != (STRLEN)(e - s) ) {
2224 goto NUM_ESCAPE_INSERT;
2226 res = newSVpvn(s + 1, e - s - 1);
2227 type = newSVpvn(s - 2,e - s + 3);
2228 res = new_constant( NULL, 0, "charnames",
2229 res, NULL, SvPVX(type) );
2232 sv_utf8_upgrade(res);
2233 str = SvPV_const(res,len);
2234 #ifdef EBCDIC_NEVER_MIND
2235 /* charnames uses pack U and that has been
2236 * recently changed to do the below uni->native
2237 * mapping, so this would be redundant (and wrong,
2238 * the code point would be doubly converted).
2239 * But leave this in just in case the pack U change
2240 * gets revoked, but the semantics is still
2241 * desireable for charnames. --jhi */
2243 UV uv = utf8_to_uvchr((const U8*)str, 0);
2246 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2248 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2249 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2250 str = SvPV_const(res, len);
2254 if (!has_utf8 && SvUTF8(res)) {
2255 const char * const ostart = SvPVX_const(sv);
2256 SvCUR_set(sv, d - ostart);
2259 sv_utf8_upgrade(sv);
2260 /* this just broke our allocation above... */
2261 SvGROW(sv, (STRLEN)(send - start));
2262 d = SvPVX(sv) + SvCUR(sv);
2265 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2266 const char * const odest = SvPVX_const(sv);
2268 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2269 d = SvPVX(sv) + (d - odest);
2273 native_range = FALSE; /* \N{} is guessed to be Unicode */
2275 Copy(str, d, len, char);
2282 yyerror("Missing braces on \\N{}");
2285 /* \c is a control character */
2294 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2297 yyerror("Missing control char name in \\c");
2301 /* printf-style backslashes, formfeeds, newlines, etc */
2303 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2306 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2309 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2312 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2315 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2318 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2321 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2327 } /* end if (backslash) */
2334 /* If we started with encoded form, or already know we want it
2335 and then encode the next character */
2336 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2338 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2339 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2342 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2343 const STRLEN off = d - SvPVX_const(sv);
2344 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2346 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2349 if (uv > 255 && !dorange)
2350 native_range = FALSE;
2354 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2356 } /* while loop to process each character */
2358 /* terminate the string and set up the sv */
2360 SvCUR_set(sv, d - SvPVX_const(sv));
2361 if (SvCUR(sv) >= SvLEN(sv))
2362 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2365 if (PL_encoding && !has_utf8) {
2366 sv_recode_to_utf8(sv, PL_encoding);
2372 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2373 PL_sublex_info.sub_op->op_private |=
2374 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2378 /* shrink the sv if we allocated more than we used */
2379 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2380 SvPV_shrink_to_cur(sv);
2383 /* return the substring (via yylval) only if we parsed anything */
2384 if (s > PL_bufptr) {
2385 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2386 sv = new_constant(start, s - start,
2387 (const char *)(PL_lex_inpat ? "qr" : "q"),
2390 (( PL_lex_inwhat == OP_TRANS
2392 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2395 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2402 * Returns TRUE if there's more to the expression (e.g., a subscript),
2405 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2407 * ->[ and ->{ return TRUE
2408 * { and [ outside a pattern are always subscripts, so return TRUE
2409 * if we're outside a pattern and it's not { or [, then return FALSE
2410 * if we're in a pattern and the first char is a {
2411 * {4,5} (any digits around the comma) returns FALSE
2412 * if we're in a pattern and the first char is a [
2414 * [SOMETHING] has a funky algorithm to decide whether it's a
2415 * character class or not. It has to deal with things like
2416 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2417 * anything else returns TRUE
2420 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2423 S_intuit_more(pTHX_ register char *s)
2426 if (PL_lex_brackets)
2428 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2430 if (*s != '{' && *s != '[')
2435 /* In a pattern, so maybe we have {n,m}. */
2452 /* On the other hand, maybe we have a character class */
2455 if (*s == ']' || *s == '^')
2458 /* this is terrifying, and it works */
2459 int weight = 2; /* let's weigh the evidence */
2461 unsigned char un_char = 255, last_un_char;
2462 const char * const send = strchr(s,']');
2463 char tmpbuf[sizeof PL_tokenbuf * 4];
2465 if (!send) /* has to be an expression */
2468 Zero(seen,256,char);
2471 else if (isDIGIT(*s)) {
2473 if (isDIGIT(s[1]) && s[2] == ']')
2479 for (; s < send; s++) {
2480 last_un_char = un_char;
2481 un_char = (unsigned char)*s;
2486 weight -= seen[un_char] * 10;
2487 if (isALNUM_lazy_if(s+1,UTF)) {
2489 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2490 len = (int)strlen(tmpbuf);
2491 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2496 else if (*s == '$' && s[1] &&
2497 strchr("[#!%*<>()-=",s[1])) {
2498 if (/*{*/ strchr("])} =",s[2]))
2507 if (strchr("wds]",s[1]))
2509 else if (seen[(U8)'\''] || seen[(U8)'"'])
2511 else if (strchr("rnftbxcav",s[1]))
2513 else if (isDIGIT(s[1])) {
2515 while (s[1] && isDIGIT(s[1]))
2525 if (strchr("aA01! ",last_un_char))
2527 if (strchr("zZ79~",s[1]))
2529 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2530 weight -= 5; /* cope with negative subscript */
2533 if (!isALNUM(last_un_char)
2534 && !(last_un_char == '$' || last_un_char == '@'
2535 || last_un_char == '&')
2536 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2541 if (keyword(tmpbuf, d - tmpbuf, 0))
2544 if (un_char == last_un_char + 1)
2546 weight -= seen[un_char];
2551 if (weight >= 0) /* probably a character class */
2561 * Does all the checking to disambiguate
2563 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2564 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2566 * First argument is the stuff after the first token, e.g. "bar".
2568 * Not a method if bar is a filehandle.
2569 * Not a method if foo is a subroutine prototyped to take a filehandle.
2570 * Not a method if it's really "Foo $bar"
2571 * Method if it's "foo $bar"
2572 * Not a method if it's really "print foo $bar"
2573 * Method if it's really "foo package::" (interpreted as package->foo)
2574 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2575 * Not a method if bar is a filehandle or package, but is quoted with
2580 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2583 char *s = start + (*start == '$');
2584 char tmpbuf[sizeof PL_tokenbuf];
2592 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2596 const char *proto = SvPVX_const(cv);
2607 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2608 /* start is the beginning of the possible filehandle/object,
2609 * and s is the end of it
2610 * tmpbuf is a copy of it
2613 if (*start == '$') {
2614 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2617 len = start - SvPVX(PL_linestr);
2621 start = SvPVX(PL_linestr) + len;
2625 return *s == '(' ? FUNCMETH : METHOD;
2627 if (!keyword(tmpbuf, len, 0)) {
2628 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2632 soff = s - SvPVX(PL_linestr);
2636 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2637 if (indirgv && GvCVu(indirgv))
2639 /* filehandle or package name makes it a method */
2640 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2642 soff = s - SvPVX(PL_linestr);
2645 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2646 return 0; /* no assumptions -- "=>" quotes bearword */
2648 start_force(PL_curforce);
2649 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2650 newSVpvn(tmpbuf,len));
2651 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2653 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2658 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2660 return *s == '(' ? FUNCMETH : METHOD;
2668 * Return a string of Perl code to load the debugger. If PERL5DB
2669 * is set, it will return the contents of that, otherwise a
2670 * compile-time require of perl5db.pl.
2678 const char * const pdb = PerlEnv_getenv("PERL5DB");
2682 SETERRNO(0,SS_NORMAL);
2683 return "BEGIN { require 'perl5db.pl' }";
2689 /* Encoded script support. filter_add() effectively inserts a
2690 * 'pre-processing' function into the current source input stream.
2691 * Note that the filter function only applies to the current source file
2692 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2694 * The datasv parameter (which may be NULL) can be used to pass
2695 * private data to this instance of the filter. The filter function
2696 * can recover the SV using the FILTER_DATA macro and use it to
2697 * store private buffers and state information.
2699 * The supplied datasv parameter is upgraded to a PVIO type
2700 * and the IoDIRP/IoANY field is used to store the function pointer,
2701 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2702 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2703 * private use must be set using malloc'd pointers.
2707 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2713 if (!PL_rsfp_filters)
2714 PL_rsfp_filters = newAV();
2717 SvUPGRADE(datasv, SVt_PVIO);
2718 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2719 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2720 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2721 FPTR2DPTR(void *, IoANY(datasv)),
2722 SvPV_nolen(datasv)));
2723 av_unshift(PL_rsfp_filters, 1);
2724 av_store(PL_rsfp_filters, 0, datasv) ;
2729 /* Delete most recently added instance of this filter function. */
2731 Perl_filter_del(pTHX_ filter_t funcp)
2737 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2738 FPTR2DPTR(void*, funcp)));
2740 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2742 /* if filter is on top of stack (usual case) just pop it off */
2743 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2744 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2745 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2746 IoANY(datasv) = (void *)NULL;
2747 sv_free(av_pop(PL_rsfp_filters));
2751 /* we need to search for the correct entry and clear it */
2752 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2756 /* Invoke the idxth filter function for the current rsfp. */
2757 /* maxlen 0 = read one text line */
2759 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2764 /* This API is bad. It should have been using unsigned int for maxlen.
2765 Not sure if we want to change the API, but if not we should sanity
2766 check the value here. */
2767 const unsigned int correct_length
2776 if (!PL_rsfp_filters)
2778 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2779 /* Provide a default input filter to make life easy. */
2780 /* Note that we append to the line. This is handy. */
2781 DEBUG_P(PerlIO_printf(Perl_debug_log,
2782 "filter_read %d: from rsfp\n", idx));
2783 if (correct_length) {
2786 const int old_len = SvCUR(buf_sv);
2788 /* ensure buf_sv is large enough */
2789 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2790 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2791 correct_length)) <= 0) {
2792 if (PerlIO_error(PL_rsfp))
2793 return -1; /* error */
2795 return 0 ; /* end of file */
2797 SvCUR_set(buf_sv, old_len + len) ;
2800 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2801 if (PerlIO_error(PL_rsfp))
2802 return -1; /* error */
2804 return 0 ; /* end of file */
2807 return SvCUR(buf_sv);
2809 /* Skip this filter slot if filter has been deleted */
2810 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2811 DEBUG_P(PerlIO_printf(Perl_debug_log,
2812 "filter_read %d: skipped (filter deleted)\n",
2814 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2816 /* Get function pointer hidden within datasv */
2817 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2818 DEBUG_P(PerlIO_printf(Perl_debug_log,
2819 "filter_read %d: via function %p (%s)\n",
2820 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2821 /* Call function. The function is expected to */
2822 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2823 /* Return: <0:error, =0:eof, >0:not eof */
2824 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2828 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2831 #ifdef PERL_CR_FILTER
2832 if (!PL_rsfp_filters) {
2833 filter_add(S_cr_textfilter,NULL);
2836 if (PL_rsfp_filters) {
2838 SvCUR_set(sv, 0); /* start with empty line */
2839 if (FILTER_READ(0, sv, 0) > 0)
2840 return ( SvPVX(sv) ) ;
2845 return (sv_gets(sv, fp, append));
2849 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2854 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2858 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2859 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2861 return GvHV(gv); /* Foo:: */
2864 /* use constant CLASS => 'MyClass' */
2865 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2866 if (gv && GvCV(gv)) {
2867 SV * const sv = cv_const_sv(GvCV(gv));
2869 pkgname = SvPV_nolen_const(sv);
2872 return gv_stashpv(pkgname, FALSE);
2876 * S_readpipe_override
2877 * Check whether readpipe() is overriden, and generates the appropriate
2878 * optree, provided sublex_start() is called afterwards.
2881 S_readpipe_override(pTHX)
2884 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
2885 yylval.ival = OP_BACKTICK;
2887 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
2889 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
2890 && (gv_readpipe = *gvp) != (GV*)&PL_sv_undef
2891 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
2893 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
2894 append_elem(OP_LIST,
2895 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
2896 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
2906 * The intent of this yylex wrapper is to minimize the changes to the
2907 * tokener when we aren't interested in collecting madprops. It remains
2908 * to be seen how successful this strategy will be...
2915 char *s = PL_bufptr;
2917 /* make sure PL_thiswhite is initialized */
2921 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2922 if (PL_pending_ident)
2923 return S_pending_ident(aTHX);
2925 /* previous token ate up our whitespace? */
2926 if (!PL_lasttoke && PL_nextwhite) {
2927 PL_thiswhite = PL_nextwhite;
2931 /* isolate the token, and figure out where it is without whitespace */
2932 PL_realtokenstart = -1;
2936 assert(PL_curforce < 0);
2938 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2939 if (!PL_thistoken) {
2940 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2941 PL_thistoken = newSVpvs("");
2943 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2944 PL_thistoken = newSVpvn(tstart, s - tstart);
2947 if (PL_thismad) /* install head */
2948 CURMAD('X', PL_thistoken);
2951 /* last whitespace of a sublex? */
2952 if (optype == ')' && PL_endwhite) {
2953 CURMAD('X', PL_endwhite);
2958 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
2959 if (!PL_thiswhite && !PL_endwhite && !optype) {
2960 sv_free(PL_thistoken);
2965 /* put off final whitespace till peg */
2966 if (optype == ';' && !PL_rsfp) {
2967 PL_nextwhite = PL_thiswhite;
2970 else if (PL_thisopen) {
2971 CURMAD('q', PL_thisopen);
2973 sv_free(PL_thistoken);
2977 /* Store actual token text as madprop X */
2978 CURMAD('X', PL_thistoken);
2982 /* add preceding whitespace as madprop _ */
2983 CURMAD('_', PL_thiswhite);
2987 /* add quoted material as madprop = */
2988 CURMAD('=', PL_thisstuff);
2992 /* add terminating quote as madprop Q */
2993 CURMAD('Q', PL_thisclose);
2997 /* special processing based on optype */
3001 /* opval doesn't need a TOKEN since it can already store mp */
3012 append_madprops(PL_thismad, yylval.opval, 0);
3020 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3029 /* remember any fake bracket that lexer is about to discard */
3030 if (PL_lex_brackets == 1 &&
3031 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3034 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3037 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3038 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3041 break; /* don't bother looking for trailing comment */
3050 /* attach a trailing comment to its statement instead of next token */
3054 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3056 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3058 if (*s == '\n' || *s == '#') {
3059 while (s < PL_bufend && *s != '\n')
3063 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3064 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3081 /* Create new token struct. Note: opvals return early above. */
3082 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
3089 S_tokenize_use(pTHX_ int is_use, char *s) {
3091 if (PL_expect != XSTATE)
3092 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3093 is_use ? "use" : "no"));
3095 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3096 s = force_version(s, TRUE);
3097 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3098 start_force(PL_curforce);
3099 NEXTVAL_NEXTTOKE.opval = NULL;
3102 else if (*s == 'v') {
3103 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3104 s = force_version(s, FALSE);
3108 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3109 s = force_version(s, FALSE);
3111 yylval.ival = is_use;
3115 static const char* const exp_name[] =
3116 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3117 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3124 Works out what to call the token just pulled out of the input
3125 stream. The yacc parser takes care of taking the ops we return and
3126 stitching them into a tree.
3132 if read an identifier
3133 if we're in a my declaration
3134 croak if they tried to say my($foo::bar)
3135 build the ops for a my() declaration
3136 if it's an access to a my() variable
3137 are we in a sort block?
3138 croak if my($a); $a <=> $b
3139 build ops for access to a my() variable
3140 if in a dq string, and they've said @foo and we can't find @foo
3142 build ops for a bareword
3143 if we already built the token before, use it.
3148 #pragma segment Perl_yylex
3154 register char *s = PL_bufptr;
3159 /* orig_keyword, gvp, and gv are initialized here because
3160 * jump to the label just_a_word_zero can bypass their
3161 * initialization later. */
3162 I32 orig_keyword = 0;
3167 SV* tmp = newSVpvs("");
3168 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3169 (IV)CopLINE(PL_curcop),
3170 lex_state_names[PL_lex_state],
3171 exp_name[PL_expect],
3172 pv_display(tmp, s, strlen(s), 0, 60));
3175 /* check if there's an identifier for us to look at */
3176 if (PL_pending_ident)
3177 return REPORT(S_pending_ident(aTHX));
3179 /* no identifier pending identification */
3181 switch (PL_lex_state) {
3183 case LEX_NORMAL: /* Some compilers will produce faster */
3184 case LEX_INTERPNORMAL: /* code if we comment these out. */
3188 /* when we've already built the next token, just pull it out of the queue */
3192 yylval = PL_nexttoke[PL_lasttoke].next_val;
3194 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3195 PL_nexttoke[PL_lasttoke].next_mad = 0;
3196 if (PL_thismad && PL_thismad->mad_key == '_') {
3197 PL_thiswhite = (SV*)PL_thismad->mad_val;
3198 PL_thismad->mad_val = 0;
3199 mad_free(PL_thismad);
3204 PL_lex_state = PL_lex_defer;
3205 PL_expect = PL_lex_expect;
3206 PL_lex_defer = LEX_NORMAL;
3207 if (!PL_nexttoke[PL_lasttoke].next_type)
3212 yylval = PL_nextval[PL_nexttoke];
3214 PL_lex_state = PL_lex_defer;
3215 PL_expect = PL_lex_expect;
3216 PL_lex_defer = LEX_NORMAL;
3220 /* FIXME - can these be merged? */
3221 return(PL_nexttoke[PL_lasttoke].next_type);
3223 return REPORT(PL_nexttype[PL_nexttoke]);
3226 /* interpolated case modifiers like \L \U, including \Q and \E.
3227 when we get here, PL_bufptr is at the \
3229 case LEX_INTERPCASEMOD:
3231 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3232 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3234 /* handle \E or end of string */
3235 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3237 if (PL_lex_casemods) {
3238 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3239 PL_lex_casestack[PL_lex_casemods] = '\0';
3241 if (PL_bufptr != PL_bufend
3242 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3244 PL_lex_state = LEX_INTERPCONCAT;
3247 PL_thistoken = newSVpvs("\\E");
3253 while (PL_bufptr != PL_bufend &&
3254 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3256 PL_thiswhite = newSVpvs("");
3257 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3261 if (PL_bufptr != PL_bufend)
3264 PL_lex_state = LEX_INTERPCONCAT;
3268 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3269 "### Saw case modifier\n"); });
3271 if (s[1] == '\\' && s[2] == 'E') {
3274 PL_thiswhite = newSVpvs("");
3275 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3278 PL_lex_state = LEX_INTERPCONCAT;
3283 if (!PL_madskills) /* when just compiling don't need correct */
3284 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3285 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3286 if ((*s == 'L' || *s == 'U') &&
3287 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3288 PL_lex_casestack[--PL_lex_casemods] = '\0';
3291 if (PL_lex_casemods > 10)
3292 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3293 PL_lex_casestack[PL_lex_casemods++] = *s;
3294 PL_lex_casestack[PL_lex_casemods] = '\0';
3295 PL_lex_state = LEX_INTERPCONCAT;
3296 start_force(PL_curforce);
3297 NEXTVAL_NEXTTOKE.ival = 0;
3299 start_force(PL_curforce);
3301 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3303 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3305 NEXTVAL_NEXTTOKE.ival = OP_LC;
3307 NEXTVAL_NEXTTOKE.ival = OP_UC;
3309 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3311 Perl_croak(aTHX_ "panic: yylex");
3313 SV* const tmpsv = newSVpvs("");
3314 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3320 if (PL_lex_starts) {
3326 sv_free(PL_thistoken);
3327 PL_thistoken = newSVpvs("");
3330 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3331 if (PL_lex_casemods == 1 && PL_lex_inpat)
3340 case LEX_INTERPPUSH:
3341 return REPORT(sublex_push());
3343 case LEX_INTERPSTART:
3344 if (PL_bufptr == PL_bufend)
3345 return REPORT(sublex_done());
3346 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3347 "### Interpolated variable\n"); });
3349 PL_lex_dojoin = (*PL_bufptr == '@');
3350 PL_lex_state = LEX_INTERPNORMAL;
3351 if (PL_lex_dojoin) {
3352 start_force(PL_curforce);
3353 NEXTVAL_NEXTTOKE.ival = 0;
3355 start_force(PL_curforce);
3356 force_ident("\"", '$');
3357 start_force(PL_curforce);
3358 NEXTVAL_NEXTTOKE.ival = 0;
3360 start_force(PL_curforce);
3361 NEXTVAL_NEXTTOKE.ival = 0;
3363 start_force(PL_curforce);
3364 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3367 if (PL_lex_starts++) {
3372 sv_free(PL_thistoken);
3373 PL_thistoken = newSVpvs("");
3376 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3377 if (!PL_lex_casemods && PL_lex_inpat)
3384 case LEX_INTERPENDMAYBE:
3385 if (intuit_more(PL_bufptr)) {
3386 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3392 if (PL_lex_dojoin) {
3393 PL_lex_dojoin = FALSE;
3394 PL_lex_state = LEX_INTERPCONCAT;
3398 sv_free(PL_thistoken);
3399 PL_thistoken = newSVpvs("");
3404 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3405 && SvEVALED(PL_lex_repl))
3407 if (PL_bufptr != PL_bufend)
3408 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3412 case LEX_INTERPCONCAT:
3414 if (PL_lex_brackets)
3415 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3417 if (PL_bufptr == PL_bufend)
3418 return REPORT(sublex_done());
3420 if (SvIVX(PL_linestr) == '\'') {
3421 SV *sv = newSVsv(PL_linestr);
3424 else if ( PL_hints & HINT_NEW_RE )
3425 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3426 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3430 s = scan_const(PL_bufptr);
3432 PL_lex_state = LEX_INTERPCASEMOD;
3434 PL_lex_state = LEX_INTERPSTART;
3437 if (s != PL_bufptr) {
3438 start_force(PL_curforce);
3440 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3442 NEXTVAL_NEXTTOKE = yylval;
3445 if (PL_lex_starts++) {
3449 sv_free(PL_thistoken);
3450 PL_thistoken = newSVpvs("");
3453 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3454 if (!PL_lex_casemods && PL_lex_inpat)
3467 PL_lex_state = LEX_NORMAL;
3468 s = scan_formline(PL_bufptr);
3469 if (!PL_lex_formbrack)
3475 PL_oldoldbufptr = PL_oldbufptr;
3481 sv_free(PL_thistoken);
3484 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3488 if (isIDFIRST_lazy_if(s,UTF))
3490 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3493 goto fake_eof; /* emulate EOF on ^D or ^Z */
3502 if (PL_lex_brackets) {
3503 yyerror((const char *)
3505 ? "Format not terminated"
3506 : "Missing right curly or square bracket"));
3508 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3509 "### Tokener got EOF\n");
3513 if (s++ < PL_bufend)
3514 goto retry; /* ignore stray nulls */
3517 if (!PL_in_eval && !PL_preambled) {
3518 PL_preambled = TRUE;
3523 sv_setpv(PL_linestr,incl_perldb());
3524 if (SvCUR(PL_linestr))
3525 sv_catpvs(PL_linestr,";");
3527 while(AvFILLp(PL_preambleav) >= 0) {
3528 SV *tmpsv = av_shift(PL_preambleav);
3529 sv_catsv(PL_linestr, tmpsv);
3530 sv_catpvs(PL_linestr, ";");
3533 sv_free((SV*)PL_preambleav);
3534 PL_preambleav = NULL;
3536 if (PL_minus_n || PL_minus_p) {
3537 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3539 sv_catpvs(PL_linestr,"chomp;");
3542 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3543 || *PL_splitstr == '"')
3544 && strchr(PL_splitstr + 1, *PL_splitstr))
3545 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3547 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3548 bytes can be used as quoting characters. :-) */
3549 const char *splits = PL_splitstr;
3550 sv_catpvs(PL_linestr, "our @F=split(q\0");
3553 if (*splits == '\\')
3554 sv_catpvn(PL_linestr, splits, 1);
3555 sv_catpvn(PL_linestr, splits, 1);
3556 } while (*splits++);
3557 /* This loop will embed the trailing NUL of
3558 PL_linestr as the last thing it does before
3560 sv_catpvs(PL_linestr, ");");
3564 sv_catpvs(PL_linestr,"our @F=split(' ');");
3568 sv_catpvs(PL_linestr,"use feature ':5.10';");
3569 sv_catpvs(PL_linestr, "\n");
3570 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3571 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3572 PL_last_lop = PL_last_uni = NULL;
3573 if (PERLDB_LINE && PL_curstash != PL_debstash)
3574 update_debugger_info_sv(PL_linestr);
3578 bof = PL_rsfp ? TRUE : FALSE;
3579 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3582 PL_realtokenstart = -1;
3585 if (PL_preprocess && !PL_in_eval)
3586 (void)PerlProc_pclose(PL_rsfp);
3587 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3588 PerlIO_clearerr(PL_rsfp);
3590 (void)PerlIO_close(PL_rsfp);
3592 PL_doextract = FALSE;
3594 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3599 sv_setpv(PL_linestr,
3602 ? ";}continue{print;}" : ";}"));
3603 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3604 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3605 PL_last_lop = PL_last_uni = NULL;
3606 PL_minus_n = PL_minus_p = 0;
3609 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3610 PL_last_lop = PL_last_uni = NULL;
3611 sv_setpvn(PL_linestr,"",0);
3612 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3614 /* If it looks like the start of a BOM or raw UTF-16,
3615 * check if it in fact is. */
3621 #ifdef PERLIO_IS_STDIO
3622 # ifdef __GNU_LIBRARY__
3623 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3624 # define FTELL_FOR_PIPE_IS_BROKEN
3628 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3629 # define FTELL_FOR_PIPE_IS_BROKEN
3634 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3635 /* This loses the possibility to detect the bof
3636 * situation on perl -P when the libc5 is being used.
3637 * Workaround? Maybe attach some extra state to PL_rsfp?
3640 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3642 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3645 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3646 s = swallow_bom((U8*)s);
3650 /* Incest with pod. */
3653 sv_catsv(PL_thiswhite, PL_linestr);
3655 if (*s == '=' && strnEQ(s, "=cut", 4)) {
3656 sv_setpvn(PL_linestr, "", 0);
3657 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3658 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3659 PL_last_lop = PL_last_uni = NULL;
3660 PL_doextract = FALSE;
3664 } while (PL_doextract);
3665 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3666 if (PERLDB_LINE && PL_curstash != PL_debstash)
3667 update_debugger_info_sv(PL_linestr);
3668 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3669 PL_last_lop = PL_last_uni = NULL;
3670 if (CopLINE(PL_curcop) == 1) {
3671 while (s < PL_bufend && isSPACE(*s))
3673 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3677 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3681 if (*s == '#' && *(s+1) == '!')
3683 #ifdef ALTERNATE_SHEBANG
3685 static char const as[] = ALTERNATE_SHEBANG;
3686 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3687 d = s + (sizeof(as) - 1);
3689 #endif /* ALTERNATE_SHEBANG */
3698 while (*d && !isSPACE(*d))
3702 #ifdef ARG_ZERO_IS_SCRIPT
3703 if (ipathend > ipath) {
3705 * HP-UX (at least) sets argv[0] to the script name,
3706 * which makes $^X incorrect. And Digital UNIX and Linux,
3707 * at least, set argv[0] to the basename of the Perl
3708 * interpreter. So, having found "#!", we'll set it right.
3710 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3712 assert(SvPOK(x) || SvGMAGICAL(x));
3713 if (sv_eq(x, CopFILESV(PL_curcop))) {
3714 sv_setpvn(x, ipath, ipathend - ipath);
3720 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3721 const char * const lstart = SvPV_const(x,llen);
3723 bstart += blen - llen;
3724 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3725 sv_setpvn(x, ipath, ipathend - ipath);
3730 TAINT_NOT; /* $^X is always tainted, but that's OK */
3732 #endif /* ARG_ZERO_IS_SCRIPT */
3737 d = instr(s,"perl -");
3739 d = instr(s,"perl");
3741 /* avoid getting into infinite loops when shebang
3742 * line contains "Perl" rather than "perl" */
3744 for (d = ipathend-4; d >= ipath; --d) {
3745 if ((*d == 'p' || *d == 'P')
3746 && !ibcmp(d, "perl", 4))
3756 #ifdef ALTERNATE_SHEBANG
3758 * If the ALTERNATE_SHEBANG on this system starts with a
3759 * character that can be part of a Perl expression, then if
3760 * we see it but not "perl", we're probably looking at the
3761 * start of Perl code, not a request to hand off to some
3762 * other interpreter. Similarly, if "perl" is there, but
3763 * not in the first 'word' of the line, we assume the line
3764 * contains the start of the Perl program.
3766 if (d && *s != '#') {
3767 const char *c = ipath;
3768 while (*c && !strchr("; \t\r\n\f\v#", *c))
3771 d = NULL; /* "perl" not in first word; ignore */
3773 *s = '#'; /* Don't try to parse shebang line */
3775 #endif /* ALTERNATE_SHEBANG */
3776 #ifndef MACOS_TRADITIONAL
3781 !instr(s,"indir") &&
3782 instr(PL_origargv[0],"perl"))
3789 while (s < PL_bufend && isSPACE(*s))
3791 if (s < PL_bufend) {
3792 Newxz(newargv,PL_origargc+3,char*);
3794 while (s < PL_bufend && !isSPACE(*s))
3797 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3800 newargv = PL_origargv;
3803 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3805 Perl_croak(aTHX_ "Can't exec %s", ipath);
3809 while (*d && !isSPACE(*d))
3811 while (SPACE_OR_TAB(*d))
3815 const bool switches_done = PL_doswitches;
3816 const U32 oldpdb = PL_perldb;
3817 const bool oldn = PL_minus_n;
3818 const bool oldp = PL_minus_p;
3821 if (*d == 'M' || *d == 'm' || *d == 'C') {
3822 const char * const m = d;
3823 while (*d && !isSPACE(*d))
3825 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3828 d = moreswitches(d);
3830 if (PL_doswitches && !switches_done) {
3831 int argc = PL_origargc;
3832 char **argv = PL_origargv;
3835 } while (argc && argv[0][0] == '-' && argv[0][1]);
3836 init_argv_symbols(argc,argv);
3838 if ((PERLDB_LINE && !oldpdb) ||
3839 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3840 /* if we have already added "LINE: while (<>) {",
3841 we must not do it again */
3843 sv_setpvn(PL_linestr, "", 0);
3844 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3845 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3846 PL_last_lop = PL_last_uni = NULL;
3847 PL_preambled = FALSE;
3849 (void)gv_fetchfile(PL_origfilename);
3856 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3858 PL_lex_state = LEX_FORMLINE;
3863 #ifdef PERL_STRICT_CR
3864 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3866 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3868 case ' ': case '\t': case '\f': case 013:
3869 #ifdef MACOS_TRADITIONAL
3873 PL_realtokenstart = -1;
3882 PL_realtokenstart = -1;
3886 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3887 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3888 /* handle eval qq[#line 1 "foo"\n ...] */
3889 CopLINE_dec(PL_curcop);
3892 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3894 if (!PL_in_eval || PL_rsfp)
3899 while (d < PL_bufend && *d != '\n')
3903 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3904 Perl_croak(aTHX_ "panic: input overflow");
3907 PL_thiswhite = newSVpvn(s, d - s);
3912 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3914 PL_lex_state = LEX_FORMLINE;
3920 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3921 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3924 TOKEN(PEG); /* make sure any #! line is accessible */
3929 /* if (PL_madskills && PL_lex_formbrack) { */
3931 while (d < PL_bufend && *d != '\n')
3935 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3936 Perl_croak(aTHX_ "panic: input overflow");
3937 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3939 PL_thiswhite = newSVpvs("");
3940 if (CopLINE(PL_curcop) == 1) {
3941 sv_setpvn(PL_thiswhite, "", 0);
3944 sv_catpvn(PL_thiswhite, s, d - s);
3958 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3966 while (s < PL_bufend && SPACE_OR_TAB(*s))
3969 if (strnEQ(s,"=>",2)) {
3970 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3971 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
3972 OPERATOR('-'); /* unary minus */
3974 PL_last_uni = PL_oldbufptr;
3976 case 'r': ftst = OP_FTEREAD; break;
3977 case 'w': ftst = OP_FTEWRITE; break;
3978 case 'x': ftst = OP_FTEEXEC; break;
3979 case 'o': ftst = OP_FTEOWNED; break;
3980 case 'R': ftst = OP_FTRREAD; break;
3981 case 'W': ftst = OP_FTRWRITE; break;
3982 case 'X': ftst = OP_FTREXEC; break;
3983 case 'O': ftst = OP_FTROWNED; break;
3984 case 'e': ftst = OP_FTIS; break;
3985 case 'z': ftst = OP_FTZERO; break;
3986 case 's': ftst = OP_FTSIZE; break;
3987 case 'f': ftst = OP_FTFILE; break;
3988 case 'd': ftst = OP_FTDIR; break;
3989 case 'l': ftst = OP_FTLINK; break;
3990 case 'p': ftst = OP_FTPIPE; break;
3991 case 'S': ftst = OP_FTSOCK; break;
3992 case 'u': ftst = OP_FTSUID; break;
3993 case 'g': ftst = OP_FTSGID; break;
3994 case 'k': ftst = OP_FTSVTX; break;
3995 case 'b': ftst = OP_FTBLK; break;
3996 case 'c': ftst = OP_FTCHR; break;
3997 case 't': ftst = OP_FTTTY; break;
3998 case 'T': ftst = OP_FTTEXT; break;
3999 case 'B': ftst = OP_FTBINARY; break;
4000 case 'M': case 'A': case 'C':
4001 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
4003 case 'M': ftst = OP_FTMTIME; break;
4004 case 'A': ftst = OP_FTATIME; break;
4005 case 'C': ftst = OP_FTCTIME; break;
4013 PL_last_lop_op = (OPCODE)ftst;
4014 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4015 "### Saw file test %c\n", (int)tmp);
4020 /* Assume it was a minus followed by a one-letter named
4021 * subroutine call (or a -bareword), then. */
4022 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4023 "### '-%c' looked like a file test but was not\n",
4030 const char tmp = *s++;
4033 if (PL_expect == XOPERATOR)
4038 else if (*s == '>') {
4041 if (isIDFIRST_lazy_if(s,UTF)) {
4042 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4050 if (PL_expect == XOPERATOR)
4053 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4055 OPERATOR('-'); /* unary minus */
4061 const char tmp = *s++;
4064 if (PL_expect == XOPERATOR)
4069 if (PL_expect == XOPERATOR)
4072 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4079 if (PL_expect != XOPERATOR) {
4080 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4081 PL_expect = XOPERATOR;
4082 force_ident(PL_tokenbuf, '*');
4095 if (PL_expect == XOPERATOR) {
4099 PL_tokenbuf[0] = '%';
4100 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
4101 if (!PL_tokenbuf[1]) {
4104 PL_pending_ident = '%';
4115 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
4116 && FEATURE_IS_ENABLED("~~"))
4123 const char tmp = *s++;
4129 goto just_a_word_zero_gv;
4132 switch (PL_expect) {
4138 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4140 PL_bufptr = s; /* update in case we back off */
4146 PL_expect = XTERMBLOCK;
4149 stuffstart = s - SvPVX(PL_linestr) - 1;
4153 while (isIDFIRST_lazy_if(s,UTF)) {
4156 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4157 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4158 if (tmp < 0) tmp = -tmp;
4173 sv = newSVpvn(s, len);
4175 d = scan_str(d,TRUE,TRUE);
4177 /* MUST advance bufptr here to avoid bogus
4178 "at end of line" context messages from yyerror().
4180 PL_bufptr = s + len;
4181 yyerror("Unterminated attribute parameter in attribute list");
4185 return REPORT(0); /* EOF indicator */
4189 sv_catsv(sv, PL_lex_stuff);
4190 attrs = append_elem(OP_LIST, attrs,
4191 newSVOP(OP_CONST, 0, sv));
4192 SvREFCNT_dec(PL_lex_stuff);
4193 PL_lex_stuff = NULL;
4196 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4198 if (PL_in_my == KEY_our) {
4200 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4202 /* skip to avoid loading attributes.pm */
4204 deprecate(":unique");
4207 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4210 /* NOTE: any CV attrs applied here need to be part of
4211 the CVf_BUILTIN_ATTRS define in cv.h! */
4212 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4214 CvLVALUE_on(PL_compcv);
4216 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4218 CvLOCKED_on(PL_compcv);
4220 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4222 CvMETHOD_on(PL_compcv);
4224 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4226 CvASSERTION_on(PL_compcv);
4228 /* After we've set the flags, it could be argued that
4229 we don't need to do the attributes.pm-based setting
4230 process, and shouldn't bother appending recognized
4231 flags. To experiment with that, uncomment the
4232 following "else". (Note that's already been
4233 uncommented. That keeps the above-applied built-in
4234 attributes from being intercepted (and possibly
4235 rejected) by a package's attribute routines, but is
4236 justified by the performance win for the common case
4237 of applying only built-in attributes.) */
4239 attrs = append_elem(OP_LIST, attrs,
4240 newSVOP(OP_CONST, 0,
4244 if (*s == ':' && s[1] != ':')
4247 break; /* require real whitespace or :'s */
4248 /* XXX losing whitespace on sequential attributes here */
4252 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4253 if (*s != ';' && *s != '}' && *s != tmp
4254 && (tmp != '=' || *s != ')')) {
4255 const char q = ((*s == '\'') ? '"' : '\'');
4256 /* If here for an expression, and parsed no attrs, back
4258 if (tmp == '=' && !attrs) {
4262 /* MUST advance bufptr here to avoid bogus "at end of line"
4263 context messages from yyerror().
4266 yyerror( (const char *)
4268 ? Perl_form(aTHX_ "Invalid separator character "
4269 "%c%c%c in attribute list", q, *s, q)
4270 : "Unterminated attribute list" ) );
4278 start_force(PL_curforce);
4279 NEXTVAL_NEXTTOKE.opval = attrs;
4280 CURMAD('_', PL_nextwhite);
4285 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4286 (s - SvPVX(PL_linestr)) - stuffstart);
4294 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4295 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4303 const char tmp = *s++;
4308 const char tmp = *s++;
4316 if (PL_lex_brackets <= 0)
4317 yyerror("Unmatched right square bracket");
4320 if (PL_lex_state == LEX_INTERPNORMAL) {
4321 if (PL_lex_brackets == 0) {
4322 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4323 PL_lex_state = LEX_INTERPEND;
4330 if (PL_lex_brackets > 100) {
4331 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4333 switch (PL_expect) {
4335 if (PL_lex_formbrack) {
4339 if (PL_oldoldbufptr == PL_last_lop)
4340 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4342 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4343 OPERATOR(HASHBRACK);
4345 while (s < PL_bufend && SPACE_OR_TAB(*s))
4348 PL_tokenbuf[0] = '\0';
4349 if (d < PL_bufend && *d == '-') {
4350 PL_tokenbuf[0] = '-';
4352 while (d < PL_bufend && SPACE_OR_TAB(*d))
4355 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4356 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4358 while (d < PL_bufend && SPACE_OR_TAB(*d))
4361 const char minus = (PL_tokenbuf[0] == '-');
4362 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4370 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4375 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4380 if (PL_oldoldbufptr == PL_last_lop)
4381 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4383 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4386 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4388 /* This hack is to get the ${} in the message. */
4390 yyerror("syntax error");
4393 OPERATOR(HASHBRACK);
4395 /* This hack serves to disambiguate a pair of curlies
4396 * as being a block or an anon hash. Normally, expectation
4397 * determines that, but in cases where we're not in a
4398 * position to expect anything in particular (like inside
4399 * eval"") we have to resolve the ambiguity. This code
4400 * covers the case where the first term in the curlies is a
4401 * quoted string. Most other cases need to be explicitly
4402 * disambiguated by prepending a "+" before the opening
4403 * curly in order to force resolution as an anon hash.
4405 * XXX should probably propagate the outer expectation
4406 * into eval"" to rely less on this hack, but that could
4407 * potentially break current behavior of eval"".
4411 if (*s == '\'' || *s == '"' || *s == '`') {
4412 /* common case: get past first string, handling escapes */
4413 for (t++; t < PL_bufend && *t != *s;)
4414 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4418 else if (*s == 'q') {
4421 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4424 /* skip q//-like construct */
4426 char open, close, term;
4429 while (t < PL_bufend && isSPACE(*t))
4431 /* check for q => */
4432 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4433 OPERATOR(HASHBRACK);
4437 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4441 for (t++; t < PL_bufend; t++) {
4442 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4444 else if (*t == open)
4448 for (t++; t < PL_bufend; t++) {
4449 if (*t == '\\' && t+1 < PL_bufend)
4451 else if (*t == close && --brackets <= 0)
4453 else if (*t == open)
4460 /* skip plain q word */
4461 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4464 else if (isALNUM_lazy_if(t,UTF)) {
4466 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4469 while (t < PL_bufend && isSPACE(*t))
4471 /* if comma follows first term, call it an anon hash */
4472 /* XXX it could be a comma expression with loop modifiers */
4473 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4474 || (*t == '=' && t[1] == '>')))
4475 OPERATOR(HASHBRACK);
4476 if (PL_expect == XREF)
4479 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4485 yylval.ival = CopLINE(PL_curcop);
4486 if (isSPACE(*s) || *s == '#')
4487 PL_copline = NOLINE; /* invalidate current command line number */
4492 if (PL_lex_brackets <= 0)
4493 yyerror("Unmatched right curly bracket");
4495 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4496 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4497 PL_lex_formbrack = 0;
4498 if (PL_lex_state == LEX_INTERPNORMAL) {
4499 if (PL_lex_brackets == 0) {
4500 if (PL_expect & XFAKEBRACK) {
4501 PL_expect &= XENUMMASK;
4502 PL_lex_state = LEX_INTERPEND;
4507 PL_thiswhite = newSVpvs("");
4508 sv_catpvn(PL_thiswhite,"}",1);
4511 return yylex(); /* ignore fake brackets */
4513 if (*s == '-' && s[1] == '>')
4514 PL_lex_state = LEX_INTERPENDMAYBE;
4515 else if (*s != '[' && *s != '{')
4516 PL_lex_state = LEX_INTERPEND;
4519 if (PL_expect & XFAKEBRACK) {
4520 PL_expect &= XENUMMASK;
4522 return yylex(); /* ignore fake brackets */
4524 start_force(PL_curforce);
4526 curmad('X', newSVpvn(s-1,1));
4527 CURMAD('_', PL_thiswhite);
4532 PL_thistoken = newSVpvs("");
4540 if (PL_expect == XOPERATOR) {
4541 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4542 && isIDFIRST_lazy_if(s,UTF))
4544 CopLINE_dec(PL_curcop);
4545 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4546 CopLINE_inc(PL_curcop);
4551 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4553 PL_expect = XOPERATOR;
4554 force_ident(PL_tokenbuf, '&');
4558 yylval.ival = (OPpENTERSUB_AMPER<<8);
4570 const char tmp = *s++;
4577 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4578 && strchr("+-*/%.^&|<",tmp))
4579 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4580 "Reversed %c= operator",(int)tmp);
4582 if (PL_expect == XSTATE && isALPHA(tmp) &&
4583 (s == PL_linestart+1 || s[-2] == '\n') )
4585 if (PL_in_eval && !PL_rsfp) {
4590 if (strnEQ(s,"=cut",4)) {
4606 PL_thiswhite = newSVpvs("");
4607 sv_catpvn(PL_thiswhite, PL_linestart,
4608 PL_bufend - PL_linestart);
4612 PL_doextract = TRUE;
4616 if (PL_lex_brackets < PL_lex_formbrack) {
4618 #ifdef PERL_STRICT_CR
4619 while (SPACE_OR_TAB(*t))
4621 while (SPACE_OR_TAB(*t) || *t == '\r')
4624 if (*t == '\n' || *t == '#') {
4635 const char tmp = *s++;
4637 /* was this !=~ where !~ was meant?
4638 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4640 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4641 const char *t = s+1;
4643 while (t < PL_bufend && isSPACE(*t))
4646 if (*t == '/' || *t == '?' ||
4647 ((*t == 'm' || *t == 's' || *t == 'y')
4648 && !isALNUM(t[1])) ||
4649 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4650 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4651 "!=~ should be !~");
4661 if (PL_expect != XOPERATOR) {
4662 if (s[1] != '<' && !strchr(s,'>'))
4665 s = scan_heredoc(s);
4667 s = scan_inputsymbol(s);
4668 TERM(sublex_start());
4674 SHop(OP_LEFT_SHIFT);
4688 const char tmp = *s++;
4690 SHop(OP_RIGHT_SHIFT);
4691 else if (tmp == '=')
4700 if (PL_expect == XOPERATOR) {
4701 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4703 deprecate_old(commaless_variable_list);
4704 return REPORT(','); /* grandfather non-comma-format format */
4708 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4709 PL_tokenbuf[0] = '@';
4710 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4711 sizeof PL_tokenbuf - 1, FALSE);
4712 if (PL_expect == XOPERATOR)
4713 no_op("Array length", s);
4714 if (!PL_tokenbuf[1])
4716 PL_expect = XOPERATOR;
4717 PL_pending_ident = '#';
4721 PL_tokenbuf[0] = '$';
4722 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4723 sizeof PL_tokenbuf - 1, FALSE);
4724 if (PL_expect == XOPERATOR)
4726 if (!PL_tokenbuf[1]) {
4728 yyerror("Final $ should be \\$ or $name");
4732 /* This kludge not intended to be bulletproof. */
4733 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4734 yylval.opval = newSVOP(OP_CONST, 0,
4735 newSViv(CopARYBASE_get(&PL_compiling)));
4736 yylval.opval->op_private = OPpCONST_ARYBASE;
4742 const char tmp = *s;
4743 if (PL_lex_state == LEX_NORMAL)
4746 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4747 && intuit_more(s)) {
4749 PL_tokenbuf[0] = '@';
4750 if (ckWARN(WARN_SYNTAX)) {
4753 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4756 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4757 while (t < PL_bufend && *t != ']')
4759 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4760 "Multidimensional syntax %.*s not supported",
4761 (int)((t - PL_bufptr) + 1), PL_bufptr);
4765 else if (*s == '{') {
4767 PL_tokenbuf[0] = '%';
4768 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4769 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4771 char tmpbuf[sizeof PL_tokenbuf];
4774 } while (isSPACE(*t));
4775 if (isIDFIRST_lazy_if(t,UTF)) {
4777 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4781 if (*t == ';' && get_cv(tmpbuf, FALSE))
4782 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4783 "You need to quote \"%s\"",
4790 PL_expect = XOPERATOR;
4791 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4792 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4793 if (!islop || PL_last_lop_op == OP_GREPSTART)
4794 PL_expect = XOPERATOR;
4795 else if (strchr("$@\"'`q", *s))
4796 PL_expect = XTERM; /* e.g. print $fh "foo" */
4797 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4798 PL_expect = XTERM; /* e.g. print $fh &sub */
4799 else if (isIDFIRST_lazy_if(s,UTF)) {
4800 char tmpbuf[sizeof PL_tokenbuf];
4802 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4803 if ((t2 = keyword(tmpbuf, len, 0))) {
4804 /* binary operators exclude handle interpretations */
4816 PL_expect = XTERM; /* e.g. print $fh length() */
4821 PL_expect = XTERM; /* e.g. print $fh subr() */
4824 else if (isDIGIT(*s))
4825 PL_expect = XTERM; /* e.g. print $fh 3 */
4826 else if (*s == '.' && isDIGIT(s[1]))
4827 PL_expect = XTERM; /* e.g. print $fh .3 */
4828 else if ((*s == '?' || *s == '-' || *s == '+')
4829 && !isSPACE(s[1]) && s[1] != '=')
4830 PL_expect = XTERM; /* e.g. print $fh -1 */
4831 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4833 PL_expect = XTERM; /* e.g. print $fh /.../
4834 XXX except DORDOR operator
4836 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4838 PL_expect = XTERM; /* print $fh <<"EOF" */
4841 PL_pending_ident = '$';
4845 if (PL_expect == XOPERATOR)
4847 PL_tokenbuf[0] = '@';
4848 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4849 if (!PL_tokenbuf[1]) {
4852 if (PL_lex_state == LEX_NORMAL)
4854 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4856 PL_tokenbuf[0] = '%';
4858 /* Warn about @ where they meant $. */
4859 if (*s == '[' || *s == '{') {
4860 if (ckWARN(WARN_SYNTAX)) {
4861 const char *t = s + 1;
4862 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4864 if (*t == '}' || *t == ']') {
4866 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4867 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4868 "Scalar value %.*s better written as $%.*s",
4869 (int)(t-PL_bufptr), PL_bufptr,
4870 (int)(t-PL_bufptr-1), PL_bufptr+1);
4875 PL_pending_ident = '@';
4878 case '/': /* may be division, defined-or, or pattern */
4879 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4883 case '?': /* may either be conditional or pattern */
4884 if(PL_expect == XOPERATOR) {
4892 /* A // operator. */
4902 /* Disable warning on "study /blah/" */
4903 if (PL_oldoldbufptr == PL_last_uni
4904 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4905 || memNE(PL_last_uni, "study", 5)
4906 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4909 s = scan_pat(s,OP_MATCH);
4910 TERM(sublex_start());
4914 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4915 #ifdef PERL_STRICT_CR
4918 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4920 && (s == PL_linestart || s[-1] == '\n') )
4922 PL_lex_formbrack = 0;
4926 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4932 yylval.ival = OPf_SPECIAL;
4938 if (PL_expect != XOPERATOR)
4943 case '0': case '1': case '2': case '3': case '4':
4944 case '5': case '6': case '7': case '8': case '9':
4945 s = scan_num(s, &yylval);
4946 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
4947 if (PL_expect == XOPERATOR)
4952 s = scan_str(s,!!PL_madskills,FALSE);
4953 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4954 if (PL_expect == XOPERATOR) {
4955 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4957 deprecate_old(commaless_variable_list);
4958 return REPORT(','); /* grandfather non-comma-format format */
4965 yylval.ival = OP_CONST;
4966 TERM(sublex_start());
4969 s = scan_str(s,!!PL_madskills,FALSE);
4970 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4971 if (PL_expect == XOPERATOR) {
4972 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4974 deprecate_old(commaless_variable_list);
4975 return REPORT(','); /* grandfather non-comma-format format */
4982 yylval.ival = OP_CONST;
4983 /* FIXME. I think that this can be const if char *d is replaced by
4984 more localised variables. */
4985 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4986 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4987 yylval.ival = OP_STRINGIFY;
4991 TERM(sublex_start());
4994 s = scan_str(s,!!PL_madskills,FALSE);
4995 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
4996 if (PL_expect == XOPERATOR)
4997 no_op("Backticks",s);
5000 readpipe_override();
5001 TERM(sublex_start());
5005 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
5006 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5008 if (PL_expect == XOPERATOR)
5009 no_op("Backslash",s);
5013 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
5014 char *start = s + 2;
5015 while (isDIGIT(*start) || *start == '_')
5017 if (*start == '.' && isDIGIT(start[1])) {
5018 s = scan_num(s, &yylval);
5021 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
5022 else if (!isALPHA(*start) && (PL_expect == XTERM
5023 || PL_expect == XREF || PL_expect == XSTATE
5024 || PL_expect == XTERMORDORDOR)) {
5025 /* XXX Use gv_fetchpvn rather than stomping on a const string */
5026 const char c = *start;
5029 gv = gv_fetchpv(s, 0, SVt_PVCV);
5032 s = scan_num(s, &yylval);
5039 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5081 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5083 /* Some keywords can be followed by any delimiter, including ':' */
5084 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5085 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5086 (PL_tokenbuf[0] == 'q' &&
5087 strchr("qwxr", PL_tokenbuf[1])))));
5089 /* x::* is just a word, unless x is "CORE" */
5090 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5094 while (d < PL_bufend && isSPACE(*d))
5095 d++; /* no comments skipped here, or s### is misparsed */
5097 /* Is this a label? */
5098 if (!tmp && PL_expect == XSTATE
5099 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5101 yylval.pval = CopLABEL_alloc(PL_tokenbuf);
5106 /* Check for keywords */
5107 tmp = keyword(PL_tokenbuf, len, 0);
5109 /* Is this a word before a => operator? */
5110 if (*d == '=' && d[1] == '>') {
5113 = (OP*)newSVOP(OP_CONST, 0,
5114 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5115 yylval.opval->op_private = OPpCONST_BARE;
5119 if (tmp < 0) { /* second-class keyword? */
5120 GV *ogv = NULL; /* override (winner) */
5121 GV *hgv = NULL; /* hidden (loser) */
5122 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5124 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5127 if (GvIMPORTED_CV(gv))
5129 else if (! CvMETHOD(cv))
5133 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5134 (gv = *gvp) != (GV*)&PL_sv_undef &&
5135 GvCVu(gv) && GvIMPORTED_CV(gv))
5142 tmp = 0; /* overridden by import or by GLOBAL */
5145 && -tmp==KEY_lock /* XXX generalizable kludge */
5147 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
5149 tmp = 0; /* any sub overrides "weak" keyword */
5151 else { /* no override */
5153 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5154 Perl_warner(aTHX_ packWARN(WARN_MISC),
5155 "dump() better written as CORE::dump()");
5159 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5160 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5161 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5162 "Ambiguous call resolved as CORE::%s(), %s",
5163 GvENAME(hgv), "qualify as such or use &");
5170 default: /* not a keyword */
5171 /* Trade off - by using this evil construction we can pull the
5172 variable gv into the block labelled keylookup. If not, then
5173 we have to give it function scope so that the goto from the
5174 earlier ':' case doesn't bypass the initialisation. */
5176 just_a_word_zero_gv:
5184 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5187 SV *nextPL_nextwhite = 0;
5191 /* Get the rest if it looks like a package qualifier */
5193 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5195 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5198 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5199 *s == '\'' ? "'" : "::");
5204 if (PL_expect == XOPERATOR) {
5205 if (PL_bufptr == PL_linestart) {
5206 CopLINE_dec(PL_curcop);
5207 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5208 CopLINE_inc(PL_curcop);
5211 no_op("Bareword",s);
5214 /* Look for a subroutine with this name in current package,
5215 unless name is "Foo::", in which case Foo is a bearword
5216 (and a package name). */
5218 if (len > 2 && !PL_madskills &&
5219 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5221 if (ckWARN(WARN_BAREWORD)
5222 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5223 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5224 "Bareword \"%s\" refers to nonexistent package",
5227 PL_tokenbuf[len] = '\0';
5233 /* Mustn't actually add anything to a symbol table.
5234 But also don't want to "initialise" any placeholder
5235 constants that might already be there into full
5236 blown PVGVs with attached PVCV. */
5237 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5238 GV_NOADD_NOINIT, SVt_PVCV);
5243 /* if we saw a global override before, get the right name */
5246 sv = newSVpvs("CORE::GLOBAL::");
5247 sv_catpv(sv,PL_tokenbuf);
5250 /* If len is 0, newSVpv does strlen(), which is correct.
5251 If len is non-zero, then it will be the true length,
5252 and so the scalar will be created correctly. */
5253 sv = newSVpv(PL_tokenbuf,len);
5256 if (PL_madskills && !PL_thistoken) {
5257 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5258 PL_thistoken = newSVpv(start,s - start);
5259 PL_realtokenstart = s - SvPVX(PL_linestr);
5263 /* Presume this is going to be a bareword of some sort. */
5266 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5267 yylval.opval->op_private = OPpCONST_BARE;
5268 /* UTF-8 package name? */
5269 if (UTF && !IN_BYTES &&
5270 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5273 /* And if "Foo::", then that's what it certainly is. */
5278 /* Do the explicit type check so that we don't need to force
5279 the initialisation of the symbol table to have a real GV.
5280 Beware - gv may not really be a PVGV, cv may not really be
5281 a PVCV, (because of the space optimisations that gv_init
5282 understands) But they're true if for this symbol there is
5283 respectively a typeglob and a subroutine.
5285 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5286 /* Real typeglob, so get the real subroutine: */
5288 /* A proxy for a subroutine in this package? */
5289 : SvOK(gv) ? (CV *) gv : NULL)
5292 /* See if it's the indirect object for a list operator. */
5294 if (PL_oldoldbufptr &&
5295 PL_oldoldbufptr < PL_bufptr &&
5296 (PL_oldoldbufptr == PL_last_lop
5297 || PL_oldoldbufptr == PL_last_uni) &&
5298 /* NO SKIPSPACE BEFORE HERE! */
5299 (PL_expect == XREF ||
5300 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5302 bool immediate_paren = *s == '(';
5304 /* (Now we can afford to cross potential line boundary.) */
5305 s = SKIPSPACE2(s,nextPL_nextwhite);
5307 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5310 /* Two barewords in a row may indicate method call. */
5312 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5313 (tmp = intuit_method(s, gv, cv)))
5316 /* If not a declared subroutine, it's an indirect object. */
5317 /* (But it's an indir obj regardless for sort.) */
5318 /* Also, if "_" follows a filetest operator, it's a bareword */
5321 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5323 (PL_last_lop_op != OP_MAPSTART &&
5324 PL_last_lop_op != OP_GREPSTART))))
5325 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5326 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5329 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5334 PL_expect = XOPERATOR;
5337 s = SKIPSPACE2(s,nextPL_nextwhite);
5338 PL_nextwhite = nextPL_nextwhite;
5343 /* Is this a word before a => operator? */
5344 if (*s == '=' && s[1] == '>' && !pkgname) {
5346 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5347 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5348 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5352 /* If followed by a paren, it's certainly a subroutine. */
5357 while (SPACE_OR_TAB(*d))
5359 if (*d == ')' && (sv = gv_const_sv(gv))) {
5363 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5364 sv_catpvn(PL_thistoken, par, s - par);
5366 sv_free(PL_nextwhite);
5376 PL_nextwhite = PL_thiswhite;
5379 start_force(PL_curforce);
5381 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5382 PL_expect = XOPERATOR;
5385 PL_nextwhite = nextPL_nextwhite;
5386 curmad('X', PL_thistoken);
5387 PL_thistoken = newSVpvs("");
5395 /* If followed by var or block, call it a method (unless sub) */
5397 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5398 PL_last_lop = PL_oldbufptr;
5399 PL_last_lop_op = OP_METHOD;
5403 /* If followed by a bareword, see if it looks like indir obj. */
5406 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5407 && (tmp = intuit_method(s, gv, cv)))
5410 /* Not a method, so call it a subroutine (if defined) */
5413 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5414 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5415 "Ambiguous use of -%s resolved as -&%s()",
5416 PL_tokenbuf, PL_tokenbuf);
5417 /* Check for a constant sub */
5418 if ((sv = gv_const_sv(gv))) {
5420 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5421 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5422 yylval.opval->op_private = 0;
5426 /* Resolve to GV now. */
5427 if (SvTYPE(gv) != SVt_PVGV) {
5428 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5429 assert (SvTYPE(gv) == SVt_PVGV);
5430 /* cv must have been some sort of placeholder, so
5431 now needs replacing with a real code reference. */
5435 op_free(yylval.opval);
5436 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5437 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5438 PL_last_lop = PL_oldbufptr;
5439 PL_last_lop_op = OP_ENTERSUB;
5440 /* Is there a prototype? */
5448 const char *proto = SvPV_const((SV*)cv, protolen);
5451 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
5453 while (*proto == ';')
5455 if (*proto == '&' && *s == '{') {
5456 sv_setpv(PL_subname,
5459 "__ANON__" : "__ANON__::__ANON__"));
5466 PL_nextwhite = PL_thiswhite;
5469 start_force(PL_curforce);
5470 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5473 PL_nextwhite = nextPL_nextwhite;
5474 curmad('X', PL_thistoken);
5475 PL_thistoken = newSVpvs("");
5482 /* Guess harder when madskills require "best effort". */
5483 if (PL_madskills && (!gv || !GvCVu(gv))) {
5484 int probable_sub = 0;
5485 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5487 else if (isALPHA(*s)) {
5491 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5492 if (!keyword(tmpbuf, tmplen, 0))
5495 while (d < PL_bufend && isSPACE(*d))
5497 if (*d == '=' && d[1] == '>')
5502 gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5503 op_free(yylval.opval);
5504 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5505 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5506 PL_last_lop = PL_oldbufptr;
5507 PL_last_lop_op = OP_ENTERSUB;
5508 PL_nextwhite = PL_thiswhite;
5510 start_force(PL_curforce);
5511 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5513 PL_nextwhite = nextPL_nextwhite;
5514 curmad('X', PL_thistoken);
5515 PL_thistoken = newSVpvs("");
5520 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5527 /* Call it a bare word */
5529 if (PL_hints & HINT_STRICT_SUBS)
5530 yylval.opval->op_private |= OPpCONST_STRICT;
5533 if (lastchar != '-') {
5534 if (ckWARN(WARN_RESERVED)) {
5538 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
5539 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5546 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5547 && ckWARN_d(WARN_AMBIGUOUS)) {
5548 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5549 "Operator or semicolon missing before %c%s",
5550 lastchar, PL_tokenbuf);
5551 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5552 "Ambiguous use of %c resolved as operator %c",
5553 lastchar, lastchar);
5559 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5560 newSVpv(CopFILE(PL_curcop),0));
5564 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5565 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5568 case KEY___PACKAGE__:
5569 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5571 ? newSVhek(HvNAME_HEK(PL_curstash))
5578 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5579 const char *pname = "main";
5580 if (PL_tokenbuf[2] == 'D')
5581 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5582 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5586 GvIOp(gv) = newIO();
5587 IoIFP(GvIOp(gv)) = PL_rsfp;
5588 #if defined(HAS_FCNTL) && defined(F_SETFD)
5590 const int fd = PerlIO_fileno(PL_rsfp);
5591 fcntl(fd,F_SETFD,fd >= 3);
5594 /* Mark this internal pseudo-handle as clean */
5595 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5597 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5598 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5599 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5601 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5602 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5603 /* if the script was opened in binmode, we need to revert
5604 * it to text mode for compatibility; but only iff it has CRs
5605 * XXX this is a questionable hack at best. */
5606 if (PL_bufend-PL_bufptr > 2
5607 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5610 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5611 loc = PerlIO_tell(PL_rsfp);
5612 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5615 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5617 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5618 #endif /* NETWARE */
5619 #ifdef PERLIO_IS_STDIO /* really? */
5620 # if defined(__BORLANDC__)
5621 /* XXX see note in do_binmode() */
5622 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5626 PerlIO_seek(PL_rsfp, loc, 0);
5630 #ifdef PERLIO_LAYERS
5633 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5634 else if (PL_encoding) {
5641 XPUSHs(PL_encoding);
5643 call_method("name", G_SCALAR);
5647 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5648 Perl_form(aTHX_ ":encoding(%"SVf")",
5657 if (PL_realtokenstart >= 0) {
5658 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5660 PL_endwhite = newSVpvs("");
5661 sv_catsv(PL_endwhite, PL_thiswhite);
5663 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5664 PL_realtokenstart = -1;
5666 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5667 SvCUR(PL_endwhite))) != Nullch) ;
5682 if (PL_expect == XSTATE) {
5689 if (*s == ':' && s[1] == ':') {
5692 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5693 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5694 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5697 else if (tmp == KEY_require || tmp == KEY_do)
5698 /* that's a way to remember we saw "CORE::" */
5711 LOP(OP_ACCEPT,XTERM);
5717 LOP(OP_ATAN2,XTERM);
5723 LOP(OP_BINMODE,XTERM);
5726 LOP(OP_BLESS,XTERM);
5735 /* When 'use switch' is in effect, continue has a dual
5736 life as a control operator. */
5738 if (!FEATURE_IS_ENABLED("switch"))
5741 /* We have to disambiguate the two senses of
5742 "continue". If the next token is a '{' then
5743 treat it as the start of a continue block;
5744 otherwise treat it as a control operator.
5756 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5773 if (!PL_cryptseen) {
5774 PL_cryptseen = TRUE;
5778 LOP(OP_CRYPT,XTERM);
5781 LOP(OP_CHMOD,XTERM);
5784 LOP(OP_CHOWN,XTERM);
5787 LOP(OP_CONNECT,XTERM);
5806 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5807 if (orig_keyword == KEY_do) {
5816 PL_hints |= HINT_BLOCK_SCOPE;
5826 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5827 LOP(OP_DBMOPEN,XTERM);
5833 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5840 yylval.ival = CopLINE(PL_curcop);
5856 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5857 UNIBRACK(OP_ENTEREVAL);
5875 case KEY_endhostent:
5881 case KEY_endservent:
5884 case KEY_endprotoent:
5895 yylval.ival = CopLINE(PL_curcop);
5897 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5900 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5903 if ((PL_bufend - p) >= 3 &&
5904 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5906 else if ((PL_bufend - p) >= 4 &&
5907 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5910 if (isIDFIRST_lazy_if(p,UTF)) {
5911 p = scan_ident(p, PL_bufend,
5912 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5916 Perl_croak(aTHX_ "Missing $ on loop variable");
5918 s = SvPVX(PL_linestr) + soff;
5924 LOP(OP_FORMLINE,XTERM);
5930 LOP(OP_FCNTL,XTERM);
5936 LOP(OP_FLOCK,XTERM);
5945 LOP(OP_GREPSTART, XREF);
5948 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5963 case KEY_getpriority:
5964 LOP(OP_GETPRIORITY,XTERM);
5966 case KEY_getprotobyname:
5969 case KEY_getprotobynumber:
5970 LOP(OP_GPBYNUMBER,XTERM);
5972 case KEY_getprotoent:
5984 case KEY_getpeername:
5985 UNI(OP_GETPEERNAME);
5987 case KEY_gethostbyname:
5990 case KEY_gethostbyaddr:
5991 LOP(OP_GHBYADDR,XTERM);
5993 case KEY_gethostent:
5996 case KEY_getnetbyname:
5999 case KEY_getnetbyaddr:
6000 LOP(OP_GNBYADDR,XTERM);
6005 case KEY_getservbyname:
6006 LOP(OP_GSBYNAME,XTERM);
6008 case KEY_getservbyport:
6009 LOP(OP_GSBYPORT,XTERM);
6011 case KEY_getservent:
6014 case KEY_getsockname:
6015 UNI(OP_GETSOCKNAME);
6017 case KEY_getsockopt:
6018 LOP(OP_GSOCKOPT,XTERM);
6033 yylval.ival = CopLINE(PL_curcop);
6044 yylval.ival = CopLINE(PL_curcop);
6048 LOP(OP_INDEX,XTERM);
6054 LOP(OP_IOCTL,XTERM);
6066 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6098 LOP(OP_LISTEN,XTERM);
6107 s = scan_pat(s,OP_MATCH);
6108 TERM(sublex_start());
6111 LOP(OP_MAPSTART, XREF);
6114 LOP(OP_MKDIR,XTERM);
6117 LOP(OP_MSGCTL,XTERM);
6120 LOP(OP_MSGGET,XTERM);
6123 LOP(OP_MSGRCV,XTERM);
6126 LOP(OP_MSGSND,XTERM);
6133 if (isIDFIRST_lazy_if(s,UTF)) {
6137 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6138 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6140 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6141 if (!PL_in_my_stash) {
6144 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6148 if (PL_madskills) { /* just add type to declarator token */
6149 sv_catsv(PL_thistoken, PL_nextwhite);
6151 sv_catpvn(PL_thistoken, start, s - start);
6159 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6166 s = tokenize_use(0, s);
6170 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6177 if (isIDFIRST_lazy_if(s,UTF)) {
6179 for (d = s; isALNUM_lazy_if(d,UTF);)
6181 for (t=d; isSPACE(*t);)
6183 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6185 && !(t[0] == '=' && t[1] == '>')
6187 int parms_len = (int)(d-s);
6188 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6189 "Precedence problem: open %.*s should be open(%.*s)",
6190 parms_len, s, parms_len, s);
6196 yylval.ival = OP_OR;
6206 LOP(OP_OPEN_DIR,XTERM);
6209 checkcomma(s,PL_tokenbuf,"filehandle");
6213 checkcomma(s,PL_tokenbuf,"filehandle");
6232 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6236 LOP(OP_PIPE_OP,XTERM);
6239 s = scan_str(s,!!PL_madskills,FALSE);
6242 yylval.ival = OP_CONST;
6243 TERM(sublex_start());
6249 s = scan_str(s,!!PL_madskills,FALSE);
6252 PL_expect = XOPERATOR;
6254 if (SvCUR(PL_lex_stuff)) {
6257 d = SvPV_force(PL_lex_stuff, len);
6259 for (; isSPACE(*d) && len; --len, ++d)
6264 if (!warned && ckWARN(WARN_QW)) {
6265 for (; !isSPACE(*d) && len; --len, ++d) {
6267 Perl_warner(aTHX_ packWARN(WARN_QW),
6268 "Possible attempt to separate words with commas");
6271 else if (*d == '#') {
6272 Perl_warner(aTHX_ packWARN(WARN_QW),
6273 "Possible attempt to put comments in qw() list");
6279 for (; !isSPACE(*d) && len; --len, ++d)
6282 sv = newSVpvn(b, d-b);
6283 if (DO_UTF8(PL_lex_stuff))
6285 words = append_elem(OP_LIST, words,
6286 newSVOP(OP_CONST, 0, tokeq(sv)));
6290 start_force(PL_curforce);
6291 NEXTVAL_NEXTTOKE.opval = words;
6296 SvREFCNT_dec(PL_lex_stuff);
6297 PL_lex_stuff = NULL;
6303 s = scan_str(s,!!PL_madskills,FALSE);
6306 yylval.ival = OP_STRINGIFY;
6307 if (SvIVX(PL_lex_stuff) == '\'')
6308 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6309 TERM(sublex_start());
6312 s = scan_pat(s,OP_QR);
6313 TERM(sublex_start());
6316 s = scan_str(s,!!PL_madskills,FALSE);
6319 readpipe_override();
6320 TERM(sublex_start());
6328 s = force_version(s, FALSE);
6330 else if (*s != 'v' || !isDIGIT(s[1])
6331 || (s = force_version(s, TRUE), *s == 'v'))
6333 *PL_tokenbuf = '\0';
6334 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6335 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6336 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6338 yyerror("<> should be quotes");
6340 if (orig_keyword == KEY_require) {
6348 PL_last_uni = PL_oldbufptr;
6349 PL_last_lop_op = OP_REQUIRE;
6351 return REPORT( (int)REQUIRE );
6357 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6361 LOP(OP_RENAME,XTERM);
6370 LOP(OP_RINDEX,XTERM);
6380 UNIDOR(OP_READLINE);
6393 LOP(OP_REVERSE,XTERM);
6396 UNIDOR(OP_READLINK);
6404 TERM(sublex_start());
6406 TOKEN(1); /* force error */
6409 checkcomma(s,PL_tokenbuf,"filehandle");
6419 LOP(OP_SELECT,XTERM);
6425 LOP(OP_SEMCTL,XTERM);
6428 LOP(OP_SEMGET,XTERM);
6431 LOP(OP_SEMOP,XTERM);
6437 LOP(OP_SETPGRP,XTERM);
6439 case KEY_setpriority:
6440 LOP(OP_SETPRIORITY,XTERM);
6442 case KEY_sethostent:
6448 case KEY_setservent:
6451 case KEY_setprotoent:
6461 LOP(OP_SEEKDIR,XTERM);
6463 case KEY_setsockopt:
6464 LOP(OP_SSOCKOPT,XTERM);
6470 LOP(OP_SHMCTL,XTERM);
6473 LOP(OP_SHMGET,XTERM);
6476 LOP(OP_SHMREAD,XTERM);
6479 LOP(OP_SHMWRITE,XTERM);
6482 LOP(OP_SHUTDOWN,XTERM);
6491 LOP(OP_SOCKET,XTERM);
6493 case KEY_socketpair:
6494 LOP(OP_SOCKPAIR,XTERM);
6497 checkcomma(s,PL_tokenbuf,"subroutine name");
6499 if (*s == ';' || *s == ')') /* probably a close */
6500 Perl_croak(aTHX_ "sort is now a reserved word");
6502 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6506 LOP(OP_SPLIT,XTERM);
6509 LOP(OP_SPRINTF,XTERM);
6512 LOP(OP_SPLICE,XTERM);
6527 LOP(OP_SUBSTR,XTERM);
6533 char tmpbuf[sizeof PL_tokenbuf];
6534 SSize_t tboffset = 0;
6535 expectation attrful;
6536 bool have_name, have_proto;
6537 const int key = tmp;
6542 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6543 SV *subtoken = newSVpvn(tstart, s - tstart);
6547 s = SKIPSPACE2(s,tmpwhite);
6552 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6553 (*s == ':' && s[1] == ':'))
6560 attrful = XATTRBLOCK;
6561 /* remember buffer pos'n for later force_word */
6562 tboffset = s - PL_oldbufptr;
6563 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6566 nametoke = newSVpvn(s, d - s);
6568 if (strchr(tmpbuf, ':'))
6569 sv_setpv(PL_subname, tmpbuf);
6571 sv_setsv(PL_subname,PL_curstname);
6572 sv_catpvs(PL_subname,"::");
6573 sv_catpvn(PL_subname,tmpbuf,len);
6580 CURMAD('X', nametoke);
6581 CURMAD('_', tmpwhite);
6582 (void) force_word(PL_oldbufptr + tboffset, WORD,
6585 s = SKIPSPACE2(d,tmpwhite);
6592 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6593 PL_expect = XTERMBLOCK;
6594 attrful = XATTRTERM;
6595 sv_setpvn(PL_subname,"?",1);
6599 if (key == KEY_format) {
6601 PL_lex_formbrack = PL_lex_brackets + 1;
6603 PL_thistoken = subtoken;
6607 (void) force_word(PL_oldbufptr + tboffset, WORD,
6613 /* Look for a prototype */
6616 bool bad_proto = FALSE;
6617 const bool warnsyntax = ckWARN(WARN_SYNTAX);
6619 s = scan_str(s,!!PL_madskills,FALSE);
6621 Perl_croak(aTHX_ "Prototype not terminated");
6622 /* strip spaces and check for bad characters */
6623 d = SvPVX(PL_lex_stuff);
6625 for (p = d; *p; ++p) {
6628 if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
6634 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6635 "Illegal character in prototype for %"SVf" : %s",
6636 (void*)PL_subname, d);
6637 SvCUR_set(PL_lex_stuff, tmp);
6642 CURMAD('q', PL_thisopen);
6643 CURMAD('_', tmpwhite);
6644 CURMAD('=', PL_thisstuff);
6645 CURMAD('Q', PL_thisclose);
6646 NEXTVAL_NEXTTOKE.opval =
6647 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6648 PL_lex_stuff = Nullsv;
6651 s = SKIPSPACE2(s,tmpwhite);
6659 if (*s == ':' && s[1] != ':')
6660 PL_expect = attrful;
6661 else if (*s != '{' && key == KEY_sub) {
6663 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6665 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, (void*)PL_subname);
6672 curmad('^', newSVpvs(""));
6673 CURMAD('_', tmpwhite);
6677 PL_thistoken = subtoken;
6680 NEXTVAL_NEXTTOKE.opval =
6681 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6682 PL_lex_stuff = NULL;
6687 sv_setpv(PL_subname,
6689 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
6693 (void) force_word(PL_oldbufptr + tboffset, WORD,
6703 LOP(OP_SYSTEM,XREF);
6706 LOP(OP_SYMLINK,XTERM);
6709 LOP(OP_SYSCALL,XTERM);
6712 LOP(OP_SYSOPEN,XTERM);
6715 LOP(OP_SYSSEEK,XTERM);
6718 LOP(OP_SYSREAD,XTERM);
6721 LOP(OP_SYSWRITE,XTERM);
6725 TERM(sublex_start());
6746 LOP(OP_TRUNCATE,XTERM);
6758 yylval.ival = CopLINE(PL_curcop);
6762 yylval.ival = CopLINE(PL_curcop);
6766 LOP(OP_UNLINK,XTERM);
6772 LOP(OP_UNPACK,XTERM);
6775 LOP(OP_UTIME,XTERM);
6781 LOP(OP_UNSHIFT,XTERM);
6784 s = tokenize_use(1, s);
6794 yylval.ival = CopLINE(PL_curcop);
6798 yylval.ival = CopLINE(PL_curcop);
6802 PL_hints |= HINT_BLOCK_SCOPE;
6809 LOP(OP_WAITPID,XTERM);
6818 ctl_l[0] = toCTRL('L');
6820 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6823 /* Make sure $^L is defined */
6824 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6829 if (PL_expect == XOPERATOR)
6835 yylval.ival = OP_XOR;
6840 TERM(sublex_start());
6845 #pragma segment Main
6849 S_pending_ident(pTHX)
6854 /* pit holds the identifier we read and pending_ident is reset */
6855 char pit = PL_pending_ident;
6856 PL_pending_ident = 0;
6858 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6859 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6860 "### Pending identifier '%s'\n", PL_tokenbuf); });
6862 /* if we're in a my(), we can't allow dynamics here.
6863 $foo'bar has already been turned into $foo::bar, so
6864 just check for colons.
6866 if it's a legal name, the OP is a PADANY.
6869 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6870 if (strchr(PL_tokenbuf,':'))
6871 yyerror(Perl_form(aTHX_ "No package name allowed for "
6872 "variable %s in \"our\"",
6874 tmp = allocmy(PL_tokenbuf);
6877 if (strchr(PL_tokenbuf,':'))
6878 yyerror(Perl_form(aTHX_ PL_no_myglob,
6879 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6881 yylval.opval = newOP(OP_PADANY, 0);
6882 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6888 build the ops for accesses to a my() variable.
6890 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6891 then used in a comparison. This catches most, but not
6892 all cases. For instance, it catches
6893 sort { my($a); $a <=> $b }
6895 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6896 (although why you'd do that is anyone's guess).
6899 if (!strchr(PL_tokenbuf,':')) {
6901 tmp = pad_findmy(PL_tokenbuf);
6902 if (tmp != NOT_IN_PAD) {
6903 /* might be an "our" variable" */
6904 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6905 /* build ops for a bareword */
6906 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6907 HEK * const stashname = HvNAME_HEK(stash);
6908 SV * const sym = newSVhek(stashname);
6909 sv_catpvs(sym, "::");
6910 sv_catpv(sym, PL_tokenbuf+1);
6911 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6912 yylval.opval->op_private = OPpCONST_ENTERED;
6915 ? (GV_ADDMULTI | GV_ADDINEVAL)
6918 ((PL_tokenbuf[0] == '$') ? SVt_PV
6919 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6924 /* if it's a sort block and they're naming $a or $b */
6925 if (PL_last_lop_op == OP_SORT &&
6926 PL_tokenbuf[0] == '$' &&
6927 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6930 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6931 d < PL_bufend && *d != '\n';
6934 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6935 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6941 yylval.opval = newOP(OP_PADANY, 0);
6942 yylval.opval->op_targ = tmp;
6948 Whine if they've said @foo in a doublequoted string,
6949 and @foo isn't a variable we can find in the symbol
6952 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6953 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6954 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6955 && ckWARN(WARN_AMBIGUOUS))
6957 /* Downgraded from fatal to warning 20000522 mjd */
6958 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6959 "Possible unintended interpolation of %s in string",
6964 /* build ops for a bareword */
6965 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6966 yylval.opval->op_private = OPpCONST_ENTERED;
6969 /* If the identifier refers to a stash, don't autovivify it.
6970 * Change 24660 had the side effect of causing symbol table
6971 * hashes to always be defined, even if they were freshly
6972 * created and the only reference in the entire program was
6973 * the single statement with the defined %foo::bar:: test.
6974 * It appears that all code in the wild doing this actually
6975 * wants to know whether sub-packages have been loaded, so
6976 * by avoiding auto-vivifying symbol tables, we ensure that
6977 * defined %foo::bar:: continues to be false, and the existing
6978 * tests still give the expected answers, even though what
6979 * they're actually testing has now changed subtly.
6981 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6983 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
6984 ((PL_tokenbuf[0] == '$') ? SVt_PV
6985 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6991 * The following code was generated by perl_keyword.pl.
6995 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
7000 case 1: /* 5 tokens of length 1 */
7032 case 2: /* 18 tokens of length 2 */
7178 case 3: /* 29 tokens of length 3 */
7182 if (name[1] == 'N' &&
7245 if (name[1] == 'i' &&
7267 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7285 if (name[1] == 'o' &&
7294 if (name[1] == 'e' &&
7303 if (name[1] == 'n' &&
7312 if (name[1] == 'o' &&
7321 if (name[1] == 'a' &&
7330 if (name[1] == 'o' &&
7392 if (name[1] == 'e' &&
7406 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
7432 if (name[1] == 'i' &&
7441 if (name[1] == 's' &&
7450 if (name[1] == 'e' &&
7459 if (name[1] == 'o' &&
7471 case 4: /* 41 tokens of length 4 */
7475 if (name[1] == 'O' &&
7485 if (name[1] == 'N' &&
7495 if (name[1] == 'i' &&
7505 if (name[1] == 'h' &&
7515 if (name[1] == 'u' &&
7528 if (name[2] == 'c' &&
7537 if (name[2] == 's' &&
7546 if (name[2] == 'a' &&
7582 if (name[1] == 'o' &&
7595 if (name[2] == 't' &&
7604 if (name[2] == 'o' &&
7613 if (name[2] == 't' &&
7622 if (name[2] == 'e' &&
7635 if (name[1] == 'o' &&
7648 if (name[2] == 'y' &&
7657 if (name[2] == 'l' &&
7673 if (name[2] == 's' &&
7682 if (name[2] == 'n' &&
7691 if (name[2] == 'c' &&
7704 if (name[1] == 'e' &&
7714 if (name[1] == 'p' &&
7727 if (name[2] == 'c' &&
7736 if (name[2] == 'p' &&
7745 if (name[2] == 's' &&
7761 if (name[2] == 'n' &&
7831 if (name[2] == 'r' &&
7840 if (name[2] == 'r' &&
7849 if (name[2] == 'a' &&
7865 if (name[2] == 'l' &&
7927 if (name[2] == 'e' &&
7930 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7943 case 5: /* 39 tokens of length 5 */
7947 if (name[1] == 'E' &&
7958 if (name[1] == 'H' &&
7972 if (name[2] == 'a' &&
7982 if (name[2] == 'a' &&
7999 if (name[2] == 'e' &&
8009 if (name[2] == 'e' &&
8013 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
8029 if (name[3] == 'i' &&
8038 if (name[3] == 'o' &&
8074 if (name[2] == 'o' &&
8084 if (name[2] == 'y' &&
8098 if (name[1] == 'l' &&
8112 if (name[2] == 'n' &&
8122 if (name[2] == 'o' &&
8136 if (name[1] == 'i' &&
8141 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8150 if (name[2] == 'd' &&
8160 if (name[2] == 'c' &&
8177 if (name[2] == 'c' &&
8187 if (name[2] == 't' &&
8201 if (name[1] == 'k' &&
8212 if (name[1] == 'r' &&
8226 if (name[2] == 's' &&
8236 if (name[2] == 'd' &&
8253 if (name[2] == 'm' &&
8263 if (name[2] == 'i' &&
8273 if (name[2] == 'e' &&
8283 if (name[2] == 'l' &&
8293 if (name[2] == 'a' &&
8306 if (name[3] == 't' &&
8309 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8315 if (name[3] == 'd' &&
8332 if (name[1] == 'i' &&
8346 if (name[2] == 'a' &&
8359 if (name[3] == 'e' &&
8394 if (name[2] == 'i' &&
8411 if (name[2] == 'i' &&
8421 if (name[2] == 'i' &&
8438 case 6: /* 33 tokens of length 6 */
8442 if (name[1] == 'c' &&
8457 if (name[2] == 'l' &&
8468 if (name[2] == 'r' &&
8483 if (name[1] == 'e' &&
8498 if (name[2] == 's' &&
8503 if(ckWARN_d(WARN_SYNTAX))
8504 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8510 if (name[2] == 'i' &&
8528 if (name[2] == 'l' &&
8539 if (name[2] == 'r' &&
8554 if (name[1] == 'm' &&
8569 if (name[2] == 'n' &&
8580 if (name[2] == 's' &&
8595 if (name[1] == 's' &&
8601 if (name[4] == 't' &&
8610 if (name[4] == 'e' &&
8619 if (name[4] == 'c' &&
8628 if (name[4] == 'n' &&
8644 if (name[1] == 'r' &&
8662 if (name[3] == 'a' &&
8672 if (name[3] == 'u' &&
8686 if (name[2] == 'n' &&
8704 if (name[2] == 'a' &&
8718 if (name[3] == 'e' &&
8731 if (name[4] == 't' &&
8740 if (name[4] == 'e' &&
8762 if (name[4] == 't' &&
8771 if (name[4] == 'e' &&
8787 if (name[2] == 'c' &&
8798 if (name[2] == 'l' &&
8809 if (name[2] == 'b' &&
8820 if (name[2] == 's' &&
8843 if (name[4] == 's' &&
8852 if (name[4] == 'n' &&
8865 if (name[3] == 'a' &&
8882 if (name[1] == 'a' &&
8897 case 7: /* 29 tokens of length 7 */
8901 if (name[1] == 'E' &&
8914 if (name[1] == '_' &&
8927 if (name[1] == 'i' &&
8934 return -KEY_binmode;
8940 if (name[1] == 'o' &&
8947 return -KEY_connect;
8956 if (name[2] == 'm' &&
8962 return -KEY_dbmopen;
8973 if (name[4] == 'u' &&
8977 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
8983 if (name[4] == 'n' &&
9004 if (name[1] == 'o' &&
9017 if (name[1] == 'e' &&
9024 if (name[5] == 'r' &&
9027 return -KEY_getpgrp;
9033 if (name[5] == 'i' &&
9036 return -KEY_getppid;
9049 if (name[1] == 'c' &&
9056 return -KEY_lcfirst;
9062 if (name[1] == 'p' &&
9069 return -KEY_opendir;
9075 if (name[1] == 'a' &&
9093 if (name[3] == 'd' &&
9098 return -KEY_readdir;
9104 if (name[3] == 'u' &&
9115 if (name[3] == 'e' &&
9120 return -KEY_reverse;
9139 if (name[3] == 'k' &&
9144 return -KEY_seekdir;
9150 if (name[3] == 'p' &&
9155 return -KEY_setpgrp;
9165 if (name[2] == 'm' &&
9171 return -KEY_shmread;
9177 if (name[2] == 'r' &&
9183 return -KEY_sprintf;
9192 if (name[3] == 'l' &&
9197 return -KEY_symlink;
9206 if (name[4] == 'a' &&
9210 return -KEY_syscall;
9216 if (name[4] == 'p' &&
9220 return -KEY_sysopen;
9226 if (name[4] == 'e' &&
9230 return -KEY_sysread;
9236 if (name[4] == 'e' &&
9240 return -KEY_sysseek;
9258 if (name[1] == 'e' &&
9265 return -KEY_telldir;
9274 if (name[2] == 'f' &&
9280 return -KEY_ucfirst;
9286 if (name[2] == 's' &&
9292 return -KEY_unshift;
9302 if (name[1] == 'a' &&
9309 return -KEY_waitpid;
9318 case 8: /* 26 tokens of length 8 */
9322 if (name[1] == 'U' &&
9330 return KEY_AUTOLOAD;
9341 if (name[3] == 'A' &&
9347 return KEY___DATA__;
9353 if (name[3] == 'I' &&
9359 return -KEY___FILE__;
9365 if (name[3] == 'I' &&
9371 return -KEY___LINE__;
9387 if (name[2] == 'o' &&
9394 return -KEY_closedir;
9400 if (name[2] == 'n' &&
9407 return -KEY_continue;
9417 if (name[1] == 'b' &&
9425 return -KEY_dbmclose;
9431 if (name[1] == 'n' &&
9437 if (name[4] == 'r' &&
9442 return -KEY_endgrent;
9448 if (name[4] == 'w' &&
9453 return -KEY_endpwent;
9466 if (name[1] == 'o' &&
9474 return -KEY_formline;
9480 if (name[1] == 'e' &&
9491 if (name[6] == 'n' &&
9494 return -KEY_getgrent;
9500 if (name[6] == 'i' &&
9503 return -KEY_getgrgid;
9509 if (name[6] == 'a' &&
9512 return -KEY_getgrnam;
9525 if (name[4] == 'o' &&
9530 return -KEY_getlogin;
9541 if (name[6] == 'n' &&
9544 return -KEY_getpwent;
9550 if (name[6] == 'a' &&
9553 return -KEY_getpwnam;
9559 if (name[6] == 'i' &&
9562 return -KEY_getpwuid;
9582 if (name[1] == 'e' &&
9589 if (name[5] == 'i' &&
9596 return -KEY_readline;
9601 return -KEY_readlink;
9612 if (name[5] == 'i' &&
9616 return -KEY_readpipe;
9637 if (name[4] == 'r' &&
9642 return -KEY_setgrent;
9648 if (name[4] == 'w' &&
9653 return -KEY_setpwent;
9669 if (name[3] == 'w' &&
9675 return -KEY_shmwrite;
9681 if (name[3] == 't' &&
9687 return -KEY_shutdown;
9697 if (name[2] == 's' &&
9704 return -KEY_syswrite;
9714 if (name[1] == 'r' &&
9722 return -KEY_truncate;
9731 case 9: /* 9 tokens of length 9 */
9735 if (name[1] == 'N' &&
9744 return KEY_UNITCHECK;
9750 if (name[1] == 'n' &&
9759 return -KEY_endnetent;
9765 if (name[1] == 'e' &&
9774 return -KEY_getnetent;
9780 if (name[1] == 'o' &&
9789 return -KEY_localtime;
9795 if (name[1] == 'r' &&
9804 return KEY_prototype;
9810 if (name[1] == 'u' &&
9819 return -KEY_quotemeta;
9825 if (name[1] == 'e' &&
9834 return -KEY_rewinddir;
9840 if (name[1] == 'e' &&
9849 return -KEY_setnetent;
9855 if (name[1] == 'a' &&
9864 return -KEY_wantarray;
9873 case 10: /* 9 tokens of length 10 */
9877 if (name[1] == 'n' &&
9883 if (name[4] == 'o' &&
9890 return -KEY_endhostent;
9896 if (name[4] == 'e' &&
9903 return -KEY_endservent;
9916 if (name[1] == 'e' &&
9922 if (name[4] == 'o' &&
9929 return -KEY_gethostent;
9938 if (name[5] == 'r' &&
9944 return -KEY_getservent;
9950 if (name[5] == 'c' &&
9956 return -KEY_getsockopt;
9981 if (name[4] == 'o' &&
9988 return -KEY_sethostent;
9997 if (name[5] == 'r' &&
10003 return -KEY_setservent;
10009 if (name[5] == 'c' &&
10015 return -KEY_setsockopt;
10032 if (name[2] == 'c' &&
10041 return -KEY_socketpair;
10054 case 11: /* 8 tokens of length 11 */
10058 if (name[1] == '_' &&
10068 { /* __PACKAGE__ */
10069 return -KEY___PACKAGE__;
10075 if (name[1] == 'n' &&
10085 { /* endprotoent */
10086 return -KEY_endprotoent;
10092 if (name[1] == 'e' &&
10101 if (name[5] == 'e' &&
10107 { /* getpeername */
10108 return -KEY_getpeername;
10117 if (name[6] == 'o' &&
10122 { /* getpriority */
10123 return -KEY_getpriority;
10129 if (name[6] == 't' &&
10134 { /* getprotoent */
10135 return -KEY_getprotoent;
10149 if (name[4] == 'o' &&
10156 { /* getsockname */
10157 return -KEY_getsockname;
10170 if (name[1] == 'e' &&
10178 if (name[6] == 'o' &&
10183 { /* setpriority */
10184 return -KEY_setpriority;
10190 if (name[6] == 't' &&
10195 { /* setprotoent */
10196 return -KEY_setprotoent;
10212 case 12: /* 2 tokens of length 12 */
10213 if (name[0] == 'g' &&
10225 if (name[9] == 'd' &&
10228 { /* getnetbyaddr */
10229 return -KEY_getnetbyaddr;
10235 if (name[9] == 'a' &&
10238 { /* getnetbyname */
10239 return -KEY_getnetbyname;
10251 case 13: /* 4 tokens of length 13 */
10252 if (name[0] == 'g' &&
10259 if (name[4] == 'o' &&
10268 if (name[10] == 'd' &&
10271 { /* gethostbyaddr */
10272 return -KEY_gethostbyaddr;
10278 if (name[10] == 'a' &&
10281 { /* gethostbyname */
10282 return -KEY_gethostbyname;
10295 if (name[4] == 'e' &&
10304 if (name[10] == 'a' &&
10307 { /* getservbyname */
10308 return -KEY_getservbyname;
10314 if (name[10] == 'o' &&
10317 { /* getservbyport */
10318 return -KEY_getservbyport;
10337 case 14: /* 1 tokens of length 14 */
10338 if (name[0] == 'g' &&
10352 { /* getprotobyname */
10353 return -KEY_getprotobyname;
10358 case 16: /* 1 tokens of length 16 */
10359 if (name[0] == 'g' &&
10375 { /* getprotobynumber */
10376 return -KEY_getprotobynumber;
10390 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10394 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10395 if (ckWARN(WARN_SYNTAX)) {
10398 for (w = s+2; *w && level; w++) {
10401 else if (*w == ')')
10404 while (isSPACE(*w))
10406 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
10407 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10408 "%s (...) interpreted as function",name);
10411 while (s < PL_bufend && isSPACE(*s))
10415 while (s < PL_bufend && isSPACE(*s))
10417 if (isIDFIRST_lazy_if(s,UTF)) {
10418 const char * const w = s++;
10419 while (isALNUM_lazy_if(s,UTF))
10421 while (s < PL_bufend && isSPACE(*s))
10425 if (keyword(w, s - w, 0))
10428 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10429 if (gv && GvCVu(gv))
10431 Perl_croak(aTHX_ "No comma allowed after %s", what);
10436 /* Either returns sv, or mortalizes sv and returns a new SV*.
10437 Best used as sv=new_constant(..., sv, ...).
10438 If s, pv are NULL, calls subroutine with one argument,
10439 and type is used with error messages only. */
10442 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10446 HV * const table = GvHV(PL_hintgv); /* ^H */
10450 const char *why1 = "", *why2 = "", *why3 = "";
10452 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10455 why2 = (const char *)
10456 (strEQ(key,"charnames")
10457 ? "(possibly a missing \"use charnames ...\")"
10459 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10460 (type ? type: "undef"), why2);
10462 /* This is convoluted and evil ("goto considered harmful")
10463 * but I do not understand the intricacies of all the different
10464 * failure modes of %^H in here. The goal here is to make
10465 * the most probable error message user-friendly. --jhi */
10470 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10471 (type ? type: "undef"), why1, why2, why3);
10473 yyerror(SvPVX_const(msg));
10477 cvp = hv_fetch(table, key, strlen(key), FALSE);
10478 if (!cvp || !SvOK(*cvp)) {
10481 why3 = "} is not defined";
10484 sv_2mortal(sv); /* Parent created it permanently */
10487 pv = sv_2mortal(newSVpvn(s, len));
10489 typesv = sv_2mortal(newSVpv(type, 0));
10491 typesv = &PL_sv_undef;
10493 PUSHSTACKi(PERLSI_OVERLOAD);
10505 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10509 /* Check the eval first */
10510 if (!PL_in_eval && SvTRUE(ERRSV)) {
10511 sv_catpvs(ERRSV, "Propagated");
10512 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10514 res = SvREFCNT_inc_simple(sv);
10518 SvREFCNT_inc_simple_void(res);
10527 why1 = "Call to &{$^H{";
10529 why3 = "}} did not return a defined value";
10537 /* Returns a NUL terminated string, with the length of the string written to
10541 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10544 register char *d = dest;
10545 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10548 Perl_croak(aTHX_ ident_too_long);
10549 if (isALNUM(*s)) /* UTF handled below */
10551 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10556 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10560 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10561 char *t = s + UTF8SKIP(s);
10563 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10567 Perl_croak(aTHX_ ident_too_long);
10568 Copy(s, d, len, char);
10581 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10584 char *bracket = NULL;
10586 register char *d = dest;
10587 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10592 while (isDIGIT(*s)) {
10594 Perl_croak(aTHX_ ident_too_long);
10601 Perl_croak(aTHX_ ident_too_long);
10602 if (isALNUM(*s)) /* UTF handled below */
10604 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10609 else if (*s == ':' && s[1] == ':') {
10613 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10614 char *t = s + UTF8SKIP(s);
10615 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10617 if (d + (t - s) > e)
10618 Perl_croak(aTHX_ ident_too_long);
10619 Copy(s, d, t - s, char);
10630 if (PL_lex_state != LEX_NORMAL)
10631 PL_lex_state = LEX_INTERPENDMAYBE;
10634 if (*s == '$' && s[1] &&
10635 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10648 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10653 if (isSPACE(s[-1])) {
10655 const char ch = *s++;
10656 if (!SPACE_OR_TAB(ch)) {
10662 if (isIDFIRST_lazy_if(d,UTF)) {
10666 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10667 end += UTF8SKIP(end);
10668 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10669 end += UTF8SKIP(end);
10671 Copy(s, d, end - s, char);
10676 while ((isALNUM(*s) || *s == ':') && d < e)
10679 Perl_croak(aTHX_ ident_too_long);
10682 while (s < send && SPACE_OR_TAB(*s))
10684 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10685 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10686 const char * const brack =
10688 ((*s == '[') ? "[...]" : "{...}");
10689 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10690 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10691 funny, dest, brack, funny, dest, brack);
10694 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10698 /* Handle extended ${^Foo} variables
10699 * 1999-02-27 mjd-perl-patch@plover.com */
10700 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10704 while (isALNUM(*s) && d < e) {
10708 Perl_croak(aTHX_ ident_too_long);
10713 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10714 PL_lex_state = LEX_INTERPEND;
10717 if (PL_lex_state == LEX_NORMAL) {
10718 if (ckWARN(WARN_AMBIGUOUS) &&
10719 (keyword(dest, d - dest, 0) || get_cv(dest, FALSE)))
10723 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10724 "Ambiguous use of %c{%s} resolved to %c%s",
10725 funny, dest, funny, dest);
10730 s = bracket; /* let the parser handle it */
10734 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10735 PL_lex_state = LEX_INTERPEND;
10740 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10742 PERL_UNUSED_CONTEXT;
10745 else if (ch == 'g')
10746 *pmfl |= PMf_GLOBAL;
10747 else if (ch == 'c')
10748 *pmfl |= PMf_CONTINUE;
10749 else if (ch == 'o')
10751 else if (ch == 'm')
10752 *pmfl |= PMf_MULTILINE;
10753 else if (ch == 's')
10754 *pmfl |= PMf_SINGLELINE;
10755 else if (ch == 'x')
10756 *pmfl |= PMf_EXTENDED;
10760 S_scan_pat(pTHX_ char *start, I32 type)
10764 char *s = scan_str(start,!!PL_madskills,FALSE);
10765 const char * const valid_flags =
10766 (const char *)((type == OP_QR) ? "iomsx" : "iogcmsx");
10773 const char * const delimiter = skipspace(start);
10777 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10778 : "Search pattern not terminated" ));
10781 pm = (PMOP*)newPMOP(type, 0);
10782 if (PL_multi_open == '?')
10783 pm->op_pmflags |= PMf_ONCE;
10787 while (*s && strchr(valid_flags, *s))
10788 pmflag(&pm->op_pmflags,*s++);
10790 if (PL_madskills && modstart != s) {
10791 SV* tmptoken = newSVpvn(modstart, s - modstart);
10792 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10795 /* issue a warning if /c is specified,but /g is not */
10796 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10797 && ckWARN(WARN_REGEXP))
10799 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
10802 pm->op_pmpermflags = pm->op_pmflags;
10804 PL_lex_op = (OP*)pm;
10805 yylval.ival = OP_MATCH;
10810 S_scan_subst(pTHX_ char *start)
10821 yylval.ival = OP_NULL;
10823 s = scan_str(start,!!PL_madskills,FALSE);
10826 Perl_croak(aTHX_ "Substitution pattern not terminated");
10828 if (s[-1] == PL_multi_open)
10831 if (PL_madskills) {
10832 CURMAD('q', PL_thisopen);
10833 CURMAD('_', PL_thiswhite);
10834 CURMAD('E', PL_thisstuff);
10835 CURMAD('Q', PL_thisclose);
10836 PL_realtokenstart = s - SvPVX(PL_linestr);
10840 first_start = PL_multi_start;
10841 s = scan_str(s,!!PL_madskills,FALSE);
10843 if (PL_lex_stuff) {
10844 SvREFCNT_dec(PL_lex_stuff);
10845 PL_lex_stuff = NULL;
10847 Perl_croak(aTHX_ "Substitution replacement not terminated");
10849 PL_multi_start = first_start; /* so whole substitution is taken together */
10851 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10854 if (PL_madskills) {
10855 CURMAD('z', PL_thisopen);
10856 CURMAD('R', PL_thisstuff);
10857 CURMAD('Z', PL_thisclose);
10867 else if (strchr("iogcmsx", *s))
10868 pmflag(&pm->op_pmflags,*s++);
10874 if (PL_madskills) {
10876 curmad('m', newSVpvn(modstart, s - modstart));
10877 append_madprops(PL_thismad, (OP*)pm, 0);
10881 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10882 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10886 SV * const repl = newSVpvs("");
10888 PL_sublex_info.super_bufptr = s;
10889 PL_sublex_info.super_bufend = PL_bufend;
10891 pm->op_pmflags |= PMf_EVAL;
10893 sv_catpv(repl, (const char *)(es ? "eval " : "do "));
10894 sv_catpvs(repl, "{");
10895 sv_catsv(repl, PL_lex_repl);
10896 if (strchr(SvPVX(PL_lex_repl), '#'))
10897 sv_catpvs(repl, "\n");
10898 sv_catpvs(repl, "}");
10900 SvREFCNT_dec(PL_lex_repl);
10901 PL_lex_repl = repl;
10904 pm->op_pmpermflags = pm->op_pmflags;
10905 PL_lex_op = (OP*)pm;
10906 yylval.ival = OP_SUBST;
10911 S_scan_trans(pTHX_ char *start)
10924 yylval.ival = OP_NULL;
10926 s = scan_str(start,!!PL_madskills,FALSE);
10928 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10930 if (s[-1] == PL_multi_open)
10933 if (PL_madskills) {
10934 CURMAD('q', PL_thisopen);
10935 CURMAD('_', PL_thiswhite);
10936 CURMAD('E', PL_thisstuff);
10937 CURMAD('Q', PL_thisclose);
10938 PL_realtokenstart = s - SvPVX(PL_linestr);
10942 s = scan_str(s,!!PL_madskills,FALSE);
10944 if (PL_lex_stuff) {
10945 SvREFCNT_dec(PL_lex_stuff);
10946 PL_lex_stuff = NULL;
10948 Perl_croak(aTHX_ "Transliteration replacement not terminated");
10950 if (PL_madskills) {
10951 CURMAD('z', PL_thisopen);
10952 CURMAD('R', PL_thisstuff);
10953 CURMAD('Z', PL_thisclose);
10956 complement = del = squash = 0;
10963 complement = OPpTRANS_COMPLEMENT;
10966 del = OPpTRANS_DELETE;
10969 squash = OPpTRANS_SQUASH;
10978 Newx(tbl, complement&&!del?258:256, short);
10979 o = newPVOP(OP_TRANS, 0, (char*)tbl);
10980 o->op_private &= ~OPpTRANS_ALL;
10981 o->op_private |= del|squash|complement|
10982 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10983 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
10986 yylval.ival = OP_TRANS;
10989 if (PL_madskills) {
10991 curmad('m', newSVpvn(modstart, s - modstart));
10992 append_madprops(PL_thismad, o, 0);
11001 S_scan_heredoc(pTHX_ register char *s)
11005 I32 op_type = OP_SCALAR;
11009 const char *found_newline;
11013 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
11015 I32 stuffstart = s - SvPVX(PL_linestr);
11018 PL_realtokenstart = -1;
11023 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
11027 while (SPACE_OR_TAB(*peek))
11029 if (*peek == '`' || *peek == '\'' || *peek =='"') {
11032 s = delimcpy(d, e, s, PL_bufend, term, &len);
11042 if (!isALNUM_lazy_if(s,UTF))
11043 deprecate_old("bare << to mean <<\"\"");
11044 for (; isALNUM_lazy_if(s,UTF); s++) {
11049 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
11050 Perl_croak(aTHX_ "Delimiter for here document is too long");
11053 len = d - PL_tokenbuf;
11056 if (PL_madskills) {
11057 tstart = PL_tokenbuf + !outer;
11058 PL_thisclose = newSVpvn(tstart, len - !outer);
11059 tstart = SvPVX(PL_linestr) + stuffstart;
11060 PL_thisopen = newSVpvn(tstart, s - tstart);
11061 stuffstart = s - SvPVX(PL_linestr);
11064 #ifndef PERL_STRICT_CR
11065 d = strchr(s, '\r');
11067 char * const olds = s;
11069 while (s < PL_bufend) {
11075 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11084 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11091 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11092 herewas = newSVpvn(s,PL_bufend-s);
11096 herewas = newSVpvn(s-1,found_newline-s+1);
11099 herewas = newSVpvn(s,found_newline-s);
11103 if (PL_madskills) {
11104 tstart = SvPVX(PL_linestr) + stuffstart;
11106 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11108 PL_thisstuff = newSVpvn(tstart, s - tstart);
11111 s += SvCUR(herewas);
11114 stuffstart = s - SvPVX(PL_linestr);
11120 tmpstr = newSV(79);
11121 sv_upgrade(tmpstr, SVt_PVIV);
11122 if (term == '\'') {
11123 op_type = OP_CONST;
11124 SvIV_set(tmpstr, -1);
11126 else if (term == '`') {
11127 op_type = OP_BACKTICK;
11128 SvIV_set(tmpstr, '\\');
11132 PL_multi_start = CopLINE(PL_curcop);
11133 PL_multi_open = PL_multi_close = '<';
11134 term = *PL_tokenbuf;
11135 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11136 char * const bufptr = PL_sublex_info.super_bufptr;
11137 char * const bufend = PL_sublex_info.super_bufend;
11138 char * const olds = s - SvCUR(herewas);
11139 s = strchr(bufptr, '\n');
11143 while (s < bufend &&
11144 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11146 CopLINE_inc(PL_curcop);
11149 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11150 missingterm(PL_tokenbuf);
11152 sv_setpvn(herewas,bufptr,d-bufptr+1);
11153 sv_setpvn(tmpstr,d+1,s-d);
11155 sv_catpvn(herewas,s,bufend-s);
11156 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11163 while (s < PL_bufend &&
11164 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11166 CopLINE_inc(PL_curcop);
11168 if (s >= PL_bufend) {
11169 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11170 missingterm(PL_tokenbuf);
11172 sv_setpvn(tmpstr,d+1,s-d);
11174 if (PL_madskills) {
11176 sv_catpvn(PL_thisstuff, d + 1, s - d);
11178 PL_thisstuff = newSVpvn(d + 1, s - d);
11179 stuffstart = s - SvPVX(PL_linestr);
11183 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11185 sv_catpvn(herewas,s,PL_bufend-s);
11186 sv_setsv(PL_linestr,herewas);
11187 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11188 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11189 PL_last_lop = PL_last_uni = NULL;
11192 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11193 while (s >= PL_bufend) { /* multiple line string? */
11195 if (PL_madskills) {
11196 tstart = SvPVX(PL_linestr) + stuffstart;
11198 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11200 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11204 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11205 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11206 missingterm(PL_tokenbuf);
11209 stuffstart = s - SvPVX(PL_linestr);
11211 CopLINE_inc(PL_curcop);
11212 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11213 PL_last_lop = PL_last_uni = NULL;
11214 #ifndef PERL_STRICT_CR
11215 if (PL_bufend - PL_linestart >= 2) {
11216 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11217 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11219 PL_bufend[-2] = '\n';
11221 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11223 else if (PL_bufend[-1] == '\r')
11224 PL_bufend[-1] = '\n';
11226 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11227 PL_bufend[-1] = '\n';
11229 if (PERLDB_LINE && PL_curstash != PL_debstash)
11230 update_debugger_info_sv(PL_linestr);
11231 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11232 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11233 *(SvPVX(PL_linestr) + off ) = ' ';
11234 sv_catsv(PL_linestr,herewas);
11235 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11236 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11240 sv_catsv(tmpstr,PL_linestr);
11245 PL_multi_end = CopLINE(PL_curcop);
11246 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11247 SvPV_shrink_to_cur(tmpstr);
11249 SvREFCNT_dec(herewas);
11251 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11253 else if (PL_encoding)
11254 sv_recode_to_utf8(tmpstr, PL_encoding);
11256 PL_lex_stuff = tmpstr;
11257 yylval.ival = op_type;
11261 /* scan_inputsymbol
11262 takes: current position in input buffer
11263 returns: new position in input buffer
11264 side-effects: yylval and lex_op are set.
11269 <FH> read from filehandle
11270 <pkg::FH> read from package qualified filehandle
11271 <pkg'FH> read from package qualified filehandle
11272 <$fh> read from filehandle in $fh
11273 <*.h> filename glob
11278 S_scan_inputsymbol(pTHX_ char *start)
11281 register char *s = start; /* current position in buffer */
11285 char *d = PL_tokenbuf; /* start of temp holding space */
11286 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11288 end = strchr(s, '\n');
11291 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11293 /* die if we didn't have space for the contents of the <>,
11294 or if it didn't end, or if we see a newline
11297 if (len >= (I32)sizeof PL_tokenbuf)
11298 Perl_croak(aTHX_ "Excessively long <> operator");
11300 Perl_croak(aTHX_ "Unterminated <> operator");
11305 Remember, only scalar variables are interpreted as filehandles by
11306 this code. Anything more complex (e.g., <$fh{$num}>) will be
11307 treated as a glob() call.
11308 This code makes use of the fact that except for the $ at the front,
11309 a scalar variable and a filehandle look the same.
11311 if (*d == '$' && d[1]) d++;
11313 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11314 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11317 /* If we've tried to read what we allow filehandles to look like, and
11318 there's still text left, then it must be a glob() and not a getline.
11319 Use scan_str to pull out the stuff between the <> and treat it
11320 as nothing more than a string.
11323 if (d - PL_tokenbuf != len) {
11324 yylval.ival = OP_GLOB;
11326 s = scan_str(start,!!PL_madskills,FALSE);
11328 Perl_croak(aTHX_ "Glob not terminated");
11332 bool readline_overriden = FALSE;
11335 /* we're in a filehandle read situation */
11338 /* turn <> into <ARGV> */
11340 Copy("ARGV",d,5,char);
11342 /* Check whether readline() is overriden */
11343 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11345 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11347 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11348 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
11349 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11350 readline_overriden = TRUE;
11352 /* if <$fh>, create the ops to turn the variable into a
11356 /* try to find it in the pad for this block, otherwise find
11357 add symbol table ops
11359 const PADOFFSET tmp = pad_findmy(d);
11360 if (tmp != NOT_IN_PAD) {
11361 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11362 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11363 HEK * const stashname = HvNAME_HEK(stash);
11364 SV * const sym = sv_2mortal(newSVhek(stashname));
11365 sv_catpvs(sym, "::");
11366 sv_catpv(sym, d+1);
11371 OP * const o = newOP(OP_PADSV, 0);
11373 PL_lex_op = readline_overriden
11374 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11375 append_elem(OP_LIST, o,
11376 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11377 : (OP*)newUNOP(OP_READLINE, 0, o);
11386 ? (GV_ADDMULTI | GV_ADDINEVAL)
11389 PL_lex_op = readline_overriden
11390 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11391 append_elem(OP_LIST,
11392 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11393 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11394 : (OP*)newUNOP(OP_READLINE, 0,
11395 newUNOP(OP_RV2SV, 0,
11396 newGVOP(OP_GV, 0, gv)));
11398 if (!readline_overriden)
11399 PL_lex_op->op_flags |= OPf_SPECIAL;
11400 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11401 yylval.ival = OP_NULL;
11404 /* If it's none of the above, it must be a literal filehandle
11405 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11407 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11408 PL_lex_op = readline_overriden
11409 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11410 append_elem(OP_LIST,
11411 newGVOP(OP_GV, 0, gv),
11412 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11413 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11414 yylval.ival = OP_NULL;
11423 takes: start position in buffer
11424 keep_quoted preserve \ on the embedded delimiter(s)
11425 keep_delims preserve the delimiters around the string
11426 returns: position to continue reading from buffer
11427 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11428 updates the read buffer.
11430 This subroutine pulls a string out of the input. It is called for:
11431 q single quotes q(literal text)
11432 ' single quotes 'literal text'
11433 qq double quotes qq(interpolate $here please)
11434 " double quotes "interpolate $here please"
11435 qx backticks qx(/bin/ls -l)
11436 ` backticks `/bin/ls -l`
11437 qw quote words @EXPORT_OK = qw( func() $spam )
11438 m// regexp match m/this/
11439 s/// regexp substitute s/this/that/
11440 tr/// string transliterate tr/this/that/
11441 y/// string transliterate y/this/that/
11442 ($*@) sub prototypes sub foo ($)
11443 (stuff) sub attr parameters sub foo : attr(stuff)
11444 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11446 In most of these cases (all but <>, patterns and transliterate)
11447 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11448 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11449 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11452 It skips whitespace before the string starts, and treats the first
11453 character as the delimiter. If the delimiter is one of ([{< then
11454 the corresponding "close" character )]}> is used as the closing
11455 delimiter. It allows quoting of delimiters, and if the string has
11456 balanced delimiters ([{<>}]) it allows nesting.
11458 On success, the SV with the resulting string is put into lex_stuff or,
11459 if that is already non-NULL, into lex_repl. The second case occurs only
11460 when parsing the RHS of the special constructs s/// and tr/// (y///).
11461 For convenience, the terminating delimiter character is stuffed into
11466 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11469 SV *sv; /* scalar value: string */
11470 const char *tmps; /* temp string, used for delimiter matching */
11471 register char *s = start; /* current position in the buffer */
11472 register char term; /* terminating character */
11473 register char *to; /* current position in the sv's data */
11474 I32 brackets = 1; /* bracket nesting level */
11475 bool has_utf8 = FALSE; /* is there any utf8 content? */
11476 I32 termcode; /* terminating char. code */
11477 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11478 STRLEN termlen; /* length of terminating string */
11479 int last_off = 0; /* last position for nesting bracket */
11485 /* skip space before the delimiter */
11491 if (PL_realtokenstart >= 0) {
11492 stuffstart = PL_realtokenstart;
11493 PL_realtokenstart = -1;
11496 stuffstart = start - SvPVX(PL_linestr);
11498 /* mark where we are, in case we need to report errors */
11501 /* after skipping whitespace, the next character is the terminator */
11504 termcode = termstr[0] = term;
11508 termcode = utf8_to_uvchr((U8*)s, &termlen);
11509 Copy(s, termstr, termlen, U8);
11510 if (!UTF8_IS_INVARIANT(term))
11514 /* mark where we are */
11515 PL_multi_start = CopLINE(PL_curcop);
11516 PL_multi_open = term;
11518 /* find corresponding closing delimiter */
11519 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11520 termcode = termstr[0] = term = tmps[5];
11522 PL_multi_close = term;
11524 /* create a new SV to hold the contents. 79 is the SV's initial length.
11525 What a random number. */
11527 sv_upgrade(sv, SVt_PVIV);
11528 SvIV_set(sv, termcode);
11529 (void)SvPOK_only(sv); /* validate pointer */
11531 /* move past delimiter and try to read a complete string */
11533 sv_catpvn(sv, s, termlen);
11536 tstart = SvPVX(PL_linestr) + stuffstart;
11537 if (!PL_thisopen && !keep_delims) {
11538 PL_thisopen = newSVpvn(tstart, s - tstart);
11539 stuffstart = s - SvPVX(PL_linestr);
11543 if (PL_encoding && !UTF) {
11547 int offset = s - SvPVX_const(PL_linestr);
11548 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11549 &offset, (char*)termstr, termlen);
11550 const char * const ns = SvPVX_const(PL_linestr) + offset;
11551 char * const svlast = SvEND(sv) - 1;
11553 for (; s < ns; s++) {
11554 if (*s == '\n' && !PL_rsfp)
11555 CopLINE_inc(PL_curcop);
11558 goto read_more_line;
11560 /* handle quoted delimiters */
11561 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11563 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11565 if ((svlast-1 - t) % 2) {
11566 if (!keep_quoted) {
11567 *(svlast-1) = term;
11569 SvCUR_set(sv, SvCUR(sv) - 1);
11574 if (PL_multi_open == PL_multi_close) {
11580 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
11581 /* At here, all closes are "was quoted" one,
11582 so we don't check PL_multi_close. */
11584 if (!keep_quoted && *(t+1) == PL_multi_open)
11589 else if (*t == PL_multi_open)
11597 SvCUR_set(sv, w - SvPVX_const(sv));
11599 last_off = w - SvPVX(sv);
11600 if (--brackets <= 0)
11605 if (!keep_delims) {
11606 SvCUR_set(sv, SvCUR(sv) - 1);
11612 /* extend sv if need be */
11613 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11614 /* set 'to' to the next character in the sv's string */
11615 to = SvPVX(sv)+SvCUR(sv);
11617 /* if open delimiter is the close delimiter read unbridle */
11618 if (PL_multi_open == PL_multi_close) {
11619 for (; s < PL_bufend; s++,to++) {
11620 /* embedded newlines increment the current line number */
11621 if (*s == '\n' && !PL_rsfp)
11622 CopLINE_inc(PL_curcop);
11623 /* handle quoted delimiters */
11624 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11625 if (!keep_quoted && s[1] == term)
11627 /* any other quotes are simply copied straight through */
11631 /* terminate when run out of buffer (the for() condition), or
11632 have found the terminator */
11633 else if (*s == term) {
11636 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11639 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11645 /* if the terminator isn't the same as the start character (e.g.,
11646 matched brackets), we have to allow more in the quoting, and
11647 be prepared for nested brackets.
11650 /* read until we run out of string, or we find the terminator */
11651 for (; s < PL_bufend; s++,to++) {
11652 /* embedded newlines increment the line count */
11653 if (*s == '\n' && !PL_rsfp)
11654 CopLINE_inc(PL_curcop);
11655 /* backslashes can escape the open or closing characters */
11656 if (*s == '\\' && s+1 < PL_bufend) {
11657 if (!keep_quoted &&
11658 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11663 /* allow nested opens and closes */
11664 else if (*s == PL_multi_close && --brackets <= 0)
11666 else if (*s == PL_multi_open)
11668 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11673 /* terminate the copied string and update the sv's end-of-string */
11675 SvCUR_set(sv, to - SvPVX_const(sv));
11678 * this next chunk reads more into the buffer if we're not done yet
11682 break; /* handle case where we are done yet :-) */
11684 #ifndef PERL_STRICT_CR
11685 if (to - SvPVX_const(sv) >= 2) {
11686 if ((to[-2] == '\r' && to[-1] == '\n') ||
11687 (to[-2] == '\n' && to[-1] == '\r'))
11691 SvCUR_set(sv, to - SvPVX_const(sv));
11693 else if (to[-1] == '\r')
11696 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11701 /* if we're out of file, or a read fails, bail and reset the current
11702 line marker so we can report where the unterminated string began
11705 if (PL_madskills) {
11706 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11708 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11710 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11714 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11716 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11722 /* we read a line, so increment our line counter */
11723 CopLINE_inc(PL_curcop);
11725 /* update debugger info */
11726 if (PERLDB_LINE && PL_curstash != PL_debstash)
11727 update_debugger_info_sv(PL_linestr);
11729 /* having changed the buffer, we must update PL_bufend */
11730 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11731 PL_last_lop = PL_last_uni = NULL;
11734 /* at this point, we have successfully read the delimited string */
11736 if (!PL_encoding || UTF) {
11738 if (PL_madskills) {
11739 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11740 const int len = s - tstart;
11742 sv_catpvn(PL_thisstuff, tstart, len);
11744 PL_thisstuff = newSVpvn(tstart, len);
11745 if (!PL_thisclose && !keep_delims)
11746 PL_thisclose = newSVpvn(s,termlen);
11751 sv_catpvn(sv, s, termlen);
11756 if (PL_madskills) {
11757 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11758 const int len = s - tstart - termlen;
11760 sv_catpvn(PL_thisstuff, tstart, len);
11762 PL_thisstuff = newSVpvn(tstart, len);
11763 if (!PL_thisclose && !keep_delims)
11764 PL_thisclose = newSVpvn(s - termlen,termlen);
11768 if (has_utf8 || PL_encoding)
11771 PL_multi_end = CopLINE(PL_curcop);
11773 /* if we allocated too much space, give some back */
11774 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11775 SvLEN_set(sv, SvCUR(sv) + 1);
11776 SvPV_renew(sv, SvLEN(sv));
11779 /* decide whether this is the first or second quoted string we've read
11792 takes: pointer to position in buffer
11793 returns: pointer to new position in buffer
11794 side-effects: builds ops for the constant in yylval.op
11796 Read a number in any of the formats that Perl accepts:
11798 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11799 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11802 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11804 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11807 If it reads a number without a decimal point or an exponent, it will
11808 try converting the number to an integer and see if it can do so
11809 without loss of precision.
11813 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11816 register const char *s = start; /* current position in buffer */
11817 register char *d; /* destination in temp buffer */
11818 register char *e; /* end of temp buffer */
11819 NV nv; /* number read, as a double */
11820 SV *sv = NULL; /* place to put the converted number */
11821 bool floatit; /* boolean: int or float? */
11822 const char *lastub = NULL; /* position of last underbar */
11823 static char const number_too_long[] = "Number too long";
11825 /* We use the first character to decide what type of number this is */
11829 Perl_croak(aTHX_ "panic: scan_num");
11831 /* if it starts with a 0, it could be an octal number, a decimal in
11832 0.13 disguise, or a hexadecimal number, or a binary number. */
11836 u holds the "number so far"
11837 shift the power of 2 of the base
11838 (hex == 4, octal == 3, binary == 1)
11839 overflowed was the number more than we can hold?
11841 Shift is used when we add a digit. It also serves as an "are
11842 we in octal/hex/binary?" indicator to disallow hex characters
11843 when in octal mode.
11848 bool overflowed = FALSE;
11849 bool just_zero = TRUE; /* just plain 0 or binary number? */
11850 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11851 static const char* const bases[5] =
11852 { "", "binary", "", "octal", "hexadecimal" };
11853 static const char* const Bases[5] =
11854 { "", "Binary", "", "Octal", "Hexadecimal" };
11855 static const char* const maxima[5] =
11857 "0b11111111111111111111111111111111",
11861 const char *base, *Base, *max;
11863 /* check for hex */
11868 } else if (s[1] == 'b') {
11873 /* check for a decimal in disguise */
11874 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11876 /* so it must be octal */
11883 if (ckWARN(WARN_SYNTAX))
11884 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11885 "Misplaced _ in number");
11889 base = bases[shift];
11890 Base = Bases[shift];
11891 max = maxima[shift];
11893 /* read the rest of the number */
11895 /* x is used in the overflow test,
11896 b is the digit we're adding on. */
11901 /* if we don't mention it, we're done */
11905 /* _ are ignored -- but warned about if consecutive */
11907 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11908 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11909 "Misplaced _ in number");
11913 /* 8 and 9 are not octal */
11914 case '8': case '9':
11916 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11920 case '2': case '3': case '4':
11921 case '5': case '6': case '7':
11923 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11926 case '0': case '1':
11927 b = *s++ & 15; /* ASCII digit -> value of digit */
11931 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11932 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11933 /* make sure they said 0x */
11936 b = (*s++ & 7) + 9;
11938 /* Prepare to put the digit we have onto the end
11939 of the number so far. We check for overflows.
11945 x = u << shift; /* make room for the digit */
11947 if ((x >> shift) != u
11948 && !(PL_hints & HINT_NEW_BINARY)) {
11951 if (ckWARN_d(WARN_OVERFLOW))
11952 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11953 "Integer overflow in %s number",
11956 u = x | b; /* add the digit to the end */
11959 n *= nvshift[shift];
11960 /* If an NV has not enough bits in its
11961 * mantissa to represent an UV this summing of
11962 * small low-order numbers is a waste of time
11963 * (because the NV cannot preserve the
11964 * low-order bits anyway): we could just
11965 * remember when did we overflow and in the
11966 * end just multiply n by the right
11974 /* if we get here, we had success: make a scalar value from
11979 /* final misplaced underbar check */
11980 if (s[-1] == '_') {
11981 if (ckWARN(WARN_SYNTAX))
11982 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11987 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
11988 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11989 "%s number > %s non-portable",
11995 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
11996 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11997 "%s number > %s non-portable",
12002 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
12003 sv = new_constant(start, s - start, "integer",
12005 else if (PL_hints & HINT_NEW_BINARY)
12006 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
12011 handle decimal numbers.
12012 we're also sent here when we read a 0 as the first digit
12014 case '1': case '2': case '3': case '4': case '5':
12015 case '6': case '7': case '8': case '9': case '.':
12018 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
12021 /* read next group of digits and _ and copy into d */
12022 while (isDIGIT(*s) || *s == '_') {
12023 /* skip underscores, checking for misplaced ones
12027 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12028 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12029 "Misplaced _ in number");
12033 /* check for end of fixed-length buffer */
12035 Perl_croak(aTHX_ number_too_long);
12036 /* if we're ok, copy the character */
12041 /* final misplaced underbar check */
12042 if (lastub && s == lastub + 1) {
12043 if (ckWARN(WARN_SYNTAX))
12044 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12047 /* read a decimal portion if there is one. avoid
12048 3..5 being interpreted as the number 3. followed
12051 if (*s == '.' && s[1] != '.') {
12056 if (ckWARN(WARN_SYNTAX))
12057 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12058 "Misplaced _ in number");
12062 /* copy, ignoring underbars, until we run out of digits.
12064 for (; isDIGIT(*s) || *s == '_'; s++) {
12065 /* fixed length buffer check */
12067 Perl_croak(aTHX_ number_too_long);
12069 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12070 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12071 "Misplaced _ in number");
12077 /* fractional part ending in underbar? */
12078 if (s[-1] == '_') {
12079 if (ckWARN(WARN_SYNTAX))
12080 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12081 "Misplaced _ in number");
12083 if (*s == '.' && isDIGIT(s[1])) {
12084 /* oops, it's really a v-string, but without the "v" */
12090 /* read exponent part, if present */
12091 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12095 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12096 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12098 /* stray preinitial _ */
12100 if (ckWARN(WARN_SYNTAX))
12101 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12102 "Misplaced _ in number");
12106 /* allow positive or negative exponent */
12107 if (*s == '+' || *s == '-')
12110 /* stray initial _ */
12112 if (ckWARN(WARN_SYNTAX))
12113 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12114 "Misplaced _ in number");
12118 /* read digits of exponent */
12119 while (isDIGIT(*s) || *s == '_') {
12122 Perl_croak(aTHX_ number_too_long);
12126 if (((lastub && s == lastub + 1) ||
12127 (!isDIGIT(s[1]) && s[1] != '_'))
12128 && ckWARN(WARN_SYNTAX))
12129 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12130 "Misplaced _ in number");
12137 /* make an sv from the string */
12141 We try to do an integer conversion first if no characters
12142 indicating "float" have been found.
12147 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12149 if (flags == IS_NUMBER_IN_UV) {
12151 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12154 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12155 if (uv <= (UV) IV_MIN)
12156 sv_setiv(sv, -(IV)uv);
12163 /* terminate the string */
12165 nv = Atof(PL_tokenbuf);
12169 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12170 (PL_hints & HINT_NEW_INTEGER) )
12171 sv = new_constant(PL_tokenbuf,
12174 (floatit ? "float" : "integer"),
12178 /* if it starts with a v, it could be a v-string */
12181 sv = newSV(5); /* preallocate storage space */
12182 s = scan_vstring(s,sv);
12186 /* make the op for the constant and return */
12189 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12191 lvalp->opval = NULL;
12197 S_scan_formline(pTHX_ register char *s)
12200 register char *eol;
12202 SV * const stuff = newSVpvs("");
12203 bool needargs = FALSE;
12204 bool eofmt = FALSE;
12206 char *tokenstart = s;
12209 if (PL_madskills) {
12210 savewhite = PL_thiswhite;
12215 while (!needargs) {
12218 #ifdef PERL_STRICT_CR
12219 while (SPACE_OR_TAB(*t))
12222 while (SPACE_OR_TAB(*t) || *t == '\r')
12225 if (*t == '\n' || t == PL_bufend) {
12230 if (PL_in_eval && !PL_rsfp) {
12231 eol = (char *) memchr(s,'\n',PL_bufend-s);
12236 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12238 for (t = s; t < eol; t++) {
12239 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12241 goto enough; /* ~~ must be first line in formline */
12243 if (*t == '@' || *t == '^')
12247 sv_catpvn(stuff, s, eol-s);
12248 #ifndef PERL_STRICT_CR
12249 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12250 char *end = SvPVX(stuff) + SvCUR(stuff);
12253 SvCUR_set(stuff, SvCUR(stuff) - 1);
12263 if (PL_madskills) {
12265 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12267 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12270 s = filter_gets(PL_linestr, PL_rsfp, 0);
12272 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12274 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12276 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12277 PL_last_lop = PL_last_uni = NULL;
12286 if (SvCUR(stuff)) {
12289 PL_lex_state = LEX_NORMAL;
12290 start_force(PL_curforce);
12291 NEXTVAL_NEXTTOKE.ival = 0;
12295 PL_lex_state = LEX_FORMLINE;
12297 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12299 else if (PL_encoding)
12300 sv_recode_to_utf8(stuff, PL_encoding);
12302 start_force(PL_curforce);
12303 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12305 start_force(PL_curforce);
12306 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12310 SvREFCNT_dec(stuff);
12312 PL_lex_formbrack = 0;
12316 if (PL_madskills) {
12318 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12320 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12321 PL_thiswhite = savewhite;
12333 PL_cshlen = strlen(PL_cshname);
12335 #if defined(USE_ITHREADS)
12336 PERL_UNUSED_CONTEXT;
12342 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12345 const I32 oldsavestack_ix = PL_savestack_ix;
12346 CV* const outsidecv = PL_compcv;
12349 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12351 SAVEI32(PL_subline);
12352 save_item(PL_subname);
12353 SAVESPTR(PL_compcv);
12355 PL_compcv = (CV*)newSV(0);
12356 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12357 CvFLAGS(PL_compcv) |= flags;
12359 PL_subline = CopLINE(PL_curcop);
12360 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12361 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12362 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12364 return oldsavestack_ix;
12368 #pragma segment Perl_yylex
12371 Perl_yywarn(pTHX_ const char *s)
12374 PL_in_eval |= EVAL_WARNONLY;
12376 PL_in_eval &= ~EVAL_WARNONLY;
12381 Perl_yyerror(pTHX_ const char *s)
12384 const char *where = NULL;
12385 const char *context = NULL;
12388 int yychar = PL_parser->yychar;
12390 if (!yychar || (yychar == ';' && !PL_rsfp))
12392 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12393 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12394 PL_oldbufptr != PL_bufptr) {
12397 The code below is removed for NetWare because it abends/crashes on NetWare
12398 when the script has error such as not having the closing quotes like:
12399 if ($var eq "value)
12400 Checking of white spaces is anyway done in NetWare code.
12403 while (isSPACE(*PL_oldoldbufptr))
12406 context = PL_oldoldbufptr;
12407 contlen = PL_bufptr - PL_oldoldbufptr;
12409 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12410 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12413 The code below is removed for NetWare because it abends/crashes on NetWare
12414 when the script has error such as not having the closing quotes like:
12415 if ($var eq "value)
12416 Checking of white spaces is anyway done in NetWare code.
12419 while (isSPACE(*PL_oldbufptr))
12422 context = PL_oldbufptr;
12423 contlen = PL_bufptr - PL_oldbufptr;
12425 else if (yychar > 255)
12426 where = "next token ???";
12427 else if (yychar == -2) { /* YYEMPTY */
12428 if (PL_lex_state == LEX_NORMAL ||
12429 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12430 where = "at end of line";
12431 else if (PL_lex_inpat)
12432 where = "within pattern";
12434 where = "within string";
12437 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12439 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12440 else if (isPRINT_LC(yychar))
12441 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12443 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12444 where = SvPVX_const(where_sv);
12446 msg = sv_2mortal(newSVpv(s, 0));
12447 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12448 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12450 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12452 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12453 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12454 Perl_sv_catpvf(aTHX_ msg,
12455 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12456 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12459 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12460 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, (void*)msg);
12463 if (PL_error_count >= 10) {
12464 if (PL_in_eval && SvCUR(ERRSV))
12465 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12466 (void*)ERRSV, OutCopFILE(PL_curcop));
12468 Perl_croak(aTHX_ "%s has too many errors.\n",
12469 OutCopFILE(PL_curcop));
12472 PL_in_my_stash = NULL;
12476 #pragma segment Main
12480 S_swallow_bom(pTHX_ U8 *s)
12483 const STRLEN slen = SvCUR(PL_linestr);
12486 if (s[1] == 0xFE) {
12487 /* UTF-16 little-endian? (or UTF32-LE?) */
12488 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12489 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12490 #ifndef PERL_NO_UTF16_FILTER
12491 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12494 if (PL_bufend > (char*)s) {
12498 filter_add(utf16rev_textfilter, NULL);
12499 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12500 utf16_to_utf8_reversed(s, news,
12501 PL_bufend - (char*)s - 1,
12503 sv_setpvn(PL_linestr, (const char*)news, newlen);
12505 s = (U8*)SvPVX(PL_linestr);
12506 Copy(news, s, newlen, U8);
12510 SvUTF8_on(PL_linestr);
12511 s = (U8*)SvPVX(PL_linestr);
12513 /* FIXME - is this a general bug fix? */
12516 PL_bufend = SvPVX(PL_linestr) + newlen;
12519 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12524 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12525 #ifndef PERL_NO_UTF16_FILTER
12526 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12529 if (PL_bufend > (char *)s) {
12533 filter_add(utf16_textfilter, NULL);
12534 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12535 utf16_to_utf8(s, news,
12536 PL_bufend - (char*)s,
12538 sv_setpvn(PL_linestr, (const char*)news, newlen);
12540 SvUTF8_on(PL_linestr);
12541 s = (U8*)SvPVX(PL_linestr);
12542 PL_bufend = SvPVX(PL_linestr) + newlen;
12545 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12550 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12551 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12552 s += 3; /* UTF-8 */
12558 if (s[2] == 0xFE && s[3] == 0xFF) {
12559 /* UTF-32 big-endian */
12560 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12563 else if (s[2] == 0 && s[3] != 0) {
12566 * are a good indicator of UTF-16BE. */
12567 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12573 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12574 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12575 s += 4; /* UTF-8 */
12581 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12584 * are a good indicator of UTF-16LE. */
12585 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12594 * Restore a source filter.
12598 restore_rsfp(pTHX_ void *f)
12601 PerlIO * const fp = (PerlIO*)f;
12603 if (PL_rsfp == PerlIO_stdin())
12604 PerlIO_clearerr(PL_rsfp);
12605 else if (PL_rsfp && (PL_rsfp != fp))
12606 PerlIO_close(PL_rsfp);
12610 #ifndef PERL_NO_UTF16_FILTER
12612 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12615 const STRLEN old = SvCUR(sv);
12616 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12617 DEBUG_P(PerlIO_printf(Perl_debug_log,
12618 "utf16_textfilter(%p): %d %d (%d)\n",
12619 FPTR2DPTR(void *, utf16_textfilter),
12620 idx, maxlen, (int) count));
12624 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12625 Copy(SvPVX_const(sv), tmps, old, char);
12626 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12627 SvCUR(sv) - old, &newlen);
12628 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12630 DEBUG_P({sv_dump(sv);});
12635 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12638 const STRLEN old = SvCUR(sv);
12639 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12640 DEBUG_P(PerlIO_printf(Perl_debug_log,
12641 "utf16rev_textfilter(%p): %d %d (%d)\n",
12642 FPTR2DPTR(void *, utf16rev_textfilter),
12643 idx, maxlen, (int) count));
12647 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12648 Copy(SvPVX_const(sv), tmps, old, char);
12649 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12650 SvCUR(sv) - old, &newlen);
12651 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12653 DEBUG_P({ sv_dump(sv); });
12659 Returns a pointer to the next character after the parsed
12660 vstring, as well as updating the passed in sv.
12662 Function must be called like
12665 s = scan_vstring(s,sv);
12667 The sv should already be large enough to store the vstring
12668 passed in, for performance reasons.
12673 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12676 const char *pos = s;
12677 const char *start = s;
12678 if (*pos == 'v') pos++; /* get past 'v' */
12679 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12681 if ( *pos != '.') {
12682 /* this may not be a v-string if followed by => */
12683 const char *next = pos;
12684 while (next < PL_bufend && isSPACE(*next))
12686 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12687 /* return string not v-string */
12688 sv_setpvn(sv,(char *)s,pos-s);
12689 return (char *)pos;
12693 if (!isALPHA(*pos)) {
12694 U8 tmpbuf[UTF8_MAXBYTES+1];
12697 s++; /* get past 'v' */
12699 sv_setpvn(sv, "", 0);
12702 /* this is atoi() that tolerates underscores */
12705 const char *end = pos;
12707 while (--end >= s) {
12709 const UV orev = rev;
12710 rev += (*end - '0') * mult;
12712 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12713 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12714 "Integer overflow in decimal number");
12718 if (rev > 0x7FFFFFFF)
12719 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12721 /* Append native character for the rev point */
12722 tmpend = uvchr_to_utf8(tmpbuf, rev);
12723 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12724 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12726 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12732 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12736 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12744 * c-indentation-style: bsd
12745 * c-basic-offset: 4
12746 * indent-tabs-mode: t
12749 * ex: set ts=8 sts=4 sw=4 noet: