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(PL_linestr, len);
665 if (SvREADONLY(PL_linestr) || !len || s[len-1] != ';') {
666 PL_linestr = sv_2mortal(len ? newSVsv(PL_linestr) : newSVpvn(s, 0));
667 if (!len || s[len-1] != ';')
668 sv_catpvs(PL_linestr, "\n;");
670 SvTEMP_off(PL_linestr);
671 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
672 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
673 PL_last_lop = PL_last_uni = NULL;
679 * Finalizer for lexing operations. Must be called when the parser is
680 * done with the lexer.
687 PL_doextract = FALSE;
692 * This subroutine has nothing to do with tilting, whether at windmills
693 * or pinball tables. Its name is short for "increment line". It
694 * increments the current line number in CopLINE(PL_curcop) and checks
695 * to see whether the line starts with a comment of the form
696 * # line 500 "foo.pm"
697 * If so, it sets the current line number and file to the values in the comment.
701 S_incline(pTHX_ char *s)
709 CopLINE_inc(PL_curcop);
712 while (SPACE_OR_TAB(*s))
714 if (strnEQ(s, "line", 4))
718 if (SPACE_OR_TAB(*s))
722 while (SPACE_OR_TAB(*s))
730 while (SPACE_OR_TAB(*s))
732 if (*s == '"' && (t = strchr(s+1, '"'))) {
742 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
744 if (*e != '\n' && *e != '\0')
745 return; /* false alarm */
751 const char * const cf = CopFILE(PL_curcop);
752 STRLEN tmplen = cf ? strlen(cf) : 0;
753 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
754 /* must copy *{"::_<(eval N)[oldfilename:L]"}
755 * to *{"::_<newfilename"} */
756 char smallbuf[256], smallbuf2[256];
757 char *tmpbuf, *tmpbuf2;
759 STRLEN tmplen2 = strlen(s);
760 if (tmplen + 3 < sizeof smallbuf)
763 Newx(tmpbuf, tmplen + 3, char);
764 if (tmplen2 + 3 < sizeof smallbuf2)
767 Newx(tmpbuf2, tmplen2 + 3, char);
768 tmpbuf[0] = tmpbuf2[0] = '_';
769 tmpbuf[1] = tmpbuf2[1] = '<';
770 memcpy(tmpbuf + 2, cf, ++tmplen);
771 memcpy(tmpbuf2 + 2, s, ++tmplen2);
773 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
775 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
777 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
778 /* adjust ${"::_<newfilename"} to store the new file name */
779 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
780 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
781 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
784 if (tmpbuf != smallbuf) Safefree(tmpbuf);
785 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
788 CopFILE_free(PL_curcop);
789 CopFILE_set(PL_curcop, s);
792 CopLINE_set(PL_curcop, atoi(n)-1);
796 /* skip space before PL_thistoken */
799 S_skipspace0(pTHX_ register char *s)
806 PL_thiswhite = newSVpvs("");
807 sv_catsv(PL_thiswhite, PL_skipwhite);
808 sv_free(PL_skipwhite);
811 PL_realtokenstart = s - SvPVX(PL_linestr);
815 /* skip space after PL_thistoken */
818 S_skipspace1(pTHX_ register char *s)
820 const char *start = s;
821 I32 startoff = start - SvPVX(PL_linestr);
826 start = SvPVX(PL_linestr) + startoff;
827 if (!PL_thistoken && PL_realtokenstart >= 0) {
828 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
829 PL_thistoken = newSVpvn(tstart, start - tstart);
831 PL_realtokenstart = -1;
834 PL_nextwhite = newSVpvs("");
835 sv_catsv(PL_nextwhite, PL_skipwhite);
836 sv_free(PL_skipwhite);
843 S_skipspace2(pTHX_ register char *s, SV **svp)
846 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
847 const I32 startoff = s - SvPVX(PL_linestr);
850 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
851 if (!PL_madskills || !svp)
853 start = SvPVX(PL_linestr) + startoff;
854 if (!PL_thistoken && PL_realtokenstart >= 0) {
855 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
856 PL_thistoken = newSVpvn(tstart, start - tstart);
857 PL_realtokenstart = -1;
862 sv_setsv(*svp, PL_skipwhite);
863 sv_free(PL_skipwhite);
872 S_update_debugger_info_pv(pTHX_ const char *buf, STRLEN len)
874 AV *av = CopFILEAVx(PL_curcop);
876 SV * const sv = newSV(0);
877 sv_upgrade(sv, SVt_PVMG);
878 sv_setpvn(sv, buf, len);
881 av_store(av, (I32)CopLINE(PL_curcop), sv);
886 S_update_debugger_info_sv(pTHX_ SV *orig_sv)
888 AV *av = CopFILEAVx(PL_curcop);
890 SV * const sv = newSV(0);
891 sv_upgrade(sv, SVt_PVMG);
892 sv_setsv(sv, orig_sv);
895 av_store(av, (I32)CopLINE(PL_curcop), sv);
901 * Called to gobble the appropriate amount and type of whitespace.
902 * Skips comments as well.
906 S_skipspace(pTHX_ register char *s)
911 int startoff = s - SvPVX(PL_linestr);
914 sv_free(PL_skipwhite);
919 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
920 while (s < PL_bufend && SPACE_OR_TAB(*s))
930 SSize_t oldprevlen, oldoldprevlen;
931 SSize_t oldloplen = 0, oldunilen = 0;
932 while (s < PL_bufend && isSPACE(*s)) {
933 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
938 if (s < PL_bufend && *s == '#') {
939 while (s < PL_bufend && *s != '\n')
943 if (PL_in_eval && !PL_rsfp) {
950 /* only continue to recharge the buffer if we're at the end
951 * of the buffer, we're not reading from a source filter, and
952 * we're in normal lexing mode
954 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
955 PL_lex_state == LEX_FORMLINE)
962 /* try to recharge the buffer */
964 curoff = s - SvPVX(PL_linestr);
967 if ((s = filter_gets(PL_linestr, PL_rsfp,
968 (prevlen = SvCUR(PL_linestr)))) == NULL)
971 if (PL_madskills && curoff != startoff) {
973 PL_skipwhite = newSVpvs("");
974 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
978 /* mustn't throw out old stuff yet if madpropping */
979 SvCUR(PL_linestr) = curoff;
980 s = SvPVX(PL_linestr) + curoff;
982 if (curoff && s[-1] == '\n')
986 /* end of file. Add on the -p or -n magic */
987 /* XXX these shouldn't really be added here, can't set PL_faketokens */
991 ";}continue{print or die qq(-p destination: $!\\n);}");
994 ";}continue{print or die qq(-p destination: $!\\n);}");
996 PL_minus_n = PL_minus_p = 0;
998 else if (PL_minus_n) {
1000 sv_catpvn(PL_linestr, ";}", 2);
1002 sv_setpvn(PL_linestr, ";}", 2);
1008 sv_catpvn(PL_linestr,";", 1);
1010 sv_setpvn(PL_linestr,";", 1);
1013 /* reset variables for next time we lex */
1014 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
1020 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1021 PL_last_lop = PL_last_uni = NULL;
1023 /* Close the filehandle. Could be from -P preprocessor,
1024 * STDIN, or a regular file. If we were reading code from
1025 * STDIN (because the commandline held no -e or filename)
1026 * then we don't close it, we reset it so the code can
1027 * read from STDIN too.
1030 if (PL_preprocess && !PL_in_eval)
1031 (void)PerlProc_pclose(PL_rsfp);
1032 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1033 PerlIO_clearerr(PL_rsfp);
1035 (void)PerlIO_close(PL_rsfp);
1040 /* not at end of file, so we only read another line */
1041 /* make corresponding updates to old pointers, for yyerror() */
1042 oldprevlen = PL_oldbufptr - PL_bufend;
1043 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1045 oldunilen = PL_last_uni - PL_bufend;
1047 oldloplen = PL_last_lop - PL_bufend;
1048 PL_linestart = PL_bufptr = s + prevlen;
1049 PL_bufend = s + SvCUR(PL_linestr);
1051 PL_oldbufptr = s + oldprevlen;
1052 PL_oldoldbufptr = s + oldoldprevlen;
1054 PL_last_uni = s + oldunilen;
1056 PL_last_lop = s + oldloplen;
1059 /* debugger active and we're not compiling the debugger code,
1060 * so store the line into the debugger's array of lines
1062 if (PERLDB_LINE && PL_curstash != PL_debstash)
1063 update_debugger_info_pv(PL_bufptr, PL_bufend - PL_bufptr);
1070 PL_skipwhite = newSVpvs("");
1071 curoff = s - SvPVX(PL_linestr);
1072 if (curoff - startoff)
1073 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1082 * Check the unary operators to ensure there's no ambiguity in how they're
1083 * used. An ambiguous piece of code would be:
1085 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1086 * the +5 is its argument.
1096 if (PL_oldoldbufptr != PL_last_uni)
1098 while (isSPACE(*PL_last_uni))
1101 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1103 if ((t = strchr(s, '(')) && t < PL_bufptr)
1106 if (ckWARN_d(WARN_AMBIGUOUS)){
1107 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1108 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1109 (int)(s - PL_last_uni), PL_last_uni);
1114 * LOP : macro to build a list operator. Its behaviour has been replaced
1115 * with a subroutine, S_lop() for which LOP is just another name.
1118 #define LOP(f,x) return lop(f,x,s)
1122 * Build a list operator (or something that might be one). The rules:
1123 * - if we have a next token, then it's a list operator [why?]
1124 * - if the next thing is an opening paren, then it's a function
1125 * - else it's a list operator
1129 S_lop(pTHX_ I32 f, int x, char *s)
1136 PL_last_lop = PL_oldbufptr;
1137 PL_last_lop_op = (OPCODE)f;
1140 return REPORT(LSTOP);
1143 return REPORT(LSTOP);
1146 return REPORT(FUNC);
1149 return REPORT(FUNC);
1151 return REPORT(LSTOP);
1157 * Sets up for an eventual force_next(). start_force(0) basically does
1158 * an unshift, while start_force(-1) does a push. yylex removes items
1163 S_start_force(pTHX_ int where)
1167 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1168 where = PL_lasttoke;
1169 assert(PL_curforce < 0 || PL_curforce == where);
1170 if (PL_curforce != where) {
1171 for (i = PL_lasttoke; i > where; --i) {
1172 PL_nexttoke[i] = PL_nexttoke[i-1];
1176 if (PL_curforce < 0) /* in case of duplicate start_force() */
1177 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1178 PL_curforce = where;
1181 curmad('^', newSVpvs(""));
1182 CURMAD('_', PL_nextwhite);
1187 S_curmad(pTHX_ char slot, SV *sv)
1193 if (PL_curforce < 0)
1194 where = &PL_thismad;
1196 where = &PL_nexttoke[PL_curforce].next_mad;
1199 sv_setpvn(sv, "", 0);
1202 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1204 else if (PL_encoding) {
1205 sv_recode_to_utf8(sv, PL_encoding);
1210 /* keep a slot open for the head of the list? */
1211 if (slot != '_' && *where && (*where)->mad_key == '^') {
1212 (*where)->mad_key = slot;
1213 sv_free((*where)->mad_val);
1214 (*where)->mad_val = (void*)sv;
1217 addmad(newMADsv(slot, sv), where, 0);
1220 # define start_force(where) NOOP
1221 # define curmad(slot, sv) NOOP
1226 * When the lexer realizes it knows the next token (for instance,
1227 * it is reordering tokens for the parser) then it can call S_force_next
1228 * to know what token to return the next time the lexer is called. Caller
1229 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1230 * and possibly PL_expect to ensure the lexer handles the token correctly.
1234 S_force_next(pTHX_ I32 type)
1238 if (PL_curforce < 0)
1239 start_force(PL_lasttoke);
1240 PL_nexttoke[PL_curforce].next_type = type;
1241 if (PL_lex_state != LEX_KNOWNEXT)
1242 PL_lex_defer = PL_lex_state;
1243 PL_lex_state = LEX_KNOWNEXT;
1244 PL_lex_expect = PL_expect;
1247 PL_nexttype[PL_nexttoke] = type;
1249 if (PL_lex_state != LEX_KNOWNEXT) {
1250 PL_lex_defer = PL_lex_state;
1251 PL_lex_expect = PL_expect;
1252 PL_lex_state = LEX_KNOWNEXT;
1258 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1261 SV * const sv = newSVpvn(start,len);
1262 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1269 * When the lexer knows the next thing is a word (for instance, it has
1270 * just seen -> and it knows that the next char is a word char, then
1271 * it calls S_force_word to stick the next word into the PL_next lookahead.
1274 * char *start : buffer position (must be within PL_linestr)
1275 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
1276 * int check_keyword : if true, Perl checks to make sure the word isn't
1277 * a keyword (do this if the word is a label, e.g. goto FOO)
1278 * int allow_pack : if true, : characters will also be allowed (require,
1279 * use, etc. do this)
1280 * int allow_initial_tick : used by the "sub" lexer only.
1284 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1290 start = SKIPSPACE1(start);
1292 if (isIDFIRST_lazy_if(s,UTF) ||
1293 (allow_pack && *s == ':') ||
1294 (allow_initial_tick && *s == '\'') )
1296 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1297 if (check_keyword && keyword(PL_tokenbuf, len, 0))
1299 start_force(PL_curforce);
1301 curmad('X', newSVpvn(start,s-start));
1302 if (token == METHOD) {
1307 PL_expect = XOPERATOR;
1310 NEXTVAL_NEXTTOKE.opval
1311 = (OP*)newSVOP(OP_CONST,0,
1312 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1313 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1321 * Called when the lexer wants $foo *foo &foo etc, but the program
1322 * text only contains the "foo" portion. The first argument is a pointer
1323 * to the "foo", and the second argument is the type symbol to prefix.
1324 * Forces the next token to be a "WORD".
1325 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1329 S_force_ident(pTHX_ register const char *s, int kind)
1333 const STRLEN len = strlen(s);
1334 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1335 start_force(PL_curforce);
1336 NEXTVAL_NEXTTOKE.opval = o;
1339 o->op_private = OPpCONST_ENTERED;
1340 /* XXX see note in pp_entereval() for why we forgo typo
1341 warnings if the symbol must be introduced in an eval.
1343 gv_fetchpvn_flags(s, len,
1344 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1346 kind == '$' ? SVt_PV :
1347 kind == '@' ? SVt_PVAV :
1348 kind == '%' ? SVt_PVHV :
1356 Perl_str_to_version(pTHX_ SV *sv)
1361 const char *start = SvPV_const(sv,len);
1362 const char * const end = start + len;
1363 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1364 while (start < end) {
1368 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1373 retval += ((NV)n)/nshift;
1382 * Forces the next token to be a version number.
1383 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1384 * and if "guessing" is TRUE, then no new token is created (and the caller
1385 * must use an alternative parsing method).
1389 S_force_version(pTHX_ char *s, int guessing)
1395 I32 startoff = s - SvPVX(PL_linestr);
1404 while (isDIGIT(*d) || *d == '_' || *d == '.')
1408 start_force(PL_curforce);
1409 curmad('X', newSVpvn(s,d-s));
1412 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1414 s = scan_num(s, &yylval);
1415 version = yylval.opval;
1416 ver = cSVOPx(version)->op_sv;
1417 if (SvPOK(ver) && !SvNIOK(ver)) {
1418 SvUPGRADE(ver, SVt_PVNV);
1419 SvNV_set(ver, str_to_version(ver));
1420 SvNOK_on(ver); /* hint that it is a version */
1423 else if (guessing) {
1426 sv_free(PL_nextwhite); /* let next token collect whitespace */
1428 s = SvPVX(PL_linestr) + startoff;
1436 if (PL_madskills && !version) {
1437 sv_free(PL_nextwhite); /* let next token collect whitespace */
1439 s = SvPVX(PL_linestr) + startoff;
1442 /* NOTE: The parser sees the package name and the VERSION swapped */
1443 start_force(PL_curforce);
1444 NEXTVAL_NEXTTOKE.opval = version;
1452 * Tokenize a quoted string passed in as an SV. It finds the next
1453 * chunk, up to end of string or a backslash. It may make a new
1454 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1459 S_tokeq(pTHX_ SV *sv)
1463 register char *send;
1471 s = SvPV_force(sv, len);
1472 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1475 while (s < send && *s != '\\')
1480 if ( PL_hints & HINT_NEW_STRING ) {
1481 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1487 if (s + 1 < send && (s[1] == '\\'))
1488 s++; /* all that, just for this */
1493 SvCUR_set(sv, d - SvPVX_const(sv));
1495 if ( PL_hints & HINT_NEW_STRING )
1496 return new_constant(NULL, 0, "q", sv, pv, "q");
1501 * Now come three functions related to double-quote context,
1502 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1503 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1504 * interact with PL_lex_state, and create fake ( ... ) argument lists
1505 * to handle functions and concatenation.
1506 * They assume that whoever calls them will be setting up a fake
1507 * join call, because each subthing puts a ',' after it. This lets
1510 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1512 * (I'm not sure whether the spurious commas at the end of lcfirst's
1513 * arguments and join's arguments are created or not).
1518 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1520 * Pattern matching will set PL_lex_op to the pattern-matching op to
1521 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1523 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1525 * Everything else becomes a FUNC.
1527 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1528 * had an OP_CONST or OP_READLINE). This just sets us up for a
1529 * call to S_sublex_push().
1533 S_sublex_start(pTHX)
1536 register const I32 op_type = yylval.ival;
1538 if (op_type == OP_NULL) {
1539 yylval.opval = PL_lex_op;
1543 if (op_type == OP_CONST || op_type == OP_READLINE) {
1544 SV *sv = tokeq(PL_lex_stuff);
1546 if (SvTYPE(sv) == SVt_PVIV) {
1547 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1549 const char * const p = SvPV_const(sv, len);
1550 SV * const nsv = newSVpvn(p, len);
1556 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1557 PL_lex_stuff = NULL;
1558 /* Allow <FH> // "foo" */
1559 if (op_type == OP_READLINE)
1560 PL_expect = XTERMORDORDOR;
1563 else if (op_type == OP_BACKTICK && PL_lex_op) {
1564 /* readpipe() vas overriden */
1565 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1566 yylval.opval = PL_lex_op;
1568 PL_lex_stuff = NULL;
1572 PL_sublex_info.super_state = PL_lex_state;
1573 PL_sublex_info.sub_inwhat = op_type;
1574 PL_sublex_info.sub_op = PL_lex_op;
1575 PL_lex_state = LEX_INTERPPUSH;
1579 yylval.opval = PL_lex_op;
1589 * Create a new scope to save the lexing state. The scope will be
1590 * ended in S_sublex_done. Returns a '(', starting the function arguments
1591 * to the uc, lc, etc. found before.
1592 * Sets PL_lex_state to LEX_INTERPCONCAT.
1601 PL_lex_state = PL_sublex_info.super_state;
1602 SAVEI32(PL_lex_dojoin);
1603 SAVEI32(PL_lex_brackets);
1604 SAVEI32(PL_lex_casemods);
1605 SAVEI32(PL_lex_starts);
1606 SAVEI32(PL_lex_state);
1607 SAVEVPTR(PL_lex_inpat);
1608 SAVEI32(PL_lex_inwhat);
1609 SAVECOPLINE(PL_curcop);
1610 SAVEPPTR(PL_bufptr);
1611 SAVEPPTR(PL_bufend);
1612 SAVEPPTR(PL_oldbufptr);
1613 SAVEPPTR(PL_oldoldbufptr);
1614 SAVEPPTR(PL_last_lop);
1615 SAVEPPTR(PL_last_uni);
1616 SAVEPPTR(PL_linestart);
1617 SAVESPTR(PL_linestr);
1618 SAVEGENERICPV(PL_lex_brackstack);
1619 SAVEGENERICPV(PL_lex_casestack);
1621 PL_linestr = PL_lex_stuff;
1622 PL_lex_stuff = NULL;
1624 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1625 = SvPVX(PL_linestr);
1626 PL_bufend += SvCUR(PL_linestr);
1627 PL_last_lop = PL_last_uni = NULL;
1628 SAVEFREESV(PL_linestr);
1630 PL_lex_dojoin = FALSE;
1631 PL_lex_brackets = 0;
1632 Newx(PL_lex_brackstack, 120, char);
1633 Newx(PL_lex_casestack, 12, char);
1634 PL_lex_casemods = 0;
1635 *PL_lex_casestack = '\0';
1637 PL_lex_state = LEX_INTERPCONCAT;
1638 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1640 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1641 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1642 PL_lex_inpat = PL_sublex_info.sub_op;
1644 PL_lex_inpat = NULL;
1651 * Restores lexer state after a S_sublex_push.
1658 if (!PL_lex_starts++) {
1659 SV * const sv = newSVpvs("");
1660 if (SvUTF8(PL_linestr))
1662 PL_expect = XOPERATOR;
1663 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1667 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1668 PL_lex_state = LEX_INTERPCASEMOD;
1672 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1673 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1674 PL_linestr = PL_lex_repl;
1676 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1677 PL_bufend += SvCUR(PL_linestr);
1678 PL_last_lop = PL_last_uni = NULL;
1679 SAVEFREESV(PL_linestr);
1680 PL_lex_dojoin = FALSE;
1681 PL_lex_brackets = 0;
1682 PL_lex_casemods = 0;
1683 *PL_lex_casestack = '\0';
1685 if (SvEVALED(PL_lex_repl)) {
1686 PL_lex_state = LEX_INTERPNORMAL;
1688 /* we don't clear PL_lex_repl here, so that we can check later
1689 whether this is an evalled subst; that means we rely on the
1690 logic to ensure sublex_done() is called again only via the
1691 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1694 PL_lex_state = LEX_INTERPCONCAT;
1704 PL_endwhite = newSVpvs("");
1705 sv_catsv(PL_endwhite, PL_thiswhite);
1709 sv_setpvn(PL_thistoken,"",0);
1711 PL_realtokenstart = -1;
1715 PL_bufend = SvPVX(PL_linestr);
1716 PL_bufend += SvCUR(PL_linestr);
1717 PL_expect = XOPERATOR;
1718 PL_sublex_info.sub_inwhat = 0;
1726 Extracts a pattern, double-quoted string, or transliteration. This
1729 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
1730 processing a pattern (PL_lex_inpat is true), a transliteration
1731 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
1733 Returns a pointer to the character scanned up to. If this is
1734 advanced from the start pointer supplied (i.e. if anything was
1735 successfully parsed), will leave an OP for the substring scanned
1736 in yylval. Caller must intuit reason for not parsing further
1737 by looking at the next characters herself.
1741 double-quoted style: \r and \n
1742 regexp special ones: \D \s
1745 case and quoting: \U \Q \E
1746 stops on @ and $, but not for $ as tail anchor
1748 In transliterations:
1749 characters are VERY literal, except for - not at the start or end
1750 of the string, which indicates a range. If the range is in bytes,
1751 scan_const expands the range to the full set of intermediate
1752 characters. If the range is in utf8, the hyphen is replaced with
1753 a certain range mark which will be handled by pmtrans() in op.c.
1755 In double-quoted strings:
1757 double-quoted style: \r and \n
1759 deprecated backrefs: \1 (in substitution replacements)
1760 case and quoting: \U \Q \E
1763 scan_const does *not* construct ops to handle interpolated strings.
1764 It stops processing as soon as it finds an embedded $ or @ variable
1765 and leaves it to the caller to work out what's going on.
1767 embedded arrays (whether in pattern or not) could be:
1768 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1770 $ in double-quoted strings must be the symbol of an embedded scalar.
1772 $ in pattern could be $foo or could be tail anchor. Assumption:
1773 it's a tail anchor if $ is the last thing in the string, or if it's
1774 followed by one of "()| \r\n\t"
1776 \1 (backreferences) are turned into $1
1778 The structure of the code is
1779 while (there's a character to process) {
1780 handle transliteration ranges
1781 skip regexp comments /(?#comment)/ and codes /(?{code})/
1782 skip #-initiated comments in //x patterns
1783 check for embedded arrays
1784 check for embedded scalars
1786 leave intact backslashes from leaveit (below)
1787 deprecate \1 in substitution replacements
1788 handle string-changing backslashes \l \U \Q \E, etc.
1789 switch (what was escaped) {
1790 handle \- in a transliteration (becomes a literal -)
1791 handle \132 (octal characters)
1792 handle \x15 and \x{1234} (hex characters)
1793 handle \N{name} (named characters)
1794 handle \cV (control characters)
1795 handle printf-style backslashes (\f, \r, \n, etc)
1797 } (end if backslash)
1798 } (end while character to read)
1803 S_scan_const(pTHX_ char *start)
1806 register char *send = PL_bufend; /* end of the constant */
1807 SV *sv = newSV(send - start); /* sv for the constant */
1808 register char *s = start; /* start of the constant */
1809 register char *d = SvPVX(sv); /* destination for copies */
1810 bool dorange = FALSE; /* are we in a translit range? */
1811 bool didrange = FALSE; /* did we just finish a range? */
1812 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1813 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1816 UV literal_endpoint = 0;
1817 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
1820 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1821 /* If we are doing a trans and we know we want UTF8 set expectation */
1822 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1823 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1827 while (s < send || dorange) {
1828 /* get transliterations out of the way (they're most literal) */
1829 if (PL_lex_inwhat == OP_TRANS) {
1830 /* expand a range A-Z to the full set of characters. AIE! */
1832 I32 i; /* current expanded character */
1833 I32 min; /* first character in range */
1834 I32 max; /* last character in range */
1845 char * const c = (char*)utf8_hop((U8*)d, -1);
1849 *c = (char)UTF_TO_NATIVE(0xff);
1850 /* mark the range as done, and continue */
1856 i = d - SvPVX_const(sv); /* remember current offset */
1859 SvLEN(sv) + (has_utf8 ?
1860 (512 - UTF_CONTINUATION_MARK +
1863 /* How many two-byte within 0..255: 128 in UTF-8,
1864 * 96 in UTF-8-mod. */
1866 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1868 d = SvPVX(sv) + i; /* refresh d after realloc */
1872 for (j = 0; j <= 1; j++) {
1873 char * const c = (char*)utf8_hop((U8*)d, -1);
1874 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
1880 max = (U8)0xff; /* only to \xff */
1881 uvmax = uv; /* \x{100} to uvmax */
1883 d = c; /* eat endpoint chars */
1888 d -= 2; /* eat the first char and the - */
1889 min = (U8)*d; /* first char in range */
1890 max = (U8)d[1]; /* last char in range */
1897 "Invalid range \"%c-%c\" in transliteration operator",
1898 (char)min, (char)max);
1902 if (literal_endpoint == 2 &&
1903 ((isLOWER(min) && isLOWER(max)) ||
1904 (isUPPER(min) && isUPPER(max)))) {
1906 for (i = min; i <= max; i++)
1908 *d++ = NATIVE_TO_NEED(has_utf8,i);
1910 for (i = min; i <= max; i++)
1912 *d++ = NATIVE_TO_NEED(has_utf8,i);
1917 for (i = min; i <= max; i++)
1920 const U8 ch = (U8)NATIVE_TO_UTF(i);
1921 if (UNI_IS_INVARIANT(ch))
1924 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
1925 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
1934 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
1936 *d++ = (char)UTF_TO_NATIVE(0xff);
1938 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
1942 /* mark the range as done, and continue */
1946 literal_endpoint = 0;
1951 /* range begins (ignore - as first or last char) */
1952 else if (*s == '-' && s+1 < send && s != start) {
1954 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1961 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1971 literal_endpoint = 0;
1972 native_range = TRUE;
1977 /* if we get here, we're not doing a transliteration */
1979 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1980 except for the last char, which will be done separately. */
1981 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1983 while (s+1 < send && *s != ')')
1984 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1986 else if (s[2] == '{' /* This should match regcomp.c */
1987 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1990 char *regparse = s + (s[2] == '{' ? 3 : 4);
1993 while (count && (c = *regparse)) {
1994 if (c == '\\' && regparse[1])
2002 if (*regparse != ')')
2003 regparse--; /* Leave one char for continuation. */
2004 while (s < regparse)
2005 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2009 /* likewise skip #-initiated comments in //x patterns */
2010 else if (*s == '#' && PL_lex_inpat &&
2011 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2012 while (s+1 < send && *s != '\n')
2013 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2016 /* check for embedded arrays
2017 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2019 else if (*s == '@' && s[1]) {
2020 if (isALNUM_lazy_if(s+1,UTF))
2022 if (strchr(":'{$", s[1]))
2024 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2025 break; /* in regexp, neither @+ nor @- are interpolated */
2028 /* check for embedded scalars. only stop if we're sure it's a
2031 else if (*s == '$') {
2032 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
2034 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
2035 break; /* in regexp, $ might be tail anchor */
2038 /* End of else if chain - OP_TRANS rejoin rest */
2041 if (*s == '\\' && s+1 < send) {
2044 /* deprecate \1 in strings and substitution replacements */
2045 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2046 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2048 if (ckWARN(WARN_SYNTAX))
2049 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2054 /* string-change backslash escapes */
2055 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2059 /* skip any other backslash escapes in a pattern */
2060 else if (PL_lex_inpat) {
2061 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2062 goto default_action;
2065 /* if we get here, it's either a quoted -, or a digit */
2068 /* quoted - in transliterations */
2070 if (PL_lex_inwhat == OP_TRANS) {
2077 if ((isALPHA(*s) || isDIGIT(*s)) &&
2079 Perl_warner(aTHX_ packWARN(WARN_MISC),
2080 "Unrecognized escape \\%c passed through",
2082 /* default action is to copy the quoted character */
2083 goto default_action;
2086 /* \132 indicates an octal constant */
2087 case '0': case '1': case '2': case '3':
2088 case '4': case '5': case '6': case '7':
2092 uv = grok_oct(s, &len, &flags, NULL);
2095 goto NUM_ESCAPE_INSERT;
2097 /* \x24 indicates a hex constant */
2101 char* const e = strchr(s, '}');
2102 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2103 PERL_SCAN_DISALLOW_PREFIX;
2108 yyerror("Missing right brace on \\x{}");
2112 uv = grok_hex(s, &len, &flags, NULL);
2118 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2119 uv = grok_hex(s, &len, &flags, NULL);
2125 /* Insert oct or hex escaped character.
2126 * There will always enough room in sv since such
2127 * escapes will be longer than any UTF-8 sequence
2128 * they can end up as. */
2130 /* We need to map to chars to ASCII before doing the tests
2133 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2134 if (!has_utf8 && uv > 255) {
2135 /* Might need to recode whatever we have
2136 * accumulated so far if it contains any
2139 * (Can't we keep track of that and avoid
2140 * this rescan? --jhi)
2144 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2145 if (!NATIVE_IS_INVARIANT(*c)) {
2150 const STRLEN offset = d - SvPVX_const(sv);
2152 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2156 while (src >= (const U8 *)SvPVX_const(sv)) {
2157 if (!NATIVE_IS_INVARIANT(*src)) {
2158 const U8 ch = NATIVE_TO_ASCII(*src);
2159 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2160 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2170 if (has_utf8 || uv > 255) {
2171 d = (char*)uvchr_to_utf8((U8*)d, uv);
2173 if (PL_lex_inwhat == OP_TRANS &&
2174 PL_sublex_info.sub_op) {
2175 PL_sublex_info.sub_op->op_private |=
2176 (PL_lex_repl ? OPpTRANS_FROM_UTF
2180 if (uv > 255 && !dorange)
2181 native_range = FALSE;
2193 /* \N{LATIN SMALL LETTER A} is a named character */
2197 char* e = strchr(s, '}');
2204 yyerror("Missing right brace on \\N{}");
2208 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2210 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2211 PERL_SCAN_DISALLOW_PREFIX;
2214 uv = grok_hex(s, &len, &flags, NULL);
2215 if ( e > s && len != (STRLEN)(e - s) ) {
2219 goto NUM_ESCAPE_INSERT;
2221 res = newSVpvn(s + 1, e - s - 1);
2222 type = newSVpvn(s - 2,e - s + 3);
2223 res = new_constant( NULL, 0, "charnames",
2224 res, NULL, SvPVX(type) );
2227 sv_utf8_upgrade(res);
2228 str = SvPV_const(res,len);
2229 #ifdef EBCDIC_NEVER_MIND
2230 /* charnames uses pack U and that has been
2231 * recently changed to do the below uni->native
2232 * mapping, so this would be redundant (and wrong,
2233 * the code point would be doubly converted).
2234 * But leave this in just in case the pack U change
2235 * gets revoked, but the semantics is still
2236 * desireable for charnames. --jhi */
2238 UV uv = utf8_to_uvchr((const U8*)str, 0);
2241 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2243 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2244 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2245 str = SvPV_const(res, len);
2249 if (!has_utf8 && SvUTF8(res)) {
2250 const char * const ostart = SvPVX_const(sv);
2251 SvCUR_set(sv, d - ostart);
2254 sv_utf8_upgrade(sv);
2255 /* this just broke our allocation above... */
2256 SvGROW(sv, (STRLEN)(send - start));
2257 d = SvPVX(sv) + SvCUR(sv);
2260 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2261 const char * const odest = SvPVX_const(sv);
2263 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2264 d = SvPVX(sv) + (d - odest);
2268 native_range = FALSE; /* \N{} is guessed to be Unicode */
2270 Copy(str, d, len, char);
2277 yyerror("Missing braces on \\N{}");
2280 /* \c is a control character */
2289 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2292 yyerror("Missing control char name in \\c");
2296 /* printf-style backslashes, formfeeds, newlines, etc */
2298 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2301 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2304 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2307 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2310 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2313 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2316 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2322 } /* end if (backslash) */
2329 /* If we started with encoded form, or already know we want it
2330 and then encode the next character */
2331 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2333 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2334 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2337 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2338 const STRLEN off = d - SvPVX_const(sv);
2339 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2341 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2344 if (uv > 255 && !dorange)
2345 native_range = FALSE;
2349 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2351 } /* while loop to process each character */
2353 /* terminate the string and set up the sv */
2355 SvCUR_set(sv, d - SvPVX_const(sv));
2356 if (SvCUR(sv) >= SvLEN(sv))
2357 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2360 if (PL_encoding && !has_utf8) {
2361 sv_recode_to_utf8(sv, PL_encoding);
2367 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2368 PL_sublex_info.sub_op->op_private |=
2369 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2373 /* shrink the sv if we allocated more than we used */
2374 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2375 SvPV_shrink_to_cur(sv);
2378 /* return the substring (via yylval) only if we parsed anything */
2379 if (s > PL_bufptr) {
2380 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2381 sv = new_constant(start, s - start,
2382 (const char *)(PL_lex_inpat ? "qr" : "q"),
2385 (( PL_lex_inwhat == OP_TRANS
2387 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2390 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2397 * Returns TRUE if there's more to the expression (e.g., a subscript),
2400 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2402 * ->[ and ->{ return TRUE
2403 * { and [ outside a pattern are always subscripts, so return TRUE
2404 * if we're outside a pattern and it's not { or [, then return FALSE
2405 * if we're in a pattern and the first char is a {
2406 * {4,5} (any digits around the comma) returns FALSE
2407 * if we're in a pattern and the first char is a [
2409 * [SOMETHING] has a funky algorithm to decide whether it's a
2410 * character class or not. It has to deal with things like
2411 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2412 * anything else returns TRUE
2415 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2418 S_intuit_more(pTHX_ register char *s)
2421 if (PL_lex_brackets)
2423 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2425 if (*s != '{' && *s != '[')
2430 /* In a pattern, so maybe we have {n,m}. */
2447 /* On the other hand, maybe we have a character class */
2450 if (*s == ']' || *s == '^')
2453 /* this is terrifying, and it works */
2454 int weight = 2; /* let's weigh the evidence */
2456 unsigned char un_char = 255, last_un_char;
2457 const char * const send = strchr(s,']');
2458 char tmpbuf[sizeof PL_tokenbuf * 4];
2460 if (!send) /* has to be an expression */
2463 Zero(seen,256,char);
2466 else if (isDIGIT(*s)) {
2468 if (isDIGIT(s[1]) && s[2] == ']')
2474 for (; s < send; s++) {
2475 last_un_char = un_char;
2476 un_char = (unsigned char)*s;
2481 weight -= seen[un_char] * 10;
2482 if (isALNUM_lazy_if(s+1,UTF)) {
2484 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2485 len = (int)strlen(tmpbuf);
2486 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2491 else if (*s == '$' && s[1] &&
2492 strchr("[#!%*<>()-=",s[1])) {
2493 if (/*{*/ strchr("])} =",s[2]))
2502 if (strchr("wds]",s[1]))
2504 else if (seen[(U8)'\''] || seen[(U8)'"'])
2506 else if (strchr("rnftbxcav",s[1]))
2508 else if (isDIGIT(s[1])) {
2510 while (s[1] && isDIGIT(s[1]))
2520 if (strchr("aA01! ",last_un_char))
2522 if (strchr("zZ79~",s[1]))
2524 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2525 weight -= 5; /* cope with negative subscript */
2528 if (!isALNUM(last_un_char)
2529 && !(last_un_char == '$' || last_un_char == '@'
2530 || last_un_char == '&')
2531 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2536 if (keyword(tmpbuf, d - tmpbuf, 0))
2539 if (un_char == last_un_char + 1)
2541 weight -= seen[un_char];
2546 if (weight >= 0) /* probably a character class */
2556 * Does all the checking to disambiguate
2558 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2559 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2561 * First argument is the stuff after the first token, e.g. "bar".
2563 * Not a method if bar is a filehandle.
2564 * Not a method if foo is a subroutine prototyped to take a filehandle.
2565 * Not a method if it's really "Foo $bar"
2566 * Method if it's "foo $bar"
2567 * Not a method if it's really "print foo $bar"
2568 * Method if it's really "foo package::" (interpreted as package->foo)
2569 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2570 * Not a method if bar is a filehandle or package, but is quoted with
2575 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2578 char *s = start + (*start == '$');
2579 char tmpbuf[sizeof PL_tokenbuf];
2587 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2591 const char *proto = SvPVX_const(cv);
2602 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2603 /* start is the beginning of the possible filehandle/object,
2604 * and s is the end of it
2605 * tmpbuf is a copy of it
2608 if (*start == '$') {
2609 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2612 len = start - SvPVX(PL_linestr);
2616 start = SvPVX(PL_linestr) + len;
2620 return *s == '(' ? FUNCMETH : METHOD;
2622 if (!keyword(tmpbuf, len, 0)) {
2623 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2627 soff = s - SvPVX(PL_linestr);
2631 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2632 if (indirgv && GvCVu(indirgv))
2634 /* filehandle or package name makes it a method */
2635 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2637 soff = s - SvPVX(PL_linestr);
2640 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2641 return 0; /* no assumptions -- "=>" quotes bearword */
2643 start_force(PL_curforce);
2644 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2645 newSVpvn(tmpbuf,len));
2646 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2648 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2653 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2655 return *s == '(' ? FUNCMETH : METHOD;
2663 * Return a string of Perl code to load the debugger. If PERL5DB
2664 * is set, it will return the contents of that, otherwise a
2665 * compile-time require of perl5db.pl.
2673 const char * const pdb = PerlEnv_getenv("PERL5DB");
2677 SETERRNO(0,SS_NORMAL);
2678 return "BEGIN { require 'perl5db.pl' }";
2684 /* Encoded script support. filter_add() effectively inserts a
2685 * 'pre-processing' function into the current source input stream.
2686 * Note that the filter function only applies to the current source file
2687 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2689 * The datasv parameter (which may be NULL) can be used to pass
2690 * private data to this instance of the filter. The filter function
2691 * can recover the SV using the FILTER_DATA macro and use it to
2692 * store private buffers and state information.
2694 * The supplied datasv parameter is upgraded to a PVIO type
2695 * and the IoDIRP/IoANY field is used to store the function pointer,
2696 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2697 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2698 * private use must be set using malloc'd pointers.
2702 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2708 if (!PL_rsfp_filters)
2709 PL_rsfp_filters = newAV();
2712 SvUPGRADE(datasv, SVt_PVIO);
2713 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2714 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2715 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2716 FPTR2DPTR(void *, IoANY(datasv)),
2717 SvPV_nolen(datasv)));
2718 av_unshift(PL_rsfp_filters, 1);
2719 av_store(PL_rsfp_filters, 0, datasv) ;
2724 /* Delete most recently added instance of this filter function. */
2726 Perl_filter_del(pTHX_ filter_t funcp)
2732 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2733 FPTR2DPTR(void*, funcp)));
2735 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2737 /* if filter is on top of stack (usual case) just pop it off */
2738 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2739 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2740 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2741 IoANY(datasv) = (void *)NULL;
2742 sv_free(av_pop(PL_rsfp_filters));
2746 /* we need to search for the correct entry and clear it */
2747 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2751 /* Invoke the idxth filter function for the current rsfp. */
2752 /* maxlen 0 = read one text line */
2754 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2759 /* This API is bad. It should have been using unsigned int for maxlen.
2760 Not sure if we want to change the API, but if not we should sanity
2761 check the value here. */
2762 const unsigned int correct_length
2771 if (!PL_rsfp_filters)
2773 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2774 /* Provide a default input filter to make life easy. */
2775 /* Note that we append to the line. This is handy. */
2776 DEBUG_P(PerlIO_printf(Perl_debug_log,
2777 "filter_read %d: from rsfp\n", idx));
2778 if (correct_length) {
2781 const int old_len = SvCUR(buf_sv);
2783 /* ensure buf_sv is large enough */
2784 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2785 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2786 correct_length)) <= 0) {
2787 if (PerlIO_error(PL_rsfp))
2788 return -1; /* error */
2790 return 0 ; /* end of file */
2792 SvCUR_set(buf_sv, old_len + len) ;
2795 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2796 if (PerlIO_error(PL_rsfp))
2797 return -1; /* error */
2799 return 0 ; /* end of file */
2802 return SvCUR(buf_sv);
2804 /* Skip this filter slot if filter has been deleted */
2805 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2806 DEBUG_P(PerlIO_printf(Perl_debug_log,
2807 "filter_read %d: skipped (filter deleted)\n",
2809 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2811 /* Get function pointer hidden within datasv */
2812 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2813 DEBUG_P(PerlIO_printf(Perl_debug_log,
2814 "filter_read %d: via function %p (%s)\n",
2815 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2816 /* Call function. The function is expected to */
2817 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2818 /* Return: <0:error, =0:eof, >0:not eof */
2819 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2823 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2826 #ifdef PERL_CR_FILTER
2827 if (!PL_rsfp_filters) {
2828 filter_add(S_cr_textfilter,NULL);
2831 if (PL_rsfp_filters) {
2833 SvCUR_set(sv, 0); /* start with empty line */
2834 if (FILTER_READ(0, sv, 0) > 0)
2835 return ( SvPVX(sv) ) ;
2840 return (sv_gets(sv, fp, append));
2844 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2849 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2853 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2854 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2856 return GvHV(gv); /* Foo:: */
2859 /* use constant CLASS => 'MyClass' */
2860 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2861 if (gv && GvCV(gv)) {
2862 SV * const sv = cv_const_sv(GvCV(gv));
2864 pkgname = SvPV_nolen_const(sv);
2867 return gv_stashpv(pkgname, FALSE);
2871 * S_readpipe_override
2872 * Check whether readpipe() is overriden, and generates the appropriate
2873 * optree, provided sublex_start() is called afterwards.
2876 S_readpipe_override(pTHX)
2879 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
2880 yylval.ival = OP_BACKTICK;
2882 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
2884 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
2885 && (gv_readpipe = *gvp) != (GV*)&PL_sv_undef
2886 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
2888 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
2889 append_elem(OP_LIST,
2890 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
2891 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
2901 * The intent of this yylex wrapper is to minimize the changes to the
2902 * tokener when we aren't interested in collecting madprops. It remains
2903 * to be seen how successful this strategy will be...
2910 char *s = PL_bufptr;
2912 /* make sure PL_thiswhite is initialized */
2916 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2917 if (PL_pending_ident)
2918 return S_pending_ident(aTHX);
2920 /* previous token ate up our whitespace? */
2921 if (!PL_lasttoke && PL_nextwhite) {
2922 PL_thiswhite = PL_nextwhite;
2926 /* isolate the token, and figure out where it is without whitespace */
2927 PL_realtokenstart = -1;
2931 assert(PL_curforce < 0);
2933 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2934 if (!PL_thistoken) {
2935 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2936 PL_thistoken = newSVpvs("");
2938 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2939 PL_thistoken = newSVpvn(tstart, s - tstart);
2942 if (PL_thismad) /* install head */
2943 CURMAD('X', PL_thistoken);
2946 /* last whitespace of a sublex? */
2947 if (optype == ')' && PL_endwhite) {
2948 CURMAD('X', PL_endwhite);
2953 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
2954 if (!PL_thiswhite && !PL_endwhite && !optype) {
2955 sv_free(PL_thistoken);
2960 /* put off final whitespace till peg */
2961 if (optype == ';' && !PL_rsfp) {
2962 PL_nextwhite = PL_thiswhite;
2965 else if (PL_thisopen) {
2966 CURMAD('q', PL_thisopen);
2968 sv_free(PL_thistoken);
2972 /* Store actual token text as madprop X */
2973 CURMAD('X', PL_thistoken);
2977 /* add preceding whitespace as madprop _ */
2978 CURMAD('_', PL_thiswhite);
2982 /* add quoted material as madprop = */
2983 CURMAD('=', PL_thisstuff);
2987 /* add terminating quote as madprop Q */
2988 CURMAD('Q', PL_thisclose);
2992 /* special processing based on optype */
2996 /* opval doesn't need a TOKEN since it can already store mp */
3007 append_madprops(PL_thismad, yylval.opval, 0);
3015 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3024 /* remember any fake bracket that lexer is about to discard */
3025 if (PL_lex_brackets == 1 &&
3026 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3029 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3032 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3033 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3036 break; /* don't bother looking for trailing comment */
3045 /* attach a trailing comment to its statement instead of next token */
3049 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3051 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3053 if (*s == '\n' || *s == '#') {
3054 while (s < PL_bufend && *s != '\n')
3058 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3059 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3076 /* Create new token struct. Note: opvals return early above. */
3077 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
3084 S_tokenize_use(pTHX_ int is_use, char *s) {
3086 if (PL_expect != XSTATE)
3087 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3088 is_use ? "use" : "no"));
3090 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3091 s = force_version(s, TRUE);
3092 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3093 start_force(PL_curforce);
3094 NEXTVAL_NEXTTOKE.opval = NULL;
3097 else if (*s == 'v') {
3098 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3099 s = force_version(s, FALSE);
3103 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3104 s = force_version(s, FALSE);
3106 yylval.ival = is_use;
3110 static const char* const exp_name[] =
3111 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3112 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3119 Works out what to call the token just pulled out of the input
3120 stream. The yacc parser takes care of taking the ops we return and
3121 stitching them into a tree.
3127 if read an identifier
3128 if we're in a my declaration
3129 croak if they tried to say my($foo::bar)
3130 build the ops for a my() declaration
3131 if it's an access to a my() variable
3132 are we in a sort block?
3133 croak if my($a); $a <=> $b
3134 build ops for access to a my() variable
3135 if in a dq string, and they've said @foo and we can't find @foo
3137 build ops for a bareword
3138 if we already built the token before, use it.
3143 #pragma segment Perl_yylex
3149 register char *s = PL_bufptr;
3154 /* orig_keyword, gvp, and gv are initialized here because
3155 * jump to the label just_a_word_zero can bypass their
3156 * initialization later. */
3157 I32 orig_keyword = 0;
3162 SV* tmp = newSVpvs("");
3163 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3164 (IV)CopLINE(PL_curcop),
3165 lex_state_names[PL_lex_state],
3166 exp_name[PL_expect],
3167 pv_display(tmp, s, strlen(s), 0, 60));
3170 /* check if there's an identifier for us to look at */
3171 if (PL_pending_ident)
3172 return REPORT(S_pending_ident(aTHX));
3174 /* no identifier pending identification */
3176 switch (PL_lex_state) {
3178 case LEX_NORMAL: /* Some compilers will produce faster */
3179 case LEX_INTERPNORMAL: /* code if we comment these out. */
3183 /* when we've already built the next token, just pull it out of the queue */
3187 yylval = PL_nexttoke[PL_lasttoke].next_val;
3189 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3190 PL_nexttoke[PL_lasttoke].next_mad = 0;
3191 if (PL_thismad && PL_thismad->mad_key == '_') {
3192 PL_thiswhite = (SV*)PL_thismad->mad_val;
3193 PL_thismad->mad_val = 0;
3194 mad_free(PL_thismad);
3199 PL_lex_state = PL_lex_defer;
3200 PL_expect = PL_lex_expect;
3201 PL_lex_defer = LEX_NORMAL;
3202 if (!PL_nexttoke[PL_lasttoke].next_type)
3207 yylval = PL_nextval[PL_nexttoke];
3209 PL_lex_state = PL_lex_defer;
3210 PL_expect = PL_lex_expect;
3211 PL_lex_defer = LEX_NORMAL;
3215 /* FIXME - can these be merged? */
3216 return(PL_nexttoke[PL_lasttoke].next_type);
3218 return REPORT(PL_nexttype[PL_nexttoke]);
3221 /* interpolated case modifiers like \L \U, including \Q and \E.
3222 when we get here, PL_bufptr is at the \
3224 case LEX_INTERPCASEMOD:
3226 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3227 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3229 /* handle \E or end of string */
3230 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3232 if (PL_lex_casemods) {
3233 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3234 PL_lex_casestack[PL_lex_casemods] = '\0';
3236 if (PL_bufptr != PL_bufend
3237 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3239 PL_lex_state = LEX_INTERPCONCAT;
3242 PL_thistoken = newSVpvs("\\E");
3248 while (PL_bufptr != PL_bufend &&
3249 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3251 PL_thiswhite = newSVpvs("");
3252 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3256 if (PL_bufptr != PL_bufend)
3259 PL_lex_state = LEX_INTERPCONCAT;
3263 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3264 "### Saw case modifier\n"); });
3266 if (s[1] == '\\' && s[2] == 'E') {
3269 PL_thiswhite = newSVpvs("");
3270 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3273 PL_lex_state = LEX_INTERPCONCAT;
3278 if (!PL_madskills) /* when just compiling don't need correct */
3279 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3280 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3281 if ((*s == 'L' || *s == 'U') &&
3282 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3283 PL_lex_casestack[--PL_lex_casemods] = '\0';
3286 if (PL_lex_casemods > 10)
3287 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3288 PL_lex_casestack[PL_lex_casemods++] = *s;
3289 PL_lex_casestack[PL_lex_casemods] = '\0';
3290 PL_lex_state = LEX_INTERPCONCAT;
3291 start_force(PL_curforce);
3292 NEXTVAL_NEXTTOKE.ival = 0;
3294 start_force(PL_curforce);
3296 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3298 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3300 NEXTVAL_NEXTTOKE.ival = OP_LC;
3302 NEXTVAL_NEXTTOKE.ival = OP_UC;
3304 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3306 Perl_croak(aTHX_ "panic: yylex");
3308 SV* const tmpsv = newSVpvs("");
3309 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3315 if (PL_lex_starts) {
3321 sv_free(PL_thistoken);
3322 PL_thistoken = newSVpvs("");
3325 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3326 if (PL_lex_casemods == 1 && PL_lex_inpat)
3335 case LEX_INTERPPUSH:
3336 return REPORT(sublex_push());
3338 case LEX_INTERPSTART:
3339 if (PL_bufptr == PL_bufend)
3340 return REPORT(sublex_done());
3341 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3342 "### Interpolated variable\n"); });
3344 PL_lex_dojoin = (*PL_bufptr == '@');
3345 PL_lex_state = LEX_INTERPNORMAL;
3346 if (PL_lex_dojoin) {
3347 start_force(PL_curforce);
3348 NEXTVAL_NEXTTOKE.ival = 0;
3350 start_force(PL_curforce);
3351 force_ident("\"", '$');
3352 start_force(PL_curforce);
3353 NEXTVAL_NEXTTOKE.ival = 0;
3355 start_force(PL_curforce);
3356 NEXTVAL_NEXTTOKE.ival = 0;
3358 start_force(PL_curforce);
3359 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3362 if (PL_lex_starts++) {
3367 sv_free(PL_thistoken);
3368 PL_thistoken = newSVpvs("");
3371 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3372 if (!PL_lex_casemods && PL_lex_inpat)
3379 case LEX_INTERPENDMAYBE:
3380 if (intuit_more(PL_bufptr)) {
3381 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3387 if (PL_lex_dojoin) {
3388 PL_lex_dojoin = FALSE;
3389 PL_lex_state = LEX_INTERPCONCAT;
3393 sv_free(PL_thistoken);
3394 PL_thistoken = newSVpvs("");
3399 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3400 && SvEVALED(PL_lex_repl))
3402 if (PL_bufptr != PL_bufend)
3403 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3407 case LEX_INTERPCONCAT:
3409 if (PL_lex_brackets)
3410 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3412 if (PL_bufptr == PL_bufend)
3413 return REPORT(sublex_done());
3415 if (SvIVX(PL_linestr) == '\'') {
3416 SV *sv = newSVsv(PL_linestr);
3419 else if ( PL_hints & HINT_NEW_RE )
3420 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3421 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3425 s = scan_const(PL_bufptr);
3427 PL_lex_state = LEX_INTERPCASEMOD;
3429 PL_lex_state = LEX_INTERPSTART;
3432 if (s != PL_bufptr) {
3433 start_force(PL_curforce);
3435 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3437 NEXTVAL_NEXTTOKE = yylval;
3440 if (PL_lex_starts++) {
3444 sv_free(PL_thistoken);
3445 PL_thistoken = newSVpvs("");
3448 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3449 if (!PL_lex_casemods && PL_lex_inpat)
3462 PL_lex_state = LEX_NORMAL;
3463 s = scan_formline(PL_bufptr);
3464 if (!PL_lex_formbrack)
3470 PL_oldoldbufptr = PL_oldbufptr;
3476 sv_free(PL_thistoken);
3479 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3483 if (isIDFIRST_lazy_if(s,UTF))
3485 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3488 goto fake_eof; /* emulate EOF on ^D or ^Z */
3497 if (PL_lex_brackets) {
3498 yyerror((const char *)
3500 ? "Format not terminated"
3501 : "Missing right curly or square bracket"));
3503 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3504 "### Tokener got EOF\n");
3508 if (s++ < PL_bufend)
3509 goto retry; /* ignore stray nulls */
3512 if (!PL_in_eval && !PL_preambled) {
3513 PL_preambled = TRUE;
3518 sv_setpv(PL_linestr,incl_perldb());
3519 if (SvCUR(PL_linestr))
3520 sv_catpvs(PL_linestr,";");
3522 while(AvFILLp(PL_preambleav) >= 0) {
3523 SV *tmpsv = av_shift(PL_preambleav);
3524 sv_catsv(PL_linestr, tmpsv);
3525 sv_catpvs(PL_linestr, ";");
3528 sv_free((SV*)PL_preambleav);
3529 PL_preambleav = NULL;
3531 if (PL_minus_n || PL_minus_p) {
3532 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3534 sv_catpvs(PL_linestr,"chomp;");
3537 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3538 || *PL_splitstr == '"')
3539 && strchr(PL_splitstr + 1, *PL_splitstr))
3540 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3542 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3543 bytes can be used as quoting characters. :-) */
3544 const char *splits = PL_splitstr;
3545 sv_catpvs(PL_linestr, "our @F=split(q\0");
3548 if (*splits == '\\')
3549 sv_catpvn(PL_linestr, splits, 1);
3550 sv_catpvn(PL_linestr, splits, 1);
3551 } while (*splits++);
3552 /* This loop will embed the trailing NUL of
3553 PL_linestr as the last thing it does before
3555 sv_catpvs(PL_linestr, ");");
3559 sv_catpvs(PL_linestr,"our @F=split(' ');");
3563 sv_catpvs(PL_linestr,"use feature ':5.10';");
3564 sv_catpvs(PL_linestr, "\n");
3565 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3566 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3567 PL_last_lop = PL_last_uni = NULL;
3568 if (PERLDB_LINE && PL_curstash != PL_debstash)
3569 update_debugger_info_sv(PL_linestr);
3573 bof = PL_rsfp ? TRUE : FALSE;
3574 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3577 PL_realtokenstart = -1;
3580 if (PL_preprocess && !PL_in_eval)
3581 (void)PerlProc_pclose(PL_rsfp);
3582 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3583 PerlIO_clearerr(PL_rsfp);
3585 (void)PerlIO_close(PL_rsfp);
3587 PL_doextract = FALSE;
3589 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3594 sv_setpv(PL_linestr,
3597 ? ";}continue{print;}" : ";}"));
3598 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3599 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3600 PL_last_lop = PL_last_uni = NULL;
3601 PL_minus_n = PL_minus_p = 0;
3604 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3605 PL_last_lop = PL_last_uni = NULL;
3606 sv_setpvn(PL_linestr,"",0);
3607 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3609 /* If it looks like the start of a BOM or raw UTF-16,
3610 * check if it in fact is. */
3616 #ifdef PERLIO_IS_STDIO
3617 # ifdef __GNU_LIBRARY__
3618 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3619 # define FTELL_FOR_PIPE_IS_BROKEN
3623 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3624 # define FTELL_FOR_PIPE_IS_BROKEN
3629 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3630 /* This loses the possibility to detect the bof
3631 * situation on perl -P when the libc5 is being used.
3632 * Workaround? Maybe attach some extra state to PL_rsfp?
3635 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3637 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3640 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3641 s = swallow_bom((U8*)s);
3645 /* Incest with pod. */
3648 sv_catsv(PL_thiswhite, PL_linestr);
3650 if (*s == '=' && strnEQ(s, "=cut", 4)) {
3651 sv_setpvn(PL_linestr, "", 0);
3652 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3653 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3654 PL_last_lop = PL_last_uni = NULL;
3655 PL_doextract = FALSE;
3659 } while (PL_doextract);
3660 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3661 if (PERLDB_LINE && PL_curstash != PL_debstash)
3662 update_debugger_info_sv(PL_linestr);
3663 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3664 PL_last_lop = PL_last_uni = NULL;
3665 if (CopLINE(PL_curcop) == 1) {
3666 while (s < PL_bufend && isSPACE(*s))
3668 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3672 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3676 if (*s == '#' && *(s+1) == '!')
3678 #ifdef ALTERNATE_SHEBANG
3680 static char const as[] = ALTERNATE_SHEBANG;
3681 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3682 d = s + (sizeof(as) - 1);
3684 #endif /* ALTERNATE_SHEBANG */
3693 while (*d && !isSPACE(*d))
3697 #ifdef ARG_ZERO_IS_SCRIPT
3698 if (ipathend > ipath) {
3700 * HP-UX (at least) sets argv[0] to the script name,
3701 * which makes $^X incorrect. And Digital UNIX and Linux,
3702 * at least, set argv[0] to the basename of the Perl
3703 * interpreter. So, having found "#!", we'll set it right.
3705 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3707 assert(SvPOK(x) || SvGMAGICAL(x));
3708 if (sv_eq(x, CopFILESV(PL_curcop))) {
3709 sv_setpvn(x, ipath, ipathend - ipath);
3715 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3716 const char * const lstart = SvPV_const(x,llen);
3718 bstart += blen - llen;
3719 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3720 sv_setpvn(x, ipath, ipathend - ipath);
3725 TAINT_NOT; /* $^X is always tainted, but that's OK */
3727 #endif /* ARG_ZERO_IS_SCRIPT */
3732 d = instr(s,"perl -");
3734 d = instr(s,"perl");
3736 /* avoid getting into infinite loops when shebang
3737 * line contains "Perl" rather than "perl" */
3739 for (d = ipathend-4; d >= ipath; --d) {
3740 if ((*d == 'p' || *d == 'P')
3741 && !ibcmp(d, "perl", 4))
3751 #ifdef ALTERNATE_SHEBANG
3753 * If the ALTERNATE_SHEBANG on this system starts with a
3754 * character that can be part of a Perl expression, then if
3755 * we see it but not "perl", we're probably looking at the
3756 * start of Perl code, not a request to hand off to some
3757 * other interpreter. Similarly, if "perl" is there, but
3758 * not in the first 'word' of the line, we assume the line
3759 * contains the start of the Perl program.
3761 if (d && *s != '#') {
3762 const char *c = ipath;
3763 while (*c && !strchr("; \t\r\n\f\v#", *c))
3766 d = NULL; /* "perl" not in first word; ignore */
3768 *s = '#'; /* Don't try to parse shebang line */
3770 #endif /* ALTERNATE_SHEBANG */
3771 #ifndef MACOS_TRADITIONAL
3776 !instr(s,"indir") &&
3777 instr(PL_origargv[0],"perl"))
3784 while (s < PL_bufend && isSPACE(*s))
3786 if (s < PL_bufend) {
3787 Newxz(newargv,PL_origargc+3,char*);
3789 while (s < PL_bufend && !isSPACE(*s))
3792 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3795 newargv = PL_origargv;
3798 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3800 Perl_croak(aTHX_ "Can't exec %s", ipath);
3804 while (*d && !isSPACE(*d))
3806 while (SPACE_OR_TAB(*d))
3810 const bool switches_done = PL_doswitches;
3811 const U32 oldpdb = PL_perldb;
3812 const bool oldn = PL_minus_n;
3813 const bool oldp = PL_minus_p;
3816 if (*d == 'M' || *d == 'm' || *d == 'C') {
3817 const char * const m = d;
3818 while (*d && !isSPACE(*d))
3820 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3823 d = moreswitches(d);
3825 if (PL_doswitches && !switches_done) {
3826 int argc = PL_origargc;
3827 char **argv = PL_origargv;
3830 } while (argc && argv[0][0] == '-' && argv[0][1]);
3831 init_argv_symbols(argc,argv);
3833 if ((PERLDB_LINE && !oldpdb) ||
3834 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3835 /* if we have already added "LINE: while (<>) {",
3836 we must not do it again */
3838 sv_setpvn(PL_linestr, "", 0);
3839 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3840 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3841 PL_last_lop = PL_last_uni = NULL;
3842 PL_preambled = FALSE;
3844 (void)gv_fetchfile(PL_origfilename);
3851 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3853 PL_lex_state = LEX_FORMLINE;
3858 #ifdef PERL_STRICT_CR
3859 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3861 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3863 case ' ': case '\t': case '\f': case 013:
3864 #ifdef MACOS_TRADITIONAL
3868 PL_realtokenstart = -1;
3877 PL_realtokenstart = -1;
3881 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3882 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3883 /* handle eval qq[#line 1 "foo"\n ...] */
3884 CopLINE_dec(PL_curcop);
3887 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3889 if (!PL_in_eval || PL_rsfp)
3894 while (d < PL_bufend && *d != '\n')
3898 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3899 Perl_croak(aTHX_ "panic: input overflow");
3902 PL_thiswhite = newSVpvn(s, d - s);
3907 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3909 PL_lex_state = LEX_FORMLINE;
3915 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3916 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3919 TOKEN(PEG); /* make sure any #! line is accessible */
3924 /* if (PL_madskills && PL_lex_formbrack) { */
3926 while (d < PL_bufend && *d != '\n')
3930 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3931 Perl_croak(aTHX_ "panic: input overflow");
3932 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3934 PL_thiswhite = newSVpvs("");
3935 if (CopLINE(PL_curcop) == 1) {
3936 sv_setpvn(PL_thiswhite, "", 0);
3939 sv_catpvn(PL_thiswhite, s, d - s);
3953 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3961 while (s < PL_bufend && SPACE_OR_TAB(*s))
3964 if (strnEQ(s,"=>",2)) {
3965 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3966 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
3967 OPERATOR('-'); /* unary minus */
3969 PL_last_uni = PL_oldbufptr;
3971 case 'r': ftst = OP_FTEREAD; break;
3972 case 'w': ftst = OP_FTEWRITE; break;
3973 case 'x': ftst = OP_FTEEXEC; break;
3974 case 'o': ftst = OP_FTEOWNED; break;
3975 case 'R': ftst = OP_FTRREAD; break;
3976 case 'W': ftst = OP_FTRWRITE; break;
3977 case 'X': ftst = OP_FTREXEC; break;
3978 case 'O': ftst = OP_FTROWNED; break;
3979 case 'e': ftst = OP_FTIS; break;
3980 case 'z': ftst = OP_FTZERO; break;
3981 case 's': ftst = OP_FTSIZE; break;
3982 case 'f': ftst = OP_FTFILE; break;
3983 case 'd': ftst = OP_FTDIR; break;
3984 case 'l': ftst = OP_FTLINK; break;
3985 case 'p': ftst = OP_FTPIPE; break;
3986 case 'S': ftst = OP_FTSOCK; break;
3987 case 'u': ftst = OP_FTSUID; break;
3988 case 'g': ftst = OP_FTSGID; break;
3989 case 'k': ftst = OP_FTSVTX; break;
3990 case 'b': ftst = OP_FTBLK; break;
3991 case 'c': ftst = OP_FTCHR; break;
3992 case 't': ftst = OP_FTTTY; break;
3993 case 'T': ftst = OP_FTTEXT; break;
3994 case 'B': ftst = OP_FTBINARY; break;
3995 case 'M': case 'A': case 'C':
3996 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
3998 case 'M': ftst = OP_FTMTIME; break;
3999 case 'A': ftst = OP_FTATIME; break;
4000 case 'C': ftst = OP_FTCTIME; break;
4008 PL_last_lop_op = (OPCODE)ftst;
4009 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4010 "### Saw file test %c\n", (int)tmp);
4015 /* Assume it was a minus followed by a one-letter named
4016 * subroutine call (or a -bareword), then. */
4017 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4018 "### '-%c' looked like a file test but was not\n",
4025 const char tmp = *s++;
4028 if (PL_expect == XOPERATOR)
4033 else if (*s == '>') {
4036 if (isIDFIRST_lazy_if(s,UTF)) {
4037 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4045 if (PL_expect == XOPERATOR)
4048 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4050 OPERATOR('-'); /* unary minus */
4056 const char tmp = *s++;
4059 if (PL_expect == XOPERATOR)
4064 if (PL_expect == XOPERATOR)
4067 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4074 if (PL_expect != XOPERATOR) {
4075 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4076 PL_expect = XOPERATOR;
4077 force_ident(PL_tokenbuf, '*');
4090 if (PL_expect == XOPERATOR) {
4094 PL_tokenbuf[0] = '%';
4095 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
4096 if (!PL_tokenbuf[1]) {
4099 PL_pending_ident = '%';
4110 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
4111 && FEATURE_IS_ENABLED("~~"))
4118 const char tmp = *s++;
4124 goto just_a_word_zero_gv;
4127 switch (PL_expect) {
4133 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4135 PL_bufptr = s; /* update in case we back off */
4141 PL_expect = XTERMBLOCK;
4144 stuffstart = s - SvPVX(PL_linestr) - 1;
4148 while (isIDFIRST_lazy_if(s,UTF)) {
4151 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4152 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4153 if (tmp < 0) tmp = -tmp;
4168 sv = newSVpvn(s, len);
4170 d = scan_str(d,TRUE,TRUE);
4172 /* MUST advance bufptr here to avoid bogus
4173 "at end of line" context messages from yyerror().
4175 PL_bufptr = s + len;
4176 yyerror("Unterminated attribute parameter in attribute list");
4180 return REPORT(0); /* EOF indicator */
4184 sv_catsv(sv, PL_lex_stuff);
4185 attrs = append_elem(OP_LIST, attrs,
4186 newSVOP(OP_CONST, 0, sv));
4187 SvREFCNT_dec(PL_lex_stuff);
4188 PL_lex_stuff = NULL;
4191 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4193 if (PL_in_my == KEY_our) {
4195 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4197 /* skip to avoid loading attributes.pm */
4199 deprecate(":unique");
4202 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4205 /* NOTE: any CV attrs applied here need to be part of
4206 the CVf_BUILTIN_ATTRS define in cv.h! */
4207 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4209 CvLVALUE_on(PL_compcv);
4211 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4213 CvLOCKED_on(PL_compcv);
4215 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4217 CvMETHOD_on(PL_compcv);
4219 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4221 CvASSERTION_on(PL_compcv);
4223 /* After we've set the flags, it could be argued that
4224 we don't need to do the attributes.pm-based setting
4225 process, and shouldn't bother appending recognized
4226 flags. To experiment with that, uncomment the
4227 following "else". (Note that's already been
4228 uncommented. That keeps the above-applied built-in
4229 attributes from being intercepted (and possibly
4230 rejected) by a package's attribute routines, but is
4231 justified by the performance win for the common case
4232 of applying only built-in attributes.) */
4234 attrs = append_elem(OP_LIST, attrs,
4235 newSVOP(OP_CONST, 0,
4239 if (*s == ':' && s[1] != ':')
4242 break; /* require real whitespace or :'s */
4243 /* XXX losing whitespace on sequential attributes here */
4247 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4248 if (*s != ';' && *s != '}' && *s != tmp
4249 && (tmp != '=' || *s != ')')) {
4250 const char q = ((*s == '\'') ? '"' : '\'');
4251 /* If here for an expression, and parsed no attrs, back
4253 if (tmp == '=' && !attrs) {
4257 /* MUST advance bufptr here to avoid bogus "at end of line"
4258 context messages from yyerror().
4261 yyerror( (const char *)
4263 ? Perl_form(aTHX_ "Invalid separator character "
4264 "%c%c%c in attribute list", q, *s, q)
4265 : "Unterminated attribute list" ) );
4273 start_force(PL_curforce);
4274 NEXTVAL_NEXTTOKE.opval = attrs;
4275 CURMAD('_', PL_nextwhite);
4280 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4281 (s - SvPVX(PL_linestr)) - stuffstart);
4289 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4290 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4298 const char tmp = *s++;
4303 const char tmp = *s++;
4311 if (PL_lex_brackets <= 0)
4312 yyerror("Unmatched right square bracket");
4315 if (PL_lex_state == LEX_INTERPNORMAL) {
4316 if (PL_lex_brackets == 0) {
4317 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4318 PL_lex_state = LEX_INTERPEND;
4325 if (PL_lex_brackets > 100) {
4326 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4328 switch (PL_expect) {
4330 if (PL_lex_formbrack) {
4334 if (PL_oldoldbufptr == PL_last_lop)
4335 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4337 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4338 OPERATOR(HASHBRACK);
4340 while (s < PL_bufend && SPACE_OR_TAB(*s))
4343 PL_tokenbuf[0] = '\0';
4344 if (d < PL_bufend && *d == '-') {
4345 PL_tokenbuf[0] = '-';
4347 while (d < PL_bufend && SPACE_OR_TAB(*d))
4350 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4351 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4353 while (d < PL_bufend && SPACE_OR_TAB(*d))
4356 const char minus = (PL_tokenbuf[0] == '-');
4357 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4365 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4370 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4375 if (PL_oldoldbufptr == PL_last_lop)
4376 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4378 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4381 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4383 /* This hack is to get the ${} in the message. */
4385 yyerror("syntax error");
4388 OPERATOR(HASHBRACK);
4390 /* This hack serves to disambiguate a pair of curlies
4391 * as being a block or an anon hash. Normally, expectation
4392 * determines that, but in cases where we're not in a
4393 * position to expect anything in particular (like inside
4394 * eval"") we have to resolve the ambiguity. This code
4395 * covers the case where the first term in the curlies is a
4396 * quoted string. Most other cases need to be explicitly
4397 * disambiguated by prepending a "+" before the opening
4398 * curly in order to force resolution as an anon hash.
4400 * XXX should probably propagate the outer expectation
4401 * into eval"" to rely less on this hack, but that could
4402 * potentially break current behavior of eval"".
4406 if (*s == '\'' || *s == '"' || *s == '`') {
4407 /* common case: get past first string, handling escapes */
4408 for (t++; t < PL_bufend && *t != *s;)
4409 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4413 else if (*s == 'q') {
4416 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4419 /* skip q//-like construct */
4421 char open, close, term;
4424 while (t < PL_bufend && isSPACE(*t))
4426 /* check for q => */
4427 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4428 OPERATOR(HASHBRACK);
4432 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4436 for (t++; t < PL_bufend; t++) {
4437 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4439 else if (*t == open)
4443 for (t++; t < PL_bufend; t++) {
4444 if (*t == '\\' && t+1 < PL_bufend)
4446 else if (*t == close && --brackets <= 0)
4448 else if (*t == open)
4455 /* skip plain q word */
4456 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4459 else if (isALNUM_lazy_if(t,UTF)) {
4461 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4464 while (t < PL_bufend && isSPACE(*t))
4466 /* if comma follows first term, call it an anon hash */
4467 /* XXX it could be a comma expression with loop modifiers */
4468 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4469 || (*t == '=' && t[1] == '>')))
4470 OPERATOR(HASHBRACK);
4471 if (PL_expect == XREF)
4474 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4480 yylval.ival = CopLINE(PL_curcop);
4481 if (isSPACE(*s) || *s == '#')
4482 PL_copline = NOLINE; /* invalidate current command line number */
4487 if (PL_lex_brackets <= 0)
4488 yyerror("Unmatched right curly bracket");
4490 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4491 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4492 PL_lex_formbrack = 0;
4493 if (PL_lex_state == LEX_INTERPNORMAL) {
4494 if (PL_lex_brackets == 0) {
4495 if (PL_expect & XFAKEBRACK) {
4496 PL_expect &= XENUMMASK;
4497 PL_lex_state = LEX_INTERPEND;
4502 PL_thiswhite = newSVpvs("");
4503 sv_catpvn(PL_thiswhite,"}",1);
4506 return yylex(); /* ignore fake brackets */
4508 if (*s == '-' && s[1] == '>')
4509 PL_lex_state = LEX_INTERPENDMAYBE;
4510 else if (*s != '[' && *s != '{')
4511 PL_lex_state = LEX_INTERPEND;
4514 if (PL_expect & XFAKEBRACK) {
4515 PL_expect &= XENUMMASK;
4517 return yylex(); /* ignore fake brackets */
4519 start_force(PL_curforce);
4521 curmad('X', newSVpvn(s-1,1));
4522 CURMAD('_', PL_thiswhite);
4527 PL_thistoken = newSVpvs("");
4535 if (PL_expect == XOPERATOR) {
4536 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4537 && isIDFIRST_lazy_if(s,UTF))
4539 CopLINE_dec(PL_curcop);
4540 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4541 CopLINE_inc(PL_curcop);
4546 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4548 PL_expect = XOPERATOR;
4549 force_ident(PL_tokenbuf, '&');
4553 yylval.ival = (OPpENTERSUB_AMPER<<8);
4565 const char tmp = *s++;
4572 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4573 && strchr("+-*/%.^&|<",tmp))
4574 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4575 "Reversed %c= operator",(int)tmp);
4577 if (PL_expect == XSTATE && isALPHA(tmp) &&
4578 (s == PL_linestart+1 || s[-2] == '\n') )
4580 if (PL_in_eval && !PL_rsfp) {
4585 if (strnEQ(s,"=cut",4)) {
4601 PL_thiswhite = newSVpvs("");
4602 sv_catpvn(PL_thiswhite, PL_linestart,
4603 PL_bufend - PL_linestart);
4607 PL_doextract = TRUE;
4611 if (PL_lex_brackets < PL_lex_formbrack) {
4613 #ifdef PERL_STRICT_CR
4614 while (SPACE_OR_TAB(*t))
4616 while (SPACE_OR_TAB(*t) || *t == '\r')
4619 if (*t == '\n' || *t == '#') {
4630 const char tmp = *s++;
4632 /* was this !=~ where !~ was meant?
4633 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4635 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4636 const char *t = s+1;
4638 while (t < PL_bufend && isSPACE(*t))
4641 if (*t == '/' || *t == '?' ||
4642 ((*t == 'm' || *t == 's' || *t == 'y')
4643 && !isALNUM(t[1])) ||
4644 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4645 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4646 "!=~ should be !~");
4656 if (PL_expect != XOPERATOR) {
4657 if (s[1] != '<' && !strchr(s,'>'))
4660 s = scan_heredoc(s);
4662 s = scan_inputsymbol(s);
4663 TERM(sublex_start());
4669 SHop(OP_LEFT_SHIFT);
4683 const char tmp = *s++;
4685 SHop(OP_RIGHT_SHIFT);
4686 else if (tmp == '=')
4695 if (PL_expect == XOPERATOR) {
4696 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4698 deprecate_old(commaless_variable_list);
4699 return REPORT(','); /* grandfather non-comma-format format */
4703 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4704 PL_tokenbuf[0] = '@';
4705 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4706 sizeof PL_tokenbuf - 1, FALSE);
4707 if (PL_expect == XOPERATOR)
4708 no_op("Array length", s);
4709 if (!PL_tokenbuf[1])
4711 PL_expect = XOPERATOR;
4712 PL_pending_ident = '#';
4716 PL_tokenbuf[0] = '$';
4717 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4718 sizeof PL_tokenbuf - 1, FALSE);
4719 if (PL_expect == XOPERATOR)
4721 if (!PL_tokenbuf[1]) {
4723 yyerror("Final $ should be \\$ or $name");
4727 /* This kludge not intended to be bulletproof. */
4728 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4729 yylval.opval = newSVOP(OP_CONST, 0,
4730 newSViv(CopARYBASE_get(&PL_compiling)));
4731 yylval.opval->op_private = OPpCONST_ARYBASE;
4737 const char tmp = *s;
4738 if (PL_lex_state == LEX_NORMAL)
4741 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4742 && intuit_more(s)) {
4744 PL_tokenbuf[0] = '@';
4745 if (ckWARN(WARN_SYNTAX)) {
4748 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4751 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4752 while (t < PL_bufend && *t != ']')
4754 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4755 "Multidimensional syntax %.*s not supported",
4756 (int)((t - PL_bufptr) + 1), PL_bufptr);
4760 else if (*s == '{') {
4762 PL_tokenbuf[0] = '%';
4763 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4764 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4766 char tmpbuf[sizeof PL_tokenbuf];
4769 } while (isSPACE(*t));
4770 if (isIDFIRST_lazy_if(t,UTF)) {
4772 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4776 if (*t == ';' && get_cv(tmpbuf, FALSE))
4777 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4778 "You need to quote \"%s\"",
4785 PL_expect = XOPERATOR;
4786 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4787 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4788 if (!islop || PL_last_lop_op == OP_GREPSTART)
4789 PL_expect = XOPERATOR;
4790 else if (strchr("$@\"'`q", *s))
4791 PL_expect = XTERM; /* e.g. print $fh "foo" */
4792 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4793 PL_expect = XTERM; /* e.g. print $fh &sub */
4794 else if (isIDFIRST_lazy_if(s,UTF)) {
4795 char tmpbuf[sizeof PL_tokenbuf];
4797 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4798 if ((t2 = keyword(tmpbuf, len, 0))) {
4799 /* binary operators exclude handle interpretations */
4811 PL_expect = XTERM; /* e.g. print $fh length() */
4816 PL_expect = XTERM; /* e.g. print $fh subr() */
4819 else if (isDIGIT(*s))
4820 PL_expect = XTERM; /* e.g. print $fh 3 */
4821 else if (*s == '.' && isDIGIT(s[1]))
4822 PL_expect = XTERM; /* e.g. print $fh .3 */
4823 else if ((*s == '?' || *s == '-' || *s == '+')
4824 && !isSPACE(s[1]) && s[1] != '=')
4825 PL_expect = XTERM; /* e.g. print $fh -1 */
4826 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4828 PL_expect = XTERM; /* e.g. print $fh /.../
4829 XXX except DORDOR operator
4831 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4833 PL_expect = XTERM; /* print $fh <<"EOF" */
4836 PL_pending_ident = '$';
4840 if (PL_expect == XOPERATOR)
4842 PL_tokenbuf[0] = '@';
4843 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4844 if (!PL_tokenbuf[1]) {
4847 if (PL_lex_state == LEX_NORMAL)
4849 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4851 PL_tokenbuf[0] = '%';
4853 /* Warn about @ where they meant $. */
4854 if (*s == '[' || *s == '{') {
4855 if (ckWARN(WARN_SYNTAX)) {
4856 const char *t = s + 1;
4857 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4859 if (*t == '}' || *t == ']') {
4861 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4862 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4863 "Scalar value %.*s better written as $%.*s",
4864 (int)(t-PL_bufptr), PL_bufptr,
4865 (int)(t-PL_bufptr-1), PL_bufptr+1);
4870 PL_pending_ident = '@';
4873 case '/': /* may be division, defined-or, or pattern */
4874 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4878 case '?': /* may either be conditional or pattern */
4879 if(PL_expect == XOPERATOR) {
4887 /* A // operator. */
4897 /* Disable warning on "study /blah/" */
4898 if (PL_oldoldbufptr == PL_last_uni
4899 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4900 || memNE(PL_last_uni, "study", 5)
4901 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4904 s = scan_pat(s,OP_MATCH);
4905 TERM(sublex_start());
4909 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4910 #ifdef PERL_STRICT_CR
4913 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4915 && (s == PL_linestart || s[-1] == '\n') )
4917 PL_lex_formbrack = 0;
4921 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4927 yylval.ival = OPf_SPECIAL;
4933 if (PL_expect != XOPERATOR)
4938 case '0': case '1': case '2': case '3': case '4':
4939 case '5': case '6': case '7': case '8': case '9':
4940 s = scan_num(s, &yylval);
4941 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
4942 if (PL_expect == XOPERATOR)
4947 s = scan_str(s,!!PL_madskills,FALSE);
4948 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4949 if (PL_expect == XOPERATOR) {
4950 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4952 deprecate_old(commaless_variable_list);
4953 return REPORT(','); /* grandfather non-comma-format format */
4960 yylval.ival = OP_CONST;
4961 TERM(sublex_start());
4964 s = scan_str(s,!!PL_madskills,FALSE);
4965 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4966 if (PL_expect == XOPERATOR) {
4967 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4969 deprecate_old(commaless_variable_list);
4970 return REPORT(','); /* grandfather non-comma-format format */
4977 yylval.ival = OP_CONST;
4978 /* FIXME. I think that this can be const if char *d is replaced by
4979 more localised variables. */
4980 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4981 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4982 yylval.ival = OP_STRINGIFY;
4986 TERM(sublex_start());
4989 s = scan_str(s,!!PL_madskills,FALSE);
4990 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
4991 if (PL_expect == XOPERATOR)
4992 no_op("Backticks",s);
4995 readpipe_override();
4996 TERM(sublex_start());
5000 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
5001 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5003 if (PL_expect == XOPERATOR)
5004 no_op("Backslash",s);
5008 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
5009 char *start = s + 2;
5010 while (isDIGIT(*start) || *start == '_')
5012 if (*start == '.' && isDIGIT(start[1])) {
5013 s = scan_num(s, &yylval);
5016 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
5017 else if (!isALPHA(*start) && (PL_expect == XTERM
5018 || PL_expect == XREF || PL_expect == XSTATE
5019 || PL_expect == XTERMORDORDOR)) {
5020 /* XXX Use gv_fetchpvn rather than stomping on a const string */
5021 const char c = *start;
5024 gv = gv_fetchpv(s, 0, SVt_PVCV);
5027 s = scan_num(s, &yylval);
5034 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5076 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5078 /* Some keywords can be followed by any delimiter, including ':' */
5079 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5080 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5081 (PL_tokenbuf[0] == 'q' &&
5082 strchr("qwxr", PL_tokenbuf[1])))));
5084 /* x::* is just a word, unless x is "CORE" */
5085 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5089 while (d < PL_bufend && isSPACE(*d))
5090 d++; /* no comments skipped here, or s### is misparsed */
5092 /* Is this a label? */
5093 if (!tmp && PL_expect == XSTATE
5094 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5096 yylval.pval = CopLABEL_alloc(PL_tokenbuf);
5101 /* Check for keywords */
5102 tmp = keyword(PL_tokenbuf, len, 0);
5104 /* Is this a word before a => operator? */
5105 if (*d == '=' && d[1] == '>') {
5108 = (OP*)newSVOP(OP_CONST, 0,
5109 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5110 yylval.opval->op_private = OPpCONST_BARE;
5114 if (tmp < 0) { /* second-class keyword? */
5115 GV *ogv = NULL; /* override (winner) */
5116 GV *hgv = NULL; /* hidden (loser) */
5117 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5119 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5122 if (GvIMPORTED_CV(gv))
5124 else if (! CvMETHOD(cv))
5128 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5129 (gv = *gvp) != (GV*)&PL_sv_undef &&
5130 GvCVu(gv) && GvIMPORTED_CV(gv))
5137 tmp = 0; /* overridden by import or by GLOBAL */
5140 && -tmp==KEY_lock /* XXX generalizable kludge */
5142 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
5144 tmp = 0; /* any sub overrides "weak" keyword */
5146 else { /* no override */
5148 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5149 Perl_warner(aTHX_ packWARN(WARN_MISC),
5150 "dump() better written as CORE::dump()");
5154 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5155 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5156 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5157 "Ambiguous call resolved as CORE::%s(), %s",
5158 GvENAME(hgv), "qualify as such or use &");
5165 default: /* not a keyword */
5166 /* Trade off - by using this evil construction we can pull the
5167 variable gv into the block labelled keylookup. If not, then
5168 we have to give it function scope so that the goto from the
5169 earlier ':' case doesn't bypass the initialisation. */
5171 just_a_word_zero_gv:
5179 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5182 SV *nextPL_nextwhite = 0;
5186 /* Get the rest if it looks like a package qualifier */
5188 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5190 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5193 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5194 *s == '\'' ? "'" : "::");
5199 if (PL_expect == XOPERATOR) {
5200 if (PL_bufptr == PL_linestart) {
5201 CopLINE_dec(PL_curcop);
5202 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5203 CopLINE_inc(PL_curcop);
5206 no_op("Bareword",s);
5209 /* Look for a subroutine with this name in current package,
5210 unless name is "Foo::", in which case Foo is a bearword
5211 (and a package name). */
5213 if (len > 2 && !PL_madskills &&
5214 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5216 if (ckWARN(WARN_BAREWORD)
5217 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5218 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5219 "Bareword \"%s\" refers to nonexistent package",
5222 PL_tokenbuf[len] = '\0';
5228 /* Mustn't actually add anything to a symbol table.
5229 But also don't want to "initialise" any placeholder
5230 constants that might already be there into full
5231 blown PVGVs with attached PVCV. */
5232 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5233 GV_NOADD_NOINIT, SVt_PVCV);
5238 /* if we saw a global override before, get the right name */
5241 sv = newSVpvs("CORE::GLOBAL::");
5242 sv_catpv(sv,PL_tokenbuf);
5245 /* If len is 0, newSVpv does strlen(), which is correct.
5246 If len is non-zero, then it will be the true length,
5247 and so the scalar will be created correctly. */
5248 sv = newSVpv(PL_tokenbuf,len);
5251 if (PL_madskills && !PL_thistoken) {
5252 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5253 PL_thistoken = newSVpv(start,s - start);
5254 PL_realtokenstart = s - SvPVX(PL_linestr);
5258 /* Presume this is going to be a bareword of some sort. */
5261 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5262 yylval.opval->op_private = OPpCONST_BARE;
5263 /* UTF-8 package name? */
5264 if (UTF && !IN_BYTES &&
5265 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5268 /* And if "Foo::", then that's what it certainly is. */
5273 /* Do the explicit type check so that we don't need to force
5274 the initialisation of the symbol table to have a real GV.
5275 Beware - gv may not really be a PVGV, cv may not really be
5276 a PVCV, (because of the space optimisations that gv_init
5277 understands) But they're true if for this symbol there is
5278 respectively a typeglob and a subroutine.
5280 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5281 /* Real typeglob, so get the real subroutine: */
5283 /* A proxy for a subroutine in this package? */
5284 : SvOK(gv) ? (CV *) gv : NULL)
5287 /* See if it's the indirect object for a list operator. */
5289 if (PL_oldoldbufptr &&
5290 PL_oldoldbufptr < PL_bufptr &&
5291 (PL_oldoldbufptr == PL_last_lop
5292 || PL_oldoldbufptr == PL_last_uni) &&
5293 /* NO SKIPSPACE BEFORE HERE! */
5294 (PL_expect == XREF ||
5295 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5297 bool immediate_paren = *s == '(';
5299 /* (Now we can afford to cross potential line boundary.) */
5300 s = SKIPSPACE2(s,nextPL_nextwhite);
5302 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5305 /* Two barewords in a row may indicate method call. */
5307 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5308 (tmp = intuit_method(s, gv, cv)))
5311 /* If not a declared subroutine, it's an indirect object. */
5312 /* (But it's an indir obj regardless for sort.) */
5313 /* Also, if "_" follows a filetest operator, it's a bareword */
5316 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5318 (PL_last_lop_op != OP_MAPSTART &&
5319 PL_last_lop_op != OP_GREPSTART))))
5320 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5321 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5324 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5329 PL_expect = XOPERATOR;
5332 s = SKIPSPACE2(s,nextPL_nextwhite);
5333 PL_nextwhite = nextPL_nextwhite;
5338 /* Is this a word before a => operator? */
5339 if (*s == '=' && s[1] == '>' && !pkgname) {
5341 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5342 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5343 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5347 /* If followed by a paren, it's certainly a subroutine. */
5352 while (SPACE_OR_TAB(*d))
5354 if (*d == ')' && (sv = gv_const_sv(gv))) {
5358 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5359 sv_catpvn(PL_thistoken, par, s - par);
5361 sv_free(PL_nextwhite);
5371 PL_nextwhite = PL_thiswhite;
5374 start_force(PL_curforce);
5376 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5377 PL_expect = XOPERATOR;
5380 PL_nextwhite = nextPL_nextwhite;
5381 curmad('X', PL_thistoken);
5382 PL_thistoken = newSVpvs("");
5390 /* If followed by var or block, call it a method (unless sub) */
5392 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5393 PL_last_lop = PL_oldbufptr;
5394 PL_last_lop_op = OP_METHOD;
5398 /* If followed by a bareword, see if it looks like indir obj. */
5401 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5402 && (tmp = intuit_method(s, gv, cv)))
5405 /* Not a method, so call it a subroutine (if defined) */
5408 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5409 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5410 "Ambiguous use of -%s resolved as -&%s()",
5411 PL_tokenbuf, PL_tokenbuf);
5412 /* Check for a constant sub */
5413 if ((sv = gv_const_sv(gv))) {
5415 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5416 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5417 yylval.opval->op_private = 0;
5421 /* Resolve to GV now. */
5422 if (SvTYPE(gv) != SVt_PVGV) {
5423 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5424 assert (SvTYPE(gv) == SVt_PVGV);
5425 /* cv must have been some sort of placeholder, so
5426 now needs replacing with a real code reference. */
5430 op_free(yylval.opval);
5431 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5432 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5433 PL_last_lop = PL_oldbufptr;
5434 PL_last_lop_op = OP_ENTERSUB;
5435 /* Is there a prototype? */
5443 const char *proto = SvPV_const((SV*)cv, protolen);
5446 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
5448 while (*proto == ';')
5450 if (*proto == '&' && *s == '{') {
5451 sv_setpv(PL_subname,
5454 "__ANON__" : "__ANON__::__ANON__"));
5461 PL_nextwhite = PL_thiswhite;
5464 start_force(PL_curforce);
5465 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5468 PL_nextwhite = nextPL_nextwhite;
5469 curmad('X', PL_thistoken);
5470 PL_thistoken = newSVpvs("");
5477 /* Guess harder when madskills require "best effort". */
5478 if (PL_madskills && (!gv || !GvCVu(gv))) {
5479 int probable_sub = 0;
5480 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5482 else if (isALPHA(*s)) {
5486 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5487 if (!keyword(tmpbuf, tmplen, 0))
5490 while (d < PL_bufend && isSPACE(*d))
5492 if (*d == '=' && d[1] == '>')
5497 gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5498 op_free(yylval.opval);
5499 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5500 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5501 PL_last_lop = PL_oldbufptr;
5502 PL_last_lop_op = OP_ENTERSUB;
5503 PL_nextwhite = PL_thiswhite;
5505 start_force(PL_curforce);
5506 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5508 PL_nextwhite = nextPL_nextwhite;
5509 curmad('X', PL_thistoken);
5510 PL_thistoken = newSVpvs("");
5515 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5522 /* Call it a bare word */
5524 if (PL_hints & HINT_STRICT_SUBS)
5525 yylval.opval->op_private |= OPpCONST_STRICT;
5528 if (lastchar != '-') {
5529 if (ckWARN(WARN_RESERVED)) {
5533 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
5534 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5541 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5542 && ckWARN_d(WARN_AMBIGUOUS)) {
5543 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5544 "Operator or semicolon missing before %c%s",
5545 lastchar, PL_tokenbuf);
5546 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5547 "Ambiguous use of %c resolved as operator %c",
5548 lastchar, lastchar);
5554 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5555 newSVpv(CopFILE(PL_curcop),0));
5559 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5560 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5563 case KEY___PACKAGE__:
5564 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5566 ? newSVhek(HvNAME_HEK(PL_curstash))
5573 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5574 const char *pname = "main";
5575 if (PL_tokenbuf[2] == 'D')
5576 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5577 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5581 GvIOp(gv) = newIO();
5582 IoIFP(GvIOp(gv)) = PL_rsfp;
5583 #if defined(HAS_FCNTL) && defined(F_SETFD)
5585 const int fd = PerlIO_fileno(PL_rsfp);
5586 fcntl(fd,F_SETFD,fd >= 3);
5589 /* Mark this internal pseudo-handle as clean */
5590 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5592 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5593 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5594 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5596 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5597 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5598 /* if the script was opened in binmode, we need to revert
5599 * it to text mode for compatibility; but only iff it has CRs
5600 * XXX this is a questionable hack at best. */
5601 if (PL_bufend-PL_bufptr > 2
5602 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5605 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5606 loc = PerlIO_tell(PL_rsfp);
5607 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5610 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5612 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5613 #endif /* NETWARE */
5614 #ifdef PERLIO_IS_STDIO /* really? */
5615 # if defined(__BORLANDC__)
5616 /* XXX see note in do_binmode() */
5617 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5621 PerlIO_seek(PL_rsfp, loc, 0);
5625 #ifdef PERLIO_LAYERS
5628 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5629 else if (PL_encoding) {
5636 XPUSHs(PL_encoding);
5638 call_method("name", G_SCALAR);
5642 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5643 Perl_form(aTHX_ ":encoding(%"SVf")",
5652 if (PL_realtokenstart >= 0) {
5653 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5655 PL_endwhite = newSVpvs("");
5656 sv_catsv(PL_endwhite, PL_thiswhite);
5658 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5659 PL_realtokenstart = -1;
5661 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5662 SvCUR(PL_endwhite))) != Nullch) ;
5677 if (PL_expect == XSTATE) {
5684 if (*s == ':' && s[1] == ':') {
5687 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5688 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5689 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5692 else if (tmp == KEY_require || tmp == KEY_do)
5693 /* that's a way to remember we saw "CORE::" */
5706 LOP(OP_ACCEPT,XTERM);
5712 LOP(OP_ATAN2,XTERM);
5718 LOP(OP_BINMODE,XTERM);
5721 LOP(OP_BLESS,XTERM);
5730 /* When 'use switch' is in effect, continue has a dual
5731 life as a control operator. */
5733 if (!FEATURE_IS_ENABLED("switch"))
5736 /* We have to disambiguate the two senses of
5737 "continue". If the next token is a '{' then
5738 treat it as the start of a continue block;
5739 otherwise treat it as a control operator.
5751 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5768 if (!PL_cryptseen) {
5769 PL_cryptseen = TRUE;
5773 LOP(OP_CRYPT,XTERM);
5776 LOP(OP_CHMOD,XTERM);
5779 LOP(OP_CHOWN,XTERM);
5782 LOP(OP_CONNECT,XTERM);
5801 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5802 if (orig_keyword == KEY_do) {
5811 PL_hints |= HINT_BLOCK_SCOPE;
5821 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5822 LOP(OP_DBMOPEN,XTERM);
5828 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5835 yylval.ival = CopLINE(PL_curcop);
5851 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5852 UNIBRACK(OP_ENTEREVAL);
5870 case KEY_endhostent:
5876 case KEY_endservent:
5879 case KEY_endprotoent:
5890 yylval.ival = CopLINE(PL_curcop);
5892 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5895 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5898 if ((PL_bufend - p) >= 3 &&
5899 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5901 else if ((PL_bufend - p) >= 4 &&
5902 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5905 if (isIDFIRST_lazy_if(p,UTF)) {
5906 p = scan_ident(p, PL_bufend,
5907 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5911 Perl_croak(aTHX_ "Missing $ on loop variable");
5913 s = SvPVX(PL_linestr) + soff;
5919 LOP(OP_FORMLINE,XTERM);
5925 LOP(OP_FCNTL,XTERM);
5931 LOP(OP_FLOCK,XTERM);
5940 LOP(OP_GREPSTART, XREF);
5943 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5958 case KEY_getpriority:
5959 LOP(OP_GETPRIORITY,XTERM);
5961 case KEY_getprotobyname:
5964 case KEY_getprotobynumber:
5965 LOP(OP_GPBYNUMBER,XTERM);
5967 case KEY_getprotoent:
5979 case KEY_getpeername:
5980 UNI(OP_GETPEERNAME);
5982 case KEY_gethostbyname:
5985 case KEY_gethostbyaddr:
5986 LOP(OP_GHBYADDR,XTERM);
5988 case KEY_gethostent:
5991 case KEY_getnetbyname:
5994 case KEY_getnetbyaddr:
5995 LOP(OP_GNBYADDR,XTERM);
6000 case KEY_getservbyname:
6001 LOP(OP_GSBYNAME,XTERM);
6003 case KEY_getservbyport:
6004 LOP(OP_GSBYPORT,XTERM);
6006 case KEY_getservent:
6009 case KEY_getsockname:
6010 UNI(OP_GETSOCKNAME);
6012 case KEY_getsockopt:
6013 LOP(OP_GSOCKOPT,XTERM);
6028 yylval.ival = CopLINE(PL_curcop);
6039 yylval.ival = CopLINE(PL_curcop);
6043 LOP(OP_INDEX,XTERM);
6049 LOP(OP_IOCTL,XTERM);
6061 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6093 LOP(OP_LISTEN,XTERM);
6102 s = scan_pat(s,OP_MATCH);
6103 TERM(sublex_start());
6106 LOP(OP_MAPSTART, XREF);
6109 LOP(OP_MKDIR,XTERM);
6112 LOP(OP_MSGCTL,XTERM);
6115 LOP(OP_MSGGET,XTERM);
6118 LOP(OP_MSGRCV,XTERM);
6121 LOP(OP_MSGSND,XTERM);
6128 if (isIDFIRST_lazy_if(s,UTF)) {
6132 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6133 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6135 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6136 if (!PL_in_my_stash) {
6139 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6143 if (PL_madskills) { /* just add type to declarator token */
6144 sv_catsv(PL_thistoken, PL_nextwhite);
6146 sv_catpvn(PL_thistoken, start, s - start);
6154 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6161 s = tokenize_use(0, s);
6165 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6172 if (isIDFIRST_lazy_if(s,UTF)) {
6174 for (d = s; isALNUM_lazy_if(d,UTF);)
6176 for (t=d; isSPACE(*t);)
6178 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6180 && !(t[0] == '=' && t[1] == '>')
6182 int parms_len = (int)(d-s);
6183 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6184 "Precedence problem: open %.*s should be open(%.*s)",
6185 parms_len, s, parms_len, s);
6191 yylval.ival = OP_OR;
6201 LOP(OP_OPEN_DIR,XTERM);
6204 checkcomma(s,PL_tokenbuf,"filehandle");
6208 checkcomma(s,PL_tokenbuf,"filehandle");
6227 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6231 LOP(OP_PIPE_OP,XTERM);
6234 s = scan_str(s,!!PL_madskills,FALSE);
6237 yylval.ival = OP_CONST;
6238 TERM(sublex_start());
6244 s = scan_str(s,!!PL_madskills,FALSE);
6247 PL_expect = XOPERATOR;
6249 if (SvCUR(PL_lex_stuff)) {
6252 d = SvPV_force(PL_lex_stuff, len);
6254 for (; isSPACE(*d) && len; --len, ++d)
6259 if (!warned && ckWARN(WARN_QW)) {
6260 for (; !isSPACE(*d) && len; --len, ++d) {
6262 Perl_warner(aTHX_ packWARN(WARN_QW),
6263 "Possible attempt to separate words with commas");
6266 else if (*d == '#') {
6267 Perl_warner(aTHX_ packWARN(WARN_QW),
6268 "Possible attempt to put comments in qw() list");
6274 for (; !isSPACE(*d) && len; --len, ++d)
6277 sv = newSVpvn(b, d-b);
6278 if (DO_UTF8(PL_lex_stuff))
6280 words = append_elem(OP_LIST, words,
6281 newSVOP(OP_CONST, 0, tokeq(sv)));
6285 start_force(PL_curforce);
6286 NEXTVAL_NEXTTOKE.opval = words;
6291 SvREFCNT_dec(PL_lex_stuff);
6292 PL_lex_stuff = NULL;
6298 s = scan_str(s,!!PL_madskills,FALSE);
6301 yylval.ival = OP_STRINGIFY;
6302 if (SvIVX(PL_lex_stuff) == '\'')
6303 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6304 TERM(sublex_start());
6307 s = scan_pat(s,OP_QR);
6308 TERM(sublex_start());
6311 s = scan_str(s,!!PL_madskills,FALSE);
6314 readpipe_override();
6315 TERM(sublex_start());
6323 s = force_version(s, FALSE);
6325 else if (*s != 'v' || !isDIGIT(s[1])
6326 || (s = force_version(s, TRUE), *s == 'v'))
6328 *PL_tokenbuf = '\0';
6329 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6330 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6331 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6333 yyerror("<> should be quotes");
6335 if (orig_keyword == KEY_require) {
6343 PL_last_uni = PL_oldbufptr;
6344 PL_last_lop_op = OP_REQUIRE;
6346 return REPORT( (int)REQUIRE );
6352 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6356 LOP(OP_RENAME,XTERM);
6365 LOP(OP_RINDEX,XTERM);
6375 UNIDOR(OP_READLINE);
6388 LOP(OP_REVERSE,XTERM);
6391 UNIDOR(OP_READLINK);
6399 TERM(sublex_start());
6401 TOKEN(1); /* force error */
6404 checkcomma(s,PL_tokenbuf,"filehandle");
6414 LOP(OP_SELECT,XTERM);
6420 LOP(OP_SEMCTL,XTERM);
6423 LOP(OP_SEMGET,XTERM);
6426 LOP(OP_SEMOP,XTERM);
6432 LOP(OP_SETPGRP,XTERM);
6434 case KEY_setpriority:
6435 LOP(OP_SETPRIORITY,XTERM);
6437 case KEY_sethostent:
6443 case KEY_setservent:
6446 case KEY_setprotoent:
6456 LOP(OP_SEEKDIR,XTERM);
6458 case KEY_setsockopt:
6459 LOP(OP_SSOCKOPT,XTERM);
6465 LOP(OP_SHMCTL,XTERM);
6468 LOP(OP_SHMGET,XTERM);
6471 LOP(OP_SHMREAD,XTERM);
6474 LOP(OP_SHMWRITE,XTERM);
6477 LOP(OP_SHUTDOWN,XTERM);
6486 LOP(OP_SOCKET,XTERM);
6488 case KEY_socketpair:
6489 LOP(OP_SOCKPAIR,XTERM);
6492 checkcomma(s,PL_tokenbuf,"subroutine name");
6494 if (*s == ';' || *s == ')') /* probably a close */
6495 Perl_croak(aTHX_ "sort is now a reserved word");
6497 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6501 LOP(OP_SPLIT,XTERM);
6504 LOP(OP_SPRINTF,XTERM);
6507 LOP(OP_SPLICE,XTERM);
6522 LOP(OP_SUBSTR,XTERM);
6528 char tmpbuf[sizeof PL_tokenbuf];
6529 SSize_t tboffset = 0;
6530 expectation attrful;
6531 bool have_name, have_proto;
6532 const int key = tmp;
6537 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6538 SV *subtoken = newSVpvn(tstart, s - tstart);
6542 s = SKIPSPACE2(s,tmpwhite);
6547 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6548 (*s == ':' && s[1] == ':'))
6555 attrful = XATTRBLOCK;
6556 /* remember buffer pos'n for later force_word */
6557 tboffset = s - PL_oldbufptr;
6558 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6561 nametoke = newSVpvn(s, d - s);
6563 if (strchr(tmpbuf, ':'))
6564 sv_setpv(PL_subname, tmpbuf);
6566 sv_setsv(PL_subname,PL_curstname);
6567 sv_catpvs(PL_subname,"::");
6568 sv_catpvn(PL_subname,tmpbuf,len);
6575 CURMAD('X', nametoke);
6576 CURMAD('_', tmpwhite);
6577 (void) force_word(PL_oldbufptr + tboffset, WORD,
6580 s = SKIPSPACE2(d,tmpwhite);
6587 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6588 PL_expect = XTERMBLOCK;
6589 attrful = XATTRTERM;
6590 sv_setpvn(PL_subname,"?",1);
6594 if (key == KEY_format) {
6596 PL_lex_formbrack = PL_lex_brackets + 1;
6598 PL_thistoken = subtoken;
6602 (void) force_word(PL_oldbufptr + tboffset, WORD,
6608 /* Look for a prototype */
6611 bool bad_proto = FALSE;
6612 const bool warnsyntax = ckWARN(WARN_SYNTAX);
6614 s = scan_str(s,!!PL_madskills,FALSE);
6616 Perl_croak(aTHX_ "Prototype not terminated");
6617 /* strip spaces and check for bad characters */
6618 d = SvPVX(PL_lex_stuff);
6620 for (p = d; *p; ++p) {
6623 if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
6629 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6630 "Illegal character in prototype for %"SVf" : %s",
6631 (void*)PL_subname, d);
6632 SvCUR_set(PL_lex_stuff, tmp);
6637 CURMAD('q', PL_thisopen);
6638 CURMAD('_', tmpwhite);
6639 CURMAD('=', PL_thisstuff);
6640 CURMAD('Q', PL_thisclose);
6641 NEXTVAL_NEXTTOKE.opval =
6642 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6643 PL_lex_stuff = Nullsv;
6646 s = SKIPSPACE2(s,tmpwhite);
6654 if (*s == ':' && s[1] != ':')
6655 PL_expect = attrful;
6656 else if (*s != '{' && key == KEY_sub) {
6658 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6660 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, (void*)PL_subname);
6667 curmad('^', newSVpvs(""));
6668 CURMAD('_', tmpwhite);
6672 PL_thistoken = subtoken;
6675 NEXTVAL_NEXTTOKE.opval =
6676 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6677 PL_lex_stuff = NULL;
6682 sv_setpv(PL_subname,
6684 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
6688 (void) force_word(PL_oldbufptr + tboffset, WORD,
6698 LOP(OP_SYSTEM,XREF);
6701 LOP(OP_SYMLINK,XTERM);
6704 LOP(OP_SYSCALL,XTERM);
6707 LOP(OP_SYSOPEN,XTERM);
6710 LOP(OP_SYSSEEK,XTERM);
6713 LOP(OP_SYSREAD,XTERM);
6716 LOP(OP_SYSWRITE,XTERM);
6720 TERM(sublex_start());
6741 LOP(OP_TRUNCATE,XTERM);
6753 yylval.ival = CopLINE(PL_curcop);
6757 yylval.ival = CopLINE(PL_curcop);
6761 LOP(OP_UNLINK,XTERM);
6767 LOP(OP_UNPACK,XTERM);
6770 LOP(OP_UTIME,XTERM);
6776 LOP(OP_UNSHIFT,XTERM);
6779 s = tokenize_use(1, s);
6789 yylval.ival = CopLINE(PL_curcop);
6793 yylval.ival = CopLINE(PL_curcop);
6797 PL_hints |= HINT_BLOCK_SCOPE;
6804 LOP(OP_WAITPID,XTERM);
6813 ctl_l[0] = toCTRL('L');
6815 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6818 /* Make sure $^L is defined */
6819 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6824 if (PL_expect == XOPERATOR)
6830 yylval.ival = OP_XOR;
6835 TERM(sublex_start());
6840 #pragma segment Main
6844 S_pending_ident(pTHX)
6849 /* pit holds the identifier we read and pending_ident is reset */
6850 char pit = PL_pending_ident;
6851 PL_pending_ident = 0;
6853 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6854 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6855 "### Pending identifier '%s'\n", PL_tokenbuf); });
6857 /* if we're in a my(), we can't allow dynamics here.
6858 $foo'bar has already been turned into $foo::bar, so
6859 just check for colons.
6861 if it's a legal name, the OP is a PADANY.
6864 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6865 if (strchr(PL_tokenbuf,':'))
6866 yyerror(Perl_form(aTHX_ "No package name allowed for "
6867 "variable %s in \"our\"",
6869 tmp = allocmy(PL_tokenbuf);
6872 if (strchr(PL_tokenbuf,':'))
6873 yyerror(Perl_form(aTHX_ PL_no_myglob,
6874 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6876 yylval.opval = newOP(OP_PADANY, 0);
6877 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6883 build the ops for accesses to a my() variable.
6885 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6886 then used in a comparison. This catches most, but not
6887 all cases. For instance, it catches
6888 sort { my($a); $a <=> $b }
6890 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6891 (although why you'd do that is anyone's guess).
6894 if (!strchr(PL_tokenbuf,':')) {
6896 tmp = pad_findmy(PL_tokenbuf);
6897 if (tmp != NOT_IN_PAD) {
6898 /* might be an "our" variable" */
6899 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6900 /* build ops for a bareword */
6901 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6902 HEK * const stashname = HvNAME_HEK(stash);
6903 SV * const sym = newSVhek(stashname);
6904 sv_catpvs(sym, "::");
6905 sv_catpv(sym, PL_tokenbuf+1);
6906 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6907 yylval.opval->op_private = OPpCONST_ENTERED;
6910 ? (GV_ADDMULTI | GV_ADDINEVAL)
6913 ((PL_tokenbuf[0] == '$') ? SVt_PV
6914 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6919 /* if it's a sort block and they're naming $a or $b */
6920 if (PL_last_lop_op == OP_SORT &&
6921 PL_tokenbuf[0] == '$' &&
6922 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6925 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6926 d < PL_bufend && *d != '\n';
6929 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6930 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6936 yylval.opval = newOP(OP_PADANY, 0);
6937 yylval.opval->op_targ = tmp;
6943 Whine if they've said @foo in a doublequoted string,
6944 and @foo isn't a variable we can find in the symbol
6947 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6948 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6949 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6950 && ckWARN(WARN_AMBIGUOUS))
6952 /* Downgraded from fatal to warning 20000522 mjd */
6953 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6954 "Possible unintended interpolation of %s in string",
6959 /* build ops for a bareword */
6960 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6961 yylval.opval->op_private = OPpCONST_ENTERED;
6964 /* If the identifier refers to a stash, don't autovivify it.
6965 * Change 24660 had the side effect of causing symbol table
6966 * hashes to always be defined, even if they were freshly
6967 * created and the only reference in the entire program was
6968 * the single statement with the defined %foo::bar:: test.
6969 * It appears that all code in the wild doing this actually
6970 * wants to know whether sub-packages have been loaded, so
6971 * by avoiding auto-vivifying symbol tables, we ensure that
6972 * defined %foo::bar:: continues to be false, and the existing
6973 * tests still give the expected answers, even though what
6974 * they're actually testing has now changed subtly.
6976 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6978 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
6979 ((PL_tokenbuf[0] == '$') ? SVt_PV
6980 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6986 * The following code was generated by perl_keyword.pl.
6990 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
6995 case 1: /* 5 tokens of length 1 */
7027 case 2: /* 18 tokens of length 2 */
7173 case 3: /* 29 tokens of length 3 */
7177 if (name[1] == 'N' &&
7240 if (name[1] == 'i' &&
7262 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7280 if (name[1] == 'o' &&
7289 if (name[1] == 'e' &&
7298 if (name[1] == 'n' &&
7307 if (name[1] == 'o' &&
7316 if (name[1] == 'a' &&
7325 if (name[1] == 'o' &&
7387 if (name[1] == 'e' &&
7401 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
7427 if (name[1] == 'i' &&
7436 if (name[1] == 's' &&
7445 if (name[1] == 'e' &&
7454 if (name[1] == 'o' &&
7466 case 4: /* 41 tokens of length 4 */
7470 if (name[1] == 'O' &&
7480 if (name[1] == 'N' &&
7490 if (name[1] == 'i' &&
7500 if (name[1] == 'h' &&
7510 if (name[1] == 'u' &&
7523 if (name[2] == 'c' &&
7532 if (name[2] == 's' &&
7541 if (name[2] == 'a' &&
7577 if (name[1] == 'o' &&
7590 if (name[2] == 't' &&
7599 if (name[2] == 'o' &&
7608 if (name[2] == 't' &&
7617 if (name[2] == 'e' &&
7630 if (name[1] == 'o' &&
7643 if (name[2] == 'y' &&
7652 if (name[2] == 'l' &&
7668 if (name[2] == 's' &&
7677 if (name[2] == 'n' &&
7686 if (name[2] == 'c' &&
7699 if (name[1] == 'e' &&
7709 if (name[1] == 'p' &&
7722 if (name[2] == 'c' &&
7731 if (name[2] == 'p' &&
7740 if (name[2] == 's' &&
7756 if (name[2] == 'n' &&
7826 if (name[2] == 'r' &&
7835 if (name[2] == 'r' &&
7844 if (name[2] == 'a' &&
7860 if (name[2] == 'l' &&
7922 if (name[2] == 'e' &&
7925 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7938 case 5: /* 39 tokens of length 5 */
7942 if (name[1] == 'E' &&
7953 if (name[1] == 'H' &&
7967 if (name[2] == 'a' &&
7977 if (name[2] == 'a' &&
7994 if (name[2] == 'e' &&
8004 if (name[2] == 'e' &&
8008 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
8024 if (name[3] == 'i' &&
8033 if (name[3] == 'o' &&
8069 if (name[2] == 'o' &&
8079 if (name[2] == 'y' &&
8093 if (name[1] == 'l' &&
8107 if (name[2] == 'n' &&
8117 if (name[2] == 'o' &&
8131 if (name[1] == 'i' &&
8136 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8145 if (name[2] == 'd' &&
8155 if (name[2] == 'c' &&
8172 if (name[2] == 'c' &&
8182 if (name[2] == 't' &&
8196 if (name[1] == 'k' &&
8207 if (name[1] == 'r' &&
8221 if (name[2] == 's' &&
8231 if (name[2] == 'd' &&
8248 if (name[2] == 'm' &&
8258 if (name[2] == 'i' &&
8268 if (name[2] == 'e' &&
8278 if (name[2] == 'l' &&
8288 if (name[2] == 'a' &&
8301 if (name[3] == 't' &&
8304 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8310 if (name[3] == 'd' &&
8327 if (name[1] == 'i' &&
8341 if (name[2] == 'a' &&
8354 if (name[3] == 'e' &&
8389 if (name[2] == 'i' &&
8406 if (name[2] == 'i' &&
8416 if (name[2] == 'i' &&
8433 case 6: /* 33 tokens of length 6 */
8437 if (name[1] == 'c' &&
8452 if (name[2] == 'l' &&
8463 if (name[2] == 'r' &&
8478 if (name[1] == 'e' &&
8493 if (name[2] == 's' &&
8498 if(ckWARN_d(WARN_SYNTAX))
8499 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8505 if (name[2] == 'i' &&
8523 if (name[2] == 'l' &&
8534 if (name[2] == 'r' &&
8549 if (name[1] == 'm' &&
8564 if (name[2] == 'n' &&
8575 if (name[2] == 's' &&
8590 if (name[1] == 's' &&
8596 if (name[4] == 't' &&
8605 if (name[4] == 'e' &&
8614 if (name[4] == 'c' &&
8623 if (name[4] == 'n' &&
8639 if (name[1] == 'r' &&
8657 if (name[3] == 'a' &&
8667 if (name[3] == 'u' &&
8681 if (name[2] == 'n' &&
8699 if (name[2] == 'a' &&
8713 if (name[3] == 'e' &&
8726 if (name[4] == 't' &&
8735 if (name[4] == 'e' &&
8757 if (name[4] == 't' &&
8766 if (name[4] == 'e' &&
8782 if (name[2] == 'c' &&
8793 if (name[2] == 'l' &&
8804 if (name[2] == 'b' &&
8815 if (name[2] == 's' &&
8838 if (name[4] == 's' &&
8847 if (name[4] == 'n' &&
8860 if (name[3] == 'a' &&
8877 if (name[1] == 'a' &&
8892 case 7: /* 29 tokens of length 7 */
8896 if (name[1] == 'E' &&
8909 if (name[1] == '_' &&
8922 if (name[1] == 'i' &&
8929 return -KEY_binmode;
8935 if (name[1] == 'o' &&
8942 return -KEY_connect;
8951 if (name[2] == 'm' &&
8957 return -KEY_dbmopen;
8968 if (name[4] == 'u' &&
8972 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
8978 if (name[4] == 'n' &&
8999 if (name[1] == 'o' &&
9012 if (name[1] == 'e' &&
9019 if (name[5] == 'r' &&
9022 return -KEY_getpgrp;
9028 if (name[5] == 'i' &&
9031 return -KEY_getppid;
9044 if (name[1] == 'c' &&
9051 return -KEY_lcfirst;
9057 if (name[1] == 'p' &&
9064 return -KEY_opendir;
9070 if (name[1] == 'a' &&
9088 if (name[3] == 'd' &&
9093 return -KEY_readdir;
9099 if (name[3] == 'u' &&
9110 if (name[3] == 'e' &&
9115 return -KEY_reverse;
9134 if (name[3] == 'k' &&
9139 return -KEY_seekdir;
9145 if (name[3] == 'p' &&
9150 return -KEY_setpgrp;
9160 if (name[2] == 'm' &&
9166 return -KEY_shmread;
9172 if (name[2] == 'r' &&
9178 return -KEY_sprintf;
9187 if (name[3] == 'l' &&
9192 return -KEY_symlink;
9201 if (name[4] == 'a' &&
9205 return -KEY_syscall;
9211 if (name[4] == 'p' &&
9215 return -KEY_sysopen;
9221 if (name[4] == 'e' &&
9225 return -KEY_sysread;
9231 if (name[4] == 'e' &&
9235 return -KEY_sysseek;
9253 if (name[1] == 'e' &&
9260 return -KEY_telldir;
9269 if (name[2] == 'f' &&
9275 return -KEY_ucfirst;
9281 if (name[2] == 's' &&
9287 return -KEY_unshift;
9297 if (name[1] == 'a' &&
9304 return -KEY_waitpid;
9313 case 8: /* 26 tokens of length 8 */
9317 if (name[1] == 'U' &&
9325 return KEY_AUTOLOAD;
9336 if (name[3] == 'A' &&
9342 return KEY___DATA__;
9348 if (name[3] == 'I' &&
9354 return -KEY___FILE__;
9360 if (name[3] == 'I' &&
9366 return -KEY___LINE__;
9382 if (name[2] == 'o' &&
9389 return -KEY_closedir;
9395 if (name[2] == 'n' &&
9402 return -KEY_continue;
9412 if (name[1] == 'b' &&
9420 return -KEY_dbmclose;
9426 if (name[1] == 'n' &&
9432 if (name[4] == 'r' &&
9437 return -KEY_endgrent;
9443 if (name[4] == 'w' &&
9448 return -KEY_endpwent;
9461 if (name[1] == 'o' &&
9469 return -KEY_formline;
9475 if (name[1] == 'e' &&
9486 if (name[6] == 'n' &&
9489 return -KEY_getgrent;
9495 if (name[6] == 'i' &&
9498 return -KEY_getgrgid;
9504 if (name[6] == 'a' &&
9507 return -KEY_getgrnam;
9520 if (name[4] == 'o' &&
9525 return -KEY_getlogin;
9536 if (name[6] == 'n' &&
9539 return -KEY_getpwent;
9545 if (name[6] == 'a' &&
9548 return -KEY_getpwnam;
9554 if (name[6] == 'i' &&
9557 return -KEY_getpwuid;
9577 if (name[1] == 'e' &&
9584 if (name[5] == 'i' &&
9591 return -KEY_readline;
9596 return -KEY_readlink;
9607 if (name[5] == 'i' &&
9611 return -KEY_readpipe;
9632 if (name[4] == 'r' &&
9637 return -KEY_setgrent;
9643 if (name[4] == 'w' &&
9648 return -KEY_setpwent;
9664 if (name[3] == 'w' &&
9670 return -KEY_shmwrite;
9676 if (name[3] == 't' &&
9682 return -KEY_shutdown;
9692 if (name[2] == 's' &&
9699 return -KEY_syswrite;
9709 if (name[1] == 'r' &&
9717 return -KEY_truncate;
9726 case 9: /* 9 tokens of length 9 */
9730 if (name[1] == 'N' &&
9739 return KEY_UNITCHECK;
9745 if (name[1] == 'n' &&
9754 return -KEY_endnetent;
9760 if (name[1] == 'e' &&
9769 return -KEY_getnetent;
9775 if (name[1] == 'o' &&
9784 return -KEY_localtime;
9790 if (name[1] == 'r' &&
9799 return KEY_prototype;
9805 if (name[1] == 'u' &&
9814 return -KEY_quotemeta;
9820 if (name[1] == 'e' &&
9829 return -KEY_rewinddir;
9835 if (name[1] == 'e' &&
9844 return -KEY_setnetent;
9850 if (name[1] == 'a' &&
9859 return -KEY_wantarray;
9868 case 10: /* 9 tokens of length 10 */
9872 if (name[1] == 'n' &&
9878 if (name[4] == 'o' &&
9885 return -KEY_endhostent;
9891 if (name[4] == 'e' &&
9898 return -KEY_endservent;
9911 if (name[1] == 'e' &&
9917 if (name[4] == 'o' &&
9924 return -KEY_gethostent;
9933 if (name[5] == 'r' &&
9939 return -KEY_getservent;
9945 if (name[5] == 'c' &&
9951 return -KEY_getsockopt;
9976 if (name[4] == 'o' &&
9983 return -KEY_sethostent;
9992 if (name[5] == 'r' &&
9998 return -KEY_setservent;
10004 if (name[5] == 'c' &&
10010 return -KEY_setsockopt;
10027 if (name[2] == 'c' &&
10036 return -KEY_socketpair;
10049 case 11: /* 8 tokens of length 11 */
10053 if (name[1] == '_' &&
10063 { /* __PACKAGE__ */
10064 return -KEY___PACKAGE__;
10070 if (name[1] == 'n' &&
10080 { /* endprotoent */
10081 return -KEY_endprotoent;
10087 if (name[1] == 'e' &&
10096 if (name[5] == 'e' &&
10102 { /* getpeername */
10103 return -KEY_getpeername;
10112 if (name[6] == 'o' &&
10117 { /* getpriority */
10118 return -KEY_getpriority;
10124 if (name[6] == 't' &&
10129 { /* getprotoent */
10130 return -KEY_getprotoent;
10144 if (name[4] == 'o' &&
10151 { /* getsockname */
10152 return -KEY_getsockname;
10165 if (name[1] == 'e' &&
10173 if (name[6] == 'o' &&
10178 { /* setpriority */
10179 return -KEY_setpriority;
10185 if (name[6] == 't' &&
10190 { /* setprotoent */
10191 return -KEY_setprotoent;
10207 case 12: /* 2 tokens of length 12 */
10208 if (name[0] == 'g' &&
10220 if (name[9] == 'd' &&
10223 { /* getnetbyaddr */
10224 return -KEY_getnetbyaddr;
10230 if (name[9] == 'a' &&
10233 { /* getnetbyname */
10234 return -KEY_getnetbyname;
10246 case 13: /* 4 tokens of length 13 */
10247 if (name[0] == 'g' &&
10254 if (name[4] == 'o' &&
10263 if (name[10] == 'd' &&
10266 { /* gethostbyaddr */
10267 return -KEY_gethostbyaddr;
10273 if (name[10] == 'a' &&
10276 { /* gethostbyname */
10277 return -KEY_gethostbyname;
10290 if (name[4] == 'e' &&
10299 if (name[10] == 'a' &&
10302 { /* getservbyname */
10303 return -KEY_getservbyname;
10309 if (name[10] == 'o' &&
10312 { /* getservbyport */
10313 return -KEY_getservbyport;
10332 case 14: /* 1 tokens of length 14 */
10333 if (name[0] == 'g' &&
10347 { /* getprotobyname */
10348 return -KEY_getprotobyname;
10353 case 16: /* 1 tokens of length 16 */
10354 if (name[0] == 'g' &&
10370 { /* getprotobynumber */
10371 return -KEY_getprotobynumber;
10385 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10389 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10390 if (ckWARN(WARN_SYNTAX)) {
10393 for (w = s+2; *w && level; w++) {
10396 else if (*w == ')')
10399 while (isSPACE(*w))
10401 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
10402 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10403 "%s (...) interpreted as function",name);
10406 while (s < PL_bufend && isSPACE(*s))
10410 while (s < PL_bufend && isSPACE(*s))
10412 if (isIDFIRST_lazy_if(s,UTF)) {
10413 const char * const w = s++;
10414 while (isALNUM_lazy_if(s,UTF))
10416 while (s < PL_bufend && isSPACE(*s))
10420 if (keyword(w, s - w, 0))
10423 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10424 if (gv && GvCVu(gv))
10426 Perl_croak(aTHX_ "No comma allowed after %s", what);
10431 /* Either returns sv, or mortalizes sv and returns a new SV*.
10432 Best used as sv=new_constant(..., sv, ...).
10433 If s, pv are NULL, calls subroutine with one argument,
10434 and type is used with error messages only. */
10437 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10441 HV * const table = GvHV(PL_hintgv); /* ^H */
10445 const char *why1 = "", *why2 = "", *why3 = "";
10447 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10450 why2 = (const char *)
10451 (strEQ(key,"charnames")
10452 ? "(possibly a missing \"use charnames ...\")"
10454 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10455 (type ? type: "undef"), why2);
10457 /* This is convoluted and evil ("goto considered harmful")
10458 * but I do not understand the intricacies of all the different
10459 * failure modes of %^H in here. The goal here is to make
10460 * the most probable error message user-friendly. --jhi */
10465 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10466 (type ? type: "undef"), why1, why2, why3);
10468 yyerror(SvPVX_const(msg));
10472 cvp = hv_fetch(table, key, strlen(key), FALSE);
10473 if (!cvp || !SvOK(*cvp)) {
10476 why3 = "} is not defined";
10479 sv_2mortal(sv); /* Parent created it permanently */
10482 pv = sv_2mortal(newSVpvn(s, len));
10484 typesv = sv_2mortal(newSVpv(type, 0));
10486 typesv = &PL_sv_undef;
10488 PUSHSTACKi(PERLSI_OVERLOAD);
10500 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10504 /* Check the eval first */
10505 if (!PL_in_eval && SvTRUE(ERRSV)) {
10506 sv_catpvs(ERRSV, "Propagated");
10507 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10509 res = SvREFCNT_inc_simple(sv);
10513 SvREFCNT_inc_simple_void(res);
10522 why1 = "Call to &{$^H{";
10524 why3 = "}} did not return a defined value";
10532 /* Returns a NUL terminated string, with the length of the string written to
10536 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10539 register char *d = dest;
10540 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10543 Perl_croak(aTHX_ ident_too_long);
10544 if (isALNUM(*s)) /* UTF handled below */
10546 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10551 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10555 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10556 char *t = s + UTF8SKIP(s);
10558 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10562 Perl_croak(aTHX_ ident_too_long);
10563 Copy(s, d, len, char);
10576 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10579 char *bracket = NULL;
10581 register char *d = dest;
10582 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10587 while (isDIGIT(*s)) {
10589 Perl_croak(aTHX_ ident_too_long);
10596 Perl_croak(aTHX_ ident_too_long);
10597 if (isALNUM(*s)) /* UTF handled below */
10599 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10604 else if (*s == ':' && s[1] == ':') {
10608 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10609 char *t = s + UTF8SKIP(s);
10610 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10612 if (d + (t - s) > e)
10613 Perl_croak(aTHX_ ident_too_long);
10614 Copy(s, d, t - s, char);
10625 if (PL_lex_state != LEX_NORMAL)
10626 PL_lex_state = LEX_INTERPENDMAYBE;
10629 if (*s == '$' && s[1] &&
10630 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10643 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10648 if (isSPACE(s[-1])) {
10650 const char ch = *s++;
10651 if (!SPACE_OR_TAB(ch)) {
10657 if (isIDFIRST_lazy_if(d,UTF)) {
10661 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10662 end += UTF8SKIP(end);
10663 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10664 end += UTF8SKIP(end);
10666 Copy(s, d, end - s, char);
10671 while ((isALNUM(*s) || *s == ':') && d < e)
10674 Perl_croak(aTHX_ ident_too_long);
10677 while (s < send && SPACE_OR_TAB(*s))
10679 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10680 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10681 const char * const brack =
10683 ((*s == '[') ? "[...]" : "{...}");
10684 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10685 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10686 funny, dest, brack, funny, dest, brack);
10689 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10693 /* Handle extended ${^Foo} variables
10694 * 1999-02-27 mjd-perl-patch@plover.com */
10695 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10699 while (isALNUM(*s) && d < e) {
10703 Perl_croak(aTHX_ ident_too_long);
10708 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10709 PL_lex_state = LEX_INTERPEND;
10712 if (PL_lex_state == LEX_NORMAL) {
10713 if (ckWARN(WARN_AMBIGUOUS) &&
10714 (keyword(dest, d - dest, 0) || get_cv(dest, FALSE)))
10718 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10719 "Ambiguous use of %c{%s} resolved to %c%s",
10720 funny, dest, funny, dest);
10725 s = bracket; /* let the parser handle it */
10729 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10730 PL_lex_state = LEX_INTERPEND;
10735 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10737 PERL_UNUSED_CONTEXT;
10740 else if (ch == 'g')
10741 *pmfl |= PMf_GLOBAL;
10742 else if (ch == 'c')
10743 *pmfl |= PMf_CONTINUE;
10744 else if (ch == 'o')
10746 else if (ch == 'm')
10747 *pmfl |= PMf_MULTILINE;
10748 else if (ch == 's')
10749 *pmfl |= PMf_SINGLELINE;
10750 else if (ch == 'x')
10751 *pmfl |= PMf_EXTENDED;
10755 S_scan_pat(pTHX_ char *start, I32 type)
10759 char *s = scan_str(start,!!PL_madskills,FALSE);
10760 const char * const valid_flags =
10761 (const char *)((type == OP_QR) ? "iomsx" : "iogcmsx");
10768 const char * const delimiter = skipspace(start);
10772 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10773 : "Search pattern not terminated" ));
10776 pm = (PMOP*)newPMOP(type, 0);
10777 if (PL_multi_open == '?')
10778 pm->op_pmflags |= PMf_ONCE;
10782 while (*s && strchr(valid_flags, *s))
10783 pmflag(&pm->op_pmflags,*s++);
10785 if (PL_madskills && modstart != s) {
10786 SV* tmptoken = newSVpvn(modstart, s - modstart);
10787 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10790 /* issue a warning if /c is specified,but /g is not */
10791 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10792 && ckWARN(WARN_REGEXP))
10794 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
10797 pm->op_pmpermflags = pm->op_pmflags;
10799 PL_lex_op = (OP*)pm;
10800 yylval.ival = OP_MATCH;
10805 S_scan_subst(pTHX_ char *start)
10816 yylval.ival = OP_NULL;
10818 s = scan_str(start,!!PL_madskills,FALSE);
10821 Perl_croak(aTHX_ "Substitution pattern not terminated");
10823 if (s[-1] == PL_multi_open)
10826 if (PL_madskills) {
10827 CURMAD('q', PL_thisopen);
10828 CURMAD('_', PL_thiswhite);
10829 CURMAD('E', PL_thisstuff);
10830 CURMAD('Q', PL_thisclose);
10831 PL_realtokenstart = s - SvPVX(PL_linestr);
10835 first_start = PL_multi_start;
10836 s = scan_str(s,!!PL_madskills,FALSE);
10838 if (PL_lex_stuff) {
10839 SvREFCNT_dec(PL_lex_stuff);
10840 PL_lex_stuff = NULL;
10842 Perl_croak(aTHX_ "Substitution replacement not terminated");
10844 PL_multi_start = first_start; /* so whole substitution is taken together */
10846 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10849 if (PL_madskills) {
10850 CURMAD('z', PL_thisopen);
10851 CURMAD('R', PL_thisstuff);
10852 CURMAD('Z', PL_thisclose);
10862 else if (strchr("iogcmsx", *s))
10863 pmflag(&pm->op_pmflags,*s++);
10869 if (PL_madskills) {
10871 curmad('m', newSVpvn(modstart, s - modstart));
10872 append_madprops(PL_thismad, (OP*)pm, 0);
10876 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10877 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10881 SV * const repl = newSVpvs("");
10883 PL_sublex_info.super_bufptr = s;
10884 PL_sublex_info.super_bufend = PL_bufend;
10886 pm->op_pmflags |= PMf_EVAL;
10888 sv_catpv(repl, (const char *)(es ? "eval " : "do "));
10889 sv_catpvs(repl, "{");
10890 sv_catsv(repl, PL_lex_repl);
10891 if (strchr(SvPVX(PL_lex_repl), '#'))
10892 sv_catpvs(repl, "\n");
10893 sv_catpvs(repl, "}");
10895 SvREFCNT_dec(PL_lex_repl);
10896 PL_lex_repl = repl;
10899 pm->op_pmpermflags = pm->op_pmflags;
10900 PL_lex_op = (OP*)pm;
10901 yylval.ival = OP_SUBST;
10906 S_scan_trans(pTHX_ char *start)
10919 yylval.ival = OP_NULL;
10921 s = scan_str(start,!!PL_madskills,FALSE);
10923 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10925 if (s[-1] == PL_multi_open)
10928 if (PL_madskills) {
10929 CURMAD('q', PL_thisopen);
10930 CURMAD('_', PL_thiswhite);
10931 CURMAD('E', PL_thisstuff);
10932 CURMAD('Q', PL_thisclose);
10933 PL_realtokenstart = s - SvPVX(PL_linestr);
10937 s = scan_str(s,!!PL_madskills,FALSE);
10939 if (PL_lex_stuff) {
10940 SvREFCNT_dec(PL_lex_stuff);
10941 PL_lex_stuff = NULL;
10943 Perl_croak(aTHX_ "Transliteration replacement not terminated");
10945 if (PL_madskills) {
10946 CURMAD('z', PL_thisopen);
10947 CURMAD('R', PL_thisstuff);
10948 CURMAD('Z', PL_thisclose);
10951 complement = del = squash = 0;
10958 complement = OPpTRANS_COMPLEMENT;
10961 del = OPpTRANS_DELETE;
10964 squash = OPpTRANS_SQUASH;
10973 Newx(tbl, complement&&!del?258:256, short);
10974 o = newPVOP(OP_TRANS, 0, (char*)tbl);
10975 o->op_private &= ~OPpTRANS_ALL;
10976 o->op_private |= del|squash|complement|
10977 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10978 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
10981 yylval.ival = OP_TRANS;
10984 if (PL_madskills) {
10986 curmad('m', newSVpvn(modstart, s - modstart));
10987 append_madprops(PL_thismad, o, 0);
10996 S_scan_heredoc(pTHX_ register char *s)
11000 I32 op_type = OP_SCALAR;
11004 const char *found_newline;
11008 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
11010 I32 stuffstart = s - SvPVX(PL_linestr);
11013 PL_realtokenstart = -1;
11018 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
11022 while (SPACE_OR_TAB(*peek))
11024 if (*peek == '`' || *peek == '\'' || *peek =='"') {
11027 s = delimcpy(d, e, s, PL_bufend, term, &len);
11037 if (!isALNUM_lazy_if(s,UTF))
11038 deprecate_old("bare << to mean <<\"\"");
11039 for (; isALNUM_lazy_if(s,UTF); s++) {
11044 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
11045 Perl_croak(aTHX_ "Delimiter for here document is too long");
11048 len = d - PL_tokenbuf;
11051 if (PL_madskills) {
11052 tstart = PL_tokenbuf + !outer;
11053 PL_thisclose = newSVpvn(tstart, len - !outer);
11054 tstart = SvPVX(PL_linestr) + stuffstart;
11055 PL_thisopen = newSVpvn(tstart, s - tstart);
11056 stuffstart = s - SvPVX(PL_linestr);
11059 #ifndef PERL_STRICT_CR
11060 d = strchr(s, '\r');
11062 char * const olds = s;
11064 while (s < PL_bufend) {
11070 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11079 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11086 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11087 herewas = newSVpvn(s,PL_bufend-s);
11091 herewas = newSVpvn(s-1,found_newline-s+1);
11094 herewas = newSVpvn(s,found_newline-s);
11098 if (PL_madskills) {
11099 tstart = SvPVX(PL_linestr) + stuffstart;
11101 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11103 PL_thisstuff = newSVpvn(tstart, s - tstart);
11106 s += SvCUR(herewas);
11109 stuffstart = s - SvPVX(PL_linestr);
11115 tmpstr = newSV(79);
11116 sv_upgrade(tmpstr, SVt_PVIV);
11117 if (term == '\'') {
11118 op_type = OP_CONST;
11119 SvIV_set(tmpstr, -1);
11121 else if (term == '`') {
11122 op_type = OP_BACKTICK;
11123 SvIV_set(tmpstr, '\\');
11127 PL_multi_start = CopLINE(PL_curcop);
11128 PL_multi_open = PL_multi_close = '<';
11129 term = *PL_tokenbuf;
11130 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11131 char * const bufptr = PL_sublex_info.super_bufptr;
11132 char * const bufend = PL_sublex_info.super_bufend;
11133 char * const olds = s - SvCUR(herewas);
11134 s = strchr(bufptr, '\n');
11138 while (s < bufend &&
11139 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11141 CopLINE_inc(PL_curcop);
11144 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11145 missingterm(PL_tokenbuf);
11147 sv_setpvn(herewas,bufptr,d-bufptr+1);
11148 sv_setpvn(tmpstr,d+1,s-d);
11150 sv_catpvn(herewas,s,bufend-s);
11151 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11158 while (s < PL_bufend &&
11159 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11161 CopLINE_inc(PL_curcop);
11163 if (s >= PL_bufend) {
11164 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11165 missingterm(PL_tokenbuf);
11167 sv_setpvn(tmpstr,d+1,s-d);
11169 if (PL_madskills) {
11171 sv_catpvn(PL_thisstuff, d + 1, s - d);
11173 PL_thisstuff = newSVpvn(d + 1, s - d);
11174 stuffstart = s - SvPVX(PL_linestr);
11178 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11180 sv_catpvn(herewas,s,PL_bufend-s);
11181 sv_setsv(PL_linestr,herewas);
11182 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11183 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11184 PL_last_lop = PL_last_uni = NULL;
11187 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11188 while (s >= PL_bufend) { /* multiple line string? */
11190 if (PL_madskills) {
11191 tstart = SvPVX(PL_linestr) + stuffstart;
11193 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11195 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11199 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11200 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11201 missingterm(PL_tokenbuf);
11204 stuffstart = s - SvPVX(PL_linestr);
11206 CopLINE_inc(PL_curcop);
11207 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11208 PL_last_lop = PL_last_uni = NULL;
11209 #ifndef PERL_STRICT_CR
11210 if (PL_bufend - PL_linestart >= 2) {
11211 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11212 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11214 PL_bufend[-2] = '\n';
11216 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11218 else if (PL_bufend[-1] == '\r')
11219 PL_bufend[-1] = '\n';
11221 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11222 PL_bufend[-1] = '\n';
11224 if (PERLDB_LINE && PL_curstash != PL_debstash)
11225 update_debugger_info_sv(PL_linestr);
11226 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11227 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11228 *(SvPVX(PL_linestr) + off ) = ' ';
11229 sv_catsv(PL_linestr,herewas);
11230 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11231 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11235 sv_catsv(tmpstr,PL_linestr);
11240 PL_multi_end = CopLINE(PL_curcop);
11241 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11242 SvPV_shrink_to_cur(tmpstr);
11244 SvREFCNT_dec(herewas);
11246 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11248 else if (PL_encoding)
11249 sv_recode_to_utf8(tmpstr, PL_encoding);
11251 PL_lex_stuff = tmpstr;
11252 yylval.ival = op_type;
11256 /* scan_inputsymbol
11257 takes: current position in input buffer
11258 returns: new position in input buffer
11259 side-effects: yylval and lex_op are set.
11264 <FH> read from filehandle
11265 <pkg::FH> read from package qualified filehandle
11266 <pkg'FH> read from package qualified filehandle
11267 <$fh> read from filehandle in $fh
11268 <*.h> filename glob
11273 S_scan_inputsymbol(pTHX_ char *start)
11276 register char *s = start; /* current position in buffer */
11280 char *d = PL_tokenbuf; /* start of temp holding space */
11281 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11283 end = strchr(s, '\n');
11286 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11288 /* die if we didn't have space for the contents of the <>,
11289 or if it didn't end, or if we see a newline
11292 if (len >= (I32)sizeof PL_tokenbuf)
11293 Perl_croak(aTHX_ "Excessively long <> operator");
11295 Perl_croak(aTHX_ "Unterminated <> operator");
11300 Remember, only scalar variables are interpreted as filehandles by
11301 this code. Anything more complex (e.g., <$fh{$num}>) will be
11302 treated as a glob() call.
11303 This code makes use of the fact that except for the $ at the front,
11304 a scalar variable and a filehandle look the same.
11306 if (*d == '$' && d[1]) d++;
11308 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11309 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11312 /* If we've tried to read what we allow filehandles to look like, and
11313 there's still text left, then it must be a glob() and not a getline.
11314 Use scan_str to pull out the stuff between the <> and treat it
11315 as nothing more than a string.
11318 if (d - PL_tokenbuf != len) {
11319 yylval.ival = OP_GLOB;
11321 s = scan_str(start,!!PL_madskills,FALSE);
11323 Perl_croak(aTHX_ "Glob not terminated");
11327 bool readline_overriden = FALSE;
11330 /* we're in a filehandle read situation */
11333 /* turn <> into <ARGV> */
11335 Copy("ARGV",d,5,char);
11337 /* Check whether readline() is overriden */
11338 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11340 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11342 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11343 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
11344 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11345 readline_overriden = TRUE;
11347 /* if <$fh>, create the ops to turn the variable into a
11351 /* try to find it in the pad for this block, otherwise find
11352 add symbol table ops
11354 const PADOFFSET tmp = pad_findmy(d);
11355 if (tmp != NOT_IN_PAD) {
11356 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11357 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11358 HEK * const stashname = HvNAME_HEK(stash);
11359 SV * const sym = sv_2mortal(newSVhek(stashname));
11360 sv_catpvs(sym, "::");
11361 sv_catpv(sym, d+1);
11366 OP * const o = newOP(OP_PADSV, 0);
11368 PL_lex_op = readline_overriden
11369 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11370 append_elem(OP_LIST, o,
11371 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11372 : (OP*)newUNOP(OP_READLINE, 0, o);
11381 ? (GV_ADDMULTI | GV_ADDINEVAL)
11384 PL_lex_op = readline_overriden
11385 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11386 append_elem(OP_LIST,
11387 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11388 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11389 : (OP*)newUNOP(OP_READLINE, 0,
11390 newUNOP(OP_RV2SV, 0,
11391 newGVOP(OP_GV, 0, gv)));
11393 if (!readline_overriden)
11394 PL_lex_op->op_flags |= OPf_SPECIAL;
11395 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11396 yylval.ival = OP_NULL;
11399 /* If it's none of the above, it must be a literal filehandle
11400 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11402 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11403 PL_lex_op = readline_overriden
11404 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11405 append_elem(OP_LIST,
11406 newGVOP(OP_GV, 0, gv),
11407 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11408 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11409 yylval.ival = OP_NULL;
11418 takes: start position in buffer
11419 keep_quoted preserve \ on the embedded delimiter(s)
11420 keep_delims preserve the delimiters around the string
11421 returns: position to continue reading from buffer
11422 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11423 updates the read buffer.
11425 This subroutine pulls a string out of the input. It is called for:
11426 q single quotes q(literal text)
11427 ' single quotes 'literal text'
11428 qq double quotes qq(interpolate $here please)
11429 " double quotes "interpolate $here please"
11430 qx backticks qx(/bin/ls -l)
11431 ` backticks `/bin/ls -l`
11432 qw quote words @EXPORT_OK = qw( func() $spam )
11433 m// regexp match m/this/
11434 s/// regexp substitute s/this/that/
11435 tr/// string transliterate tr/this/that/
11436 y/// string transliterate y/this/that/
11437 ($*@) sub prototypes sub foo ($)
11438 (stuff) sub attr parameters sub foo : attr(stuff)
11439 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11441 In most of these cases (all but <>, patterns and transliterate)
11442 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11443 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11444 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11447 It skips whitespace before the string starts, and treats the first
11448 character as the delimiter. If the delimiter is one of ([{< then
11449 the corresponding "close" character )]}> is used as the closing
11450 delimiter. It allows quoting of delimiters, and if the string has
11451 balanced delimiters ([{<>}]) it allows nesting.
11453 On success, the SV with the resulting string is put into lex_stuff or,
11454 if that is already non-NULL, into lex_repl. The second case occurs only
11455 when parsing the RHS of the special constructs s/// and tr/// (y///).
11456 For convenience, the terminating delimiter character is stuffed into
11461 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11464 SV *sv; /* scalar value: string */
11465 const char *tmps; /* temp string, used for delimiter matching */
11466 register char *s = start; /* current position in the buffer */
11467 register char term; /* terminating character */
11468 register char *to; /* current position in the sv's data */
11469 I32 brackets = 1; /* bracket nesting level */
11470 bool has_utf8 = FALSE; /* is there any utf8 content? */
11471 I32 termcode; /* terminating char. code */
11472 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11473 STRLEN termlen; /* length of terminating string */
11474 int last_off = 0; /* last position for nesting bracket */
11480 /* skip space before the delimiter */
11486 if (PL_realtokenstart >= 0) {
11487 stuffstart = PL_realtokenstart;
11488 PL_realtokenstart = -1;
11491 stuffstart = start - SvPVX(PL_linestr);
11493 /* mark where we are, in case we need to report errors */
11496 /* after skipping whitespace, the next character is the terminator */
11499 termcode = termstr[0] = term;
11503 termcode = utf8_to_uvchr((U8*)s, &termlen);
11504 Copy(s, termstr, termlen, U8);
11505 if (!UTF8_IS_INVARIANT(term))
11509 /* mark where we are */
11510 PL_multi_start = CopLINE(PL_curcop);
11511 PL_multi_open = term;
11513 /* find corresponding closing delimiter */
11514 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11515 termcode = termstr[0] = term = tmps[5];
11517 PL_multi_close = term;
11519 /* create a new SV to hold the contents. 79 is the SV's initial length.
11520 What a random number. */
11522 sv_upgrade(sv, SVt_PVIV);
11523 SvIV_set(sv, termcode);
11524 (void)SvPOK_only(sv); /* validate pointer */
11526 /* move past delimiter and try to read a complete string */
11528 sv_catpvn(sv, s, termlen);
11531 tstart = SvPVX(PL_linestr) + stuffstart;
11532 if (!PL_thisopen && !keep_delims) {
11533 PL_thisopen = newSVpvn(tstart, s - tstart);
11534 stuffstart = s - SvPVX(PL_linestr);
11538 if (PL_encoding && !UTF) {
11542 int offset = s - SvPVX_const(PL_linestr);
11543 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11544 &offset, (char*)termstr, termlen);
11545 const char * const ns = SvPVX_const(PL_linestr) + offset;
11546 char * const svlast = SvEND(sv) - 1;
11548 for (; s < ns; s++) {
11549 if (*s == '\n' && !PL_rsfp)
11550 CopLINE_inc(PL_curcop);
11553 goto read_more_line;
11555 /* handle quoted delimiters */
11556 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11558 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11560 if ((svlast-1 - t) % 2) {
11561 if (!keep_quoted) {
11562 *(svlast-1) = term;
11564 SvCUR_set(sv, SvCUR(sv) - 1);
11569 if (PL_multi_open == PL_multi_close) {
11575 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
11576 /* At here, all closes are "was quoted" one,
11577 so we don't check PL_multi_close. */
11579 if (!keep_quoted && *(t+1) == PL_multi_open)
11584 else if (*t == PL_multi_open)
11592 SvCUR_set(sv, w - SvPVX_const(sv));
11594 last_off = w - SvPVX(sv);
11595 if (--brackets <= 0)
11600 if (!keep_delims) {
11601 SvCUR_set(sv, SvCUR(sv) - 1);
11607 /* extend sv if need be */
11608 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11609 /* set 'to' to the next character in the sv's string */
11610 to = SvPVX(sv)+SvCUR(sv);
11612 /* if open delimiter is the close delimiter read unbridle */
11613 if (PL_multi_open == PL_multi_close) {
11614 for (; s < PL_bufend; s++,to++) {
11615 /* embedded newlines increment the current line number */
11616 if (*s == '\n' && !PL_rsfp)
11617 CopLINE_inc(PL_curcop);
11618 /* handle quoted delimiters */
11619 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11620 if (!keep_quoted && s[1] == term)
11622 /* any other quotes are simply copied straight through */
11626 /* terminate when run out of buffer (the for() condition), or
11627 have found the terminator */
11628 else if (*s == term) {
11631 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11634 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11640 /* if the terminator isn't the same as the start character (e.g.,
11641 matched brackets), we have to allow more in the quoting, and
11642 be prepared for nested brackets.
11645 /* read until we run out of string, or we find the terminator */
11646 for (; s < PL_bufend; s++,to++) {
11647 /* embedded newlines increment the line count */
11648 if (*s == '\n' && !PL_rsfp)
11649 CopLINE_inc(PL_curcop);
11650 /* backslashes can escape the open or closing characters */
11651 if (*s == '\\' && s+1 < PL_bufend) {
11652 if (!keep_quoted &&
11653 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11658 /* allow nested opens and closes */
11659 else if (*s == PL_multi_close && --brackets <= 0)
11661 else if (*s == PL_multi_open)
11663 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11668 /* terminate the copied string and update the sv's end-of-string */
11670 SvCUR_set(sv, to - SvPVX_const(sv));
11673 * this next chunk reads more into the buffer if we're not done yet
11677 break; /* handle case where we are done yet :-) */
11679 #ifndef PERL_STRICT_CR
11680 if (to - SvPVX_const(sv) >= 2) {
11681 if ((to[-2] == '\r' && to[-1] == '\n') ||
11682 (to[-2] == '\n' && to[-1] == '\r'))
11686 SvCUR_set(sv, to - SvPVX_const(sv));
11688 else if (to[-1] == '\r')
11691 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11696 /* if we're out of file, or a read fails, bail and reset the current
11697 line marker so we can report where the unterminated string began
11700 if (PL_madskills) {
11701 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11703 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11705 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11709 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11711 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11717 /* we read a line, so increment our line counter */
11718 CopLINE_inc(PL_curcop);
11720 /* update debugger info */
11721 if (PERLDB_LINE && PL_curstash != PL_debstash)
11722 update_debugger_info_sv(PL_linestr);
11724 /* having changed the buffer, we must update PL_bufend */
11725 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11726 PL_last_lop = PL_last_uni = NULL;
11729 /* at this point, we have successfully read the delimited string */
11731 if (!PL_encoding || UTF) {
11733 if (PL_madskills) {
11734 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11735 const int len = s - tstart;
11737 sv_catpvn(PL_thisstuff, tstart, len);
11739 PL_thisstuff = newSVpvn(tstart, len);
11740 if (!PL_thisclose && !keep_delims)
11741 PL_thisclose = newSVpvn(s,termlen);
11746 sv_catpvn(sv, s, termlen);
11751 if (PL_madskills) {
11752 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11753 const int len = s - tstart - termlen;
11755 sv_catpvn(PL_thisstuff, tstart, len);
11757 PL_thisstuff = newSVpvn(tstart, len);
11758 if (!PL_thisclose && !keep_delims)
11759 PL_thisclose = newSVpvn(s - termlen,termlen);
11763 if (has_utf8 || PL_encoding)
11766 PL_multi_end = CopLINE(PL_curcop);
11768 /* if we allocated too much space, give some back */
11769 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11770 SvLEN_set(sv, SvCUR(sv) + 1);
11771 SvPV_renew(sv, SvLEN(sv));
11774 /* decide whether this is the first or second quoted string we've read
11787 takes: pointer to position in buffer
11788 returns: pointer to new position in buffer
11789 side-effects: builds ops for the constant in yylval.op
11791 Read a number in any of the formats that Perl accepts:
11793 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11794 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11797 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11799 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11802 If it reads a number without a decimal point or an exponent, it will
11803 try converting the number to an integer and see if it can do so
11804 without loss of precision.
11808 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11811 register const char *s = start; /* current position in buffer */
11812 register char *d; /* destination in temp buffer */
11813 register char *e; /* end of temp buffer */
11814 NV nv; /* number read, as a double */
11815 SV *sv = NULL; /* place to put the converted number */
11816 bool floatit; /* boolean: int or float? */
11817 const char *lastub = NULL; /* position of last underbar */
11818 static char const number_too_long[] = "Number too long";
11820 /* We use the first character to decide what type of number this is */
11824 Perl_croak(aTHX_ "panic: scan_num");
11826 /* if it starts with a 0, it could be an octal number, a decimal in
11827 0.13 disguise, or a hexadecimal number, or a binary number. */
11831 u holds the "number so far"
11832 shift the power of 2 of the base
11833 (hex == 4, octal == 3, binary == 1)
11834 overflowed was the number more than we can hold?
11836 Shift is used when we add a digit. It also serves as an "are
11837 we in octal/hex/binary?" indicator to disallow hex characters
11838 when in octal mode.
11843 bool overflowed = FALSE;
11844 bool just_zero = TRUE; /* just plain 0 or binary number? */
11845 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11846 static const char* const bases[5] =
11847 { "", "binary", "", "octal", "hexadecimal" };
11848 static const char* const Bases[5] =
11849 { "", "Binary", "", "Octal", "Hexadecimal" };
11850 static const char* const maxima[5] =
11852 "0b11111111111111111111111111111111",
11856 const char *base, *Base, *max;
11858 /* check for hex */
11863 } else if (s[1] == 'b') {
11868 /* check for a decimal in disguise */
11869 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11871 /* so it must be octal */
11878 if (ckWARN(WARN_SYNTAX))
11879 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11880 "Misplaced _ in number");
11884 base = bases[shift];
11885 Base = Bases[shift];
11886 max = maxima[shift];
11888 /* read the rest of the number */
11890 /* x is used in the overflow test,
11891 b is the digit we're adding on. */
11896 /* if we don't mention it, we're done */
11900 /* _ are ignored -- but warned about if consecutive */
11902 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11903 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11904 "Misplaced _ in number");
11908 /* 8 and 9 are not octal */
11909 case '8': case '9':
11911 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11915 case '2': case '3': case '4':
11916 case '5': case '6': case '7':
11918 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11921 case '0': case '1':
11922 b = *s++ & 15; /* ASCII digit -> value of digit */
11926 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11927 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11928 /* make sure they said 0x */
11931 b = (*s++ & 7) + 9;
11933 /* Prepare to put the digit we have onto the end
11934 of the number so far. We check for overflows.
11940 x = u << shift; /* make room for the digit */
11942 if ((x >> shift) != u
11943 && !(PL_hints & HINT_NEW_BINARY)) {
11946 if (ckWARN_d(WARN_OVERFLOW))
11947 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11948 "Integer overflow in %s number",
11951 u = x | b; /* add the digit to the end */
11954 n *= nvshift[shift];
11955 /* If an NV has not enough bits in its
11956 * mantissa to represent an UV this summing of
11957 * small low-order numbers is a waste of time
11958 * (because the NV cannot preserve the
11959 * low-order bits anyway): we could just
11960 * remember when did we overflow and in the
11961 * end just multiply n by the right
11969 /* if we get here, we had success: make a scalar value from
11974 /* final misplaced underbar check */
11975 if (s[-1] == '_') {
11976 if (ckWARN(WARN_SYNTAX))
11977 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11982 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
11983 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11984 "%s number > %s non-portable",
11990 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
11991 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11992 "%s number > %s non-portable",
11997 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
11998 sv = new_constant(start, s - start, "integer",
12000 else if (PL_hints & HINT_NEW_BINARY)
12001 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
12006 handle decimal numbers.
12007 we're also sent here when we read a 0 as the first digit
12009 case '1': case '2': case '3': case '4': case '5':
12010 case '6': case '7': case '8': case '9': case '.':
12013 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
12016 /* read next group of digits and _ and copy into d */
12017 while (isDIGIT(*s) || *s == '_') {
12018 /* skip underscores, checking for misplaced ones
12022 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12023 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12024 "Misplaced _ in number");
12028 /* check for end of fixed-length buffer */
12030 Perl_croak(aTHX_ number_too_long);
12031 /* if we're ok, copy the character */
12036 /* final misplaced underbar check */
12037 if (lastub && s == lastub + 1) {
12038 if (ckWARN(WARN_SYNTAX))
12039 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12042 /* read a decimal portion if there is one. avoid
12043 3..5 being interpreted as the number 3. followed
12046 if (*s == '.' && s[1] != '.') {
12051 if (ckWARN(WARN_SYNTAX))
12052 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12053 "Misplaced _ in number");
12057 /* copy, ignoring underbars, until we run out of digits.
12059 for (; isDIGIT(*s) || *s == '_'; s++) {
12060 /* fixed length buffer check */
12062 Perl_croak(aTHX_ number_too_long);
12064 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12065 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12066 "Misplaced _ in number");
12072 /* fractional part ending in underbar? */
12073 if (s[-1] == '_') {
12074 if (ckWARN(WARN_SYNTAX))
12075 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12076 "Misplaced _ in number");
12078 if (*s == '.' && isDIGIT(s[1])) {
12079 /* oops, it's really a v-string, but without the "v" */
12085 /* read exponent part, if present */
12086 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12090 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12091 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12093 /* stray preinitial _ */
12095 if (ckWARN(WARN_SYNTAX))
12096 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12097 "Misplaced _ in number");
12101 /* allow positive or negative exponent */
12102 if (*s == '+' || *s == '-')
12105 /* stray initial _ */
12107 if (ckWARN(WARN_SYNTAX))
12108 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12109 "Misplaced _ in number");
12113 /* read digits of exponent */
12114 while (isDIGIT(*s) || *s == '_') {
12117 Perl_croak(aTHX_ number_too_long);
12121 if (((lastub && s == lastub + 1) ||
12122 (!isDIGIT(s[1]) && s[1] != '_'))
12123 && ckWARN(WARN_SYNTAX))
12124 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12125 "Misplaced _ in number");
12132 /* make an sv from the string */
12136 We try to do an integer conversion first if no characters
12137 indicating "float" have been found.
12142 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12144 if (flags == IS_NUMBER_IN_UV) {
12146 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12149 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12150 if (uv <= (UV) IV_MIN)
12151 sv_setiv(sv, -(IV)uv);
12158 /* terminate the string */
12160 nv = Atof(PL_tokenbuf);
12164 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12165 (PL_hints & HINT_NEW_INTEGER) )
12166 sv = new_constant(PL_tokenbuf,
12169 (floatit ? "float" : "integer"),
12173 /* if it starts with a v, it could be a v-string */
12176 sv = newSV(5); /* preallocate storage space */
12177 s = scan_vstring(s,sv);
12181 /* make the op for the constant and return */
12184 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12186 lvalp->opval = NULL;
12192 S_scan_formline(pTHX_ register char *s)
12195 register char *eol;
12197 SV * const stuff = newSVpvs("");
12198 bool needargs = FALSE;
12199 bool eofmt = FALSE;
12201 char *tokenstart = s;
12204 if (PL_madskills) {
12205 savewhite = PL_thiswhite;
12210 while (!needargs) {
12213 #ifdef PERL_STRICT_CR
12214 while (SPACE_OR_TAB(*t))
12217 while (SPACE_OR_TAB(*t) || *t == '\r')
12220 if (*t == '\n' || t == PL_bufend) {
12225 if (PL_in_eval && !PL_rsfp) {
12226 eol = (char *) memchr(s,'\n',PL_bufend-s);
12231 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12233 for (t = s; t < eol; t++) {
12234 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12236 goto enough; /* ~~ must be first line in formline */
12238 if (*t == '@' || *t == '^')
12242 sv_catpvn(stuff, s, eol-s);
12243 #ifndef PERL_STRICT_CR
12244 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12245 char *end = SvPVX(stuff) + SvCUR(stuff);
12248 SvCUR_set(stuff, SvCUR(stuff) - 1);
12258 if (PL_madskills) {
12260 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12262 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12265 s = filter_gets(PL_linestr, PL_rsfp, 0);
12267 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12269 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12271 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12272 PL_last_lop = PL_last_uni = NULL;
12281 if (SvCUR(stuff)) {
12284 PL_lex_state = LEX_NORMAL;
12285 start_force(PL_curforce);
12286 NEXTVAL_NEXTTOKE.ival = 0;
12290 PL_lex_state = LEX_FORMLINE;
12292 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12294 else if (PL_encoding)
12295 sv_recode_to_utf8(stuff, PL_encoding);
12297 start_force(PL_curforce);
12298 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12300 start_force(PL_curforce);
12301 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12305 SvREFCNT_dec(stuff);
12307 PL_lex_formbrack = 0;
12311 if (PL_madskills) {
12313 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12315 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12316 PL_thiswhite = savewhite;
12328 PL_cshlen = strlen(PL_cshname);
12330 #if defined(USE_ITHREADS)
12331 PERL_UNUSED_CONTEXT;
12337 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12340 const I32 oldsavestack_ix = PL_savestack_ix;
12341 CV* const outsidecv = PL_compcv;
12344 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12346 SAVEI32(PL_subline);
12347 save_item(PL_subname);
12348 SAVESPTR(PL_compcv);
12350 PL_compcv = (CV*)newSV(0);
12351 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12352 CvFLAGS(PL_compcv) |= flags;
12354 PL_subline = CopLINE(PL_curcop);
12355 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12356 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12357 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12359 return oldsavestack_ix;
12363 #pragma segment Perl_yylex
12366 Perl_yywarn(pTHX_ const char *s)
12369 PL_in_eval |= EVAL_WARNONLY;
12371 PL_in_eval &= ~EVAL_WARNONLY;
12376 Perl_yyerror(pTHX_ const char *s)
12379 const char *where = NULL;
12380 const char *context = NULL;
12383 int yychar = PL_parser->yychar;
12385 if (!yychar || (yychar == ';' && !PL_rsfp))
12387 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12388 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12389 PL_oldbufptr != PL_bufptr) {
12392 The code below is removed for NetWare because it abends/crashes on NetWare
12393 when the script has error such as not having the closing quotes like:
12394 if ($var eq "value)
12395 Checking of white spaces is anyway done in NetWare code.
12398 while (isSPACE(*PL_oldoldbufptr))
12401 context = PL_oldoldbufptr;
12402 contlen = PL_bufptr - PL_oldoldbufptr;
12404 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12405 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12408 The code below is removed for NetWare because it abends/crashes on NetWare
12409 when the script has error such as not having the closing quotes like:
12410 if ($var eq "value)
12411 Checking of white spaces is anyway done in NetWare code.
12414 while (isSPACE(*PL_oldbufptr))
12417 context = PL_oldbufptr;
12418 contlen = PL_bufptr - PL_oldbufptr;
12420 else if (yychar > 255)
12421 where = "next token ???";
12422 else if (yychar == -2) { /* YYEMPTY */
12423 if (PL_lex_state == LEX_NORMAL ||
12424 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12425 where = "at end of line";
12426 else if (PL_lex_inpat)
12427 where = "within pattern";
12429 where = "within string";
12432 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12434 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12435 else if (isPRINT_LC(yychar))
12436 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12438 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12439 where = SvPVX_const(where_sv);
12441 msg = sv_2mortal(newSVpv(s, 0));
12442 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12443 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12445 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12447 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12448 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12449 Perl_sv_catpvf(aTHX_ msg,
12450 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12451 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12454 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12455 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, (void*)msg);
12458 if (PL_error_count >= 10) {
12459 if (PL_in_eval && SvCUR(ERRSV))
12460 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12461 (void*)ERRSV, OutCopFILE(PL_curcop));
12463 Perl_croak(aTHX_ "%s has too many errors.\n",
12464 OutCopFILE(PL_curcop));
12467 PL_in_my_stash = NULL;
12471 #pragma segment Main
12475 S_swallow_bom(pTHX_ U8 *s)
12478 const STRLEN slen = SvCUR(PL_linestr);
12481 if (s[1] == 0xFE) {
12482 /* UTF-16 little-endian? (or UTF32-LE?) */
12483 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12484 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12485 #ifndef PERL_NO_UTF16_FILTER
12486 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12489 if (PL_bufend > (char*)s) {
12493 filter_add(utf16rev_textfilter, NULL);
12494 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12495 utf16_to_utf8_reversed(s, news,
12496 PL_bufend - (char*)s - 1,
12498 sv_setpvn(PL_linestr, (const char*)news, newlen);
12500 s = (U8*)SvPVX(PL_linestr);
12501 Copy(news, s, newlen, U8);
12505 SvUTF8_on(PL_linestr);
12506 s = (U8*)SvPVX(PL_linestr);
12508 /* FIXME - is this a general bug fix? */
12511 PL_bufend = SvPVX(PL_linestr) + newlen;
12514 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12519 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12520 #ifndef PERL_NO_UTF16_FILTER
12521 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12524 if (PL_bufend > (char *)s) {
12528 filter_add(utf16_textfilter, NULL);
12529 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12530 utf16_to_utf8(s, news,
12531 PL_bufend - (char*)s,
12533 sv_setpvn(PL_linestr, (const char*)news, newlen);
12535 SvUTF8_on(PL_linestr);
12536 s = (U8*)SvPVX(PL_linestr);
12537 PL_bufend = SvPVX(PL_linestr) + newlen;
12540 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12545 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12546 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12547 s += 3; /* UTF-8 */
12553 if (s[2] == 0xFE && s[3] == 0xFF) {
12554 /* UTF-32 big-endian */
12555 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12558 else if (s[2] == 0 && s[3] != 0) {
12561 * are a good indicator of UTF-16BE. */
12562 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12568 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12569 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12570 s += 4; /* UTF-8 */
12576 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12579 * are a good indicator of UTF-16LE. */
12580 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12589 * Restore a source filter.
12593 restore_rsfp(pTHX_ void *f)
12596 PerlIO * const fp = (PerlIO*)f;
12598 if (PL_rsfp == PerlIO_stdin())
12599 PerlIO_clearerr(PL_rsfp);
12600 else if (PL_rsfp && (PL_rsfp != fp))
12601 PerlIO_close(PL_rsfp);
12605 #ifndef PERL_NO_UTF16_FILTER
12607 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12610 const STRLEN old = SvCUR(sv);
12611 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12612 DEBUG_P(PerlIO_printf(Perl_debug_log,
12613 "utf16_textfilter(%p): %d %d (%d)\n",
12614 FPTR2DPTR(void *, utf16_textfilter),
12615 idx, maxlen, (int) count));
12619 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12620 Copy(SvPVX_const(sv), tmps, old, char);
12621 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12622 SvCUR(sv) - old, &newlen);
12623 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12625 DEBUG_P({sv_dump(sv);});
12630 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12633 const STRLEN old = SvCUR(sv);
12634 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12635 DEBUG_P(PerlIO_printf(Perl_debug_log,
12636 "utf16rev_textfilter(%p): %d %d (%d)\n",
12637 FPTR2DPTR(void *, utf16rev_textfilter),
12638 idx, maxlen, (int) count));
12642 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12643 Copy(SvPVX_const(sv), tmps, old, char);
12644 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12645 SvCUR(sv) - old, &newlen);
12646 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12648 DEBUG_P({ sv_dump(sv); });
12654 Returns a pointer to the next character after the parsed
12655 vstring, as well as updating the passed in sv.
12657 Function must be called like
12660 s = scan_vstring(s,sv);
12662 The sv should already be large enough to store the vstring
12663 passed in, for performance reasons.
12668 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12671 const char *pos = s;
12672 const char *start = s;
12673 if (*pos == 'v') pos++; /* get past 'v' */
12674 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12676 if ( *pos != '.') {
12677 /* this may not be a v-string if followed by => */
12678 const char *next = pos;
12679 while (next < PL_bufend && isSPACE(*next))
12681 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12682 /* return string not v-string */
12683 sv_setpvn(sv,(char *)s,pos-s);
12684 return (char *)pos;
12688 if (!isALPHA(*pos)) {
12689 U8 tmpbuf[UTF8_MAXBYTES+1];
12692 s++; /* get past 'v' */
12694 sv_setpvn(sv, "", 0);
12697 /* this is atoi() that tolerates underscores */
12700 const char *end = pos;
12702 while (--end >= s) {
12704 const UV orev = rev;
12705 rev += (*end - '0') * mult;
12707 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12708 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12709 "Integer overflow in decimal number");
12713 if (rev > 0x7FFFFFFF)
12714 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12716 /* Append native character for the rev point */
12717 tmpend = uvchr_to_utf8(tmpbuf, rev);
12718 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12719 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12721 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12727 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12731 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12739 * c-indentation-style: bsd
12740 * c-basic-offset: 4
12741 * indent-tabs-mode: t
12744 * ex: set ts=8 sts=4 sw=4 noet: