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*)u.iop, 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)
2170 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", (void*)u.iop));
2172 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2174 /* if filter is on top of stack (usual case) just pop it off */
2175 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2176 u.iop = IoANY(datasv);
2177 if (u.filter == funcp) {
2178 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2179 IoANY(datasv) = (void *)NULL;
2180 sv_free(av_pop(PL_rsfp_filters));
2184 /* we need to search for the correct entry and clear it */
2185 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2189 /* Invoke the idxth filter function for the current rsfp. */
2190 /* maxlen 0 = read one text line */
2192 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2198 if (!PL_rsfp_filters)
2200 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2201 /* Provide a default input filter to make life easy. */
2202 /* Note that we append to the line. This is handy. */
2203 DEBUG_P(PerlIO_printf(Perl_debug_log,
2204 "filter_read %d: from rsfp\n", idx));
2208 const int old_len = SvCUR(buf_sv);
2210 /* ensure buf_sv is large enough */
2211 SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ;
2212 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
2213 if (PerlIO_error(PL_rsfp))
2214 return -1; /* error */
2216 return 0 ; /* end of file */
2218 SvCUR_set(buf_sv, old_len + len) ;
2221 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2222 if (PerlIO_error(PL_rsfp))
2223 return -1; /* error */
2225 return 0 ; /* end of file */
2228 return SvCUR(buf_sv);
2230 /* Skip this filter slot if filter has been deleted */
2231 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2232 DEBUG_P(PerlIO_printf(Perl_debug_log,
2233 "filter_read %d: skipped (filter deleted)\n",
2235 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
2237 /* Get function pointer hidden within datasv */
2238 u.iop = IoANY(datasv);
2240 DEBUG_P(PerlIO_printf(Perl_debug_log,
2241 "filter_read %d: via function %p (%s)\n",
2242 idx, (void*)u.iop, SvPV_nolen(datasv)));
2243 /* Call function. The function is expected to */
2244 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2245 /* Return: <0:error, =0:eof, >0:not eof */
2246 return (*funcp)(aTHX_ idx, buf_sv, maxlen);
2250 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2252 #ifdef PERL_CR_FILTER
2253 if (!PL_rsfp_filters) {
2254 filter_add(S_cr_textfilter,NULL);
2257 if (PL_rsfp_filters) {
2259 SvCUR_set(sv, 0); /* start with empty line */
2260 if (FILTER_READ(0, sv, 0) > 0)
2261 return ( SvPVX(sv) ) ;
2266 return (sv_gets(sv, fp, append));
2270 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2274 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2278 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2279 (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV)))
2281 return GvHV(gv); /* Foo:: */
2284 /* use constant CLASS => 'MyClass' */
2285 if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) {
2287 if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2288 pkgname = SvPV_nolen(sv);
2292 return gv_stashpv(pkgname, FALSE);
2296 static const char* const exp_name[] =
2297 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2298 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
2305 Works out what to call the token just pulled out of the input
2306 stream. The yacc parser takes care of taking the ops we return and
2307 stitching them into a tree.
2313 if read an identifier
2314 if we're in a my declaration
2315 croak if they tried to say my($foo::bar)
2316 build the ops for a my() declaration
2317 if it's an access to a my() variable
2318 are we in a sort block?
2319 croak if my($a); $a <=> $b
2320 build ops for access to a my() variable
2321 if in a dq string, and they've said @foo and we can't find @foo
2323 build ops for a bareword
2324 if we already built the token before, use it.
2329 #pragma segment Perl_yylex
2334 register char *s = PL_bufptr;
2341 I32 orig_keyword = 0;
2344 PerlIO_printf(Perl_debug_log, "### LEX_%s\n",
2345 lex_state_names[PL_lex_state]);
2347 /* check if there's an identifier for us to look at */
2348 if (PL_pending_ident)
2349 return REPORT(S_pending_ident(aTHX));
2351 /* no identifier pending identification */
2353 switch (PL_lex_state) {
2355 case LEX_NORMAL: /* Some compilers will produce faster */
2356 case LEX_INTERPNORMAL: /* code if we comment these out. */
2360 /* when we've already built the next token, just pull it out of the queue */
2363 yylval = PL_nextval[PL_nexttoke];
2365 PL_lex_state = PL_lex_defer;
2366 PL_expect = PL_lex_expect;
2367 PL_lex_defer = LEX_NORMAL;
2369 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2370 "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr,
2371 (IV)PL_nexttype[PL_nexttoke]); });
2373 return REPORT(PL_nexttype[PL_nexttoke]);
2375 /* interpolated case modifiers like \L \U, including \Q and \E.
2376 when we get here, PL_bufptr is at the \
2378 case LEX_INTERPCASEMOD:
2380 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2381 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2383 /* handle \E or end of string */
2384 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2386 if (PL_lex_casemods) {
2387 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
2388 PL_lex_casestack[PL_lex_casemods] = '\0';
2390 if (PL_bufptr != PL_bufend
2391 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
2393 PL_lex_state = LEX_INTERPCONCAT;
2397 if (PL_bufptr != PL_bufend)
2399 PL_lex_state = LEX_INTERPCONCAT;
2403 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2404 "### Saw case modifier at '%s'\n", PL_bufptr); });
2406 if (s[1] == '\\' && s[2] == 'E') {
2408 PL_lex_state = LEX_INTERPCONCAT;
2412 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2413 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
2414 if ((*s == 'L' || *s == 'U') &&
2415 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
2416 PL_lex_casestack[--PL_lex_casemods] = '\0';
2419 if (PL_lex_casemods > 10)
2420 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2421 PL_lex_casestack[PL_lex_casemods++] = *s;
2422 PL_lex_casestack[PL_lex_casemods] = '\0';
2423 PL_lex_state = LEX_INTERPCONCAT;
2424 PL_nextval[PL_nexttoke].ival = 0;
2427 PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2429 PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2431 PL_nextval[PL_nexttoke].ival = OP_LC;
2433 PL_nextval[PL_nexttoke].ival = OP_UC;
2435 PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2437 Perl_croak(aTHX_ "panic: yylex");
2441 if (PL_lex_starts) {
2444 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2445 if (PL_lex_casemods == 1 && PL_lex_inpat)
2454 case LEX_INTERPPUSH:
2455 return REPORT(sublex_push());
2457 case LEX_INTERPSTART:
2458 if (PL_bufptr == PL_bufend)
2459 return REPORT(sublex_done());
2460 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2461 "### Interpolated variable at '%s'\n", PL_bufptr); });
2463 PL_lex_dojoin = (*PL_bufptr == '@');
2464 PL_lex_state = LEX_INTERPNORMAL;
2465 if (PL_lex_dojoin) {
2466 PL_nextval[PL_nexttoke].ival = 0;
2468 force_ident("\"", '$');
2469 PL_nextval[PL_nexttoke].ival = 0;
2471 PL_nextval[PL_nexttoke].ival = 0;
2473 PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
2476 if (PL_lex_starts++) {
2478 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2479 if (!PL_lex_casemods && PL_lex_inpat)
2486 case LEX_INTERPENDMAYBE:
2487 if (intuit_more(PL_bufptr)) {
2488 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
2494 if (PL_lex_dojoin) {
2495 PL_lex_dojoin = FALSE;
2496 PL_lex_state = LEX_INTERPCONCAT;
2499 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2500 && SvEVALED(PL_lex_repl))
2502 if (PL_bufptr != PL_bufend)
2503 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2504 PL_lex_repl = Nullsv;
2507 case LEX_INTERPCONCAT:
2509 if (PL_lex_brackets)
2510 Perl_croak(aTHX_ "panic: INTERPCONCAT");
2512 if (PL_bufptr == PL_bufend)
2513 return REPORT(sublex_done());
2515 if (SvIVX(PL_linestr) == '\'') {
2516 SV *sv = newSVsv(PL_linestr);
2519 else if ( PL_hints & HINT_NEW_RE )
2520 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2521 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2525 s = scan_const(PL_bufptr);
2527 PL_lex_state = LEX_INTERPCASEMOD;
2529 PL_lex_state = LEX_INTERPSTART;
2532 if (s != PL_bufptr) {
2533 PL_nextval[PL_nexttoke] = yylval;
2536 if (PL_lex_starts++) {
2537 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2538 if (!PL_lex_casemods && PL_lex_inpat)
2551 PL_lex_state = LEX_NORMAL;
2552 s = scan_formline(PL_bufptr);
2553 if (!PL_lex_formbrack)
2559 PL_oldoldbufptr = PL_oldbufptr;
2562 PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at [%s]\n",
2563 exp_name[PL_expect], s);
2569 if (isIDFIRST_lazy_if(s,UTF))
2571 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2574 goto fake_eof; /* emulate EOF on ^D or ^Z */
2579 if (PL_lex_brackets) {
2580 if (PL_lex_formbrack)
2581 yyerror("Format not terminated");
2583 yyerror("Missing right curly or square bracket");
2585 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2586 "### Tokener got EOF\n");
2590 if (s++ < PL_bufend)
2591 goto retry; /* ignore stray nulls */
2594 if (!PL_in_eval && !PL_preambled) {
2595 PL_preambled = TRUE;
2596 sv_setpv(PL_linestr,incl_perldb());
2597 if (SvCUR(PL_linestr))
2598 sv_catpvn(PL_linestr,";", 1);
2600 while(AvFILLp(PL_preambleav) >= 0) {
2601 SV *tmpsv = av_shift(PL_preambleav);
2602 sv_catsv(PL_linestr, tmpsv);
2603 sv_catpvn(PL_linestr, ";", 1);
2606 sv_free((SV*)PL_preambleav);
2607 PL_preambleav = NULL;
2609 if (PL_minus_n || PL_minus_p) {
2610 sv_catpv(PL_linestr, "LINE: while (<>) {");
2612 sv_catpv(PL_linestr,"chomp;");
2615 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
2616 || *PL_splitstr == '"')
2617 && strchr(PL_splitstr + 1, *PL_splitstr))
2618 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
2620 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
2621 bytes can be used as quoting characters. :-) */
2622 /* The count here deliberately includes the NUL
2623 that terminates the C string constant. This
2624 embeds the opening NUL into the string. */
2625 const char *splits = PL_splitstr;
2626 sv_catpvn(PL_linestr, "our @F=split(q", 15);
2629 if (*splits == '\\')
2630 sv_catpvn(PL_linestr, splits, 1);
2631 sv_catpvn(PL_linestr, splits, 1);
2632 } while (*splits++);
2633 /* This loop will embed the trailing NUL of
2634 PL_linestr as the last thing it does before
2636 sv_catpvn(PL_linestr, ");", 2);
2640 sv_catpv(PL_linestr,"our @F=split(' ');");
2643 sv_catpvn(PL_linestr, "\n", 1);
2644 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2645 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2646 PL_last_lop = PL_last_uni = Nullch;
2647 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2648 SV *sv = NEWSV(85,0);
2650 sv_upgrade(sv, SVt_PVMG);
2651 sv_setsv(sv,PL_linestr);
2654 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2659 bof = PL_rsfp ? TRUE : FALSE;
2660 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2663 if (PL_preprocess && !PL_in_eval)
2664 (void)PerlProc_pclose(PL_rsfp);
2665 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2666 PerlIO_clearerr(PL_rsfp);
2668 (void)PerlIO_close(PL_rsfp);
2670 PL_doextract = FALSE;
2672 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2673 sv_setpv(PL_linestr,PL_minus_p
2674 ? ";}continue{print;}" : ";}");
2675 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2676 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2677 PL_last_lop = PL_last_uni = Nullch;
2678 PL_minus_n = PL_minus_p = 0;
2681 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2682 PL_last_lop = PL_last_uni = Nullch;
2683 sv_setpvn(PL_linestr,"",0);
2684 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
2686 /* If it looks like the start of a BOM or raw UTF-16,
2687 * check if it in fact is. */
2693 #ifdef PERLIO_IS_STDIO
2694 # ifdef __GNU_LIBRARY__
2695 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
2696 # define FTELL_FOR_PIPE_IS_BROKEN
2700 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
2701 # define FTELL_FOR_PIPE_IS_BROKEN
2706 #ifdef FTELL_FOR_PIPE_IS_BROKEN
2707 /* This loses the possibility to detect the bof
2708 * situation on perl -P when the libc5 is being used.
2709 * Workaround? Maybe attach some extra state to PL_rsfp?
2712 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2714 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
2717 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2718 s = swallow_bom((U8*)s);
2722 /* Incest with pod. */
2723 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2724 sv_setpvn(PL_linestr, "", 0);
2725 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2726 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2727 PL_last_lop = PL_last_uni = Nullch;
2728 PL_doextract = FALSE;
2732 } while (PL_doextract);
2733 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2734 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2735 SV *sv = NEWSV(85,0);
2737 sv_upgrade(sv, SVt_PVMG);
2738 sv_setsv(sv,PL_linestr);
2741 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2743 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2744 PL_last_lop = PL_last_uni = Nullch;
2745 if (CopLINE(PL_curcop) == 1) {
2746 while (s < PL_bufend && isSPACE(*s))
2748 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2752 if (*s == '#' && *(s+1) == '!')
2754 #ifdef ALTERNATE_SHEBANG
2756 static char const as[] = ALTERNATE_SHEBANG;
2757 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2758 d = s + (sizeof(as) - 1);
2760 #endif /* ALTERNATE_SHEBANG */
2769 while (*d && !isSPACE(*d))
2773 #ifdef ARG_ZERO_IS_SCRIPT
2774 if (ipathend > ipath) {
2776 * HP-UX (at least) sets argv[0] to the script name,
2777 * which makes $^X incorrect. And Digital UNIX and Linux,
2778 * at least, set argv[0] to the basename of the Perl
2779 * interpreter. So, having found "#!", we'll set it right.
2781 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); /* $^X */
2782 assert(SvPOK(x) || SvGMAGICAL(x));
2783 if (sv_eq(x, CopFILESV(PL_curcop))) {
2784 sv_setpvn(x, ipath, ipathend - ipath);
2790 const char *bstart = SvPV(CopFILESV(PL_curcop),blen);
2791 const char *lstart = SvPV(x,llen);
2793 bstart += blen - llen;
2794 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
2795 sv_setpvn(x, ipath, ipathend - ipath);
2800 TAINT_NOT; /* $^X is always tainted, but that's OK */
2802 #endif /* ARG_ZERO_IS_SCRIPT */
2807 d = instr(s,"perl -");
2809 d = instr(s,"perl");
2811 /* avoid getting into infinite loops when shebang
2812 * line contains "Perl" rather than "perl" */
2814 for (d = ipathend-4; d >= ipath; --d) {
2815 if ((*d == 'p' || *d == 'P')
2816 && !ibcmp(d, "perl", 4))
2826 #ifdef ALTERNATE_SHEBANG
2828 * If the ALTERNATE_SHEBANG on this system starts with a
2829 * character that can be part of a Perl expression, then if
2830 * we see it but not "perl", we're probably looking at the
2831 * start of Perl code, not a request to hand off to some
2832 * other interpreter. Similarly, if "perl" is there, but
2833 * not in the first 'word' of the line, we assume the line
2834 * contains the start of the Perl program.
2836 if (d && *s != '#') {
2837 const char *c = ipath;
2838 while (*c && !strchr("; \t\r\n\f\v#", *c))
2841 d = Nullch; /* "perl" not in first word; ignore */
2843 *s = '#'; /* Don't try to parse shebang line */
2845 #endif /* ALTERNATE_SHEBANG */
2846 #ifndef MACOS_TRADITIONAL
2851 !instr(s,"indir") &&
2852 instr(PL_origargv[0],"perl"))
2859 while (s < PL_bufend && isSPACE(*s))
2861 if (s < PL_bufend) {
2862 Newz(899,newargv,PL_origargc+3,char*);
2864 while (s < PL_bufend && !isSPACE(*s))
2867 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2870 newargv = PL_origargv;
2873 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
2875 Perl_croak(aTHX_ "Can't exec %s", ipath);
2879 const U32 oldpdb = PL_perldb;
2880 const bool oldn = PL_minus_n;
2881 const bool oldp = PL_minus_p;
2883 while (*d && !isSPACE(*d)) d++;
2884 while (SPACE_OR_TAB(*d)) d++;
2887 const bool switches_done = PL_doswitches;
2889 if (*d == 'M' || *d == 'm' || *d == 'C') {
2891 while (*d && !isSPACE(*d)) d++;
2892 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2895 d = moreswitches(d);
2897 if (PL_doswitches && !switches_done) {
2898 int argc = PL_origargc;
2899 char **argv = PL_origargv;
2902 } while (argc && argv[0][0] == '-' && argv[0][1]);
2903 init_argv_symbols(argc,argv);
2905 if ((PERLDB_LINE && !oldpdb) ||
2906 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
2907 /* if we have already added "LINE: while (<>) {",
2908 we must not do it again */
2910 sv_setpvn(PL_linestr, "", 0);
2911 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2912 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2913 PL_last_lop = PL_last_uni = Nullch;
2914 PL_preambled = FALSE;
2916 (void)gv_fetchfile(PL_origfilename);
2919 if (PL_doswitches && !switches_done) {
2920 int argc = PL_origargc;
2921 char **argv = PL_origargv;
2924 } while (argc && argv[0][0] == '-' && argv[0][1]);
2925 init_argv_symbols(argc,argv);
2931 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2933 PL_lex_state = LEX_FORMLINE;
2938 #ifdef PERL_STRICT_CR
2939 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
2941 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
2943 case ' ': case '\t': case '\f': case 013:
2944 #ifdef MACOS_TRADITIONAL
2951 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
2952 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
2953 /* handle eval qq[#line 1 "foo"\n ...] */
2954 CopLINE_dec(PL_curcop);
2958 while (s < d && *s != '\n')
2962 else if (s > d) /* Found by Ilya: feed random input to Perl. */
2963 Perl_croak(aTHX_ "panic: input overflow");
2965 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2967 PL_lex_state = LEX_FORMLINE;
2977 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2984 while (s < PL_bufend && SPACE_OR_TAB(*s))
2987 if (strnEQ(s,"=>",2)) {
2988 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
2989 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2990 "### Saw unary minus before =>, forcing word '%s'\n", s);
2992 OPERATOR('-'); /* unary minus */
2994 PL_last_uni = PL_oldbufptr;
2996 case 'r': ftst = OP_FTEREAD; break;
2997 case 'w': ftst = OP_FTEWRITE; break;
2998 case 'x': ftst = OP_FTEEXEC; break;
2999 case 'o': ftst = OP_FTEOWNED; break;
3000 case 'R': ftst = OP_FTRREAD; break;
3001 case 'W': ftst = OP_FTRWRITE; break;
3002 case 'X': ftst = OP_FTREXEC; break;
3003 case 'O': ftst = OP_FTROWNED; break;
3004 case 'e': ftst = OP_FTIS; break;
3005 case 'z': ftst = OP_FTZERO; break;
3006 case 's': ftst = OP_FTSIZE; break;
3007 case 'f': ftst = OP_FTFILE; break;
3008 case 'd': ftst = OP_FTDIR; break;
3009 case 'l': ftst = OP_FTLINK; break;
3010 case 'p': ftst = OP_FTPIPE; break;
3011 case 'S': ftst = OP_FTSOCK; break;
3012 case 'u': ftst = OP_FTSUID; break;
3013 case 'g': ftst = OP_FTSGID; break;
3014 case 'k': ftst = OP_FTSVTX; break;
3015 case 'b': ftst = OP_FTBLK; break;
3016 case 'c': ftst = OP_FTCHR; break;
3017 case 't': ftst = OP_FTTTY; break;
3018 case 'T': ftst = OP_FTTEXT; break;
3019 case 'B': ftst = OP_FTBINARY; break;
3020 case 'M': case 'A': case 'C':
3021 gv_fetchpv("\024",TRUE, SVt_PV);
3023 case 'M': ftst = OP_FTMTIME; break;
3024 case 'A': ftst = OP_FTATIME; break;
3025 case 'C': ftst = OP_FTCTIME; break;
3033 PL_last_lop_op = (OPCODE)ftst;
3034 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3035 "### Saw file test %c\n", (int)ftst);
3040 /* Assume it was a minus followed by a one-letter named
3041 * subroutine call (or a -bareword), then. */
3042 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3043 "### '-%c' looked like a file test but was not\n",
3052 if (PL_expect == XOPERATOR)
3057 else if (*s == '>') {
3060 if (isIDFIRST_lazy_if(s,UTF)) {
3061 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3069 if (PL_expect == XOPERATOR)
3072 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3074 OPERATOR('-'); /* unary minus */
3081 if (PL_expect == XOPERATOR)
3086 if (PL_expect == XOPERATOR)
3089 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3095 if (PL_expect != XOPERATOR) {
3096 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3097 PL_expect = XOPERATOR;
3098 force_ident(PL_tokenbuf, '*');
3111 if (PL_expect == XOPERATOR) {
3115 PL_tokenbuf[0] = '%';
3116 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3117 if (!PL_tokenbuf[1]) {
3120 PL_pending_ident = '%';
3139 switch (PL_expect) {
3142 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3144 PL_bufptr = s; /* update in case we back off */
3150 PL_expect = XTERMBLOCK;
3154 while (isIDFIRST_lazy_if(s,UTF)) {
3155 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3156 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
3157 if (tmp < 0) tmp = -tmp;
3173 d = scan_str(d,TRUE,TRUE);
3175 /* MUST advance bufptr here to avoid bogus
3176 "at end of line" context messages from yyerror().
3178 PL_bufptr = s + len;
3179 yyerror("Unterminated attribute parameter in attribute list");
3182 return REPORT(0); /* EOF indicator */
3186 SV *sv = newSVpvn(s, len);
3187 sv_catsv(sv, PL_lex_stuff);
3188 attrs = append_elem(OP_LIST, attrs,
3189 newSVOP(OP_CONST, 0, sv));
3190 SvREFCNT_dec(PL_lex_stuff);
3191 PL_lex_stuff = Nullsv;
3194 if (len == 6 && strnEQ(s, "unique", len)) {
3195 if (PL_in_my == KEY_our)
3197 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
3199 ; /* skip to avoid loading attributes.pm */
3202 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
3205 /* NOTE: any CV attrs applied here need to be part of
3206 the CVf_BUILTIN_ATTRS define in cv.h! */
3207 else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
3208 CvLVALUE_on(PL_compcv);
3209 else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
3210 CvLOCKED_on(PL_compcv);
3211 else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
3212 CvMETHOD_on(PL_compcv);
3213 else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len))
3214 CvASSERTION_on(PL_compcv);
3215 /* After we've set the flags, it could be argued that
3216 we don't need to do the attributes.pm-based setting
3217 process, and shouldn't bother appending recognized
3218 flags. To experiment with that, uncomment the
3219 following "else". (Note that's already been
3220 uncommented. That keeps the above-applied built-in
3221 attributes from being intercepted (and possibly
3222 rejected) by a package's attribute routines, but is
3223 justified by the performance win for the common case
3224 of applying only built-in attributes.) */
3226 attrs = append_elem(OP_LIST, attrs,
3227 newSVOP(OP_CONST, 0,
3231 if (*s == ':' && s[1] != ':')
3234 break; /* require real whitespace or :'s */
3236 tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
3237 if (*s != ';' && *s != '}' && *s != tmp && (tmp != '=' || *s != ')')) {
3238 const char q = ((*s == '\'') ? '"' : '\'');
3239 /* If here for an expression, and parsed no attrs, back off. */
3240 if (tmp == '=' && !attrs) {
3244 /* MUST advance bufptr here to avoid bogus "at end of line"
3245 context messages from yyerror().
3249 yyerror("Unterminated attribute list");
3251 yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
3259 PL_nextval[PL_nexttoke].opval = attrs;
3267 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
3268 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
3285 if (PL_lex_brackets <= 0)
3286 yyerror("Unmatched right square bracket");
3289 if (PL_lex_state == LEX_INTERPNORMAL) {
3290 if (PL_lex_brackets == 0) {
3291 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3292 PL_lex_state = LEX_INTERPEND;
3299 if (PL_lex_brackets > 100) {
3300 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
3302 switch (PL_expect) {
3304 if (PL_lex_formbrack) {
3308 if (PL_oldoldbufptr == PL_last_lop)
3309 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3311 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3312 OPERATOR(HASHBRACK);
3314 while (s < PL_bufend && SPACE_OR_TAB(*s))
3317 PL_tokenbuf[0] = '\0';
3318 if (d < PL_bufend && *d == '-') {
3319 PL_tokenbuf[0] = '-';
3321 while (d < PL_bufend && SPACE_OR_TAB(*d))
3324 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3325 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
3327 while (d < PL_bufend && SPACE_OR_TAB(*d))
3330 const char minus = (PL_tokenbuf[0] == '-');
3331 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
3339 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
3344 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3349 if (PL_oldoldbufptr == PL_last_lop)
3350 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3352 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3355 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
3357 /* This hack is to get the ${} in the message. */
3359 yyerror("syntax error");
3362 OPERATOR(HASHBRACK);
3364 /* This hack serves to disambiguate a pair of curlies
3365 * as being a block or an anon hash. Normally, expectation
3366 * determines that, but in cases where we're not in a
3367 * position to expect anything in particular (like inside
3368 * eval"") we have to resolve the ambiguity. This code
3369 * covers the case where the first term in the curlies is a
3370 * quoted string. Most other cases need to be explicitly
3371 * disambiguated by prepending a `+' before the opening
3372 * curly in order to force resolution as an anon hash.
3374 * XXX should probably propagate the outer expectation
3375 * into eval"" to rely less on this hack, but that could
3376 * potentially break current behavior of eval"".
3380 if (*s == '\'' || *s == '"' || *s == '`') {
3381 /* common case: get past first string, handling escapes */
3382 for (t++; t < PL_bufend && *t != *s;)
3383 if (*t++ == '\\' && (*t == '\\' || *t == *s))
3387 else if (*s == 'q') {
3390 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
3393 /* skip q//-like construct */
3395 char open, close, term;
3398 while (t < PL_bufend && isSPACE(*t))
3400 /* check for q => */
3401 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
3402 OPERATOR(HASHBRACK);
3406 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
3410 for (t++; t < PL_bufend; t++) {
3411 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
3413 else if (*t == open)
3417 for (t++; t < PL_bufend; t++) {
3418 if (*t == '\\' && t+1 < PL_bufend)
3420 else if (*t == close && --brackets <= 0)
3422 else if (*t == open)
3429 /* skip plain q word */
3430 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3433 else if (isALNUM_lazy_if(t,UTF)) {
3435 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3438 while (t < PL_bufend && isSPACE(*t))
3440 /* if comma follows first term, call it an anon hash */
3441 /* XXX it could be a comma expression with loop modifiers */
3442 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
3443 || (*t == '=' && t[1] == '>')))
3444 OPERATOR(HASHBRACK);
3445 if (PL_expect == XREF)
3448 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3454 yylval.ival = CopLINE(PL_curcop);
3455 if (isSPACE(*s) || *s == '#')
3456 PL_copline = NOLINE; /* invalidate current command line number */
3461 if (PL_lex_brackets <= 0)
3462 yyerror("Unmatched right curly bracket");
3464 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3465 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3466 PL_lex_formbrack = 0;
3467 if (PL_lex_state == LEX_INTERPNORMAL) {
3468 if (PL_lex_brackets == 0) {
3469 if (PL_expect & XFAKEBRACK) {
3470 PL_expect &= XENUMMASK;
3471 PL_lex_state = LEX_INTERPEND;
3473 return yylex(); /* ignore fake brackets */
3475 if (*s == '-' && s[1] == '>')
3476 PL_lex_state = LEX_INTERPENDMAYBE;
3477 else if (*s != '[' && *s != '{')
3478 PL_lex_state = LEX_INTERPEND;
3481 if (PL_expect & XFAKEBRACK) {
3482 PL_expect &= XENUMMASK;
3484 return yylex(); /* ignore fake brackets */
3494 if (PL_expect == XOPERATOR) {
3495 if (ckWARN(WARN_SEMICOLON)
3496 && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart)
3498 CopLINE_dec(PL_curcop);
3499 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
3500 CopLINE_inc(PL_curcop);
3505 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3507 PL_expect = XOPERATOR;
3508 force_ident(PL_tokenbuf, '&');
3512 yylval.ival = (OPpENTERSUB_AMPER<<8);
3531 if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
3532 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Reversed %c= operator",(int)tmp);
3534 if (PL_expect == XSTATE && isALPHA(tmp) &&
3535 (s == PL_linestart+1 || s[-2] == '\n') )
3537 if (PL_in_eval && !PL_rsfp) {
3542 if (strnEQ(s,"=cut",4)) {
3556 PL_doextract = TRUE;
3559 if (PL_lex_brackets < PL_lex_formbrack) {
3561 #ifdef PERL_STRICT_CR
3562 for (t = s; SPACE_OR_TAB(*t); t++) ;
3564 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3566 if (*t == '\n' || *t == '#') {
3578 /* was this !=~ where !~ was meant?
3579 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
3581 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
3582 const char *t = s+1;
3584 while (t < PL_bufend && isSPACE(*t))
3587 if (*t == '/' || *t == '?' ||
3588 ((*t == 'm' || *t == 's' || *t == 'y') && !isALNUM(t[1])) ||
3589 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
3590 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3591 "!=~ should be !~");
3600 if (PL_expect != XOPERATOR) {
3601 if (s[1] != '<' && !strchr(s,'>'))
3604 s = scan_heredoc(s);
3606 s = scan_inputsymbol(s);
3607 TERM(sublex_start());
3612 SHop(OP_LEFT_SHIFT);
3626 SHop(OP_RIGHT_SHIFT);
3635 if (PL_expect == XOPERATOR) {
3636 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3639 return REPORT(','); /* grandfather non-comma-format format */
3643 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3644 PL_tokenbuf[0] = '@';
3645 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3646 sizeof PL_tokenbuf - 1, FALSE);
3647 if (PL_expect == XOPERATOR)
3648 no_op("Array length", s);
3649 if (!PL_tokenbuf[1])
3651 PL_expect = XOPERATOR;
3652 PL_pending_ident = '#';
3656 PL_tokenbuf[0] = '$';
3657 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3658 sizeof PL_tokenbuf - 1, FALSE);
3659 if (PL_expect == XOPERATOR)
3661 if (!PL_tokenbuf[1]) {
3663 yyerror("Final $ should be \\$ or $name");
3667 /* This kludge not intended to be bulletproof. */
3668 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3669 yylval.opval = newSVOP(OP_CONST, 0,
3670 newSViv(PL_compiling.cop_arybase));
3671 yylval.opval->op_private = OPpCONST_ARYBASE;
3677 if (PL_lex_state == LEX_NORMAL)
3680 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3683 PL_tokenbuf[0] = '@';
3684 if (ckWARN(WARN_SYNTAX)) {
3686 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3689 PL_bufptr = skipspace(PL_bufptr);
3690 while (t < PL_bufend && *t != ']')
3692 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3693 "Multidimensional syntax %.*s not supported",
3694 (t - PL_bufptr) + 1, PL_bufptr);
3698 else if (*s == '{') {
3699 PL_tokenbuf[0] = '%';
3700 if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") &&
3701 (t = strchr(s, '}')) && (t = strchr(t, '=')))
3703 char tmpbuf[sizeof PL_tokenbuf];
3704 for (t++; isSPACE(*t); t++) ;
3705 if (isIDFIRST_lazy_if(t,UTF)) {
3707 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3708 for (; isSPACE(*t); t++) ;
3709 if (*t == ';' && get_cv(tmpbuf, FALSE))
3710 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3711 "You need to quote \"%s\"", tmpbuf);
3717 PL_expect = XOPERATOR;
3718 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3719 const bool islop = (PL_last_lop == PL_oldoldbufptr);
3720 if (!islop || PL_last_lop_op == OP_GREPSTART)
3721 PL_expect = XOPERATOR;
3722 else if (strchr("$@\"'`q", *s))
3723 PL_expect = XTERM; /* e.g. print $fh "foo" */
3724 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3725 PL_expect = XTERM; /* e.g. print $fh &sub */
3726 else if (isIDFIRST_lazy_if(s,UTF)) {
3727 char tmpbuf[sizeof PL_tokenbuf];
3728 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3729 if ((tmp = keyword(tmpbuf, len))) {
3730 /* binary operators exclude handle interpretations */
3742 PL_expect = XTERM; /* e.g. print $fh length() */
3747 PL_expect = XTERM; /* e.g. print $fh subr() */
3750 else if (isDIGIT(*s))
3751 PL_expect = XTERM; /* e.g. print $fh 3 */
3752 else if (*s == '.' && isDIGIT(s[1]))
3753 PL_expect = XTERM; /* e.g. print $fh .3 */
3754 else if ((*s == '?' || *s == '-' || *s == '+')
3755 && !isSPACE(s[1]) && s[1] != '=')
3756 PL_expect = XTERM; /* e.g. print $fh -1 */
3757 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' && s[1] != '/')
3758 PL_expect = XTERM; /* e.g. print $fh /.../
3759 XXX except DORDOR operator */
3760 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3761 PL_expect = XTERM; /* print $fh <<"EOF" */
3763 PL_pending_ident = '$';
3767 if (PL_expect == XOPERATOR)
3769 PL_tokenbuf[0] = '@';
3770 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3771 if (!PL_tokenbuf[1]) {
3774 if (PL_lex_state == LEX_NORMAL)
3776 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3778 PL_tokenbuf[0] = '%';
3780 /* Warn about @ where they meant $. */
3781 if (ckWARN(WARN_SYNTAX)) {
3782 if (*s == '[' || *s == '{') {
3783 const char *t = s + 1;
3784 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3786 if (*t == '}' || *t == ']') {
3788 PL_bufptr = skipspace(PL_bufptr);
3789 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3790 "Scalar value %.*s better written as $%.*s",
3791 t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3796 PL_pending_ident = '@';
3799 case '/': /* may be division, defined-or, or pattern */
3800 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
3804 case '?': /* may either be conditional or pattern */
3805 if(PL_expect == XOPERATOR) {
3813 /* A // operator. */
3823 /* Disable warning on "study /blah/" */
3824 if (PL_oldoldbufptr == PL_last_uni
3825 && (*PL_last_uni != 's' || s - PL_last_uni < 5
3826 || memNE(PL_last_uni, "study", 5)
3827 || isALNUM_lazy_if(PL_last_uni+5,UTF)
3830 s = scan_pat(s,OP_MATCH);
3831 TERM(sublex_start());
3835 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3836 #ifdef PERL_STRICT_CR
3839 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3841 && (s == PL_linestart || s[-1] == '\n') )
3843 PL_lex_formbrack = 0;
3847 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3853 yylval.ival = OPf_SPECIAL;
3859 if (PL_expect != XOPERATOR)
3864 case '0': case '1': case '2': case '3': case '4':
3865 case '5': case '6': case '7': case '8': case '9':
3866 s = scan_num(s, &yylval);
3867 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3868 "### Saw number in '%s'\n", s);
3870 if (PL_expect == XOPERATOR)
3875 s = scan_str(s,FALSE,FALSE);
3876 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3877 "### Saw string before '%s'\n", s);
3879 if (PL_expect == XOPERATOR) {
3880 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3883 return REPORT(','); /* grandfather non-comma-format format */
3889 missingterm((char*)0);
3890 yylval.ival = OP_CONST;
3891 TERM(sublex_start());
3894 s = scan_str(s,FALSE,FALSE);
3895 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3896 "### Saw string before '%s'\n", s);
3898 if (PL_expect == XOPERATOR) {
3899 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3902 return REPORT(','); /* grandfather non-comma-format format */
3908 missingterm((char*)0);
3909 yylval.ival = OP_CONST;
3910 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3911 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
3912 yylval.ival = OP_STRINGIFY;
3916 TERM(sublex_start());
3919 s = scan_str(s,FALSE,FALSE);
3920 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3921 "### Saw backtick string before '%s'\n", s);
3923 if (PL_expect == XOPERATOR)
3924 no_op("Backticks",s);
3926 missingterm((char*)0);
3927 yylval.ival = OP_BACKTICK;
3929 TERM(sublex_start());
3933 if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s))
3934 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
3936 if (PL_expect == XOPERATOR)
3937 no_op("Backslash",s);
3941 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
3942 char *start = s + 2;
3943 while (isDIGIT(*start) || *start == '_')
3945 if (*start == '.' && isDIGIT(start[1])) {
3946 s = scan_num(s, &yylval);
3949 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
3950 else if (!isALPHA(*start) && (PL_expect == XTERM
3951 || PL_expect == XREF || PL_expect == XSTATE
3952 || PL_expect == XTERMORDORDOR)) {
3953 const char c = *start;
3956 gv = gv_fetchpv(s, FALSE, SVt_PVCV);
3959 s = scan_num(s, &yylval);
3966 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
4006 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4008 /* Some keywords can be followed by any delimiter, including ':' */
4009 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
4010 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
4011 (PL_tokenbuf[0] == 'q' &&
4012 strchr("qwxr", PL_tokenbuf[1])))));
4014 /* x::* is just a word, unless x is "CORE" */
4015 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4019 while (d < PL_bufend && isSPACE(*d))
4020 d++; /* no comments skipped here, or s### is misparsed */
4022 /* Is this a label? */
4023 if (!tmp && PL_expect == XSTATE
4024 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4026 yylval.pval = savepv(PL_tokenbuf);
4031 /* Check for keywords */
4032 tmp = keyword(PL_tokenbuf, len);
4034 /* Is this a word before a => operator? */
4035 if (*d == '=' && d[1] == '>') {
4038 = (OP*)newSVOP(OP_CONST, 0,
4039 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
4040 yylval.opval->op_private = OPpCONST_BARE;
4044 if (tmp < 0) { /* second-class keyword? */
4045 GV *ogv = Nullgv; /* override (winner) */
4046 GV *hgv = Nullgv; /* hidden (loser) */
4047 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4049 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
4052 if (GvIMPORTED_CV(gv))
4054 else if (! CvMETHOD(cv))
4058 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4059 (gv = *gvp) != (GV*)&PL_sv_undef &&
4060 GvCVu(gv) && GvIMPORTED_CV(gv))
4067 tmp = 0; /* overridden by import or by GLOBAL */
4070 && -tmp==KEY_lock /* XXX generalizable kludge */
4072 && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
4074 tmp = 0; /* any sub overrides "weak" keyword */
4079 && PL_expect != XOPERATOR
4080 && PL_expect != XTERMORDORDOR)
4082 /* any sub overrides the "err" keyword, except when really an
4083 * operator is expected */
4086 else { /* no override */
4088 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
4089 Perl_warner(aTHX_ packWARN(WARN_MISC),
4090 "dump() better written as CORE::dump()");
4094 if (ckWARN(WARN_AMBIGUOUS) && hgv
4095 && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
4096 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4097 "Ambiguous call resolved as CORE::%s(), %s",
4098 GvENAME(hgv), "qualify as such or use &");
4105 default: /* not a keyword */
4109 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
4111 /* Get the rest if it looks like a package qualifier */
4113 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
4115 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
4118 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
4119 *s == '\'' ? "'" : "::");
4124 if (PL_expect == XOPERATOR) {
4125 if (PL_bufptr == PL_linestart) {
4126 CopLINE_dec(PL_curcop);
4127 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4128 CopLINE_inc(PL_curcop);
4131 no_op("Bareword",s);
4134 /* Look for a subroutine with this name in current package,
4135 unless name is "Foo::", in which case Foo is a bearword
4136 (and a package name). */
4139 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
4141 if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
4142 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
4143 "Bareword \"%s\" refers to nonexistent package",
4146 PL_tokenbuf[len] = '\0';
4153 gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
4156 /* if we saw a global override before, get the right name */
4159 sv = newSVpvn("CORE::GLOBAL::",14);
4160 sv_catpv(sv,PL_tokenbuf);
4163 /* If len is 0, newSVpv does strlen(), which is correct.
4164 If len is non-zero, then it will be the true length,
4165 and so the scalar will be created correctly. */
4166 sv = newSVpv(PL_tokenbuf,len);
4169 /* Presume this is going to be a bareword of some sort. */
4172 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4173 yylval.opval->op_private = OPpCONST_BARE;
4174 /* UTF-8 package name? */
4175 if (UTF && !IN_BYTES &&
4176 is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
4179 /* And if "Foo::", then that's what it certainly is. */
4184 /* See if it's the indirect object for a list operator. */
4186 if (PL_oldoldbufptr &&
4187 PL_oldoldbufptr < PL_bufptr &&
4188 (PL_oldoldbufptr == PL_last_lop
4189 || PL_oldoldbufptr == PL_last_uni) &&
4190 /* NO SKIPSPACE BEFORE HERE! */
4191 (PL_expect == XREF ||
4192 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
4194 bool immediate_paren = *s == '(';
4196 /* (Now we can afford to cross potential line boundary.) */
4199 /* Two barewords in a row may indicate method call. */
4201 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv)))
4204 /* If not a declared subroutine, it's an indirect object. */
4205 /* (But it's an indir obj regardless for sort.) */
4207 if ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
4208 ((!gv || !GvCVu(gv)) &&
4209 (PL_last_lop_op != OP_MAPSTART &&
4210 PL_last_lop_op != OP_GREPSTART))))
4212 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
4217 PL_expect = XOPERATOR;
4220 /* Is this a word before a => operator? */
4221 if (*s == '=' && s[1] == '>' && !pkgname) {
4223 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
4224 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
4225 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
4229 /* If followed by a paren, it's certainly a subroutine. */
4232 if (gv && GvCVu(gv)) {
4233 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
4234 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
4239 PL_nextval[PL_nexttoke].opval = yylval.opval;
4240 PL_expect = XOPERATOR;
4246 /* If followed by var or block, call it a method (unless sub) */
4248 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
4249 PL_last_lop = PL_oldbufptr;
4250 PL_last_lop_op = OP_METHOD;
4254 /* If followed by a bareword, see if it looks like indir obj. */
4257 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
4258 && (tmp = intuit_method(s,gv)))
4261 /* Not a method, so call it a subroutine (if defined) */
4263 if (gv && GvCVu(gv)) {
4265 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
4266 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4267 "Ambiguous use of -%s resolved as -&%s()",
4268 PL_tokenbuf, PL_tokenbuf);
4269 /* Check for a constant sub */
4271 if ((sv = cv_const_sv(cv))) {
4273 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
4274 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
4275 yylval.opval->op_private = 0;
4279 /* Resolve to GV now. */
4280 op_free(yylval.opval);
4281 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4282 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
4283 PL_last_lop = PL_oldbufptr;
4284 PL_last_lop_op = OP_ENTERSUB;
4285 /* Is there a prototype? */
4288 char *proto = SvPV((SV*)cv, len);
4291 if (*proto == '$' && proto[1] == '\0')
4293 while (*proto == ';')
4295 if (*proto == '&' && *s == '{') {
4296 sv_setpv(PL_subname, PL_curstash ?
4297 "__ANON__" : "__ANON__::__ANON__");
4301 PL_nextval[PL_nexttoke].opval = yylval.opval;
4307 /* Call it a bare word */
4309 if (PL_hints & HINT_STRICT_SUBS)
4310 yylval.opval->op_private |= OPpCONST_STRICT;
4313 if (ckWARN(WARN_RESERVED)) {
4314 if (lastchar != '-') {
4315 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
4316 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
4317 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
4324 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
4325 && ckWARN_d(WARN_AMBIGUOUS)) {
4326 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4327 "Operator or semicolon missing before %c%s",
4328 lastchar, PL_tokenbuf);
4329 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4330 "Ambiguous use of %c resolved as operator %c",
4331 lastchar, lastchar);
4337 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4338 newSVpv(CopFILE(PL_curcop),0));
4342 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4343 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
4346 case KEY___PACKAGE__:
4347 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4349 ? newSVpv(HvNAME(PL_curstash), 0)
4358 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
4359 const char *pname = "main";
4360 if (PL_tokenbuf[2] == 'D')
4361 pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash);
4362 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);
4365 GvIOp(gv) = newIO();
4366 IoIFP(GvIOp(gv)) = PL_rsfp;
4367 #if defined(HAS_FCNTL) && defined(F_SETFD)
4369 const int fd = PerlIO_fileno(PL_rsfp);
4370 fcntl(fd,F_SETFD,fd >= 3);
4373 /* Mark this internal pseudo-handle as clean */
4374 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4376 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
4377 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
4378 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
4380 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
4381 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
4382 /* if the script was opened in binmode, we need to revert
4383 * it to text mode for compatibility; but only iff it has CRs
4384 * XXX this is a questionable hack at best. */
4385 if (PL_bufend-PL_bufptr > 2
4386 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
4389 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
4390 loc = PerlIO_tell(PL_rsfp);
4391 (void)PerlIO_seek(PL_rsfp, 0L, 0);
4394 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
4396 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
4397 #endif /* NETWARE */
4398 #ifdef PERLIO_IS_STDIO /* really? */
4399 # if defined(__BORLANDC__)
4400 /* XXX see note in do_binmode() */
4401 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
4405 PerlIO_seek(PL_rsfp, loc, 0);
4409 #ifdef PERLIO_LAYERS
4412 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
4413 else if (PL_encoding) {
4420 XPUSHs(PL_encoding);
4422 call_method("name", G_SCALAR);
4426 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
4427 Perl_form(aTHX_ ":encoding(%"SVf")",
4445 if (PL_expect == XSTATE) {
4452 if (*s == ':' && s[1] == ':') {
4455 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4456 if (!(tmp = keyword(PL_tokenbuf, len)))
4457 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
4471 LOP(OP_ACCEPT,XTERM);
4477 LOP(OP_ATAN2,XTERM);
4483 LOP(OP_BINMODE,XTERM);
4486 LOP(OP_BLESS,XTERM);
4495 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
4512 if (!PL_cryptseen) {
4513 PL_cryptseen = TRUE;
4517 LOP(OP_CRYPT,XTERM);
4520 LOP(OP_CHMOD,XTERM);
4523 LOP(OP_CHOWN,XTERM);
4526 LOP(OP_CONNECT,XTERM);
4542 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4546 PL_hints |= HINT_BLOCK_SCOPE;
4556 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
4557 LOP(OP_DBMOPEN,XTERM);
4563 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4570 yylval.ival = CopLINE(PL_curcop);
4584 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4585 UNIBRACK(OP_ENTEREVAL);
4603 case KEY_endhostent:
4609 case KEY_endservent:
4612 case KEY_endprotoent:
4623 yylval.ival = CopLINE(PL_curcop);
4625 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4627 if ((PL_bufend - p) >= 3 &&
4628 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4630 else if ((PL_bufend - p) >= 4 &&
4631 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4634 if (isIDFIRST_lazy_if(p,UTF)) {
4635 p = scan_ident(p, PL_bufend,
4636 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4640 Perl_croak(aTHX_ "Missing $ on loop variable");
4645 LOP(OP_FORMLINE,XTERM);
4651 LOP(OP_FCNTL,XTERM);
4657 LOP(OP_FLOCK,XTERM);
4666 LOP(OP_GREPSTART, XREF);
4669 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4684 case KEY_getpriority:
4685 LOP(OP_GETPRIORITY,XTERM);
4687 case KEY_getprotobyname:
4690 case KEY_getprotobynumber:
4691 LOP(OP_GPBYNUMBER,XTERM);
4693 case KEY_getprotoent:
4705 case KEY_getpeername:
4706 UNI(OP_GETPEERNAME);
4708 case KEY_gethostbyname:
4711 case KEY_gethostbyaddr:
4712 LOP(OP_GHBYADDR,XTERM);
4714 case KEY_gethostent:
4717 case KEY_getnetbyname:
4720 case KEY_getnetbyaddr:
4721 LOP(OP_GNBYADDR,XTERM);
4726 case KEY_getservbyname:
4727 LOP(OP_GSBYNAME,XTERM);
4729 case KEY_getservbyport:
4730 LOP(OP_GSBYPORT,XTERM);
4732 case KEY_getservent:
4735 case KEY_getsockname:
4736 UNI(OP_GETSOCKNAME);
4738 case KEY_getsockopt:
4739 LOP(OP_GSOCKOPT,XTERM);
4761 yylval.ival = CopLINE(PL_curcop);
4765 LOP(OP_INDEX,XTERM);
4771 LOP(OP_IOCTL,XTERM);
4783 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4815 LOP(OP_LISTEN,XTERM);
4824 s = scan_pat(s,OP_MATCH);
4825 TERM(sublex_start());
4828 LOP(OP_MAPSTART, XREF);
4831 LOP(OP_MKDIR,XTERM);
4834 LOP(OP_MSGCTL,XTERM);
4837 LOP(OP_MSGGET,XTERM);
4840 LOP(OP_MSGRCV,XTERM);
4843 LOP(OP_MSGSND,XTERM);
4849 if (isIDFIRST_lazy_if(s,UTF)) {
4850 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4851 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4853 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
4854 if (!PL_in_my_stash) {
4857 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4865 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4872 if (PL_expect != XSTATE)
4873 yyerror("\"no\" not allowed in expression");
4874 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4875 s = force_version(s, FALSE);
4880 if (*s == '(' || (s = skipspace(s), *s == '('))
4887 if (isIDFIRST_lazy_if(s,UTF)) {
4889 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
4890 for (t=d; *t && isSPACE(*t); t++) ;
4891 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
4893 && !(t[0] == '=' && t[1] == '>')
4895 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
4896 "Precedence problem: open %.*s should be open(%.*s)",
4897 d - s, s, d - s, s);
4903 yylval.ival = OP_OR;
4913 LOP(OP_OPEN_DIR,XTERM);
4916 checkcomma(s,PL_tokenbuf,"filehandle");
4920 checkcomma(s,PL_tokenbuf,"filehandle");
4939 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4943 LOP(OP_PIPE_OP,XTERM);
4946 s = scan_str(s,FALSE,FALSE);
4948 missingterm((char*)0);
4949 yylval.ival = OP_CONST;
4950 TERM(sublex_start());
4956 s = scan_str(s,FALSE,FALSE);
4958 missingterm((char*)0);
4960 if (SvCUR(PL_lex_stuff)) {
4963 d = SvPV_force(PL_lex_stuff, len);
4966 for (; isSPACE(*d) && len; --len, ++d) ;
4969 if (!warned && ckWARN(WARN_QW)) {
4970 for (; !isSPACE(*d) && len; --len, ++d) {
4972 Perl_warner(aTHX_ packWARN(WARN_QW),
4973 "Possible attempt to separate words with commas");
4976 else if (*d == '#') {
4977 Perl_warner(aTHX_ packWARN(WARN_QW),
4978 "Possible attempt to put comments in qw() list");
4984 for (; !isSPACE(*d) && len; --len, ++d) ;
4986 sv = newSVpvn(b, d-b);
4987 if (DO_UTF8(PL_lex_stuff))
4989 words = append_elem(OP_LIST, words,
4990 newSVOP(OP_CONST, 0, tokeq(sv)));
4994 PL_nextval[PL_nexttoke].opval = words;
4999 SvREFCNT_dec(PL_lex_stuff);
5000 PL_lex_stuff = Nullsv;
5006 s = scan_str(s,FALSE,FALSE);
5008 missingterm((char*)0);
5009 yylval.ival = OP_STRINGIFY;
5010 if (SvIVX(PL_lex_stuff) == '\'')
5011 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
5012 TERM(sublex_start());
5015 s = scan_pat(s,OP_QR);
5016 TERM(sublex_start());
5019 s = scan_str(s,FALSE,FALSE);
5021 missingterm((char*)0);
5022 yylval.ival = OP_BACKTICK;
5024 TERM(sublex_start());
5032 s = force_version(s, FALSE);
5034 else if (*s != 'v' || !isDIGIT(s[1])
5035 || (s = force_version(s, TRUE), *s == 'v'))
5037 *PL_tokenbuf = '\0';
5038 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5039 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
5040 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
5042 yyerror("<> should be quotes");
5050 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5054 LOP(OP_RENAME,XTERM);
5063 LOP(OP_RINDEX,XTERM);
5073 UNIDOR(OP_READLINE);
5086 LOP(OP_REVERSE,XTERM);
5089 UNIDOR(OP_READLINK);
5097 TERM(sublex_start());
5099 TOKEN(1); /* force error */
5108 LOP(OP_SELECT,XTERM);
5114 LOP(OP_SEMCTL,XTERM);
5117 LOP(OP_SEMGET,XTERM);
5120 LOP(OP_SEMOP,XTERM);
5126 LOP(OP_SETPGRP,XTERM);
5128 case KEY_setpriority:
5129 LOP(OP_SETPRIORITY,XTERM);
5131 case KEY_sethostent:
5137 case KEY_setservent:
5140 case KEY_setprotoent:
5150 LOP(OP_SEEKDIR,XTERM);
5152 case KEY_setsockopt:
5153 LOP(OP_SSOCKOPT,XTERM);
5159 LOP(OP_SHMCTL,XTERM);
5162 LOP(OP_SHMGET,XTERM);
5165 LOP(OP_SHMREAD,XTERM);
5168 LOP(OP_SHMWRITE,XTERM);
5171 LOP(OP_SHUTDOWN,XTERM);
5180 LOP(OP_SOCKET,XTERM);
5182 case KEY_socketpair:
5183 LOP(OP_SOCKPAIR,XTERM);
5186 checkcomma(s,PL_tokenbuf,"subroutine name");
5188 if (*s == ';' || *s == ')') /* probably a close */
5189 Perl_croak(aTHX_ "sort is now a reserved word");
5191 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5195 LOP(OP_SPLIT,XTERM);
5198 LOP(OP_SPRINTF,XTERM);
5201 LOP(OP_SPLICE,XTERM);
5216 LOP(OP_SUBSTR,XTERM);
5222 char tmpbuf[sizeof PL_tokenbuf];
5223 SSize_t tboffset = 0;
5224 expectation attrful;
5225 bool have_name, have_proto, bad_proto;
5226 const int key = tmp;
5230 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
5231 (*s == ':' && s[1] == ':'))
5234 attrful = XATTRBLOCK;
5235 /* remember buffer pos'n for later force_word */
5236 tboffset = s - PL_oldbufptr;
5237 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5238 if (strchr(tmpbuf, ':'))
5239 sv_setpv(PL_subname, tmpbuf);
5241 sv_setsv(PL_subname,PL_curstname);
5242 sv_catpvn(PL_subname,"::",2);
5243 sv_catpvn(PL_subname,tmpbuf,len);
5250 Perl_croak(aTHX_ "Missing name in \"my sub\"");
5251 PL_expect = XTERMBLOCK;
5252 attrful = XATTRTERM;
5253 sv_setpvn(PL_subname,"?",1);
5257 if (key == KEY_format) {
5259 PL_lex_formbrack = PL_lex_brackets + 1;
5261 (void) force_word(PL_oldbufptr + tboffset, WORD,
5266 /* Look for a prototype */
5270 s = scan_str(s,FALSE,FALSE);
5272 Perl_croak(aTHX_ "Prototype not terminated");
5273 /* strip spaces and check for bad characters */
5274 d = SvPVX(PL_lex_stuff);
5277 for (p = d; *p; ++p) {
5280 if (!strchr("$@%*;[]&\\", *p))
5285 if (bad_proto && ckWARN(WARN_SYNTAX))
5286 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5287 "Illegal character in prototype for %"SVf" : %s",
5289 SvCUR_set(PL_lex_stuff, tmp);
5297 if (*s == ':' && s[1] != ':')
5298 PL_expect = attrful;
5299 else if (*s != '{' && key == KEY_sub) {
5301 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
5303 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname);
5307 PL_nextval[PL_nexttoke].opval =
5308 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
5309 PL_lex_stuff = Nullsv;
5313 sv_setpv(PL_subname,
5314 PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
5317 (void) force_word(PL_oldbufptr + tboffset, WORD,
5326 LOP(OP_SYSTEM,XREF);
5329 LOP(OP_SYMLINK,XTERM);
5332 LOP(OP_SYSCALL,XTERM);
5335 LOP(OP_SYSOPEN,XTERM);
5338 LOP(OP_SYSSEEK,XTERM);
5341 LOP(OP_SYSREAD,XTERM);
5344 LOP(OP_SYSWRITE,XTERM);
5348 TERM(sublex_start());
5369 LOP(OP_TRUNCATE,XTERM);
5381 yylval.ival = CopLINE(PL_curcop);
5385 yylval.ival = CopLINE(PL_curcop);
5389 LOP(OP_UNLINK,XTERM);
5395 LOP(OP_UNPACK,XTERM);
5398 LOP(OP_UTIME,XTERM);
5404 LOP(OP_UNSHIFT,XTERM);
5407 if (PL_expect != XSTATE)
5408 yyerror("\"use\" not allowed in expression");
5410 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
5411 s = force_version(s, TRUE);
5412 if (*s == ';' || (s = skipspace(s), *s == ';')) {
5413 PL_nextval[PL_nexttoke].opval = Nullop;
5416 else if (*s == 'v') {
5417 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5418 s = force_version(s, FALSE);
5422 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5423 s = force_version(s, FALSE);
5435 yylval.ival = CopLINE(PL_curcop);
5439 PL_hints |= HINT_BLOCK_SCOPE;
5446 LOP(OP_WAITPID,XTERM);
5455 ctl_l[0] = toCTRL('L');
5457 gv_fetchpv(ctl_l,TRUE, SVt_PV);
5460 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
5465 if (PL_expect == XOPERATOR)
5471 yylval.ival = OP_XOR;
5476 TERM(sublex_start());
5481 #pragma segment Main
5485 S_pending_ident(pTHX)
5488 register I32 tmp = 0;
5489 /* pit holds the identifier we read and pending_ident is reset */
5490 char pit = PL_pending_ident;
5491 PL_pending_ident = 0;
5493 DEBUG_T({ PerlIO_printf(Perl_debug_log,
5494 "### Tokener saw identifier '%s'\n", PL_tokenbuf); });
5496 /* if we're in a my(), we can't allow dynamics here.
5497 $foo'bar has already been turned into $foo::bar, so
5498 just check for colons.
5500 if it's a legal name, the OP is a PADANY.
5503 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
5504 if (strchr(PL_tokenbuf,':'))
5505 yyerror(Perl_form(aTHX_ "No package name allowed for "
5506 "variable %s in \"our\"",
5508 tmp = allocmy(PL_tokenbuf);
5511 if (strchr(PL_tokenbuf,':'))
5512 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
5514 yylval.opval = newOP(OP_PADANY, 0);
5515 yylval.opval->op_targ = allocmy(PL_tokenbuf);
5521 build the ops for accesses to a my() variable.
5523 Deny my($a) or my($b) in a sort block, *if* $a or $b is
5524 then used in a comparison. This catches most, but not
5525 all cases. For instance, it catches
5526 sort { my($a); $a <=> $b }
5528 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
5529 (although why you'd do that is anyone's guess).
5532 if (!strchr(PL_tokenbuf,':')) {
5534 tmp = pad_findmy(PL_tokenbuf);
5535 if (tmp != NOT_IN_PAD) {
5536 /* might be an "our" variable" */
5537 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
5538 /* build ops for a bareword */
5539 SV *sym = newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)), 0);
5540 sv_catpvn(sym, "::", 2);
5541 sv_catpv(sym, PL_tokenbuf+1);
5542 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
5543 yylval.opval->op_private = OPpCONST_ENTERED;
5546 ? (GV_ADDMULTI | GV_ADDINEVAL)
5549 ((PL_tokenbuf[0] == '$') ? SVt_PV
5550 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5555 /* if it's a sort block and they're naming $a or $b */
5556 if (PL_last_lop_op == OP_SORT &&
5557 PL_tokenbuf[0] == '$' &&
5558 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
5561 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
5562 d < PL_bufend && *d != '\n';
5565 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
5566 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
5572 yylval.opval = newOP(OP_PADANY, 0);
5573 yylval.opval->op_targ = tmp;
5579 Whine if they've said @foo in a doublequoted string,
5580 and @foo isn't a variable we can find in the symbol
5583 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
5584 GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
5585 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
5586 && ckWARN(WARN_AMBIGUOUS))
5588 /* Downgraded from fatal to warning 20000522 mjd */
5589 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5590 "Possible unintended interpolation of %s in string",
5595 /* build ops for a bareword */
5596 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
5597 yylval.opval->op_private = OPpCONST_ENTERED;
5598 gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
5599 ((PL_tokenbuf[0] == '$') ? SVt_PV
5600 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5606 * The following code was generated by perl_keyword.pl.
5610 Perl_keyword (pTHX_ const char *name, I32 len)
5614 case 1: /* 5 tokens of length 1 */
5646 case 2: /* 18 tokens of length 2 */
5792 case 3: /* 28 tokens of length 3 */
5796 if (name[1] == 'N' &&
5859 if (name[1] == 'i' &&
5899 if (name[1] == 'o' &&
5908 if (name[1] == 'e' &&
5917 if (name[1] == 'n' &&
5926 if (name[1] == 'o' &&
5935 if (name[1] == 'a' &&
5944 if (name[1] == 'o' &&
6006 if (name[1] == 'e' &&
6038 if (name[1] == 'i' &&
6047 if (name[1] == 's' &&
6056 if (name[1] == 'e' &&
6065 if (name[1] == 'o' &&
6077 case 4: /* 40 tokens of length 4 */
6081 if (name[1] == 'O' &&
6091 if (name[1] == 'N' &&
6101 if (name[1] == 'i' &&
6111 if (name[1] == 'h' &&
6121 if (name[1] == 'u' &&
6134 if (name[2] == 'c' &&
6143 if (name[2] == 's' &&
6152 if (name[2] == 'a' &&
6188 if (name[1] == 'o' &&
6201 if (name[2] == 't' &&
6210 if (name[2] == 'o' &&
6219 if (name[2] == 't' &&
6228 if (name[2] == 'e' &&
6241 if (name[1] == 'o' &&
6254 if (name[2] == 'y' &&
6263 if (name[2] == 'l' &&
6279 if (name[2] == 's' &&
6288 if (name[2] == 'n' &&
6297 if (name[2] == 'c' &&
6310 if (name[1] == 'e' &&
6320 if (name[1] == 'p' &&
6333 if (name[2] == 'c' &&
6342 if (name[2] == 'p' &&
6351 if (name[2] == 's' &&
6367 if (name[2] == 'n' &&
6437 if (name[2] == 'r' &&
6446 if (name[2] == 'r' &&
6455 if (name[2] == 'a' &&
6471 if (name[2] == 'l' &&
6538 case 5: /* 36 tokens of length 5 */
6542 if (name[1] == 'E' &&
6553 if (name[1] == 'H' &&
6567 if (name[2] == 'a' &&
6577 if (name[2] == 'a' &&
6591 if (name[1] == 'l' &&
6608 if (name[3] == 'i' &&
6617 if (name[3] == 'o' &&
6653 if (name[2] == 'o' &&
6663 if (name[2] == 'y' &&
6677 if (name[1] == 'l' &&
6691 if (name[2] == 'n' &&
6701 if (name[2] == 'o' &&
6718 if (name[2] == 'd' &&
6728 if (name[2] == 'c' &&
6745 if (name[2] == 'c' &&
6755 if (name[2] == 't' &&
6769 if (name[1] == 'k' &&
6780 if (name[1] == 'r' &&
6794 if (name[2] == 's' &&
6804 if (name[2] == 'd' &&
6821 if (name[2] == 'm' &&
6831 if (name[2] == 'i' &&
6841 if (name[2] == 'e' &&
6851 if (name[2] == 'l' &&
6861 if (name[2] == 'a' &&
6871 if (name[2] == 'u' &&
6885 if (name[1] == 'i' &&
6899 if (name[2] == 'a' &&
6912 if (name[3] == 'e' &&
6947 if (name[2] == 'i' &&
6964 if (name[2] == 'i' &&
6974 if (name[2] == 'i' &&
6991 case 6: /* 33 tokens of length 6 */
6995 if (name[1] == 'c' &&
7010 if (name[2] == 'l' &&
7021 if (name[2] == 'r' &&
7036 if (name[1] == 'e' &&
7051 if (name[2] == 's' &&
7056 if(ckWARN_d(WARN_SYNTAX))
7057 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
7063 if (name[2] == 'i' &&
7081 if (name[2] == 'l' &&
7092 if (name[2] == 'r' &&
7107 if (name[1] == 'm' &&
7122 if (name[2] == 'n' &&
7133 if (name[2] == 's' &&
7148 if (name[1] == 's' &&
7154 if (name[4] == 't' &&
7163 if (name[4] == 'e' &&
7172 if (name[4] == 'c' &&
7181 if (name[4] == 'n' &&
7197 if (name[1] == 'r' &&
7215 if (name[3] == 'a' &&
7225 if (name[3] == 'u' &&
7239 if (name[2] == 'n' &&
7257 if (name[2] == 'a' &&
7271 if (name[3] == 'e' &&
7284 if (name[4] == 't' &&
7293 if (name[4] == 'e' &&
7315 if (name[4] == 't' &&
7324 if (name[4] == 'e' &&
7340 if (name[2] == 'c' &&
7351 if (name[2] == 'l' &&
7362 if (name[2] == 'b' &&
7373 if (name[2] == 's' &&
7396 if (name[4] == 's' &&
7405 if (name[4] == 'n' &&
7418 if (name[3] == 'a' &&
7435 if (name[1] == 'a' &&
7450 case 7: /* 28 tokens of length 7 */
7454 if (name[1] == 'E' &&
7467 if (name[1] == '_' &&
7480 if (name[1] == 'i' &&
7487 return -KEY_binmode;
7493 if (name[1] == 'o' &&
7500 return -KEY_connect;
7509 if (name[2] == 'm' &&
7515 return -KEY_dbmopen;
7521 if (name[2] == 'f' &&
7537 if (name[1] == 'o' &&
7550 if (name[1] == 'e' &&
7557 if (name[5] == 'r' &&
7560 return -KEY_getpgrp;
7566 if (name[5] == 'i' &&
7569 return -KEY_getppid;
7582 if (name[1] == 'c' &&
7589 return -KEY_lcfirst;
7595 if (name[1] == 'p' &&
7602 return -KEY_opendir;
7608 if (name[1] == 'a' &&
7626 if (name[3] == 'd' &&
7631 return -KEY_readdir;
7637 if (name[3] == 'u' &&
7648 if (name[3] == 'e' &&
7653 return -KEY_reverse;
7672 if (name[3] == 'k' &&
7677 return -KEY_seekdir;
7683 if (name[3] == 'p' &&
7688 return -KEY_setpgrp;
7698 if (name[2] == 'm' &&
7704 return -KEY_shmread;
7710 if (name[2] == 'r' &&
7716 return -KEY_sprintf;
7725 if (name[3] == 'l' &&
7730 return -KEY_symlink;
7739 if (name[4] == 'a' &&
7743 return -KEY_syscall;
7749 if (name[4] == 'p' &&
7753 return -KEY_sysopen;
7759 if (name[4] == 'e' &&
7763 return -KEY_sysread;
7769 if (name[4] == 'e' &&
7773 return -KEY_sysseek;
7791 if (name[1] == 'e' &&
7798 return -KEY_telldir;
7807 if (name[2] == 'f' &&
7813 return -KEY_ucfirst;
7819 if (name[2] == 's' &&
7825 return -KEY_unshift;
7835 if (name[1] == 'a' &&
7842 return -KEY_waitpid;
7851 case 8: /* 26 tokens of length 8 */
7855 if (name[1] == 'U' &&
7863 return KEY_AUTOLOAD;
7874 if (name[3] == 'A' &&
7880 return KEY___DATA__;
7886 if (name[3] == 'I' &&
7892 return -KEY___FILE__;
7898 if (name[3] == 'I' &&
7904 return -KEY___LINE__;
7920 if (name[2] == 'o' &&
7927 return -KEY_closedir;
7933 if (name[2] == 'n' &&
7940 return -KEY_continue;
7950 if (name[1] == 'b' &&
7958 return -KEY_dbmclose;
7964 if (name[1] == 'n' &&
7970 if (name[4] == 'r' &&
7975 return -KEY_endgrent;
7981 if (name[4] == 'w' &&
7986 return -KEY_endpwent;
7999 if (name[1] == 'o' &&
8007 return -KEY_formline;
8013 if (name[1] == 'e' &&
8024 if (name[6] == 'n' &&
8027 return -KEY_getgrent;
8033 if (name[6] == 'i' &&
8036 return -KEY_getgrgid;
8042 if (name[6] == 'a' &&
8045 return -KEY_getgrnam;
8058 if (name[4] == 'o' &&
8063 return -KEY_getlogin;
8074 if (name[6] == 'n' &&
8077 return -KEY_getpwent;
8083 if (name[6] == 'a' &&
8086 return -KEY_getpwnam;
8092 if (name[6] == 'i' &&
8095 return -KEY_getpwuid;
8115 if (name[1] == 'e' &&
8122 if (name[5] == 'i' &&
8129 return -KEY_readline;
8134 return -KEY_readlink;
8145 if (name[5] == 'i' &&
8149 return -KEY_readpipe;
8170 if (name[4] == 'r' &&
8175 return -KEY_setgrent;
8181 if (name[4] == 'w' &&
8186 return -KEY_setpwent;
8202 if (name[3] == 'w' &&
8208 return -KEY_shmwrite;
8214 if (name[3] == 't' &&
8220 return -KEY_shutdown;
8230 if (name[2] == 's' &&
8237 return -KEY_syswrite;
8247 if (name[1] == 'r' &&
8255 return -KEY_truncate;
8264 case 9: /* 8 tokens of length 9 */
8268 if (name[1] == 'n' &&
8277 return -KEY_endnetent;
8283 if (name[1] == 'e' &&
8292 return -KEY_getnetent;
8298 if (name[1] == 'o' &&
8307 return -KEY_localtime;
8313 if (name[1] == 'r' &&
8322 return KEY_prototype;
8328 if (name[1] == 'u' &&
8337 return -KEY_quotemeta;
8343 if (name[1] == 'e' &&
8352 return -KEY_rewinddir;
8358 if (name[1] == 'e' &&
8367 return -KEY_setnetent;
8373 if (name[1] == 'a' &&
8382 return -KEY_wantarray;
8391 case 10: /* 9 tokens of length 10 */
8395 if (name[1] == 'n' &&
8401 if (name[4] == 'o' &&
8408 return -KEY_endhostent;
8414 if (name[4] == 'e' &&
8421 return -KEY_endservent;
8434 if (name[1] == 'e' &&
8440 if (name[4] == 'o' &&
8447 return -KEY_gethostent;
8456 if (name[5] == 'r' &&
8462 return -KEY_getservent;
8468 if (name[5] == 'c' &&
8474 return -KEY_getsockopt;
8499 if (name[4] == 'o' &&
8506 return -KEY_sethostent;
8515 if (name[5] == 'r' &&
8521 return -KEY_setservent;
8527 if (name[5] == 'c' &&
8533 return -KEY_setsockopt;
8550 if (name[2] == 'c' &&
8559 return -KEY_socketpair;
8572 case 11: /* 8 tokens of length 11 */
8576 if (name[1] == '_' &&
8587 return -KEY___PACKAGE__;
8593 if (name[1] == 'n' &&
8604 return -KEY_endprotoent;
8610 if (name[1] == 'e' &&
8619 if (name[5] == 'e' &&
8626 return -KEY_getpeername;
8635 if (name[6] == 'o' &&
8641 return -KEY_getpriority;
8647 if (name[6] == 't' &&
8653 return -KEY_getprotoent;
8667 if (name[4] == 'o' &&
8675 return -KEY_getsockname;
8688 if (name[1] == 'e' &&
8696 if (name[6] == 'o' &&
8702 return -KEY_setpriority;
8708 if (name[6] == 't' &&
8714 return -KEY_setprotoent;
8730 case 12: /* 2 tokens of length 12 */
8731 if (name[0] == 'g' &&
8743 if (name[9] == 'd' &&
8746 { /* getnetbyaddr */
8747 return -KEY_getnetbyaddr;
8753 if (name[9] == 'a' &&
8756 { /* getnetbyname */
8757 return -KEY_getnetbyname;
8769 case 13: /* 4 tokens of length 13 */
8770 if (name[0] == 'g' &&
8777 if (name[4] == 'o' &&
8786 if (name[10] == 'd' &&
8789 { /* gethostbyaddr */
8790 return -KEY_gethostbyaddr;
8796 if (name[10] == 'a' &&
8799 { /* gethostbyname */
8800 return -KEY_gethostbyname;
8813 if (name[4] == 'e' &&
8822 if (name[10] == 'a' &&
8825 { /* getservbyname */
8826 return -KEY_getservbyname;
8832 if (name[10] == 'o' &&
8835 { /* getservbyport */
8836 return -KEY_getservbyport;
8855 case 14: /* 1 tokens of length 14 */
8856 if (name[0] == 'g' &&
8870 { /* getprotobyname */
8871 return -KEY_getprotobyname;
8876 case 16: /* 1 tokens of length 16 */
8877 if (name[0] == 'g' &&
8893 { /* getprotobynumber */
8894 return -KEY_getprotobynumber;
8908 S_checkcomma(pTHX_ register char *s, const char *name, const char *what)
8912 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
8913 if (ckWARN(WARN_SYNTAX)) {
8915 for (w = s+2; *w && level; w++) {
8922 for (; *w && isSPACE(*w); w++) ;
8923 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
8924 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
8925 "%s (...) interpreted as function",name);
8928 while (s < PL_bufend && isSPACE(*s))
8932 while (s < PL_bufend && isSPACE(*s))
8934 if (isIDFIRST_lazy_if(s,UTF)) {
8936 while (isALNUM_lazy_if(s,UTF))
8938 while (s < PL_bufend && isSPACE(*s))
8942 *s = '\0'; /* XXX If we didn't do this, we could const a lot of toke.c */
8943 kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
8947 Perl_croak(aTHX_ "No comma allowed after %s", what);
8952 /* Either returns sv, or mortalizes sv and returns a new SV*.
8953 Best used as sv=new_constant(..., sv, ...).
8954 If s, pv are NULL, calls subroutine with one argument,
8955 and type is used with error messages only. */
8958 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
8962 HV *table = GvHV(PL_hintgv); /* ^H */
8966 const char *why1, *why2, *why3;
8968 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
8971 why2 = strEQ(key,"charnames")
8972 ? "(possibly a missing \"use charnames ...\")"
8974 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
8975 (type ? type: "undef"), why2);
8977 /* This is convoluted and evil ("goto considered harmful")
8978 * but I do not understand the intricacies of all the different
8979 * failure modes of %^H in here. The goal here is to make
8980 * the most probable error message user-friendly. --jhi */
8985 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
8986 (type ? type: "undef"), why1, why2, why3);
8988 yyerror(SvPVX(msg));
8992 cvp = hv_fetch(table, key, strlen(key), FALSE);
8993 if (!cvp || !SvOK(*cvp)) {
8996 why3 = "} is not defined";
8999 sv_2mortal(sv); /* Parent created it permanently */
9002 pv = sv_2mortal(newSVpvn(s, len));
9004 typesv = sv_2mortal(newSVpv(type, 0));
9006 typesv = &PL_sv_undef;
9008 PUSHSTACKi(PERLSI_OVERLOAD);
9020 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
9024 /* Check the eval first */
9025 if (!PL_in_eval && SvTRUE(ERRSV)) {
9027 sv_catpv(ERRSV, "Propagated");
9028 yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */
9030 res = SvREFCNT_inc(sv);
9034 (void)SvREFCNT_inc(res);
9043 why1 = "Call to &{$^H{";
9045 why3 = "}} did not return a defined value";
9053 /* Returns a NUL terminated string, with the length of the string written to
9057 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
9059 register char *d = dest;
9060 register char *e = d + destlen - 3; /* two-character token, ending NUL */
9063 Perl_croak(aTHX_ ident_too_long);
9064 if (isALNUM(*s)) /* UTF handled below */
9066 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
9071 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
9075 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9076 char *t = s + UTF8SKIP(s);
9077 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9079 if (d + (t - s) > e)
9080 Perl_croak(aTHX_ ident_too_long);
9081 Copy(s, d, t - s, char);
9094 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
9104 e = d + destlen - 3; /* two-character token, ending NUL */
9106 while (isDIGIT(*s)) {
9108 Perl_croak(aTHX_ ident_too_long);
9115 Perl_croak(aTHX_ ident_too_long);
9116 if (isALNUM(*s)) /* UTF handled below */
9118 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
9123 else if (*s == ':' && s[1] == ':') {
9127 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9128 char *t = s + UTF8SKIP(s);
9129 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9131 if (d + (t - s) > e)
9132 Perl_croak(aTHX_ ident_too_long);
9133 Copy(s, d, t - s, char);
9144 if (PL_lex_state != LEX_NORMAL)
9145 PL_lex_state = LEX_INTERPENDMAYBE;
9148 if (*s == '$' && s[1] &&
9149 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
9162 if (*d == '^' && *s && isCONTROLVAR(*s)) {
9167 if (isSPACE(s[-1])) {
9169 const char ch = *s++;
9170 if (!SPACE_OR_TAB(ch)) {
9176 if (isIDFIRST_lazy_if(d,UTF)) {
9180 while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') {
9182 while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e))
9185 Copy(s, d, e - s, char);
9190 while ((isALNUM(*s) || *s == ':') && d < e)
9193 Perl_croak(aTHX_ ident_too_long);
9196 while (s < send && SPACE_OR_TAB(*s)) s++;
9197 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
9198 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
9199 const char *brack = *s == '[' ? "[...]" : "{...}";
9200 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9201 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
9202 funny, dest, brack, funny, dest, brack);
9205 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
9209 /* Handle extended ${^Foo} variables
9210 * 1999-02-27 mjd-perl-patch@plover.com */
9211 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
9215 while (isALNUM(*s) && d < e) {
9219 Perl_croak(aTHX_ ident_too_long);
9224 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
9225 PL_lex_state = LEX_INTERPEND;
9230 if (PL_lex_state == LEX_NORMAL) {
9231 if (ckWARN(WARN_AMBIGUOUS) &&
9232 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
9234 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9235 "Ambiguous use of %c{%s} resolved to %c%s",
9236 funny, dest, funny, dest);
9241 s = bracket; /* let the parser handle it */
9245 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
9246 PL_lex_state = LEX_INTERPEND;
9251 Perl_pmflag(pTHX_ U32* pmfl, int ch)
9256 *pmfl |= PMf_GLOBAL;
9258 *pmfl |= PMf_CONTINUE;
9262 *pmfl |= PMf_MULTILINE;
9264 *pmfl |= PMf_SINGLELINE;
9266 *pmfl |= PMf_EXTENDED;
9270 S_scan_pat(pTHX_ char *start, I32 type)
9273 char *s = scan_str(start,FALSE,FALSE);
9276 Perl_croak(aTHX_ "Search pattern not terminated");
9278 pm = (PMOP*)newPMOP(type, 0);
9279 if (PL_multi_open == '?')
9280 pm->op_pmflags |= PMf_ONCE;
9282 while (*s && strchr("iomsx", *s))
9283 pmflag(&pm->op_pmflags,*s++);
9286 while (*s && strchr("iogcmsx", *s))
9287 pmflag(&pm->op_pmflags,*s++);
9289 /* issue a warning if /c is specified,but /g is not */
9290 if (ckWARN(WARN_REGEXP) &&
9291 (pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
9293 Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_without_g);
9296 pm->op_pmpermflags = pm->op_pmflags;
9298 PL_lex_op = (OP*)pm;
9299 yylval.ival = OP_MATCH;
9304 S_scan_subst(pTHX_ char *start)
9312 yylval.ival = OP_NULL;
9314 s = scan_str(start,FALSE,FALSE);
9317 Perl_croak(aTHX_ "Substitution pattern not terminated");
9319 if (s[-1] == PL_multi_open)
9322 first_start = PL_multi_start;
9323 s = scan_str(s,FALSE,FALSE);
9326 SvREFCNT_dec(PL_lex_stuff);
9327 PL_lex_stuff = Nullsv;
9329 Perl_croak(aTHX_ "Substitution replacement not terminated");
9331 PL_multi_start = first_start; /* so whole substitution is taken together */
9333 pm = (PMOP*)newPMOP(OP_SUBST, 0);
9339 else if (strchr("iogcmsx", *s))
9340 pmflag(&pm->op_pmflags,*s++);
9345 /* /c is not meaningful with s/// */
9346 if (ckWARN(WARN_REGEXP) && (pm->op_pmflags & PMf_CONTINUE))
9348 Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_in_subst);
9353 PL_sublex_info.super_bufptr = s;
9354 PL_sublex_info.super_bufend = PL_bufend;
9356 pm->op_pmflags |= PMf_EVAL;
9357 repl = newSVpvn("",0);
9359 sv_catpv(repl, es ? "eval " : "do ");
9360 sv_catpvn(repl, "{ ", 2);
9361 sv_catsv(repl, PL_lex_repl);
9362 sv_catpvn(repl, " };", 2);
9364 SvREFCNT_dec(PL_lex_repl);
9368 pm->op_pmpermflags = pm->op_pmflags;
9369 PL_lex_op = (OP*)pm;
9370 yylval.ival = OP_SUBST;
9375 S_scan_trans(pTHX_ char *start)
9384 yylval.ival = OP_NULL;
9386 s = scan_str(start,FALSE,FALSE);
9388 Perl_croak(aTHX_ "Transliteration pattern not terminated");
9389 if (s[-1] == PL_multi_open)
9392 s = scan_str(s,FALSE,FALSE);
9395 SvREFCNT_dec(PL_lex_stuff);
9396 PL_lex_stuff = Nullsv;
9398 Perl_croak(aTHX_ "Transliteration replacement not terminated");
9401 complement = del = squash = 0;
9405 complement = OPpTRANS_COMPLEMENT;
9408 del = OPpTRANS_DELETE;
9411 squash = OPpTRANS_SQUASH;
9420 New(803, tbl, complement&&!del?258:256, short);
9421 o = newPVOP(OP_TRANS, 0, (char*)tbl);
9422 o->op_private &= ~OPpTRANS_ALL;
9423 o->op_private |= del|squash|complement|
9424 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
9425 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
9428 yylval.ival = OP_TRANS;
9433 S_scan_heredoc(pTHX_ register char *s)
9436 I32 op_type = OP_SCALAR;
9440 const char newline[] = "\n";
9441 const char *found_newline;
9445 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
9449 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
9452 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
9453 if (*peek == '`' || *peek == '\'' || *peek =='"') {
9456 s = delimcpy(d, e, s, PL_bufend, term, &len);
9466 if (!isALNUM_lazy_if(s,UTF))
9467 deprecate_old("bare << to mean <<\"\"");
9468 for (; isALNUM_lazy_if(s,UTF); s++) {
9473 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
9474 Perl_croak(aTHX_ "Delimiter for here document is too long");
9477 len = d - PL_tokenbuf;
9478 #ifndef PERL_STRICT_CR
9479 d = strchr(s, '\r');
9483 while (s < PL_bufend) {
9489 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
9498 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
9502 if ( outer || !(found_newline = ninstr(s,PL_bufend,newline,newline+1)) ) {
9503 herewas = newSVpvn(s,PL_bufend-s);
9507 herewas = newSVpvn(s,found_newline-s);
9509 s += SvCUR(herewas);
9511 tmpstr = NEWSV(87,79);
9512 sv_upgrade(tmpstr, SVt_PVIV);
9515 SvIV_set(tmpstr, -1);
9517 else if (term == '`') {
9518 op_type = OP_BACKTICK;
9519 SvIV_set(tmpstr, '\\');
9523 PL_multi_start = CopLINE(PL_curcop);
9524 PL_multi_open = PL_multi_close = '<';
9525 term = *PL_tokenbuf;
9526 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
9527 char *bufptr = PL_sublex_info.super_bufptr;
9528 char *bufend = PL_sublex_info.super_bufend;
9529 char *olds = s - SvCUR(herewas);
9530 s = strchr(bufptr, '\n');
9534 while (s < bufend &&
9535 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9537 CopLINE_inc(PL_curcop);
9540 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9541 missingterm(PL_tokenbuf);
9543 sv_setpvn(herewas,bufptr,d-bufptr+1);
9544 sv_setpvn(tmpstr,d+1,s-d);
9546 sv_catpvn(herewas,s,bufend-s);
9547 Copy(SvPVX(herewas),bufptr,SvCUR(herewas) + 1,char);
9554 while (s < PL_bufend &&
9555 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9557 CopLINE_inc(PL_curcop);
9559 if (s >= PL_bufend) {
9560 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9561 missingterm(PL_tokenbuf);
9563 sv_setpvn(tmpstr,d+1,s-d);
9565 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
9567 sv_catpvn(herewas,s,PL_bufend-s);
9568 sv_setsv(PL_linestr,herewas);
9569 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
9570 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9571 PL_last_lop = PL_last_uni = Nullch;
9574 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
9575 while (s >= PL_bufend) { /* multiple line string? */
9577 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
9578 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9579 missingterm(PL_tokenbuf);
9581 CopLINE_inc(PL_curcop);
9582 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9583 PL_last_lop = PL_last_uni = Nullch;
9584 #ifndef PERL_STRICT_CR
9585 if (PL_bufend - PL_linestart >= 2) {
9586 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
9587 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
9589 PL_bufend[-2] = '\n';
9591 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
9593 else if (PL_bufend[-1] == '\r')
9594 PL_bufend[-1] = '\n';
9596 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
9597 PL_bufend[-1] = '\n';
9599 if (PERLDB_LINE && PL_curstash != PL_debstash) {
9600 SV *sv = NEWSV(88,0);
9602 sv_upgrade(sv, SVt_PVMG);
9603 sv_setsv(sv,PL_linestr);
9606 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
9608 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
9609 STRLEN off = PL_bufend - 1 - SvPVX(PL_linestr);
9610 *(SvPVX(PL_linestr) + off ) = ' ';
9611 sv_catsv(PL_linestr,herewas);
9612 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9613 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
9617 sv_catsv(tmpstr,PL_linestr);
9622 PL_multi_end = CopLINE(PL_curcop);
9623 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
9624 SvPV_shrink_to_cur(tmpstr);
9626 SvREFCNT_dec(herewas);
9628 if (UTF && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr)))
9630 else if (PL_encoding)
9631 sv_recode_to_utf8(tmpstr, PL_encoding);
9633 PL_lex_stuff = tmpstr;
9634 yylval.ival = op_type;
9639 takes: current position in input buffer
9640 returns: new position in input buffer
9641 side-effects: yylval and lex_op are set.
9646 <FH> read from filehandle
9647 <pkg::FH> read from package qualified filehandle
9648 <pkg'FH> read from package qualified filehandle
9649 <$fh> read from filehandle in $fh
9655 S_scan_inputsymbol(pTHX_ char *start)
9657 register char *s = start; /* current position in buffer */
9663 d = PL_tokenbuf; /* start of temp holding space */
9664 e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
9665 end = strchr(s, '\n');
9668 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
9670 /* die if we didn't have space for the contents of the <>,
9671 or if it didn't end, or if we see a newline
9674 if (len >= sizeof PL_tokenbuf)
9675 Perl_croak(aTHX_ "Excessively long <> operator");
9677 Perl_croak(aTHX_ "Unterminated <> operator");
9682 Remember, only scalar variables are interpreted as filehandles by
9683 this code. Anything more complex (e.g., <$fh{$num}>) will be
9684 treated as a glob() call.
9685 This code makes use of the fact that except for the $ at the front,
9686 a scalar variable and a filehandle look the same.
9688 if (*d == '$' && d[1]) d++;
9690 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
9691 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
9694 /* If we've tried to read what we allow filehandles to look like, and
9695 there's still text left, then it must be a glob() and not a getline.
9696 Use scan_str to pull out the stuff between the <> and treat it
9697 as nothing more than a string.
9700 if (d - PL_tokenbuf != len) {
9701 yylval.ival = OP_GLOB;
9703 s = scan_str(start,FALSE,FALSE);
9705 Perl_croak(aTHX_ "Glob not terminated");
9709 bool readline_overriden = FALSE;
9710 GV *gv_readline = Nullgv;
9712 /* we're in a filehandle read situation */
9715 /* turn <> into <ARGV> */
9717 Copy("ARGV",d,5,char);
9719 /* Check whether readline() is overriden */
9720 if (((gv_readline = gv_fetchpv("readline", FALSE, SVt_PVCV))
9721 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
9723 ((gvp = (GV**)hv_fetch(PL_globalstash, "readline", 8, FALSE))
9724 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
9725 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
9726 readline_overriden = TRUE;
9728 /* if <$fh>, create the ops to turn the variable into a
9734 /* try to find it in the pad for this block, otherwise find
9735 add symbol table ops
9737 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
9738 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
9739 SV *sym = sv_2mortal(
9740 newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)),0));
9741 sv_catpvn(sym, "::", 2);
9747 OP *o = newOP(OP_PADSV, 0);
9749 PL_lex_op = readline_overriden
9750 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9751 append_elem(OP_LIST, o,
9752 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
9753 : (OP*)newUNOP(OP_READLINE, 0, o);
9762 ? (GV_ADDMULTI | GV_ADDINEVAL)
9765 PL_lex_op = readline_overriden
9766 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9767 append_elem(OP_LIST,
9768 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
9769 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9770 : (OP*)newUNOP(OP_READLINE, 0,
9771 newUNOP(OP_RV2SV, 0,
9772 newGVOP(OP_GV, 0, gv)));
9774 if (!readline_overriden)
9775 PL_lex_op->op_flags |= OPf_SPECIAL;
9776 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
9777 yylval.ival = OP_NULL;
9780 /* If it's none of the above, it must be a literal filehandle
9781 (<Foo::BAR> or <FOO>) so build a simple readline OP */
9783 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
9784 PL_lex_op = readline_overriden
9785 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9786 append_elem(OP_LIST,
9787 newGVOP(OP_GV, 0, gv),
9788 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9789 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
9790 yylval.ival = OP_NULL;
9799 takes: start position in buffer
9800 keep_quoted preserve \ on the embedded delimiter(s)
9801 keep_delims preserve the delimiters around the string
9802 returns: position to continue reading from buffer
9803 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
9804 updates the read buffer.
9806 This subroutine pulls a string out of the input. It is called for:
9807 q single quotes q(literal text)
9808 ' single quotes 'literal text'
9809 qq double quotes qq(interpolate $here please)
9810 " double quotes "interpolate $here please"
9811 qx backticks qx(/bin/ls -l)
9812 ` backticks `/bin/ls -l`
9813 qw quote words @EXPORT_OK = qw( func() $spam )
9814 m// regexp match m/this/
9815 s/// regexp substitute s/this/that/
9816 tr/// string transliterate tr/this/that/
9817 y/// string transliterate y/this/that/
9818 ($*@) sub prototypes sub foo ($)
9819 (stuff) sub attr parameters sub foo : attr(stuff)
9820 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
9822 In most of these cases (all but <>, patterns and transliterate)
9823 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
9824 calls scan_str(). s/// makes yylex() call scan_subst() which calls
9825 scan_str(). tr/// and y/// make yylex() call scan_trans() which
9828 It skips whitespace before the string starts, and treats the first
9829 character as the delimiter. If the delimiter is one of ([{< then
9830 the corresponding "close" character )]}> is used as the closing
9831 delimiter. It allows quoting of delimiters, and if the string has
9832 balanced delimiters ([{<>}]) it allows nesting.
9834 On success, the SV with the resulting string is put into lex_stuff or,
9835 if that is already non-NULL, into lex_repl. The second case occurs only
9836 when parsing the RHS of the special constructs s/// and tr/// (y///).
9837 For convenience, the terminating delimiter character is stuffed into
9842 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
9844 SV *sv; /* scalar value: string */
9845 char *tmps; /* temp string, used for delimiter matching */
9846 register char *s = start; /* current position in the buffer */
9847 register char term; /* terminating character */
9848 register char *to; /* current position in the sv's data */
9849 I32 brackets = 1; /* bracket nesting level */
9850 bool has_utf8 = FALSE; /* is there any utf8 content? */
9851 I32 termcode; /* terminating char. code */
9852 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
9853 STRLEN termlen; /* length of terminating string */
9854 char *last = NULL; /* last position for nesting bracket */
9856 /* skip space before the delimiter */
9860 /* mark where we are, in case we need to report errors */
9863 /* after skipping whitespace, the next character is the terminator */
9866 termcode = termstr[0] = term;
9870 termcode = utf8_to_uvchr((U8*)s, &termlen);
9871 Copy(s, termstr, termlen, U8);
9872 if (!UTF8_IS_INVARIANT(term))
9876 /* mark where we are */
9877 PL_multi_start = CopLINE(PL_curcop);
9878 PL_multi_open = term;
9880 /* find corresponding closing delimiter */
9881 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
9882 termcode = termstr[0] = term = tmps[5];
9884 PL_multi_close = term;
9886 /* create a new SV to hold the contents. 87 is leak category, I'm
9887 assuming. 79 is the SV's initial length. What a random number. */
9889 sv_upgrade(sv, SVt_PVIV);
9890 SvIV_set(sv, termcode);
9891 (void)SvPOK_only(sv); /* validate pointer */
9893 /* move past delimiter and try to read a complete string */
9895 sv_catpvn(sv, s, termlen);
9898 if (PL_encoding && !UTF) {
9902 int offset = s - SvPVX(PL_linestr);
9903 bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
9904 &offset, (char*)termstr, termlen);
9905 char *ns = SvPVX(PL_linestr) + offset;
9906 char *svlast = SvEND(sv) - 1;
9908 for (; s < ns; s++) {
9909 if (*s == '\n' && !PL_rsfp)
9910 CopLINE_inc(PL_curcop);
9913 goto read_more_line;
9915 /* handle quoted delimiters */
9916 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
9918 for (t = svlast-2; t >= SvPVX(sv) && *t == '\\';)
9920 if ((svlast-1 - t) % 2) {
9924 SvCUR_set(sv, SvCUR(sv) - 1);
9929 if (PL_multi_open == PL_multi_close) {
9937 for (t = w = last; t < svlast; w++, t++) {
9938 /* At here, all closes are "was quoted" one,
9939 so we don't check PL_multi_close. */
9941 if (!keep_quoted && *(t+1) == PL_multi_open)
9946 else if (*t == PL_multi_open)
9954 SvCUR_set(sv, w - SvPVX(sv));
9957 if (--brackets <= 0)
9963 SvCUR_set(sv, SvCUR(sv) - 1);
9969 /* extend sv if need be */
9970 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
9971 /* set 'to' to the next character in the sv's string */
9972 to = SvPVX(sv)+SvCUR(sv);
9974 /* if open delimiter is the close delimiter read unbridle */
9975 if (PL_multi_open == PL_multi_close) {
9976 for (; s < PL_bufend; s++,to++) {
9977 /* embedded newlines increment the current line number */
9978 if (*s == '\n' && !PL_rsfp)
9979 CopLINE_inc(PL_curcop);
9980 /* handle quoted delimiters */
9981 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
9982 if (!keep_quoted && s[1] == term)
9984 /* any other quotes are simply copied straight through */
9988 /* terminate when run out of buffer (the for() condition), or
9989 have found the terminator */
9990 else if (*s == term) {
9993 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
9996 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
10002 /* if the terminator isn't the same as the start character (e.g.,
10003 matched brackets), we have to allow more in the quoting, and
10004 be prepared for nested brackets.
10007 /* read until we run out of string, or we find the terminator */
10008 for (; s < PL_bufend; s++,to++) {
10009 /* embedded newlines increment the line count */
10010 if (*s == '\n' && !PL_rsfp)
10011 CopLINE_inc(PL_curcop);
10012 /* backslashes can escape the open or closing characters */
10013 if (*s == '\\' && s+1 < PL_bufend) {
10014 if (!keep_quoted &&
10015 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
10020 /* allow nested opens and closes */
10021 else if (*s == PL_multi_close && --brackets <= 0)
10023 else if (*s == PL_multi_open)
10025 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
10030 /* terminate the copied string and update the sv's end-of-string */
10032 SvCUR_set(sv, to - SvPVX(sv));
10035 * this next chunk reads more into the buffer if we're not done yet
10039 break; /* handle case where we are done yet :-) */
10041 #ifndef PERL_STRICT_CR
10042 if (to - SvPVX(sv) >= 2) {
10043 if ((to[-2] == '\r' && to[-1] == '\n') ||
10044 (to[-2] == '\n' && to[-1] == '\r'))
10048 SvCUR_set(sv, to - SvPVX(sv));
10050 else if (to[-1] == '\r')
10053 else if (to - SvPVX(sv) == 1 && to[-1] == '\r')
10058 /* if we're out of file, or a read fails, bail and reset the current
10059 line marker so we can report where the unterminated string began
10062 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
10064 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10067 /* we read a line, so increment our line counter */
10068 CopLINE_inc(PL_curcop);
10070 /* update debugger info */
10071 if (PERLDB_LINE && PL_curstash != PL_debstash) {
10072 SV *sv = NEWSV(88,0);
10074 sv_upgrade(sv, SVt_PVMG);
10075 sv_setsv(sv,PL_linestr);
10076 (void)SvIOK_on(sv);
10078 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
10081 /* having changed the buffer, we must update PL_bufend */
10082 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10083 PL_last_lop = PL_last_uni = Nullch;
10086 /* at this point, we have successfully read the delimited string */
10088 if (!PL_encoding || UTF) {
10090 sv_catpvn(sv, s, termlen);
10093 if (has_utf8 || PL_encoding)
10096 PL_multi_end = CopLINE(PL_curcop);
10098 /* if we allocated too much space, give some back */
10099 if (SvCUR(sv) + 5 < SvLEN(sv)) {
10100 SvLEN_set(sv, SvCUR(sv) + 1);
10101 SvPV_renew(sv, SvLEN(sv));
10104 /* decide whether this is the first or second quoted string we've read
10117 takes: pointer to position in buffer
10118 returns: pointer to new position in buffer
10119 side-effects: builds ops for the constant in yylval.op
10121 Read a number in any of the formats that Perl accepts:
10123 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
10124 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
10127 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
10129 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
10132 If it reads a number without a decimal point or an exponent, it will
10133 try converting the number to an integer and see if it can do so
10134 without loss of precision.
10138 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
10140 register const char *s = start; /* current position in buffer */
10141 register char *d; /* destination in temp buffer */
10142 register char *e; /* end of temp buffer */
10143 NV nv; /* number read, as a double */
10144 SV *sv = Nullsv; /* place to put the converted number */
10145 bool floatit; /* boolean: int or float? */
10146 const char *lastub = 0; /* position of last underbar */
10147 static char const number_too_long[] = "Number too long";
10149 /* We use the first character to decide what type of number this is */
10153 Perl_croak(aTHX_ "panic: scan_num");
10155 /* if it starts with a 0, it could be an octal number, a decimal in
10156 0.13 disguise, or a hexadecimal number, or a binary number. */
10160 u holds the "number so far"
10161 shift the power of 2 of the base
10162 (hex == 4, octal == 3, binary == 1)
10163 overflowed was the number more than we can hold?
10165 Shift is used when we add a digit. It also serves as an "are
10166 we in octal/hex/binary?" indicator to disallow hex characters
10167 when in octal mode.
10172 bool overflowed = FALSE;
10173 bool just_zero = TRUE; /* just plain 0 or binary number? */
10174 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
10175 static const char* const bases[5] =
10176 { "", "binary", "", "octal", "hexadecimal" };
10177 static const char* const Bases[5] =
10178 { "", "Binary", "", "Octal", "Hexadecimal" };
10179 static const char* const maxima[5] =
10181 "0b11111111111111111111111111111111",
10185 const char *base, *Base, *max;
10187 /* check for hex */
10192 } else if (s[1] == 'b') {
10197 /* check for a decimal in disguise */
10198 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
10200 /* so it must be octal */
10207 if (ckWARN(WARN_SYNTAX))
10208 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10209 "Misplaced _ in number");
10213 base = bases[shift];
10214 Base = Bases[shift];
10215 max = maxima[shift];
10217 /* read the rest of the number */
10219 /* x is used in the overflow test,
10220 b is the digit we're adding on. */
10225 /* if we don't mention it, we're done */
10229 /* _ are ignored -- but warned about if consecutive */
10231 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10232 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10233 "Misplaced _ in number");
10237 /* 8 and 9 are not octal */
10238 case '8': case '9':
10240 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
10244 case '2': case '3': case '4':
10245 case '5': case '6': case '7':
10247 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
10250 case '0': case '1':
10251 b = *s++ & 15; /* ASCII digit -> value of digit */
10255 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
10256 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
10257 /* make sure they said 0x */
10260 b = (*s++ & 7) + 9;
10262 /* Prepare to put the digit we have onto the end
10263 of the number so far. We check for overflows.
10269 x = u << shift; /* make room for the digit */
10271 if ((x >> shift) != u
10272 && !(PL_hints & HINT_NEW_BINARY)) {
10275 if (ckWARN_d(WARN_OVERFLOW))
10276 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
10277 "Integer overflow in %s number",
10280 u = x | b; /* add the digit to the end */
10283 n *= nvshift[shift];
10284 /* If an NV has not enough bits in its
10285 * mantissa to represent an UV this summing of
10286 * small low-order numbers is a waste of time
10287 * (because the NV cannot preserve the
10288 * low-order bits anyway): we could just
10289 * remember when did we overflow and in the
10290 * end just multiply n by the right
10298 /* if we get here, we had success: make a scalar value from
10303 /* final misplaced underbar check */
10304 if (s[-1] == '_') {
10305 if (ckWARN(WARN_SYNTAX))
10306 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10311 if (ckWARN(WARN_PORTABLE) && n > 4294967295.0)
10312 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10313 "%s number > %s non-portable",
10319 if (ckWARN(WARN_PORTABLE) && u > 0xffffffff)
10320 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10321 "%s number > %s non-portable",
10326 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
10327 sv = new_constant(start, s - start, "integer",
10329 else if (PL_hints & HINT_NEW_BINARY)
10330 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
10335 handle decimal numbers.
10336 we're also sent here when we read a 0 as the first digit
10338 case '1': case '2': case '3': case '4': case '5':
10339 case '6': case '7': case '8': case '9': case '.':
10342 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
10345 /* read next group of digits and _ and copy into d */
10346 while (isDIGIT(*s) || *s == '_') {
10347 /* skip underscores, checking for misplaced ones
10351 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10352 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10353 "Misplaced _ in number");
10357 /* check for end of fixed-length buffer */
10359 Perl_croak(aTHX_ number_too_long);
10360 /* if we're ok, copy the character */
10365 /* final misplaced underbar check */
10366 if (lastub && s == lastub + 1) {
10367 if (ckWARN(WARN_SYNTAX))
10368 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10371 /* read a decimal portion if there is one. avoid
10372 3..5 being interpreted as the number 3. followed
10375 if (*s == '.' && s[1] != '.') {
10380 if (ckWARN(WARN_SYNTAX))
10381 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10382 "Misplaced _ in number");
10386 /* copy, ignoring underbars, until we run out of digits.
10388 for (; isDIGIT(*s) || *s == '_'; s++) {
10389 /* fixed length buffer check */
10391 Perl_croak(aTHX_ number_too_long);
10393 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10394 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10395 "Misplaced _ in number");
10401 /* fractional part ending in underbar? */
10402 if (s[-1] == '_') {
10403 if (ckWARN(WARN_SYNTAX))
10404 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10405 "Misplaced _ in number");
10407 if (*s == '.' && isDIGIT(s[1])) {
10408 /* oops, it's really a v-string, but without the "v" */
10414 /* read exponent part, if present */
10415 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
10419 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
10420 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
10422 /* stray preinitial _ */
10424 if (ckWARN(WARN_SYNTAX))
10425 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10426 "Misplaced _ in number");
10430 /* allow positive or negative exponent */
10431 if (*s == '+' || *s == '-')
10434 /* stray initial _ */
10436 if (ckWARN(WARN_SYNTAX))
10437 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10438 "Misplaced _ in number");
10442 /* read digits of exponent */
10443 while (isDIGIT(*s) || *s == '_') {
10446 Perl_croak(aTHX_ number_too_long);
10450 if (ckWARN(WARN_SYNTAX) &&
10451 ((lastub && s == lastub + 1) ||
10452 (!isDIGIT(s[1]) && s[1] != '_')))
10453 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10454 "Misplaced _ in number");
10461 /* make an sv from the string */
10465 We try to do an integer conversion first if no characters
10466 indicating "float" have been found.
10471 int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
10473 if (flags == IS_NUMBER_IN_UV) {
10475 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
10478 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
10479 if (uv <= (UV) IV_MIN)
10480 sv_setiv(sv, -(IV)uv);
10487 /* terminate the string */
10489 nv = Atof(PL_tokenbuf);
10493 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
10494 (PL_hints & HINT_NEW_INTEGER) )
10495 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
10496 (floatit ? "float" : "integer"),
10500 /* if it starts with a v, it could be a v-string */
10503 sv = NEWSV(92,5); /* preallocate storage space */
10504 s = scan_vstring(s,sv);
10508 /* make the op for the constant and return */
10511 lvalp->opval = newSVOP(OP_CONST, 0, sv);
10513 lvalp->opval = Nullop;
10519 S_scan_formline(pTHX_ register char *s)
10521 register char *eol;
10523 SV *stuff = newSVpvn("",0);
10524 bool needargs = FALSE;
10525 bool eofmt = FALSE;
10527 while (!needargs) {
10530 #ifdef PERL_STRICT_CR
10531 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
10533 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
10535 if (*t == '\n' || t == PL_bufend) {
10540 if (PL_in_eval && !PL_rsfp) {
10541 eol = (char *) memchr(s,'\n',PL_bufend-s);
10546 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10548 for (t = s; t < eol; t++) {
10549 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
10551 goto enough; /* ~~ must be first line in formline */
10553 if (*t == '@' || *t == '^')
10557 sv_catpvn(stuff, s, eol-s);
10558 #ifndef PERL_STRICT_CR
10559 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
10560 char *end = SvPVX(stuff) + SvCUR(stuff);
10563 SvCUR_set(stuff, SvCUR(stuff) - 1);
10572 s = filter_gets(PL_linestr, PL_rsfp, 0);
10573 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
10574 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
10575 PL_last_lop = PL_last_uni = Nullch;
10584 if (SvCUR(stuff)) {
10587 PL_lex_state = LEX_NORMAL;
10588 PL_nextval[PL_nexttoke].ival = 0;
10592 PL_lex_state = LEX_FORMLINE;
10594 if (UTF && is_utf8_string((U8*)SvPVX(stuff), SvCUR(stuff)))
10596 else if (PL_encoding)
10597 sv_recode_to_utf8(stuff, PL_encoding);
10599 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
10601 PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
10605 SvREFCNT_dec(stuff);
10607 PL_lex_formbrack = 0;
10618 PL_cshlen = strlen(PL_cshname);
10623 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
10625 I32 oldsavestack_ix = PL_savestack_ix;
10626 CV* outsidecv = PL_compcv;
10629 assert(SvTYPE(PL_compcv) == SVt_PVCV);
10631 SAVEI32(PL_subline);
10632 save_item(PL_subname);
10633 SAVESPTR(PL_compcv);
10635 PL_compcv = (CV*)NEWSV(1104,0);
10636 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
10637 CvFLAGS(PL_compcv) |= flags;
10639 PL_subline = CopLINE(PL_curcop);
10640 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
10641 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
10642 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
10644 return oldsavestack_ix;
10648 #pragma segment Perl_yylex
10651 Perl_yywarn(pTHX_ const char *s)
10653 PL_in_eval |= EVAL_WARNONLY;
10655 PL_in_eval &= ~EVAL_WARNONLY;
10660 Perl_yyerror(pTHX_ const char *s)
10662 const char *where = NULL;
10663 const char *context = NULL;
10667 if (!yychar || (yychar == ';' && !PL_rsfp))
10669 else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 &&
10670 PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) {
10673 The code below is removed for NetWare because it abends/crashes on NetWare
10674 when the script has error such as not having the closing quotes like:
10675 if ($var eq "value)
10676 Checking of white spaces is anyway done in NetWare code.
10679 while (isSPACE(*PL_oldoldbufptr))
10682 context = PL_oldoldbufptr;
10683 contlen = PL_bufptr - PL_oldoldbufptr;
10685 else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 &&
10686 PL_oldbufptr != PL_bufptr) {
10689 The code below is removed for NetWare because it abends/crashes on NetWare
10690 when the script has error such as not having the closing quotes like:
10691 if ($var eq "value)
10692 Checking of white spaces is anyway done in NetWare code.
10695 while (isSPACE(*PL_oldbufptr))
10698 context = PL_oldbufptr;
10699 contlen = PL_bufptr - PL_oldbufptr;
10701 else if (yychar > 255)
10702 where = "next token ???";
10703 else if (yychar == -2) { /* YYEMPTY */
10704 if (PL_lex_state == LEX_NORMAL ||
10705 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
10706 where = "at end of line";
10707 else if (PL_lex_inpat)
10708 where = "within pattern";
10710 where = "within string";
10713 SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
10715 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
10716 else if (isPRINT_LC(yychar))
10717 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
10719 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
10720 where = SvPVX(where_sv);
10722 msg = sv_2mortal(newSVpv(s, 0));
10723 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
10724 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
10726 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
10728 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
10729 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
10730 Perl_sv_catpvf(aTHX_ msg,
10731 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
10732 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
10735 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
10736 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg);
10739 if (PL_error_count >= 10) {
10740 if (PL_in_eval && SvCUR(ERRSV))
10741 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
10742 ERRSV, OutCopFILE(PL_curcop));
10744 Perl_croak(aTHX_ "%s has too many errors.\n",
10745 OutCopFILE(PL_curcop));
10748 PL_in_my_stash = Nullhv;
10752 #pragma segment Main
10756 S_swallow_bom(pTHX_ U8 *s)
10758 const STRLEN slen = SvCUR(PL_linestr);
10761 if (s[1] == 0xFE) {
10762 /* UTF-16 little-endian? (or UTF32-LE?) */
10763 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
10764 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
10765 #ifndef PERL_NO_UTF16_FILTER
10766 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
10769 if (PL_bufend > (char*)s) {
10773 filter_add(utf16rev_textfilter, NULL);
10774 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10775 utf16_to_utf8_reversed(s, news,
10776 PL_bufend - (char*)s - 1,
10778 sv_setpvn(PL_linestr, (const char*)news, newlen);
10780 SvUTF8_on(PL_linestr);
10781 s = (U8*)SvPVX(PL_linestr);
10782 PL_bufend = SvPVX(PL_linestr) + newlen;
10785 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
10790 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
10791 #ifndef PERL_NO_UTF16_FILTER
10792 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
10795 if (PL_bufend > (char *)s) {
10799 filter_add(utf16_textfilter, NULL);
10800 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10801 utf16_to_utf8(s, news,
10802 PL_bufend - (char*)s,
10804 sv_setpvn(PL_linestr, (const char*)news, newlen);
10806 SvUTF8_on(PL_linestr);
10807 s = (U8*)SvPVX(PL_linestr);
10808 PL_bufend = SvPVX(PL_linestr) + newlen;
10811 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
10816 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
10817 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
10818 s += 3; /* UTF-8 */
10824 if (s[2] == 0xFE && s[3] == 0xFF) {
10825 /* UTF-32 big-endian */
10826 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
10829 else if (s[2] == 0 && s[3] != 0) {
10832 * are a good indicator of UTF-16BE. */
10833 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
10838 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
10841 * are a good indicator of UTF-16LE. */
10842 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
10851 * Restore a source filter.
10855 restore_rsfp(pTHX_ void *f)
10857 PerlIO *fp = (PerlIO*)f;
10859 if (PL_rsfp == PerlIO_stdin())
10860 PerlIO_clearerr(PL_rsfp);
10861 else if (PL_rsfp && (PL_rsfp != fp))
10862 PerlIO_close(PL_rsfp);
10866 #ifndef PERL_NO_UTF16_FILTER
10868 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10870 const STRLEN old = SvCUR(sv);
10871 const I32 count = FILTER_READ(idx+1, sv, maxlen);
10872 DEBUG_P(PerlIO_printf(Perl_debug_log,
10873 "utf16_textfilter(%p): %d %d (%d)\n",
10874 utf16_textfilter, idx, maxlen, (int) count));
10878 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10879 Copy(SvPVX(sv), tmps, old, char);
10880 utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old,
10881 SvCUR(sv) - old, &newlen);
10882 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10884 DEBUG_P({sv_dump(sv);});
10889 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10891 const STRLEN old = SvCUR(sv);
10892 const I32 count = FILTER_READ(idx+1, sv, maxlen);
10893 DEBUG_P(PerlIO_printf(Perl_debug_log,
10894 "utf16rev_textfilter(%p): %d %d (%d)\n",
10895 utf16rev_textfilter, idx, maxlen, (int) count));
10899 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10900 Copy(SvPVX(sv), tmps, old, char);
10901 utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old,
10902 SvCUR(sv) - old, &newlen);
10903 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10905 DEBUG_P({ sv_dump(sv); });
10911 Returns a pointer to the next character after the parsed
10912 vstring, as well as updating the passed in sv.
10914 Function must be called like
10917 s = scan_vstring(s,sv);
10919 The sv should already be large enough to store the vstring
10920 passed in, for performance reasons.
10925 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
10927 const char *pos = s;
10928 const char *start = s;
10929 if (*pos == 'v') pos++; /* get past 'v' */
10930 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
10932 if ( *pos != '.') {
10933 /* this may not be a v-string if followed by => */
10934 const char *next = pos;
10935 while (next < PL_bufend && isSPACE(*next))
10937 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
10938 /* return string not v-string */
10939 sv_setpvn(sv,(char *)s,pos-s);
10940 return (char *)pos;
10944 if (!isALPHA(*pos)) {
10946 U8 tmpbuf[UTF8_MAXBYTES+1];
10949 if (*s == 'v') s++; /* get past 'v' */
10951 sv_setpvn(sv, "", 0);
10956 /* this is atoi() that tolerates underscores */
10957 const char *end = pos;
10959 while (--end >= s) {
10964 rev += (*end - '0') * mult;
10966 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
10967 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
10968 "Integer overflow in decimal number");
10972 if (rev > 0x7FFFFFFF)
10973 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
10975 /* Append native character for the rev point */
10976 tmpend = uvchr_to_utf8(tmpbuf, rev);
10977 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
10978 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
10980 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
10986 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
10990 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
10998 * c-indentation-style: bsd
10999 * c-basic-offset: 4
11000 * indent-tabs-mode: t
11003 * ex: set ts=8 sts=4 sw=4 noet: