3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 * 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 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
14 * [p.719 of _The Lord of the Rings_, IV/ix: "Shelob's Lair"]
18 * This file is the lexer for Perl. It's closely linked to the
21 * The main routine is yylex(), which returns the next token.
25 #define PERL_IN_TOKE_C
28 #define new_constant(a,b,c,d,e,f,g) \
29 S_new_constant(aTHX_ a,b,STR_WITH_LEN(c),d,e,f, g)
31 #define pl_yylval (PL_parser->yylval)
33 /* YYINITDEPTH -- initial size of the parser's stacks. */
34 #define YYINITDEPTH 200
36 /* XXX temporary backwards compatibility */
37 #define PL_lex_brackets (PL_parser->lex_brackets)
38 #define PL_lex_brackstack (PL_parser->lex_brackstack)
39 #define PL_lex_casemods (PL_parser->lex_casemods)
40 #define PL_lex_casestack (PL_parser->lex_casestack)
41 #define PL_lex_defer (PL_parser->lex_defer)
42 #define PL_lex_dojoin (PL_parser->lex_dojoin)
43 #define PL_lex_expect (PL_parser->lex_expect)
44 #define PL_lex_formbrack (PL_parser->lex_formbrack)
45 #define PL_lex_inpat (PL_parser->lex_inpat)
46 #define PL_lex_inwhat (PL_parser->lex_inwhat)
47 #define PL_lex_op (PL_parser->lex_op)
48 #define PL_lex_repl (PL_parser->lex_repl)
49 #define PL_lex_starts (PL_parser->lex_starts)
50 #define PL_lex_stuff (PL_parser->lex_stuff)
51 #define PL_multi_start (PL_parser->multi_start)
52 #define PL_multi_open (PL_parser->multi_open)
53 #define PL_multi_close (PL_parser->multi_close)
54 #define PL_pending_ident (PL_parser->pending_ident)
55 #define PL_preambled (PL_parser->preambled)
56 #define PL_sublex_info (PL_parser->sublex_info)
57 #define PL_linestr (PL_parser->linestr)
58 #define PL_expect (PL_parser->expect)
59 #define PL_copline (PL_parser->copline)
60 #define PL_bufptr (PL_parser->bufptr)
61 #define PL_oldbufptr (PL_parser->oldbufptr)
62 #define PL_oldoldbufptr (PL_parser->oldoldbufptr)
63 #define PL_linestart (PL_parser->linestart)
64 #define PL_bufend (PL_parser->bufend)
65 #define PL_last_uni (PL_parser->last_uni)
66 #define PL_last_lop (PL_parser->last_lop)
67 #define PL_last_lop_op (PL_parser->last_lop_op)
68 #define PL_lex_state (PL_parser->lex_state)
69 #define PL_rsfp (PL_parser->rsfp)
70 #define PL_rsfp_filters (PL_parser->rsfp_filters)
71 #define PL_in_my (PL_parser->in_my)
72 #define PL_in_my_stash (PL_parser->in_my_stash)
73 #define PL_tokenbuf (PL_parser->tokenbuf)
74 #define PL_multi_end (PL_parser->multi_end)
75 #define PL_error_count (PL_parser->error_count)
78 # define PL_endwhite (PL_parser->endwhite)
79 # define PL_faketokens (PL_parser->faketokens)
80 # define PL_lasttoke (PL_parser->lasttoke)
81 # define PL_nextwhite (PL_parser->nextwhite)
82 # define PL_realtokenstart (PL_parser->realtokenstart)
83 # define PL_skipwhite (PL_parser->skipwhite)
84 # define PL_thisclose (PL_parser->thisclose)
85 # define PL_thismad (PL_parser->thismad)
86 # define PL_thisopen (PL_parser->thisopen)
87 # define PL_thisstuff (PL_parser->thisstuff)
88 # define PL_thistoken (PL_parser->thistoken)
89 # define PL_thiswhite (PL_parser->thiswhite)
90 # define PL_thiswhite (PL_parser->thiswhite)
91 # define PL_nexttoke (PL_parser->nexttoke)
92 # define PL_curforce (PL_parser->curforce)
94 # define PL_nexttoke (PL_parser->nexttoke)
95 # define PL_nexttype (PL_parser->nexttype)
96 # define PL_nextval (PL_parser->nextval)
100 S_pending_ident(pTHX);
102 static const char ident_too_long[] = "Identifier too long";
103 static const char commaless_variable_list[] = "comma-less variable list";
105 #ifndef PERL_NO_UTF16_FILTER
106 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
107 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
111 # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
112 # define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
114 # define CURMAD(slot,sv)
115 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
118 #define XFAKEBRACK 128
119 #define XENUMMASK 127
121 #ifdef USE_UTF8_SCRIPTS
122 # define UTF (!IN_BYTES)
124 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
127 /* In variables named $^X, these are the legal values for X.
128 * 1999-02-27 mjd-perl-patch@plover.com */
129 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
131 /* On MacOS, respect nonbreaking spaces */
132 #ifdef MACOS_TRADITIONAL
133 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
135 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
138 /* LEX_* are values for PL_lex_state, the state of the lexer.
139 * They are arranged oddly so that the guard on the switch statement
140 * can get by with a single comparison (if the compiler is smart enough).
143 /* #define LEX_NOTPARSING 11 is done in perl.h. */
145 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
146 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
147 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
148 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
149 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
151 /* at end of code, eg "$x" followed by: */
152 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
153 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
155 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
156 string or after \E, $foo, etc */
157 #define LEX_INTERPCONST 2 /* NOT USED */
158 #define LEX_FORMLINE 1 /* expecting a format line */
159 #define LEX_KNOWNEXT 0 /* next token known; just return it */
163 static const char* const lex_state_names[] = {
182 #include "keywords.h"
184 /* CLINE is a macro that ensures PL_copline has a sane value */
189 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
192 # define SKIPSPACE0(s) skipspace0(s)
193 # define SKIPSPACE1(s) skipspace1(s)
194 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
195 # define PEEKSPACE(s) skipspace2(s,0)
197 # define SKIPSPACE0(s) skipspace(s)
198 # define SKIPSPACE1(s) skipspace(s)
199 # define SKIPSPACE2(s,tsv) skipspace(s)
200 # define PEEKSPACE(s) skipspace(s)
204 * Convenience functions to return different tokens and prime the
205 * lexer for the next token. They all take an argument.
207 * TOKEN : generic token (used for '(', DOLSHARP, etc)
208 * OPERATOR : generic operator
209 * AOPERATOR : assignment operator
210 * PREBLOCK : beginning the block after an if, while, foreach, ...
211 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
212 * PREREF : *EXPR where EXPR is not a simple identifier
213 * TERM : expression term
214 * LOOPX : loop exiting command (goto, last, dump, etc)
215 * FTST : file test operator
216 * FUN0 : zero-argument function
217 * FUN1 : not used, except for not, which isn't a UNIOP
218 * BOop : bitwise or or xor
220 * SHop : shift operator
221 * PWop : power operator
222 * PMop : pattern-matching operator
223 * Aop : addition-level operator
224 * Mop : multiplication-level operator
225 * Eop : equality-testing operator
226 * Rop : relational operator <= != gt
228 * Also see LOP and lop() below.
231 #ifdef DEBUGGING /* Serve -DT. */
232 # define REPORT(retval) tokereport((I32)retval, &pl_yylval)
234 # define REPORT(retval) (retval)
237 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
238 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
239 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
240 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
241 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
242 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
243 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
244 #define LOOPX(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
245 #define FTST(f) return (pl_yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
246 #define FUN0(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
247 #define FUN1(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
248 #define BOop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
249 #define BAop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
250 #define SHop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
251 #define PWop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
252 #define PMop(f) return(pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
253 #define Aop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
254 #define Mop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
255 #define Eop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
256 #define Rop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
258 /* This bit of chicanery makes a unary function followed by
259 * a parenthesis into a function with one argument, highest precedence.
260 * The UNIDOR macro is for unary functions that can be followed by the //
261 * operator (such as C<shift // 0>).
263 #define UNI2(f,x) { \
264 pl_yylval.ival = f; \
267 PL_last_uni = PL_oldbufptr; \
268 PL_last_lop_op = f; \
270 return REPORT( (int)FUNC1 ); \
272 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
274 #define UNI(f) UNI2(f,XTERM)
275 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
277 #define UNIBRACK(f) { \
278 pl_yylval.ival = f; \
280 PL_last_uni = PL_oldbufptr; \
282 return REPORT( (int)FUNC1 ); \
284 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
287 /* grandfather return to old style */
288 #define OLDLOP(f) return(pl_yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
292 /* how to interpret the pl_yylval associated with the token */
296 TOKENTYPE_OPNUM, /* pl_yylval.ival contains an opcode number */
302 static struct debug_tokens {
304 enum token_type type;
306 } const debug_tokens[] =
308 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
309 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
310 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
311 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
312 { ARROW, TOKENTYPE_NONE, "ARROW" },
313 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
314 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
315 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
316 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
317 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
318 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
319 { DO, TOKENTYPE_NONE, "DO" },
320 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
321 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
322 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
323 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
324 { ELSE, TOKENTYPE_NONE, "ELSE" },
325 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
326 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
327 { FOR, TOKENTYPE_IVAL, "FOR" },
328 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
329 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
330 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
331 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
332 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
333 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
334 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
335 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
336 { IF, TOKENTYPE_IVAL, "IF" },
337 { LABEL, TOKENTYPE_PVAL, "LABEL" },
338 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
339 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
340 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
341 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
342 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
343 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
344 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
345 { MY, TOKENTYPE_IVAL, "MY" },
346 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
347 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
348 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
349 { OROP, TOKENTYPE_IVAL, "OROP" },
350 { OROR, TOKENTYPE_NONE, "OROR" },
351 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
352 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
353 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
354 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
355 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
356 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
357 { PREINC, TOKENTYPE_NONE, "PREINC" },
358 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
359 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
360 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
361 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
362 { SUB, TOKENTYPE_NONE, "SUB" },
363 { THING, TOKENTYPE_OPVAL, "THING" },
364 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
365 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
366 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
367 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
368 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
369 { USE, TOKENTYPE_IVAL, "USE" },
370 { WHEN, TOKENTYPE_IVAL, "WHEN" },
371 { WHILE, TOKENTYPE_IVAL, "WHILE" },
372 { WORD, TOKENTYPE_OPVAL, "WORD" },
373 { YADAYADA, TOKENTYPE_IVAL, "YADAYADA" },
374 { 0, TOKENTYPE_NONE, NULL }
377 /* dump the returned token in rv, plus any optional arg in pl_yylval */
380 S_tokereport(pTHX_ I32 rv, const YYSTYPE* lvalp)
384 PERL_ARGS_ASSERT_TOKEREPORT;
387 const char *name = NULL;
388 enum token_type type = TOKENTYPE_NONE;
389 const struct debug_tokens *p;
390 SV* const report = newSVpvs("<== ");
392 for (p = debug_tokens; p->token; p++) {
393 if (p->token == (int)rv) {
400 Perl_sv_catpv(aTHX_ report, name);
401 else if ((char)rv > ' ' && (char)rv < '~')
402 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
404 sv_catpvs(report, "EOF");
406 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
409 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
412 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)lvalp->ival);
414 case TOKENTYPE_OPNUM:
415 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
416 PL_op_name[lvalp->ival]);
419 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", lvalp->pval);
421 case TOKENTYPE_OPVAL:
423 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
424 PL_op_name[lvalp->opval->op_type]);
425 if (lvalp->opval->op_type == OP_CONST) {
426 Perl_sv_catpvf(aTHX_ report, " %s",
427 SvPEEK(cSVOPx_sv(lvalp->opval)));
432 sv_catpvs(report, "(opval=null)");
435 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
441 /* print the buffer with suitable escapes */
444 S_printbuf(pTHX_ const char *const fmt, const char *const s)
446 SV* const tmp = newSVpvs("");
448 PERL_ARGS_ASSERT_PRINTBUF;
450 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
459 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
460 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
464 S_ao(pTHX_ int toketype)
467 if (*PL_bufptr == '=') {
469 if (toketype == ANDAND)
470 pl_yylval.ival = OP_ANDASSIGN;
471 else if (toketype == OROR)
472 pl_yylval.ival = OP_ORASSIGN;
473 else if (toketype == DORDOR)
474 pl_yylval.ival = OP_DORASSIGN;
482 * When Perl expects an operator and finds something else, no_op
483 * prints the warning. It always prints "<something> found where
484 * operator expected. It prints "Missing semicolon on previous line?"
485 * if the surprise occurs at the start of the line. "do you need to
486 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
487 * where the compiler doesn't know if foo is a method call or a function.
488 * It prints "Missing operator before end of line" if there's nothing
489 * after the missing operator, or "... before <...>" if there is something
490 * after the missing operator.
494 S_no_op(pTHX_ const char *const what, char *s)
497 char * const oldbp = PL_bufptr;
498 const bool is_first = (PL_oldbufptr == PL_linestart);
500 PERL_ARGS_ASSERT_NO_OP;
506 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
507 if (ckWARN_d(WARN_SYNTAX)) {
509 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
510 "\t(Missing semicolon on previous line?)\n");
511 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
513 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
515 if (t < PL_bufptr && isSPACE(*t))
516 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
517 "\t(Do you need to predeclare %.*s?)\n",
518 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
522 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
523 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
531 * Complain about missing quote/regexp/heredoc terminator.
532 * If it's called with NULL then it cauterizes the line buffer.
533 * If we're in a delimited string and the delimiter is a control
534 * character, it's reformatted into a two-char sequence like ^C.
539 S_missingterm(pTHX_ char *s)
545 char * const nl = strrchr(s,'\n');
551 iscntrl(PL_multi_close)
553 PL_multi_close < 32 || PL_multi_close == 127
557 tmpbuf[1] = (char)toCTRL(PL_multi_close);
562 *tmpbuf = (char)PL_multi_close;
566 q = strchr(s,'"') ? '\'' : '"';
567 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
570 #define FEATURE_IS_ENABLED(name) \
571 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
572 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
573 /* The longest string we pass in. */
574 #define MAX_FEATURE_LEN (sizeof("switch")-1)
577 * S_feature_is_enabled
578 * Check whether the named feature is enabled.
581 S_feature_is_enabled(pTHX_ const char *const name, STRLEN namelen)
584 HV * const hinthv = GvHV(PL_hintgv);
585 char he_name[8 + MAX_FEATURE_LEN] = "feature_";
587 PERL_ARGS_ASSERT_FEATURE_IS_ENABLED;
589 assert(namelen <= MAX_FEATURE_LEN);
590 memcpy(&he_name[8], name, namelen);
592 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
600 Perl_deprecate(pTHX_ const char *const s)
602 PERL_ARGS_ASSERT_DEPRECATE;
604 if (ckWARN(WARN_DEPRECATED))
605 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
609 Perl_deprecate_old(pTHX_ const char *const s)
611 /* This function should NOT be called for any new deprecated warnings */
612 /* Use Perl_deprecate instead */
614 /* It is here to maintain backward compatibility with the pre-5.8 */
615 /* warnings category hierarchy. The "deprecated" category used to */
616 /* live under the "syntax" category. It is now a top-level category */
617 /* in its own right. */
619 PERL_ARGS_ASSERT_DEPRECATE_OLD;
621 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
622 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
623 "Use of %s is deprecated", s);
627 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
628 * utf16-to-utf8-reversed.
631 #ifdef PERL_CR_FILTER
635 register const char *s = SvPVX_const(sv);
636 register const char * const e = s + SvCUR(sv);
638 PERL_ARGS_ASSERT_STRIP_RETURN;
640 /* outer loop optimized to do nothing if there are no CR-LFs */
642 if (*s++ == '\r' && *s == '\n') {
643 /* hit a CR-LF, need to copy the rest */
644 register char *d = s - 1;
647 if (*s == '\r' && s[1] == '\n')
658 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
660 const I32 count = FILTER_READ(idx+1, sv, maxlen);
661 if (count > 0 && !maxlen)
672 * Create a parser object and initialise its parser and lexer fields
674 * rsfp is the opened file handle to read from (if any),
676 * line holds any initial content already read from the file (or in
677 * the case of no file, such as an eval, the whole contents);
679 * new_filter indicates that this is a new file and it shouldn't inherit
680 * the filters from the current parser (ie require).
684 Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, bool new_filter)
687 const char *s = NULL;
689 yy_parser *parser, *oparser;
691 /* create and initialise a parser */
693 Newxz(parser, 1, yy_parser);
694 parser->old_parser = oparser = PL_parser;
697 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
698 parser->ps = parser->stack;
699 parser->stack_size = YYINITDEPTH;
701 parser->stack->state = 0;
702 parser->yyerrstatus = 0;
703 parser->yychar = YYEMPTY; /* Cause a token to be read. */
705 /* on scope exit, free this parser and restore any outer one */
707 parser->saved_curcop = PL_curcop;
709 /* initialise lexer state */
712 parser->curforce = -1;
714 parser->nexttoke = 0;
716 parser->error_count = oparser ? oparser->error_count : 0;
717 parser->copline = NOLINE;
718 parser->lex_state = LEX_NORMAL;
719 parser->expect = XSTATE;
721 parser->rsfp_filters = (new_filter || !oparser) ? newAV()
722 : MUTABLE_AV(SvREFCNT_inc(oparser->rsfp_filters));
724 Newx(parser->lex_brackstack, 120, char);
725 Newx(parser->lex_casestack, 12, char);
726 *parser->lex_casestack = '\0';
729 s = SvPV_const(line, len);
735 parser->linestr = newSVpvs("\n;");
736 } else if (SvREADONLY(line) || s[len-1] != ';') {
737 parser->linestr = newSVsv(line);
739 sv_catpvs(parser->linestr, "\n;");
742 SvREFCNT_inc_simple_void_NN(line);
743 parser->linestr = line;
745 parser->oldoldbufptr =
748 parser->linestart = SvPVX(parser->linestr);
749 parser->bufend = parser->bufptr + SvCUR(parser->linestr);
750 parser->last_lop = parser->last_uni = NULL;
754 /* delete a parser object */
757 Perl_parser_free(pTHX_ const yy_parser *parser)
759 PERL_ARGS_ASSERT_PARSER_FREE;
761 PL_curcop = parser->saved_curcop;
762 SvREFCNT_dec(parser->linestr);
764 if (parser->rsfp == PerlIO_stdin())
765 PerlIO_clearerr(parser->rsfp);
766 else if (parser->rsfp && (!parser->old_parser ||
767 (parser->old_parser && parser->rsfp != parser->old_parser->rsfp)))
768 PerlIO_close(parser->rsfp);
769 SvREFCNT_dec(parser->rsfp_filters);
771 Safefree(parser->stack);
772 Safefree(parser->lex_brackstack);
773 Safefree(parser->lex_casestack);
774 PL_parser = parser->old_parser;
781 * Finalizer for lexing operations. Must be called when the parser is
782 * done with the lexer.
789 PL_doextract = FALSE;
794 * This subroutine has nothing to do with tilting, whether at windmills
795 * or pinball tables. Its name is short for "increment line". It
796 * increments the current line number in CopLINE(PL_curcop) and checks
797 * to see whether the line starts with a comment of the form
798 * # line 500 "foo.pm"
799 * If so, it sets the current line number and file to the values in the comment.
803 S_incline(pTHX_ const char *s)
810 PERL_ARGS_ASSERT_INCLINE;
812 CopLINE_inc(PL_curcop);
815 while (SPACE_OR_TAB(*s))
817 if (strnEQ(s, "line", 4))
821 if (SPACE_OR_TAB(*s))
825 while (SPACE_OR_TAB(*s))
833 while (SPACE_OR_TAB(*s))
835 if (*s == '"' && (t = strchr(s+1, '"'))) {
845 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
847 if (*e != '\n' && *e != '\0')
848 return; /* false alarm */
851 const STRLEN len = t - s;
853 SV *const temp_sv = CopFILESV(PL_curcop);
859 tmplen = SvCUR(temp_sv);
865 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
866 /* must copy *{"::_<(eval N)[oldfilename:L]"}
867 * to *{"::_<newfilename"} */
868 /* However, the long form of evals is only turned on by the
869 debugger - usually they're "(eval %lu)" */
873 STRLEN tmplen2 = len;
874 if (tmplen + 2 <= sizeof smallbuf)
877 Newx(tmpbuf, tmplen + 2, char);
880 memcpy(tmpbuf + 2, cf, tmplen);
882 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
887 if (tmplen2 + 2 <= sizeof smallbuf)
890 Newx(tmpbuf2, tmplen2 + 2, char);
892 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
893 /* Either they malloc'd it, or we malloc'd it,
894 so no prefix is present in ours. */
899 memcpy(tmpbuf2 + 2, s, tmplen2);
902 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
904 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
905 /* adjust ${"::_<newfilename"} to store the new file name */
906 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
907 GvHV(gv2) = MUTABLE_HV(SvREFCNT_inc(GvHV(*gvp)));
908 GvAV(gv2) = MUTABLE_AV(SvREFCNT_inc(GvAV(*gvp)));
911 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
913 if (tmpbuf != smallbuf) Safefree(tmpbuf);
916 CopFILE_free(PL_curcop);
917 CopFILE_setn(PL_curcop, s, len);
919 CopLINE_set(PL_curcop, atoi(n)-1);
923 /* skip space before PL_thistoken */
926 S_skipspace0(pTHX_ register char *s)
928 PERL_ARGS_ASSERT_SKIPSPACE0;
935 PL_thiswhite = newSVpvs("");
936 sv_catsv(PL_thiswhite, PL_skipwhite);
937 sv_free(PL_skipwhite);
940 PL_realtokenstart = s - SvPVX(PL_linestr);
944 /* skip space after PL_thistoken */
947 S_skipspace1(pTHX_ register char *s)
949 const char *start = s;
950 I32 startoff = start - SvPVX(PL_linestr);
952 PERL_ARGS_ASSERT_SKIPSPACE1;
957 start = SvPVX(PL_linestr) + startoff;
958 if (!PL_thistoken && PL_realtokenstart >= 0) {
959 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
960 PL_thistoken = newSVpvn(tstart, start - tstart);
962 PL_realtokenstart = -1;
965 PL_nextwhite = newSVpvs("");
966 sv_catsv(PL_nextwhite, PL_skipwhite);
967 sv_free(PL_skipwhite);
974 S_skipspace2(pTHX_ register char *s, SV **svp)
977 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
978 const I32 startoff = s - SvPVX(PL_linestr);
980 PERL_ARGS_ASSERT_SKIPSPACE2;
983 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
984 if (!PL_madskills || !svp)
986 start = SvPVX(PL_linestr) + startoff;
987 if (!PL_thistoken && PL_realtokenstart >= 0) {
988 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
989 PL_thistoken = newSVpvn(tstart, start - tstart);
990 PL_realtokenstart = -1;
995 sv_setsv(*svp, PL_skipwhite);
996 sv_free(PL_skipwhite);
1005 S_update_debugger_info(pTHX_ SV *orig_sv, const char *const buf, STRLEN len)
1007 AV *av = CopFILEAVx(PL_curcop);
1009 SV * const sv = newSV_type(SVt_PVMG);
1011 sv_setsv(sv, orig_sv);
1013 sv_setpvn(sv, buf, len);
1016 av_store(av, (I32)CopLINE(PL_curcop), sv);
1022 * Called to gobble the appropriate amount and type of whitespace.
1023 * Skips comments as well.
1027 S_skipspace(pTHX_ register char *s)
1032 int startoff = s - SvPVX(PL_linestr);
1034 PERL_ARGS_ASSERT_SKIPSPACE;
1037 sv_free(PL_skipwhite);
1041 PERL_ARGS_ASSERT_SKIPSPACE;
1043 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
1044 while (s < PL_bufend && SPACE_OR_TAB(*s))
1054 SSize_t oldprevlen, oldoldprevlen;
1055 SSize_t oldloplen = 0, oldunilen = 0;
1056 while (s < PL_bufend && isSPACE(*s)) {
1057 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
1062 if (s < PL_bufend && *s == '#') {
1063 while (s < PL_bufend && *s != '\n')
1065 if (s < PL_bufend) {
1067 if (PL_in_eval && !PL_rsfp) {
1074 /* only continue to recharge the buffer if we're at the end
1075 * of the buffer, we're not reading from a source filter, and
1076 * we're in normal lexing mode
1078 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
1079 PL_lex_state == LEX_FORMLINE)
1086 /* try to recharge the buffer */
1088 curoff = s - SvPVX(PL_linestr);
1091 if ((s = filter_gets(PL_linestr, PL_rsfp,
1092 (prevlen = SvCUR(PL_linestr)))) == NULL)
1095 if (PL_madskills && curoff != startoff) {
1097 PL_skipwhite = newSVpvs("");
1098 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1102 /* mustn't throw out old stuff yet if madpropping */
1103 SvCUR(PL_linestr) = curoff;
1104 s = SvPVX(PL_linestr) + curoff;
1106 if (curoff && s[-1] == '\n')
1110 /* end of file. Add on the -p or -n magic */
1111 /* XXX these shouldn't really be added here, can't set PL_faketokens */
1114 sv_catpvs(PL_linestr,
1115 ";}continue{print or die qq(-p destination: $!\\n);}");
1117 sv_setpvs(PL_linestr,
1118 ";}continue{print or die qq(-p destination: $!\\n);}");
1120 PL_minus_n = PL_minus_p = 0;
1122 else if (PL_minus_n) {
1124 sv_catpvs(PL_linestr, ";}");
1126 sv_setpvs(PL_linestr, ";}");
1132 sv_catpvs(PL_linestr,";");
1134 sv_setpvs(PL_linestr,";");
1137 /* reset variables for next time we lex */
1138 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
1144 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1145 PL_last_lop = PL_last_uni = NULL;
1147 /* Close the filehandle. Could be from
1148 * STDIN, or a regular file. If we were reading code from
1149 * STDIN (because the commandline held no -e or filename)
1150 * then we don't close it, we reset it so the code can
1151 * read from STDIN too.
1154 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1155 PerlIO_clearerr(PL_rsfp);
1157 (void)PerlIO_close(PL_rsfp);
1162 /* not at end of file, so we only read another line */
1163 /* make corresponding updates to old pointers, for yyerror() */
1164 oldprevlen = PL_oldbufptr - PL_bufend;
1165 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1167 oldunilen = PL_last_uni - PL_bufend;
1169 oldloplen = PL_last_lop - PL_bufend;
1170 PL_linestart = PL_bufptr = s + prevlen;
1171 PL_bufend = s + SvCUR(PL_linestr);
1173 PL_oldbufptr = s + oldprevlen;
1174 PL_oldoldbufptr = s + oldoldprevlen;
1176 PL_last_uni = s + oldunilen;
1178 PL_last_lop = s + oldloplen;
1181 /* debugger active and we're not compiling the debugger code,
1182 * so store the line into the debugger's array of lines
1184 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
1185 update_debugger_info(NULL, PL_bufptr, PL_bufend - PL_bufptr);
1192 PL_skipwhite = newSVpvs("");
1193 curoff = s - SvPVX(PL_linestr);
1194 if (curoff - startoff)
1195 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1204 * Check the unary operators to ensure there's no ambiguity in how they're
1205 * used. An ambiguous piece of code would be:
1207 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1208 * the +5 is its argument.
1218 if (PL_oldoldbufptr != PL_last_uni)
1220 while (isSPACE(*PL_last_uni))
1223 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1225 if ((t = strchr(s, '(')) && t < PL_bufptr)
1228 if (ckWARN_d(WARN_AMBIGUOUS)){
1229 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1230 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1231 (int)(s - PL_last_uni), PL_last_uni);
1236 * LOP : macro to build a list operator. Its behaviour has been replaced
1237 * with a subroutine, S_lop() for which LOP is just another name.
1240 #define LOP(f,x) return lop(f,x,s)
1244 * Build a list operator (or something that might be one). The rules:
1245 * - if we have a next token, then it's a list operator [why?]
1246 * - if the next thing is an opening paren, then it's a function
1247 * - else it's a list operator
1251 S_lop(pTHX_ I32 f, int x, char *s)
1255 PERL_ARGS_ASSERT_LOP;
1261 PL_last_lop = PL_oldbufptr;
1262 PL_last_lop_op = (OPCODE)f;
1265 return REPORT(LSTOP);
1268 return REPORT(LSTOP);
1271 return REPORT(FUNC);
1274 return REPORT(FUNC);
1276 return REPORT(LSTOP);
1282 * Sets up for an eventual force_next(). start_force(0) basically does
1283 * an unshift, while start_force(-1) does a push. yylex removes items
1288 S_start_force(pTHX_ int where)
1292 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1293 where = PL_lasttoke;
1294 assert(PL_curforce < 0 || PL_curforce == where);
1295 if (PL_curforce != where) {
1296 for (i = PL_lasttoke; i > where; --i) {
1297 PL_nexttoke[i] = PL_nexttoke[i-1];
1301 if (PL_curforce < 0) /* in case of duplicate start_force() */
1302 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1303 PL_curforce = where;
1306 curmad('^', newSVpvs(""));
1307 CURMAD('_', PL_nextwhite);
1312 S_curmad(pTHX_ char slot, SV *sv)
1318 if (PL_curforce < 0)
1319 where = &PL_thismad;
1321 where = &PL_nexttoke[PL_curforce].next_mad;
1327 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1329 else if (PL_encoding) {
1330 sv_recode_to_utf8(sv, PL_encoding);
1335 /* keep a slot open for the head of the list? */
1336 if (slot != '_' && *where && (*where)->mad_key == '^') {
1337 (*where)->mad_key = slot;
1338 sv_free(MUTABLE_SV(((*where)->mad_val)));
1339 (*where)->mad_val = (void*)sv;
1342 addmad(newMADsv(slot, sv), where, 0);
1345 # define start_force(where) NOOP
1346 # define curmad(slot, sv) NOOP
1351 * When the lexer realizes it knows the next token (for instance,
1352 * it is reordering tokens for the parser) then it can call S_force_next
1353 * to know what token to return the next time the lexer is called. Caller
1354 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1355 * and possibly PL_expect to ensure the lexer handles the token correctly.
1359 S_force_next(pTHX_ I32 type)
1364 PerlIO_printf(Perl_debug_log, "### forced token:\n");
1365 tokereport(type, &NEXTVAL_NEXTTOKE);
1369 if (PL_curforce < 0)
1370 start_force(PL_lasttoke);
1371 PL_nexttoke[PL_curforce].next_type = type;
1372 if (PL_lex_state != LEX_KNOWNEXT)
1373 PL_lex_defer = PL_lex_state;
1374 PL_lex_state = LEX_KNOWNEXT;
1375 PL_lex_expect = PL_expect;
1378 PL_nexttype[PL_nexttoke] = type;
1380 if (PL_lex_state != LEX_KNOWNEXT) {
1381 PL_lex_defer = PL_lex_state;
1382 PL_lex_expect = PL_expect;
1383 PL_lex_state = LEX_KNOWNEXT;
1389 S_newSV_maybe_utf8(pTHX_ const char *const start, STRLEN len)
1392 SV * const sv = newSVpvn_utf8(start, len,
1394 && is_utf8_string((const U8*)start, len));
1400 * When the lexer knows the next thing is a word (for instance, it has
1401 * just seen -> and it knows that the next char is a word char, then
1402 * it calls S_force_word to stick the next word into the PL_nexttoke/val
1406 * char *start : buffer position (must be within PL_linestr)
1407 * int token : PL_next* will be this type of bare word (e.g., METHOD,WORD)
1408 * int check_keyword : if true, Perl checks to make sure the word isn't
1409 * a keyword (do this if the word is a label, e.g. goto FOO)
1410 * int allow_pack : if true, : characters will also be allowed (require,
1411 * use, etc. do this)
1412 * int allow_initial_tick : used by the "sub" lexer only.
1416 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1422 PERL_ARGS_ASSERT_FORCE_WORD;
1424 start = SKIPSPACE1(start);
1426 if (isIDFIRST_lazy_if(s,UTF) ||
1427 (allow_pack && *s == ':') ||
1428 (allow_initial_tick && *s == '\'') )
1430 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1431 if (check_keyword && keyword(PL_tokenbuf, len, 0))
1433 start_force(PL_curforce);
1435 curmad('X', newSVpvn(start,s-start));
1436 if (token == METHOD) {
1441 PL_expect = XOPERATOR;
1445 curmad('g', newSVpvs( "forced" ));
1446 NEXTVAL_NEXTTOKE.opval
1447 = (OP*)newSVOP(OP_CONST,0,
1448 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1449 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1457 * Called when the lexer wants $foo *foo &foo etc, but the program
1458 * text only contains the "foo" portion. The first argument is a pointer
1459 * to the "foo", and the second argument is the type symbol to prefix.
1460 * Forces the next token to be a "WORD".
1461 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1465 S_force_ident(pTHX_ register const char *s, int kind)
1469 PERL_ARGS_ASSERT_FORCE_IDENT;
1472 const STRLEN len = strlen(s);
1473 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1474 start_force(PL_curforce);
1475 NEXTVAL_NEXTTOKE.opval = o;
1478 o->op_private = OPpCONST_ENTERED;
1479 /* XXX see note in pp_entereval() for why we forgo typo
1480 warnings if the symbol must be introduced in an eval.
1482 gv_fetchpvn_flags(s, len,
1483 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1485 kind == '$' ? SVt_PV :
1486 kind == '@' ? SVt_PVAV :
1487 kind == '%' ? SVt_PVHV :
1495 Perl_str_to_version(pTHX_ SV *sv)
1500 const char *start = SvPV_const(sv,len);
1501 const char * const end = start + len;
1502 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1504 PERL_ARGS_ASSERT_STR_TO_VERSION;
1506 while (start < end) {
1510 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1515 retval += ((NV)n)/nshift;
1524 * Forces the next token to be a version number.
1525 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1526 * and if "guessing" is TRUE, then no new token is created (and the caller
1527 * must use an alternative parsing method).
1531 S_force_version(pTHX_ char *s, int guessing)
1537 I32 startoff = s - SvPVX(PL_linestr);
1540 PERL_ARGS_ASSERT_FORCE_VERSION;
1548 while (isDIGIT(*d) || *d == '_' || *d == '.')
1552 start_force(PL_curforce);
1553 curmad('X', newSVpvn(s,d-s));
1556 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1558 s = scan_num(s, &pl_yylval);
1559 version = pl_yylval.opval;
1560 ver = cSVOPx(version)->op_sv;
1561 if (SvPOK(ver) && !SvNIOK(ver)) {
1562 SvUPGRADE(ver, SVt_PVNV);
1563 SvNV_set(ver, str_to_version(ver));
1564 SvNOK_on(ver); /* hint that it is a version */
1567 else if (guessing) {
1570 sv_free(PL_nextwhite); /* let next token collect whitespace */
1572 s = SvPVX(PL_linestr) + startoff;
1580 if (PL_madskills && !version) {
1581 sv_free(PL_nextwhite); /* let next token collect whitespace */
1583 s = SvPVX(PL_linestr) + startoff;
1586 /* NOTE: The parser sees the package name and the VERSION swapped */
1587 start_force(PL_curforce);
1588 NEXTVAL_NEXTTOKE.opval = version;
1596 * Tokenize a quoted string passed in as an SV. It finds the next
1597 * chunk, up to end of string or a backslash. It may make a new
1598 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1603 S_tokeq(pTHX_ SV *sv)
1607 register char *send;
1612 PERL_ARGS_ASSERT_TOKEQ;
1617 s = SvPV_force(sv, len);
1618 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1621 while (s < send && *s != '\\')
1626 if ( PL_hints & HINT_NEW_STRING ) {
1627 pv = newSVpvn_flags(SvPVX_const(pv), len, SVs_TEMP | SvUTF8(sv));
1631 if (s + 1 < send && (s[1] == '\\'))
1632 s++; /* all that, just for this */
1637 SvCUR_set(sv, d - SvPVX_const(sv));
1639 if ( PL_hints & HINT_NEW_STRING )
1640 return new_constant(NULL, 0, "q", sv, pv, "q", 1);
1645 * Now come three functions related to double-quote context,
1646 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1647 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1648 * interact with PL_lex_state, and create fake ( ... ) argument lists
1649 * to handle functions and concatenation.
1650 * They assume that whoever calls them will be setting up a fake
1651 * join call, because each subthing puts a ',' after it. This lets
1654 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1656 * (I'm not sure whether the spurious commas at the end of lcfirst's
1657 * arguments and join's arguments are created or not).
1662 * Assumes that pl_yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1664 * Pattern matching will set PL_lex_op to the pattern-matching op to
1665 * make (we return THING if pl_yylval.ival is OP_NULL, PMFUNC otherwise).
1667 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1669 * Everything else becomes a FUNC.
1671 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1672 * had an OP_CONST or OP_READLINE). This just sets us up for a
1673 * call to S_sublex_push().
1677 S_sublex_start(pTHX)
1680 register const I32 op_type = pl_yylval.ival;
1682 if (op_type == OP_NULL) {
1683 pl_yylval.opval = PL_lex_op;
1687 if (op_type == OP_CONST || op_type == OP_READLINE) {
1688 SV *sv = tokeq(PL_lex_stuff);
1690 if (SvTYPE(sv) == SVt_PVIV) {
1691 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1693 const char * const p = SvPV_const(sv, len);
1694 SV * const nsv = newSVpvn_flags(p, len, SvUTF8(sv));
1698 pl_yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1699 PL_lex_stuff = NULL;
1700 /* Allow <FH> // "foo" */
1701 if (op_type == OP_READLINE)
1702 PL_expect = XTERMORDORDOR;
1705 else if (op_type == OP_BACKTICK && PL_lex_op) {
1706 /* readpipe() vas overriden */
1707 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1708 pl_yylval.opval = PL_lex_op;
1710 PL_lex_stuff = NULL;
1714 PL_sublex_info.super_state = PL_lex_state;
1715 PL_sublex_info.sub_inwhat = (U16)op_type;
1716 PL_sublex_info.sub_op = PL_lex_op;
1717 PL_lex_state = LEX_INTERPPUSH;
1721 pl_yylval.opval = PL_lex_op;
1731 * Create a new scope to save the lexing state. The scope will be
1732 * ended in S_sublex_done. Returns a '(', starting the function arguments
1733 * to the uc, lc, etc. found before.
1734 * Sets PL_lex_state to LEX_INTERPCONCAT.
1743 PL_lex_state = PL_sublex_info.super_state;
1744 SAVEBOOL(PL_lex_dojoin);
1745 SAVEI32(PL_lex_brackets);
1746 SAVEI32(PL_lex_casemods);
1747 SAVEI32(PL_lex_starts);
1748 SAVEI8(PL_lex_state);
1749 SAVEVPTR(PL_lex_inpat);
1750 SAVEI16(PL_lex_inwhat);
1751 SAVECOPLINE(PL_curcop);
1752 SAVEPPTR(PL_bufptr);
1753 SAVEPPTR(PL_bufend);
1754 SAVEPPTR(PL_oldbufptr);
1755 SAVEPPTR(PL_oldoldbufptr);
1756 SAVEPPTR(PL_last_lop);
1757 SAVEPPTR(PL_last_uni);
1758 SAVEPPTR(PL_linestart);
1759 SAVESPTR(PL_linestr);
1760 SAVEGENERICPV(PL_lex_brackstack);
1761 SAVEGENERICPV(PL_lex_casestack);
1763 PL_linestr = PL_lex_stuff;
1764 PL_lex_stuff = NULL;
1766 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1767 = SvPVX(PL_linestr);
1768 PL_bufend += SvCUR(PL_linestr);
1769 PL_last_lop = PL_last_uni = NULL;
1770 SAVEFREESV(PL_linestr);
1772 PL_lex_dojoin = FALSE;
1773 PL_lex_brackets = 0;
1774 Newx(PL_lex_brackstack, 120, char);
1775 Newx(PL_lex_casestack, 12, char);
1776 PL_lex_casemods = 0;
1777 *PL_lex_casestack = '\0';
1779 PL_lex_state = LEX_INTERPCONCAT;
1780 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1782 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1783 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1784 PL_lex_inpat = PL_sublex_info.sub_op;
1786 PL_lex_inpat = NULL;
1793 * Restores lexer state after a S_sublex_push.
1800 if (!PL_lex_starts++) {
1801 SV * const sv = newSVpvs("");
1802 if (SvUTF8(PL_linestr))
1804 PL_expect = XOPERATOR;
1805 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1809 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1810 PL_lex_state = LEX_INTERPCASEMOD;
1814 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1815 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1816 PL_linestr = PL_lex_repl;
1818 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1819 PL_bufend += SvCUR(PL_linestr);
1820 PL_last_lop = PL_last_uni = NULL;
1821 SAVEFREESV(PL_linestr);
1822 PL_lex_dojoin = FALSE;
1823 PL_lex_brackets = 0;
1824 PL_lex_casemods = 0;
1825 *PL_lex_casestack = '\0';
1827 if (SvEVALED(PL_lex_repl)) {
1828 PL_lex_state = LEX_INTERPNORMAL;
1830 /* we don't clear PL_lex_repl here, so that we can check later
1831 whether this is an evalled subst; that means we rely on the
1832 logic to ensure sublex_done() is called again only via the
1833 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1836 PL_lex_state = LEX_INTERPCONCAT;
1846 PL_endwhite = newSVpvs("");
1847 sv_catsv(PL_endwhite, PL_thiswhite);
1851 sv_setpvs(PL_thistoken,"");
1853 PL_realtokenstart = -1;
1857 PL_bufend = SvPVX(PL_linestr);
1858 PL_bufend += SvCUR(PL_linestr);
1859 PL_expect = XOPERATOR;
1860 PL_sublex_info.sub_inwhat = 0;
1868 Extracts a pattern, double-quoted string, or transliteration. This
1871 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
1872 processing a pattern (PL_lex_inpat is true), a transliteration
1873 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
1875 Returns a pointer to the character scanned up to. If this is
1876 advanced from the start pointer supplied (i.e. if anything was
1877 successfully parsed), will leave an OP for the substring scanned
1878 in pl_yylval. Caller must intuit reason for not parsing further
1879 by looking at the next characters herself.
1883 double-quoted style: \r and \n
1884 regexp special ones: \D \s
1887 case and quoting: \U \Q \E
1888 stops on @ and $, but not for $ as tail anchor
1890 In transliterations:
1891 characters are VERY literal, except for - not at the start or end
1892 of the string, which indicates a range. If the range is in bytes,
1893 scan_const expands the range to the full set of intermediate
1894 characters. If the range is in utf8, the hyphen is replaced with
1895 a certain range mark which will be handled by pmtrans() in op.c.
1897 In double-quoted strings:
1899 double-quoted style: \r and \n
1901 deprecated backrefs: \1 (in substitution replacements)
1902 case and quoting: \U \Q \E
1905 scan_const does *not* construct ops to handle interpolated strings.
1906 It stops processing as soon as it finds an embedded $ or @ variable
1907 and leaves it to the caller to work out what's going on.
1909 embedded arrays (whether in pattern or not) could be:
1910 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1912 $ in double-quoted strings must be the symbol of an embedded scalar.
1914 $ in pattern could be $foo or could be tail anchor. Assumption:
1915 it's a tail anchor if $ is the last thing in the string, or if it's
1916 followed by one of "()| \r\n\t"
1918 \1 (backreferences) are turned into $1
1920 The structure of the code is
1921 while (there's a character to process) {
1922 handle transliteration ranges
1923 skip regexp comments /(?#comment)/ and codes /(?{code})/
1924 skip #-initiated comments in //x patterns
1925 check for embedded arrays
1926 check for embedded scalars
1928 leave intact backslashes from leaveit (below)
1929 deprecate \1 in substitution replacements
1930 handle string-changing backslashes \l \U \Q \E, etc.
1931 switch (what was escaped) {
1932 handle \- in a transliteration (becomes a literal -)
1933 handle \132 (octal characters)
1934 handle \x15 and \x{1234} (hex characters)
1935 handle \N{name} (named characters)
1936 handle \cV (control characters)
1937 handle printf-style backslashes (\f, \r, \n, etc)
1939 } (end if backslash)
1940 } (end while character to read)
1945 S_scan_const(pTHX_ char *start)
1948 register char *send = PL_bufend; /* end of the constant */
1949 SV *sv = newSV(send - start); /* sv for the constant */
1950 register char *s = start; /* start of the constant */
1951 register char *d = SvPVX(sv); /* destination for copies */
1952 bool dorange = FALSE; /* are we in a translit range? */
1953 bool didrange = FALSE; /* did we just finish a range? */
1954 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1955 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1958 UV literal_endpoint = 0;
1959 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
1962 PERL_ARGS_ASSERT_SCAN_CONST;
1964 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1965 /* If we are doing a trans and we know we want UTF8 set expectation */
1966 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1967 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1971 while (s < send || dorange) {
1972 /* get transliterations out of the way (they're most literal) */
1973 if (PL_lex_inwhat == OP_TRANS) {
1974 /* expand a range A-Z to the full set of characters. AIE! */
1976 I32 i; /* current expanded character */
1977 I32 min; /* first character in range */
1978 I32 max; /* last character in range */
1989 char * const c = (char*)utf8_hop((U8*)d, -1);
1993 *c = (char)UTF_TO_NATIVE(0xff);
1994 /* mark the range as done, and continue */
2000 i = d - SvPVX_const(sv); /* remember current offset */
2003 SvLEN(sv) + (has_utf8 ?
2004 (512 - UTF_CONTINUATION_MARK +
2007 /* How many two-byte within 0..255: 128 in UTF-8,
2008 * 96 in UTF-8-mod. */
2010 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
2012 d = SvPVX(sv) + i; /* refresh d after realloc */
2016 for (j = 0; j <= 1; j++) {
2017 char * const c = (char*)utf8_hop((U8*)d, -1);
2018 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
2024 max = (U8)0xff; /* only to \xff */
2025 uvmax = uv; /* \x{100} to uvmax */
2027 d = c; /* eat endpoint chars */
2032 d -= 2; /* eat the first char and the - */
2033 min = (U8)*d; /* first char in range */
2034 max = (U8)d[1]; /* last char in range */
2041 "Invalid range \"%c-%c\" in transliteration operator",
2042 (char)min, (char)max);
2046 if (literal_endpoint == 2 &&
2047 ((isLOWER(min) && isLOWER(max)) ||
2048 (isUPPER(min) && isUPPER(max)))) {
2050 for (i = min; i <= max; i++)
2052 *d++ = NATIVE_TO_NEED(has_utf8,i);
2054 for (i = min; i <= max; i++)
2056 *d++ = NATIVE_TO_NEED(has_utf8,i);
2061 for (i = min; i <= max; i++)
2064 const U8 ch = (U8)NATIVE_TO_UTF(i);
2065 if (UNI_IS_INVARIANT(ch))
2068 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
2069 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
2078 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
2080 *d++ = (char)UTF_TO_NATIVE(0xff);
2082 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
2086 /* mark the range as done, and continue */
2090 literal_endpoint = 0;
2095 /* range begins (ignore - as first or last char) */
2096 else if (*s == '-' && s+1 < send && s != start) {
2098 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
2105 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
2115 literal_endpoint = 0;
2116 native_range = TRUE;
2121 /* if we get here, we're not doing a transliteration */
2123 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2124 except for the last char, which will be done separately. */
2125 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
2127 while (s+1 < send && *s != ')')
2128 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2130 else if (s[2] == '{' /* This should match regcomp.c */
2131 || (s[2] == '?' && s[3] == '{'))
2134 char *regparse = s + (s[2] == '{' ? 3 : 4);
2137 while (count && (c = *regparse)) {
2138 if (c == '\\' && regparse[1])
2146 if (*regparse != ')')
2147 regparse--; /* Leave one char for continuation. */
2148 while (s < regparse)
2149 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2153 /* likewise skip #-initiated comments in //x patterns */
2154 else if (*s == '#' && PL_lex_inpat &&
2155 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2156 while (s+1 < send && *s != '\n')
2157 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2160 /* check for embedded arrays
2161 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2163 else if (*s == '@' && s[1]) {
2164 if (isALNUM_lazy_if(s+1,UTF))
2166 if (strchr(":'{$", s[1]))
2168 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2169 break; /* in regexp, neither @+ nor @- are interpolated */
2172 /* check for embedded scalars. only stop if we're sure it's a
2175 else if (*s == '$') {
2176 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
2178 if (s + 1 < send && !strchr("()| \r\n\t", s[1])) {
2179 if (s[1] == '\\' && ckWARN(WARN_AMBIGUOUS)) {
2180 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
2181 "Possible unintended interpolation of $\\ in regex");
2183 break; /* in regexp, $ might be tail anchor */
2187 /* End of else if chain - OP_TRANS rejoin rest */
2190 if (*s == '\\' && s+1 < send) {
2193 /* deprecate \1 in strings and substitution replacements */
2194 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2195 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2197 if (ckWARN(WARN_SYNTAX))
2198 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2203 /* string-change backslash escapes */
2204 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2208 /* skip any other backslash escapes in a pattern */
2209 else if (PL_lex_inpat) {
2210 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2211 goto default_action;
2214 /* if we get here, it's either a quoted -, or a digit */
2217 /* quoted - in transliterations */
2219 if (PL_lex_inwhat == OP_TRANS) {
2226 if ((isALPHA(*s) || isDIGIT(*s)) &&
2228 Perl_warner(aTHX_ packWARN(WARN_MISC),
2229 "Unrecognized escape \\%c passed through",
2231 /* default action is to copy the quoted character */
2232 goto default_action;
2235 /* \132 indicates an octal constant */
2236 case '0': case '1': case '2': case '3':
2237 case '4': case '5': case '6': case '7':
2241 uv = grok_oct(s, &len, &flags, NULL);
2244 goto NUM_ESCAPE_INSERT;
2246 /* \x24 indicates a hex constant */
2250 char* const e = strchr(s, '}');
2251 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2252 PERL_SCAN_DISALLOW_PREFIX;
2257 yyerror("Missing right brace on \\x{}");
2261 uv = grok_hex(s, &len, &flags, NULL);
2267 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2268 uv = grok_hex(s, &len, &flags, NULL);
2274 /* Insert oct or hex escaped character.
2275 * There will always enough room in sv since such
2276 * escapes will be longer than any UTF-8 sequence
2277 * they can end up as. */
2279 /* We need to map to chars to ASCII before doing the tests
2282 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2283 if (!has_utf8 && uv > 255) {
2284 /* Might need to recode whatever we have
2285 * accumulated so far if it contains any
2288 * (Can't we keep track of that and avoid
2289 * this rescan? --jhi)
2293 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2294 if (!NATIVE_IS_INVARIANT(*c)) {
2299 const STRLEN offset = d - SvPVX_const(sv);
2301 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2305 while (src >= (const U8 *)SvPVX_const(sv)) {
2306 if (!NATIVE_IS_INVARIANT(*src)) {
2307 const U8 ch = NATIVE_TO_ASCII(*src);
2308 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2309 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2319 if (has_utf8 || uv > 255) {
2320 d = (char*)uvchr_to_utf8((U8*)d, uv);
2322 if (PL_lex_inwhat == OP_TRANS &&
2323 PL_sublex_info.sub_op) {
2324 PL_sublex_info.sub_op->op_private |=
2325 (PL_lex_repl ? OPpTRANS_FROM_UTF
2329 if (uv > 255 && !dorange)
2330 native_range = FALSE;
2342 /* \N{LATIN SMALL LETTER A} is a named character */
2346 char* e = strchr(s, '}');
2352 yyerror("Missing right brace on \\N{}");
2356 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2358 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2359 PERL_SCAN_DISALLOW_PREFIX;
2362 uv = grok_hex(s, &len, &flags, NULL);
2363 if ( e > s && len != (STRLEN)(e - s) ) {
2367 goto NUM_ESCAPE_INSERT;
2369 res = newSVpvn(s + 1, e - s - 1);
2370 res = new_constant( NULL, 0, "charnames",
2371 res, NULL, s - 2, e - s + 3 );
2373 sv_utf8_upgrade(res);
2374 str = SvPV_const(res,len);
2375 #ifdef EBCDIC_NEVER_MIND
2376 /* charnames uses pack U and that has been
2377 * recently changed to do the below uni->native
2378 * mapping, so this would be redundant (and wrong,
2379 * the code point would be doubly converted).
2380 * But leave this in just in case the pack U change
2381 * gets revoked, but the semantics is still
2382 * desireable for charnames. --jhi */
2384 UV uv = utf8_to_uvchr((const U8*)str, 0);
2387 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2389 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2390 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2391 str = SvPV_const(res, len);
2395 if (!has_utf8 && SvUTF8(res)) {
2396 const char * const ostart = SvPVX_const(sv);
2397 SvCUR_set(sv, d - ostart);
2400 sv_utf8_upgrade(sv);
2401 /* this just broke our allocation above... */
2402 SvGROW(sv, (STRLEN)(send - start));
2403 d = SvPVX(sv) + SvCUR(sv);
2406 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2407 const char * const odest = SvPVX_const(sv);
2409 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2410 d = SvPVX(sv) + (d - odest);
2414 native_range = FALSE; /* \N{} is guessed to be Unicode */
2416 Copy(str, d, len, char);
2423 yyerror("Missing braces on \\N{}");
2426 /* \c is a control character */
2435 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2438 yyerror("Missing control char name in \\c");
2442 /* printf-style backslashes, formfeeds, newlines, etc */
2444 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2447 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2450 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2453 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2456 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2459 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2462 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2468 } /* end if (backslash) */
2475 /* If we started with encoded form, or already know we want it
2476 and then encode the next character */
2477 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2479 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2480 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2483 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2484 const STRLEN off = d - SvPVX_const(sv);
2485 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2487 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2490 if (uv > 255 && !dorange)
2491 native_range = FALSE;
2495 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2497 } /* while loop to process each character */
2499 /* terminate the string and set up the sv */
2501 SvCUR_set(sv, d - SvPVX_const(sv));
2502 if (SvCUR(sv) >= SvLEN(sv))
2503 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2506 if (PL_encoding && !has_utf8) {
2507 sv_recode_to_utf8(sv, PL_encoding);
2513 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2514 PL_sublex_info.sub_op->op_private |=
2515 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2519 /* shrink the sv if we allocated more than we used */
2520 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2521 SvPV_shrink_to_cur(sv);
2524 /* return the substring (via pl_yylval) only if we parsed anything */
2525 if (s > PL_bufptr) {
2526 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) {
2527 const char *const key = PL_lex_inpat ? "qr" : "q";
2528 const STRLEN keylen = PL_lex_inpat ? 2 : 1;
2532 if (PL_lex_inwhat == OP_TRANS) {
2535 } else if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) {
2543 sv = S_new_constant(aTHX_ start, s - start, key, keylen, sv, NULL,
2546 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2553 * Returns TRUE if there's more to the expression (e.g., a subscript),
2556 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2558 * ->[ and ->{ return TRUE
2559 * { and [ outside a pattern are always subscripts, so return TRUE
2560 * if we're outside a pattern and it's not { or [, then return FALSE
2561 * if we're in a pattern and the first char is a {
2562 * {4,5} (any digits around the comma) returns FALSE
2563 * if we're in a pattern and the first char is a [
2565 * [SOMETHING] has a funky algorithm to decide whether it's a
2566 * character class or not. It has to deal with things like
2567 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2568 * anything else returns TRUE
2571 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2574 S_intuit_more(pTHX_ register char *s)
2578 PERL_ARGS_ASSERT_INTUIT_MORE;
2580 if (PL_lex_brackets)
2582 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2584 if (*s != '{' && *s != '[')
2589 /* In a pattern, so maybe we have {n,m}. */
2606 /* On the other hand, maybe we have a character class */
2609 if (*s == ']' || *s == '^')
2612 /* this is terrifying, and it works */
2613 int weight = 2; /* let's weigh the evidence */
2615 unsigned char un_char = 255, last_un_char;
2616 const char * const send = strchr(s,']');
2617 char tmpbuf[sizeof PL_tokenbuf * 4];
2619 if (!send) /* has to be an expression */
2622 Zero(seen,256,char);
2625 else if (isDIGIT(*s)) {
2627 if (isDIGIT(s[1]) && s[2] == ']')
2633 for (; s < send; s++) {
2634 last_un_char = un_char;
2635 un_char = (unsigned char)*s;
2640 weight -= seen[un_char] * 10;
2641 if (isALNUM_lazy_if(s+1,UTF)) {
2643 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2644 len = (int)strlen(tmpbuf);
2645 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2650 else if (*s == '$' && s[1] &&
2651 strchr("[#!%*<>()-=",s[1])) {
2652 if (/*{*/ strchr("])} =",s[2]))
2661 if (strchr("wds]",s[1]))
2663 else if (seen[(U8)'\''] || seen[(U8)'"'])
2665 else if (strchr("rnftbxcav",s[1]))
2667 else if (isDIGIT(s[1])) {
2669 while (s[1] && isDIGIT(s[1]))
2679 if (strchr("aA01! ",last_un_char))
2681 if (strchr("zZ79~",s[1]))
2683 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2684 weight -= 5; /* cope with negative subscript */
2687 if (!isALNUM(last_un_char)
2688 && !(last_un_char == '$' || last_un_char == '@'
2689 || last_un_char == '&')
2690 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2695 if (keyword(tmpbuf, d - tmpbuf, 0))
2698 if (un_char == last_un_char + 1)
2700 weight -= seen[un_char];
2705 if (weight >= 0) /* probably a character class */
2715 * Does all the checking to disambiguate
2717 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2718 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2720 * First argument is the stuff after the first token, e.g. "bar".
2722 * Not a method if bar is a filehandle.
2723 * Not a method if foo is a subroutine prototyped to take a filehandle.
2724 * Not a method if it's really "Foo $bar"
2725 * Method if it's "foo $bar"
2726 * Not a method if it's really "print foo $bar"
2727 * Method if it's really "foo package::" (interpreted as package->foo)
2728 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2729 * Not a method if bar is a filehandle or package, but is quoted with
2734 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2737 char *s = start + (*start == '$');
2738 char tmpbuf[sizeof PL_tokenbuf];
2745 PERL_ARGS_ASSERT_INTUIT_METHOD;
2748 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2752 const char *proto = SvPVX_const(cv);
2763 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2764 /* start is the beginning of the possible filehandle/object,
2765 * and s is the end of it
2766 * tmpbuf is a copy of it
2769 if (*start == '$') {
2770 if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
2771 isUPPER(*PL_tokenbuf))
2774 len = start - SvPVX(PL_linestr);
2778 start = SvPVX(PL_linestr) + len;
2782 return *s == '(' ? FUNCMETH : METHOD;
2784 if (!keyword(tmpbuf, len, 0)) {
2785 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2789 soff = s - SvPVX(PL_linestr);
2793 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2794 if (indirgv && GvCVu(indirgv))
2796 /* filehandle or package name makes it a method */
2797 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
2799 soff = s - SvPVX(PL_linestr);
2802 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2803 return 0; /* no assumptions -- "=>" quotes bearword */
2805 start_force(PL_curforce);
2806 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2807 newSVpvn(tmpbuf,len));
2808 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2810 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2815 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2817 return *s == '(' ? FUNCMETH : METHOD;
2823 /* Encoded script support. filter_add() effectively inserts a
2824 * 'pre-processing' function into the current source input stream.
2825 * Note that the filter function only applies to the current source file
2826 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2828 * The datasv parameter (which may be NULL) can be used to pass
2829 * private data to this instance of the filter. The filter function
2830 * can recover the SV using the FILTER_DATA macro and use it to
2831 * store private buffers and state information.
2833 * The supplied datasv parameter is upgraded to a PVIO type
2834 * and the IoDIRP/IoANY field is used to store the function pointer,
2835 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2836 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2837 * private use must be set using malloc'd pointers.
2841 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2850 if (!PL_rsfp_filters)
2851 PL_rsfp_filters = newAV();
2854 SvUPGRADE(datasv, SVt_PVIO);
2855 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2856 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2857 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2858 FPTR2DPTR(void *, IoANY(datasv)),
2859 SvPV_nolen(datasv)));
2860 av_unshift(PL_rsfp_filters, 1);
2861 av_store(PL_rsfp_filters, 0, datasv) ;
2866 /* Delete most recently added instance of this filter function. */
2868 Perl_filter_del(pTHX_ filter_t funcp)
2873 PERL_ARGS_ASSERT_FILTER_DEL;
2876 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2877 FPTR2DPTR(void*, funcp)));
2879 if (!PL_parser || !PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2881 /* if filter is on top of stack (usual case) just pop it off */
2882 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2883 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2884 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2885 IoANY(datasv) = (void *)NULL;
2886 sv_free(av_pop(PL_rsfp_filters));
2890 /* we need to search for the correct entry and clear it */
2891 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2895 /* Invoke the idxth filter function for the current rsfp. */
2896 /* maxlen 0 = read one text line */
2898 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2903 /* This API is bad. It should have been using unsigned int for maxlen.
2904 Not sure if we want to change the API, but if not we should sanity
2905 check the value here. */
2906 const unsigned int correct_length
2915 PERL_ARGS_ASSERT_FILTER_READ;
2917 if (!PL_parser || !PL_rsfp_filters)
2919 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2920 /* Provide a default input filter to make life easy. */
2921 /* Note that we append to the line. This is handy. */
2922 DEBUG_P(PerlIO_printf(Perl_debug_log,
2923 "filter_read %d: from rsfp\n", idx));
2924 if (correct_length) {
2927 const int old_len = SvCUR(buf_sv);
2929 /* ensure buf_sv is large enough */
2930 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2931 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2932 correct_length)) <= 0) {
2933 if (PerlIO_error(PL_rsfp))
2934 return -1; /* error */
2936 return 0 ; /* end of file */
2938 SvCUR_set(buf_sv, old_len + len) ;
2941 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2942 if (PerlIO_error(PL_rsfp))
2943 return -1; /* error */
2945 return 0 ; /* end of file */
2948 return SvCUR(buf_sv);
2950 /* Skip this filter slot if filter has been deleted */
2951 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2952 DEBUG_P(PerlIO_printf(Perl_debug_log,
2953 "filter_read %d: skipped (filter deleted)\n",
2955 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2957 /* Get function pointer hidden within datasv */
2958 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2959 DEBUG_P(PerlIO_printf(Perl_debug_log,
2960 "filter_read %d: via function %p (%s)\n",
2961 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2962 /* Call function. The function is expected to */
2963 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2964 /* Return: <0:error, =0:eof, >0:not eof */
2965 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2969 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2973 PERL_ARGS_ASSERT_FILTER_GETS;
2975 #ifdef PERL_CR_FILTER
2976 if (!PL_rsfp_filters) {
2977 filter_add(S_cr_textfilter,NULL);
2980 if (PL_rsfp_filters) {
2982 SvCUR_set(sv, 0); /* start with empty line */
2983 if (FILTER_READ(0, sv, 0) > 0)
2984 return ( SvPVX(sv) ) ;
2989 return (sv_gets(sv, fp, append));
2993 S_find_in_my_stash(pTHX_ const char *pkgname, STRLEN len)
2998 PERL_ARGS_ASSERT_FIND_IN_MY_STASH;
3000 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
3004 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
3005 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
3007 return GvHV(gv); /* Foo:: */
3010 /* use constant CLASS => 'MyClass' */
3011 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
3012 if (gv && GvCV(gv)) {
3013 SV * const sv = cv_const_sv(GvCV(gv));
3015 pkgname = SvPV_const(sv, len);
3018 return gv_stashpvn(pkgname, len, 0);
3022 * S_readpipe_override
3023 * Check whether readpipe() is overriden, and generates the appropriate
3024 * optree, provided sublex_start() is called afterwards.
3027 S_readpipe_override(pTHX)
3030 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
3031 pl_yylval.ival = OP_BACKTICK;
3033 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
3035 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
3036 && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
3037 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
3039 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
3040 append_elem(OP_LIST,
3041 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
3042 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
3049 * The intent of this yylex wrapper is to minimize the changes to the
3050 * tokener when we aren't interested in collecting madprops. It remains
3051 * to be seen how successful this strategy will be...
3058 char *s = PL_bufptr;
3060 /* make sure PL_thiswhite is initialized */
3064 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
3065 if (PL_pending_ident)
3066 return S_pending_ident(aTHX);
3068 /* previous token ate up our whitespace? */
3069 if (!PL_lasttoke && PL_nextwhite) {
3070 PL_thiswhite = PL_nextwhite;
3074 /* isolate the token, and figure out where it is without whitespace */
3075 PL_realtokenstart = -1;
3079 assert(PL_curforce < 0);
3081 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
3082 if (!PL_thistoken) {
3083 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
3084 PL_thistoken = newSVpvs("");
3086 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
3087 PL_thistoken = newSVpvn(tstart, s - tstart);
3090 if (PL_thismad) /* install head */
3091 CURMAD('X', PL_thistoken);
3094 /* last whitespace of a sublex? */
3095 if (optype == ')' && PL_endwhite) {
3096 CURMAD('X', PL_endwhite);
3101 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
3102 if (!PL_thiswhite && !PL_endwhite && !optype) {
3103 sv_free(PL_thistoken);
3108 /* put off final whitespace till peg */
3109 if (optype == ';' && !PL_rsfp) {
3110 PL_nextwhite = PL_thiswhite;
3113 else if (PL_thisopen) {
3114 CURMAD('q', PL_thisopen);
3116 sv_free(PL_thistoken);
3120 /* Store actual token text as madprop X */
3121 CURMAD('X', PL_thistoken);
3125 /* add preceding whitespace as madprop _ */
3126 CURMAD('_', PL_thiswhite);
3130 /* add quoted material as madprop = */
3131 CURMAD('=', PL_thisstuff);
3135 /* add terminating quote as madprop Q */
3136 CURMAD('Q', PL_thisclose);
3140 /* special processing based on optype */
3144 /* opval doesn't need a TOKEN since it can already store mp */
3154 if (pl_yylval.opval)
3155 append_madprops(PL_thismad, pl_yylval.opval, 0);
3163 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3172 /* remember any fake bracket that lexer is about to discard */
3173 if (PL_lex_brackets == 1 &&
3174 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3177 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3180 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3181 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3184 break; /* don't bother looking for trailing comment */
3193 /* attach a trailing comment to its statement instead of next token */
3197 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3199 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3201 if (*s == '\n' || *s == '#') {
3202 while (s < PL_bufend && *s != '\n')
3206 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3207 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3224 /* Create new token struct. Note: opvals return early above. */
3225 pl_yylval.tkval = newTOKEN(optype, pl_yylval, PL_thismad);
3232 S_tokenize_use(pTHX_ int is_use, char *s) {
3235 PERL_ARGS_ASSERT_TOKENIZE_USE;
3237 if (PL_expect != XSTATE)
3238 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3239 is_use ? "use" : "no"));
3241 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3242 s = force_version(s, TRUE);
3243 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3244 start_force(PL_curforce);
3245 NEXTVAL_NEXTTOKE.opval = NULL;
3248 else if (*s == 'v') {
3249 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3250 s = force_version(s, FALSE);
3254 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3255 s = force_version(s, FALSE);
3257 pl_yylval.ival = is_use;
3261 static const char* const exp_name[] =
3262 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3263 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3270 Works out what to call the token just pulled out of the input
3271 stream. The yacc parser takes care of taking the ops we return and
3272 stitching them into a tree.
3278 if read an identifier
3279 if we're in a my declaration
3280 croak if they tried to say my($foo::bar)
3281 build the ops for a my() declaration
3282 if it's an access to a my() variable
3283 are we in a sort block?
3284 croak if my($a); $a <=> $b
3285 build ops for access to a my() variable
3286 if in a dq string, and they've said @foo and we can't find @foo
3288 build ops for a bareword
3289 if we already built the token before, use it.
3294 #pragma segment Perl_yylex
3300 register char *s = PL_bufptr;
3305 /* orig_keyword, gvp, and gv are initialized here because
3306 * jump to the label just_a_word_zero can bypass their
3307 * initialization later. */
3308 I32 orig_keyword = 0;
3313 SV* tmp = newSVpvs("");
3314 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3315 (IV)CopLINE(PL_curcop),
3316 lex_state_names[PL_lex_state],
3317 exp_name[PL_expect],
3318 pv_display(tmp, s, strlen(s), 0, 60));
3321 /* check if there's an identifier for us to look at */
3322 if (PL_pending_ident)
3323 return REPORT(S_pending_ident(aTHX));
3325 /* no identifier pending identification */
3327 switch (PL_lex_state) {
3329 case LEX_NORMAL: /* Some compilers will produce faster */
3330 case LEX_INTERPNORMAL: /* code if we comment these out. */
3334 /* when we've already built the next token, just pull it out of the queue */
3338 pl_yylval = PL_nexttoke[PL_lasttoke].next_val;
3340 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3341 PL_nexttoke[PL_lasttoke].next_mad = 0;
3342 if (PL_thismad && PL_thismad->mad_key == '_') {
3343 PL_thiswhite = MUTABLE_SV(PL_thismad->mad_val);
3344 PL_thismad->mad_val = 0;
3345 mad_free(PL_thismad);
3350 PL_lex_state = PL_lex_defer;
3351 PL_expect = PL_lex_expect;
3352 PL_lex_defer = LEX_NORMAL;
3353 if (!PL_nexttoke[PL_lasttoke].next_type)
3358 pl_yylval = PL_nextval[PL_nexttoke];
3360 PL_lex_state = PL_lex_defer;
3361 PL_expect = PL_lex_expect;
3362 PL_lex_defer = LEX_NORMAL;
3366 /* FIXME - can these be merged? */
3367 return(PL_nexttoke[PL_lasttoke].next_type);
3369 return REPORT(PL_nexttype[PL_nexttoke]);
3372 /* interpolated case modifiers like \L \U, including \Q and \E.
3373 when we get here, PL_bufptr is at the \
3375 case LEX_INTERPCASEMOD:
3377 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3378 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3380 /* handle \E or end of string */
3381 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3383 if (PL_lex_casemods) {
3384 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3385 PL_lex_casestack[PL_lex_casemods] = '\0';
3387 if (PL_bufptr != PL_bufend
3388 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3390 PL_lex_state = LEX_INTERPCONCAT;
3393 PL_thistoken = newSVpvs("\\E");
3399 while (PL_bufptr != PL_bufend &&
3400 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3402 PL_thiswhite = newSVpvs("");
3403 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3407 if (PL_bufptr != PL_bufend)
3410 PL_lex_state = LEX_INTERPCONCAT;
3414 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3415 "### Saw case modifier\n"); });
3417 if (s[1] == '\\' && s[2] == 'E') {
3420 PL_thiswhite = newSVpvs("");
3421 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3424 PL_lex_state = LEX_INTERPCONCAT;
3429 if (!PL_madskills) /* when just compiling don't need correct */
3430 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3431 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3432 if ((*s == 'L' || *s == 'U') &&
3433 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3434 PL_lex_casestack[--PL_lex_casemods] = '\0';
3437 if (PL_lex_casemods > 10)
3438 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3439 PL_lex_casestack[PL_lex_casemods++] = *s;
3440 PL_lex_casestack[PL_lex_casemods] = '\0';
3441 PL_lex_state = LEX_INTERPCONCAT;
3442 start_force(PL_curforce);
3443 NEXTVAL_NEXTTOKE.ival = 0;
3445 start_force(PL_curforce);
3447 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3449 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3451 NEXTVAL_NEXTTOKE.ival = OP_LC;
3453 NEXTVAL_NEXTTOKE.ival = OP_UC;
3455 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3457 Perl_croak(aTHX_ "panic: yylex");
3459 SV* const tmpsv = newSVpvs("\\ ");
3460 /* replace the space with the character we want to escape
3462 SvPVX(tmpsv)[1] = *s;
3468 if (PL_lex_starts) {
3474 sv_free(PL_thistoken);
3475 PL_thistoken = newSVpvs("");
3478 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3479 if (PL_lex_casemods == 1 && PL_lex_inpat)
3488 case LEX_INTERPPUSH:
3489 return REPORT(sublex_push());
3491 case LEX_INTERPSTART:
3492 if (PL_bufptr == PL_bufend)
3493 return REPORT(sublex_done());
3494 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3495 "### Interpolated variable\n"); });
3497 PL_lex_dojoin = (*PL_bufptr == '@');
3498 PL_lex_state = LEX_INTERPNORMAL;
3499 if (PL_lex_dojoin) {
3500 start_force(PL_curforce);
3501 NEXTVAL_NEXTTOKE.ival = 0;
3503 start_force(PL_curforce);
3504 force_ident("\"", '$');
3505 start_force(PL_curforce);
3506 NEXTVAL_NEXTTOKE.ival = 0;
3508 start_force(PL_curforce);
3509 NEXTVAL_NEXTTOKE.ival = 0;
3511 start_force(PL_curforce);
3512 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3515 if (PL_lex_starts++) {
3520 sv_free(PL_thistoken);
3521 PL_thistoken = newSVpvs("");
3524 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3525 if (!PL_lex_casemods && PL_lex_inpat)
3532 case LEX_INTERPENDMAYBE:
3533 if (intuit_more(PL_bufptr)) {
3534 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3540 if (PL_lex_dojoin) {
3541 PL_lex_dojoin = FALSE;
3542 PL_lex_state = LEX_INTERPCONCAT;
3546 sv_free(PL_thistoken);
3547 PL_thistoken = newSVpvs("");
3552 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3553 && SvEVALED(PL_lex_repl))
3555 if (PL_bufptr != PL_bufend)
3556 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3560 case LEX_INTERPCONCAT:
3562 if (PL_lex_brackets)
3563 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3565 if (PL_bufptr == PL_bufend)
3566 return REPORT(sublex_done());
3568 if (SvIVX(PL_linestr) == '\'') {
3569 SV *sv = newSVsv(PL_linestr);
3572 else if ( PL_hints & HINT_NEW_RE )
3573 sv = new_constant(NULL, 0, "qr", sv, sv, "q", 1);
3574 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3578 s = scan_const(PL_bufptr);
3580 PL_lex_state = LEX_INTERPCASEMOD;
3582 PL_lex_state = LEX_INTERPSTART;
3585 if (s != PL_bufptr) {
3586 start_force(PL_curforce);
3588 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3590 NEXTVAL_NEXTTOKE = pl_yylval;
3593 if (PL_lex_starts++) {
3597 sv_free(PL_thistoken);
3598 PL_thistoken = newSVpvs("");
3601 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3602 if (!PL_lex_casemods && PL_lex_inpat)
3615 PL_lex_state = LEX_NORMAL;
3616 s = scan_formline(PL_bufptr);
3617 if (!PL_lex_formbrack)
3623 PL_oldoldbufptr = PL_oldbufptr;
3629 sv_free(PL_thistoken);
3632 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3636 if (isIDFIRST_lazy_if(s,UTF))
3638 len = UTF ? Perl_utf8_length(aTHX_ (U8 *) PL_linestart, (U8 *) s) : (STRLEN) (s - PL_linestart);
3639 Perl_croak(aTHX_ "Unrecognized character \\x%02X in column %d", *s & 255, (int) len + 1);
3642 goto fake_eof; /* emulate EOF on ^D or ^Z */
3651 if (PL_lex_brackets) {
3652 yyerror((const char *)
3654 ? "Format not terminated"
3655 : "Missing right curly or square bracket"));
3657 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3658 "### Tokener got EOF\n");
3662 if (s++ < PL_bufend)
3663 goto retry; /* ignore stray nulls */
3666 if (!PL_in_eval && !PL_preambled) {
3667 PL_preambled = TRUE;
3673 /* Generate a string of Perl code to load the debugger.
3674 * If PERL5DB is set, it will return the contents of that,
3675 * otherwise a compile-time require of perl5db.pl. */
3677 const char * const pdb = PerlEnv_getenv("PERL5DB");
3680 sv_setpv(PL_linestr, pdb);
3681 sv_catpvs(PL_linestr,";");
3683 SETERRNO(0,SS_NORMAL);
3684 sv_setpvs(PL_linestr, "BEGIN { require 'perl5db.pl' };");
3687 sv_setpvs(PL_linestr,"");
3688 if (PL_preambleav) {
3689 SV **svp = AvARRAY(PL_preambleav);
3690 SV **const end = svp + AvFILLp(PL_preambleav);
3692 sv_catsv(PL_linestr, *svp);
3694 sv_catpvs(PL_linestr, ";");
3696 sv_free(MUTABLE_SV(PL_preambleav));
3697 PL_preambleav = NULL;
3700 sv_catpvs(PL_linestr,
3701 "use feature ':5." STRINGIFY(PERL_VERSION) "';");
3702 if (PL_minus_n || PL_minus_p) {
3703 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3705 sv_catpvs(PL_linestr,"chomp;");
3708 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3709 || *PL_splitstr == '"')
3710 && strchr(PL_splitstr + 1, *PL_splitstr))
3711 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3713 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3714 bytes can be used as quoting characters. :-) */
3715 const char *splits = PL_splitstr;
3716 sv_catpvs(PL_linestr, "our @F=split(q\0");
3719 if (*splits == '\\')
3720 sv_catpvn(PL_linestr, splits, 1);
3721 sv_catpvn(PL_linestr, splits, 1);
3722 } while (*splits++);
3723 /* This loop will embed the trailing NUL of
3724 PL_linestr as the last thing it does before
3726 sv_catpvs(PL_linestr, ");");
3730 sv_catpvs(PL_linestr,"our @F=split(' ');");
3733 sv_catpvs(PL_linestr, "\n");
3734 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3735 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3736 PL_last_lop = PL_last_uni = NULL;
3737 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
3738 update_debugger_info(PL_linestr, NULL, 0);
3742 bof = PL_rsfp ? TRUE : FALSE;
3743 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3746 PL_realtokenstart = -1;
3749 if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3750 PerlIO_clearerr(PL_rsfp);
3752 (void)PerlIO_close(PL_rsfp);
3754 PL_doextract = FALSE;
3756 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3762 sv_setpvs(PL_linestr, ";}continue{print;}");
3764 sv_setpvs(PL_linestr, ";}");
3765 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3766 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3767 PL_last_lop = PL_last_uni = NULL;
3768 PL_minus_n = PL_minus_p = 0;
3771 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3772 PL_last_lop = PL_last_uni = NULL;
3773 sv_setpvs(PL_linestr,"");
3774 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3776 /* If it looks like the start of a BOM or raw UTF-16,
3777 * check if it in fact is. */
3783 #ifdef PERLIO_IS_STDIO
3784 # ifdef __GNU_LIBRARY__
3785 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3786 # define FTELL_FOR_PIPE_IS_BROKEN
3790 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3791 # define FTELL_FOR_PIPE_IS_BROKEN
3796 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3798 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3799 s = swallow_bom((U8*)s);
3803 /* Incest with pod. */
3806 sv_catsv(PL_thiswhite, PL_linestr);
3808 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
3809 sv_setpvs(PL_linestr, "");
3810 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3811 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3812 PL_last_lop = PL_last_uni = NULL;
3813 PL_doextract = FALSE;
3817 } while (PL_doextract);
3818 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3819 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
3820 update_debugger_info(PL_linestr, NULL, 0);
3821 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3822 PL_last_lop = PL_last_uni = NULL;
3823 if (CopLINE(PL_curcop) == 1) {
3824 while (s < PL_bufend && isSPACE(*s))
3826 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3830 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3834 if (*s == '#' && *(s+1) == '!')
3836 #ifdef ALTERNATE_SHEBANG
3838 static char const as[] = ALTERNATE_SHEBANG;
3839 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3840 d = s + (sizeof(as) - 1);
3842 #endif /* ALTERNATE_SHEBANG */
3851 while (*d && !isSPACE(*d))
3855 #ifdef ARG_ZERO_IS_SCRIPT
3856 if (ipathend > ipath) {
3858 * HP-UX (at least) sets argv[0] to the script name,
3859 * which makes $^X incorrect. And Digital UNIX and Linux,
3860 * at least, set argv[0] to the basename of the Perl
3861 * interpreter. So, having found "#!", we'll set it right.
3863 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3865 assert(SvPOK(x) || SvGMAGICAL(x));
3866 if (sv_eq(x, CopFILESV(PL_curcop))) {
3867 sv_setpvn(x, ipath, ipathend - ipath);
3873 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3874 const char * const lstart = SvPV_const(x,llen);
3876 bstart += blen - llen;
3877 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3878 sv_setpvn(x, ipath, ipathend - ipath);
3883 TAINT_NOT; /* $^X is always tainted, but that's OK */
3885 #endif /* ARG_ZERO_IS_SCRIPT */
3890 d = instr(s,"perl -");
3892 d = instr(s,"perl");
3894 /* avoid getting into infinite loops when shebang
3895 * line contains "Perl" rather than "perl" */
3897 for (d = ipathend-4; d >= ipath; --d) {
3898 if ((*d == 'p' || *d == 'P')
3899 && !ibcmp(d, "perl", 4))
3909 #ifdef ALTERNATE_SHEBANG
3911 * If the ALTERNATE_SHEBANG on this system starts with a
3912 * character that can be part of a Perl expression, then if
3913 * we see it but not "perl", we're probably looking at the
3914 * start of Perl code, not a request to hand off to some
3915 * other interpreter. Similarly, if "perl" is there, but
3916 * not in the first 'word' of the line, we assume the line
3917 * contains the start of the Perl program.
3919 if (d && *s != '#') {
3920 const char *c = ipath;
3921 while (*c && !strchr("; \t\r\n\f\v#", *c))
3924 d = NULL; /* "perl" not in first word; ignore */
3926 *s = '#'; /* Don't try to parse shebang line */
3928 #endif /* ALTERNATE_SHEBANG */
3929 #ifndef MACOS_TRADITIONAL
3934 !instr(s,"indir") &&
3935 instr(PL_origargv[0],"perl"))
3942 while (s < PL_bufend && isSPACE(*s))
3944 if (s < PL_bufend) {
3945 Newxz(newargv,PL_origargc+3,char*);
3947 while (s < PL_bufend && !isSPACE(*s))
3950 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3953 newargv = PL_origargv;
3956 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3958 Perl_croak(aTHX_ "Can't exec %s", ipath);
3962 while (*d && !isSPACE(*d))
3964 while (SPACE_OR_TAB(*d))
3968 const bool switches_done = PL_doswitches;
3969 const U32 oldpdb = PL_perldb;
3970 const bool oldn = PL_minus_n;
3971 const bool oldp = PL_minus_p;
3975 if (*d1 == 'M' || *d1 == 'm' || *d1 == 'C') {
3976 const char * const m = d1;
3977 while (*d1 && !isSPACE(*d1))
3979 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3982 d1 = moreswitches(d1);
3984 if (PL_doswitches && !switches_done) {
3985 int argc = PL_origargc;
3986 char **argv = PL_origargv;
3989 } while (argc && argv[0][0] == '-' && argv[0][1]);
3990 init_argv_symbols(argc,argv);
3992 if (((PERLDB_LINE || PERLDB_SAVESRC) && !oldpdb) ||
3993 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3994 /* if we have already added "LINE: while (<>) {",
3995 we must not do it again */
3997 sv_setpvs(PL_linestr, "");
3998 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3999 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4000 PL_last_lop = PL_last_uni = NULL;
4001 PL_preambled = FALSE;
4002 if (PERLDB_LINE || PERLDB_SAVESRC)
4003 (void)gv_fetchfile(PL_origfilename);
4010 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4012 PL_lex_state = LEX_FORMLINE;
4017 #ifdef PERL_STRICT_CR
4018 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
4020 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
4022 case ' ': case '\t': case '\f': case 013:
4023 #ifdef MACOS_TRADITIONAL
4027 PL_realtokenstart = -1;
4029 PL_thiswhite = newSVpvs("");
4030 sv_catpvn(PL_thiswhite, s, 1);
4037 PL_realtokenstart = -1;
4041 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
4042 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
4043 /* handle eval qq[#line 1 "foo"\n ...] */
4044 CopLINE_dec(PL_curcop);
4047 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
4049 if (!PL_in_eval || PL_rsfp)
4054 while (d < PL_bufend && *d != '\n')
4058 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4059 Perl_croak(aTHX_ "panic: input overflow");
4062 PL_thiswhite = newSVpvn(s, d - s);
4067 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4069 PL_lex_state = LEX_FORMLINE;
4075 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
4076 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
4079 TOKEN(PEG); /* make sure any #! line is accessible */
4084 /* if (PL_madskills && PL_lex_formbrack) { */
4086 while (d < PL_bufend && *d != '\n')
4090 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4091 Perl_croak(aTHX_ "panic: input overflow");
4092 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
4094 PL_thiswhite = newSVpvs("");
4095 if (CopLINE(PL_curcop) == 1) {
4096 sv_setpvs(PL_thiswhite, "");
4099 sv_catpvn(PL_thiswhite, s, d - s);
4113 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
4121 while (s < PL_bufend && SPACE_OR_TAB(*s))
4124 if (strnEQ(s,"=>",2)) {
4125 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
4126 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
4127 OPERATOR('-'); /* unary minus */
4129 PL_last_uni = PL_oldbufptr;
4131 case 'r': ftst = OP_FTEREAD; break;
4132 case 'w': ftst = OP_FTEWRITE; break;
4133 case 'x': ftst = OP_FTEEXEC; break;
4134 case 'o': ftst = OP_FTEOWNED; break;
4135 case 'R': ftst = OP_FTRREAD; break;
4136 case 'W': ftst = OP_FTRWRITE; break;
4137 case 'X': ftst = OP_FTREXEC; break;
4138 case 'O': ftst = OP_FTROWNED; break;
4139 case 'e': ftst = OP_FTIS; break;
4140 case 'z': ftst = OP_FTZERO; break;
4141 case 's': ftst = OP_FTSIZE; break;
4142 case 'f': ftst = OP_FTFILE; break;
4143 case 'd': ftst = OP_FTDIR; break;
4144 case 'l': ftst = OP_FTLINK; break;
4145 case 'p': ftst = OP_FTPIPE; break;
4146 case 'S': ftst = OP_FTSOCK; break;
4147 case 'u': ftst = OP_FTSUID; break;
4148 case 'g': ftst = OP_FTSGID; break;
4149 case 'k': ftst = OP_FTSVTX; break;
4150 case 'b': ftst = OP_FTBLK; break;
4151 case 'c': ftst = OP_FTCHR; break;
4152 case 't': ftst = OP_FTTTY; break;
4153 case 'T': ftst = OP_FTTEXT; break;
4154 case 'B': ftst = OP_FTBINARY; break;
4155 case 'M': case 'A': case 'C':
4156 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
4158 case 'M': ftst = OP_FTMTIME; break;
4159 case 'A': ftst = OP_FTATIME; break;
4160 case 'C': ftst = OP_FTCTIME; break;
4168 PL_last_lop_op = (OPCODE)ftst;
4169 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4170 "### Saw file test %c\n", (int)tmp);
4175 /* Assume it was a minus followed by a one-letter named
4176 * subroutine call (or a -bareword), then. */
4177 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4178 "### '-%c' looked like a file test but was not\n",
4185 const char tmp = *s++;
4188 if (PL_expect == XOPERATOR)
4193 else if (*s == '>') {
4196 if (isIDFIRST_lazy_if(s,UTF)) {
4197 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4205 if (PL_expect == XOPERATOR)
4208 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4210 OPERATOR('-'); /* unary minus */
4216 const char tmp = *s++;
4219 if (PL_expect == XOPERATOR)
4224 if (PL_expect == XOPERATOR)
4227 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4234 if (PL_expect != XOPERATOR) {
4235 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4236 PL_expect = XOPERATOR;
4237 force_ident(PL_tokenbuf, '*');
4250 if (PL_expect == XOPERATOR) {
4254 PL_tokenbuf[0] = '%';
4255 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4256 sizeof PL_tokenbuf - 1, FALSE);
4257 if (!PL_tokenbuf[1]) {
4260 PL_pending_ident = '%';
4271 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
4278 const char tmp = *s++;
4284 goto just_a_word_zero_gv;
4287 switch (PL_expect) {
4293 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4295 PL_bufptr = s; /* update in case we back off */
4301 PL_expect = XTERMBLOCK;
4304 stuffstart = s - SvPVX(PL_linestr) - 1;
4308 while (isIDFIRST_lazy_if(s,UTF)) {
4311 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4312 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4313 if (tmp < 0) tmp = -tmp;
4327 sv = newSVpvn(s, len);
4329 d = scan_str(d,TRUE,TRUE);
4331 /* MUST advance bufptr here to avoid bogus
4332 "at end of line" context messages from yyerror().
4334 PL_bufptr = s + len;
4335 yyerror("Unterminated attribute parameter in attribute list");
4339 return REPORT(0); /* EOF indicator */
4343 sv_catsv(sv, PL_lex_stuff);
4344 attrs = append_elem(OP_LIST, attrs,
4345 newSVOP(OP_CONST, 0, sv));
4346 SvREFCNT_dec(PL_lex_stuff);
4347 PL_lex_stuff = NULL;
4350 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4352 if (PL_in_my == KEY_our) {
4354 GvUNIQUE_on(cGVOPx_gv(pl_yylval.opval));
4356 /* skip to avoid loading attributes.pm */
4358 deprecate(":unique");
4361 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4364 /* NOTE: any CV attrs applied here need to be part of
4365 the CVf_BUILTIN_ATTRS define in cv.h! */
4366 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4368 CvLVALUE_on(PL_compcv);
4370 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4372 CvLOCKED_on(PL_compcv);
4374 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4376 CvMETHOD_on(PL_compcv);
4378 /* After we've set the flags, it could be argued that
4379 we don't need to do the attributes.pm-based setting
4380 process, and shouldn't bother appending recognized
4381 flags. To experiment with that, uncomment the
4382 following "else". (Note that's already been
4383 uncommented. That keeps the above-applied built-in
4384 attributes from being intercepted (and possibly
4385 rejected) by a package's attribute routines, but is
4386 justified by the performance win for the common case
4387 of applying only built-in attributes.) */
4389 attrs = append_elem(OP_LIST, attrs,
4390 newSVOP(OP_CONST, 0,
4394 if (*s == ':' && s[1] != ':')
4397 break; /* require real whitespace or :'s */
4398 /* XXX losing whitespace on sequential attributes here */
4402 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4403 if (*s != ';' && *s != '}' && *s != tmp
4404 && (tmp != '=' || *s != ')')) {
4405 const char q = ((*s == '\'') ? '"' : '\'');
4406 /* If here for an expression, and parsed no attrs, back
4408 if (tmp == '=' && !attrs) {
4412 /* MUST advance bufptr here to avoid bogus "at end of line"
4413 context messages from yyerror().
4416 yyerror( (const char *)
4418 ? Perl_form(aTHX_ "Invalid separator character "
4419 "%c%c%c in attribute list", q, *s, q)
4420 : "Unterminated attribute list" ) );
4428 start_force(PL_curforce);
4429 NEXTVAL_NEXTTOKE.opval = attrs;
4430 CURMAD('_', PL_nextwhite);
4435 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4436 (s - SvPVX(PL_linestr)) - stuffstart);
4444 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4445 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4453 const char tmp = *s++;
4458 const char tmp = *s++;
4466 if (PL_lex_brackets <= 0)
4467 yyerror("Unmatched right square bracket");
4470 if (PL_lex_state == LEX_INTERPNORMAL) {
4471 if (PL_lex_brackets == 0) {
4472 if (*s == '-' && s[1] == '>')
4473 PL_lex_state = LEX_INTERPENDMAYBE;
4474 else if (*s != '[' && *s != '{')
4475 PL_lex_state = LEX_INTERPEND;
4482 if (PL_lex_brackets > 100) {
4483 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4485 switch (PL_expect) {
4487 if (PL_lex_formbrack) {
4491 if (PL_oldoldbufptr == PL_last_lop)
4492 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4494 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4495 OPERATOR(HASHBRACK);
4497 while (s < PL_bufend && SPACE_OR_TAB(*s))
4500 PL_tokenbuf[0] = '\0';
4501 if (d < PL_bufend && *d == '-') {
4502 PL_tokenbuf[0] = '-';
4504 while (d < PL_bufend && SPACE_OR_TAB(*d))
4507 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4508 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4510 while (d < PL_bufend && SPACE_OR_TAB(*d))
4513 const char minus = (PL_tokenbuf[0] == '-');
4514 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4522 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4527 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4532 if (PL_oldoldbufptr == PL_last_lop)
4533 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4535 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4538 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4540 /* This hack is to get the ${} in the message. */
4542 yyerror("syntax error");
4545 OPERATOR(HASHBRACK);
4547 /* This hack serves to disambiguate a pair of curlies
4548 * as being a block or an anon hash. Normally, expectation
4549 * determines that, but in cases where we're not in a
4550 * position to expect anything in particular (like inside
4551 * eval"") we have to resolve the ambiguity. This code
4552 * covers the case where the first term in the curlies is a
4553 * quoted string. Most other cases need to be explicitly
4554 * disambiguated by prepending a "+" before the opening
4555 * curly in order to force resolution as an anon hash.
4557 * XXX should probably propagate the outer expectation
4558 * into eval"" to rely less on this hack, but that could
4559 * potentially break current behavior of eval"".
4563 if (*s == '\'' || *s == '"' || *s == '`') {
4564 /* common case: get past first string, handling escapes */
4565 for (t++; t < PL_bufend && *t != *s;)
4566 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4570 else if (*s == 'q') {
4573 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4576 /* skip q//-like construct */
4578 char open, close, term;
4581 while (t < PL_bufend && isSPACE(*t))
4583 /* check for q => */
4584 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4585 OPERATOR(HASHBRACK);
4589 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4593 for (t++; t < PL_bufend; t++) {
4594 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4596 else if (*t == open)
4600 for (t++; t < PL_bufend; t++) {
4601 if (*t == '\\' && t+1 < PL_bufend)
4603 else if (*t == close && --brackets <= 0)
4605 else if (*t == open)
4612 /* skip plain q word */
4613 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4616 else if (isALNUM_lazy_if(t,UTF)) {
4618 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4621 while (t < PL_bufend && isSPACE(*t))
4623 /* if comma follows first term, call it an anon hash */
4624 /* XXX it could be a comma expression with loop modifiers */
4625 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4626 || (*t == '=' && t[1] == '>')))
4627 OPERATOR(HASHBRACK);
4628 if (PL_expect == XREF)
4631 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4637 pl_yylval.ival = CopLINE(PL_curcop);
4638 if (isSPACE(*s) || *s == '#')
4639 PL_copline = NOLINE; /* invalidate current command line number */
4644 if (PL_lex_brackets <= 0)
4645 yyerror("Unmatched right curly bracket");
4647 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4648 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4649 PL_lex_formbrack = 0;
4650 if (PL_lex_state == LEX_INTERPNORMAL) {
4651 if (PL_lex_brackets == 0) {
4652 if (PL_expect & XFAKEBRACK) {
4653 PL_expect &= XENUMMASK;
4654 PL_lex_state = LEX_INTERPEND;
4659 PL_thiswhite = newSVpvs("");
4660 sv_catpvs(PL_thiswhite,"}");
4663 return yylex(); /* ignore fake brackets */
4665 if (*s == '-' && s[1] == '>')
4666 PL_lex_state = LEX_INTERPENDMAYBE;
4667 else if (*s != '[' && *s != '{')
4668 PL_lex_state = LEX_INTERPEND;
4671 if (PL_expect & XFAKEBRACK) {
4672 PL_expect &= XENUMMASK;
4674 return yylex(); /* ignore fake brackets */
4676 start_force(PL_curforce);
4678 curmad('X', newSVpvn(s-1,1));
4679 CURMAD('_', PL_thiswhite);
4684 PL_thistoken = newSVpvs("");
4692 if (PL_expect == XOPERATOR) {
4693 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4694 && isIDFIRST_lazy_if(s,UTF))
4696 CopLINE_dec(PL_curcop);
4697 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
4698 CopLINE_inc(PL_curcop);
4703 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4705 PL_expect = XOPERATOR;
4706 force_ident(PL_tokenbuf, '&');
4710 pl_yylval.ival = (OPpENTERSUB_AMPER<<8);
4722 const char tmp = *s++;
4729 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4730 && strchr("+-*/%.^&|<",tmp))
4731 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4732 "Reversed %c= operator",(int)tmp);
4734 if (PL_expect == XSTATE && isALPHA(tmp) &&
4735 (s == PL_linestart+1 || s[-2] == '\n') )
4737 if (PL_in_eval && !PL_rsfp) {
4742 if (strnEQ(s,"=cut",4)) {
4758 PL_thiswhite = newSVpvs("");
4759 sv_catpvn(PL_thiswhite, PL_linestart,
4760 PL_bufend - PL_linestart);
4764 PL_doextract = TRUE;
4768 if (PL_lex_brackets < PL_lex_formbrack) {
4770 #ifdef PERL_STRICT_CR
4771 while (SPACE_OR_TAB(*t))
4773 while (SPACE_OR_TAB(*t) || *t == '\r')
4776 if (*t == '\n' || *t == '#') {
4785 if (PL_expect == XSTATE && s[1] == '!' && s[2] == '!') {
4791 const char tmp = *s++;
4793 /* was this !=~ where !~ was meant?
4794 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4796 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4797 const char *t = s+1;
4799 while (t < PL_bufend && isSPACE(*t))
4802 if (*t == '/' || *t == '?' ||
4803 ((*t == 'm' || *t == 's' || *t == 'y')
4804 && !isALNUM(t[1])) ||
4805 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4806 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4807 "!=~ should be !~");
4817 if (PL_expect != XOPERATOR) {
4818 if (s[1] != '<' && !strchr(s,'>'))
4821 s = scan_heredoc(s);
4823 s = scan_inputsymbol(s);
4824 TERM(sublex_start());
4830 SHop(OP_LEFT_SHIFT);
4844 const char tmp = *s++;
4846 SHop(OP_RIGHT_SHIFT);
4847 else if (tmp == '=')
4856 if (PL_expect == XOPERATOR) {
4857 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4859 deprecate_old(commaless_variable_list);
4860 return REPORT(','); /* grandfather non-comma-format format */
4864 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4865 PL_tokenbuf[0] = '@';
4866 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4867 sizeof PL_tokenbuf - 1, FALSE);
4868 if (PL_expect == XOPERATOR)
4869 no_op("Array length", s);
4870 if (!PL_tokenbuf[1])
4872 PL_expect = XOPERATOR;
4873 PL_pending_ident = '#';
4877 PL_tokenbuf[0] = '$';
4878 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4879 sizeof PL_tokenbuf - 1, FALSE);
4880 if (PL_expect == XOPERATOR)
4882 if (!PL_tokenbuf[1]) {
4884 yyerror("Final $ should be \\$ or $name");
4888 /* This kludge not intended to be bulletproof. */
4889 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4890 pl_yylval.opval = newSVOP(OP_CONST, 0,
4891 newSViv(CopARYBASE_get(&PL_compiling)));
4892 pl_yylval.opval->op_private = OPpCONST_ARYBASE;
4898 const char tmp = *s;
4899 if (PL_lex_state == LEX_NORMAL)
4902 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4903 && intuit_more(s)) {
4905 PL_tokenbuf[0] = '@';
4906 if (ckWARN(WARN_SYNTAX)) {
4909 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4912 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4913 while (t < PL_bufend && *t != ']')
4915 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4916 "Multidimensional syntax %.*s not supported",
4917 (int)((t - PL_bufptr) + 1), PL_bufptr);
4921 else if (*s == '{') {
4923 PL_tokenbuf[0] = '%';
4924 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4925 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4927 char tmpbuf[sizeof PL_tokenbuf];
4930 } while (isSPACE(*t));
4931 if (isIDFIRST_lazy_if(t,UTF)) {
4933 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4937 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
4938 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4939 "You need to quote \"%s\"",
4946 PL_expect = XOPERATOR;
4947 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4948 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4949 if (!islop || PL_last_lop_op == OP_GREPSTART)
4950 PL_expect = XOPERATOR;
4951 else if (strchr("$@\"'`q", *s))
4952 PL_expect = XTERM; /* e.g. print $fh "foo" */
4953 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4954 PL_expect = XTERM; /* e.g. print $fh &sub */
4955 else if (isIDFIRST_lazy_if(s,UTF)) {
4956 char tmpbuf[sizeof PL_tokenbuf];
4958 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4959 if ((t2 = keyword(tmpbuf, len, 0))) {
4960 /* binary operators exclude handle interpretations */
4972 PL_expect = XTERM; /* e.g. print $fh length() */
4977 PL_expect = XTERM; /* e.g. print $fh subr() */
4980 else if (isDIGIT(*s))
4981 PL_expect = XTERM; /* e.g. print $fh 3 */
4982 else if (*s == '.' && isDIGIT(s[1]))
4983 PL_expect = XTERM; /* e.g. print $fh .3 */
4984 else if ((*s == '?' || *s == '-' || *s == '+')
4985 && !isSPACE(s[1]) && s[1] != '=')
4986 PL_expect = XTERM; /* e.g. print $fh -1 */
4987 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4989 PL_expect = XTERM; /* e.g. print $fh /.../
4990 XXX except DORDOR operator
4992 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4994 PL_expect = XTERM; /* print $fh <<"EOF" */
4997 PL_pending_ident = '$';
5001 if (PL_expect == XOPERATOR)
5003 PL_tokenbuf[0] = '@';
5004 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
5005 if (!PL_tokenbuf[1]) {
5008 if (PL_lex_state == LEX_NORMAL)
5010 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
5012 PL_tokenbuf[0] = '%';
5014 /* Warn about @ where they meant $. */
5015 if (*s == '[' || *s == '{') {
5016 if (ckWARN(WARN_SYNTAX)) {
5017 const char *t = s + 1;
5018 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
5020 if (*t == '}' || *t == ']') {
5022 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
5023 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5024 "Scalar value %.*s better written as $%.*s",
5025 (int)(t-PL_bufptr), PL_bufptr,
5026 (int)(t-PL_bufptr-1), PL_bufptr+1);
5031 PL_pending_ident = '@';
5034 case '/': /* may be division, defined-or, or pattern */
5035 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
5039 case '?': /* may either be conditional or pattern */
5040 if (PL_expect == XSTATE && s[1] == '?' && s[2] == '?') {
5044 if (PL_expect == XOPERATOR) {
5052 /* A // operator. */
5062 /* Disable warning on "study /blah/" */
5063 if (PL_oldoldbufptr == PL_last_uni
5064 && (*PL_last_uni != 's' || s - PL_last_uni < 5
5065 || memNE(PL_last_uni, "study", 5)
5066 || isALNUM_lazy_if(PL_last_uni+5,UTF)
5069 s = scan_pat(s,OP_MATCH);
5070 TERM(sublex_start());
5074 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
5075 #ifdef PERL_STRICT_CR
5078 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
5080 && (s == PL_linestart || s[-1] == '\n') )
5082 PL_lex_formbrack = 0;
5086 if (PL_expect == XSTATE && s[1] == '.' && s[2] == '.') {
5090 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
5096 pl_yylval.ival = OPf_SPECIAL;
5102 if (PL_expect != XOPERATOR)
5107 case '0': case '1': case '2': case '3': case '4':
5108 case '5': case '6': case '7': case '8': case '9':
5109 s = scan_num(s, &pl_yylval);
5110 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
5111 if (PL_expect == XOPERATOR)
5116 s = scan_str(s,!!PL_madskills,FALSE);
5117 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5118 if (PL_expect == XOPERATOR) {
5119 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5121 deprecate_old(commaless_variable_list);
5122 return REPORT(','); /* grandfather non-comma-format format */
5129 pl_yylval.ival = OP_CONST;
5130 TERM(sublex_start());
5133 s = scan_str(s,!!PL_madskills,FALSE);
5134 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5135 if (PL_expect == XOPERATOR) {
5136 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5138 deprecate_old(commaless_variable_list);
5139 return REPORT(','); /* grandfather non-comma-format format */
5146 pl_yylval.ival = OP_CONST;
5147 /* FIXME. I think that this can be const if char *d is replaced by
5148 more localised variables. */
5149 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
5150 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
5151 pl_yylval.ival = OP_STRINGIFY;
5155 TERM(sublex_start());
5158 s = scan_str(s,!!PL_madskills,FALSE);
5159 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
5160 if (PL_expect == XOPERATOR)
5161 no_op("Backticks",s);
5164 readpipe_override();
5165 TERM(sublex_start());
5169 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
5170 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5172 if (PL_expect == XOPERATOR)
5173 no_op("Backslash",s);
5177 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
5178 char *start = s + 2;
5179 while (isDIGIT(*start) || *start == '_')
5181 if (*start == '.' && isDIGIT(start[1])) {
5182 s = scan_num(s, &pl_yylval);
5185 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
5186 else if (!isALPHA(*start) && (PL_expect == XTERM
5187 || PL_expect == XREF || PL_expect == XSTATE
5188 || PL_expect == XTERMORDORDOR)) {
5189 GV *const gv = gv_fetchpvn_flags(s, start - s, 0, SVt_PVCV);
5191 s = scan_num(s, &pl_yylval);
5198 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5240 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5242 /* Some keywords can be followed by any delimiter, including ':' */
5243 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5244 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5245 (PL_tokenbuf[0] == 'q' &&
5246 strchr("qwxr", PL_tokenbuf[1])))));
5248 /* x::* is just a word, unless x is "CORE" */
5249 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5253 while (d < PL_bufend && isSPACE(*d))
5254 d++; /* no comments skipped here, or s### is misparsed */
5256 /* Is this a label? */
5257 if (!tmp && PL_expect == XSTATE
5258 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5260 pl_yylval.pval = CopLABEL_alloc(PL_tokenbuf);
5265 /* Check for keywords */
5266 tmp = keyword(PL_tokenbuf, len, 0);
5268 /* Is this a word before a => operator? */
5269 if (*d == '=' && d[1] == '>') {
5272 = (OP*)newSVOP(OP_CONST, 0,
5273 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5274 pl_yylval.opval->op_private = OPpCONST_BARE;
5278 if (tmp < 0) { /* second-class keyword? */
5279 GV *ogv = NULL; /* override (winner) */
5280 GV *hgv = NULL; /* hidden (loser) */
5281 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5283 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5286 if (GvIMPORTED_CV(gv))
5288 else if (! CvMETHOD(cv))
5292 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5293 (gv = *gvp) && isGV_with_GP(gv) &&
5294 GvCVu(gv) && GvIMPORTED_CV(gv))
5301 tmp = 0; /* overridden by import or by GLOBAL */
5304 && -tmp==KEY_lock /* XXX generalizable kludge */
5307 tmp = 0; /* any sub overrides "weak" keyword */
5309 else { /* no override */
5311 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5312 Perl_warner(aTHX_ packWARN(WARN_MISC),
5313 "dump() better written as CORE::dump()");
5317 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5318 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5319 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5320 "Ambiguous call resolved as CORE::%s(), %s",
5321 GvENAME(hgv), "qualify as such or use &");
5328 default: /* not a keyword */
5329 /* Trade off - by using this evil construction we can pull the
5330 variable gv into the block labelled keylookup. If not, then
5331 we have to give it function scope so that the goto from the
5332 earlier ':' case doesn't bypass the initialisation. */
5334 just_a_word_zero_gv:
5342 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5345 SV *nextPL_nextwhite = 0;
5349 /* Get the rest if it looks like a package qualifier */
5351 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5353 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5356 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5357 *s == '\'' ? "'" : "::");
5362 if (PL_expect == XOPERATOR) {
5363 if (PL_bufptr == PL_linestart) {
5364 CopLINE_dec(PL_curcop);
5365 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
5366 CopLINE_inc(PL_curcop);
5369 no_op("Bareword",s);
5372 /* Look for a subroutine with this name in current package,
5373 unless name is "Foo::", in which case Foo is a bearword
5374 (and a package name). */
5376 if (len > 2 && !PL_madskills &&
5377 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5379 if (ckWARN(WARN_BAREWORD)
5380 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5381 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5382 "Bareword \"%s\" refers to nonexistent package",
5385 PL_tokenbuf[len] = '\0';
5391 /* Mustn't actually add anything to a symbol table.
5392 But also don't want to "initialise" any placeholder
5393 constants that might already be there into full
5394 blown PVGVs with attached PVCV. */
5395 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5396 GV_NOADD_NOINIT, SVt_PVCV);
5401 /* if we saw a global override before, get the right name */
5404 sv = newSVpvs("CORE::GLOBAL::");
5405 sv_catpv(sv,PL_tokenbuf);
5408 /* If len is 0, newSVpv does strlen(), which is correct.
5409 If len is non-zero, then it will be the true length,
5410 and so the scalar will be created correctly. */
5411 sv = newSVpv(PL_tokenbuf,len);
5414 if (PL_madskills && !PL_thistoken) {
5415 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5416 PL_thistoken = newSVpvn(start,s - start);
5417 PL_realtokenstart = s - SvPVX(PL_linestr);
5421 /* Presume this is going to be a bareword of some sort. */
5424 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5425 pl_yylval.opval->op_private = OPpCONST_BARE;
5426 /* UTF-8 package name? */
5427 if (UTF && !IN_BYTES &&
5428 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5431 /* And if "Foo::", then that's what it certainly is. */
5436 /* Do the explicit type check so that we don't need to force
5437 the initialisation of the symbol table to have a real GV.
5438 Beware - gv may not really be a PVGV, cv may not really be
5439 a PVCV, (because of the space optimisations that gv_init
5440 understands) But they're true if for this symbol there is
5441 respectively a typeglob and a subroutine.
5443 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5444 /* Real typeglob, so get the real subroutine: */
5446 /* A proxy for a subroutine in this package? */
5447 : SvOK(gv) ? MUTABLE_CV(gv) : NULL)
5450 /* See if it's the indirect object for a list operator. */
5452 if (PL_oldoldbufptr &&
5453 PL_oldoldbufptr < PL_bufptr &&
5454 (PL_oldoldbufptr == PL_last_lop
5455 || PL_oldoldbufptr == PL_last_uni) &&
5456 /* NO SKIPSPACE BEFORE HERE! */
5457 (PL_expect == XREF ||
5458 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5460 bool immediate_paren = *s == '(';
5462 /* (Now we can afford to cross potential line boundary.) */
5463 s = SKIPSPACE2(s,nextPL_nextwhite);
5465 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5468 /* Two barewords in a row may indicate method call. */
5470 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5471 (tmp = intuit_method(s, gv, cv)))
5474 /* If not a declared subroutine, it's an indirect object. */
5475 /* (But it's an indir obj regardless for sort.) */
5476 /* Also, if "_" follows a filetest operator, it's a bareword */
5479 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5481 (PL_last_lop_op != OP_MAPSTART &&
5482 PL_last_lop_op != OP_GREPSTART))))
5483 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5484 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5487 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5492 PL_expect = XOPERATOR;
5495 s = SKIPSPACE2(s,nextPL_nextwhite);
5496 PL_nextwhite = nextPL_nextwhite;
5501 /* Is this a word before a => operator? */
5502 if (*s == '=' && s[1] == '>' && !pkgname) {
5504 sv_setpv(((SVOP*)pl_yylval.opval)->op_sv, PL_tokenbuf);
5505 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5506 SvUTF8_on(((SVOP*)pl_yylval.opval)->op_sv);
5510 /* If followed by a paren, it's certainly a subroutine. */
5515 while (SPACE_OR_TAB(*d))
5517 if (*d == ')' && (sv = gv_const_sv(gv))) {
5524 PL_nextwhite = PL_thiswhite;
5527 start_force(PL_curforce);
5529 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5530 PL_expect = XOPERATOR;
5533 PL_nextwhite = nextPL_nextwhite;
5534 curmad('X', PL_thistoken);
5535 PL_thistoken = newSVpvs("");
5543 /* If followed by var or block, call it a method (unless sub) */
5545 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5546 PL_last_lop = PL_oldbufptr;
5547 PL_last_lop_op = OP_METHOD;
5551 /* If followed by a bareword, see if it looks like indir obj. */
5554 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5555 && (tmp = intuit_method(s, gv, cv)))
5558 /* Not a method, so call it a subroutine (if defined) */
5561 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5562 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5563 "Ambiguous use of -%s resolved as -&%s()",
5564 PL_tokenbuf, PL_tokenbuf);
5565 /* Check for a constant sub */
5566 if ((sv = gv_const_sv(gv))) {
5568 SvREFCNT_dec(((SVOP*)pl_yylval.opval)->op_sv);
5569 ((SVOP*)pl_yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5570 pl_yylval.opval->op_private = 0;
5574 /* Resolve to GV now. */
5575 if (SvTYPE(gv) != SVt_PVGV) {
5576 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5577 assert (SvTYPE(gv) == SVt_PVGV);
5578 /* cv must have been some sort of placeholder, so
5579 now needs replacing with a real code reference. */
5583 op_free(pl_yylval.opval);
5584 pl_yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5585 pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5586 PL_last_lop = PL_oldbufptr;
5587 PL_last_lop_op = OP_ENTERSUB;
5588 /* Is there a prototype? */
5596 const char *proto = SvPV_const(MUTABLE_SV(cv), protolen);
5599 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
5601 while (*proto == ';')
5603 if (*proto == '&' && *s == '{') {
5605 sv_setpvs(PL_subname, "__ANON__");
5607 sv_setpvs(PL_subname, "__ANON__::__ANON__");
5614 PL_nextwhite = PL_thiswhite;
5617 start_force(PL_curforce);
5618 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5621 PL_nextwhite = nextPL_nextwhite;
5622 curmad('X', PL_thistoken);
5623 PL_thistoken = newSVpvs("");
5630 /* Guess harder when madskills require "best effort". */
5631 if (PL_madskills && (!gv || !GvCVu(gv))) {
5632 int probable_sub = 0;
5633 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5635 else if (isALPHA(*s)) {
5639 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5640 if (!keyword(tmpbuf, tmplen, 0))
5643 while (d < PL_bufend && isSPACE(*d))
5645 if (*d == '=' && d[1] == '>')
5650 gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
5651 op_free(pl_yylval.opval);
5652 pl_yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5653 pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5654 PL_last_lop = PL_oldbufptr;
5655 PL_last_lop_op = OP_ENTERSUB;
5656 PL_nextwhite = PL_thiswhite;
5658 start_force(PL_curforce);
5659 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5661 PL_nextwhite = nextPL_nextwhite;
5662 curmad('X', PL_thistoken);
5663 PL_thistoken = newSVpvs("");
5668 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5675 /* Call it a bare word */
5678 if (PL_hints & HINT_STRICT_SUBS)
5679 pl_yylval.opval->op_private |= OPpCONST_STRICT;
5681 if (lastchar != '-') {
5682 if (ckWARN(WARN_RESERVED)) {
5686 if (!*d && !gv_stashpv(PL_tokenbuf, 0))
5687 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5694 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5695 && ckWARN_d(WARN_AMBIGUOUS)) {
5696 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5697 "Operator or semicolon missing before %c%s",
5698 lastchar, PL_tokenbuf);
5699 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5700 "Ambiguous use of %c resolved as operator %c",
5701 lastchar, lastchar);
5707 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5708 newSVpv(CopFILE(PL_curcop),0));
5712 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5713 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5716 case KEY___PACKAGE__:
5717 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5719 ? newSVhek(HvNAME_HEK(PL_curstash))
5726 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5727 const char *pname = "main";
5728 if (PL_tokenbuf[2] == 'D')
5729 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5730 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5734 GvIOp(gv) = newIO();
5735 IoIFP(GvIOp(gv)) = PL_rsfp;
5736 #if defined(HAS_FCNTL) && defined(F_SETFD)
5738 const int fd = PerlIO_fileno(PL_rsfp);
5739 fcntl(fd,F_SETFD,fd >= 3);
5742 /* Mark this internal pseudo-handle as clean */
5743 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5744 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5745 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5747 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5748 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5749 /* if the script was opened in binmode, we need to revert
5750 * it to text mode for compatibility; but only iff it has CRs
5751 * XXX this is a questionable hack at best. */
5752 if (PL_bufend-PL_bufptr > 2
5753 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5756 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5757 loc = PerlIO_tell(PL_rsfp);
5758 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5761 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5763 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5764 #endif /* NETWARE */
5765 #ifdef PERLIO_IS_STDIO /* really? */
5766 # if defined(__BORLANDC__)
5767 /* XXX see note in do_binmode() */
5768 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5772 PerlIO_seek(PL_rsfp, loc, 0);
5776 #ifdef PERLIO_LAYERS
5779 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5780 else if (PL_encoding) {
5787 XPUSHs(PL_encoding);
5789 call_method("name", G_SCALAR);
5793 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5794 Perl_form(aTHX_ ":encoding(%"SVf")",
5803 if (PL_realtokenstart >= 0) {
5804 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5806 PL_endwhite = newSVpvs("");
5807 sv_catsv(PL_endwhite, PL_thiswhite);
5809 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5810 PL_realtokenstart = -1;
5812 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5813 SvCUR(PL_endwhite))) != NULL) ;
5828 if (PL_expect == XSTATE) {
5835 if (*s == ':' && s[1] == ':') {
5838 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5839 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5840 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5843 else if (tmp == KEY_require || tmp == KEY_do)
5844 /* that's a way to remember we saw "CORE::" */
5857 LOP(OP_ACCEPT,XTERM);
5863 LOP(OP_ATAN2,XTERM);
5869 LOP(OP_BINMODE,XTERM);
5872 LOP(OP_BLESS,XTERM);
5881 /* When 'use switch' is in effect, continue has a dual
5882 life as a control operator. */
5884 if (!FEATURE_IS_ENABLED("switch"))
5887 /* We have to disambiguate the two senses of
5888 "continue". If the next token is a '{' then
5889 treat it as the start of a continue block;
5890 otherwise treat it as a control operator.
5902 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5919 if (!PL_cryptseen) {
5920 PL_cryptseen = TRUE;
5924 LOP(OP_CRYPT,XTERM);
5927 LOP(OP_CHMOD,XTERM);
5930 LOP(OP_CHOWN,XTERM);
5933 LOP(OP_CONNECT,XTERM);
5952 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5953 if (orig_keyword == KEY_do) {
5962 PL_hints |= HINT_BLOCK_SCOPE;
5972 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5973 LOP(OP_DBMOPEN,XTERM);
5979 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5986 pl_yylval.ival = CopLINE(PL_curcop);
6002 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
6003 UNIBRACK(OP_ENTEREVAL);
6017 case KEY_endhostent:
6023 case KEY_endservent:
6026 case KEY_endprotoent:
6037 pl_yylval.ival = CopLINE(PL_curcop);
6039 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
6042 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
6045 if ((PL_bufend - p) >= 3 &&
6046 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
6048 else if ((PL_bufend - p) >= 4 &&
6049 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
6052 if (isIDFIRST_lazy_if(p,UTF)) {
6053 p = scan_ident(p, PL_bufend,
6054 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
6058 Perl_croak(aTHX_ "Missing $ on loop variable");
6060 s = SvPVX(PL_linestr) + soff;
6066 LOP(OP_FORMLINE,XTERM);
6072 LOP(OP_FCNTL,XTERM);
6078 LOP(OP_FLOCK,XTERM);
6087 LOP(OP_GREPSTART, XREF);
6090 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6105 case KEY_getpriority:
6106 LOP(OP_GETPRIORITY,XTERM);
6108 case KEY_getprotobyname:
6111 case KEY_getprotobynumber:
6112 LOP(OP_GPBYNUMBER,XTERM);
6114 case KEY_getprotoent:
6126 case KEY_getpeername:
6127 UNI(OP_GETPEERNAME);
6129 case KEY_gethostbyname:
6132 case KEY_gethostbyaddr:
6133 LOP(OP_GHBYADDR,XTERM);
6135 case KEY_gethostent:
6138 case KEY_getnetbyname:
6141 case KEY_getnetbyaddr:
6142 LOP(OP_GNBYADDR,XTERM);
6147 case KEY_getservbyname:
6148 LOP(OP_GSBYNAME,XTERM);
6150 case KEY_getservbyport:
6151 LOP(OP_GSBYPORT,XTERM);
6153 case KEY_getservent:
6156 case KEY_getsockname:
6157 UNI(OP_GETSOCKNAME);
6159 case KEY_getsockopt:
6160 LOP(OP_GSOCKOPT,XTERM);
6175 pl_yylval.ival = CopLINE(PL_curcop);
6185 pl_yylval.ival = CopLINE(PL_curcop);
6189 LOP(OP_INDEX,XTERM);
6195 LOP(OP_IOCTL,XTERM);
6207 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6239 LOP(OP_LISTEN,XTERM);
6248 s = scan_pat(s,OP_MATCH);
6249 TERM(sublex_start());
6252 LOP(OP_MAPSTART, XREF);
6255 LOP(OP_MKDIR,XTERM);
6258 LOP(OP_MSGCTL,XTERM);
6261 LOP(OP_MSGGET,XTERM);
6264 LOP(OP_MSGRCV,XTERM);
6267 LOP(OP_MSGSND,XTERM);
6272 PL_in_my = (U16)tmp;
6274 if (isIDFIRST_lazy_if(s,UTF)) {
6278 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6279 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6281 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6282 if (!PL_in_my_stash) {
6285 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6289 if (PL_madskills) { /* just add type to declarator token */
6290 sv_catsv(PL_thistoken, PL_nextwhite);
6292 sv_catpvn(PL_thistoken, start, s - start);
6300 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6307 s = tokenize_use(0, s);
6311 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6318 if (isIDFIRST_lazy_if(s,UTF)) {
6320 for (d = s; isALNUM_lazy_if(d,UTF);)
6322 for (t=d; isSPACE(*t);)
6324 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6326 && !(t[0] == '=' && t[1] == '>')
6328 int parms_len = (int)(d-s);
6329 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6330 "Precedence problem: open %.*s should be open(%.*s)",
6331 parms_len, s, parms_len, s);
6337 pl_yylval.ival = OP_OR;
6347 LOP(OP_OPEN_DIR,XTERM);
6350 checkcomma(s,PL_tokenbuf,"filehandle");
6354 checkcomma(s,PL_tokenbuf,"filehandle");
6373 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6377 LOP(OP_PIPE_OP,XTERM);
6380 s = scan_str(s,!!PL_madskills,FALSE);
6383 pl_yylval.ival = OP_CONST;
6384 TERM(sublex_start());
6390 s = scan_str(s,!!PL_madskills,FALSE);
6393 PL_expect = XOPERATOR;
6395 if (SvCUR(PL_lex_stuff)) {
6398 d = SvPV_force(PL_lex_stuff, len);
6400 for (; isSPACE(*d) && len; --len, ++d)
6405 if (!warned && ckWARN(WARN_QW)) {
6406 for (; !isSPACE(*d) && len; --len, ++d) {
6408 Perl_warner(aTHX_ packWARN(WARN_QW),
6409 "Possible attempt to separate words with commas");
6412 else if (*d == '#') {
6413 Perl_warner(aTHX_ packWARN(WARN_QW),
6414 "Possible attempt to put comments in qw() list");
6420 for (; !isSPACE(*d) && len; --len, ++d)
6423 sv = newSVpvn_utf8(b, d-b, DO_UTF8(PL_lex_stuff));
6424 words = append_elem(OP_LIST, words,
6425 newSVOP(OP_CONST, 0, tokeq(sv)));
6429 start_force(PL_curforce);
6430 NEXTVAL_NEXTTOKE.opval = words;
6435 SvREFCNT_dec(PL_lex_stuff);
6436 PL_lex_stuff = NULL;
6442 s = scan_str(s,!!PL_madskills,FALSE);
6445 pl_yylval.ival = OP_STRINGIFY;
6446 if (SvIVX(PL_lex_stuff) == '\'')
6447 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6448 TERM(sublex_start());
6451 s = scan_pat(s,OP_QR);
6452 TERM(sublex_start());
6455 s = scan_str(s,!!PL_madskills,FALSE);
6458 readpipe_override();
6459 TERM(sublex_start());
6467 s = force_version(s, FALSE);
6469 else if (*s != 'v' || !isDIGIT(s[1])
6470 || (s = force_version(s, TRUE), *s == 'v'))
6472 *PL_tokenbuf = '\0';
6473 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6474 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6475 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
6477 yyerror("<> should be quotes");
6479 if (orig_keyword == KEY_require) {
6487 PL_last_uni = PL_oldbufptr;
6488 PL_last_lop_op = OP_REQUIRE;
6490 return REPORT( (int)REQUIRE );
6496 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6500 LOP(OP_RENAME,XTERM);
6509 LOP(OP_RINDEX,XTERM);
6518 UNIDOR(OP_READLINE);
6521 UNIDOR(OP_BACKTICK);
6530 LOP(OP_REVERSE,XTERM);
6533 UNIDOR(OP_READLINK);
6540 if (pl_yylval.opval)
6541 TERM(sublex_start());
6543 TOKEN(1); /* force error */
6546 checkcomma(s,PL_tokenbuf,"filehandle");
6556 LOP(OP_SELECT,XTERM);
6562 LOP(OP_SEMCTL,XTERM);
6565 LOP(OP_SEMGET,XTERM);
6568 LOP(OP_SEMOP,XTERM);
6574 LOP(OP_SETPGRP,XTERM);
6576 case KEY_setpriority:
6577 LOP(OP_SETPRIORITY,XTERM);
6579 case KEY_sethostent:
6585 case KEY_setservent:
6588 case KEY_setprotoent:
6598 LOP(OP_SEEKDIR,XTERM);
6600 case KEY_setsockopt:
6601 LOP(OP_SSOCKOPT,XTERM);
6607 LOP(OP_SHMCTL,XTERM);
6610 LOP(OP_SHMGET,XTERM);
6613 LOP(OP_SHMREAD,XTERM);
6616 LOP(OP_SHMWRITE,XTERM);
6619 LOP(OP_SHUTDOWN,XTERM);
6628 LOP(OP_SOCKET,XTERM);
6630 case KEY_socketpair:
6631 LOP(OP_SOCKPAIR,XTERM);
6634 checkcomma(s,PL_tokenbuf,"subroutine name");
6636 if (*s == ';' || *s == ')') /* probably a close */
6637 Perl_croak(aTHX_ "sort is now a reserved word");
6639 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6643 LOP(OP_SPLIT,XTERM);
6646 LOP(OP_SPRINTF,XTERM);
6649 LOP(OP_SPLICE,XTERM);
6664 LOP(OP_SUBSTR,XTERM);
6670 char tmpbuf[sizeof PL_tokenbuf];
6671 SSize_t tboffset = 0;
6672 expectation attrful;
6673 bool have_name, have_proto;
6674 const int key = tmp;
6679 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6680 SV *subtoken = newSVpvn(tstart, s - tstart);
6684 s = SKIPSPACE2(s,tmpwhite);
6689 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6690 (*s == ':' && s[1] == ':'))
6693 SV *nametoke = NULL;
6697 attrful = XATTRBLOCK;
6698 /* remember buffer pos'n for later force_word */
6699 tboffset = s - PL_oldbufptr;
6700 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6703 nametoke = newSVpvn(s, d - s);
6705 if (memchr(tmpbuf, ':', len))
6706 sv_setpvn(PL_subname, tmpbuf, len);
6708 sv_setsv(PL_subname,PL_curstname);
6709 sv_catpvs(PL_subname,"::");
6710 sv_catpvn(PL_subname,tmpbuf,len);
6717 CURMAD('X', nametoke);
6718 CURMAD('_', tmpwhite);
6719 (void) force_word(PL_oldbufptr + tboffset, WORD,
6722 s = SKIPSPACE2(d,tmpwhite);
6729 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6730 PL_expect = XTERMBLOCK;
6731 attrful = XATTRTERM;
6732 sv_setpvs(PL_subname,"?");
6736 if (key == KEY_format) {
6738 PL_lex_formbrack = PL_lex_brackets + 1;
6740 PL_thistoken = subtoken;
6744 (void) force_word(PL_oldbufptr + tboffset, WORD,
6750 /* Look for a prototype */
6753 bool bad_proto = FALSE;
6754 bool in_brackets = FALSE;
6755 char greedy_proto = ' ';
6756 bool proto_after_greedy_proto = FALSE;
6757 bool must_be_last = FALSE;
6758 bool underscore = FALSE;
6759 bool seen_underscore = FALSE;
6760 const bool warnsyntax = ckWARN(WARN_SYNTAX);
6762 s = scan_str(s,!!PL_madskills,FALSE);
6764 Perl_croak(aTHX_ "Prototype not terminated");
6765 /* strip spaces and check for bad characters */
6766 d = SvPVX(PL_lex_stuff);
6768 for (p = d; *p; ++p) {
6774 proto_after_greedy_proto = TRUE;
6775 if (!strchr("$@%*;[]&\\_", *p)) {
6787 else if ( *p == ']' ) {
6788 in_brackets = FALSE;
6790 else if ( (*p == '@' || *p == '%') &&
6791 ( tmp < 2 || d[tmp-2] != '\\' ) &&
6793 must_be_last = TRUE;
6796 else if ( *p == '_' ) {
6797 underscore = seen_underscore = TRUE;
6804 if (proto_after_greedy_proto)
6805 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6806 "Prototype after '%c' for %"SVf" : %s",
6807 greedy_proto, SVfARG(PL_subname), d);
6809 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6810 "Illegal character %sin prototype for %"SVf" : %s",
6811 seen_underscore ? "after '_' " : "",
6812 SVfARG(PL_subname), d);
6813 SvCUR_set(PL_lex_stuff, tmp);
6818 CURMAD('q', PL_thisopen);
6819 CURMAD('_', tmpwhite);
6820 CURMAD('=', PL_thisstuff);
6821 CURMAD('Q', PL_thisclose);
6822 NEXTVAL_NEXTTOKE.opval =
6823 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6824 PL_lex_stuff = NULL;
6827 s = SKIPSPACE2(s,tmpwhite);
6835 if (*s == ':' && s[1] != ':')
6836 PL_expect = attrful;
6837 else if (*s != '{' && key == KEY_sub) {
6839 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6841 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
6848 curmad('^', newSVpvs(""));
6849 CURMAD('_', tmpwhite);
6853 PL_thistoken = subtoken;
6856 NEXTVAL_NEXTTOKE.opval =
6857 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6858 PL_lex_stuff = NULL;
6864 sv_setpvs(PL_subname, "__ANON__");
6866 sv_setpvs(PL_subname, "__ANON__::__ANON__");
6870 (void) force_word(PL_oldbufptr + tboffset, WORD,
6879 LOP(OP_SYSTEM,XREF);
6882 LOP(OP_SYMLINK,XTERM);
6885 LOP(OP_SYSCALL,XTERM);
6888 LOP(OP_SYSOPEN,XTERM);
6891 LOP(OP_SYSSEEK,XTERM);
6894 LOP(OP_SYSREAD,XTERM);
6897 LOP(OP_SYSWRITE,XTERM);
6901 TERM(sublex_start());
6922 LOP(OP_TRUNCATE,XTERM);
6934 pl_yylval.ival = CopLINE(PL_curcop);
6938 pl_yylval.ival = CopLINE(PL_curcop);
6942 LOP(OP_UNLINK,XTERM);
6948 LOP(OP_UNPACK,XTERM);
6951 LOP(OP_UTIME,XTERM);
6957 LOP(OP_UNSHIFT,XTERM);
6960 s = tokenize_use(1, s);
6970 pl_yylval.ival = CopLINE(PL_curcop);
6974 pl_yylval.ival = CopLINE(PL_curcop);
6978 PL_hints |= HINT_BLOCK_SCOPE;
6985 LOP(OP_WAITPID,XTERM);
6994 ctl_l[0] = toCTRL('L');
6996 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6999 /* Make sure $^L is defined */
7000 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
7005 if (PL_expect == XOPERATOR)
7011 pl_yylval.ival = OP_XOR;
7016 TERM(sublex_start());
7021 #pragma segment Main
7025 S_pending_ident(pTHX)
7030 /* pit holds the identifier we read and pending_ident is reset */
7031 char pit = PL_pending_ident;
7032 const STRLEN tokenbuf_len = strlen(PL_tokenbuf);
7033 /* All routes through this function want to know if there is a colon. */
7034 const char *const has_colon = (const char*) memchr (PL_tokenbuf, ':', tokenbuf_len);
7035 PL_pending_ident = 0;
7037 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
7038 DEBUG_T({ PerlIO_printf(Perl_debug_log,
7039 "### Pending identifier '%s'\n", PL_tokenbuf); });
7041 /* if we're in a my(), we can't allow dynamics here.
7042 $foo'bar has already been turned into $foo::bar, so
7043 just check for colons.
7045 if it's a legal name, the OP is a PADANY.
7048 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
7050 yyerror(Perl_form(aTHX_ "No package name allowed for "
7051 "variable %s in \"our\"",
7053 tmp = allocmy(PL_tokenbuf);
7057 yyerror(Perl_form(aTHX_ PL_no_myglob,
7058 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
7060 pl_yylval.opval = newOP(OP_PADANY, 0);
7061 pl_yylval.opval->op_targ = allocmy(PL_tokenbuf);
7067 build the ops for accesses to a my() variable.
7069 Deny my($a) or my($b) in a sort block, *if* $a or $b is
7070 then used in a comparison. This catches most, but not
7071 all cases. For instance, it catches
7072 sort { my($a); $a <=> $b }
7074 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
7075 (although why you'd do that is anyone's guess).
7080 tmp = pad_findmy(PL_tokenbuf);
7081 if (tmp != NOT_IN_PAD) {
7082 /* might be an "our" variable" */
7083 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
7084 /* build ops for a bareword */
7085 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
7086 HEK * const stashname = HvNAME_HEK(stash);
7087 SV * const sym = newSVhek(stashname);
7088 sv_catpvs(sym, "::");
7089 sv_catpvn(sym, PL_tokenbuf+1, tokenbuf_len - 1);
7090 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
7091 pl_yylval.opval->op_private = OPpCONST_ENTERED;
7094 ? (GV_ADDMULTI | GV_ADDINEVAL)
7097 ((PL_tokenbuf[0] == '$') ? SVt_PV
7098 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7103 /* if it's a sort block and they're naming $a or $b */
7104 if (PL_last_lop_op == OP_SORT &&
7105 PL_tokenbuf[0] == '$' &&
7106 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
7109 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
7110 d < PL_bufend && *d != '\n';
7113 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
7114 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
7120 pl_yylval.opval = newOP(OP_PADANY, 0);
7121 pl_yylval.opval->op_targ = tmp;
7127 Whine if they've said @foo in a doublequoted string,
7128 and @foo isn't a variable we can find in the symbol
7131 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
7132 GV *const gv = gv_fetchpvn_flags(PL_tokenbuf + 1, tokenbuf_len - 1, 0,
7134 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
7135 && ckWARN(WARN_AMBIGUOUS)
7136 /* DO NOT warn for @- and @+ */
7137 && !( PL_tokenbuf[2] == '\0' &&
7138 ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
7141 /* Downgraded from fatal to warning 20000522 mjd */
7142 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
7143 "Possible unintended interpolation of %s in string",
7148 /* build ops for a bareword */
7149 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpvn(PL_tokenbuf + 1,
7151 pl_yylval.opval->op_private = OPpCONST_ENTERED;
7153 PL_tokenbuf + 1, tokenbuf_len - 1,
7154 /* If the identifier refers to a stash, don't autovivify it.
7155 * Change 24660 had the side effect of causing symbol table
7156 * hashes to always be defined, even if they were freshly
7157 * created and the only reference in the entire program was
7158 * the single statement with the defined %foo::bar:: test.
7159 * It appears that all code in the wild doing this actually
7160 * wants to know whether sub-packages have been loaded, so
7161 * by avoiding auto-vivifying symbol tables, we ensure that
7162 * defined %foo::bar:: continues to be false, and the existing
7163 * tests still give the expected answers, even though what
7164 * they're actually testing has now changed subtly.
7166 (*PL_tokenbuf == '%'
7167 && *(d = PL_tokenbuf + tokenbuf_len - 1) == ':'
7170 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
7171 ((PL_tokenbuf[0] == '$') ? SVt_PV
7172 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7178 * The following code was generated by perl_keyword.pl.
7182 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
7186 PERL_ARGS_ASSERT_KEYWORD;
7190 case 1: /* 5 tokens of length 1 */
7222 case 2: /* 18 tokens of length 2 */
7368 case 3: /* 29 tokens of length 3 */
7372 if (name[1] == 'N' &&
7435 if (name[1] == 'i' &&
7467 if (name[1] == 'o' &&
7476 if (name[1] == 'e' &&
7485 if (name[1] == 'n' &&
7494 if (name[1] == 'o' &&
7503 if (name[1] == 'a' &&
7512 if (name[1] == 'o' &&
7574 if (name[1] == 'e' &&
7588 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
7614 if (name[1] == 'i' &&
7623 if (name[1] == 's' &&
7632 if (name[1] == 'e' &&
7641 if (name[1] == 'o' &&
7653 case 4: /* 41 tokens of length 4 */
7657 if (name[1] == 'O' &&
7667 if (name[1] == 'N' &&
7677 if (name[1] == 'i' &&
7687 if (name[1] == 'h' &&
7697 if (name[1] == 'u' &&
7710 if (name[2] == 'c' &&
7719 if (name[2] == 's' &&
7728 if (name[2] == 'a' &&
7764 if (name[1] == 'o' &&
7777 if (name[2] == 't' &&
7786 if (name[2] == 'o' &&
7795 if (name[2] == 't' &&
7804 if (name[2] == 'e' &&
7817 if (name[1] == 'o' &&
7830 if (name[2] == 'y' &&
7839 if (name[2] == 'l' &&
7855 if (name[2] == 's' &&
7864 if (name[2] == 'n' &&
7873 if (name[2] == 'c' &&
7886 if (name[1] == 'e' &&
7896 if (name[1] == 'p' &&
7909 if (name[2] == 'c' &&
7918 if (name[2] == 'p' &&
7927 if (name[2] == 's' &&
7943 if (name[2] == 'n' &&
8013 if (name[2] == 'r' &&
8022 if (name[2] == 'r' &&
8031 if (name[2] == 'a' &&
8047 if (name[2] == 'l' &&
8109 if (name[2] == 'e' &&
8112 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
8125 case 5: /* 39 tokens of length 5 */
8129 if (name[1] == 'E' &&
8140 if (name[1] == 'H' &&
8154 if (name[2] == 'a' &&
8164 if (name[2] == 'a' &&
8181 if (name[2] == 'e' &&
8191 if (name[2] == 'e' &&
8195 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
8211 if (name[3] == 'i' &&
8220 if (name[3] == 'o' &&
8256 if (name[2] == 'o' &&
8266 if (name[2] == 'y' &&
8280 if (name[1] == 'l' &&
8294 if (name[2] == 'n' &&
8304 if (name[2] == 'o' &&
8318 if (name[1] == 'i' &&
8323 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8332 if (name[2] == 'd' &&
8342 if (name[2] == 'c' &&
8359 if (name[2] == 'c' &&
8369 if (name[2] == 't' &&
8383 if (name[1] == 'k' &&
8394 if (name[1] == 'r' &&
8408 if (name[2] == 's' &&
8418 if (name[2] == 'd' &&
8435 if (name[2] == 'm' &&
8445 if (name[2] == 'i' &&
8455 if (name[2] == 'e' &&
8465 if (name[2] == 'l' &&
8475 if (name[2] == 'a' &&
8488 if (name[3] == 't' &&
8491 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8497 if (name[3] == 'd' &&
8514 if (name[1] == 'i' &&
8528 if (name[2] == 'a' &&
8541 if (name[3] == 'e' &&
8576 if (name[2] == 'i' &&
8593 if (name[2] == 'i' &&
8603 if (name[2] == 'i' &&
8620 case 6: /* 33 tokens of length 6 */
8624 if (name[1] == 'c' &&
8639 if (name[2] == 'l' &&
8650 if (name[2] == 'r' &&
8665 if (name[1] == 'e' &&
8680 if (name[2] == 's' &&
8685 if(ckWARN_d(WARN_SYNTAX))
8686 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8692 if (name[2] == 'i' &&
8710 if (name[2] == 'l' &&
8721 if (name[2] == 'r' &&
8736 if (name[1] == 'm' &&
8751 if (name[2] == 'n' &&
8762 if (name[2] == 's' &&
8777 if (name[1] == 's' &&
8783 if (name[4] == 't' &&
8792 if (name[4] == 'e' &&
8801 if (name[4] == 'c' &&
8810 if (name[4] == 'n' &&
8826 if (name[1] == 'r' &&
8844 if (name[3] == 'a' &&
8854 if (name[3] == 'u' &&
8868 if (name[2] == 'n' &&
8886 if (name[2] == 'a' &&
8900 if (name[3] == 'e' &&
8913 if (name[4] == 't' &&
8922 if (name[4] == 'e' &&
8944 if (name[4] == 't' &&
8953 if (name[4] == 'e' &&
8969 if (name[2] == 'c' &&
8980 if (name[2] == 'l' &&
8991 if (name[2] == 'b' &&
9002 if (name[2] == 's' &&
9025 if (name[4] == 's' &&
9034 if (name[4] == 'n' &&
9047 if (name[3] == 'a' &&
9064 if (name[1] == 'a' &&
9079 case 7: /* 29 tokens of length 7 */
9083 if (name[1] == 'E' &&
9096 if (name[1] == '_' &&
9109 if (name[1] == 'i' &&
9116 return -KEY_binmode;
9122 if (name[1] == 'o' &&
9129 return -KEY_connect;
9138 if (name[2] == 'm' &&
9144 return -KEY_dbmopen;
9155 if (name[4] == 'u' &&
9159 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
9165 if (name[4] == 'n' &&
9186 if (name[1] == 'o' &&
9199 if (name[1] == 'e' &&
9206 if (name[5] == 'r' &&
9209 return -KEY_getpgrp;
9215 if (name[5] == 'i' &&
9218 return -KEY_getppid;
9231 if (name[1] == 'c' &&
9238 return -KEY_lcfirst;
9244 if (name[1] == 'p' &&
9251 return -KEY_opendir;
9257 if (name[1] == 'a' &&
9275 if (name[3] == 'd' &&
9280 return -KEY_readdir;
9286 if (name[3] == 'u' &&
9297 if (name[3] == 'e' &&
9302 return -KEY_reverse;
9321 if (name[3] == 'k' &&
9326 return -KEY_seekdir;
9332 if (name[3] == 'p' &&
9337 return -KEY_setpgrp;
9347 if (name[2] == 'm' &&
9353 return -KEY_shmread;
9359 if (name[2] == 'r' &&
9365 return -KEY_sprintf;
9374 if (name[3] == 'l' &&
9379 return -KEY_symlink;
9388 if (name[4] == 'a' &&
9392 return -KEY_syscall;
9398 if (name[4] == 'p' &&
9402 return -KEY_sysopen;
9408 if (name[4] == 'e' &&
9412 return -KEY_sysread;
9418 if (name[4] == 'e' &&
9422 return -KEY_sysseek;
9440 if (name[1] == 'e' &&
9447 return -KEY_telldir;
9456 if (name[2] == 'f' &&
9462 return -KEY_ucfirst;
9468 if (name[2] == 's' &&
9474 return -KEY_unshift;
9484 if (name[1] == 'a' &&
9491 return -KEY_waitpid;
9500 case 8: /* 26 tokens of length 8 */
9504 if (name[1] == 'U' &&
9512 return KEY_AUTOLOAD;
9523 if (name[3] == 'A' &&
9529 return KEY___DATA__;
9535 if (name[3] == 'I' &&
9541 return -KEY___FILE__;
9547 if (name[3] == 'I' &&
9553 return -KEY___LINE__;
9569 if (name[2] == 'o' &&
9576 return -KEY_closedir;
9582 if (name[2] == 'n' &&
9589 return -KEY_continue;
9599 if (name[1] == 'b' &&
9607 return -KEY_dbmclose;
9613 if (name[1] == 'n' &&
9619 if (name[4] == 'r' &&
9624 return -KEY_endgrent;
9630 if (name[4] == 'w' &&
9635 return -KEY_endpwent;
9648 if (name[1] == 'o' &&
9656 return -KEY_formline;
9662 if (name[1] == 'e' &&
9673 if (name[6] == 'n' &&
9676 return -KEY_getgrent;
9682 if (name[6] == 'i' &&
9685 return -KEY_getgrgid;
9691 if (name[6] == 'a' &&
9694 return -KEY_getgrnam;
9707 if (name[4] == 'o' &&
9712 return -KEY_getlogin;
9723 if (name[6] == 'n' &&
9726 return -KEY_getpwent;
9732 if (name[6] == 'a' &&
9735 return -KEY_getpwnam;
9741 if (name[6] == 'i' &&
9744 return -KEY_getpwuid;
9764 if (name[1] == 'e' &&
9771 if (name[5] == 'i' &&
9778 return -KEY_readline;
9783 return -KEY_readlink;
9794 if (name[5] == 'i' &&
9798 return -KEY_readpipe;
9819 if (name[4] == 'r' &&
9824 return -KEY_setgrent;
9830 if (name[4] == 'w' &&
9835 return -KEY_setpwent;
9851 if (name[3] == 'w' &&
9857 return -KEY_shmwrite;
9863 if (name[3] == 't' &&
9869 return -KEY_shutdown;
9879 if (name[2] == 's' &&
9886 return -KEY_syswrite;
9896 if (name[1] == 'r' &&
9904 return -KEY_truncate;
9913 case 9: /* 9 tokens of length 9 */
9917 if (name[1] == 'N' &&
9926 return KEY_UNITCHECK;
9932 if (name[1] == 'n' &&
9941 return -KEY_endnetent;
9947 if (name[1] == 'e' &&
9956 return -KEY_getnetent;
9962 if (name[1] == 'o' &&
9971 return -KEY_localtime;
9977 if (name[1] == 'r' &&
9986 return KEY_prototype;
9992 if (name[1] == 'u' &&
10001 return -KEY_quotemeta;
10007 if (name[1] == 'e' &&
10016 return -KEY_rewinddir;
10022 if (name[1] == 'e' &&
10031 return -KEY_setnetent;
10037 if (name[1] == 'a' &&
10046 return -KEY_wantarray;
10055 case 10: /* 9 tokens of length 10 */
10059 if (name[1] == 'n' &&
10065 if (name[4] == 'o' &&
10072 return -KEY_endhostent;
10078 if (name[4] == 'e' &&
10085 return -KEY_endservent;
10098 if (name[1] == 'e' &&
10104 if (name[4] == 'o' &&
10111 return -KEY_gethostent;
10120 if (name[5] == 'r' &&
10126 return -KEY_getservent;
10132 if (name[5] == 'c' &&
10138 return -KEY_getsockopt;
10158 if (name[2] == 't')
10163 if (name[4] == 'o' &&
10170 return -KEY_sethostent;
10179 if (name[5] == 'r' &&
10185 return -KEY_setservent;
10191 if (name[5] == 'c' &&
10197 return -KEY_setsockopt;
10214 if (name[2] == 'c' &&
10223 return -KEY_socketpair;
10236 case 11: /* 8 tokens of length 11 */
10240 if (name[1] == '_' &&
10250 { /* __PACKAGE__ */
10251 return -KEY___PACKAGE__;
10257 if (name[1] == 'n' &&
10267 { /* endprotoent */
10268 return -KEY_endprotoent;
10274 if (name[1] == 'e' &&
10283 if (name[5] == 'e' &&
10289 { /* getpeername */
10290 return -KEY_getpeername;
10299 if (name[6] == 'o' &&
10304 { /* getpriority */
10305 return -KEY_getpriority;
10311 if (name[6] == 't' &&
10316 { /* getprotoent */
10317 return -KEY_getprotoent;
10331 if (name[4] == 'o' &&
10338 { /* getsockname */
10339 return -KEY_getsockname;
10352 if (name[1] == 'e' &&
10360 if (name[6] == 'o' &&
10365 { /* setpriority */
10366 return -KEY_setpriority;
10372 if (name[6] == 't' &&
10377 { /* setprotoent */
10378 return -KEY_setprotoent;
10394 case 12: /* 2 tokens of length 12 */
10395 if (name[0] == 'g' &&
10407 if (name[9] == 'd' &&
10410 { /* getnetbyaddr */
10411 return -KEY_getnetbyaddr;
10417 if (name[9] == 'a' &&
10420 { /* getnetbyname */
10421 return -KEY_getnetbyname;
10433 case 13: /* 4 tokens of length 13 */
10434 if (name[0] == 'g' &&
10441 if (name[4] == 'o' &&
10450 if (name[10] == 'd' &&
10453 { /* gethostbyaddr */
10454 return -KEY_gethostbyaddr;
10460 if (name[10] == 'a' &&
10463 { /* gethostbyname */
10464 return -KEY_gethostbyname;
10477 if (name[4] == 'e' &&
10486 if (name[10] == 'a' &&
10489 { /* getservbyname */
10490 return -KEY_getservbyname;
10496 if (name[10] == 'o' &&
10499 { /* getservbyport */
10500 return -KEY_getservbyport;
10519 case 14: /* 1 tokens of length 14 */
10520 if (name[0] == 'g' &&
10534 { /* getprotobyname */
10535 return -KEY_getprotobyname;
10540 case 16: /* 1 tokens of length 16 */
10541 if (name[0] == 'g' &&
10557 { /* getprotobynumber */
10558 return -KEY_getprotobynumber;
10572 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10576 PERL_ARGS_ASSERT_CHECKCOMMA;
10578 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10579 if (ckWARN(WARN_SYNTAX)) {
10582 for (w = s+2; *w && level; w++) {
10585 else if (*w == ')')
10588 while (isSPACE(*w))
10590 /* the list of chars below is for end of statements or
10591 * block / parens, boolean operators (&&, ||, //) and branch
10592 * constructs (or, and, if, until, unless, while, err, for).
10593 * Not a very solid hack... */
10594 if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
10595 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10596 "%s (...) interpreted as function",name);
10599 while (s < PL_bufend && isSPACE(*s))
10603 while (s < PL_bufend && isSPACE(*s))
10605 if (isIDFIRST_lazy_if(s,UTF)) {
10606 const char * const w = s++;
10607 while (isALNUM_lazy_if(s,UTF))
10609 while (s < PL_bufend && isSPACE(*s))
10613 if (keyword(w, s - w, 0))
10616 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10617 if (gv && GvCVu(gv))
10619 Perl_croak(aTHX_ "No comma allowed after %s", what);
10624 /* Either returns sv, or mortalizes sv and returns a new SV*.
10625 Best used as sv=new_constant(..., sv, ...).
10626 If s, pv are NULL, calls subroutine with one argument,
10627 and type is used with error messages only. */
10630 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen,
10631 SV *sv, SV *pv, const char *type, STRLEN typelen)
10634 HV * const table = GvHV(PL_hintgv); /* ^H */
10638 const char *why1 = "", *why2 = "", *why3 = "";
10640 PERL_ARGS_ASSERT_NEW_CONSTANT;
10642 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10645 why2 = (const char *)
10646 (strEQ(key,"charnames")
10647 ? "(possibly a missing \"use charnames ...\")"
10649 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10650 (type ? type: "undef"), why2);
10652 /* This is convoluted and evil ("goto considered harmful")
10653 * but I do not understand the intricacies of all the different
10654 * failure modes of %^H in here. The goal here is to make
10655 * the most probable error message user-friendly. --jhi */
10660 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10661 (type ? type: "undef"), why1, why2, why3);
10663 yyerror(SvPVX_const(msg));
10667 cvp = hv_fetch(table, key, keylen, FALSE);
10668 if (!cvp || !SvOK(*cvp)) {
10671 why3 = "} is not defined";
10674 sv_2mortal(sv); /* Parent created it permanently */
10677 pv = newSVpvn_flags(s, len, SVs_TEMP);
10679 typesv = newSVpvn_flags(type, typelen, SVs_TEMP);
10681 typesv = &PL_sv_undef;
10683 PUSHSTACKi(PERLSI_OVERLOAD);
10695 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10699 /* Check the eval first */
10700 if (!PL_in_eval && SvTRUE(ERRSV)) {
10701 sv_catpvs(ERRSV, "Propagated");
10702 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10704 res = SvREFCNT_inc_simple(sv);
10708 SvREFCNT_inc_simple_void(res);
10717 why1 = "Call to &{$^H{";
10719 why3 = "}} did not return a defined value";
10727 /* Returns a NUL terminated string, with the length of the string written to
10731 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10734 register char *d = dest;
10735 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10737 PERL_ARGS_ASSERT_SCAN_WORD;
10741 Perl_croak(aTHX_ ident_too_long);
10742 if (isALNUM(*s)) /* UTF handled below */
10744 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10749 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10753 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10754 char *t = s + UTF8SKIP(s);
10756 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10760 Perl_croak(aTHX_ ident_too_long);
10761 Copy(s, d, len, char);
10774 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10777 char *bracket = NULL;
10779 register char *d = dest;
10780 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10782 PERL_ARGS_ASSERT_SCAN_IDENT;
10787 while (isDIGIT(*s)) {
10789 Perl_croak(aTHX_ ident_too_long);
10796 Perl_croak(aTHX_ ident_too_long);
10797 if (isALNUM(*s)) /* UTF handled below */
10799 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10804 else if (*s == ':' && s[1] == ':') {
10808 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10809 char *t = s + UTF8SKIP(s);
10810 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10812 if (d + (t - s) > e)
10813 Perl_croak(aTHX_ ident_too_long);
10814 Copy(s, d, t - s, char);
10825 if (PL_lex_state != LEX_NORMAL)
10826 PL_lex_state = LEX_INTERPENDMAYBE;
10829 if (*s == '$' && s[1] &&
10830 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10843 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10848 if (isSPACE(s[-1])) {
10850 const char ch = *s++;
10851 if (!SPACE_OR_TAB(ch)) {
10857 if (isIDFIRST_lazy_if(d,UTF)) {
10861 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10862 end += UTF8SKIP(end);
10863 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10864 end += UTF8SKIP(end);
10866 Copy(s, d, end - s, char);
10871 while ((isALNUM(*s) || *s == ':') && d < e)
10874 Perl_croak(aTHX_ ident_too_long);
10877 while (s < send && SPACE_OR_TAB(*s))
10879 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10880 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10881 const char * const brack =
10883 ((*s == '[') ? "[...]" : "{...}");
10884 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10885 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10886 funny, dest, brack, funny, dest, brack);
10889 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10893 /* Handle extended ${^Foo} variables
10894 * 1999-02-27 mjd-perl-patch@plover.com */
10895 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10899 while (isALNUM(*s) && d < e) {
10903 Perl_croak(aTHX_ ident_too_long);
10908 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10909 PL_lex_state = LEX_INTERPEND;
10912 if (PL_lex_state == LEX_NORMAL) {
10913 if (ckWARN(WARN_AMBIGUOUS) &&
10914 (keyword(dest, d - dest, 0)
10915 || get_cvn_flags(dest, d - dest, 0)))
10919 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10920 "Ambiguous use of %c{%s} resolved to %c%s",
10921 funny, dest, funny, dest);
10926 s = bracket; /* let the parser handle it */
10930 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10931 PL_lex_state = LEX_INTERPEND;
10936 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10938 PERL_ARGS_ASSERT_PMFLAG;
10940 PERL_UNUSED_CONTEXT;
10942 const char c = (char)ch;
10944 CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
10945 case GLOBAL_PAT_MOD: *pmfl |= PMf_GLOBAL; break;
10946 case CONTINUE_PAT_MOD: *pmfl |= PMf_CONTINUE; break;
10947 case ONCE_PAT_MOD: *pmfl |= PMf_KEEP; break;
10948 case KEEPCOPY_PAT_MOD: *pmfl |= PMf_KEEPCOPY; break;
10954 S_scan_pat(pTHX_ char *start, I32 type)
10958 char *s = scan_str(start,!!PL_madskills,FALSE);
10959 const char * const valid_flags =
10960 (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
10965 PERL_ARGS_ASSERT_SCAN_PAT;
10968 const char * const delimiter = skipspace(start);
10972 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10973 : "Search pattern not terminated" ));
10976 pm = (PMOP*)newPMOP(type, 0);
10977 if (PL_multi_open == '?') {
10978 /* This is the only point in the code that sets PMf_ONCE: */
10979 pm->op_pmflags |= PMf_ONCE;
10981 /* Hence it's safe to do this bit of PMOP book-keeping here, which
10982 allows us to restrict the list needed by reset to just the ??
10984 assert(type != OP_TRANS);
10986 MAGIC *mg = mg_find((const SV *)PL_curstash, PERL_MAGIC_symtab);
10989 mg = sv_magicext(MUTABLE_SV(PL_curstash), 0, PERL_MAGIC_symtab, 0, 0,
10992 elements = mg->mg_len / sizeof(PMOP**);
10993 Renewc(mg->mg_ptr, elements + 1, PMOP*, char);
10994 ((PMOP**)mg->mg_ptr) [elements++] = pm;
10995 mg->mg_len = elements * sizeof(PMOP**);
10996 PmopSTASH_set(pm,PL_curstash);
11002 while (*s && strchr(valid_flags, *s))
11003 pmflag(&pm->op_pmflags,*s++);
11005 if (PL_madskills && modstart != s) {
11006 SV* tmptoken = newSVpvn(modstart, s - modstart);
11007 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
11010 /* issue a warning if /c is specified,but /g is not */
11011 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
11012 && ckWARN(WARN_REGEXP))
11014 Perl_warner(aTHX_ packWARN(WARN_REGEXP),
11015 "Use of /c modifier is meaningless without /g" );
11018 PL_lex_op = (OP*)pm;
11019 pl_yylval.ival = OP_MATCH;
11024 S_scan_subst(pTHX_ char *start)
11035 PERL_ARGS_ASSERT_SCAN_SUBST;
11037 pl_yylval.ival = OP_NULL;
11039 s = scan_str(start,!!PL_madskills,FALSE);
11042 Perl_croak(aTHX_ "Substitution pattern not terminated");
11044 if (s[-1] == PL_multi_open)
11047 if (PL_madskills) {
11048 CURMAD('q', PL_thisopen);
11049 CURMAD('_', PL_thiswhite);
11050 CURMAD('E', PL_thisstuff);
11051 CURMAD('Q', PL_thisclose);
11052 PL_realtokenstart = s - SvPVX(PL_linestr);
11056 first_start = PL_multi_start;
11057 s = scan_str(s,!!PL_madskills,FALSE);
11059 if (PL_lex_stuff) {
11060 SvREFCNT_dec(PL_lex_stuff);
11061 PL_lex_stuff = NULL;
11063 Perl_croak(aTHX_ "Substitution replacement not terminated");
11065 PL_multi_start = first_start; /* so whole substitution is taken together */
11067 pm = (PMOP*)newPMOP(OP_SUBST, 0);
11070 if (PL_madskills) {
11071 CURMAD('z', PL_thisopen);
11072 CURMAD('R', PL_thisstuff);
11073 CURMAD('Z', PL_thisclose);
11079 if (*s == EXEC_PAT_MOD) {
11083 else if (strchr(S_PAT_MODS, *s))
11084 pmflag(&pm->op_pmflags,*s++);
11090 if (PL_madskills) {
11092 curmad('m', newSVpvn(modstart, s - modstart));
11093 append_madprops(PL_thismad, (OP*)pm, 0);
11097 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
11098 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
11102 SV * const repl = newSVpvs("");
11104 PL_sublex_info.super_bufptr = s;
11105 PL_sublex_info.super_bufend = PL_bufend;
11107 pm->op_pmflags |= PMf_EVAL;
11110 sv_catpvs(repl, "eval ");
11112 sv_catpvs(repl, "do ");
11114 sv_catpvs(repl, "{");
11115 sv_catsv(repl, PL_lex_repl);
11116 if (strchr(SvPVX(PL_lex_repl), '#'))
11117 sv_catpvs(repl, "\n");
11118 sv_catpvs(repl, "}");
11120 SvREFCNT_dec(PL_lex_repl);
11121 PL_lex_repl = repl;
11124 PL_lex_op = (OP*)pm;
11125 pl_yylval.ival = OP_SUBST;
11130 S_scan_trans(pTHX_ char *start)
11143 PERL_ARGS_ASSERT_SCAN_TRANS;
11145 pl_yylval.ival = OP_NULL;
11147 s = scan_str(start,!!PL_madskills,FALSE);
11149 Perl_croak(aTHX_ "Transliteration pattern not terminated");
11151 if (s[-1] == PL_multi_open)
11154 if (PL_madskills) {
11155 CURMAD('q', PL_thisopen);
11156 CURMAD('_', PL_thiswhite);
11157 CURMAD('E', PL_thisstuff);
11158 CURMAD('Q', PL_thisclose);
11159 PL_realtokenstart = s - SvPVX(PL_linestr);
11163 s = scan_str(s,!!PL_madskills,FALSE);
11165 if (PL_lex_stuff) {
11166 SvREFCNT_dec(PL_lex_stuff);
11167 PL_lex_stuff = NULL;
11169 Perl_croak(aTHX_ "Transliteration replacement not terminated");
11171 if (PL_madskills) {
11172 CURMAD('z', PL_thisopen);
11173 CURMAD('R', PL_thisstuff);
11174 CURMAD('Z', PL_thisclose);
11177 complement = del = squash = 0;
11184 complement = OPpTRANS_COMPLEMENT;
11187 del = OPpTRANS_DELETE;
11190 squash = OPpTRANS_SQUASH;
11199 tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
11200 o = newPVOP(OP_TRANS, 0, (char*)tbl);
11201 o->op_private &= ~OPpTRANS_ALL;
11202 o->op_private |= del|squash|complement|
11203 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
11204 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
11207 pl_yylval.ival = OP_TRANS;
11210 if (PL_madskills) {
11212 curmad('m', newSVpvn(modstart, s - modstart));
11213 append_madprops(PL_thismad, o, 0);
11222 S_scan_heredoc(pTHX_ register char *s)
11226 I32 op_type = OP_SCALAR;
11230 const char *found_newline;
11234 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
11236 I32 stuffstart = s - SvPVX(PL_linestr);
11239 PL_realtokenstart = -1;
11242 PERL_ARGS_ASSERT_SCAN_HEREDOC;
11246 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
11250 while (SPACE_OR_TAB(*peek))
11252 if (*peek == '`' || *peek == '\'' || *peek =='"') {
11255 s = delimcpy(d, e, s, PL_bufend, term, &len);
11265 if (!isALNUM_lazy_if(s,UTF))
11266 deprecate_old("bare << to mean <<\"\"");
11267 for (; isALNUM_lazy_if(s,UTF); s++) {
11272 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
11273 Perl_croak(aTHX_ "Delimiter for here document is too long");
11276 len = d - PL_tokenbuf;
11279 if (PL_madskills) {
11280 tstart = PL_tokenbuf + !outer;
11281 PL_thisclose = newSVpvn(tstart, len - !outer);
11282 tstart = SvPVX(PL_linestr) + stuffstart;
11283 PL_thisopen = newSVpvn(tstart, s - tstart);
11284 stuffstart = s - SvPVX(PL_linestr);
11287 #ifndef PERL_STRICT_CR
11288 d = strchr(s, '\r');
11290 char * const olds = s;
11292 while (s < PL_bufend) {
11298 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11307 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11314 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11315 herewas = newSVpvn(s,PL_bufend-s);
11319 herewas = newSVpvn(s-1,found_newline-s+1);
11322 herewas = newSVpvn(s,found_newline-s);
11326 if (PL_madskills) {
11327 tstart = SvPVX(PL_linestr) + stuffstart;
11329 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11331 PL_thisstuff = newSVpvn(tstart, s - tstart);
11334 s += SvCUR(herewas);
11337 stuffstart = s - SvPVX(PL_linestr);
11343 tmpstr = newSV_type(SVt_PVIV);
11344 SvGROW(tmpstr, 80);
11345 if (term == '\'') {
11346 op_type = OP_CONST;
11347 SvIV_set(tmpstr, -1);
11349 else if (term == '`') {
11350 op_type = OP_BACKTICK;
11351 SvIV_set(tmpstr, '\\');
11355 PL_multi_start = CopLINE(PL_curcop);
11356 PL_multi_open = PL_multi_close = '<';
11357 term = *PL_tokenbuf;
11358 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11359 char * const bufptr = PL_sublex_info.super_bufptr;
11360 char * const bufend = PL_sublex_info.super_bufend;
11361 char * const olds = s - SvCUR(herewas);
11362 s = strchr(bufptr, '\n');
11366 while (s < bufend &&
11367 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11369 CopLINE_inc(PL_curcop);
11372 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11373 missingterm(PL_tokenbuf);
11375 sv_setpvn(herewas,bufptr,d-bufptr+1);
11376 sv_setpvn(tmpstr,d+1,s-d);
11378 sv_catpvn(herewas,s,bufend-s);
11379 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11386 while (s < PL_bufend &&
11387 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11389 CopLINE_inc(PL_curcop);
11391 if (s >= PL_bufend) {
11392 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11393 missingterm(PL_tokenbuf);
11395 sv_setpvn(tmpstr,d+1,s-d);
11397 if (PL_madskills) {
11399 sv_catpvn(PL_thisstuff, d + 1, s - d);
11401 PL_thisstuff = newSVpvn(d + 1, s - d);
11402 stuffstart = s - SvPVX(PL_linestr);
11406 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11408 sv_catpvn(herewas,s,PL_bufend-s);
11409 sv_setsv(PL_linestr,herewas);
11410 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11411 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11412 PL_last_lop = PL_last_uni = NULL;
11415 sv_setpvs(tmpstr,""); /* avoid "uninitialized" warning */
11416 while (s >= PL_bufend) { /* multiple line string? */
11418 if (PL_madskills) {
11419 tstart = SvPVX(PL_linestr) + stuffstart;
11421 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11423 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11427 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11428 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11429 missingterm(PL_tokenbuf);
11432 stuffstart = s - SvPVX(PL_linestr);
11434 CopLINE_inc(PL_curcop);
11435 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11436 PL_last_lop = PL_last_uni = NULL;
11437 #ifndef PERL_STRICT_CR
11438 if (PL_bufend - PL_linestart >= 2) {
11439 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11440 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11442 PL_bufend[-2] = '\n';
11444 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11446 else if (PL_bufend[-1] == '\r')
11447 PL_bufend[-1] = '\n';
11449 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11450 PL_bufend[-1] = '\n';
11452 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
11453 update_debugger_info(PL_linestr, NULL, 0);
11454 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11455 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11456 *(SvPVX(PL_linestr) + off ) = ' ';
11457 sv_catsv(PL_linestr,herewas);
11458 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11459 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11463 sv_catsv(tmpstr,PL_linestr);
11468 PL_multi_end = CopLINE(PL_curcop);
11469 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11470 SvPV_shrink_to_cur(tmpstr);
11472 SvREFCNT_dec(herewas);
11474 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11476 else if (PL_encoding)
11477 sv_recode_to_utf8(tmpstr, PL_encoding);
11479 PL_lex_stuff = tmpstr;
11480 pl_yylval.ival = op_type;
11484 /* scan_inputsymbol
11485 takes: current position in input buffer
11486 returns: new position in input buffer
11487 side-effects: pl_yylval and lex_op are set.
11492 <FH> read from filehandle
11493 <pkg::FH> read from package qualified filehandle
11494 <pkg'FH> read from package qualified filehandle
11495 <$fh> read from filehandle in $fh
11496 <*.h> filename glob
11501 S_scan_inputsymbol(pTHX_ char *start)
11504 register char *s = start; /* current position in buffer */
11507 char *d = PL_tokenbuf; /* start of temp holding space */
11508 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11510 PERL_ARGS_ASSERT_SCAN_INPUTSYMBOL;
11512 end = strchr(s, '\n');
11515 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11517 /* die if we didn't have space for the contents of the <>,
11518 or if it didn't end, or if we see a newline
11521 if (len >= (I32)sizeof PL_tokenbuf)
11522 Perl_croak(aTHX_ "Excessively long <> operator");
11524 Perl_croak(aTHX_ "Unterminated <> operator");
11529 Remember, only scalar variables are interpreted as filehandles by
11530 this code. Anything more complex (e.g., <$fh{$num}>) will be
11531 treated as a glob() call.
11532 This code makes use of the fact that except for the $ at the front,
11533 a scalar variable and a filehandle look the same.
11535 if (*d == '$' && d[1]) d++;
11537 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11538 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11541 /* If we've tried to read what we allow filehandles to look like, and
11542 there's still text left, then it must be a glob() and not a getline.
11543 Use scan_str to pull out the stuff between the <> and treat it
11544 as nothing more than a string.
11547 if (d - PL_tokenbuf != len) {
11548 pl_yylval.ival = OP_GLOB;
11549 s = scan_str(start,!!PL_madskills,FALSE);
11551 Perl_croak(aTHX_ "Glob not terminated");
11555 bool readline_overriden = FALSE;
11558 /* we're in a filehandle read situation */
11561 /* turn <> into <ARGV> */
11563 Copy("ARGV",d,5,char);
11565 /* Check whether readline() is overriden */
11566 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11568 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11570 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11571 && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
11572 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11573 readline_overriden = TRUE;
11575 /* if <$fh>, create the ops to turn the variable into a
11579 /* try to find it in the pad for this block, otherwise find
11580 add symbol table ops
11582 const PADOFFSET tmp = pad_findmy(d);
11583 if (tmp != NOT_IN_PAD) {
11584 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11585 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11586 HEK * const stashname = HvNAME_HEK(stash);
11587 SV * const sym = sv_2mortal(newSVhek(stashname));
11588 sv_catpvs(sym, "::");
11589 sv_catpv(sym, d+1);
11594 OP * const o = newOP(OP_PADSV, 0);
11596 PL_lex_op = readline_overriden
11597 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11598 append_elem(OP_LIST, o,
11599 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11600 : (OP*)newUNOP(OP_READLINE, 0, o);
11609 ? (GV_ADDMULTI | GV_ADDINEVAL)
11612 PL_lex_op = readline_overriden
11613 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11614 append_elem(OP_LIST,
11615 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11616 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11617 : (OP*)newUNOP(OP_READLINE, 0,
11618 newUNOP(OP_RV2SV, 0,
11619 newGVOP(OP_GV, 0, gv)));
11621 if (!readline_overriden)
11622 PL_lex_op->op_flags |= OPf_SPECIAL;
11623 /* we created the ops in PL_lex_op, so make pl_yylval.ival a null op */
11624 pl_yylval.ival = OP_NULL;
11627 /* If it's none of the above, it must be a literal filehandle
11628 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11630 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11631 PL_lex_op = readline_overriden
11632 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11633 append_elem(OP_LIST,
11634 newGVOP(OP_GV, 0, gv),
11635 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11636 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11637 pl_yylval.ival = OP_NULL;
11646 takes: start position in buffer
11647 keep_quoted preserve \ on the embedded delimiter(s)
11648 keep_delims preserve the delimiters around the string
11649 returns: position to continue reading from buffer
11650 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11651 updates the read buffer.
11653 This subroutine pulls a string out of the input. It is called for:
11654 q single quotes q(literal text)
11655 ' single quotes 'literal text'
11656 qq double quotes qq(interpolate $here please)
11657 " double quotes "interpolate $here please"
11658 qx backticks qx(/bin/ls -l)
11659 ` backticks `/bin/ls -l`
11660 qw quote words @EXPORT_OK = qw( func() $spam )
11661 m// regexp match m/this/
11662 s/// regexp substitute s/this/that/
11663 tr/// string transliterate tr/this/that/
11664 y/// string transliterate y/this/that/
11665 ($*@) sub prototypes sub foo ($)
11666 (stuff) sub attr parameters sub foo : attr(stuff)
11667 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11669 In most of these cases (all but <>, patterns and transliterate)
11670 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11671 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11672 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11675 It skips whitespace before the string starts, and treats the first
11676 character as the delimiter. If the delimiter is one of ([{< then
11677 the corresponding "close" character )]}> is used as the closing
11678 delimiter. It allows quoting of delimiters, and if the string has
11679 balanced delimiters ([{<>}]) it allows nesting.
11681 On success, the SV with the resulting string is put into lex_stuff or,
11682 if that is already non-NULL, into lex_repl. The second case occurs only
11683 when parsing the RHS of the special constructs s/// and tr/// (y///).
11684 For convenience, the terminating delimiter character is stuffed into
11689 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11692 SV *sv; /* scalar value: string */
11693 const char *tmps; /* temp string, used for delimiter matching */
11694 register char *s = start; /* current position in the buffer */
11695 register char term; /* terminating character */
11696 register char *to; /* current position in the sv's data */
11697 I32 brackets = 1; /* bracket nesting level */
11698 bool has_utf8 = FALSE; /* is there any utf8 content? */
11699 I32 termcode; /* terminating char. code */
11700 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11701 STRLEN termlen; /* length of terminating string */
11702 int last_off = 0; /* last position for nesting bracket */
11708 PERL_ARGS_ASSERT_SCAN_STR;
11710 /* skip space before the delimiter */
11716 if (PL_realtokenstart >= 0) {
11717 stuffstart = PL_realtokenstart;
11718 PL_realtokenstart = -1;
11721 stuffstart = start - SvPVX(PL_linestr);
11723 /* mark where we are, in case we need to report errors */
11726 /* after skipping whitespace, the next character is the terminator */
11729 termcode = termstr[0] = term;
11733 termcode = utf8_to_uvchr((U8*)s, &termlen);
11734 Copy(s, termstr, termlen, U8);
11735 if (!UTF8_IS_INVARIANT(term))
11739 /* mark where we are */
11740 PL_multi_start = CopLINE(PL_curcop);
11741 PL_multi_open = term;
11743 /* find corresponding closing delimiter */
11744 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11745 termcode = termstr[0] = term = tmps[5];
11747 PL_multi_close = term;
11749 /* create a new SV to hold the contents. 79 is the SV's initial length.
11750 What a random number. */
11751 sv = newSV_type(SVt_PVIV);
11753 SvIV_set(sv, termcode);
11754 (void)SvPOK_only(sv); /* validate pointer */
11756 /* move past delimiter and try to read a complete string */
11758 sv_catpvn(sv, s, termlen);
11761 tstart = SvPVX(PL_linestr) + stuffstart;
11762 if (!PL_thisopen && !keep_delims) {
11763 PL_thisopen = newSVpvn(tstart, s - tstart);
11764 stuffstart = s - SvPVX(PL_linestr);
11768 if (PL_encoding && !UTF) {
11772 int offset = s - SvPVX_const(PL_linestr);
11773 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11774 &offset, (char*)termstr, termlen);
11775 const char * const ns = SvPVX_const(PL_linestr) + offset;
11776 char * const svlast = SvEND(sv) - 1;
11778 for (; s < ns; s++) {
11779 if (*s == '\n' && !PL_rsfp)
11780 CopLINE_inc(PL_curcop);
11783 goto read_more_line;
11785 /* handle quoted delimiters */
11786 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11788 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11790 if ((svlast-1 - t) % 2) {
11791 if (!keep_quoted) {
11792 *(svlast-1) = term;
11794 SvCUR_set(sv, SvCUR(sv) - 1);
11799 if (PL_multi_open == PL_multi_close) {
11805 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
11806 /* At here, all closes are "was quoted" one,
11807 so we don't check PL_multi_close. */
11809 if (!keep_quoted && *(t+1) == PL_multi_open)
11814 else if (*t == PL_multi_open)
11822 SvCUR_set(sv, w - SvPVX_const(sv));
11824 last_off = w - SvPVX(sv);
11825 if (--brackets <= 0)
11830 if (!keep_delims) {
11831 SvCUR_set(sv, SvCUR(sv) - 1);
11837 /* extend sv if need be */
11838 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11839 /* set 'to' to the next character in the sv's string */
11840 to = SvPVX(sv)+SvCUR(sv);
11842 /* if open delimiter is the close delimiter read unbridle */
11843 if (PL_multi_open == PL_multi_close) {
11844 for (; s < PL_bufend; s++,to++) {
11845 /* embedded newlines increment the current line number */
11846 if (*s == '\n' && !PL_rsfp)
11847 CopLINE_inc(PL_curcop);
11848 /* handle quoted delimiters */
11849 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11850 if (!keep_quoted && s[1] == term)
11852 /* any other quotes are simply copied straight through */
11856 /* terminate when run out of buffer (the for() condition), or
11857 have found the terminator */
11858 else if (*s == term) {
11861 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11864 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11870 /* if the terminator isn't the same as the start character (e.g.,
11871 matched brackets), we have to allow more in the quoting, and
11872 be prepared for nested brackets.
11875 /* read until we run out of string, or we find the terminator */
11876 for (; s < PL_bufend; s++,to++) {
11877 /* embedded newlines increment the line count */
11878 if (*s == '\n' && !PL_rsfp)
11879 CopLINE_inc(PL_curcop);
11880 /* backslashes can escape the open or closing characters */
11881 if (*s == '\\' && s+1 < PL_bufend) {
11882 if (!keep_quoted &&
11883 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11888 /* allow nested opens and closes */
11889 else if (*s == PL_multi_close && --brackets <= 0)
11891 else if (*s == PL_multi_open)
11893 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11898 /* terminate the copied string and update the sv's end-of-string */
11900 SvCUR_set(sv, to - SvPVX_const(sv));
11903 * this next chunk reads more into the buffer if we're not done yet
11907 break; /* handle case where we are done yet :-) */
11909 #ifndef PERL_STRICT_CR
11910 if (to - SvPVX_const(sv) >= 2) {
11911 if ((to[-2] == '\r' && to[-1] == '\n') ||
11912 (to[-2] == '\n' && to[-1] == '\r'))
11916 SvCUR_set(sv, to - SvPVX_const(sv));
11918 else if (to[-1] == '\r')
11921 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11926 /* if we're out of file, or a read fails, bail and reset the current
11927 line marker so we can report where the unterminated string began
11930 if (PL_madskills) {
11931 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11933 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11935 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11939 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11941 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11947 /* we read a line, so increment our line counter */
11948 CopLINE_inc(PL_curcop);
11950 /* update debugger info */
11951 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
11952 update_debugger_info(PL_linestr, NULL, 0);
11954 /* having changed the buffer, we must update PL_bufend */
11955 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11956 PL_last_lop = PL_last_uni = NULL;
11959 /* at this point, we have successfully read the delimited string */
11961 if (!PL_encoding || UTF) {
11963 if (PL_madskills) {
11964 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11965 const int len = s - tstart;
11967 sv_catpvn(PL_thisstuff, tstart, len);
11969 PL_thisstuff = newSVpvn(tstart, len);
11970 if (!PL_thisclose && !keep_delims)
11971 PL_thisclose = newSVpvn(s,termlen);
11976 sv_catpvn(sv, s, termlen);
11981 if (PL_madskills) {
11982 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11983 const int len = s - tstart - termlen;
11985 sv_catpvn(PL_thisstuff, tstart, len);
11987 PL_thisstuff = newSVpvn(tstart, len);
11988 if (!PL_thisclose && !keep_delims)
11989 PL_thisclose = newSVpvn(s - termlen,termlen);
11993 if (has_utf8 || PL_encoding)
11996 PL_multi_end = CopLINE(PL_curcop);
11998 /* if we allocated too much space, give some back */
11999 if (SvCUR(sv) + 5 < SvLEN(sv)) {
12000 SvLEN_set(sv, SvCUR(sv) + 1);
12001 SvPV_renew(sv, SvLEN(sv));
12004 /* decide whether this is the first or second quoted string we've read
12017 takes: pointer to position in buffer
12018 returns: pointer to new position in buffer
12019 side-effects: builds ops for the constant in pl_yylval.op
12021 Read a number in any of the formats that Perl accepts:
12023 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
12024 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
12027 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
12029 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
12032 If it reads a number without a decimal point or an exponent, it will
12033 try converting the number to an integer and see if it can do so
12034 without loss of precision.
12038 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
12041 register const char *s = start; /* current position in buffer */
12042 register char *d; /* destination in temp buffer */
12043 register char *e; /* end of temp buffer */
12044 NV nv; /* number read, as a double */
12045 SV *sv = NULL; /* place to put the converted number */
12046 bool floatit; /* boolean: int or float? */
12047 const char *lastub = NULL; /* position of last underbar */
12048 static char const number_too_long[] = "Number too long";
12050 PERL_ARGS_ASSERT_SCAN_NUM;
12052 /* We use the first character to decide what type of number this is */
12056 Perl_croak(aTHX_ "panic: scan_num");
12058 /* if it starts with a 0, it could be an octal number, a decimal in
12059 0.13 disguise, or a hexadecimal number, or a binary number. */
12063 u holds the "number so far"
12064 shift the power of 2 of the base
12065 (hex == 4, octal == 3, binary == 1)
12066 overflowed was the number more than we can hold?
12068 Shift is used when we add a digit. It also serves as an "are
12069 we in octal/hex/binary?" indicator to disallow hex characters
12070 when in octal mode.
12075 bool overflowed = FALSE;
12076 bool just_zero = TRUE; /* just plain 0 or binary number? */
12077 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
12078 static const char* const bases[5] =
12079 { "", "binary", "", "octal", "hexadecimal" };
12080 static const char* const Bases[5] =
12081 { "", "Binary", "", "Octal", "Hexadecimal" };
12082 static const char* const maxima[5] =
12084 "0b11111111111111111111111111111111",
12088 const char *base, *Base, *max;
12090 /* check for hex */
12095 } else if (s[1] == 'b') {
12100 /* check for a decimal in disguise */
12101 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
12103 /* so it must be octal */
12110 if (ckWARN(WARN_SYNTAX))
12111 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12112 "Misplaced _ in number");
12116 base = bases[shift];
12117 Base = Bases[shift];
12118 max = maxima[shift];
12120 /* read the rest of the number */
12122 /* x is used in the overflow test,
12123 b is the digit we're adding on. */
12128 /* if we don't mention it, we're done */
12132 /* _ are ignored -- but warned about if consecutive */
12134 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12135 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12136 "Misplaced _ in number");
12140 /* 8 and 9 are not octal */
12141 case '8': case '9':
12143 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
12147 case '2': case '3': case '4':
12148 case '5': case '6': case '7':
12150 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
12153 case '0': case '1':
12154 b = *s++ & 15; /* ASCII digit -> value of digit */
12158 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
12159 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
12160 /* make sure they said 0x */
12163 b = (*s++ & 7) + 9;
12165 /* Prepare to put the digit we have onto the end
12166 of the number so far. We check for overflows.
12172 x = u << shift; /* make room for the digit */
12174 if ((x >> shift) != u
12175 && !(PL_hints & HINT_NEW_BINARY)) {
12178 if (ckWARN_d(WARN_OVERFLOW))
12179 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12180 "Integer overflow in %s number",
12183 u = x | b; /* add the digit to the end */
12186 n *= nvshift[shift];
12187 /* If an NV has not enough bits in its
12188 * mantissa to represent an UV this summing of
12189 * small low-order numbers is a waste of time
12190 * (because the NV cannot preserve the
12191 * low-order bits anyway): we could just
12192 * remember when did we overflow and in the
12193 * end just multiply n by the right
12201 /* if we get here, we had success: make a scalar value from
12206 /* final misplaced underbar check */
12207 if (s[-1] == '_') {
12208 if (ckWARN(WARN_SYNTAX))
12209 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12214 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
12215 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12216 "%s number > %s non-portable",
12222 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
12223 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12224 "%s number > %s non-portable",
12229 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
12230 sv = new_constant(start, s - start, "integer",
12231 sv, NULL, NULL, 0);
12232 else if (PL_hints & HINT_NEW_BINARY)
12233 sv = new_constant(start, s - start, "binary", sv, NULL, NULL, 0);
12238 handle decimal numbers.
12239 we're also sent here when we read a 0 as the first digit
12241 case '1': case '2': case '3': case '4': case '5':
12242 case '6': case '7': case '8': case '9': case '.':
12245 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
12248 /* read next group of digits and _ and copy into d */
12249 while (isDIGIT(*s) || *s == '_') {
12250 /* skip underscores, checking for misplaced ones
12254 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12255 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12256 "Misplaced _ in number");
12260 /* check for end of fixed-length buffer */
12262 Perl_croak(aTHX_ number_too_long);
12263 /* if we're ok, copy the character */
12268 /* final misplaced underbar check */
12269 if (lastub && s == lastub + 1) {
12270 if (ckWARN(WARN_SYNTAX))
12271 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12274 /* read a decimal portion if there is one. avoid
12275 3..5 being interpreted as the number 3. followed
12278 if (*s == '.' && s[1] != '.') {
12283 if (ckWARN(WARN_SYNTAX))
12284 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12285 "Misplaced _ in number");
12289 /* copy, ignoring underbars, until we run out of digits.
12291 for (; isDIGIT(*s) || *s == '_'; s++) {
12292 /* fixed length buffer check */
12294 Perl_croak(aTHX_ number_too_long);
12296 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12297 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12298 "Misplaced _ in number");
12304 /* fractional part ending in underbar? */
12305 if (s[-1] == '_') {
12306 if (ckWARN(WARN_SYNTAX))
12307 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12308 "Misplaced _ in number");
12310 if (*s == '.' && isDIGIT(s[1])) {
12311 /* oops, it's really a v-string, but without the "v" */
12317 /* read exponent part, if present */
12318 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12322 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12323 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12325 /* stray preinitial _ */
12327 if (ckWARN(WARN_SYNTAX))
12328 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12329 "Misplaced _ in number");
12333 /* allow positive or negative exponent */
12334 if (*s == '+' || *s == '-')
12337 /* stray initial _ */
12339 if (ckWARN(WARN_SYNTAX))
12340 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12341 "Misplaced _ in number");
12345 /* read digits of exponent */
12346 while (isDIGIT(*s) || *s == '_') {
12349 Perl_croak(aTHX_ number_too_long);
12353 if (((lastub && s == lastub + 1) ||
12354 (!isDIGIT(s[1]) && s[1] != '_'))
12355 && ckWARN(WARN_SYNTAX))
12356 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12357 "Misplaced _ in number");
12364 /* make an sv from the string */
12368 We try to do an integer conversion first if no characters
12369 indicating "float" have been found.
12374 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12376 if (flags == IS_NUMBER_IN_UV) {
12378 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12381 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12382 if (uv <= (UV) IV_MIN)
12383 sv_setiv(sv, -(IV)uv);
12390 /* terminate the string */
12392 nv = Atof(PL_tokenbuf);
12397 ? (PL_hints & HINT_NEW_FLOAT) : (PL_hints & HINT_NEW_INTEGER) ) {
12398 const char *const key = floatit ? "float" : "integer";
12399 const STRLEN keylen = floatit ? 5 : 7;
12400 sv = S_new_constant(aTHX_ PL_tokenbuf, d - PL_tokenbuf,
12401 key, keylen, sv, NULL, NULL, 0);
12405 /* if it starts with a v, it could be a v-string */
12408 sv = newSV(5); /* preallocate storage space */
12409 s = scan_vstring(s, PL_bufend, sv);
12413 /* make the op for the constant and return */
12416 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12418 lvalp->opval = NULL;
12424 S_scan_formline(pTHX_ register char *s)
12427 register char *eol;
12429 SV * const stuff = newSVpvs("");
12430 bool needargs = FALSE;
12431 bool eofmt = FALSE;
12433 char *tokenstart = s;
12434 SV* savewhite = NULL;
12436 if (PL_madskills) {
12437 savewhite = PL_thiswhite;
12442 PERL_ARGS_ASSERT_SCAN_FORMLINE;
12444 while (!needargs) {
12447 #ifdef PERL_STRICT_CR
12448 while (SPACE_OR_TAB(*t))
12451 while (SPACE_OR_TAB(*t) || *t == '\r')
12454 if (*t == '\n' || t == PL_bufend) {
12459 if (PL_in_eval && !PL_rsfp) {
12460 eol = (char *) memchr(s,'\n',PL_bufend-s);
12465 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12467 for (t = s; t < eol; t++) {
12468 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12470 goto enough; /* ~~ must be first line in formline */
12472 if (*t == '@' || *t == '^')
12476 sv_catpvn(stuff, s, eol-s);
12477 #ifndef PERL_STRICT_CR
12478 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12479 char *end = SvPVX(stuff) + SvCUR(stuff);
12482 SvCUR_set(stuff, SvCUR(stuff) - 1);
12492 if (PL_madskills) {
12494 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12496 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12499 s = filter_gets(PL_linestr, PL_rsfp, 0);
12501 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12503 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12505 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12506 PL_last_lop = PL_last_uni = NULL;
12515 if (SvCUR(stuff)) {
12518 PL_lex_state = LEX_NORMAL;
12519 start_force(PL_curforce);
12520 NEXTVAL_NEXTTOKE.ival = 0;
12524 PL_lex_state = LEX_FORMLINE;
12526 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12528 else if (PL_encoding)
12529 sv_recode_to_utf8(stuff, PL_encoding);
12531 start_force(PL_curforce);
12532 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12534 start_force(PL_curforce);
12535 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12539 SvREFCNT_dec(stuff);
12541 PL_lex_formbrack = 0;
12545 if (PL_madskills) {
12547 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12549 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12550 PL_thiswhite = savewhite;
12557 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12560 const I32 oldsavestack_ix = PL_savestack_ix;
12561 CV* const outsidecv = PL_compcv;
12564 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12566 SAVEI32(PL_subline);
12567 save_item(PL_subname);
12568 SAVESPTR(PL_compcv);
12570 PL_compcv = MUTABLE_CV(newSV_type(is_format ? SVt_PVFM : SVt_PVCV));
12571 CvFLAGS(PL_compcv) |= flags;
12573 PL_subline = CopLINE(PL_curcop);
12574 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12575 CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv));
12576 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12578 return oldsavestack_ix;
12582 #pragma segment Perl_yylex
12585 Perl_yywarn(pTHX_ const char *const s)
12589 PERL_ARGS_ASSERT_YYWARN;
12591 PL_in_eval |= EVAL_WARNONLY;
12593 PL_in_eval &= ~EVAL_WARNONLY;
12598 Perl_yyerror(pTHX_ const char *const s)
12601 const char *where = NULL;
12602 const char *context = NULL;
12605 int yychar = PL_parser->yychar;
12607 PERL_ARGS_ASSERT_YYERROR;
12609 if (!yychar || (yychar == ';' && !PL_rsfp))
12611 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12612 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12613 PL_oldbufptr != PL_bufptr) {
12616 The code below is removed for NetWare because it abends/crashes on NetWare
12617 when the script has error such as not having the closing quotes like:
12618 if ($var eq "value)
12619 Checking of white spaces is anyway done in NetWare code.
12622 while (isSPACE(*PL_oldoldbufptr))
12625 context = PL_oldoldbufptr;
12626 contlen = PL_bufptr - PL_oldoldbufptr;
12628 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12629 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12632 The code below is removed for NetWare because it abends/crashes on NetWare
12633 when the script has error such as not having the closing quotes like:
12634 if ($var eq "value)
12635 Checking of white spaces is anyway done in NetWare code.
12638 while (isSPACE(*PL_oldbufptr))
12641 context = PL_oldbufptr;
12642 contlen = PL_bufptr - PL_oldbufptr;
12644 else if (yychar > 255)
12645 where = "next token ???";
12646 else if (yychar == -2) { /* YYEMPTY */
12647 if (PL_lex_state == LEX_NORMAL ||
12648 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12649 where = "at end of line";
12650 else if (PL_lex_inpat)
12651 where = "within pattern";
12653 where = "within string";
12656 SV * const where_sv = newSVpvs_flags("next char ", SVs_TEMP);
12658 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12659 else if (isPRINT_LC(yychar)) {
12660 const char string = yychar;
12661 sv_catpvn(where_sv, &string, 1);
12664 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12665 where = SvPVX_const(where_sv);
12667 msg = sv_2mortal(newSVpv(s, 0));
12668 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12669 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12671 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12673 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12674 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12675 Perl_sv_catpvf(aTHX_ msg,
12676 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12677 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12680 if (PL_in_eval & EVAL_WARNONLY) {
12681 if (ckWARN_d(WARN_SYNTAX))
12682 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
12686 if (PL_error_count >= 10) {
12687 if (PL_in_eval && SvCUR(ERRSV))
12688 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12689 SVfARG(ERRSV), OutCopFILE(PL_curcop));
12691 Perl_croak(aTHX_ "%s has too many errors.\n",
12692 OutCopFILE(PL_curcop));
12695 PL_in_my_stash = NULL;
12699 #pragma segment Main
12703 S_swallow_bom(pTHX_ U8 *s)
12706 const STRLEN slen = SvCUR(PL_linestr);
12708 PERL_ARGS_ASSERT_SWALLOW_BOM;
12712 if (s[1] == 0xFE) {
12713 /* UTF-16 little-endian? (or UTF32-LE?) */
12714 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12715 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12716 #ifndef PERL_NO_UTF16_FILTER
12717 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12720 if (PL_bufend > (char*)s) {
12724 filter_add(utf16rev_textfilter, NULL);
12725 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12726 utf16_to_utf8_reversed(s, news,
12727 PL_bufend - (char*)s - 1,
12729 sv_setpvn(PL_linestr, (const char*)news, newlen);
12731 s = (U8*)SvPVX(PL_linestr);
12732 Copy(news, s, newlen, U8);
12736 SvUTF8_on(PL_linestr);
12737 s = (U8*)SvPVX(PL_linestr);
12739 /* FIXME - is this a general bug fix? */
12742 PL_bufend = SvPVX(PL_linestr) + newlen;
12745 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12750 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12751 #ifndef PERL_NO_UTF16_FILTER
12752 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12755 if (PL_bufend > (char *)s) {
12759 filter_add(utf16_textfilter, NULL);
12760 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12761 utf16_to_utf8(s, news,
12762 PL_bufend - (char*)s,
12764 sv_setpvn(PL_linestr, (const char*)news, newlen);
12766 SvUTF8_on(PL_linestr);
12767 s = (U8*)SvPVX(PL_linestr);
12768 PL_bufend = SvPVX(PL_linestr) + newlen;
12771 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12776 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12777 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12778 s += 3; /* UTF-8 */
12784 if (s[2] == 0xFE && s[3] == 0xFF) {
12785 /* UTF-32 big-endian */
12786 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12789 else if (s[2] == 0 && s[3] != 0) {
12792 * are a good indicator of UTF-16BE. */
12793 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12799 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12800 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12801 s += 4; /* UTF-8 */
12807 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12810 * are a good indicator of UTF-16LE. */
12811 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12819 #ifndef PERL_NO_UTF16_FILTER
12821 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12824 const STRLEN old = SvCUR(sv);
12825 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12826 DEBUG_P(PerlIO_printf(Perl_debug_log,
12827 "utf16_textfilter(%p): %d %d (%d)\n",
12828 FPTR2DPTR(void *, utf16_textfilter),
12829 idx, maxlen, (int) count));
12833 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12834 Copy(SvPVX_const(sv), tmps, old, char);
12835 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12836 SvCUR(sv) - old, &newlen);
12837 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12839 DEBUG_P({sv_dump(sv);});
12844 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12847 const STRLEN old = SvCUR(sv);
12848 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12849 DEBUG_P(PerlIO_printf(Perl_debug_log,
12850 "utf16rev_textfilter(%p): %d %d (%d)\n",
12851 FPTR2DPTR(void *, utf16rev_textfilter),
12852 idx, maxlen, (int) count));
12856 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12857 Copy(SvPVX_const(sv), tmps, old, char);
12858 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12859 SvCUR(sv) - old, &newlen);
12860 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12862 DEBUG_P({ sv_dump(sv); });
12868 Returns a pointer to the next character after the parsed
12869 vstring, as well as updating the passed in sv.
12871 Function must be called like
12874 s = scan_vstring(s,e,sv);
12876 where s and e are the start and end of the string.
12877 The sv should already be large enough to store the vstring
12878 passed in, for performance reasons.
12883 Perl_scan_vstring(pTHX_ const char *s, const char *const e, SV *sv)
12886 const char *pos = s;
12887 const char *start = s;
12889 PERL_ARGS_ASSERT_SCAN_VSTRING;
12891 if (*pos == 'v') pos++; /* get past 'v' */
12892 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12894 if ( *pos != '.') {
12895 /* this may not be a v-string if followed by => */
12896 const char *next = pos;
12897 while (next < e && isSPACE(*next))
12899 if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
12900 /* return string not v-string */
12901 sv_setpvn(sv,(char *)s,pos-s);
12902 return (char *)pos;
12906 if (!isALPHA(*pos)) {
12907 U8 tmpbuf[UTF8_MAXBYTES+1];
12910 s++; /* get past 'v' */
12915 /* this is atoi() that tolerates underscores */
12918 const char *end = pos;
12920 while (--end >= s) {
12922 const UV orev = rev;
12923 rev += (*end - '0') * mult;
12925 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12926 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12927 "Integer overflow in decimal number");
12931 if (rev > 0x7FFFFFFF)
12932 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12934 /* Append native character for the rev point */
12935 tmpend = uvchr_to_utf8(tmpbuf, rev);
12936 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12937 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12939 if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
12945 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12949 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12957 * c-indentation-style: bsd
12958 * c-basic-offset: 4
12959 * indent-tabs-mode: t
12962 * ex: set ts=8 sts=4 sw=4 noet: