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)
54 # define PL_endwhite (PL_parser->endwhite)
55 # define PL_faketokens (PL_parser->faketokens)
56 # define PL_lasttoke (PL_parser->lasttoke)
57 # define PL_nextwhite (PL_parser->nextwhite)
58 # define PL_realtokenstart (PL_parser->realtokenstart)
59 # define PL_skipwhite (PL_parser->skipwhite)
60 # define PL_thisclose (PL_parser->thisclose)
61 # define PL_thismad (PL_parser->thismad)
62 # define PL_thisopen (PL_parser->thisopen)
63 # define PL_thisstuff (PL_parser->thisstuff)
64 # define PL_thistoken (PL_parser->thistoken)
65 # define PL_thiswhite (PL_parser->thiswhite)
69 S_pending_ident(pTHX);
71 static const char ident_too_long[] = "Identifier too long";
72 static const char commaless_variable_list[] = "comma-less variable list";
74 static void restore_rsfp(pTHX_ void *f);
75 #ifndef PERL_NO_UTF16_FILTER
76 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
77 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
81 # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
82 # define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
84 # define CURMAD(slot,sv)
85 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
88 #define XFAKEBRACK 128
91 #ifdef USE_UTF8_SCRIPTS
92 # define UTF (!IN_BYTES)
94 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
97 /* In variables named $^X, these are the legal values for X.
98 * 1999-02-27 mjd-perl-patch@plover.com */
99 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
101 /* On MacOS, respect nonbreaking spaces */
102 #ifdef MACOS_TRADITIONAL
103 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
105 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
108 /* LEX_* are values for PL_lex_state, the state of the lexer.
109 * They are arranged oddly so that the guard on the switch statement
110 * can get by with a single comparison (if the compiler is smart enough).
113 /* #define LEX_NOTPARSING 11 is done in perl.h. */
115 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
116 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
117 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
118 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
119 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
121 /* at end of code, eg "$x" followed by: */
122 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
123 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
125 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
126 string or after \E, $foo, etc */
127 #define LEX_INTERPCONST 2 /* NOT USED */
128 #define LEX_FORMLINE 1 /* expecting a format line */
129 #define LEX_KNOWNEXT 0 /* next token known; just return it */
133 static const char* const lex_state_names[] = {
152 #include "keywords.h"
154 /* CLINE is a macro that ensures PL_copline has a sane value */
159 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
162 # define SKIPSPACE0(s) skipspace0(s)
163 # define SKIPSPACE1(s) skipspace1(s)
164 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
165 # define PEEKSPACE(s) skipspace2(s,0)
167 # define SKIPSPACE0(s) skipspace(s)
168 # define SKIPSPACE1(s) skipspace(s)
169 # define SKIPSPACE2(s,tsv) skipspace(s)
170 # define PEEKSPACE(s) skipspace(s)
174 * Convenience functions to return different tokens and prime the
175 * lexer for the next token. They all take an argument.
177 * TOKEN : generic token (used for '(', DOLSHARP, etc)
178 * OPERATOR : generic operator
179 * AOPERATOR : assignment operator
180 * PREBLOCK : beginning the block after an if, while, foreach, ...
181 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
182 * PREREF : *EXPR where EXPR is not a simple identifier
183 * TERM : expression term
184 * LOOPX : loop exiting command (goto, last, dump, etc)
185 * FTST : file test operator
186 * FUN0 : zero-argument function
187 * FUN1 : not used, except for not, which isn't a UNIOP
188 * BOop : bitwise or or xor
190 * SHop : shift operator
191 * PWop : power operator
192 * PMop : pattern-matching operator
193 * Aop : addition-level operator
194 * Mop : multiplication-level operator
195 * Eop : equality-testing operator
196 * Rop : relational operator <= != gt
198 * Also see LOP and lop() below.
201 #ifdef DEBUGGING /* Serve -DT. */
202 # define REPORT(retval) tokereport((I32)retval)
204 # define REPORT(retval) (retval)
207 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
208 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
209 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
210 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
211 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
212 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
213 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
214 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
215 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
216 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
217 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
218 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
219 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
220 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
221 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
222 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
223 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
224 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
225 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
226 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
228 /* This bit of chicanery makes a unary function followed by
229 * a parenthesis into a function with one argument, highest precedence.
230 * The UNIDOR macro is for unary functions that can be followed by the //
231 * operator (such as C<shift // 0>).
233 #define UNI2(f,x) { \
237 PL_last_uni = PL_oldbufptr; \
238 PL_last_lop_op = f; \
240 return REPORT( (int)FUNC1 ); \
242 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
244 #define UNI(f) UNI2(f,XTERM)
245 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
247 #define UNIBRACK(f) { \
250 PL_last_uni = PL_oldbufptr; \
252 return REPORT( (int)FUNC1 ); \
254 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
257 /* grandfather return to old style */
258 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
262 /* how to interpret the yylval associated with the token */
266 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
272 static struct debug_tokens {
274 enum token_type type;
276 } const debug_tokens[] =
278 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
279 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
280 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
281 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
282 { ARROW, TOKENTYPE_NONE, "ARROW" },
283 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
284 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
285 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
286 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
287 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
288 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
289 { DO, TOKENTYPE_NONE, "DO" },
290 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
291 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
292 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
293 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
294 { ELSE, TOKENTYPE_NONE, "ELSE" },
295 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
296 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
297 { FOR, TOKENTYPE_IVAL, "FOR" },
298 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
299 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
300 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
301 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
302 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
303 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
304 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
305 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
306 { IF, TOKENTYPE_IVAL, "IF" },
307 { LABEL, TOKENTYPE_PVAL, "LABEL" },
308 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
309 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
310 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
311 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
312 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
313 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
314 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
315 { MY, TOKENTYPE_IVAL, "MY" },
316 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
317 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
318 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
319 { OROP, TOKENTYPE_IVAL, "OROP" },
320 { OROR, TOKENTYPE_NONE, "OROR" },
321 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
322 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
323 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
324 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
325 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
326 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
327 { PREINC, TOKENTYPE_NONE, "PREINC" },
328 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
329 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
330 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
331 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
332 { SUB, TOKENTYPE_NONE, "SUB" },
333 { THING, TOKENTYPE_OPVAL, "THING" },
334 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
335 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
336 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
337 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
338 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
339 { USE, TOKENTYPE_IVAL, "USE" },
340 { WHEN, TOKENTYPE_IVAL, "WHEN" },
341 { WHILE, TOKENTYPE_IVAL, "WHILE" },
342 { WORD, TOKENTYPE_OPVAL, "WORD" },
343 { 0, TOKENTYPE_NONE, NULL }
346 /* dump the returned token in rv, plus any optional arg in yylval */
349 S_tokereport(pTHX_ I32 rv)
353 const char *name = NULL;
354 enum token_type type = TOKENTYPE_NONE;
355 const struct debug_tokens *p;
356 SV* const report = newSVpvs("<== ");
358 for (p = debug_tokens; p->token; p++) {
359 if (p->token == (int)rv) {
366 Perl_sv_catpv(aTHX_ report, name);
367 else if ((char)rv > ' ' && (char)rv < '~')
368 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
370 sv_catpvs(report, "EOF");
372 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
375 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
378 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
380 case TOKENTYPE_OPNUM:
381 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
382 PL_op_name[yylval.ival]);
385 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
387 case TOKENTYPE_OPVAL:
389 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
390 PL_op_name[yylval.opval->op_type]);
391 if (yylval.opval->op_type == OP_CONST) {
392 Perl_sv_catpvf(aTHX_ report, " %s",
393 SvPEEK(cSVOPx_sv(yylval.opval)));
398 sv_catpvs(report, "(opval=null)");
401 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
407 /* print the buffer with suitable escapes */
410 S_printbuf(pTHX_ const char* fmt, const char* s)
412 SV* const tmp = newSVpvs("");
413 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
422 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
423 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
427 S_ao(pTHX_ int toketype)
430 if (*PL_bufptr == '=') {
432 if (toketype == ANDAND)
433 yylval.ival = OP_ANDASSIGN;
434 else if (toketype == OROR)
435 yylval.ival = OP_ORASSIGN;
436 else if (toketype == DORDOR)
437 yylval.ival = OP_DORASSIGN;
445 * When Perl expects an operator and finds something else, no_op
446 * prints the warning. It always prints "<something> found where
447 * operator expected. It prints "Missing semicolon on previous line?"
448 * if the surprise occurs at the start of the line. "do you need to
449 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
450 * where the compiler doesn't know if foo is a method call or a function.
451 * It prints "Missing operator before end of line" if there's nothing
452 * after the missing operator, or "... before <...>" if there is something
453 * after the missing operator.
457 S_no_op(pTHX_ const char *what, char *s)
460 char * const oldbp = PL_bufptr;
461 const bool is_first = (PL_oldbufptr == PL_linestart);
467 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
468 if (ckWARN_d(WARN_SYNTAX)) {
470 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
471 "\t(Missing semicolon on previous line?)\n");
472 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
474 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
476 if (t < PL_bufptr && isSPACE(*t))
477 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
478 "\t(Do you need to predeclare %.*s?)\n",
479 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
483 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
484 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
492 * Complain about missing quote/regexp/heredoc terminator.
493 * If it's called with NULL then it cauterizes the line buffer.
494 * If we're in a delimited string and the delimiter is a control
495 * character, it's reformatted into a two-char sequence like ^C.
500 S_missingterm(pTHX_ char *s)
506 char * const nl = strrchr(s,'\n');
512 iscntrl(PL_multi_close)
514 PL_multi_close < 32 || PL_multi_close == 127
518 tmpbuf[1] = (char)toCTRL(PL_multi_close);
523 *tmpbuf = (char)PL_multi_close;
527 q = strchr(s,'"') ? '\'' : '"';
528 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
531 #define FEATURE_IS_ENABLED(name) \
532 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
533 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
535 * S_feature_is_enabled
536 * Check whether the named feature is enabled.
539 S_feature_is_enabled(pTHX_ const char *name, STRLEN namelen)
542 HV * const hinthv = GvHV(PL_hintgv);
543 char he_name[32] = "feature_";
544 (void) my_strlcpy(&he_name[8], name, 24);
546 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
554 Perl_deprecate(pTHX_ const char *s)
556 if (ckWARN(WARN_DEPRECATED))
557 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
561 Perl_deprecate_old(pTHX_ const char *s)
563 /* This function should NOT be called for any new deprecated warnings */
564 /* Use Perl_deprecate instead */
566 /* It is here to maintain backward compatibility with the pre-5.8 */
567 /* warnings category hierarchy. The "deprecated" category used to */
568 /* live under the "syntax" category. It is now a top-level category */
569 /* in its own right. */
571 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
572 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
573 "Use of %s is deprecated", s);
577 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
578 * utf16-to-utf8-reversed.
581 #ifdef PERL_CR_FILTER
585 register const char *s = SvPVX_const(sv);
586 register const char * const e = s + SvCUR(sv);
587 /* outer loop optimized to do nothing if there are no CR-LFs */
589 if (*s++ == '\r' && *s == '\n') {
590 /* hit a CR-LF, need to copy the rest */
591 register char *d = s - 1;
594 if (*s == '\r' && s[1] == '\n')
605 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
607 const I32 count = FILTER_READ(idx+1, sv, maxlen);
608 if (count > 0 && !maxlen)
618 * Create a parser object and initialise its parser and lexer fields
622 Perl_lex_start(pTHX_ SV *line)
625 const char *s = NULL;
629 /* create and initialise a parser */
631 Newxz(parser, 1, yy_parser);
632 parser->old_parser = PL_parser;
635 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
636 parser->ps = parser->stack;
637 parser->stack_size = YYINITDEPTH;
639 parser->stack->state = 0;
640 parser->yyerrstatus = 0;
641 parser->yychar = YYEMPTY; /* Cause a token to be read. */
643 /* on scope exit, free this parser and restore any outer one */
646 /* initialise lexer state */
648 SAVEI32(PL_lex_state);
650 if (PL_lex_state == LEX_KNOWNEXT) {
651 I32 toke = parser->old_parser->lasttoke;
652 while (--toke >= 0) {
653 SAVEI32(PL_nexttoke[toke].next_type);
654 SAVEVPTR(PL_nexttoke[toke].next_val);
656 SAVEVPTR(PL_nexttoke[toke].next_mad);
659 SAVEI32(PL_curforce);
662 if (PL_lex_state == LEX_KNOWNEXT) {
663 I32 toke = PL_nexttoke;
664 while (--toke >= 0) {
665 SAVEI32(PL_nexttype[toke]);
666 SAVEVPTR(PL_nextval[toke]);
668 SAVEI32(PL_nexttoke);
671 SAVECOPLINE(PL_curcop);
674 SAVEPPTR(PL_oldbufptr);
675 SAVEPPTR(PL_oldoldbufptr);
676 SAVEPPTR(PL_last_lop);
677 SAVEPPTR(PL_last_uni);
678 SAVEPPTR(PL_linestart);
679 SAVESPTR(PL_linestr);
680 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
684 PL_lex_state = LEX_NORMAL;
686 Newx(parser->lex_brackstack, 120, char);
687 Newx(parser->lex_casestack, 12, char);
688 *parser->lex_casestack = '\0';
694 s = SvPV_const(line, len);
699 PL_linestr = newSVpvs("\n;");
700 } else if (SvREADONLY(line) || s[len-1] != ';') {
701 PL_linestr = newSVsv(line);
703 sv_catpvs(PL_linestr, "\n;");
706 SvREFCNT_inc_simple_void_NN(line);
709 /* PL_linestr needs to survive until end of scope, not just the next
710 FREETMPS. See changes 17505 and 17546 which fixed the symptoms only. */
711 SAVEFREESV(PL_linestr);
712 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
713 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
714 PL_last_lop = PL_last_uni = NULL;
719 /* delete a parser object */
722 Perl_parser_free(pTHX_ const yy_parser *parser)
724 Safefree(parser->stack);
725 Safefree(parser->lex_brackstack);
726 Safefree(parser->lex_casestack);
727 PL_parser = parser->old_parser;
734 * Finalizer for lexing operations. Must be called when the parser is
735 * done with the lexer.
742 PL_doextract = FALSE;
747 * This subroutine has nothing to do with tilting, whether at windmills
748 * or pinball tables. Its name is short for "increment line". It
749 * increments the current line number in CopLINE(PL_curcop) and checks
750 * to see whether the line starts with a comment of the form
751 * # line 500 "foo.pm"
752 * If so, it sets the current line number and file to the values in the comment.
756 S_incline(pTHX_ const char *s)
763 CopLINE_inc(PL_curcop);
766 while (SPACE_OR_TAB(*s))
768 if (strnEQ(s, "line", 4))
772 if (SPACE_OR_TAB(*s))
776 while (SPACE_OR_TAB(*s))
784 while (SPACE_OR_TAB(*s))
786 if (*s == '"' && (t = strchr(s+1, '"'))) {
796 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
798 if (*e != '\n' && *e != '\0')
799 return; /* false alarm */
802 const STRLEN len = t - s;
804 const char * const cf = CopFILE(PL_curcop);
805 STRLEN tmplen = cf ? strlen(cf) : 0;
806 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
807 /* must copy *{"::_<(eval N)[oldfilename:L]"}
808 * to *{"::_<newfilename"} */
809 /* However, the long form of evals is only turned on by the
810 debugger - usually they're "(eval %lu)" */
814 STRLEN tmplen2 = len;
815 if (tmplen + 2 <= sizeof smallbuf)
818 Newx(tmpbuf, tmplen + 2, char);
821 memcpy(tmpbuf + 2, cf, tmplen);
823 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
828 if (tmplen2 + 2 <= sizeof smallbuf)
831 Newx(tmpbuf2, tmplen2 + 2, char);
833 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
834 /* Either they malloc'd it, or we malloc'd it,
835 so no prefix is present in ours. */
840 memcpy(tmpbuf2 + 2, s, tmplen2);
843 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
845 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
846 /* adjust ${"::_<newfilename"} to store the new file name */
847 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
848 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
849 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
852 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
854 if (tmpbuf != smallbuf) Safefree(tmpbuf);
857 CopFILE_free(PL_curcop);
858 CopFILE_setn(PL_curcop, s, len);
860 CopLINE_set(PL_curcop, atoi(n)-1);
864 /* skip space before PL_thistoken */
867 S_skipspace0(pTHX_ register char *s)
874 PL_thiswhite = newSVpvs("");
875 sv_catsv(PL_thiswhite, PL_skipwhite);
876 sv_free(PL_skipwhite);
879 PL_realtokenstart = s - SvPVX(PL_linestr);
883 /* skip space after PL_thistoken */
886 S_skipspace1(pTHX_ register char *s)
888 const char *start = s;
889 I32 startoff = start - SvPVX(PL_linestr);
894 start = SvPVX(PL_linestr) + startoff;
895 if (!PL_thistoken && PL_realtokenstart >= 0) {
896 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
897 PL_thistoken = newSVpvn(tstart, start - tstart);
899 PL_realtokenstart = -1;
902 PL_nextwhite = newSVpvs("");
903 sv_catsv(PL_nextwhite, PL_skipwhite);
904 sv_free(PL_skipwhite);
911 S_skipspace2(pTHX_ register char *s, SV **svp)
914 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
915 const I32 startoff = s - SvPVX(PL_linestr);
918 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
919 if (!PL_madskills || !svp)
921 start = SvPVX(PL_linestr) + startoff;
922 if (!PL_thistoken && PL_realtokenstart >= 0) {
923 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
924 PL_thistoken = newSVpvn(tstart, start - tstart);
925 PL_realtokenstart = -1;
930 sv_setsv(*svp, PL_skipwhite);
931 sv_free(PL_skipwhite);
940 S_update_debugger_info(pTHX_ SV *orig_sv, const char *buf, STRLEN len)
942 AV *av = CopFILEAVx(PL_curcop);
944 SV * const sv = newSV_type(SVt_PVMG);
946 sv_setsv(sv, orig_sv);
948 sv_setpvn(sv, buf, len);
951 av_store(av, (I32)CopLINE(PL_curcop), sv);
957 * Called to gobble the appropriate amount and type of whitespace.
958 * Skips comments as well.
962 S_skipspace(pTHX_ register char *s)
967 int startoff = s - SvPVX(PL_linestr);
970 sv_free(PL_skipwhite);
975 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
976 while (s < PL_bufend && SPACE_OR_TAB(*s))
986 SSize_t oldprevlen, oldoldprevlen;
987 SSize_t oldloplen = 0, oldunilen = 0;
988 while (s < PL_bufend && isSPACE(*s)) {
989 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
994 if (s < PL_bufend && *s == '#') {
995 while (s < PL_bufend && *s != '\n')
999 if (PL_in_eval && !PL_rsfp) {
1006 /* only continue to recharge the buffer if we're at the end
1007 * of the buffer, we're not reading from a source filter, and
1008 * we're in normal lexing mode
1010 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
1011 PL_lex_state == LEX_FORMLINE)
1018 /* try to recharge the buffer */
1020 curoff = s - SvPVX(PL_linestr);
1023 if ((s = filter_gets(PL_linestr, PL_rsfp,
1024 (prevlen = SvCUR(PL_linestr)))) == NULL)
1027 if (PL_madskills && curoff != startoff) {
1029 PL_skipwhite = newSVpvs("");
1030 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1034 /* mustn't throw out old stuff yet if madpropping */
1035 SvCUR(PL_linestr) = curoff;
1036 s = SvPVX(PL_linestr) + curoff;
1038 if (curoff && s[-1] == '\n')
1042 /* end of file. Add on the -p or -n magic */
1043 /* XXX these shouldn't really be added here, can't set PL_faketokens */
1046 sv_catpvs(PL_linestr,
1047 ";}continue{print or die qq(-p destination: $!\\n);}");
1049 sv_setpvs(PL_linestr,
1050 ";}continue{print or die qq(-p destination: $!\\n);}");
1052 PL_minus_n = PL_minus_p = 0;
1054 else if (PL_minus_n) {
1056 sv_catpvn(PL_linestr, ";}", 2);
1058 sv_setpvn(PL_linestr, ";}", 2);
1064 sv_catpvn(PL_linestr,";", 1);
1066 sv_setpvn(PL_linestr,";", 1);
1069 /* reset variables for next time we lex */
1070 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
1076 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1077 PL_last_lop = PL_last_uni = NULL;
1079 /* Close the filehandle. Could be from -P preprocessor,
1080 * STDIN, or a regular file. If we were reading code from
1081 * STDIN (because the commandline held no -e or filename)
1082 * then we don't close it, we reset it so the code can
1083 * read from STDIN too.
1086 if (PL_preprocess && !PL_in_eval)
1087 (void)PerlProc_pclose(PL_rsfp);
1088 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1089 PerlIO_clearerr(PL_rsfp);
1091 (void)PerlIO_close(PL_rsfp);
1096 /* not at end of file, so we only read another line */
1097 /* make corresponding updates to old pointers, for yyerror() */
1098 oldprevlen = PL_oldbufptr - PL_bufend;
1099 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1101 oldunilen = PL_last_uni - PL_bufend;
1103 oldloplen = PL_last_lop - PL_bufend;
1104 PL_linestart = PL_bufptr = s + prevlen;
1105 PL_bufend = s + SvCUR(PL_linestr);
1107 PL_oldbufptr = s + oldprevlen;
1108 PL_oldoldbufptr = s + oldoldprevlen;
1110 PL_last_uni = s + oldunilen;
1112 PL_last_lop = s + oldloplen;
1115 /* debugger active and we're not compiling the debugger code,
1116 * so store the line into the debugger's array of lines
1118 if (PERLDB_LINE && PL_curstash != PL_debstash)
1119 update_debugger_info(NULL, PL_bufptr, PL_bufend - PL_bufptr);
1126 PL_skipwhite = newSVpvs("");
1127 curoff = s - SvPVX(PL_linestr);
1128 if (curoff - startoff)
1129 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1138 * Check the unary operators to ensure there's no ambiguity in how they're
1139 * used. An ambiguous piece of code would be:
1141 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1142 * the +5 is its argument.
1152 if (PL_oldoldbufptr != PL_last_uni)
1154 while (isSPACE(*PL_last_uni))
1157 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1159 if ((t = strchr(s, '(')) && t < PL_bufptr)
1162 if (ckWARN_d(WARN_AMBIGUOUS)){
1163 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1164 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1165 (int)(s - PL_last_uni), PL_last_uni);
1170 * LOP : macro to build a list operator. Its behaviour has been replaced
1171 * with a subroutine, S_lop() for which LOP is just another name.
1174 #define LOP(f,x) return lop(f,x,s)
1178 * Build a list operator (or something that might be one). The rules:
1179 * - if we have a next token, then it's a list operator [why?]
1180 * - if the next thing is an opening paren, then it's a function
1181 * - else it's a list operator
1185 S_lop(pTHX_ I32 f, int x, char *s)
1192 PL_last_lop = PL_oldbufptr;
1193 PL_last_lop_op = (OPCODE)f;
1196 return REPORT(LSTOP);
1199 return REPORT(LSTOP);
1202 return REPORT(FUNC);
1205 return REPORT(FUNC);
1207 return REPORT(LSTOP);
1213 * Sets up for an eventual force_next(). start_force(0) basically does
1214 * an unshift, while start_force(-1) does a push. yylex removes items
1219 S_start_force(pTHX_ int where)
1223 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1224 where = PL_lasttoke;
1225 assert(PL_curforce < 0 || PL_curforce == where);
1226 if (PL_curforce != where) {
1227 for (i = PL_lasttoke; i > where; --i) {
1228 PL_nexttoke[i] = PL_nexttoke[i-1];
1232 if (PL_curforce < 0) /* in case of duplicate start_force() */
1233 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1234 PL_curforce = where;
1237 curmad('^', newSVpvs(""));
1238 CURMAD('_', PL_nextwhite);
1243 S_curmad(pTHX_ char slot, SV *sv)
1249 if (PL_curforce < 0)
1250 where = &PL_thismad;
1252 where = &PL_nexttoke[PL_curforce].next_mad;
1255 sv_setpvn(sv, "", 0);
1258 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1260 else if (PL_encoding) {
1261 sv_recode_to_utf8(sv, PL_encoding);
1266 /* keep a slot open for the head of the list? */
1267 if (slot != '_' && *where && (*where)->mad_key == '^') {
1268 (*where)->mad_key = slot;
1269 sv_free((*where)->mad_val);
1270 (*where)->mad_val = (void*)sv;
1273 addmad(newMADsv(slot, sv), where, 0);
1276 # define start_force(where) NOOP
1277 # define curmad(slot, sv) NOOP
1282 * When the lexer realizes it knows the next token (for instance,
1283 * it is reordering tokens for the parser) then it can call S_force_next
1284 * to know what token to return the next time the lexer is called. Caller
1285 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1286 * and possibly PL_expect to ensure the lexer handles the token correctly.
1290 S_force_next(pTHX_ I32 type)
1294 if (PL_curforce < 0)
1295 start_force(PL_lasttoke);
1296 PL_nexttoke[PL_curforce].next_type = type;
1297 if (PL_lex_state != LEX_KNOWNEXT)
1298 PL_lex_defer = PL_lex_state;
1299 PL_lex_state = LEX_KNOWNEXT;
1300 PL_lex_expect = PL_expect;
1303 PL_nexttype[PL_nexttoke] = type;
1305 if (PL_lex_state != LEX_KNOWNEXT) {
1306 PL_lex_defer = PL_lex_state;
1307 PL_lex_expect = PL_expect;
1308 PL_lex_state = LEX_KNOWNEXT;
1314 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1317 SV * const sv = newSVpvn(start,len);
1318 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1325 * When the lexer knows the next thing is a word (for instance, it has
1326 * just seen -> and it knows that the next char is a word char, then
1327 * it calls S_force_word to stick the next word into the PL_nexttoke/val
1331 * char *start : buffer position (must be within PL_linestr)
1332 * int token : PL_next* will be this type of bare word (e.g., METHOD,WORD)
1333 * int check_keyword : if true, Perl checks to make sure the word isn't
1334 * a keyword (do this if the word is a label, e.g. goto FOO)
1335 * int allow_pack : if true, : characters will also be allowed (require,
1336 * use, etc. do this)
1337 * int allow_initial_tick : used by the "sub" lexer only.
1341 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1347 start = SKIPSPACE1(start);
1349 if (isIDFIRST_lazy_if(s,UTF) ||
1350 (allow_pack && *s == ':') ||
1351 (allow_initial_tick && *s == '\'') )
1353 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1354 if (check_keyword && keyword(PL_tokenbuf, len, 0))
1356 start_force(PL_curforce);
1358 curmad('X', newSVpvn(start,s-start));
1359 if (token == METHOD) {
1364 PL_expect = XOPERATOR;
1367 NEXTVAL_NEXTTOKE.opval
1368 = (OP*)newSVOP(OP_CONST,0,
1369 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1370 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1378 * Called when the lexer wants $foo *foo &foo etc, but the program
1379 * text only contains the "foo" portion. The first argument is a pointer
1380 * to the "foo", and the second argument is the type symbol to prefix.
1381 * Forces the next token to be a "WORD".
1382 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1386 S_force_ident(pTHX_ register const char *s, int kind)
1390 const STRLEN len = strlen(s);
1391 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1392 start_force(PL_curforce);
1393 NEXTVAL_NEXTTOKE.opval = o;
1396 o->op_private = OPpCONST_ENTERED;
1397 /* XXX see note in pp_entereval() for why we forgo typo
1398 warnings if the symbol must be introduced in an eval.
1400 gv_fetchpvn_flags(s, len,
1401 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1403 kind == '$' ? SVt_PV :
1404 kind == '@' ? SVt_PVAV :
1405 kind == '%' ? SVt_PVHV :
1413 Perl_str_to_version(pTHX_ SV *sv)
1418 const char *start = SvPV_const(sv,len);
1419 const char * const end = start + len;
1420 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1421 while (start < end) {
1425 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1430 retval += ((NV)n)/nshift;
1439 * Forces the next token to be a version number.
1440 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1441 * and if "guessing" is TRUE, then no new token is created (and the caller
1442 * must use an alternative parsing method).
1446 S_force_version(pTHX_ char *s, int guessing)
1452 I32 startoff = s - SvPVX(PL_linestr);
1461 while (isDIGIT(*d) || *d == '_' || *d == '.')
1465 start_force(PL_curforce);
1466 curmad('X', newSVpvn(s,d-s));
1469 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1471 s = scan_num(s, &yylval);
1472 version = yylval.opval;
1473 ver = cSVOPx(version)->op_sv;
1474 if (SvPOK(ver) && !SvNIOK(ver)) {
1475 SvUPGRADE(ver, SVt_PVNV);
1476 SvNV_set(ver, str_to_version(ver));
1477 SvNOK_on(ver); /* hint that it is a version */
1480 else if (guessing) {
1483 sv_free(PL_nextwhite); /* let next token collect whitespace */
1485 s = SvPVX(PL_linestr) + startoff;
1493 if (PL_madskills && !version) {
1494 sv_free(PL_nextwhite); /* let next token collect whitespace */
1496 s = SvPVX(PL_linestr) + startoff;
1499 /* NOTE: The parser sees the package name and the VERSION swapped */
1500 start_force(PL_curforce);
1501 NEXTVAL_NEXTTOKE.opval = version;
1509 * Tokenize a quoted string passed in as an SV. It finds the next
1510 * chunk, up to end of string or a backslash. It may make a new
1511 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1516 S_tokeq(pTHX_ SV *sv)
1520 register char *send;
1528 s = SvPV_force(sv, len);
1529 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1532 while (s < send && *s != '\\')
1537 if ( PL_hints & HINT_NEW_STRING ) {
1538 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1544 if (s + 1 < send && (s[1] == '\\'))
1545 s++; /* all that, just for this */
1550 SvCUR_set(sv, d - SvPVX_const(sv));
1552 if ( PL_hints & HINT_NEW_STRING )
1553 return new_constant(NULL, 0, "q", sv, pv, "q");
1558 * Now come three functions related to double-quote context,
1559 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1560 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1561 * interact with PL_lex_state, and create fake ( ... ) argument lists
1562 * to handle functions and concatenation.
1563 * They assume that whoever calls them will be setting up a fake
1564 * join call, because each subthing puts a ',' after it. This lets
1567 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1569 * (I'm not sure whether the spurious commas at the end of lcfirst's
1570 * arguments and join's arguments are created or not).
1575 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1577 * Pattern matching will set PL_lex_op to the pattern-matching op to
1578 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1580 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1582 * Everything else becomes a FUNC.
1584 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1585 * had an OP_CONST or OP_READLINE). This just sets us up for a
1586 * call to S_sublex_push().
1590 S_sublex_start(pTHX)
1593 register const I32 op_type = yylval.ival;
1595 if (op_type == OP_NULL) {
1596 yylval.opval = PL_lex_op;
1600 if (op_type == OP_CONST || op_type == OP_READLINE) {
1601 SV *sv = tokeq(PL_lex_stuff);
1603 if (SvTYPE(sv) == SVt_PVIV) {
1604 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1606 const char * const p = SvPV_const(sv, len);
1607 SV * const nsv = newSVpvn(p, len);
1613 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1614 PL_lex_stuff = NULL;
1615 /* Allow <FH> // "foo" */
1616 if (op_type == OP_READLINE)
1617 PL_expect = XTERMORDORDOR;
1620 else if (op_type == OP_BACKTICK && PL_lex_op) {
1621 /* readpipe() vas overriden */
1622 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1623 yylval.opval = PL_lex_op;
1625 PL_lex_stuff = NULL;
1629 PL_sublex_info.super_state = PL_lex_state;
1630 PL_sublex_info.sub_inwhat = op_type;
1631 PL_sublex_info.sub_op = PL_lex_op;
1632 PL_lex_state = LEX_INTERPPUSH;
1636 yylval.opval = PL_lex_op;
1646 * Create a new scope to save the lexing state. The scope will be
1647 * ended in S_sublex_done. Returns a '(', starting the function arguments
1648 * to the uc, lc, etc. found before.
1649 * Sets PL_lex_state to LEX_INTERPCONCAT.
1658 PL_lex_state = PL_sublex_info.super_state;
1659 SAVEI32(PL_lex_dojoin);
1660 SAVEI32(PL_lex_brackets);
1661 SAVEI32(PL_lex_casemods);
1662 SAVEI32(PL_lex_starts);
1663 SAVEI32(PL_lex_state);
1664 SAVEVPTR(PL_lex_inpat);
1665 SAVEI32(PL_lex_inwhat);
1666 SAVECOPLINE(PL_curcop);
1667 SAVEPPTR(PL_bufptr);
1668 SAVEPPTR(PL_bufend);
1669 SAVEPPTR(PL_oldbufptr);
1670 SAVEPPTR(PL_oldoldbufptr);
1671 SAVEPPTR(PL_last_lop);
1672 SAVEPPTR(PL_last_uni);
1673 SAVEPPTR(PL_linestart);
1674 SAVESPTR(PL_linestr);
1675 SAVEGENERICPV(PL_lex_brackstack);
1676 SAVEGENERICPV(PL_lex_casestack);
1678 PL_linestr = PL_lex_stuff;
1679 PL_lex_stuff = NULL;
1681 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1682 = SvPVX(PL_linestr);
1683 PL_bufend += SvCUR(PL_linestr);
1684 PL_last_lop = PL_last_uni = NULL;
1685 SAVEFREESV(PL_linestr);
1687 PL_lex_dojoin = FALSE;
1688 PL_lex_brackets = 0;
1689 Newx(PL_lex_brackstack, 120, char);
1690 Newx(PL_lex_casestack, 12, char);
1691 PL_lex_casemods = 0;
1692 *PL_lex_casestack = '\0';
1694 PL_lex_state = LEX_INTERPCONCAT;
1695 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1697 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1698 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1699 PL_lex_inpat = PL_sublex_info.sub_op;
1701 PL_lex_inpat = NULL;
1708 * Restores lexer state after a S_sublex_push.
1715 if (!PL_lex_starts++) {
1716 SV * const sv = newSVpvs("");
1717 if (SvUTF8(PL_linestr))
1719 PL_expect = XOPERATOR;
1720 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1724 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1725 PL_lex_state = LEX_INTERPCASEMOD;
1729 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1730 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1731 PL_linestr = PL_lex_repl;
1733 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1734 PL_bufend += SvCUR(PL_linestr);
1735 PL_last_lop = PL_last_uni = NULL;
1736 SAVEFREESV(PL_linestr);
1737 PL_lex_dojoin = FALSE;
1738 PL_lex_brackets = 0;
1739 PL_lex_casemods = 0;
1740 *PL_lex_casestack = '\0';
1742 if (SvEVALED(PL_lex_repl)) {
1743 PL_lex_state = LEX_INTERPNORMAL;
1745 /* we don't clear PL_lex_repl here, so that we can check later
1746 whether this is an evalled subst; that means we rely on the
1747 logic to ensure sublex_done() is called again only via the
1748 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1751 PL_lex_state = LEX_INTERPCONCAT;
1761 PL_endwhite = newSVpvs("");
1762 sv_catsv(PL_endwhite, PL_thiswhite);
1766 sv_setpvn(PL_thistoken,"",0);
1768 PL_realtokenstart = -1;
1772 PL_bufend = SvPVX(PL_linestr);
1773 PL_bufend += SvCUR(PL_linestr);
1774 PL_expect = XOPERATOR;
1775 PL_sublex_info.sub_inwhat = 0;
1783 Extracts a pattern, double-quoted string, or transliteration. This
1786 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
1787 processing a pattern (PL_lex_inpat is true), a transliteration
1788 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
1790 Returns a pointer to the character scanned up to. If this is
1791 advanced from the start pointer supplied (i.e. if anything was
1792 successfully parsed), will leave an OP for the substring scanned
1793 in yylval. Caller must intuit reason for not parsing further
1794 by looking at the next characters herself.
1798 double-quoted style: \r and \n
1799 regexp special ones: \D \s
1802 case and quoting: \U \Q \E
1803 stops on @ and $, but not for $ as tail anchor
1805 In transliterations:
1806 characters are VERY literal, except for - not at the start or end
1807 of the string, which indicates a range. If the range is in bytes,
1808 scan_const expands the range to the full set of intermediate
1809 characters. If the range is in utf8, the hyphen is replaced with
1810 a certain range mark which will be handled by pmtrans() in op.c.
1812 In double-quoted strings:
1814 double-quoted style: \r and \n
1816 deprecated backrefs: \1 (in substitution replacements)
1817 case and quoting: \U \Q \E
1820 scan_const does *not* construct ops to handle interpolated strings.
1821 It stops processing as soon as it finds an embedded $ or @ variable
1822 and leaves it to the caller to work out what's going on.
1824 embedded arrays (whether in pattern or not) could be:
1825 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1827 $ in double-quoted strings must be the symbol of an embedded scalar.
1829 $ in pattern could be $foo or could be tail anchor. Assumption:
1830 it's a tail anchor if $ is the last thing in the string, or if it's
1831 followed by one of "()| \r\n\t"
1833 \1 (backreferences) are turned into $1
1835 The structure of the code is
1836 while (there's a character to process) {
1837 handle transliteration ranges
1838 skip regexp comments /(?#comment)/ and codes /(?{code})/
1839 skip #-initiated comments in //x patterns
1840 check for embedded arrays
1841 check for embedded scalars
1843 leave intact backslashes from leaveit (below)
1844 deprecate \1 in substitution replacements
1845 handle string-changing backslashes \l \U \Q \E, etc.
1846 switch (what was escaped) {
1847 handle \- in a transliteration (becomes a literal -)
1848 handle \132 (octal characters)
1849 handle \x15 and \x{1234} (hex characters)
1850 handle \N{name} (named characters)
1851 handle \cV (control characters)
1852 handle printf-style backslashes (\f, \r, \n, etc)
1854 } (end if backslash)
1855 } (end while character to read)
1860 S_scan_const(pTHX_ char *start)
1863 register char *send = PL_bufend; /* end of the constant */
1864 SV *sv = newSV(send - start); /* sv for the constant */
1865 register char *s = start; /* start of the constant */
1866 register char *d = SvPVX(sv); /* destination for copies */
1867 bool dorange = FALSE; /* are we in a translit range? */
1868 bool didrange = FALSE; /* did we just finish a range? */
1869 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1870 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1873 UV literal_endpoint = 0;
1874 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
1877 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1878 /* If we are doing a trans and we know we want UTF8 set expectation */
1879 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1880 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1884 while (s < send || dorange) {
1885 /* get transliterations out of the way (they're most literal) */
1886 if (PL_lex_inwhat == OP_TRANS) {
1887 /* expand a range A-Z to the full set of characters. AIE! */
1889 I32 i; /* current expanded character */
1890 I32 min; /* first character in range */
1891 I32 max; /* last character in range */
1902 char * const c = (char*)utf8_hop((U8*)d, -1);
1906 *c = (char)UTF_TO_NATIVE(0xff);
1907 /* mark the range as done, and continue */
1913 i = d - SvPVX_const(sv); /* remember current offset */
1916 SvLEN(sv) + (has_utf8 ?
1917 (512 - UTF_CONTINUATION_MARK +
1920 /* How many two-byte within 0..255: 128 in UTF-8,
1921 * 96 in UTF-8-mod. */
1923 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1925 d = SvPVX(sv) + i; /* refresh d after realloc */
1929 for (j = 0; j <= 1; j++) {
1930 char * const c = (char*)utf8_hop((U8*)d, -1);
1931 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
1937 max = (U8)0xff; /* only to \xff */
1938 uvmax = uv; /* \x{100} to uvmax */
1940 d = c; /* eat endpoint chars */
1945 d -= 2; /* eat the first char and the - */
1946 min = (U8)*d; /* first char in range */
1947 max = (U8)d[1]; /* last char in range */
1954 "Invalid range \"%c-%c\" in transliteration operator",
1955 (char)min, (char)max);
1959 if (literal_endpoint == 2 &&
1960 ((isLOWER(min) && isLOWER(max)) ||
1961 (isUPPER(min) && isUPPER(max)))) {
1963 for (i = min; i <= max; i++)
1965 *d++ = NATIVE_TO_NEED(has_utf8,i);
1967 for (i = min; i <= max; i++)
1969 *d++ = NATIVE_TO_NEED(has_utf8,i);
1974 for (i = min; i <= max; i++)
1977 const U8 ch = (U8)NATIVE_TO_UTF(i);
1978 if (UNI_IS_INVARIANT(ch))
1981 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
1982 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
1991 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
1993 *d++ = (char)UTF_TO_NATIVE(0xff);
1995 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
1999 /* mark the range as done, and continue */
2003 literal_endpoint = 0;
2008 /* range begins (ignore - as first or last char) */
2009 else if (*s == '-' && s+1 < send && s != start) {
2011 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
2018 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
2028 literal_endpoint = 0;
2029 native_range = TRUE;
2034 /* if we get here, we're not doing a transliteration */
2036 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2037 except for the last char, which will be done separately. */
2038 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
2040 while (s+1 < send && *s != ')')
2041 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2043 else if (s[2] == '{' /* This should match regcomp.c */
2044 || (s[2] == '?' && s[3] == '{'))
2047 char *regparse = s + (s[2] == '{' ? 3 : 4);
2050 while (count && (c = *regparse)) {
2051 if (c == '\\' && regparse[1])
2059 if (*regparse != ')')
2060 regparse--; /* Leave one char for continuation. */
2061 while (s < regparse)
2062 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2066 /* likewise skip #-initiated comments in //x patterns */
2067 else if (*s == '#' && PL_lex_inpat &&
2068 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2069 while (s+1 < send && *s != '\n')
2070 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2073 /* check for embedded arrays
2074 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2076 else if (*s == '@' && s[1]) {
2077 if (isALNUM_lazy_if(s+1,UTF))
2079 if (strchr(":'{$", s[1]))
2081 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2082 break; /* in regexp, neither @+ nor @- are interpolated */
2085 /* check for embedded scalars. only stop if we're sure it's a
2088 else if (*s == '$') {
2089 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
2091 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
2092 break; /* in regexp, $ might be tail anchor */
2095 /* End of else if chain - OP_TRANS rejoin rest */
2098 if (*s == '\\' && s+1 < send) {
2101 /* deprecate \1 in strings and substitution replacements */
2102 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2103 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2105 if (ckWARN(WARN_SYNTAX))
2106 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2111 /* string-change backslash escapes */
2112 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2116 /* skip any other backslash escapes in a pattern */
2117 else if (PL_lex_inpat) {
2118 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2119 goto default_action;
2122 /* if we get here, it's either a quoted -, or a digit */
2125 /* quoted - in transliterations */
2127 if (PL_lex_inwhat == OP_TRANS) {
2134 if ((isALPHA(*s) || isDIGIT(*s)) &&
2136 Perl_warner(aTHX_ packWARN(WARN_MISC),
2137 "Unrecognized escape \\%c passed through",
2139 /* default action is to copy the quoted character */
2140 goto default_action;
2143 /* \132 indicates an octal constant */
2144 case '0': case '1': case '2': case '3':
2145 case '4': case '5': case '6': case '7':
2149 uv = grok_oct(s, &len, &flags, NULL);
2152 goto NUM_ESCAPE_INSERT;
2154 /* \x24 indicates a hex constant */
2158 char* const e = strchr(s, '}');
2159 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2160 PERL_SCAN_DISALLOW_PREFIX;
2165 yyerror("Missing right brace on \\x{}");
2169 uv = grok_hex(s, &len, &flags, NULL);
2175 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2176 uv = grok_hex(s, &len, &flags, NULL);
2182 /* Insert oct or hex escaped character.
2183 * There will always enough room in sv since such
2184 * escapes will be longer than any UTF-8 sequence
2185 * they can end up as. */
2187 /* We need to map to chars to ASCII before doing the tests
2190 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2191 if (!has_utf8 && uv > 255) {
2192 /* Might need to recode whatever we have
2193 * accumulated so far if it contains any
2196 * (Can't we keep track of that and avoid
2197 * this rescan? --jhi)
2201 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2202 if (!NATIVE_IS_INVARIANT(*c)) {
2207 const STRLEN offset = d - SvPVX_const(sv);
2209 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2213 while (src >= (const U8 *)SvPVX_const(sv)) {
2214 if (!NATIVE_IS_INVARIANT(*src)) {
2215 const U8 ch = NATIVE_TO_ASCII(*src);
2216 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2217 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2227 if (has_utf8 || uv > 255) {
2228 d = (char*)uvchr_to_utf8((U8*)d, uv);
2230 if (PL_lex_inwhat == OP_TRANS &&
2231 PL_sublex_info.sub_op) {
2232 PL_sublex_info.sub_op->op_private |=
2233 (PL_lex_repl ? OPpTRANS_FROM_UTF
2237 if (uv > 255 && !dorange)
2238 native_range = FALSE;
2250 /* \N{LATIN SMALL LETTER A} is a named character */
2254 char* e = strchr(s, '}');
2261 yyerror("Missing right brace on \\N{}");
2265 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2267 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2268 PERL_SCAN_DISALLOW_PREFIX;
2271 uv = grok_hex(s, &len, &flags, NULL);
2272 if ( e > s && len != (STRLEN)(e - s) ) {
2276 goto NUM_ESCAPE_INSERT;
2278 res = newSVpvn(s + 1, e - s - 1);
2279 type = newSVpvn(s - 2,e - s + 3);
2280 res = new_constant( NULL, 0, "charnames",
2281 res, NULL, SvPVX(type) );
2284 sv_utf8_upgrade(res);
2285 str = SvPV_const(res,len);
2286 #ifdef EBCDIC_NEVER_MIND
2287 /* charnames uses pack U and that has been
2288 * recently changed to do the below uni->native
2289 * mapping, so this would be redundant (and wrong,
2290 * the code point would be doubly converted).
2291 * But leave this in just in case the pack U change
2292 * gets revoked, but the semantics is still
2293 * desireable for charnames. --jhi */
2295 UV uv = utf8_to_uvchr((const U8*)str, 0);
2298 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2300 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2301 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2302 str = SvPV_const(res, len);
2306 if (!has_utf8 && SvUTF8(res)) {
2307 const char * const ostart = SvPVX_const(sv);
2308 SvCUR_set(sv, d - ostart);
2311 sv_utf8_upgrade(sv);
2312 /* this just broke our allocation above... */
2313 SvGROW(sv, (STRLEN)(send - start));
2314 d = SvPVX(sv) + SvCUR(sv);
2317 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2318 const char * const odest = SvPVX_const(sv);
2320 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2321 d = SvPVX(sv) + (d - odest);
2325 native_range = FALSE; /* \N{} is guessed to be Unicode */
2327 Copy(str, d, len, char);
2334 yyerror("Missing braces on \\N{}");
2337 /* \c is a control character */
2346 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2349 yyerror("Missing control char name in \\c");
2353 /* printf-style backslashes, formfeeds, newlines, etc */
2355 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2358 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2361 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2364 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2367 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2370 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2373 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2379 } /* end if (backslash) */
2386 /* If we started with encoded form, or already know we want it
2387 and then encode the next character */
2388 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2390 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2391 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2394 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2395 const STRLEN off = d - SvPVX_const(sv);
2396 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2398 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2401 if (uv > 255 && !dorange)
2402 native_range = FALSE;
2406 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2408 } /* while loop to process each character */
2410 /* terminate the string and set up the sv */
2412 SvCUR_set(sv, d - SvPVX_const(sv));
2413 if (SvCUR(sv) >= SvLEN(sv))
2414 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2417 if (PL_encoding && !has_utf8) {
2418 sv_recode_to_utf8(sv, PL_encoding);
2424 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2425 PL_sublex_info.sub_op->op_private |=
2426 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2430 /* shrink the sv if we allocated more than we used */
2431 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2432 SvPV_shrink_to_cur(sv);
2435 /* return the substring (via yylval) only if we parsed anything */
2436 if (s > PL_bufptr) {
2437 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2438 sv = new_constant(start, s - start,
2439 (const char *)(PL_lex_inpat ? "qr" : "q"),
2442 (( PL_lex_inwhat == OP_TRANS
2444 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2447 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2454 * Returns TRUE if there's more to the expression (e.g., a subscript),
2457 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2459 * ->[ and ->{ return TRUE
2460 * { and [ outside a pattern are always subscripts, so return TRUE
2461 * if we're outside a pattern and it's not { or [, then return FALSE
2462 * if we're in a pattern and the first char is a {
2463 * {4,5} (any digits around the comma) returns FALSE
2464 * if we're in a pattern and the first char is a [
2466 * [SOMETHING] has a funky algorithm to decide whether it's a
2467 * character class or not. It has to deal with things like
2468 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2469 * anything else returns TRUE
2472 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2475 S_intuit_more(pTHX_ register char *s)
2478 if (PL_lex_brackets)
2480 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2482 if (*s != '{' && *s != '[')
2487 /* In a pattern, so maybe we have {n,m}. */
2504 /* On the other hand, maybe we have a character class */
2507 if (*s == ']' || *s == '^')
2510 /* this is terrifying, and it works */
2511 int weight = 2; /* let's weigh the evidence */
2513 unsigned char un_char = 255, last_un_char;
2514 const char * const send = strchr(s,']');
2515 char tmpbuf[sizeof PL_tokenbuf * 4];
2517 if (!send) /* has to be an expression */
2520 Zero(seen,256,char);
2523 else if (isDIGIT(*s)) {
2525 if (isDIGIT(s[1]) && s[2] == ']')
2531 for (; s < send; s++) {
2532 last_un_char = un_char;
2533 un_char = (unsigned char)*s;
2538 weight -= seen[un_char] * 10;
2539 if (isALNUM_lazy_if(s+1,UTF)) {
2541 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2542 len = (int)strlen(tmpbuf);
2543 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2548 else if (*s == '$' && s[1] &&
2549 strchr("[#!%*<>()-=",s[1])) {
2550 if (/*{*/ strchr("])} =",s[2]))
2559 if (strchr("wds]",s[1]))
2561 else if (seen[(U8)'\''] || seen[(U8)'"'])
2563 else if (strchr("rnftbxcav",s[1]))
2565 else if (isDIGIT(s[1])) {
2567 while (s[1] && isDIGIT(s[1]))
2577 if (strchr("aA01! ",last_un_char))
2579 if (strchr("zZ79~",s[1]))
2581 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2582 weight -= 5; /* cope with negative subscript */
2585 if (!isALNUM(last_un_char)
2586 && !(last_un_char == '$' || last_un_char == '@'
2587 || last_un_char == '&')
2588 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2593 if (keyword(tmpbuf, d - tmpbuf, 0))
2596 if (un_char == last_un_char + 1)
2598 weight -= seen[un_char];
2603 if (weight >= 0) /* probably a character class */
2613 * Does all the checking to disambiguate
2615 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2616 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2618 * First argument is the stuff after the first token, e.g. "bar".
2620 * Not a method if bar is a filehandle.
2621 * Not a method if foo is a subroutine prototyped to take a filehandle.
2622 * Not a method if it's really "Foo $bar"
2623 * Method if it's "foo $bar"
2624 * Not a method if it's really "print foo $bar"
2625 * Method if it's really "foo package::" (interpreted as package->foo)
2626 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2627 * Not a method if bar is a filehandle or package, but is quoted with
2632 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2635 char *s = start + (*start == '$');
2636 char tmpbuf[sizeof PL_tokenbuf];
2644 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2648 const char *proto = SvPVX_const(cv);
2659 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2660 /* start is the beginning of the possible filehandle/object,
2661 * and s is the end of it
2662 * tmpbuf is a copy of it
2665 if (*start == '$') {
2666 if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
2667 isUPPER(*PL_tokenbuf))
2670 len = start - SvPVX(PL_linestr);
2674 start = SvPVX(PL_linestr) + len;
2678 return *s == '(' ? FUNCMETH : METHOD;
2680 if (!keyword(tmpbuf, len, 0)) {
2681 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2685 soff = s - SvPVX(PL_linestr);
2689 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2690 if (indirgv && GvCVu(indirgv))
2692 /* filehandle or package name makes it a method */
2693 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
2695 soff = s - SvPVX(PL_linestr);
2698 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2699 return 0; /* no assumptions -- "=>" quotes bearword */
2701 start_force(PL_curforce);
2702 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2703 newSVpvn(tmpbuf,len));
2704 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2706 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2711 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2713 return *s == '(' ? FUNCMETH : METHOD;
2721 * Return a string of Perl code to load the debugger. If PERL5DB
2722 * is set, it will return the contents of that, otherwise a
2723 * compile-time require of perl5db.pl.
2731 const char * const pdb = PerlEnv_getenv("PERL5DB");
2735 SETERRNO(0,SS_NORMAL);
2736 return "BEGIN { require 'perl5db.pl' }";
2742 /* Encoded script support. filter_add() effectively inserts a
2743 * 'pre-processing' function into the current source input stream.
2744 * Note that the filter function only applies to the current source file
2745 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2747 * The datasv parameter (which may be NULL) can be used to pass
2748 * private data to this instance of the filter. The filter function
2749 * can recover the SV using the FILTER_DATA macro and use it to
2750 * store private buffers and state information.
2752 * The supplied datasv parameter is upgraded to a PVIO type
2753 * and the IoDIRP/IoANY field is used to store the function pointer,
2754 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2755 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2756 * private use must be set using malloc'd pointers.
2760 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2766 if (!PL_rsfp_filters)
2767 PL_rsfp_filters = newAV();
2770 SvUPGRADE(datasv, SVt_PVIO);
2771 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2772 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2773 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2774 FPTR2DPTR(void *, IoANY(datasv)),
2775 SvPV_nolen(datasv)));
2776 av_unshift(PL_rsfp_filters, 1);
2777 av_store(PL_rsfp_filters, 0, datasv) ;
2782 /* Delete most recently added instance of this filter function. */
2784 Perl_filter_del(pTHX_ filter_t funcp)
2790 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2791 FPTR2DPTR(void*, funcp)));
2793 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2795 /* if filter is on top of stack (usual case) just pop it off */
2796 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2797 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2798 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2799 IoANY(datasv) = (void *)NULL;
2800 sv_free(av_pop(PL_rsfp_filters));
2804 /* we need to search for the correct entry and clear it */
2805 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2809 /* Invoke the idxth filter function for the current rsfp. */
2810 /* maxlen 0 = read one text line */
2812 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2817 /* This API is bad. It should have been using unsigned int for maxlen.
2818 Not sure if we want to change the API, but if not we should sanity
2819 check the value here. */
2820 const unsigned int correct_length
2829 if (!PL_rsfp_filters)
2831 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2832 /* Provide a default input filter to make life easy. */
2833 /* Note that we append to the line. This is handy. */
2834 DEBUG_P(PerlIO_printf(Perl_debug_log,
2835 "filter_read %d: from rsfp\n", idx));
2836 if (correct_length) {
2839 const int old_len = SvCUR(buf_sv);
2841 /* ensure buf_sv is large enough */
2842 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2843 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2844 correct_length)) <= 0) {
2845 if (PerlIO_error(PL_rsfp))
2846 return -1; /* error */
2848 return 0 ; /* end of file */
2850 SvCUR_set(buf_sv, old_len + len) ;
2853 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2854 if (PerlIO_error(PL_rsfp))
2855 return -1; /* error */
2857 return 0 ; /* end of file */
2860 return SvCUR(buf_sv);
2862 /* Skip this filter slot if filter has been deleted */
2863 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2864 DEBUG_P(PerlIO_printf(Perl_debug_log,
2865 "filter_read %d: skipped (filter deleted)\n",
2867 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2869 /* Get function pointer hidden within datasv */
2870 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2871 DEBUG_P(PerlIO_printf(Perl_debug_log,
2872 "filter_read %d: via function %p (%s)\n",
2873 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2874 /* Call function. The function is expected to */
2875 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2876 /* Return: <0:error, =0:eof, >0:not eof */
2877 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2881 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2884 #ifdef PERL_CR_FILTER
2885 if (!PL_rsfp_filters) {
2886 filter_add(S_cr_textfilter,NULL);
2889 if (PL_rsfp_filters) {
2891 SvCUR_set(sv, 0); /* start with empty line */
2892 if (FILTER_READ(0, sv, 0) > 0)
2893 return ( SvPVX(sv) ) ;
2898 return (sv_gets(sv, fp, append));
2902 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2907 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2911 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2912 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2914 return GvHV(gv); /* Foo:: */
2917 /* use constant CLASS => 'MyClass' */
2918 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2919 if (gv && GvCV(gv)) {
2920 SV * const sv = cv_const_sv(GvCV(gv));
2922 pkgname = SvPV_nolen_const(sv);
2925 return gv_stashpv(pkgname, 0);
2929 * S_readpipe_override
2930 * Check whether readpipe() is overriden, and generates the appropriate
2931 * optree, provided sublex_start() is called afterwards.
2934 S_readpipe_override(pTHX)
2937 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
2938 yylval.ival = OP_BACKTICK;
2940 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
2942 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
2943 && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
2944 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
2946 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
2947 append_elem(OP_LIST,
2948 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
2949 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
2959 * The intent of this yylex wrapper is to minimize the changes to the
2960 * tokener when we aren't interested in collecting madprops. It remains
2961 * to be seen how successful this strategy will be...
2968 char *s = PL_bufptr;
2970 /* make sure PL_thiswhite is initialized */
2974 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2975 if (PL_pending_ident)
2976 return S_pending_ident(aTHX);
2978 /* previous token ate up our whitespace? */
2979 if (!PL_lasttoke && PL_nextwhite) {
2980 PL_thiswhite = PL_nextwhite;
2984 /* isolate the token, and figure out where it is without whitespace */
2985 PL_realtokenstart = -1;
2989 assert(PL_curforce < 0);
2991 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2992 if (!PL_thistoken) {
2993 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2994 PL_thistoken = newSVpvs("");
2996 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2997 PL_thistoken = newSVpvn(tstart, s - tstart);
3000 if (PL_thismad) /* install head */
3001 CURMAD('X', PL_thistoken);
3004 /* last whitespace of a sublex? */
3005 if (optype == ')' && PL_endwhite) {
3006 CURMAD('X', PL_endwhite);
3011 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
3012 if (!PL_thiswhite && !PL_endwhite && !optype) {
3013 sv_free(PL_thistoken);
3018 /* put off final whitespace till peg */
3019 if (optype == ';' && !PL_rsfp) {
3020 PL_nextwhite = PL_thiswhite;
3023 else if (PL_thisopen) {
3024 CURMAD('q', PL_thisopen);
3026 sv_free(PL_thistoken);
3030 /* Store actual token text as madprop X */
3031 CURMAD('X', PL_thistoken);
3035 /* add preceding whitespace as madprop _ */
3036 CURMAD('_', PL_thiswhite);
3040 /* add quoted material as madprop = */
3041 CURMAD('=', PL_thisstuff);
3045 /* add terminating quote as madprop Q */
3046 CURMAD('Q', PL_thisclose);
3050 /* special processing based on optype */
3054 /* opval doesn't need a TOKEN since it can already store mp */
3065 append_madprops(PL_thismad, yylval.opval, 0);
3073 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3082 /* remember any fake bracket that lexer is about to discard */
3083 if (PL_lex_brackets == 1 &&
3084 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3087 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3090 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3091 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3094 break; /* don't bother looking for trailing comment */
3103 /* attach a trailing comment to its statement instead of next token */
3107 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3109 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3111 if (*s == '\n' || *s == '#') {
3112 while (s < PL_bufend && *s != '\n')
3116 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3117 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3134 /* Create new token struct. Note: opvals return early above. */
3135 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
3142 S_tokenize_use(pTHX_ int is_use, char *s) {
3144 if (PL_expect != XSTATE)
3145 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3146 is_use ? "use" : "no"));
3148 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3149 s = force_version(s, TRUE);
3150 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3151 start_force(PL_curforce);
3152 NEXTVAL_NEXTTOKE.opval = NULL;
3155 else if (*s == 'v') {
3156 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3157 s = force_version(s, FALSE);
3161 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3162 s = force_version(s, FALSE);
3164 yylval.ival = is_use;
3168 static const char* const exp_name[] =
3169 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3170 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3177 Works out what to call the token just pulled out of the input
3178 stream. The yacc parser takes care of taking the ops we return and
3179 stitching them into a tree.
3185 if read an identifier
3186 if we're in a my declaration
3187 croak if they tried to say my($foo::bar)
3188 build the ops for a my() declaration
3189 if it's an access to a my() variable
3190 are we in a sort block?
3191 croak if my($a); $a <=> $b
3192 build ops for access to a my() variable
3193 if in a dq string, and they've said @foo and we can't find @foo
3195 build ops for a bareword
3196 if we already built the token before, use it.
3201 #pragma segment Perl_yylex
3207 register char *s = PL_bufptr;
3212 /* orig_keyword, gvp, and gv are initialized here because
3213 * jump to the label just_a_word_zero can bypass their
3214 * initialization later. */
3215 I32 orig_keyword = 0;
3220 SV* tmp = newSVpvs("");
3221 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3222 (IV)CopLINE(PL_curcop),
3223 lex_state_names[PL_lex_state],
3224 exp_name[PL_expect],
3225 pv_display(tmp, s, strlen(s), 0, 60));
3228 /* check if there's an identifier for us to look at */
3229 if (PL_pending_ident)
3230 return REPORT(S_pending_ident(aTHX));
3232 /* no identifier pending identification */
3234 switch (PL_lex_state) {
3236 case LEX_NORMAL: /* Some compilers will produce faster */
3237 case LEX_INTERPNORMAL: /* code if we comment these out. */
3241 /* when we've already built the next token, just pull it out of the queue */
3245 yylval = PL_nexttoke[PL_lasttoke].next_val;
3247 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3248 PL_nexttoke[PL_lasttoke].next_mad = 0;
3249 if (PL_thismad && PL_thismad->mad_key == '_') {
3250 PL_thiswhite = (SV*)PL_thismad->mad_val;
3251 PL_thismad->mad_val = 0;
3252 mad_free(PL_thismad);
3257 PL_lex_state = PL_lex_defer;
3258 PL_expect = PL_lex_expect;
3259 PL_lex_defer = LEX_NORMAL;
3260 if (!PL_nexttoke[PL_lasttoke].next_type)
3265 yylval = PL_nextval[PL_nexttoke];
3267 PL_lex_state = PL_lex_defer;
3268 PL_expect = PL_lex_expect;
3269 PL_lex_defer = LEX_NORMAL;
3273 /* FIXME - can these be merged? */
3274 return(PL_nexttoke[PL_lasttoke].next_type);
3276 return REPORT(PL_nexttype[PL_nexttoke]);
3279 /* interpolated case modifiers like \L \U, including \Q and \E.
3280 when we get here, PL_bufptr is at the \
3282 case LEX_INTERPCASEMOD:
3284 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3285 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3287 /* handle \E or end of string */
3288 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3290 if (PL_lex_casemods) {
3291 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3292 PL_lex_casestack[PL_lex_casemods] = '\0';
3294 if (PL_bufptr != PL_bufend
3295 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3297 PL_lex_state = LEX_INTERPCONCAT;
3300 PL_thistoken = newSVpvs("\\E");
3306 while (PL_bufptr != PL_bufend &&
3307 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3309 PL_thiswhite = newSVpvs("");
3310 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3314 if (PL_bufptr != PL_bufend)
3317 PL_lex_state = LEX_INTERPCONCAT;
3321 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3322 "### Saw case modifier\n"); });
3324 if (s[1] == '\\' && s[2] == 'E') {
3327 PL_thiswhite = newSVpvs("");
3328 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3331 PL_lex_state = LEX_INTERPCONCAT;
3336 if (!PL_madskills) /* when just compiling don't need correct */
3337 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3338 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3339 if ((*s == 'L' || *s == 'U') &&
3340 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3341 PL_lex_casestack[--PL_lex_casemods] = '\0';
3344 if (PL_lex_casemods > 10)
3345 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3346 PL_lex_casestack[PL_lex_casemods++] = *s;
3347 PL_lex_casestack[PL_lex_casemods] = '\0';
3348 PL_lex_state = LEX_INTERPCONCAT;
3349 start_force(PL_curforce);
3350 NEXTVAL_NEXTTOKE.ival = 0;
3352 start_force(PL_curforce);
3354 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3356 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3358 NEXTVAL_NEXTTOKE.ival = OP_LC;
3360 NEXTVAL_NEXTTOKE.ival = OP_UC;
3362 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3364 Perl_croak(aTHX_ "panic: yylex");
3366 SV* const tmpsv = newSVpvs("");
3367 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3373 if (PL_lex_starts) {
3379 sv_free(PL_thistoken);
3380 PL_thistoken = newSVpvs("");
3383 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3384 if (PL_lex_casemods == 1 && PL_lex_inpat)
3393 case LEX_INTERPPUSH:
3394 return REPORT(sublex_push());
3396 case LEX_INTERPSTART:
3397 if (PL_bufptr == PL_bufend)
3398 return REPORT(sublex_done());
3399 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3400 "### Interpolated variable\n"); });
3402 PL_lex_dojoin = (*PL_bufptr == '@');
3403 PL_lex_state = LEX_INTERPNORMAL;
3404 if (PL_lex_dojoin) {
3405 start_force(PL_curforce);
3406 NEXTVAL_NEXTTOKE.ival = 0;
3408 start_force(PL_curforce);
3409 force_ident("\"", '$');
3410 start_force(PL_curforce);
3411 NEXTVAL_NEXTTOKE.ival = 0;
3413 start_force(PL_curforce);
3414 NEXTVAL_NEXTTOKE.ival = 0;
3416 start_force(PL_curforce);
3417 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3420 if (PL_lex_starts++) {
3425 sv_free(PL_thistoken);
3426 PL_thistoken = newSVpvs("");
3429 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3430 if (!PL_lex_casemods && PL_lex_inpat)
3437 case LEX_INTERPENDMAYBE:
3438 if (intuit_more(PL_bufptr)) {
3439 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3445 if (PL_lex_dojoin) {
3446 PL_lex_dojoin = FALSE;
3447 PL_lex_state = LEX_INTERPCONCAT;
3451 sv_free(PL_thistoken);
3452 PL_thistoken = newSVpvs("");
3457 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3458 && SvEVALED(PL_lex_repl))
3460 if (PL_bufptr != PL_bufend)
3461 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3465 case LEX_INTERPCONCAT:
3467 if (PL_lex_brackets)
3468 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3470 if (PL_bufptr == PL_bufend)
3471 return REPORT(sublex_done());
3473 if (SvIVX(PL_linestr) == '\'') {
3474 SV *sv = newSVsv(PL_linestr);
3477 else if ( PL_hints & HINT_NEW_RE )
3478 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3479 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3483 s = scan_const(PL_bufptr);
3485 PL_lex_state = LEX_INTERPCASEMOD;
3487 PL_lex_state = LEX_INTERPSTART;
3490 if (s != PL_bufptr) {
3491 start_force(PL_curforce);
3493 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3495 NEXTVAL_NEXTTOKE = yylval;
3498 if (PL_lex_starts++) {
3502 sv_free(PL_thistoken);
3503 PL_thistoken = newSVpvs("");
3506 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3507 if (!PL_lex_casemods && PL_lex_inpat)
3520 PL_lex_state = LEX_NORMAL;
3521 s = scan_formline(PL_bufptr);
3522 if (!PL_lex_formbrack)
3528 PL_oldoldbufptr = PL_oldbufptr;
3534 sv_free(PL_thistoken);
3537 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3541 if (isIDFIRST_lazy_if(s,UTF))
3543 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3546 goto fake_eof; /* emulate EOF on ^D or ^Z */
3555 if (PL_lex_brackets) {
3556 yyerror((const char *)
3558 ? "Format not terminated"
3559 : "Missing right curly or square bracket"));
3561 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3562 "### Tokener got EOF\n");
3566 if (s++ < PL_bufend)
3567 goto retry; /* ignore stray nulls */
3570 if (!PL_in_eval && !PL_preambled) {
3571 PL_preambled = TRUE;
3576 sv_setpv(PL_linestr,incl_perldb());
3577 if (SvCUR(PL_linestr))
3578 sv_catpvs(PL_linestr,";");
3580 while(AvFILLp(PL_preambleav) >= 0) {
3581 SV *tmpsv = av_shift(PL_preambleav);
3582 sv_catsv(PL_linestr, tmpsv);
3583 sv_catpvs(PL_linestr, ";");
3586 sv_free((SV*)PL_preambleav);
3587 PL_preambleav = NULL;
3589 if (PL_minus_n || PL_minus_p) {
3590 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3592 sv_catpvs(PL_linestr,"chomp;");
3595 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3596 || *PL_splitstr == '"')
3597 && strchr(PL_splitstr + 1, *PL_splitstr))
3598 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3600 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3601 bytes can be used as quoting characters. :-) */
3602 const char *splits = PL_splitstr;
3603 sv_catpvs(PL_linestr, "our @F=split(q\0");
3606 if (*splits == '\\')
3607 sv_catpvn(PL_linestr, splits, 1);
3608 sv_catpvn(PL_linestr, splits, 1);
3609 } while (*splits++);
3610 /* This loop will embed the trailing NUL of
3611 PL_linestr as the last thing it does before
3613 sv_catpvs(PL_linestr, ");");
3617 sv_catpvs(PL_linestr,"our @F=split(' ');");
3621 sv_catpvs(PL_linestr,"use feature ':5.10';");
3622 sv_catpvs(PL_linestr, "\n");
3623 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3624 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3625 PL_last_lop = PL_last_uni = NULL;
3626 if (PERLDB_LINE && PL_curstash != PL_debstash)
3627 update_debugger_info(PL_linestr, NULL, 0);
3631 bof = PL_rsfp ? TRUE : FALSE;
3632 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3635 PL_realtokenstart = -1;
3638 if (PL_preprocess && !PL_in_eval)
3639 (void)PerlProc_pclose(PL_rsfp);
3640 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3641 PerlIO_clearerr(PL_rsfp);
3643 (void)PerlIO_close(PL_rsfp);
3645 PL_doextract = FALSE;
3647 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3652 sv_setpv(PL_linestr,
3655 ? ";}continue{print;}" : ";}"));
3656 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3657 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3658 PL_last_lop = PL_last_uni = NULL;
3659 PL_minus_n = PL_minus_p = 0;
3662 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3663 PL_last_lop = PL_last_uni = NULL;
3664 sv_setpvn(PL_linestr,"",0);
3665 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3667 /* If it looks like the start of a BOM or raw UTF-16,
3668 * check if it in fact is. */
3674 #ifdef PERLIO_IS_STDIO
3675 # ifdef __GNU_LIBRARY__
3676 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3677 # define FTELL_FOR_PIPE_IS_BROKEN
3681 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3682 # define FTELL_FOR_PIPE_IS_BROKEN
3687 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3688 /* This loses the possibility to detect the bof
3689 * situation on perl -P when the libc5 is being used.
3690 * Workaround? Maybe attach some extra state to PL_rsfp?
3693 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3695 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3698 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3699 s = swallow_bom((U8*)s);
3703 /* Incest with pod. */
3706 sv_catsv(PL_thiswhite, PL_linestr);
3708 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
3709 sv_setpvn(PL_linestr, "", 0);
3710 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3711 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3712 PL_last_lop = PL_last_uni = NULL;
3713 PL_doextract = FALSE;
3717 } while (PL_doextract);
3718 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3719 if (PERLDB_LINE && PL_curstash != PL_debstash)
3720 update_debugger_info(PL_linestr, NULL, 0);
3721 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3722 PL_last_lop = PL_last_uni = NULL;
3723 if (CopLINE(PL_curcop) == 1) {
3724 while (s < PL_bufend && isSPACE(*s))
3726 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3730 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3734 if (*s == '#' && *(s+1) == '!')
3736 #ifdef ALTERNATE_SHEBANG
3738 static char const as[] = ALTERNATE_SHEBANG;
3739 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3740 d = s + (sizeof(as) - 1);
3742 #endif /* ALTERNATE_SHEBANG */
3751 while (*d && !isSPACE(*d))
3755 #ifdef ARG_ZERO_IS_SCRIPT
3756 if (ipathend > ipath) {
3758 * HP-UX (at least) sets argv[0] to the script name,
3759 * which makes $^X incorrect. And Digital UNIX and Linux,
3760 * at least, set argv[0] to the basename of the Perl
3761 * interpreter. So, having found "#!", we'll set it right.
3763 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3765 assert(SvPOK(x) || SvGMAGICAL(x));
3766 if (sv_eq(x, CopFILESV(PL_curcop))) {
3767 sv_setpvn(x, ipath, ipathend - ipath);
3773 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3774 const char * const lstart = SvPV_const(x,llen);
3776 bstart += blen - llen;
3777 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3778 sv_setpvn(x, ipath, ipathend - ipath);
3783 TAINT_NOT; /* $^X is always tainted, but that's OK */
3785 #endif /* ARG_ZERO_IS_SCRIPT */
3790 d = instr(s,"perl -");
3792 d = instr(s,"perl");
3794 /* avoid getting into infinite loops when shebang
3795 * line contains "Perl" rather than "perl" */
3797 for (d = ipathend-4; d >= ipath; --d) {
3798 if ((*d == 'p' || *d == 'P')
3799 && !ibcmp(d, "perl", 4))
3809 #ifdef ALTERNATE_SHEBANG
3811 * If the ALTERNATE_SHEBANG on this system starts with a
3812 * character that can be part of a Perl expression, then if
3813 * we see it but not "perl", we're probably looking at the
3814 * start of Perl code, not a request to hand off to some
3815 * other interpreter. Similarly, if "perl" is there, but
3816 * not in the first 'word' of the line, we assume the line
3817 * contains the start of the Perl program.
3819 if (d && *s != '#') {
3820 const char *c = ipath;
3821 while (*c && !strchr("; \t\r\n\f\v#", *c))
3824 d = NULL; /* "perl" not in first word; ignore */
3826 *s = '#'; /* Don't try to parse shebang line */
3828 #endif /* ALTERNATE_SHEBANG */
3829 #ifndef MACOS_TRADITIONAL
3834 !instr(s,"indir") &&
3835 instr(PL_origargv[0],"perl"))
3842 while (s < PL_bufend && isSPACE(*s))
3844 if (s < PL_bufend) {
3845 Newxz(newargv,PL_origargc+3,char*);
3847 while (s < PL_bufend && !isSPACE(*s))
3850 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3853 newargv = PL_origargv;
3856 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3858 Perl_croak(aTHX_ "Can't exec %s", ipath);
3862 while (*d && !isSPACE(*d))
3864 while (SPACE_OR_TAB(*d))
3868 const bool switches_done = PL_doswitches;
3869 const U32 oldpdb = PL_perldb;
3870 const bool oldn = PL_minus_n;
3871 const bool oldp = PL_minus_p;
3874 if (*d == 'M' || *d == 'm' || *d == 'C') {
3875 const char * const m = d;
3876 while (*d && !isSPACE(*d))
3878 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3881 d = moreswitches(d);
3883 if (PL_doswitches && !switches_done) {
3884 int argc = PL_origargc;
3885 char **argv = PL_origargv;
3888 } while (argc && argv[0][0] == '-' && argv[0][1]);
3889 init_argv_symbols(argc,argv);
3891 if ((PERLDB_LINE && !oldpdb) ||
3892 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3893 /* if we have already added "LINE: while (<>) {",
3894 we must not do it again */
3896 sv_setpvn(PL_linestr, "", 0);
3897 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3898 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3899 PL_last_lop = PL_last_uni = NULL;
3900 PL_preambled = FALSE;
3902 (void)gv_fetchfile(PL_origfilename);
3909 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3911 PL_lex_state = LEX_FORMLINE;
3916 #ifdef PERL_STRICT_CR
3917 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3919 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3921 case ' ': case '\t': case '\f': case 013:
3922 #ifdef MACOS_TRADITIONAL
3926 PL_realtokenstart = -1;
3928 PL_thiswhite = newSVpvs("");
3929 sv_catpvn(PL_thiswhite, s, 1);
3936 PL_realtokenstart = -1;
3940 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3941 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3942 /* handle eval qq[#line 1 "foo"\n ...] */
3943 CopLINE_dec(PL_curcop);
3946 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3948 if (!PL_in_eval || PL_rsfp)
3953 while (d < PL_bufend && *d != '\n')
3957 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3958 Perl_croak(aTHX_ "panic: input overflow");
3961 PL_thiswhite = newSVpvn(s, d - s);
3966 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3968 PL_lex_state = LEX_FORMLINE;
3974 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3975 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3978 TOKEN(PEG); /* make sure any #! line is accessible */
3983 /* if (PL_madskills && PL_lex_formbrack) { */
3985 while (d < PL_bufend && *d != '\n')
3989 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3990 Perl_croak(aTHX_ "panic: input overflow");
3991 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3993 PL_thiswhite = newSVpvs("");
3994 if (CopLINE(PL_curcop) == 1) {
3995 sv_setpvn(PL_thiswhite, "", 0);
3998 sv_catpvn(PL_thiswhite, s, d - s);
4012 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
4020 while (s < PL_bufend && SPACE_OR_TAB(*s))
4023 if (strnEQ(s,"=>",2)) {
4024 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
4025 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
4026 OPERATOR('-'); /* unary minus */
4028 PL_last_uni = PL_oldbufptr;
4030 case 'r': ftst = OP_FTEREAD; break;
4031 case 'w': ftst = OP_FTEWRITE; break;
4032 case 'x': ftst = OP_FTEEXEC; break;
4033 case 'o': ftst = OP_FTEOWNED; break;
4034 case 'R': ftst = OP_FTRREAD; break;
4035 case 'W': ftst = OP_FTRWRITE; break;
4036 case 'X': ftst = OP_FTREXEC; break;
4037 case 'O': ftst = OP_FTROWNED; break;
4038 case 'e': ftst = OP_FTIS; break;
4039 case 'z': ftst = OP_FTZERO; break;
4040 case 's': ftst = OP_FTSIZE; break;
4041 case 'f': ftst = OP_FTFILE; break;
4042 case 'd': ftst = OP_FTDIR; break;
4043 case 'l': ftst = OP_FTLINK; break;
4044 case 'p': ftst = OP_FTPIPE; break;
4045 case 'S': ftst = OP_FTSOCK; break;
4046 case 'u': ftst = OP_FTSUID; break;
4047 case 'g': ftst = OP_FTSGID; break;
4048 case 'k': ftst = OP_FTSVTX; break;
4049 case 'b': ftst = OP_FTBLK; break;
4050 case 'c': ftst = OP_FTCHR; break;
4051 case 't': ftst = OP_FTTTY; break;
4052 case 'T': ftst = OP_FTTEXT; break;
4053 case 'B': ftst = OP_FTBINARY; break;
4054 case 'M': case 'A': case 'C':
4055 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
4057 case 'M': ftst = OP_FTMTIME; break;
4058 case 'A': ftst = OP_FTATIME; break;
4059 case 'C': ftst = OP_FTCTIME; break;
4067 PL_last_lop_op = (OPCODE)ftst;
4068 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4069 "### Saw file test %c\n", (int)tmp);
4074 /* Assume it was a minus followed by a one-letter named
4075 * subroutine call (or a -bareword), then. */
4076 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4077 "### '-%c' looked like a file test but was not\n",
4084 const char tmp = *s++;
4087 if (PL_expect == XOPERATOR)
4092 else if (*s == '>') {
4095 if (isIDFIRST_lazy_if(s,UTF)) {
4096 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4104 if (PL_expect == XOPERATOR)
4107 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4109 OPERATOR('-'); /* unary minus */
4115 const char tmp = *s++;
4118 if (PL_expect == XOPERATOR)
4123 if (PL_expect == XOPERATOR)
4126 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4133 if (PL_expect != XOPERATOR) {
4134 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4135 PL_expect = XOPERATOR;
4136 force_ident(PL_tokenbuf, '*');
4149 if (PL_expect == XOPERATOR) {
4153 PL_tokenbuf[0] = '%';
4154 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4155 sizeof PL_tokenbuf - 1, FALSE);
4156 if (!PL_tokenbuf[1]) {
4159 PL_pending_ident = '%';
4170 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
4177 const char tmp = *s++;
4183 goto just_a_word_zero_gv;
4186 switch (PL_expect) {
4192 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4194 PL_bufptr = s; /* update in case we back off */
4200 PL_expect = XTERMBLOCK;
4203 stuffstart = s - SvPVX(PL_linestr) - 1;
4207 while (isIDFIRST_lazy_if(s,UTF)) {
4210 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4211 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4212 if (tmp < 0) tmp = -tmp;
4227 sv = newSVpvn(s, len);
4229 d = scan_str(d,TRUE,TRUE);
4231 /* MUST advance bufptr here to avoid bogus
4232 "at end of line" context messages from yyerror().
4234 PL_bufptr = s + len;
4235 yyerror("Unterminated attribute parameter in attribute list");
4239 return REPORT(0); /* EOF indicator */
4243 sv_catsv(sv, PL_lex_stuff);
4244 attrs = append_elem(OP_LIST, attrs,
4245 newSVOP(OP_CONST, 0, sv));
4246 SvREFCNT_dec(PL_lex_stuff);
4247 PL_lex_stuff = NULL;
4250 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4252 if (PL_in_my == KEY_our) {
4254 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4256 /* skip to avoid loading attributes.pm */
4258 deprecate(":unique");
4261 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4264 /* NOTE: any CV attrs applied here need to be part of
4265 the CVf_BUILTIN_ATTRS define in cv.h! */
4266 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4268 CvLVALUE_on(PL_compcv);
4270 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4272 CvLOCKED_on(PL_compcv);
4274 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4276 CvMETHOD_on(PL_compcv);
4278 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4280 CvASSERTION_on(PL_compcv);
4282 /* After we've set the flags, it could be argued that
4283 we don't need to do the attributes.pm-based setting
4284 process, and shouldn't bother appending recognized
4285 flags. To experiment with that, uncomment the
4286 following "else". (Note that's already been
4287 uncommented. That keeps the above-applied built-in
4288 attributes from being intercepted (and possibly
4289 rejected) by a package's attribute routines, but is
4290 justified by the performance win for the common case
4291 of applying only built-in attributes.) */
4293 attrs = append_elem(OP_LIST, attrs,
4294 newSVOP(OP_CONST, 0,
4298 if (*s == ':' && s[1] != ':')
4301 break; /* require real whitespace or :'s */
4302 /* XXX losing whitespace on sequential attributes here */
4306 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4307 if (*s != ';' && *s != '}' && *s != tmp
4308 && (tmp != '=' || *s != ')')) {
4309 const char q = ((*s == '\'') ? '"' : '\'');
4310 /* If here for an expression, and parsed no attrs, back
4312 if (tmp == '=' && !attrs) {
4316 /* MUST advance bufptr here to avoid bogus "at end of line"
4317 context messages from yyerror().
4320 yyerror( (const char *)
4322 ? Perl_form(aTHX_ "Invalid separator character "
4323 "%c%c%c in attribute list", q, *s, q)
4324 : "Unterminated attribute list" ) );
4332 start_force(PL_curforce);
4333 NEXTVAL_NEXTTOKE.opval = attrs;
4334 CURMAD('_', PL_nextwhite);
4339 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4340 (s - SvPVX(PL_linestr)) - stuffstart);
4348 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4349 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4357 const char tmp = *s++;
4362 const char tmp = *s++;
4370 if (PL_lex_brackets <= 0)
4371 yyerror("Unmatched right square bracket");
4374 if (PL_lex_state == LEX_INTERPNORMAL) {
4375 if (PL_lex_brackets == 0) {
4376 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4377 PL_lex_state = LEX_INTERPEND;
4384 if (PL_lex_brackets > 100) {
4385 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4387 switch (PL_expect) {
4389 if (PL_lex_formbrack) {
4393 if (PL_oldoldbufptr == PL_last_lop)
4394 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4396 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4397 OPERATOR(HASHBRACK);
4399 while (s < PL_bufend && SPACE_OR_TAB(*s))
4402 PL_tokenbuf[0] = '\0';
4403 if (d < PL_bufend && *d == '-') {
4404 PL_tokenbuf[0] = '-';
4406 while (d < PL_bufend && SPACE_OR_TAB(*d))
4409 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4410 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4412 while (d < PL_bufend && SPACE_OR_TAB(*d))
4415 const char minus = (PL_tokenbuf[0] == '-');
4416 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4424 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4429 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4434 if (PL_oldoldbufptr == PL_last_lop)
4435 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4437 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4440 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4442 /* This hack is to get the ${} in the message. */
4444 yyerror("syntax error");
4447 OPERATOR(HASHBRACK);
4449 /* This hack serves to disambiguate a pair of curlies
4450 * as being a block or an anon hash. Normally, expectation
4451 * determines that, but in cases where we're not in a
4452 * position to expect anything in particular (like inside
4453 * eval"") we have to resolve the ambiguity. This code
4454 * covers the case where the first term in the curlies is a
4455 * quoted string. Most other cases need to be explicitly
4456 * disambiguated by prepending a "+" before the opening
4457 * curly in order to force resolution as an anon hash.
4459 * XXX should probably propagate the outer expectation
4460 * into eval"" to rely less on this hack, but that could
4461 * potentially break current behavior of eval"".
4465 if (*s == '\'' || *s == '"' || *s == '`') {
4466 /* common case: get past first string, handling escapes */
4467 for (t++; t < PL_bufend && *t != *s;)
4468 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4472 else if (*s == 'q') {
4475 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4478 /* skip q//-like construct */
4480 char open, close, term;
4483 while (t < PL_bufend && isSPACE(*t))
4485 /* check for q => */
4486 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4487 OPERATOR(HASHBRACK);
4491 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4495 for (t++; t < PL_bufend; t++) {
4496 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4498 else if (*t == open)
4502 for (t++; t < PL_bufend; t++) {
4503 if (*t == '\\' && t+1 < PL_bufend)
4505 else if (*t == close && --brackets <= 0)
4507 else if (*t == open)
4514 /* skip plain q word */
4515 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4518 else if (isALNUM_lazy_if(t,UTF)) {
4520 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4523 while (t < PL_bufend && isSPACE(*t))
4525 /* if comma follows first term, call it an anon hash */
4526 /* XXX it could be a comma expression with loop modifiers */
4527 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4528 || (*t == '=' && t[1] == '>')))
4529 OPERATOR(HASHBRACK);
4530 if (PL_expect == XREF)
4533 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4539 yylval.ival = CopLINE(PL_curcop);
4540 if (isSPACE(*s) || *s == '#')
4541 PL_copline = NOLINE; /* invalidate current command line number */
4546 if (PL_lex_brackets <= 0)
4547 yyerror("Unmatched right curly bracket");
4549 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4550 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4551 PL_lex_formbrack = 0;
4552 if (PL_lex_state == LEX_INTERPNORMAL) {
4553 if (PL_lex_brackets == 0) {
4554 if (PL_expect & XFAKEBRACK) {
4555 PL_expect &= XENUMMASK;
4556 PL_lex_state = LEX_INTERPEND;
4561 PL_thiswhite = newSVpvs("");
4562 sv_catpvn(PL_thiswhite,"}",1);
4565 return yylex(); /* ignore fake brackets */
4567 if (*s == '-' && s[1] == '>')
4568 PL_lex_state = LEX_INTERPENDMAYBE;
4569 else if (*s != '[' && *s != '{')
4570 PL_lex_state = LEX_INTERPEND;
4573 if (PL_expect & XFAKEBRACK) {
4574 PL_expect &= XENUMMASK;
4576 return yylex(); /* ignore fake brackets */
4578 start_force(PL_curforce);
4580 curmad('X', newSVpvn(s-1,1));
4581 CURMAD('_', PL_thiswhite);
4586 PL_thistoken = newSVpvs("");
4594 if (PL_expect == XOPERATOR) {
4595 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4596 && isIDFIRST_lazy_if(s,UTF))
4598 CopLINE_dec(PL_curcop);
4599 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4600 CopLINE_inc(PL_curcop);
4605 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4607 PL_expect = XOPERATOR;
4608 force_ident(PL_tokenbuf, '&');
4612 yylval.ival = (OPpENTERSUB_AMPER<<8);
4624 const char tmp = *s++;
4631 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4632 && strchr("+-*/%.^&|<",tmp))
4633 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4634 "Reversed %c= operator",(int)tmp);
4636 if (PL_expect == XSTATE && isALPHA(tmp) &&
4637 (s == PL_linestart+1 || s[-2] == '\n') )
4639 if (PL_in_eval && !PL_rsfp) {
4644 if (strnEQ(s,"=cut",4)) {
4660 PL_thiswhite = newSVpvs("");
4661 sv_catpvn(PL_thiswhite, PL_linestart,
4662 PL_bufend - PL_linestart);
4666 PL_doextract = TRUE;
4670 if (PL_lex_brackets < PL_lex_formbrack) {
4672 #ifdef PERL_STRICT_CR
4673 while (SPACE_OR_TAB(*t))
4675 while (SPACE_OR_TAB(*t) || *t == '\r')
4678 if (*t == '\n' || *t == '#') {
4689 const char tmp = *s++;
4691 /* was this !=~ where !~ was meant?
4692 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4694 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4695 const char *t = s+1;
4697 while (t < PL_bufend && isSPACE(*t))
4700 if (*t == '/' || *t == '?' ||
4701 ((*t == 'm' || *t == 's' || *t == 'y')
4702 && !isALNUM(t[1])) ||
4703 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4704 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4705 "!=~ should be !~");
4715 if (PL_expect != XOPERATOR) {
4716 if (s[1] != '<' && !strchr(s,'>'))
4719 s = scan_heredoc(s);
4721 s = scan_inputsymbol(s);
4722 TERM(sublex_start());
4728 SHop(OP_LEFT_SHIFT);
4742 const char tmp = *s++;
4744 SHop(OP_RIGHT_SHIFT);
4745 else if (tmp == '=')
4754 if (PL_expect == XOPERATOR) {
4755 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4757 deprecate_old(commaless_variable_list);
4758 return REPORT(','); /* grandfather non-comma-format format */
4762 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4763 PL_tokenbuf[0] = '@';
4764 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4765 sizeof PL_tokenbuf - 1, FALSE);
4766 if (PL_expect == XOPERATOR)
4767 no_op("Array length", s);
4768 if (!PL_tokenbuf[1])
4770 PL_expect = XOPERATOR;
4771 PL_pending_ident = '#';
4775 PL_tokenbuf[0] = '$';
4776 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4777 sizeof PL_tokenbuf - 1, FALSE);
4778 if (PL_expect == XOPERATOR)
4780 if (!PL_tokenbuf[1]) {
4782 yyerror("Final $ should be \\$ or $name");
4786 /* This kludge not intended to be bulletproof. */
4787 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4788 yylval.opval = newSVOP(OP_CONST, 0,
4789 newSViv(CopARYBASE_get(&PL_compiling)));
4790 yylval.opval->op_private = OPpCONST_ARYBASE;
4796 const char tmp = *s;
4797 if (PL_lex_state == LEX_NORMAL)
4800 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4801 && intuit_more(s)) {
4803 PL_tokenbuf[0] = '@';
4804 if (ckWARN(WARN_SYNTAX)) {
4807 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4810 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4811 while (t < PL_bufend && *t != ']')
4813 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4814 "Multidimensional syntax %.*s not supported",
4815 (int)((t - PL_bufptr) + 1), PL_bufptr);
4819 else if (*s == '{') {
4821 PL_tokenbuf[0] = '%';
4822 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4823 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4825 char tmpbuf[sizeof PL_tokenbuf];
4828 } while (isSPACE(*t));
4829 if (isIDFIRST_lazy_if(t,UTF)) {
4831 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4835 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
4836 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4837 "You need to quote \"%s\"",
4844 PL_expect = XOPERATOR;
4845 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4846 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4847 if (!islop || PL_last_lop_op == OP_GREPSTART)
4848 PL_expect = XOPERATOR;
4849 else if (strchr("$@\"'`q", *s))
4850 PL_expect = XTERM; /* e.g. print $fh "foo" */
4851 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4852 PL_expect = XTERM; /* e.g. print $fh &sub */
4853 else if (isIDFIRST_lazy_if(s,UTF)) {
4854 char tmpbuf[sizeof PL_tokenbuf];
4856 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4857 if ((t2 = keyword(tmpbuf, len, 0))) {
4858 /* binary operators exclude handle interpretations */
4870 PL_expect = XTERM; /* e.g. print $fh length() */
4875 PL_expect = XTERM; /* e.g. print $fh subr() */
4878 else if (isDIGIT(*s))
4879 PL_expect = XTERM; /* e.g. print $fh 3 */
4880 else if (*s == '.' && isDIGIT(s[1]))
4881 PL_expect = XTERM; /* e.g. print $fh .3 */
4882 else if ((*s == '?' || *s == '-' || *s == '+')
4883 && !isSPACE(s[1]) && s[1] != '=')
4884 PL_expect = XTERM; /* e.g. print $fh -1 */
4885 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4887 PL_expect = XTERM; /* e.g. print $fh /.../
4888 XXX except DORDOR operator
4890 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4892 PL_expect = XTERM; /* print $fh <<"EOF" */
4895 PL_pending_ident = '$';
4899 if (PL_expect == XOPERATOR)
4901 PL_tokenbuf[0] = '@';
4902 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4903 if (!PL_tokenbuf[1]) {
4906 if (PL_lex_state == LEX_NORMAL)
4908 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4910 PL_tokenbuf[0] = '%';
4912 /* Warn about @ where they meant $. */
4913 if (*s == '[' || *s == '{') {
4914 if (ckWARN(WARN_SYNTAX)) {
4915 const char *t = s + 1;
4916 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4918 if (*t == '}' || *t == ']') {
4920 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4921 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4922 "Scalar value %.*s better written as $%.*s",
4923 (int)(t-PL_bufptr), PL_bufptr,
4924 (int)(t-PL_bufptr-1), PL_bufptr+1);
4929 PL_pending_ident = '@';
4932 case '/': /* may be division, defined-or, or pattern */
4933 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4937 case '?': /* may either be conditional or pattern */
4938 if(PL_expect == XOPERATOR) {
4946 /* A // operator. */
4956 /* Disable warning on "study /blah/" */
4957 if (PL_oldoldbufptr == PL_last_uni
4958 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4959 || memNE(PL_last_uni, "study", 5)
4960 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4963 s = scan_pat(s,OP_MATCH);
4964 TERM(sublex_start());
4968 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4969 #ifdef PERL_STRICT_CR
4972 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4974 && (s == PL_linestart || s[-1] == '\n') )
4976 PL_lex_formbrack = 0;
4980 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4986 yylval.ival = OPf_SPECIAL;
4992 if (PL_expect != XOPERATOR)
4997 case '0': case '1': case '2': case '3': case '4':
4998 case '5': case '6': case '7': case '8': case '9':
4999 s = scan_num(s, &yylval);
5000 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
5001 if (PL_expect == XOPERATOR)
5006 s = scan_str(s,!!PL_madskills,FALSE);
5007 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5008 if (PL_expect == XOPERATOR) {
5009 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5011 deprecate_old(commaless_variable_list);
5012 return REPORT(','); /* grandfather non-comma-format format */
5019 yylval.ival = OP_CONST;
5020 TERM(sublex_start());
5023 s = scan_str(s,!!PL_madskills,FALSE);
5024 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5025 if (PL_expect == XOPERATOR) {
5026 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5028 deprecate_old(commaless_variable_list);
5029 return REPORT(','); /* grandfather non-comma-format format */
5036 yylval.ival = OP_CONST;
5037 /* FIXME. I think that this can be const if char *d is replaced by
5038 more localised variables. */
5039 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
5040 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
5041 yylval.ival = OP_STRINGIFY;
5045 TERM(sublex_start());
5048 s = scan_str(s,!!PL_madskills,FALSE);
5049 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
5050 if (PL_expect == XOPERATOR)
5051 no_op("Backticks",s);
5054 readpipe_override();
5055 TERM(sublex_start());
5059 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
5060 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5062 if (PL_expect == XOPERATOR)
5063 no_op("Backslash",s);
5067 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
5068 char *start = s + 2;
5069 while (isDIGIT(*start) || *start == '_')
5071 if (*start == '.' && isDIGIT(start[1])) {
5072 s = scan_num(s, &yylval);
5075 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
5076 else if (!isALPHA(*start) && (PL_expect == XTERM
5077 || PL_expect == XREF || PL_expect == XSTATE
5078 || PL_expect == XTERMORDORDOR)) {
5079 /* XXX Use gv_fetchpvn rather than stomping on a const string */
5080 const char c = *start;
5083 gv = gv_fetchpv(s, 0, SVt_PVCV);
5086 s = scan_num(s, &yylval);
5093 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5135 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5137 /* Some keywords can be followed by any delimiter, including ':' */
5138 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5139 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5140 (PL_tokenbuf[0] == 'q' &&
5141 strchr("qwxr", PL_tokenbuf[1])))));
5143 /* x::* is just a word, unless x is "CORE" */
5144 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5148 while (d < PL_bufend && isSPACE(*d))
5149 d++; /* no comments skipped here, or s### is misparsed */
5151 /* Is this a label? */
5152 if (!tmp && PL_expect == XSTATE
5153 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5155 yylval.pval = CopLABEL_alloc(PL_tokenbuf);
5160 /* Check for keywords */
5161 tmp = keyword(PL_tokenbuf, len, 0);
5163 /* Is this a word before a => operator? */
5164 if (*d == '=' && d[1] == '>') {
5167 = (OP*)newSVOP(OP_CONST, 0,
5168 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5169 yylval.opval->op_private = OPpCONST_BARE;
5173 if (tmp < 0) { /* second-class keyword? */
5174 GV *ogv = NULL; /* override (winner) */
5175 GV *hgv = NULL; /* hidden (loser) */
5176 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5178 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5181 if (GvIMPORTED_CV(gv))
5183 else if (! CvMETHOD(cv))
5187 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5188 (gv = *gvp) && isGV_with_GP(gv) &&
5189 GvCVu(gv) && GvIMPORTED_CV(gv))
5196 tmp = 0; /* overridden by import or by GLOBAL */
5199 && -tmp==KEY_lock /* XXX generalizable kludge */
5201 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
5203 tmp = 0; /* any sub overrides "weak" keyword */
5205 else { /* no override */
5207 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5208 Perl_warner(aTHX_ packWARN(WARN_MISC),
5209 "dump() better written as CORE::dump()");
5213 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5214 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5215 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5216 "Ambiguous call resolved as CORE::%s(), %s",
5217 GvENAME(hgv), "qualify as such or use &");
5224 default: /* not a keyword */
5225 /* Trade off - by using this evil construction we can pull the
5226 variable gv into the block labelled keylookup. If not, then
5227 we have to give it function scope so that the goto from the
5228 earlier ':' case doesn't bypass the initialisation. */
5230 just_a_word_zero_gv:
5238 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5241 SV *nextPL_nextwhite = 0;
5245 /* Get the rest if it looks like a package qualifier */
5247 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5249 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5252 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5253 *s == '\'' ? "'" : "::");
5258 if (PL_expect == XOPERATOR) {
5259 if (PL_bufptr == PL_linestart) {
5260 CopLINE_dec(PL_curcop);
5261 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5262 CopLINE_inc(PL_curcop);
5265 no_op("Bareword",s);
5268 /* Look for a subroutine with this name in current package,
5269 unless name is "Foo::", in which case Foo is a bearword
5270 (and a package name). */
5272 if (len > 2 && !PL_madskills &&
5273 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5275 if (ckWARN(WARN_BAREWORD)
5276 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5277 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5278 "Bareword \"%s\" refers to nonexistent package",
5281 PL_tokenbuf[len] = '\0';
5287 /* Mustn't actually add anything to a symbol table.
5288 But also don't want to "initialise" any placeholder
5289 constants that might already be there into full
5290 blown PVGVs with attached PVCV. */
5291 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5292 GV_NOADD_NOINIT, SVt_PVCV);
5297 /* if we saw a global override before, get the right name */
5300 sv = newSVpvs("CORE::GLOBAL::");
5301 sv_catpv(sv,PL_tokenbuf);
5304 /* If len is 0, newSVpv does strlen(), which is correct.
5305 If len is non-zero, then it will be the true length,
5306 and so the scalar will be created correctly. */
5307 sv = newSVpv(PL_tokenbuf,len);
5310 if (PL_madskills && !PL_thistoken) {
5311 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5312 PL_thistoken = newSVpv(start,s - start);
5313 PL_realtokenstart = s - SvPVX(PL_linestr);
5317 /* Presume this is going to be a bareword of some sort. */
5320 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5321 yylval.opval->op_private = OPpCONST_BARE;
5322 /* UTF-8 package name? */
5323 if (UTF && !IN_BYTES &&
5324 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5327 /* And if "Foo::", then that's what it certainly is. */
5332 /* Do the explicit type check so that we don't need to force
5333 the initialisation of the symbol table to have a real GV.
5334 Beware - gv may not really be a PVGV, cv may not really be
5335 a PVCV, (because of the space optimisations that gv_init
5336 understands) But they're true if for this symbol there is
5337 respectively a typeglob and a subroutine.
5339 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5340 /* Real typeglob, so get the real subroutine: */
5342 /* A proxy for a subroutine in this package? */
5343 : SvOK(gv) ? (CV *) gv : NULL)
5346 /* See if it's the indirect object for a list operator. */
5348 if (PL_oldoldbufptr &&
5349 PL_oldoldbufptr < PL_bufptr &&
5350 (PL_oldoldbufptr == PL_last_lop
5351 || PL_oldoldbufptr == PL_last_uni) &&
5352 /* NO SKIPSPACE BEFORE HERE! */
5353 (PL_expect == XREF ||
5354 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5356 bool immediate_paren = *s == '(';
5358 /* (Now we can afford to cross potential line boundary.) */
5359 s = SKIPSPACE2(s,nextPL_nextwhite);
5361 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5364 /* Two barewords in a row may indicate method call. */
5366 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5367 (tmp = intuit_method(s, gv, cv)))
5370 /* If not a declared subroutine, it's an indirect object. */
5371 /* (But it's an indir obj regardless for sort.) */
5372 /* Also, if "_" follows a filetest operator, it's a bareword */
5375 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5377 (PL_last_lop_op != OP_MAPSTART &&
5378 PL_last_lop_op != OP_GREPSTART))))
5379 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5380 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5383 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5388 PL_expect = XOPERATOR;
5391 s = SKIPSPACE2(s,nextPL_nextwhite);
5392 PL_nextwhite = nextPL_nextwhite;
5397 /* Is this a word before a => operator? */
5398 if (*s == '=' && s[1] == '>' && !pkgname) {
5400 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5401 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5402 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5406 /* If followed by a paren, it's certainly a subroutine. */
5411 while (SPACE_OR_TAB(*d))
5413 if (*d == ')' && (sv = gv_const_sv(gv))) {
5417 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5418 sv_catpvn(PL_thistoken, par, s - par);
5420 sv_free(PL_nextwhite);
5431 PL_nextwhite = PL_thiswhite;
5434 start_force(PL_curforce);
5436 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5437 PL_expect = XOPERATOR;
5440 PL_nextwhite = nextPL_nextwhite;
5441 curmad('X', PL_thistoken);
5442 PL_thistoken = newSVpvs("");
5450 /* If followed by var or block, call it a method (unless sub) */
5452 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5453 PL_last_lop = PL_oldbufptr;
5454 PL_last_lop_op = OP_METHOD;
5458 /* If followed by a bareword, see if it looks like indir obj. */
5461 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5462 && (tmp = intuit_method(s, gv, cv)))
5465 /* Not a method, so call it a subroutine (if defined) */
5468 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5469 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5470 "Ambiguous use of -%s resolved as -&%s()",
5471 PL_tokenbuf, PL_tokenbuf);
5472 /* Check for a constant sub */
5473 if ((sv = gv_const_sv(gv)) && !PL_madskills) {
5475 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5476 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5477 yylval.opval->op_private = 0;
5481 /* Resolve to GV now. */
5482 if (SvTYPE(gv) != SVt_PVGV) {
5483 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5484 assert (SvTYPE(gv) == SVt_PVGV);
5485 /* cv must have been some sort of placeholder, so
5486 now needs replacing with a real code reference. */
5490 op_free(yylval.opval);
5491 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5492 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5493 PL_last_lop = PL_oldbufptr;
5494 PL_last_lop_op = OP_ENTERSUB;
5495 /* Is there a prototype? */
5503 const char *proto = SvPV_const((SV*)cv, protolen);
5506 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
5508 while (*proto == ';')
5510 if (*proto == '&' && *s == '{') {
5511 sv_setpv(PL_subname,
5514 "__ANON__" : "__ANON__::__ANON__"));
5521 PL_nextwhite = PL_thiswhite;
5524 start_force(PL_curforce);
5525 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5528 PL_nextwhite = nextPL_nextwhite;
5529 curmad('X', PL_thistoken);
5530 PL_thistoken = newSVpvs("");
5537 /* Guess harder when madskills require "best effort". */
5538 if (PL_madskills && (!gv || !GvCVu(gv))) {
5539 int probable_sub = 0;
5540 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5542 else if (isALPHA(*s)) {
5546 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5547 if (!keyword(tmpbuf, tmplen, 0))
5550 while (d < PL_bufend && isSPACE(*d))
5552 if (*d == '=' && d[1] == '>')
5557 gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
5558 op_free(yylval.opval);
5559 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5560 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5561 PL_last_lop = PL_oldbufptr;
5562 PL_last_lop_op = OP_ENTERSUB;
5563 PL_nextwhite = PL_thiswhite;
5565 start_force(PL_curforce);
5566 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5568 PL_nextwhite = nextPL_nextwhite;
5569 curmad('X', PL_thistoken);
5570 PL_thistoken = newSVpvs("");
5575 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5582 /* Call it a bare word */
5584 if (PL_hints & HINT_STRICT_SUBS)
5585 yylval.opval->op_private |= OPpCONST_STRICT;
5588 if (lastchar != '-') {
5589 if (ckWARN(WARN_RESERVED)) {
5593 if (!*d && !gv_stashpv(PL_tokenbuf, 0))
5594 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5601 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5602 && ckWARN_d(WARN_AMBIGUOUS)) {
5603 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5604 "Operator or semicolon missing before %c%s",
5605 lastchar, PL_tokenbuf);
5606 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5607 "Ambiguous use of %c resolved as operator %c",
5608 lastchar, lastchar);
5614 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5615 newSVpv(CopFILE(PL_curcop),0));
5619 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5620 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5623 case KEY___PACKAGE__:
5624 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5626 ? newSVhek(HvNAME_HEK(PL_curstash))
5633 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5634 const char *pname = "main";
5635 if (PL_tokenbuf[2] == 'D')
5636 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5637 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5641 GvIOp(gv) = newIO();
5642 IoIFP(GvIOp(gv)) = PL_rsfp;
5643 #if defined(HAS_FCNTL) && defined(F_SETFD)
5645 const int fd = PerlIO_fileno(PL_rsfp);
5646 fcntl(fd,F_SETFD,fd >= 3);
5649 /* Mark this internal pseudo-handle as clean */
5650 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5652 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5653 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5654 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5656 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5657 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5658 /* if the script was opened in binmode, we need to revert
5659 * it to text mode for compatibility; but only iff it has CRs
5660 * XXX this is a questionable hack at best. */
5661 if (PL_bufend-PL_bufptr > 2
5662 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5665 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5666 loc = PerlIO_tell(PL_rsfp);
5667 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5670 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5672 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5673 #endif /* NETWARE */
5674 #ifdef PERLIO_IS_STDIO /* really? */
5675 # if defined(__BORLANDC__)
5676 /* XXX see note in do_binmode() */
5677 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5681 PerlIO_seek(PL_rsfp, loc, 0);
5685 #ifdef PERLIO_LAYERS
5688 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5689 else if (PL_encoding) {
5696 XPUSHs(PL_encoding);
5698 call_method("name", G_SCALAR);
5702 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5703 Perl_form(aTHX_ ":encoding(%"SVf")",
5712 if (PL_realtokenstart >= 0) {
5713 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5715 PL_endwhite = newSVpvs("");
5716 sv_catsv(PL_endwhite, PL_thiswhite);
5718 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5719 PL_realtokenstart = -1;
5721 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5722 SvCUR(PL_endwhite))) != Nullch) ;
5737 if (PL_expect == XSTATE) {
5744 if (*s == ':' && s[1] == ':') {
5747 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5748 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5749 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5752 else if (tmp == KEY_require || tmp == KEY_do)
5753 /* that's a way to remember we saw "CORE::" */
5766 LOP(OP_ACCEPT,XTERM);
5772 LOP(OP_ATAN2,XTERM);
5778 LOP(OP_BINMODE,XTERM);
5781 LOP(OP_BLESS,XTERM);
5790 /* When 'use switch' is in effect, continue has a dual
5791 life as a control operator. */
5793 if (!FEATURE_IS_ENABLED("switch"))
5796 /* We have to disambiguate the two senses of
5797 "continue". If the next token is a '{' then
5798 treat it as the start of a continue block;
5799 otherwise treat it as a control operator.
5811 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5828 if (!PL_cryptseen) {
5829 PL_cryptseen = TRUE;
5833 LOP(OP_CRYPT,XTERM);
5836 LOP(OP_CHMOD,XTERM);
5839 LOP(OP_CHOWN,XTERM);
5842 LOP(OP_CONNECT,XTERM);
5861 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5862 if (orig_keyword == KEY_do) {
5871 PL_hints |= HINT_BLOCK_SCOPE;
5881 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5882 LOP(OP_DBMOPEN,XTERM);
5888 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5895 yylval.ival = CopLINE(PL_curcop);
5911 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5912 UNIBRACK(OP_ENTEREVAL);
5930 case KEY_endhostent:
5936 case KEY_endservent:
5939 case KEY_endprotoent:
5950 yylval.ival = CopLINE(PL_curcop);
5952 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5955 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5958 if ((PL_bufend - p) >= 3 &&
5959 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5961 else if ((PL_bufend - p) >= 4 &&
5962 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5965 if (isIDFIRST_lazy_if(p,UTF)) {
5966 p = scan_ident(p, PL_bufend,
5967 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5971 Perl_croak(aTHX_ "Missing $ on loop variable");
5973 s = SvPVX(PL_linestr) + soff;
5979 LOP(OP_FORMLINE,XTERM);
5985 LOP(OP_FCNTL,XTERM);
5991 LOP(OP_FLOCK,XTERM);
6000 LOP(OP_GREPSTART, XREF);
6003 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6018 case KEY_getpriority:
6019 LOP(OP_GETPRIORITY,XTERM);
6021 case KEY_getprotobyname:
6024 case KEY_getprotobynumber:
6025 LOP(OP_GPBYNUMBER,XTERM);
6027 case KEY_getprotoent:
6039 case KEY_getpeername:
6040 UNI(OP_GETPEERNAME);
6042 case KEY_gethostbyname:
6045 case KEY_gethostbyaddr:
6046 LOP(OP_GHBYADDR,XTERM);
6048 case KEY_gethostent:
6051 case KEY_getnetbyname:
6054 case KEY_getnetbyaddr:
6055 LOP(OP_GNBYADDR,XTERM);
6060 case KEY_getservbyname:
6061 LOP(OP_GSBYNAME,XTERM);
6063 case KEY_getservbyport:
6064 LOP(OP_GSBYPORT,XTERM);
6066 case KEY_getservent:
6069 case KEY_getsockname:
6070 UNI(OP_GETSOCKNAME);
6072 case KEY_getsockopt:
6073 LOP(OP_GSOCKOPT,XTERM);
6088 yylval.ival = CopLINE(PL_curcop);
6099 yylval.ival = CopLINE(PL_curcop);
6103 LOP(OP_INDEX,XTERM);
6109 LOP(OP_IOCTL,XTERM);
6121 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6153 LOP(OP_LISTEN,XTERM);
6162 s = scan_pat(s,OP_MATCH);
6163 TERM(sublex_start());
6166 LOP(OP_MAPSTART, XREF);
6169 LOP(OP_MKDIR,XTERM);
6172 LOP(OP_MSGCTL,XTERM);
6175 LOP(OP_MSGGET,XTERM);
6178 LOP(OP_MSGRCV,XTERM);
6181 LOP(OP_MSGSND,XTERM);
6188 if (isIDFIRST_lazy_if(s,UTF)) {
6192 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6193 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6195 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6196 if (!PL_in_my_stash) {
6199 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6203 if (PL_madskills) { /* just add type to declarator token */
6204 sv_catsv(PL_thistoken, PL_nextwhite);
6206 sv_catpvn(PL_thistoken, start, s - start);
6214 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6221 s = tokenize_use(0, s);
6225 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6232 if (isIDFIRST_lazy_if(s,UTF)) {
6234 for (d = s; isALNUM_lazy_if(d,UTF);)
6236 for (t=d; isSPACE(*t);)
6238 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6240 && !(t[0] == '=' && t[1] == '>')
6242 int parms_len = (int)(d-s);
6243 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6244 "Precedence problem: open %.*s should be open(%.*s)",
6245 parms_len, s, parms_len, s);
6251 yylval.ival = OP_OR;
6261 LOP(OP_OPEN_DIR,XTERM);
6264 checkcomma(s,PL_tokenbuf,"filehandle");
6268 checkcomma(s,PL_tokenbuf,"filehandle");
6287 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6291 LOP(OP_PIPE_OP,XTERM);
6294 s = scan_str(s,!!PL_madskills,FALSE);
6297 yylval.ival = OP_CONST;
6298 TERM(sublex_start());
6304 s = scan_str(s,!!PL_madskills,FALSE);
6307 PL_expect = XOPERATOR;
6309 if (SvCUR(PL_lex_stuff)) {
6312 d = SvPV_force(PL_lex_stuff, len);
6314 for (; isSPACE(*d) && len; --len, ++d)
6319 if (!warned && ckWARN(WARN_QW)) {
6320 for (; !isSPACE(*d) && len; --len, ++d) {
6322 Perl_warner(aTHX_ packWARN(WARN_QW),
6323 "Possible attempt to separate words with commas");
6326 else if (*d == '#') {
6327 Perl_warner(aTHX_ packWARN(WARN_QW),
6328 "Possible attempt to put comments in qw() list");
6334 for (; !isSPACE(*d) && len; --len, ++d)
6337 sv = newSVpvn(b, d-b);
6338 if (DO_UTF8(PL_lex_stuff))
6340 words = append_elem(OP_LIST, words,
6341 newSVOP(OP_CONST, 0, tokeq(sv)));
6345 start_force(PL_curforce);
6346 NEXTVAL_NEXTTOKE.opval = words;
6351 SvREFCNT_dec(PL_lex_stuff);
6352 PL_lex_stuff = NULL;
6358 s = scan_str(s,!!PL_madskills,FALSE);
6361 yylval.ival = OP_STRINGIFY;
6362 if (SvIVX(PL_lex_stuff) == '\'')
6363 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6364 TERM(sublex_start());
6367 s = scan_pat(s,OP_QR);
6368 TERM(sublex_start());
6371 s = scan_str(s,!!PL_madskills,FALSE);
6374 readpipe_override();
6375 TERM(sublex_start());
6383 s = force_version(s, FALSE);
6385 else if (*s != 'v' || !isDIGIT(s[1])
6386 || (s = force_version(s, TRUE), *s == 'v'))
6388 *PL_tokenbuf = '\0';
6389 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6390 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6391 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
6393 yyerror("<> should be quotes");
6395 if (orig_keyword == KEY_require) {
6403 PL_last_uni = PL_oldbufptr;
6404 PL_last_lop_op = OP_REQUIRE;
6406 return REPORT( (int)REQUIRE );
6412 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6416 LOP(OP_RENAME,XTERM);
6425 LOP(OP_RINDEX,XTERM);
6435 UNIDOR(OP_READLINE);
6439 UNIDOR(OP_BACKTICK);
6448 LOP(OP_REVERSE,XTERM);
6451 UNIDOR(OP_READLINK);
6459 TERM(sublex_start());
6461 TOKEN(1); /* force error */
6464 checkcomma(s,PL_tokenbuf,"filehandle");
6474 LOP(OP_SELECT,XTERM);
6480 LOP(OP_SEMCTL,XTERM);
6483 LOP(OP_SEMGET,XTERM);
6486 LOP(OP_SEMOP,XTERM);
6492 LOP(OP_SETPGRP,XTERM);
6494 case KEY_setpriority:
6495 LOP(OP_SETPRIORITY,XTERM);
6497 case KEY_sethostent:
6503 case KEY_setservent:
6506 case KEY_setprotoent:
6516 LOP(OP_SEEKDIR,XTERM);
6518 case KEY_setsockopt:
6519 LOP(OP_SSOCKOPT,XTERM);
6525 LOP(OP_SHMCTL,XTERM);
6528 LOP(OP_SHMGET,XTERM);
6531 LOP(OP_SHMREAD,XTERM);
6534 LOP(OP_SHMWRITE,XTERM);
6537 LOP(OP_SHUTDOWN,XTERM);
6546 LOP(OP_SOCKET,XTERM);
6548 case KEY_socketpair:
6549 LOP(OP_SOCKPAIR,XTERM);
6552 checkcomma(s,PL_tokenbuf,"subroutine name");
6554 if (*s == ';' || *s == ')') /* probably a close */
6555 Perl_croak(aTHX_ "sort is now a reserved word");
6557 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6561 LOP(OP_SPLIT,XTERM);
6564 LOP(OP_SPRINTF,XTERM);
6567 LOP(OP_SPLICE,XTERM);
6582 LOP(OP_SUBSTR,XTERM);
6588 char tmpbuf[sizeof PL_tokenbuf];
6589 SSize_t tboffset = 0;
6590 expectation attrful;
6591 bool have_name, have_proto;
6592 const int key = tmp;
6597 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6598 SV *subtoken = newSVpvn(tstart, s - tstart);
6602 s = SKIPSPACE2(s,tmpwhite);
6607 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6608 (*s == ':' && s[1] == ':'))
6615 attrful = XATTRBLOCK;
6616 /* remember buffer pos'n for later force_word */
6617 tboffset = s - PL_oldbufptr;
6618 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6621 nametoke = newSVpvn(s, d - s);
6623 if (memchr(tmpbuf, ':', len))
6624 sv_setpvn(PL_subname, tmpbuf, len);
6626 sv_setsv(PL_subname,PL_curstname);
6627 sv_catpvs(PL_subname,"::");
6628 sv_catpvn(PL_subname,tmpbuf,len);
6635 CURMAD('X', nametoke);
6636 CURMAD('_', tmpwhite);
6637 (void) force_word(PL_oldbufptr + tboffset, WORD,
6640 s = SKIPSPACE2(d,tmpwhite);
6647 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6648 PL_expect = XTERMBLOCK;
6649 attrful = XATTRTERM;
6650 sv_setpvn(PL_subname,"?",1);
6654 if (key == KEY_format) {
6656 PL_lex_formbrack = PL_lex_brackets + 1;
6658 PL_thistoken = subtoken;
6662 (void) force_word(PL_oldbufptr + tboffset, WORD,
6668 /* Look for a prototype */
6671 bool bad_proto = FALSE;
6672 const bool warnsyntax = ckWARN(WARN_SYNTAX);
6674 s = scan_str(s,!!PL_madskills,FALSE);
6676 Perl_croak(aTHX_ "Prototype not terminated");
6677 /* strip spaces and check for bad characters */
6678 d = SvPVX(PL_lex_stuff);
6680 for (p = d; *p; ++p) {
6683 if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
6689 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6690 "Illegal character in prototype for %"SVf" : %s",
6691 SVfARG(PL_subname), d);
6692 SvCUR_set(PL_lex_stuff, tmp);
6697 CURMAD('q', PL_thisopen);
6698 CURMAD('_', tmpwhite);
6699 CURMAD('=', PL_thisstuff);
6700 CURMAD('Q', PL_thisclose);
6701 NEXTVAL_NEXTTOKE.opval =
6702 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6703 PL_lex_stuff = Nullsv;
6706 s = SKIPSPACE2(s,tmpwhite);
6714 if (*s == ':' && s[1] != ':')
6715 PL_expect = attrful;
6716 else if (*s != '{' && key == KEY_sub) {
6718 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6720 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
6727 curmad('^', newSVpvs(""));
6728 CURMAD('_', tmpwhite);
6732 PL_thistoken = subtoken;
6735 NEXTVAL_NEXTTOKE.opval =
6736 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6737 PL_lex_stuff = NULL;
6742 sv_setpv(PL_subname,
6744 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
6748 (void) force_word(PL_oldbufptr + tboffset, WORD,
6758 LOP(OP_SYSTEM,XREF);
6761 LOP(OP_SYMLINK,XTERM);
6764 LOP(OP_SYSCALL,XTERM);
6767 LOP(OP_SYSOPEN,XTERM);
6770 LOP(OP_SYSSEEK,XTERM);
6773 LOP(OP_SYSREAD,XTERM);
6776 LOP(OP_SYSWRITE,XTERM);
6780 TERM(sublex_start());
6801 LOP(OP_TRUNCATE,XTERM);
6813 yylval.ival = CopLINE(PL_curcop);
6817 yylval.ival = CopLINE(PL_curcop);
6821 LOP(OP_UNLINK,XTERM);
6827 LOP(OP_UNPACK,XTERM);
6830 LOP(OP_UTIME,XTERM);
6836 LOP(OP_UNSHIFT,XTERM);
6839 s = tokenize_use(1, s);
6849 yylval.ival = CopLINE(PL_curcop);
6853 yylval.ival = CopLINE(PL_curcop);
6857 PL_hints |= HINT_BLOCK_SCOPE;
6864 LOP(OP_WAITPID,XTERM);
6873 ctl_l[0] = toCTRL('L');
6875 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6878 /* Make sure $^L is defined */
6879 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6884 if (PL_expect == XOPERATOR)
6890 yylval.ival = OP_XOR;
6895 TERM(sublex_start());
6900 #pragma segment Main
6904 S_pending_ident(pTHX)
6909 /* pit holds the identifier we read and pending_ident is reset */
6910 char pit = PL_pending_ident;
6911 PL_pending_ident = 0;
6913 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6914 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6915 "### Pending identifier '%s'\n", PL_tokenbuf); });
6917 /* if we're in a my(), we can't allow dynamics here.
6918 $foo'bar has already been turned into $foo::bar, so
6919 just check for colons.
6921 if it's a legal name, the OP is a PADANY.
6924 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6925 if (strchr(PL_tokenbuf,':'))
6926 yyerror(Perl_form(aTHX_ "No package name allowed for "
6927 "variable %s in \"our\"",
6929 tmp = allocmy(PL_tokenbuf);
6932 if (strchr(PL_tokenbuf,':'))
6933 yyerror(Perl_form(aTHX_ PL_no_myglob,
6934 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6936 yylval.opval = newOP(OP_PADANY, 0);
6937 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6943 build the ops for accesses to a my() variable.
6945 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6946 then used in a comparison. This catches most, but not
6947 all cases. For instance, it catches
6948 sort { my($a); $a <=> $b }
6950 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6951 (although why you'd do that is anyone's guess).
6954 if (!strchr(PL_tokenbuf,':')) {
6956 tmp = pad_findmy(PL_tokenbuf);
6957 if (tmp != NOT_IN_PAD) {
6958 /* might be an "our" variable" */
6959 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6960 /* build ops for a bareword */
6961 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6962 HEK * const stashname = HvNAME_HEK(stash);
6963 SV * const sym = newSVhek(stashname);
6964 sv_catpvs(sym, "::");
6965 sv_catpv(sym, PL_tokenbuf+1);
6966 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6967 yylval.opval->op_private = OPpCONST_ENTERED;
6970 ? (GV_ADDMULTI | GV_ADDINEVAL)
6973 ((PL_tokenbuf[0] == '$') ? SVt_PV
6974 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6979 /* if it's a sort block and they're naming $a or $b */
6980 if (PL_last_lop_op == OP_SORT &&
6981 PL_tokenbuf[0] == '$' &&
6982 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6985 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6986 d < PL_bufend && *d != '\n';
6989 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6990 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6996 yylval.opval = newOP(OP_PADANY, 0);
6997 yylval.opval->op_targ = tmp;
7003 Whine if they've said @foo in a doublequoted string,
7004 and @foo isn't a variable we can find in the symbol
7007 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
7008 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
7009 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
7010 && ckWARN(WARN_AMBIGUOUS)
7011 /* DO NOT warn for @- and @+ */
7012 && !( PL_tokenbuf[2] == '\0' &&
7013 ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
7016 /* Downgraded from fatal to warning 20000522 mjd */
7017 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
7018 "Possible unintended interpolation of %s in string",
7023 /* build ops for a bareword */
7024 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
7025 yylval.opval->op_private = OPpCONST_ENTERED;
7028 /* If the identifier refers to a stash, don't autovivify it.
7029 * Change 24660 had the side effect of causing symbol table
7030 * hashes to always be defined, even if they were freshly
7031 * created and the only reference in the entire program was
7032 * the single statement with the defined %foo::bar:: test.
7033 * It appears that all code in the wild doing this actually
7034 * wants to know whether sub-packages have been loaded, so
7035 * by avoiding auto-vivifying symbol tables, we ensure that
7036 * defined %foo::bar:: continues to be false, and the existing
7037 * tests still give the expected answers, even though what
7038 * they're actually testing has now changed subtly.
7040 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
7042 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
7043 ((PL_tokenbuf[0] == '$') ? SVt_PV
7044 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7050 * The following code was generated by perl_keyword.pl.
7054 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
7059 case 1: /* 5 tokens of length 1 */
7091 case 2: /* 18 tokens of length 2 */
7237 case 3: /* 29 tokens of length 3 */
7241 if (name[1] == 'N' &&
7304 if (name[1] == 'i' &&
7326 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7344 if (name[1] == 'o' &&
7353 if (name[1] == 'e' &&
7362 if (name[1] == 'n' &&
7371 if (name[1] == 'o' &&
7380 if (name[1] == 'a' &&
7389 if (name[1] == 'o' &&
7451 if (name[1] == 'e' &&
7465 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
7491 if (name[1] == 'i' &&
7500 if (name[1] == 's' &&
7509 if (name[1] == 'e' &&
7518 if (name[1] == 'o' &&
7530 case 4: /* 41 tokens of length 4 */
7534 if (name[1] == 'O' &&
7544 if (name[1] == 'N' &&
7554 if (name[1] == 'i' &&
7564 if (name[1] == 'h' &&
7574 if (name[1] == 'u' &&
7587 if (name[2] == 'c' &&
7596 if (name[2] == 's' &&
7605 if (name[2] == 'a' &&
7641 if (name[1] == 'o' &&
7654 if (name[2] == 't' &&
7663 if (name[2] == 'o' &&
7672 if (name[2] == 't' &&
7681 if (name[2] == 'e' &&
7694 if (name[1] == 'o' &&
7707 if (name[2] == 'y' &&
7716 if (name[2] == 'l' &&
7732 if (name[2] == 's' &&
7741 if (name[2] == 'n' &&
7750 if (name[2] == 'c' &&
7763 if (name[1] == 'e' &&
7773 if (name[1] == 'p' &&
7786 if (name[2] == 'c' &&
7795 if (name[2] == 'p' &&
7804 if (name[2] == 's' &&
7820 if (name[2] == 'n' &&
7890 if (name[2] == 'r' &&
7899 if (name[2] == 'r' &&
7908 if (name[2] == 'a' &&
7924 if (name[2] == 'l' &&
7986 if (name[2] == 'e' &&
7989 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
8002 case 5: /* 39 tokens of length 5 */
8006 if (name[1] == 'E' &&
8017 if (name[1] == 'H' &&
8031 if (name[2] == 'a' &&
8041 if (name[2] == 'a' &&
8058 if (name[2] == 'e' &&
8068 if (name[2] == 'e' &&
8072 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
8088 if (name[3] == 'i' &&
8097 if (name[3] == 'o' &&
8133 if (name[2] == 'o' &&
8143 if (name[2] == 'y' &&
8157 if (name[1] == 'l' &&
8171 if (name[2] == 'n' &&
8181 if (name[2] == 'o' &&
8195 if (name[1] == 'i' &&
8200 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8209 if (name[2] == 'd' &&
8219 if (name[2] == 'c' &&
8236 if (name[2] == 'c' &&
8246 if (name[2] == 't' &&
8260 if (name[1] == 'k' &&
8271 if (name[1] == 'r' &&
8285 if (name[2] == 's' &&
8295 if (name[2] == 'd' &&
8312 if (name[2] == 'm' &&
8322 if (name[2] == 'i' &&
8332 if (name[2] == 'e' &&
8342 if (name[2] == 'l' &&
8352 if (name[2] == 'a' &&
8365 if (name[3] == 't' &&
8368 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8374 if (name[3] == 'd' &&
8391 if (name[1] == 'i' &&
8405 if (name[2] == 'a' &&
8418 if (name[3] == 'e' &&
8453 if (name[2] == 'i' &&
8470 if (name[2] == 'i' &&
8480 if (name[2] == 'i' &&
8497 case 6: /* 33 tokens of length 6 */
8501 if (name[1] == 'c' &&
8516 if (name[2] == 'l' &&
8527 if (name[2] == 'r' &&
8542 if (name[1] == 'e' &&
8557 if (name[2] == 's' &&
8562 if(ckWARN_d(WARN_SYNTAX))
8563 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8569 if (name[2] == 'i' &&
8587 if (name[2] == 'l' &&
8598 if (name[2] == 'r' &&
8613 if (name[1] == 'm' &&
8628 if (name[2] == 'n' &&
8639 if (name[2] == 's' &&
8654 if (name[1] == 's' &&
8660 if (name[4] == 't' &&
8669 if (name[4] == 'e' &&
8678 if (name[4] == 'c' &&
8687 if (name[4] == 'n' &&
8703 if (name[1] == 'r' &&
8721 if (name[3] == 'a' &&
8731 if (name[3] == 'u' &&
8745 if (name[2] == 'n' &&
8763 if (name[2] == 'a' &&
8777 if (name[3] == 'e' &&
8790 if (name[4] == 't' &&
8799 if (name[4] == 'e' &&
8821 if (name[4] == 't' &&
8830 if (name[4] == 'e' &&
8846 if (name[2] == 'c' &&
8857 if (name[2] == 'l' &&
8868 if (name[2] == 'b' &&
8879 if (name[2] == 's' &&
8902 if (name[4] == 's' &&
8911 if (name[4] == 'n' &&
8924 if (name[3] == 'a' &&
8941 if (name[1] == 'a' &&
8956 case 7: /* 29 tokens of length 7 */
8960 if (name[1] == 'E' &&
8973 if (name[1] == '_' &&
8986 if (name[1] == 'i' &&
8993 return -KEY_binmode;
8999 if (name[1] == 'o' &&
9006 return -KEY_connect;
9015 if (name[2] == 'm' &&
9021 return -KEY_dbmopen;
9032 if (name[4] == 'u' &&
9036 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
9042 if (name[4] == 'n' &&
9063 if (name[1] == 'o' &&
9076 if (name[1] == 'e' &&
9083 if (name[5] == 'r' &&
9086 return -KEY_getpgrp;
9092 if (name[5] == 'i' &&
9095 return -KEY_getppid;
9108 if (name[1] == 'c' &&
9115 return -KEY_lcfirst;
9121 if (name[1] == 'p' &&
9128 return -KEY_opendir;
9134 if (name[1] == 'a' &&
9152 if (name[3] == 'd' &&
9157 return -KEY_readdir;
9163 if (name[3] == 'u' &&
9174 if (name[3] == 'e' &&
9179 return -KEY_reverse;
9198 if (name[3] == 'k' &&
9203 return -KEY_seekdir;
9209 if (name[3] == 'p' &&
9214 return -KEY_setpgrp;
9224 if (name[2] == 'm' &&
9230 return -KEY_shmread;
9236 if (name[2] == 'r' &&
9242 return -KEY_sprintf;
9251 if (name[3] == 'l' &&
9256 return -KEY_symlink;
9265 if (name[4] == 'a' &&
9269 return -KEY_syscall;
9275 if (name[4] == 'p' &&
9279 return -KEY_sysopen;
9285 if (name[4] == 'e' &&
9289 return -KEY_sysread;
9295 if (name[4] == 'e' &&
9299 return -KEY_sysseek;
9317 if (name[1] == 'e' &&
9324 return -KEY_telldir;
9333 if (name[2] == 'f' &&
9339 return -KEY_ucfirst;
9345 if (name[2] == 's' &&
9351 return -KEY_unshift;
9361 if (name[1] == 'a' &&
9368 return -KEY_waitpid;
9377 case 8: /* 26 tokens of length 8 */
9381 if (name[1] == 'U' &&
9389 return KEY_AUTOLOAD;
9400 if (name[3] == 'A' &&
9406 return KEY___DATA__;
9412 if (name[3] == 'I' &&
9418 return -KEY___FILE__;
9424 if (name[3] == 'I' &&
9430 return -KEY___LINE__;
9446 if (name[2] == 'o' &&
9453 return -KEY_closedir;
9459 if (name[2] == 'n' &&
9466 return -KEY_continue;
9476 if (name[1] == 'b' &&
9484 return -KEY_dbmclose;
9490 if (name[1] == 'n' &&
9496 if (name[4] == 'r' &&
9501 return -KEY_endgrent;
9507 if (name[4] == 'w' &&
9512 return -KEY_endpwent;
9525 if (name[1] == 'o' &&
9533 return -KEY_formline;
9539 if (name[1] == 'e' &&
9550 if (name[6] == 'n' &&
9553 return -KEY_getgrent;
9559 if (name[6] == 'i' &&
9562 return -KEY_getgrgid;
9568 if (name[6] == 'a' &&
9571 return -KEY_getgrnam;
9584 if (name[4] == 'o' &&
9589 return -KEY_getlogin;
9600 if (name[6] == 'n' &&
9603 return -KEY_getpwent;
9609 if (name[6] == 'a' &&
9612 return -KEY_getpwnam;
9618 if (name[6] == 'i' &&
9621 return -KEY_getpwuid;
9641 if (name[1] == 'e' &&
9648 if (name[5] == 'i' &&
9655 return -KEY_readline;
9660 return -KEY_readlink;
9671 if (name[5] == 'i' &&
9675 return -KEY_readpipe;
9696 if (name[4] == 'r' &&
9701 return -KEY_setgrent;
9707 if (name[4] == 'w' &&
9712 return -KEY_setpwent;
9728 if (name[3] == 'w' &&
9734 return -KEY_shmwrite;
9740 if (name[3] == 't' &&
9746 return -KEY_shutdown;
9756 if (name[2] == 's' &&
9763 return -KEY_syswrite;
9773 if (name[1] == 'r' &&
9781 return -KEY_truncate;
9790 case 9: /* 9 tokens of length 9 */
9794 if (name[1] == 'N' &&
9803 return KEY_UNITCHECK;
9809 if (name[1] == 'n' &&
9818 return -KEY_endnetent;
9824 if (name[1] == 'e' &&
9833 return -KEY_getnetent;
9839 if (name[1] == 'o' &&
9848 return -KEY_localtime;
9854 if (name[1] == 'r' &&
9863 return KEY_prototype;
9869 if (name[1] == 'u' &&
9878 return -KEY_quotemeta;
9884 if (name[1] == 'e' &&
9893 return -KEY_rewinddir;
9899 if (name[1] == 'e' &&
9908 return -KEY_setnetent;
9914 if (name[1] == 'a' &&
9923 return -KEY_wantarray;
9932 case 10: /* 9 tokens of length 10 */
9936 if (name[1] == 'n' &&
9942 if (name[4] == 'o' &&
9949 return -KEY_endhostent;
9955 if (name[4] == 'e' &&
9962 return -KEY_endservent;
9975 if (name[1] == 'e' &&
9981 if (name[4] == 'o' &&
9988 return -KEY_gethostent;
9997 if (name[5] == 'r' &&
10003 return -KEY_getservent;
10009 if (name[5] == 'c' &&
10015 return -KEY_getsockopt;
10035 if (name[2] == 't')
10040 if (name[4] == 'o' &&
10047 return -KEY_sethostent;
10056 if (name[5] == 'r' &&
10062 return -KEY_setservent;
10068 if (name[5] == 'c' &&
10074 return -KEY_setsockopt;
10091 if (name[2] == 'c' &&
10100 return -KEY_socketpair;
10113 case 11: /* 8 tokens of length 11 */
10117 if (name[1] == '_' &&
10127 { /* __PACKAGE__ */
10128 return -KEY___PACKAGE__;
10134 if (name[1] == 'n' &&
10144 { /* endprotoent */
10145 return -KEY_endprotoent;
10151 if (name[1] == 'e' &&
10160 if (name[5] == 'e' &&
10166 { /* getpeername */
10167 return -KEY_getpeername;
10176 if (name[6] == 'o' &&
10181 { /* getpriority */
10182 return -KEY_getpriority;
10188 if (name[6] == 't' &&
10193 { /* getprotoent */
10194 return -KEY_getprotoent;
10208 if (name[4] == 'o' &&
10215 { /* getsockname */
10216 return -KEY_getsockname;
10229 if (name[1] == 'e' &&
10237 if (name[6] == 'o' &&
10242 { /* setpriority */
10243 return -KEY_setpriority;
10249 if (name[6] == 't' &&
10254 { /* setprotoent */
10255 return -KEY_setprotoent;
10271 case 12: /* 2 tokens of length 12 */
10272 if (name[0] == 'g' &&
10284 if (name[9] == 'd' &&
10287 { /* getnetbyaddr */
10288 return -KEY_getnetbyaddr;
10294 if (name[9] == 'a' &&
10297 { /* getnetbyname */
10298 return -KEY_getnetbyname;
10310 case 13: /* 4 tokens of length 13 */
10311 if (name[0] == 'g' &&
10318 if (name[4] == 'o' &&
10327 if (name[10] == 'd' &&
10330 { /* gethostbyaddr */
10331 return -KEY_gethostbyaddr;
10337 if (name[10] == 'a' &&
10340 { /* gethostbyname */
10341 return -KEY_gethostbyname;
10354 if (name[4] == 'e' &&
10363 if (name[10] == 'a' &&
10366 { /* getservbyname */
10367 return -KEY_getservbyname;
10373 if (name[10] == 'o' &&
10376 { /* getservbyport */
10377 return -KEY_getservbyport;
10396 case 14: /* 1 tokens of length 14 */
10397 if (name[0] == 'g' &&
10411 { /* getprotobyname */
10412 return -KEY_getprotobyname;
10417 case 16: /* 1 tokens of length 16 */
10418 if (name[0] == 'g' &&
10434 { /* getprotobynumber */
10435 return -KEY_getprotobynumber;
10449 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10453 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10454 if (ckWARN(WARN_SYNTAX)) {
10457 for (w = s+2; *w && level; w++) {
10460 else if (*w == ')')
10463 while (isSPACE(*w))
10465 /* the list of chars below is for end of statements or
10466 * block / parens, boolean operators (&&, ||, //) and branch
10467 * constructs (or, and, if, until, unless, while, err, for).
10468 * Not a very solid hack... */
10469 if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
10470 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10471 "%s (...) interpreted as function",name);
10474 while (s < PL_bufend && isSPACE(*s))
10478 while (s < PL_bufend && isSPACE(*s))
10480 if (isIDFIRST_lazy_if(s,UTF)) {
10481 const char * const w = s++;
10482 while (isALNUM_lazy_if(s,UTF))
10484 while (s < PL_bufend && isSPACE(*s))
10488 if (keyword(w, s - w, 0))
10491 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10492 if (gv && GvCVu(gv))
10494 Perl_croak(aTHX_ "No comma allowed after %s", what);
10499 /* Either returns sv, or mortalizes sv and returns a new SV*.
10500 Best used as sv=new_constant(..., sv, ...).
10501 If s, pv are NULL, calls subroutine with one argument,
10502 and type is used with error messages only. */
10505 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10509 HV * const table = GvHV(PL_hintgv); /* ^H */
10513 const char *why1 = "", *why2 = "", *why3 = "";
10515 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10518 why2 = (const char *)
10519 (strEQ(key,"charnames")
10520 ? "(possibly a missing \"use charnames ...\")"
10522 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10523 (type ? type: "undef"), why2);
10525 /* This is convoluted and evil ("goto considered harmful")
10526 * but I do not understand the intricacies of all the different
10527 * failure modes of %^H in here. The goal here is to make
10528 * the most probable error message user-friendly. --jhi */
10533 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10534 (type ? type: "undef"), why1, why2, why3);
10536 yyerror(SvPVX_const(msg));
10540 cvp = hv_fetch(table, key, strlen(key), FALSE);
10541 if (!cvp || !SvOK(*cvp)) {
10544 why3 = "} is not defined";
10547 sv_2mortal(sv); /* Parent created it permanently */
10550 pv = sv_2mortal(newSVpvn(s, len));
10552 typesv = sv_2mortal(newSVpv(type, 0));
10554 typesv = &PL_sv_undef;
10556 PUSHSTACKi(PERLSI_OVERLOAD);
10568 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10572 /* Check the eval first */
10573 if (!PL_in_eval && SvTRUE(ERRSV)) {
10574 sv_catpvs(ERRSV, "Propagated");
10575 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10577 res = SvREFCNT_inc_simple(sv);
10581 SvREFCNT_inc_simple_void(res);
10590 why1 = "Call to &{$^H{";
10592 why3 = "}} did not return a defined value";
10600 /* Returns a NUL terminated string, with the length of the string written to
10604 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10607 register char *d = dest;
10608 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10611 Perl_croak(aTHX_ ident_too_long);
10612 if (isALNUM(*s)) /* UTF handled below */
10614 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10619 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10623 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10624 char *t = s + UTF8SKIP(s);
10626 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10630 Perl_croak(aTHX_ ident_too_long);
10631 Copy(s, d, len, char);
10644 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10647 char *bracket = NULL;
10649 register char *d = dest;
10650 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10655 while (isDIGIT(*s)) {
10657 Perl_croak(aTHX_ ident_too_long);
10664 Perl_croak(aTHX_ ident_too_long);
10665 if (isALNUM(*s)) /* UTF handled below */
10667 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10672 else if (*s == ':' && s[1] == ':') {
10676 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10677 char *t = s + UTF8SKIP(s);
10678 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10680 if (d + (t - s) > e)
10681 Perl_croak(aTHX_ ident_too_long);
10682 Copy(s, d, t - s, char);
10693 if (PL_lex_state != LEX_NORMAL)
10694 PL_lex_state = LEX_INTERPENDMAYBE;
10697 if (*s == '$' && s[1] &&
10698 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10711 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10716 if (isSPACE(s[-1])) {
10718 const char ch = *s++;
10719 if (!SPACE_OR_TAB(ch)) {
10725 if (isIDFIRST_lazy_if(d,UTF)) {
10729 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10730 end += UTF8SKIP(end);
10731 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10732 end += UTF8SKIP(end);
10734 Copy(s, d, end - s, char);
10739 while ((isALNUM(*s) || *s == ':') && d < e)
10742 Perl_croak(aTHX_ ident_too_long);
10745 while (s < send && SPACE_OR_TAB(*s))
10747 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10748 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10749 const char * const brack =
10751 ((*s == '[') ? "[...]" : "{...}");
10752 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10753 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10754 funny, dest, brack, funny, dest, brack);
10757 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10761 /* Handle extended ${^Foo} variables
10762 * 1999-02-27 mjd-perl-patch@plover.com */
10763 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10767 while (isALNUM(*s) && d < e) {
10771 Perl_croak(aTHX_ ident_too_long);
10776 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10777 PL_lex_state = LEX_INTERPEND;
10780 if (PL_lex_state == LEX_NORMAL) {
10781 if (ckWARN(WARN_AMBIGUOUS) &&
10782 (keyword(dest, d - dest, 0)
10783 || get_cvn_flags(dest, d - dest, 0)))
10787 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10788 "Ambiguous use of %c{%s} resolved to %c%s",
10789 funny, dest, funny, dest);
10794 s = bracket; /* let the parser handle it */
10798 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10799 PL_lex_state = LEX_INTERPEND;
10804 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10806 PERL_UNUSED_CONTEXT;
10810 CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
10811 case GLOBAL_PAT_MOD: *pmfl |= PMf_GLOBAL; break;
10812 case CONTINUE_PAT_MOD: *pmfl |= PMf_CONTINUE; break;
10813 case ONCE_PAT_MOD: *pmfl |= PMf_KEEP; break;
10814 case KEEPCOPY_PAT_MOD: *pmfl |= PMf_KEEPCOPY; break;
10820 S_scan_pat(pTHX_ char *start, I32 type)
10824 char *s = scan_str(start,!!PL_madskills,FALSE);
10825 const char * const valid_flags =
10826 (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
10833 const char * const delimiter = skipspace(start);
10837 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10838 : "Search pattern not terminated" ));
10841 pm = (PMOP*)newPMOP(type, 0);
10842 if (PL_multi_open == '?')
10843 pm->op_pmflags |= PMf_ONCE;
10847 while (*s && strchr(valid_flags, *s))
10848 pmflag(&pm->op_pmflags,*s++);
10850 if (PL_madskills && modstart != s) {
10851 SV* tmptoken = newSVpvn(modstart, s - modstart);
10852 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10855 /* issue a warning if /c is specified,but /g is not */
10856 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10857 && ckWARN(WARN_REGEXP))
10859 Perl_warner(aTHX_ packWARN(WARN_REGEXP),
10860 "Use of /c modifier is meaningless without /g" );
10863 pm->op_pmpermflags = pm->op_pmflags;
10865 PL_lex_op = (OP*)pm;
10866 yylval.ival = OP_MATCH;
10871 S_scan_subst(pTHX_ char *start)
10882 yylval.ival = OP_NULL;
10884 s = scan_str(start,!!PL_madskills,FALSE);
10887 Perl_croak(aTHX_ "Substitution pattern not terminated");
10889 if (s[-1] == PL_multi_open)
10892 if (PL_madskills) {
10893 CURMAD('q', PL_thisopen);
10894 CURMAD('_', PL_thiswhite);
10895 CURMAD('E', PL_thisstuff);
10896 CURMAD('Q', PL_thisclose);
10897 PL_realtokenstart = s - SvPVX(PL_linestr);
10901 first_start = PL_multi_start;
10902 s = scan_str(s,!!PL_madskills,FALSE);
10904 if (PL_lex_stuff) {
10905 SvREFCNT_dec(PL_lex_stuff);
10906 PL_lex_stuff = NULL;
10908 Perl_croak(aTHX_ "Substitution replacement not terminated");
10910 PL_multi_start = first_start; /* so whole substitution is taken together */
10912 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10915 if (PL_madskills) {
10916 CURMAD('z', PL_thisopen);
10917 CURMAD('R', PL_thisstuff);
10918 CURMAD('Z', PL_thisclose);
10924 if (*s == EXEC_PAT_MOD) {
10928 else if (strchr(S_PAT_MODS, *s))
10929 pmflag(&pm->op_pmflags,*s++);
10935 if (PL_madskills) {
10937 curmad('m', newSVpvn(modstart, s - modstart));
10938 append_madprops(PL_thismad, (OP*)pm, 0);
10942 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10943 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10947 SV * const repl = newSVpvs("");
10949 PL_sublex_info.super_bufptr = s;
10950 PL_sublex_info.super_bufend = PL_bufend;
10952 pm->op_pmflags |= PMf_EVAL;
10954 sv_catpv(repl, (const char *)(es ? "eval " : "do "));
10955 sv_catpvs(repl, "{");
10956 sv_catsv(repl, PL_lex_repl);
10957 if (strchr(SvPVX(PL_lex_repl), '#'))
10958 sv_catpvs(repl, "\n");
10959 sv_catpvs(repl, "}");
10961 SvREFCNT_dec(PL_lex_repl);
10962 PL_lex_repl = repl;
10965 pm->op_pmpermflags = pm->op_pmflags;
10966 PL_lex_op = (OP*)pm;
10967 yylval.ival = OP_SUBST;
10972 S_scan_trans(pTHX_ char *start)
10985 yylval.ival = OP_NULL;
10987 s = scan_str(start,!!PL_madskills,FALSE);
10989 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10991 if (s[-1] == PL_multi_open)
10994 if (PL_madskills) {
10995 CURMAD('q', PL_thisopen);
10996 CURMAD('_', PL_thiswhite);
10997 CURMAD('E', PL_thisstuff);
10998 CURMAD('Q', PL_thisclose);
10999 PL_realtokenstart = s - SvPVX(PL_linestr);
11003 s = scan_str(s,!!PL_madskills,FALSE);
11005 if (PL_lex_stuff) {
11006 SvREFCNT_dec(PL_lex_stuff);
11007 PL_lex_stuff = NULL;
11009 Perl_croak(aTHX_ "Transliteration replacement not terminated");
11011 if (PL_madskills) {
11012 CURMAD('z', PL_thisopen);
11013 CURMAD('R', PL_thisstuff);
11014 CURMAD('Z', PL_thisclose);
11017 complement = del = squash = 0;
11024 complement = OPpTRANS_COMPLEMENT;
11027 del = OPpTRANS_DELETE;
11030 squash = OPpTRANS_SQUASH;
11039 tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
11040 o = newPVOP(OP_TRANS, 0, (char*)tbl);
11041 o->op_private &= ~OPpTRANS_ALL;
11042 o->op_private |= del|squash|complement|
11043 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
11044 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
11047 yylval.ival = OP_TRANS;
11050 if (PL_madskills) {
11052 curmad('m', newSVpvn(modstart, s - modstart));
11053 append_madprops(PL_thismad, o, 0);
11062 S_scan_heredoc(pTHX_ register char *s)
11066 I32 op_type = OP_SCALAR;
11070 const char *found_newline;
11074 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
11076 I32 stuffstart = s - SvPVX(PL_linestr);
11079 PL_realtokenstart = -1;
11084 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
11088 while (SPACE_OR_TAB(*peek))
11090 if (*peek == '`' || *peek == '\'' || *peek =='"') {
11093 s = delimcpy(d, e, s, PL_bufend, term, &len);
11103 if (!isALNUM_lazy_if(s,UTF))
11104 deprecate_old("bare << to mean <<\"\"");
11105 for (; isALNUM_lazy_if(s,UTF); s++) {
11110 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
11111 Perl_croak(aTHX_ "Delimiter for here document is too long");
11114 len = d - PL_tokenbuf;
11117 if (PL_madskills) {
11118 tstart = PL_tokenbuf + !outer;
11119 PL_thisclose = newSVpvn(tstart, len - !outer);
11120 tstart = SvPVX(PL_linestr) + stuffstart;
11121 PL_thisopen = newSVpvn(tstart, s - tstart);
11122 stuffstart = s - SvPVX(PL_linestr);
11125 #ifndef PERL_STRICT_CR
11126 d = strchr(s, '\r');
11128 char * const olds = s;
11130 while (s < PL_bufend) {
11136 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11145 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11152 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11153 herewas = newSVpvn(s,PL_bufend-s);
11157 herewas = newSVpvn(s-1,found_newline-s+1);
11160 herewas = newSVpvn(s,found_newline-s);
11164 if (PL_madskills) {
11165 tstart = SvPVX(PL_linestr) + stuffstart;
11167 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11169 PL_thisstuff = newSVpvn(tstart, s - tstart);
11172 s += SvCUR(herewas);
11175 stuffstart = s - SvPVX(PL_linestr);
11181 tmpstr = newSV_type(SVt_PVIV);
11182 SvGROW(tmpstr, 80);
11183 if (term == '\'') {
11184 op_type = OP_CONST;
11185 SvIV_set(tmpstr, -1);
11187 else if (term == '`') {
11188 op_type = OP_BACKTICK;
11189 SvIV_set(tmpstr, '\\');
11193 PL_multi_start = CopLINE(PL_curcop);
11194 PL_multi_open = PL_multi_close = '<';
11195 term = *PL_tokenbuf;
11196 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11197 char * const bufptr = PL_sublex_info.super_bufptr;
11198 char * const bufend = PL_sublex_info.super_bufend;
11199 char * const olds = s - SvCUR(herewas);
11200 s = strchr(bufptr, '\n');
11204 while (s < bufend &&
11205 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11207 CopLINE_inc(PL_curcop);
11210 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11211 missingterm(PL_tokenbuf);
11213 sv_setpvn(herewas,bufptr,d-bufptr+1);
11214 sv_setpvn(tmpstr,d+1,s-d);
11216 sv_catpvn(herewas,s,bufend-s);
11217 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11224 while (s < PL_bufend &&
11225 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11227 CopLINE_inc(PL_curcop);
11229 if (s >= PL_bufend) {
11230 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11231 missingterm(PL_tokenbuf);
11233 sv_setpvn(tmpstr,d+1,s-d);
11235 if (PL_madskills) {
11237 sv_catpvn(PL_thisstuff, d + 1, s - d);
11239 PL_thisstuff = newSVpvn(d + 1, s - d);
11240 stuffstart = s - SvPVX(PL_linestr);
11244 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11246 sv_catpvn(herewas,s,PL_bufend-s);
11247 sv_setsv(PL_linestr,herewas);
11248 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11249 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11250 PL_last_lop = PL_last_uni = NULL;
11253 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11254 while (s >= PL_bufend) { /* multiple line string? */
11256 if (PL_madskills) {
11257 tstart = SvPVX(PL_linestr) + stuffstart;
11259 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11261 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11265 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11266 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11267 missingterm(PL_tokenbuf);
11270 stuffstart = s - SvPVX(PL_linestr);
11272 CopLINE_inc(PL_curcop);
11273 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11274 PL_last_lop = PL_last_uni = NULL;
11275 #ifndef PERL_STRICT_CR
11276 if (PL_bufend - PL_linestart >= 2) {
11277 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11278 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11280 PL_bufend[-2] = '\n';
11282 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11284 else if (PL_bufend[-1] == '\r')
11285 PL_bufend[-1] = '\n';
11287 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11288 PL_bufend[-1] = '\n';
11290 if (PERLDB_LINE && PL_curstash != PL_debstash)
11291 update_debugger_info(PL_linestr, NULL, 0);
11292 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11293 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11294 *(SvPVX(PL_linestr) + off ) = ' ';
11295 sv_catsv(PL_linestr,herewas);
11296 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11297 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11301 sv_catsv(tmpstr,PL_linestr);
11306 PL_multi_end = CopLINE(PL_curcop);
11307 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11308 SvPV_shrink_to_cur(tmpstr);
11310 SvREFCNT_dec(herewas);
11312 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11314 else if (PL_encoding)
11315 sv_recode_to_utf8(tmpstr, PL_encoding);
11317 PL_lex_stuff = tmpstr;
11318 yylval.ival = op_type;
11322 /* scan_inputsymbol
11323 takes: current position in input buffer
11324 returns: new position in input buffer
11325 side-effects: yylval and lex_op are set.
11330 <FH> read from filehandle
11331 <pkg::FH> read from package qualified filehandle
11332 <pkg'FH> read from package qualified filehandle
11333 <$fh> read from filehandle in $fh
11334 <*.h> filename glob
11339 S_scan_inputsymbol(pTHX_ char *start)
11342 register char *s = start; /* current position in buffer */
11346 char *d = PL_tokenbuf; /* start of temp holding space */
11347 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11349 end = strchr(s, '\n');
11352 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11354 /* die if we didn't have space for the contents of the <>,
11355 or if it didn't end, or if we see a newline
11358 if (len >= (I32)sizeof PL_tokenbuf)
11359 Perl_croak(aTHX_ "Excessively long <> operator");
11361 Perl_croak(aTHX_ "Unterminated <> operator");
11366 Remember, only scalar variables are interpreted as filehandles by
11367 this code. Anything more complex (e.g., <$fh{$num}>) will be
11368 treated as a glob() call.
11369 This code makes use of the fact that except for the $ at the front,
11370 a scalar variable and a filehandle look the same.
11372 if (*d == '$' && d[1]) d++;
11374 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11375 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11378 /* If we've tried to read what we allow filehandles to look like, and
11379 there's still text left, then it must be a glob() and not a getline.
11380 Use scan_str to pull out the stuff between the <> and treat it
11381 as nothing more than a string.
11384 if (d - PL_tokenbuf != len) {
11385 yylval.ival = OP_GLOB;
11387 s = scan_str(start,!!PL_madskills,FALSE);
11389 Perl_croak(aTHX_ "Glob not terminated");
11393 bool readline_overriden = FALSE;
11396 /* we're in a filehandle read situation */
11399 /* turn <> into <ARGV> */
11401 Copy("ARGV",d,5,char);
11403 /* Check whether readline() is overriden */
11404 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11406 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11408 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11409 && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
11410 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11411 readline_overriden = TRUE;
11413 /* if <$fh>, create the ops to turn the variable into a
11417 /* try to find it in the pad for this block, otherwise find
11418 add symbol table ops
11420 const PADOFFSET tmp = pad_findmy(d);
11421 if (tmp != NOT_IN_PAD) {
11422 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11423 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11424 HEK * const stashname = HvNAME_HEK(stash);
11425 SV * const sym = sv_2mortal(newSVhek(stashname));
11426 sv_catpvs(sym, "::");
11427 sv_catpv(sym, d+1);
11432 OP * const o = newOP(OP_PADSV, 0);
11434 PL_lex_op = readline_overriden
11435 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11436 append_elem(OP_LIST, o,
11437 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11438 : (OP*)newUNOP(OP_READLINE, 0, o);
11447 ? (GV_ADDMULTI | GV_ADDINEVAL)
11450 PL_lex_op = readline_overriden
11451 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11452 append_elem(OP_LIST,
11453 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11454 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11455 : (OP*)newUNOP(OP_READLINE, 0,
11456 newUNOP(OP_RV2SV, 0,
11457 newGVOP(OP_GV, 0, gv)));
11459 if (!readline_overriden)
11460 PL_lex_op->op_flags |= OPf_SPECIAL;
11461 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11462 yylval.ival = OP_NULL;
11465 /* If it's none of the above, it must be a literal filehandle
11466 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11468 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11469 PL_lex_op = readline_overriden
11470 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11471 append_elem(OP_LIST,
11472 newGVOP(OP_GV, 0, gv),
11473 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11474 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11475 yylval.ival = OP_NULL;
11484 takes: start position in buffer
11485 keep_quoted preserve \ on the embedded delimiter(s)
11486 keep_delims preserve the delimiters around the string
11487 returns: position to continue reading from buffer
11488 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11489 updates the read buffer.
11491 This subroutine pulls a string out of the input. It is called for:
11492 q single quotes q(literal text)
11493 ' single quotes 'literal text'
11494 qq double quotes qq(interpolate $here please)
11495 " double quotes "interpolate $here please"
11496 qx backticks qx(/bin/ls -l)
11497 ` backticks `/bin/ls -l`
11498 qw quote words @EXPORT_OK = qw( func() $spam )
11499 m// regexp match m/this/
11500 s/// regexp substitute s/this/that/
11501 tr/// string transliterate tr/this/that/
11502 y/// string transliterate y/this/that/
11503 ($*@) sub prototypes sub foo ($)
11504 (stuff) sub attr parameters sub foo : attr(stuff)
11505 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11507 In most of these cases (all but <>, patterns and transliterate)
11508 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11509 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11510 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11513 It skips whitespace before the string starts, and treats the first
11514 character as the delimiter. If the delimiter is one of ([{< then
11515 the corresponding "close" character )]}> is used as the closing
11516 delimiter. It allows quoting of delimiters, and if the string has
11517 balanced delimiters ([{<>}]) it allows nesting.
11519 On success, the SV with the resulting string is put into lex_stuff or,
11520 if that is already non-NULL, into lex_repl. The second case occurs only
11521 when parsing the RHS of the special constructs s/// and tr/// (y///).
11522 For convenience, the terminating delimiter character is stuffed into
11527 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11530 SV *sv; /* scalar value: string */
11531 const char *tmps; /* temp string, used for delimiter matching */
11532 register char *s = start; /* current position in the buffer */
11533 register char term; /* terminating character */
11534 register char *to; /* current position in the sv's data */
11535 I32 brackets = 1; /* bracket nesting level */
11536 bool has_utf8 = FALSE; /* is there any utf8 content? */
11537 I32 termcode; /* terminating char. code */
11538 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11539 STRLEN termlen; /* length of terminating string */
11540 int last_off = 0; /* last position for nesting bracket */
11546 /* skip space before the delimiter */
11552 if (PL_realtokenstart >= 0) {
11553 stuffstart = PL_realtokenstart;
11554 PL_realtokenstart = -1;
11557 stuffstart = start - SvPVX(PL_linestr);
11559 /* mark where we are, in case we need to report errors */
11562 /* after skipping whitespace, the next character is the terminator */
11565 termcode = termstr[0] = term;
11569 termcode = utf8_to_uvchr((U8*)s, &termlen);
11570 Copy(s, termstr, termlen, U8);
11571 if (!UTF8_IS_INVARIANT(term))
11575 /* mark where we are */
11576 PL_multi_start = CopLINE(PL_curcop);
11577 PL_multi_open = term;
11579 /* find corresponding closing delimiter */
11580 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11581 termcode = termstr[0] = term = tmps[5];
11583 PL_multi_close = term;
11585 /* create a new SV to hold the contents. 79 is the SV's initial length.
11586 What a random number. */
11587 sv = newSV_type(SVt_PVIV);
11589 SvIV_set(sv, termcode);
11590 (void)SvPOK_only(sv); /* validate pointer */
11592 /* move past delimiter and try to read a complete string */
11594 sv_catpvn(sv, s, termlen);
11597 tstart = SvPVX(PL_linestr) + stuffstart;
11598 if (!PL_thisopen && !keep_delims) {
11599 PL_thisopen = newSVpvn(tstart, s - tstart);
11600 stuffstart = s - SvPVX(PL_linestr);
11604 if (PL_encoding && !UTF) {
11608 int offset = s - SvPVX_const(PL_linestr);
11609 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11610 &offset, (char*)termstr, termlen);
11611 const char * const ns = SvPVX_const(PL_linestr) + offset;
11612 char * const svlast = SvEND(sv) - 1;
11614 for (; s < ns; s++) {
11615 if (*s == '\n' && !PL_rsfp)
11616 CopLINE_inc(PL_curcop);
11619 goto read_more_line;
11621 /* handle quoted delimiters */
11622 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11624 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11626 if ((svlast-1 - t) % 2) {
11627 if (!keep_quoted) {
11628 *(svlast-1) = term;
11630 SvCUR_set(sv, SvCUR(sv) - 1);
11635 if (PL_multi_open == PL_multi_close) {
11641 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
11642 /* At here, all closes are "was quoted" one,
11643 so we don't check PL_multi_close. */
11645 if (!keep_quoted && *(t+1) == PL_multi_open)
11650 else if (*t == PL_multi_open)
11658 SvCUR_set(sv, w - SvPVX_const(sv));
11660 last_off = w - SvPVX(sv);
11661 if (--brackets <= 0)
11666 if (!keep_delims) {
11667 SvCUR_set(sv, SvCUR(sv) - 1);
11673 /* extend sv if need be */
11674 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11675 /* set 'to' to the next character in the sv's string */
11676 to = SvPVX(sv)+SvCUR(sv);
11678 /* if open delimiter is the close delimiter read unbridle */
11679 if (PL_multi_open == PL_multi_close) {
11680 for (; s < PL_bufend; s++,to++) {
11681 /* embedded newlines increment the current line number */
11682 if (*s == '\n' && !PL_rsfp)
11683 CopLINE_inc(PL_curcop);
11684 /* handle quoted delimiters */
11685 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11686 if (!keep_quoted && s[1] == term)
11688 /* any other quotes are simply copied straight through */
11692 /* terminate when run out of buffer (the for() condition), or
11693 have found the terminator */
11694 else if (*s == term) {
11697 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11700 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11706 /* if the terminator isn't the same as the start character (e.g.,
11707 matched brackets), we have to allow more in the quoting, and
11708 be prepared for nested brackets.
11711 /* read until we run out of string, or we find the terminator */
11712 for (; s < PL_bufend; s++,to++) {
11713 /* embedded newlines increment the line count */
11714 if (*s == '\n' && !PL_rsfp)
11715 CopLINE_inc(PL_curcop);
11716 /* backslashes can escape the open or closing characters */
11717 if (*s == '\\' && s+1 < PL_bufend) {
11718 if (!keep_quoted &&
11719 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11724 /* allow nested opens and closes */
11725 else if (*s == PL_multi_close && --brackets <= 0)
11727 else if (*s == PL_multi_open)
11729 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11734 /* terminate the copied string and update the sv's end-of-string */
11736 SvCUR_set(sv, to - SvPVX_const(sv));
11739 * this next chunk reads more into the buffer if we're not done yet
11743 break; /* handle case where we are done yet :-) */
11745 #ifndef PERL_STRICT_CR
11746 if (to - SvPVX_const(sv) >= 2) {
11747 if ((to[-2] == '\r' && to[-1] == '\n') ||
11748 (to[-2] == '\n' && to[-1] == '\r'))
11752 SvCUR_set(sv, to - SvPVX_const(sv));
11754 else if (to[-1] == '\r')
11757 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11762 /* if we're out of file, or a read fails, bail and reset the current
11763 line marker so we can report where the unterminated string began
11766 if (PL_madskills) {
11767 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11769 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11771 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11775 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11777 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11783 /* we read a line, so increment our line counter */
11784 CopLINE_inc(PL_curcop);
11786 /* update debugger info */
11787 if (PERLDB_LINE && PL_curstash != PL_debstash)
11788 update_debugger_info(PL_linestr, NULL, 0);
11790 /* having changed the buffer, we must update PL_bufend */
11791 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11792 PL_last_lop = PL_last_uni = NULL;
11795 /* at this point, we have successfully read the delimited string */
11797 if (!PL_encoding || UTF) {
11799 if (PL_madskills) {
11800 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11801 const int len = s - tstart;
11803 sv_catpvn(PL_thisstuff, tstart, len);
11805 PL_thisstuff = newSVpvn(tstart, len);
11806 if (!PL_thisclose && !keep_delims)
11807 PL_thisclose = newSVpvn(s,termlen);
11812 sv_catpvn(sv, s, termlen);
11817 if (PL_madskills) {
11818 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11819 const int len = s - tstart - termlen;
11821 sv_catpvn(PL_thisstuff, tstart, len);
11823 PL_thisstuff = newSVpvn(tstart, len);
11824 if (!PL_thisclose && !keep_delims)
11825 PL_thisclose = newSVpvn(s - termlen,termlen);
11829 if (has_utf8 || PL_encoding)
11832 PL_multi_end = CopLINE(PL_curcop);
11834 /* if we allocated too much space, give some back */
11835 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11836 SvLEN_set(sv, SvCUR(sv) + 1);
11837 SvPV_renew(sv, SvLEN(sv));
11840 /* decide whether this is the first or second quoted string we've read
11853 takes: pointer to position in buffer
11854 returns: pointer to new position in buffer
11855 side-effects: builds ops for the constant in yylval.op
11857 Read a number in any of the formats that Perl accepts:
11859 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11860 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11863 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11865 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11868 If it reads a number without a decimal point or an exponent, it will
11869 try converting the number to an integer and see if it can do so
11870 without loss of precision.
11874 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11877 register const char *s = start; /* current position in buffer */
11878 register char *d; /* destination in temp buffer */
11879 register char *e; /* end of temp buffer */
11880 NV nv; /* number read, as a double */
11881 SV *sv = NULL; /* place to put the converted number */
11882 bool floatit; /* boolean: int or float? */
11883 const char *lastub = NULL; /* position of last underbar */
11884 static char const number_too_long[] = "Number too long";
11886 /* We use the first character to decide what type of number this is */
11890 Perl_croak(aTHX_ "panic: scan_num");
11892 /* if it starts with a 0, it could be an octal number, a decimal in
11893 0.13 disguise, or a hexadecimal number, or a binary number. */
11897 u holds the "number so far"
11898 shift the power of 2 of the base
11899 (hex == 4, octal == 3, binary == 1)
11900 overflowed was the number more than we can hold?
11902 Shift is used when we add a digit. It also serves as an "are
11903 we in octal/hex/binary?" indicator to disallow hex characters
11904 when in octal mode.
11909 bool overflowed = FALSE;
11910 bool just_zero = TRUE; /* just plain 0 or binary number? */
11911 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11912 static const char* const bases[5] =
11913 { "", "binary", "", "octal", "hexadecimal" };
11914 static const char* const Bases[5] =
11915 { "", "Binary", "", "Octal", "Hexadecimal" };
11916 static const char* const maxima[5] =
11918 "0b11111111111111111111111111111111",
11922 const char *base, *Base, *max;
11924 /* check for hex */
11929 } else if (s[1] == 'b') {
11934 /* check for a decimal in disguise */
11935 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11937 /* so it must be octal */
11944 if (ckWARN(WARN_SYNTAX))
11945 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11946 "Misplaced _ in number");
11950 base = bases[shift];
11951 Base = Bases[shift];
11952 max = maxima[shift];
11954 /* read the rest of the number */
11956 /* x is used in the overflow test,
11957 b is the digit we're adding on. */
11962 /* if we don't mention it, we're done */
11966 /* _ are ignored -- but warned about if consecutive */
11968 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11969 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11970 "Misplaced _ in number");
11974 /* 8 and 9 are not octal */
11975 case '8': case '9':
11977 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11981 case '2': case '3': case '4':
11982 case '5': case '6': case '7':
11984 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11987 case '0': case '1':
11988 b = *s++ & 15; /* ASCII digit -> value of digit */
11992 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11993 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11994 /* make sure they said 0x */
11997 b = (*s++ & 7) + 9;
11999 /* Prepare to put the digit we have onto the end
12000 of the number so far. We check for overflows.
12006 x = u << shift; /* make room for the digit */
12008 if ((x >> shift) != u
12009 && !(PL_hints & HINT_NEW_BINARY)) {
12012 if (ckWARN_d(WARN_OVERFLOW))
12013 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12014 "Integer overflow in %s number",
12017 u = x | b; /* add the digit to the end */
12020 n *= nvshift[shift];
12021 /* If an NV has not enough bits in its
12022 * mantissa to represent an UV this summing of
12023 * small low-order numbers is a waste of time
12024 * (because the NV cannot preserve the
12025 * low-order bits anyway): we could just
12026 * remember when did we overflow and in the
12027 * end just multiply n by the right
12035 /* if we get here, we had success: make a scalar value from
12040 /* final misplaced underbar check */
12041 if (s[-1] == '_') {
12042 if (ckWARN(WARN_SYNTAX))
12043 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12048 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
12049 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12050 "%s number > %s non-portable",
12056 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
12057 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12058 "%s number > %s non-portable",
12063 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
12064 sv = new_constant(start, s - start, "integer",
12066 else if (PL_hints & HINT_NEW_BINARY)
12067 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
12072 handle decimal numbers.
12073 we're also sent here when we read a 0 as the first digit
12075 case '1': case '2': case '3': case '4': case '5':
12076 case '6': case '7': case '8': case '9': case '.':
12079 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
12082 /* read next group of digits and _ and copy into d */
12083 while (isDIGIT(*s) || *s == '_') {
12084 /* skip underscores, checking for misplaced ones
12088 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12089 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12090 "Misplaced _ in number");
12094 /* check for end of fixed-length buffer */
12096 Perl_croak(aTHX_ number_too_long);
12097 /* if we're ok, copy the character */
12102 /* final misplaced underbar check */
12103 if (lastub && s == lastub + 1) {
12104 if (ckWARN(WARN_SYNTAX))
12105 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12108 /* read a decimal portion if there is one. avoid
12109 3..5 being interpreted as the number 3. followed
12112 if (*s == '.' && s[1] != '.') {
12117 if (ckWARN(WARN_SYNTAX))
12118 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12119 "Misplaced _ in number");
12123 /* copy, ignoring underbars, until we run out of digits.
12125 for (; isDIGIT(*s) || *s == '_'; s++) {
12126 /* fixed length buffer check */
12128 Perl_croak(aTHX_ number_too_long);
12130 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12131 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12132 "Misplaced _ in number");
12138 /* fractional part ending in underbar? */
12139 if (s[-1] == '_') {
12140 if (ckWARN(WARN_SYNTAX))
12141 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12142 "Misplaced _ in number");
12144 if (*s == '.' && isDIGIT(s[1])) {
12145 /* oops, it's really a v-string, but without the "v" */
12151 /* read exponent part, if present */
12152 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12156 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12157 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12159 /* stray preinitial _ */
12161 if (ckWARN(WARN_SYNTAX))
12162 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12163 "Misplaced _ in number");
12167 /* allow positive or negative exponent */
12168 if (*s == '+' || *s == '-')
12171 /* stray initial _ */
12173 if (ckWARN(WARN_SYNTAX))
12174 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12175 "Misplaced _ in number");
12179 /* read digits of exponent */
12180 while (isDIGIT(*s) || *s == '_') {
12183 Perl_croak(aTHX_ number_too_long);
12187 if (((lastub && s == lastub + 1) ||
12188 (!isDIGIT(s[1]) && s[1] != '_'))
12189 && ckWARN(WARN_SYNTAX))
12190 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12191 "Misplaced _ in number");
12198 /* make an sv from the string */
12202 We try to do an integer conversion first if no characters
12203 indicating "float" have been found.
12208 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12210 if (flags == IS_NUMBER_IN_UV) {
12212 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12215 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12216 if (uv <= (UV) IV_MIN)
12217 sv_setiv(sv, -(IV)uv);
12224 /* terminate the string */
12226 nv = Atof(PL_tokenbuf);
12230 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12231 (PL_hints & HINT_NEW_INTEGER) )
12232 sv = new_constant(PL_tokenbuf,
12235 (floatit ? "float" : "integer"),
12239 /* if it starts with a v, it could be a v-string */
12242 sv = newSV(5); /* preallocate storage space */
12243 s = scan_vstring(s, PL_bufend, sv);
12247 /* make the op for the constant and return */
12250 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12252 lvalp->opval = NULL;
12258 S_scan_formline(pTHX_ register char *s)
12261 register char *eol;
12263 SV * const stuff = newSVpvs("");
12264 bool needargs = FALSE;
12265 bool eofmt = FALSE;
12267 char *tokenstart = s;
12270 if (PL_madskills) {
12271 savewhite = PL_thiswhite;
12276 while (!needargs) {
12279 #ifdef PERL_STRICT_CR
12280 while (SPACE_OR_TAB(*t))
12283 while (SPACE_OR_TAB(*t) || *t == '\r')
12286 if (*t == '\n' || t == PL_bufend) {
12291 if (PL_in_eval && !PL_rsfp) {
12292 eol = (char *) memchr(s,'\n',PL_bufend-s);
12297 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12299 for (t = s; t < eol; t++) {
12300 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12302 goto enough; /* ~~ must be first line in formline */
12304 if (*t == '@' || *t == '^')
12308 sv_catpvn(stuff, s, eol-s);
12309 #ifndef PERL_STRICT_CR
12310 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12311 char *end = SvPVX(stuff) + SvCUR(stuff);
12314 SvCUR_set(stuff, SvCUR(stuff) - 1);
12324 if (PL_madskills) {
12326 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12328 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12331 s = filter_gets(PL_linestr, PL_rsfp, 0);
12333 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12335 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12337 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12338 PL_last_lop = PL_last_uni = NULL;
12347 if (SvCUR(stuff)) {
12350 PL_lex_state = LEX_NORMAL;
12351 start_force(PL_curforce);
12352 NEXTVAL_NEXTTOKE.ival = 0;
12356 PL_lex_state = LEX_FORMLINE;
12358 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12360 else if (PL_encoding)
12361 sv_recode_to_utf8(stuff, PL_encoding);
12363 start_force(PL_curforce);
12364 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12366 start_force(PL_curforce);
12367 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12371 SvREFCNT_dec(stuff);
12373 PL_lex_formbrack = 0;
12377 if (PL_madskills) {
12379 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12381 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12382 PL_thiswhite = savewhite;
12394 PL_cshlen = strlen(PL_cshname);
12396 #if defined(USE_ITHREADS)
12397 PERL_UNUSED_CONTEXT;
12403 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12406 const I32 oldsavestack_ix = PL_savestack_ix;
12407 CV* const outsidecv = PL_compcv;
12410 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12412 SAVEI32(PL_subline);
12413 save_item(PL_subname);
12414 SAVESPTR(PL_compcv);
12416 PL_compcv = (CV*)newSV_type(is_format ? SVt_PVFM : SVt_PVCV);
12417 CvFLAGS(PL_compcv) |= flags;
12419 PL_subline = CopLINE(PL_curcop);
12420 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12421 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12422 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12424 return oldsavestack_ix;
12428 #pragma segment Perl_yylex
12431 Perl_yywarn(pTHX_ const char *s)
12434 PL_in_eval |= EVAL_WARNONLY;
12436 PL_in_eval &= ~EVAL_WARNONLY;
12441 Perl_yyerror(pTHX_ const char *s)
12444 const char *where = NULL;
12445 const char *context = NULL;
12448 int yychar = PL_parser->yychar;
12450 if (!yychar || (yychar == ';' && !PL_rsfp))
12452 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12453 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12454 PL_oldbufptr != PL_bufptr) {
12457 The code below is removed for NetWare because it abends/crashes on NetWare
12458 when the script has error such as not having the closing quotes like:
12459 if ($var eq "value)
12460 Checking of white spaces is anyway done in NetWare code.
12463 while (isSPACE(*PL_oldoldbufptr))
12466 context = PL_oldoldbufptr;
12467 contlen = PL_bufptr - PL_oldoldbufptr;
12469 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12470 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12473 The code below is removed for NetWare because it abends/crashes on NetWare
12474 when the script has error such as not having the closing quotes like:
12475 if ($var eq "value)
12476 Checking of white spaces is anyway done in NetWare code.
12479 while (isSPACE(*PL_oldbufptr))
12482 context = PL_oldbufptr;
12483 contlen = PL_bufptr - PL_oldbufptr;
12485 else if (yychar > 255)
12486 where = "next token ???";
12487 else if (yychar == -2) { /* YYEMPTY */
12488 if (PL_lex_state == LEX_NORMAL ||
12489 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12490 where = "at end of line";
12491 else if (PL_lex_inpat)
12492 where = "within pattern";
12494 where = "within string";
12497 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12499 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12500 else if (isPRINT_LC(yychar))
12501 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12503 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12504 where = SvPVX_const(where_sv);
12506 msg = sv_2mortal(newSVpv(s, 0));
12507 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12508 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12510 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12512 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12513 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12514 Perl_sv_catpvf(aTHX_ msg,
12515 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12516 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12519 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12520 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
12523 if (PL_error_count >= 10) {
12524 if (PL_in_eval && SvCUR(ERRSV))
12525 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12526 SVfARG(ERRSV), OutCopFILE(PL_curcop));
12528 Perl_croak(aTHX_ "%s has too many errors.\n",
12529 OutCopFILE(PL_curcop));
12532 PL_in_my_stash = NULL;
12536 #pragma segment Main
12540 S_swallow_bom(pTHX_ U8 *s)
12543 const STRLEN slen = SvCUR(PL_linestr);
12546 if (s[1] == 0xFE) {
12547 /* UTF-16 little-endian? (or UTF32-LE?) */
12548 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12549 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12550 #ifndef PERL_NO_UTF16_FILTER
12551 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12554 if (PL_bufend > (char*)s) {
12558 filter_add(utf16rev_textfilter, NULL);
12559 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12560 utf16_to_utf8_reversed(s, news,
12561 PL_bufend - (char*)s - 1,
12563 sv_setpvn(PL_linestr, (const char*)news, newlen);
12565 s = (U8*)SvPVX(PL_linestr);
12566 Copy(news, s, newlen, U8);
12570 SvUTF8_on(PL_linestr);
12571 s = (U8*)SvPVX(PL_linestr);
12573 /* FIXME - is this a general bug fix? */
12576 PL_bufend = SvPVX(PL_linestr) + newlen;
12579 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12584 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12585 #ifndef PERL_NO_UTF16_FILTER
12586 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12589 if (PL_bufend > (char *)s) {
12593 filter_add(utf16_textfilter, NULL);
12594 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12595 utf16_to_utf8(s, news,
12596 PL_bufend - (char*)s,
12598 sv_setpvn(PL_linestr, (const char*)news, newlen);
12600 SvUTF8_on(PL_linestr);
12601 s = (U8*)SvPVX(PL_linestr);
12602 PL_bufend = SvPVX(PL_linestr) + newlen;
12605 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12610 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12611 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12612 s += 3; /* UTF-8 */
12618 if (s[2] == 0xFE && s[3] == 0xFF) {
12619 /* UTF-32 big-endian */
12620 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12623 else if (s[2] == 0 && s[3] != 0) {
12626 * are a good indicator of UTF-16BE. */
12627 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12633 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12634 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12635 s += 4; /* UTF-8 */
12641 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12644 * are a good indicator of UTF-16LE. */
12645 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12654 * Restore a source filter.
12658 restore_rsfp(pTHX_ void *f)
12661 PerlIO * const fp = (PerlIO*)f;
12663 if (PL_rsfp == PerlIO_stdin())
12664 PerlIO_clearerr(PL_rsfp);
12665 else if (PL_rsfp && (PL_rsfp != fp))
12666 PerlIO_close(PL_rsfp);
12670 #ifndef PERL_NO_UTF16_FILTER
12672 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12675 const STRLEN old = SvCUR(sv);
12676 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12677 DEBUG_P(PerlIO_printf(Perl_debug_log,
12678 "utf16_textfilter(%p): %d %d (%d)\n",
12679 FPTR2DPTR(void *, utf16_textfilter),
12680 idx, maxlen, (int) count));
12684 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12685 Copy(SvPVX_const(sv), tmps, old, char);
12686 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12687 SvCUR(sv) - old, &newlen);
12688 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12690 DEBUG_P({sv_dump(sv);});
12695 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12698 const STRLEN old = SvCUR(sv);
12699 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12700 DEBUG_P(PerlIO_printf(Perl_debug_log,
12701 "utf16rev_textfilter(%p): %d %d (%d)\n",
12702 FPTR2DPTR(void *, utf16rev_textfilter),
12703 idx, maxlen, (int) count));
12707 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12708 Copy(SvPVX_const(sv), tmps, old, char);
12709 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12710 SvCUR(sv) - old, &newlen);
12711 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12713 DEBUG_P({ sv_dump(sv); });
12719 Returns a pointer to the next character after the parsed
12720 vstring, as well as updating the passed in sv.
12722 Function must be called like
12725 s = scan_vstring(s,e,sv);
12727 where s and e are the start and end of the string.
12728 The sv should already be large enough to store the vstring
12729 passed in, for performance reasons.
12734 Perl_scan_vstring(pTHX_ const char *s, const char *e, SV *sv)
12737 const char *pos = s;
12738 const char *start = s;
12739 if (*pos == 'v') pos++; /* get past 'v' */
12740 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12742 if ( *pos != '.') {
12743 /* this may not be a v-string if followed by => */
12744 const char *next = pos;
12745 while (next < e && isSPACE(*next))
12747 if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
12748 /* return string not v-string */
12749 sv_setpvn(sv,(char *)s,pos-s);
12750 return (char *)pos;
12754 if (!isALPHA(*pos)) {
12755 U8 tmpbuf[UTF8_MAXBYTES+1];
12758 s++; /* get past 'v' */
12760 sv_setpvn(sv, "", 0);
12763 /* this is atoi() that tolerates underscores */
12766 const char *end = pos;
12768 while (--end >= s) {
12770 const UV orev = rev;
12771 rev += (*end - '0') * mult;
12773 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12774 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12775 "Integer overflow in decimal number");
12779 if (rev > 0x7FFFFFFF)
12780 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12782 /* Append native character for the rev point */
12783 tmpend = uvchr_to_utf8(tmpbuf, rev);
12784 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12785 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12787 if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
12793 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12797 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12805 * c-indentation-style: bsd
12806 * c-basic-offset: 4
12807 * indent-tabs-mode: t
12810 * ex: set ts=8 sts=4 sw=4 noet: