3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "It all comes from here, the stench and the peril." --Frodo
16 * This file is the lexer for Perl. It's closely linked to the
19 * The main routine is yylex(), which returns the next token.
23 #define PERL_IN_TOKE_C
26 #define yylval (PL_parser->yylval)
28 /* YYINITDEPTH -- initial size of the parser's stacks. */
29 #define YYINITDEPTH 200
31 /* XXX temporary backwards compatibility */
32 #define PL_lex_brackets (PL_parser->lex_brackets)
33 #define PL_lex_brackstack (PL_parser->lex_brackstack)
34 #define PL_lex_casemods (PL_parser->lex_casemods)
35 #define PL_lex_casestack (PL_parser->lex_casestack)
36 #define PL_lex_defer (PL_parser->lex_defer)
37 #define PL_lex_dojoin (PL_parser->lex_dojoin)
38 #define PL_lex_expect (PL_parser->lex_expect)
39 #define PL_lex_formbrack (PL_parser->lex_formbrack)
40 #define PL_lex_inpat (PL_parser->lex_inpat)
41 #define PL_lex_inwhat (PL_parser->lex_inwhat)
42 #define PL_lex_op (PL_parser->lex_op)
43 #define PL_lex_repl (PL_parser->lex_repl)
44 #define PL_lex_starts (PL_parser->lex_starts)
45 #define PL_lex_stuff (PL_parser->lex_stuff)
46 #define PL_multi_start (PL_parser->multi_start)
47 #define PL_multi_open (PL_parser->multi_open)
48 #define PL_multi_close (PL_parser->multi_close)
49 #define PL_pending_ident (PL_parser->pending_ident)
50 #define PL_preambled (PL_parser->preambled)
51 #define PL_sublex_info (PL_parser->sublex_info)
52 #define PL_linestr (PL_parser->linestr)
53 #define PL_expect (PL_parser->expect)
54 #define PL_copline (PL_parser->copline)
55 #define PL_bufptr (PL_parser->bufptr)
56 #define PL_oldbufptr (PL_parser->oldbufptr)
57 #define PL_oldoldbufptr (PL_parser->oldoldbufptr)
58 #define PL_linestart (PL_parser->linestart)
59 #define PL_bufend (PL_parser->bufend)
60 #define PL_last_uni (PL_parser->last_uni)
61 #define PL_last_lop (PL_parser->last_lop)
62 #define PL_last_lop_op (PL_parser->last_lop_op)
63 #define PL_lex_state (PL_parser->lex_state)
64 #define PL_rsfp (PL_parser->rsfp)
65 #define PL_rsfp_filters (PL_parser->rsfp_filters)
68 # define PL_endwhite (PL_parser->endwhite)
69 # define PL_faketokens (PL_parser->faketokens)
70 # define PL_lasttoke (PL_parser->lasttoke)
71 # define PL_nextwhite (PL_parser->nextwhite)
72 # define PL_realtokenstart (PL_parser->realtokenstart)
73 # define PL_skipwhite (PL_parser->skipwhite)
74 # define PL_thisclose (PL_parser->thisclose)
75 # define PL_thismad (PL_parser->thismad)
76 # define PL_thisopen (PL_parser->thisopen)
77 # define PL_thisstuff (PL_parser->thisstuff)
78 # define PL_thistoken (PL_parser->thistoken)
79 # define PL_thiswhite (PL_parser->thiswhite)
80 # define PL_thiswhite (PL_parser->thiswhite)
81 # define PL_nexttoke (PL_parser->nexttoke)
82 # define PL_curforce (PL_parser->curforce)
84 # define PL_nexttoke (PL_parser->nexttoke)
85 # define PL_nexttype (PL_parser->nexttype)
86 # define PL_nextval (PL_parser->nextval)
90 S_pending_ident(pTHX);
92 static const char ident_too_long[] = "Identifier too long";
93 static const char commaless_variable_list[] = "comma-less variable list";
95 #ifndef PERL_NO_UTF16_FILTER
96 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
97 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
101 # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
102 # define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
104 # define CURMAD(slot,sv)
105 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
108 #define XFAKEBRACK 128
109 #define XENUMMASK 127
111 #ifdef USE_UTF8_SCRIPTS
112 # define UTF (!IN_BYTES)
114 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
117 /* In variables named $^X, these are the legal values for X.
118 * 1999-02-27 mjd-perl-patch@plover.com */
119 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
121 /* On MacOS, respect nonbreaking spaces */
122 #ifdef MACOS_TRADITIONAL
123 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
125 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
128 /* LEX_* are values for PL_lex_state, the state of the lexer.
129 * They are arranged oddly so that the guard on the switch statement
130 * can get by with a single comparison (if the compiler is smart enough).
133 /* #define LEX_NOTPARSING 11 is done in perl.h. */
135 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
136 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
137 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
138 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
139 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
141 /* at end of code, eg "$x" followed by: */
142 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
143 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
145 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
146 string or after \E, $foo, etc */
147 #define LEX_INTERPCONST 2 /* NOT USED */
148 #define LEX_FORMLINE 1 /* expecting a format line */
149 #define LEX_KNOWNEXT 0 /* next token known; just return it */
153 static const char* const lex_state_names[] = {
172 #include "keywords.h"
174 /* CLINE is a macro that ensures PL_copline has a sane value */
179 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
182 # define SKIPSPACE0(s) skipspace0(s)
183 # define SKIPSPACE1(s) skipspace1(s)
184 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
185 # define PEEKSPACE(s) skipspace2(s,0)
187 # define SKIPSPACE0(s) skipspace(s)
188 # define SKIPSPACE1(s) skipspace(s)
189 # define SKIPSPACE2(s,tsv) skipspace(s)
190 # define PEEKSPACE(s) skipspace(s)
194 * Convenience functions to return different tokens and prime the
195 * lexer for the next token. They all take an argument.
197 * TOKEN : generic token (used for '(', DOLSHARP, etc)
198 * OPERATOR : generic operator
199 * AOPERATOR : assignment operator
200 * PREBLOCK : beginning the block after an if, while, foreach, ...
201 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
202 * PREREF : *EXPR where EXPR is not a simple identifier
203 * TERM : expression term
204 * LOOPX : loop exiting command (goto, last, dump, etc)
205 * FTST : file test operator
206 * FUN0 : zero-argument function
207 * FUN1 : not used, except for not, which isn't a UNIOP
208 * BOop : bitwise or or xor
210 * SHop : shift operator
211 * PWop : power operator
212 * PMop : pattern-matching operator
213 * Aop : addition-level operator
214 * Mop : multiplication-level operator
215 * Eop : equality-testing operator
216 * Rop : relational operator <= != gt
218 * Also see LOP and lop() below.
221 #ifdef DEBUGGING /* Serve -DT. */
222 # define REPORT(retval) tokereport((I32)retval)
224 # define REPORT(retval) (retval)
227 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
228 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
229 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
230 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
231 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
232 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
233 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
234 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
235 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
236 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
237 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
238 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
239 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
240 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
241 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
242 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
243 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
244 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
245 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
246 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
248 /* This bit of chicanery makes a unary function followed by
249 * a parenthesis into a function with one argument, highest precedence.
250 * The UNIDOR macro is for unary functions that can be followed by the //
251 * operator (such as C<shift // 0>).
253 #define UNI2(f,x) { \
257 PL_last_uni = PL_oldbufptr; \
258 PL_last_lop_op = f; \
260 return REPORT( (int)FUNC1 ); \
262 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
264 #define UNI(f) UNI2(f,XTERM)
265 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
267 #define UNIBRACK(f) { \
270 PL_last_uni = PL_oldbufptr; \
272 return REPORT( (int)FUNC1 ); \
274 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
277 /* grandfather return to old style */
278 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
282 /* how to interpret the yylval associated with the token */
286 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
292 static struct debug_tokens {
294 enum token_type type;
296 } const debug_tokens[] =
298 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
299 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
300 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
301 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
302 { ARROW, TOKENTYPE_NONE, "ARROW" },
303 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
304 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
305 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
306 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
307 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
308 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
309 { DO, TOKENTYPE_NONE, "DO" },
310 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
311 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
312 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
313 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
314 { ELSE, TOKENTYPE_NONE, "ELSE" },
315 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
316 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
317 { FOR, TOKENTYPE_IVAL, "FOR" },
318 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
319 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
320 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
321 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
322 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
323 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
324 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
325 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
326 { IF, TOKENTYPE_IVAL, "IF" },
327 { LABEL, TOKENTYPE_PVAL, "LABEL" },
328 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
329 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
330 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
331 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
332 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
333 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
334 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
335 { MY, TOKENTYPE_IVAL, "MY" },
336 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
337 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
338 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
339 { OROP, TOKENTYPE_IVAL, "OROP" },
340 { OROR, TOKENTYPE_NONE, "OROR" },
341 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
342 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
343 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
344 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
345 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
346 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
347 { PREINC, TOKENTYPE_NONE, "PREINC" },
348 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
349 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
350 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
351 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
352 { SUB, TOKENTYPE_NONE, "SUB" },
353 { THING, TOKENTYPE_OPVAL, "THING" },
354 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
355 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
356 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
357 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
358 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
359 { USE, TOKENTYPE_IVAL, "USE" },
360 { WHEN, TOKENTYPE_IVAL, "WHEN" },
361 { WHILE, TOKENTYPE_IVAL, "WHILE" },
362 { WORD, TOKENTYPE_OPVAL, "WORD" },
363 { 0, TOKENTYPE_NONE, NULL }
366 /* dump the returned token in rv, plus any optional arg in yylval */
369 S_tokereport(pTHX_ I32 rv)
373 const char *name = NULL;
374 enum token_type type = TOKENTYPE_NONE;
375 const struct debug_tokens *p;
376 SV* const report = newSVpvs("<== ");
378 for (p = debug_tokens; p->token; p++) {
379 if (p->token == (int)rv) {
386 Perl_sv_catpv(aTHX_ report, name);
387 else if ((char)rv > ' ' && (char)rv < '~')
388 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
390 sv_catpvs(report, "EOF");
392 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
395 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
398 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
400 case TOKENTYPE_OPNUM:
401 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
402 PL_op_name[yylval.ival]);
405 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
407 case TOKENTYPE_OPVAL:
409 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
410 PL_op_name[yylval.opval->op_type]);
411 if (yylval.opval->op_type == OP_CONST) {
412 Perl_sv_catpvf(aTHX_ report, " %s",
413 SvPEEK(cSVOPx_sv(yylval.opval)));
418 sv_catpvs(report, "(opval=null)");
421 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
427 /* print the buffer with suitable escapes */
430 S_printbuf(pTHX_ const char* fmt, const char* s)
432 SV* const tmp = newSVpvs("");
433 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
442 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
443 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
447 S_ao(pTHX_ int toketype)
450 if (*PL_bufptr == '=') {
452 if (toketype == ANDAND)
453 yylval.ival = OP_ANDASSIGN;
454 else if (toketype == OROR)
455 yylval.ival = OP_ORASSIGN;
456 else if (toketype == DORDOR)
457 yylval.ival = OP_DORASSIGN;
465 * When Perl expects an operator and finds something else, no_op
466 * prints the warning. It always prints "<something> found where
467 * operator expected. It prints "Missing semicolon on previous line?"
468 * if the surprise occurs at the start of the line. "do you need to
469 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
470 * where the compiler doesn't know if foo is a method call or a function.
471 * It prints "Missing operator before end of line" if there's nothing
472 * after the missing operator, or "... before <...>" if there is something
473 * after the missing operator.
477 S_no_op(pTHX_ const char *what, char *s)
480 char * const oldbp = PL_bufptr;
481 const bool is_first = (PL_oldbufptr == PL_linestart);
487 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
488 if (ckWARN_d(WARN_SYNTAX)) {
490 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
491 "\t(Missing semicolon on previous line?)\n");
492 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
494 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
496 if (t < PL_bufptr && isSPACE(*t))
497 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
498 "\t(Do you need to predeclare %.*s?)\n",
499 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
503 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
504 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
512 * Complain about missing quote/regexp/heredoc terminator.
513 * If it's called with NULL then it cauterizes the line buffer.
514 * If we're in a delimited string and the delimiter is a control
515 * character, it's reformatted into a two-char sequence like ^C.
520 S_missingterm(pTHX_ char *s)
526 char * const nl = strrchr(s,'\n');
532 iscntrl(PL_multi_close)
534 PL_multi_close < 32 || PL_multi_close == 127
538 tmpbuf[1] = (char)toCTRL(PL_multi_close);
543 *tmpbuf = (char)PL_multi_close;
547 q = strchr(s,'"') ? '\'' : '"';
548 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
551 #define FEATURE_IS_ENABLED(name) \
552 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
553 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
555 * S_feature_is_enabled
556 * Check whether the named feature is enabled.
559 S_feature_is_enabled(pTHX_ const char *name, STRLEN namelen)
562 HV * const hinthv = GvHV(PL_hintgv);
563 char he_name[32] = "feature_";
564 (void) my_strlcpy(&he_name[8], name, 24);
566 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
574 Perl_deprecate(pTHX_ const char *s)
576 if (ckWARN(WARN_DEPRECATED))
577 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
581 Perl_deprecate_old(pTHX_ const char *s)
583 /* This function should NOT be called for any new deprecated warnings */
584 /* Use Perl_deprecate instead */
586 /* It is here to maintain backward compatibility with the pre-5.8 */
587 /* warnings category hierarchy. The "deprecated" category used to */
588 /* live under the "syntax" category. It is now a top-level category */
589 /* in its own right. */
591 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
592 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
593 "Use of %s is deprecated", s);
597 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
598 * utf16-to-utf8-reversed.
601 #ifdef PERL_CR_FILTER
605 register const char *s = SvPVX_const(sv);
606 register const char * const e = s + SvCUR(sv);
607 /* outer loop optimized to do nothing if there are no CR-LFs */
609 if (*s++ == '\r' && *s == '\n') {
610 /* hit a CR-LF, need to copy the rest */
611 register char *d = s - 1;
614 if (*s == '\r' && s[1] == '\n')
625 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
627 const I32 count = FILTER_READ(idx+1, sv, maxlen);
628 if (count > 0 && !maxlen)
639 * Create a parser object and initialise its parser and lexer fields
641 * rsfp is the opened file handle to read from (if any),
643 * line holds any initial content already read from the file (or in
644 * the case of no file, such as an eval, the whole contents);
646 * new_filter indicates that this is a new file and it shouldn't inherit
647 * the filters from the current parser (ie require).
651 Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, bool new_filter)
654 const char *s = NULL;
656 yy_parser *parser, *oparser;
658 /* create and initialise a parser */
660 Newxz(parser, 1, yy_parser);
661 parser->old_parser = oparser = PL_parser;
664 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
665 parser->ps = parser->stack;
666 parser->stack_size = YYINITDEPTH;
668 parser->stack->state = 0;
669 parser->yyerrstatus = 0;
670 parser->yychar = YYEMPTY; /* Cause a token to be read. */
672 /* on scope exit, free this parser and restore any outer one */
675 /* initialise lexer state */
677 SAVECOPLINE(PL_curcop);
680 parser->curforce = -1;
682 parser->nexttoke = 0;
684 parser->copline = NOLINE;
685 PL_lex_state = LEX_NORMAL;
686 parser->expect = XSTATE;
688 parser->rsfp_filters = (new_filter || !oparser) ? NULL
689 : (AV*)SvREFCNT_inc(oparser->rsfp_filters);
691 Newx(parser->lex_brackstack, 120, char);
692 Newx(parser->lex_casestack, 12, char);
693 *parser->lex_casestack = '\0';
696 s = SvPV_const(line, len);
702 parser->linestr = newSVpvs("\n;");
703 } else if (SvREADONLY(line) || s[len-1] != ';') {
704 parser->linestr = newSVsv(line);
706 sv_catpvs(parser->linestr, "\n;");
709 SvREFCNT_inc_simple_void_NN(line);
710 parser->linestr = line;
712 parser->oldoldbufptr =
715 parser->linestart = SvPVX(parser->linestr);
716 parser->bufend = parser->bufptr + SvCUR(parser->linestr);
717 parser->last_lop = parser->last_uni = NULL;
721 /* delete a parser object */
724 Perl_parser_free(pTHX_ const yy_parser *parser)
726 SvREFCNT_dec(parser->linestr);
728 if (parser->rsfp == PerlIO_stdin())
729 PerlIO_clearerr(parser->rsfp);
730 else if (parser->rsfp && parser->old_parser
731 && parser->rsfp != parser->old_parser->rsfp)
732 PerlIO_close(parser->rsfp);
733 SvREFCNT_dec(parser->rsfp_filters);
735 Safefree(parser->stack);
736 Safefree(parser->lex_brackstack);
737 Safefree(parser->lex_casestack);
738 PL_parser = parser->old_parser;
745 * Finalizer for lexing operations. Must be called when the parser is
746 * done with the lexer.
753 PL_doextract = FALSE;
758 * This subroutine has nothing to do with tilting, whether at windmills
759 * or pinball tables. Its name is short for "increment line". It
760 * increments the current line number in CopLINE(PL_curcop) and checks
761 * to see whether the line starts with a comment of the form
762 * # line 500 "foo.pm"
763 * If so, it sets the current line number and file to the values in the comment.
767 S_incline(pTHX_ const char *s)
774 CopLINE_inc(PL_curcop);
777 while (SPACE_OR_TAB(*s))
779 if (strnEQ(s, "line", 4))
783 if (SPACE_OR_TAB(*s))
787 while (SPACE_OR_TAB(*s))
795 while (SPACE_OR_TAB(*s))
797 if (*s == '"' && (t = strchr(s+1, '"'))) {
807 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
809 if (*e != '\n' && *e != '\0')
810 return; /* false alarm */
813 const STRLEN len = t - s;
815 const char * const cf = CopFILE(PL_curcop);
816 STRLEN tmplen = cf ? strlen(cf) : 0;
817 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
818 /* must copy *{"::_<(eval N)[oldfilename:L]"}
819 * to *{"::_<newfilename"} */
820 /* However, the long form of evals is only turned on by the
821 debugger - usually they're "(eval %lu)" */
825 STRLEN tmplen2 = len;
826 if (tmplen + 2 <= sizeof smallbuf)
829 Newx(tmpbuf, tmplen + 2, char);
832 memcpy(tmpbuf + 2, cf, tmplen);
834 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
839 if (tmplen2 + 2 <= sizeof smallbuf)
842 Newx(tmpbuf2, tmplen2 + 2, char);
844 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
845 /* Either they malloc'd it, or we malloc'd it,
846 so no prefix is present in ours. */
851 memcpy(tmpbuf2 + 2, s, tmplen2);
854 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
856 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
857 /* adjust ${"::_<newfilename"} to store the new file name */
858 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
859 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
860 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
863 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
865 if (tmpbuf != smallbuf) Safefree(tmpbuf);
868 CopFILE_free(PL_curcop);
869 CopFILE_setn(PL_curcop, s, len);
871 CopLINE_set(PL_curcop, atoi(n)-1);
875 /* skip space before PL_thistoken */
878 S_skipspace0(pTHX_ register char *s)
885 PL_thiswhite = newSVpvs("");
886 sv_catsv(PL_thiswhite, PL_skipwhite);
887 sv_free(PL_skipwhite);
890 PL_realtokenstart = s - SvPVX(PL_linestr);
894 /* skip space after PL_thistoken */
897 S_skipspace1(pTHX_ register char *s)
899 const char *start = s;
900 I32 startoff = start - SvPVX(PL_linestr);
905 start = SvPVX(PL_linestr) + startoff;
906 if (!PL_thistoken && PL_realtokenstart >= 0) {
907 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
908 PL_thistoken = newSVpvn(tstart, start - tstart);
910 PL_realtokenstart = -1;
913 PL_nextwhite = newSVpvs("");
914 sv_catsv(PL_nextwhite, PL_skipwhite);
915 sv_free(PL_skipwhite);
922 S_skipspace2(pTHX_ register char *s, SV **svp)
925 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
926 const I32 startoff = s - SvPVX(PL_linestr);
929 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
930 if (!PL_madskills || !svp)
932 start = SvPVX(PL_linestr) + startoff;
933 if (!PL_thistoken && PL_realtokenstart >= 0) {
934 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
935 PL_thistoken = newSVpvn(tstart, start - tstart);
936 PL_realtokenstart = -1;
941 sv_setsv(*svp, PL_skipwhite);
942 sv_free(PL_skipwhite);
951 S_update_debugger_info(pTHX_ SV *orig_sv, const char *buf, STRLEN len)
953 AV *av = CopFILEAVx(PL_curcop);
955 SV * const sv = newSV_type(SVt_PVMG);
957 sv_setsv(sv, orig_sv);
959 sv_setpvn(sv, buf, len);
962 av_store(av, (I32)CopLINE(PL_curcop), sv);
968 * Called to gobble the appropriate amount and type of whitespace.
969 * Skips comments as well.
973 S_skipspace(pTHX_ register char *s)
978 int startoff = s - SvPVX(PL_linestr);
981 sv_free(PL_skipwhite);
986 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
987 while (s < PL_bufend && SPACE_OR_TAB(*s))
997 SSize_t oldprevlen, oldoldprevlen;
998 SSize_t oldloplen = 0, oldunilen = 0;
999 while (s < PL_bufend && isSPACE(*s)) {
1000 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
1005 if (s < PL_bufend && *s == '#') {
1006 while (s < PL_bufend && *s != '\n')
1008 if (s < PL_bufend) {
1010 if (PL_in_eval && !PL_rsfp) {
1017 /* only continue to recharge the buffer if we're at the end
1018 * of the buffer, we're not reading from a source filter, and
1019 * we're in normal lexing mode
1021 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
1022 PL_lex_state == LEX_FORMLINE)
1029 /* try to recharge the buffer */
1031 curoff = s - SvPVX(PL_linestr);
1034 if ((s = filter_gets(PL_linestr, PL_rsfp,
1035 (prevlen = SvCUR(PL_linestr)))) == NULL)
1038 if (PL_madskills && curoff != startoff) {
1040 PL_skipwhite = newSVpvs("");
1041 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1045 /* mustn't throw out old stuff yet if madpropping */
1046 SvCUR(PL_linestr) = curoff;
1047 s = SvPVX(PL_linestr) + curoff;
1049 if (curoff && s[-1] == '\n')
1053 /* end of file. Add on the -p or -n magic */
1054 /* XXX these shouldn't really be added here, can't set PL_faketokens */
1057 sv_catpvs(PL_linestr,
1058 ";}continue{print or die qq(-p destination: $!\\n);}");
1060 sv_setpvs(PL_linestr,
1061 ";}continue{print or die qq(-p destination: $!\\n);}");
1063 PL_minus_n = PL_minus_p = 0;
1065 else if (PL_minus_n) {
1067 sv_catpvn(PL_linestr, ";}", 2);
1069 sv_setpvn(PL_linestr, ";}", 2);
1075 sv_catpvn(PL_linestr,";", 1);
1077 sv_setpvn(PL_linestr,";", 1);
1080 /* reset variables for next time we lex */
1081 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
1087 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1088 PL_last_lop = PL_last_uni = NULL;
1090 /* Close the filehandle. Could be from -P preprocessor,
1091 * STDIN, or a regular file. If we were reading code from
1092 * STDIN (because the commandline held no -e or filename)
1093 * then we don't close it, we reset it so the code can
1094 * read from STDIN too.
1097 if (PL_preprocess && !PL_in_eval)
1098 (void)PerlProc_pclose(PL_rsfp);
1099 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1100 PerlIO_clearerr(PL_rsfp);
1102 (void)PerlIO_close(PL_rsfp);
1107 /* not at end of file, so we only read another line */
1108 /* make corresponding updates to old pointers, for yyerror() */
1109 oldprevlen = PL_oldbufptr - PL_bufend;
1110 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1112 oldunilen = PL_last_uni - PL_bufend;
1114 oldloplen = PL_last_lop - PL_bufend;
1115 PL_linestart = PL_bufptr = s + prevlen;
1116 PL_bufend = s + SvCUR(PL_linestr);
1118 PL_oldbufptr = s + oldprevlen;
1119 PL_oldoldbufptr = s + oldoldprevlen;
1121 PL_last_uni = s + oldunilen;
1123 PL_last_lop = s + oldloplen;
1126 /* debugger active and we're not compiling the debugger code,
1127 * so store the line into the debugger's array of lines
1129 if (PERLDB_LINE && PL_curstash != PL_debstash)
1130 update_debugger_info(NULL, PL_bufptr, PL_bufend - PL_bufptr);
1137 PL_skipwhite = newSVpvs("");
1138 curoff = s - SvPVX(PL_linestr);
1139 if (curoff - startoff)
1140 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1149 * Check the unary operators to ensure there's no ambiguity in how they're
1150 * used. An ambiguous piece of code would be:
1152 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1153 * the +5 is its argument.
1163 if (PL_oldoldbufptr != PL_last_uni)
1165 while (isSPACE(*PL_last_uni))
1168 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1170 if ((t = strchr(s, '(')) && t < PL_bufptr)
1173 if (ckWARN_d(WARN_AMBIGUOUS)){
1174 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1175 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1176 (int)(s - PL_last_uni), PL_last_uni);
1181 * LOP : macro to build a list operator. Its behaviour has been replaced
1182 * with a subroutine, S_lop() for which LOP is just another name.
1185 #define LOP(f,x) return lop(f,x,s)
1189 * Build a list operator (or something that might be one). The rules:
1190 * - if we have a next token, then it's a list operator [why?]
1191 * - if the next thing is an opening paren, then it's a function
1192 * - else it's a list operator
1196 S_lop(pTHX_ I32 f, int x, char *s)
1203 PL_last_lop = PL_oldbufptr;
1204 PL_last_lop_op = (OPCODE)f;
1207 return REPORT(LSTOP);
1210 return REPORT(LSTOP);
1213 return REPORT(FUNC);
1216 return REPORT(FUNC);
1218 return REPORT(LSTOP);
1224 * Sets up for an eventual force_next(). start_force(0) basically does
1225 * an unshift, while start_force(-1) does a push. yylex removes items
1230 S_start_force(pTHX_ int where)
1234 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1235 where = PL_lasttoke;
1236 assert(PL_curforce < 0 || PL_curforce == where);
1237 if (PL_curforce != where) {
1238 for (i = PL_lasttoke; i > where; --i) {
1239 PL_nexttoke[i] = PL_nexttoke[i-1];
1243 if (PL_curforce < 0) /* in case of duplicate start_force() */
1244 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1245 PL_curforce = where;
1248 curmad('^', newSVpvs(""));
1249 CURMAD('_', PL_nextwhite);
1254 S_curmad(pTHX_ char slot, SV *sv)
1260 if (PL_curforce < 0)
1261 where = &PL_thismad;
1263 where = &PL_nexttoke[PL_curforce].next_mad;
1266 sv_setpvn(sv, "", 0);
1269 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1271 else if (PL_encoding) {
1272 sv_recode_to_utf8(sv, PL_encoding);
1277 /* keep a slot open for the head of the list? */
1278 if (slot != '_' && *where && (*where)->mad_key == '^') {
1279 (*where)->mad_key = slot;
1280 sv_free((*where)->mad_val);
1281 (*where)->mad_val = (void*)sv;
1284 addmad(newMADsv(slot, sv), where, 0);
1287 # define start_force(where) NOOP
1288 # define curmad(slot, sv) NOOP
1293 * When the lexer realizes it knows the next token (for instance,
1294 * it is reordering tokens for the parser) then it can call S_force_next
1295 * to know what token to return the next time the lexer is called. Caller
1296 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1297 * and possibly PL_expect to ensure the lexer handles the token correctly.
1301 S_force_next(pTHX_ I32 type)
1305 if (PL_curforce < 0)
1306 start_force(PL_lasttoke);
1307 PL_nexttoke[PL_curforce].next_type = type;
1308 if (PL_lex_state != LEX_KNOWNEXT)
1309 PL_lex_defer = PL_lex_state;
1310 PL_lex_state = LEX_KNOWNEXT;
1311 PL_lex_expect = PL_expect;
1314 PL_nexttype[PL_nexttoke] = type;
1316 if (PL_lex_state != LEX_KNOWNEXT) {
1317 PL_lex_defer = PL_lex_state;
1318 PL_lex_expect = PL_expect;
1319 PL_lex_state = LEX_KNOWNEXT;
1325 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1328 SV * const sv = newSVpvn(start,len);
1329 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1336 * When the lexer knows the next thing is a word (for instance, it has
1337 * just seen -> and it knows that the next char is a word char, then
1338 * it calls S_force_word to stick the next word into the PL_nexttoke/val
1342 * char *start : buffer position (must be within PL_linestr)
1343 * int token : PL_next* will be this type of bare word (e.g., METHOD,WORD)
1344 * int check_keyword : if true, Perl checks to make sure the word isn't
1345 * a keyword (do this if the word is a label, e.g. goto FOO)
1346 * int allow_pack : if true, : characters will also be allowed (require,
1347 * use, etc. do this)
1348 * int allow_initial_tick : used by the "sub" lexer only.
1352 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1358 start = SKIPSPACE1(start);
1360 if (isIDFIRST_lazy_if(s,UTF) ||
1361 (allow_pack && *s == ':') ||
1362 (allow_initial_tick && *s == '\'') )
1364 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1365 if (check_keyword && keyword(PL_tokenbuf, len, 0))
1367 start_force(PL_curforce);
1369 curmad('X', newSVpvn(start,s-start));
1370 if (token == METHOD) {
1375 PL_expect = XOPERATOR;
1379 curmad('g', newSVpvs( "forced" ));
1380 NEXTVAL_NEXTTOKE.opval
1381 = (OP*)newSVOP(OP_CONST,0,
1382 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1383 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1391 * Called when the lexer wants $foo *foo &foo etc, but the program
1392 * text only contains the "foo" portion. The first argument is a pointer
1393 * to the "foo", and the second argument is the type symbol to prefix.
1394 * Forces the next token to be a "WORD".
1395 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1399 S_force_ident(pTHX_ register const char *s, int kind)
1403 const STRLEN len = strlen(s);
1404 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1405 start_force(PL_curforce);
1406 NEXTVAL_NEXTTOKE.opval = o;
1409 o->op_private = OPpCONST_ENTERED;
1410 /* XXX see note in pp_entereval() for why we forgo typo
1411 warnings if the symbol must be introduced in an eval.
1413 gv_fetchpvn_flags(s, len,
1414 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1416 kind == '$' ? SVt_PV :
1417 kind == '@' ? SVt_PVAV :
1418 kind == '%' ? SVt_PVHV :
1426 Perl_str_to_version(pTHX_ SV *sv)
1431 const char *start = SvPV_const(sv,len);
1432 const char * const end = start + len;
1433 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1434 while (start < end) {
1438 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1443 retval += ((NV)n)/nshift;
1452 * Forces the next token to be a version number.
1453 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1454 * and if "guessing" is TRUE, then no new token is created (and the caller
1455 * must use an alternative parsing method).
1459 S_force_version(pTHX_ char *s, int guessing)
1465 I32 startoff = s - SvPVX(PL_linestr);
1474 while (isDIGIT(*d) || *d == '_' || *d == '.')
1478 start_force(PL_curforce);
1479 curmad('X', newSVpvn(s,d-s));
1482 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1484 s = scan_num(s, &yylval);
1485 version = yylval.opval;
1486 ver = cSVOPx(version)->op_sv;
1487 if (SvPOK(ver) && !SvNIOK(ver)) {
1488 SvUPGRADE(ver, SVt_PVNV);
1489 SvNV_set(ver, str_to_version(ver));
1490 SvNOK_on(ver); /* hint that it is a version */
1493 else if (guessing) {
1496 sv_free(PL_nextwhite); /* let next token collect whitespace */
1498 s = SvPVX(PL_linestr) + startoff;
1506 if (PL_madskills && !version) {
1507 sv_free(PL_nextwhite); /* let next token collect whitespace */
1509 s = SvPVX(PL_linestr) + startoff;
1512 /* NOTE: The parser sees the package name and the VERSION swapped */
1513 start_force(PL_curforce);
1514 NEXTVAL_NEXTTOKE.opval = version;
1522 * Tokenize a quoted string passed in as an SV. It finds the next
1523 * chunk, up to end of string or a backslash. It may make a new
1524 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1529 S_tokeq(pTHX_ SV *sv)
1533 register char *send;
1541 s = SvPV_force(sv, len);
1542 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1545 while (s < send && *s != '\\')
1550 if ( PL_hints & HINT_NEW_STRING ) {
1551 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1557 if (s + 1 < send && (s[1] == '\\'))
1558 s++; /* all that, just for this */
1563 SvCUR_set(sv, d - SvPVX_const(sv));
1565 if ( PL_hints & HINT_NEW_STRING )
1566 return new_constant(NULL, 0, "q", sv, pv, "q");
1571 * Now come three functions related to double-quote context,
1572 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1573 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1574 * interact with PL_lex_state, and create fake ( ... ) argument lists
1575 * to handle functions and concatenation.
1576 * They assume that whoever calls them will be setting up a fake
1577 * join call, because each subthing puts a ',' after it. This lets
1580 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1582 * (I'm not sure whether the spurious commas at the end of lcfirst's
1583 * arguments and join's arguments are created or not).
1588 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1590 * Pattern matching will set PL_lex_op to the pattern-matching op to
1591 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1593 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1595 * Everything else becomes a FUNC.
1597 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1598 * had an OP_CONST or OP_READLINE). This just sets us up for a
1599 * call to S_sublex_push().
1603 S_sublex_start(pTHX)
1606 register const I32 op_type = yylval.ival;
1608 if (op_type == OP_NULL) {
1609 yylval.opval = PL_lex_op;
1613 if (op_type == OP_CONST || op_type == OP_READLINE) {
1614 SV *sv = tokeq(PL_lex_stuff);
1616 if (SvTYPE(sv) == SVt_PVIV) {
1617 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1619 const char * const p = SvPV_const(sv, len);
1620 SV * const nsv = newSVpvn(p, len);
1626 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1627 PL_lex_stuff = NULL;
1628 /* Allow <FH> // "foo" */
1629 if (op_type == OP_READLINE)
1630 PL_expect = XTERMORDORDOR;
1633 else if (op_type == OP_BACKTICK && PL_lex_op) {
1634 /* readpipe() vas overriden */
1635 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1636 yylval.opval = PL_lex_op;
1638 PL_lex_stuff = NULL;
1642 PL_sublex_info.super_state = PL_lex_state;
1643 PL_sublex_info.sub_inwhat = (U16)op_type;
1644 PL_sublex_info.sub_op = PL_lex_op;
1645 PL_lex_state = LEX_INTERPPUSH;
1649 yylval.opval = PL_lex_op;
1659 * Create a new scope to save the lexing state. The scope will be
1660 * ended in S_sublex_done. Returns a '(', starting the function arguments
1661 * to the uc, lc, etc. found before.
1662 * Sets PL_lex_state to LEX_INTERPCONCAT.
1671 PL_lex_state = PL_sublex_info.super_state;
1672 SAVEBOOL(PL_lex_dojoin);
1673 SAVEI32(PL_lex_brackets);
1674 SAVEI32(PL_lex_casemods);
1675 SAVEI32(PL_lex_starts);
1676 SAVEI8(PL_lex_state);
1677 SAVEVPTR(PL_lex_inpat);
1678 SAVEI16(PL_lex_inwhat);
1679 SAVECOPLINE(PL_curcop);
1680 SAVEPPTR(PL_bufptr);
1681 SAVEPPTR(PL_bufend);
1682 SAVEPPTR(PL_oldbufptr);
1683 SAVEPPTR(PL_oldoldbufptr);
1684 SAVEPPTR(PL_last_lop);
1685 SAVEPPTR(PL_last_uni);
1686 SAVEPPTR(PL_linestart);
1687 SAVESPTR(PL_linestr);
1688 SAVEGENERICPV(PL_lex_brackstack);
1689 SAVEGENERICPV(PL_lex_casestack);
1691 PL_linestr = PL_lex_stuff;
1692 PL_lex_stuff = NULL;
1694 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1695 = SvPVX(PL_linestr);
1696 PL_bufend += SvCUR(PL_linestr);
1697 PL_last_lop = PL_last_uni = NULL;
1698 SAVEFREESV(PL_linestr);
1700 PL_lex_dojoin = FALSE;
1701 PL_lex_brackets = 0;
1702 Newx(PL_lex_brackstack, 120, char);
1703 Newx(PL_lex_casestack, 12, char);
1704 PL_lex_casemods = 0;
1705 *PL_lex_casestack = '\0';
1707 PL_lex_state = LEX_INTERPCONCAT;
1708 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1710 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1711 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1712 PL_lex_inpat = PL_sublex_info.sub_op;
1714 PL_lex_inpat = NULL;
1721 * Restores lexer state after a S_sublex_push.
1728 if (!PL_lex_starts++) {
1729 SV * const sv = newSVpvs("");
1730 if (SvUTF8(PL_linestr))
1732 PL_expect = XOPERATOR;
1733 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1737 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1738 PL_lex_state = LEX_INTERPCASEMOD;
1742 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1743 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1744 PL_linestr = PL_lex_repl;
1746 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1747 PL_bufend += SvCUR(PL_linestr);
1748 PL_last_lop = PL_last_uni = NULL;
1749 SAVEFREESV(PL_linestr);
1750 PL_lex_dojoin = FALSE;
1751 PL_lex_brackets = 0;
1752 PL_lex_casemods = 0;
1753 *PL_lex_casestack = '\0';
1755 if (SvEVALED(PL_lex_repl)) {
1756 PL_lex_state = LEX_INTERPNORMAL;
1758 /* we don't clear PL_lex_repl here, so that we can check later
1759 whether this is an evalled subst; that means we rely on the
1760 logic to ensure sublex_done() is called again only via the
1761 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1764 PL_lex_state = LEX_INTERPCONCAT;
1774 PL_endwhite = newSVpvs("");
1775 sv_catsv(PL_endwhite, PL_thiswhite);
1779 sv_setpvn(PL_thistoken,"",0);
1781 PL_realtokenstart = -1;
1785 PL_bufend = SvPVX(PL_linestr);
1786 PL_bufend += SvCUR(PL_linestr);
1787 PL_expect = XOPERATOR;
1788 PL_sublex_info.sub_inwhat = 0;
1796 Extracts a pattern, double-quoted string, or transliteration. This
1799 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
1800 processing a pattern (PL_lex_inpat is true), a transliteration
1801 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
1803 Returns a pointer to the character scanned up to. If this is
1804 advanced from the start pointer supplied (i.e. if anything was
1805 successfully parsed), will leave an OP for the substring scanned
1806 in yylval. Caller must intuit reason for not parsing further
1807 by looking at the next characters herself.
1811 double-quoted style: \r and \n
1812 regexp special ones: \D \s
1815 case and quoting: \U \Q \E
1816 stops on @ and $, but not for $ as tail anchor
1818 In transliterations:
1819 characters are VERY literal, except for - not at the start or end
1820 of the string, which indicates a range. If the range is in bytes,
1821 scan_const expands the range to the full set of intermediate
1822 characters. If the range is in utf8, the hyphen is replaced with
1823 a certain range mark which will be handled by pmtrans() in op.c.
1825 In double-quoted strings:
1827 double-quoted style: \r and \n
1829 deprecated backrefs: \1 (in substitution replacements)
1830 case and quoting: \U \Q \E
1833 scan_const does *not* construct ops to handle interpolated strings.
1834 It stops processing as soon as it finds an embedded $ or @ variable
1835 and leaves it to the caller to work out what's going on.
1837 embedded arrays (whether in pattern or not) could be:
1838 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1840 $ in double-quoted strings must be the symbol of an embedded scalar.
1842 $ in pattern could be $foo or could be tail anchor. Assumption:
1843 it's a tail anchor if $ is the last thing in the string, or if it's
1844 followed by one of "()| \r\n\t"
1846 \1 (backreferences) are turned into $1
1848 The structure of the code is
1849 while (there's a character to process) {
1850 handle transliteration ranges
1851 skip regexp comments /(?#comment)/ and codes /(?{code})/
1852 skip #-initiated comments in //x patterns
1853 check for embedded arrays
1854 check for embedded scalars
1856 leave intact backslashes from leaveit (below)
1857 deprecate \1 in substitution replacements
1858 handle string-changing backslashes \l \U \Q \E, etc.
1859 switch (what was escaped) {
1860 handle \- in a transliteration (becomes a literal -)
1861 handle \132 (octal characters)
1862 handle \x15 and \x{1234} (hex characters)
1863 handle \N{name} (named characters)
1864 handle \cV (control characters)
1865 handle printf-style backslashes (\f, \r, \n, etc)
1867 } (end if backslash)
1868 } (end while character to read)
1873 S_scan_const(pTHX_ char *start)
1876 register char *send = PL_bufend; /* end of the constant */
1877 SV *sv = newSV(send - start); /* sv for the constant */
1878 register char *s = start; /* start of the constant */
1879 register char *d = SvPVX(sv); /* destination for copies */
1880 bool dorange = FALSE; /* are we in a translit range? */
1881 bool didrange = FALSE; /* did we just finish a range? */
1882 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1883 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1886 UV literal_endpoint = 0;
1887 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
1890 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1891 /* If we are doing a trans and we know we want UTF8 set expectation */
1892 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1893 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1897 while (s < send || dorange) {
1898 /* get transliterations out of the way (they're most literal) */
1899 if (PL_lex_inwhat == OP_TRANS) {
1900 /* expand a range A-Z to the full set of characters. AIE! */
1902 I32 i; /* current expanded character */
1903 I32 min; /* first character in range */
1904 I32 max; /* last character in range */
1915 char * const c = (char*)utf8_hop((U8*)d, -1);
1919 *c = (char)UTF_TO_NATIVE(0xff);
1920 /* mark the range as done, and continue */
1926 i = d - SvPVX_const(sv); /* remember current offset */
1929 SvLEN(sv) + (has_utf8 ?
1930 (512 - UTF_CONTINUATION_MARK +
1933 /* How many two-byte within 0..255: 128 in UTF-8,
1934 * 96 in UTF-8-mod. */
1936 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1938 d = SvPVX(sv) + i; /* refresh d after realloc */
1942 for (j = 0; j <= 1; j++) {
1943 char * const c = (char*)utf8_hop((U8*)d, -1);
1944 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
1950 max = (U8)0xff; /* only to \xff */
1951 uvmax = uv; /* \x{100} to uvmax */
1953 d = c; /* eat endpoint chars */
1958 d -= 2; /* eat the first char and the - */
1959 min = (U8)*d; /* first char in range */
1960 max = (U8)d[1]; /* last char in range */
1967 "Invalid range \"%c-%c\" in transliteration operator",
1968 (char)min, (char)max);
1972 if (literal_endpoint == 2 &&
1973 ((isLOWER(min) && isLOWER(max)) ||
1974 (isUPPER(min) && isUPPER(max)))) {
1976 for (i = min; i <= max; i++)
1978 *d++ = NATIVE_TO_NEED(has_utf8,i);
1980 for (i = min; i <= max; i++)
1982 *d++ = NATIVE_TO_NEED(has_utf8,i);
1987 for (i = min; i <= max; i++)
1990 const U8 ch = (U8)NATIVE_TO_UTF(i);
1991 if (UNI_IS_INVARIANT(ch))
1994 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
1995 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
2004 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
2006 *d++ = (char)UTF_TO_NATIVE(0xff);
2008 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
2012 /* mark the range as done, and continue */
2016 literal_endpoint = 0;
2021 /* range begins (ignore - as first or last char) */
2022 else if (*s == '-' && s+1 < send && s != start) {
2024 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
2031 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
2041 literal_endpoint = 0;
2042 native_range = TRUE;
2047 /* if we get here, we're not doing a transliteration */
2049 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2050 except for the last char, which will be done separately. */
2051 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
2053 while (s+1 < send && *s != ')')
2054 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2056 else if (s[2] == '{' /* This should match regcomp.c */
2057 || (s[2] == '?' && s[3] == '{'))
2060 char *regparse = s + (s[2] == '{' ? 3 : 4);
2063 while (count && (c = *regparse)) {
2064 if (c == '\\' && regparse[1])
2072 if (*regparse != ')')
2073 regparse--; /* Leave one char for continuation. */
2074 while (s < regparse)
2075 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2079 /* likewise skip #-initiated comments in //x patterns */
2080 else if (*s == '#' && PL_lex_inpat &&
2081 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2082 while (s+1 < send && *s != '\n')
2083 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2086 /* check for embedded arrays
2087 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2089 else if (*s == '@' && s[1]) {
2090 if (isALNUM_lazy_if(s+1,UTF))
2092 if (strchr(":'{$", s[1]))
2094 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2095 break; /* in regexp, neither @+ nor @- are interpolated */
2098 /* check for embedded scalars. only stop if we're sure it's a
2101 else if (*s == '$') {
2102 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
2104 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
2105 break; /* in regexp, $ might be tail anchor */
2108 /* End of else if chain - OP_TRANS rejoin rest */
2111 if (*s == '\\' && s+1 < send) {
2114 /* deprecate \1 in strings and substitution replacements */
2115 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2116 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2118 if (ckWARN(WARN_SYNTAX))
2119 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2124 /* string-change backslash escapes */
2125 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2129 /* skip any other backslash escapes in a pattern */
2130 else if (PL_lex_inpat) {
2131 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2132 goto default_action;
2135 /* if we get here, it's either a quoted -, or a digit */
2138 /* quoted - in transliterations */
2140 if (PL_lex_inwhat == OP_TRANS) {
2147 if ((isALPHA(*s) || isDIGIT(*s)) &&
2149 Perl_warner(aTHX_ packWARN(WARN_MISC),
2150 "Unrecognized escape \\%c passed through",
2152 /* default action is to copy the quoted character */
2153 goto default_action;
2156 /* \132 indicates an octal constant */
2157 case '0': case '1': case '2': case '3':
2158 case '4': case '5': case '6': case '7':
2162 uv = grok_oct(s, &len, &flags, NULL);
2165 goto NUM_ESCAPE_INSERT;
2167 /* \x24 indicates a hex constant */
2171 char* const e = strchr(s, '}');
2172 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2173 PERL_SCAN_DISALLOW_PREFIX;
2178 yyerror("Missing right brace on \\x{}");
2182 uv = grok_hex(s, &len, &flags, NULL);
2188 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2189 uv = grok_hex(s, &len, &flags, NULL);
2195 /* Insert oct or hex escaped character.
2196 * There will always enough room in sv since such
2197 * escapes will be longer than any UTF-8 sequence
2198 * they can end up as. */
2200 /* We need to map to chars to ASCII before doing the tests
2203 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2204 if (!has_utf8 && uv > 255) {
2205 /* Might need to recode whatever we have
2206 * accumulated so far if it contains any
2209 * (Can't we keep track of that and avoid
2210 * this rescan? --jhi)
2214 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2215 if (!NATIVE_IS_INVARIANT(*c)) {
2220 const STRLEN offset = d - SvPVX_const(sv);
2222 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2226 while (src >= (const U8 *)SvPVX_const(sv)) {
2227 if (!NATIVE_IS_INVARIANT(*src)) {
2228 const U8 ch = NATIVE_TO_ASCII(*src);
2229 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2230 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2240 if (has_utf8 || uv > 255) {
2241 d = (char*)uvchr_to_utf8((U8*)d, uv);
2243 if (PL_lex_inwhat == OP_TRANS &&
2244 PL_sublex_info.sub_op) {
2245 PL_sublex_info.sub_op->op_private |=
2246 (PL_lex_repl ? OPpTRANS_FROM_UTF
2250 if (uv > 255 && !dorange)
2251 native_range = FALSE;
2263 /* \N{LATIN SMALL LETTER A} is a named character */
2267 char* e = strchr(s, '}');
2274 yyerror("Missing right brace on \\N{}");
2278 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2280 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2281 PERL_SCAN_DISALLOW_PREFIX;
2284 uv = grok_hex(s, &len, &flags, NULL);
2285 if ( e > s && len != (STRLEN)(e - s) ) {
2289 goto NUM_ESCAPE_INSERT;
2291 res = newSVpvn(s + 1, e - s - 1);
2292 type = newSVpvn(s - 2,e - s + 3);
2293 res = new_constant( NULL, 0, "charnames",
2294 res, NULL, SvPVX(type) );
2297 sv_utf8_upgrade(res);
2298 str = SvPV_const(res,len);
2299 #ifdef EBCDIC_NEVER_MIND
2300 /* charnames uses pack U and that has been
2301 * recently changed to do the below uni->native
2302 * mapping, so this would be redundant (and wrong,
2303 * the code point would be doubly converted).
2304 * But leave this in just in case the pack U change
2305 * gets revoked, but the semantics is still
2306 * desireable for charnames. --jhi */
2308 UV uv = utf8_to_uvchr((const U8*)str, 0);
2311 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2313 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2314 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2315 str = SvPV_const(res, len);
2319 if (!has_utf8 && SvUTF8(res)) {
2320 const char * const ostart = SvPVX_const(sv);
2321 SvCUR_set(sv, d - ostart);
2324 sv_utf8_upgrade(sv);
2325 /* this just broke our allocation above... */
2326 SvGROW(sv, (STRLEN)(send - start));
2327 d = SvPVX(sv) + SvCUR(sv);
2330 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2331 const char * const odest = SvPVX_const(sv);
2333 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2334 d = SvPVX(sv) + (d - odest);
2338 native_range = FALSE; /* \N{} is guessed to be Unicode */
2340 Copy(str, d, len, char);
2347 yyerror("Missing braces on \\N{}");
2350 /* \c is a control character */
2359 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2362 yyerror("Missing control char name in \\c");
2366 /* printf-style backslashes, formfeeds, newlines, etc */
2368 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2371 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2374 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2377 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2380 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2383 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2386 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2392 } /* end if (backslash) */
2399 /* If we started with encoded form, or already know we want it
2400 and then encode the next character */
2401 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2403 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2404 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2407 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2408 const STRLEN off = d - SvPVX_const(sv);
2409 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2411 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2414 if (uv > 255 && !dorange)
2415 native_range = FALSE;
2419 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2421 } /* while loop to process each character */
2423 /* terminate the string and set up the sv */
2425 SvCUR_set(sv, d - SvPVX_const(sv));
2426 if (SvCUR(sv) >= SvLEN(sv))
2427 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2430 if (PL_encoding && !has_utf8) {
2431 sv_recode_to_utf8(sv, PL_encoding);
2437 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2438 PL_sublex_info.sub_op->op_private |=
2439 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2443 /* shrink the sv if we allocated more than we used */
2444 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2445 SvPV_shrink_to_cur(sv);
2448 /* return the substring (via yylval) only if we parsed anything */
2449 if (s > PL_bufptr) {
2450 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2451 sv = new_constant(start, s - start,
2452 (const char *)(PL_lex_inpat ? "qr" : "q"),
2455 (( PL_lex_inwhat == OP_TRANS
2457 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2460 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2467 * Returns TRUE if there's more to the expression (e.g., a subscript),
2470 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2472 * ->[ and ->{ return TRUE
2473 * { and [ outside a pattern are always subscripts, so return TRUE
2474 * if we're outside a pattern and it's not { or [, then return FALSE
2475 * if we're in a pattern and the first char is a {
2476 * {4,5} (any digits around the comma) returns FALSE
2477 * if we're in a pattern and the first char is a [
2479 * [SOMETHING] has a funky algorithm to decide whether it's a
2480 * character class or not. It has to deal with things like
2481 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2482 * anything else returns TRUE
2485 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2488 S_intuit_more(pTHX_ register char *s)
2491 if (PL_lex_brackets)
2493 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2495 if (*s != '{' && *s != '[')
2500 /* In a pattern, so maybe we have {n,m}. */
2517 /* On the other hand, maybe we have a character class */
2520 if (*s == ']' || *s == '^')
2523 /* this is terrifying, and it works */
2524 int weight = 2; /* let's weigh the evidence */
2526 unsigned char un_char = 255, last_un_char;
2527 const char * const send = strchr(s,']');
2528 char tmpbuf[sizeof PL_tokenbuf * 4];
2530 if (!send) /* has to be an expression */
2533 Zero(seen,256,char);
2536 else if (isDIGIT(*s)) {
2538 if (isDIGIT(s[1]) && s[2] == ']')
2544 for (; s < send; s++) {
2545 last_un_char = un_char;
2546 un_char = (unsigned char)*s;
2551 weight -= seen[un_char] * 10;
2552 if (isALNUM_lazy_if(s+1,UTF)) {
2554 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2555 len = (int)strlen(tmpbuf);
2556 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2561 else if (*s == '$' && s[1] &&
2562 strchr("[#!%*<>()-=",s[1])) {
2563 if (/*{*/ strchr("])} =",s[2]))
2572 if (strchr("wds]",s[1]))
2574 else if (seen[(U8)'\''] || seen[(U8)'"'])
2576 else if (strchr("rnftbxcav",s[1]))
2578 else if (isDIGIT(s[1])) {
2580 while (s[1] && isDIGIT(s[1]))
2590 if (strchr("aA01! ",last_un_char))
2592 if (strchr("zZ79~",s[1]))
2594 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2595 weight -= 5; /* cope with negative subscript */
2598 if (!isALNUM(last_un_char)
2599 && !(last_un_char == '$' || last_un_char == '@'
2600 || last_un_char == '&')
2601 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2606 if (keyword(tmpbuf, d - tmpbuf, 0))
2609 if (un_char == last_un_char + 1)
2611 weight -= seen[un_char];
2616 if (weight >= 0) /* probably a character class */
2626 * Does all the checking to disambiguate
2628 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2629 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2631 * First argument is the stuff after the first token, e.g. "bar".
2633 * Not a method if bar is a filehandle.
2634 * Not a method if foo is a subroutine prototyped to take a filehandle.
2635 * Not a method if it's really "Foo $bar"
2636 * Method if it's "foo $bar"
2637 * Not a method if it's really "print foo $bar"
2638 * Method if it's really "foo package::" (interpreted as package->foo)
2639 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2640 * Not a method if bar is a filehandle or package, but is quoted with
2645 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2648 char *s = start + (*start == '$');
2649 char tmpbuf[sizeof PL_tokenbuf];
2657 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2661 const char *proto = SvPVX_const(cv);
2672 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2673 /* start is the beginning of the possible filehandle/object,
2674 * and s is the end of it
2675 * tmpbuf is a copy of it
2678 if (*start == '$') {
2679 if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
2680 isUPPER(*PL_tokenbuf))
2683 len = start - SvPVX(PL_linestr);
2687 start = SvPVX(PL_linestr) + len;
2691 return *s == '(' ? FUNCMETH : METHOD;
2693 if (!keyword(tmpbuf, len, 0)) {
2694 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2698 soff = s - SvPVX(PL_linestr);
2702 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2703 if (indirgv && GvCVu(indirgv))
2705 /* filehandle or package name makes it a method */
2706 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
2708 soff = s - SvPVX(PL_linestr);
2711 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2712 return 0; /* no assumptions -- "=>" quotes bearword */
2714 start_force(PL_curforce);
2715 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2716 newSVpvn(tmpbuf,len));
2717 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2719 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2724 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2726 return *s == '(' ? FUNCMETH : METHOD;
2734 * Return a string of Perl code to load the debugger. If PERL5DB
2735 * is set, it will return the contents of that, otherwise a
2736 * compile-time require of perl5db.pl.
2744 const char * const pdb = PerlEnv_getenv("PERL5DB");
2748 SETERRNO(0,SS_NORMAL);
2749 return "BEGIN { require 'perl5db.pl' }";
2755 /* Encoded script support. filter_add() effectively inserts a
2756 * 'pre-processing' function into the current source input stream.
2757 * Note that the filter function only applies to the current source file
2758 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2760 * The datasv parameter (which may be NULL) can be used to pass
2761 * private data to this instance of the filter. The filter function
2762 * can recover the SV using the FILTER_DATA macro and use it to
2763 * store private buffers and state information.
2765 * The supplied datasv parameter is upgraded to a PVIO type
2766 * and the IoDIRP/IoANY field is used to store the function pointer,
2767 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2768 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2769 * private use must be set using malloc'd pointers.
2773 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2782 if (!PL_rsfp_filters)
2783 PL_rsfp_filters = newAV();
2786 SvUPGRADE(datasv, SVt_PVIO);
2787 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2788 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2789 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2790 FPTR2DPTR(void *, IoANY(datasv)),
2791 SvPV_nolen(datasv)));
2792 av_unshift(PL_rsfp_filters, 1);
2793 av_store(PL_rsfp_filters, 0, datasv) ;
2798 /* Delete most recently added instance of this filter function. */
2800 Perl_filter_del(pTHX_ filter_t funcp)
2806 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2807 FPTR2DPTR(void*, funcp)));
2809 if (!PL_parser || !PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2811 /* if filter is on top of stack (usual case) just pop it off */
2812 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2813 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2814 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2815 IoANY(datasv) = (void *)NULL;
2816 sv_free(av_pop(PL_rsfp_filters));
2820 /* we need to search for the correct entry and clear it */
2821 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2825 /* Invoke the idxth filter function for the current rsfp. */
2826 /* maxlen 0 = read one text line */
2828 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2833 /* This API is bad. It should have been using unsigned int for maxlen.
2834 Not sure if we want to change the API, but if not we should sanity
2835 check the value here. */
2836 const unsigned int correct_length
2845 if (!PL_parser || !PL_rsfp_filters)
2847 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2848 /* Provide a default input filter to make life easy. */
2849 /* Note that we append to the line. This is handy. */
2850 DEBUG_P(PerlIO_printf(Perl_debug_log,
2851 "filter_read %d: from rsfp\n", idx));
2852 if (correct_length) {
2855 const int old_len = SvCUR(buf_sv);
2857 /* ensure buf_sv is large enough */
2858 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2859 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2860 correct_length)) <= 0) {
2861 if (PerlIO_error(PL_rsfp))
2862 return -1; /* error */
2864 return 0 ; /* end of file */
2866 SvCUR_set(buf_sv, old_len + len) ;
2869 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2870 if (PerlIO_error(PL_rsfp))
2871 return -1; /* error */
2873 return 0 ; /* end of file */
2876 return SvCUR(buf_sv);
2878 /* Skip this filter slot if filter has been deleted */
2879 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2880 DEBUG_P(PerlIO_printf(Perl_debug_log,
2881 "filter_read %d: skipped (filter deleted)\n",
2883 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2885 /* Get function pointer hidden within datasv */
2886 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2887 DEBUG_P(PerlIO_printf(Perl_debug_log,
2888 "filter_read %d: via function %p (%s)\n",
2889 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2890 /* Call function. The function is expected to */
2891 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2892 /* Return: <0:error, =0:eof, >0:not eof */
2893 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2897 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2900 #ifdef PERL_CR_FILTER
2901 if (!PL_rsfp_filters) {
2902 filter_add(S_cr_textfilter,NULL);
2905 if (PL_rsfp_filters) {
2907 SvCUR_set(sv, 0); /* start with empty line */
2908 if (FILTER_READ(0, sv, 0) > 0)
2909 return ( SvPVX(sv) ) ;
2914 return (sv_gets(sv, fp, append));
2918 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2923 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2927 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2928 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2930 return GvHV(gv); /* Foo:: */
2933 /* use constant CLASS => 'MyClass' */
2934 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2935 if (gv && GvCV(gv)) {
2936 SV * const sv = cv_const_sv(GvCV(gv));
2938 pkgname = SvPV_nolen_const(sv);
2941 return gv_stashpv(pkgname, 0);
2945 * S_readpipe_override
2946 * Check whether readpipe() is overriden, and generates the appropriate
2947 * optree, provided sublex_start() is called afterwards.
2950 S_readpipe_override(pTHX)
2953 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
2954 yylval.ival = OP_BACKTICK;
2956 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
2958 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
2959 && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
2960 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
2962 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
2963 append_elem(OP_LIST,
2964 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
2965 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
2975 * The intent of this yylex wrapper is to minimize the changes to the
2976 * tokener when we aren't interested in collecting madprops. It remains
2977 * to be seen how successful this strategy will be...
2984 char *s = PL_bufptr;
2986 /* make sure PL_thiswhite is initialized */
2990 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2991 if (PL_pending_ident)
2992 return S_pending_ident(aTHX);
2994 /* previous token ate up our whitespace? */
2995 if (!PL_lasttoke && PL_nextwhite) {
2996 PL_thiswhite = PL_nextwhite;
3000 /* isolate the token, and figure out where it is without whitespace */
3001 PL_realtokenstart = -1;
3005 assert(PL_curforce < 0);
3007 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
3008 if (!PL_thistoken) {
3009 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
3010 PL_thistoken = newSVpvs("");
3012 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
3013 PL_thistoken = newSVpvn(tstart, s - tstart);
3016 if (PL_thismad) /* install head */
3017 CURMAD('X', PL_thistoken);
3020 /* last whitespace of a sublex? */
3021 if (optype == ')' && PL_endwhite) {
3022 CURMAD('X', PL_endwhite);
3027 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
3028 if (!PL_thiswhite && !PL_endwhite && !optype) {
3029 sv_free(PL_thistoken);
3034 /* put off final whitespace till peg */
3035 if (optype == ';' && !PL_rsfp) {
3036 PL_nextwhite = PL_thiswhite;
3039 else if (PL_thisopen) {
3040 CURMAD('q', PL_thisopen);
3042 sv_free(PL_thistoken);
3046 /* Store actual token text as madprop X */
3047 CURMAD('X', PL_thistoken);
3051 /* add preceding whitespace as madprop _ */
3052 CURMAD('_', PL_thiswhite);
3056 /* add quoted material as madprop = */
3057 CURMAD('=', PL_thisstuff);
3061 /* add terminating quote as madprop Q */
3062 CURMAD('Q', PL_thisclose);
3066 /* special processing based on optype */
3070 /* opval doesn't need a TOKEN since it can already store mp */
3081 append_madprops(PL_thismad, yylval.opval, 0);
3089 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3098 /* remember any fake bracket that lexer is about to discard */
3099 if (PL_lex_brackets == 1 &&
3100 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3103 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3106 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3107 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3110 break; /* don't bother looking for trailing comment */
3119 /* attach a trailing comment to its statement instead of next token */
3123 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3125 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3127 if (*s == '\n' || *s == '#') {
3128 while (s < PL_bufend && *s != '\n')
3132 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3133 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3150 /* Create new token struct. Note: opvals return early above. */
3151 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
3158 S_tokenize_use(pTHX_ int is_use, char *s) {
3160 if (PL_expect != XSTATE)
3161 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3162 is_use ? "use" : "no"));
3164 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3165 s = force_version(s, TRUE);
3166 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3167 start_force(PL_curforce);
3168 NEXTVAL_NEXTTOKE.opval = NULL;
3171 else if (*s == 'v') {
3172 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3173 s = force_version(s, FALSE);
3177 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3178 s = force_version(s, FALSE);
3180 yylval.ival = is_use;
3184 static const char* const exp_name[] =
3185 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3186 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3193 Works out what to call the token just pulled out of the input
3194 stream. The yacc parser takes care of taking the ops we return and
3195 stitching them into a tree.
3201 if read an identifier
3202 if we're in a my declaration
3203 croak if they tried to say my($foo::bar)
3204 build the ops for a my() declaration
3205 if it's an access to a my() variable
3206 are we in a sort block?
3207 croak if my($a); $a <=> $b
3208 build ops for access to a my() variable
3209 if in a dq string, and they've said @foo and we can't find @foo
3211 build ops for a bareword
3212 if we already built the token before, use it.
3217 #pragma segment Perl_yylex
3223 register char *s = PL_bufptr;
3228 /* orig_keyword, gvp, and gv are initialized here because
3229 * jump to the label just_a_word_zero can bypass their
3230 * initialization later. */
3231 I32 orig_keyword = 0;
3236 SV* tmp = newSVpvs("");
3237 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3238 (IV)CopLINE(PL_curcop),
3239 lex_state_names[PL_lex_state],
3240 exp_name[PL_expect],
3241 pv_display(tmp, s, strlen(s), 0, 60));
3244 /* check if there's an identifier for us to look at */
3245 if (PL_pending_ident)
3246 return REPORT(S_pending_ident(aTHX));
3248 /* no identifier pending identification */
3250 switch (PL_lex_state) {
3252 case LEX_NORMAL: /* Some compilers will produce faster */
3253 case LEX_INTERPNORMAL: /* code if we comment these out. */
3257 /* when we've already built the next token, just pull it out of the queue */
3261 yylval = PL_nexttoke[PL_lasttoke].next_val;
3263 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3264 PL_nexttoke[PL_lasttoke].next_mad = 0;
3265 if (PL_thismad && PL_thismad->mad_key == '_') {
3266 PL_thiswhite = (SV*)PL_thismad->mad_val;
3267 PL_thismad->mad_val = 0;
3268 mad_free(PL_thismad);
3273 PL_lex_state = PL_lex_defer;
3274 PL_expect = PL_lex_expect;
3275 PL_lex_defer = LEX_NORMAL;
3276 if (!PL_nexttoke[PL_lasttoke].next_type)
3281 yylval = PL_nextval[PL_nexttoke];
3283 PL_lex_state = PL_lex_defer;
3284 PL_expect = PL_lex_expect;
3285 PL_lex_defer = LEX_NORMAL;
3289 /* FIXME - can these be merged? */
3290 return(PL_nexttoke[PL_lasttoke].next_type);
3292 return REPORT(PL_nexttype[PL_nexttoke]);
3295 /* interpolated case modifiers like \L \U, including \Q and \E.
3296 when we get here, PL_bufptr is at the \
3298 case LEX_INTERPCASEMOD:
3300 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3301 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3303 /* handle \E or end of string */
3304 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3306 if (PL_lex_casemods) {
3307 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3308 PL_lex_casestack[PL_lex_casemods] = '\0';
3310 if (PL_bufptr != PL_bufend
3311 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3313 PL_lex_state = LEX_INTERPCONCAT;
3316 PL_thistoken = newSVpvs("\\E");
3322 while (PL_bufptr != PL_bufend &&
3323 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3325 PL_thiswhite = newSVpvs("");
3326 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3330 if (PL_bufptr != PL_bufend)
3333 PL_lex_state = LEX_INTERPCONCAT;
3337 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3338 "### Saw case modifier\n"); });
3340 if (s[1] == '\\' && s[2] == 'E') {
3343 PL_thiswhite = newSVpvs("");
3344 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3347 PL_lex_state = LEX_INTERPCONCAT;
3352 if (!PL_madskills) /* when just compiling don't need correct */
3353 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3354 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3355 if ((*s == 'L' || *s == 'U') &&
3356 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3357 PL_lex_casestack[--PL_lex_casemods] = '\0';
3360 if (PL_lex_casemods > 10)
3361 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3362 PL_lex_casestack[PL_lex_casemods++] = *s;
3363 PL_lex_casestack[PL_lex_casemods] = '\0';
3364 PL_lex_state = LEX_INTERPCONCAT;
3365 start_force(PL_curforce);
3366 NEXTVAL_NEXTTOKE.ival = 0;
3368 start_force(PL_curforce);
3370 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3372 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3374 NEXTVAL_NEXTTOKE.ival = OP_LC;
3376 NEXTVAL_NEXTTOKE.ival = OP_UC;
3378 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3380 Perl_croak(aTHX_ "panic: yylex");
3382 SV* const tmpsv = newSVpvs("");
3383 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3389 if (PL_lex_starts) {
3395 sv_free(PL_thistoken);
3396 PL_thistoken = newSVpvs("");
3399 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3400 if (PL_lex_casemods == 1 && PL_lex_inpat)
3409 case LEX_INTERPPUSH:
3410 return REPORT(sublex_push());
3412 case LEX_INTERPSTART:
3413 if (PL_bufptr == PL_bufend)
3414 return REPORT(sublex_done());
3415 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3416 "### Interpolated variable\n"); });
3418 PL_lex_dojoin = (*PL_bufptr == '@');
3419 PL_lex_state = LEX_INTERPNORMAL;
3420 if (PL_lex_dojoin) {
3421 start_force(PL_curforce);
3422 NEXTVAL_NEXTTOKE.ival = 0;
3424 start_force(PL_curforce);
3425 force_ident("\"", '$');
3426 start_force(PL_curforce);
3427 NEXTVAL_NEXTTOKE.ival = 0;
3429 start_force(PL_curforce);
3430 NEXTVAL_NEXTTOKE.ival = 0;
3432 start_force(PL_curforce);
3433 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3436 if (PL_lex_starts++) {
3441 sv_free(PL_thistoken);
3442 PL_thistoken = newSVpvs("");
3445 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3446 if (!PL_lex_casemods && PL_lex_inpat)
3453 case LEX_INTERPENDMAYBE:
3454 if (intuit_more(PL_bufptr)) {
3455 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3461 if (PL_lex_dojoin) {
3462 PL_lex_dojoin = FALSE;
3463 PL_lex_state = LEX_INTERPCONCAT;
3467 sv_free(PL_thistoken);
3468 PL_thistoken = newSVpvs("");
3473 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3474 && SvEVALED(PL_lex_repl))
3476 if (PL_bufptr != PL_bufend)
3477 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3481 case LEX_INTERPCONCAT:
3483 if (PL_lex_brackets)
3484 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3486 if (PL_bufptr == PL_bufend)
3487 return REPORT(sublex_done());
3489 if (SvIVX(PL_linestr) == '\'') {
3490 SV *sv = newSVsv(PL_linestr);
3493 else if ( PL_hints & HINT_NEW_RE )
3494 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3495 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3499 s = scan_const(PL_bufptr);
3501 PL_lex_state = LEX_INTERPCASEMOD;
3503 PL_lex_state = LEX_INTERPSTART;
3506 if (s != PL_bufptr) {
3507 start_force(PL_curforce);
3509 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3511 NEXTVAL_NEXTTOKE = yylval;
3514 if (PL_lex_starts++) {
3518 sv_free(PL_thistoken);
3519 PL_thistoken = newSVpvs("");
3522 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3523 if (!PL_lex_casemods && PL_lex_inpat)
3536 PL_lex_state = LEX_NORMAL;
3537 s = scan_formline(PL_bufptr);
3538 if (!PL_lex_formbrack)
3544 PL_oldoldbufptr = PL_oldbufptr;
3550 sv_free(PL_thistoken);
3553 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3557 if (isIDFIRST_lazy_if(s,UTF))
3559 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3562 goto fake_eof; /* emulate EOF on ^D or ^Z */
3571 if (PL_lex_brackets) {
3572 yyerror((const char *)
3574 ? "Format not terminated"
3575 : "Missing right curly or square bracket"));
3577 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3578 "### Tokener got EOF\n");
3582 if (s++ < PL_bufend)
3583 goto retry; /* ignore stray nulls */
3586 if (!PL_in_eval && !PL_preambled) {
3587 PL_preambled = TRUE;
3592 sv_setpv(PL_linestr,incl_perldb());
3593 if (SvCUR(PL_linestr))
3594 sv_catpvs(PL_linestr,";");
3596 while(AvFILLp(PL_preambleav) >= 0) {
3597 SV *tmpsv = av_shift(PL_preambleav);
3598 sv_catsv(PL_linestr, tmpsv);
3599 sv_catpvs(PL_linestr, ";");
3602 sv_free((SV*)PL_preambleav);
3603 PL_preambleav = NULL;
3605 if (PL_minus_n || PL_minus_p) {
3606 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3608 sv_catpvs(PL_linestr,"chomp;");
3611 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3612 || *PL_splitstr == '"')
3613 && strchr(PL_splitstr + 1, *PL_splitstr))
3614 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3616 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3617 bytes can be used as quoting characters. :-) */
3618 const char *splits = PL_splitstr;
3619 sv_catpvs(PL_linestr, "our @F=split(q\0");
3622 if (*splits == '\\')
3623 sv_catpvn(PL_linestr, splits, 1);
3624 sv_catpvn(PL_linestr, splits, 1);
3625 } while (*splits++);
3626 /* This loop will embed the trailing NUL of
3627 PL_linestr as the last thing it does before
3629 sv_catpvs(PL_linestr, ");");
3633 sv_catpvs(PL_linestr,"our @F=split(' ');");
3637 sv_catpvs(PL_linestr,"use feature ':5.10';");
3638 sv_catpvs(PL_linestr, "\n");
3639 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3640 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3641 PL_last_lop = PL_last_uni = NULL;
3642 if (PERLDB_LINE && PL_curstash != PL_debstash)
3643 update_debugger_info(PL_linestr, NULL, 0);
3647 bof = PL_rsfp ? TRUE : FALSE;
3648 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3651 PL_realtokenstart = -1;
3654 if (PL_preprocess && !PL_in_eval)
3655 (void)PerlProc_pclose(PL_rsfp);
3656 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3657 PerlIO_clearerr(PL_rsfp);
3659 (void)PerlIO_close(PL_rsfp);
3661 PL_doextract = FALSE;
3663 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3668 sv_setpv(PL_linestr,
3671 ? ";}continue{print;}" : ";}"));
3672 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3673 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3674 PL_last_lop = PL_last_uni = NULL;
3675 PL_minus_n = PL_minus_p = 0;
3678 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3679 PL_last_lop = PL_last_uni = NULL;
3680 sv_setpvn(PL_linestr,"",0);
3681 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3683 /* If it looks like the start of a BOM or raw UTF-16,
3684 * check if it in fact is. */
3690 #ifdef PERLIO_IS_STDIO
3691 # ifdef __GNU_LIBRARY__
3692 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3693 # define FTELL_FOR_PIPE_IS_BROKEN
3697 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3698 # define FTELL_FOR_PIPE_IS_BROKEN
3703 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3704 /* This loses the possibility to detect the bof
3705 * situation on perl -P when the libc5 is being used.
3706 * Workaround? Maybe attach some extra state to PL_rsfp?
3709 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3711 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3714 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3715 s = swallow_bom((U8*)s);
3719 /* Incest with pod. */
3722 sv_catsv(PL_thiswhite, PL_linestr);
3724 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
3725 sv_setpvn(PL_linestr, "", 0);
3726 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3727 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3728 PL_last_lop = PL_last_uni = NULL;
3729 PL_doextract = FALSE;
3733 } while (PL_doextract);
3734 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3735 if (PERLDB_LINE && PL_curstash != PL_debstash)
3736 update_debugger_info(PL_linestr, NULL, 0);
3737 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3738 PL_last_lop = PL_last_uni = NULL;
3739 if (CopLINE(PL_curcop) == 1) {
3740 while (s < PL_bufend && isSPACE(*s))
3742 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3746 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3750 if (*s == '#' && *(s+1) == '!')
3752 #ifdef ALTERNATE_SHEBANG
3754 static char const as[] = ALTERNATE_SHEBANG;
3755 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3756 d = s + (sizeof(as) - 1);
3758 #endif /* ALTERNATE_SHEBANG */
3767 while (*d && !isSPACE(*d))
3771 #ifdef ARG_ZERO_IS_SCRIPT
3772 if (ipathend > ipath) {
3774 * HP-UX (at least) sets argv[0] to the script name,
3775 * which makes $^X incorrect. And Digital UNIX and Linux,
3776 * at least, set argv[0] to the basename of the Perl
3777 * interpreter. So, having found "#!", we'll set it right.
3779 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3781 assert(SvPOK(x) || SvGMAGICAL(x));
3782 if (sv_eq(x, CopFILESV(PL_curcop))) {
3783 sv_setpvn(x, ipath, ipathend - ipath);
3789 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3790 const char * const lstart = SvPV_const(x,llen);
3792 bstart += blen - llen;
3793 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3794 sv_setpvn(x, ipath, ipathend - ipath);
3799 TAINT_NOT; /* $^X is always tainted, but that's OK */
3801 #endif /* ARG_ZERO_IS_SCRIPT */
3806 d = instr(s,"perl -");
3808 d = instr(s,"perl");
3810 /* avoid getting into infinite loops when shebang
3811 * line contains "Perl" rather than "perl" */
3813 for (d = ipathend-4; d >= ipath; --d) {
3814 if ((*d == 'p' || *d == 'P')
3815 && !ibcmp(d, "perl", 4))
3825 #ifdef ALTERNATE_SHEBANG
3827 * If the ALTERNATE_SHEBANG on this system starts with a
3828 * character that can be part of a Perl expression, then if
3829 * we see it but not "perl", we're probably looking at the
3830 * start of Perl code, not a request to hand off to some
3831 * other interpreter. Similarly, if "perl" is there, but
3832 * not in the first 'word' of the line, we assume the line
3833 * contains the start of the Perl program.
3835 if (d && *s != '#') {
3836 const char *c = ipath;
3837 while (*c && !strchr("; \t\r\n\f\v#", *c))
3840 d = NULL; /* "perl" not in first word; ignore */
3842 *s = '#'; /* Don't try to parse shebang line */
3844 #endif /* ALTERNATE_SHEBANG */
3845 #ifndef MACOS_TRADITIONAL
3850 !instr(s,"indir") &&
3851 instr(PL_origargv[0],"perl"))
3858 while (s < PL_bufend && isSPACE(*s))
3860 if (s < PL_bufend) {
3861 Newxz(newargv,PL_origargc+3,char*);
3863 while (s < PL_bufend && !isSPACE(*s))
3866 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3869 newargv = PL_origargv;
3872 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3874 Perl_croak(aTHX_ "Can't exec %s", ipath);
3878 while (*d && !isSPACE(*d))
3880 while (SPACE_OR_TAB(*d))
3884 const bool switches_done = PL_doswitches;
3885 const U32 oldpdb = PL_perldb;
3886 const bool oldn = PL_minus_n;
3887 const bool oldp = PL_minus_p;
3890 if (*d == 'M' || *d == 'm' || *d == 'C') {
3891 const char * const m = d;
3892 while (*d && !isSPACE(*d))
3894 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3897 d = moreswitches(d);
3899 if (PL_doswitches && !switches_done) {
3900 int argc = PL_origargc;
3901 char **argv = PL_origargv;
3904 } while (argc && argv[0][0] == '-' && argv[0][1]);
3905 init_argv_symbols(argc,argv);
3907 if ((PERLDB_LINE && !oldpdb) ||
3908 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3909 /* if we have already added "LINE: while (<>) {",
3910 we must not do it again */
3912 sv_setpvn(PL_linestr, "", 0);
3913 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3914 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3915 PL_last_lop = PL_last_uni = NULL;
3916 PL_preambled = FALSE;
3918 (void)gv_fetchfile(PL_origfilename);
3925 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3927 PL_lex_state = LEX_FORMLINE;
3932 #ifdef PERL_STRICT_CR
3933 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3935 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3937 case ' ': case '\t': case '\f': case 013:
3938 #ifdef MACOS_TRADITIONAL
3942 PL_realtokenstart = -1;
3944 PL_thiswhite = newSVpvs("");
3945 sv_catpvn(PL_thiswhite, s, 1);
3952 PL_realtokenstart = -1;
3956 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3957 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3958 /* handle eval qq[#line 1 "foo"\n ...] */
3959 CopLINE_dec(PL_curcop);
3962 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3964 if (!PL_in_eval || PL_rsfp)
3969 while (d < PL_bufend && *d != '\n')
3973 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3974 Perl_croak(aTHX_ "panic: input overflow");
3977 PL_thiswhite = newSVpvn(s, d - s);
3982 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3984 PL_lex_state = LEX_FORMLINE;
3990 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3991 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3994 TOKEN(PEG); /* make sure any #! line is accessible */
3999 /* if (PL_madskills && PL_lex_formbrack) { */
4001 while (d < PL_bufend && *d != '\n')
4005 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4006 Perl_croak(aTHX_ "panic: input overflow");
4007 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
4009 PL_thiswhite = newSVpvs("");
4010 if (CopLINE(PL_curcop) == 1) {
4011 sv_setpvn(PL_thiswhite, "", 0);
4014 sv_catpvn(PL_thiswhite, s, d - s);
4028 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
4036 while (s < PL_bufend && SPACE_OR_TAB(*s))
4039 if (strnEQ(s,"=>",2)) {
4040 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
4041 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
4042 OPERATOR('-'); /* unary minus */
4044 PL_last_uni = PL_oldbufptr;
4046 case 'r': ftst = OP_FTEREAD; break;
4047 case 'w': ftst = OP_FTEWRITE; break;
4048 case 'x': ftst = OP_FTEEXEC; break;
4049 case 'o': ftst = OP_FTEOWNED; break;
4050 case 'R': ftst = OP_FTRREAD; break;
4051 case 'W': ftst = OP_FTRWRITE; break;
4052 case 'X': ftst = OP_FTREXEC; break;
4053 case 'O': ftst = OP_FTROWNED; break;
4054 case 'e': ftst = OP_FTIS; break;
4055 case 'z': ftst = OP_FTZERO; break;
4056 case 's': ftst = OP_FTSIZE; break;
4057 case 'f': ftst = OP_FTFILE; break;
4058 case 'd': ftst = OP_FTDIR; break;
4059 case 'l': ftst = OP_FTLINK; break;
4060 case 'p': ftst = OP_FTPIPE; break;
4061 case 'S': ftst = OP_FTSOCK; break;
4062 case 'u': ftst = OP_FTSUID; break;
4063 case 'g': ftst = OP_FTSGID; break;
4064 case 'k': ftst = OP_FTSVTX; break;
4065 case 'b': ftst = OP_FTBLK; break;
4066 case 'c': ftst = OP_FTCHR; break;
4067 case 't': ftst = OP_FTTTY; break;
4068 case 'T': ftst = OP_FTTEXT; break;
4069 case 'B': ftst = OP_FTBINARY; break;
4070 case 'M': case 'A': case 'C':
4071 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
4073 case 'M': ftst = OP_FTMTIME; break;
4074 case 'A': ftst = OP_FTATIME; break;
4075 case 'C': ftst = OP_FTCTIME; break;
4083 PL_last_lop_op = (OPCODE)ftst;
4084 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4085 "### Saw file test %c\n", (int)tmp);
4090 /* Assume it was a minus followed by a one-letter named
4091 * subroutine call (or a -bareword), then. */
4092 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4093 "### '-%c' looked like a file test but was not\n",
4100 const char tmp = *s++;
4103 if (PL_expect == XOPERATOR)
4108 else if (*s == '>') {
4111 if (isIDFIRST_lazy_if(s,UTF)) {
4112 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4120 if (PL_expect == XOPERATOR)
4123 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4125 OPERATOR('-'); /* unary minus */
4131 const char tmp = *s++;
4134 if (PL_expect == XOPERATOR)
4139 if (PL_expect == XOPERATOR)
4142 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4149 if (PL_expect != XOPERATOR) {
4150 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4151 PL_expect = XOPERATOR;
4152 force_ident(PL_tokenbuf, '*');
4165 if (PL_expect == XOPERATOR) {
4169 PL_tokenbuf[0] = '%';
4170 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4171 sizeof PL_tokenbuf - 1, FALSE);
4172 if (!PL_tokenbuf[1]) {
4175 PL_pending_ident = '%';
4186 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
4193 const char tmp = *s++;
4199 goto just_a_word_zero_gv;
4202 switch (PL_expect) {
4208 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4210 PL_bufptr = s; /* update in case we back off */
4216 PL_expect = XTERMBLOCK;
4219 stuffstart = s - SvPVX(PL_linestr) - 1;
4223 while (isIDFIRST_lazy_if(s,UTF)) {
4226 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4227 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4228 if (tmp < 0) tmp = -tmp;
4243 sv = newSVpvn(s, len);
4245 d = scan_str(d,TRUE,TRUE);
4247 /* MUST advance bufptr here to avoid bogus
4248 "at end of line" context messages from yyerror().
4250 PL_bufptr = s + len;
4251 yyerror("Unterminated attribute parameter in attribute list");
4255 return REPORT(0); /* EOF indicator */
4259 sv_catsv(sv, PL_lex_stuff);
4260 attrs = append_elem(OP_LIST, attrs,
4261 newSVOP(OP_CONST, 0, sv));
4262 SvREFCNT_dec(PL_lex_stuff);
4263 PL_lex_stuff = NULL;
4266 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4268 if (PL_in_my == KEY_our) {
4270 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4272 /* skip to avoid loading attributes.pm */
4274 deprecate(":unique");
4277 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4280 /* NOTE: any CV attrs applied here need to be part of
4281 the CVf_BUILTIN_ATTRS define in cv.h! */
4282 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4284 CvLVALUE_on(PL_compcv);
4286 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4288 CvLOCKED_on(PL_compcv);
4290 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4292 CvMETHOD_on(PL_compcv);
4294 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4296 CvASSERTION_on(PL_compcv);
4298 /* After we've set the flags, it could be argued that
4299 we don't need to do the attributes.pm-based setting
4300 process, and shouldn't bother appending recognized
4301 flags. To experiment with that, uncomment the
4302 following "else". (Note that's already been
4303 uncommented. That keeps the above-applied built-in
4304 attributes from being intercepted (and possibly
4305 rejected) by a package's attribute routines, but is
4306 justified by the performance win for the common case
4307 of applying only built-in attributes.) */
4309 attrs = append_elem(OP_LIST, attrs,
4310 newSVOP(OP_CONST, 0,
4314 if (*s == ':' && s[1] != ':')
4317 break; /* require real whitespace or :'s */
4318 /* XXX losing whitespace on sequential attributes here */
4322 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4323 if (*s != ';' && *s != '}' && *s != tmp
4324 && (tmp != '=' || *s != ')')) {
4325 const char q = ((*s == '\'') ? '"' : '\'');
4326 /* If here for an expression, and parsed no attrs, back
4328 if (tmp == '=' && !attrs) {
4332 /* MUST advance bufptr here to avoid bogus "at end of line"
4333 context messages from yyerror().
4336 yyerror( (const char *)
4338 ? Perl_form(aTHX_ "Invalid separator character "
4339 "%c%c%c in attribute list", q, *s, q)
4340 : "Unterminated attribute list" ) );
4348 start_force(PL_curforce);
4349 NEXTVAL_NEXTTOKE.opval = attrs;
4350 CURMAD('_', PL_nextwhite);
4355 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4356 (s - SvPVX(PL_linestr)) - stuffstart);
4364 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4365 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4373 const char tmp = *s++;
4378 const char tmp = *s++;
4386 if (PL_lex_brackets <= 0)
4387 yyerror("Unmatched right square bracket");
4390 if (PL_lex_state == LEX_INTERPNORMAL) {
4391 if (PL_lex_brackets == 0) {
4392 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4393 PL_lex_state = LEX_INTERPEND;
4400 if (PL_lex_brackets > 100) {
4401 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4403 switch (PL_expect) {
4405 if (PL_lex_formbrack) {
4409 if (PL_oldoldbufptr == PL_last_lop)
4410 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4412 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4413 OPERATOR(HASHBRACK);
4415 while (s < PL_bufend && SPACE_OR_TAB(*s))
4418 PL_tokenbuf[0] = '\0';
4419 if (d < PL_bufend && *d == '-') {
4420 PL_tokenbuf[0] = '-';
4422 while (d < PL_bufend && SPACE_OR_TAB(*d))
4425 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4426 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4428 while (d < PL_bufend && SPACE_OR_TAB(*d))
4431 const char minus = (PL_tokenbuf[0] == '-');
4432 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4440 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4445 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4450 if (PL_oldoldbufptr == PL_last_lop)
4451 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4453 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4456 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4458 /* This hack is to get the ${} in the message. */
4460 yyerror("syntax error");
4463 OPERATOR(HASHBRACK);
4465 /* This hack serves to disambiguate a pair of curlies
4466 * as being a block or an anon hash. Normally, expectation
4467 * determines that, but in cases where we're not in a
4468 * position to expect anything in particular (like inside
4469 * eval"") we have to resolve the ambiguity. This code
4470 * covers the case where the first term in the curlies is a
4471 * quoted string. Most other cases need to be explicitly
4472 * disambiguated by prepending a "+" before the opening
4473 * curly in order to force resolution as an anon hash.
4475 * XXX should probably propagate the outer expectation
4476 * into eval"" to rely less on this hack, but that could
4477 * potentially break current behavior of eval"".
4481 if (*s == '\'' || *s == '"' || *s == '`') {
4482 /* common case: get past first string, handling escapes */
4483 for (t++; t < PL_bufend && *t != *s;)
4484 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4488 else if (*s == 'q') {
4491 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4494 /* skip q//-like construct */
4496 char open, close, term;
4499 while (t < PL_bufend && isSPACE(*t))
4501 /* check for q => */
4502 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4503 OPERATOR(HASHBRACK);
4507 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4511 for (t++; t < PL_bufend; t++) {
4512 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4514 else if (*t == open)
4518 for (t++; t < PL_bufend; t++) {
4519 if (*t == '\\' && t+1 < PL_bufend)
4521 else if (*t == close && --brackets <= 0)
4523 else if (*t == open)
4530 /* skip plain q word */
4531 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4534 else if (isALNUM_lazy_if(t,UTF)) {
4536 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4539 while (t < PL_bufend && isSPACE(*t))
4541 /* if comma follows first term, call it an anon hash */
4542 /* XXX it could be a comma expression with loop modifiers */
4543 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4544 || (*t == '=' && t[1] == '>')))
4545 OPERATOR(HASHBRACK);
4546 if (PL_expect == XREF)
4549 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4555 yylval.ival = CopLINE(PL_curcop);
4556 if (isSPACE(*s) || *s == '#')
4557 PL_copline = NOLINE; /* invalidate current command line number */
4562 if (PL_lex_brackets <= 0)
4563 yyerror("Unmatched right curly bracket");
4565 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4566 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4567 PL_lex_formbrack = 0;
4568 if (PL_lex_state == LEX_INTERPNORMAL) {
4569 if (PL_lex_brackets == 0) {
4570 if (PL_expect & XFAKEBRACK) {
4571 PL_expect &= XENUMMASK;
4572 PL_lex_state = LEX_INTERPEND;
4577 PL_thiswhite = newSVpvs("");
4578 sv_catpvn(PL_thiswhite,"}",1);
4581 return yylex(); /* ignore fake brackets */
4583 if (*s == '-' && s[1] == '>')
4584 PL_lex_state = LEX_INTERPENDMAYBE;
4585 else if (*s != '[' && *s != '{')
4586 PL_lex_state = LEX_INTERPEND;
4589 if (PL_expect & XFAKEBRACK) {
4590 PL_expect &= XENUMMASK;
4592 return yylex(); /* ignore fake brackets */
4594 start_force(PL_curforce);
4596 curmad('X', newSVpvn(s-1,1));
4597 CURMAD('_', PL_thiswhite);
4602 PL_thistoken = newSVpvs("");
4610 if (PL_expect == XOPERATOR) {
4611 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4612 && isIDFIRST_lazy_if(s,UTF))
4614 CopLINE_dec(PL_curcop);
4615 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4616 CopLINE_inc(PL_curcop);
4621 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4623 PL_expect = XOPERATOR;
4624 force_ident(PL_tokenbuf, '&');
4628 yylval.ival = (OPpENTERSUB_AMPER<<8);
4640 const char tmp = *s++;
4647 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4648 && strchr("+-*/%.^&|<",tmp))
4649 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4650 "Reversed %c= operator",(int)tmp);
4652 if (PL_expect == XSTATE && isALPHA(tmp) &&
4653 (s == PL_linestart+1 || s[-2] == '\n') )
4655 if (PL_in_eval && !PL_rsfp) {
4660 if (strnEQ(s,"=cut",4)) {
4676 PL_thiswhite = newSVpvs("");
4677 sv_catpvn(PL_thiswhite, PL_linestart,
4678 PL_bufend - PL_linestart);
4682 PL_doextract = TRUE;
4686 if (PL_lex_brackets < PL_lex_formbrack) {
4688 #ifdef PERL_STRICT_CR
4689 while (SPACE_OR_TAB(*t))
4691 while (SPACE_OR_TAB(*t) || *t == '\r')
4694 if (*t == '\n' || *t == '#') {
4705 const char tmp = *s++;
4707 /* was this !=~ where !~ was meant?
4708 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4710 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4711 const char *t = s+1;
4713 while (t < PL_bufend && isSPACE(*t))
4716 if (*t == '/' || *t == '?' ||
4717 ((*t == 'm' || *t == 's' || *t == 'y')
4718 && !isALNUM(t[1])) ||
4719 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4720 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4721 "!=~ should be !~");
4731 if (PL_expect != XOPERATOR) {
4732 if (s[1] != '<' && !strchr(s,'>'))
4735 s = scan_heredoc(s);
4737 s = scan_inputsymbol(s);
4738 TERM(sublex_start());
4744 SHop(OP_LEFT_SHIFT);
4758 const char tmp = *s++;
4760 SHop(OP_RIGHT_SHIFT);
4761 else if (tmp == '=')
4770 if (PL_expect == XOPERATOR) {
4771 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4773 deprecate_old(commaless_variable_list);
4774 return REPORT(','); /* grandfather non-comma-format format */
4778 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4779 PL_tokenbuf[0] = '@';
4780 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4781 sizeof PL_tokenbuf - 1, FALSE);
4782 if (PL_expect == XOPERATOR)
4783 no_op("Array length", s);
4784 if (!PL_tokenbuf[1])
4786 PL_expect = XOPERATOR;
4787 PL_pending_ident = '#';
4791 PL_tokenbuf[0] = '$';
4792 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4793 sizeof PL_tokenbuf - 1, FALSE);
4794 if (PL_expect == XOPERATOR)
4796 if (!PL_tokenbuf[1]) {
4798 yyerror("Final $ should be \\$ or $name");
4802 /* This kludge not intended to be bulletproof. */
4803 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4804 yylval.opval = newSVOP(OP_CONST, 0,
4805 newSViv(CopARYBASE_get(&PL_compiling)));
4806 yylval.opval->op_private = OPpCONST_ARYBASE;
4812 const char tmp = *s;
4813 if (PL_lex_state == LEX_NORMAL)
4816 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4817 && intuit_more(s)) {
4819 PL_tokenbuf[0] = '@';
4820 if (ckWARN(WARN_SYNTAX)) {
4823 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4826 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4827 while (t < PL_bufend && *t != ']')
4829 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4830 "Multidimensional syntax %.*s not supported",
4831 (int)((t - PL_bufptr) + 1), PL_bufptr);
4835 else if (*s == '{') {
4837 PL_tokenbuf[0] = '%';
4838 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4839 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4841 char tmpbuf[sizeof PL_tokenbuf];
4844 } while (isSPACE(*t));
4845 if (isIDFIRST_lazy_if(t,UTF)) {
4847 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4851 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
4852 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4853 "You need to quote \"%s\"",
4860 PL_expect = XOPERATOR;
4861 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4862 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4863 if (!islop || PL_last_lop_op == OP_GREPSTART)
4864 PL_expect = XOPERATOR;
4865 else if (strchr("$@\"'`q", *s))
4866 PL_expect = XTERM; /* e.g. print $fh "foo" */
4867 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4868 PL_expect = XTERM; /* e.g. print $fh &sub */
4869 else if (isIDFIRST_lazy_if(s,UTF)) {
4870 char tmpbuf[sizeof PL_tokenbuf];
4872 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4873 if ((t2 = keyword(tmpbuf, len, 0))) {
4874 /* binary operators exclude handle interpretations */
4886 PL_expect = XTERM; /* e.g. print $fh length() */
4891 PL_expect = XTERM; /* e.g. print $fh subr() */
4894 else if (isDIGIT(*s))
4895 PL_expect = XTERM; /* e.g. print $fh 3 */
4896 else if (*s == '.' && isDIGIT(s[1]))
4897 PL_expect = XTERM; /* e.g. print $fh .3 */
4898 else if ((*s == '?' || *s == '-' || *s == '+')
4899 && !isSPACE(s[1]) && s[1] != '=')
4900 PL_expect = XTERM; /* e.g. print $fh -1 */
4901 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4903 PL_expect = XTERM; /* e.g. print $fh /.../
4904 XXX except DORDOR operator
4906 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4908 PL_expect = XTERM; /* print $fh <<"EOF" */
4911 PL_pending_ident = '$';
4915 if (PL_expect == XOPERATOR)
4917 PL_tokenbuf[0] = '@';
4918 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4919 if (!PL_tokenbuf[1]) {
4922 if (PL_lex_state == LEX_NORMAL)
4924 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4926 PL_tokenbuf[0] = '%';
4928 /* Warn about @ where they meant $. */
4929 if (*s == '[' || *s == '{') {
4930 if (ckWARN(WARN_SYNTAX)) {
4931 const char *t = s + 1;
4932 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4934 if (*t == '}' || *t == ']') {
4936 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4937 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4938 "Scalar value %.*s better written as $%.*s",
4939 (int)(t-PL_bufptr), PL_bufptr,
4940 (int)(t-PL_bufptr-1), PL_bufptr+1);
4945 PL_pending_ident = '@';
4948 case '/': /* may be division, defined-or, or pattern */
4949 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4953 case '?': /* may either be conditional or pattern */
4954 if(PL_expect == XOPERATOR) {
4962 /* A // operator. */
4972 /* Disable warning on "study /blah/" */
4973 if (PL_oldoldbufptr == PL_last_uni
4974 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4975 || memNE(PL_last_uni, "study", 5)
4976 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4979 s = scan_pat(s,OP_MATCH);
4980 TERM(sublex_start());
4984 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4985 #ifdef PERL_STRICT_CR
4988 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4990 && (s == PL_linestart || s[-1] == '\n') )
4992 PL_lex_formbrack = 0;
4996 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
5002 yylval.ival = OPf_SPECIAL;
5008 if (PL_expect != XOPERATOR)
5013 case '0': case '1': case '2': case '3': case '4':
5014 case '5': case '6': case '7': case '8': case '9':
5015 s = scan_num(s, &yylval);
5016 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
5017 if (PL_expect == XOPERATOR)
5022 s = scan_str(s,!!PL_madskills,FALSE);
5023 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5024 if (PL_expect == XOPERATOR) {
5025 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5027 deprecate_old(commaless_variable_list);
5028 return REPORT(','); /* grandfather non-comma-format format */
5035 yylval.ival = OP_CONST;
5036 TERM(sublex_start());
5039 s = scan_str(s,!!PL_madskills,FALSE);
5040 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5041 if (PL_expect == XOPERATOR) {
5042 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5044 deprecate_old(commaless_variable_list);
5045 return REPORT(','); /* grandfather non-comma-format format */
5052 yylval.ival = OP_CONST;
5053 /* FIXME. I think that this can be const if char *d is replaced by
5054 more localised variables. */
5055 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
5056 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
5057 yylval.ival = OP_STRINGIFY;
5061 TERM(sublex_start());
5064 s = scan_str(s,!!PL_madskills,FALSE);
5065 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
5066 if (PL_expect == XOPERATOR)
5067 no_op("Backticks",s);
5070 readpipe_override();
5071 TERM(sublex_start());
5075 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
5076 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5078 if (PL_expect == XOPERATOR)
5079 no_op("Backslash",s);
5083 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
5084 char *start = s + 2;
5085 while (isDIGIT(*start) || *start == '_')
5087 if (*start == '.' && isDIGIT(start[1])) {
5088 s = scan_num(s, &yylval);
5091 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
5092 else if (!isALPHA(*start) && (PL_expect == XTERM
5093 || PL_expect == XREF || PL_expect == XSTATE
5094 || PL_expect == XTERMORDORDOR)) {
5095 /* XXX Use gv_fetchpvn rather than stomping on a const string */
5096 const char c = *start;
5099 gv = gv_fetchpv(s, 0, SVt_PVCV);
5102 s = scan_num(s, &yylval);
5109 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5151 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5153 /* Some keywords can be followed by any delimiter, including ':' */
5154 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5155 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5156 (PL_tokenbuf[0] == 'q' &&
5157 strchr("qwxr", PL_tokenbuf[1])))));
5159 /* x::* is just a word, unless x is "CORE" */
5160 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5164 while (d < PL_bufend && isSPACE(*d))
5165 d++; /* no comments skipped here, or s### is misparsed */
5167 /* Is this a label? */
5168 if (!tmp && PL_expect == XSTATE
5169 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5171 yylval.pval = CopLABEL_alloc(PL_tokenbuf);
5176 /* Check for keywords */
5177 tmp = keyword(PL_tokenbuf, len, 0);
5179 /* Is this a word before a => operator? */
5180 if (*d == '=' && d[1] == '>') {
5183 = (OP*)newSVOP(OP_CONST, 0,
5184 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5185 yylval.opval->op_private = OPpCONST_BARE;
5189 if (tmp < 0) { /* second-class keyword? */
5190 GV *ogv = NULL; /* override (winner) */
5191 GV *hgv = NULL; /* hidden (loser) */
5192 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5194 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5197 if (GvIMPORTED_CV(gv))
5199 else if (! CvMETHOD(cv))
5203 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5204 (gv = *gvp) && isGV_with_GP(gv) &&
5205 GvCVu(gv) && GvIMPORTED_CV(gv))
5212 tmp = 0; /* overridden by import or by GLOBAL */
5215 && -tmp==KEY_lock /* XXX generalizable kludge */
5218 tmp = 0; /* any sub overrides "weak" keyword */
5220 else { /* no override */
5222 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5223 Perl_warner(aTHX_ packWARN(WARN_MISC),
5224 "dump() better written as CORE::dump()");
5228 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5229 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5230 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5231 "Ambiguous call resolved as CORE::%s(), %s",
5232 GvENAME(hgv), "qualify as such or use &");
5239 default: /* not a keyword */
5240 /* Trade off - by using this evil construction we can pull the
5241 variable gv into the block labelled keylookup. If not, then
5242 we have to give it function scope so that the goto from the
5243 earlier ':' case doesn't bypass the initialisation. */
5245 just_a_word_zero_gv:
5253 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5256 SV *nextPL_nextwhite = 0;
5260 /* Get the rest if it looks like a package qualifier */
5262 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5264 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5267 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5268 *s == '\'' ? "'" : "::");
5273 if (PL_expect == XOPERATOR) {
5274 if (PL_bufptr == PL_linestart) {
5275 CopLINE_dec(PL_curcop);
5276 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5277 CopLINE_inc(PL_curcop);
5280 no_op("Bareword",s);
5283 /* Look for a subroutine with this name in current package,
5284 unless name is "Foo::", in which case Foo is a bearword
5285 (and a package name). */
5287 if (len > 2 && !PL_madskills &&
5288 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5290 if (ckWARN(WARN_BAREWORD)
5291 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5292 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5293 "Bareword \"%s\" refers to nonexistent package",
5296 PL_tokenbuf[len] = '\0';
5302 /* Mustn't actually add anything to a symbol table.
5303 But also don't want to "initialise" any placeholder
5304 constants that might already be there into full
5305 blown PVGVs with attached PVCV. */
5306 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5307 GV_NOADD_NOINIT, SVt_PVCV);
5312 /* if we saw a global override before, get the right name */
5315 sv = newSVpvs("CORE::GLOBAL::");
5316 sv_catpv(sv,PL_tokenbuf);
5319 /* If len is 0, newSVpv does strlen(), which is correct.
5320 If len is non-zero, then it will be the true length,
5321 and so the scalar will be created correctly. */
5322 sv = newSVpv(PL_tokenbuf,len);
5325 if (PL_madskills && !PL_thistoken) {
5326 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5327 PL_thistoken = newSVpv(start,s - start);
5328 PL_realtokenstart = s - SvPVX(PL_linestr);
5332 /* Presume this is going to be a bareword of some sort. */
5335 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5336 yylval.opval->op_private = OPpCONST_BARE;
5337 /* UTF-8 package name? */
5338 if (UTF && !IN_BYTES &&
5339 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5342 /* And if "Foo::", then that's what it certainly is. */
5347 /* Do the explicit type check so that we don't need to force
5348 the initialisation of the symbol table to have a real GV.
5349 Beware - gv may not really be a PVGV, cv may not really be
5350 a PVCV, (because of the space optimisations that gv_init
5351 understands) But they're true if for this symbol there is
5352 respectively a typeglob and a subroutine.
5354 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5355 /* Real typeglob, so get the real subroutine: */
5357 /* A proxy for a subroutine in this package? */
5358 : SvOK(gv) ? (CV *) gv : NULL)
5361 /* See if it's the indirect object for a list operator. */
5363 if (PL_oldoldbufptr &&
5364 PL_oldoldbufptr < PL_bufptr &&
5365 (PL_oldoldbufptr == PL_last_lop
5366 || PL_oldoldbufptr == PL_last_uni) &&
5367 /* NO SKIPSPACE BEFORE HERE! */
5368 (PL_expect == XREF ||
5369 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5371 bool immediate_paren = *s == '(';
5373 /* (Now we can afford to cross potential line boundary.) */
5374 s = SKIPSPACE2(s,nextPL_nextwhite);
5376 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5379 /* Two barewords in a row may indicate method call. */
5381 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5382 (tmp = intuit_method(s, gv, cv)))
5385 /* If not a declared subroutine, it's an indirect object. */
5386 /* (But it's an indir obj regardless for sort.) */
5387 /* Also, if "_" follows a filetest operator, it's a bareword */
5390 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5392 (PL_last_lop_op != OP_MAPSTART &&
5393 PL_last_lop_op != OP_GREPSTART))))
5394 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5395 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5398 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5403 PL_expect = XOPERATOR;
5406 s = SKIPSPACE2(s,nextPL_nextwhite);
5407 PL_nextwhite = nextPL_nextwhite;
5412 /* Is this a word before a => operator? */
5413 if (*s == '=' && s[1] == '>' && !pkgname) {
5415 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5416 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5417 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5421 /* If followed by a paren, it's certainly a subroutine. */
5426 while (SPACE_OR_TAB(*d))
5428 if (*d == ')' && (sv = gv_const_sv(gv))) {
5432 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5433 sv_catpvn(PL_thistoken, par, s - par);
5435 sv_free(PL_nextwhite);
5446 PL_nextwhite = PL_thiswhite;
5449 start_force(PL_curforce);
5451 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5452 PL_expect = XOPERATOR;
5455 PL_nextwhite = nextPL_nextwhite;
5456 curmad('X', PL_thistoken);
5457 PL_thistoken = newSVpvs("");
5465 /* If followed by var or block, call it a method (unless sub) */
5467 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5468 PL_last_lop = PL_oldbufptr;
5469 PL_last_lop_op = OP_METHOD;
5473 /* If followed by a bareword, see if it looks like indir obj. */
5476 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5477 && (tmp = intuit_method(s, gv, cv)))
5480 /* Not a method, so call it a subroutine (if defined) */
5483 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5484 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5485 "Ambiguous use of -%s resolved as -&%s()",
5486 PL_tokenbuf, PL_tokenbuf);
5487 /* Check for a constant sub */
5488 if ((sv = gv_const_sv(gv)) && !PL_madskills) {
5490 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5491 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5492 yylval.opval->op_private = 0;
5496 /* Resolve to GV now. */
5497 if (SvTYPE(gv) != SVt_PVGV) {
5498 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5499 assert (SvTYPE(gv) == SVt_PVGV);
5500 /* cv must have been some sort of placeholder, so
5501 now needs replacing with a real code reference. */
5505 op_free(yylval.opval);
5506 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5507 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5508 PL_last_lop = PL_oldbufptr;
5509 PL_last_lop_op = OP_ENTERSUB;
5510 /* Is there a prototype? */
5518 const char *proto = SvPV_const((SV*)cv, protolen);
5521 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
5523 while (*proto == ';')
5525 if (*proto == '&' && *s == '{') {
5526 sv_setpv(PL_subname,
5529 "__ANON__" : "__ANON__::__ANON__"));
5536 PL_nextwhite = PL_thiswhite;
5539 start_force(PL_curforce);
5540 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5543 PL_nextwhite = nextPL_nextwhite;
5544 curmad('X', PL_thistoken);
5545 PL_thistoken = newSVpvs("");
5552 /* Guess harder when madskills require "best effort". */
5553 if (PL_madskills && (!gv || !GvCVu(gv))) {
5554 int probable_sub = 0;
5555 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5557 else if (isALPHA(*s)) {
5561 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5562 if (!keyword(tmpbuf, tmplen, 0))
5565 while (d < PL_bufend && isSPACE(*d))
5567 if (*d == '=' && d[1] == '>')
5572 gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
5573 op_free(yylval.opval);
5574 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5575 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5576 PL_last_lop = PL_oldbufptr;
5577 PL_last_lop_op = OP_ENTERSUB;
5578 PL_nextwhite = PL_thiswhite;
5580 start_force(PL_curforce);
5581 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5583 PL_nextwhite = nextPL_nextwhite;
5584 curmad('X', PL_thistoken);
5585 PL_thistoken = newSVpvs("");
5590 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5597 /* Call it a bare word */
5599 if (PL_hints & HINT_STRICT_SUBS)
5600 yylval.opval->op_private |= OPpCONST_STRICT;
5603 if (lastchar != '-') {
5604 if (ckWARN(WARN_RESERVED)) {
5608 if (!*d && !gv_stashpv(PL_tokenbuf, 0))
5609 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5616 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5617 && ckWARN_d(WARN_AMBIGUOUS)) {
5618 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5619 "Operator or semicolon missing before %c%s",
5620 lastchar, PL_tokenbuf);
5621 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5622 "Ambiguous use of %c resolved as operator %c",
5623 lastchar, lastchar);
5629 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5630 newSVpv(CopFILE(PL_curcop),0));
5634 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5635 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5638 case KEY___PACKAGE__:
5639 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5641 ? newSVhek(HvNAME_HEK(PL_curstash))
5648 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5649 const char *pname = "main";
5650 if (PL_tokenbuf[2] == 'D')
5651 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5652 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5656 GvIOp(gv) = newIO();
5657 IoIFP(GvIOp(gv)) = PL_rsfp;
5658 #if defined(HAS_FCNTL) && defined(F_SETFD)
5660 const int fd = PerlIO_fileno(PL_rsfp);
5661 fcntl(fd,F_SETFD,fd >= 3);
5664 /* Mark this internal pseudo-handle as clean */
5665 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5667 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5668 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5669 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5671 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5672 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5673 /* if the script was opened in binmode, we need to revert
5674 * it to text mode for compatibility; but only iff it has CRs
5675 * XXX this is a questionable hack at best. */
5676 if (PL_bufend-PL_bufptr > 2
5677 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5680 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5681 loc = PerlIO_tell(PL_rsfp);
5682 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5685 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5687 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5688 #endif /* NETWARE */
5689 #ifdef PERLIO_IS_STDIO /* really? */
5690 # if defined(__BORLANDC__)
5691 /* XXX see note in do_binmode() */
5692 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5696 PerlIO_seek(PL_rsfp, loc, 0);
5700 #ifdef PERLIO_LAYERS
5703 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5704 else if (PL_encoding) {
5711 XPUSHs(PL_encoding);
5713 call_method("name", G_SCALAR);
5717 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5718 Perl_form(aTHX_ ":encoding(%"SVf")",
5727 if (PL_realtokenstart >= 0) {
5728 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5730 PL_endwhite = newSVpvs("");
5731 sv_catsv(PL_endwhite, PL_thiswhite);
5733 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5734 PL_realtokenstart = -1;
5736 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5737 SvCUR(PL_endwhite))) != Nullch) ;
5752 if (PL_expect == XSTATE) {
5759 if (*s == ':' && s[1] == ':') {
5762 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5763 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5764 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5767 else if (tmp == KEY_require || tmp == KEY_do)
5768 /* that's a way to remember we saw "CORE::" */
5781 LOP(OP_ACCEPT,XTERM);
5787 LOP(OP_ATAN2,XTERM);
5793 LOP(OP_BINMODE,XTERM);
5796 LOP(OP_BLESS,XTERM);
5805 /* When 'use switch' is in effect, continue has a dual
5806 life as a control operator. */
5808 if (!FEATURE_IS_ENABLED("switch"))
5811 /* We have to disambiguate the two senses of
5812 "continue". If the next token is a '{' then
5813 treat it as the start of a continue block;
5814 otherwise treat it as a control operator.
5826 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5843 if (!PL_cryptseen) {
5844 PL_cryptseen = TRUE;
5848 LOP(OP_CRYPT,XTERM);
5851 LOP(OP_CHMOD,XTERM);
5854 LOP(OP_CHOWN,XTERM);
5857 LOP(OP_CONNECT,XTERM);
5876 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5877 if (orig_keyword == KEY_do) {
5886 PL_hints |= HINT_BLOCK_SCOPE;
5896 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5897 LOP(OP_DBMOPEN,XTERM);
5903 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5910 yylval.ival = CopLINE(PL_curcop);
5926 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5927 UNIBRACK(OP_ENTEREVAL);
5945 case KEY_endhostent:
5951 case KEY_endservent:
5954 case KEY_endprotoent:
5965 yylval.ival = CopLINE(PL_curcop);
5967 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5970 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5973 if ((PL_bufend - p) >= 3 &&
5974 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5976 else if ((PL_bufend - p) >= 4 &&
5977 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5980 if (isIDFIRST_lazy_if(p,UTF)) {
5981 p = scan_ident(p, PL_bufend,
5982 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5986 Perl_croak(aTHX_ "Missing $ on loop variable");
5988 s = SvPVX(PL_linestr) + soff;
5994 LOP(OP_FORMLINE,XTERM);
6000 LOP(OP_FCNTL,XTERM);
6006 LOP(OP_FLOCK,XTERM);
6015 LOP(OP_GREPSTART, XREF);
6018 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6033 case KEY_getpriority:
6034 LOP(OP_GETPRIORITY,XTERM);
6036 case KEY_getprotobyname:
6039 case KEY_getprotobynumber:
6040 LOP(OP_GPBYNUMBER,XTERM);
6042 case KEY_getprotoent:
6054 case KEY_getpeername:
6055 UNI(OP_GETPEERNAME);
6057 case KEY_gethostbyname:
6060 case KEY_gethostbyaddr:
6061 LOP(OP_GHBYADDR,XTERM);
6063 case KEY_gethostent:
6066 case KEY_getnetbyname:
6069 case KEY_getnetbyaddr:
6070 LOP(OP_GNBYADDR,XTERM);
6075 case KEY_getservbyname:
6076 LOP(OP_GSBYNAME,XTERM);
6078 case KEY_getservbyport:
6079 LOP(OP_GSBYPORT,XTERM);
6081 case KEY_getservent:
6084 case KEY_getsockname:
6085 UNI(OP_GETSOCKNAME);
6087 case KEY_getsockopt:
6088 LOP(OP_GSOCKOPT,XTERM);
6103 yylval.ival = CopLINE(PL_curcop);
6114 yylval.ival = CopLINE(PL_curcop);
6118 LOP(OP_INDEX,XTERM);
6124 LOP(OP_IOCTL,XTERM);
6136 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6168 LOP(OP_LISTEN,XTERM);
6177 s = scan_pat(s,OP_MATCH);
6178 TERM(sublex_start());
6181 LOP(OP_MAPSTART, XREF);
6184 LOP(OP_MKDIR,XTERM);
6187 LOP(OP_MSGCTL,XTERM);
6190 LOP(OP_MSGGET,XTERM);
6193 LOP(OP_MSGRCV,XTERM);
6196 LOP(OP_MSGSND,XTERM);
6201 PL_in_my = (U16)tmp;
6203 if (isIDFIRST_lazy_if(s,UTF)) {
6207 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6208 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6210 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6211 if (!PL_in_my_stash) {
6214 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6218 if (PL_madskills) { /* just add type to declarator token */
6219 sv_catsv(PL_thistoken, PL_nextwhite);
6221 sv_catpvn(PL_thistoken, start, s - start);
6229 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6236 s = tokenize_use(0, s);
6240 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6247 if (isIDFIRST_lazy_if(s,UTF)) {
6249 for (d = s; isALNUM_lazy_if(d,UTF);)
6251 for (t=d; isSPACE(*t);)
6253 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6255 && !(t[0] == '=' && t[1] == '>')
6257 int parms_len = (int)(d-s);
6258 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6259 "Precedence problem: open %.*s should be open(%.*s)",
6260 parms_len, s, parms_len, s);
6266 yylval.ival = OP_OR;
6276 LOP(OP_OPEN_DIR,XTERM);
6279 checkcomma(s,PL_tokenbuf,"filehandle");
6283 checkcomma(s,PL_tokenbuf,"filehandle");
6302 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6306 LOP(OP_PIPE_OP,XTERM);
6309 s = scan_str(s,!!PL_madskills,FALSE);
6312 yylval.ival = OP_CONST;
6313 TERM(sublex_start());
6319 s = scan_str(s,!!PL_madskills,FALSE);
6322 PL_expect = XOPERATOR;
6324 if (SvCUR(PL_lex_stuff)) {
6327 d = SvPV_force(PL_lex_stuff, len);
6329 for (; isSPACE(*d) && len; --len, ++d)
6334 if (!warned && ckWARN(WARN_QW)) {
6335 for (; !isSPACE(*d) && len; --len, ++d) {
6337 Perl_warner(aTHX_ packWARN(WARN_QW),
6338 "Possible attempt to separate words with commas");
6341 else if (*d == '#') {
6342 Perl_warner(aTHX_ packWARN(WARN_QW),
6343 "Possible attempt to put comments in qw() list");
6349 for (; !isSPACE(*d) && len; --len, ++d)
6352 sv = newSVpvn(b, d-b);
6353 if (DO_UTF8(PL_lex_stuff))
6355 words = append_elem(OP_LIST, words,
6356 newSVOP(OP_CONST, 0, tokeq(sv)));
6360 start_force(PL_curforce);
6361 NEXTVAL_NEXTTOKE.opval = words;
6366 SvREFCNT_dec(PL_lex_stuff);
6367 PL_lex_stuff = NULL;
6373 s = scan_str(s,!!PL_madskills,FALSE);
6376 yylval.ival = OP_STRINGIFY;
6377 if (SvIVX(PL_lex_stuff) == '\'')
6378 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6379 TERM(sublex_start());
6382 s = scan_pat(s,OP_QR);
6383 TERM(sublex_start());
6386 s = scan_str(s,!!PL_madskills,FALSE);
6389 readpipe_override();
6390 TERM(sublex_start());
6398 s = force_version(s, FALSE);
6400 else if (*s != 'v' || !isDIGIT(s[1])
6401 || (s = force_version(s, TRUE), *s == 'v'))
6403 *PL_tokenbuf = '\0';
6404 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6405 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6406 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
6408 yyerror("<> should be quotes");
6410 if (orig_keyword == KEY_require) {
6418 PL_last_uni = PL_oldbufptr;
6419 PL_last_lop_op = OP_REQUIRE;
6421 return REPORT( (int)REQUIRE );
6427 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6431 LOP(OP_RENAME,XTERM);
6440 LOP(OP_RINDEX,XTERM);
6450 UNIDOR(OP_READLINE);
6454 UNIDOR(OP_BACKTICK);
6463 LOP(OP_REVERSE,XTERM);
6466 UNIDOR(OP_READLINK);
6474 TERM(sublex_start());
6476 TOKEN(1); /* force error */
6479 checkcomma(s,PL_tokenbuf,"filehandle");
6489 LOP(OP_SELECT,XTERM);
6495 LOP(OP_SEMCTL,XTERM);
6498 LOP(OP_SEMGET,XTERM);
6501 LOP(OP_SEMOP,XTERM);
6507 LOP(OP_SETPGRP,XTERM);
6509 case KEY_setpriority:
6510 LOP(OP_SETPRIORITY,XTERM);
6512 case KEY_sethostent:
6518 case KEY_setservent:
6521 case KEY_setprotoent:
6531 LOP(OP_SEEKDIR,XTERM);
6533 case KEY_setsockopt:
6534 LOP(OP_SSOCKOPT,XTERM);
6540 LOP(OP_SHMCTL,XTERM);
6543 LOP(OP_SHMGET,XTERM);
6546 LOP(OP_SHMREAD,XTERM);
6549 LOP(OP_SHMWRITE,XTERM);
6552 LOP(OP_SHUTDOWN,XTERM);
6561 LOP(OP_SOCKET,XTERM);
6563 case KEY_socketpair:
6564 LOP(OP_SOCKPAIR,XTERM);
6567 checkcomma(s,PL_tokenbuf,"subroutine name");
6569 if (*s == ';' || *s == ')') /* probably a close */
6570 Perl_croak(aTHX_ "sort is now a reserved word");
6572 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6576 LOP(OP_SPLIT,XTERM);
6579 LOP(OP_SPRINTF,XTERM);
6582 LOP(OP_SPLICE,XTERM);
6597 LOP(OP_SUBSTR,XTERM);
6603 char tmpbuf[sizeof PL_tokenbuf];
6604 SSize_t tboffset = 0;
6605 expectation attrful;
6606 bool have_name, have_proto;
6607 const int key = tmp;
6612 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6613 SV *subtoken = newSVpvn(tstart, s - tstart);
6617 s = SKIPSPACE2(s,tmpwhite);
6622 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6623 (*s == ':' && s[1] == ':'))
6630 attrful = XATTRBLOCK;
6631 /* remember buffer pos'n for later force_word */
6632 tboffset = s - PL_oldbufptr;
6633 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6636 nametoke = newSVpvn(s, d - s);
6638 if (memchr(tmpbuf, ':', len))
6639 sv_setpvn(PL_subname, tmpbuf, len);
6641 sv_setsv(PL_subname,PL_curstname);
6642 sv_catpvs(PL_subname,"::");
6643 sv_catpvn(PL_subname,tmpbuf,len);
6650 CURMAD('X', nametoke);
6651 CURMAD('_', tmpwhite);
6652 (void) force_word(PL_oldbufptr + tboffset, WORD,
6655 s = SKIPSPACE2(d,tmpwhite);
6662 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6663 PL_expect = XTERMBLOCK;
6664 attrful = XATTRTERM;
6665 sv_setpvn(PL_subname,"?",1);
6669 if (key == KEY_format) {
6671 PL_lex_formbrack = PL_lex_brackets + 1;
6673 PL_thistoken = subtoken;
6677 (void) force_word(PL_oldbufptr + tboffset, WORD,
6683 /* Look for a prototype */
6686 bool bad_proto = FALSE;
6687 const bool warnsyntax = ckWARN(WARN_SYNTAX);
6689 s = scan_str(s,!!PL_madskills,FALSE);
6691 Perl_croak(aTHX_ "Prototype not terminated");
6692 /* strip spaces and check for bad characters */
6693 d = SvPVX(PL_lex_stuff);
6695 for (p = d; *p; ++p) {
6698 if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
6704 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6705 "Illegal character in prototype for %"SVf" : %s",
6706 SVfARG(PL_subname), d);
6707 SvCUR_set(PL_lex_stuff, tmp);
6712 CURMAD('q', PL_thisopen);
6713 CURMAD('_', tmpwhite);
6714 CURMAD('=', PL_thisstuff);
6715 CURMAD('Q', PL_thisclose);
6716 NEXTVAL_NEXTTOKE.opval =
6717 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6718 PL_lex_stuff = Nullsv;
6721 s = SKIPSPACE2(s,tmpwhite);
6729 if (*s == ':' && s[1] != ':')
6730 PL_expect = attrful;
6731 else if (*s != '{' && key == KEY_sub) {
6733 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6735 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
6742 curmad('^', newSVpvs(""));
6743 CURMAD('_', tmpwhite);
6747 PL_thistoken = subtoken;
6750 NEXTVAL_NEXTTOKE.opval =
6751 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6752 PL_lex_stuff = NULL;
6757 sv_setpv(PL_subname,
6759 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
6763 (void) force_word(PL_oldbufptr + tboffset, WORD,
6773 LOP(OP_SYSTEM,XREF);
6776 LOP(OP_SYMLINK,XTERM);
6779 LOP(OP_SYSCALL,XTERM);
6782 LOP(OP_SYSOPEN,XTERM);
6785 LOP(OP_SYSSEEK,XTERM);
6788 LOP(OP_SYSREAD,XTERM);
6791 LOP(OP_SYSWRITE,XTERM);
6795 TERM(sublex_start());
6816 LOP(OP_TRUNCATE,XTERM);
6828 yylval.ival = CopLINE(PL_curcop);
6832 yylval.ival = CopLINE(PL_curcop);
6836 LOP(OP_UNLINK,XTERM);
6842 LOP(OP_UNPACK,XTERM);
6845 LOP(OP_UTIME,XTERM);
6851 LOP(OP_UNSHIFT,XTERM);
6854 s = tokenize_use(1, s);
6864 yylval.ival = CopLINE(PL_curcop);
6868 yylval.ival = CopLINE(PL_curcop);
6872 PL_hints |= HINT_BLOCK_SCOPE;
6879 LOP(OP_WAITPID,XTERM);
6888 ctl_l[0] = toCTRL('L');
6890 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6893 /* Make sure $^L is defined */
6894 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6899 if (PL_expect == XOPERATOR)
6905 yylval.ival = OP_XOR;
6910 TERM(sublex_start());
6915 #pragma segment Main
6919 S_pending_ident(pTHX)
6924 /* pit holds the identifier we read and pending_ident is reset */
6925 char pit = PL_pending_ident;
6926 PL_pending_ident = 0;
6928 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6929 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6930 "### Pending identifier '%s'\n", PL_tokenbuf); });
6932 /* if we're in a my(), we can't allow dynamics here.
6933 $foo'bar has already been turned into $foo::bar, so
6934 just check for colons.
6936 if it's a legal name, the OP is a PADANY.
6939 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6940 if (strchr(PL_tokenbuf,':'))
6941 yyerror(Perl_form(aTHX_ "No package name allowed for "
6942 "variable %s in \"our\"",
6944 tmp = allocmy(PL_tokenbuf);
6947 if (strchr(PL_tokenbuf,':'))
6948 yyerror(Perl_form(aTHX_ PL_no_myglob,
6949 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6951 yylval.opval = newOP(OP_PADANY, 0);
6952 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6958 build the ops for accesses to a my() variable.
6960 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6961 then used in a comparison. This catches most, but not
6962 all cases. For instance, it catches
6963 sort { my($a); $a <=> $b }
6965 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6966 (although why you'd do that is anyone's guess).
6969 if (!strchr(PL_tokenbuf,':')) {
6971 tmp = pad_findmy(PL_tokenbuf);
6972 if (tmp != NOT_IN_PAD) {
6973 /* might be an "our" variable" */
6974 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6975 /* build ops for a bareword */
6976 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6977 HEK * const stashname = HvNAME_HEK(stash);
6978 SV * const sym = newSVhek(stashname);
6979 sv_catpvs(sym, "::");
6980 sv_catpv(sym, PL_tokenbuf+1);
6981 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6982 yylval.opval->op_private = OPpCONST_ENTERED;
6985 ? (GV_ADDMULTI | GV_ADDINEVAL)
6988 ((PL_tokenbuf[0] == '$') ? SVt_PV
6989 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6994 /* if it's a sort block and they're naming $a or $b */
6995 if (PL_last_lop_op == OP_SORT &&
6996 PL_tokenbuf[0] == '$' &&
6997 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
7000 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
7001 d < PL_bufend && *d != '\n';
7004 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
7005 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
7011 yylval.opval = newOP(OP_PADANY, 0);
7012 yylval.opval->op_targ = tmp;
7018 Whine if they've said @foo in a doublequoted string,
7019 and @foo isn't a variable we can find in the symbol
7022 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
7023 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
7024 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
7025 && ckWARN(WARN_AMBIGUOUS)
7026 /* DO NOT warn for @- and @+ */
7027 && !( PL_tokenbuf[2] == '\0' &&
7028 ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
7031 /* Downgraded from fatal to warning 20000522 mjd */
7032 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
7033 "Possible unintended interpolation of %s in string",
7038 /* build ops for a bareword */
7039 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
7040 yylval.opval->op_private = OPpCONST_ENTERED;
7043 /* If the identifier refers to a stash, don't autovivify it.
7044 * Change 24660 had the side effect of causing symbol table
7045 * hashes to always be defined, even if they were freshly
7046 * created and the only reference in the entire program was
7047 * the single statement with the defined %foo::bar:: test.
7048 * It appears that all code in the wild doing this actually
7049 * wants to know whether sub-packages have been loaded, so
7050 * by avoiding auto-vivifying symbol tables, we ensure that
7051 * defined %foo::bar:: continues to be false, and the existing
7052 * tests still give the expected answers, even though what
7053 * they're actually testing has now changed subtly.
7055 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
7057 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
7058 ((PL_tokenbuf[0] == '$') ? SVt_PV
7059 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7065 * The following code was generated by perl_keyword.pl.
7069 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
7074 case 1: /* 5 tokens of length 1 */
7106 case 2: /* 18 tokens of length 2 */
7252 case 3: /* 29 tokens of length 3 */
7256 if (name[1] == 'N' &&
7319 if (name[1] == 'i' &&
7341 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7359 if (name[1] == 'o' &&
7368 if (name[1] == 'e' &&
7377 if (name[1] == 'n' &&
7386 if (name[1] == 'o' &&
7395 if (name[1] == 'a' &&
7404 if (name[1] == 'o' &&
7466 if (name[1] == 'e' &&
7480 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
7506 if (name[1] == 'i' &&
7515 if (name[1] == 's' &&
7524 if (name[1] == 'e' &&
7533 if (name[1] == 'o' &&
7545 case 4: /* 41 tokens of length 4 */
7549 if (name[1] == 'O' &&
7559 if (name[1] == 'N' &&
7569 if (name[1] == 'i' &&
7579 if (name[1] == 'h' &&
7589 if (name[1] == 'u' &&
7602 if (name[2] == 'c' &&
7611 if (name[2] == 's' &&
7620 if (name[2] == 'a' &&
7656 if (name[1] == 'o' &&
7669 if (name[2] == 't' &&
7678 if (name[2] == 'o' &&
7687 if (name[2] == 't' &&
7696 if (name[2] == 'e' &&
7709 if (name[1] == 'o' &&
7722 if (name[2] == 'y' &&
7731 if (name[2] == 'l' &&
7747 if (name[2] == 's' &&
7756 if (name[2] == 'n' &&
7765 if (name[2] == 'c' &&
7778 if (name[1] == 'e' &&
7788 if (name[1] == 'p' &&
7801 if (name[2] == 'c' &&
7810 if (name[2] == 'p' &&
7819 if (name[2] == 's' &&
7835 if (name[2] == 'n' &&
7905 if (name[2] == 'r' &&
7914 if (name[2] == 'r' &&
7923 if (name[2] == 'a' &&
7939 if (name[2] == 'l' &&
8001 if (name[2] == 'e' &&
8004 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
8017 case 5: /* 39 tokens of length 5 */
8021 if (name[1] == 'E' &&
8032 if (name[1] == 'H' &&
8046 if (name[2] == 'a' &&
8056 if (name[2] == 'a' &&
8073 if (name[2] == 'e' &&
8083 if (name[2] == 'e' &&
8087 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
8103 if (name[3] == 'i' &&
8112 if (name[3] == 'o' &&
8148 if (name[2] == 'o' &&
8158 if (name[2] == 'y' &&
8172 if (name[1] == 'l' &&
8186 if (name[2] == 'n' &&
8196 if (name[2] == 'o' &&
8210 if (name[1] == 'i' &&
8215 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8224 if (name[2] == 'd' &&
8234 if (name[2] == 'c' &&
8251 if (name[2] == 'c' &&
8261 if (name[2] == 't' &&
8275 if (name[1] == 'k' &&
8286 if (name[1] == 'r' &&
8300 if (name[2] == 's' &&
8310 if (name[2] == 'd' &&
8327 if (name[2] == 'm' &&
8337 if (name[2] == 'i' &&
8347 if (name[2] == 'e' &&
8357 if (name[2] == 'l' &&
8367 if (name[2] == 'a' &&
8380 if (name[3] == 't' &&
8383 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8389 if (name[3] == 'd' &&
8406 if (name[1] == 'i' &&
8420 if (name[2] == 'a' &&
8433 if (name[3] == 'e' &&
8468 if (name[2] == 'i' &&
8485 if (name[2] == 'i' &&
8495 if (name[2] == 'i' &&
8512 case 6: /* 33 tokens of length 6 */
8516 if (name[1] == 'c' &&
8531 if (name[2] == 'l' &&
8542 if (name[2] == 'r' &&
8557 if (name[1] == 'e' &&
8572 if (name[2] == 's' &&
8577 if(ckWARN_d(WARN_SYNTAX))
8578 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8584 if (name[2] == 'i' &&
8602 if (name[2] == 'l' &&
8613 if (name[2] == 'r' &&
8628 if (name[1] == 'm' &&
8643 if (name[2] == 'n' &&
8654 if (name[2] == 's' &&
8669 if (name[1] == 's' &&
8675 if (name[4] == 't' &&
8684 if (name[4] == 'e' &&
8693 if (name[4] == 'c' &&
8702 if (name[4] == 'n' &&
8718 if (name[1] == 'r' &&
8736 if (name[3] == 'a' &&
8746 if (name[3] == 'u' &&
8760 if (name[2] == 'n' &&
8778 if (name[2] == 'a' &&
8792 if (name[3] == 'e' &&
8805 if (name[4] == 't' &&
8814 if (name[4] == 'e' &&
8836 if (name[4] == 't' &&
8845 if (name[4] == 'e' &&
8861 if (name[2] == 'c' &&
8872 if (name[2] == 'l' &&
8883 if (name[2] == 'b' &&
8894 if (name[2] == 's' &&
8917 if (name[4] == 's' &&
8926 if (name[4] == 'n' &&
8939 if (name[3] == 'a' &&
8956 if (name[1] == 'a' &&
8971 case 7: /* 29 tokens of length 7 */
8975 if (name[1] == 'E' &&
8988 if (name[1] == '_' &&
9001 if (name[1] == 'i' &&
9008 return -KEY_binmode;
9014 if (name[1] == 'o' &&
9021 return -KEY_connect;
9030 if (name[2] == 'm' &&
9036 return -KEY_dbmopen;
9047 if (name[4] == 'u' &&
9051 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
9057 if (name[4] == 'n' &&
9078 if (name[1] == 'o' &&
9091 if (name[1] == 'e' &&
9098 if (name[5] == 'r' &&
9101 return -KEY_getpgrp;
9107 if (name[5] == 'i' &&
9110 return -KEY_getppid;
9123 if (name[1] == 'c' &&
9130 return -KEY_lcfirst;
9136 if (name[1] == 'p' &&
9143 return -KEY_opendir;
9149 if (name[1] == 'a' &&
9167 if (name[3] == 'd' &&
9172 return -KEY_readdir;
9178 if (name[3] == 'u' &&
9189 if (name[3] == 'e' &&
9194 return -KEY_reverse;
9213 if (name[3] == 'k' &&
9218 return -KEY_seekdir;
9224 if (name[3] == 'p' &&
9229 return -KEY_setpgrp;
9239 if (name[2] == 'm' &&
9245 return -KEY_shmread;
9251 if (name[2] == 'r' &&
9257 return -KEY_sprintf;
9266 if (name[3] == 'l' &&
9271 return -KEY_symlink;
9280 if (name[4] == 'a' &&
9284 return -KEY_syscall;
9290 if (name[4] == 'p' &&
9294 return -KEY_sysopen;
9300 if (name[4] == 'e' &&
9304 return -KEY_sysread;
9310 if (name[4] == 'e' &&
9314 return -KEY_sysseek;
9332 if (name[1] == 'e' &&
9339 return -KEY_telldir;
9348 if (name[2] == 'f' &&
9354 return -KEY_ucfirst;
9360 if (name[2] == 's' &&
9366 return -KEY_unshift;
9376 if (name[1] == 'a' &&
9383 return -KEY_waitpid;
9392 case 8: /* 26 tokens of length 8 */
9396 if (name[1] == 'U' &&
9404 return KEY_AUTOLOAD;
9415 if (name[3] == 'A' &&
9421 return KEY___DATA__;
9427 if (name[3] == 'I' &&
9433 return -KEY___FILE__;
9439 if (name[3] == 'I' &&
9445 return -KEY___LINE__;
9461 if (name[2] == 'o' &&
9468 return -KEY_closedir;
9474 if (name[2] == 'n' &&
9481 return -KEY_continue;
9491 if (name[1] == 'b' &&
9499 return -KEY_dbmclose;
9505 if (name[1] == 'n' &&
9511 if (name[4] == 'r' &&
9516 return -KEY_endgrent;
9522 if (name[4] == 'w' &&
9527 return -KEY_endpwent;
9540 if (name[1] == 'o' &&
9548 return -KEY_formline;
9554 if (name[1] == 'e' &&
9565 if (name[6] == 'n' &&
9568 return -KEY_getgrent;
9574 if (name[6] == 'i' &&
9577 return -KEY_getgrgid;
9583 if (name[6] == 'a' &&
9586 return -KEY_getgrnam;
9599 if (name[4] == 'o' &&
9604 return -KEY_getlogin;
9615 if (name[6] == 'n' &&
9618 return -KEY_getpwent;
9624 if (name[6] == 'a' &&
9627 return -KEY_getpwnam;
9633 if (name[6] == 'i' &&
9636 return -KEY_getpwuid;
9656 if (name[1] == 'e' &&
9663 if (name[5] == 'i' &&
9670 return -KEY_readline;
9675 return -KEY_readlink;
9686 if (name[5] == 'i' &&
9690 return -KEY_readpipe;
9711 if (name[4] == 'r' &&
9716 return -KEY_setgrent;
9722 if (name[4] == 'w' &&
9727 return -KEY_setpwent;
9743 if (name[3] == 'w' &&
9749 return -KEY_shmwrite;
9755 if (name[3] == 't' &&
9761 return -KEY_shutdown;
9771 if (name[2] == 's' &&
9778 return -KEY_syswrite;
9788 if (name[1] == 'r' &&
9796 return -KEY_truncate;
9805 case 9: /* 9 tokens of length 9 */
9809 if (name[1] == 'N' &&
9818 return KEY_UNITCHECK;
9824 if (name[1] == 'n' &&
9833 return -KEY_endnetent;
9839 if (name[1] == 'e' &&
9848 return -KEY_getnetent;
9854 if (name[1] == 'o' &&
9863 return -KEY_localtime;
9869 if (name[1] == 'r' &&
9878 return KEY_prototype;
9884 if (name[1] == 'u' &&
9893 return -KEY_quotemeta;
9899 if (name[1] == 'e' &&
9908 return -KEY_rewinddir;
9914 if (name[1] == 'e' &&
9923 return -KEY_setnetent;
9929 if (name[1] == 'a' &&
9938 return -KEY_wantarray;
9947 case 10: /* 9 tokens of length 10 */
9951 if (name[1] == 'n' &&
9957 if (name[4] == 'o' &&
9964 return -KEY_endhostent;
9970 if (name[4] == 'e' &&
9977 return -KEY_endservent;
9990 if (name[1] == 'e' &&
9996 if (name[4] == 'o' &&
10003 return -KEY_gethostent;
10012 if (name[5] == 'r' &&
10018 return -KEY_getservent;
10024 if (name[5] == 'c' &&
10030 return -KEY_getsockopt;
10050 if (name[2] == 't')
10055 if (name[4] == 'o' &&
10062 return -KEY_sethostent;
10071 if (name[5] == 'r' &&
10077 return -KEY_setservent;
10083 if (name[5] == 'c' &&
10089 return -KEY_setsockopt;
10106 if (name[2] == 'c' &&
10115 return -KEY_socketpair;
10128 case 11: /* 8 tokens of length 11 */
10132 if (name[1] == '_' &&
10142 { /* __PACKAGE__ */
10143 return -KEY___PACKAGE__;
10149 if (name[1] == 'n' &&
10159 { /* endprotoent */
10160 return -KEY_endprotoent;
10166 if (name[1] == 'e' &&
10175 if (name[5] == 'e' &&
10181 { /* getpeername */
10182 return -KEY_getpeername;
10191 if (name[6] == 'o' &&
10196 { /* getpriority */
10197 return -KEY_getpriority;
10203 if (name[6] == 't' &&
10208 { /* getprotoent */
10209 return -KEY_getprotoent;
10223 if (name[4] == 'o' &&
10230 { /* getsockname */
10231 return -KEY_getsockname;
10244 if (name[1] == 'e' &&
10252 if (name[6] == 'o' &&
10257 { /* setpriority */
10258 return -KEY_setpriority;
10264 if (name[6] == 't' &&
10269 { /* setprotoent */
10270 return -KEY_setprotoent;
10286 case 12: /* 2 tokens of length 12 */
10287 if (name[0] == 'g' &&
10299 if (name[9] == 'd' &&
10302 { /* getnetbyaddr */
10303 return -KEY_getnetbyaddr;
10309 if (name[9] == 'a' &&
10312 { /* getnetbyname */
10313 return -KEY_getnetbyname;
10325 case 13: /* 4 tokens of length 13 */
10326 if (name[0] == 'g' &&
10333 if (name[4] == 'o' &&
10342 if (name[10] == 'd' &&
10345 { /* gethostbyaddr */
10346 return -KEY_gethostbyaddr;
10352 if (name[10] == 'a' &&
10355 { /* gethostbyname */
10356 return -KEY_gethostbyname;
10369 if (name[4] == 'e' &&
10378 if (name[10] == 'a' &&
10381 { /* getservbyname */
10382 return -KEY_getservbyname;
10388 if (name[10] == 'o' &&
10391 { /* getservbyport */
10392 return -KEY_getservbyport;
10411 case 14: /* 1 tokens of length 14 */
10412 if (name[0] == 'g' &&
10426 { /* getprotobyname */
10427 return -KEY_getprotobyname;
10432 case 16: /* 1 tokens of length 16 */
10433 if (name[0] == 'g' &&
10449 { /* getprotobynumber */
10450 return -KEY_getprotobynumber;
10464 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10468 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10469 if (ckWARN(WARN_SYNTAX)) {
10472 for (w = s+2; *w && level; w++) {
10475 else if (*w == ')')
10478 while (isSPACE(*w))
10480 /* the list of chars below is for end of statements or
10481 * block / parens, boolean operators (&&, ||, //) and branch
10482 * constructs (or, and, if, until, unless, while, err, for).
10483 * Not a very solid hack... */
10484 if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
10485 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10486 "%s (...) interpreted as function",name);
10489 while (s < PL_bufend && isSPACE(*s))
10493 while (s < PL_bufend && isSPACE(*s))
10495 if (isIDFIRST_lazy_if(s,UTF)) {
10496 const char * const w = s++;
10497 while (isALNUM_lazy_if(s,UTF))
10499 while (s < PL_bufend && isSPACE(*s))
10503 if (keyword(w, s - w, 0))
10506 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10507 if (gv && GvCVu(gv))
10509 Perl_croak(aTHX_ "No comma allowed after %s", what);
10514 /* Either returns sv, or mortalizes sv and returns a new SV*.
10515 Best used as sv=new_constant(..., sv, ...).
10516 If s, pv are NULL, calls subroutine with one argument,
10517 and type is used with error messages only. */
10520 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10524 HV * const table = GvHV(PL_hintgv); /* ^H */
10528 const char *why1 = "", *why2 = "", *why3 = "";
10530 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10533 why2 = (const char *)
10534 (strEQ(key,"charnames")
10535 ? "(possibly a missing \"use charnames ...\")"
10537 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10538 (type ? type: "undef"), why2);
10540 /* This is convoluted and evil ("goto considered harmful")
10541 * but I do not understand the intricacies of all the different
10542 * failure modes of %^H in here. The goal here is to make
10543 * the most probable error message user-friendly. --jhi */
10548 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10549 (type ? type: "undef"), why1, why2, why3);
10551 yyerror(SvPVX_const(msg));
10555 cvp = hv_fetch(table, key, strlen(key), FALSE);
10556 if (!cvp || !SvOK(*cvp)) {
10559 why3 = "} is not defined";
10562 sv_2mortal(sv); /* Parent created it permanently */
10565 pv = sv_2mortal(newSVpvn(s, len));
10567 typesv = sv_2mortal(newSVpv(type, 0));
10569 typesv = &PL_sv_undef;
10571 PUSHSTACKi(PERLSI_OVERLOAD);
10583 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10587 /* Check the eval first */
10588 if (!PL_in_eval && SvTRUE(ERRSV)) {
10589 sv_catpvs(ERRSV, "Propagated");
10590 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10592 res = SvREFCNT_inc_simple(sv);
10596 SvREFCNT_inc_simple_void(res);
10605 why1 = "Call to &{$^H{";
10607 why3 = "}} did not return a defined value";
10615 /* Returns a NUL terminated string, with the length of the string written to
10619 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10622 register char *d = dest;
10623 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10626 Perl_croak(aTHX_ ident_too_long);
10627 if (isALNUM(*s)) /* UTF handled below */
10629 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10634 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10638 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10639 char *t = s + UTF8SKIP(s);
10641 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10645 Perl_croak(aTHX_ ident_too_long);
10646 Copy(s, d, len, char);
10659 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10662 char *bracket = NULL;
10664 register char *d = dest;
10665 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10670 while (isDIGIT(*s)) {
10672 Perl_croak(aTHX_ ident_too_long);
10679 Perl_croak(aTHX_ ident_too_long);
10680 if (isALNUM(*s)) /* UTF handled below */
10682 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10687 else if (*s == ':' && s[1] == ':') {
10691 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10692 char *t = s + UTF8SKIP(s);
10693 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10695 if (d + (t - s) > e)
10696 Perl_croak(aTHX_ ident_too_long);
10697 Copy(s, d, t - s, char);
10708 if (PL_lex_state != LEX_NORMAL)
10709 PL_lex_state = LEX_INTERPENDMAYBE;
10712 if (*s == '$' && s[1] &&
10713 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10726 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10731 if (isSPACE(s[-1])) {
10733 const char ch = *s++;
10734 if (!SPACE_OR_TAB(ch)) {
10740 if (isIDFIRST_lazy_if(d,UTF)) {
10744 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10745 end += UTF8SKIP(end);
10746 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10747 end += UTF8SKIP(end);
10749 Copy(s, d, end - s, char);
10754 while ((isALNUM(*s) || *s == ':') && d < e)
10757 Perl_croak(aTHX_ ident_too_long);
10760 while (s < send && SPACE_OR_TAB(*s))
10762 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10763 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10764 const char * const brack =
10766 ((*s == '[') ? "[...]" : "{...}");
10767 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10768 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10769 funny, dest, brack, funny, dest, brack);
10772 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10776 /* Handle extended ${^Foo} variables
10777 * 1999-02-27 mjd-perl-patch@plover.com */
10778 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10782 while (isALNUM(*s) && d < e) {
10786 Perl_croak(aTHX_ ident_too_long);
10791 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10792 PL_lex_state = LEX_INTERPEND;
10795 if (PL_lex_state == LEX_NORMAL) {
10796 if (ckWARN(WARN_AMBIGUOUS) &&
10797 (keyword(dest, d - dest, 0)
10798 || get_cvn_flags(dest, d - dest, 0)))
10802 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10803 "Ambiguous use of %c{%s} resolved to %c%s",
10804 funny, dest, funny, dest);
10809 s = bracket; /* let the parser handle it */
10813 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10814 PL_lex_state = LEX_INTERPEND;
10819 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10821 PERL_UNUSED_CONTEXT;
10825 CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
10826 case GLOBAL_PAT_MOD: *pmfl |= PMf_GLOBAL; break;
10827 case CONTINUE_PAT_MOD: *pmfl |= PMf_CONTINUE; break;
10828 case ONCE_PAT_MOD: *pmfl |= PMf_KEEP; break;
10829 case KEEPCOPY_PAT_MOD: *pmfl |= PMf_KEEPCOPY; break;
10835 S_scan_pat(pTHX_ char *start, I32 type)
10839 char *s = scan_str(start,!!PL_madskills,FALSE);
10840 const char * const valid_flags =
10841 (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
10848 const char * const delimiter = skipspace(start);
10852 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10853 : "Search pattern not terminated" ));
10856 pm = (PMOP*)newPMOP(type, 0);
10857 if (PL_multi_open == '?') {
10858 /* This is the only point in the code that sets PMf_ONCE: */
10859 pm->op_pmflags |= PMf_ONCE;
10861 /* Hence it's safe to do this bit of PMOP book-keeping here, which
10862 allows us to restrict the list needed by reset to just the ??
10864 assert(type != OP_TRANS);
10866 MAGIC *mg = mg_find((SV*)PL_curstash, PERL_MAGIC_symtab);
10869 mg = sv_magicext((SV*)PL_curstash, 0, PERL_MAGIC_symtab, 0, 0,
10872 elements = mg->mg_len / sizeof(PMOP**);
10873 Renewc(mg->mg_ptr, elements + 1, PMOP*, char);
10874 ((PMOP**)mg->mg_ptr) [elements++] = pm;
10875 mg->mg_len = elements * sizeof(PMOP**);
10876 PmopSTASH_set(pm,PL_curstash);
10882 while (*s && strchr(valid_flags, *s))
10883 pmflag(&pm->op_pmflags,*s++);
10885 if (PL_madskills && modstart != s) {
10886 SV* tmptoken = newSVpvn(modstart, s - modstart);
10887 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10890 /* issue a warning if /c is specified,but /g is not */
10891 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10892 && ckWARN(WARN_REGEXP))
10894 Perl_warner(aTHX_ packWARN(WARN_REGEXP),
10895 "Use of /c modifier is meaningless without /g" );
10898 PL_lex_op = (OP*)pm;
10899 yylval.ival = OP_MATCH;
10904 S_scan_subst(pTHX_ char *start)
10915 yylval.ival = OP_NULL;
10917 s = scan_str(start,!!PL_madskills,FALSE);
10920 Perl_croak(aTHX_ "Substitution pattern not terminated");
10922 if (s[-1] == PL_multi_open)
10925 if (PL_madskills) {
10926 CURMAD('q', PL_thisopen);
10927 CURMAD('_', PL_thiswhite);
10928 CURMAD('E', PL_thisstuff);
10929 CURMAD('Q', PL_thisclose);
10930 PL_realtokenstart = s - SvPVX(PL_linestr);
10934 first_start = PL_multi_start;
10935 s = scan_str(s,!!PL_madskills,FALSE);
10937 if (PL_lex_stuff) {
10938 SvREFCNT_dec(PL_lex_stuff);
10939 PL_lex_stuff = NULL;
10941 Perl_croak(aTHX_ "Substitution replacement not terminated");
10943 PL_multi_start = first_start; /* so whole substitution is taken together */
10945 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10948 if (PL_madskills) {
10949 CURMAD('z', PL_thisopen);
10950 CURMAD('R', PL_thisstuff);
10951 CURMAD('Z', PL_thisclose);
10957 if (*s == EXEC_PAT_MOD) {
10961 else if (strchr(S_PAT_MODS, *s))
10962 pmflag(&pm->op_pmflags,*s++);
10968 if (PL_madskills) {
10970 curmad('m', newSVpvn(modstart, s - modstart));
10971 append_madprops(PL_thismad, (OP*)pm, 0);
10975 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10976 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10980 SV * const repl = newSVpvs("");
10982 PL_sublex_info.super_bufptr = s;
10983 PL_sublex_info.super_bufend = PL_bufend;
10985 pm->op_pmflags |= PMf_EVAL;
10987 sv_catpv(repl, (const char *)(es ? "eval " : "do "));
10988 sv_catpvs(repl, "{");
10989 sv_catsv(repl, PL_lex_repl);
10990 if (strchr(SvPVX(PL_lex_repl), '#'))
10991 sv_catpvs(repl, "\n");
10992 sv_catpvs(repl, "}");
10994 SvREFCNT_dec(PL_lex_repl);
10995 PL_lex_repl = repl;
10998 PL_lex_op = (OP*)pm;
10999 yylval.ival = OP_SUBST;
11004 S_scan_trans(pTHX_ char *start)
11017 yylval.ival = OP_NULL;
11019 s = scan_str(start,!!PL_madskills,FALSE);
11021 Perl_croak(aTHX_ "Transliteration pattern not terminated");
11023 if (s[-1] == PL_multi_open)
11026 if (PL_madskills) {
11027 CURMAD('q', PL_thisopen);
11028 CURMAD('_', PL_thiswhite);
11029 CURMAD('E', PL_thisstuff);
11030 CURMAD('Q', PL_thisclose);
11031 PL_realtokenstart = s - SvPVX(PL_linestr);
11035 s = scan_str(s,!!PL_madskills,FALSE);
11037 if (PL_lex_stuff) {
11038 SvREFCNT_dec(PL_lex_stuff);
11039 PL_lex_stuff = NULL;
11041 Perl_croak(aTHX_ "Transliteration replacement not terminated");
11043 if (PL_madskills) {
11044 CURMAD('z', PL_thisopen);
11045 CURMAD('R', PL_thisstuff);
11046 CURMAD('Z', PL_thisclose);
11049 complement = del = squash = 0;
11056 complement = OPpTRANS_COMPLEMENT;
11059 del = OPpTRANS_DELETE;
11062 squash = OPpTRANS_SQUASH;
11071 tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
11072 o = newPVOP(OP_TRANS, 0, (char*)tbl);
11073 o->op_private &= ~OPpTRANS_ALL;
11074 o->op_private |= del|squash|complement|
11075 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
11076 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
11079 yylval.ival = OP_TRANS;
11082 if (PL_madskills) {
11084 curmad('m', newSVpvn(modstart, s - modstart));
11085 append_madprops(PL_thismad, o, 0);
11094 S_scan_heredoc(pTHX_ register char *s)
11098 I32 op_type = OP_SCALAR;
11102 const char *found_newline;
11106 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
11108 I32 stuffstart = s - SvPVX(PL_linestr);
11111 PL_realtokenstart = -1;
11116 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
11120 while (SPACE_OR_TAB(*peek))
11122 if (*peek == '`' || *peek == '\'' || *peek =='"') {
11125 s = delimcpy(d, e, s, PL_bufend, term, &len);
11135 if (!isALNUM_lazy_if(s,UTF))
11136 deprecate_old("bare << to mean <<\"\"");
11137 for (; isALNUM_lazy_if(s,UTF); s++) {
11142 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
11143 Perl_croak(aTHX_ "Delimiter for here document is too long");
11146 len = d - PL_tokenbuf;
11149 if (PL_madskills) {
11150 tstart = PL_tokenbuf + !outer;
11151 PL_thisclose = newSVpvn(tstart, len - !outer);
11152 tstart = SvPVX(PL_linestr) + stuffstart;
11153 PL_thisopen = newSVpvn(tstart, s - tstart);
11154 stuffstart = s - SvPVX(PL_linestr);
11157 #ifndef PERL_STRICT_CR
11158 d = strchr(s, '\r');
11160 char * const olds = s;
11162 while (s < PL_bufend) {
11168 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11177 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11184 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11185 herewas = newSVpvn(s,PL_bufend-s);
11189 herewas = newSVpvn(s-1,found_newline-s+1);
11192 herewas = newSVpvn(s,found_newline-s);
11196 if (PL_madskills) {
11197 tstart = SvPVX(PL_linestr) + stuffstart;
11199 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11201 PL_thisstuff = newSVpvn(tstart, s - tstart);
11204 s += SvCUR(herewas);
11207 stuffstart = s - SvPVX(PL_linestr);
11213 tmpstr = newSV_type(SVt_PVIV);
11214 SvGROW(tmpstr, 80);
11215 if (term == '\'') {
11216 op_type = OP_CONST;
11217 SvIV_set(tmpstr, -1);
11219 else if (term == '`') {
11220 op_type = OP_BACKTICK;
11221 SvIV_set(tmpstr, '\\');
11225 PL_multi_start = CopLINE(PL_curcop);
11226 PL_multi_open = PL_multi_close = '<';
11227 term = *PL_tokenbuf;
11228 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11229 char * const bufptr = PL_sublex_info.super_bufptr;
11230 char * const bufend = PL_sublex_info.super_bufend;
11231 char * const olds = s - SvCUR(herewas);
11232 s = strchr(bufptr, '\n');
11236 while (s < bufend &&
11237 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11239 CopLINE_inc(PL_curcop);
11242 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11243 missingterm(PL_tokenbuf);
11245 sv_setpvn(herewas,bufptr,d-bufptr+1);
11246 sv_setpvn(tmpstr,d+1,s-d);
11248 sv_catpvn(herewas,s,bufend-s);
11249 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11256 while (s < PL_bufend &&
11257 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11259 CopLINE_inc(PL_curcop);
11261 if (s >= PL_bufend) {
11262 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11263 missingterm(PL_tokenbuf);
11265 sv_setpvn(tmpstr,d+1,s-d);
11267 if (PL_madskills) {
11269 sv_catpvn(PL_thisstuff, d + 1, s - d);
11271 PL_thisstuff = newSVpvn(d + 1, s - d);
11272 stuffstart = s - SvPVX(PL_linestr);
11276 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11278 sv_catpvn(herewas,s,PL_bufend-s);
11279 sv_setsv(PL_linestr,herewas);
11280 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11281 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11282 PL_last_lop = PL_last_uni = NULL;
11285 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11286 while (s >= PL_bufend) { /* multiple line string? */
11288 if (PL_madskills) {
11289 tstart = SvPVX(PL_linestr) + stuffstart;
11291 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11293 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11297 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11298 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11299 missingterm(PL_tokenbuf);
11302 stuffstart = s - SvPVX(PL_linestr);
11304 CopLINE_inc(PL_curcop);
11305 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11306 PL_last_lop = PL_last_uni = NULL;
11307 #ifndef PERL_STRICT_CR
11308 if (PL_bufend - PL_linestart >= 2) {
11309 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11310 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11312 PL_bufend[-2] = '\n';
11314 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11316 else if (PL_bufend[-1] == '\r')
11317 PL_bufend[-1] = '\n';
11319 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11320 PL_bufend[-1] = '\n';
11322 if (PERLDB_LINE && PL_curstash != PL_debstash)
11323 update_debugger_info(PL_linestr, NULL, 0);
11324 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11325 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11326 *(SvPVX(PL_linestr) + off ) = ' ';
11327 sv_catsv(PL_linestr,herewas);
11328 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11329 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11333 sv_catsv(tmpstr,PL_linestr);
11338 PL_multi_end = CopLINE(PL_curcop);
11339 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11340 SvPV_shrink_to_cur(tmpstr);
11342 SvREFCNT_dec(herewas);
11344 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11346 else if (PL_encoding)
11347 sv_recode_to_utf8(tmpstr, PL_encoding);
11349 PL_lex_stuff = tmpstr;
11350 yylval.ival = op_type;
11354 /* scan_inputsymbol
11355 takes: current position in input buffer
11356 returns: new position in input buffer
11357 side-effects: yylval and lex_op are set.
11362 <FH> read from filehandle
11363 <pkg::FH> read from package qualified filehandle
11364 <pkg'FH> read from package qualified filehandle
11365 <$fh> read from filehandle in $fh
11366 <*.h> filename glob
11371 S_scan_inputsymbol(pTHX_ char *start)
11374 register char *s = start; /* current position in buffer */
11378 char *d = PL_tokenbuf; /* start of temp holding space */
11379 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11381 end = strchr(s, '\n');
11384 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11386 /* die if we didn't have space for the contents of the <>,
11387 or if it didn't end, or if we see a newline
11390 if (len >= (I32)sizeof PL_tokenbuf)
11391 Perl_croak(aTHX_ "Excessively long <> operator");
11393 Perl_croak(aTHX_ "Unterminated <> operator");
11398 Remember, only scalar variables are interpreted as filehandles by
11399 this code. Anything more complex (e.g., <$fh{$num}>) will be
11400 treated as a glob() call.
11401 This code makes use of the fact that except for the $ at the front,
11402 a scalar variable and a filehandle look the same.
11404 if (*d == '$' && d[1]) d++;
11406 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11407 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11410 /* If we've tried to read what we allow filehandles to look like, and
11411 there's still text left, then it must be a glob() and not a getline.
11412 Use scan_str to pull out the stuff between the <> and treat it
11413 as nothing more than a string.
11416 if (d - PL_tokenbuf != len) {
11417 yylval.ival = OP_GLOB;
11419 s = scan_str(start,!!PL_madskills,FALSE);
11421 Perl_croak(aTHX_ "Glob not terminated");
11425 bool readline_overriden = FALSE;
11428 /* we're in a filehandle read situation */
11431 /* turn <> into <ARGV> */
11433 Copy("ARGV",d,5,char);
11435 /* Check whether readline() is overriden */
11436 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11438 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11440 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11441 && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
11442 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11443 readline_overriden = TRUE;
11445 /* if <$fh>, create the ops to turn the variable into a
11449 /* try to find it in the pad for this block, otherwise find
11450 add symbol table ops
11452 const PADOFFSET tmp = pad_findmy(d);
11453 if (tmp != NOT_IN_PAD) {
11454 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11455 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11456 HEK * const stashname = HvNAME_HEK(stash);
11457 SV * const sym = sv_2mortal(newSVhek(stashname));
11458 sv_catpvs(sym, "::");
11459 sv_catpv(sym, d+1);
11464 OP * const o = newOP(OP_PADSV, 0);
11466 PL_lex_op = readline_overriden
11467 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11468 append_elem(OP_LIST, o,
11469 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11470 : (OP*)newUNOP(OP_READLINE, 0, o);
11479 ? (GV_ADDMULTI | GV_ADDINEVAL)
11482 PL_lex_op = readline_overriden
11483 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11484 append_elem(OP_LIST,
11485 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11486 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11487 : (OP*)newUNOP(OP_READLINE, 0,
11488 newUNOP(OP_RV2SV, 0,
11489 newGVOP(OP_GV, 0, gv)));
11491 if (!readline_overriden)
11492 PL_lex_op->op_flags |= OPf_SPECIAL;
11493 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11494 yylval.ival = OP_NULL;
11497 /* If it's none of the above, it must be a literal filehandle
11498 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11500 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11501 PL_lex_op = readline_overriden
11502 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11503 append_elem(OP_LIST,
11504 newGVOP(OP_GV, 0, gv),
11505 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11506 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11507 yylval.ival = OP_NULL;
11516 takes: start position in buffer
11517 keep_quoted preserve \ on the embedded delimiter(s)
11518 keep_delims preserve the delimiters around the string
11519 returns: position to continue reading from buffer
11520 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11521 updates the read buffer.
11523 This subroutine pulls a string out of the input. It is called for:
11524 q single quotes q(literal text)
11525 ' single quotes 'literal text'
11526 qq double quotes qq(interpolate $here please)
11527 " double quotes "interpolate $here please"
11528 qx backticks qx(/bin/ls -l)
11529 ` backticks `/bin/ls -l`
11530 qw quote words @EXPORT_OK = qw( func() $spam )
11531 m// regexp match m/this/
11532 s/// regexp substitute s/this/that/
11533 tr/// string transliterate tr/this/that/
11534 y/// string transliterate y/this/that/
11535 ($*@) sub prototypes sub foo ($)
11536 (stuff) sub attr parameters sub foo : attr(stuff)
11537 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11539 In most of these cases (all but <>, patterns and transliterate)
11540 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11541 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11542 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11545 It skips whitespace before the string starts, and treats the first
11546 character as the delimiter. If the delimiter is one of ([{< then
11547 the corresponding "close" character )]}> is used as the closing
11548 delimiter. It allows quoting of delimiters, and if the string has
11549 balanced delimiters ([{<>}]) it allows nesting.
11551 On success, the SV with the resulting string is put into lex_stuff or,
11552 if that is already non-NULL, into lex_repl. The second case occurs only
11553 when parsing the RHS of the special constructs s/// and tr/// (y///).
11554 For convenience, the terminating delimiter character is stuffed into
11559 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11562 SV *sv; /* scalar value: string */
11563 const char *tmps; /* temp string, used for delimiter matching */
11564 register char *s = start; /* current position in the buffer */
11565 register char term; /* terminating character */
11566 register char *to; /* current position in the sv's data */
11567 I32 brackets = 1; /* bracket nesting level */
11568 bool has_utf8 = FALSE; /* is there any utf8 content? */
11569 I32 termcode; /* terminating char. code */
11570 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11571 STRLEN termlen; /* length of terminating string */
11572 int last_off = 0; /* last position for nesting bracket */
11578 /* skip space before the delimiter */
11584 if (PL_realtokenstart >= 0) {
11585 stuffstart = PL_realtokenstart;
11586 PL_realtokenstart = -1;
11589 stuffstart = start - SvPVX(PL_linestr);
11591 /* mark where we are, in case we need to report errors */
11594 /* after skipping whitespace, the next character is the terminator */
11597 termcode = termstr[0] = term;
11601 termcode = utf8_to_uvchr((U8*)s, &termlen);
11602 Copy(s, termstr, termlen, U8);
11603 if (!UTF8_IS_INVARIANT(term))
11607 /* mark where we are */
11608 PL_multi_start = CopLINE(PL_curcop);
11609 PL_multi_open = term;
11611 /* find corresponding closing delimiter */
11612 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11613 termcode = termstr[0] = term = tmps[5];
11615 PL_multi_close = term;
11617 /* create a new SV to hold the contents. 79 is the SV's initial length.
11618 What a random number. */
11619 sv = newSV_type(SVt_PVIV);
11621 SvIV_set(sv, termcode);
11622 (void)SvPOK_only(sv); /* validate pointer */
11624 /* move past delimiter and try to read a complete string */
11626 sv_catpvn(sv, s, termlen);
11629 tstart = SvPVX(PL_linestr) + stuffstart;
11630 if (!PL_thisopen && !keep_delims) {
11631 PL_thisopen = newSVpvn(tstart, s - tstart);
11632 stuffstart = s - SvPVX(PL_linestr);
11636 if (PL_encoding && !UTF) {
11640 int offset = s - SvPVX_const(PL_linestr);
11641 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11642 &offset, (char*)termstr, termlen);
11643 const char * const ns = SvPVX_const(PL_linestr) + offset;
11644 char * const svlast = SvEND(sv) - 1;
11646 for (; s < ns; s++) {
11647 if (*s == '\n' && !PL_rsfp)
11648 CopLINE_inc(PL_curcop);
11651 goto read_more_line;
11653 /* handle quoted delimiters */
11654 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11656 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11658 if ((svlast-1 - t) % 2) {
11659 if (!keep_quoted) {
11660 *(svlast-1) = term;
11662 SvCUR_set(sv, SvCUR(sv) - 1);
11667 if (PL_multi_open == PL_multi_close) {
11673 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
11674 /* At here, all closes are "was quoted" one,
11675 so we don't check PL_multi_close. */
11677 if (!keep_quoted && *(t+1) == PL_multi_open)
11682 else if (*t == PL_multi_open)
11690 SvCUR_set(sv, w - SvPVX_const(sv));
11692 last_off = w - SvPVX(sv);
11693 if (--brackets <= 0)
11698 if (!keep_delims) {
11699 SvCUR_set(sv, SvCUR(sv) - 1);
11705 /* extend sv if need be */
11706 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11707 /* set 'to' to the next character in the sv's string */
11708 to = SvPVX(sv)+SvCUR(sv);
11710 /* if open delimiter is the close delimiter read unbridle */
11711 if (PL_multi_open == PL_multi_close) {
11712 for (; s < PL_bufend; s++,to++) {
11713 /* embedded newlines increment the current line number */
11714 if (*s == '\n' && !PL_rsfp)
11715 CopLINE_inc(PL_curcop);
11716 /* handle quoted delimiters */
11717 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11718 if (!keep_quoted && s[1] == term)
11720 /* any other quotes are simply copied straight through */
11724 /* terminate when run out of buffer (the for() condition), or
11725 have found the terminator */
11726 else if (*s == term) {
11729 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11732 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11738 /* if the terminator isn't the same as the start character (e.g.,
11739 matched brackets), we have to allow more in the quoting, and
11740 be prepared for nested brackets.
11743 /* read until we run out of string, or we find the terminator */
11744 for (; s < PL_bufend; s++,to++) {
11745 /* embedded newlines increment the line count */
11746 if (*s == '\n' && !PL_rsfp)
11747 CopLINE_inc(PL_curcop);
11748 /* backslashes can escape the open or closing characters */
11749 if (*s == '\\' && s+1 < PL_bufend) {
11750 if (!keep_quoted &&
11751 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11756 /* allow nested opens and closes */
11757 else if (*s == PL_multi_close && --brackets <= 0)
11759 else if (*s == PL_multi_open)
11761 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11766 /* terminate the copied string and update the sv's end-of-string */
11768 SvCUR_set(sv, to - SvPVX_const(sv));
11771 * this next chunk reads more into the buffer if we're not done yet
11775 break; /* handle case where we are done yet :-) */
11777 #ifndef PERL_STRICT_CR
11778 if (to - SvPVX_const(sv) >= 2) {
11779 if ((to[-2] == '\r' && to[-1] == '\n') ||
11780 (to[-2] == '\n' && to[-1] == '\r'))
11784 SvCUR_set(sv, to - SvPVX_const(sv));
11786 else if (to[-1] == '\r')
11789 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11794 /* if we're out of file, or a read fails, bail and reset the current
11795 line marker so we can report where the unterminated string began
11798 if (PL_madskills) {
11799 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11801 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11803 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11807 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11809 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11815 /* we read a line, so increment our line counter */
11816 CopLINE_inc(PL_curcop);
11818 /* update debugger info */
11819 if (PERLDB_LINE && PL_curstash != PL_debstash)
11820 update_debugger_info(PL_linestr, NULL, 0);
11822 /* having changed the buffer, we must update PL_bufend */
11823 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11824 PL_last_lop = PL_last_uni = NULL;
11827 /* at this point, we have successfully read the delimited string */
11829 if (!PL_encoding || UTF) {
11831 if (PL_madskills) {
11832 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11833 const int len = s - tstart;
11835 sv_catpvn(PL_thisstuff, tstart, len);
11837 PL_thisstuff = newSVpvn(tstart, len);
11838 if (!PL_thisclose && !keep_delims)
11839 PL_thisclose = newSVpvn(s,termlen);
11844 sv_catpvn(sv, s, termlen);
11849 if (PL_madskills) {
11850 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11851 const int len = s - tstart - termlen;
11853 sv_catpvn(PL_thisstuff, tstart, len);
11855 PL_thisstuff = newSVpvn(tstart, len);
11856 if (!PL_thisclose && !keep_delims)
11857 PL_thisclose = newSVpvn(s - termlen,termlen);
11861 if (has_utf8 || PL_encoding)
11864 PL_multi_end = CopLINE(PL_curcop);
11866 /* if we allocated too much space, give some back */
11867 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11868 SvLEN_set(sv, SvCUR(sv) + 1);
11869 SvPV_renew(sv, SvLEN(sv));
11872 /* decide whether this is the first or second quoted string we've read
11885 takes: pointer to position in buffer
11886 returns: pointer to new position in buffer
11887 side-effects: builds ops for the constant in yylval.op
11889 Read a number in any of the formats that Perl accepts:
11891 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11892 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11895 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11897 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11900 If it reads a number without a decimal point or an exponent, it will
11901 try converting the number to an integer and see if it can do so
11902 without loss of precision.
11906 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11909 register const char *s = start; /* current position in buffer */
11910 register char *d; /* destination in temp buffer */
11911 register char *e; /* end of temp buffer */
11912 NV nv; /* number read, as a double */
11913 SV *sv = NULL; /* place to put the converted number */
11914 bool floatit; /* boolean: int or float? */
11915 const char *lastub = NULL; /* position of last underbar */
11916 static char const number_too_long[] = "Number too long";
11918 /* We use the first character to decide what type of number this is */
11922 Perl_croak(aTHX_ "panic: scan_num");
11924 /* if it starts with a 0, it could be an octal number, a decimal in
11925 0.13 disguise, or a hexadecimal number, or a binary number. */
11929 u holds the "number so far"
11930 shift the power of 2 of the base
11931 (hex == 4, octal == 3, binary == 1)
11932 overflowed was the number more than we can hold?
11934 Shift is used when we add a digit. It also serves as an "are
11935 we in octal/hex/binary?" indicator to disallow hex characters
11936 when in octal mode.
11941 bool overflowed = FALSE;
11942 bool just_zero = TRUE; /* just plain 0 or binary number? */
11943 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11944 static const char* const bases[5] =
11945 { "", "binary", "", "octal", "hexadecimal" };
11946 static const char* const Bases[5] =
11947 { "", "Binary", "", "Octal", "Hexadecimal" };
11948 static const char* const maxima[5] =
11950 "0b11111111111111111111111111111111",
11954 const char *base, *Base, *max;
11956 /* check for hex */
11961 } else if (s[1] == 'b') {
11966 /* check for a decimal in disguise */
11967 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11969 /* so it must be octal */
11976 if (ckWARN(WARN_SYNTAX))
11977 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11978 "Misplaced _ in number");
11982 base = bases[shift];
11983 Base = Bases[shift];
11984 max = maxima[shift];
11986 /* read the rest of the number */
11988 /* x is used in the overflow test,
11989 b is the digit we're adding on. */
11994 /* if we don't mention it, we're done */
11998 /* _ are ignored -- but warned about if consecutive */
12000 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12001 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12002 "Misplaced _ in number");
12006 /* 8 and 9 are not octal */
12007 case '8': case '9':
12009 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
12013 case '2': case '3': case '4':
12014 case '5': case '6': case '7':
12016 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
12019 case '0': case '1':
12020 b = *s++ & 15; /* ASCII digit -> value of digit */
12024 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
12025 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
12026 /* make sure they said 0x */
12029 b = (*s++ & 7) + 9;
12031 /* Prepare to put the digit we have onto the end
12032 of the number so far. We check for overflows.
12038 x = u << shift; /* make room for the digit */
12040 if ((x >> shift) != u
12041 && !(PL_hints & HINT_NEW_BINARY)) {
12044 if (ckWARN_d(WARN_OVERFLOW))
12045 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12046 "Integer overflow in %s number",
12049 u = x | b; /* add the digit to the end */
12052 n *= nvshift[shift];
12053 /* If an NV has not enough bits in its
12054 * mantissa to represent an UV this summing of
12055 * small low-order numbers is a waste of time
12056 * (because the NV cannot preserve the
12057 * low-order bits anyway): we could just
12058 * remember when did we overflow and in the
12059 * end just multiply n by the right
12067 /* if we get here, we had success: make a scalar value from
12072 /* final misplaced underbar check */
12073 if (s[-1] == '_') {
12074 if (ckWARN(WARN_SYNTAX))
12075 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12080 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
12081 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12082 "%s number > %s non-portable",
12088 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
12089 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12090 "%s number > %s non-portable",
12095 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
12096 sv = new_constant(start, s - start, "integer",
12098 else if (PL_hints & HINT_NEW_BINARY)
12099 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
12104 handle decimal numbers.
12105 we're also sent here when we read a 0 as the first digit
12107 case '1': case '2': case '3': case '4': case '5':
12108 case '6': case '7': case '8': case '9': case '.':
12111 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
12114 /* read next group of digits and _ and copy into d */
12115 while (isDIGIT(*s) || *s == '_') {
12116 /* skip underscores, checking for misplaced ones
12120 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12121 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12122 "Misplaced _ in number");
12126 /* check for end of fixed-length buffer */
12128 Perl_croak(aTHX_ number_too_long);
12129 /* if we're ok, copy the character */
12134 /* final misplaced underbar check */
12135 if (lastub && s == lastub + 1) {
12136 if (ckWARN(WARN_SYNTAX))
12137 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12140 /* read a decimal portion if there is one. avoid
12141 3..5 being interpreted as the number 3. followed
12144 if (*s == '.' && s[1] != '.') {
12149 if (ckWARN(WARN_SYNTAX))
12150 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12151 "Misplaced _ in number");
12155 /* copy, ignoring underbars, until we run out of digits.
12157 for (; isDIGIT(*s) || *s == '_'; s++) {
12158 /* fixed length buffer check */
12160 Perl_croak(aTHX_ number_too_long);
12162 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12163 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12164 "Misplaced _ in number");
12170 /* fractional part ending in underbar? */
12171 if (s[-1] == '_') {
12172 if (ckWARN(WARN_SYNTAX))
12173 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12174 "Misplaced _ in number");
12176 if (*s == '.' && isDIGIT(s[1])) {
12177 /* oops, it's really a v-string, but without the "v" */
12183 /* read exponent part, if present */
12184 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12188 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12189 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12191 /* stray preinitial _ */
12193 if (ckWARN(WARN_SYNTAX))
12194 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12195 "Misplaced _ in number");
12199 /* allow positive or negative exponent */
12200 if (*s == '+' || *s == '-')
12203 /* stray initial _ */
12205 if (ckWARN(WARN_SYNTAX))
12206 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12207 "Misplaced _ in number");
12211 /* read digits of exponent */
12212 while (isDIGIT(*s) || *s == '_') {
12215 Perl_croak(aTHX_ number_too_long);
12219 if (((lastub && s == lastub + 1) ||
12220 (!isDIGIT(s[1]) && s[1] != '_'))
12221 && ckWARN(WARN_SYNTAX))
12222 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12223 "Misplaced _ in number");
12230 /* make an sv from the string */
12234 We try to do an integer conversion first if no characters
12235 indicating "float" have been found.
12240 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12242 if (flags == IS_NUMBER_IN_UV) {
12244 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12247 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12248 if (uv <= (UV) IV_MIN)
12249 sv_setiv(sv, -(IV)uv);
12256 /* terminate the string */
12258 nv = Atof(PL_tokenbuf);
12262 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12263 (PL_hints & HINT_NEW_INTEGER) )
12264 sv = new_constant(PL_tokenbuf,
12267 (floatit ? "float" : "integer"),
12271 /* if it starts with a v, it could be a v-string */
12274 sv = newSV(5); /* preallocate storage space */
12275 s = scan_vstring(s, PL_bufend, sv);
12279 /* make the op for the constant and return */
12282 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12284 lvalp->opval = NULL;
12290 S_scan_formline(pTHX_ register char *s)
12293 register char *eol;
12295 SV * const stuff = newSVpvs("");
12296 bool needargs = FALSE;
12297 bool eofmt = FALSE;
12299 char *tokenstart = s;
12302 if (PL_madskills) {
12303 savewhite = PL_thiswhite;
12308 while (!needargs) {
12311 #ifdef PERL_STRICT_CR
12312 while (SPACE_OR_TAB(*t))
12315 while (SPACE_OR_TAB(*t) || *t == '\r')
12318 if (*t == '\n' || t == PL_bufend) {
12323 if (PL_in_eval && !PL_rsfp) {
12324 eol = (char *) memchr(s,'\n',PL_bufend-s);
12329 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12331 for (t = s; t < eol; t++) {
12332 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12334 goto enough; /* ~~ must be first line in formline */
12336 if (*t == '@' || *t == '^')
12340 sv_catpvn(stuff, s, eol-s);
12341 #ifndef PERL_STRICT_CR
12342 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12343 char *end = SvPVX(stuff) + SvCUR(stuff);
12346 SvCUR_set(stuff, SvCUR(stuff) - 1);
12356 if (PL_madskills) {
12358 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12360 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12363 s = filter_gets(PL_linestr, PL_rsfp, 0);
12365 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12367 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12369 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12370 PL_last_lop = PL_last_uni = NULL;
12379 if (SvCUR(stuff)) {
12382 PL_lex_state = LEX_NORMAL;
12383 start_force(PL_curforce);
12384 NEXTVAL_NEXTTOKE.ival = 0;
12388 PL_lex_state = LEX_FORMLINE;
12390 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12392 else if (PL_encoding)
12393 sv_recode_to_utf8(stuff, PL_encoding);
12395 start_force(PL_curforce);
12396 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12398 start_force(PL_curforce);
12399 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12403 SvREFCNT_dec(stuff);
12405 PL_lex_formbrack = 0;
12409 if (PL_madskills) {
12411 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12413 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12414 PL_thiswhite = savewhite;
12426 PL_cshlen = strlen(PL_cshname);
12428 #if defined(USE_ITHREADS)
12429 PERL_UNUSED_CONTEXT;
12435 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12438 const I32 oldsavestack_ix = PL_savestack_ix;
12439 CV* const outsidecv = PL_compcv;
12442 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12444 SAVEI32(PL_subline);
12445 save_item(PL_subname);
12446 SAVESPTR(PL_compcv);
12448 PL_compcv = (CV*)newSV_type(is_format ? SVt_PVFM : SVt_PVCV);
12449 CvFLAGS(PL_compcv) |= flags;
12451 PL_subline = CopLINE(PL_curcop);
12452 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12453 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12454 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12456 return oldsavestack_ix;
12460 #pragma segment Perl_yylex
12463 Perl_yywarn(pTHX_ const char *s)
12466 PL_in_eval |= EVAL_WARNONLY;
12468 PL_in_eval &= ~EVAL_WARNONLY;
12473 Perl_yyerror(pTHX_ const char *s)
12476 const char *where = NULL;
12477 const char *context = NULL;
12480 int yychar = PL_parser->yychar;
12482 if (!yychar || (yychar == ';' && !PL_rsfp))
12484 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12485 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12486 PL_oldbufptr != PL_bufptr) {
12489 The code below is removed for NetWare because it abends/crashes on NetWare
12490 when the script has error such as not having the closing quotes like:
12491 if ($var eq "value)
12492 Checking of white spaces is anyway done in NetWare code.
12495 while (isSPACE(*PL_oldoldbufptr))
12498 context = PL_oldoldbufptr;
12499 contlen = PL_bufptr - PL_oldoldbufptr;
12501 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12502 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12505 The code below is removed for NetWare because it abends/crashes on NetWare
12506 when the script has error such as not having the closing quotes like:
12507 if ($var eq "value)
12508 Checking of white spaces is anyway done in NetWare code.
12511 while (isSPACE(*PL_oldbufptr))
12514 context = PL_oldbufptr;
12515 contlen = PL_bufptr - PL_oldbufptr;
12517 else if (yychar > 255)
12518 where = "next token ???";
12519 else if (yychar == -2) { /* YYEMPTY */
12520 if (PL_lex_state == LEX_NORMAL ||
12521 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12522 where = "at end of line";
12523 else if (PL_lex_inpat)
12524 where = "within pattern";
12526 where = "within string";
12529 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12531 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12532 else if (isPRINT_LC(yychar))
12533 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12535 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12536 where = SvPVX_const(where_sv);
12538 msg = sv_2mortal(newSVpv(s, 0));
12539 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12540 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12542 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12544 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12545 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12546 Perl_sv_catpvf(aTHX_ msg,
12547 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12548 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12551 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12552 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
12555 if (PL_error_count >= 10) {
12556 if (PL_in_eval && SvCUR(ERRSV))
12557 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12558 SVfARG(ERRSV), OutCopFILE(PL_curcop));
12560 Perl_croak(aTHX_ "%s has too many errors.\n",
12561 OutCopFILE(PL_curcop));
12564 PL_in_my_stash = NULL;
12568 #pragma segment Main
12572 S_swallow_bom(pTHX_ U8 *s)
12575 const STRLEN slen = SvCUR(PL_linestr);
12578 if (s[1] == 0xFE) {
12579 /* UTF-16 little-endian? (or UTF32-LE?) */
12580 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12581 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12582 #ifndef PERL_NO_UTF16_FILTER
12583 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12586 if (PL_bufend > (char*)s) {
12590 filter_add(utf16rev_textfilter, NULL);
12591 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12592 utf16_to_utf8_reversed(s, news,
12593 PL_bufend - (char*)s - 1,
12595 sv_setpvn(PL_linestr, (const char*)news, newlen);
12597 s = (U8*)SvPVX(PL_linestr);
12598 Copy(news, s, newlen, U8);
12602 SvUTF8_on(PL_linestr);
12603 s = (U8*)SvPVX(PL_linestr);
12605 /* FIXME - is this a general bug fix? */
12608 PL_bufend = SvPVX(PL_linestr) + newlen;
12611 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12616 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12617 #ifndef PERL_NO_UTF16_FILTER
12618 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12621 if (PL_bufend > (char *)s) {
12625 filter_add(utf16_textfilter, NULL);
12626 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12627 utf16_to_utf8(s, news,
12628 PL_bufend - (char*)s,
12630 sv_setpvn(PL_linestr, (const char*)news, newlen);
12632 SvUTF8_on(PL_linestr);
12633 s = (U8*)SvPVX(PL_linestr);
12634 PL_bufend = SvPVX(PL_linestr) + newlen;
12637 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12642 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12643 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12644 s += 3; /* UTF-8 */
12650 if (s[2] == 0xFE && s[3] == 0xFF) {
12651 /* UTF-32 big-endian */
12652 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12655 else if (s[2] == 0 && s[3] != 0) {
12658 * are a good indicator of UTF-16BE. */
12659 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12665 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12666 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12667 s += 4; /* UTF-8 */
12673 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12676 * are a good indicator of UTF-16LE. */
12677 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12685 #ifndef PERL_NO_UTF16_FILTER
12687 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12690 const STRLEN old = SvCUR(sv);
12691 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12692 DEBUG_P(PerlIO_printf(Perl_debug_log,
12693 "utf16_textfilter(%p): %d %d (%d)\n",
12694 FPTR2DPTR(void *, utf16_textfilter),
12695 idx, maxlen, (int) count));
12699 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12700 Copy(SvPVX_const(sv), tmps, old, char);
12701 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12702 SvCUR(sv) - old, &newlen);
12703 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12705 DEBUG_P({sv_dump(sv);});
12710 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12713 const STRLEN old = SvCUR(sv);
12714 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12715 DEBUG_P(PerlIO_printf(Perl_debug_log,
12716 "utf16rev_textfilter(%p): %d %d (%d)\n",
12717 FPTR2DPTR(void *, utf16rev_textfilter),
12718 idx, maxlen, (int) count));
12722 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12723 Copy(SvPVX_const(sv), tmps, old, char);
12724 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12725 SvCUR(sv) - old, &newlen);
12726 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12728 DEBUG_P({ sv_dump(sv); });
12734 Returns a pointer to the next character after the parsed
12735 vstring, as well as updating the passed in sv.
12737 Function must be called like
12740 s = scan_vstring(s,e,sv);
12742 where s and e are the start and end of the string.
12743 The sv should already be large enough to store the vstring
12744 passed in, for performance reasons.
12749 Perl_scan_vstring(pTHX_ const char *s, const char *e, SV *sv)
12752 const char *pos = s;
12753 const char *start = s;
12754 if (*pos == 'v') pos++; /* get past 'v' */
12755 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12757 if ( *pos != '.') {
12758 /* this may not be a v-string if followed by => */
12759 const char *next = pos;
12760 while (next < e && isSPACE(*next))
12762 if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
12763 /* return string not v-string */
12764 sv_setpvn(sv,(char *)s,pos-s);
12765 return (char *)pos;
12769 if (!isALPHA(*pos)) {
12770 U8 tmpbuf[UTF8_MAXBYTES+1];
12773 s++; /* get past 'v' */
12775 sv_setpvn(sv, "", 0);
12778 /* this is atoi() that tolerates underscores */
12781 const char *end = pos;
12783 while (--end >= s) {
12785 const UV orev = rev;
12786 rev += (*end - '0') * mult;
12788 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12789 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12790 "Integer overflow in decimal number");
12794 if (rev > 0x7FFFFFFF)
12795 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12797 /* Append native character for the rev point */
12798 tmpend = uvchr_to_utf8(tmpbuf, rev);
12799 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12800 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12802 if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
12808 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12812 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12820 * c-indentation-style: bsd
12821 * c-basic-offset: 4
12822 * indent-tabs-mode: t
12825 * ex: set ts=8 sts=4 sw=4 noet: