3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "It all comes from here, the stench and the peril." --Frodo
16 * This file is the lexer for Perl. It's closely linked to the
19 * The main routine is yylex(), which returns the next token.
23 #define PERL_IN_TOKE_C
26 #define yychar (*PL_yycharp)
27 #define yylval (*PL_yylvalp)
29 static const char ident_too_long[] =
30 "Identifier too long";
31 static const char c_without_g[] =
32 "Use of /c modifier is meaningless without /g";
33 static const char c_in_subst[] =
34 "Use of /c modifier is meaningless in s///";
36 static void restore_rsfp(pTHX_ void *f);
37 #ifndef PERL_NO_UTF16_FILTER
38 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
39 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
42 #define XFAKEBRACK 128
45 #ifdef USE_UTF8_SCRIPTS
46 # define UTF (!IN_BYTES)
48 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
51 /* In variables named $^X, these are the legal values for X.
52 * 1999-02-27 mjd-perl-patch@plover.com */
53 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
55 /* On MacOS, respect nonbreaking spaces */
56 #ifdef MACOS_TRADITIONAL
57 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
59 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
62 /* LEX_* are values for PL_lex_state, the state of the lexer.
63 * They are arranged oddly so that the guard on the switch statement
64 * can get by with a single comparison (if the compiler is smart enough).
67 /* #define LEX_NOTPARSING 11 is done in perl.h. */
70 #define LEX_INTERPNORMAL 9
71 #define LEX_INTERPCASEMOD 8
72 #define LEX_INTERPPUSH 7
73 #define LEX_INTERPSTART 6
74 #define LEX_INTERPEND 5
75 #define LEX_INTERPENDMAYBE 4
76 #define LEX_INTERPCONCAT 3
77 #define LEX_INTERPCONST 2
78 #define LEX_FORMLINE 1
79 #define LEX_KNOWNEXT 0
82 static const char* const lex_state_names[] = {
101 #include "keywords.h"
103 /* CLINE is a macro that ensures PL_copline has a sane value */
108 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
110 /* According to some strict interpretations of ANSI C89 one cannot
111 * cast void pointers to code pointers or vice versa (as filter_add(),
112 * filter_del(), and filter_read() will want to do). We should still
113 * be able to use a union for sneaky "casting". */
120 * Convenience functions to return different tokens and prime the
121 * lexer for the next token. They all take an argument.
123 * TOKEN : generic token (used for '(', DOLSHARP, etc)
124 * OPERATOR : generic operator
125 * AOPERATOR : assignment operator
126 * PREBLOCK : beginning the block after an if, while, foreach, ...
127 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
128 * PREREF : *EXPR where EXPR is not a simple identifier
129 * TERM : expression term
130 * LOOPX : loop exiting command (goto, last, dump, etc)
131 * FTST : file test operator
132 * FUN0 : zero-argument function
133 * FUN1 : not used, except for not, which isn't a UNIOP
134 * BOop : bitwise or or xor
136 * SHop : shift operator
137 * PWop : power operator
138 * PMop : pattern-matching operator
139 * Aop : addition-level operator
140 * Mop : multiplication-level operator
141 * Eop : equality-testing operator
142 * Rop : relational operator <= != gt
144 * Also see LOP and lop() below.
147 #ifdef DEBUGGING /* Serve -DT. */
148 # define REPORT(retval) tokereport(s,(int)retval)
150 # define REPORT(retval) (retval)
153 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
154 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
155 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
156 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
157 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
158 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
159 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
160 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
161 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
162 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
163 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
164 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
165 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
166 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
167 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
168 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
169 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
170 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
171 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
172 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
174 /* This bit of chicanery makes a unary function followed by
175 * a parenthesis into a function with one argument, highest precedence.
176 * The UNIDOR macro is for unary functions that can be followed by the //
177 * operator (such as C<shift // 0>).
179 #define UNI2(f,x) return ( \
183 PL_last_uni = PL_oldbufptr, \
184 PL_last_lop_op = f, \
186 (*s == '(' || (s = skipspace(s), *s == '(') \
187 ? (int)FUNC1 : (int)UNIOP)))
188 #define UNI(f) UNI2(f,XTERM)
189 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
191 #define UNIBRACK(f) return ( \
194 PL_last_uni = PL_oldbufptr, \
196 (*s == '(' || (s = skipspace(s), *s == '(') \
197 ? (int)FUNC1 : (int)UNIOP)))
199 /* grandfather return to old style */
200 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
204 /* how to interpret the yylval associated with the token */
208 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
214 static struct debug_tokens { const int token, type; const char *name; }
215 const debug_tokens[] =
217 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
218 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
219 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
220 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
221 { ARROW, TOKENTYPE_NONE, "ARROW" },
222 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
223 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
224 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
225 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
226 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
227 { DO, TOKENTYPE_NONE, "DO" },
228 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
229 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
230 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
231 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
232 { ELSE, TOKENTYPE_NONE, "ELSE" },
233 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
234 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
235 { FOR, TOKENTYPE_IVAL, "FOR" },
236 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
237 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
238 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
239 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
240 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
241 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
242 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
243 { IF, TOKENTYPE_IVAL, "IF" },
244 { LABEL, TOKENTYPE_PVAL, "LABEL" },
245 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
246 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
247 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
248 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
249 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
250 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
251 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
252 { MY, TOKENTYPE_IVAL, "MY" },
253 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
254 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
255 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
256 { OROP, TOKENTYPE_IVAL, "OROP" },
257 { OROR, TOKENTYPE_NONE, "OROR" },
258 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
259 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
260 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
261 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
262 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
263 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
264 { PREINC, TOKENTYPE_NONE, "PREINC" },
265 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
266 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
267 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
268 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
269 { SUB, TOKENTYPE_NONE, "SUB" },
270 { THING, TOKENTYPE_OPVAL, "THING" },
271 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
272 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
273 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
274 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
275 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
276 { USE, TOKENTYPE_IVAL, "USE" },
277 { WHILE, TOKENTYPE_IVAL, "WHILE" },
278 { WORD, TOKENTYPE_OPVAL, "WORD" },
279 { 0, TOKENTYPE_NONE, 0 }
282 /* dump the returned token in rv, plus any optional arg in yylval */
285 S_tokereport(pTHX_ const char* s, I32 rv)
288 const char *name = Nullch;
289 enum token_type type = TOKENTYPE_NONE;
290 const struct debug_tokens *p;
291 SV* report = newSVpvn("<== ", 4);
293 for (p = debug_tokens; p->token; p++) {
294 if (p->token == (int)rv) {
301 Perl_sv_catpv(aTHX_ report, name);
302 else if ((char)rv > ' ' && (char)rv < '~')
303 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
305 Perl_sv_catpv(aTHX_ report, "EOF");
307 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
310 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
313 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
315 case TOKENTYPE_OPNUM:
316 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
317 PL_op_name[yylval.ival]);
320 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
322 case TOKENTYPE_OPVAL:
324 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
325 PL_op_name[yylval.opval->op_type]);
327 Perl_sv_catpv(aTHX_ report, "(opval=null)");
330 Perl_sv_catpvf(aTHX_ report, " at line %"IVdf" [", (IV)CopLINE(PL_curcop));
331 if (s - PL_bufptr > 0)
332 sv_catpvn(report, PL_bufptr, s - PL_bufptr);
334 if (PL_oldbufptr && *PL_oldbufptr)
335 sv_catpv(report, PL_tokenbuf);
337 PerlIO_printf(Perl_debug_log, "### %s]\n", SvPV_nolen(report));
347 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
348 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
352 S_ao(pTHX_ int toketype)
354 if (*PL_bufptr == '=') {
356 if (toketype == ANDAND)
357 yylval.ival = OP_ANDASSIGN;
358 else if (toketype == OROR)
359 yylval.ival = OP_ORASSIGN;
360 else if (toketype == DORDOR)
361 yylval.ival = OP_DORASSIGN;
369 * When Perl expects an operator and finds something else, no_op
370 * prints the warning. It always prints "<something> found where
371 * operator expected. It prints "Missing semicolon on previous line?"
372 * if the surprise occurs at the start of the line. "do you need to
373 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
374 * where the compiler doesn't know if foo is a method call or a function.
375 * It prints "Missing operator before end of line" if there's nothing
376 * after the missing operator, or "... before <...>" if there is something
377 * after the missing operator.
381 S_no_op(pTHX_ const char *what, char *s)
383 char *oldbp = PL_bufptr;
384 bool is_first = (PL_oldbufptr == PL_linestart);
390 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
391 if (ckWARN_d(WARN_SYNTAX)) {
393 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
394 "\t(Missing semicolon on previous line?)\n");
395 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
397 for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
398 if (t < PL_bufptr && isSPACE(*t))
399 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
400 "\t(Do you need to predeclare %.*s?)\n",
401 t - PL_oldoldbufptr, PL_oldoldbufptr);
405 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
406 "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
414 * Complain about missing quote/regexp/heredoc terminator.
415 * If it's called with (char *)NULL then it cauterizes the line buffer.
416 * If we're in a delimited string and the delimiter is a control
417 * character, it's reformatted into a two-char sequence like ^C.
422 S_missingterm(pTHX_ char *s)
427 char *nl = strrchr(s,'\n');
433 iscntrl(PL_multi_close)
435 PL_multi_close < 32 || PL_multi_close == 127
439 tmpbuf[1] = toCTRL(PL_multi_close);
444 *tmpbuf = (char)PL_multi_close;
448 q = strchr(s,'"') ? '\'' : '"';
449 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
457 Perl_deprecate(pTHX_ const char *s)
459 if (ckWARN(WARN_DEPRECATED))
460 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
464 Perl_deprecate_old(pTHX_ const char *s)
466 /* This function should NOT be called for any new deprecated warnings */
467 /* Use Perl_deprecate instead */
469 /* It is here to maintain backward compatibility with the pre-5.8 */
470 /* warnings category hierarchy. The "deprecated" category used to */
471 /* live under the "syntax" category. It is now a top-level category */
472 /* in its own right. */
474 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
475 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
476 "Use of %s is deprecated", s);
481 * Deprecate a comma-less variable list.
487 deprecate_old("comma-less variable list");
491 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
492 * utf16-to-utf8-reversed.
495 #ifdef PERL_CR_FILTER
499 register const char *s = SvPVX(sv);
500 register const char *e = s + SvCUR(sv);
501 /* outer loop optimized to do nothing if there are no CR-LFs */
503 if (*s++ == '\r' && *s == '\n') {
504 /* hit a CR-LF, need to copy the rest */
505 register char *d = s - 1;
508 if (*s == '\r' && s[1] == '\n')
519 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
521 const I32 count = FILTER_READ(idx+1, sv, maxlen);
522 if (count > 0 && !maxlen)
530 * Initialize variables. Uses the Perl save_stack to save its state (for
531 * recursive calls to the parser).
535 Perl_lex_start(pTHX_ SV *line)
540 SAVEI32(PL_lex_dojoin);
541 SAVEI32(PL_lex_brackets);
542 SAVEI32(PL_lex_casemods);
543 SAVEI32(PL_lex_starts);
544 SAVEI32(PL_lex_state);
545 SAVEVPTR(PL_lex_inpat);
546 SAVEI32(PL_lex_inwhat);
547 if (PL_lex_state == LEX_KNOWNEXT) {
548 I32 toke = PL_nexttoke;
549 while (--toke >= 0) {
550 SAVEI32(PL_nexttype[toke]);
551 SAVEVPTR(PL_nextval[toke]);
553 SAVEI32(PL_nexttoke);
555 SAVECOPLINE(PL_curcop);
558 SAVEPPTR(PL_oldbufptr);
559 SAVEPPTR(PL_oldoldbufptr);
560 SAVEPPTR(PL_last_lop);
561 SAVEPPTR(PL_last_uni);
562 SAVEPPTR(PL_linestart);
563 SAVESPTR(PL_linestr);
564 SAVEGENERICPV(PL_lex_brackstack);
565 SAVEGENERICPV(PL_lex_casestack);
566 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
567 SAVESPTR(PL_lex_stuff);
568 SAVEI32(PL_lex_defer);
569 SAVEI32(PL_sublex_info.sub_inwhat);
570 SAVESPTR(PL_lex_repl);
572 SAVEINT(PL_lex_expect);
574 PL_lex_state = LEX_NORMAL;
578 New(899, PL_lex_brackstack, 120, char);
579 New(899, PL_lex_casestack, 12, char);
581 *PL_lex_casestack = '\0';
584 PL_lex_stuff = Nullsv;
585 PL_lex_repl = Nullsv;
589 PL_sublex_info.sub_inwhat = 0;
591 if (SvREADONLY(PL_linestr))
592 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
593 s = SvPV(PL_linestr, len);
594 if (!len || s[len-1] != ';') {
595 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
596 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
597 sv_catpvn(PL_linestr, "\n;", 2);
599 SvTEMP_off(PL_linestr);
600 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
601 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
602 PL_last_lop = PL_last_uni = Nullch;
608 * Finalizer for lexing operations. Must be called when the parser is
609 * done with the lexer.
615 PL_doextract = FALSE;
620 * This subroutine has nothing to do with tilting, whether at windmills
621 * or pinball tables. Its name is short for "increment line". It
622 * increments the current line number in CopLINE(PL_curcop) and checks
623 * to see whether the line starts with a comment of the form
624 * # line 500 "foo.pm"
625 * If so, it sets the current line number and file to the values in the comment.
629 S_incline(pTHX_ char *s)
636 CopLINE_inc(PL_curcop);
639 while (SPACE_OR_TAB(*s)) s++;
640 if (strnEQ(s, "line", 4))
644 if (SPACE_OR_TAB(*s))
648 while (SPACE_OR_TAB(*s)) s++;
654 while (SPACE_OR_TAB(*s))
656 if (*s == '"' && (t = strchr(s+1, '"'))) {
661 for (t = s; !isSPACE(*t); t++) ;
664 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
666 if (*e != '\n' && *e != '\0')
667 return; /* false alarm */
672 CopFILE_free(PL_curcop);
673 CopFILE_set(PL_curcop, s);
676 CopLINE_set(PL_curcop, atoi(n)-1);
681 * Called to gobble the appropriate amount and type of whitespace.
682 * Skips comments as well.
686 S_skipspace(pTHX_ register char *s)
688 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
689 while (s < PL_bufend && SPACE_OR_TAB(*s))
695 SSize_t oldprevlen, oldoldprevlen;
696 SSize_t oldloplen = 0, oldunilen = 0;
697 while (s < PL_bufend && isSPACE(*s)) {
698 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
703 if (s < PL_bufend && *s == '#') {
704 while (s < PL_bufend && *s != '\n')
708 if (PL_in_eval && !PL_rsfp) {
715 /* only continue to recharge the buffer if we're at the end
716 * of the buffer, we're not reading from a source filter, and
717 * we're in normal lexing mode
719 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
720 PL_lex_state == LEX_FORMLINE)
723 /* try to recharge the buffer */
724 if ((s = filter_gets(PL_linestr, PL_rsfp,
725 (prevlen = SvCUR(PL_linestr)))) == Nullch)
727 /* end of file. Add on the -p or -n magic */
730 ";}continue{print or die qq(-p destination: $!\\n);}");
731 PL_minus_n = PL_minus_p = 0;
733 else if (PL_minus_n) {
734 sv_setpvn(PL_linestr, ";}", 2);
738 sv_setpvn(PL_linestr,";", 1);
740 /* reset variables for next time we lex */
741 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
743 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
744 PL_last_lop = PL_last_uni = Nullch;
746 /* Close the filehandle. Could be from -P preprocessor,
747 * STDIN, or a regular file. If we were reading code from
748 * STDIN (because the commandline held no -e or filename)
749 * then we don't close it, we reset it so the code can
750 * read from STDIN too.
753 if (PL_preprocess && !PL_in_eval)
754 (void)PerlProc_pclose(PL_rsfp);
755 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
756 PerlIO_clearerr(PL_rsfp);
758 (void)PerlIO_close(PL_rsfp);
763 /* not at end of file, so we only read another line */
764 /* make corresponding updates to old pointers, for yyerror() */
765 oldprevlen = PL_oldbufptr - PL_bufend;
766 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
768 oldunilen = PL_last_uni - PL_bufend;
770 oldloplen = PL_last_lop - PL_bufend;
771 PL_linestart = PL_bufptr = s + prevlen;
772 PL_bufend = s + SvCUR(PL_linestr);
774 PL_oldbufptr = s + oldprevlen;
775 PL_oldoldbufptr = s + oldoldprevlen;
777 PL_last_uni = s + oldunilen;
779 PL_last_lop = s + oldloplen;
782 /* debugger active and we're not compiling the debugger code,
783 * so store the line into the debugger's array of lines
785 if (PERLDB_LINE && PL_curstash != PL_debstash) {
786 SV *sv = NEWSV(85,0);
788 sv_upgrade(sv, SVt_PVMG);
789 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
792 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
799 * Check the unary operators to ensure there's no ambiguity in how they're
800 * used. An ambiguous piece of code would be:
802 * This doesn't mean rand() + 5. Because rand() is a unary operator,
803 * the +5 is its argument.
812 if (PL_oldoldbufptr != PL_last_uni)
814 while (isSPACE(*PL_last_uni))
816 for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
817 if ((t = strchr(s, '(')) && t < PL_bufptr)
819 if (ckWARN_d(WARN_AMBIGUOUS)){
822 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
823 "Warning: Use of \"%s\" without parentheses is ambiguous",
830 * LOP : macro to build a list operator. Its behaviour has been replaced
831 * with a subroutine, S_lop() for which LOP is just another name.
834 #define LOP(f,x) return lop(f,x,s)
838 * Build a list operator (or something that might be one). The rules:
839 * - if we have a next token, then it's a list operator [why?]
840 * - if the next thing is an opening paren, then it's a function
841 * - else it's a list operator
845 S_lop(pTHX_ I32 f, int x, char *s)
851 PL_last_lop = PL_oldbufptr;
852 PL_last_lop_op = (OPCODE)f;
854 return REPORT(LSTOP);
861 return REPORT(LSTOP);
866 * When the lexer realizes it knows the next token (for instance,
867 * it is reordering tokens for the parser) then it can call S_force_next
868 * to know what token to return the next time the lexer is called. Caller
869 * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer
870 * handles the token correctly.
874 S_force_next(pTHX_ I32 type)
876 PL_nexttype[PL_nexttoke] = type;
878 if (PL_lex_state != LEX_KNOWNEXT) {
879 PL_lex_defer = PL_lex_state;
880 PL_lex_expect = PL_expect;
881 PL_lex_state = LEX_KNOWNEXT;
886 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
888 SV *sv = newSVpvn(start,len);
889 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
896 * When the lexer knows the next thing is a word (for instance, it has
897 * just seen -> and it knows that the next char is a word char, then
898 * it calls S_force_word to stick the next word into the PL_next lookahead.
901 * char *start : buffer position (must be within PL_linestr)
902 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
903 * int check_keyword : if true, Perl checks to make sure the word isn't
904 * a keyword (do this if the word is a label, e.g. goto FOO)
905 * int allow_pack : if true, : characters will also be allowed (require,
907 * int allow_initial_tick : used by the "sub" lexer only.
911 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
916 start = skipspace(start);
918 if (isIDFIRST_lazy_if(s,UTF) ||
919 (allow_pack && *s == ':') ||
920 (allow_initial_tick && *s == '\'') )
922 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
923 if (check_keyword && keyword(PL_tokenbuf, len))
925 if (token == METHOD) {
930 PL_expect = XOPERATOR;
933 PL_nextval[PL_nexttoke].opval
934 = (OP*)newSVOP(OP_CONST,0,
935 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
936 PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
944 * Called when the lexer wants $foo *foo &foo etc, but the program
945 * text only contains the "foo" portion. The first argument is a pointer
946 * to the "foo", and the second argument is the type symbol to prefix.
947 * Forces the next token to be a "WORD".
948 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
952 S_force_ident(pTHX_ register const char *s, int kind)
955 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
956 PL_nextval[PL_nexttoke].opval = o;
959 o->op_private = OPpCONST_ENTERED;
960 /* XXX see note in pp_entereval() for why we forgo typo
961 warnings if the symbol must be introduced in an eval.
963 gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
964 kind == '$' ? SVt_PV :
965 kind == '@' ? SVt_PVAV :
966 kind == '%' ? SVt_PVHV :
974 Perl_str_to_version(pTHX_ SV *sv)
979 const char *start = SvPVx(sv,len);
980 const char *end = start + len;
981 bool utf = SvUTF8(sv) ? TRUE : FALSE;
982 while (start < end) {
986 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
991 retval += ((NV)n)/nshift;
1000 * Forces the next token to be a version number.
1001 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1002 * and if "guessing" is TRUE, then no new token is created (and the caller
1003 * must use an alternative parsing method).
1007 S_force_version(pTHX_ char *s, int guessing)
1009 OP *version = Nullop;
1018 while (isDIGIT(*d) || *d == '_' || *d == '.')
1020 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1022 s = scan_num(s, &yylval);
1023 version = yylval.opval;
1024 ver = cSVOPx(version)->op_sv;
1025 if (SvPOK(ver) && !SvNIOK(ver)) {
1026 (void)SvUPGRADE(ver, SVt_PVNV);
1027 SvNV_set(ver, str_to_version(ver));
1028 SvNOK_on(ver); /* hint that it is a version */
1035 /* NOTE: The parser sees the package name and the VERSION swapped */
1036 PL_nextval[PL_nexttoke].opval = version;
1044 * Tokenize a quoted string passed in as an SV. It finds the next
1045 * chunk, up to end of string or a backslash. It may make a new
1046 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1051 S_tokeq(pTHX_ SV *sv)
1054 register char *send;
1062 s = SvPV_force(sv, len);
1063 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1066 while (s < send && *s != '\\')
1071 if ( PL_hints & HINT_NEW_STRING ) {
1072 pv = sv_2mortal(newSVpvn(SvPVX(pv), len));
1078 if (s + 1 < send && (s[1] == '\\'))
1079 s++; /* all that, just for this */
1084 SvCUR_set(sv, d - SvPVX(sv));
1086 if ( PL_hints & HINT_NEW_STRING )
1087 return new_constant(NULL, 0, "q", sv, pv, "q");
1092 * Now come three functions related to double-quote context,
1093 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1094 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1095 * interact with PL_lex_state, and create fake ( ... ) argument lists
1096 * to handle functions and concatenation.
1097 * They assume that whoever calls them will be setting up a fake
1098 * join call, because each subthing puts a ',' after it. This lets
1101 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1103 * (I'm not sure whether the spurious commas at the end of lcfirst's
1104 * arguments and join's arguments are created or not).
1109 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1111 * Pattern matching will set PL_lex_op to the pattern-matching op to
1112 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1114 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1116 * Everything else becomes a FUNC.
1118 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1119 * had an OP_CONST or OP_READLINE). This just sets us up for a
1120 * call to S_sublex_push().
1124 S_sublex_start(pTHX)
1126 const register I32 op_type = yylval.ival;
1128 if (op_type == OP_NULL) {
1129 yylval.opval = PL_lex_op;
1133 if (op_type == OP_CONST || op_type == OP_READLINE) {
1134 SV *sv = tokeq(PL_lex_stuff);
1136 if (SvTYPE(sv) == SVt_PVIV) {
1137 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1139 const char *p = SvPV(sv, len);
1140 SV * const nsv = newSVpvn(p, len);
1146 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1147 PL_lex_stuff = Nullsv;
1148 /* Allow <FH> // "foo" */
1149 if (op_type == OP_READLINE)
1150 PL_expect = XTERMORDORDOR;
1154 PL_sublex_info.super_state = PL_lex_state;
1155 PL_sublex_info.sub_inwhat = op_type;
1156 PL_sublex_info.sub_op = PL_lex_op;
1157 PL_lex_state = LEX_INTERPPUSH;
1161 yylval.opval = PL_lex_op;
1171 * Create a new scope to save the lexing state. The scope will be
1172 * ended in S_sublex_done. Returns a '(', starting the function arguments
1173 * to the uc, lc, etc. found before.
1174 * Sets PL_lex_state to LEX_INTERPCONCAT.
1183 PL_lex_state = PL_sublex_info.super_state;
1184 SAVEI32(PL_lex_dojoin);
1185 SAVEI32(PL_lex_brackets);
1186 SAVEI32(PL_lex_casemods);
1187 SAVEI32(PL_lex_starts);
1188 SAVEI32(PL_lex_state);
1189 SAVEVPTR(PL_lex_inpat);
1190 SAVEI32(PL_lex_inwhat);
1191 SAVECOPLINE(PL_curcop);
1192 SAVEPPTR(PL_bufptr);
1193 SAVEPPTR(PL_bufend);
1194 SAVEPPTR(PL_oldbufptr);
1195 SAVEPPTR(PL_oldoldbufptr);
1196 SAVEPPTR(PL_last_lop);
1197 SAVEPPTR(PL_last_uni);
1198 SAVEPPTR(PL_linestart);
1199 SAVESPTR(PL_linestr);
1200 SAVEGENERICPV(PL_lex_brackstack);
1201 SAVEGENERICPV(PL_lex_casestack);
1203 PL_linestr = PL_lex_stuff;
1204 PL_lex_stuff = Nullsv;
1206 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1207 = SvPVX(PL_linestr);
1208 PL_bufend += SvCUR(PL_linestr);
1209 PL_last_lop = PL_last_uni = Nullch;
1210 SAVEFREESV(PL_linestr);
1212 PL_lex_dojoin = FALSE;
1213 PL_lex_brackets = 0;
1214 New(899, PL_lex_brackstack, 120, char);
1215 New(899, PL_lex_casestack, 12, char);
1216 PL_lex_casemods = 0;
1217 *PL_lex_casestack = '\0';
1219 PL_lex_state = LEX_INTERPCONCAT;
1220 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1222 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1223 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1224 PL_lex_inpat = PL_sublex_info.sub_op;
1226 PL_lex_inpat = Nullop;
1233 * Restores lexer state after a S_sublex_push.
1240 if (!PL_lex_starts++) {
1241 SV *sv = newSVpvn("",0);
1242 if (SvUTF8(PL_linestr))
1244 PL_expect = XOPERATOR;
1245 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1249 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1250 PL_lex_state = LEX_INTERPCASEMOD;
1254 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1255 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1256 PL_linestr = PL_lex_repl;
1258 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1259 PL_bufend += SvCUR(PL_linestr);
1260 PL_last_lop = PL_last_uni = Nullch;
1261 SAVEFREESV(PL_linestr);
1262 PL_lex_dojoin = FALSE;
1263 PL_lex_brackets = 0;
1264 PL_lex_casemods = 0;
1265 *PL_lex_casestack = '\0';
1267 if (SvEVALED(PL_lex_repl)) {
1268 PL_lex_state = LEX_INTERPNORMAL;
1270 /* we don't clear PL_lex_repl here, so that we can check later
1271 whether this is an evalled subst; that means we rely on the
1272 logic to ensure sublex_done() is called again only via the
1273 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1276 PL_lex_state = LEX_INTERPCONCAT;
1277 PL_lex_repl = Nullsv;
1283 PL_bufend = SvPVX(PL_linestr);
1284 PL_bufend += SvCUR(PL_linestr);
1285 PL_expect = XOPERATOR;
1286 PL_sublex_info.sub_inwhat = 0;
1294 Extracts a pattern, double-quoted string, or transliteration. This
1297 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1298 processing a pattern (PL_lex_inpat is true), a transliteration
1299 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1301 Returns a pointer to the character scanned up to. Iff this is
1302 advanced from the start pointer supplied (ie if anything was
1303 successfully parsed), will leave an OP for the substring scanned
1304 in yylval. Caller must intuit reason for not parsing further
1305 by looking at the next characters herself.
1309 double-quoted style: \r and \n
1310 regexp special ones: \D \s
1312 backrefs: \1 (deprecated in substitution replacements)
1313 case and quoting: \U \Q \E
1314 stops on @ and $, but not for $ as tail anchor
1316 In transliterations:
1317 characters are VERY literal, except for - not at the start or end
1318 of the string, which indicates a range. scan_const expands the
1319 range to the full set of intermediate characters.
1321 In double-quoted strings:
1323 double-quoted style: \r and \n
1325 backrefs: \1 (deprecated)
1326 case and quoting: \U \Q \E
1329 scan_const does *not* construct ops to handle interpolated strings.
1330 It stops processing as soon as it finds an embedded $ or @ variable
1331 and leaves it to the caller to work out what's going on.
1333 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo.
1335 $ in pattern could be $foo or could be tail anchor. Assumption:
1336 it's a tail anchor if $ is the last thing in the string, or if it's
1337 followed by one of ")| \n\t"
1339 \1 (backreferences) are turned into $1
1341 The structure of the code is
1342 while (there's a character to process) {
1343 handle transliteration ranges
1344 skip regexp comments
1345 skip # initiated comments in //x patterns
1346 check for embedded @foo
1347 check for embedded scalars
1349 leave intact backslashes from leave (below)
1350 deprecate \1 in strings and sub replacements
1351 handle string-changing backslashes \l \U \Q \E, etc.
1352 switch (what was escaped) {
1353 handle - in a transliteration (becomes a literal -)
1354 handle \132 octal characters
1355 handle 0x15 hex characters
1356 handle \cV (control V)
1357 handle printf backslashes (\f, \r, \n, etc)
1359 } (end if backslash)
1360 } (end while character to read)
1365 S_scan_const(pTHX_ char *start)
1367 register char *send = PL_bufend; /* end of the constant */
1368 SV *sv = NEWSV(93, send - start); /* sv for the constant */
1369 register char *s = start; /* start of the constant */
1370 register char *d = SvPVX(sv); /* destination for copies */
1371 bool dorange = FALSE; /* are we in a translit range? */
1372 bool didrange = FALSE; /* did we just finish a range? */
1373 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1374 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1377 const char *leaveit = /* set of acceptably-backslashed characters */
1379 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#"
1382 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1383 /* If we are doing a trans and we know we want UTF8 set expectation */
1384 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1385 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1389 while (s < send || dorange) {
1390 /* get transliterations out of the way (they're most literal) */
1391 if (PL_lex_inwhat == OP_TRANS) {
1392 /* expand a range A-Z to the full set of characters. AIE! */
1394 I32 i; /* current expanded character */
1395 I32 min; /* first character in range */
1396 I32 max; /* last character in range */
1399 char *c = (char*)utf8_hop((U8*)d, -1);
1403 *c = (char)UTF_TO_NATIVE(0xff);
1404 /* mark the range as done, and continue */
1410 i = d - SvPVX(sv); /* remember current offset */
1411 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1412 d = SvPVX(sv) + i; /* refresh d after realloc */
1413 d -= 2; /* eat the first char and the - */
1415 min = (U8)*d; /* first char in range */
1416 max = (U8)d[1]; /* last char in range */
1420 "Invalid range \"%c-%c\" in transliteration operator",
1421 (char)min, (char)max);
1425 if ((isLOWER(min) && isLOWER(max)) ||
1426 (isUPPER(min) && isUPPER(max))) {
1428 for (i = min; i <= max; i++)
1430 *d++ = NATIVE_TO_NEED(has_utf8,i);
1432 for (i = min; i <= max; i++)
1434 *d++ = NATIVE_TO_NEED(has_utf8,i);
1439 for (i = min; i <= max; i++)
1442 /* mark the range as done, and continue */
1448 /* range begins (ignore - as first or last char) */
1449 else if (*s == '-' && s+1 < send && s != start) {
1451 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1454 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1466 /* if we get here, we're not doing a transliteration */
1468 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1469 except for the last char, which will be done separately. */
1470 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1472 while (s+1 < send && *s != ')')
1473 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1475 else if (s[2] == '{' /* This should match regcomp.c */
1476 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1479 char *regparse = s + (s[2] == '{' ? 3 : 4);
1482 while (count && (c = *regparse)) {
1483 if (c == '\\' && regparse[1])
1491 if (*regparse != ')')
1492 regparse--; /* Leave one char for continuation. */
1493 while (s < regparse)
1494 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1498 /* likewise skip #-initiated comments in //x patterns */
1499 else if (*s == '#' && PL_lex_inpat &&
1500 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1501 while (s+1 < send && *s != '\n')
1502 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1505 /* check for embedded arrays
1506 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1508 else if (*s == '@' && s[1]
1509 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1512 /* check for embedded scalars. only stop if we're sure it's a
1515 else if (*s == '$') {
1516 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1518 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1519 break; /* in regexp, $ might be tail anchor */
1522 /* End of else if chain - OP_TRANS rejoin rest */
1525 if (*s == '\\' && s+1 < send) {
1528 /* some backslashes we leave behind */
1529 if (*leaveit && *s && strchr(leaveit, *s)) {
1530 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1531 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1535 /* deprecate \1 in strings and substitution replacements */
1536 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1537 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1539 if (ckWARN(WARN_SYNTAX))
1540 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
1545 /* string-change backslash escapes */
1546 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1551 /* if we get here, it's either a quoted -, or a digit */
1554 /* quoted - in transliterations */
1556 if (PL_lex_inwhat == OP_TRANS) {
1563 if (ckWARN(WARN_MISC) &&
1566 Perl_warner(aTHX_ packWARN(WARN_MISC),
1567 "Unrecognized escape \\%c passed through",
1569 /* default action is to copy the quoted character */
1570 goto default_action;
1573 /* \132 indicates an octal constant */
1574 case '0': case '1': case '2': case '3':
1575 case '4': case '5': case '6': case '7':
1579 uv = grok_oct(s, &len, &flags, NULL);
1582 goto NUM_ESCAPE_INSERT;
1584 /* \x24 indicates a hex constant */
1588 char* e = strchr(s, '}');
1589 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1590 PERL_SCAN_DISALLOW_PREFIX;
1595 yyerror("Missing right brace on \\x{}");
1599 uv = grok_hex(s, &len, &flags, NULL);
1605 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
1606 uv = grok_hex(s, &len, &flags, NULL);
1612 /* Insert oct or hex escaped character.
1613 * There will always enough room in sv since such
1614 * escapes will be longer than any UTF-8 sequence
1615 * they can end up as. */
1617 /* We need to map to chars to ASCII before doing the tests
1620 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
1621 if (!has_utf8 && uv > 255) {
1622 /* Might need to recode whatever we have
1623 * accumulated so far if it contains any
1626 * (Can't we keep track of that and avoid
1627 * this rescan? --jhi)
1631 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
1632 if (!NATIVE_IS_INVARIANT(*c)) {
1637 STRLEN offset = d - SvPVX(sv);
1639 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
1643 while (src >= (U8 *)SvPVX(sv)) {
1644 if (!NATIVE_IS_INVARIANT(*src)) {
1645 U8 ch = NATIVE_TO_ASCII(*src);
1646 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
1647 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
1657 if (has_utf8 || uv > 255) {
1658 d = (char*)uvchr_to_utf8((U8*)d, uv);
1660 if (PL_lex_inwhat == OP_TRANS &&
1661 PL_sublex_info.sub_op) {
1662 PL_sublex_info.sub_op->op_private |=
1663 (PL_lex_repl ? OPpTRANS_FROM_UTF
1676 /* \N{LATIN SMALL LETTER A} is a named character */
1680 char* e = strchr(s, '}');
1686 yyerror("Missing right brace on \\N{}");
1690 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
1692 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1693 PERL_SCAN_DISALLOW_PREFIX;
1696 uv = grok_hex(s, &len, &flags, NULL);
1698 goto NUM_ESCAPE_INSERT;
1700 res = newSVpvn(s + 1, e - s - 1);
1701 res = new_constant( Nullch, 0, "charnames",
1702 res, Nullsv, "\\N{...}" );
1704 sv_utf8_upgrade(res);
1705 str = SvPV(res,len);
1706 #ifdef EBCDIC_NEVER_MIND
1707 /* charnames uses pack U and that has been
1708 * recently changed to do the below uni->native
1709 * mapping, so this would be redundant (and wrong,
1710 * the code point would be doubly converted).
1711 * But leave this in just in case the pack U change
1712 * gets revoked, but the semantics is still
1713 * desireable for charnames. --jhi */
1715 UV uv = utf8_to_uvchr((U8*)str, 0);
1718 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
1720 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
1721 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
1722 str = SvPV(res, len);
1726 if (!has_utf8 && SvUTF8(res)) {
1727 char *ostart = SvPVX(sv);
1728 SvCUR_set(sv, d - ostart);
1731 sv_utf8_upgrade(sv);
1732 /* this just broke our allocation above... */
1733 SvGROW(sv, (STRLEN)(send - start));
1734 d = SvPVX(sv) + SvCUR(sv);
1737 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
1738 char *odest = SvPVX(sv);
1740 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
1741 d = SvPVX(sv) + (d - odest);
1743 Copy(str, d, len, char);
1750 yyerror("Missing braces on \\N{}");
1753 /* \c is a control character */
1762 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
1765 yyerror("Missing control char name in \\c");
1769 /* printf-style backslashes, formfeeds, newlines, etc */
1771 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
1774 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
1777 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
1780 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
1783 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
1786 *d++ = ASCII_TO_NEED(has_utf8,'\033');
1789 *d++ = ASCII_TO_NEED(has_utf8,'\007');
1795 } /* end if (backslash) */
1798 /* If we started with encoded form, or already know we want it
1799 and then encode the next character */
1800 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
1802 UV uv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
1803 STRLEN need = UNISKIP(NATIVE_TO_UNI(uv));
1806 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
1807 STRLEN off = d - SvPVX(sv);
1808 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
1810 d = (char*)uvchr_to_utf8((U8*)d, uv);
1814 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1816 } /* while loop to process each character */
1818 /* terminate the string and set up the sv */
1820 SvCUR_set(sv, d - SvPVX(sv));
1821 if (SvCUR(sv) >= SvLEN(sv))
1822 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
1825 if (PL_encoding && !has_utf8) {
1826 sv_recode_to_utf8(sv, PL_encoding);
1832 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1833 PL_sublex_info.sub_op->op_private |=
1834 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1838 /* shrink the sv if we allocated more than we used */
1839 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1840 SvPV_shrink_to_cur(sv);
1843 /* return the substring (via yylval) only if we parsed anything */
1844 if (s > PL_bufptr) {
1845 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1846 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1848 ( PL_lex_inwhat == OP_TRANS
1850 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1853 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1860 * Returns TRUE if there's more to the expression (e.g., a subscript),
1863 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
1865 * ->[ and ->{ return TRUE
1866 * { and [ outside a pattern are always subscripts, so return TRUE
1867 * if we're outside a pattern and it's not { or [, then return FALSE
1868 * if we're in a pattern and the first char is a {
1869 * {4,5} (any digits around the comma) returns FALSE
1870 * if we're in a pattern and the first char is a [
1872 * [SOMETHING] has a funky algorithm to decide whether it's a
1873 * character class or not. It has to deal with things like
1874 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
1875 * anything else returns TRUE
1878 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1881 S_intuit_more(pTHX_ register char *s)
1883 if (PL_lex_brackets)
1885 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1887 if (*s != '{' && *s != '[')
1892 /* In a pattern, so maybe we have {n,m}. */
1909 /* On the other hand, maybe we have a character class */
1912 if (*s == ']' || *s == '^')
1915 /* this is terrifying, and it works */
1916 int weight = 2; /* let's weigh the evidence */
1918 unsigned char un_char = 255, last_un_char;
1919 const char *send = strchr(s,']');
1920 char tmpbuf[sizeof PL_tokenbuf * 4];
1922 if (!send) /* has to be an expression */
1925 Zero(seen,256,char);
1928 else if (isDIGIT(*s)) {
1930 if (isDIGIT(s[1]) && s[2] == ']')
1936 for (; s < send; s++) {
1937 last_un_char = un_char;
1938 un_char = (unsigned char)*s;
1943 weight -= seen[un_char] * 10;
1944 if (isALNUM_lazy_if(s+1,UTF)) {
1945 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
1946 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
1951 else if (*s == '$' && s[1] &&
1952 strchr("[#!%*<>()-=",s[1])) {
1953 if (/*{*/ strchr("])} =",s[2]))
1962 if (strchr("wds]",s[1]))
1964 else if (seen['\''] || seen['"'])
1966 else if (strchr("rnftbxcav",s[1]))
1968 else if (isDIGIT(s[1])) {
1970 while (s[1] && isDIGIT(s[1]))
1980 if (strchr("aA01! ",last_un_char))
1982 if (strchr("zZ79~",s[1]))
1984 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
1985 weight -= 5; /* cope with negative subscript */
1988 if (!isALNUM(last_un_char)
1989 && !(last_un_char == '$' || last_un_char == '@'
1990 || last_un_char == '&')
1991 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
1996 if (keyword(tmpbuf, d - tmpbuf))
1999 if (un_char == last_un_char + 1)
2001 weight -= seen[un_char];
2006 if (weight >= 0) /* probably a character class */
2016 * Does all the checking to disambiguate
2018 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2019 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2021 * First argument is the stuff after the first token, e.g. "bar".
2023 * Not a method if bar is a filehandle.
2024 * Not a method if foo is a subroutine prototyped to take a filehandle.
2025 * Not a method if it's really "Foo $bar"
2026 * Method if it's "foo $bar"
2027 * Not a method if it's really "print foo $bar"
2028 * Method if it's really "foo package::" (interpreted as package->foo)
2029 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2030 * Not a method if bar is a filehandle or package, but is quoted with
2035 S_intuit_method(pTHX_ char *start, GV *gv)
2037 char *s = start + (*start == '$');
2038 char tmpbuf[sizeof PL_tokenbuf];
2046 if ((cv = GvCVu(gv))) {
2047 const char *proto = SvPVX(cv);
2057 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2058 /* start is the beginning of the possible filehandle/object,
2059 * and s is the end of it
2060 * tmpbuf is a copy of it
2063 if (*start == '$') {
2064 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2069 return *s == '(' ? FUNCMETH : METHOD;
2071 if (!keyword(tmpbuf, len)) {
2072 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2077 indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2078 if (indirgv && GvCVu(indirgv))
2080 /* filehandle or package name makes it a method */
2081 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2083 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2084 return 0; /* no assumptions -- "=>" quotes bearword */
2086 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
2087 newSVpvn(tmpbuf,len));
2088 PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
2092 return *s == '(' ? FUNCMETH : METHOD;
2100 * Return a string of Perl code to load the debugger. If PERL5DB
2101 * is set, it will return the contents of that, otherwise a
2102 * compile-time require of perl5db.pl.
2109 const char *pdb = PerlEnv_getenv("PERL5DB");
2113 SETERRNO(0,SS_NORMAL);
2114 return "BEGIN { require 'perl5db.pl' }";
2120 /* Encoded script support. filter_add() effectively inserts a
2121 * 'pre-processing' function into the current source input stream.
2122 * Note that the filter function only applies to the current source file
2123 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2125 * The datasv parameter (which may be NULL) can be used to pass
2126 * private data to this instance of the filter. The filter function
2127 * can recover the SV using the FILTER_DATA macro and use it to
2128 * store private buffers and state information.
2130 * The supplied datasv parameter is upgraded to a PVIO type
2131 * and the IoDIRP/IoANY field is used to store the function pointer,
2132 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2133 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2134 * private use must be set using malloc'd pointers.
2138 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2145 if (!PL_rsfp_filters)
2146 PL_rsfp_filters = newAV();
2148 datasv = NEWSV(255,0);
2149 (void)SvUPGRADE(datasv, SVt_PVIO);
2151 IoANY(datasv) = u.iop; /* stash funcp into spare field */
2152 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2153 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2154 (void*)funcp, SvPV_nolen(datasv)));
2155 av_unshift(PL_rsfp_filters, 1);
2156 av_store(PL_rsfp_filters, 0, datasv) ;
2161 /* Delete most recently added instance of this filter function. */
2163 Perl_filter_del(pTHX_ filter_t funcp)
2168 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", (void*)funcp));
2169 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2171 /* if filter is on top of stack (usual case) just pop it off */
2172 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2173 u.iop = IoANY(datasv);
2174 if (u.filter == funcp) {
2175 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2176 IoANY(datasv) = (void *)NULL;
2177 sv_free(av_pop(PL_rsfp_filters));
2181 /* we need to search for the correct entry and clear it */
2182 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2186 /* Invoke the idxth filter function for the current rsfp. */
2187 /* maxlen 0 = read one text line */
2189 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2195 if (!PL_rsfp_filters)
2197 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2198 /* Provide a default input filter to make life easy. */
2199 /* Note that we append to the line. This is handy. */
2200 DEBUG_P(PerlIO_printf(Perl_debug_log,
2201 "filter_read %d: from rsfp\n", idx));
2205 const int old_len = SvCUR(buf_sv);
2207 /* ensure buf_sv is large enough */
2208 SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ;
2209 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
2210 if (PerlIO_error(PL_rsfp))
2211 return -1; /* error */
2213 return 0 ; /* end of file */
2215 SvCUR_set(buf_sv, old_len + len) ;
2218 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2219 if (PerlIO_error(PL_rsfp))
2220 return -1; /* error */
2222 return 0 ; /* end of file */
2225 return SvCUR(buf_sv);
2227 /* Skip this filter slot if filter has been deleted */
2228 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2229 DEBUG_P(PerlIO_printf(Perl_debug_log,
2230 "filter_read %d: skipped (filter deleted)\n",
2232 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
2234 /* Get function pointer hidden within datasv */
2235 u.iop = IoANY(datasv);
2237 DEBUG_P(PerlIO_printf(Perl_debug_log,
2238 "filter_read %d: via function %p (%s)\n",
2239 idx, (void*)funcp, SvPV_nolen(datasv)));
2240 /* Call function. The function is expected to */
2241 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2242 /* Return: <0:error, =0:eof, >0:not eof */
2243 return (*funcp)(aTHX_ idx, buf_sv, maxlen);
2247 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2249 #ifdef PERL_CR_FILTER
2250 if (!PL_rsfp_filters) {
2251 filter_add(S_cr_textfilter,NULL);
2254 if (PL_rsfp_filters) {
2256 SvCUR_set(sv, 0); /* start with empty line */
2257 if (FILTER_READ(0, sv, 0) > 0)
2258 return ( SvPVX(sv) ) ;
2263 return (sv_gets(sv, fp, append));
2267 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2271 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2275 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2276 (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV)))
2278 return GvHV(gv); /* Foo:: */
2281 /* use constant CLASS => 'MyClass' */
2282 if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) {
2284 if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2285 pkgname = SvPV_nolen(sv);
2289 return gv_stashpv(pkgname, FALSE);
2293 static const char* const exp_name[] =
2294 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2295 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
2302 Works out what to call the token just pulled out of the input
2303 stream. The yacc parser takes care of taking the ops we return and
2304 stitching them into a tree.
2310 if read an identifier
2311 if we're in a my declaration
2312 croak if they tried to say my($foo::bar)
2313 build the ops for a my() declaration
2314 if it's an access to a my() variable
2315 are we in a sort block?
2316 croak if my($a); $a <=> $b
2317 build ops for access to a my() variable
2318 if in a dq string, and they've said @foo and we can't find @foo
2320 build ops for a bareword
2321 if we already built the token before, use it.
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) {
2441 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2442 if (PL_lex_casemods == 1 && PL_lex_inpat)
2451 case LEX_INTERPPUSH:
2452 return REPORT(sublex_push());
2454 case LEX_INTERPSTART:
2455 if (PL_bufptr == PL_bufend)
2456 return REPORT(sublex_done());
2457 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2458 "### Interpolated variable at '%s'\n", PL_bufptr); });
2460 PL_lex_dojoin = (*PL_bufptr == '@');
2461 PL_lex_state = LEX_INTERPNORMAL;
2462 if (PL_lex_dojoin) {
2463 PL_nextval[PL_nexttoke].ival = 0;
2465 force_ident("\"", '$');
2466 PL_nextval[PL_nexttoke].ival = 0;
2468 PL_nextval[PL_nexttoke].ival = 0;
2470 PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
2473 if (PL_lex_starts++) {
2475 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2476 if (!PL_lex_casemods && PL_lex_inpat)
2483 case LEX_INTERPENDMAYBE:
2484 if (intuit_more(PL_bufptr)) {
2485 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
2491 if (PL_lex_dojoin) {
2492 PL_lex_dojoin = FALSE;
2493 PL_lex_state = LEX_INTERPCONCAT;
2496 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2497 && SvEVALED(PL_lex_repl))
2499 if (PL_bufptr != PL_bufend)
2500 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2501 PL_lex_repl = Nullsv;
2504 case LEX_INTERPCONCAT:
2506 if (PL_lex_brackets)
2507 Perl_croak(aTHX_ "panic: INTERPCONCAT");
2509 if (PL_bufptr == PL_bufend)
2510 return REPORT(sublex_done());
2512 if (SvIVX(PL_linestr) == '\'') {
2513 SV *sv = newSVsv(PL_linestr);
2516 else if ( PL_hints & HINT_NEW_RE )
2517 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2518 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2522 s = scan_const(PL_bufptr);
2524 PL_lex_state = LEX_INTERPCASEMOD;
2526 PL_lex_state = LEX_INTERPSTART;
2529 if (s != PL_bufptr) {
2530 PL_nextval[PL_nexttoke] = yylval;
2533 if (PL_lex_starts++) {
2534 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2535 if (!PL_lex_casemods && PL_lex_inpat)
2548 PL_lex_state = LEX_NORMAL;
2549 s = scan_formline(PL_bufptr);
2550 if (!PL_lex_formbrack)
2556 PL_oldoldbufptr = PL_oldbufptr;
2559 PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at [%s]\n",
2560 exp_name[PL_expect], s);
2566 if (isIDFIRST_lazy_if(s,UTF))
2568 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2571 goto fake_eof; /* emulate EOF on ^D or ^Z */
2576 if (PL_lex_brackets) {
2577 if (PL_lex_formbrack)
2578 yyerror("Format not terminated");
2580 yyerror("Missing right curly or square bracket");
2582 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2583 "### Tokener got EOF\n");
2587 if (s++ < PL_bufend)
2588 goto retry; /* ignore stray nulls */
2591 if (!PL_in_eval && !PL_preambled) {
2592 PL_preambled = TRUE;
2593 sv_setpv(PL_linestr,incl_perldb());
2594 if (SvCUR(PL_linestr))
2595 sv_catpvn(PL_linestr,";", 1);
2597 while(AvFILLp(PL_preambleav) >= 0) {
2598 SV *tmpsv = av_shift(PL_preambleav);
2599 sv_catsv(PL_linestr, tmpsv);
2600 sv_catpvn(PL_linestr, ";", 1);
2603 sv_free((SV*)PL_preambleav);
2604 PL_preambleav = NULL;
2606 if (PL_minus_n || PL_minus_p) {
2607 sv_catpv(PL_linestr, "LINE: while (<>) {");
2609 sv_catpv(PL_linestr,"chomp;");
2612 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
2613 || *PL_splitstr == '"')
2614 && strchr(PL_splitstr + 1, *PL_splitstr))
2615 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
2617 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
2618 bytes can be used as quoting characters. :-) */
2619 /* The count here deliberately includes the NUL
2620 that terminates the C string constant. This
2621 embeds the opening NUL into the string. */
2622 const char *splits = PL_splitstr;
2623 sv_catpvn(PL_linestr, "our @F=split(q", 15);
2626 if (*splits == '\\')
2627 sv_catpvn(PL_linestr, splits, 1);
2628 sv_catpvn(PL_linestr, splits, 1);
2629 } while (*splits++);
2630 /* This loop will embed the trailing NUL of
2631 PL_linestr as the last thing it does before
2633 sv_catpvn(PL_linestr, ");", 2);
2637 sv_catpv(PL_linestr,"our @F=split(' ');");
2640 sv_catpvn(PL_linestr, "\n", 1);
2641 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2642 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2643 PL_last_lop = PL_last_uni = Nullch;
2644 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2645 SV *sv = NEWSV(85,0);
2647 sv_upgrade(sv, SVt_PVMG);
2648 sv_setsv(sv,PL_linestr);
2651 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2656 bof = PL_rsfp ? TRUE : FALSE;
2657 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2660 if (PL_preprocess && !PL_in_eval)
2661 (void)PerlProc_pclose(PL_rsfp);
2662 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2663 PerlIO_clearerr(PL_rsfp);
2665 (void)PerlIO_close(PL_rsfp);
2667 PL_doextract = FALSE;
2669 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2670 sv_setpv(PL_linestr,PL_minus_p
2671 ? ";}continue{print;}" : ";}");
2672 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2673 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2674 PL_last_lop = PL_last_uni = Nullch;
2675 PL_minus_n = PL_minus_p = 0;
2678 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2679 PL_last_lop = PL_last_uni = Nullch;
2680 sv_setpvn(PL_linestr,"",0);
2681 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
2683 /* If it looks like the start of a BOM or raw UTF-16,
2684 * check if it in fact is. */
2690 #ifdef PERLIO_IS_STDIO
2691 # ifdef __GNU_LIBRARY__
2692 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
2693 # define FTELL_FOR_PIPE_IS_BROKEN
2697 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
2698 # define FTELL_FOR_PIPE_IS_BROKEN
2703 #ifdef FTELL_FOR_PIPE_IS_BROKEN
2704 /* This loses the possibility to detect the bof
2705 * situation on perl -P when the libc5 is being used.
2706 * Workaround? Maybe attach some extra state to PL_rsfp?
2709 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2711 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
2714 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2715 s = swallow_bom((U8*)s);
2719 /* Incest with pod. */
2720 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2721 sv_setpvn(PL_linestr, "", 0);
2722 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2723 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2724 PL_last_lop = PL_last_uni = Nullch;
2725 PL_doextract = FALSE;
2729 } while (PL_doextract);
2730 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2731 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2732 SV *sv = NEWSV(85,0);
2734 sv_upgrade(sv, SVt_PVMG);
2735 sv_setsv(sv,PL_linestr);
2738 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2740 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2741 PL_last_lop = PL_last_uni = Nullch;
2742 if (CopLINE(PL_curcop) == 1) {
2743 while (s < PL_bufend && isSPACE(*s))
2745 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2749 if (*s == '#' && *(s+1) == '!')
2751 #ifdef ALTERNATE_SHEBANG
2753 static char const as[] = ALTERNATE_SHEBANG;
2754 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2755 d = s + (sizeof(as) - 1);
2757 #endif /* ALTERNATE_SHEBANG */
2766 while (*d && !isSPACE(*d))
2770 #ifdef ARG_ZERO_IS_SCRIPT
2771 if (ipathend > ipath) {
2773 * HP-UX (at least) sets argv[0] to the script name,
2774 * which makes $^X incorrect. And Digital UNIX and Linux,
2775 * at least, set argv[0] to the basename of the Perl
2776 * interpreter. So, having found "#!", we'll set it right.
2778 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); /* $^X */
2779 assert(SvPOK(x) || SvGMAGICAL(x));
2780 if (sv_eq(x, CopFILESV(PL_curcop))) {
2781 sv_setpvn(x, ipath, ipathend - ipath);
2787 const char *bstart = SvPV(CopFILESV(PL_curcop),blen);
2788 const char *lstart = SvPV(x,llen);
2790 bstart += blen - llen;
2791 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
2792 sv_setpvn(x, ipath, ipathend - ipath);
2797 TAINT_NOT; /* $^X is always tainted, but that's OK */
2799 #endif /* ARG_ZERO_IS_SCRIPT */
2804 d = instr(s,"perl -");
2806 d = instr(s,"perl");
2808 /* avoid getting into infinite loops when shebang
2809 * line contains "Perl" rather than "perl" */
2811 for (d = ipathend-4; d >= ipath; --d) {
2812 if ((*d == 'p' || *d == 'P')
2813 && !ibcmp(d, "perl", 4))
2823 #ifdef ALTERNATE_SHEBANG
2825 * If the ALTERNATE_SHEBANG on this system starts with a
2826 * character that can be part of a Perl expression, then if
2827 * we see it but not "perl", we're probably looking at the
2828 * start of Perl code, not a request to hand off to some
2829 * other interpreter. Similarly, if "perl" is there, but
2830 * not in the first 'word' of the line, we assume the line
2831 * contains the start of the Perl program.
2833 if (d && *s != '#') {
2834 const char *c = ipath;
2835 while (*c && !strchr("; \t\r\n\f\v#", *c))
2838 d = Nullch; /* "perl" not in first word; ignore */
2840 *s = '#'; /* Don't try to parse shebang line */
2842 #endif /* ALTERNATE_SHEBANG */
2843 #ifndef MACOS_TRADITIONAL
2848 !instr(s,"indir") &&
2849 instr(PL_origargv[0],"perl"))
2856 while (s < PL_bufend && isSPACE(*s))
2858 if (s < PL_bufend) {
2859 Newz(899,newargv,PL_origargc+3,char*);
2861 while (s < PL_bufend && !isSPACE(*s))
2864 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2867 newargv = PL_origargv;
2870 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
2872 Perl_croak(aTHX_ "Can't exec %s", ipath);
2876 const U32 oldpdb = PL_perldb;
2877 const bool oldn = PL_minus_n;
2878 const bool oldp = PL_minus_p;
2880 while (*d && !isSPACE(*d)) d++;
2881 while (SPACE_OR_TAB(*d)) d++;
2884 const bool switches_done = PL_doswitches;
2886 if (*d == 'M' || *d == 'm' || *d == 'C') {
2888 while (*d && !isSPACE(*d)) d++;
2889 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2892 d = moreswitches(d);
2894 if (PL_doswitches && !switches_done) {
2895 int argc = PL_origargc;
2896 char **argv = PL_origargv;
2899 } while (argc && argv[0][0] == '-' && argv[0][1]);
2900 init_argv_symbols(argc,argv);
2902 if ((PERLDB_LINE && !oldpdb) ||
2903 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
2904 /* if we have already added "LINE: while (<>) {",
2905 we must not do it again */
2907 sv_setpvn(PL_linestr, "", 0);
2908 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2909 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2910 PL_last_lop = PL_last_uni = Nullch;
2911 PL_preambled = FALSE;
2913 (void)gv_fetchfile(PL_origfilename);
2916 if (PL_doswitches && !switches_done) {
2917 int argc = PL_origargc;
2918 char **argv = PL_origargv;
2921 } while (argc && argv[0][0] == '-' && argv[0][1]);
2922 init_argv_symbols(argc,argv);
2928 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2930 PL_lex_state = LEX_FORMLINE;
2935 #ifdef PERL_STRICT_CR
2936 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
2938 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
2940 case ' ': case '\t': case '\f': case 013:
2941 #ifdef MACOS_TRADITIONAL
2948 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
2949 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
2950 /* handle eval qq[#line 1 "foo"\n ...] */
2951 CopLINE_dec(PL_curcop);
2955 while (s < d && *s != '\n')
2959 else if (s > d) /* Found by Ilya: feed random input to Perl. */
2960 Perl_croak(aTHX_ "panic: input overflow");
2962 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2964 PL_lex_state = LEX_FORMLINE;
2974 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2981 while (s < PL_bufend && SPACE_OR_TAB(*s))
2984 if (strnEQ(s,"=>",2)) {
2985 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
2986 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2987 "### Saw unary minus before =>, forcing word '%s'\n", s);
2989 OPERATOR('-'); /* unary minus */
2991 PL_last_uni = PL_oldbufptr;
2993 case 'r': ftst = OP_FTEREAD; break;
2994 case 'w': ftst = OP_FTEWRITE; break;
2995 case 'x': ftst = OP_FTEEXEC; break;
2996 case 'o': ftst = OP_FTEOWNED; break;
2997 case 'R': ftst = OP_FTRREAD; break;
2998 case 'W': ftst = OP_FTRWRITE; break;
2999 case 'X': ftst = OP_FTREXEC; break;
3000 case 'O': ftst = OP_FTROWNED; break;
3001 case 'e': ftst = OP_FTIS; break;
3002 case 'z': ftst = OP_FTZERO; break;
3003 case 's': ftst = OP_FTSIZE; break;
3004 case 'f': ftst = OP_FTFILE; break;
3005 case 'd': ftst = OP_FTDIR; break;
3006 case 'l': ftst = OP_FTLINK; break;
3007 case 'p': ftst = OP_FTPIPE; break;
3008 case 'S': ftst = OP_FTSOCK; break;
3009 case 'u': ftst = OP_FTSUID; break;
3010 case 'g': ftst = OP_FTSGID; break;
3011 case 'k': ftst = OP_FTSVTX; break;
3012 case 'b': ftst = OP_FTBLK; break;
3013 case 'c': ftst = OP_FTCHR; break;
3014 case 't': ftst = OP_FTTTY; break;
3015 case 'T': ftst = OP_FTTEXT; break;
3016 case 'B': ftst = OP_FTBINARY; break;
3017 case 'M': case 'A': case 'C':
3018 gv_fetchpv("\024",TRUE, SVt_PV);
3020 case 'M': ftst = OP_FTMTIME; break;
3021 case 'A': ftst = OP_FTATIME; break;
3022 case 'C': ftst = OP_FTCTIME; break;
3030 PL_last_lop_op = (OPCODE)ftst;
3031 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3032 "### Saw file test %c\n", (int)ftst);
3037 /* Assume it was a minus followed by a one-letter named
3038 * subroutine call (or a -bareword), then. */
3039 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3040 "### '-%c' looked like a file test but was not\n",
3049 if (PL_expect == XOPERATOR)
3054 else if (*s == '>') {
3057 if (isIDFIRST_lazy_if(s,UTF)) {
3058 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3066 if (PL_expect == XOPERATOR)
3069 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3071 OPERATOR('-'); /* unary minus */
3078 if (PL_expect == XOPERATOR)
3083 if (PL_expect == XOPERATOR)
3086 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3092 if (PL_expect != XOPERATOR) {
3093 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3094 PL_expect = XOPERATOR;
3095 force_ident(PL_tokenbuf, '*');
3108 if (PL_expect == XOPERATOR) {
3112 PL_tokenbuf[0] = '%';
3113 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3114 if (!PL_tokenbuf[1]) {
3117 PL_pending_ident = '%';
3136 switch (PL_expect) {
3139 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3141 PL_bufptr = s; /* update in case we back off */
3147 PL_expect = XTERMBLOCK;
3151 while (isIDFIRST_lazy_if(s,UTF)) {
3152 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3153 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
3154 if (tmp < 0) tmp = -tmp;
3170 d = scan_str(d,TRUE,TRUE);
3172 /* MUST advance bufptr here to avoid bogus
3173 "at end of line" context messages from yyerror().
3175 PL_bufptr = s + len;
3176 yyerror("Unterminated attribute parameter in attribute list");
3179 return REPORT(0); /* EOF indicator */
3183 SV *sv = newSVpvn(s, len);
3184 sv_catsv(sv, PL_lex_stuff);
3185 attrs = append_elem(OP_LIST, attrs,
3186 newSVOP(OP_CONST, 0, sv));
3187 SvREFCNT_dec(PL_lex_stuff);
3188 PL_lex_stuff = Nullsv;
3191 if (len == 6 && strnEQ(s, "unique", len)) {
3192 if (PL_in_my == KEY_our)
3194 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
3196 ; /* skip to avoid loading attributes.pm */
3199 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
3202 /* NOTE: any CV attrs applied here need to be part of
3203 the CVf_BUILTIN_ATTRS define in cv.h! */
3204 else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
3205 CvLVALUE_on(PL_compcv);
3206 else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
3207 CvLOCKED_on(PL_compcv);
3208 else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
3209 CvMETHOD_on(PL_compcv);
3210 else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len))
3211 CvASSERTION_on(PL_compcv);
3212 /* After we've set the flags, it could be argued that
3213 we don't need to do the attributes.pm-based setting
3214 process, and shouldn't bother appending recognized
3215 flags. To experiment with that, uncomment the
3216 following "else". (Note that's already been
3217 uncommented. That keeps the above-applied built-in
3218 attributes from being intercepted (and possibly
3219 rejected) by a package's attribute routines, but is
3220 justified by the performance win for the common case
3221 of applying only built-in attributes.) */
3223 attrs = append_elem(OP_LIST, attrs,
3224 newSVOP(OP_CONST, 0,
3228 if (*s == ':' && s[1] != ':')
3231 break; /* require real whitespace or :'s */
3233 tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
3234 if (*s != ';' && *s != '}' && *s != tmp && (tmp != '=' || *s != ')')) {
3235 const char q = ((*s == '\'') ? '"' : '\'');
3236 /* If here for an expression, and parsed no attrs, back off. */
3237 if (tmp == '=' && !attrs) {
3241 /* MUST advance bufptr here to avoid bogus "at end of line"
3242 context messages from yyerror().
3246 yyerror("Unterminated attribute list");
3248 yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
3256 PL_nextval[PL_nexttoke].opval = attrs;
3264 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
3265 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
3282 if (PL_lex_brackets <= 0)
3283 yyerror("Unmatched right square bracket");
3286 if (PL_lex_state == LEX_INTERPNORMAL) {
3287 if (PL_lex_brackets == 0) {
3288 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3289 PL_lex_state = LEX_INTERPEND;
3296 if (PL_lex_brackets > 100) {
3297 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
3299 switch (PL_expect) {
3301 if (PL_lex_formbrack) {
3305 if (PL_oldoldbufptr == PL_last_lop)
3306 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3308 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3309 OPERATOR(HASHBRACK);
3311 while (s < PL_bufend && SPACE_OR_TAB(*s))
3314 PL_tokenbuf[0] = '\0';
3315 if (d < PL_bufend && *d == '-') {
3316 PL_tokenbuf[0] = '-';
3318 while (d < PL_bufend && SPACE_OR_TAB(*d))
3321 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3322 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
3324 while (d < PL_bufend && SPACE_OR_TAB(*d))
3327 const char minus = (PL_tokenbuf[0] == '-');
3328 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
3336 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
3341 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3346 if (PL_oldoldbufptr == PL_last_lop)
3347 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3349 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3352 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
3354 /* This hack is to get the ${} in the message. */
3356 yyerror("syntax error");
3359 OPERATOR(HASHBRACK);
3361 /* This hack serves to disambiguate a pair of curlies
3362 * as being a block or an anon hash. Normally, expectation
3363 * determines that, but in cases where we're not in a
3364 * position to expect anything in particular (like inside
3365 * eval"") we have to resolve the ambiguity. This code
3366 * covers the case where the first term in the curlies is a
3367 * quoted string. Most other cases need to be explicitly
3368 * disambiguated by prepending a `+' before the opening
3369 * curly in order to force resolution as an anon hash.
3371 * XXX should probably propagate the outer expectation
3372 * into eval"" to rely less on this hack, but that could
3373 * potentially break current behavior of eval"".
3377 if (*s == '\'' || *s == '"' || *s == '`') {
3378 /* common case: get past first string, handling escapes */
3379 for (t++; t < PL_bufend && *t != *s;)
3380 if (*t++ == '\\' && (*t == '\\' || *t == *s))
3384 else if (*s == 'q') {
3387 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
3390 /* skip q//-like construct */
3392 char open, close, term;
3395 while (t < PL_bufend && isSPACE(*t))
3397 /* check for q => */
3398 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
3399 OPERATOR(HASHBRACK);
3403 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
3407 for (t++; t < PL_bufend; t++) {
3408 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
3410 else if (*t == open)
3414 for (t++; t < PL_bufend; t++) {
3415 if (*t == '\\' && t+1 < PL_bufend)
3417 else if (*t == close && --brackets <= 0)
3419 else if (*t == open)
3426 /* skip plain q word */
3427 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3430 else if (isALNUM_lazy_if(t,UTF)) {
3432 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3435 while (t < PL_bufend && isSPACE(*t))
3437 /* if comma follows first term, call it an anon hash */
3438 /* XXX it could be a comma expression with loop modifiers */
3439 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
3440 || (*t == '=' && t[1] == '>')))
3441 OPERATOR(HASHBRACK);
3442 if (PL_expect == XREF)
3445 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3451 yylval.ival = CopLINE(PL_curcop);
3452 if (isSPACE(*s) || *s == '#')
3453 PL_copline = NOLINE; /* invalidate current command line number */
3458 if (PL_lex_brackets <= 0)
3459 yyerror("Unmatched right curly bracket");
3461 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3462 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3463 PL_lex_formbrack = 0;
3464 if (PL_lex_state == LEX_INTERPNORMAL) {
3465 if (PL_lex_brackets == 0) {
3466 if (PL_expect & XFAKEBRACK) {
3467 PL_expect &= XENUMMASK;
3468 PL_lex_state = LEX_INTERPEND;
3470 return yylex(); /* ignore fake brackets */
3472 if (*s == '-' && s[1] == '>')
3473 PL_lex_state = LEX_INTERPENDMAYBE;
3474 else if (*s != '[' && *s != '{')
3475 PL_lex_state = LEX_INTERPEND;
3478 if (PL_expect & XFAKEBRACK) {
3479 PL_expect &= XENUMMASK;
3481 return yylex(); /* ignore fake brackets */
3491 if (PL_expect == XOPERATOR) {
3492 if (ckWARN(WARN_SEMICOLON)
3493 && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart)
3495 CopLINE_dec(PL_curcop);
3496 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
3497 CopLINE_inc(PL_curcop);
3502 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3504 PL_expect = XOPERATOR;
3505 force_ident(PL_tokenbuf, '&');
3509 yylval.ival = (OPpENTERSUB_AMPER<<8);
3528 if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
3529 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Reversed %c= operator",(int)tmp);
3531 if (PL_expect == XSTATE && isALPHA(tmp) &&
3532 (s == PL_linestart+1 || s[-2] == '\n') )
3534 if (PL_in_eval && !PL_rsfp) {
3539 if (strnEQ(s,"=cut",4)) {
3553 PL_doextract = TRUE;
3556 if (PL_lex_brackets < PL_lex_formbrack) {
3558 #ifdef PERL_STRICT_CR
3559 for (t = s; SPACE_OR_TAB(*t); t++) ;
3561 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3563 if (*t == '\n' || *t == '#') {
3575 /* was this !=~ where !~ was meant?
3576 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
3578 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
3579 const char *t = s+1;
3581 while (t < PL_bufend && isSPACE(*t))
3584 if (*t == '/' || *t == '?' ||
3585 ((*t == 'm' || *t == 's' || *t == 'y') && !isALNUM(t[1])) ||
3586 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
3587 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3588 "!=~ should be !~");
3597 if (PL_expect != XOPERATOR) {
3598 if (s[1] != '<' && !strchr(s,'>'))
3601 s = scan_heredoc(s);
3603 s = scan_inputsymbol(s);
3604 TERM(sublex_start());
3609 SHop(OP_LEFT_SHIFT);
3623 SHop(OP_RIGHT_SHIFT);
3632 if (PL_expect == XOPERATOR) {
3633 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3636 return REPORT(','); /* grandfather non-comma-format format */
3640 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3641 PL_tokenbuf[0] = '@';
3642 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3643 sizeof PL_tokenbuf - 1, FALSE);
3644 if (PL_expect == XOPERATOR)
3645 no_op("Array length", s);
3646 if (!PL_tokenbuf[1])
3648 PL_expect = XOPERATOR;
3649 PL_pending_ident = '#';
3653 PL_tokenbuf[0] = '$';
3654 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3655 sizeof PL_tokenbuf - 1, FALSE);
3656 if (PL_expect == XOPERATOR)
3658 if (!PL_tokenbuf[1]) {
3660 yyerror("Final $ should be \\$ or $name");
3664 /* This kludge not intended to be bulletproof. */
3665 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3666 yylval.opval = newSVOP(OP_CONST, 0,
3667 newSViv(PL_compiling.cop_arybase));
3668 yylval.opval->op_private = OPpCONST_ARYBASE;
3674 if (PL_lex_state == LEX_NORMAL)
3677 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3680 PL_tokenbuf[0] = '@';
3681 if (ckWARN(WARN_SYNTAX)) {
3683 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3686 PL_bufptr = skipspace(PL_bufptr);
3687 while (t < PL_bufend && *t != ']')
3689 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3690 "Multidimensional syntax %.*s not supported",
3691 (t - PL_bufptr) + 1, PL_bufptr);
3695 else if (*s == '{') {
3696 PL_tokenbuf[0] = '%';
3697 if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") &&
3698 (t = strchr(s, '}')) && (t = strchr(t, '=')))
3700 char tmpbuf[sizeof PL_tokenbuf];
3701 for (t++; isSPACE(*t); t++) ;
3702 if (isIDFIRST_lazy_if(t,UTF)) {
3704 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3705 for (; isSPACE(*t); t++) ;
3706 if (*t == ';' && get_cv(tmpbuf, FALSE))
3707 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3708 "You need to quote \"%s\"", tmpbuf);
3714 PL_expect = XOPERATOR;
3715 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3716 const bool islop = (PL_last_lop == PL_oldoldbufptr);
3717 if (!islop || PL_last_lop_op == OP_GREPSTART)
3718 PL_expect = XOPERATOR;
3719 else if (strchr("$@\"'`q", *s))
3720 PL_expect = XTERM; /* e.g. print $fh "foo" */
3721 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3722 PL_expect = XTERM; /* e.g. print $fh &sub */
3723 else if (isIDFIRST_lazy_if(s,UTF)) {
3724 char tmpbuf[sizeof PL_tokenbuf];
3725 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3726 if ((tmp = keyword(tmpbuf, len))) {
3727 /* binary operators exclude handle interpretations */
3739 PL_expect = XTERM; /* e.g. print $fh length() */
3744 PL_expect = XTERM; /* e.g. print $fh subr() */
3747 else if (isDIGIT(*s))
3748 PL_expect = XTERM; /* e.g. print $fh 3 */
3749 else if (*s == '.' && isDIGIT(s[1]))
3750 PL_expect = XTERM; /* e.g. print $fh .3 */
3751 else if ((*s == '?' || *s == '-' || *s == '+')
3752 && !isSPACE(s[1]) && s[1] != '=')
3753 PL_expect = XTERM; /* e.g. print $fh -1 */
3754 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' && s[1] != '/')
3755 PL_expect = XTERM; /* e.g. print $fh /.../
3756 XXX except DORDOR operator */
3757 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3758 PL_expect = XTERM; /* print $fh <<"EOF" */
3760 PL_pending_ident = '$';
3764 if (PL_expect == XOPERATOR)
3766 PL_tokenbuf[0] = '@';
3767 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3768 if (!PL_tokenbuf[1]) {
3771 if (PL_lex_state == LEX_NORMAL)
3773 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3775 PL_tokenbuf[0] = '%';
3777 /* Warn about @ where they meant $. */
3778 if (ckWARN(WARN_SYNTAX)) {
3779 if (*s == '[' || *s == '{') {
3780 const char *t = s + 1;
3781 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3783 if (*t == '}' || *t == ']') {
3785 PL_bufptr = skipspace(PL_bufptr);
3786 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3787 "Scalar value %.*s better written as $%.*s",
3788 t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3793 PL_pending_ident = '@';
3796 case '/': /* may be division, defined-or, or pattern */
3797 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
3801 case '?': /* may either be conditional or pattern */
3802 if(PL_expect == XOPERATOR) {
3810 /* A // operator. */
3820 /* Disable warning on "study /blah/" */
3821 if (PL_oldoldbufptr == PL_last_uni
3822 && (*PL_last_uni != 's' || s - PL_last_uni < 5
3823 || memNE(PL_last_uni, "study", 5)
3824 || isALNUM_lazy_if(PL_last_uni+5,UTF)
3827 s = scan_pat(s,OP_MATCH);
3828 TERM(sublex_start());
3832 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3833 #ifdef PERL_STRICT_CR
3836 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3838 && (s == PL_linestart || s[-1] == '\n') )
3840 PL_lex_formbrack = 0;
3844 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3850 yylval.ival = OPf_SPECIAL;
3856 if (PL_expect != XOPERATOR)
3861 case '0': case '1': case '2': case '3': case '4':
3862 case '5': case '6': case '7': case '8': case '9':
3863 s = scan_num(s, &yylval);
3864 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3865 "### Saw number in '%s'\n", s);
3867 if (PL_expect == XOPERATOR)
3872 s = scan_str(s,FALSE,FALSE);
3873 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3874 "### Saw string before '%s'\n", s);
3876 if (PL_expect == XOPERATOR) {
3877 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3880 return REPORT(','); /* grandfather non-comma-format format */
3886 missingterm((char*)0);
3887 yylval.ival = OP_CONST;
3888 TERM(sublex_start());
3891 s = scan_str(s,FALSE,FALSE);
3892 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3893 "### Saw string before '%s'\n", s);
3895 if (PL_expect == XOPERATOR) {
3896 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3899 return REPORT(','); /* grandfather non-comma-format format */
3905 missingterm((char*)0);
3906 yylval.ival = OP_CONST;
3907 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3908 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
3909 yylval.ival = OP_STRINGIFY;
3913 TERM(sublex_start());
3916 s = scan_str(s,FALSE,FALSE);
3917 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3918 "### Saw backtick string before '%s'\n", s);
3920 if (PL_expect == XOPERATOR)
3921 no_op("Backticks",s);
3923 missingterm((char*)0);
3924 yylval.ival = OP_BACKTICK;
3926 TERM(sublex_start());
3930 if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s))
3931 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
3933 if (PL_expect == XOPERATOR)
3934 no_op("Backslash",s);
3938 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
3939 char *start = s + 2;
3940 while (isDIGIT(*start) || *start == '_')
3942 if (*start == '.' && isDIGIT(start[1])) {
3943 s = scan_num(s, &yylval);
3946 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
3947 else if (!isALPHA(*start) && (PL_expect == XTERM
3948 || PL_expect == XREF || PL_expect == XSTATE
3949 || PL_expect == XTERMORDORDOR)) {
3950 const char c = *start;
3953 gv = gv_fetchpv(s, FALSE, SVt_PVCV);
3956 s = scan_num(s, &yylval);
3963 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
4003 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4005 /* Some keywords can be followed by any delimiter, including ':' */
4006 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
4007 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
4008 (PL_tokenbuf[0] == 'q' &&
4009 strchr("qwxr", PL_tokenbuf[1])))));
4011 /* x::* is just a word, unless x is "CORE" */
4012 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4016 while (d < PL_bufend && isSPACE(*d))
4017 d++; /* no comments skipped here, or s### is misparsed */
4019 /* Is this a label? */
4020 if (!tmp && PL_expect == XSTATE
4021 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4023 yylval.pval = savepv(PL_tokenbuf);
4028 /* Check for keywords */
4029 tmp = keyword(PL_tokenbuf, len);
4031 /* Is this a word before a => operator? */
4032 if (*d == '=' && d[1] == '>') {
4035 = (OP*)newSVOP(OP_CONST, 0,
4036 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
4037 yylval.opval->op_private = OPpCONST_BARE;
4041 if (tmp < 0) { /* second-class keyword? */
4042 GV *ogv = Nullgv; /* override (winner) */
4043 GV *hgv = Nullgv; /* hidden (loser) */
4044 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4046 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
4049 if (GvIMPORTED_CV(gv))
4051 else if (! CvMETHOD(cv))
4055 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4056 (gv = *gvp) != (GV*)&PL_sv_undef &&
4057 GvCVu(gv) && GvIMPORTED_CV(gv))
4064 tmp = 0; /* overridden by import or by GLOBAL */
4067 && -tmp==KEY_lock /* XXX generalizable kludge */
4069 && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
4071 tmp = 0; /* any sub overrides "weak" keyword */
4076 && PL_expect != XOPERATOR
4077 && PL_expect != XTERMORDORDOR)
4079 /* any sub overrides the "err" keyword, except when really an
4080 * operator is expected */
4083 else { /* no override */
4085 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
4086 Perl_warner(aTHX_ packWARN(WARN_MISC),
4087 "dump() better written as CORE::dump()");
4091 if (ckWARN(WARN_AMBIGUOUS) && hgv
4092 && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
4093 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4094 "Ambiguous call resolved as CORE::%s(), %s",
4095 GvENAME(hgv), "qualify as such or use &");
4102 default: /* not a keyword */
4106 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
4108 /* Get the rest if it looks like a package qualifier */
4110 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
4112 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
4115 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
4116 *s == '\'' ? "'" : "::");
4121 if (PL_expect == XOPERATOR) {
4122 if (PL_bufptr == PL_linestart) {
4123 CopLINE_dec(PL_curcop);
4124 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4125 CopLINE_inc(PL_curcop);
4128 no_op("Bareword",s);
4131 /* Look for a subroutine with this name in current package,
4132 unless name is "Foo::", in which case Foo is a bearword
4133 (and a package name). */
4136 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
4138 if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
4139 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
4140 "Bareword \"%s\" refers to nonexistent package",
4143 PL_tokenbuf[len] = '\0';
4150 gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
4153 /* if we saw a global override before, get the right name */
4156 sv = newSVpvn("CORE::GLOBAL::",14);
4157 sv_catpv(sv,PL_tokenbuf);
4160 /* If len is 0, newSVpv does strlen(), which is correct.
4161 If len is non-zero, then it will be the true length,
4162 and so the scalar will be created correctly. */
4163 sv = newSVpv(PL_tokenbuf,len);
4166 /* Presume this is going to be a bareword of some sort. */
4169 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4170 yylval.opval->op_private = OPpCONST_BARE;
4171 /* UTF-8 package name? */
4172 if (UTF && !IN_BYTES &&
4173 is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
4176 /* And if "Foo::", then that's what it certainly is. */
4181 /* See if it's the indirect object for a list operator. */
4183 if (PL_oldoldbufptr &&
4184 PL_oldoldbufptr < PL_bufptr &&
4185 (PL_oldoldbufptr == PL_last_lop
4186 || PL_oldoldbufptr == PL_last_uni) &&
4187 /* NO SKIPSPACE BEFORE HERE! */
4188 (PL_expect == XREF ||
4189 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
4191 bool immediate_paren = *s == '(';
4193 /* (Now we can afford to cross potential line boundary.) */
4196 /* Two barewords in a row may indicate method call. */
4198 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv)))
4201 /* If not a declared subroutine, it's an indirect object. */
4202 /* (But it's an indir obj regardless for sort.) */
4204 if ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
4205 ((!gv || !GvCVu(gv)) &&
4206 (PL_last_lop_op != OP_MAPSTART &&
4207 PL_last_lop_op != OP_GREPSTART))))
4209 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
4214 PL_expect = XOPERATOR;
4217 /* Is this a word before a => operator? */
4218 if (*s == '=' && s[1] == '>' && !pkgname) {
4220 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
4221 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
4222 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
4226 /* If followed by a paren, it's certainly a subroutine. */
4229 if (gv && GvCVu(gv)) {
4230 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
4231 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
4236 PL_nextval[PL_nexttoke].opval = yylval.opval;
4237 PL_expect = XOPERATOR;
4243 /* If followed by var or block, call it a method (unless sub) */
4245 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
4246 PL_last_lop = PL_oldbufptr;
4247 PL_last_lop_op = OP_METHOD;
4251 /* If followed by a bareword, see if it looks like indir obj. */
4254 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
4255 && (tmp = intuit_method(s,gv)))
4258 /* Not a method, so call it a subroutine (if defined) */
4260 if (gv && GvCVu(gv)) {
4262 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
4263 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4264 "Ambiguous use of -%s resolved as -&%s()",
4265 PL_tokenbuf, PL_tokenbuf);
4266 /* Check for a constant sub */
4268 if ((sv = cv_const_sv(cv))) {
4270 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
4271 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
4272 yylval.opval->op_private = 0;
4276 /* Resolve to GV now. */
4277 op_free(yylval.opval);
4278 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4279 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
4280 PL_last_lop = PL_oldbufptr;
4281 PL_last_lop_op = OP_ENTERSUB;
4282 /* Is there a prototype? */
4285 char *proto = SvPV((SV*)cv, len);
4288 if (*proto == '$' && proto[1] == '\0')
4290 while (*proto == ';')
4292 if (*proto == '&' && *s == '{') {
4293 sv_setpv(PL_subname, PL_curstash ?
4294 "__ANON__" : "__ANON__::__ANON__");
4298 PL_nextval[PL_nexttoke].opval = yylval.opval;
4304 /* Call it a bare word */
4306 if (PL_hints & HINT_STRICT_SUBS)
4307 yylval.opval->op_private |= OPpCONST_STRICT;
4310 if (ckWARN(WARN_RESERVED)) {
4311 if (lastchar != '-') {
4312 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
4313 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
4314 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
4321 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
4322 && ckWARN_d(WARN_AMBIGUOUS)) {
4323 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4324 "Operator or semicolon missing before %c%s",
4325 lastchar, PL_tokenbuf);
4326 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4327 "Ambiguous use of %c resolved as operator %c",
4328 lastchar, lastchar);
4334 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4335 newSVpv(CopFILE(PL_curcop),0));
4339 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4340 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
4343 case KEY___PACKAGE__:
4344 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4346 ? newSVpv(HvNAME(PL_curstash), 0)
4355 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
4356 const char *pname = "main";
4357 if (PL_tokenbuf[2] == 'D')
4358 pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash);
4359 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);
4362 GvIOp(gv) = newIO();
4363 IoIFP(GvIOp(gv)) = PL_rsfp;
4364 #if defined(HAS_FCNTL) && defined(F_SETFD)
4366 const int fd = PerlIO_fileno(PL_rsfp);
4367 fcntl(fd,F_SETFD,fd >= 3);
4370 /* Mark this internal pseudo-handle as clean */
4371 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4373 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
4374 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
4375 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
4377 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
4378 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
4379 /* if the script was opened in binmode, we need to revert
4380 * it to text mode for compatibility; but only iff it has CRs
4381 * XXX this is a questionable hack at best. */
4382 if (PL_bufend-PL_bufptr > 2
4383 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
4386 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
4387 loc = PerlIO_tell(PL_rsfp);
4388 (void)PerlIO_seek(PL_rsfp, 0L, 0);
4391 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
4393 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
4394 #endif /* NETWARE */
4395 #ifdef PERLIO_IS_STDIO /* really? */
4396 # if defined(__BORLANDC__)
4397 /* XXX see note in do_binmode() */
4398 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
4402 PerlIO_seek(PL_rsfp, loc, 0);
4406 #ifdef PERLIO_LAYERS
4409 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
4410 else if (PL_encoding) {
4417 XPUSHs(PL_encoding);
4419 call_method("name", G_SCALAR);
4423 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
4424 Perl_form(aTHX_ ":encoding(%"SVf")",
4442 if (PL_expect == XSTATE) {
4449 if (*s == ':' && s[1] == ':') {
4452 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4453 if (!(tmp = keyword(PL_tokenbuf, len)))
4454 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
4468 LOP(OP_ACCEPT,XTERM);
4474 LOP(OP_ATAN2,XTERM);
4480 LOP(OP_BINMODE,XTERM);
4483 LOP(OP_BLESS,XTERM);
4492 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
4509 if (!PL_cryptseen) {
4510 PL_cryptseen = TRUE;
4514 LOP(OP_CRYPT,XTERM);
4517 LOP(OP_CHMOD,XTERM);
4520 LOP(OP_CHOWN,XTERM);
4523 LOP(OP_CONNECT,XTERM);
4539 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4543 PL_hints |= HINT_BLOCK_SCOPE;
4553 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
4554 LOP(OP_DBMOPEN,XTERM);
4560 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4567 yylval.ival = CopLINE(PL_curcop);
4581 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4582 UNIBRACK(OP_ENTEREVAL);
4600 case KEY_endhostent:
4606 case KEY_endservent:
4609 case KEY_endprotoent:
4620 yylval.ival = CopLINE(PL_curcop);
4622 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4624 if ((PL_bufend - p) >= 3 &&
4625 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4627 else if ((PL_bufend - p) >= 4 &&
4628 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4631 if (isIDFIRST_lazy_if(p,UTF)) {
4632 p = scan_ident(p, PL_bufend,
4633 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4637 Perl_croak(aTHX_ "Missing $ on loop variable");
4642 LOP(OP_FORMLINE,XTERM);
4648 LOP(OP_FCNTL,XTERM);
4654 LOP(OP_FLOCK,XTERM);
4663 LOP(OP_GREPSTART, XREF);
4666 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4681 case KEY_getpriority:
4682 LOP(OP_GETPRIORITY,XTERM);
4684 case KEY_getprotobyname:
4687 case KEY_getprotobynumber:
4688 LOP(OP_GPBYNUMBER,XTERM);
4690 case KEY_getprotoent:
4702 case KEY_getpeername:
4703 UNI(OP_GETPEERNAME);
4705 case KEY_gethostbyname:
4708 case KEY_gethostbyaddr:
4709 LOP(OP_GHBYADDR,XTERM);
4711 case KEY_gethostent:
4714 case KEY_getnetbyname:
4717 case KEY_getnetbyaddr:
4718 LOP(OP_GNBYADDR,XTERM);
4723 case KEY_getservbyname:
4724 LOP(OP_GSBYNAME,XTERM);
4726 case KEY_getservbyport:
4727 LOP(OP_GSBYPORT,XTERM);
4729 case KEY_getservent:
4732 case KEY_getsockname:
4733 UNI(OP_GETSOCKNAME);
4735 case KEY_getsockopt:
4736 LOP(OP_GSOCKOPT,XTERM);
4758 yylval.ival = CopLINE(PL_curcop);
4762 LOP(OP_INDEX,XTERM);
4768 LOP(OP_IOCTL,XTERM);
4780 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4812 LOP(OP_LISTEN,XTERM);
4821 s = scan_pat(s,OP_MATCH);
4822 TERM(sublex_start());
4825 LOP(OP_MAPSTART, XREF);
4828 LOP(OP_MKDIR,XTERM);
4831 LOP(OP_MSGCTL,XTERM);
4834 LOP(OP_MSGGET,XTERM);
4837 LOP(OP_MSGRCV,XTERM);
4840 LOP(OP_MSGSND,XTERM);
4846 if (isIDFIRST_lazy_if(s,UTF)) {
4847 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4848 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4850 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
4851 if (!PL_in_my_stash) {
4854 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4862 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4869 if (PL_expect != XSTATE)
4870 yyerror("\"no\" not allowed in expression");
4871 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4872 s = force_version(s, FALSE);
4877 if (*s == '(' || (s = skipspace(s), *s == '('))
4884 if (isIDFIRST_lazy_if(s,UTF)) {
4886 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
4887 for (t=d; *t && isSPACE(*t); t++) ;
4888 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
4890 && !(t[0] == '=' && t[1] == '>')
4892 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
4893 "Precedence problem: open %.*s should be open(%.*s)",
4894 d - s, s, d - s, s);
4900 yylval.ival = OP_OR;
4910 LOP(OP_OPEN_DIR,XTERM);
4913 checkcomma(s,PL_tokenbuf,"filehandle");
4917 checkcomma(s,PL_tokenbuf,"filehandle");
4936 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4940 LOP(OP_PIPE_OP,XTERM);
4943 s = scan_str(s,FALSE,FALSE);
4945 missingterm((char*)0);
4946 yylval.ival = OP_CONST;
4947 TERM(sublex_start());
4953 s = scan_str(s,FALSE,FALSE);
4955 missingterm((char*)0);
4957 if (SvCUR(PL_lex_stuff)) {
4960 d = SvPV_force(PL_lex_stuff, len);
4963 for (; isSPACE(*d) && len; --len, ++d) ;
4966 if (!warned && ckWARN(WARN_QW)) {
4967 for (; !isSPACE(*d) && len; --len, ++d) {
4969 Perl_warner(aTHX_ packWARN(WARN_QW),
4970 "Possible attempt to separate words with commas");
4973 else if (*d == '#') {
4974 Perl_warner(aTHX_ packWARN(WARN_QW),
4975 "Possible attempt to put comments in qw() list");
4981 for (; !isSPACE(*d) && len; --len, ++d) ;
4983 sv = newSVpvn(b, d-b);
4984 if (DO_UTF8(PL_lex_stuff))
4986 words = append_elem(OP_LIST, words,
4987 newSVOP(OP_CONST, 0, tokeq(sv)));
4991 PL_nextval[PL_nexttoke].opval = words;
4996 SvREFCNT_dec(PL_lex_stuff);
4997 PL_lex_stuff = Nullsv;
5003 s = scan_str(s,FALSE,FALSE);
5005 missingterm((char*)0);
5006 yylval.ival = OP_STRINGIFY;
5007 if (SvIVX(PL_lex_stuff) == '\'')
5008 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
5009 TERM(sublex_start());
5012 s = scan_pat(s,OP_QR);
5013 TERM(sublex_start());
5016 s = scan_str(s,FALSE,FALSE);
5018 missingterm((char*)0);
5019 yylval.ival = OP_BACKTICK;
5021 TERM(sublex_start());
5029 s = force_version(s, FALSE);
5031 else if (*s != 'v' || !isDIGIT(s[1])
5032 || (s = force_version(s, TRUE), *s == 'v'))
5034 *PL_tokenbuf = '\0';
5035 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5036 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
5037 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
5039 yyerror("<> should be quotes");
5047 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5051 LOP(OP_RENAME,XTERM);
5060 LOP(OP_RINDEX,XTERM);
5070 UNIDOR(OP_READLINE);
5083 LOP(OP_REVERSE,XTERM);
5086 UNIDOR(OP_READLINK);
5094 TERM(sublex_start());
5096 TOKEN(1); /* force error */
5105 LOP(OP_SELECT,XTERM);
5111 LOP(OP_SEMCTL,XTERM);
5114 LOP(OP_SEMGET,XTERM);
5117 LOP(OP_SEMOP,XTERM);
5123 LOP(OP_SETPGRP,XTERM);
5125 case KEY_setpriority:
5126 LOP(OP_SETPRIORITY,XTERM);
5128 case KEY_sethostent:
5134 case KEY_setservent:
5137 case KEY_setprotoent:
5147 LOP(OP_SEEKDIR,XTERM);
5149 case KEY_setsockopt:
5150 LOP(OP_SSOCKOPT,XTERM);
5156 LOP(OP_SHMCTL,XTERM);
5159 LOP(OP_SHMGET,XTERM);
5162 LOP(OP_SHMREAD,XTERM);
5165 LOP(OP_SHMWRITE,XTERM);
5168 LOP(OP_SHUTDOWN,XTERM);
5177 LOP(OP_SOCKET,XTERM);
5179 case KEY_socketpair:
5180 LOP(OP_SOCKPAIR,XTERM);
5183 checkcomma(s,PL_tokenbuf,"subroutine name");
5185 if (*s == ';' || *s == ')') /* probably a close */
5186 Perl_croak(aTHX_ "sort is now a reserved word");
5188 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5192 LOP(OP_SPLIT,XTERM);
5195 LOP(OP_SPRINTF,XTERM);
5198 LOP(OP_SPLICE,XTERM);
5213 LOP(OP_SUBSTR,XTERM);
5219 char tmpbuf[sizeof PL_tokenbuf];
5220 SSize_t tboffset = 0;
5221 expectation attrful;
5222 bool have_name, have_proto, bad_proto;
5223 const int key = tmp;
5227 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
5228 (*s == ':' && s[1] == ':'))
5231 attrful = XATTRBLOCK;
5232 /* remember buffer pos'n for later force_word */
5233 tboffset = s - PL_oldbufptr;
5234 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5235 if (strchr(tmpbuf, ':'))
5236 sv_setpv(PL_subname, tmpbuf);
5238 sv_setsv(PL_subname,PL_curstname);
5239 sv_catpvn(PL_subname,"::",2);
5240 sv_catpvn(PL_subname,tmpbuf,len);
5247 Perl_croak(aTHX_ "Missing name in \"my sub\"");
5248 PL_expect = XTERMBLOCK;
5249 attrful = XATTRTERM;
5250 sv_setpvn(PL_subname,"?",1);
5254 if (key == KEY_format) {
5256 PL_lex_formbrack = PL_lex_brackets + 1;
5258 (void) force_word(PL_oldbufptr + tboffset, WORD,
5263 /* Look for a prototype */
5267 s = scan_str(s,FALSE,FALSE);
5269 Perl_croak(aTHX_ "Prototype not terminated");
5270 /* strip spaces and check for bad characters */
5271 d = SvPVX(PL_lex_stuff);
5274 for (p = d; *p; ++p) {
5277 if (!strchr("$@%*;[]&\\", *p))
5282 if (bad_proto && ckWARN(WARN_SYNTAX))
5283 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5284 "Illegal character in prototype for %"SVf" : %s",
5286 SvCUR_set(PL_lex_stuff, tmp);
5294 if (*s == ':' && s[1] != ':')
5295 PL_expect = attrful;
5296 else if (*s != '{' && key == KEY_sub) {
5298 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
5300 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname);
5304 PL_nextval[PL_nexttoke].opval =
5305 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
5306 PL_lex_stuff = Nullsv;
5310 sv_setpv(PL_subname,
5311 PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
5314 (void) force_word(PL_oldbufptr + tboffset, WORD,
5323 LOP(OP_SYSTEM,XREF);
5326 LOP(OP_SYMLINK,XTERM);
5329 LOP(OP_SYSCALL,XTERM);
5332 LOP(OP_SYSOPEN,XTERM);
5335 LOP(OP_SYSSEEK,XTERM);
5338 LOP(OP_SYSREAD,XTERM);
5341 LOP(OP_SYSWRITE,XTERM);
5345 TERM(sublex_start());
5366 LOP(OP_TRUNCATE,XTERM);
5378 yylval.ival = CopLINE(PL_curcop);
5382 yylval.ival = CopLINE(PL_curcop);
5386 LOP(OP_UNLINK,XTERM);
5392 LOP(OP_UNPACK,XTERM);
5395 LOP(OP_UTIME,XTERM);
5401 LOP(OP_UNSHIFT,XTERM);
5404 if (PL_expect != XSTATE)
5405 yyerror("\"use\" not allowed in expression");
5407 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
5408 s = force_version(s, TRUE);
5409 if (*s == ';' || (s = skipspace(s), *s == ';')) {
5410 PL_nextval[PL_nexttoke].opval = Nullop;
5413 else if (*s == 'v') {
5414 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5415 s = force_version(s, FALSE);
5419 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5420 s = force_version(s, FALSE);
5432 yylval.ival = CopLINE(PL_curcop);
5436 PL_hints |= HINT_BLOCK_SCOPE;
5443 LOP(OP_WAITPID,XTERM);
5452 ctl_l[0] = toCTRL('L');
5454 gv_fetchpv(ctl_l,TRUE, SVt_PV);
5457 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
5462 if (PL_expect == XOPERATOR)
5468 yylval.ival = OP_XOR;
5473 TERM(sublex_start());
5478 #pragma segment Main
5482 S_pending_ident(pTHX)
5485 register I32 tmp = 0;
5486 /* pit holds the identifier we read and pending_ident is reset */
5487 char pit = PL_pending_ident;
5488 PL_pending_ident = 0;
5490 DEBUG_T({ PerlIO_printf(Perl_debug_log,
5491 "### Tokener saw identifier '%s'\n", PL_tokenbuf); });
5493 /* if we're in a my(), we can't allow dynamics here.
5494 $foo'bar has already been turned into $foo::bar, so
5495 just check for colons.
5497 if it's a legal name, the OP is a PADANY.
5500 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
5501 if (strchr(PL_tokenbuf,':'))
5502 yyerror(Perl_form(aTHX_ "No package name allowed for "
5503 "variable %s in \"our\"",
5505 tmp = allocmy(PL_tokenbuf);
5508 if (strchr(PL_tokenbuf,':'))
5509 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
5511 yylval.opval = newOP(OP_PADANY, 0);
5512 yylval.opval->op_targ = allocmy(PL_tokenbuf);
5518 build the ops for accesses to a my() variable.
5520 Deny my($a) or my($b) in a sort block, *if* $a or $b is
5521 then used in a comparison. This catches most, but not
5522 all cases. For instance, it catches
5523 sort { my($a); $a <=> $b }
5525 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
5526 (although why you'd do that is anyone's guess).
5529 if (!strchr(PL_tokenbuf,':')) {
5531 tmp = pad_findmy(PL_tokenbuf);
5532 if (tmp != NOT_IN_PAD) {
5533 /* might be an "our" variable" */
5534 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
5535 /* build ops for a bareword */
5536 SV *sym = newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)), 0);
5537 sv_catpvn(sym, "::", 2);
5538 sv_catpv(sym, PL_tokenbuf+1);
5539 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
5540 yylval.opval->op_private = OPpCONST_ENTERED;
5543 ? (GV_ADDMULTI | GV_ADDINEVAL)
5546 ((PL_tokenbuf[0] == '$') ? SVt_PV
5547 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5552 /* if it's a sort block and they're naming $a or $b */
5553 if (PL_last_lop_op == OP_SORT &&
5554 PL_tokenbuf[0] == '$' &&
5555 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
5558 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
5559 d < PL_bufend && *d != '\n';
5562 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
5563 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
5569 yylval.opval = newOP(OP_PADANY, 0);
5570 yylval.opval->op_targ = tmp;
5576 Whine if they've said @foo in a doublequoted string,
5577 and @foo isn't a variable we can find in the symbol
5580 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
5581 GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
5582 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
5583 && ckWARN(WARN_AMBIGUOUS))
5585 /* Downgraded from fatal to warning 20000522 mjd */
5586 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5587 "Possible unintended interpolation of %s in string",
5592 /* build ops for a bareword */
5593 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
5594 yylval.opval->op_private = OPpCONST_ENTERED;
5595 gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
5596 ((PL_tokenbuf[0] == '$') ? SVt_PV
5597 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5603 * The following code was generated by perl_keyword.pl.
5607 Perl_keyword (pTHX_ const char *name, I32 len)
5611 case 1: /* 5 tokens of length 1 */
5643 case 2: /* 18 tokens of length 2 */
5789 case 3: /* 28 tokens of length 3 */
5793 if (name[1] == 'N' &&
5856 if (name[1] == 'i' &&
5896 if (name[1] == 'o' &&
5905 if (name[1] == 'e' &&
5914 if (name[1] == 'n' &&
5923 if (name[1] == 'o' &&
5932 if (name[1] == 'a' &&
5941 if (name[1] == 'o' &&
6003 if (name[1] == 'e' &&
6035 if (name[1] == 'i' &&
6044 if (name[1] == 's' &&
6053 if (name[1] == 'e' &&
6062 if (name[1] == 'o' &&
6074 case 4: /* 40 tokens of length 4 */
6078 if (name[1] == 'O' &&
6088 if (name[1] == 'N' &&
6098 if (name[1] == 'i' &&
6108 if (name[1] == 'h' &&
6118 if (name[1] == 'u' &&
6131 if (name[2] == 'c' &&
6140 if (name[2] == 's' &&
6149 if (name[2] == 'a' &&
6185 if (name[1] == 'o' &&
6198 if (name[2] == 't' &&
6207 if (name[2] == 'o' &&
6216 if (name[2] == 't' &&
6225 if (name[2] == 'e' &&
6238 if (name[1] == 'o' &&
6251 if (name[2] == 'y' &&
6260 if (name[2] == 'l' &&
6276 if (name[2] == 's' &&
6285 if (name[2] == 'n' &&
6294 if (name[2] == 'c' &&
6307 if (name[1] == 'e' &&
6317 if (name[1] == 'p' &&
6330 if (name[2] == 'c' &&
6339 if (name[2] == 'p' &&
6348 if (name[2] == 's' &&
6364 if (name[2] == 'n' &&
6434 if (name[2] == 'r' &&
6443 if (name[2] == 'r' &&
6452 if (name[2] == 'a' &&
6468 if (name[2] == 'l' &&
6535 case 5: /* 36 tokens of length 5 */
6539 if (name[1] == 'E' &&
6550 if (name[1] == 'H' &&
6564 if (name[2] == 'a' &&
6574 if (name[2] == 'a' &&
6588 if (name[1] == 'l' &&
6605 if (name[3] == 'i' &&
6614 if (name[3] == 'o' &&
6650 if (name[2] == 'o' &&
6660 if (name[2] == 'y' &&
6674 if (name[1] == 'l' &&
6688 if (name[2] == 'n' &&
6698 if (name[2] == 'o' &&
6715 if (name[2] == 'd' &&
6725 if (name[2] == 'c' &&
6742 if (name[2] == 'c' &&
6752 if (name[2] == 't' &&
6766 if (name[1] == 'k' &&
6777 if (name[1] == 'r' &&
6791 if (name[2] == 's' &&
6801 if (name[2] == 'd' &&
6818 if (name[2] == 'm' &&
6828 if (name[2] == 'i' &&
6838 if (name[2] == 'e' &&
6848 if (name[2] == 'l' &&
6858 if (name[2] == 'a' &&
6868 if (name[2] == 'u' &&
6882 if (name[1] == 'i' &&
6896 if (name[2] == 'a' &&
6909 if (name[3] == 'e' &&
6944 if (name[2] == 'i' &&
6961 if (name[2] == 'i' &&
6971 if (name[2] == 'i' &&
6988 case 6: /* 33 tokens of length 6 */
6992 if (name[1] == 'c' &&
7007 if (name[2] == 'l' &&
7018 if (name[2] == 'r' &&
7033 if (name[1] == 'e' &&
7048 if (name[2] == 's' &&
7053 if(ckWARN_d(WARN_SYNTAX))
7054 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
7060 if (name[2] == 'i' &&
7078 if (name[2] == 'l' &&
7089 if (name[2] == 'r' &&
7104 if (name[1] == 'm' &&
7119 if (name[2] == 'n' &&
7130 if (name[2] == 's' &&
7145 if (name[1] == 's' &&
7151 if (name[4] == 't' &&
7160 if (name[4] == 'e' &&
7169 if (name[4] == 'c' &&
7178 if (name[4] == 'n' &&
7194 if (name[1] == 'r' &&
7212 if (name[3] == 'a' &&
7222 if (name[3] == 'u' &&
7236 if (name[2] == 'n' &&
7254 if (name[2] == 'a' &&
7268 if (name[3] == 'e' &&
7281 if (name[4] == 't' &&
7290 if (name[4] == 'e' &&
7312 if (name[4] == 't' &&
7321 if (name[4] == 'e' &&
7337 if (name[2] == 'c' &&
7348 if (name[2] == 'l' &&
7359 if (name[2] == 'b' &&
7370 if (name[2] == 's' &&
7393 if (name[4] == 's' &&
7402 if (name[4] == 'n' &&
7415 if (name[3] == 'a' &&
7432 if (name[1] == 'a' &&
7447 case 7: /* 28 tokens of length 7 */
7451 if (name[1] == 'E' &&
7464 if (name[1] == '_' &&
7477 if (name[1] == 'i' &&
7484 return -KEY_binmode;
7490 if (name[1] == 'o' &&
7497 return -KEY_connect;
7506 if (name[2] == 'm' &&
7512 return -KEY_dbmopen;
7518 if (name[2] == 'f' &&
7534 if (name[1] == 'o' &&
7547 if (name[1] == 'e' &&
7554 if (name[5] == 'r' &&
7557 return -KEY_getpgrp;
7563 if (name[5] == 'i' &&
7566 return -KEY_getppid;
7579 if (name[1] == 'c' &&
7586 return -KEY_lcfirst;
7592 if (name[1] == 'p' &&
7599 return -KEY_opendir;
7605 if (name[1] == 'a' &&
7623 if (name[3] == 'd' &&
7628 return -KEY_readdir;
7634 if (name[3] == 'u' &&
7645 if (name[3] == 'e' &&
7650 return -KEY_reverse;
7669 if (name[3] == 'k' &&
7674 return -KEY_seekdir;
7680 if (name[3] == 'p' &&
7685 return -KEY_setpgrp;
7695 if (name[2] == 'm' &&
7701 return -KEY_shmread;
7707 if (name[2] == 'r' &&
7713 return -KEY_sprintf;
7722 if (name[3] == 'l' &&
7727 return -KEY_symlink;
7736 if (name[4] == 'a' &&
7740 return -KEY_syscall;
7746 if (name[4] == 'p' &&
7750 return -KEY_sysopen;
7756 if (name[4] == 'e' &&
7760 return -KEY_sysread;
7766 if (name[4] == 'e' &&
7770 return -KEY_sysseek;
7788 if (name[1] == 'e' &&
7795 return -KEY_telldir;
7804 if (name[2] == 'f' &&
7810 return -KEY_ucfirst;
7816 if (name[2] == 's' &&
7822 return -KEY_unshift;
7832 if (name[1] == 'a' &&
7839 return -KEY_waitpid;
7848 case 8: /* 26 tokens of length 8 */
7852 if (name[1] == 'U' &&
7860 return KEY_AUTOLOAD;
7871 if (name[3] == 'A' &&
7877 return KEY___DATA__;
7883 if (name[3] == 'I' &&
7889 return -KEY___FILE__;
7895 if (name[3] == 'I' &&
7901 return -KEY___LINE__;
7917 if (name[2] == 'o' &&
7924 return -KEY_closedir;
7930 if (name[2] == 'n' &&
7937 return -KEY_continue;
7947 if (name[1] == 'b' &&
7955 return -KEY_dbmclose;
7961 if (name[1] == 'n' &&
7967 if (name[4] == 'r' &&
7972 return -KEY_endgrent;
7978 if (name[4] == 'w' &&
7983 return -KEY_endpwent;
7996 if (name[1] == 'o' &&
8004 return -KEY_formline;
8010 if (name[1] == 'e' &&
8021 if (name[6] == 'n' &&
8024 return -KEY_getgrent;
8030 if (name[6] == 'i' &&
8033 return -KEY_getgrgid;
8039 if (name[6] == 'a' &&
8042 return -KEY_getgrnam;
8055 if (name[4] == 'o' &&
8060 return -KEY_getlogin;
8071 if (name[6] == 'n' &&
8074 return -KEY_getpwent;
8080 if (name[6] == 'a' &&
8083 return -KEY_getpwnam;
8089 if (name[6] == 'i' &&
8092 return -KEY_getpwuid;
8112 if (name[1] == 'e' &&
8119 if (name[5] == 'i' &&
8126 return -KEY_readline;
8131 return -KEY_readlink;
8142 if (name[5] == 'i' &&
8146 return -KEY_readpipe;
8167 if (name[4] == 'r' &&
8172 return -KEY_setgrent;
8178 if (name[4] == 'w' &&
8183 return -KEY_setpwent;
8199 if (name[3] == 'w' &&
8205 return -KEY_shmwrite;
8211 if (name[3] == 't' &&
8217 return -KEY_shutdown;
8227 if (name[2] == 's' &&
8234 return -KEY_syswrite;
8244 if (name[1] == 'r' &&
8252 return -KEY_truncate;
8261 case 9: /* 8 tokens of length 9 */
8265 if (name[1] == 'n' &&
8274 return -KEY_endnetent;
8280 if (name[1] == 'e' &&
8289 return -KEY_getnetent;
8295 if (name[1] == 'o' &&
8304 return -KEY_localtime;
8310 if (name[1] == 'r' &&
8319 return KEY_prototype;
8325 if (name[1] == 'u' &&
8334 return -KEY_quotemeta;
8340 if (name[1] == 'e' &&
8349 return -KEY_rewinddir;
8355 if (name[1] == 'e' &&
8364 return -KEY_setnetent;
8370 if (name[1] == 'a' &&
8379 return -KEY_wantarray;
8388 case 10: /* 9 tokens of length 10 */
8392 if (name[1] == 'n' &&
8398 if (name[4] == 'o' &&
8405 return -KEY_endhostent;
8411 if (name[4] == 'e' &&
8418 return -KEY_endservent;
8431 if (name[1] == 'e' &&
8437 if (name[4] == 'o' &&
8444 return -KEY_gethostent;
8453 if (name[5] == 'r' &&
8459 return -KEY_getservent;
8465 if (name[5] == 'c' &&
8471 return -KEY_getsockopt;
8496 if (name[4] == 'o' &&
8503 return -KEY_sethostent;
8512 if (name[5] == 'r' &&
8518 return -KEY_setservent;
8524 if (name[5] == 'c' &&
8530 return -KEY_setsockopt;
8547 if (name[2] == 'c' &&
8556 return -KEY_socketpair;
8569 case 11: /* 8 tokens of length 11 */
8573 if (name[1] == '_' &&
8584 return -KEY___PACKAGE__;
8590 if (name[1] == 'n' &&
8601 return -KEY_endprotoent;
8607 if (name[1] == 'e' &&
8616 if (name[5] == 'e' &&
8623 return -KEY_getpeername;
8632 if (name[6] == 'o' &&
8638 return -KEY_getpriority;
8644 if (name[6] == 't' &&
8650 return -KEY_getprotoent;
8664 if (name[4] == 'o' &&
8672 return -KEY_getsockname;
8685 if (name[1] == 'e' &&
8693 if (name[6] == 'o' &&
8699 return -KEY_setpriority;
8705 if (name[6] == 't' &&
8711 return -KEY_setprotoent;
8727 case 12: /* 2 tokens of length 12 */
8728 if (name[0] == 'g' &&
8740 if (name[9] == 'd' &&
8743 { /* getnetbyaddr */
8744 return -KEY_getnetbyaddr;
8750 if (name[9] == 'a' &&
8753 { /* getnetbyname */
8754 return -KEY_getnetbyname;
8766 case 13: /* 4 tokens of length 13 */
8767 if (name[0] == 'g' &&
8774 if (name[4] == 'o' &&
8783 if (name[10] == 'd' &&
8786 { /* gethostbyaddr */
8787 return -KEY_gethostbyaddr;
8793 if (name[10] == 'a' &&
8796 { /* gethostbyname */
8797 return -KEY_gethostbyname;
8810 if (name[4] == 'e' &&
8819 if (name[10] == 'a' &&
8822 { /* getservbyname */
8823 return -KEY_getservbyname;
8829 if (name[10] == 'o' &&
8832 { /* getservbyport */
8833 return -KEY_getservbyport;
8852 case 14: /* 1 tokens of length 14 */
8853 if (name[0] == 'g' &&
8867 { /* getprotobyname */
8868 return -KEY_getprotobyname;
8873 case 16: /* 1 tokens of length 16 */
8874 if (name[0] == 'g' &&
8890 { /* getprotobynumber */
8891 return -KEY_getprotobynumber;
8905 S_checkcomma(pTHX_ register char *s, const char *name, const char *what)
8909 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
8910 if (ckWARN(WARN_SYNTAX)) {
8912 for (w = s+2; *w && level; w++) {
8919 for (; *w && isSPACE(*w); w++) ;
8920 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
8921 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
8922 "%s (...) interpreted as function",name);
8925 while (s < PL_bufend && isSPACE(*s))
8929 while (s < PL_bufend && isSPACE(*s))
8931 if (isIDFIRST_lazy_if(s,UTF)) {
8933 while (isALNUM_lazy_if(s,UTF))
8935 while (s < PL_bufend && isSPACE(*s))
8939 *s = '\0'; /* XXX If we didn't do this, we could const a lot of toke.c */
8940 kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
8944 Perl_croak(aTHX_ "No comma allowed after %s", what);
8949 /* Either returns sv, or mortalizes sv and returns a new SV*.
8950 Best used as sv=new_constant(..., sv, ...).
8951 If s, pv are NULL, calls subroutine with one argument,
8952 and type is used with error messages only. */
8955 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
8959 HV *table = GvHV(PL_hintgv); /* ^H */
8963 const char *why1, *why2, *why3;
8965 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
8968 why2 = strEQ(key,"charnames")
8969 ? "(possibly a missing \"use charnames ...\")"
8971 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
8972 (type ? type: "undef"), why2);
8974 /* This is convoluted and evil ("goto considered harmful")
8975 * but I do not understand the intricacies of all the different
8976 * failure modes of %^H in here. The goal here is to make
8977 * the most probable error message user-friendly. --jhi */
8982 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
8983 (type ? type: "undef"), why1, why2, why3);
8985 yyerror(SvPVX(msg));
8989 cvp = hv_fetch(table, key, strlen(key), FALSE);
8990 if (!cvp || !SvOK(*cvp)) {
8993 why3 = "} is not defined";
8996 sv_2mortal(sv); /* Parent created it permanently */
8999 pv = sv_2mortal(newSVpvn(s, len));
9001 typesv = sv_2mortal(newSVpv(type, 0));
9003 typesv = &PL_sv_undef;
9005 PUSHSTACKi(PERLSI_OVERLOAD);
9017 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
9021 /* Check the eval first */
9022 if (!PL_in_eval && SvTRUE(ERRSV)) {
9024 sv_catpv(ERRSV, "Propagated");
9025 yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */
9027 res = SvREFCNT_inc(sv);
9031 (void)SvREFCNT_inc(res);
9040 why1 = "Call to &{$^H{";
9042 why3 = "}} did not return a defined value";
9050 /* Returns a NUL terminated string, with the length of the string written to
9054 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
9056 register char *d = dest;
9057 register char *e = d + destlen - 3; /* two-character token, ending NUL */
9060 Perl_croak(aTHX_ ident_too_long);
9061 if (isALNUM(*s)) /* UTF handled below */
9063 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
9068 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
9072 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9073 char *t = s + UTF8SKIP(s);
9074 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9076 if (d + (t - s) > e)
9077 Perl_croak(aTHX_ ident_too_long);
9078 Copy(s, d, t - s, char);
9091 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
9101 e = d + destlen - 3; /* two-character token, ending NUL */
9103 while (isDIGIT(*s)) {
9105 Perl_croak(aTHX_ ident_too_long);
9112 Perl_croak(aTHX_ ident_too_long);
9113 if (isALNUM(*s)) /* UTF handled below */
9115 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
9120 else if (*s == ':' && s[1] == ':') {
9124 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9125 char *t = s + UTF8SKIP(s);
9126 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9128 if (d + (t - s) > e)
9129 Perl_croak(aTHX_ ident_too_long);
9130 Copy(s, d, t - s, char);
9141 if (PL_lex_state != LEX_NORMAL)
9142 PL_lex_state = LEX_INTERPENDMAYBE;
9145 if (*s == '$' && s[1] &&
9146 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
9159 if (*d == '^' && *s && isCONTROLVAR(*s)) {
9164 if (isSPACE(s[-1])) {
9166 const char ch = *s++;
9167 if (!SPACE_OR_TAB(ch)) {
9173 if (isIDFIRST_lazy_if(d,UTF)) {
9177 while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') {
9179 while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e))
9182 Copy(s, d, e - s, char);
9187 while ((isALNUM(*s) || *s == ':') && d < e)
9190 Perl_croak(aTHX_ ident_too_long);
9193 while (s < send && SPACE_OR_TAB(*s)) s++;
9194 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
9195 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
9196 const char *brack = *s == '[' ? "[...]" : "{...}";
9197 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9198 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
9199 funny, dest, brack, funny, dest, brack);
9202 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
9206 /* Handle extended ${^Foo} variables
9207 * 1999-02-27 mjd-perl-patch@plover.com */
9208 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
9212 while (isALNUM(*s) && d < e) {
9216 Perl_croak(aTHX_ ident_too_long);
9221 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
9222 PL_lex_state = LEX_INTERPEND;
9227 if (PL_lex_state == LEX_NORMAL) {
9228 if (ckWARN(WARN_AMBIGUOUS) &&
9229 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
9231 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9232 "Ambiguous use of %c{%s} resolved to %c%s",
9233 funny, dest, funny, dest);
9238 s = bracket; /* let the parser handle it */
9242 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
9243 PL_lex_state = LEX_INTERPEND;
9248 Perl_pmflag(pTHX_ U32* pmfl, int ch)
9253 *pmfl |= PMf_GLOBAL;
9255 *pmfl |= PMf_CONTINUE;
9259 *pmfl |= PMf_MULTILINE;
9261 *pmfl |= PMf_SINGLELINE;
9263 *pmfl |= PMf_EXTENDED;
9267 S_scan_pat(pTHX_ char *start, I32 type)
9270 char *s = scan_str(start,FALSE,FALSE);
9273 Perl_croak(aTHX_ "Search pattern not terminated");
9275 pm = (PMOP*)newPMOP(type, 0);
9276 if (PL_multi_open == '?')
9277 pm->op_pmflags |= PMf_ONCE;
9279 while (*s && strchr("iomsx", *s))
9280 pmflag(&pm->op_pmflags,*s++);
9283 while (*s && strchr("iogcmsx", *s))
9284 pmflag(&pm->op_pmflags,*s++);
9286 /* issue a warning if /c is specified,but /g is not */
9287 if (ckWARN(WARN_REGEXP) &&
9288 (pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
9290 Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_without_g);
9293 pm->op_pmpermflags = pm->op_pmflags;
9295 PL_lex_op = (OP*)pm;
9296 yylval.ival = OP_MATCH;
9301 S_scan_subst(pTHX_ char *start)
9309 yylval.ival = OP_NULL;
9311 s = scan_str(start,FALSE,FALSE);
9314 Perl_croak(aTHX_ "Substitution pattern not terminated");
9316 if (s[-1] == PL_multi_open)
9319 first_start = PL_multi_start;
9320 s = scan_str(s,FALSE,FALSE);
9323 SvREFCNT_dec(PL_lex_stuff);
9324 PL_lex_stuff = Nullsv;
9326 Perl_croak(aTHX_ "Substitution replacement not terminated");
9328 PL_multi_start = first_start; /* so whole substitution is taken together */
9330 pm = (PMOP*)newPMOP(OP_SUBST, 0);
9336 else if (strchr("iogcmsx", *s))
9337 pmflag(&pm->op_pmflags,*s++);
9342 /* /c is not meaningful with s/// */
9343 if (ckWARN(WARN_REGEXP) && (pm->op_pmflags & PMf_CONTINUE))
9345 Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_in_subst);
9350 PL_sublex_info.super_bufptr = s;
9351 PL_sublex_info.super_bufend = PL_bufend;
9353 pm->op_pmflags |= PMf_EVAL;
9354 repl = newSVpvn("",0);
9356 sv_catpv(repl, es ? "eval " : "do ");
9357 sv_catpvn(repl, "{ ", 2);
9358 sv_catsv(repl, PL_lex_repl);
9359 sv_catpvn(repl, " };", 2);
9361 SvREFCNT_dec(PL_lex_repl);
9365 pm->op_pmpermflags = pm->op_pmflags;
9366 PL_lex_op = (OP*)pm;
9367 yylval.ival = OP_SUBST;
9372 S_scan_trans(pTHX_ char *start)
9381 yylval.ival = OP_NULL;
9383 s = scan_str(start,FALSE,FALSE);
9385 Perl_croak(aTHX_ "Transliteration pattern not terminated");
9386 if (s[-1] == PL_multi_open)
9389 s = scan_str(s,FALSE,FALSE);
9392 SvREFCNT_dec(PL_lex_stuff);
9393 PL_lex_stuff = Nullsv;
9395 Perl_croak(aTHX_ "Transliteration replacement not terminated");
9398 complement = del = squash = 0;
9402 complement = OPpTRANS_COMPLEMENT;
9405 del = OPpTRANS_DELETE;
9408 squash = OPpTRANS_SQUASH;
9417 New(803, tbl, complement&&!del?258:256, short);
9418 o = newPVOP(OP_TRANS, 0, (char*)tbl);
9419 o->op_private &= ~OPpTRANS_ALL;
9420 o->op_private |= del|squash|complement|
9421 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
9422 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
9425 yylval.ival = OP_TRANS;
9430 S_scan_heredoc(pTHX_ register char *s)
9433 I32 op_type = OP_SCALAR;
9437 const char newline[] = "\n";
9438 const char *found_newline;
9442 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
9446 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
9449 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
9450 if (*peek == '`' || *peek == '\'' || *peek =='"') {
9453 s = delimcpy(d, e, s, PL_bufend, term, &len);
9463 if (!isALNUM_lazy_if(s,UTF))
9464 deprecate_old("bare << to mean <<\"\"");
9465 for (; isALNUM_lazy_if(s,UTF); s++) {
9470 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
9471 Perl_croak(aTHX_ "Delimiter for here document is too long");
9474 len = d - PL_tokenbuf;
9475 #ifndef PERL_STRICT_CR
9476 d = strchr(s, '\r');
9480 while (s < PL_bufend) {
9486 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
9495 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
9499 if ( outer || !(found_newline = ninstr(s,PL_bufend,newline,newline+1)) ) {
9500 herewas = newSVpvn(s,PL_bufend-s);
9504 herewas = newSVpvn(s,found_newline-s);
9506 s += SvCUR(herewas);
9508 tmpstr = NEWSV(87,79);
9509 sv_upgrade(tmpstr, SVt_PVIV);
9512 SvIV_set(tmpstr, -1);
9514 else if (term == '`') {
9515 op_type = OP_BACKTICK;
9516 SvIV_set(tmpstr, '\\');
9520 PL_multi_start = CopLINE(PL_curcop);
9521 PL_multi_open = PL_multi_close = '<';
9522 term = *PL_tokenbuf;
9523 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
9524 char *bufptr = PL_sublex_info.super_bufptr;
9525 char *bufend = PL_sublex_info.super_bufend;
9526 char *olds = s - SvCUR(herewas);
9527 s = strchr(bufptr, '\n');
9531 while (s < bufend &&
9532 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9534 CopLINE_inc(PL_curcop);
9537 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9538 missingterm(PL_tokenbuf);
9540 sv_setpvn(herewas,bufptr,d-bufptr+1);
9541 sv_setpvn(tmpstr,d+1,s-d);
9543 sv_catpvn(herewas,s,bufend-s);
9544 Copy(SvPVX(herewas),bufptr,SvCUR(herewas) + 1,char);
9551 while (s < PL_bufend &&
9552 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9554 CopLINE_inc(PL_curcop);
9556 if (s >= PL_bufend) {
9557 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9558 missingterm(PL_tokenbuf);
9560 sv_setpvn(tmpstr,d+1,s-d);
9562 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
9564 sv_catpvn(herewas,s,PL_bufend-s);
9565 sv_setsv(PL_linestr,herewas);
9566 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
9567 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9568 PL_last_lop = PL_last_uni = Nullch;
9571 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
9572 while (s >= PL_bufend) { /* multiple line string? */
9574 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
9575 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9576 missingterm(PL_tokenbuf);
9578 CopLINE_inc(PL_curcop);
9579 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9580 PL_last_lop = PL_last_uni = Nullch;
9581 #ifndef PERL_STRICT_CR
9582 if (PL_bufend - PL_linestart >= 2) {
9583 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
9584 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
9586 PL_bufend[-2] = '\n';
9588 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
9590 else if (PL_bufend[-1] == '\r')
9591 PL_bufend[-1] = '\n';
9593 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
9594 PL_bufend[-1] = '\n';
9596 if (PERLDB_LINE && PL_curstash != PL_debstash) {
9597 SV *sv = NEWSV(88,0);
9599 sv_upgrade(sv, SVt_PVMG);
9600 sv_setsv(sv,PL_linestr);
9603 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
9605 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
9606 STRLEN off = PL_bufend - 1 - SvPVX(PL_linestr);
9607 *(SvPVX(PL_linestr) + off ) = ' ';
9608 sv_catsv(PL_linestr,herewas);
9609 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9610 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
9614 sv_catsv(tmpstr,PL_linestr);
9619 PL_multi_end = CopLINE(PL_curcop);
9620 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
9621 SvPV_shrink_to_cur(tmpstr);
9623 SvREFCNT_dec(herewas);
9625 if (UTF && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr)))
9627 else if (PL_encoding)
9628 sv_recode_to_utf8(tmpstr, PL_encoding);
9630 PL_lex_stuff = tmpstr;
9631 yylval.ival = op_type;
9636 takes: current position in input buffer
9637 returns: new position in input buffer
9638 side-effects: yylval and lex_op are set.
9643 <FH> read from filehandle
9644 <pkg::FH> read from package qualified filehandle
9645 <pkg'FH> read from package qualified filehandle
9646 <$fh> read from filehandle in $fh
9652 S_scan_inputsymbol(pTHX_ char *start)
9654 register char *s = start; /* current position in buffer */
9660 d = PL_tokenbuf; /* start of temp holding space */
9661 e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
9662 end = strchr(s, '\n');
9665 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
9667 /* die if we didn't have space for the contents of the <>,
9668 or if it didn't end, or if we see a newline
9671 if (len >= sizeof PL_tokenbuf)
9672 Perl_croak(aTHX_ "Excessively long <> operator");
9674 Perl_croak(aTHX_ "Unterminated <> operator");
9679 Remember, only scalar variables are interpreted as filehandles by
9680 this code. Anything more complex (e.g., <$fh{$num}>) will be
9681 treated as a glob() call.
9682 This code makes use of the fact that except for the $ at the front,
9683 a scalar variable and a filehandle look the same.
9685 if (*d == '$' && d[1]) d++;
9687 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
9688 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
9691 /* If we've tried to read what we allow filehandles to look like, and
9692 there's still text left, then it must be a glob() and not a getline.
9693 Use scan_str to pull out the stuff between the <> and treat it
9694 as nothing more than a string.
9697 if (d - PL_tokenbuf != len) {
9698 yylval.ival = OP_GLOB;
9700 s = scan_str(start,FALSE,FALSE);
9702 Perl_croak(aTHX_ "Glob not terminated");
9706 bool readline_overriden = FALSE;
9707 GV *gv_readline = Nullgv;
9709 /* we're in a filehandle read situation */
9712 /* turn <> into <ARGV> */
9714 Copy("ARGV",d,5,char);
9716 /* Check whether readline() is overriden */
9717 if (((gv_readline = gv_fetchpv("readline", FALSE, SVt_PVCV))
9718 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
9720 ((gvp = (GV**)hv_fetch(PL_globalstash, "readline", 8, FALSE))
9721 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
9722 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
9723 readline_overriden = TRUE;
9725 /* if <$fh>, create the ops to turn the variable into a
9731 /* try to find it in the pad for this block, otherwise find
9732 add symbol table ops
9734 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
9735 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
9736 SV *sym = sv_2mortal(
9737 newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)),0));
9738 sv_catpvn(sym, "::", 2);
9744 OP *o = newOP(OP_PADSV, 0);
9746 PL_lex_op = readline_overriden
9747 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9748 append_elem(OP_LIST, o,
9749 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
9750 : (OP*)newUNOP(OP_READLINE, 0, o);
9759 ? (GV_ADDMULTI | GV_ADDINEVAL)
9762 PL_lex_op = readline_overriden
9763 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9764 append_elem(OP_LIST,
9765 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
9766 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9767 : (OP*)newUNOP(OP_READLINE, 0,
9768 newUNOP(OP_RV2SV, 0,
9769 newGVOP(OP_GV, 0, gv)));
9771 if (!readline_overriden)
9772 PL_lex_op->op_flags |= OPf_SPECIAL;
9773 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
9774 yylval.ival = OP_NULL;
9777 /* If it's none of the above, it must be a literal filehandle
9778 (<Foo::BAR> or <FOO>) so build a simple readline OP */
9780 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
9781 PL_lex_op = readline_overriden
9782 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9783 append_elem(OP_LIST,
9784 newGVOP(OP_GV, 0, gv),
9785 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9786 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
9787 yylval.ival = OP_NULL;
9796 takes: start position in buffer
9797 keep_quoted preserve \ on the embedded delimiter(s)
9798 keep_delims preserve the delimiters around the string
9799 returns: position to continue reading from buffer
9800 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
9801 updates the read buffer.
9803 This subroutine pulls a string out of the input. It is called for:
9804 q single quotes q(literal text)
9805 ' single quotes 'literal text'
9806 qq double quotes qq(interpolate $here please)
9807 " double quotes "interpolate $here please"
9808 qx backticks qx(/bin/ls -l)
9809 ` backticks `/bin/ls -l`
9810 qw quote words @EXPORT_OK = qw( func() $spam )
9811 m// regexp match m/this/
9812 s/// regexp substitute s/this/that/
9813 tr/// string transliterate tr/this/that/
9814 y/// string transliterate y/this/that/
9815 ($*@) sub prototypes sub foo ($)
9816 (stuff) sub attr parameters sub foo : attr(stuff)
9817 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
9819 In most of these cases (all but <>, patterns and transliterate)
9820 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
9821 calls scan_str(). s/// makes yylex() call scan_subst() which calls
9822 scan_str(). tr/// and y/// make yylex() call scan_trans() which
9825 It skips whitespace before the string starts, and treats the first
9826 character as the delimiter. If the delimiter is one of ([{< then
9827 the corresponding "close" character )]}> is used as the closing
9828 delimiter. It allows quoting of delimiters, and if the string has
9829 balanced delimiters ([{<>}]) it allows nesting.
9831 On success, the SV with the resulting string is put into lex_stuff or,
9832 if that is already non-NULL, into lex_repl. The second case occurs only
9833 when parsing the RHS of the special constructs s/// and tr/// (y///).
9834 For convenience, the terminating delimiter character is stuffed into
9839 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
9841 SV *sv; /* scalar value: string */
9842 char *tmps; /* temp string, used for delimiter matching */
9843 register char *s = start; /* current position in the buffer */
9844 register char term; /* terminating character */
9845 register char *to; /* current position in the sv's data */
9846 I32 brackets = 1; /* bracket nesting level */
9847 bool has_utf8 = FALSE; /* is there any utf8 content? */
9848 I32 termcode; /* terminating char. code */
9849 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
9850 STRLEN termlen; /* length of terminating string */
9851 char *last = NULL; /* last position for nesting bracket */
9853 /* skip space before the delimiter */
9857 /* mark where we are, in case we need to report errors */
9860 /* after skipping whitespace, the next character is the terminator */
9863 termcode = termstr[0] = term;
9867 termcode = utf8_to_uvchr((U8*)s, &termlen);
9868 Copy(s, termstr, termlen, U8);
9869 if (!UTF8_IS_INVARIANT(term))
9873 /* mark where we are */
9874 PL_multi_start = CopLINE(PL_curcop);
9875 PL_multi_open = term;
9877 /* find corresponding closing delimiter */
9878 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
9879 termcode = termstr[0] = term = tmps[5];
9881 PL_multi_close = term;
9883 /* create a new SV to hold the contents. 87 is leak category, I'm
9884 assuming. 79 is the SV's initial length. What a random number. */
9886 sv_upgrade(sv, SVt_PVIV);
9887 SvIV_set(sv, termcode);
9888 (void)SvPOK_only(sv); /* validate pointer */
9890 /* move past delimiter and try to read a complete string */
9892 sv_catpvn(sv, s, termlen);
9895 if (PL_encoding && !UTF) {
9899 int offset = s - SvPVX(PL_linestr);
9900 bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
9901 &offset, (char*)termstr, termlen);
9902 char *ns = SvPVX(PL_linestr) + offset;
9903 char *svlast = SvEND(sv) - 1;
9905 for (; s < ns; s++) {
9906 if (*s == '\n' && !PL_rsfp)
9907 CopLINE_inc(PL_curcop);
9910 goto read_more_line;
9912 /* handle quoted delimiters */
9913 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
9915 for (t = svlast-2; t >= SvPVX(sv) && *t == '\\';)
9917 if ((svlast-1 - t) % 2) {
9921 SvCUR_set(sv, SvCUR(sv) - 1);
9926 if (PL_multi_open == PL_multi_close) {
9934 for (t = w = last; t < svlast; w++, t++) {
9935 /* At here, all closes are "was quoted" one,
9936 so we don't check PL_multi_close. */
9938 if (!keep_quoted && *(t+1) == PL_multi_open)
9943 else if (*t == PL_multi_open)
9951 SvCUR_set(sv, w - SvPVX(sv));
9954 if (--brackets <= 0)
9960 SvCUR_set(sv, SvCUR(sv) - 1);
9966 /* extend sv if need be */
9967 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
9968 /* set 'to' to the next character in the sv's string */
9969 to = SvPVX(sv)+SvCUR(sv);
9971 /* if open delimiter is the close delimiter read unbridle */
9972 if (PL_multi_open == PL_multi_close) {
9973 for (; s < PL_bufend; s++,to++) {
9974 /* embedded newlines increment the current line number */
9975 if (*s == '\n' && !PL_rsfp)
9976 CopLINE_inc(PL_curcop);
9977 /* handle quoted delimiters */
9978 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
9979 if (!keep_quoted && s[1] == term)
9981 /* any other quotes are simply copied straight through */
9985 /* terminate when run out of buffer (the for() condition), or
9986 have found the terminator */
9987 else if (*s == term) {
9990 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
9993 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
9999 /* if the terminator isn't the same as the start character (e.g.,
10000 matched brackets), we have to allow more in the quoting, and
10001 be prepared for nested brackets.
10004 /* read until we run out of string, or we find the terminator */
10005 for (; s < PL_bufend; s++,to++) {
10006 /* embedded newlines increment the line count */
10007 if (*s == '\n' && !PL_rsfp)
10008 CopLINE_inc(PL_curcop);
10009 /* backslashes can escape the open or closing characters */
10010 if (*s == '\\' && s+1 < PL_bufend) {
10011 if (!keep_quoted &&
10012 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
10017 /* allow nested opens and closes */
10018 else if (*s == PL_multi_close && --brackets <= 0)
10020 else if (*s == PL_multi_open)
10022 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
10027 /* terminate the copied string and update the sv's end-of-string */
10029 SvCUR_set(sv, to - SvPVX(sv));
10032 * this next chunk reads more into the buffer if we're not done yet
10036 break; /* handle case where we are done yet :-) */
10038 #ifndef PERL_STRICT_CR
10039 if (to - SvPVX(sv) >= 2) {
10040 if ((to[-2] == '\r' && to[-1] == '\n') ||
10041 (to[-2] == '\n' && to[-1] == '\r'))
10045 SvCUR_set(sv, to - SvPVX(sv));
10047 else if (to[-1] == '\r')
10050 else if (to - SvPVX(sv) == 1 && to[-1] == '\r')
10055 /* if we're out of file, or a read fails, bail and reset the current
10056 line marker so we can report where the unterminated string began
10059 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
10061 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10064 /* we read a line, so increment our line counter */
10065 CopLINE_inc(PL_curcop);
10067 /* update debugger info */
10068 if (PERLDB_LINE && PL_curstash != PL_debstash) {
10069 SV *sv = NEWSV(88,0);
10071 sv_upgrade(sv, SVt_PVMG);
10072 sv_setsv(sv,PL_linestr);
10073 (void)SvIOK_on(sv);
10075 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
10078 /* having changed the buffer, we must update PL_bufend */
10079 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10080 PL_last_lop = PL_last_uni = Nullch;
10083 /* at this point, we have successfully read the delimited string */
10085 if (!PL_encoding || UTF) {
10087 sv_catpvn(sv, s, termlen);
10090 if (has_utf8 || PL_encoding)
10093 PL_multi_end = CopLINE(PL_curcop);
10095 /* if we allocated too much space, give some back */
10096 if (SvCUR(sv) + 5 < SvLEN(sv)) {
10097 SvLEN_set(sv, SvCUR(sv) + 1);
10098 SvPV_renew(sv, SvLEN(sv));
10101 /* decide whether this is the first or second quoted string we've read
10114 takes: pointer to position in buffer
10115 returns: pointer to new position in buffer
10116 side-effects: builds ops for the constant in yylval.op
10118 Read a number in any of the formats that Perl accepts:
10120 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
10121 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
10124 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
10126 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
10129 If it reads a number without a decimal point or an exponent, it will
10130 try converting the number to an integer and see if it can do so
10131 without loss of precision.
10135 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
10137 register const char *s = start; /* current position in buffer */
10138 register char *d; /* destination in temp buffer */
10139 register char *e; /* end of temp buffer */
10140 NV nv; /* number read, as a double */
10141 SV *sv = Nullsv; /* place to put the converted number */
10142 bool floatit; /* boolean: int or float? */
10143 const char *lastub = 0; /* position of last underbar */
10144 static char const number_too_long[] = "Number too long";
10146 /* We use the first character to decide what type of number this is */
10150 Perl_croak(aTHX_ "panic: scan_num");
10152 /* if it starts with a 0, it could be an octal number, a decimal in
10153 0.13 disguise, or a hexadecimal number, or a binary number. */
10157 u holds the "number so far"
10158 shift the power of 2 of the base
10159 (hex == 4, octal == 3, binary == 1)
10160 overflowed was the number more than we can hold?
10162 Shift is used when we add a digit. It also serves as an "are
10163 we in octal/hex/binary?" indicator to disallow hex characters
10164 when in octal mode.
10169 bool overflowed = FALSE;
10170 bool just_zero = TRUE; /* just plain 0 or binary number? */
10171 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
10172 static const char* const bases[5] =
10173 { "", "binary", "", "octal", "hexadecimal" };
10174 static const char* const Bases[5] =
10175 { "", "Binary", "", "Octal", "Hexadecimal" };
10176 static const char* const maxima[5] =
10178 "0b11111111111111111111111111111111",
10182 const char *base, *Base, *max;
10184 /* check for hex */
10189 } else if (s[1] == 'b') {
10194 /* check for a decimal in disguise */
10195 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
10197 /* so it must be octal */
10204 if (ckWARN(WARN_SYNTAX))
10205 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10206 "Misplaced _ in number");
10210 base = bases[shift];
10211 Base = Bases[shift];
10212 max = maxima[shift];
10214 /* read the rest of the number */
10216 /* x is used in the overflow test,
10217 b is the digit we're adding on. */
10222 /* if we don't mention it, we're done */
10226 /* _ are ignored -- but warned about if consecutive */
10228 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10229 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10230 "Misplaced _ in number");
10234 /* 8 and 9 are not octal */
10235 case '8': case '9':
10237 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
10241 case '2': case '3': case '4':
10242 case '5': case '6': case '7':
10244 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
10247 case '0': case '1':
10248 b = *s++ & 15; /* ASCII digit -> value of digit */
10252 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
10253 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
10254 /* make sure they said 0x */
10257 b = (*s++ & 7) + 9;
10259 /* Prepare to put the digit we have onto the end
10260 of the number so far. We check for overflows.
10266 x = u << shift; /* make room for the digit */
10268 if ((x >> shift) != u
10269 && !(PL_hints & HINT_NEW_BINARY)) {
10272 if (ckWARN_d(WARN_OVERFLOW))
10273 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
10274 "Integer overflow in %s number",
10277 u = x | b; /* add the digit to the end */
10280 n *= nvshift[shift];
10281 /* If an NV has not enough bits in its
10282 * mantissa to represent an UV this summing of
10283 * small low-order numbers is a waste of time
10284 * (because the NV cannot preserve the
10285 * low-order bits anyway): we could just
10286 * remember when did we overflow and in the
10287 * end just multiply n by the right
10295 /* if we get here, we had success: make a scalar value from
10300 /* final misplaced underbar check */
10301 if (s[-1] == '_') {
10302 if (ckWARN(WARN_SYNTAX))
10303 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10308 if (ckWARN(WARN_PORTABLE) && n > 4294967295.0)
10309 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10310 "%s number > %s non-portable",
10316 if (ckWARN(WARN_PORTABLE) && u > 0xffffffff)
10317 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10318 "%s number > %s non-portable",
10323 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
10324 sv = new_constant(start, s - start, "integer",
10326 else if (PL_hints & HINT_NEW_BINARY)
10327 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
10332 handle decimal numbers.
10333 we're also sent here when we read a 0 as the first digit
10335 case '1': case '2': case '3': case '4': case '5':
10336 case '6': case '7': case '8': case '9': case '.':
10339 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
10342 /* read next group of digits and _ and copy into d */
10343 while (isDIGIT(*s) || *s == '_') {
10344 /* skip underscores, checking for misplaced ones
10348 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10349 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10350 "Misplaced _ in number");
10354 /* check for end of fixed-length buffer */
10356 Perl_croak(aTHX_ number_too_long);
10357 /* if we're ok, copy the character */
10362 /* final misplaced underbar check */
10363 if (lastub && s == lastub + 1) {
10364 if (ckWARN(WARN_SYNTAX))
10365 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10368 /* read a decimal portion if there is one. avoid
10369 3..5 being interpreted as the number 3. followed
10372 if (*s == '.' && s[1] != '.') {
10377 if (ckWARN(WARN_SYNTAX))
10378 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10379 "Misplaced _ in number");
10383 /* copy, ignoring underbars, until we run out of digits.
10385 for (; isDIGIT(*s) || *s == '_'; s++) {
10386 /* fixed length buffer check */
10388 Perl_croak(aTHX_ number_too_long);
10390 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10391 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10392 "Misplaced _ in number");
10398 /* fractional part ending in underbar? */
10399 if (s[-1] == '_') {
10400 if (ckWARN(WARN_SYNTAX))
10401 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10402 "Misplaced _ in number");
10404 if (*s == '.' && isDIGIT(s[1])) {
10405 /* oops, it's really a v-string, but without the "v" */
10411 /* read exponent part, if present */
10412 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
10416 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
10417 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
10419 /* stray preinitial _ */
10421 if (ckWARN(WARN_SYNTAX))
10422 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10423 "Misplaced _ in number");
10427 /* allow positive or negative exponent */
10428 if (*s == '+' || *s == '-')
10431 /* stray initial _ */
10433 if (ckWARN(WARN_SYNTAX))
10434 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10435 "Misplaced _ in number");
10439 /* read digits of exponent */
10440 while (isDIGIT(*s) || *s == '_') {
10443 Perl_croak(aTHX_ number_too_long);
10447 if (ckWARN(WARN_SYNTAX) &&
10448 ((lastub && s == lastub + 1) ||
10449 (!isDIGIT(s[1]) && s[1] != '_')))
10450 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10451 "Misplaced _ in number");
10458 /* make an sv from the string */
10462 We try to do an integer conversion first if no characters
10463 indicating "float" have been found.
10468 int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
10470 if (flags == IS_NUMBER_IN_UV) {
10472 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
10475 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
10476 if (uv <= (UV) IV_MIN)
10477 sv_setiv(sv, -(IV)uv);
10484 /* terminate the string */
10486 nv = Atof(PL_tokenbuf);
10490 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
10491 (PL_hints & HINT_NEW_INTEGER) )
10492 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
10493 (floatit ? "float" : "integer"),
10497 /* if it starts with a v, it could be a v-string */
10500 sv = NEWSV(92,5); /* preallocate storage space */
10501 s = scan_vstring(s,sv);
10505 /* make the op for the constant and return */
10508 lvalp->opval = newSVOP(OP_CONST, 0, sv);
10510 lvalp->opval = Nullop;
10516 S_scan_formline(pTHX_ register char *s)
10518 register char *eol;
10520 SV *stuff = newSVpvn("",0);
10521 bool needargs = FALSE;
10522 bool eofmt = FALSE;
10524 while (!needargs) {
10527 #ifdef PERL_STRICT_CR
10528 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
10530 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
10532 if (*t == '\n' || t == PL_bufend) {
10537 if (PL_in_eval && !PL_rsfp) {
10538 eol = (char *) memchr(s,'\n',PL_bufend-s);
10543 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10545 for (t = s; t < eol; t++) {
10546 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
10548 goto enough; /* ~~ must be first line in formline */
10550 if (*t == '@' || *t == '^')
10554 sv_catpvn(stuff, s, eol-s);
10555 #ifndef PERL_STRICT_CR
10556 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
10557 char *end = SvPVX(stuff) + SvCUR(stuff);
10560 SvCUR_set(stuff, SvCUR(stuff) - 1);
10569 s = filter_gets(PL_linestr, PL_rsfp, 0);
10570 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
10571 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
10572 PL_last_lop = PL_last_uni = Nullch;
10581 if (SvCUR(stuff)) {
10584 PL_lex_state = LEX_NORMAL;
10585 PL_nextval[PL_nexttoke].ival = 0;
10589 PL_lex_state = LEX_FORMLINE;
10591 if (UTF && is_utf8_string((U8*)SvPVX(stuff), SvCUR(stuff)))
10593 else if (PL_encoding)
10594 sv_recode_to_utf8(stuff, PL_encoding);
10596 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
10598 PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
10602 SvREFCNT_dec(stuff);
10604 PL_lex_formbrack = 0;
10615 PL_cshlen = strlen(PL_cshname);
10620 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
10622 I32 oldsavestack_ix = PL_savestack_ix;
10623 CV* outsidecv = PL_compcv;
10626 assert(SvTYPE(PL_compcv) == SVt_PVCV);
10628 SAVEI32(PL_subline);
10629 save_item(PL_subname);
10630 SAVESPTR(PL_compcv);
10632 PL_compcv = (CV*)NEWSV(1104,0);
10633 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
10634 CvFLAGS(PL_compcv) |= flags;
10636 PL_subline = CopLINE(PL_curcop);
10637 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
10638 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
10639 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
10641 return oldsavestack_ix;
10645 #pragma segment Perl_yylex
10648 Perl_yywarn(pTHX_ const char *s)
10650 PL_in_eval |= EVAL_WARNONLY;
10652 PL_in_eval &= ~EVAL_WARNONLY;
10657 Perl_yyerror(pTHX_ const char *s)
10659 const char *where = NULL;
10660 const char *context = NULL;
10664 if (!yychar || (yychar == ';' && !PL_rsfp))
10666 else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 &&
10667 PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) {
10670 The code below is removed for NetWare because it abends/crashes on NetWare
10671 when the script has error such as not having the closing quotes like:
10672 if ($var eq "value)
10673 Checking of white spaces is anyway done in NetWare code.
10676 while (isSPACE(*PL_oldoldbufptr))
10679 context = PL_oldoldbufptr;
10680 contlen = PL_bufptr - PL_oldoldbufptr;
10682 else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 &&
10683 PL_oldbufptr != PL_bufptr) {
10686 The code below is removed for NetWare because it abends/crashes on NetWare
10687 when the script has error such as not having the closing quotes like:
10688 if ($var eq "value)
10689 Checking of white spaces is anyway done in NetWare code.
10692 while (isSPACE(*PL_oldbufptr))
10695 context = PL_oldbufptr;
10696 contlen = PL_bufptr - PL_oldbufptr;
10698 else if (yychar > 255)
10699 where = "next token ???";
10700 else if (yychar == -2) { /* YYEMPTY */
10701 if (PL_lex_state == LEX_NORMAL ||
10702 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
10703 where = "at end of line";
10704 else if (PL_lex_inpat)
10705 where = "within pattern";
10707 where = "within string";
10710 SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
10712 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
10713 else if (isPRINT_LC(yychar))
10714 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
10716 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
10717 where = SvPVX(where_sv);
10719 msg = sv_2mortal(newSVpv(s, 0));
10720 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
10721 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
10723 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
10725 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
10726 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
10727 Perl_sv_catpvf(aTHX_ msg,
10728 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
10729 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
10732 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
10733 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg);
10736 if (PL_error_count >= 10) {
10737 if (PL_in_eval && SvCUR(ERRSV))
10738 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
10739 ERRSV, OutCopFILE(PL_curcop));
10741 Perl_croak(aTHX_ "%s has too many errors.\n",
10742 OutCopFILE(PL_curcop));
10745 PL_in_my_stash = Nullhv;
10749 #pragma segment Main
10753 S_swallow_bom(pTHX_ U8 *s)
10755 const STRLEN slen = SvCUR(PL_linestr);
10758 if (s[1] == 0xFE) {
10759 /* UTF-16 little-endian? (or UTF32-LE?) */
10760 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
10761 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
10762 #ifndef PERL_NO_UTF16_FILTER
10763 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
10766 if (PL_bufend > (char*)s) {
10770 filter_add(utf16rev_textfilter, NULL);
10771 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10772 utf16_to_utf8_reversed(s, news,
10773 PL_bufend - (char*)s - 1,
10775 sv_setpvn(PL_linestr, (const char*)news, newlen);
10777 SvUTF8_on(PL_linestr);
10778 s = (U8*)SvPVX(PL_linestr);
10779 PL_bufend = SvPVX(PL_linestr) + newlen;
10782 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
10787 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
10788 #ifndef PERL_NO_UTF16_FILTER
10789 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
10792 if (PL_bufend > (char *)s) {
10796 filter_add(utf16_textfilter, NULL);
10797 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10798 utf16_to_utf8(s, news,
10799 PL_bufend - (char*)s,
10801 sv_setpvn(PL_linestr, (const char*)news, newlen);
10803 SvUTF8_on(PL_linestr);
10804 s = (U8*)SvPVX(PL_linestr);
10805 PL_bufend = SvPVX(PL_linestr) + newlen;
10808 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
10813 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
10814 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
10815 s += 3; /* UTF-8 */
10821 if (s[2] == 0xFE && s[3] == 0xFF) {
10822 /* UTF-32 big-endian */
10823 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
10826 else if (s[2] == 0 && s[3] != 0) {
10829 * are a good indicator of UTF-16BE. */
10830 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
10835 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
10838 * are a good indicator of UTF-16LE. */
10839 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
10848 * Restore a source filter.
10852 restore_rsfp(pTHX_ void *f)
10854 PerlIO *fp = (PerlIO*)f;
10856 if (PL_rsfp == PerlIO_stdin())
10857 PerlIO_clearerr(PL_rsfp);
10858 else if (PL_rsfp && (PL_rsfp != fp))
10859 PerlIO_close(PL_rsfp);
10863 #ifndef PERL_NO_UTF16_FILTER
10865 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10867 const STRLEN old = SvCUR(sv);
10868 const I32 count = FILTER_READ(idx+1, sv, maxlen);
10869 DEBUG_P(PerlIO_printf(Perl_debug_log,
10870 "utf16_textfilter(%p): %d %d (%d)\n",
10871 utf16_textfilter, idx, maxlen, (int) count));
10875 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10876 Copy(SvPVX(sv), tmps, old, char);
10877 utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old,
10878 SvCUR(sv) - old, &newlen);
10879 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10881 DEBUG_P({sv_dump(sv);});
10886 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10888 const STRLEN old = SvCUR(sv);
10889 const I32 count = FILTER_READ(idx+1, sv, maxlen);
10890 DEBUG_P(PerlIO_printf(Perl_debug_log,
10891 "utf16rev_textfilter(%p): %d %d (%d)\n",
10892 utf16rev_textfilter, idx, maxlen, (int) count));
10896 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10897 Copy(SvPVX(sv), tmps, old, char);
10898 utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old,
10899 SvCUR(sv) - old, &newlen);
10900 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10902 DEBUG_P({ sv_dump(sv); });
10908 Returns a pointer to the next character after the parsed
10909 vstring, as well as updating the passed in sv.
10911 Function must be called like
10914 s = scan_vstring(s,sv);
10916 The sv should already be large enough to store the vstring
10917 passed in, for performance reasons.
10922 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
10924 const char *pos = s;
10925 const char *start = s;
10926 if (*pos == 'v') pos++; /* get past 'v' */
10927 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
10929 if ( *pos != '.') {
10930 /* this may not be a v-string if followed by => */
10931 const char *next = pos;
10932 while (next < PL_bufend && isSPACE(*next))
10934 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
10935 /* return string not v-string */
10936 sv_setpvn(sv,(char *)s,pos-s);
10937 return (char *)pos;
10941 if (!isALPHA(*pos)) {
10943 U8 tmpbuf[UTF8_MAXBYTES+1];
10946 if (*s == 'v') s++; /* get past 'v' */
10948 sv_setpvn(sv, "", 0);
10953 /* this is atoi() that tolerates underscores */
10954 const char *end = pos;
10956 while (--end >= s) {
10961 rev += (*end - '0') * mult;
10963 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
10964 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
10965 "Integer overflow in decimal number");
10969 if (rev > 0x7FFFFFFF)
10970 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
10972 /* Append native character for the rev point */
10973 tmpend = uvchr_to_utf8(tmpbuf, rev);
10974 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
10975 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
10977 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
10983 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
10987 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
10995 * c-indentation-style: bsd
10996 * c-basic-offset: 4
10997 * indent-tabs-mode: t
11000 * ex: set ts=8 sts=4 sw=4 noet: