3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "It all comes from here, the stench and the peril." --Frodo
16 * This file is the lexer for Perl. It's closely linked to the
19 * The main routine is yylex(), which returns the next token.
23 #define PERL_IN_TOKE_C
26 #define yychar (*PL_yycharp)
27 #define yylval (*PL_yylvalp)
29 static const char ident_too_long[] = "Identifier too long";
30 static const char commaless_variable_list[] = "comma-less variable list";
32 static void restore_rsfp(pTHX_ void *f);
33 #ifndef PERL_NO_UTF16_FILTER
34 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
35 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
39 # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
40 # define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
42 # define CURMAD(slot,sv)
43 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
46 #define XFAKEBRACK 128
49 #ifdef USE_UTF8_SCRIPTS
50 # define UTF (!IN_BYTES)
52 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
55 /* In variables named $^X, these are the legal values for X.
56 * 1999-02-27 mjd-perl-patch@plover.com */
57 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
59 /* On MacOS, respect nonbreaking spaces */
60 #ifdef MACOS_TRADITIONAL
61 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
63 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
66 /* LEX_* are values for PL_lex_state, the state of the lexer.
67 * They are arranged oddly so that the guard on the switch statement
68 * can get by with a single comparison (if the compiler is smart enough).
71 /* #define LEX_NOTPARSING 11 is done in perl.h. */
73 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
74 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
75 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
76 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
77 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
79 /* at end of code, eg "$x" followed by: */
80 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
81 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
83 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
84 string or after \E, $foo, etc */
85 #define LEX_INTERPCONST 2 /* NOT USED */
86 #define LEX_FORMLINE 1 /* expecting a format line */
87 #define LEX_KNOWNEXT 0 /* next token known; just return it */
91 static const char* const lex_state_names[] = {
110 #include "keywords.h"
112 /* CLINE is a macro that ensures PL_copline has a sane value */
117 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
120 # define SKIPSPACE0(s) skipspace0(s)
121 # define SKIPSPACE1(s) skipspace1(s)
122 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
123 # define PEEKSPACE(s) skipspace2(s,0)
125 # define SKIPSPACE0(s) skipspace(s)
126 # define SKIPSPACE1(s) skipspace(s)
127 # define SKIPSPACE2(s,tsv) skipspace(s)
128 # define PEEKSPACE(s) skipspace(s)
132 * Convenience functions to return different tokens and prime the
133 * lexer for the next token. They all take an argument.
135 * TOKEN : generic token (used for '(', DOLSHARP, etc)
136 * OPERATOR : generic operator
137 * AOPERATOR : assignment operator
138 * PREBLOCK : beginning the block after an if, while, foreach, ...
139 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
140 * PREREF : *EXPR where EXPR is not a simple identifier
141 * TERM : expression term
142 * LOOPX : loop exiting command (goto, last, dump, etc)
143 * FTST : file test operator
144 * FUN0 : zero-argument function
145 * FUN1 : not used, except for not, which isn't a UNIOP
146 * BOop : bitwise or or xor
148 * SHop : shift operator
149 * PWop : power operator
150 * PMop : pattern-matching operator
151 * Aop : addition-level operator
152 * Mop : multiplication-level operator
153 * Eop : equality-testing operator
154 * Rop : relational operator <= != gt
156 * Also see LOP and lop() below.
159 #ifdef DEBUGGING /* Serve -DT. */
160 # define REPORT(retval) tokereport((I32)retval)
162 # define REPORT(retval) (retval)
165 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
166 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
167 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
168 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
169 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
170 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
171 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
172 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
173 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
174 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
175 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
176 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
177 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
178 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
179 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
180 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
181 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
182 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
183 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
184 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
186 /* This bit of chicanery makes a unary function followed by
187 * a parenthesis into a function with one argument, highest precedence.
188 * The UNIDOR macro is for unary functions that can be followed by the //
189 * operator (such as C<shift // 0>).
191 #define UNI2(f,x) { \
195 PL_last_uni = PL_oldbufptr; \
196 PL_last_lop_op = f; \
198 return REPORT( (int)FUNC1 ); \
200 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
202 #define UNI(f) UNI2(f,XTERM)
203 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
205 #define UNIBRACK(f) { \
208 PL_last_uni = PL_oldbufptr; \
210 return REPORT( (int)FUNC1 ); \
212 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
215 /* grandfather return to old style */
216 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
220 /* how to interpret the yylval associated with the token */
224 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
230 static struct debug_tokens {
232 enum token_type type;
234 } const debug_tokens[] =
236 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
237 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
238 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
239 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
240 { ARROW, TOKENTYPE_NONE, "ARROW" },
241 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
242 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
243 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
244 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
245 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
246 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
247 { DO, TOKENTYPE_NONE, "DO" },
248 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
249 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
250 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
251 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
252 { ELSE, TOKENTYPE_NONE, "ELSE" },
253 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
254 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
255 { FOR, TOKENTYPE_IVAL, "FOR" },
256 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
257 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
258 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
259 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
260 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
261 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
262 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
263 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
264 { IF, TOKENTYPE_IVAL, "IF" },
265 { LABEL, TOKENTYPE_PVAL, "LABEL" },
266 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
267 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
268 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
269 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
270 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
271 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
272 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
273 { MY, TOKENTYPE_IVAL, "MY" },
274 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
275 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
276 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
277 { OROP, TOKENTYPE_IVAL, "OROP" },
278 { OROR, TOKENTYPE_NONE, "OROR" },
279 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
280 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
281 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
282 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
283 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
284 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
285 { PREINC, TOKENTYPE_NONE, "PREINC" },
286 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
287 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
288 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
289 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
290 { SUB, TOKENTYPE_NONE, "SUB" },
291 { THING, TOKENTYPE_OPVAL, "THING" },
292 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
293 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
294 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
295 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
296 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
297 { USE, TOKENTYPE_IVAL, "USE" },
298 { WHEN, TOKENTYPE_IVAL, "WHEN" },
299 { WHILE, TOKENTYPE_IVAL, "WHILE" },
300 { WORD, TOKENTYPE_OPVAL, "WORD" },
301 { 0, TOKENTYPE_NONE, NULL }
304 /* dump the returned token in rv, plus any optional arg in yylval */
307 S_tokereport(pTHX_ I32 rv)
311 const char *name = NULL;
312 enum token_type type = TOKENTYPE_NONE;
313 const struct debug_tokens *p;
314 SV* const report = newSVpvs("<== ");
316 for (p = debug_tokens; p->token; p++) {
317 if (p->token == (int)rv) {
324 Perl_sv_catpv(aTHX_ report, name);
325 else if ((char)rv > ' ' && (char)rv < '~')
326 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
328 sv_catpvs(report, "EOF");
330 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
333 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
336 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
338 case TOKENTYPE_OPNUM:
339 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
340 PL_op_name[yylval.ival]);
343 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
345 case TOKENTYPE_OPVAL:
347 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
348 PL_op_name[yylval.opval->op_type]);
349 if (yylval.opval->op_type == OP_CONST) {
350 Perl_sv_catpvf(aTHX_ report, " %s",
351 SvPEEK(cSVOPx_sv(yylval.opval)));
356 sv_catpvs(report, "(opval=null)");
359 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
365 /* print the buffer with suitable escapes */
368 S_printbuf(pTHX_ const char* fmt, const char* s)
370 SV* const tmp = newSVpvs("");
371 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
380 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
381 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
385 S_ao(pTHX_ int toketype)
388 if (*PL_bufptr == '=') {
390 if (toketype == ANDAND)
391 yylval.ival = OP_ANDASSIGN;
392 else if (toketype == OROR)
393 yylval.ival = OP_ORASSIGN;
394 else if (toketype == DORDOR)
395 yylval.ival = OP_DORASSIGN;
403 * When Perl expects an operator and finds something else, no_op
404 * prints the warning. It always prints "<something> found where
405 * operator expected. It prints "Missing semicolon on previous line?"
406 * if the surprise occurs at the start of the line. "do you need to
407 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
408 * where the compiler doesn't know if foo is a method call or a function.
409 * It prints "Missing operator before end of line" if there's nothing
410 * after the missing operator, or "... before <...>" if there is something
411 * after the missing operator.
415 S_no_op(pTHX_ const char *what, char *s)
418 char * const oldbp = PL_bufptr;
419 const bool is_first = (PL_oldbufptr == PL_linestart);
425 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
426 if (ckWARN_d(WARN_SYNTAX)) {
428 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
429 "\t(Missing semicolon on previous line?)\n");
430 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
432 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
434 if (t < PL_bufptr && isSPACE(*t))
435 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
436 "\t(Do you need to predeclare %.*s?)\n",
437 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
441 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
442 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
450 * Complain about missing quote/regexp/heredoc terminator.
451 * If it's called with NULL then it cauterizes the line buffer.
452 * If we're in a delimited string and the delimiter is a control
453 * character, it's reformatted into a two-char sequence like ^C.
458 S_missingterm(pTHX_ char *s)
464 char * const nl = strrchr(s,'\n');
470 iscntrl(PL_multi_close)
472 PL_multi_close < 32 || PL_multi_close == 127
476 tmpbuf[1] = (char)toCTRL(PL_multi_close);
481 *tmpbuf = (char)PL_multi_close;
485 q = strchr(s,'"') ? '\'' : '"';
486 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
489 #define FEATURE_IS_ENABLED(name) \
490 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
491 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
493 * S_feature_is_enabled
494 * Check whether the named feature is enabled.
497 S_feature_is_enabled(pTHX_ const char *name, STRLEN namelen)
500 HV * const hinthv = GvHV(PL_hintgv);
501 char he_name[32] = "feature_";
502 (void) my_strlcpy(&he_name[8], name, 24);
504 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
512 Perl_deprecate(pTHX_ const char *s)
514 if (ckWARN(WARN_DEPRECATED))
515 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
519 Perl_deprecate_old(pTHX_ const char *s)
521 /* This function should NOT be called for any new deprecated warnings */
522 /* Use Perl_deprecate instead */
524 /* It is here to maintain backward compatibility with the pre-5.8 */
525 /* warnings category hierarchy. The "deprecated" category used to */
526 /* live under the "syntax" category. It is now a top-level category */
527 /* in its own right. */
529 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
530 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
531 "Use of %s is deprecated", s);
535 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
536 * utf16-to-utf8-reversed.
539 #ifdef PERL_CR_FILTER
543 register const char *s = SvPVX_const(sv);
544 register const char * const e = s + SvCUR(sv);
545 /* outer loop optimized to do nothing if there are no CR-LFs */
547 if (*s++ == '\r' && *s == '\n') {
548 /* hit a CR-LF, need to copy the rest */
549 register char *d = s - 1;
552 if (*s == '\r' && s[1] == '\n')
563 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
565 const I32 count = FILTER_READ(idx+1, sv, maxlen);
566 if (count > 0 && !maxlen)
574 * Initialize variables. Uses the Perl save_stack to save its state (for
575 * recursive calls to the parser).
579 Perl_lex_start(pTHX_ SV *line)
585 SAVEI32(PL_lex_dojoin);
586 SAVEI32(PL_lex_brackets);
587 SAVEI32(PL_lex_casemods);
588 SAVEI32(PL_lex_starts);
589 SAVEI32(PL_lex_state);
590 SAVEVPTR(PL_lex_inpat);
591 SAVEI32(PL_lex_inwhat);
593 if (PL_lex_state == LEX_KNOWNEXT) {
594 I32 toke = PL_lasttoke;
595 while (--toke >= 0) {
596 SAVEI32(PL_nexttoke[toke].next_type);
597 SAVEVPTR(PL_nexttoke[toke].next_val);
599 SAVEVPTR(PL_nexttoke[toke].next_mad);
601 SAVEI32(PL_lasttoke);
604 SAVESPTR(PL_thistoken);
605 SAVESPTR(PL_thiswhite);
606 SAVESPTR(PL_nextwhite);
607 SAVESPTR(PL_thisopen);
608 SAVESPTR(PL_thisclose);
609 SAVESPTR(PL_thisstuff);
610 SAVEVPTR(PL_thismad);
611 SAVEI32(PL_realtokenstart);
612 SAVEI32(PL_faketokens);
614 SAVEI32(PL_curforce);
616 if (PL_lex_state == LEX_KNOWNEXT) {
617 I32 toke = PL_nexttoke;
618 while (--toke >= 0) {
619 SAVEI32(PL_nexttype[toke]);
620 SAVEVPTR(PL_nextval[toke]);
622 SAVEI32(PL_nexttoke);
625 SAVECOPLINE(PL_curcop);
628 SAVEPPTR(PL_oldbufptr);
629 SAVEPPTR(PL_oldoldbufptr);
630 SAVEPPTR(PL_last_lop);
631 SAVEPPTR(PL_last_uni);
632 SAVEPPTR(PL_linestart);
633 SAVESPTR(PL_linestr);
634 SAVEGENERICPV(PL_lex_brackstack);
635 SAVEGENERICPV(PL_lex_casestack);
636 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
637 SAVESPTR(PL_lex_stuff);
638 SAVEI32(PL_lex_defer);
639 SAVEI32(PL_sublex_info.sub_inwhat);
640 SAVESPTR(PL_lex_repl);
642 SAVEINT(PL_lex_expect);
644 PL_lex_state = LEX_NORMAL;
648 Newx(PL_lex_brackstack, 120, char);
649 Newx(PL_lex_casestack, 12, char);
651 *PL_lex_casestack = '\0';
663 PL_sublex_info.sub_inwhat = 0;
665 if (SvREADONLY(PL_linestr))
666 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
667 s = SvPV_const(PL_linestr, len);
668 if (!len || s[len-1] != ';') {
669 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
670 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
671 sv_catpvs(PL_linestr, "\n;");
673 SvTEMP_off(PL_linestr);
674 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
675 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
676 PL_last_lop = PL_last_uni = NULL;
682 * Finalizer for lexing operations. Must be called when the parser is
683 * done with the lexer.
690 PL_doextract = FALSE;
695 * This subroutine has nothing to do with tilting, whether at windmills
696 * or pinball tables. Its name is short for "increment line". It
697 * increments the current line number in CopLINE(PL_curcop) and checks
698 * to see whether the line starts with a comment of the form
699 * # line 500 "foo.pm"
700 * If so, it sets the current line number and file to the values in the comment.
704 S_incline(pTHX_ char *s)
712 CopLINE_inc(PL_curcop);
715 while (SPACE_OR_TAB(*s))
717 if (strnEQ(s, "line", 4))
721 if (SPACE_OR_TAB(*s))
725 while (SPACE_OR_TAB(*s))
733 while (SPACE_OR_TAB(*s))
735 if (*s == '"' && (t = strchr(s+1, '"'))) {
745 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
747 if (*e != '\n' && *e != '\0')
748 return; /* false alarm */
754 const char * const cf = CopFILE(PL_curcop);
755 STRLEN tmplen = cf ? strlen(cf) : 0;
756 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
757 /* must copy *{"::_<(eval N)[oldfilename:L]"}
758 * to *{"::_<newfilename"} */
759 char smallbuf[256], smallbuf2[256];
760 char *tmpbuf, *tmpbuf2;
762 STRLEN tmplen2 = strlen(s);
763 if (tmplen + 3 < sizeof smallbuf)
766 Newx(tmpbuf, tmplen + 3, char);
767 if (tmplen2 + 3 < sizeof smallbuf2)
770 Newx(tmpbuf2, tmplen2 + 3, char);
771 tmpbuf[0] = tmpbuf2[0] = '_';
772 tmpbuf[1] = tmpbuf2[1] = '<';
773 memcpy(tmpbuf + 2, cf, ++tmplen);
774 memcpy(tmpbuf2 + 2, s, ++tmplen2);
776 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
778 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
780 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
781 /* adjust ${"::_<newfilename"} to store the new file name */
782 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
783 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
784 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
786 if (tmpbuf != smallbuf) Safefree(tmpbuf);
787 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
790 CopFILE_free(PL_curcop);
791 CopFILE_set(PL_curcop, s);
794 CopLINE_set(PL_curcop, atoi(n)-1);
798 /* skip space before PL_thistoken */
801 S_skipspace0(pTHX_ register char *s)
808 PL_thiswhite = newSVpvs("");
809 sv_catsv(PL_thiswhite, PL_skipwhite);
810 sv_free(PL_skipwhite);
813 PL_realtokenstart = s - SvPVX(PL_linestr);
817 /* skip space after PL_thistoken */
820 S_skipspace1(pTHX_ register char *s)
822 const char *start = s;
823 I32 startoff = start - SvPVX(PL_linestr);
828 start = SvPVX(PL_linestr) + startoff;
829 if (!PL_thistoken && PL_realtokenstart >= 0) {
830 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
831 PL_thistoken = newSVpvn(tstart, start - tstart);
833 PL_realtokenstart = -1;
836 PL_nextwhite = newSVpvs("");
837 sv_catsv(PL_nextwhite, PL_skipwhite);
838 sv_free(PL_skipwhite);
845 S_skipspace2(pTHX_ register char *s, SV **svp)
848 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
849 const I32 startoff = s - SvPVX(PL_linestr);
852 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
853 if (!PL_madskills || !svp)
855 start = SvPVX(PL_linestr) + startoff;
856 if (!PL_thistoken && PL_realtokenstart >= 0) {
857 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
858 PL_thistoken = newSVpvn(tstart, start - tstart);
859 PL_realtokenstart = -1;
864 sv_setsv(*svp, PL_skipwhite);
865 sv_free(PL_skipwhite);
875 * Called to gobble the appropriate amount and type of whitespace.
876 * Skips comments as well.
880 S_skipspace(pTHX_ register char *s)
885 int startoff = s - SvPVX(PL_linestr);
888 sv_free(PL_skipwhite);
893 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
894 while (s < PL_bufend && SPACE_OR_TAB(*s))
904 SSize_t oldprevlen, oldoldprevlen;
905 SSize_t oldloplen = 0, oldunilen = 0;
906 while (s < PL_bufend && isSPACE(*s)) {
907 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
912 if (s < PL_bufend && *s == '#') {
913 while (s < PL_bufend && *s != '\n')
917 if (PL_in_eval && !PL_rsfp) {
924 /* only continue to recharge the buffer if we're at the end
925 * of the buffer, we're not reading from a source filter, and
926 * we're in normal lexing mode
928 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
929 PL_lex_state == LEX_FORMLINE)
936 /* try to recharge the buffer */
938 curoff = s - SvPVX(PL_linestr);
941 if ((s = filter_gets(PL_linestr, PL_rsfp,
942 (prevlen = SvCUR(PL_linestr)))) == NULL)
945 if (PL_madskills && curoff != startoff) {
947 PL_skipwhite = newSVpvs("");
948 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
952 /* mustn't throw out old stuff yet if madpropping */
953 SvCUR(PL_linestr) = curoff;
954 s = SvPVX(PL_linestr) + curoff;
956 if (curoff && s[-1] == '\n')
960 /* end of file. Add on the -p or -n magic */
961 /* XXX these shouldn't really be added here, can't set PL_faketokens */
965 ";}continue{print or die qq(-p destination: $!\\n);}");
968 ";}continue{print or die qq(-p destination: $!\\n);}");
970 PL_minus_n = PL_minus_p = 0;
972 else if (PL_minus_n) {
974 sv_catpvn(PL_linestr, ";}", 2);
976 sv_setpvn(PL_linestr, ";}", 2);
982 sv_catpvn(PL_linestr,";", 1);
984 sv_setpvn(PL_linestr,";", 1);
987 /* reset variables for next time we lex */
988 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
994 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
995 PL_last_lop = PL_last_uni = NULL;
997 /* Close the filehandle. Could be from -P preprocessor,
998 * STDIN, or a regular file. If we were reading code from
999 * STDIN (because the commandline held no -e or filename)
1000 * then we don't close it, we reset it so the code can
1001 * read from STDIN too.
1004 if (PL_preprocess && !PL_in_eval)
1005 (void)PerlProc_pclose(PL_rsfp);
1006 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1007 PerlIO_clearerr(PL_rsfp);
1009 (void)PerlIO_close(PL_rsfp);
1014 /* not at end of file, so we only read another line */
1015 /* make corresponding updates to old pointers, for yyerror() */
1016 oldprevlen = PL_oldbufptr - PL_bufend;
1017 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1019 oldunilen = PL_last_uni - PL_bufend;
1021 oldloplen = PL_last_lop - PL_bufend;
1022 PL_linestart = PL_bufptr = s + prevlen;
1023 PL_bufend = s + SvCUR(PL_linestr);
1025 PL_oldbufptr = s + oldprevlen;
1026 PL_oldoldbufptr = s + oldoldprevlen;
1028 PL_last_uni = s + oldunilen;
1030 PL_last_lop = s + oldloplen;
1033 /* debugger active and we're not compiling the debugger code,
1034 * so store the line into the debugger's array of lines
1036 if (PERLDB_LINE && PL_curstash != PL_debstash) {
1037 SV * const sv = newSV(0);
1039 sv_upgrade(sv, SVt_PVMG);
1040 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
1043 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
1051 PL_skipwhite = newSVpvs("");
1052 curoff = s - SvPVX(PL_linestr);
1053 if (curoff - startoff)
1054 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1063 * Check the unary operators to ensure there's no ambiguity in how they're
1064 * used. An ambiguous piece of code would be:
1066 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1067 * the +5 is its argument.
1077 if (PL_oldoldbufptr != PL_last_uni)
1079 while (isSPACE(*PL_last_uni))
1082 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1084 if ((t = strchr(s, '(')) && t < PL_bufptr)
1087 if (ckWARN_d(WARN_AMBIGUOUS)){
1088 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1089 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1090 (int)(s - PL_last_uni), PL_last_uni);
1095 * LOP : macro to build a list operator. Its behaviour has been replaced
1096 * with a subroutine, S_lop() for which LOP is just another name.
1099 #define LOP(f,x) return lop(f,x,s)
1103 * Build a list operator (or something that might be one). The rules:
1104 * - if we have a next token, then it's a list operator [why?]
1105 * - if the next thing is an opening paren, then it's a function
1106 * - else it's a list operator
1110 S_lop(pTHX_ I32 f, int x, char *s)
1117 PL_last_lop = PL_oldbufptr;
1118 PL_last_lop_op = (OPCODE)f;
1121 return REPORT(LSTOP);
1124 return REPORT(LSTOP);
1127 return REPORT(FUNC);
1130 return REPORT(FUNC);
1132 return REPORT(LSTOP);
1138 * Sets up for an eventual force_next(). start_force(0) basically does
1139 * an unshift, while start_force(-1) does a push. yylex removes items
1144 S_start_force(pTHX_ int where)
1148 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1149 where = PL_lasttoke;
1150 assert(PL_curforce < 0 || PL_curforce == where);
1151 if (PL_curforce != where) {
1152 for (i = PL_lasttoke; i > where; --i) {
1153 PL_nexttoke[i] = PL_nexttoke[i-1];
1157 if (PL_curforce < 0) /* in case of duplicate start_force() */
1158 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1159 PL_curforce = where;
1162 curmad('^', newSVpvs(""));
1163 CURMAD('_', PL_nextwhite);
1168 S_curmad(pTHX_ char slot, SV *sv)
1174 if (PL_curforce < 0)
1175 where = &PL_thismad;
1177 where = &PL_nexttoke[PL_curforce].next_mad;
1180 sv_setpvn(sv, "", 0);
1183 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1185 else if (PL_encoding) {
1186 sv_recode_to_utf8(sv, PL_encoding);
1191 /* keep a slot open for the head of the list? */
1192 if (slot != '_' && *where && (*where)->mad_key == '^') {
1193 (*where)->mad_key = slot;
1194 sv_free((*where)->mad_val);
1195 (*where)->mad_val = (void*)sv;
1198 addmad(newMADsv(slot, sv), where, 0);
1201 # define start_force(where) NOOP
1202 # define curmad(slot, sv) NOOP
1207 * When the lexer realizes it knows the next token (for instance,
1208 * it is reordering tokens for the parser) then it can call S_force_next
1209 * to know what token to return the next time the lexer is called. Caller
1210 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1211 * and possibly PL_expect to ensure the lexer handles the token correctly.
1215 S_force_next(pTHX_ I32 type)
1219 if (PL_curforce < 0)
1220 start_force(PL_lasttoke);
1221 PL_nexttoke[PL_curforce].next_type = type;
1222 if (PL_lex_state != LEX_KNOWNEXT)
1223 PL_lex_defer = PL_lex_state;
1224 PL_lex_state = LEX_KNOWNEXT;
1225 PL_lex_expect = PL_expect;
1228 PL_nexttype[PL_nexttoke] = type;
1230 if (PL_lex_state != LEX_KNOWNEXT) {
1231 PL_lex_defer = PL_lex_state;
1232 PL_lex_expect = PL_expect;
1233 PL_lex_state = LEX_KNOWNEXT;
1239 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1242 SV * const sv = newSVpvn(start,len);
1243 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1250 * When the lexer knows the next thing is a word (for instance, it has
1251 * just seen -> and it knows that the next char is a word char, then
1252 * it calls S_force_word to stick the next word into the PL_next lookahead.
1255 * char *start : buffer position (must be within PL_linestr)
1256 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
1257 * int check_keyword : if true, Perl checks to make sure the word isn't
1258 * a keyword (do this if the word is a label, e.g. goto FOO)
1259 * int allow_pack : if true, : characters will also be allowed (require,
1260 * use, etc. do this)
1261 * int allow_initial_tick : used by the "sub" lexer only.
1265 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1271 start = SKIPSPACE1(start);
1273 if (isIDFIRST_lazy_if(s,UTF) ||
1274 (allow_pack && *s == ':') ||
1275 (allow_initial_tick && *s == '\'') )
1277 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1278 if (check_keyword && keyword(PL_tokenbuf, len, 0))
1280 start_force(PL_curforce);
1282 curmad('X', newSVpvn(start,s-start));
1283 if (token == METHOD) {
1288 PL_expect = XOPERATOR;
1291 NEXTVAL_NEXTTOKE.opval
1292 = (OP*)newSVOP(OP_CONST,0,
1293 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1294 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1302 * Called when the lexer wants $foo *foo &foo etc, but the program
1303 * text only contains the "foo" portion. The first argument is a pointer
1304 * to the "foo", and the second argument is the type symbol to prefix.
1305 * Forces the next token to be a "WORD".
1306 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1310 S_force_ident(pTHX_ register const char *s, int kind)
1314 const STRLEN len = strlen(s);
1315 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1316 start_force(PL_curforce);
1317 NEXTVAL_NEXTTOKE.opval = o;
1320 o->op_private = OPpCONST_ENTERED;
1321 /* XXX see note in pp_entereval() for why we forgo typo
1322 warnings if the symbol must be introduced in an eval.
1324 gv_fetchpvn_flags(s, len,
1325 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1327 kind == '$' ? SVt_PV :
1328 kind == '@' ? SVt_PVAV :
1329 kind == '%' ? SVt_PVHV :
1337 Perl_str_to_version(pTHX_ SV *sv)
1342 const char *start = SvPV_const(sv,len);
1343 const char * const end = start + len;
1344 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1345 while (start < end) {
1349 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1354 retval += ((NV)n)/nshift;
1363 * Forces the next token to be a version number.
1364 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1365 * and if "guessing" is TRUE, then no new token is created (and the caller
1366 * must use an alternative parsing method).
1370 S_force_version(pTHX_ char *s, int guessing)
1376 I32 startoff = s - SvPVX(PL_linestr);
1385 while (isDIGIT(*d) || *d == '_' || *d == '.')
1389 start_force(PL_curforce);
1390 curmad('X', newSVpvn(s,d-s));
1393 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1395 s = scan_num(s, &yylval);
1396 version = yylval.opval;
1397 ver = cSVOPx(version)->op_sv;
1398 if (SvPOK(ver) && !SvNIOK(ver)) {
1399 SvUPGRADE(ver, SVt_PVNV);
1400 SvNV_set(ver, str_to_version(ver));
1401 SvNOK_on(ver); /* hint that it is a version */
1404 else if (guessing) {
1407 sv_free(PL_nextwhite); /* let next token collect whitespace */
1409 s = SvPVX(PL_linestr) + startoff;
1417 if (PL_madskills && !version) {
1418 sv_free(PL_nextwhite); /* let next token collect whitespace */
1420 s = SvPVX(PL_linestr) + startoff;
1423 /* NOTE: The parser sees the package name and the VERSION swapped */
1424 start_force(PL_curforce);
1425 NEXTVAL_NEXTTOKE.opval = version;
1433 * Tokenize a quoted string passed in as an SV. It finds the next
1434 * chunk, up to end of string or a backslash. It may make a new
1435 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1440 S_tokeq(pTHX_ SV *sv)
1444 register char *send;
1452 s = SvPV_force(sv, len);
1453 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1456 while (s < send && *s != '\\')
1461 if ( PL_hints & HINT_NEW_STRING ) {
1462 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1468 if (s + 1 < send && (s[1] == '\\'))
1469 s++; /* all that, just for this */
1474 SvCUR_set(sv, d - SvPVX_const(sv));
1476 if ( PL_hints & HINT_NEW_STRING )
1477 return new_constant(NULL, 0, "q", sv, pv, "q");
1482 * Now come three functions related to double-quote context,
1483 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1484 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1485 * interact with PL_lex_state, and create fake ( ... ) argument lists
1486 * to handle functions and concatenation.
1487 * They assume that whoever calls them will be setting up a fake
1488 * join call, because each subthing puts a ',' after it. This lets
1491 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1493 * (I'm not sure whether the spurious commas at the end of lcfirst's
1494 * arguments and join's arguments are created or not).
1499 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1501 * Pattern matching will set PL_lex_op to the pattern-matching op to
1502 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1504 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1506 * Everything else becomes a FUNC.
1508 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1509 * had an OP_CONST or OP_READLINE). This just sets us up for a
1510 * call to S_sublex_push().
1514 S_sublex_start(pTHX)
1517 register const I32 op_type = yylval.ival;
1519 if (op_type == OP_NULL) {
1520 yylval.opval = PL_lex_op;
1524 if (op_type == OP_CONST || op_type == OP_READLINE) {
1525 SV *sv = tokeq(PL_lex_stuff);
1527 if (SvTYPE(sv) == SVt_PVIV) {
1528 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1530 const char * const p = SvPV_const(sv, len);
1531 SV * const nsv = newSVpvn(p, len);
1537 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1538 PL_lex_stuff = NULL;
1539 /* Allow <FH> // "foo" */
1540 if (op_type == OP_READLINE)
1541 PL_expect = XTERMORDORDOR;
1545 PL_sublex_info.super_state = PL_lex_state;
1546 PL_sublex_info.sub_inwhat = op_type;
1547 PL_sublex_info.sub_op = PL_lex_op;
1548 PL_lex_state = LEX_INTERPPUSH;
1552 yylval.opval = PL_lex_op;
1562 * Create a new scope to save the lexing state. The scope will be
1563 * ended in S_sublex_done. Returns a '(', starting the function arguments
1564 * to the uc, lc, etc. found before.
1565 * Sets PL_lex_state to LEX_INTERPCONCAT.
1574 PL_lex_state = PL_sublex_info.super_state;
1575 SAVEI32(PL_lex_dojoin);
1576 SAVEI32(PL_lex_brackets);
1577 SAVEI32(PL_lex_casemods);
1578 SAVEI32(PL_lex_starts);
1579 SAVEI32(PL_lex_state);
1580 SAVEVPTR(PL_lex_inpat);
1581 SAVEI32(PL_lex_inwhat);
1582 SAVECOPLINE(PL_curcop);
1583 SAVEPPTR(PL_bufptr);
1584 SAVEPPTR(PL_bufend);
1585 SAVEPPTR(PL_oldbufptr);
1586 SAVEPPTR(PL_oldoldbufptr);
1587 SAVEPPTR(PL_last_lop);
1588 SAVEPPTR(PL_last_uni);
1589 SAVEPPTR(PL_linestart);
1590 SAVESPTR(PL_linestr);
1591 SAVEGENERICPV(PL_lex_brackstack);
1592 SAVEGENERICPV(PL_lex_casestack);
1594 PL_linestr = PL_lex_stuff;
1595 PL_lex_stuff = NULL;
1597 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1598 = SvPVX(PL_linestr);
1599 PL_bufend += SvCUR(PL_linestr);
1600 PL_last_lop = PL_last_uni = NULL;
1601 SAVEFREESV(PL_linestr);
1603 PL_lex_dojoin = FALSE;
1604 PL_lex_brackets = 0;
1605 Newx(PL_lex_brackstack, 120, char);
1606 Newx(PL_lex_casestack, 12, char);
1607 PL_lex_casemods = 0;
1608 *PL_lex_casestack = '\0';
1610 PL_lex_state = LEX_INTERPCONCAT;
1611 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1613 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1614 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1615 PL_lex_inpat = PL_sublex_info.sub_op;
1617 PL_lex_inpat = NULL;
1624 * Restores lexer state after a S_sublex_push.
1631 if (!PL_lex_starts++) {
1632 SV * const sv = newSVpvs("");
1633 if (SvUTF8(PL_linestr))
1635 PL_expect = XOPERATOR;
1636 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1640 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1641 PL_lex_state = LEX_INTERPCASEMOD;
1645 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1646 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1647 PL_linestr = PL_lex_repl;
1649 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1650 PL_bufend += SvCUR(PL_linestr);
1651 PL_last_lop = PL_last_uni = NULL;
1652 SAVEFREESV(PL_linestr);
1653 PL_lex_dojoin = FALSE;
1654 PL_lex_brackets = 0;
1655 PL_lex_casemods = 0;
1656 *PL_lex_casestack = '\0';
1658 if (SvEVALED(PL_lex_repl)) {
1659 PL_lex_state = LEX_INTERPNORMAL;
1661 /* we don't clear PL_lex_repl here, so that we can check later
1662 whether this is an evalled subst; that means we rely on the
1663 logic to ensure sublex_done() is called again only via the
1664 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1667 PL_lex_state = LEX_INTERPCONCAT;
1677 PL_endwhite = newSVpvs("");
1678 sv_catsv(PL_endwhite, PL_thiswhite);
1682 sv_setpvn(PL_thistoken,"",0);
1684 PL_realtokenstart = -1;
1688 PL_bufend = SvPVX(PL_linestr);
1689 PL_bufend += SvCUR(PL_linestr);
1690 PL_expect = XOPERATOR;
1691 PL_sublex_info.sub_inwhat = 0;
1699 Extracts a pattern, double-quoted string, or transliteration. This
1702 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
1703 processing a pattern (PL_lex_inpat is true), a transliteration
1704 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
1706 Returns a pointer to the character scanned up to. If this is
1707 advanced from the start pointer supplied (i.e. if anything was
1708 successfully parsed), will leave an OP for the substring scanned
1709 in yylval. Caller must intuit reason for not parsing further
1710 by looking at the next characters herself.
1714 double-quoted style: \r and \n
1715 regexp special ones: \D \s
1718 case and quoting: \U \Q \E
1719 stops on @ and $, but not for $ as tail anchor
1721 In transliterations:
1722 characters are VERY literal, except for - not at the start or end
1723 of the string, which indicates a range. If the range is in bytes,
1724 scan_const expands the range to the full set of intermediate
1725 characters. If the range is in utf8, the hyphen is replaced with
1726 a certain range mark which will be handled by pmtrans() in op.c.
1728 In double-quoted strings:
1730 double-quoted style: \r and \n
1732 deprecated backrefs: \1 (in substitution replacements)
1733 case and quoting: \U \Q \E
1736 scan_const does *not* construct ops to handle interpolated strings.
1737 It stops processing as soon as it finds an embedded $ or @ variable
1738 and leaves it to the caller to work out what's going on.
1740 embedded arrays (whether in pattern or not) could be:
1741 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1743 $ in double-quoted strings must be the symbol of an embedded scalar.
1745 $ in pattern could be $foo or could be tail anchor. Assumption:
1746 it's a tail anchor if $ is the last thing in the string, or if it's
1747 followed by one of "()| \r\n\t"
1749 \1 (backreferences) are turned into $1
1751 The structure of the code is
1752 while (there's a character to process) {
1753 handle transliteration ranges
1754 skip regexp comments /(?#comment)/ and codes /(?{code})/
1755 skip #-initiated comments in //x patterns
1756 check for embedded arrays
1757 check for embedded scalars
1759 leave intact backslashes from leaveit (below)
1760 deprecate \1 in substitution replacements
1761 handle string-changing backslashes \l \U \Q \E, etc.
1762 switch (what was escaped) {
1763 handle \- in a transliteration (becomes a literal -)
1764 handle \132 (octal characters)
1765 handle \x15 and \x{1234} (hex characters)
1766 handle \N{name} (named characters)
1767 handle \cV (control characters)
1768 handle printf-style backslashes (\f, \r, \n, etc)
1770 } (end if backslash)
1771 } (end while character to read)
1776 S_scan_const(pTHX_ char *start)
1779 register char *send = PL_bufend; /* end of the constant */
1780 SV *sv = newSV(send - start); /* sv for the constant */
1781 register char *s = start; /* start of the constant */
1782 register char *d = SvPVX(sv); /* destination for copies */
1783 bool dorange = FALSE; /* are we in a translit range? */
1784 bool didrange = FALSE; /* did we just finish a range? */
1785 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1786 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1789 UV literal_endpoint = 0;
1790 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
1793 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1794 /* If we are doing a trans and we know we want UTF8 set expectation */
1795 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1796 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1800 while (s < send || dorange) {
1801 /* get transliterations out of the way (they're most literal) */
1802 if (PL_lex_inwhat == OP_TRANS) {
1803 /* expand a range A-Z to the full set of characters. AIE! */
1805 I32 i; /* current expanded character */
1806 I32 min; /* first character in range */
1807 I32 max; /* last character in range */
1818 char * const c = (char*)utf8_hop((U8*)d, -1);
1822 *c = (char)UTF_TO_NATIVE(0xff);
1823 /* mark the range as done, and continue */
1829 i = d - SvPVX_const(sv); /* remember current offset */
1832 SvLEN(sv) + (has_utf8 ?
1833 (512 - UTF_CONTINUATION_MARK +
1836 /* How many two-byte within 0..255: 128 in UTF-8,
1837 * 96 in UTF-8-mod. */
1839 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1841 d = SvPVX(sv) + i; /* refresh d after realloc */
1845 for (j = 0; j <= 1; j++) {
1846 char * const c = (char*)utf8_hop((U8*)d, -1);
1847 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
1853 max = (U8)0xff; /* only to \xff */
1854 uvmax = uv; /* \x{100} to uvmax */
1856 d = c; /* eat endpoint chars */
1861 d -= 2; /* eat the first char and the - */
1862 min = (U8)*d; /* first char in range */
1863 max = (U8)d[1]; /* last char in range */
1870 "Invalid range \"%c-%c\" in transliteration operator",
1871 (char)min, (char)max);
1875 if (literal_endpoint == 2 &&
1876 ((isLOWER(min) && isLOWER(max)) ||
1877 (isUPPER(min) && isUPPER(max)))) {
1879 for (i = min; i <= max; i++)
1881 *d++ = NATIVE_TO_NEED(has_utf8,i);
1883 for (i = min; i <= max; i++)
1885 *d++ = NATIVE_TO_NEED(has_utf8,i);
1890 for (i = min; i <= max; i++)
1893 const U8 ch = (U8)NATIVE_TO_UTF(i);
1894 if (UNI_IS_INVARIANT(ch))
1897 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
1898 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
1907 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
1909 *d++ = (char)UTF_TO_NATIVE(0xff);
1911 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
1915 /* mark the range as done, and continue */
1919 literal_endpoint = 0;
1924 /* range begins (ignore - as first or last char) */
1925 else if (*s == '-' && s+1 < send && s != start) {
1927 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1934 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1944 literal_endpoint = 0;
1945 native_range = TRUE;
1950 /* if we get here, we're not doing a transliteration */
1952 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1953 except for the last char, which will be done separately. */
1954 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1956 while (s+1 < send && *s != ')')
1957 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1959 else if (s[2] == '{' /* This should match regcomp.c */
1960 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1963 char *regparse = s + (s[2] == '{' ? 3 : 4);
1966 while (count && (c = *regparse)) {
1967 if (c == '\\' && regparse[1])
1975 if (*regparse != ')')
1976 regparse--; /* Leave one char for continuation. */
1977 while (s < regparse)
1978 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1982 /* likewise skip #-initiated comments in //x patterns */
1983 else if (*s == '#' && PL_lex_inpat &&
1984 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1985 while (s+1 < send && *s != '\n')
1986 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1989 /* check for embedded arrays
1990 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1992 else if (*s == '@' && s[1]) {
1993 if (isALNUM_lazy_if(s+1,UTF))
1995 if (strchr(":'{$", s[1]))
1997 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
1998 break; /* in regexp, neither @+ nor @- are interpolated */
2001 /* check for embedded scalars. only stop if we're sure it's a
2004 else if (*s == '$') {
2005 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
2007 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
2008 break; /* in regexp, $ might be tail anchor */
2011 /* End of else if chain - OP_TRANS rejoin rest */
2014 if (*s == '\\' && s+1 < send) {
2017 /* deprecate \1 in strings and substitution replacements */
2018 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2019 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2021 if (ckWARN(WARN_SYNTAX))
2022 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2027 /* string-change backslash escapes */
2028 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2032 /* skip any other backslash escapes in a pattern */
2033 else if (PL_lex_inpat) {
2034 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2035 goto default_action;
2038 /* if we get here, it's either a quoted -, or a digit */
2041 /* quoted - in transliterations */
2043 if (PL_lex_inwhat == OP_TRANS) {
2050 if ((isALPHA(*s) || isDIGIT(*s)) &&
2052 Perl_warner(aTHX_ packWARN(WARN_MISC),
2053 "Unrecognized escape \\%c passed through",
2055 /* default action is to copy the quoted character */
2056 goto default_action;
2059 /* \132 indicates an octal constant */
2060 case '0': case '1': case '2': case '3':
2061 case '4': case '5': case '6': case '7':
2065 uv = grok_oct(s, &len, &flags, NULL);
2068 goto NUM_ESCAPE_INSERT;
2070 /* \x24 indicates a hex constant */
2074 char* const e = strchr(s, '}');
2075 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2076 PERL_SCAN_DISALLOW_PREFIX;
2081 yyerror("Missing right brace on \\x{}");
2085 uv = grok_hex(s, &len, &flags, NULL);
2091 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2092 uv = grok_hex(s, &len, &flags, NULL);
2098 /* Insert oct or hex escaped character.
2099 * There will always enough room in sv since such
2100 * escapes will be longer than any UTF-8 sequence
2101 * they can end up as. */
2103 /* We need to map to chars to ASCII before doing the tests
2106 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2107 if (!has_utf8 && uv > 255) {
2108 /* Might need to recode whatever we have
2109 * accumulated so far if it contains any
2112 * (Can't we keep track of that and avoid
2113 * this rescan? --jhi)
2117 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2118 if (!NATIVE_IS_INVARIANT(*c)) {
2123 const STRLEN offset = d - SvPVX_const(sv);
2125 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2129 while (src >= (const U8 *)SvPVX_const(sv)) {
2130 if (!NATIVE_IS_INVARIANT(*src)) {
2131 const U8 ch = NATIVE_TO_ASCII(*src);
2132 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2133 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2143 if (has_utf8 || uv > 255) {
2144 d = (char*)uvchr_to_utf8((U8*)d, uv);
2146 if (PL_lex_inwhat == OP_TRANS &&
2147 PL_sublex_info.sub_op) {
2148 PL_sublex_info.sub_op->op_private |=
2149 (PL_lex_repl ? OPpTRANS_FROM_UTF
2153 if (uv > 255 && !dorange)
2154 native_range = FALSE;
2166 /* \N{LATIN SMALL LETTER A} is a named character */
2170 char* e = strchr(s, '}');
2177 yyerror("Missing right brace on \\N{}");
2181 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2183 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2184 PERL_SCAN_DISALLOW_PREFIX;
2187 uv = grok_hex(s, &len, &flags, NULL);
2188 if ( e > s && len != (STRLEN)(e - s) ) {
2192 goto NUM_ESCAPE_INSERT;
2194 res = newSVpvn(s + 1, e - s - 1);
2195 type = newSVpvn(s - 2,e - s + 3);
2196 res = new_constant( NULL, 0, "charnames",
2197 res, NULL, SvPVX(type) );
2200 sv_utf8_upgrade(res);
2201 str = SvPV_const(res,len);
2202 #ifdef EBCDIC_NEVER_MIND
2203 /* charnames uses pack U and that has been
2204 * recently changed to do the below uni->native
2205 * mapping, so this would be redundant (and wrong,
2206 * the code point would be doubly converted).
2207 * But leave this in just in case the pack U change
2208 * gets revoked, but the semantics is still
2209 * desireable for charnames. --jhi */
2211 UV uv = utf8_to_uvchr((const U8*)str, 0);
2214 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2216 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2217 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2218 str = SvPV_const(res, len);
2222 if (!has_utf8 && SvUTF8(res)) {
2223 const char * const ostart = SvPVX_const(sv);
2224 SvCUR_set(sv, d - ostart);
2227 sv_utf8_upgrade(sv);
2228 /* this just broke our allocation above... */
2229 SvGROW(sv, (STRLEN)(send - start));
2230 d = SvPVX(sv) + SvCUR(sv);
2233 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2234 const char * const odest = SvPVX_const(sv);
2236 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2237 d = SvPVX(sv) + (d - odest);
2241 native_range = FALSE; /* \N{} is guessed to be Unicode */
2243 Copy(str, d, len, char);
2250 yyerror("Missing braces on \\N{}");
2253 /* \c is a control character */
2262 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2265 yyerror("Missing control char name in \\c");
2269 /* printf-style backslashes, formfeeds, newlines, etc */
2271 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2274 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2277 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2280 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2283 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2286 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2289 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2295 } /* end if (backslash) */
2302 /* If we started with encoded form, or already know we want it
2303 and then encode the next character */
2304 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2306 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2307 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2310 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2311 const STRLEN off = d - SvPVX_const(sv);
2312 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2314 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2317 if (uv > 255 && !dorange)
2318 native_range = FALSE;
2322 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2324 } /* while loop to process each character */
2326 /* terminate the string and set up the sv */
2328 SvCUR_set(sv, d - SvPVX_const(sv));
2329 if (SvCUR(sv) >= SvLEN(sv))
2330 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2333 if (PL_encoding && !has_utf8) {
2334 sv_recode_to_utf8(sv, PL_encoding);
2340 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2341 PL_sublex_info.sub_op->op_private |=
2342 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2346 /* shrink the sv if we allocated more than we used */
2347 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2348 SvPV_shrink_to_cur(sv);
2351 /* return the substring (via yylval) only if we parsed anything */
2352 if (s > PL_bufptr) {
2353 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2354 sv = new_constant(start, s - start,
2355 (const char *)(PL_lex_inpat ? "qr" : "q"),
2358 (( PL_lex_inwhat == OP_TRANS
2360 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2363 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2370 * Returns TRUE if there's more to the expression (e.g., a subscript),
2373 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2375 * ->[ and ->{ return TRUE
2376 * { and [ outside a pattern are always subscripts, so return TRUE
2377 * if we're outside a pattern and it's not { or [, then return FALSE
2378 * if we're in a pattern and the first char is a {
2379 * {4,5} (any digits around the comma) returns FALSE
2380 * if we're in a pattern and the first char is a [
2382 * [SOMETHING] has a funky algorithm to decide whether it's a
2383 * character class or not. It has to deal with things like
2384 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2385 * anything else returns TRUE
2388 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2391 S_intuit_more(pTHX_ register char *s)
2394 if (PL_lex_brackets)
2396 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2398 if (*s != '{' && *s != '[')
2403 /* In a pattern, so maybe we have {n,m}. */
2420 /* On the other hand, maybe we have a character class */
2423 if (*s == ']' || *s == '^')
2426 /* this is terrifying, and it works */
2427 int weight = 2; /* let's weigh the evidence */
2429 unsigned char un_char = 255, last_un_char;
2430 const char * const send = strchr(s,']');
2431 char tmpbuf[sizeof PL_tokenbuf * 4];
2433 if (!send) /* has to be an expression */
2436 Zero(seen,256,char);
2439 else if (isDIGIT(*s)) {
2441 if (isDIGIT(s[1]) && s[2] == ']')
2447 for (; s < send; s++) {
2448 last_un_char = un_char;
2449 un_char = (unsigned char)*s;
2454 weight -= seen[un_char] * 10;
2455 if (isALNUM_lazy_if(s+1,UTF)) {
2457 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2458 len = (int)strlen(tmpbuf);
2459 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2464 else if (*s == '$' && s[1] &&
2465 strchr("[#!%*<>()-=",s[1])) {
2466 if (/*{*/ strchr("])} =",s[2]))
2475 if (strchr("wds]",s[1]))
2477 else if (seen[(U8)'\''] || seen[(U8)'"'])
2479 else if (strchr("rnftbxcav",s[1]))
2481 else if (isDIGIT(s[1])) {
2483 while (s[1] && isDIGIT(s[1]))
2493 if (strchr("aA01! ",last_un_char))
2495 if (strchr("zZ79~",s[1]))
2497 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2498 weight -= 5; /* cope with negative subscript */
2501 if (!isALNUM(last_un_char)
2502 && !(last_un_char == '$' || last_un_char == '@'
2503 || last_un_char == '&')
2504 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2509 if (keyword(tmpbuf, d - tmpbuf, 0))
2512 if (un_char == last_un_char + 1)
2514 weight -= seen[un_char];
2519 if (weight >= 0) /* probably a character class */
2529 * Does all the checking to disambiguate
2531 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2532 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2534 * First argument is the stuff after the first token, e.g. "bar".
2536 * Not a method if bar is a filehandle.
2537 * Not a method if foo is a subroutine prototyped to take a filehandle.
2538 * Not a method if it's really "Foo $bar"
2539 * Method if it's "foo $bar"
2540 * Not a method if it's really "print foo $bar"
2541 * Method if it's really "foo package::" (interpreted as package->foo)
2542 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2543 * Not a method if bar is a filehandle or package, but is quoted with
2548 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2551 char *s = start + (*start == '$');
2552 char tmpbuf[sizeof PL_tokenbuf];
2560 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2564 const char *proto = SvPVX_const(cv);
2575 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2576 /* start is the beginning of the possible filehandle/object,
2577 * and s is the end of it
2578 * tmpbuf is a copy of it
2581 if (*start == '$') {
2582 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2585 len = start - SvPVX(PL_linestr);
2589 start = SvPVX(PL_linestr) + len;
2593 return *s == '(' ? FUNCMETH : METHOD;
2595 if (!keyword(tmpbuf, len, 0)) {
2596 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2600 soff = s - SvPVX(PL_linestr);
2604 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2605 if (indirgv && GvCVu(indirgv))
2607 /* filehandle or package name makes it a method */
2608 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2610 soff = s - SvPVX(PL_linestr);
2613 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2614 return 0; /* no assumptions -- "=>" quotes bearword */
2616 start_force(PL_curforce);
2617 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2618 newSVpvn(tmpbuf,len));
2619 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2621 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2626 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2628 return *s == '(' ? FUNCMETH : METHOD;
2636 * Return a string of Perl code to load the debugger. If PERL5DB
2637 * is set, it will return the contents of that, otherwise a
2638 * compile-time require of perl5db.pl.
2646 const char * const pdb = PerlEnv_getenv("PERL5DB");
2650 SETERRNO(0,SS_NORMAL);
2651 return "BEGIN { require 'perl5db.pl' }";
2657 /* Encoded script support. filter_add() effectively inserts a
2658 * 'pre-processing' function into the current source input stream.
2659 * Note that the filter function only applies to the current source file
2660 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2662 * The datasv parameter (which may be NULL) can be used to pass
2663 * private data to this instance of the filter. The filter function
2664 * can recover the SV using the FILTER_DATA macro and use it to
2665 * store private buffers and state information.
2667 * The supplied datasv parameter is upgraded to a PVIO type
2668 * and the IoDIRP/IoANY field is used to store the function pointer,
2669 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2670 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2671 * private use must be set using malloc'd pointers.
2675 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2681 if (!PL_rsfp_filters)
2682 PL_rsfp_filters = newAV();
2685 SvUPGRADE(datasv, SVt_PVIO);
2686 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2687 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2688 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2689 FPTR2DPTR(void *, IoANY(datasv)),
2690 SvPV_nolen(datasv)));
2691 av_unshift(PL_rsfp_filters, 1);
2692 av_store(PL_rsfp_filters, 0, datasv) ;
2697 /* Delete most recently added instance of this filter function. */
2699 Perl_filter_del(pTHX_ filter_t funcp)
2705 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2706 FPTR2DPTR(void*, funcp)));
2708 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2710 /* if filter is on top of stack (usual case) just pop it off */
2711 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2712 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2713 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2714 IoANY(datasv) = (void *)NULL;
2715 sv_free(av_pop(PL_rsfp_filters));
2719 /* we need to search for the correct entry and clear it */
2720 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2724 /* Invoke the idxth filter function for the current rsfp. */
2725 /* maxlen 0 = read one text line */
2727 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2732 /* This API is bad. It should have been using unsigned int for maxlen.
2733 Not sure if we want to change the API, but if not we should sanity
2734 check the value here. */
2735 const unsigned int correct_length
2744 if (!PL_rsfp_filters)
2746 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2747 /* Provide a default input filter to make life easy. */
2748 /* Note that we append to the line. This is handy. */
2749 DEBUG_P(PerlIO_printf(Perl_debug_log,
2750 "filter_read %d: from rsfp\n", idx));
2751 if (correct_length) {
2754 const int old_len = SvCUR(buf_sv);
2756 /* ensure buf_sv is large enough */
2757 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2758 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2759 correct_length)) <= 0) {
2760 if (PerlIO_error(PL_rsfp))
2761 return -1; /* error */
2763 return 0 ; /* end of file */
2765 SvCUR_set(buf_sv, old_len + len) ;
2768 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2769 if (PerlIO_error(PL_rsfp))
2770 return -1; /* error */
2772 return 0 ; /* end of file */
2775 return SvCUR(buf_sv);
2777 /* Skip this filter slot if filter has been deleted */
2778 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2779 DEBUG_P(PerlIO_printf(Perl_debug_log,
2780 "filter_read %d: skipped (filter deleted)\n",
2782 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2784 /* Get function pointer hidden within datasv */
2785 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2786 DEBUG_P(PerlIO_printf(Perl_debug_log,
2787 "filter_read %d: via function %p (%s)\n",
2788 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2789 /* Call function. The function is expected to */
2790 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2791 /* Return: <0:error, =0:eof, >0:not eof */
2792 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2796 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2799 #ifdef PERL_CR_FILTER
2800 if (!PL_rsfp_filters) {
2801 filter_add(S_cr_textfilter,NULL);
2804 if (PL_rsfp_filters) {
2806 SvCUR_set(sv, 0); /* start with empty line */
2807 if (FILTER_READ(0, sv, 0) > 0)
2808 return ( SvPVX(sv) ) ;
2813 return (sv_gets(sv, fp, append));
2817 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2822 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2826 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2827 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2829 return GvHV(gv); /* Foo:: */
2832 /* use constant CLASS => 'MyClass' */
2833 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2834 if (gv && GvCV(gv)) {
2835 SV * const sv = cv_const_sv(GvCV(gv));
2837 pkgname = SvPV_nolen_const(sv);
2840 return gv_stashpv(pkgname, FALSE);
2846 * The intent of this yylex wrapper is to minimize the changes to the
2847 * tokener when we aren't interested in collecting madprops. It remains
2848 * to be seen how successful this strategy will be...
2855 char *s = PL_bufptr;
2857 /* make sure PL_thiswhite is initialized */
2861 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2862 if (PL_pending_ident)
2863 return S_pending_ident(aTHX);
2865 /* previous token ate up our whitespace? */
2866 if (!PL_lasttoke && PL_nextwhite) {
2867 PL_thiswhite = PL_nextwhite;
2871 /* isolate the token, and figure out where it is without whitespace */
2872 PL_realtokenstart = -1;
2876 assert(PL_curforce < 0);
2878 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2879 if (!PL_thistoken) {
2880 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2881 PL_thistoken = newSVpvs("");
2883 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2884 PL_thistoken = newSVpvn(tstart, s - tstart);
2887 if (PL_thismad) /* install head */
2888 CURMAD('X', PL_thistoken);
2891 /* last whitespace of a sublex? */
2892 if (optype == ')' && PL_endwhite) {
2893 CURMAD('X', PL_endwhite);
2898 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
2899 if (!PL_thiswhite && !PL_endwhite && !optype) {
2900 sv_free(PL_thistoken);
2905 /* put off final whitespace till peg */
2906 if (optype == ';' && !PL_rsfp) {
2907 PL_nextwhite = PL_thiswhite;
2910 else if (PL_thisopen) {
2911 CURMAD('q', PL_thisopen);
2913 sv_free(PL_thistoken);
2917 /* Store actual token text as madprop X */
2918 CURMAD('X', PL_thistoken);
2922 /* add preceding whitespace as madprop _ */
2923 CURMAD('_', PL_thiswhite);
2927 /* add quoted material as madprop = */
2928 CURMAD('=', PL_thisstuff);
2932 /* add terminating quote as madprop Q */
2933 CURMAD('Q', PL_thisclose);
2937 /* special processing based on optype */
2941 /* opval doesn't need a TOKEN since it can already store mp */
2952 append_madprops(PL_thismad, yylval.opval, 0);
2960 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
2969 /* remember any fake bracket that lexer is about to discard */
2970 if (PL_lex_brackets == 1 &&
2971 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
2974 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2977 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
2978 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
2981 break; /* don't bother looking for trailing comment */
2990 /* attach a trailing comment to its statement instead of next token */
2994 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
2996 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2998 if (*s == '\n' || *s == '#') {
2999 while (s < PL_bufend && *s != '\n')
3003 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3004 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3021 /* Create new token struct. Note: opvals return early above. */
3022 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
3029 S_tokenize_use(pTHX_ int is_use, char *s) {
3031 if (PL_expect != XSTATE)
3032 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3033 is_use ? "use" : "no"));
3035 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3036 s = force_version(s, TRUE);
3037 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3038 start_force(PL_curforce);
3039 NEXTVAL_NEXTTOKE.opval = NULL;
3042 else if (*s == 'v') {
3043 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3044 s = force_version(s, FALSE);
3048 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3049 s = force_version(s, FALSE);
3051 yylval.ival = is_use;
3055 static const char* const exp_name[] =
3056 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3057 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3064 Works out what to call the token just pulled out of the input
3065 stream. The yacc parser takes care of taking the ops we return and
3066 stitching them into a tree.
3072 if read an identifier
3073 if we're in a my declaration
3074 croak if they tried to say my($foo::bar)
3075 build the ops for a my() declaration
3076 if it's an access to a my() variable
3077 are we in a sort block?
3078 croak if my($a); $a <=> $b
3079 build ops for access to a my() variable
3080 if in a dq string, and they've said @foo and we can't find @foo
3082 build ops for a bareword
3083 if we already built the token before, use it.
3088 #pragma segment Perl_yylex
3094 register char *s = PL_bufptr;
3099 /* orig_keyword, gvp, and gv are initialized here because
3100 * jump to the label just_a_word_zero can bypass their
3101 * initialization later. */
3102 I32 orig_keyword = 0;
3107 SV* tmp = newSVpvs("");
3108 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3109 (IV)CopLINE(PL_curcop),
3110 lex_state_names[PL_lex_state],
3111 exp_name[PL_expect],
3112 pv_display(tmp, s, strlen(s), 0, 60));
3115 /* check if there's an identifier for us to look at */
3116 if (PL_pending_ident)
3117 return REPORT(S_pending_ident(aTHX));
3119 /* no identifier pending identification */
3121 switch (PL_lex_state) {
3123 case LEX_NORMAL: /* Some compilers will produce faster */
3124 case LEX_INTERPNORMAL: /* code if we comment these out. */
3128 /* when we've already built the next token, just pull it out of the queue */
3132 yylval = PL_nexttoke[PL_lasttoke].next_val;
3134 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3135 PL_nexttoke[PL_lasttoke].next_mad = 0;
3136 if (PL_thismad && PL_thismad->mad_key == '_') {
3137 PL_thiswhite = (SV*)PL_thismad->mad_val;
3138 PL_thismad->mad_val = 0;
3139 mad_free(PL_thismad);
3144 PL_lex_state = PL_lex_defer;
3145 PL_expect = PL_lex_expect;
3146 PL_lex_defer = LEX_NORMAL;
3147 if (!PL_nexttoke[PL_lasttoke].next_type)
3152 yylval = PL_nextval[PL_nexttoke];
3154 PL_lex_state = PL_lex_defer;
3155 PL_expect = PL_lex_expect;
3156 PL_lex_defer = LEX_NORMAL;
3160 /* FIXME - can these be merged? */
3161 return(PL_nexttoke[PL_lasttoke].next_type);
3163 return REPORT(PL_nexttype[PL_nexttoke]);
3166 /* interpolated case modifiers like \L \U, including \Q and \E.
3167 when we get here, PL_bufptr is at the \
3169 case LEX_INTERPCASEMOD:
3171 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3172 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3174 /* handle \E or end of string */
3175 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3177 if (PL_lex_casemods) {
3178 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3179 PL_lex_casestack[PL_lex_casemods] = '\0';
3181 if (PL_bufptr != PL_bufend
3182 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3184 PL_lex_state = LEX_INTERPCONCAT;
3187 PL_thistoken = newSVpvs("\\E");
3193 while (PL_bufptr != PL_bufend &&
3194 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3196 PL_thiswhite = newSVpvs("");
3197 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3201 if (PL_bufptr != PL_bufend)
3204 PL_lex_state = LEX_INTERPCONCAT;
3208 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3209 "### Saw case modifier\n"); });
3211 if (s[1] == '\\' && s[2] == 'E') {
3214 PL_thiswhite = newSVpvs("");
3215 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3218 PL_lex_state = LEX_INTERPCONCAT;
3223 if (!PL_madskills) /* when just compiling don't need correct */
3224 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3225 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3226 if ((*s == 'L' || *s == 'U') &&
3227 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3228 PL_lex_casestack[--PL_lex_casemods] = '\0';
3231 if (PL_lex_casemods > 10)
3232 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3233 PL_lex_casestack[PL_lex_casemods++] = *s;
3234 PL_lex_casestack[PL_lex_casemods] = '\0';
3235 PL_lex_state = LEX_INTERPCONCAT;
3236 start_force(PL_curforce);
3237 NEXTVAL_NEXTTOKE.ival = 0;
3239 start_force(PL_curforce);
3241 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3243 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3245 NEXTVAL_NEXTTOKE.ival = OP_LC;
3247 NEXTVAL_NEXTTOKE.ival = OP_UC;
3249 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3251 Perl_croak(aTHX_ "panic: yylex");
3253 SV* const tmpsv = newSVpvs("");
3254 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3260 if (PL_lex_starts) {
3266 sv_free(PL_thistoken);
3267 PL_thistoken = newSVpvs("");
3270 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3271 if (PL_lex_casemods == 1 && PL_lex_inpat)
3280 case LEX_INTERPPUSH:
3281 return REPORT(sublex_push());
3283 case LEX_INTERPSTART:
3284 if (PL_bufptr == PL_bufend)
3285 return REPORT(sublex_done());
3286 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3287 "### Interpolated variable\n"); });
3289 PL_lex_dojoin = (*PL_bufptr == '@');
3290 PL_lex_state = LEX_INTERPNORMAL;
3291 if (PL_lex_dojoin) {
3292 start_force(PL_curforce);
3293 NEXTVAL_NEXTTOKE.ival = 0;
3295 start_force(PL_curforce);
3296 force_ident("\"", '$');
3297 start_force(PL_curforce);
3298 NEXTVAL_NEXTTOKE.ival = 0;
3300 start_force(PL_curforce);
3301 NEXTVAL_NEXTTOKE.ival = 0;
3303 start_force(PL_curforce);
3304 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3307 if (PL_lex_starts++) {
3312 sv_free(PL_thistoken);
3313 PL_thistoken = newSVpvs("");
3316 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3317 if (!PL_lex_casemods && PL_lex_inpat)
3324 case LEX_INTERPENDMAYBE:
3325 if (intuit_more(PL_bufptr)) {
3326 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3332 if (PL_lex_dojoin) {
3333 PL_lex_dojoin = FALSE;
3334 PL_lex_state = LEX_INTERPCONCAT;
3338 sv_free(PL_thistoken);
3339 PL_thistoken = newSVpvs("");
3344 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3345 && SvEVALED(PL_lex_repl))
3347 if (PL_bufptr != PL_bufend)
3348 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3352 case LEX_INTERPCONCAT:
3354 if (PL_lex_brackets)
3355 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3357 if (PL_bufptr == PL_bufend)
3358 return REPORT(sublex_done());
3360 if (SvIVX(PL_linestr) == '\'') {
3361 SV *sv = newSVsv(PL_linestr);
3364 else if ( PL_hints & HINT_NEW_RE )
3365 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3366 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3370 s = scan_const(PL_bufptr);
3372 PL_lex_state = LEX_INTERPCASEMOD;
3374 PL_lex_state = LEX_INTERPSTART;
3377 if (s != PL_bufptr) {
3378 start_force(PL_curforce);
3380 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3382 NEXTVAL_NEXTTOKE = yylval;
3385 if (PL_lex_starts++) {
3389 sv_free(PL_thistoken);
3390 PL_thistoken = newSVpvs("");
3393 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3394 if (!PL_lex_casemods && PL_lex_inpat)
3407 PL_lex_state = LEX_NORMAL;
3408 s = scan_formline(PL_bufptr);
3409 if (!PL_lex_formbrack)
3415 PL_oldoldbufptr = PL_oldbufptr;
3421 sv_free(PL_thistoken);
3424 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3428 if (isIDFIRST_lazy_if(s,UTF))
3430 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3433 goto fake_eof; /* emulate EOF on ^D or ^Z */
3442 if (PL_lex_brackets) {
3443 yyerror((const char *)
3445 ? "Format not terminated"
3446 : "Missing right curly or square bracket"));
3448 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3449 "### Tokener got EOF\n");
3453 if (s++ < PL_bufend)
3454 goto retry; /* ignore stray nulls */
3457 if (!PL_in_eval && !PL_preambled) {
3458 PL_preambled = TRUE;
3463 sv_setpv(PL_linestr,incl_perldb());
3464 if (SvCUR(PL_linestr))
3465 sv_catpvs(PL_linestr,";");
3467 while(AvFILLp(PL_preambleav) >= 0) {
3468 SV *tmpsv = av_shift(PL_preambleav);
3469 sv_catsv(PL_linestr, tmpsv);
3470 sv_catpvs(PL_linestr, ";");
3473 sv_free((SV*)PL_preambleav);
3474 PL_preambleav = NULL;
3476 if (PL_minus_n || PL_minus_p) {
3477 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3479 sv_catpvs(PL_linestr,"chomp;");
3482 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3483 || *PL_splitstr == '"')
3484 && strchr(PL_splitstr + 1, *PL_splitstr))
3485 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3487 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3488 bytes can be used as quoting characters. :-) */
3489 const char *splits = PL_splitstr;
3490 sv_catpvs(PL_linestr, "our @F=split(q\0");
3493 if (*splits == '\\')
3494 sv_catpvn(PL_linestr, splits, 1);
3495 sv_catpvn(PL_linestr, splits, 1);
3496 } while (*splits++);
3497 /* This loop will embed the trailing NUL of
3498 PL_linestr as the last thing it does before
3500 sv_catpvs(PL_linestr, ");");
3504 sv_catpvs(PL_linestr,"our @F=split(' ');");
3508 sv_catpvs(PL_linestr,"use feature ':5.10';");
3509 sv_catpvs(PL_linestr, "\n");
3510 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3511 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3512 PL_last_lop = PL_last_uni = NULL;
3513 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3514 SV * const sv = newSV(0);
3516 sv_upgrade(sv, SVt_PVMG);
3517 sv_setsv(sv,PL_linestr);
3520 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3525 bof = PL_rsfp ? TRUE : FALSE;
3526 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3529 PL_realtokenstart = -1;
3532 if (PL_preprocess && !PL_in_eval)
3533 (void)PerlProc_pclose(PL_rsfp);
3534 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3535 PerlIO_clearerr(PL_rsfp);
3537 (void)PerlIO_close(PL_rsfp);
3539 PL_doextract = FALSE;
3541 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3546 sv_setpv(PL_linestr,
3549 ? ";}continue{print;}" : ";}"));
3550 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3551 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3552 PL_last_lop = PL_last_uni = NULL;
3553 PL_minus_n = PL_minus_p = 0;
3556 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3557 PL_last_lop = PL_last_uni = NULL;
3558 sv_setpvn(PL_linestr,"",0);
3559 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3561 /* If it looks like the start of a BOM or raw UTF-16,
3562 * check if it in fact is. */
3568 #ifdef PERLIO_IS_STDIO
3569 # ifdef __GNU_LIBRARY__
3570 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3571 # define FTELL_FOR_PIPE_IS_BROKEN
3575 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3576 # define FTELL_FOR_PIPE_IS_BROKEN
3581 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3582 /* This loses the possibility to detect the bof
3583 * situation on perl -P when the libc5 is being used.
3584 * Workaround? Maybe attach some extra state to PL_rsfp?
3587 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3589 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3592 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3593 s = swallow_bom((U8*)s);
3597 /* Incest with pod. */
3600 sv_catsv(PL_thiswhite, PL_linestr);
3602 if (*s == '=' && strnEQ(s, "=cut", 4)) {
3603 sv_setpvn(PL_linestr, "", 0);
3604 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3605 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3606 PL_last_lop = PL_last_uni = NULL;
3607 PL_doextract = FALSE;
3611 } while (PL_doextract);
3612 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3613 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3614 SV * const sv = newSV(0);
3616 sv_upgrade(sv, SVt_PVMG);
3617 sv_setsv(sv,PL_linestr);
3620 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3622 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3623 PL_last_lop = PL_last_uni = NULL;
3624 if (CopLINE(PL_curcop) == 1) {
3625 while (s < PL_bufend && isSPACE(*s))
3627 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3631 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3635 if (*s == '#' && *(s+1) == '!')
3637 #ifdef ALTERNATE_SHEBANG
3639 static char const as[] = ALTERNATE_SHEBANG;
3640 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3641 d = s + (sizeof(as) - 1);
3643 #endif /* ALTERNATE_SHEBANG */
3652 while (*d && !isSPACE(*d))
3656 #ifdef ARG_ZERO_IS_SCRIPT
3657 if (ipathend > ipath) {
3659 * HP-UX (at least) sets argv[0] to the script name,
3660 * which makes $^X incorrect. And Digital UNIX and Linux,
3661 * at least, set argv[0] to the basename of the Perl
3662 * interpreter. So, having found "#!", we'll set it right.
3664 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3666 assert(SvPOK(x) || SvGMAGICAL(x));
3667 if (sv_eq(x, CopFILESV(PL_curcop))) {
3668 sv_setpvn(x, ipath, ipathend - ipath);
3674 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3675 const char * const lstart = SvPV_const(x,llen);
3677 bstart += blen - llen;
3678 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3679 sv_setpvn(x, ipath, ipathend - ipath);
3684 TAINT_NOT; /* $^X is always tainted, but that's OK */
3686 #endif /* ARG_ZERO_IS_SCRIPT */
3691 d = instr(s,"perl -");
3693 d = instr(s,"perl");
3695 /* avoid getting into infinite loops when shebang
3696 * line contains "Perl" rather than "perl" */
3698 for (d = ipathend-4; d >= ipath; --d) {
3699 if ((*d == 'p' || *d == 'P')
3700 && !ibcmp(d, "perl", 4))
3710 #ifdef ALTERNATE_SHEBANG
3712 * If the ALTERNATE_SHEBANG on this system starts with a
3713 * character that can be part of a Perl expression, then if
3714 * we see it but not "perl", we're probably looking at the
3715 * start of Perl code, not a request to hand off to some
3716 * other interpreter. Similarly, if "perl" is there, but
3717 * not in the first 'word' of the line, we assume the line
3718 * contains the start of the Perl program.
3720 if (d && *s != '#') {
3721 const char *c = ipath;
3722 while (*c && !strchr("; \t\r\n\f\v#", *c))
3725 d = NULL; /* "perl" not in first word; ignore */
3727 *s = '#'; /* Don't try to parse shebang line */
3729 #endif /* ALTERNATE_SHEBANG */
3730 #ifndef MACOS_TRADITIONAL
3735 !instr(s,"indir") &&
3736 instr(PL_origargv[0],"perl"))
3743 while (s < PL_bufend && isSPACE(*s))
3745 if (s < PL_bufend) {
3746 Newxz(newargv,PL_origargc+3,char*);
3748 while (s < PL_bufend && !isSPACE(*s))
3751 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3754 newargv = PL_origargv;
3757 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3759 Perl_croak(aTHX_ "Can't exec %s", ipath);
3763 while (*d && !isSPACE(*d))
3765 while (SPACE_OR_TAB(*d))
3769 const bool switches_done = PL_doswitches;
3770 const U32 oldpdb = PL_perldb;
3771 const bool oldn = PL_minus_n;
3772 const bool oldp = PL_minus_p;
3775 if (*d == 'M' || *d == 'm' || *d == 'C') {
3776 const char * const m = d;
3777 while (*d && !isSPACE(*d))
3779 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3782 d = moreswitches(d);
3784 if (PL_doswitches && !switches_done) {
3785 int argc = PL_origargc;
3786 char **argv = PL_origargv;
3789 } while (argc && argv[0][0] == '-' && argv[0][1]);
3790 init_argv_symbols(argc,argv);
3792 if ((PERLDB_LINE && !oldpdb) ||
3793 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3794 /* if we have already added "LINE: while (<>) {",
3795 we must not do it again */
3797 sv_setpvn(PL_linestr, "", 0);
3798 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3799 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3800 PL_last_lop = PL_last_uni = NULL;
3801 PL_preambled = FALSE;
3803 (void)gv_fetchfile(PL_origfilename);
3810 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3812 PL_lex_state = LEX_FORMLINE;
3817 #ifdef PERL_STRICT_CR
3818 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3820 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3822 case ' ': case '\t': case '\f': case 013:
3823 #ifdef MACOS_TRADITIONAL
3827 PL_realtokenstart = -1;
3836 PL_realtokenstart = -1;
3840 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3841 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3842 /* handle eval qq[#line 1 "foo"\n ...] */
3843 CopLINE_dec(PL_curcop);
3846 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3848 if (!PL_in_eval || PL_rsfp)
3853 while (d < PL_bufend && *d != '\n')
3857 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3858 Perl_croak(aTHX_ "panic: input overflow");
3861 PL_thiswhite = newSVpvn(s, d - s);
3866 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3868 PL_lex_state = LEX_FORMLINE;
3874 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3875 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3878 TOKEN(PEG); /* make sure any #! line is accessible */
3883 /* if (PL_madskills && PL_lex_formbrack) { */
3885 while (d < PL_bufend && *d != '\n')
3889 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3890 Perl_croak(aTHX_ "panic: input overflow");
3891 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3893 PL_thiswhite = newSVpvs("");
3894 if (CopLINE(PL_curcop) == 1) {
3895 sv_setpvn(PL_thiswhite, "", 0);
3898 sv_catpvn(PL_thiswhite, s, d - s);
3912 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3920 while (s < PL_bufend && SPACE_OR_TAB(*s))
3923 if (strnEQ(s,"=>",2)) {
3924 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3925 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
3926 OPERATOR('-'); /* unary minus */
3928 PL_last_uni = PL_oldbufptr;
3930 case 'r': ftst = OP_FTEREAD; break;
3931 case 'w': ftst = OP_FTEWRITE; break;
3932 case 'x': ftst = OP_FTEEXEC; break;
3933 case 'o': ftst = OP_FTEOWNED; break;
3934 case 'R': ftst = OP_FTRREAD; break;
3935 case 'W': ftst = OP_FTRWRITE; break;
3936 case 'X': ftst = OP_FTREXEC; break;
3937 case 'O': ftst = OP_FTROWNED; break;
3938 case 'e': ftst = OP_FTIS; break;
3939 case 'z': ftst = OP_FTZERO; break;
3940 case 's': ftst = OP_FTSIZE; break;
3941 case 'f': ftst = OP_FTFILE; break;
3942 case 'd': ftst = OP_FTDIR; break;
3943 case 'l': ftst = OP_FTLINK; break;
3944 case 'p': ftst = OP_FTPIPE; break;
3945 case 'S': ftst = OP_FTSOCK; break;
3946 case 'u': ftst = OP_FTSUID; break;
3947 case 'g': ftst = OP_FTSGID; break;
3948 case 'k': ftst = OP_FTSVTX; break;
3949 case 'b': ftst = OP_FTBLK; break;
3950 case 'c': ftst = OP_FTCHR; break;
3951 case 't': ftst = OP_FTTTY; break;
3952 case 'T': ftst = OP_FTTEXT; break;
3953 case 'B': ftst = OP_FTBINARY; break;
3954 case 'M': case 'A': case 'C':
3955 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
3957 case 'M': ftst = OP_FTMTIME; break;
3958 case 'A': ftst = OP_FTATIME; break;
3959 case 'C': ftst = OP_FTCTIME; break;
3967 PL_last_lop_op = (OPCODE)ftst;
3968 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3969 "### Saw file test %c\n", (int)tmp);
3974 /* Assume it was a minus followed by a one-letter named
3975 * subroutine call (or a -bareword), then. */
3976 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3977 "### '-%c' looked like a file test but was not\n",
3984 const char tmp = *s++;
3987 if (PL_expect == XOPERATOR)
3992 else if (*s == '>') {
3995 if (isIDFIRST_lazy_if(s,UTF)) {
3996 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4004 if (PL_expect == XOPERATOR)
4007 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4009 OPERATOR('-'); /* unary minus */
4015 const char tmp = *s++;
4018 if (PL_expect == XOPERATOR)
4023 if (PL_expect == XOPERATOR)
4026 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4033 if (PL_expect != XOPERATOR) {
4034 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4035 PL_expect = XOPERATOR;
4036 force_ident(PL_tokenbuf, '*');
4049 if (PL_expect == XOPERATOR) {
4053 PL_tokenbuf[0] = '%';
4054 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
4055 if (!PL_tokenbuf[1]) {
4058 PL_pending_ident = '%';
4069 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
4070 && FEATURE_IS_ENABLED("~~"))
4077 const char tmp = *s++;
4083 goto just_a_word_zero_gv;
4086 switch (PL_expect) {
4092 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4094 PL_bufptr = s; /* update in case we back off */
4100 PL_expect = XTERMBLOCK;
4103 stuffstart = s - SvPVX(PL_linestr) - 1;
4107 while (isIDFIRST_lazy_if(s,UTF)) {
4110 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4111 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4112 if (tmp < 0) tmp = -tmp;
4127 sv = newSVpvn(s, len);
4129 d = scan_str(d,TRUE,TRUE);
4131 /* MUST advance bufptr here to avoid bogus
4132 "at end of line" context messages from yyerror().
4134 PL_bufptr = s + len;
4135 yyerror("Unterminated attribute parameter in attribute list");
4139 return REPORT(0); /* EOF indicator */
4143 sv_catsv(sv, PL_lex_stuff);
4144 attrs = append_elem(OP_LIST, attrs,
4145 newSVOP(OP_CONST, 0, sv));
4146 SvREFCNT_dec(PL_lex_stuff);
4147 PL_lex_stuff = NULL;
4150 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4152 if (PL_in_my == KEY_our) {
4154 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4156 /* skip to avoid loading attributes.pm */
4158 deprecate(":unique");
4161 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4164 /* NOTE: any CV attrs applied here need to be part of
4165 the CVf_BUILTIN_ATTRS define in cv.h! */
4166 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4168 CvLVALUE_on(PL_compcv);
4170 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4172 CvLOCKED_on(PL_compcv);
4174 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4176 CvMETHOD_on(PL_compcv);
4178 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4180 CvASSERTION_on(PL_compcv);
4182 /* After we've set the flags, it could be argued that
4183 we don't need to do the attributes.pm-based setting
4184 process, and shouldn't bother appending recognized
4185 flags. To experiment with that, uncomment the
4186 following "else". (Note that's already been
4187 uncommented. That keeps the above-applied built-in
4188 attributes from being intercepted (and possibly
4189 rejected) by a package's attribute routines, but is
4190 justified by the performance win for the common case
4191 of applying only built-in attributes.) */
4193 attrs = append_elem(OP_LIST, attrs,
4194 newSVOP(OP_CONST, 0,
4198 if (*s == ':' && s[1] != ':')
4201 break; /* require real whitespace or :'s */
4202 /* XXX losing whitespace on sequential attributes here */
4206 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4207 if (*s != ';' && *s != '}' && *s != tmp
4208 && (tmp != '=' || *s != ')')) {
4209 const char q = ((*s == '\'') ? '"' : '\'');
4210 /* If here for an expression, and parsed no attrs, back
4212 if (tmp == '=' && !attrs) {
4216 /* MUST advance bufptr here to avoid bogus "at end of line"
4217 context messages from yyerror().
4220 yyerror( (const char *)
4222 ? Perl_form(aTHX_ "Invalid separator character "
4223 "%c%c%c in attribute list", q, *s, q)
4224 : "Unterminated attribute list" ) );
4232 start_force(PL_curforce);
4233 NEXTVAL_NEXTTOKE.opval = attrs;
4234 CURMAD('_', PL_nextwhite);
4239 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4240 (s - SvPVX(PL_linestr)) - stuffstart);
4248 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4249 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4257 const char tmp = *s++;
4262 const char tmp = *s++;
4270 if (PL_lex_brackets <= 0)
4271 yyerror("Unmatched right square bracket");
4274 if (PL_lex_state == LEX_INTERPNORMAL) {
4275 if (PL_lex_brackets == 0) {
4276 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4277 PL_lex_state = LEX_INTERPEND;
4284 if (PL_lex_brackets > 100) {
4285 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4287 switch (PL_expect) {
4289 if (PL_lex_formbrack) {
4293 if (PL_oldoldbufptr == PL_last_lop)
4294 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4296 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4297 OPERATOR(HASHBRACK);
4299 while (s < PL_bufend && SPACE_OR_TAB(*s))
4302 PL_tokenbuf[0] = '\0';
4303 if (d < PL_bufend && *d == '-') {
4304 PL_tokenbuf[0] = '-';
4306 while (d < PL_bufend && SPACE_OR_TAB(*d))
4309 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4310 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4312 while (d < PL_bufend && SPACE_OR_TAB(*d))
4315 const char minus = (PL_tokenbuf[0] == '-');
4316 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4324 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4329 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4334 if (PL_oldoldbufptr == PL_last_lop)
4335 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4337 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4340 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4342 /* This hack is to get the ${} in the message. */
4344 yyerror("syntax error");
4347 OPERATOR(HASHBRACK);
4349 /* This hack serves to disambiguate a pair of curlies
4350 * as being a block or an anon hash. Normally, expectation
4351 * determines that, but in cases where we're not in a
4352 * position to expect anything in particular (like inside
4353 * eval"") we have to resolve the ambiguity. This code
4354 * covers the case where the first term in the curlies is a
4355 * quoted string. Most other cases need to be explicitly
4356 * disambiguated by prepending a "+" before the opening
4357 * curly in order to force resolution as an anon hash.
4359 * XXX should probably propagate the outer expectation
4360 * into eval"" to rely less on this hack, but that could
4361 * potentially break current behavior of eval"".
4365 if (*s == '\'' || *s == '"' || *s == '`') {
4366 /* common case: get past first string, handling escapes */
4367 for (t++; t < PL_bufend && *t != *s;)
4368 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4372 else if (*s == 'q') {
4375 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4378 /* skip q//-like construct */
4380 char open, close, term;
4383 while (t < PL_bufend && isSPACE(*t))
4385 /* check for q => */
4386 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4387 OPERATOR(HASHBRACK);
4391 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4395 for (t++; t < PL_bufend; t++) {
4396 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4398 else if (*t == open)
4402 for (t++; t < PL_bufend; t++) {
4403 if (*t == '\\' && t+1 < PL_bufend)
4405 else if (*t == close && --brackets <= 0)
4407 else if (*t == open)
4414 /* skip plain q word */
4415 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4418 else if (isALNUM_lazy_if(t,UTF)) {
4420 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4423 while (t < PL_bufend && isSPACE(*t))
4425 /* if comma follows first term, call it an anon hash */
4426 /* XXX it could be a comma expression with loop modifiers */
4427 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4428 || (*t == '=' && t[1] == '>')))
4429 OPERATOR(HASHBRACK);
4430 if (PL_expect == XREF)
4433 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4439 yylval.ival = CopLINE(PL_curcop);
4440 if (isSPACE(*s) || *s == '#')
4441 PL_copline = NOLINE; /* invalidate current command line number */
4446 if (PL_lex_brackets <= 0)
4447 yyerror("Unmatched right curly bracket");
4449 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4450 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4451 PL_lex_formbrack = 0;
4452 if (PL_lex_state == LEX_INTERPNORMAL) {
4453 if (PL_lex_brackets == 0) {
4454 if (PL_expect & XFAKEBRACK) {
4455 PL_expect &= XENUMMASK;
4456 PL_lex_state = LEX_INTERPEND;
4461 PL_thiswhite = newSVpvs("");
4462 sv_catpvn(PL_thiswhite,"}",1);
4465 return yylex(); /* ignore fake brackets */
4467 if (*s == '-' && s[1] == '>')
4468 PL_lex_state = LEX_INTERPENDMAYBE;
4469 else if (*s != '[' && *s != '{')
4470 PL_lex_state = LEX_INTERPEND;
4473 if (PL_expect & XFAKEBRACK) {
4474 PL_expect &= XENUMMASK;
4476 return yylex(); /* ignore fake brackets */
4478 start_force(PL_curforce);
4480 curmad('X', newSVpvn(s-1,1));
4481 CURMAD('_', PL_thiswhite);
4486 PL_thistoken = newSVpvs("");
4494 if (PL_expect == XOPERATOR) {
4495 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4496 && isIDFIRST_lazy_if(s,UTF))
4498 CopLINE_dec(PL_curcop);
4499 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4500 CopLINE_inc(PL_curcop);
4505 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4507 PL_expect = XOPERATOR;
4508 force_ident(PL_tokenbuf, '&');
4512 yylval.ival = (OPpENTERSUB_AMPER<<8);
4524 const char tmp = *s++;
4531 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4532 && strchr("+-*/%.^&|<",tmp))
4533 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4534 "Reversed %c= operator",(int)tmp);
4536 if (PL_expect == XSTATE && isALPHA(tmp) &&
4537 (s == PL_linestart+1 || s[-2] == '\n') )
4539 if (PL_in_eval && !PL_rsfp) {
4544 if (strnEQ(s,"=cut",4)) {
4560 PL_thiswhite = newSVpvs("");
4561 sv_catpvn(PL_thiswhite, PL_linestart,
4562 PL_bufend - PL_linestart);
4566 PL_doextract = TRUE;
4570 if (PL_lex_brackets < PL_lex_formbrack) {
4572 #ifdef PERL_STRICT_CR
4573 while (SPACE_OR_TAB(*t))
4575 while (SPACE_OR_TAB(*t) || *t == '\r')
4578 if (*t == '\n' || *t == '#') {
4589 const char tmp = *s++;
4591 /* was this !=~ where !~ was meant?
4592 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4594 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4595 const char *t = s+1;
4597 while (t < PL_bufend && isSPACE(*t))
4600 if (*t == '/' || *t == '?' ||
4601 ((*t == 'm' || *t == 's' || *t == 'y')
4602 && !isALNUM(t[1])) ||
4603 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4604 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4605 "!=~ should be !~");
4615 if (PL_expect != XOPERATOR) {
4616 if (s[1] != '<' && !strchr(s,'>'))
4619 s = scan_heredoc(s);
4621 s = scan_inputsymbol(s);
4622 TERM(sublex_start());
4628 SHop(OP_LEFT_SHIFT);
4642 const char tmp = *s++;
4644 SHop(OP_RIGHT_SHIFT);
4645 else if (tmp == '=')
4654 if (PL_expect == XOPERATOR) {
4655 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4657 deprecate_old(commaless_variable_list);
4658 return REPORT(','); /* grandfather non-comma-format format */
4662 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4663 PL_tokenbuf[0] = '@';
4664 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4665 sizeof PL_tokenbuf - 1, FALSE);
4666 if (PL_expect == XOPERATOR)
4667 no_op("Array length", s);
4668 if (!PL_tokenbuf[1])
4670 PL_expect = XOPERATOR;
4671 PL_pending_ident = '#';
4675 PL_tokenbuf[0] = '$';
4676 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4677 sizeof PL_tokenbuf - 1, FALSE);
4678 if (PL_expect == XOPERATOR)
4680 if (!PL_tokenbuf[1]) {
4682 yyerror("Final $ should be \\$ or $name");
4686 /* This kludge not intended to be bulletproof. */
4687 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4688 yylval.opval = newSVOP(OP_CONST, 0,
4689 newSViv(CopARYBASE_get(&PL_compiling)));
4690 yylval.opval->op_private = OPpCONST_ARYBASE;
4696 const char tmp = *s;
4697 if (PL_lex_state == LEX_NORMAL)
4700 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4701 && intuit_more(s)) {
4703 PL_tokenbuf[0] = '@';
4704 if (ckWARN(WARN_SYNTAX)) {
4707 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4710 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4711 while (t < PL_bufend && *t != ']')
4713 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4714 "Multidimensional syntax %.*s not supported",
4715 (int)((t - PL_bufptr) + 1), PL_bufptr);
4719 else if (*s == '{') {
4721 PL_tokenbuf[0] = '%';
4722 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4723 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4725 char tmpbuf[sizeof PL_tokenbuf];
4728 } while (isSPACE(*t));
4729 if (isIDFIRST_lazy_if(t,UTF)) {
4731 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4735 if (*t == ';' && get_cv(tmpbuf, FALSE))
4736 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4737 "You need to quote \"%s\"",
4744 PL_expect = XOPERATOR;
4745 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4746 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4747 if (!islop || PL_last_lop_op == OP_GREPSTART)
4748 PL_expect = XOPERATOR;
4749 else if (strchr("$@\"'`q", *s))
4750 PL_expect = XTERM; /* e.g. print $fh "foo" */
4751 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4752 PL_expect = XTERM; /* e.g. print $fh &sub */
4753 else if (isIDFIRST_lazy_if(s,UTF)) {
4754 char tmpbuf[sizeof PL_tokenbuf];
4756 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4757 if ((t2 = keyword(tmpbuf, len, 0))) {
4758 /* binary operators exclude handle interpretations */
4770 PL_expect = XTERM; /* e.g. print $fh length() */
4775 PL_expect = XTERM; /* e.g. print $fh subr() */
4778 else if (isDIGIT(*s))
4779 PL_expect = XTERM; /* e.g. print $fh 3 */
4780 else if (*s == '.' && isDIGIT(s[1]))
4781 PL_expect = XTERM; /* e.g. print $fh .3 */
4782 else if ((*s == '?' || *s == '-' || *s == '+')
4783 && !isSPACE(s[1]) && s[1] != '=')
4784 PL_expect = XTERM; /* e.g. print $fh -1 */
4785 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4787 PL_expect = XTERM; /* e.g. print $fh /.../
4788 XXX except DORDOR operator
4790 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4792 PL_expect = XTERM; /* print $fh <<"EOF" */
4795 PL_pending_ident = '$';
4799 if (PL_expect == XOPERATOR)
4801 PL_tokenbuf[0] = '@';
4802 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4803 if (!PL_tokenbuf[1]) {
4806 if (PL_lex_state == LEX_NORMAL)
4808 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4810 PL_tokenbuf[0] = '%';
4812 /* Warn about @ where they meant $. */
4813 if (*s == '[' || *s == '{') {
4814 if (ckWARN(WARN_SYNTAX)) {
4815 const char *t = s + 1;
4816 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4818 if (*t == '}' || *t == ']') {
4820 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4821 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4822 "Scalar value %.*s better written as $%.*s",
4823 (int)(t-PL_bufptr), PL_bufptr,
4824 (int)(t-PL_bufptr-1), PL_bufptr+1);
4829 PL_pending_ident = '@';
4832 case '/': /* may be division, defined-or, or pattern */
4833 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4837 case '?': /* may either be conditional or pattern */
4838 if(PL_expect == XOPERATOR) {
4846 /* A // operator. */
4856 /* Disable warning on "study /blah/" */
4857 if (PL_oldoldbufptr == PL_last_uni
4858 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4859 || memNE(PL_last_uni, "study", 5)
4860 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4863 s = scan_pat(s,OP_MATCH);
4864 TERM(sublex_start());
4868 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4869 #ifdef PERL_STRICT_CR
4872 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4874 && (s == PL_linestart || s[-1] == '\n') )
4876 PL_lex_formbrack = 0;
4880 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4886 yylval.ival = OPf_SPECIAL;
4892 if (PL_expect != XOPERATOR)
4897 case '0': case '1': case '2': case '3': case '4':
4898 case '5': case '6': case '7': case '8': case '9':
4899 s = scan_num(s, &yylval);
4900 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
4901 if (PL_expect == XOPERATOR)
4906 s = scan_str(s,!!PL_madskills,FALSE);
4907 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4908 if (PL_expect == XOPERATOR) {
4909 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4911 deprecate_old(commaless_variable_list);
4912 return REPORT(','); /* grandfather non-comma-format format */
4919 yylval.ival = OP_CONST;
4920 TERM(sublex_start());
4923 s = scan_str(s,!!PL_madskills,FALSE);
4924 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4925 if (PL_expect == XOPERATOR) {
4926 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4928 deprecate_old(commaless_variable_list);
4929 return REPORT(','); /* grandfather non-comma-format format */
4936 yylval.ival = OP_CONST;
4937 /* FIXME. I think that this can be const if char *d is replaced by
4938 more localised variables. */
4939 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4940 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4941 yylval.ival = OP_STRINGIFY;
4945 TERM(sublex_start());
4948 s = scan_str(s,!!PL_madskills,FALSE);
4949 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
4950 if (PL_expect == XOPERATOR)
4951 no_op("Backticks",s);
4954 yylval.ival = OP_BACKTICK;
4956 TERM(sublex_start());
4960 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
4961 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
4963 if (PL_expect == XOPERATOR)
4964 no_op("Backslash",s);
4968 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
4969 char *start = s + 2;
4970 while (isDIGIT(*start) || *start == '_')
4972 if (*start == '.' && isDIGIT(start[1])) {
4973 s = scan_num(s, &yylval);
4976 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
4977 else if (!isALPHA(*start) && (PL_expect == XTERM
4978 || PL_expect == XREF || PL_expect == XSTATE
4979 || PL_expect == XTERMORDORDOR)) {
4980 /* XXX Use gv_fetchpvn rather than stomping on a const string */
4981 const char c = *start;
4984 gv = gv_fetchpv(s, 0, SVt_PVCV);
4987 s = scan_num(s, &yylval);
4994 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5036 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5038 /* Some keywords can be followed by any delimiter, including ':' */
5039 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5040 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5041 (PL_tokenbuf[0] == 'q' &&
5042 strchr("qwxr", PL_tokenbuf[1])))));
5044 /* x::* is just a word, unless x is "CORE" */
5045 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5049 while (d < PL_bufend && isSPACE(*d))
5050 d++; /* no comments skipped here, or s### is misparsed */
5052 /* Is this a label? */
5053 if (!tmp && PL_expect == XSTATE
5054 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5056 yylval.pval = savepv(PL_tokenbuf);
5061 /* Check for keywords */
5062 tmp = keyword(PL_tokenbuf, len, 0);
5064 /* Is this a word before a => operator? */
5065 if (*d == '=' && d[1] == '>') {
5068 = (OP*)newSVOP(OP_CONST, 0,
5069 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5070 yylval.opval->op_private = OPpCONST_BARE;
5074 if (tmp < 0) { /* second-class keyword? */
5075 GV *ogv = NULL; /* override (winner) */
5076 GV *hgv = NULL; /* hidden (loser) */
5077 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5079 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5082 if (GvIMPORTED_CV(gv))
5084 else if (! CvMETHOD(cv))
5088 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5089 (gv = *gvp) != (GV*)&PL_sv_undef &&
5090 GvCVu(gv) && GvIMPORTED_CV(gv))
5097 tmp = 0; /* overridden by import or by GLOBAL */
5100 && -tmp==KEY_lock /* XXX generalizable kludge */
5102 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
5104 tmp = 0; /* any sub overrides "weak" keyword */
5106 else { /* no override */
5108 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5109 Perl_warner(aTHX_ packWARN(WARN_MISC),
5110 "dump() better written as CORE::dump()");
5114 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5115 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5116 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5117 "Ambiguous call resolved as CORE::%s(), %s",
5118 GvENAME(hgv), "qualify as such or use &");
5125 default: /* not a keyword */
5126 /* Trade off - by using this evil construction we can pull the
5127 variable gv into the block labelled keylookup. If not, then
5128 we have to give it function scope so that the goto from the
5129 earlier ':' case doesn't bypass the initialisation. */
5131 just_a_word_zero_gv:
5139 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5142 SV *nextPL_nextwhite = 0;
5146 /* Get the rest if it looks like a package qualifier */
5148 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5150 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5153 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5154 *s == '\'' ? "'" : "::");
5159 if (PL_expect == XOPERATOR) {
5160 if (PL_bufptr == PL_linestart) {
5161 CopLINE_dec(PL_curcop);
5162 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5163 CopLINE_inc(PL_curcop);
5166 no_op("Bareword",s);
5169 /* Look for a subroutine with this name in current package,
5170 unless name is "Foo::", in which case Foo is a bearword
5171 (and a package name). */
5173 if (len > 2 && !PL_madskills &&
5174 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5176 if (ckWARN(WARN_BAREWORD)
5177 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5178 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5179 "Bareword \"%s\" refers to nonexistent package",
5182 PL_tokenbuf[len] = '\0';
5188 /* Mustn't actually add anything to a symbol table.
5189 But also don't want to "initialise" any placeholder
5190 constants that might already be there into full
5191 blown PVGVs with attached PVCV. */
5192 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5193 GV_NOADD_NOINIT, SVt_PVCV);
5198 /* if we saw a global override before, get the right name */
5201 sv = newSVpvs("CORE::GLOBAL::");
5202 sv_catpv(sv,PL_tokenbuf);
5205 /* If len is 0, newSVpv does strlen(), which is correct.
5206 If len is non-zero, then it will be the true length,
5207 and so the scalar will be created correctly. */
5208 sv = newSVpv(PL_tokenbuf,len);
5211 if (PL_madskills && !PL_thistoken) {
5212 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5213 PL_thistoken = newSVpv(start,s - start);
5214 PL_realtokenstart = s - SvPVX(PL_linestr);
5218 /* Presume this is going to be a bareword of some sort. */
5221 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5222 yylval.opval->op_private = OPpCONST_BARE;
5223 /* UTF-8 package name? */
5224 if (UTF && !IN_BYTES &&
5225 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5228 /* And if "Foo::", then that's what it certainly is. */
5233 /* Do the explicit type check so that we don't need to force
5234 the initialisation of the symbol table to have a real GV.
5235 Beware - gv may not really be a PVGV, cv may not really be
5236 a PVCV, (because of the space optimisations that gv_init
5237 understands) But they're true if for this symbol there is
5238 respectively a typeglob and a subroutine.
5240 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5241 /* Real typeglob, so get the real subroutine: */
5243 /* A proxy for a subroutine in this package? */
5244 : SvOK(gv) ? (CV *) gv : NULL)
5247 /* See if it's the indirect object for a list operator. */
5249 if (PL_oldoldbufptr &&
5250 PL_oldoldbufptr < PL_bufptr &&
5251 (PL_oldoldbufptr == PL_last_lop
5252 || PL_oldoldbufptr == PL_last_uni) &&
5253 /* NO SKIPSPACE BEFORE HERE! */
5254 (PL_expect == XREF ||
5255 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5257 bool immediate_paren = *s == '(';
5259 /* (Now we can afford to cross potential line boundary.) */
5260 s = SKIPSPACE2(s,nextPL_nextwhite);
5262 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5265 /* Two barewords in a row may indicate method call. */
5267 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5268 (tmp = intuit_method(s, gv, cv)))
5271 /* If not a declared subroutine, it's an indirect object. */
5272 /* (But it's an indir obj regardless for sort.) */
5273 /* Also, if "_" follows a filetest operator, it's a bareword */
5276 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5278 (PL_last_lop_op != OP_MAPSTART &&
5279 PL_last_lop_op != OP_GREPSTART))))
5280 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5281 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5284 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5289 PL_expect = XOPERATOR;
5292 s = SKIPSPACE2(s,nextPL_nextwhite);
5293 PL_nextwhite = nextPL_nextwhite;
5298 /* Is this a word before a => operator? */
5299 if (*s == '=' && s[1] == '>' && !pkgname) {
5301 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5302 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5303 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5307 /* If followed by a paren, it's certainly a subroutine. */
5312 while (SPACE_OR_TAB(*d))
5314 if (*d == ')' && (sv = gv_const_sv(gv))) {
5318 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5319 sv_catpvn(PL_thistoken, par, s - par);
5321 sv_free(PL_nextwhite);
5331 PL_nextwhite = PL_thiswhite;
5334 start_force(PL_curforce);
5336 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5337 PL_expect = XOPERATOR;
5340 PL_nextwhite = nextPL_nextwhite;
5341 curmad('X', PL_thistoken);
5342 PL_thistoken = newSVpvs("");
5350 /* If followed by var or block, call it a method (unless sub) */
5352 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5353 PL_last_lop = PL_oldbufptr;
5354 PL_last_lop_op = OP_METHOD;
5358 /* If followed by a bareword, see if it looks like indir obj. */
5361 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5362 && (tmp = intuit_method(s, gv, cv)))
5365 /* Not a method, so call it a subroutine (if defined) */
5368 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5369 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5370 "Ambiguous use of -%s resolved as -&%s()",
5371 PL_tokenbuf, PL_tokenbuf);
5372 /* Check for a constant sub */
5373 if ((sv = gv_const_sv(gv))) {
5375 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5376 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5377 yylval.opval->op_private = 0;
5381 /* Resolve to GV now. */
5382 if (SvTYPE(gv) != SVt_PVGV) {
5383 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5384 assert (SvTYPE(gv) == SVt_PVGV);
5385 /* cv must have been some sort of placeholder, so
5386 now needs replacing with a real code reference. */
5390 op_free(yylval.opval);
5391 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5392 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5393 PL_last_lop = PL_oldbufptr;
5394 PL_last_lop_op = OP_ENTERSUB;
5395 /* Is there a prototype? */
5402 const char *proto = SvPV_const((SV*)cv, protolen);
5405 if (*proto == '$' && proto[1] == '\0')
5407 while (*proto == ';')
5409 if (*proto == '&' && *s == '{') {
5410 sv_setpv(PL_subname,
5413 "__ANON__" : "__ANON__::__ANON__"));
5420 PL_nextwhite = PL_thiswhite;
5423 start_force(PL_curforce);
5424 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5427 PL_nextwhite = nextPL_nextwhite;
5428 curmad('X', PL_thistoken);
5429 PL_thistoken = newSVpvs("");
5436 /* Guess harder when madskills require "best effort". */
5437 if (PL_madskills && (!gv || !GvCVu(gv))) {
5438 int probable_sub = 0;
5439 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5441 else if (isALPHA(*s)) {
5445 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5446 if (!keyword(tmpbuf, tmplen, 0))
5449 while (d < PL_bufend && isSPACE(*d))
5451 if (*d == '=' && d[1] == '>')
5456 gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5457 op_free(yylval.opval);
5458 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5459 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5460 PL_last_lop = PL_oldbufptr;
5461 PL_last_lop_op = OP_ENTERSUB;
5462 PL_nextwhite = PL_thiswhite;
5464 start_force(PL_curforce);
5465 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5467 PL_nextwhite = nextPL_nextwhite;
5468 curmad('X', PL_thistoken);
5469 PL_thistoken = newSVpvs("");
5474 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5481 /* Call it a bare word */
5483 if (PL_hints & HINT_STRICT_SUBS)
5484 yylval.opval->op_private |= OPpCONST_STRICT;
5487 if (lastchar != '-') {
5488 if (ckWARN(WARN_RESERVED)) {
5492 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
5493 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5500 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5501 && ckWARN_d(WARN_AMBIGUOUS)) {
5502 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5503 "Operator or semicolon missing before %c%s",
5504 lastchar, PL_tokenbuf);
5505 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5506 "Ambiguous use of %c resolved as operator %c",
5507 lastchar, lastchar);
5513 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5514 newSVpv(CopFILE(PL_curcop),0));
5518 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5519 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5522 case KEY___PACKAGE__:
5523 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5525 ? newSVhek(HvNAME_HEK(PL_curstash))
5532 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5533 const char *pname = "main";
5534 if (PL_tokenbuf[2] == 'D')
5535 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5536 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5540 GvIOp(gv) = newIO();
5541 IoIFP(GvIOp(gv)) = PL_rsfp;
5542 #if defined(HAS_FCNTL) && defined(F_SETFD)
5544 const int fd = PerlIO_fileno(PL_rsfp);
5545 fcntl(fd,F_SETFD,fd >= 3);
5548 /* Mark this internal pseudo-handle as clean */
5549 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5551 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5552 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5553 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5555 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5556 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5557 /* if the script was opened in binmode, we need to revert
5558 * it to text mode for compatibility; but only iff it has CRs
5559 * XXX this is a questionable hack at best. */
5560 if (PL_bufend-PL_bufptr > 2
5561 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5564 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5565 loc = PerlIO_tell(PL_rsfp);
5566 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5569 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5571 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5572 #endif /* NETWARE */
5573 #ifdef PERLIO_IS_STDIO /* really? */
5574 # if defined(__BORLANDC__)
5575 /* XXX see note in do_binmode() */
5576 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5580 PerlIO_seek(PL_rsfp, loc, 0);
5584 #ifdef PERLIO_LAYERS
5587 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5588 else if (PL_encoding) {
5595 XPUSHs(PL_encoding);
5597 call_method("name", G_SCALAR);
5601 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5602 Perl_form(aTHX_ ":encoding(%"SVf")",
5611 if (PL_realtokenstart >= 0) {
5612 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5614 PL_endwhite = newSVpvs("");
5615 sv_catsv(PL_endwhite, PL_thiswhite);
5617 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5618 PL_realtokenstart = -1;
5620 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5621 SvCUR(PL_endwhite))) != Nullch) ;
5635 if (PL_expect == XSTATE) {
5642 if (*s == ':' && s[1] == ':') {
5645 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5646 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5647 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5650 else if (tmp == KEY_require || tmp == KEY_do)
5651 /* that's a way to remember we saw "CORE::" */
5664 LOP(OP_ACCEPT,XTERM);
5670 LOP(OP_ATAN2,XTERM);
5676 LOP(OP_BINMODE,XTERM);
5679 LOP(OP_BLESS,XTERM);
5688 /* When 'use switch' is in effect, continue has a dual
5689 life as a control operator. */
5691 if (!FEATURE_IS_ENABLED("switch"))
5694 /* We have to disambiguate the two senses of
5695 "continue". If the next token is a '{' then
5696 treat it as the start of a continue block;
5697 otherwise treat it as a control operator.
5709 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5726 if (!PL_cryptseen) {
5727 PL_cryptseen = TRUE;
5731 LOP(OP_CRYPT,XTERM);
5734 LOP(OP_CHMOD,XTERM);
5737 LOP(OP_CHOWN,XTERM);
5740 LOP(OP_CONNECT,XTERM);
5759 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5760 if (orig_keyword == KEY_do) {
5769 PL_hints |= HINT_BLOCK_SCOPE;
5779 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5780 LOP(OP_DBMOPEN,XTERM);
5786 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5793 yylval.ival = CopLINE(PL_curcop);
5809 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5810 UNIBRACK(OP_ENTEREVAL);
5828 case KEY_endhostent:
5834 case KEY_endservent:
5837 case KEY_endprotoent:
5848 yylval.ival = CopLINE(PL_curcop);
5850 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5853 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5856 if ((PL_bufend - p) >= 3 &&
5857 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5859 else if ((PL_bufend - p) >= 4 &&
5860 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5863 if (isIDFIRST_lazy_if(p,UTF)) {
5864 p = scan_ident(p, PL_bufend,
5865 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5869 Perl_croak(aTHX_ "Missing $ on loop variable");
5871 s = SvPVX(PL_linestr) + soff;
5877 LOP(OP_FORMLINE,XTERM);
5883 LOP(OP_FCNTL,XTERM);
5889 LOP(OP_FLOCK,XTERM);
5898 LOP(OP_GREPSTART, XREF);
5901 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5916 case KEY_getpriority:
5917 LOP(OP_GETPRIORITY,XTERM);
5919 case KEY_getprotobyname:
5922 case KEY_getprotobynumber:
5923 LOP(OP_GPBYNUMBER,XTERM);
5925 case KEY_getprotoent:
5937 case KEY_getpeername:
5938 UNI(OP_GETPEERNAME);
5940 case KEY_gethostbyname:
5943 case KEY_gethostbyaddr:
5944 LOP(OP_GHBYADDR,XTERM);
5946 case KEY_gethostent:
5949 case KEY_getnetbyname:
5952 case KEY_getnetbyaddr:
5953 LOP(OP_GNBYADDR,XTERM);
5958 case KEY_getservbyname:
5959 LOP(OP_GSBYNAME,XTERM);
5961 case KEY_getservbyport:
5962 LOP(OP_GSBYPORT,XTERM);
5964 case KEY_getservent:
5967 case KEY_getsockname:
5968 UNI(OP_GETSOCKNAME);
5970 case KEY_getsockopt:
5971 LOP(OP_GSOCKOPT,XTERM);
5986 yylval.ival = CopLINE(PL_curcop);
5997 yylval.ival = CopLINE(PL_curcop);
6001 LOP(OP_INDEX,XTERM);
6007 LOP(OP_IOCTL,XTERM);
6019 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6051 LOP(OP_LISTEN,XTERM);
6060 s = scan_pat(s,OP_MATCH);
6061 TERM(sublex_start());
6064 LOP(OP_MAPSTART, XREF);
6067 LOP(OP_MKDIR,XTERM);
6070 LOP(OP_MSGCTL,XTERM);
6073 LOP(OP_MSGGET,XTERM);
6076 LOP(OP_MSGRCV,XTERM);
6079 LOP(OP_MSGSND,XTERM);
6086 if (isIDFIRST_lazy_if(s,UTF)) {
6090 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6091 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6093 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6094 if (!PL_in_my_stash) {
6097 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6101 if (PL_madskills) { /* just add type to declarator token */
6102 sv_catsv(PL_thistoken, PL_nextwhite);
6104 sv_catpvn(PL_thistoken, start, s - start);
6112 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6119 s = tokenize_use(0, s);
6123 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6130 if (isIDFIRST_lazy_if(s,UTF)) {
6132 for (d = s; isALNUM_lazy_if(d,UTF);)
6134 for (t=d; isSPACE(*t);)
6136 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6138 && !(t[0] == '=' && t[1] == '>')
6140 int parms_len = (int)(d-s);
6141 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6142 "Precedence problem: open %.*s should be open(%.*s)",
6143 parms_len, s, parms_len, s);
6149 yylval.ival = OP_OR;
6159 LOP(OP_OPEN_DIR,XTERM);
6162 checkcomma(s,PL_tokenbuf,"filehandle");
6166 checkcomma(s,PL_tokenbuf,"filehandle");
6185 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6189 LOP(OP_PIPE_OP,XTERM);
6192 s = scan_str(s,!!PL_madskills,FALSE);
6195 yylval.ival = OP_CONST;
6196 TERM(sublex_start());
6202 s = scan_str(s,!!PL_madskills,FALSE);
6205 PL_expect = XOPERATOR;
6207 if (SvCUR(PL_lex_stuff)) {
6210 d = SvPV_force(PL_lex_stuff, len);
6212 for (; isSPACE(*d) && len; --len, ++d)
6217 if (!warned && ckWARN(WARN_QW)) {
6218 for (; !isSPACE(*d) && len; --len, ++d) {
6220 Perl_warner(aTHX_ packWARN(WARN_QW),
6221 "Possible attempt to separate words with commas");
6224 else if (*d == '#') {
6225 Perl_warner(aTHX_ packWARN(WARN_QW),
6226 "Possible attempt to put comments in qw() list");
6232 for (; !isSPACE(*d) && len; --len, ++d)
6235 sv = newSVpvn(b, d-b);
6236 if (DO_UTF8(PL_lex_stuff))
6238 words = append_elem(OP_LIST, words,
6239 newSVOP(OP_CONST, 0, tokeq(sv)));
6243 start_force(PL_curforce);
6244 NEXTVAL_NEXTTOKE.opval = words;
6249 SvREFCNT_dec(PL_lex_stuff);
6250 PL_lex_stuff = NULL;
6256 s = scan_str(s,!!PL_madskills,FALSE);
6259 yylval.ival = OP_STRINGIFY;
6260 if (SvIVX(PL_lex_stuff) == '\'')
6261 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6262 TERM(sublex_start());
6265 s = scan_pat(s,OP_QR);
6266 TERM(sublex_start());
6269 s = scan_str(s,!!PL_madskills,FALSE);
6272 yylval.ival = OP_BACKTICK;
6274 TERM(sublex_start());
6282 s = force_version(s, FALSE);
6284 else if (*s != 'v' || !isDIGIT(s[1])
6285 || (s = force_version(s, TRUE), *s == 'v'))
6287 *PL_tokenbuf = '\0';
6288 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6289 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6290 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6292 yyerror("<> should be quotes");
6294 if (orig_keyword == KEY_require) {
6302 PL_last_uni = PL_oldbufptr;
6303 PL_last_lop_op = OP_REQUIRE;
6305 return REPORT( (int)REQUIRE );
6311 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6315 LOP(OP_RENAME,XTERM);
6324 LOP(OP_RINDEX,XTERM);
6334 UNIDOR(OP_READLINE);
6347 LOP(OP_REVERSE,XTERM);
6350 UNIDOR(OP_READLINK);
6358 TERM(sublex_start());
6360 TOKEN(1); /* force error */
6363 checkcomma(s,PL_tokenbuf,"filehandle");
6373 LOP(OP_SELECT,XTERM);
6379 LOP(OP_SEMCTL,XTERM);
6382 LOP(OP_SEMGET,XTERM);
6385 LOP(OP_SEMOP,XTERM);
6391 LOP(OP_SETPGRP,XTERM);
6393 case KEY_setpriority:
6394 LOP(OP_SETPRIORITY,XTERM);
6396 case KEY_sethostent:
6402 case KEY_setservent:
6405 case KEY_setprotoent:
6415 LOP(OP_SEEKDIR,XTERM);
6417 case KEY_setsockopt:
6418 LOP(OP_SSOCKOPT,XTERM);
6424 LOP(OP_SHMCTL,XTERM);
6427 LOP(OP_SHMGET,XTERM);
6430 LOP(OP_SHMREAD,XTERM);
6433 LOP(OP_SHMWRITE,XTERM);
6436 LOP(OP_SHUTDOWN,XTERM);
6445 LOP(OP_SOCKET,XTERM);
6447 case KEY_socketpair:
6448 LOP(OP_SOCKPAIR,XTERM);
6451 checkcomma(s,PL_tokenbuf,"subroutine name");
6453 if (*s == ';' || *s == ')') /* probably a close */
6454 Perl_croak(aTHX_ "sort is now a reserved word");
6456 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6460 LOP(OP_SPLIT,XTERM);
6463 LOP(OP_SPRINTF,XTERM);
6466 LOP(OP_SPLICE,XTERM);
6481 LOP(OP_SUBSTR,XTERM);
6487 char tmpbuf[sizeof PL_tokenbuf];
6488 SSize_t tboffset = 0;
6489 expectation attrful;
6490 bool have_name, have_proto;
6491 const int key = tmp;
6496 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6497 SV *subtoken = newSVpvn(tstart, s - tstart);
6501 s = SKIPSPACE2(s,tmpwhite);
6506 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6507 (*s == ':' && s[1] == ':'))
6514 attrful = XATTRBLOCK;
6515 /* remember buffer pos'n for later force_word */
6516 tboffset = s - PL_oldbufptr;
6517 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6520 nametoke = newSVpvn(s, d - s);
6522 if (strchr(tmpbuf, ':'))
6523 sv_setpv(PL_subname, tmpbuf);
6525 sv_setsv(PL_subname,PL_curstname);
6526 sv_catpvs(PL_subname,"::");
6527 sv_catpvn(PL_subname,tmpbuf,len);
6534 CURMAD('X', nametoke);
6535 CURMAD('_', tmpwhite);
6536 (void) force_word(PL_oldbufptr + tboffset, WORD,
6539 s = SKIPSPACE2(d,tmpwhite);
6546 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6547 PL_expect = XTERMBLOCK;
6548 attrful = XATTRTERM;
6549 sv_setpvn(PL_subname,"?",1);
6553 if (key == KEY_format) {
6555 PL_lex_formbrack = PL_lex_brackets + 1;
6557 PL_thistoken = subtoken;
6561 (void) force_word(PL_oldbufptr + tboffset, WORD,
6567 /* Look for a prototype */
6570 s = scan_str(s,!!PL_madskills,FALSE);
6572 Perl_croak(aTHX_ "Prototype not terminated");
6573 /* strip spaces and check for bad characters */
6574 d = SvPVX(PL_lex_stuff);
6578 bool bad_proto = FALSE;
6579 const bool warnsyntax = ckWARN(WARN_SYNTAX);
6580 for (p = d; *p; ++p) {
6583 if (warnsyntax && !strchr("$@%*;[]&\\", *p))
6589 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6590 "Illegal character in prototype for %"SVf" : %s",
6591 (void*)PL_subname, d);
6593 SvCUR_set(PL_lex_stuff, tmp);
6598 CURMAD('q', PL_thisopen);
6599 CURMAD('_', tmpwhite);
6600 CURMAD('=', PL_thisstuff);
6601 CURMAD('Q', PL_thisclose);
6602 NEXTVAL_NEXTTOKE.opval =
6603 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6604 PL_lex_stuff = Nullsv;
6607 s = SKIPSPACE2(s,tmpwhite);
6615 if (*s == ':' && s[1] != ':')
6616 PL_expect = attrful;
6617 else if (*s != '{' && key == KEY_sub) {
6619 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6621 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, (void*)PL_subname);
6628 curmad('^', newSVpvs(""));
6629 CURMAD('_', tmpwhite);
6633 PL_thistoken = subtoken;
6636 NEXTVAL_NEXTTOKE.opval =
6637 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6638 PL_lex_stuff = NULL;
6643 sv_setpv(PL_subname,
6645 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
6649 (void) force_word(PL_oldbufptr + tboffset, WORD,
6659 LOP(OP_SYSTEM,XREF);
6662 LOP(OP_SYMLINK,XTERM);
6665 LOP(OP_SYSCALL,XTERM);
6668 LOP(OP_SYSOPEN,XTERM);
6671 LOP(OP_SYSSEEK,XTERM);
6674 LOP(OP_SYSREAD,XTERM);
6677 LOP(OP_SYSWRITE,XTERM);
6681 TERM(sublex_start());
6702 LOP(OP_TRUNCATE,XTERM);
6714 yylval.ival = CopLINE(PL_curcop);
6718 yylval.ival = CopLINE(PL_curcop);
6722 LOP(OP_UNLINK,XTERM);
6728 LOP(OP_UNPACK,XTERM);
6731 LOP(OP_UTIME,XTERM);
6737 LOP(OP_UNSHIFT,XTERM);
6740 s = tokenize_use(1, s);
6750 yylval.ival = CopLINE(PL_curcop);
6754 yylval.ival = CopLINE(PL_curcop);
6758 PL_hints |= HINT_BLOCK_SCOPE;
6765 LOP(OP_WAITPID,XTERM);
6774 ctl_l[0] = toCTRL('L');
6776 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6779 /* Make sure $^L is defined */
6780 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6785 if (PL_expect == XOPERATOR)
6791 yylval.ival = OP_XOR;
6796 TERM(sublex_start());
6801 #pragma segment Main
6805 S_pending_ident(pTHX)
6810 /* pit holds the identifier we read and pending_ident is reset */
6811 char pit = PL_pending_ident;
6812 PL_pending_ident = 0;
6814 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6815 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6816 "### Pending identifier '%s'\n", PL_tokenbuf); });
6818 /* if we're in a my(), we can't allow dynamics here.
6819 $foo'bar has already been turned into $foo::bar, so
6820 just check for colons.
6822 if it's a legal name, the OP is a PADANY.
6825 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6826 if (strchr(PL_tokenbuf,':'))
6827 yyerror(Perl_form(aTHX_ "No package name allowed for "
6828 "variable %s in \"our\"",
6830 tmp = allocmy(PL_tokenbuf);
6833 if (strchr(PL_tokenbuf,':'))
6834 yyerror(Perl_form(aTHX_ PL_no_myglob,
6835 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6837 yylval.opval = newOP(OP_PADANY, 0);
6838 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6844 build the ops for accesses to a my() variable.
6846 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6847 then used in a comparison. This catches most, but not
6848 all cases. For instance, it catches
6849 sort { my($a); $a <=> $b }
6851 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6852 (although why you'd do that is anyone's guess).
6855 if (!strchr(PL_tokenbuf,':')) {
6857 tmp = pad_findmy(PL_tokenbuf);
6858 if (tmp != NOT_IN_PAD) {
6859 /* might be an "our" variable" */
6860 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6861 /* build ops for a bareword */
6862 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6863 HEK * const stashname = HvNAME_HEK(stash);
6864 SV * const sym = newSVhek(stashname);
6865 sv_catpvs(sym, "::");
6866 sv_catpv(sym, PL_tokenbuf+1);
6867 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6868 yylval.opval->op_private = OPpCONST_ENTERED;
6871 ? (GV_ADDMULTI | GV_ADDINEVAL)
6874 ((PL_tokenbuf[0] == '$') ? SVt_PV
6875 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6880 /* if it's a sort block and they're naming $a or $b */
6881 if (PL_last_lop_op == OP_SORT &&
6882 PL_tokenbuf[0] == '$' &&
6883 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6886 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6887 d < PL_bufend && *d != '\n';
6890 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6891 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6897 yylval.opval = newOP(OP_PADANY, 0);
6898 yylval.opval->op_targ = tmp;
6904 Whine if they've said @foo in a doublequoted string,
6905 and @foo isn't a variable we can find in the symbol
6908 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6909 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6910 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6911 && ckWARN(WARN_AMBIGUOUS))
6913 /* Downgraded from fatal to warning 20000522 mjd */
6914 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6915 "Possible unintended interpolation of %s in string",
6920 /* build ops for a bareword */
6921 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6922 yylval.opval->op_private = OPpCONST_ENTERED;
6925 /* If the identifier refers to a stash, don't autovivify it.
6926 * Change 24660 had the side effect of causing symbol table
6927 * hashes to always be defined, even if they were freshly
6928 * created and the only reference in the entire program was
6929 * the single statement with the defined %foo::bar:: test.
6930 * It appears that all code in the wild doing this actually
6931 * wants to know whether sub-packages have been loaded, so
6932 * by avoiding auto-vivifying symbol tables, we ensure that
6933 * defined %foo::bar:: continues to be false, and the existing
6934 * tests still give the expected answers, even though what
6935 * they're actually testing has now changed subtly.
6937 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6939 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
6940 ((PL_tokenbuf[0] == '$') ? SVt_PV
6941 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6947 * The following code was generated by perl_keyword.pl.
6951 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
6956 case 1: /* 5 tokens of length 1 */
6988 case 2: /* 18 tokens of length 2 */
7134 case 3: /* 29 tokens of length 3 */
7138 if (name[1] == 'N' &&
7201 if (name[1] == 'i' &&
7223 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7241 if (name[1] == 'o' &&
7250 if (name[1] == 'e' &&
7259 if (name[1] == 'n' &&
7268 if (name[1] == 'o' &&
7277 if (name[1] == 'a' &&
7286 if (name[1] == 'o' &&
7348 if (name[1] == 'e' &&
7362 return (all_keywords || FEATURE_IS_ENABLED("say") ? -KEY_say : 0);
7388 if (name[1] == 'i' &&
7397 if (name[1] == 's' &&
7406 if (name[1] == 'e' &&
7415 if (name[1] == 'o' &&
7427 case 4: /* 41 tokens of length 4 */
7431 if (name[1] == 'O' &&
7441 if (name[1] == 'N' &&
7451 if (name[1] == 'i' &&
7461 if (name[1] == 'h' &&
7471 if (name[1] == 'u' &&
7484 if (name[2] == 'c' &&
7493 if (name[2] == 's' &&
7502 if (name[2] == 'a' &&
7538 if (name[1] == 'o' &&
7551 if (name[2] == 't' &&
7560 if (name[2] == 'o' &&
7569 if (name[2] == 't' &&
7578 if (name[2] == 'e' &&
7591 if (name[1] == 'o' &&
7604 if (name[2] == 'y' &&
7613 if (name[2] == 'l' &&
7629 if (name[2] == 's' &&
7638 if (name[2] == 'n' &&
7647 if (name[2] == 'c' &&
7660 if (name[1] == 'e' &&
7670 if (name[1] == 'p' &&
7683 if (name[2] == 'c' &&
7692 if (name[2] == 'p' &&
7701 if (name[2] == 's' &&
7717 if (name[2] == 'n' &&
7787 if (name[2] == 'r' &&
7796 if (name[2] == 'r' &&
7805 if (name[2] == 'a' &&
7821 if (name[2] == 'l' &&
7883 if (name[2] == 'e' &&
7886 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7899 case 5: /* 39 tokens of length 5 */
7903 if (name[1] == 'E' &&
7914 if (name[1] == 'H' &&
7928 if (name[2] == 'a' &&
7938 if (name[2] == 'a' &&
7955 if (name[2] == 'e' &&
7965 if (name[2] == 'e' &&
7969 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
7985 if (name[3] == 'i' &&
7994 if (name[3] == 'o' &&
8030 if (name[2] == 'o' &&
8040 if (name[2] == 'y' &&
8054 if (name[1] == 'l' &&
8068 if (name[2] == 'n' &&
8078 if (name[2] == 'o' &&
8092 if (name[1] == 'i' &&
8097 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8106 if (name[2] == 'd' &&
8116 if (name[2] == 'c' &&
8133 if (name[2] == 'c' &&
8143 if (name[2] == 't' &&
8157 if (name[1] == 'k' &&
8168 if (name[1] == 'r' &&
8182 if (name[2] == 's' &&
8192 if (name[2] == 'd' &&
8209 if (name[2] == 'm' &&
8219 if (name[2] == 'i' &&
8229 if (name[2] == 'e' &&
8239 if (name[2] == 'l' &&
8249 if (name[2] == 'a' &&
8262 if (name[3] == 't' &&
8265 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8271 if (name[3] == 'd' &&
8288 if (name[1] == 'i' &&
8302 if (name[2] == 'a' &&
8315 if (name[3] == 'e' &&
8350 if (name[2] == 'i' &&
8367 if (name[2] == 'i' &&
8377 if (name[2] == 'i' &&
8394 case 6: /* 33 tokens of length 6 */
8398 if (name[1] == 'c' &&
8413 if (name[2] == 'l' &&
8424 if (name[2] == 'r' &&
8439 if (name[1] == 'e' &&
8454 if (name[2] == 's' &&
8459 if(ckWARN_d(WARN_SYNTAX))
8460 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8466 if (name[2] == 'i' &&
8484 if (name[2] == 'l' &&
8495 if (name[2] == 'r' &&
8510 if (name[1] == 'm' &&
8525 if (name[2] == 'n' &&
8536 if (name[2] == 's' &&
8551 if (name[1] == 's' &&
8557 if (name[4] == 't' &&
8566 if (name[4] == 'e' &&
8575 if (name[4] == 'c' &&
8584 if (name[4] == 'n' &&
8600 if (name[1] == 'r' &&
8618 if (name[3] == 'a' &&
8628 if (name[3] == 'u' &&
8642 if (name[2] == 'n' &&
8660 if (name[2] == 'a' &&
8674 if (name[3] == 'e' &&
8687 if (name[4] == 't' &&
8696 if (name[4] == 'e' &&
8718 if (name[4] == 't' &&
8727 if (name[4] == 'e' &&
8743 if (name[2] == 'c' &&
8754 if (name[2] == 'l' &&
8765 if (name[2] == 'b' &&
8776 if (name[2] == 's' &&
8799 if (name[4] == 's' &&
8808 if (name[4] == 'n' &&
8821 if (name[3] == 'a' &&
8838 if (name[1] == 'a' &&
8853 case 7: /* 29 tokens of length 7 */
8857 if (name[1] == 'E' &&
8870 if (name[1] == '_' &&
8883 if (name[1] == 'i' &&
8890 return -KEY_binmode;
8896 if (name[1] == 'o' &&
8903 return -KEY_connect;
8912 if (name[2] == 'm' &&
8918 return -KEY_dbmopen;
8929 if (name[4] == 'u' &&
8933 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
8939 if (name[4] == 'n' &&
8960 if (name[1] == 'o' &&
8973 if (name[1] == 'e' &&
8980 if (name[5] == 'r' &&
8983 return -KEY_getpgrp;
8989 if (name[5] == 'i' &&
8992 return -KEY_getppid;
9005 if (name[1] == 'c' &&
9012 return -KEY_lcfirst;
9018 if (name[1] == 'p' &&
9025 return -KEY_opendir;
9031 if (name[1] == 'a' &&
9049 if (name[3] == 'd' &&
9054 return -KEY_readdir;
9060 if (name[3] == 'u' &&
9071 if (name[3] == 'e' &&
9076 return -KEY_reverse;
9095 if (name[3] == 'k' &&
9100 return -KEY_seekdir;
9106 if (name[3] == 'p' &&
9111 return -KEY_setpgrp;
9121 if (name[2] == 'm' &&
9127 return -KEY_shmread;
9133 if (name[2] == 'r' &&
9139 return -KEY_sprintf;
9148 if (name[3] == 'l' &&
9153 return -KEY_symlink;
9162 if (name[4] == 'a' &&
9166 return -KEY_syscall;
9172 if (name[4] == 'p' &&
9176 return -KEY_sysopen;
9182 if (name[4] == 'e' &&
9186 return -KEY_sysread;
9192 if (name[4] == 'e' &&
9196 return -KEY_sysseek;
9214 if (name[1] == 'e' &&
9221 return -KEY_telldir;
9230 if (name[2] == 'f' &&
9236 return -KEY_ucfirst;
9242 if (name[2] == 's' &&
9248 return -KEY_unshift;
9258 if (name[1] == 'a' &&
9265 return -KEY_waitpid;
9274 case 8: /* 26 tokens of length 8 */
9278 if (name[1] == 'U' &&
9286 return KEY_AUTOLOAD;
9297 if (name[3] == 'A' &&
9303 return KEY___DATA__;
9309 if (name[3] == 'I' &&
9315 return -KEY___FILE__;
9321 if (name[3] == 'I' &&
9327 return -KEY___LINE__;
9343 if (name[2] == 'o' &&
9350 return -KEY_closedir;
9356 if (name[2] == 'n' &&
9363 return -KEY_continue;
9373 if (name[1] == 'b' &&
9381 return -KEY_dbmclose;
9387 if (name[1] == 'n' &&
9393 if (name[4] == 'r' &&
9398 return -KEY_endgrent;
9404 if (name[4] == 'w' &&
9409 return -KEY_endpwent;
9422 if (name[1] == 'o' &&
9430 return -KEY_formline;
9436 if (name[1] == 'e' &&
9447 if (name[6] == 'n' &&
9450 return -KEY_getgrent;
9456 if (name[6] == 'i' &&
9459 return -KEY_getgrgid;
9465 if (name[6] == 'a' &&
9468 return -KEY_getgrnam;
9481 if (name[4] == 'o' &&
9486 return -KEY_getlogin;
9497 if (name[6] == 'n' &&
9500 return -KEY_getpwent;
9506 if (name[6] == 'a' &&
9509 return -KEY_getpwnam;
9515 if (name[6] == 'i' &&
9518 return -KEY_getpwuid;
9538 if (name[1] == 'e' &&
9545 if (name[5] == 'i' &&
9552 return -KEY_readline;
9557 return -KEY_readlink;
9568 if (name[5] == 'i' &&
9572 return -KEY_readpipe;
9593 if (name[4] == 'r' &&
9598 return -KEY_setgrent;
9604 if (name[4] == 'w' &&
9609 return -KEY_setpwent;
9625 if (name[3] == 'w' &&
9631 return -KEY_shmwrite;
9637 if (name[3] == 't' &&
9643 return -KEY_shutdown;
9653 if (name[2] == 's' &&
9660 return -KEY_syswrite;
9670 if (name[1] == 'r' &&
9678 return -KEY_truncate;
9687 case 9: /* 8 tokens of length 9 */
9691 if (name[1] == 'n' &&
9700 return -KEY_endnetent;
9706 if (name[1] == 'e' &&
9715 return -KEY_getnetent;
9721 if (name[1] == 'o' &&
9730 return -KEY_localtime;
9736 if (name[1] == 'r' &&
9745 return KEY_prototype;
9751 if (name[1] == 'u' &&
9760 return -KEY_quotemeta;
9766 if (name[1] == 'e' &&
9775 return -KEY_rewinddir;
9781 if (name[1] == 'e' &&
9790 return -KEY_setnetent;
9796 if (name[1] == 'a' &&
9805 return -KEY_wantarray;
9814 case 10: /* 9 tokens of length 10 */
9818 if (name[1] == 'n' &&
9824 if (name[4] == 'o' &&
9831 return -KEY_endhostent;
9837 if (name[4] == 'e' &&
9844 return -KEY_endservent;
9857 if (name[1] == 'e' &&
9863 if (name[4] == 'o' &&
9870 return -KEY_gethostent;
9879 if (name[5] == 'r' &&
9885 return -KEY_getservent;
9891 if (name[5] == 'c' &&
9897 return -KEY_getsockopt;
9922 if (name[4] == 'o' &&
9929 return -KEY_sethostent;
9938 if (name[5] == 'r' &&
9944 return -KEY_setservent;
9950 if (name[5] == 'c' &&
9956 return -KEY_setsockopt;
9973 if (name[2] == 'c' &&
9982 return -KEY_socketpair;
9995 case 11: /* 8 tokens of length 11 */
9999 if (name[1] == '_' &&
10009 { /* __PACKAGE__ */
10010 return -KEY___PACKAGE__;
10016 if (name[1] == 'n' &&
10026 { /* endprotoent */
10027 return -KEY_endprotoent;
10033 if (name[1] == 'e' &&
10042 if (name[5] == 'e' &&
10048 { /* getpeername */
10049 return -KEY_getpeername;
10058 if (name[6] == 'o' &&
10063 { /* getpriority */
10064 return -KEY_getpriority;
10070 if (name[6] == 't' &&
10075 { /* getprotoent */
10076 return -KEY_getprotoent;
10090 if (name[4] == 'o' &&
10097 { /* getsockname */
10098 return -KEY_getsockname;
10111 if (name[1] == 'e' &&
10119 if (name[6] == 'o' &&
10124 { /* setpriority */
10125 return -KEY_setpriority;
10131 if (name[6] == 't' &&
10136 { /* setprotoent */
10137 return -KEY_setprotoent;
10153 case 12: /* 2 tokens of length 12 */
10154 if (name[0] == 'g' &&
10166 if (name[9] == 'd' &&
10169 { /* getnetbyaddr */
10170 return -KEY_getnetbyaddr;
10176 if (name[9] == 'a' &&
10179 { /* getnetbyname */
10180 return -KEY_getnetbyname;
10192 case 13: /* 4 tokens of length 13 */
10193 if (name[0] == 'g' &&
10200 if (name[4] == 'o' &&
10209 if (name[10] == 'd' &&
10212 { /* gethostbyaddr */
10213 return -KEY_gethostbyaddr;
10219 if (name[10] == 'a' &&
10222 { /* gethostbyname */
10223 return -KEY_gethostbyname;
10236 if (name[4] == 'e' &&
10245 if (name[10] == 'a' &&
10248 { /* getservbyname */
10249 return -KEY_getservbyname;
10255 if (name[10] == 'o' &&
10258 { /* getservbyport */
10259 return -KEY_getservbyport;
10278 case 14: /* 1 tokens of length 14 */
10279 if (name[0] == 'g' &&
10293 { /* getprotobyname */
10294 return -KEY_getprotobyname;
10299 case 16: /* 1 tokens of length 16 */
10300 if (name[0] == 'g' &&
10316 { /* getprotobynumber */
10317 return -KEY_getprotobynumber;
10331 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10335 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10336 if (ckWARN(WARN_SYNTAX)) {
10339 for (w = s+2; *w && level; w++) {
10342 else if (*w == ')')
10345 while (isSPACE(*w))
10347 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
10348 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10349 "%s (...) interpreted as function",name);
10352 while (s < PL_bufend && isSPACE(*s))
10356 while (s < PL_bufend && isSPACE(*s))
10358 if (isIDFIRST_lazy_if(s,UTF)) {
10359 const char * const w = s++;
10360 while (isALNUM_lazy_if(s,UTF))
10362 while (s < PL_bufend && isSPACE(*s))
10366 if (keyword(w, s - w, 0))
10369 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10370 if (gv && GvCVu(gv))
10372 Perl_croak(aTHX_ "No comma allowed after %s", what);
10377 /* Either returns sv, or mortalizes sv and returns a new SV*.
10378 Best used as sv=new_constant(..., sv, ...).
10379 If s, pv are NULL, calls subroutine with one argument,
10380 and type is used with error messages only. */
10383 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10387 HV * const table = GvHV(PL_hintgv); /* ^H */
10391 const char *why1 = "", *why2 = "", *why3 = "";
10393 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10396 why2 = (const char *)
10397 (strEQ(key,"charnames")
10398 ? "(possibly a missing \"use charnames ...\")"
10400 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10401 (type ? type: "undef"), why2);
10403 /* This is convoluted and evil ("goto considered harmful")
10404 * but I do not understand the intricacies of all the different
10405 * failure modes of %^H in here. The goal here is to make
10406 * the most probable error message user-friendly. --jhi */
10411 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10412 (type ? type: "undef"), why1, why2, why3);
10414 yyerror(SvPVX_const(msg));
10418 cvp = hv_fetch(table, key, strlen(key), FALSE);
10419 if (!cvp || !SvOK(*cvp)) {
10422 why3 = "} is not defined";
10425 sv_2mortal(sv); /* Parent created it permanently */
10428 pv = sv_2mortal(newSVpvn(s, len));
10430 typesv = sv_2mortal(newSVpv(type, 0));
10432 typesv = &PL_sv_undef;
10434 PUSHSTACKi(PERLSI_OVERLOAD);
10446 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10450 /* Check the eval first */
10451 if (!PL_in_eval && SvTRUE(ERRSV)) {
10452 sv_catpvs(ERRSV, "Propagated");
10453 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10455 res = SvREFCNT_inc_simple(sv);
10459 SvREFCNT_inc_simple_void(res);
10468 why1 = "Call to &{$^H{";
10470 why3 = "}} did not return a defined value";
10478 /* Returns a NUL terminated string, with the length of the string written to
10482 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10485 register char *d = dest;
10486 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10489 Perl_croak(aTHX_ ident_too_long);
10490 if (isALNUM(*s)) /* UTF handled below */
10492 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10497 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10501 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10502 char *t = s + UTF8SKIP(s);
10504 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10508 Perl_croak(aTHX_ ident_too_long);
10509 Copy(s, d, len, char);
10522 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10525 char *bracket = NULL;
10527 register char *d = dest;
10528 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10533 while (isDIGIT(*s)) {
10535 Perl_croak(aTHX_ ident_too_long);
10542 Perl_croak(aTHX_ ident_too_long);
10543 if (isALNUM(*s)) /* UTF handled below */
10545 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10550 else if (*s == ':' && s[1] == ':') {
10554 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10555 char *t = s + UTF8SKIP(s);
10556 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10558 if (d + (t - s) > e)
10559 Perl_croak(aTHX_ ident_too_long);
10560 Copy(s, d, t - s, char);
10571 if (PL_lex_state != LEX_NORMAL)
10572 PL_lex_state = LEX_INTERPENDMAYBE;
10575 if (*s == '$' && s[1] &&
10576 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10589 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10594 if (isSPACE(s[-1])) {
10596 const char ch = *s++;
10597 if (!SPACE_OR_TAB(ch)) {
10603 if (isIDFIRST_lazy_if(d,UTF)) {
10607 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10608 end += UTF8SKIP(end);
10609 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10610 end += UTF8SKIP(end);
10612 Copy(s, d, end - s, char);
10617 while ((isALNUM(*s) || *s == ':') && d < e)
10620 Perl_croak(aTHX_ ident_too_long);
10623 while (s < send && SPACE_OR_TAB(*s))
10625 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10626 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10627 const char * const brack =
10629 ((*s == '[') ? "[...]" : "{...}");
10630 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10631 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10632 funny, dest, brack, funny, dest, brack);
10635 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10639 /* Handle extended ${^Foo} variables
10640 * 1999-02-27 mjd-perl-patch@plover.com */
10641 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10645 while (isALNUM(*s) && d < e) {
10649 Perl_croak(aTHX_ ident_too_long);
10654 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10655 PL_lex_state = LEX_INTERPEND;
10658 if (PL_lex_state == LEX_NORMAL) {
10659 if (ckWARN(WARN_AMBIGUOUS) &&
10660 (keyword(dest, d - dest, 0) || get_cv(dest, FALSE)))
10664 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10665 "Ambiguous use of %c{%s} resolved to %c%s",
10666 funny, dest, funny, dest);
10671 s = bracket; /* let the parser handle it */
10675 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10676 PL_lex_state = LEX_INTERPEND;
10681 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10683 PERL_UNUSED_CONTEXT;
10686 else if (ch == 'g')
10687 *pmfl |= PMf_GLOBAL;
10688 else if (ch == 'c')
10689 *pmfl |= PMf_CONTINUE;
10690 else if (ch == 'o')
10692 else if (ch == 'm')
10693 *pmfl |= PMf_MULTILINE;
10694 else if (ch == 's')
10695 *pmfl |= PMf_SINGLELINE;
10696 else if (ch == 'x')
10697 *pmfl |= PMf_EXTENDED;
10701 S_scan_pat(pTHX_ char *start, I32 type)
10705 char *s = scan_str(start,!!PL_madskills,FALSE);
10706 const char * const valid_flags =
10707 (const char *)((type == OP_QR) ? "iomsx" : "iogcmsx");
10714 const char * const delimiter = skipspace(start);
10718 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10719 : "Search pattern not terminated" ));
10722 pm = (PMOP*)newPMOP(type, 0);
10723 if (PL_multi_open == '?')
10724 pm->op_pmflags |= PMf_ONCE;
10728 while (*s && strchr(valid_flags, *s))
10729 pmflag(&pm->op_pmflags,*s++);
10731 if (PL_madskills && modstart != s) {
10732 SV* tmptoken = newSVpvn(modstart, s - modstart);
10733 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10736 /* issue a warning if /c is specified,but /g is not */
10737 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10738 && ckWARN(WARN_REGEXP))
10740 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
10743 pm->op_pmpermflags = pm->op_pmflags;
10745 PL_lex_op = (OP*)pm;
10746 yylval.ival = OP_MATCH;
10751 S_scan_subst(pTHX_ char *start)
10762 yylval.ival = OP_NULL;
10764 s = scan_str(start,!!PL_madskills,FALSE);
10767 Perl_croak(aTHX_ "Substitution pattern not terminated");
10769 if (s[-1] == PL_multi_open)
10772 if (PL_madskills) {
10773 CURMAD('q', PL_thisopen);
10774 CURMAD('_', PL_thiswhite);
10775 CURMAD('E', PL_thisstuff);
10776 CURMAD('Q', PL_thisclose);
10777 PL_realtokenstart = s - SvPVX(PL_linestr);
10781 first_start = PL_multi_start;
10782 s = scan_str(s,!!PL_madskills,FALSE);
10784 if (PL_lex_stuff) {
10785 SvREFCNT_dec(PL_lex_stuff);
10786 PL_lex_stuff = NULL;
10788 Perl_croak(aTHX_ "Substitution replacement not terminated");
10790 PL_multi_start = first_start; /* so whole substitution is taken together */
10792 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10795 if (PL_madskills) {
10796 CURMAD('z', PL_thisopen);
10797 CURMAD('R', PL_thisstuff);
10798 CURMAD('Z', PL_thisclose);
10808 else if (strchr("iogcmsx", *s))
10809 pmflag(&pm->op_pmflags,*s++);
10815 if (PL_madskills) {
10817 curmad('m', newSVpvn(modstart, s - modstart));
10818 append_madprops(PL_thismad, (OP*)pm, 0);
10822 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10823 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10827 SV * const repl = newSVpvs("");
10829 PL_sublex_info.super_bufptr = s;
10830 PL_sublex_info.super_bufend = PL_bufend;
10832 pm->op_pmflags |= PMf_EVAL;
10834 sv_catpv(repl, (const char *)(es ? "eval " : "do "));
10835 sv_catpvs(repl, "{");
10836 sv_catsv(repl, PL_lex_repl);
10837 if (strchr(SvPVX(PL_lex_repl), '#'))
10838 sv_catpvs(repl, "\n");
10839 sv_catpvs(repl, "}");
10841 SvREFCNT_dec(PL_lex_repl);
10842 PL_lex_repl = repl;
10845 pm->op_pmpermflags = pm->op_pmflags;
10846 PL_lex_op = (OP*)pm;
10847 yylval.ival = OP_SUBST;
10852 S_scan_trans(pTHX_ char *start)
10865 yylval.ival = OP_NULL;
10867 s = scan_str(start,!!PL_madskills,FALSE);
10869 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10871 if (s[-1] == PL_multi_open)
10874 if (PL_madskills) {
10875 CURMAD('q', PL_thisopen);
10876 CURMAD('_', PL_thiswhite);
10877 CURMAD('E', PL_thisstuff);
10878 CURMAD('Q', PL_thisclose);
10879 PL_realtokenstart = s - SvPVX(PL_linestr);
10883 s = scan_str(s,!!PL_madskills,FALSE);
10885 if (PL_lex_stuff) {
10886 SvREFCNT_dec(PL_lex_stuff);
10887 PL_lex_stuff = NULL;
10889 Perl_croak(aTHX_ "Transliteration replacement not terminated");
10891 if (PL_madskills) {
10892 CURMAD('z', PL_thisopen);
10893 CURMAD('R', PL_thisstuff);
10894 CURMAD('Z', PL_thisclose);
10897 complement = del = squash = 0;
10904 complement = OPpTRANS_COMPLEMENT;
10907 del = OPpTRANS_DELETE;
10910 squash = OPpTRANS_SQUASH;
10919 Newx(tbl, complement&&!del?258:256, short);
10920 o = newPVOP(OP_TRANS, 0, (char*)tbl);
10921 o->op_private &= ~OPpTRANS_ALL;
10922 o->op_private |= del|squash|complement|
10923 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10924 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
10927 yylval.ival = OP_TRANS;
10930 if (PL_madskills) {
10932 curmad('m', newSVpvn(modstart, s - modstart));
10933 append_madprops(PL_thismad, o, 0);
10942 S_scan_heredoc(pTHX_ register char *s)
10946 I32 op_type = OP_SCALAR;
10950 const char *found_newline;
10954 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
10956 I32 stuffstart = s - SvPVX(PL_linestr);
10959 PL_realtokenstart = -1;
10964 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
10968 while (SPACE_OR_TAB(*peek))
10970 if (*peek == '`' || *peek == '\'' || *peek =='"') {
10973 s = delimcpy(d, e, s, PL_bufend, term, &len);
10983 if (!isALNUM_lazy_if(s,UTF))
10984 deprecate_old("bare << to mean <<\"\"");
10985 for (; isALNUM_lazy_if(s,UTF); s++) {
10990 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
10991 Perl_croak(aTHX_ "Delimiter for here document is too long");
10994 len = d - PL_tokenbuf;
10997 if (PL_madskills) {
10998 tstart = PL_tokenbuf + !outer;
10999 PL_thisclose = newSVpvn(tstart, len - !outer);
11000 tstart = SvPVX(PL_linestr) + stuffstart;
11001 PL_thisopen = newSVpvn(tstart, s - tstart);
11002 stuffstart = s - SvPVX(PL_linestr);
11005 #ifndef PERL_STRICT_CR
11006 d = strchr(s, '\r');
11008 char * const olds = s;
11010 while (s < PL_bufend) {
11016 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11025 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11032 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11033 herewas = newSVpvn(s,PL_bufend-s);
11037 herewas = newSVpvn(s-1,found_newline-s+1);
11040 herewas = newSVpvn(s,found_newline-s);
11044 if (PL_madskills) {
11045 tstart = SvPVX(PL_linestr) + stuffstart;
11047 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11049 PL_thisstuff = newSVpvn(tstart, s - tstart);
11052 s += SvCUR(herewas);
11055 stuffstart = s - SvPVX(PL_linestr);
11061 tmpstr = newSV(79);
11062 sv_upgrade(tmpstr, SVt_PVIV);
11063 if (term == '\'') {
11064 op_type = OP_CONST;
11065 SvIV_set(tmpstr, -1);
11067 else if (term == '`') {
11068 op_type = OP_BACKTICK;
11069 SvIV_set(tmpstr, '\\');
11073 PL_multi_start = CopLINE(PL_curcop);
11074 PL_multi_open = PL_multi_close = '<';
11075 term = *PL_tokenbuf;
11076 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11077 char * const bufptr = PL_sublex_info.super_bufptr;
11078 char * const bufend = PL_sublex_info.super_bufend;
11079 char * const olds = s - SvCUR(herewas);
11080 s = strchr(bufptr, '\n');
11084 while (s < bufend &&
11085 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11087 CopLINE_inc(PL_curcop);
11090 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11091 missingterm(PL_tokenbuf);
11093 sv_setpvn(herewas,bufptr,d-bufptr+1);
11094 sv_setpvn(tmpstr,d+1,s-d);
11096 sv_catpvn(herewas,s,bufend-s);
11097 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11104 while (s < PL_bufend &&
11105 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11107 CopLINE_inc(PL_curcop);
11109 if (s >= PL_bufend) {
11110 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11111 missingterm(PL_tokenbuf);
11113 sv_setpvn(tmpstr,d+1,s-d);
11115 if (PL_madskills) {
11117 sv_catpvn(PL_thisstuff, d + 1, s - d);
11119 PL_thisstuff = newSVpvn(d + 1, s - d);
11120 stuffstart = s - SvPVX(PL_linestr);
11124 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11126 sv_catpvn(herewas,s,PL_bufend-s);
11127 sv_setsv(PL_linestr,herewas);
11128 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11129 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11130 PL_last_lop = PL_last_uni = NULL;
11133 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11134 while (s >= PL_bufend) { /* multiple line string? */
11136 if (PL_madskills) {
11137 tstart = SvPVX(PL_linestr) + stuffstart;
11139 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11141 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11145 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11146 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11147 missingterm(PL_tokenbuf);
11150 stuffstart = s - SvPVX(PL_linestr);
11152 CopLINE_inc(PL_curcop);
11153 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11154 PL_last_lop = PL_last_uni = NULL;
11155 #ifndef PERL_STRICT_CR
11156 if (PL_bufend - PL_linestart >= 2) {
11157 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11158 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11160 PL_bufend[-2] = '\n';
11162 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11164 else if (PL_bufend[-1] == '\r')
11165 PL_bufend[-1] = '\n';
11167 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11168 PL_bufend[-1] = '\n';
11170 if (PERLDB_LINE && PL_curstash != PL_debstash) {
11171 SV * const sv = newSV(0);
11173 sv_upgrade(sv, SVt_PVMG);
11174 sv_setsv(sv,PL_linestr);
11175 (void)SvIOK_on(sv);
11177 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop),sv);
11179 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11180 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11181 *(SvPVX(PL_linestr) + off ) = ' ';
11182 sv_catsv(PL_linestr,herewas);
11183 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11184 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11188 sv_catsv(tmpstr,PL_linestr);
11193 PL_multi_end = CopLINE(PL_curcop);
11194 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11195 SvPV_shrink_to_cur(tmpstr);
11197 SvREFCNT_dec(herewas);
11199 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11201 else if (PL_encoding)
11202 sv_recode_to_utf8(tmpstr, PL_encoding);
11204 PL_lex_stuff = tmpstr;
11205 yylval.ival = op_type;
11209 /* scan_inputsymbol
11210 takes: current position in input buffer
11211 returns: new position in input buffer
11212 side-effects: yylval and lex_op are set.
11217 <FH> read from filehandle
11218 <pkg::FH> read from package qualified filehandle
11219 <pkg'FH> read from package qualified filehandle
11220 <$fh> read from filehandle in $fh
11221 <*.h> filename glob
11226 S_scan_inputsymbol(pTHX_ char *start)
11229 register char *s = start; /* current position in buffer */
11233 char *d = PL_tokenbuf; /* start of temp holding space */
11234 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11236 end = strchr(s, '\n');
11239 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11241 /* die if we didn't have space for the contents of the <>,
11242 or if it didn't end, or if we see a newline
11245 if (len >= (I32)sizeof PL_tokenbuf)
11246 Perl_croak(aTHX_ "Excessively long <> operator");
11248 Perl_croak(aTHX_ "Unterminated <> operator");
11253 Remember, only scalar variables are interpreted as filehandles by
11254 this code. Anything more complex (e.g., <$fh{$num}>) will be
11255 treated as a glob() call.
11256 This code makes use of the fact that except for the $ at the front,
11257 a scalar variable and a filehandle look the same.
11259 if (*d == '$' && d[1]) d++;
11261 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11262 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11265 /* If we've tried to read what we allow filehandles to look like, and
11266 there's still text left, then it must be a glob() and not a getline.
11267 Use scan_str to pull out the stuff between the <> and treat it
11268 as nothing more than a string.
11271 if (d - PL_tokenbuf != len) {
11272 yylval.ival = OP_GLOB;
11274 s = scan_str(start,!!PL_madskills,FALSE);
11276 Perl_croak(aTHX_ "Glob not terminated");
11280 bool readline_overriden = FALSE;
11283 /* we're in a filehandle read situation */
11286 /* turn <> into <ARGV> */
11288 Copy("ARGV",d,5,char);
11290 /* Check whether readline() is overriden */
11291 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11293 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11295 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11296 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
11297 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11298 readline_overriden = TRUE;
11300 /* if <$fh>, create the ops to turn the variable into a
11304 /* try to find it in the pad for this block, otherwise find
11305 add symbol table ops
11307 const PADOFFSET tmp = pad_findmy(d);
11308 if (tmp != NOT_IN_PAD) {
11309 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11310 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11311 HEK * const stashname = HvNAME_HEK(stash);
11312 SV * const sym = sv_2mortal(newSVhek(stashname));
11313 sv_catpvs(sym, "::");
11314 sv_catpv(sym, d+1);
11319 OP * const o = newOP(OP_PADSV, 0);
11321 PL_lex_op = readline_overriden
11322 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11323 append_elem(OP_LIST, o,
11324 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11325 : (OP*)newUNOP(OP_READLINE, 0, o);
11334 ? (GV_ADDMULTI | GV_ADDINEVAL)
11337 PL_lex_op = readline_overriden
11338 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11339 append_elem(OP_LIST,
11340 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11341 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11342 : (OP*)newUNOP(OP_READLINE, 0,
11343 newUNOP(OP_RV2SV, 0,
11344 newGVOP(OP_GV, 0, gv)));
11346 if (!readline_overriden)
11347 PL_lex_op->op_flags |= OPf_SPECIAL;
11348 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11349 yylval.ival = OP_NULL;
11352 /* If it's none of the above, it must be a literal filehandle
11353 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11355 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11356 PL_lex_op = readline_overriden
11357 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11358 append_elem(OP_LIST,
11359 newGVOP(OP_GV, 0, gv),
11360 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11361 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11362 yylval.ival = OP_NULL;
11371 takes: start position in buffer
11372 keep_quoted preserve \ on the embedded delimiter(s)
11373 keep_delims preserve the delimiters around the string
11374 returns: position to continue reading from buffer
11375 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11376 updates the read buffer.
11378 This subroutine pulls a string out of the input. It is called for:
11379 q single quotes q(literal text)
11380 ' single quotes 'literal text'
11381 qq double quotes qq(interpolate $here please)
11382 " double quotes "interpolate $here please"
11383 qx backticks qx(/bin/ls -l)
11384 ` backticks `/bin/ls -l`
11385 qw quote words @EXPORT_OK = qw( func() $spam )
11386 m// regexp match m/this/
11387 s/// regexp substitute s/this/that/
11388 tr/// string transliterate tr/this/that/
11389 y/// string transliterate y/this/that/
11390 ($*@) sub prototypes sub foo ($)
11391 (stuff) sub attr parameters sub foo : attr(stuff)
11392 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11394 In most of these cases (all but <>, patterns and transliterate)
11395 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11396 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11397 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11400 It skips whitespace before the string starts, and treats the first
11401 character as the delimiter. If the delimiter is one of ([{< then
11402 the corresponding "close" character )]}> is used as the closing
11403 delimiter. It allows quoting of delimiters, and if the string has
11404 balanced delimiters ([{<>}]) it allows nesting.
11406 On success, the SV with the resulting string is put into lex_stuff or,
11407 if that is already non-NULL, into lex_repl. The second case occurs only
11408 when parsing the RHS of the special constructs s/// and tr/// (y///).
11409 For convenience, the terminating delimiter character is stuffed into
11414 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11417 SV *sv; /* scalar value: string */
11418 const char *tmps; /* temp string, used for delimiter matching */
11419 register char *s = start; /* current position in the buffer */
11420 register char term; /* terminating character */
11421 register char *to; /* current position in the sv's data */
11422 I32 brackets = 1; /* bracket nesting level */
11423 bool has_utf8 = FALSE; /* is there any utf8 content? */
11424 I32 termcode; /* terminating char. code */
11425 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11426 STRLEN termlen; /* length of terminating string */
11427 char *last = NULL; /* last position for nesting bracket */
11433 /* skip space before the delimiter */
11439 if (PL_realtokenstart >= 0) {
11440 stuffstart = PL_realtokenstart;
11441 PL_realtokenstart = -1;
11444 stuffstart = start - SvPVX(PL_linestr);
11446 /* mark where we are, in case we need to report errors */
11449 /* after skipping whitespace, the next character is the terminator */
11452 termcode = termstr[0] = term;
11456 termcode = utf8_to_uvchr((U8*)s, &termlen);
11457 Copy(s, termstr, termlen, U8);
11458 if (!UTF8_IS_INVARIANT(term))
11462 /* mark where we are */
11463 PL_multi_start = CopLINE(PL_curcop);
11464 PL_multi_open = term;
11466 /* find corresponding closing delimiter */
11467 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11468 termcode = termstr[0] = term = tmps[5];
11470 PL_multi_close = term;
11472 /* create a new SV to hold the contents. 79 is the SV's initial length.
11473 What a random number. */
11475 sv_upgrade(sv, SVt_PVIV);
11476 SvIV_set(sv, termcode);
11477 (void)SvPOK_only(sv); /* validate pointer */
11479 /* move past delimiter and try to read a complete string */
11481 sv_catpvn(sv, s, termlen);
11484 tstart = SvPVX(PL_linestr) + stuffstart;
11485 if (!PL_thisopen && !keep_delims) {
11486 PL_thisopen = newSVpvn(tstart, s - tstart);
11487 stuffstart = s - SvPVX(PL_linestr);
11491 if (PL_encoding && !UTF) {
11495 int offset = s - SvPVX_const(PL_linestr);
11496 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11497 &offset, (char*)termstr, termlen);
11498 const char * const ns = SvPVX_const(PL_linestr) + offset;
11499 char * const svlast = SvEND(sv) - 1;
11501 for (; s < ns; s++) {
11502 if (*s == '\n' && !PL_rsfp)
11503 CopLINE_inc(PL_curcop);
11506 goto read_more_line;
11508 /* handle quoted delimiters */
11509 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11511 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11513 if ((svlast-1 - t) % 2) {
11514 if (!keep_quoted) {
11515 *(svlast-1) = term;
11517 SvCUR_set(sv, SvCUR(sv) - 1);
11522 if (PL_multi_open == PL_multi_close) {
11530 for (t = w = last; t < svlast; w++, t++) {
11531 /* At here, all closes are "was quoted" one,
11532 so we don't check PL_multi_close. */
11534 if (!keep_quoted && *(t+1) == PL_multi_open)
11539 else if (*t == PL_multi_open)
11547 SvCUR_set(sv, w - SvPVX_const(sv));
11550 if (--brackets <= 0)
11555 if (!keep_delims) {
11556 SvCUR_set(sv, SvCUR(sv) - 1);
11562 /* extend sv if need be */
11563 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11564 /* set 'to' to the next character in the sv's string */
11565 to = SvPVX(sv)+SvCUR(sv);
11567 /* if open delimiter is the close delimiter read unbridle */
11568 if (PL_multi_open == PL_multi_close) {
11569 for (; s < PL_bufend; s++,to++) {
11570 /* embedded newlines increment the current line number */
11571 if (*s == '\n' && !PL_rsfp)
11572 CopLINE_inc(PL_curcop);
11573 /* handle quoted delimiters */
11574 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11575 if (!keep_quoted && s[1] == term)
11577 /* any other quotes are simply copied straight through */
11581 /* terminate when run out of buffer (the for() condition), or
11582 have found the terminator */
11583 else if (*s == term) {
11586 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11589 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11595 /* if the terminator isn't the same as the start character (e.g.,
11596 matched brackets), we have to allow more in the quoting, and
11597 be prepared for nested brackets.
11600 /* read until we run out of string, or we find the terminator */
11601 for (; s < PL_bufend; s++,to++) {
11602 /* embedded newlines increment the line count */
11603 if (*s == '\n' && !PL_rsfp)
11604 CopLINE_inc(PL_curcop);
11605 /* backslashes can escape the open or closing characters */
11606 if (*s == '\\' && s+1 < PL_bufend) {
11607 if (!keep_quoted &&
11608 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11613 /* allow nested opens and closes */
11614 else if (*s == PL_multi_close && --brackets <= 0)
11616 else if (*s == PL_multi_open)
11618 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11623 /* terminate the copied string and update the sv's end-of-string */
11625 SvCUR_set(sv, to - SvPVX_const(sv));
11628 * this next chunk reads more into the buffer if we're not done yet
11632 break; /* handle case where we are done yet :-) */
11634 #ifndef PERL_STRICT_CR
11635 if (to - SvPVX_const(sv) >= 2) {
11636 if ((to[-2] == '\r' && to[-1] == '\n') ||
11637 (to[-2] == '\n' && to[-1] == '\r'))
11641 SvCUR_set(sv, to - SvPVX_const(sv));
11643 else if (to[-1] == '\r')
11646 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11651 /* if we're out of file, or a read fails, bail and reset the current
11652 line marker so we can report where the unterminated string began
11655 if (PL_madskills) {
11656 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11658 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11660 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11664 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11666 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11672 /* we read a line, so increment our line counter */
11673 CopLINE_inc(PL_curcop);
11675 /* update debugger info */
11676 if (PERLDB_LINE && PL_curstash != PL_debstash) {
11677 SV * const line_sv = newSV(0);
11679 sv_upgrade(line_sv, SVt_PVMG);
11680 sv_setsv(line_sv,PL_linestr);
11681 (void)SvIOK_on(line_sv);
11682 SvIV_set(line_sv, 0);
11683 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop), line_sv);
11686 /* having changed the buffer, we must update PL_bufend */
11687 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11688 PL_last_lop = PL_last_uni = NULL;
11691 /* at this point, we have successfully read the delimited string */
11693 if (!PL_encoding || UTF) {
11695 if (PL_madskills) {
11696 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11697 const int len = s - start;
11699 sv_catpvn(PL_thisstuff, tstart, len);
11701 PL_thisstuff = newSVpvn(tstart, len);
11702 if (!PL_thisclose && !keep_delims)
11703 PL_thisclose = newSVpvn(s,termlen);
11708 sv_catpvn(sv, s, termlen);
11713 if (PL_madskills) {
11714 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11715 const int len = s - tstart - termlen;
11717 sv_catpvn(PL_thisstuff, tstart, len);
11719 PL_thisstuff = newSVpvn(tstart, len);
11720 if (!PL_thisclose && !keep_delims)
11721 PL_thisclose = newSVpvn(s - termlen,termlen);
11725 if (has_utf8 || PL_encoding)
11728 PL_multi_end = CopLINE(PL_curcop);
11730 /* if we allocated too much space, give some back */
11731 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11732 SvLEN_set(sv, SvCUR(sv) + 1);
11733 SvPV_renew(sv, SvLEN(sv));
11736 /* decide whether this is the first or second quoted string we've read
11749 takes: pointer to position in buffer
11750 returns: pointer to new position in buffer
11751 side-effects: builds ops for the constant in yylval.op
11753 Read a number in any of the formats that Perl accepts:
11755 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11756 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11759 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11761 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11764 If it reads a number without a decimal point or an exponent, it will
11765 try converting the number to an integer and see if it can do so
11766 without loss of precision.
11770 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11773 register const char *s = start; /* current position in buffer */
11774 register char *d; /* destination in temp buffer */
11775 register char *e; /* end of temp buffer */
11776 NV nv; /* number read, as a double */
11777 SV *sv = NULL; /* place to put the converted number */
11778 bool floatit; /* boolean: int or float? */
11779 const char *lastub = NULL; /* position of last underbar */
11780 static char const number_too_long[] = "Number too long";
11782 /* We use the first character to decide what type of number this is */
11786 Perl_croak(aTHX_ "panic: scan_num");
11788 /* if it starts with a 0, it could be an octal number, a decimal in
11789 0.13 disguise, or a hexadecimal number, or a binary number. */
11793 u holds the "number so far"
11794 shift the power of 2 of the base
11795 (hex == 4, octal == 3, binary == 1)
11796 overflowed was the number more than we can hold?
11798 Shift is used when we add a digit. It also serves as an "are
11799 we in octal/hex/binary?" indicator to disallow hex characters
11800 when in octal mode.
11805 bool overflowed = FALSE;
11806 bool just_zero = TRUE; /* just plain 0 or binary number? */
11807 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11808 static const char* const bases[5] =
11809 { "", "binary", "", "octal", "hexadecimal" };
11810 static const char* const Bases[5] =
11811 { "", "Binary", "", "Octal", "Hexadecimal" };
11812 static const char* const maxima[5] =
11814 "0b11111111111111111111111111111111",
11818 const char *base, *Base, *max;
11820 /* check for hex */
11825 } else if (s[1] == 'b') {
11830 /* check for a decimal in disguise */
11831 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11833 /* so it must be octal */
11840 if (ckWARN(WARN_SYNTAX))
11841 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11842 "Misplaced _ in number");
11846 base = bases[shift];
11847 Base = Bases[shift];
11848 max = maxima[shift];
11850 /* read the rest of the number */
11852 /* x is used in the overflow test,
11853 b is the digit we're adding on. */
11858 /* if we don't mention it, we're done */
11862 /* _ are ignored -- but warned about if consecutive */
11864 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11865 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11866 "Misplaced _ in number");
11870 /* 8 and 9 are not octal */
11871 case '8': case '9':
11873 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11877 case '2': case '3': case '4':
11878 case '5': case '6': case '7':
11880 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11883 case '0': case '1':
11884 b = *s++ & 15; /* ASCII digit -> value of digit */
11888 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11889 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11890 /* make sure they said 0x */
11893 b = (*s++ & 7) + 9;
11895 /* Prepare to put the digit we have onto the end
11896 of the number so far. We check for overflows.
11902 x = u << shift; /* make room for the digit */
11904 if ((x >> shift) != u
11905 && !(PL_hints & HINT_NEW_BINARY)) {
11908 if (ckWARN_d(WARN_OVERFLOW))
11909 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11910 "Integer overflow in %s number",
11913 u = x | b; /* add the digit to the end */
11916 n *= nvshift[shift];
11917 /* If an NV has not enough bits in its
11918 * mantissa to represent an UV this summing of
11919 * small low-order numbers is a waste of time
11920 * (because the NV cannot preserve the
11921 * low-order bits anyway): we could just
11922 * remember when did we overflow and in the
11923 * end just multiply n by the right
11931 /* if we get here, we had success: make a scalar value from
11936 /* final misplaced underbar check */
11937 if (s[-1] == '_') {
11938 if (ckWARN(WARN_SYNTAX))
11939 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11944 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
11945 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11946 "%s number > %s non-portable",
11952 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
11953 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11954 "%s number > %s non-portable",
11959 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
11960 sv = new_constant(start, s - start, "integer",
11962 else if (PL_hints & HINT_NEW_BINARY)
11963 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
11968 handle decimal numbers.
11969 we're also sent here when we read a 0 as the first digit
11971 case '1': case '2': case '3': case '4': case '5':
11972 case '6': case '7': case '8': case '9': case '.':
11975 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
11978 /* read next group of digits and _ and copy into d */
11979 while (isDIGIT(*s) || *s == '_') {
11980 /* skip underscores, checking for misplaced ones
11984 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11985 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11986 "Misplaced _ in number");
11990 /* check for end of fixed-length buffer */
11992 Perl_croak(aTHX_ number_too_long);
11993 /* if we're ok, copy the character */
11998 /* final misplaced underbar check */
11999 if (lastub && s == lastub + 1) {
12000 if (ckWARN(WARN_SYNTAX))
12001 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12004 /* read a decimal portion if there is one. avoid
12005 3..5 being interpreted as the number 3. followed
12008 if (*s == '.' && s[1] != '.') {
12013 if (ckWARN(WARN_SYNTAX))
12014 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12015 "Misplaced _ in number");
12019 /* copy, ignoring underbars, until we run out of digits.
12021 for (; isDIGIT(*s) || *s == '_'; s++) {
12022 /* fixed length buffer check */
12024 Perl_croak(aTHX_ number_too_long);
12026 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12027 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12028 "Misplaced _ in number");
12034 /* fractional part ending in underbar? */
12035 if (s[-1] == '_') {
12036 if (ckWARN(WARN_SYNTAX))
12037 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12038 "Misplaced _ in number");
12040 if (*s == '.' && isDIGIT(s[1])) {
12041 /* oops, it's really a v-string, but without the "v" */
12047 /* read exponent part, if present */
12048 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12052 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12053 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12055 /* stray preinitial _ */
12057 if (ckWARN(WARN_SYNTAX))
12058 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12059 "Misplaced _ in number");
12063 /* allow positive or negative exponent */
12064 if (*s == '+' || *s == '-')
12067 /* stray initial _ */
12069 if (ckWARN(WARN_SYNTAX))
12070 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12071 "Misplaced _ in number");
12075 /* read digits of exponent */
12076 while (isDIGIT(*s) || *s == '_') {
12079 Perl_croak(aTHX_ number_too_long);
12083 if (((lastub && s == lastub + 1) ||
12084 (!isDIGIT(s[1]) && s[1] != '_'))
12085 && ckWARN(WARN_SYNTAX))
12086 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12087 "Misplaced _ in number");
12094 /* make an sv from the string */
12098 We try to do an integer conversion first if no characters
12099 indicating "float" have been found.
12104 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12106 if (flags == IS_NUMBER_IN_UV) {
12108 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12111 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12112 if (uv <= (UV) IV_MIN)
12113 sv_setiv(sv, -(IV)uv);
12120 /* terminate the string */
12122 nv = Atof(PL_tokenbuf);
12126 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12127 (PL_hints & HINT_NEW_INTEGER) )
12128 sv = new_constant(PL_tokenbuf,
12131 (floatit ? "float" : "integer"),
12135 /* if it starts with a v, it could be a v-string */
12138 sv = newSV(5); /* preallocate storage space */
12139 s = scan_vstring(s,sv);
12143 /* make the op for the constant and return */
12146 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12148 lvalp->opval = NULL;
12154 S_scan_formline(pTHX_ register char *s)
12157 register char *eol;
12159 SV * const stuff = newSVpvs("");
12160 bool needargs = FALSE;
12161 bool eofmt = FALSE;
12163 char *tokenstart = s;
12166 if (PL_madskills) {
12167 savewhite = PL_thiswhite;
12172 while (!needargs) {
12175 #ifdef PERL_STRICT_CR
12176 while (SPACE_OR_TAB(*t))
12179 while (SPACE_OR_TAB(*t) || *t == '\r')
12182 if (*t == '\n' || t == PL_bufend) {
12187 if (PL_in_eval && !PL_rsfp) {
12188 eol = (char *) memchr(s,'\n',PL_bufend-s);
12193 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12195 for (t = s; t < eol; t++) {
12196 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12198 goto enough; /* ~~ must be first line in formline */
12200 if (*t == '@' || *t == '^')
12204 sv_catpvn(stuff, s, eol-s);
12205 #ifndef PERL_STRICT_CR
12206 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12207 char *end = SvPVX(stuff) + SvCUR(stuff);
12210 SvCUR_set(stuff, SvCUR(stuff) - 1);
12220 if (PL_madskills) {
12222 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12224 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12227 s = filter_gets(PL_linestr, PL_rsfp, 0);
12229 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12231 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12233 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12234 PL_last_lop = PL_last_uni = NULL;
12243 if (SvCUR(stuff)) {
12246 PL_lex_state = LEX_NORMAL;
12247 start_force(PL_curforce);
12248 NEXTVAL_NEXTTOKE.ival = 0;
12252 PL_lex_state = LEX_FORMLINE;
12254 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12256 else if (PL_encoding)
12257 sv_recode_to_utf8(stuff, PL_encoding);
12259 start_force(PL_curforce);
12260 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12262 start_force(PL_curforce);
12263 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12267 SvREFCNT_dec(stuff);
12269 PL_lex_formbrack = 0;
12273 if (PL_madskills) {
12275 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12277 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12278 PL_thiswhite = savewhite;
12290 PL_cshlen = strlen(PL_cshname);
12292 #if defined(USE_ITHREADS)
12293 PERL_UNUSED_CONTEXT;
12299 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12302 const I32 oldsavestack_ix = PL_savestack_ix;
12303 CV* const outsidecv = PL_compcv;
12306 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12308 SAVEI32(PL_subline);
12309 save_item(PL_subname);
12310 SAVESPTR(PL_compcv);
12312 PL_compcv = (CV*)newSV(0);
12313 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12314 CvFLAGS(PL_compcv) |= flags;
12316 PL_subline = CopLINE(PL_curcop);
12317 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12318 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12319 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12321 return oldsavestack_ix;
12325 #pragma segment Perl_yylex
12328 Perl_yywarn(pTHX_ const char *s)
12331 PL_in_eval |= EVAL_WARNONLY;
12333 PL_in_eval &= ~EVAL_WARNONLY;
12338 Perl_yyerror(pTHX_ const char *s)
12341 const char *where = NULL;
12342 const char *context = NULL;
12346 if (!yychar || (yychar == ';' && !PL_rsfp))
12348 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12349 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12350 PL_oldbufptr != PL_bufptr) {
12353 The code below is removed for NetWare because it abends/crashes on NetWare
12354 when the script has error such as not having the closing quotes like:
12355 if ($var eq "value)
12356 Checking of white spaces is anyway done in NetWare code.
12359 while (isSPACE(*PL_oldoldbufptr))
12362 context = PL_oldoldbufptr;
12363 contlen = PL_bufptr - PL_oldoldbufptr;
12365 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12366 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12369 The code below is removed for NetWare because it abends/crashes on NetWare
12370 when the script has error such as not having the closing quotes like:
12371 if ($var eq "value)
12372 Checking of white spaces is anyway done in NetWare code.
12375 while (isSPACE(*PL_oldbufptr))
12378 context = PL_oldbufptr;
12379 contlen = PL_bufptr - PL_oldbufptr;
12381 else if (yychar > 255)
12382 where = "next token ???";
12383 else if (yychar == -2) { /* YYEMPTY */
12384 if (PL_lex_state == LEX_NORMAL ||
12385 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12386 where = "at end of line";
12387 else if (PL_lex_inpat)
12388 where = "within pattern";
12390 where = "within string";
12393 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12395 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12396 else if (isPRINT_LC(yychar))
12397 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12399 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12400 where = SvPVX_const(where_sv);
12402 msg = sv_2mortal(newSVpv(s, 0));
12403 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12404 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12406 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12408 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12409 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12410 Perl_sv_catpvf(aTHX_ msg,
12411 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12412 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12415 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12416 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, (void*)msg);
12419 if (PL_error_count >= 10) {
12420 if (PL_in_eval && SvCUR(ERRSV))
12421 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12422 (void*)ERRSV, OutCopFILE(PL_curcop));
12424 Perl_croak(aTHX_ "%s has too many errors.\n",
12425 OutCopFILE(PL_curcop));
12428 PL_in_my_stash = NULL;
12432 #pragma segment Main
12436 S_swallow_bom(pTHX_ U8 *s)
12439 const STRLEN slen = SvCUR(PL_linestr);
12442 if (s[1] == 0xFE) {
12443 /* UTF-16 little-endian? (or UTF32-LE?) */
12444 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12445 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12446 #ifndef PERL_NO_UTF16_FILTER
12447 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12450 if (PL_bufend > (char*)s) {
12454 filter_add(utf16rev_textfilter, NULL);
12455 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12456 utf16_to_utf8_reversed(s, news,
12457 PL_bufend - (char*)s - 1,
12459 sv_setpvn(PL_linestr, (const char*)news, newlen);
12461 s = (U8*)SvPVX(PL_linestr);
12462 Copy(news, s, newlen, U8);
12466 SvUTF8_on(PL_linestr);
12467 s = (U8*)SvPVX(PL_linestr);
12469 /* FIXME - is this a general bug fix? */
12472 PL_bufend = SvPVX(PL_linestr) + newlen;
12475 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12480 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12481 #ifndef PERL_NO_UTF16_FILTER
12482 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12485 if (PL_bufend > (char *)s) {
12489 filter_add(utf16_textfilter, NULL);
12490 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12491 utf16_to_utf8(s, news,
12492 PL_bufend - (char*)s,
12494 sv_setpvn(PL_linestr, (const char*)news, newlen);
12496 SvUTF8_on(PL_linestr);
12497 s = (U8*)SvPVX(PL_linestr);
12498 PL_bufend = SvPVX(PL_linestr) + newlen;
12501 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12506 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12507 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12508 s += 3; /* UTF-8 */
12514 if (s[2] == 0xFE && s[3] == 0xFF) {
12515 /* UTF-32 big-endian */
12516 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12519 else if (s[2] == 0 && s[3] != 0) {
12522 * are a good indicator of UTF-16BE. */
12523 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12529 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12530 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12531 s += 4; /* UTF-8 */
12537 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12540 * are a good indicator of UTF-16LE. */
12541 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12550 * Restore a source filter.
12554 restore_rsfp(pTHX_ void *f)
12557 PerlIO * const fp = (PerlIO*)f;
12559 if (PL_rsfp == PerlIO_stdin())
12560 PerlIO_clearerr(PL_rsfp);
12561 else if (PL_rsfp && (PL_rsfp != fp))
12562 PerlIO_close(PL_rsfp);
12566 #ifndef PERL_NO_UTF16_FILTER
12568 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12571 const STRLEN old = SvCUR(sv);
12572 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12573 DEBUG_P(PerlIO_printf(Perl_debug_log,
12574 "utf16_textfilter(%p): %d %d (%d)\n",
12575 FPTR2DPTR(void *, utf16_textfilter),
12576 idx, maxlen, (int) count));
12580 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12581 Copy(SvPVX_const(sv), tmps, old, char);
12582 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12583 SvCUR(sv) - old, &newlen);
12584 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12586 DEBUG_P({sv_dump(sv);});
12591 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12594 const STRLEN old = SvCUR(sv);
12595 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12596 DEBUG_P(PerlIO_printf(Perl_debug_log,
12597 "utf16rev_textfilter(%p): %d %d (%d)\n",
12598 FPTR2DPTR(void *, utf16rev_textfilter),
12599 idx, maxlen, (int) count));
12603 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12604 Copy(SvPVX_const(sv), tmps, old, char);
12605 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12606 SvCUR(sv) - old, &newlen);
12607 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12609 DEBUG_P({ sv_dump(sv); });
12615 Returns a pointer to the next character after the parsed
12616 vstring, as well as updating the passed in sv.
12618 Function must be called like
12621 s = scan_vstring(s,sv);
12623 The sv should already be large enough to store the vstring
12624 passed in, for performance reasons.
12629 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12632 const char *pos = s;
12633 const char *start = s;
12634 if (*pos == 'v') pos++; /* get past 'v' */
12635 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12637 if ( *pos != '.') {
12638 /* this may not be a v-string if followed by => */
12639 const char *next = pos;
12640 while (next < PL_bufend && isSPACE(*next))
12642 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12643 /* return string not v-string */
12644 sv_setpvn(sv,(char *)s,pos-s);
12645 return (char *)pos;
12649 if (!isALPHA(*pos)) {
12650 U8 tmpbuf[UTF8_MAXBYTES+1];
12653 s++; /* get past 'v' */
12655 sv_setpvn(sv, "", 0);
12658 /* this is atoi() that tolerates underscores */
12661 const char *end = pos;
12663 while (--end >= s) {
12665 const UV orev = rev;
12666 rev += (*end - '0') * mult;
12668 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12669 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12670 "Integer overflow in decimal number");
12674 if (rev > 0x7FFFFFFF)
12675 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12677 /* Append native character for the rev point */
12678 tmpend = uvchr_to_utf8(tmpbuf, rev);
12679 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12680 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12682 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12688 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12692 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12700 * c-indentation-style: bsd
12701 * c-basic-offset: 4
12702 * indent-tabs-mode: t
12705 * ex: set ts=8 sts=4 sw=4 noet: