3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "It all comes from here, the stench and the peril." --Frodo
16 * This file is the lexer for Perl. It's closely linked to the
19 * The main routine is yylex(), which returns the next token.
23 #define PERL_IN_TOKE_C
26 #define yychar (*PL_yycharp)
27 #define yylval (*PL_yylvalp)
29 static const char ident_too_long[] =
30 "Identifier too long";
31 static const char c_without_g[] =
32 "Use of /c modifier is meaningless without /g";
33 static const char c_in_subst[] =
34 "Use of /c modifier is meaningless in s///";
36 static void restore_rsfp(pTHX_ void *f);
37 #ifndef PERL_NO_UTF16_FILTER
38 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
39 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
42 #define XFAKEBRACK 128
45 #ifdef USE_UTF8_SCRIPTS
46 # define UTF (!IN_BYTES)
48 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
51 /* In variables named $^X, these are the legal values for X.
52 * 1999-02-27 mjd-perl-patch@plover.com */
53 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
55 /* On MacOS, respect nonbreaking spaces */
56 #ifdef MACOS_TRADITIONAL
57 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
59 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
62 /* LEX_* are values for PL_lex_state, the state of the lexer.
63 * They are arranged oddly so that the guard on the switch statement
64 * can get by with a single comparison (if the compiler is smart enough).
67 /* #define LEX_NOTPARSING 11 is done in perl.h. */
69 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
70 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
71 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
72 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
73 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
75 /* at end of code, eg "$x" followed by: */
76 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
77 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
79 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
80 string or after \E, $foo, etc */
81 #define LEX_INTERPCONST 2 /* NOT USED */
82 #define LEX_FORMLINE 1 /* expecting a format line */
83 #define LEX_KNOWNEXT 0 /* next token known; just return it */
87 static const char* const lex_state_names[] = {
106 #include "keywords.h"
108 /* CLINE is a macro that ensures PL_copline has a sane value */
113 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
116 * Convenience functions to return different tokens and prime the
117 * lexer for the next token. They all take an argument.
119 * TOKEN : generic token (used for '(', DOLSHARP, etc)
120 * OPERATOR : generic operator
121 * AOPERATOR : assignment operator
122 * PREBLOCK : beginning the block after an if, while, foreach, ...
123 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
124 * PREREF : *EXPR where EXPR is not a simple identifier
125 * TERM : expression term
126 * LOOPX : loop exiting command (goto, last, dump, etc)
127 * FTST : file test operator
128 * FUN0 : zero-argument function
129 * FUN1 : not used, except for not, which isn't a UNIOP
130 * BOop : bitwise or or xor
132 * SHop : shift operator
133 * PWop : power operator
134 * PMop : pattern-matching operator
135 * Aop : addition-level operator
136 * Mop : multiplication-level operator
137 * Eop : equality-testing operator
138 * Rop : relational operator <= != gt
140 * Also see LOP and lop() below.
143 #ifdef DEBUGGING /* Serve -DT. */
144 # define REPORT(retval) tokereport((I32)retval)
146 # define REPORT(retval) (retval)
149 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
150 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
151 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
152 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
153 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
154 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
155 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
156 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
157 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
158 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
159 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
160 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
161 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
162 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
163 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
164 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
165 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
166 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
167 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
168 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
170 /* This bit of chicanery makes a unary function followed by
171 * a parenthesis into a function with one argument, highest precedence.
172 * The UNIDOR macro is for unary functions that can be followed by the //
173 * operator (such as C<shift // 0>).
175 #define UNI2(f,x) { \
179 PL_last_uni = PL_oldbufptr; \
180 PL_last_lop_op = f; \
182 return REPORT( (int)FUNC1 ); \
184 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
186 #define UNI(f) UNI2(f,XTERM)
187 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
189 #define UNIBRACK(f) { \
192 PL_last_uni = PL_oldbufptr; \
194 return REPORT( (int)FUNC1 ); \
196 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
199 /* grandfather return to old style */
200 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
204 /* how to interpret the yylval associated with the token */
208 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
214 static struct debug_tokens { const int token, type; const char *name; }
215 const debug_tokens[] =
217 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
218 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
219 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
220 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
221 { ARROW, TOKENTYPE_NONE, "ARROW" },
222 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
223 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
224 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
225 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
226 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
227 { DO, TOKENTYPE_NONE, "DO" },
228 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
229 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
230 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
231 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
232 { ELSE, TOKENTYPE_NONE, "ELSE" },
233 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
234 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
235 { FOR, TOKENTYPE_IVAL, "FOR" },
236 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
237 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
238 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
239 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
240 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
241 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
242 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
243 { IF, TOKENTYPE_IVAL, "IF" },
244 { LABEL, TOKENTYPE_PVAL, "LABEL" },
245 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
246 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
247 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
248 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
249 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
250 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
251 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
252 { MY, TOKENTYPE_IVAL, "MY" },
253 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
254 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
255 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
256 { OROP, TOKENTYPE_IVAL, "OROP" },
257 { OROR, TOKENTYPE_NONE, "OROR" },
258 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
259 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
260 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
261 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
262 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
263 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
264 { PREINC, TOKENTYPE_NONE, "PREINC" },
265 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
266 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
267 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
268 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
269 { SUB, TOKENTYPE_NONE, "SUB" },
270 { THING, TOKENTYPE_OPVAL, "THING" },
271 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
272 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
273 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
274 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
275 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
276 { USE, TOKENTYPE_IVAL, "USE" },
277 { WHILE, TOKENTYPE_IVAL, "WHILE" },
278 { WORD, TOKENTYPE_OPVAL, "WORD" },
279 { 0, TOKENTYPE_NONE, 0 }
282 /* dump the returned token in rv, plus any optional arg in yylval */
285 S_tokereport(pTHX_ I32 rv)
288 const char *name = Nullch;
289 enum token_type type = TOKENTYPE_NONE;
290 const struct debug_tokens *p;
291 SV* const report = newSVpvn("<== ", 4);
293 for (p = debug_tokens; p->token; p++) {
294 if (p->token == (int)rv) {
301 Perl_sv_catpv(aTHX_ report, name);
302 else if ((char)rv > ' ' && (char)rv < '~')
303 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
305 Perl_sv_catpv(aTHX_ report, "EOF");
307 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
310 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
313 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
315 case TOKENTYPE_OPNUM:
316 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
317 PL_op_name[yylval.ival]);
320 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
322 case TOKENTYPE_OPVAL:
324 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
325 PL_op_name[yylval.opval->op_type]);
326 if (yylval.opval->op_type == OP_CONST) {
327 Perl_sv_catpvf(aTHX_ report, " %s",
328 SvPEEK(cSVOPx_sv(yylval.opval)));
333 Perl_sv_catpv(aTHX_ report, "(opval=null)");
336 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
342 /* print the buffer with suitable escapes */
345 S_printbuf(pTHX_ const char* fmt, const char* s)
347 SV* const tmp = newSVpvn("", 0);
348 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
357 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
358 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
362 S_ao(pTHX_ int toketype)
364 if (*PL_bufptr == '=') {
366 if (toketype == ANDAND)
367 yylval.ival = OP_ANDASSIGN;
368 else if (toketype == OROR)
369 yylval.ival = OP_ORASSIGN;
370 else if (toketype == DORDOR)
371 yylval.ival = OP_DORASSIGN;
379 * When Perl expects an operator and finds something else, no_op
380 * prints the warning. It always prints "<something> found where
381 * operator expected. It prints "Missing semicolon on previous line?"
382 * if the surprise occurs at the start of the line. "do you need to
383 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
384 * where the compiler doesn't know if foo is a method call or a function.
385 * It prints "Missing operator before end of line" if there's nothing
386 * after the missing operator, or "... before <...>" if there is something
387 * after the missing operator.
391 S_no_op(pTHX_ const char *what, char *s)
393 char * const oldbp = PL_bufptr;
394 const bool is_first = (PL_oldbufptr == PL_linestart);
400 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
401 if (ckWARN_d(WARN_SYNTAX)) {
403 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
404 "\t(Missing semicolon on previous line?)\n");
405 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
407 for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
408 if (t < PL_bufptr && isSPACE(*t))
409 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
410 "\t(Do you need to predeclare %.*s?)\n",
411 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
415 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
416 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
424 * Complain about missing quote/regexp/heredoc terminator.
425 * If it's called with (char *)NULL then it cauterizes the line buffer.
426 * If we're in a delimited string and the delimiter is a control
427 * character, it's reformatted into a two-char sequence like ^C.
432 S_missingterm(pTHX_ char *s)
437 char * const nl = strrchr(s,'\n');
443 iscntrl(PL_multi_close)
445 PL_multi_close < 32 || PL_multi_close == 127
449 tmpbuf[1] = (char)toCTRL(PL_multi_close);
454 *tmpbuf = (char)PL_multi_close;
458 q = strchr(s,'"') ? '\'' : '"';
459 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
467 Perl_deprecate(pTHX_ const char *s)
469 if (ckWARN(WARN_DEPRECATED))
470 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
474 Perl_deprecate_old(pTHX_ const char *s)
476 /* This function should NOT be called for any new deprecated warnings */
477 /* Use Perl_deprecate instead */
479 /* It is here to maintain backward compatibility with the pre-5.8 */
480 /* warnings category hierarchy. The "deprecated" category used to */
481 /* live under the "syntax" category. It is now a top-level category */
482 /* in its own right. */
484 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
485 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
486 "Use of %s is deprecated", s);
491 * Deprecate a comma-less variable list.
497 deprecate_old("comma-less variable list");
501 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
502 * utf16-to-utf8-reversed.
505 #ifdef PERL_CR_FILTER
509 register const char *s = SvPVX_const(sv);
510 register const char * const e = s + SvCUR(sv);
511 /* outer loop optimized to do nothing if there are no CR-LFs */
513 if (*s++ == '\r' && *s == '\n') {
514 /* hit a CR-LF, need to copy the rest */
515 register char *d = s - 1;
518 if (*s == '\r' && s[1] == '\n')
529 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
531 const I32 count = FILTER_READ(idx+1, sv, maxlen);
532 if (count > 0 && !maxlen)
540 * Initialize variables. Uses the Perl save_stack to save its state (for
541 * recursive calls to the parser).
545 Perl_lex_start(pTHX_ SV *line)
550 SAVEI32(PL_lex_dojoin);
551 SAVEI32(PL_lex_brackets);
552 SAVEI32(PL_lex_casemods);
553 SAVEI32(PL_lex_starts);
554 SAVEI32(PL_lex_state);
555 SAVEVPTR(PL_lex_inpat);
556 SAVEI32(PL_lex_inwhat);
557 if (PL_lex_state == LEX_KNOWNEXT) {
558 I32 toke = PL_nexttoke;
559 while (--toke >= 0) {
560 SAVEI32(PL_nexttype[toke]);
561 SAVEVPTR(PL_nextval[toke]);
563 SAVEI32(PL_nexttoke);
565 SAVECOPLINE(PL_curcop);
568 SAVEPPTR(PL_oldbufptr);
569 SAVEPPTR(PL_oldoldbufptr);
570 SAVEPPTR(PL_last_lop);
571 SAVEPPTR(PL_last_uni);
572 SAVEPPTR(PL_linestart);
573 SAVESPTR(PL_linestr);
574 SAVEGENERICPV(PL_lex_brackstack);
575 SAVEGENERICPV(PL_lex_casestack);
576 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
577 SAVESPTR(PL_lex_stuff);
578 SAVEI32(PL_lex_defer);
579 SAVEI32(PL_sublex_info.sub_inwhat);
580 SAVESPTR(PL_lex_repl);
582 SAVEINT(PL_lex_expect);
584 PL_lex_state = LEX_NORMAL;
588 Newx(PL_lex_brackstack, 120, char);
589 Newx(PL_lex_casestack, 12, char);
591 *PL_lex_casestack = '\0';
594 PL_lex_stuff = Nullsv;
595 PL_lex_repl = Nullsv;
599 PL_sublex_info.sub_inwhat = 0;
601 if (SvREADONLY(PL_linestr))
602 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
603 s = SvPV_const(PL_linestr, len);
604 if (!len || s[len-1] != ';') {
605 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
606 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
607 sv_catpvn(PL_linestr, "\n;", 2);
609 SvTEMP_off(PL_linestr);
610 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
611 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
612 PL_last_lop = PL_last_uni = Nullch;
618 * Finalizer for lexing operations. Must be called when the parser is
619 * done with the lexer.
625 PL_doextract = FALSE;
630 * This subroutine has nothing to do with tilting, whether at windmills
631 * or pinball tables. Its name is short for "increment line". It
632 * increments the current line number in CopLINE(PL_curcop) and checks
633 * to see whether the line starts with a comment of the form
634 * # line 500 "foo.pm"
635 * If so, it sets the current line number and file to the values in the comment.
639 S_incline(pTHX_ char *s)
646 CopLINE_inc(PL_curcop);
649 while (SPACE_OR_TAB(*s)) s++;
650 if (strnEQ(s, "line", 4))
654 if (SPACE_OR_TAB(*s))
658 while (SPACE_OR_TAB(*s)) s++;
664 while (SPACE_OR_TAB(*s))
666 if (*s == '"' && (t = strchr(s+1, '"'))) {
671 for (t = s; !isSPACE(*t); t++) ;
674 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
676 if (*e != '\n' && *e != '\0')
677 return; /* false alarm */
683 const char * const cf = CopFILE(PL_curcop);
684 STRLEN tmplen = cf ? strlen(cf) : 0;
685 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
686 /* must copy *{"::_<(eval N)[oldfilename:L]"}
687 * to *{"::_<newfilename"} */
688 char smallbuf[256], smallbuf2[256];
689 char *tmpbuf, *tmpbuf2;
691 STRLEN tmplen = strlen(cf);
692 STRLEN tmplen2 = strlen(s);
693 if (tmplen + 3 < sizeof smallbuf)
696 Newx(tmpbuf, tmplen + 3, char);
697 if (tmplen2 + 3 < sizeof smallbuf2)
700 Newx(tmpbuf2, tmplen2 + 3, char);
701 tmpbuf[0] = tmpbuf2[0] = '_';
702 tmpbuf[1] = tmpbuf2[1] = '<';
703 memcpy(tmpbuf + 2, cf, ++tmplen);
704 memcpy(tmpbuf2 + 2, s, ++tmplen2);
706 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
708 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
710 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
711 /* adjust ${"::_<newfilename"} to store the new file name */
712 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
713 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
714 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
716 if (tmpbuf != smallbuf) Safefree(tmpbuf);
717 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
720 CopFILE_free(PL_curcop);
721 CopFILE_set(PL_curcop, s);
724 CopLINE_set(PL_curcop, atoi(n)-1);
729 * Called to gobble the appropriate amount and type of whitespace.
730 * Skips comments as well.
734 S_skipspace(pTHX_ register char *s)
736 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
737 while (s < PL_bufend && SPACE_OR_TAB(*s))
743 SSize_t oldprevlen, oldoldprevlen;
744 SSize_t oldloplen = 0, oldunilen = 0;
745 while (s < PL_bufend && isSPACE(*s)) {
746 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
751 if (s < PL_bufend && *s == '#') {
752 while (s < PL_bufend && *s != '\n')
756 if (PL_in_eval && !PL_rsfp) {
763 /* only continue to recharge the buffer if we're at the end
764 * of the buffer, we're not reading from a source filter, and
765 * we're in normal lexing mode
767 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
768 PL_lex_state == LEX_FORMLINE)
771 /* try to recharge the buffer */
772 if ((s = filter_gets(PL_linestr, PL_rsfp,
773 (prevlen = SvCUR(PL_linestr)))) == Nullch)
775 /* end of file. Add on the -p or -n magic */
778 ";}continue{print or die qq(-p destination: $!\\n);}");
779 PL_minus_n = PL_minus_p = 0;
781 else if (PL_minus_n) {
782 sv_setpvn(PL_linestr, ";}", 2);
786 sv_setpvn(PL_linestr,";", 1);
788 /* reset variables for next time we lex */
789 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
791 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
792 PL_last_lop = PL_last_uni = Nullch;
794 /* Close the filehandle. Could be from -P preprocessor,
795 * STDIN, or a regular file. If we were reading code from
796 * STDIN (because the commandline held no -e or filename)
797 * then we don't close it, we reset it so the code can
798 * read from STDIN too.
801 if (PL_preprocess && !PL_in_eval)
802 (void)PerlProc_pclose(PL_rsfp);
803 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
804 PerlIO_clearerr(PL_rsfp);
806 (void)PerlIO_close(PL_rsfp);
811 /* not at end of file, so we only read another line */
812 /* make corresponding updates to old pointers, for yyerror() */
813 oldprevlen = PL_oldbufptr - PL_bufend;
814 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
816 oldunilen = PL_last_uni - PL_bufend;
818 oldloplen = PL_last_lop - PL_bufend;
819 PL_linestart = PL_bufptr = s + prevlen;
820 PL_bufend = s + SvCUR(PL_linestr);
822 PL_oldbufptr = s + oldprevlen;
823 PL_oldoldbufptr = s + oldoldprevlen;
825 PL_last_uni = s + oldunilen;
827 PL_last_lop = s + oldloplen;
830 /* debugger active and we're not compiling the debugger code,
831 * so store the line into the debugger's array of lines
833 if (PERLDB_LINE && PL_curstash != PL_debstash) {
834 SV * const sv = NEWSV(85,0);
836 sv_upgrade(sv, SVt_PVMG);
837 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
840 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
847 * Check the unary operators to ensure there's no ambiguity in how they're
848 * used. An ambiguous piece of code would be:
850 * This doesn't mean rand() + 5. Because rand() is a unary operator,
851 * the +5 is its argument.
860 if (PL_oldoldbufptr != PL_last_uni)
862 while (isSPACE(*PL_last_uni))
864 for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
865 if ((t = strchr(s, '(')) && t < PL_bufptr)
867 if (ckWARN_d(WARN_AMBIGUOUS)){
870 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
871 "Warning: Use of \"%s\" without parentheses is ambiguous",
878 * LOP : macro to build a list operator. Its behaviour has been replaced
879 * with a subroutine, S_lop() for which LOP is just another name.
882 #define LOP(f,x) return lop(f,x,s)
886 * Build a list operator (or something that might be one). The rules:
887 * - if we have a next token, then it's a list operator [why?]
888 * - if the next thing is an opening paren, then it's a function
889 * - else it's a list operator
893 S_lop(pTHX_ I32 f, int x, char *s)
899 PL_last_lop = PL_oldbufptr;
900 PL_last_lop_op = (OPCODE)f;
902 return REPORT(LSTOP);
909 return REPORT(LSTOP);
914 * When the lexer realizes it knows the next token (for instance,
915 * it is reordering tokens for the parser) then it can call S_force_next
916 * to know what token to return the next time the lexer is called. Caller
917 * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer
918 * handles the token correctly.
922 S_force_next(pTHX_ I32 type)
924 PL_nexttype[PL_nexttoke] = type;
926 if (PL_lex_state != LEX_KNOWNEXT) {
927 PL_lex_defer = PL_lex_state;
928 PL_lex_expect = PL_expect;
929 PL_lex_state = LEX_KNOWNEXT;
934 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
936 SV * const sv = newSVpvn(start,len);
937 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
944 * When the lexer knows the next thing is a word (for instance, it has
945 * just seen -> and it knows that the next char is a word char, then
946 * it calls S_force_word to stick the next word into the PL_next lookahead.
949 * char *start : buffer position (must be within PL_linestr)
950 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
951 * int check_keyword : if true, Perl checks to make sure the word isn't
952 * a keyword (do this if the word is a label, e.g. goto FOO)
953 * int allow_pack : if true, : characters will also be allowed (require,
955 * int allow_initial_tick : used by the "sub" lexer only.
959 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
964 start = skipspace(start);
966 if (isIDFIRST_lazy_if(s,UTF) ||
967 (allow_pack && *s == ':') ||
968 (allow_initial_tick && *s == '\'') )
970 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
971 if (check_keyword && keyword(PL_tokenbuf, len))
973 if (token == METHOD) {
978 PL_expect = XOPERATOR;
981 PL_nextval[PL_nexttoke].opval
982 = (OP*)newSVOP(OP_CONST,0,
983 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
984 PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
992 * Called when the lexer wants $foo *foo &foo etc, but the program
993 * text only contains the "foo" portion. The first argument is a pointer
994 * to the "foo", and the second argument is the type symbol to prefix.
995 * Forces the next token to be a "WORD".
996 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1000 S_force_ident(pTHX_ register const char *s, int kind)
1003 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
1004 PL_nextval[PL_nexttoke].opval = o;
1007 o->op_private = OPpCONST_ENTERED;
1008 /* XXX see note in pp_entereval() for why we forgo typo
1009 warnings if the symbol must be introduced in an eval.
1011 gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
1012 kind == '$' ? SVt_PV :
1013 kind == '@' ? SVt_PVAV :
1014 kind == '%' ? SVt_PVHV :
1022 Perl_str_to_version(pTHX_ SV *sv)
1027 const char *start = SvPV_const(sv,len);
1028 const char * const end = start + len;
1029 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1030 while (start < end) {
1034 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1039 retval += ((NV)n)/nshift;
1048 * Forces the next token to be a version number.
1049 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1050 * and if "guessing" is TRUE, then no new token is created (and the caller
1051 * must use an alternative parsing method).
1055 S_force_version(pTHX_ char *s, int guessing)
1057 OP *version = Nullop;
1066 while (isDIGIT(*d) || *d == '_' || *d == '.')
1068 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1070 s = scan_num(s, &yylval);
1071 version = yylval.opval;
1072 ver = cSVOPx(version)->op_sv;
1073 if (SvPOK(ver) && !SvNIOK(ver)) {
1074 SvUPGRADE(ver, SVt_PVNV);
1075 SvNV_set(ver, str_to_version(ver));
1076 SvNOK_on(ver); /* hint that it is a version */
1083 /* NOTE: The parser sees the package name and the VERSION swapped */
1084 PL_nextval[PL_nexttoke].opval = version;
1092 * Tokenize a quoted string passed in as an SV. It finds the next
1093 * chunk, up to end of string or a backslash. It may make a new
1094 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1099 S_tokeq(pTHX_ SV *sv)
1102 register char *send;
1110 s = SvPV_force(sv, len);
1111 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1114 while (s < send && *s != '\\')
1119 if ( PL_hints & HINT_NEW_STRING ) {
1120 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1126 if (s + 1 < send && (s[1] == '\\'))
1127 s++; /* all that, just for this */
1132 SvCUR_set(sv, d - SvPVX_const(sv));
1134 if ( PL_hints & HINT_NEW_STRING )
1135 return new_constant(NULL, 0, "q", sv, pv, "q");
1140 * Now come three functions related to double-quote context,
1141 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1142 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1143 * interact with PL_lex_state, and create fake ( ... ) argument lists
1144 * to handle functions and concatenation.
1145 * They assume that whoever calls them will be setting up a fake
1146 * join call, because each subthing puts a ',' after it. This lets
1149 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1151 * (I'm not sure whether the spurious commas at the end of lcfirst's
1152 * arguments and join's arguments are created or not).
1157 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1159 * Pattern matching will set PL_lex_op to the pattern-matching op to
1160 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1162 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1164 * Everything else becomes a FUNC.
1166 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1167 * had an OP_CONST or OP_READLINE). This just sets us up for a
1168 * call to S_sublex_push().
1172 S_sublex_start(pTHX)
1174 register const I32 op_type = yylval.ival;
1176 if (op_type == OP_NULL) {
1177 yylval.opval = PL_lex_op;
1181 if (op_type == OP_CONST || op_type == OP_READLINE) {
1182 SV *sv = tokeq(PL_lex_stuff);
1184 if (SvTYPE(sv) == SVt_PVIV) {
1185 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1187 const char *p = SvPV_const(sv, len);
1188 SV * const nsv = newSVpvn(p, len);
1194 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1195 PL_lex_stuff = Nullsv;
1196 /* Allow <FH> // "foo" */
1197 if (op_type == OP_READLINE)
1198 PL_expect = XTERMORDORDOR;
1202 PL_sublex_info.super_state = PL_lex_state;
1203 PL_sublex_info.sub_inwhat = op_type;
1204 PL_sublex_info.sub_op = PL_lex_op;
1205 PL_lex_state = LEX_INTERPPUSH;
1209 yylval.opval = PL_lex_op;
1219 * Create a new scope to save the lexing state. The scope will be
1220 * ended in S_sublex_done. Returns a '(', starting the function arguments
1221 * to the uc, lc, etc. found before.
1222 * Sets PL_lex_state to LEX_INTERPCONCAT.
1231 PL_lex_state = PL_sublex_info.super_state;
1232 SAVEI32(PL_lex_dojoin);
1233 SAVEI32(PL_lex_brackets);
1234 SAVEI32(PL_lex_casemods);
1235 SAVEI32(PL_lex_starts);
1236 SAVEI32(PL_lex_state);
1237 SAVEVPTR(PL_lex_inpat);
1238 SAVEI32(PL_lex_inwhat);
1239 SAVECOPLINE(PL_curcop);
1240 SAVEPPTR(PL_bufptr);
1241 SAVEPPTR(PL_bufend);
1242 SAVEPPTR(PL_oldbufptr);
1243 SAVEPPTR(PL_oldoldbufptr);
1244 SAVEPPTR(PL_last_lop);
1245 SAVEPPTR(PL_last_uni);
1246 SAVEPPTR(PL_linestart);
1247 SAVESPTR(PL_linestr);
1248 SAVEGENERICPV(PL_lex_brackstack);
1249 SAVEGENERICPV(PL_lex_casestack);
1251 PL_linestr = PL_lex_stuff;
1252 PL_lex_stuff = Nullsv;
1254 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1255 = SvPVX(PL_linestr);
1256 PL_bufend += SvCUR(PL_linestr);
1257 PL_last_lop = PL_last_uni = Nullch;
1258 SAVEFREESV(PL_linestr);
1260 PL_lex_dojoin = FALSE;
1261 PL_lex_brackets = 0;
1262 Newx(PL_lex_brackstack, 120, char);
1263 Newx(PL_lex_casestack, 12, char);
1264 PL_lex_casemods = 0;
1265 *PL_lex_casestack = '\0';
1267 PL_lex_state = LEX_INTERPCONCAT;
1268 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1270 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1271 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1272 PL_lex_inpat = PL_sublex_info.sub_op;
1274 PL_lex_inpat = Nullop;
1281 * Restores lexer state after a S_sublex_push.
1288 if (!PL_lex_starts++) {
1289 SV * const sv = newSVpvn("",0);
1290 if (SvUTF8(PL_linestr))
1292 PL_expect = XOPERATOR;
1293 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1297 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1298 PL_lex_state = LEX_INTERPCASEMOD;
1302 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1303 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1304 PL_linestr = PL_lex_repl;
1306 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1307 PL_bufend += SvCUR(PL_linestr);
1308 PL_last_lop = PL_last_uni = Nullch;
1309 SAVEFREESV(PL_linestr);
1310 PL_lex_dojoin = FALSE;
1311 PL_lex_brackets = 0;
1312 PL_lex_casemods = 0;
1313 *PL_lex_casestack = '\0';
1315 if (SvEVALED(PL_lex_repl)) {
1316 PL_lex_state = LEX_INTERPNORMAL;
1318 /* we don't clear PL_lex_repl here, so that we can check later
1319 whether this is an evalled subst; that means we rely on the
1320 logic to ensure sublex_done() is called again only via the
1321 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1324 PL_lex_state = LEX_INTERPCONCAT;
1325 PL_lex_repl = Nullsv;
1331 PL_bufend = SvPVX(PL_linestr);
1332 PL_bufend += SvCUR(PL_linestr);
1333 PL_expect = XOPERATOR;
1334 PL_sublex_info.sub_inwhat = 0;
1342 Extracts a pattern, double-quoted string, or transliteration. This
1345 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1346 processing a pattern (PL_lex_inpat is true), a transliteration
1347 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1349 Returns a pointer to the character scanned up to. Iff this is
1350 advanced from the start pointer supplied (ie if anything was
1351 successfully parsed), will leave an OP for the substring scanned
1352 in yylval. Caller must intuit reason for not parsing further
1353 by looking at the next characters herself.
1357 double-quoted style: \r and \n
1358 regexp special ones: \D \s
1360 backrefs: \1 (deprecated in substitution replacements)
1361 case and quoting: \U \Q \E
1362 stops on @ and $, but not for $ as tail anchor
1364 In transliterations:
1365 characters are VERY literal, except for - not at the start or end
1366 of the string, which indicates a range. scan_const expands the
1367 range to the full set of intermediate characters.
1369 In double-quoted strings:
1371 double-quoted style: \r and \n
1373 backrefs: \1 (deprecated)
1374 case and quoting: \U \Q \E
1377 scan_const does *not* construct ops to handle interpolated strings.
1378 It stops processing as soon as it finds an embedded $ or @ variable
1379 and leaves it to the caller to work out what's going on.
1381 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo.
1383 $ in pattern could be $foo or could be tail anchor. Assumption:
1384 it's a tail anchor if $ is the last thing in the string, or if it's
1385 followed by one of ")| \n\t"
1387 \1 (backreferences) are turned into $1
1389 The structure of the code is
1390 while (there's a character to process) {
1391 handle transliteration ranges
1392 skip regexp comments
1393 skip # initiated comments in //x patterns
1394 check for embedded @foo
1395 check for embedded scalars
1397 leave intact backslashes from leave (below)
1398 deprecate \1 in strings and sub replacements
1399 handle string-changing backslashes \l \U \Q \E, etc.
1400 switch (what was escaped) {
1401 handle - in a transliteration (becomes a literal -)
1402 handle \132 octal characters
1403 handle 0x15 hex characters
1404 handle \cV (control V)
1405 handle printf backslashes (\f, \r, \n, etc)
1407 } (end if backslash)
1408 } (end while character to read)
1413 S_scan_const(pTHX_ char *start)
1415 register char *send = PL_bufend; /* end of the constant */
1416 SV *sv = NEWSV(93, send - start); /* sv for the constant */
1417 register char *s = start; /* start of the constant */
1418 register char *d = SvPVX(sv); /* destination for copies */
1419 bool dorange = FALSE; /* are we in a translit range? */
1420 bool didrange = FALSE; /* did we just finish a range? */
1421 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1422 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1425 UV literal_endpoint = 0;
1428 const char *leaveit = /* set of acceptably-backslashed characters */
1430 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#"
1433 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1434 /* If we are doing a trans and we know we want UTF8 set expectation */
1435 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1436 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1440 while (s < send || dorange) {
1441 /* get transliterations out of the way (they're most literal) */
1442 if (PL_lex_inwhat == OP_TRANS) {
1443 /* expand a range A-Z to the full set of characters. AIE! */
1445 I32 i; /* current expanded character */
1446 I32 min; /* first character in range */
1447 I32 max; /* last character in range */
1450 char * const c = (char*)utf8_hop((U8*)d, -1);
1454 *c = (char)UTF_TO_NATIVE(0xff);
1455 /* mark the range as done, and continue */
1461 i = d - SvPVX_const(sv); /* remember current offset */
1462 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1463 d = SvPVX(sv) + i; /* refresh d after realloc */
1464 d -= 2; /* eat the first char and the - */
1466 min = (U8)*d; /* first char in range */
1467 max = (U8)d[1]; /* last char in range */
1471 "Invalid range \"%c-%c\" in transliteration operator",
1472 (char)min, (char)max);
1476 if (literal_endpoint == 2 &&
1477 ((isLOWER(min) && isLOWER(max)) ||
1478 (isUPPER(min) && isUPPER(max)))) {
1480 for (i = min; i <= max; i++)
1482 *d++ = NATIVE_TO_NEED(has_utf8,i);
1484 for (i = min; i <= max; i++)
1486 *d++ = NATIVE_TO_NEED(has_utf8,i);
1491 for (i = min; i <= max; i++)
1494 /* mark the range as done, and continue */
1498 literal_endpoint = 0;
1503 /* range begins (ignore - as first or last char) */
1504 else if (*s == '-' && s+1 < send && s != start) {
1506 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1509 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1519 literal_endpoint = 0;
1524 /* if we get here, we're not doing a transliteration */
1526 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1527 except for the last char, which will be done separately. */
1528 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1530 while (s+1 < send && *s != ')')
1531 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1533 else if (s[2] == '{' /* This should match regcomp.c */
1534 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1537 char *regparse = s + (s[2] == '{' ? 3 : 4);
1540 while (count && (c = *regparse)) {
1541 if (c == '\\' && regparse[1])
1549 if (*regparse != ')')
1550 regparse--; /* Leave one char for continuation. */
1551 while (s < regparse)
1552 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1556 /* likewise skip #-initiated comments in //x patterns */
1557 else if (*s == '#' && PL_lex_inpat &&
1558 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1559 while (s+1 < send && *s != '\n')
1560 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1563 /* check for embedded arrays
1564 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1566 else if (*s == '@' && s[1]
1567 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1570 /* check for embedded scalars. only stop if we're sure it's a
1573 else if (*s == '$') {
1574 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1576 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1577 break; /* in regexp, $ might be tail anchor */
1580 /* End of else if chain - OP_TRANS rejoin rest */
1583 if (*s == '\\' && s+1 < send) {
1586 /* some backslashes we leave behind */
1587 if (*leaveit && *s && strchr(leaveit, *s)) {
1588 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1589 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1593 /* deprecate \1 in strings and substitution replacements */
1594 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1595 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1597 if (ckWARN(WARN_SYNTAX))
1598 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
1603 /* string-change backslash escapes */
1604 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1609 /* if we get here, it's either a quoted -, or a digit */
1612 /* quoted - in transliterations */
1614 if (PL_lex_inwhat == OP_TRANS) {
1624 Perl_warner(aTHX_ packWARN(WARN_MISC),
1625 "Unrecognized escape \\%c passed through",
1627 /* default action is to copy the quoted character */
1628 goto default_action;
1631 /* \132 indicates an octal constant */
1632 case '0': case '1': case '2': case '3':
1633 case '4': case '5': case '6': case '7':
1637 uv = grok_oct(s, &len, &flags, NULL);
1640 goto NUM_ESCAPE_INSERT;
1642 /* \x24 indicates a hex constant */
1646 char* const e = strchr(s, '}');
1647 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1648 PERL_SCAN_DISALLOW_PREFIX;
1653 yyerror("Missing right brace on \\x{}");
1657 uv = grok_hex(s, &len, &flags, NULL);
1663 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
1664 uv = grok_hex(s, &len, &flags, NULL);
1670 /* Insert oct or hex escaped character.
1671 * There will always enough room in sv since such
1672 * escapes will be longer than any UTF-8 sequence
1673 * they can end up as. */
1675 /* We need to map to chars to ASCII before doing the tests
1678 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
1679 if (!has_utf8 && uv > 255) {
1680 /* Might need to recode whatever we have
1681 * accumulated so far if it contains any
1684 * (Can't we keep track of that and avoid
1685 * this rescan? --jhi)
1689 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
1690 if (!NATIVE_IS_INVARIANT(*c)) {
1695 const STRLEN offset = d - SvPVX_const(sv);
1697 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
1701 while (src >= (const U8 *)SvPVX_const(sv)) {
1702 if (!NATIVE_IS_INVARIANT(*src)) {
1703 const U8 ch = NATIVE_TO_ASCII(*src);
1704 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
1705 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
1715 if (has_utf8 || uv > 255) {
1716 d = (char*)uvchr_to_utf8((U8*)d, uv);
1718 if (PL_lex_inwhat == OP_TRANS &&
1719 PL_sublex_info.sub_op) {
1720 PL_sublex_info.sub_op->op_private |=
1721 (PL_lex_repl ? OPpTRANS_FROM_UTF
1734 /* \N{LATIN SMALL LETTER A} is a named character */
1738 char* e = strchr(s, '}');
1744 yyerror("Missing right brace on \\N{}");
1748 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
1750 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1751 PERL_SCAN_DISALLOW_PREFIX;
1754 uv = grok_hex(s, &len, &flags, NULL);
1756 goto NUM_ESCAPE_INSERT;
1758 res = newSVpvn(s + 1, e - s - 1);
1759 res = new_constant( Nullch, 0, "charnames",
1760 res, Nullsv, "\\N{...}" );
1762 sv_utf8_upgrade(res);
1763 str = SvPV_const(res,len);
1764 #ifdef EBCDIC_NEVER_MIND
1765 /* charnames uses pack U and that has been
1766 * recently changed to do the below uni->native
1767 * mapping, so this would be redundant (and wrong,
1768 * the code point would be doubly converted).
1769 * But leave this in just in case the pack U change
1770 * gets revoked, but the semantics is still
1771 * desireable for charnames. --jhi */
1773 UV uv = utf8_to_uvchr((const U8*)str, 0);
1776 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
1778 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
1779 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
1780 str = SvPV_const(res, len);
1784 if (!has_utf8 && SvUTF8(res)) {
1785 const char * const ostart = SvPVX_const(sv);
1786 SvCUR_set(sv, d - ostart);
1789 sv_utf8_upgrade(sv);
1790 /* this just broke our allocation above... */
1791 SvGROW(sv, (STRLEN)(send - start));
1792 d = SvPVX(sv) + SvCUR(sv);
1795 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
1796 const char * const odest = SvPVX_const(sv);
1798 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
1799 d = SvPVX(sv) + (d - odest);
1801 Copy(str, d, len, char);
1808 yyerror("Missing braces on \\N{}");
1811 /* \c is a control character */
1820 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
1823 yyerror("Missing control char name in \\c");
1827 /* printf-style backslashes, formfeeds, newlines, etc */
1829 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
1832 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
1835 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
1838 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
1841 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
1844 *d++ = ASCII_TO_NEED(has_utf8,'\033');
1847 *d++ = ASCII_TO_NEED(has_utf8,'\007');
1853 } /* end if (backslash) */
1860 /* If we started with encoded form, or already know we want it
1861 and then encode the next character */
1862 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
1864 const UV uv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
1865 const STRLEN need = UNISKIP(NATIVE_TO_UNI(uv));
1868 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
1869 const STRLEN off = d - SvPVX_const(sv);
1870 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
1872 d = (char*)uvchr_to_utf8((U8*)d, uv);
1876 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1878 } /* while loop to process each character */
1880 /* terminate the string and set up the sv */
1882 SvCUR_set(sv, d - SvPVX_const(sv));
1883 if (SvCUR(sv) >= SvLEN(sv))
1884 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
1887 if (PL_encoding && !has_utf8) {
1888 sv_recode_to_utf8(sv, PL_encoding);
1894 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1895 PL_sublex_info.sub_op->op_private |=
1896 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1900 /* shrink the sv if we allocated more than we used */
1901 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1902 SvPV_shrink_to_cur(sv);
1905 /* return the substring (via yylval) only if we parsed anything */
1906 if (s > PL_bufptr) {
1907 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1908 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1910 ( PL_lex_inwhat == OP_TRANS
1912 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1915 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1922 * Returns TRUE if there's more to the expression (e.g., a subscript),
1925 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
1927 * ->[ and ->{ return TRUE
1928 * { and [ outside a pattern are always subscripts, so return TRUE
1929 * if we're outside a pattern and it's not { or [, then return FALSE
1930 * if we're in a pattern and the first char is a {
1931 * {4,5} (any digits around the comma) returns FALSE
1932 * if we're in a pattern and the first char is a [
1934 * [SOMETHING] has a funky algorithm to decide whether it's a
1935 * character class or not. It has to deal with things like
1936 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
1937 * anything else returns TRUE
1940 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1943 S_intuit_more(pTHX_ register char *s)
1945 if (PL_lex_brackets)
1947 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1949 if (*s != '{' && *s != '[')
1954 /* In a pattern, so maybe we have {n,m}. */
1971 /* On the other hand, maybe we have a character class */
1974 if (*s == ']' || *s == '^')
1977 /* this is terrifying, and it works */
1978 int weight = 2; /* let's weigh the evidence */
1980 unsigned char un_char = 255, last_un_char;
1981 const char * const send = strchr(s,']');
1982 char tmpbuf[sizeof PL_tokenbuf * 4];
1984 if (!send) /* has to be an expression */
1987 Zero(seen,256,char);
1990 else if (isDIGIT(*s)) {
1992 if (isDIGIT(s[1]) && s[2] == ']')
1998 for (; s < send; s++) {
1999 last_un_char = un_char;
2000 un_char = (unsigned char)*s;
2005 weight -= seen[un_char] * 10;
2006 if (isALNUM_lazy_if(s+1,UTF)) {
2007 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2008 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
2013 else if (*s == '$' && s[1] &&
2014 strchr("[#!%*<>()-=",s[1])) {
2015 if (/*{*/ strchr("])} =",s[2]))
2024 if (strchr("wds]",s[1]))
2026 else if (seen['\''] || seen['"'])
2028 else if (strchr("rnftbxcav",s[1]))
2030 else if (isDIGIT(s[1])) {
2032 while (s[1] && isDIGIT(s[1]))
2042 if (strchr("aA01! ",last_un_char))
2044 if (strchr("zZ79~",s[1]))
2046 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2047 weight -= 5; /* cope with negative subscript */
2050 if (!isALNUM(last_un_char)
2051 && !(last_un_char == '$' || last_un_char == '@'
2052 || last_un_char == '&')
2053 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2058 if (keyword(tmpbuf, d - tmpbuf))
2061 if (un_char == last_un_char + 1)
2063 weight -= seen[un_char];
2068 if (weight >= 0) /* probably a character class */
2078 * Does all the checking to disambiguate
2080 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2081 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2083 * First argument is the stuff after the first token, e.g. "bar".
2085 * Not a method if bar is a filehandle.
2086 * Not a method if foo is a subroutine prototyped to take a filehandle.
2087 * Not a method if it's really "Foo $bar"
2088 * Method if it's "foo $bar"
2089 * Not a method if it's really "print foo $bar"
2090 * Method if it's really "foo package::" (interpreted as package->foo)
2091 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2092 * Not a method if bar is a filehandle or package, but is quoted with
2097 S_intuit_method(pTHX_ char *start, GV *gv)
2099 char *s = start + (*start == '$');
2100 char tmpbuf[sizeof PL_tokenbuf];
2108 if ((cv = GvCVu(gv))) {
2109 const char *proto = SvPVX_const(cv);
2119 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2120 /* start is the beginning of the possible filehandle/object,
2121 * and s is the end of it
2122 * tmpbuf is a copy of it
2125 if (*start == '$') {
2126 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2131 return *s == '(' ? FUNCMETH : METHOD;
2133 if (!keyword(tmpbuf, len)) {
2134 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2139 indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2140 if (indirgv && GvCVu(indirgv))
2142 /* filehandle or package name makes it a method */
2143 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2145 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2146 return 0; /* no assumptions -- "=>" quotes bearword */
2148 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
2149 newSVpvn(tmpbuf,len));
2150 PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
2154 return *s == '(' ? FUNCMETH : METHOD;
2162 * Return a string of Perl code to load the debugger. If PERL5DB
2163 * is set, it will return the contents of that, otherwise a
2164 * compile-time require of perl5db.pl.
2171 const char * const pdb = PerlEnv_getenv("PERL5DB");
2175 SETERRNO(0,SS_NORMAL);
2176 return "BEGIN { require 'perl5db.pl' }";
2182 /* Encoded script support. filter_add() effectively inserts a
2183 * 'pre-processing' function into the current source input stream.
2184 * Note that the filter function only applies to the current source file
2185 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2187 * The datasv parameter (which may be NULL) can be used to pass
2188 * private data to this instance of the filter. The filter function
2189 * can recover the SV using the FILTER_DATA macro and use it to
2190 * store private buffers and state information.
2192 * The supplied datasv parameter is upgraded to a PVIO type
2193 * and the IoDIRP/IoANY field is used to store the function pointer,
2194 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2195 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2196 * private use must be set using malloc'd pointers.
2200 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2205 if (!PL_rsfp_filters)
2206 PL_rsfp_filters = newAV();
2208 datasv = NEWSV(255,0);
2209 SvUPGRADE(datasv, SVt_PVIO);
2210 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2211 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2212 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2213 IoANY(datasv), SvPV_nolen(datasv)));
2214 av_unshift(PL_rsfp_filters, 1);
2215 av_store(PL_rsfp_filters, 0, datasv) ;
2220 /* Delete most recently added instance of this filter function. */
2222 Perl_filter_del(pTHX_ filter_t funcp)
2227 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", FPTR2DPTR(XPVIO *, funcp)));
2229 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2231 /* if filter is on top of stack (usual case) just pop it off */
2232 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2233 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2234 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2235 IoANY(datasv) = (void *)NULL;
2236 sv_free(av_pop(PL_rsfp_filters));
2240 /* we need to search for the correct entry and clear it */
2241 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2245 /* Invoke the idxth filter function for the current rsfp. */
2246 /* maxlen 0 = read one text line */
2248 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2253 if (!PL_rsfp_filters)
2255 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2256 /* Provide a default input filter to make life easy. */
2257 /* Note that we append to the line. This is handy. */
2258 DEBUG_P(PerlIO_printf(Perl_debug_log,
2259 "filter_read %d: from rsfp\n", idx));
2263 const int old_len = SvCUR(buf_sv);
2265 /* ensure buf_sv is large enough */
2266 SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ;
2267 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
2268 if (PerlIO_error(PL_rsfp))
2269 return -1; /* error */
2271 return 0 ; /* end of file */
2273 SvCUR_set(buf_sv, old_len + len) ;
2276 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2277 if (PerlIO_error(PL_rsfp))
2278 return -1; /* error */
2280 return 0 ; /* end of file */
2283 return SvCUR(buf_sv);
2285 /* Skip this filter slot if filter has been deleted */
2286 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2287 DEBUG_P(PerlIO_printf(Perl_debug_log,
2288 "filter_read %d: skipped (filter deleted)\n",
2290 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
2292 /* Get function pointer hidden within datasv */
2293 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2294 DEBUG_P(PerlIO_printf(Perl_debug_log,
2295 "filter_read %d: via function %p (%s)\n",
2296 idx, datasv, SvPV_nolen_const(datasv)));
2297 /* Call function. The function is expected to */
2298 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2299 /* Return: <0:error, =0:eof, >0:not eof */
2300 return (*funcp)(aTHX_ idx, buf_sv, maxlen);
2304 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2306 #ifdef PERL_CR_FILTER
2307 if (!PL_rsfp_filters) {
2308 filter_add(S_cr_textfilter,NULL);
2311 if (PL_rsfp_filters) {
2313 SvCUR_set(sv, 0); /* start with empty line */
2314 if (FILTER_READ(0, sv, 0) > 0)
2315 return ( SvPVX(sv) ) ;
2320 return (sv_gets(sv, fp, append));
2324 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2328 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2332 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2333 (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV)))
2335 return GvHV(gv); /* Foo:: */
2338 /* use constant CLASS => 'MyClass' */
2339 if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) {
2341 if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2342 pkgname = SvPV_nolen_const(sv);
2346 return gv_stashpv(pkgname, FALSE);
2350 S_tokenize_use(pTHX_ int is_use, char *s) {
2351 if (PL_expect != XSTATE)
2352 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
2353 is_use ? "use" : "no"));
2355 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
2356 s = force_version(s, TRUE);
2357 if (*s == ';' || (s = skipspace(s), *s == ';')) {
2358 PL_nextval[PL_nexttoke].opval = Nullop;
2361 else if (*s == 'v') {
2362 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2363 s = force_version(s, FALSE);
2367 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2368 s = force_version(s, FALSE);
2370 yylval.ival = is_use;
2374 static const char* const exp_name[] =
2375 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2376 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
2383 Works out what to call the token just pulled out of the input
2384 stream. The yacc parser takes care of taking the ops we return and
2385 stitching them into a tree.
2391 if read an identifier
2392 if we're in a my declaration
2393 croak if they tried to say my($foo::bar)
2394 build the ops for a my() declaration
2395 if it's an access to a my() variable
2396 are we in a sort block?
2397 croak if my($a); $a <=> $b
2398 build ops for access to a my() variable
2399 if in a dq string, and they've said @foo and we can't find @foo
2401 build ops for a bareword
2402 if we already built the token before, use it.
2407 #pragma segment Perl_yylex
2412 register char *s = PL_bufptr;
2419 I32 orig_keyword = 0;
2422 SV* tmp = newSVpvn("", 0);
2423 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
2424 (IV)CopLINE(PL_curcop),
2425 lex_state_names[PL_lex_state],
2426 exp_name[PL_expect],
2427 pv_display(tmp, s, strlen(s), 0, 60));
2430 /* check if there's an identifier for us to look at */
2431 if (PL_pending_ident)
2432 return REPORT(S_pending_ident(aTHX));
2434 /* no identifier pending identification */
2436 switch (PL_lex_state) {
2438 case LEX_NORMAL: /* Some compilers will produce faster */
2439 case LEX_INTERPNORMAL: /* code if we comment these out. */
2443 /* when we've already built the next token, just pull it out of the queue */
2446 yylval = PL_nextval[PL_nexttoke];
2448 PL_lex_state = PL_lex_defer;
2449 PL_expect = PL_lex_expect;
2450 PL_lex_defer = LEX_NORMAL;
2452 return REPORT(PL_nexttype[PL_nexttoke]);
2454 /* interpolated case modifiers like \L \U, including \Q and \E.
2455 when we get here, PL_bufptr is at the \
2457 case LEX_INTERPCASEMOD:
2459 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2460 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2462 /* handle \E or end of string */
2463 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2465 if (PL_lex_casemods) {
2466 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
2467 PL_lex_casestack[PL_lex_casemods] = '\0';
2469 if (PL_bufptr != PL_bufend
2470 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
2472 PL_lex_state = LEX_INTERPCONCAT;
2476 if (PL_bufptr != PL_bufend)
2478 PL_lex_state = LEX_INTERPCONCAT;
2482 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2483 "### Saw case modifier\n"); });
2485 if (s[1] == '\\' && s[2] == 'E') {
2487 PL_lex_state = LEX_INTERPCONCAT;
2491 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2492 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
2493 if ((*s == 'L' || *s == 'U') &&
2494 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
2495 PL_lex_casestack[--PL_lex_casemods] = '\0';
2498 if (PL_lex_casemods > 10)
2499 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2500 PL_lex_casestack[PL_lex_casemods++] = *s;
2501 PL_lex_casestack[PL_lex_casemods] = '\0';
2502 PL_lex_state = LEX_INTERPCONCAT;
2503 PL_nextval[PL_nexttoke].ival = 0;
2506 PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2508 PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2510 PL_nextval[PL_nexttoke].ival = OP_LC;
2512 PL_nextval[PL_nexttoke].ival = OP_UC;
2514 PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2516 Perl_croak(aTHX_ "panic: yylex");
2520 if (PL_lex_starts) {
2523 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2524 if (PL_lex_casemods == 1 && PL_lex_inpat)
2533 case LEX_INTERPPUSH:
2534 return REPORT(sublex_push());
2536 case LEX_INTERPSTART:
2537 if (PL_bufptr == PL_bufend)
2538 return REPORT(sublex_done());
2539 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2540 "### Interpolated variable\n"); });
2542 PL_lex_dojoin = (*PL_bufptr == '@');
2543 PL_lex_state = LEX_INTERPNORMAL;
2544 if (PL_lex_dojoin) {
2545 PL_nextval[PL_nexttoke].ival = 0;
2547 force_ident("\"", '$');
2548 PL_nextval[PL_nexttoke].ival = 0;
2550 PL_nextval[PL_nexttoke].ival = 0;
2552 PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
2555 if (PL_lex_starts++) {
2557 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2558 if (!PL_lex_casemods && PL_lex_inpat)
2565 case LEX_INTERPENDMAYBE:
2566 if (intuit_more(PL_bufptr)) {
2567 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
2573 if (PL_lex_dojoin) {
2574 PL_lex_dojoin = FALSE;
2575 PL_lex_state = LEX_INTERPCONCAT;
2578 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2579 && SvEVALED(PL_lex_repl))
2581 if (PL_bufptr != PL_bufend)
2582 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2583 PL_lex_repl = Nullsv;
2586 case LEX_INTERPCONCAT:
2588 if (PL_lex_brackets)
2589 Perl_croak(aTHX_ "panic: INTERPCONCAT");
2591 if (PL_bufptr == PL_bufend)
2592 return REPORT(sublex_done());
2594 if (SvIVX(PL_linestr) == '\'') {
2595 SV *sv = newSVsv(PL_linestr);
2598 else if ( PL_hints & HINT_NEW_RE )
2599 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2600 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2604 s = scan_const(PL_bufptr);
2606 PL_lex_state = LEX_INTERPCASEMOD;
2608 PL_lex_state = LEX_INTERPSTART;
2611 if (s != PL_bufptr) {
2612 PL_nextval[PL_nexttoke] = yylval;
2615 if (PL_lex_starts++) {
2616 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2617 if (!PL_lex_casemods && PL_lex_inpat)
2630 PL_lex_state = LEX_NORMAL;
2631 s = scan_formline(PL_bufptr);
2632 if (!PL_lex_formbrack)
2638 PL_oldoldbufptr = PL_oldbufptr;
2644 if (isIDFIRST_lazy_if(s,UTF))
2646 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2649 goto fake_eof; /* emulate EOF on ^D or ^Z */
2654 if (PL_lex_brackets) {
2655 if (PL_lex_formbrack)
2656 yyerror("Format not terminated");
2658 yyerror("Missing right curly or square bracket");
2660 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2661 "### Tokener got EOF\n");
2665 if (s++ < PL_bufend)
2666 goto retry; /* ignore stray nulls */
2669 if (!PL_in_eval && !PL_preambled) {
2670 PL_preambled = TRUE;
2671 sv_setpv(PL_linestr,incl_perldb());
2672 if (SvCUR(PL_linestr))
2673 sv_catpvn(PL_linestr,";", 1);
2675 while(AvFILLp(PL_preambleav) >= 0) {
2676 SV *tmpsv = av_shift(PL_preambleav);
2677 sv_catsv(PL_linestr, tmpsv);
2678 sv_catpvn(PL_linestr, ";", 1);
2681 sv_free((SV*)PL_preambleav);
2682 PL_preambleav = NULL;
2684 if (PL_minus_n || PL_minus_p) {
2685 sv_catpv(PL_linestr, "LINE: while (<>) {");
2687 sv_catpv(PL_linestr,"chomp;");
2690 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
2691 || *PL_splitstr == '"')
2692 && strchr(PL_splitstr + 1, *PL_splitstr))
2693 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
2695 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
2696 bytes can be used as quoting characters. :-) */
2697 /* The count here deliberately includes the NUL
2698 that terminates the C string constant. This
2699 embeds the opening NUL into the string. */
2700 const char *splits = PL_splitstr;
2701 sv_catpvn(PL_linestr, "our @F=split(q", 15);
2704 if (*splits == '\\')
2705 sv_catpvn(PL_linestr, splits, 1);
2706 sv_catpvn(PL_linestr, splits, 1);
2707 } while (*splits++);
2708 /* This loop will embed the trailing NUL of
2709 PL_linestr as the last thing it does before
2711 sv_catpvn(PL_linestr, ");", 2);
2715 sv_catpv(PL_linestr,"our @F=split(' ');");
2718 sv_catpvn(PL_linestr, "\n", 1);
2719 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2720 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2721 PL_last_lop = PL_last_uni = Nullch;
2722 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2723 SV * const sv = NEWSV(85,0);
2725 sv_upgrade(sv, SVt_PVMG);
2726 sv_setsv(sv,PL_linestr);
2729 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2734 bof = PL_rsfp ? TRUE : FALSE;
2735 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2738 if (PL_preprocess && !PL_in_eval)
2739 (void)PerlProc_pclose(PL_rsfp);
2740 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2741 PerlIO_clearerr(PL_rsfp);
2743 (void)PerlIO_close(PL_rsfp);
2745 PL_doextract = FALSE;
2747 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2748 sv_setpv(PL_linestr,PL_minus_p
2749 ? ";}continue{print;}" : ";}");
2750 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2751 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2752 PL_last_lop = PL_last_uni = Nullch;
2753 PL_minus_n = PL_minus_p = 0;
2756 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2757 PL_last_lop = PL_last_uni = Nullch;
2758 sv_setpvn(PL_linestr,"",0);
2759 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
2761 /* If it looks like the start of a BOM or raw UTF-16,
2762 * check if it in fact is. */
2768 #ifdef PERLIO_IS_STDIO
2769 # ifdef __GNU_LIBRARY__
2770 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
2771 # define FTELL_FOR_PIPE_IS_BROKEN
2775 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
2776 # define FTELL_FOR_PIPE_IS_BROKEN
2781 #ifdef FTELL_FOR_PIPE_IS_BROKEN
2782 /* This loses the possibility to detect the bof
2783 * situation on perl -P when the libc5 is being used.
2784 * Workaround? Maybe attach some extra state to PL_rsfp?
2787 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2789 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
2792 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2793 s = swallow_bom((U8*)s);
2797 /* Incest with pod. */
2798 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2799 sv_setpvn(PL_linestr, "", 0);
2800 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2801 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2802 PL_last_lop = PL_last_uni = Nullch;
2803 PL_doextract = FALSE;
2807 } while (PL_doextract);
2808 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2809 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2810 SV * const sv = NEWSV(85,0);
2812 sv_upgrade(sv, SVt_PVMG);
2813 sv_setsv(sv,PL_linestr);
2816 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2818 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2819 PL_last_lop = PL_last_uni = Nullch;
2820 if (CopLINE(PL_curcop) == 1) {
2821 while (s < PL_bufend && isSPACE(*s))
2823 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2827 if (*s == '#' && *(s+1) == '!')
2829 #ifdef ALTERNATE_SHEBANG
2831 static char const as[] = ALTERNATE_SHEBANG;
2832 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2833 d = s + (sizeof(as) - 1);
2835 #endif /* ALTERNATE_SHEBANG */
2844 while (*d && !isSPACE(*d))
2848 #ifdef ARG_ZERO_IS_SCRIPT
2849 if (ipathend > ipath) {
2851 * HP-UX (at least) sets argv[0] to the script name,
2852 * which makes $^X incorrect. And Digital UNIX and Linux,
2853 * at least, set argv[0] to the basename of the Perl
2854 * interpreter. So, having found "#!", we'll set it right.
2856 SV * const x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); /* $^X */
2857 assert(SvPOK(x) || SvGMAGICAL(x));
2858 if (sv_eq(x, CopFILESV(PL_curcop))) {
2859 sv_setpvn(x, ipath, ipathend - ipath);
2865 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
2866 const char * const lstart = SvPV_const(x,llen);
2868 bstart += blen - llen;
2869 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
2870 sv_setpvn(x, ipath, ipathend - ipath);
2875 TAINT_NOT; /* $^X is always tainted, but that's OK */
2877 #endif /* ARG_ZERO_IS_SCRIPT */
2882 d = instr(s,"perl -");
2884 d = instr(s,"perl");
2886 /* avoid getting into infinite loops when shebang
2887 * line contains "Perl" rather than "perl" */
2889 for (d = ipathend-4; d >= ipath; --d) {
2890 if ((*d == 'p' || *d == 'P')
2891 && !ibcmp(d, "perl", 4))
2901 #ifdef ALTERNATE_SHEBANG
2903 * If the ALTERNATE_SHEBANG on this system starts with a
2904 * character that can be part of a Perl expression, then if
2905 * we see it but not "perl", we're probably looking at the
2906 * start of Perl code, not a request to hand off to some
2907 * other interpreter. Similarly, if "perl" is there, but
2908 * not in the first 'word' of the line, we assume the line
2909 * contains the start of the Perl program.
2911 if (d && *s != '#') {
2912 const char *c = ipath;
2913 while (*c && !strchr("; \t\r\n\f\v#", *c))
2916 d = Nullch; /* "perl" not in first word; ignore */
2918 *s = '#'; /* Don't try to parse shebang line */
2920 #endif /* ALTERNATE_SHEBANG */
2921 #ifndef MACOS_TRADITIONAL
2926 !instr(s,"indir") &&
2927 instr(PL_origargv[0],"perl"))
2934 while (s < PL_bufend && isSPACE(*s))
2936 if (s < PL_bufend) {
2937 Newxz(newargv,PL_origargc+3,char*);
2939 while (s < PL_bufend && !isSPACE(*s))
2942 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2945 newargv = PL_origargv;
2948 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
2950 Perl_croak(aTHX_ "Can't exec %s", ipath);
2954 const U32 oldpdb = PL_perldb;
2955 const bool oldn = PL_minus_n;
2956 const bool oldp = PL_minus_p;
2958 while (*d && !isSPACE(*d)) d++;
2959 while (SPACE_OR_TAB(*d)) d++;
2962 const bool switches_done = PL_doswitches;
2964 if (*d == 'M' || *d == 'm' || *d == 'C') {
2965 const char * const m = d;
2966 while (*d && !isSPACE(*d)) d++;
2967 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2970 d = moreswitches(d);
2972 if (PL_doswitches && !switches_done) {
2973 int argc = PL_origargc;
2974 char **argv = PL_origargv;
2977 } while (argc && argv[0][0] == '-' && argv[0][1]);
2978 init_argv_symbols(argc,argv);
2980 if ((PERLDB_LINE && !oldpdb) ||
2981 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
2982 /* if we have already added "LINE: while (<>) {",
2983 we must not do it again */
2985 sv_setpvn(PL_linestr, "", 0);
2986 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2987 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2988 PL_last_lop = PL_last_uni = Nullch;
2989 PL_preambled = FALSE;
2991 (void)gv_fetchfile(PL_origfilename);
2994 if (PL_doswitches && !switches_done) {
2995 int argc = PL_origargc;
2996 char **argv = PL_origargv;
2999 } while (argc && argv[0][0] == '-' && argv[0][1]);
3000 init_argv_symbols(argc,argv);
3006 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3008 PL_lex_state = LEX_FORMLINE;
3013 #ifdef PERL_STRICT_CR
3014 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3016 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3018 case ' ': case '\t': case '\f': case 013:
3019 #ifdef MACOS_TRADITIONAL
3026 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3027 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3028 /* handle eval qq[#line 1 "foo"\n ...] */
3029 CopLINE_dec(PL_curcop);
3033 while (s < d && *s != '\n')
3037 else if (s > d) /* Found by Ilya: feed random input to Perl. */
3038 Perl_croak(aTHX_ "panic: input overflow");
3040 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3042 PL_lex_state = LEX_FORMLINE;
3052 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3059 while (s < PL_bufend && SPACE_OR_TAB(*s))
3062 if (strnEQ(s,"=>",2)) {
3063 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3064 DEBUG_T( { S_printbuf(aTHX_
3065 "### Saw unary minus before =>, forcing word %s\n", s);
3067 OPERATOR('-'); /* unary minus */
3069 PL_last_uni = PL_oldbufptr;
3071 case 'r': ftst = OP_FTEREAD; break;
3072 case 'w': ftst = OP_FTEWRITE; break;
3073 case 'x': ftst = OP_FTEEXEC; break;
3074 case 'o': ftst = OP_FTEOWNED; break;
3075 case 'R': ftst = OP_FTRREAD; break;
3076 case 'W': ftst = OP_FTRWRITE; break;
3077 case 'X': ftst = OP_FTREXEC; break;
3078 case 'O': ftst = OP_FTROWNED; break;
3079 case 'e': ftst = OP_FTIS; break;
3080 case 'z': ftst = OP_FTZERO; break;
3081 case 's': ftst = OP_FTSIZE; break;
3082 case 'f': ftst = OP_FTFILE; break;
3083 case 'd': ftst = OP_FTDIR; break;
3084 case 'l': ftst = OP_FTLINK; break;
3085 case 'p': ftst = OP_FTPIPE; break;
3086 case 'S': ftst = OP_FTSOCK; break;
3087 case 'u': ftst = OP_FTSUID; break;
3088 case 'g': ftst = OP_FTSGID; break;
3089 case 'k': ftst = OP_FTSVTX; break;
3090 case 'b': ftst = OP_FTBLK; break;
3091 case 'c': ftst = OP_FTCHR; break;
3092 case 't': ftst = OP_FTTTY; break;
3093 case 'T': ftst = OP_FTTEXT; break;
3094 case 'B': ftst = OP_FTBINARY; break;
3095 case 'M': case 'A': case 'C':
3096 gv_fetchpv("\024",TRUE, SVt_PV);
3098 case 'M': ftst = OP_FTMTIME; break;
3099 case 'A': ftst = OP_FTATIME; break;
3100 case 'C': ftst = OP_FTCTIME; break;
3108 PL_last_lop_op = (OPCODE)ftst;
3109 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3110 "### Saw file test %c\n", (int)tmp);
3115 /* Assume it was a minus followed by a one-letter named
3116 * subroutine call (or a -bareword), then. */
3117 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3118 "### '-%c' looked like a file test but was not\n",
3127 if (PL_expect == XOPERATOR)
3132 else if (*s == '>') {
3135 if (isIDFIRST_lazy_if(s,UTF)) {
3136 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3144 if (PL_expect == XOPERATOR)
3147 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3149 OPERATOR('-'); /* unary minus */
3156 if (PL_expect == XOPERATOR)
3161 if (PL_expect == XOPERATOR)
3164 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3170 if (PL_expect != XOPERATOR) {
3171 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3172 PL_expect = XOPERATOR;
3173 force_ident(PL_tokenbuf, '*');
3186 if (PL_expect == XOPERATOR) {
3190 PL_tokenbuf[0] = '%';
3191 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3192 if (!PL_tokenbuf[1]) {
3195 PL_pending_ident = '%';
3214 switch (PL_expect) {
3217 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3219 PL_bufptr = s; /* update in case we back off */
3225 PL_expect = XTERMBLOCK;
3229 while (isIDFIRST_lazy_if(s,UTF)) {
3230 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3231 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
3232 if (tmp < 0) tmp = -tmp;
3248 d = scan_str(d,TRUE,TRUE);
3250 /* MUST advance bufptr here to avoid bogus
3251 "at end of line" context messages from yyerror().
3253 PL_bufptr = s + len;
3254 yyerror("Unterminated attribute parameter in attribute list");
3257 return REPORT(0); /* EOF indicator */
3261 SV *sv = newSVpvn(s, len);
3262 sv_catsv(sv, PL_lex_stuff);
3263 attrs = append_elem(OP_LIST, attrs,
3264 newSVOP(OP_CONST, 0, sv));
3265 SvREFCNT_dec(PL_lex_stuff);
3266 PL_lex_stuff = Nullsv;
3269 if (len == 6 && strnEQ(s, "unique", len)) {
3270 if (PL_in_my == KEY_our)
3272 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
3274 ; /* skip to avoid loading attributes.pm */
3277 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
3280 /* NOTE: any CV attrs applied here need to be part of
3281 the CVf_BUILTIN_ATTRS define in cv.h! */
3282 else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
3283 CvLVALUE_on(PL_compcv);
3284 else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
3285 CvLOCKED_on(PL_compcv);
3286 else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
3287 CvMETHOD_on(PL_compcv);
3288 else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len))
3289 CvASSERTION_on(PL_compcv);
3290 /* After we've set the flags, it could be argued that
3291 we don't need to do the attributes.pm-based setting
3292 process, and shouldn't bother appending recognized
3293 flags. To experiment with that, uncomment the
3294 following "else". (Note that's already been
3295 uncommented. That keeps the above-applied built-in
3296 attributes from being intercepted (and possibly
3297 rejected) by a package's attribute routines, but is
3298 justified by the performance win for the common case
3299 of applying only built-in attributes.) */
3301 attrs = append_elem(OP_LIST, attrs,
3302 newSVOP(OP_CONST, 0,
3306 if (*s == ':' && s[1] != ':')
3309 break; /* require real whitespace or :'s */
3311 tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
3312 if (*s != ';' && *s != '}' && *s != tmp && (tmp != '=' || *s != ')')) {
3313 const char q = ((*s == '\'') ? '"' : '\'');
3314 /* If here for an expression, and parsed no attrs, back off. */
3315 if (tmp == '=' && !attrs) {
3319 /* MUST advance bufptr here to avoid bogus "at end of line"
3320 context messages from yyerror().
3324 yyerror("Unterminated attribute list");
3326 yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
3334 PL_nextval[PL_nexttoke].opval = attrs;
3342 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
3343 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
3360 if (PL_lex_brackets <= 0)
3361 yyerror("Unmatched right square bracket");
3364 if (PL_lex_state == LEX_INTERPNORMAL) {
3365 if (PL_lex_brackets == 0) {
3366 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3367 PL_lex_state = LEX_INTERPEND;
3374 if (PL_lex_brackets > 100) {
3375 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
3377 switch (PL_expect) {
3379 if (PL_lex_formbrack) {
3383 if (PL_oldoldbufptr == PL_last_lop)
3384 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3386 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3387 OPERATOR(HASHBRACK);
3389 while (s < PL_bufend && SPACE_OR_TAB(*s))
3392 PL_tokenbuf[0] = '\0';
3393 if (d < PL_bufend && *d == '-') {
3394 PL_tokenbuf[0] = '-';
3396 while (d < PL_bufend && SPACE_OR_TAB(*d))
3399 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3400 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
3402 while (d < PL_bufend && SPACE_OR_TAB(*d))
3405 const char minus = (PL_tokenbuf[0] == '-');
3406 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
3414 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
3419 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3424 if (PL_oldoldbufptr == PL_last_lop)
3425 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3427 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3430 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
3432 /* This hack is to get the ${} in the message. */
3434 yyerror("syntax error");
3437 OPERATOR(HASHBRACK);
3439 /* This hack serves to disambiguate a pair of curlies
3440 * as being a block or an anon hash. Normally, expectation
3441 * determines that, but in cases where we're not in a
3442 * position to expect anything in particular (like inside
3443 * eval"") we have to resolve the ambiguity. This code
3444 * covers the case where the first term in the curlies is a
3445 * quoted string. Most other cases need to be explicitly
3446 * disambiguated by prepending a "+" before the opening
3447 * curly in order to force resolution as an anon hash.
3449 * XXX should probably propagate the outer expectation
3450 * into eval"" to rely less on this hack, but that could
3451 * potentially break current behavior of eval"".
3455 if (*s == '\'' || *s == '"' || *s == '`') {
3456 /* common case: get past first string, handling escapes */
3457 for (t++; t < PL_bufend && *t != *s;)
3458 if (*t++ == '\\' && (*t == '\\' || *t == *s))
3462 else if (*s == 'q') {
3465 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
3468 /* skip q//-like construct */
3470 char open, close, term;
3473 while (t < PL_bufend && isSPACE(*t))
3475 /* check for q => */
3476 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
3477 OPERATOR(HASHBRACK);
3481 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
3485 for (t++; t < PL_bufend; t++) {
3486 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
3488 else if (*t == open)
3492 for (t++; t < PL_bufend; t++) {
3493 if (*t == '\\' && t+1 < PL_bufend)
3495 else if (*t == close && --brackets <= 0)
3497 else if (*t == open)
3504 /* skip plain q word */
3505 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3508 else if (isALNUM_lazy_if(t,UTF)) {
3510 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3513 while (t < PL_bufend && isSPACE(*t))
3515 /* if comma follows first term, call it an anon hash */
3516 /* XXX it could be a comma expression with loop modifiers */
3517 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
3518 || (*t == '=' && t[1] == '>')))
3519 OPERATOR(HASHBRACK);
3520 if (PL_expect == XREF)
3523 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3529 yylval.ival = CopLINE(PL_curcop);
3530 if (isSPACE(*s) || *s == '#')
3531 PL_copline = NOLINE; /* invalidate current command line number */
3536 if (PL_lex_brackets <= 0)
3537 yyerror("Unmatched right curly bracket");
3539 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3540 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3541 PL_lex_formbrack = 0;
3542 if (PL_lex_state == LEX_INTERPNORMAL) {
3543 if (PL_lex_brackets == 0) {
3544 if (PL_expect & XFAKEBRACK) {
3545 PL_expect &= XENUMMASK;
3546 PL_lex_state = LEX_INTERPEND;
3548 return yylex(); /* ignore fake brackets */
3550 if (*s == '-' && s[1] == '>')
3551 PL_lex_state = LEX_INTERPENDMAYBE;
3552 else if (*s != '[' && *s != '{')
3553 PL_lex_state = LEX_INTERPEND;
3556 if (PL_expect & XFAKEBRACK) {
3557 PL_expect &= XENUMMASK;
3559 return yylex(); /* ignore fake brackets */
3569 if (PL_expect == XOPERATOR) {
3570 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
3571 && isIDFIRST_lazy_if(s,UTF))
3573 CopLINE_dec(PL_curcop);
3574 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
3575 CopLINE_inc(PL_curcop);
3580 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3582 PL_expect = XOPERATOR;
3583 force_ident(PL_tokenbuf, '&');
3587 yylval.ival = (OPpENTERSUB_AMPER<<8);
3606 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX) && strchr("+-*/%.^&|<",tmp))
3607 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Reversed %c= operator",(int)tmp);
3609 if (PL_expect == XSTATE && isALPHA(tmp) &&
3610 (s == PL_linestart+1 || s[-2] == '\n') )
3612 if (PL_in_eval && !PL_rsfp) {
3617 if (strnEQ(s,"=cut",4)) {
3631 PL_doextract = TRUE;
3634 if (PL_lex_brackets < PL_lex_formbrack) {
3636 #ifdef PERL_STRICT_CR
3637 for (t = s; SPACE_OR_TAB(*t); t++) ;
3639 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3641 if (*t == '\n' || *t == '#') {
3653 /* was this !=~ where !~ was meant?
3654 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
3656 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
3657 const char *t = s+1;
3659 while (t < PL_bufend && isSPACE(*t))
3662 if (*t == '/' || *t == '?' ||
3663 ((*t == 'm' || *t == 's' || *t == 'y') && !isALNUM(t[1])) ||
3664 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
3665 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3666 "!=~ should be !~");
3675 if (PL_expect != XOPERATOR) {
3676 if (s[1] != '<' && !strchr(s,'>'))
3679 s = scan_heredoc(s);
3681 s = scan_inputsymbol(s);
3682 TERM(sublex_start());
3687 SHop(OP_LEFT_SHIFT);
3701 SHop(OP_RIGHT_SHIFT);
3710 if (PL_expect == XOPERATOR) {
3711 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3714 return REPORT(','); /* grandfather non-comma-format format */
3718 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3719 PL_tokenbuf[0] = '@';
3720 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3721 sizeof PL_tokenbuf - 1, FALSE);
3722 if (PL_expect == XOPERATOR)
3723 no_op("Array length", s);
3724 if (!PL_tokenbuf[1])
3726 PL_expect = XOPERATOR;
3727 PL_pending_ident = '#';
3731 PL_tokenbuf[0] = '$';
3732 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3733 sizeof PL_tokenbuf - 1, FALSE);
3734 if (PL_expect == XOPERATOR)
3736 if (!PL_tokenbuf[1]) {
3738 yyerror("Final $ should be \\$ or $name");
3742 /* This kludge not intended to be bulletproof. */
3743 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3744 yylval.opval = newSVOP(OP_CONST, 0,
3745 newSViv(PL_compiling.cop_arybase));
3746 yylval.opval->op_private = OPpCONST_ARYBASE;
3752 if (PL_lex_state == LEX_NORMAL)
3755 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3757 PL_tokenbuf[0] = '@';
3758 if (ckWARN(WARN_SYNTAX)) {
3761 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3764 PL_bufptr = skipspace(PL_bufptr);
3765 while (t < PL_bufend && *t != ']')
3767 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3768 "Multidimensional syntax %.*s not supported",
3769 (t - PL_bufptr) + 1, PL_bufptr);
3773 else if (*s == '{') {
3775 PL_tokenbuf[0] = '%';
3776 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
3777 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
3779 char tmpbuf[sizeof PL_tokenbuf];
3780 for (t++; isSPACE(*t); t++) ;
3781 if (isIDFIRST_lazy_if(t,UTF)) {
3783 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3784 for (; isSPACE(*t); t++) ;
3785 if (*t == ';' && get_cv(tmpbuf, FALSE))
3786 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3787 "You need to quote \"%s\"", tmpbuf);
3793 PL_expect = XOPERATOR;
3794 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3795 const bool islop = (PL_last_lop == PL_oldoldbufptr);
3796 if (!islop || PL_last_lop_op == OP_GREPSTART)
3797 PL_expect = XOPERATOR;
3798 else if (strchr("$@\"'`q", *s))
3799 PL_expect = XTERM; /* e.g. print $fh "foo" */
3800 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3801 PL_expect = XTERM; /* e.g. print $fh &sub */
3802 else if (isIDFIRST_lazy_if(s,UTF)) {
3803 char tmpbuf[sizeof PL_tokenbuf];
3804 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3805 if ((tmp = keyword(tmpbuf, len))) {
3806 /* binary operators exclude handle interpretations */
3818 PL_expect = XTERM; /* e.g. print $fh length() */
3823 PL_expect = XTERM; /* e.g. print $fh subr() */
3826 else if (isDIGIT(*s))
3827 PL_expect = XTERM; /* e.g. print $fh 3 */
3828 else if (*s == '.' && isDIGIT(s[1]))
3829 PL_expect = XTERM; /* e.g. print $fh .3 */
3830 else if ((*s == '?' || *s == '-' || *s == '+')
3831 && !isSPACE(s[1]) && s[1] != '=')
3832 PL_expect = XTERM; /* e.g. print $fh -1 */
3833 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' && s[1] != '/')
3834 PL_expect = XTERM; /* e.g. print $fh /.../
3835 XXX except DORDOR operator */
3836 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3837 PL_expect = XTERM; /* print $fh <<"EOF" */
3839 PL_pending_ident = '$';
3843 if (PL_expect == XOPERATOR)
3845 PL_tokenbuf[0] = '@';
3846 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3847 if (!PL_tokenbuf[1]) {
3850 if (PL_lex_state == LEX_NORMAL)
3852 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3854 PL_tokenbuf[0] = '%';
3856 /* Warn about @ where they meant $. */
3857 if (*s == '[' || *s == '{') {
3858 if (ckWARN(WARN_SYNTAX)) {
3859 const char *t = s + 1;
3860 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3862 if (*t == '}' || *t == ']') {
3864 PL_bufptr = skipspace(PL_bufptr);
3865 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3866 "Scalar value %.*s better written as $%.*s",
3867 t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3872 PL_pending_ident = '@';
3875 case '/': /* may be division, defined-or, or pattern */
3876 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
3880 case '?': /* may either be conditional or pattern */
3881 if(PL_expect == XOPERATOR) {
3889 /* A // operator. */
3899 /* Disable warning on "study /blah/" */
3900 if (PL_oldoldbufptr == PL_last_uni
3901 && (*PL_last_uni != 's' || s - PL_last_uni < 5
3902 || memNE(PL_last_uni, "study", 5)
3903 || isALNUM_lazy_if(PL_last_uni+5,UTF)
3906 s = scan_pat(s,OP_MATCH);
3907 TERM(sublex_start());
3911 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3912 #ifdef PERL_STRICT_CR
3915 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3917 && (s == PL_linestart || s[-1] == '\n') )
3919 PL_lex_formbrack = 0;
3923 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3929 yylval.ival = OPf_SPECIAL;
3935 if (PL_expect != XOPERATOR)
3940 case '0': case '1': case '2': case '3': case '4':
3941 case '5': case '6': case '7': case '8': case '9':
3942 s = scan_num(s, &yylval);
3943 DEBUG_T( { S_printbuf(aTHX_ "### Saw number in %s\n", s); } );
3944 if (PL_expect == XOPERATOR)
3949 s = scan_str(s,FALSE,FALSE);
3950 DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } );
3951 if (PL_expect == XOPERATOR) {
3952 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3955 return REPORT(','); /* grandfather non-comma-format format */
3961 missingterm((char*)0);
3962 yylval.ival = OP_CONST;
3963 TERM(sublex_start());
3966 s = scan_str(s,FALSE,FALSE);
3967 DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } );
3968 if (PL_expect == XOPERATOR) {
3969 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3972 return REPORT(','); /* grandfather non-comma-format format */
3978 missingterm((char*)0);
3979 yylval.ival = OP_CONST;
3980 /* FIXME. I think that this can be const if char *d is replaced by
3981 more localised variables. */
3982 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3983 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
3984 yylval.ival = OP_STRINGIFY;
3988 TERM(sublex_start());
3991 s = scan_str(s,FALSE,FALSE);
3992 DEBUG_T( { S_printbuf(aTHX_ "### Saw backtick string before %s\n", s); } );
3993 if (PL_expect == XOPERATOR)
3994 no_op("Backticks",s);
3996 missingterm((char*)0);
3997 yylval.ival = OP_BACKTICK;
3999 TERM(sublex_start());
4003 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
4004 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
4006 if (PL_expect == XOPERATOR)
4007 no_op("Backslash",s);
4011 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
4012 char *start = s + 2;
4013 while (isDIGIT(*start) || *start == '_')
4015 if (*start == '.' && isDIGIT(start[1])) {
4016 s = scan_num(s, &yylval);
4019 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
4020 else if (!isALPHA(*start) && (PL_expect == XTERM
4021 || PL_expect == XREF || PL_expect == XSTATE
4022 || PL_expect == XTERMORDORDOR)) {
4023 const char c = *start;
4026 gv = gv_fetchpv(s, FALSE, SVt_PVCV);
4029 s = scan_num(s, &yylval);
4036 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
4076 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4078 /* Some keywords can be followed by any delimiter, including ':' */
4079 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
4080 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
4081 (PL_tokenbuf[0] == 'q' &&
4082 strchr("qwxr", PL_tokenbuf[1])))));
4084 /* x::* is just a word, unless x is "CORE" */
4085 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4089 while (d < PL_bufend && isSPACE(*d))
4090 d++; /* no comments skipped here, or s### is misparsed */
4092 /* Is this a label? */
4093 if (!tmp && PL_expect == XSTATE
4094 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4096 yylval.pval = savepv(PL_tokenbuf);
4101 /* Check for keywords */
4102 tmp = keyword(PL_tokenbuf, len);
4104 /* Is this a word before a => operator? */
4105 if (*d == '=' && d[1] == '>') {
4108 = (OP*)newSVOP(OP_CONST, 0,
4109 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
4110 yylval.opval->op_private = OPpCONST_BARE;
4114 if (tmp < 0) { /* second-class keyword? */
4115 GV *ogv = Nullgv; /* override (winner) */
4116 GV *hgv = Nullgv; /* hidden (loser) */
4117 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4119 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
4122 if (GvIMPORTED_CV(gv))
4124 else if (! CvMETHOD(cv))
4128 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4129 (gv = *gvp) != (GV*)&PL_sv_undef &&
4130 GvCVu(gv) && GvIMPORTED_CV(gv))
4137 tmp = 0; /* overridden by import or by GLOBAL */
4140 && -tmp==KEY_lock /* XXX generalizable kludge */
4142 && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
4144 tmp = 0; /* any sub overrides "weak" keyword */
4149 && PL_expect != XOPERATOR
4150 && PL_expect != XTERMORDORDOR)
4152 /* any sub overrides the "err" keyword, except when really an
4153 * operator is expected */
4156 else { /* no override */
4158 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
4159 Perl_warner(aTHX_ packWARN(WARN_MISC),
4160 "dump() better written as CORE::dump()");
4164 if (hgv && tmp != KEY_x && tmp != KEY_CORE
4165 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
4166 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4167 "Ambiguous call resolved as CORE::%s(), %s",
4168 GvENAME(hgv), "qualify as such or use &");
4175 default: /* not a keyword */
4179 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
4181 /* Get the rest if it looks like a package qualifier */
4183 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
4185 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
4188 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
4189 *s == '\'' ? "'" : "::");
4194 if (PL_expect == XOPERATOR) {
4195 if (PL_bufptr == PL_linestart) {
4196 CopLINE_dec(PL_curcop);
4197 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4198 CopLINE_inc(PL_curcop);
4201 no_op("Bareword",s);
4204 /* Look for a subroutine with this name in current package,
4205 unless name is "Foo::", in which case Foo is a bearword
4206 (and a package name). */
4209 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
4211 if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
4212 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
4213 "Bareword \"%s\" refers to nonexistent package",
4216 PL_tokenbuf[len] = '\0';
4223 gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
4226 /* if we saw a global override before, get the right name */
4229 sv = newSVpvn("CORE::GLOBAL::",14);
4230 sv_catpv(sv,PL_tokenbuf);
4233 /* If len is 0, newSVpv does strlen(), which is correct.
4234 If len is non-zero, then it will be the true length,
4235 and so the scalar will be created correctly. */
4236 sv = newSVpv(PL_tokenbuf,len);
4239 /* Presume this is going to be a bareword of some sort. */
4242 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4243 yylval.opval->op_private = OPpCONST_BARE;
4244 /* UTF-8 package name? */
4245 if (UTF && !IN_BYTES &&
4246 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
4249 /* And if "Foo::", then that's what it certainly is. */
4254 /* See if it's the indirect object for a list operator. */
4256 if (PL_oldoldbufptr &&
4257 PL_oldoldbufptr < PL_bufptr &&
4258 (PL_oldoldbufptr == PL_last_lop
4259 || PL_oldoldbufptr == PL_last_uni) &&
4260 /* NO SKIPSPACE BEFORE HERE! */
4261 (PL_expect == XREF ||
4262 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
4264 bool immediate_paren = *s == '(';
4266 /* (Now we can afford to cross potential line boundary.) */
4269 /* Two barewords in a row may indicate method call. */
4271 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv)))
4274 /* If not a declared subroutine, it's an indirect object. */
4275 /* (But it's an indir obj regardless for sort.) */
4276 /* Also, if "_" follows a filetest operator, it's a bareword */
4279 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
4280 ((!gv || !GvCVu(gv)) &&
4281 (PL_last_lop_op != OP_MAPSTART &&
4282 PL_last_lop_op != OP_GREPSTART))))
4283 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
4284 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
4287 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
4292 PL_expect = XOPERATOR;
4295 /* Is this a word before a => operator? */
4296 if (*s == '=' && s[1] == '>' && !pkgname) {
4298 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
4299 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
4300 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
4304 /* If followed by a paren, it's certainly a subroutine. */
4307 if (gv && GvCVu(gv)) {
4308 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
4309 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
4314 PL_nextval[PL_nexttoke].opval = yylval.opval;
4315 PL_expect = XOPERATOR;
4321 /* If followed by var or block, call it a method (unless sub) */
4323 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
4324 PL_last_lop = PL_oldbufptr;
4325 PL_last_lop_op = OP_METHOD;
4329 /* If followed by a bareword, see if it looks like indir obj. */
4332 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
4333 && (tmp = intuit_method(s,gv)))
4336 /* Not a method, so call it a subroutine (if defined) */
4338 if (gv && GvCVu(gv)) {
4340 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
4341 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4342 "Ambiguous use of -%s resolved as -&%s()",
4343 PL_tokenbuf, PL_tokenbuf);
4344 /* Check for a constant sub */
4346 if ((sv = cv_const_sv(cv))) {
4348 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
4349 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
4350 yylval.opval->op_private = 0;
4354 /* Resolve to GV now. */
4355 op_free(yylval.opval);
4356 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4357 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
4358 PL_last_lop = PL_oldbufptr;
4359 PL_last_lop_op = OP_ENTERSUB;
4360 /* Is there a prototype? */
4363 const char *proto = SvPV_const((SV*)cv, len);
4366 if (*proto == '$' && proto[1] == '\0')
4368 while (*proto == ';')
4370 if (*proto == '&' && *s == '{') {
4371 sv_setpv(PL_subname, PL_curstash ?
4372 "__ANON__" : "__ANON__::__ANON__");
4376 PL_nextval[PL_nexttoke].opval = yylval.opval;
4382 /* Call it a bare word */
4384 if (PL_hints & HINT_STRICT_SUBS)
4385 yylval.opval->op_private |= OPpCONST_STRICT;
4388 if (lastchar != '-') {
4389 if (ckWARN(WARN_RESERVED)) {
4390 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
4391 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
4392 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
4399 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
4400 && ckWARN_d(WARN_AMBIGUOUS)) {
4401 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4402 "Operator or semicolon missing before %c%s",
4403 lastchar, PL_tokenbuf);
4404 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4405 "Ambiguous use of %c resolved as operator %c",
4406 lastchar, lastchar);
4412 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4413 newSVpv(CopFILE(PL_curcop),0));
4417 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4418 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
4421 case KEY___PACKAGE__:
4422 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4424 ? newSVhek(HvNAME_HEK(PL_curstash))
4431 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
4432 const char *pname = "main";
4433 if (PL_tokenbuf[2] == 'D')
4434 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
4435 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);
4438 GvIOp(gv) = newIO();
4439 IoIFP(GvIOp(gv)) = PL_rsfp;
4440 #if defined(HAS_FCNTL) && defined(F_SETFD)
4442 const int fd = PerlIO_fileno(PL_rsfp);
4443 fcntl(fd,F_SETFD,fd >= 3);
4446 /* Mark this internal pseudo-handle as clean */
4447 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4449 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
4450 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
4451 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
4453 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
4454 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
4455 /* if the script was opened in binmode, we need to revert
4456 * it to text mode for compatibility; but only iff it has CRs
4457 * XXX this is a questionable hack at best. */
4458 if (PL_bufend-PL_bufptr > 2
4459 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
4462 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
4463 loc = PerlIO_tell(PL_rsfp);
4464 (void)PerlIO_seek(PL_rsfp, 0L, 0);
4467 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
4469 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
4470 #endif /* NETWARE */
4471 #ifdef PERLIO_IS_STDIO /* really? */
4472 # if defined(__BORLANDC__)
4473 /* XXX see note in do_binmode() */
4474 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
4478 PerlIO_seek(PL_rsfp, loc, 0);
4482 #ifdef PERLIO_LAYERS
4485 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
4486 else if (PL_encoding) {
4493 XPUSHs(PL_encoding);
4495 call_method("name", G_SCALAR);
4499 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
4500 Perl_form(aTHX_ ":encoding(%"SVf")",
4518 if (PL_expect == XSTATE) {
4525 if (*s == ':' && s[1] == ':') {
4528 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4529 if (!(tmp = keyword(PL_tokenbuf, len)))
4530 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
4533 else if (tmp == KEY_require || tmp == KEY_do)
4534 /* that's a way to remember we saw "CORE::" */
4547 LOP(OP_ACCEPT,XTERM);
4553 LOP(OP_ATAN2,XTERM);
4559 LOP(OP_BINMODE,XTERM);
4562 LOP(OP_BLESS,XTERM);
4571 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
4588 if (!PL_cryptseen) {
4589 PL_cryptseen = TRUE;
4593 LOP(OP_CRYPT,XTERM);
4596 LOP(OP_CHMOD,XTERM);
4599 LOP(OP_CHOWN,XTERM);
4602 LOP(OP_CONNECT,XTERM);
4618 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4619 if (orig_keyword == KEY_do) {
4628 PL_hints |= HINT_BLOCK_SCOPE;
4638 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
4639 LOP(OP_DBMOPEN,XTERM);
4645 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4652 yylval.ival = CopLINE(PL_curcop);
4666 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4667 UNIBRACK(OP_ENTEREVAL);
4685 case KEY_endhostent:
4691 case KEY_endservent:
4694 case KEY_endprotoent:
4705 yylval.ival = CopLINE(PL_curcop);
4707 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4709 if ((PL_bufend - p) >= 3 &&
4710 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4712 else if ((PL_bufend - p) >= 4 &&
4713 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4716 if (isIDFIRST_lazy_if(p,UTF)) {
4717 p = scan_ident(p, PL_bufend,
4718 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4722 Perl_croak(aTHX_ "Missing $ on loop variable");
4727 LOP(OP_FORMLINE,XTERM);
4733 LOP(OP_FCNTL,XTERM);
4739 LOP(OP_FLOCK,XTERM);
4748 LOP(OP_GREPSTART, XREF);
4751 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4766 case KEY_getpriority:
4767 LOP(OP_GETPRIORITY,XTERM);
4769 case KEY_getprotobyname:
4772 case KEY_getprotobynumber:
4773 LOP(OP_GPBYNUMBER,XTERM);
4775 case KEY_getprotoent:
4787 case KEY_getpeername:
4788 UNI(OP_GETPEERNAME);
4790 case KEY_gethostbyname:
4793 case KEY_gethostbyaddr:
4794 LOP(OP_GHBYADDR,XTERM);
4796 case KEY_gethostent:
4799 case KEY_getnetbyname:
4802 case KEY_getnetbyaddr:
4803 LOP(OP_GNBYADDR,XTERM);
4808 case KEY_getservbyname:
4809 LOP(OP_GSBYNAME,XTERM);
4811 case KEY_getservbyport:
4812 LOP(OP_GSBYPORT,XTERM);
4814 case KEY_getservent:
4817 case KEY_getsockname:
4818 UNI(OP_GETSOCKNAME);
4820 case KEY_getsockopt:
4821 LOP(OP_GSOCKOPT,XTERM);
4843 yylval.ival = CopLINE(PL_curcop);
4847 LOP(OP_INDEX,XTERM);
4853 LOP(OP_IOCTL,XTERM);
4865 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4897 LOP(OP_LISTEN,XTERM);
4906 s = scan_pat(s,OP_MATCH);
4907 TERM(sublex_start());
4910 LOP(OP_MAPSTART, XREF);
4913 LOP(OP_MKDIR,XTERM);
4916 LOP(OP_MSGCTL,XTERM);
4919 LOP(OP_MSGGET,XTERM);
4922 LOP(OP_MSGRCV,XTERM);
4925 LOP(OP_MSGSND,XTERM);
4931 if (isIDFIRST_lazy_if(s,UTF)) {
4932 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4933 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4935 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
4936 if (!PL_in_my_stash) {
4939 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4947 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4954 s = tokenize_use(0, s);
4958 if (*s == '(' || (s = skipspace(s), *s == '('))
4965 if (isIDFIRST_lazy_if(s,UTF)) {
4967 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
4968 for (t=d; *t && isSPACE(*t); t++) ;
4969 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
4971 && !(t[0] == '=' && t[1] == '>')
4973 int len = (int)(d-s);
4974 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
4975 "Precedence problem: open %.*s should be open(%.*s)",
4982 yylval.ival = OP_OR;
4992 LOP(OP_OPEN_DIR,XTERM);
4995 checkcomma(s,PL_tokenbuf,"filehandle");
4999 checkcomma(s,PL_tokenbuf,"filehandle");
5018 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5022 LOP(OP_PIPE_OP,XTERM);
5025 s = scan_str(s,FALSE,FALSE);
5027 missingterm((char*)0);
5028 yylval.ival = OP_CONST;
5029 TERM(sublex_start());
5035 s = scan_str(s,FALSE,FALSE);
5037 missingterm((char*)0);
5038 PL_expect = XOPERATOR;
5040 if (SvCUR(PL_lex_stuff)) {
5043 d = SvPV_force(PL_lex_stuff, len);
5046 for (; isSPACE(*d) && len; --len, ++d) ;
5049 if (!warned && ckWARN(WARN_QW)) {
5050 for (; !isSPACE(*d) && len; --len, ++d) {
5052 Perl_warner(aTHX_ packWARN(WARN_QW),
5053 "Possible attempt to separate words with commas");
5056 else if (*d == '#') {
5057 Perl_warner(aTHX_ packWARN(WARN_QW),
5058 "Possible attempt to put comments in qw() list");
5064 for (; !isSPACE(*d) && len; --len, ++d) ;
5066 sv = newSVpvn(b, d-b);
5067 if (DO_UTF8(PL_lex_stuff))
5069 words = append_elem(OP_LIST, words,
5070 newSVOP(OP_CONST, 0, tokeq(sv)));
5074 PL_nextval[PL_nexttoke].opval = words;
5079 SvREFCNT_dec(PL_lex_stuff);
5080 PL_lex_stuff = Nullsv;
5086 s = scan_str(s,FALSE,FALSE);
5088 missingterm((char*)0);
5089 yylval.ival = OP_STRINGIFY;
5090 if (SvIVX(PL_lex_stuff) == '\'')
5091 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
5092 TERM(sublex_start());
5095 s = scan_pat(s,OP_QR);
5096 TERM(sublex_start());
5099 s = scan_str(s,FALSE,FALSE);
5101 missingterm((char*)0);
5102 yylval.ival = OP_BACKTICK;
5104 TERM(sublex_start());
5112 s = force_version(s, FALSE);
5114 else if (*s != 'v' || !isDIGIT(s[1])
5115 || (s = force_version(s, TRUE), *s == 'v'))
5117 *PL_tokenbuf = '\0';
5118 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5119 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
5120 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
5122 yyerror("<> should be quotes");
5124 if (orig_keyword == KEY_require) {
5132 PL_last_uni = PL_oldbufptr;
5133 PL_last_lop_op = OP_REQUIRE;
5135 return REPORT( (int)REQUIRE );
5141 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5145 LOP(OP_RENAME,XTERM);
5154 LOP(OP_RINDEX,XTERM);
5164 UNIDOR(OP_READLINE);
5177 LOP(OP_REVERSE,XTERM);
5180 UNIDOR(OP_READLINK);
5188 TERM(sublex_start());
5190 TOKEN(1); /* force error */
5199 LOP(OP_SELECT,XTERM);
5205 LOP(OP_SEMCTL,XTERM);
5208 LOP(OP_SEMGET,XTERM);
5211 LOP(OP_SEMOP,XTERM);
5217 LOP(OP_SETPGRP,XTERM);
5219 case KEY_setpriority:
5220 LOP(OP_SETPRIORITY,XTERM);
5222 case KEY_sethostent:
5228 case KEY_setservent:
5231 case KEY_setprotoent:
5241 LOP(OP_SEEKDIR,XTERM);
5243 case KEY_setsockopt:
5244 LOP(OP_SSOCKOPT,XTERM);
5250 LOP(OP_SHMCTL,XTERM);
5253 LOP(OP_SHMGET,XTERM);
5256 LOP(OP_SHMREAD,XTERM);
5259 LOP(OP_SHMWRITE,XTERM);
5262 LOP(OP_SHUTDOWN,XTERM);
5271 LOP(OP_SOCKET,XTERM);
5273 case KEY_socketpair:
5274 LOP(OP_SOCKPAIR,XTERM);
5277 checkcomma(s,PL_tokenbuf,"subroutine name");
5279 if (*s == ';' || *s == ')') /* probably a close */
5280 Perl_croak(aTHX_ "sort is now a reserved word");
5282 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5286 LOP(OP_SPLIT,XTERM);
5289 LOP(OP_SPRINTF,XTERM);
5292 LOP(OP_SPLICE,XTERM);
5307 LOP(OP_SUBSTR,XTERM);
5313 char tmpbuf[sizeof PL_tokenbuf];
5314 SSize_t tboffset = 0;
5315 expectation attrful;
5316 bool have_name, have_proto, bad_proto;
5317 const int key = tmp;
5321 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
5322 (*s == ':' && s[1] == ':'))
5325 attrful = XATTRBLOCK;
5326 /* remember buffer pos'n for later force_word */
5327 tboffset = s - PL_oldbufptr;
5328 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5329 if (strchr(tmpbuf, ':'))
5330 sv_setpv(PL_subname, tmpbuf);
5332 sv_setsv(PL_subname,PL_curstname);
5333 sv_catpvn(PL_subname,"::",2);
5334 sv_catpvn(PL_subname,tmpbuf,len);
5341 Perl_croak(aTHX_ "Missing name in \"my sub\"");
5342 PL_expect = XTERMBLOCK;
5343 attrful = XATTRTERM;
5344 sv_setpvn(PL_subname,"?",1);
5348 if (key == KEY_format) {
5350 PL_lex_formbrack = PL_lex_brackets + 1;
5352 (void) force_word(PL_oldbufptr + tboffset, WORD,
5357 /* Look for a prototype */
5361 s = scan_str(s,FALSE,FALSE);
5363 Perl_croak(aTHX_ "Prototype not terminated");
5364 /* strip spaces and check for bad characters */
5365 d = SvPVX(PL_lex_stuff);
5368 for (p = d; *p; ++p) {
5371 if (!strchr("$@%*;[]&\\", *p))
5376 if (bad_proto && ckWARN(WARN_SYNTAX))
5377 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5378 "Illegal character in prototype for %"SVf" : %s",
5380 SvCUR_set(PL_lex_stuff, tmp);
5388 if (*s == ':' && s[1] != ':')
5389 PL_expect = attrful;
5390 else if (*s != '{' && key == KEY_sub) {
5392 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
5394 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname);
5398 PL_nextval[PL_nexttoke].opval =
5399 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
5400 PL_lex_stuff = Nullsv;
5404 sv_setpv(PL_subname,
5405 PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
5408 (void) force_word(PL_oldbufptr + tboffset, WORD,
5417 LOP(OP_SYSTEM,XREF);
5420 LOP(OP_SYMLINK,XTERM);
5423 LOP(OP_SYSCALL,XTERM);
5426 LOP(OP_SYSOPEN,XTERM);
5429 LOP(OP_SYSSEEK,XTERM);
5432 LOP(OP_SYSREAD,XTERM);
5435 LOP(OP_SYSWRITE,XTERM);
5439 TERM(sublex_start());
5460 LOP(OP_TRUNCATE,XTERM);
5472 yylval.ival = CopLINE(PL_curcop);
5476 yylval.ival = CopLINE(PL_curcop);
5480 LOP(OP_UNLINK,XTERM);
5486 LOP(OP_UNPACK,XTERM);
5489 LOP(OP_UTIME,XTERM);
5495 LOP(OP_UNSHIFT,XTERM);
5498 s = tokenize_use(1, s);
5508 yylval.ival = CopLINE(PL_curcop);
5512 PL_hints |= HINT_BLOCK_SCOPE;
5519 LOP(OP_WAITPID,XTERM);
5528 ctl_l[0] = toCTRL('L');
5530 gv_fetchpv(ctl_l,TRUE, SVt_PV);
5533 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
5538 if (PL_expect == XOPERATOR)
5544 yylval.ival = OP_XOR;
5549 TERM(sublex_start());
5554 #pragma segment Main
5558 S_pending_ident(pTHX)
5561 register I32 tmp = 0;
5562 /* pit holds the identifier we read and pending_ident is reset */
5563 char pit = PL_pending_ident;
5564 PL_pending_ident = 0;
5566 DEBUG_T({ PerlIO_printf(Perl_debug_log,
5567 "### Pending identifier '%s'\n", PL_tokenbuf); });
5569 /* if we're in a my(), we can't allow dynamics here.
5570 $foo'bar has already been turned into $foo::bar, so
5571 just check for colons.
5573 if it's a legal name, the OP is a PADANY.
5576 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
5577 if (strchr(PL_tokenbuf,':'))
5578 yyerror(Perl_form(aTHX_ "No package name allowed for "
5579 "variable %s in \"our\"",
5581 tmp = allocmy(PL_tokenbuf);
5584 if (strchr(PL_tokenbuf,':'))
5585 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
5587 yylval.opval = newOP(OP_PADANY, 0);
5588 yylval.opval->op_targ = allocmy(PL_tokenbuf);
5594 build the ops for accesses to a my() variable.
5596 Deny my($a) or my($b) in a sort block, *if* $a or $b is
5597 then used in a comparison. This catches most, but not
5598 all cases. For instance, it catches
5599 sort { my($a); $a <=> $b }
5601 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
5602 (although why you'd do that is anyone's guess).
5605 if (!strchr(PL_tokenbuf,':')) {
5607 tmp = pad_findmy(PL_tokenbuf);
5608 if (tmp != NOT_IN_PAD) {
5609 /* might be an "our" variable" */
5610 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
5611 /* build ops for a bareword */
5612 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
5613 HEK * const stashname = HvNAME_HEK(stash);
5614 SV * const sym = newSVhek(stashname);
5615 sv_catpvn(sym, "::", 2);
5616 sv_catpv(sym, PL_tokenbuf+1);
5617 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
5618 yylval.opval->op_private = OPpCONST_ENTERED;
5621 ? (GV_ADDMULTI | GV_ADDINEVAL)
5624 ((PL_tokenbuf[0] == '$') ? SVt_PV
5625 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5630 /* if it's a sort block and they're naming $a or $b */
5631 if (PL_last_lop_op == OP_SORT &&
5632 PL_tokenbuf[0] == '$' &&
5633 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
5636 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
5637 d < PL_bufend && *d != '\n';
5640 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
5641 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
5647 yylval.opval = newOP(OP_PADANY, 0);
5648 yylval.opval->op_targ = tmp;
5654 Whine if they've said @foo in a doublequoted string,
5655 and @foo isn't a variable we can find in the symbol
5658 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
5659 GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
5660 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
5661 && ckWARN(WARN_AMBIGUOUS))
5663 /* Downgraded from fatal to warning 20000522 mjd */
5664 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5665 "Possible unintended interpolation of %s in string",
5670 /* build ops for a bareword */
5671 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
5672 yylval.opval->op_private = OPpCONST_ENTERED;
5673 gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
5674 ((PL_tokenbuf[0] == '$') ? SVt_PV
5675 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5681 * The following code was generated by perl_keyword.pl.
5685 Perl_keyword (pTHX_ const char *name, I32 len)
5689 case 1: /* 5 tokens of length 1 */
5721 case 2: /* 18 tokens of length 2 */
5867 case 3: /* 28 tokens of length 3 */
5871 if (name[1] == 'N' &&
5934 if (name[1] == 'i' &&
5974 if (name[1] == 'o' &&
5983 if (name[1] == 'e' &&
5992 if (name[1] == 'n' &&
6001 if (name[1] == 'o' &&
6010 if (name[1] == 'a' &&
6019 if (name[1] == 'o' &&
6081 if (name[1] == 'e' &&
6113 if (name[1] == 'i' &&
6122 if (name[1] == 's' &&
6131 if (name[1] == 'e' &&
6140 if (name[1] == 'o' &&
6152 case 4: /* 40 tokens of length 4 */
6156 if (name[1] == 'O' &&
6166 if (name[1] == 'N' &&
6176 if (name[1] == 'i' &&
6186 if (name[1] == 'h' &&
6196 if (name[1] == 'u' &&
6209 if (name[2] == 'c' &&
6218 if (name[2] == 's' &&
6227 if (name[2] == 'a' &&
6263 if (name[1] == 'o' &&
6276 if (name[2] == 't' &&
6285 if (name[2] == 'o' &&
6294 if (name[2] == 't' &&
6303 if (name[2] == 'e' &&
6316 if (name[1] == 'o' &&
6329 if (name[2] == 'y' &&
6338 if (name[2] == 'l' &&
6354 if (name[2] == 's' &&
6363 if (name[2] == 'n' &&
6372 if (name[2] == 'c' &&
6385 if (name[1] == 'e' &&
6395 if (name[1] == 'p' &&
6408 if (name[2] == 'c' &&
6417 if (name[2] == 'p' &&
6426 if (name[2] == 's' &&
6442 if (name[2] == 'n' &&
6512 if (name[2] == 'r' &&
6521 if (name[2] == 'r' &&
6530 if (name[2] == 'a' &&
6546 if (name[2] == 'l' &&
6613 case 5: /* 36 tokens of length 5 */
6617 if (name[1] == 'E' &&
6628 if (name[1] == 'H' &&
6642 if (name[2] == 'a' &&
6652 if (name[2] == 'a' &&
6666 if (name[1] == 'l' &&
6683 if (name[3] == 'i' &&
6692 if (name[3] == 'o' &&
6728 if (name[2] == 'o' &&
6738 if (name[2] == 'y' &&
6752 if (name[1] == 'l' &&
6766 if (name[2] == 'n' &&
6776 if (name[2] == 'o' &&
6793 if (name[2] == 'd' &&
6803 if (name[2] == 'c' &&
6820 if (name[2] == 'c' &&
6830 if (name[2] == 't' &&
6844 if (name[1] == 'k' &&
6855 if (name[1] == 'r' &&
6869 if (name[2] == 's' &&
6879 if (name[2] == 'd' &&
6896 if (name[2] == 'm' &&
6906 if (name[2] == 'i' &&
6916 if (name[2] == 'e' &&
6926 if (name[2] == 'l' &&
6936 if (name[2] == 'a' &&
6946 if (name[2] == 'u' &&
6960 if (name[1] == 'i' &&
6974 if (name[2] == 'a' &&
6987 if (name[3] == 'e' &&
7022 if (name[2] == 'i' &&
7039 if (name[2] == 'i' &&
7049 if (name[2] == 'i' &&
7066 case 6: /* 33 tokens of length 6 */
7070 if (name[1] == 'c' &&
7085 if (name[2] == 'l' &&
7096 if (name[2] == 'r' &&
7111 if (name[1] == 'e' &&
7126 if (name[2] == 's' &&
7131 if(ckWARN_d(WARN_SYNTAX))
7132 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
7138 if (name[2] == 'i' &&
7156 if (name[2] == 'l' &&
7167 if (name[2] == 'r' &&
7182 if (name[1] == 'm' &&
7197 if (name[2] == 'n' &&
7208 if (name[2] == 's' &&
7223 if (name[1] == 's' &&
7229 if (name[4] == 't' &&
7238 if (name[4] == 'e' &&
7247 if (name[4] == 'c' &&
7256 if (name[4] == 'n' &&
7272 if (name[1] == 'r' &&
7290 if (name[3] == 'a' &&
7300 if (name[3] == 'u' &&
7314 if (name[2] == 'n' &&
7332 if (name[2] == 'a' &&
7346 if (name[3] == 'e' &&
7359 if (name[4] == 't' &&
7368 if (name[4] == 'e' &&
7390 if (name[4] == 't' &&
7399 if (name[4] == 'e' &&
7415 if (name[2] == 'c' &&
7426 if (name[2] == 'l' &&
7437 if (name[2] == 'b' &&
7448 if (name[2] == 's' &&
7471 if (name[4] == 's' &&
7480 if (name[4] == 'n' &&
7493 if (name[3] == 'a' &&
7510 if (name[1] == 'a' &&
7525 case 7: /* 28 tokens of length 7 */
7529 if (name[1] == 'E' &&
7542 if (name[1] == '_' &&
7555 if (name[1] == 'i' &&
7562 return -KEY_binmode;
7568 if (name[1] == 'o' &&
7575 return -KEY_connect;
7584 if (name[2] == 'm' &&
7590 return -KEY_dbmopen;
7596 if (name[2] == 'f' &&
7612 if (name[1] == 'o' &&
7625 if (name[1] == 'e' &&
7632 if (name[5] == 'r' &&
7635 return -KEY_getpgrp;
7641 if (name[5] == 'i' &&
7644 return -KEY_getppid;
7657 if (name[1] == 'c' &&
7664 return -KEY_lcfirst;
7670 if (name[1] == 'p' &&
7677 return -KEY_opendir;
7683 if (name[1] == 'a' &&
7701 if (name[3] == 'd' &&
7706 return -KEY_readdir;
7712 if (name[3] == 'u' &&
7723 if (name[3] == 'e' &&
7728 return -KEY_reverse;
7747 if (name[3] == 'k' &&
7752 return -KEY_seekdir;
7758 if (name[3] == 'p' &&
7763 return -KEY_setpgrp;
7773 if (name[2] == 'm' &&
7779 return -KEY_shmread;
7785 if (name[2] == 'r' &&
7791 return -KEY_sprintf;
7800 if (name[3] == 'l' &&
7805 return -KEY_symlink;
7814 if (name[4] == 'a' &&
7818 return -KEY_syscall;
7824 if (name[4] == 'p' &&
7828 return -KEY_sysopen;
7834 if (name[4] == 'e' &&
7838 return -KEY_sysread;
7844 if (name[4] == 'e' &&
7848 return -KEY_sysseek;
7866 if (name[1] == 'e' &&
7873 return -KEY_telldir;
7882 if (name[2] == 'f' &&
7888 return -KEY_ucfirst;
7894 if (name[2] == 's' &&
7900 return -KEY_unshift;
7910 if (name[1] == 'a' &&
7917 return -KEY_waitpid;
7926 case 8: /* 26 tokens of length 8 */
7930 if (name[1] == 'U' &&
7938 return KEY_AUTOLOAD;
7949 if (name[3] == 'A' &&
7955 return KEY___DATA__;
7961 if (name[3] == 'I' &&
7967 return -KEY___FILE__;
7973 if (name[3] == 'I' &&
7979 return -KEY___LINE__;
7995 if (name[2] == 'o' &&
8002 return -KEY_closedir;
8008 if (name[2] == 'n' &&
8015 return -KEY_continue;
8025 if (name[1] == 'b' &&
8033 return -KEY_dbmclose;
8039 if (name[1] == 'n' &&
8045 if (name[4] == 'r' &&
8050 return -KEY_endgrent;
8056 if (name[4] == 'w' &&
8061 return -KEY_endpwent;
8074 if (name[1] == 'o' &&
8082 return -KEY_formline;
8088 if (name[1] == 'e' &&
8099 if (name[6] == 'n' &&
8102 return -KEY_getgrent;
8108 if (name[6] == 'i' &&
8111 return -KEY_getgrgid;
8117 if (name[6] == 'a' &&
8120 return -KEY_getgrnam;
8133 if (name[4] == 'o' &&
8138 return -KEY_getlogin;
8149 if (name[6] == 'n' &&
8152 return -KEY_getpwent;
8158 if (name[6] == 'a' &&
8161 return -KEY_getpwnam;
8167 if (name[6] == 'i' &&
8170 return -KEY_getpwuid;
8190 if (name[1] == 'e' &&
8197 if (name[5] == 'i' &&
8204 return -KEY_readline;
8209 return -KEY_readlink;
8220 if (name[5] == 'i' &&
8224 return -KEY_readpipe;
8245 if (name[4] == 'r' &&
8250 return -KEY_setgrent;
8256 if (name[4] == 'w' &&
8261 return -KEY_setpwent;
8277 if (name[3] == 'w' &&
8283 return -KEY_shmwrite;
8289 if (name[3] == 't' &&
8295 return -KEY_shutdown;
8305 if (name[2] == 's' &&
8312 return -KEY_syswrite;
8322 if (name[1] == 'r' &&
8330 return -KEY_truncate;
8339 case 9: /* 8 tokens of length 9 */
8343 if (name[1] == 'n' &&
8352 return -KEY_endnetent;
8358 if (name[1] == 'e' &&
8367 return -KEY_getnetent;
8373 if (name[1] == 'o' &&
8382 return -KEY_localtime;
8388 if (name[1] == 'r' &&
8397 return KEY_prototype;
8403 if (name[1] == 'u' &&
8412 return -KEY_quotemeta;
8418 if (name[1] == 'e' &&
8427 return -KEY_rewinddir;
8433 if (name[1] == 'e' &&
8442 return -KEY_setnetent;
8448 if (name[1] == 'a' &&
8457 return -KEY_wantarray;
8466 case 10: /* 9 tokens of length 10 */
8470 if (name[1] == 'n' &&
8476 if (name[4] == 'o' &&
8483 return -KEY_endhostent;
8489 if (name[4] == 'e' &&
8496 return -KEY_endservent;
8509 if (name[1] == 'e' &&
8515 if (name[4] == 'o' &&
8522 return -KEY_gethostent;
8531 if (name[5] == 'r' &&
8537 return -KEY_getservent;
8543 if (name[5] == 'c' &&
8549 return -KEY_getsockopt;
8574 if (name[4] == 'o' &&
8581 return -KEY_sethostent;
8590 if (name[5] == 'r' &&
8596 return -KEY_setservent;
8602 if (name[5] == 'c' &&
8608 return -KEY_setsockopt;
8625 if (name[2] == 'c' &&
8634 return -KEY_socketpair;
8647 case 11: /* 8 tokens of length 11 */
8651 if (name[1] == '_' &&
8662 return -KEY___PACKAGE__;
8668 if (name[1] == 'n' &&
8679 return -KEY_endprotoent;
8685 if (name[1] == 'e' &&
8694 if (name[5] == 'e' &&
8701 return -KEY_getpeername;
8710 if (name[6] == 'o' &&
8716 return -KEY_getpriority;
8722 if (name[6] == 't' &&
8728 return -KEY_getprotoent;
8742 if (name[4] == 'o' &&
8750 return -KEY_getsockname;
8763 if (name[1] == 'e' &&
8771 if (name[6] == 'o' &&
8777 return -KEY_setpriority;
8783 if (name[6] == 't' &&
8789 return -KEY_setprotoent;
8805 case 12: /* 2 tokens of length 12 */
8806 if (name[0] == 'g' &&
8818 if (name[9] == 'd' &&
8821 { /* getnetbyaddr */
8822 return -KEY_getnetbyaddr;
8828 if (name[9] == 'a' &&
8831 { /* getnetbyname */
8832 return -KEY_getnetbyname;
8844 case 13: /* 4 tokens of length 13 */
8845 if (name[0] == 'g' &&
8852 if (name[4] == 'o' &&
8861 if (name[10] == 'd' &&
8864 { /* gethostbyaddr */
8865 return -KEY_gethostbyaddr;
8871 if (name[10] == 'a' &&
8874 { /* gethostbyname */
8875 return -KEY_gethostbyname;
8888 if (name[4] == 'e' &&
8897 if (name[10] == 'a' &&
8900 { /* getservbyname */
8901 return -KEY_getservbyname;
8907 if (name[10] == 'o' &&
8910 { /* getservbyport */
8911 return -KEY_getservbyport;
8930 case 14: /* 1 tokens of length 14 */
8931 if (name[0] == 'g' &&
8945 { /* getprotobyname */
8946 return -KEY_getprotobyname;
8951 case 16: /* 1 tokens of length 16 */
8952 if (name[0] == 'g' &&
8968 { /* getprotobynumber */
8969 return -KEY_getprotobynumber;
8983 S_checkcomma(pTHX_ register char *s, const char *name, const char *what)
8987 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
8988 if (ckWARN(WARN_SYNTAX)) {
8990 for (w = s+2; *w && level; w++) {
8997 for (; *w && isSPACE(*w); w++) ;
8998 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
8999 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
9000 "%s (...) interpreted as function",name);
9003 while (s < PL_bufend && isSPACE(*s))
9007 while (s < PL_bufend && isSPACE(*s))
9009 if (isIDFIRST_lazy_if(s,UTF)) {
9011 while (isALNUM_lazy_if(s,UTF))
9013 while (s < PL_bufend && isSPACE(*s))
9017 *s = '\0'; /* XXX If we didn't do this, we could const a lot of toke.c */
9018 kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
9022 Perl_croak(aTHX_ "No comma allowed after %s", what);
9027 /* Either returns sv, or mortalizes sv and returns a new SV*.
9028 Best used as sv=new_constant(..., sv, ...).
9029 If s, pv are NULL, calls subroutine with one argument,
9030 and type is used with error messages only. */
9033 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
9037 HV * const table = GvHV(PL_hintgv); /* ^H */
9041 const char *why1 = "", *why2 = "", *why3 = "";
9043 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
9046 why2 = strEQ(key,"charnames")
9047 ? "(possibly a missing \"use charnames ...\")"
9049 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
9050 (type ? type: "undef"), why2);
9052 /* This is convoluted and evil ("goto considered harmful")
9053 * but I do not understand the intricacies of all the different
9054 * failure modes of %^H in here. The goal here is to make
9055 * the most probable error message user-friendly. --jhi */
9060 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
9061 (type ? type: "undef"), why1, why2, why3);
9063 yyerror(SvPVX_const(msg));
9067 cvp = hv_fetch(table, key, strlen(key), FALSE);
9068 if (!cvp || !SvOK(*cvp)) {
9071 why3 = "} is not defined";
9074 sv_2mortal(sv); /* Parent created it permanently */
9077 pv = sv_2mortal(newSVpvn(s, len));
9079 typesv = sv_2mortal(newSVpv(type, 0));
9081 typesv = &PL_sv_undef;
9083 PUSHSTACKi(PERLSI_OVERLOAD);
9095 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
9099 /* Check the eval first */
9100 if (!PL_in_eval && SvTRUE(ERRSV)) {
9101 sv_catpv(ERRSV, "Propagated");
9102 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
9104 res = SvREFCNT_inc(sv);
9108 (void)SvREFCNT_inc(res);
9117 why1 = "Call to &{$^H{";
9119 why3 = "}} did not return a defined value";
9127 /* Returns a NUL terminated string, with the length of the string written to
9131 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
9133 register char *d = dest;
9134 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
9137 Perl_croak(aTHX_ ident_too_long);
9138 if (isALNUM(*s)) /* UTF handled below */
9140 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
9145 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
9149 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9150 char *t = s + UTF8SKIP(s);
9151 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9153 if (d + (t - s) > e)
9154 Perl_croak(aTHX_ ident_too_long);
9155 Copy(s, d, t - s, char);
9168 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
9172 char *bracket = Nullch;
9178 e = d + destlen - 3; /* two-character token, ending NUL */
9180 while (isDIGIT(*s)) {
9182 Perl_croak(aTHX_ ident_too_long);
9189 Perl_croak(aTHX_ ident_too_long);
9190 if (isALNUM(*s)) /* UTF handled below */
9192 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
9197 else if (*s == ':' && s[1] == ':') {
9201 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9202 char *t = s + UTF8SKIP(s);
9203 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9205 if (d + (t - s) > e)
9206 Perl_croak(aTHX_ ident_too_long);
9207 Copy(s, d, t - s, char);
9218 if (PL_lex_state != LEX_NORMAL)
9219 PL_lex_state = LEX_INTERPENDMAYBE;
9222 if (*s == '$' && s[1] &&
9223 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
9236 if (*d == '^' && *s && isCONTROLVAR(*s)) {
9241 if (isSPACE(s[-1])) {
9243 const char ch = *s++;
9244 if (!SPACE_OR_TAB(ch)) {
9250 if (isIDFIRST_lazy_if(d,UTF)) {
9254 while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') {
9256 while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e))
9259 Copy(s, d, e - s, char);
9264 while ((isALNUM(*s) || *s == ':') && d < e)
9267 Perl_croak(aTHX_ ident_too_long);
9270 while (s < send && SPACE_OR_TAB(*s)) s++;
9271 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
9272 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
9273 const char *brack = *s == '[' ? "[...]" : "{...}";
9274 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9275 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
9276 funny, dest, brack, funny, dest, brack);
9279 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
9283 /* Handle extended ${^Foo} variables
9284 * 1999-02-27 mjd-perl-patch@plover.com */
9285 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
9289 while (isALNUM(*s) && d < e) {
9293 Perl_croak(aTHX_ ident_too_long);
9298 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
9299 PL_lex_state = LEX_INTERPEND;
9304 if (PL_lex_state == LEX_NORMAL) {
9305 if (ckWARN(WARN_AMBIGUOUS) &&
9306 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
9308 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9309 "Ambiguous use of %c{%s} resolved to %c%s",
9310 funny, dest, funny, dest);
9315 s = bracket; /* let the parser handle it */
9319 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
9320 PL_lex_state = LEX_INTERPEND;
9325 Perl_pmflag(pTHX_ U32* pmfl, int ch)
9330 *pmfl |= PMf_GLOBAL;
9332 *pmfl |= PMf_CONTINUE;
9336 *pmfl |= PMf_MULTILINE;
9338 *pmfl |= PMf_SINGLELINE;
9340 *pmfl |= PMf_EXTENDED;
9344 S_scan_pat(pTHX_ char *start, I32 type)
9347 char *s = scan_str(start,FALSE,FALSE);
9350 char * const delimiter = skipspace(start);
9351 Perl_croak(aTHX_ *delimiter == '?'
9352 ? "Search pattern not terminated or ternary operator parsed as search pattern"
9353 : "Search pattern not terminated" );
9356 pm = (PMOP*)newPMOP(type, 0);
9357 if (PL_multi_open == '?')
9358 pm->op_pmflags |= PMf_ONCE;
9360 while (*s && strchr("iomsx", *s))
9361 pmflag(&pm->op_pmflags,*s++);
9364 while (*s && strchr("iogcmsx", *s))
9365 pmflag(&pm->op_pmflags,*s++);
9367 /* issue a warning if /c is specified,but /g is not */
9368 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
9369 && ckWARN(WARN_REGEXP))
9371 Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_without_g);
9374 pm->op_pmpermflags = pm->op_pmflags;
9376 PL_lex_op = (OP*)pm;
9377 yylval.ival = OP_MATCH;
9382 S_scan_subst(pTHX_ char *start)
9390 yylval.ival = OP_NULL;
9392 s = scan_str(start,FALSE,FALSE);
9395 Perl_croak(aTHX_ "Substitution pattern not terminated");
9397 if (s[-1] == PL_multi_open)
9400 first_start = PL_multi_start;
9401 s = scan_str(s,FALSE,FALSE);
9404 SvREFCNT_dec(PL_lex_stuff);
9405 PL_lex_stuff = Nullsv;
9407 Perl_croak(aTHX_ "Substitution replacement not terminated");
9409 PL_multi_start = first_start; /* so whole substitution is taken together */
9411 pm = (PMOP*)newPMOP(OP_SUBST, 0);
9417 else if (strchr("iogcmsx", *s))
9418 pmflag(&pm->op_pmflags,*s++);
9423 /* /c is not meaningful with s/// */
9424 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP))
9426 Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_in_subst);
9431 PL_sublex_info.super_bufptr = s;
9432 PL_sublex_info.super_bufend = PL_bufend;
9434 pm->op_pmflags |= PMf_EVAL;
9435 repl = newSVpvn("",0);
9437 sv_catpv(repl, es ? "eval " : "do ");
9438 sv_catpvn(repl, "{ ", 2);
9439 sv_catsv(repl, PL_lex_repl);
9440 sv_catpvn(repl, " };", 2);
9442 SvREFCNT_dec(PL_lex_repl);
9446 pm->op_pmpermflags = pm->op_pmflags;
9447 PL_lex_op = (OP*)pm;
9448 yylval.ival = OP_SUBST;
9453 S_scan_trans(pTHX_ char *start)
9462 yylval.ival = OP_NULL;
9464 s = scan_str(start,FALSE,FALSE);
9466 Perl_croak(aTHX_ "Transliteration pattern not terminated");
9467 if (s[-1] == PL_multi_open)
9470 s = scan_str(s,FALSE,FALSE);
9473 SvREFCNT_dec(PL_lex_stuff);
9474 PL_lex_stuff = Nullsv;
9476 Perl_croak(aTHX_ "Transliteration replacement not terminated");
9479 complement = del = squash = 0;
9483 complement = OPpTRANS_COMPLEMENT;
9486 del = OPpTRANS_DELETE;
9489 squash = OPpTRANS_SQUASH;
9498 Newx(tbl, complement&&!del?258:256, short);
9499 o = newPVOP(OP_TRANS, 0, (char*)tbl);
9500 o->op_private &= ~OPpTRANS_ALL;
9501 o->op_private |= del|squash|complement|
9502 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
9503 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
9506 yylval.ival = OP_TRANS;
9511 S_scan_heredoc(pTHX_ register char *s)
9514 I32 op_type = OP_SCALAR;
9518 const char newline[] = "\n";
9519 const char *found_newline;
9523 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
9527 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
9530 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
9531 if (*peek == '`' || *peek == '\'' || *peek =='"') {
9534 s = delimcpy(d, e, s, PL_bufend, term, &len);
9544 if (!isALNUM_lazy_if(s,UTF))
9545 deprecate_old("bare << to mean <<\"\"");
9546 for (; isALNUM_lazy_if(s,UTF); s++) {
9551 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
9552 Perl_croak(aTHX_ "Delimiter for here document is too long");
9555 len = d - PL_tokenbuf;
9556 #ifndef PERL_STRICT_CR
9557 d = strchr(s, '\r');
9559 char * const olds = s;
9561 while (s < PL_bufend) {
9567 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
9576 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
9580 if ( outer || !(found_newline = ninstr(s,PL_bufend,newline,newline+1)) ) {
9581 herewas = newSVpvn(s,PL_bufend-s);
9585 herewas = newSVpvn(s,found_newline-s);
9587 s += SvCUR(herewas);
9589 tmpstr = NEWSV(87,79);
9590 sv_upgrade(tmpstr, SVt_PVIV);
9593 SvIV_set(tmpstr, -1);
9595 else if (term == '`') {
9596 op_type = OP_BACKTICK;
9597 SvIV_set(tmpstr, '\\');
9601 PL_multi_start = CopLINE(PL_curcop);
9602 PL_multi_open = PL_multi_close = '<';
9603 term = *PL_tokenbuf;
9604 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
9605 char *bufptr = PL_sublex_info.super_bufptr;
9606 char *bufend = PL_sublex_info.super_bufend;
9607 char * const olds = s - SvCUR(herewas);
9608 s = strchr(bufptr, '\n');
9612 while (s < bufend &&
9613 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9615 CopLINE_inc(PL_curcop);
9618 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9619 missingterm(PL_tokenbuf);
9621 sv_setpvn(herewas,bufptr,d-bufptr+1);
9622 sv_setpvn(tmpstr,d+1,s-d);
9624 sv_catpvn(herewas,s,bufend-s);
9625 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
9632 while (s < PL_bufend &&
9633 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9635 CopLINE_inc(PL_curcop);
9637 if (s >= PL_bufend) {
9638 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9639 missingterm(PL_tokenbuf);
9641 sv_setpvn(tmpstr,d+1,s-d);
9643 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
9645 sv_catpvn(herewas,s,PL_bufend-s);
9646 sv_setsv(PL_linestr,herewas);
9647 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
9648 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9649 PL_last_lop = PL_last_uni = Nullch;
9652 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
9653 while (s >= PL_bufend) { /* multiple line string? */
9655 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
9656 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9657 missingterm(PL_tokenbuf);
9659 CopLINE_inc(PL_curcop);
9660 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9661 PL_last_lop = PL_last_uni = Nullch;
9662 #ifndef PERL_STRICT_CR
9663 if (PL_bufend - PL_linestart >= 2) {
9664 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
9665 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
9667 PL_bufend[-2] = '\n';
9669 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
9671 else if (PL_bufend[-1] == '\r')
9672 PL_bufend[-1] = '\n';
9674 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
9675 PL_bufend[-1] = '\n';
9677 if (PERLDB_LINE && PL_curstash != PL_debstash) {
9678 SV *sv = NEWSV(88,0);
9680 sv_upgrade(sv, SVt_PVMG);
9681 sv_setsv(sv,PL_linestr);
9684 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
9686 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
9687 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
9688 *(SvPVX(PL_linestr) + off ) = ' ';
9689 sv_catsv(PL_linestr,herewas);
9690 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9691 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
9695 sv_catsv(tmpstr,PL_linestr);
9700 PL_multi_end = CopLINE(PL_curcop);
9701 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
9702 SvPV_shrink_to_cur(tmpstr);
9704 SvREFCNT_dec(herewas);
9706 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
9708 else if (PL_encoding)
9709 sv_recode_to_utf8(tmpstr, PL_encoding);
9711 PL_lex_stuff = tmpstr;
9712 yylval.ival = op_type;
9717 takes: current position in input buffer
9718 returns: new position in input buffer
9719 side-effects: yylval and lex_op are set.
9724 <FH> read from filehandle
9725 <pkg::FH> read from package qualified filehandle
9726 <pkg'FH> read from package qualified filehandle
9727 <$fh> read from filehandle in $fh
9733 S_scan_inputsymbol(pTHX_ char *start)
9735 register char *s = start; /* current position in buffer */
9741 d = PL_tokenbuf; /* start of temp holding space */
9742 e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
9743 end = strchr(s, '\n');
9746 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
9748 /* die if we didn't have space for the contents of the <>,
9749 or if it didn't end, or if we see a newline
9752 if (len >= sizeof PL_tokenbuf)
9753 Perl_croak(aTHX_ "Excessively long <> operator");
9755 Perl_croak(aTHX_ "Unterminated <> operator");
9760 Remember, only scalar variables are interpreted as filehandles by
9761 this code. Anything more complex (e.g., <$fh{$num}>) will be
9762 treated as a glob() call.
9763 This code makes use of the fact that except for the $ at the front,
9764 a scalar variable and a filehandle look the same.
9766 if (*d == '$' && d[1]) d++;
9768 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
9769 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
9772 /* If we've tried to read what we allow filehandles to look like, and
9773 there's still text left, then it must be a glob() and not a getline.
9774 Use scan_str to pull out the stuff between the <> and treat it
9775 as nothing more than a string.
9778 if (d - PL_tokenbuf != len) {
9779 yylval.ival = OP_GLOB;
9781 s = scan_str(start,FALSE,FALSE);
9783 Perl_croak(aTHX_ "Glob not terminated");
9787 bool readline_overriden = FALSE;
9788 GV *gv_readline = Nullgv;
9790 /* we're in a filehandle read situation */
9793 /* turn <> into <ARGV> */
9795 Copy("ARGV",d,5,char);
9797 /* Check whether readline() is overriden */
9798 if (((gv_readline = gv_fetchpv("readline", FALSE, SVt_PVCV))
9799 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
9801 ((gvp = (GV**)hv_fetch(PL_globalstash, "readline", 8, FALSE))
9802 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
9803 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
9804 readline_overriden = TRUE;
9806 /* if <$fh>, create the ops to turn the variable into a
9812 /* try to find it in the pad for this block, otherwise find
9813 add symbol table ops
9815 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
9816 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
9817 HV *stash = PAD_COMPNAME_OURSTASH(tmp);
9818 HEK *stashname = HvNAME_HEK(stash);
9819 SV *sym = sv_2mortal(newSVhek(stashname));
9820 sv_catpvn(sym, "::", 2);
9826 OP *o = newOP(OP_PADSV, 0);
9828 PL_lex_op = readline_overriden
9829 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9830 append_elem(OP_LIST, o,
9831 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
9832 : (OP*)newUNOP(OP_READLINE, 0, o);
9841 ? (GV_ADDMULTI | GV_ADDINEVAL)
9844 PL_lex_op = readline_overriden
9845 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9846 append_elem(OP_LIST,
9847 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
9848 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9849 : (OP*)newUNOP(OP_READLINE, 0,
9850 newUNOP(OP_RV2SV, 0,
9851 newGVOP(OP_GV, 0, gv)));
9853 if (!readline_overriden)
9854 PL_lex_op->op_flags |= OPf_SPECIAL;
9855 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
9856 yylval.ival = OP_NULL;
9859 /* If it's none of the above, it must be a literal filehandle
9860 (<Foo::BAR> or <FOO>) so build a simple readline OP */
9862 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
9863 PL_lex_op = readline_overriden
9864 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9865 append_elem(OP_LIST,
9866 newGVOP(OP_GV, 0, gv),
9867 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9868 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
9869 yylval.ival = OP_NULL;
9878 takes: start position in buffer
9879 keep_quoted preserve \ on the embedded delimiter(s)
9880 keep_delims preserve the delimiters around the string
9881 returns: position to continue reading from buffer
9882 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
9883 updates the read buffer.
9885 This subroutine pulls a string out of the input. It is called for:
9886 q single quotes q(literal text)
9887 ' single quotes 'literal text'
9888 qq double quotes qq(interpolate $here please)
9889 " double quotes "interpolate $here please"
9890 qx backticks qx(/bin/ls -l)
9891 ` backticks `/bin/ls -l`
9892 qw quote words @EXPORT_OK = qw( func() $spam )
9893 m// regexp match m/this/
9894 s/// regexp substitute s/this/that/
9895 tr/// string transliterate tr/this/that/
9896 y/// string transliterate y/this/that/
9897 ($*@) sub prototypes sub foo ($)
9898 (stuff) sub attr parameters sub foo : attr(stuff)
9899 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
9901 In most of these cases (all but <>, patterns and transliterate)
9902 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
9903 calls scan_str(). s/// makes yylex() call scan_subst() which calls
9904 scan_str(). tr/// and y/// make yylex() call scan_trans() which
9907 It skips whitespace before the string starts, and treats the first
9908 character as the delimiter. If the delimiter is one of ([{< then
9909 the corresponding "close" character )]}> is used as the closing
9910 delimiter. It allows quoting of delimiters, and if the string has
9911 balanced delimiters ([{<>}]) it allows nesting.
9913 On success, the SV with the resulting string is put into lex_stuff or,
9914 if that is already non-NULL, into lex_repl. The second case occurs only
9915 when parsing the RHS of the special constructs s/// and tr/// (y///).
9916 For convenience, the terminating delimiter character is stuffed into
9921 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
9923 SV *sv; /* scalar value: string */
9924 char *tmps; /* temp string, used for delimiter matching */
9925 register char *s = start; /* current position in the buffer */
9926 register char term; /* terminating character */
9927 register char *to; /* current position in the sv's data */
9928 I32 brackets = 1; /* bracket nesting level */
9929 bool has_utf8 = FALSE; /* is there any utf8 content? */
9930 I32 termcode; /* terminating char. code */
9931 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
9932 STRLEN termlen; /* length of terminating string */
9933 char *last = NULL; /* last position for nesting bracket */
9935 /* skip space before the delimiter */
9939 /* mark where we are, in case we need to report errors */
9942 /* after skipping whitespace, the next character is the terminator */
9945 termcode = termstr[0] = term;
9949 termcode = utf8_to_uvchr((U8*)s, &termlen);
9950 Copy(s, termstr, termlen, U8);
9951 if (!UTF8_IS_INVARIANT(term))
9955 /* mark where we are */
9956 PL_multi_start = CopLINE(PL_curcop);
9957 PL_multi_open = term;
9959 /* find corresponding closing delimiter */
9960 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
9961 termcode = termstr[0] = term = tmps[5];
9963 PL_multi_close = term;
9965 /* create a new SV to hold the contents. 87 is leak category, I'm
9966 assuming. 79 is the SV's initial length. What a random number. */
9968 sv_upgrade(sv, SVt_PVIV);
9969 SvIV_set(sv, termcode);
9970 (void)SvPOK_only(sv); /* validate pointer */
9972 /* move past delimiter and try to read a complete string */
9974 sv_catpvn(sv, s, termlen);
9977 if (PL_encoding && !UTF) {
9981 int offset = s - SvPVX_const(PL_linestr);
9982 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
9983 &offset, (char*)termstr, termlen);
9984 const char *ns = SvPVX_const(PL_linestr) + offset;
9985 char *svlast = SvEND(sv) - 1;
9987 for (; s < ns; s++) {
9988 if (*s == '\n' && !PL_rsfp)
9989 CopLINE_inc(PL_curcop);
9992 goto read_more_line;
9994 /* handle quoted delimiters */
9995 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
9997 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
9999 if ((svlast-1 - t) % 2) {
10000 if (!keep_quoted) {
10001 *(svlast-1) = term;
10003 SvCUR_set(sv, SvCUR(sv) - 1);
10008 if (PL_multi_open == PL_multi_close) {
10016 for (t = w = last; t < svlast; w++, t++) {
10017 /* At here, all closes are "was quoted" one,
10018 so we don't check PL_multi_close. */
10020 if (!keep_quoted && *(t+1) == PL_multi_open)
10025 else if (*t == PL_multi_open)
10033 SvCUR_set(sv, w - SvPVX_const(sv));
10036 if (--brackets <= 0)
10041 if (!keep_delims) {
10042 SvCUR_set(sv, SvCUR(sv) - 1);
10048 /* extend sv if need be */
10049 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
10050 /* set 'to' to the next character in the sv's string */
10051 to = SvPVX(sv)+SvCUR(sv);
10053 /* if open delimiter is the close delimiter read unbridle */
10054 if (PL_multi_open == PL_multi_close) {
10055 for (; s < PL_bufend; s++,to++) {
10056 /* embedded newlines increment the current line number */
10057 if (*s == '\n' && !PL_rsfp)
10058 CopLINE_inc(PL_curcop);
10059 /* handle quoted delimiters */
10060 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
10061 if (!keep_quoted && s[1] == term)
10063 /* any other quotes are simply copied straight through */
10067 /* terminate when run out of buffer (the for() condition), or
10068 have found the terminator */
10069 else if (*s == term) {
10072 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
10075 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
10081 /* if the terminator isn't the same as the start character (e.g.,
10082 matched brackets), we have to allow more in the quoting, and
10083 be prepared for nested brackets.
10086 /* read until we run out of string, or we find the terminator */
10087 for (; s < PL_bufend; s++,to++) {
10088 /* embedded newlines increment the line count */
10089 if (*s == '\n' && !PL_rsfp)
10090 CopLINE_inc(PL_curcop);
10091 /* backslashes can escape the open or closing characters */
10092 if (*s == '\\' && s+1 < PL_bufend) {
10093 if (!keep_quoted &&
10094 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
10099 /* allow nested opens and closes */
10100 else if (*s == PL_multi_close && --brackets <= 0)
10102 else if (*s == PL_multi_open)
10104 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
10109 /* terminate the copied string and update the sv's end-of-string */
10111 SvCUR_set(sv, to - SvPVX_const(sv));
10114 * this next chunk reads more into the buffer if we're not done yet
10118 break; /* handle case where we are done yet :-) */
10120 #ifndef PERL_STRICT_CR
10121 if (to - SvPVX_const(sv) >= 2) {
10122 if ((to[-2] == '\r' && to[-1] == '\n') ||
10123 (to[-2] == '\n' && to[-1] == '\r'))
10127 SvCUR_set(sv, to - SvPVX_const(sv));
10129 else if (to[-1] == '\r')
10132 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
10137 /* if we're out of file, or a read fails, bail and reset the current
10138 line marker so we can report where the unterminated string began
10141 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
10143 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10146 /* we read a line, so increment our line counter */
10147 CopLINE_inc(PL_curcop);
10149 /* update debugger info */
10150 if (PERLDB_LINE && PL_curstash != PL_debstash) {
10151 SV *sv = NEWSV(88,0);
10153 sv_upgrade(sv, SVt_PVMG);
10154 sv_setsv(sv,PL_linestr);
10155 (void)SvIOK_on(sv);
10157 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
10160 /* having changed the buffer, we must update PL_bufend */
10161 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10162 PL_last_lop = PL_last_uni = Nullch;
10165 /* at this point, we have successfully read the delimited string */
10167 if (!PL_encoding || UTF) {
10169 sv_catpvn(sv, s, termlen);
10172 if (has_utf8 || PL_encoding)
10175 PL_multi_end = CopLINE(PL_curcop);
10177 /* if we allocated too much space, give some back */
10178 if (SvCUR(sv) + 5 < SvLEN(sv)) {
10179 SvLEN_set(sv, SvCUR(sv) + 1);
10180 SvPV_renew(sv, SvLEN(sv));
10183 /* decide whether this is the first or second quoted string we've read
10196 takes: pointer to position in buffer
10197 returns: pointer to new position in buffer
10198 side-effects: builds ops for the constant in yylval.op
10200 Read a number in any of the formats that Perl accepts:
10202 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
10203 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
10206 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
10208 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
10211 If it reads a number without a decimal point or an exponent, it will
10212 try converting the number to an integer and see if it can do so
10213 without loss of precision.
10217 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
10219 register const char *s = start; /* current position in buffer */
10220 register char *d; /* destination in temp buffer */
10221 register char *e; /* end of temp buffer */
10222 NV nv; /* number read, as a double */
10223 SV *sv = Nullsv; /* place to put the converted number */
10224 bool floatit; /* boolean: int or float? */
10225 const char *lastub = 0; /* position of last underbar */
10226 static char const number_too_long[] = "Number too long";
10228 /* We use the first character to decide what type of number this is */
10232 Perl_croak(aTHX_ "panic: scan_num");
10234 /* if it starts with a 0, it could be an octal number, a decimal in
10235 0.13 disguise, or a hexadecimal number, or a binary number. */
10239 u holds the "number so far"
10240 shift the power of 2 of the base
10241 (hex == 4, octal == 3, binary == 1)
10242 overflowed was the number more than we can hold?
10244 Shift is used when we add a digit. It also serves as an "are
10245 we in octal/hex/binary?" indicator to disallow hex characters
10246 when in octal mode.
10251 bool overflowed = FALSE;
10252 bool just_zero = TRUE; /* just plain 0 or binary number? */
10253 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
10254 static const char* const bases[5] =
10255 { "", "binary", "", "octal", "hexadecimal" };
10256 static const char* const Bases[5] =
10257 { "", "Binary", "", "Octal", "Hexadecimal" };
10258 static const char* const maxima[5] =
10260 "0b11111111111111111111111111111111",
10264 const char *base, *Base, *max;
10266 /* check for hex */
10271 } else if (s[1] == 'b') {
10276 /* check for a decimal in disguise */
10277 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
10279 /* so it must be octal */
10286 if (ckWARN(WARN_SYNTAX))
10287 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10288 "Misplaced _ in number");
10292 base = bases[shift];
10293 Base = Bases[shift];
10294 max = maxima[shift];
10296 /* read the rest of the number */
10298 /* x is used in the overflow test,
10299 b is the digit we're adding on. */
10304 /* if we don't mention it, we're done */
10308 /* _ are ignored -- but warned about if consecutive */
10310 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
10311 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10312 "Misplaced _ in number");
10316 /* 8 and 9 are not octal */
10317 case '8': case '9':
10319 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
10323 case '2': case '3': case '4':
10324 case '5': case '6': case '7':
10326 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
10329 case '0': case '1':
10330 b = *s++ & 15; /* ASCII digit -> value of digit */
10334 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
10335 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
10336 /* make sure they said 0x */
10339 b = (*s++ & 7) + 9;
10341 /* Prepare to put the digit we have onto the end
10342 of the number so far. We check for overflows.
10348 x = u << shift; /* make room for the digit */
10350 if ((x >> shift) != u
10351 && !(PL_hints & HINT_NEW_BINARY)) {
10354 if (ckWARN_d(WARN_OVERFLOW))
10355 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
10356 "Integer overflow in %s number",
10359 u = x | b; /* add the digit to the end */
10362 n *= nvshift[shift];
10363 /* If an NV has not enough bits in its
10364 * mantissa to represent an UV this summing of
10365 * small low-order numbers is a waste of time
10366 * (because the NV cannot preserve the
10367 * low-order bits anyway): we could just
10368 * remember when did we overflow and in the
10369 * end just multiply n by the right
10377 /* if we get here, we had success: make a scalar value from
10382 /* final misplaced underbar check */
10383 if (s[-1] == '_') {
10384 if (ckWARN(WARN_SYNTAX))
10385 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10390 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
10391 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10392 "%s number > %s non-portable",
10398 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
10399 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10400 "%s number > %s non-portable",
10405 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
10406 sv = new_constant(start, s - start, "integer",
10408 else if (PL_hints & HINT_NEW_BINARY)
10409 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
10414 handle decimal numbers.
10415 we're also sent here when we read a 0 as the first digit
10417 case '1': case '2': case '3': case '4': case '5':
10418 case '6': case '7': case '8': case '9': case '.':
10421 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
10424 /* read next group of digits and _ and copy into d */
10425 while (isDIGIT(*s) || *s == '_') {
10426 /* skip underscores, checking for misplaced ones
10430 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
10431 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10432 "Misplaced _ in number");
10436 /* check for end of fixed-length buffer */
10438 Perl_croak(aTHX_ number_too_long);
10439 /* if we're ok, copy the character */
10444 /* final misplaced underbar check */
10445 if (lastub && s == lastub + 1) {
10446 if (ckWARN(WARN_SYNTAX))
10447 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10450 /* read a decimal portion if there is one. avoid
10451 3..5 being interpreted as the number 3. followed
10454 if (*s == '.' && s[1] != '.') {
10459 if (ckWARN(WARN_SYNTAX))
10460 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10461 "Misplaced _ in number");
10465 /* copy, ignoring underbars, until we run out of digits.
10467 for (; isDIGIT(*s) || *s == '_'; s++) {
10468 /* fixed length buffer check */
10470 Perl_croak(aTHX_ number_too_long);
10472 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
10473 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10474 "Misplaced _ in number");
10480 /* fractional part ending in underbar? */
10481 if (s[-1] == '_') {
10482 if (ckWARN(WARN_SYNTAX))
10483 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10484 "Misplaced _ in number");
10486 if (*s == '.' && isDIGIT(s[1])) {
10487 /* oops, it's really a v-string, but without the "v" */
10493 /* read exponent part, if present */
10494 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
10498 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
10499 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
10501 /* stray preinitial _ */
10503 if (ckWARN(WARN_SYNTAX))
10504 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10505 "Misplaced _ in number");
10509 /* allow positive or negative exponent */
10510 if (*s == '+' || *s == '-')
10513 /* stray initial _ */
10515 if (ckWARN(WARN_SYNTAX))
10516 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10517 "Misplaced _ in number");
10521 /* read digits of exponent */
10522 while (isDIGIT(*s) || *s == '_') {
10525 Perl_croak(aTHX_ number_too_long);
10529 if (((lastub && s == lastub + 1) ||
10530 (!isDIGIT(s[1]) && s[1] != '_'))
10531 && ckWARN(WARN_SYNTAX))
10532 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10533 "Misplaced _ in number");
10540 /* make an sv from the string */
10544 We try to do an integer conversion first if no characters
10545 indicating "float" have been found.
10550 int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
10552 if (flags == IS_NUMBER_IN_UV) {
10554 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
10557 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
10558 if (uv <= (UV) IV_MIN)
10559 sv_setiv(sv, -(IV)uv);
10566 /* terminate the string */
10568 nv = Atof(PL_tokenbuf);
10572 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
10573 (PL_hints & HINT_NEW_INTEGER) )
10574 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
10575 (floatit ? "float" : "integer"),
10579 /* if it starts with a v, it could be a v-string */
10582 sv = NEWSV(92,5); /* preallocate storage space */
10583 s = scan_vstring(s,sv);
10587 /* make the op for the constant and return */
10590 lvalp->opval = newSVOP(OP_CONST, 0, sv);
10592 lvalp->opval = Nullop;
10598 S_scan_formline(pTHX_ register char *s)
10600 register char *eol;
10602 SV *stuff = newSVpvn("",0);
10603 bool needargs = FALSE;
10604 bool eofmt = FALSE;
10606 while (!needargs) {
10608 #ifdef PERL_STRICT_CR
10609 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
10611 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
10613 if (*t == '\n' || t == PL_bufend) {
10618 if (PL_in_eval && !PL_rsfp) {
10619 eol = (char *) memchr(s,'\n',PL_bufend-s);
10624 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10626 for (t = s; t < eol; t++) {
10627 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
10629 goto enough; /* ~~ must be first line in formline */
10631 if (*t == '@' || *t == '^')
10635 sv_catpvn(stuff, s, eol-s);
10636 #ifndef PERL_STRICT_CR
10637 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
10638 char *end = SvPVX(stuff) + SvCUR(stuff);
10641 SvCUR_set(stuff, SvCUR(stuff) - 1);
10650 s = filter_gets(PL_linestr, PL_rsfp, 0);
10651 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
10652 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
10653 PL_last_lop = PL_last_uni = Nullch;
10662 if (SvCUR(stuff)) {
10665 PL_lex_state = LEX_NORMAL;
10666 PL_nextval[PL_nexttoke].ival = 0;
10670 PL_lex_state = LEX_FORMLINE;
10672 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
10674 else if (PL_encoding)
10675 sv_recode_to_utf8(stuff, PL_encoding);
10677 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
10679 PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
10683 SvREFCNT_dec(stuff);
10685 PL_lex_formbrack = 0;
10696 PL_cshlen = strlen(PL_cshname);
10701 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
10703 const I32 oldsavestack_ix = PL_savestack_ix;
10704 CV* outsidecv = PL_compcv;
10707 assert(SvTYPE(PL_compcv) == SVt_PVCV);
10709 SAVEI32(PL_subline);
10710 save_item(PL_subname);
10711 SAVESPTR(PL_compcv);
10713 PL_compcv = (CV*)NEWSV(1104,0);
10714 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
10715 CvFLAGS(PL_compcv) |= flags;
10717 PL_subline = CopLINE(PL_curcop);
10718 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
10719 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
10720 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
10722 return oldsavestack_ix;
10726 #pragma segment Perl_yylex
10729 Perl_yywarn(pTHX_ const char *s)
10731 PL_in_eval |= EVAL_WARNONLY;
10733 PL_in_eval &= ~EVAL_WARNONLY;
10738 Perl_yyerror(pTHX_ const char *s)
10740 const char *where = NULL;
10741 const char *context = NULL;
10745 if (!yychar || (yychar == ';' && !PL_rsfp))
10747 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
10748 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
10749 PL_oldbufptr != PL_bufptr) {
10752 The code below is removed for NetWare because it abends/crashes on NetWare
10753 when the script has error such as not having the closing quotes like:
10754 if ($var eq "value)
10755 Checking of white spaces is anyway done in NetWare code.
10758 while (isSPACE(*PL_oldoldbufptr))
10761 context = PL_oldoldbufptr;
10762 contlen = PL_bufptr - PL_oldoldbufptr;
10764 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
10765 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
10768 The code below is removed for NetWare because it abends/crashes on NetWare
10769 when the script has error such as not having the closing quotes like:
10770 if ($var eq "value)
10771 Checking of white spaces is anyway done in NetWare code.
10774 while (isSPACE(*PL_oldbufptr))
10777 context = PL_oldbufptr;
10778 contlen = PL_bufptr - PL_oldbufptr;
10780 else if (yychar > 255)
10781 where = "next token ???";
10782 else if (yychar == -2) { /* YYEMPTY */
10783 if (PL_lex_state == LEX_NORMAL ||
10784 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
10785 where = "at end of line";
10786 else if (PL_lex_inpat)
10787 where = "within pattern";
10789 where = "within string";
10792 SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
10794 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
10795 else if (isPRINT_LC(yychar))
10796 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
10798 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
10799 where = SvPVX_const(where_sv);
10801 msg = sv_2mortal(newSVpv(s, 0));
10802 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
10803 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
10805 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
10807 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
10808 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
10809 Perl_sv_catpvf(aTHX_ msg,
10810 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
10811 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
10814 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
10815 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg);
10818 if (PL_error_count >= 10) {
10819 if (PL_in_eval && SvCUR(ERRSV))
10820 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
10821 ERRSV, OutCopFILE(PL_curcop));
10823 Perl_croak(aTHX_ "%s has too many errors.\n",
10824 OutCopFILE(PL_curcop));
10827 PL_in_my_stash = Nullhv;
10831 #pragma segment Main
10835 S_swallow_bom(pTHX_ U8 *s)
10837 const STRLEN slen = SvCUR(PL_linestr);
10840 if (s[1] == 0xFE) {
10841 /* UTF-16 little-endian? (or UTF32-LE?) */
10842 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
10843 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
10844 #ifndef PERL_NO_UTF16_FILTER
10845 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
10848 if (PL_bufend > (char*)s) {
10852 filter_add(utf16rev_textfilter, NULL);
10853 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10854 utf16_to_utf8_reversed(s, news,
10855 PL_bufend - (char*)s - 1,
10857 sv_setpvn(PL_linestr, (const char*)news, newlen);
10859 SvUTF8_on(PL_linestr);
10860 s = (U8*)SvPVX(PL_linestr);
10861 PL_bufend = SvPVX(PL_linestr) + newlen;
10864 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
10869 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
10870 #ifndef PERL_NO_UTF16_FILTER
10871 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
10874 if (PL_bufend > (char *)s) {
10878 filter_add(utf16_textfilter, NULL);
10879 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10880 utf16_to_utf8(s, news,
10881 PL_bufend - (char*)s,
10883 sv_setpvn(PL_linestr, (const char*)news, newlen);
10885 SvUTF8_on(PL_linestr);
10886 s = (U8*)SvPVX(PL_linestr);
10887 PL_bufend = SvPVX(PL_linestr) + newlen;
10890 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
10895 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
10896 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
10897 s += 3; /* UTF-8 */
10903 if (s[2] == 0xFE && s[3] == 0xFF) {
10904 /* UTF-32 big-endian */
10905 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
10908 else if (s[2] == 0 && s[3] != 0) {
10911 * are a good indicator of UTF-16BE. */
10912 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
10917 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
10920 * are a good indicator of UTF-16LE. */
10921 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
10930 * Restore a source filter.
10934 restore_rsfp(pTHX_ void *f)
10936 PerlIO *fp = (PerlIO*)f;
10938 if (PL_rsfp == PerlIO_stdin())
10939 PerlIO_clearerr(PL_rsfp);
10940 else if (PL_rsfp && (PL_rsfp != fp))
10941 PerlIO_close(PL_rsfp);
10945 #ifndef PERL_NO_UTF16_FILTER
10947 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10949 const STRLEN old = SvCUR(sv);
10950 const I32 count = FILTER_READ(idx+1, sv, maxlen);
10951 DEBUG_P(PerlIO_printf(Perl_debug_log,
10952 "utf16_textfilter(%p): %d %d (%d)\n",
10953 utf16_textfilter, idx, maxlen, (int) count));
10957 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10958 Copy(SvPVX_const(sv), tmps, old, char);
10959 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
10960 SvCUR(sv) - old, &newlen);
10961 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10963 DEBUG_P({sv_dump(sv);});
10968 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10970 const STRLEN old = SvCUR(sv);
10971 const I32 count = FILTER_READ(idx+1, sv, maxlen);
10972 DEBUG_P(PerlIO_printf(Perl_debug_log,
10973 "utf16rev_textfilter(%p): %d %d (%d)\n",
10974 utf16rev_textfilter, idx, maxlen, (int) count));
10978 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10979 Copy(SvPVX_const(sv), tmps, old, char);
10980 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
10981 SvCUR(sv) - old, &newlen);
10982 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10984 DEBUG_P({ sv_dump(sv); });
10990 Returns a pointer to the next character after the parsed
10991 vstring, as well as updating the passed in sv.
10993 Function must be called like
10996 s = scan_vstring(s,sv);
10998 The sv should already be large enough to store the vstring
10999 passed in, for performance reasons.
11004 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
11006 const char *pos = s;
11007 const char *start = s;
11008 if (*pos == 'v') pos++; /* get past 'v' */
11009 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
11011 if ( *pos != '.') {
11012 /* this may not be a v-string if followed by => */
11013 const char *next = pos;
11014 while (next < PL_bufend && isSPACE(*next))
11016 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
11017 /* return string not v-string */
11018 sv_setpvn(sv,(char *)s,pos-s);
11019 return (char *)pos;
11023 if (!isALPHA(*pos)) {
11025 U8 tmpbuf[UTF8_MAXBYTES+1];
11028 if (*s == 'v') s++; /* get past 'v' */
11030 sv_setpvn(sv, "", 0);
11035 /* this is atoi() that tolerates underscores */
11036 const char *end = pos;
11038 while (--end >= s) {
11043 rev += (*end - '0') * mult;
11045 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
11046 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11047 "Integer overflow in decimal number");
11051 if (rev > 0x7FFFFFFF)
11052 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
11054 /* Append native character for the rev point */
11055 tmpend = uvchr_to_utf8(tmpbuf, rev);
11056 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
11057 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
11059 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
11065 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
11069 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
11077 * c-indentation-style: bsd
11078 * c-basic-offset: 4
11079 * indent-tabs-mode: t
11082 * ex: set ts=8 sts=4 sw=4 noet: