3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "It all comes from here, the stench and the peril." --Frodo
16 * This file is the lexer for Perl. It's closely linked to the
19 * The main routine is yylex(), which returns the next token.
23 #define PERL_IN_TOKE_C
26 #define yylval (PL_parser->yylval)
28 /* YYINITDEPTH -- initial size of the parser's stacks. */
29 #define YYINITDEPTH 200
31 /* XXX temporary backwards compatibility */
32 #define PL_lex_brackets (PL_parser->lex_brackets)
33 #define PL_lex_brackstack (PL_parser->lex_brackstack)
34 #define PL_lex_casemods (PL_parser->lex_casemods)
35 #define PL_lex_casestack (PL_parser->lex_casestack)
36 #define PL_lex_defer (PL_parser->lex_defer)
37 #define PL_lex_dojoin (PL_parser->lex_dojoin)
38 #define PL_lex_expect (PL_parser->lex_expect)
39 #define PL_lex_formbrack (PL_parser->lex_formbrack)
40 #define PL_lex_inpat (PL_parser->lex_inpat)
41 #define PL_lex_inwhat (PL_parser->lex_inwhat)
42 #define PL_lex_op (PL_parser->lex_op)
43 #define PL_lex_repl (PL_parser->lex_repl)
44 #define PL_lex_starts (PL_parser->lex_starts)
45 #define PL_lex_stuff (PL_parser->lex_stuff)
46 #define PL_multi_start (PL_parser->multi_start)
47 #define PL_multi_open (PL_parser->multi_open)
48 #define PL_multi_close (PL_parser->multi_close)
49 #define PL_pending_ident (PL_parser->pending_ident)
50 #define PL_preambled (PL_parser->preambled)
51 #define PL_sublex_info (PL_parser->sublex_info)
52 #define PL_linestr (PL_parser->linestr)
53 #define PL_expect (PL_parser->expect)
54 #define PL_copline (PL_parser->copline)
55 #define PL_bufptr (PL_parser->bufptr)
56 #define PL_oldbufptr (PL_parser->oldbufptr)
57 #define PL_oldoldbufptr (PL_parser->oldoldbufptr)
58 #define PL_linestart (PL_parser->linestart)
59 #define PL_bufend (PL_parser->bufend)
60 #define PL_last_uni (PL_parser->last_uni)
61 #define PL_last_lop (PL_parser->last_lop)
62 #define PL_last_lop_op (PL_parser->last_lop_op)
63 #define PL_lex_state (PL_parser->lex_state)
64 #define PL_rsfp (PL_parser->rsfp)
67 # define PL_endwhite (PL_parser->endwhite)
68 # define PL_faketokens (PL_parser->faketokens)
69 # define PL_lasttoke (PL_parser->lasttoke)
70 # define PL_nextwhite (PL_parser->nextwhite)
71 # define PL_realtokenstart (PL_parser->realtokenstart)
72 # define PL_skipwhite (PL_parser->skipwhite)
73 # define PL_thisclose (PL_parser->thisclose)
74 # define PL_thismad (PL_parser->thismad)
75 # define PL_thisopen (PL_parser->thisopen)
76 # define PL_thisstuff (PL_parser->thisstuff)
77 # define PL_thistoken (PL_parser->thistoken)
78 # define PL_thiswhite (PL_parser->thiswhite)
79 # define PL_thiswhite (PL_parser->thiswhite)
80 # define PL_nexttoke (PL_parser->nexttoke)
81 # define PL_curforce (PL_parser->curforce)
83 # define PL_nexttoke (PL_parser->nexttoke)
84 # define PL_nexttype (PL_parser->nexttype)
85 # define PL_nextval (PL_parser->nextval)
89 S_pending_ident(pTHX);
91 static const char ident_too_long[] = "Identifier too long";
92 static const char commaless_variable_list[] = "comma-less variable list";
94 static void restore_rsfp(pTHX_ void *f);
95 #ifndef PERL_NO_UTF16_FILTER
96 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
97 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
101 # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
102 # define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
104 # define CURMAD(slot,sv)
105 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
108 #define XFAKEBRACK 128
109 #define XENUMMASK 127
111 #ifdef USE_UTF8_SCRIPTS
112 # define UTF (!IN_BYTES)
114 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
117 /* In variables named $^X, these are the legal values for X.
118 * 1999-02-27 mjd-perl-patch@plover.com */
119 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
121 /* On MacOS, respect nonbreaking spaces */
122 #ifdef MACOS_TRADITIONAL
123 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
125 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
128 /* LEX_* are values for PL_lex_state, the state of the lexer.
129 * They are arranged oddly so that the guard on the switch statement
130 * can get by with a single comparison (if the compiler is smart enough).
133 /* #define LEX_NOTPARSING 11 is done in perl.h. */
135 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
136 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
137 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
138 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
139 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
141 /* at end of code, eg "$x" followed by: */
142 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
143 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
145 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
146 string or after \E, $foo, etc */
147 #define LEX_INTERPCONST 2 /* NOT USED */
148 #define LEX_FORMLINE 1 /* expecting a format line */
149 #define LEX_KNOWNEXT 0 /* next token known; just return it */
153 static const char* const lex_state_names[] = {
172 #include "keywords.h"
174 /* CLINE is a macro that ensures PL_copline has a sane value */
179 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
182 # define SKIPSPACE0(s) skipspace0(s)
183 # define SKIPSPACE1(s) skipspace1(s)
184 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
185 # define PEEKSPACE(s) skipspace2(s,0)
187 # define SKIPSPACE0(s) skipspace(s)
188 # define SKIPSPACE1(s) skipspace(s)
189 # define SKIPSPACE2(s,tsv) skipspace(s)
190 # define PEEKSPACE(s) skipspace(s)
194 * Convenience functions to return different tokens and prime the
195 * lexer for the next token. They all take an argument.
197 * TOKEN : generic token (used for '(', DOLSHARP, etc)
198 * OPERATOR : generic operator
199 * AOPERATOR : assignment operator
200 * PREBLOCK : beginning the block after an if, while, foreach, ...
201 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
202 * PREREF : *EXPR where EXPR is not a simple identifier
203 * TERM : expression term
204 * LOOPX : loop exiting command (goto, last, dump, etc)
205 * FTST : file test operator
206 * FUN0 : zero-argument function
207 * FUN1 : not used, except for not, which isn't a UNIOP
208 * BOop : bitwise or or xor
210 * SHop : shift operator
211 * PWop : power operator
212 * PMop : pattern-matching operator
213 * Aop : addition-level operator
214 * Mop : multiplication-level operator
215 * Eop : equality-testing operator
216 * Rop : relational operator <= != gt
218 * Also see LOP and lop() below.
221 #ifdef DEBUGGING /* Serve -DT. */
222 # define REPORT(retval) tokereport((I32)retval)
224 # define REPORT(retval) (retval)
227 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
228 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
229 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
230 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
231 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
232 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
233 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
234 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
235 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
236 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
237 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
238 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
239 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
240 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
241 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
242 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
243 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
244 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
245 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
246 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
248 /* This bit of chicanery makes a unary function followed by
249 * a parenthesis into a function with one argument, highest precedence.
250 * The UNIDOR macro is for unary functions that can be followed by the //
251 * operator (such as C<shift // 0>).
253 #define UNI2(f,x) { \
257 PL_last_uni = PL_oldbufptr; \
258 PL_last_lop_op = f; \
260 return REPORT( (int)FUNC1 ); \
262 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
264 #define UNI(f) UNI2(f,XTERM)
265 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
267 #define UNIBRACK(f) { \
270 PL_last_uni = PL_oldbufptr; \
272 return REPORT( (int)FUNC1 ); \
274 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
277 /* grandfather return to old style */
278 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
282 /* how to interpret the yylval associated with the token */
286 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
292 static struct debug_tokens {
294 enum token_type type;
296 } const debug_tokens[] =
298 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
299 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
300 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
301 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
302 { ARROW, TOKENTYPE_NONE, "ARROW" },
303 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
304 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
305 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
306 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
307 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
308 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
309 { DO, TOKENTYPE_NONE, "DO" },
310 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
311 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
312 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
313 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
314 { ELSE, TOKENTYPE_NONE, "ELSE" },
315 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
316 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
317 { FOR, TOKENTYPE_IVAL, "FOR" },
318 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
319 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
320 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
321 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
322 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
323 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
324 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
325 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
326 { IF, TOKENTYPE_IVAL, "IF" },
327 { LABEL, TOKENTYPE_PVAL, "LABEL" },
328 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
329 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
330 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
331 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
332 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
333 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
334 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
335 { MY, TOKENTYPE_IVAL, "MY" },
336 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
337 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
338 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
339 { OROP, TOKENTYPE_IVAL, "OROP" },
340 { OROR, TOKENTYPE_NONE, "OROR" },
341 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
342 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
343 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
344 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
345 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
346 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
347 { PREINC, TOKENTYPE_NONE, "PREINC" },
348 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
349 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
350 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
351 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
352 { SUB, TOKENTYPE_NONE, "SUB" },
353 { THING, TOKENTYPE_OPVAL, "THING" },
354 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
355 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
356 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
357 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
358 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
359 { USE, TOKENTYPE_IVAL, "USE" },
360 { WHEN, TOKENTYPE_IVAL, "WHEN" },
361 { WHILE, TOKENTYPE_IVAL, "WHILE" },
362 { WORD, TOKENTYPE_OPVAL, "WORD" },
363 { 0, TOKENTYPE_NONE, NULL }
366 /* dump the returned token in rv, plus any optional arg in yylval */
369 S_tokereport(pTHX_ I32 rv)
373 const char *name = NULL;
374 enum token_type type = TOKENTYPE_NONE;
375 const struct debug_tokens *p;
376 SV* const report = newSVpvs("<== ");
378 for (p = debug_tokens; p->token; p++) {
379 if (p->token == (int)rv) {
386 Perl_sv_catpv(aTHX_ report, name);
387 else if ((char)rv > ' ' && (char)rv < '~')
388 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
390 sv_catpvs(report, "EOF");
392 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
395 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
398 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
400 case TOKENTYPE_OPNUM:
401 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
402 PL_op_name[yylval.ival]);
405 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
407 case TOKENTYPE_OPVAL:
409 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
410 PL_op_name[yylval.opval->op_type]);
411 if (yylval.opval->op_type == OP_CONST) {
412 Perl_sv_catpvf(aTHX_ report, " %s",
413 SvPEEK(cSVOPx_sv(yylval.opval)));
418 sv_catpvs(report, "(opval=null)");
421 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
427 /* print the buffer with suitable escapes */
430 S_printbuf(pTHX_ const char* fmt, const char* s)
432 SV* const tmp = newSVpvs("");
433 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
442 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
443 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
447 S_ao(pTHX_ int toketype)
450 if (*PL_bufptr == '=') {
452 if (toketype == ANDAND)
453 yylval.ival = OP_ANDASSIGN;
454 else if (toketype == OROR)
455 yylval.ival = OP_ORASSIGN;
456 else if (toketype == DORDOR)
457 yylval.ival = OP_DORASSIGN;
465 * When Perl expects an operator and finds something else, no_op
466 * prints the warning. It always prints "<something> found where
467 * operator expected. It prints "Missing semicolon on previous line?"
468 * if the surprise occurs at the start of the line. "do you need to
469 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
470 * where the compiler doesn't know if foo is a method call or a function.
471 * It prints "Missing operator before end of line" if there's nothing
472 * after the missing operator, or "... before <...>" if there is something
473 * after the missing operator.
477 S_no_op(pTHX_ const char *what, char *s)
480 char * const oldbp = PL_bufptr;
481 const bool is_first = (PL_oldbufptr == PL_linestart);
487 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
488 if (ckWARN_d(WARN_SYNTAX)) {
490 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
491 "\t(Missing semicolon on previous line?)\n");
492 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
494 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
496 if (t < PL_bufptr && isSPACE(*t))
497 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
498 "\t(Do you need to predeclare %.*s?)\n",
499 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
503 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
504 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
512 * Complain about missing quote/regexp/heredoc terminator.
513 * If it's called with NULL then it cauterizes the line buffer.
514 * If we're in a delimited string and the delimiter is a control
515 * character, it's reformatted into a two-char sequence like ^C.
520 S_missingterm(pTHX_ char *s)
526 char * const nl = strrchr(s,'\n');
532 iscntrl(PL_multi_close)
534 PL_multi_close < 32 || PL_multi_close == 127
538 tmpbuf[1] = (char)toCTRL(PL_multi_close);
543 *tmpbuf = (char)PL_multi_close;
547 q = strchr(s,'"') ? '\'' : '"';
548 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
551 #define FEATURE_IS_ENABLED(name) \
552 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
553 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
555 * S_feature_is_enabled
556 * Check whether the named feature is enabled.
559 S_feature_is_enabled(pTHX_ const char *name, STRLEN namelen)
562 HV * const hinthv = GvHV(PL_hintgv);
563 char he_name[32] = "feature_";
564 (void) my_strlcpy(&he_name[8], name, 24);
566 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
574 Perl_deprecate(pTHX_ const char *s)
576 if (ckWARN(WARN_DEPRECATED))
577 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
581 Perl_deprecate_old(pTHX_ const char *s)
583 /* This function should NOT be called for any new deprecated warnings */
584 /* Use Perl_deprecate instead */
586 /* It is here to maintain backward compatibility with the pre-5.8 */
587 /* warnings category hierarchy. The "deprecated" category used to */
588 /* live under the "syntax" category. It is now a top-level category */
589 /* in its own right. */
591 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
592 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
593 "Use of %s is deprecated", s);
597 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
598 * utf16-to-utf8-reversed.
601 #ifdef PERL_CR_FILTER
605 register const char *s = SvPVX_const(sv);
606 register const char * const e = s + SvCUR(sv);
607 /* outer loop optimized to do nothing if there are no CR-LFs */
609 if (*s++ == '\r' && *s == '\n') {
610 /* hit a CR-LF, need to copy the rest */
611 register char *d = s - 1;
614 if (*s == '\r' && s[1] == '\n')
625 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
627 const I32 count = FILTER_READ(idx+1, sv, maxlen);
628 if (count > 0 && !maxlen)
638 * Create a parser object and initialise its parser and lexer fields
642 Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp)
645 const char *s = NULL;
649 /* create and initialise a parser */
651 Newxz(parser, 1, yy_parser);
652 parser->old_parser = PL_parser;
655 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
656 parser->ps = parser->stack;
657 parser->stack_size = YYINITDEPTH;
659 parser->stack->state = 0;
660 parser->yyerrstatus = 0;
661 parser->yychar = YYEMPTY; /* Cause a token to be read. */
663 /* on scope exit, free this parser and restore any outer one */
666 /* initialise lexer state */
668 SAVECOPLINE(PL_curcop);
671 parser->curforce = -1;
673 parser->nexttoke = 0;
675 parser->copline = NOLINE;
676 PL_lex_state = LEX_NORMAL;
677 parser->expect = XSTATE;
680 Newx(parser->lex_brackstack, 120, char);
681 Newx(parser->lex_casestack, 12, char);
682 *parser->lex_casestack = '\0';
685 s = SvPV_const(line, len);
691 parser->linestr = newSVpvs("\n;");
692 } else if (SvREADONLY(line) || s[len-1] != ';') {
693 parser->linestr = newSVsv(line);
695 sv_catpvs(parser->linestr, "\n;");
698 SvREFCNT_inc_simple_void_NN(line);
699 parser->linestr = line;
701 parser->oldoldbufptr =
704 parser->linestart = SvPVX(parser->linestr);
705 parser->bufend = parser->bufptr + SvCUR(parser->linestr);
706 parser->last_lop = parser->last_uni = NULL;
710 /* delete a parser object */
713 Perl_parser_free(pTHX_ const yy_parser *parser)
715 SvREFCNT_dec(parser->linestr);
717 if (parser->rsfp == PerlIO_stdin())
718 PerlIO_clearerr(parser->rsfp);
719 else if (parser->rsfp && parser->old_parser
720 && parser->rsfp != parser->old_parser->rsfp)
721 PerlIO_close(parser->rsfp);
723 Safefree(parser->stack);
724 Safefree(parser->lex_brackstack);
725 Safefree(parser->lex_casestack);
726 PL_parser = parser->old_parser;
733 * Finalizer for lexing operations. Must be called when the parser is
734 * done with the lexer.
741 PL_doextract = FALSE;
746 * This subroutine has nothing to do with tilting, whether at windmills
747 * or pinball tables. Its name is short for "increment line". It
748 * increments the current line number in CopLINE(PL_curcop) and checks
749 * to see whether the line starts with a comment of the form
750 * # line 500 "foo.pm"
751 * If so, it sets the current line number and file to the values in the comment.
755 S_incline(pTHX_ const char *s)
762 CopLINE_inc(PL_curcop);
765 while (SPACE_OR_TAB(*s))
767 if (strnEQ(s, "line", 4))
771 if (SPACE_OR_TAB(*s))
775 while (SPACE_OR_TAB(*s))
783 while (SPACE_OR_TAB(*s))
785 if (*s == '"' && (t = strchr(s+1, '"'))) {
795 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
797 if (*e != '\n' && *e != '\0')
798 return; /* false alarm */
801 const STRLEN len = t - s;
803 const char * const cf = CopFILE(PL_curcop);
804 STRLEN tmplen = cf ? strlen(cf) : 0;
805 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
806 /* must copy *{"::_<(eval N)[oldfilename:L]"}
807 * to *{"::_<newfilename"} */
808 /* However, the long form of evals is only turned on by the
809 debugger - usually they're "(eval %lu)" */
813 STRLEN tmplen2 = len;
814 if (tmplen + 2 <= sizeof smallbuf)
817 Newx(tmpbuf, tmplen + 2, char);
820 memcpy(tmpbuf + 2, cf, tmplen);
822 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
827 if (tmplen2 + 2 <= sizeof smallbuf)
830 Newx(tmpbuf2, tmplen2 + 2, char);
832 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
833 /* Either they malloc'd it, or we malloc'd it,
834 so no prefix is present in ours. */
839 memcpy(tmpbuf2 + 2, s, tmplen2);
842 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
844 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
845 /* adjust ${"::_<newfilename"} to store the new file name */
846 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
847 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
848 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
851 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
853 if (tmpbuf != smallbuf) Safefree(tmpbuf);
856 CopFILE_free(PL_curcop);
857 CopFILE_setn(PL_curcop, s, len);
859 CopLINE_set(PL_curcop, atoi(n)-1);
863 /* skip space before PL_thistoken */
866 S_skipspace0(pTHX_ register char *s)
873 PL_thiswhite = newSVpvs("");
874 sv_catsv(PL_thiswhite, PL_skipwhite);
875 sv_free(PL_skipwhite);
878 PL_realtokenstart = s - SvPVX(PL_linestr);
882 /* skip space after PL_thistoken */
885 S_skipspace1(pTHX_ register char *s)
887 const char *start = s;
888 I32 startoff = start - SvPVX(PL_linestr);
893 start = SvPVX(PL_linestr) + startoff;
894 if (!PL_thistoken && PL_realtokenstart >= 0) {
895 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
896 PL_thistoken = newSVpvn(tstart, start - tstart);
898 PL_realtokenstart = -1;
901 PL_nextwhite = newSVpvs("");
902 sv_catsv(PL_nextwhite, PL_skipwhite);
903 sv_free(PL_skipwhite);
910 S_skipspace2(pTHX_ register char *s, SV **svp)
913 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
914 const I32 startoff = s - SvPVX(PL_linestr);
917 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
918 if (!PL_madskills || !svp)
920 start = SvPVX(PL_linestr) + startoff;
921 if (!PL_thistoken && PL_realtokenstart >= 0) {
922 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
923 PL_thistoken = newSVpvn(tstart, start - tstart);
924 PL_realtokenstart = -1;
929 sv_setsv(*svp, PL_skipwhite);
930 sv_free(PL_skipwhite);
939 S_update_debugger_info(pTHX_ SV *orig_sv, const char *buf, STRLEN len)
941 AV *av = CopFILEAVx(PL_curcop);
943 SV * const sv = newSV_type(SVt_PVMG);
945 sv_setsv(sv, orig_sv);
947 sv_setpvn(sv, buf, len);
950 av_store(av, (I32)CopLINE(PL_curcop), sv);
956 * Called to gobble the appropriate amount and type of whitespace.
957 * Skips comments as well.
961 S_skipspace(pTHX_ register char *s)
966 int startoff = s - SvPVX(PL_linestr);
969 sv_free(PL_skipwhite);
974 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
975 while (s < PL_bufend && SPACE_OR_TAB(*s))
985 SSize_t oldprevlen, oldoldprevlen;
986 SSize_t oldloplen = 0, oldunilen = 0;
987 while (s < PL_bufend && isSPACE(*s)) {
988 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
993 if (s < PL_bufend && *s == '#') {
994 while (s < PL_bufend && *s != '\n')
998 if (PL_in_eval && !PL_rsfp) {
1005 /* only continue to recharge the buffer if we're at the end
1006 * of the buffer, we're not reading from a source filter, and
1007 * we're in normal lexing mode
1009 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
1010 PL_lex_state == LEX_FORMLINE)
1017 /* try to recharge the buffer */
1019 curoff = s - SvPVX(PL_linestr);
1022 if ((s = filter_gets(PL_linestr, PL_rsfp,
1023 (prevlen = SvCUR(PL_linestr)))) == NULL)
1026 if (PL_madskills && curoff != startoff) {
1028 PL_skipwhite = newSVpvs("");
1029 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1033 /* mustn't throw out old stuff yet if madpropping */
1034 SvCUR(PL_linestr) = curoff;
1035 s = SvPVX(PL_linestr) + curoff;
1037 if (curoff && s[-1] == '\n')
1041 /* end of file. Add on the -p or -n magic */
1042 /* XXX these shouldn't really be added here, can't set PL_faketokens */
1045 sv_catpvs(PL_linestr,
1046 ";}continue{print or die qq(-p destination: $!\\n);}");
1048 sv_setpvs(PL_linestr,
1049 ";}continue{print or die qq(-p destination: $!\\n);}");
1051 PL_minus_n = PL_minus_p = 0;
1053 else if (PL_minus_n) {
1055 sv_catpvn(PL_linestr, ";}", 2);
1057 sv_setpvn(PL_linestr, ";}", 2);
1063 sv_catpvn(PL_linestr,";", 1);
1065 sv_setpvn(PL_linestr,";", 1);
1068 /* reset variables for next time we lex */
1069 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
1075 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1076 PL_last_lop = PL_last_uni = NULL;
1078 /* Close the filehandle. Could be from -P preprocessor,
1079 * STDIN, or a regular file. If we were reading code from
1080 * STDIN (because the commandline held no -e or filename)
1081 * then we don't close it, we reset it so the code can
1082 * read from STDIN too.
1085 if (PL_preprocess && !PL_in_eval)
1086 (void)PerlProc_pclose(PL_rsfp);
1087 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1088 PerlIO_clearerr(PL_rsfp);
1090 (void)PerlIO_close(PL_rsfp);
1095 /* not at end of file, so we only read another line */
1096 /* make corresponding updates to old pointers, for yyerror() */
1097 oldprevlen = PL_oldbufptr - PL_bufend;
1098 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1100 oldunilen = PL_last_uni - PL_bufend;
1102 oldloplen = PL_last_lop - PL_bufend;
1103 PL_linestart = PL_bufptr = s + prevlen;
1104 PL_bufend = s + SvCUR(PL_linestr);
1106 PL_oldbufptr = s + oldprevlen;
1107 PL_oldoldbufptr = s + oldoldprevlen;
1109 PL_last_uni = s + oldunilen;
1111 PL_last_lop = s + oldloplen;
1114 /* debugger active and we're not compiling the debugger code,
1115 * so store the line into the debugger's array of lines
1117 if (PERLDB_LINE && PL_curstash != PL_debstash)
1118 update_debugger_info(NULL, PL_bufptr, PL_bufend - PL_bufptr);
1125 PL_skipwhite = newSVpvs("");
1126 curoff = s - SvPVX(PL_linestr);
1127 if (curoff - startoff)
1128 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1137 * Check the unary operators to ensure there's no ambiguity in how they're
1138 * used. An ambiguous piece of code would be:
1140 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1141 * the +5 is its argument.
1151 if (PL_oldoldbufptr != PL_last_uni)
1153 while (isSPACE(*PL_last_uni))
1156 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1158 if ((t = strchr(s, '(')) && t < PL_bufptr)
1161 if (ckWARN_d(WARN_AMBIGUOUS)){
1162 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1163 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1164 (int)(s - PL_last_uni), PL_last_uni);
1169 * LOP : macro to build a list operator. Its behaviour has been replaced
1170 * with a subroutine, S_lop() for which LOP is just another name.
1173 #define LOP(f,x) return lop(f,x,s)
1177 * Build a list operator (or something that might be one). The rules:
1178 * - if we have a next token, then it's a list operator [why?]
1179 * - if the next thing is an opening paren, then it's a function
1180 * - else it's a list operator
1184 S_lop(pTHX_ I32 f, int x, char *s)
1191 PL_last_lop = PL_oldbufptr;
1192 PL_last_lop_op = (OPCODE)f;
1195 return REPORT(LSTOP);
1198 return REPORT(LSTOP);
1201 return REPORT(FUNC);
1204 return REPORT(FUNC);
1206 return REPORT(LSTOP);
1212 * Sets up for an eventual force_next(). start_force(0) basically does
1213 * an unshift, while start_force(-1) does a push. yylex removes items
1218 S_start_force(pTHX_ int where)
1222 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1223 where = PL_lasttoke;
1224 assert(PL_curforce < 0 || PL_curforce == where);
1225 if (PL_curforce != where) {
1226 for (i = PL_lasttoke; i > where; --i) {
1227 PL_nexttoke[i] = PL_nexttoke[i-1];
1231 if (PL_curforce < 0) /* in case of duplicate start_force() */
1232 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1233 PL_curforce = where;
1236 curmad('^', newSVpvs(""));
1237 CURMAD('_', PL_nextwhite);
1242 S_curmad(pTHX_ char slot, SV *sv)
1248 if (PL_curforce < 0)
1249 where = &PL_thismad;
1251 where = &PL_nexttoke[PL_curforce].next_mad;
1254 sv_setpvn(sv, "", 0);
1257 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1259 else if (PL_encoding) {
1260 sv_recode_to_utf8(sv, PL_encoding);
1265 /* keep a slot open for the head of the list? */
1266 if (slot != '_' && *where && (*where)->mad_key == '^') {
1267 (*where)->mad_key = slot;
1268 sv_free((*where)->mad_val);
1269 (*where)->mad_val = (void*)sv;
1272 addmad(newMADsv(slot, sv), where, 0);
1275 # define start_force(where) NOOP
1276 # define curmad(slot, sv) NOOP
1281 * When the lexer realizes it knows the next token (for instance,
1282 * it is reordering tokens for the parser) then it can call S_force_next
1283 * to know what token to return the next time the lexer is called. Caller
1284 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1285 * and possibly PL_expect to ensure the lexer handles the token correctly.
1289 S_force_next(pTHX_ I32 type)
1293 if (PL_curforce < 0)
1294 start_force(PL_lasttoke);
1295 PL_nexttoke[PL_curforce].next_type = type;
1296 if (PL_lex_state != LEX_KNOWNEXT)
1297 PL_lex_defer = PL_lex_state;
1298 PL_lex_state = LEX_KNOWNEXT;
1299 PL_lex_expect = PL_expect;
1302 PL_nexttype[PL_nexttoke] = type;
1304 if (PL_lex_state != LEX_KNOWNEXT) {
1305 PL_lex_defer = PL_lex_state;
1306 PL_lex_expect = PL_expect;
1307 PL_lex_state = LEX_KNOWNEXT;
1313 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1316 SV * const sv = newSVpvn(start,len);
1317 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1324 * When the lexer knows the next thing is a word (for instance, it has
1325 * just seen -> and it knows that the next char is a word char, then
1326 * it calls S_force_word to stick the next word into the PL_nexttoke/val
1330 * char *start : buffer position (must be within PL_linestr)
1331 * int token : PL_next* will be this type of bare word (e.g., METHOD,WORD)
1332 * int check_keyword : if true, Perl checks to make sure the word isn't
1333 * a keyword (do this if the word is a label, e.g. goto FOO)
1334 * int allow_pack : if true, : characters will also be allowed (require,
1335 * use, etc. do this)
1336 * int allow_initial_tick : used by the "sub" lexer only.
1340 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1346 start = SKIPSPACE1(start);
1348 if (isIDFIRST_lazy_if(s,UTF) ||
1349 (allow_pack && *s == ':') ||
1350 (allow_initial_tick && *s == '\'') )
1352 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1353 if (check_keyword && keyword(PL_tokenbuf, len, 0))
1355 start_force(PL_curforce);
1357 curmad('X', newSVpvn(start,s-start));
1358 if (token == METHOD) {
1363 PL_expect = XOPERATOR;
1367 curmad('g', newSVpvs( "forced" ));
1368 NEXTVAL_NEXTTOKE.opval
1369 = (OP*)newSVOP(OP_CONST,0,
1370 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1371 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1379 * Called when the lexer wants $foo *foo &foo etc, but the program
1380 * text only contains the "foo" portion. The first argument is a pointer
1381 * to the "foo", and the second argument is the type symbol to prefix.
1382 * Forces the next token to be a "WORD".
1383 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1387 S_force_ident(pTHX_ register const char *s, int kind)
1391 const STRLEN len = strlen(s);
1392 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1393 start_force(PL_curforce);
1394 NEXTVAL_NEXTTOKE.opval = o;
1397 o->op_private = OPpCONST_ENTERED;
1398 /* XXX see note in pp_entereval() for why we forgo typo
1399 warnings if the symbol must be introduced in an eval.
1401 gv_fetchpvn_flags(s, len,
1402 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1404 kind == '$' ? SVt_PV :
1405 kind == '@' ? SVt_PVAV :
1406 kind == '%' ? SVt_PVHV :
1414 Perl_str_to_version(pTHX_ SV *sv)
1419 const char *start = SvPV_const(sv,len);
1420 const char * const end = start + len;
1421 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1422 while (start < end) {
1426 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1431 retval += ((NV)n)/nshift;
1440 * Forces the next token to be a version number.
1441 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1442 * and if "guessing" is TRUE, then no new token is created (and the caller
1443 * must use an alternative parsing method).
1447 S_force_version(pTHX_ char *s, int guessing)
1453 I32 startoff = s - SvPVX(PL_linestr);
1462 while (isDIGIT(*d) || *d == '_' || *d == '.')
1466 start_force(PL_curforce);
1467 curmad('X', newSVpvn(s,d-s));
1470 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1472 s = scan_num(s, &yylval);
1473 version = yylval.opval;
1474 ver = cSVOPx(version)->op_sv;
1475 if (SvPOK(ver) && !SvNIOK(ver)) {
1476 SvUPGRADE(ver, SVt_PVNV);
1477 SvNV_set(ver, str_to_version(ver));
1478 SvNOK_on(ver); /* hint that it is a version */
1481 else if (guessing) {
1484 sv_free(PL_nextwhite); /* let next token collect whitespace */
1486 s = SvPVX(PL_linestr) + startoff;
1494 if (PL_madskills && !version) {
1495 sv_free(PL_nextwhite); /* let next token collect whitespace */
1497 s = SvPVX(PL_linestr) + startoff;
1500 /* NOTE: The parser sees the package name and the VERSION swapped */
1501 start_force(PL_curforce);
1502 NEXTVAL_NEXTTOKE.opval = version;
1510 * Tokenize a quoted string passed in as an SV. It finds the next
1511 * chunk, up to end of string or a backslash. It may make a new
1512 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1517 S_tokeq(pTHX_ SV *sv)
1521 register char *send;
1529 s = SvPV_force(sv, len);
1530 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1533 while (s < send && *s != '\\')
1538 if ( PL_hints & HINT_NEW_STRING ) {
1539 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1545 if (s + 1 < send && (s[1] == '\\'))
1546 s++; /* all that, just for this */
1551 SvCUR_set(sv, d - SvPVX_const(sv));
1553 if ( PL_hints & HINT_NEW_STRING )
1554 return new_constant(NULL, 0, "q", sv, pv, "q");
1559 * Now come three functions related to double-quote context,
1560 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1561 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1562 * interact with PL_lex_state, and create fake ( ... ) argument lists
1563 * to handle functions and concatenation.
1564 * They assume that whoever calls them will be setting up a fake
1565 * join call, because each subthing puts a ',' after it. This lets
1568 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1570 * (I'm not sure whether the spurious commas at the end of lcfirst's
1571 * arguments and join's arguments are created or not).
1576 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1578 * Pattern matching will set PL_lex_op to the pattern-matching op to
1579 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1581 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1583 * Everything else becomes a FUNC.
1585 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1586 * had an OP_CONST or OP_READLINE). This just sets us up for a
1587 * call to S_sublex_push().
1591 S_sublex_start(pTHX)
1594 register const I32 op_type = yylval.ival;
1596 if (op_type == OP_NULL) {
1597 yylval.opval = PL_lex_op;
1601 if (op_type == OP_CONST || op_type == OP_READLINE) {
1602 SV *sv = tokeq(PL_lex_stuff);
1604 if (SvTYPE(sv) == SVt_PVIV) {
1605 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1607 const char * const p = SvPV_const(sv, len);
1608 SV * const nsv = newSVpvn(p, len);
1614 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1615 PL_lex_stuff = NULL;
1616 /* Allow <FH> // "foo" */
1617 if (op_type == OP_READLINE)
1618 PL_expect = XTERMORDORDOR;
1621 else if (op_type == OP_BACKTICK && PL_lex_op) {
1622 /* readpipe() vas overriden */
1623 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1624 yylval.opval = PL_lex_op;
1626 PL_lex_stuff = NULL;
1630 PL_sublex_info.super_state = PL_lex_state;
1631 PL_sublex_info.sub_inwhat = (U16)op_type;
1632 PL_sublex_info.sub_op = PL_lex_op;
1633 PL_lex_state = LEX_INTERPPUSH;
1637 yylval.opval = PL_lex_op;
1647 * Create a new scope to save the lexing state. The scope will be
1648 * ended in S_sublex_done. Returns a '(', starting the function arguments
1649 * to the uc, lc, etc. found before.
1650 * Sets PL_lex_state to LEX_INTERPCONCAT.
1659 PL_lex_state = PL_sublex_info.super_state;
1660 SAVEBOOL(PL_lex_dojoin);
1661 SAVEI32(PL_lex_brackets);
1662 SAVEI32(PL_lex_casemods);
1663 SAVEI32(PL_lex_starts);
1664 SAVEI8(PL_lex_state);
1665 SAVEVPTR(PL_lex_inpat);
1666 SAVEI16(PL_lex_inwhat);
1667 SAVECOPLINE(PL_curcop);
1668 SAVEPPTR(PL_bufptr);
1669 SAVEPPTR(PL_bufend);
1670 SAVEPPTR(PL_oldbufptr);
1671 SAVEPPTR(PL_oldoldbufptr);
1672 SAVEPPTR(PL_last_lop);
1673 SAVEPPTR(PL_last_uni);
1674 SAVEPPTR(PL_linestart);
1675 SAVESPTR(PL_linestr);
1676 SAVEGENERICPV(PL_lex_brackstack);
1677 SAVEGENERICPV(PL_lex_casestack);
1679 PL_linestr = PL_lex_stuff;
1680 PL_lex_stuff = NULL;
1682 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1683 = SvPVX(PL_linestr);
1684 PL_bufend += SvCUR(PL_linestr);
1685 PL_last_lop = PL_last_uni = NULL;
1686 SAVEFREESV(PL_linestr);
1688 PL_lex_dojoin = FALSE;
1689 PL_lex_brackets = 0;
1690 Newx(PL_lex_brackstack, 120, char);
1691 Newx(PL_lex_casestack, 12, char);
1692 PL_lex_casemods = 0;
1693 *PL_lex_casestack = '\0';
1695 PL_lex_state = LEX_INTERPCONCAT;
1696 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1698 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1699 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1700 PL_lex_inpat = PL_sublex_info.sub_op;
1702 PL_lex_inpat = NULL;
1709 * Restores lexer state after a S_sublex_push.
1716 if (!PL_lex_starts++) {
1717 SV * const sv = newSVpvs("");
1718 if (SvUTF8(PL_linestr))
1720 PL_expect = XOPERATOR;
1721 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1725 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1726 PL_lex_state = LEX_INTERPCASEMOD;
1730 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1731 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1732 PL_linestr = PL_lex_repl;
1734 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1735 PL_bufend += SvCUR(PL_linestr);
1736 PL_last_lop = PL_last_uni = NULL;
1737 SAVEFREESV(PL_linestr);
1738 PL_lex_dojoin = FALSE;
1739 PL_lex_brackets = 0;
1740 PL_lex_casemods = 0;
1741 *PL_lex_casestack = '\0';
1743 if (SvEVALED(PL_lex_repl)) {
1744 PL_lex_state = LEX_INTERPNORMAL;
1746 /* we don't clear PL_lex_repl here, so that we can check later
1747 whether this is an evalled subst; that means we rely on the
1748 logic to ensure sublex_done() is called again only via the
1749 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1752 PL_lex_state = LEX_INTERPCONCAT;
1762 PL_endwhite = newSVpvs("");
1763 sv_catsv(PL_endwhite, PL_thiswhite);
1767 sv_setpvn(PL_thistoken,"",0);
1769 PL_realtokenstart = -1;
1773 PL_bufend = SvPVX(PL_linestr);
1774 PL_bufend += SvCUR(PL_linestr);
1775 PL_expect = XOPERATOR;
1776 PL_sublex_info.sub_inwhat = 0;
1784 Extracts a pattern, double-quoted string, or transliteration. This
1787 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
1788 processing a pattern (PL_lex_inpat is true), a transliteration
1789 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
1791 Returns a pointer to the character scanned up to. If this is
1792 advanced from the start pointer supplied (i.e. if anything was
1793 successfully parsed), will leave an OP for the substring scanned
1794 in yylval. Caller must intuit reason for not parsing further
1795 by looking at the next characters herself.
1799 double-quoted style: \r and \n
1800 regexp special ones: \D \s
1803 case and quoting: \U \Q \E
1804 stops on @ and $, but not for $ as tail anchor
1806 In transliterations:
1807 characters are VERY literal, except for - not at the start or end
1808 of the string, which indicates a range. If the range is in bytes,
1809 scan_const expands the range to the full set of intermediate
1810 characters. If the range is in utf8, the hyphen is replaced with
1811 a certain range mark which will be handled by pmtrans() in op.c.
1813 In double-quoted strings:
1815 double-quoted style: \r and \n
1817 deprecated backrefs: \1 (in substitution replacements)
1818 case and quoting: \U \Q \E
1821 scan_const does *not* construct ops to handle interpolated strings.
1822 It stops processing as soon as it finds an embedded $ or @ variable
1823 and leaves it to the caller to work out what's going on.
1825 embedded arrays (whether in pattern or not) could be:
1826 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1828 $ in double-quoted strings must be the symbol of an embedded scalar.
1830 $ in pattern could be $foo or could be tail anchor. Assumption:
1831 it's a tail anchor if $ is the last thing in the string, or if it's
1832 followed by one of "()| \r\n\t"
1834 \1 (backreferences) are turned into $1
1836 The structure of the code is
1837 while (there's a character to process) {
1838 handle transliteration ranges
1839 skip regexp comments /(?#comment)/ and codes /(?{code})/
1840 skip #-initiated comments in //x patterns
1841 check for embedded arrays
1842 check for embedded scalars
1844 leave intact backslashes from leaveit (below)
1845 deprecate \1 in substitution replacements
1846 handle string-changing backslashes \l \U \Q \E, etc.
1847 switch (what was escaped) {
1848 handle \- in a transliteration (becomes a literal -)
1849 handle \132 (octal characters)
1850 handle \x15 and \x{1234} (hex characters)
1851 handle \N{name} (named characters)
1852 handle \cV (control characters)
1853 handle printf-style backslashes (\f, \r, \n, etc)
1855 } (end if backslash)
1856 } (end while character to read)
1861 S_scan_const(pTHX_ char *start)
1864 register char *send = PL_bufend; /* end of the constant */
1865 SV *sv = newSV(send - start); /* sv for the constant */
1866 register char *s = start; /* start of the constant */
1867 register char *d = SvPVX(sv); /* destination for copies */
1868 bool dorange = FALSE; /* are we in a translit range? */
1869 bool didrange = FALSE; /* did we just finish a range? */
1870 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1871 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1874 UV literal_endpoint = 0;
1875 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
1878 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1879 /* If we are doing a trans and we know we want UTF8 set expectation */
1880 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1881 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1885 while (s < send || dorange) {
1886 /* get transliterations out of the way (they're most literal) */
1887 if (PL_lex_inwhat == OP_TRANS) {
1888 /* expand a range A-Z to the full set of characters. AIE! */
1890 I32 i; /* current expanded character */
1891 I32 min; /* first character in range */
1892 I32 max; /* last character in range */
1903 char * const c = (char*)utf8_hop((U8*)d, -1);
1907 *c = (char)UTF_TO_NATIVE(0xff);
1908 /* mark the range as done, and continue */
1914 i = d - SvPVX_const(sv); /* remember current offset */
1917 SvLEN(sv) + (has_utf8 ?
1918 (512 - UTF_CONTINUATION_MARK +
1921 /* How many two-byte within 0..255: 128 in UTF-8,
1922 * 96 in UTF-8-mod. */
1924 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1926 d = SvPVX(sv) + i; /* refresh d after realloc */
1930 for (j = 0; j <= 1; j++) {
1931 char * const c = (char*)utf8_hop((U8*)d, -1);
1932 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
1938 max = (U8)0xff; /* only to \xff */
1939 uvmax = uv; /* \x{100} to uvmax */
1941 d = c; /* eat endpoint chars */
1946 d -= 2; /* eat the first char and the - */
1947 min = (U8)*d; /* first char in range */
1948 max = (U8)d[1]; /* last char in range */
1955 "Invalid range \"%c-%c\" in transliteration operator",
1956 (char)min, (char)max);
1960 if (literal_endpoint == 2 &&
1961 ((isLOWER(min) && isLOWER(max)) ||
1962 (isUPPER(min) && isUPPER(max)))) {
1964 for (i = min; i <= max; i++)
1966 *d++ = NATIVE_TO_NEED(has_utf8,i);
1968 for (i = min; i <= max; i++)
1970 *d++ = NATIVE_TO_NEED(has_utf8,i);
1975 for (i = min; i <= max; i++)
1978 const U8 ch = (U8)NATIVE_TO_UTF(i);
1979 if (UNI_IS_INVARIANT(ch))
1982 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
1983 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
1992 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
1994 *d++ = (char)UTF_TO_NATIVE(0xff);
1996 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
2000 /* mark the range as done, and continue */
2004 literal_endpoint = 0;
2009 /* range begins (ignore - as first or last char) */
2010 else if (*s == '-' && s+1 < send && s != start) {
2012 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
2019 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
2029 literal_endpoint = 0;
2030 native_range = TRUE;
2035 /* if we get here, we're not doing a transliteration */
2037 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2038 except for the last char, which will be done separately. */
2039 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
2041 while (s+1 < send && *s != ')')
2042 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2044 else if (s[2] == '{' /* This should match regcomp.c */
2045 || (s[2] == '?' && s[3] == '{'))
2048 char *regparse = s + (s[2] == '{' ? 3 : 4);
2051 while (count && (c = *regparse)) {
2052 if (c == '\\' && regparse[1])
2060 if (*regparse != ')')
2061 regparse--; /* Leave one char for continuation. */
2062 while (s < regparse)
2063 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2067 /* likewise skip #-initiated comments in //x patterns */
2068 else if (*s == '#' && PL_lex_inpat &&
2069 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2070 while (s+1 < send && *s != '\n')
2071 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2074 /* check for embedded arrays
2075 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2077 else if (*s == '@' && s[1]) {
2078 if (isALNUM_lazy_if(s+1,UTF))
2080 if (strchr(":'{$", s[1]))
2082 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2083 break; /* in regexp, neither @+ nor @- are interpolated */
2086 /* check for embedded scalars. only stop if we're sure it's a
2089 else if (*s == '$') {
2090 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
2092 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
2093 break; /* in regexp, $ might be tail anchor */
2096 /* End of else if chain - OP_TRANS rejoin rest */
2099 if (*s == '\\' && s+1 < send) {
2102 /* deprecate \1 in strings and substitution replacements */
2103 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2104 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2106 if (ckWARN(WARN_SYNTAX))
2107 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2112 /* string-change backslash escapes */
2113 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2117 /* skip any other backslash escapes in a pattern */
2118 else if (PL_lex_inpat) {
2119 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2120 goto default_action;
2123 /* if we get here, it's either a quoted -, or a digit */
2126 /* quoted - in transliterations */
2128 if (PL_lex_inwhat == OP_TRANS) {
2135 if ((isALPHA(*s) || isDIGIT(*s)) &&
2137 Perl_warner(aTHX_ packWARN(WARN_MISC),
2138 "Unrecognized escape \\%c passed through",
2140 /* default action is to copy the quoted character */
2141 goto default_action;
2144 /* \132 indicates an octal constant */
2145 case '0': case '1': case '2': case '3':
2146 case '4': case '5': case '6': case '7':
2150 uv = grok_oct(s, &len, &flags, NULL);
2153 goto NUM_ESCAPE_INSERT;
2155 /* \x24 indicates a hex constant */
2159 char* const e = strchr(s, '}');
2160 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2161 PERL_SCAN_DISALLOW_PREFIX;
2166 yyerror("Missing right brace on \\x{}");
2170 uv = grok_hex(s, &len, &flags, NULL);
2176 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2177 uv = grok_hex(s, &len, &flags, NULL);
2183 /* Insert oct or hex escaped character.
2184 * There will always enough room in sv since such
2185 * escapes will be longer than any UTF-8 sequence
2186 * they can end up as. */
2188 /* We need to map to chars to ASCII before doing the tests
2191 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2192 if (!has_utf8 && uv > 255) {
2193 /* Might need to recode whatever we have
2194 * accumulated so far if it contains any
2197 * (Can't we keep track of that and avoid
2198 * this rescan? --jhi)
2202 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2203 if (!NATIVE_IS_INVARIANT(*c)) {
2208 const STRLEN offset = d - SvPVX_const(sv);
2210 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2214 while (src >= (const U8 *)SvPVX_const(sv)) {
2215 if (!NATIVE_IS_INVARIANT(*src)) {
2216 const U8 ch = NATIVE_TO_ASCII(*src);
2217 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2218 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2228 if (has_utf8 || uv > 255) {
2229 d = (char*)uvchr_to_utf8((U8*)d, uv);
2231 if (PL_lex_inwhat == OP_TRANS &&
2232 PL_sublex_info.sub_op) {
2233 PL_sublex_info.sub_op->op_private |=
2234 (PL_lex_repl ? OPpTRANS_FROM_UTF
2238 if (uv > 255 && !dorange)
2239 native_range = FALSE;
2251 /* \N{LATIN SMALL LETTER A} is a named character */
2255 char* e = strchr(s, '}');
2262 yyerror("Missing right brace on \\N{}");
2266 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2268 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2269 PERL_SCAN_DISALLOW_PREFIX;
2272 uv = grok_hex(s, &len, &flags, NULL);
2273 if ( e > s && len != (STRLEN)(e - s) ) {
2277 goto NUM_ESCAPE_INSERT;
2279 res = newSVpvn(s + 1, e - s - 1);
2280 type = newSVpvn(s - 2,e - s + 3);
2281 res = new_constant( NULL, 0, "charnames",
2282 res, NULL, SvPVX(type) );
2285 sv_utf8_upgrade(res);
2286 str = SvPV_const(res,len);
2287 #ifdef EBCDIC_NEVER_MIND
2288 /* charnames uses pack U and that has been
2289 * recently changed to do the below uni->native
2290 * mapping, so this would be redundant (and wrong,
2291 * the code point would be doubly converted).
2292 * But leave this in just in case the pack U change
2293 * gets revoked, but the semantics is still
2294 * desireable for charnames. --jhi */
2296 UV uv = utf8_to_uvchr((const U8*)str, 0);
2299 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2301 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2302 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2303 str = SvPV_const(res, len);
2307 if (!has_utf8 && SvUTF8(res)) {
2308 const char * const ostart = SvPVX_const(sv);
2309 SvCUR_set(sv, d - ostart);
2312 sv_utf8_upgrade(sv);
2313 /* this just broke our allocation above... */
2314 SvGROW(sv, (STRLEN)(send - start));
2315 d = SvPVX(sv) + SvCUR(sv);
2318 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2319 const char * const odest = SvPVX_const(sv);
2321 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2322 d = SvPVX(sv) + (d - odest);
2326 native_range = FALSE; /* \N{} is guessed to be Unicode */
2328 Copy(str, d, len, char);
2335 yyerror("Missing braces on \\N{}");
2338 /* \c is a control character */
2347 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2350 yyerror("Missing control char name in \\c");
2354 /* printf-style backslashes, formfeeds, newlines, etc */
2356 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2359 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2362 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2365 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2368 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2371 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2374 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2380 } /* end if (backslash) */
2387 /* If we started with encoded form, or already know we want it
2388 and then encode the next character */
2389 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2391 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2392 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2395 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2396 const STRLEN off = d - SvPVX_const(sv);
2397 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2399 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2402 if (uv > 255 && !dorange)
2403 native_range = FALSE;
2407 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2409 } /* while loop to process each character */
2411 /* terminate the string and set up the sv */
2413 SvCUR_set(sv, d - SvPVX_const(sv));
2414 if (SvCUR(sv) >= SvLEN(sv))
2415 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2418 if (PL_encoding && !has_utf8) {
2419 sv_recode_to_utf8(sv, PL_encoding);
2425 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2426 PL_sublex_info.sub_op->op_private |=
2427 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2431 /* shrink the sv if we allocated more than we used */
2432 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2433 SvPV_shrink_to_cur(sv);
2436 /* return the substring (via yylval) only if we parsed anything */
2437 if (s > PL_bufptr) {
2438 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2439 sv = new_constant(start, s - start,
2440 (const char *)(PL_lex_inpat ? "qr" : "q"),
2443 (( PL_lex_inwhat == OP_TRANS
2445 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2448 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2455 * Returns TRUE if there's more to the expression (e.g., a subscript),
2458 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2460 * ->[ and ->{ return TRUE
2461 * { and [ outside a pattern are always subscripts, so return TRUE
2462 * if we're outside a pattern and it's not { or [, then return FALSE
2463 * if we're in a pattern and the first char is a {
2464 * {4,5} (any digits around the comma) returns FALSE
2465 * if we're in a pattern and the first char is a [
2467 * [SOMETHING] has a funky algorithm to decide whether it's a
2468 * character class or not. It has to deal with things like
2469 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2470 * anything else returns TRUE
2473 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2476 S_intuit_more(pTHX_ register char *s)
2479 if (PL_lex_brackets)
2481 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2483 if (*s != '{' && *s != '[')
2488 /* In a pattern, so maybe we have {n,m}. */
2505 /* On the other hand, maybe we have a character class */
2508 if (*s == ']' || *s == '^')
2511 /* this is terrifying, and it works */
2512 int weight = 2; /* let's weigh the evidence */
2514 unsigned char un_char = 255, last_un_char;
2515 const char * const send = strchr(s,']');
2516 char tmpbuf[sizeof PL_tokenbuf * 4];
2518 if (!send) /* has to be an expression */
2521 Zero(seen,256,char);
2524 else if (isDIGIT(*s)) {
2526 if (isDIGIT(s[1]) && s[2] == ']')
2532 for (; s < send; s++) {
2533 last_un_char = un_char;
2534 un_char = (unsigned char)*s;
2539 weight -= seen[un_char] * 10;
2540 if (isALNUM_lazy_if(s+1,UTF)) {
2542 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2543 len = (int)strlen(tmpbuf);
2544 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2549 else if (*s == '$' && s[1] &&
2550 strchr("[#!%*<>()-=",s[1])) {
2551 if (/*{*/ strchr("])} =",s[2]))
2560 if (strchr("wds]",s[1]))
2562 else if (seen[(U8)'\''] || seen[(U8)'"'])
2564 else if (strchr("rnftbxcav",s[1]))
2566 else if (isDIGIT(s[1])) {
2568 while (s[1] && isDIGIT(s[1]))
2578 if (strchr("aA01! ",last_un_char))
2580 if (strchr("zZ79~",s[1]))
2582 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2583 weight -= 5; /* cope with negative subscript */
2586 if (!isALNUM(last_un_char)
2587 && !(last_un_char == '$' || last_un_char == '@'
2588 || last_un_char == '&')
2589 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2594 if (keyword(tmpbuf, d - tmpbuf, 0))
2597 if (un_char == last_un_char + 1)
2599 weight -= seen[un_char];
2604 if (weight >= 0) /* probably a character class */
2614 * Does all the checking to disambiguate
2616 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2617 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2619 * First argument is the stuff after the first token, e.g. "bar".
2621 * Not a method if bar is a filehandle.
2622 * Not a method if foo is a subroutine prototyped to take a filehandle.
2623 * Not a method if it's really "Foo $bar"
2624 * Method if it's "foo $bar"
2625 * Not a method if it's really "print foo $bar"
2626 * Method if it's really "foo package::" (interpreted as package->foo)
2627 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2628 * Not a method if bar is a filehandle or package, but is quoted with
2633 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2636 char *s = start + (*start == '$');
2637 char tmpbuf[sizeof PL_tokenbuf];
2645 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2649 const char *proto = SvPVX_const(cv);
2660 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2661 /* start is the beginning of the possible filehandle/object,
2662 * and s is the end of it
2663 * tmpbuf is a copy of it
2666 if (*start == '$') {
2667 if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
2668 isUPPER(*PL_tokenbuf))
2671 len = start - SvPVX(PL_linestr);
2675 start = SvPVX(PL_linestr) + len;
2679 return *s == '(' ? FUNCMETH : METHOD;
2681 if (!keyword(tmpbuf, len, 0)) {
2682 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2686 soff = s - SvPVX(PL_linestr);
2690 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2691 if (indirgv && GvCVu(indirgv))
2693 /* filehandle or package name makes it a method */
2694 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
2696 soff = s - SvPVX(PL_linestr);
2699 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2700 return 0; /* no assumptions -- "=>" quotes bearword */
2702 start_force(PL_curforce);
2703 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2704 newSVpvn(tmpbuf,len));
2705 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2707 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2712 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2714 return *s == '(' ? FUNCMETH : METHOD;
2722 * Return a string of Perl code to load the debugger. If PERL5DB
2723 * is set, it will return the contents of that, otherwise a
2724 * compile-time require of perl5db.pl.
2732 const char * const pdb = PerlEnv_getenv("PERL5DB");
2736 SETERRNO(0,SS_NORMAL);
2737 return "BEGIN { require 'perl5db.pl' }";
2743 /* Encoded script support. filter_add() effectively inserts a
2744 * 'pre-processing' function into the current source input stream.
2745 * Note that the filter function only applies to the current source file
2746 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2748 * The datasv parameter (which may be NULL) can be used to pass
2749 * private data to this instance of the filter. The filter function
2750 * can recover the SV using the FILTER_DATA macro and use it to
2751 * store private buffers and state information.
2753 * The supplied datasv parameter is upgraded to a PVIO type
2754 * and the IoDIRP/IoANY field is used to store the function pointer,
2755 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2756 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2757 * private use must be set using malloc'd pointers.
2761 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2767 if (!PL_rsfp_filters)
2768 PL_rsfp_filters = newAV();
2771 SvUPGRADE(datasv, SVt_PVIO);
2772 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2773 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2774 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2775 FPTR2DPTR(void *, IoANY(datasv)),
2776 SvPV_nolen(datasv)));
2777 av_unshift(PL_rsfp_filters, 1);
2778 av_store(PL_rsfp_filters, 0, datasv) ;
2783 /* Delete most recently added instance of this filter function. */
2785 Perl_filter_del(pTHX_ filter_t funcp)
2791 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2792 FPTR2DPTR(void*, funcp)));
2794 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2796 /* if filter is on top of stack (usual case) just pop it off */
2797 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2798 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2799 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2800 IoANY(datasv) = (void *)NULL;
2801 sv_free(av_pop(PL_rsfp_filters));
2805 /* we need to search for the correct entry and clear it */
2806 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2810 /* Invoke the idxth filter function for the current rsfp. */
2811 /* maxlen 0 = read one text line */
2813 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2818 /* This API is bad. It should have been using unsigned int for maxlen.
2819 Not sure if we want to change the API, but if not we should sanity
2820 check the value here. */
2821 const unsigned int correct_length
2830 if (!PL_rsfp_filters)
2832 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2833 /* Provide a default input filter to make life easy. */
2834 /* Note that we append to the line. This is handy. */
2835 DEBUG_P(PerlIO_printf(Perl_debug_log,
2836 "filter_read %d: from rsfp\n", idx));
2837 if (correct_length) {
2840 const int old_len = SvCUR(buf_sv);
2842 /* ensure buf_sv is large enough */
2843 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2844 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2845 correct_length)) <= 0) {
2846 if (PerlIO_error(PL_rsfp))
2847 return -1; /* error */
2849 return 0 ; /* end of file */
2851 SvCUR_set(buf_sv, old_len + len) ;
2854 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2855 if (PerlIO_error(PL_rsfp))
2856 return -1; /* error */
2858 return 0 ; /* end of file */
2861 return SvCUR(buf_sv);
2863 /* Skip this filter slot if filter has been deleted */
2864 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2865 DEBUG_P(PerlIO_printf(Perl_debug_log,
2866 "filter_read %d: skipped (filter deleted)\n",
2868 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2870 /* Get function pointer hidden within datasv */
2871 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2872 DEBUG_P(PerlIO_printf(Perl_debug_log,
2873 "filter_read %d: via function %p (%s)\n",
2874 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2875 /* Call function. The function is expected to */
2876 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2877 /* Return: <0:error, =0:eof, >0:not eof */
2878 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2882 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2885 #ifdef PERL_CR_FILTER
2886 if (!PL_rsfp_filters) {
2887 filter_add(S_cr_textfilter,NULL);
2890 if (PL_rsfp_filters) {
2892 SvCUR_set(sv, 0); /* start with empty line */
2893 if (FILTER_READ(0, sv, 0) > 0)
2894 return ( SvPVX(sv) ) ;
2899 return (sv_gets(sv, fp, append));
2903 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2908 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2912 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2913 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2915 return GvHV(gv); /* Foo:: */
2918 /* use constant CLASS => 'MyClass' */
2919 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
2920 if (gv && GvCV(gv)) {
2921 SV * const sv = cv_const_sv(GvCV(gv));
2923 pkgname = SvPV_nolen_const(sv);
2926 return gv_stashpv(pkgname, 0);
2930 * S_readpipe_override
2931 * Check whether readpipe() is overriden, and generates the appropriate
2932 * optree, provided sublex_start() is called afterwards.
2935 S_readpipe_override(pTHX)
2938 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
2939 yylval.ival = OP_BACKTICK;
2941 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
2943 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
2944 && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
2945 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
2947 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
2948 append_elem(OP_LIST,
2949 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
2950 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
2960 * The intent of this yylex wrapper is to minimize the changes to the
2961 * tokener when we aren't interested in collecting madprops. It remains
2962 * to be seen how successful this strategy will be...
2969 char *s = PL_bufptr;
2971 /* make sure PL_thiswhite is initialized */
2975 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2976 if (PL_pending_ident)
2977 return S_pending_ident(aTHX);
2979 /* previous token ate up our whitespace? */
2980 if (!PL_lasttoke && PL_nextwhite) {
2981 PL_thiswhite = PL_nextwhite;
2985 /* isolate the token, and figure out where it is without whitespace */
2986 PL_realtokenstart = -1;
2990 assert(PL_curforce < 0);
2992 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2993 if (!PL_thistoken) {
2994 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2995 PL_thistoken = newSVpvs("");
2997 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2998 PL_thistoken = newSVpvn(tstart, s - tstart);
3001 if (PL_thismad) /* install head */
3002 CURMAD('X', PL_thistoken);
3005 /* last whitespace of a sublex? */
3006 if (optype == ')' && PL_endwhite) {
3007 CURMAD('X', PL_endwhite);
3012 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
3013 if (!PL_thiswhite && !PL_endwhite && !optype) {
3014 sv_free(PL_thistoken);
3019 /* put off final whitespace till peg */
3020 if (optype == ';' && !PL_rsfp) {
3021 PL_nextwhite = PL_thiswhite;
3024 else if (PL_thisopen) {
3025 CURMAD('q', PL_thisopen);
3027 sv_free(PL_thistoken);
3031 /* Store actual token text as madprop X */
3032 CURMAD('X', PL_thistoken);
3036 /* add preceding whitespace as madprop _ */
3037 CURMAD('_', PL_thiswhite);
3041 /* add quoted material as madprop = */
3042 CURMAD('=', PL_thisstuff);
3046 /* add terminating quote as madprop Q */
3047 CURMAD('Q', PL_thisclose);
3051 /* special processing based on optype */
3055 /* opval doesn't need a TOKEN since it can already store mp */
3066 append_madprops(PL_thismad, yylval.opval, 0);
3074 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3083 /* remember any fake bracket that lexer is about to discard */
3084 if (PL_lex_brackets == 1 &&
3085 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3088 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3091 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3092 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3095 break; /* don't bother looking for trailing comment */
3104 /* attach a trailing comment to its statement instead of next token */
3108 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3110 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3112 if (*s == '\n' || *s == '#') {
3113 while (s < PL_bufend && *s != '\n')
3117 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3118 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3135 /* Create new token struct. Note: opvals return early above. */
3136 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
3143 S_tokenize_use(pTHX_ int is_use, char *s) {
3145 if (PL_expect != XSTATE)
3146 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3147 is_use ? "use" : "no"));
3149 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3150 s = force_version(s, TRUE);
3151 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3152 start_force(PL_curforce);
3153 NEXTVAL_NEXTTOKE.opval = NULL;
3156 else if (*s == 'v') {
3157 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3158 s = force_version(s, FALSE);
3162 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3163 s = force_version(s, FALSE);
3165 yylval.ival = is_use;
3169 static const char* const exp_name[] =
3170 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3171 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3178 Works out what to call the token just pulled out of the input
3179 stream. The yacc parser takes care of taking the ops we return and
3180 stitching them into a tree.
3186 if read an identifier
3187 if we're in a my declaration
3188 croak if they tried to say my($foo::bar)
3189 build the ops for a my() declaration
3190 if it's an access to a my() variable
3191 are we in a sort block?
3192 croak if my($a); $a <=> $b
3193 build ops for access to a my() variable
3194 if in a dq string, and they've said @foo and we can't find @foo
3196 build ops for a bareword
3197 if we already built the token before, use it.
3202 #pragma segment Perl_yylex
3208 register char *s = PL_bufptr;
3213 /* orig_keyword, gvp, and gv are initialized here because
3214 * jump to the label just_a_word_zero can bypass their
3215 * initialization later. */
3216 I32 orig_keyword = 0;
3221 SV* tmp = newSVpvs("");
3222 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3223 (IV)CopLINE(PL_curcop),
3224 lex_state_names[PL_lex_state],
3225 exp_name[PL_expect],
3226 pv_display(tmp, s, strlen(s), 0, 60));
3229 /* check if there's an identifier for us to look at */
3230 if (PL_pending_ident)
3231 return REPORT(S_pending_ident(aTHX));
3233 /* no identifier pending identification */
3235 switch (PL_lex_state) {
3237 case LEX_NORMAL: /* Some compilers will produce faster */
3238 case LEX_INTERPNORMAL: /* code if we comment these out. */
3242 /* when we've already built the next token, just pull it out of the queue */
3246 yylval = PL_nexttoke[PL_lasttoke].next_val;
3248 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3249 PL_nexttoke[PL_lasttoke].next_mad = 0;
3250 if (PL_thismad && PL_thismad->mad_key == '_') {
3251 PL_thiswhite = (SV*)PL_thismad->mad_val;
3252 PL_thismad->mad_val = 0;
3253 mad_free(PL_thismad);
3258 PL_lex_state = PL_lex_defer;
3259 PL_expect = PL_lex_expect;
3260 PL_lex_defer = LEX_NORMAL;
3261 if (!PL_nexttoke[PL_lasttoke].next_type)
3266 yylval = PL_nextval[PL_nexttoke];
3268 PL_lex_state = PL_lex_defer;
3269 PL_expect = PL_lex_expect;
3270 PL_lex_defer = LEX_NORMAL;
3274 /* FIXME - can these be merged? */
3275 return(PL_nexttoke[PL_lasttoke].next_type);
3277 return REPORT(PL_nexttype[PL_nexttoke]);
3280 /* interpolated case modifiers like \L \U, including \Q and \E.
3281 when we get here, PL_bufptr is at the \
3283 case LEX_INTERPCASEMOD:
3285 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3286 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3288 /* handle \E or end of string */
3289 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3291 if (PL_lex_casemods) {
3292 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3293 PL_lex_casestack[PL_lex_casemods] = '\0';
3295 if (PL_bufptr != PL_bufend
3296 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3298 PL_lex_state = LEX_INTERPCONCAT;
3301 PL_thistoken = newSVpvs("\\E");
3307 while (PL_bufptr != PL_bufend &&
3308 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3310 PL_thiswhite = newSVpvs("");
3311 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3315 if (PL_bufptr != PL_bufend)
3318 PL_lex_state = LEX_INTERPCONCAT;
3322 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3323 "### Saw case modifier\n"); });
3325 if (s[1] == '\\' && s[2] == 'E') {
3328 PL_thiswhite = newSVpvs("");
3329 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3332 PL_lex_state = LEX_INTERPCONCAT;
3337 if (!PL_madskills) /* when just compiling don't need correct */
3338 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3339 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3340 if ((*s == 'L' || *s == 'U') &&
3341 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3342 PL_lex_casestack[--PL_lex_casemods] = '\0';
3345 if (PL_lex_casemods > 10)
3346 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3347 PL_lex_casestack[PL_lex_casemods++] = *s;
3348 PL_lex_casestack[PL_lex_casemods] = '\0';
3349 PL_lex_state = LEX_INTERPCONCAT;
3350 start_force(PL_curforce);
3351 NEXTVAL_NEXTTOKE.ival = 0;
3353 start_force(PL_curforce);
3355 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3357 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3359 NEXTVAL_NEXTTOKE.ival = OP_LC;
3361 NEXTVAL_NEXTTOKE.ival = OP_UC;
3363 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3365 Perl_croak(aTHX_ "panic: yylex");
3367 SV* const tmpsv = newSVpvs("");
3368 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3374 if (PL_lex_starts) {
3380 sv_free(PL_thistoken);
3381 PL_thistoken = newSVpvs("");
3384 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3385 if (PL_lex_casemods == 1 && PL_lex_inpat)
3394 case LEX_INTERPPUSH:
3395 return REPORT(sublex_push());
3397 case LEX_INTERPSTART:
3398 if (PL_bufptr == PL_bufend)
3399 return REPORT(sublex_done());
3400 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3401 "### Interpolated variable\n"); });
3403 PL_lex_dojoin = (*PL_bufptr == '@');
3404 PL_lex_state = LEX_INTERPNORMAL;
3405 if (PL_lex_dojoin) {
3406 start_force(PL_curforce);
3407 NEXTVAL_NEXTTOKE.ival = 0;
3409 start_force(PL_curforce);
3410 force_ident("\"", '$');
3411 start_force(PL_curforce);
3412 NEXTVAL_NEXTTOKE.ival = 0;
3414 start_force(PL_curforce);
3415 NEXTVAL_NEXTTOKE.ival = 0;
3417 start_force(PL_curforce);
3418 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3421 if (PL_lex_starts++) {
3426 sv_free(PL_thistoken);
3427 PL_thistoken = newSVpvs("");
3430 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3431 if (!PL_lex_casemods && PL_lex_inpat)
3438 case LEX_INTERPENDMAYBE:
3439 if (intuit_more(PL_bufptr)) {
3440 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3446 if (PL_lex_dojoin) {
3447 PL_lex_dojoin = FALSE;
3448 PL_lex_state = LEX_INTERPCONCAT;
3452 sv_free(PL_thistoken);
3453 PL_thistoken = newSVpvs("");
3458 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3459 && SvEVALED(PL_lex_repl))
3461 if (PL_bufptr != PL_bufend)
3462 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3466 case LEX_INTERPCONCAT:
3468 if (PL_lex_brackets)
3469 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3471 if (PL_bufptr == PL_bufend)
3472 return REPORT(sublex_done());
3474 if (SvIVX(PL_linestr) == '\'') {
3475 SV *sv = newSVsv(PL_linestr);
3478 else if ( PL_hints & HINT_NEW_RE )
3479 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3480 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3484 s = scan_const(PL_bufptr);
3486 PL_lex_state = LEX_INTERPCASEMOD;
3488 PL_lex_state = LEX_INTERPSTART;
3491 if (s != PL_bufptr) {
3492 start_force(PL_curforce);
3494 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3496 NEXTVAL_NEXTTOKE = yylval;
3499 if (PL_lex_starts++) {
3503 sv_free(PL_thistoken);
3504 PL_thistoken = newSVpvs("");
3507 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3508 if (!PL_lex_casemods && PL_lex_inpat)
3521 PL_lex_state = LEX_NORMAL;
3522 s = scan_formline(PL_bufptr);
3523 if (!PL_lex_formbrack)
3529 PL_oldoldbufptr = PL_oldbufptr;
3535 sv_free(PL_thistoken);
3538 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3542 if (isIDFIRST_lazy_if(s,UTF))
3544 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3547 goto fake_eof; /* emulate EOF on ^D or ^Z */
3556 if (PL_lex_brackets) {
3557 yyerror((const char *)
3559 ? "Format not terminated"
3560 : "Missing right curly or square bracket"));
3562 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3563 "### Tokener got EOF\n");
3567 if (s++ < PL_bufend)
3568 goto retry; /* ignore stray nulls */
3571 if (!PL_in_eval && !PL_preambled) {
3572 PL_preambled = TRUE;
3577 sv_setpv(PL_linestr,incl_perldb());
3578 if (SvCUR(PL_linestr))
3579 sv_catpvs(PL_linestr,";");
3581 while(AvFILLp(PL_preambleav) >= 0) {
3582 SV *tmpsv = av_shift(PL_preambleav);
3583 sv_catsv(PL_linestr, tmpsv);
3584 sv_catpvs(PL_linestr, ";");
3587 sv_free((SV*)PL_preambleav);
3588 PL_preambleav = NULL;
3590 if (PL_minus_n || PL_minus_p) {
3591 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3593 sv_catpvs(PL_linestr,"chomp;");
3596 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3597 || *PL_splitstr == '"')
3598 && strchr(PL_splitstr + 1, *PL_splitstr))
3599 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3601 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3602 bytes can be used as quoting characters. :-) */
3603 const char *splits = PL_splitstr;
3604 sv_catpvs(PL_linestr, "our @F=split(q\0");
3607 if (*splits == '\\')
3608 sv_catpvn(PL_linestr, splits, 1);
3609 sv_catpvn(PL_linestr, splits, 1);
3610 } while (*splits++);
3611 /* This loop will embed the trailing NUL of
3612 PL_linestr as the last thing it does before
3614 sv_catpvs(PL_linestr, ");");
3618 sv_catpvs(PL_linestr,"our @F=split(' ');");
3622 sv_catpvs(PL_linestr,"use feature ':5.10';");
3623 sv_catpvs(PL_linestr, "\n");
3624 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3625 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3626 PL_last_lop = PL_last_uni = NULL;
3627 if (PERLDB_LINE && PL_curstash != PL_debstash)
3628 update_debugger_info(PL_linestr, NULL, 0);
3632 bof = PL_rsfp ? TRUE : FALSE;
3633 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3636 PL_realtokenstart = -1;
3639 if (PL_preprocess && !PL_in_eval)
3640 (void)PerlProc_pclose(PL_rsfp);
3641 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3642 PerlIO_clearerr(PL_rsfp);
3644 (void)PerlIO_close(PL_rsfp);
3646 PL_doextract = FALSE;
3648 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3653 sv_setpv(PL_linestr,
3656 ? ";}continue{print;}" : ";}"));
3657 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3658 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3659 PL_last_lop = PL_last_uni = NULL;
3660 PL_minus_n = PL_minus_p = 0;
3663 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3664 PL_last_lop = PL_last_uni = NULL;
3665 sv_setpvn(PL_linestr,"",0);
3666 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3668 /* If it looks like the start of a BOM or raw UTF-16,
3669 * check if it in fact is. */
3675 #ifdef PERLIO_IS_STDIO
3676 # ifdef __GNU_LIBRARY__
3677 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3678 # define FTELL_FOR_PIPE_IS_BROKEN
3682 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3683 # define FTELL_FOR_PIPE_IS_BROKEN
3688 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3689 /* This loses the possibility to detect the bof
3690 * situation on perl -P when the libc5 is being used.
3691 * Workaround? Maybe attach some extra state to PL_rsfp?
3694 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3696 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3699 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3700 s = swallow_bom((U8*)s);
3704 /* Incest with pod. */
3707 sv_catsv(PL_thiswhite, PL_linestr);
3709 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
3710 sv_setpvn(PL_linestr, "", 0);
3711 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3712 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3713 PL_last_lop = PL_last_uni = NULL;
3714 PL_doextract = FALSE;
3718 } while (PL_doextract);
3719 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3720 if (PERLDB_LINE && PL_curstash != PL_debstash)
3721 update_debugger_info(PL_linestr, NULL, 0);
3722 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3723 PL_last_lop = PL_last_uni = NULL;
3724 if (CopLINE(PL_curcop) == 1) {
3725 while (s < PL_bufend && isSPACE(*s))
3727 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3731 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3735 if (*s == '#' && *(s+1) == '!')
3737 #ifdef ALTERNATE_SHEBANG
3739 static char const as[] = ALTERNATE_SHEBANG;
3740 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3741 d = s + (sizeof(as) - 1);
3743 #endif /* ALTERNATE_SHEBANG */
3752 while (*d && !isSPACE(*d))
3756 #ifdef ARG_ZERO_IS_SCRIPT
3757 if (ipathend > ipath) {
3759 * HP-UX (at least) sets argv[0] to the script name,
3760 * which makes $^X incorrect. And Digital UNIX and Linux,
3761 * at least, set argv[0] to the basename of the Perl
3762 * interpreter. So, having found "#!", we'll set it right.
3764 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3766 assert(SvPOK(x) || SvGMAGICAL(x));
3767 if (sv_eq(x, CopFILESV(PL_curcop))) {
3768 sv_setpvn(x, ipath, ipathend - ipath);
3774 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3775 const char * const lstart = SvPV_const(x,llen);
3777 bstart += blen - llen;
3778 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3779 sv_setpvn(x, ipath, ipathend - ipath);
3784 TAINT_NOT; /* $^X is always tainted, but that's OK */
3786 #endif /* ARG_ZERO_IS_SCRIPT */
3791 d = instr(s,"perl -");
3793 d = instr(s,"perl");
3795 /* avoid getting into infinite loops when shebang
3796 * line contains "Perl" rather than "perl" */
3798 for (d = ipathend-4; d >= ipath; --d) {
3799 if ((*d == 'p' || *d == 'P')
3800 && !ibcmp(d, "perl", 4))
3810 #ifdef ALTERNATE_SHEBANG
3812 * If the ALTERNATE_SHEBANG on this system starts with a
3813 * character that can be part of a Perl expression, then if
3814 * we see it but not "perl", we're probably looking at the
3815 * start of Perl code, not a request to hand off to some
3816 * other interpreter. Similarly, if "perl" is there, but
3817 * not in the first 'word' of the line, we assume the line
3818 * contains the start of the Perl program.
3820 if (d && *s != '#') {
3821 const char *c = ipath;
3822 while (*c && !strchr("; \t\r\n\f\v#", *c))
3825 d = NULL; /* "perl" not in first word; ignore */
3827 *s = '#'; /* Don't try to parse shebang line */
3829 #endif /* ALTERNATE_SHEBANG */
3830 #ifndef MACOS_TRADITIONAL
3835 !instr(s,"indir") &&
3836 instr(PL_origargv[0],"perl"))
3843 while (s < PL_bufend && isSPACE(*s))
3845 if (s < PL_bufend) {
3846 Newxz(newargv,PL_origargc+3,char*);
3848 while (s < PL_bufend && !isSPACE(*s))
3851 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3854 newargv = PL_origargv;
3857 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3859 Perl_croak(aTHX_ "Can't exec %s", ipath);
3863 while (*d && !isSPACE(*d))
3865 while (SPACE_OR_TAB(*d))
3869 const bool switches_done = PL_doswitches;
3870 const U32 oldpdb = PL_perldb;
3871 const bool oldn = PL_minus_n;
3872 const bool oldp = PL_minus_p;
3875 if (*d == 'M' || *d == 'm' || *d == 'C') {
3876 const char * const m = d;
3877 while (*d && !isSPACE(*d))
3879 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3882 d = moreswitches(d);
3884 if (PL_doswitches && !switches_done) {
3885 int argc = PL_origargc;
3886 char **argv = PL_origargv;
3889 } while (argc && argv[0][0] == '-' && argv[0][1]);
3890 init_argv_symbols(argc,argv);
3892 if ((PERLDB_LINE && !oldpdb) ||
3893 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3894 /* if we have already added "LINE: while (<>) {",
3895 we must not do it again */
3897 sv_setpvn(PL_linestr, "", 0);
3898 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3899 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3900 PL_last_lop = PL_last_uni = NULL;
3901 PL_preambled = FALSE;
3903 (void)gv_fetchfile(PL_origfilename);
3910 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3912 PL_lex_state = LEX_FORMLINE;
3917 #ifdef PERL_STRICT_CR
3918 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3920 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3922 case ' ': case '\t': case '\f': case 013:
3923 #ifdef MACOS_TRADITIONAL
3927 PL_realtokenstart = -1;
3929 PL_thiswhite = newSVpvs("");
3930 sv_catpvn(PL_thiswhite, s, 1);
3937 PL_realtokenstart = -1;
3941 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3942 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3943 /* handle eval qq[#line 1 "foo"\n ...] */
3944 CopLINE_dec(PL_curcop);
3947 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3949 if (!PL_in_eval || PL_rsfp)
3954 while (d < PL_bufend && *d != '\n')
3958 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3959 Perl_croak(aTHX_ "panic: input overflow");
3962 PL_thiswhite = newSVpvn(s, d - s);
3967 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3969 PL_lex_state = LEX_FORMLINE;
3975 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3976 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3979 TOKEN(PEG); /* make sure any #! line is accessible */
3984 /* if (PL_madskills && PL_lex_formbrack) { */
3986 while (d < PL_bufend && *d != '\n')
3990 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3991 Perl_croak(aTHX_ "panic: input overflow");
3992 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3994 PL_thiswhite = newSVpvs("");
3995 if (CopLINE(PL_curcop) == 1) {
3996 sv_setpvn(PL_thiswhite, "", 0);
3999 sv_catpvn(PL_thiswhite, s, d - s);
4013 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
4021 while (s < PL_bufend && SPACE_OR_TAB(*s))
4024 if (strnEQ(s,"=>",2)) {
4025 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
4026 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
4027 OPERATOR('-'); /* unary minus */
4029 PL_last_uni = PL_oldbufptr;
4031 case 'r': ftst = OP_FTEREAD; break;
4032 case 'w': ftst = OP_FTEWRITE; break;
4033 case 'x': ftst = OP_FTEEXEC; break;
4034 case 'o': ftst = OP_FTEOWNED; break;
4035 case 'R': ftst = OP_FTRREAD; break;
4036 case 'W': ftst = OP_FTRWRITE; break;
4037 case 'X': ftst = OP_FTREXEC; break;
4038 case 'O': ftst = OP_FTROWNED; break;
4039 case 'e': ftst = OP_FTIS; break;
4040 case 'z': ftst = OP_FTZERO; break;
4041 case 's': ftst = OP_FTSIZE; break;
4042 case 'f': ftst = OP_FTFILE; break;
4043 case 'd': ftst = OP_FTDIR; break;
4044 case 'l': ftst = OP_FTLINK; break;
4045 case 'p': ftst = OP_FTPIPE; break;
4046 case 'S': ftst = OP_FTSOCK; break;
4047 case 'u': ftst = OP_FTSUID; break;
4048 case 'g': ftst = OP_FTSGID; break;
4049 case 'k': ftst = OP_FTSVTX; break;
4050 case 'b': ftst = OP_FTBLK; break;
4051 case 'c': ftst = OP_FTCHR; break;
4052 case 't': ftst = OP_FTTTY; break;
4053 case 'T': ftst = OP_FTTEXT; break;
4054 case 'B': ftst = OP_FTBINARY; break;
4055 case 'M': case 'A': case 'C':
4056 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
4058 case 'M': ftst = OP_FTMTIME; break;
4059 case 'A': ftst = OP_FTATIME; break;
4060 case 'C': ftst = OP_FTCTIME; break;
4068 PL_last_lop_op = (OPCODE)ftst;
4069 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4070 "### Saw file test %c\n", (int)tmp);
4075 /* Assume it was a minus followed by a one-letter named
4076 * subroutine call (or a -bareword), then. */
4077 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4078 "### '-%c' looked like a file test but was not\n",
4085 const char tmp = *s++;
4088 if (PL_expect == XOPERATOR)
4093 else if (*s == '>') {
4096 if (isIDFIRST_lazy_if(s,UTF)) {
4097 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4105 if (PL_expect == XOPERATOR)
4108 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4110 OPERATOR('-'); /* unary minus */
4116 const char tmp = *s++;
4119 if (PL_expect == XOPERATOR)
4124 if (PL_expect == XOPERATOR)
4127 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4134 if (PL_expect != XOPERATOR) {
4135 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4136 PL_expect = XOPERATOR;
4137 force_ident(PL_tokenbuf, '*');
4150 if (PL_expect == XOPERATOR) {
4154 PL_tokenbuf[0] = '%';
4155 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4156 sizeof PL_tokenbuf - 1, FALSE);
4157 if (!PL_tokenbuf[1]) {
4160 PL_pending_ident = '%';
4171 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
4178 const char tmp = *s++;
4184 goto just_a_word_zero_gv;
4187 switch (PL_expect) {
4193 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4195 PL_bufptr = s; /* update in case we back off */
4201 PL_expect = XTERMBLOCK;
4204 stuffstart = s - SvPVX(PL_linestr) - 1;
4208 while (isIDFIRST_lazy_if(s,UTF)) {
4211 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4212 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4213 if (tmp < 0) tmp = -tmp;
4228 sv = newSVpvn(s, len);
4230 d = scan_str(d,TRUE,TRUE);
4232 /* MUST advance bufptr here to avoid bogus
4233 "at end of line" context messages from yyerror().
4235 PL_bufptr = s + len;
4236 yyerror("Unterminated attribute parameter in attribute list");
4240 return REPORT(0); /* EOF indicator */
4244 sv_catsv(sv, PL_lex_stuff);
4245 attrs = append_elem(OP_LIST, attrs,
4246 newSVOP(OP_CONST, 0, sv));
4247 SvREFCNT_dec(PL_lex_stuff);
4248 PL_lex_stuff = NULL;
4251 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4253 if (PL_in_my == KEY_our) {
4255 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4257 /* skip to avoid loading attributes.pm */
4259 deprecate(":unique");
4262 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4265 /* NOTE: any CV attrs applied here need to be part of
4266 the CVf_BUILTIN_ATTRS define in cv.h! */
4267 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4269 CvLVALUE_on(PL_compcv);
4271 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4273 CvLOCKED_on(PL_compcv);
4275 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4277 CvMETHOD_on(PL_compcv);
4279 else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4281 CvASSERTION_on(PL_compcv);
4283 /* After we've set the flags, it could be argued that
4284 we don't need to do the attributes.pm-based setting
4285 process, and shouldn't bother appending recognized
4286 flags. To experiment with that, uncomment the
4287 following "else". (Note that's already been
4288 uncommented. That keeps the above-applied built-in
4289 attributes from being intercepted (and possibly
4290 rejected) by a package's attribute routines, but is
4291 justified by the performance win for the common case
4292 of applying only built-in attributes.) */
4294 attrs = append_elem(OP_LIST, attrs,
4295 newSVOP(OP_CONST, 0,
4299 if (*s == ':' && s[1] != ':')
4302 break; /* require real whitespace or :'s */
4303 /* XXX losing whitespace on sequential attributes here */
4307 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4308 if (*s != ';' && *s != '}' && *s != tmp
4309 && (tmp != '=' || *s != ')')) {
4310 const char q = ((*s == '\'') ? '"' : '\'');
4311 /* If here for an expression, and parsed no attrs, back
4313 if (tmp == '=' && !attrs) {
4317 /* MUST advance bufptr here to avoid bogus "at end of line"
4318 context messages from yyerror().
4321 yyerror( (const char *)
4323 ? Perl_form(aTHX_ "Invalid separator character "
4324 "%c%c%c in attribute list", q, *s, q)
4325 : "Unterminated attribute list" ) );
4333 start_force(PL_curforce);
4334 NEXTVAL_NEXTTOKE.opval = attrs;
4335 CURMAD('_', PL_nextwhite);
4340 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4341 (s - SvPVX(PL_linestr)) - stuffstart);
4349 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4350 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4358 const char tmp = *s++;
4363 const char tmp = *s++;
4371 if (PL_lex_brackets <= 0)
4372 yyerror("Unmatched right square bracket");
4375 if (PL_lex_state == LEX_INTERPNORMAL) {
4376 if (PL_lex_brackets == 0) {
4377 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4378 PL_lex_state = LEX_INTERPEND;
4385 if (PL_lex_brackets > 100) {
4386 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4388 switch (PL_expect) {
4390 if (PL_lex_formbrack) {
4394 if (PL_oldoldbufptr == PL_last_lop)
4395 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4397 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4398 OPERATOR(HASHBRACK);
4400 while (s < PL_bufend && SPACE_OR_TAB(*s))
4403 PL_tokenbuf[0] = '\0';
4404 if (d < PL_bufend && *d == '-') {
4405 PL_tokenbuf[0] = '-';
4407 while (d < PL_bufend && SPACE_OR_TAB(*d))
4410 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4411 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4413 while (d < PL_bufend && SPACE_OR_TAB(*d))
4416 const char minus = (PL_tokenbuf[0] == '-');
4417 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4425 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4430 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4435 if (PL_oldoldbufptr == PL_last_lop)
4436 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4438 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4441 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4443 /* This hack is to get the ${} in the message. */
4445 yyerror("syntax error");
4448 OPERATOR(HASHBRACK);
4450 /* This hack serves to disambiguate a pair of curlies
4451 * as being a block or an anon hash. Normally, expectation
4452 * determines that, but in cases where we're not in a
4453 * position to expect anything in particular (like inside
4454 * eval"") we have to resolve the ambiguity. This code
4455 * covers the case where the first term in the curlies is a
4456 * quoted string. Most other cases need to be explicitly
4457 * disambiguated by prepending a "+" before the opening
4458 * curly in order to force resolution as an anon hash.
4460 * XXX should probably propagate the outer expectation
4461 * into eval"" to rely less on this hack, but that could
4462 * potentially break current behavior of eval"".
4466 if (*s == '\'' || *s == '"' || *s == '`') {
4467 /* common case: get past first string, handling escapes */
4468 for (t++; t < PL_bufend && *t != *s;)
4469 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4473 else if (*s == 'q') {
4476 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4479 /* skip q//-like construct */
4481 char open, close, term;
4484 while (t < PL_bufend && isSPACE(*t))
4486 /* check for q => */
4487 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4488 OPERATOR(HASHBRACK);
4492 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4496 for (t++; t < PL_bufend; t++) {
4497 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4499 else if (*t == open)
4503 for (t++; t < PL_bufend; t++) {
4504 if (*t == '\\' && t+1 < PL_bufend)
4506 else if (*t == close && --brackets <= 0)
4508 else if (*t == open)
4515 /* skip plain q word */
4516 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4519 else if (isALNUM_lazy_if(t,UTF)) {
4521 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4524 while (t < PL_bufend && isSPACE(*t))
4526 /* if comma follows first term, call it an anon hash */
4527 /* XXX it could be a comma expression with loop modifiers */
4528 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4529 || (*t == '=' && t[1] == '>')))
4530 OPERATOR(HASHBRACK);
4531 if (PL_expect == XREF)
4534 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4540 yylval.ival = CopLINE(PL_curcop);
4541 if (isSPACE(*s) || *s == '#')
4542 PL_copline = NOLINE; /* invalidate current command line number */
4547 if (PL_lex_brackets <= 0)
4548 yyerror("Unmatched right curly bracket");
4550 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4551 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4552 PL_lex_formbrack = 0;
4553 if (PL_lex_state == LEX_INTERPNORMAL) {
4554 if (PL_lex_brackets == 0) {
4555 if (PL_expect & XFAKEBRACK) {
4556 PL_expect &= XENUMMASK;
4557 PL_lex_state = LEX_INTERPEND;
4562 PL_thiswhite = newSVpvs("");
4563 sv_catpvn(PL_thiswhite,"}",1);
4566 return yylex(); /* ignore fake brackets */
4568 if (*s == '-' && s[1] == '>')
4569 PL_lex_state = LEX_INTERPENDMAYBE;
4570 else if (*s != '[' && *s != '{')
4571 PL_lex_state = LEX_INTERPEND;
4574 if (PL_expect & XFAKEBRACK) {
4575 PL_expect &= XENUMMASK;
4577 return yylex(); /* ignore fake brackets */
4579 start_force(PL_curforce);
4581 curmad('X', newSVpvn(s-1,1));
4582 CURMAD('_', PL_thiswhite);
4587 PL_thistoken = newSVpvs("");
4595 if (PL_expect == XOPERATOR) {
4596 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4597 && isIDFIRST_lazy_if(s,UTF))
4599 CopLINE_dec(PL_curcop);
4600 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4601 CopLINE_inc(PL_curcop);
4606 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4608 PL_expect = XOPERATOR;
4609 force_ident(PL_tokenbuf, '&');
4613 yylval.ival = (OPpENTERSUB_AMPER<<8);
4625 const char tmp = *s++;
4632 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4633 && strchr("+-*/%.^&|<",tmp))
4634 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4635 "Reversed %c= operator",(int)tmp);
4637 if (PL_expect == XSTATE && isALPHA(tmp) &&
4638 (s == PL_linestart+1 || s[-2] == '\n') )
4640 if (PL_in_eval && !PL_rsfp) {
4645 if (strnEQ(s,"=cut",4)) {
4661 PL_thiswhite = newSVpvs("");
4662 sv_catpvn(PL_thiswhite, PL_linestart,
4663 PL_bufend - PL_linestart);
4667 PL_doextract = TRUE;
4671 if (PL_lex_brackets < PL_lex_formbrack) {
4673 #ifdef PERL_STRICT_CR
4674 while (SPACE_OR_TAB(*t))
4676 while (SPACE_OR_TAB(*t) || *t == '\r')
4679 if (*t == '\n' || *t == '#') {
4690 const char tmp = *s++;
4692 /* was this !=~ where !~ was meant?
4693 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4695 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4696 const char *t = s+1;
4698 while (t < PL_bufend && isSPACE(*t))
4701 if (*t == '/' || *t == '?' ||
4702 ((*t == 'm' || *t == 's' || *t == 'y')
4703 && !isALNUM(t[1])) ||
4704 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4705 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4706 "!=~ should be !~");
4716 if (PL_expect != XOPERATOR) {
4717 if (s[1] != '<' && !strchr(s,'>'))
4720 s = scan_heredoc(s);
4722 s = scan_inputsymbol(s);
4723 TERM(sublex_start());
4729 SHop(OP_LEFT_SHIFT);
4743 const char tmp = *s++;
4745 SHop(OP_RIGHT_SHIFT);
4746 else if (tmp == '=')
4755 if (PL_expect == XOPERATOR) {
4756 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4758 deprecate_old(commaless_variable_list);
4759 return REPORT(','); /* grandfather non-comma-format format */
4763 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4764 PL_tokenbuf[0] = '@';
4765 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4766 sizeof PL_tokenbuf - 1, FALSE);
4767 if (PL_expect == XOPERATOR)
4768 no_op("Array length", s);
4769 if (!PL_tokenbuf[1])
4771 PL_expect = XOPERATOR;
4772 PL_pending_ident = '#';
4776 PL_tokenbuf[0] = '$';
4777 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4778 sizeof PL_tokenbuf - 1, FALSE);
4779 if (PL_expect == XOPERATOR)
4781 if (!PL_tokenbuf[1]) {
4783 yyerror("Final $ should be \\$ or $name");
4787 /* This kludge not intended to be bulletproof. */
4788 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4789 yylval.opval = newSVOP(OP_CONST, 0,
4790 newSViv(CopARYBASE_get(&PL_compiling)));
4791 yylval.opval->op_private = OPpCONST_ARYBASE;
4797 const char tmp = *s;
4798 if (PL_lex_state == LEX_NORMAL)
4801 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4802 && intuit_more(s)) {
4804 PL_tokenbuf[0] = '@';
4805 if (ckWARN(WARN_SYNTAX)) {
4808 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4811 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4812 while (t < PL_bufend && *t != ']')
4814 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4815 "Multidimensional syntax %.*s not supported",
4816 (int)((t - PL_bufptr) + 1), PL_bufptr);
4820 else if (*s == '{') {
4822 PL_tokenbuf[0] = '%';
4823 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4824 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4826 char tmpbuf[sizeof PL_tokenbuf];
4829 } while (isSPACE(*t));
4830 if (isIDFIRST_lazy_if(t,UTF)) {
4832 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4836 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
4837 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4838 "You need to quote \"%s\"",
4845 PL_expect = XOPERATOR;
4846 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4847 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4848 if (!islop || PL_last_lop_op == OP_GREPSTART)
4849 PL_expect = XOPERATOR;
4850 else if (strchr("$@\"'`q", *s))
4851 PL_expect = XTERM; /* e.g. print $fh "foo" */
4852 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4853 PL_expect = XTERM; /* e.g. print $fh &sub */
4854 else if (isIDFIRST_lazy_if(s,UTF)) {
4855 char tmpbuf[sizeof PL_tokenbuf];
4857 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4858 if ((t2 = keyword(tmpbuf, len, 0))) {
4859 /* binary operators exclude handle interpretations */
4871 PL_expect = XTERM; /* e.g. print $fh length() */
4876 PL_expect = XTERM; /* e.g. print $fh subr() */
4879 else if (isDIGIT(*s))
4880 PL_expect = XTERM; /* e.g. print $fh 3 */
4881 else if (*s == '.' && isDIGIT(s[1]))
4882 PL_expect = XTERM; /* e.g. print $fh .3 */
4883 else if ((*s == '?' || *s == '-' || *s == '+')
4884 && !isSPACE(s[1]) && s[1] != '=')
4885 PL_expect = XTERM; /* e.g. print $fh -1 */
4886 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4888 PL_expect = XTERM; /* e.g. print $fh /.../
4889 XXX except DORDOR operator
4891 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4893 PL_expect = XTERM; /* print $fh <<"EOF" */
4896 PL_pending_ident = '$';
4900 if (PL_expect == XOPERATOR)
4902 PL_tokenbuf[0] = '@';
4903 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4904 if (!PL_tokenbuf[1]) {
4907 if (PL_lex_state == LEX_NORMAL)
4909 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4911 PL_tokenbuf[0] = '%';
4913 /* Warn about @ where they meant $. */
4914 if (*s == '[' || *s == '{') {
4915 if (ckWARN(WARN_SYNTAX)) {
4916 const char *t = s + 1;
4917 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4919 if (*t == '}' || *t == ']') {
4921 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4922 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4923 "Scalar value %.*s better written as $%.*s",
4924 (int)(t-PL_bufptr), PL_bufptr,
4925 (int)(t-PL_bufptr-1), PL_bufptr+1);
4930 PL_pending_ident = '@';
4933 case '/': /* may be division, defined-or, or pattern */
4934 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4938 case '?': /* may either be conditional or pattern */
4939 if(PL_expect == XOPERATOR) {
4947 /* A // operator. */
4957 /* Disable warning on "study /blah/" */
4958 if (PL_oldoldbufptr == PL_last_uni
4959 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4960 || memNE(PL_last_uni, "study", 5)
4961 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4964 s = scan_pat(s,OP_MATCH);
4965 TERM(sublex_start());
4969 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4970 #ifdef PERL_STRICT_CR
4973 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4975 && (s == PL_linestart || s[-1] == '\n') )
4977 PL_lex_formbrack = 0;
4981 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4987 yylval.ival = OPf_SPECIAL;
4993 if (PL_expect != XOPERATOR)
4998 case '0': case '1': case '2': case '3': case '4':
4999 case '5': case '6': case '7': case '8': case '9':
5000 s = scan_num(s, &yylval);
5001 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
5002 if (PL_expect == XOPERATOR)
5007 s = scan_str(s,!!PL_madskills,FALSE);
5008 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5009 if (PL_expect == XOPERATOR) {
5010 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5012 deprecate_old(commaless_variable_list);
5013 return REPORT(','); /* grandfather non-comma-format format */
5020 yylval.ival = OP_CONST;
5021 TERM(sublex_start());
5024 s = scan_str(s,!!PL_madskills,FALSE);
5025 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5026 if (PL_expect == XOPERATOR) {
5027 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5029 deprecate_old(commaless_variable_list);
5030 return REPORT(','); /* grandfather non-comma-format format */
5037 yylval.ival = OP_CONST;
5038 /* FIXME. I think that this can be const if char *d is replaced by
5039 more localised variables. */
5040 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
5041 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
5042 yylval.ival = OP_STRINGIFY;
5046 TERM(sublex_start());
5049 s = scan_str(s,!!PL_madskills,FALSE);
5050 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
5051 if (PL_expect == XOPERATOR)
5052 no_op("Backticks",s);
5055 readpipe_override();
5056 TERM(sublex_start());
5060 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
5061 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5063 if (PL_expect == XOPERATOR)
5064 no_op("Backslash",s);
5068 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
5069 char *start = s + 2;
5070 while (isDIGIT(*start) || *start == '_')
5072 if (*start == '.' && isDIGIT(start[1])) {
5073 s = scan_num(s, &yylval);
5076 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
5077 else if (!isALPHA(*start) && (PL_expect == XTERM
5078 || PL_expect == XREF || PL_expect == XSTATE
5079 || PL_expect == XTERMORDORDOR)) {
5080 /* XXX Use gv_fetchpvn rather than stomping on a const string */
5081 const char c = *start;
5084 gv = gv_fetchpv(s, 0, SVt_PVCV);
5087 s = scan_num(s, &yylval);
5094 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5136 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5138 /* Some keywords can be followed by any delimiter, including ':' */
5139 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5140 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5141 (PL_tokenbuf[0] == 'q' &&
5142 strchr("qwxr", PL_tokenbuf[1])))));
5144 /* x::* is just a word, unless x is "CORE" */
5145 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5149 while (d < PL_bufend && isSPACE(*d))
5150 d++; /* no comments skipped here, or s### is misparsed */
5152 /* Is this a label? */
5153 if (!tmp && PL_expect == XSTATE
5154 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5156 yylval.pval = CopLABEL_alloc(PL_tokenbuf);
5161 /* Check for keywords */
5162 tmp = keyword(PL_tokenbuf, len, 0);
5164 /* Is this a word before a => operator? */
5165 if (*d == '=' && d[1] == '>') {
5168 = (OP*)newSVOP(OP_CONST, 0,
5169 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5170 yylval.opval->op_private = OPpCONST_BARE;
5174 if (tmp < 0) { /* second-class keyword? */
5175 GV *ogv = NULL; /* override (winner) */
5176 GV *hgv = NULL; /* hidden (loser) */
5177 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5179 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5182 if (GvIMPORTED_CV(gv))
5184 else if (! CvMETHOD(cv))
5188 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5189 (gv = *gvp) && isGV_with_GP(gv) &&
5190 GvCVu(gv) && GvIMPORTED_CV(gv))
5197 tmp = 0; /* overridden by import or by GLOBAL */
5200 && -tmp==KEY_lock /* XXX generalizable kludge */
5203 tmp = 0; /* any sub overrides "weak" keyword */
5205 else { /* no override */
5207 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5208 Perl_warner(aTHX_ packWARN(WARN_MISC),
5209 "dump() better written as CORE::dump()");
5213 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5214 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5215 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5216 "Ambiguous call resolved as CORE::%s(), %s",
5217 GvENAME(hgv), "qualify as such or use &");
5224 default: /* not a keyword */
5225 /* Trade off - by using this evil construction we can pull the
5226 variable gv into the block labelled keylookup. If not, then
5227 we have to give it function scope so that the goto from the
5228 earlier ':' case doesn't bypass the initialisation. */
5230 just_a_word_zero_gv:
5238 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5241 SV *nextPL_nextwhite = 0;
5245 /* Get the rest if it looks like a package qualifier */
5247 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5249 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5252 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5253 *s == '\'' ? "'" : "::");
5258 if (PL_expect == XOPERATOR) {
5259 if (PL_bufptr == PL_linestart) {
5260 CopLINE_dec(PL_curcop);
5261 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5262 CopLINE_inc(PL_curcop);
5265 no_op("Bareword",s);
5268 /* Look for a subroutine with this name in current package,
5269 unless name is "Foo::", in which case Foo is a bearword
5270 (and a package name). */
5272 if (len > 2 && !PL_madskills &&
5273 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5275 if (ckWARN(WARN_BAREWORD)
5276 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5277 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5278 "Bareword \"%s\" refers to nonexistent package",
5281 PL_tokenbuf[len] = '\0';
5287 /* Mustn't actually add anything to a symbol table.
5288 But also don't want to "initialise" any placeholder
5289 constants that might already be there into full
5290 blown PVGVs with attached PVCV. */
5291 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5292 GV_NOADD_NOINIT, SVt_PVCV);
5297 /* if we saw a global override before, get the right name */
5300 sv = newSVpvs("CORE::GLOBAL::");
5301 sv_catpv(sv,PL_tokenbuf);
5304 /* If len is 0, newSVpv does strlen(), which is correct.
5305 If len is non-zero, then it will be the true length,
5306 and so the scalar will be created correctly. */
5307 sv = newSVpv(PL_tokenbuf,len);
5310 if (PL_madskills && !PL_thistoken) {
5311 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5312 PL_thistoken = newSVpv(start,s - start);
5313 PL_realtokenstart = s - SvPVX(PL_linestr);
5317 /* Presume this is going to be a bareword of some sort. */
5320 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5321 yylval.opval->op_private = OPpCONST_BARE;
5322 /* UTF-8 package name? */
5323 if (UTF && !IN_BYTES &&
5324 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5327 /* And if "Foo::", then that's what it certainly is. */
5332 /* Do the explicit type check so that we don't need to force
5333 the initialisation of the symbol table to have a real GV.
5334 Beware - gv may not really be a PVGV, cv may not really be
5335 a PVCV, (because of the space optimisations that gv_init
5336 understands) But they're true if for this symbol there is
5337 respectively a typeglob and a subroutine.
5339 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5340 /* Real typeglob, so get the real subroutine: */
5342 /* A proxy for a subroutine in this package? */
5343 : SvOK(gv) ? (CV *) gv : NULL)
5346 /* See if it's the indirect object for a list operator. */
5348 if (PL_oldoldbufptr &&
5349 PL_oldoldbufptr < PL_bufptr &&
5350 (PL_oldoldbufptr == PL_last_lop
5351 || PL_oldoldbufptr == PL_last_uni) &&
5352 /* NO SKIPSPACE BEFORE HERE! */
5353 (PL_expect == XREF ||
5354 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5356 bool immediate_paren = *s == '(';
5358 /* (Now we can afford to cross potential line boundary.) */
5359 s = SKIPSPACE2(s,nextPL_nextwhite);
5361 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5364 /* Two barewords in a row may indicate method call. */
5366 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5367 (tmp = intuit_method(s, gv, cv)))
5370 /* If not a declared subroutine, it's an indirect object. */
5371 /* (But it's an indir obj regardless for sort.) */
5372 /* Also, if "_" follows a filetest operator, it's a bareword */
5375 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5377 (PL_last_lop_op != OP_MAPSTART &&
5378 PL_last_lop_op != OP_GREPSTART))))
5379 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5380 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5383 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5388 PL_expect = XOPERATOR;
5391 s = SKIPSPACE2(s,nextPL_nextwhite);
5392 PL_nextwhite = nextPL_nextwhite;
5397 /* Is this a word before a => operator? */
5398 if (*s == '=' && s[1] == '>' && !pkgname) {
5400 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5401 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5402 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5406 /* If followed by a paren, it's certainly a subroutine. */
5411 while (SPACE_OR_TAB(*d))
5413 if (*d == ')' && (sv = gv_const_sv(gv))) {
5417 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5418 sv_catpvn(PL_thistoken, par, s - par);
5420 sv_free(PL_nextwhite);
5431 PL_nextwhite = PL_thiswhite;
5434 start_force(PL_curforce);
5436 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5437 PL_expect = XOPERATOR;
5440 PL_nextwhite = nextPL_nextwhite;
5441 curmad('X', PL_thistoken);
5442 PL_thistoken = newSVpvs("");
5450 /* If followed by var or block, call it a method (unless sub) */
5452 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5453 PL_last_lop = PL_oldbufptr;
5454 PL_last_lop_op = OP_METHOD;
5458 /* If followed by a bareword, see if it looks like indir obj. */
5461 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5462 && (tmp = intuit_method(s, gv, cv)))
5465 /* Not a method, so call it a subroutine (if defined) */
5468 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5469 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5470 "Ambiguous use of -%s resolved as -&%s()",
5471 PL_tokenbuf, PL_tokenbuf);
5472 /* Check for a constant sub */
5473 if ((sv = gv_const_sv(gv)) && !PL_madskills) {
5475 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5476 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5477 yylval.opval->op_private = 0;
5481 /* Resolve to GV now. */
5482 if (SvTYPE(gv) != SVt_PVGV) {
5483 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5484 assert (SvTYPE(gv) == SVt_PVGV);
5485 /* cv must have been some sort of placeholder, so
5486 now needs replacing with a real code reference. */
5490 op_free(yylval.opval);
5491 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5492 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5493 PL_last_lop = PL_oldbufptr;
5494 PL_last_lop_op = OP_ENTERSUB;
5495 /* Is there a prototype? */
5503 const char *proto = SvPV_const((SV*)cv, protolen);
5506 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
5508 while (*proto == ';')
5510 if (*proto == '&' && *s == '{') {
5511 sv_setpv(PL_subname,
5514 "__ANON__" : "__ANON__::__ANON__"));
5521 PL_nextwhite = PL_thiswhite;
5524 start_force(PL_curforce);
5525 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5528 PL_nextwhite = nextPL_nextwhite;
5529 curmad('X', PL_thistoken);
5530 PL_thistoken = newSVpvs("");
5537 /* Guess harder when madskills require "best effort". */
5538 if (PL_madskills && (!gv || !GvCVu(gv))) {
5539 int probable_sub = 0;
5540 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5542 else if (isALPHA(*s)) {
5546 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5547 if (!keyword(tmpbuf, tmplen, 0))
5550 while (d < PL_bufend && isSPACE(*d))
5552 if (*d == '=' && d[1] == '>')
5557 gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
5558 op_free(yylval.opval);
5559 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5560 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5561 PL_last_lop = PL_oldbufptr;
5562 PL_last_lop_op = OP_ENTERSUB;
5563 PL_nextwhite = PL_thiswhite;
5565 start_force(PL_curforce);
5566 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5568 PL_nextwhite = nextPL_nextwhite;
5569 curmad('X', PL_thistoken);
5570 PL_thistoken = newSVpvs("");
5575 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5582 /* Call it a bare word */
5584 if (PL_hints & HINT_STRICT_SUBS)
5585 yylval.opval->op_private |= OPpCONST_STRICT;
5588 if (lastchar != '-') {
5589 if (ckWARN(WARN_RESERVED)) {
5593 if (!*d && !gv_stashpv(PL_tokenbuf, 0))
5594 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5601 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5602 && ckWARN_d(WARN_AMBIGUOUS)) {
5603 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5604 "Operator or semicolon missing before %c%s",
5605 lastchar, PL_tokenbuf);
5606 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5607 "Ambiguous use of %c resolved as operator %c",
5608 lastchar, lastchar);
5614 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5615 newSVpv(CopFILE(PL_curcop),0));
5619 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5620 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5623 case KEY___PACKAGE__:
5624 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5626 ? newSVhek(HvNAME_HEK(PL_curstash))
5633 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5634 const char *pname = "main";
5635 if (PL_tokenbuf[2] == 'D')
5636 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5637 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5641 GvIOp(gv) = newIO();
5642 IoIFP(GvIOp(gv)) = PL_rsfp;
5643 #if defined(HAS_FCNTL) && defined(F_SETFD)
5645 const int fd = PerlIO_fileno(PL_rsfp);
5646 fcntl(fd,F_SETFD,fd >= 3);
5649 /* Mark this internal pseudo-handle as clean */
5650 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5652 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5653 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5654 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5656 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5657 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5658 /* if the script was opened in binmode, we need to revert
5659 * it to text mode for compatibility; but only iff it has CRs
5660 * XXX this is a questionable hack at best. */
5661 if (PL_bufend-PL_bufptr > 2
5662 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5665 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5666 loc = PerlIO_tell(PL_rsfp);
5667 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5670 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5672 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5673 #endif /* NETWARE */
5674 #ifdef PERLIO_IS_STDIO /* really? */
5675 # if defined(__BORLANDC__)
5676 /* XXX see note in do_binmode() */
5677 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5681 PerlIO_seek(PL_rsfp, loc, 0);
5685 #ifdef PERLIO_LAYERS
5688 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5689 else if (PL_encoding) {
5696 XPUSHs(PL_encoding);
5698 call_method("name", G_SCALAR);
5702 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5703 Perl_form(aTHX_ ":encoding(%"SVf")",
5712 if (PL_realtokenstart >= 0) {
5713 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5715 PL_endwhite = newSVpvs("");
5716 sv_catsv(PL_endwhite, PL_thiswhite);
5718 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5719 PL_realtokenstart = -1;
5721 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5722 SvCUR(PL_endwhite))) != Nullch) ;
5737 if (PL_expect == XSTATE) {
5744 if (*s == ':' && s[1] == ':') {
5747 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5748 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5749 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5752 else if (tmp == KEY_require || tmp == KEY_do)
5753 /* that's a way to remember we saw "CORE::" */
5766 LOP(OP_ACCEPT,XTERM);
5772 LOP(OP_ATAN2,XTERM);
5778 LOP(OP_BINMODE,XTERM);
5781 LOP(OP_BLESS,XTERM);
5790 /* When 'use switch' is in effect, continue has a dual
5791 life as a control operator. */
5793 if (!FEATURE_IS_ENABLED("switch"))
5796 /* We have to disambiguate the two senses of
5797 "continue". If the next token is a '{' then
5798 treat it as the start of a continue block;
5799 otherwise treat it as a control operator.
5811 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5828 if (!PL_cryptseen) {
5829 PL_cryptseen = TRUE;
5833 LOP(OP_CRYPT,XTERM);
5836 LOP(OP_CHMOD,XTERM);
5839 LOP(OP_CHOWN,XTERM);
5842 LOP(OP_CONNECT,XTERM);
5861 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5862 if (orig_keyword == KEY_do) {
5871 PL_hints |= HINT_BLOCK_SCOPE;
5881 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5882 LOP(OP_DBMOPEN,XTERM);
5888 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5895 yylval.ival = CopLINE(PL_curcop);
5911 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5912 UNIBRACK(OP_ENTEREVAL);
5930 case KEY_endhostent:
5936 case KEY_endservent:
5939 case KEY_endprotoent:
5950 yylval.ival = CopLINE(PL_curcop);
5952 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5955 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5958 if ((PL_bufend - p) >= 3 &&
5959 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5961 else if ((PL_bufend - p) >= 4 &&
5962 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5965 if (isIDFIRST_lazy_if(p,UTF)) {
5966 p = scan_ident(p, PL_bufend,
5967 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5971 Perl_croak(aTHX_ "Missing $ on loop variable");
5973 s = SvPVX(PL_linestr) + soff;
5979 LOP(OP_FORMLINE,XTERM);
5985 LOP(OP_FCNTL,XTERM);
5991 LOP(OP_FLOCK,XTERM);
6000 LOP(OP_GREPSTART, XREF);
6003 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6018 case KEY_getpriority:
6019 LOP(OP_GETPRIORITY,XTERM);
6021 case KEY_getprotobyname:
6024 case KEY_getprotobynumber:
6025 LOP(OP_GPBYNUMBER,XTERM);
6027 case KEY_getprotoent:
6039 case KEY_getpeername:
6040 UNI(OP_GETPEERNAME);
6042 case KEY_gethostbyname:
6045 case KEY_gethostbyaddr:
6046 LOP(OP_GHBYADDR,XTERM);
6048 case KEY_gethostent:
6051 case KEY_getnetbyname:
6054 case KEY_getnetbyaddr:
6055 LOP(OP_GNBYADDR,XTERM);
6060 case KEY_getservbyname:
6061 LOP(OP_GSBYNAME,XTERM);
6063 case KEY_getservbyport:
6064 LOP(OP_GSBYPORT,XTERM);
6066 case KEY_getservent:
6069 case KEY_getsockname:
6070 UNI(OP_GETSOCKNAME);
6072 case KEY_getsockopt:
6073 LOP(OP_GSOCKOPT,XTERM);
6088 yylval.ival = CopLINE(PL_curcop);
6099 yylval.ival = CopLINE(PL_curcop);
6103 LOP(OP_INDEX,XTERM);
6109 LOP(OP_IOCTL,XTERM);
6121 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6153 LOP(OP_LISTEN,XTERM);
6162 s = scan_pat(s,OP_MATCH);
6163 TERM(sublex_start());
6166 LOP(OP_MAPSTART, XREF);
6169 LOP(OP_MKDIR,XTERM);
6172 LOP(OP_MSGCTL,XTERM);
6175 LOP(OP_MSGGET,XTERM);
6178 LOP(OP_MSGRCV,XTERM);
6181 LOP(OP_MSGSND,XTERM);
6186 PL_in_my = (U16)tmp;
6188 if (isIDFIRST_lazy_if(s,UTF)) {
6192 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6193 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6195 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6196 if (!PL_in_my_stash) {
6199 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6203 if (PL_madskills) { /* just add type to declarator token */
6204 sv_catsv(PL_thistoken, PL_nextwhite);
6206 sv_catpvn(PL_thistoken, start, s - start);
6214 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6221 s = tokenize_use(0, s);
6225 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6232 if (isIDFIRST_lazy_if(s,UTF)) {
6234 for (d = s; isALNUM_lazy_if(d,UTF);)
6236 for (t=d; isSPACE(*t);)
6238 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6240 && !(t[0] == '=' && t[1] == '>')
6242 int parms_len = (int)(d-s);
6243 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6244 "Precedence problem: open %.*s should be open(%.*s)",
6245 parms_len, s, parms_len, s);
6251 yylval.ival = OP_OR;
6261 LOP(OP_OPEN_DIR,XTERM);
6264 checkcomma(s,PL_tokenbuf,"filehandle");
6268 checkcomma(s,PL_tokenbuf,"filehandle");
6287 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6291 LOP(OP_PIPE_OP,XTERM);
6294 s = scan_str(s,!!PL_madskills,FALSE);
6297 yylval.ival = OP_CONST;
6298 TERM(sublex_start());
6304 s = scan_str(s,!!PL_madskills,FALSE);
6307 PL_expect = XOPERATOR;
6309 if (SvCUR(PL_lex_stuff)) {
6312 d = SvPV_force(PL_lex_stuff, len);
6314 for (; isSPACE(*d) && len; --len, ++d)
6319 if (!warned && ckWARN(WARN_QW)) {
6320 for (; !isSPACE(*d) && len; --len, ++d) {
6322 Perl_warner(aTHX_ packWARN(WARN_QW),
6323 "Possible attempt to separate words with commas");
6326 else if (*d == '#') {
6327 Perl_warner(aTHX_ packWARN(WARN_QW),
6328 "Possible attempt to put comments in qw() list");
6334 for (; !isSPACE(*d) && len; --len, ++d)
6337 sv = newSVpvn(b, d-b);
6338 if (DO_UTF8(PL_lex_stuff))
6340 words = append_elem(OP_LIST, words,
6341 newSVOP(OP_CONST, 0, tokeq(sv)));
6345 start_force(PL_curforce);
6346 NEXTVAL_NEXTTOKE.opval = words;
6351 SvREFCNT_dec(PL_lex_stuff);
6352 PL_lex_stuff = NULL;
6358 s = scan_str(s,!!PL_madskills,FALSE);
6361 yylval.ival = OP_STRINGIFY;
6362 if (SvIVX(PL_lex_stuff) == '\'')
6363 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6364 TERM(sublex_start());
6367 s = scan_pat(s,OP_QR);
6368 TERM(sublex_start());
6371 s = scan_str(s,!!PL_madskills,FALSE);
6374 readpipe_override();
6375 TERM(sublex_start());
6383 s = force_version(s, FALSE);
6385 else if (*s != 'v' || !isDIGIT(s[1])
6386 || (s = force_version(s, TRUE), *s == 'v'))
6388 *PL_tokenbuf = '\0';
6389 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6390 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6391 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
6393 yyerror("<> should be quotes");
6395 if (orig_keyword == KEY_require) {
6403 PL_last_uni = PL_oldbufptr;
6404 PL_last_lop_op = OP_REQUIRE;
6406 return REPORT( (int)REQUIRE );
6412 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6416 LOP(OP_RENAME,XTERM);
6425 LOP(OP_RINDEX,XTERM);
6435 UNIDOR(OP_READLINE);
6439 UNIDOR(OP_BACKTICK);
6448 LOP(OP_REVERSE,XTERM);
6451 UNIDOR(OP_READLINK);
6459 TERM(sublex_start());
6461 TOKEN(1); /* force error */
6464 checkcomma(s,PL_tokenbuf,"filehandle");
6474 LOP(OP_SELECT,XTERM);
6480 LOP(OP_SEMCTL,XTERM);
6483 LOP(OP_SEMGET,XTERM);
6486 LOP(OP_SEMOP,XTERM);
6492 LOP(OP_SETPGRP,XTERM);
6494 case KEY_setpriority:
6495 LOP(OP_SETPRIORITY,XTERM);
6497 case KEY_sethostent:
6503 case KEY_setservent:
6506 case KEY_setprotoent:
6516 LOP(OP_SEEKDIR,XTERM);
6518 case KEY_setsockopt:
6519 LOP(OP_SSOCKOPT,XTERM);
6525 LOP(OP_SHMCTL,XTERM);
6528 LOP(OP_SHMGET,XTERM);
6531 LOP(OP_SHMREAD,XTERM);
6534 LOP(OP_SHMWRITE,XTERM);
6537 LOP(OP_SHUTDOWN,XTERM);
6546 LOP(OP_SOCKET,XTERM);
6548 case KEY_socketpair:
6549 LOP(OP_SOCKPAIR,XTERM);
6552 checkcomma(s,PL_tokenbuf,"subroutine name");
6554 if (*s == ';' || *s == ')') /* probably a close */
6555 Perl_croak(aTHX_ "sort is now a reserved word");
6557 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6561 LOP(OP_SPLIT,XTERM);
6564 LOP(OP_SPRINTF,XTERM);
6567 LOP(OP_SPLICE,XTERM);
6582 LOP(OP_SUBSTR,XTERM);
6588 char tmpbuf[sizeof PL_tokenbuf];
6589 SSize_t tboffset = 0;
6590 expectation attrful;
6591 bool have_name, have_proto;
6592 const int key = tmp;
6597 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6598 SV *subtoken = newSVpvn(tstart, s - tstart);
6602 s = SKIPSPACE2(s,tmpwhite);
6607 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6608 (*s == ':' && s[1] == ':'))
6615 attrful = XATTRBLOCK;
6616 /* remember buffer pos'n for later force_word */
6617 tboffset = s - PL_oldbufptr;
6618 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6621 nametoke = newSVpvn(s, d - s);
6623 if (memchr(tmpbuf, ':', len))
6624 sv_setpvn(PL_subname, tmpbuf, len);
6626 sv_setsv(PL_subname,PL_curstname);
6627 sv_catpvs(PL_subname,"::");
6628 sv_catpvn(PL_subname,tmpbuf,len);
6635 CURMAD('X', nametoke);
6636 CURMAD('_', tmpwhite);
6637 (void) force_word(PL_oldbufptr + tboffset, WORD,
6640 s = SKIPSPACE2(d,tmpwhite);
6647 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6648 PL_expect = XTERMBLOCK;
6649 attrful = XATTRTERM;
6650 sv_setpvn(PL_subname,"?",1);
6654 if (key == KEY_format) {
6656 PL_lex_formbrack = PL_lex_brackets + 1;
6658 PL_thistoken = subtoken;
6662 (void) force_word(PL_oldbufptr + tboffset, WORD,
6668 /* Look for a prototype */
6671 bool bad_proto = FALSE;
6672 const bool warnsyntax = ckWARN(WARN_SYNTAX);
6674 s = scan_str(s,!!PL_madskills,FALSE);
6676 Perl_croak(aTHX_ "Prototype not terminated");
6677 /* strip spaces and check for bad characters */
6678 d = SvPVX(PL_lex_stuff);
6680 for (p = d; *p; ++p) {
6683 if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
6689 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6690 "Illegal character in prototype for %"SVf" : %s",
6691 SVfARG(PL_subname), d);
6692 SvCUR_set(PL_lex_stuff, tmp);
6697 CURMAD('q', PL_thisopen);
6698 CURMAD('_', tmpwhite);
6699 CURMAD('=', PL_thisstuff);
6700 CURMAD('Q', PL_thisclose);
6701 NEXTVAL_NEXTTOKE.opval =
6702 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6703 PL_lex_stuff = Nullsv;
6706 s = SKIPSPACE2(s,tmpwhite);
6714 if (*s == ':' && s[1] != ':')
6715 PL_expect = attrful;
6716 else if (*s != '{' && key == KEY_sub) {
6718 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6720 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
6727 curmad('^', newSVpvs(""));
6728 CURMAD('_', tmpwhite);
6732 PL_thistoken = subtoken;
6735 NEXTVAL_NEXTTOKE.opval =
6736 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6737 PL_lex_stuff = NULL;
6742 sv_setpv(PL_subname,
6744 (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
6748 (void) force_word(PL_oldbufptr + tboffset, WORD,
6758 LOP(OP_SYSTEM,XREF);
6761 LOP(OP_SYMLINK,XTERM);
6764 LOP(OP_SYSCALL,XTERM);
6767 LOP(OP_SYSOPEN,XTERM);
6770 LOP(OP_SYSSEEK,XTERM);
6773 LOP(OP_SYSREAD,XTERM);
6776 LOP(OP_SYSWRITE,XTERM);
6780 TERM(sublex_start());
6801 LOP(OP_TRUNCATE,XTERM);
6813 yylval.ival = CopLINE(PL_curcop);
6817 yylval.ival = CopLINE(PL_curcop);
6821 LOP(OP_UNLINK,XTERM);
6827 LOP(OP_UNPACK,XTERM);
6830 LOP(OP_UTIME,XTERM);
6836 LOP(OP_UNSHIFT,XTERM);
6839 s = tokenize_use(1, s);
6849 yylval.ival = CopLINE(PL_curcop);
6853 yylval.ival = CopLINE(PL_curcop);
6857 PL_hints |= HINT_BLOCK_SCOPE;
6864 LOP(OP_WAITPID,XTERM);
6873 ctl_l[0] = toCTRL('L');
6875 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6878 /* Make sure $^L is defined */
6879 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6884 if (PL_expect == XOPERATOR)
6890 yylval.ival = OP_XOR;
6895 TERM(sublex_start());
6900 #pragma segment Main
6904 S_pending_ident(pTHX)
6909 /* pit holds the identifier we read and pending_ident is reset */
6910 char pit = PL_pending_ident;
6911 PL_pending_ident = 0;
6913 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6914 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6915 "### Pending identifier '%s'\n", PL_tokenbuf); });
6917 /* if we're in a my(), we can't allow dynamics here.
6918 $foo'bar has already been turned into $foo::bar, so
6919 just check for colons.
6921 if it's a legal name, the OP is a PADANY.
6924 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6925 if (strchr(PL_tokenbuf,':'))
6926 yyerror(Perl_form(aTHX_ "No package name allowed for "
6927 "variable %s in \"our\"",
6929 tmp = allocmy(PL_tokenbuf);
6932 if (strchr(PL_tokenbuf,':'))
6933 yyerror(Perl_form(aTHX_ PL_no_myglob,
6934 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6936 yylval.opval = newOP(OP_PADANY, 0);
6937 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6943 build the ops for accesses to a my() variable.
6945 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6946 then used in a comparison. This catches most, but not
6947 all cases. For instance, it catches
6948 sort { my($a); $a <=> $b }
6950 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6951 (although why you'd do that is anyone's guess).
6954 if (!strchr(PL_tokenbuf,':')) {
6956 tmp = pad_findmy(PL_tokenbuf);
6957 if (tmp != NOT_IN_PAD) {
6958 /* might be an "our" variable" */
6959 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6960 /* build ops for a bareword */
6961 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6962 HEK * const stashname = HvNAME_HEK(stash);
6963 SV * const sym = newSVhek(stashname);
6964 sv_catpvs(sym, "::");
6965 sv_catpv(sym, PL_tokenbuf+1);
6966 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6967 yylval.opval->op_private = OPpCONST_ENTERED;
6970 ? (GV_ADDMULTI | GV_ADDINEVAL)
6973 ((PL_tokenbuf[0] == '$') ? SVt_PV
6974 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6979 /* if it's a sort block and they're naming $a or $b */
6980 if (PL_last_lop_op == OP_SORT &&
6981 PL_tokenbuf[0] == '$' &&
6982 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6985 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6986 d < PL_bufend && *d != '\n';
6989 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6990 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6996 yylval.opval = newOP(OP_PADANY, 0);
6997 yylval.opval->op_targ = tmp;
7003 Whine if they've said @foo in a doublequoted string,
7004 and @foo isn't a variable we can find in the symbol
7007 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
7008 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
7009 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
7010 && ckWARN(WARN_AMBIGUOUS)
7011 /* DO NOT warn for @- and @+ */
7012 && !( PL_tokenbuf[2] == '\0' &&
7013 ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
7016 /* Downgraded from fatal to warning 20000522 mjd */
7017 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
7018 "Possible unintended interpolation of %s in string",
7023 /* build ops for a bareword */
7024 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
7025 yylval.opval->op_private = OPpCONST_ENTERED;
7028 /* If the identifier refers to a stash, don't autovivify it.
7029 * Change 24660 had the side effect of causing symbol table
7030 * hashes to always be defined, even if they were freshly
7031 * created and the only reference in the entire program was
7032 * the single statement with the defined %foo::bar:: test.
7033 * It appears that all code in the wild doing this actually
7034 * wants to know whether sub-packages have been loaded, so
7035 * by avoiding auto-vivifying symbol tables, we ensure that
7036 * defined %foo::bar:: continues to be false, and the existing
7037 * tests still give the expected answers, even though what
7038 * they're actually testing has now changed subtly.
7040 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
7042 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
7043 ((PL_tokenbuf[0] == '$') ? SVt_PV
7044 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7050 * The following code was generated by perl_keyword.pl.
7054 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
7059 case 1: /* 5 tokens of length 1 */
7091 case 2: /* 18 tokens of length 2 */
7237 case 3: /* 29 tokens of length 3 */
7241 if (name[1] == 'N' &&
7304 if (name[1] == 'i' &&
7326 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7344 if (name[1] == 'o' &&
7353 if (name[1] == 'e' &&
7362 if (name[1] == 'n' &&
7371 if (name[1] == 'o' &&
7380 if (name[1] == 'a' &&
7389 if (name[1] == 'o' &&
7451 if (name[1] == 'e' &&
7465 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
7491 if (name[1] == 'i' &&
7500 if (name[1] == 's' &&
7509 if (name[1] == 'e' &&
7518 if (name[1] == 'o' &&
7530 case 4: /* 41 tokens of length 4 */
7534 if (name[1] == 'O' &&
7544 if (name[1] == 'N' &&
7554 if (name[1] == 'i' &&
7564 if (name[1] == 'h' &&
7574 if (name[1] == 'u' &&
7587 if (name[2] == 'c' &&
7596 if (name[2] == 's' &&
7605 if (name[2] == 'a' &&
7641 if (name[1] == 'o' &&
7654 if (name[2] == 't' &&
7663 if (name[2] == 'o' &&
7672 if (name[2] == 't' &&
7681 if (name[2] == 'e' &&
7694 if (name[1] == 'o' &&
7707 if (name[2] == 'y' &&
7716 if (name[2] == 'l' &&
7732 if (name[2] == 's' &&
7741 if (name[2] == 'n' &&
7750 if (name[2] == 'c' &&
7763 if (name[1] == 'e' &&
7773 if (name[1] == 'p' &&
7786 if (name[2] == 'c' &&
7795 if (name[2] == 'p' &&
7804 if (name[2] == 's' &&
7820 if (name[2] == 'n' &&
7890 if (name[2] == 'r' &&
7899 if (name[2] == 'r' &&
7908 if (name[2] == 'a' &&
7924 if (name[2] == 'l' &&
7986 if (name[2] == 'e' &&
7989 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
8002 case 5: /* 39 tokens of length 5 */
8006 if (name[1] == 'E' &&
8017 if (name[1] == 'H' &&
8031 if (name[2] == 'a' &&
8041 if (name[2] == 'a' &&
8058 if (name[2] == 'e' &&
8068 if (name[2] == 'e' &&
8072 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
8088 if (name[3] == 'i' &&
8097 if (name[3] == 'o' &&
8133 if (name[2] == 'o' &&
8143 if (name[2] == 'y' &&
8157 if (name[1] == 'l' &&
8171 if (name[2] == 'n' &&
8181 if (name[2] == 'o' &&
8195 if (name[1] == 'i' &&
8200 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8209 if (name[2] == 'd' &&
8219 if (name[2] == 'c' &&
8236 if (name[2] == 'c' &&
8246 if (name[2] == 't' &&
8260 if (name[1] == 'k' &&
8271 if (name[1] == 'r' &&
8285 if (name[2] == 's' &&
8295 if (name[2] == 'd' &&
8312 if (name[2] == 'm' &&
8322 if (name[2] == 'i' &&
8332 if (name[2] == 'e' &&
8342 if (name[2] == 'l' &&
8352 if (name[2] == 'a' &&
8365 if (name[3] == 't' &&
8368 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8374 if (name[3] == 'd' &&
8391 if (name[1] == 'i' &&
8405 if (name[2] == 'a' &&
8418 if (name[3] == 'e' &&
8453 if (name[2] == 'i' &&
8470 if (name[2] == 'i' &&
8480 if (name[2] == 'i' &&
8497 case 6: /* 33 tokens of length 6 */
8501 if (name[1] == 'c' &&
8516 if (name[2] == 'l' &&
8527 if (name[2] == 'r' &&
8542 if (name[1] == 'e' &&
8557 if (name[2] == 's' &&
8562 if(ckWARN_d(WARN_SYNTAX))
8563 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8569 if (name[2] == 'i' &&
8587 if (name[2] == 'l' &&
8598 if (name[2] == 'r' &&
8613 if (name[1] == 'm' &&
8628 if (name[2] == 'n' &&
8639 if (name[2] == 's' &&
8654 if (name[1] == 's' &&
8660 if (name[4] == 't' &&
8669 if (name[4] == 'e' &&
8678 if (name[4] == 'c' &&
8687 if (name[4] == 'n' &&
8703 if (name[1] == 'r' &&
8721 if (name[3] == 'a' &&
8731 if (name[3] == 'u' &&
8745 if (name[2] == 'n' &&
8763 if (name[2] == 'a' &&
8777 if (name[3] == 'e' &&
8790 if (name[4] == 't' &&
8799 if (name[4] == 'e' &&
8821 if (name[4] == 't' &&
8830 if (name[4] == 'e' &&
8846 if (name[2] == 'c' &&
8857 if (name[2] == 'l' &&
8868 if (name[2] == 'b' &&
8879 if (name[2] == 's' &&
8902 if (name[4] == 's' &&
8911 if (name[4] == 'n' &&
8924 if (name[3] == 'a' &&
8941 if (name[1] == 'a' &&
8956 case 7: /* 29 tokens of length 7 */
8960 if (name[1] == 'E' &&
8973 if (name[1] == '_' &&
8986 if (name[1] == 'i' &&
8993 return -KEY_binmode;
8999 if (name[1] == 'o' &&
9006 return -KEY_connect;
9015 if (name[2] == 'm' &&
9021 return -KEY_dbmopen;
9032 if (name[4] == 'u' &&
9036 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
9042 if (name[4] == 'n' &&
9063 if (name[1] == 'o' &&
9076 if (name[1] == 'e' &&
9083 if (name[5] == 'r' &&
9086 return -KEY_getpgrp;
9092 if (name[5] == 'i' &&
9095 return -KEY_getppid;
9108 if (name[1] == 'c' &&
9115 return -KEY_lcfirst;
9121 if (name[1] == 'p' &&
9128 return -KEY_opendir;
9134 if (name[1] == 'a' &&
9152 if (name[3] == 'd' &&
9157 return -KEY_readdir;
9163 if (name[3] == 'u' &&
9174 if (name[3] == 'e' &&
9179 return -KEY_reverse;
9198 if (name[3] == 'k' &&
9203 return -KEY_seekdir;
9209 if (name[3] == 'p' &&
9214 return -KEY_setpgrp;
9224 if (name[2] == 'm' &&
9230 return -KEY_shmread;
9236 if (name[2] == 'r' &&
9242 return -KEY_sprintf;
9251 if (name[3] == 'l' &&
9256 return -KEY_symlink;
9265 if (name[4] == 'a' &&
9269 return -KEY_syscall;
9275 if (name[4] == 'p' &&
9279 return -KEY_sysopen;
9285 if (name[4] == 'e' &&
9289 return -KEY_sysread;
9295 if (name[4] == 'e' &&
9299 return -KEY_sysseek;
9317 if (name[1] == 'e' &&
9324 return -KEY_telldir;
9333 if (name[2] == 'f' &&
9339 return -KEY_ucfirst;
9345 if (name[2] == 's' &&
9351 return -KEY_unshift;
9361 if (name[1] == 'a' &&
9368 return -KEY_waitpid;
9377 case 8: /* 26 tokens of length 8 */
9381 if (name[1] == 'U' &&
9389 return KEY_AUTOLOAD;
9400 if (name[3] == 'A' &&
9406 return KEY___DATA__;
9412 if (name[3] == 'I' &&
9418 return -KEY___FILE__;
9424 if (name[3] == 'I' &&
9430 return -KEY___LINE__;
9446 if (name[2] == 'o' &&
9453 return -KEY_closedir;
9459 if (name[2] == 'n' &&
9466 return -KEY_continue;
9476 if (name[1] == 'b' &&
9484 return -KEY_dbmclose;
9490 if (name[1] == 'n' &&
9496 if (name[4] == 'r' &&
9501 return -KEY_endgrent;
9507 if (name[4] == 'w' &&
9512 return -KEY_endpwent;
9525 if (name[1] == 'o' &&
9533 return -KEY_formline;
9539 if (name[1] == 'e' &&
9550 if (name[6] == 'n' &&
9553 return -KEY_getgrent;
9559 if (name[6] == 'i' &&
9562 return -KEY_getgrgid;
9568 if (name[6] == 'a' &&
9571 return -KEY_getgrnam;
9584 if (name[4] == 'o' &&
9589 return -KEY_getlogin;
9600 if (name[6] == 'n' &&
9603 return -KEY_getpwent;
9609 if (name[6] == 'a' &&
9612 return -KEY_getpwnam;
9618 if (name[6] == 'i' &&
9621 return -KEY_getpwuid;
9641 if (name[1] == 'e' &&
9648 if (name[5] == 'i' &&
9655 return -KEY_readline;
9660 return -KEY_readlink;
9671 if (name[5] == 'i' &&
9675 return -KEY_readpipe;
9696 if (name[4] == 'r' &&
9701 return -KEY_setgrent;
9707 if (name[4] == 'w' &&
9712 return -KEY_setpwent;
9728 if (name[3] == 'w' &&
9734 return -KEY_shmwrite;
9740 if (name[3] == 't' &&
9746 return -KEY_shutdown;
9756 if (name[2] == 's' &&
9763 return -KEY_syswrite;
9773 if (name[1] == 'r' &&
9781 return -KEY_truncate;
9790 case 9: /* 9 tokens of length 9 */
9794 if (name[1] == 'N' &&
9803 return KEY_UNITCHECK;
9809 if (name[1] == 'n' &&
9818 return -KEY_endnetent;
9824 if (name[1] == 'e' &&
9833 return -KEY_getnetent;
9839 if (name[1] == 'o' &&
9848 return -KEY_localtime;
9854 if (name[1] == 'r' &&
9863 return KEY_prototype;
9869 if (name[1] == 'u' &&
9878 return -KEY_quotemeta;
9884 if (name[1] == 'e' &&
9893 return -KEY_rewinddir;
9899 if (name[1] == 'e' &&
9908 return -KEY_setnetent;
9914 if (name[1] == 'a' &&
9923 return -KEY_wantarray;
9932 case 10: /* 9 tokens of length 10 */
9936 if (name[1] == 'n' &&
9942 if (name[4] == 'o' &&
9949 return -KEY_endhostent;
9955 if (name[4] == 'e' &&
9962 return -KEY_endservent;
9975 if (name[1] == 'e' &&
9981 if (name[4] == 'o' &&
9988 return -KEY_gethostent;
9997 if (name[5] == 'r' &&
10003 return -KEY_getservent;
10009 if (name[5] == 'c' &&
10015 return -KEY_getsockopt;
10035 if (name[2] == 't')
10040 if (name[4] == 'o' &&
10047 return -KEY_sethostent;
10056 if (name[5] == 'r' &&
10062 return -KEY_setservent;
10068 if (name[5] == 'c' &&
10074 return -KEY_setsockopt;
10091 if (name[2] == 'c' &&
10100 return -KEY_socketpair;
10113 case 11: /* 8 tokens of length 11 */
10117 if (name[1] == '_' &&
10127 { /* __PACKAGE__ */
10128 return -KEY___PACKAGE__;
10134 if (name[1] == 'n' &&
10144 { /* endprotoent */
10145 return -KEY_endprotoent;
10151 if (name[1] == 'e' &&
10160 if (name[5] == 'e' &&
10166 { /* getpeername */
10167 return -KEY_getpeername;
10176 if (name[6] == 'o' &&
10181 { /* getpriority */
10182 return -KEY_getpriority;
10188 if (name[6] == 't' &&
10193 { /* getprotoent */
10194 return -KEY_getprotoent;
10208 if (name[4] == 'o' &&
10215 { /* getsockname */
10216 return -KEY_getsockname;
10229 if (name[1] == 'e' &&
10237 if (name[6] == 'o' &&
10242 { /* setpriority */
10243 return -KEY_setpriority;
10249 if (name[6] == 't' &&
10254 { /* setprotoent */
10255 return -KEY_setprotoent;
10271 case 12: /* 2 tokens of length 12 */
10272 if (name[0] == 'g' &&
10284 if (name[9] == 'd' &&
10287 { /* getnetbyaddr */
10288 return -KEY_getnetbyaddr;
10294 if (name[9] == 'a' &&
10297 { /* getnetbyname */
10298 return -KEY_getnetbyname;
10310 case 13: /* 4 tokens of length 13 */
10311 if (name[0] == 'g' &&
10318 if (name[4] == 'o' &&
10327 if (name[10] == 'd' &&
10330 { /* gethostbyaddr */
10331 return -KEY_gethostbyaddr;
10337 if (name[10] == 'a' &&
10340 { /* gethostbyname */
10341 return -KEY_gethostbyname;
10354 if (name[4] == 'e' &&
10363 if (name[10] == 'a' &&
10366 { /* getservbyname */
10367 return -KEY_getservbyname;
10373 if (name[10] == 'o' &&
10376 { /* getservbyport */
10377 return -KEY_getservbyport;
10396 case 14: /* 1 tokens of length 14 */
10397 if (name[0] == 'g' &&
10411 { /* getprotobyname */
10412 return -KEY_getprotobyname;
10417 case 16: /* 1 tokens of length 16 */
10418 if (name[0] == 'g' &&
10434 { /* getprotobynumber */
10435 return -KEY_getprotobynumber;
10449 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10453 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10454 if (ckWARN(WARN_SYNTAX)) {
10457 for (w = s+2; *w && level; w++) {
10460 else if (*w == ')')
10463 while (isSPACE(*w))
10465 /* the list of chars below is for end of statements or
10466 * block / parens, boolean operators (&&, ||, //) and branch
10467 * constructs (or, and, if, until, unless, while, err, for).
10468 * Not a very solid hack... */
10469 if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
10470 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10471 "%s (...) interpreted as function",name);
10474 while (s < PL_bufend && isSPACE(*s))
10478 while (s < PL_bufend && isSPACE(*s))
10480 if (isIDFIRST_lazy_if(s,UTF)) {
10481 const char * const w = s++;
10482 while (isALNUM_lazy_if(s,UTF))
10484 while (s < PL_bufend && isSPACE(*s))
10488 if (keyword(w, s - w, 0))
10491 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10492 if (gv && GvCVu(gv))
10494 Perl_croak(aTHX_ "No comma allowed after %s", what);
10499 /* Either returns sv, or mortalizes sv and returns a new SV*.
10500 Best used as sv=new_constant(..., sv, ...).
10501 If s, pv are NULL, calls subroutine with one argument,
10502 and type is used with error messages only. */
10505 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10509 HV * const table = GvHV(PL_hintgv); /* ^H */
10513 const char *why1 = "", *why2 = "", *why3 = "";
10515 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10518 why2 = (const char *)
10519 (strEQ(key,"charnames")
10520 ? "(possibly a missing \"use charnames ...\")"
10522 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10523 (type ? type: "undef"), why2);
10525 /* This is convoluted and evil ("goto considered harmful")
10526 * but I do not understand the intricacies of all the different
10527 * failure modes of %^H in here. The goal here is to make
10528 * the most probable error message user-friendly. --jhi */
10533 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10534 (type ? type: "undef"), why1, why2, why3);
10536 yyerror(SvPVX_const(msg));
10540 cvp = hv_fetch(table, key, strlen(key), FALSE);
10541 if (!cvp || !SvOK(*cvp)) {
10544 why3 = "} is not defined";
10547 sv_2mortal(sv); /* Parent created it permanently */
10550 pv = sv_2mortal(newSVpvn(s, len));
10552 typesv = sv_2mortal(newSVpv(type, 0));
10554 typesv = &PL_sv_undef;
10556 PUSHSTACKi(PERLSI_OVERLOAD);
10568 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10572 /* Check the eval first */
10573 if (!PL_in_eval && SvTRUE(ERRSV)) {
10574 sv_catpvs(ERRSV, "Propagated");
10575 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10577 res = SvREFCNT_inc_simple(sv);
10581 SvREFCNT_inc_simple_void(res);
10590 why1 = "Call to &{$^H{";
10592 why3 = "}} did not return a defined value";
10600 /* Returns a NUL terminated string, with the length of the string written to
10604 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10607 register char *d = dest;
10608 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10611 Perl_croak(aTHX_ ident_too_long);
10612 if (isALNUM(*s)) /* UTF handled below */
10614 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10619 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10623 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10624 char *t = s + UTF8SKIP(s);
10626 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10630 Perl_croak(aTHX_ ident_too_long);
10631 Copy(s, d, len, char);
10644 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10647 char *bracket = NULL;
10649 register char *d = dest;
10650 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10655 while (isDIGIT(*s)) {
10657 Perl_croak(aTHX_ ident_too_long);
10664 Perl_croak(aTHX_ ident_too_long);
10665 if (isALNUM(*s)) /* UTF handled below */
10667 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10672 else if (*s == ':' && s[1] == ':') {
10676 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10677 char *t = s + UTF8SKIP(s);
10678 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10680 if (d + (t - s) > e)
10681 Perl_croak(aTHX_ ident_too_long);
10682 Copy(s, d, t - s, char);
10693 if (PL_lex_state != LEX_NORMAL)
10694 PL_lex_state = LEX_INTERPENDMAYBE;
10697 if (*s == '$' && s[1] &&
10698 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10711 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10716 if (isSPACE(s[-1])) {
10718 const char ch = *s++;
10719 if (!SPACE_OR_TAB(ch)) {
10725 if (isIDFIRST_lazy_if(d,UTF)) {
10729 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10730 end += UTF8SKIP(end);
10731 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10732 end += UTF8SKIP(end);
10734 Copy(s, d, end - s, char);
10739 while ((isALNUM(*s) || *s == ':') && d < e)
10742 Perl_croak(aTHX_ ident_too_long);
10745 while (s < send && SPACE_OR_TAB(*s))
10747 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10748 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10749 const char * const brack =
10751 ((*s == '[') ? "[...]" : "{...}");
10752 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10753 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10754 funny, dest, brack, funny, dest, brack);
10757 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10761 /* Handle extended ${^Foo} variables
10762 * 1999-02-27 mjd-perl-patch@plover.com */
10763 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10767 while (isALNUM(*s) && d < e) {
10771 Perl_croak(aTHX_ ident_too_long);
10776 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10777 PL_lex_state = LEX_INTERPEND;
10780 if (PL_lex_state == LEX_NORMAL) {
10781 if (ckWARN(WARN_AMBIGUOUS) &&
10782 (keyword(dest, d - dest, 0)
10783 || get_cvn_flags(dest, d - dest, 0)))
10787 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10788 "Ambiguous use of %c{%s} resolved to %c%s",
10789 funny, dest, funny, dest);
10794 s = bracket; /* let the parser handle it */
10798 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10799 PL_lex_state = LEX_INTERPEND;
10804 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10806 PERL_UNUSED_CONTEXT;
10810 CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
10811 case GLOBAL_PAT_MOD: *pmfl |= PMf_GLOBAL; break;
10812 case CONTINUE_PAT_MOD: *pmfl |= PMf_CONTINUE; break;
10813 case ONCE_PAT_MOD: *pmfl |= PMf_KEEP; break;
10814 case KEEPCOPY_PAT_MOD: *pmfl |= PMf_KEEPCOPY; break;
10820 S_scan_pat(pTHX_ char *start, I32 type)
10824 char *s = scan_str(start,!!PL_madskills,FALSE);
10825 const char * const valid_flags =
10826 (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
10833 const char * const delimiter = skipspace(start);
10837 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10838 : "Search pattern not terminated" ));
10841 pm = (PMOP*)newPMOP(type, 0);
10842 if (PL_multi_open == '?') {
10843 /* This is the only point in the code that sets PMf_ONCE: */
10844 pm->op_pmflags |= PMf_ONCE;
10846 /* Hence it's safe to do this bit of PMOP book-keeping here, which
10847 allows us to restrict the list needed by reset to just the ??
10849 assert(type != OP_TRANS);
10851 MAGIC *mg = mg_find((SV*)PL_curstash, PERL_MAGIC_symtab);
10854 mg = sv_magicext((SV*)PL_curstash, 0, PERL_MAGIC_symtab, 0, 0,
10857 elements = mg->mg_len / sizeof(PMOP**);
10858 Renewc(mg->mg_ptr, elements + 1, PMOP*, char);
10859 ((PMOP**)mg->mg_ptr) [elements++] = pm;
10860 mg->mg_len = elements * sizeof(PMOP**);
10861 PmopSTASH_set(pm,PL_curstash);
10867 while (*s && strchr(valid_flags, *s))
10868 pmflag(&pm->op_pmflags,*s++);
10870 if (PL_madskills && modstart != s) {
10871 SV* tmptoken = newSVpvn(modstart, s - modstart);
10872 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10875 /* issue a warning if /c is specified,but /g is not */
10876 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10877 && ckWARN(WARN_REGEXP))
10879 Perl_warner(aTHX_ packWARN(WARN_REGEXP),
10880 "Use of /c modifier is meaningless without /g" );
10883 PL_lex_op = (OP*)pm;
10884 yylval.ival = OP_MATCH;
10889 S_scan_subst(pTHX_ char *start)
10900 yylval.ival = OP_NULL;
10902 s = scan_str(start,!!PL_madskills,FALSE);
10905 Perl_croak(aTHX_ "Substitution pattern not terminated");
10907 if (s[-1] == PL_multi_open)
10910 if (PL_madskills) {
10911 CURMAD('q', PL_thisopen);
10912 CURMAD('_', PL_thiswhite);
10913 CURMAD('E', PL_thisstuff);
10914 CURMAD('Q', PL_thisclose);
10915 PL_realtokenstart = s - SvPVX(PL_linestr);
10919 first_start = PL_multi_start;
10920 s = scan_str(s,!!PL_madskills,FALSE);
10922 if (PL_lex_stuff) {
10923 SvREFCNT_dec(PL_lex_stuff);
10924 PL_lex_stuff = NULL;
10926 Perl_croak(aTHX_ "Substitution replacement not terminated");
10928 PL_multi_start = first_start; /* so whole substitution is taken together */
10930 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10933 if (PL_madskills) {
10934 CURMAD('z', PL_thisopen);
10935 CURMAD('R', PL_thisstuff);
10936 CURMAD('Z', PL_thisclose);
10942 if (*s == EXEC_PAT_MOD) {
10946 else if (strchr(S_PAT_MODS, *s))
10947 pmflag(&pm->op_pmflags,*s++);
10953 if (PL_madskills) {
10955 curmad('m', newSVpvn(modstart, s - modstart));
10956 append_madprops(PL_thismad, (OP*)pm, 0);
10960 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10961 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10965 SV * const repl = newSVpvs("");
10967 PL_sublex_info.super_bufptr = s;
10968 PL_sublex_info.super_bufend = PL_bufend;
10970 pm->op_pmflags |= PMf_EVAL;
10972 sv_catpv(repl, (const char *)(es ? "eval " : "do "));
10973 sv_catpvs(repl, "{");
10974 sv_catsv(repl, PL_lex_repl);
10975 if (strchr(SvPVX(PL_lex_repl), '#'))
10976 sv_catpvs(repl, "\n");
10977 sv_catpvs(repl, "}");
10979 SvREFCNT_dec(PL_lex_repl);
10980 PL_lex_repl = repl;
10983 PL_lex_op = (OP*)pm;
10984 yylval.ival = OP_SUBST;
10989 S_scan_trans(pTHX_ char *start)
11002 yylval.ival = OP_NULL;
11004 s = scan_str(start,!!PL_madskills,FALSE);
11006 Perl_croak(aTHX_ "Transliteration pattern not terminated");
11008 if (s[-1] == PL_multi_open)
11011 if (PL_madskills) {
11012 CURMAD('q', PL_thisopen);
11013 CURMAD('_', PL_thiswhite);
11014 CURMAD('E', PL_thisstuff);
11015 CURMAD('Q', PL_thisclose);
11016 PL_realtokenstart = s - SvPVX(PL_linestr);
11020 s = scan_str(s,!!PL_madskills,FALSE);
11022 if (PL_lex_stuff) {
11023 SvREFCNT_dec(PL_lex_stuff);
11024 PL_lex_stuff = NULL;
11026 Perl_croak(aTHX_ "Transliteration replacement not terminated");
11028 if (PL_madskills) {
11029 CURMAD('z', PL_thisopen);
11030 CURMAD('R', PL_thisstuff);
11031 CURMAD('Z', PL_thisclose);
11034 complement = del = squash = 0;
11041 complement = OPpTRANS_COMPLEMENT;
11044 del = OPpTRANS_DELETE;
11047 squash = OPpTRANS_SQUASH;
11056 tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
11057 o = newPVOP(OP_TRANS, 0, (char*)tbl);
11058 o->op_private &= ~OPpTRANS_ALL;
11059 o->op_private |= del|squash|complement|
11060 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
11061 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
11064 yylval.ival = OP_TRANS;
11067 if (PL_madskills) {
11069 curmad('m', newSVpvn(modstart, s - modstart));
11070 append_madprops(PL_thismad, o, 0);
11079 S_scan_heredoc(pTHX_ register char *s)
11083 I32 op_type = OP_SCALAR;
11087 const char *found_newline;
11091 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
11093 I32 stuffstart = s - SvPVX(PL_linestr);
11096 PL_realtokenstart = -1;
11101 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
11105 while (SPACE_OR_TAB(*peek))
11107 if (*peek == '`' || *peek == '\'' || *peek =='"') {
11110 s = delimcpy(d, e, s, PL_bufend, term, &len);
11120 if (!isALNUM_lazy_if(s,UTF))
11121 deprecate_old("bare << to mean <<\"\"");
11122 for (; isALNUM_lazy_if(s,UTF); s++) {
11127 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
11128 Perl_croak(aTHX_ "Delimiter for here document is too long");
11131 len = d - PL_tokenbuf;
11134 if (PL_madskills) {
11135 tstart = PL_tokenbuf + !outer;
11136 PL_thisclose = newSVpvn(tstart, len - !outer);
11137 tstart = SvPVX(PL_linestr) + stuffstart;
11138 PL_thisopen = newSVpvn(tstart, s - tstart);
11139 stuffstart = s - SvPVX(PL_linestr);
11142 #ifndef PERL_STRICT_CR
11143 d = strchr(s, '\r');
11145 char * const olds = s;
11147 while (s < PL_bufend) {
11153 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11162 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11169 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11170 herewas = newSVpvn(s,PL_bufend-s);
11174 herewas = newSVpvn(s-1,found_newline-s+1);
11177 herewas = newSVpvn(s,found_newline-s);
11181 if (PL_madskills) {
11182 tstart = SvPVX(PL_linestr) + stuffstart;
11184 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11186 PL_thisstuff = newSVpvn(tstart, s - tstart);
11189 s += SvCUR(herewas);
11192 stuffstart = s - SvPVX(PL_linestr);
11198 tmpstr = newSV_type(SVt_PVIV);
11199 SvGROW(tmpstr, 80);
11200 if (term == '\'') {
11201 op_type = OP_CONST;
11202 SvIV_set(tmpstr, -1);
11204 else if (term == '`') {
11205 op_type = OP_BACKTICK;
11206 SvIV_set(tmpstr, '\\');
11210 PL_multi_start = CopLINE(PL_curcop);
11211 PL_multi_open = PL_multi_close = '<';
11212 term = *PL_tokenbuf;
11213 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11214 char * const bufptr = PL_sublex_info.super_bufptr;
11215 char * const bufend = PL_sublex_info.super_bufend;
11216 char * const olds = s - SvCUR(herewas);
11217 s = strchr(bufptr, '\n');
11221 while (s < bufend &&
11222 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11224 CopLINE_inc(PL_curcop);
11227 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11228 missingterm(PL_tokenbuf);
11230 sv_setpvn(herewas,bufptr,d-bufptr+1);
11231 sv_setpvn(tmpstr,d+1,s-d);
11233 sv_catpvn(herewas,s,bufend-s);
11234 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11241 while (s < PL_bufend &&
11242 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11244 CopLINE_inc(PL_curcop);
11246 if (s >= PL_bufend) {
11247 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11248 missingterm(PL_tokenbuf);
11250 sv_setpvn(tmpstr,d+1,s-d);
11252 if (PL_madskills) {
11254 sv_catpvn(PL_thisstuff, d + 1, s - d);
11256 PL_thisstuff = newSVpvn(d + 1, s - d);
11257 stuffstart = s - SvPVX(PL_linestr);
11261 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11263 sv_catpvn(herewas,s,PL_bufend-s);
11264 sv_setsv(PL_linestr,herewas);
11265 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11266 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11267 PL_last_lop = PL_last_uni = NULL;
11270 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
11271 while (s >= PL_bufend) { /* multiple line string? */
11273 if (PL_madskills) {
11274 tstart = SvPVX(PL_linestr) + stuffstart;
11276 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11278 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11282 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11283 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11284 missingterm(PL_tokenbuf);
11287 stuffstart = s - SvPVX(PL_linestr);
11289 CopLINE_inc(PL_curcop);
11290 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11291 PL_last_lop = PL_last_uni = NULL;
11292 #ifndef PERL_STRICT_CR
11293 if (PL_bufend - PL_linestart >= 2) {
11294 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11295 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11297 PL_bufend[-2] = '\n';
11299 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11301 else if (PL_bufend[-1] == '\r')
11302 PL_bufend[-1] = '\n';
11304 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11305 PL_bufend[-1] = '\n';
11307 if (PERLDB_LINE && PL_curstash != PL_debstash)
11308 update_debugger_info(PL_linestr, NULL, 0);
11309 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11310 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11311 *(SvPVX(PL_linestr) + off ) = ' ';
11312 sv_catsv(PL_linestr,herewas);
11313 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11314 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11318 sv_catsv(tmpstr,PL_linestr);
11323 PL_multi_end = CopLINE(PL_curcop);
11324 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11325 SvPV_shrink_to_cur(tmpstr);
11327 SvREFCNT_dec(herewas);
11329 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11331 else if (PL_encoding)
11332 sv_recode_to_utf8(tmpstr, PL_encoding);
11334 PL_lex_stuff = tmpstr;
11335 yylval.ival = op_type;
11339 /* scan_inputsymbol
11340 takes: current position in input buffer
11341 returns: new position in input buffer
11342 side-effects: yylval and lex_op are set.
11347 <FH> read from filehandle
11348 <pkg::FH> read from package qualified filehandle
11349 <pkg'FH> read from package qualified filehandle
11350 <$fh> read from filehandle in $fh
11351 <*.h> filename glob
11356 S_scan_inputsymbol(pTHX_ char *start)
11359 register char *s = start; /* current position in buffer */
11363 char *d = PL_tokenbuf; /* start of temp holding space */
11364 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11366 end = strchr(s, '\n');
11369 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11371 /* die if we didn't have space for the contents of the <>,
11372 or if it didn't end, or if we see a newline
11375 if (len >= (I32)sizeof PL_tokenbuf)
11376 Perl_croak(aTHX_ "Excessively long <> operator");
11378 Perl_croak(aTHX_ "Unterminated <> operator");
11383 Remember, only scalar variables are interpreted as filehandles by
11384 this code. Anything more complex (e.g., <$fh{$num}>) will be
11385 treated as a glob() call.
11386 This code makes use of the fact that except for the $ at the front,
11387 a scalar variable and a filehandle look the same.
11389 if (*d == '$' && d[1]) d++;
11391 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11392 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11395 /* If we've tried to read what we allow filehandles to look like, and
11396 there's still text left, then it must be a glob() and not a getline.
11397 Use scan_str to pull out the stuff between the <> and treat it
11398 as nothing more than a string.
11401 if (d - PL_tokenbuf != len) {
11402 yylval.ival = OP_GLOB;
11404 s = scan_str(start,!!PL_madskills,FALSE);
11406 Perl_croak(aTHX_ "Glob not terminated");
11410 bool readline_overriden = FALSE;
11413 /* we're in a filehandle read situation */
11416 /* turn <> into <ARGV> */
11418 Copy("ARGV",d,5,char);
11420 /* Check whether readline() is overriden */
11421 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11423 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11425 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11426 && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
11427 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11428 readline_overriden = TRUE;
11430 /* if <$fh>, create the ops to turn the variable into a
11434 /* try to find it in the pad for this block, otherwise find
11435 add symbol table ops
11437 const PADOFFSET tmp = pad_findmy(d);
11438 if (tmp != NOT_IN_PAD) {
11439 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11440 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11441 HEK * const stashname = HvNAME_HEK(stash);
11442 SV * const sym = sv_2mortal(newSVhek(stashname));
11443 sv_catpvs(sym, "::");
11444 sv_catpv(sym, d+1);
11449 OP * const o = newOP(OP_PADSV, 0);
11451 PL_lex_op = readline_overriden
11452 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11453 append_elem(OP_LIST, o,
11454 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11455 : (OP*)newUNOP(OP_READLINE, 0, o);
11464 ? (GV_ADDMULTI | GV_ADDINEVAL)
11467 PL_lex_op = readline_overriden
11468 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11469 append_elem(OP_LIST,
11470 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11471 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11472 : (OP*)newUNOP(OP_READLINE, 0,
11473 newUNOP(OP_RV2SV, 0,
11474 newGVOP(OP_GV, 0, gv)));
11476 if (!readline_overriden)
11477 PL_lex_op->op_flags |= OPf_SPECIAL;
11478 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11479 yylval.ival = OP_NULL;
11482 /* If it's none of the above, it must be a literal filehandle
11483 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11485 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11486 PL_lex_op = readline_overriden
11487 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11488 append_elem(OP_LIST,
11489 newGVOP(OP_GV, 0, gv),
11490 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11491 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11492 yylval.ival = OP_NULL;
11501 takes: start position in buffer
11502 keep_quoted preserve \ on the embedded delimiter(s)
11503 keep_delims preserve the delimiters around the string
11504 returns: position to continue reading from buffer
11505 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11506 updates the read buffer.
11508 This subroutine pulls a string out of the input. It is called for:
11509 q single quotes q(literal text)
11510 ' single quotes 'literal text'
11511 qq double quotes qq(interpolate $here please)
11512 " double quotes "interpolate $here please"
11513 qx backticks qx(/bin/ls -l)
11514 ` backticks `/bin/ls -l`
11515 qw quote words @EXPORT_OK = qw( func() $spam )
11516 m// regexp match m/this/
11517 s/// regexp substitute s/this/that/
11518 tr/// string transliterate tr/this/that/
11519 y/// string transliterate y/this/that/
11520 ($*@) sub prototypes sub foo ($)
11521 (stuff) sub attr parameters sub foo : attr(stuff)
11522 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11524 In most of these cases (all but <>, patterns and transliterate)
11525 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11526 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11527 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11530 It skips whitespace before the string starts, and treats the first
11531 character as the delimiter. If the delimiter is one of ([{< then
11532 the corresponding "close" character )]}> is used as the closing
11533 delimiter. It allows quoting of delimiters, and if the string has
11534 balanced delimiters ([{<>}]) it allows nesting.
11536 On success, the SV with the resulting string is put into lex_stuff or,
11537 if that is already non-NULL, into lex_repl. The second case occurs only
11538 when parsing the RHS of the special constructs s/// and tr/// (y///).
11539 For convenience, the terminating delimiter character is stuffed into
11544 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11547 SV *sv; /* scalar value: string */
11548 const char *tmps; /* temp string, used for delimiter matching */
11549 register char *s = start; /* current position in the buffer */
11550 register char term; /* terminating character */
11551 register char *to; /* current position in the sv's data */
11552 I32 brackets = 1; /* bracket nesting level */
11553 bool has_utf8 = FALSE; /* is there any utf8 content? */
11554 I32 termcode; /* terminating char. code */
11555 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11556 STRLEN termlen; /* length of terminating string */
11557 int last_off = 0; /* last position for nesting bracket */
11563 /* skip space before the delimiter */
11569 if (PL_realtokenstart >= 0) {
11570 stuffstart = PL_realtokenstart;
11571 PL_realtokenstart = -1;
11574 stuffstart = start - SvPVX(PL_linestr);
11576 /* mark where we are, in case we need to report errors */
11579 /* after skipping whitespace, the next character is the terminator */
11582 termcode = termstr[0] = term;
11586 termcode = utf8_to_uvchr((U8*)s, &termlen);
11587 Copy(s, termstr, termlen, U8);
11588 if (!UTF8_IS_INVARIANT(term))
11592 /* mark where we are */
11593 PL_multi_start = CopLINE(PL_curcop);
11594 PL_multi_open = term;
11596 /* find corresponding closing delimiter */
11597 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11598 termcode = termstr[0] = term = tmps[5];
11600 PL_multi_close = term;
11602 /* create a new SV to hold the contents. 79 is the SV's initial length.
11603 What a random number. */
11604 sv = newSV_type(SVt_PVIV);
11606 SvIV_set(sv, termcode);
11607 (void)SvPOK_only(sv); /* validate pointer */
11609 /* move past delimiter and try to read a complete string */
11611 sv_catpvn(sv, s, termlen);
11614 tstart = SvPVX(PL_linestr) + stuffstart;
11615 if (!PL_thisopen && !keep_delims) {
11616 PL_thisopen = newSVpvn(tstart, s - tstart);
11617 stuffstart = s - SvPVX(PL_linestr);
11621 if (PL_encoding && !UTF) {
11625 int offset = s - SvPVX_const(PL_linestr);
11626 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11627 &offset, (char*)termstr, termlen);
11628 const char * const ns = SvPVX_const(PL_linestr) + offset;
11629 char * const svlast = SvEND(sv) - 1;
11631 for (; s < ns; s++) {
11632 if (*s == '\n' && !PL_rsfp)
11633 CopLINE_inc(PL_curcop);
11636 goto read_more_line;
11638 /* handle quoted delimiters */
11639 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11641 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11643 if ((svlast-1 - t) % 2) {
11644 if (!keep_quoted) {
11645 *(svlast-1) = term;
11647 SvCUR_set(sv, SvCUR(sv) - 1);
11652 if (PL_multi_open == PL_multi_close) {
11658 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
11659 /* At here, all closes are "was quoted" one,
11660 so we don't check PL_multi_close. */
11662 if (!keep_quoted && *(t+1) == PL_multi_open)
11667 else if (*t == PL_multi_open)
11675 SvCUR_set(sv, w - SvPVX_const(sv));
11677 last_off = w - SvPVX(sv);
11678 if (--brackets <= 0)
11683 if (!keep_delims) {
11684 SvCUR_set(sv, SvCUR(sv) - 1);
11690 /* extend sv if need be */
11691 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11692 /* set 'to' to the next character in the sv's string */
11693 to = SvPVX(sv)+SvCUR(sv);
11695 /* if open delimiter is the close delimiter read unbridle */
11696 if (PL_multi_open == PL_multi_close) {
11697 for (; s < PL_bufend; s++,to++) {
11698 /* embedded newlines increment the current line number */
11699 if (*s == '\n' && !PL_rsfp)
11700 CopLINE_inc(PL_curcop);
11701 /* handle quoted delimiters */
11702 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11703 if (!keep_quoted && s[1] == term)
11705 /* any other quotes are simply copied straight through */
11709 /* terminate when run out of buffer (the for() condition), or
11710 have found the terminator */
11711 else if (*s == term) {
11714 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11717 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11723 /* if the terminator isn't the same as the start character (e.g.,
11724 matched brackets), we have to allow more in the quoting, and
11725 be prepared for nested brackets.
11728 /* read until we run out of string, or we find the terminator */
11729 for (; s < PL_bufend; s++,to++) {
11730 /* embedded newlines increment the line count */
11731 if (*s == '\n' && !PL_rsfp)
11732 CopLINE_inc(PL_curcop);
11733 /* backslashes can escape the open or closing characters */
11734 if (*s == '\\' && s+1 < PL_bufend) {
11735 if (!keep_quoted &&
11736 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11741 /* allow nested opens and closes */
11742 else if (*s == PL_multi_close && --brackets <= 0)
11744 else if (*s == PL_multi_open)
11746 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11751 /* terminate the copied string and update the sv's end-of-string */
11753 SvCUR_set(sv, to - SvPVX_const(sv));
11756 * this next chunk reads more into the buffer if we're not done yet
11760 break; /* handle case where we are done yet :-) */
11762 #ifndef PERL_STRICT_CR
11763 if (to - SvPVX_const(sv) >= 2) {
11764 if ((to[-2] == '\r' && to[-1] == '\n') ||
11765 (to[-2] == '\n' && to[-1] == '\r'))
11769 SvCUR_set(sv, to - SvPVX_const(sv));
11771 else if (to[-1] == '\r')
11774 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11779 /* if we're out of file, or a read fails, bail and reset the current
11780 line marker so we can report where the unterminated string began
11783 if (PL_madskills) {
11784 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11786 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11788 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11792 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11794 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11800 /* we read a line, so increment our line counter */
11801 CopLINE_inc(PL_curcop);
11803 /* update debugger info */
11804 if (PERLDB_LINE && PL_curstash != PL_debstash)
11805 update_debugger_info(PL_linestr, NULL, 0);
11807 /* having changed the buffer, we must update PL_bufend */
11808 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11809 PL_last_lop = PL_last_uni = NULL;
11812 /* at this point, we have successfully read the delimited string */
11814 if (!PL_encoding || UTF) {
11816 if (PL_madskills) {
11817 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11818 const int len = s - tstart;
11820 sv_catpvn(PL_thisstuff, tstart, len);
11822 PL_thisstuff = newSVpvn(tstart, len);
11823 if (!PL_thisclose && !keep_delims)
11824 PL_thisclose = newSVpvn(s,termlen);
11829 sv_catpvn(sv, s, termlen);
11834 if (PL_madskills) {
11835 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11836 const int len = s - tstart - termlen;
11838 sv_catpvn(PL_thisstuff, tstart, len);
11840 PL_thisstuff = newSVpvn(tstart, len);
11841 if (!PL_thisclose && !keep_delims)
11842 PL_thisclose = newSVpvn(s - termlen,termlen);
11846 if (has_utf8 || PL_encoding)
11849 PL_multi_end = CopLINE(PL_curcop);
11851 /* if we allocated too much space, give some back */
11852 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11853 SvLEN_set(sv, SvCUR(sv) + 1);
11854 SvPV_renew(sv, SvLEN(sv));
11857 /* decide whether this is the first or second quoted string we've read
11870 takes: pointer to position in buffer
11871 returns: pointer to new position in buffer
11872 side-effects: builds ops for the constant in yylval.op
11874 Read a number in any of the formats that Perl accepts:
11876 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11877 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11880 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11882 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11885 If it reads a number without a decimal point or an exponent, it will
11886 try converting the number to an integer and see if it can do so
11887 without loss of precision.
11891 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11894 register const char *s = start; /* current position in buffer */
11895 register char *d; /* destination in temp buffer */
11896 register char *e; /* end of temp buffer */
11897 NV nv; /* number read, as a double */
11898 SV *sv = NULL; /* place to put the converted number */
11899 bool floatit; /* boolean: int or float? */
11900 const char *lastub = NULL; /* position of last underbar */
11901 static char const number_too_long[] = "Number too long";
11903 /* We use the first character to decide what type of number this is */
11907 Perl_croak(aTHX_ "panic: scan_num");
11909 /* if it starts with a 0, it could be an octal number, a decimal in
11910 0.13 disguise, or a hexadecimal number, or a binary number. */
11914 u holds the "number so far"
11915 shift the power of 2 of the base
11916 (hex == 4, octal == 3, binary == 1)
11917 overflowed was the number more than we can hold?
11919 Shift is used when we add a digit. It also serves as an "are
11920 we in octal/hex/binary?" indicator to disallow hex characters
11921 when in octal mode.
11926 bool overflowed = FALSE;
11927 bool just_zero = TRUE; /* just plain 0 or binary number? */
11928 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11929 static const char* const bases[5] =
11930 { "", "binary", "", "octal", "hexadecimal" };
11931 static const char* const Bases[5] =
11932 { "", "Binary", "", "Octal", "Hexadecimal" };
11933 static const char* const maxima[5] =
11935 "0b11111111111111111111111111111111",
11939 const char *base, *Base, *max;
11941 /* check for hex */
11946 } else if (s[1] == 'b') {
11951 /* check for a decimal in disguise */
11952 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11954 /* so it must be octal */
11961 if (ckWARN(WARN_SYNTAX))
11962 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11963 "Misplaced _ in number");
11967 base = bases[shift];
11968 Base = Bases[shift];
11969 max = maxima[shift];
11971 /* read the rest of the number */
11973 /* x is used in the overflow test,
11974 b is the digit we're adding on. */
11979 /* if we don't mention it, we're done */
11983 /* _ are ignored -- but warned about if consecutive */
11985 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11986 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11987 "Misplaced _ in number");
11991 /* 8 and 9 are not octal */
11992 case '8': case '9':
11994 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11998 case '2': case '3': case '4':
11999 case '5': case '6': case '7':
12001 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
12004 case '0': case '1':
12005 b = *s++ & 15; /* ASCII digit -> value of digit */
12009 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
12010 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
12011 /* make sure they said 0x */
12014 b = (*s++ & 7) + 9;
12016 /* Prepare to put the digit we have onto the end
12017 of the number so far. We check for overflows.
12023 x = u << shift; /* make room for the digit */
12025 if ((x >> shift) != u
12026 && !(PL_hints & HINT_NEW_BINARY)) {
12029 if (ckWARN_d(WARN_OVERFLOW))
12030 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12031 "Integer overflow in %s number",
12034 u = x | b; /* add the digit to the end */
12037 n *= nvshift[shift];
12038 /* If an NV has not enough bits in its
12039 * mantissa to represent an UV this summing of
12040 * small low-order numbers is a waste of time
12041 * (because the NV cannot preserve the
12042 * low-order bits anyway): we could just
12043 * remember when did we overflow and in the
12044 * end just multiply n by the right
12052 /* if we get here, we had success: make a scalar value from
12057 /* final misplaced underbar check */
12058 if (s[-1] == '_') {
12059 if (ckWARN(WARN_SYNTAX))
12060 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12065 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
12066 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12067 "%s number > %s non-portable",
12073 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
12074 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12075 "%s number > %s non-portable",
12080 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
12081 sv = new_constant(start, s - start, "integer",
12083 else if (PL_hints & HINT_NEW_BINARY)
12084 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
12089 handle decimal numbers.
12090 we're also sent here when we read a 0 as the first digit
12092 case '1': case '2': case '3': case '4': case '5':
12093 case '6': case '7': case '8': case '9': case '.':
12096 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
12099 /* read next group of digits and _ and copy into d */
12100 while (isDIGIT(*s) || *s == '_') {
12101 /* skip underscores, checking for misplaced ones
12105 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12106 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12107 "Misplaced _ in number");
12111 /* check for end of fixed-length buffer */
12113 Perl_croak(aTHX_ number_too_long);
12114 /* if we're ok, copy the character */
12119 /* final misplaced underbar check */
12120 if (lastub && s == lastub + 1) {
12121 if (ckWARN(WARN_SYNTAX))
12122 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12125 /* read a decimal portion if there is one. avoid
12126 3..5 being interpreted as the number 3. followed
12129 if (*s == '.' && s[1] != '.') {
12134 if (ckWARN(WARN_SYNTAX))
12135 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12136 "Misplaced _ in number");
12140 /* copy, ignoring underbars, until we run out of digits.
12142 for (; isDIGIT(*s) || *s == '_'; s++) {
12143 /* fixed length buffer check */
12145 Perl_croak(aTHX_ number_too_long);
12147 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12148 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12149 "Misplaced _ in number");
12155 /* fractional part ending in underbar? */
12156 if (s[-1] == '_') {
12157 if (ckWARN(WARN_SYNTAX))
12158 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12159 "Misplaced _ in number");
12161 if (*s == '.' && isDIGIT(s[1])) {
12162 /* oops, it's really a v-string, but without the "v" */
12168 /* read exponent part, if present */
12169 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12173 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12174 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12176 /* stray preinitial _ */
12178 if (ckWARN(WARN_SYNTAX))
12179 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12180 "Misplaced _ in number");
12184 /* allow positive or negative exponent */
12185 if (*s == '+' || *s == '-')
12188 /* stray initial _ */
12190 if (ckWARN(WARN_SYNTAX))
12191 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12192 "Misplaced _ in number");
12196 /* read digits of exponent */
12197 while (isDIGIT(*s) || *s == '_') {
12200 Perl_croak(aTHX_ number_too_long);
12204 if (((lastub && s == lastub + 1) ||
12205 (!isDIGIT(s[1]) && s[1] != '_'))
12206 && ckWARN(WARN_SYNTAX))
12207 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12208 "Misplaced _ in number");
12215 /* make an sv from the string */
12219 We try to do an integer conversion first if no characters
12220 indicating "float" have been found.
12225 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12227 if (flags == IS_NUMBER_IN_UV) {
12229 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12232 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12233 if (uv <= (UV) IV_MIN)
12234 sv_setiv(sv, -(IV)uv);
12241 /* terminate the string */
12243 nv = Atof(PL_tokenbuf);
12247 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12248 (PL_hints & HINT_NEW_INTEGER) )
12249 sv = new_constant(PL_tokenbuf,
12252 (floatit ? "float" : "integer"),
12256 /* if it starts with a v, it could be a v-string */
12259 sv = newSV(5); /* preallocate storage space */
12260 s = scan_vstring(s, PL_bufend, sv);
12264 /* make the op for the constant and return */
12267 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12269 lvalp->opval = NULL;
12275 S_scan_formline(pTHX_ register char *s)
12278 register char *eol;
12280 SV * const stuff = newSVpvs("");
12281 bool needargs = FALSE;
12282 bool eofmt = FALSE;
12284 char *tokenstart = s;
12287 if (PL_madskills) {
12288 savewhite = PL_thiswhite;
12293 while (!needargs) {
12296 #ifdef PERL_STRICT_CR
12297 while (SPACE_OR_TAB(*t))
12300 while (SPACE_OR_TAB(*t) || *t == '\r')
12303 if (*t == '\n' || t == PL_bufend) {
12308 if (PL_in_eval && !PL_rsfp) {
12309 eol = (char *) memchr(s,'\n',PL_bufend-s);
12314 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12316 for (t = s; t < eol; t++) {
12317 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12319 goto enough; /* ~~ must be first line in formline */
12321 if (*t == '@' || *t == '^')
12325 sv_catpvn(stuff, s, eol-s);
12326 #ifndef PERL_STRICT_CR
12327 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12328 char *end = SvPVX(stuff) + SvCUR(stuff);
12331 SvCUR_set(stuff, SvCUR(stuff) - 1);
12341 if (PL_madskills) {
12343 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12345 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12348 s = filter_gets(PL_linestr, PL_rsfp, 0);
12350 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12352 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12354 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12355 PL_last_lop = PL_last_uni = NULL;
12364 if (SvCUR(stuff)) {
12367 PL_lex_state = LEX_NORMAL;
12368 start_force(PL_curforce);
12369 NEXTVAL_NEXTTOKE.ival = 0;
12373 PL_lex_state = LEX_FORMLINE;
12375 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12377 else if (PL_encoding)
12378 sv_recode_to_utf8(stuff, PL_encoding);
12380 start_force(PL_curforce);
12381 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12383 start_force(PL_curforce);
12384 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12388 SvREFCNT_dec(stuff);
12390 PL_lex_formbrack = 0;
12394 if (PL_madskills) {
12396 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12398 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12399 PL_thiswhite = savewhite;
12411 PL_cshlen = strlen(PL_cshname);
12413 #if defined(USE_ITHREADS)
12414 PERL_UNUSED_CONTEXT;
12420 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12423 const I32 oldsavestack_ix = PL_savestack_ix;
12424 CV* const outsidecv = PL_compcv;
12427 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12429 SAVEI32(PL_subline);
12430 save_item(PL_subname);
12431 SAVESPTR(PL_compcv);
12433 PL_compcv = (CV*)newSV_type(is_format ? SVt_PVFM : SVt_PVCV);
12434 CvFLAGS(PL_compcv) |= flags;
12436 PL_subline = CopLINE(PL_curcop);
12437 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12438 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12439 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12441 return oldsavestack_ix;
12445 #pragma segment Perl_yylex
12448 Perl_yywarn(pTHX_ const char *s)
12451 PL_in_eval |= EVAL_WARNONLY;
12453 PL_in_eval &= ~EVAL_WARNONLY;
12458 Perl_yyerror(pTHX_ const char *s)
12461 const char *where = NULL;
12462 const char *context = NULL;
12465 int yychar = PL_parser->yychar;
12467 if (!yychar || (yychar == ';' && !PL_rsfp))
12469 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12470 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12471 PL_oldbufptr != PL_bufptr) {
12474 The code below is removed for NetWare because it abends/crashes on NetWare
12475 when the script has error such as not having the closing quotes like:
12476 if ($var eq "value)
12477 Checking of white spaces is anyway done in NetWare code.
12480 while (isSPACE(*PL_oldoldbufptr))
12483 context = PL_oldoldbufptr;
12484 contlen = PL_bufptr - PL_oldoldbufptr;
12486 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12487 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12490 The code below is removed for NetWare because it abends/crashes on NetWare
12491 when the script has error such as not having the closing quotes like:
12492 if ($var eq "value)
12493 Checking of white spaces is anyway done in NetWare code.
12496 while (isSPACE(*PL_oldbufptr))
12499 context = PL_oldbufptr;
12500 contlen = PL_bufptr - PL_oldbufptr;
12502 else if (yychar > 255)
12503 where = "next token ???";
12504 else if (yychar == -2) { /* YYEMPTY */
12505 if (PL_lex_state == LEX_NORMAL ||
12506 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12507 where = "at end of line";
12508 else if (PL_lex_inpat)
12509 where = "within pattern";
12511 where = "within string";
12514 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12516 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12517 else if (isPRINT_LC(yychar))
12518 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12520 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12521 where = SvPVX_const(where_sv);
12523 msg = sv_2mortal(newSVpv(s, 0));
12524 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12525 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12527 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12529 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12530 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12531 Perl_sv_catpvf(aTHX_ msg,
12532 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12533 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12536 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12537 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
12540 if (PL_error_count >= 10) {
12541 if (PL_in_eval && SvCUR(ERRSV))
12542 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12543 SVfARG(ERRSV), OutCopFILE(PL_curcop));
12545 Perl_croak(aTHX_ "%s has too many errors.\n",
12546 OutCopFILE(PL_curcop));
12549 PL_in_my_stash = NULL;
12553 #pragma segment Main
12557 S_swallow_bom(pTHX_ U8 *s)
12560 const STRLEN slen = SvCUR(PL_linestr);
12563 if (s[1] == 0xFE) {
12564 /* UTF-16 little-endian? (or UTF32-LE?) */
12565 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12566 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12567 #ifndef PERL_NO_UTF16_FILTER
12568 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12571 if (PL_bufend > (char*)s) {
12575 filter_add(utf16rev_textfilter, NULL);
12576 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12577 utf16_to_utf8_reversed(s, news,
12578 PL_bufend - (char*)s - 1,
12580 sv_setpvn(PL_linestr, (const char*)news, newlen);
12582 s = (U8*)SvPVX(PL_linestr);
12583 Copy(news, s, newlen, U8);
12587 SvUTF8_on(PL_linestr);
12588 s = (U8*)SvPVX(PL_linestr);
12590 /* FIXME - is this a general bug fix? */
12593 PL_bufend = SvPVX(PL_linestr) + newlen;
12596 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12601 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12602 #ifndef PERL_NO_UTF16_FILTER
12603 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12606 if (PL_bufend > (char *)s) {
12610 filter_add(utf16_textfilter, NULL);
12611 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12612 utf16_to_utf8(s, news,
12613 PL_bufend - (char*)s,
12615 sv_setpvn(PL_linestr, (const char*)news, newlen);
12617 SvUTF8_on(PL_linestr);
12618 s = (U8*)SvPVX(PL_linestr);
12619 PL_bufend = SvPVX(PL_linestr) + newlen;
12622 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12627 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12628 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12629 s += 3; /* UTF-8 */
12635 if (s[2] == 0xFE && s[3] == 0xFF) {
12636 /* UTF-32 big-endian */
12637 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12640 else if (s[2] == 0 && s[3] != 0) {
12643 * are a good indicator of UTF-16BE. */
12644 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12650 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12651 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12652 s += 4; /* UTF-8 */
12658 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12661 * are a good indicator of UTF-16LE. */
12662 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12670 #ifndef PERL_NO_UTF16_FILTER
12672 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12675 const STRLEN old = SvCUR(sv);
12676 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12677 DEBUG_P(PerlIO_printf(Perl_debug_log,
12678 "utf16_textfilter(%p): %d %d (%d)\n",
12679 FPTR2DPTR(void *, utf16_textfilter),
12680 idx, maxlen, (int) count));
12684 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12685 Copy(SvPVX_const(sv), tmps, old, char);
12686 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12687 SvCUR(sv) - old, &newlen);
12688 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12690 DEBUG_P({sv_dump(sv);});
12695 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12698 const STRLEN old = SvCUR(sv);
12699 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12700 DEBUG_P(PerlIO_printf(Perl_debug_log,
12701 "utf16rev_textfilter(%p): %d %d (%d)\n",
12702 FPTR2DPTR(void *, utf16rev_textfilter),
12703 idx, maxlen, (int) count));
12707 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12708 Copy(SvPVX_const(sv), tmps, old, char);
12709 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12710 SvCUR(sv) - old, &newlen);
12711 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12713 DEBUG_P({ sv_dump(sv); });
12719 Returns a pointer to the next character after the parsed
12720 vstring, as well as updating the passed in sv.
12722 Function must be called like
12725 s = scan_vstring(s,e,sv);
12727 where s and e are the start and end of the string.
12728 The sv should already be large enough to store the vstring
12729 passed in, for performance reasons.
12734 Perl_scan_vstring(pTHX_ const char *s, const char *e, SV *sv)
12737 const char *pos = s;
12738 const char *start = s;
12739 if (*pos == 'v') pos++; /* get past 'v' */
12740 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12742 if ( *pos != '.') {
12743 /* this may not be a v-string if followed by => */
12744 const char *next = pos;
12745 while (next < e && isSPACE(*next))
12747 if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
12748 /* return string not v-string */
12749 sv_setpvn(sv,(char *)s,pos-s);
12750 return (char *)pos;
12754 if (!isALPHA(*pos)) {
12755 U8 tmpbuf[UTF8_MAXBYTES+1];
12758 s++; /* get past 'v' */
12760 sv_setpvn(sv, "", 0);
12763 /* this is atoi() that tolerates underscores */
12766 const char *end = pos;
12768 while (--end >= s) {
12770 const UV orev = rev;
12771 rev += (*end - '0') * mult;
12773 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12774 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12775 "Integer overflow in decimal number");
12779 if (rev > 0x7FFFFFFF)
12780 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12782 /* Append native character for the rev point */
12783 tmpend = uvchr_to_utf8(tmpbuf, rev);
12784 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12785 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12787 if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
12793 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12797 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12805 * c-indentation-style: bsd
12806 * c-basic-offset: 4
12807 * indent-tabs-mode: t
12810 * ex: set ts=8 sts=4 sw=4 noet: