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_yychar
27 #define yylval PL_yylval
29 static char const ident_too_long[] = "Identifier too long";
30 static char const c_without_g[] = "Use of /c modifier is meaningless without /g";
31 static char const c_in_subst[] = "Use of /c modifier is meaningless in s///";
33 static void restore_rsfp(pTHX_ void *f);
34 #ifndef PERL_NO_UTF16_FILTER
35 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
36 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
39 #define XFAKEBRACK 128
42 #ifdef USE_UTF8_SCRIPTS
43 # define UTF (!IN_BYTES)
45 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
48 /* In variables named $^X, these are the legal values for X.
49 * 1999-02-27 mjd-perl-patch@plover.com */
50 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
52 /* On MacOS, respect nonbreaking spaces */
53 #ifdef MACOS_TRADITIONAL
54 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
56 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
59 /* LEX_* are values for PL_lex_state, the state of the lexer.
60 * They are arranged oddly so that the guard on the switch statement
61 * can get by with a single comparison (if the compiler is smart enough).
64 /* #define LEX_NOTPARSING 11 is done in perl.h. */
67 #define LEX_INTERPNORMAL 9
68 #define LEX_INTERPCASEMOD 8
69 #define LEX_INTERPPUSH 7
70 #define LEX_INTERPSTART 6
71 #define LEX_INTERPEND 5
72 #define LEX_INTERPENDMAYBE 4
73 #define LEX_INTERPCONCAT 3
74 #define LEX_INTERPCONST 2
75 #define LEX_FORMLINE 1
76 #define LEX_KNOWNEXT 0
79 static char const* lex_state_names[] = {
100 # define YYMAXLEVEL 100
102 YYSTYPE* yylval_pointer[YYMAXLEVEL];
103 int* yychar_pointer[YYMAXLEVEL];
107 # define yylval (*yylval_pointer[yyactlevel])
108 # define yychar (*yychar_pointer[yyactlevel])
109 # define PERL_YYLEX_PARAM yylval_pointer[yyactlevel],yychar_pointer[yyactlevel]
111 # define yylex() Perl_yylex_r(aTHX_ yylval_pointer[yyactlevel],yychar_pointer[yyactlevel])
114 #include "keywords.h"
116 /* CLINE is a macro that ensures PL_copline has a sane value */
121 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
124 * Convenience functions to return different tokens and prime the
125 * lexer for the next token. They all take an argument.
127 * TOKEN : generic token (used for '(', DOLSHARP, etc)
128 * OPERATOR : generic operator
129 * AOPERATOR : assignment operator
130 * PREBLOCK : beginning the block after an if, while, foreach, ...
131 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
132 * PREREF : *EXPR where EXPR is not a simple identifier
133 * TERM : expression term
134 * LOOPX : loop exiting command (goto, last, dump, etc)
135 * FTST : file test operator
136 * FUN0 : zero-argument function
137 * FUN1 : not used, except for not, which isn't a UNIOP
138 * BOop : bitwise or or xor
140 * SHop : shift operator
141 * PWop : power operator
142 * PMop : pattern-matching operator
143 * Aop : addition-level operator
144 * Mop : multiplication-level operator
145 * Eop : equality-testing operator
146 * Rop : relational operator <= != gt
148 * Also see LOP and lop() below.
151 #ifdef DEBUGGING /* Serve -DT. */
152 # define REPORT(retval) tokereport(s,(int)retval)
154 # define REPORT(retval) (retval)
157 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
158 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
159 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
160 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
161 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
162 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
163 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
164 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
165 #define FTST(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)UNIOP))
166 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
167 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
168 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
169 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
170 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
171 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
172 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
173 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
174 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
175 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
176 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
178 /* This bit of chicanery makes a unary function followed by
179 * a parenthesis into a function with one argument, highest precedence.
185 PL_last_uni = PL_oldbufptr; \
186 PL_last_lop_op = f; \
188 return REPORT( (int)FUNC1 ); \
190 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
193 #define UNIBRACK(f) { \
196 PL_last_uni = PL_oldbufptr; \
198 return REPORT( (int)FUNC1 ); \
200 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
203 /* grandfather return to old style */
204 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
208 /* how to interpret the yylval associated with the token */
212 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
218 static struct debug_tokens { const int token, type; const char *name; } debug_tokens[] =
220 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
221 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
222 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
223 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
224 { ARROW, TOKENTYPE_NONE, "ARROW" },
225 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
226 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
227 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
228 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
229 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
230 { DO, TOKENTYPE_NONE, "DO" },
231 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
232 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
233 { ELSE, TOKENTYPE_NONE, "ELSE" },
234 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
235 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
236 { FOR, TOKENTYPE_IVAL, "FOR" },
237 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
238 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
239 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
240 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
241 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
242 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
243 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
244 { IF, TOKENTYPE_IVAL, "IF" },
245 { LABEL, TOKENTYPE_PVAL, "LABEL" },
246 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
247 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
248 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
249 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
250 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
251 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
252 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
253 { MY, TOKENTYPE_IVAL, "MY" },
254 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
255 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
256 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
257 { OROP, TOKENTYPE_IVAL, "OROP" },
258 { OROR, TOKENTYPE_NONE, "OROR" },
259 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
260 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
261 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
262 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
263 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
264 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
265 { PREINC, TOKENTYPE_NONE, "PREINC" },
266 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
267 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
268 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
269 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
270 { SUB, TOKENTYPE_NONE, "SUB" },
271 { THING, TOKENTYPE_OPVAL, "THING" },
272 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
273 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
274 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
275 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
276 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
277 { USE, TOKENTYPE_IVAL, "USE" },
278 { WHILE, TOKENTYPE_IVAL, "WHILE" },
279 { WORD, TOKENTYPE_OPVAL, "WORD" },
280 { 0, TOKENTYPE_NONE, 0 }
283 /* dump the returned token in rv, plus any optional arg in yylval */
286 S_tokereport(pTHX_ const char* s, I32 rv)
289 const char *name = Nullch;
290 enum token_type type = TOKENTYPE_NONE;
291 const struct debug_tokens *p;
292 SV* report = newSVpvn("<== ", 4);
294 for (p = debug_tokens; p->token; p++) {
295 if (p->token == (int)rv) {
302 Perl_sv_catpvf(aTHX_ report, "%s", name);
303 else if ((char)rv > ' ' && (char)rv < '~')
304 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
306 Perl_sv_catpvf(aTHX_ report, "EOF");
308 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
311 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
314 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", yylval.ival);
316 case TOKENTYPE_OPNUM:
317 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
318 PL_op_name[yylval.ival]);
321 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
323 case TOKENTYPE_OPVAL:
325 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
326 PL_op_name[yylval.opval->op_type]);
328 Perl_sv_catpv(aTHX_ report, "(opval=null)");
331 Perl_sv_catpvf(aTHX_ report, " at line %d [", CopLINE(PL_curcop));
332 if (s - PL_bufptr > 0)
333 sv_catpvn(report, PL_bufptr, s - PL_bufptr);
335 if (PL_oldbufptr && *PL_oldbufptr)
336 sv_catpv(report, PL_tokenbuf);
338 PerlIO_printf(Perl_debug_log, "### %s]\n", SvPV_nolen_const(report));
348 * This subroutine detects &&= and ||= and turns an ANDAND or OROR
349 * into an OP_ANDASSIGN or OP_ORASSIGN
353 S_ao(pTHX_ int toketype)
355 if (*PL_bufptr == '=') {
357 if (toketype == ANDAND)
358 yylval.ival = OP_ANDASSIGN;
359 else if (toketype == OROR)
360 yylval.ival = OP_ORASSIGN;
368 * When Perl expects an operator and finds something else, no_op
369 * prints the warning. It always prints "<something> found where
370 * operator expected. It prints "Missing semicolon on previous line?"
371 * if the surprise occurs at the start of the line. "do you need to
372 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
373 * where the compiler doesn't know if foo is a method call or a function.
374 * It prints "Missing operator before end of line" if there's nothing
375 * after the missing operator, or "... before <...>" if there is something
376 * after the missing operator.
380 S_no_op(pTHX_ const char *what, char *s)
382 char *oldbp = PL_bufptr;
383 bool is_first = (PL_oldbufptr == PL_linestart);
389 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
390 if (ckWARN_d(WARN_SYNTAX)) {
392 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
393 "\t(Missing semicolon on previous line?)\n");
394 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
396 for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
397 if (t < PL_bufptr && isSPACE(*t))
398 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
399 "\t(Do you need to predeclare %.*s?)\n",
400 t - PL_oldoldbufptr, PL_oldoldbufptr);
404 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
405 "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
413 * Complain about missing quote/regexp/heredoc terminator.
414 * If it's called with (char *)NULL then it cauterizes the line buffer.
415 * If we're in a delimited string and the delimiter is a control
416 * character, it's reformatted into a two-char sequence like ^C.
421 S_missingterm(pTHX_ char *s)
426 char *nl = strrchr(s,'\n');
432 iscntrl(PL_multi_close)
434 PL_multi_close < 32 || PL_multi_close == 127
438 tmpbuf[1] = toCTRL(PL_multi_close);
443 *tmpbuf = (char)PL_multi_close;
447 q = strchr(s,'"') ? '\'' : '"';
448 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
456 Perl_deprecate(pTHX_ char *s)
458 if (ckWARN(WARN_DEPRECATED))
459 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
463 Perl_deprecate_old(pTHX_ char *s)
465 /* This function should NOT be called for any new deprecated warnings */
466 /* Use Perl_deprecate instead */
468 /* It is here to maintain backward compatibility with the pre-5.8 */
469 /* warnings category hierarchy. The "deprecated" category used to */
470 /* live under the "syntax" category. It is now a top-level category */
471 /* in its own right. */
473 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
474 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
475 "Use of %s is deprecated", s);
480 * Deprecate a comma-less variable list.
486 deprecate_old("comma-less variable list");
490 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
491 * utf16-to-utf8-reversed.
494 #ifdef PERL_CR_FILTER
498 register const char *s = SvPVX_const(sv);
499 register const char *e = s + SvCUR(sv);
500 /* outer loop optimized to do nothing if there are no CR-LFs */
502 if (*s++ == '\r' && *s == '\n') {
503 /* hit a CR-LF, need to copy the rest */
504 register char *d = s - 1;
507 if (*s == '\r' && s[1] == '\n')
518 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
520 const I32 count = FILTER_READ(idx+1, sv, maxlen);
521 if (count > 0 && !maxlen)
529 * Initialize variables. Uses the Perl save_stack to save its state (for
530 * recursive calls to the parser).
534 Perl_lex_start(pTHX_ SV *line)
539 SAVEI32(PL_lex_dojoin);
540 SAVEI32(PL_lex_brackets);
541 SAVEI32(PL_lex_casemods);
542 SAVEI32(PL_lex_starts);
543 SAVEI32(PL_lex_state);
544 SAVEVPTR(PL_lex_inpat);
545 SAVEI32(PL_lex_inwhat);
546 if (PL_lex_state == LEX_KNOWNEXT) {
547 I32 toke = PL_nexttoke;
548 while (--toke >= 0) {
549 SAVEI32(PL_nexttype[toke]);
550 SAVEVPTR(PL_nextval[toke]);
552 SAVEI32(PL_nexttoke);
554 SAVECOPLINE(PL_curcop);
557 SAVEPPTR(PL_oldbufptr);
558 SAVEPPTR(PL_oldoldbufptr);
559 SAVEPPTR(PL_last_lop);
560 SAVEPPTR(PL_last_uni);
561 SAVEPPTR(PL_linestart);
562 SAVESPTR(PL_linestr);
563 SAVEGENERICPV(PL_lex_brackstack);
564 SAVEGENERICPV(PL_lex_casestack);
565 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
566 SAVESPTR(PL_lex_stuff);
567 SAVEI32(PL_lex_defer);
568 SAVEI32(PL_sublex_info.sub_inwhat);
569 SAVESPTR(PL_lex_repl);
571 SAVEINT(PL_lex_expect);
573 PL_lex_state = LEX_NORMAL;
577 New(899, PL_lex_brackstack, 120, char);
578 New(899, PL_lex_casestack, 12, char);
580 *PL_lex_casestack = '\0';
583 PL_lex_stuff = Nullsv;
584 PL_lex_repl = Nullsv;
588 PL_sublex_info.sub_inwhat = 0;
590 if (SvREADONLY(PL_linestr))
591 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
592 s = SvPV_const(PL_linestr, len);
593 if (!len || s[len-1] != ';') {
594 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
595 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
596 sv_catpvn(PL_linestr, "\n;", 2);
598 SvTEMP_off(PL_linestr);
599 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
600 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
601 PL_last_lop = PL_last_uni = Nullch;
607 * Finalizer for lexing operations. Must be called when the parser is
608 * done with the lexer.
614 PL_doextract = FALSE;
619 * This subroutine has nothing to do with tilting, whether at windmills
620 * or pinball tables. Its name is short for "increment line". It
621 * increments the current line number in CopLINE(PL_curcop) and checks
622 * to see whether the line starts with a comment of the form
623 * # line 500 "foo.pm"
624 * If so, it sets the current line number and file to the values in the comment.
628 S_incline(pTHX_ char *s)
635 CopLINE_inc(PL_curcop);
638 while (SPACE_OR_TAB(*s)) s++;
639 if (strnEQ(s, "line", 4))
643 if (SPACE_OR_TAB(*s))
647 while (SPACE_OR_TAB(*s)) s++;
653 while (SPACE_OR_TAB(*s))
655 if (*s == '"' && (t = strchr(s+1, '"'))) {
660 for (t = s; !isSPACE(*t); t++) ;
663 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
665 if (*e != '\n' && *e != '\0')
666 return; /* false alarm */
671 CopFILE_free(PL_curcop);
672 CopFILE_set(PL_curcop, s);
675 CopLINE_set(PL_curcop, atoi(n)-1);
680 * Called to gobble the appropriate amount and type of whitespace.
681 * Skips comments as well.
685 S_skipspace(pTHX_ register char *s)
687 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
688 while (s < PL_bufend && SPACE_OR_TAB(*s))
694 SSize_t oldprevlen, oldoldprevlen;
695 SSize_t oldloplen = 0, oldunilen = 0;
696 while (s < PL_bufend && isSPACE(*s)) {
697 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
702 if (s < PL_bufend && *s == '#') {
703 while (s < PL_bufend && *s != '\n')
707 if (PL_in_eval && !PL_rsfp) {
714 /* only continue to recharge the buffer if we're at the end
715 * of the buffer, we're not reading from a source filter, and
716 * we're in normal lexing mode
718 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
719 PL_lex_state == LEX_FORMLINE)
722 /* try to recharge the buffer */
723 if ((s = filter_gets(PL_linestr, PL_rsfp,
724 (prevlen = SvCUR(PL_linestr)))) == Nullch)
726 /* end of file. Add on the -p or -n magic */
729 ";}continue{print or die qq(-p destination: $!\\n);}");
730 PL_minus_n = PL_minus_p = 0;
732 else if (PL_minus_n) {
733 sv_setpvn(PL_linestr, ";}", 2);
737 sv_setpvn(PL_linestr,";", 1);
739 /* reset variables for next time we lex */
740 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
742 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
743 PL_last_lop = PL_last_uni = Nullch;
745 /* Close the filehandle. Could be from -P preprocessor,
746 * STDIN, or a regular file. If we were reading code from
747 * STDIN (because the commandline held no -e or filename)
748 * then we don't close it, we reset it so the code can
749 * read from STDIN too.
752 if (PL_preprocess && !PL_in_eval)
753 (void)PerlProc_pclose(PL_rsfp);
754 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
755 PerlIO_clearerr(PL_rsfp);
757 (void)PerlIO_close(PL_rsfp);
762 /* not at end of file, so we only read another line */
763 /* make corresponding updates to old pointers, for yyerror() */
764 oldprevlen = PL_oldbufptr - PL_bufend;
765 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
767 oldunilen = PL_last_uni - PL_bufend;
769 oldloplen = PL_last_lop - PL_bufend;
770 PL_linestart = PL_bufptr = s + prevlen;
771 PL_bufend = s + SvCUR(PL_linestr);
773 PL_oldbufptr = s + oldprevlen;
774 PL_oldoldbufptr = s + oldoldprevlen;
776 PL_last_uni = s + oldunilen;
778 PL_last_lop = s + oldloplen;
781 /* debugger active and we're not compiling the debugger code,
782 * so store the line into the debugger's array of lines
784 if (PERLDB_LINE && PL_curstash != PL_debstash) {
785 SV *sv = NEWSV(85,0);
787 sv_upgrade(sv, SVt_PVMG);
788 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
791 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
798 * Check the unary operators to ensure there's no ambiguity in how they're
799 * used. An ambiguous piece of code would be:
801 * This doesn't mean rand() + 5. Because rand() is a unary operator,
802 * the +5 is its argument.
811 if (PL_oldoldbufptr != PL_last_uni)
813 while (isSPACE(*PL_last_uni))
815 for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
816 if ((t = strchr(s, '(')) && t < PL_bufptr)
818 if (ckWARN_d(WARN_AMBIGUOUS)){
821 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
822 "Warning: Use of \"%s\" without parentheses is ambiguous",
829 * LOP : macro to build a list operator. Its behaviour has been replaced
830 * with a subroutine, S_lop() for which LOP is just another name.
833 #define LOP(f,x) return lop(f,x,s)
837 * Build a list operator (or something that might be one). The rules:
838 * - if we have a next token, then it's a list operator [why?]
839 * - if the next thing is an opening paren, then it's a function
840 * - else it's a list operator
844 S_lop(pTHX_ I32 f, int x, char *s)
850 PL_last_lop = PL_oldbufptr;
851 PL_last_lop_op = (OPCODE)f;
853 return REPORT(LSTOP);
860 return REPORT(LSTOP);
865 * When the lexer realizes it knows the next token (for instance,
866 * it is reordering tokens for the parser) then it can call S_force_next
867 * to know what token to return the next time the lexer is called. Caller
868 * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer
869 * handles the token correctly.
873 S_force_next(pTHX_ I32 type)
875 PL_nexttype[PL_nexttoke] = type;
877 if (PL_lex_state != LEX_KNOWNEXT) {
878 PL_lex_defer = PL_lex_state;
879 PL_lex_expect = PL_expect;
880 PL_lex_state = LEX_KNOWNEXT;
886 * When the lexer knows the next thing is a word (for instance, it has
887 * just seen -> and it knows that the next char is a word char, then
888 * it calls S_force_word to stick the next word into the PL_next lookahead.
891 * char *start : buffer position (must be within PL_linestr)
892 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
893 * int check_keyword : if true, Perl checks to make sure the word isn't
894 * a keyword (do this if the word is a label, e.g. goto FOO)
895 * int allow_pack : if true, : characters will also be allowed (require,
897 * int allow_initial_tick : used by the "sub" lexer only.
901 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
906 start = skipspace(start);
908 if (isIDFIRST_lazy_if(s,UTF) ||
909 (allow_pack && *s == ':') ||
910 (allow_initial_tick && *s == '\'') )
912 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
913 if (check_keyword && keyword(PL_tokenbuf, len))
915 if (token == METHOD) {
920 PL_expect = XOPERATOR;
923 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(PL_tokenbuf,0));
924 PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
925 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
926 SvUTF8_on(((SVOP*)PL_nextval[PL_nexttoke].opval)->op_sv);
934 * Called when the lexer wants $foo *foo &foo etc, but the program
935 * text only contains the "foo" portion. The first argument is a pointer
936 * to the "foo", and the second argument is the type symbol to prefix.
937 * Forces the next token to be a "WORD".
938 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
942 S_force_ident(pTHX_ register const char *s, int kind)
945 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
946 PL_nextval[PL_nexttoke].opval = o;
949 o->op_private = OPpCONST_ENTERED;
950 /* XXX see note in pp_entereval() for why we forgo typo
951 warnings if the symbol must be introduced in an eval.
953 gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
954 kind == '$' ? SVt_PV :
955 kind == '@' ? SVt_PVAV :
956 kind == '%' ? SVt_PVHV :
964 Perl_str_to_version(pTHX_ SV *sv)
969 const char *start = SvPV_const(sv,len);
970 const char *end = start + len;
971 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
972 while (start < end) {
976 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
981 retval += ((NV)n)/nshift;
990 * Forces the next token to be a version number.
991 * If the next token appears to be an invalid version number, (e.g. "v2b"),
992 * and if "guessing" is TRUE, then no new token is created (and the caller
993 * must use an alternative parsing method).
997 S_force_version(pTHX_ char *s, int guessing)
999 OP *version = Nullop;
1008 while (isDIGIT(*d) || *d == '_' || *d == '.')
1010 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1012 s = scan_num(s, &yylval);
1013 version = yylval.opval;
1014 ver = cSVOPx(version)->op_sv;
1015 if (SvPOK(ver) && !SvNIOK(ver)) {
1016 (void)SvUPGRADE(ver, SVt_PVNV);
1017 SvNV_set(ver, str_to_version(ver));
1018 SvNOK_on(ver); /* hint that it is a version */
1025 /* NOTE: The parser sees the package name and the VERSION swapped */
1026 PL_nextval[PL_nexttoke].opval = version;
1034 * Tokenize a quoted string passed in as an SV. It finds the next
1035 * chunk, up to end of string or a backslash. It may make a new
1036 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1041 S_tokeq(pTHX_ SV *sv)
1044 register char *send;
1052 s = SvPV_force(sv, len);
1053 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1056 while (s < send && *s != '\\')
1061 if ( PL_hints & HINT_NEW_STRING ) {
1062 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1068 if (s + 1 < send && (s[1] == '\\'))
1069 s++; /* all that, just for this */
1074 SvCUR_set(sv, d - SvPVX_const(sv));
1076 if ( PL_hints & HINT_NEW_STRING )
1077 return new_constant(NULL, 0, "q", sv, pv, "q");
1082 * Now come three functions related to double-quote context,
1083 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1084 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1085 * interact with PL_lex_state, and create fake ( ... ) argument lists
1086 * to handle functions and concatenation.
1087 * They assume that whoever calls them will be setting up a fake
1088 * join call, because each subthing puts a ',' after it. This lets
1091 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1093 * (I'm not sure whether the spurious commas at the end of lcfirst's
1094 * arguments and join's arguments are created or not).
1099 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1101 * Pattern matching will set PL_lex_op to the pattern-matching op to
1102 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1104 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1106 * Everything else becomes a FUNC.
1108 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1109 * had an OP_CONST or OP_READLINE). This just sets us up for a
1110 * call to S_sublex_push().
1114 S_sublex_start(pTHX)
1116 const register I32 op_type = yylval.ival;
1118 if (op_type == OP_NULL) {
1119 yylval.opval = PL_lex_op;
1123 if (op_type == OP_CONST || op_type == OP_READLINE) {
1124 SV *sv = tokeq(PL_lex_stuff);
1126 if (SvTYPE(sv) == SVt_PVIV) {
1127 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1129 const char *p = SvPV_const(sv, len);
1130 SV * const nsv = newSVpvn(p, len);
1136 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1137 PL_lex_stuff = Nullsv;
1141 PL_sublex_info.super_state = PL_lex_state;
1142 PL_sublex_info.sub_inwhat = op_type;
1143 PL_sublex_info.sub_op = PL_lex_op;
1144 PL_lex_state = LEX_INTERPPUSH;
1148 yylval.opval = PL_lex_op;
1158 * Create a new scope to save the lexing state. The scope will be
1159 * ended in S_sublex_done. Returns a '(', starting the function arguments
1160 * to the uc, lc, etc. found before.
1161 * Sets PL_lex_state to LEX_INTERPCONCAT.
1169 PL_lex_state = PL_sublex_info.super_state;
1170 SAVEI32(PL_lex_dojoin);
1171 SAVEI32(PL_lex_brackets);
1172 SAVEI32(PL_lex_casemods);
1173 SAVEI32(PL_lex_starts);
1174 SAVEI32(PL_lex_state);
1175 SAVEVPTR(PL_lex_inpat);
1176 SAVEI32(PL_lex_inwhat);
1177 SAVECOPLINE(PL_curcop);
1178 SAVEPPTR(PL_bufptr);
1179 SAVEPPTR(PL_bufend);
1180 SAVEPPTR(PL_oldbufptr);
1181 SAVEPPTR(PL_oldoldbufptr);
1182 SAVEPPTR(PL_last_lop);
1183 SAVEPPTR(PL_last_uni);
1184 SAVEPPTR(PL_linestart);
1185 SAVESPTR(PL_linestr);
1186 SAVEGENERICPV(PL_lex_brackstack);
1187 SAVEGENERICPV(PL_lex_casestack);
1189 PL_linestr = PL_lex_stuff;
1190 PL_lex_stuff = Nullsv;
1192 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1193 = SvPVX(PL_linestr);
1194 PL_bufend += SvCUR(PL_linestr);
1195 PL_last_lop = PL_last_uni = Nullch;
1196 SAVEFREESV(PL_linestr);
1198 PL_lex_dojoin = FALSE;
1199 PL_lex_brackets = 0;
1200 New(899, PL_lex_brackstack, 120, char);
1201 New(899, PL_lex_casestack, 12, char);
1202 PL_lex_casemods = 0;
1203 *PL_lex_casestack = '\0';
1205 PL_lex_state = LEX_INTERPCONCAT;
1206 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1208 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1209 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1210 PL_lex_inpat = PL_sublex_info.sub_op;
1212 PL_lex_inpat = Nullop;
1219 * Restores lexer state after a S_sublex_push.
1225 if (!PL_lex_starts++) {
1226 SV *sv = newSVpvn("",0);
1227 if (SvUTF8(PL_linestr))
1229 PL_expect = XOPERATOR;
1230 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1234 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1235 PL_lex_state = LEX_INTERPCASEMOD;
1239 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1240 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1241 PL_linestr = PL_lex_repl;
1243 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1244 PL_bufend += SvCUR(PL_linestr);
1245 PL_last_lop = PL_last_uni = Nullch;
1246 SAVEFREESV(PL_linestr);
1247 PL_lex_dojoin = FALSE;
1248 PL_lex_brackets = 0;
1249 PL_lex_casemods = 0;
1250 *PL_lex_casestack = '\0';
1252 if (SvEVALED(PL_lex_repl)) {
1253 PL_lex_state = LEX_INTERPNORMAL;
1255 /* we don't clear PL_lex_repl here, so that we can check later
1256 whether this is an evalled subst; that means we rely on the
1257 logic to ensure sublex_done() is called again only via the
1258 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1261 PL_lex_state = LEX_INTERPCONCAT;
1262 PL_lex_repl = Nullsv;
1268 PL_bufend = SvPVX(PL_linestr);
1269 PL_bufend += SvCUR(PL_linestr);
1270 PL_expect = XOPERATOR;
1271 PL_sublex_info.sub_inwhat = 0;
1279 Extracts a pattern, double-quoted string, or transliteration. This
1282 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1283 processing a pattern (PL_lex_inpat is true), a transliteration
1284 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1286 Returns a pointer to the character scanned up to. Iff this is
1287 advanced from the start pointer supplied (ie if anything was
1288 successfully parsed), will leave an OP for the substring scanned
1289 in yylval. Caller must intuit reason for not parsing further
1290 by looking at the next characters herself.
1294 double-quoted style: \r and \n
1295 regexp special ones: \D \s
1297 backrefs: \1 (deprecated in substitution replacements)
1298 case and quoting: \U \Q \E
1299 stops on @ and $, but not for $ as tail anchor
1301 In transliterations:
1302 characters are VERY literal, except for - not at the start or end
1303 of the string, which indicates a range. scan_const expands the
1304 range to the full set of intermediate characters.
1306 In double-quoted strings:
1308 double-quoted style: \r and \n
1310 backrefs: \1 (deprecated)
1311 case and quoting: \U \Q \E
1314 scan_const does *not* construct ops to handle interpolated strings.
1315 It stops processing as soon as it finds an embedded $ or @ variable
1316 and leaves it to the caller to work out what's going on.
1318 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo.
1320 $ in pattern could be $foo or could be tail anchor. Assumption:
1321 it's a tail anchor if $ is the last thing in the string, or if it's
1322 followed by one of ")| \n\t"
1324 \1 (backreferences) are turned into $1
1326 The structure of the code is
1327 while (there's a character to process) {
1328 handle transliteration ranges
1329 skip regexp comments
1330 skip # initiated comments in //x patterns
1331 check for embedded @foo
1332 check for embedded scalars
1334 leave intact backslashes from leave (below)
1335 deprecate \1 in strings and sub replacements
1336 handle string-changing backslashes \l \U \Q \E, etc.
1337 switch (what was escaped) {
1338 handle - in a transliteration (becomes a literal -)
1339 handle \132 octal characters
1340 handle 0x15 hex characters
1341 handle \cV (control V)
1342 handle printf backslashes (\f, \r, \n, etc)
1344 } (end if backslash)
1345 } (end while character to read)
1350 S_scan_const(pTHX_ char *start)
1352 register char *send = PL_bufend; /* end of the constant */
1353 SV *sv = NEWSV(93, send - start); /* sv for the constant */
1354 register char *s = start; /* start of the constant */
1355 register char *d = SvPVX(sv); /* destination for copies */
1356 bool dorange = FALSE; /* are we in a translit range? */
1357 bool didrange = FALSE; /* did we just finish a range? */
1358 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1359 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1362 const char *leaveit = /* set of acceptably-backslashed characters */
1364 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#"
1367 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1368 /* If we are doing a trans and we know we want UTF8 set expectation */
1369 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1370 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1374 while (s < send || dorange) {
1375 /* get transliterations out of the way (they're most literal) */
1376 if (PL_lex_inwhat == OP_TRANS) {
1377 /* expand a range A-Z to the full set of characters. AIE! */
1379 I32 i; /* current expanded character */
1380 I32 min; /* first character in range */
1381 I32 max; /* last character in range */
1384 char *c = (char*)utf8_hop((U8*)d, -1);
1388 *c = (char)UTF_TO_NATIVE(0xff);
1389 /* mark the range as done, and continue */
1395 i = d - SvPVX_const(sv); /* remember current offset */
1396 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1397 d = SvPVX(sv) + i; /* refresh d after realloc */
1398 d -= 2; /* eat the first char and the - */
1400 min = (U8)*d; /* first char in range */
1401 max = (U8)d[1]; /* last char in range */
1405 "Invalid range \"%c-%c\" in transliteration operator",
1406 (char)min, (char)max);
1410 if ((isLOWER(min) && isLOWER(max)) ||
1411 (isUPPER(min) && isUPPER(max))) {
1413 for (i = min; i <= max; i++)
1415 *d++ = NATIVE_TO_NEED(has_utf8,i);
1417 for (i = min; i <= max; i++)
1419 *d++ = NATIVE_TO_NEED(has_utf8,i);
1424 for (i = min; i <= max; i++)
1427 /* mark the range as done, and continue */
1433 /* range begins (ignore - as first or last char) */
1434 else if (*s == '-' && s+1 < send && s != start) {
1436 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1439 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1451 /* if we get here, we're not doing a transliteration */
1453 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1454 except for the last char, which will be done separately. */
1455 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1457 while (s+1 < send && *s != ')')
1458 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1460 else if (s[2] == '{' /* This should match regcomp.c */
1461 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1464 char *regparse = s + (s[2] == '{' ? 3 : 4);
1467 while (count && (c = *regparse)) {
1468 if (c == '\\' && regparse[1])
1476 if (*regparse != ')')
1477 regparse--; /* Leave one char for continuation. */
1478 while (s < regparse)
1479 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1483 /* likewise skip #-initiated comments in //x patterns */
1484 else if (*s == '#' && PL_lex_inpat &&
1485 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1486 while (s+1 < send && *s != '\n')
1487 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1490 /* check for embedded arrays
1491 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1493 else if (*s == '@' && s[1]
1494 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1497 /* check for embedded scalars. only stop if we're sure it's a
1500 else if (*s == '$') {
1501 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1503 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1504 break; /* in regexp, $ might be tail anchor */
1507 /* End of else if chain - OP_TRANS rejoin rest */
1510 if (*s == '\\' && s+1 < send) {
1513 /* some backslashes we leave behind */
1514 if (*leaveit && *s && strchr(leaveit, *s)) {
1515 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1516 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1520 /* deprecate \1 in strings and substitution replacements */
1521 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1522 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1524 if (ckWARN(WARN_SYNTAX))
1525 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
1530 /* string-change backslash escapes */
1531 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1536 /* if we get here, it's either a quoted -, or a digit */
1539 /* quoted - in transliterations */
1541 if (PL_lex_inwhat == OP_TRANS) {
1548 if (ckWARN(WARN_MISC) &&
1551 Perl_warner(aTHX_ packWARN(WARN_MISC),
1552 "Unrecognized escape \\%c passed through",
1554 /* default action is to copy the quoted character */
1555 goto default_action;
1558 /* \132 indicates an octal constant */
1559 case '0': case '1': case '2': case '3':
1560 case '4': case '5': case '6': case '7':
1564 uv = grok_oct(s, &len, &flags, NULL);
1567 goto NUM_ESCAPE_INSERT;
1569 /* \x24 indicates a hex constant */
1573 char* e = strchr(s, '}');
1574 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1575 PERL_SCAN_DISALLOW_PREFIX;
1580 yyerror("Missing right brace on \\x{}");
1584 uv = grok_hex(s, &len, &flags, NULL);
1590 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
1591 uv = grok_hex(s, &len, &flags, NULL);
1597 /* Insert oct or hex escaped character.
1598 * There will always enough room in sv since such
1599 * escapes will be longer than any UTF-8 sequence
1600 * they can end up as. */
1602 /* We need to map to chars to ASCII before doing the tests
1605 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
1606 if (!has_utf8 && uv > 255) {
1607 /* Might need to recode whatever we have
1608 * accumulated so far if it contains any
1611 * (Can't we keep track of that and avoid
1612 * this rescan? --jhi)
1616 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
1617 if (!NATIVE_IS_INVARIANT(*c)) {
1622 STRLEN offset = d - SvPVX_const(sv);
1624 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
1628 while (src >= (const U8 *)SvPVX_const(sv)) {
1629 if (!NATIVE_IS_INVARIANT(*src)) {
1630 U8 ch = NATIVE_TO_ASCII(*src);
1631 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
1632 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
1642 if (has_utf8 || uv > 255) {
1643 d = (char*)uvchr_to_utf8((U8*)d, uv);
1645 if (PL_lex_inwhat == OP_TRANS &&
1646 PL_sublex_info.sub_op) {
1647 PL_sublex_info.sub_op->op_private |=
1648 (PL_lex_repl ? OPpTRANS_FROM_UTF
1661 /* \N{LATIN SMALL LETTER A} is a named character */
1665 char* e = strchr(s, '}');
1671 yyerror("Missing right brace on \\N{}");
1675 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
1677 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1678 PERL_SCAN_DISALLOW_PREFIX;
1681 uv = grok_hex(s, &len, &flags, NULL);
1683 goto NUM_ESCAPE_INSERT;
1685 res = newSVpvn(s + 1, e - s - 1);
1686 res = new_constant( Nullch, 0, "charnames",
1687 res, Nullsv, "\\N{...}" );
1689 sv_utf8_upgrade(res);
1690 str = SvPV_const(res,len);
1691 #ifdef EBCDIC_NEVER_MIND
1692 /* charnames uses pack U and that has been
1693 * recently changed to do the below uni->native
1694 * mapping, so this would be redundant (and wrong,
1695 * the code point would be doubly converted).
1696 * But leave this in just in case the pack U change
1697 * gets revoked, but the semantics is still
1698 * desireable for charnames. --jhi */
1700 UV uv = utf8_to_uvchr((const U8*)str, 0);
1703 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
1705 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
1706 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
1707 str = SvPV_const(res, len);
1711 if (!has_utf8 && SvUTF8(res)) {
1712 const char *ostart = SvPVX_const(sv);
1713 SvCUR_set(sv, d - ostart);
1716 sv_utf8_upgrade(sv);
1717 /* this just broke our allocation above... */
1718 SvGROW(sv, (STRLEN)(send - start));
1719 d = SvPVX(sv) + SvCUR(sv);
1722 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
1723 const char *odest = SvPVX_const(sv);
1725 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
1726 d = SvPVX(sv) + (d - odest);
1728 Copy(str, d, len, char);
1735 yyerror("Missing braces on \\N{}");
1738 /* \c is a control character */
1747 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
1750 yyerror("Missing control char name in \\c");
1754 /* printf-style backslashes, formfeeds, newlines, etc */
1756 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
1759 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
1762 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
1765 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
1768 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
1771 *d++ = ASCII_TO_NEED(has_utf8,'\033');
1774 *d++ = ASCII_TO_NEED(has_utf8,'\007');
1780 } /* end if (backslash) */
1783 /* If we started with encoded form, or already know we want it
1784 and then encode the next character */
1785 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
1787 UV uv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
1788 STRLEN need = UNISKIP(NATIVE_TO_UNI(uv));
1791 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
1792 STRLEN off = d - SvPVX_const(sv);
1793 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
1795 d = (char*)uvchr_to_utf8((U8*)d, uv);
1799 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1801 } /* while loop to process each character */
1803 /* terminate the string and set up the sv */
1805 SvCUR_set(sv, d - SvPVX_const(sv));
1806 if (SvCUR(sv) >= SvLEN(sv))
1807 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
1810 if (PL_encoding && !has_utf8) {
1811 sv_recode_to_utf8(sv, PL_encoding);
1817 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1818 PL_sublex_info.sub_op->op_private |=
1819 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1823 /* shrink the sv if we allocated more than we used */
1824 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1825 SvPV_shrink_to_cur(sv);
1828 /* return the substring (via yylval) only if we parsed anything */
1829 if (s > PL_bufptr) {
1830 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1831 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1833 ( PL_lex_inwhat == OP_TRANS
1835 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1838 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1845 * Returns TRUE if there's more to the expression (e.g., a subscript),
1848 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
1850 * ->[ and ->{ return TRUE
1851 * { and [ outside a pattern are always subscripts, so return TRUE
1852 * if we're outside a pattern and it's not { or [, then return FALSE
1853 * if we're in a pattern and the first char is a {
1854 * {4,5} (any digits around the comma) returns FALSE
1855 * if we're in a pattern and the first char is a [
1857 * [SOMETHING] has a funky algorithm to decide whether it's a
1858 * character class or not. It has to deal with things like
1859 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
1860 * anything else returns TRUE
1863 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1866 S_intuit_more(pTHX_ register char *s)
1868 if (PL_lex_brackets)
1870 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1872 if (*s != '{' && *s != '[')
1877 /* In a pattern, so maybe we have {n,m}. */
1894 /* On the other hand, maybe we have a character class */
1897 if (*s == ']' || *s == '^')
1900 /* this is terrifying, and it works */
1901 int weight = 2; /* let's weigh the evidence */
1903 unsigned char un_char = 255, last_un_char;
1904 const char *send = strchr(s,']');
1905 char tmpbuf[sizeof PL_tokenbuf * 4];
1907 if (!send) /* has to be an expression */
1910 Zero(seen,256,char);
1913 else if (isDIGIT(*s)) {
1915 if (isDIGIT(s[1]) && s[2] == ']')
1921 for (; s < send; s++) {
1922 last_un_char = un_char;
1923 un_char = (unsigned char)*s;
1928 weight -= seen[un_char] * 10;
1929 if (isALNUM_lazy_if(s+1,UTF)) {
1930 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
1931 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
1936 else if (*s == '$' && s[1] &&
1937 strchr("[#!%*<>()-=",s[1])) {
1938 if (/*{*/ strchr("])} =",s[2]))
1947 if (strchr("wds]",s[1]))
1949 else if (seen['\''] || seen['"'])
1951 else if (strchr("rnftbxcav",s[1]))
1953 else if (isDIGIT(s[1])) {
1955 while (s[1] && isDIGIT(s[1]))
1965 if (strchr("aA01! ",last_un_char))
1967 if (strchr("zZ79~",s[1]))
1969 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
1970 weight -= 5; /* cope with negative subscript */
1973 if (!isALNUM(last_un_char)
1974 && !(last_un_char == '$' || last_un_char == '@'
1975 || last_un_char == '&')
1976 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
1981 if (keyword(tmpbuf, d - tmpbuf))
1984 if (un_char == last_un_char + 1)
1986 weight -= seen[un_char];
1991 if (weight >= 0) /* probably a character class */
2001 * Does all the checking to disambiguate
2003 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2004 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2006 * First argument is the stuff after the first token, e.g. "bar".
2008 * Not a method if bar is a filehandle.
2009 * Not a method if foo is a subroutine prototyped to take a filehandle.
2010 * Not a method if it's really "Foo $bar"
2011 * Method if it's "foo $bar"
2012 * Not a method if it's really "print foo $bar"
2013 * Method if it's really "foo package::" (interpreted as package->foo)
2014 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2015 * Not a method if bar is a filehandle or package, but is quoted with
2020 S_intuit_method(pTHX_ char *start, GV *gv)
2022 char *s = start + (*start == '$');
2023 char tmpbuf[sizeof PL_tokenbuf];
2031 if ((cv = GvCVu(gv))) {
2032 const char *proto = SvPVX_const(cv);
2042 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2043 /* start is the beginning of the possible filehandle/object,
2044 * and s is the end of it
2045 * tmpbuf is a copy of it
2048 if (*start == '$') {
2049 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2054 return *s == '(' ? FUNCMETH : METHOD;
2056 if (!keyword(tmpbuf, len)) {
2057 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2062 indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2063 if (indirgv && GvCVu(indirgv))
2065 /* filehandle or package name makes it a method */
2066 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2068 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2069 return 0; /* no assumptions -- "=>" quotes bearword */
2071 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
2072 newSVpvn(tmpbuf,len));
2073 PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
2077 return *s == '(' ? FUNCMETH : METHOD;
2085 * Return a string of Perl code to load the debugger. If PERL5DB
2086 * is set, it will return the contents of that, otherwise a
2087 * compile-time require of perl5db.pl.
2094 const char *pdb = PerlEnv_getenv("PERL5DB");
2098 SETERRNO(0,SS_NORMAL);
2099 return "BEGIN { require 'perl5db.pl' }";
2105 /* Encoded script support. filter_add() effectively inserts a
2106 * 'pre-processing' function into the current source input stream.
2107 * Note that the filter function only applies to the current source file
2108 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2110 * The datasv parameter (which may be NULL) can be used to pass
2111 * private data to this instance of the filter. The filter function
2112 * can recover the SV using the FILTER_DATA macro and use it to
2113 * store private buffers and state information.
2115 * The supplied datasv parameter is upgraded to a PVIO type
2116 * and the IoDIRP/IoANY field is used to store the function pointer,
2117 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2118 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2119 * private use must be set using malloc'd pointers.
2123 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2128 if (!PL_rsfp_filters)
2129 PL_rsfp_filters = newAV();
2131 datasv = NEWSV(255,0);
2132 (void)SvUPGRADE(datasv, SVt_PVIO);
2133 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2134 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2135 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2136 IoANY(datasv), SvPV_nolen(datasv)));
2137 av_unshift(PL_rsfp_filters, 1);
2138 av_store(PL_rsfp_filters, 0, datasv) ;
2143 /* Delete most recently added instance of this filter function. */
2145 Perl_filter_del(pTHX_ filter_t funcp)
2150 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", FPTR2DPTR(XPVIO *, funcp)));
2152 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2154 /* if filter is on top of stack (usual case) just pop it off */
2155 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2156 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2157 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2158 IoANY(datasv) = (void *)NULL;
2159 sv_free(av_pop(PL_rsfp_filters));
2163 /* we need to search for the correct entry and clear it */
2164 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2168 /* Invoke the idxth filter function for the current rsfp. */
2169 /* maxlen 0 = read one text line */
2171 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2176 if (!PL_rsfp_filters)
2178 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2179 /* Provide a default input filter to make life easy. */
2180 /* Note that we append to the line. This is handy. */
2181 DEBUG_P(PerlIO_printf(Perl_debug_log,
2182 "filter_read %d: from rsfp\n", idx));
2186 const int old_len = SvCUR(buf_sv);
2188 /* ensure buf_sv is large enough */
2189 SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ;
2190 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
2191 if (PerlIO_error(PL_rsfp))
2192 return -1; /* error */
2194 return 0 ; /* end of file */
2196 SvCUR_set(buf_sv, old_len + len) ;
2199 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2200 if (PerlIO_error(PL_rsfp))
2201 return -1; /* error */
2203 return 0 ; /* end of file */
2206 return SvCUR(buf_sv);
2208 /* Skip this filter slot if filter has been deleted */
2209 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2210 DEBUG_P(PerlIO_printf(Perl_debug_log,
2211 "filter_read %d: skipped (filter deleted)\n",
2213 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
2215 /* Get function pointer hidden within datasv */
2216 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2217 DEBUG_P(PerlIO_printf(Perl_debug_log,
2218 "filter_read %d: via function %p (%s)\n",
2219 idx, datasv, SvPV_nolen_const(datasv)));
2220 /* Call function. The function is expected to */
2221 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2222 /* Return: <0:error, =0:eof, >0:not eof */
2223 return (*funcp)(aTHX_ idx, buf_sv, maxlen);
2227 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2229 #ifdef PERL_CR_FILTER
2230 if (!PL_rsfp_filters) {
2231 filter_add(S_cr_textfilter,NULL);
2234 if (PL_rsfp_filters) {
2236 SvCUR_set(sv, 0); /* start with empty line */
2237 if (FILTER_READ(0, sv, 0) > 0)
2238 return ( SvPVX(sv) ) ;
2243 return (sv_gets(sv, fp, append));
2247 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2251 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2255 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2256 (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV)))
2258 return GvHV(gv); /* Foo:: */
2261 /* use constant CLASS => 'MyClass' */
2262 if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) {
2264 if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2265 pkgname = SvPV_nolen_const(sv);
2269 return gv_stashpv(pkgname, FALSE);
2273 static char const* exp_name[] =
2274 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2275 "ATTRTERM", "TERMBLOCK"
2282 Works out what to call the token just pulled out of the input
2283 stream. The yacc parser takes care of taking the ops we return and
2284 stitching them into a tree.
2290 if read an identifier
2291 if we're in a my declaration
2292 croak if they tried to say my($foo::bar)
2293 build the ops for a my() declaration
2294 if it's an access to a my() variable
2295 are we in a sort block?
2296 croak if my($a); $a <=> $b
2297 build ops for access to a my() variable
2298 if in a dq string, and they've said @foo and we can't find @foo
2300 build ops for a bareword
2301 if we already built the token before, use it.
2304 #ifdef USE_PURE_BISON
2306 Perl_yylex_r(pTHX_ YYSTYPE *lvalp, int *lcharp)
2311 yylval_pointer[yyactlevel] = lvalp;
2312 yychar_pointer[yyactlevel] = lcharp;
2313 if (yyactlevel >= YYMAXLEVEL)
2314 Perl_croak(aTHX_ "panic: YYMAXLEVEL");
2316 r = Perl_yylex(aTHX);
2326 #pragma segment Perl_yylex
2331 register char *s = PL_bufptr;
2338 I32 orig_keyword = 0;
2341 PerlIO_printf(Perl_debug_log, "### LEX_%s\n",
2342 lex_state_names[PL_lex_state]);
2344 /* check if there's an identifier for us to look at */
2345 if (PL_pending_ident)
2346 return REPORT(S_pending_ident(aTHX));
2348 /* no identifier pending identification */
2350 switch (PL_lex_state) {
2352 case LEX_NORMAL: /* Some compilers will produce faster */
2353 case LEX_INTERPNORMAL: /* code if we comment these out. */
2357 /* when we've already built the next token, just pull it out of the queue */
2360 yylval = PL_nextval[PL_nexttoke];
2362 PL_lex_state = PL_lex_defer;
2363 PL_expect = PL_lex_expect;
2364 PL_lex_defer = LEX_NORMAL;
2366 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2367 "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr,
2368 (IV)PL_nexttype[PL_nexttoke]); });
2370 return REPORT(PL_nexttype[PL_nexttoke]);
2372 /* interpolated case modifiers like \L \U, including \Q and \E.
2373 when we get here, PL_bufptr is at the \
2375 case LEX_INTERPCASEMOD:
2377 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2378 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2380 /* handle \E or end of string */
2381 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2383 if (PL_lex_casemods) {
2384 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
2385 PL_lex_casestack[PL_lex_casemods] = '\0';
2387 if (PL_bufptr != PL_bufend
2388 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
2390 PL_lex_state = LEX_INTERPCONCAT;
2394 if (PL_bufptr != PL_bufend)
2396 PL_lex_state = LEX_INTERPCONCAT;
2400 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2401 "### Saw case modifier at '%s'\n", PL_bufptr); });
2403 if (s[1] == '\\' && s[2] == 'E') {
2405 PL_lex_state = LEX_INTERPCONCAT;
2409 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2410 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
2411 if ((*s == 'L' || *s == 'U') &&
2412 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
2413 PL_lex_casestack[--PL_lex_casemods] = '\0';
2416 if (PL_lex_casemods > 10)
2417 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2418 PL_lex_casestack[PL_lex_casemods++] = *s;
2419 PL_lex_casestack[PL_lex_casemods] = '\0';
2420 PL_lex_state = LEX_INTERPCONCAT;
2421 PL_nextval[PL_nexttoke].ival = 0;
2424 PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2426 PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2428 PL_nextval[PL_nexttoke].ival = OP_LC;
2430 PL_nextval[PL_nexttoke].ival = OP_UC;
2432 PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2434 Perl_croak(aTHX_ "panic: yylex");
2438 if (PL_lex_starts) {
2447 case LEX_INTERPPUSH:
2448 return REPORT(sublex_push());
2450 case LEX_INTERPSTART:
2451 if (PL_bufptr == PL_bufend)
2452 return REPORT(sublex_done());
2453 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2454 "### Interpolated variable at '%s'\n", PL_bufptr); });
2456 PL_lex_dojoin = (*PL_bufptr == '@');
2457 PL_lex_state = LEX_INTERPNORMAL;
2458 if (PL_lex_dojoin) {
2459 PL_nextval[PL_nexttoke].ival = 0;
2461 #ifdef USE_5005THREADS
2462 PL_nextval[PL_nexttoke].opval = newOP(OP_THREADSV, 0);
2463 PL_nextval[PL_nexttoke].opval->op_targ = find_threadsv("\"");
2464 force_next(PRIVATEREF);
2466 force_ident("\"", '$');
2467 #endif /* USE_5005THREADS */
2468 PL_nextval[PL_nexttoke].ival = 0;
2470 PL_nextval[PL_nexttoke].ival = 0;
2472 PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
2475 if (PL_lex_starts++) {
2481 case LEX_INTERPENDMAYBE:
2482 if (intuit_more(PL_bufptr)) {
2483 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
2489 if (PL_lex_dojoin) {
2490 PL_lex_dojoin = FALSE;
2491 PL_lex_state = LEX_INTERPCONCAT;
2494 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2495 && SvEVALED(PL_lex_repl))
2497 if (PL_bufptr != PL_bufend)
2498 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2499 PL_lex_repl = Nullsv;
2502 case LEX_INTERPCONCAT:
2504 if (PL_lex_brackets)
2505 Perl_croak(aTHX_ "panic: INTERPCONCAT");
2507 if (PL_bufptr == PL_bufend)
2508 return REPORT(sublex_done());
2510 if (SvIVX(PL_linestr) == '\'') {
2511 SV *sv = newSVsv(PL_linestr);
2514 else if ( PL_hints & HINT_NEW_RE )
2515 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2516 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2520 s = scan_const(PL_bufptr);
2522 PL_lex_state = LEX_INTERPCASEMOD;
2524 PL_lex_state = LEX_INTERPSTART;
2527 if (s != PL_bufptr) {
2528 PL_nextval[PL_nexttoke] = yylval;
2531 if (PL_lex_starts++)
2541 PL_lex_state = LEX_NORMAL;
2542 s = scan_formline(PL_bufptr);
2543 if (!PL_lex_formbrack)
2549 PL_oldoldbufptr = PL_oldbufptr;
2552 PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at [%s]\n",
2553 exp_name[PL_expect], s);
2559 if (isIDFIRST_lazy_if(s,UTF))
2561 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2564 goto fake_eof; /* emulate EOF on ^D or ^Z */
2569 if (PL_lex_brackets) {
2570 if (PL_lex_formbrack)
2571 yyerror("Format not terminated");
2573 yyerror("Missing right curly or square bracket");
2575 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2576 "### Tokener got EOF\n");
2580 if (s++ < PL_bufend)
2581 goto retry; /* ignore stray nulls */
2584 if (!PL_in_eval && !PL_preambled) {
2585 PL_preambled = TRUE;
2586 sv_setpv(PL_linestr,incl_perldb());
2587 if (SvCUR(PL_linestr))
2588 sv_catpvn(PL_linestr,";", 1);
2590 while(AvFILLp(PL_preambleav) >= 0) {
2591 SV *tmpsv = av_shift(PL_preambleav);
2592 sv_catsv(PL_linestr, tmpsv);
2593 sv_catpvn(PL_linestr, ";", 1);
2596 sv_free((SV*)PL_preambleav);
2597 PL_preambleav = NULL;
2599 if (PL_minus_n || PL_minus_p) {
2600 sv_catpv(PL_linestr, "LINE: while (<>) {");
2602 sv_catpv(PL_linestr,"chomp;");
2605 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
2606 || *PL_splitstr == '"')
2607 && strchr(PL_splitstr + 1, *PL_splitstr))
2608 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
2610 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
2611 bytes can be used as quoting characters. :-) */
2612 /* The count here deliberately includes the NUL
2613 that terminates the C string constant. This
2614 embeds the opening NUL into the string. */
2615 const char *splits = PL_splitstr;
2616 sv_catpvn(PL_linestr, "our @F=split(q", 15);
2619 if (*splits == '\\')
2620 sv_catpvn(PL_linestr, splits, 1);
2621 sv_catpvn(PL_linestr, splits, 1);
2622 } while (*splits++);
2623 /* This loop will embed the trailing NUL of
2624 PL_linestr as the last thing it does before
2626 sv_catpvn(PL_linestr, ");", 2);
2630 sv_catpv(PL_linestr,"our @F=split(' ');");
2633 sv_catpvn(PL_linestr, "\n", 1);
2634 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2635 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2636 PL_last_lop = PL_last_uni = Nullch;
2637 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2638 SV *sv = NEWSV(85,0);
2640 sv_upgrade(sv, SVt_PVMG);
2641 sv_setsv(sv,PL_linestr);
2644 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2649 bof = PL_rsfp ? TRUE : FALSE;
2650 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2653 if (PL_preprocess && !PL_in_eval)
2654 (void)PerlProc_pclose(PL_rsfp);
2655 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2656 PerlIO_clearerr(PL_rsfp);
2658 (void)PerlIO_close(PL_rsfp);
2660 PL_doextract = FALSE;
2662 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2663 sv_setpv(PL_linestr,PL_minus_p
2664 ? ";}continue{print;}" : ";}");
2665 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2666 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2667 PL_last_lop = PL_last_uni = Nullch;
2668 PL_minus_n = PL_minus_p = 0;
2671 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2672 PL_last_lop = PL_last_uni = Nullch;
2673 sv_setpvn(PL_linestr,"",0);
2674 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
2676 /* If it looks like the start of a BOM or raw UTF-16,
2677 * check if it in fact is. */
2683 #ifdef PERLIO_IS_STDIO
2684 # ifdef __GNU_LIBRARY__
2685 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
2686 # define FTELL_FOR_PIPE_IS_BROKEN
2690 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
2691 # define FTELL_FOR_PIPE_IS_BROKEN
2696 #ifdef FTELL_FOR_PIPE_IS_BROKEN
2697 /* This loses the possibility to detect the bof
2698 * situation on perl -P when the libc5 is being used.
2699 * Workaround? Maybe attach some extra state to PL_rsfp?
2702 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2704 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
2707 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2708 s = swallow_bom((U8*)s);
2712 /* Incest with pod. */
2713 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2714 sv_setpvn(PL_linestr, "", 0);
2715 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2716 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2717 PL_last_lop = PL_last_uni = Nullch;
2718 PL_doextract = FALSE;
2722 } while (PL_doextract);
2723 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2724 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2725 SV *sv = NEWSV(85,0);
2727 sv_upgrade(sv, SVt_PVMG);
2728 sv_setsv(sv,PL_linestr);
2731 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2733 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2734 PL_last_lop = PL_last_uni = Nullch;
2735 if (CopLINE(PL_curcop) == 1) {
2736 while (s < PL_bufend && isSPACE(*s))
2738 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2742 if (*s == '#' && *(s+1) == '!')
2744 #ifdef ALTERNATE_SHEBANG
2746 static char const as[] = ALTERNATE_SHEBANG;
2747 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2748 d = s + (sizeof(as) - 1);
2750 #endif /* ALTERNATE_SHEBANG */
2759 while (*d && !isSPACE(*d))
2763 #ifdef ARG_ZERO_IS_SCRIPT
2764 if (ipathend > ipath) {
2766 * HP-UX (at least) sets argv[0] to the script name,
2767 * which makes $^X incorrect. And Digital UNIX and Linux,
2768 * at least, set argv[0] to the basename of the Perl
2769 * interpreter. So, having found "#!", we'll set it right.
2771 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); /* $^X */
2772 assert(SvPOK(x) || SvGMAGICAL(x));
2773 if (sv_eq(x, CopFILESV(PL_curcop))) {
2774 sv_setpvn(x, ipath, ipathend - ipath);
2780 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
2781 const char *lstart = SvPV_const(x,llen);
2783 bstart += blen - llen;
2784 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
2785 sv_setpvn(x, ipath, ipathend - ipath);
2790 TAINT_NOT; /* $^X is always tainted, but that's OK */
2792 #endif /* ARG_ZERO_IS_SCRIPT */
2797 d = instr(s,"perl -");
2799 d = instr(s,"perl");
2801 /* avoid getting into infinite loops when shebang
2802 * line contains "Perl" rather than "perl" */
2804 for (d = ipathend-4; d >= ipath; --d) {
2805 if ((*d == 'p' || *d == 'P')
2806 && !ibcmp(d, "perl", 4))
2816 #ifdef ALTERNATE_SHEBANG
2818 * If the ALTERNATE_SHEBANG on this system starts with a
2819 * character that can be part of a Perl expression, then if
2820 * we see it but not "perl", we're probably looking at the
2821 * start of Perl code, not a request to hand off to some
2822 * other interpreter. Similarly, if "perl" is there, but
2823 * not in the first 'word' of the line, we assume the line
2824 * contains the start of the Perl program.
2826 if (d && *s != '#') {
2827 const char *c = ipath;
2828 while (*c && !strchr("; \t\r\n\f\v#", *c))
2831 d = Nullch; /* "perl" not in first word; ignore */
2833 *s = '#'; /* Don't try to parse shebang line */
2835 #endif /* ALTERNATE_SHEBANG */
2836 #ifndef MACOS_TRADITIONAL
2841 !instr(s,"indir") &&
2842 instr(PL_origargv[0],"perl"))
2848 while (s < PL_bufend && isSPACE(*s))
2850 if (s < PL_bufend) {
2851 Newz(899,newargv,PL_origargc+3,char*);
2853 while (s < PL_bufend && !isSPACE(*s))
2856 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2859 newargv = PL_origargv;
2862 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
2864 Perl_croak(aTHX_ "Can't exec %s", ipath);
2868 const U32 oldpdb = PL_perldb;
2869 const bool oldn = PL_minus_n;
2870 const bool oldp = PL_minus_p;
2872 while (*d && !isSPACE(*d)) d++;
2873 while (SPACE_OR_TAB(*d)) d++;
2876 const bool switches_done = PL_doswitches;
2878 if (*d == 'M' || *d == 'm') {
2880 while (*d && !isSPACE(*d)) d++;
2881 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2884 d = moreswitches(d);
2886 if (PL_doswitches && !switches_done) {
2887 int argc = PL_origargc;
2888 char **argv = PL_origargv;
2891 } while (argc && argv[0][0] == '-' && argv[0][1]);
2892 init_argv_symbols(argc,argv);
2894 if ((PERLDB_LINE && !oldpdb) ||
2895 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
2896 /* if we have already added "LINE: while (<>) {",
2897 we must not do it again */
2899 sv_setpvn(PL_linestr, "", 0);
2900 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2901 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2902 PL_last_lop = PL_last_uni = Nullch;
2903 PL_preambled = FALSE;
2905 (void)gv_fetchfile(PL_origfilename);
2908 if (PL_doswitches && !switches_done) {
2909 int argc = PL_origargc;
2910 char **argv = PL_origargv;
2913 } while (argc && argv[0][0] == '-' && argv[0][1]);
2914 init_argv_symbols(argc,argv);
2920 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2922 PL_lex_state = LEX_FORMLINE;
2927 #ifdef PERL_STRICT_CR
2928 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
2930 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
2932 case ' ': case '\t': case '\f': case 013:
2933 #ifdef MACOS_TRADITIONAL
2940 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
2941 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
2942 /* handle eval qq[#line 1 "foo"\n ...] */
2943 CopLINE_dec(PL_curcop);
2947 while (s < d && *s != '\n')
2951 else if (s > d) /* Found by Ilya: feed random input to Perl. */
2952 Perl_croak(aTHX_ "panic: input overflow");
2954 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2956 PL_lex_state = LEX_FORMLINE;
2966 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2973 while (s < PL_bufend && SPACE_OR_TAB(*s))
2976 if (strnEQ(s,"=>",2)) {
2977 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
2978 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2979 "### Saw unary minus before =>, forcing word '%s'\n", s);
2981 OPERATOR('-'); /* unary minus */
2983 PL_last_uni = PL_oldbufptr;
2985 case 'r': ftst = OP_FTEREAD; break;
2986 case 'w': ftst = OP_FTEWRITE; break;
2987 case 'x': ftst = OP_FTEEXEC; break;
2988 case 'o': ftst = OP_FTEOWNED; break;
2989 case 'R': ftst = OP_FTRREAD; break;
2990 case 'W': ftst = OP_FTRWRITE; break;
2991 case 'X': ftst = OP_FTREXEC; break;
2992 case 'O': ftst = OP_FTROWNED; break;
2993 case 'e': ftst = OP_FTIS; break;
2994 case 'z': ftst = OP_FTZERO; break;
2995 case 's': ftst = OP_FTSIZE; break;
2996 case 'f': ftst = OP_FTFILE; break;
2997 case 'd': ftst = OP_FTDIR; break;
2998 case 'l': ftst = OP_FTLINK; break;
2999 case 'p': ftst = OP_FTPIPE; break;
3000 case 'S': ftst = OP_FTSOCK; break;
3001 case 'u': ftst = OP_FTSUID; break;
3002 case 'g': ftst = OP_FTSGID; break;
3003 case 'k': ftst = OP_FTSVTX; break;
3004 case 'b': ftst = OP_FTBLK; break;
3005 case 'c': ftst = OP_FTCHR; break;
3006 case 't': ftst = OP_FTTTY; break;
3007 case 'T': ftst = OP_FTTEXT; break;
3008 case 'B': ftst = OP_FTBINARY; break;
3009 case 'M': case 'A': case 'C':
3010 gv_fetchpv("\024",TRUE, SVt_PV);
3012 case 'M': ftst = OP_FTMTIME; break;
3013 case 'A': ftst = OP_FTATIME; break;
3014 case 'C': ftst = OP_FTCTIME; break;
3022 PL_last_lop_op = (OPCODE)ftst;
3023 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3024 "### Saw file test %c\n", (int)ftst);
3029 /* Assume it was a minus followed by a one-letter named
3030 * subroutine call (or a -bareword), then. */
3031 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3032 "### '-%c' looked like a file test but was not\n",
3041 if (PL_expect == XOPERATOR)
3046 else if (*s == '>') {
3049 if (isIDFIRST_lazy_if(s,UTF)) {
3050 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3058 if (PL_expect == XOPERATOR)
3061 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3063 OPERATOR('-'); /* unary minus */
3070 if (PL_expect == XOPERATOR)
3075 if (PL_expect == XOPERATOR)
3078 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3084 if (PL_expect != XOPERATOR) {
3085 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3086 PL_expect = XOPERATOR;
3087 force_ident(PL_tokenbuf, '*');
3100 if (PL_expect == XOPERATOR) {
3104 PL_tokenbuf[0] = '%';
3105 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3106 if (!PL_tokenbuf[1]) {
3109 PL_pending_ident = '%';
3128 switch (PL_expect) {
3131 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3133 PL_bufptr = s; /* update in case we back off */
3139 PL_expect = XTERMBLOCK;
3143 while (isIDFIRST_lazy_if(s,UTF)) {
3144 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3145 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
3146 if (tmp < 0) tmp = -tmp;
3161 d = scan_str(d,TRUE,TRUE);
3163 /* MUST advance bufptr here to avoid bogus
3164 "at end of line" context messages from yyerror().
3166 PL_bufptr = s + len;
3167 yyerror("Unterminated attribute parameter in attribute list");
3170 return REPORT(0); /* EOF indicator */
3174 SV *sv = newSVpvn(s, len);
3175 sv_catsv(sv, PL_lex_stuff);
3176 attrs = append_elem(OP_LIST, attrs,
3177 newSVOP(OP_CONST, 0, sv));
3178 SvREFCNT_dec(PL_lex_stuff);
3179 PL_lex_stuff = Nullsv;
3182 if (len == 6 && strnEQ(s, "unique", len)) {
3183 if (PL_in_my == KEY_our)
3185 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
3187 ; /* skip to avoid loading attributes.pm */
3190 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
3193 /* NOTE: any CV attrs applied here need to be part of
3194 the CVf_BUILTIN_ATTRS define in cv.h! */
3195 else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
3196 CvLVALUE_on(PL_compcv);
3197 else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
3198 CvLOCKED_on(PL_compcv);
3199 else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
3200 CvMETHOD_on(PL_compcv);
3201 /* After we've set the flags, it could be argued that
3202 we don't need to do the attributes.pm-based setting
3203 process, and shouldn't bother appending recognized
3204 flags. To experiment with that, uncomment the
3205 following "else". (Note that's already been
3206 uncommented. That keeps the above-applied built-in
3207 attributes from being intercepted (and possibly
3208 rejected) by a package's attribute routines, but is
3209 justified by the performance win for the common case
3210 of applying only built-in attributes.) */
3212 attrs = append_elem(OP_LIST, attrs,
3213 newSVOP(OP_CONST, 0,
3217 if (*s == ':' && s[1] != ':')
3220 break; /* require real whitespace or :'s */
3222 tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
3223 if (*s != ';' && *s != '}' && *s != tmp && (tmp != '=' || *s != ')')) {
3224 const char q = ((*s == '\'') ? '"' : '\'');
3225 /* If here for an expression, and parsed no attrs, back off. */
3226 if (tmp == '=' && !attrs) {
3230 /* MUST advance bufptr here to avoid bogus "at end of line"
3231 context messages from yyerror().
3235 yyerror("Unterminated attribute list");
3237 yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
3245 PL_nextval[PL_nexttoke].opval = attrs;
3253 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
3254 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
3271 if (PL_lex_brackets <= 0)
3272 yyerror("Unmatched right square bracket");
3275 if (PL_lex_state == LEX_INTERPNORMAL) {
3276 if (PL_lex_brackets == 0) {
3277 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3278 PL_lex_state = LEX_INTERPEND;
3285 if (PL_lex_brackets > 100) {
3286 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
3288 switch (PL_expect) {
3290 if (PL_lex_formbrack) {
3294 if (PL_oldoldbufptr == PL_last_lop)
3295 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3297 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3298 OPERATOR(HASHBRACK);
3300 while (s < PL_bufend && SPACE_OR_TAB(*s))
3303 PL_tokenbuf[0] = '\0';
3304 if (d < PL_bufend && *d == '-') {
3305 PL_tokenbuf[0] = '-';
3307 while (d < PL_bufend && SPACE_OR_TAB(*d))
3310 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3311 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
3313 while (d < PL_bufend && SPACE_OR_TAB(*d))
3316 const char minus = (PL_tokenbuf[0] == '-');
3317 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
3325 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
3330 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3335 if (PL_oldoldbufptr == PL_last_lop)
3336 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3338 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3341 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
3343 /* This hack is to get the ${} in the message. */
3345 yyerror("syntax error");
3348 OPERATOR(HASHBRACK);
3350 /* This hack serves to disambiguate a pair of curlies
3351 * as being a block or an anon hash. Normally, expectation
3352 * determines that, but in cases where we're not in a
3353 * position to expect anything in particular (like inside
3354 * eval"") we have to resolve the ambiguity. This code
3355 * covers the case where the first term in the curlies is a
3356 * quoted string. Most other cases need to be explicitly
3357 * disambiguated by prepending a "+" before the opening
3358 * curly in order to force resolution as an anon hash.
3360 * XXX should probably propagate the outer expectation
3361 * into eval"" to rely less on this hack, but that could
3362 * potentially break current behavior of eval"".
3366 if (*s == '\'' || *s == '"' || *s == '`') {
3367 /* common case: get past first string, handling escapes */
3368 for (t++; t < PL_bufend && *t != *s;)
3369 if (*t++ == '\\' && (*t == '\\' || *t == *s))
3373 else if (*s == 'q') {
3376 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
3379 /* skip q//-like construct */
3381 char open, close, term;
3384 while (t < PL_bufend && isSPACE(*t))
3386 /* check for q => */
3387 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
3388 OPERATOR(HASHBRACK);
3392 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
3396 for (t++; t < PL_bufend; t++) {
3397 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
3399 else if (*t == open)
3403 for (t++; t < PL_bufend; t++) {
3404 if (*t == '\\' && t+1 < PL_bufend)
3406 else if (*t == close && --brackets <= 0)
3408 else if (*t == open)
3415 /* skip plain q word */
3416 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3419 else if (isALNUM_lazy_if(t,UTF)) {
3421 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3424 while (t < PL_bufend && isSPACE(*t))
3426 /* if comma follows first term, call it an anon hash */
3427 /* XXX it could be a comma expression with loop modifiers */
3428 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
3429 || (*t == '=' && t[1] == '>')))
3430 OPERATOR(HASHBRACK);
3431 if (PL_expect == XREF)
3434 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3440 yylval.ival = CopLINE(PL_curcop);
3441 if (isSPACE(*s) || *s == '#')
3442 PL_copline = NOLINE; /* invalidate current command line number */
3447 if (PL_lex_brackets <= 0)
3448 yyerror("Unmatched right curly bracket");
3450 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3451 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3452 PL_lex_formbrack = 0;
3453 if (PL_lex_state == LEX_INTERPNORMAL) {
3454 if (PL_lex_brackets == 0) {
3455 if (PL_expect & XFAKEBRACK) {
3456 PL_expect &= XENUMMASK;
3457 PL_lex_state = LEX_INTERPEND;
3459 return yylex(); /* ignore fake brackets */
3461 if (*s == '-' && s[1] == '>')
3462 PL_lex_state = LEX_INTERPENDMAYBE;
3463 else if (*s != '[' && *s != '{')
3464 PL_lex_state = LEX_INTERPEND;
3467 if (PL_expect & XFAKEBRACK) {
3468 PL_expect &= XENUMMASK;
3470 return yylex(); /* ignore fake brackets */
3480 if (PL_expect == XOPERATOR) {
3481 if (ckWARN(WARN_SEMICOLON)
3482 && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart)
3484 CopLINE_dec(PL_curcop);
3485 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
3486 CopLINE_inc(PL_curcop);
3491 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3493 PL_expect = XOPERATOR;
3494 force_ident(PL_tokenbuf, '&');
3498 yylval.ival = (OPpENTERSUB_AMPER<<8);
3517 if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
3518 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Reversed %c= operator",(int)tmp);
3520 if (PL_expect == XSTATE && isALPHA(tmp) &&
3521 (s == PL_linestart+1 || s[-2] == '\n') )
3523 if (PL_in_eval && !PL_rsfp) {
3528 if (strnEQ(s,"=cut",4)) {
3542 PL_doextract = TRUE;
3545 if (PL_lex_brackets < PL_lex_formbrack) {
3547 #ifdef PERL_STRICT_CR
3548 for (t = s; SPACE_OR_TAB(*t); t++) ;
3550 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3552 if (*t == '\n' || *t == '#') {
3570 if (PL_expect != XOPERATOR) {
3571 if (s[1] != '<' && !strchr(s,'>'))
3574 s = scan_heredoc(s);
3576 s = scan_inputsymbol(s);
3577 TERM(sublex_start());
3582 SHop(OP_LEFT_SHIFT);
3596 SHop(OP_RIGHT_SHIFT);
3605 if (PL_expect == XOPERATOR) {
3606 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3609 return REPORT(','); /* grandfather non-comma-format format */
3613 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3614 PL_tokenbuf[0] = '@';
3615 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3616 sizeof PL_tokenbuf - 1, FALSE);
3617 if (PL_expect == XOPERATOR)
3618 no_op("Array length", s);
3619 if (!PL_tokenbuf[1])
3621 PL_expect = XOPERATOR;
3622 PL_pending_ident = '#';
3626 PL_tokenbuf[0] = '$';
3627 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3628 sizeof PL_tokenbuf - 1, FALSE);
3629 if (PL_expect == XOPERATOR)
3631 if (!PL_tokenbuf[1]) {
3633 yyerror("Final $ should be \\$ or $name");
3637 /* This kludge not intended to be bulletproof. */
3638 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3639 yylval.opval = newSVOP(OP_CONST, 0,
3640 newSViv(PL_compiling.cop_arybase));
3641 yylval.opval->op_private = OPpCONST_ARYBASE;
3647 if (PL_lex_state == LEX_NORMAL)
3650 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3653 PL_tokenbuf[0] = '@';
3654 if (ckWARN(WARN_SYNTAX)) {
3656 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3659 PL_bufptr = skipspace(PL_bufptr);
3660 while (t < PL_bufend && *t != ']')
3662 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3663 "Multidimensional syntax %.*s not supported",
3664 (t - PL_bufptr) + 1, PL_bufptr);
3668 else if (*s == '{') {
3669 PL_tokenbuf[0] = '%';
3670 if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") &&
3671 (t = strchr(s, '}')) && (t = strchr(t, '=')))
3673 char tmpbuf[sizeof PL_tokenbuf];
3674 for (t++; isSPACE(*t); t++) ;
3675 if (isIDFIRST_lazy_if(t,UTF)) {
3677 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3678 for (; isSPACE(*t); t++) ;
3679 if (*t == ';' && get_cv(tmpbuf, FALSE))
3680 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3681 "You need to quote \"%s\"", tmpbuf);
3687 PL_expect = XOPERATOR;
3688 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3689 const bool islop = (PL_last_lop == PL_oldoldbufptr);
3690 if (!islop || PL_last_lop_op == OP_GREPSTART)
3691 PL_expect = XOPERATOR;
3692 else if (strchr("$@\"'`q", *s))
3693 PL_expect = XTERM; /* e.g. print $fh "foo" */
3694 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3695 PL_expect = XTERM; /* e.g. print $fh &sub */
3696 else if (isIDFIRST_lazy_if(s,UTF)) {
3697 char tmpbuf[sizeof PL_tokenbuf];
3698 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3699 if ((tmp = keyword(tmpbuf, len))) {
3700 /* binary operators exclude handle interpretations */
3712 PL_expect = XTERM; /* e.g. print $fh length() */
3717 PL_expect = XTERM; /* e.g. print $fh subr() */
3720 else if (isDIGIT(*s))
3721 PL_expect = XTERM; /* e.g. print $fh 3 */
3722 else if (*s == '.' && isDIGIT(s[1]))
3723 PL_expect = XTERM; /* e.g. print $fh .3 */
3724 else if ((*s == '?' || *s == '-' || *s == '+')
3725 && !isSPACE(s[1]) && s[1] != '=')
3726 PL_expect = XTERM; /* e.g. print $fh -1 */
3727 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3728 PL_expect = XTERM; /* print $fh <<"EOF" */
3730 PL_pending_ident = '$';
3734 if (PL_expect == XOPERATOR)
3736 PL_tokenbuf[0] = '@';
3737 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3738 if (!PL_tokenbuf[1]) {
3741 if (PL_lex_state == LEX_NORMAL)
3743 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3745 PL_tokenbuf[0] = '%';
3747 /* Warn about @ where they meant $. */
3748 if (ckWARN(WARN_SYNTAX)) {
3749 if (*s == '[' || *s == '{') {
3750 const char *t = s + 1;
3751 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3753 if (*t == '}' || *t == ']') {
3755 PL_bufptr = skipspace(PL_bufptr);
3756 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3757 "Scalar value %.*s better written as $%.*s",
3758 t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3763 PL_pending_ident = '@';
3766 case '/': /* may either be division or pattern */
3767 case '?': /* may either be conditional or pattern */
3768 if (PL_expect != XOPERATOR) {
3769 /* Disable warning on "study /blah/" */
3770 if (PL_oldoldbufptr == PL_last_uni
3771 && (*PL_last_uni != 's' || s - PL_last_uni < 5
3772 || memNE(PL_last_uni, "study", 5)
3773 || isALNUM_lazy_if(PL_last_uni+5,UTF)))
3775 s = scan_pat(s,OP_MATCH);
3776 TERM(sublex_start());
3784 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3785 #ifdef PERL_STRICT_CR
3788 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3790 && (s == PL_linestart || s[-1] == '\n') )
3792 PL_lex_formbrack = 0;
3796 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3802 yylval.ival = OPf_SPECIAL;
3808 if (PL_expect != XOPERATOR)
3813 case '0': case '1': case '2': case '3': case '4':
3814 case '5': case '6': case '7': case '8': case '9':
3815 s = scan_num(s, &yylval);
3816 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3817 "### Saw number before '%s'\n", s);
3819 if (PL_expect == XOPERATOR)
3824 s = scan_str(s,FALSE,FALSE);
3825 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3826 "### Saw string before '%s'\n", s);
3828 if (PL_expect == XOPERATOR) {
3829 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3832 return REPORT(','); /* grandfather non-comma-format format */
3838 missingterm((char*)0);
3839 yylval.ival = OP_CONST;
3840 TERM(sublex_start());
3843 s = scan_str(s,FALSE,FALSE);
3844 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3845 "### Saw string before '%s'\n", s);
3847 if (PL_expect == XOPERATOR) {
3848 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3851 return REPORT(','); /* grandfather non-comma-format format */
3857 missingterm((char*)0);
3858 yylval.ival = OP_CONST;
3859 /* FIXME. I think that this can be const if char *d is replaced by
3860 more localised variables. */
3861 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3862 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
3863 yylval.ival = OP_STRINGIFY;
3867 TERM(sublex_start());
3870 s = scan_str(s,FALSE,FALSE);
3871 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3872 "### Saw backtick string before '%s'\n", s);
3874 if (PL_expect == XOPERATOR)
3875 no_op("Backticks",s);
3877 missingterm((char*)0);
3878 yylval.ival = OP_BACKTICK;
3880 TERM(sublex_start());
3884 if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s))
3885 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
3887 if (PL_expect == XOPERATOR)
3888 no_op("Backslash",s);
3892 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
3893 char *start = s + 2;
3894 while (isDIGIT(*start) || *start == '_')
3896 if (*start == '.' && isDIGIT(start[1])) {
3897 s = scan_num(s, &yylval);
3900 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
3901 else if (!isALPHA(*start) && (PL_expect == XTERM || PL_expect == XREF || PL_expect == XSTATE)) {
3902 const char c = *start;
3905 gv = gv_fetchpv(s, FALSE, SVt_PVCV);
3908 s = scan_num(s, &yylval);
3915 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
3955 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3957 /* Some keywords can be followed by any delimiter, including ':' */
3958 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
3959 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
3960 (PL_tokenbuf[0] == 'q' &&
3961 strchr("qwxr", PL_tokenbuf[1])))));
3963 /* x::* is just a word, unless x is "CORE" */
3964 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
3968 while (d < PL_bufend && isSPACE(*d))
3969 d++; /* no comments skipped here, or s### is misparsed */
3971 /* Is this a label? */
3972 if (!tmp && PL_expect == XSTATE
3973 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
3975 yylval.pval = savepv(PL_tokenbuf);
3980 /* Check for keywords */
3981 tmp = keyword(PL_tokenbuf, len);
3983 /* Is this a word before a => operator? */
3984 if (*d == '=' && d[1] == '>') {
3986 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf,0));
3987 yylval.opval->op_private = OPpCONST_BARE;
3988 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
3989 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
3993 if (tmp < 0) { /* second-class keyword? */
3994 GV *ogv = Nullgv; /* override (winner) */
3995 GV *hgv = Nullgv; /* hidden (loser) */
3996 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
3998 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
4001 if (GvIMPORTED_CV(gv))
4003 else if (! CvMETHOD(cv))
4007 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4008 (gv = *gvp) != (GV*)&PL_sv_undef &&
4009 GvCVu(gv) && GvIMPORTED_CV(gv))
4016 tmp = 0; /* overridden by import or by GLOBAL */
4019 && -tmp==KEY_lock /* XXX generalizable kludge */
4021 && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
4023 tmp = 0; /* any sub overrides "weak" keyword */
4025 else { /* no override */
4027 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
4028 Perl_warner(aTHX_ packWARN(WARN_MISC),
4029 "dump() better written as CORE::dump()");
4033 if (ckWARN(WARN_AMBIGUOUS) && hgv
4034 && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
4035 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4036 "Ambiguous call resolved as CORE::%s(), %s",
4037 GvENAME(hgv), "qualify as such or use &");
4044 default: /* not a keyword */
4048 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
4050 /* Get the rest if it looks like a package qualifier */
4052 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
4054 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
4057 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
4058 *s == '\'' ? "'" : "::");
4063 if (PL_expect == XOPERATOR) {
4064 if (PL_bufptr == PL_linestart) {
4065 CopLINE_dec(PL_curcop);
4066 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4067 CopLINE_inc(PL_curcop);
4070 no_op("Bareword",s);
4073 /* Look for a subroutine with this name in current package,
4074 unless name is "Foo::", in which case Foo is a bearword
4075 (and a package name). */
4078 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
4080 if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
4081 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
4082 "Bareword \"%s\" refers to nonexistent package",
4085 PL_tokenbuf[len] = '\0';
4092 gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
4095 /* if we saw a global override before, get the right name */
4098 sv = newSVpvn("CORE::GLOBAL::",14);
4099 sv_catpv(sv,PL_tokenbuf);
4102 /* If len is 0, newSVpv does strlen(), which is correct.
4103 If len is non-zero, then it will be the true length,
4104 and so the scalar will be created correctly. */
4105 sv = newSVpv(PL_tokenbuf,len);
4108 /* Presume this is going to be a bareword of some sort. */
4111 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4112 yylval.opval->op_private = OPpCONST_BARE;
4113 /* UTF-8 package name? */
4114 if (UTF && !IN_BYTES &&
4115 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
4118 /* And if "Foo::", then that's what it certainly is. */
4123 /* See if it's the indirect object for a list operator. */
4125 if (PL_oldoldbufptr &&
4126 PL_oldoldbufptr < PL_bufptr &&
4127 (PL_oldoldbufptr == PL_last_lop
4128 || PL_oldoldbufptr == PL_last_uni) &&
4129 /* NO SKIPSPACE BEFORE HERE! */
4130 (PL_expect == XREF ||
4131 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
4133 bool immediate_paren = *s == '(';
4135 /* (Now we can afford to cross potential line boundary.) */
4138 /* Two barewords in a row may indicate method call. */
4140 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv)))
4143 /* If not a declared subroutine, it's an indirect object. */
4144 /* (But it's an indir obj regardless for sort.) */
4146 if ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
4147 ((!gv || !GvCVu(gv)) &&
4148 (PL_last_lop_op != OP_MAPSTART &&
4149 PL_last_lop_op != OP_GREPSTART))))
4151 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
4156 PL_expect = XOPERATOR;
4159 /* Is this a word before a => operator? */
4160 if (*s == '=' && s[1] == '>' && !pkgname) {
4162 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
4163 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
4164 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
4168 /* If followed by a paren, it's certainly a subroutine. */
4171 if (gv && GvCVu(gv)) {
4172 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
4173 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
4178 PL_nextval[PL_nexttoke].opval = yylval.opval;
4179 PL_expect = XOPERATOR;
4185 /* If followed by var or block, call it a method (unless sub) */
4187 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
4188 PL_last_lop = PL_oldbufptr;
4189 PL_last_lop_op = OP_METHOD;
4193 /* If followed by a bareword, see if it looks like indir obj. */
4196 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
4197 && (tmp = intuit_method(s,gv)))
4200 /* Not a method, so call it a subroutine (if defined) */
4202 if (gv && GvCVu(gv)) {
4204 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
4205 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4206 "Ambiguous use of -%s resolved as -&%s()",
4207 PL_tokenbuf, PL_tokenbuf);
4208 /* Check for a constant sub */
4210 if ((sv = cv_const_sv(cv))) {
4212 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
4213 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
4214 yylval.opval->op_private = 0;
4218 /* Resolve to GV now. */
4219 op_free(yylval.opval);
4220 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4221 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
4222 PL_last_lop = PL_oldbufptr;
4223 PL_last_lop_op = OP_ENTERSUB;
4224 /* Is there a prototype? */
4227 const char *proto = SvPV_const((SV*)cv, len);
4230 if (*proto == '$' && proto[1] == '\0')
4232 while (*proto == ';')
4234 if (*proto == '&' && *s == '{') {
4235 sv_setpv(PL_subname, PL_curstash ?
4236 "__ANON__" : "__ANON__::__ANON__");
4240 PL_nextval[PL_nexttoke].opval = yylval.opval;
4246 /* Call it a bare word */
4248 if (PL_hints & HINT_STRICT_SUBS)
4249 yylval.opval->op_private |= OPpCONST_STRICT;
4252 if (ckWARN(WARN_RESERVED)) {
4253 if (lastchar != '-') {
4254 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
4255 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
4256 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
4263 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
4264 && ckWARN_d(WARN_AMBIGUOUS)) {
4265 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4266 "Operator or semicolon missing before %c%s",
4267 lastchar, PL_tokenbuf);
4268 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4269 "Ambiguous use of %c resolved as operator %c",
4270 lastchar, lastchar);
4276 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4277 newSVpv(CopFILE(PL_curcop),0));
4281 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4282 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
4285 case KEY___PACKAGE__:
4286 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4288 ? newSVpv(HvNAME_get(PL_curstash), 0)
4295 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
4296 const char *pname = "main";
4297 if (PL_tokenbuf[2] == 'D')
4298 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
4299 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);
4302 GvIOp(gv) = newIO();
4303 IoIFP(GvIOp(gv)) = PL_rsfp;
4304 #if defined(HAS_FCNTL) && defined(F_SETFD)
4306 const int fd = PerlIO_fileno(PL_rsfp);
4307 fcntl(fd,F_SETFD,fd >= 3);
4310 /* Mark this internal pseudo-handle as clean */
4311 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4313 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
4314 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
4315 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
4317 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
4318 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
4319 /* if the script was opened in binmode, we need to revert
4320 * it to text mode for compatibility; but only iff it has CRs
4321 * XXX this is a questionable hack at best. */
4322 if (PL_bufend-PL_bufptr > 2
4323 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
4326 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
4327 loc = PerlIO_tell(PL_rsfp);
4328 (void)PerlIO_seek(PL_rsfp, 0L, 0);
4331 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
4333 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
4334 #endif /* NETWARE */
4335 #ifdef PERLIO_IS_STDIO /* really? */
4336 # if defined(__BORLANDC__)
4337 /* XXX see note in do_binmode() */
4338 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
4342 PerlIO_seek(PL_rsfp, loc, 0);
4346 #ifdef PERLIO_LAYERS
4349 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
4350 else if (PL_encoding) {
4357 XPUSHs(PL_encoding);
4359 call_method("name", G_SCALAR);
4363 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
4364 Perl_form(aTHX_ ":encoding(%"SVf")",
4382 if (PL_expect == XSTATE) {
4389 if (*s == ':' && s[1] == ':') {
4392 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4393 if (!(tmp = keyword(PL_tokenbuf, len)))
4394 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
4408 LOP(OP_ACCEPT,XTERM);
4414 LOP(OP_ATAN2,XTERM);
4420 LOP(OP_BINMODE,XTERM);
4423 LOP(OP_BLESS,XTERM);
4432 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
4449 if (!PL_cryptseen) {
4450 PL_cryptseen = TRUE;
4454 LOP(OP_CRYPT,XTERM);
4457 LOP(OP_CHMOD,XTERM);
4460 LOP(OP_CHOWN,XTERM);
4463 LOP(OP_CONNECT,XTERM);
4479 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4483 PL_hints |= HINT_BLOCK_SCOPE;
4493 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
4494 LOP(OP_DBMOPEN,XTERM);
4500 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4507 yylval.ival = CopLINE(PL_curcop);
4521 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4522 UNIBRACK(OP_ENTEREVAL);
4537 case KEY_endhostent:
4543 case KEY_endservent:
4546 case KEY_endprotoent:
4557 yylval.ival = CopLINE(PL_curcop);
4559 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4561 if ((PL_bufend - p) >= 3 &&
4562 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4564 else if ((PL_bufend - p) >= 4 &&
4565 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4568 if (isIDFIRST_lazy_if(p,UTF)) {
4569 p = scan_ident(p, PL_bufend,
4570 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4574 Perl_croak(aTHX_ "Missing $ on loop variable");
4579 LOP(OP_FORMLINE,XTERM);
4585 LOP(OP_FCNTL,XTERM);
4591 LOP(OP_FLOCK,XTERM);
4600 LOP(OP_GREPSTART, XREF);
4603 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4618 case KEY_getpriority:
4619 LOP(OP_GETPRIORITY,XTERM);
4621 case KEY_getprotobyname:
4624 case KEY_getprotobynumber:
4625 LOP(OP_GPBYNUMBER,XTERM);
4627 case KEY_getprotoent:
4639 case KEY_getpeername:
4640 UNI(OP_GETPEERNAME);
4642 case KEY_gethostbyname:
4645 case KEY_gethostbyaddr:
4646 LOP(OP_GHBYADDR,XTERM);
4648 case KEY_gethostent:
4651 case KEY_getnetbyname:
4654 case KEY_getnetbyaddr:
4655 LOP(OP_GNBYADDR,XTERM);
4660 case KEY_getservbyname:
4661 LOP(OP_GSBYNAME,XTERM);
4663 case KEY_getservbyport:
4664 LOP(OP_GSBYPORT,XTERM);
4666 case KEY_getservent:
4669 case KEY_getsockname:
4670 UNI(OP_GETSOCKNAME);
4672 case KEY_getsockopt:
4673 LOP(OP_GSOCKOPT,XTERM);
4695 yylval.ival = CopLINE(PL_curcop);
4699 LOP(OP_INDEX,XTERM);
4705 LOP(OP_IOCTL,XTERM);
4717 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4749 LOP(OP_LISTEN,XTERM);
4758 s = scan_pat(s,OP_MATCH);
4759 TERM(sublex_start());
4762 LOP(OP_MAPSTART, XREF);
4765 LOP(OP_MKDIR,XTERM);
4768 LOP(OP_MSGCTL,XTERM);
4771 LOP(OP_MSGGET,XTERM);
4774 LOP(OP_MSGRCV,XTERM);
4777 LOP(OP_MSGSND,XTERM);
4783 if (isIDFIRST_lazy_if(s,UTF)) {
4784 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4785 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4787 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
4788 if (!PL_in_my_stash) {
4791 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4799 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4806 if (PL_expect != XSTATE)
4807 yyerror("\"no\" not allowed in expression");
4808 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4809 s = force_version(s, FALSE);
4814 if (*s == '(' || (s = skipspace(s), *s == '('))
4821 if (isIDFIRST_lazy_if(s,UTF)) {
4823 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
4824 for (t=d; *t && isSPACE(*t); t++) ;
4825 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
4827 && !(t[0] == '=' && t[1] == '>')
4829 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
4830 "Precedence problem: open %.*s should be open(%.*s)",
4831 d - s, s, d - s, s);
4837 yylval.ival = OP_OR;
4847 LOP(OP_OPEN_DIR,XTERM);
4850 checkcomma(s,PL_tokenbuf,"filehandle");
4854 checkcomma(s,PL_tokenbuf,"filehandle");
4873 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4877 LOP(OP_PIPE_OP,XTERM);
4880 s = scan_str(s,FALSE,FALSE);
4882 missingterm((char*)0);
4883 yylval.ival = OP_CONST;
4884 TERM(sublex_start());
4890 s = scan_str(s,FALSE,FALSE);
4892 missingterm((char*)0);
4893 PL_expect = XOPERATOR;
4895 if (SvCUR(PL_lex_stuff)) {
4898 d = SvPV_force(PL_lex_stuff, len);
4901 for (; isSPACE(*d) && len; --len, ++d) ;
4904 if (!warned && ckWARN(WARN_QW)) {
4905 for (; !isSPACE(*d) && len; --len, ++d) {
4907 Perl_warner(aTHX_ packWARN(WARN_QW),
4908 "Possible attempt to separate words with commas");
4911 else if (*d == '#') {
4912 Perl_warner(aTHX_ packWARN(WARN_QW),
4913 "Possible attempt to put comments in qw() list");
4919 for (; !isSPACE(*d) && len; --len, ++d) ;
4921 sv = newSVpvn(b, d-b);
4922 if (DO_UTF8(PL_lex_stuff))
4924 words = append_elem(OP_LIST, words,
4925 newSVOP(OP_CONST, 0, tokeq(sv)));
4929 PL_nextval[PL_nexttoke].opval = words;
4934 SvREFCNT_dec(PL_lex_stuff);
4935 PL_lex_stuff = Nullsv;
4941 s = scan_str(s,FALSE,FALSE);
4943 missingterm((char*)0);
4944 yylval.ival = OP_STRINGIFY;
4945 if (SvIVX(PL_lex_stuff) == '\'')
4946 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
4947 TERM(sublex_start());
4950 s = scan_pat(s,OP_QR);
4951 TERM(sublex_start());
4954 s = scan_str(s,FALSE,FALSE);
4956 missingterm((char*)0);
4957 yylval.ival = OP_BACKTICK;
4959 TERM(sublex_start());
4967 s = force_version(s, FALSE);
4969 else if (*s != 'v' || !isDIGIT(s[1])
4970 || (s = force_version(s, TRUE), *s == 'v'))
4972 *PL_tokenbuf = '\0';
4973 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4974 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
4975 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
4977 yyerror("<> should be quotes");
4985 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4989 LOP(OP_RENAME,XTERM);
4998 LOP(OP_RINDEX,XTERM);
5021 LOP(OP_REVERSE,XTERM);
5032 TERM(sublex_start());
5034 TOKEN(1); /* force error */
5043 LOP(OP_SELECT,XTERM);
5049 LOP(OP_SEMCTL,XTERM);
5052 LOP(OP_SEMGET,XTERM);
5055 LOP(OP_SEMOP,XTERM);
5061 LOP(OP_SETPGRP,XTERM);
5063 case KEY_setpriority:
5064 LOP(OP_SETPRIORITY,XTERM);
5066 case KEY_sethostent:
5072 case KEY_setservent:
5075 case KEY_setprotoent:
5085 LOP(OP_SEEKDIR,XTERM);
5087 case KEY_setsockopt:
5088 LOP(OP_SSOCKOPT,XTERM);
5094 LOP(OP_SHMCTL,XTERM);
5097 LOP(OP_SHMGET,XTERM);
5100 LOP(OP_SHMREAD,XTERM);
5103 LOP(OP_SHMWRITE,XTERM);
5106 LOP(OP_SHUTDOWN,XTERM);
5115 LOP(OP_SOCKET,XTERM);
5117 case KEY_socketpair:
5118 LOP(OP_SOCKPAIR,XTERM);
5121 checkcomma(s,PL_tokenbuf,"subroutine name");
5123 if (*s == ';' || *s == ')') /* probably a close */
5124 Perl_croak(aTHX_ "sort is now a reserved word");
5126 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5130 LOP(OP_SPLIT,XTERM);
5133 LOP(OP_SPRINTF,XTERM);
5136 LOP(OP_SPLICE,XTERM);
5151 LOP(OP_SUBSTR,XTERM);
5157 char tmpbuf[sizeof PL_tokenbuf];
5158 SSize_t tboffset = 0;
5159 expectation attrful;
5160 bool have_name, have_proto, bad_proto;
5161 const int key = tmp;
5165 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
5166 (*s == ':' && s[1] == ':'))
5169 attrful = XATTRBLOCK;
5170 /* remember buffer pos'n for later force_word */
5171 tboffset = s - PL_oldbufptr;
5172 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5173 if (strchr(tmpbuf, ':'))
5174 sv_setpv(PL_subname, tmpbuf);
5176 sv_setsv(PL_subname,PL_curstname);
5177 sv_catpvn(PL_subname,"::",2);
5178 sv_catpvn(PL_subname,tmpbuf,len);
5185 Perl_croak(aTHX_ "Missing name in \"my sub\"");
5186 PL_expect = XTERMBLOCK;
5187 attrful = XATTRTERM;
5188 sv_setpvn(PL_subname,"?",1);
5192 if (key == KEY_format) {
5194 PL_lex_formbrack = PL_lex_brackets + 1;
5196 (void) force_word(PL_oldbufptr + tboffset, WORD,
5201 /* Look for a prototype */
5205 s = scan_str(s,FALSE,FALSE);
5207 Perl_croak(aTHX_ "Prototype not terminated");
5208 /* strip spaces and check for bad characters */
5209 d = SvPVX(PL_lex_stuff);
5212 for (p = d; *p; ++p) {
5215 if (!strchr("$@%*;[]&\\", *p))
5220 if (bad_proto && ckWARN(WARN_SYNTAX))
5221 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5222 "Illegal character in prototype for %"SVf" : %s",
5224 SvCUR_set(PL_lex_stuff, tmp);
5232 if (*s == ':' && s[1] != ':')
5233 PL_expect = attrful;
5234 else if (*s != '{' && key == KEY_sub) {
5236 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
5238 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname);
5242 PL_nextval[PL_nexttoke].opval =
5243 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
5244 PL_lex_stuff = Nullsv;
5248 sv_setpv(PL_subname,
5249 PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
5252 (void) force_word(PL_oldbufptr + tboffset, WORD,
5261 LOP(OP_SYSTEM,XREF);
5264 LOP(OP_SYMLINK,XTERM);
5267 LOP(OP_SYSCALL,XTERM);
5270 LOP(OP_SYSOPEN,XTERM);
5273 LOP(OP_SYSSEEK,XTERM);
5276 LOP(OP_SYSREAD,XTERM);
5279 LOP(OP_SYSWRITE,XTERM);
5283 TERM(sublex_start());
5304 LOP(OP_TRUNCATE,XTERM);
5316 yylval.ival = CopLINE(PL_curcop);
5320 yylval.ival = CopLINE(PL_curcop);
5324 LOP(OP_UNLINK,XTERM);
5330 LOP(OP_UNPACK,XTERM);
5333 LOP(OP_UTIME,XTERM);
5339 LOP(OP_UNSHIFT,XTERM);
5342 if (PL_expect != XSTATE)
5343 yyerror("\"use\" not allowed in expression");
5345 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
5346 s = force_version(s, TRUE);
5347 if (*s == ';' || (s = skipspace(s), *s == ';')) {
5348 PL_nextval[PL_nexttoke].opval = Nullop;
5351 else if (*s == 'v') {
5352 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5353 s = force_version(s, FALSE);
5357 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5358 s = force_version(s, FALSE);
5370 yylval.ival = CopLINE(PL_curcop);
5374 PL_hints |= HINT_BLOCK_SCOPE;
5381 LOP(OP_WAITPID,XTERM);
5390 ctl_l[0] = toCTRL('L');
5392 gv_fetchpv(ctl_l,TRUE, SVt_PV);
5395 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
5400 if (PL_expect == XOPERATOR)
5406 yylval.ival = OP_XOR;
5411 TERM(sublex_start());
5416 #pragma segment Main
5420 S_pending_ident(pTHX)
5423 register I32 tmp = 0;
5424 /* pit holds the identifier we read and pending_ident is reset */
5425 char pit = PL_pending_ident;
5426 PL_pending_ident = 0;
5428 DEBUG_T({ PerlIO_printf(Perl_debug_log,
5429 "### Tokener saw identifier '%s'\n", PL_tokenbuf); });
5431 /* if we're in a my(), we can't allow dynamics here.
5432 $foo'bar has already been turned into $foo::bar, so
5433 just check for colons.
5435 if it's a legal name, the OP is a PADANY.
5438 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
5439 if (strchr(PL_tokenbuf,':'))
5440 yyerror(Perl_form(aTHX_ "No package name allowed for "
5441 "variable %s in \"our\"",
5443 tmp = allocmy(PL_tokenbuf);
5446 if (strchr(PL_tokenbuf,':'))
5447 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
5449 yylval.opval = newOP(OP_PADANY, 0);
5450 yylval.opval->op_targ = allocmy(PL_tokenbuf);
5456 build the ops for accesses to a my() variable.
5458 Deny my($a) or my($b) in a sort block, *if* $a or $b is
5459 then used in a comparison. This catches most, but not
5460 all cases. For instance, it catches
5461 sort { my($a); $a <=> $b }
5463 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
5464 (although why you'd do that is anyone's guess).
5467 if (!strchr(PL_tokenbuf,':')) {
5468 #ifdef USE_5005THREADS
5469 /* Check for single character per-thread SVs */
5470 if (PL_tokenbuf[0] == '$' && PL_tokenbuf[2] == '\0'
5471 && !isALPHA(PL_tokenbuf[1]) /* Rule out obvious non-threadsvs */
5472 && (tmp = find_threadsv(&PL_tokenbuf[1])) != NOT_IN_PAD)
5474 yylval.opval = newOP(OP_THREADSV, 0);
5475 yylval.opval->op_targ = tmp;
5478 #endif /* USE_5005THREADS */
5480 tmp = pad_findmy(PL_tokenbuf);
5481 if (tmp != NOT_IN_PAD) {
5482 /* might be an "our" variable" */
5483 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
5484 /* build ops for a bareword */
5485 SV *sym = newSVpv(HvNAME_get(PAD_COMPNAME_OURSTASH(tmp)), 0);
5486 sv_catpvn(sym, "::", 2);
5487 sv_catpv(sym, PL_tokenbuf+1);
5488 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
5489 yylval.opval->op_private = OPpCONST_ENTERED;
5490 gv_fetchpv(SvPVX(sym),
5492 ? (GV_ADDMULTI | GV_ADDINEVAL)
5495 ((PL_tokenbuf[0] == '$') ? SVt_PV
5496 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5501 /* if it's a sort block and they're naming $a or $b */
5502 if (PL_last_lop_op == OP_SORT &&
5503 PL_tokenbuf[0] == '$' &&
5504 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
5507 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
5508 d < PL_bufend && *d != '\n';
5511 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
5512 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
5518 yylval.opval = newOP(OP_PADANY, 0);
5519 yylval.opval->op_targ = tmp;
5525 Whine if they've said @foo in a doublequoted string,
5526 and @foo isn't a variable we can find in the symbol
5529 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
5530 GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
5531 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
5532 && ckWARN(WARN_AMBIGUOUS))
5534 /* Downgraded from fatal to warning 20000522 mjd */
5535 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5536 "Possible unintended interpolation of %s in string",
5541 /* build ops for a bareword */
5542 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
5543 yylval.opval->op_private = OPpCONST_ENTERED;
5544 gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
5545 ((PL_tokenbuf[0] == '$') ? SVt_PV
5546 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5552 * The following code was generated by perl_keyword.pl.
5556 Perl_keyword (pTHX_ char *name, I32 len)
5560 case 1: /* 5 tokens of length 1 */
5592 case 2: /* 18 tokens of length 2 */
5738 case 3: /* 27 tokens of length 3 */
5742 if (name[1] == 'N' &&
5805 if (name[1] == 'i' &&
5837 if (name[1] == 'o' &&
5846 if (name[1] == 'e' &&
5855 if (name[1] == 'n' &&
5864 if (name[1] == 'o' &&
5873 if (name[1] == 'a' &&
5882 if (name[1] == 'o' &&
5944 if (name[1] == 'e' &&
5976 if (name[1] == 'i' &&
5985 if (name[1] == 's' &&
5994 if (name[1] == 'e' &&
6003 if (name[1] == 'o' &&
6015 case 4: /* 40 tokens of length 4 */
6019 if (name[1] == 'O' &&
6029 if (name[1] == 'N' &&
6039 if (name[1] == 'i' &&
6049 if (name[1] == 'h' &&
6059 if (name[1] == 'u' &&
6072 if (name[2] == 'c' &&
6081 if (name[2] == 's' &&
6090 if (name[2] == 'a' &&
6126 if (name[1] == 'o' &&
6139 if (name[2] == 't' &&
6148 if (name[2] == 'o' &&
6157 if (name[2] == 't' &&
6166 if (name[2] == 'e' &&
6179 if (name[1] == 'o' &&
6192 if (name[2] == 'y' &&
6201 if (name[2] == 'l' &&
6217 if (name[2] == 's' &&
6226 if (name[2] == 'n' &&
6235 if (name[2] == 'c' &&
6248 if (name[1] == 'e' &&
6258 if (name[1] == 'p' &&
6271 if (name[2] == 'c' &&
6280 if (name[2] == 'p' &&
6289 if (name[2] == 's' &&
6305 if (name[2] == 'n' &&
6375 if (name[2] == 'r' &&
6384 if (name[2] == 'r' &&
6393 if (name[2] == 'a' &&
6409 if (name[2] == 'l' &&
6476 case 5: /* 36 tokens of length 5 */
6480 if (name[1] == 'E' &&
6491 if (name[1] == 'H' &&
6505 if (name[2] == 'a' &&
6515 if (name[2] == 'a' &&
6529 if (name[1] == 'l' &&
6546 if (name[3] == 'i' &&
6555 if (name[3] == 'o' &&
6591 if (name[2] == 'o' &&
6601 if (name[2] == 'y' &&
6615 if (name[1] == 'l' &&
6629 if (name[2] == 'n' &&
6639 if (name[2] == 'o' &&
6656 if (name[2] == 'd' &&
6666 if (name[2] == 'c' &&
6683 if (name[2] == 'c' &&
6693 if (name[2] == 't' &&
6707 if (name[1] == 'k' &&
6718 if (name[1] == 'r' &&
6732 if (name[2] == 's' &&
6742 if (name[2] == 'd' &&
6759 if (name[2] == 'm' &&
6769 if (name[2] == 'i' &&
6779 if (name[2] == 'e' &&
6789 if (name[2] == 'l' &&
6799 if (name[2] == 'a' &&
6809 if (name[2] == 'u' &&
6823 if (name[1] == 'i' &&
6837 if (name[2] == 'a' &&
6850 if (name[3] == 'e' &&
6885 if (name[2] == 'i' &&
6902 if (name[2] == 'i' &&
6912 if (name[2] == 'i' &&
6929 case 6: /* 33 tokens of length 6 */
6933 if (name[1] == 'c' &&
6948 if (name[2] == 'l' &&
6959 if (name[2] == 'r' &&
6974 if (name[1] == 'e' &&
6989 if (name[2] == 's' &&
6994 if(ckWARN_d(WARN_SYNTAX))
6995 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
7001 if (name[2] == 'i' &&
7019 if (name[2] == 'l' &&
7030 if (name[2] == 'r' &&
7045 if (name[1] == 'm' &&
7060 if (name[2] == 'n' &&
7071 if (name[2] == 's' &&
7086 if (name[1] == 's' &&
7092 if (name[4] == 't' &&
7101 if (name[4] == 'e' &&
7110 if (name[4] == 'c' &&
7119 if (name[4] == 'n' &&
7135 if (name[1] == 'r' &&
7153 if (name[3] == 'a' &&
7163 if (name[3] == 'u' &&
7177 if (name[2] == 'n' &&
7195 if (name[2] == 'a' &&
7209 if (name[3] == 'e' &&
7222 if (name[4] == 't' &&
7231 if (name[4] == 'e' &&
7253 if (name[4] == 't' &&
7262 if (name[4] == 'e' &&
7278 if (name[2] == 'c' &&
7289 if (name[2] == 'l' &&
7300 if (name[2] == 'b' &&
7311 if (name[2] == 's' &&
7334 if (name[4] == 's' &&
7343 if (name[4] == 'n' &&
7356 if (name[3] == 'a' &&
7373 if (name[1] == 'a' &&
7388 case 7: /* 28 tokens of length 7 */
7392 if (name[1] == 'E' &&
7405 if (name[1] == '_' &&
7418 if (name[1] == 'i' &&
7425 return -KEY_binmode;
7431 if (name[1] == 'o' &&
7438 return -KEY_connect;
7447 if (name[2] == 'm' &&
7453 return -KEY_dbmopen;
7459 if (name[2] == 'f' &&
7475 if (name[1] == 'o' &&
7488 if (name[1] == 'e' &&
7495 if (name[5] == 'r' &&
7498 return -KEY_getpgrp;
7504 if (name[5] == 'i' &&
7507 return -KEY_getppid;
7520 if (name[1] == 'c' &&
7527 return -KEY_lcfirst;
7533 if (name[1] == 'p' &&
7540 return -KEY_opendir;
7546 if (name[1] == 'a' &&
7564 if (name[3] == 'd' &&
7569 return -KEY_readdir;
7575 if (name[3] == 'u' &&
7586 if (name[3] == 'e' &&
7591 return -KEY_reverse;
7610 if (name[3] == 'k' &&
7615 return -KEY_seekdir;
7621 if (name[3] == 'p' &&
7626 return -KEY_setpgrp;
7636 if (name[2] == 'm' &&
7642 return -KEY_shmread;
7648 if (name[2] == 'r' &&
7654 return -KEY_sprintf;
7663 if (name[3] == 'l' &&
7668 return -KEY_symlink;
7677 if (name[4] == 'a' &&
7681 return -KEY_syscall;
7687 if (name[4] == 'p' &&
7691 return -KEY_sysopen;
7697 if (name[4] == 'e' &&
7701 return -KEY_sysread;
7707 if (name[4] == 'e' &&
7711 return -KEY_sysseek;
7729 if (name[1] == 'e' &&
7736 return -KEY_telldir;
7745 if (name[2] == 'f' &&
7751 return -KEY_ucfirst;
7757 if (name[2] == 's' &&
7763 return -KEY_unshift;
7773 if (name[1] == 'a' &&
7780 return -KEY_waitpid;
7789 case 8: /* 26 tokens of length 8 */
7793 if (name[1] == 'U' &&
7801 return KEY_AUTOLOAD;
7812 if (name[3] == 'A' &&
7818 return KEY___DATA__;
7824 if (name[3] == 'I' &&
7830 return -KEY___FILE__;
7836 if (name[3] == 'I' &&
7842 return -KEY___LINE__;
7858 if (name[2] == 'o' &&
7865 return -KEY_closedir;
7871 if (name[2] == 'n' &&
7878 return -KEY_continue;
7888 if (name[1] == 'b' &&
7896 return -KEY_dbmclose;
7902 if (name[1] == 'n' &&
7908 if (name[4] == 'r' &&
7913 return -KEY_endgrent;
7919 if (name[4] == 'w' &&
7924 return -KEY_endpwent;
7937 if (name[1] == 'o' &&
7945 return -KEY_formline;
7951 if (name[1] == 'e' &&
7962 if (name[6] == 'n' &&
7965 return -KEY_getgrent;
7971 if (name[6] == 'i' &&
7974 return -KEY_getgrgid;
7980 if (name[6] == 'a' &&
7983 return -KEY_getgrnam;
7996 if (name[4] == 'o' &&
8001 return -KEY_getlogin;
8012 if (name[6] == 'n' &&
8015 return -KEY_getpwent;
8021 if (name[6] == 'a' &&
8024 return -KEY_getpwnam;
8030 if (name[6] == 'i' &&
8033 return -KEY_getpwuid;
8053 if (name[1] == 'e' &&
8060 if (name[5] == 'i' &&
8067 return -KEY_readline;
8072 return -KEY_readlink;
8083 if (name[5] == 'i' &&
8087 return -KEY_readpipe;
8108 if (name[4] == 'r' &&
8113 return -KEY_setgrent;
8119 if (name[4] == 'w' &&
8124 return -KEY_setpwent;
8140 if (name[3] == 'w' &&
8146 return -KEY_shmwrite;
8152 if (name[3] == 't' &&
8158 return -KEY_shutdown;
8168 if (name[2] == 's' &&
8175 return -KEY_syswrite;
8185 if (name[1] == 'r' &&
8193 return -KEY_truncate;
8202 case 9: /* 8 tokens of length 9 */
8206 if (name[1] == 'n' &&
8215 return -KEY_endnetent;
8221 if (name[1] == 'e' &&
8230 return -KEY_getnetent;
8236 if (name[1] == 'o' &&
8245 return -KEY_localtime;
8251 if (name[1] == 'r' &&
8260 return KEY_prototype;
8266 if (name[1] == 'u' &&
8275 return -KEY_quotemeta;
8281 if (name[1] == 'e' &&
8290 return -KEY_rewinddir;
8296 if (name[1] == 'e' &&
8305 return -KEY_setnetent;
8311 if (name[1] == 'a' &&
8320 return -KEY_wantarray;
8329 case 10: /* 9 tokens of length 10 */
8333 if (name[1] == 'n' &&
8339 if (name[4] == 'o' &&
8346 return -KEY_endhostent;
8352 if (name[4] == 'e' &&
8359 return -KEY_endservent;
8372 if (name[1] == 'e' &&
8378 if (name[4] == 'o' &&
8385 return -KEY_gethostent;
8394 if (name[5] == 'r' &&
8400 return -KEY_getservent;
8406 if (name[5] == 'c' &&
8412 return -KEY_getsockopt;
8437 if (name[4] == 'o' &&
8444 return -KEY_sethostent;
8453 if (name[5] == 'r' &&
8459 return -KEY_setservent;
8465 if (name[5] == 'c' &&
8471 return -KEY_setsockopt;
8488 if (name[2] == 'c' &&
8497 return -KEY_socketpair;
8510 case 11: /* 8 tokens of length 11 */
8514 if (name[1] == '_' &&
8525 return -KEY___PACKAGE__;
8531 if (name[1] == 'n' &&
8542 return -KEY_endprotoent;
8548 if (name[1] == 'e' &&
8557 if (name[5] == 'e' &&
8564 return -KEY_getpeername;
8573 if (name[6] == 'o' &&
8579 return -KEY_getpriority;
8585 if (name[6] == 't' &&
8591 return -KEY_getprotoent;
8605 if (name[4] == 'o' &&
8613 return -KEY_getsockname;
8626 if (name[1] == 'e' &&
8634 if (name[6] == 'o' &&
8640 return -KEY_setpriority;
8646 if (name[6] == 't' &&
8652 return -KEY_setprotoent;
8668 case 12: /* 2 tokens of length 12 */
8669 if (name[0] == 'g' &&
8681 if (name[9] == 'd' &&
8684 { /* getnetbyaddr */
8685 return -KEY_getnetbyaddr;
8691 if (name[9] == 'a' &&
8694 { /* getnetbyname */
8695 return -KEY_getnetbyname;
8707 case 13: /* 4 tokens of length 13 */
8708 if (name[0] == 'g' &&
8715 if (name[4] == 'o' &&
8724 if (name[10] == 'd' &&
8727 { /* gethostbyaddr */
8728 return -KEY_gethostbyaddr;
8734 if (name[10] == 'a' &&
8737 { /* gethostbyname */
8738 return -KEY_gethostbyname;
8751 if (name[4] == 'e' &&
8760 if (name[10] == 'a' &&
8763 { /* getservbyname */
8764 return -KEY_getservbyname;
8770 if (name[10] == 'o' &&
8773 { /* getservbyport */
8774 return -KEY_getservbyport;
8793 case 14: /* 1 tokens of length 14 */
8794 if (name[0] == 'g' &&
8808 { /* getprotobyname */
8809 return -KEY_getprotobyname;
8814 case 16: /* 1 tokens of length 16 */
8815 if (name[0] == 'g' &&
8831 { /* getprotobynumber */
8832 return -KEY_getprotobynumber;
8846 S_checkcomma(pTHX_ register char *s, const char *name, const char *what)
8850 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
8851 if (ckWARN(WARN_SYNTAX)) {
8853 for (w = s+2; *w && level; w++) {
8860 for (; *w && isSPACE(*w); w++) ;
8861 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
8862 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
8863 "%s (...) interpreted as function",name);
8866 while (s < PL_bufend && isSPACE(*s))
8870 while (s < PL_bufend && isSPACE(*s))
8872 if (isIDFIRST_lazy_if(s,UTF)) {
8874 while (isALNUM_lazy_if(s,UTF))
8876 while (s < PL_bufend && isSPACE(*s))
8880 *s = '\0'; /* XXX If we didn't do this, we could const a lot of toke.c */
8881 kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
8885 Perl_croak(aTHX_ "No comma allowed after %s", what);
8890 /* Either returns sv, or mortalizes sv and returns a new SV*.
8891 Best used as sv=new_constant(..., sv, ...).
8892 If s, pv are NULL, calls subroutine with one argument,
8893 and type is used with error messages only. */
8896 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
8900 HV *table = GvHV(PL_hintgv); /* ^H */
8904 const char *why1 = "", *why2 = "", *why3 = "";
8906 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
8909 why2 = strEQ(key,"charnames")
8910 ? "(possibly a missing \"use charnames ...\")"
8912 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
8913 (type ? type: "undef"), why2);
8915 /* This is convoluted and evil ("goto considered harmful")
8916 * but I do not understand the intricacies of all the different
8917 * failure modes of %^H in here. The goal here is to make
8918 * the most probable error message user-friendly. --jhi */
8923 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
8924 (type ? type: "undef"), why1, why2, why3);
8926 yyerror(SvPVX_const(msg));
8930 cvp = hv_fetch(table, key, strlen(key), FALSE);
8931 if (!cvp || !SvOK(*cvp)) {
8934 why3 = "} is not defined";
8937 sv_2mortal(sv); /* Parent created it permanently */
8940 pv = sv_2mortal(newSVpvn(s, len));
8942 typesv = sv_2mortal(newSVpv(type, 0));
8944 typesv = &PL_sv_undef;
8946 PUSHSTACKi(PERLSI_OVERLOAD);
8958 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
8962 /* Check the eval first */
8963 if (!PL_in_eval && SvTRUE(ERRSV)) {
8964 sv_catpv(ERRSV, "Propagated");
8965 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
8967 res = SvREFCNT_inc(sv);
8971 (void)SvREFCNT_inc(res);
8980 why1 = "Call to &{$^H{";
8982 why3 = "}} did not return a defined value";
8991 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
8993 register char *d = dest;
8994 register char *e = d + destlen - 3; /* two-character token, ending NUL */
8997 Perl_croak(aTHX_ ident_too_long);
8998 if (isALNUM(*s)) /* UTF handled below */
9000 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
9005 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
9009 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9010 char *t = s + UTF8SKIP(s);
9011 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9013 if (d + (t - s) > e)
9014 Perl_croak(aTHX_ ident_too_long);
9015 Copy(s, d, t - s, char);
9028 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
9038 e = d + destlen - 3; /* two-character token, ending NUL */
9040 while (isDIGIT(*s)) {
9042 Perl_croak(aTHX_ ident_too_long);
9049 Perl_croak(aTHX_ ident_too_long);
9050 if (isALNUM(*s)) /* UTF handled below */
9052 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
9057 else if (*s == ':' && s[1] == ':') {
9061 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9062 char *t = s + UTF8SKIP(s);
9063 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9065 if (d + (t - s) > e)
9066 Perl_croak(aTHX_ ident_too_long);
9067 Copy(s, d, t - s, char);
9078 if (PL_lex_state != LEX_NORMAL)
9079 PL_lex_state = LEX_INTERPENDMAYBE;
9082 if (*s == '$' && s[1] &&
9083 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
9096 if (*d == '^' && *s && isCONTROLVAR(*s)) {
9101 if (isSPACE(s[-1])) {
9103 const char ch = *s++;
9104 if (!SPACE_OR_TAB(ch)) {
9110 if (isIDFIRST_lazy_if(d,UTF)) {
9114 while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') {
9116 while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e))
9119 Copy(s, d, e - s, char);
9124 while ((isALNUM(*s) || *s == ':') && d < e)
9127 Perl_croak(aTHX_ ident_too_long);
9130 while (s < send && SPACE_OR_TAB(*s)) s++;
9131 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
9132 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
9133 const char *brack = *s == '[' ? "[...]" : "{...}";
9134 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9135 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
9136 funny, dest, brack, funny, dest, brack);
9139 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
9143 /* Handle extended ${^Foo} variables
9144 * 1999-02-27 mjd-perl-patch@plover.com */
9145 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
9149 while (isALNUM(*s) && d < e) {
9153 Perl_croak(aTHX_ ident_too_long);
9158 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
9159 PL_lex_state = LEX_INTERPEND;
9164 if (PL_lex_state == LEX_NORMAL) {
9165 if (ckWARN(WARN_AMBIGUOUS) &&
9166 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
9168 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9169 "Ambiguous use of %c{%s} resolved to %c%s",
9170 funny, dest, funny, dest);
9175 s = bracket; /* let the parser handle it */
9179 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
9180 PL_lex_state = LEX_INTERPEND;
9185 Perl_pmflag(pTHX_ U32* pmfl, int ch)
9190 *pmfl |= PMf_GLOBAL;
9192 *pmfl |= PMf_CONTINUE;
9196 *pmfl |= PMf_MULTILINE;
9198 *pmfl |= PMf_SINGLELINE;
9200 *pmfl |= PMf_EXTENDED;
9204 S_scan_pat(pTHX_ char *start, I32 type)
9207 char *s = scan_str(start,FALSE,FALSE);
9210 char *delimiter = skipspace(start);
9211 Perl_croak(aTHX_ *delimiter == '?'
9212 ? "Search pattern not terminated or ternary operator parsed as search pattern"
9213 : "Search pattern not terminated" );
9216 pm = (PMOP*)newPMOP(type, 0);
9217 if (PL_multi_open == '?')
9218 pm->op_pmflags |= PMf_ONCE;
9220 while (*s && strchr("iomsx", *s))
9221 pmflag(&pm->op_pmflags,*s++);
9224 while (*s && strchr("iogcmsx", *s))
9225 pmflag(&pm->op_pmflags,*s++);
9227 /* issue a warning if /c is specified,but /g is not */
9228 if (ckWARN(WARN_REGEXP) &&
9229 (pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
9231 Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_without_g);
9234 pm->op_pmpermflags = pm->op_pmflags;
9236 PL_lex_op = (OP*)pm;
9237 yylval.ival = OP_MATCH;
9242 S_scan_subst(pTHX_ char *start)
9249 yylval.ival = OP_NULL;
9251 s = scan_str(start,FALSE,FALSE);
9254 Perl_croak(aTHX_ "Substitution pattern not terminated");
9256 if (s[-1] == PL_multi_open)
9259 first_start = PL_multi_start;
9260 s = scan_str(s,FALSE,FALSE);
9263 SvREFCNT_dec(PL_lex_stuff);
9264 PL_lex_stuff = Nullsv;
9266 Perl_croak(aTHX_ "Substitution replacement not terminated");
9268 PL_multi_start = first_start; /* so whole substitution is taken together */
9270 pm = (PMOP*)newPMOP(OP_SUBST, 0);
9276 else if (strchr("iogcmsx", *s))
9277 pmflag(&pm->op_pmflags,*s++);
9282 /* /c is not meaningful with s/// */
9283 if (ckWARN(WARN_REGEXP) && (pm->op_pmflags & PMf_CONTINUE))
9285 Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_in_subst);
9290 PL_sublex_info.super_bufptr = s;
9291 PL_sublex_info.super_bufend = PL_bufend;
9293 pm->op_pmflags |= PMf_EVAL;
9294 repl = newSVpvn("",0);
9296 sv_catpv(repl, es ? "eval " : "do ");
9297 sv_catpvn(repl, "{ ", 2);
9298 sv_catsv(repl, PL_lex_repl);
9299 sv_catpvn(repl, " };", 2);
9301 SvREFCNT_dec(PL_lex_repl);
9305 pm->op_pmpermflags = pm->op_pmflags;
9306 PL_lex_op = (OP*)pm;
9307 yylval.ival = OP_SUBST;
9312 S_scan_trans(pTHX_ char *start)
9321 yylval.ival = OP_NULL;
9323 s = scan_str(start,FALSE,FALSE);
9325 Perl_croak(aTHX_ "Transliteration pattern not terminated");
9326 if (s[-1] == PL_multi_open)
9329 s = scan_str(s,FALSE,FALSE);
9332 SvREFCNT_dec(PL_lex_stuff);
9333 PL_lex_stuff = Nullsv;
9335 Perl_croak(aTHX_ "Transliteration replacement not terminated");
9338 complement = del = squash = 0;
9342 complement = OPpTRANS_COMPLEMENT;
9345 del = OPpTRANS_DELETE;
9348 squash = OPpTRANS_SQUASH;
9357 New(803, tbl, complement&&!del?258:256, short);
9358 o = newPVOP(OP_TRANS, 0, (char*)tbl);
9359 o->op_private = del|squash|complement|
9360 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
9361 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
9364 yylval.ival = OP_TRANS;
9369 S_scan_heredoc(pTHX_ register char *s)
9372 I32 op_type = OP_SCALAR;
9376 const char newline[] = "\n";
9377 const char *found_newline;
9381 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
9385 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
9388 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
9389 if (*peek == '`' || *peek == '\'' || *peek =='"') {
9392 s = delimcpy(d, e, s, PL_bufend, term, &len);
9402 if (!isALNUM_lazy_if(s,UTF))
9403 deprecate_old("bare << to mean <<\"\"");
9404 for (; isALNUM_lazy_if(s,UTF); s++) {
9409 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
9410 Perl_croak(aTHX_ "Delimiter for here document is too long");
9413 len = d - PL_tokenbuf;
9414 #ifndef PERL_STRICT_CR
9415 d = strchr(s, '\r');
9417 char * const olds = s;
9419 while (s < PL_bufend) {
9425 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
9434 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
9438 if ( outer || !(found_newline = ninstr(s,PL_bufend,newline,newline+1)) ) {
9439 herewas = newSVpvn(s,PL_bufend-s);
9443 herewas = newSVpvn(s,found_newline-s);
9445 s += SvCUR(herewas);
9447 tmpstr = NEWSV(87,79);
9448 sv_upgrade(tmpstr, SVt_PVIV);
9451 SvIV_set(tmpstr, -1);
9453 else if (term == '`') {
9454 op_type = OP_BACKTICK;
9455 SvIV_set(tmpstr, '\\');
9459 PL_multi_start = CopLINE(PL_curcop);
9460 PL_multi_open = PL_multi_close = '<';
9461 term = *PL_tokenbuf;
9462 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
9463 char *bufptr = PL_sublex_info.super_bufptr;
9464 char *bufend = PL_sublex_info.super_bufend;
9465 char * const olds = s - SvCUR(herewas);
9466 s = strchr(bufptr, '\n');
9470 while (s < bufend &&
9471 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9473 CopLINE_inc(PL_curcop);
9476 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9477 missingterm(PL_tokenbuf);
9479 sv_setpvn(herewas,bufptr,d-bufptr+1);
9480 sv_setpvn(tmpstr,d+1,s-d);
9482 sv_catpvn(herewas,s,bufend-s);
9483 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
9490 while (s < PL_bufend &&
9491 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9493 CopLINE_inc(PL_curcop);
9495 if (s >= PL_bufend) {
9496 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9497 missingterm(PL_tokenbuf);
9499 sv_setpvn(tmpstr,d+1,s-d);
9501 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
9503 sv_catpvn(herewas,s,PL_bufend-s);
9504 sv_setsv(PL_linestr,herewas);
9505 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
9506 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9507 PL_last_lop = PL_last_uni = Nullch;
9510 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
9511 while (s >= PL_bufend) { /* multiple line string? */
9513 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
9514 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9515 missingterm(PL_tokenbuf);
9517 CopLINE_inc(PL_curcop);
9518 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9519 PL_last_lop = PL_last_uni = Nullch;
9520 #ifndef PERL_STRICT_CR
9521 if (PL_bufend - PL_linestart >= 2) {
9522 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
9523 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
9525 PL_bufend[-2] = '\n';
9527 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
9529 else if (PL_bufend[-1] == '\r')
9530 PL_bufend[-1] = '\n';
9532 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
9533 PL_bufend[-1] = '\n';
9535 if (PERLDB_LINE && PL_curstash != PL_debstash) {
9536 SV *sv = NEWSV(88,0);
9538 sv_upgrade(sv, SVt_PVMG);
9539 sv_setsv(sv,PL_linestr);
9542 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
9544 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
9545 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
9546 *(SvPVX(PL_linestr) + off ) = ' ';
9547 sv_catsv(PL_linestr,herewas);
9548 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9549 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
9553 sv_catsv(tmpstr,PL_linestr);
9558 PL_multi_end = CopLINE(PL_curcop);
9559 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
9560 SvPV_shrink_to_cur(tmpstr);
9562 SvREFCNT_dec(herewas);
9564 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
9566 else if (PL_encoding)
9567 sv_recode_to_utf8(tmpstr, PL_encoding);
9569 PL_lex_stuff = tmpstr;
9570 yylval.ival = op_type;
9575 takes: current position in input buffer
9576 returns: new position in input buffer
9577 side-effects: yylval and lex_op are set.
9582 <FH> read from filehandle
9583 <pkg::FH> read from package qualified filehandle
9584 <pkg'FH> read from package qualified filehandle
9585 <$fh> read from filehandle in $fh
9591 S_scan_inputsymbol(pTHX_ char *start)
9593 register char *s = start; /* current position in buffer */
9599 d = PL_tokenbuf; /* start of temp holding space */
9600 e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
9601 end = strchr(s, '\n');
9604 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
9606 /* die if we didn't have space for the contents of the <>,
9607 or if it didn't end, or if we see a newline
9610 if (len >= sizeof PL_tokenbuf)
9611 Perl_croak(aTHX_ "Excessively long <> operator");
9613 Perl_croak(aTHX_ "Unterminated <> operator");
9618 Remember, only scalar variables are interpreted as filehandles by
9619 this code. Anything more complex (e.g., <$fh{$num}>) will be
9620 treated as a glob() call.
9621 This code makes use of the fact that except for the $ at the front,
9622 a scalar variable and a filehandle look the same.
9624 if (*d == '$' && d[1]) d++;
9626 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
9627 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
9630 /* If we've tried to read what we allow filehandles to look like, and
9631 there's still text left, then it must be a glob() and not a getline.
9632 Use scan_str to pull out the stuff between the <> and treat it
9633 as nothing more than a string.
9636 if (d - PL_tokenbuf != len) {
9637 yylval.ival = OP_GLOB;
9639 s = scan_str(start,FALSE,FALSE);
9641 Perl_croak(aTHX_ "Glob not terminated");
9645 bool readline_overriden = FALSE;
9646 GV *gv_readline = Nullgv;
9648 /* we're in a filehandle read situation */
9651 /* turn <> into <ARGV> */
9653 Copy("ARGV",d,5,char);
9655 /* Check whether readline() is overriden */
9656 if (((gv_readline = gv_fetchpv("readline", FALSE, SVt_PVCV))
9657 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
9659 ((gvp = (GV**)hv_fetch(PL_globalstash, "readline", 8, FALSE))
9660 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
9661 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
9662 readline_overriden = TRUE;
9664 /* if <$fh>, create the ops to turn the variable into a
9670 /* try to find it in the pad for this block, otherwise find
9671 add symbol table ops
9673 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
9674 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
9675 SV *sym = sv_2mortal(
9676 newSVpv(HvNAME_get(PAD_COMPNAME_OURSTASH(tmp)),0));
9677 sv_catpvn(sym, "::", 2);
9683 OP *o = newOP(OP_PADSV, 0);
9685 PL_lex_op = readline_overriden
9686 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9687 append_elem(OP_LIST, o,
9688 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
9689 : (OP*)newUNOP(OP_READLINE, 0, o);
9698 ? (GV_ADDMULTI | GV_ADDINEVAL)
9701 PL_lex_op = readline_overriden
9702 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9703 append_elem(OP_LIST,
9704 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
9705 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9706 : (OP*)newUNOP(OP_READLINE, 0,
9707 newUNOP(OP_RV2SV, 0,
9708 newGVOP(OP_GV, 0, gv)));
9710 if (!readline_overriden)
9711 PL_lex_op->op_flags |= OPf_SPECIAL;
9712 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
9713 yylval.ival = OP_NULL;
9716 /* If it's none of the above, it must be a literal filehandle
9717 (<Foo::BAR> or <FOO>) so build a simple readline OP */
9719 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
9720 PL_lex_op = readline_overriden
9721 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9722 append_elem(OP_LIST,
9723 newGVOP(OP_GV, 0, gv),
9724 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9725 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
9726 yylval.ival = OP_NULL;
9735 takes: start position in buffer
9736 keep_quoted preserve \ on the embedded delimiter(s)
9737 keep_delims preserve the delimiters around the string
9738 returns: position to continue reading from buffer
9739 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
9740 updates the read buffer.
9742 This subroutine pulls a string out of the input. It is called for:
9743 q single quotes q(literal text)
9744 ' single quotes 'literal text'
9745 qq double quotes qq(interpolate $here please)
9746 " double quotes "interpolate $here please"
9747 qx backticks qx(/bin/ls -l)
9748 ` backticks `/bin/ls -l`
9749 qw quote words @EXPORT_OK = qw( func() $spam )
9750 m// regexp match m/this/
9751 s/// regexp substitute s/this/that/
9752 tr/// string transliterate tr/this/that/
9753 y/// string transliterate y/this/that/
9754 ($*@) sub prototypes sub foo ($)
9755 (stuff) sub attr parameters sub foo : attr(stuff)
9756 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
9758 In most of these cases (all but <>, patterns and transliterate)
9759 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
9760 calls scan_str(). s/// makes yylex() call scan_subst() which calls
9761 scan_str(). tr/// and y/// make yylex() call scan_trans() which
9764 It skips whitespace before the string starts, and treats the first
9765 character as the delimiter. If the delimiter is one of ([{< then
9766 the corresponding "close" character )]}> is used as the closing
9767 delimiter. It allows quoting of delimiters, and if the string has
9768 balanced delimiters ([{<>}]) it allows nesting.
9770 On success, the SV with the resulting string is put into lex_stuff or,
9771 if that is already non-NULL, into lex_repl. The second case occurs only
9772 when parsing the RHS of the special constructs s/// and tr/// (y///).
9773 For convenience, the terminating delimiter character is stuffed into
9778 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
9780 SV *sv; /* scalar value: string */
9781 char *tmps; /* temp string, used for delimiter matching */
9782 register char *s = start; /* current position in the buffer */
9783 register char term; /* terminating character */
9784 register char *to; /* current position in the sv's data */
9785 I32 brackets = 1; /* bracket nesting level */
9786 bool has_utf8 = FALSE; /* is there any utf8 content? */
9787 I32 termcode; /* terminating char. code */
9788 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
9789 STRLEN termlen; /* length of terminating string */
9790 char *last = NULL; /* last position for nesting bracket */
9792 /* skip space before the delimiter */
9796 /* mark where we are, in case we need to report errors */
9799 /* after skipping whitespace, the next character is the terminator */
9802 termcode = termstr[0] = term;
9806 termcode = utf8_to_uvchr((U8*)s, &termlen);
9807 Copy(s, termstr, termlen, U8);
9808 if (!UTF8_IS_INVARIANT(term))
9812 /* mark where we are */
9813 PL_multi_start = CopLINE(PL_curcop);
9814 PL_multi_open = term;
9816 /* find corresponding closing delimiter */
9817 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
9818 termcode = termstr[0] = term = tmps[5];
9820 PL_multi_close = term;
9822 /* create a new SV to hold the contents. 87 is leak category, I'm
9823 assuming. 79 is the SV's initial length. What a random number. */
9825 sv_upgrade(sv, SVt_PVIV);
9826 SvIV_set(sv, termcode);
9827 (void)SvPOK_only(sv); /* validate pointer */
9829 /* move past delimiter and try to read a complete string */
9831 sv_catpvn(sv, s, termlen);
9834 if (PL_encoding && !UTF) {
9838 int offset = s - SvPVX_const(PL_linestr);
9839 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
9840 &offset, (char*)termstr, termlen);
9841 const char *ns = SvPVX_const(PL_linestr) + offset;
9842 char *svlast = SvEND(sv) - 1;
9844 for (; s < ns; s++) {
9845 if (*s == '\n' && !PL_rsfp)
9846 CopLINE_inc(PL_curcop);
9849 goto read_more_line;
9851 /* handle quoted delimiters */
9852 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
9854 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
9856 if ((svlast-1 - t) % 2) {
9860 SvCUR_set(sv, SvCUR(sv) - 1);
9865 if (PL_multi_open == PL_multi_close) {
9873 for (t = w = last; t < svlast; w++, t++) {
9874 /* At here, all closes are "was quoted" one,
9875 so we don't check PL_multi_close. */
9877 if (!keep_quoted && *(t+1) == PL_multi_open)
9882 else if (*t == PL_multi_open)
9890 SvCUR_set(sv, w - SvPVX_const(sv));
9893 if (--brackets <= 0)
9899 SvCUR_set(sv, SvCUR(sv) - 1);
9905 /* extend sv if need be */
9906 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
9907 /* set 'to' to the next character in the sv's string */
9908 to = SvPVX(sv)+SvCUR(sv);
9910 /* if open delimiter is the close delimiter read unbridle */
9911 if (PL_multi_open == PL_multi_close) {
9912 for (; s < PL_bufend; s++,to++) {
9913 /* embedded newlines increment the current line number */
9914 if (*s == '\n' && !PL_rsfp)
9915 CopLINE_inc(PL_curcop);
9916 /* handle quoted delimiters */
9917 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
9918 if (!keep_quoted && s[1] == term)
9920 /* any other quotes are simply copied straight through */
9924 /* terminate when run out of buffer (the for() condition), or
9925 have found the terminator */
9926 else if (*s == term) {
9929 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
9932 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
9938 /* if the terminator isn't the same as the start character (e.g.,
9939 matched brackets), we have to allow more in the quoting, and
9940 be prepared for nested brackets.
9943 /* read until we run out of string, or we find the terminator */
9944 for (; s < PL_bufend; s++,to++) {
9945 /* embedded newlines increment the line count */
9946 if (*s == '\n' && !PL_rsfp)
9947 CopLINE_inc(PL_curcop);
9948 /* backslashes can escape the open or closing characters */
9949 if (*s == '\\' && s+1 < PL_bufend) {
9951 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
9956 /* allow nested opens and closes */
9957 else if (*s == PL_multi_close && --brackets <= 0)
9959 else if (*s == PL_multi_open)
9961 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
9966 /* terminate the copied string and update the sv's end-of-string */
9968 SvCUR_set(sv, to - SvPVX_const(sv));
9971 * this next chunk reads more into the buffer if we're not done yet
9975 break; /* handle case where we are done yet :-) */
9977 #ifndef PERL_STRICT_CR
9978 if (to - SvPVX_const(sv) >= 2) {
9979 if ((to[-2] == '\r' && to[-1] == '\n') ||
9980 (to[-2] == '\n' && to[-1] == '\r'))
9984 SvCUR_set(sv, to - SvPVX_const(sv));
9986 else if (to[-1] == '\r')
9989 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
9994 /* if we're out of file, or a read fails, bail and reset the current
9995 line marker so we can report where the unterminated string began
9998 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
10000 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10003 /* we read a line, so increment our line counter */
10004 CopLINE_inc(PL_curcop);
10006 /* update debugger info */
10007 if (PERLDB_LINE && PL_curstash != PL_debstash) {
10008 SV *sv = NEWSV(88,0);
10010 sv_upgrade(sv, SVt_PVMG);
10011 sv_setsv(sv,PL_linestr);
10012 (void)SvIOK_on(sv);
10014 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
10017 /* having changed the buffer, we must update PL_bufend */
10018 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10019 PL_last_lop = PL_last_uni = Nullch;
10022 /* at this point, we have successfully read the delimited string */
10024 if (!PL_encoding || UTF) {
10026 sv_catpvn(sv, s, termlen);
10029 if (has_utf8 || PL_encoding)
10032 PL_multi_end = CopLINE(PL_curcop);
10034 /* if we allocated too much space, give some back */
10035 if (SvCUR(sv) + 5 < SvLEN(sv)) {
10036 SvLEN_set(sv, SvCUR(sv) + 1);
10037 SvPV_renew(sv, SvLEN(sv));
10040 /* decide whether this is the first or second quoted string we've read
10053 takes: pointer to position in buffer
10054 returns: pointer to new position in buffer
10055 side-effects: builds ops for the constant in yylval.op
10057 Read a number in any of the formats that Perl accepts:
10059 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
10060 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
10063 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
10065 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
10068 If it reads a number without a decimal point or an exponent, it will
10069 try converting the number to an integer and see if it can do so
10070 without loss of precision.
10074 Perl_scan_num(pTHX_ char *start, YYSTYPE* lvalp)
10076 register const char *s = start; /* current position in buffer */
10077 register char *d; /* destination in temp buffer */
10078 register char *e; /* end of temp buffer */
10079 NV nv; /* number read, as a double */
10080 SV *sv = Nullsv; /* place to put the converted number */
10081 bool floatit; /* boolean: int or float? */
10082 const char *lastub = 0; /* position of last underbar */
10083 static char const number_too_long[] = "Number too long";
10085 /* We use the first character to decide what type of number this is */
10089 Perl_croak(aTHX_ "panic: scan_num");
10091 /* if it starts with a 0, it could be an octal number, a decimal in
10092 0.13 disguise, or a hexadecimal number, or a binary number. */
10096 u holds the "number so far"
10097 shift the power of 2 of the base
10098 (hex == 4, octal == 3, binary == 1)
10099 overflowed was the number more than we can hold?
10101 Shift is used when we add a digit. It also serves as an "are
10102 we in octal/hex/binary?" indicator to disallow hex characters
10103 when in octal mode.
10108 bool overflowed = FALSE;
10109 bool just_zero = TRUE; /* just plain 0 or binary number? */
10110 static NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
10111 static char const* bases[5] = { "", "binary", "", "octal",
10113 static char const* Bases[5] = { "", "Binary", "", "Octal",
10115 static char const *maxima[5] = { "",
10116 "0b11111111111111111111111111111111",
10120 const char *base, *Base, *max;
10122 /* check for hex */
10127 } else if (s[1] == 'b') {
10132 /* check for a decimal in disguise */
10133 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
10135 /* so it must be octal */
10142 if (ckWARN(WARN_SYNTAX))
10143 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10144 "Misplaced _ in number");
10148 base = bases[shift];
10149 Base = Bases[shift];
10150 max = maxima[shift];
10152 /* read the rest of the number */
10154 /* x is used in the overflow test,
10155 b is the digit we're adding on. */
10160 /* if we don't mention it, we're done */
10164 /* _ are ignored -- but warned about if consecutive */
10166 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10167 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10168 "Misplaced _ in number");
10172 /* 8 and 9 are not octal */
10173 case '8': case '9':
10175 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
10179 case '2': case '3': case '4':
10180 case '5': case '6': case '7':
10182 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
10185 case '0': case '1':
10186 b = *s++ & 15; /* ASCII digit -> value of digit */
10190 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
10191 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
10192 /* make sure they said 0x */
10195 b = (*s++ & 7) + 9;
10197 /* Prepare to put the digit we have onto the end
10198 of the number so far. We check for overflows.
10204 x = u << shift; /* make room for the digit */
10206 if ((x >> shift) != u
10207 && !(PL_hints & HINT_NEW_BINARY)) {
10210 if (ckWARN_d(WARN_OVERFLOW))
10211 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
10212 "Integer overflow in %s number",
10215 u = x | b; /* add the digit to the end */
10218 n *= nvshift[shift];
10219 /* If an NV has not enough bits in its
10220 * mantissa to represent an UV this summing of
10221 * small low-order numbers is a waste of time
10222 * (because the NV cannot preserve the
10223 * low-order bits anyway): we could just
10224 * remember when did we overflow and in the
10225 * end just multiply n by the right
10233 /* if we get here, we had success: make a scalar value from
10238 /* final misplaced underbar check */
10239 if (s[-1] == '_') {
10240 if (ckWARN(WARN_SYNTAX))
10241 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10246 if (ckWARN(WARN_PORTABLE) && n > 4294967295.0)
10247 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10248 "%s number > %s non-portable",
10254 if (ckWARN(WARN_PORTABLE) && u > 0xffffffff)
10255 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10256 "%s number > %s non-portable",
10261 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
10262 sv = new_constant(start, s - start, "integer",
10264 else if (PL_hints & HINT_NEW_BINARY)
10265 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
10270 handle decimal numbers.
10271 we're also sent here when we read a 0 as the first digit
10273 case '1': case '2': case '3': case '4': case '5':
10274 case '6': case '7': case '8': case '9': case '.':
10277 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
10280 /* read next group of digits and _ and copy into d */
10281 while (isDIGIT(*s) || *s == '_') {
10282 /* skip underscores, checking for misplaced ones
10286 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10287 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10288 "Misplaced _ in number");
10292 /* check for end of fixed-length buffer */
10294 Perl_croak(aTHX_ number_too_long);
10295 /* if we're ok, copy the character */
10300 /* final misplaced underbar check */
10301 if (lastub && s == lastub + 1) {
10302 if (ckWARN(WARN_SYNTAX))
10303 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10306 /* read a decimal portion if there is one. avoid
10307 3..5 being interpreted as the number 3. followed
10310 if (*s == '.' && s[1] != '.') {
10315 if (ckWARN(WARN_SYNTAX))
10316 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10317 "Misplaced _ in number");
10321 /* copy, ignoring underbars, until we run out of digits.
10323 for (; isDIGIT(*s) || *s == '_'; s++) {
10324 /* fixed length buffer check */
10326 Perl_croak(aTHX_ number_too_long);
10328 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10329 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10330 "Misplaced _ in number");
10336 /* fractional part ending in underbar? */
10337 if (s[-1] == '_') {
10338 if (ckWARN(WARN_SYNTAX))
10339 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10340 "Misplaced _ in number");
10342 if (*s == '.' && isDIGIT(s[1])) {
10343 /* oops, it's really a v-string, but without the "v" */
10349 /* read exponent part, if present */
10350 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
10354 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
10355 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
10357 /* stray preinitial _ */
10359 if (ckWARN(WARN_SYNTAX))
10360 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10361 "Misplaced _ in number");
10365 /* allow positive or negative exponent */
10366 if (*s == '+' || *s == '-')
10369 /* stray initial _ */
10371 if (ckWARN(WARN_SYNTAX))
10372 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10373 "Misplaced _ in number");
10377 /* read digits of exponent */
10378 while (isDIGIT(*s) || *s == '_') {
10381 Perl_croak(aTHX_ number_too_long);
10385 if (ckWARN(WARN_SYNTAX) &&
10386 ((lastub && s == lastub + 1) ||
10387 (!isDIGIT(s[1]) && s[1] != '_')))
10388 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10389 "Misplaced _ in number");
10396 /* make an sv from the string */
10400 We try to do an integer conversion first if no characters
10401 indicating "float" have been found.
10406 int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
10408 if (flags == IS_NUMBER_IN_UV) {
10410 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
10413 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
10414 if (uv <= (UV) IV_MIN)
10415 sv_setiv(sv, -(IV)uv);
10422 /* terminate the string */
10424 nv = Atof(PL_tokenbuf);
10428 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
10429 (PL_hints & HINT_NEW_INTEGER) )
10430 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
10431 (floatit ? "float" : "integer"),
10435 /* if it starts with a v, it could be a v-string */
10438 sv = NEWSV(92,5); /* preallocate storage space */
10439 s = scan_vstring(s,sv);
10440 DEBUG_T( { PerlIO_printf(Perl_debug_log,
10441 "### Saw v-string before '%s'\n", s);
10446 /* make the op for the constant and return */
10449 lvalp->opval = newSVOP(OP_CONST, 0, sv);
10451 lvalp->opval = Nullop;
10457 S_scan_formline(pTHX_ register char *s)
10459 register char *eol;
10461 SV *stuff = newSVpvn("",0);
10462 bool needargs = FALSE;
10463 bool eofmt = FALSE;
10465 while (!needargs) {
10467 #ifdef PERL_STRICT_CR
10468 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
10470 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
10472 if (*t == '\n' || t == PL_bufend) {
10477 if (PL_in_eval && !PL_rsfp) {
10478 eol = (char *) memchr(s,'\n',PL_bufend-s);
10483 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10485 for (t = s; t < eol; t++) {
10486 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
10488 goto enough; /* ~~ must be first line in formline */
10490 if (*t == '@' || *t == '^')
10494 sv_catpvn(stuff, s, eol-s);
10495 #ifndef PERL_STRICT_CR
10496 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
10497 char *end = SvPVX(stuff) + SvCUR(stuff);
10500 SvCUR_set(stuff, SvCUR(stuff) - 1);
10509 s = filter_gets(PL_linestr, PL_rsfp, 0);
10510 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
10511 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
10512 PL_last_lop = PL_last_uni = Nullch;
10521 if (SvCUR(stuff)) {
10524 PL_lex_state = LEX_NORMAL;
10525 PL_nextval[PL_nexttoke].ival = 0;
10529 PL_lex_state = LEX_FORMLINE;
10531 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
10533 else if (PL_encoding)
10534 sv_recode_to_utf8(stuff, PL_encoding);
10536 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
10538 PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
10542 SvREFCNT_dec(stuff);
10544 PL_lex_formbrack = 0;
10555 PL_cshlen = strlen(PL_cshname);
10560 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
10562 const I32 oldsavestack_ix = PL_savestack_ix;
10563 CV* outsidecv = PL_compcv;
10566 assert(SvTYPE(PL_compcv) == SVt_PVCV);
10568 SAVEI32(PL_subline);
10569 save_item(PL_subname);
10570 SAVESPTR(PL_compcv);
10572 PL_compcv = (CV*)NEWSV(1104,0);
10573 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
10574 CvFLAGS(PL_compcv) |= flags;
10576 PL_subline = CopLINE(PL_curcop);
10577 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
10578 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
10579 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
10580 #ifdef USE_5005THREADS
10581 CvOWNER(PL_compcv) = 0;
10582 New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
10583 MUTEX_INIT(CvMUTEXP(PL_compcv));
10584 #endif /* USE_5005THREADS */
10586 return oldsavestack_ix;
10590 #pragma segment Perl_yylex
10593 Perl_yywarn(pTHX_ char *s)
10595 PL_in_eval |= EVAL_WARNONLY;
10597 PL_in_eval &= ~EVAL_WARNONLY;
10602 Perl_yyerror(pTHX_ char *s)
10604 const char *where = NULL;
10605 const char *context = NULL;
10609 if (!yychar || (yychar == ';' && !PL_rsfp))
10611 else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 &&
10612 PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) {
10615 The code below is removed for NetWare because it abends/crashes on NetWare
10616 when the script has error such as not having the closing quotes like:
10617 if ($var eq "value)
10618 Checking of white spaces is anyway done in NetWare code.
10621 while (isSPACE(*PL_oldoldbufptr))
10624 context = PL_oldoldbufptr;
10625 contlen = PL_bufptr - PL_oldoldbufptr;
10627 else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 &&
10628 PL_oldbufptr != PL_bufptr) {
10631 The code below is removed for NetWare because it abends/crashes on NetWare
10632 when the script has error such as not having the closing quotes like:
10633 if ($var eq "value)
10634 Checking of white spaces is anyway done in NetWare code.
10637 while (isSPACE(*PL_oldbufptr))
10640 context = PL_oldbufptr;
10641 contlen = PL_bufptr - PL_oldbufptr;
10643 else if (yychar > 255)
10644 where = "next token ???";
10645 #ifdef USE_PURE_BISON
10646 /* GNU Bison sets the value -2 */
10647 else if (yychar == -2) {
10649 else if ((yychar & 127) == 127) {
10651 if (PL_lex_state == LEX_NORMAL ||
10652 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
10653 where = "at end of line";
10654 else if (PL_lex_inpat)
10655 where = "within pattern";
10657 where = "within string";
10660 SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
10662 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
10663 else if (isPRINT_LC(yychar))
10664 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
10666 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
10667 where = SvPVX_const(where_sv);
10669 msg = sv_2mortal(newSVpv(s, 0));
10670 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
10671 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
10673 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
10675 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
10676 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
10677 Perl_sv_catpvf(aTHX_ msg,
10678 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
10679 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
10682 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
10683 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg);
10686 if (PL_error_count >= 10) {
10687 if (PL_in_eval && SvCUR(ERRSV))
10688 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
10689 ERRSV, OutCopFILE(PL_curcop));
10691 Perl_croak(aTHX_ "%s has too many errors.\n",
10692 OutCopFILE(PL_curcop));
10695 PL_in_my_stash = Nullhv;
10699 #pragma segment Main
10703 S_swallow_bom(pTHX_ U8 *s)
10705 const STRLEN slen = SvCUR(PL_linestr);
10708 if (s[1] == 0xFE) {
10709 /* UTF-16 little-endian? (or UTF32-LE?) */
10710 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
10711 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
10712 #ifndef PERL_NO_UTF16_FILTER
10713 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
10716 if (PL_bufend > (char*)s) {
10720 filter_add(utf16rev_textfilter, NULL);
10721 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10722 utf16_to_utf8_reversed(s, news,
10723 PL_bufend - (char*)s - 1,
10725 sv_setpvn(PL_linestr, (const char*)news, newlen);
10727 SvUTF8_on(PL_linestr);
10728 s = (U8*)SvPVX(PL_linestr);
10729 PL_bufend = SvPVX(PL_linestr) + newlen;
10732 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
10737 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
10738 #ifndef PERL_NO_UTF16_FILTER
10739 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
10742 if (PL_bufend > (char *)s) {
10746 filter_add(utf16_textfilter, NULL);
10747 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10748 utf16_to_utf8(s, news,
10749 PL_bufend - (char*)s,
10751 sv_setpvn(PL_linestr, (const char*)news, newlen);
10753 SvUTF8_on(PL_linestr);
10754 s = (U8*)SvPVX(PL_linestr);
10755 PL_bufend = SvPVX(PL_linestr) + newlen;
10758 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
10763 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
10764 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
10765 s += 3; /* UTF-8 */
10771 if (s[2] == 0xFE && s[3] == 0xFF) {
10772 /* UTF-32 big-endian */
10773 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
10776 else if (s[2] == 0 && s[3] != 0) {
10779 * are a good indicator of UTF-16BE. */
10780 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
10785 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
10788 * are a good indicator of UTF-16LE. */
10789 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
10798 * Restore a source filter.
10802 restore_rsfp(pTHX_ void *f)
10804 PerlIO *fp = (PerlIO*)f;
10806 if (PL_rsfp == PerlIO_stdin())
10807 PerlIO_clearerr(PL_rsfp);
10808 else if (PL_rsfp && (PL_rsfp != fp))
10809 PerlIO_close(PL_rsfp);
10813 #ifndef PERL_NO_UTF16_FILTER
10815 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10817 const STRLEN old = SvCUR(sv);
10818 const I32 count = FILTER_READ(idx+1, sv, maxlen);
10819 DEBUG_P(PerlIO_printf(Perl_debug_log,
10820 "utf16_textfilter(%p): %d %d (%d)\n",
10821 utf16_textfilter, idx, maxlen, (int) count));
10825 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10826 Copy(SvPVX_const(sv), tmps, old, char);
10827 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
10828 SvCUR(sv) - old, &newlen);
10829 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10831 DEBUG_P({sv_dump(sv);});
10836 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10838 const STRLEN old = SvCUR(sv);
10839 const I32 count = FILTER_READ(idx+1, sv, maxlen);
10840 DEBUG_P(PerlIO_printf(Perl_debug_log,
10841 "utf16rev_textfilter(%p): %d %d (%d)\n",
10842 utf16rev_textfilter, idx, maxlen, (int) count));
10846 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10847 Copy(SvPVX_const(sv), tmps, old, char);
10848 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
10849 SvCUR(sv) - old, &newlen);
10850 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10852 DEBUG_P({ sv_dump(sv); });
10858 Returns a pointer to the next character after the parsed
10859 vstring, as well as updating the passed in sv.
10861 Function must be called like
10864 s = scan_vstring(s,sv);
10866 The sv should already be large enough to store the vstring
10867 passed in, for performance reasons.
10872 Perl_scan_vstring(pTHX_ char *s, SV *sv)
10874 const char *pos = s;
10875 const char *start = s;
10876 if (*pos == 'v') pos++; /* get past 'v' */
10877 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
10879 if ( *pos != '.') {
10880 /* this may not be a v-string if followed by => */
10881 const char *next = pos;
10882 while (next < PL_bufend && isSPACE(*next))
10884 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
10885 /* return string not v-string */
10886 sv_setpvn(sv,(char *)s,pos-s);
10887 return (char *)pos;
10891 if (!isALPHA(*pos)) {
10893 U8 tmpbuf[UTF8_MAXBYTES+1];
10896 if (*s == 'v') s++; /* get past 'v' */
10898 sv_setpvn(sv, "", 0);
10903 /* this is atoi() that tolerates underscores */
10904 const char *end = pos;
10906 while (--end >= s) {
10911 rev += (*end - '0') * mult;
10913 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
10914 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
10915 "Integer overflow in decimal number");
10919 if (rev > 0x7FFFFFFF)
10920 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
10922 /* Append native character for the rev point */
10923 tmpend = uvchr_to_utf8(tmpbuf, rev);
10924 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
10925 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
10927 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
10933 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
10937 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
10945 * c-indentation-style: bsd
10946 * c-basic-offset: 4
10947 * indent-tabs-mode: t
10950 * ex: set ts=8 sts=4 sw=4 noet: