3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "It all comes from here, the stench and the peril." --Frodo
16 * This file is the lexer for Perl. It's closely linked to the
19 * The main routine is yylex(), which returns the next token.
23 #define PERL_IN_TOKE_C
26 #define yylval (PL_parser->yylval)
28 /* YYINITDEPTH -- initial size of the parser's stacks. */
29 #define YYINITDEPTH 200
31 /* XXX temporary backwards compatibility */
32 #define PL_lex_brackets (PL_parser->lex_brackets)
33 #define PL_lex_brackstack (PL_parser->lex_brackstack)
34 #define PL_lex_casemods (PL_parser->lex_casemods)
35 #define PL_lex_casestack (PL_parser->lex_casestack)
36 #define PL_lex_defer (PL_parser->lex_defer)
37 #define PL_lex_dojoin (PL_parser->lex_dojoin)
38 #define PL_lex_expect (PL_parser->lex_expect)
39 #define PL_lex_formbrack (PL_parser->lex_formbrack)
40 #define PL_lex_inpat (PL_parser->lex_inpat)
41 #define PL_lex_inwhat (PL_parser->lex_inwhat)
42 #define PL_lex_op (PL_parser->lex_op)
43 #define PL_lex_repl (PL_parser->lex_repl)
44 #define PL_lex_starts (PL_parser->lex_starts)
45 #define PL_lex_stuff (PL_parser->lex_stuff)
46 #define PL_multi_start (PL_parser->multi_start)
47 #define PL_multi_open (PL_parser->multi_open)
48 #define PL_multi_close (PL_parser->multi_close)
49 #define PL_pending_ident (PL_parser->pending_ident)
50 #define PL_preambled (PL_parser->preambled)
51 #define PL_sublex_info (PL_parser->sublex_info)
52 #define PL_linestr (PL_parser->linestr)
53 #define PL_expect (PL_parser->expect)
54 #define PL_copline (PL_parser->copline)
55 #define PL_bufptr (PL_parser->bufptr)
56 #define PL_oldbufptr (PL_parser->oldbufptr)
57 #define PL_oldoldbufptr (PL_parser->oldoldbufptr)
58 #define PL_linestart (PL_parser->linestart)
59 #define PL_bufend (PL_parser->bufend)
60 #define PL_last_uni (PL_parser->last_uni)
61 #define PL_last_lop (PL_parser->last_lop)
62 #define PL_last_lop_op (PL_parser->last_lop_op)
63 #define PL_lex_state (PL_parser->lex_state)
66 # define PL_endwhite (PL_parser->endwhite)
67 # define PL_faketokens (PL_parser->faketokens)
68 # define PL_lasttoke (PL_parser->lasttoke)
69 # define PL_nextwhite (PL_parser->nextwhite)
70 # define PL_realtokenstart (PL_parser->realtokenstart)
71 # define PL_skipwhite (PL_parser->skipwhite)
72 # define PL_thisclose (PL_parser->thisclose)
73 # define PL_thismad (PL_parser->thismad)
74 # define PL_thisopen (PL_parser->thisopen)
75 # define PL_thisstuff (PL_parser->thisstuff)
76 # define PL_thistoken (PL_parser->thistoken)
77 # define PL_thiswhite (PL_parser->thiswhite)
78 # define PL_thiswhite (PL_parser->thiswhite)
79 # define PL_nexttoke (PL_parser->nexttoke)
80 # define PL_curforce (PL_parser->curforce)
82 # define PL_nexttoke (PL_parser->nexttoke)
83 # define PL_nexttype (PL_parser->nexttype)
84 # define PL_nextval (PL_parser->nextval)
88 S_pending_ident(pTHX);
90 static const char ident_too_long[] = "Identifier too long";
91 static const char commaless_variable_list[] = "comma-less variable list";
93 static void restore_rsfp(pTHX_ void *f);
94 #ifndef PERL_NO_UTF16_FILTER
95 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
96 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
100 # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
101 # define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
103 # define CURMAD(slot,sv)
104 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
107 #define XFAKEBRACK 128
108 #define XENUMMASK 127
110 #ifdef USE_UTF8_SCRIPTS
111 # define UTF (!IN_BYTES)
113 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
116 /* In variables named $^X, these are the legal values for X.
117 * 1999-02-27 mjd-perl-patch@plover.com */
118 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
120 /* On MacOS, respect nonbreaking spaces */
121 #ifdef MACOS_TRADITIONAL
122 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
124 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
127 /* LEX_* are values for PL_lex_state, the state of the lexer.
128 * They are arranged oddly so that the guard on the switch statement
129 * can get by with a single comparison (if the compiler is smart enough).
132 /* #define LEX_NOTPARSING 11 is done in perl.h. */
134 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
135 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
136 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
137 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
138 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
140 /* at end of code, eg "$x" followed by: */
141 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
142 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
144 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
145 string or after \E, $foo, etc */
146 #define LEX_INTERPCONST 2 /* NOT USED */
147 #define LEX_FORMLINE 1 /* expecting a format line */
148 #define LEX_KNOWNEXT 0 /* next token known; just return it */
152 static const char* const lex_state_names[] = {
171 #include "keywords.h"
173 /* CLINE is a macro that ensures PL_copline has a sane value */
178 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
181 # define SKIPSPACE0(s) skipspace0(s)
182 # define SKIPSPACE1(s) skipspace1(s)
183 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
184 # define PEEKSPACE(s) skipspace2(s,0)
186 # define SKIPSPACE0(s) skipspace(s)
187 # define SKIPSPACE1(s) skipspace(s)
188 # define SKIPSPACE2(s,tsv) skipspace(s)
189 # define PEEKSPACE(s) skipspace(s)
193 * Convenience functions to return different tokens and prime the
194 * lexer for the next token. They all take an argument.
196 * TOKEN : generic token (used for '(', DOLSHARP, etc)
197 * OPERATOR : generic operator
198 * AOPERATOR : assignment operator
199 * PREBLOCK : beginning the block after an if, while, foreach, ...
200 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
201 * PREREF : *EXPR where EXPR is not a simple identifier
202 * TERM : expression term
203 * LOOPX : loop exiting command (goto, last, dump, etc)
204 * FTST : file test operator
205 * FUN0 : zero-argument function
206 * FUN1 : not used, except for not, which isn't a UNIOP
207 * BOop : bitwise or or xor
209 * SHop : shift operator
210 * PWop : power operator
211 * PMop : pattern-matching operator
212 * Aop : addition-level operator
213 * Mop : multiplication-level operator
214 * Eop : equality-testing operator
215 * Rop : relational operator <= != gt
217 * Also see LOP and lop() below.
220 #ifdef DEBUGGING /* Serve -DT. */
221 # define REPORT(retval) tokereport((I32)retval)
223 # define REPORT(retval) (retval)
226 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
227 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
228 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
229 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
230 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
231 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
232 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
233 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
234 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
235 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
236 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
237 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
238 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
239 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
240 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
241 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
242 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
243 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
244 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
245 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
247 /* This bit of chicanery makes a unary function followed by
248 * a parenthesis into a function with one argument, highest precedence.
249 * The UNIDOR macro is for unary functions that can be followed by the //
250 * operator (such as C<shift // 0>).
252 #define UNI2(f,x) { \
256 PL_last_uni = PL_oldbufptr; \
257 PL_last_lop_op = f; \
259 return REPORT( (int)FUNC1 ); \
261 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
263 #define UNI(f) UNI2(f,XTERM)
264 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
266 #define UNIBRACK(f) { \
269 PL_last_uni = PL_oldbufptr; \
271 return REPORT( (int)FUNC1 ); \
273 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
276 /* grandfather return to old style */
277 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
281 /* how to interpret the yylval associated with the token */
285 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
291 static struct debug_tokens {
293 enum token_type type;
295 } const debug_tokens[] =
297 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
298 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
299 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
300 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
301 { ARROW, TOKENTYPE_NONE, "ARROW" },
302 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
303 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
304 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
305 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
306 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
307 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
308 { DO, TOKENTYPE_NONE, "DO" },
309 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
310 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
311 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
312 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
313 { ELSE, TOKENTYPE_NONE, "ELSE" },
314 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
315 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
316 { FOR, TOKENTYPE_IVAL, "FOR" },
317 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
318 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
319 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
320 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
321 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
322 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
323 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
324 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
325 { IF, TOKENTYPE_IVAL, "IF" },
326 { LABEL, TOKENTYPE_PVAL, "LABEL" },
327 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
328 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
329 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
330 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
331 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
332 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
333 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
334 { MY, TOKENTYPE_IVAL, "MY" },
335 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
336 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
337 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
338 { OROP, TOKENTYPE_IVAL, "OROP" },
339 { OROR, TOKENTYPE_NONE, "OROR" },
340 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
341 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
342 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
343 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
344 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
345 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
346 { PREINC, TOKENTYPE_NONE, "PREINC" },
347 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
348 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
349 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
350 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
351 { SUB, TOKENTYPE_NONE, "SUB" },
352 { THING, TOKENTYPE_OPVAL, "THING" },
353 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
354 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
355 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
356 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
357 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
358 { USE, TOKENTYPE_IVAL, "USE" },
359 { WHEN, TOKENTYPE_IVAL, "WHEN" },
360 { WHILE, TOKENTYPE_IVAL, "WHILE" },
361 { WORD, TOKENTYPE_OPVAL, "WORD" },
362 { 0, TOKENTYPE_NONE, NULL }
365 /* dump the returned token in rv, plus any optional arg in yylval */
368 S_tokereport(pTHX_ I32 rv)
372 const char *name = NULL;
373 enum token_type type = TOKENTYPE_NONE;
374 const struct debug_tokens *p;
375 SV* const report = newSVpvs("<== ");
377 for (p = debug_tokens; p->token; p++) {
378 if (p->token == (int)rv) {
385 Perl_sv_catpv(aTHX_ report, name);
386 else if ((char)rv > ' ' && (char)rv < '~')
387 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
389 sv_catpvs(report, "EOF");
391 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
394 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
397 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
399 case TOKENTYPE_OPNUM:
400 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
401 PL_op_name[yylval.ival]);
404 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
406 case TOKENTYPE_OPVAL:
408 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
409 PL_op_name[yylval.opval->op_type]);
410 if (yylval.opval->op_type == OP_CONST) {
411 Perl_sv_catpvf(aTHX_ report, " %s",
412 SvPEEK(cSVOPx_sv(yylval.opval)));
417 sv_catpvs(report, "(opval=null)");
420 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
426 /* print the buffer with suitable escapes */
429 S_printbuf(pTHX_ const char* fmt, const char* s)
431 SV* const tmp = newSVpvs("");
432 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
441 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
442 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
446 S_ao(pTHX_ int toketype)
449 if (*PL_bufptr == '=') {
451 if (toketype == ANDAND)
452 yylval.ival = OP_ANDASSIGN;
453 else if (toketype == OROR)
454 yylval.ival = OP_ORASSIGN;
455 else if (toketype == DORDOR)
456 yylval.ival = OP_DORASSIGN;
464 * When Perl expects an operator and finds something else, no_op
465 * prints the warning. It always prints "<something> found where
466 * operator expected. It prints "Missing semicolon on previous line?"
467 * if the surprise occurs at the start of the line. "do you need to
468 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
469 * where the compiler doesn't know if foo is a method call or a function.
470 * It prints "Missing operator before end of line" if there's nothing
471 * after the missing operator, or "... before <...>" if there is something
472 * after the missing operator.
476 S_no_op(pTHX_ const char *what, char *s)
479 char * const oldbp = PL_bufptr;
480 const bool is_first = (PL_oldbufptr == PL_linestart);
486 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
487 if (ckWARN_d(WARN_SYNTAX)) {
489 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
490 "\t(Missing semicolon on previous line?)\n");
491 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
493 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
495 if (t < PL_bufptr && isSPACE(*t))
496 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
497 "\t(Do you need to predeclare %.*s?)\n",
498 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
502 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
503 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
511 * Complain about missing quote/regexp/heredoc terminator.
512 * If it's called with NULL then it cauterizes the line buffer.
513 * If we're in a delimited string and the delimiter is a control
514 * character, it's reformatted into a two-char sequence like ^C.
519 S_missingterm(pTHX_ char *s)
525 char * const nl = strrchr(s,'\n');
531 iscntrl(PL_multi_close)
533 PL_multi_close < 32 || PL_multi_close == 127
537 tmpbuf[1] = (char)toCTRL(PL_multi_close);
542 *tmpbuf = (char)PL_multi_close;
546 q = strchr(s,'"') ? '\'' : '"';
547 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
550 #define FEATURE_IS_ENABLED(name) \
551 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
552 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
554 * S_feature_is_enabled
555 * Check whether the named feature is enabled.
558 S_feature_is_enabled(pTHX_ const char *name, STRLEN namelen)
561 HV * const hinthv = GvHV(PL_hintgv);
562 char he_name[32] = "feature_";
563 (void) my_strlcpy(&he_name[8], name, 24);
565 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
573 Perl_deprecate(pTHX_ const char *s)
575 if (ckWARN(WARN_DEPRECATED))
576 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
580 Perl_deprecate_old(pTHX_ const char *s)
582 /* This function should NOT be called for any new deprecated warnings */
583 /* Use Perl_deprecate instead */
585 /* It is here to maintain backward compatibility with the pre-5.8 */
586 /* warnings category hierarchy. The "deprecated" category used to */
587 /* live under the "syntax" category. It is now a top-level category */
588 /* in its own right. */
590 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
591 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
592 "Use of %s is deprecated", s);
596 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
597 * utf16-to-utf8-reversed.
600 #ifdef PERL_CR_FILTER
604 register const char *s = SvPVX_const(sv);
605 register const char * const e = s + SvCUR(sv);
606 /* outer loop optimized to do nothing if there are no CR-LFs */
608 if (*s++ == '\r' && *s == '\n') {
609 /* hit a CR-LF, need to copy the rest */
610 register char *d = s - 1;
613 if (*s == '\r' && s[1] == '\n')
624 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
626 const I32 count = FILTER_READ(idx+1, sv, maxlen);
627 if (count > 0 && !maxlen)
637 * Create a parser object and initialise its parser and lexer fields
641 Perl_lex_start(pTHX_ SV *line)
644 const char *s = NULL;
648 /* create and initialise a parser */
650 Newxz(parser, 1, yy_parser);
651 parser->old_parser = PL_parser;
654 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
655 parser->ps = parser->stack;
656 parser->stack_size = YYINITDEPTH;
658 parser->stack->state = 0;
659 parser->yyerrstatus = 0;
660 parser->yychar = YYEMPTY; /* Cause a token to be read. */
662 /* on scope exit, free this parser and restore any outer one */
665 /* initialise lexer state */
667 SAVECOPLINE(PL_curcop);
668 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
671 parser->curforce = -1;
673 parser->nexttoke = 0;
675 parser->copline = NOLINE;
676 PL_lex_state = LEX_NORMAL;
677 parser->expect = XSTATE;
678 Newx(parser->lex_brackstack, 120, char);
679 Newx(parser->lex_casestack, 12, char);
680 *parser->lex_casestack = '\0';
683 s = SvPV_const(line, len);
689 parser->linestr = newSVpvs("\n;");
690 } else if (SvREADONLY(line) || s[len-1] != ';') {
691 parser->linestr = newSVsv(line);
693 sv_catpvs(parser->linestr, "\n;");
696 SvREFCNT_inc_simple_void_NN(line);
697 parser->linestr = line;
699 parser->oldoldbufptr =
702 parser->linestart = SvPVX(parser->linestr);
703 parser->bufend = parser->bufptr + SvCUR(parser->linestr);
704 parser->last_lop = parser->last_uni = NULL;
709 /* delete a parser object */
712 Perl_parser_free(pTHX_ const yy_parser *parser)
714 SvREFCNT_dec(parser->linestr);
716 Safefree(parser->stack);
717 Safefree(parser->lex_brackstack);
718 Safefree(parser->lex_casestack);
719 PL_parser = parser->old_parser;
726 * Finalizer for lexing operations. Must be called when the parser is
727 * done with the lexer.
734 PL_doextract = FALSE;
739 * This subroutine has nothing to do with tilting, whether at windmills
740 * or pinball tables. Its name is short for "increment line". It
741 * increments the current line number in CopLINE(PL_curcop) and checks
742 * to see whether the line starts with a comment of the form
743 * # line 500 "foo.pm"
744 * If so, it sets the current line number and file to the values in the comment.
748 S_incline(pTHX_ const char *s)
755 CopLINE_inc(PL_curcop);
758 while (SPACE_OR_TAB(*s))
760 if (strnEQ(s, "line", 4))
764 if (SPACE_OR_TAB(*s))
768 while (SPACE_OR_TAB(*s))
776 while (SPACE_OR_TAB(*s))
778 if (*s == '"' && (t = strchr(s+1, '"'))) {
788 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
790 if (*e != '\n' && *e != '\0')
791 return; /* false alarm */
794 const STRLEN len = t - s;
796 const char * const cf = CopFILE(PL_curcop);
797 STRLEN tmplen = cf ? strlen(cf) : 0;
798 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
799 /* must copy *{"::_<(eval N)[oldfilename:L]"}
800 * to *{"::_<newfilename"} */
801 /* However, the long form of evals is only turned on by the
802 debugger - usually they're "(eval %lu)" */
806 STRLEN tmplen2 = len;
807 if (tmplen + 2 <= sizeof smallbuf)
810 Newx(tmpbuf, tmplen + 2, char);
813 memcpy(tmpbuf + 2, cf, tmplen);
815 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
820 if (tmplen2 + 2 <= sizeof smallbuf)
823 Newx(tmpbuf2, tmplen2 + 2, char);
825 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
826 /* Either they malloc'd it, or we malloc'd it,
827 so no prefix is present in ours. */
832 memcpy(tmpbuf2 + 2, s, tmplen2);
835 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
837 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
838 /* adjust ${"::_<newfilename"} to store the new file name */
839 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
840 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
841 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
844 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
846 if (tmpbuf != smallbuf) Safefree(tmpbuf);
849 CopFILE_free(PL_curcop);
850 CopFILE_setn(PL_curcop, s, len);
852 CopLINE_set(PL_curcop, atoi(n)-1);
856 /* skip space before PL_thistoken */
859 S_skipspace0(pTHX_ register char *s)
866 PL_thiswhite = newSVpvs("");
867 sv_catsv(PL_thiswhite, PL_skipwhite);
868 sv_free(PL_skipwhite);
871 PL_realtokenstart = s - SvPVX(PL_linestr);
875 /* skip space after PL_thistoken */
878 S_skipspace1(pTHX_ register char *s)
880 const char *start = s;
881 I32 startoff = start - SvPVX(PL_linestr);
886 start = SvPVX(PL_linestr) + startoff;
887 if (!PL_thistoken && PL_realtokenstart >= 0) {
888 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
889 PL_thistoken = newSVpvn(tstart, start - tstart);
891 PL_realtokenstart = -1;
894 PL_nextwhite = newSVpvs("");
895 sv_catsv(PL_nextwhite, PL_skipwhite);
896 sv_free(PL_skipwhite);
903 S_skipspace2(pTHX_ register char *s, SV **svp)
906 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
907 const I32 startoff = s - SvPVX(PL_linestr);
910 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
911 if (!PL_madskills || !svp)
913 start = SvPVX(PL_linestr) + startoff;
914 if (!PL_thistoken && PL_realtokenstart >= 0) {
915 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
916 PL_thistoken = newSVpvn(tstart, start - tstart);
917 PL_realtokenstart = -1;
922 sv_setsv(*svp, PL_skipwhite);
923 sv_free(PL_skipwhite);
932 S_update_debugger_info(pTHX_ SV *orig_sv, const char *buf, STRLEN len)
934 AV *av = CopFILEAVx(PL_curcop);
936 SV * const sv = newSV_type(SVt_PVMG);
938 sv_setsv(sv, orig_sv);
940 sv_setpvn(sv, buf, len);
943 av_store(av, (I32)CopLINE(PL_curcop), sv);
949 * Called to gobble the appropriate amount and type of whitespace.
950 * Skips comments as well.
954 S_skipspace(pTHX_ register char *s)
959 int startoff = s - SvPVX(PL_linestr);
962 sv_free(PL_skipwhite);
967 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
968 while (s < PL_bufend && SPACE_OR_TAB(*s))
978 SSize_t oldprevlen, oldoldprevlen;
979 SSize_t oldloplen = 0, oldunilen = 0;
980 while (s < PL_bufend && isSPACE(*s)) {
981 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
986 if (s < PL_bufend && *s == '#') {
987 while (s < PL_bufend && *s != '\n')
991 if (PL_in_eval && !PL_rsfp) {
998 /* only continue to recharge the buffer if we're at the end
999 * of the buffer, we're not reading from a source filter, and
1000 * we're in normal lexing mode
1002 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
1003 PL_lex_state == LEX_FORMLINE)
1010 /* try to recharge the buffer */
1012 curoff = s - SvPVX(PL_linestr);
1015 if ((s = filter_gets(PL_linestr, PL_rsfp,
1016 (prevlen = SvCUR(PL_linestr)))) == NULL)
1019 if (PL_madskills && curoff != startoff) {
1021 PL_skipwhite = newSVpvs("");
1022 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1026 /* mustn't throw out old stuff yet if madpropping */
1027 SvCUR(PL_linestr) = curoff;
1028 s = SvPVX(PL_linestr) + curoff;
1030 if (curoff && s[-1] == '\n')
1034 /* end of file. Add on the -p or -n magic */
1035 /* XXX these shouldn't really be added here, can't set PL_faketokens */
1038 sv_catpvs(PL_linestr,
1039 ";}continue{print or die qq(-p destination: $!\\n);}");
1041 sv_setpvs(PL_linestr,
1042 ";}continue{print or die qq(-p destination: $!\\n);}");
1044 PL_minus_n = PL_minus_p = 0;
1046 else if (PL_minus_n) {
1048 sv_catpvn(PL_linestr, ";}", 2);
1050 sv_setpvn(PL_linestr, ";}", 2);
1056 sv_catpvn(PL_linestr,";", 1);
1058 sv_setpvn(PL_linestr,";", 1);
1061 /* reset variables for next time we lex */
1062 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
1068 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1069 PL_last_lop = PL_last_uni = NULL;
1071 /* Close the filehandle. Could be from -P preprocessor,
1072 * STDIN, or a regular file. If we were reading code from
1073 * STDIN (because the commandline held no -e or filename)
1074 * then we don't close it, we reset it so the code can
1075 * read from STDIN too.
1078 if (PL_preprocess && !PL_in_eval)
1079 (void)PerlProc_pclose(PL_rsfp);
1080 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1081 PerlIO_clearerr(PL_rsfp);
1083 (void)PerlIO_close(PL_rsfp);
1088 /* not at end of file, so we only read another line */
1089 /* make corresponding updates to old pointers, for yyerror() */
1090 oldprevlen = PL_oldbufptr - PL_bufend;
1091 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1093 oldunilen = PL_last_uni - PL_bufend;
1095 oldloplen = PL_last_lop - PL_bufend;
1096 PL_linestart = PL_bufptr = s + prevlen;
1097 PL_bufend = s + SvCUR(PL_linestr);
1099 PL_oldbufptr = s + oldprevlen;
1100 PL_oldoldbufptr = s + oldoldprevlen;
1102 PL_last_uni = s + oldunilen;
1104 PL_last_lop = s + oldloplen;
1107 /* debugger active and we're not compiling the debugger code,
1108 * so store the line into the debugger's array of lines
1110 if (PERLDB_LINE && PL_curstash != PL_debstash)
1111 update_debugger_info(NULL, PL_bufptr, PL_bufend - PL_bufptr);
1118 PL_skipwhite = newSVpvs("");
1119 curoff = s - SvPVX(PL_linestr);
1120 if (curoff - startoff)
1121 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1130 * Check the unary operators to ensure there's no ambiguity in how they're
1131 * used. An ambiguous piece of code would be:
1133 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1134 * the +5 is its argument.
1144 if (PL_oldoldbufptr != PL_last_uni)
1146 while (isSPACE(*PL_last_uni))
1149 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1151 if ((t = strchr(s, '(')) && t < PL_bufptr)
1154 if (ckWARN_d(WARN_AMBIGUOUS)){
1155 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1156 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1157 (int)(s - PL_last_uni), PL_last_uni);
1162 * LOP : macro to build a list operator. Its behaviour has been replaced
1163 * with a subroutine, S_lop() for which LOP is just another name.
1166 #define LOP(f,x) return lop(f,x,s)
1170 * Build a list operator (or something that might be one). The rules:
1171 * - if we have a next token, then it's a list operator [why?]
1172 * - if the next thing is an opening paren, then it's a function
1173 * - else it's a list operator
1177 S_lop(pTHX_ I32 f, int x, char *s)
1184 PL_last_lop = PL_oldbufptr;
1185 PL_last_lop_op = (OPCODE)f;
1188 return REPORT(LSTOP);
1191 return REPORT(LSTOP);
1194 return REPORT(FUNC);
1197 return REPORT(FUNC);
1199 return REPORT(LSTOP);
1205 * Sets up for an eventual force_next(). start_force(0) basically does
1206 * an unshift, while start_force(-1) does a push. yylex removes items
1211 S_start_force(pTHX_ int where)
1215 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1216 where = PL_lasttoke;
1217 assert(PL_curforce < 0 || PL_curforce == where);
1218 if (PL_curforce != where) {
1219 for (i = PL_lasttoke; i > where; --i) {
1220 PL_nexttoke[i] = PL_nexttoke[i-1];
1224 if (PL_curforce < 0) /* in case of duplicate start_force() */
1225 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1226 PL_curforce = where;
1229 curmad('^', newSVpvs(""));
1230 CURMAD('_', PL_nextwhite);
1235 S_curmad(pTHX_ char slot, SV *sv)
1241 if (PL_curforce < 0)
1242 where = &PL_thismad;
1244 where = &PL_nexttoke[PL_curforce].next_mad;
1247 sv_setpvn(sv, "", 0);
1250 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1252 else if (PL_encoding) {
1253 sv_recode_to_utf8(sv, PL_encoding);
1258 /* keep a slot open for the head of the list? */
1259 if (slot != '_' && *where && (*where)->mad_key == '^') {
1260 (*where)->mad_key = slot;
1261 sv_free((*where)->mad_val);
1262 (*where)->mad_val = (void*)sv;
1265 addmad(newMADsv(slot, sv), where, 0);
1268 # define start_force(where) NOOP
1269 # define curmad(slot, sv) NOOP
1274 * When the lexer realizes it knows the next token (for instance,
1275 * it is reordering tokens for the parser) then it can call S_force_next
1276 * to know what token to return the next time the lexer is called. Caller
1277 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1278 * and possibly PL_expect to ensure the lexer handles the token correctly.
1282 S_force_next(pTHX_ I32 type)
1286 if (PL_curforce < 0)
1287 start_force(PL_lasttoke);
1288 PL_nexttoke[PL_curforce].next_type = type;
1289 if (PL_lex_state != LEX_KNOWNEXT)
1290 PL_lex_defer = PL_lex_state;
1291 PL_lex_state = LEX_KNOWNEXT;
1292 PL_lex_expect = PL_expect;
1295 PL_nexttype[PL_nexttoke] = type;
1297 if (PL_lex_state != LEX_KNOWNEXT) {
1298 PL_lex_defer = PL_lex_state;
1299 PL_lex_expect = PL_expect;
1300 PL_lex_state = LEX_KNOWNEXT;
1306 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1309 SV * const sv = newSVpvn(start,len);
1310 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1317 * When the lexer knows the next thing is a word (for instance, it has
1318 * just seen -> and it knows that the next char is a word char, then
1319 * it calls S_force_word to stick the next word into the PL_nexttoke/val
1323 * char *start : buffer position (must be within PL_linestr)
1324 * int token : PL_next* will be this type of bare word (e.g., METHOD,WORD)
1325 * int check_keyword : if true, Perl checks to make sure the word isn't
1326 * a keyword (do this if the word is a label, e.g. goto FOO)
1327 * int allow_pack : if true, : characters will also be allowed (require,
1328 * use, etc. do this)
1329 * int allow_initial_tick : used by the "sub" lexer only.
1333 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1339 start = SKIPSPACE1(start);
1341 if (isIDFIRST_lazy_if(s,UTF) ||
1342 (allow_pack && *s == ':') ||
1343 (allow_initial_tick && *s == '\'') )
1345 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1346 if (check_keyword && keyword(PL_tokenbuf, len, 0))
1348 start_force(PL_curforce);
1350 curmad('X', newSVpvn(start,s-start));
1351 if (token == METHOD) {
1356 PL_expect = XOPERATOR;
1360 curmad('g', newSVpvs( "forced" ));
1361 NEXTVAL_NEXTTOKE.opval
1362 = (OP*)newSVOP(OP_CONST,0,
1363 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1364 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1372 * Called when the lexer wants $foo *foo &foo etc, but the program
1373 * text only contains the "foo" portion. The first argument is a pointer
1374 * to the "foo", and the second argument is the type symbol to prefix.
1375 * Forces the next token to be a "WORD".
1376 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1380 S_force_ident(pTHX_ register const char *s, int kind)
1384 const STRLEN len = strlen(s);
1385 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1386 start_force(PL_curforce);
1387 NEXTVAL_NEXTTOKE.opval = o;
1390 o->op_private = OPpCONST_ENTERED;
1391 /* XXX see note in pp_entereval() for why we forgo typo
1392 warnings if the symbol must be introduced in an eval.
1394 gv_fetchpvn_flags(s, len,
1395 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1397 kind == '$' ? SVt_PV :
1398 kind == '@' ? SVt_PVAV :
1399 kind == '%' ? SVt_PVHV :
1407 Perl_str_to_version(pTHX_ SV *sv)
1412 const char *start = SvPV_const(sv,len);
1413 const char * const end = start + len;
1414 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1415 while (start < end) {
1419 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1424 retval += ((NV)n)/nshift;
1433 * Forces the next token to be a version number.
1434 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1435 * and if "guessing" is TRUE, then no new token is created (and the caller
1436 * must use an alternative parsing method).
1440 S_force_version(pTHX_ char *s, int guessing)
1446 I32 startoff = s - SvPVX(PL_linestr);
1455 while (isDIGIT(*d) || *d == '_' || *d == '.')
1459 start_force(PL_curforce);
1460 curmad('X', newSVpvn(s,d-s));
1463 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1465 s = scan_num(s, &yylval);
1466 version = yylval.opval;
1467 ver = cSVOPx(version)->op_sv;
1468 if (SvPOK(ver) && !SvNIOK(ver)) {
1469 SvUPGRADE(ver, SVt_PVNV);
1470 SvNV_set(ver, str_to_version(ver));
1471 SvNOK_on(ver); /* hint that it is a version */
1474 else if (guessing) {
1477 sv_free(PL_nextwhite); /* let next token collect whitespace */
1479 s = SvPVX(PL_linestr) + startoff;
1487 if (PL_madskills && !version) {
1488 sv_free(PL_nextwhite); /* let next token collect whitespace */
1490 s = SvPVX(PL_linestr) + startoff;
1493 /* NOTE: The parser sees the package name and the VERSION swapped */
1494 start_force(PL_curforce);
1495 NEXTVAL_NEXTTOKE.opval = version;
1503 * Tokenize a quoted string passed in as an SV. It finds the next
1504 * chunk, up to end of string or a backslash. It may make a new
1505 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1510 S_tokeq(pTHX_ SV *sv)
1514 register char *send;
1522 s = SvPV_force(sv, len);
1523 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1526 while (s < send && *s != '\\')
1531 if ( PL_hints & HINT_NEW_STRING ) {
1532 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1538 if (s + 1 < send && (s[1] == '\\'))
1539 s++; /* all that, just for this */
1544 SvCUR_set(sv, d - SvPVX_const(sv));
1546 if ( PL_hints & HINT_NEW_STRING )
1547 return new_constant(NULL, 0, "q", sv, pv, "q");
1552 * Now come three functions related to double-quote context,
1553 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1554 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1555 * interact with PL_lex_state, and create fake ( ... ) argument lists
1556 * to handle functions and concatenation.
1557 * They assume that whoever calls them will be setting up a fake
1558 * join call, because each subthing puts a ',' after it. This lets
1561 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1563 * (I'm not sure whether the spurious commas at the end of lcfirst's
1564 * arguments and join's arguments are created or not).
1569 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1571 * Pattern matching will set PL_lex_op to the pattern-matching op to
1572 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1574 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1576 * Everything else becomes a FUNC.
1578 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1579 * had an OP_CONST or OP_READLINE). This just sets us up for a
1580 * call to S_sublex_push().
1584 S_sublex_start(pTHX)
1587 register const I32 op_type = yylval.ival;
1589 if (op_type == OP_NULL) {
1590 yylval.opval = PL_lex_op;
1594 if (op_type == OP_CONST || op_type == OP_READLINE) {
1595 SV *sv = tokeq(PL_lex_stuff);
1597 if (SvTYPE(sv) == SVt_PVIV) {
1598 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1600 const char * const p = SvPV_const(sv, len);
1601 SV * const nsv = newSVpvn(p, len);
1607 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1608 PL_lex_stuff = NULL;
1609 /* Allow <FH> // "foo" */
1610 if (op_type == OP_READLINE)
1611 PL_expect = XTERMORDORDOR;
1614 else if (op_type == OP_BACKTICK && PL_lex_op) {
1615 /* readpipe() vas overriden */
1616 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1617 yylval.opval = PL_lex_op;
1619 PL_lex_stuff = NULL;
1623 PL_sublex_info.super_state = PL_lex_state;
1624 PL_sublex_info.sub_inwhat = (U16)op_type;
1625 PL_sublex_info.sub_op = PL_lex_op;
1626 PL_lex_state = LEX_INTERPPUSH;
1630 yylval.opval = PL_lex_op;
1640 * Create a new scope to save the lexing state. The scope will be
1641 * ended in S_sublex_done. Returns a '(', starting the function arguments
1642 * to the uc, lc, etc. found before.
1643 * Sets PL_lex_state to LEX_INTERPCONCAT.
1652 PL_lex_state = PL_sublex_info.super_state;
1653 SAVEBOOL(PL_lex_dojoin);
1654 SAVEI32(PL_lex_brackets);
1655 SAVEI32(PL_lex_casemods);
1656 SAVEI32(PL_lex_starts);
1657 SAVEI8(PL_lex_state);
1658 SAVEVPTR(PL_lex_inpat);
1659 SAVEI16(PL_lex_inwhat);
1660 SAVECOPLINE(PL_curcop);
1661 SAVEPPTR(PL_bufptr);
1662 SAVEPPTR(PL_bufend);
1663 SAVEPPTR(PL_oldbufptr);
1664 SAVEPPTR(PL_oldoldbufptr);
1665 SAVEPPTR(PL_last_lop);
1666 SAVEPPTR(PL_last_uni);
1667 SAVEPPTR(PL_linestart);
1668 SAVESPTR(PL_linestr);
1669 SAVEGENERICPV(PL_lex_brackstack);
1670 SAVEGENERICPV(PL_lex_casestack);
1672 PL_linestr = PL_lex_stuff;
1673 PL_lex_stuff = NULL;
1675 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1676 = SvPVX(PL_linestr);
1677 PL_bufend += SvCUR(PL_linestr);
1678 PL_last_lop = PL_last_uni = NULL;
1679 SAVEFREESV(PL_linestr);
1681 PL_lex_dojoin = FALSE;
1682 PL_lex_brackets = 0;
1683 Newx(PL_lex_brackstack, 120, char);
1684 Newx(PL_lex_casestack, 12, char);
1685 PL_lex_casemods = 0;
1686 *PL_lex_casestack = '\0';
1688 PL_lex_state = LEX_INTERPCONCAT;
1689 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1691 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1692 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1693 PL_lex_inpat = PL_sublex_info.sub_op;
1695 PL_lex_inpat = NULL;
1702 * Restores lexer state after a S_sublex_push.
1709 if (!PL_lex_starts++) {
1710 SV * const sv = newSVpvs("");
1711 if (SvUTF8(PL_linestr))
1713 PL_expect = XOPERATOR;
1714 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1718 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1719 PL_lex_state = LEX_INTERPCASEMOD;
1723 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1724 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1725 PL_linestr = PL_lex_repl;
1727 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1728 PL_bufend += SvCUR(PL_linestr);
1729 PL_last_lop = PL_last_uni = NULL;
1730 SAVEFREESV(PL_linestr);
1731 PL_lex_dojoin = FALSE;
1732 PL_lex_brackets = 0;
1733 PL_lex_casemods = 0;
1734 *PL_lex_casestack = '\0';
1736 if (SvEVALED(PL_lex_repl)) {
1737 PL_lex_state = LEX_INTERPNORMAL;
1739 /* we don't clear PL_lex_repl here, so that we can check later
1740 whether this is an evalled subst; that means we rely on the
1741 logic to ensure sublex_done() is called again only via the
1742 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1745 PL_lex_state = LEX_INTERPCONCAT;
1755 PL_endwhite = newSVpvs("");
1756 sv_catsv(PL_endwhite, PL_thiswhite);
1760 sv_setpvn(PL_thistoken,"",0);
1762 PL_realtokenstart = -1;
1766 PL_bufend = SvPVX(PL_linestr);
1767 PL_bufend += SvCUR(PL_linestr);
1768 PL_expect = XOPERATOR;
1769 PL_sublex_info.sub_inwhat = 0;
1777 Extracts a pattern, double-quoted string, or transliteration. This
1780 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
1781 processing a pattern (PL_lex_inpat is true), a transliteration
1782 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
1784 Returns a pointer to the character scanned up to. If this is
1785 advanced from the start pointer supplied (i.e. if anything was
1786 successfully parsed), will leave an OP for the substring scanned
1787 in yylval. Caller must intuit reason for not parsing further
1788 by looking at the next characters herself.
1792 double-quoted style: \r and \n
1793 regexp special ones: \D \s
1796 case and quoting: \U \Q \E
1797 stops on @ and $, but not for $ as tail anchor
1799 In transliterations:
1800 characters are VERY literal, except for - not at the start or end
1801 of the string, which indicates a range. If the range is in bytes,
1802 scan_const expands the range to the full set of intermediate
1803 characters. If the range is in utf8, the hyphen is replaced with
1804 a certain range mark which will be handled by pmtrans() in op.c.
1806 In double-quoted strings:
1808 double-quoted style: \r and \n
1810 deprecated backrefs: \1 (in substitution replacements)
1811 case and quoting: \U \Q \E
1814 scan_const does *not* construct ops to handle interpolated strings.
1815 It stops processing as soon as it finds an embedded $ or @ variable
1816 and leaves it to the caller to work out what's going on.
1818 embedded arrays (whether in pattern or not) could be:
1819 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1821 $ in double-quoted strings must be the symbol of an embedded scalar.
1823 $ in pattern could be $foo or could be tail anchor. Assumption:
1824 it's a tail anchor if $ is the last thing in the string, or if it's
1825 followed by one of "()| \r\n\t"
1827 \1 (backreferences) are turned into $1
1829 The structure of the code is
1830 while (there's a character to process) {
1831 handle transliteration ranges
1832 skip regexp comments /(?#comment)/ and codes /(?{code})/
1833 skip #-initiated comments in //x patterns
1834 check for embedded arrays
1835 check for embedded scalars
1837 leave intact backslashes from leaveit (below)
1838 deprecate \1 in substitution replacements
1839 handle string-changing backslashes \l \U \Q \E, etc.
1840 switch (what was escaped) {
1841 handle \- in a transliteration (becomes a literal -)
1842 handle \132 (octal characters)
1843 handle \x15 and \x{1234} (hex characters)
1844 handle \N{name} (named characters)
1845 handle \cV (control characters)
1846 handle printf-style backslashes (\f, \r, \n, etc)
1848 } (end if backslash)
1849 } (end while character to read)
1854 S_scan_const(pTHX_ char *start)
1857 register char *send = PL_bufend; /* end of the constant */
1858 SV *sv = newSV(send - start); /* sv for the constant */
1859 register char *s = start; /* start of the constant */
1860 register char *d = SvPVX(sv); /* destination for copies */
1861 bool dorange = FALSE; /* are we in a translit range? */
1862 bool didrange = FALSE; /* did we just finish a range? */
1863 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1864 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1867 UV literal_endpoint = 0;
1868 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
1871 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1872 /* If we are doing a trans and we know we want UTF8 set expectation */
1873 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1874 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1878 while (s < send || dorange) {
1879 /* get transliterations out of the way (they're most literal) */
1880 if (PL_lex_inwhat == OP_TRANS) {
1881 /* expand a range A-Z to the full set of characters. AIE! */
1883 I32 i; /* current expanded character */
1884 I32 min; /* first character in range */
1885 I32 max; /* last character in range */
1896 char * const c = (char*)utf8_hop((U8*)d, -1);
1900 *c = (char)UTF_TO_NATIVE(0xff);
1901 /* mark the range as done, and continue */
1907 i = d - SvPVX_const(sv); /* remember current offset */
1910 SvLEN(sv) + (has_utf8 ?
1911 (512 - UTF_CONTINUATION_MARK +
1914 /* How many two-byte within 0..255: 128 in UTF-8,
1915 * 96 in UTF-8-mod. */
1917 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1919 d = SvPVX(sv) + i; /* refresh d after realloc */
1923 for (j = 0; j <= 1; j++) {
1924 char * const c = (char*)utf8_hop((U8*)d, -1);
1925 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
1931 max = (U8)0xff; /* only to \xff */
1932 uvmax = uv; /* \x{100} to uvmax */
1934 d = c; /* eat endpoint chars */
1939 d -= 2; /* eat the first char and the - */
1940 min = (U8)*d; /* first char in range */
1941 max = (U8)d[1]; /* last char in range */
1948 "Invalid range \"%c-%c\" in transliteration operator",
1949 (char)min, (char)max);
1953 if (literal_endpoint == 2 &&
1954 ((isLOWER(min) && isLOWER(max)) ||
1955 (isUPPER(min) && isUPPER(max)))) {
1957 for (i = min; i <= max; i++)
1959 *d++ = NATIVE_TO_NEED(has_utf8,i);
1961 for (i = min; i <= max; i++)
1963 *d++ = NATIVE_TO_NEED(has_utf8,i);
1968 for (i = min; i <= max; i++)
1971 const U8 ch = (U8)NATIVE_TO_UTF(i);
1972 if (UNI_IS_INVARIANT(ch))
1975 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
1976 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
1985 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
1987 *d++ = (char)UTF_TO_NATIVE(0xff);
1989 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
1993 /* mark the range as done, and continue */
1997 literal_endpoint = 0;
2002 /* range begins (ignore - as first or last char) */
2003 else if (*s == '-' && s+1 < send && s != start) {
2005 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
2012 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
2022 literal_endpoint = 0;
2023 native_range = TRUE;
2028 /* if we get here, we're not doing a transliteration */
2030 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2031 except for the last char, which will be done separately. */
2032 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
2034 while (s+1 < send && *s != ')')
2035 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2037 else if (s[2] == '{' /* This should match regcomp.c */
2038 || (s[2] == '?' && s[3] == '{'))
2041 char *regparse = s + (s[2] == '{' ? 3 : 4);
2044 while (count && (c = *regparse)) {
2045 if (c == '\\' && regparse[1])
2053 if (*regparse != ')')
2054 regparse--; /* Leave one char for continuation. */
2055 while (s < regparse)
2056 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2060 /* likewise skip #-initiated comments in //x patterns */
2061 else if (*s == '#' && PL_lex_inpat &&
2062 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2063 while (s+1 < send && *s != '\n')
2064 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2067 /* check for embedded arrays
2068 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2070 else if (*s == '@' && s[1]) {
2071 if (isALNUM_lazy_if(s+1,UTF))
2073 if (strchr(":'{$", s[1]))
2075 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2076 break; /* in regexp, neither @+ nor @- are interpolated */
2079 /* check for embedded scalars. only stop if we're sure it's a
2082 else if (*s == '$') {
2083 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
2085 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
2086 break; /* in regexp, $ might be tail anchor */
2089 /* End of else if chain - OP_TRANS rejoin rest */
2092 if (*s == '\\' && s+1 < send) {
2095 /* deprecate \1 in strings and substitution replacements */
2096 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2097 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2099 if (ckWARN(WARN_SYNTAX))
2100 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2105 /* string-change backslash escapes */
2106 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2110 /* skip any other backslash escapes in a pattern */
2111 else if (PL_lex_inpat) {
2112 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2113 goto default_action;
2116 /* if we get here, it's either a quoted -, or a digit */
2119 /* quoted - in transliterations */
2121 if (PL_lex_inwhat == OP_TRANS) {
2128 if ((isALPHA(*s) || isDIGIT(*s)) &&
2130 Perl_warner(aTHX_ packWARN(WARN_MISC),
2131 "Unrecognized escape \\%c passed through",
2133 /* default action is to copy the quoted character */
2134 goto default_action;
2137 /* \132 indicates an octal constant */
2138 case '0': case '1': case '2': case '3':
2139 case '4': case '5': case '6': case '7':
2143 uv = grok_oct(s, &len, &flags, NULL);
2146 goto NUM_ESCAPE_INSERT;
2148 /* \x24 indicates a hex constant */
2152 char* const e = strchr(s, '}');
2153 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2154 PERL_SCAN_DISALLOW_PREFIX;
2159 yyerror("Missing right brace on \\x{}");
2163 uv = grok_hex(s, &len, &flags, NULL);
2169 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2170 uv = grok_hex(s, &len, &flags, NULL);
2176 /* Insert oct or hex escaped character.
2177 * There will always enough room in sv since such
2178 * escapes will be longer than any UTF-8 sequence
2179 * they can end up as. */
2181 /* We need to map to chars to ASCII before doing the tests
2184 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2185 if (!has_utf8 && uv > 255) {
2186 /* Might need to recode whatever we have
2187 * accumulated so far if it contains any
2190 * (Can't we keep track of that and avoid
2191 * this rescan? --jhi)
2195 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2196 if (!NATIVE_IS_INVARIANT(*c)) {
2201 const STRLEN offset = d - SvPVX_const(sv);
2203 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2207 while (src >= (const U8 *)SvPVX_const(sv)) {
2208 if (!NATIVE_IS_INVARIANT(*src)) {
2209 const U8 ch = NATIVE_TO_ASCII(*src);
2210 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2211 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2221 if (has_utf8 || uv > 255) {
2222 d = (char*)uvchr_to_utf8((U8*)d, uv);
2224 if (PL_lex_inwhat == OP_TRANS &&
2225 PL_sublex_info.sub_op) {
2226 PL_sublex_info.sub_op->op_private |=
2227 (PL_lex_repl ? OPpTRANS_FROM_UTF
2231 if (uv > 255 && !dorange)
2232 native_range = FALSE;
2244 /* \N{LATIN SMALL LETTER A} is a named character */
2248 char* e = strchr(s, '}');
2255 yyerror("Missing right brace on \\N{}");
2259 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2261 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2262 PERL_SCAN_DISALLOW_PREFIX;
2265 uv = grok_hex(s, &len, &flags, NULL);
2266 if ( e > s && len != (STRLEN)(e - s) ) {
2270 goto NUM_ESCAPE_INSERT;
2272 res = newSVpvn(s + 1, e - s - 1);
2273 type = newSVpvn(s - 2,e - s + 3);
2274 res = new_constant( NULL, 0, "charnames",
2275 res, NULL, SvPVX(type) );
2278 sv_utf8_upgrade(res);
2279 str = SvPV_const(res,len);
2280 #ifdef EBCDIC_NEVER_MIND
2281 /* charnames uses pack U and that has been
2282 * recently changed to do the below uni->native
2283 * mapping, so this would be redundant (and wrong,
2284 * the code point would be doubly converted).
2285 * But leave this in just in case the pack U change
2286 * gets revoked, but the semantics is still
2287 * desireable for charnames. --jhi */
2289 UV uv = utf8_to_uvchr((const U8*)str, 0);
2292 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2294 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2295 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2296 str = SvPV_const(res, len);
2300 if (!has_utf8 && SvUTF8(res)) {
2301 const char * const ostart = SvPVX_const(sv);
2302 SvCUR_set(sv, d - ostart);
2305 sv_utf8_upgrade(sv);
2306 /* this just broke our allocation above... */
2307 SvGROW(sv, (STRLEN)(send - start));
2308 d = SvPVX(sv) + SvCUR(sv);
2311 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2312 const char * const odest = SvPVX_const(sv);
2314 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2315 d = SvPVX(sv) + (d - odest);
2319 native_range = FALSE; /* \N{} is guessed to be Unicode */
2321 Copy(str, d, len, char);
2328 yyerror("Missing braces on \\N{}");
2331 /* \c is a control character */
2340 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2343 yyerror("Missing control char name in \\c");
2347 /* printf-style backslashes, formfeeds, newlines, etc */
2349 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2352 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2355 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2358 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2361 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2364 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2367 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2373 } /* end if (backslash) */
2380 /* If we started with encoded form, or already know we want it
2381 and then encode the next character */
2382 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2384 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2385 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2388 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2389 const STRLEN off = d - SvPVX_const(sv);
2390 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2392 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2395 if (uv > 255 && !dorange)
2396 native_range = FALSE;
2400 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2402 } /* while loop to process each character */
2404 /* terminate the string and set up the sv */
2406 SvCUR_set(sv, d - SvPVX_const(sv));
2407 if (SvCUR(sv) >= SvLEN(sv))
2408 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2411 if (PL_encoding && !has_utf8) {
2412 sv_recode_to_utf8(sv, PL_encoding);
2418 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2419 PL_sublex_info.sub_op->op_private |=
2420 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2424 /* shrink the sv if we allocated more than we used */
2425 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2426 SvPV_shrink_to_cur(sv);
2429 /* return the substring (via yylval) only if we parsed anything */
2430 if (s > PL_bufptr) {
2431 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2432 sv = new_constant(start, s - start,
2433 (const char *)(PL_lex_inpat ? "qr" : "q"),
2436 (( PL_lex_inwhat == OP_TRANS
2438 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2441 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2448 * Returns TRUE if there's more to the expression (e.g., a subscript),
2451 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2453 * ->[ and ->{ return TRUE
2454 * { and [ outside a pattern are always subscripts, so return TRUE
2455 * if we're outside a pattern and it's not { or [, then return FALSE
2456 * if we're in a pattern and the first char is a {
2457 * {4,5} (any digits around the comma) returns FALSE
2458 * if we're in a pattern and the first char is a [
2460 * [SOMETHING] has a funky algorithm to decide whether it's a
2461 * character class or not. It has to deal with things like
2462 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2463 * anything else returns TRUE
2466 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2469 S_intuit_more(pTHX_ register char *s)
2472 if (PL_lex_brackets)
2474 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2476 if (*s != '{' && *s != '[')
2481 /* In a pattern, so maybe we have {n,m}. */
2498 /* On the other hand, maybe we have a character class */
2501 if (*s == ']' || *s == '^')
2504 /* this is terrifying, and it works */
2505 int weight = 2; /* let's weigh the evidence */
2507 unsigned char un_char = 255, last_un_char;
2508 const char * const send = strchr(s,']');
2509 char tmpbuf[sizeof PL_tokenbuf * 4];
2511 if (!send) /* has to be an expression */
2514 Zero(seen,256,char);
2517 else if (isDIGIT(*s)) {
2519 if (isDIGIT(s[1]) && s[2] == ']')
2525 for (; s < send; s++) {
2526 last_un_char = un_char;
2527 un_char = (unsigned char)*s;
2532 weight -= seen[un_char] * 10;
2533 if (isALNUM_lazy_if(s+1,UTF)) {
2535 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2536 len = (int)strlen(tmpbuf);
2537 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2542 else if (*s == '$' && s[1] &&
2543 strchr("[#!%*<>()-=",s[1])) {
2544 if (/*{*/ strchr("])} =",s[2]))
2553 if (strchr("wds]",s[1]))
2555 else if (seen[(U8)'\''] || seen[(U8)'"'])
2557 else if (strchr("rnftbxcav",s[1]))
2559 else if (isDIGIT(s[1])) {
2561 while (s[1] && isDIGIT(s[1]))
2571 if (strchr("aA01! ",last_un_char))
2573 if (strchr("zZ79~",s[1]))
2575 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2576 weight -= 5; /* cope with negative subscript */
2579 if (!isALNUM(last_un_char)
2580 && !(last_un_char == '$' || last_un_char == '@'
2581 || last_un_char == '&')
2582 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2587 if (keyword(tmpbuf, d - tmpbuf, 0))
2590 if (un_char == last_un_char + 1)
2592 weight -= seen[un_char];
2597 if (weight >= 0) /* probably a character class */
2607 * Does all the checking to disambiguate
2609 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2610 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2612 * First argument is the stuff after the first token, e.g. "bar".
2614 * Not a method if bar is a filehandle.
2615 * Not a method if foo is a subroutine prototyped to take a filehandle.
2616 * Not a method if it's really "Foo $bar"
2617 * Method if it's "foo $bar"
2618 * Not a method if it's really "print foo $bar"
2619 * Method if it's really "foo package::" (interpreted as package->foo)
2620 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2621 * Not a method if bar is a filehandle or package, but is quoted with
2626 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2629 char *s = start + (*start == '$');
2630 char tmpbuf[sizeof PL_tokenbuf];
2638 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2642 const char *proto = SvPVX_const(cv);
2653 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2654 /* start is the beginning of the possible filehandle/object,
2655 * and s is the end of it
2656 * tmpbuf is a copy of it
2659 if (*start == '$') {
2660 if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
2661 isUPPER(*PL_tokenbuf))
2664 len = start - SvPVX(PL_linestr);
2668 start = SvPVX(PL_linestr) + len;
2672 return *s == '(' ? FUNCMETH : METHOD;
2674 if (!keyword(tmpbuf, len, 0)) {
2675 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2679 soff = s - SvPVX(PL_linestr);
2683 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2684 if (indirgv && GvCVu(indirgv))
2686 /* filehandle or package name makes it a method */
2687 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
2689 soff = s - SvPVX(PL_linestr);
2692 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2693 return 0; /* no assumptions -- "=>" quotes bearword */
2695 start_force(PL_curforce);
2696 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2697 newSVpvn(tmpbuf,len));
2698 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2700 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2705 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2707 return *s == '(' ? FUNCMETH : METHOD;
2715 * Return a string of Perl code to load the debugger. If PERL5DB
2716 * is set, it will return the contents of that, otherwise a
2717 * compile-time require of perl5db.pl.
2725 const char * const pdb = PerlEnv_getenv("PERL5DB");
2729 SETERRNO(0,SS_NORMAL);
2730 return "BEGIN { require 'perl5db.pl' }";
2736 /* Encoded script support. filter_add() effectively inserts a
2737 * 'pre-processing' function into the current source input stream.
2738 * Note that the filter function only applies to the current source file
2739 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2741 * The datasv parameter (which may be NULL) can be used to pass
2742 * private data to this instance of the filter. The filter function
2743 * can recover the SV using the FILTER_DATA macro and use it to
2744 * store private buffers and state information.
2746 * The supplied datasv parameter is upgraded to a PVIO type
2747 * and the IoDIRP/IoANY field is used to store the function pointer,
2748 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2749 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2750 * private use must be set using malloc'd pointers.
2754 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2760 if (!PL_rsfp_filters)
2761 PL_rsfp_filters = newAV();
2764 SvUPGRADE(datasv, SVt_PVIO);
2765 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2766 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2767 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2768 FPTR2DPTR(void *, IoANY(datasv)),
2769 SvPV_nolen(datasv)));
2770 av_unshift(PL_rsfp_filters, 1);
2771 av_store(PL_rsfp_filters, 0, datasv) ;
2776 /* Delete most recently added instance of this filter function. */
2778 Perl_filter_del(pTHX_ filter_t funcp)
2784 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2785 FPTR2DPTR(void*, funcp)));
2787 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2789 /* if filter is on top of stack (usual case) just pop it off */
2790 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2791 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2792 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2793 IoANY(datasv) = (void *)NULL;
2794 sv_free(av_pop(PL_rsfp_filters));
2798 /* we need to search for the correct entry and clear it */
2799 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2803 /* Invoke the idxth filter function for the current rsfp. */
2804 /* maxlen 0 = read one text line */
2806 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2811 /* This API is bad. It should have been using unsigned int for maxlen.
2812 Not sure if we want to change the API, but if not we should sanity
2813 check the value here. */
2814 const unsigned int correct_length
2823 if (!PL_rsfp_filters)
2825 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2826 /* Provide a default input filter to make life easy. */
2827 /* Note that we append to the line. This is handy. */
2828 DEBUG_P(PerlIO_printf(Perl_debug_log,
2829 "filter_read %d: from rsfp\n", idx));
2830 if (correct_length) {
2833 const int old_len = SvCUR(buf_sv);
2835 /* ensure buf_sv is large enough */
2836 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2837 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2838 correct_length)) <= 0) {
2839 if (PerlIO_error(PL_rsfp))
2840 return -1; /* error */
2842 return 0 ; /* end of file */
2844 SvCUR_set(buf_sv, old_len + len) ;
2847 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2848 if (PerlIO_error(PL_rsfp))
2849 return -1; /* error */
2851 return 0 ; /* end of file */
2854 return SvCUR(buf_sv);
2856 /* Skip this filter slot if filter has been deleted */
2857 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2858 DEBUG_P(PerlIO_printf(Perl_debug_log,
2859 "filter_read %d: skipped (filter deleted)\n",
2861 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2863 /* Get function pointer hidden within datasv */
2864 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2865 DEBUG_P(PerlIO_printf(Perl_debug_log,
2866 "filter_read %d: via function %p (%s)\n",
2867 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2868 /* Call function. The function is expected to */
2869 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2870 /* Return: <0:error, =0:eof, >0:not eof */
2871 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2875 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2878 #ifdef PERL_CR_FILTER
2879 if (!PL_rsfp_filters) {
2880 filter_add(S_cr_textfilter,NULL);
2883 if (PL_rsfp_filters) {
2885 SvCUR_set(sv, 0); /* start with empty line */
2886 if (FILTER_READ(0, sv, 0) > 0)
2887 return ( SvPVX(sv) ) ;
2892 return (sv_gets(sv, fp, append));
2896 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2901 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2905 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2906 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2908 return GvHV(gv); /* Foo:: */
2911 /* use constant CLASS => 'MyClass' */
2912 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2913 if (gv && GvCV(gv)) {
2914 SV * const sv = cv_const_sv(GvCV(gv));
2916 pkgname = SvPV_nolen_const(sv);
2919 return gv_stashpv(pkgname, 0);
2923 * S_readpipe_override
2924 * Check whether readpipe() is overriden, and generates the appropriate
2925 * optree, provided sublex_start() is called afterwards.
2928 S_readpipe_override(pTHX)
2931 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
2932 yylval.ival = OP_BACKTICK;
2934 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
2936 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
2937 && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
2938 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
2940 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
2941 append_elem(OP_LIST,
2942 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
2943 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
2953 * The intent of this yylex wrapper is to minimize the changes to the
2954 * tokener when we aren't interested in collecting madprops. It remains
2955 * to be seen how successful this strategy will be...
2962 char *s = PL_bufptr;
2964 /* make sure PL_thiswhite is initialized */
2968 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2969 if (PL_pending_ident)
2970 return S_pending_ident(aTHX);
2972 /* previous token ate up our whitespace? */
2973 if (!PL_lasttoke && PL_nextwhite) {
2974 PL_thiswhite = PL_nextwhite;
2978 /* isolate the token, and figure out where it is without whitespace */
2979 PL_realtokenstart = -1;
2983 assert(PL_curforce < 0);
2985 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2986 if (!PL_thistoken) {
2987 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2988 PL_thistoken = newSVpvs("");
2990 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2991 PL_thistoken = newSVpvn(tstart, s - tstart);
2994 if (PL_thismad) /* install head */
2995 CURMAD('X', PL_thistoken);
2998 /* last whitespace of a sublex? */
2999 if (optype == ')' && PL_endwhite) {
3000 CURMAD('X', PL_endwhite);
3005 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
3006 if (!PL_thiswhite && !PL_endwhite && !optype) {
3007 sv_free(PL_thistoken);
3012 /* put off final whitespace till peg */
3013 if (optype == ';' && !PL_rsfp) {
3014 PL_nextwhite = PL_thiswhite;
3017 else if (PL_thisopen) {
3018 CURMAD('q', PL_thisopen);
3020 sv_free(PL_thistoken);
3024 /* Store actual token text as madprop X */
3025 CURMAD('X', PL_thistoken);
3029 /* add preceding whitespace as madprop _ */
3030 CURMAD('_', PL_thiswhite);
3034 /* add quoted material as madprop = */
3035 CURMAD('=', PL_thisstuff);
3039 /* add terminating quote as madprop Q */
3040 CURMAD('Q', PL_thisclose);
3044 /* special processing based on optype */
3048 /* opval doesn't need a TOKEN since it can already store mp */
3059 append_madprops(PL_thismad, yylval.opval, 0);
3067 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3076 /* remember any fake bracket that lexer is about to discard */
3077 if (PL_lex_brackets == 1 &&
3078 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3081 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3084 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3085 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3088 break; /* don't bother looking for trailing comment */
3097 /* attach a trailing comment to its statement instead of next token */
3101 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3103 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3105 if (*s == '\n' || *s == '#') {
3106 while (s < PL_bufend && *s != '\n')
3110 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3111 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3128 /* Create new token struct. Note: opvals return early above. */
3129 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
3136 S_tokenize_use(pTHX_ int is_use, char *s) {
3138 if (PL_expect != XSTATE)
3139 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3140 is_use ? "use" : "no"));
3142 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3143 s = force_version(s, TRUE);
3144 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3145 start_force(PL_curforce);
3146 NEXTVAL_NEXTTOKE.opval = NULL;
3149 else if (*s == 'v') {
3150 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3151 s = force_version(s, FALSE);
3155 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3156 s = force_version(s, FALSE);
3158 yylval.ival = is_use;
3162 static const char* const exp_name[] =
3163 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3164 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3171 Works out what to call the token just pulled out of the input
3172 stream. The yacc parser takes care of taking the ops we return and
3173 stitching them into a tree.
3179 if read an identifier
3180 if we're in a my declaration
3181 croak if they tried to say my($foo::bar)
3182 build the ops for a my() declaration
3183 if it's an access to a my() variable
3184 are we in a sort block?
3185 croak if my($a); $a <=> $b
3186 build ops for access to a my() variable
3187 if in a dq string, and they've said @foo and we can't find @foo
3189 build ops for a bareword
3190 if we already built the token before, use it.
3195 #pragma segment Perl_yylex
3201 register char *s = PL_bufptr;
3206 /* orig_keyword, gvp, and gv are initialized here because
3207 * jump to the label just_a_word_zero can bypass their
3208 * initialization later. */
3209 I32 orig_keyword = 0;
3214 SV* tmp = newSVpvs("");
3215 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3216 (IV)CopLINE(PL_curcop),
3217 lex_state_names[PL_lex_state],
3218 exp_name[PL_expect],
3219 pv_display(tmp, s, strlen(s), 0, 60));
3222 /* check if there's an identifier for us to look at */
3223 if (PL_pending_ident)
3224 return REPORT(S_pending_ident(aTHX));
3226 /* no identifier pending identification */
3228 switch (PL_lex_state) {
3230 case LEX_NORMAL: /* Some compilers will produce faster */
3231 case LEX_INTERPNORMAL: /* code if we comment these out. */
3235 /* when we've already built the next token, just pull it out of the queue */
3239 yylval = PL_nexttoke[PL_lasttoke].next_val;
3241 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3242 PL_nexttoke[PL_lasttoke].next_mad = 0;
3243 if (PL_thismad && PL_thismad->mad_key == '_') {
3244 PL_thiswhite = (SV*)PL_thismad->mad_val;
3245 PL_thismad->mad_val = 0;
3246 mad_free(PL_thismad);
3251 PL_lex_state = PL_lex_defer;
3252 PL_expect = PL_lex_expect;
3253 PL_lex_defer = LEX_NORMAL;
3254 if (!PL_nexttoke[PL_lasttoke].next_type)
3259 yylval = PL_nextval[PL_nexttoke];
3261 PL_lex_state = PL_lex_defer;
3262 PL_expect = PL_lex_expect;
3263 PL_lex_defer = LEX_NORMAL;
3267 /* FIXME - can these be merged? */
3268 return(PL_nexttoke[PL_lasttoke].next_type);
3270 return REPORT(PL_nexttype[PL_nexttoke]);
3273 /* interpolated case modifiers like \L \U, including \Q and \E.
3274 when we get here, PL_bufptr is at the \
3276 case LEX_INTERPCASEMOD:
3278 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3279 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3281 /* handle \E or end of string */
3282 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3284 if (PL_lex_casemods) {
3285 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3286 PL_lex_casestack[PL_lex_casemods] = '\0';
3288 if (PL_bufptr != PL_bufend
3289 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3291 PL_lex_state = LEX_INTERPCONCAT;
3294 PL_thistoken = newSVpvs("\\E");
3300 while (PL_bufptr != PL_bufend &&
3301 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3303 PL_thiswhite = newSVpvs("");
3304 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3308 if (PL_bufptr != PL_bufend)
3311 PL_lex_state = LEX_INTERPCONCAT;
3315 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3316 "### Saw case modifier\n"); });
3318 if (s[1] == '\\' && s[2] == 'E') {
3321 PL_thiswhite = newSVpvs("");
3322 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3325 PL_lex_state = LEX_INTERPCONCAT;
3330 if (!PL_madskills) /* when just compiling don't need correct */
3331 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3332 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3333 if ((*s == 'L' || *s == 'U') &&
3334 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3335 PL_lex_casestack[--PL_lex_casemods] = '\0';
3338 if (PL_lex_casemods > 10)
3339 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3340 PL_lex_casestack[PL_lex_casemods++] = *s;
3341 PL_lex_casestack[PL_lex_casemods] = '\0';
3342 PL_lex_state = LEX_INTERPCONCAT;
3343 start_force(PL_curforce);
3344 NEXTVAL_NEXTTOKE.ival = 0;
3346 start_force(PL_curforce);
3348 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3350 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3352 NEXTVAL_NEXTTOKE.ival = OP_LC;
3354 NEXTVAL_NEXTTOKE.ival = OP_UC;
3356 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3358 Perl_croak(aTHX_ "panic: yylex");
3360 SV* const tmpsv = newSVpvs("");
3361 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3367 if (PL_lex_starts) {
3373 sv_free(PL_thistoken);
3374 PL_thistoken = newSVpvs("");
3377 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3378 if (PL_lex_casemods == 1 && PL_lex_inpat)
3387 case LEX_INTERPPUSH:
3388 return REPORT(sublex_push());
3390 case LEX_INTERPSTART:
3391 if (PL_bufptr == PL_bufend)
3392 return REPORT(sublex_done());
3393 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3394 "### Interpolated variable\n"); });
3396 PL_lex_dojoin = (*PL_bufptr == '@');
3397 PL_lex_state = LEX_INTERPNORMAL;
3398 if (PL_lex_dojoin) {
3399 start_force(PL_curforce);
3400 NEXTVAL_NEXTTOKE.ival = 0;
3402 start_force(PL_curforce);
3403 force_ident("\"", '$');
3404 start_force(PL_curforce);
3405 NEXTVAL_NEXTTOKE.ival = 0;
3407 start_force(PL_curforce);
3408 NEXTVAL_NEXTTOKE.ival = 0;
3410 start_force(PL_curforce);
3411 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3414 if (PL_lex_starts++) {
3419 sv_free(PL_thistoken);
3420 PL_thistoken = newSVpvs("");
3423 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3424 if (!PL_lex_casemods && PL_lex_inpat)
3431 case LEX_INTERPENDMAYBE:
3432 if (intuit_more(PL_bufptr)) {
3433 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3439 if (PL_lex_dojoin) {
3440 PL_lex_dojoin = FALSE;
3441 PL_lex_state = LEX_INTERPCONCAT;
3445 sv_free(PL_thistoken);
3446 PL_thistoken = newSVpvs("");
3451 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3452 && SvEVALED(PL_lex_repl))
3454 if (PL_bufptr != PL_bufend)
3455 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3459 case LEX_INTERPCONCAT:
3461 if (PL_lex_brackets)
3462 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3464 if (PL_bufptr == PL_bufend)
3465 return REPORT(sublex_done());
3467 if (SvIVX(PL_linestr) == '\'') {
3468 SV *sv = newSVsv(PL_linestr);
3471 else if ( PL_hints & HINT_NEW_RE )
3472 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3473 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3477 s = scan_const(PL_bufptr);
3479 PL_lex_state = LEX_INTERPCASEMOD;
3481 PL_lex_state = LEX_INTERPSTART;
3484 if (s != PL_bufptr) {
3485 start_force(PL_curforce);
3487 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3489 NEXTVAL_NEXTTOKE = yylval;
3492 if (PL_lex_starts++) {
3496 sv_free(PL_thistoken);
3497 PL_thistoken = newSVpvs("");
3500 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3501 if (!PL_lex_casemods && PL_lex_inpat)
3514 PL_lex_state = LEX_NORMAL;
3515 s = scan_formline(PL_bufptr);
3516 if (!PL_lex_formbrack)
3522 PL_oldoldbufptr = PL_oldbufptr;
3528 sv_free(PL_thistoken);
3531 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3535 if (isIDFIRST_lazy_if(s,UTF))
3537 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3540 goto fake_eof; /* emulate EOF on ^D or ^Z */
3549 if (PL_lex_brackets) {
3550 yyerror((const char *)
3552 ? "Format not terminated"
3553 : "Missing right curly or square bracket"));
3555 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3556 "### Tokener got EOF\n");
3560 if (s++ < PL_bufend)
3561 goto retry; /* ignore stray nulls */
3564 if (!PL_in_eval && !PL_preambled) {
3565 PL_preambled = TRUE;
3570 sv_setpv(PL_linestr,incl_perldb());
3571 if (SvCUR(PL_linestr))
3572 sv_catpvs(PL_linestr,";");
3574 while(AvFILLp(PL_preambleav) >= 0) {
3575 SV *tmpsv = av_shift(PL_preambleav);
3576 sv_catsv(PL_linestr, tmpsv);
3577 sv_catpvs(PL_linestr, ";");
3580 sv_free((SV*)PL_preambleav);
3581 PL_preambleav = NULL;
3583 if (PL_minus_n || PL_minus_p) {
3584 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3586 sv_catpvs(PL_linestr,"chomp;");
3589 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3590 || *PL_splitstr == '"')
3591 && strchr(PL_splitstr + 1, *PL_splitstr))
3592 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3594 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3595 bytes can be used as quoting characters. :-) */
3596 const char *splits = PL_splitstr;
3597 sv_catpvs(PL_linestr, "our @F=split(q\0");
3600 if (*splits == '\\')
3601 sv_catpvn(PL_linestr, splits, 1);
3602 sv_catpvn(PL_linestr, splits, 1);
3603 } while (*splits++);
3604 /* This loop will embed the trailing NUL of
3605 PL_linestr as the last thing it does before
3607 sv_catpvs(PL_linestr, ");");
3611 sv_catpvs(PL_linestr,"our @F=split(' ');");
3615 sv_catpvs(PL_linestr,"use feature ':5.10';");
3616 sv_catpvs(PL_linestr, "\n");
3617 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3618 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3619 PL_last_lop = PL_last_uni = NULL;
3620 if (PERLDB_LINE && PL_curstash != PL_debstash)
3621 update_debugger_info(PL_linestr, NULL, 0);
3625 bof = PL_rsfp ? TRUE : FALSE;
3626 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3629 PL_realtokenstart = -1;
3632 if (PL_preprocess && !PL_in_eval)
3633 (void)PerlProc_pclose(PL_rsfp);
3634 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3635 PerlIO_clearerr(PL_rsfp);
3637 (void)PerlIO_close(PL_rsfp);
3639 PL_doextract = FALSE;
3641 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3646 sv_setpv(PL_linestr,
3649 ? ";}continue{print;}" : ";}"));
3650 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3651 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3652 PL_last_lop = PL_last_uni = NULL;
3653 PL_minus_n = PL_minus_p = 0;
3656 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3657 PL_last_lop = PL_last_uni = NULL;
3658 sv_setpvn(PL_linestr,"",0);
3659 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3661 /* If it looks like the start of a BOM or raw UTF-16,
3662 * check if it in fact is. */
3668 #ifdef PERLIO_IS_STDIO
3669 # ifdef __GNU_LIBRARY__
3670 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3671 # define FTELL_FOR_PIPE_IS_BROKEN
3675 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3676 # define FTELL_FOR_PIPE_IS_BROKEN
3681 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3682 /* This loses the possibility to detect the bof
3683 * situation on perl -P when the libc5 is being used.
3684 * Workaround? Maybe attach some extra state to PL_rsfp?
3687 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3689 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3692 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3693 s = swallow_bom((U8*)s);
3697 /* Incest with pod. */
3700 sv_catsv(PL_thiswhite, PL_linestr);
3702 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
3703 sv_setpvn(PL_linestr, "", 0);
3704 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3705 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3706 PL_last_lop = PL_last_uni = NULL;
3707 PL_doextract = FALSE;
3711 } while (PL_doextract);
3712 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3713 if (PERLDB_LINE && PL_curstash != PL_debstash)
3714 update_debugger_info(PL_linestr, NULL, 0);
3715 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3716 PL_last_lop = PL_last_uni = NULL;
3717 if (CopLINE(PL_curcop) == 1) {
3718 while (s < PL_bufend && isSPACE(*s))
3720 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3724 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3728 if (*s == '#' && *(s+1) == '!')
3730 #ifdef ALTERNATE_SHEBANG
3732 static char const as[] = ALTERNATE_SHEBANG;
3733 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3734 d = s + (sizeof(as) - 1);
3736 #endif /* ALTERNATE_SHEBANG */
3745 while (*d && !isSPACE(*d))
3749 #ifdef ARG_ZERO_IS_SCRIPT
3750 if (ipathend > ipath) {
3752 * HP-UX (at least) sets argv[0] to the script name,
3753 * which makes $^X incorrect. And Digital UNIX and Linux,
3754 * at least, set argv[0] to the basename of the Perl
3755 * interpreter. So, having found "#!", we'll set it right.
3757 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3759 assert(SvPOK(x) || SvGMAGICAL(x));
3760 if (sv_eq(x, CopFILESV(PL_curcop))) {
3761 sv_setpvn(x, ipath, ipathend - ipath);
3767 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3768 const char * const lstart = SvPV_const(x,llen);
3770 bstart += blen - llen;
3771 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3772 sv_setpvn(x, ipath, ipathend - ipath);
3777 TAINT_NOT; /* $^X is always tainted, but that's OK */
3779 #endif /* ARG_ZERO_IS_SCRIPT */
3784 d = instr(s,"perl -");
3786 d = instr(s,"perl");
3788 /* avoid getting into infinite loops when shebang
3789 * line contains "Perl" rather than "perl" */
3791 for (d = ipathend-4; d >= ipath; --d) {
3792 if ((*d == 'p' || *d == 'P')
3793 && !ibcmp(d, "perl", 4))
3803 #ifdef ALTERNATE_SHEBANG
3805 * If the ALTERNATE_SHEBANG on this system starts with a
3806 * character that can be part of a Perl expression, then if
3807 * we see it but not "perl", we're probably looking at the
3808 * start of Perl code, not a request to hand off to some
3809 * other interpreter. Similarly, if "perl" is there, but
3810 * not in the first 'word' of the line, we assume the line
3811 * contains the start of the Perl program.
3813 if (d && *s != '#') {
3814 const char *c = ipath;
3815 while (*c && !strchr("; \t\r\n\f\v#", *c))
3818 d = NULL; /* "perl" not in first word; ignore */
3820 *s = '#'; /* Don't try to parse shebang line */
3822 #endif /* ALTERNATE_SHEBANG */
3823 #ifndef MACOS_TRADITIONAL
3828 !instr(s,"indir") &&
3829 instr(PL_origargv[0],"perl"))
3836 while (s < PL_bufend && isSPACE(*s))
3838 if (s < PL_bufend) {
3839 Newxz(newargv,PL_origargc+3,char*);
3841 while (s < PL_bufend && !isSPACE(*s))
3844 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3847 newargv = PL_origargv;
3850 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3852 Perl_croak(aTHX_ "Can't exec %s", ipath);
3856 while (*d && !isSPACE(*d))
3858 while (SPACE_OR_TAB(*d))
3862 const bool switches_done = PL_doswitches;
3863 const U32 oldpdb = PL_perldb;
3864 const bool oldn = PL_minus_n;
3865 const bool oldp = PL_minus_p;
3868 if (*d == 'M' || *d == 'm' || *d == 'C') {
3869 const char * const m = d;
3870 while (*d && !isSPACE(*d))
3872 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3875 d = moreswitches(d);
3877 if (PL_doswitches && !switches_done) {
3878 int argc = PL_origargc;
3879 char **argv = PL_origargv;
3882 } while (argc && argv[0][0] == '-' && argv[0][1]);
3883 init_argv_symbols(argc,argv);
3885 if ((PERLDB_LINE && !oldpdb) ||
3886 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3887 /* if we have already added "LINE: while (<>) {",
3888 we must not do it again */
3890 sv_setpvn(PL_linestr, "", 0);
3891 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3892 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3893 PL_last_lop = PL_last_uni = NULL;
3894 PL_preambled = FALSE;
3896 (void)gv_fetchfile(PL_origfilename);
3903 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3905 PL_lex_state = LEX_FORMLINE;
3910 #ifdef PERL_STRICT_CR
3911 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3913 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3915 case ' ': case '\t': case '\f': case 013:
3916 #ifdef MACOS_TRADITIONAL
3920 PL_realtokenstart = -1;
3922 PL_thiswhite = newSVpvs("");
3923 sv_catpvn(PL_thiswhite, s, 1);
3930 PL_realtokenstart = -1;
3934 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3935 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3936 /* handle eval qq[#line 1 "foo"\n ...] */
3937 CopLINE_dec(PL_curcop);
3940 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3942 if (!PL_in_eval || PL_rsfp)
3947 while (d < PL_bufend && *d != '\n')
3951 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3952 Perl_croak(aTHX_ "panic: input overflow");
3955 PL_thiswhite = newSVpvn(s, d - s);
3960 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3962 PL_lex_state = LEX_FORMLINE;
3968 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3969 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3972 TOKEN(PEG); /* make sure any #! line is accessible */
3977 /* if (PL_madskills && PL_lex_formbrack) { */
3979 while (d < PL_bufend && *d != '\n')
3983 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3984 Perl_croak(aTHX_ "panic: input overflow");
3985 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3987 PL_thiswhite = newSVpvs("");
3988 if (CopLINE(PL_curcop) == 1) {
3989 sv_setpvn(PL_thiswhite, "", 0);
3992 sv_catpvn(PL_thiswhite, s, d - s);
4006 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
4014 while (s < PL_bufend && SPACE_OR_TAB(*s))
4017 if (strnEQ(s,"=>",2)) {
4018 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
4019 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
4020 OPERATOR('-'); /* unary minus */
4022 PL_last_uni = PL_oldbufptr;
4024 case 'r': ftst = OP_FTEREAD; break;
4025 case 'w': ftst = OP_FTEWRITE; break;
4026 case 'x': ftst = OP_FTEEXEC; break;
4027 case 'o': ftst = OP_FTEOWNED; break;
4028 case 'R': ftst = OP_FTRREAD; break;
4029 case 'W': ftst = OP_FTRWRITE; break;
4030 case 'X': ftst = OP_FTREXEC; break;
4031 case 'O': ftst = OP_FTROWNED; break;
4032 case 'e': ftst = OP_FTIS; break;
4033 case 'z': ftst = OP_FTZERO; break;
4034 case 's': ftst = OP_FTSIZE; break;
4035 case 'f': ftst = OP_FTFILE; break;
4036 case 'd': ftst = OP_FTDIR; break;
4037 case 'l': ftst = OP_FTLINK; break;
4038 case 'p': ftst = OP_FTPIPE; break;
4039 case 'S': ftst = OP_FTSOCK; break;
4040 case 'u': ftst = OP_FTSUID; break;
4041 case 'g': ftst = OP_FTSGID; break;
4042 case 'k': ftst = OP_FTSVTX; break;
4043 case 'b': ftst = OP_FTBLK; break;
4044 case 'c': ftst = OP_FTCHR; break;
4045 case 't': ftst = OP_FTTTY; break;
4046 case 'T': ftst = OP_FTTEXT; break;
4047 case 'B': ftst = OP_FTBINARY; break;
4048 case 'M': case 'A': case 'C':
4049 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
4051 case 'M': ftst = OP_FTMTIME; break;
4052 case 'A': ftst = OP_FTATIME; break;
4053 case 'C': ftst = OP_FTCTIME; break;
4061 PL_last_lop_op = (OPCODE)ftst;
4062 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4063 "### Saw file test %c\n", (int)tmp);
4068 /* Assume it was a minus followed by a one-letter named
4069 * subroutine call (or a -bareword), then. */
4070 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4071 "### '-%c' looked like a file test but was not\n",
4078 const char tmp = *s++;
4081 if (PL_expect == XOPERATOR)
4086 else if (*s == '>') {
4089 if (isIDFIRST_lazy_if(s,UTF)) {
4090 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4098 if (PL_expect == XOPERATOR)
4101 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4103 OPERATOR('-'); /* unary minus */
4109 const char tmp = *s++;
4112 if (PL_expect == XOPERATOR)
4117 if (PL_expect == XOPERATOR)
4120 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4127 if (PL_expect != XOPERATOR) {
4128 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4129 PL_expect = XOPERATOR;
4130 force_ident(PL_tokenbuf, '*');
4143 if (PL_expect == XOPERATOR) {
4147 PL_tokenbuf[0] = '%';
4148 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4149 sizeof PL_tokenbuf - 1, FALSE);
4150 if (!PL_tokenbuf[1]) {
4153 PL_pending_ident = '%';
4164 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
4171 const char tmp = *s++;
4177 goto just_a_word_zero_gv;
4180 switch (PL_expect) {
4186 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4188 PL_bufptr = s; /* update in case we back off */
4194 PL_expect = XTERMBLOCK;
4197 stuffstart = s - SvPVX(PL_linestr) - 1;
4201 while (isIDFIRST_lazy_if(s,UTF)) {
4204 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4205 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4206 if (tmp < 0) tmp = -tmp;
4221 sv = newSVpvn(s, len);
4223 d = scan_str(d,TRUE,TRUE);
4225 /* MUST advance bufptr here to avoid bogus
4226 "at end of line" context messages from yyerror().
4228 PL_bufptr = s + len;
4229 yyerror("Unterminated attribute parameter in attribute list");
4233 return REPORT(0); /* EOF indicator */
4237 sv_catsv(sv, PL_lex_stuff);
4238 attrs = append_elem(OP_LIST, attrs,
4239 newSVOP(OP_CONST, 0, sv));
4240 SvREFCNT_dec(PL_lex_stuff);
4241 PL_lex_stuff = NULL;
4244 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4246 if (PL_in_my == KEY_our) {
4248 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4250 /* skip to avoid loading attributes.pm */
4252 deprecate(":unique");
4255 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4258 /* NOTE: any CV attrs applied here need to be part of
4259 the CVf_BUILTIN_ATTRS define in cv.h! */
4260 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4262 CvLVALUE_on(PL_compcv);
4264 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4266 CvLOCKED_on(PL_compcv);
4268 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4270 CvMETHOD_on(PL_compcv);
4272 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4274 CvASSERTION_on(PL_compcv);
4276 /* After we've set the flags, it could be argued that
4277 we don't need to do the attributes.pm-based setting
4278 process, and shouldn't bother appending recognized
4279 flags. To experiment with that, uncomment the
4280 following "else". (Note that's already been
4281 uncommented. That keeps the above-applied built-in
4282 attributes from being intercepted (and possibly
4283 rejected) by a package's attribute routines, but is
4284 justified by the performance win for the common case
4285 of applying only built-in attributes.) */
4287 attrs = append_elem(OP_LIST, attrs,
4288 newSVOP(OP_CONST, 0,
4292 if (*s == ':' && s[1] != ':')
4295 break; /* require real whitespace or :'s */
4296 /* XXX losing whitespace on sequential attributes here */
4300 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4301 if (*s != ';' && *s != '}' && *s != tmp
4302 && (tmp != '=' || *s != ')')) {
4303 const char q = ((*s == '\'') ? '"' : '\'');
4304 /* If here for an expression, and parsed no attrs, back
4306 if (tmp == '=' && !attrs) {
4310 /* MUST advance bufptr here to avoid bogus "at end of line"
4311 context messages from yyerror().
4314 yyerror( (const char *)
4316 ? Perl_form(aTHX_ "Invalid separator character "
4317 "%c%c%c in attribute list", q, *s, q)
4318 : "Unterminated attribute list" ) );
4326 start_force(PL_curforce);
4327 NEXTVAL_NEXTTOKE.opval = attrs;
4328 CURMAD('_', PL_nextwhite);
4333 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4334 (s - SvPVX(PL_linestr)) - stuffstart);
4342 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4343 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4351 const char tmp = *s++;
4356 const char tmp = *s++;
4364 if (PL_lex_brackets <= 0)
4365 yyerror("Unmatched right square bracket");
4368 if (PL_lex_state == LEX_INTERPNORMAL) {
4369 if (PL_lex_brackets == 0) {
4370 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4371 PL_lex_state = LEX_INTERPEND;
4378 if (PL_lex_brackets > 100) {
4379 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4381 switch (PL_expect) {
4383 if (PL_lex_formbrack) {
4387 if (PL_oldoldbufptr == PL_last_lop)
4388 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4390 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4391 OPERATOR(HASHBRACK);
4393 while (s < PL_bufend && SPACE_OR_TAB(*s))
4396 PL_tokenbuf[0] = '\0';
4397 if (d < PL_bufend && *d == '-') {
4398 PL_tokenbuf[0] = '-';
4400 while (d < PL_bufend && SPACE_OR_TAB(*d))
4403 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4404 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4406 while (d < PL_bufend && SPACE_OR_TAB(*d))
4409 const char minus = (PL_tokenbuf[0] == '-');
4410 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4418 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4423 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4428 if (PL_oldoldbufptr == PL_last_lop)
4429 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4431 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4434 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4436 /* This hack is to get the ${} in the message. */
4438 yyerror("syntax error");
4441 OPERATOR(HASHBRACK);
4443 /* This hack serves to disambiguate a pair of curlies
4444 * as being a block or an anon hash. Normally, expectation
4445 * determines that, but in cases where we're not in a
4446 * position to expect anything in particular (like inside
4447 * eval"") we have to resolve the ambiguity. This code
4448 * covers the case where the first term in the curlies is a
4449 * quoted string. Most other cases need to be explicitly
4450 * disambiguated by prepending a "+" before the opening
4451 * curly in order to force resolution as an anon hash.
4453 * XXX should probably propagate the outer expectation
4454 * into eval"" to rely less on this hack, but that could
4455 * potentially break current behavior of eval"".
4459 if (*s == '\'' || *s == '"' || *s == '`') {
4460 /* common case: get past first string, handling escapes */
4461 for (t++; t < PL_bufend && *t != *s;)
4462 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4466 else if (*s == 'q') {
4469 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4472 /* skip q//-like construct */
4474 char open, close, term;
4477 while (t < PL_bufend && isSPACE(*t))
4479 /* check for q => */
4480 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4481 OPERATOR(HASHBRACK);
4485 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4489 for (t++; t < PL_bufend; t++) {
4490 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4492 else if (*t == open)
4496 for (t++; t < PL_bufend; t++) {
4497 if (*t == '\\' && t+1 < PL_bufend)
4499 else if (*t == close && --brackets <= 0)
4501 else if (*t == open)
4508 /* skip plain q word */
4509 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4512 else if (isALNUM_lazy_if(t,UTF)) {
4514 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4517 while (t < PL_bufend && isSPACE(*t))
4519 /* if comma follows first term, call it an anon hash */
4520 /* XXX it could be a comma expression with loop modifiers */
4521 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4522 || (*t == '=' && t[1] == '>')))
4523 OPERATOR(HASHBRACK);
4524 if (PL_expect == XREF)
4527 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4533 yylval.ival = CopLINE(PL_curcop);
4534 if (isSPACE(*s) || *s == '#')
4535 PL_copline = NOLINE; /* invalidate current command line number */
4540 if (PL_lex_brackets <= 0)
4541 yyerror("Unmatched right curly bracket");
4543 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4544 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4545 PL_lex_formbrack = 0;
4546 if (PL_lex_state == LEX_INTERPNORMAL) {
4547 if (PL_lex_brackets == 0) {
4548 if (PL_expect & XFAKEBRACK) {
4549 PL_expect &= XENUMMASK;
4550 PL_lex_state = LEX_INTERPEND;
4555 PL_thiswhite = newSVpvs("");
4556 sv_catpvn(PL_thiswhite,"}",1);
4559 return yylex(); /* ignore fake brackets */
4561 if (*s == '-' && s[1] == '>')
4562 PL_lex_state = LEX_INTERPENDMAYBE;
4563 else if (*s != '[' && *s != '{')
4564 PL_lex_state = LEX_INTERPEND;
4567 if (PL_expect & XFAKEBRACK) {
4568 PL_expect &= XENUMMASK;
4570 return yylex(); /* ignore fake brackets */
4572 start_force(PL_curforce);
4574 curmad('X', newSVpvn(s-1,1));
4575 CURMAD('_', PL_thiswhite);
4580 PL_thistoken = newSVpvs("");
4588 if (PL_expect == XOPERATOR) {
4589 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4590 && isIDFIRST_lazy_if(s,UTF))
4592 CopLINE_dec(PL_curcop);
4593 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4594 CopLINE_inc(PL_curcop);
4599 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4601 PL_expect = XOPERATOR;
4602 force_ident(PL_tokenbuf, '&');
4606 yylval.ival = (OPpENTERSUB_AMPER<<8);
4618 const char tmp = *s++;
4625 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4626 && strchr("+-*/%.^&|<",tmp))
4627 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4628 "Reversed %c= operator",(int)tmp);
4630 if (PL_expect == XSTATE && isALPHA(tmp) &&
4631 (s == PL_linestart+1 || s[-2] == '\n') )
4633 if (PL_in_eval && !PL_rsfp) {
4638 if (strnEQ(s,"=cut",4)) {
4654 PL_thiswhite = newSVpvs("");
4655 sv_catpvn(PL_thiswhite, PL_linestart,
4656 PL_bufend - PL_linestart);
4660 PL_doextract = TRUE;
4664 if (PL_lex_brackets < PL_lex_formbrack) {
4666 #ifdef PERL_STRICT_CR
4667 while (SPACE_OR_TAB(*t))
4669 while (SPACE_OR_TAB(*t) || *t == '\r')
4672 if (*t == '\n' || *t == '#') {
4683 const char tmp = *s++;
4685 /* was this !=~ where !~ was meant?
4686 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4688 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4689 const char *t = s+1;
4691 while (t < PL_bufend && isSPACE(*t))
4694 if (*t == '/' || *t == '?' ||
4695 ((*t == 'm' || *t == 's' || *t == 'y')
4696 && !isALNUM(t[1])) ||
4697 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4698 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4699 "!=~ should be !~");
4709 if (PL_expect != XOPERATOR) {
4710 if (s[1] != '<' && !strchr(s,'>'))
4713 s = scan_heredoc(s);
4715 s = scan_inputsymbol(s);
4716 TERM(sublex_start());
4722 SHop(OP_LEFT_SHIFT);
4736 const char tmp = *s++;
4738 SHop(OP_RIGHT_SHIFT);
4739 else if (tmp == '=')
4748 if (PL_expect == XOPERATOR) {
4749 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4751 deprecate_old(commaless_variable_list);
4752 return REPORT(','); /* grandfather non-comma-format format */
4756 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4757 PL_tokenbuf[0] = '@';
4758 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4759 sizeof PL_tokenbuf - 1, FALSE);
4760 if (PL_expect == XOPERATOR)
4761 no_op("Array length", s);
4762 if (!PL_tokenbuf[1])
4764 PL_expect = XOPERATOR;
4765 PL_pending_ident = '#';
4769 PL_tokenbuf[0] = '$';
4770 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4771 sizeof PL_tokenbuf - 1, FALSE);
4772 if (PL_expect == XOPERATOR)
4774 if (!PL_tokenbuf[1]) {
4776 yyerror("Final $ should be \\$ or $name");
4780 /* This kludge not intended to be bulletproof. */
4781 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4782 yylval.opval = newSVOP(OP_CONST, 0,
4783 newSViv(CopARYBASE_get(&PL_compiling)));
4784 yylval.opval->op_private = OPpCONST_ARYBASE;
4790 const char tmp = *s;
4791 if (PL_lex_state == LEX_NORMAL)
4794 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4795 && intuit_more(s)) {
4797 PL_tokenbuf[0] = '@';
4798 if (ckWARN(WARN_SYNTAX)) {
4801 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4804 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4805 while (t < PL_bufend && *t != ']')
4807 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4808 "Multidimensional syntax %.*s not supported",
4809 (int)((t - PL_bufptr) + 1), PL_bufptr);
4813 else if (*s == '{') {
4815 PL_tokenbuf[0] = '%';
4816 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4817 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4819 char tmpbuf[sizeof PL_tokenbuf];
4822 } while (isSPACE(*t));
4823 if (isIDFIRST_lazy_if(t,UTF)) {
4825 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4829 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
4830 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4831 "You need to quote \"%s\"",
4838 PL_expect = XOPERATOR;
4839 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4840 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4841 if (!islop || PL_last_lop_op == OP_GREPSTART)
4842 PL_expect = XOPERATOR;
4843 else if (strchr("$@\"'`q", *s))
4844 PL_expect = XTERM; /* e.g. print $fh "foo" */
4845 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4846 PL_expect = XTERM; /* e.g. print $fh &sub */
4847 else if (isIDFIRST_lazy_if(s,UTF)) {
4848 char tmpbuf[sizeof PL_tokenbuf];
4850 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4851 if ((t2 = keyword(tmpbuf, len, 0))) {
4852 /* binary operators exclude handle interpretations */
4864 PL_expect = XTERM; /* e.g. print $fh length() */
4869 PL_expect = XTERM; /* e.g. print $fh subr() */
4872 else if (isDIGIT(*s))
4873 PL_expect = XTERM; /* e.g. print $fh 3 */
4874 else if (*s == '.' && isDIGIT(s[1]))
4875 PL_expect = XTERM; /* e.g. print $fh .3 */
4876 else if ((*s == '?' || *s == '-' || *s == '+')
4877 && !isSPACE(s[1]) && s[1] != '=')
4878 PL_expect = XTERM; /* e.g. print $fh -1 */
4879 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4881 PL_expect = XTERM; /* e.g. print $fh /.../
4882 XXX except DORDOR operator
4884 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4886 PL_expect = XTERM; /* print $fh <<"EOF" */
4889 PL_pending_ident = '$';
4893 if (PL_expect == XOPERATOR)
4895 PL_tokenbuf[0] = '@';
4896 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4897 if (!PL_tokenbuf[1]) {
4900 if (PL_lex_state == LEX_NORMAL)
4902 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4904 PL_tokenbuf[0] = '%';
4906 /* Warn about @ where they meant $. */
4907 if (*s == '[' || *s == '{') {
4908 if (ckWARN(WARN_SYNTAX)) {
4909 const char *t = s + 1;
4910 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4912 if (*t == '}' || *t == ']') {
4914 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4915 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4916 "Scalar value %.*s better written as $%.*s",
4917 (int)(t-PL_bufptr), PL_bufptr,
4918 (int)(t-PL_bufptr-1), PL_bufptr+1);
4923 PL_pending_ident = '@';
4926 case '/': /* may be division, defined-or, or pattern */
4927 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4931 case '?': /* may either be conditional or pattern */
4932 if(PL_expect == XOPERATOR) {
4940 /* A // operator. */
4950 /* Disable warning on "study /blah/" */
4951 if (PL_oldoldbufptr == PL_last_uni
4952 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4953 || memNE(PL_last_uni, "study", 5)
4954 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4957 s = scan_pat(s,OP_MATCH);
4958 TERM(sublex_start());
4962 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4963 #ifdef PERL_STRICT_CR
4966 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4968 && (s == PL_linestart || s[-1] == '\n') )
4970 PL_lex_formbrack = 0;
4974 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4980 yylval.ival = OPf_SPECIAL;
4986 if (PL_expect != XOPERATOR)
4991 case '0': case '1': case '2': case '3': case '4':
4992 case '5': case '6': case '7': case '8': case '9':
4993 s = scan_num(s, &yylval);
4994 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
4995 if (PL_expect == XOPERATOR)
5000 s = scan_str(s,!!PL_madskills,FALSE);
5001 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5002 if (PL_expect == XOPERATOR) {
5003 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5005 deprecate_old(commaless_variable_list);
5006 return REPORT(','); /* grandfather non-comma-format format */
5013 yylval.ival = OP_CONST;
5014 TERM(sublex_start());
5017 s = scan_str(s,!!PL_madskills,FALSE);
5018 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5019 if (PL_expect == XOPERATOR) {
5020 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5022 deprecate_old(commaless_variable_list);
5023 return REPORT(','); /* grandfather non-comma-format format */
5030 yylval.ival = OP_CONST;
5031 /* FIXME. I think that this can be const if char *d is replaced by
5032 more localised variables. */
5033 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
5034 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
5035 yylval.ival = OP_STRINGIFY;
5039 TERM(sublex_start());
5042 s = scan_str(s,!!PL_madskills,FALSE);
5043 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
5044 if (PL_expect == XOPERATOR)
5045 no_op("Backticks",s);
5048 readpipe_override();
5049 TERM(sublex_start());
5053 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
5054 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5056 if (PL_expect == XOPERATOR)
5057 no_op("Backslash",s);
5061 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
5062 char *start = s + 2;
5063 while (isDIGIT(*start) || *start == '_')
5065 if (*start == '.' && isDIGIT(start[1])) {
5066 s = scan_num(s, &yylval);
5069 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
5070 else if (!isALPHA(*start) && (PL_expect == XTERM
5071 || PL_expect == XREF || PL_expect == XSTATE
5072 || PL_expect == XTERMORDORDOR)) {
5073 /* XXX Use gv_fetchpvn rather than stomping on a const string */
5074 const char c = *start;
5077 gv = gv_fetchpv(s, 0, SVt_PVCV);
5080 s = scan_num(s, &yylval);
5087 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5129 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5131 /* Some keywords can be followed by any delimiter, including ':' */
5132 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5133 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5134 (PL_tokenbuf[0] == 'q' &&
5135 strchr("qwxr", PL_tokenbuf[1])))));
5137 /* x::* is just a word, unless x is "CORE" */
5138 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5142 while (d < PL_bufend && isSPACE(*d))
5143 d++; /* no comments skipped here, or s### is misparsed */
5145 /* Is this a label? */
5146 if (!tmp && PL_expect == XSTATE
5147 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5149 yylval.pval = CopLABEL_alloc(PL_tokenbuf);
5154 /* Check for keywords */
5155 tmp = keyword(PL_tokenbuf, len, 0);
5157 /* Is this a word before a => operator? */
5158 if (*d == '=' && d[1] == '>') {
5161 = (OP*)newSVOP(OP_CONST, 0,
5162 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5163 yylval.opval->op_private = OPpCONST_BARE;
5167 if (tmp < 0) { /* second-class keyword? */
5168 GV *ogv = NULL; /* override (winner) */
5169 GV *hgv = NULL; /* hidden (loser) */
5170 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5172 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5175 if (GvIMPORTED_CV(gv))
5177 else if (! CvMETHOD(cv))
5181 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5182 (gv = *gvp) && isGV_with_GP(gv) &&
5183 GvCVu(gv) && GvIMPORTED_CV(gv))
5190 tmp = 0; /* overridden by import or by GLOBAL */
5193 && -tmp==KEY_lock /* XXX generalizable kludge */
5196 tmp = 0; /* any sub overrides "weak" keyword */
5198 else { /* no override */
5200 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5201 Perl_warner(aTHX_ packWARN(WARN_MISC),
5202 "dump() better written as CORE::dump()");
5206 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5207 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5208 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5209 "Ambiguous call resolved as CORE::%s(), %s",
5210 GvENAME(hgv), "qualify as such or use &");
5217 default: /* not a keyword */
5218 /* Trade off - by using this evil construction we can pull the
5219 variable gv into the block labelled keylookup. If not, then
5220 we have to give it function scope so that the goto from the
5221 earlier ':' case doesn't bypass the initialisation. */
5223 just_a_word_zero_gv:
5231 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5234 SV *nextPL_nextwhite = 0;
5238 /* Get the rest if it looks like a package qualifier */
5240 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5242 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5245 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5246 *s == '\'' ? "'" : "::");
5251 if (PL_expect == XOPERATOR) {
5252 if (PL_bufptr == PL_linestart) {
5253 CopLINE_dec(PL_curcop);
5254 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5255 CopLINE_inc(PL_curcop);
5258 no_op("Bareword",s);
5261 /* Look for a subroutine with this name in current package,
5262 unless name is "Foo::", in which case Foo is a bearword
5263 (and a package name). */
5265 if (len > 2 && !PL_madskills &&
5266 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5268 if (ckWARN(WARN_BAREWORD)
5269 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5270 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5271 "Bareword \"%s\" refers to nonexistent package",
5274 PL_tokenbuf[len] = '\0';
5280 /* Mustn't actually add anything to a symbol table.
5281 But also don't want to "initialise" any placeholder
5282 constants that might already be there into full
5283 blown PVGVs with attached PVCV. */
5284 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5285 GV_NOADD_NOINIT, SVt_PVCV);
5290 /* if we saw a global override before, get the right name */
5293 sv = newSVpvs("CORE::GLOBAL::");
5294 sv_catpv(sv,PL_tokenbuf);
5297 /* If len is 0, newSVpv does strlen(), which is correct.
5298 If len is non-zero, then it will be the true length,
5299 and so the scalar will be created correctly. */
5300 sv = newSVpv(PL_tokenbuf,len);
5303 if (PL_madskills && !PL_thistoken) {
5304 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5305 PL_thistoken = newSVpv(start,s - start);
5306 PL_realtokenstart = s - SvPVX(PL_linestr);
5310 /* Presume this is going to be a bareword of some sort. */
5313 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5314 yylval.opval->op_private = OPpCONST_BARE;
5315 /* UTF-8 package name? */
5316 if (UTF && !IN_BYTES &&
5317 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5320 /* And if "Foo::", then that's what it certainly is. */
5325 /* Do the explicit type check so that we don't need to force
5326 the initialisation of the symbol table to have a real GV.
5327 Beware - gv may not really be a PVGV, cv may not really be
5328 a PVCV, (because of the space optimisations that gv_init
5329 understands) But they're true if for this symbol there is
5330 respectively a typeglob and a subroutine.
5332 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5333 /* Real typeglob, so get the real subroutine: */
5335 /* A proxy for a subroutine in this package? */
5336 : SvOK(gv) ? (CV *) gv : NULL)
5339 /* See if it's the indirect object for a list operator. */
5341 if (PL_oldoldbufptr &&
5342 PL_oldoldbufptr < PL_bufptr &&
5343 (PL_oldoldbufptr == PL_last_lop
5344 || PL_oldoldbufptr == PL_last_uni) &&
5345 /* NO SKIPSPACE BEFORE HERE! */
5346 (PL_expect == XREF ||
5347 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5349 bool immediate_paren = *s == '(';
5351 /* (Now we can afford to cross potential line boundary.) */
5352 s = SKIPSPACE2(s,nextPL_nextwhite);
5354 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5357 /* Two barewords in a row may indicate method call. */
5359 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5360 (tmp = intuit_method(s, gv, cv)))
5363 /* If not a declared subroutine, it's an indirect object. */
5364 /* (But it's an indir obj regardless for sort.) */
5365 /* Also, if "_" follows a filetest operator, it's a bareword */
5368 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5370 (PL_last_lop_op != OP_MAPSTART &&
5371 PL_last_lop_op != OP_GREPSTART))))
5372 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5373 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5376 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5381 PL_expect = XOPERATOR;
5384 s = SKIPSPACE2(s,nextPL_nextwhite);
5385 PL_nextwhite = nextPL_nextwhite;
5390 /* Is this a word before a => operator? */
5391 if (*s == '=' && s[1] == '>' && !pkgname) {
5393 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5394 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5395 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5399 /* If followed by a paren, it's certainly a subroutine. */
5404 while (SPACE_OR_TAB(*d))
5406 if (*d == ')' && (sv = gv_const_sv(gv))) {
5410 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5411 sv_catpvn(PL_thistoken, par, s - par);
5413 sv_free(PL_nextwhite);
5424 PL_nextwhite = PL_thiswhite;
5427 start_force(PL_curforce);
5429 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5430 PL_expect = XOPERATOR;
5433 PL_nextwhite = nextPL_nextwhite;
5434 curmad('X', PL_thistoken);
5435 PL_thistoken = newSVpvs("");
5443 /* If followed by var or block, call it a method (unless sub) */
5445 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5446 PL_last_lop = PL_oldbufptr;
5447 PL_last_lop_op = OP_METHOD;
5451 /* If followed by a bareword, see if it looks like indir obj. */
5454 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5455 && (tmp = intuit_method(s, gv, cv)))
5458 /* Not a method, so call it a subroutine (if defined) */
5461 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5462 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5463 "Ambiguous use of -%s resolved as -&%s()",
5464 PL_tokenbuf, PL_tokenbuf);
5465 /* Check for a constant sub */
5466 if ((sv = gv_const_sv(gv)) && !PL_madskills) {
5468 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5469 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5470 yylval.opval->op_private = 0;
5474 /* Resolve to GV now. */
5475 if (SvTYPE(gv) != SVt_PVGV) {
5476 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5477 assert (SvTYPE(gv) == SVt_PVGV);
5478 /* cv must have been some sort of placeholder, so
5479 now needs replacing with a real code reference. */
5483 op_free(yylval.opval);
5484 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5485 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5486 PL_last_lop = PL_oldbufptr;
5487 PL_last_lop_op = OP_ENTERSUB;
5488 /* Is there a prototype? */
5496 const char *proto = SvPV_const((SV*)cv, protolen);
5499 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
5501 while (*proto == ';')
5503 if (*proto == '&' && *s == '{') {
5504 sv_setpv(PL_subname,
5507 "__ANON__" : "__ANON__::__ANON__"));
5514 PL_nextwhite = PL_thiswhite;
5517 start_force(PL_curforce);
5518 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5521 PL_nextwhite = nextPL_nextwhite;
5522 curmad('X', PL_thistoken);
5523 PL_thistoken = newSVpvs("");
5530 /* Guess harder when madskills require "best effort". */
5531 if (PL_madskills && (!gv || !GvCVu(gv))) {
5532 int probable_sub = 0;
5533 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5535 else if (isALPHA(*s)) {
5539 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5540 if (!keyword(tmpbuf, tmplen, 0))
5543 while (d < PL_bufend && isSPACE(*d))
5545 if (*d == '=' && d[1] == '>')
5550 gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
5551 op_free(yylval.opval);
5552 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5553 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5554 PL_last_lop = PL_oldbufptr;
5555 PL_last_lop_op = OP_ENTERSUB;
5556 PL_nextwhite = PL_thiswhite;
5558 start_force(PL_curforce);
5559 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5561 PL_nextwhite = nextPL_nextwhite;
5562 curmad('X', PL_thistoken);
5563 PL_thistoken = newSVpvs("");
5568 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5575 /* Call it a bare word */
5577 if (PL_hints & HINT_STRICT_SUBS)
5578 yylval.opval->op_private |= OPpCONST_STRICT;
5581 if (lastchar != '-') {
5582 if (ckWARN(WARN_RESERVED)) {
5586 if (!*d && !gv_stashpv(PL_tokenbuf, 0))
5587 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5594 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5595 && ckWARN_d(WARN_AMBIGUOUS)) {
5596 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5597 "Operator or semicolon missing before %c%s",
5598 lastchar, PL_tokenbuf);
5599 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5600 "Ambiguous use of %c resolved as operator %c",
5601 lastchar, lastchar);
5607 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5608 newSVpv(CopFILE(PL_curcop),0));
5612 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5613 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5616 case KEY___PACKAGE__:
5617 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5619 ? newSVhek(HvNAME_HEK(PL_curstash))
5626 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5627 const char *pname = "main";
5628 if (PL_tokenbuf[2] == 'D')
5629 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5630 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5634 GvIOp(gv) = newIO();
5635 IoIFP(GvIOp(gv)) = PL_rsfp;
5636 #if defined(HAS_FCNTL) && defined(F_SETFD)
5638 const int fd = PerlIO_fileno(PL_rsfp);
5639 fcntl(fd,F_SETFD,fd >= 3);
5642 /* Mark this internal pseudo-handle as clean */
5643 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5645 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5646 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5647 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5649 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5650 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5651 /* if the script was opened in binmode, we need to revert
5652 * it to text mode for compatibility; but only iff it has CRs
5653 * XXX this is a questionable hack at best. */
5654 if (PL_bufend-PL_bufptr > 2
5655 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5658 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5659 loc = PerlIO_tell(PL_rsfp);
5660 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5663 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5665 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5666 #endif /* NETWARE */
5667 #ifdef PERLIO_IS_STDIO /* really? */
5668 # if defined(__BORLANDC__)
5669 /* XXX see note in do_binmode() */
5670 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5674 PerlIO_seek(PL_rsfp, loc, 0);
5678 #ifdef PERLIO_LAYERS
5681 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5682 else if (PL_encoding) {
5689 XPUSHs(PL_encoding);
5691 call_method("name", G_SCALAR);
5695 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5696 Perl_form(aTHX_ ":encoding(%"SVf")",
5705 if (PL_realtokenstart >= 0) {
5706 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5708 PL_endwhite = newSVpvs("");
5709 sv_catsv(PL_endwhite, PL_thiswhite);
5711 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5712 PL_realtokenstart = -1;
5714 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5715 SvCUR(PL_endwhite))) != Nullch) ;
5730 if (PL_expect == XSTATE) {
5737 if (*s == ':' && s[1] == ':') {
5740 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5741 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5742 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5745 else if (tmp == KEY_require || tmp == KEY_do)
5746 /* that's a way to remember we saw "CORE::" */
5759 LOP(OP_ACCEPT,XTERM);
5765 LOP(OP_ATAN2,XTERM);
5771 LOP(OP_BINMODE,XTERM);
5774 LOP(OP_BLESS,XTERM);
5783 /* When 'use switch' is in effect, continue has a dual
5784 life as a control operator. */
5786 if (!FEATURE_IS_ENABLED("switch"))
5789 /* We have to disambiguate the two senses of
5790 "continue". If the next token is a '{' then
5791 treat it as the start of a continue block;
5792 otherwise treat it as a control operator.
5804 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5821 if (!PL_cryptseen) {
5822 PL_cryptseen = TRUE;
5826 LOP(OP_CRYPT,XTERM);
5829 LOP(OP_CHMOD,XTERM);
5832 LOP(OP_CHOWN,XTERM);
5835 LOP(OP_CONNECT,XTERM);
5854 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5855 if (orig_keyword == KEY_do) {
5864 PL_hints |= HINT_BLOCK_SCOPE;
5874 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5875 LOP(OP_DBMOPEN,XTERM);
5881 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5888 yylval.ival = CopLINE(PL_curcop);
5904 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5905 UNIBRACK(OP_ENTEREVAL);
5923 case KEY_endhostent:
5929 case KEY_endservent:
5932 case KEY_endprotoent:
5943 yylval.ival = CopLINE(PL_curcop);
5945 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5948 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5951 if ((PL_bufend - p) >= 3 &&
5952 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5954 else if ((PL_bufend - p) >= 4 &&
5955 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5958 if (isIDFIRST_lazy_if(p,UTF)) {
5959 p = scan_ident(p, PL_bufend,
5960 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5964 Perl_croak(aTHX_ "Missing $ on loop variable");
5966 s = SvPVX(PL_linestr) + soff;
5972 LOP(OP_FORMLINE,XTERM);
5978 LOP(OP_FCNTL,XTERM);
5984 LOP(OP_FLOCK,XTERM);
5993 LOP(OP_GREPSTART, XREF);
5996 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6011 case KEY_getpriority:
6012 LOP(OP_GETPRIORITY,XTERM);
6014 case KEY_getprotobyname:
6017 case KEY_getprotobynumber:
6018 LOP(OP_GPBYNUMBER,XTERM);
6020 case KEY_getprotoent:
6032 case KEY_getpeername:
6033 UNI(OP_GETPEERNAME);
6035 case KEY_gethostbyname:
6038 case KEY_gethostbyaddr:
6039 LOP(OP_GHBYADDR,XTERM);
6041 case KEY_gethostent:
6044 case KEY_getnetbyname:
6047 case KEY_getnetbyaddr:
6048 LOP(OP_GNBYADDR,XTERM);
6053 case KEY_getservbyname:
6054 LOP(OP_GSBYNAME,XTERM);
6056 case KEY_getservbyport:
6057 LOP(OP_GSBYPORT,XTERM);
6059 case KEY_getservent:
6062 case KEY_getsockname:
6063 UNI(OP_GETSOCKNAME);
6065 case KEY_getsockopt:
6066 LOP(OP_GSOCKOPT,XTERM);
6081 yylval.ival = CopLINE(PL_curcop);
6092 yylval.ival = CopLINE(PL_curcop);
6096 LOP(OP_INDEX,XTERM);
6102 LOP(OP_IOCTL,XTERM);
6114 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6146 LOP(OP_LISTEN,XTERM);
6155 s = scan_pat(s,OP_MATCH);
6156 TERM(sublex_start());
6159 LOP(OP_MAPSTART, XREF);
6162 LOP(OP_MKDIR,XTERM);
6165 LOP(OP_MSGCTL,XTERM);
6168 LOP(OP_MSGGET,XTERM);
6171 LOP(OP_MSGRCV,XTERM);
6174 LOP(OP_MSGSND,XTERM);
6179 PL_in_my = (U16)tmp;
6181 if (isIDFIRST_lazy_if(s,UTF)) {
6185 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6186 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6188 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6189 if (!PL_in_my_stash) {
6192 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6196 if (PL_madskills) { /* just add type to declarator token */
6197 sv_catsv(PL_thistoken, PL_nextwhite);
6199 sv_catpvn(PL_thistoken, start, s - start);
6207 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6214 s = tokenize_use(0, s);
6218 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6225 if (isIDFIRST_lazy_if(s,UTF)) {
6227 for (d = s; isALNUM_lazy_if(d,UTF);)
6229 for (t=d; isSPACE(*t);)
6231 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6233 && !(t[0] == '=' && t[1] == '>')
6235 int parms_len = (int)(d-s);
6236 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6237 "Precedence problem: open %.*s should be open(%.*s)",
6238 parms_len, s, parms_len, s);
6244 yylval.ival = OP_OR;
6254 LOP(OP_OPEN_DIR,XTERM);
6257 checkcomma(s,PL_tokenbuf,"filehandle");
6261 checkcomma(s,PL_tokenbuf,"filehandle");
6280 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6284 LOP(OP_PIPE_OP,XTERM);
6287 s = scan_str(s,!!PL_madskills,FALSE);
6290 yylval.ival = OP_CONST;
6291 TERM(sublex_start());
6297 s = scan_str(s,!!PL_madskills,FALSE);
6300 PL_expect = XOPERATOR;
6302 if (SvCUR(PL_lex_stuff)) {
6305 d = SvPV_force(PL_lex_stuff, len);
6307 for (; isSPACE(*d) && len; --len, ++d)
6312 if (!warned && ckWARN(WARN_QW)) {
6313 for (; !isSPACE(*d) && len; --len, ++d) {
6315 Perl_warner(aTHX_ packWARN(WARN_QW),
6316 "Possible attempt to separate words with commas");
6319 else if (*d == '#') {
6320 Perl_warner(aTHX_ packWARN(WARN_QW),
6321 "Possible attempt to put comments in qw() list");
6327 for (; !isSPACE(*d) && len; --len, ++d)
6330 sv = newSVpvn(b, d-b);
6331 if (DO_UTF8(PL_lex_stuff))
6333 words = append_elem(OP_LIST, words,
6334 newSVOP(OP_CONST, 0, tokeq(sv)));
6338 start_force(PL_curforce);
6339 NEXTVAL_NEXTTOKE.opval = words;
6344 SvREFCNT_dec(PL_lex_stuff);
6345 PL_lex_stuff = NULL;
6351 s = scan_str(s,!!PL_madskills,FALSE);
6354 yylval.ival = OP_STRINGIFY;
6355 if (SvIVX(PL_lex_stuff) == '\'')
6356 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6357 TERM(sublex_start());
6360 s = scan_pat(s,OP_QR);
6361 TERM(sublex_start());
6364 s = scan_str(s,!!PL_madskills,FALSE);
6367 readpipe_override();
6368 TERM(sublex_start());
6376 s = force_version(s, FALSE);
6378 else if (*s != 'v' || !isDIGIT(s[1])
6379 || (s = force_version(s, TRUE), *s == 'v'))
6381 *PL_tokenbuf = '\0';
6382 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6383 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6384 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
6386 yyerror("<> should be quotes");
6388 if (orig_keyword == KEY_require) {
6396 PL_last_uni = PL_oldbufptr;
6397 PL_last_lop_op = OP_REQUIRE;
6399 return REPORT( (int)REQUIRE );
6405 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6409 LOP(OP_RENAME,XTERM);
6418 LOP(OP_RINDEX,XTERM);
6428 UNIDOR(OP_READLINE);
6432 UNIDOR(OP_BACKTICK);
6441 LOP(OP_REVERSE,XTERM);
6444 UNIDOR(OP_READLINK);
6452 TERM(sublex_start());
6454 TOKEN(1); /* force error */
6457 checkcomma(s,PL_tokenbuf,"filehandle");
6467 LOP(OP_SELECT,XTERM);
6473 LOP(OP_SEMCTL,XTERM);
6476 LOP(OP_SEMGET,XTERM);
6479 LOP(OP_SEMOP,XTERM);
6485 LOP(OP_SETPGRP,XTERM);
6487 case KEY_setpriority:
6488 LOP(OP_SETPRIORITY,XTERM);
6490 case KEY_sethostent:
6496 case KEY_setservent:
6499 case KEY_setprotoent:
6509 LOP(OP_SEEKDIR,XTERM);
6511 case KEY_setsockopt:
6512 LOP(OP_SSOCKOPT,XTERM);
6518 LOP(OP_SHMCTL,XTERM);
6521 LOP(OP_SHMGET,XTERM);
6524 LOP(OP_SHMREAD,XTERM);
6527 LOP(OP_SHMWRITE,XTERM);
6530 LOP(OP_SHUTDOWN,XTERM);
6539 LOP(OP_SOCKET,XTERM);
6541 case KEY_socketpair:
6542 LOP(OP_SOCKPAIR,XTERM);
6545 checkcomma(s,PL_tokenbuf,"subroutine name");
6547 if (*s == ';' || *s == ')') /* probably a close */
6548 Perl_croak(aTHX_ "sort is now a reserved word");
6550 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6554 LOP(OP_SPLIT,XTERM);
6557 LOP(OP_SPRINTF,XTERM);
6560 LOP(OP_SPLICE,XTERM);
6575 LOP(OP_SUBSTR,XTERM);
6581 char tmpbuf[sizeof PL_tokenbuf];
6582 SSize_t tboffset = 0;
6583 expectation attrful;
6584 bool have_name, have_proto;
6585 const int key = tmp;
6590 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6591 SV *subtoken = newSVpvn(tstart, s - tstart);
6595 s = SKIPSPACE2(s,tmpwhite);
6600 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6601 (*s == ':' && s[1] == ':'))
6608 attrful = XATTRBLOCK;
6609 /* remember buffer pos'n for later force_word */
6610 tboffset = s - PL_oldbufptr;
6611 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6614 nametoke = newSVpvn(s, d - s);
6616 if (memchr(tmpbuf, ':', len))
6617 sv_setpvn(PL_subname, tmpbuf, len);
6619 sv_setsv(PL_subname,PL_curstname);
6620 sv_catpvs(PL_subname,"::");
6621 sv_catpvn(PL_subname,tmpbuf,len);
6628 CURMAD('X', nametoke);
6629 CURMAD('_', tmpwhite);
6630 (void) force_word(PL_oldbufptr + tboffset, WORD,
6633 s = SKIPSPACE2(d,tmpwhite);
6640 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6641 PL_expect = XTERMBLOCK;
6642 attrful = XATTRTERM;
6643 sv_setpvn(PL_subname,"?",1);
6647 if (key == KEY_format) {
6649 PL_lex_formbrack = PL_lex_brackets + 1;
6651 PL_thistoken = subtoken;
6655 (void) force_word(PL_oldbufptr + tboffset, WORD,
6661 /* Look for a prototype */
6664 bool bad_proto = FALSE;
6665 const bool warnsyntax = ckWARN(WARN_SYNTAX);
6667 s = scan_str(s,!!PL_madskills,FALSE);
6669 Perl_croak(aTHX_ "Prototype not terminated");
6670 /* strip spaces and check for bad characters */
6671 d = SvPVX(PL_lex_stuff);
6673 for (p = d; *p; ++p) {
6676 if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
6682 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6683 "Illegal character in prototype for %"SVf" : %s",
6684 SVfARG(PL_subname), d);
6685 SvCUR_set(PL_lex_stuff, tmp);
6690 CURMAD('q', PL_thisopen);
6691 CURMAD('_', tmpwhite);
6692 CURMAD('=', PL_thisstuff);
6693 CURMAD('Q', PL_thisclose);
6694 NEXTVAL_NEXTTOKE.opval =
6695 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6696 PL_lex_stuff = Nullsv;
6699 s = SKIPSPACE2(s,tmpwhite);
6707 if (*s == ':' && s[1] != ':')
6708 PL_expect = attrful;
6709 else if (*s != '{' && key == KEY_sub) {
6711 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6713 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
6720 curmad('^', newSVpvs(""));
6721 CURMAD('_', tmpwhite);
6725 PL_thistoken = subtoken;
6728 NEXTVAL_NEXTTOKE.opval =
6729 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6730 PL_lex_stuff = NULL;
6735 sv_setpv(PL_subname,
6737 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
6741 (void) force_word(PL_oldbufptr + tboffset, WORD,
6751 LOP(OP_SYSTEM,XREF);
6754 LOP(OP_SYMLINK,XTERM);
6757 LOP(OP_SYSCALL,XTERM);
6760 LOP(OP_SYSOPEN,XTERM);
6763 LOP(OP_SYSSEEK,XTERM);
6766 LOP(OP_SYSREAD,XTERM);
6769 LOP(OP_SYSWRITE,XTERM);
6773 TERM(sublex_start());
6794 LOP(OP_TRUNCATE,XTERM);
6806 yylval.ival = CopLINE(PL_curcop);
6810 yylval.ival = CopLINE(PL_curcop);
6814 LOP(OP_UNLINK,XTERM);
6820 LOP(OP_UNPACK,XTERM);
6823 LOP(OP_UTIME,XTERM);
6829 LOP(OP_UNSHIFT,XTERM);
6832 s = tokenize_use(1, s);
6842 yylval.ival = CopLINE(PL_curcop);
6846 yylval.ival = CopLINE(PL_curcop);
6850 PL_hints |= HINT_BLOCK_SCOPE;
6857 LOP(OP_WAITPID,XTERM);
6866 ctl_l[0] = toCTRL('L');
6868 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6871 /* Make sure $^L is defined */
6872 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6877 if (PL_expect == XOPERATOR)
6883 yylval.ival = OP_XOR;
6888 TERM(sublex_start());
6893 #pragma segment Main
6897 S_pending_ident(pTHX)
6902 /* pit holds the identifier we read and pending_ident is reset */
6903 char pit = PL_pending_ident;
6904 PL_pending_ident = 0;
6906 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6907 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6908 "### Pending identifier '%s'\n", PL_tokenbuf); });
6910 /* if we're in a my(), we can't allow dynamics here.
6911 $foo'bar has already been turned into $foo::bar, so
6912 just check for colons.
6914 if it's a legal name, the OP is a PADANY.
6917 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6918 if (strchr(PL_tokenbuf,':'))
6919 yyerror(Perl_form(aTHX_ "No package name allowed for "
6920 "variable %s in \"our\"",
6922 tmp = allocmy(PL_tokenbuf);
6925 if (strchr(PL_tokenbuf,':'))
6926 yyerror(Perl_form(aTHX_ PL_no_myglob,
6927 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6929 yylval.opval = newOP(OP_PADANY, 0);
6930 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6936 build the ops for accesses to a my() variable.
6938 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6939 then used in a comparison. This catches most, but not
6940 all cases. For instance, it catches
6941 sort { my($a); $a <=> $b }
6943 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6944 (although why you'd do that is anyone's guess).
6947 if (!strchr(PL_tokenbuf,':')) {
6949 tmp = pad_findmy(PL_tokenbuf);
6950 if (tmp != NOT_IN_PAD) {
6951 /* might be an "our" variable" */
6952 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6953 /* build ops for a bareword */
6954 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6955 HEK * const stashname = HvNAME_HEK(stash);
6956 SV * const sym = newSVhek(stashname);
6957 sv_catpvs(sym, "::");
6958 sv_catpv(sym, PL_tokenbuf+1);
6959 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6960 yylval.opval->op_private = OPpCONST_ENTERED;
6963 ? (GV_ADDMULTI | GV_ADDINEVAL)
6966 ((PL_tokenbuf[0] == '$') ? SVt_PV
6967 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6972 /* if it's a sort block and they're naming $a or $b */
6973 if (PL_last_lop_op == OP_SORT &&
6974 PL_tokenbuf[0] == '$' &&
6975 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6978 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6979 d < PL_bufend && *d != '\n';
6982 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6983 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6989 yylval.opval = newOP(OP_PADANY, 0);
6990 yylval.opval->op_targ = tmp;
6996 Whine if they've said @foo in a doublequoted string,
6997 and @foo isn't a variable we can find in the symbol
7000 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
7001 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
7002 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
7003 && ckWARN(WARN_AMBIGUOUS)
7004 /* DO NOT warn for @- and @+ */
7005 && !( PL_tokenbuf[2] == '\0' &&
7006 ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
7009 /* Downgraded from fatal to warning 20000522 mjd */
7010 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
7011 "Possible unintended interpolation of %s in string",
7016 /* build ops for a bareword */
7017 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
7018 yylval.opval->op_private = OPpCONST_ENTERED;
7021 /* If the identifier refers to a stash, don't autovivify it.
7022 * Change 24660 had the side effect of causing symbol table
7023 * hashes to always be defined, even if they were freshly
7024 * created and the only reference in the entire program was
7025 * the single statement with the defined %foo::bar:: test.
7026 * It appears that all code in the wild doing this actually
7027 * wants to know whether sub-packages have been loaded, so
7028 * by avoiding auto-vivifying symbol tables, we ensure that
7029 * defined %foo::bar:: continues to be false, and the existing
7030 * tests still give the expected answers, even though what
7031 * they're actually testing has now changed subtly.
7033 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
7035 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
7036 ((PL_tokenbuf[0] == '$') ? SVt_PV
7037 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7043 * The following code was generated by perl_keyword.pl.
7047 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
7052 case 1: /* 5 tokens of length 1 */
7084 case 2: /* 18 tokens of length 2 */
7230 case 3: /* 29 tokens of length 3 */
7234 if (name[1] == 'N' &&
7297 if (name[1] == 'i' &&
7319 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7337 if (name[1] == 'o' &&
7346 if (name[1] == 'e' &&
7355 if (name[1] == 'n' &&
7364 if (name[1] == 'o' &&
7373 if (name[1] == 'a' &&
7382 if (name[1] == 'o' &&
7444 if (name[1] == 'e' &&
7458 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
7484 if (name[1] == 'i' &&
7493 if (name[1] == 's' &&
7502 if (name[1] == 'e' &&
7511 if (name[1] == 'o' &&
7523 case 4: /* 41 tokens of length 4 */
7527 if (name[1] == 'O' &&
7537 if (name[1] == 'N' &&
7547 if (name[1] == 'i' &&
7557 if (name[1] == 'h' &&
7567 if (name[1] == 'u' &&
7580 if (name[2] == 'c' &&
7589 if (name[2] == 's' &&
7598 if (name[2] == 'a' &&
7634 if (name[1] == 'o' &&
7647 if (name[2] == 't' &&
7656 if (name[2] == 'o' &&
7665 if (name[2] == 't' &&
7674 if (name[2] == 'e' &&
7687 if (name[1] == 'o' &&
7700 if (name[2] == 'y' &&
7709 if (name[2] == 'l' &&
7725 if (name[2] == 's' &&
7734 if (name[2] == 'n' &&
7743 if (name[2] == 'c' &&
7756 if (name[1] == 'e' &&
7766 if (name[1] == 'p' &&
7779 if (name[2] == 'c' &&
7788 if (name[2] == 'p' &&
7797 if (name[2] == 's' &&
7813 if (name[2] == 'n' &&
7883 if (name[2] == 'r' &&
7892 if (name[2] == 'r' &&
7901 if (name[2] == 'a' &&
7917 if (name[2] == 'l' &&
7979 if (name[2] == 'e' &&
7982 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7995 case 5: /* 39 tokens of length 5 */
7999 if (name[1] == 'E' &&
8010 if (name[1] == 'H' &&
8024 if (name[2] == 'a' &&
8034 if (name[2] == 'a' &&
8051 if (name[2] == 'e' &&
8061 if (name[2] == 'e' &&
8065 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
8081 if (name[3] == 'i' &&
8090 if (name[3] == 'o' &&
8126 if (name[2] == 'o' &&
8136 if (name[2] == 'y' &&
8150 if (name[1] == 'l' &&
8164 if (name[2] == 'n' &&
8174 if (name[2] == 'o' &&
8188 if (name[1] == 'i' &&
8193 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8202 if (name[2] == 'd' &&
8212 if (name[2] == 'c' &&
8229 if (name[2] == 'c' &&
8239 if (name[2] == 't' &&
8253 if (name[1] == 'k' &&
8264 if (name[1] == 'r' &&
8278 if (name[2] == 's' &&
8288 if (name[2] == 'd' &&
8305 if (name[2] == 'm' &&
8315 if (name[2] == 'i' &&
8325 if (name[2] == 'e' &&
8335 if (name[2] == 'l' &&
8345 if (name[2] == 'a' &&
8358 if (name[3] == 't' &&
8361 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8367 if (name[3] == 'd' &&
8384 if (name[1] == 'i' &&
8398 if (name[2] == 'a' &&
8411 if (name[3] == 'e' &&
8446 if (name[2] == 'i' &&
8463 if (name[2] == 'i' &&
8473 if (name[2] == 'i' &&
8490 case 6: /* 33 tokens of length 6 */
8494 if (name[1] == 'c' &&
8509 if (name[2] == 'l' &&
8520 if (name[2] == 'r' &&
8535 if (name[1] == 'e' &&
8550 if (name[2] == 's' &&
8555 if(ckWARN_d(WARN_SYNTAX))
8556 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8562 if (name[2] == 'i' &&
8580 if (name[2] == 'l' &&
8591 if (name[2] == 'r' &&
8606 if (name[1] == 'm' &&
8621 if (name[2] == 'n' &&
8632 if (name[2] == 's' &&
8647 if (name[1] == 's' &&
8653 if (name[4] == 't' &&
8662 if (name[4] == 'e' &&
8671 if (name[4] == 'c' &&
8680 if (name[4] == 'n' &&
8696 if (name[1] == 'r' &&
8714 if (name[3] == 'a' &&
8724 if (name[3] == 'u' &&
8738 if (name[2] == 'n' &&
8756 if (name[2] == 'a' &&
8770 if (name[3] == 'e' &&
8783 if (name[4] == 't' &&
8792 if (name[4] == 'e' &&
8814 if (name[4] == 't' &&
8823 if (name[4] == 'e' &&
8839 if (name[2] == 'c' &&
8850 if (name[2] == 'l' &&
8861 if (name[2] == 'b' &&
8872 if (name[2] == 's' &&
8895 if (name[4] == 's' &&
8904 if (name[4] == 'n' &&
8917 if (name[3] == 'a' &&
8934 if (name[1] == 'a' &&
8949 case 7: /* 29 tokens of length 7 */
8953 if (name[1] == 'E' &&
8966 if (name[1] == '_' &&
8979 if (name[1] == 'i' &&
8986 return -KEY_binmode;
8992 if (name[1] == 'o' &&
8999 return -KEY_connect;
9008 if (name[2] == 'm' &&
9014 return -KEY_dbmopen;
9025 if (name[4] == 'u' &&
9029 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
9035 if (name[4] == 'n' &&
9056 if (name[1] == 'o' &&
9069 if (name[1] == 'e' &&
9076 if (name[5] == 'r' &&
9079 return -KEY_getpgrp;
9085 if (name[5] == 'i' &&
9088 return -KEY_getppid;
9101 if (name[1] == 'c' &&
9108 return -KEY_lcfirst;
9114 if (name[1] == 'p' &&
9121 return -KEY_opendir;
9127 if (name[1] == 'a' &&
9145 if (name[3] == 'd' &&
9150 return -KEY_readdir;
9156 if (name[3] == 'u' &&
9167 if (name[3] == 'e' &&
9172 return -KEY_reverse;
9191 if (name[3] == 'k' &&
9196 return -KEY_seekdir;
9202 if (name[3] == 'p' &&
9207 return -KEY_setpgrp;
9217 if (name[2] == 'm' &&
9223 return -KEY_shmread;
9229 if (name[2] == 'r' &&
9235 return -KEY_sprintf;
9244 if (name[3] == 'l' &&
9249 return -KEY_symlink;
9258 if (name[4] == 'a' &&
9262 return -KEY_syscall;
9268 if (name[4] == 'p' &&
9272 return -KEY_sysopen;
9278 if (name[4] == 'e' &&
9282 return -KEY_sysread;
9288 if (name[4] == 'e' &&
9292 return -KEY_sysseek;
9310 if (name[1] == 'e' &&
9317 return -KEY_telldir;
9326 if (name[2] == 'f' &&
9332 return -KEY_ucfirst;
9338 if (name[2] == 's' &&
9344 return -KEY_unshift;
9354 if (name[1] == 'a' &&
9361 return -KEY_waitpid;
9370 case 8: /* 26 tokens of length 8 */
9374 if (name[1] == 'U' &&
9382 return KEY_AUTOLOAD;
9393 if (name[3] == 'A' &&
9399 return KEY___DATA__;
9405 if (name[3] == 'I' &&
9411 return -KEY___FILE__;
9417 if (name[3] == 'I' &&
9423 return -KEY___LINE__;
9439 if (name[2] == 'o' &&
9446 return -KEY_closedir;
9452 if (name[2] == 'n' &&
9459 return -KEY_continue;
9469 if (name[1] == 'b' &&
9477 return -KEY_dbmclose;
9483 if (name[1] == 'n' &&
9489 if (name[4] == 'r' &&
9494 return -KEY_endgrent;
9500 if (name[4] == 'w' &&
9505 return -KEY_endpwent;
9518 if (name[1] == 'o' &&
9526 return -KEY_formline;
9532 if (name[1] == 'e' &&
9543 if (name[6] == 'n' &&
9546 return -KEY_getgrent;
9552 if (name[6] == 'i' &&
9555 return -KEY_getgrgid;
9561 if (name[6] == 'a' &&
9564 return -KEY_getgrnam;
9577 if (name[4] == 'o' &&
9582 return -KEY_getlogin;
9593 if (name[6] == 'n' &&
9596 return -KEY_getpwent;
9602 if (name[6] == 'a' &&
9605 return -KEY_getpwnam;
9611 if (name[6] == 'i' &&
9614 return -KEY_getpwuid;
9634 if (name[1] == 'e' &&
9641 if (name[5] == 'i' &&
9648 return -KEY_readline;
9653 return -KEY_readlink;
9664 if (name[5] == 'i' &&
9668 return -KEY_readpipe;
9689 if (name[4] == 'r' &&
9694 return -KEY_setgrent;
9700 if (name[4] == 'w' &&
9705 return -KEY_setpwent;
9721 if (name[3] == 'w' &&
9727 return -KEY_shmwrite;
9733 if (name[3] == 't' &&
9739 return -KEY_shutdown;
9749 if (name[2] == 's' &&
9756 return -KEY_syswrite;
9766 if (name[1] == 'r' &&
9774 return -KEY_truncate;
9783 case 9: /* 9 tokens of length 9 */
9787 if (name[1] == 'N' &&
9796 return KEY_UNITCHECK;
9802 if (name[1] == 'n' &&
9811 return -KEY_endnetent;
9817 if (name[1] == 'e' &&
9826 return -KEY_getnetent;
9832 if (name[1] == 'o' &&
9841 return -KEY_localtime;
9847 if (name[1] == 'r' &&
9856 return KEY_prototype;
9862 if (name[1] == 'u' &&
9871 return -KEY_quotemeta;
9877 if (name[1] == 'e' &&
9886 return -KEY_rewinddir;
9892 if (name[1] == 'e' &&
9901 return -KEY_setnetent;
9907 if (name[1] == 'a' &&
9916 return -KEY_wantarray;
9925 case 10: /* 9 tokens of length 10 */
9929 if (name[1] == 'n' &&
9935 if (name[4] == 'o' &&
9942 return -KEY_endhostent;
9948 if (name[4] == 'e' &&
9955 return -KEY_endservent;
9968 if (name[1] == 'e' &&
9974 if (name[4] == 'o' &&
9981 return -KEY_gethostent;
9990 if (name[5] == 'r' &&
9996 return -KEY_getservent;
10002 if (name[5] == 'c' &&
10008 return -KEY_getsockopt;
10028 if (name[2] == 't')
10033 if (name[4] == 'o' &&
10040 return -KEY_sethostent;
10049 if (name[5] == 'r' &&
10055 return -KEY_setservent;
10061 if (name[5] == 'c' &&
10067 return -KEY_setsockopt;
10084 if (name[2] == 'c' &&
10093 return -KEY_socketpair;
10106 case 11: /* 8 tokens of length 11 */
10110 if (name[1] == '_' &&
10120 { /* __PACKAGE__ */
10121 return -KEY___PACKAGE__;
10127 if (name[1] == 'n' &&
10137 { /* endprotoent */
10138 return -KEY_endprotoent;
10144 if (name[1] == 'e' &&
10153 if (name[5] == 'e' &&
10159 { /* getpeername */
10160 return -KEY_getpeername;
10169 if (name[6] == 'o' &&
10174 { /* getpriority */
10175 return -KEY_getpriority;
10181 if (name[6] == 't' &&
10186 { /* getprotoent */
10187 return -KEY_getprotoent;
10201 if (name[4] == 'o' &&
10208 { /* getsockname */
10209 return -KEY_getsockname;
10222 if (name[1] == 'e' &&
10230 if (name[6] == 'o' &&
10235 { /* setpriority */
10236 return -KEY_setpriority;
10242 if (name[6] == 't' &&
10247 { /* setprotoent */
10248 return -KEY_setprotoent;
10264 case 12: /* 2 tokens of length 12 */
10265 if (name[0] == 'g' &&
10277 if (name[9] == 'd' &&
10280 { /* getnetbyaddr */
10281 return -KEY_getnetbyaddr;
10287 if (name[9] == 'a' &&
10290 { /* getnetbyname */
10291 return -KEY_getnetbyname;
10303 case 13: /* 4 tokens of length 13 */
10304 if (name[0] == 'g' &&
10311 if (name[4] == 'o' &&
10320 if (name[10] == 'd' &&
10323 { /* gethostbyaddr */
10324 return -KEY_gethostbyaddr;
10330 if (name[10] == 'a' &&
10333 { /* gethostbyname */
10334 return -KEY_gethostbyname;
10347 if (name[4] == 'e' &&
10356 if (name[10] == 'a' &&
10359 { /* getservbyname */
10360 return -KEY_getservbyname;
10366 if (name[10] == 'o' &&
10369 { /* getservbyport */
10370 return -KEY_getservbyport;
10389 case 14: /* 1 tokens of length 14 */
10390 if (name[0] == 'g' &&
10404 { /* getprotobyname */
10405 return -KEY_getprotobyname;
10410 case 16: /* 1 tokens of length 16 */
10411 if (name[0] == 'g' &&
10427 { /* getprotobynumber */
10428 return -KEY_getprotobynumber;
10442 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10446 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10447 if (ckWARN(WARN_SYNTAX)) {
10450 for (w = s+2; *w && level; w++) {
10453 else if (*w == ')')
10456 while (isSPACE(*w))
10458 /* the list of chars below is for end of statements or
10459 * block / parens, boolean operators (&&, ||, //) and branch
10460 * constructs (or, and, if, until, unless, while, err, for).
10461 * Not a very solid hack... */
10462 if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
10463 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10464 "%s (...) interpreted as function",name);
10467 while (s < PL_bufend && isSPACE(*s))
10471 while (s < PL_bufend && isSPACE(*s))
10473 if (isIDFIRST_lazy_if(s,UTF)) {
10474 const char * const w = s++;
10475 while (isALNUM_lazy_if(s,UTF))
10477 while (s < PL_bufend && isSPACE(*s))
10481 if (keyword(w, s - w, 0))
10484 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10485 if (gv && GvCVu(gv))
10487 Perl_croak(aTHX_ "No comma allowed after %s", what);
10492 /* Either returns sv, or mortalizes sv and returns a new SV*.
10493 Best used as sv=new_constant(..., sv, ...).
10494 If s, pv are NULL, calls subroutine with one argument,
10495 and type is used with error messages only. */
10498 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10502 HV * const table = GvHV(PL_hintgv); /* ^H */
10506 const char *why1 = "", *why2 = "", *why3 = "";
10508 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10511 why2 = (const char *)
10512 (strEQ(key,"charnames")
10513 ? "(possibly a missing \"use charnames ...\")"
10515 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10516 (type ? type: "undef"), why2);
10518 /* This is convoluted and evil ("goto considered harmful")
10519 * but I do not understand the intricacies of all the different
10520 * failure modes of %^H in here. The goal here is to make
10521 * the most probable error message user-friendly. --jhi */
10526 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10527 (type ? type: "undef"), why1, why2, why3);
10529 yyerror(SvPVX_const(msg));
10533 cvp = hv_fetch(table, key, strlen(key), FALSE);
10534 if (!cvp || !SvOK(*cvp)) {
10537 why3 = "} is not defined";
10540 sv_2mortal(sv); /* Parent created it permanently */
10543 pv = sv_2mortal(newSVpvn(s, len));
10545 typesv = sv_2mortal(newSVpv(type, 0));
10547 typesv = &PL_sv_undef;
10549 PUSHSTACKi(PERLSI_OVERLOAD);
10561 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10565 /* Check the eval first */
10566 if (!PL_in_eval && SvTRUE(ERRSV)) {
10567 sv_catpvs(ERRSV, "Propagated");
10568 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10570 res = SvREFCNT_inc_simple(sv);
10574 SvREFCNT_inc_simple_void(res);
10583 why1 = "Call to &{$^H{";
10585 why3 = "}} did not return a defined value";
10593 /* Returns a NUL terminated string, with the length of the string written to
10597 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10600 register char *d = dest;
10601 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10604 Perl_croak(aTHX_ ident_too_long);
10605 if (isALNUM(*s)) /* UTF handled below */
10607 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10612 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10616 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10617 char *t = s + UTF8SKIP(s);
10619 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10623 Perl_croak(aTHX_ ident_too_long);
10624 Copy(s, d, len, char);
10637 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10640 char *bracket = NULL;
10642 register char *d = dest;
10643 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10648 while (isDIGIT(*s)) {
10650 Perl_croak(aTHX_ ident_too_long);
10657 Perl_croak(aTHX_ ident_too_long);
10658 if (isALNUM(*s)) /* UTF handled below */
10660 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10665 else if (*s == ':' && s[1] == ':') {
10669 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10670 char *t = s + UTF8SKIP(s);
10671 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10673 if (d + (t - s) > e)
10674 Perl_croak(aTHX_ ident_too_long);
10675 Copy(s, d, t - s, char);
10686 if (PL_lex_state != LEX_NORMAL)
10687 PL_lex_state = LEX_INTERPENDMAYBE;
10690 if (*s == '$' && s[1] &&
10691 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10704 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10709 if (isSPACE(s[-1])) {
10711 const char ch = *s++;
10712 if (!SPACE_OR_TAB(ch)) {
10718 if (isIDFIRST_lazy_if(d,UTF)) {
10722 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10723 end += UTF8SKIP(end);
10724 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10725 end += UTF8SKIP(end);
10727 Copy(s, d, end - s, char);
10732 while ((isALNUM(*s) || *s == ':') && d < e)
10735 Perl_croak(aTHX_ ident_too_long);
10738 while (s < send && SPACE_OR_TAB(*s))
10740 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10741 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10742 const char * const brack =
10744 ((*s == '[') ? "[...]" : "{...}");
10745 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10746 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10747 funny, dest, brack, funny, dest, brack);
10750 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10754 /* Handle extended ${^Foo} variables
10755 * 1999-02-27 mjd-perl-patch@plover.com */
10756 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10760 while (isALNUM(*s) && d < e) {
10764 Perl_croak(aTHX_ ident_too_long);
10769 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10770 PL_lex_state = LEX_INTERPEND;
10773 if (PL_lex_state == LEX_NORMAL) {
10774 if (ckWARN(WARN_AMBIGUOUS) &&
10775 (keyword(dest, d - dest, 0)
10776 || get_cvn_flags(dest, d - dest, 0)))
10780 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10781 "Ambiguous use of %c{%s} resolved to %c%s",
10782 funny, dest, funny, dest);
10787 s = bracket; /* let the parser handle it */
10791 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10792 PL_lex_state = LEX_INTERPEND;
10797 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10799 PERL_UNUSED_CONTEXT;
10803 CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
10804 case GLOBAL_PAT_MOD: *pmfl |= PMf_GLOBAL; break;
10805 case CONTINUE_PAT_MOD: *pmfl |= PMf_CONTINUE; break;
10806 case ONCE_PAT_MOD: *pmfl |= PMf_KEEP; break;
10807 case KEEPCOPY_PAT_MOD: *pmfl |= PMf_KEEPCOPY; break;
10813 S_scan_pat(pTHX_ char *start, I32 type)
10817 char *s = scan_str(start,!!PL_madskills,FALSE);
10818 const char * const valid_flags =
10819 (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
10826 const char * const delimiter = skipspace(start);
10830 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10831 : "Search pattern not terminated" ));
10834 pm = (PMOP*)newPMOP(type, 0);
10835 if (PL_multi_open == '?') {
10836 /* This is the only point in the code that sets PMf_ONCE: */
10837 pm->op_pmflags |= PMf_ONCE;
10839 /* Hence it's safe to do this bit of PMOP book-keeping here, which
10840 allows us to restrict the list needed by reset to just the ??
10842 assert(type != OP_TRANS);
10844 MAGIC *mg = mg_find((SV*)PL_curstash, PERL_MAGIC_symtab);
10847 mg = sv_magicext((SV*)PL_curstash, 0, PERL_MAGIC_symtab, 0, 0,
10850 elements = mg->mg_len / sizeof(PMOP**);
10851 Renewc(mg->mg_ptr, elements + 1, PMOP*, char);
10852 ((PMOP**)mg->mg_ptr) [elements++] = pm;
10853 mg->mg_len = elements * sizeof(PMOP**);
10854 PmopSTASH_set(pm,PL_curstash);
10860 while (*s && strchr(valid_flags, *s))
10861 pmflag(&pm->op_pmflags,*s++);
10863 if (PL_madskills && modstart != s) {
10864 SV* tmptoken = newSVpvn(modstart, s - modstart);
10865 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10868 /* issue a warning if /c is specified,but /g is not */
10869 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10870 && ckWARN(WARN_REGEXP))
10872 Perl_warner(aTHX_ packWARN(WARN_REGEXP),
10873 "Use of /c modifier is meaningless without /g" );
10876 PL_lex_op = (OP*)pm;
10877 yylval.ival = OP_MATCH;
10882 S_scan_subst(pTHX_ char *start)
10893 yylval.ival = OP_NULL;
10895 s = scan_str(start,!!PL_madskills,FALSE);
10898 Perl_croak(aTHX_ "Substitution pattern not terminated");
10900 if (s[-1] == PL_multi_open)
10903 if (PL_madskills) {
10904 CURMAD('q', PL_thisopen);
10905 CURMAD('_', PL_thiswhite);
10906 CURMAD('E', PL_thisstuff);
10907 CURMAD('Q', PL_thisclose);
10908 PL_realtokenstart = s - SvPVX(PL_linestr);
10912 first_start = PL_multi_start;
10913 s = scan_str(s,!!PL_madskills,FALSE);
10915 if (PL_lex_stuff) {
10916 SvREFCNT_dec(PL_lex_stuff);
10917 PL_lex_stuff = NULL;
10919 Perl_croak(aTHX_ "Substitution replacement not terminated");
10921 PL_multi_start = first_start; /* so whole substitution is taken together */
10923 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10926 if (PL_madskills) {
10927 CURMAD('z', PL_thisopen);
10928 CURMAD('R', PL_thisstuff);
10929 CURMAD('Z', PL_thisclose);
10935 if (*s == EXEC_PAT_MOD) {
10939 else if (strchr(S_PAT_MODS, *s))
10940 pmflag(&pm->op_pmflags,*s++);
10946 if (PL_madskills) {
10948 curmad('m', newSVpvn(modstart, s - modstart));
10949 append_madprops(PL_thismad, (OP*)pm, 0);
10953 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10954 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10958 SV * const repl = newSVpvs("");
10960 PL_sublex_info.super_bufptr = s;
10961 PL_sublex_info.super_bufend = PL_bufend;
10963 pm->op_pmflags |= PMf_EVAL;
10965 sv_catpv(repl, (const char *)(es ? "eval " : "do "));
10966 sv_catpvs(repl, "{");
10967 sv_catsv(repl, PL_lex_repl);
10968 if (strchr(SvPVX(PL_lex_repl), '#'))
10969 sv_catpvs(repl, "\n");
10970 sv_catpvs(repl, "}");
10972 SvREFCNT_dec(PL_lex_repl);
10973 PL_lex_repl = repl;
10976 PL_lex_op = (OP*)pm;
10977 yylval.ival = OP_SUBST;
10982 S_scan_trans(pTHX_ char *start)
10995 yylval.ival = OP_NULL;
10997 s = scan_str(start,!!PL_madskills,FALSE);
10999 Perl_croak(aTHX_ "Transliteration pattern not terminated");
11001 if (s[-1] == PL_multi_open)
11004 if (PL_madskills) {
11005 CURMAD('q', PL_thisopen);
11006 CURMAD('_', PL_thiswhite);
11007 CURMAD('E', PL_thisstuff);
11008 CURMAD('Q', PL_thisclose);
11009 PL_realtokenstart = s - SvPVX(PL_linestr);
11013 s = scan_str(s,!!PL_madskills,FALSE);
11015 if (PL_lex_stuff) {
11016 SvREFCNT_dec(PL_lex_stuff);
11017 PL_lex_stuff = NULL;
11019 Perl_croak(aTHX_ "Transliteration replacement not terminated");
11021 if (PL_madskills) {
11022 CURMAD('z', PL_thisopen);
11023 CURMAD('R', PL_thisstuff);
11024 CURMAD('Z', PL_thisclose);
11027 complement = del = squash = 0;
11034 complement = OPpTRANS_COMPLEMENT;
11037 del = OPpTRANS_DELETE;
11040 squash = OPpTRANS_SQUASH;
11049 tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
11050 o = newPVOP(OP_TRANS, 0, (char*)tbl);
11051 o->op_private &= ~OPpTRANS_ALL;
11052 o->op_private |= del|squash|complement|
11053 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
11054 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
11057 yylval.ival = OP_TRANS;
11060 if (PL_madskills) {
11062 curmad('m', newSVpvn(modstart, s - modstart));
11063 append_madprops(PL_thismad, o, 0);
11072 S_scan_heredoc(pTHX_ register char *s)
11076 I32 op_type = OP_SCALAR;
11080 const char *found_newline;
11084 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
11086 I32 stuffstart = s - SvPVX(PL_linestr);
11089 PL_realtokenstart = -1;
11094 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
11098 while (SPACE_OR_TAB(*peek))
11100 if (*peek == '`' || *peek == '\'' || *peek =='"') {
11103 s = delimcpy(d, e, s, PL_bufend, term, &len);
11113 if (!isALNUM_lazy_if(s,UTF))
11114 deprecate_old("bare << to mean <<\"\"");
11115 for (; isALNUM_lazy_if(s,UTF); s++) {
11120 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
11121 Perl_croak(aTHX_ "Delimiter for here document is too long");
11124 len = d - PL_tokenbuf;
11127 if (PL_madskills) {
11128 tstart = PL_tokenbuf + !outer;
11129 PL_thisclose = newSVpvn(tstart, len - !outer);
11130 tstart = SvPVX(PL_linestr) + stuffstart;
11131 PL_thisopen = newSVpvn(tstart, s - tstart);
11132 stuffstart = s - SvPVX(PL_linestr);
11135 #ifndef PERL_STRICT_CR
11136 d = strchr(s, '\r');
11138 char * const olds = s;
11140 while (s < PL_bufend) {
11146 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11155 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11162 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11163 herewas = newSVpvn(s,PL_bufend-s);
11167 herewas = newSVpvn(s-1,found_newline-s+1);
11170 herewas = newSVpvn(s,found_newline-s);
11174 if (PL_madskills) {
11175 tstart = SvPVX(PL_linestr) + stuffstart;
11177 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11179 PL_thisstuff = newSVpvn(tstart, s - tstart);
11182 s += SvCUR(herewas);
11185 stuffstart = s - SvPVX(PL_linestr);
11191 tmpstr = newSV_type(SVt_PVIV);
11192 SvGROW(tmpstr, 80);
11193 if (term == '\'') {
11194 op_type = OP_CONST;
11195 SvIV_set(tmpstr, -1);
11197 else if (term == '`') {
11198 op_type = OP_BACKTICK;
11199 SvIV_set(tmpstr, '\\');
11203 PL_multi_start = CopLINE(PL_curcop);
11204 PL_multi_open = PL_multi_close = '<';
11205 term = *PL_tokenbuf;
11206 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11207 char * const bufptr = PL_sublex_info.super_bufptr;
11208 char * const bufend = PL_sublex_info.super_bufend;
11209 char * const olds = s - SvCUR(herewas);
11210 s = strchr(bufptr, '\n');
11214 while (s < bufend &&
11215 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11217 CopLINE_inc(PL_curcop);
11220 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11221 missingterm(PL_tokenbuf);
11223 sv_setpvn(herewas,bufptr,d-bufptr+1);
11224 sv_setpvn(tmpstr,d+1,s-d);
11226 sv_catpvn(herewas,s,bufend-s);
11227 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11234 while (s < PL_bufend &&
11235 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11237 CopLINE_inc(PL_curcop);
11239 if (s >= PL_bufend) {
11240 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11241 missingterm(PL_tokenbuf);
11243 sv_setpvn(tmpstr,d+1,s-d);
11245 if (PL_madskills) {
11247 sv_catpvn(PL_thisstuff, d + 1, s - d);
11249 PL_thisstuff = newSVpvn(d + 1, s - d);
11250 stuffstart = s - SvPVX(PL_linestr);
11254 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11256 sv_catpvn(herewas,s,PL_bufend-s);
11257 sv_setsv(PL_linestr,herewas);
11258 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11259 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11260 PL_last_lop = PL_last_uni = NULL;
11263 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11264 while (s >= PL_bufend) { /* multiple line string? */
11266 if (PL_madskills) {
11267 tstart = SvPVX(PL_linestr) + stuffstart;
11269 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11271 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11275 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11276 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11277 missingterm(PL_tokenbuf);
11280 stuffstart = s - SvPVX(PL_linestr);
11282 CopLINE_inc(PL_curcop);
11283 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11284 PL_last_lop = PL_last_uni = NULL;
11285 #ifndef PERL_STRICT_CR
11286 if (PL_bufend - PL_linestart >= 2) {
11287 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11288 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11290 PL_bufend[-2] = '\n';
11292 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11294 else if (PL_bufend[-1] == '\r')
11295 PL_bufend[-1] = '\n';
11297 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11298 PL_bufend[-1] = '\n';
11300 if (PERLDB_LINE && PL_curstash != PL_debstash)
11301 update_debugger_info(PL_linestr, NULL, 0);
11302 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11303 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11304 *(SvPVX(PL_linestr) + off ) = ' ';
11305 sv_catsv(PL_linestr,herewas);
11306 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11307 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11311 sv_catsv(tmpstr,PL_linestr);
11316 PL_multi_end = CopLINE(PL_curcop);
11317 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11318 SvPV_shrink_to_cur(tmpstr);
11320 SvREFCNT_dec(herewas);
11322 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11324 else if (PL_encoding)
11325 sv_recode_to_utf8(tmpstr, PL_encoding);
11327 PL_lex_stuff = tmpstr;
11328 yylval.ival = op_type;
11332 /* scan_inputsymbol
11333 takes: current position in input buffer
11334 returns: new position in input buffer
11335 side-effects: yylval and lex_op are set.
11340 <FH> read from filehandle
11341 <pkg::FH> read from package qualified filehandle
11342 <pkg'FH> read from package qualified filehandle
11343 <$fh> read from filehandle in $fh
11344 <*.h> filename glob
11349 S_scan_inputsymbol(pTHX_ char *start)
11352 register char *s = start; /* current position in buffer */
11356 char *d = PL_tokenbuf; /* start of temp holding space */
11357 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11359 end = strchr(s, '\n');
11362 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11364 /* die if we didn't have space for the contents of the <>,
11365 or if it didn't end, or if we see a newline
11368 if (len >= (I32)sizeof PL_tokenbuf)
11369 Perl_croak(aTHX_ "Excessively long <> operator");
11371 Perl_croak(aTHX_ "Unterminated <> operator");
11376 Remember, only scalar variables are interpreted as filehandles by
11377 this code. Anything more complex (e.g., <$fh{$num}>) will be
11378 treated as a glob() call.
11379 This code makes use of the fact that except for the $ at the front,
11380 a scalar variable and a filehandle look the same.
11382 if (*d == '$' && d[1]) d++;
11384 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11385 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11388 /* If we've tried to read what we allow filehandles to look like, and
11389 there's still text left, then it must be a glob() and not a getline.
11390 Use scan_str to pull out the stuff between the <> and treat it
11391 as nothing more than a string.
11394 if (d - PL_tokenbuf != len) {
11395 yylval.ival = OP_GLOB;
11397 s = scan_str(start,!!PL_madskills,FALSE);
11399 Perl_croak(aTHX_ "Glob not terminated");
11403 bool readline_overriden = FALSE;
11406 /* we're in a filehandle read situation */
11409 /* turn <> into <ARGV> */
11411 Copy("ARGV",d,5,char);
11413 /* Check whether readline() is overriden */
11414 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11416 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11418 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11419 && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
11420 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11421 readline_overriden = TRUE;
11423 /* if <$fh>, create the ops to turn the variable into a
11427 /* try to find it in the pad for this block, otherwise find
11428 add symbol table ops
11430 const PADOFFSET tmp = pad_findmy(d);
11431 if (tmp != NOT_IN_PAD) {
11432 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11433 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11434 HEK * const stashname = HvNAME_HEK(stash);
11435 SV * const sym = sv_2mortal(newSVhek(stashname));
11436 sv_catpvs(sym, "::");
11437 sv_catpv(sym, d+1);
11442 OP * const o = newOP(OP_PADSV, 0);
11444 PL_lex_op = readline_overriden
11445 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11446 append_elem(OP_LIST, o,
11447 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11448 : (OP*)newUNOP(OP_READLINE, 0, o);
11457 ? (GV_ADDMULTI | GV_ADDINEVAL)
11460 PL_lex_op = readline_overriden
11461 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11462 append_elem(OP_LIST,
11463 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11464 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11465 : (OP*)newUNOP(OP_READLINE, 0,
11466 newUNOP(OP_RV2SV, 0,
11467 newGVOP(OP_GV, 0, gv)));
11469 if (!readline_overriden)
11470 PL_lex_op->op_flags |= OPf_SPECIAL;
11471 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11472 yylval.ival = OP_NULL;
11475 /* If it's none of the above, it must be a literal filehandle
11476 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11478 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11479 PL_lex_op = readline_overriden
11480 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11481 append_elem(OP_LIST,
11482 newGVOP(OP_GV, 0, gv),
11483 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11484 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11485 yylval.ival = OP_NULL;
11494 takes: start position in buffer
11495 keep_quoted preserve \ on the embedded delimiter(s)
11496 keep_delims preserve the delimiters around the string
11497 returns: position to continue reading from buffer
11498 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11499 updates the read buffer.
11501 This subroutine pulls a string out of the input. It is called for:
11502 q single quotes q(literal text)
11503 ' single quotes 'literal text'
11504 qq double quotes qq(interpolate $here please)
11505 " double quotes "interpolate $here please"
11506 qx backticks qx(/bin/ls -l)
11507 ` backticks `/bin/ls -l`
11508 qw quote words @EXPORT_OK = qw( func() $spam )
11509 m// regexp match m/this/
11510 s/// regexp substitute s/this/that/
11511 tr/// string transliterate tr/this/that/
11512 y/// string transliterate y/this/that/
11513 ($*@) sub prototypes sub foo ($)
11514 (stuff) sub attr parameters sub foo : attr(stuff)
11515 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11517 In most of these cases (all but <>, patterns and transliterate)
11518 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11519 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11520 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11523 It skips whitespace before the string starts, and treats the first
11524 character as the delimiter. If the delimiter is one of ([{< then
11525 the corresponding "close" character )]}> is used as the closing
11526 delimiter. It allows quoting of delimiters, and if the string has
11527 balanced delimiters ([{<>}]) it allows nesting.
11529 On success, the SV with the resulting string is put into lex_stuff or,
11530 if that is already non-NULL, into lex_repl. The second case occurs only
11531 when parsing the RHS of the special constructs s/// and tr/// (y///).
11532 For convenience, the terminating delimiter character is stuffed into
11537 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11540 SV *sv; /* scalar value: string */
11541 const char *tmps; /* temp string, used for delimiter matching */
11542 register char *s = start; /* current position in the buffer */
11543 register char term; /* terminating character */
11544 register char *to; /* current position in the sv's data */
11545 I32 brackets = 1; /* bracket nesting level */
11546 bool has_utf8 = FALSE; /* is there any utf8 content? */
11547 I32 termcode; /* terminating char. code */
11548 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11549 STRLEN termlen; /* length of terminating string */
11550 int last_off = 0; /* last position for nesting bracket */
11556 /* skip space before the delimiter */
11562 if (PL_realtokenstart >= 0) {
11563 stuffstart = PL_realtokenstart;
11564 PL_realtokenstart = -1;
11567 stuffstart = start - SvPVX(PL_linestr);
11569 /* mark where we are, in case we need to report errors */
11572 /* after skipping whitespace, the next character is the terminator */
11575 termcode = termstr[0] = term;
11579 termcode = utf8_to_uvchr((U8*)s, &termlen);
11580 Copy(s, termstr, termlen, U8);
11581 if (!UTF8_IS_INVARIANT(term))
11585 /* mark where we are */
11586 PL_multi_start = CopLINE(PL_curcop);
11587 PL_multi_open = term;
11589 /* find corresponding closing delimiter */
11590 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11591 termcode = termstr[0] = term = tmps[5];
11593 PL_multi_close = term;
11595 /* create a new SV to hold the contents. 79 is the SV's initial length.
11596 What a random number. */
11597 sv = newSV_type(SVt_PVIV);
11599 SvIV_set(sv, termcode);
11600 (void)SvPOK_only(sv); /* validate pointer */
11602 /* move past delimiter and try to read a complete string */
11604 sv_catpvn(sv, s, termlen);
11607 tstart = SvPVX(PL_linestr) + stuffstart;
11608 if (!PL_thisopen && !keep_delims) {
11609 PL_thisopen = newSVpvn(tstart, s - tstart);
11610 stuffstart = s - SvPVX(PL_linestr);
11614 if (PL_encoding && !UTF) {
11618 int offset = s - SvPVX_const(PL_linestr);
11619 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11620 &offset, (char*)termstr, termlen);
11621 const char * const ns = SvPVX_const(PL_linestr) + offset;
11622 char * const svlast = SvEND(sv) - 1;
11624 for (; s < ns; s++) {
11625 if (*s == '\n' && !PL_rsfp)
11626 CopLINE_inc(PL_curcop);
11629 goto read_more_line;
11631 /* handle quoted delimiters */
11632 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11634 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11636 if ((svlast-1 - t) % 2) {
11637 if (!keep_quoted) {
11638 *(svlast-1) = term;
11640 SvCUR_set(sv, SvCUR(sv) - 1);
11645 if (PL_multi_open == PL_multi_close) {
11651 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
11652 /* At here, all closes are "was quoted" one,
11653 so we don't check PL_multi_close. */
11655 if (!keep_quoted && *(t+1) == PL_multi_open)
11660 else if (*t == PL_multi_open)
11668 SvCUR_set(sv, w - SvPVX_const(sv));
11670 last_off = w - SvPVX(sv);
11671 if (--brackets <= 0)
11676 if (!keep_delims) {
11677 SvCUR_set(sv, SvCUR(sv) - 1);
11683 /* extend sv if need be */
11684 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11685 /* set 'to' to the next character in the sv's string */
11686 to = SvPVX(sv)+SvCUR(sv);
11688 /* if open delimiter is the close delimiter read unbridle */
11689 if (PL_multi_open == PL_multi_close) {
11690 for (; s < PL_bufend; s++,to++) {
11691 /* embedded newlines increment the current line number */
11692 if (*s == '\n' && !PL_rsfp)
11693 CopLINE_inc(PL_curcop);
11694 /* handle quoted delimiters */
11695 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11696 if (!keep_quoted && s[1] == term)
11698 /* any other quotes are simply copied straight through */
11702 /* terminate when run out of buffer (the for() condition), or
11703 have found the terminator */
11704 else if (*s == term) {
11707 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11710 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11716 /* if the terminator isn't the same as the start character (e.g.,
11717 matched brackets), we have to allow more in the quoting, and
11718 be prepared for nested brackets.
11721 /* read until we run out of string, or we find the terminator */
11722 for (; s < PL_bufend; s++,to++) {
11723 /* embedded newlines increment the line count */
11724 if (*s == '\n' && !PL_rsfp)
11725 CopLINE_inc(PL_curcop);
11726 /* backslashes can escape the open or closing characters */
11727 if (*s == '\\' && s+1 < PL_bufend) {
11728 if (!keep_quoted &&
11729 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11734 /* allow nested opens and closes */
11735 else if (*s == PL_multi_close && --brackets <= 0)
11737 else if (*s == PL_multi_open)
11739 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11744 /* terminate the copied string and update the sv's end-of-string */
11746 SvCUR_set(sv, to - SvPVX_const(sv));
11749 * this next chunk reads more into the buffer if we're not done yet
11753 break; /* handle case where we are done yet :-) */
11755 #ifndef PERL_STRICT_CR
11756 if (to - SvPVX_const(sv) >= 2) {
11757 if ((to[-2] == '\r' && to[-1] == '\n') ||
11758 (to[-2] == '\n' && to[-1] == '\r'))
11762 SvCUR_set(sv, to - SvPVX_const(sv));
11764 else if (to[-1] == '\r')
11767 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11772 /* if we're out of file, or a read fails, bail and reset the current
11773 line marker so we can report where the unterminated string began
11776 if (PL_madskills) {
11777 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11779 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11781 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11785 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11787 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11793 /* we read a line, so increment our line counter */
11794 CopLINE_inc(PL_curcop);
11796 /* update debugger info */
11797 if (PERLDB_LINE && PL_curstash != PL_debstash)
11798 update_debugger_info(PL_linestr, NULL, 0);
11800 /* having changed the buffer, we must update PL_bufend */
11801 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11802 PL_last_lop = PL_last_uni = NULL;
11805 /* at this point, we have successfully read the delimited string */
11807 if (!PL_encoding || UTF) {
11809 if (PL_madskills) {
11810 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11811 const int len = s - tstart;
11813 sv_catpvn(PL_thisstuff, tstart, len);
11815 PL_thisstuff = newSVpvn(tstart, len);
11816 if (!PL_thisclose && !keep_delims)
11817 PL_thisclose = newSVpvn(s,termlen);
11822 sv_catpvn(sv, s, termlen);
11827 if (PL_madskills) {
11828 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11829 const int len = s - tstart - termlen;
11831 sv_catpvn(PL_thisstuff, tstart, len);
11833 PL_thisstuff = newSVpvn(tstart, len);
11834 if (!PL_thisclose && !keep_delims)
11835 PL_thisclose = newSVpvn(s - termlen,termlen);
11839 if (has_utf8 || PL_encoding)
11842 PL_multi_end = CopLINE(PL_curcop);
11844 /* if we allocated too much space, give some back */
11845 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11846 SvLEN_set(sv, SvCUR(sv) + 1);
11847 SvPV_renew(sv, SvLEN(sv));
11850 /* decide whether this is the first or second quoted string we've read
11863 takes: pointer to position in buffer
11864 returns: pointer to new position in buffer
11865 side-effects: builds ops for the constant in yylval.op
11867 Read a number in any of the formats that Perl accepts:
11869 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11870 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11873 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11875 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11878 If it reads a number without a decimal point or an exponent, it will
11879 try converting the number to an integer and see if it can do so
11880 without loss of precision.
11884 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11887 register const char *s = start; /* current position in buffer */
11888 register char *d; /* destination in temp buffer */
11889 register char *e; /* end of temp buffer */
11890 NV nv; /* number read, as a double */
11891 SV *sv = NULL; /* place to put the converted number */
11892 bool floatit; /* boolean: int or float? */
11893 const char *lastub = NULL; /* position of last underbar */
11894 static char const number_too_long[] = "Number too long";
11896 /* We use the first character to decide what type of number this is */
11900 Perl_croak(aTHX_ "panic: scan_num");
11902 /* if it starts with a 0, it could be an octal number, a decimal in
11903 0.13 disguise, or a hexadecimal number, or a binary number. */
11907 u holds the "number so far"
11908 shift the power of 2 of the base
11909 (hex == 4, octal == 3, binary == 1)
11910 overflowed was the number more than we can hold?
11912 Shift is used when we add a digit. It also serves as an "are
11913 we in octal/hex/binary?" indicator to disallow hex characters
11914 when in octal mode.
11919 bool overflowed = FALSE;
11920 bool just_zero = TRUE; /* just plain 0 or binary number? */
11921 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11922 static const char* const bases[5] =
11923 { "", "binary", "", "octal", "hexadecimal" };
11924 static const char* const Bases[5] =
11925 { "", "Binary", "", "Octal", "Hexadecimal" };
11926 static const char* const maxima[5] =
11928 "0b11111111111111111111111111111111",
11932 const char *base, *Base, *max;
11934 /* check for hex */
11939 } else if (s[1] == 'b') {
11944 /* check for a decimal in disguise */
11945 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11947 /* so it must be octal */
11954 if (ckWARN(WARN_SYNTAX))
11955 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11956 "Misplaced _ in number");
11960 base = bases[shift];
11961 Base = Bases[shift];
11962 max = maxima[shift];
11964 /* read the rest of the number */
11966 /* x is used in the overflow test,
11967 b is the digit we're adding on. */
11972 /* if we don't mention it, we're done */
11976 /* _ are ignored -- but warned about if consecutive */
11978 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11979 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11980 "Misplaced _ in number");
11984 /* 8 and 9 are not octal */
11985 case '8': case '9':
11987 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11991 case '2': case '3': case '4':
11992 case '5': case '6': case '7':
11994 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11997 case '0': case '1':
11998 b = *s++ & 15; /* ASCII digit -> value of digit */
12002 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
12003 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
12004 /* make sure they said 0x */
12007 b = (*s++ & 7) + 9;
12009 /* Prepare to put the digit we have onto the end
12010 of the number so far. We check for overflows.
12016 x = u << shift; /* make room for the digit */
12018 if ((x >> shift) != u
12019 && !(PL_hints & HINT_NEW_BINARY)) {
12022 if (ckWARN_d(WARN_OVERFLOW))
12023 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12024 "Integer overflow in %s number",
12027 u = x | b; /* add the digit to the end */
12030 n *= nvshift[shift];
12031 /* If an NV has not enough bits in its
12032 * mantissa to represent an UV this summing of
12033 * small low-order numbers is a waste of time
12034 * (because the NV cannot preserve the
12035 * low-order bits anyway): we could just
12036 * remember when did we overflow and in the
12037 * end just multiply n by the right
12045 /* if we get here, we had success: make a scalar value from
12050 /* final misplaced underbar check */
12051 if (s[-1] == '_') {
12052 if (ckWARN(WARN_SYNTAX))
12053 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12058 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
12059 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12060 "%s number > %s non-portable",
12066 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
12067 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12068 "%s number > %s non-portable",
12073 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
12074 sv = new_constant(start, s - start, "integer",
12076 else if (PL_hints & HINT_NEW_BINARY)
12077 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
12082 handle decimal numbers.
12083 we're also sent here when we read a 0 as the first digit
12085 case '1': case '2': case '3': case '4': case '5':
12086 case '6': case '7': case '8': case '9': case '.':
12089 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
12092 /* read next group of digits and _ and copy into d */
12093 while (isDIGIT(*s) || *s == '_') {
12094 /* skip underscores, checking for misplaced ones
12098 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12099 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12100 "Misplaced _ in number");
12104 /* check for end of fixed-length buffer */
12106 Perl_croak(aTHX_ number_too_long);
12107 /* if we're ok, copy the character */
12112 /* final misplaced underbar check */
12113 if (lastub && s == lastub + 1) {
12114 if (ckWARN(WARN_SYNTAX))
12115 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12118 /* read a decimal portion if there is one. avoid
12119 3..5 being interpreted as the number 3. followed
12122 if (*s == '.' && s[1] != '.') {
12127 if (ckWARN(WARN_SYNTAX))
12128 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12129 "Misplaced _ in number");
12133 /* copy, ignoring underbars, until we run out of digits.
12135 for (; isDIGIT(*s) || *s == '_'; s++) {
12136 /* fixed length buffer check */
12138 Perl_croak(aTHX_ number_too_long);
12140 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12141 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12142 "Misplaced _ in number");
12148 /* fractional part ending in underbar? */
12149 if (s[-1] == '_') {
12150 if (ckWARN(WARN_SYNTAX))
12151 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12152 "Misplaced _ in number");
12154 if (*s == '.' && isDIGIT(s[1])) {
12155 /* oops, it's really a v-string, but without the "v" */
12161 /* read exponent part, if present */
12162 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12166 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12167 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12169 /* stray preinitial _ */
12171 if (ckWARN(WARN_SYNTAX))
12172 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12173 "Misplaced _ in number");
12177 /* allow positive or negative exponent */
12178 if (*s == '+' || *s == '-')
12181 /* stray initial _ */
12183 if (ckWARN(WARN_SYNTAX))
12184 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12185 "Misplaced _ in number");
12189 /* read digits of exponent */
12190 while (isDIGIT(*s) || *s == '_') {
12193 Perl_croak(aTHX_ number_too_long);
12197 if (((lastub && s == lastub + 1) ||
12198 (!isDIGIT(s[1]) && s[1] != '_'))
12199 && ckWARN(WARN_SYNTAX))
12200 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12201 "Misplaced _ in number");
12208 /* make an sv from the string */
12212 We try to do an integer conversion first if no characters
12213 indicating "float" have been found.
12218 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12220 if (flags == IS_NUMBER_IN_UV) {
12222 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12225 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12226 if (uv <= (UV) IV_MIN)
12227 sv_setiv(sv, -(IV)uv);
12234 /* terminate the string */
12236 nv = Atof(PL_tokenbuf);
12240 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12241 (PL_hints & HINT_NEW_INTEGER) )
12242 sv = new_constant(PL_tokenbuf,
12245 (floatit ? "float" : "integer"),
12249 /* if it starts with a v, it could be a v-string */
12252 sv = newSV(5); /* preallocate storage space */
12253 s = scan_vstring(s, PL_bufend, sv);
12257 /* make the op for the constant and return */
12260 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12262 lvalp->opval = NULL;
12268 S_scan_formline(pTHX_ register char *s)
12271 register char *eol;
12273 SV * const stuff = newSVpvs("");
12274 bool needargs = FALSE;
12275 bool eofmt = FALSE;
12277 char *tokenstart = s;
12280 if (PL_madskills) {
12281 savewhite = PL_thiswhite;
12286 while (!needargs) {
12289 #ifdef PERL_STRICT_CR
12290 while (SPACE_OR_TAB(*t))
12293 while (SPACE_OR_TAB(*t) || *t == '\r')
12296 if (*t == '\n' || t == PL_bufend) {
12301 if (PL_in_eval && !PL_rsfp) {
12302 eol = (char *) memchr(s,'\n',PL_bufend-s);
12307 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12309 for (t = s; t < eol; t++) {
12310 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12312 goto enough; /* ~~ must be first line in formline */
12314 if (*t == '@' || *t == '^')
12318 sv_catpvn(stuff, s, eol-s);
12319 #ifndef PERL_STRICT_CR
12320 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12321 char *end = SvPVX(stuff) + SvCUR(stuff);
12324 SvCUR_set(stuff, SvCUR(stuff) - 1);
12334 if (PL_madskills) {
12336 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12338 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12341 s = filter_gets(PL_linestr, PL_rsfp, 0);
12343 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12345 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12347 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12348 PL_last_lop = PL_last_uni = NULL;
12357 if (SvCUR(stuff)) {
12360 PL_lex_state = LEX_NORMAL;
12361 start_force(PL_curforce);
12362 NEXTVAL_NEXTTOKE.ival = 0;
12366 PL_lex_state = LEX_FORMLINE;
12368 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12370 else if (PL_encoding)
12371 sv_recode_to_utf8(stuff, PL_encoding);
12373 start_force(PL_curforce);
12374 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12376 start_force(PL_curforce);
12377 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12381 SvREFCNT_dec(stuff);
12383 PL_lex_formbrack = 0;
12387 if (PL_madskills) {
12389 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12391 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12392 PL_thiswhite = savewhite;
12404 PL_cshlen = strlen(PL_cshname);
12406 #if defined(USE_ITHREADS)
12407 PERL_UNUSED_CONTEXT;
12413 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12416 const I32 oldsavestack_ix = PL_savestack_ix;
12417 CV* const outsidecv = PL_compcv;
12420 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12422 SAVEI32(PL_subline);
12423 save_item(PL_subname);
12424 SAVESPTR(PL_compcv);
12426 PL_compcv = (CV*)newSV_type(is_format ? SVt_PVFM : SVt_PVCV);
12427 CvFLAGS(PL_compcv) |= flags;
12429 PL_subline = CopLINE(PL_curcop);
12430 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12431 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12432 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12434 return oldsavestack_ix;
12438 #pragma segment Perl_yylex
12441 Perl_yywarn(pTHX_ const char *s)
12444 PL_in_eval |= EVAL_WARNONLY;
12446 PL_in_eval &= ~EVAL_WARNONLY;
12451 Perl_yyerror(pTHX_ const char *s)
12454 const char *where = NULL;
12455 const char *context = NULL;
12458 int yychar = PL_parser->yychar;
12460 if (!yychar || (yychar == ';' && !PL_rsfp))
12462 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12463 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12464 PL_oldbufptr != PL_bufptr) {
12467 The code below is removed for NetWare because it abends/crashes on NetWare
12468 when the script has error such as not having the closing quotes like:
12469 if ($var eq "value)
12470 Checking of white spaces is anyway done in NetWare code.
12473 while (isSPACE(*PL_oldoldbufptr))
12476 context = PL_oldoldbufptr;
12477 contlen = PL_bufptr - PL_oldoldbufptr;
12479 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12480 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12483 The code below is removed for NetWare because it abends/crashes on NetWare
12484 when the script has error such as not having the closing quotes like:
12485 if ($var eq "value)
12486 Checking of white spaces is anyway done in NetWare code.
12489 while (isSPACE(*PL_oldbufptr))
12492 context = PL_oldbufptr;
12493 contlen = PL_bufptr - PL_oldbufptr;
12495 else if (yychar > 255)
12496 where = "next token ???";
12497 else if (yychar == -2) { /* YYEMPTY */
12498 if (PL_lex_state == LEX_NORMAL ||
12499 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12500 where = "at end of line";
12501 else if (PL_lex_inpat)
12502 where = "within pattern";
12504 where = "within string";
12507 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12509 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12510 else if (isPRINT_LC(yychar))
12511 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12513 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12514 where = SvPVX_const(where_sv);
12516 msg = sv_2mortal(newSVpv(s, 0));
12517 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12518 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12520 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12522 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12523 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12524 Perl_sv_catpvf(aTHX_ msg,
12525 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12526 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12529 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12530 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
12533 if (PL_error_count >= 10) {
12534 if (PL_in_eval && SvCUR(ERRSV))
12535 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12536 SVfARG(ERRSV), OutCopFILE(PL_curcop));
12538 Perl_croak(aTHX_ "%s has too many errors.\n",
12539 OutCopFILE(PL_curcop));
12542 PL_in_my_stash = NULL;
12546 #pragma segment Main
12550 S_swallow_bom(pTHX_ U8 *s)
12553 const STRLEN slen = SvCUR(PL_linestr);
12556 if (s[1] == 0xFE) {
12557 /* UTF-16 little-endian? (or UTF32-LE?) */
12558 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12559 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12560 #ifndef PERL_NO_UTF16_FILTER
12561 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12564 if (PL_bufend > (char*)s) {
12568 filter_add(utf16rev_textfilter, NULL);
12569 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12570 utf16_to_utf8_reversed(s, news,
12571 PL_bufend - (char*)s - 1,
12573 sv_setpvn(PL_linestr, (const char*)news, newlen);
12575 s = (U8*)SvPVX(PL_linestr);
12576 Copy(news, s, newlen, U8);
12580 SvUTF8_on(PL_linestr);
12581 s = (U8*)SvPVX(PL_linestr);
12583 /* FIXME - is this a general bug fix? */
12586 PL_bufend = SvPVX(PL_linestr) + newlen;
12589 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12594 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12595 #ifndef PERL_NO_UTF16_FILTER
12596 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12599 if (PL_bufend > (char *)s) {
12603 filter_add(utf16_textfilter, NULL);
12604 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12605 utf16_to_utf8(s, news,
12606 PL_bufend - (char*)s,
12608 sv_setpvn(PL_linestr, (const char*)news, newlen);
12610 SvUTF8_on(PL_linestr);
12611 s = (U8*)SvPVX(PL_linestr);
12612 PL_bufend = SvPVX(PL_linestr) + newlen;
12615 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12620 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12621 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12622 s += 3; /* UTF-8 */
12628 if (s[2] == 0xFE && s[3] == 0xFF) {
12629 /* UTF-32 big-endian */
12630 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12633 else if (s[2] == 0 && s[3] != 0) {
12636 * are a good indicator of UTF-16BE. */
12637 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12643 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12644 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12645 s += 4; /* UTF-8 */
12651 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12654 * are a good indicator of UTF-16LE. */
12655 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12664 * Restore a source filter.
12668 restore_rsfp(pTHX_ void *f)
12671 PerlIO * const fp = (PerlIO*)f;
12673 if (PL_rsfp == PerlIO_stdin())
12674 PerlIO_clearerr(PL_rsfp);
12675 else if (PL_rsfp && (PL_rsfp != fp))
12676 PerlIO_close(PL_rsfp);
12680 #ifndef PERL_NO_UTF16_FILTER
12682 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12685 const STRLEN old = SvCUR(sv);
12686 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12687 DEBUG_P(PerlIO_printf(Perl_debug_log,
12688 "utf16_textfilter(%p): %d %d (%d)\n",
12689 FPTR2DPTR(void *, utf16_textfilter),
12690 idx, maxlen, (int) count));
12694 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12695 Copy(SvPVX_const(sv), tmps, old, char);
12696 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12697 SvCUR(sv) - old, &newlen);
12698 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12700 DEBUG_P({sv_dump(sv);});
12705 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12708 const STRLEN old = SvCUR(sv);
12709 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12710 DEBUG_P(PerlIO_printf(Perl_debug_log,
12711 "utf16rev_textfilter(%p): %d %d (%d)\n",
12712 FPTR2DPTR(void *, utf16rev_textfilter),
12713 idx, maxlen, (int) count));
12717 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12718 Copy(SvPVX_const(sv), tmps, old, char);
12719 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12720 SvCUR(sv) - old, &newlen);
12721 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12723 DEBUG_P({ sv_dump(sv); });
12729 Returns a pointer to the next character after the parsed
12730 vstring, as well as updating the passed in sv.
12732 Function must be called like
12735 s = scan_vstring(s,e,sv);
12737 where s and e are the start and end of the string.
12738 The sv should already be large enough to store the vstring
12739 passed in, for performance reasons.
12744 Perl_scan_vstring(pTHX_ const char *s, const char *e, SV *sv)
12747 const char *pos = s;
12748 const char *start = s;
12749 if (*pos == 'v') pos++; /* get past 'v' */
12750 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12752 if ( *pos != '.') {
12753 /* this may not be a v-string if followed by => */
12754 const char *next = pos;
12755 while (next < e && isSPACE(*next))
12757 if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
12758 /* return string not v-string */
12759 sv_setpvn(sv,(char *)s,pos-s);
12760 return (char *)pos;
12764 if (!isALPHA(*pos)) {
12765 U8 tmpbuf[UTF8_MAXBYTES+1];
12768 s++; /* get past 'v' */
12770 sv_setpvn(sv, "", 0);
12773 /* this is atoi() that tolerates underscores */
12776 const char *end = pos;
12778 while (--end >= s) {
12780 const UV orev = rev;
12781 rev += (*end - '0') * mult;
12783 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12784 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12785 "Integer overflow in decimal number");
12789 if (rev > 0x7FFFFFFF)
12790 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12792 /* Append native character for the rev point */
12793 tmpend = uvchr_to_utf8(tmpbuf, rev);
12794 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12795 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12797 if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
12803 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12807 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12815 * c-indentation-style: bsd
12816 * c-basic-offset: 4
12817 * indent-tabs-mode: t
12820 * ex: set ts=8 sts=4 sw=4 noet: