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);
5430 PL_nextwhite = PL_thiswhite;
5433 start_force(PL_curforce);
5435 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5436 PL_expect = XOPERATOR;
5439 PL_nextwhite = nextPL_nextwhite;
5440 curmad('X', PL_thistoken);
5441 PL_thistoken = newSVpvs("");
5449 /* If followed by var or block, call it a method (unless sub) */
5451 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5452 PL_last_lop = PL_oldbufptr;
5453 PL_last_lop_op = OP_METHOD;
5457 /* If followed by a bareword, see if it looks like indir obj. */
5460 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5461 && (tmp = intuit_method(s, gv, cv)))
5464 /* Not a method, so call it a subroutine (if defined) */
5467 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5468 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5469 "Ambiguous use of -%s resolved as -&%s()",
5470 PL_tokenbuf, PL_tokenbuf);
5471 /* Check for a constant sub */
5472 if ((sv = gv_const_sv(gv))) {
5474 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5475 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5476 yylval.opval->op_private = 0;
5480 /* Resolve to GV now. */
5481 if (SvTYPE(gv) != SVt_PVGV) {
5482 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5483 assert (SvTYPE(gv) == SVt_PVGV);
5484 /* cv must have been some sort of placeholder, so
5485 now needs replacing with a real code reference. */
5489 op_free(yylval.opval);
5490 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5491 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5492 PL_last_lop = PL_oldbufptr;
5493 PL_last_lop_op = OP_ENTERSUB;
5494 /* Is there a prototype? */
5502 const char *proto = SvPV_const((SV*)cv, protolen);
5505 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
5507 while (*proto == ';')
5509 if (*proto == '&' && *s == '{') {
5510 sv_setpv(PL_subname,
5513 "__ANON__" : "__ANON__::__ANON__"));
5520 PL_nextwhite = PL_thiswhite;
5523 start_force(PL_curforce);
5524 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5527 PL_nextwhite = nextPL_nextwhite;
5528 curmad('X', PL_thistoken);
5529 PL_thistoken = newSVpvs("");
5536 /* Guess harder when madskills require "best effort". */
5537 if (PL_madskills && (!gv || !GvCVu(gv))) {
5538 int probable_sub = 0;
5539 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5541 else if (isALPHA(*s)) {
5545 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5546 if (!keyword(tmpbuf, tmplen, 0))
5549 while (d < PL_bufend && isSPACE(*d))
5551 if (*d == '=' && d[1] == '>')
5556 gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
5557 op_free(yylval.opval);
5558 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5559 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5560 PL_last_lop = PL_oldbufptr;
5561 PL_last_lop_op = OP_ENTERSUB;
5562 PL_nextwhite = PL_thiswhite;
5564 start_force(PL_curforce);
5565 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5567 PL_nextwhite = nextPL_nextwhite;
5568 curmad('X', PL_thistoken);
5569 PL_thistoken = newSVpvs("");
5574 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5581 /* Call it a bare word */
5583 if (PL_hints & HINT_STRICT_SUBS)
5584 yylval.opval->op_private |= OPpCONST_STRICT;
5587 if (lastchar != '-') {
5588 if (ckWARN(WARN_RESERVED)) {
5592 if (!*d && !gv_stashpv(PL_tokenbuf, 0))
5593 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5600 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5601 && ckWARN_d(WARN_AMBIGUOUS)) {
5602 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5603 "Operator or semicolon missing before %c%s",
5604 lastchar, PL_tokenbuf);
5605 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5606 "Ambiguous use of %c resolved as operator %c",
5607 lastchar, lastchar);
5613 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5614 newSVpv(CopFILE(PL_curcop),0));
5618 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5619 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5622 case KEY___PACKAGE__:
5623 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5625 ? newSVhek(HvNAME_HEK(PL_curstash))
5632 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5633 const char *pname = "main";
5634 if (PL_tokenbuf[2] == 'D')
5635 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5636 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5640 GvIOp(gv) = newIO();
5641 IoIFP(GvIOp(gv)) = PL_rsfp;
5642 #if defined(HAS_FCNTL) && defined(F_SETFD)
5644 const int fd = PerlIO_fileno(PL_rsfp);
5645 fcntl(fd,F_SETFD,fd >= 3);
5648 /* Mark this internal pseudo-handle as clean */
5649 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5651 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5652 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5653 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5655 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5656 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5657 /* if the script was opened in binmode, we need to revert
5658 * it to text mode for compatibility; but only iff it has CRs
5659 * XXX this is a questionable hack at best. */
5660 if (PL_bufend-PL_bufptr > 2
5661 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5664 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5665 loc = PerlIO_tell(PL_rsfp);
5666 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5669 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5671 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5672 #endif /* NETWARE */
5673 #ifdef PERLIO_IS_STDIO /* really? */
5674 # if defined(__BORLANDC__)
5675 /* XXX see note in do_binmode() */
5676 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5680 PerlIO_seek(PL_rsfp, loc, 0);
5684 #ifdef PERLIO_LAYERS
5687 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5688 else if (PL_encoding) {
5695 XPUSHs(PL_encoding);
5697 call_method("name", G_SCALAR);
5701 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5702 Perl_form(aTHX_ ":encoding(%"SVf")",
5711 if (PL_realtokenstart >= 0) {
5712 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5714 PL_endwhite = newSVpvs("");
5715 sv_catsv(PL_endwhite, PL_thiswhite);
5717 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5718 PL_realtokenstart = -1;
5720 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5721 SvCUR(PL_endwhite))) != Nullch) ;
5736 if (PL_expect == XSTATE) {
5743 if (*s == ':' && s[1] == ':') {
5746 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5747 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5748 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5751 else if (tmp == KEY_require || tmp == KEY_do)
5752 /* that's a way to remember we saw "CORE::" */
5765 LOP(OP_ACCEPT,XTERM);
5771 LOP(OP_ATAN2,XTERM);
5777 LOP(OP_BINMODE,XTERM);
5780 LOP(OP_BLESS,XTERM);
5789 /* When 'use switch' is in effect, continue has a dual
5790 life as a control operator. */
5792 if (!FEATURE_IS_ENABLED("switch"))
5795 /* We have to disambiguate the two senses of
5796 "continue". If the next token is a '{' then
5797 treat it as the start of a continue block;
5798 otherwise treat it as a control operator.
5810 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5827 if (!PL_cryptseen) {
5828 PL_cryptseen = TRUE;
5832 LOP(OP_CRYPT,XTERM);
5835 LOP(OP_CHMOD,XTERM);
5838 LOP(OP_CHOWN,XTERM);
5841 LOP(OP_CONNECT,XTERM);
5860 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5861 if (orig_keyword == KEY_do) {
5870 PL_hints |= HINT_BLOCK_SCOPE;
5880 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5881 LOP(OP_DBMOPEN,XTERM);
5887 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5894 yylval.ival = CopLINE(PL_curcop);
5910 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5911 UNIBRACK(OP_ENTEREVAL);
5929 case KEY_endhostent:
5935 case KEY_endservent:
5938 case KEY_endprotoent:
5949 yylval.ival = CopLINE(PL_curcop);
5951 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5954 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5957 if ((PL_bufend - p) >= 3 &&
5958 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5960 else if ((PL_bufend - p) >= 4 &&
5961 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5964 if (isIDFIRST_lazy_if(p,UTF)) {
5965 p = scan_ident(p, PL_bufend,
5966 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5970 Perl_croak(aTHX_ "Missing $ on loop variable");
5972 s = SvPVX(PL_linestr) + soff;
5978 LOP(OP_FORMLINE,XTERM);
5984 LOP(OP_FCNTL,XTERM);
5990 LOP(OP_FLOCK,XTERM);
5999 LOP(OP_GREPSTART, XREF);
6002 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6017 case KEY_getpriority:
6018 LOP(OP_GETPRIORITY,XTERM);
6020 case KEY_getprotobyname:
6023 case KEY_getprotobynumber:
6024 LOP(OP_GPBYNUMBER,XTERM);
6026 case KEY_getprotoent:
6038 case KEY_getpeername:
6039 UNI(OP_GETPEERNAME);
6041 case KEY_gethostbyname:
6044 case KEY_gethostbyaddr:
6045 LOP(OP_GHBYADDR,XTERM);
6047 case KEY_gethostent:
6050 case KEY_getnetbyname:
6053 case KEY_getnetbyaddr:
6054 LOP(OP_GNBYADDR,XTERM);
6059 case KEY_getservbyname:
6060 LOP(OP_GSBYNAME,XTERM);
6062 case KEY_getservbyport:
6063 LOP(OP_GSBYPORT,XTERM);
6065 case KEY_getservent:
6068 case KEY_getsockname:
6069 UNI(OP_GETSOCKNAME);
6071 case KEY_getsockopt:
6072 LOP(OP_GSOCKOPT,XTERM);
6087 yylval.ival = CopLINE(PL_curcop);
6098 yylval.ival = CopLINE(PL_curcop);
6102 LOP(OP_INDEX,XTERM);
6108 LOP(OP_IOCTL,XTERM);
6120 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6152 LOP(OP_LISTEN,XTERM);
6161 s = scan_pat(s,OP_MATCH);
6162 TERM(sublex_start());
6165 LOP(OP_MAPSTART, XREF);
6168 LOP(OP_MKDIR,XTERM);
6171 LOP(OP_MSGCTL,XTERM);
6174 LOP(OP_MSGGET,XTERM);
6177 LOP(OP_MSGRCV,XTERM);
6180 LOP(OP_MSGSND,XTERM);
6187 if (isIDFIRST_lazy_if(s,UTF)) {
6191 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6192 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6194 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6195 if (!PL_in_my_stash) {
6198 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6202 if (PL_madskills) { /* just add type to declarator token */
6203 sv_catsv(PL_thistoken, PL_nextwhite);
6205 sv_catpvn(PL_thistoken, start, s - start);
6213 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6220 s = tokenize_use(0, s);
6224 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6231 if (isIDFIRST_lazy_if(s,UTF)) {
6233 for (d = s; isALNUM_lazy_if(d,UTF);)
6235 for (t=d; isSPACE(*t);)
6237 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6239 && !(t[0] == '=' && t[1] == '>')
6241 int parms_len = (int)(d-s);
6242 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6243 "Precedence problem: open %.*s should be open(%.*s)",
6244 parms_len, s, parms_len, s);
6250 yylval.ival = OP_OR;
6260 LOP(OP_OPEN_DIR,XTERM);
6263 checkcomma(s,PL_tokenbuf,"filehandle");
6267 checkcomma(s,PL_tokenbuf,"filehandle");
6286 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6290 LOP(OP_PIPE_OP,XTERM);
6293 s = scan_str(s,!!PL_madskills,FALSE);
6296 yylval.ival = OP_CONST;
6297 TERM(sublex_start());
6303 s = scan_str(s,!!PL_madskills,FALSE);
6306 PL_expect = XOPERATOR;
6308 if (SvCUR(PL_lex_stuff)) {
6311 d = SvPV_force(PL_lex_stuff, len);
6313 for (; isSPACE(*d) && len; --len, ++d)
6318 if (!warned && ckWARN(WARN_QW)) {
6319 for (; !isSPACE(*d) && len; --len, ++d) {
6321 Perl_warner(aTHX_ packWARN(WARN_QW),
6322 "Possible attempt to separate words with commas");
6325 else if (*d == '#') {
6326 Perl_warner(aTHX_ packWARN(WARN_QW),
6327 "Possible attempt to put comments in qw() list");
6333 for (; !isSPACE(*d) && len; --len, ++d)
6336 sv = newSVpvn(b, d-b);
6337 if (DO_UTF8(PL_lex_stuff))
6339 words = append_elem(OP_LIST, words,
6340 newSVOP(OP_CONST, 0, tokeq(sv)));
6344 start_force(PL_curforce);
6345 NEXTVAL_NEXTTOKE.opval = words;
6350 SvREFCNT_dec(PL_lex_stuff);
6351 PL_lex_stuff = NULL;
6357 s = scan_str(s,!!PL_madskills,FALSE);
6360 yylval.ival = OP_STRINGIFY;
6361 if (SvIVX(PL_lex_stuff) == '\'')
6362 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6363 TERM(sublex_start());
6366 s = scan_pat(s,OP_QR);
6367 TERM(sublex_start());
6370 s = scan_str(s,!!PL_madskills,FALSE);
6373 readpipe_override();
6374 TERM(sublex_start());
6382 s = force_version(s, FALSE);
6384 else if (*s != 'v' || !isDIGIT(s[1])
6385 || (s = force_version(s, TRUE), *s == 'v'))
6387 *PL_tokenbuf = '\0';
6388 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6389 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6390 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
6392 yyerror("<> should be quotes");
6394 if (orig_keyword == KEY_require) {
6402 PL_last_uni = PL_oldbufptr;
6403 PL_last_lop_op = OP_REQUIRE;
6405 return REPORT( (int)REQUIRE );
6411 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6415 LOP(OP_RENAME,XTERM);
6424 LOP(OP_RINDEX,XTERM);
6434 UNIDOR(OP_READLINE);
6438 UNIDOR(OP_BACKTICK);
6447 LOP(OP_REVERSE,XTERM);
6450 UNIDOR(OP_READLINK);
6458 TERM(sublex_start());
6460 TOKEN(1); /* force error */
6463 checkcomma(s,PL_tokenbuf,"filehandle");
6473 LOP(OP_SELECT,XTERM);
6479 LOP(OP_SEMCTL,XTERM);
6482 LOP(OP_SEMGET,XTERM);
6485 LOP(OP_SEMOP,XTERM);
6491 LOP(OP_SETPGRP,XTERM);
6493 case KEY_setpriority:
6494 LOP(OP_SETPRIORITY,XTERM);
6496 case KEY_sethostent:
6502 case KEY_setservent:
6505 case KEY_setprotoent:
6515 LOP(OP_SEEKDIR,XTERM);
6517 case KEY_setsockopt:
6518 LOP(OP_SSOCKOPT,XTERM);
6524 LOP(OP_SHMCTL,XTERM);
6527 LOP(OP_SHMGET,XTERM);
6530 LOP(OP_SHMREAD,XTERM);
6533 LOP(OP_SHMWRITE,XTERM);
6536 LOP(OP_SHUTDOWN,XTERM);
6545 LOP(OP_SOCKET,XTERM);
6547 case KEY_socketpair:
6548 LOP(OP_SOCKPAIR,XTERM);
6551 checkcomma(s,PL_tokenbuf,"subroutine name");
6553 if (*s == ';' || *s == ')') /* probably a close */
6554 Perl_croak(aTHX_ "sort is now a reserved word");
6556 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6560 LOP(OP_SPLIT,XTERM);
6563 LOP(OP_SPRINTF,XTERM);
6566 LOP(OP_SPLICE,XTERM);
6581 LOP(OP_SUBSTR,XTERM);
6587 char tmpbuf[sizeof PL_tokenbuf];
6588 SSize_t tboffset = 0;
6589 expectation attrful;
6590 bool have_name, have_proto;
6591 const int key = tmp;
6596 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6597 SV *subtoken = newSVpvn(tstart, s - tstart);
6601 s = SKIPSPACE2(s,tmpwhite);
6606 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6607 (*s == ':' && s[1] == ':'))
6614 attrful = XATTRBLOCK;
6615 /* remember buffer pos'n for later force_word */
6616 tboffset = s - PL_oldbufptr;
6617 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6620 nametoke = newSVpvn(s, d - s);
6622 if (memchr(tmpbuf, ':', len))
6623 sv_setpvn(PL_subname, tmpbuf, len);
6625 sv_setsv(PL_subname,PL_curstname);
6626 sv_catpvs(PL_subname,"::");
6627 sv_catpvn(PL_subname,tmpbuf,len);
6634 CURMAD('X', nametoke);
6635 CURMAD('_', tmpwhite);
6636 (void) force_word(PL_oldbufptr + tboffset, WORD,
6639 s = SKIPSPACE2(d,tmpwhite);
6646 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6647 PL_expect = XTERMBLOCK;
6648 attrful = XATTRTERM;
6649 sv_setpvn(PL_subname,"?",1);
6653 if (key == KEY_format) {
6655 PL_lex_formbrack = PL_lex_brackets + 1;
6657 PL_thistoken = subtoken;
6661 (void) force_word(PL_oldbufptr + tboffset, WORD,
6667 /* Look for a prototype */
6670 bool bad_proto = FALSE;
6671 const bool warnsyntax = ckWARN(WARN_SYNTAX);
6673 s = scan_str(s,!!PL_madskills,FALSE);
6675 Perl_croak(aTHX_ "Prototype not terminated");
6676 /* strip spaces and check for bad characters */
6677 d = SvPVX(PL_lex_stuff);
6679 for (p = d; *p; ++p) {
6682 if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
6688 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6689 "Illegal character in prototype for %"SVf" : %s",
6690 SVfARG(PL_subname), d);
6691 SvCUR_set(PL_lex_stuff, tmp);
6696 CURMAD('q', PL_thisopen);
6697 CURMAD('_', tmpwhite);
6698 CURMAD('=', PL_thisstuff);
6699 CURMAD('Q', PL_thisclose);
6700 NEXTVAL_NEXTTOKE.opval =
6701 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6702 PL_lex_stuff = Nullsv;
6705 s = SKIPSPACE2(s,tmpwhite);
6713 if (*s == ':' && s[1] != ':')
6714 PL_expect = attrful;
6715 else if (*s != '{' && key == KEY_sub) {
6717 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6719 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
6726 curmad('^', newSVpvs(""));
6727 CURMAD('_', tmpwhite);
6731 PL_thistoken = subtoken;
6734 NEXTVAL_NEXTTOKE.opval =
6735 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6736 PL_lex_stuff = NULL;
6741 sv_setpv(PL_subname,
6743 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
6747 (void) force_word(PL_oldbufptr + tboffset, WORD,
6757 LOP(OP_SYSTEM,XREF);
6760 LOP(OP_SYMLINK,XTERM);
6763 LOP(OP_SYSCALL,XTERM);
6766 LOP(OP_SYSOPEN,XTERM);
6769 LOP(OP_SYSSEEK,XTERM);
6772 LOP(OP_SYSREAD,XTERM);
6775 LOP(OP_SYSWRITE,XTERM);
6779 TERM(sublex_start());
6800 LOP(OP_TRUNCATE,XTERM);
6812 yylval.ival = CopLINE(PL_curcop);
6816 yylval.ival = CopLINE(PL_curcop);
6820 LOP(OP_UNLINK,XTERM);
6826 LOP(OP_UNPACK,XTERM);
6829 LOP(OP_UTIME,XTERM);
6835 LOP(OP_UNSHIFT,XTERM);
6838 s = tokenize_use(1, s);
6848 yylval.ival = CopLINE(PL_curcop);
6852 yylval.ival = CopLINE(PL_curcop);
6856 PL_hints |= HINT_BLOCK_SCOPE;
6863 LOP(OP_WAITPID,XTERM);
6872 ctl_l[0] = toCTRL('L');
6874 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6877 /* Make sure $^L is defined */
6878 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6883 if (PL_expect == XOPERATOR)
6889 yylval.ival = OP_XOR;
6894 TERM(sublex_start());
6899 #pragma segment Main
6903 S_pending_ident(pTHX)
6908 /* pit holds the identifier we read and pending_ident is reset */
6909 char pit = PL_pending_ident;
6910 PL_pending_ident = 0;
6912 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6913 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6914 "### Pending identifier '%s'\n", PL_tokenbuf); });
6916 /* if we're in a my(), we can't allow dynamics here.
6917 $foo'bar has already been turned into $foo::bar, so
6918 just check for colons.
6920 if it's a legal name, the OP is a PADANY.
6923 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6924 if (strchr(PL_tokenbuf,':'))
6925 yyerror(Perl_form(aTHX_ "No package name allowed for "
6926 "variable %s in \"our\"",
6928 tmp = allocmy(PL_tokenbuf);
6931 if (strchr(PL_tokenbuf,':'))
6932 yyerror(Perl_form(aTHX_ PL_no_myglob,
6933 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6935 yylval.opval = newOP(OP_PADANY, 0);
6936 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6942 build the ops for accesses to a my() variable.
6944 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6945 then used in a comparison. This catches most, but not
6946 all cases. For instance, it catches
6947 sort { my($a); $a <=> $b }
6949 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6950 (although why you'd do that is anyone's guess).
6953 if (!strchr(PL_tokenbuf,':')) {
6955 tmp = pad_findmy(PL_tokenbuf);
6956 if (tmp != NOT_IN_PAD) {
6957 /* might be an "our" variable" */
6958 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6959 /* build ops for a bareword */
6960 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6961 HEK * const stashname = HvNAME_HEK(stash);
6962 SV * const sym = newSVhek(stashname);
6963 sv_catpvs(sym, "::");
6964 sv_catpv(sym, PL_tokenbuf+1);
6965 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6966 yylval.opval->op_private = OPpCONST_ENTERED;
6969 ? (GV_ADDMULTI | GV_ADDINEVAL)
6972 ((PL_tokenbuf[0] == '$') ? SVt_PV
6973 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6978 /* if it's a sort block and they're naming $a or $b */
6979 if (PL_last_lop_op == OP_SORT &&
6980 PL_tokenbuf[0] == '$' &&
6981 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6984 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6985 d < PL_bufend && *d != '\n';
6988 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6989 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6995 yylval.opval = newOP(OP_PADANY, 0);
6996 yylval.opval->op_targ = tmp;
7002 Whine if they've said @foo in a doublequoted string,
7003 and @foo isn't a variable we can find in the symbol
7006 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
7007 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
7008 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
7009 && ckWARN(WARN_AMBIGUOUS)
7010 /* DO NOT warn for @- and @+ */
7011 && !( PL_tokenbuf[2] == '\0' &&
7012 ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
7015 /* Downgraded from fatal to warning 20000522 mjd */
7016 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
7017 "Possible unintended interpolation of %s in string",
7022 /* build ops for a bareword */
7023 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
7024 yylval.opval->op_private = OPpCONST_ENTERED;
7027 /* If the identifier refers to a stash, don't autovivify it.
7028 * Change 24660 had the side effect of causing symbol table
7029 * hashes to always be defined, even if they were freshly
7030 * created and the only reference in the entire program was
7031 * the single statement with the defined %foo::bar:: test.
7032 * It appears that all code in the wild doing this actually
7033 * wants to know whether sub-packages have been loaded, so
7034 * by avoiding auto-vivifying symbol tables, we ensure that
7035 * defined %foo::bar:: continues to be false, and the existing
7036 * tests still give the expected answers, even though what
7037 * they're actually testing has now changed subtly.
7039 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
7041 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
7042 ((PL_tokenbuf[0] == '$') ? SVt_PV
7043 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7049 * The following code was generated by perl_keyword.pl.
7053 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
7058 case 1: /* 5 tokens of length 1 */
7090 case 2: /* 18 tokens of length 2 */
7236 case 3: /* 29 tokens of length 3 */
7240 if (name[1] == 'N' &&
7303 if (name[1] == 'i' &&
7325 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7343 if (name[1] == 'o' &&
7352 if (name[1] == 'e' &&
7361 if (name[1] == 'n' &&
7370 if (name[1] == 'o' &&
7379 if (name[1] == 'a' &&
7388 if (name[1] == 'o' &&
7450 if (name[1] == 'e' &&
7464 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
7490 if (name[1] == 'i' &&
7499 if (name[1] == 's' &&
7508 if (name[1] == 'e' &&
7517 if (name[1] == 'o' &&
7529 case 4: /* 41 tokens of length 4 */
7533 if (name[1] == 'O' &&
7543 if (name[1] == 'N' &&
7553 if (name[1] == 'i' &&
7563 if (name[1] == 'h' &&
7573 if (name[1] == 'u' &&
7586 if (name[2] == 'c' &&
7595 if (name[2] == 's' &&
7604 if (name[2] == 'a' &&
7640 if (name[1] == 'o' &&
7653 if (name[2] == 't' &&
7662 if (name[2] == 'o' &&
7671 if (name[2] == 't' &&
7680 if (name[2] == 'e' &&
7693 if (name[1] == 'o' &&
7706 if (name[2] == 'y' &&
7715 if (name[2] == 'l' &&
7731 if (name[2] == 's' &&
7740 if (name[2] == 'n' &&
7749 if (name[2] == 'c' &&
7762 if (name[1] == 'e' &&
7772 if (name[1] == 'p' &&
7785 if (name[2] == 'c' &&
7794 if (name[2] == 'p' &&
7803 if (name[2] == 's' &&
7819 if (name[2] == 'n' &&
7889 if (name[2] == 'r' &&
7898 if (name[2] == 'r' &&
7907 if (name[2] == 'a' &&
7923 if (name[2] == 'l' &&
7985 if (name[2] == 'e' &&
7988 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
8001 case 5: /* 39 tokens of length 5 */
8005 if (name[1] == 'E' &&
8016 if (name[1] == 'H' &&
8030 if (name[2] == 'a' &&
8040 if (name[2] == 'a' &&
8057 if (name[2] == 'e' &&
8067 if (name[2] == 'e' &&
8071 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
8087 if (name[3] == 'i' &&
8096 if (name[3] == 'o' &&
8132 if (name[2] == 'o' &&
8142 if (name[2] == 'y' &&
8156 if (name[1] == 'l' &&
8170 if (name[2] == 'n' &&
8180 if (name[2] == 'o' &&
8194 if (name[1] == 'i' &&
8199 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8208 if (name[2] == 'd' &&
8218 if (name[2] == 'c' &&
8235 if (name[2] == 'c' &&
8245 if (name[2] == 't' &&
8259 if (name[1] == 'k' &&
8270 if (name[1] == 'r' &&
8284 if (name[2] == 's' &&
8294 if (name[2] == 'd' &&
8311 if (name[2] == 'm' &&
8321 if (name[2] == 'i' &&
8331 if (name[2] == 'e' &&
8341 if (name[2] == 'l' &&
8351 if (name[2] == 'a' &&
8364 if (name[3] == 't' &&
8367 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8373 if (name[3] == 'd' &&
8390 if (name[1] == 'i' &&
8404 if (name[2] == 'a' &&
8417 if (name[3] == 'e' &&
8452 if (name[2] == 'i' &&
8469 if (name[2] == 'i' &&
8479 if (name[2] == 'i' &&
8496 case 6: /* 33 tokens of length 6 */
8500 if (name[1] == 'c' &&
8515 if (name[2] == 'l' &&
8526 if (name[2] == 'r' &&
8541 if (name[1] == 'e' &&
8556 if (name[2] == 's' &&
8561 if(ckWARN_d(WARN_SYNTAX))
8562 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8568 if (name[2] == 'i' &&
8586 if (name[2] == 'l' &&
8597 if (name[2] == 'r' &&
8612 if (name[1] == 'm' &&
8627 if (name[2] == 'n' &&
8638 if (name[2] == 's' &&
8653 if (name[1] == 's' &&
8659 if (name[4] == 't' &&
8668 if (name[4] == 'e' &&
8677 if (name[4] == 'c' &&
8686 if (name[4] == 'n' &&
8702 if (name[1] == 'r' &&
8720 if (name[3] == 'a' &&
8730 if (name[3] == 'u' &&
8744 if (name[2] == 'n' &&
8762 if (name[2] == 'a' &&
8776 if (name[3] == 'e' &&
8789 if (name[4] == 't' &&
8798 if (name[4] == 'e' &&
8820 if (name[4] == 't' &&
8829 if (name[4] == 'e' &&
8845 if (name[2] == 'c' &&
8856 if (name[2] == 'l' &&
8867 if (name[2] == 'b' &&
8878 if (name[2] == 's' &&
8901 if (name[4] == 's' &&
8910 if (name[4] == 'n' &&
8923 if (name[3] == 'a' &&
8940 if (name[1] == 'a' &&
8955 case 7: /* 29 tokens of length 7 */
8959 if (name[1] == 'E' &&
8972 if (name[1] == '_' &&
8985 if (name[1] == 'i' &&
8992 return -KEY_binmode;
8998 if (name[1] == 'o' &&
9005 return -KEY_connect;
9014 if (name[2] == 'm' &&
9020 return -KEY_dbmopen;
9031 if (name[4] == 'u' &&
9035 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
9041 if (name[4] == 'n' &&
9062 if (name[1] == 'o' &&
9075 if (name[1] == 'e' &&
9082 if (name[5] == 'r' &&
9085 return -KEY_getpgrp;
9091 if (name[5] == 'i' &&
9094 return -KEY_getppid;
9107 if (name[1] == 'c' &&
9114 return -KEY_lcfirst;
9120 if (name[1] == 'p' &&
9127 return -KEY_opendir;
9133 if (name[1] == 'a' &&
9151 if (name[3] == 'd' &&
9156 return -KEY_readdir;
9162 if (name[3] == 'u' &&
9173 if (name[3] == 'e' &&
9178 return -KEY_reverse;
9197 if (name[3] == 'k' &&
9202 return -KEY_seekdir;
9208 if (name[3] == 'p' &&
9213 return -KEY_setpgrp;
9223 if (name[2] == 'm' &&
9229 return -KEY_shmread;
9235 if (name[2] == 'r' &&
9241 return -KEY_sprintf;
9250 if (name[3] == 'l' &&
9255 return -KEY_symlink;
9264 if (name[4] == 'a' &&
9268 return -KEY_syscall;
9274 if (name[4] == 'p' &&
9278 return -KEY_sysopen;
9284 if (name[4] == 'e' &&
9288 return -KEY_sysread;
9294 if (name[4] == 'e' &&
9298 return -KEY_sysseek;
9316 if (name[1] == 'e' &&
9323 return -KEY_telldir;
9332 if (name[2] == 'f' &&
9338 return -KEY_ucfirst;
9344 if (name[2] == 's' &&
9350 return -KEY_unshift;
9360 if (name[1] == 'a' &&
9367 return -KEY_waitpid;
9376 case 8: /* 26 tokens of length 8 */
9380 if (name[1] == 'U' &&
9388 return KEY_AUTOLOAD;
9399 if (name[3] == 'A' &&
9405 return KEY___DATA__;
9411 if (name[3] == 'I' &&
9417 return -KEY___FILE__;
9423 if (name[3] == 'I' &&
9429 return -KEY___LINE__;
9445 if (name[2] == 'o' &&
9452 return -KEY_closedir;
9458 if (name[2] == 'n' &&
9465 return -KEY_continue;
9475 if (name[1] == 'b' &&
9483 return -KEY_dbmclose;
9489 if (name[1] == 'n' &&
9495 if (name[4] == 'r' &&
9500 return -KEY_endgrent;
9506 if (name[4] == 'w' &&
9511 return -KEY_endpwent;
9524 if (name[1] == 'o' &&
9532 return -KEY_formline;
9538 if (name[1] == 'e' &&
9549 if (name[6] == 'n' &&
9552 return -KEY_getgrent;
9558 if (name[6] == 'i' &&
9561 return -KEY_getgrgid;
9567 if (name[6] == 'a' &&
9570 return -KEY_getgrnam;
9583 if (name[4] == 'o' &&
9588 return -KEY_getlogin;
9599 if (name[6] == 'n' &&
9602 return -KEY_getpwent;
9608 if (name[6] == 'a' &&
9611 return -KEY_getpwnam;
9617 if (name[6] == 'i' &&
9620 return -KEY_getpwuid;
9640 if (name[1] == 'e' &&
9647 if (name[5] == 'i' &&
9654 return -KEY_readline;
9659 return -KEY_readlink;
9670 if (name[5] == 'i' &&
9674 return -KEY_readpipe;
9695 if (name[4] == 'r' &&
9700 return -KEY_setgrent;
9706 if (name[4] == 'w' &&
9711 return -KEY_setpwent;
9727 if (name[3] == 'w' &&
9733 return -KEY_shmwrite;
9739 if (name[3] == 't' &&
9745 return -KEY_shutdown;
9755 if (name[2] == 's' &&
9762 return -KEY_syswrite;
9772 if (name[1] == 'r' &&
9780 return -KEY_truncate;
9789 case 9: /* 9 tokens of length 9 */
9793 if (name[1] == 'N' &&
9802 return KEY_UNITCHECK;
9808 if (name[1] == 'n' &&
9817 return -KEY_endnetent;
9823 if (name[1] == 'e' &&
9832 return -KEY_getnetent;
9838 if (name[1] == 'o' &&
9847 return -KEY_localtime;
9853 if (name[1] == 'r' &&
9862 return KEY_prototype;
9868 if (name[1] == 'u' &&
9877 return -KEY_quotemeta;
9883 if (name[1] == 'e' &&
9892 return -KEY_rewinddir;
9898 if (name[1] == 'e' &&
9907 return -KEY_setnetent;
9913 if (name[1] == 'a' &&
9922 return -KEY_wantarray;
9931 case 10: /* 9 tokens of length 10 */
9935 if (name[1] == 'n' &&
9941 if (name[4] == 'o' &&
9948 return -KEY_endhostent;
9954 if (name[4] == 'e' &&
9961 return -KEY_endservent;
9974 if (name[1] == 'e' &&
9980 if (name[4] == 'o' &&
9987 return -KEY_gethostent;
9996 if (name[5] == 'r' &&
10002 return -KEY_getservent;
10008 if (name[5] == 'c' &&
10014 return -KEY_getsockopt;
10034 if (name[2] == 't')
10039 if (name[4] == 'o' &&
10046 return -KEY_sethostent;
10055 if (name[5] == 'r' &&
10061 return -KEY_setservent;
10067 if (name[5] == 'c' &&
10073 return -KEY_setsockopt;
10090 if (name[2] == 'c' &&
10099 return -KEY_socketpair;
10112 case 11: /* 8 tokens of length 11 */
10116 if (name[1] == '_' &&
10126 { /* __PACKAGE__ */
10127 return -KEY___PACKAGE__;
10133 if (name[1] == 'n' &&
10143 { /* endprotoent */
10144 return -KEY_endprotoent;
10150 if (name[1] == 'e' &&
10159 if (name[5] == 'e' &&
10165 { /* getpeername */
10166 return -KEY_getpeername;
10175 if (name[6] == 'o' &&
10180 { /* getpriority */
10181 return -KEY_getpriority;
10187 if (name[6] == 't' &&
10192 { /* getprotoent */
10193 return -KEY_getprotoent;
10207 if (name[4] == 'o' &&
10214 { /* getsockname */
10215 return -KEY_getsockname;
10228 if (name[1] == 'e' &&
10236 if (name[6] == 'o' &&
10241 { /* setpriority */
10242 return -KEY_setpriority;
10248 if (name[6] == 't' &&
10253 { /* setprotoent */
10254 return -KEY_setprotoent;
10270 case 12: /* 2 tokens of length 12 */
10271 if (name[0] == 'g' &&
10283 if (name[9] == 'd' &&
10286 { /* getnetbyaddr */
10287 return -KEY_getnetbyaddr;
10293 if (name[9] == 'a' &&
10296 { /* getnetbyname */
10297 return -KEY_getnetbyname;
10309 case 13: /* 4 tokens of length 13 */
10310 if (name[0] == 'g' &&
10317 if (name[4] == 'o' &&
10326 if (name[10] == 'd' &&
10329 { /* gethostbyaddr */
10330 return -KEY_gethostbyaddr;
10336 if (name[10] == 'a' &&
10339 { /* gethostbyname */
10340 return -KEY_gethostbyname;
10353 if (name[4] == 'e' &&
10362 if (name[10] == 'a' &&
10365 { /* getservbyname */
10366 return -KEY_getservbyname;
10372 if (name[10] == 'o' &&
10375 { /* getservbyport */
10376 return -KEY_getservbyport;
10395 case 14: /* 1 tokens of length 14 */
10396 if (name[0] == 'g' &&
10410 { /* getprotobyname */
10411 return -KEY_getprotobyname;
10416 case 16: /* 1 tokens of length 16 */
10417 if (name[0] == 'g' &&
10433 { /* getprotobynumber */
10434 return -KEY_getprotobynumber;
10448 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10452 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10453 if (ckWARN(WARN_SYNTAX)) {
10456 for (w = s+2; *w && level; w++) {
10459 else if (*w == ')')
10462 while (isSPACE(*w))
10464 /* the list of chars below is for end of statements or
10465 * block / parens, boolean operators (&&, ||, //) and branch
10466 * constructs (or, and, if, until, unless, while, err, for).
10467 * Not a very solid hack... */
10468 if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
10469 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10470 "%s (...) interpreted as function",name);
10473 while (s < PL_bufend && isSPACE(*s))
10477 while (s < PL_bufend && isSPACE(*s))
10479 if (isIDFIRST_lazy_if(s,UTF)) {
10480 const char * const w = s++;
10481 while (isALNUM_lazy_if(s,UTF))
10483 while (s < PL_bufend && isSPACE(*s))
10487 if (keyword(w, s - w, 0))
10490 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10491 if (gv && GvCVu(gv))
10493 Perl_croak(aTHX_ "No comma allowed after %s", what);
10498 /* Either returns sv, or mortalizes sv and returns a new SV*.
10499 Best used as sv=new_constant(..., sv, ...).
10500 If s, pv are NULL, calls subroutine with one argument,
10501 and type is used with error messages only. */
10504 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10508 HV * const table = GvHV(PL_hintgv); /* ^H */
10512 const char *why1 = "", *why2 = "", *why3 = "";
10514 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10517 why2 = (const char *)
10518 (strEQ(key,"charnames")
10519 ? "(possibly a missing \"use charnames ...\")"
10521 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10522 (type ? type: "undef"), why2);
10524 /* This is convoluted and evil ("goto considered harmful")
10525 * but I do not understand the intricacies of all the different
10526 * failure modes of %^H in here. The goal here is to make
10527 * the most probable error message user-friendly. --jhi */
10532 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10533 (type ? type: "undef"), why1, why2, why3);
10535 yyerror(SvPVX_const(msg));
10539 cvp = hv_fetch(table, key, strlen(key), FALSE);
10540 if (!cvp || !SvOK(*cvp)) {
10543 why3 = "} is not defined";
10546 sv_2mortal(sv); /* Parent created it permanently */
10549 pv = sv_2mortal(newSVpvn(s, len));
10551 typesv = sv_2mortal(newSVpv(type, 0));
10553 typesv = &PL_sv_undef;
10555 PUSHSTACKi(PERLSI_OVERLOAD);
10567 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10571 /* Check the eval first */
10572 if (!PL_in_eval && SvTRUE(ERRSV)) {
10573 sv_catpvs(ERRSV, "Propagated");
10574 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10576 res = SvREFCNT_inc_simple(sv);
10580 SvREFCNT_inc_simple_void(res);
10589 why1 = "Call to &{$^H{";
10591 why3 = "}} did not return a defined value";
10599 /* Returns a NUL terminated string, with the length of the string written to
10603 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10606 register char *d = dest;
10607 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10610 Perl_croak(aTHX_ ident_too_long);
10611 if (isALNUM(*s)) /* UTF handled below */
10613 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10618 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10622 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10623 char *t = s + UTF8SKIP(s);
10625 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10629 Perl_croak(aTHX_ ident_too_long);
10630 Copy(s, d, len, char);
10643 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10646 char *bracket = NULL;
10648 register char *d = dest;
10649 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10654 while (isDIGIT(*s)) {
10656 Perl_croak(aTHX_ ident_too_long);
10663 Perl_croak(aTHX_ ident_too_long);
10664 if (isALNUM(*s)) /* UTF handled below */
10666 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10671 else if (*s == ':' && s[1] == ':') {
10675 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10676 char *t = s + UTF8SKIP(s);
10677 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10679 if (d + (t - s) > e)
10680 Perl_croak(aTHX_ ident_too_long);
10681 Copy(s, d, t - s, char);
10692 if (PL_lex_state != LEX_NORMAL)
10693 PL_lex_state = LEX_INTERPENDMAYBE;
10696 if (*s == '$' && s[1] &&
10697 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10710 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10715 if (isSPACE(s[-1])) {
10717 const char ch = *s++;
10718 if (!SPACE_OR_TAB(ch)) {
10724 if (isIDFIRST_lazy_if(d,UTF)) {
10728 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10729 end += UTF8SKIP(end);
10730 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10731 end += UTF8SKIP(end);
10733 Copy(s, d, end - s, char);
10738 while ((isALNUM(*s) || *s == ':') && d < e)
10741 Perl_croak(aTHX_ ident_too_long);
10744 while (s < send && SPACE_OR_TAB(*s))
10746 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10747 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10748 const char * const brack =
10750 ((*s == '[') ? "[...]" : "{...}");
10751 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10752 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10753 funny, dest, brack, funny, dest, brack);
10756 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10760 /* Handle extended ${^Foo} variables
10761 * 1999-02-27 mjd-perl-patch@plover.com */
10762 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10766 while (isALNUM(*s) && d < e) {
10770 Perl_croak(aTHX_ ident_too_long);
10775 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10776 PL_lex_state = LEX_INTERPEND;
10779 if (PL_lex_state == LEX_NORMAL) {
10780 if (ckWARN(WARN_AMBIGUOUS) &&
10781 (keyword(dest, d - dest, 0)
10782 || get_cvn_flags(dest, d - dest, 0)))
10786 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10787 "Ambiguous use of %c{%s} resolved to %c%s",
10788 funny, dest, funny, dest);
10793 s = bracket; /* let the parser handle it */
10797 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10798 PL_lex_state = LEX_INTERPEND;
10803 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10805 PERL_UNUSED_CONTEXT;
10809 CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
10810 case GLOBAL_PAT_MOD: *pmfl |= PMf_GLOBAL; break;
10811 case CONTINUE_PAT_MOD: *pmfl |= PMf_CONTINUE; break;
10812 case ONCE_PAT_MOD: *pmfl |= PMf_KEEP; break;
10813 case KEEPCOPY_PAT_MOD: *pmfl |= PMf_KEEPCOPY; break;
10819 S_scan_pat(pTHX_ char *start, I32 type)
10823 char *s = scan_str(start,!!PL_madskills,FALSE);
10824 const char * const valid_flags =
10825 (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
10832 const char * const delimiter = skipspace(start);
10836 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10837 : "Search pattern not terminated" ));
10840 pm = (PMOP*)newPMOP(type, 0);
10841 if (PL_multi_open == '?')
10842 pm->op_pmflags |= PMf_ONCE;
10846 while (*s && strchr(valid_flags, *s))
10847 pmflag(&pm->op_pmflags,*s++);
10849 if (PL_madskills && modstart != s) {
10850 SV* tmptoken = newSVpvn(modstart, s - modstart);
10851 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10854 /* issue a warning if /c is specified,but /g is not */
10855 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10856 && ckWARN(WARN_REGEXP))
10858 Perl_warner(aTHX_ packWARN(WARN_REGEXP),
10859 "Use of /c modifier is meaningless without /g" );
10862 pm->op_pmpermflags = pm->op_pmflags;
10864 PL_lex_op = (OP*)pm;
10865 yylval.ival = OP_MATCH;
10870 S_scan_subst(pTHX_ char *start)
10881 yylval.ival = OP_NULL;
10883 s = scan_str(start,!!PL_madskills,FALSE);
10886 Perl_croak(aTHX_ "Substitution pattern not terminated");
10888 if (s[-1] == PL_multi_open)
10891 if (PL_madskills) {
10892 CURMAD('q', PL_thisopen);
10893 CURMAD('_', PL_thiswhite);
10894 CURMAD('E', PL_thisstuff);
10895 CURMAD('Q', PL_thisclose);
10896 PL_realtokenstart = s - SvPVX(PL_linestr);
10900 first_start = PL_multi_start;
10901 s = scan_str(s,!!PL_madskills,FALSE);
10903 if (PL_lex_stuff) {
10904 SvREFCNT_dec(PL_lex_stuff);
10905 PL_lex_stuff = NULL;
10907 Perl_croak(aTHX_ "Substitution replacement not terminated");
10909 PL_multi_start = first_start; /* so whole substitution is taken together */
10911 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10914 if (PL_madskills) {
10915 CURMAD('z', PL_thisopen);
10916 CURMAD('R', PL_thisstuff);
10917 CURMAD('Z', PL_thisclose);
10923 if (*s == EXEC_PAT_MOD) {
10927 else if (strchr(S_PAT_MODS, *s))
10928 pmflag(&pm->op_pmflags,*s++);
10934 if (PL_madskills) {
10936 curmad('m', newSVpvn(modstart, s - modstart));
10937 append_madprops(PL_thismad, (OP*)pm, 0);
10941 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10942 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10946 SV * const repl = newSVpvs("");
10948 PL_sublex_info.super_bufptr = s;
10949 PL_sublex_info.super_bufend = PL_bufend;
10951 pm->op_pmflags |= PMf_EVAL;
10953 sv_catpv(repl, (const char *)(es ? "eval " : "do "));
10954 sv_catpvs(repl, "{");
10955 sv_catsv(repl, PL_lex_repl);
10956 if (strchr(SvPVX(PL_lex_repl), '#'))
10957 sv_catpvs(repl, "\n");
10958 sv_catpvs(repl, "}");
10960 SvREFCNT_dec(PL_lex_repl);
10961 PL_lex_repl = repl;
10964 pm->op_pmpermflags = pm->op_pmflags;
10965 PL_lex_op = (OP*)pm;
10966 yylval.ival = OP_SUBST;
10971 S_scan_trans(pTHX_ char *start)
10984 yylval.ival = OP_NULL;
10986 s = scan_str(start,!!PL_madskills,FALSE);
10988 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10990 if (s[-1] == PL_multi_open)
10993 if (PL_madskills) {
10994 CURMAD('q', PL_thisopen);
10995 CURMAD('_', PL_thiswhite);
10996 CURMAD('E', PL_thisstuff);
10997 CURMAD('Q', PL_thisclose);
10998 PL_realtokenstart = s - SvPVX(PL_linestr);
11002 s = scan_str(s,!!PL_madskills,FALSE);
11004 if (PL_lex_stuff) {
11005 SvREFCNT_dec(PL_lex_stuff);
11006 PL_lex_stuff = NULL;
11008 Perl_croak(aTHX_ "Transliteration replacement not terminated");
11010 if (PL_madskills) {
11011 CURMAD('z', PL_thisopen);
11012 CURMAD('R', PL_thisstuff);
11013 CURMAD('Z', PL_thisclose);
11016 complement = del = squash = 0;
11023 complement = OPpTRANS_COMPLEMENT;
11026 del = OPpTRANS_DELETE;
11029 squash = OPpTRANS_SQUASH;
11038 tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
11039 o = newPVOP(OP_TRANS, 0, (char*)tbl);
11040 o->op_private &= ~OPpTRANS_ALL;
11041 o->op_private |= del|squash|complement|
11042 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
11043 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
11046 yylval.ival = OP_TRANS;
11049 if (PL_madskills) {
11051 curmad('m', newSVpvn(modstart, s - modstart));
11052 append_madprops(PL_thismad, o, 0);
11061 S_scan_heredoc(pTHX_ register char *s)
11065 I32 op_type = OP_SCALAR;
11069 const char *found_newline;
11073 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
11075 I32 stuffstart = s - SvPVX(PL_linestr);
11078 PL_realtokenstart = -1;
11083 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
11087 while (SPACE_OR_TAB(*peek))
11089 if (*peek == '`' || *peek == '\'' || *peek =='"') {
11092 s = delimcpy(d, e, s, PL_bufend, term, &len);
11102 if (!isALNUM_lazy_if(s,UTF))
11103 deprecate_old("bare << to mean <<\"\"");
11104 for (; isALNUM_lazy_if(s,UTF); s++) {
11109 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
11110 Perl_croak(aTHX_ "Delimiter for here document is too long");
11113 len = d - PL_tokenbuf;
11116 if (PL_madskills) {
11117 tstart = PL_tokenbuf + !outer;
11118 PL_thisclose = newSVpvn(tstart, len - !outer);
11119 tstart = SvPVX(PL_linestr) + stuffstart;
11120 PL_thisopen = newSVpvn(tstart, s - tstart);
11121 stuffstart = s - SvPVX(PL_linestr);
11124 #ifndef PERL_STRICT_CR
11125 d = strchr(s, '\r');
11127 char * const olds = s;
11129 while (s < PL_bufend) {
11135 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11144 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11151 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11152 herewas = newSVpvn(s,PL_bufend-s);
11156 herewas = newSVpvn(s-1,found_newline-s+1);
11159 herewas = newSVpvn(s,found_newline-s);
11163 if (PL_madskills) {
11164 tstart = SvPVX(PL_linestr) + stuffstart;
11166 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11168 PL_thisstuff = newSVpvn(tstart, s - tstart);
11171 s += SvCUR(herewas);
11174 stuffstart = s - SvPVX(PL_linestr);
11180 tmpstr = newSV_type(SVt_PVIV);
11181 SvGROW(tmpstr, 80);
11182 if (term == '\'') {
11183 op_type = OP_CONST;
11184 SvIV_set(tmpstr, -1);
11186 else if (term == '`') {
11187 op_type = OP_BACKTICK;
11188 SvIV_set(tmpstr, '\\');
11192 PL_multi_start = CopLINE(PL_curcop);
11193 PL_multi_open = PL_multi_close = '<';
11194 term = *PL_tokenbuf;
11195 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11196 char * const bufptr = PL_sublex_info.super_bufptr;
11197 char * const bufend = PL_sublex_info.super_bufend;
11198 char * const olds = s - SvCUR(herewas);
11199 s = strchr(bufptr, '\n');
11203 while (s < bufend &&
11204 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11206 CopLINE_inc(PL_curcop);
11209 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11210 missingterm(PL_tokenbuf);
11212 sv_setpvn(herewas,bufptr,d-bufptr+1);
11213 sv_setpvn(tmpstr,d+1,s-d);
11215 sv_catpvn(herewas,s,bufend-s);
11216 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11223 while (s < PL_bufend &&
11224 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11226 CopLINE_inc(PL_curcop);
11228 if (s >= PL_bufend) {
11229 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11230 missingterm(PL_tokenbuf);
11232 sv_setpvn(tmpstr,d+1,s-d);
11234 if (PL_madskills) {
11236 sv_catpvn(PL_thisstuff, d + 1, s - d);
11238 PL_thisstuff = newSVpvn(d + 1, s - d);
11239 stuffstart = s - SvPVX(PL_linestr);
11243 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11245 sv_catpvn(herewas,s,PL_bufend-s);
11246 sv_setsv(PL_linestr,herewas);
11247 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11248 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11249 PL_last_lop = PL_last_uni = NULL;
11252 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11253 while (s >= PL_bufend) { /* multiple line string? */
11255 if (PL_madskills) {
11256 tstart = SvPVX(PL_linestr) + stuffstart;
11258 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11260 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11264 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11265 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11266 missingterm(PL_tokenbuf);
11269 stuffstart = s - SvPVX(PL_linestr);
11271 CopLINE_inc(PL_curcop);
11272 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11273 PL_last_lop = PL_last_uni = NULL;
11274 #ifndef PERL_STRICT_CR
11275 if (PL_bufend - PL_linestart >= 2) {
11276 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11277 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11279 PL_bufend[-2] = '\n';
11281 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11283 else if (PL_bufend[-1] == '\r')
11284 PL_bufend[-1] = '\n';
11286 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11287 PL_bufend[-1] = '\n';
11289 if (PERLDB_LINE && PL_curstash != PL_debstash)
11290 update_debugger_info(PL_linestr, NULL, 0);
11291 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11292 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11293 *(SvPVX(PL_linestr) + off ) = ' ';
11294 sv_catsv(PL_linestr,herewas);
11295 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11296 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11300 sv_catsv(tmpstr,PL_linestr);
11305 PL_multi_end = CopLINE(PL_curcop);
11306 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11307 SvPV_shrink_to_cur(tmpstr);
11309 SvREFCNT_dec(herewas);
11311 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11313 else if (PL_encoding)
11314 sv_recode_to_utf8(tmpstr, PL_encoding);
11316 PL_lex_stuff = tmpstr;
11317 yylval.ival = op_type;
11321 /* scan_inputsymbol
11322 takes: current position in input buffer
11323 returns: new position in input buffer
11324 side-effects: yylval and lex_op are set.
11329 <FH> read from filehandle
11330 <pkg::FH> read from package qualified filehandle
11331 <pkg'FH> read from package qualified filehandle
11332 <$fh> read from filehandle in $fh
11333 <*.h> filename glob
11338 S_scan_inputsymbol(pTHX_ char *start)
11341 register char *s = start; /* current position in buffer */
11345 char *d = PL_tokenbuf; /* start of temp holding space */
11346 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11348 end = strchr(s, '\n');
11351 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11353 /* die if we didn't have space for the contents of the <>,
11354 or if it didn't end, or if we see a newline
11357 if (len >= (I32)sizeof PL_tokenbuf)
11358 Perl_croak(aTHX_ "Excessively long <> operator");
11360 Perl_croak(aTHX_ "Unterminated <> operator");
11365 Remember, only scalar variables are interpreted as filehandles by
11366 this code. Anything more complex (e.g., <$fh{$num}>) will be
11367 treated as a glob() call.
11368 This code makes use of the fact that except for the $ at the front,
11369 a scalar variable and a filehandle look the same.
11371 if (*d == '$' && d[1]) d++;
11373 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11374 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11377 /* If we've tried to read what we allow filehandles to look like, and
11378 there's still text left, then it must be a glob() and not a getline.
11379 Use scan_str to pull out the stuff between the <> and treat it
11380 as nothing more than a string.
11383 if (d - PL_tokenbuf != len) {
11384 yylval.ival = OP_GLOB;
11386 s = scan_str(start,!!PL_madskills,FALSE);
11388 Perl_croak(aTHX_ "Glob not terminated");
11392 bool readline_overriden = FALSE;
11395 /* we're in a filehandle read situation */
11398 /* turn <> into <ARGV> */
11400 Copy("ARGV",d,5,char);
11402 /* Check whether readline() is overriden */
11403 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11405 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11407 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11408 && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
11409 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11410 readline_overriden = TRUE;
11412 /* if <$fh>, create the ops to turn the variable into a
11416 /* try to find it in the pad for this block, otherwise find
11417 add symbol table ops
11419 const PADOFFSET tmp = pad_findmy(d);
11420 if (tmp != NOT_IN_PAD) {
11421 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11422 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11423 HEK * const stashname = HvNAME_HEK(stash);
11424 SV * const sym = sv_2mortal(newSVhek(stashname));
11425 sv_catpvs(sym, "::");
11426 sv_catpv(sym, d+1);
11431 OP * const o = newOP(OP_PADSV, 0);
11433 PL_lex_op = readline_overriden
11434 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11435 append_elem(OP_LIST, o,
11436 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11437 : (OP*)newUNOP(OP_READLINE, 0, o);
11446 ? (GV_ADDMULTI | GV_ADDINEVAL)
11449 PL_lex_op = readline_overriden
11450 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11451 append_elem(OP_LIST,
11452 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11453 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11454 : (OP*)newUNOP(OP_READLINE, 0,
11455 newUNOP(OP_RV2SV, 0,
11456 newGVOP(OP_GV, 0, gv)));
11458 if (!readline_overriden)
11459 PL_lex_op->op_flags |= OPf_SPECIAL;
11460 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11461 yylval.ival = OP_NULL;
11464 /* If it's none of the above, it must be a literal filehandle
11465 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11467 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11468 PL_lex_op = readline_overriden
11469 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11470 append_elem(OP_LIST,
11471 newGVOP(OP_GV, 0, gv),
11472 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11473 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11474 yylval.ival = OP_NULL;
11483 takes: start position in buffer
11484 keep_quoted preserve \ on the embedded delimiter(s)
11485 keep_delims preserve the delimiters around the string
11486 returns: position to continue reading from buffer
11487 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11488 updates the read buffer.
11490 This subroutine pulls a string out of the input. It is called for:
11491 q single quotes q(literal text)
11492 ' single quotes 'literal text'
11493 qq double quotes qq(interpolate $here please)
11494 " double quotes "interpolate $here please"
11495 qx backticks qx(/bin/ls -l)
11496 ` backticks `/bin/ls -l`
11497 qw quote words @EXPORT_OK = qw( func() $spam )
11498 m// regexp match m/this/
11499 s/// regexp substitute s/this/that/
11500 tr/// string transliterate tr/this/that/
11501 y/// string transliterate y/this/that/
11502 ($*@) sub prototypes sub foo ($)
11503 (stuff) sub attr parameters sub foo : attr(stuff)
11504 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11506 In most of these cases (all but <>, patterns and transliterate)
11507 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11508 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11509 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11512 It skips whitespace before the string starts, and treats the first
11513 character as the delimiter. If the delimiter is one of ([{< then
11514 the corresponding "close" character )]}> is used as the closing
11515 delimiter. It allows quoting of delimiters, and if the string has
11516 balanced delimiters ([{<>}]) it allows nesting.
11518 On success, the SV with the resulting string is put into lex_stuff or,
11519 if that is already non-NULL, into lex_repl. The second case occurs only
11520 when parsing the RHS of the special constructs s/// and tr/// (y///).
11521 For convenience, the terminating delimiter character is stuffed into
11526 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11529 SV *sv; /* scalar value: string */
11530 const char *tmps; /* temp string, used for delimiter matching */
11531 register char *s = start; /* current position in the buffer */
11532 register char term; /* terminating character */
11533 register char *to; /* current position in the sv's data */
11534 I32 brackets = 1; /* bracket nesting level */
11535 bool has_utf8 = FALSE; /* is there any utf8 content? */
11536 I32 termcode; /* terminating char. code */
11537 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11538 STRLEN termlen; /* length of terminating string */
11539 int last_off = 0; /* last position for nesting bracket */
11545 /* skip space before the delimiter */
11551 if (PL_realtokenstart >= 0) {
11552 stuffstart = PL_realtokenstart;
11553 PL_realtokenstart = -1;
11556 stuffstart = start - SvPVX(PL_linestr);
11558 /* mark where we are, in case we need to report errors */
11561 /* after skipping whitespace, the next character is the terminator */
11564 termcode = termstr[0] = term;
11568 termcode = utf8_to_uvchr((U8*)s, &termlen);
11569 Copy(s, termstr, termlen, U8);
11570 if (!UTF8_IS_INVARIANT(term))
11574 /* mark where we are */
11575 PL_multi_start = CopLINE(PL_curcop);
11576 PL_multi_open = term;
11578 /* find corresponding closing delimiter */
11579 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11580 termcode = termstr[0] = term = tmps[5];
11582 PL_multi_close = term;
11584 /* create a new SV to hold the contents. 79 is the SV's initial length.
11585 What a random number. */
11586 sv = newSV_type(SVt_PVIV);
11588 SvIV_set(sv, termcode);
11589 (void)SvPOK_only(sv); /* validate pointer */
11591 /* move past delimiter and try to read a complete string */
11593 sv_catpvn(sv, s, termlen);
11596 tstart = SvPVX(PL_linestr) + stuffstart;
11597 if (!PL_thisopen && !keep_delims) {
11598 PL_thisopen = newSVpvn(tstart, s - tstart);
11599 stuffstart = s - SvPVX(PL_linestr);
11603 if (PL_encoding && !UTF) {
11607 int offset = s - SvPVX_const(PL_linestr);
11608 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11609 &offset, (char*)termstr, termlen);
11610 const char * const ns = SvPVX_const(PL_linestr) + offset;
11611 char * const svlast = SvEND(sv) - 1;
11613 for (; s < ns; s++) {
11614 if (*s == '\n' && !PL_rsfp)
11615 CopLINE_inc(PL_curcop);
11618 goto read_more_line;
11620 /* handle quoted delimiters */
11621 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11623 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11625 if ((svlast-1 - t) % 2) {
11626 if (!keep_quoted) {
11627 *(svlast-1) = term;
11629 SvCUR_set(sv, SvCUR(sv) - 1);
11634 if (PL_multi_open == PL_multi_close) {
11640 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
11641 /* At here, all closes are "was quoted" one,
11642 so we don't check PL_multi_close. */
11644 if (!keep_quoted && *(t+1) == PL_multi_open)
11649 else if (*t == PL_multi_open)
11657 SvCUR_set(sv, w - SvPVX_const(sv));
11659 last_off = w - SvPVX(sv);
11660 if (--brackets <= 0)
11665 if (!keep_delims) {
11666 SvCUR_set(sv, SvCUR(sv) - 1);
11672 /* extend sv if need be */
11673 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11674 /* set 'to' to the next character in the sv's string */
11675 to = SvPVX(sv)+SvCUR(sv);
11677 /* if open delimiter is the close delimiter read unbridle */
11678 if (PL_multi_open == PL_multi_close) {
11679 for (; s < PL_bufend; s++,to++) {
11680 /* embedded newlines increment the current line number */
11681 if (*s == '\n' && !PL_rsfp)
11682 CopLINE_inc(PL_curcop);
11683 /* handle quoted delimiters */
11684 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11685 if (!keep_quoted && s[1] == term)
11687 /* any other quotes are simply copied straight through */
11691 /* terminate when run out of buffer (the for() condition), or
11692 have found the terminator */
11693 else if (*s == term) {
11696 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11699 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11705 /* if the terminator isn't the same as the start character (e.g.,
11706 matched brackets), we have to allow more in the quoting, and
11707 be prepared for nested brackets.
11710 /* read until we run out of string, or we find the terminator */
11711 for (; s < PL_bufend; s++,to++) {
11712 /* embedded newlines increment the line count */
11713 if (*s == '\n' && !PL_rsfp)
11714 CopLINE_inc(PL_curcop);
11715 /* backslashes can escape the open or closing characters */
11716 if (*s == '\\' && s+1 < PL_bufend) {
11717 if (!keep_quoted &&
11718 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11723 /* allow nested opens and closes */
11724 else if (*s == PL_multi_close && --brackets <= 0)
11726 else if (*s == PL_multi_open)
11728 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11733 /* terminate the copied string and update the sv's end-of-string */
11735 SvCUR_set(sv, to - SvPVX_const(sv));
11738 * this next chunk reads more into the buffer if we're not done yet
11742 break; /* handle case where we are done yet :-) */
11744 #ifndef PERL_STRICT_CR
11745 if (to - SvPVX_const(sv) >= 2) {
11746 if ((to[-2] == '\r' && to[-1] == '\n') ||
11747 (to[-2] == '\n' && to[-1] == '\r'))
11751 SvCUR_set(sv, to - SvPVX_const(sv));
11753 else if (to[-1] == '\r')
11756 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11761 /* if we're out of file, or a read fails, bail and reset the current
11762 line marker so we can report where the unterminated string began
11765 if (PL_madskills) {
11766 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11768 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11770 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11774 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11776 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11782 /* we read a line, so increment our line counter */
11783 CopLINE_inc(PL_curcop);
11785 /* update debugger info */
11786 if (PERLDB_LINE && PL_curstash != PL_debstash)
11787 update_debugger_info(PL_linestr, NULL, 0);
11789 /* having changed the buffer, we must update PL_bufend */
11790 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11791 PL_last_lop = PL_last_uni = NULL;
11794 /* at this point, we have successfully read the delimited string */
11796 if (!PL_encoding || UTF) {
11798 if (PL_madskills) {
11799 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11800 const int len = s - tstart;
11802 sv_catpvn(PL_thisstuff, tstart, len);
11804 PL_thisstuff = newSVpvn(tstart, len);
11805 if (!PL_thisclose && !keep_delims)
11806 PL_thisclose = newSVpvn(s,termlen);
11811 sv_catpvn(sv, s, termlen);
11816 if (PL_madskills) {
11817 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11818 const int len = s - tstart - termlen;
11820 sv_catpvn(PL_thisstuff, tstart, len);
11822 PL_thisstuff = newSVpvn(tstart, len);
11823 if (!PL_thisclose && !keep_delims)
11824 PL_thisclose = newSVpvn(s - termlen,termlen);
11828 if (has_utf8 || PL_encoding)
11831 PL_multi_end = CopLINE(PL_curcop);
11833 /* if we allocated too much space, give some back */
11834 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11835 SvLEN_set(sv, SvCUR(sv) + 1);
11836 SvPV_renew(sv, SvLEN(sv));
11839 /* decide whether this is the first or second quoted string we've read
11852 takes: pointer to position in buffer
11853 returns: pointer to new position in buffer
11854 side-effects: builds ops for the constant in yylval.op
11856 Read a number in any of the formats that Perl accepts:
11858 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11859 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11862 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11864 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11867 If it reads a number without a decimal point or an exponent, it will
11868 try converting the number to an integer and see if it can do so
11869 without loss of precision.
11873 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11876 register const char *s = start; /* current position in buffer */
11877 register char *d; /* destination in temp buffer */
11878 register char *e; /* end of temp buffer */
11879 NV nv; /* number read, as a double */
11880 SV *sv = NULL; /* place to put the converted number */
11881 bool floatit; /* boolean: int or float? */
11882 const char *lastub = NULL; /* position of last underbar */
11883 static char const number_too_long[] = "Number too long";
11885 /* We use the first character to decide what type of number this is */
11889 Perl_croak(aTHX_ "panic: scan_num");
11891 /* if it starts with a 0, it could be an octal number, a decimal in
11892 0.13 disguise, or a hexadecimal number, or a binary number. */
11896 u holds the "number so far"
11897 shift the power of 2 of the base
11898 (hex == 4, octal == 3, binary == 1)
11899 overflowed was the number more than we can hold?
11901 Shift is used when we add a digit. It also serves as an "are
11902 we in octal/hex/binary?" indicator to disallow hex characters
11903 when in octal mode.
11908 bool overflowed = FALSE;
11909 bool just_zero = TRUE; /* just plain 0 or binary number? */
11910 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11911 static const char* const bases[5] =
11912 { "", "binary", "", "octal", "hexadecimal" };
11913 static const char* const Bases[5] =
11914 { "", "Binary", "", "Octal", "Hexadecimal" };
11915 static const char* const maxima[5] =
11917 "0b11111111111111111111111111111111",
11921 const char *base, *Base, *max;
11923 /* check for hex */
11928 } else if (s[1] == 'b') {
11933 /* check for a decimal in disguise */
11934 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11936 /* so it must be octal */
11943 if (ckWARN(WARN_SYNTAX))
11944 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11945 "Misplaced _ in number");
11949 base = bases[shift];
11950 Base = Bases[shift];
11951 max = maxima[shift];
11953 /* read the rest of the number */
11955 /* x is used in the overflow test,
11956 b is the digit we're adding on. */
11961 /* if we don't mention it, we're done */
11965 /* _ are ignored -- but warned about if consecutive */
11967 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11968 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11969 "Misplaced _ in number");
11973 /* 8 and 9 are not octal */
11974 case '8': case '9':
11976 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11980 case '2': case '3': case '4':
11981 case '5': case '6': case '7':
11983 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11986 case '0': case '1':
11987 b = *s++ & 15; /* ASCII digit -> value of digit */
11991 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11992 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11993 /* make sure they said 0x */
11996 b = (*s++ & 7) + 9;
11998 /* Prepare to put the digit we have onto the end
11999 of the number so far. We check for overflows.
12005 x = u << shift; /* make room for the digit */
12007 if ((x >> shift) != u
12008 && !(PL_hints & HINT_NEW_BINARY)) {
12011 if (ckWARN_d(WARN_OVERFLOW))
12012 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12013 "Integer overflow in %s number",
12016 u = x | b; /* add the digit to the end */
12019 n *= nvshift[shift];
12020 /* If an NV has not enough bits in its
12021 * mantissa to represent an UV this summing of
12022 * small low-order numbers is a waste of time
12023 * (because the NV cannot preserve the
12024 * low-order bits anyway): we could just
12025 * remember when did we overflow and in the
12026 * end just multiply n by the right
12034 /* if we get here, we had success: make a scalar value from
12039 /* final misplaced underbar check */
12040 if (s[-1] == '_') {
12041 if (ckWARN(WARN_SYNTAX))
12042 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12047 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
12048 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12049 "%s number > %s non-portable",
12055 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
12056 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12057 "%s number > %s non-portable",
12062 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
12063 sv = new_constant(start, s - start, "integer",
12065 else if (PL_hints & HINT_NEW_BINARY)
12066 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
12071 handle decimal numbers.
12072 we're also sent here when we read a 0 as the first digit
12074 case '1': case '2': case '3': case '4': case '5':
12075 case '6': case '7': case '8': case '9': case '.':
12078 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
12081 /* read next group of digits and _ and copy into d */
12082 while (isDIGIT(*s) || *s == '_') {
12083 /* skip underscores, checking for misplaced ones
12087 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12088 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12089 "Misplaced _ in number");
12093 /* check for end of fixed-length buffer */
12095 Perl_croak(aTHX_ number_too_long);
12096 /* if we're ok, copy the character */
12101 /* final misplaced underbar check */
12102 if (lastub && s == lastub + 1) {
12103 if (ckWARN(WARN_SYNTAX))
12104 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12107 /* read a decimal portion if there is one. avoid
12108 3..5 being interpreted as the number 3. followed
12111 if (*s == '.' && s[1] != '.') {
12116 if (ckWARN(WARN_SYNTAX))
12117 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12118 "Misplaced _ in number");
12122 /* copy, ignoring underbars, until we run out of digits.
12124 for (; isDIGIT(*s) || *s == '_'; s++) {
12125 /* fixed length buffer check */
12127 Perl_croak(aTHX_ number_too_long);
12129 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12130 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12131 "Misplaced _ in number");
12137 /* fractional part ending in underbar? */
12138 if (s[-1] == '_') {
12139 if (ckWARN(WARN_SYNTAX))
12140 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12141 "Misplaced _ in number");
12143 if (*s == '.' && isDIGIT(s[1])) {
12144 /* oops, it's really a v-string, but without the "v" */
12150 /* read exponent part, if present */
12151 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12155 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12156 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12158 /* stray preinitial _ */
12160 if (ckWARN(WARN_SYNTAX))
12161 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12162 "Misplaced _ in number");
12166 /* allow positive or negative exponent */
12167 if (*s == '+' || *s == '-')
12170 /* stray initial _ */
12172 if (ckWARN(WARN_SYNTAX))
12173 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12174 "Misplaced _ in number");
12178 /* read digits of exponent */
12179 while (isDIGIT(*s) || *s == '_') {
12182 Perl_croak(aTHX_ number_too_long);
12186 if (((lastub && s == lastub + 1) ||
12187 (!isDIGIT(s[1]) && s[1] != '_'))
12188 && ckWARN(WARN_SYNTAX))
12189 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12190 "Misplaced _ in number");
12197 /* make an sv from the string */
12201 We try to do an integer conversion first if no characters
12202 indicating "float" have been found.
12207 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12209 if (flags == IS_NUMBER_IN_UV) {
12211 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12214 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12215 if (uv <= (UV) IV_MIN)
12216 sv_setiv(sv, -(IV)uv);
12223 /* terminate the string */
12225 nv = Atof(PL_tokenbuf);
12229 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12230 (PL_hints & HINT_NEW_INTEGER) )
12231 sv = new_constant(PL_tokenbuf,
12234 (floatit ? "float" : "integer"),
12238 /* if it starts with a v, it could be a v-string */
12241 sv = newSV(5); /* preallocate storage space */
12242 s = scan_vstring(s, PL_bufend, sv);
12246 /* make the op for the constant and return */
12249 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12251 lvalp->opval = NULL;
12257 S_scan_formline(pTHX_ register char *s)
12260 register char *eol;
12262 SV * const stuff = newSVpvs("");
12263 bool needargs = FALSE;
12264 bool eofmt = FALSE;
12266 char *tokenstart = s;
12269 if (PL_madskills) {
12270 savewhite = PL_thiswhite;
12275 while (!needargs) {
12278 #ifdef PERL_STRICT_CR
12279 while (SPACE_OR_TAB(*t))
12282 while (SPACE_OR_TAB(*t) || *t == '\r')
12285 if (*t == '\n' || t == PL_bufend) {
12290 if (PL_in_eval && !PL_rsfp) {
12291 eol = (char *) memchr(s,'\n',PL_bufend-s);
12296 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12298 for (t = s; t < eol; t++) {
12299 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12301 goto enough; /* ~~ must be first line in formline */
12303 if (*t == '@' || *t == '^')
12307 sv_catpvn(stuff, s, eol-s);
12308 #ifndef PERL_STRICT_CR
12309 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12310 char *end = SvPVX(stuff) + SvCUR(stuff);
12313 SvCUR_set(stuff, SvCUR(stuff) - 1);
12323 if (PL_madskills) {
12325 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12327 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12330 s = filter_gets(PL_linestr, PL_rsfp, 0);
12332 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12334 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12336 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12337 PL_last_lop = PL_last_uni = NULL;
12346 if (SvCUR(stuff)) {
12349 PL_lex_state = LEX_NORMAL;
12350 start_force(PL_curforce);
12351 NEXTVAL_NEXTTOKE.ival = 0;
12355 PL_lex_state = LEX_FORMLINE;
12357 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12359 else if (PL_encoding)
12360 sv_recode_to_utf8(stuff, PL_encoding);
12362 start_force(PL_curforce);
12363 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12365 start_force(PL_curforce);
12366 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12370 SvREFCNT_dec(stuff);
12372 PL_lex_formbrack = 0;
12376 if (PL_madskills) {
12378 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12380 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12381 PL_thiswhite = savewhite;
12393 PL_cshlen = strlen(PL_cshname);
12395 #if defined(USE_ITHREADS)
12396 PERL_UNUSED_CONTEXT;
12402 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12405 const I32 oldsavestack_ix = PL_savestack_ix;
12406 CV* const outsidecv = PL_compcv;
12409 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12411 SAVEI32(PL_subline);
12412 save_item(PL_subname);
12413 SAVESPTR(PL_compcv);
12415 PL_compcv = (CV*)newSV_type(is_format ? SVt_PVFM : SVt_PVCV);
12416 CvFLAGS(PL_compcv) |= flags;
12418 PL_subline = CopLINE(PL_curcop);
12419 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12420 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12421 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12423 return oldsavestack_ix;
12427 #pragma segment Perl_yylex
12430 Perl_yywarn(pTHX_ const char *s)
12433 PL_in_eval |= EVAL_WARNONLY;
12435 PL_in_eval &= ~EVAL_WARNONLY;
12440 Perl_yyerror(pTHX_ const char *s)
12443 const char *where = NULL;
12444 const char *context = NULL;
12447 int yychar = PL_parser->yychar;
12449 if (!yychar || (yychar == ';' && !PL_rsfp))
12451 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12452 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12453 PL_oldbufptr != PL_bufptr) {
12456 The code below is removed for NetWare because it abends/crashes on NetWare
12457 when the script has error such as not having the closing quotes like:
12458 if ($var eq "value)
12459 Checking of white spaces is anyway done in NetWare code.
12462 while (isSPACE(*PL_oldoldbufptr))
12465 context = PL_oldoldbufptr;
12466 contlen = PL_bufptr - PL_oldoldbufptr;
12468 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12469 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12472 The code below is removed for NetWare because it abends/crashes on NetWare
12473 when the script has error such as not having the closing quotes like:
12474 if ($var eq "value)
12475 Checking of white spaces is anyway done in NetWare code.
12478 while (isSPACE(*PL_oldbufptr))
12481 context = PL_oldbufptr;
12482 contlen = PL_bufptr - PL_oldbufptr;
12484 else if (yychar > 255)
12485 where = "next token ???";
12486 else if (yychar == -2) { /* YYEMPTY */
12487 if (PL_lex_state == LEX_NORMAL ||
12488 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12489 where = "at end of line";
12490 else if (PL_lex_inpat)
12491 where = "within pattern";
12493 where = "within string";
12496 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12498 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12499 else if (isPRINT_LC(yychar))
12500 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12502 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12503 where = SvPVX_const(where_sv);
12505 msg = sv_2mortal(newSVpv(s, 0));
12506 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12507 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12509 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12511 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12512 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12513 Perl_sv_catpvf(aTHX_ msg,
12514 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12515 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12518 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12519 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
12522 if (PL_error_count >= 10) {
12523 if (PL_in_eval && SvCUR(ERRSV))
12524 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12525 SVfARG(ERRSV), OutCopFILE(PL_curcop));
12527 Perl_croak(aTHX_ "%s has too many errors.\n",
12528 OutCopFILE(PL_curcop));
12531 PL_in_my_stash = NULL;
12535 #pragma segment Main
12539 S_swallow_bom(pTHX_ U8 *s)
12542 const STRLEN slen = SvCUR(PL_linestr);
12545 if (s[1] == 0xFE) {
12546 /* UTF-16 little-endian? (or UTF32-LE?) */
12547 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12548 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12549 #ifndef PERL_NO_UTF16_FILTER
12550 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12553 if (PL_bufend > (char*)s) {
12557 filter_add(utf16rev_textfilter, NULL);
12558 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12559 utf16_to_utf8_reversed(s, news,
12560 PL_bufend - (char*)s - 1,
12562 sv_setpvn(PL_linestr, (const char*)news, newlen);
12564 s = (U8*)SvPVX(PL_linestr);
12565 Copy(news, s, newlen, U8);
12569 SvUTF8_on(PL_linestr);
12570 s = (U8*)SvPVX(PL_linestr);
12572 /* FIXME - is this a general bug fix? */
12575 PL_bufend = SvPVX(PL_linestr) + newlen;
12578 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12583 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12584 #ifndef PERL_NO_UTF16_FILTER
12585 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12588 if (PL_bufend > (char *)s) {
12592 filter_add(utf16_textfilter, NULL);
12593 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12594 utf16_to_utf8(s, news,
12595 PL_bufend - (char*)s,
12597 sv_setpvn(PL_linestr, (const char*)news, newlen);
12599 SvUTF8_on(PL_linestr);
12600 s = (U8*)SvPVX(PL_linestr);
12601 PL_bufend = SvPVX(PL_linestr) + newlen;
12604 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12609 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12610 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12611 s += 3; /* UTF-8 */
12617 if (s[2] == 0xFE && s[3] == 0xFF) {
12618 /* UTF-32 big-endian */
12619 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12622 else if (s[2] == 0 && s[3] != 0) {
12625 * are a good indicator of UTF-16BE. */
12626 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12632 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12633 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12634 s += 4; /* UTF-8 */
12640 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12643 * are a good indicator of UTF-16LE. */
12644 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12653 * Restore a source filter.
12657 restore_rsfp(pTHX_ void *f)
12660 PerlIO * const fp = (PerlIO*)f;
12662 if (PL_rsfp == PerlIO_stdin())
12663 PerlIO_clearerr(PL_rsfp);
12664 else if (PL_rsfp && (PL_rsfp != fp))
12665 PerlIO_close(PL_rsfp);
12669 #ifndef PERL_NO_UTF16_FILTER
12671 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12674 const STRLEN old = SvCUR(sv);
12675 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12676 DEBUG_P(PerlIO_printf(Perl_debug_log,
12677 "utf16_textfilter(%p): %d %d (%d)\n",
12678 FPTR2DPTR(void *, utf16_textfilter),
12679 idx, maxlen, (int) count));
12683 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12684 Copy(SvPVX_const(sv), tmps, old, char);
12685 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12686 SvCUR(sv) - old, &newlen);
12687 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12689 DEBUG_P({sv_dump(sv);});
12694 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12697 const STRLEN old = SvCUR(sv);
12698 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12699 DEBUG_P(PerlIO_printf(Perl_debug_log,
12700 "utf16rev_textfilter(%p): %d %d (%d)\n",
12701 FPTR2DPTR(void *, utf16rev_textfilter),
12702 idx, maxlen, (int) count));
12706 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12707 Copy(SvPVX_const(sv), tmps, old, char);
12708 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12709 SvCUR(sv) - old, &newlen);
12710 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12712 DEBUG_P({ sv_dump(sv); });
12718 Returns a pointer to the next character after the parsed
12719 vstring, as well as updating the passed in sv.
12721 Function must be called like
12724 s = scan_vstring(s,e,sv);
12726 where s and e are the start and end of the string.
12727 The sv should already be large enough to store the vstring
12728 passed in, for performance reasons.
12733 Perl_scan_vstring(pTHX_ const char *s, const char *e, SV *sv)
12736 const char *pos = s;
12737 const char *start = s;
12738 if (*pos == 'v') pos++; /* get past 'v' */
12739 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12741 if ( *pos != '.') {
12742 /* this may not be a v-string if followed by => */
12743 const char *next = pos;
12744 while (next < e && isSPACE(*next))
12746 if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
12747 /* return string not v-string */
12748 sv_setpvn(sv,(char *)s,pos-s);
12749 return (char *)pos;
12753 if (!isALPHA(*pos)) {
12754 U8 tmpbuf[UTF8_MAXBYTES+1];
12757 s++; /* get past 'v' */
12759 sv_setpvn(sv, "", 0);
12762 /* this is atoi() that tolerates underscores */
12765 const char *end = pos;
12767 while (--end >= s) {
12769 const UV orev = rev;
12770 rev += (*end - '0') * mult;
12772 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12773 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12774 "Integer overflow in decimal number");
12778 if (rev > 0x7FFFFFFF)
12779 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12781 /* Append native character for the rev point */
12782 tmpend = uvchr_to_utf8(tmpbuf, rev);
12783 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12784 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12786 if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
12792 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12796 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12804 * c-indentation-style: bsd
12805 * c-basic-offset: 4
12806 * indent-tabs-mode: t
12809 * ex: set ts=8 sts=4 sw=4 noet: