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;
664 s = SvPV_const(line, len);
669 PL_linestr = newSVpvs("\n;");
670 } else if (SvREADONLY(line) || s[len-1] != ';') {
671 PL_linestr = newSVsv(line);
673 sv_catpvs(PL_linestr, "\n;");
676 SvREFCNT_inc_simple_void_NN(line);
679 /* PL_linestr needs to survive until end of scope, not just the next
680 FREETMPS. See changes 17505 and 17546 which fixed the symptoms only. */
681 SAVEFREESV(PL_linestr);
682 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
683 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
684 PL_last_lop = PL_last_uni = NULL;
690 * Finalizer for lexing operations. Must be called when the parser is
691 * done with the lexer.
698 PL_doextract = FALSE;
703 * This subroutine has nothing to do with tilting, whether at windmills
704 * or pinball tables. Its name is short for "increment line". It
705 * increments the current line number in CopLINE(PL_curcop) and checks
706 * to see whether the line starts with a comment of the form
707 * # line 500 "foo.pm"
708 * If so, it sets the current line number and file to the values in the comment.
712 S_incline(pTHX_ char *s)
720 CopLINE_inc(PL_curcop);
723 while (SPACE_OR_TAB(*s))
725 if (strnEQ(s, "line", 4))
729 if (SPACE_OR_TAB(*s))
733 while (SPACE_OR_TAB(*s))
741 while (SPACE_OR_TAB(*s))
743 if (*s == '"' && (t = strchr(s+1, '"'))) {
753 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
755 if (*e != '\n' && *e != '\0')
756 return; /* false alarm */
762 const char * const cf = CopFILE(PL_curcop);
763 STRLEN tmplen = cf ? strlen(cf) : 0;
764 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
765 /* must copy *{"::_<(eval N)[oldfilename:L]"}
766 * to *{"::_<newfilename"} */
767 char smallbuf[256], smallbuf2[256];
768 char *tmpbuf, *tmpbuf2;
770 STRLEN tmplen2 = strlen(s);
771 if (tmplen + 3 < sizeof smallbuf)
774 Newx(tmpbuf, tmplen + 3, char);
775 if (tmplen2 + 3 < sizeof smallbuf2)
778 Newx(tmpbuf2, tmplen2 + 3, char);
779 tmpbuf[0] = tmpbuf2[0] = '_';
780 tmpbuf[1] = tmpbuf2[1] = '<';
781 memcpy(tmpbuf + 2, cf, ++tmplen);
782 memcpy(tmpbuf2 + 2, s, ++tmplen2);
784 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
786 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
788 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
789 /* adjust ${"::_<newfilename"} to store the new file name */
790 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
791 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
792 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
795 if (tmpbuf != smallbuf) Safefree(tmpbuf);
796 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
799 CopFILE_free(PL_curcop);
800 CopFILE_set(PL_curcop, s);
803 CopLINE_set(PL_curcop, atoi(n)-1);
807 /* skip space before PL_thistoken */
810 S_skipspace0(pTHX_ register char *s)
817 PL_thiswhite = newSVpvs("");
818 sv_catsv(PL_thiswhite, PL_skipwhite);
819 sv_free(PL_skipwhite);
822 PL_realtokenstart = s - SvPVX(PL_linestr);
826 /* skip space after PL_thistoken */
829 S_skipspace1(pTHX_ register char *s)
831 const char *start = s;
832 I32 startoff = start - SvPVX(PL_linestr);
837 start = SvPVX(PL_linestr) + startoff;
838 if (!PL_thistoken && PL_realtokenstart >= 0) {
839 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
840 PL_thistoken = newSVpvn(tstart, start - tstart);
842 PL_realtokenstart = -1;
845 PL_nextwhite = newSVpvs("");
846 sv_catsv(PL_nextwhite, PL_skipwhite);
847 sv_free(PL_skipwhite);
854 S_skipspace2(pTHX_ register char *s, SV **svp)
857 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
858 const I32 startoff = s - SvPVX(PL_linestr);
861 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
862 if (!PL_madskills || !svp)
864 start = SvPVX(PL_linestr) + startoff;
865 if (!PL_thistoken && PL_realtokenstart >= 0) {
866 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
867 PL_thistoken = newSVpvn(tstart, start - tstart);
868 PL_realtokenstart = -1;
873 sv_setsv(*svp, PL_skipwhite);
874 sv_free(PL_skipwhite);
883 S_update_debugger_info_pv(pTHX_ const char *buf, STRLEN len)
885 AV *av = CopFILEAVx(PL_curcop);
887 SV * const sv = newSV(0);
888 sv_upgrade(sv, SVt_PVMG);
889 sv_setpvn(sv, buf, len);
892 av_store(av, (I32)CopLINE(PL_curcop), sv);
897 S_update_debugger_info_sv(pTHX_ SV *orig_sv)
899 AV *av = CopFILEAVx(PL_curcop);
901 SV * const sv = newSV(0);
902 sv_upgrade(sv, SVt_PVMG);
903 sv_setsv(sv, orig_sv);
906 av_store(av, (I32)CopLINE(PL_curcop), sv);
912 * Called to gobble the appropriate amount and type of whitespace.
913 * Skips comments as well.
917 S_skipspace(pTHX_ register char *s)
922 int startoff = s - SvPVX(PL_linestr);
925 sv_free(PL_skipwhite);
930 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
931 while (s < PL_bufend && SPACE_OR_TAB(*s))
941 SSize_t oldprevlen, oldoldprevlen;
942 SSize_t oldloplen = 0, oldunilen = 0;
943 while (s < PL_bufend && isSPACE(*s)) {
944 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
949 if (s < PL_bufend && *s == '#') {
950 while (s < PL_bufend && *s != '\n')
954 if (PL_in_eval && !PL_rsfp) {
961 /* only continue to recharge the buffer if we're at the end
962 * of the buffer, we're not reading from a source filter, and
963 * we're in normal lexing mode
965 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
966 PL_lex_state == LEX_FORMLINE)
973 /* try to recharge the buffer */
975 curoff = s - SvPVX(PL_linestr);
978 if ((s = filter_gets(PL_linestr, PL_rsfp,
979 (prevlen = SvCUR(PL_linestr)))) == NULL)
982 if (PL_madskills && curoff != startoff) {
984 PL_skipwhite = newSVpvs("");
985 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
989 /* mustn't throw out old stuff yet if madpropping */
990 SvCUR(PL_linestr) = curoff;
991 s = SvPVX(PL_linestr) + curoff;
993 if (curoff && s[-1] == '\n')
997 /* end of file. Add on the -p or -n magic */
998 /* XXX these shouldn't really be added here, can't set PL_faketokens */
1001 sv_catpv(PL_linestr,
1002 ";}continue{print or die qq(-p destination: $!\\n);}");
1004 sv_setpv(PL_linestr,
1005 ";}continue{print or die qq(-p destination: $!\\n);}");
1007 PL_minus_n = PL_minus_p = 0;
1009 else if (PL_minus_n) {
1011 sv_catpvn(PL_linestr, ";}", 2);
1013 sv_setpvn(PL_linestr, ";}", 2);
1019 sv_catpvn(PL_linestr,";", 1);
1021 sv_setpvn(PL_linestr,";", 1);
1024 /* reset variables for next time we lex */
1025 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
1031 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1032 PL_last_lop = PL_last_uni = NULL;
1034 /* Close the filehandle. Could be from -P preprocessor,
1035 * STDIN, or a regular file. If we were reading code from
1036 * STDIN (because the commandline held no -e or filename)
1037 * then we don't close it, we reset it so the code can
1038 * read from STDIN too.
1041 if (PL_preprocess && !PL_in_eval)
1042 (void)PerlProc_pclose(PL_rsfp);
1043 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1044 PerlIO_clearerr(PL_rsfp);
1046 (void)PerlIO_close(PL_rsfp);
1051 /* not at end of file, so we only read another line */
1052 /* make corresponding updates to old pointers, for yyerror() */
1053 oldprevlen = PL_oldbufptr - PL_bufend;
1054 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1056 oldunilen = PL_last_uni - PL_bufend;
1058 oldloplen = PL_last_lop - PL_bufend;
1059 PL_linestart = PL_bufptr = s + prevlen;
1060 PL_bufend = s + SvCUR(PL_linestr);
1062 PL_oldbufptr = s + oldprevlen;
1063 PL_oldoldbufptr = s + oldoldprevlen;
1065 PL_last_uni = s + oldunilen;
1067 PL_last_lop = s + oldloplen;
1070 /* debugger active and we're not compiling the debugger code,
1071 * so store the line into the debugger's array of lines
1073 if (PERLDB_LINE && PL_curstash != PL_debstash)
1074 update_debugger_info_pv(PL_bufptr, PL_bufend - PL_bufptr);
1081 PL_skipwhite = newSVpvs("");
1082 curoff = s - SvPVX(PL_linestr);
1083 if (curoff - startoff)
1084 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1093 * Check the unary operators to ensure there's no ambiguity in how they're
1094 * used. An ambiguous piece of code would be:
1096 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1097 * the +5 is its argument.
1107 if (PL_oldoldbufptr != PL_last_uni)
1109 while (isSPACE(*PL_last_uni))
1112 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1114 if ((t = strchr(s, '(')) && t < PL_bufptr)
1117 if (ckWARN_d(WARN_AMBIGUOUS)){
1118 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1119 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1120 (int)(s - PL_last_uni), PL_last_uni);
1125 * LOP : macro to build a list operator. Its behaviour has been replaced
1126 * with a subroutine, S_lop() for which LOP is just another name.
1129 #define LOP(f,x) return lop(f,x,s)
1133 * Build a list operator (or something that might be one). The rules:
1134 * - if we have a next token, then it's a list operator [why?]
1135 * - if the next thing is an opening paren, then it's a function
1136 * - else it's a list operator
1140 S_lop(pTHX_ I32 f, int x, char *s)
1147 PL_last_lop = PL_oldbufptr;
1148 PL_last_lop_op = (OPCODE)f;
1151 return REPORT(LSTOP);
1154 return REPORT(LSTOP);
1157 return REPORT(FUNC);
1160 return REPORT(FUNC);
1162 return REPORT(LSTOP);
1168 * Sets up for an eventual force_next(). start_force(0) basically does
1169 * an unshift, while start_force(-1) does a push. yylex removes items
1174 S_start_force(pTHX_ int where)
1178 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1179 where = PL_lasttoke;
1180 assert(PL_curforce < 0 || PL_curforce == where);
1181 if (PL_curforce != where) {
1182 for (i = PL_lasttoke; i > where; --i) {
1183 PL_nexttoke[i] = PL_nexttoke[i-1];
1187 if (PL_curforce < 0) /* in case of duplicate start_force() */
1188 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1189 PL_curforce = where;
1192 curmad('^', newSVpvs(""));
1193 CURMAD('_', PL_nextwhite);
1198 S_curmad(pTHX_ char slot, SV *sv)
1204 if (PL_curforce < 0)
1205 where = &PL_thismad;
1207 where = &PL_nexttoke[PL_curforce].next_mad;
1210 sv_setpvn(sv, "", 0);
1213 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1215 else if (PL_encoding) {
1216 sv_recode_to_utf8(sv, PL_encoding);
1221 /* keep a slot open for the head of the list? */
1222 if (slot != '_' && *where && (*where)->mad_key == '^') {
1223 (*where)->mad_key = slot;
1224 sv_free((*where)->mad_val);
1225 (*where)->mad_val = (void*)sv;
1228 addmad(newMADsv(slot, sv), where, 0);
1231 # define start_force(where) NOOP
1232 # define curmad(slot, sv) NOOP
1237 * When the lexer realizes it knows the next token (for instance,
1238 * it is reordering tokens for the parser) then it can call S_force_next
1239 * to know what token to return the next time the lexer is called. Caller
1240 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1241 * and possibly PL_expect to ensure the lexer handles the token correctly.
1245 S_force_next(pTHX_ I32 type)
1249 if (PL_curforce < 0)
1250 start_force(PL_lasttoke);
1251 PL_nexttoke[PL_curforce].next_type = type;
1252 if (PL_lex_state != LEX_KNOWNEXT)
1253 PL_lex_defer = PL_lex_state;
1254 PL_lex_state = LEX_KNOWNEXT;
1255 PL_lex_expect = PL_expect;
1258 PL_nexttype[PL_nexttoke] = type;
1260 if (PL_lex_state != LEX_KNOWNEXT) {
1261 PL_lex_defer = PL_lex_state;
1262 PL_lex_expect = PL_expect;
1263 PL_lex_state = LEX_KNOWNEXT;
1269 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1272 SV * const sv = newSVpvn(start,len);
1273 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1280 * When the lexer knows the next thing is a word (for instance, it has
1281 * just seen -> and it knows that the next char is a word char, then
1282 * it calls S_force_word to stick the next word into the PL_next lookahead.
1285 * char *start : buffer position (must be within PL_linestr)
1286 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
1287 * int check_keyword : if true, Perl checks to make sure the word isn't
1288 * a keyword (do this if the word is a label, e.g. goto FOO)
1289 * int allow_pack : if true, : characters will also be allowed (require,
1290 * use, etc. do this)
1291 * int allow_initial_tick : used by the "sub" lexer only.
1295 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1301 start = SKIPSPACE1(start);
1303 if (isIDFIRST_lazy_if(s,UTF) ||
1304 (allow_pack && *s == ':') ||
1305 (allow_initial_tick && *s == '\'') )
1307 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1308 if (check_keyword && keyword(PL_tokenbuf, len, 0))
1310 start_force(PL_curforce);
1312 curmad('X', newSVpvn(start,s-start));
1313 if (token == METHOD) {
1318 PL_expect = XOPERATOR;
1321 NEXTVAL_NEXTTOKE.opval
1322 = (OP*)newSVOP(OP_CONST,0,
1323 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1324 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1332 * Called when the lexer wants $foo *foo &foo etc, but the program
1333 * text only contains the "foo" portion. The first argument is a pointer
1334 * to the "foo", and the second argument is the type symbol to prefix.
1335 * Forces the next token to be a "WORD".
1336 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1340 S_force_ident(pTHX_ register const char *s, int kind)
1344 const STRLEN len = strlen(s);
1345 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1346 start_force(PL_curforce);
1347 NEXTVAL_NEXTTOKE.opval = o;
1350 o->op_private = OPpCONST_ENTERED;
1351 /* XXX see note in pp_entereval() for why we forgo typo
1352 warnings if the symbol must be introduced in an eval.
1354 gv_fetchpvn_flags(s, len,
1355 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1357 kind == '$' ? SVt_PV :
1358 kind == '@' ? SVt_PVAV :
1359 kind == '%' ? SVt_PVHV :
1367 Perl_str_to_version(pTHX_ SV *sv)
1372 const char *start = SvPV_const(sv,len);
1373 const char * const end = start + len;
1374 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1375 while (start < end) {
1379 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1384 retval += ((NV)n)/nshift;
1393 * Forces the next token to be a version number.
1394 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1395 * and if "guessing" is TRUE, then no new token is created (and the caller
1396 * must use an alternative parsing method).
1400 S_force_version(pTHX_ char *s, int guessing)
1406 I32 startoff = s - SvPVX(PL_linestr);
1415 while (isDIGIT(*d) || *d == '_' || *d == '.')
1419 start_force(PL_curforce);
1420 curmad('X', newSVpvn(s,d-s));
1423 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1425 s = scan_num(s, &yylval);
1426 version = yylval.opval;
1427 ver = cSVOPx(version)->op_sv;
1428 if (SvPOK(ver) && !SvNIOK(ver)) {
1429 SvUPGRADE(ver, SVt_PVNV);
1430 SvNV_set(ver, str_to_version(ver));
1431 SvNOK_on(ver); /* hint that it is a version */
1434 else if (guessing) {
1437 sv_free(PL_nextwhite); /* let next token collect whitespace */
1439 s = SvPVX(PL_linestr) + startoff;
1447 if (PL_madskills && !version) {
1448 sv_free(PL_nextwhite); /* let next token collect whitespace */
1450 s = SvPVX(PL_linestr) + startoff;
1453 /* NOTE: The parser sees the package name and the VERSION swapped */
1454 start_force(PL_curforce);
1455 NEXTVAL_NEXTTOKE.opval = version;
1463 * Tokenize a quoted string passed in as an SV. It finds the next
1464 * chunk, up to end of string or a backslash. It may make a new
1465 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1470 S_tokeq(pTHX_ SV *sv)
1474 register char *send;
1482 s = SvPV_force(sv, len);
1483 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1486 while (s < send && *s != '\\')
1491 if ( PL_hints & HINT_NEW_STRING ) {
1492 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1498 if (s + 1 < send && (s[1] == '\\'))
1499 s++; /* all that, just for this */
1504 SvCUR_set(sv, d - SvPVX_const(sv));
1506 if ( PL_hints & HINT_NEW_STRING )
1507 return new_constant(NULL, 0, "q", sv, pv, "q");
1512 * Now come three functions related to double-quote context,
1513 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1514 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1515 * interact with PL_lex_state, and create fake ( ... ) argument lists
1516 * to handle functions and concatenation.
1517 * They assume that whoever calls them will be setting up a fake
1518 * join call, because each subthing puts a ',' after it. This lets
1521 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1523 * (I'm not sure whether the spurious commas at the end of lcfirst's
1524 * arguments and join's arguments are created or not).
1529 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1531 * Pattern matching will set PL_lex_op to the pattern-matching op to
1532 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1534 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1536 * Everything else becomes a FUNC.
1538 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1539 * had an OP_CONST or OP_READLINE). This just sets us up for a
1540 * call to S_sublex_push().
1544 S_sublex_start(pTHX)
1547 register const I32 op_type = yylval.ival;
1549 if (op_type == OP_NULL) {
1550 yylval.opval = PL_lex_op;
1554 if (op_type == OP_CONST || op_type == OP_READLINE) {
1555 SV *sv = tokeq(PL_lex_stuff);
1557 if (SvTYPE(sv) == SVt_PVIV) {
1558 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1560 const char * const p = SvPV_const(sv, len);
1561 SV * const nsv = newSVpvn(p, len);
1567 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1568 PL_lex_stuff = NULL;
1569 /* Allow <FH> // "foo" */
1570 if (op_type == OP_READLINE)
1571 PL_expect = XTERMORDORDOR;
1574 else if (op_type == OP_BACKTICK && PL_lex_op) {
1575 /* readpipe() vas overriden */
1576 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1577 yylval.opval = PL_lex_op;
1579 PL_lex_stuff = NULL;
1583 PL_sublex_info.super_state = PL_lex_state;
1584 PL_sublex_info.sub_inwhat = op_type;
1585 PL_sublex_info.sub_op = PL_lex_op;
1586 PL_lex_state = LEX_INTERPPUSH;
1590 yylval.opval = PL_lex_op;
1600 * Create a new scope to save the lexing state. The scope will be
1601 * ended in S_sublex_done. Returns a '(', starting the function arguments
1602 * to the uc, lc, etc. found before.
1603 * Sets PL_lex_state to LEX_INTERPCONCAT.
1612 PL_lex_state = PL_sublex_info.super_state;
1613 SAVEI32(PL_lex_dojoin);
1614 SAVEI32(PL_lex_brackets);
1615 SAVEI32(PL_lex_casemods);
1616 SAVEI32(PL_lex_starts);
1617 SAVEI32(PL_lex_state);
1618 SAVEVPTR(PL_lex_inpat);
1619 SAVEI32(PL_lex_inwhat);
1620 SAVECOPLINE(PL_curcop);
1621 SAVEPPTR(PL_bufptr);
1622 SAVEPPTR(PL_bufend);
1623 SAVEPPTR(PL_oldbufptr);
1624 SAVEPPTR(PL_oldoldbufptr);
1625 SAVEPPTR(PL_last_lop);
1626 SAVEPPTR(PL_last_uni);
1627 SAVEPPTR(PL_linestart);
1628 SAVESPTR(PL_linestr);
1629 SAVEGENERICPV(PL_lex_brackstack);
1630 SAVEGENERICPV(PL_lex_casestack);
1632 PL_linestr = PL_lex_stuff;
1633 PL_lex_stuff = NULL;
1635 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1636 = SvPVX(PL_linestr);
1637 PL_bufend += SvCUR(PL_linestr);
1638 PL_last_lop = PL_last_uni = NULL;
1639 SAVEFREESV(PL_linestr);
1641 PL_lex_dojoin = FALSE;
1642 PL_lex_brackets = 0;
1643 Newx(PL_lex_brackstack, 120, char);
1644 Newx(PL_lex_casestack, 12, char);
1645 PL_lex_casemods = 0;
1646 *PL_lex_casestack = '\0';
1648 PL_lex_state = LEX_INTERPCONCAT;
1649 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1651 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1652 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1653 PL_lex_inpat = PL_sublex_info.sub_op;
1655 PL_lex_inpat = NULL;
1662 * Restores lexer state after a S_sublex_push.
1669 if (!PL_lex_starts++) {
1670 SV * const sv = newSVpvs("");
1671 if (SvUTF8(PL_linestr))
1673 PL_expect = XOPERATOR;
1674 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1678 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1679 PL_lex_state = LEX_INTERPCASEMOD;
1683 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1684 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1685 PL_linestr = PL_lex_repl;
1687 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1688 PL_bufend += SvCUR(PL_linestr);
1689 PL_last_lop = PL_last_uni = NULL;
1690 SAVEFREESV(PL_linestr);
1691 PL_lex_dojoin = FALSE;
1692 PL_lex_brackets = 0;
1693 PL_lex_casemods = 0;
1694 *PL_lex_casestack = '\0';
1696 if (SvEVALED(PL_lex_repl)) {
1697 PL_lex_state = LEX_INTERPNORMAL;
1699 /* we don't clear PL_lex_repl here, so that we can check later
1700 whether this is an evalled subst; that means we rely on the
1701 logic to ensure sublex_done() is called again only via the
1702 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1705 PL_lex_state = LEX_INTERPCONCAT;
1715 PL_endwhite = newSVpvs("");
1716 sv_catsv(PL_endwhite, PL_thiswhite);
1720 sv_setpvn(PL_thistoken,"",0);
1722 PL_realtokenstart = -1;
1726 PL_bufend = SvPVX(PL_linestr);
1727 PL_bufend += SvCUR(PL_linestr);
1728 PL_expect = XOPERATOR;
1729 PL_sublex_info.sub_inwhat = 0;
1737 Extracts a pattern, double-quoted string, or transliteration. This
1740 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
1741 processing a pattern (PL_lex_inpat is true), a transliteration
1742 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
1744 Returns a pointer to the character scanned up to. If this is
1745 advanced from the start pointer supplied (i.e. if anything was
1746 successfully parsed), will leave an OP for the substring scanned
1747 in yylval. Caller must intuit reason for not parsing further
1748 by looking at the next characters herself.
1752 double-quoted style: \r and \n
1753 regexp special ones: \D \s
1756 case and quoting: \U \Q \E
1757 stops on @ and $, but not for $ as tail anchor
1759 In transliterations:
1760 characters are VERY literal, except for - not at the start or end
1761 of the string, which indicates a range. If the range is in bytes,
1762 scan_const expands the range to the full set of intermediate
1763 characters. If the range is in utf8, the hyphen is replaced with
1764 a certain range mark which will be handled by pmtrans() in op.c.
1766 In double-quoted strings:
1768 double-quoted style: \r and \n
1770 deprecated backrefs: \1 (in substitution replacements)
1771 case and quoting: \U \Q \E
1774 scan_const does *not* construct ops to handle interpolated strings.
1775 It stops processing as soon as it finds an embedded $ or @ variable
1776 and leaves it to the caller to work out what's going on.
1778 embedded arrays (whether in pattern or not) could be:
1779 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1781 $ in double-quoted strings must be the symbol of an embedded scalar.
1783 $ in pattern could be $foo or could be tail anchor. Assumption:
1784 it's a tail anchor if $ is the last thing in the string, or if it's
1785 followed by one of "()| \r\n\t"
1787 \1 (backreferences) are turned into $1
1789 The structure of the code is
1790 while (there's a character to process) {
1791 handle transliteration ranges
1792 skip regexp comments /(?#comment)/ and codes /(?{code})/
1793 skip #-initiated comments in //x patterns
1794 check for embedded arrays
1795 check for embedded scalars
1797 leave intact backslashes from leaveit (below)
1798 deprecate \1 in substitution replacements
1799 handle string-changing backslashes \l \U \Q \E, etc.
1800 switch (what was escaped) {
1801 handle \- in a transliteration (becomes a literal -)
1802 handle \132 (octal characters)
1803 handle \x15 and \x{1234} (hex characters)
1804 handle \N{name} (named characters)
1805 handle \cV (control characters)
1806 handle printf-style backslashes (\f, \r, \n, etc)
1808 } (end if backslash)
1809 } (end while character to read)
1814 S_scan_const(pTHX_ char *start)
1817 register char *send = PL_bufend; /* end of the constant */
1818 SV *sv = newSV(send - start); /* sv for the constant */
1819 register char *s = start; /* start of the constant */
1820 register char *d = SvPVX(sv); /* destination for copies */
1821 bool dorange = FALSE; /* are we in a translit range? */
1822 bool didrange = FALSE; /* did we just finish a range? */
1823 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1824 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1827 UV literal_endpoint = 0;
1828 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
1831 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1832 /* If we are doing a trans and we know we want UTF8 set expectation */
1833 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1834 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1838 while (s < send || dorange) {
1839 /* get transliterations out of the way (they're most literal) */
1840 if (PL_lex_inwhat == OP_TRANS) {
1841 /* expand a range A-Z to the full set of characters. AIE! */
1843 I32 i; /* current expanded character */
1844 I32 min; /* first character in range */
1845 I32 max; /* last character in range */
1856 char * const c = (char*)utf8_hop((U8*)d, -1);
1860 *c = (char)UTF_TO_NATIVE(0xff);
1861 /* mark the range as done, and continue */
1867 i = d - SvPVX_const(sv); /* remember current offset */
1870 SvLEN(sv) + (has_utf8 ?
1871 (512 - UTF_CONTINUATION_MARK +
1874 /* How many two-byte within 0..255: 128 in UTF-8,
1875 * 96 in UTF-8-mod. */
1877 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1879 d = SvPVX(sv) + i; /* refresh d after realloc */
1883 for (j = 0; j <= 1; j++) {
1884 char * const c = (char*)utf8_hop((U8*)d, -1);
1885 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
1891 max = (U8)0xff; /* only to \xff */
1892 uvmax = uv; /* \x{100} to uvmax */
1894 d = c; /* eat endpoint chars */
1899 d -= 2; /* eat the first char and the - */
1900 min = (U8)*d; /* first char in range */
1901 max = (U8)d[1]; /* last char in range */
1908 "Invalid range \"%c-%c\" in transliteration operator",
1909 (char)min, (char)max);
1913 if (literal_endpoint == 2 &&
1914 ((isLOWER(min) && isLOWER(max)) ||
1915 (isUPPER(min) && isUPPER(max)))) {
1917 for (i = min; i <= max; i++)
1919 *d++ = NATIVE_TO_NEED(has_utf8,i);
1921 for (i = min; i <= max; i++)
1923 *d++ = NATIVE_TO_NEED(has_utf8,i);
1928 for (i = min; i <= max; i++)
1931 const U8 ch = (U8)NATIVE_TO_UTF(i);
1932 if (UNI_IS_INVARIANT(ch))
1935 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
1936 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
1945 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
1947 *d++ = (char)UTF_TO_NATIVE(0xff);
1949 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
1953 /* mark the range as done, and continue */
1957 literal_endpoint = 0;
1962 /* range begins (ignore - as first or last char) */
1963 else if (*s == '-' && s+1 < send && s != start) {
1965 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1972 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1982 literal_endpoint = 0;
1983 native_range = TRUE;
1988 /* if we get here, we're not doing a transliteration */
1990 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1991 except for the last char, which will be done separately. */
1992 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1994 while (s+1 < send && *s != ')')
1995 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1997 else if (s[2] == '{' /* This should match regcomp.c */
1998 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
2001 char *regparse = s + (s[2] == '{' ? 3 : 4);
2004 while (count && (c = *regparse)) {
2005 if (c == '\\' && regparse[1])
2013 if (*regparse != ')')
2014 regparse--; /* Leave one char for continuation. */
2015 while (s < regparse)
2016 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2020 /* likewise skip #-initiated comments in //x patterns */
2021 else if (*s == '#' && PL_lex_inpat &&
2022 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2023 while (s+1 < send && *s != '\n')
2024 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2027 /* check for embedded arrays
2028 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2030 else if (*s == '@' && s[1]) {
2031 if (isALNUM_lazy_if(s+1,UTF))
2033 if (strchr(":'{$", s[1]))
2035 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2036 break; /* in regexp, neither @+ nor @- are interpolated */
2039 /* check for embedded scalars. only stop if we're sure it's a
2042 else if (*s == '$') {
2043 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
2045 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
2046 break; /* in regexp, $ might be tail anchor */
2049 /* End of else if chain - OP_TRANS rejoin rest */
2052 if (*s == '\\' && s+1 < send) {
2055 /* deprecate \1 in strings and substitution replacements */
2056 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2057 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2059 if (ckWARN(WARN_SYNTAX))
2060 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2065 /* string-change backslash escapes */
2066 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2070 /* skip any other backslash escapes in a pattern */
2071 else if (PL_lex_inpat) {
2072 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2073 goto default_action;
2076 /* if we get here, it's either a quoted -, or a digit */
2079 /* quoted - in transliterations */
2081 if (PL_lex_inwhat == OP_TRANS) {
2088 if ((isALPHA(*s) || isDIGIT(*s)) &&
2090 Perl_warner(aTHX_ packWARN(WARN_MISC),
2091 "Unrecognized escape \\%c passed through",
2093 /* default action is to copy the quoted character */
2094 goto default_action;
2097 /* \132 indicates an octal constant */
2098 case '0': case '1': case '2': case '3':
2099 case '4': case '5': case '6': case '7':
2103 uv = grok_oct(s, &len, &flags, NULL);
2106 goto NUM_ESCAPE_INSERT;
2108 /* \x24 indicates a hex constant */
2112 char* const e = strchr(s, '}');
2113 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2114 PERL_SCAN_DISALLOW_PREFIX;
2119 yyerror("Missing right brace on \\x{}");
2123 uv = grok_hex(s, &len, &flags, NULL);
2129 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2130 uv = grok_hex(s, &len, &flags, NULL);
2136 /* Insert oct or hex escaped character.
2137 * There will always enough room in sv since such
2138 * escapes will be longer than any UTF-8 sequence
2139 * they can end up as. */
2141 /* We need to map to chars to ASCII before doing the tests
2144 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2145 if (!has_utf8 && uv > 255) {
2146 /* Might need to recode whatever we have
2147 * accumulated so far if it contains any
2150 * (Can't we keep track of that and avoid
2151 * this rescan? --jhi)
2155 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2156 if (!NATIVE_IS_INVARIANT(*c)) {
2161 const STRLEN offset = d - SvPVX_const(sv);
2163 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2167 while (src >= (const U8 *)SvPVX_const(sv)) {
2168 if (!NATIVE_IS_INVARIANT(*src)) {
2169 const U8 ch = NATIVE_TO_ASCII(*src);
2170 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2171 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2181 if (has_utf8 || uv > 255) {
2182 d = (char*)uvchr_to_utf8((U8*)d, uv);
2184 if (PL_lex_inwhat == OP_TRANS &&
2185 PL_sublex_info.sub_op) {
2186 PL_sublex_info.sub_op->op_private |=
2187 (PL_lex_repl ? OPpTRANS_FROM_UTF
2191 if (uv > 255 && !dorange)
2192 native_range = FALSE;
2204 /* \N{LATIN SMALL LETTER A} is a named character */
2208 char* e = strchr(s, '}');
2215 yyerror("Missing right brace on \\N{}");
2219 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2221 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2222 PERL_SCAN_DISALLOW_PREFIX;
2225 uv = grok_hex(s, &len, &flags, NULL);
2226 if ( e > s && len != (STRLEN)(e - s) ) {
2230 goto NUM_ESCAPE_INSERT;
2232 res = newSVpvn(s + 1, e - s - 1);
2233 type = newSVpvn(s - 2,e - s + 3);
2234 res = new_constant( NULL, 0, "charnames",
2235 res, NULL, SvPVX(type) );
2238 sv_utf8_upgrade(res);
2239 str = SvPV_const(res,len);
2240 #ifdef EBCDIC_NEVER_MIND
2241 /* charnames uses pack U and that has been
2242 * recently changed to do the below uni->native
2243 * mapping, so this would be redundant (and wrong,
2244 * the code point would be doubly converted).
2245 * But leave this in just in case the pack U change
2246 * gets revoked, but the semantics is still
2247 * desireable for charnames. --jhi */
2249 UV uv = utf8_to_uvchr((const U8*)str, 0);
2252 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2254 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2255 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2256 str = SvPV_const(res, len);
2260 if (!has_utf8 && SvUTF8(res)) {
2261 const char * const ostart = SvPVX_const(sv);
2262 SvCUR_set(sv, d - ostart);
2265 sv_utf8_upgrade(sv);
2266 /* this just broke our allocation above... */
2267 SvGROW(sv, (STRLEN)(send - start));
2268 d = SvPVX(sv) + SvCUR(sv);
2271 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2272 const char * const odest = SvPVX_const(sv);
2274 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2275 d = SvPVX(sv) + (d - odest);
2279 native_range = FALSE; /* \N{} is guessed to be Unicode */
2281 Copy(str, d, len, char);
2288 yyerror("Missing braces on \\N{}");
2291 /* \c is a control character */
2300 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2303 yyerror("Missing control char name in \\c");
2307 /* printf-style backslashes, formfeeds, newlines, etc */
2309 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2312 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2315 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2318 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2321 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2324 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2327 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2333 } /* end if (backslash) */
2340 /* If we started with encoded form, or already know we want it
2341 and then encode the next character */
2342 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2344 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2345 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2348 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2349 const STRLEN off = d - SvPVX_const(sv);
2350 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2352 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2355 if (uv > 255 && !dorange)
2356 native_range = FALSE;
2360 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2362 } /* while loop to process each character */
2364 /* terminate the string and set up the sv */
2366 SvCUR_set(sv, d - SvPVX_const(sv));
2367 if (SvCUR(sv) >= SvLEN(sv))
2368 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2371 if (PL_encoding && !has_utf8) {
2372 sv_recode_to_utf8(sv, PL_encoding);
2378 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2379 PL_sublex_info.sub_op->op_private |=
2380 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2384 /* shrink the sv if we allocated more than we used */
2385 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2386 SvPV_shrink_to_cur(sv);
2389 /* return the substring (via yylval) only if we parsed anything */
2390 if (s > PL_bufptr) {
2391 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2392 sv = new_constant(start, s - start,
2393 (const char *)(PL_lex_inpat ? "qr" : "q"),
2396 (( PL_lex_inwhat == OP_TRANS
2398 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2401 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2408 * Returns TRUE if there's more to the expression (e.g., a subscript),
2411 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2413 * ->[ and ->{ return TRUE
2414 * { and [ outside a pattern are always subscripts, so return TRUE
2415 * if we're outside a pattern and it's not { or [, then return FALSE
2416 * if we're in a pattern and the first char is a {
2417 * {4,5} (any digits around the comma) returns FALSE
2418 * if we're in a pattern and the first char is a [
2420 * [SOMETHING] has a funky algorithm to decide whether it's a
2421 * character class or not. It has to deal with things like
2422 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2423 * anything else returns TRUE
2426 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2429 S_intuit_more(pTHX_ register char *s)
2432 if (PL_lex_brackets)
2434 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2436 if (*s != '{' && *s != '[')
2441 /* In a pattern, so maybe we have {n,m}. */
2458 /* On the other hand, maybe we have a character class */
2461 if (*s == ']' || *s == '^')
2464 /* this is terrifying, and it works */
2465 int weight = 2; /* let's weigh the evidence */
2467 unsigned char un_char = 255, last_un_char;
2468 const char * const send = strchr(s,']');
2469 char tmpbuf[sizeof PL_tokenbuf * 4];
2471 if (!send) /* has to be an expression */
2474 Zero(seen,256,char);
2477 else if (isDIGIT(*s)) {
2479 if (isDIGIT(s[1]) && s[2] == ']')
2485 for (; s < send; s++) {
2486 last_un_char = un_char;
2487 un_char = (unsigned char)*s;
2492 weight -= seen[un_char] * 10;
2493 if (isALNUM_lazy_if(s+1,UTF)) {
2495 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2496 len = (int)strlen(tmpbuf);
2497 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2502 else if (*s == '$' && s[1] &&
2503 strchr("[#!%*<>()-=",s[1])) {
2504 if (/*{*/ strchr("])} =",s[2]))
2513 if (strchr("wds]",s[1]))
2515 else if (seen[(U8)'\''] || seen[(U8)'"'])
2517 else if (strchr("rnftbxcav",s[1]))
2519 else if (isDIGIT(s[1])) {
2521 while (s[1] && isDIGIT(s[1]))
2531 if (strchr("aA01! ",last_un_char))
2533 if (strchr("zZ79~",s[1]))
2535 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2536 weight -= 5; /* cope with negative subscript */
2539 if (!isALNUM(last_un_char)
2540 && !(last_un_char == '$' || last_un_char == '@'
2541 || last_un_char == '&')
2542 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2547 if (keyword(tmpbuf, d - tmpbuf, 0))
2550 if (un_char == last_un_char + 1)
2552 weight -= seen[un_char];
2557 if (weight >= 0) /* probably a character class */
2567 * Does all the checking to disambiguate
2569 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2570 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2572 * First argument is the stuff after the first token, e.g. "bar".
2574 * Not a method if bar is a filehandle.
2575 * Not a method if foo is a subroutine prototyped to take a filehandle.
2576 * Not a method if it's really "Foo $bar"
2577 * Method if it's "foo $bar"
2578 * Not a method if it's really "print foo $bar"
2579 * Method if it's really "foo package::" (interpreted as package->foo)
2580 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2581 * Not a method if bar is a filehandle or package, but is quoted with
2586 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2589 char *s = start + (*start == '$');
2590 char tmpbuf[sizeof PL_tokenbuf];
2598 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2602 const char *proto = SvPVX_const(cv);
2613 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2614 /* start is the beginning of the possible filehandle/object,
2615 * and s is the end of it
2616 * tmpbuf is a copy of it
2619 if (*start == '$') {
2620 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2623 len = start - SvPVX(PL_linestr);
2627 start = SvPVX(PL_linestr) + len;
2631 return *s == '(' ? FUNCMETH : METHOD;
2633 if (!keyword(tmpbuf, len, 0)) {
2634 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2638 soff = s - SvPVX(PL_linestr);
2642 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2643 if (indirgv && GvCVu(indirgv))
2645 /* filehandle or package name makes it a method */
2646 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2648 soff = s - SvPVX(PL_linestr);
2651 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2652 return 0; /* no assumptions -- "=>" quotes bearword */
2654 start_force(PL_curforce);
2655 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2656 newSVpvn(tmpbuf,len));
2657 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2659 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2664 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2666 return *s == '(' ? FUNCMETH : METHOD;
2674 * Return a string of Perl code to load the debugger. If PERL5DB
2675 * is set, it will return the contents of that, otherwise a
2676 * compile-time require of perl5db.pl.
2684 const char * const pdb = PerlEnv_getenv("PERL5DB");
2688 SETERRNO(0,SS_NORMAL);
2689 return "BEGIN { require 'perl5db.pl' }";
2695 /* Encoded script support. filter_add() effectively inserts a
2696 * 'pre-processing' function into the current source input stream.
2697 * Note that the filter function only applies to the current source file
2698 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2700 * The datasv parameter (which may be NULL) can be used to pass
2701 * private data to this instance of the filter. The filter function
2702 * can recover the SV using the FILTER_DATA macro and use it to
2703 * store private buffers and state information.
2705 * The supplied datasv parameter is upgraded to a PVIO type
2706 * and the IoDIRP/IoANY field is used to store the function pointer,
2707 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2708 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2709 * private use must be set using malloc'd pointers.
2713 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2719 if (!PL_rsfp_filters)
2720 PL_rsfp_filters = newAV();
2723 SvUPGRADE(datasv, SVt_PVIO);
2724 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2725 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2726 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2727 FPTR2DPTR(void *, IoANY(datasv)),
2728 SvPV_nolen(datasv)));
2729 av_unshift(PL_rsfp_filters, 1);
2730 av_store(PL_rsfp_filters, 0, datasv) ;
2735 /* Delete most recently added instance of this filter function. */
2737 Perl_filter_del(pTHX_ filter_t funcp)
2743 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2744 FPTR2DPTR(void*, funcp)));
2746 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2748 /* if filter is on top of stack (usual case) just pop it off */
2749 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2750 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2751 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2752 IoANY(datasv) = (void *)NULL;
2753 sv_free(av_pop(PL_rsfp_filters));
2757 /* we need to search for the correct entry and clear it */
2758 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2762 /* Invoke the idxth filter function for the current rsfp. */
2763 /* maxlen 0 = read one text line */
2765 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2770 /* This API is bad. It should have been using unsigned int for maxlen.
2771 Not sure if we want to change the API, but if not we should sanity
2772 check the value here. */
2773 const unsigned int correct_length
2782 if (!PL_rsfp_filters)
2784 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2785 /* Provide a default input filter to make life easy. */
2786 /* Note that we append to the line. This is handy. */
2787 DEBUG_P(PerlIO_printf(Perl_debug_log,
2788 "filter_read %d: from rsfp\n", idx));
2789 if (correct_length) {
2792 const int old_len = SvCUR(buf_sv);
2794 /* ensure buf_sv is large enough */
2795 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2796 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2797 correct_length)) <= 0) {
2798 if (PerlIO_error(PL_rsfp))
2799 return -1; /* error */
2801 return 0 ; /* end of file */
2803 SvCUR_set(buf_sv, old_len + len) ;
2806 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2807 if (PerlIO_error(PL_rsfp))
2808 return -1; /* error */
2810 return 0 ; /* end of file */
2813 return SvCUR(buf_sv);
2815 /* Skip this filter slot if filter has been deleted */
2816 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2817 DEBUG_P(PerlIO_printf(Perl_debug_log,
2818 "filter_read %d: skipped (filter deleted)\n",
2820 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2822 /* Get function pointer hidden within datasv */
2823 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2824 DEBUG_P(PerlIO_printf(Perl_debug_log,
2825 "filter_read %d: via function %p (%s)\n",
2826 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2827 /* Call function. The function is expected to */
2828 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2829 /* Return: <0:error, =0:eof, >0:not eof */
2830 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2834 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2837 #ifdef PERL_CR_FILTER
2838 if (!PL_rsfp_filters) {
2839 filter_add(S_cr_textfilter,NULL);
2842 if (PL_rsfp_filters) {
2844 SvCUR_set(sv, 0); /* start with empty line */
2845 if (FILTER_READ(0, sv, 0) > 0)
2846 return ( SvPVX(sv) ) ;
2851 return (sv_gets(sv, fp, append));
2855 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2860 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2864 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2865 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2867 return GvHV(gv); /* Foo:: */
2870 /* use constant CLASS => 'MyClass' */
2871 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2872 if (gv && GvCV(gv)) {
2873 SV * const sv = cv_const_sv(GvCV(gv));
2875 pkgname = SvPV_nolen_const(sv);
2878 return gv_stashpv(pkgname, FALSE);
2882 * S_readpipe_override
2883 * Check whether readpipe() is overriden, and generates the appropriate
2884 * optree, provided sublex_start() is called afterwards.
2887 S_readpipe_override(pTHX)
2890 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
2891 yylval.ival = OP_BACKTICK;
2893 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
2895 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
2896 && (gv_readpipe = *gvp) != (GV*)&PL_sv_undef
2897 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
2899 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
2900 append_elem(OP_LIST,
2901 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
2902 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
2912 * The intent of this yylex wrapper is to minimize the changes to the
2913 * tokener when we aren't interested in collecting madprops. It remains
2914 * to be seen how successful this strategy will be...
2921 char *s = PL_bufptr;
2923 /* make sure PL_thiswhite is initialized */
2927 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2928 if (PL_pending_ident)
2929 return S_pending_ident(aTHX);
2931 /* previous token ate up our whitespace? */
2932 if (!PL_lasttoke && PL_nextwhite) {
2933 PL_thiswhite = PL_nextwhite;
2937 /* isolate the token, and figure out where it is without whitespace */
2938 PL_realtokenstart = -1;
2942 assert(PL_curforce < 0);
2944 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2945 if (!PL_thistoken) {
2946 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2947 PL_thistoken = newSVpvs("");
2949 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2950 PL_thistoken = newSVpvn(tstart, s - tstart);
2953 if (PL_thismad) /* install head */
2954 CURMAD('X', PL_thistoken);
2957 /* last whitespace of a sublex? */
2958 if (optype == ')' && PL_endwhite) {
2959 CURMAD('X', PL_endwhite);
2964 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
2965 if (!PL_thiswhite && !PL_endwhite && !optype) {
2966 sv_free(PL_thistoken);
2971 /* put off final whitespace till peg */
2972 if (optype == ';' && !PL_rsfp) {
2973 PL_nextwhite = PL_thiswhite;
2976 else if (PL_thisopen) {
2977 CURMAD('q', PL_thisopen);
2979 sv_free(PL_thistoken);
2983 /* Store actual token text as madprop X */
2984 CURMAD('X', PL_thistoken);
2988 /* add preceding whitespace as madprop _ */
2989 CURMAD('_', PL_thiswhite);
2993 /* add quoted material as madprop = */
2994 CURMAD('=', PL_thisstuff);
2998 /* add terminating quote as madprop Q */
2999 CURMAD('Q', PL_thisclose);
3003 /* special processing based on optype */
3007 /* opval doesn't need a TOKEN since it can already store mp */
3018 append_madprops(PL_thismad, yylval.opval, 0);
3026 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3035 /* remember any fake bracket that lexer is about to discard */
3036 if (PL_lex_brackets == 1 &&
3037 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3040 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3043 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3044 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3047 break; /* don't bother looking for trailing comment */
3056 /* attach a trailing comment to its statement instead of next token */
3060 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3062 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3064 if (*s == '\n' || *s == '#') {
3065 while (s < PL_bufend && *s != '\n')
3069 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3070 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3087 /* Create new token struct. Note: opvals return early above. */
3088 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
3095 S_tokenize_use(pTHX_ int is_use, char *s) {
3097 if (PL_expect != XSTATE)
3098 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3099 is_use ? "use" : "no"));
3101 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3102 s = force_version(s, TRUE);
3103 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3104 start_force(PL_curforce);
3105 NEXTVAL_NEXTTOKE.opval = NULL;
3108 else if (*s == 'v') {
3109 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3110 s = force_version(s, FALSE);
3114 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3115 s = force_version(s, FALSE);
3117 yylval.ival = is_use;
3121 static const char* const exp_name[] =
3122 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3123 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3130 Works out what to call the token just pulled out of the input
3131 stream. The yacc parser takes care of taking the ops we return and
3132 stitching them into a tree.
3138 if read an identifier
3139 if we're in a my declaration
3140 croak if they tried to say my($foo::bar)
3141 build the ops for a my() declaration
3142 if it's an access to a my() variable
3143 are we in a sort block?
3144 croak if my($a); $a <=> $b
3145 build ops for access to a my() variable
3146 if in a dq string, and they've said @foo and we can't find @foo
3148 build ops for a bareword
3149 if we already built the token before, use it.
3154 #pragma segment Perl_yylex
3160 register char *s = PL_bufptr;
3165 /* orig_keyword, gvp, and gv are initialized here because
3166 * jump to the label just_a_word_zero can bypass their
3167 * initialization later. */
3168 I32 orig_keyword = 0;
3173 SV* tmp = newSVpvs("");
3174 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3175 (IV)CopLINE(PL_curcop),
3176 lex_state_names[PL_lex_state],
3177 exp_name[PL_expect],
3178 pv_display(tmp, s, strlen(s), 0, 60));
3181 /* check if there's an identifier for us to look at */
3182 if (PL_pending_ident)
3183 return REPORT(S_pending_ident(aTHX));
3185 /* no identifier pending identification */
3187 switch (PL_lex_state) {
3189 case LEX_NORMAL: /* Some compilers will produce faster */
3190 case LEX_INTERPNORMAL: /* code if we comment these out. */
3194 /* when we've already built the next token, just pull it out of the queue */
3198 yylval = PL_nexttoke[PL_lasttoke].next_val;
3200 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3201 PL_nexttoke[PL_lasttoke].next_mad = 0;
3202 if (PL_thismad && PL_thismad->mad_key == '_') {
3203 PL_thiswhite = (SV*)PL_thismad->mad_val;
3204 PL_thismad->mad_val = 0;
3205 mad_free(PL_thismad);
3210 PL_lex_state = PL_lex_defer;
3211 PL_expect = PL_lex_expect;
3212 PL_lex_defer = LEX_NORMAL;
3213 if (!PL_nexttoke[PL_lasttoke].next_type)
3218 yylval = PL_nextval[PL_nexttoke];
3220 PL_lex_state = PL_lex_defer;
3221 PL_expect = PL_lex_expect;
3222 PL_lex_defer = LEX_NORMAL;
3226 /* FIXME - can these be merged? */
3227 return(PL_nexttoke[PL_lasttoke].next_type);
3229 return REPORT(PL_nexttype[PL_nexttoke]);
3232 /* interpolated case modifiers like \L \U, including \Q and \E.
3233 when we get here, PL_bufptr is at the \
3235 case LEX_INTERPCASEMOD:
3237 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3238 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3240 /* handle \E or end of string */
3241 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3243 if (PL_lex_casemods) {
3244 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3245 PL_lex_casestack[PL_lex_casemods] = '\0';
3247 if (PL_bufptr != PL_bufend
3248 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3250 PL_lex_state = LEX_INTERPCONCAT;
3253 PL_thistoken = newSVpvs("\\E");
3259 while (PL_bufptr != PL_bufend &&
3260 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3262 PL_thiswhite = newSVpvs("");
3263 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3267 if (PL_bufptr != PL_bufend)
3270 PL_lex_state = LEX_INTERPCONCAT;
3274 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3275 "### Saw case modifier\n"); });
3277 if (s[1] == '\\' && s[2] == 'E') {
3280 PL_thiswhite = newSVpvs("");
3281 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3284 PL_lex_state = LEX_INTERPCONCAT;
3289 if (!PL_madskills) /* when just compiling don't need correct */
3290 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3291 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3292 if ((*s == 'L' || *s == 'U') &&
3293 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3294 PL_lex_casestack[--PL_lex_casemods] = '\0';
3297 if (PL_lex_casemods > 10)
3298 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3299 PL_lex_casestack[PL_lex_casemods++] = *s;
3300 PL_lex_casestack[PL_lex_casemods] = '\0';
3301 PL_lex_state = LEX_INTERPCONCAT;
3302 start_force(PL_curforce);
3303 NEXTVAL_NEXTTOKE.ival = 0;
3305 start_force(PL_curforce);
3307 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3309 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3311 NEXTVAL_NEXTTOKE.ival = OP_LC;
3313 NEXTVAL_NEXTTOKE.ival = OP_UC;
3315 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3317 Perl_croak(aTHX_ "panic: yylex");
3319 SV* const tmpsv = newSVpvs("");
3320 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3326 if (PL_lex_starts) {
3332 sv_free(PL_thistoken);
3333 PL_thistoken = newSVpvs("");
3336 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3337 if (PL_lex_casemods == 1 && PL_lex_inpat)
3346 case LEX_INTERPPUSH:
3347 return REPORT(sublex_push());
3349 case LEX_INTERPSTART:
3350 if (PL_bufptr == PL_bufend)
3351 return REPORT(sublex_done());
3352 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3353 "### Interpolated variable\n"); });
3355 PL_lex_dojoin = (*PL_bufptr == '@');
3356 PL_lex_state = LEX_INTERPNORMAL;
3357 if (PL_lex_dojoin) {
3358 start_force(PL_curforce);
3359 NEXTVAL_NEXTTOKE.ival = 0;
3361 start_force(PL_curforce);
3362 force_ident("\"", '$');
3363 start_force(PL_curforce);
3364 NEXTVAL_NEXTTOKE.ival = 0;
3366 start_force(PL_curforce);
3367 NEXTVAL_NEXTTOKE.ival = 0;
3369 start_force(PL_curforce);
3370 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3373 if (PL_lex_starts++) {
3378 sv_free(PL_thistoken);
3379 PL_thistoken = newSVpvs("");
3382 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3383 if (!PL_lex_casemods && PL_lex_inpat)
3390 case LEX_INTERPENDMAYBE:
3391 if (intuit_more(PL_bufptr)) {
3392 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3398 if (PL_lex_dojoin) {
3399 PL_lex_dojoin = FALSE;
3400 PL_lex_state = LEX_INTERPCONCAT;
3404 sv_free(PL_thistoken);
3405 PL_thistoken = newSVpvs("");
3410 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3411 && SvEVALED(PL_lex_repl))
3413 if (PL_bufptr != PL_bufend)
3414 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3418 case LEX_INTERPCONCAT:
3420 if (PL_lex_brackets)
3421 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3423 if (PL_bufptr == PL_bufend)
3424 return REPORT(sublex_done());
3426 if (SvIVX(PL_linestr) == '\'') {
3427 SV *sv = newSVsv(PL_linestr);
3430 else if ( PL_hints & HINT_NEW_RE )
3431 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3432 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3436 s = scan_const(PL_bufptr);
3438 PL_lex_state = LEX_INTERPCASEMOD;
3440 PL_lex_state = LEX_INTERPSTART;
3443 if (s != PL_bufptr) {
3444 start_force(PL_curforce);
3446 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3448 NEXTVAL_NEXTTOKE = yylval;
3451 if (PL_lex_starts++) {
3455 sv_free(PL_thistoken);
3456 PL_thistoken = newSVpvs("");
3459 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3460 if (!PL_lex_casemods && PL_lex_inpat)
3473 PL_lex_state = LEX_NORMAL;
3474 s = scan_formline(PL_bufptr);
3475 if (!PL_lex_formbrack)
3481 PL_oldoldbufptr = PL_oldbufptr;
3487 sv_free(PL_thistoken);
3490 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3494 if (isIDFIRST_lazy_if(s,UTF))
3496 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3499 goto fake_eof; /* emulate EOF on ^D or ^Z */
3508 if (PL_lex_brackets) {
3509 yyerror((const char *)
3511 ? "Format not terminated"
3512 : "Missing right curly or square bracket"));
3514 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3515 "### Tokener got EOF\n");
3519 if (s++ < PL_bufend)
3520 goto retry; /* ignore stray nulls */
3523 if (!PL_in_eval && !PL_preambled) {
3524 PL_preambled = TRUE;
3529 sv_setpv(PL_linestr,incl_perldb());
3530 if (SvCUR(PL_linestr))
3531 sv_catpvs(PL_linestr,";");
3533 while(AvFILLp(PL_preambleav) >= 0) {
3534 SV *tmpsv = av_shift(PL_preambleav);
3535 sv_catsv(PL_linestr, tmpsv);
3536 sv_catpvs(PL_linestr, ";");
3539 sv_free((SV*)PL_preambleav);
3540 PL_preambleav = NULL;
3542 if (PL_minus_n || PL_minus_p) {
3543 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3545 sv_catpvs(PL_linestr,"chomp;");
3548 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3549 || *PL_splitstr == '"')
3550 && strchr(PL_splitstr + 1, *PL_splitstr))
3551 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3553 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3554 bytes can be used as quoting characters. :-) */
3555 const char *splits = PL_splitstr;
3556 sv_catpvs(PL_linestr, "our @F=split(q\0");
3559 if (*splits == '\\')
3560 sv_catpvn(PL_linestr, splits, 1);
3561 sv_catpvn(PL_linestr, splits, 1);
3562 } while (*splits++);
3563 /* This loop will embed the trailing NUL of
3564 PL_linestr as the last thing it does before
3566 sv_catpvs(PL_linestr, ");");
3570 sv_catpvs(PL_linestr,"our @F=split(' ');");
3574 sv_catpvs(PL_linestr,"use feature ':5.10';");
3575 sv_catpvs(PL_linestr, "\n");
3576 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3577 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3578 PL_last_lop = PL_last_uni = NULL;
3579 if (PERLDB_LINE && PL_curstash != PL_debstash)
3580 update_debugger_info_sv(PL_linestr);
3584 bof = PL_rsfp ? TRUE : FALSE;
3585 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3588 PL_realtokenstart = -1;
3591 if (PL_preprocess && !PL_in_eval)
3592 (void)PerlProc_pclose(PL_rsfp);
3593 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3594 PerlIO_clearerr(PL_rsfp);
3596 (void)PerlIO_close(PL_rsfp);
3598 PL_doextract = FALSE;
3600 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3605 sv_setpv(PL_linestr,
3608 ? ";}continue{print;}" : ";}"));
3609 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3610 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3611 PL_last_lop = PL_last_uni = NULL;
3612 PL_minus_n = PL_minus_p = 0;
3615 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3616 PL_last_lop = PL_last_uni = NULL;
3617 sv_setpvn(PL_linestr,"",0);
3618 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3620 /* If it looks like the start of a BOM or raw UTF-16,
3621 * check if it in fact is. */
3627 #ifdef PERLIO_IS_STDIO
3628 # ifdef __GNU_LIBRARY__
3629 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3630 # define FTELL_FOR_PIPE_IS_BROKEN
3634 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3635 # define FTELL_FOR_PIPE_IS_BROKEN
3640 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3641 /* This loses the possibility to detect the bof
3642 * situation on perl -P when the libc5 is being used.
3643 * Workaround? Maybe attach some extra state to PL_rsfp?
3646 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3648 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3651 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3652 s = swallow_bom((U8*)s);
3656 /* Incest with pod. */
3659 sv_catsv(PL_thiswhite, PL_linestr);
3661 if (*s == '=' && strnEQ(s, "=cut", 4)) {
3662 sv_setpvn(PL_linestr, "", 0);
3663 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3664 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3665 PL_last_lop = PL_last_uni = NULL;
3666 PL_doextract = FALSE;
3670 } while (PL_doextract);
3671 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3672 if (PERLDB_LINE && PL_curstash != PL_debstash)
3673 update_debugger_info_sv(PL_linestr);
3674 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3675 PL_last_lop = PL_last_uni = NULL;
3676 if (CopLINE(PL_curcop) == 1) {
3677 while (s < PL_bufend && isSPACE(*s))
3679 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3683 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3687 if (*s == '#' && *(s+1) == '!')
3689 #ifdef ALTERNATE_SHEBANG
3691 static char const as[] = ALTERNATE_SHEBANG;
3692 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3693 d = s + (sizeof(as) - 1);
3695 #endif /* ALTERNATE_SHEBANG */
3704 while (*d && !isSPACE(*d))
3708 #ifdef ARG_ZERO_IS_SCRIPT
3709 if (ipathend > ipath) {
3711 * HP-UX (at least) sets argv[0] to the script name,
3712 * which makes $^X incorrect. And Digital UNIX and Linux,
3713 * at least, set argv[0] to the basename of the Perl
3714 * interpreter. So, having found "#!", we'll set it right.
3716 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3718 assert(SvPOK(x) || SvGMAGICAL(x));
3719 if (sv_eq(x, CopFILESV(PL_curcop))) {
3720 sv_setpvn(x, ipath, ipathend - ipath);
3726 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3727 const char * const lstart = SvPV_const(x,llen);
3729 bstart += blen - llen;
3730 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3731 sv_setpvn(x, ipath, ipathend - ipath);
3736 TAINT_NOT; /* $^X is always tainted, but that's OK */
3738 #endif /* ARG_ZERO_IS_SCRIPT */
3743 d = instr(s,"perl -");
3745 d = instr(s,"perl");
3747 /* avoid getting into infinite loops when shebang
3748 * line contains "Perl" rather than "perl" */
3750 for (d = ipathend-4; d >= ipath; --d) {
3751 if ((*d == 'p' || *d == 'P')
3752 && !ibcmp(d, "perl", 4))
3762 #ifdef ALTERNATE_SHEBANG
3764 * If the ALTERNATE_SHEBANG on this system starts with a
3765 * character that can be part of a Perl expression, then if
3766 * we see it but not "perl", we're probably looking at the
3767 * start of Perl code, not a request to hand off to some
3768 * other interpreter. Similarly, if "perl" is there, but
3769 * not in the first 'word' of the line, we assume the line
3770 * contains the start of the Perl program.
3772 if (d && *s != '#') {
3773 const char *c = ipath;
3774 while (*c && !strchr("; \t\r\n\f\v#", *c))
3777 d = NULL; /* "perl" not in first word; ignore */
3779 *s = '#'; /* Don't try to parse shebang line */
3781 #endif /* ALTERNATE_SHEBANG */
3782 #ifndef MACOS_TRADITIONAL
3787 !instr(s,"indir") &&
3788 instr(PL_origargv[0],"perl"))
3795 while (s < PL_bufend && isSPACE(*s))
3797 if (s < PL_bufend) {
3798 Newxz(newargv,PL_origargc+3,char*);
3800 while (s < PL_bufend && !isSPACE(*s))
3803 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3806 newargv = PL_origargv;
3809 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3811 Perl_croak(aTHX_ "Can't exec %s", ipath);
3815 while (*d && !isSPACE(*d))
3817 while (SPACE_OR_TAB(*d))
3821 const bool switches_done = PL_doswitches;
3822 const U32 oldpdb = PL_perldb;
3823 const bool oldn = PL_minus_n;
3824 const bool oldp = PL_minus_p;
3827 if (*d == 'M' || *d == 'm' || *d == 'C') {
3828 const char * const m = d;
3829 while (*d && !isSPACE(*d))
3831 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3834 d = moreswitches(d);
3836 if (PL_doswitches && !switches_done) {
3837 int argc = PL_origargc;
3838 char **argv = PL_origargv;
3841 } while (argc && argv[0][0] == '-' && argv[0][1]);
3842 init_argv_symbols(argc,argv);
3844 if ((PERLDB_LINE && !oldpdb) ||
3845 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3846 /* if we have already added "LINE: while (<>) {",
3847 we must not do it again */
3849 sv_setpvn(PL_linestr, "", 0);
3850 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3851 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3852 PL_last_lop = PL_last_uni = NULL;
3853 PL_preambled = FALSE;
3855 (void)gv_fetchfile(PL_origfilename);
3862 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3864 PL_lex_state = LEX_FORMLINE;
3869 #ifdef PERL_STRICT_CR
3870 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3872 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3874 case ' ': case '\t': case '\f': case 013:
3875 #ifdef MACOS_TRADITIONAL
3879 PL_realtokenstart = -1;
3888 PL_realtokenstart = -1;
3892 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3893 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3894 /* handle eval qq[#line 1 "foo"\n ...] */
3895 CopLINE_dec(PL_curcop);
3898 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3900 if (!PL_in_eval || PL_rsfp)
3905 while (d < PL_bufend && *d != '\n')
3909 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3910 Perl_croak(aTHX_ "panic: input overflow");
3913 PL_thiswhite = newSVpvn(s, d - s);
3918 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3920 PL_lex_state = LEX_FORMLINE;
3926 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3927 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3930 TOKEN(PEG); /* make sure any #! line is accessible */
3935 /* if (PL_madskills && PL_lex_formbrack) { */
3937 while (d < PL_bufend && *d != '\n')
3941 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3942 Perl_croak(aTHX_ "panic: input overflow");
3943 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3945 PL_thiswhite = newSVpvs("");
3946 if (CopLINE(PL_curcop) == 1) {
3947 sv_setpvn(PL_thiswhite, "", 0);
3950 sv_catpvn(PL_thiswhite, s, d - s);
3964 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3972 while (s < PL_bufend && SPACE_OR_TAB(*s))
3975 if (strnEQ(s,"=>",2)) {
3976 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3977 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
3978 OPERATOR('-'); /* unary minus */
3980 PL_last_uni = PL_oldbufptr;
3982 case 'r': ftst = OP_FTEREAD; break;
3983 case 'w': ftst = OP_FTEWRITE; break;
3984 case 'x': ftst = OP_FTEEXEC; break;
3985 case 'o': ftst = OP_FTEOWNED; break;
3986 case 'R': ftst = OP_FTRREAD; break;
3987 case 'W': ftst = OP_FTRWRITE; break;
3988 case 'X': ftst = OP_FTREXEC; break;
3989 case 'O': ftst = OP_FTROWNED; break;
3990 case 'e': ftst = OP_FTIS; break;
3991 case 'z': ftst = OP_FTZERO; break;
3992 case 's': ftst = OP_FTSIZE; break;
3993 case 'f': ftst = OP_FTFILE; break;
3994 case 'd': ftst = OP_FTDIR; break;
3995 case 'l': ftst = OP_FTLINK; break;
3996 case 'p': ftst = OP_FTPIPE; break;
3997 case 'S': ftst = OP_FTSOCK; break;
3998 case 'u': ftst = OP_FTSUID; break;
3999 case 'g': ftst = OP_FTSGID; break;
4000 case 'k': ftst = OP_FTSVTX; break;
4001 case 'b': ftst = OP_FTBLK; break;
4002 case 'c': ftst = OP_FTCHR; break;
4003 case 't': ftst = OP_FTTTY; break;
4004 case 'T': ftst = OP_FTTEXT; break;
4005 case 'B': ftst = OP_FTBINARY; break;
4006 case 'M': case 'A': case 'C':
4007 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
4009 case 'M': ftst = OP_FTMTIME; break;
4010 case 'A': ftst = OP_FTATIME; break;
4011 case 'C': ftst = OP_FTCTIME; break;
4019 PL_last_lop_op = (OPCODE)ftst;
4020 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4021 "### Saw file test %c\n", (int)tmp);
4026 /* Assume it was a minus followed by a one-letter named
4027 * subroutine call (or a -bareword), then. */
4028 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4029 "### '-%c' looked like a file test but was not\n",
4036 const char tmp = *s++;
4039 if (PL_expect == XOPERATOR)
4044 else if (*s == '>') {
4047 if (isIDFIRST_lazy_if(s,UTF)) {
4048 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4056 if (PL_expect == XOPERATOR)
4059 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4061 OPERATOR('-'); /* unary minus */
4067 const char tmp = *s++;
4070 if (PL_expect == XOPERATOR)
4075 if (PL_expect == XOPERATOR)
4078 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4085 if (PL_expect != XOPERATOR) {
4086 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4087 PL_expect = XOPERATOR;
4088 force_ident(PL_tokenbuf, '*');
4101 if (PL_expect == XOPERATOR) {
4105 PL_tokenbuf[0] = '%';
4106 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
4107 if (!PL_tokenbuf[1]) {
4110 PL_pending_ident = '%';
4121 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
4122 && FEATURE_IS_ENABLED("~~"))
4129 const char tmp = *s++;
4135 goto just_a_word_zero_gv;
4138 switch (PL_expect) {
4144 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4146 PL_bufptr = s; /* update in case we back off */
4152 PL_expect = XTERMBLOCK;
4155 stuffstart = s - SvPVX(PL_linestr) - 1;
4159 while (isIDFIRST_lazy_if(s,UTF)) {
4162 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4163 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4164 if (tmp < 0) tmp = -tmp;
4179 sv = newSVpvn(s, len);
4181 d = scan_str(d,TRUE,TRUE);
4183 /* MUST advance bufptr here to avoid bogus
4184 "at end of line" context messages from yyerror().
4186 PL_bufptr = s + len;
4187 yyerror("Unterminated attribute parameter in attribute list");
4191 return REPORT(0); /* EOF indicator */
4195 sv_catsv(sv, PL_lex_stuff);
4196 attrs = append_elem(OP_LIST, attrs,
4197 newSVOP(OP_CONST, 0, sv));
4198 SvREFCNT_dec(PL_lex_stuff);
4199 PL_lex_stuff = NULL;
4202 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4204 if (PL_in_my == KEY_our) {
4206 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4208 /* skip to avoid loading attributes.pm */
4210 deprecate(":unique");
4213 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4216 /* NOTE: any CV attrs applied here need to be part of
4217 the CVf_BUILTIN_ATTRS define in cv.h! */
4218 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4220 CvLVALUE_on(PL_compcv);
4222 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4224 CvLOCKED_on(PL_compcv);
4226 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4228 CvMETHOD_on(PL_compcv);
4230 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4232 CvASSERTION_on(PL_compcv);
4234 /* After we've set the flags, it could be argued that
4235 we don't need to do the attributes.pm-based setting
4236 process, and shouldn't bother appending recognized
4237 flags. To experiment with that, uncomment the
4238 following "else". (Note that's already been
4239 uncommented. That keeps the above-applied built-in
4240 attributes from being intercepted (and possibly
4241 rejected) by a package's attribute routines, but is
4242 justified by the performance win for the common case
4243 of applying only built-in attributes.) */
4245 attrs = append_elem(OP_LIST, attrs,
4246 newSVOP(OP_CONST, 0,
4250 if (*s == ':' && s[1] != ':')
4253 break; /* require real whitespace or :'s */
4254 /* XXX losing whitespace on sequential attributes here */
4258 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4259 if (*s != ';' && *s != '}' && *s != tmp
4260 && (tmp != '=' || *s != ')')) {
4261 const char q = ((*s == '\'') ? '"' : '\'');
4262 /* If here for an expression, and parsed no attrs, back
4264 if (tmp == '=' && !attrs) {
4268 /* MUST advance bufptr here to avoid bogus "at end of line"
4269 context messages from yyerror().
4272 yyerror( (const char *)
4274 ? Perl_form(aTHX_ "Invalid separator character "
4275 "%c%c%c in attribute list", q, *s, q)
4276 : "Unterminated attribute list" ) );
4284 start_force(PL_curforce);
4285 NEXTVAL_NEXTTOKE.opval = attrs;
4286 CURMAD('_', PL_nextwhite);
4291 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4292 (s - SvPVX(PL_linestr)) - stuffstart);
4300 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4301 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4309 const char tmp = *s++;
4314 const char tmp = *s++;
4322 if (PL_lex_brackets <= 0)
4323 yyerror("Unmatched right square bracket");
4326 if (PL_lex_state == LEX_INTERPNORMAL) {
4327 if (PL_lex_brackets == 0) {
4328 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4329 PL_lex_state = LEX_INTERPEND;
4336 if (PL_lex_brackets > 100) {
4337 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4339 switch (PL_expect) {
4341 if (PL_lex_formbrack) {
4345 if (PL_oldoldbufptr == PL_last_lop)
4346 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4348 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4349 OPERATOR(HASHBRACK);
4351 while (s < PL_bufend && SPACE_OR_TAB(*s))
4354 PL_tokenbuf[0] = '\0';
4355 if (d < PL_bufend && *d == '-') {
4356 PL_tokenbuf[0] = '-';
4358 while (d < PL_bufend && SPACE_OR_TAB(*d))
4361 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4362 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4364 while (d < PL_bufend && SPACE_OR_TAB(*d))
4367 const char minus = (PL_tokenbuf[0] == '-');
4368 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4376 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4381 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4386 if (PL_oldoldbufptr == PL_last_lop)
4387 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4389 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4392 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4394 /* This hack is to get the ${} in the message. */
4396 yyerror("syntax error");
4399 OPERATOR(HASHBRACK);
4401 /* This hack serves to disambiguate a pair of curlies
4402 * as being a block or an anon hash. Normally, expectation
4403 * determines that, but in cases where we're not in a
4404 * position to expect anything in particular (like inside
4405 * eval"") we have to resolve the ambiguity. This code
4406 * covers the case where the first term in the curlies is a
4407 * quoted string. Most other cases need to be explicitly
4408 * disambiguated by prepending a "+" before the opening
4409 * curly in order to force resolution as an anon hash.
4411 * XXX should probably propagate the outer expectation
4412 * into eval"" to rely less on this hack, but that could
4413 * potentially break current behavior of eval"".
4417 if (*s == '\'' || *s == '"' || *s == '`') {
4418 /* common case: get past first string, handling escapes */
4419 for (t++; t < PL_bufend && *t != *s;)
4420 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4424 else if (*s == 'q') {
4427 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4430 /* skip q//-like construct */
4432 char open, close, term;
4435 while (t < PL_bufend && isSPACE(*t))
4437 /* check for q => */
4438 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4439 OPERATOR(HASHBRACK);
4443 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4447 for (t++; t < PL_bufend; t++) {
4448 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4450 else if (*t == open)
4454 for (t++; t < PL_bufend; t++) {
4455 if (*t == '\\' && t+1 < PL_bufend)
4457 else if (*t == close && --brackets <= 0)
4459 else if (*t == open)
4466 /* skip plain q word */
4467 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4470 else if (isALNUM_lazy_if(t,UTF)) {
4472 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4475 while (t < PL_bufend && isSPACE(*t))
4477 /* if comma follows first term, call it an anon hash */
4478 /* XXX it could be a comma expression with loop modifiers */
4479 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4480 || (*t == '=' && t[1] == '>')))
4481 OPERATOR(HASHBRACK);
4482 if (PL_expect == XREF)
4485 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4491 yylval.ival = CopLINE(PL_curcop);
4492 if (isSPACE(*s) || *s == '#')
4493 PL_copline = NOLINE; /* invalidate current command line number */
4498 if (PL_lex_brackets <= 0)
4499 yyerror("Unmatched right curly bracket");
4501 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4502 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4503 PL_lex_formbrack = 0;
4504 if (PL_lex_state == LEX_INTERPNORMAL) {
4505 if (PL_lex_brackets == 0) {
4506 if (PL_expect & XFAKEBRACK) {
4507 PL_expect &= XENUMMASK;
4508 PL_lex_state = LEX_INTERPEND;
4513 PL_thiswhite = newSVpvs("");
4514 sv_catpvn(PL_thiswhite,"}",1);
4517 return yylex(); /* ignore fake brackets */
4519 if (*s == '-' && s[1] == '>')
4520 PL_lex_state = LEX_INTERPENDMAYBE;
4521 else if (*s != '[' && *s != '{')
4522 PL_lex_state = LEX_INTERPEND;
4525 if (PL_expect & XFAKEBRACK) {
4526 PL_expect &= XENUMMASK;
4528 return yylex(); /* ignore fake brackets */
4530 start_force(PL_curforce);
4532 curmad('X', newSVpvn(s-1,1));
4533 CURMAD('_', PL_thiswhite);
4538 PL_thistoken = newSVpvs("");
4546 if (PL_expect == XOPERATOR) {
4547 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4548 && isIDFIRST_lazy_if(s,UTF))
4550 CopLINE_dec(PL_curcop);
4551 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4552 CopLINE_inc(PL_curcop);
4557 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4559 PL_expect = XOPERATOR;
4560 force_ident(PL_tokenbuf, '&');
4564 yylval.ival = (OPpENTERSUB_AMPER<<8);
4576 const char tmp = *s++;
4583 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4584 && strchr("+-*/%.^&|<",tmp))
4585 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4586 "Reversed %c= operator",(int)tmp);
4588 if (PL_expect == XSTATE && isALPHA(tmp) &&
4589 (s == PL_linestart+1 || s[-2] == '\n') )
4591 if (PL_in_eval && !PL_rsfp) {
4596 if (strnEQ(s,"=cut",4)) {
4612 PL_thiswhite = newSVpvs("");
4613 sv_catpvn(PL_thiswhite, PL_linestart,
4614 PL_bufend - PL_linestart);
4618 PL_doextract = TRUE;
4622 if (PL_lex_brackets < PL_lex_formbrack) {
4624 #ifdef PERL_STRICT_CR
4625 while (SPACE_OR_TAB(*t))
4627 while (SPACE_OR_TAB(*t) || *t == '\r')
4630 if (*t == '\n' || *t == '#') {
4641 const char tmp = *s++;
4643 /* was this !=~ where !~ was meant?
4644 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4646 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4647 const char *t = s+1;
4649 while (t < PL_bufend && isSPACE(*t))
4652 if (*t == '/' || *t == '?' ||
4653 ((*t == 'm' || *t == 's' || *t == 'y')
4654 && !isALNUM(t[1])) ||
4655 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4656 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4657 "!=~ should be !~");
4667 if (PL_expect != XOPERATOR) {
4668 if (s[1] != '<' && !strchr(s,'>'))
4671 s = scan_heredoc(s);
4673 s = scan_inputsymbol(s);
4674 TERM(sublex_start());
4680 SHop(OP_LEFT_SHIFT);
4694 const char tmp = *s++;
4696 SHop(OP_RIGHT_SHIFT);
4697 else if (tmp == '=')
4706 if (PL_expect == XOPERATOR) {
4707 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4709 deprecate_old(commaless_variable_list);
4710 return REPORT(','); /* grandfather non-comma-format format */
4714 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4715 PL_tokenbuf[0] = '@';
4716 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4717 sizeof PL_tokenbuf - 1, FALSE);
4718 if (PL_expect == XOPERATOR)
4719 no_op("Array length", s);
4720 if (!PL_tokenbuf[1])
4722 PL_expect = XOPERATOR;
4723 PL_pending_ident = '#';
4727 PL_tokenbuf[0] = '$';
4728 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4729 sizeof PL_tokenbuf - 1, FALSE);
4730 if (PL_expect == XOPERATOR)
4732 if (!PL_tokenbuf[1]) {
4734 yyerror("Final $ should be \\$ or $name");
4738 /* This kludge not intended to be bulletproof. */
4739 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4740 yylval.opval = newSVOP(OP_CONST, 0,
4741 newSViv(CopARYBASE_get(&PL_compiling)));
4742 yylval.opval->op_private = OPpCONST_ARYBASE;
4748 const char tmp = *s;
4749 if (PL_lex_state == LEX_NORMAL)
4752 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4753 && intuit_more(s)) {
4755 PL_tokenbuf[0] = '@';
4756 if (ckWARN(WARN_SYNTAX)) {
4759 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4762 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4763 while (t < PL_bufend && *t != ']')
4765 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4766 "Multidimensional syntax %.*s not supported",
4767 (int)((t - PL_bufptr) + 1), PL_bufptr);
4771 else if (*s == '{') {
4773 PL_tokenbuf[0] = '%';
4774 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4775 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4777 char tmpbuf[sizeof PL_tokenbuf];
4780 } while (isSPACE(*t));
4781 if (isIDFIRST_lazy_if(t,UTF)) {
4783 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4787 if (*t == ';' && get_cv(tmpbuf, FALSE))
4788 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4789 "You need to quote \"%s\"",
4796 PL_expect = XOPERATOR;
4797 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4798 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4799 if (!islop || PL_last_lop_op == OP_GREPSTART)
4800 PL_expect = XOPERATOR;
4801 else if (strchr("$@\"'`q", *s))
4802 PL_expect = XTERM; /* e.g. print $fh "foo" */
4803 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4804 PL_expect = XTERM; /* e.g. print $fh &sub */
4805 else if (isIDFIRST_lazy_if(s,UTF)) {
4806 char tmpbuf[sizeof PL_tokenbuf];
4808 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4809 if ((t2 = keyword(tmpbuf, len, 0))) {
4810 /* binary operators exclude handle interpretations */
4822 PL_expect = XTERM; /* e.g. print $fh length() */
4827 PL_expect = XTERM; /* e.g. print $fh subr() */
4830 else if (isDIGIT(*s))
4831 PL_expect = XTERM; /* e.g. print $fh 3 */
4832 else if (*s == '.' && isDIGIT(s[1]))
4833 PL_expect = XTERM; /* e.g. print $fh .3 */
4834 else if ((*s == '?' || *s == '-' || *s == '+')
4835 && !isSPACE(s[1]) && s[1] != '=')
4836 PL_expect = XTERM; /* e.g. print $fh -1 */
4837 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4839 PL_expect = XTERM; /* e.g. print $fh /.../
4840 XXX except DORDOR operator
4842 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4844 PL_expect = XTERM; /* print $fh <<"EOF" */
4847 PL_pending_ident = '$';
4851 if (PL_expect == XOPERATOR)
4853 PL_tokenbuf[0] = '@';
4854 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4855 if (!PL_tokenbuf[1]) {
4858 if (PL_lex_state == LEX_NORMAL)
4860 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4862 PL_tokenbuf[0] = '%';
4864 /* Warn about @ where they meant $. */
4865 if (*s == '[' || *s == '{') {
4866 if (ckWARN(WARN_SYNTAX)) {
4867 const char *t = s + 1;
4868 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4870 if (*t == '}' || *t == ']') {
4872 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4873 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4874 "Scalar value %.*s better written as $%.*s",
4875 (int)(t-PL_bufptr), PL_bufptr,
4876 (int)(t-PL_bufptr-1), PL_bufptr+1);
4881 PL_pending_ident = '@';
4884 case '/': /* may be division, defined-or, or pattern */
4885 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4889 case '?': /* may either be conditional or pattern */
4890 if(PL_expect == XOPERATOR) {
4898 /* A // operator. */
4908 /* Disable warning on "study /blah/" */
4909 if (PL_oldoldbufptr == PL_last_uni
4910 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4911 || memNE(PL_last_uni, "study", 5)
4912 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4915 s = scan_pat(s,OP_MATCH);
4916 TERM(sublex_start());
4920 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4921 #ifdef PERL_STRICT_CR
4924 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4926 && (s == PL_linestart || s[-1] == '\n') )
4928 PL_lex_formbrack = 0;
4932 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4938 yylval.ival = OPf_SPECIAL;
4944 if (PL_expect != XOPERATOR)
4949 case '0': case '1': case '2': case '3': case '4':
4950 case '5': case '6': case '7': case '8': case '9':
4951 s = scan_num(s, &yylval);
4952 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
4953 if (PL_expect == XOPERATOR)
4958 s = scan_str(s,!!PL_madskills,FALSE);
4959 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4960 if (PL_expect == XOPERATOR) {
4961 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4963 deprecate_old(commaless_variable_list);
4964 return REPORT(','); /* grandfather non-comma-format format */
4971 yylval.ival = OP_CONST;
4972 TERM(sublex_start());
4975 s = scan_str(s,!!PL_madskills,FALSE);
4976 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4977 if (PL_expect == XOPERATOR) {
4978 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4980 deprecate_old(commaless_variable_list);
4981 return REPORT(','); /* grandfather non-comma-format format */
4988 yylval.ival = OP_CONST;
4989 /* FIXME. I think that this can be const if char *d is replaced by
4990 more localised variables. */
4991 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4992 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4993 yylval.ival = OP_STRINGIFY;
4997 TERM(sublex_start());
5000 s = scan_str(s,!!PL_madskills,FALSE);
5001 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
5002 if (PL_expect == XOPERATOR)
5003 no_op("Backticks",s);
5006 readpipe_override();
5007 TERM(sublex_start());
5011 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
5012 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5014 if (PL_expect == XOPERATOR)
5015 no_op("Backslash",s);
5019 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
5020 char *start = s + 2;
5021 while (isDIGIT(*start) || *start == '_')
5023 if (*start == '.' && isDIGIT(start[1])) {
5024 s = scan_num(s, &yylval);
5027 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
5028 else if (!isALPHA(*start) && (PL_expect == XTERM
5029 || PL_expect == XREF || PL_expect == XSTATE
5030 || PL_expect == XTERMORDORDOR)) {
5031 /* XXX Use gv_fetchpvn rather than stomping on a const string */
5032 const char c = *start;
5035 gv = gv_fetchpv(s, 0, SVt_PVCV);
5038 s = scan_num(s, &yylval);
5045 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5087 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5089 /* Some keywords can be followed by any delimiter, including ':' */
5090 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5091 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5092 (PL_tokenbuf[0] == 'q' &&
5093 strchr("qwxr", PL_tokenbuf[1])))));
5095 /* x::* is just a word, unless x is "CORE" */
5096 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5100 while (d < PL_bufend && isSPACE(*d))
5101 d++; /* no comments skipped here, or s### is misparsed */
5103 /* Is this a label? */
5104 if (!tmp && PL_expect == XSTATE
5105 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5107 yylval.pval = CopLABEL_alloc(PL_tokenbuf);
5112 /* Check for keywords */
5113 tmp = keyword(PL_tokenbuf, len, 0);
5115 /* Is this a word before a => operator? */
5116 if (*d == '=' && d[1] == '>') {
5119 = (OP*)newSVOP(OP_CONST, 0,
5120 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5121 yylval.opval->op_private = OPpCONST_BARE;
5125 if (tmp < 0) { /* second-class keyword? */
5126 GV *ogv = NULL; /* override (winner) */
5127 GV *hgv = NULL; /* hidden (loser) */
5128 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5130 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5133 if (GvIMPORTED_CV(gv))
5135 else if (! CvMETHOD(cv))
5139 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5140 (gv = *gvp) != (GV*)&PL_sv_undef &&
5141 GvCVu(gv) && GvIMPORTED_CV(gv))
5148 tmp = 0; /* overridden by import or by GLOBAL */
5151 && -tmp==KEY_lock /* XXX generalizable kludge */
5153 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
5155 tmp = 0; /* any sub overrides "weak" keyword */
5157 else { /* no override */
5159 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5160 Perl_warner(aTHX_ packWARN(WARN_MISC),
5161 "dump() better written as CORE::dump()");
5165 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5166 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5167 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5168 "Ambiguous call resolved as CORE::%s(), %s",
5169 GvENAME(hgv), "qualify as such or use &");
5176 default: /* not a keyword */
5177 /* Trade off - by using this evil construction we can pull the
5178 variable gv into the block labelled keylookup. If not, then
5179 we have to give it function scope so that the goto from the
5180 earlier ':' case doesn't bypass the initialisation. */
5182 just_a_word_zero_gv:
5190 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5193 SV *nextPL_nextwhite = 0;
5197 /* Get the rest if it looks like a package qualifier */
5199 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5201 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5204 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5205 *s == '\'' ? "'" : "::");
5210 if (PL_expect == XOPERATOR) {
5211 if (PL_bufptr == PL_linestart) {
5212 CopLINE_dec(PL_curcop);
5213 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5214 CopLINE_inc(PL_curcop);
5217 no_op("Bareword",s);
5220 /* Look for a subroutine with this name in current package,
5221 unless name is "Foo::", in which case Foo is a bearword
5222 (and a package name). */
5224 if (len > 2 && !PL_madskills &&
5225 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5227 if (ckWARN(WARN_BAREWORD)
5228 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5229 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5230 "Bareword \"%s\" refers to nonexistent package",
5233 PL_tokenbuf[len] = '\0';
5239 /* Mustn't actually add anything to a symbol table.
5240 But also don't want to "initialise" any placeholder
5241 constants that might already be there into full
5242 blown PVGVs with attached PVCV. */
5243 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5244 GV_NOADD_NOINIT, SVt_PVCV);
5249 /* if we saw a global override before, get the right name */
5252 sv = newSVpvs("CORE::GLOBAL::");
5253 sv_catpv(sv,PL_tokenbuf);
5256 /* If len is 0, newSVpv does strlen(), which is correct.
5257 If len is non-zero, then it will be the true length,
5258 and so the scalar will be created correctly. */
5259 sv = newSVpv(PL_tokenbuf,len);
5262 if (PL_madskills && !PL_thistoken) {
5263 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5264 PL_thistoken = newSVpv(start,s - start);
5265 PL_realtokenstart = s - SvPVX(PL_linestr);
5269 /* Presume this is going to be a bareword of some sort. */
5272 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5273 yylval.opval->op_private = OPpCONST_BARE;
5274 /* UTF-8 package name? */
5275 if (UTF && !IN_BYTES &&
5276 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5279 /* And if "Foo::", then that's what it certainly is. */
5284 /* Do the explicit type check so that we don't need to force
5285 the initialisation of the symbol table to have a real GV.
5286 Beware - gv may not really be a PVGV, cv may not really be
5287 a PVCV, (because of the space optimisations that gv_init
5288 understands) But they're true if for this symbol there is
5289 respectively a typeglob and a subroutine.
5291 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5292 /* Real typeglob, so get the real subroutine: */
5294 /* A proxy for a subroutine in this package? */
5295 : SvOK(gv) ? (CV *) gv : NULL)
5298 /* See if it's the indirect object for a list operator. */
5300 if (PL_oldoldbufptr &&
5301 PL_oldoldbufptr < PL_bufptr &&
5302 (PL_oldoldbufptr == PL_last_lop
5303 || PL_oldoldbufptr == PL_last_uni) &&
5304 /* NO SKIPSPACE BEFORE HERE! */
5305 (PL_expect == XREF ||
5306 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5308 bool immediate_paren = *s == '(';
5310 /* (Now we can afford to cross potential line boundary.) */
5311 s = SKIPSPACE2(s,nextPL_nextwhite);
5313 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5316 /* Two barewords in a row may indicate method call. */
5318 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5319 (tmp = intuit_method(s, gv, cv)))
5322 /* If not a declared subroutine, it's an indirect object. */
5323 /* (But it's an indir obj regardless for sort.) */
5324 /* Also, if "_" follows a filetest operator, it's a bareword */
5327 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5329 (PL_last_lop_op != OP_MAPSTART &&
5330 PL_last_lop_op != OP_GREPSTART))))
5331 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5332 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5335 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5340 PL_expect = XOPERATOR;
5343 s = SKIPSPACE2(s,nextPL_nextwhite);
5344 PL_nextwhite = nextPL_nextwhite;
5349 /* Is this a word before a => operator? */
5350 if (*s == '=' && s[1] == '>' && !pkgname) {
5352 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5353 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5354 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5358 /* If followed by a paren, it's certainly a subroutine. */
5363 while (SPACE_OR_TAB(*d))
5365 if (*d == ')' && (sv = gv_const_sv(gv))) {
5369 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5370 sv_catpvn(PL_thistoken, par, s - par);
5372 sv_free(PL_nextwhite);
5382 PL_nextwhite = PL_thiswhite;
5385 start_force(PL_curforce);
5387 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5388 PL_expect = XOPERATOR;
5391 PL_nextwhite = nextPL_nextwhite;
5392 curmad('X', PL_thistoken);
5393 PL_thistoken = newSVpvs("");
5401 /* If followed by var or block, call it a method (unless sub) */
5403 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5404 PL_last_lop = PL_oldbufptr;
5405 PL_last_lop_op = OP_METHOD;
5409 /* If followed by a bareword, see if it looks like indir obj. */
5412 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5413 && (tmp = intuit_method(s, gv, cv)))
5416 /* Not a method, so call it a subroutine (if defined) */
5419 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5420 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5421 "Ambiguous use of -%s resolved as -&%s()",
5422 PL_tokenbuf, PL_tokenbuf);
5423 /* Check for a constant sub */
5424 if ((sv = gv_const_sv(gv))) {
5426 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5427 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5428 yylval.opval->op_private = 0;
5432 /* Resolve to GV now. */
5433 if (SvTYPE(gv) != SVt_PVGV) {
5434 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5435 assert (SvTYPE(gv) == SVt_PVGV);
5436 /* cv must have been some sort of placeholder, so
5437 now needs replacing with a real code reference. */
5441 op_free(yylval.opval);
5442 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5443 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5444 PL_last_lop = PL_oldbufptr;
5445 PL_last_lop_op = OP_ENTERSUB;
5446 /* Is there a prototype? */
5454 const char *proto = SvPV_const((SV*)cv, protolen);
5457 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
5459 while (*proto == ';')
5461 if (*proto == '&' && *s == '{') {
5462 sv_setpv(PL_subname,
5465 "__ANON__" : "__ANON__::__ANON__"));
5472 PL_nextwhite = PL_thiswhite;
5475 start_force(PL_curforce);
5476 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5479 PL_nextwhite = nextPL_nextwhite;
5480 curmad('X', PL_thistoken);
5481 PL_thistoken = newSVpvs("");
5488 /* Guess harder when madskills require "best effort". */
5489 if (PL_madskills && (!gv || !GvCVu(gv))) {
5490 int probable_sub = 0;
5491 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5493 else if (isALPHA(*s)) {
5497 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5498 if (!keyword(tmpbuf, tmplen, 0))
5501 while (d < PL_bufend && isSPACE(*d))
5503 if (*d == '=' && d[1] == '>')
5508 gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5509 op_free(yylval.opval);
5510 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5511 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5512 PL_last_lop = PL_oldbufptr;
5513 PL_last_lop_op = OP_ENTERSUB;
5514 PL_nextwhite = PL_thiswhite;
5516 start_force(PL_curforce);
5517 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5519 PL_nextwhite = nextPL_nextwhite;
5520 curmad('X', PL_thistoken);
5521 PL_thistoken = newSVpvs("");
5526 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5533 /* Call it a bare word */
5535 if (PL_hints & HINT_STRICT_SUBS)
5536 yylval.opval->op_private |= OPpCONST_STRICT;
5539 if (lastchar != '-') {
5540 if (ckWARN(WARN_RESERVED)) {
5544 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
5545 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5552 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5553 && ckWARN_d(WARN_AMBIGUOUS)) {
5554 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5555 "Operator or semicolon missing before %c%s",
5556 lastchar, PL_tokenbuf);
5557 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5558 "Ambiguous use of %c resolved as operator %c",
5559 lastchar, lastchar);
5565 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5566 newSVpv(CopFILE(PL_curcop),0));
5570 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5571 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5574 case KEY___PACKAGE__:
5575 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5577 ? newSVhek(HvNAME_HEK(PL_curstash))
5584 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5585 const char *pname = "main";
5586 if (PL_tokenbuf[2] == 'D')
5587 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5588 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5592 GvIOp(gv) = newIO();
5593 IoIFP(GvIOp(gv)) = PL_rsfp;
5594 #if defined(HAS_FCNTL) && defined(F_SETFD)
5596 const int fd = PerlIO_fileno(PL_rsfp);
5597 fcntl(fd,F_SETFD,fd >= 3);
5600 /* Mark this internal pseudo-handle as clean */
5601 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5603 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5604 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5605 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5607 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5608 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5609 /* if the script was opened in binmode, we need to revert
5610 * it to text mode for compatibility; but only iff it has CRs
5611 * XXX this is a questionable hack at best. */
5612 if (PL_bufend-PL_bufptr > 2
5613 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5616 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5617 loc = PerlIO_tell(PL_rsfp);
5618 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5621 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5623 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5624 #endif /* NETWARE */
5625 #ifdef PERLIO_IS_STDIO /* really? */
5626 # if defined(__BORLANDC__)
5627 /* XXX see note in do_binmode() */
5628 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5632 PerlIO_seek(PL_rsfp, loc, 0);
5636 #ifdef PERLIO_LAYERS
5639 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5640 else if (PL_encoding) {
5647 XPUSHs(PL_encoding);
5649 call_method("name", G_SCALAR);
5653 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5654 Perl_form(aTHX_ ":encoding(%"SVf")",
5663 if (PL_realtokenstart >= 0) {
5664 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5666 PL_endwhite = newSVpvs("");
5667 sv_catsv(PL_endwhite, PL_thiswhite);
5669 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5670 PL_realtokenstart = -1;
5672 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5673 SvCUR(PL_endwhite))) != Nullch) ;
5688 if (PL_expect == XSTATE) {
5695 if (*s == ':' && s[1] == ':') {
5698 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5699 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5700 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5703 else if (tmp == KEY_require || tmp == KEY_do)
5704 /* that's a way to remember we saw "CORE::" */
5717 LOP(OP_ACCEPT,XTERM);
5723 LOP(OP_ATAN2,XTERM);
5729 LOP(OP_BINMODE,XTERM);
5732 LOP(OP_BLESS,XTERM);
5741 /* When 'use switch' is in effect, continue has a dual
5742 life as a control operator. */
5744 if (!FEATURE_IS_ENABLED("switch"))
5747 /* We have to disambiguate the two senses of
5748 "continue". If the next token is a '{' then
5749 treat it as the start of a continue block;
5750 otherwise treat it as a control operator.
5762 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5779 if (!PL_cryptseen) {
5780 PL_cryptseen = TRUE;
5784 LOP(OP_CRYPT,XTERM);
5787 LOP(OP_CHMOD,XTERM);
5790 LOP(OP_CHOWN,XTERM);
5793 LOP(OP_CONNECT,XTERM);
5812 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5813 if (orig_keyword == KEY_do) {
5822 PL_hints |= HINT_BLOCK_SCOPE;
5832 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5833 LOP(OP_DBMOPEN,XTERM);
5839 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5846 yylval.ival = CopLINE(PL_curcop);
5862 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5863 UNIBRACK(OP_ENTEREVAL);
5881 case KEY_endhostent:
5887 case KEY_endservent:
5890 case KEY_endprotoent:
5901 yylval.ival = CopLINE(PL_curcop);
5903 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5906 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5909 if ((PL_bufend - p) >= 3 &&
5910 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5912 else if ((PL_bufend - p) >= 4 &&
5913 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5916 if (isIDFIRST_lazy_if(p,UTF)) {
5917 p = scan_ident(p, PL_bufend,
5918 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5922 Perl_croak(aTHX_ "Missing $ on loop variable");
5924 s = SvPVX(PL_linestr) + soff;
5930 LOP(OP_FORMLINE,XTERM);
5936 LOP(OP_FCNTL,XTERM);
5942 LOP(OP_FLOCK,XTERM);
5951 LOP(OP_GREPSTART, XREF);
5954 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5969 case KEY_getpriority:
5970 LOP(OP_GETPRIORITY,XTERM);
5972 case KEY_getprotobyname:
5975 case KEY_getprotobynumber:
5976 LOP(OP_GPBYNUMBER,XTERM);
5978 case KEY_getprotoent:
5990 case KEY_getpeername:
5991 UNI(OP_GETPEERNAME);
5993 case KEY_gethostbyname:
5996 case KEY_gethostbyaddr:
5997 LOP(OP_GHBYADDR,XTERM);
5999 case KEY_gethostent:
6002 case KEY_getnetbyname:
6005 case KEY_getnetbyaddr:
6006 LOP(OP_GNBYADDR,XTERM);
6011 case KEY_getservbyname:
6012 LOP(OP_GSBYNAME,XTERM);
6014 case KEY_getservbyport:
6015 LOP(OP_GSBYPORT,XTERM);
6017 case KEY_getservent:
6020 case KEY_getsockname:
6021 UNI(OP_GETSOCKNAME);
6023 case KEY_getsockopt:
6024 LOP(OP_GSOCKOPT,XTERM);
6039 yylval.ival = CopLINE(PL_curcop);
6050 yylval.ival = CopLINE(PL_curcop);
6054 LOP(OP_INDEX,XTERM);
6060 LOP(OP_IOCTL,XTERM);
6072 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6104 LOP(OP_LISTEN,XTERM);
6113 s = scan_pat(s,OP_MATCH);
6114 TERM(sublex_start());
6117 LOP(OP_MAPSTART, XREF);
6120 LOP(OP_MKDIR,XTERM);
6123 LOP(OP_MSGCTL,XTERM);
6126 LOP(OP_MSGGET,XTERM);
6129 LOP(OP_MSGRCV,XTERM);
6132 LOP(OP_MSGSND,XTERM);
6139 if (isIDFIRST_lazy_if(s,UTF)) {
6143 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6144 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6146 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6147 if (!PL_in_my_stash) {
6150 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6154 if (PL_madskills) { /* just add type to declarator token */
6155 sv_catsv(PL_thistoken, PL_nextwhite);
6157 sv_catpvn(PL_thistoken, start, s - start);
6165 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6172 s = tokenize_use(0, s);
6176 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6183 if (isIDFIRST_lazy_if(s,UTF)) {
6185 for (d = s; isALNUM_lazy_if(d,UTF);)
6187 for (t=d; isSPACE(*t);)
6189 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6191 && !(t[0] == '=' && t[1] == '>')
6193 int parms_len = (int)(d-s);
6194 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6195 "Precedence problem: open %.*s should be open(%.*s)",
6196 parms_len, s, parms_len, s);
6202 yylval.ival = OP_OR;
6212 LOP(OP_OPEN_DIR,XTERM);
6215 checkcomma(s,PL_tokenbuf,"filehandle");
6219 checkcomma(s,PL_tokenbuf,"filehandle");
6238 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6242 LOP(OP_PIPE_OP,XTERM);
6245 s = scan_str(s,!!PL_madskills,FALSE);
6248 yylval.ival = OP_CONST;
6249 TERM(sublex_start());
6255 s = scan_str(s,!!PL_madskills,FALSE);
6258 PL_expect = XOPERATOR;
6260 if (SvCUR(PL_lex_stuff)) {
6263 d = SvPV_force(PL_lex_stuff, len);
6265 for (; isSPACE(*d) && len; --len, ++d)
6270 if (!warned && ckWARN(WARN_QW)) {
6271 for (; !isSPACE(*d) && len; --len, ++d) {
6273 Perl_warner(aTHX_ packWARN(WARN_QW),
6274 "Possible attempt to separate words with commas");
6277 else if (*d == '#') {
6278 Perl_warner(aTHX_ packWARN(WARN_QW),
6279 "Possible attempt to put comments in qw() list");
6285 for (; !isSPACE(*d) && len; --len, ++d)
6288 sv = newSVpvn(b, d-b);
6289 if (DO_UTF8(PL_lex_stuff))
6291 words = append_elem(OP_LIST, words,
6292 newSVOP(OP_CONST, 0, tokeq(sv)));
6296 start_force(PL_curforce);
6297 NEXTVAL_NEXTTOKE.opval = words;
6302 SvREFCNT_dec(PL_lex_stuff);
6303 PL_lex_stuff = NULL;
6309 s = scan_str(s,!!PL_madskills,FALSE);
6312 yylval.ival = OP_STRINGIFY;
6313 if (SvIVX(PL_lex_stuff) == '\'')
6314 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6315 TERM(sublex_start());
6318 s = scan_pat(s,OP_QR);
6319 TERM(sublex_start());
6322 s = scan_str(s,!!PL_madskills,FALSE);
6325 readpipe_override();
6326 TERM(sublex_start());
6334 s = force_version(s, FALSE);
6336 else if (*s != 'v' || !isDIGIT(s[1])
6337 || (s = force_version(s, TRUE), *s == 'v'))
6339 *PL_tokenbuf = '\0';
6340 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6341 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6342 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6344 yyerror("<> should be quotes");
6346 if (orig_keyword == KEY_require) {
6354 PL_last_uni = PL_oldbufptr;
6355 PL_last_lop_op = OP_REQUIRE;
6357 return REPORT( (int)REQUIRE );
6363 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6367 LOP(OP_RENAME,XTERM);
6376 LOP(OP_RINDEX,XTERM);
6386 UNIDOR(OP_READLINE);
6399 LOP(OP_REVERSE,XTERM);
6402 UNIDOR(OP_READLINK);
6410 TERM(sublex_start());
6412 TOKEN(1); /* force error */
6415 checkcomma(s,PL_tokenbuf,"filehandle");
6425 LOP(OP_SELECT,XTERM);
6431 LOP(OP_SEMCTL,XTERM);
6434 LOP(OP_SEMGET,XTERM);
6437 LOP(OP_SEMOP,XTERM);
6443 LOP(OP_SETPGRP,XTERM);
6445 case KEY_setpriority:
6446 LOP(OP_SETPRIORITY,XTERM);
6448 case KEY_sethostent:
6454 case KEY_setservent:
6457 case KEY_setprotoent:
6467 LOP(OP_SEEKDIR,XTERM);
6469 case KEY_setsockopt:
6470 LOP(OP_SSOCKOPT,XTERM);
6476 LOP(OP_SHMCTL,XTERM);
6479 LOP(OP_SHMGET,XTERM);
6482 LOP(OP_SHMREAD,XTERM);
6485 LOP(OP_SHMWRITE,XTERM);
6488 LOP(OP_SHUTDOWN,XTERM);
6497 LOP(OP_SOCKET,XTERM);
6499 case KEY_socketpair:
6500 LOP(OP_SOCKPAIR,XTERM);
6503 checkcomma(s,PL_tokenbuf,"subroutine name");
6505 if (*s == ';' || *s == ')') /* probably a close */
6506 Perl_croak(aTHX_ "sort is now a reserved word");
6508 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6512 LOP(OP_SPLIT,XTERM);
6515 LOP(OP_SPRINTF,XTERM);
6518 LOP(OP_SPLICE,XTERM);
6533 LOP(OP_SUBSTR,XTERM);
6539 char tmpbuf[sizeof PL_tokenbuf];
6540 SSize_t tboffset = 0;
6541 expectation attrful;
6542 bool have_name, have_proto;
6543 const int key = tmp;
6548 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6549 SV *subtoken = newSVpvn(tstart, s - tstart);
6553 s = SKIPSPACE2(s,tmpwhite);
6558 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6559 (*s == ':' && s[1] == ':'))
6566 attrful = XATTRBLOCK;
6567 /* remember buffer pos'n for later force_word */
6568 tboffset = s - PL_oldbufptr;
6569 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6572 nametoke = newSVpvn(s, d - s);
6574 if (strchr(tmpbuf, ':'))
6575 sv_setpv(PL_subname, tmpbuf);
6577 sv_setsv(PL_subname,PL_curstname);
6578 sv_catpvs(PL_subname,"::");
6579 sv_catpvn(PL_subname,tmpbuf,len);
6586 CURMAD('X', nametoke);
6587 CURMAD('_', tmpwhite);
6588 (void) force_word(PL_oldbufptr + tboffset, WORD,
6591 s = SKIPSPACE2(d,tmpwhite);
6598 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6599 PL_expect = XTERMBLOCK;
6600 attrful = XATTRTERM;
6601 sv_setpvn(PL_subname,"?",1);
6605 if (key == KEY_format) {
6607 PL_lex_formbrack = PL_lex_brackets + 1;
6609 PL_thistoken = subtoken;
6613 (void) force_word(PL_oldbufptr + tboffset, WORD,
6619 /* Look for a prototype */
6622 bool bad_proto = FALSE;
6623 const bool warnsyntax = ckWARN(WARN_SYNTAX);
6625 s = scan_str(s,!!PL_madskills,FALSE);
6627 Perl_croak(aTHX_ "Prototype not terminated");
6628 /* strip spaces and check for bad characters */
6629 d = SvPVX(PL_lex_stuff);
6631 for (p = d; *p; ++p) {
6634 if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
6640 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6641 "Illegal character in prototype for %"SVf" : %s",
6642 (void*)PL_subname, d);
6643 SvCUR_set(PL_lex_stuff, tmp);
6648 CURMAD('q', PL_thisopen);
6649 CURMAD('_', tmpwhite);
6650 CURMAD('=', PL_thisstuff);
6651 CURMAD('Q', PL_thisclose);
6652 NEXTVAL_NEXTTOKE.opval =
6653 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6654 PL_lex_stuff = Nullsv;
6657 s = SKIPSPACE2(s,tmpwhite);
6665 if (*s == ':' && s[1] != ':')
6666 PL_expect = attrful;
6667 else if (*s != '{' && key == KEY_sub) {
6669 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6671 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, (void*)PL_subname);
6678 curmad('^', newSVpvs(""));
6679 CURMAD('_', tmpwhite);
6683 PL_thistoken = subtoken;
6686 NEXTVAL_NEXTTOKE.opval =
6687 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6688 PL_lex_stuff = NULL;
6693 sv_setpv(PL_subname,
6695 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
6699 (void) force_word(PL_oldbufptr + tboffset, WORD,
6709 LOP(OP_SYSTEM,XREF);
6712 LOP(OP_SYMLINK,XTERM);
6715 LOP(OP_SYSCALL,XTERM);
6718 LOP(OP_SYSOPEN,XTERM);
6721 LOP(OP_SYSSEEK,XTERM);
6724 LOP(OP_SYSREAD,XTERM);
6727 LOP(OP_SYSWRITE,XTERM);
6731 TERM(sublex_start());
6752 LOP(OP_TRUNCATE,XTERM);
6764 yylval.ival = CopLINE(PL_curcop);
6768 yylval.ival = CopLINE(PL_curcop);
6772 LOP(OP_UNLINK,XTERM);
6778 LOP(OP_UNPACK,XTERM);
6781 LOP(OP_UTIME,XTERM);
6787 LOP(OP_UNSHIFT,XTERM);
6790 s = tokenize_use(1, s);
6800 yylval.ival = CopLINE(PL_curcop);
6804 yylval.ival = CopLINE(PL_curcop);
6808 PL_hints |= HINT_BLOCK_SCOPE;
6815 LOP(OP_WAITPID,XTERM);
6824 ctl_l[0] = toCTRL('L');
6826 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6829 /* Make sure $^L is defined */
6830 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6835 if (PL_expect == XOPERATOR)
6841 yylval.ival = OP_XOR;
6846 TERM(sublex_start());
6851 #pragma segment Main
6855 S_pending_ident(pTHX)
6860 /* pit holds the identifier we read and pending_ident is reset */
6861 char pit = PL_pending_ident;
6862 PL_pending_ident = 0;
6864 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6865 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6866 "### Pending identifier '%s'\n", PL_tokenbuf); });
6868 /* if we're in a my(), we can't allow dynamics here.
6869 $foo'bar has already been turned into $foo::bar, so
6870 just check for colons.
6872 if it's a legal name, the OP is a PADANY.
6875 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6876 if (strchr(PL_tokenbuf,':'))
6877 yyerror(Perl_form(aTHX_ "No package name allowed for "
6878 "variable %s in \"our\"",
6880 tmp = allocmy(PL_tokenbuf);
6883 if (strchr(PL_tokenbuf,':'))
6884 yyerror(Perl_form(aTHX_ PL_no_myglob,
6885 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6887 yylval.opval = newOP(OP_PADANY, 0);
6888 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6894 build the ops for accesses to a my() variable.
6896 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6897 then used in a comparison. This catches most, but not
6898 all cases. For instance, it catches
6899 sort { my($a); $a <=> $b }
6901 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6902 (although why you'd do that is anyone's guess).
6905 if (!strchr(PL_tokenbuf,':')) {
6907 tmp = pad_findmy(PL_tokenbuf);
6908 if (tmp != NOT_IN_PAD) {
6909 /* might be an "our" variable" */
6910 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6911 /* build ops for a bareword */
6912 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6913 HEK * const stashname = HvNAME_HEK(stash);
6914 SV * const sym = newSVhek(stashname);
6915 sv_catpvs(sym, "::");
6916 sv_catpv(sym, PL_tokenbuf+1);
6917 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6918 yylval.opval->op_private = OPpCONST_ENTERED;
6921 ? (GV_ADDMULTI | GV_ADDINEVAL)
6924 ((PL_tokenbuf[0] == '$') ? SVt_PV
6925 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6930 /* if it's a sort block and they're naming $a or $b */
6931 if (PL_last_lop_op == OP_SORT &&
6932 PL_tokenbuf[0] == '$' &&
6933 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6936 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6937 d < PL_bufend && *d != '\n';
6940 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6941 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6947 yylval.opval = newOP(OP_PADANY, 0);
6948 yylval.opval->op_targ = tmp;
6954 Whine if they've said @foo in a doublequoted string,
6955 and @foo isn't a variable we can find in the symbol
6958 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6959 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6960 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6961 && ckWARN(WARN_AMBIGUOUS))
6963 /* Downgraded from fatal to warning 20000522 mjd */
6964 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6965 "Possible unintended interpolation of %s in string",
6970 /* build ops for a bareword */
6971 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6972 yylval.opval->op_private = OPpCONST_ENTERED;
6975 /* If the identifier refers to a stash, don't autovivify it.
6976 * Change 24660 had the side effect of causing symbol table
6977 * hashes to always be defined, even if they were freshly
6978 * created and the only reference in the entire program was
6979 * the single statement with the defined %foo::bar:: test.
6980 * It appears that all code in the wild doing this actually
6981 * wants to know whether sub-packages have been loaded, so
6982 * by avoiding auto-vivifying symbol tables, we ensure that
6983 * defined %foo::bar:: continues to be false, and the existing
6984 * tests still give the expected answers, even though what
6985 * they're actually testing has now changed subtly.
6987 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6989 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
6990 ((PL_tokenbuf[0] == '$') ? SVt_PV
6991 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6997 * The following code was generated by perl_keyword.pl.
7001 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
7006 case 1: /* 5 tokens of length 1 */
7038 case 2: /* 18 tokens of length 2 */
7184 case 3: /* 29 tokens of length 3 */
7188 if (name[1] == 'N' &&
7251 if (name[1] == 'i' &&
7273 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7291 if (name[1] == 'o' &&
7300 if (name[1] == 'e' &&
7309 if (name[1] == 'n' &&
7318 if (name[1] == 'o' &&
7327 if (name[1] == 'a' &&
7336 if (name[1] == 'o' &&
7398 if (name[1] == 'e' &&
7412 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
7438 if (name[1] == 'i' &&
7447 if (name[1] == 's' &&
7456 if (name[1] == 'e' &&
7465 if (name[1] == 'o' &&
7477 case 4: /* 41 tokens of length 4 */
7481 if (name[1] == 'O' &&
7491 if (name[1] == 'N' &&
7501 if (name[1] == 'i' &&
7511 if (name[1] == 'h' &&
7521 if (name[1] == 'u' &&
7534 if (name[2] == 'c' &&
7543 if (name[2] == 's' &&
7552 if (name[2] == 'a' &&
7588 if (name[1] == 'o' &&
7601 if (name[2] == 't' &&
7610 if (name[2] == 'o' &&
7619 if (name[2] == 't' &&
7628 if (name[2] == 'e' &&
7641 if (name[1] == 'o' &&
7654 if (name[2] == 'y' &&
7663 if (name[2] == 'l' &&
7679 if (name[2] == 's' &&
7688 if (name[2] == 'n' &&
7697 if (name[2] == 'c' &&
7710 if (name[1] == 'e' &&
7720 if (name[1] == 'p' &&
7733 if (name[2] == 'c' &&
7742 if (name[2] == 'p' &&
7751 if (name[2] == 's' &&
7767 if (name[2] == 'n' &&
7837 if (name[2] == 'r' &&
7846 if (name[2] == 'r' &&
7855 if (name[2] == 'a' &&
7871 if (name[2] == 'l' &&
7933 if (name[2] == 'e' &&
7936 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7949 case 5: /* 39 tokens of length 5 */
7953 if (name[1] == 'E' &&
7964 if (name[1] == 'H' &&
7978 if (name[2] == 'a' &&
7988 if (name[2] == 'a' &&
8005 if (name[2] == 'e' &&
8015 if (name[2] == 'e' &&
8019 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
8035 if (name[3] == 'i' &&
8044 if (name[3] == 'o' &&
8080 if (name[2] == 'o' &&
8090 if (name[2] == 'y' &&
8104 if (name[1] == 'l' &&
8118 if (name[2] == 'n' &&
8128 if (name[2] == 'o' &&
8142 if (name[1] == 'i' &&
8147 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8156 if (name[2] == 'd' &&
8166 if (name[2] == 'c' &&
8183 if (name[2] == 'c' &&
8193 if (name[2] == 't' &&
8207 if (name[1] == 'k' &&
8218 if (name[1] == 'r' &&
8232 if (name[2] == 's' &&
8242 if (name[2] == 'd' &&
8259 if (name[2] == 'm' &&
8269 if (name[2] == 'i' &&
8279 if (name[2] == 'e' &&
8289 if (name[2] == 'l' &&
8299 if (name[2] == 'a' &&
8312 if (name[3] == 't' &&
8315 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8321 if (name[3] == 'd' &&
8338 if (name[1] == 'i' &&
8352 if (name[2] == 'a' &&
8365 if (name[3] == 'e' &&
8400 if (name[2] == 'i' &&
8417 if (name[2] == 'i' &&
8427 if (name[2] == 'i' &&
8444 case 6: /* 33 tokens of length 6 */
8448 if (name[1] == 'c' &&
8463 if (name[2] == 'l' &&
8474 if (name[2] == 'r' &&
8489 if (name[1] == 'e' &&
8504 if (name[2] == 's' &&
8509 if(ckWARN_d(WARN_SYNTAX))
8510 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8516 if (name[2] == 'i' &&
8534 if (name[2] == 'l' &&
8545 if (name[2] == 'r' &&
8560 if (name[1] == 'm' &&
8575 if (name[2] == 'n' &&
8586 if (name[2] == 's' &&
8601 if (name[1] == 's' &&
8607 if (name[4] == 't' &&
8616 if (name[4] == 'e' &&
8625 if (name[4] == 'c' &&
8634 if (name[4] == 'n' &&
8650 if (name[1] == 'r' &&
8668 if (name[3] == 'a' &&
8678 if (name[3] == 'u' &&
8692 if (name[2] == 'n' &&
8710 if (name[2] == 'a' &&
8724 if (name[3] == 'e' &&
8737 if (name[4] == 't' &&
8746 if (name[4] == 'e' &&
8768 if (name[4] == 't' &&
8777 if (name[4] == 'e' &&
8793 if (name[2] == 'c' &&
8804 if (name[2] == 'l' &&
8815 if (name[2] == 'b' &&
8826 if (name[2] == 's' &&
8849 if (name[4] == 's' &&
8858 if (name[4] == 'n' &&
8871 if (name[3] == 'a' &&
8888 if (name[1] == 'a' &&
8903 case 7: /* 29 tokens of length 7 */
8907 if (name[1] == 'E' &&
8920 if (name[1] == '_' &&
8933 if (name[1] == 'i' &&
8940 return -KEY_binmode;
8946 if (name[1] == 'o' &&
8953 return -KEY_connect;
8962 if (name[2] == 'm' &&
8968 return -KEY_dbmopen;
8979 if (name[4] == 'u' &&
8983 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
8989 if (name[4] == 'n' &&
9010 if (name[1] == 'o' &&
9023 if (name[1] == 'e' &&
9030 if (name[5] == 'r' &&
9033 return -KEY_getpgrp;
9039 if (name[5] == 'i' &&
9042 return -KEY_getppid;
9055 if (name[1] == 'c' &&
9062 return -KEY_lcfirst;
9068 if (name[1] == 'p' &&
9075 return -KEY_opendir;
9081 if (name[1] == 'a' &&
9099 if (name[3] == 'd' &&
9104 return -KEY_readdir;
9110 if (name[3] == 'u' &&
9121 if (name[3] == 'e' &&
9126 return -KEY_reverse;
9145 if (name[3] == 'k' &&
9150 return -KEY_seekdir;
9156 if (name[3] == 'p' &&
9161 return -KEY_setpgrp;
9171 if (name[2] == 'm' &&
9177 return -KEY_shmread;
9183 if (name[2] == 'r' &&
9189 return -KEY_sprintf;
9198 if (name[3] == 'l' &&
9203 return -KEY_symlink;
9212 if (name[4] == 'a' &&
9216 return -KEY_syscall;
9222 if (name[4] == 'p' &&
9226 return -KEY_sysopen;
9232 if (name[4] == 'e' &&
9236 return -KEY_sysread;
9242 if (name[4] == 'e' &&
9246 return -KEY_sysseek;
9264 if (name[1] == 'e' &&
9271 return -KEY_telldir;
9280 if (name[2] == 'f' &&
9286 return -KEY_ucfirst;
9292 if (name[2] == 's' &&
9298 return -KEY_unshift;
9308 if (name[1] == 'a' &&
9315 return -KEY_waitpid;
9324 case 8: /* 26 tokens of length 8 */
9328 if (name[1] == 'U' &&
9336 return KEY_AUTOLOAD;
9347 if (name[3] == 'A' &&
9353 return KEY___DATA__;
9359 if (name[3] == 'I' &&
9365 return -KEY___FILE__;
9371 if (name[3] == 'I' &&
9377 return -KEY___LINE__;
9393 if (name[2] == 'o' &&
9400 return -KEY_closedir;
9406 if (name[2] == 'n' &&
9413 return -KEY_continue;
9423 if (name[1] == 'b' &&
9431 return -KEY_dbmclose;
9437 if (name[1] == 'n' &&
9443 if (name[4] == 'r' &&
9448 return -KEY_endgrent;
9454 if (name[4] == 'w' &&
9459 return -KEY_endpwent;
9472 if (name[1] == 'o' &&
9480 return -KEY_formline;
9486 if (name[1] == 'e' &&
9497 if (name[6] == 'n' &&
9500 return -KEY_getgrent;
9506 if (name[6] == 'i' &&
9509 return -KEY_getgrgid;
9515 if (name[6] == 'a' &&
9518 return -KEY_getgrnam;
9531 if (name[4] == 'o' &&
9536 return -KEY_getlogin;
9547 if (name[6] == 'n' &&
9550 return -KEY_getpwent;
9556 if (name[6] == 'a' &&
9559 return -KEY_getpwnam;
9565 if (name[6] == 'i' &&
9568 return -KEY_getpwuid;
9588 if (name[1] == 'e' &&
9595 if (name[5] == 'i' &&
9602 return -KEY_readline;
9607 return -KEY_readlink;
9618 if (name[5] == 'i' &&
9622 return -KEY_readpipe;
9643 if (name[4] == 'r' &&
9648 return -KEY_setgrent;
9654 if (name[4] == 'w' &&
9659 return -KEY_setpwent;
9675 if (name[3] == 'w' &&
9681 return -KEY_shmwrite;
9687 if (name[3] == 't' &&
9693 return -KEY_shutdown;
9703 if (name[2] == 's' &&
9710 return -KEY_syswrite;
9720 if (name[1] == 'r' &&
9728 return -KEY_truncate;
9737 case 9: /* 9 tokens of length 9 */
9741 if (name[1] == 'N' &&
9750 return KEY_UNITCHECK;
9756 if (name[1] == 'n' &&
9765 return -KEY_endnetent;
9771 if (name[1] == 'e' &&
9780 return -KEY_getnetent;
9786 if (name[1] == 'o' &&
9795 return -KEY_localtime;
9801 if (name[1] == 'r' &&
9810 return KEY_prototype;
9816 if (name[1] == 'u' &&
9825 return -KEY_quotemeta;
9831 if (name[1] == 'e' &&
9840 return -KEY_rewinddir;
9846 if (name[1] == 'e' &&
9855 return -KEY_setnetent;
9861 if (name[1] == 'a' &&
9870 return -KEY_wantarray;
9879 case 10: /* 9 tokens of length 10 */
9883 if (name[1] == 'n' &&
9889 if (name[4] == 'o' &&
9896 return -KEY_endhostent;
9902 if (name[4] == 'e' &&
9909 return -KEY_endservent;
9922 if (name[1] == 'e' &&
9928 if (name[4] == 'o' &&
9935 return -KEY_gethostent;
9944 if (name[5] == 'r' &&
9950 return -KEY_getservent;
9956 if (name[5] == 'c' &&
9962 return -KEY_getsockopt;
9987 if (name[4] == 'o' &&
9994 return -KEY_sethostent;
10003 if (name[5] == 'r' &&
10009 return -KEY_setservent;
10015 if (name[5] == 'c' &&
10021 return -KEY_setsockopt;
10038 if (name[2] == 'c' &&
10047 return -KEY_socketpair;
10060 case 11: /* 8 tokens of length 11 */
10064 if (name[1] == '_' &&
10074 { /* __PACKAGE__ */
10075 return -KEY___PACKAGE__;
10081 if (name[1] == 'n' &&
10091 { /* endprotoent */
10092 return -KEY_endprotoent;
10098 if (name[1] == 'e' &&
10107 if (name[5] == 'e' &&
10113 { /* getpeername */
10114 return -KEY_getpeername;
10123 if (name[6] == 'o' &&
10128 { /* getpriority */
10129 return -KEY_getpriority;
10135 if (name[6] == 't' &&
10140 { /* getprotoent */
10141 return -KEY_getprotoent;
10155 if (name[4] == 'o' &&
10162 { /* getsockname */
10163 return -KEY_getsockname;
10176 if (name[1] == 'e' &&
10184 if (name[6] == 'o' &&
10189 { /* setpriority */
10190 return -KEY_setpriority;
10196 if (name[6] == 't' &&
10201 { /* setprotoent */
10202 return -KEY_setprotoent;
10218 case 12: /* 2 tokens of length 12 */
10219 if (name[0] == 'g' &&
10231 if (name[9] == 'd' &&
10234 { /* getnetbyaddr */
10235 return -KEY_getnetbyaddr;
10241 if (name[9] == 'a' &&
10244 { /* getnetbyname */
10245 return -KEY_getnetbyname;
10257 case 13: /* 4 tokens of length 13 */
10258 if (name[0] == 'g' &&
10265 if (name[4] == 'o' &&
10274 if (name[10] == 'd' &&
10277 { /* gethostbyaddr */
10278 return -KEY_gethostbyaddr;
10284 if (name[10] == 'a' &&
10287 { /* gethostbyname */
10288 return -KEY_gethostbyname;
10301 if (name[4] == 'e' &&
10310 if (name[10] == 'a' &&
10313 { /* getservbyname */
10314 return -KEY_getservbyname;
10320 if (name[10] == 'o' &&
10323 { /* getservbyport */
10324 return -KEY_getservbyport;
10343 case 14: /* 1 tokens of length 14 */
10344 if (name[0] == 'g' &&
10358 { /* getprotobyname */
10359 return -KEY_getprotobyname;
10364 case 16: /* 1 tokens of length 16 */
10365 if (name[0] == 'g' &&
10381 { /* getprotobynumber */
10382 return -KEY_getprotobynumber;
10396 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10400 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10401 if (ckWARN(WARN_SYNTAX)) {
10404 for (w = s+2; *w && level; w++) {
10407 else if (*w == ')')
10410 while (isSPACE(*w))
10412 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
10413 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10414 "%s (...) interpreted as function",name);
10417 while (s < PL_bufend && isSPACE(*s))
10421 while (s < PL_bufend && isSPACE(*s))
10423 if (isIDFIRST_lazy_if(s,UTF)) {
10424 const char * const w = s++;
10425 while (isALNUM_lazy_if(s,UTF))
10427 while (s < PL_bufend && isSPACE(*s))
10431 if (keyword(w, s - w, 0))
10434 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10435 if (gv && GvCVu(gv))
10437 Perl_croak(aTHX_ "No comma allowed after %s", what);
10442 /* Either returns sv, or mortalizes sv and returns a new SV*.
10443 Best used as sv=new_constant(..., sv, ...).
10444 If s, pv are NULL, calls subroutine with one argument,
10445 and type is used with error messages only. */
10448 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10452 HV * const table = GvHV(PL_hintgv); /* ^H */
10456 const char *why1 = "", *why2 = "", *why3 = "";
10458 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10461 why2 = (const char *)
10462 (strEQ(key,"charnames")
10463 ? "(possibly a missing \"use charnames ...\")"
10465 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10466 (type ? type: "undef"), why2);
10468 /* This is convoluted and evil ("goto considered harmful")
10469 * but I do not understand the intricacies of all the different
10470 * failure modes of %^H in here. The goal here is to make
10471 * the most probable error message user-friendly. --jhi */
10476 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10477 (type ? type: "undef"), why1, why2, why3);
10479 yyerror(SvPVX_const(msg));
10483 cvp = hv_fetch(table, key, strlen(key), FALSE);
10484 if (!cvp || !SvOK(*cvp)) {
10487 why3 = "} is not defined";
10490 sv_2mortal(sv); /* Parent created it permanently */
10493 pv = sv_2mortal(newSVpvn(s, len));
10495 typesv = sv_2mortal(newSVpv(type, 0));
10497 typesv = &PL_sv_undef;
10499 PUSHSTACKi(PERLSI_OVERLOAD);
10511 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10515 /* Check the eval first */
10516 if (!PL_in_eval && SvTRUE(ERRSV)) {
10517 sv_catpvs(ERRSV, "Propagated");
10518 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10520 res = SvREFCNT_inc_simple(sv);
10524 SvREFCNT_inc_simple_void(res);
10533 why1 = "Call to &{$^H{";
10535 why3 = "}} did not return a defined value";
10543 /* Returns a NUL terminated string, with the length of the string written to
10547 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10550 register char *d = dest;
10551 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10554 Perl_croak(aTHX_ ident_too_long);
10555 if (isALNUM(*s)) /* UTF handled below */
10557 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10562 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10566 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10567 char *t = s + UTF8SKIP(s);
10569 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10573 Perl_croak(aTHX_ ident_too_long);
10574 Copy(s, d, len, char);
10587 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10590 char *bracket = NULL;
10592 register char *d = dest;
10593 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10598 while (isDIGIT(*s)) {
10600 Perl_croak(aTHX_ ident_too_long);
10607 Perl_croak(aTHX_ ident_too_long);
10608 if (isALNUM(*s)) /* UTF handled below */
10610 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10615 else if (*s == ':' && s[1] == ':') {
10619 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10620 char *t = s + UTF8SKIP(s);
10621 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10623 if (d + (t - s) > e)
10624 Perl_croak(aTHX_ ident_too_long);
10625 Copy(s, d, t - s, char);
10636 if (PL_lex_state != LEX_NORMAL)
10637 PL_lex_state = LEX_INTERPENDMAYBE;
10640 if (*s == '$' && s[1] &&
10641 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10654 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10659 if (isSPACE(s[-1])) {
10661 const char ch = *s++;
10662 if (!SPACE_OR_TAB(ch)) {
10668 if (isIDFIRST_lazy_if(d,UTF)) {
10672 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10673 end += UTF8SKIP(end);
10674 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10675 end += UTF8SKIP(end);
10677 Copy(s, d, end - s, char);
10682 while ((isALNUM(*s) || *s == ':') && d < e)
10685 Perl_croak(aTHX_ ident_too_long);
10688 while (s < send && SPACE_OR_TAB(*s))
10690 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10691 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10692 const char * const brack =
10694 ((*s == '[') ? "[...]" : "{...}");
10695 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10696 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10697 funny, dest, brack, funny, dest, brack);
10700 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10704 /* Handle extended ${^Foo} variables
10705 * 1999-02-27 mjd-perl-patch@plover.com */
10706 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10710 while (isALNUM(*s) && d < e) {
10714 Perl_croak(aTHX_ ident_too_long);
10719 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10720 PL_lex_state = LEX_INTERPEND;
10723 if (PL_lex_state == LEX_NORMAL) {
10724 if (ckWARN(WARN_AMBIGUOUS) &&
10725 (keyword(dest, d - dest, 0) || get_cv(dest, FALSE)))
10729 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10730 "Ambiguous use of %c{%s} resolved to %c%s",
10731 funny, dest, funny, dest);
10736 s = bracket; /* let the parser handle it */
10740 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10741 PL_lex_state = LEX_INTERPEND;
10746 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10748 PERL_UNUSED_CONTEXT;
10751 else if (ch == 'g')
10752 *pmfl |= PMf_GLOBAL;
10753 else if (ch == 'c')
10754 *pmfl |= PMf_CONTINUE;
10755 else if (ch == 'o')
10757 else if (ch == 'm')
10758 *pmfl |= PMf_MULTILINE;
10759 else if (ch == 's')
10760 *pmfl |= PMf_SINGLELINE;
10761 else if (ch == 'x')
10762 *pmfl |= PMf_EXTENDED;
10766 S_scan_pat(pTHX_ char *start, I32 type)
10770 char *s = scan_str(start,!!PL_madskills,FALSE);
10771 const char * const valid_flags =
10772 (const char *)((type == OP_QR) ? "iomsx" : "iogcmsx");
10779 const char * const delimiter = skipspace(start);
10783 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10784 : "Search pattern not terminated" ));
10787 pm = (PMOP*)newPMOP(type, 0);
10788 if (PL_multi_open == '?')
10789 pm->op_pmflags |= PMf_ONCE;
10793 while (*s && strchr(valid_flags, *s))
10794 pmflag(&pm->op_pmflags,*s++);
10796 if (PL_madskills && modstart != s) {
10797 SV* tmptoken = newSVpvn(modstart, s - modstart);
10798 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10801 /* issue a warning if /c is specified,but /g is not */
10802 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10803 && ckWARN(WARN_REGEXP))
10805 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
10808 pm->op_pmpermflags = pm->op_pmflags;
10810 PL_lex_op = (OP*)pm;
10811 yylval.ival = OP_MATCH;
10816 S_scan_subst(pTHX_ char *start)
10827 yylval.ival = OP_NULL;
10829 s = scan_str(start,!!PL_madskills,FALSE);
10832 Perl_croak(aTHX_ "Substitution pattern not terminated");
10834 if (s[-1] == PL_multi_open)
10837 if (PL_madskills) {
10838 CURMAD('q', PL_thisopen);
10839 CURMAD('_', PL_thiswhite);
10840 CURMAD('E', PL_thisstuff);
10841 CURMAD('Q', PL_thisclose);
10842 PL_realtokenstart = s - SvPVX(PL_linestr);
10846 first_start = PL_multi_start;
10847 s = scan_str(s,!!PL_madskills,FALSE);
10849 if (PL_lex_stuff) {
10850 SvREFCNT_dec(PL_lex_stuff);
10851 PL_lex_stuff = NULL;
10853 Perl_croak(aTHX_ "Substitution replacement not terminated");
10855 PL_multi_start = first_start; /* so whole substitution is taken together */
10857 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10860 if (PL_madskills) {
10861 CURMAD('z', PL_thisopen);
10862 CURMAD('R', PL_thisstuff);
10863 CURMAD('Z', PL_thisclose);
10873 else if (strchr("iogcmsx", *s))
10874 pmflag(&pm->op_pmflags,*s++);
10880 if (PL_madskills) {
10882 curmad('m', newSVpvn(modstart, s - modstart));
10883 append_madprops(PL_thismad, (OP*)pm, 0);
10887 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10888 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10892 SV * const repl = newSVpvs("");
10894 PL_sublex_info.super_bufptr = s;
10895 PL_sublex_info.super_bufend = PL_bufend;
10897 pm->op_pmflags |= PMf_EVAL;
10899 sv_catpv(repl, (const char *)(es ? "eval " : "do "));
10900 sv_catpvs(repl, "{");
10901 sv_catsv(repl, PL_lex_repl);
10902 if (strchr(SvPVX(PL_lex_repl), '#'))
10903 sv_catpvs(repl, "\n");
10904 sv_catpvs(repl, "}");
10906 SvREFCNT_dec(PL_lex_repl);
10907 PL_lex_repl = repl;
10910 pm->op_pmpermflags = pm->op_pmflags;
10911 PL_lex_op = (OP*)pm;
10912 yylval.ival = OP_SUBST;
10917 S_scan_trans(pTHX_ char *start)
10930 yylval.ival = OP_NULL;
10932 s = scan_str(start,!!PL_madskills,FALSE);
10934 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10936 if (s[-1] == PL_multi_open)
10939 if (PL_madskills) {
10940 CURMAD('q', PL_thisopen);
10941 CURMAD('_', PL_thiswhite);
10942 CURMAD('E', PL_thisstuff);
10943 CURMAD('Q', PL_thisclose);
10944 PL_realtokenstart = s - SvPVX(PL_linestr);
10948 s = scan_str(s,!!PL_madskills,FALSE);
10950 if (PL_lex_stuff) {
10951 SvREFCNT_dec(PL_lex_stuff);
10952 PL_lex_stuff = NULL;
10954 Perl_croak(aTHX_ "Transliteration replacement not terminated");
10956 if (PL_madskills) {
10957 CURMAD('z', PL_thisopen);
10958 CURMAD('R', PL_thisstuff);
10959 CURMAD('Z', PL_thisclose);
10962 complement = del = squash = 0;
10969 complement = OPpTRANS_COMPLEMENT;
10972 del = OPpTRANS_DELETE;
10975 squash = OPpTRANS_SQUASH;
10984 Newx(tbl, complement&&!del?258:256, short);
10985 o = newPVOP(OP_TRANS, 0, (char*)tbl);
10986 o->op_private &= ~OPpTRANS_ALL;
10987 o->op_private |= del|squash|complement|
10988 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10989 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
10992 yylval.ival = OP_TRANS;
10995 if (PL_madskills) {
10997 curmad('m', newSVpvn(modstart, s - modstart));
10998 append_madprops(PL_thismad, o, 0);
11007 S_scan_heredoc(pTHX_ register char *s)
11011 I32 op_type = OP_SCALAR;
11015 const char *found_newline;
11019 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
11021 I32 stuffstart = s - SvPVX(PL_linestr);
11024 PL_realtokenstart = -1;
11029 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
11033 while (SPACE_OR_TAB(*peek))
11035 if (*peek == '`' || *peek == '\'' || *peek =='"') {
11038 s = delimcpy(d, e, s, PL_bufend, term, &len);
11048 if (!isALNUM_lazy_if(s,UTF))
11049 deprecate_old("bare << to mean <<\"\"");
11050 for (; isALNUM_lazy_if(s,UTF); s++) {
11055 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
11056 Perl_croak(aTHX_ "Delimiter for here document is too long");
11059 len = d - PL_tokenbuf;
11062 if (PL_madskills) {
11063 tstart = PL_tokenbuf + !outer;
11064 PL_thisclose = newSVpvn(tstart, len - !outer);
11065 tstart = SvPVX(PL_linestr) + stuffstart;
11066 PL_thisopen = newSVpvn(tstart, s - tstart);
11067 stuffstart = s - SvPVX(PL_linestr);
11070 #ifndef PERL_STRICT_CR
11071 d = strchr(s, '\r');
11073 char * const olds = s;
11075 while (s < PL_bufend) {
11081 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11090 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11097 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11098 herewas = newSVpvn(s,PL_bufend-s);
11102 herewas = newSVpvn(s-1,found_newline-s+1);
11105 herewas = newSVpvn(s,found_newline-s);
11109 if (PL_madskills) {
11110 tstart = SvPVX(PL_linestr) + stuffstart;
11112 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11114 PL_thisstuff = newSVpvn(tstart, s - tstart);
11117 s += SvCUR(herewas);
11120 stuffstart = s - SvPVX(PL_linestr);
11126 tmpstr = newSV(79);
11127 sv_upgrade(tmpstr, SVt_PVIV);
11128 if (term == '\'') {
11129 op_type = OP_CONST;
11130 SvIV_set(tmpstr, -1);
11132 else if (term == '`') {
11133 op_type = OP_BACKTICK;
11134 SvIV_set(tmpstr, '\\');
11138 PL_multi_start = CopLINE(PL_curcop);
11139 PL_multi_open = PL_multi_close = '<';
11140 term = *PL_tokenbuf;
11141 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11142 char * const bufptr = PL_sublex_info.super_bufptr;
11143 char * const bufend = PL_sublex_info.super_bufend;
11144 char * const olds = s - SvCUR(herewas);
11145 s = strchr(bufptr, '\n');
11149 while (s < bufend &&
11150 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11152 CopLINE_inc(PL_curcop);
11155 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11156 missingterm(PL_tokenbuf);
11158 sv_setpvn(herewas,bufptr,d-bufptr+1);
11159 sv_setpvn(tmpstr,d+1,s-d);
11161 sv_catpvn(herewas,s,bufend-s);
11162 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11169 while (s < PL_bufend &&
11170 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11172 CopLINE_inc(PL_curcop);
11174 if (s >= PL_bufend) {
11175 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11176 missingterm(PL_tokenbuf);
11178 sv_setpvn(tmpstr,d+1,s-d);
11180 if (PL_madskills) {
11182 sv_catpvn(PL_thisstuff, d + 1, s - d);
11184 PL_thisstuff = newSVpvn(d + 1, s - d);
11185 stuffstart = s - SvPVX(PL_linestr);
11189 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11191 sv_catpvn(herewas,s,PL_bufend-s);
11192 sv_setsv(PL_linestr,herewas);
11193 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11194 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11195 PL_last_lop = PL_last_uni = NULL;
11198 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11199 while (s >= PL_bufend) { /* multiple line string? */
11201 if (PL_madskills) {
11202 tstart = SvPVX(PL_linestr) + stuffstart;
11204 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11206 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11210 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11211 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11212 missingterm(PL_tokenbuf);
11215 stuffstart = s - SvPVX(PL_linestr);
11217 CopLINE_inc(PL_curcop);
11218 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11219 PL_last_lop = PL_last_uni = NULL;
11220 #ifndef PERL_STRICT_CR
11221 if (PL_bufend - PL_linestart >= 2) {
11222 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11223 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11225 PL_bufend[-2] = '\n';
11227 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11229 else if (PL_bufend[-1] == '\r')
11230 PL_bufend[-1] = '\n';
11232 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11233 PL_bufend[-1] = '\n';
11235 if (PERLDB_LINE && PL_curstash != PL_debstash)
11236 update_debugger_info_sv(PL_linestr);
11237 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11238 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11239 *(SvPVX(PL_linestr) + off ) = ' ';
11240 sv_catsv(PL_linestr,herewas);
11241 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11242 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11246 sv_catsv(tmpstr,PL_linestr);
11251 PL_multi_end = CopLINE(PL_curcop);
11252 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11253 SvPV_shrink_to_cur(tmpstr);
11255 SvREFCNT_dec(herewas);
11257 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11259 else if (PL_encoding)
11260 sv_recode_to_utf8(tmpstr, PL_encoding);
11262 PL_lex_stuff = tmpstr;
11263 yylval.ival = op_type;
11267 /* scan_inputsymbol
11268 takes: current position in input buffer
11269 returns: new position in input buffer
11270 side-effects: yylval and lex_op are set.
11275 <FH> read from filehandle
11276 <pkg::FH> read from package qualified filehandle
11277 <pkg'FH> read from package qualified filehandle
11278 <$fh> read from filehandle in $fh
11279 <*.h> filename glob
11284 S_scan_inputsymbol(pTHX_ char *start)
11287 register char *s = start; /* current position in buffer */
11291 char *d = PL_tokenbuf; /* start of temp holding space */
11292 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11294 end = strchr(s, '\n');
11297 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11299 /* die if we didn't have space for the contents of the <>,
11300 or if it didn't end, or if we see a newline
11303 if (len >= (I32)sizeof PL_tokenbuf)
11304 Perl_croak(aTHX_ "Excessively long <> operator");
11306 Perl_croak(aTHX_ "Unterminated <> operator");
11311 Remember, only scalar variables are interpreted as filehandles by
11312 this code. Anything more complex (e.g., <$fh{$num}>) will be
11313 treated as a glob() call.
11314 This code makes use of the fact that except for the $ at the front,
11315 a scalar variable and a filehandle look the same.
11317 if (*d == '$' && d[1]) d++;
11319 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11320 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11323 /* If we've tried to read what we allow filehandles to look like, and
11324 there's still text left, then it must be a glob() and not a getline.
11325 Use scan_str to pull out the stuff between the <> and treat it
11326 as nothing more than a string.
11329 if (d - PL_tokenbuf != len) {
11330 yylval.ival = OP_GLOB;
11332 s = scan_str(start,!!PL_madskills,FALSE);
11334 Perl_croak(aTHX_ "Glob not terminated");
11338 bool readline_overriden = FALSE;
11341 /* we're in a filehandle read situation */
11344 /* turn <> into <ARGV> */
11346 Copy("ARGV",d,5,char);
11348 /* Check whether readline() is overriden */
11349 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11351 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11353 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11354 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
11355 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11356 readline_overriden = TRUE;
11358 /* if <$fh>, create the ops to turn the variable into a
11362 /* try to find it in the pad for this block, otherwise find
11363 add symbol table ops
11365 const PADOFFSET tmp = pad_findmy(d);
11366 if (tmp != NOT_IN_PAD) {
11367 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11368 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11369 HEK * const stashname = HvNAME_HEK(stash);
11370 SV * const sym = sv_2mortal(newSVhek(stashname));
11371 sv_catpvs(sym, "::");
11372 sv_catpv(sym, d+1);
11377 OP * const o = newOP(OP_PADSV, 0);
11379 PL_lex_op = readline_overriden
11380 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11381 append_elem(OP_LIST, o,
11382 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11383 : (OP*)newUNOP(OP_READLINE, 0, o);
11392 ? (GV_ADDMULTI | GV_ADDINEVAL)
11395 PL_lex_op = readline_overriden
11396 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11397 append_elem(OP_LIST,
11398 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11399 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11400 : (OP*)newUNOP(OP_READLINE, 0,
11401 newUNOP(OP_RV2SV, 0,
11402 newGVOP(OP_GV, 0, gv)));
11404 if (!readline_overriden)
11405 PL_lex_op->op_flags |= OPf_SPECIAL;
11406 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11407 yylval.ival = OP_NULL;
11410 /* If it's none of the above, it must be a literal filehandle
11411 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11413 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11414 PL_lex_op = readline_overriden
11415 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11416 append_elem(OP_LIST,
11417 newGVOP(OP_GV, 0, gv),
11418 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11419 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11420 yylval.ival = OP_NULL;
11429 takes: start position in buffer
11430 keep_quoted preserve \ on the embedded delimiter(s)
11431 keep_delims preserve the delimiters around the string
11432 returns: position to continue reading from buffer
11433 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11434 updates the read buffer.
11436 This subroutine pulls a string out of the input. It is called for:
11437 q single quotes q(literal text)
11438 ' single quotes 'literal text'
11439 qq double quotes qq(interpolate $here please)
11440 " double quotes "interpolate $here please"
11441 qx backticks qx(/bin/ls -l)
11442 ` backticks `/bin/ls -l`
11443 qw quote words @EXPORT_OK = qw( func() $spam )
11444 m// regexp match m/this/
11445 s/// regexp substitute s/this/that/
11446 tr/// string transliterate tr/this/that/
11447 y/// string transliterate y/this/that/
11448 ($*@) sub prototypes sub foo ($)
11449 (stuff) sub attr parameters sub foo : attr(stuff)
11450 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11452 In most of these cases (all but <>, patterns and transliterate)
11453 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11454 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11455 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11458 It skips whitespace before the string starts, and treats the first
11459 character as the delimiter. If the delimiter is one of ([{< then
11460 the corresponding "close" character )]}> is used as the closing
11461 delimiter. It allows quoting of delimiters, and if the string has
11462 balanced delimiters ([{<>}]) it allows nesting.
11464 On success, the SV with the resulting string is put into lex_stuff or,
11465 if that is already non-NULL, into lex_repl. The second case occurs only
11466 when parsing the RHS of the special constructs s/// and tr/// (y///).
11467 For convenience, the terminating delimiter character is stuffed into
11472 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11475 SV *sv; /* scalar value: string */
11476 const char *tmps; /* temp string, used for delimiter matching */
11477 register char *s = start; /* current position in the buffer */
11478 register char term; /* terminating character */
11479 register char *to; /* current position in the sv's data */
11480 I32 brackets = 1; /* bracket nesting level */
11481 bool has_utf8 = FALSE; /* is there any utf8 content? */
11482 I32 termcode; /* terminating char. code */
11483 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11484 STRLEN termlen; /* length of terminating string */
11485 int last_off = 0; /* last position for nesting bracket */
11491 /* skip space before the delimiter */
11497 if (PL_realtokenstart >= 0) {
11498 stuffstart = PL_realtokenstart;
11499 PL_realtokenstart = -1;
11502 stuffstart = start - SvPVX(PL_linestr);
11504 /* mark where we are, in case we need to report errors */
11507 /* after skipping whitespace, the next character is the terminator */
11510 termcode = termstr[0] = term;
11514 termcode = utf8_to_uvchr((U8*)s, &termlen);
11515 Copy(s, termstr, termlen, U8);
11516 if (!UTF8_IS_INVARIANT(term))
11520 /* mark where we are */
11521 PL_multi_start = CopLINE(PL_curcop);
11522 PL_multi_open = term;
11524 /* find corresponding closing delimiter */
11525 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11526 termcode = termstr[0] = term = tmps[5];
11528 PL_multi_close = term;
11530 /* create a new SV to hold the contents. 79 is the SV's initial length.
11531 What a random number. */
11533 sv_upgrade(sv, SVt_PVIV);
11534 SvIV_set(sv, termcode);
11535 (void)SvPOK_only(sv); /* validate pointer */
11537 /* move past delimiter and try to read a complete string */
11539 sv_catpvn(sv, s, termlen);
11542 tstart = SvPVX(PL_linestr) + stuffstart;
11543 if (!PL_thisopen && !keep_delims) {
11544 PL_thisopen = newSVpvn(tstart, s - tstart);
11545 stuffstart = s - SvPVX(PL_linestr);
11549 if (PL_encoding && !UTF) {
11553 int offset = s - SvPVX_const(PL_linestr);
11554 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11555 &offset, (char*)termstr, termlen);
11556 const char * const ns = SvPVX_const(PL_linestr) + offset;
11557 char * const svlast = SvEND(sv) - 1;
11559 for (; s < ns; s++) {
11560 if (*s == '\n' && !PL_rsfp)
11561 CopLINE_inc(PL_curcop);
11564 goto read_more_line;
11566 /* handle quoted delimiters */
11567 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11569 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11571 if ((svlast-1 - t) % 2) {
11572 if (!keep_quoted) {
11573 *(svlast-1) = term;
11575 SvCUR_set(sv, SvCUR(sv) - 1);
11580 if (PL_multi_open == PL_multi_close) {
11586 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
11587 /* At here, all closes are "was quoted" one,
11588 so we don't check PL_multi_close. */
11590 if (!keep_quoted && *(t+1) == PL_multi_open)
11595 else if (*t == PL_multi_open)
11603 SvCUR_set(sv, w - SvPVX_const(sv));
11605 last_off = w - SvPVX(sv);
11606 if (--brackets <= 0)
11611 if (!keep_delims) {
11612 SvCUR_set(sv, SvCUR(sv) - 1);
11618 /* extend sv if need be */
11619 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11620 /* set 'to' to the next character in the sv's string */
11621 to = SvPVX(sv)+SvCUR(sv);
11623 /* if open delimiter is the close delimiter read unbridle */
11624 if (PL_multi_open == PL_multi_close) {
11625 for (; s < PL_bufend; s++,to++) {
11626 /* embedded newlines increment the current line number */
11627 if (*s == '\n' && !PL_rsfp)
11628 CopLINE_inc(PL_curcop);
11629 /* handle quoted delimiters */
11630 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11631 if (!keep_quoted && s[1] == term)
11633 /* any other quotes are simply copied straight through */
11637 /* terminate when run out of buffer (the for() condition), or
11638 have found the terminator */
11639 else if (*s == term) {
11642 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11645 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11651 /* if the terminator isn't the same as the start character (e.g.,
11652 matched brackets), we have to allow more in the quoting, and
11653 be prepared for nested brackets.
11656 /* read until we run out of string, or we find the terminator */
11657 for (; s < PL_bufend; s++,to++) {
11658 /* embedded newlines increment the line count */
11659 if (*s == '\n' && !PL_rsfp)
11660 CopLINE_inc(PL_curcop);
11661 /* backslashes can escape the open or closing characters */
11662 if (*s == '\\' && s+1 < PL_bufend) {
11663 if (!keep_quoted &&
11664 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11669 /* allow nested opens and closes */
11670 else if (*s == PL_multi_close && --brackets <= 0)
11672 else if (*s == PL_multi_open)
11674 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11679 /* terminate the copied string and update the sv's end-of-string */
11681 SvCUR_set(sv, to - SvPVX_const(sv));
11684 * this next chunk reads more into the buffer if we're not done yet
11688 break; /* handle case where we are done yet :-) */
11690 #ifndef PERL_STRICT_CR
11691 if (to - SvPVX_const(sv) >= 2) {
11692 if ((to[-2] == '\r' && to[-1] == '\n') ||
11693 (to[-2] == '\n' && to[-1] == '\r'))
11697 SvCUR_set(sv, to - SvPVX_const(sv));
11699 else if (to[-1] == '\r')
11702 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11707 /* if we're out of file, or a read fails, bail and reset the current
11708 line marker so we can report where the unterminated string began
11711 if (PL_madskills) {
11712 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11714 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11716 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11720 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11722 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11728 /* we read a line, so increment our line counter */
11729 CopLINE_inc(PL_curcop);
11731 /* update debugger info */
11732 if (PERLDB_LINE && PL_curstash != PL_debstash)
11733 update_debugger_info_sv(PL_linestr);
11735 /* having changed the buffer, we must update PL_bufend */
11736 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11737 PL_last_lop = PL_last_uni = NULL;
11740 /* at this point, we have successfully read the delimited string */
11742 if (!PL_encoding || UTF) {
11744 if (PL_madskills) {
11745 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11746 const int len = s - tstart;
11748 sv_catpvn(PL_thisstuff, tstart, len);
11750 PL_thisstuff = newSVpvn(tstart, len);
11751 if (!PL_thisclose && !keep_delims)
11752 PL_thisclose = newSVpvn(s,termlen);
11757 sv_catpvn(sv, s, termlen);
11762 if (PL_madskills) {
11763 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11764 const int len = s - tstart - termlen;
11766 sv_catpvn(PL_thisstuff, tstart, len);
11768 PL_thisstuff = newSVpvn(tstart, len);
11769 if (!PL_thisclose && !keep_delims)
11770 PL_thisclose = newSVpvn(s - termlen,termlen);
11774 if (has_utf8 || PL_encoding)
11777 PL_multi_end = CopLINE(PL_curcop);
11779 /* if we allocated too much space, give some back */
11780 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11781 SvLEN_set(sv, SvCUR(sv) + 1);
11782 SvPV_renew(sv, SvLEN(sv));
11785 /* decide whether this is the first or second quoted string we've read
11798 takes: pointer to position in buffer
11799 returns: pointer to new position in buffer
11800 side-effects: builds ops for the constant in yylval.op
11802 Read a number in any of the formats that Perl accepts:
11804 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11805 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11808 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11810 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11813 If it reads a number without a decimal point or an exponent, it will
11814 try converting the number to an integer and see if it can do so
11815 without loss of precision.
11819 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11822 register const char *s = start; /* current position in buffer */
11823 register char *d; /* destination in temp buffer */
11824 register char *e; /* end of temp buffer */
11825 NV nv; /* number read, as a double */
11826 SV *sv = NULL; /* place to put the converted number */
11827 bool floatit; /* boolean: int or float? */
11828 const char *lastub = NULL; /* position of last underbar */
11829 static char const number_too_long[] = "Number too long";
11831 /* We use the first character to decide what type of number this is */
11835 Perl_croak(aTHX_ "panic: scan_num");
11837 /* if it starts with a 0, it could be an octal number, a decimal in
11838 0.13 disguise, or a hexadecimal number, or a binary number. */
11842 u holds the "number so far"
11843 shift the power of 2 of the base
11844 (hex == 4, octal == 3, binary == 1)
11845 overflowed was the number more than we can hold?
11847 Shift is used when we add a digit. It also serves as an "are
11848 we in octal/hex/binary?" indicator to disallow hex characters
11849 when in octal mode.
11854 bool overflowed = FALSE;
11855 bool just_zero = TRUE; /* just plain 0 or binary number? */
11856 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11857 static const char* const bases[5] =
11858 { "", "binary", "", "octal", "hexadecimal" };
11859 static const char* const Bases[5] =
11860 { "", "Binary", "", "Octal", "Hexadecimal" };
11861 static const char* const maxima[5] =
11863 "0b11111111111111111111111111111111",
11867 const char *base, *Base, *max;
11869 /* check for hex */
11874 } else if (s[1] == 'b') {
11879 /* check for a decimal in disguise */
11880 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11882 /* so it must be octal */
11889 if (ckWARN(WARN_SYNTAX))
11890 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11891 "Misplaced _ in number");
11895 base = bases[shift];
11896 Base = Bases[shift];
11897 max = maxima[shift];
11899 /* read the rest of the number */
11901 /* x is used in the overflow test,
11902 b is the digit we're adding on. */
11907 /* if we don't mention it, we're done */
11911 /* _ are ignored -- but warned about if consecutive */
11913 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11914 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11915 "Misplaced _ in number");
11919 /* 8 and 9 are not octal */
11920 case '8': case '9':
11922 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11926 case '2': case '3': case '4':
11927 case '5': case '6': case '7':
11929 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11932 case '0': case '1':
11933 b = *s++ & 15; /* ASCII digit -> value of digit */
11937 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11938 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11939 /* make sure they said 0x */
11942 b = (*s++ & 7) + 9;
11944 /* Prepare to put the digit we have onto the end
11945 of the number so far. We check for overflows.
11951 x = u << shift; /* make room for the digit */
11953 if ((x >> shift) != u
11954 && !(PL_hints & HINT_NEW_BINARY)) {
11957 if (ckWARN_d(WARN_OVERFLOW))
11958 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11959 "Integer overflow in %s number",
11962 u = x | b; /* add the digit to the end */
11965 n *= nvshift[shift];
11966 /* If an NV has not enough bits in its
11967 * mantissa to represent an UV this summing of
11968 * small low-order numbers is a waste of time
11969 * (because the NV cannot preserve the
11970 * low-order bits anyway): we could just
11971 * remember when did we overflow and in the
11972 * end just multiply n by the right
11980 /* if we get here, we had success: make a scalar value from
11985 /* final misplaced underbar check */
11986 if (s[-1] == '_') {
11987 if (ckWARN(WARN_SYNTAX))
11988 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11993 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
11994 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11995 "%s number > %s non-portable",
12001 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
12002 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12003 "%s number > %s non-portable",
12008 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
12009 sv = new_constant(start, s - start, "integer",
12011 else if (PL_hints & HINT_NEW_BINARY)
12012 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
12017 handle decimal numbers.
12018 we're also sent here when we read a 0 as the first digit
12020 case '1': case '2': case '3': case '4': case '5':
12021 case '6': case '7': case '8': case '9': case '.':
12024 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
12027 /* read next group of digits and _ and copy into d */
12028 while (isDIGIT(*s) || *s == '_') {
12029 /* skip underscores, checking for misplaced ones
12033 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12034 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12035 "Misplaced _ in number");
12039 /* check for end of fixed-length buffer */
12041 Perl_croak(aTHX_ number_too_long);
12042 /* if we're ok, copy the character */
12047 /* final misplaced underbar check */
12048 if (lastub && s == lastub + 1) {
12049 if (ckWARN(WARN_SYNTAX))
12050 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12053 /* read a decimal portion if there is one. avoid
12054 3..5 being interpreted as the number 3. followed
12057 if (*s == '.' && s[1] != '.') {
12062 if (ckWARN(WARN_SYNTAX))
12063 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12064 "Misplaced _ in number");
12068 /* copy, ignoring underbars, until we run out of digits.
12070 for (; isDIGIT(*s) || *s == '_'; s++) {
12071 /* fixed length buffer check */
12073 Perl_croak(aTHX_ number_too_long);
12075 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12076 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12077 "Misplaced _ in number");
12083 /* fractional part ending in underbar? */
12084 if (s[-1] == '_') {
12085 if (ckWARN(WARN_SYNTAX))
12086 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12087 "Misplaced _ in number");
12089 if (*s == '.' && isDIGIT(s[1])) {
12090 /* oops, it's really a v-string, but without the "v" */
12096 /* read exponent part, if present */
12097 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12101 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12102 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12104 /* stray preinitial _ */
12106 if (ckWARN(WARN_SYNTAX))
12107 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12108 "Misplaced _ in number");
12112 /* allow positive or negative exponent */
12113 if (*s == '+' || *s == '-')
12116 /* stray initial _ */
12118 if (ckWARN(WARN_SYNTAX))
12119 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12120 "Misplaced _ in number");
12124 /* read digits of exponent */
12125 while (isDIGIT(*s) || *s == '_') {
12128 Perl_croak(aTHX_ number_too_long);
12132 if (((lastub && s == lastub + 1) ||
12133 (!isDIGIT(s[1]) && s[1] != '_'))
12134 && ckWARN(WARN_SYNTAX))
12135 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12136 "Misplaced _ in number");
12143 /* make an sv from the string */
12147 We try to do an integer conversion first if no characters
12148 indicating "float" have been found.
12153 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12155 if (flags == IS_NUMBER_IN_UV) {
12157 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12160 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12161 if (uv <= (UV) IV_MIN)
12162 sv_setiv(sv, -(IV)uv);
12169 /* terminate the string */
12171 nv = Atof(PL_tokenbuf);
12175 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12176 (PL_hints & HINT_NEW_INTEGER) )
12177 sv = new_constant(PL_tokenbuf,
12180 (floatit ? "float" : "integer"),
12184 /* if it starts with a v, it could be a v-string */
12187 sv = newSV(5); /* preallocate storage space */
12188 s = scan_vstring(s,sv);
12192 /* make the op for the constant and return */
12195 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12197 lvalp->opval = NULL;
12203 S_scan_formline(pTHX_ register char *s)
12206 register char *eol;
12208 SV * const stuff = newSVpvs("");
12209 bool needargs = FALSE;
12210 bool eofmt = FALSE;
12212 char *tokenstart = s;
12215 if (PL_madskills) {
12216 savewhite = PL_thiswhite;
12221 while (!needargs) {
12224 #ifdef PERL_STRICT_CR
12225 while (SPACE_OR_TAB(*t))
12228 while (SPACE_OR_TAB(*t) || *t == '\r')
12231 if (*t == '\n' || t == PL_bufend) {
12236 if (PL_in_eval && !PL_rsfp) {
12237 eol = (char *) memchr(s,'\n',PL_bufend-s);
12242 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12244 for (t = s; t < eol; t++) {
12245 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12247 goto enough; /* ~~ must be first line in formline */
12249 if (*t == '@' || *t == '^')
12253 sv_catpvn(stuff, s, eol-s);
12254 #ifndef PERL_STRICT_CR
12255 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12256 char *end = SvPVX(stuff) + SvCUR(stuff);
12259 SvCUR_set(stuff, SvCUR(stuff) - 1);
12269 if (PL_madskills) {
12271 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12273 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12276 s = filter_gets(PL_linestr, PL_rsfp, 0);
12278 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12280 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12282 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12283 PL_last_lop = PL_last_uni = NULL;
12292 if (SvCUR(stuff)) {
12295 PL_lex_state = LEX_NORMAL;
12296 start_force(PL_curforce);
12297 NEXTVAL_NEXTTOKE.ival = 0;
12301 PL_lex_state = LEX_FORMLINE;
12303 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12305 else if (PL_encoding)
12306 sv_recode_to_utf8(stuff, PL_encoding);
12308 start_force(PL_curforce);
12309 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12311 start_force(PL_curforce);
12312 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12316 SvREFCNT_dec(stuff);
12318 PL_lex_formbrack = 0;
12322 if (PL_madskills) {
12324 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12326 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12327 PL_thiswhite = savewhite;
12339 PL_cshlen = strlen(PL_cshname);
12341 #if defined(USE_ITHREADS)
12342 PERL_UNUSED_CONTEXT;
12348 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12351 const I32 oldsavestack_ix = PL_savestack_ix;
12352 CV* const outsidecv = PL_compcv;
12355 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12357 SAVEI32(PL_subline);
12358 save_item(PL_subname);
12359 SAVESPTR(PL_compcv);
12361 PL_compcv = (CV*)newSV(0);
12362 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12363 CvFLAGS(PL_compcv) |= flags;
12365 PL_subline = CopLINE(PL_curcop);
12366 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12367 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12368 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12370 return oldsavestack_ix;
12374 #pragma segment Perl_yylex
12377 Perl_yywarn(pTHX_ const char *s)
12380 PL_in_eval |= EVAL_WARNONLY;
12382 PL_in_eval &= ~EVAL_WARNONLY;
12387 Perl_yyerror(pTHX_ const char *s)
12390 const char *where = NULL;
12391 const char *context = NULL;
12394 int yychar = PL_parser->yychar;
12396 if (!yychar || (yychar == ';' && !PL_rsfp))
12398 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12399 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12400 PL_oldbufptr != PL_bufptr) {
12403 The code below is removed for NetWare because it abends/crashes on NetWare
12404 when the script has error such as not having the closing quotes like:
12405 if ($var eq "value)
12406 Checking of white spaces is anyway done in NetWare code.
12409 while (isSPACE(*PL_oldoldbufptr))
12412 context = PL_oldoldbufptr;
12413 contlen = PL_bufptr - PL_oldoldbufptr;
12415 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12416 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12419 The code below is removed for NetWare because it abends/crashes on NetWare
12420 when the script has error such as not having the closing quotes like:
12421 if ($var eq "value)
12422 Checking of white spaces is anyway done in NetWare code.
12425 while (isSPACE(*PL_oldbufptr))
12428 context = PL_oldbufptr;
12429 contlen = PL_bufptr - PL_oldbufptr;
12431 else if (yychar > 255)
12432 where = "next token ???";
12433 else if (yychar == -2) { /* YYEMPTY */
12434 if (PL_lex_state == LEX_NORMAL ||
12435 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12436 where = "at end of line";
12437 else if (PL_lex_inpat)
12438 where = "within pattern";
12440 where = "within string";
12443 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12445 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12446 else if (isPRINT_LC(yychar))
12447 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12449 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12450 where = SvPVX_const(where_sv);
12452 msg = sv_2mortal(newSVpv(s, 0));
12453 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12454 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12456 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12458 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12459 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12460 Perl_sv_catpvf(aTHX_ msg,
12461 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12462 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12465 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12466 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, (void*)msg);
12469 if (PL_error_count >= 10) {
12470 if (PL_in_eval && SvCUR(ERRSV))
12471 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12472 (void*)ERRSV, OutCopFILE(PL_curcop));
12474 Perl_croak(aTHX_ "%s has too many errors.\n",
12475 OutCopFILE(PL_curcop));
12478 PL_in_my_stash = NULL;
12482 #pragma segment Main
12486 S_swallow_bom(pTHX_ U8 *s)
12489 const STRLEN slen = SvCUR(PL_linestr);
12492 if (s[1] == 0xFE) {
12493 /* UTF-16 little-endian? (or UTF32-LE?) */
12494 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12495 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12496 #ifndef PERL_NO_UTF16_FILTER
12497 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12500 if (PL_bufend > (char*)s) {
12504 filter_add(utf16rev_textfilter, NULL);
12505 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12506 utf16_to_utf8_reversed(s, news,
12507 PL_bufend - (char*)s - 1,
12509 sv_setpvn(PL_linestr, (const char*)news, newlen);
12511 s = (U8*)SvPVX(PL_linestr);
12512 Copy(news, s, newlen, U8);
12516 SvUTF8_on(PL_linestr);
12517 s = (U8*)SvPVX(PL_linestr);
12519 /* FIXME - is this a general bug fix? */
12522 PL_bufend = SvPVX(PL_linestr) + newlen;
12525 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12530 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12531 #ifndef PERL_NO_UTF16_FILTER
12532 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12535 if (PL_bufend > (char *)s) {
12539 filter_add(utf16_textfilter, NULL);
12540 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12541 utf16_to_utf8(s, news,
12542 PL_bufend - (char*)s,
12544 sv_setpvn(PL_linestr, (const char*)news, newlen);
12546 SvUTF8_on(PL_linestr);
12547 s = (U8*)SvPVX(PL_linestr);
12548 PL_bufend = SvPVX(PL_linestr) + newlen;
12551 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12556 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12557 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12558 s += 3; /* UTF-8 */
12564 if (s[2] == 0xFE && s[3] == 0xFF) {
12565 /* UTF-32 big-endian */
12566 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12569 else if (s[2] == 0 && s[3] != 0) {
12572 * are a good indicator of UTF-16BE. */
12573 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12579 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12580 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12581 s += 4; /* UTF-8 */
12587 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12590 * are a good indicator of UTF-16LE. */
12591 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12600 * Restore a source filter.
12604 restore_rsfp(pTHX_ void *f)
12607 PerlIO * const fp = (PerlIO*)f;
12609 if (PL_rsfp == PerlIO_stdin())
12610 PerlIO_clearerr(PL_rsfp);
12611 else if (PL_rsfp && (PL_rsfp != fp))
12612 PerlIO_close(PL_rsfp);
12616 #ifndef PERL_NO_UTF16_FILTER
12618 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12621 const STRLEN old = SvCUR(sv);
12622 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12623 DEBUG_P(PerlIO_printf(Perl_debug_log,
12624 "utf16_textfilter(%p): %d %d (%d)\n",
12625 FPTR2DPTR(void *, utf16_textfilter),
12626 idx, maxlen, (int) count));
12630 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12631 Copy(SvPVX_const(sv), tmps, old, char);
12632 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12633 SvCUR(sv) - old, &newlen);
12634 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12636 DEBUG_P({sv_dump(sv);});
12641 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12644 const STRLEN old = SvCUR(sv);
12645 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12646 DEBUG_P(PerlIO_printf(Perl_debug_log,
12647 "utf16rev_textfilter(%p): %d %d (%d)\n",
12648 FPTR2DPTR(void *, utf16rev_textfilter),
12649 idx, maxlen, (int) count));
12653 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12654 Copy(SvPVX_const(sv), tmps, old, char);
12655 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12656 SvCUR(sv) - old, &newlen);
12657 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12659 DEBUG_P({ sv_dump(sv); });
12665 Returns a pointer to the next character after the parsed
12666 vstring, as well as updating the passed in sv.
12668 Function must be called like
12671 s = scan_vstring(s,sv);
12673 The sv should already be large enough to store the vstring
12674 passed in, for performance reasons.
12679 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12682 const char *pos = s;
12683 const char *start = s;
12684 if (*pos == 'v') pos++; /* get past 'v' */
12685 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12687 if ( *pos != '.') {
12688 /* this may not be a v-string if followed by => */
12689 const char *next = pos;
12690 while (next < PL_bufend && isSPACE(*next))
12692 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12693 /* return string not v-string */
12694 sv_setpvn(sv,(char *)s,pos-s);
12695 return (char *)pos;
12699 if (!isALPHA(*pos)) {
12700 U8 tmpbuf[UTF8_MAXBYTES+1];
12703 s++; /* get past 'v' */
12705 sv_setpvn(sv, "", 0);
12708 /* this is atoi() that tolerates underscores */
12711 const char *end = pos;
12713 while (--end >= s) {
12715 const UV orev = rev;
12716 rev += (*end - '0') * mult;
12718 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12719 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12720 "Integer overflow in decimal number");
12724 if (rev > 0x7FFFFFFF)
12725 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12727 /* Append native character for the rev point */
12728 tmpend = uvchr_to_utf8(tmpbuf, rev);
12729 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12730 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12732 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12738 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12742 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12750 * c-indentation-style: bsd
12751 * c-basic-offset: 4
12752 * indent-tabs-mode: t
12755 * ex: set ts=8 sts=4 sw=4 noet: