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 = newSVpvn("",0);
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 = newSVpvn("",0);
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;
863 *svp = newSVpvn("",0);
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 = newSVpvn("",0);
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 = newSVpvn("",0);
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('^', newSVpvn("",0));
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))
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 = newSVpvn("",0);
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 const char * const leaveit = /* set of acceptably-backslashed characters */
1795 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxcz0123456789[{]} \t\n\r\f\v#"
1798 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1799 /* If we are doing a trans and we know we want UTF8 set expectation */
1800 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1801 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1805 while (s < send || dorange) {
1806 /* get transliterations out of the way (they're most literal) */
1807 if (PL_lex_inwhat == OP_TRANS) {
1808 /* expand a range A-Z to the full set of characters. AIE! */
1810 I32 i; /* current expanded character */
1811 I32 min; /* first character in range */
1812 I32 max; /* last character in range */
1823 char * const c = (char*)utf8_hop((U8*)d, -1);
1827 *c = (char)UTF_TO_NATIVE(0xff);
1828 /* mark the range as done, and continue */
1834 i = d - SvPVX_const(sv); /* remember current offset */
1837 SvLEN(sv) + (has_utf8 ?
1838 (512 - UTF_CONTINUATION_MARK +
1841 /* How many two-byte within 0..255: 128 in UTF-8,
1842 * 96 in UTF-8-mod. */
1844 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1846 d = SvPVX(sv) + i; /* refresh d after realloc */
1850 for (j = 0; j <= 1; j++) {
1851 char * const c = (char*)utf8_hop((U8*)d, -1);
1852 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
1858 max = (U8)0xff; /* only to \xff */
1859 uvmax = uv; /* \x{100} to uvmax */
1861 d = c; /* eat endpoint chars */
1866 d -= 2; /* eat the first char and the - */
1867 min = (U8)*d; /* first char in range */
1868 max = (U8)d[1]; /* last char in range */
1875 "Invalid range \"%c-%c\" in transliteration operator",
1876 (char)min, (char)max);
1880 if (literal_endpoint == 2 &&
1881 ((isLOWER(min) && isLOWER(max)) ||
1882 (isUPPER(min) && isUPPER(max)))) {
1884 for (i = min; i <= max; i++)
1886 *d++ = NATIVE_TO_NEED(has_utf8,i);
1888 for (i = min; i <= max; i++)
1890 *d++ = NATIVE_TO_NEED(has_utf8,i);
1895 for (i = min; i <= max; i++)
1898 const U8 ch = (U8)NATIVE_TO_UTF(i);
1899 if (UNI_IS_INVARIANT(ch))
1902 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
1903 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
1912 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
1914 *d++ = (char)UTF_TO_NATIVE(0xff);
1916 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
1920 /* mark the range as done, and continue */
1924 literal_endpoint = 0;
1929 /* range begins (ignore - as first or last char) */
1930 else if (*s == '-' && s+1 < send && s != start) {
1932 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1939 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1949 literal_endpoint = 0;
1950 native_range = TRUE;
1955 /* if we get here, we're not doing a transliteration */
1957 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1958 except for the last char, which will be done separately. */
1959 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1961 while (s+1 < send && *s != ')')
1962 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1964 else if (s[2] == '{' /* This should match regcomp.c */
1965 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1968 char *regparse = s + (s[2] == '{' ? 3 : 4);
1971 while (count && (c = *regparse)) {
1972 if (c == '\\' && regparse[1])
1980 if (*regparse != ')')
1981 regparse--; /* Leave one char for continuation. */
1982 while (s < regparse)
1983 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1987 /* likewise skip #-initiated comments in //x patterns */
1988 else if (*s == '#' && PL_lex_inpat &&
1989 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1990 while (s+1 < send && *s != '\n')
1991 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1994 /* check for embedded arrays
1995 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1997 else if (*s == '@' && s[1]
1998 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
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 /* some backslashes we leave behind */
2018 if (*leaveit && *s && strchr(leaveit, *s)) {
2019 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2020 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2024 /* deprecate \1 in strings and substitution replacements */
2025 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2026 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2028 if (ckWARN(WARN_SYNTAX))
2029 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2034 /* string-change backslash escapes */
2035 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2040 /* if we get here, it's either a quoted -, or a digit */
2043 /* quoted - in transliterations */
2045 if (PL_lex_inwhat == OP_TRANS) {
2052 if ((isALPHA(*s) || isDIGIT(*s)) &&
2054 Perl_warner(aTHX_ packWARN(WARN_MISC),
2055 "Unrecognized escape \\%c passed through",
2057 /* default action is to copy the quoted character */
2058 goto default_action;
2061 /* \132 indicates an octal constant */
2062 case '0': case '1': case '2': case '3':
2063 case '4': case '5': case '6': case '7':
2067 uv = grok_oct(s, &len, &flags, NULL);
2070 goto NUM_ESCAPE_INSERT;
2072 /* \x24 indicates a hex constant */
2076 char* const e = strchr(s, '}');
2077 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2078 PERL_SCAN_DISALLOW_PREFIX;
2083 yyerror("Missing right brace on \\x{}");
2087 uv = grok_hex(s, &len, &flags, NULL);
2093 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2094 uv = grok_hex(s, &len, &flags, NULL);
2100 /* Insert oct or hex escaped character.
2101 * There will always enough room in sv since such
2102 * escapes will be longer than any UTF-8 sequence
2103 * they can end up as. */
2105 /* We need to map to chars to ASCII before doing the tests
2108 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2109 if (!has_utf8 && uv > 255) {
2110 /* Might need to recode whatever we have
2111 * accumulated so far if it contains any
2114 * (Can't we keep track of that and avoid
2115 * this rescan? --jhi)
2119 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2120 if (!NATIVE_IS_INVARIANT(*c)) {
2125 const STRLEN offset = d - SvPVX_const(sv);
2127 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2131 while (src >= (const U8 *)SvPVX_const(sv)) {
2132 if (!NATIVE_IS_INVARIANT(*src)) {
2133 const U8 ch = NATIVE_TO_ASCII(*src);
2134 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2135 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2145 if (has_utf8 || uv > 255) {
2146 d = (char*)uvchr_to_utf8((U8*)d, uv);
2148 if (PL_lex_inwhat == OP_TRANS &&
2149 PL_sublex_info.sub_op) {
2150 PL_sublex_info.sub_op->op_private |=
2151 (PL_lex_repl ? OPpTRANS_FROM_UTF
2155 if (uv > 255 && !dorange)
2156 native_range = FALSE;
2168 /* \N{LATIN SMALL LETTER A} is a named character */
2172 char* e = strchr(s, '}');
2178 yyerror("Missing right brace on \\N{}");
2182 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2184 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2185 PERL_SCAN_DISALLOW_PREFIX;
2188 uv = grok_hex(s, &len, &flags, NULL);
2190 goto NUM_ESCAPE_INSERT;
2192 res = newSVpvn(s + 1, e - s - 1);
2193 res = new_constant( NULL, 0, "charnames",
2194 res, NULL, "\\N{...}" );
2196 sv_utf8_upgrade(res);
2197 str = SvPV_const(res,len);
2198 #ifdef EBCDIC_NEVER_MIND
2199 /* charnames uses pack U and that has been
2200 * recently changed to do the below uni->native
2201 * mapping, so this would be redundant (and wrong,
2202 * the code point would be doubly converted).
2203 * But leave this in just in case the pack U change
2204 * gets revoked, but the semantics is still
2205 * desireable for charnames. --jhi */
2207 UV uv = utf8_to_uvchr((const U8*)str, 0);
2210 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2212 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2213 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2214 str = SvPV_const(res, len);
2218 if (!has_utf8 && SvUTF8(res)) {
2219 const char * const ostart = SvPVX_const(sv);
2220 SvCUR_set(sv, d - ostart);
2223 sv_utf8_upgrade(sv);
2224 /* this just broke our allocation above... */
2225 SvGROW(sv, (STRLEN)(send - start));
2226 d = SvPVX(sv) + SvCUR(sv);
2229 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2230 const char * const odest = SvPVX_const(sv);
2232 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2233 d = SvPVX(sv) + (d - odest);
2237 native_range = FALSE; /* \N{} is guessed to be Unicode */
2239 Copy(str, d, len, char);
2246 yyerror("Missing braces on \\N{}");
2249 /* \c is a control character */
2258 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2261 yyerror("Missing control char name in \\c");
2265 /* printf-style backslashes, formfeeds, newlines, etc */
2267 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2270 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2273 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2276 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2279 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2282 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2285 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2291 } /* end if (backslash) */
2298 /* If we started with encoded form, or already know we want it
2299 and then encode the next character */
2300 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2302 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2303 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2306 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2307 const STRLEN off = d - SvPVX_const(sv);
2308 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2310 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2313 if (uv > 255 && !dorange)
2314 native_range = FALSE;
2318 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2320 } /* while loop to process each character */
2322 /* terminate the string and set up the sv */
2324 SvCUR_set(sv, d - SvPVX_const(sv));
2325 if (SvCUR(sv) >= SvLEN(sv))
2326 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2329 if (PL_encoding && !has_utf8) {
2330 sv_recode_to_utf8(sv, PL_encoding);
2336 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2337 PL_sublex_info.sub_op->op_private |=
2338 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2342 /* shrink the sv if we allocated more than we used */
2343 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2344 SvPV_shrink_to_cur(sv);
2347 /* return the substring (via yylval) only if we parsed anything */
2348 if (s > PL_bufptr) {
2349 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2350 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
2352 ( PL_lex_inwhat == OP_TRANS
2354 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2357 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2364 * Returns TRUE if there's more to the expression (e.g., a subscript),
2367 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2369 * ->[ and ->{ return TRUE
2370 * { and [ outside a pattern are always subscripts, so return TRUE
2371 * if we're outside a pattern and it's not { or [, then return FALSE
2372 * if we're in a pattern and the first char is a {
2373 * {4,5} (any digits around the comma) returns FALSE
2374 * if we're in a pattern and the first char is a [
2376 * [SOMETHING] has a funky algorithm to decide whether it's a
2377 * character class or not. It has to deal with things like
2378 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2379 * anything else returns TRUE
2382 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2385 S_intuit_more(pTHX_ register char *s)
2388 if (PL_lex_brackets)
2390 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2392 if (*s != '{' && *s != '[')
2397 /* In a pattern, so maybe we have {n,m}. */
2414 /* On the other hand, maybe we have a character class */
2417 if (*s == ']' || *s == '^')
2420 /* this is terrifying, and it works */
2421 int weight = 2; /* let's weigh the evidence */
2423 unsigned char un_char = 255, last_un_char;
2424 const char * const send = strchr(s,']');
2425 char tmpbuf[sizeof PL_tokenbuf * 4];
2427 if (!send) /* has to be an expression */
2430 Zero(seen,256,char);
2433 else if (isDIGIT(*s)) {
2435 if (isDIGIT(s[1]) && s[2] == ']')
2441 for (; s < send; s++) {
2442 last_un_char = un_char;
2443 un_char = (unsigned char)*s;
2448 weight -= seen[un_char] * 10;
2449 if (isALNUM_lazy_if(s+1,UTF)) {
2451 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2452 len = (int)strlen(tmpbuf);
2453 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2458 else if (*s == '$' && s[1] &&
2459 strchr("[#!%*<>()-=",s[1])) {
2460 if (/*{*/ strchr("])} =",s[2]))
2469 if (strchr("wds]",s[1]))
2471 else if (seen['\''] || seen['"'])
2473 else if (strchr("rnftbxcav",s[1]))
2475 else if (isDIGIT(s[1])) {
2477 while (s[1] && isDIGIT(s[1]))
2487 if (strchr("aA01! ",last_un_char))
2489 if (strchr("zZ79~",s[1]))
2491 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2492 weight -= 5; /* cope with negative subscript */
2495 if (!isALNUM(last_un_char)
2496 && !(last_un_char == '$' || last_un_char == '@'
2497 || last_un_char == '&')
2498 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2503 if (keyword(tmpbuf, d - tmpbuf))
2506 if (un_char == last_un_char + 1)
2508 weight -= seen[un_char];
2513 if (weight >= 0) /* probably a character class */
2523 * Does all the checking to disambiguate
2525 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2526 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2528 * First argument is the stuff after the first token, e.g. "bar".
2530 * Not a method if bar is a filehandle.
2531 * Not a method if foo is a subroutine prototyped to take a filehandle.
2532 * Not a method if it's really "Foo $bar"
2533 * Method if it's "foo $bar"
2534 * Not a method if it's really "print foo $bar"
2535 * Method if it's really "foo package::" (interpreted as package->foo)
2536 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2537 * Not a method if bar is a filehandle or package, but is quoted with
2542 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2545 char *s = start + (*start == '$');
2546 char tmpbuf[sizeof PL_tokenbuf];
2554 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2558 const char *proto = SvPVX_const(cv);
2569 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2570 /* start is the beginning of the possible filehandle/object,
2571 * and s is the end of it
2572 * tmpbuf is a copy of it
2575 if (*start == '$') {
2576 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2579 len = start - SvPVX(PL_linestr);
2583 start = SvPVX(PL_linestr) + len;
2587 return *s == '(' ? FUNCMETH : METHOD;
2589 if (!keyword(tmpbuf, len)) {
2590 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2594 soff = s - SvPVX(PL_linestr);
2598 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2599 if (indirgv && GvCVu(indirgv))
2601 /* filehandle or package name makes it a method */
2602 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2604 soff = s - SvPVX(PL_linestr);
2607 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2608 return 0; /* no assumptions -- "=>" quotes bearword */
2610 start_force(PL_curforce);
2611 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2612 newSVpvn(tmpbuf,len));
2613 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2615 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2620 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2622 return *s == '(' ? FUNCMETH : METHOD;
2630 * Return a string of Perl code to load the debugger. If PERL5DB
2631 * is set, it will return the contents of that, otherwise a
2632 * compile-time require of perl5db.pl.
2640 const char * const pdb = PerlEnv_getenv("PERL5DB");
2644 SETERRNO(0,SS_NORMAL);
2645 return "BEGIN { require 'perl5db.pl' }";
2651 /* Encoded script support. filter_add() effectively inserts a
2652 * 'pre-processing' function into the current source input stream.
2653 * Note that the filter function only applies to the current source file
2654 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2656 * The datasv parameter (which may be NULL) can be used to pass
2657 * private data to this instance of the filter. The filter function
2658 * can recover the SV using the FILTER_DATA macro and use it to
2659 * store private buffers and state information.
2661 * The supplied datasv parameter is upgraded to a PVIO type
2662 * and the IoDIRP/IoANY field is used to store the function pointer,
2663 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2664 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2665 * private use must be set using malloc'd pointers.
2669 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2675 if (!PL_rsfp_filters)
2676 PL_rsfp_filters = newAV();
2679 SvUPGRADE(datasv, SVt_PVIO);
2680 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2681 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2682 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2683 FPTR2DPTR(void *, IoANY(datasv)),
2684 SvPV_nolen(datasv)));
2685 av_unshift(PL_rsfp_filters, 1);
2686 av_store(PL_rsfp_filters, 0, datasv) ;
2691 /* Delete most recently added instance of this filter function. */
2693 Perl_filter_del(pTHX_ filter_t funcp)
2699 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2700 FPTR2DPTR(void*, funcp)));
2702 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2704 /* if filter is on top of stack (usual case) just pop it off */
2705 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2706 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2707 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2708 IoANY(datasv) = (void *)NULL;
2709 sv_free(av_pop(PL_rsfp_filters));
2713 /* we need to search for the correct entry and clear it */
2714 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2718 /* Invoke the idxth filter function for the current rsfp. */
2719 /* maxlen 0 = read one text line */
2721 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2726 /* This API is bad. It should have been using unsigned int for maxlen.
2727 Not sure if we want to change the API, but if not we should sanity
2728 check the value here. */
2729 const unsigned int correct_length
2738 if (!PL_rsfp_filters)
2740 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2741 /* Provide a default input filter to make life easy. */
2742 /* Note that we append to the line. This is handy. */
2743 DEBUG_P(PerlIO_printf(Perl_debug_log,
2744 "filter_read %d: from rsfp\n", idx));
2745 if (correct_length) {
2748 const int old_len = SvCUR(buf_sv);
2750 /* ensure buf_sv is large enough */
2751 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2752 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2753 correct_length)) <= 0) {
2754 if (PerlIO_error(PL_rsfp))
2755 return -1; /* error */
2757 return 0 ; /* end of file */
2759 SvCUR_set(buf_sv, old_len + len) ;
2762 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2763 if (PerlIO_error(PL_rsfp))
2764 return -1; /* error */
2766 return 0 ; /* end of file */
2769 return SvCUR(buf_sv);
2771 /* Skip this filter slot if filter has been deleted */
2772 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2773 DEBUG_P(PerlIO_printf(Perl_debug_log,
2774 "filter_read %d: skipped (filter deleted)\n",
2776 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2778 /* Get function pointer hidden within datasv */
2779 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2780 DEBUG_P(PerlIO_printf(Perl_debug_log,
2781 "filter_read %d: via function %p (%s)\n",
2782 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2783 /* Call function. The function is expected to */
2784 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2785 /* Return: <0:error, =0:eof, >0:not eof */
2786 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2790 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2793 #ifdef PERL_CR_FILTER
2794 if (!PL_rsfp_filters) {
2795 filter_add(S_cr_textfilter,NULL);
2798 if (PL_rsfp_filters) {
2800 SvCUR_set(sv, 0); /* start with empty line */
2801 if (FILTER_READ(0, sv, 0) > 0)
2802 return ( SvPVX(sv) ) ;
2807 return (sv_gets(sv, fp, append));
2811 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2816 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2820 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2821 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2823 return GvHV(gv); /* Foo:: */
2826 /* use constant CLASS => 'MyClass' */
2827 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2828 if (gv && GvCV(gv)) {
2829 SV * const sv = cv_const_sv(GvCV(gv));
2831 pkgname = SvPV_nolen_const(sv);
2834 return gv_stashpv(pkgname, FALSE);
2840 * The intent of this yylex wrapper is to minimize the changes to the
2841 * tokener when we aren't interested in collecting madprops. It remains
2842 * to be seen how successful this strategy will be...
2849 char *s = PL_bufptr;
2851 /* make sure PL_thiswhite is initialized */
2855 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2856 if (PL_pending_ident)
2857 return S_pending_ident(aTHX);
2859 /* previous token ate up our whitespace? */
2860 if (!PL_lasttoke && PL_nextwhite) {
2861 PL_thiswhite = PL_nextwhite;
2865 /* isolate the token, and figure out where it is without whitespace */
2866 PL_realtokenstart = -1;
2870 assert(PL_curforce < 0);
2872 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2873 if (!PL_thistoken) {
2874 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2875 PL_thistoken = newSVpvn("",0);
2877 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2878 PL_thistoken = newSVpvn(tstart, s - tstart);
2881 if (PL_thismad) /* install head */
2882 CURMAD('X', PL_thistoken);
2885 /* last whitespace of a sublex? */
2886 if (optype == ')' && PL_endwhite) {
2887 CURMAD('X', PL_endwhite);
2892 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
2893 if (!PL_thiswhite && !PL_endwhite && !optype) {
2894 sv_free(PL_thistoken);
2899 /* put off final whitespace till peg */
2900 if (optype == ';' && !PL_rsfp) {
2901 PL_nextwhite = PL_thiswhite;
2904 else if (PL_thisopen) {
2905 CURMAD('q', PL_thisopen);
2907 sv_free(PL_thistoken);
2911 /* Store actual token text as madprop X */
2912 CURMAD('X', PL_thistoken);
2916 /* add preceding whitespace as madprop _ */
2917 CURMAD('_', PL_thiswhite);
2921 /* add quoted material as madprop = */
2922 CURMAD('=', PL_thisstuff);
2926 /* add terminating quote as madprop Q */
2927 CURMAD('Q', PL_thisclose);
2931 /* special processing based on optype */
2935 /* opval doesn't need a TOKEN since it can already store mp */
2946 append_madprops(PL_thismad, yylval.opval, 0);
2954 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
2963 /* remember any fake bracket that lexer is about to discard */
2964 if (PL_lex_brackets == 1 &&
2965 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
2968 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2971 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
2972 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
2975 break; /* don't bother looking for trailing comment */
2984 /* attach a trailing comment to its statement instead of next token */
2988 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
2990 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2992 if (*s == '\n' || *s == '#') {
2993 while (s < PL_bufend && *s != '\n')
2997 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
2998 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3015 /* Create new token struct. Note: opvals return early above. */
3016 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
3023 S_tokenize_use(pTHX_ int is_use, char *s) {
3025 if (PL_expect != XSTATE)
3026 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3027 is_use ? "use" : "no"));
3029 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3030 s = force_version(s, TRUE);
3031 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3032 start_force(PL_curforce);
3033 NEXTVAL_NEXTTOKE.opval = NULL;
3036 else if (*s == 'v') {
3037 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3038 s = force_version(s, FALSE);
3042 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3043 s = force_version(s, FALSE);
3045 yylval.ival = is_use;
3049 static const char* const exp_name[] =
3050 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3051 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3058 Works out what to call the token just pulled out of the input
3059 stream. The yacc parser takes care of taking the ops we return and
3060 stitching them into a tree.
3066 if read an identifier
3067 if we're in a my declaration
3068 croak if they tried to say my($foo::bar)
3069 build the ops for a my() declaration
3070 if it's an access to a my() variable
3071 are we in a sort block?
3072 croak if my($a); $a <=> $b
3073 build ops for access to a my() variable
3074 if in a dq string, and they've said @foo and we can't find @foo
3076 build ops for a bareword
3077 if we already built the token before, use it.
3082 #pragma segment Perl_yylex
3088 register char *s = PL_bufptr;
3094 SV* tmp = newSVpvs("");
3095 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3096 (IV)CopLINE(PL_curcop),
3097 lex_state_names[PL_lex_state],
3098 exp_name[PL_expect],
3099 pv_display(tmp, s, strlen(s), 0, 60));
3102 /* check if there's an identifier for us to look at */
3103 if (PL_pending_ident)
3104 return REPORT(S_pending_ident(aTHX));
3106 /* no identifier pending identification */
3108 switch (PL_lex_state) {
3110 case LEX_NORMAL: /* Some compilers will produce faster */
3111 case LEX_INTERPNORMAL: /* code if we comment these out. */
3115 /* when we've already built the next token, just pull it out of the queue */
3119 yylval = PL_nexttoke[PL_lasttoke].next_val;
3121 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3122 PL_nexttoke[PL_lasttoke].next_mad = 0;
3123 if (PL_thismad && PL_thismad->mad_key == '_') {
3124 PL_thiswhite = (SV*)PL_thismad->mad_val;
3125 PL_thismad->mad_val = 0;
3126 mad_free(PL_thismad);
3131 PL_lex_state = PL_lex_defer;
3132 PL_expect = PL_lex_expect;
3133 PL_lex_defer = LEX_NORMAL;
3134 if (!PL_nexttoke[PL_lasttoke].next_type)
3139 yylval = PL_nextval[PL_nexttoke];
3141 PL_lex_state = PL_lex_defer;
3142 PL_expect = PL_lex_expect;
3143 PL_lex_defer = LEX_NORMAL;
3147 /* FIXME - can these be merged? */
3148 return(PL_nexttoke[PL_lasttoke].next_type);
3150 return REPORT(PL_nexttype[PL_nexttoke]);
3153 /* interpolated case modifiers like \L \U, including \Q and \E.
3154 when we get here, PL_bufptr is at the \
3156 case LEX_INTERPCASEMOD:
3158 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3159 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3161 /* handle \E or end of string */
3162 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3164 if (PL_lex_casemods) {
3165 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3166 PL_lex_casestack[PL_lex_casemods] = '\0';
3168 if (PL_bufptr != PL_bufend
3169 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3171 PL_lex_state = LEX_INTERPCONCAT;
3174 PL_thistoken = newSVpvn("\\E",2);
3180 while (PL_bufptr != PL_bufend &&
3181 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3183 PL_thiswhite = newSVpvn("",0);
3184 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3188 if (PL_bufptr != PL_bufend)
3191 PL_lex_state = LEX_INTERPCONCAT;
3195 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3196 "### Saw case modifier\n"); });
3198 if (s[1] == '\\' && s[2] == 'E') {
3201 PL_thiswhite = newSVpvn("",0);
3202 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3205 PL_lex_state = LEX_INTERPCONCAT;
3210 if (!PL_madskills) /* when just compiling don't need correct */
3211 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3212 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3213 if ((*s == 'L' || *s == 'U') &&
3214 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3215 PL_lex_casestack[--PL_lex_casemods] = '\0';
3218 if (PL_lex_casemods > 10)
3219 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3220 PL_lex_casestack[PL_lex_casemods++] = *s;
3221 PL_lex_casestack[PL_lex_casemods] = '\0';
3222 PL_lex_state = LEX_INTERPCONCAT;
3223 start_force(PL_curforce);
3224 NEXTVAL_NEXTTOKE.ival = 0;
3226 start_force(PL_curforce);
3228 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3230 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3232 NEXTVAL_NEXTTOKE.ival = OP_LC;
3234 NEXTVAL_NEXTTOKE.ival = OP_UC;
3236 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3238 Perl_croak(aTHX_ "panic: yylex");
3240 SV* const tmpsv = newSVpvn("",0);
3241 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3247 if (PL_lex_starts) {
3253 sv_free(PL_thistoken);
3254 PL_thistoken = newSVpvn("",0);
3257 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3258 if (PL_lex_casemods == 1 && PL_lex_inpat)
3267 case LEX_INTERPPUSH:
3268 return REPORT(sublex_push());
3270 case LEX_INTERPSTART:
3271 if (PL_bufptr == PL_bufend)
3272 return REPORT(sublex_done());
3273 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3274 "### Interpolated variable\n"); });
3276 PL_lex_dojoin = (*PL_bufptr == '@');
3277 PL_lex_state = LEX_INTERPNORMAL;
3278 if (PL_lex_dojoin) {
3279 start_force(PL_curforce);
3280 NEXTVAL_NEXTTOKE.ival = 0;
3282 start_force(PL_curforce);
3283 force_ident("\"", '$');
3284 start_force(PL_curforce);
3285 NEXTVAL_NEXTTOKE.ival = 0;
3287 start_force(PL_curforce);
3288 NEXTVAL_NEXTTOKE.ival = 0;
3290 start_force(PL_curforce);
3291 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3294 if (PL_lex_starts++) {
3299 sv_free(PL_thistoken);
3300 PL_thistoken = newSVpvn("",0);
3303 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3304 if (!PL_lex_casemods && PL_lex_inpat)
3311 case LEX_INTERPENDMAYBE:
3312 if (intuit_more(PL_bufptr)) {
3313 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3319 if (PL_lex_dojoin) {
3320 PL_lex_dojoin = FALSE;
3321 PL_lex_state = LEX_INTERPCONCAT;
3325 sv_free(PL_thistoken);
3326 PL_thistoken = newSVpvn("",0);
3331 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3332 && SvEVALED(PL_lex_repl))
3334 if (PL_bufptr != PL_bufend)
3335 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3339 case LEX_INTERPCONCAT:
3341 if (PL_lex_brackets)
3342 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3344 if (PL_bufptr == PL_bufend)
3345 return REPORT(sublex_done());
3347 if (SvIVX(PL_linestr) == '\'') {
3348 SV *sv = newSVsv(PL_linestr);
3351 else if ( PL_hints & HINT_NEW_RE )
3352 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3353 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3357 s = scan_const(PL_bufptr);
3359 PL_lex_state = LEX_INTERPCASEMOD;
3361 PL_lex_state = LEX_INTERPSTART;
3364 if (s != PL_bufptr) {
3365 start_force(PL_curforce);
3367 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3369 NEXTVAL_NEXTTOKE = yylval;
3372 if (PL_lex_starts++) {
3376 sv_free(PL_thistoken);
3377 PL_thistoken = newSVpvn("",0);
3380 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3381 if (!PL_lex_casemods && PL_lex_inpat)
3394 PL_lex_state = LEX_NORMAL;
3395 s = scan_formline(PL_bufptr);
3396 if (!PL_lex_formbrack)
3402 PL_oldoldbufptr = PL_oldbufptr;
3408 sv_free(PL_thistoken);
3411 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3415 if (isIDFIRST_lazy_if(s,UTF))
3417 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3420 goto fake_eof; /* emulate EOF on ^D or ^Z */
3429 if (PL_lex_brackets) {
3430 yyerror(PL_lex_formbrack
3431 ? "Format not terminated"
3432 : "Missing right curly or square bracket");
3434 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3435 "### Tokener got EOF\n");
3439 if (s++ < PL_bufend)
3440 goto retry; /* ignore stray nulls */
3443 if (!PL_in_eval && !PL_preambled) {
3444 PL_preambled = TRUE;
3449 sv_setpv(PL_linestr,incl_perldb());
3450 if (SvCUR(PL_linestr))
3451 sv_catpvs(PL_linestr,";");
3453 while(AvFILLp(PL_preambleav) >= 0) {
3454 SV *tmpsv = av_shift(PL_preambleav);
3455 sv_catsv(PL_linestr, tmpsv);
3456 sv_catpvs(PL_linestr, ";");
3459 sv_free((SV*)PL_preambleav);
3460 PL_preambleav = NULL;
3462 if (PL_minus_n || PL_minus_p) {
3463 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3465 sv_catpvs(PL_linestr,"chomp;");
3468 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3469 || *PL_splitstr == '"')
3470 && strchr(PL_splitstr + 1, *PL_splitstr))
3471 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3473 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3474 bytes can be used as quoting characters. :-) */
3475 const char *splits = PL_splitstr;
3476 sv_catpvs(PL_linestr, "our @F=split(q\0");
3479 if (*splits == '\\')
3480 sv_catpvn(PL_linestr, splits, 1);
3481 sv_catpvn(PL_linestr, splits, 1);
3482 } while (*splits++);
3483 /* This loop will embed the trailing NUL of
3484 PL_linestr as the last thing it does before
3486 sv_catpvs(PL_linestr, ");");
3490 sv_catpvs(PL_linestr,"our @F=split(' ');");
3494 sv_catpvs(PL_linestr,"use feature ':5.10';");
3495 sv_catpvs(PL_linestr, "\n");
3496 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3497 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3498 PL_last_lop = PL_last_uni = NULL;
3499 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3500 SV * const sv = newSV(0);
3502 sv_upgrade(sv, SVt_PVMG);
3503 sv_setsv(sv,PL_linestr);
3506 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3511 bof = PL_rsfp ? TRUE : FALSE;
3512 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3515 PL_realtokenstart = -1;
3518 if (PL_preprocess && !PL_in_eval)
3519 (void)PerlProc_pclose(PL_rsfp);
3520 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3521 PerlIO_clearerr(PL_rsfp);
3523 (void)PerlIO_close(PL_rsfp);
3525 PL_doextract = FALSE;
3527 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3532 sv_setpv(PL_linestr,PL_minus_p
3533 ? ";}continue{print;}" : ";}");
3534 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3535 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3536 PL_last_lop = PL_last_uni = NULL;
3537 PL_minus_n = PL_minus_p = 0;
3540 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3541 PL_last_lop = PL_last_uni = NULL;
3542 sv_setpvn(PL_linestr,"",0);
3543 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3545 /* If it looks like the start of a BOM or raw UTF-16,
3546 * check if it in fact is. */
3552 #ifdef PERLIO_IS_STDIO
3553 # ifdef __GNU_LIBRARY__
3554 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3555 # define FTELL_FOR_PIPE_IS_BROKEN
3559 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3560 # define FTELL_FOR_PIPE_IS_BROKEN
3565 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3566 /* This loses the possibility to detect the bof
3567 * situation on perl -P when the libc5 is being used.
3568 * Workaround? Maybe attach some extra state to PL_rsfp?
3571 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3573 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3576 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3577 s = swallow_bom((U8*)s);
3581 /* Incest with pod. */
3584 sv_catsv(PL_thiswhite, PL_linestr);
3586 if (*s == '=' && strnEQ(s, "=cut", 4)) {
3587 sv_setpvn(PL_linestr, "", 0);
3588 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3589 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3590 PL_last_lop = PL_last_uni = NULL;
3591 PL_doextract = FALSE;
3595 } while (PL_doextract);
3596 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3597 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3598 SV * const sv = newSV(0);
3600 sv_upgrade(sv, SVt_PVMG);
3601 sv_setsv(sv,PL_linestr);
3604 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3606 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3607 PL_last_lop = PL_last_uni = NULL;
3608 if (CopLINE(PL_curcop) == 1) {
3609 while (s < PL_bufend && isSPACE(*s))
3611 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3615 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3619 if (*s == '#' && *(s+1) == '!')
3621 #ifdef ALTERNATE_SHEBANG
3623 static char const as[] = ALTERNATE_SHEBANG;
3624 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3625 d = s + (sizeof(as) - 1);
3627 #endif /* ALTERNATE_SHEBANG */
3636 while (*d && !isSPACE(*d))
3640 #ifdef ARG_ZERO_IS_SCRIPT
3641 if (ipathend > ipath) {
3643 * HP-UX (at least) sets argv[0] to the script name,
3644 * which makes $^X incorrect. And Digital UNIX and Linux,
3645 * at least, set argv[0] to the basename of the Perl
3646 * interpreter. So, having found "#!", we'll set it right.
3648 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3650 assert(SvPOK(x) || SvGMAGICAL(x));
3651 if (sv_eq(x, CopFILESV(PL_curcop))) {
3652 sv_setpvn(x, ipath, ipathend - ipath);
3658 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3659 const char * const lstart = SvPV_const(x,llen);
3661 bstart += blen - llen;
3662 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3663 sv_setpvn(x, ipath, ipathend - ipath);
3668 TAINT_NOT; /* $^X is always tainted, but that's OK */
3670 #endif /* ARG_ZERO_IS_SCRIPT */
3675 d = instr(s,"perl -");
3677 d = instr(s,"perl");
3679 /* avoid getting into infinite loops when shebang
3680 * line contains "Perl" rather than "perl" */
3682 for (d = ipathend-4; d >= ipath; --d) {
3683 if ((*d == 'p' || *d == 'P')
3684 && !ibcmp(d, "perl", 4))
3694 #ifdef ALTERNATE_SHEBANG
3696 * If the ALTERNATE_SHEBANG on this system starts with a
3697 * character that can be part of a Perl expression, then if
3698 * we see it but not "perl", we're probably looking at the
3699 * start of Perl code, not a request to hand off to some
3700 * other interpreter. Similarly, if "perl" is there, but
3701 * not in the first 'word' of the line, we assume the line
3702 * contains the start of the Perl program.
3704 if (d && *s != '#') {
3705 const char *c = ipath;
3706 while (*c && !strchr("; \t\r\n\f\v#", *c))
3709 d = NULL; /* "perl" not in first word; ignore */
3711 *s = '#'; /* Don't try to parse shebang line */
3713 #endif /* ALTERNATE_SHEBANG */
3714 #ifndef MACOS_TRADITIONAL
3719 !instr(s,"indir") &&
3720 instr(PL_origargv[0],"perl"))
3727 while (s < PL_bufend && isSPACE(*s))
3729 if (s < PL_bufend) {
3730 Newxz(newargv,PL_origargc+3,char*);
3732 while (s < PL_bufend && !isSPACE(*s))
3735 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3738 newargv = PL_origargv;
3741 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3743 Perl_croak(aTHX_ "Can't exec %s", ipath);
3747 while (*d && !isSPACE(*d))
3749 while (SPACE_OR_TAB(*d))
3753 const bool switches_done = PL_doswitches;
3754 const U32 oldpdb = PL_perldb;
3755 const bool oldn = PL_minus_n;
3756 const bool oldp = PL_minus_p;
3759 if (*d == 'M' || *d == 'm' || *d == 'C') {
3760 const char * const m = d;
3761 while (*d && !isSPACE(*d))
3763 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3766 d = moreswitches(d);
3768 if (PL_doswitches && !switches_done) {
3769 int argc = PL_origargc;
3770 char **argv = PL_origargv;
3773 } while (argc && argv[0][0] == '-' && argv[0][1]);
3774 init_argv_symbols(argc,argv);
3776 if ((PERLDB_LINE && !oldpdb) ||
3777 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3778 /* if we have already added "LINE: while (<>) {",
3779 we must not do it again */
3781 sv_setpvn(PL_linestr, "", 0);
3782 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3783 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3784 PL_last_lop = PL_last_uni = NULL;
3785 PL_preambled = FALSE;
3787 (void)gv_fetchfile(PL_origfilename);
3794 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3796 PL_lex_state = LEX_FORMLINE;
3801 #ifdef PERL_STRICT_CR
3802 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3804 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3806 case ' ': case '\t': case '\f': case 013:
3807 #ifdef MACOS_TRADITIONAL
3811 PL_realtokenstart = -1;
3820 PL_realtokenstart = -1;
3824 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3825 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3826 /* handle eval qq[#line 1 "foo"\n ...] */
3827 CopLINE_dec(PL_curcop);
3830 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3832 if (!PL_in_eval || PL_rsfp)
3837 while (d < PL_bufend && *d != '\n')
3841 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3842 Perl_croak(aTHX_ "panic: input overflow");
3845 PL_thiswhite = newSVpvn(s, d - s);
3850 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3852 PL_lex_state = LEX_FORMLINE;
3858 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3859 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3862 TOKEN(PEG); /* make sure any #! line is accessible */
3867 /* if (PL_madskills && PL_lex_formbrack) { */
3869 while (d < PL_bufend && *d != '\n')
3873 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3874 Perl_croak(aTHX_ "panic: input overflow");
3875 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3877 PL_thiswhite = newSVpvn("",0);
3878 if (CopLINE(PL_curcop) == 1) {
3879 sv_setpvn(PL_thiswhite, "", 0);
3882 sv_catpvn(PL_thiswhite, s, d - s);
3896 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3904 while (s < PL_bufend && SPACE_OR_TAB(*s))
3907 if (strnEQ(s,"=>",2)) {
3908 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3909 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
3910 OPERATOR('-'); /* unary minus */
3912 PL_last_uni = PL_oldbufptr;
3914 case 'r': ftst = OP_FTEREAD; break;
3915 case 'w': ftst = OP_FTEWRITE; break;
3916 case 'x': ftst = OP_FTEEXEC; break;
3917 case 'o': ftst = OP_FTEOWNED; break;
3918 case 'R': ftst = OP_FTRREAD; break;
3919 case 'W': ftst = OP_FTRWRITE; break;
3920 case 'X': ftst = OP_FTREXEC; break;
3921 case 'O': ftst = OP_FTROWNED; break;
3922 case 'e': ftst = OP_FTIS; break;
3923 case 'z': ftst = OP_FTZERO; break;
3924 case 's': ftst = OP_FTSIZE; break;
3925 case 'f': ftst = OP_FTFILE; break;
3926 case 'd': ftst = OP_FTDIR; break;
3927 case 'l': ftst = OP_FTLINK; break;
3928 case 'p': ftst = OP_FTPIPE; break;
3929 case 'S': ftst = OP_FTSOCK; break;
3930 case 'u': ftst = OP_FTSUID; break;
3931 case 'g': ftst = OP_FTSGID; break;
3932 case 'k': ftst = OP_FTSVTX; break;
3933 case 'b': ftst = OP_FTBLK; break;
3934 case 'c': ftst = OP_FTCHR; break;
3935 case 't': ftst = OP_FTTTY; break;
3936 case 'T': ftst = OP_FTTEXT; break;
3937 case 'B': ftst = OP_FTBINARY; break;
3938 case 'M': case 'A': case 'C':
3939 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
3941 case 'M': ftst = OP_FTMTIME; break;
3942 case 'A': ftst = OP_FTATIME; break;
3943 case 'C': ftst = OP_FTCTIME; break;
3951 PL_last_lop_op = (OPCODE)ftst;
3952 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3953 "### Saw file test %c\n", (int)tmp);
3958 /* Assume it was a minus followed by a one-letter named
3959 * subroutine call (or a -bareword), then. */
3960 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3961 "### '-%c' looked like a file test but was not\n",
3968 const char tmp = *s++;
3971 if (PL_expect == XOPERATOR)
3976 else if (*s == '>') {
3979 if (isIDFIRST_lazy_if(s,UTF)) {
3980 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3988 if (PL_expect == XOPERATOR)
3991 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3993 OPERATOR('-'); /* unary minus */
3999 const char tmp = *s++;
4002 if (PL_expect == XOPERATOR)
4007 if (PL_expect == XOPERATOR)
4010 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4017 if (PL_expect != XOPERATOR) {
4018 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4019 PL_expect = XOPERATOR;
4020 force_ident(PL_tokenbuf, '*');
4033 if (PL_expect == XOPERATOR) {
4037 PL_tokenbuf[0] = '%';
4038 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
4039 if (!PL_tokenbuf[1]) {
4042 PL_pending_ident = '%';
4053 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
4054 && FEATURE_IS_ENABLED("~~"))
4061 const char tmp = *s++;
4067 goto just_a_word_zero_gv;
4070 switch (PL_expect) {
4076 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4078 PL_bufptr = s; /* update in case we back off */
4084 PL_expect = XTERMBLOCK;
4087 stuffstart = s - SvPVX(PL_linestr) - 1;
4091 while (isIDFIRST_lazy_if(s,UTF)) {
4094 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4095 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
4096 if (tmp < 0) tmp = -tmp;
4111 sv = newSVpvn(s, len);
4113 d = scan_str(d,TRUE,TRUE);
4115 /* MUST advance bufptr here to avoid bogus
4116 "at end of line" context messages from yyerror().
4118 PL_bufptr = s + len;
4119 yyerror("Unterminated attribute parameter in attribute list");
4123 return REPORT(0); /* EOF indicator */
4127 sv_catsv(sv, PL_lex_stuff);
4128 attrs = append_elem(OP_LIST, attrs,
4129 newSVOP(OP_CONST, 0, sv));
4130 SvREFCNT_dec(PL_lex_stuff);
4131 PL_lex_stuff = NULL;
4134 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4136 if (PL_in_my == KEY_our) {
4138 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4140 /* skip to avoid loading attributes.pm */
4142 deprecate(":unique");
4145 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4148 /* NOTE: any CV attrs applied here need to be part of
4149 the CVf_BUILTIN_ATTRS define in cv.h! */
4150 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4152 CvLVALUE_on(PL_compcv);
4154 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4156 CvLOCKED_on(PL_compcv);
4158 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4160 CvMETHOD_on(PL_compcv);
4162 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4164 CvASSERTION_on(PL_compcv);
4166 /* After we've set the flags, it could be argued that
4167 we don't need to do the attributes.pm-based setting
4168 process, and shouldn't bother appending recognized
4169 flags. To experiment with that, uncomment the
4170 following "else". (Note that's already been
4171 uncommented. That keeps the above-applied built-in
4172 attributes from being intercepted (and possibly
4173 rejected) by a package's attribute routines, but is
4174 justified by the performance win for the common case
4175 of applying only built-in attributes.) */
4177 attrs = append_elem(OP_LIST, attrs,
4178 newSVOP(OP_CONST, 0,
4182 if (*s == ':' && s[1] != ':')
4185 break; /* require real whitespace or :'s */
4186 /* XXX losing whitespace on sequential attributes here */
4190 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4191 if (*s != ';' && *s != '}' && *s != tmp
4192 && (tmp != '=' || *s != ')')) {
4193 const char q = ((*s == '\'') ? '"' : '\'');
4194 /* If here for an expression, and parsed no attrs, back
4196 if (tmp == '=' && !attrs) {
4200 /* MUST advance bufptr here to avoid bogus "at end of line"
4201 context messages from yyerror().
4205 ? Perl_form(aTHX_ "Invalid separator character "
4206 "%c%c%c in attribute list", q, *s, q)
4207 : "Unterminated attribute list" );
4215 start_force(PL_curforce);
4216 NEXTVAL_NEXTTOKE.opval = attrs;
4217 CURMAD('_', PL_nextwhite);
4222 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4223 (s - SvPVX(PL_linestr)) - stuffstart);
4231 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4232 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4240 const char tmp = *s++;
4245 const char tmp = *s++;
4253 if (PL_lex_brackets <= 0)
4254 yyerror("Unmatched right square bracket");
4257 if (PL_lex_state == LEX_INTERPNORMAL) {
4258 if (PL_lex_brackets == 0) {
4259 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4260 PL_lex_state = LEX_INTERPEND;
4267 if (PL_lex_brackets > 100) {
4268 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4270 switch (PL_expect) {
4272 if (PL_lex_formbrack) {
4276 if (PL_oldoldbufptr == PL_last_lop)
4277 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4279 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4280 OPERATOR(HASHBRACK);
4282 while (s < PL_bufend && SPACE_OR_TAB(*s))
4285 PL_tokenbuf[0] = '\0';
4286 if (d < PL_bufend && *d == '-') {
4287 PL_tokenbuf[0] = '-';
4289 while (d < PL_bufend && SPACE_OR_TAB(*d))
4292 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4293 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4295 while (d < PL_bufend && SPACE_OR_TAB(*d))
4298 const char minus = (PL_tokenbuf[0] == '-');
4299 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4307 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4312 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4317 if (PL_oldoldbufptr == PL_last_lop)
4318 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4320 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4323 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4325 /* This hack is to get the ${} in the message. */
4327 yyerror("syntax error");
4330 OPERATOR(HASHBRACK);
4332 /* This hack serves to disambiguate a pair of curlies
4333 * as being a block or an anon hash. Normally, expectation
4334 * determines that, but in cases where we're not in a
4335 * position to expect anything in particular (like inside
4336 * eval"") we have to resolve the ambiguity. This code
4337 * covers the case where the first term in the curlies is a
4338 * quoted string. Most other cases need to be explicitly
4339 * disambiguated by prepending a "+" before the opening
4340 * curly in order to force resolution as an anon hash.
4342 * XXX should probably propagate the outer expectation
4343 * into eval"" to rely less on this hack, but that could
4344 * potentially break current behavior of eval"".
4348 if (*s == '\'' || *s == '"' || *s == '`') {
4349 /* common case: get past first string, handling escapes */
4350 for (t++; t < PL_bufend && *t != *s;)
4351 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4355 else if (*s == 'q') {
4358 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4361 /* skip q//-like construct */
4363 char open, close, term;
4366 while (t < PL_bufend && isSPACE(*t))
4368 /* check for q => */
4369 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4370 OPERATOR(HASHBRACK);
4374 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4378 for (t++; t < PL_bufend; t++) {
4379 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4381 else if (*t == open)
4385 for (t++; t < PL_bufend; t++) {
4386 if (*t == '\\' && t+1 < PL_bufend)
4388 else if (*t == close && --brackets <= 0)
4390 else if (*t == open)
4397 /* skip plain q word */
4398 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4401 else if (isALNUM_lazy_if(t,UTF)) {
4403 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4406 while (t < PL_bufend && isSPACE(*t))
4408 /* if comma follows first term, call it an anon hash */
4409 /* XXX it could be a comma expression with loop modifiers */
4410 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4411 || (*t == '=' && t[1] == '>')))
4412 OPERATOR(HASHBRACK);
4413 if (PL_expect == XREF)
4416 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4422 yylval.ival = CopLINE(PL_curcop);
4423 if (isSPACE(*s) || *s == '#')
4424 PL_copline = NOLINE; /* invalidate current command line number */
4429 if (PL_lex_brackets <= 0)
4430 yyerror("Unmatched right curly bracket");
4432 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4433 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4434 PL_lex_formbrack = 0;
4435 if (PL_lex_state == LEX_INTERPNORMAL) {
4436 if (PL_lex_brackets == 0) {
4437 if (PL_expect & XFAKEBRACK) {
4438 PL_expect &= XENUMMASK;
4439 PL_lex_state = LEX_INTERPEND;
4444 PL_thiswhite = newSVpvn("",0);
4445 sv_catpvn(PL_thiswhite,"}",1);
4448 return yylex(); /* ignore fake brackets */
4450 if (*s == '-' && s[1] == '>')
4451 PL_lex_state = LEX_INTERPENDMAYBE;
4452 else if (*s != '[' && *s != '{')
4453 PL_lex_state = LEX_INTERPEND;
4456 if (PL_expect & XFAKEBRACK) {
4457 PL_expect &= XENUMMASK;
4459 return yylex(); /* ignore fake brackets */
4461 start_force(PL_curforce);
4463 curmad('X', newSVpvn(s-1,1));
4464 CURMAD('_', PL_thiswhite);
4469 PL_thistoken = newSVpvn("",0);
4477 if (PL_expect == XOPERATOR) {
4478 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4479 && isIDFIRST_lazy_if(s,UTF))
4481 CopLINE_dec(PL_curcop);
4482 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4483 CopLINE_inc(PL_curcop);
4488 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4490 PL_expect = XOPERATOR;
4491 force_ident(PL_tokenbuf, '&');
4495 yylval.ival = (OPpENTERSUB_AMPER<<8);
4507 const char tmp = *s++;
4514 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4515 && strchr("+-*/%.^&|<",tmp))
4516 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4517 "Reversed %c= operator",(int)tmp);
4519 if (PL_expect == XSTATE && isALPHA(tmp) &&
4520 (s == PL_linestart+1 || s[-2] == '\n') )
4522 if (PL_in_eval && !PL_rsfp) {
4527 if (strnEQ(s,"=cut",4)) {
4543 PL_thiswhite = newSVpvn("",0);
4544 sv_catpvn(PL_thiswhite, PL_linestart,
4545 PL_bufend - PL_linestart);
4549 PL_doextract = TRUE;
4553 if (PL_lex_brackets < PL_lex_formbrack) {
4555 #ifdef PERL_STRICT_CR
4556 while (SPACE_OR_TAB(*t))
4558 while (SPACE_OR_TAB(*t) || *t == '\r')
4561 if (*t == '\n' || *t == '#') {
4572 const char tmp = *s++;
4574 /* was this !=~ where !~ was meant?
4575 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4577 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4578 const char *t = s+1;
4580 while (t < PL_bufend && isSPACE(*t))
4583 if (*t == '/' || *t == '?' ||
4584 ((*t == 'm' || *t == 's' || *t == 'y')
4585 && !isALNUM(t[1])) ||
4586 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4587 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4588 "!=~ should be !~");
4598 if (PL_expect != XOPERATOR) {
4599 if (s[1] != '<' && !strchr(s,'>'))
4602 s = scan_heredoc(s);
4604 s = scan_inputsymbol(s);
4605 TERM(sublex_start());
4611 SHop(OP_LEFT_SHIFT);
4625 const char tmp = *s++;
4627 SHop(OP_RIGHT_SHIFT);
4628 else if (tmp == '=')
4637 if (PL_expect == XOPERATOR) {
4638 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4640 deprecate_old(commaless_variable_list);
4641 return REPORT(','); /* grandfather non-comma-format format */
4645 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4646 PL_tokenbuf[0] = '@';
4647 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4648 sizeof PL_tokenbuf - 1, FALSE);
4649 if (PL_expect == XOPERATOR)
4650 no_op("Array length", s);
4651 if (!PL_tokenbuf[1])
4653 PL_expect = XOPERATOR;
4654 PL_pending_ident = '#';
4658 PL_tokenbuf[0] = '$';
4659 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4660 sizeof PL_tokenbuf - 1, FALSE);
4661 if (PL_expect == XOPERATOR)
4663 if (!PL_tokenbuf[1]) {
4665 yyerror("Final $ should be \\$ or $name");
4669 /* This kludge not intended to be bulletproof. */
4670 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4671 yylval.opval = newSVOP(OP_CONST, 0,
4672 newSViv(CopARYBASE_get(&PL_compiling)));
4673 yylval.opval->op_private = OPpCONST_ARYBASE;
4679 const char tmp = *s;
4680 if (PL_lex_state == LEX_NORMAL)
4683 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4684 && intuit_more(s)) {
4686 PL_tokenbuf[0] = '@';
4687 if (ckWARN(WARN_SYNTAX)) {
4690 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4693 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4694 while (t < PL_bufend && *t != ']')
4696 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4697 "Multidimensional syntax %.*s not supported",
4698 (int)((t - PL_bufptr) + 1), PL_bufptr);
4702 else if (*s == '{') {
4704 PL_tokenbuf[0] = '%';
4705 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4706 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4708 char tmpbuf[sizeof PL_tokenbuf];
4711 } while (isSPACE(*t));
4712 if (isIDFIRST_lazy_if(t,UTF)) {
4714 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4718 if (*t == ';' && get_cv(tmpbuf, FALSE))
4719 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4720 "You need to quote \"%s\"",
4727 PL_expect = XOPERATOR;
4728 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4729 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4730 if (!islop || PL_last_lop_op == OP_GREPSTART)
4731 PL_expect = XOPERATOR;
4732 else if (strchr("$@\"'`q", *s))
4733 PL_expect = XTERM; /* e.g. print $fh "foo" */
4734 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4735 PL_expect = XTERM; /* e.g. print $fh &sub */
4736 else if (isIDFIRST_lazy_if(s,UTF)) {
4737 char tmpbuf[sizeof PL_tokenbuf];
4739 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4740 if ((t2 = keyword(tmpbuf, len))) {
4741 /* binary operators exclude handle interpretations */
4753 PL_expect = XTERM; /* e.g. print $fh length() */
4758 PL_expect = XTERM; /* e.g. print $fh subr() */
4761 else if (isDIGIT(*s))
4762 PL_expect = XTERM; /* e.g. print $fh 3 */
4763 else if (*s == '.' && isDIGIT(s[1]))
4764 PL_expect = XTERM; /* e.g. print $fh .3 */
4765 else if ((*s == '?' || *s == '-' || *s == '+')
4766 && !isSPACE(s[1]) && s[1] != '=')
4767 PL_expect = XTERM; /* e.g. print $fh -1 */
4768 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4770 PL_expect = XTERM; /* e.g. print $fh /.../
4771 XXX except DORDOR operator
4773 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4775 PL_expect = XTERM; /* print $fh <<"EOF" */
4778 PL_pending_ident = '$';
4782 if (PL_expect == XOPERATOR)
4784 PL_tokenbuf[0] = '@';
4785 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4786 if (!PL_tokenbuf[1]) {
4789 if (PL_lex_state == LEX_NORMAL)
4791 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4793 PL_tokenbuf[0] = '%';
4795 /* Warn about @ where they meant $. */
4796 if (*s == '[' || *s == '{') {
4797 if (ckWARN(WARN_SYNTAX)) {
4798 const char *t = s + 1;
4799 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4801 if (*t == '}' || *t == ']') {
4803 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4804 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4805 "Scalar value %.*s better written as $%.*s",
4806 (int)(t-PL_bufptr), PL_bufptr,
4807 (int)(t-PL_bufptr-1), PL_bufptr+1);
4812 PL_pending_ident = '@';
4815 case '/': /* may be division, defined-or, or pattern */
4816 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4820 case '?': /* may either be conditional or pattern */
4821 if(PL_expect == XOPERATOR) {
4829 /* A // operator. */
4839 /* Disable warning on "study /blah/" */
4840 if (PL_oldoldbufptr == PL_last_uni
4841 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4842 || memNE(PL_last_uni, "study", 5)
4843 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4846 s = scan_pat(s,OP_MATCH);
4847 TERM(sublex_start());
4851 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4852 #ifdef PERL_STRICT_CR
4855 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4857 && (s == PL_linestart || s[-1] == '\n') )
4859 PL_lex_formbrack = 0;
4863 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4869 yylval.ival = OPf_SPECIAL;
4875 if (PL_expect != XOPERATOR)
4880 case '0': case '1': case '2': case '3': case '4':
4881 case '5': case '6': case '7': case '8': case '9':
4882 s = scan_num(s, &yylval);
4883 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
4884 if (PL_expect == XOPERATOR)
4889 s = scan_str(s,!!PL_madskills,FALSE);
4890 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4891 if (PL_expect == XOPERATOR) {
4892 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4894 deprecate_old(commaless_variable_list);
4895 return REPORT(','); /* grandfather non-comma-format format */
4902 yylval.ival = OP_CONST;
4903 TERM(sublex_start());
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 /* FIXME. I think that this can be const if char *d is replaced by
4921 more localised variables. */
4922 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4923 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4924 yylval.ival = OP_STRINGIFY;
4928 TERM(sublex_start());
4931 s = scan_str(s,!!PL_madskills,FALSE);
4932 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
4933 if (PL_expect == XOPERATOR)
4934 no_op("Backticks",s);
4937 yylval.ival = OP_BACKTICK;
4939 TERM(sublex_start());
4943 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
4944 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
4946 if (PL_expect == XOPERATOR)
4947 no_op("Backslash",s);
4951 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
4952 char *start = s + 2;
4953 while (isDIGIT(*start) || *start == '_')
4955 if (*start == '.' && isDIGIT(start[1])) {
4956 s = scan_num(s, &yylval);
4959 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
4960 else if (!isALPHA(*start) && (PL_expect == XTERM
4961 || PL_expect == XREF || PL_expect == XSTATE
4962 || PL_expect == XTERMORDORDOR)) {
4963 /* XXX Use gv_fetchpvn rather than stomping on a const string */
4964 const char c = *start;
4967 gv = gv_fetchpv(s, 0, SVt_PVCV);
4970 s = scan_num(s, &yylval);
4977 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5013 I32 orig_keyword = 0;
5018 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5020 /* Some keywords can be followed by any delimiter, including ':' */
5021 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5022 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5023 (PL_tokenbuf[0] == 'q' &&
5024 strchr("qwxr", PL_tokenbuf[1])))));
5026 /* x::* is just a word, unless x is "CORE" */
5027 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5031 while (d < PL_bufend && isSPACE(*d))
5032 d++; /* no comments skipped here, or s### is misparsed */
5034 /* Is this a label? */
5035 if (!tmp && PL_expect == XSTATE
5036 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5038 yylval.pval = savepv(PL_tokenbuf);
5043 /* Check for keywords */
5044 tmp = keyword(PL_tokenbuf, len);
5046 /* Is this a word before a => operator? */
5047 if (*d == '=' && d[1] == '>') {
5050 = (OP*)newSVOP(OP_CONST, 0,
5051 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5052 yylval.opval->op_private = OPpCONST_BARE;
5056 if (tmp < 0) { /* second-class keyword? */
5057 GV *ogv = NULL; /* override (winner) */
5058 GV *hgv = NULL; /* hidden (loser) */
5059 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5061 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5064 if (GvIMPORTED_CV(gv))
5066 else if (! CvMETHOD(cv))
5070 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5071 (gv = *gvp) != (GV*)&PL_sv_undef &&
5072 GvCVu(gv) && GvIMPORTED_CV(gv))
5079 tmp = 0; /* overridden by import or by GLOBAL */
5082 && -tmp==KEY_lock /* XXX generalizable kludge */
5084 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
5086 tmp = 0; /* any sub overrides "weak" keyword */
5088 else { /* no override */
5090 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5091 Perl_warner(aTHX_ packWARN(WARN_MISC),
5092 "dump() better written as CORE::dump()");
5096 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5097 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5098 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5099 "Ambiguous call resolved as CORE::%s(), %s",
5100 GvENAME(hgv), "qualify as such or use &");
5107 default: /* not a keyword */
5108 /* Trade off - by using this evil construction we can pull the
5109 variable gv into the block labelled keylookup. If not, then
5110 we have to give it function scope so that the goto from the
5111 earlier ':' case doesn't bypass the initialisation. */
5113 just_a_word_zero_gv:
5121 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5124 SV *nextPL_nextwhite = 0;
5128 /* Get the rest if it looks like a package qualifier */
5130 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5132 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5135 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5136 *s == '\'' ? "'" : "::");
5141 if (PL_expect == XOPERATOR) {
5142 if (PL_bufptr == PL_linestart) {
5143 CopLINE_dec(PL_curcop);
5144 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5145 CopLINE_inc(PL_curcop);
5148 no_op("Bareword",s);
5151 /* Look for a subroutine with this name in current package,
5152 unless name is "Foo::", in which case Foo is a bearword
5153 (and a package name). */
5155 if (len > 2 && !PL_madskills &&
5156 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5158 if (ckWARN(WARN_BAREWORD)
5159 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5160 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5161 "Bareword \"%s\" refers to nonexistent package",
5164 PL_tokenbuf[len] = '\0';
5170 /* Mustn't actually add anything to a symbol table.
5171 But also don't want to "initialise" any placeholder
5172 constants that might already be there into full
5173 blown PVGVs with attached PVCV. */
5174 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5175 GV_NOADD_NOINIT, SVt_PVCV);
5180 /* if we saw a global override before, get the right name */
5183 sv = newSVpvs("CORE::GLOBAL::");
5184 sv_catpv(sv,PL_tokenbuf);
5187 /* If len is 0, newSVpv does strlen(), which is correct.
5188 If len is non-zero, then it will be the true length,
5189 and so the scalar will be created correctly. */
5190 sv = newSVpv(PL_tokenbuf,len);
5193 if (PL_madskills && !PL_thistoken) {
5194 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5195 PL_thistoken = newSVpv(start,s - start);
5196 PL_realtokenstart = s - SvPVX(PL_linestr);
5200 /* Presume this is going to be a bareword of some sort. */
5203 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5204 yylval.opval->op_private = OPpCONST_BARE;
5205 /* UTF-8 package name? */
5206 if (UTF && !IN_BYTES &&
5207 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5210 /* And if "Foo::", then that's what it certainly is. */
5215 /* Do the explicit type check so that we don't need to force
5216 the initialisation of the symbol table to have a real GV.
5217 Beware - gv may not really be a PVGV, cv may not really be
5218 a PVCV, (because of the space optimisations that gv_init
5219 understands) But they're true if for this symbol there is
5220 respectively a typeglob and a subroutine.
5222 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5223 /* Real typeglob, so get the real subroutine: */
5225 /* A proxy for a subroutine in this package? */
5226 : SvOK(gv) ? (CV *) gv : NULL)
5229 /* See if it's the indirect object for a list operator. */
5231 if (PL_oldoldbufptr &&
5232 PL_oldoldbufptr < PL_bufptr &&
5233 (PL_oldoldbufptr == PL_last_lop
5234 || PL_oldoldbufptr == PL_last_uni) &&
5235 /* NO SKIPSPACE BEFORE HERE! */
5236 (PL_expect == XREF ||
5237 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5239 bool immediate_paren = *s == '(';
5241 /* (Now we can afford to cross potential line boundary.) */
5242 s = SKIPSPACE2(s,nextPL_nextwhite);
5244 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5247 /* Two barewords in a row may indicate method call. */
5249 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5250 (tmp = intuit_method(s, gv, cv)))
5253 /* If not a declared subroutine, it's an indirect object. */
5254 /* (But it's an indir obj regardless for sort.) */
5255 /* Also, if "_" follows a filetest operator, it's a bareword */
5258 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5260 (PL_last_lop_op != OP_MAPSTART &&
5261 PL_last_lop_op != OP_GREPSTART))))
5262 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5263 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5266 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5271 PL_expect = XOPERATOR;
5274 s = SKIPSPACE2(s,nextPL_nextwhite);
5275 PL_nextwhite = nextPL_nextwhite;
5280 /* Is this a word before a => operator? */
5281 if (*s == '=' && s[1] == '>' && !pkgname) {
5283 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5284 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5285 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5289 /* If followed by a paren, it's certainly a subroutine. */
5294 while (SPACE_OR_TAB(*d))
5296 if (*d == ')' && (sv = gv_const_sv(gv))) {
5300 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5301 sv_catpvn(PL_thistoken, par, s - par);
5303 sv_free(PL_nextwhite);
5313 PL_nextwhite = PL_thiswhite;
5316 start_force(PL_curforce);
5318 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5319 PL_expect = XOPERATOR;
5322 PL_nextwhite = nextPL_nextwhite;
5323 curmad('X', PL_thistoken);
5324 PL_thistoken = newSVpvn("",0);
5332 /* If followed by var or block, call it a method (unless sub) */
5334 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5335 PL_last_lop = PL_oldbufptr;
5336 PL_last_lop_op = OP_METHOD;
5340 /* If followed by a bareword, see if it looks like indir obj. */
5343 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5344 && (tmp = intuit_method(s, gv, cv)))
5347 /* Not a method, so call it a subroutine (if defined) */
5350 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5351 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5352 "Ambiguous use of -%s resolved as -&%s()",
5353 PL_tokenbuf, PL_tokenbuf);
5354 /* Check for a constant sub */
5355 if ((sv = gv_const_sv(gv))) {
5357 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5358 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5359 yylval.opval->op_private = 0;
5363 /* Resolve to GV now. */
5364 if (SvTYPE(gv) != SVt_PVGV) {
5365 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5366 assert (SvTYPE(gv) == SVt_PVGV);
5367 /* cv must have been some sort of placeholder, so
5368 now needs replacing with a real code reference. */
5372 op_free(yylval.opval);
5373 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5374 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5375 PL_last_lop = PL_oldbufptr;
5376 PL_last_lop_op = OP_ENTERSUB;
5377 /* Is there a prototype? */
5384 const char *proto = SvPV_const((SV*)cv, protolen);
5387 if (*proto == '$' && proto[1] == '\0')
5389 while (*proto == ';')
5391 if (*proto == '&' && *s == '{') {
5392 sv_setpv(PL_subname, PL_curstash ?
5393 "__ANON__" : "__ANON__::__ANON__");
5400 PL_nextwhite = PL_thiswhite;
5403 start_force(PL_curforce);
5404 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5407 PL_nextwhite = nextPL_nextwhite;
5408 curmad('X', PL_thistoken);
5409 PL_thistoken = newSVpvn("",0);
5416 /* Guess harder when madskills require "best effort". */
5417 if (PL_madskills && (!gv || !GvCVu(gv))) {
5418 int probable_sub = 0;
5419 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5421 else if (isALPHA(*s)) {
5425 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5426 if (!keyword(tmpbuf,tmplen))
5429 while (d < PL_bufend && isSPACE(*d))
5431 if (*d == '=' && d[1] == '>')
5436 gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5437 op_free(yylval.opval);
5438 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5439 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5440 PL_last_lop = PL_oldbufptr;
5441 PL_last_lop_op = OP_ENTERSUB;
5442 PL_nextwhite = PL_thiswhite;
5444 start_force(PL_curforce);
5445 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5447 PL_nextwhite = nextPL_nextwhite;
5448 curmad('X', PL_thistoken);
5449 PL_thistoken = newSVpvn("",0);
5454 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5461 /* Call it a bare word */
5463 if (PL_hints & HINT_STRICT_SUBS)
5464 yylval.opval->op_private |= OPpCONST_STRICT;
5467 if (lastchar != '-') {
5468 if (ckWARN(WARN_RESERVED)) {
5472 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
5473 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5480 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5481 && ckWARN_d(WARN_AMBIGUOUS)) {
5482 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5483 "Operator or semicolon missing before %c%s",
5484 lastchar, PL_tokenbuf);
5485 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5486 "Ambiguous use of %c resolved as operator %c",
5487 lastchar, lastchar);
5493 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5494 newSVpv(CopFILE(PL_curcop),0));
5498 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5499 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5502 case KEY___PACKAGE__:
5503 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5505 ? newSVhek(HvNAME_HEK(PL_curstash))
5512 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5513 const char *pname = "main";
5514 if (PL_tokenbuf[2] == 'D')
5515 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5516 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5520 GvIOp(gv) = newIO();
5521 IoIFP(GvIOp(gv)) = PL_rsfp;
5522 #if defined(HAS_FCNTL) && defined(F_SETFD)
5524 const int fd = PerlIO_fileno(PL_rsfp);
5525 fcntl(fd,F_SETFD,fd >= 3);
5528 /* Mark this internal pseudo-handle as clean */
5529 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5531 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5532 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5533 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5535 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5536 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5537 /* if the script was opened in binmode, we need to revert
5538 * it to text mode for compatibility; but only iff it has CRs
5539 * XXX this is a questionable hack at best. */
5540 if (PL_bufend-PL_bufptr > 2
5541 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5544 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5545 loc = PerlIO_tell(PL_rsfp);
5546 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5549 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5551 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5552 #endif /* NETWARE */
5553 #ifdef PERLIO_IS_STDIO /* really? */
5554 # if defined(__BORLANDC__)
5555 /* XXX see note in do_binmode() */
5556 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5560 PerlIO_seek(PL_rsfp, loc, 0);
5564 #ifdef PERLIO_LAYERS
5567 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5568 else if (PL_encoding) {
5575 XPUSHs(PL_encoding);
5577 call_method("name", G_SCALAR);
5581 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5582 Perl_form(aTHX_ ":encoding(%"SVf")",
5591 if (PL_realtokenstart >= 0) {
5592 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5594 PL_endwhite = newSVpvn("",0);
5595 sv_catsv(PL_endwhite, PL_thiswhite);
5597 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5598 PL_realtokenstart = -1;
5600 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5601 SvCUR(PL_endwhite))) != Nullch) ;
5615 if (PL_expect == XSTATE) {
5622 if (*s == ':' && s[1] == ':') {
5625 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5626 if (!(tmp = keyword(PL_tokenbuf, len)))
5627 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5630 else if (tmp == KEY_require || tmp == KEY_do)
5631 /* that's a way to remember we saw "CORE::" */
5644 LOP(OP_ACCEPT,XTERM);
5650 LOP(OP_ATAN2,XTERM);
5656 LOP(OP_BINMODE,XTERM);
5659 LOP(OP_BLESS,XTERM);
5668 /* When 'use switch' is in effect, continue has a dual
5669 life as a control operator. */
5671 if (!FEATURE_IS_ENABLED("switch"))
5674 /* We have to disambiguate the two senses of
5675 "continue". If the next token is a '{' then
5676 treat it as the start of a continue block;
5677 otherwise treat it as a control operator.
5689 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5706 if (!PL_cryptseen) {
5707 PL_cryptseen = TRUE;
5711 LOP(OP_CRYPT,XTERM);
5714 LOP(OP_CHMOD,XTERM);
5717 LOP(OP_CHOWN,XTERM);
5720 LOP(OP_CONNECT,XTERM);
5739 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5740 if (orig_keyword == KEY_do) {
5749 PL_hints |= HINT_BLOCK_SCOPE;
5759 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5760 LOP(OP_DBMOPEN,XTERM);
5766 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5773 yylval.ival = CopLINE(PL_curcop);
5789 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5790 UNIBRACK(OP_ENTEREVAL);
5808 case KEY_endhostent:
5814 case KEY_endservent:
5817 case KEY_endprotoent:
5828 yylval.ival = CopLINE(PL_curcop);
5830 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5833 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5836 if ((PL_bufend - p) >= 3 &&
5837 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5839 else if ((PL_bufend - p) >= 4 &&
5840 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5843 if (isIDFIRST_lazy_if(p,UTF)) {
5844 p = scan_ident(p, PL_bufend,
5845 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5849 Perl_croak(aTHX_ "Missing $ on loop variable");
5851 s = SvPVX(PL_linestr) + soff;
5857 LOP(OP_FORMLINE,XTERM);
5863 LOP(OP_FCNTL,XTERM);
5869 LOP(OP_FLOCK,XTERM);
5878 LOP(OP_GREPSTART, XREF);
5881 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5896 case KEY_getpriority:
5897 LOP(OP_GETPRIORITY,XTERM);
5899 case KEY_getprotobyname:
5902 case KEY_getprotobynumber:
5903 LOP(OP_GPBYNUMBER,XTERM);
5905 case KEY_getprotoent:
5917 case KEY_getpeername:
5918 UNI(OP_GETPEERNAME);
5920 case KEY_gethostbyname:
5923 case KEY_gethostbyaddr:
5924 LOP(OP_GHBYADDR,XTERM);
5926 case KEY_gethostent:
5929 case KEY_getnetbyname:
5932 case KEY_getnetbyaddr:
5933 LOP(OP_GNBYADDR,XTERM);
5938 case KEY_getservbyname:
5939 LOP(OP_GSBYNAME,XTERM);
5941 case KEY_getservbyport:
5942 LOP(OP_GSBYPORT,XTERM);
5944 case KEY_getservent:
5947 case KEY_getsockname:
5948 UNI(OP_GETSOCKNAME);
5950 case KEY_getsockopt:
5951 LOP(OP_GSOCKOPT,XTERM);
5966 yylval.ival = CopLINE(PL_curcop);
5977 yylval.ival = CopLINE(PL_curcop);
5981 LOP(OP_INDEX,XTERM);
5987 LOP(OP_IOCTL,XTERM);
5999 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6031 LOP(OP_LISTEN,XTERM);
6040 s = scan_pat(s,OP_MATCH);
6041 TERM(sublex_start());
6044 LOP(OP_MAPSTART, XREF);
6047 LOP(OP_MKDIR,XTERM);
6050 LOP(OP_MSGCTL,XTERM);
6053 LOP(OP_MSGGET,XTERM);
6056 LOP(OP_MSGRCV,XTERM);
6059 LOP(OP_MSGSND,XTERM);
6066 if (isIDFIRST_lazy_if(s,UTF)) {
6070 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6071 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6073 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6074 if (!PL_in_my_stash) {
6077 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6081 if (PL_madskills) { /* just add type to declarator token */
6082 sv_catsv(PL_thistoken, PL_nextwhite);
6084 sv_catpvn(PL_thistoken, start, s - start);
6092 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6099 s = tokenize_use(0, s);
6103 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6110 if (isIDFIRST_lazy_if(s,UTF)) {
6112 for (d = s; isALNUM_lazy_if(d,UTF);)
6114 for (t=d; isSPACE(*t);)
6116 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6118 && !(t[0] == '=' && t[1] == '>')
6120 int parms_len = (int)(d-s);
6121 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6122 "Precedence problem: open %.*s should be open(%.*s)",
6123 parms_len, s, parms_len, s);
6129 yylval.ival = OP_OR;
6139 LOP(OP_OPEN_DIR,XTERM);
6142 checkcomma(s,PL_tokenbuf,"filehandle");
6146 checkcomma(s,PL_tokenbuf,"filehandle");
6165 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6169 LOP(OP_PIPE_OP,XTERM);
6172 s = scan_str(s,!!PL_madskills,FALSE);
6175 yylval.ival = OP_CONST;
6176 TERM(sublex_start());
6182 s = scan_str(s,!!PL_madskills,FALSE);
6185 PL_expect = XOPERATOR;
6187 if (SvCUR(PL_lex_stuff)) {
6190 d = SvPV_force(PL_lex_stuff, len);
6192 for (; isSPACE(*d) && len; --len, ++d)
6197 if (!warned && ckWARN(WARN_QW)) {
6198 for (; !isSPACE(*d) && len; --len, ++d) {
6200 Perl_warner(aTHX_ packWARN(WARN_QW),
6201 "Possible attempt to separate words with commas");
6204 else if (*d == '#') {
6205 Perl_warner(aTHX_ packWARN(WARN_QW),
6206 "Possible attempt to put comments in qw() list");
6212 for (; !isSPACE(*d) && len; --len, ++d)
6215 sv = newSVpvn(b, d-b);
6216 if (DO_UTF8(PL_lex_stuff))
6218 words = append_elem(OP_LIST, words,
6219 newSVOP(OP_CONST, 0, tokeq(sv)));
6223 start_force(PL_curforce);
6224 NEXTVAL_NEXTTOKE.opval = words;
6229 SvREFCNT_dec(PL_lex_stuff);
6230 PL_lex_stuff = NULL;
6236 s = scan_str(s,!!PL_madskills,FALSE);
6239 yylval.ival = OP_STRINGIFY;
6240 if (SvIVX(PL_lex_stuff) == '\'')
6241 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6242 TERM(sublex_start());
6245 s = scan_pat(s,OP_QR);
6246 TERM(sublex_start());
6249 s = scan_str(s,!!PL_madskills,FALSE);
6252 yylval.ival = OP_BACKTICK;
6254 TERM(sublex_start());
6262 s = force_version(s, FALSE);
6264 else if (*s != 'v' || !isDIGIT(s[1])
6265 || (s = force_version(s, TRUE), *s == 'v'))
6267 *PL_tokenbuf = '\0';
6268 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6269 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6270 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6272 yyerror("<> should be quotes");
6274 if (orig_keyword == KEY_require) {
6282 PL_last_uni = PL_oldbufptr;
6283 PL_last_lop_op = OP_REQUIRE;
6285 return REPORT( (int)REQUIRE );
6291 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6295 LOP(OP_RENAME,XTERM);
6304 LOP(OP_RINDEX,XTERM);
6314 UNIDOR(OP_READLINE);
6327 LOP(OP_REVERSE,XTERM);
6330 UNIDOR(OP_READLINK);
6338 TERM(sublex_start());
6340 TOKEN(1); /* force error */
6343 checkcomma(s,PL_tokenbuf,"filehandle");
6353 LOP(OP_SELECT,XTERM);
6359 LOP(OP_SEMCTL,XTERM);
6362 LOP(OP_SEMGET,XTERM);
6365 LOP(OP_SEMOP,XTERM);
6371 LOP(OP_SETPGRP,XTERM);
6373 case KEY_setpriority:
6374 LOP(OP_SETPRIORITY,XTERM);
6376 case KEY_sethostent:
6382 case KEY_setservent:
6385 case KEY_setprotoent:
6395 LOP(OP_SEEKDIR,XTERM);
6397 case KEY_setsockopt:
6398 LOP(OP_SSOCKOPT,XTERM);
6404 LOP(OP_SHMCTL,XTERM);
6407 LOP(OP_SHMGET,XTERM);
6410 LOP(OP_SHMREAD,XTERM);
6413 LOP(OP_SHMWRITE,XTERM);
6416 LOP(OP_SHUTDOWN,XTERM);
6425 LOP(OP_SOCKET,XTERM);
6427 case KEY_socketpair:
6428 LOP(OP_SOCKPAIR,XTERM);
6431 checkcomma(s,PL_tokenbuf,"subroutine name");
6433 if (*s == ';' || *s == ')') /* probably a close */
6434 Perl_croak(aTHX_ "sort is now a reserved word");
6436 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6440 LOP(OP_SPLIT,XTERM);
6443 LOP(OP_SPRINTF,XTERM);
6446 LOP(OP_SPLICE,XTERM);
6461 LOP(OP_SUBSTR,XTERM);
6467 char tmpbuf[sizeof PL_tokenbuf];
6468 SSize_t tboffset = 0;
6469 expectation attrful;
6470 bool have_name, have_proto, bad_proto;
6471 const int key = tmp;
6476 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6477 SV *subtoken = newSVpvn(tstart, s - tstart);
6481 s = SKIPSPACE2(s,tmpwhite);
6486 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6487 (*s == ':' && s[1] == ':'))
6494 attrful = XATTRBLOCK;
6495 /* remember buffer pos'n for later force_word */
6496 tboffset = s - PL_oldbufptr;
6497 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6500 nametoke = newSVpvn(s, d - s);
6502 if (strchr(tmpbuf, ':'))
6503 sv_setpv(PL_subname, tmpbuf);
6505 sv_setsv(PL_subname,PL_curstname);
6506 sv_catpvs(PL_subname,"::");
6507 sv_catpvn(PL_subname,tmpbuf,len);
6514 CURMAD('X', nametoke);
6515 CURMAD('_', tmpwhite);
6516 (void) force_word(PL_oldbufptr + tboffset, WORD,
6519 s = SKIPSPACE2(d,tmpwhite);
6526 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6527 PL_expect = XTERMBLOCK;
6528 attrful = XATTRTERM;
6529 sv_setpvn(PL_subname,"?",1);
6533 if (key == KEY_format) {
6535 PL_lex_formbrack = PL_lex_brackets + 1;
6537 PL_thistoken = subtoken;
6541 (void) force_word(PL_oldbufptr + tboffset, WORD,
6547 /* Look for a prototype */
6551 s = scan_str(s,!!PL_madskills,FALSE);
6553 Perl_croak(aTHX_ "Prototype not terminated");
6554 /* strip spaces and check for bad characters */
6555 d = SvPVX(PL_lex_stuff);
6558 for (p = d; *p; ++p) {
6561 if (!strchr("$@%*;[]&\\", *p))
6566 if (bad_proto && ckWARN(WARN_SYNTAX))
6567 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6568 "Illegal character in prototype for %"SVf" : %s",
6569 (void*)PL_subname, d);
6570 SvCUR_set(PL_lex_stuff, tmp);
6575 CURMAD('q', PL_thisopen);
6576 CURMAD('_', tmpwhite);
6577 CURMAD('=', PL_thisstuff);
6578 CURMAD('Q', PL_thisclose);
6579 NEXTVAL_NEXTTOKE.opval =
6580 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6581 PL_lex_stuff = Nullsv;
6584 s = SKIPSPACE2(s,tmpwhite);
6592 if (*s == ':' && s[1] != ':')
6593 PL_expect = attrful;
6594 else if (*s != '{' && key == KEY_sub) {
6596 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6598 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, (void*)PL_subname);
6605 curmad('^', newSVpvn("",0));
6606 CURMAD('_', tmpwhite);
6610 PL_thistoken = subtoken;
6613 NEXTVAL_NEXTTOKE.opval =
6614 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6615 PL_lex_stuff = NULL;
6620 sv_setpv(PL_subname,
6621 PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
6625 (void) force_word(PL_oldbufptr + tboffset, WORD,
6635 LOP(OP_SYSTEM,XREF);
6638 LOP(OP_SYMLINK,XTERM);
6641 LOP(OP_SYSCALL,XTERM);
6644 LOP(OP_SYSOPEN,XTERM);
6647 LOP(OP_SYSSEEK,XTERM);
6650 LOP(OP_SYSREAD,XTERM);
6653 LOP(OP_SYSWRITE,XTERM);
6657 TERM(sublex_start());
6678 LOP(OP_TRUNCATE,XTERM);
6690 yylval.ival = CopLINE(PL_curcop);
6694 yylval.ival = CopLINE(PL_curcop);
6698 LOP(OP_UNLINK,XTERM);
6704 LOP(OP_UNPACK,XTERM);
6707 LOP(OP_UTIME,XTERM);
6713 LOP(OP_UNSHIFT,XTERM);
6716 s = tokenize_use(1, s);
6726 yylval.ival = CopLINE(PL_curcop);
6730 yylval.ival = CopLINE(PL_curcop);
6734 PL_hints |= HINT_BLOCK_SCOPE;
6741 LOP(OP_WAITPID,XTERM);
6750 ctl_l[0] = toCTRL('L');
6752 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6755 /* Make sure $^L is defined */
6756 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6761 if (PL_expect == XOPERATOR)
6767 yylval.ival = OP_XOR;
6772 TERM(sublex_start());
6777 #pragma segment Main
6781 S_pending_ident(pTHX)
6786 /* pit holds the identifier we read and pending_ident is reset */
6787 char pit = PL_pending_ident;
6788 PL_pending_ident = 0;
6790 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6791 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6792 "### Pending identifier '%s'\n", PL_tokenbuf); });
6794 /* if we're in a my(), we can't allow dynamics here.
6795 $foo'bar has already been turned into $foo::bar, so
6796 just check for colons.
6798 if it's a legal name, the OP is a PADANY.
6801 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6802 if (strchr(PL_tokenbuf,':'))
6803 yyerror(Perl_form(aTHX_ "No package name allowed for "
6804 "variable %s in \"our\"",
6806 tmp = allocmy(PL_tokenbuf);
6809 if (strchr(PL_tokenbuf,':'))
6810 yyerror(Perl_form(aTHX_ PL_no_myglob,
6811 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6813 yylval.opval = newOP(OP_PADANY, 0);
6814 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6820 build the ops for accesses to a my() variable.
6822 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6823 then used in a comparison. This catches most, but not
6824 all cases. For instance, it catches
6825 sort { my($a); $a <=> $b }
6827 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6828 (although why you'd do that is anyone's guess).
6831 if (!strchr(PL_tokenbuf,':')) {
6833 tmp = pad_findmy(PL_tokenbuf);
6834 if (tmp != NOT_IN_PAD) {
6835 /* might be an "our" variable" */
6836 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6837 /* build ops for a bareword */
6838 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6839 HEK * const stashname = HvNAME_HEK(stash);
6840 SV * const sym = newSVhek(stashname);
6841 sv_catpvs(sym, "::");
6842 sv_catpv(sym, PL_tokenbuf+1);
6843 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6844 yylval.opval->op_private = OPpCONST_ENTERED;
6847 ? (GV_ADDMULTI | GV_ADDINEVAL)
6850 ((PL_tokenbuf[0] == '$') ? SVt_PV
6851 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6856 /* if it's a sort block and they're naming $a or $b */
6857 if (PL_last_lop_op == OP_SORT &&
6858 PL_tokenbuf[0] == '$' &&
6859 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6862 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6863 d < PL_bufend && *d != '\n';
6866 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6867 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6873 yylval.opval = newOP(OP_PADANY, 0);
6874 yylval.opval->op_targ = tmp;
6880 Whine if they've said @foo in a doublequoted string,
6881 and @foo isn't a variable we can find in the symbol
6884 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6885 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6886 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6887 && ckWARN(WARN_AMBIGUOUS))
6889 /* Downgraded from fatal to warning 20000522 mjd */
6890 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6891 "Possible unintended interpolation of %s in string",
6896 /* build ops for a bareword */
6897 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6898 yylval.opval->op_private = OPpCONST_ENTERED;
6901 /* If the identifier refers to a stash, don't autovivify it.
6902 * Change 24660 had the side effect of causing symbol table
6903 * hashes to always be defined, even if they were freshly
6904 * created and the only reference in the entire program was
6905 * the single statement with the defined %foo::bar:: test.
6906 * It appears that all code in the wild doing this actually
6907 * wants to know whether sub-packages have been loaded, so
6908 * by avoiding auto-vivifying symbol tables, we ensure that
6909 * defined %foo::bar:: continues to be false, and the existing
6910 * tests still give the expected answers, even though what
6911 * they're actually testing has now changed subtly.
6913 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6915 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
6916 ((PL_tokenbuf[0] == '$') ? SVt_PV
6917 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6923 * The following code was generated by perl_keyword.pl.
6927 Perl_keyword (pTHX_ const char *name, I32 len)
6932 case 1: /* 5 tokens of length 1 */
6964 case 2: /* 18 tokens of length 2 */
7110 case 3: /* 29 tokens of length 3 */
7114 if (name[1] == 'N' &&
7177 if (name[1] == 'i' &&
7199 return (FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7217 if (name[1] == 'o' &&
7226 if (name[1] == 'e' &&
7235 if (name[1] == 'n' &&
7244 if (name[1] == 'o' &&
7253 if (name[1] == 'a' &&
7262 if (name[1] == 'o' &&
7324 if (name[1] == 'e' &&
7338 return (FEATURE_IS_ENABLED("say") ? -KEY_say : 0);
7364 if (name[1] == 'i' &&
7373 if (name[1] == 's' &&
7382 if (name[1] == 'e' &&
7391 if (name[1] == 'o' &&
7403 case 4: /* 41 tokens of length 4 */
7407 if (name[1] == 'O' &&
7417 if (name[1] == 'N' &&
7427 if (name[1] == 'i' &&
7437 if (name[1] == 'h' &&
7447 if (name[1] == 'u' &&
7460 if (name[2] == 'c' &&
7469 if (name[2] == 's' &&
7478 if (name[2] == 'a' &&
7514 if (name[1] == 'o' &&
7527 if (name[2] == 't' &&
7536 if (name[2] == 'o' &&
7545 if (name[2] == 't' &&
7554 if (name[2] == 'e' &&
7567 if (name[1] == 'o' &&
7580 if (name[2] == 'y' &&
7589 if (name[2] == 'l' &&
7605 if (name[2] == 's' &&
7614 if (name[2] == 'n' &&
7623 if (name[2] == 'c' &&
7636 if (name[1] == 'e' &&
7646 if (name[1] == 'p' &&
7659 if (name[2] == 'c' &&
7668 if (name[2] == 'p' &&
7677 if (name[2] == 's' &&
7693 if (name[2] == 'n' &&
7763 if (name[2] == 'r' &&
7772 if (name[2] == 'r' &&
7781 if (name[2] == 'a' &&
7797 if (name[2] == 'l' &&
7859 if (name[2] == 'e' &&
7862 return (FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7875 case 5: /* 39 tokens of length 5 */
7879 if (name[1] == 'E' &&
7890 if (name[1] == 'H' &&
7904 if (name[2] == 'a' &&
7914 if (name[2] == 'a' &&
7931 if (name[2] == 'e' &&
7941 if (name[2] == 'e' &&
7945 return (FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
7961 if (name[3] == 'i' &&
7970 if (name[3] == 'o' &&
8006 if (name[2] == 'o' &&
8016 if (name[2] == 'y' &&
8030 if (name[1] == 'l' &&
8044 if (name[2] == 'n' &&
8054 if (name[2] == 'o' &&
8068 if (name[1] == 'i' &&
8073 return (FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8082 if (name[2] == 'd' &&
8092 if (name[2] == 'c' &&
8109 if (name[2] == 'c' &&
8119 if (name[2] == 't' &&
8133 if (name[1] == 'k' &&
8144 if (name[1] == 'r' &&
8158 if (name[2] == 's' &&
8168 if (name[2] == 'd' &&
8185 if (name[2] == 'm' &&
8195 if (name[2] == 'i' &&
8205 if (name[2] == 'e' &&
8215 if (name[2] == 'l' &&
8225 if (name[2] == 'a' &&
8238 if (name[3] == 't' &&
8241 return (FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8247 if (name[3] == 'd' &&
8264 if (name[1] == 'i' &&
8278 if (name[2] == 'a' &&
8291 if (name[3] == 'e' &&
8326 if (name[2] == 'i' &&
8343 if (name[2] == 'i' &&
8353 if (name[2] == 'i' &&
8370 case 6: /* 33 tokens of length 6 */
8374 if (name[1] == 'c' &&
8389 if (name[2] == 'l' &&
8400 if (name[2] == 'r' &&
8415 if (name[1] == 'e' &&
8430 if (name[2] == 's' &&
8435 if(ckWARN_d(WARN_SYNTAX))
8436 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8442 if (name[2] == 'i' &&
8460 if (name[2] == 'l' &&
8471 if (name[2] == 'r' &&
8486 if (name[1] == 'm' &&
8501 if (name[2] == 'n' &&
8512 if (name[2] == 's' &&
8527 if (name[1] == 's' &&
8533 if (name[4] == 't' &&
8542 if (name[4] == 'e' &&
8551 if (name[4] == 'c' &&
8560 if (name[4] == 'n' &&
8576 if (name[1] == 'r' &&
8594 if (name[3] == 'a' &&
8604 if (name[3] == 'u' &&
8618 if (name[2] == 'n' &&
8636 if (name[2] == 'a' &&
8650 if (name[3] == 'e' &&
8663 if (name[4] == 't' &&
8672 if (name[4] == 'e' &&
8694 if (name[4] == 't' &&
8703 if (name[4] == 'e' &&
8719 if (name[2] == 'c' &&
8730 if (name[2] == 'l' &&
8741 if (name[2] == 'b' &&
8752 if (name[2] == 's' &&
8775 if (name[4] == 's' &&
8784 if (name[4] == 'n' &&
8797 if (name[3] == 'a' &&
8814 if (name[1] == 'a' &&
8829 case 7: /* 29 tokens of length 7 */
8833 if (name[1] == 'E' &&
8846 if (name[1] == '_' &&
8859 if (name[1] == 'i' &&
8866 return -KEY_binmode;
8872 if (name[1] == 'o' &&
8879 return -KEY_connect;
8888 if (name[2] == 'm' &&
8894 return -KEY_dbmopen;
8905 if (name[4] == 'u' &&
8909 return (FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
8915 if (name[4] == 'n' &&
8936 if (name[1] == 'o' &&
8949 if (name[1] == 'e' &&
8956 if (name[5] == 'r' &&
8959 return -KEY_getpgrp;
8965 if (name[5] == 'i' &&
8968 return -KEY_getppid;
8981 if (name[1] == 'c' &&
8988 return -KEY_lcfirst;
8994 if (name[1] == 'p' &&
9001 return -KEY_opendir;
9007 if (name[1] == 'a' &&
9025 if (name[3] == 'd' &&
9030 return -KEY_readdir;
9036 if (name[3] == 'u' &&
9047 if (name[3] == 'e' &&
9052 return -KEY_reverse;
9071 if (name[3] == 'k' &&
9076 return -KEY_seekdir;
9082 if (name[3] == 'p' &&
9087 return -KEY_setpgrp;
9097 if (name[2] == 'm' &&
9103 return -KEY_shmread;
9109 if (name[2] == 'r' &&
9115 return -KEY_sprintf;
9124 if (name[3] == 'l' &&
9129 return -KEY_symlink;
9138 if (name[4] == 'a' &&
9142 return -KEY_syscall;
9148 if (name[4] == 'p' &&
9152 return -KEY_sysopen;
9158 if (name[4] == 'e' &&
9162 return -KEY_sysread;
9168 if (name[4] == 'e' &&
9172 return -KEY_sysseek;
9190 if (name[1] == 'e' &&
9197 return -KEY_telldir;
9206 if (name[2] == 'f' &&
9212 return -KEY_ucfirst;
9218 if (name[2] == 's' &&
9224 return -KEY_unshift;
9234 if (name[1] == 'a' &&
9241 return -KEY_waitpid;
9250 case 8: /* 26 tokens of length 8 */
9254 if (name[1] == 'U' &&
9262 return KEY_AUTOLOAD;
9273 if (name[3] == 'A' &&
9279 return KEY___DATA__;
9285 if (name[3] == 'I' &&
9291 return -KEY___FILE__;
9297 if (name[3] == 'I' &&
9303 return -KEY___LINE__;
9319 if (name[2] == 'o' &&
9326 return -KEY_closedir;
9332 if (name[2] == 'n' &&
9339 return -KEY_continue;
9349 if (name[1] == 'b' &&
9357 return -KEY_dbmclose;
9363 if (name[1] == 'n' &&
9369 if (name[4] == 'r' &&
9374 return -KEY_endgrent;
9380 if (name[4] == 'w' &&
9385 return -KEY_endpwent;
9398 if (name[1] == 'o' &&
9406 return -KEY_formline;
9412 if (name[1] == 'e' &&
9423 if (name[6] == 'n' &&
9426 return -KEY_getgrent;
9432 if (name[6] == 'i' &&
9435 return -KEY_getgrgid;
9441 if (name[6] == 'a' &&
9444 return -KEY_getgrnam;
9457 if (name[4] == 'o' &&
9462 return -KEY_getlogin;
9473 if (name[6] == 'n' &&
9476 return -KEY_getpwent;
9482 if (name[6] == 'a' &&
9485 return -KEY_getpwnam;
9491 if (name[6] == 'i' &&
9494 return -KEY_getpwuid;
9514 if (name[1] == 'e' &&
9521 if (name[5] == 'i' &&
9528 return -KEY_readline;
9533 return -KEY_readlink;
9544 if (name[5] == 'i' &&
9548 return -KEY_readpipe;
9569 if (name[4] == 'r' &&
9574 return -KEY_setgrent;
9580 if (name[4] == 'w' &&
9585 return -KEY_setpwent;
9601 if (name[3] == 'w' &&
9607 return -KEY_shmwrite;
9613 if (name[3] == 't' &&
9619 return -KEY_shutdown;
9629 if (name[2] == 's' &&
9636 return -KEY_syswrite;
9646 if (name[1] == 'r' &&
9654 return -KEY_truncate;
9663 case 9: /* 8 tokens of length 9 */
9667 if (name[1] == 'n' &&
9676 return -KEY_endnetent;
9682 if (name[1] == 'e' &&
9691 return -KEY_getnetent;
9697 if (name[1] == 'o' &&
9706 return -KEY_localtime;
9712 if (name[1] == 'r' &&
9721 return KEY_prototype;
9727 if (name[1] == 'u' &&
9736 return -KEY_quotemeta;
9742 if (name[1] == 'e' &&
9751 return -KEY_rewinddir;
9757 if (name[1] == 'e' &&
9766 return -KEY_setnetent;
9772 if (name[1] == 'a' &&
9781 return -KEY_wantarray;
9790 case 10: /* 9 tokens of length 10 */
9794 if (name[1] == 'n' &&
9800 if (name[4] == 'o' &&
9807 return -KEY_endhostent;
9813 if (name[4] == 'e' &&
9820 return -KEY_endservent;
9833 if (name[1] == 'e' &&
9839 if (name[4] == 'o' &&
9846 return -KEY_gethostent;
9855 if (name[5] == 'r' &&
9861 return -KEY_getservent;
9867 if (name[5] == 'c' &&
9873 return -KEY_getsockopt;
9898 if (name[4] == 'o' &&
9905 return -KEY_sethostent;
9914 if (name[5] == 'r' &&
9920 return -KEY_setservent;
9926 if (name[5] == 'c' &&
9932 return -KEY_setsockopt;
9949 if (name[2] == 'c' &&
9958 return -KEY_socketpair;
9971 case 11: /* 8 tokens of length 11 */
9975 if (name[1] == '_' &&
9986 return -KEY___PACKAGE__;
9992 if (name[1] == 'n' &&
10002 { /* endprotoent */
10003 return -KEY_endprotoent;
10009 if (name[1] == 'e' &&
10018 if (name[5] == 'e' &&
10024 { /* getpeername */
10025 return -KEY_getpeername;
10034 if (name[6] == 'o' &&
10039 { /* getpriority */
10040 return -KEY_getpriority;
10046 if (name[6] == 't' &&
10051 { /* getprotoent */
10052 return -KEY_getprotoent;
10066 if (name[4] == 'o' &&
10073 { /* getsockname */
10074 return -KEY_getsockname;
10087 if (name[1] == 'e' &&
10095 if (name[6] == 'o' &&
10100 { /* setpriority */
10101 return -KEY_setpriority;
10107 if (name[6] == 't' &&
10112 { /* setprotoent */
10113 return -KEY_setprotoent;
10129 case 12: /* 2 tokens of length 12 */
10130 if (name[0] == 'g' &&
10142 if (name[9] == 'd' &&
10145 { /* getnetbyaddr */
10146 return -KEY_getnetbyaddr;
10152 if (name[9] == 'a' &&
10155 { /* getnetbyname */
10156 return -KEY_getnetbyname;
10168 case 13: /* 4 tokens of length 13 */
10169 if (name[0] == 'g' &&
10176 if (name[4] == 'o' &&
10185 if (name[10] == 'd' &&
10188 { /* gethostbyaddr */
10189 return -KEY_gethostbyaddr;
10195 if (name[10] == 'a' &&
10198 { /* gethostbyname */
10199 return -KEY_gethostbyname;
10212 if (name[4] == 'e' &&
10221 if (name[10] == 'a' &&
10224 { /* getservbyname */
10225 return -KEY_getservbyname;
10231 if (name[10] == 'o' &&
10234 { /* getservbyport */
10235 return -KEY_getservbyport;
10254 case 14: /* 1 tokens of length 14 */
10255 if (name[0] == 'g' &&
10269 { /* getprotobyname */
10270 return -KEY_getprotobyname;
10275 case 16: /* 1 tokens of length 16 */
10276 if (name[0] == 'g' &&
10292 { /* getprotobynumber */
10293 return -KEY_getprotobynumber;
10307 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10311 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10312 if (ckWARN(WARN_SYNTAX)) {
10315 for (w = s+2; *w && level; w++) {
10318 else if (*w == ')')
10321 while (isSPACE(*w))
10323 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
10324 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10325 "%s (...) interpreted as function",name);
10328 while (s < PL_bufend && isSPACE(*s))
10332 while (s < PL_bufend && isSPACE(*s))
10334 if (isIDFIRST_lazy_if(s,UTF)) {
10335 const char * const w = s++;
10336 while (isALNUM_lazy_if(s,UTF))
10338 while (s < PL_bufend && isSPACE(*s))
10342 if (keyword(w, s - w))
10345 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10346 if (gv && GvCVu(gv))
10348 Perl_croak(aTHX_ "No comma allowed after %s", what);
10353 /* Either returns sv, or mortalizes sv and returns a new SV*.
10354 Best used as sv=new_constant(..., sv, ...).
10355 If s, pv are NULL, calls subroutine with one argument,
10356 and type is used with error messages only. */
10359 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10363 HV * const table = GvHV(PL_hintgv); /* ^H */
10367 const char *why1 = "", *why2 = "", *why3 = "";
10369 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10372 why2 = strEQ(key,"charnames")
10373 ? "(possibly a missing \"use charnames ...\")"
10375 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10376 (type ? type: "undef"), why2);
10378 /* This is convoluted and evil ("goto considered harmful")
10379 * but I do not understand the intricacies of all the different
10380 * failure modes of %^H in here. The goal here is to make
10381 * the most probable error message user-friendly. --jhi */
10386 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10387 (type ? type: "undef"), why1, why2, why3);
10389 yyerror(SvPVX_const(msg));
10393 cvp = hv_fetch(table, key, strlen(key), FALSE);
10394 if (!cvp || !SvOK(*cvp)) {
10397 why3 = "} is not defined";
10400 sv_2mortal(sv); /* Parent created it permanently */
10403 pv = sv_2mortal(newSVpvn(s, len));
10405 typesv = sv_2mortal(newSVpv(type, 0));
10407 typesv = &PL_sv_undef;
10409 PUSHSTACKi(PERLSI_OVERLOAD);
10421 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10425 /* Check the eval first */
10426 if (!PL_in_eval && SvTRUE(ERRSV)) {
10427 sv_catpvs(ERRSV, "Propagated");
10428 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10430 res = SvREFCNT_inc_simple(sv);
10434 SvREFCNT_inc_simple_void(res);
10443 why1 = "Call to &{$^H{";
10445 why3 = "}} did not return a defined value";
10453 /* Returns a NUL terminated string, with the length of the string written to
10457 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10460 register char *d = dest;
10461 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10464 Perl_croak(aTHX_ ident_too_long);
10465 if (isALNUM(*s)) /* UTF handled below */
10467 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10472 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10476 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10477 char *t = s + UTF8SKIP(s);
10479 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10483 Perl_croak(aTHX_ ident_too_long);
10484 Copy(s, d, len, char);
10497 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10500 char *bracket = NULL;
10502 register char *d = dest;
10503 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10508 while (isDIGIT(*s)) {
10510 Perl_croak(aTHX_ ident_too_long);
10517 Perl_croak(aTHX_ ident_too_long);
10518 if (isALNUM(*s)) /* UTF handled below */
10520 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10525 else if (*s == ':' && s[1] == ':') {
10529 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10530 char *t = s + UTF8SKIP(s);
10531 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10533 if (d + (t - s) > e)
10534 Perl_croak(aTHX_ ident_too_long);
10535 Copy(s, d, t - s, char);
10546 if (PL_lex_state != LEX_NORMAL)
10547 PL_lex_state = LEX_INTERPENDMAYBE;
10550 if (*s == '$' && s[1] &&
10551 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10564 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10569 if (isSPACE(s[-1])) {
10571 const char ch = *s++;
10572 if (!SPACE_OR_TAB(ch)) {
10578 if (isIDFIRST_lazy_if(d,UTF)) {
10582 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10583 end += UTF8SKIP(end);
10584 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10585 end += UTF8SKIP(end);
10587 Copy(s, d, end - s, char);
10592 while ((isALNUM(*s) || *s == ':') && d < e)
10595 Perl_croak(aTHX_ ident_too_long);
10598 while (s < send && SPACE_OR_TAB(*s))
10600 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10601 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
10602 const char * const brack = (*s == '[') ? "[...]" : "{...}";
10603 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10604 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10605 funny, dest, brack, funny, dest, brack);
10608 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10612 /* Handle extended ${^Foo} variables
10613 * 1999-02-27 mjd-perl-patch@plover.com */
10614 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10618 while (isALNUM(*s) && d < e) {
10622 Perl_croak(aTHX_ ident_too_long);
10627 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10628 PL_lex_state = LEX_INTERPEND;
10631 if (PL_lex_state == LEX_NORMAL) {
10632 if (ckWARN(WARN_AMBIGUOUS) &&
10633 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
10637 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10638 "Ambiguous use of %c{%s} resolved to %c%s",
10639 funny, dest, funny, dest);
10644 s = bracket; /* let the parser handle it */
10648 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10649 PL_lex_state = LEX_INTERPEND;
10654 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10656 PERL_UNUSED_CONTEXT;
10659 else if (ch == 'g')
10660 *pmfl |= PMf_GLOBAL;
10661 else if (ch == 'c')
10662 *pmfl |= PMf_CONTINUE;
10663 else if (ch == 'o')
10665 else if (ch == 'm')
10666 *pmfl |= PMf_MULTILINE;
10667 else if (ch == 's')
10668 *pmfl |= PMf_SINGLELINE;
10669 else if (ch == 'x')
10670 *pmfl |= PMf_EXTENDED;
10674 S_scan_pat(pTHX_ char *start, I32 type)
10678 char *s = scan_str(start,!!PL_madskills,FALSE);
10679 const char * const valid_flags = (type == OP_QR) ? "iomsx" : "iogcmsx";
10686 const char * const delimiter = skipspace(start);
10687 Perl_croak(aTHX_ *delimiter == '?'
10688 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10689 : "Search pattern not terminated" );
10692 pm = (PMOP*)newPMOP(type, 0);
10693 if (PL_multi_open == '?')
10694 pm->op_pmflags |= PMf_ONCE;
10698 while (*s && strchr(valid_flags, *s))
10699 pmflag(&pm->op_pmflags,*s++);
10701 if (PL_madskills && modstart != s) {
10702 SV* tmptoken = newSVpvn(modstart, s - modstart);
10703 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10706 /* issue a warning if /c is specified,but /g is not */
10707 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10708 && ckWARN(WARN_REGEXP))
10710 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
10713 pm->op_pmpermflags = pm->op_pmflags;
10715 PL_lex_op = (OP*)pm;
10716 yylval.ival = OP_MATCH;
10721 S_scan_subst(pTHX_ char *start)
10732 yylval.ival = OP_NULL;
10734 s = scan_str(start,!!PL_madskills,FALSE);
10737 Perl_croak(aTHX_ "Substitution pattern not terminated");
10739 if (s[-1] == PL_multi_open)
10742 if (PL_madskills) {
10743 CURMAD('q', PL_thisopen);
10744 CURMAD('_', PL_thiswhite);
10745 CURMAD('E', PL_thisstuff);
10746 CURMAD('Q', PL_thisclose);
10747 PL_realtokenstart = s - SvPVX(PL_linestr);
10751 first_start = PL_multi_start;
10752 s = scan_str(s,!!PL_madskills,FALSE);
10754 if (PL_lex_stuff) {
10755 SvREFCNT_dec(PL_lex_stuff);
10756 PL_lex_stuff = NULL;
10758 Perl_croak(aTHX_ "Substitution replacement not terminated");
10760 PL_multi_start = first_start; /* so whole substitution is taken together */
10762 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10765 if (PL_madskills) {
10766 CURMAD('z', PL_thisopen);
10767 CURMAD('R', PL_thisstuff);
10768 CURMAD('Z', PL_thisclose);
10778 else if (strchr("iogcmsx", *s))
10779 pmflag(&pm->op_pmflags,*s++);
10785 if (PL_madskills) {
10787 curmad('m', newSVpvn(modstart, s - modstart));
10788 append_madprops(PL_thismad, (OP*)pm, 0);
10792 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10793 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10797 SV * const repl = newSVpvs("");
10799 PL_sublex_info.super_bufptr = s;
10800 PL_sublex_info.super_bufend = PL_bufend;
10802 pm->op_pmflags |= PMf_EVAL;
10804 sv_catpv(repl, es ? "eval " : "do ");
10805 sv_catpvs(repl, "{");
10806 sv_catsv(repl, PL_lex_repl);
10807 if (strchr(SvPVX(PL_lex_repl), '#'))
10808 sv_catpvs(repl, "\n");
10809 sv_catpvs(repl, "}");
10811 SvREFCNT_dec(PL_lex_repl);
10812 PL_lex_repl = repl;
10815 pm->op_pmpermflags = pm->op_pmflags;
10816 PL_lex_op = (OP*)pm;
10817 yylval.ival = OP_SUBST;
10822 S_scan_trans(pTHX_ char *start)
10835 yylval.ival = OP_NULL;
10837 s = scan_str(start,!!PL_madskills,FALSE);
10839 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10841 if (s[-1] == PL_multi_open)
10844 if (PL_madskills) {
10845 CURMAD('q', PL_thisopen);
10846 CURMAD('_', PL_thiswhite);
10847 CURMAD('E', PL_thisstuff);
10848 CURMAD('Q', PL_thisclose);
10849 PL_realtokenstart = s - SvPVX(PL_linestr);
10853 s = scan_str(s,!!PL_madskills,FALSE);
10855 if (PL_lex_stuff) {
10856 SvREFCNT_dec(PL_lex_stuff);
10857 PL_lex_stuff = NULL;
10859 Perl_croak(aTHX_ "Transliteration replacement not terminated");
10861 if (PL_madskills) {
10862 CURMAD('z', PL_thisopen);
10863 CURMAD('R', PL_thisstuff);
10864 CURMAD('Z', PL_thisclose);
10867 complement = del = squash = 0;
10874 complement = OPpTRANS_COMPLEMENT;
10877 del = OPpTRANS_DELETE;
10880 squash = OPpTRANS_SQUASH;
10889 Newx(tbl, complement&&!del?258:256, short);
10890 o = newPVOP(OP_TRANS, 0, (char*)tbl);
10891 o->op_private &= ~OPpTRANS_ALL;
10892 o->op_private |= del|squash|complement|
10893 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10894 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
10897 yylval.ival = OP_TRANS;
10900 if (PL_madskills) {
10902 curmad('m', newSVpvn(modstart, s - modstart));
10903 append_madprops(PL_thismad, o, 0);
10912 S_scan_heredoc(pTHX_ register char *s)
10916 I32 op_type = OP_SCALAR;
10920 const char *found_newline;
10924 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
10926 I32 stuffstart = s - SvPVX(PL_linestr);
10929 PL_realtokenstart = -1;
10934 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
10938 while (SPACE_OR_TAB(*peek))
10940 if (*peek == '`' || *peek == '\'' || *peek =='"') {
10943 s = delimcpy(d, e, s, PL_bufend, term, &len);
10953 if (!isALNUM_lazy_if(s,UTF))
10954 deprecate_old("bare << to mean <<\"\"");
10955 for (; isALNUM_lazy_if(s,UTF); s++) {
10960 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
10961 Perl_croak(aTHX_ "Delimiter for here document is too long");
10964 len = d - PL_tokenbuf;
10967 if (PL_madskills) {
10968 tstart = PL_tokenbuf + !outer;
10969 PL_thisclose = newSVpvn(tstart, len - !outer);
10970 tstart = SvPVX(PL_linestr) + stuffstart;
10971 PL_thisopen = newSVpvn(tstart, s - tstart);
10972 stuffstart = s - SvPVX(PL_linestr);
10975 #ifndef PERL_STRICT_CR
10976 d = strchr(s, '\r');
10978 char * const olds = s;
10980 while (s < PL_bufend) {
10986 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
10995 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11002 if ( outer || !(found_newline = memchr(s, '\n', PL_bufend - s)) ) {
11003 herewas = newSVpvn(s,PL_bufend-s);
11007 herewas = newSVpvn(s-1,found_newline-s+1);
11010 herewas = newSVpvn(s,found_newline-s);
11014 if (PL_madskills) {
11015 tstart = SvPVX(PL_linestr) + stuffstart;
11017 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11019 PL_thisstuff = newSVpvn(tstart, s - tstart);
11022 s += SvCUR(herewas);
11025 stuffstart = s - SvPVX(PL_linestr);
11031 tmpstr = newSV(79);
11032 sv_upgrade(tmpstr, SVt_PVIV);
11033 if (term == '\'') {
11034 op_type = OP_CONST;
11035 SvIV_set(tmpstr, -1);
11037 else if (term == '`') {
11038 op_type = OP_BACKTICK;
11039 SvIV_set(tmpstr, '\\');
11043 PL_multi_start = CopLINE(PL_curcop);
11044 PL_multi_open = PL_multi_close = '<';
11045 term = *PL_tokenbuf;
11046 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11047 char * const bufptr = PL_sublex_info.super_bufptr;
11048 char * const bufend = PL_sublex_info.super_bufend;
11049 char * const olds = s - SvCUR(herewas);
11050 s = strchr(bufptr, '\n');
11054 while (s < bufend &&
11055 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11057 CopLINE_inc(PL_curcop);
11060 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11061 missingterm(PL_tokenbuf);
11063 sv_setpvn(herewas,bufptr,d-bufptr+1);
11064 sv_setpvn(tmpstr,d+1,s-d);
11066 sv_catpvn(herewas,s,bufend-s);
11067 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11074 while (s < PL_bufend &&
11075 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11077 CopLINE_inc(PL_curcop);
11079 if (s >= PL_bufend) {
11080 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11081 missingterm(PL_tokenbuf);
11083 sv_setpvn(tmpstr,d+1,s-d);
11085 if (PL_madskills) {
11087 sv_catpvn(PL_thisstuff, d + 1, s - d);
11089 PL_thisstuff = newSVpvn(d + 1, s - d);
11090 stuffstart = s - SvPVX(PL_linestr);
11094 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11096 sv_catpvn(herewas,s,PL_bufend-s);
11097 sv_setsv(PL_linestr,herewas);
11098 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11099 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11100 PL_last_lop = PL_last_uni = NULL;
11103 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11104 while (s >= PL_bufend) { /* multiple line string? */
11106 if (PL_madskills) {
11107 tstart = SvPVX(PL_linestr) + stuffstart;
11109 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11111 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11115 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11116 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11117 missingterm(PL_tokenbuf);
11120 stuffstart = s - SvPVX(PL_linestr);
11122 CopLINE_inc(PL_curcop);
11123 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11124 PL_last_lop = PL_last_uni = NULL;
11125 #ifndef PERL_STRICT_CR
11126 if (PL_bufend - PL_linestart >= 2) {
11127 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11128 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11130 PL_bufend[-2] = '\n';
11132 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11134 else if (PL_bufend[-1] == '\r')
11135 PL_bufend[-1] = '\n';
11137 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11138 PL_bufend[-1] = '\n';
11140 if (PERLDB_LINE && PL_curstash != PL_debstash) {
11141 SV * const sv = newSV(0);
11143 sv_upgrade(sv, SVt_PVMG);
11144 sv_setsv(sv,PL_linestr);
11145 (void)SvIOK_on(sv);
11147 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop),sv);
11149 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11150 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11151 *(SvPVX(PL_linestr) + off ) = ' ';
11152 sv_catsv(PL_linestr,herewas);
11153 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11154 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11158 sv_catsv(tmpstr,PL_linestr);
11163 PL_multi_end = CopLINE(PL_curcop);
11164 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11165 SvPV_shrink_to_cur(tmpstr);
11167 SvREFCNT_dec(herewas);
11169 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11171 else if (PL_encoding)
11172 sv_recode_to_utf8(tmpstr, PL_encoding);
11174 PL_lex_stuff = tmpstr;
11175 yylval.ival = op_type;
11179 /* scan_inputsymbol
11180 takes: current position in input buffer
11181 returns: new position in input buffer
11182 side-effects: yylval and lex_op are set.
11187 <FH> read from filehandle
11188 <pkg::FH> read from package qualified filehandle
11189 <pkg'FH> read from package qualified filehandle
11190 <$fh> read from filehandle in $fh
11191 <*.h> filename glob
11196 S_scan_inputsymbol(pTHX_ char *start)
11199 register char *s = start; /* current position in buffer */
11203 char *d = PL_tokenbuf; /* start of temp holding space */
11204 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11206 end = strchr(s, '\n');
11209 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11211 /* die if we didn't have space for the contents of the <>,
11212 or if it didn't end, or if we see a newline
11215 if (len >= (I32)sizeof PL_tokenbuf)
11216 Perl_croak(aTHX_ "Excessively long <> operator");
11218 Perl_croak(aTHX_ "Unterminated <> operator");
11223 Remember, only scalar variables are interpreted as filehandles by
11224 this code. Anything more complex (e.g., <$fh{$num}>) will be
11225 treated as a glob() call.
11226 This code makes use of the fact that except for the $ at the front,
11227 a scalar variable and a filehandle look the same.
11229 if (*d == '$' && d[1]) d++;
11231 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11232 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11235 /* If we've tried to read what we allow filehandles to look like, and
11236 there's still text left, then it must be a glob() and not a getline.
11237 Use scan_str to pull out the stuff between the <> and treat it
11238 as nothing more than a string.
11241 if (d - PL_tokenbuf != len) {
11242 yylval.ival = OP_GLOB;
11244 s = scan_str(start,!!PL_madskills,FALSE);
11246 Perl_croak(aTHX_ "Glob not terminated");
11250 bool readline_overriden = FALSE;
11253 /* we're in a filehandle read situation */
11256 /* turn <> into <ARGV> */
11258 Copy("ARGV",d,5,char);
11260 /* Check whether readline() is overriden */
11261 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11263 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11265 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11266 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
11267 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11268 readline_overriden = TRUE;
11270 /* if <$fh>, create the ops to turn the variable into a
11274 /* try to find it in the pad for this block, otherwise find
11275 add symbol table ops
11277 const PADOFFSET tmp = pad_findmy(d);
11278 if (tmp != NOT_IN_PAD) {
11279 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11280 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11281 HEK * const stashname = HvNAME_HEK(stash);
11282 SV * const sym = sv_2mortal(newSVhek(stashname));
11283 sv_catpvs(sym, "::");
11284 sv_catpv(sym, d+1);
11289 OP * const o = newOP(OP_PADSV, 0);
11291 PL_lex_op = readline_overriden
11292 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11293 append_elem(OP_LIST, o,
11294 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11295 : (OP*)newUNOP(OP_READLINE, 0, o);
11304 ? (GV_ADDMULTI | GV_ADDINEVAL)
11307 PL_lex_op = readline_overriden
11308 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11309 append_elem(OP_LIST,
11310 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11311 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11312 : (OP*)newUNOP(OP_READLINE, 0,
11313 newUNOP(OP_RV2SV, 0,
11314 newGVOP(OP_GV, 0, gv)));
11316 if (!readline_overriden)
11317 PL_lex_op->op_flags |= OPf_SPECIAL;
11318 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11319 yylval.ival = OP_NULL;
11322 /* If it's none of the above, it must be a literal filehandle
11323 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11325 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11326 PL_lex_op = readline_overriden
11327 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11328 append_elem(OP_LIST,
11329 newGVOP(OP_GV, 0, gv),
11330 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11331 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11332 yylval.ival = OP_NULL;
11341 takes: start position in buffer
11342 keep_quoted preserve \ on the embedded delimiter(s)
11343 keep_delims preserve the delimiters around the string
11344 returns: position to continue reading from buffer
11345 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11346 updates the read buffer.
11348 This subroutine pulls a string out of the input. It is called for:
11349 q single quotes q(literal text)
11350 ' single quotes 'literal text'
11351 qq double quotes qq(interpolate $here please)
11352 " double quotes "interpolate $here please"
11353 qx backticks qx(/bin/ls -l)
11354 ` backticks `/bin/ls -l`
11355 qw quote words @EXPORT_OK = qw( func() $spam )
11356 m// regexp match m/this/
11357 s/// regexp substitute s/this/that/
11358 tr/// string transliterate tr/this/that/
11359 y/// string transliterate y/this/that/
11360 ($*@) sub prototypes sub foo ($)
11361 (stuff) sub attr parameters sub foo : attr(stuff)
11362 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11364 In most of these cases (all but <>, patterns and transliterate)
11365 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11366 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11367 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11370 It skips whitespace before the string starts, and treats the first
11371 character as the delimiter. If the delimiter is one of ([{< then
11372 the corresponding "close" character )]}> is used as the closing
11373 delimiter. It allows quoting of delimiters, and if the string has
11374 balanced delimiters ([{<>}]) it allows nesting.
11376 On success, the SV with the resulting string is put into lex_stuff or,
11377 if that is already non-NULL, into lex_repl. The second case occurs only
11378 when parsing the RHS of the special constructs s/// and tr/// (y///).
11379 For convenience, the terminating delimiter character is stuffed into
11384 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11387 SV *sv; /* scalar value: string */
11388 char *tmps; /* temp string, used for delimiter matching */
11389 register char *s = start; /* current position in the buffer */
11390 register char term; /* terminating character */
11391 register char *to; /* current position in the sv's data */
11392 I32 brackets = 1; /* bracket nesting level */
11393 bool has_utf8 = FALSE; /* is there any utf8 content? */
11394 I32 termcode; /* terminating char. code */
11395 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11396 STRLEN termlen; /* length of terminating string */
11397 char *last = NULL; /* last position for nesting bracket */
11403 /* skip space before the delimiter */
11409 if (PL_realtokenstart >= 0) {
11410 stuffstart = PL_realtokenstart;
11411 PL_realtokenstart = -1;
11414 stuffstart = start - SvPVX(PL_linestr);
11416 /* mark where we are, in case we need to report errors */
11419 /* after skipping whitespace, the next character is the terminator */
11422 termcode = termstr[0] = term;
11426 termcode = utf8_to_uvchr((U8*)s, &termlen);
11427 Copy(s, termstr, termlen, U8);
11428 if (!UTF8_IS_INVARIANT(term))
11432 /* mark where we are */
11433 PL_multi_start = CopLINE(PL_curcop);
11434 PL_multi_open = term;
11436 /* find corresponding closing delimiter */
11437 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11438 termcode = termstr[0] = term = tmps[5];
11440 PL_multi_close = term;
11442 /* create a new SV to hold the contents. 79 is the SV's initial length.
11443 What a random number. */
11445 sv_upgrade(sv, SVt_PVIV);
11446 SvIV_set(sv, termcode);
11447 (void)SvPOK_only(sv); /* validate pointer */
11449 /* move past delimiter and try to read a complete string */
11451 sv_catpvn(sv, s, termlen);
11454 tstart = SvPVX(PL_linestr) + stuffstart;
11455 if (!PL_thisopen && !keep_delims) {
11456 PL_thisopen = newSVpvn(tstart, s - tstart);
11457 stuffstart = s - SvPVX(PL_linestr);
11461 if (PL_encoding && !UTF) {
11465 int offset = s - SvPVX_const(PL_linestr);
11466 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11467 &offset, (char*)termstr, termlen);
11468 const char * const ns = SvPVX_const(PL_linestr) + offset;
11469 char * const svlast = SvEND(sv) - 1;
11471 for (; s < ns; s++) {
11472 if (*s == '\n' && !PL_rsfp)
11473 CopLINE_inc(PL_curcop);
11476 goto read_more_line;
11478 /* handle quoted delimiters */
11479 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11481 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11483 if ((svlast-1 - t) % 2) {
11484 if (!keep_quoted) {
11485 *(svlast-1) = term;
11487 SvCUR_set(sv, SvCUR(sv) - 1);
11492 if (PL_multi_open == PL_multi_close) {
11500 for (t = w = last; t < svlast; w++, t++) {
11501 /* At here, all closes are "was quoted" one,
11502 so we don't check PL_multi_close. */
11504 if (!keep_quoted && *(t+1) == PL_multi_open)
11509 else if (*t == PL_multi_open)
11517 SvCUR_set(sv, w - SvPVX_const(sv));
11520 if (--brackets <= 0)
11525 if (!keep_delims) {
11526 SvCUR_set(sv, SvCUR(sv) - 1);
11532 /* extend sv if need be */
11533 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11534 /* set 'to' to the next character in the sv's string */
11535 to = SvPVX(sv)+SvCUR(sv);
11537 /* if open delimiter is the close delimiter read unbridle */
11538 if (PL_multi_open == PL_multi_close) {
11539 for (; s < PL_bufend; s++,to++) {
11540 /* embedded newlines increment the current line number */
11541 if (*s == '\n' && !PL_rsfp)
11542 CopLINE_inc(PL_curcop);
11543 /* handle quoted delimiters */
11544 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11545 if (!keep_quoted && s[1] == term)
11547 /* any other quotes are simply copied straight through */
11551 /* terminate when run out of buffer (the for() condition), or
11552 have found the terminator */
11553 else if (*s == term) {
11556 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11559 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11565 /* if the terminator isn't the same as the start character (e.g.,
11566 matched brackets), we have to allow more in the quoting, and
11567 be prepared for nested brackets.
11570 /* read until we run out of string, or we find the terminator */
11571 for (; s < PL_bufend; s++,to++) {
11572 /* embedded newlines increment the line count */
11573 if (*s == '\n' && !PL_rsfp)
11574 CopLINE_inc(PL_curcop);
11575 /* backslashes can escape the open or closing characters */
11576 if (*s == '\\' && s+1 < PL_bufend) {
11577 if (!keep_quoted &&
11578 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11583 /* allow nested opens and closes */
11584 else if (*s == PL_multi_close && --brackets <= 0)
11586 else if (*s == PL_multi_open)
11588 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11593 /* terminate the copied string and update the sv's end-of-string */
11595 SvCUR_set(sv, to - SvPVX_const(sv));
11598 * this next chunk reads more into the buffer if we're not done yet
11602 break; /* handle case where we are done yet :-) */
11604 #ifndef PERL_STRICT_CR
11605 if (to - SvPVX_const(sv) >= 2) {
11606 if ((to[-2] == '\r' && to[-1] == '\n') ||
11607 (to[-2] == '\n' && to[-1] == '\r'))
11611 SvCUR_set(sv, to - SvPVX_const(sv));
11613 else if (to[-1] == '\r')
11616 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11621 /* if we're out of file, or a read fails, bail and reset the current
11622 line marker so we can report where the unterminated string began
11625 if (PL_madskills) {
11626 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11628 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11630 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11634 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11636 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11642 /* we read a line, so increment our line counter */
11643 CopLINE_inc(PL_curcop);
11645 /* update debugger info */
11646 if (PERLDB_LINE && PL_curstash != PL_debstash) {
11647 SV * const line_sv = newSV(0);
11649 sv_upgrade(line_sv, SVt_PVMG);
11650 sv_setsv(line_sv,PL_linestr);
11651 (void)SvIOK_on(line_sv);
11652 SvIV_set(line_sv, 0);
11653 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop), line_sv);
11656 /* having changed the buffer, we must update PL_bufend */
11657 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11658 PL_last_lop = PL_last_uni = NULL;
11661 /* at this point, we have successfully read the delimited string */
11663 if (!PL_encoding || UTF) {
11665 if (PL_madskills) {
11666 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11667 const int len = s - start;
11669 sv_catpvn(PL_thisstuff, tstart, len);
11671 PL_thisstuff = newSVpvn(tstart, len);
11672 if (!PL_thisclose && !keep_delims)
11673 PL_thisclose = newSVpvn(s,termlen);
11678 sv_catpvn(sv, s, termlen);
11683 if (PL_madskills) {
11684 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11685 const int len = s - tstart - termlen;
11687 sv_catpvn(PL_thisstuff, tstart, len);
11689 PL_thisstuff = newSVpvn(tstart, len);
11690 if (!PL_thisclose && !keep_delims)
11691 PL_thisclose = newSVpvn(s - termlen,termlen);
11695 if (has_utf8 || PL_encoding)
11698 PL_multi_end = CopLINE(PL_curcop);
11700 /* if we allocated too much space, give some back */
11701 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11702 SvLEN_set(sv, SvCUR(sv) + 1);
11703 SvPV_renew(sv, SvLEN(sv));
11706 /* decide whether this is the first or second quoted string we've read
11719 takes: pointer to position in buffer
11720 returns: pointer to new position in buffer
11721 side-effects: builds ops for the constant in yylval.op
11723 Read a number in any of the formats that Perl accepts:
11725 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11726 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11729 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11731 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11734 If it reads a number without a decimal point or an exponent, it will
11735 try converting the number to an integer and see if it can do so
11736 without loss of precision.
11740 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11743 register const char *s = start; /* current position in buffer */
11744 register char *d; /* destination in temp buffer */
11745 register char *e; /* end of temp buffer */
11746 NV nv; /* number read, as a double */
11747 SV *sv = NULL; /* place to put the converted number */
11748 bool floatit; /* boolean: int or float? */
11749 const char *lastub = NULL; /* position of last underbar */
11750 static char const number_too_long[] = "Number too long";
11752 /* We use the first character to decide what type of number this is */
11756 Perl_croak(aTHX_ "panic: scan_num");
11758 /* if it starts with a 0, it could be an octal number, a decimal in
11759 0.13 disguise, or a hexadecimal number, or a binary number. */
11763 u holds the "number so far"
11764 shift the power of 2 of the base
11765 (hex == 4, octal == 3, binary == 1)
11766 overflowed was the number more than we can hold?
11768 Shift is used when we add a digit. It also serves as an "are
11769 we in octal/hex/binary?" indicator to disallow hex characters
11770 when in octal mode.
11775 bool overflowed = FALSE;
11776 bool just_zero = TRUE; /* just plain 0 or binary number? */
11777 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11778 static const char* const bases[5] =
11779 { "", "binary", "", "octal", "hexadecimal" };
11780 static const char* const Bases[5] =
11781 { "", "Binary", "", "Octal", "Hexadecimal" };
11782 static const char* const maxima[5] =
11784 "0b11111111111111111111111111111111",
11788 const char *base, *Base, *max;
11790 /* check for hex */
11795 } else if (s[1] == 'b') {
11800 /* check for a decimal in disguise */
11801 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11803 /* so it must be octal */
11810 if (ckWARN(WARN_SYNTAX))
11811 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11812 "Misplaced _ in number");
11816 base = bases[shift];
11817 Base = Bases[shift];
11818 max = maxima[shift];
11820 /* read the rest of the number */
11822 /* x is used in the overflow test,
11823 b is the digit we're adding on. */
11828 /* if we don't mention it, we're done */
11832 /* _ are ignored -- but warned about if consecutive */
11834 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11835 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11836 "Misplaced _ in number");
11840 /* 8 and 9 are not octal */
11841 case '8': case '9':
11843 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11847 case '2': case '3': case '4':
11848 case '5': case '6': case '7':
11850 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11853 case '0': case '1':
11854 b = *s++ & 15; /* ASCII digit -> value of digit */
11858 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11859 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11860 /* make sure they said 0x */
11863 b = (*s++ & 7) + 9;
11865 /* Prepare to put the digit we have onto the end
11866 of the number so far. We check for overflows.
11872 x = u << shift; /* make room for the digit */
11874 if ((x >> shift) != u
11875 && !(PL_hints & HINT_NEW_BINARY)) {
11878 if (ckWARN_d(WARN_OVERFLOW))
11879 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11880 "Integer overflow in %s number",
11883 u = x | b; /* add the digit to the end */
11886 n *= nvshift[shift];
11887 /* If an NV has not enough bits in its
11888 * mantissa to represent an UV this summing of
11889 * small low-order numbers is a waste of time
11890 * (because the NV cannot preserve the
11891 * low-order bits anyway): we could just
11892 * remember when did we overflow and in the
11893 * end just multiply n by the right
11901 /* if we get here, we had success: make a scalar value from
11906 /* final misplaced underbar check */
11907 if (s[-1] == '_') {
11908 if (ckWARN(WARN_SYNTAX))
11909 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11914 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
11915 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11916 "%s number > %s non-portable",
11922 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
11923 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11924 "%s number > %s non-portable",
11929 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
11930 sv = new_constant(start, s - start, "integer",
11932 else if (PL_hints & HINT_NEW_BINARY)
11933 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
11938 handle decimal numbers.
11939 we're also sent here when we read a 0 as the first digit
11941 case '1': case '2': case '3': case '4': case '5':
11942 case '6': case '7': case '8': case '9': case '.':
11945 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
11948 /* read next group of digits and _ and copy into d */
11949 while (isDIGIT(*s) || *s == '_') {
11950 /* skip underscores, checking for misplaced ones
11954 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11955 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11956 "Misplaced _ in number");
11960 /* check for end of fixed-length buffer */
11962 Perl_croak(aTHX_ number_too_long);
11963 /* if we're ok, copy the character */
11968 /* final misplaced underbar check */
11969 if (lastub && s == lastub + 1) {
11970 if (ckWARN(WARN_SYNTAX))
11971 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11974 /* read a decimal portion if there is one. avoid
11975 3..5 being interpreted as the number 3. followed
11978 if (*s == '.' && s[1] != '.') {
11983 if (ckWARN(WARN_SYNTAX))
11984 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11985 "Misplaced _ in number");
11989 /* copy, ignoring underbars, until we run out of digits.
11991 for (; isDIGIT(*s) || *s == '_'; s++) {
11992 /* fixed length buffer check */
11994 Perl_croak(aTHX_ number_too_long);
11996 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11997 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11998 "Misplaced _ in number");
12004 /* fractional part ending in underbar? */
12005 if (s[-1] == '_') {
12006 if (ckWARN(WARN_SYNTAX))
12007 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12008 "Misplaced _ in number");
12010 if (*s == '.' && isDIGIT(s[1])) {
12011 /* oops, it's really a v-string, but without the "v" */
12017 /* read exponent part, if present */
12018 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12022 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12023 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12025 /* stray preinitial _ */
12027 if (ckWARN(WARN_SYNTAX))
12028 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12029 "Misplaced _ in number");
12033 /* allow positive or negative exponent */
12034 if (*s == '+' || *s == '-')
12037 /* stray initial _ */
12039 if (ckWARN(WARN_SYNTAX))
12040 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12041 "Misplaced _ in number");
12045 /* read digits of exponent */
12046 while (isDIGIT(*s) || *s == '_') {
12049 Perl_croak(aTHX_ number_too_long);
12053 if (((lastub && s == lastub + 1) ||
12054 (!isDIGIT(s[1]) && s[1] != '_'))
12055 && ckWARN(WARN_SYNTAX))
12056 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12057 "Misplaced _ in number");
12064 /* make an sv from the string */
12068 We try to do an integer conversion first if no characters
12069 indicating "float" have been found.
12074 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12076 if (flags == IS_NUMBER_IN_UV) {
12078 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12081 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12082 if (uv <= (UV) IV_MIN)
12083 sv_setiv(sv, -(IV)uv);
12090 /* terminate the string */
12092 nv = Atof(PL_tokenbuf);
12096 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12097 (PL_hints & HINT_NEW_INTEGER) )
12098 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
12099 (floatit ? "float" : "integer"),
12103 /* if it starts with a v, it could be a v-string */
12106 sv = newSV(5); /* preallocate storage space */
12107 s = scan_vstring(s,sv);
12111 /* make the op for the constant and return */
12114 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12116 lvalp->opval = NULL;
12122 S_scan_formline(pTHX_ register char *s)
12125 register char *eol;
12127 SV * const stuff = newSVpvs("");
12128 bool needargs = FALSE;
12129 bool eofmt = FALSE;
12131 char *tokenstart = s;
12134 if (PL_madskills) {
12135 savewhite = PL_thiswhite;
12140 while (!needargs) {
12143 #ifdef PERL_STRICT_CR
12144 while (SPACE_OR_TAB(*t))
12147 while (SPACE_OR_TAB(*t) || *t == '\r')
12150 if (*t == '\n' || t == PL_bufend) {
12155 if (PL_in_eval && !PL_rsfp) {
12156 eol = (char *) memchr(s,'\n',PL_bufend-s);
12161 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12163 for (t = s; t < eol; t++) {
12164 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12166 goto enough; /* ~~ must be first line in formline */
12168 if (*t == '@' || *t == '^')
12172 sv_catpvn(stuff, s, eol-s);
12173 #ifndef PERL_STRICT_CR
12174 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12175 char *end = SvPVX(stuff) + SvCUR(stuff);
12178 SvCUR_set(stuff, SvCUR(stuff) - 1);
12188 if (PL_madskills) {
12190 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12192 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12195 s = filter_gets(PL_linestr, PL_rsfp, 0);
12197 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12199 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12201 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12202 PL_last_lop = PL_last_uni = NULL;
12211 if (SvCUR(stuff)) {
12214 PL_lex_state = LEX_NORMAL;
12215 start_force(PL_curforce);
12216 NEXTVAL_NEXTTOKE.ival = 0;
12220 PL_lex_state = LEX_FORMLINE;
12222 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12224 else if (PL_encoding)
12225 sv_recode_to_utf8(stuff, PL_encoding);
12227 start_force(PL_curforce);
12228 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12230 start_force(PL_curforce);
12231 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12235 SvREFCNT_dec(stuff);
12237 PL_lex_formbrack = 0;
12241 if (PL_madskills) {
12243 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12245 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12246 PL_thiswhite = savewhite;
12258 PL_cshlen = strlen(PL_cshname);
12260 #if defined(USE_ITHREADS)
12261 PERL_UNUSED_CONTEXT;
12267 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12270 const I32 oldsavestack_ix = PL_savestack_ix;
12271 CV* const outsidecv = PL_compcv;
12274 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12276 SAVEI32(PL_subline);
12277 save_item(PL_subname);
12278 SAVESPTR(PL_compcv);
12280 PL_compcv = (CV*)newSV(0);
12281 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12282 CvFLAGS(PL_compcv) |= flags;
12284 PL_subline = CopLINE(PL_curcop);
12285 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12286 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12287 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12289 return oldsavestack_ix;
12293 #pragma segment Perl_yylex
12296 Perl_yywarn(pTHX_ const char *s)
12299 PL_in_eval |= EVAL_WARNONLY;
12301 PL_in_eval &= ~EVAL_WARNONLY;
12306 Perl_yyerror(pTHX_ const char *s)
12309 const char *where = NULL;
12310 const char *context = NULL;
12314 if (!yychar || (yychar == ';' && !PL_rsfp))
12316 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12317 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12318 PL_oldbufptr != PL_bufptr) {
12321 The code below is removed for NetWare because it abends/crashes on NetWare
12322 when the script has error such as not having the closing quotes like:
12323 if ($var eq "value)
12324 Checking of white spaces is anyway done in NetWare code.
12327 while (isSPACE(*PL_oldoldbufptr))
12330 context = PL_oldoldbufptr;
12331 contlen = PL_bufptr - PL_oldoldbufptr;
12333 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12334 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12337 The code below is removed for NetWare because it abends/crashes on NetWare
12338 when the script has error such as not having the closing quotes like:
12339 if ($var eq "value)
12340 Checking of white spaces is anyway done in NetWare code.
12343 while (isSPACE(*PL_oldbufptr))
12346 context = PL_oldbufptr;
12347 contlen = PL_bufptr - PL_oldbufptr;
12349 else if (yychar > 255)
12350 where = "next token ???";
12351 else if (yychar == -2) { /* YYEMPTY */
12352 if (PL_lex_state == LEX_NORMAL ||
12353 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12354 where = "at end of line";
12355 else if (PL_lex_inpat)
12356 where = "within pattern";
12358 where = "within string";
12361 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12363 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12364 else if (isPRINT_LC(yychar))
12365 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12367 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12368 where = SvPVX_const(where_sv);
12370 msg = sv_2mortal(newSVpv(s, 0));
12371 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12372 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12374 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12376 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12377 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12378 Perl_sv_catpvf(aTHX_ msg,
12379 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12380 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12383 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12384 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, (void*)msg);
12387 if (PL_error_count >= 10) {
12388 if (PL_in_eval && SvCUR(ERRSV))
12389 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12390 (void*)ERRSV, OutCopFILE(PL_curcop));
12392 Perl_croak(aTHX_ "%s has too many errors.\n",
12393 OutCopFILE(PL_curcop));
12396 PL_in_my_stash = NULL;
12400 #pragma segment Main
12404 S_swallow_bom(pTHX_ U8 *s)
12407 const STRLEN slen = SvCUR(PL_linestr);
12410 if (s[1] == 0xFE) {
12411 /* UTF-16 little-endian? (or UTF32-LE?) */
12412 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12413 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12414 #ifndef PERL_NO_UTF16_FILTER
12415 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12418 if (PL_bufend > (char*)s) {
12422 filter_add(utf16rev_textfilter, NULL);
12423 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12424 utf16_to_utf8_reversed(s, news,
12425 PL_bufend - (char*)s,
12427 sv_setpvn(PL_linestr, (const char*)news, newlen);
12429 s = (U8*)SvPVX(PL_linestr);
12430 Copy(news, s, newlen, U8);
12434 SvUTF8_on(PL_linestr);
12435 s = (U8*)SvPVX(PL_linestr);
12437 /* FIXME - is this a general bug fix? */
12440 PL_bufend = SvPVX(PL_linestr) + newlen;
12443 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12448 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12449 #ifndef PERL_NO_UTF16_FILTER
12450 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12453 if (PL_bufend > (char *)s) {
12457 filter_add(utf16_textfilter, NULL);
12458 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12459 utf16_to_utf8(s, news,
12460 PL_bufend - (char*)s,
12462 sv_setpvn(PL_linestr, (const char*)news, newlen);
12464 SvUTF8_on(PL_linestr);
12465 s = (U8*)SvPVX(PL_linestr);
12466 PL_bufend = SvPVX(PL_linestr) + newlen;
12469 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12474 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12475 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12476 s += 3; /* UTF-8 */
12482 if (s[2] == 0xFE && s[3] == 0xFF) {
12483 /* UTF-32 big-endian */
12484 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12487 else if (s[2] == 0 && s[3] != 0) {
12490 * are a good indicator of UTF-16BE. */
12491 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12497 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12498 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12499 s += 4; /* UTF-8 */
12505 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12508 * are a good indicator of UTF-16LE. */
12509 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12518 * Restore a source filter.
12522 restore_rsfp(pTHX_ void *f)
12525 PerlIO * const fp = (PerlIO*)f;
12527 if (PL_rsfp == PerlIO_stdin())
12528 PerlIO_clearerr(PL_rsfp);
12529 else if (PL_rsfp && (PL_rsfp != fp))
12530 PerlIO_close(PL_rsfp);
12534 #ifndef PERL_NO_UTF16_FILTER
12536 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12539 const STRLEN old = SvCUR(sv);
12540 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12541 DEBUG_P(PerlIO_printf(Perl_debug_log,
12542 "utf16_textfilter(%p): %d %d (%d)\n",
12543 FPTR2DPTR(void *, utf16_textfilter),
12544 idx, maxlen, (int) count));
12548 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12549 Copy(SvPVX_const(sv), tmps, old, char);
12550 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12551 SvCUR(sv) - old, &newlen);
12552 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12554 DEBUG_P({sv_dump(sv);});
12559 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12562 const STRLEN old = SvCUR(sv);
12563 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12564 DEBUG_P(PerlIO_printf(Perl_debug_log,
12565 "utf16rev_textfilter(%p): %d %d (%d)\n",
12566 FPTR2DPTR(void *, utf16rev_textfilter),
12567 idx, maxlen, (int) count));
12571 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12572 Copy(SvPVX_const(sv), tmps, old, char);
12573 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12574 SvCUR(sv) - old, &newlen);
12575 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12577 DEBUG_P({ sv_dump(sv); });
12583 Returns a pointer to the next character after the parsed
12584 vstring, as well as updating the passed in sv.
12586 Function must be called like
12589 s = scan_vstring(s,sv);
12591 The sv should already be large enough to store the vstring
12592 passed in, for performance reasons.
12597 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12600 const char *pos = s;
12601 const char *start = s;
12602 if (*pos == 'v') pos++; /* get past 'v' */
12603 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12605 if ( *pos != '.') {
12606 /* this may not be a v-string if followed by => */
12607 const char *next = pos;
12608 while (next < PL_bufend && isSPACE(*next))
12610 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12611 /* return string not v-string */
12612 sv_setpvn(sv,(char *)s,pos-s);
12613 return (char *)pos;
12617 if (!isALPHA(*pos)) {
12618 U8 tmpbuf[UTF8_MAXBYTES+1];
12621 s++; /* get past 'v' */
12623 sv_setpvn(sv, "", 0);
12626 /* this is atoi() that tolerates underscores */
12629 const char *end = pos;
12631 while (--end >= s) {
12633 const UV orev = rev;
12634 rev += (*end - '0') * mult;
12636 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12637 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12638 "Integer overflow in decimal number");
12642 if (rev > 0x7FFFFFFF)
12643 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12645 /* Append native character for the rev point */
12646 tmpend = uvchr_to_utf8(tmpbuf, rev);
12647 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12648 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12650 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12656 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12660 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12668 * c-indentation-style: bsd
12669 * c-basic-offset: 4
12670 * indent-tabs-mode: t
12673 * ex: set ts=8 sts=4 sw=4 noet: