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 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
133 /* LEX_* are values for PL_lex_state, the state of the lexer.
134 * They are arranged oddly so that the guard on the switch statement
135 * can get by with a single comparison (if the compiler is smart enough).
138 /* #define LEX_NOTPARSING 11 is done in perl.h. */
140 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
141 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
142 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
143 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
144 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
146 /* at end of code, eg "$x" followed by: */
147 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
148 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
150 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
151 string or after \E, $foo, etc */
152 #define LEX_INTERPCONST 2 /* NOT USED */
153 #define LEX_FORMLINE 1 /* expecting a format line */
154 #define LEX_KNOWNEXT 0 /* next token known; just return it */
158 static const char* const lex_state_names[] = {
177 #include "keywords.h"
179 /* CLINE is a macro that ensures PL_copline has a sane value */
184 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
187 # define SKIPSPACE0(s) skipspace0(s)
188 # define SKIPSPACE1(s) skipspace1(s)
189 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
190 # define PEEKSPACE(s) skipspace2(s,0)
192 # define SKIPSPACE0(s) skipspace(s)
193 # define SKIPSPACE1(s) skipspace(s)
194 # define SKIPSPACE2(s,tsv) skipspace(s)
195 # define PEEKSPACE(s) skipspace(s)
199 * Convenience functions to return different tokens and prime the
200 * lexer for the next token. They all take an argument.
202 * TOKEN : generic token (used for '(', DOLSHARP, etc)
203 * OPERATOR : generic operator
204 * AOPERATOR : assignment operator
205 * PREBLOCK : beginning the block after an if, while, foreach, ...
206 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
207 * PREREF : *EXPR where EXPR is not a simple identifier
208 * TERM : expression term
209 * LOOPX : loop exiting command (goto, last, dump, etc)
210 * FTST : file test operator
211 * FUN0 : zero-argument function
212 * FUN1 : not used, except for not, which isn't a UNIOP
213 * BOop : bitwise or or xor
215 * SHop : shift operator
216 * PWop : power operator
217 * PMop : pattern-matching operator
218 * Aop : addition-level operator
219 * Mop : multiplication-level operator
220 * Eop : equality-testing operator
221 * Rop : relational operator <= != gt
223 * Also see LOP and lop() below.
226 #ifdef DEBUGGING /* Serve -DT. */
227 # define REPORT(retval) tokereport((I32)retval, &pl_yylval)
229 # define REPORT(retval) (retval)
232 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
233 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
234 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
235 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
236 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
237 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
238 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
239 #define LOOPX(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
240 #define FTST(f) return (pl_yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
241 #define FUN0(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
242 #define FUN1(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
243 #define BOop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
244 #define BAop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
245 #define SHop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
246 #define PWop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
247 #define PMop(f) return(pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
248 #define Aop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
249 #define Mop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
250 #define Eop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
251 #define Rop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
253 /* This bit of chicanery makes a unary function followed by
254 * a parenthesis into a function with one argument, highest precedence.
255 * The UNIDOR macro is for unary functions that can be followed by the //
256 * operator (such as C<shift // 0>).
258 #define UNI2(f,x) { \
259 pl_yylval.ival = f; \
262 PL_last_uni = PL_oldbufptr; \
263 PL_last_lop_op = f; \
265 return REPORT( (int)FUNC1 ); \
267 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
269 #define UNI(f) UNI2(f,XTERM)
270 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
272 #define UNIBRACK(f) { \
273 pl_yylval.ival = f; \
275 PL_last_uni = PL_oldbufptr; \
277 return REPORT( (int)FUNC1 ); \
279 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
282 /* grandfather return to old style */
283 #define OLDLOP(f) return(pl_yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
287 /* how to interpret the pl_yylval associated with the token */
291 TOKENTYPE_OPNUM, /* pl_yylval.ival contains an opcode number */
297 static struct debug_tokens {
299 enum token_type type;
301 } const debug_tokens[] =
303 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
304 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
305 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
306 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
307 { ARROW, TOKENTYPE_NONE, "ARROW" },
308 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
309 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
310 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
311 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
312 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
313 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
314 { DO, TOKENTYPE_NONE, "DO" },
315 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
316 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
317 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
318 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
319 { ELSE, TOKENTYPE_NONE, "ELSE" },
320 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
321 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
322 { FOR, TOKENTYPE_IVAL, "FOR" },
323 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
324 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
325 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
326 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
327 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
328 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
329 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
330 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
331 { IF, TOKENTYPE_IVAL, "IF" },
332 { LABEL, TOKENTYPE_PVAL, "LABEL" },
333 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
334 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
335 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
336 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
337 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
338 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
339 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
340 { MY, TOKENTYPE_IVAL, "MY" },
341 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
342 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
343 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
344 { OROP, TOKENTYPE_IVAL, "OROP" },
345 { OROR, TOKENTYPE_NONE, "OROR" },
346 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
347 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
348 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
349 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
350 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
351 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
352 { PREINC, TOKENTYPE_NONE, "PREINC" },
353 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
354 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
355 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
356 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
357 { SUB, TOKENTYPE_NONE, "SUB" },
358 { THING, TOKENTYPE_OPVAL, "THING" },
359 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
360 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
361 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
362 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
363 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
364 { USE, TOKENTYPE_IVAL, "USE" },
365 { WHEN, TOKENTYPE_IVAL, "WHEN" },
366 { WHILE, TOKENTYPE_IVAL, "WHILE" },
367 { WORD, TOKENTYPE_OPVAL, "WORD" },
368 { YADAYADA, TOKENTYPE_IVAL, "YADAYADA" },
369 { 0, TOKENTYPE_NONE, NULL }
372 /* dump the returned token in rv, plus any optional arg in pl_yylval */
375 S_tokereport(pTHX_ I32 rv, const YYSTYPE* lvalp)
379 PERL_ARGS_ASSERT_TOKEREPORT;
382 const char *name = NULL;
383 enum token_type type = TOKENTYPE_NONE;
384 const struct debug_tokens *p;
385 SV* const report = newSVpvs("<== ");
387 for (p = debug_tokens; p->token; p++) {
388 if (p->token == (int)rv) {
395 Perl_sv_catpv(aTHX_ report, name);
396 else if ((char)rv > ' ' && (char)rv < '~')
397 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
399 sv_catpvs(report, "EOF");
401 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
404 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
407 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)lvalp->ival);
409 case TOKENTYPE_OPNUM:
410 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
411 PL_op_name[lvalp->ival]);
414 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", lvalp->pval);
416 case TOKENTYPE_OPVAL:
418 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
419 PL_op_name[lvalp->opval->op_type]);
420 if (lvalp->opval->op_type == OP_CONST) {
421 Perl_sv_catpvf(aTHX_ report, " %s",
422 SvPEEK(cSVOPx_sv(lvalp->opval)));
427 sv_catpvs(report, "(opval=null)");
430 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
436 /* print the buffer with suitable escapes */
439 S_printbuf(pTHX_ const char *const fmt, const char *const s)
441 SV* const tmp = newSVpvs("");
443 PERL_ARGS_ASSERT_PRINTBUF;
445 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
454 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
455 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
459 S_ao(pTHX_ int toketype)
462 if (*PL_bufptr == '=') {
464 if (toketype == ANDAND)
465 pl_yylval.ival = OP_ANDASSIGN;
466 else if (toketype == OROR)
467 pl_yylval.ival = OP_ORASSIGN;
468 else if (toketype == DORDOR)
469 pl_yylval.ival = OP_DORASSIGN;
477 * When Perl expects an operator and finds something else, no_op
478 * prints the warning. It always prints "<something> found where
479 * operator expected. It prints "Missing semicolon on previous line?"
480 * if the surprise occurs at the start of the line. "do you need to
481 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
482 * where the compiler doesn't know if foo is a method call or a function.
483 * It prints "Missing operator before end of line" if there's nothing
484 * after the missing operator, or "... before <...>" if there is something
485 * after the missing operator.
489 S_no_op(pTHX_ const char *const what, char *s)
492 char * const oldbp = PL_bufptr;
493 const bool is_first = (PL_oldbufptr == PL_linestart);
495 PERL_ARGS_ASSERT_NO_OP;
501 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
502 if (ckWARN_d(WARN_SYNTAX)) {
504 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
505 "\t(Missing semicolon on previous line?)\n");
506 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
508 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
510 if (t < PL_bufptr && isSPACE(*t))
511 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
512 "\t(Do you need to predeclare %.*s?)\n",
513 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
517 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
518 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
526 * Complain about missing quote/regexp/heredoc terminator.
527 * If it's called with NULL then it cauterizes the line buffer.
528 * If we're in a delimited string and the delimiter is a control
529 * character, it's reformatted into a two-char sequence like ^C.
534 S_missingterm(pTHX_ char *s)
540 char * const nl = strrchr(s,'\n');
544 else if (isCNTRL(PL_multi_close)) {
546 tmpbuf[1] = (char)toCTRL(PL_multi_close);
551 *tmpbuf = (char)PL_multi_close;
555 q = strchr(s,'"') ? '\'' : '"';
556 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
559 #define FEATURE_IS_ENABLED(name) \
560 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
561 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
562 /* The longest string we pass in. */
563 #define MAX_FEATURE_LEN (sizeof("switch")-1)
566 * S_feature_is_enabled
567 * Check whether the named feature is enabled.
570 S_feature_is_enabled(pTHX_ const char *const name, STRLEN namelen)
573 HV * const hinthv = GvHV(PL_hintgv);
574 char he_name[8 + MAX_FEATURE_LEN] = "feature_";
576 PERL_ARGS_ASSERT_FEATURE_IS_ENABLED;
578 assert(namelen <= MAX_FEATURE_LEN);
579 memcpy(&he_name[8], name, namelen);
581 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
589 Perl_deprecate(pTHX_ const char *const s)
591 PERL_ARGS_ASSERT_DEPRECATE;
593 if (ckWARN(WARN_DEPRECATED))
594 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
598 Perl_deprecate_old(pTHX_ const char *const s)
600 /* This function should NOT be called for any new deprecated warnings */
601 /* Use Perl_deprecate instead */
603 /* It is here to maintain backward compatibility with the pre-5.8 */
604 /* warnings category hierarchy. The "deprecated" category used to */
605 /* live under the "syntax" category. It is now a top-level category */
606 /* in its own right. */
608 PERL_ARGS_ASSERT_DEPRECATE_OLD;
610 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
611 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
612 "Use of %s is deprecated", s);
616 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
617 * utf16-to-utf8-reversed.
620 #ifdef PERL_CR_FILTER
624 register const char *s = SvPVX_const(sv);
625 register const char * const e = s + SvCUR(sv);
627 PERL_ARGS_ASSERT_STRIP_RETURN;
629 /* outer loop optimized to do nothing if there are no CR-LFs */
631 if (*s++ == '\r' && *s == '\n') {
632 /* hit a CR-LF, need to copy the rest */
633 register char *d = s - 1;
636 if (*s == '\r' && s[1] == '\n')
647 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
649 const I32 count = FILTER_READ(idx+1, sv, maxlen);
650 if (count > 0 && !maxlen)
661 * Create a parser object and initialise its parser and lexer fields
663 * rsfp is the opened file handle to read from (if any),
665 * line holds any initial content already read from the file (or in
666 * the case of no file, such as an eval, the whole contents);
668 * new_filter indicates that this is a new file and it shouldn't inherit
669 * the filters from the current parser (ie require).
673 Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, bool new_filter)
676 const char *s = NULL;
678 yy_parser *parser, *oparser;
680 /* create and initialise a parser */
682 Newxz(parser, 1, yy_parser);
683 parser->old_parser = oparser = PL_parser;
686 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
687 parser->ps = parser->stack;
688 parser->stack_size = YYINITDEPTH;
690 parser->stack->state = 0;
691 parser->yyerrstatus = 0;
692 parser->yychar = YYEMPTY; /* Cause a token to be read. */
694 /* on scope exit, free this parser and restore any outer one */
696 parser->saved_curcop = PL_curcop;
698 /* initialise lexer state */
701 parser->curforce = -1;
703 parser->nexttoke = 0;
705 parser->error_count = oparser ? oparser->error_count : 0;
706 parser->copline = NOLINE;
707 parser->lex_state = LEX_NORMAL;
708 parser->expect = XSTATE;
710 parser->rsfp_filters = (new_filter || !oparser) ? newAV()
711 : MUTABLE_AV(SvREFCNT_inc(oparser->rsfp_filters));
713 Newx(parser->lex_brackstack, 120, char);
714 Newx(parser->lex_casestack, 12, char);
715 *parser->lex_casestack = '\0';
718 s = SvPV_const(line, len);
724 parser->linestr = newSVpvs("\n;");
725 } else if (SvREADONLY(line) || s[len-1] != ';') {
726 parser->linestr = newSVsv(line);
728 sv_catpvs(parser->linestr, "\n;");
731 SvREFCNT_inc_simple_void_NN(line);
732 parser->linestr = line;
734 parser->oldoldbufptr =
737 parser->linestart = SvPVX(parser->linestr);
738 parser->bufend = parser->bufptr + SvCUR(parser->linestr);
739 parser->last_lop = parser->last_uni = NULL;
743 /* delete a parser object */
746 Perl_parser_free(pTHX_ const yy_parser *parser)
748 PERL_ARGS_ASSERT_PARSER_FREE;
750 PL_curcop = parser->saved_curcop;
751 SvREFCNT_dec(parser->linestr);
753 if (parser->rsfp == PerlIO_stdin())
754 PerlIO_clearerr(parser->rsfp);
755 else if (parser->rsfp && (!parser->old_parser ||
756 (parser->old_parser && parser->rsfp != parser->old_parser->rsfp)))
757 PerlIO_close(parser->rsfp);
758 SvREFCNT_dec(parser->rsfp_filters);
760 Safefree(parser->stack);
761 Safefree(parser->lex_brackstack);
762 Safefree(parser->lex_casestack);
763 PL_parser = parser->old_parser;
770 * Finalizer for lexing operations. Must be called when the parser is
771 * done with the lexer.
778 PL_doextract = FALSE;
783 * This subroutine has nothing to do with tilting, whether at windmills
784 * or pinball tables. Its name is short for "increment line". It
785 * increments the current line number in CopLINE(PL_curcop) and checks
786 * to see whether the line starts with a comment of the form
787 * # line 500 "foo.pm"
788 * If so, it sets the current line number and file to the values in the comment.
792 S_incline(pTHX_ const char *s)
799 PERL_ARGS_ASSERT_INCLINE;
801 CopLINE_inc(PL_curcop);
804 while (SPACE_OR_TAB(*s))
806 if (strnEQ(s, "line", 4))
810 if (SPACE_OR_TAB(*s))
814 while (SPACE_OR_TAB(*s))
822 if (!SPACE_OR_TAB(*s) && *s != '\r' && *s != '\n' && *s != '\0')
824 while (SPACE_OR_TAB(*s))
826 if (*s == '"' && (t = strchr(s+1, '"'))) {
836 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
838 if (*e != '\n' && *e != '\0')
839 return; /* false alarm */
842 const STRLEN len = t - s;
844 SV *const temp_sv = CopFILESV(PL_curcop);
850 tmplen = SvCUR(temp_sv);
856 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
857 /* must copy *{"::_<(eval N)[oldfilename:L]"}
858 * to *{"::_<newfilename"} */
859 /* However, the long form of evals is only turned on by the
860 debugger - usually they're "(eval %lu)" */
864 STRLEN tmplen2 = len;
865 if (tmplen + 2 <= sizeof smallbuf)
868 Newx(tmpbuf, tmplen + 2, char);
871 memcpy(tmpbuf + 2, cf, tmplen);
873 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
878 if (tmplen2 + 2 <= sizeof smallbuf)
881 Newx(tmpbuf2, tmplen2 + 2, char);
883 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
884 /* Either they malloc'd it, or we malloc'd it,
885 so no prefix is present in ours. */
890 memcpy(tmpbuf2 + 2, s, tmplen2);
893 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
895 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
896 /* adjust ${"::_<newfilename"} to store the new file name */
897 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
898 GvHV(gv2) = MUTABLE_HV(SvREFCNT_inc(GvHV(*gvp)));
899 GvAV(gv2) = MUTABLE_AV(SvREFCNT_inc(GvAV(*gvp)));
902 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
904 if (tmpbuf != smallbuf) Safefree(tmpbuf);
907 CopFILE_free(PL_curcop);
908 CopFILE_setn(PL_curcop, s, len);
910 CopLINE_set(PL_curcop, atoi(n)-1);
914 /* skip space before PL_thistoken */
917 S_skipspace0(pTHX_ register char *s)
919 PERL_ARGS_ASSERT_SKIPSPACE0;
926 PL_thiswhite = newSVpvs("");
927 sv_catsv(PL_thiswhite, PL_skipwhite);
928 sv_free(PL_skipwhite);
931 PL_realtokenstart = s - SvPVX(PL_linestr);
935 /* skip space after PL_thistoken */
938 S_skipspace1(pTHX_ register char *s)
940 const char *start = s;
941 I32 startoff = start - SvPVX(PL_linestr);
943 PERL_ARGS_ASSERT_SKIPSPACE1;
948 start = SvPVX(PL_linestr) + startoff;
949 if (!PL_thistoken && PL_realtokenstart >= 0) {
950 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
951 PL_thistoken = newSVpvn(tstart, start - tstart);
953 PL_realtokenstart = -1;
956 PL_nextwhite = newSVpvs("");
957 sv_catsv(PL_nextwhite, PL_skipwhite);
958 sv_free(PL_skipwhite);
965 S_skipspace2(pTHX_ register char *s, SV **svp)
968 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
969 const I32 startoff = s - SvPVX(PL_linestr);
971 PERL_ARGS_ASSERT_SKIPSPACE2;
974 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
975 if (!PL_madskills || !svp)
977 start = SvPVX(PL_linestr) + startoff;
978 if (!PL_thistoken && PL_realtokenstart >= 0) {
979 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
980 PL_thistoken = newSVpvn(tstart, start - tstart);
981 PL_realtokenstart = -1;
986 sv_setsv(*svp, PL_skipwhite);
987 sv_free(PL_skipwhite);
996 S_update_debugger_info(pTHX_ SV *orig_sv, const char *const buf, STRLEN len)
998 AV *av = CopFILEAVx(PL_curcop);
1000 SV * const sv = newSV_type(SVt_PVMG);
1002 sv_setsv(sv, orig_sv);
1004 sv_setpvn(sv, buf, len);
1007 av_store(av, (I32)CopLINE(PL_curcop), sv);
1013 * Called to gobble the appropriate amount and type of whitespace.
1014 * Skips comments as well.
1018 S_skipspace(pTHX_ register char *s)
1023 int startoff = s - SvPVX(PL_linestr);
1025 PERL_ARGS_ASSERT_SKIPSPACE;
1028 sv_free(PL_skipwhite);
1032 PERL_ARGS_ASSERT_SKIPSPACE;
1034 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
1035 while (s < PL_bufend && SPACE_OR_TAB(*s))
1045 SSize_t oldprevlen, oldoldprevlen;
1046 SSize_t oldloplen = 0, oldunilen = 0;
1047 while (s < PL_bufend && isSPACE(*s)) {
1048 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
1053 if (s < PL_bufend && *s == '#') {
1054 while (s < PL_bufend && *s != '\n')
1056 if (s < PL_bufend) {
1058 if (PL_in_eval && !PL_rsfp) {
1065 /* only continue to recharge the buffer if we're at the end
1066 * of the buffer, we're not reading from a source filter, and
1067 * we're in normal lexing mode
1069 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
1070 PL_lex_state == LEX_FORMLINE)
1077 /* try to recharge the buffer */
1079 curoff = s - SvPVX(PL_linestr);
1082 if ((s = filter_gets(PL_linestr, PL_rsfp,
1083 (prevlen = SvCUR(PL_linestr)))) == NULL)
1086 if (PL_madskills && curoff != startoff) {
1088 PL_skipwhite = newSVpvs("");
1089 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1093 /* mustn't throw out old stuff yet if madpropping */
1094 SvCUR(PL_linestr) = curoff;
1095 s = SvPVX(PL_linestr) + curoff;
1097 if (curoff && s[-1] == '\n')
1101 /* end of file. Add on the -p or -n magic */
1102 /* XXX these shouldn't really be added here, can't set PL_faketokens */
1105 sv_catpvs(PL_linestr,
1106 ";}continue{print or die qq(-p destination: $!\\n);}");
1108 sv_setpvs(PL_linestr,
1109 ";}continue{print or die qq(-p destination: $!\\n);}");
1111 PL_minus_n = PL_minus_p = 0;
1113 else if (PL_minus_n) {
1115 sv_catpvs(PL_linestr, ";}");
1117 sv_setpvs(PL_linestr, ";}");
1123 sv_catpvs(PL_linestr,";");
1125 sv_setpvs(PL_linestr,";");
1128 /* reset variables for next time we lex */
1129 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
1135 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1136 PL_last_lop = PL_last_uni = NULL;
1138 /* Close the filehandle. Could be from
1139 * STDIN, or a regular file. If we were reading code from
1140 * STDIN (because the commandline held no -e or filename)
1141 * then we don't close it, we reset it so the code can
1142 * read from STDIN too.
1145 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1146 PerlIO_clearerr(PL_rsfp);
1148 (void)PerlIO_close(PL_rsfp);
1153 /* not at end of file, so we only read another line */
1154 /* make corresponding updates to old pointers, for yyerror() */
1155 oldprevlen = PL_oldbufptr - PL_bufend;
1156 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1158 oldunilen = PL_last_uni - PL_bufend;
1160 oldloplen = PL_last_lop - PL_bufend;
1161 PL_linestart = PL_bufptr = s + prevlen;
1162 PL_bufend = s + SvCUR(PL_linestr);
1164 PL_oldbufptr = s + oldprevlen;
1165 PL_oldoldbufptr = s + oldoldprevlen;
1167 PL_last_uni = s + oldunilen;
1169 PL_last_lop = s + oldloplen;
1172 /* debugger active and we're not compiling the debugger code,
1173 * so store the line into the debugger's array of lines
1175 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
1176 update_debugger_info(NULL, PL_bufptr, PL_bufend - PL_bufptr);
1183 PL_skipwhite = newSVpvs("");
1184 curoff = s - SvPVX(PL_linestr);
1185 if (curoff - startoff)
1186 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1195 * Check the unary operators to ensure there's no ambiguity in how they're
1196 * used. An ambiguous piece of code would be:
1198 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1199 * the +5 is its argument.
1209 if (PL_oldoldbufptr != PL_last_uni)
1211 while (isSPACE(*PL_last_uni))
1214 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1216 if ((t = strchr(s, '(')) && t < PL_bufptr)
1219 if (ckWARN_d(WARN_AMBIGUOUS)){
1220 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1221 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1222 (int)(s - PL_last_uni), PL_last_uni);
1227 * LOP : macro to build a list operator. Its behaviour has been replaced
1228 * with a subroutine, S_lop() for which LOP is just another name.
1231 #define LOP(f,x) return lop(f,x,s)
1235 * Build a list operator (or something that might be one). The rules:
1236 * - if we have a next token, then it's a list operator [why?]
1237 * - if the next thing is an opening paren, then it's a function
1238 * - else it's a list operator
1242 S_lop(pTHX_ I32 f, int x, char *s)
1246 PERL_ARGS_ASSERT_LOP;
1252 PL_last_lop = PL_oldbufptr;
1253 PL_last_lop_op = (OPCODE)f;
1256 return REPORT(LSTOP);
1259 return REPORT(LSTOP);
1262 return REPORT(FUNC);
1265 return REPORT(FUNC);
1267 return REPORT(LSTOP);
1273 * Sets up for an eventual force_next(). start_force(0) basically does
1274 * an unshift, while start_force(-1) does a push. yylex removes items
1279 S_start_force(pTHX_ int where)
1283 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1284 where = PL_lasttoke;
1285 assert(PL_curforce < 0 || PL_curforce == where);
1286 if (PL_curforce != where) {
1287 for (i = PL_lasttoke; i > where; --i) {
1288 PL_nexttoke[i] = PL_nexttoke[i-1];
1292 if (PL_curforce < 0) /* in case of duplicate start_force() */
1293 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1294 PL_curforce = where;
1297 curmad('^', newSVpvs(""));
1298 CURMAD('_', PL_nextwhite);
1303 S_curmad(pTHX_ char slot, SV *sv)
1309 if (PL_curforce < 0)
1310 where = &PL_thismad;
1312 where = &PL_nexttoke[PL_curforce].next_mad;
1318 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1320 else if (PL_encoding) {
1321 sv_recode_to_utf8(sv, PL_encoding);
1326 /* keep a slot open for the head of the list? */
1327 if (slot != '_' && *where && (*where)->mad_key == '^') {
1328 (*where)->mad_key = slot;
1329 sv_free(MUTABLE_SV(((*where)->mad_val)));
1330 (*where)->mad_val = (void*)sv;
1333 addmad(newMADsv(slot, sv), where, 0);
1336 # define start_force(where) NOOP
1337 # define curmad(slot, sv) NOOP
1342 * When the lexer realizes it knows the next token (for instance,
1343 * it is reordering tokens for the parser) then it can call S_force_next
1344 * to know what token to return the next time the lexer is called. Caller
1345 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1346 * and possibly PL_expect to ensure the lexer handles the token correctly.
1350 S_force_next(pTHX_ I32 type)
1355 PerlIO_printf(Perl_debug_log, "### forced token:\n");
1356 tokereport(type, &NEXTVAL_NEXTTOKE);
1360 if (PL_curforce < 0)
1361 start_force(PL_lasttoke);
1362 PL_nexttoke[PL_curforce].next_type = type;
1363 if (PL_lex_state != LEX_KNOWNEXT)
1364 PL_lex_defer = PL_lex_state;
1365 PL_lex_state = LEX_KNOWNEXT;
1366 PL_lex_expect = PL_expect;
1369 PL_nexttype[PL_nexttoke] = type;
1371 if (PL_lex_state != LEX_KNOWNEXT) {
1372 PL_lex_defer = PL_lex_state;
1373 PL_lex_expect = PL_expect;
1374 PL_lex_state = LEX_KNOWNEXT;
1380 S_newSV_maybe_utf8(pTHX_ const char *const start, STRLEN len)
1383 SV * const sv = newSVpvn_utf8(start, len,
1385 && is_utf8_string((const U8*)start, len));
1391 * When the lexer knows the next thing is a word (for instance, it has
1392 * just seen -> and it knows that the next char is a word char, then
1393 * it calls S_force_word to stick the next word into the PL_nexttoke/val
1397 * char *start : buffer position (must be within PL_linestr)
1398 * int token : PL_next* will be this type of bare word (e.g., METHOD,WORD)
1399 * int check_keyword : if true, Perl checks to make sure the word isn't
1400 * a keyword (do this if the word is a label, e.g. goto FOO)
1401 * int allow_pack : if true, : characters will also be allowed (require,
1402 * use, etc. do this)
1403 * int allow_initial_tick : used by the "sub" lexer only.
1407 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1413 PERL_ARGS_ASSERT_FORCE_WORD;
1415 start = SKIPSPACE1(start);
1417 if (isIDFIRST_lazy_if(s,UTF) ||
1418 (allow_pack && *s == ':') ||
1419 (allow_initial_tick && *s == '\'') )
1421 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1422 if (check_keyword && keyword(PL_tokenbuf, len, 0))
1424 start_force(PL_curforce);
1426 curmad('X', newSVpvn(start,s-start));
1427 if (token == METHOD) {
1432 PL_expect = XOPERATOR;
1436 curmad('g', newSVpvs( "forced" ));
1437 NEXTVAL_NEXTTOKE.opval
1438 = (OP*)newSVOP(OP_CONST,0,
1439 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1440 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1448 * Called when the lexer wants $foo *foo &foo etc, but the program
1449 * text only contains the "foo" portion. The first argument is a pointer
1450 * to the "foo", and the second argument is the type symbol to prefix.
1451 * Forces the next token to be a "WORD".
1452 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1456 S_force_ident(pTHX_ register const char *s, int kind)
1460 PERL_ARGS_ASSERT_FORCE_IDENT;
1463 const STRLEN len = strlen(s);
1464 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1465 start_force(PL_curforce);
1466 NEXTVAL_NEXTTOKE.opval = o;
1469 o->op_private = OPpCONST_ENTERED;
1470 /* XXX see note in pp_entereval() for why we forgo typo
1471 warnings if the symbol must be introduced in an eval.
1473 gv_fetchpvn_flags(s, len,
1474 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1476 kind == '$' ? SVt_PV :
1477 kind == '@' ? SVt_PVAV :
1478 kind == '%' ? SVt_PVHV :
1486 Perl_str_to_version(pTHX_ SV *sv)
1491 const char *start = SvPV_const(sv,len);
1492 const char * const end = start + len;
1493 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1495 PERL_ARGS_ASSERT_STR_TO_VERSION;
1497 while (start < end) {
1501 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1506 retval += ((NV)n)/nshift;
1515 * Forces the next token to be a version number.
1516 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1517 * and if "guessing" is TRUE, then no new token is created (and the caller
1518 * must use an alternative parsing method).
1522 S_force_version(pTHX_ char *s, int guessing)
1528 I32 startoff = s - SvPVX(PL_linestr);
1531 PERL_ARGS_ASSERT_FORCE_VERSION;
1539 while (isDIGIT(*d) || *d == '_' || *d == '.')
1543 start_force(PL_curforce);
1544 curmad('X', newSVpvn(s,d-s));
1547 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1549 s = scan_num(s, &pl_yylval);
1550 version = pl_yylval.opval;
1551 ver = cSVOPx(version)->op_sv;
1552 if (SvPOK(ver) && !SvNIOK(ver)) {
1553 SvUPGRADE(ver, SVt_PVNV);
1554 SvNV_set(ver, str_to_version(ver));
1555 SvNOK_on(ver); /* hint that it is a version */
1558 else if (guessing) {
1561 sv_free(PL_nextwhite); /* let next token collect whitespace */
1563 s = SvPVX(PL_linestr) + startoff;
1571 if (PL_madskills && !version) {
1572 sv_free(PL_nextwhite); /* let next token collect whitespace */
1574 s = SvPVX(PL_linestr) + startoff;
1577 /* NOTE: The parser sees the package name and the VERSION swapped */
1578 start_force(PL_curforce);
1579 NEXTVAL_NEXTTOKE.opval = version;
1587 * Tokenize a quoted string passed in as an SV. It finds the next
1588 * chunk, up to end of string or a backslash. It may make a new
1589 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1594 S_tokeq(pTHX_ SV *sv)
1598 register char *send;
1603 PERL_ARGS_ASSERT_TOKEQ;
1608 s = SvPV_force(sv, len);
1609 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1612 while (s < send && *s != '\\')
1617 if ( PL_hints & HINT_NEW_STRING ) {
1618 pv = newSVpvn_flags(SvPVX_const(pv), len, SVs_TEMP | SvUTF8(sv));
1622 if (s + 1 < send && (s[1] == '\\'))
1623 s++; /* all that, just for this */
1628 SvCUR_set(sv, d - SvPVX_const(sv));
1630 if ( PL_hints & HINT_NEW_STRING )
1631 return new_constant(NULL, 0, "q", sv, pv, "q", 1);
1636 * Now come three functions related to double-quote context,
1637 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1638 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1639 * interact with PL_lex_state, and create fake ( ... ) argument lists
1640 * to handle functions and concatenation.
1641 * They assume that whoever calls them will be setting up a fake
1642 * join call, because each subthing puts a ',' after it. This lets
1645 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1647 * (I'm not sure whether the spurious commas at the end of lcfirst's
1648 * arguments and join's arguments are created or not).
1653 * Assumes that pl_yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1655 * Pattern matching will set PL_lex_op to the pattern-matching op to
1656 * make (we return THING if pl_yylval.ival is OP_NULL, PMFUNC otherwise).
1658 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1660 * Everything else becomes a FUNC.
1662 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1663 * had an OP_CONST or OP_READLINE). This just sets us up for a
1664 * call to S_sublex_push().
1668 S_sublex_start(pTHX)
1671 register const I32 op_type = pl_yylval.ival;
1673 if (op_type == OP_NULL) {
1674 pl_yylval.opval = PL_lex_op;
1678 if (op_type == OP_CONST || op_type == OP_READLINE) {
1679 SV *sv = tokeq(PL_lex_stuff);
1681 if (SvTYPE(sv) == SVt_PVIV) {
1682 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1684 const char * const p = SvPV_const(sv, len);
1685 SV * const nsv = newSVpvn_flags(p, len, SvUTF8(sv));
1689 pl_yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1690 PL_lex_stuff = NULL;
1691 /* Allow <FH> // "foo" */
1692 if (op_type == OP_READLINE)
1693 PL_expect = XTERMORDORDOR;
1696 else if (op_type == OP_BACKTICK && PL_lex_op) {
1697 /* readpipe() vas overriden */
1698 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1699 pl_yylval.opval = PL_lex_op;
1701 PL_lex_stuff = NULL;
1705 PL_sublex_info.super_state = PL_lex_state;
1706 PL_sublex_info.sub_inwhat = (U16)op_type;
1707 PL_sublex_info.sub_op = PL_lex_op;
1708 PL_lex_state = LEX_INTERPPUSH;
1712 pl_yylval.opval = PL_lex_op;
1722 * Create a new scope to save the lexing state. The scope will be
1723 * ended in S_sublex_done. Returns a '(', starting the function arguments
1724 * to the uc, lc, etc. found before.
1725 * Sets PL_lex_state to LEX_INTERPCONCAT.
1734 PL_lex_state = PL_sublex_info.super_state;
1735 SAVEBOOL(PL_lex_dojoin);
1736 SAVEI32(PL_lex_brackets);
1737 SAVEI32(PL_lex_casemods);
1738 SAVEI32(PL_lex_starts);
1739 SAVEI8(PL_lex_state);
1740 SAVEVPTR(PL_lex_inpat);
1741 SAVEI16(PL_lex_inwhat);
1742 SAVECOPLINE(PL_curcop);
1743 SAVEPPTR(PL_bufptr);
1744 SAVEPPTR(PL_bufend);
1745 SAVEPPTR(PL_oldbufptr);
1746 SAVEPPTR(PL_oldoldbufptr);
1747 SAVEPPTR(PL_last_lop);
1748 SAVEPPTR(PL_last_uni);
1749 SAVEPPTR(PL_linestart);
1750 SAVESPTR(PL_linestr);
1751 SAVEGENERICPV(PL_lex_brackstack);
1752 SAVEGENERICPV(PL_lex_casestack);
1754 PL_linestr = PL_lex_stuff;
1755 PL_lex_stuff = NULL;
1757 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1758 = SvPVX(PL_linestr);
1759 PL_bufend += SvCUR(PL_linestr);
1760 PL_last_lop = PL_last_uni = NULL;
1761 SAVEFREESV(PL_linestr);
1763 PL_lex_dojoin = FALSE;
1764 PL_lex_brackets = 0;
1765 Newx(PL_lex_brackstack, 120, char);
1766 Newx(PL_lex_casestack, 12, char);
1767 PL_lex_casemods = 0;
1768 *PL_lex_casestack = '\0';
1770 PL_lex_state = LEX_INTERPCONCAT;
1771 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1773 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1774 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1775 PL_lex_inpat = PL_sublex_info.sub_op;
1777 PL_lex_inpat = NULL;
1784 * Restores lexer state after a S_sublex_push.
1791 if (!PL_lex_starts++) {
1792 SV * const sv = newSVpvs("");
1793 if (SvUTF8(PL_linestr))
1795 PL_expect = XOPERATOR;
1796 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1800 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1801 PL_lex_state = LEX_INTERPCASEMOD;
1805 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1806 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1807 PL_linestr = PL_lex_repl;
1809 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1810 PL_bufend += SvCUR(PL_linestr);
1811 PL_last_lop = PL_last_uni = NULL;
1812 SAVEFREESV(PL_linestr);
1813 PL_lex_dojoin = FALSE;
1814 PL_lex_brackets = 0;
1815 PL_lex_casemods = 0;
1816 *PL_lex_casestack = '\0';
1818 if (SvEVALED(PL_lex_repl)) {
1819 PL_lex_state = LEX_INTERPNORMAL;
1821 /* we don't clear PL_lex_repl here, so that we can check later
1822 whether this is an evalled subst; that means we rely on the
1823 logic to ensure sublex_done() is called again only via the
1824 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1827 PL_lex_state = LEX_INTERPCONCAT;
1837 PL_endwhite = newSVpvs("");
1838 sv_catsv(PL_endwhite, PL_thiswhite);
1842 sv_setpvs(PL_thistoken,"");
1844 PL_realtokenstart = -1;
1848 PL_bufend = SvPVX(PL_linestr);
1849 PL_bufend += SvCUR(PL_linestr);
1850 PL_expect = XOPERATOR;
1851 PL_sublex_info.sub_inwhat = 0;
1859 Extracts a pattern, double-quoted string, or transliteration. This
1862 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
1863 processing a pattern (PL_lex_inpat is true), a transliteration
1864 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
1866 Returns a pointer to the character scanned up to. If this is
1867 advanced from the start pointer supplied (i.e. if anything was
1868 successfully parsed), will leave an OP for the substring scanned
1869 in pl_yylval. Caller must intuit reason for not parsing further
1870 by looking at the next characters herself.
1874 double-quoted style: \r and \n
1875 regexp special ones: \D \s
1878 case and quoting: \U \Q \E
1879 stops on @ and $, but not for $ as tail anchor
1881 In transliterations:
1882 characters are VERY literal, except for - not at the start or end
1883 of the string, which indicates a range. If the range is in bytes,
1884 scan_const expands the range to the full set of intermediate
1885 characters. If the range is in utf8, the hyphen is replaced with
1886 a certain range mark which will be handled by pmtrans() in op.c.
1888 In double-quoted strings:
1890 double-quoted style: \r and \n
1892 deprecated backrefs: \1 (in substitution replacements)
1893 case and quoting: \U \Q \E
1896 scan_const does *not* construct ops to handle interpolated strings.
1897 It stops processing as soon as it finds an embedded $ or @ variable
1898 and leaves it to the caller to work out what's going on.
1900 embedded arrays (whether in pattern or not) could be:
1901 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1903 $ in double-quoted strings must be the symbol of an embedded scalar.
1905 $ in pattern could be $foo or could be tail anchor. Assumption:
1906 it's a tail anchor if $ is the last thing in the string, or if it's
1907 followed by one of "()| \r\n\t"
1909 \1 (backreferences) are turned into $1
1911 The structure of the code is
1912 while (there's a character to process) {
1913 handle transliteration ranges
1914 skip regexp comments /(?#comment)/ and codes /(?{code})/
1915 skip #-initiated comments in //x patterns
1916 check for embedded arrays
1917 check for embedded scalars
1919 leave intact backslashes from leaveit (below)
1920 deprecate \1 in substitution replacements
1921 handle string-changing backslashes \l \U \Q \E, etc.
1922 switch (what was escaped) {
1923 handle \- in a transliteration (becomes a literal -)
1924 handle \132 (octal characters)
1925 handle \x15 and \x{1234} (hex characters)
1926 handle \N{name} (named characters)
1927 handle \cV (control characters)
1928 handle printf-style backslashes (\f, \r, \n, etc)
1931 } (end if backslash)
1932 handle regular character
1933 } (end while character to read)
1938 S_scan_const(pTHX_ char *start)
1941 register char *send = PL_bufend; /* end of the constant */
1942 SV *sv = newSV(send - start); /* sv for the constant. See
1943 note below on sizing. */
1944 register char *s = start; /* start of the constant */
1945 register char *d = SvPVX(sv); /* destination for copies */
1946 bool dorange = FALSE; /* are we in a translit range? */
1947 bool didrange = FALSE; /* did we just finish a range? */
1948 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1949 I32 this_utf8 = UTF; /* Is the source string assumed
1950 to be UTF8? But, this can
1951 show as true when the source
1952 isn't utf8, as for example
1953 when it is entirely composed
1956 /* Note on sizing: The scanned constant is placed into sv, which is
1957 * initialized by newSV() assuming one byte of output for every byte of
1958 * input. This routine expects newSV() to allocate an extra byte for a
1959 * trailing NUL, which this routine will append if it gets to the end of
1960 * the input. There may be more bytes of input than output (eg., \N{LATIN
1961 * CAPITAL LETTER A}), or more output than input if the constant ends up
1962 * recoded to utf8, but each time a construct is found that might increase
1963 * the needed size, SvGROW() is called. Its size parameter each time is
1964 * based on the best guess estimate at the time, namely the length used so
1965 * far, plus the length the current construct will occupy, plus room for
1966 * the trailing NUL, plus one byte for every input byte still unscanned */
1970 UV literal_endpoint = 0;
1971 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
1974 PERL_ARGS_ASSERT_SCAN_CONST;
1976 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1977 /* If we are doing a trans and we know we want UTF8 set expectation */
1978 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1979 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1983 while (s < send || dorange) {
1984 /* get transliterations out of the way (they're most literal) */
1985 if (PL_lex_inwhat == OP_TRANS) {
1986 /* expand a range A-Z to the full set of characters. AIE! */
1988 I32 i; /* current expanded character */
1989 I32 min; /* first character in range */
1990 I32 max; /* last character in range */
2001 char * const c = (char*)utf8_hop((U8*)d, -1);
2005 *c = (char)UTF_TO_NATIVE(0xff);
2006 /* mark the range as done, and continue */
2012 i = d - SvPVX_const(sv); /* remember current offset */
2015 SvLEN(sv) + (has_utf8 ?
2016 (512 - UTF_CONTINUATION_MARK +
2019 /* How many two-byte within 0..255: 128 in UTF-8,
2020 * 96 in UTF-8-mod. */
2022 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
2024 d = SvPVX(sv) + i; /* refresh d after realloc */
2028 for (j = 0; j <= 1; j++) {
2029 char * const c = (char*)utf8_hop((U8*)d, -1);
2030 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
2036 max = (U8)0xff; /* only to \xff */
2037 uvmax = uv; /* \x{100} to uvmax */
2039 d = c; /* eat endpoint chars */
2044 d -= 2; /* eat the first char and the - */
2045 min = (U8)*d; /* first char in range */
2046 max = (U8)d[1]; /* last char in range */
2053 "Invalid range \"%c-%c\" in transliteration operator",
2054 (char)min, (char)max);
2058 if (literal_endpoint == 2 &&
2059 ((isLOWER(min) && isLOWER(max)) ||
2060 (isUPPER(min) && isUPPER(max)))) {
2062 for (i = min; i <= max; i++)
2064 *d++ = NATIVE_TO_NEED(has_utf8,i);
2066 for (i = min; i <= max; i++)
2068 *d++ = NATIVE_TO_NEED(has_utf8,i);
2073 for (i = min; i <= max; i++)
2076 const U8 ch = (U8)NATIVE_TO_UTF(i);
2077 if (UNI_IS_INVARIANT(ch))
2080 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
2081 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
2090 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
2092 *d++ = (char)UTF_TO_NATIVE(0xff);
2094 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
2098 /* mark the range as done, and continue */
2102 literal_endpoint = 0;
2107 /* range begins (ignore - as first or last char) */
2108 else if (*s == '-' && s+1 < send && s != start) {
2110 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
2117 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
2127 literal_endpoint = 0;
2128 native_range = TRUE;
2133 /* if we get here, we're not doing a transliteration */
2135 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2136 except for the last char, which will be done separately. */
2137 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
2139 while (s+1 < send && *s != ')')
2140 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2142 else if (s[2] == '{' /* This should match regcomp.c */
2143 || (s[2] == '?' && s[3] == '{'))
2146 char *regparse = s + (s[2] == '{' ? 3 : 4);
2149 while (count && (c = *regparse)) {
2150 if (c == '\\' && regparse[1])
2158 if (*regparse != ')')
2159 regparse--; /* Leave one char for continuation. */
2160 while (s < regparse)
2161 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2165 /* likewise skip #-initiated comments in //x patterns */
2166 else if (*s == '#' && PL_lex_inpat &&
2167 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2168 while (s+1 < send && *s != '\n')
2169 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2172 /* check for embedded arrays
2173 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2175 else if (*s == '@' && s[1]) {
2176 if (isALNUM_lazy_if(s+1,UTF))
2178 if (strchr(":'{$", s[1]))
2180 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2181 break; /* in regexp, neither @+ nor @- are interpolated */
2184 /* check for embedded scalars. only stop if we're sure it's a
2187 else if (*s == '$') {
2188 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
2190 if (s + 1 < send && !strchr("()| \r\n\t", s[1])) {
2191 if (s[1] == '\\' && ckWARN(WARN_AMBIGUOUS)) {
2192 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
2193 "Possible unintended interpolation of $\\ in regex");
2195 break; /* in regexp, $ might be tail anchor */
2199 /* End of else if chain - OP_TRANS rejoin rest */
2202 if (*s == '\\' && s+1 < send) {
2205 /* deprecate \1 in strings and substitution replacements */
2206 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2207 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2209 if (ckWARN(WARN_SYNTAX))
2210 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2215 /* string-change backslash escapes */
2216 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2220 /* skip any other backslash escapes in a pattern */
2221 else if (PL_lex_inpat) {
2222 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2223 goto default_action;
2226 /* if we get here, it's either a quoted -, or a digit */
2229 /* quoted - in transliterations */
2231 if (PL_lex_inwhat == OP_TRANS) {
2238 if ((isALPHA(*s) || isDIGIT(*s)) &&
2240 Perl_warner(aTHX_ packWARN(WARN_MISC),
2241 "Unrecognized escape \\%c passed through",
2243 /* default action is to copy the quoted character */
2244 goto default_action;
2247 /* eg. \132 indicates the octal constant 0x132 */
2248 case '0': case '1': case '2': case '3':
2249 case '4': case '5': case '6': case '7':
2253 uv = NATIVE_TO_UNI(grok_oct(s, &len, &flags, NULL));
2256 goto NUM_ESCAPE_INSERT;
2258 /* eg. \x24 indicates the hex constant 0x24 */
2262 char* const e = strchr(s, '}');
2263 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2264 PERL_SCAN_DISALLOW_PREFIX;
2269 yyerror("Missing right brace on \\x{}");
2273 uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
2279 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2280 uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
2286 /* Insert oct, hex, or \N{U+...} escaped character. There will
2287 * always be enough room in sv since such escapes will be
2288 * longer than any UTF-8 sequence they can end up as, except if
2289 * they force us to recode the rest of the string into utf8 */
2291 /* Here uv is the ordinal of the next character being added in
2292 * unicode (converted from native). (It has to be done before
2293 * here because \N is interpreted as unicode, and oct and hex
2295 if (!UNI_IS_INVARIANT(uv)) {
2296 if (!has_utf8 && uv > 255) {
2297 /* Might need to recode whatever we have accumulated so
2298 * far if it contains any chars variant in utf8 or
2301 SvCUR_set(sv, d - SvPVX_const(sv));
2304 /* See Note on sizing above. */
2305 sv_utf8_upgrade_flags_grow(sv,
2306 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2307 UNISKIP(uv) + (STRLEN)(send - s) + 1);
2308 d = SvPVX(sv) + SvCUR(sv);
2313 d = (char*)uvuni_to_utf8((U8*)d, uv);
2314 if (PL_lex_inwhat == OP_TRANS &&
2315 PL_sublex_info.sub_op) {
2316 PL_sublex_info.sub_op->op_private |=
2317 (PL_lex_repl ? OPpTRANS_FROM_UTF
2321 if (uv > 255 && !dorange)
2322 native_range = FALSE;
2334 /* \N{LATIN SMALL LETTER A} is a named character, and so is
2339 char* e = strchr(s, '}');
2345 yyerror("Missing right brace on \\N{}");
2349 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2350 /* \N{U+...} The ... is a unicode value even on EBCDIC
2352 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2353 PERL_SCAN_DISALLOW_PREFIX;
2356 uv = grok_hex(s, &len, &flags, NULL);
2357 if ( e > s && len != (STRLEN)(e - s) ) {
2361 goto NUM_ESCAPE_INSERT;
2363 res = newSVpvn(s + 1, e - s - 1);
2364 res = new_constant( NULL, 0, "charnames",
2365 res, NULL, s - 2, e - s + 3 );
2367 sv_utf8_upgrade(res);
2368 str = SvPV_const(res,len);
2369 #ifdef EBCDIC_NEVER_MIND
2370 /* charnames uses pack U and that has been
2371 * recently changed to do the below uni->native
2372 * mapping, so this would be redundant (and wrong,
2373 * the code point would be doubly converted).
2374 * But leave this in just in case the pack U change
2375 * gets revoked, but the semantics is still
2376 * desireable for charnames. --jhi */
2378 UV uv = utf8_to_uvchr((const U8*)str, 0);
2381 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2383 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2384 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2385 str = SvPV_const(res, len);
2389 /* If destination is not in utf8 but this new character is,
2390 * recode the dest to utf8 */
2391 if (!has_utf8 && SvUTF8(res)) {
2392 SvCUR_set(sv, d - SvPVX_const(sv));
2395 /* See Note on sizing above. */
2396 sv_utf8_upgrade_flags_grow(sv,
2397 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2398 len + (STRLEN)(send - s) + 1);
2399 d = SvPVX(sv) + SvCUR(sv);
2401 } else if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2403 /* See Note on sizing above. (NOTE: SvCUR() is not set
2404 * correctly here). */
2405 const STRLEN off = d - SvPVX_const(sv);
2406 d = SvGROW(sv, off + len + (STRLEN)(send - s) + 1) + off;
2410 native_range = FALSE; /* \N{} is guessed to be Unicode */
2412 Copy(str, d, len, char);
2419 yyerror("Missing braces on \\N{}");
2422 /* \c is a control character */
2431 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2434 yyerror("Missing control char name in \\c");
2438 /* printf-style backslashes, formfeeds, newlines, etc */
2440 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2443 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2446 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2449 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2452 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2455 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2458 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2464 } /* end if (backslash) */
2471 /* If we started with encoded form, or already know we want it,
2472 then encode the next character */
2473 if (! NATIVE_IS_INVARIANT((U8)(*s)) && (this_utf8 || has_utf8)) {
2477 /* One might think that it is wasted effort in the case of the
2478 * source being utf8 (this_utf8 == TRUE) to take the next character
2479 * in the source, convert it to an unsigned value, and then convert
2480 * it back again. But the source has not been validated here. The
2481 * routine that does the conversion checks for errors like
2484 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2485 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2487 SvCUR_set(sv, d - SvPVX_const(sv));
2490 /* See Note on sizing above. */
2491 sv_utf8_upgrade_flags_grow(sv,
2492 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2493 need + (STRLEN)(send - s) + 1);
2494 d = SvPVX(sv) + SvCUR(sv);
2496 } else if (need > len) {
2497 /* encoded value larger than old, may need extra space (NOTE:
2498 * SvCUR() is not set correctly here). See Note on sizing
2500 const STRLEN off = d - SvPVX_const(sv);
2501 d = SvGROW(sv, off + need + (STRLEN)(send - s) + 1) + off;
2505 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2507 if (uv > 255 && !dorange)
2508 native_range = FALSE;
2512 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2514 } /* while loop to process each character */
2516 /* terminate the string and set up the sv */
2518 SvCUR_set(sv, d - SvPVX_const(sv));
2519 if (SvCUR(sv) >= SvLEN(sv))
2520 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2523 if (PL_encoding && !has_utf8) {
2524 sv_recode_to_utf8(sv, PL_encoding);
2530 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2531 PL_sublex_info.sub_op->op_private |=
2532 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2536 /* shrink the sv if we allocated more than we used */
2537 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2538 SvPV_shrink_to_cur(sv);
2541 /* return the substring (via pl_yylval) only if we parsed anything */
2542 if (s > PL_bufptr) {
2543 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) {
2544 const char *const key = PL_lex_inpat ? "qr" : "q";
2545 const STRLEN keylen = PL_lex_inpat ? 2 : 1;
2549 if (PL_lex_inwhat == OP_TRANS) {
2552 } else if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) {
2560 sv = S_new_constant(aTHX_ start, s - start, key, keylen, sv, NULL,
2563 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2570 * Returns TRUE if there's more to the expression (e.g., a subscript),
2573 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2575 * ->[ and ->{ return TRUE
2576 * { and [ outside a pattern are always subscripts, so return TRUE
2577 * if we're outside a pattern and it's not { or [, then return FALSE
2578 * if we're in a pattern and the first char is a {
2579 * {4,5} (any digits around the comma) returns FALSE
2580 * if we're in a pattern and the first char is a [
2582 * [SOMETHING] has a funky algorithm to decide whether it's a
2583 * character class or not. It has to deal with things like
2584 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2585 * anything else returns TRUE
2588 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2591 S_intuit_more(pTHX_ register char *s)
2595 PERL_ARGS_ASSERT_INTUIT_MORE;
2597 if (PL_lex_brackets)
2599 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2601 if (*s != '{' && *s != '[')
2606 /* In a pattern, so maybe we have {n,m}. */
2623 /* On the other hand, maybe we have a character class */
2626 if (*s == ']' || *s == '^')
2629 /* this is terrifying, and it works */
2630 int weight = 2; /* let's weigh the evidence */
2632 unsigned char un_char = 255, last_un_char;
2633 const char * const send = strchr(s,']');
2634 char tmpbuf[sizeof PL_tokenbuf * 4];
2636 if (!send) /* has to be an expression */
2639 Zero(seen,256,char);
2642 else if (isDIGIT(*s)) {
2644 if (isDIGIT(s[1]) && s[2] == ']')
2650 for (; s < send; s++) {
2651 last_un_char = un_char;
2652 un_char = (unsigned char)*s;
2657 weight -= seen[un_char] * 10;
2658 if (isALNUM_lazy_if(s+1,UTF)) {
2660 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2661 len = (int)strlen(tmpbuf);
2662 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2667 else if (*s == '$' && s[1] &&
2668 strchr("[#!%*<>()-=",s[1])) {
2669 if (/*{*/ strchr("])} =",s[2]))
2678 if (strchr("wds]",s[1]))
2680 else if (seen[(U8)'\''] || seen[(U8)'"'])
2682 else if (strchr("rnftbxcav",s[1]))
2684 else if (isDIGIT(s[1])) {
2686 while (s[1] && isDIGIT(s[1]))
2696 if (strchr("aA01! ",last_un_char))
2698 if (strchr("zZ79~",s[1]))
2700 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2701 weight -= 5; /* cope with negative subscript */
2704 if (!isALNUM(last_un_char)
2705 && !(last_un_char == '$' || last_un_char == '@'
2706 || last_un_char == '&')
2707 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2712 if (keyword(tmpbuf, d - tmpbuf, 0))
2715 if (un_char == last_un_char + 1)
2717 weight -= seen[un_char];
2722 if (weight >= 0) /* probably a character class */
2732 * Does all the checking to disambiguate
2734 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2735 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2737 * First argument is the stuff after the first token, e.g. "bar".
2739 * Not a method if bar is a filehandle.
2740 * Not a method if foo is a subroutine prototyped to take a filehandle.
2741 * Not a method if it's really "Foo $bar"
2742 * Method if it's "foo $bar"
2743 * Not a method if it's really "print foo $bar"
2744 * Method if it's really "foo package::" (interpreted as package->foo)
2745 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2746 * Not a method if bar is a filehandle or package, but is quoted with
2751 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2754 char *s = start + (*start == '$');
2755 char tmpbuf[sizeof PL_tokenbuf];
2762 PERL_ARGS_ASSERT_INTUIT_METHOD;
2765 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2769 const char *proto = SvPVX_const(cv);
2780 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2781 /* start is the beginning of the possible filehandle/object,
2782 * and s is the end of it
2783 * tmpbuf is a copy of it
2786 if (*start == '$') {
2787 if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
2788 isUPPER(*PL_tokenbuf))
2791 len = start - SvPVX(PL_linestr);
2795 start = SvPVX(PL_linestr) + len;
2799 return *s == '(' ? FUNCMETH : METHOD;
2801 if (!keyword(tmpbuf, len, 0)) {
2802 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2806 soff = s - SvPVX(PL_linestr);
2810 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2811 if (indirgv && GvCVu(indirgv))
2813 /* filehandle or package name makes it a method */
2814 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
2816 soff = s - SvPVX(PL_linestr);
2819 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2820 return 0; /* no assumptions -- "=>" quotes bearword */
2822 start_force(PL_curforce);
2823 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2824 newSVpvn(tmpbuf,len));
2825 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2827 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2832 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2834 return *s == '(' ? FUNCMETH : METHOD;
2840 /* Encoded script support. filter_add() effectively inserts a
2841 * 'pre-processing' function into the current source input stream.
2842 * Note that the filter function only applies to the current source file
2843 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2845 * The datasv parameter (which may be NULL) can be used to pass
2846 * private data to this instance of the filter. The filter function
2847 * can recover the SV using the FILTER_DATA macro and use it to
2848 * store private buffers and state information.
2850 * The supplied datasv parameter is upgraded to a PVIO type
2851 * and the IoDIRP/IoANY field is used to store the function pointer,
2852 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2853 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2854 * private use must be set using malloc'd pointers.
2858 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2867 if (!PL_rsfp_filters)
2868 PL_rsfp_filters = newAV();
2871 SvUPGRADE(datasv, SVt_PVIO);
2872 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2873 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2874 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2875 FPTR2DPTR(void *, IoANY(datasv)),
2876 SvPV_nolen(datasv)));
2877 av_unshift(PL_rsfp_filters, 1);
2878 av_store(PL_rsfp_filters, 0, datasv) ;
2883 /* Delete most recently added instance of this filter function. */
2885 Perl_filter_del(pTHX_ filter_t funcp)
2890 PERL_ARGS_ASSERT_FILTER_DEL;
2893 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2894 FPTR2DPTR(void*, funcp)));
2896 if (!PL_parser || !PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2898 /* if filter is on top of stack (usual case) just pop it off */
2899 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2900 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2901 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2902 IoANY(datasv) = (void *)NULL;
2903 sv_free(av_pop(PL_rsfp_filters));
2907 /* we need to search for the correct entry and clear it */
2908 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2912 /* Invoke the idxth filter function for the current rsfp. */
2913 /* maxlen 0 = read one text line */
2915 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2920 /* This API is bad. It should have been using unsigned int for maxlen.
2921 Not sure if we want to change the API, but if not we should sanity
2922 check the value here. */
2923 const unsigned int correct_length
2932 PERL_ARGS_ASSERT_FILTER_READ;
2934 if (!PL_parser || !PL_rsfp_filters)
2936 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2937 /* Provide a default input filter to make life easy. */
2938 /* Note that we append to the line. This is handy. */
2939 DEBUG_P(PerlIO_printf(Perl_debug_log,
2940 "filter_read %d: from rsfp\n", idx));
2941 if (correct_length) {
2944 const int old_len = SvCUR(buf_sv);
2946 /* ensure buf_sv is large enough */
2947 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2948 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2949 correct_length)) <= 0) {
2950 if (PerlIO_error(PL_rsfp))
2951 return -1; /* error */
2953 return 0 ; /* end of file */
2955 SvCUR_set(buf_sv, old_len + len) ;
2958 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2959 if (PerlIO_error(PL_rsfp))
2960 return -1; /* error */
2962 return 0 ; /* end of file */
2965 return SvCUR(buf_sv);
2967 /* Skip this filter slot if filter has been deleted */
2968 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2969 DEBUG_P(PerlIO_printf(Perl_debug_log,
2970 "filter_read %d: skipped (filter deleted)\n",
2972 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2974 /* Get function pointer hidden within datasv */
2975 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2976 DEBUG_P(PerlIO_printf(Perl_debug_log,
2977 "filter_read %d: via function %p (%s)\n",
2978 idx, (void*)datasv, SvPV_nolen_const(datasv)));
2979 /* Call function. The function is expected to */
2980 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2981 /* Return: <0:error, =0:eof, >0:not eof */
2982 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2986 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2990 PERL_ARGS_ASSERT_FILTER_GETS;
2992 #ifdef PERL_CR_FILTER
2993 if (!PL_rsfp_filters) {
2994 filter_add(S_cr_textfilter,NULL);
2997 if (PL_rsfp_filters) {
2999 SvCUR_set(sv, 0); /* start with empty line */
3000 if (FILTER_READ(0, sv, 0) > 0)
3001 return ( SvPVX(sv) ) ;
3006 return (sv_gets(sv, fp, append));
3010 S_find_in_my_stash(pTHX_ const char *pkgname, STRLEN len)
3015 PERL_ARGS_ASSERT_FIND_IN_MY_STASH;
3017 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
3021 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
3022 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
3024 return GvHV(gv); /* Foo:: */
3027 /* use constant CLASS => 'MyClass' */
3028 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
3029 if (gv && GvCV(gv)) {
3030 SV * const sv = cv_const_sv(GvCV(gv));
3032 pkgname = SvPV_const(sv, len);
3035 return gv_stashpvn(pkgname, len, 0);
3039 * S_readpipe_override
3040 * Check whether readpipe() is overriden, and generates the appropriate
3041 * optree, provided sublex_start() is called afterwards.
3044 S_readpipe_override(pTHX)
3047 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
3048 pl_yylval.ival = OP_BACKTICK;
3050 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
3052 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
3053 && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
3054 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
3056 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
3057 append_elem(OP_LIST,
3058 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
3059 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
3066 * The intent of this yylex wrapper is to minimize the changes to the
3067 * tokener when we aren't interested in collecting madprops. It remains
3068 * to be seen how successful this strategy will be...
3075 char *s = PL_bufptr;
3077 /* make sure PL_thiswhite is initialized */
3081 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
3082 if (PL_pending_ident)
3083 return S_pending_ident(aTHX);
3085 /* previous token ate up our whitespace? */
3086 if (!PL_lasttoke && PL_nextwhite) {
3087 PL_thiswhite = PL_nextwhite;
3091 /* isolate the token, and figure out where it is without whitespace */
3092 PL_realtokenstart = -1;
3096 assert(PL_curforce < 0);
3098 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
3099 if (!PL_thistoken) {
3100 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
3101 PL_thistoken = newSVpvs("");
3103 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
3104 PL_thistoken = newSVpvn(tstart, s - tstart);
3107 if (PL_thismad) /* install head */
3108 CURMAD('X', PL_thistoken);
3111 /* last whitespace of a sublex? */
3112 if (optype == ')' && PL_endwhite) {
3113 CURMAD('X', PL_endwhite);
3118 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
3119 if (!PL_thiswhite && !PL_endwhite && !optype) {
3120 sv_free(PL_thistoken);
3125 /* put off final whitespace till peg */
3126 if (optype == ';' && !PL_rsfp) {
3127 PL_nextwhite = PL_thiswhite;
3130 else if (PL_thisopen) {
3131 CURMAD('q', PL_thisopen);
3133 sv_free(PL_thistoken);
3137 /* Store actual token text as madprop X */
3138 CURMAD('X', PL_thistoken);
3142 /* add preceding whitespace as madprop _ */
3143 CURMAD('_', PL_thiswhite);
3147 /* add quoted material as madprop = */
3148 CURMAD('=', PL_thisstuff);
3152 /* add terminating quote as madprop Q */
3153 CURMAD('Q', PL_thisclose);
3157 /* special processing based on optype */
3161 /* opval doesn't need a TOKEN since it can already store mp */
3171 if (pl_yylval.opval)
3172 append_madprops(PL_thismad, pl_yylval.opval, 0);
3180 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3189 /* remember any fake bracket that lexer is about to discard */
3190 if (PL_lex_brackets == 1 &&
3191 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3194 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3197 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3198 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3201 break; /* don't bother looking for trailing comment */
3210 /* attach a trailing comment to its statement instead of next token */
3214 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3216 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3218 if (*s == '\n' || *s == '#') {
3219 while (s < PL_bufend && *s != '\n')
3223 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3224 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3241 /* Create new token struct. Note: opvals return early above. */
3242 pl_yylval.tkval = newTOKEN(optype, pl_yylval, PL_thismad);
3249 S_tokenize_use(pTHX_ int is_use, char *s) {
3252 PERL_ARGS_ASSERT_TOKENIZE_USE;
3254 if (PL_expect != XSTATE)
3255 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3256 is_use ? "use" : "no"));
3258 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3259 s = force_version(s, TRUE);
3260 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3261 start_force(PL_curforce);
3262 NEXTVAL_NEXTTOKE.opval = NULL;
3265 else if (*s == 'v') {
3266 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3267 s = force_version(s, FALSE);
3271 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3272 s = force_version(s, FALSE);
3274 pl_yylval.ival = is_use;
3278 static const char* const exp_name[] =
3279 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3280 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3287 Works out what to call the token just pulled out of the input
3288 stream. The yacc parser takes care of taking the ops we return and
3289 stitching them into a tree.
3295 if read an identifier
3296 if we're in a my declaration
3297 croak if they tried to say my($foo::bar)
3298 build the ops for a my() declaration
3299 if it's an access to a my() variable
3300 are we in a sort block?
3301 croak if my($a); $a <=> $b
3302 build ops for access to a my() variable
3303 if in a dq string, and they've said @foo and we can't find @foo
3305 build ops for a bareword
3306 if we already built the token before, use it.
3311 #pragma segment Perl_yylex
3317 register char *s = PL_bufptr;
3322 /* orig_keyword, gvp, and gv are initialized here because
3323 * jump to the label just_a_word_zero can bypass their
3324 * initialization later. */
3325 I32 orig_keyword = 0;
3330 SV* tmp = newSVpvs("");
3331 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3332 (IV)CopLINE(PL_curcop),
3333 lex_state_names[PL_lex_state],
3334 exp_name[PL_expect],
3335 pv_display(tmp, s, strlen(s), 0, 60));
3338 /* check if there's an identifier for us to look at */
3339 if (PL_pending_ident)
3340 return REPORT(S_pending_ident(aTHX));
3342 /* no identifier pending identification */
3344 switch (PL_lex_state) {
3346 case LEX_NORMAL: /* Some compilers will produce faster */
3347 case LEX_INTERPNORMAL: /* code if we comment these out. */
3351 /* when we've already built the next token, just pull it out of the queue */
3355 pl_yylval = PL_nexttoke[PL_lasttoke].next_val;
3357 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3358 PL_nexttoke[PL_lasttoke].next_mad = 0;
3359 if (PL_thismad && PL_thismad->mad_key == '_') {
3360 PL_thiswhite = MUTABLE_SV(PL_thismad->mad_val);
3361 PL_thismad->mad_val = 0;
3362 mad_free(PL_thismad);
3367 PL_lex_state = PL_lex_defer;
3368 PL_expect = PL_lex_expect;
3369 PL_lex_defer = LEX_NORMAL;
3370 if (!PL_nexttoke[PL_lasttoke].next_type)
3375 pl_yylval = PL_nextval[PL_nexttoke];
3377 PL_lex_state = PL_lex_defer;
3378 PL_expect = PL_lex_expect;
3379 PL_lex_defer = LEX_NORMAL;
3383 /* FIXME - can these be merged? */
3384 return(PL_nexttoke[PL_lasttoke].next_type);
3386 return REPORT(PL_nexttype[PL_nexttoke]);
3389 /* interpolated case modifiers like \L \U, including \Q and \E.
3390 when we get here, PL_bufptr is at the \
3392 case LEX_INTERPCASEMOD:
3394 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3395 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3397 /* handle \E or end of string */
3398 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3400 if (PL_lex_casemods) {
3401 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3402 PL_lex_casestack[PL_lex_casemods] = '\0';
3404 if (PL_bufptr != PL_bufend
3405 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3407 PL_lex_state = LEX_INTERPCONCAT;
3410 PL_thistoken = newSVpvs("\\E");
3416 while (PL_bufptr != PL_bufend &&
3417 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3419 PL_thiswhite = newSVpvs("");
3420 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3424 if (PL_bufptr != PL_bufend)
3427 PL_lex_state = LEX_INTERPCONCAT;
3431 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3432 "### Saw case modifier\n"); });
3434 if (s[1] == '\\' && s[2] == 'E') {
3437 PL_thiswhite = newSVpvs("");
3438 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3441 PL_lex_state = LEX_INTERPCONCAT;
3446 if (!PL_madskills) /* when just compiling don't need correct */
3447 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3448 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3449 if ((*s == 'L' || *s == 'U') &&
3450 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3451 PL_lex_casestack[--PL_lex_casemods] = '\0';
3454 if (PL_lex_casemods > 10)
3455 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3456 PL_lex_casestack[PL_lex_casemods++] = *s;
3457 PL_lex_casestack[PL_lex_casemods] = '\0';
3458 PL_lex_state = LEX_INTERPCONCAT;
3459 start_force(PL_curforce);
3460 NEXTVAL_NEXTTOKE.ival = 0;
3462 start_force(PL_curforce);
3464 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3466 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3468 NEXTVAL_NEXTTOKE.ival = OP_LC;
3470 NEXTVAL_NEXTTOKE.ival = OP_UC;
3472 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3474 Perl_croak(aTHX_ "panic: yylex");
3476 SV* const tmpsv = newSVpvs("\\ ");
3477 /* replace the space with the character we want to escape
3479 SvPVX(tmpsv)[1] = *s;
3485 if (PL_lex_starts) {
3491 sv_free(PL_thistoken);
3492 PL_thistoken = newSVpvs("");
3495 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3496 if (PL_lex_casemods == 1 && PL_lex_inpat)
3505 case LEX_INTERPPUSH:
3506 return REPORT(sublex_push());
3508 case LEX_INTERPSTART:
3509 if (PL_bufptr == PL_bufend)
3510 return REPORT(sublex_done());
3511 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3512 "### Interpolated variable\n"); });
3514 PL_lex_dojoin = (*PL_bufptr == '@');
3515 PL_lex_state = LEX_INTERPNORMAL;
3516 if (PL_lex_dojoin) {
3517 start_force(PL_curforce);
3518 NEXTVAL_NEXTTOKE.ival = 0;
3520 start_force(PL_curforce);
3521 force_ident("\"", '$');
3522 start_force(PL_curforce);
3523 NEXTVAL_NEXTTOKE.ival = 0;
3525 start_force(PL_curforce);
3526 NEXTVAL_NEXTTOKE.ival = 0;
3528 start_force(PL_curforce);
3529 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3532 if (PL_lex_starts++) {
3537 sv_free(PL_thistoken);
3538 PL_thistoken = newSVpvs("");
3541 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3542 if (!PL_lex_casemods && PL_lex_inpat)
3549 case LEX_INTERPENDMAYBE:
3550 if (intuit_more(PL_bufptr)) {
3551 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3557 if (PL_lex_dojoin) {
3558 PL_lex_dojoin = FALSE;
3559 PL_lex_state = LEX_INTERPCONCAT;
3563 sv_free(PL_thistoken);
3564 PL_thistoken = newSVpvs("");
3569 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3570 && SvEVALED(PL_lex_repl))
3572 if (PL_bufptr != PL_bufend)
3573 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3577 case LEX_INTERPCONCAT:
3579 if (PL_lex_brackets)
3580 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3582 if (PL_bufptr == PL_bufend)
3583 return REPORT(sublex_done());
3585 if (SvIVX(PL_linestr) == '\'') {
3586 SV *sv = newSVsv(PL_linestr);
3589 else if ( PL_hints & HINT_NEW_RE )
3590 sv = new_constant(NULL, 0, "qr", sv, sv, "q", 1);
3591 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3595 s = scan_const(PL_bufptr);
3597 PL_lex_state = LEX_INTERPCASEMOD;
3599 PL_lex_state = LEX_INTERPSTART;
3602 if (s != PL_bufptr) {
3603 start_force(PL_curforce);
3605 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3607 NEXTVAL_NEXTTOKE = pl_yylval;
3610 if (PL_lex_starts++) {
3614 sv_free(PL_thistoken);
3615 PL_thistoken = newSVpvs("");
3618 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3619 if (!PL_lex_casemods && PL_lex_inpat)
3632 PL_lex_state = LEX_NORMAL;
3633 s = scan_formline(PL_bufptr);
3634 if (!PL_lex_formbrack)
3640 PL_oldoldbufptr = PL_oldbufptr;
3646 sv_free(PL_thistoken);
3649 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3653 if (isIDFIRST_lazy_if(s,UTF))
3655 len = UTF ? Perl_utf8_length(aTHX_ (U8 *) PL_linestart, (U8 *) s) : (STRLEN) (s - PL_linestart);
3656 Perl_croak(aTHX_ "Unrecognized character \\x%02X in column %d", *s & 255, (int) len + 1);
3659 goto fake_eof; /* emulate EOF on ^D or ^Z */
3668 if (PL_lex_brackets) {
3669 yyerror((const char *)
3671 ? "Format not terminated"
3672 : "Missing right curly or square bracket"));
3674 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3675 "### Tokener got EOF\n");
3679 if (s++ < PL_bufend)
3680 goto retry; /* ignore stray nulls */
3683 if (!PL_in_eval && !PL_preambled) {
3684 PL_preambled = TRUE;
3690 /* Generate a string of Perl code to load the debugger.
3691 * If PERL5DB is set, it will return the contents of that,
3692 * otherwise a compile-time require of perl5db.pl. */
3694 const char * const pdb = PerlEnv_getenv("PERL5DB");
3697 sv_setpv(PL_linestr, pdb);
3698 sv_catpvs(PL_linestr,";");
3700 SETERRNO(0,SS_NORMAL);
3701 sv_setpvs(PL_linestr, "BEGIN { require 'perl5db.pl' };");
3704 sv_setpvs(PL_linestr,"");
3705 if (PL_preambleav) {
3706 SV **svp = AvARRAY(PL_preambleav);
3707 SV **const end = svp + AvFILLp(PL_preambleav);
3709 sv_catsv(PL_linestr, *svp);
3711 sv_catpvs(PL_linestr, ";");
3713 sv_free(MUTABLE_SV(PL_preambleav));
3714 PL_preambleav = NULL;
3717 sv_catpvs(PL_linestr,
3718 "use feature ':5." STRINGIFY(PERL_VERSION) "';");
3719 if (PL_minus_n || PL_minus_p) {
3720 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3722 sv_catpvs(PL_linestr,"chomp;");
3725 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3726 || *PL_splitstr == '"')
3727 && strchr(PL_splitstr + 1, *PL_splitstr))
3728 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3730 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3731 bytes can be used as quoting characters. :-) */
3732 const char *splits = PL_splitstr;
3733 sv_catpvs(PL_linestr, "our @F=split(q\0");
3736 if (*splits == '\\')
3737 sv_catpvn(PL_linestr, splits, 1);
3738 sv_catpvn(PL_linestr, splits, 1);
3739 } while (*splits++);
3740 /* This loop will embed the trailing NUL of
3741 PL_linestr as the last thing it does before
3743 sv_catpvs(PL_linestr, ");");
3747 sv_catpvs(PL_linestr,"our @F=split(' ');");
3750 sv_catpvs(PL_linestr, "\n");
3751 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3752 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3753 PL_last_lop = PL_last_uni = NULL;
3754 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
3755 update_debugger_info(PL_linestr, NULL, 0);
3759 bof = PL_rsfp ? TRUE : FALSE;
3760 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3763 PL_realtokenstart = -1;
3766 if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3767 PerlIO_clearerr(PL_rsfp);
3769 (void)PerlIO_close(PL_rsfp);
3771 PL_doextract = FALSE;
3773 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3779 sv_setpvs(PL_linestr, ";}continue{print;}");
3781 sv_setpvs(PL_linestr, ";}");
3782 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3783 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3784 PL_last_lop = PL_last_uni = NULL;
3785 PL_minus_n = PL_minus_p = 0;
3788 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3789 PL_last_lop = PL_last_uni = NULL;
3790 sv_setpvs(PL_linestr,"");
3791 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3793 /* If it looks like the start of a BOM or raw UTF-16,
3794 * check if it in fact is. */
3800 #ifdef PERLIO_IS_STDIO
3801 # ifdef __GNU_LIBRARY__
3802 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3803 # define FTELL_FOR_PIPE_IS_BROKEN
3807 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3808 # define FTELL_FOR_PIPE_IS_BROKEN
3813 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3815 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3816 s = swallow_bom((U8*)s);
3820 /* Incest with pod. */
3823 sv_catsv(PL_thiswhite, PL_linestr);
3825 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
3826 sv_setpvs(PL_linestr, "");
3827 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3828 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3829 PL_last_lop = PL_last_uni = NULL;
3830 PL_doextract = FALSE;
3834 } while (PL_doextract);
3835 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3836 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
3837 update_debugger_info(PL_linestr, NULL, 0);
3838 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3839 PL_last_lop = PL_last_uni = NULL;
3840 if (CopLINE(PL_curcop) == 1) {
3841 while (s < PL_bufend && isSPACE(*s))
3843 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3847 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3851 if (*s == '#' && *(s+1) == '!')
3853 #ifdef ALTERNATE_SHEBANG
3855 static char const as[] = ALTERNATE_SHEBANG;
3856 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3857 d = s + (sizeof(as) - 1);
3859 #endif /* ALTERNATE_SHEBANG */
3868 while (*d && !isSPACE(*d))
3872 #ifdef ARG_ZERO_IS_SCRIPT
3873 if (ipathend > ipath) {
3875 * HP-UX (at least) sets argv[0] to the script name,
3876 * which makes $^X incorrect. And Digital UNIX and Linux,
3877 * at least, set argv[0] to the basename of the Perl
3878 * interpreter. So, having found "#!", we'll set it right.
3880 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3882 assert(SvPOK(x) || SvGMAGICAL(x));
3883 if (sv_eq(x, CopFILESV(PL_curcop))) {
3884 sv_setpvn(x, ipath, ipathend - ipath);
3890 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3891 const char * const lstart = SvPV_const(x,llen);
3893 bstart += blen - llen;
3894 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3895 sv_setpvn(x, ipath, ipathend - ipath);
3900 TAINT_NOT; /* $^X is always tainted, but that's OK */
3902 #endif /* ARG_ZERO_IS_SCRIPT */
3907 d = instr(s,"perl -");
3909 d = instr(s,"perl");
3911 /* avoid getting into infinite loops when shebang
3912 * line contains "Perl" rather than "perl" */
3914 for (d = ipathend-4; d >= ipath; --d) {
3915 if ((*d == 'p' || *d == 'P')
3916 && !ibcmp(d, "perl", 4))
3926 #ifdef ALTERNATE_SHEBANG
3928 * If the ALTERNATE_SHEBANG on this system starts with a
3929 * character that can be part of a Perl expression, then if
3930 * we see it but not "perl", we're probably looking at the
3931 * start of Perl code, not a request to hand off to some
3932 * other interpreter. Similarly, if "perl" is there, but
3933 * not in the first 'word' of the line, we assume the line
3934 * contains the start of the Perl program.
3936 if (d && *s != '#') {
3937 const char *c = ipath;
3938 while (*c && !strchr("; \t\r\n\f\v#", *c))
3941 d = NULL; /* "perl" not in first word; ignore */
3943 *s = '#'; /* Don't try to parse shebang line */
3945 #endif /* ALTERNATE_SHEBANG */
3950 !instr(s,"indir") &&
3951 instr(PL_origargv[0],"perl"))
3958 while (s < PL_bufend && isSPACE(*s))
3960 if (s < PL_bufend) {
3961 Newxz(newargv,PL_origargc+3,char*);
3963 while (s < PL_bufend && !isSPACE(*s))
3966 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3969 newargv = PL_origargv;
3972 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3974 Perl_croak(aTHX_ "Can't exec %s", ipath);
3977 while (*d && !isSPACE(*d))
3979 while (SPACE_OR_TAB(*d))
3983 const bool switches_done = PL_doswitches;
3984 const U32 oldpdb = PL_perldb;
3985 const bool oldn = PL_minus_n;
3986 const bool oldp = PL_minus_p;
3990 if (*d1 == 'M' || *d1 == 'm' || *d1 == 'C') {
3991 const char * const m = d1;
3992 while (*d1 && !isSPACE(*d1))
3994 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3997 d1 = moreswitches(d1);
3999 if (PL_doswitches && !switches_done) {
4000 int argc = PL_origargc;
4001 char **argv = PL_origargv;
4004 } while (argc && argv[0][0] == '-' && argv[0][1]);
4005 init_argv_symbols(argc,argv);
4007 if (((PERLDB_LINE || PERLDB_SAVESRC) && !oldpdb) ||
4008 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
4009 /* if we have already added "LINE: while (<>) {",
4010 we must not do it again */
4012 sv_setpvs(PL_linestr, "");
4013 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4014 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4015 PL_last_lop = PL_last_uni = NULL;
4016 PL_preambled = FALSE;
4017 if (PERLDB_LINE || PERLDB_SAVESRC)
4018 (void)gv_fetchfile(PL_origfilename);
4025 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4027 PL_lex_state = LEX_FORMLINE;
4032 #ifdef PERL_STRICT_CR
4033 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
4035 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
4037 case ' ': case '\t': case '\f': case 013:
4039 PL_realtokenstart = -1;
4041 PL_thiswhite = newSVpvs("");
4042 sv_catpvn(PL_thiswhite, s, 1);
4049 PL_realtokenstart = -1;
4053 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
4054 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
4055 /* handle eval qq[#line 1 "foo"\n ...] */
4056 CopLINE_dec(PL_curcop);
4059 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
4061 if (!PL_in_eval || PL_rsfp)
4066 while (d < PL_bufend && *d != '\n')
4070 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4071 Perl_croak(aTHX_ "panic: input overflow");
4074 PL_thiswhite = newSVpvn(s, d - s);
4079 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4081 PL_lex_state = LEX_FORMLINE;
4087 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
4088 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
4091 TOKEN(PEG); /* make sure any #! line is accessible */
4096 /* if (PL_madskills && PL_lex_formbrack) { */
4098 while (d < PL_bufend && *d != '\n')
4102 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4103 Perl_croak(aTHX_ "panic: input overflow");
4104 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
4106 PL_thiswhite = newSVpvs("");
4107 if (CopLINE(PL_curcop) == 1) {
4108 sv_setpvs(PL_thiswhite, "");
4111 sv_catpvn(PL_thiswhite, s, d - s);
4125 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
4133 while (s < PL_bufend && SPACE_OR_TAB(*s))
4136 if (strnEQ(s,"=>",2)) {
4137 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
4138 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
4139 OPERATOR('-'); /* unary minus */
4141 PL_last_uni = PL_oldbufptr;
4143 case 'r': ftst = OP_FTEREAD; break;
4144 case 'w': ftst = OP_FTEWRITE; break;
4145 case 'x': ftst = OP_FTEEXEC; break;
4146 case 'o': ftst = OP_FTEOWNED; break;
4147 case 'R': ftst = OP_FTRREAD; break;
4148 case 'W': ftst = OP_FTRWRITE; break;
4149 case 'X': ftst = OP_FTREXEC; break;
4150 case 'O': ftst = OP_FTROWNED; break;
4151 case 'e': ftst = OP_FTIS; break;
4152 case 'z': ftst = OP_FTZERO; break;
4153 case 's': ftst = OP_FTSIZE; break;
4154 case 'f': ftst = OP_FTFILE; break;
4155 case 'd': ftst = OP_FTDIR; break;
4156 case 'l': ftst = OP_FTLINK; break;
4157 case 'p': ftst = OP_FTPIPE; break;
4158 case 'S': ftst = OP_FTSOCK; break;
4159 case 'u': ftst = OP_FTSUID; break;
4160 case 'g': ftst = OP_FTSGID; break;
4161 case 'k': ftst = OP_FTSVTX; break;
4162 case 'b': ftst = OP_FTBLK; break;
4163 case 'c': ftst = OP_FTCHR; break;
4164 case 't': ftst = OP_FTTTY; break;
4165 case 'T': ftst = OP_FTTEXT; break;
4166 case 'B': ftst = OP_FTBINARY; break;
4167 case 'M': case 'A': case 'C':
4168 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
4170 case 'M': ftst = OP_FTMTIME; break;
4171 case 'A': ftst = OP_FTATIME; break;
4172 case 'C': ftst = OP_FTCTIME; break;
4180 PL_last_lop_op = (OPCODE)ftst;
4181 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4182 "### Saw file test %c\n", (int)tmp);
4187 /* Assume it was a minus followed by a one-letter named
4188 * subroutine call (or a -bareword), then. */
4189 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4190 "### '-%c' looked like a file test but was not\n",
4197 const char tmp = *s++;
4200 if (PL_expect == XOPERATOR)
4205 else if (*s == '>') {
4208 if (isIDFIRST_lazy_if(s,UTF)) {
4209 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4217 if (PL_expect == XOPERATOR)
4220 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4222 OPERATOR('-'); /* unary minus */
4228 const char tmp = *s++;
4231 if (PL_expect == XOPERATOR)
4236 if (PL_expect == XOPERATOR)
4239 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4246 if (PL_expect != XOPERATOR) {
4247 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4248 PL_expect = XOPERATOR;
4249 force_ident(PL_tokenbuf, '*');
4262 if (PL_expect == XOPERATOR) {
4266 PL_tokenbuf[0] = '%';
4267 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4268 sizeof PL_tokenbuf - 1, FALSE);
4269 if (!PL_tokenbuf[1]) {
4272 PL_pending_ident = '%';
4281 const char tmp = *s++;
4286 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
4293 const char tmp = *s++;
4299 goto just_a_word_zero_gv;
4302 switch (PL_expect) {
4308 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4310 PL_bufptr = s; /* update in case we back off */
4316 PL_expect = XTERMBLOCK;
4319 stuffstart = s - SvPVX(PL_linestr) - 1;
4323 while (isIDFIRST_lazy_if(s,UTF)) {
4326 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4327 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4328 if (tmp < 0) tmp = -tmp;
4343 sv = newSVpvn(s, len);
4345 d = scan_str(d,TRUE,TRUE);
4347 /* MUST advance bufptr here to avoid bogus
4348 "at end of line" context messages from yyerror().
4350 PL_bufptr = s + len;
4351 yyerror("Unterminated attribute parameter in attribute list");
4355 return REPORT(0); /* EOF indicator */
4359 sv_catsv(sv, PL_lex_stuff);
4360 attrs = append_elem(OP_LIST, attrs,
4361 newSVOP(OP_CONST, 0, sv));
4362 SvREFCNT_dec(PL_lex_stuff);
4363 PL_lex_stuff = NULL;
4366 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4368 if (PL_in_my == KEY_our) {
4369 deprecate(":unique");
4372 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4375 /* NOTE: any CV attrs applied here need to be part of
4376 the CVf_BUILTIN_ATTRS define in cv.h! */
4377 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4379 CvLVALUE_on(PL_compcv);
4381 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4383 deprecate(":locked");
4385 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4387 CvMETHOD_on(PL_compcv);
4389 /* After we've set the flags, it could be argued that
4390 we don't need to do the attributes.pm-based setting
4391 process, and shouldn't bother appending recognized
4392 flags. To experiment with that, uncomment the
4393 following "else". (Note that's already been
4394 uncommented. That keeps the above-applied built-in
4395 attributes from being intercepted (and possibly
4396 rejected) by a package's attribute routines, but is
4397 justified by the performance win for the common case
4398 of applying only built-in attributes.) */
4400 attrs = append_elem(OP_LIST, attrs,
4401 newSVOP(OP_CONST, 0,
4405 if (*s == ':' && s[1] != ':')
4408 break; /* require real whitespace or :'s */
4409 /* XXX losing whitespace on sequential attributes here */
4413 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4414 if (*s != ';' && *s != '}' && *s != tmp
4415 && (tmp != '=' || *s != ')')) {
4416 const char q = ((*s == '\'') ? '"' : '\'');
4417 /* If here for an expression, and parsed no attrs, back
4419 if (tmp == '=' && !attrs) {
4423 /* MUST advance bufptr here to avoid bogus "at end of line"
4424 context messages from yyerror().
4427 yyerror( (const char *)
4429 ? Perl_form(aTHX_ "Invalid separator character "
4430 "%c%c%c in attribute list", q, *s, q)
4431 : "Unterminated attribute list" ) );
4439 start_force(PL_curforce);
4440 NEXTVAL_NEXTTOKE.opval = attrs;
4441 CURMAD('_', PL_nextwhite);
4446 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4447 (s - SvPVX(PL_linestr)) - stuffstart);
4455 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4456 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4464 const char tmp = *s++;
4469 const char tmp = *s++;
4477 if (PL_lex_brackets <= 0)
4478 yyerror("Unmatched right square bracket");
4481 if (PL_lex_state == LEX_INTERPNORMAL) {
4482 if (PL_lex_brackets == 0) {
4483 if (*s == '-' && s[1] == '>')
4484 PL_lex_state = LEX_INTERPENDMAYBE;
4485 else if (*s != '[' && *s != '{')
4486 PL_lex_state = LEX_INTERPEND;
4493 if (PL_lex_brackets > 100) {
4494 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4496 switch (PL_expect) {
4498 if (PL_lex_formbrack) {
4502 if (PL_oldoldbufptr == PL_last_lop)
4503 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4505 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4506 OPERATOR(HASHBRACK);
4508 while (s < PL_bufend && SPACE_OR_TAB(*s))
4511 PL_tokenbuf[0] = '\0';
4512 if (d < PL_bufend && *d == '-') {
4513 PL_tokenbuf[0] = '-';
4515 while (d < PL_bufend && SPACE_OR_TAB(*d))
4518 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4519 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4521 while (d < PL_bufend && SPACE_OR_TAB(*d))
4524 const char minus = (PL_tokenbuf[0] == '-');
4525 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4533 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4538 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4543 if (PL_oldoldbufptr == PL_last_lop)
4544 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4546 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4549 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4551 /* This hack is to get the ${} in the message. */
4553 yyerror("syntax error");
4556 OPERATOR(HASHBRACK);
4558 /* This hack serves to disambiguate a pair of curlies
4559 * as being a block or an anon hash. Normally, expectation
4560 * determines that, but in cases where we're not in a
4561 * position to expect anything in particular (like inside
4562 * eval"") we have to resolve the ambiguity. This code
4563 * covers the case where the first term in the curlies is a
4564 * quoted string. Most other cases need to be explicitly
4565 * disambiguated by prepending a "+" before the opening
4566 * curly in order to force resolution as an anon hash.
4568 * XXX should probably propagate the outer expectation
4569 * into eval"" to rely less on this hack, but that could
4570 * potentially break current behavior of eval"".
4574 if (*s == '\'' || *s == '"' || *s == '`') {
4575 /* common case: get past first string, handling escapes */
4576 for (t++; t < PL_bufend && *t != *s;)
4577 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4581 else if (*s == 'q') {
4584 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4587 /* skip q//-like construct */
4589 char open, close, term;
4592 while (t < PL_bufend && isSPACE(*t))
4594 /* check for q => */
4595 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4596 OPERATOR(HASHBRACK);
4600 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4604 for (t++; t < PL_bufend; t++) {
4605 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4607 else if (*t == open)
4611 for (t++; t < PL_bufend; t++) {
4612 if (*t == '\\' && t+1 < PL_bufend)
4614 else if (*t == close && --brackets <= 0)
4616 else if (*t == open)
4623 /* skip plain q word */
4624 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4627 else if (isALNUM_lazy_if(t,UTF)) {
4629 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4632 while (t < PL_bufend && isSPACE(*t))
4634 /* if comma follows first term, call it an anon hash */
4635 /* XXX it could be a comma expression with loop modifiers */
4636 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4637 || (*t == '=' && t[1] == '>')))
4638 OPERATOR(HASHBRACK);
4639 if (PL_expect == XREF)
4642 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4648 pl_yylval.ival = CopLINE(PL_curcop);
4649 if (isSPACE(*s) || *s == '#')
4650 PL_copline = NOLINE; /* invalidate current command line number */
4655 if (PL_lex_brackets <= 0)
4656 yyerror("Unmatched right curly bracket");
4658 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4659 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4660 PL_lex_formbrack = 0;
4661 if (PL_lex_state == LEX_INTERPNORMAL) {
4662 if (PL_lex_brackets == 0) {
4663 if (PL_expect & XFAKEBRACK) {
4664 PL_expect &= XENUMMASK;
4665 PL_lex_state = LEX_INTERPEND;
4670 PL_thiswhite = newSVpvs("");
4671 sv_catpvs(PL_thiswhite,"}");
4674 return yylex(); /* ignore fake brackets */
4676 if (*s == '-' && s[1] == '>')
4677 PL_lex_state = LEX_INTERPENDMAYBE;
4678 else if (*s != '[' && *s != '{')
4679 PL_lex_state = LEX_INTERPEND;
4682 if (PL_expect & XFAKEBRACK) {
4683 PL_expect &= XENUMMASK;
4685 return yylex(); /* ignore fake brackets */
4687 start_force(PL_curforce);
4689 curmad('X', newSVpvn(s-1,1));
4690 CURMAD('_', PL_thiswhite);
4695 PL_thistoken = newSVpvs("");
4703 if (PL_expect == XOPERATOR) {
4704 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4705 && isIDFIRST_lazy_if(s,UTF))
4707 CopLINE_dec(PL_curcop);
4708 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
4709 CopLINE_inc(PL_curcop);
4714 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4716 PL_expect = XOPERATOR;
4717 force_ident(PL_tokenbuf, '&');
4721 pl_yylval.ival = (OPpENTERSUB_AMPER<<8);
4733 const char tmp = *s++;
4740 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4741 && strchr("+-*/%.^&|<",tmp))
4742 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4743 "Reversed %c= operator",(int)tmp);
4745 if (PL_expect == XSTATE && isALPHA(tmp) &&
4746 (s == PL_linestart+1 || s[-2] == '\n') )
4748 if (PL_in_eval && !PL_rsfp) {
4753 if (strnEQ(s,"=cut",4)) {
4769 PL_thiswhite = newSVpvs("");
4770 sv_catpvn(PL_thiswhite, PL_linestart,
4771 PL_bufend - PL_linestart);
4775 PL_doextract = TRUE;
4779 if (PL_lex_brackets < PL_lex_formbrack) {
4781 #ifdef PERL_STRICT_CR
4782 while (SPACE_OR_TAB(*t))
4784 while (SPACE_OR_TAB(*t) || *t == '\r')
4787 if (*t == '\n' || *t == '#') {
4796 if (PL_expect == XSTATE && s[1] == '!' && s[2] == '!') {
4802 const char tmp = *s++;
4804 /* was this !=~ where !~ was meant?
4805 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4807 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4808 const char *t = s+1;
4810 while (t < PL_bufend && isSPACE(*t))
4813 if (*t == '/' || *t == '?' ||
4814 ((*t == 'm' || *t == 's' || *t == 'y')
4815 && !isALNUM(t[1])) ||
4816 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4817 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4818 "!=~ should be !~");
4828 if (PL_expect != XOPERATOR) {
4829 if (s[1] != '<' && !strchr(s,'>'))
4832 s = scan_heredoc(s);
4834 s = scan_inputsymbol(s);
4835 TERM(sublex_start());
4841 SHop(OP_LEFT_SHIFT);
4855 const char tmp = *s++;
4857 SHop(OP_RIGHT_SHIFT);
4858 else if (tmp == '=')
4867 if (PL_expect == XOPERATOR) {
4868 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4870 deprecate_old(commaless_variable_list);
4871 return REPORT(','); /* grandfather non-comma-format format */
4875 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4876 PL_tokenbuf[0] = '@';
4877 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4878 sizeof PL_tokenbuf - 1, FALSE);
4879 if (PL_expect == XOPERATOR)
4880 no_op("Array length", s);
4881 if (!PL_tokenbuf[1])
4883 PL_expect = XOPERATOR;
4884 PL_pending_ident = '#';
4888 PL_tokenbuf[0] = '$';
4889 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4890 sizeof PL_tokenbuf - 1, FALSE);
4891 if (PL_expect == XOPERATOR)
4893 if (!PL_tokenbuf[1]) {
4895 yyerror("Final $ should be \\$ or $name");
4899 /* This kludge not intended to be bulletproof. */
4900 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4901 pl_yylval.opval = newSVOP(OP_CONST, 0,
4902 newSViv(CopARYBASE_get(&PL_compiling)));
4903 pl_yylval.opval->op_private = OPpCONST_ARYBASE;
4909 const char tmp = *s;
4910 if (PL_lex_state == LEX_NORMAL)
4913 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4914 && intuit_more(s)) {
4916 PL_tokenbuf[0] = '@';
4917 if (ckWARN(WARN_SYNTAX)) {
4920 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4923 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4924 while (t < PL_bufend && *t != ']')
4926 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4927 "Multidimensional syntax %.*s not supported",
4928 (int)((t - PL_bufptr) + 1), PL_bufptr);
4932 else if (*s == '{') {
4934 PL_tokenbuf[0] = '%';
4935 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4936 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4938 char tmpbuf[sizeof PL_tokenbuf];
4941 } while (isSPACE(*t));
4942 if (isIDFIRST_lazy_if(t,UTF)) {
4944 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4948 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
4949 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4950 "You need to quote \"%s\"",
4957 PL_expect = XOPERATOR;
4958 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4959 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4960 if (!islop || PL_last_lop_op == OP_GREPSTART)
4961 PL_expect = XOPERATOR;
4962 else if (strchr("$@\"'`q", *s))
4963 PL_expect = XTERM; /* e.g. print $fh "foo" */
4964 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4965 PL_expect = XTERM; /* e.g. print $fh &sub */
4966 else if (isIDFIRST_lazy_if(s,UTF)) {
4967 char tmpbuf[sizeof PL_tokenbuf];
4969 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4970 if ((t2 = keyword(tmpbuf, len, 0))) {
4971 /* binary operators exclude handle interpretations */
4983 PL_expect = XTERM; /* e.g. print $fh length() */
4988 PL_expect = XTERM; /* e.g. print $fh subr() */
4991 else if (isDIGIT(*s))
4992 PL_expect = XTERM; /* e.g. print $fh 3 */
4993 else if (*s == '.' && isDIGIT(s[1]))
4994 PL_expect = XTERM; /* e.g. print $fh .3 */
4995 else if ((*s == '?' || *s == '-' || *s == '+')
4996 && !isSPACE(s[1]) && s[1] != '=')
4997 PL_expect = XTERM; /* e.g. print $fh -1 */
4998 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
5000 PL_expect = XTERM; /* e.g. print $fh /.../
5001 XXX except DORDOR operator
5003 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
5005 PL_expect = XTERM; /* print $fh <<"EOF" */
5008 PL_pending_ident = '$';
5012 if (PL_expect == XOPERATOR)
5014 PL_tokenbuf[0] = '@';
5015 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
5016 if (!PL_tokenbuf[1]) {
5019 if (PL_lex_state == LEX_NORMAL)
5021 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
5023 PL_tokenbuf[0] = '%';
5025 /* Warn about @ where they meant $. */
5026 if (*s == '[' || *s == '{') {
5027 if (ckWARN(WARN_SYNTAX)) {
5028 const char *t = s + 1;
5029 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
5031 if (*t == '}' || *t == ']') {
5033 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
5034 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5035 "Scalar value %.*s better written as $%.*s",
5036 (int)(t-PL_bufptr), PL_bufptr,
5037 (int)(t-PL_bufptr-1), PL_bufptr+1);
5042 PL_pending_ident = '@';
5045 case '/': /* may be division, defined-or, or pattern */
5046 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
5050 case '?': /* may either be conditional or pattern */
5051 if (PL_expect == XSTATE && s[1] == '?' && s[2] == '?') {
5055 if (PL_expect == XOPERATOR) {
5063 /* A // operator. */
5073 /* Disable warning on "study /blah/" */
5074 if (PL_oldoldbufptr == PL_last_uni
5075 && (*PL_last_uni != 's' || s - PL_last_uni < 5
5076 || memNE(PL_last_uni, "study", 5)
5077 || isALNUM_lazy_if(PL_last_uni+5,UTF)
5080 s = scan_pat(s,OP_MATCH);
5081 TERM(sublex_start());
5085 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
5086 #ifdef PERL_STRICT_CR
5089 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
5091 && (s == PL_linestart || s[-1] == '\n') )
5093 PL_lex_formbrack = 0;
5097 if (PL_expect == XSTATE && s[1] == '.' && s[2] == '.') {
5101 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
5107 pl_yylval.ival = OPf_SPECIAL;
5113 if (PL_expect != XOPERATOR)
5118 case '0': case '1': case '2': case '3': case '4':
5119 case '5': case '6': case '7': case '8': case '9':
5120 s = scan_num(s, &pl_yylval);
5121 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
5122 if (PL_expect == XOPERATOR)
5127 s = scan_str(s,!!PL_madskills,FALSE);
5128 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5129 if (PL_expect == XOPERATOR) {
5130 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5132 deprecate_old(commaless_variable_list);
5133 return REPORT(','); /* grandfather non-comma-format format */
5140 pl_yylval.ival = OP_CONST;
5141 TERM(sublex_start());
5144 s = scan_str(s,!!PL_madskills,FALSE);
5145 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5146 if (PL_expect == XOPERATOR) {
5147 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5149 deprecate_old(commaless_variable_list);
5150 return REPORT(','); /* grandfather non-comma-format format */
5157 pl_yylval.ival = OP_CONST;
5158 /* FIXME. I think that this can be const if char *d is replaced by
5159 more localised variables. */
5160 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
5161 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
5162 pl_yylval.ival = OP_STRINGIFY;
5166 TERM(sublex_start());
5169 s = scan_str(s,!!PL_madskills,FALSE);
5170 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
5171 if (PL_expect == XOPERATOR)
5172 no_op("Backticks",s);
5175 readpipe_override();
5176 TERM(sublex_start());
5180 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
5181 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5183 if (PL_expect == XOPERATOR)
5184 no_op("Backslash",s);
5188 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
5189 char *start = s + 2;
5190 while (isDIGIT(*start) || *start == '_')
5192 if (*start == '.' && isDIGIT(start[1])) {
5193 s = scan_num(s, &pl_yylval);
5196 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
5197 else if (!isALPHA(*start) && (PL_expect == XTERM
5198 || PL_expect == XREF || PL_expect == XSTATE
5199 || PL_expect == XTERMORDORDOR)) {
5200 GV *const gv = gv_fetchpvn_flags(s, start - s, 0, SVt_PVCV);
5202 s = scan_num(s, &pl_yylval);
5209 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5251 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5253 /* Some keywords can be followed by any delimiter, including ':' */
5254 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5255 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5256 (PL_tokenbuf[0] == 'q' &&
5257 strchr("qwxr", PL_tokenbuf[1])))));
5259 /* x::* is just a word, unless x is "CORE" */
5260 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5264 while (d < PL_bufend && isSPACE(*d))
5265 d++; /* no comments skipped here, or s### is misparsed */
5267 /* Is this a label? */
5268 if (!tmp && PL_expect == XSTATE
5269 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5271 pl_yylval.pval = CopLABEL_alloc(PL_tokenbuf);
5276 /* Check for keywords */
5277 tmp = keyword(PL_tokenbuf, len, 0);
5279 /* Is this a word before a => operator? */
5280 if (*d == '=' && d[1] == '>') {
5283 = (OP*)newSVOP(OP_CONST, 0,
5284 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5285 pl_yylval.opval->op_private = OPpCONST_BARE;
5289 if (tmp < 0) { /* second-class keyword? */
5290 GV *ogv = NULL; /* override (winner) */
5291 GV *hgv = NULL; /* hidden (loser) */
5292 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5294 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5297 if (GvIMPORTED_CV(gv))
5299 else if (! CvMETHOD(cv))
5303 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5304 (gv = *gvp) && isGV_with_GP(gv) &&
5305 GvCVu(gv) && GvIMPORTED_CV(gv))
5312 tmp = 0; /* overridden by import or by GLOBAL */
5315 && -tmp==KEY_lock /* XXX generalizable kludge */
5318 tmp = 0; /* any sub overrides "weak" keyword */
5320 else { /* no override */
5322 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5323 Perl_warner(aTHX_ packWARN(WARN_MISC),
5324 "dump() better written as CORE::dump()");
5328 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5329 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
5330 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5331 "Ambiguous call resolved as CORE::%s(), %s",
5332 GvENAME(hgv), "qualify as such or use &");
5339 default: /* not a keyword */
5340 /* Trade off - by using this evil construction we can pull the
5341 variable gv into the block labelled keylookup. If not, then
5342 we have to give it function scope so that the goto from the
5343 earlier ':' case doesn't bypass the initialisation. */
5345 just_a_word_zero_gv:
5353 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5356 SV *nextPL_nextwhite = 0;
5360 /* Get the rest if it looks like a package qualifier */
5362 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5364 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5367 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5368 *s == '\'' ? "'" : "::");
5373 if (PL_expect == XOPERATOR) {
5374 if (PL_bufptr == PL_linestart) {
5375 CopLINE_dec(PL_curcop);
5376 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
5377 CopLINE_inc(PL_curcop);
5380 no_op("Bareword",s);
5383 /* Look for a subroutine with this name in current package,
5384 unless name is "Foo::", in which case Foo is a bearword
5385 (and a package name). */
5387 if (len > 2 && !PL_madskills &&
5388 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5390 if (ckWARN(WARN_BAREWORD)
5391 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5392 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5393 "Bareword \"%s\" refers to nonexistent package",
5396 PL_tokenbuf[len] = '\0';
5402 /* Mustn't actually add anything to a symbol table.
5403 But also don't want to "initialise" any placeholder
5404 constants that might already be there into full
5405 blown PVGVs with attached PVCV. */
5406 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5407 GV_NOADD_NOINIT, SVt_PVCV);
5412 /* if we saw a global override before, get the right name */
5415 sv = newSVpvs("CORE::GLOBAL::");
5416 sv_catpv(sv,PL_tokenbuf);
5419 /* If len is 0, newSVpv does strlen(), which is correct.
5420 If len is non-zero, then it will be the true length,
5421 and so the scalar will be created correctly. */
5422 sv = newSVpv(PL_tokenbuf,len);
5425 if (PL_madskills && !PL_thistoken) {
5426 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5427 PL_thistoken = newSVpvn(start,s - start);
5428 PL_realtokenstart = s - SvPVX(PL_linestr);
5432 /* Presume this is going to be a bareword of some sort. */
5435 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5436 pl_yylval.opval->op_private = OPpCONST_BARE;
5437 /* UTF-8 package name? */
5438 if (UTF && !IN_BYTES &&
5439 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5442 /* And if "Foo::", then that's what it certainly is. */
5447 /* Do the explicit type check so that we don't need to force
5448 the initialisation of the symbol table to have a real GV.
5449 Beware - gv may not really be a PVGV, cv may not really be
5450 a PVCV, (because of the space optimisations that gv_init
5451 understands) But they're true if for this symbol there is
5452 respectively a typeglob and a subroutine.
5454 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5455 /* Real typeglob, so get the real subroutine: */
5457 /* A proxy for a subroutine in this package? */
5458 : SvOK(gv) ? MUTABLE_CV(gv) : NULL)
5461 /* See if it's the indirect object for a list operator. */
5463 if (PL_oldoldbufptr &&
5464 PL_oldoldbufptr < PL_bufptr &&
5465 (PL_oldoldbufptr == PL_last_lop
5466 || PL_oldoldbufptr == PL_last_uni) &&
5467 /* NO SKIPSPACE BEFORE HERE! */
5468 (PL_expect == XREF ||
5469 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5471 bool immediate_paren = *s == '(';
5473 /* (Now we can afford to cross potential line boundary.) */
5474 s = SKIPSPACE2(s,nextPL_nextwhite);
5476 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5479 /* Two barewords in a row may indicate method call. */
5481 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5482 (tmp = intuit_method(s, gv, cv)))
5485 /* If not a declared subroutine, it's an indirect object. */
5486 /* (But it's an indir obj regardless for sort.) */
5487 /* Also, if "_" follows a filetest operator, it's a bareword */
5490 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5492 (PL_last_lop_op != OP_MAPSTART &&
5493 PL_last_lop_op != OP_GREPSTART))))
5494 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5495 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5498 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5503 PL_expect = XOPERATOR;
5506 s = SKIPSPACE2(s,nextPL_nextwhite);
5507 PL_nextwhite = nextPL_nextwhite;
5512 /* Is this a word before a => operator? */
5513 if (*s == '=' && s[1] == '>' && !pkgname) {
5515 sv_setpv(((SVOP*)pl_yylval.opval)->op_sv, PL_tokenbuf);
5516 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5517 SvUTF8_on(((SVOP*)pl_yylval.opval)->op_sv);
5521 /* If followed by a paren, it's certainly a subroutine. */
5526 while (SPACE_OR_TAB(*d))
5528 if (*d == ')' && (sv = gv_const_sv(gv))) {
5535 PL_nextwhite = PL_thiswhite;
5538 start_force(PL_curforce);
5540 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5541 PL_expect = XOPERATOR;
5544 PL_nextwhite = nextPL_nextwhite;
5545 curmad('X', PL_thistoken);
5546 PL_thistoken = newSVpvs("");
5554 /* If followed by var or block, call it a method (unless sub) */
5556 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5557 PL_last_lop = PL_oldbufptr;
5558 PL_last_lop_op = OP_METHOD;
5562 /* If followed by a bareword, see if it looks like indir obj. */
5565 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5566 && (tmp = intuit_method(s, gv, cv)))
5569 /* Not a method, so call it a subroutine (if defined) */
5572 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5573 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5574 "Ambiguous use of -%s resolved as -&%s()",
5575 PL_tokenbuf, PL_tokenbuf);
5576 /* Check for a constant sub */
5577 if ((sv = gv_const_sv(gv))) {
5579 SvREFCNT_dec(((SVOP*)pl_yylval.opval)->op_sv);
5580 ((SVOP*)pl_yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5581 pl_yylval.opval->op_private = 0;
5585 /* Resolve to GV now. */
5586 if (SvTYPE(gv) != SVt_PVGV) {
5587 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5588 assert (SvTYPE(gv) == SVt_PVGV);
5589 /* cv must have been some sort of placeholder, so
5590 now needs replacing with a real code reference. */
5594 op_free(pl_yylval.opval);
5595 pl_yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5596 pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5597 PL_last_lop = PL_oldbufptr;
5598 PL_last_lop_op = OP_ENTERSUB;
5599 /* Is there a prototype? */
5607 const char *proto = SvPV_const(MUTABLE_SV(cv), protolen);
5610 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
5612 while (*proto == ';')
5614 if (*proto == '&' && *s == '{') {
5616 sv_setpvs(PL_subname, "__ANON__");
5618 sv_setpvs(PL_subname, "__ANON__::__ANON__");
5625 PL_nextwhite = PL_thiswhite;
5628 start_force(PL_curforce);
5629 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5632 PL_nextwhite = nextPL_nextwhite;
5633 curmad('X', PL_thistoken);
5634 PL_thistoken = newSVpvs("");
5641 /* Guess harder when madskills require "best effort". */
5642 if (PL_madskills && (!gv || !GvCVu(gv))) {
5643 int probable_sub = 0;
5644 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5646 else if (isALPHA(*s)) {
5650 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5651 if (!keyword(tmpbuf, tmplen, 0))
5654 while (d < PL_bufend && isSPACE(*d))
5656 if (*d == '=' && d[1] == '>')
5661 gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
5662 op_free(pl_yylval.opval);
5663 pl_yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5664 pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5665 PL_last_lop = PL_oldbufptr;
5666 PL_last_lop_op = OP_ENTERSUB;
5667 PL_nextwhite = PL_thiswhite;
5669 start_force(PL_curforce);
5670 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5672 PL_nextwhite = nextPL_nextwhite;
5673 curmad('X', PL_thistoken);
5674 PL_thistoken = newSVpvs("");
5679 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5686 /* Call it a bare word */
5689 if (PL_hints & HINT_STRICT_SUBS)
5690 pl_yylval.opval->op_private |= OPpCONST_STRICT;
5692 if (lastchar != '-') {
5693 if (ckWARN(WARN_RESERVED)) {
5697 if (!*d && !gv_stashpv(PL_tokenbuf, 0))
5698 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5705 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5706 && ckWARN_d(WARN_AMBIGUOUS)) {
5707 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5708 "Operator or semicolon missing before %c%s",
5709 lastchar, PL_tokenbuf);
5710 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5711 "Ambiguous use of %c resolved as operator %c",
5712 lastchar, lastchar);
5718 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5719 newSVpv(CopFILE(PL_curcop),0));
5723 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5724 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5727 case KEY___PACKAGE__:
5728 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5730 ? newSVhek(HvNAME_HEK(PL_curstash))
5737 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5738 const char *pname = "main";
5739 if (PL_tokenbuf[2] == 'D')
5740 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5741 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5745 GvIOp(gv) = newIO();
5746 IoIFP(GvIOp(gv)) = PL_rsfp;
5747 #if defined(HAS_FCNTL) && defined(F_SETFD)
5749 const int fd = PerlIO_fileno(PL_rsfp);
5750 fcntl(fd,F_SETFD,fd >= 3);
5753 /* Mark this internal pseudo-handle as clean */
5754 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5755 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5756 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5758 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5759 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5760 /* if the script was opened in binmode, we need to revert
5761 * it to text mode for compatibility; but only iff it has CRs
5762 * XXX this is a questionable hack at best. */
5763 if (PL_bufend-PL_bufptr > 2
5764 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5767 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5768 loc = PerlIO_tell(PL_rsfp);
5769 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5772 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5774 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5775 #endif /* NETWARE */
5776 #ifdef PERLIO_IS_STDIO /* really? */
5777 # if defined(__BORLANDC__)
5778 /* XXX see note in do_binmode() */
5779 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5783 PerlIO_seek(PL_rsfp, loc, 0);
5787 #ifdef PERLIO_LAYERS
5790 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5791 else if (PL_encoding) {
5798 XPUSHs(PL_encoding);
5800 call_method("name", G_SCALAR);
5804 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5805 Perl_form(aTHX_ ":encoding(%"SVf")",
5814 if (PL_realtokenstart >= 0) {
5815 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5817 PL_endwhite = newSVpvs("");
5818 sv_catsv(PL_endwhite, PL_thiswhite);
5820 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5821 PL_realtokenstart = -1;
5823 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5824 SvCUR(PL_endwhite))) != NULL) ;
5839 if (PL_expect == XSTATE) {
5846 if (*s == ':' && s[1] == ':') {
5849 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5850 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5851 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5854 else if (tmp == KEY_require || tmp == KEY_do)
5855 /* that's a way to remember we saw "CORE::" */
5868 LOP(OP_ACCEPT,XTERM);
5874 LOP(OP_ATAN2,XTERM);
5880 LOP(OP_BINMODE,XTERM);
5883 LOP(OP_BLESS,XTERM);
5892 /* When 'use switch' is in effect, continue has a dual
5893 life as a control operator. */
5895 if (!FEATURE_IS_ENABLED("switch"))
5898 /* We have to disambiguate the two senses of
5899 "continue". If the next token is a '{' then
5900 treat it as the start of a continue block;
5901 otherwise treat it as a control operator.
5913 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5930 if (!PL_cryptseen) {
5931 PL_cryptseen = TRUE;
5935 LOP(OP_CRYPT,XTERM);
5938 LOP(OP_CHMOD,XTERM);
5941 LOP(OP_CHOWN,XTERM);
5944 LOP(OP_CONNECT,XTERM);
5963 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5964 if (orig_keyword == KEY_do) {
5973 PL_hints |= HINT_BLOCK_SCOPE;
5983 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5984 LOP(OP_DBMOPEN,XTERM);
5990 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5997 pl_yylval.ival = CopLINE(PL_curcop);
6013 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
6014 UNIBRACK(OP_ENTEREVAL);
6028 case KEY_endhostent:
6034 case KEY_endservent:
6037 case KEY_endprotoent:
6048 pl_yylval.ival = CopLINE(PL_curcop);
6050 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
6053 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
6056 if ((PL_bufend - p) >= 3 &&
6057 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
6059 else if ((PL_bufend - p) >= 4 &&
6060 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
6063 if (isIDFIRST_lazy_if(p,UTF)) {
6064 p = scan_ident(p, PL_bufend,
6065 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
6069 Perl_croak(aTHX_ "Missing $ on loop variable");
6071 s = SvPVX(PL_linestr) + soff;
6077 LOP(OP_FORMLINE,XTERM);
6083 LOP(OP_FCNTL,XTERM);
6089 LOP(OP_FLOCK,XTERM);
6098 LOP(OP_GREPSTART, XREF);
6101 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6116 case KEY_getpriority:
6117 LOP(OP_GETPRIORITY,XTERM);
6119 case KEY_getprotobyname:
6122 case KEY_getprotobynumber:
6123 LOP(OP_GPBYNUMBER,XTERM);
6125 case KEY_getprotoent:
6137 case KEY_getpeername:
6138 UNI(OP_GETPEERNAME);
6140 case KEY_gethostbyname:
6143 case KEY_gethostbyaddr:
6144 LOP(OP_GHBYADDR,XTERM);
6146 case KEY_gethostent:
6149 case KEY_getnetbyname:
6152 case KEY_getnetbyaddr:
6153 LOP(OP_GNBYADDR,XTERM);
6158 case KEY_getservbyname:
6159 LOP(OP_GSBYNAME,XTERM);
6161 case KEY_getservbyport:
6162 LOP(OP_GSBYPORT,XTERM);
6164 case KEY_getservent:
6167 case KEY_getsockname:
6168 UNI(OP_GETSOCKNAME);
6170 case KEY_getsockopt:
6171 LOP(OP_GSOCKOPT,XTERM);
6186 pl_yylval.ival = CopLINE(PL_curcop);
6196 pl_yylval.ival = CopLINE(PL_curcop);
6200 LOP(OP_INDEX,XTERM);
6206 LOP(OP_IOCTL,XTERM);
6218 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6250 LOP(OP_LISTEN,XTERM);
6259 s = scan_pat(s,OP_MATCH);
6260 TERM(sublex_start());
6263 LOP(OP_MAPSTART, XREF);
6266 LOP(OP_MKDIR,XTERM);
6269 LOP(OP_MSGCTL,XTERM);
6272 LOP(OP_MSGGET,XTERM);
6275 LOP(OP_MSGRCV,XTERM);
6278 LOP(OP_MSGSND,XTERM);
6283 PL_in_my = (U16)tmp;
6285 if (isIDFIRST_lazy_if(s,UTF)) {
6289 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6290 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6292 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6293 if (!PL_in_my_stash) {
6296 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6300 if (PL_madskills) { /* just add type to declarator token */
6301 sv_catsv(PL_thistoken, PL_nextwhite);
6303 sv_catpvn(PL_thistoken, start, s - start);
6311 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6318 s = tokenize_use(0, s);
6322 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6329 if (isIDFIRST_lazy_if(s,UTF)) {
6331 for (d = s; isALNUM_lazy_if(d,UTF);)
6333 for (t=d; isSPACE(*t);)
6335 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6337 && !(t[0] == '=' && t[1] == '>')
6339 int parms_len = (int)(d-s);
6340 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6341 "Precedence problem: open %.*s should be open(%.*s)",
6342 parms_len, s, parms_len, s);
6348 pl_yylval.ival = OP_OR;
6358 LOP(OP_OPEN_DIR,XTERM);
6361 checkcomma(s,PL_tokenbuf,"filehandle");
6365 checkcomma(s,PL_tokenbuf,"filehandle");
6384 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6388 LOP(OP_PIPE_OP,XTERM);
6391 s = scan_str(s,!!PL_madskills,FALSE);
6394 pl_yylval.ival = OP_CONST;
6395 TERM(sublex_start());
6401 s = scan_str(s,!!PL_madskills,FALSE);
6404 PL_expect = XOPERATOR;
6406 if (SvCUR(PL_lex_stuff)) {
6409 d = SvPV_force(PL_lex_stuff, len);
6411 for (; isSPACE(*d) && len; --len, ++d)
6416 if (!warned && ckWARN(WARN_QW)) {
6417 for (; !isSPACE(*d) && len; --len, ++d) {
6419 Perl_warner(aTHX_ packWARN(WARN_QW),
6420 "Possible attempt to separate words with commas");
6423 else if (*d == '#') {
6424 Perl_warner(aTHX_ packWARN(WARN_QW),
6425 "Possible attempt to put comments in qw() list");
6431 for (; !isSPACE(*d) && len; --len, ++d)
6434 sv = newSVpvn_utf8(b, d-b, DO_UTF8(PL_lex_stuff));
6435 words = append_elem(OP_LIST, words,
6436 newSVOP(OP_CONST, 0, tokeq(sv)));
6440 start_force(PL_curforce);
6441 NEXTVAL_NEXTTOKE.opval = words;
6446 SvREFCNT_dec(PL_lex_stuff);
6447 PL_lex_stuff = NULL;
6453 s = scan_str(s,!!PL_madskills,FALSE);
6456 pl_yylval.ival = OP_STRINGIFY;
6457 if (SvIVX(PL_lex_stuff) == '\'')
6458 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6459 TERM(sublex_start());
6462 s = scan_pat(s,OP_QR);
6463 TERM(sublex_start());
6466 s = scan_str(s,!!PL_madskills,FALSE);
6469 readpipe_override();
6470 TERM(sublex_start());
6478 s = force_version(s, FALSE);
6480 else if (*s != 'v' || !isDIGIT(s[1])
6481 || (s = force_version(s, TRUE), *s == 'v'))
6483 *PL_tokenbuf = '\0';
6484 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6485 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6486 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
6488 yyerror("<> should be quotes");
6490 if (orig_keyword == KEY_require) {
6498 PL_last_uni = PL_oldbufptr;
6499 PL_last_lop_op = OP_REQUIRE;
6501 return REPORT( (int)REQUIRE );
6507 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6511 LOP(OP_RENAME,XTERM);
6520 LOP(OP_RINDEX,XTERM);
6529 UNIDOR(OP_READLINE);
6532 UNIDOR(OP_BACKTICK);
6541 LOP(OP_REVERSE,XTERM);
6544 UNIDOR(OP_READLINK);
6551 if (pl_yylval.opval)
6552 TERM(sublex_start());
6554 TOKEN(1); /* force error */
6557 checkcomma(s,PL_tokenbuf,"filehandle");
6567 LOP(OP_SELECT,XTERM);
6573 LOP(OP_SEMCTL,XTERM);
6576 LOP(OP_SEMGET,XTERM);
6579 LOP(OP_SEMOP,XTERM);
6585 LOP(OP_SETPGRP,XTERM);
6587 case KEY_setpriority:
6588 LOP(OP_SETPRIORITY,XTERM);
6590 case KEY_sethostent:
6596 case KEY_setservent:
6599 case KEY_setprotoent:
6609 LOP(OP_SEEKDIR,XTERM);
6611 case KEY_setsockopt:
6612 LOP(OP_SSOCKOPT,XTERM);
6618 LOP(OP_SHMCTL,XTERM);
6621 LOP(OP_SHMGET,XTERM);
6624 LOP(OP_SHMREAD,XTERM);
6627 LOP(OP_SHMWRITE,XTERM);
6630 LOP(OP_SHUTDOWN,XTERM);
6639 LOP(OP_SOCKET,XTERM);
6641 case KEY_socketpair:
6642 LOP(OP_SOCKPAIR,XTERM);
6645 checkcomma(s,PL_tokenbuf,"subroutine name");
6647 if (*s == ';' || *s == ')') /* probably a close */
6648 Perl_croak(aTHX_ "sort is now a reserved word");
6650 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6654 LOP(OP_SPLIT,XTERM);
6657 LOP(OP_SPRINTF,XTERM);
6660 LOP(OP_SPLICE,XTERM);
6675 LOP(OP_SUBSTR,XTERM);
6681 char tmpbuf[sizeof PL_tokenbuf];
6682 SSize_t tboffset = 0;
6683 expectation attrful;
6684 bool have_name, have_proto;
6685 const int key = tmp;
6690 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6691 SV *subtoken = newSVpvn(tstart, s - tstart);
6695 s = SKIPSPACE2(s,tmpwhite);
6700 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6701 (*s == ':' && s[1] == ':'))
6704 SV *nametoke = NULL;
6708 attrful = XATTRBLOCK;
6709 /* remember buffer pos'n for later force_word */
6710 tboffset = s - PL_oldbufptr;
6711 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6714 nametoke = newSVpvn(s, d - s);
6716 if (memchr(tmpbuf, ':', len))
6717 sv_setpvn(PL_subname, tmpbuf, len);
6719 sv_setsv(PL_subname,PL_curstname);
6720 sv_catpvs(PL_subname,"::");
6721 sv_catpvn(PL_subname,tmpbuf,len);
6728 CURMAD('X', nametoke);
6729 CURMAD('_', tmpwhite);
6730 (void) force_word(PL_oldbufptr + tboffset, WORD,
6733 s = SKIPSPACE2(d,tmpwhite);
6740 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6741 PL_expect = XTERMBLOCK;
6742 attrful = XATTRTERM;
6743 sv_setpvs(PL_subname,"?");
6747 if (key == KEY_format) {
6749 PL_lex_formbrack = PL_lex_brackets + 1;
6751 PL_thistoken = subtoken;
6755 (void) force_word(PL_oldbufptr + tboffset, WORD,
6761 /* Look for a prototype */
6764 bool bad_proto = FALSE;
6765 bool in_brackets = FALSE;
6766 char greedy_proto = ' ';
6767 bool proto_after_greedy_proto = FALSE;
6768 bool must_be_last = FALSE;
6769 bool underscore = FALSE;
6770 bool seen_underscore = FALSE;
6771 const bool warnsyntax = ckWARN(WARN_SYNTAX);
6773 s = scan_str(s,!!PL_madskills,FALSE);
6775 Perl_croak(aTHX_ "Prototype not terminated");
6776 /* strip spaces and check for bad characters */
6777 d = SvPVX(PL_lex_stuff);
6779 for (p = d; *p; ++p) {
6785 proto_after_greedy_proto = TRUE;
6786 if (!strchr("$@%*;[]&\\_", *p)) {
6798 else if ( *p == ']' ) {
6799 in_brackets = FALSE;
6801 else if ( (*p == '@' || *p == '%') &&
6802 ( tmp < 2 || d[tmp-2] != '\\' ) &&
6804 must_be_last = TRUE;
6807 else if ( *p == '_' ) {
6808 underscore = seen_underscore = TRUE;
6815 if (proto_after_greedy_proto)
6816 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6817 "Prototype after '%c' for %"SVf" : %s",
6818 greedy_proto, SVfARG(PL_subname), d);
6820 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6821 "Illegal character %sin prototype for %"SVf" : %s",
6822 seen_underscore ? "after '_' " : "",
6823 SVfARG(PL_subname), d);
6824 SvCUR_set(PL_lex_stuff, tmp);
6829 CURMAD('q', PL_thisopen);
6830 CURMAD('_', tmpwhite);
6831 CURMAD('=', PL_thisstuff);
6832 CURMAD('Q', PL_thisclose);
6833 NEXTVAL_NEXTTOKE.opval =
6834 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6835 PL_lex_stuff = NULL;
6838 s = SKIPSPACE2(s,tmpwhite);
6846 if (*s == ':' && s[1] != ':')
6847 PL_expect = attrful;
6848 else if (*s != '{' && key == KEY_sub) {
6850 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6852 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
6859 curmad('^', newSVpvs(""));
6860 CURMAD('_', tmpwhite);
6864 PL_thistoken = subtoken;
6867 NEXTVAL_NEXTTOKE.opval =
6868 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6869 PL_lex_stuff = NULL;
6875 sv_setpvs(PL_subname, "__ANON__");
6877 sv_setpvs(PL_subname, "__ANON__::__ANON__");
6881 (void) force_word(PL_oldbufptr + tboffset, WORD,
6890 LOP(OP_SYSTEM,XREF);
6893 LOP(OP_SYMLINK,XTERM);
6896 LOP(OP_SYSCALL,XTERM);
6899 LOP(OP_SYSOPEN,XTERM);
6902 LOP(OP_SYSSEEK,XTERM);
6905 LOP(OP_SYSREAD,XTERM);
6908 LOP(OP_SYSWRITE,XTERM);
6912 TERM(sublex_start());
6933 LOP(OP_TRUNCATE,XTERM);
6945 pl_yylval.ival = CopLINE(PL_curcop);
6949 pl_yylval.ival = CopLINE(PL_curcop);
6953 LOP(OP_UNLINK,XTERM);
6959 LOP(OP_UNPACK,XTERM);
6962 LOP(OP_UTIME,XTERM);
6968 LOP(OP_UNSHIFT,XTERM);
6971 s = tokenize_use(1, s);
6981 pl_yylval.ival = CopLINE(PL_curcop);
6985 pl_yylval.ival = CopLINE(PL_curcop);
6989 PL_hints |= HINT_BLOCK_SCOPE;
6996 LOP(OP_WAITPID,XTERM);
7005 ctl_l[0] = toCTRL('L');
7007 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
7010 /* Make sure $^L is defined */
7011 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
7016 if (PL_expect == XOPERATOR)
7022 pl_yylval.ival = OP_XOR;
7027 TERM(sublex_start());
7032 #pragma segment Main
7036 S_pending_ident(pTHX)
7041 /* pit holds the identifier we read and pending_ident is reset */
7042 char pit = PL_pending_ident;
7043 const STRLEN tokenbuf_len = strlen(PL_tokenbuf);
7044 /* All routes through this function want to know if there is a colon. */
7045 const char *const has_colon = (const char*) memchr (PL_tokenbuf, ':', tokenbuf_len);
7046 PL_pending_ident = 0;
7048 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
7049 DEBUG_T({ PerlIO_printf(Perl_debug_log,
7050 "### Pending identifier '%s'\n", PL_tokenbuf); });
7052 /* if we're in a my(), we can't allow dynamics here.
7053 $foo'bar has already been turned into $foo::bar, so
7054 just check for colons.
7056 if it's a legal name, the OP is a PADANY.
7059 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
7061 yyerror(Perl_form(aTHX_ "No package name allowed for "
7062 "variable %s in \"our\"",
7064 tmp = allocmy(PL_tokenbuf);
7068 yyerror(Perl_form(aTHX_ PL_no_myglob,
7069 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
7071 pl_yylval.opval = newOP(OP_PADANY, 0);
7072 pl_yylval.opval->op_targ = allocmy(PL_tokenbuf);
7078 build the ops for accesses to a my() variable.
7080 Deny my($a) or my($b) in a sort block, *if* $a or $b is
7081 then used in a comparison. This catches most, but not
7082 all cases. For instance, it catches
7083 sort { my($a); $a <=> $b }
7085 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
7086 (although why you'd do that is anyone's guess).
7091 tmp = pad_findmy(PL_tokenbuf);
7092 if (tmp != NOT_IN_PAD) {
7093 /* might be an "our" variable" */
7094 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
7095 /* build ops for a bareword */
7096 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
7097 HEK * const stashname = HvNAME_HEK(stash);
7098 SV * const sym = newSVhek(stashname);
7099 sv_catpvs(sym, "::");
7100 sv_catpvn(sym, PL_tokenbuf+1, tokenbuf_len - 1);
7101 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
7102 pl_yylval.opval->op_private = OPpCONST_ENTERED;
7105 ? (GV_ADDMULTI | GV_ADDINEVAL)
7108 ((PL_tokenbuf[0] == '$') ? SVt_PV
7109 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7114 /* if it's a sort block and they're naming $a or $b */
7115 if (PL_last_lop_op == OP_SORT &&
7116 PL_tokenbuf[0] == '$' &&
7117 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
7120 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
7121 d < PL_bufend && *d != '\n';
7124 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
7125 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
7131 pl_yylval.opval = newOP(OP_PADANY, 0);
7132 pl_yylval.opval->op_targ = tmp;
7138 Whine if they've said @foo in a doublequoted string,
7139 and @foo isn't a variable we can find in the symbol
7142 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
7143 GV *const gv = gv_fetchpvn_flags(PL_tokenbuf + 1, tokenbuf_len - 1, 0,
7145 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
7146 && ckWARN(WARN_AMBIGUOUS)
7147 /* DO NOT warn for @- and @+ */
7148 && !( PL_tokenbuf[2] == '\0' &&
7149 ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
7152 /* Downgraded from fatal to warning 20000522 mjd */
7153 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
7154 "Possible unintended interpolation of %s in string",
7159 /* build ops for a bareword */
7160 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpvn(PL_tokenbuf + 1,
7162 pl_yylval.opval->op_private = OPpCONST_ENTERED;
7164 PL_tokenbuf + 1, tokenbuf_len - 1,
7165 /* If the identifier refers to a stash, don't autovivify it.
7166 * Change 24660 had the side effect of causing symbol table
7167 * hashes to always be defined, even if they were freshly
7168 * created and the only reference in the entire program was
7169 * the single statement with the defined %foo::bar:: test.
7170 * It appears that all code in the wild doing this actually
7171 * wants to know whether sub-packages have been loaded, so
7172 * by avoiding auto-vivifying symbol tables, we ensure that
7173 * defined %foo::bar:: continues to be false, and the existing
7174 * tests still give the expected answers, even though what
7175 * they're actually testing has now changed subtly.
7177 (*PL_tokenbuf == '%'
7178 && *(d = PL_tokenbuf + tokenbuf_len - 1) == ':'
7181 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
7182 ((PL_tokenbuf[0] == '$') ? SVt_PV
7183 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7189 * The following code was generated by perl_keyword.pl.
7193 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
7197 PERL_ARGS_ASSERT_KEYWORD;
7201 case 1: /* 5 tokens of length 1 */
7233 case 2: /* 18 tokens of length 2 */
7379 case 3: /* 29 tokens of length 3 */
7383 if (name[1] == 'N' &&
7446 if (name[1] == 'i' &&
7478 if (name[1] == 'o' &&
7487 if (name[1] == 'e' &&
7496 if (name[1] == 'n' &&
7505 if (name[1] == 'o' &&
7514 if (name[1] == 'a' &&
7523 if (name[1] == 'o' &&
7585 if (name[1] == 'e' &&
7599 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
7625 if (name[1] == 'i' &&
7634 if (name[1] == 's' &&
7643 if (name[1] == 'e' &&
7652 if (name[1] == 'o' &&
7664 case 4: /* 41 tokens of length 4 */
7668 if (name[1] == 'O' &&
7678 if (name[1] == 'N' &&
7688 if (name[1] == 'i' &&
7698 if (name[1] == 'h' &&
7708 if (name[1] == 'u' &&
7721 if (name[2] == 'c' &&
7730 if (name[2] == 's' &&
7739 if (name[2] == 'a' &&
7775 if (name[1] == 'o' &&
7788 if (name[2] == 't' &&
7797 if (name[2] == 'o' &&
7806 if (name[2] == 't' &&
7815 if (name[2] == 'e' &&
7828 if (name[1] == 'o' &&
7841 if (name[2] == 'y' &&
7850 if (name[2] == 'l' &&
7866 if (name[2] == 's' &&
7875 if (name[2] == 'n' &&
7884 if (name[2] == 'c' &&
7897 if (name[1] == 'e' &&
7907 if (name[1] == 'p' &&
7920 if (name[2] == 'c' &&
7929 if (name[2] == 'p' &&
7938 if (name[2] == 's' &&
7954 if (name[2] == 'n' &&
8024 if (name[2] == 'r' &&
8033 if (name[2] == 'r' &&
8042 if (name[2] == 'a' &&
8058 if (name[2] == 'l' &&
8120 if (name[2] == 'e' &&
8123 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
8136 case 5: /* 39 tokens of length 5 */
8140 if (name[1] == 'E' &&
8151 if (name[1] == 'H' &&
8165 if (name[2] == 'a' &&
8175 if (name[2] == 'a' &&
8192 if (name[2] == 'e' &&
8202 if (name[2] == 'e' &&
8206 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
8222 if (name[3] == 'i' &&
8231 if (name[3] == 'o' &&
8267 if (name[2] == 'o' &&
8277 if (name[2] == 'y' &&
8291 if (name[1] == 'l' &&
8305 if (name[2] == 'n' &&
8315 if (name[2] == 'o' &&
8329 if (name[1] == 'i' &&
8334 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8343 if (name[2] == 'd' &&
8353 if (name[2] == 'c' &&
8370 if (name[2] == 'c' &&
8380 if (name[2] == 't' &&
8394 if (name[1] == 'k' &&
8405 if (name[1] == 'r' &&
8419 if (name[2] == 's' &&
8429 if (name[2] == 'd' &&
8446 if (name[2] == 'm' &&
8456 if (name[2] == 'i' &&
8466 if (name[2] == 'e' &&
8476 if (name[2] == 'l' &&
8486 if (name[2] == 'a' &&
8499 if (name[3] == 't' &&
8502 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8508 if (name[3] == 'd' &&
8525 if (name[1] == 'i' &&
8539 if (name[2] == 'a' &&
8552 if (name[3] == 'e' &&
8587 if (name[2] == 'i' &&
8604 if (name[2] == 'i' &&
8614 if (name[2] == 'i' &&
8631 case 6: /* 33 tokens of length 6 */
8635 if (name[1] == 'c' &&
8650 if (name[2] == 'l' &&
8661 if (name[2] == 'r' &&
8676 if (name[1] == 'e' &&
8691 if (name[2] == 's' &&
8696 if(ckWARN_d(WARN_SYNTAX))
8697 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8703 if (name[2] == 'i' &&
8721 if (name[2] == 'l' &&
8732 if (name[2] == 'r' &&
8747 if (name[1] == 'm' &&
8762 if (name[2] == 'n' &&
8773 if (name[2] == 's' &&
8788 if (name[1] == 's' &&
8794 if (name[4] == 't' &&
8803 if (name[4] == 'e' &&
8812 if (name[4] == 'c' &&
8821 if (name[4] == 'n' &&
8837 if (name[1] == 'r' &&
8855 if (name[3] == 'a' &&
8865 if (name[3] == 'u' &&
8879 if (name[2] == 'n' &&
8897 if (name[2] == 'a' &&
8911 if (name[3] == 'e' &&
8924 if (name[4] == 't' &&
8933 if (name[4] == 'e' &&
8955 if (name[4] == 't' &&
8964 if (name[4] == 'e' &&
8980 if (name[2] == 'c' &&
8991 if (name[2] == 'l' &&
9002 if (name[2] == 'b' &&
9013 if (name[2] == 's' &&
9036 if (name[4] == 's' &&
9045 if (name[4] == 'n' &&
9058 if (name[3] == 'a' &&
9075 if (name[1] == 'a' &&
9090 case 7: /* 29 tokens of length 7 */
9094 if (name[1] == 'E' &&
9107 if (name[1] == '_' &&
9120 if (name[1] == 'i' &&
9127 return -KEY_binmode;
9133 if (name[1] == 'o' &&
9140 return -KEY_connect;
9149 if (name[2] == 'm' &&
9155 return -KEY_dbmopen;
9166 if (name[4] == 'u' &&
9170 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
9176 if (name[4] == 'n' &&
9197 if (name[1] == 'o' &&
9210 if (name[1] == 'e' &&
9217 if (name[5] == 'r' &&
9220 return -KEY_getpgrp;
9226 if (name[5] == 'i' &&
9229 return -KEY_getppid;
9242 if (name[1] == 'c' &&
9249 return -KEY_lcfirst;
9255 if (name[1] == 'p' &&
9262 return -KEY_opendir;
9268 if (name[1] == 'a' &&
9286 if (name[3] == 'd' &&
9291 return -KEY_readdir;
9297 if (name[3] == 'u' &&
9308 if (name[3] == 'e' &&
9313 return -KEY_reverse;
9332 if (name[3] == 'k' &&
9337 return -KEY_seekdir;
9343 if (name[3] == 'p' &&
9348 return -KEY_setpgrp;
9358 if (name[2] == 'm' &&
9364 return -KEY_shmread;
9370 if (name[2] == 'r' &&
9376 return -KEY_sprintf;
9385 if (name[3] == 'l' &&
9390 return -KEY_symlink;
9399 if (name[4] == 'a' &&
9403 return -KEY_syscall;
9409 if (name[4] == 'p' &&
9413 return -KEY_sysopen;
9419 if (name[4] == 'e' &&
9423 return -KEY_sysread;
9429 if (name[4] == 'e' &&
9433 return -KEY_sysseek;
9451 if (name[1] == 'e' &&
9458 return -KEY_telldir;
9467 if (name[2] == 'f' &&
9473 return -KEY_ucfirst;
9479 if (name[2] == 's' &&
9485 return -KEY_unshift;
9495 if (name[1] == 'a' &&
9502 return -KEY_waitpid;
9511 case 8: /* 26 tokens of length 8 */
9515 if (name[1] == 'U' &&
9523 return KEY_AUTOLOAD;
9534 if (name[3] == 'A' &&
9540 return KEY___DATA__;
9546 if (name[3] == 'I' &&
9552 return -KEY___FILE__;
9558 if (name[3] == 'I' &&
9564 return -KEY___LINE__;
9580 if (name[2] == 'o' &&
9587 return -KEY_closedir;
9593 if (name[2] == 'n' &&
9600 return -KEY_continue;
9610 if (name[1] == 'b' &&
9618 return -KEY_dbmclose;
9624 if (name[1] == 'n' &&
9630 if (name[4] == 'r' &&
9635 return -KEY_endgrent;
9641 if (name[4] == 'w' &&
9646 return -KEY_endpwent;
9659 if (name[1] == 'o' &&
9667 return -KEY_formline;
9673 if (name[1] == 'e' &&
9684 if (name[6] == 'n' &&
9687 return -KEY_getgrent;
9693 if (name[6] == 'i' &&
9696 return -KEY_getgrgid;
9702 if (name[6] == 'a' &&
9705 return -KEY_getgrnam;
9718 if (name[4] == 'o' &&
9723 return -KEY_getlogin;
9734 if (name[6] == 'n' &&
9737 return -KEY_getpwent;
9743 if (name[6] == 'a' &&
9746 return -KEY_getpwnam;
9752 if (name[6] == 'i' &&
9755 return -KEY_getpwuid;
9775 if (name[1] == 'e' &&
9782 if (name[5] == 'i' &&
9789 return -KEY_readline;
9794 return -KEY_readlink;
9805 if (name[5] == 'i' &&
9809 return -KEY_readpipe;
9830 if (name[4] == 'r' &&
9835 return -KEY_setgrent;
9841 if (name[4] == 'w' &&
9846 return -KEY_setpwent;
9862 if (name[3] == 'w' &&
9868 return -KEY_shmwrite;
9874 if (name[3] == 't' &&
9880 return -KEY_shutdown;
9890 if (name[2] == 's' &&
9897 return -KEY_syswrite;
9907 if (name[1] == 'r' &&
9915 return -KEY_truncate;
9924 case 9: /* 9 tokens of length 9 */
9928 if (name[1] == 'N' &&
9937 return KEY_UNITCHECK;
9943 if (name[1] == 'n' &&
9952 return -KEY_endnetent;
9958 if (name[1] == 'e' &&
9967 return -KEY_getnetent;
9973 if (name[1] == 'o' &&
9982 return -KEY_localtime;
9988 if (name[1] == 'r' &&
9997 return KEY_prototype;
10003 if (name[1] == 'u' &&
10012 return -KEY_quotemeta;
10018 if (name[1] == 'e' &&
10027 return -KEY_rewinddir;
10033 if (name[1] == 'e' &&
10042 return -KEY_setnetent;
10048 if (name[1] == 'a' &&
10057 return -KEY_wantarray;
10066 case 10: /* 9 tokens of length 10 */
10070 if (name[1] == 'n' &&
10076 if (name[4] == 'o' &&
10083 return -KEY_endhostent;
10089 if (name[4] == 'e' &&
10096 return -KEY_endservent;
10109 if (name[1] == 'e' &&
10115 if (name[4] == 'o' &&
10122 return -KEY_gethostent;
10131 if (name[5] == 'r' &&
10137 return -KEY_getservent;
10143 if (name[5] == 'c' &&
10149 return -KEY_getsockopt;
10169 if (name[2] == 't')
10174 if (name[4] == 'o' &&
10181 return -KEY_sethostent;
10190 if (name[5] == 'r' &&
10196 return -KEY_setservent;
10202 if (name[5] == 'c' &&
10208 return -KEY_setsockopt;
10225 if (name[2] == 'c' &&
10234 return -KEY_socketpair;
10247 case 11: /* 8 tokens of length 11 */
10251 if (name[1] == '_' &&
10261 { /* __PACKAGE__ */
10262 return -KEY___PACKAGE__;
10268 if (name[1] == 'n' &&
10278 { /* endprotoent */
10279 return -KEY_endprotoent;
10285 if (name[1] == 'e' &&
10294 if (name[5] == 'e' &&
10300 { /* getpeername */
10301 return -KEY_getpeername;
10310 if (name[6] == 'o' &&
10315 { /* getpriority */
10316 return -KEY_getpriority;
10322 if (name[6] == 't' &&
10327 { /* getprotoent */
10328 return -KEY_getprotoent;
10342 if (name[4] == 'o' &&
10349 { /* getsockname */
10350 return -KEY_getsockname;
10363 if (name[1] == 'e' &&
10371 if (name[6] == 'o' &&
10376 { /* setpriority */
10377 return -KEY_setpriority;
10383 if (name[6] == 't' &&
10388 { /* setprotoent */
10389 return -KEY_setprotoent;
10405 case 12: /* 2 tokens of length 12 */
10406 if (name[0] == 'g' &&
10418 if (name[9] == 'd' &&
10421 { /* getnetbyaddr */
10422 return -KEY_getnetbyaddr;
10428 if (name[9] == 'a' &&
10431 { /* getnetbyname */
10432 return -KEY_getnetbyname;
10444 case 13: /* 4 tokens of length 13 */
10445 if (name[0] == 'g' &&
10452 if (name[4] == 'o' &&
10461 if (name[10] == 'd' &&
10464 { /* gethostbyaddr */
10465 return -KEY_gethostbyaddr;
10471 if (name[10] == 'a' &&
10474 { /* gethostbyname */
10475 return -KEY_gethostbyname;
10488 if (name[4] == 'e' &&
10497 if (name[10] == 'a' &&
10500 { /* getservbyname */
10501 return -KEY_getservbyname;
10507 if (name[10] == 'o' &&
10510 { /* getservbyport */
10511 return -KEY_getservbyport;
10530 case 14: /* 1 tokens of length 14 */
10531 if (name[0] == 'g' &&
10545 { /* getprotobyname */
10546 return -KEY_getprotobyname;
10551 case 16: /* 1 tokens of length 16 */
10552 if (name[0] == 'g' &&
10568 { /* getprotobynumber */
10569 return -KEY_getprotobynumber;
10583 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10587 PERL_ARGS_ASSERT_CHECKCOMMA;
10589 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10590 if (ckWARN(WARN_SYNTAX)) {
10593 for (w = s+2; *w && level; w++) {
10596 else if (*w == ')')
10599 while (isSPACE(*w))
10601 /* the list of chars below is for end of statements or
10602 * block / parens, boolean operators (&&, ||, //) and branch
10603 * constructs (or, and, if, until, unless, while, err, for).
10604 * Not a very solid hack... */
10605 if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
10606 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10607 "%s (...) interpreted as function",name);
10610 while (s < PL_bufend && isSPACE(*s))
10614 while (s < PL_bufend && isSPACE(*s))
10616 if (isIDFIRST_lazy_if(s,UTF)) {
10617 const char * const w = s++;
10618 while (isALNUM_lazy_if(s,UTF))
10620 while (s < PL_bufend && isSPACE(*s))
10624 if (keyword(w, s - w, 0))
10627 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10628 if (gv && GvCVu(gv))
10630 Perl_croak(aTHX_ "No comma allowed after %s", what);
10635 /* Either returns sv, or mortalizes sv and returns a new SV*.
10636 Best used as sv=new_constant(..., sv, ...).
10637 If s, pv are NULL, calls subroutine with one argument,
10638 and type is used with error messages only. */
10641 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen,
10642 SV *sv, SV *pv, const char *type, STRLEN typelen)
10645 HV * const table = GvHV(PL_hintgv); /* ^H */
10649 const char *why1 = "", *why2 = "", *why3 = "";
10651 PERL_ARGS_ASSERT_NEW_CONSTANT;
10653 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10656 why2 = (const char *)
10657 (strEQ(key,"charnames")
10658 ? "(possibly a missing \"use charnames ...\")"
10660 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10661 (type ? type: "undef"), why2);
10663 /* This is convoluted and evil ("goto considered harmful")
10664 * but I do not understand the intricacies of all the different
10665 * failure modes of %^H in here. The goal here is to make
10666 * the most probable error message user-friendly. --jhi */
10671 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10672 (type ? type: "undef"), why1, why2, why3);
10674 yyerror(SvPVX_const(msg));
10678 cvp = hv_fetch(table, key, keylen, FALSE);
10679 if (!cvp || !SvOK(*cvp)) {
10682 why3 = "} is not defined";
10685 sv_2mortal(sv); /* Parent created it permanently */
10688 pv = newSVpvn_flags(s, len, SVs_TEMP);
10690 typesv = newSVpvn_flags(type, typelen, SVs_TEMP);
10692 typesv = &PL_sv_undef;
10694 PUSHSTACKi(PERLSI_OVERLOAD);
10706 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10710 /* Check the eval first */
10711 if (!PL_in_eval && SvTRUE(ERRSV)) {
10712 sv_catpvs(ERRSV, "Propagated");
10713 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10715 res = SvREFCNT_inc_simple(sv);
10719 SvREFCNT_inc_simple_void(res);
10728 why1 = "Call to &{$^H{";
10730 why3 = "}} did not return a defined value";
10738 /* Returns a NUL terminated string, with the length of the string written to
10742 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10745 register char *d = dest;
10746 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10748 PERL_ARGS_ASSERT_SCAN_WORD;
10752 Perl_croak(aTHX_ ident_too_long);
10753 if (isALNUM(*s)) /* UTF handled below */
10755 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10760 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10764 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10765 char *t = s + UTF8SKIP(s);
10767 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10771 Perl_croak(aTHX_ ident_too_long);
10772 Copy(s, d, len, char);
10785 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10788 char *bracket = NULL;
10790 register char *d = dest;
10791 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10793 PERL_ARGS_ASSERT_SCAN_IDENT;
10798 while (isDIGIT(*s)) {
10800 Perl_croak(aTHX_ ident_too_long);
10807 Perl_croak(aTHX_ ident_too_long);
10808 if (isALNUM(*s)) /* UTF handled below */
10810 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10815 else if (*s == ':' && s[1] == ':') {
10819 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10820 char *t = s + UTF8SKIP(s);
10821 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10823 if (d + (t - s) > e)
10824 Perl_croak(aTHX_ ident_too_long);
10825 Copy(s, d, t - s, char);
10836 if (PL_lex_state != LEX_NORMAL)
10837 PL_lex_state = LEX_INTERPENDMAYBE;
10840 if (*s == '$' && s[1] &&
10841 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10854 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10859 if (isSPACE(s[-1])) {
10861 const char ch = *s++;
10862 if (!SPACE_OR_TAB(ch)) {
10868 if (isIDFIRST_lazy_if(d,UTF)) {
10872 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10873 end += UTF8SKIP(end);
10874 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10875 end += UTF8SKIP(end);
10877 Copy(s, d, end - s, char);
10882 while ((isALNUM(*s) || *s == ':') && d < e)
10885 Perl_croak(aTHX_ ident_too_long);
10888 while (s < send && SPACE_OR_TAB(*s))
10890 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10891 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10892 const char * const brack =
10894 ((*s == '[') ? "[...]" : "{...}");
10895 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10896 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10897 funny, dest, brack, funny, dest, brack);
10900 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10904 /* Handle extended ${^Foo} variables
10905 * 1999-02-27 mjd-perl-patch@plover.com */
10906 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10910 while (isALNUM(*s) && d < e) {
10914 Perl_croak(aTHX_ ident_too_long);
10919 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10920 PL_lex_state = LEX_INTERPEND;
10923 if (PL_lex_state == LEX_NORMAL) {
10924 if (ckWARN(WARN_AMBIGUOUS) &&
10925 (keyword(dest, d - dest, 0)
10926 || get_cvn_flags(dest, d - dest, 0)))
10930 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10931 "Ambiguous use of %c{%s} resolved to %c%s",
10932 funny, dest, funny, dest);
10937 s = bracket; /* let the parser handle it */
10941 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10942 PL_lex_state = LEX_INTERPEND;
10947 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10949 PERL_ARGS_ASSERT_PMFLAG;
10951 PERL_UNUSED_CONTEXT;
10953 const char c = (char)ch;
10955 CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
10956 case GLOBAL_PAT_MOD: *pmfl |= PMf_GLOBAL; break;
10957 case CONTINUE_PAT_MOD: *pmfl |= PMf_CONTINUE; break;
10958 case ONCE_PAT_MOD: *pmfl |= PMf_KEEP; break;
10959 case KEEPCOPY_PAT_MOD: *pmfl |= PMf_KEEPCOPY; break;
10965 S_scan_pat(pTHX_ char *start, I32 type)
10969 char *s = scan_str(start,!!PL_madskills,FALSE);
10970 const char * const valid_flags =
10971 (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
10976 PERL_ARGS_ASSERT_SCAN_PAT;
10979 const char * const delimiter = skipspace(start);
10983 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10984 : "Search pattern not terminated" ));
10987 pm = (PMOP*)newPMOP(type, 0);
10988 if (PL_multi_open == '?') {
10989 /* This is the only point in the code that sets PMf_ONCE: */
10990 pm->op_pmflags |= PMf_ONCE;
10992 /* Hence it's safe to do this bit of PMOP book-keeping here, which
10993 allows us to restrict the list needed by reset to just the ??
10995 assert(type != OP_TRANS);
10997 MAGIC *mg = mg_find((const SV *)PL_curstash, PERL_MAGIC_symtab);
11000 mg = sv_magicext(MUTABLE_SV(PL_curstash), 0, PERL_MAGIC_symtab, 0, 0,
11003 elements = mg->mg_len / sizeof(PMOP**);
11004 Renewc(mg->mg_ptr, elements + 1, PMOP*, char);
11005 ((PMOP**)mg->mg_ptr) [elements++] = pm;
11006 mg->mg_len = elements * sizeof(PMOP**);
11007 PmopSTASH_set(pm,PL_curstash);
11013 while (*s && strchr(valid_flags, *s))
11014 pmflag(&pm->op_pmflags,*s++);
11016 if (PL_madskills && modstart != s) {
11017 SV* tmptoken = newSVpvn(modstart, s - modstart);
11018 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
11021 /* issue a warning if /c is specified,but /g is not */
11022 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
11023 && ckWARN(WARN_REGEXP))
11025 Perl_warner(aTHX_ packWARN(WARN_REGEXP),
11026 "Use of /c modifier is meaningless without /g" );
11029 PL_lex_op = (OP*)pm;
11030 pl_yylval.ival = OP_MATCH;
11035 S_scan_subst(pTHX_ char *start)
11046 PERL_ARGS_ASSERT_SCAN_SUBST;
11048 pl_yylval.ival = OP_NULL;
11050 s = scan_str(start,!!PL_madskills,FALSE);
11053 Perl_croak(aTHX_ "Substitution pattern not terminated");
11055 if (s[-1] == PL_multi_open)
11058 if (PL_madskills) {
11059 CURMAD('q', PL_thisopen);
11060 CURMAD('_', PL_thiswhite);
11061 CURMAD('E', PL_thisstuff);
11062 CURMAD('Q', PL_thisclose);
11063 PL_realtokenstart = s - SvPVX(PL_linestr);
11067 first_start = PL_multi_start;
11068 s = scan_str(s,!!PL_madskills,FALSE);
11070 if (PL_lex_stuff) {
11071 SvREFCNT_dec(PL_lex_stuff);
11072 PL_lex_stuff = NULL;
11074 Perl_croak(aTHX_ "Substitution replacement not terminated");
11076 PL_multi_start = first_start; /* so whole substitution is taken together */
11078 pm = (PMOP*)newPMOP(OP_SUBST, 0);
11081 if (PL_madskills) {
11082 CURMAD('z', PL_thisopen);
11083 CURMAD('R', PL_thisstuff);
11084 CURMAD('Z', PL_thisclose);
11090 if (*s == EXEC_PAT_MOD) {
11094 else if (strchr(S_PAT_MODS, *s))
11095 pmflag(&pm->op_pmflags,*s++);
11101 if (PL_madskills) {
11103 curmad('m', newSVpvn(modstart, s - modstart));
11104 append_madprops(PL_thismad, (OP*)pm, 0);
11108 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
11109 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
11113 SV * const repl = newSVpvs("");
11115 PL_sublex_info.super_bufptr = s;
11116 PL_sublex_info.super_bufend = PL_bufend;
11118 pm->op_pmflags |= PMf_EVAL;
11121 sv_catpvs(repl, "eval ");
11123 sv_catpvs(repl, "do ");
11125 sv_catpvs(repl, "{");
11126 sv_catsv(repl, PL_lex_repl);
11127 if (strchr(SvPVX(PL_lex_repl), '#'))
11128 sv_catpvs(repl, "\n");
11129 sv_catpvs(repl, "}");
11131 SvREFCNT_dec(PL_lex_repl);
11132 PL_lex_repl = repl;
11135 PL_lex_op = (OP*)pm;
11136 pl_yylval.ival = OP_SUBST;
11141 S_scan_trans(pTHX_ char *start)
11154 PERL_ARGS_ASSERT_SCAN_TRANS;
11156 pl_yylval.ival = OP_NULL;
11158 s = scan_str(start,!!PL_madskills,FALSE);
11160 Perl_croak(aTHX_ "Transliteration pattern not terminated");
11162 if (s[-1] == PL_multi_open)
11165 if (PL_madskills) {
11166 CURMAD('q', PL_thisopen);
11167 CURMAD('_', PL_thiswhite);
11168 CURMAD('E', PL_thisstuff);
11169 CURMAD('Q', PL_thisclose);
11170 PL_realtokenstart = s - SvPVX(PL_linestr);
11174 s = scan_str(s,!!PL_madskills,FALSE);
11176 if (PL_lex_stuff) {
11177 SvREFCNT_dec(PL_lex_stuff);
11178 PL_lex_stuff = NULL;
11180 Perl_croak(aTHX_ "Transliteration replacement not terminated");
11182 if (PL_madskills) {
11183 CURMAD('z', PL_thisopen);
11184 CURMAD('R', PL_thisstuff);
11185 CURMAD('Z', PL_thisclose);
11188 complement = del = squash = 0;
11195 complement = OPpTRANS_COMPLEMENT;
11198 del = OPpTRANS_DELETE;
11201 squash = OPpTRANS_SQUASH;
11210 tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
11211 o = newPVOP(OP_TRANS, 0, (char*)tbl);
11212 o->op_private &= ~OPpTRANS_ALL;
11213 o->op_private |= del|squash|complement|
11214 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
11215 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
11218 pl_yylval.ival = OP_TRANS;
11221 if (PL_madskills) {
11223 curmad('m', newSVpvn(modstart, s - modstart));
11224 append_madprops(PL_thismad, o, 0);
11233 S_scan_heredoc(pTHX_ register char *s)
11237 I32 op_type = OP_SCALAR;
11241 const char *found_newline;
11245 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
11247 I32 stuffstart = s - SvPVX(PL_linestr);
11250 PL_realtokenstart = -1;
11253 PERL_ARGS_ASSERT_SCAN_HEREDOC;
11257 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
11261 while (SPACE_OR_TAB(*peek))
11263 if (*peek == '`' || *peek == '\'' || *peek =='"') {
11266 s = delimcpy(d, e, s, PL_bufend, term, &len);
11276 if (!isALNUM_lazy_if(s,UTF))
11277 deprecate_old("bare << to mean <<\"\"");
11278 for (; isALNUM_lazy_if(s,UTF); s++) {
11283 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
11284 Perl_croak(aTHX_ "Delimiter for here document is too long");
11287 len = d - PL_tokenbuf;
11290 if (PL_madskills) {
11291 tstart = PL_tokenbuf + !outer;
11292 PL_thisclose = newSVpvn(tstart, len - !outer);
11293 tstart = SvPVX(PL_linestr) + stuffstart;
11294 PL_thisopen = newSVpvn(tstart, s - tstart);
11295 stuffstart = s - SvPVX(PL_linestr);
11298 #ifndef PERL_STRICT_CR
11299 d = strchr(s, '\r');
11301 char * const olds = s;
11303 while (s < PL_bufend) {
11309 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11318 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11325 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11326 herewas = newSVpvn(s,PL_bufend-s);
11330 herewas = newSVpvn(s-1,found_newline-s+1);
11333 herewas = newSVpvn(s,found_newline-s);
11337 if (PL_madskills) {
11338 tstart = SvPVX(PL_linestr) + stuffstart;
11340 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11342 PL_thisstuff = newSVpvn(tstart, s - tstart);
11345 s += SvCUR(herewas);
11348 stuffstart = s - SvPVX(PL_linestr);
11354 tmpstr = newSV_type(SVt_PVIV);
11355 SvGROW(tmpstr, 80);
11356 if (term == '\'') {
11357 op_type = OP_CONST;
11358 SvIV_set(tmpstr, -1);
11360 else if (term == '`') {
11361 op_type = OP_BACKTICK;
11362 SvIV_set(tmpstr, '\\');
11366 PL_multi_start = CopLINE(PL_curcop);
11367 PL_multi_open = PL_multi_close = '<';
11368 term = *PL_tokenbuf;
11369 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11370 char * const bufptr = PL_sublex_info.super_bufptr;
11371 char * const bufend = PL_sublex_info.super_bufend;
11372 char * const olds = s - SvCUR(herewas);
11373 s = strchr(bufptr, '\n');
11377 while (s < bufend &&
11378 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11380 CopLINE_inc(PL_curcop);
11383 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11384 missingterm(PL_tokenbuf);
11386 sv_setpvn(herewas,bufptr,d-bufptr+1);
11387 sv_setpvn(tmpstr,d+1,s-d);
11389 sv_catpvn(herewas,s,bufend-s);
11390 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11397 while (s < PL_bufend &&
11398 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11400 CopLINE_inc(PL_curcop);
11402 if (s >= PL_bufend) {
11403 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11404 missingterm(PL_tokenbuf);
11406 sv_setpvn(tmpstr,d+1,s-d);
11408 if (PL_madskills) {
11410 sv_catpvn(PL_thisstuff, d + 1, s - d);
11412 PL_thisstuff = newSVpvn(d + 1, s - d);
11413 stuffstart = s - SvPVX(PL_linestr);
11417 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11419 sv_catpvn(herewas,s,PL_bufend-s);
11420 sv_setsv(PL_linestr,herewas);
11421 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11422 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11423 PL_last_lop = PL_last_uni = NULL;
11426 sv_setpvs(tmpstr,""); /* avoid "uninitialized" warning */
11427 while (s >= PL_bufend) { /* multiple line string? */
11429 if (PL_madskills) {
11430 tstart = SvPVX(PL_linestr) + stuffstart;
11432 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11434 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11438 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11439 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11440 missingterm(PL_tokenbuf);
11443 stuffstart = s - SvPVX(PL_linestr);
11445 CopLINE_inc(PL_curcop);
11446 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11447 PL_last_lop = PL_last_uni = NULL;
11448 #ifndef PERL_STRICT_CR
11449 if (PL_bufend - PL_linestart >= 2) {
11450 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11451 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11453 PL_bufend[-2] = '\n';
11455 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11457 else if (PL_bufend[-1] == '\r')
11458 PL_bufend[-1] = '\n';
11460 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11461 PL_bufend[-1] = '\n';
11463 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
11464 update_debugger_info(PL_linestr, NULL, 0);
11465 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11466 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11467 *(SvPVX(PL_linestr) + off ) = ' ';
11468 sv_catsv(PL_linestr,herewas);
11469 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11470 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11474 sv_catsv(tmpstr,PL_linestr);
11479 PL_multi_end = CopLINE(PL_curcop);
11480 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11481 SvPV_shrink_to_cur(tmpstr);
11483 SvREFCNT_dec(herewas);
11485 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11487 else if (PL_encoding)
11488 sv_recode_to_utf8(tmpstr, PL_encoding);
11490 PL_lex_stuff = tmpstr;
11491 pl_yylval.ival = op_type;
11495 /* scan_inputsymbol
11496 takes: current position in input buffer
11497 returns: new position in input buffer
11498 side-effects: pl_yylval and lex_op are set.
11503 <FH> read from filehandle
11504 <pkg::FH> read from package qualified filehandle
11505 <pkg'FH> read from package qualified filehandle
11506 <$fh> read from filehandle in $fh
11507 <*.h> filename glob
11512 S_scan_inputsymbol(pTHX_ char *start)
11515 register char *s = start; /* current position in buffer */
11518 char *d = PL_tokenbuf; /* start of temp holding space */
11519 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11521 PERL_ARGS_ASSERT_SCAN_INPUTSYMBOL;
11523 end = strchr(s, '\n');
11526 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11528 /* die if we didn't have space for the contents of the <>,
11529 or if it didn't end, or if we see a newline
11532 if (len >= (I32)sizeof PL_tokenbuf)
11533 Perl_croak(aTHX_ "Excessively long <> operator");
11535 Perl_croak(aTHX_ "Unterminated <> operator");
11540 Remember, only scalar variables are interpreted as filehandles by
11541 this code. Anything more complex (e.g., <$fh{$num}>) will be
11542 treated as a glob() call.
11543 This code makes use of the fact that except for the $ at the front,
11544 a scalar variable and a filehandle look the same.
11546 if (*d == '$' && d[1]) d++;
11548 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11549 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11552 /* If we've tried to read what we allow filehandles to look like, and
11553 there's still text left, then it must be a glob() and not a getline.
11554 Use scan_str to pull out the stuff between the <> and treat it
11555 as nothing more than a string.
11558 if (d - PL_tokenbuf != len) {
11559 pl_yylval.ival = OP_GLOB;
11560 s = scan_str(start,!!PL_madskills,FALSE);
11562 Perl_croak(aTHX_ "Glob not terminated");
11566 bool readline_overriden = FALSE;
11569 /* we're in a filehandle read situation */
11572 /* turn <> into <ARGV> */
11574 Copy("ARGV",d,5,char);
11576 /* Check whether readline() is overriden */
11577 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11579 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11581 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11582 && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
11583 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11584 readline_overriden = TRUE;
11586 /* if <$fh>, create the ops to turn the variable into a
11590 /* try to find it in the pad for this block, otherwise find
11591 add symbol table ops
11593 const PADOFFSET tmp = pad_findmy(d);
11594 if (tmp != NOT_IN_PAD) {
11595 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11596 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11597 HEK * const stashname = HvNAME_HEK(stash);
11598 SV * const sym = sv_2mortal(newSVhek(stashname));
11599 sv_catpvs(sym, "::");
11600 sv_catpv(sym, d+1);
11605 OP * const o = newOP(OP_PADSV, 0);
11607 PL_lex_op = readline_overriden
11608 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11609 append_elem(OP_LIST, o,
11610 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11611 : (OP*)newUNOP(OP_READLINE, 0, o);
11620 ? (GV_ADDMULTI | GV_ADDINEVAL)
11623 PL_lex_op = readline_overriden
11624 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11625 append_elem(OP_LIST,
11626 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11627 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11628 : (OP*)newUNOP(OP_READLINE, 0,
11629 newUNOP(OP_RV2SV, 0,
11630 newGVOP(OP_GV, 0, gv)));
11632 if (!readline_overriden)
11633 PL_lex_op->op_flags |= OPf_SPECIAL;
11634 /* we created the ops in PL_lex_op, so make pl_yylval.ival a null op */
11635 pl_yylval.ival = OP_NULL;
11638 /* If it's none of the above, it must be a literal filehandle
11639 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11641 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11642 PL_lex_op = readline_overriden
11643 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11644 append_elem(OP_LIST,
11645 newGVOP(OP_GV, 0, gv),
11646 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11647 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11648 pl_yylval.ival = OP_NULL;
11657 takes: start position in buffer
11658 keep_quoted preserve \ on the embedded delimiter(s)
11659 keep_delims preserve the delimiters around the string
11660 returns: position to continue reading from buffer
11661 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11662 updates the read buffer.
11664 This subroutine pulls a string out of the input. It is called for:
11665 q single quotes q(literal text)
11666 ' single quotes 'literal text'
11667 qq double quotes qq(interpolate $here please)
11668 " double quotes "interpolate $here please"
11669 qx backticks qx(/bin/ls -l)
11670 ` backticks `/bin/ls -l`
11671 qw quote words @EXPORT_OK = qw( func() $spam )
11672 m// regexp match m/this/
11673 s/// regexp substitute s/this/that/
11674 tr/// string transliterate tr/this/that/
11675 y/// string transliterate y/this/that/
11676 ($*@) sub prototypes sub foo ($)
11677 (stuff) sub attr parameters sub foo : attr(stuff)
11678 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11680 In most of these cases (all but <>, patterns and transliterate)
11681 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11682 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11683 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11686 It skips whitespace before the string starts, and treats the first
11687 character as the delimiter. If the delimiter is one of ([{< then
11688 the corresponding "close" character )]}> is used as the closing
11689 delimiter. It allows quoting of delimiters, and if the string has
11690 balanced delimiters ([{<>}]) it allows nesting.
11692 On success, the SV with the resulting string is put into lex_stuff or,
11693 if that is already non-NULL, into lex_repl. The second case occurs only
11694 when parsing the RHS of the special constructs s/// and tr/// (y///).
11695 For convenience, the terminating delimiter character is stuffed into
11700 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11703 SV *sv; /* scalar value: string */
11704 const char *tmps; /* temp string, used for delimiter matching */
11705 register char *s = start; /* current position in the buffer */
11706 register char term; /* terminating character */
11707 register char *to; /* current position in the sv's data */
11708 I32 brackets = 1; /* bracket nesting level */
11709 bool has_utf8 = FALSE; /* is there any utf8 content? */
11710 I32 termcode; /* terminating char. code */
11711 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11712 STRLEN termlen; /* length of terminating string */
11713 int last_off = 0; /* last position for nesting bracket */
11719 PERL_ARGS_ASSERT_SCAN_STR;
11721 /* skip space before the delimiter */
11727 if (PL_realtokenstart >= 0) {
11728 stuffstart = PL_realtokenstart;
11729 PL_realtokenstart = -1;
11732 stuffstart = start - SvPVX(PL_linestr);
11734 /* mark where we are, in case we need to report errors */
11737 /* after skipping whitespace, the next character is the terminator */
11740 termcode = termstr[0] = term;
11744 termcode = utf8_to_uvchr((U8*)s, &termlen);
11745 Copy(s, termstr, termlen, U8);
11746 if (!UTF8_IS_INVARIANT(term))
11750 /* mark where we are */
11751 PL_multi_start = CopLINE(PL_curcop);
11752 PL_multi_open = term;
11754 /* find corresponding closing delimiter */
11755 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11756 termcode = termstr[0] = term = tmps[5];
11758 PL_multi_close = term;
11760 /* create a new SV to hold the contents. 79 is the SV's initial length.
11761 What a random number. */
11762 sv = newSV_type(SVt_PVIV);
11764 SvIV_set(sv, termcode);
11765 (void)SvPOK_only(sv); /* validate pointer */
11767 /* move past delimiter and try to read a complete string */
11769 sv_catpvn(sv, s, termlen);
11772 tstart = SvPVX(PL_linestr) + stuffstart;
11773 if (!PL_thisopen && !keep_delims) {
11774 PL_thisopen = newSVpvn(tstart, s - tstart);
11775 stuffstart = s - SvPVX(PL_linestr);
11779 if (PL_encoding && !UTF) {
11783 int offset = s - SvPVX_const(PL_linestr);
11784 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11785 &offset, (char*)termstr, termlen);
11786 const char * const ns = SvPVX_const(PL_linestr) + offset;
11787 char * const svlast = SvEND(sv) - 1;
11789 for (; s < ns; s++) {
11790 if (*s == '\n' && !PL_rsfp)
11791 CopLINE_inc(PL_curcop);
11794 goto read_more_line;
11796 /* handle quoted delimiters */
11797 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11799 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11801 if ((svlast-1 - t) % 2) {
11802 if (!keep_quoted) {
11803 *(svlast-1) = term;
11805 SvCUR_set(sv, SvCUR(sv) - 1);
11810 if (PL_multi_open == PL_multi_close) {
11816 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
11817 /* At here, all closes are "was quoted" one,
11818 so we don't check PL_multi_close. */
11820 if (!keep_quoted && *(t+1) == PL_multi_open)
11825 else if (*t == PL_multi_open)
11833 SvCUR_set(sv, w - SvPVX_const(sv));
11835 last_off = w - SvPVX(sv);
11836 if (--brackets <= 0)
11841 if (!keep_delims) {
11842 SvCUR_set(sv, SvCUR(sv) - 1);
11848 /* extend sv if need be */
11849 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11850 /* set 'to' to the next character in the sv's string */
11851 to = SvPVX(sv)+SvCUR(sv);
11853 /* if open delimiter is the close delimiter read unbridle */
11854 if (PL_multi_open == PL_multi_close) {
11855 for (; s < PL_bufend; s++,to++) {
11856 /* embedded newlines increment the current line number */
11857 if (*s == '\n' && !PL_rsfp)
11858 CopLINE_inc(PL_curcop);
11859 /* handle quoted delimiters */
11860 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11861 if (!keep_quoted && s[1] == term)
11863 /* any other quotes are simply copied straight through */
11867 /* terminate when run out of buffer (the for() condition), or
11868 have found the terminator */
11869 else if (*s == term) {
11872 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11875 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11881 /* if the terminator isn't the same as the start character (e.g.,
11882 matched brackets), we have to allow more in the quoting, and
11883 be prepared for nested brackets.
11886 /* read until we run out of string, or we find the terminator */
11887 for (; s < PL_bufend; s++,to++) {
11888 /* embedded newlines increment the line count */
11889 if (*s == '\n' && !PL_rsfp)
11890 CopLINE_inc(PL_curcop);
11891 /* backslashes can escape the open or closing characters */
11892 if (*s == '\\' && s+1 < PL_bufend) {
11893 if (!keep_quoted &&
11894 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11899 /* allow nested opens and closes */
11900 else if (*s == PL_multi_close && --brackets <= 0)
11902 else if (*s == PL_multi_open)
11904 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11909 /* terminate the copied string and update the sv's end-of-string */
11911 SvCUR_set(sv, to - SvPVX_const(sv));
11914 * this next chunk reads more into the buffer if we're not done yet
11918 break; /* handle case where we are done yet :-) */
11920 #ifndef PERL_STRICT_CR
11921 if (to - SvPVX_const(sv) >= 2) {
11922 if ((to[-2] == '\r' && to[-1] == '\n') ||
11923 (to[-2] == '\n' && to[-1] == '\r'))
11927 SvCUR_set(sv, to - SvPVX_const(sv));
11929 else if (to[-1] == '\r')
11932 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11937 /* if we're out of file, or a read fails, bail and reset the current
11938 line marker so we can report where the unterminated string began
11941 if (PL_madskills) {
11942 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11944 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11946 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11950 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11952 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11958 /* we read a line, so increment our line counter */
11959 CopLINE_inc(PL_curcop);
11961 /* update debugger info */
11962 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
11963 update_debugger_info(PL_linestr, NULL, 0);
11965 /* having changed the buffer, we must update PL_bufend */
11966 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11967 PL_last_lop = PL_last_uni = NULL;
11970 /* at this point, we have successfully read the delimited string */
11972 if (!PL_encoding || UTF) {
11974 if (PL_madskills) {
11975 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11976 const int len = s - tstart;
11978 sv_catpvn(PL_thisstuff, tstart, len);
11980 PL_thisstuff = newSVpvn(tstart, len);
11981 if (!PL_thisclose && !keep_delims)
11982 PL_thisclose = newSVpvn(s,termlen);
11987 sv_catpvn(sv, s, termlen);
11992 if (PL_madskills) {
11993 char * const tstart = SvPVX(PL_linestr) + stuffstart;
11994 const int len = s - tstart - termlen;
11996 sv_catpvn(PL_thisstuff, tstart, len);
11998 PL_thisstuff = newSVpvn(tstart, len);
11999 if (!PL_thisclose && !keep_delims)
12000 PL_thisclose = newSVpvn(s - termlen,termlen);
12004 if (has_utf8 || PL_encoding)
12007 PL_multi_end = CopLINE(PL_curcop);
12009 /* if we allocated too much space, give some back */
12010 if (SvCUR(sv) + 5 < SvLEN(sv)) {
12011 SvLEN_set(sv, SvCUR(sv) + 1);
12012 SvPV_renew(sv, SvLEN(sv));
12015 /* decide whether this is the first or second quoted string we've read
12028 takes: pointer to position in buffer
12029 returns: pointer to new position in buffer
12030 side-effects: builds ops for the constant in pl_yylval.op
12032 Read a number in any of the formats that Perl accepts:
12034 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
12035 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
12038 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
12040 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
12043 If it reads a number without a decimal point or an exponent, it will
12044 try converting the number to an integer and see if it can do so
12045 without loss of precision.
12049 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
12052 register const char *s = start; /* current position in buffer */
12053 register char *d; /* destination in temp buffer */
12054 register char *e; /* end of temp buffer */
12055 NV nv; /* number read, as a double */
12056 SV *sv = NULL; /* place to put the converted number */
12057 bool floatit; /* boolean: int or float? */
12058 const char *lastub = NULL; /* position of last underbar */
12059 static char const number_too_long[] = "Number too long";
12061 PERL_ARGS_ASSERT_SCAN_NUM;
12063 /* We use the first character to decide what type of number this is */
12067 Perl_croak(aTHX_ "panic: scan_num");
12069 /* if it starts with a 0, it could be an octal number, a decimal in
12070 0.13 disguise, or a hexadecimal number, or a binary number. */
12074 u holds the "number so far"
12075 shift the power of 2 of the base
12076 (hex == 4, octal == 3, binary == 1)
12077 overflowed was the number more than we can hold?
12079 Shift is used when we add a digit. It also serves as an "are
12080 we in octal/hex/binary?" indicator to disallow hex characters
12081 when in octal mode.
12086 bool overflowed = FALSE;
12087 bool just_zero = TRUE; /* just plain 0 or binary number? */
12088 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
12089 static const char* const bases[5] =
12090 { "", "binary", "", "octal", "hexadecimal" };
12091 static const char* const Bases[5] =
12092 { "", "Binary", "", "Octal", "Hexadecimal" };
12093 static const char* const maxima[5] =
12095 "0b11111111111111111111111111111111",
12099 const char *base, *Base, *max;
12101 /* check for hex */
12106 } else if (s[1] == 'b') {
12111 /* check for a decimal in disguise */
12112 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
12114 /* so it must be octal */
12121 if (ckWARN(WARN_SYNTAX))
12122 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12123 "Misplaced _ in number");
12127 base = bases[shift];
12128 Base = Bases[shift];
12129 max = maxima[shift];
12131 /* read the rest of the number */
12133 /* x is used in the overflow test,
12134 b is the digit we're adding on. */
12139 /* if we don't mention it, we're done */
12143 /* _ are ignored -- but warned about if consecutive */
12145 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12146 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12147 "Misplaced _ in number");
12151 /* 8 and 9 are not octal */
12152 case '8': case '9':
12154 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
12158 case '2': case '3': case '4':
12159 case '5': case '6': case '7':
12161 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
12164 case '0': case '1':
12165 b = *s++ & 15; /* ASCII digit -> value of digit */
12169 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
12170 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
12171 /* make sure they said 0x */
12174 b = (*s++ & 7) + 9;
12176 /* Prepare to put the digit we have onto the end
12177 of the number so far. We check for overflows.
12183 x = u << shift; /* make room for the digit */
12185 if ((x >> shift) != u
12186 && !(PL_hints & HINT_NEW_BINARY)) {
12189 if (ckWARN_d(WARN_OVERFLOW))
12190 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12191 "Integer overflow in %s number",
12194 u = x | b; /* add the digit to the end */
12197 n *= nvshift[shift];
12198 /* If an NV has not enough bits in its
12199 * mantissa to represent an UV this summing of
12200 * small low-order numbers is a waste of time
12201 * (because the NV cannot preserve the
12202 * low-order bits anyway): we could just
12203 * remember when did we overflow and in the
12204 * end just multiply n by the right
12212 /* if we get here, we had success: make a scalar value from
12217 /* final misplaced underbar check */
12218 if (s[-1] == '_') {
12219 if (ckWARN(WARN_SYNTAX))
12220 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12225 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
12226 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12227 "%s number > %s non-portable",
12233 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
12234 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12235 "%s number > %s non-portable",
12240 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
12241 sv = new_constant(start, s - start, "integer",
12242 sv, NULL, NULL, 0);
12243 else if (PL_hints & HINT_NEW_BINARY)
12244 sv = new_constant(start, s - start, "binary", sv, NULL, NULL, 0);
12249 handle decimal numbers.
12250 we're also sent here when we read a 0 as the first digit
12252 case '1': case '2': case '3': case '4': case '5':
12253 case '6': case '7': case '8': case '9': case '.':
12256 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
12259 /* read next group of digits and _ and copy into d */
12260 while (isDIGIT(*s) || *s == '_') {
12261 /* skip underscores, checking for misplaced ones
12265 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12266 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12267 "Misplaced _ in number");
12271 /* check for end of fixed-length buffer */
12273 Perl_croak(aTHX_ number_too_long);
12274 /* if we're ok, copy the character */
12279 /* final misplaced underbar check */
12280 if (lastub && s == lastub + 1) {
12281 if (ckWARN(WARN_SYNTAX))
12282 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12285 /* read a decimal portion if there is one. avoid
12286 3..5 being interpreted as the number 3. followed
12289 if (*s == '.' && s[1] != '.') {
12294 if (ckWARN(WARN_SYNTAX))
12295 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12296 "Misplaced _ in number");
12300 /* copy, ignoring underbars, until we run out of digits.
12302 for (; isDIGIT(*s) || *s == '_'; s++) {
12303 /* fixed length buffer check */
12305 Perl_croak(aTHX_ number_too_long);
12307 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12308 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12309 "Misplaced _ in number");
12315 /* fractional part ending in underbar? */
12316 if (s[-1] == '_') {
12317 if (ckWARN(WARN_SYNTAX))
12318 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12319 "Misplaced _ in number");
12321 if (*s == '.' && isDIGIT(s[1])) {
12322 /* oops, it's really a v-string, but without the "v" */
12328 /* read exponent part, if present */
12329 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12333 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12334 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
12336 /* stray preinitial _ */
12338 if (ckWARN(WARN_SYNTAX))
12339 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12340 "Misplaced _ in number");
12344 /* allow positive or negative exponent */
12345 if (*s == '+' || *s == '-')
12348 /* stray initial _ */
12350 if (ckWARN(WARN_SYNTAX))
12351 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12352 "Misplaced _ in number");
12356 /* read digits of exponent */
12357 while (isDIGIT(*s) || *s == '_') {
12360 Perl_croak(aTHX_ number_too_long);
12364 if (((lastub && s == lastub + 1) ||
12365 (!isDIGIT(s[1]) && s[1] != '_'))
12366 && ckWARN(WARN_SYNTAX))
12367 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12368 "Misplaced _ in number");
12375 /* make an sv from the string */
12379 We try to do an integer conversion first if no characters
12380 indicating "float" have been found.
12385 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12387 if (flags == IS_NUMBER_IN_UV) {
12389 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12392 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12393 if (uv <= (UV) IV_MIN)
12394 sv_setiv(sv, -(IV)uv);
12401 /* terminate the string */
12403 nv = Atof(PL_tokenbuf);
12408 ? (PL_hints & HINT_NEW_FLOAT) : (PL_hints & HINT_NEW_INTEGER) ) {
12409 const char *const key = floatit ? "float" : "integer";
12410 const STRLEN keylen = floatit ? 5 : 7;
12411 sv = S_new_constant(aTHX_ PL_tokenbuf, d - PL_tokenbuf,
12412 key, keylen, sv, NULL, NULL, 0);
12416 /* if it starts with a v, it could be a v-string */
12419 sv = newSV(5); /* preallocate storage space */
12420 s = scan_vstring(s, PL_bufend, sv);
12424 /* make the op for the constant and return */
12427 lvalp->opval = newSVOP(OP_CONST, 0, sv);
12429 lvalp->opval = NULL;
12435 S_scan_formline(pTHX_ register char *s)
12438 register char *eol;
12440 SV * const stuff = newSVpvs("");
12441 bool needargs = FALSE;
12442 bool eofmt = FALSE;
12444 char *tokenstart = s;
12445 SV* savewhite = NULL;
12447 if (PL_madskills) {
12448 savewhite = PL_thiswhite;
12453 PERL_ARGS_ASSERT_SCAN_FORMLINE;
12455 while (!needargs) {
12458 #ifdef PERL_STRICT_CR
12459 while (SPACE_OR_TAB(*t))
12462 while (SPACE_OR_TAB(*t) || *t == '\r')
12465 if (*t == '\n' || t == PL_bufend) {
12470 if (PL_in_eval && !PL_rsfp) {
12471 eol = (char *) memchr(s,'\n',PL_bufend-s);
12476 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12478 for (t = s; t < eol; t++) {
12479 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12481 goto enough; /* ~~ must be first line in formline */
12483 if (*t == '@' || *t == '^')
12487 sv_catpvn(stuff, s, eol-s);
12488 #ifndef PERL_STRICT_CR
12489 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12490 char *end = SvPVX(stuff) + SvCUR(stuff);
12493 SvCUR_set(stuff, SvCUR(stuff) - 1);
12503 if (PL_madskills) {
12505 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12507 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12510 s = filter_gets(PL_linestr, PL_rsfp, 0);
12512 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12514 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12516 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12517 PL_last_lop = PL_last_uni = NULL;
12526 if (SvCUR(stuff)) {
12529 PL_lex_state = LEX_NORMAL;
12530 start_force(PL_curforce);
12531 NEXTVAL_NEXTTOKE.ival = 0;
12535 PL_lex_state = LEX_FORMLINE;
12537 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12539 else if (PL_encoding)
12540 sv_recode_to_utf8(stuff, PL_encoding);
12542 start_force(PL_curforce);
12543 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12545 start_force(PL_curforce);
12546 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12550 SvREFCNT_dec(stuff);
12552 PL_lex_formbrack = 0;
12556 if (PL_madskills) {
12558 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12560 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12561 PL_thiswhite = savewhite;
12568 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12571 const I32 oldsavestack_ix = PL_savestack_ix;
12572 CV* const outsidecv = PL_compcv;
12575 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12577 SAVEI32(PL_subline);
12578 save_item(PL_subname);
12579 SAVESPTR(PL_compcv);
12581 PL_compcv = MUTABLE_CV(newSV_type(is_format ? SVt_PVFM : SVt_PVCV));
12582 CvFLAGS(PL_compcv) |= flags;
12584 PL_subline = CopLINE(PL_curcop);
12585 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12586 CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv));
12587 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12589 return oldsavestack_ix;
12593 #pragma segment Perl_yylex
12596 S_yywarn(pTHX_ const char *const s)
12600 PERL_ARGS_ASSERT_YYWARN;
12602 PL_in_eval |= EVAL_WARNONLY;
12604 PL_in_eval &= ~EVAL_WARNONLY;
12609 Perl_yyerror(pTHX_ const char *const s)
12612 const char *where = NULL;
12613 const char *context = NULL;
12616 int yychar = PL_parser->yychar;
12618 PERL_ARGS_ASSERT_YYERROR;
12620 if (!yychar || (yychar == ';' && !PL_rsfp))
12622 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12623 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12624 PL_oldbufptr != PL_bufptr) {
12627 The code below is removed for NetWare because it abends/crashes on NetWare
12628 when the script has error such as not having the closing quotes like:
12629 if ($var eq "value)
12630 Checking of white spaces is anyway done in NetWare code.
12633 while (isSPACE(*PL_oldoldbufptr))
12636 context = PL_oldoldbufptr;
12637 contlen = PL_bufptr - PL_oldoldbufptr;
12639 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12640 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12643 The code below is removed for NetWare because it abends/crashes on NetWare
12644 when the script has error such as not having the closing quotes like:
12645 if ($var eq "value)
12646 Checking of white spaces is anyway done in NetWare code.
12649 while (isSPACE(*PL_oldbufptr))
12652 context = PL_oldbufptr;
12653 contlen = PL_bufptr - PL_oldbufptr;
12655 else if (yychar > 255)
12656 where = "next token ???";
12657 else if (yychar == -2) { /* YYEMPTY */
12658 if (PL_lex_state == LEX_NORMAL ||
12659 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12660 where = "at end of line";
12661 else if (PL_lex_inpat)
12662 where = "within pattern";
12664 where = "within string";
12667 SV * const where_sv = newSVpvs_flags("next char ", SVs_TEMP);
12669 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12670 else if (isPRINT_LC(yychar)) {
12671 const char string = yychar;
12672 sv_catpvn(where_sv, &string, 1);
12675 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12676 where = SvPVX_const(where_sv);
12678 msg = sv_2mortal(newSVpv(s, 0));
12679 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12680 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12682 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12684 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12685 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12686 Perl_sv_catpvf(aTHX_ msg,
12687 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12688 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12691 if (PL_in_eval & EVAL_WARNONLY) {
12692 if (ckWARN_d(WARN_SYNTAX))
12693 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
12697 if (PL_error_count >= 10) {
12698 if (PL_in_eval && SvCUR(ERRSV))
12699 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12700 SVfARG(ERRSV), OutCopFILE(PL_curcop));
12702 Perl_croak(aTHX_ "%s has too many errors.\n",
12703 OutCopFILE(PL_curcop));
12706 PL_in_my_stash = NULL;
12710 #pragma segment Main
12714 S_swallow_bom(pTHX_ U8 *s)
12717 const STRLEN slen = SvCUR(PL_linestr);
12719 PERL_ARGS_ASSERT_SWALLOW_BOM;
12723 if (s[1] == 0xFE) {
12724 /* UTF-16 little-endian? (or UTF32-LE?) */
12725 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12726 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12727 #ifndef PERL_NO_UTF16_FILTER
12728 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12731 if (PL_bufend > (char*)s) {
12735 filter_add(utf16rev_textfilter, NULL);
12736 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12737 utf16_to_utf8_reversed(s, news,
12738 PL_bufend - (char*)s - 1,
12740 sv_setpvn(PL_linestr, (const char*)news, newlen);
12742 s = (U8*)SvPVX(PL_linestr);
12743 Copy(news, s, newlen, U8);
12747 SvUTF8_on(PL_linestr);
12748 s = (U8*)SvPVX(PL_linestr);
12750 /* FIXME - is this a general bug fix? */
12753 PL_bufend = SvPVX(PL_linestr) + newlen;
12756 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12761 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12762 #ifndef PERL_NO_UTF16_FILTER
12763 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12766 if (PL_bufend > (char *)s) {
12770 filter_add(utf16_textfilter, NULL);
12771 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12772 utf16_to_utf8(s, news,
12773 PL_bufend - (char*)s,
12775 sv_setpvn(PL_linestr, (const char*)news, newlen);
12777 SvUTF8_on(PL_linestr);
12778 s = (U8*)SvPVX(PL_linestr);
12779 PL_bufend = SvPVX(PL_linestr) + newlen;
12782 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12787 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12788 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12789 s += 3; /* UTF-8 */
12795 if (s[2] == 0xFE && s[3] == 0xFF) {
12796 /* UTF-32 big-endian */
12797 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12800 else if (s[2] == 0 && s[3] != 0) {
12803 * are a good indicator of UTF-16BE. */
12804 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12810 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12811 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12812 s += 4; /* UTF-8 */
12818 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12821 * are a good indicator of UTF-16LE. */
12822 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12830 #ifndef PERL_NO_UTF16_FILTER
12832 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12835 const STRLEN old = SvCUR(sv);
12836 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12837 DEBUG_P(PerlIO_printf(Perl_debug_log,
12838 "utf16_textfilter(%p): %d %d (%d)\n",
12839 FPTR2DPTR(void *, utf16_textfilter),
12840 idx, maxlen, (int) count));
12844 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12845 Copy(SvPVX_const(sv), tmps, old, char);
12846 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12847 SvCUR(sv) - old, &newlen);
12848 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12850 DEBUG_P({sv_dump(sv);});
12855 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12858 const STRLEN old = SvCUR(sv);
12859 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12860 DEBUG_P(PerlIO_printf(Perl_debug_log,
12861 "utf16rev_textfilter(%p): %d %d (%d)\n",
12862 FPTR2DPTR(void *, utf16rev_textfilter),
12863 idx, maxlen, (int) count));
12867 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12868 Copy(SvPVX_const(sv), tmps, old, char);
12869 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12870 SvCUR(sv) - old, &newlen);
12871 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12873 DEBUG_P({ sv_dump(sv); });
12879 Returns a pointer to the next character after the parsed
12880 vstring, as well as updating the passed in sv.
12882 Function must be called like
12885 s = scan_vstring(s,e,sv);
12887 where s and e are the start and end of the string.
12888 The sv should already be large enough to store the vstring
12889 passed in, for performance reasons.
12894 Perl_scan_vstring(pTHX_ const char *s, const char *const e, SV *sv)
12897 const char *pos = s;
12898 const char *start = s;
12900 PERL_ARGS_ASSERT_SCAN_VSTRING;
12902 if (*pos == 'v') pos++; /* get past 'v' */
12903 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12905 if ( *pos != '.') {
12906 /* this may not be a v-string if followed by => */
12907 const char *next = pos;
12908 while (next < e && isSPACE(*next))
12910 if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
12911 /* return string not v-string */
12912 sv_setpvn(sv,(char *)s,pos-s);
12913 return (char *)pos;
12917 if (!isALPHA(*pos)) {
12918 U8 tmpbuf[UTF8_MAXBYTES+1];
12921 s++; /* get past 'v' */
12926 /* this is atoi() that tolerates underscores */
12929 const char *end = pos;
12931 while (--end >= s) {
12933 const UV orev = rev;
12934 rev += (*end - '0') * mult;
12936 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12937 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12938 "Integer overflow in decimal number");
12942 if (rev > 0x7FFFFFFF)
12943 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12945 /* Append native character for the rev point */
12946 tmpend = uvchr_to_utf8(tmpbuf, rev);
12947 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12948 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12950 if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
12956 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
12960 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12968 * c-indentation-style: bsd
12969 * c-basic-offset: 4
12970 * indent-tabs-mode: t
12973 * ex: set ts=8 sts=4 sw=4 noet: