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 char const ident_too_long[] = "Identifier too long";
30 static char const c_without_g[] = "Use of /c modifier is meaningless without /g";
31 static char const c_in_subst[] = "Use of /c modifier is meaningless in s///";
33 static void restore_rsfp(pTHX_ void *f);
34 #ifndef PERL_NO_UTF16_FILTER
35 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
36 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
39 #define XFAKEBRACK 128
42 #ifdef USE_UTF8_SCRIPTS
43 # define UTF (!IN_BYTES)
45 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
48 /* In variables named $^X, these are the legal values for X.
49 * 1999-02-27 mjd-perl-patch@plover.com */
50 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
52 /* On MacOS, respect nonbreaking spaces */
53 #ifdef MACOS_TRADITIONAL
54 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
56 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
59 /* LEX_* are values for PL_lex_state, the state of the lexer.
60 * They are arranged oddly so that the guard on the switch statement
61 * can get by with a single comparison (if the compiler is smart enough).
64 /* #define LEX_NOTPARSING 11 is done in perl.h. */
67 #define LEX_INTERPNORMAL 9
68 #define LEX_INTERPCASEMOD 8
69 #define LEX_INTERPPUSH 7
70 #define LEX_INTERPSTART 6
71 #define LEX_INTERPEND 5
72 #define LEX_INTERPENDMAYBE 4
73 #define LEX_INTERPCONCAT 3
74 #define LEX_INTERPCONST 2
75 #define LEX_FORMLINE 1
76 #define LEX_KNOWNEXT 0
79 static char const* lex_state_names[] = {
100 /* CLINE is a macro that ensures PL_copline has a sane value */
105 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
108 * Convenience functions to return different tokens and prime the
109 * lexer for the next token. They all take an argument.
111 * TOKEN : generic token (used for '(', DOLSHARP, etc)
112 * OPERATOR : generic operator
113 * AOPERATOR : assignment operator
114 * PREBLOCK : beginning the block after an if, while, foreach, ...
115 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
116 * PREREF : *EXPR where EXPR is not a simple identifier
117 * TERM : expression term
118 * LOOPX : loop exiting command (goto, last, dump, etc)
119 * FTST : file test operator
120 * FUN0 : zero-argument function
121 * FUN1 : not used, except for not, which isn't a UNIOP
122 * BOop : bitwise or or xor
124 * SHop : shift operator
125 * PWop : power operator
126 * PMop : pattern-matching operator
127 * Aop : addition-level operator
128 * Mop : multiplication-level operator
129 * Eop : equality-testing operator
130 * Rop : relational operator <= != gt
132 * Also see LOP and lop() below.
135 #ifdef DEBUGGING /* Serve -DT. */
136 # define REPORT(retval) tokereport(s,(int)retval)
138 # define REPORT(retval) (retval)
141 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
142 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
143 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
144 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
145 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
146 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
147 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
148 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
149 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
150 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
151 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
152 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
153 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
154 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
155 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
156 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
157 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
158 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
159 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
160 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
162 /* This bit of chicanery makes a unary function followed by
163 * a parenthesis into a function with one argument, highest precedence.
164 * The UNIDOR macro is for unary functions that can be followed by the //
165 * operator (such as C<shift // 0>).
167 #define UNI2(f,x) return ( \
171 PL_last_uni = PL_oldbufptr, \
172 PL_last_lop_op = f, \
174 (*s == '(' || (s = skipspace(s), *s == '(') \
175 ? (int)FUNC1 : (int)UNIOP)))
176 #define UNI(f) UNI2(f,XTERM)
177 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
179 #define UNIBRACK(f) return ( \
182 PL_last_uni = PL_oldbufptr, \
184 (*s == '(' || (s = skipspace(s), *s == '(') \
185 ? (int)FUNC1 : (int)UNIOP)))
187 /* grandfather return to old style */
188 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
192 /* how to interpret the yylval associated with the token */
196 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
202 static struct debug_tokens { const int token, type; const char *name; } debug_tokens[] =
204 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
205 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
206 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
207 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
208 { ARROW, TOKENTYPE_NONE, "ARROW" },
209 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
210 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
211 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
212 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
213 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
214 { DO, TOKENTYPE_NONE, "DO" },
215 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
216 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
217 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
218 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
219 { ELSE, TOKENTYPE_NONE, "ELSE" },
220 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
221 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
222 { FOR, TOKENTYPE_IVAL, "FOR" },
223 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
224 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
225 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
226 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
227 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
228 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
229 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
230 { IF, TOKENTYPE_IVAL, "IF" },
231 { LABEL, TOKENTYPE_PVAL, "LABEL" },
232 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
233 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
234 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
235 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
236 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
237 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
238 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
239 { MY, TOKENTYPE_IVAL, "MY" },
240 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
241 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
242 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
243 { OROP, TOKENTYPE_IVAL, "OROP" },
244 { OROR, TOKENTYPE_NONE, "OROR" },
245 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
246 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
247 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
248 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
249 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
250 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
251 { PREINC, TOKENTYPE_NONE, "PREINC" },
252 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
253 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
254 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
255 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
256 { SUB, TOKENTYPE_NONE, "SUB" },
257 { THING, TOKENTYPE_OPVAL, "THING" },
258 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
259 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
260 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
261 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
262 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
263 { USE, TOKENTYPE_IVAL, "USE" },
264 { WHILE, TOKENTYPE_IVAL, "WHILE" },
265 { WORD, TOKENTYPE_OPVAL, "WORD" },
266 { 0, TOKENTYPE_NONE, 0 }
269 /* dump the returned token in rv, plus any optional arg in yylval */
272 S_tokereport(pTHX_ const char* s, I32 rv)
275 const char *name = Nullch;
276 enum token_type type = TOKENTYPE_NONE;
277 struct debug_tokens *p;
278 SV* report = newSVpvn("<== ", 4);
280 for (p = debug_tokens; p->token; p++) {
281 if (p->token == (int)rv) {
288 Perl_sv_catpv(aTHX_ report, name);
289 else if ((char)rv > ' ' && (char)rv < '~')
290 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
292 Perl_sv_catpv(aTHX_ report, "EOF");
294 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
297 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
300 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
302 case TOKENTYPE_OPNUM:
303 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
304 PL_op_name[yylval.ival]);
307 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
309 case TOKENTYPE_OPVAL:
311 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
312 PL_op_name[yylval.opval->op_type]);
314 Perl_sv_catpv(aTHX_ report, "(opval=null)");
317 Perl_sv_catpvf(aTHX_ report, " at line %"IVdf" [", (IV)CopLINE(PL_curcop));
318 if (s - PL_bufptr > 0)
319 sv_catpvn(report, PL_bufptr, s - PL_bufptr);
321 if (PL_oldbufptr && *PL_oldbufptr)
322 sv_catpv(report, PL_tokenbuf);
324 PerlIO_printf(Perl_debug_log, "### %s]\n", SvPV_nolen(report));
334 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
335 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
339 S_ao(pTHX_ int toketype)
341 if (*PL_bufptr == '=') {
343 if (toketype == ANDAND)
344 yylval.ival = OP_ANDASSIGN;
345 else if (toketype == OROR)
346 yylval.ival = OP_ORASSIGN;
347 else if (toketype == DORDOR)
348 yylval.ival = OP_DORASSIGN;
356 * When Perl expects an operator and finds something else, no_op
357 * prints the warning. It always prints "<something> found where
358 * operator expected. It prints "Missing semicolon on previous line?"
359 * if the surprise occurs at the start of the line. "do you need to
360 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
361 * where the compiler doesn't know if foo is a method call or a function.
362 * It prints "Missing operator before end of line" if there's nothing
363 * after the missing operator, or "... before <...>" if there is something
364 * after the missing operator.
368 S_no_op(pTHX_ const char *what, char *s)
370 char *oldbp = PL_bufptr;
371 bool is_first = (PL_oldbufptr == PL_linestart);
377 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
378 if (ckWARN_d(WARN_SYNTAX)) {
380 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
381 "\t(Missing semicolon on previous line?)\n");
382 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
384 for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
385 if (t < PL_bufptr && isSPACE(*t))
386 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
387 "\t(Do you need to predeclare %.*s?)\n",
388 t - PL_oldoldbufptr, PL_oldoldbufptr);
392 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
393 "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
401 * Complain about missing quote/regexp/heredoc terminator.
402 * If it's called with (char *)NULL then it cauterizes the line buffer.
403 * If we're in a delimited string and the delimiter is a control
404 * character, it's reformatted into a two-char sequence like ^C.
409 S_missingterm(pTHX_ char *s)
414 char *nl = strrchr(s,'\n');
420 iscntrl(PL_multi_close)
422 PL_multi_close < 32 || PL_multi_close == 127
426 tmpbuf[1] = toCTRL(PL_multi_close);
431 *tmpbuf = (char)PL_multi_close;
435 q = strchr(s,'"') ? '\'' : '"';
436 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
444 Perl_deprecate(pTHX_ const char *s)
446 if (ckWARN(WARN_DEPRECATED))
447 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
451 Perl_deprecate_old(pTHX_ const char *s)
453 /* This function should NOT be called for any new deprecated warnings */
454 /* Use Perl_deprecate instead */
456 /* It is here to maintain backward compatibility with the pre-5.8 */
457 /* warnings category hierarchy. The "deprecated" category used to */
458 /* live under the "syntax" category. It is now a top-level category */
459 /* in its own right. */
461 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
462 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
463 "Use of %s is deprecated", s);
468 * Deprecate a comma-less variable list.
474 deprecate_old("comma-less variable list");
478 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
479 * utf16-to-utf8-reversed.
482 #ifdef PERL_CR_FILTER
486 register char *s = SvPVX(sv);
487 register char *e = s + SvCUR(sv);
488 /* outer loop optimized to do nothing if there are no CR-LFs */
490 if (*s++ == '\r' && *s == '\n') {
491 /* hit a CR-LF, need to copy the rest */
492 register char *d = s - 1;
495 if (*s == '\r' && s[1] == '\n')
506 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
508 I32 count = FILTER_READ(idx+1, sv, maxlen);
509 if (count > 0 && !maxlen)
517 * Initialize variables. Uses the Perl save_stack to save its state (for
518 * recursive calls to the parser).
522 Perl_lex_start(pTHX_ SV *line)
527 SAVEI32(PL_lex_dojoin);
528 SAVEI32(PL_lex_brackets);
529 SAVEI32(PL_lex_casemods);
530 SAVEI32(PL_lex_starts);
531 SAVEI32(PL_lex_state);
532 SAVEVPTR(PL_lex_inpat);
533 SAVEI32(PL_lex_inwhat);
534 if (PL_lex_state == LEX_KNOWNEXT) {
535 I32 toke = PL_nexttoke;
536 while (--toke >= 0) {
537 SAVEI32(PL_nexttype[toke]);
538 SAVEVPTR(PL_nextval[toke]);
540 SAVEI32(PL_nexttoke);
542 SAVECOPLINE(PL_curcop);
545 SAVEPPTR(PL_oldbufptr);
546 SAVEPPTR(PL_oldoldbufptr);
547 SAVEPPTR(PL_last_lop);
548 SAVEPPTR(PL_last_uni);
549 SAVEPPTR(PL_linestart);
550 SAVESPTR(PL_linestr);
551 SAVEGENERICPV(PL_lex_brackstack);
552 SAVEGENERICPV(PL_lex_casestack);
553 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
554 SAVESPTR(PL_lex_stuff);
555 SAVEI32(PL_lex_defer);
556 SAVEI32(PL_sublex_info.sub_inwhat);
557 SAVESPTR(PL_lex_repl);
559 SAVEINT(PL_lex_expect);
561 PL_lex_state = LEX_NORMAL;
565 New(899, PL_lex_brackstack, 120, char);
566 New(899, PL_lex_casestack, 12, char);
568 *PL_lex_casestack = '\0';
571 PL_lex_stuff = Nullsv;
572 PL_lex_repl = Nullsv;
576 PL_sublex_info.sub_inwhat = 0;
578 if (SvREADONLY(PL_linestr))
579 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
580 s = SvPV(PL_linestr, len);
581 if (!len || s[len-1] != ';') {
582 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
583 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
584 sv_catpvn(PL_linestr, "\n;", 2);
586 SvTEMP_off(PL_linestr);
587 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
588 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
589 PL_last_lop = PL_last_uni = Nullch;
595 * Finalizer for lexing operations. Must be called when the parser is
596 * done with the lexer.
602 PL_doextract = FALSE;
607 * This subroutine has nothing to do with tilting, whether at windmills
608 * or pinball tables. Its name is short for "increment line". It
609 * increments the current line number in CopLINE(PL_curcop) and checks
610 * to see whether the line starts with a comment of the form
611 * # line 500 "foo.pm"
612 * If so, it sets the current line number and file to the values in the comment.
616 S_incline(pTHX_ char *s)
623 CopLINE_inc(PL_curcop);
626 while (SPACE_OR_TAB(*s)) s++;
627 if (strnEQ(s, "line", 4))
631 if (SPACE_OR_TAB(*s))
635 while (SPACE_OR_TAB(*s)) s++;
641 while (SPACE_OR_TAB(*s))
643 if (*s == '"' && (t = strchr(s+1, '"'))) {
648 for (t = s; !isSPACE(*t); t++) ;
651 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
653 if (*e != '\n' && *e != '\0')
654 return; /* false alarm */
659 CopFILE_free(PL_curcop);
660 CopFILE_set(PL_curcop, s);
663 CopLINE_set(PL_curcop, atoi(n)-1);
668 * Called to gobble the appropriate amount and type of whitespace.
669 * Skips comments as well.
673 S_skipspace(pTHX_ register char *s)
675 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
676 while (s < PL_bufend && SPACE_OR_TAB(*s))
682 SSize_t oldprevlen, oldoldprevlen;
683 SSize_t oldloplen = 0, oldunilen = 0;
684 while (s < PL_bufend && isSPACE(*s)) {
685 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
690 if (s < PL_bufend && *s == '#') {
691 while (s < PL_bufend && *s != '\n')
695 if (PL_in_eval && !PL_rsfp) {
702 /* only continue to recharge the buffer if we're at the end
703 * of the buffer, we're not reading from a source filter, and
704 * we're in normal lexing mode
706 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
707 PL_lex_state == LEX_FORMLINE)
710 /* try to recharge the buffer */
711 if ((s = filter_gets(PL_linestr, PL_rsfp,
712 (prevlen = SvCUR(PL_linestr)))) == Nullch)
714 /* end of file. Add on the -p or -n magic */
717 ";}continue{print or die qq(-p destination: $!\\n);}");
718 PL_minus_n = PL_minus_p = 0;
720 else if (PL_minus_n) {
721 sv_setpvn(PL_linestr, ";}", 2);
725 sv_setpvn(PL_linestr,";", 1);
727 /* reset variables for next time we lex */
728 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
730 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
731 PL_last_lop = PL_last_uni = Nullch;
733 /* Close the filehandle. Could be from -P preprocessor,
734 * STDIN, or a regular file. If we were reading code from
735 * STDIN (because the commandline held no -e or filename)
736 * then we don't close it, we reset it so the code can
737 * read from STDIN too.
740 if (PL_preprocess && !PL_in_eval)
741 (void)PerlProc_pclose(PL_rsfp);
742 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
743 PerlIO_clearerr(PL_rsfp);
745 (void)PerlIO_close(PL_rsfp);
750 /* not at end of file, so we only read another line */
751 /* make corresponding updates to old pointers, for yyerror() */
752 oldprevlen = PL_oldbufptr - PL_bufend;
753 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
755 oldunilen = PL_last_uni - PL_bufend;
757 oldloplen = PL_last_lop - PL_bufend;
758 PL_linestart = PL_bufptr = s + prevlen;
759 PL_bufend = s + SvCUR(PL_linestr);
761 PL_oldbufptr = s + oldprevlen;
762 PL_oldoldbufptr = s + oldoldprevlen;
764 PL_last_uni = s + oldunilen;
766 PL_last_lop = s + oldloplen;
769 /* debugger active and we're not compiling the debugger code,
770 * so store the line into the debugger's array of lines
772 if (PERLDB_LINE && PL_curstash != PL_debstash) {
773 SV *sv = NEWSV(85,0);
775 sv_upgrade(sv, SVt_PVMG);
776 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
779 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
786 * Check the unary operators to ensure there's no ambiguity in how they're
787 * used. An ambiguous piece of code would be:
789 * This doesn't mean rand() + 5. Because rand() is a unary operator,
790 * the +5 is its argument.
799 if (PL_oldoldbufptr != PL_last_uni)
801 while (isSPACE(*PL_last_uni))
803 for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
804 if ((t = strchr(s, '(')) && t < PL_bufptr)
806 if (ckWARN_d(WARN_AMBIGUOUS)){
809 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
810 "Warning: Use of \"%s\" without parentheses is ambiguous",
817 * LOP : macro to build a list operator. Its behaviour has been replaced
818 * with a subroutine, S_lop() for which LOP is just another name.
821 #define LOP(f,x) return lop(f,x,s)
825 * Build a list operator (or something that might be one). The rules:
826 * - if we have a next token, then it's a list operator [why?]
827 * - if the next thing is an opening paren, then it's a function
828 * - else it's a list operator
832 S_lop(pTHX_ I32 f, int x, char *s)
838 PL_last_lop = PL_oldbufptr;
839 PL_last_lop_op = (OPCODE)f;
841 return REPORT(LSTOP);
848 return REPORT(LSTOP);
853 * When the lexer realizes it knows the next token (for instance,
854 * it is reordering tokens for the parser) then it can call S_force_next
855 * to know what token to return the next time the lexer is called. Caller
856 * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer
857 * handles the token correctly.
861 S_force_next(pTHX_ I32 type)
863 PL_nexttype[PL_nexttoke] = type;
865 if (PL_lex_state != LEX_KNOWNEXT) {
866 PL_lex_defer = PL_lex_state;
867 PL_lex_expect = PL_expect;
868 PL_lex_state = LEX_KNOWNEXT;
873 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
875 SV *sv = newSVpvn(start,len);
876 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
883 * When the lexer knows the next thing is a word (for instance, it has
884 * just seen -> and it knows that the next char is a word char, then
885 * it calls S_force_word to stick the next word into the PL_next lookahead.
888 * char *start : buffer position (must be within PL_linestr)
889 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
890 * int check_keyword : if true, Perl checks to make sure the word isn't
891 * a keyword (do this if the word is a label, e.g. goto FOO)
892 * int allow_pack : if true, : characters will also be allowed (require,
894 * int allow_initial_tick : used by the "sub" lexer only.
898 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
903 start = skipspace(start);
905 if (isIDFIRST_lazy_if(s,UTF) ||
906 (allow_pack && *s == ':') ||
907 (allow_initial_tick && *s == '\'') )
909 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
910 if (check_keyword && keyword(PL_tokenbuf, len))
912 if (token == METHOD) {
917 PL_expect = XOPERATOR;
920 PL_nextval[PL_nexttoke].opval
921 = (OP*)newSVOP(OP_CONST,0,
922 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
923 PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
931 * Called when the lexer wants $foo *foo &foo etc, but the program
932 * text only contains the "foo" portion. The first argument is a pointer
933 * to the "foo", and the second argument is the type symbol to prefix.
934 * Forces the next token to be a "WORD".
935 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
939 S_force_ident(pTHX_ register const char *s, int kind)
942 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
943 PL_nextval[PL_nexttoke].opval = o;
946 o->op_private = OPpCONST_ENTERED;
947 /* XXX see note in pp_entereval() for why we forgo typo
948 warnings if the symbol must be introduced in an eval.
950 gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
951 kind == '$' ? SVt_PV :
952 kind == '@' ? SVt_PVAV :
953 kind == '%' ? SVt_PVHV :
961 Perl_str_to_version(pTHX_ SV *sv)
966 char *start = SvPVx(sv,len);
967 bool utf = SvUTF8(sv) ? TRUE : FALSE;
968 char *end = start + len;
969 while (start < end) {
973 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
978 retval += ((NV)n)/nshift;
987 * Forces the next token to be a version number.
988 * If the next token appears to be an invalid version number, (e.g. "v2b"),
989 * and if "guessing" is TRUE, then no new token is created (and the caller
990 * must use an alternative parsing method).
994 S_force_version(pTHX_ char *s, int guessing)
996 OP *version = Nullop;
1005 while (isDIGIT(*d) || *d == '_' || *d == '.')
1007 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1009 s = scan_num(s, &yylval);
1010 version = yylval.opval;
1011 ver = cSVOPx(version)->op_sv;
1012 if (SvPOK(ver) && !SvNIOK(ver)) {
1013 (void)SvUPGRADE(ver, SVt_PVNV);
1014 SvNV_set(ver, str_to_version(ver));
1015 SvNOK_on(ver); /* hint that it is a version */
1022 /* NOTE: The parser sees the package name and the VERSION swapped */
1023 PL_nextval[PL_nexttoke].opval = version;
1031 * Tokenize a quoted string passed in as an SV. It finds the next
1032 * chunk, up to end of string or a backslash. It may make a new
1033 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1038 S_tokeq(pTHX_ SV *sv)
1041 register char *send;
1049 s = SvPV_force(sv, len);
1050 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1053 while (s < send && *s != '\\')
1058 if ( PL_hints & HINT_NEW_STRING ) {
1059 pv = sv_2mortal(newSVpvn(SvPVX(pv), len));
1065 if (s + 1 < send && (s[1] == '\\'))
1066 s++; /* all that, just for this */
1071 SvCUR_set(sv, d - SvPVX(sv));
1073 if ( PL_hints & HINT_NEW_STRING )
1074 return new_constant(NULL, 0, "q", sv, pv, "q");
1079 * Now come three functions related to double-quote context,
1080 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1081 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1082 * interact with PL_lex_state, and create fake ( ... ) argument lists
1083 * to handle functions and concatenation.
1084 * They assume that whoever calls them will be setting up a fake
1085 * join call, because each subthing puts a ',' after it. This lets
1088 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1090 * (I'm not sure whether the spurious commas at the end of lcfirst's
1091 * arguments and join's arguments are created or not).
1096 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1098 * Pattern matching will set PL_lex_op to the pattern-matching op to
1099 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1101 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1103 * Everything else becomes a FUNC.
1105 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1106 * had an OP_CONST or OP_READLINE). This just sets us up for a
1107 * call to S_sublex_push().
1111 S_sublex_start(pTHX)
1113 register I32 op_type = yylval.ival;
1115 if (op_type == OP_NULL) {
1116 yylval.opval = PL_lex_op;
1120 if (op_type == OP_CONST || op_type == OP_READLINE) {
1121 SV *sv = tokeq(PL_lex_stuff);
1123 if (SvTYPE(sv) == SVt_PVIV) {
1124 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1130 nsv = newSVpvn(p, len);
1136 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1137 PL_lex_stuff = Nullsv;
1138 /* Allow <FH> // "foo" */
1139 if (op_type == OP_READLINE)
1140 PL_expect = XTERMORDORDOR;
1144 PL_sublex_info.super_state = PL_lex_state;
1145 PL_sublex_info.sub_inwhat = op_type;
1146 PL_sublex_info.sub_op = PL_lex_op;
1147 PL_lex_state = LEX_INTERPPUSH;
1151 yylval.opval = PL_lex_op;
1161 * Create a new scope to save the lexing state. The scope will be
1162 * ended in S_sublex_done. Returns a '(', starting the function arguments
1163 * to the uc, lc, etc. found before.
1164 * Sets PL_lex_state to LEX_INTERPCONCAT.
1172 PL_lex_state = PL_sublex_info.super_state;
1173 SAVEI32(PL_lex_dojoin);
1174 SAVEI32(PL_lex_brackets);
1175 SAVEI32(PL_lex_casemods);
1176 SAVEI32(PL_lex_starts);
1177 SAVEI32(PL_lex_state);
1178 SAVEVPTR(PL_lex_inpat);
1179 SAVEI32(PL_lex_inwhat);
1180 SAVECOPLINE(PL_curcop);
1181 SAVEPPTR(PL_bufptr);
1182 SAVEPPTR(PL_bufend);
1183 SAVEPPTR(PL_oldbufptr);
1184 SAVEPPTR(PL_oldoldbufptr);
1185 SAVEPPTR(PL_last_lop);
1186 SAVEPPTR(PL_last_uni);
1187 SAVEPPTR(PL_linestart);
1188 SAVESPTR(PL_linestr);
1189 SAVEGENERICPV(PL_lex_brackstack);
1190 SAVEGENERICPV(PL_lex_casestack);
1192 PL_linestr = PL_lex_stuff;
1193 PL_lex_stuff = Nullsv;
1195 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1196 = SvPVX(PL_linestr);
1197 PL_bufend += SvCUR(PL_linestr);
1198 PL_last_lop = PL_last_uni = Nullch;
1199 SAVEFREESV(PL_linestr);
1201 PL_lex_dojoin = FALSE;
1202 PL_lex_brackets = 0;
1203 New(899, PL_lex_brackstack, 120, char);
1204 New(899, PL_lex_casestack, 12, char);
1205 PL_lex_casemods = 0;
1206 *PL_lex_casestack = '\0';
1208 PL_lex_state = LEX_INTERPCONCAT;
1209 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1211 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1212 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1213 PL_lex_inpat = PL_sublex_info.sub_op;
1215 PL_lex_inpat = Nullop;
1222 * Restores lexer state after a S_sublex_push.
1228 if (!PL_lex_starts++) {
1229 SV *sv = newSVpvn("",0);
1230 if (SvUTF8(PL_linestr))
1232 PL_expect = XOPERATOR;
1233 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1237 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1238 PL_lex_state = LEX_INTERPCASEMOD;
1242 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1243 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1244 PL_linestr = PL_lex_repl;
1246 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1247 PL_bufend += SvCUR(PL_linestr);
1248 PL_last_lop = PL_last_uni = Nullch;
1249 SAVEFREESV(PL_linestr);
1250 PL_lex_dojoin = FALSE;
1251 PL_lex_brackets = 0;
1252 PL_lex_casemods = 0;
1253 *PL_lex_casestack = '\0';
1255 if (SvEVALED(PL_lex_repl)) {
1256 PL_lex_state = LEX_INTERPNORMAL;
1258 /* we don't clear PL_lex_repl here, so that we can check later
1259 whether this is an evalled subst; that means we rely on the
1260 logic to ensure sublex_done() is called again only via the
1261 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1264 PL_lex_state = LEX_INTERPCONCAT;
1265 PL_lex_repl = Nullsv;
1271 PL_bufend = SvPVX(PL_linestr);
1272 PL_bufend += SvCUR(PL_linestr);
1273 PL_expect = XOPERATOR;
1274 PL_sublex_info.sub_inwhat = 0;
1282 Extracts a pattern, double-quoted string, or transliteration. This
1285 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1286 processing a pattern (PL_lex_inpat is true), a transliteration
1287 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1289 Returns a pointer to the character scanned up to. Iff this is
1290 advanced from the start pointer supplied (ie if anything was
1291 successfully parsed), will leave an OP for the substring scanned
1292 in yylval. Caller must intuit reason for not parsing further
1293 by looking at the next characters herself.
1297 double-quoted style: \r and \n
1298 regexp special ones: \D \s
1300 backrefs: \1 (deprecated in substitution replacements)
1301 case and quoting: \U \Q \E
1302 stops on @ and $, but not for $ as tail anchor
1304 In transliterations:
1305 characters are VERY literal, except for - not at the start or end
1306 of the string, which indicates a range. scan_const expands the
1307 range to the full set of intermediate characters.
1309 In double-quoted strings:
1311 double-quoted style: \r and \n
1313 backrefs: \1 (deprecated)
1314 case and quoting: \U \Q \E
1317 scan_const does *not* construct ops to handle interpolated strings.
1318 It stops processing as soon as it finds an embedded $ or @ variable
1319 and leaves it to the caller to work out what's going on.
1321 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo.
1323 $ in pattern could be $foo or could be tail anchor. Assumption:
1324 it's a tail anchor if $ is the last thing in the string, or if it's
1325 followed by one of ")| \n\t"
1327 \1 (backreferences) are turned into $1
1329 The structure of the code is
1330 while (there's a character to process) {
1331 handle transliteration ranges
1332 skip regexp comments
1333 skip # initiated comments in //x patterns
1334 check for embedded @foo
1335 check for embedded scalars
1337 leave intact backslashes from leave (below)
1338 deprecate \1 in strings and sub replacements
1339 handle string-changing backslashes \l \U \Q \E, etc.
1340 switch (what was escaped) {
1341 handle - in a transliteration (becomes a literal -)
1342 handle \132 octal characters
1343 handle 0x15 hex characters
1344 handle \cV (control V)
1345 handle printf backslashes (\f, \r, \n, etc)
1347 } (end if backslash)
1348 } (end while character to read)
1353 S_scan_const(pTHX_ char *start)
1355 register char *send = PL_bufend; /* end of the constant */
1356 SV *sv = NEWSV(93, send - start); /* sv for the constant */
1357 register char *s = start; /* start of the constant */
1358 register char *d = SvPVX(sv); /* destination for copies */
1359 bool dorange = FALSE; /* are we in a translit range? */
1360 bool didrange = FALSE; /* did we just finish a range? */
1361 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1362 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1365 const char *leaveit = /* set of acceptably-backslashed characters */
1367 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#"
1370 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1371 /* If we are doing a trans and we know we want UTF8 set expectation */
1372 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1373 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1377 while (s < send || dorange) {
1378 /* get transliterations out of the way (they're most literal) */
1379 if (PL_lex_inwhat == OP_TRANS) {
1380 /* expand a range A-Z to the full set of characters. AIE! */
1382 I32 i; /* current expanded character */
1383 I32 min; /* first character in range */
1384 I32 max; /* last character in range */
1387 char *c = (char*)utf8_hop((U8*)d, -1);
1391 *c = (char)UTF_TO_NATIVE(0xff);
1392 /* mark the range as done, and continue */
1398 i = d - SvPVX(sv); /* remember current offset */
1399 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1400 d = SvPVX(sv) + i; /* refresh d after realloc */
1401 d -= 2; /* eat the first char and the - */
1403 min = (U8)*d; /* first char in range */
1404 max = (U8)d[1]; /* last char in range */
1408 "Invalid range \"%c-%c\" in transliteration operator",
1409 (char)min, (char)max);
1413 if ((isLOWER(min) && isLOWER(max)) ||
1414 (isUPPER(min) && isUPPER(max))) {
1416 for (i = min; i <= max; i++)
1418 *d++ = NATIVE_TO_NEED(has_utf8,i);
1420 for (i = min; i <= max; i++)
1422 *d++ = NATIVE_TO_NEED(has_utf8,i);
1427 for (i = min; i <= max; i++)
1430 /* mark the range as done, and continue */
1436 /* range begins (ignore - as first or last char) */
1437 else if (*s == '-' && s+1 < send && s != start) {
1439 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1442 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1454 /* if we get here, we're not doing a transliteration */
1456 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1457 except for the last char, which will be done separately. */
1458 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1460 while (s+1 < send && *s != ')')
1461 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1463 else if (s[2] == '{' /* This should match regcomp.c */
1464 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1467 char *regparse = s + (s[2] == '{' ? 3 : 4);
1470 while (count && (c = *regparse)) {
1471 if (c == '\\' && regparse[1])
1479 if (*regparse != ')')
1480 regparse--; /* Leave one char for continuation. */
1481 while (s < regparse)
1482 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1486 /* likewise skip #-initiated comments in //x patterns */
1487 else if (*s == '#' && PL_lex_inpat &&
1488 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1489 while (s+1 < send && *s != '\n')
1490 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1493 /* check for embedded arrays
1494 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1496 else if (*s == '@' && s[1]
1497 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1500 /* check for embedded scalars. only stop if we're sure it's a
1503 else if (*s == '$') {
1504 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1506 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1507 break; /* in regexp, $ might be tail anchor */
1510 /* End of else if chain - OP_TRANS rejoin rest */
1513 if (*s == '\\' && s+1 < send) {
1516 /* some backslashes we leave behind */
1517 if (*leaveit && *s && strchr(leaveit, *s)) {
1518 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1519 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1523 /* deprecate \1 in strings and substitution replacements */
1524 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1525 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1527 if (ckWARN(WARN_SYNTAX))
1528 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
1533 /* string-change backslash escapes */
1534 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1539 /* if we get here, it's either a quoted -, or a digit */
1542 /* quoted - in transliterations */
1544 if (PL_lex_inwhat == OP_TRANS) {
1551 if (ckWARN(WARN_MISC) &&
1554 Perl_warner(aTHX_ packWARN(WARN_MISC),
1555 "Unrecognized escape \\%c passed through",
1557 /* default action is to copy the quoted character */
1558 goto default_action;
1561 /* \132 indicates an octal constant */
1562 case '0': case '1': case '2': case '3':
1563 case '4': case '5': case '6': case '7':
1567 uv = grok_oct(s, &len, &flags, NULL);
1570 goto NUM_ESCAPE_INSERT;
1572 /* \x24 indicates a hex constant */
1576 char* e = strchr(s, '}');
1577 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1578 PERL_SCAN_DISALLOW_PREFIX;
1583 yyerror("Missing right brace on \\x{}");
1587 uv = grok_hex(s, &len, &flags, NULL);
1593 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
1594 uv = grok_hex(s, &len, &flags, NULL);
1600 /* Insert oct or hex escaped character.
1601 * There will always enough room in sv since such
1602 * escapes will be longer than any UTF-8 sequence
1603 * they can end up as. */
1605 /* We need to map to chars to ASCII before doing the tests
1608 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
1609 if (!has_utf8 && uv > 255) {
1610 /* Might need to recode whatever we have
1611 * accumulated so far if it contains any
1614 * (Can't we keep track of that and avoid
1615 * this rescan? --jhi)
1619 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
1620 if (!NATIVE_IS_INVARIANT(*c)) {
1625 STRLEN offset = d - SvPVX(sv);
1627 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
1631 while (src >= (U8 *)SvPVX(sv)) {
1632 if (!NATIVE_IS_INVARIANT(*src)) {
1633 U8 ch = NATIVE_TO_ASCII(*src);
1634 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
1635 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
1645 if (has_utf8 || uv > 255) {
1646 d = (char*)uvchr_to_utf8((U8*)d, uv);
1648 if (PL_lex_inwhat == OP_TRANS &&
1649 PL_sublex_info.sub_op) {
1650 PL_sublex_info.sub_op->op_private |=
1651 (PL_lex_repl ? OPpTRANS_FROM_UTF
1664 /* \N{LATIN SMALL LETTER A} is a named character */
1668 char* e = strchr(s, '}');
1674 yyerror("Missing right brace on \\N{}");
1678 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
1680 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1681 PERL_SCAN_DISALLOW_PREFIX;
1684 uv = grok_hex(s, &len, &flags, NULL);
1686 goto NUM_ESCAPE_INSERT;
1688 res = newSVpvn(s + 1, e - s - 1);
1689 res = new_constant( Nullch, 0, "charnames",
1690 res, Nullsv, "\\N{...}" );
1692 sv_utf8_upgrade(res);
1693 str = SvPV(res,len);
1694 #ifdef EBCDIC_NEVER_MIND
1695 /* charnames uses pack U and that has been
1696 * recently changed to do the below uni->native
1697 * mapping, so this would be redundant (and wrong,
1698 * the code point would be doubly converted).
1699 * But leave this in just in case the pack U change
1700 * gets revoked, but the semantics is still
1701 * desireable for charnames. --jhi */
1703 UV uv = utf8_to_uvchr((U8*)str, 0);
1706 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
1708 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
1709 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
1710 str = SvPV(res, len);
1714 if (!has_utf8 && SvUTF8(res)) {
1715 char *ostart = SvPVX(sv);
1716 SvCUR_set(sv, d - ostart);
1719 sv_utf8_upgrade(sv);
1720 /* this just broke our allocation above... */
1721 SvGROW(sv, (STRLEN)(send - start));
1722 d = SvPVX(sv) + SvCUR(sv);
1725 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
1726 char *odest = SvPVX(sv);
1728 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
1729 d = SvPVX(sv) + (d - odest);
1731 Copy(str, d, len, char);
1738 yyerror("Missing braces on \\N{}");
1741 /* \c is a control character */
1750 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
1753 yyerror("Missing control char name in \\c");
1757 /* printf-style backslashes, formfeeds, newlines, etc */
1759 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
1762 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
1765 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
1768 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
1771 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
1774 *d++ = ASCII_TO_NEED(has_utf8,'\033');
1777 *d++ = ASCII_TO_NEED(has_utf8,'\007');
1783 } /* end if (backslash) */
1786 /* If we started with encoded form, or already know we want it
1787 and then encode the next character */
1788 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
1790 UV uv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
1791 STRLEN need = UNISKIP(NATIVE_TO_UNI(uv));
1794 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
1795 STRLEN off = d - SvPVX(sv);
1796 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
1798 d = (char*)uvchr_to_utf8((U8*)d, uv);
1802 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1804 } /* while loop to process each character */
1806 /* terminate the string and set up the sv */
1808 SvCUR_set(sv, d - SvPVX(sv));
1809 if (SvCUR(sv) >= SvLEN(sv))
1810 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
1813 if (PL_encoding && !has_utf8) {
1814 sv_recode_to_utf8(sv, PL_encoding);
1820 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1821 PL_sublex_info.sub_op->op_private |=
1822 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1826 /* shrink the sv if we allocated more than we used */
1827 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1828 SvPV_shrink_to_cur(sv);
1831 /* return the substring (via yylval) only if we parsed anything */
1832 if (s > PL_bufptr) {
1833 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1834 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1836 ( PL_lex_inwhat == OP_TRANS
1838 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1841 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1848 * Returns TRUE if there's more to the expression (e.g., a subscript),
1851 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
1853 * ->[ and ->{ return TRUE
1854 * { and [ outside a pattern are always subscripts, so return TRUE
1855 * if we're outside a pattern and it's not { or [, then return FALSE
1856 * if we're in a pattern and the first char is a {
1857 * {4,5} (any digits around the comma) returns FALSE
1858 * if we're in a pattern and the first char is a [
1860 * [SOMETHING] has a funky algorithm to decide whether it's a
1861 * character class or not. It has to deal with things like
1862 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
1863 * anything else returns TRUE
1866 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1869 S_intuit_more(pTHX_ register char *s)
1871 if (PL_lex_brackets)
1873 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1875 if (*s != '{' && *s != '[')
1880 /* In a pattern, so maybe we have {n,m}. */
1897 /* On the other hand, maybe we have a character class */
1900 if (*s == ']' || *s == '^')
1903 /* this is terrifying, and it works */
1904 int weight = 2; /* let's weigh the evidence */
1906 unsigned char un_char = 255, last_un_char;
1907 char *send = strchr(s,']');
1908 char tmpbuf[sizeof PL_tokenbuf * 4];
1910 if (!send) /* has to be an expression */
1913 Zero(seen,256,char);
1916 else if (isDIGIT(*s)) {
1918 if (isDIGIT(s[1]) && s[2] == ']')
1924 for (; s < send; s++) {
1925 last_un_char = un_char;
1926 un_char = (unsigned char)*s;
1931 weight -= seen[un_char] * 10;
1932 if (isALNUM_lazy_if(s+1,UTF)) {
1933 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
1934 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
1939 else if (*s == '$' && s[1] &&
1940 strchr("[#!%*<>()-=",s[1])) {
1941 if (/*{*/ strchr("])} =",s[2]))
1950 if (strchr("wds]",s[1]))
1952 else if (seen['\''] || seen['"'])
1954 else if (strchr("rnftbxcav",s[1]))
1956 else if (isDIGIT(s[1])) {
1958 while (s[1] && isDIGIT(s[1]))
1968 if (strchr("aA01! ",last_un_char))
1970 if (strchr("zZ79~",s[1]))
1972 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
1973 weight -= 5; /* cope with negative subscript */
1976 if (!isALNUM(last_un_char)
1977 && !(last_un_char == '$' || last_un_char == '@'
1978 || last_un_char == '&')
1979 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
1984 if (keyword(tmpbuf, d - tmpbuf))
1987 if (un_char == last_un_char + 1)
1989 weight -= seen[un_char];
1994 if (weight >= 0) /* probably a character class */
2004 * Does all the checking to disambiguate
2006 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2007 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2009 * First argument is the stuff after the first token, e.g. "bar".
2011 * Not a method if bar is a filehandle.
2012 * Not a method if foo is a subroutine prototyped to take a filehandle.
2013 * Not a method if it's really "Foo $bar"
2014 * Method if it's "foo $bar"
2015 * Not a method if it's really "print foo $bar"
2016 * Method if it's really "foo package::" (interpreted as package->foo)
2017 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2018 * Not a method if bar is a filehandle or package, but is quoted with
2023 S_intuit_method(pTHX_ char *start, GV *gv)
2025 char *s = start + (*start == '$');
2026 char tmpbuf[sizeof PL_tokenbuf];
2034 if ((cv = GvCVu(gv))) {
2035 char *proto = SvPVX(cv);
2045 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2046 /* start is the beginning of the possible filehandle/object,
2047 * and s is the end of it
2048 * tmpbuf is a copy of it
2051 if (*start == '$') {
2052 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2057 return *s == '(' ? FUNCMETH : METHOD;
2059 if (!keyword(tmpbuf, len)) {
2060 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2065 indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2066 if (indirgv && GvCVu(indirgv))
2068 /* filehandle or package name makes it a method */
2069 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2071 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2072 return 0; /* no assumptions -- "=>" quotes bearword */
2074 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
2075 newSVpvn(tmpbuf,len));
2076 PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
2080 return *s == '(' ? FUNCMETH : METHOD;
2088 * Return a string of Perl code to load the debugger. If PERL5DB
2089 * is set, it will return the contents of that, otherwise a
2090 * compile-time require of perl5db.pl.
2097 const char *pdb = PerlEnv_getenv("PERL5DB");
2101 SETERRNO(0,SS_NORMAL);
2102 return "BEGIN { require 'perl5db.pl' }";
2108 /* Encoded script support. filter_add() effectively inserts a
2109 * 'pre-processing' function into the current source input stream.
2110 * Note that the filter function only applies to the current source file
2111 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2113 * The datasv parameter (which may be NULL) can be used to pass
2114 * private data to this instance of the filter. The filter function
2115 * can recover the SV using the FILTER_DATA macro and use it to
2116 * store private buffers and state information.
2118 * The supplied datasv parameter is upgraded to a PVIO type
2119 * and the IoDIRP/IoANY field is used to store the function pointer,
2120 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2121 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2122 * private use must be set using malloc'd pointers.
2126 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2131 if (!PL_rsfp_filters)
2132 PL_rsfp_filters = newAV();
2134 datasv = NEWSV(255,0);
2135 if (!SvUPGRADE(datasv, SVt_PVIO))
2136 Perl_die(aTHX_ "Can't upgrade filter_add data to SVt_PVIO");
2137 IoANY(datasv) = (void *)funcp; /* stash funcp into spare field */
2138 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2139 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2140 (void*)funcp, SvPV_nolen(datasv)));
2141 av_unshift(PL_rsfp_filters, 1);
2142 av_store(PL_rsfp_filters, 0, datasv) ;
2147 /* Delete most recently added instance of this filter function. */
2149 Perl_filter_del(pTHX_ filter_t funcp)
2152 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", (void*)funcp));
2153 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2155 /* if filter is on top of stack (usual case) just pop it off */
2156 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2157 if (IoANY(datasv) == (void *)funcp) {
2158 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2159 IoANY(datasv) = (void *)NULL;
2160 sv_free(av_pop(PL_rsfp_filters));
2164 /* we need to search for the correct entry and clear it */
2165 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2169 /* Invoke the idxth filter function for the current rsfp. */
2170 /* maxlen 0 = read one text line */
2172 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2177 if (!PL_rsfp_filters)
2179 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2180 /* Provide a default input filter to make life easy. */
2181 /* Note that we append to the line. This is handy. */
2182 DEBUG_P(PerlIO_printf(Perl_debug_log,
2183 "filter_read %d: from rsfp\n", idx));
2187 int old_len = SvCUR(buf_sv) ;
2189 /* ensure buf_sv is large enough */
2190 SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ;
2191 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
2192 if (PerlIO_error(PL_rsfp))
2193 return -1; /* error */
2195 return 0 ; /* end of file */
2197 SvCUR_set(buf_sv, old_len + len) ;
2200 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2201 if (PerlIO_error(PL_rsfp))
2202 return -1; /* error */
2204 return 0 ; /* end of file */
2207 return SvCUR(buf_sv);
2209 /* Skip this filter slot if filter has been deleted */
2210 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2211 DEBUG_P(PerlIO_printf(Perl_debug_log,
2212 "filter_read %d: skipped (filter deleted)\n",
2214 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
2216 /* Get function pointer hidden within datasv */
2217 funcp = (filter_t)IoANY(datasv);
2218 DEBUG_P(PerlIO_printf(Perl_debug_log,
2219 "filter_read %d: via function %p (%s)\n",
2220 idx, (void*)funcp, SvPV_nolen(datasv)));
2221 /* Call function. The function is expected to */
2222 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2223 /* Return: <0:error, =0:eof, >0:not eof */
2224 return (*funcp)(aTHX_ idx, buf_sv, maxlen);
2228 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2230 #ifdef PERL_CR_FILTER
2231 if (!PL_rsfp_filters) {
2232 filter_add(S_cr_textfilter,NULL);
2235 if (PL_rsfp_filters) {
2237 SvCUR_set(sv, 0); /* start with empty line */
2238 if (FILTER_READ(0, sv, 0) > 0)
2239 return ( SvPVX(sv) ) ;
2244 return (sv_gets(sv, fp, append));
2248 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2252 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2256 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2257 (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV)))
2259 return GvHV(gv); /* Foo:: */
2262 /* use constant CLASS => 'MyClass' */
2263 if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) {
2265 if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2266 pkgname = SvPV_nolen(sv);
2270 return gv_stashpv(pkgname, FALSE);
2274 static char const* exp_name[] =
2275 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2276 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
2283 Works out what to call the token just pulled out of the input
2284 stream. The yacc parser takes care of taking the ops we return and
2285 stitching them into a tree.
2291 if read an identifier
2292 if we're in a my declaration
2293 croak if they tried to say my($foo::bar)
2294 build the ops for a my() declaration
2295 if it's an access to a my() variable
2296 are we in a sort block?
2297 croak if my($a); $a <=> $b
2298 build ops for access to a my() variable
2299 if in a dq string, and they've said @foo and we can't find @foo
2301 build ops for a bareword
2302 if we already built the token before, use it.
2307 #pragma segment Perl_yylex
2312 register char *s = PL_bufptr;
2319 I32 orig_keyword = 0;
2322 PerlIO_printf(Perl_debug_log, "### LEX_%s\n",
2323 lex_state_names[PL_lex_state]);
2325 /* check if there's an identifier for us to look at */
2326 if (PL_pending_ident)
2327 return REPORT(S_pending_ident(aTHX));
2329 /* no identifier pending identification */
2331 switch (PL_lex_state) {
2333 case LEX_NORMAL: /* Some compilers will produce faster */
2334 case LEX_INTERPNORMAL: /* code if we comment these out. */
2338 /* when we've already built the next token, just pull it out of the queue */
2341 yylval = PL_nextval[PL_nexttoke];
2343 PL_lex_state = PL_lex_defer;
2344 PL_expect = PL_lex_expect;
2345 PL_lex_defer = LEX_NORMAL;
2347 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2348 "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr,
2349 (IV)PL_nexttype[PL_nexttoke]); });
2351 return REPORT(PL_nexttype[PL_nexttoke]);
2353 /* interpolated case modifiers like \L \U, including \Q and \E.
2354 when we get here, PL_bufptr is at the \
2356 case LEX_INTERPCASEMOD:
2358 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2359 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2361 /* handle \E or end of string */
2362 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2366 if (PL_lex_casemods) {
2367 oldmod = PL_lex_casestack[--PL_lex_casemods];
2368 PL_lex_casestack[PL_lex_casemods] = '\0';
2370 if (PL_bufptr != PL_bufend
2371 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
2373 PL_lex_state = LEX_INTERPCONCAT;
2377 if (PL_bufptr != PL_bufend)
2379 PL_lex_state = LEX_INTERPCONCAT;
2383 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2384 "### Saw case modifier at '%s'\n", PL_bufptr); });
2386 if (s[1] == '\\' && s[2] == 'E') {
2388 PL_lex_state = LEX_INTERPCONCAT;
2392 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2393 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
2394 if ((*s == 'L' || *s == 'U') &&
2395 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
2396 PL_lex_casestack[--PL_lex_casemods] = '\0';
2399 if (PL_lex_casemods > 10)
2400 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2401 PL_lex_casestack[PL_lex_casemods++] = *s;
2402 PL_lex_casestack[PL_lex_casemods] = '\0';
2403 PL_lex_state = LEX_INTERPCONCAT;
2404 PL_nextval[PL_nexttoke].ival = 0;
2407 PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2409 PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2411 PL_nextval[PL_nexttoke].ival = OP_LC;
2413 PL_nextval[PL_nexttoke].ival = OP_UC;
2415 PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2417 Perl_croak(aTHX_ "panic: yylex");
2421 if (PL_lex_starts) {
2424 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2425 if (PL_lex_casemods == 1 && PL_lex_inpat)
2434 case LEX_INTERPPUSH:
2435 return REPORT(sublex_push());
2437 case LEX_INTERPSTART:
2438 if (PL_bufptr == PL_bufend)
2439 return REPORT(sublex_done());
2440 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2441 "### Interpolated variable at '%s'\n", PL_bufptr); });
2443 PL_lex_dojoin = (*PL_bufptr == '@');
2444 PL_lex_state = LEX_INTERPNORMAL;
2445 if (PL_lex_dojoin) {
2446 PL_nextval[PL_nexttoke].ival = 0;
2448 force_ident("\"", '$');
2449 PL_nextval[PL_nexttoke].ival = 0;
2451 PL_nextval[PL_nexttoke].ival = 0;
2453 PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
2456 if (PL_lex_starts++) {
2458 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2459 if (!PL_lex_casemods && PL_lex_inpat)
2466 case LEX_INTERPENDMAYBE:
2467 if (intuit_more(PL_bufptr)) {
2468 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
2474 if (PL_lex_dojoin) {
2475 PL_lex_dojoin = FALSE;
2476 PL_lex_state = LEX_INTERPCONCAT;
2479 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2480 && SvEVALED(PL_lex_repl))
2482 if (PL_bufptr != PL_bufend)
2483 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2484 PL_lex_repl = Nullsv;
2487 case LEX_INTERPCONCAT:
2489 if (PL_lex_brackets)
2490 Perl_croak(aTHX_ "panic: INTERPCONCAT");
2492 if (PL_bufptr == PL_bufend)
2493 return REPORT(sublex_done());
2495 if (SvIVX(PL_linestr) == '\'') {
2496 SV *sv = newSVsv(PL_linestr);
2499 else if ( PL_hints & HINT_NEW_RE )
2500 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2501 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2505 s = scan_const(PL_bufptr);
2507 PL_lex_state = LEX_INTERPCASEMOD;
2509 PL_lex_state = LEX_INTERPSTART;
2512 if (s != PL_bufptr) {
2513 PL_nextval[PL_nexttoke] = yylval;
2516 if (PL_lex_starts++) {
2517 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2518 if (!PL_lex_casemods && PL_lex_inpat)
2531 PL_lex_state = LEX_NORMAL;
2532 s = scan_formline(PL_bufptr);
2533 if (!PL_lex_formbrack)
2539 PL_oldoldbufptr = PL_oldbufptr;
2542 PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at [%s]\n",
2543 exp_name[PL_expect], s);
2549 if (isIDFIRST_lazy_if(s,UTF))
2551 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2554 goto fake_eof; /* emulate EOF on ^D or ^Z */
2559 if (PL_lex_brackets) {
2560 if (PL_lex_formbrack)
2561 yyerror("Format not terminated");
2563 yyerror("Missing right curly or square bracket");
2565 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2566 "### Tokener got EOF\n");
2570 if (s++ < PL_bufend)
2571 goto retry; /* ignore stray nulls */
2574 if (!PL_in_eval && !PL_preambled) {
2575 PL_preambled = TRUE;
2576 sv_setpv(PL_linestr,incl_perldb());
2577 if (SvCUR(PL_linestr))
2578 sv_catpvn(PL_linestr,";", 1);
2580 while(AvFILLp(PL_preambleav) >= 0) {
2581 SV *tmpsv = av_shift(PL_preambleav);
2582 sv_catsv(PL_linestr, tmpsv);
2583 sv_catpvn(PL_linestr, ";", 1);
2586 sv_free((SV*)PL_preambleav);
2587 PL_preambleav = NULL;
2589 if (PL_minus_n || PL_minus_p) {
2590 sv_catpv(PL_linestr, "LINE: while (<>) {");
2592 sv_catpv(PL_linestr,"chomp;");
2595 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
2596 || *PL_splitstr == '"')
2597 && strchr(PL_splitstr + 1, *PL_splitstr))
2598 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
2600 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
2601 bytes can be used as quoting characters. :-) */
2602 /* The count here deliberately includes the NUL
2603 that terminates the C string constant. This
2604 embeds the opening NUL into the string. */
2605 const char *splits = PL_splitstr;
2606 sv_catpvn(PL_linestr, "our @F=split(q", 15);
2609 if (*splits == '\\')
2610 sv_catpvn(PL_linestr, splits, 1);
2611 sv_catpvn(PL_linestr, splits, 1);
2612 } while (*splits++);
2613 /* This loop will embed the trailing NUL of
2614 PL_linestr as the last thing it does before
2616 sv_catpvn(PL_linestr, ");", 2);
2620 sv_catpv(PL_linestr,"our @F=split(' ');");
2623 sv_catpvn(PL_linestr, "\n", 1);
2624 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2625 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2626 PL_last_lop = PL_last_uni = Nullch;
2627 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2628 SV *sv = NEWSV(85,0);
2630 sv_upgrade(sv, SVt_PVMG);
2631 sv_setsv(sv,PL_linestr);
2634 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2639 bof = PL_rsfp ? TRUE : FALSE;
2640 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2643 if (PL_preprocess && !PL_in_eval)
2644 (void)PerlProc_pclose(PL_rsfp);
2645 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2646 PerlIO_clearerr(PL_rsfp);
2648 (void)PerlIO_close(PL_rsfp);
2650 PL_doextract = FALSE;
2652 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2653 sv_setpv(PL_linestr,PL_minus_p
2654 ? ";}continue{print;}" : ";}");
2655 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2656 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2657 PL_last_lop = PL_last_uni = Nullch;
2658 PL_minus_n = PL_minus_p = 0;
2661 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2662 PL_last_lop = PL_last_uni = Nullch;
2663 sv_setpv(PL_linestr,"");
2664 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
2666 /* If it looks like the start of a BOM or raw UTF-16,
2667 * check if it in fact is. */
2673 #ifdef PERLIO_IS_STDIO
2674 # ifdef __GNU_LIBRARY__
2675 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
2676 # define FTELL_FOR_PIPE_IS_BROKEN
2680 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
2681 # define FTELL_FOR_PIPE_IS_BROKEN
2686 #ifdef FTELL_FOR_PIPE_IS_BROKEN
2687 /* This loses the possibility to detect the bof
2688 * situation on perl -P when the libc5 is being used.
2689 * Workaround? Maybe attach some extra state to PL_rsfp?
2692 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2694 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
2697 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2698 s = swallow_bom((U8*)s);
2702 /* Incest with pod. */
2703 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2704 sv_setpv(PL_linestr, "");
2705 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2706 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2707 PL_last_lop = PL_last_uni = Nullch;
2708 PL_doextract = FALSE;
2712 } while (PL_doextract);
2713 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2714 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2715 SV *sv = NEWSV(85,0);
2717 sv_upgrade(sv, SVt_PVMG);
2718 sv_setsv(sv,PL_linestr);
2721 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2723 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2724 PL_last_lop = PL_last_uni = Nullch;
2725 if (CopLINE(PL_curcop) == 1) {
2726 while (s < PL_bufend && isSPACE(*s))
2728 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2732 if (*s == '#' && *(s+1) == '!')
2734 #ifdef ALTERNATE_SHEBANG
2736 static char const as[] = ALTERNATE_SHEBANG;
2737 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2738 d = s + (sizeof(as) - 1);
2740 #endif /* ALTERNATE_SHEBANG */
2749 while (*d && !isSPACE(*d))
2753 #ifdef ARG_ZERO_IS_SCRIPT
2754 if (ipathend > ipath) {
2756 * HP-UX (at least) sets argv[0] to the script name,
2757 * which makes $^X incorrect. And Digital UNIX and Linux,
2758 * at least, set argv[0] to the basename of the Perl
2759 * interpreter. So, having found "#!", we'll set it right.
2761 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); /* $^X */
2762 assert(SvPOK(x) || SvGMAGICAL(x));
2763 if (sv_eq(x, CopFILESV(PL_curcop))) {
2764 sv_setpvn(x, ipath, ipathend - ipath);
2770 char *bstart = SvPV(CopFILESV(PL_curcop),blen);
2771 char *lstart = SvPV(x,llen);
2773 bstart += blen - llen;
2774 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
2775 sv_setpvn(x, ipath, ipathend - ipath);
2780 TAINT_NOT; /* $^X is always tainted, but that's OK */
2782 #endif /* ARG_ZERO_IS_SCRIPT */
2787 d = instr(s,"perl -");
2789 d = instr(s,"perl");
2791 /* avoid getting into infinite loops when shebang
2792 * line contains "Perl" rather than "perl" */
2794 for (d = ipathend-4; d >= ipath; --d) {
2795 if ((*d == 'p' || *d == 'P')
2796 && !ibcmp(d, "perl", 4))
2806 #ifdef ALTERNATE_SHEBANG
2808 * If the ALTERNATE_SHEBANG on this system starts with a
2809 * character that can be part of a Perl expression, then if
2810 * we see it but not "perl", we're probably looking at the
2811 * start of Perl code, not a request to hand off to some
2812 * other interpreter. Similarly, if "perl" is there, but
2813 * not in the first 'word' of the line, we assume the line
2814 * contains the start of the Perl program.
2816 if (d && *s != '#') {
2818 while (*c && !strchr("; \t\r\n\f\v#", *c))
2821 d = Nullch; /* "perl" not in first word; ignore */
2823 *s = '#'; /* Don't try to parse shebang line */
2825 #endif /* ALTERNATE_SHEBANG */
2826 #ifndef MACOS_TRADITIONAL
2831 !instr(s,"indir") &&
2832 instr(PL_origargv[0],"perl"))
2838 while (s < PL_bufend && isSPACE(*s))
2840 if (s < PL_bufend) {
2841 Newz(899,newargv,PL_origargc+3,char*);
2843 while (s < PL_bufend && !isSPACE(*s))
2846 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2849 newargv = PL_origargv;
2852 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
2854 Perl_croak(aTHX_ "Can't exec %s", ipath);
2858 U32 oldpdb = PL_perldb;
2859 bool oldn = PL_minus_n;
2860 bool oldp = PL_minus_p;
2862 while (*d && !isSPACE(*d)) d++;
2863 while (SPACE_OR_TAB(*d)) d++;
2866 bool switches_done = PL_doswitches;
2868 if (*d == 'M' || *d == 'm' || *d == 'C') {
2870 while (*d && !isSPACE(*d)) d++;
2871 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2874 d = moreswitches(d);
2876 if (PL_doswitches && !switches_done) {
2877 int argc = PL_origargc;
2878 char **argv = PL_origargv;
2881 } while (argc && argv[0][0] == '-' && argv[0][1]);
2882 init_argv_symbols(argc,argv);
2884 if ((PERLDB_LINE && !oldpdb) ||
2885 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
2886 /* if we have already added "LINE: while (<>) {",
2887 we must not do it again */
2889 sv_setpv(PL_linestr, "");
2890 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2891 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2892 PL_last_lop = PL_last_uni = Nullch;
2893 PL_preambled = FALSE;
2895 (void)gv_fetchfile(PL_origfilename);
2898 if (PL_doswitches && !switches_done) {
2899 int argc = PL_origargc;
2900 char **argv = PL_origargv;
2903 } while (argc && argv[0][0] == '-' && argv[0][1]);
2904 init_argv_symbols(argc,argv);
2910 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2912 PL_lex_state = LEX_FORMLINE;
2917 #ifdef PERL_STRICT_CR
2918 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
2920 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
2922 case ' ': case '\t': case '\f': case 013:
2923 #ifdef MACOS_TRADITIONAL
2930 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
2931 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
2932 /* handle eval qq[#line 1 "foo"\n ...] */
2933 CopLINE_dec(PL_curcop);
2937 while (s < d && *s != '\n')
2941 else if (s > d) /* Found by Ilya: feed random input to Perl. */
2942 Perl_croak(aTHX_ "panic: input overflow");
2944 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2946 PL_lex_state = LEX_FORMLINE;
2956 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2963 while (s < PL_bufend && SPACE_OR_TAB(*s))
2966 if (strnEQ(s,"=>",2)) {
2967 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
2968 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2969 "### Saw unary minus before =>, forcing word '%s'\n", s);
2971 OPERATOR('-'); /* unary minus */
2973 PL_last_uni = PL_oldbufptr;
2975 case 'r': ftst = OP_FTEREAD; break;
2976 case 'w': ftst = OP_FTEWRITE; break;
2977 case 'x': ftst = OP_FTEEXEC; break;
2978 case 'o': ftst = OP_FTEOWNED; break;
2979 case 'R': ftst = OP_FTRREAD; break;
2980 case 'W': ftst = OP_FTRWRITE; break;
2981 case 'X': ftst = OP_FTREXEC; break;
2982 case 'O': ftst = OP_FTROWNED; break;
2983 case 'e': ftst = OP_FTIS; break;
2984 case 'z': ftst = OP_FTZERO; break;
2985 case 's': ftst = OP_FTSIZE; break;
2986 case 'f': ftst = OP_FTFILE; break;
2987 case 'd': ftst = OP_FTDIR; break;
2988 case 'l': ftst = OP_FTLINK; break;
2989 case 'p': ftst = OP_FTPIPE; break;
2990 case 'S': ftst = OP_FTSOCK; break;
2991 case 'u': ftst = OP_FTSUID; break;
2992 case 'g': ftst = OP_FTSGID; break;
2993 case 'k': ftst = OP_FTSVTX; break;
2994 case 'b': ftst = OP_FTBLK; break;
2995 case 'c': ftst = OP_FTCHR; break;
2996 case 't': ftst = OP_FTTTY; break;
2997 case 'T': ftst = OP_FTTEXT; break;
2998 case 'B': ftst = OP_FTBINARY; break;
2999 case 'M': case 'A': case 'C':
3000 gv_fetchpv("\024",TRUE, SVt_PV);
3002 case 'M': ftst = OP_FTMTIME; break;
3003 case 'A': ftst = OP_FTATIME; break;
3004 case 'C': ftst = OP_FTCTIME; break;
3012 PL_last_lop_op = (OPCODE)ftst;
3013 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3014 "### Saw file test %c\n", (int)ftst);
3019 /* Assume it was a minus followed by a one-letter named
3020 * subroutine call (or a -bareword), then. */
3021 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3022 "### '-%c' looked like a file test but was not\n",
3031 if (PL_expect == XOPERATOR)
3036 else if (*s == '>') {
3039 if (isIDFIRST_lazy_if(s,UTF)) {
3040 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3048 if (PL_expect == XOPERATOR)
3051 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3053 OPERATOR('-'); /* unary minus */
3060 if (PL_expect == XOPERATOR)
3065 if (PL_expect == XOPERATOR)
3068 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3074 if (PL_expect != XOPERATOR) {
3075 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3076 PL_expect = XOPERATOR;
3077 force_ident(PL_tokenbuf, '*');
3090 if (PL_expect == XOPERATOR) {
3094 PL_tokenbuf[0] = '%';
3095 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3096 if (!PL_tokenbuf[1]) {
3099 PL_pending_ident = '%';
3118 switch (PL_expect) {
3121 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3123 PL_bufptr = s; /* update in case we back off */
3129 PL_expect = XTERMBLOCK;
3133 while (isIDFIRST_lazy_if(s,UTF)) {
3134 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3135 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
3136 if (tmp < 0) tmp = -tmp;
3152 d = scan_str(d,TRUE,TRUE);
3154 /* MUST advance bufptr here to avoid bogus
3155 "at end of line" context messages from yyerror().
3157 PL_bufptr = s + len;
3158 yyerror("Unterminated attribute parameter in attribute list");
3161 return REPORT(0); /* EOF indicator */
3165 SV *sv = newSVpvn(s, len);
3166 sv_catsv(sv, PL_lex_stuff);
3167 attrs = append_elem(OP_LIST, attrs,
3168 newSVOP(OP_CONST, 0, sv));
3169 SvREFCNT_dec(PL_lex_stuff);
3170 PL_lex_stuff = Nullsv;
3173 if (len == 6 && strnEQ(s, "unique", len)) {
3174 if (PL_in_my == KEY_our)
3176 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
3178 ; /* skip to avoid loading attributes.pm */
3181 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
3184 /* NOTE: any CV attrs applied here need to be part of
3185 the CVf_BUILTIN_ATTRS define in cv.h! */
3186 else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
3187 CvLVALUE_on(PL_compcv);
3188 else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
3189 CvLOCKED_on(PL_compcv);
3190 else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
3191 CvMETHOD_on(PL_compcv);
3192 else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len))
3193 CvASSERTION_on(PL_compcv);
3194 /* After we've set the flags, it could be argued that
3195 we don't need to do the attributes.pm-based setting
3196 process, and shouldn't bother appending recognized
3197 flags. To experiment with that, uncomment the
3198 following "else". (Note that's already been
3199 uncommented. That keeps the above-applied built-in
3200 attributes from being intercepted (and possibly
3201 rejected) by a package's attribute routines, but is
3202 justified by the performance win for the common case
3203 of applying only built-in attributes.) */
3205 attrs = append_elem(OP_LIST, attrs,
3206 newSVOP(OP_CONST, 0,
3210 if (*s == ':' && s[1] != ':')
3213 break; /* require real whitespace or :'s */
3215 tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
3216 if (*s != ';' && *s != '}' && *s != tmp && (tmp != '=' || *s != ')')) {
3217 char q = ((*s == '\'') ? '"' : '\'');
3218 /* If here for an expression, and parsed no attrs, back off. */
3219 if (tmp == '=' && !attrs) {
3223 /* MUST advance bufptr here to avoid bogus "at end of line"
3224 context messages from yyerror().
3228 yyerror("Unterminated attribute list");
3230 yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
3238 PL_nextval[PL_nexttoke].opval = attrs;
3246 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
3247 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
3264 if (PL_lex_brackets <= 0)
3265 yyerror("Unmatched right square bracket");
3268 if (PL_lex_state == LEX_INTERPNORMAL) {
3269 if (PL_lex_brackets == 0) {
3270 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3271 PL_lex_state = LEX_INTERPEND;
3278 if (PL_lex_brackets > 100) {
3279 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
3281 switch (PL_expect) {
3283 if (PL_lex_formbrack) {
3287 if (PL_oldoldbufptr == PL_last_lop)
3288 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3290 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3291 OPERATOR(HASHBRACK);
3293 while (s < PL_bufend && SPACE_OR_TAB(*s))
3296 PL_tokenbuf[0] = '\0';
3297 if (d < PL_bufend && *d == '-') {
3298 PL_tokenbuf[0] = '-';
3300 while (d < PL_bufend && SPACE_OR_TAB(*d))
3303 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3304 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
3306 while (d < PL_bufend && SPACE_OR_TAB(*d))
3309 char minus = (PL_tokenbuf[0] == '-');
3310 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
3318 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
3323 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3328 if (PL_oldoldbufptr == PL_last_lop)
3329 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3331 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3334 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
3336 /* This hack is to get the ${} in the message. */
3338 yyerror("syntax error");
3341 OPERATOR(HASHBRACK);
3343 /* This hack serves to disambiguate a pair of curlies
3344 * as being a block or an anon hash. Normally, expectation
3345 * determines that, but in cases where we're not in a
3346 * position to expect anything in particular (like inside
3347 * eval"") we have to resolve the ambiguity. This code
3348 * covers the case where the first term in the curlies is a
3349 * quoted string. Most other cases need to be explicitly
3350 * disambiguated by prepending a `+' before the opening
3351 * curly in order to force resolution as an anon hash.
3353 * XXX should probably propagate the outer expectation
3354 * into eval"" to rely less on this hack, but that could
3355 * potentially break current behavior of eval"".
3359 if (*s == '\'' || *s == '"' || *s == '`') {
3360 /* common case: get past first string, handling escapes */
3361 for (t++; t < PL_bufend && *t != *s;)
3362 if (*t++ == '\\' && (*t == '\\' || *t == *s))
3366 else if (*s == 'q') {
3369 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
3372 /* skip q//-like construct */
3374 char open, close, term;
3377 while (t < PL_bufend && isSPACE(*t))
3379 /* check for q => */
3380 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
3381 OPERATOR(HASHBRACK);
3385 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
3389 for (t++; t < PL_bufend; t++) {
3390 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
3392 else if (*t == open)
3396 for (t++; t < PL_bufend; t++) {
3397 if (*t == '\\' && t+1 < PL_bufend)
3399 else if (*t == close && --brackets <= 0)
3401 else if (*t == open)
3408 /* skip plain q word */
3409 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3412 else if (isALNUM_lazy_if(t,UTF)) {
3414 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3417 while (t < PL_bufend && isSPACE(*t))
3419 /* if comma follows first term, call it an anon hash */
3420 /* XXX it could be a comma expression with loop modifiers */
3421 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
3422 || (*t == '=' && t[1] == '>')))
3423 OPERATOR(HASHBRACK);
3424 if (PL_expect == XREF)
3427 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3433 yylval.ival = CopLINE(PL_curcop);
3434 if (isSPACE(*s) || *s == '#')
3435 PL_copline = NOLINE; /* invalidate current command line number */
3440 if (PL_lex_brackets <= 0)
3441 yyerror("Unmatched right curly bracket");
3443 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3444 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3445 PL_lex_formbrack = 0;
3446 if (PL_lex_state == LEX_INTERPNORMAL) {
3447 if (PL_lex_brackets == 0) {
3448 if (PL_expect & XFAKEBRACK) {
3449 PL_expect &= XENUMMASK;
3450 PL_lex_state = LEX_INTERPEND;
3452 return yylex(); /* ignore fake brackets */
3454 if (*s == '-' && s[1] == '>')
3455 PL_lex_state = LEX_INTERPENDMAYBE;
3456 else if (*s != '[' && *s != '{')
3457 PL_lex_state = LEX_INTERPEND;
3460 if (PL_expect & XFAKEBRACK) {
3461 PL_expect &= XENUMMASK;
3463 return yylex(); /* ignore fake brackets */
3473 if (PL_expect == XOPERATOR) {
3474 if (ckWARN(WARN_SEMICOLON)
3475 && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart)
3477 CopLINE_dec(PL_curcop);
3478 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
3479 CopLINE_inc(PL_curcop);
3484 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3486 PL_expect = XOPERATOR;
3487 force_ident(PL_tokenbuf, '&');
3491 yylval.ival = (OPpENTERSUB_AMPER<<8);
3510 if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
3511 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Reversed %c= operator",(int)tmp);
3513 if (PL_expect == XSTATE && isALPHA(tmp) &&
3514 (s == PL_linestart+1 || s[-2] == '\n') )
3516 if (PL_in_eval && !PL_rsfp) {
3521 if (strnEQ(s,"=cut",4)) {
3535 PL_doextract = TRUE;
3538 if (PL_lex_brackets < PL_lex_formbrack) {
3540 #ifdef PERL_STRICT_CR
3541 for (t = s; SPACE_OR_TAB(*t); t++) ;
3543 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3545 if (*t == '\n' || *t == '#') {
3557 /* was this !=~ where !~ was meant?
3558 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
3560 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
3563 while (t < PL_bufend && isSPACE(*t))
3566 if (*t == '/' || *t == '?' ||
3567 ((*t == 'm' || *t == 's' || *t == 'y') && !isALNUM(t[1])) ||
3568 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
3569 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3570 "!=~ should be !~");
3579 if (PL_expect != XOPERATOR) {
3580 if (s[1] != '<' && !strchr(s,'>'))
3583 s = scan_heredoc(s);
3585 s = scan_inputsymbol(s);
3586 TERM(sublex_start());
3591 SHop(OP_LEFT_SHIFT);
3605 SHop(OP_RIGHT_SHIFT);
3614 if (PL_expect == XOPERATOR) {
3615 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3618 return REPORT(','); /* grandfather non-comma-format format */
3622 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3623 PL_tokenbuf[0] = '@';
3624 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3625 sizeof PL_tokenbuf - 1, FALSE);
3626 if (PL_expect == XOPERATOR)
3627 no_op("Array length", s);
3628 if (!PL_tokenbuf[1])
3630 PL_expect = XOPERATOR;
3631 PL_pending_ident = '#';
3635 PL_tokenbuf[0] = '$';
3636 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3637 sizeof PL_tokenbuf - 1, FALSE);
3638 if (PL_expect == XOPERATOR)
3640 if (!PL_tokenbuf[1]) {
3642 yyerror("Final $ should be \\$ or $name");
3646 /* This kludge not intended to be bulletproof. */
3647 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3648 yylval.opval = newSVOP(OP_CONST, 0,
3649 newSViv(PL_compiling.cop_arybase));
3650 yylval.opval->op_private = OPpCONST_ARYBASE;
3656 if (PL_lex_state == LEX_NORMAL)
3659 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3662 PL_tokenbuf[0] = '@';
3663 if (ckWARN(WARN_SYNTAX)) {
3665 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3668 PL_bufptr = skipspace(PL_bufptr);
3669 while (t < PL_bufend && *t != ']')
3671 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3672 "Multidimensional syntax %.*s not supported",
3673 (t - PL_bufptr) + 1, PL_bufptr);
3677 else if (*s == '{') {
3678 PL_tokenbuf[0] = '%';
3679 if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") &&
3680 (t = strchr(s, '}')) && (t = strchr(t, '=')))
3682 char tmpbuf[sizeof PL_tokenbuf];
3684 for (t++; isSPACE(*t); t++) ;
3685 if (isIDFIRST_lazy_if(t,UTF)) {
3686 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3687 for (; isSPACE(*t); t++) ;
3688 if (*t == ';' && get_cv(tmpbuf, FALSE))
3689 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3690 "You need to quote \"%s\"", tmpbuf);
3696 PL_expect = XOPERATOR;
3697 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3698 bool islop = (PL_last_lop == PL_oldoldbufptr);
3699 if (!islop || PL_last_lop_op == OP_GREPSTART)
3700 PL_expect = XOPERATOR;
3701 else if (strchr("$@\"'`q", *s))
3702 PL_expect = XTERM; /* e.g. print $fh "foo" */
3703 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3704 PL_expect = XTERM; /* e.g. print $fh &sub */
3705 else if (isIDFIRST_lazy_if(s,UTF)) {
3706 char tmpbuf[sizeof PL_tokenbuf];
3707 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3708 if ((tmp = keyword(tmpbuf, len))) {
3709 /* binary operators exclude handle interpretations */
3721 PL_expect = XTERM; /* e.g. print $fh length() */
3726 PL_expect = XTERM; /* e.g. print $fh subr() */
3729 else if (isDIGIT(*s))
3730 PL_expect = XTERM; /* e.g. print $fh 3 */
3731 else if (*s == '.' && isDIGIT(s[1]))
3732 PL_expect = XTERM; /* e.g. print $fh .3 */
3733 else if ((*s == '?' || *s == '-' || *s == '+')
3734 && !isSPACE(s[1]) && s[1] != '=')
3735 PL_expect = XTERM; /* e.g. print $fh -1 */
3736 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' && s[1] != '/')
3737 PL_expect = XTERM; /* e.g. print $fh /.../
3738 XXX except DORDOR operator */
3739 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3740 PL_expect = XTERM; /* print $fh <<"EOF" */
3742 PL_pending_ident = '$';
3746 if (PL_expect == XOPERATOR)
3748 PL_tokenbuf[0] = '@';
3749 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3750 if (!PL_tokenbuf[1]) {
3753 if (PL_lex_state == LEX_NORMAL)
3755 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3757 PL_tokenbuf[0] = '%';
3759 /* Warn about @ where they meant $. */
3760 if (ckWARN(WARN_SYNTAX)) {
3761 if (*s == '[' || *s == '{') {
3763 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3765 if (*t == '}' || *t == ']') {
3767 PL_bufptr = skipspace(PL_bufptr);
3768 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3769 "Scalar value %.*s better written as $%.*s",
3770 t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3775 PL_pending_ident = '@';
3778 case '/': /* may be division, defined-or, or pattern */
3779 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
3783 case '?': /* may either be conditional or pattern */
3784 if(PL_expect == XOPERATOR) {
3792 /* A // operator. */
3802 /* Disable warning on "study /blah/" */
3803 if (PL_oldoldbufptr == PL_last_uni
3804 && (*PL_last_uni != 's' || s - PL_last_uni < 5
3805 || memNE(PL_last_uni, "study", 5)
3806 || isALNUM_lazy_if(PL_last_uni+5,UTF)
3809 s = scan_pat(s,OP_MATCH);
3810 TERM(sublex_start());
3814 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3815 #ifdef PERL_STRICT_CR
3818 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3820 && (s == PL_linestart || s[-1] == '\n') )
3822 PL_lex_formbrack = 0;
3826 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3832 yylval.ival = OPf_SPECIAL;
3838 if (PL_expect != XOPERATOR)
3843 case '0': case '1': case '2': case '3': case '4':
3844 case '5': case '6': case '7': case '8': case '9':
3845 s = scan_num(s, &yylval);
3846 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3847 "### Saw number in '%s'\n", s);
3849 if (PL_expect == XOPERATOR)
3854 s = scan_str(s,FALSE,FALSE);
3855 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3856 "### Saw string before '%s'\n", s);
3858 if (PL_expect == XOPERATOR) {
3859 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3862 return REPORT(','); /* grandfather non-comma-format format */
3868 missingterm((char*)0);
3869 yylval.ival = OP_CONST;
3870 TERM(sublex_start());
3873 s = scan_str(s,FALSE,FALSE);
3874 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3875 "### Saw string before '%s'\n", s);
3877 if (PL_expect == XOPERATOR) {
3878 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3881 return REPORT(','); /* grandfather non-comma-format format */
3887 missingterm((char*)0);
3888 yylval.ival = OP_CONST;
3889 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3890 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
3891 yylval.ival = OP_STRINGIFY;
3895 TERM(sublex_start());
3898 s = scan_str(s,FALSE,FALSE);
3899 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3900 "### Saw backtick string before '%s'\n", s);
3902 if (PL_expect == XOPERATOR)
3903 no_op("Backticks",s);
3905 missingterm((char*)0);
3906 yylval.ival = OP_BACKTICK;
3908 TERM(sublex_start());
3912 if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s))
3913 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
3915 if (PL_expect == XOPERATOR)
3916 no_op("Backslash",s);
3920 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
3924 while (isDIGIT(*start) || *start == '_')
3926 if (*start == '.' && isDIGIT(start[1])) {
3927 s = scan_num(s, &yylval);
3930 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
3931 else if (!isALPHA(*start) && (PL_expect == XTERM
3932 || PL_expect == XREF || PL_expect == XSTATE
3933 || PL_expect == XTERMORDORDOR)) {
3937 gv = gv_fetchpv(s, FALSE, SVt_PVCV);
3940 s = scan_num(s, &yylval);
3947 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
3987 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3989 /* Some keywords can be followed by any delimiter, including ':' */
3990 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
3991 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
3992 (PL_tokenbuf[0] == 'q' &&
3993 strchr("qwxr", PL_tokenbuf[1])))));
3995 /* x::* is just a word, unless x is "CORE" */
3996 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4000 while (d < PL_bufend && isSPACE(*d))
4001 d++; /* no comments skipped here, or s### is misparsed */
4003 /* Is this a label? */
4004 if (!tmp && PL_expect == XSTATE
4005 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4007 yylval.pval = savepv(PL_tokenbuf);
4012 /* Check for keywords */
4013 tmp = keyword(PL_tokenbuf, len);
4015 /* Is this a word before a => operator? */
4016 if (*d == '=' && d[1] == '>') {
4019 = (OP*)newSVOP(OP_CONST, 0,
4020 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
4021 yylval.opval->op_private = OPpCONST_BARE;
4025 if (tmp < 0) { /* second-class keyword? */
4026 GV *ogv = Nullgv; /* override (winner) */
4027 GV *hgv = Nullgv; /* hidden (loser) */
4028 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4030 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
4033 if (GvIMPORTED_CV(gv))
4035 else if (! CvMETHOD(cv))
4039 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4040 (gv = *gvp) != (GV*)&PL_sv_undef &&
4041 GvCVu(gv) && GvIMPORTED_CV(gv))
4048 tmp = 0; /* overridden by import or by GLOBAL */
4051 && -tmp==KEY_lock /* XXX generalizable kludge */
4053 && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
4055 tmp = 0; /* any sub overrides "weak" keyword */
4060 && PL_expect != XOPERATOR
4061 && PL_expect != XTERMORDORDOR)
4063 /* any sub overrides the "err" keyword, except when really an
4064 * operator is expected */
4067 else { /* no override */
4069 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
4070 Perl_warner(aTHX_ packWARN(WARN_MISC),
4071 "dump() better written as CORE::dump()");
4075 if (ckWARN(WARN_AMBIGUOUS) && hgv
4076 && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
4077 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4078 "Ambiguous call resolved as CORE::%s(), %s",
4079 GvENAME(hgv), "qualify as such or use &");
4086 default: /* not a keyword */
4090 char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
4092 /* Get the rest if it looks like a package qualifier */
4094 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
4096 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
4099 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
4100 *s == '\'' ? "'" : "::");
4105 if (PL_expect == XOPERATOR) {
4106 if (PL_bufptr == PL_linestart) {
4107 CopLINE_dec(PL_curcop);
4108 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4109 CopLINE_inc(PL_curcop);
4112 no_op("Bareword",s);
4115 /* Look for a subroutine with this name in current package,
4116 unless name is "Foo::", in which case Foo is a bearword
4117 (and a package name). */
4120 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
4122 if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
4123 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
4124 "Bareword \"%s\" refers to nonexistent package",
4127 PL_tokenbuf[len] = '\0';
4134 gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
4137 /* if we saw a global override before, get the right name */
4140 sv = newSVpvn("CORE::GLOBAL::",14);
4141 sv_catpv(sv,PL_tokenbuf);
4144 /* If len is 0, newSVpv does strlen(), which is correct.
4145 If len is non-zero, then it will be the true length,
4146 and so the scalar will be created correctly. */
4147 sv = newSVpv(PL_tokenbuf,len);
4150 /* Presume this is going to be a bareword of some sort. */
4153 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4154 yylval.opval->op_private = OPpCONST_BARE;
4155 /* UTF-8 package name? */
4156 if (UTF && !IN_BYTES &&
4157 is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
4160 /* And if "Foo::", then that's what it certainly is. */
4165 /* See if it's the indirect object for a list operator. */
4167 if (PL_oldoldbufptr &&
4168 PL_oldoldbufptr < PL_bufptr &&
4169 (PL_oldoldbufptr == PL_last_lop
4170 || PL_oldoldbufptr == PL_last_uni) &&
4171 /* NO SKIPSPACE BEFORE HERE! */
4172 (PL_expect == XREF ||
4173 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
4175 bool immediate_paren = *s == '(';
4177 /* (Now we can afford to cross potential line boundary.) */
4180 /* Two barewords in a row may indicate method call. */
4182 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv)))
4185 /* If not a declared subroutine, it's an indirect object. */
4186 /* (But it's an indir obj regardless for sort.) */
4188 if ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
4189 ((!gv || !GvCVu(gv)) &&
4190 (PL_last_lop_op != OP_MAPSTART &&
4191 PL_last_lop_op != OP_GREPSTART))))
4193 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
4198 PL_expect = XOPERATOR;
4201 /* Is this a word before a => operator? */
4202 if (*s == '=' && s[1] == '>' && !pkgname) {
4204 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
4205 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
4206 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
4210 /* If followed by a paren, it's certainly a subroutine. */
4213 if (gv && GvCVu(gv)) {
4214 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
4215 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
4220 PL_nextval[PL_nexttoke].opval = yylval.opval;
4221 PL_expect = XOPERATOR;
4227 /* If followed by var or block, call it a method (unless sub) */
4229 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
4230 PL_last_lop = PL_oldbufptr;
4231 PL_last_lop_op = OP_METHOD;
4235 /* If followed by a bareword, see if it looks like indir obj. */
4238 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
4239 && (tmp = intuit_method(s,gv)))
4242 /* Not a method, so call it a subroutine (if defined) */
4244 if (gv && GvCVu(gv)) {
4246 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
4247 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4248 "Ambiguous use of -%s resolved as -&%s()",
4249 PL_tokenbuf, PL_tokenbuf);
4250 /* Check for a constant sub */
4252 if ((sv = cv_const_sv(cv))) {
4254 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
4255 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
4256 yylval.opval->op_private = 0;
4260 /* Resolve to GV now. */
4261 op_free(yylval.opval);
4262 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4263 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
4264 PL_last_lop = PL_oldbufptr;
4265 PL_last_lop_op = OP_ENTERSUB;
4266 /* Is there a prototype? */
4269 char *proto = SvPV((SV*)cv, len);
4272 if (*proto == '$' && proto[1] == '\0')
4274 while (*proto == ';')
4276 if (*proto == '&' && *s == '{') {
4277 sv_setpv(PL_subname, PL_curstash ?
4278 "__ANON__" : "__ANON__::__ANON__");
4282 PL_nextval[PL_nexttoke].opval = yylval.opval;
4288 /* Call it a bare word */
4290 if (PL_hints & HINT_STRICT_SUBS)
4291 yylval.opval->op_private |= OPpCONST_STRICT;
4294 if (ckWARN(WARN_RESERVED)) {
4295 if (lastchar != '-') {
4296 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
4297 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
4298 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
4305 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
4306 && ckWARN_d(WARN_AMBIGUOUS)) {
4307 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4308 "Operator or semicolon missing before %c%s",
4309 lastchar, PL_tokenbuf);
4310 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4311 "Ambiguous use of %c resolved as operator %c",
4312 lastchar, lastchar);
4318 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4319 newSVpv(CopFILE(PL_curcop),0));
4323 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4324 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
4327 case KEY___PACKAGE__:
4328 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4330 ? newSVpv(HvNAME(PL_curstash), 0)
4339 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
4340 const char *pname = "main";
4341 if (PL_tokenbuf[2] == 'D')
4342 pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash);
4343 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);
4346 GvIOp(gv) = newIO();
4347 IoIFP(GvIOp(gv)) = PL_rsfp;
4348 #if defined(HAS_FCNTL) && defined(F_SETFD)
4350 int fd = PerlIO_fileno(PL_rsfp);
4351 fcntl(fd,F_SETFD,fd >= 3);
4354 /* Mark this internal pseudo-handle as clean */
4355 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4357 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
4358 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
4359 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
4361 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
4362 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
4363 /* if the script was opened in binmode, we need to revert
4364 * it to text mode for compatibility; but only iff it has CRs
4365 * XXX this is a questionable hack at best. */
4366 if (PL_bufend-PL_bufptr > 2
4367 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
4370 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
4371 loc = PerlIO_tell(PL_rsfp);
4372 (void)PerlIO_seek(PL_rsfp, 0L, 0);
4375 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
4377 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
4378 #endif /* NETWARE */
4379 #ifdef PERLIO_IS_STDIO /* really? */
4380 # if defined(__BORLANDC__)
4381 /* XXX see note in do_binmode() */
4382 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
4386 PerlIO_seek(PL_rsfp, loc, 0);
4390 #ifdef PERLIO_LAYERS
4393 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
4394 else if (PL_encoding) {
4401 XPUSHs(PL_encoding);
4403 call_method("name", G_SCALAR);
4407 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
4408 Perl_form(aTHX_ ":encoding(%"SVf")",
4426 if (PL_expect == XSTATE) {
4433 if (*s == ':' && s[1] == ':') {
4436 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4437 if (!(tmp = keyword(PL_tokenbuf, len)))
4438 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
4452 LOP(OP_ACCEPT,XTERM);
4458 LOP(OP_ATAN2,XTERM);
4464 LOP(OP_BINMODE,XTERM);
4467 LOP(OP_BLESS,XTERM);
4476 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
4493 if (!PL_cryptseen) {
4494 PL_cryptseen = TRUE;
4498 LOP(OP_CRYPT,XTERM);
4501 LOP(OP_CHMOD,XTERM);
4504 LOP(OP_CHOWN,XTERM);
4507 LOP(OP_CONNECT,XTERM);
4523 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4527 PL_hints |= HINT_BLOCK_SCOPE;
4537 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
4538 LOP(OP_DBMOPEN,XTERM);
4544 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4551 yylval.ival = CopLINE(PL_curcop);
4565 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4566 UNIBRACK(OP_ENTEREVAL);
4584 case KEY_endhostent:
4590 case KEY_endservent:
4593 case KEY_endprotoent:
4604 yylval.ival = CopLINE(PL_curcop);
4606 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4608 if ((PL_bufend - p) >= 3 &&
4609 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4611 else if ((PL_bufend - p) >= 4 &&
4612 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4615 if (isIDFIRST_lazy_if(p,UTF)) {
4616 p = scan_ident(p, PL_bufend,
4617 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4621 Perl_croak(aTHX_ "Missing $ on loop variable");
4626 LOP(OP_FORMLINE,XTERM);
4632 LOP(OP_FCNTL,XTERM);
4638 LOP(OP_FLOCK,XTERM);
4647 LOP(OP_GREPSTART, XREF);
4650 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4665 case KEY_getpriority:
4666 LOP(OP_GETPRIORITY,XTERM);
4668 case KEY_getprotobyname:
4671 case KEY_getprotobynumber:
4672 LOP(OP_GPBYNUMBER,XTERM);
4674 case KEY_getprotoent:
4686 case KEY_getpeername:
4687 UNI(OP_GETPEERNAME);
4689 case KEY_gethostbyname:
4692 case KEY_gethostbyaddr:
4693 LOP(OP_GHBYADDR,XTERM);
4695 case KEY_gethostent:
4698 case KEY_getnetbyname:
4701 case KEY_getnetbyaddr:
4702 LOP(OP_GNBYADDR,XTERM);
4707 case KEY_getservbyname:
4708 LOP(OP_GSBYNAME,XTERM);
4710 case KEY_getservbyport:
4711 LOP(OP_GSBYPORT,XTERM);
4713 case KEY_getservent:
4716 case KEY_getsockname:
4717 UNI(OP_GETSOCKNAME);
4719 case KEY_getsockopt:
4720 LOP(OP_GSOCKOPT,XTERM);
4742 yylval.ival = CopLINE(PL_curcop);
4746 LOP(OP_INDEX,XTERM);
4752 LOP(OP_IOCTL,XTERM);
4764 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4796 LOP(OP_LISTEN,XTERM);
4805 s = scan_pat(s,OP_MATCH);
4806 TERM(sublex_start());
4809 LOP(OP_MAPSTART, XREF);
4812 LOP(OP_MKDIR,XTERM);
4815 LOP(OP_MSGCTL,XTERM);
4818 LOP(OP_MSGGET,XTERM);
4821 LOP(OP_MSGRCV,XTERM);
4824 LOP(OP_MSGSND,XTERM);
4830 if (isIDFIRST_lazy_if(s,UTF)) {
4831 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4832 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4834 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
4835 if (!PL_in_my_stash) {
4838 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4846 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4853 if (PL_expect != XSTATE)
4854 yyerror("\"no\" not allowed in expression");
4855 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4856 s = force_version(s, FALSE);
4861 if (*s == '(' || (s = skipspace(s), *s == '('))
4868 if (isIDFIRST_lazy_if(s,UTF)) {
4870 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
4871 for (t=d; *t && isSPACE(*t); t++) ;
4872 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
4874 && !(t[0] == '=' && t[1] == '>')
4876 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
4877 "Precedence problem: open %.*s should be open(%.*s)",
4878 d - s, s, d - s, s);
4884 yylval.ival = OP_OR;
4894 LOP(OP_OPEN_DIR,XTERM);
4897 checkcomma(s,PL_tokenbuf,"filehandle");
4901 checkcomma(s,PL_tokenbuf,"filehandle");
4920 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4924 LOP(OP_PIPE_OP,XTERM);
4927 s = scan_str(s,FALSE,FALSE);
4929 missingterm((char*)0);
4930 yylval.ival = OP_CONST;
4931 TERM(sublex_start());
4937 s = scan_str(s,FALSE,FALSE);
4939 missingterm((char*)0);
4941 if (SvCUR(PL_lex_stuff)) {
4944 d = SvPV_force(PL_lex_stuff, len);
4947 for (; isSPACE(*d) && len; --len, ++d) ;
4950 if (!warned && ckWARN(WARN_QW)) {
4951 for (; !isSPACE(*d) && len; --len, ++d) {
4953 Perl_warner(aTHX_ packWARN(WARN_QW),
4954 "Possible attempt to separate words with commas");
4957 else if (*d == '#') {
4958 Perl_warner(aTHX_ packWARN(WARN_QW),
4959 "Possible attempt to put comments in qw() list");
4965 for (; !isSPACE(*d) && len; --len, ++d) ;
4967 sv = newSVpvn(b, d-b);
4968 if (DO_UTF8(PL_lex_stuff))
4970 words = append_elem(OP_LIST, words,
4971 newSVOP(OP_CONST, 0, tokeq(sv)));
4975 PL_nextval[PL_nexttoke].opval = words;
4980 SvREFCNT_dec(PL_lex_stuff);
4981 PL_lex_stuff = Nullsv;
4987 s = scan_str(s,FALSE,FALSE);
4989 missingterm((char*)0);
4990 yylval.ival = OP_STRINGIFY;
4991 if (SvIVX(PL_lex_stuff) == '\'')
4992 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
4993 TERM(sublex_start());
4996 s = scan_pat(s,OP_QR);
4997 TERM(sublex_start());
5000 s = scan_str(s,FALSE,FALSE);
5002 missingterm((char*)0);
5003 yylval.ival = OP_BACKTICK;
5005 TERM(sublex_start());
5013 s = force_version(s, FALSE);
5015 else if (*s != 'v' || !isDIGIT(s[1])
5016 || (s = force_version(s, TRUE), *s == 'v'))
5018 *PL_tokenbuf = '\0';
5019 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5020 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
5021 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
5023 yyerror("<> should be quotes");
5031 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5035 LOP(OP_RENAME,XTERM);
5044 LOP(OP_RINDEX,XTERM);
5054 UNIDOR(OP_READLINE);
5067 LOP(OP_REVERSE,XTERM);
5070 UNIDOR(OP_READLINK);
5078 TERM(sublex_start());
5080 TOKEN(1); /* force error */
5089 LOP(OP_SELECT,XTERM);
5095 LOP(OP_SEMCTL,XTERM);
5098 LOP(OP_SEMGET,XTERM);
5101 LOP(OP_SEMOP,XTERM);
5107 LOP(OP_SETPGRP,XTERM);
5109 case KEY_setpriority:
5110 LOP(OP_SETPRIORITY,XTERM);
5112 case KEY_sethostent:
5118 case KEY_setservent:
5121 case KEY_setprotoent:
5131 LOP(OP_SEEKDIR,XTERM);
5133 case KEY_setsockopt:
5134 LOP(OP_SSOCKOPT,XTERM);
5140 LOP(OP_SHMCTL,XTERM);
5143 LOP(OP_SHMGET,XTERM);
5146 LOP(OP_SHMREAD,XTERM);
5149 LOP(OP_SHMWRITE,XTERM);
5152 LOP(OP_SHUTDOWN,XTERM);
5161 LOP(OP_SOCKET,XTERM);
5163 case KEY_socketpair:
5164 LOP(OP_SOCKPAIR,XTERM);
5167 checkcomma(s,PL_tokenbuf,"subroutine name");
5169 if (*s == ';' || *s == ')') /* probably a close */
5170 Perl_croak(aTHX_ "sort is now a reserved word");
5172 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5176 LOP(OP_SPLIT,XTERM);
5179 LOP(OP_SPRINTF,XTERM);
5182 LOP(OP_SPLICE,XTERM);
5197 LOP(OP_SUBSTR,XTERM);
5203 char tmpbuf[sizeof PL_tokenbuf];
5204 SSize_t tboffset = 0;
5205 expectation attrful;
5206 bool have_name, have_proto, bad_proto;
5211 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
5212 (*s == ':' && s[1] == ':'))
5215 attrful = XATTRBLOCK;
5216 /* remember buffer pos'n for later force_word */
5217 tboffset = s - PL_oldbufptr;
5218 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5219 if (strchr(tmpbuf, ':'))
5220 sv_setpv(PL_subname, tmpbuf);
5222 sv_setsv(PL_subname,PL_curstname);
5223 sv_catpvn(PL_subname,"::",2);
5224 sv_catpvn(PL_subname,tmpbuf,len);
5231 Perl_croak(aTHX_ "Missing name in \"my sub\"");
5232 PL_expect = XTERMBLOCK;
5233 attrful = XATTRTERM;
5234 sv_setpv(PL_subname,"?");
5238 if (key == KEY_format) {
5240 PL_lex_formbrack = PL_lex_brackets + 1;
5242 (void) force_word(PL_oldbufptr + tboffset, WORD,
5247 /* Look for a prototype */
5251 s = scan_str(s,FALSE,FALSE);
5253 Perl_croak(aTHX_ "Prototype not terminated");
5254 /* strip spaces and check for bad characters */
5255 d = SvPVX(PL_lex_stuff);
5258 for (p = d; *p; ++p) {
5261 if (!strchr("$@%*;[]&\\", *p))
5266 if (bad_proto && ckWARN(WARN_SYNTAX))
5267 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5268 "Illegal character in prototype for %"SVf" : %s",
5270 SvCUR(PL_lex_stuff) = tmp;
5278 if (*s == ':' && s[1] != ':')
5279 PL_expect = attrful;
5280 else if (*s != '{' && key == KEY_sub) {
5282 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
5284 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname);
5288 PL_nextval[PL_nexttoke].opval =
5289 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
5290 PL_lex_stuff = Nullsv;
5294 sv_setpv(PL_subname,
5295 PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
5298 (void) force_word(PL_oldbufptr + tboffset, WORD,
5307 LOP(OP_SYSTEM,XREF);
5310 LOP(OP_SYMLINK,XTERM);
5313 LOP(OP_SYSCALL,XTERM);
5316 LOP(OP_SYSOPEN,XTERM);
5319 LOP(OP_SYSSEEK,XTERM);
5322 LOP(OP_SYSREAD,XTERM);
5325 LOP(OP_SYSWRITE,XTERM);
5329 TERM(sublex_start());
5350 LOP(OP_TRUNCATE,XTERM);
5362 yylval.ival = CopLINE(PL_curcop);
5366 yylval.ival = CopLINE(PL_curcop);
5370 LOP(OP_UNLINK,XTERM);
5376 LOP(OP_UNPACK,XTERM);
5379 LOP(OP_UTIME,XTERM);
5385 LOP(OP_UNSHIFT,XTERM);
5388 if (PL_expect != XSTATE)
5389 yyerror("\"use\" not allowed in expression");
5391 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
5392 s = force_version(s, TRUE);
5393 if (*s == ';' || (s = skipspace(s), *s == ';')) {
5394 PL_nextval[PL_nexttoke].opval = Nullop;
5397 else if (*s == 'v') {
5398 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5399 s = force_version(s, FALSE);
5403 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5404 s = force_version(s, FALSE);
5416 yylval.ival = CopLINE(PL_curcop);
5420 PL_hints |= HINT_BLOCK_SCOPE;
5427 LOP(OP_WAITPID,XTERM);
5436 ctl_l[0] = toCTRL('L');
5438 gv_fetchpv(ctl_l,TRUE, SVt_PV);
5441 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
5446 if (PL_expect == XOPERATOR)
5452 yylval.ival = OP_XOR;
5457 TERM(sublex_start());
5462 #pragma segment Main
5466 S_pending_ident(pTHX)
5469 register I32 tmp = 0;
5470 /* pit holds the identifier we read and pending_ident is reset */
5471 char pit = PL_pending_ident;
5472 PL_pending_ident = 0;
5474 DEBUG_T({ PerlIO_printf(Perl_debug_log,
5475 "### Tokener saw identifier '%s'\n", PL_tokenbuf); });
5477 /* if we're in a my(), we can't allow dynamics here.
5478 $foo'bar has already been turned into $foo::bar, so
5479 just check for colons.
5481 if it's a legal name, the OP is a PADANY.
5484 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
5485 if (strchr(PL_tokenbuf,':'))
5486 yyerror(Perl_form(aTHX_ "No package name allowed for "
5487 "variable %s in \"our\"",
5489 tmp = allocmy(PL_tokenbuf);
5492 if (strchr(PL_tokenbuf,':'))
5493 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
5495 yylval.opval = newOP(OP_PADANY, 0);
5496 yylval.opval->op_targ = allocmy(PL_tokenbuf);
5502 build the ops for accesses to a my() variable.
5504 Deny my($a) or my($b) in a sort block, *if* $a or $b is
5505 then used in a comparison. This catches most, but not
5506 all cases. For instance, it catches
5507 sort { my($a); $a <=> $b }
5509 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
5510 (although why you'd do that is anyone's guess).
5513 if (!strchr(PL_tokenbuf,':')) {
5515 tmp = pad_findmy(PL_tokenbuf);
5516 if (tmp != NOT_IN_PAD) {
5517 /* might be an "our" variable" */
5518 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
5519 /* build ops for a bareword */
5520 SV *sym = newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)), 0);
5521 sv_catpvn(sym, "::", 2);
5522 sv_catpv(sym, PL_tokenbuf+1);
5523 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
5524 yylval.opval->op_private = OPpCONST_ENTERED;
5527 ? (GV_ADDMULTI | GV_ADDINEVAL)
5530 ((PL_tokenbuf[0] == '$') ? SVt_PV
5531 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5536 /* if it's a sort block and they're naming $a or $b */
5537 if (PL_last_lop_op == OP_SORT &&
5538 PL_tokenbuf[0] == '$' &&
5539 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
5542 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
5543 d < PL_bufend && *d != '\n';
5546 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
5547 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
5553 yylval.opval = newOP(OP_PADANY, 0);
5554 yylval.opval->op_targ = tmp;
5560 Whine if they've said @foo in a doublequoted string,
5561 and @foo isn't a variable we can find in the symbol
5564 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
5565 GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
5566 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
5567 && ckWARN(WARN_AMBIGUOUS))
5569 /* Downgraded from fatal to warning 20000522 mjd */
5570 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5571 "Possible unintended interpolation of %s in string",
5576 /* build ops for a bareword */
5577 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
5578 yylval.opval->op_private = OPpCONST_ENTERED;
5579 gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
5580 ((PL_tokenbuf[0] == '$') ? SVt_PV
5581 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5587 * The following code was generated by perl_keyword.pl.
5591 Perl_keyword (pTHX_ char *name, I32 len)
5595 case 1: /* 5 tokens of length 1 */
5627 case 2: /* 18 tokens of length 2 */
5773 case 3: /* 28 tokens of length 3 */
5777 if (name[1] == 'N' &&
5840 if (name[1] == 'i' &&
5880 if (name[1] == 'o' &&
5889 if (name[1] == 'e' &&
5898 if (name[1] == 'n' &&
5907 if (name[1] == 'o' &&
5916 if (name[1] == 'a' &&
5925 if (name[1] == 'o' &&
5987 if (name[1] == 'e' &&
6019 if (name[1] == 'i' &&
6028 if (name[1] == 's' &&
6037 if (name[1] == 'e' &&
6046 if (name[1] == 'o' &&
6058 case 4: /* 40 tokens of length 4 */
6062 if (name[1] == 'O' &&
6072 if (name[1] == 'N' &&
6082 if (name[1] == 'i' &&
6092 if (name[1] == 'h' &&
6102 if (name[1] == 'u' &&
6115 if (name[2] == 'c' &&
6124 if (name[2] == 's' &&
6133 if (name[2] == 'a' &&
6169 if (name[1] == 'o' &&
6182 if (name[2] == 't' &&
6191 if (name[2] == 'o' &&
6200 if (name[2] == 't' &&
6209 if (name[2] == 'e' &&
6222 if (name[1] == 'o' &&
6235 if (name[2] == 'y' &&
6244 if (name[2] == 'l' &&
6260 if (name[2] == 's' &&
6269 if (name[2] == 'n' &&
6278 if (name[2] == 'c' &&
6291 if (name[1] == 'e' &&
6301 if (name[1] == 'p' &&
6314 if (name[2] == 'c' &&
6323 if (name[2] == 'p' &&
6332 if (name[2] == 's' &&
6348 if (name[2] == 'n' &&
6418 if (name[2] == 'r' &&
6427 if (name[2] == 'r' &&
6436 if (name[2] == 'a' &&
6452 if (name[2] == 'l' &&
6519 case 5: /* 36 tokens of length 5 */
6523 if (name[1] == 'E' &&
6534 if (name[1] == 'H' &&
6548 if (name[2] == 'a' &&
6558 if (name[2] == 'a' &&
6572 if (name[1] == 'l' &&
6589 if (name[3] == 'i' &&
6598 if (name[3] == 'o' &&
6634 if (name[2] == 'o' &&
6644 if (name[2] == 'y' &&
6658 if (name[1] == 'l' &&
6672 if (name[2] == 'n' &&
6682 if (name[2] == 'o' &&
6699 if (name[2] == 'd' &&
6709 if (name[2] == 'c' &&
6726 if (name[2] == 'c' &&
6736 if (name[2] == 't' &&
6750 if (name[1] == 'k' &&
6761 if (name[1] == 'r' &&
6775 if (name[2] == 's' &&
6785 if (name[2] == 'd' &&
6802 if (name[2] == 'm' &&
6812 if (name[2] == 'i' &&
6822 if (name[2] == 'e' &&
6832 if (name[2] == 'l' &&
6842 if (name[2] == 'a' &&
6852 if (name[2] == 'u' &&
6866 if (name[1] == 'i' &&
6880 if (name[2] == 'a' &&
6893 if (name[3] == 'e' &&
6928 if (name[2] == 'i' &&
6945 if (name[2] == 'i' &&
6955 if (name[2] == 'i' &&
6972 case 6: /* 33 tokens of length 6 */
6976 if (name[1] == 'c' &&
6991 if (name[2] == 'l' &&
7002 if (name[2] == 'r' &&
7017 if (name[1] == 'e' &&
7032 if (name[2] == 's' &&
7037 if(ckWARN_d(WARN_SYNTAX))
7038 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
7044 if (name[2] == 'i' &&
7062 if (name[2] == 'l' &&
7073 if (name[2] == 'r' &&
7088 if (name[1] == 'm' &&
7103 if (name[2] == 'n' &&
7114 if (name[2] == 's' &&
7129 if (name[1] == 's' &&
7135 if (name[4] == 't' &&
7144 if (name[4] == 'e' &&
7153 if (name[4] == 'c' &&
7162 if (name[4] == 'n' &&
7178 if (name[1] == 'r' &&
7196 if (name[3] == 'a' &&
7206 if (name[3] == 'u' &&
7220 if (name[2] == 'n' &&
7238 if (name[2] == 'a' &&
7252 if (name[3] == 'e' &&
7265 if (name[4] == 't' &&
7274 if (name[4] == 'e' &&
7296 if (name[4] == 't' &&
7305 if (name[4] == 'e' &&
7321 if (name[2] == 'c' &&
7332 if (name[2] == 'l' &&
7343 if (name[2] == 'b' &&
7354 if (name[2] == 's' &&
7377 if (name[4] == 's' &&
7386 if (name[4] == 'n' &&
7399 if (name[3] == 'a' &&
7416 if (name[1] == 'a' &&
7431 case 7: /* 28 tokens of length 7 */
7435 if (name[1] == 'E' &&
7448 if (name[1] == '_' &&
7461 if (name[1] == 'i' &&
7468 return -KEY_binmode;
7474 if (name[1] == 'o' &&
7481 return -KEY_connect;
7490 if (name[2] == 'm' &&
7496 return -KEY_dbmopen;
7502 if (name[2] == 'f' &&
7518 if (name[1] == 'o' &&
7531 if (name[1] == 'e' &&
7538 if (name[5] == 'r' &&
7541 return -KEY_getpgrp;
7547 if (name[5] == 'i' &&
7550 return -KEY_getppid;
7563 if (name[1] == 'c' &&
7570 return -KEY_lcfirst;
7576 if (name[1] == 'p' &&
7583 return -KEY_opendir;
7589 if (name[1] == 'a' &&
7607 if (name[3] == 'd' &&
7612 return -KEY_readdir;
7618 if (name[3] == 'u' &&
7629 if (name[3] == 'e' &&
7634 return -KEY_reverse;
7653 if (name[3] == 'k' &&
7658 return -KEY_seekdir;
7664 if (name[3] == 'p' &&
7669 return -KEY_setpgrp;
7679 if (name[2] == 'm' &&
7685 return -KEY_shmread;
7691 if (name[2] == 'r' &&
7697 return -KEY_sprintf;
7706 if (name[3] == 'l' &&
7711 return -KEY_symlink;
7720 if (name[4] == 'a' &&
7724 return -KEY_syscall;
7730 if (name[4] == 'p' &&
7734 return -KEY_sysopen;
7740 if (name[4] == 'e' &&
7744 return -KEY_sysread;
7750 if (name[4] == 'e' &&
7754 return -KEY_sysseek;
7772 if (name[1] == 'e' &&
7779 return -KEY_telldir;
7788 if (name[2] == 'f' &&
7794 return -KEY_ucfirst;
7800 if (name[2] == 's' &&
7806 return -KEY_unshift;
7816 if (name[1] == 'a' &&
7823 return -KEY_waitpid;
7832 case 8: /* 26 tokens of length 8 */
7836 if (name[1] == 'U' &&
7844 return KEY_AUTOLOAD;
7855 if (name[3] == 'A' &&
7861 return KEY___DATA__;
7867 if (name[3] == 'I' &&
7873 return -KEY___FILE__;
7879 if (name[3] == 'I' &&
7885 return -KEY___LINE__;
7901 if (name[2] == 'o' &&
7908 return -KEY_closedir;
7914 if (name[2] == 'n' &&
7921 return -KEY_continue;
7931 if (name[1] == 'b' &&
7939 return -KEY_dbmclose;
7945 if (name[1] == 'n' &&
7951 if (name[4] == 'r' &&
7956 return -KEY_endgrent;
7962 if (name[4] == 'w' &&
7967 return -KEY_endpwent;
7980 if (name[1] == 'o' &&
7988 return -KEY_formline;
7994 if (name[1] == 'e' &&
8005 if (name[6] == 'n' &&
8008 return -KEY_getgrent;
8014 if (name[6] == 'i' &&
8017 return -KEY_getgrgid;
8023 if (name[6] == 'a' &&
8026 return -KEY_getgrnam;
8039 if (name[4] == 'o' &&
8044 return -KEY_getlogin;
8055 if (name[6] == 'n' &&
8058 return -KEY_getpwent;
8064 if (name[6] == 'a' &&
8067 return -KEY_getpwnam;
8073 if (name[6] == 'i' &&
8076 return -KEY_getpwuid;
8096 if (name[1] == 'e' &&
8103 if (name[5] == 'i' &&
8110 return -KEY_readline;
8115 return -KEY_readlink;
8126 if (name[5] == 'i' &&
8130 return -KEY_readpipe;
8151 if (name[4] == 'r' &&
8156 return -KEY_setgrent;
8162 if (name[4] == 'w' &&
8167 return -KEY_setpwent;
8183 if (name[3] == 'w' &&
8189 return -KEY_shmwrite;
8195 if (name[3] == 't' &&
8201 return -KEY_shutdown;
8211 if (name[2] == 's' &&
8218 return -KEY_syswrite;
8228 if (name[1] == 'r' &&
8236 return -KEY_truncate;
8245 case 9: /* 8 tokens of length 9 */
8249 if (name[1] == 'n' &&
8258 return -KEY_endnetent;
8264 if (name[1] == 'e' &&
8273 return -KEY_getnetent;
8279 if (name[1] == 'o' &&
8288 return -KEY_localtime;
8294 if (name[1] == 'r' &&
8303 return KEY_prototype;
8309 if (name[1] == 'u' &&
8318 return -KEY_quotemeta;
8324 if (name[1] == 'e' &&
8333 return -KEY_rewinddir;
8339 if (name[1] == 'e' &&
8348 return -KEY_setnetent;
8354 if (name[1] == 'a' &&
8363 return -KEY_wantarray;
8372 case 10: /* 9 tokens of length 10 */
8376 if (name[1] == 'n' &&
8382 if (name[4] == 'o' &&
8389 return -KEY_endhostent;
8395 if (name[4] == 'e' &&
8402 return -KEY_endservent;
8415 if (name[1] == 'e' &&
8421 if (name[4] == 'o' &&
8428 return -KEY_gethostent;
8437 if (name[5] == 'r' &&
8443 return -KEY_getservent;
8449 if (name[5] == 'c' &&
8455 return -KEY_getsockopt;
8480 if (name[4] == 'o' &&
8487 return -KEY_sethostent;
8496 if (name[5] == 'r' &&
8502 return -KEY_setservent;
8508 if (name[5] == 'c' &&
8514 return -KEY_setsockopt;
8531 if (name[2] == 'c' &&
8540 return -KEY_socketpair;
8553 case 11: /* 8 tokens of length 11 */
8557 if (name[1] == '_' &&
8568 return -KEY___PACKAGE__;
8574 if (name[1] == 'n' &&
8585 return -KEY_endprotoent;
8591 if (name[1] == 'e' &&
8600 if (name[5] == 'e' &&
8607 return -KEY_getpeername;
8616 if (name[6] == 'o' &&
8622 return -KEY_getpriority;
8628 if (name[6] == 't' &&
8634 return -KEY_getprotoent;
8648 if (name[4] == 'o' &&
8656 return -KEY_getsockname;
8669 if (name[1] == 'e' &&
8677 if (name[6] == 'o' &&
8683 return -KEY_setpriority;
8689 if (name[6] == 't' &&
8695 return -KEY_setprotoent;
8711 case 12: /* 2 tokens of length 12 */
8712 if (name[0] == 'g' &&
8724 if (name[9] == 'd' &&
8727 { /* getnetbyaddr */
8728 return -KEY_getnetbyaddr;
8734 if (name[9] == 'a' &&
8737 { /* getnetbyname */
8738 return -KEY_getnetbyname;
8750 case 13: /* 4 tokens of length 13 */
8751 if (name[0] == 'g' &&
8758 if (name[4] == 'o' &&
8767 if (name[10] == 'd' &&
8770 { /* gethostbyaddr */
8771 return -KEY_gethostbyaddr;
8777 if (name[10] == 'a' &&
8780 { /* gethostbyname */
8781 return -KEY_gethostbyname;
8794 if (name[4] == 'e' &&
8803 if (name[10] == 'a' &&
8806 { /* getservbyname */
8807 return -KEY_getservbyname;
8813 if (name[10] == 'o' &&
8816 { /* getservbyport */
8817 return -KEY_getservbyport;
8836 case 14: /* 1 tokens of length 14 */
8837 if (name[0] == 'g' &&
8851 { /* getprotobyname */
8852 return -KEY_getprotobyname;
8857 case 16: /* 1 tokens of length 16 */
8858 if (name[0] == 'g' &&
8874 { /* getprotobynumber */
8875 return -KEY_getprotobynumber;
8889 S_checkcomma(pTHX_ register char *s, char *name, const char *what)
8893 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
8894 if (ckWARN(WARN_SYNTAX)) {
8896 for (w = s+2; *w && level; w++) {
8903 for (; *w && isSPACE(*w); w++) ;
8904 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
8905 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
8906 "%s (...) interpreted as function",name);
8909 while (s < PL_bufend && isSPACE(*s))
8913 while (s < PL_bufend && isSPACE(*s))
8915 if (isIDFIRST_lazy_if(s,UTF)) {
8917 while (isALNUM_lazy_if(s,UTF))
8919 while (s < PL_bufend && isSPACE(*s))
8924 kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
8928 Perl_croak(aTHX_ "No comma allowed after %s", what);
8933 /* Either returns sv, or mortalizes sv and returns a new SV*.
8934 Best used as sv=new_constant(..., sv, ...).
8935 If s, pv are NULL, calls subroutine with one argument,
8936 and type is used with error messages only. */
8939 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
8943 HV *table = GvHV(PL_hintgv); /* ^H */
8947 const char *why1, *why2, *why3;
8949 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
8952 why2 = strEQ(key,"charnames")
8953 ? "(possibly a missing \"use charnames ...\")"
8955 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
8956 (type ? type: "undef"), why2);
8958 /* This is convoluted and evil ("goto considered harmful")
8959 * but I do not understand the intricacies of all the different
8960 * failure modes of %^H in here. The goal here is to make
8961 * the most probable error message user-friendly. --jhi */
8966 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
8967 (type ? type: "undef"), why1, why2, why3);
8969 yyerror(SvPVX(msg));
8973 cvp = hv_fetch(table, key, strlen(key), FALSE);
8974 if (!cvp || !SvOK(*cvp)) {
8977 why3 = "} is not defined";
8980 sv_2mortal(sv); /* Parent created it permanently */
8983 pv = sv_2mortal(newSVpvn(s, len));
8985 typesv = sv_2mortal(newSVpv(type, 0));
8987 typesv = &PL_sv_undef;
8989 PUSHSTACKi(PERLSI_OVERLOAD);
9001 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
9005 /* Check the eval first */
9006 if (!PL_in_eval && SvTRUE(ERRSV)) {
9008 sv_catpv(ERRSV, "Propagated");
9009 yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */
9011 res = SvREFCNT_inc(sv);
9015 (void)SvREFCNT_inc(res);
9024 why1 = "Call to &{$^H{";
9026 why3 = "}} did not return a defined value";
9034 /* Returns a NUL terminated string, with the length of the string written to
9038 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
9040 register char *d = dest;
9041 register char *e = d + destlen - 3; /* two-character token, ending NUL */
9044 Perl_croak(aTHX_ ident_too_long);
9045 if (isALNUM(*s)) /* UTF handled below */
9047 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
9052 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
9056 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9057 char *t = s + UTF8SKIP(s);
9058 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9060 if (d + (t - s) > e)
9061 Perl_croak(aTHX_ ident_too_long);
9062 Copy(s, d, t - s, char);
9075 S_scan_ident(pTHX_ register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni)
9085 e = d + destlen - 3; /* two-character token, ending NUL */
9087 while (isDIGIT(*s)) {
9089 Perl_croak(aTHX_ ident_too_long);
9096 Perl_croak(aTHX_ ident_too_long);
9097 if (isALNUM(*s)) /* UTF handled below */
9099 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
9104 else if (*s == ':' && s[1] == ':') {
9108 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9109 char *t = s + UTF8SKIP(s);
9110 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9112 if (d + (t - s) > e)
9113 Perl_croak(aTHX_ ident_too_long);
9114 Copy(s, d, t - s, char);
9125 if (PL_lex_state != LEX_NORMAL)
9126 PL_lex_state = LEX_INTERPENDMAYBE;
9129 if (*s == '$' && s[1] &&
9130 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
9143 if (*d == '^' && *s && isCONTROLVAR(*s)) {
9148 if (isSPACE(s[-1])) {
9151 if (!SPACE_OR_TAB(ch)) {
9157 if (isIDFIRST_lazy_if(d,UTF)) {
9161 while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') {
9163 while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e))
9166 Copy(s, d, e - s, char);
9171 while ((isALNUM(*s) || *s == ':') && d < e)
9174 Perl_croak(aTHX_ ident_too_long);
9177 while (s < send && SPACE_OR_TAB(*s)) s++;
9178 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
9179 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
9180 const char *brack = *s == '[' ? "[...]" : "{...}";
9181 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9182 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
9183 funny, dest, brack, funny, dest, brack);
9186 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
9190 /* Handle extended ${^Foo} variables
9191 * 1999-02-27 mjd-perl-patch@plover.com */
9192 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
9196 while (isALNUM(*s) && d < e) {
9200 Perl_croak(aTHX_ ident_too_long);
9205 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
9206 PL_lex_state = LEX_INTERPEND;
9211 if (PL_lex_state == LEX_NORMAL) {
9212 if (ckWARN(WARN_AMBIGUOUS) &&
9213 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
9215 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9216 "Ambiguous use of %c{%s} resolved to %c%s",
9217 funny, dest, funny, dest);
9222 s = bracket; /* let the parser handle it */
9226 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
9227 PL_lex_state = LEX_INTERPEND;
9232 Perl_pmflag(pTHX_ U32* pmfl, int ch)
9237 *pmfl |= PMf_GLOBAL;
9239 *pmfl |= PMf_CONTINUE;
9243 *pmfl |= PMf_MULTILINE;
9245 *pmfl |= PMf_SINGLELINE;
9247 *pmfl |= PMf_EXTENDED;
9251 S_scan_pat(pTHX_ char *start, I32 type)
9256 s = scan_str(start,FALSE,FALSE);
9258 Perl_croak(aTHX_ "Search pattern not terminated");
9260 pm = (PMOP*)newPMOP(type, 0);
9261 if (PL_multi_open == '?')
9262 pm->op_pmflags |= PMf_ONCE;
9264 while (*s && strchr("iomsx", *s))
9265 pmflag(&pm->op_pmflags,*s++);
9268 while (*s && strchr("iogcmsx", *s))
9269 pmflag(&pm->op_pmflags,*s++);
9271 /* issue a warning if /c is specified,but /g is not */
9272 if (ckWARN(WARN_REGEXP) &&
9273 (pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
9275 Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_without_g);
9278 pm->op_pmpermflags = pm->op_pmflags;
9280 PL_lex_op = (OP*)pm;
9281 yylval.ival = OP_MATCH;
9286 S_scan_subst(pTHX_ char *start)
9293 yylval.ival = OP_NULL;
9295 s = scan_str(start,FALSE,FALSE);
9298 Perl_croak(aTHX_ "Substitution pattern not terminated");
9300 if (s[-1] == PL_multi_open)
9303 first_start = PL_multi_start;
9304 s = scan_str(s,FALSE,FALSE);
9307 SvREFCNT_dec(PL_lex_stuff);
9308 PL_lex_stuff = Nullsv;
9310 Perl_croak(aTHX_ "Substitution replacement not terminated");
9312 PL_multi_start = first_start; /* so whole substitution is taken together */
9314 pm = (PMOP*)newPMOP(OP_SUBST, 0);
9320 else if (strchr("iogcmsx", *s))
9321 pmflag(&pm->op_pmflags,*s++);
9326 /* /c is not meaningful with s/// */
9327 if (ckWARN(WARN_REGEXP) && (pm->op_pmflags & PMf_CONTINUE))
9329 Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_in_subst);
9334 PL_sublex_info.super_bufptr = s;
9335 PL_sublex_info.super_bufend = PL_bufend;
9337 pm->op_pmflags |= PMf_EVAL;
9338 repl = newSVpvn("",0);
9340 sv_catpv(repl, es ? "eval " : "do ");
9341 sv_catpvn(repl, "{ ", 2);
9342 sv_catsv(repl, PL_lex_repl);
9343 sv_catpvn(repl, " };", 2);
9345 SvREFCNT_dec(PL_lex_repl);
9349 pm->op_pmpermflags = pm->op_pmflags;
9350 PL_lex_op = (OP*)pm;
9351 yylval.ival = OP_SUBST;
9356 S_scan_trans(pTHX_ char *start)
9365 yylval.ival = OP_NULL;
9367 s = scan_str(start,FALSE,FALSE);
9369 Perl_croak(aTHX_ "Transliteration pattern not terminated");
9370 if (s[-1] == PL_multi_open)
9373 s = scan_str(s,FALSE,FALSE);
9376 SvREFCNT_dec(PL_lex_stuff);
9377 PL_lex_stuff = Nullsv;
9379 Perl_croak(aTHX_ "Transliteration replacement not terminated");
9382 complement = del = squash = 0;
9386 complement = OPpTRANS_COMPLEMENT;
9389 del = OPpTRANS_DELETE;
9392 squash = OPpTRANS_SQUASH;
9401 New(803, tbl, complement&&!del?258:256, short);
9402 o = newPVOP(OP_TRANS, 0, (char*)tbl);
9403 o->op_private &= ~OPpTRANS_ALL;
9404 o->op_private |= del|squash|complement|
9405 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
9406 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
9409 yylval.ival = OP_TRANS;
9414 S_scan_heredoc(pTHX_ register char *s)
9417 I32 op_type = OP_SCALAR;
9421 const char newline[] = "\n";
9422 const char *found_newline;
9426 int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
9430 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
9433 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
9434 if (*peek == '`' || *peek == '\'' || *peek =='"') {
9437 s = delimcpy(d, e, s, PL_bufend, term, &len);
9447 if (!isALNUM_lazy_if(s,UTF))
9448 deprecate_old("bare << to mean <<\"\"");
9449 for (; isALNUM_lazy_if(s,UTF); s++) {
9454 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
9455 Perl_croak(aTHX_ "Delimiter for here document is too long");
9458 len = d - PL_tokenbuf;
9459 #ifndef PERL_STRICT_CR
9460 d = strchr(s, '\r');
9464 while (s < PL_bufend) {
9470 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
9479 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
9483 if ( outer || !(found_newline = ninstr(s,PL_bufend,newline,newline+1)) ) {
9484 herewas = newSVpvn(s,PL_bufend-s);
9488 herewas = newSVpvn(s,found_newline-s);
9490 s += SvCUR(herewas);
9492 tmpstr = NEWSV(87,79);
9493 sv_upgrade(tmpstr, SVt_PVIV);
9496 SvIV_set(tmpstr, -1);
9498 else if (term == '`') {
9499 op_type = OP_BACKTICK;
9500 SvIV_set(tmpstr, '\\');
9504 PL_multi_start = CopLINE(PL_curcop);
9505 PL_multi_open = PL_multi_close = '<';
9506 term = *PL_tokenbuf;
9507 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
9508 char *bufptr = PL_sublex_info.super_bufptr;
9509 char *bufend = PL_sublex_info.super_bufend;
9510 char *olds = s - SvCUR(herewas);
9511 s = strchr(bufptr, '\n');
9515 while (s < bufend &&
9516 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9518 CopLINE_inc(PL_curcop);
9521 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9522 missingterm(PL_tokenbuf);
9524 sv_setpvn(herewas,bufptr,d-bufptr+1);
9525 sv_setpvn(tmpstr,d+1,s-d);
9527 sv_catpvn(herewas,s,bufend-s);
9528 Copy(SvPVX(herewas),bufptr,SvCUR(herewas) + 1,char);
9535 while (s < PL_bufend &&
9536 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9538 CopLINE_inc(PL_curcop);
9540 if (s >= PL_bufend) {
9541 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9542 missingterm(PL_tokenbuf);
9544 sv_setpvn(tmpstr,d+1,s-d);
9546 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
9548 sv_catpvn(herewas,s,PL_bufend-s);
9549 sv_setsv(PL_linestr,herewas);
9550 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
9551 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9552 PL_last_lop = PL_last_uni = Nullch;
9555 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
9556 while (s >= PL_bufend) { /* multiple line string? */
9558 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
9559 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9560 missingterm(PL_tokenbuf);
9562 CopLINE_inc(PL_curcop);
9563 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9564 PL_last_lop = PL_last_uni = Nullch;
9565 #ifndef PERL_STRICT_CR
9566 if (PL_bufend - PL_linestart >= 2) {
9567 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
9568 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
9570 PL_bufend[-2] = '\n';
9572 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
9574 else if (PL_bufend[-1] == '\r')
9575 PL_bufend[-1] = '\n';
9577 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
9578 PL_bufend[-1] = '\n';
9580 if (PERLDB_LINE && PL_curstash != PL_debstash) {
9581 SV *sv = NEWSV(88,0);
9583 sv_upgrade(sv, SVt_PVMG);
9584 sv_setsv(sv,PL_linestr);
9587 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
9589 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
9590 STRLEN off = PL_bufend - 1 - SvPVX(PL_linestr);
9591 *(SvPVX(PL_linestr) + off ) = ' ';
9592 sv_catsv(PL_linestr,herewas);
9593 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9594 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
9598 sv_catsv(tmpstr,PL_linestr);
9603 PL_multi_end = CopLINE(PL_curcop);
9604 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
9605 SvPV_shrink_to_cur(tmpstr);
9607 SvREFCNT_dec(herewas);
9609 if (UTF && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr)))
9611 else if (PL_encoding)
9612 sv_recode_to_utf8(tmpstr, PL_encoding);
9614 PL_lex_stuff = tmpstr;
9615 yylval.ival = op_type;
9620 takes: current position in input buffer
9621 returns: new position in input buffer
9622 side-effects: yylval and lex_op are set.
9627 <FH> read from filehandle
9628 <pkg::FH> read from package qualified filehandle
9629 <pkg'FH> read from package qualified filehandle
9630 <$fh> read from filehandle in $fh
9636 S_scan_inputsymbol(pTHX_ char *start)
9638 register char *s = start; /* current position in buffer */
9644 d = PL_tokenbuf; /* start of temp holding space */
9645 e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
9646 end = strchr(s, '\n');
9649 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
9651 /* die if we didn't have space for the contents of the <>,
9652 or if it didn't end, or if we see a newline
9655 if (len >= sizeof PL_tokenbuf)
9656 Perl_croak(aTHX_ "Excessively long <> operator");
9658 Perl_croak(aTHX_ "Unterminated <> operator");
9663 Remember, only scalar variables are interpreted as filehandles by
9664 this code. Anything more complex (e.g., <$fh{$num}>) will be
9665 treated as a glob() call.
9666 This code makes use of the fact that except for the $ at the front,
9667 a scalar variable and a filehandle look the same.
9669 if (*d == '$' && d[1]) d++;
9671 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
9672 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
9675 /* If we've tried to read what we allow filehandles to look like, and
9676 there's still text left, then it must be a glob() and not a getline.
9677 Use scan_str to pull out the stuff between the <> and treat it
9678 as nothing more than a string.
9681 if (d - PL_tokenbuf != len) {
9682 yylval.ival = OP_GLOB;
9684 s = scan_str(start,FALSE,FALSE);
9686 Perl_croak(aTHX_ "Glob not terminated");
9690 bool readline_overriden = FALSE;
9691 GV *gv_readline = Nullgv;
9693 /* we're in a filehandle read situation */
9696 /* turn <> into <ARGV> */
9698 Copy("ARGV",d,5,char);
9700 /* Check whether readline() is overriden */
9701 if (((gv_readline = gv_fetchpv("readline", FALSE, SVt_PVCV))
9702 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
9704 ((gvp = (GV**)hv_fetch(PL_globalstash, "readline", 8, FALSE))
9705 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
9706 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
9707 readline_overriden = TRUE;
9709 /* if <$fh>, create the ops to turn the variable into a
9715 /* try to find it in the pad for this block, otherwise find
9716 add symbol table ops
9718 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
9719 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
9720 SV *sym = sv_2mortal(
9721 newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)),0));
9722 sv_catpvn(sym, "::", 2);
9728 OP *o = newOP(OP_PADSV, 0);
9730 PL_lex_op = readline_overriden
9731 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9732 append_elem(OP_LIST, o,
9733 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
9734 : (OP*)newUNOP(OP_READLINE, 0, o);
9743 ? (GV_ADDMULTI | GV_ADDINEVAL)
9746 PL_lex_op = readline_overriden
9747 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9748 append_elem(OP_LIST,
9749 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
9750 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9751 : (OP*)newUNOP(OP_READLINE, 0,
9752 newUNOP(OP_RV2SV, 0,
9753 newGVOP(OP_GV, 0, gv)));
9755 if (!readline_overriden)
9756 PL_lex_op->op_flags |= OPf_SPECIAL;
9757 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
9758 yylval.ival = OP_NULL;
9761 /* If it's none of the above, it must be a literal filehandle
9762 (<Foo::BAR> or <FOO>) so build a simple readline OP */
9764 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
9765 PL_lex_op = readline_overriden
9766 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9767 append_elem(OP_LIST,
9768 newGVOP(OP_GV, 0, gv),
9769 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9770 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
9771 yylval.ival = OP_NULL;
9780 takes: start position in buffer
9781 keep_quoted preserve \ on the embedded delimiter(s)
9782 keep_delims preserve the delimiters around the string
9783 returns: position to continue reading from buffer
9784 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
9785 updates the read buffer.
9787 This subroutine pulls a string out of the input. It is called for:
9788 q single quotes q(literal text)
9789 ' single quotes 'literal text'
9790 qq double quotes qq(interpolate $here please)
9791 " double quotes "interpolate $here please"
9792 qx backticks qx(/bin/ls -l)
9793 ` backticks `/bin/ls -l`
9794 qw quote words @EXPORT_OK = qw( func() $spam )
9795 m// regexp match m/this/
9796 s/// regexp substitute s/this/that/
9797 tr/// string transliterate tr/this/that/
9798 y/// string transliterate y/this/that/
9799 ($*@) sub prototypes sub foo ($)
9800 (stuff) sub attr parameters sub foo : attr(stuff)
9801 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
9803 In most of these cases (all but <>, patterns and transliterate)
9804 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
9805 calls scan_str(). s/// makes yylex() call scan_subst() which calls
9806 scan_str(). tr/// and y/// make yylex() call scan_trans() which
9809 It skips whitespace before the string starts, and treats the first
9810 character as the delimiter. If the delimiter is one of ([{< then
9811 the corresponding "close" character )]}> is used as the closing
9812 delimiter. It allows quoting of delimiters, and if the string has
9813 balanced delimiters ([{<>}]) it allows nesting.
9815 On success, the SV with the resulting string is put into lex_stuff or,
9816 if that is already non-NULL, into lex_repl. The second case occurs only
9817 when parsing the RHS of the special constructs s/// and tr/// (y///).
9818 For convenience, the terminating delimiter character is stuffed into
9823 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
9825 SV *sv; /* scalar value: string */
9826 char *tmps; /* temp string, used for delimiter matching */
9827 register char *s = start; /* current position in the buffer */
9828 register char term; /* terminating character */
9829 register char *to; /* current position in the sv's data */
9830 I32 brackets = 1; /* bracket nesting level */
9831 bool has_utf8 = FALSE; /* is there any utf8 content? */
9832 I32 termcode; /* terminating char. code */
9833 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
9834 STRLEN termlen; /* length of terminating string */
9835 char *last = NULL; /* last position for nesting bracket */
9837 /* skip space before the delimiter */
9841 /* mark where we are, in case we need to report errors */
9844 /* after skipping whitespace, the next character is the terminator */
9847 termcode = termstr[0] = term;
9851 termcode = utf8_to_uvchr((U8*)s, &termlen);
9852 Copy(s, termstr, termlen, U8);
9853 if (!UTF8_IS_INVARIANT(term))
9857 /* mark where we are */
9858 PL_multi_start = CopLINE(PL_curcop);
9859 PL_multi_open = term;
9861 /* find corresponding closing delimiter */
9862 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
9863 termcode = termstr[0] = term = tmps[5];
9865 PL_multi_close = term;
9867 /* create a new SV to hold the contents. 87 is leak category, I'm
9868 assuming. 79 is the SV's initial length. What a random number. */
9870 sv_upgrade(sv, SVt_PVIV);
9871 SvIV_set(sv, termcode);
9872 (void)SvPOK_only(sv); /* validate pointer */
9874 /* move past delimiter and try to read a complete string */
9876 sv_catpvn(sv, s, termlen);
9879 if (PL_encoding && !UTF) {
9883 int offset = s - SvPVX(PL_linestr);
9884 bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
9885 &offset, (char*)termstr, termlen);
9886 char *ns = SvPVX(PL_linestr) + offset;
9887 char *svlast = SvEND(sv) - 1;
9889 for (; s < ns; s++) {
9890 if (*s == '\n' && !PL_rsfp)
9891 CopLINE_inc(PL_curcop);
9894 goto read_more_line;
9896 /* handle quoted delimiters */
9897 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
9899 for (t = svlast-2; t >= SvPVX(sv) && *t == '\\';)
9901 if ((svlast-1 - t) % 2) {
9905 SvCUR_set(sv, SvCUR(sv) - 1);
9910 if (PL_multi_open == PL_multi_close) {
9917 for (w = t = last; t < svlast; w++, t++) {
9918 /* At here, all closes are "was quoted" one,
9919 so we don't check PL_multi_close. */
9921 if (!keep_quoted && *(t+1) == PL_multi_open)
9926 else if (*t == PL_multi_open)
9934 SvCUR_set(sv, w - SvPVX(sv));
9937 if (--brackets <= 0)
9943 SvCUR_set(sv, SvCUR(sv) - 1);
9949 /* extend sv if need be */
9950 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
9951 /* set 'to' to the next character in the sv's string */
9952 to = SvPVX(sv)+SvCUR(sv);
9954 /* if open delimiter is the close delimiter read unbridle */
9955 if (PL_multi_open == PL_multi_close) {
9956 for (; s < PL_bufend; s++,to++) {
9957 /* embedded newlines increment the current line number */
9958 if (*s == '\n' && !PL_rsfp)
9959 CopLINE_inc(PL_curcop);
9960 /* handle quoted delimiters */
9961 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
9962 if (!keep_quoted && s[1] == term)
9964 /* any other quotes are simply copied straight through */
9968 /* terminate when run out of buffer (the for() condition), or
9969 have found the terminator */
9970 else if (*s == term) {
9973 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
9976 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
9982 /* if the terminator isn't the same as the start character (e.g.,
9983 matched brackets), we have to allow more in the quoting, and
9984 be prepared for nested brackets.
9987 /* read until we run out of string, or we find the terminator */
9988 for (; s < PL_bufend; s++,to++) {
9989 /* embedded newlines increment the line count */
9990 if (*s == '\n' && !PL_rsfp)
9991 CopLINE_inc(PL_curcop);
9992 /* backslashes can escape the open or closing characters */
9993 if (*s == '\\' && s+1 < PL_bufend) {
9995 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
10000 /* allow nested opens and closes */
10001 else if (*s == PL_multi_close && --brackets <= 0)
10003 else if (*s == PL_multi_open)
10005 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
10010 /* terminate the copied string and update the sv's end-of-string */
10012 SvCUR_set(sv, to - SvPVX(sv));
10015 * this next chunk reads more into the buffer if we're not done yet
10019 break; /* handle case where we are done yet :-) */
10021 #ifndef PERL_STRICT_CR
10022 if (to - SvPVX(sv) >= 2) {
10023 if ((to[-2] == '\r' && to[-1] == '\n') ||
10024 (to[-2] == '\n' && to[-1] == '\r'))
10028 SvCUR_set(sv, to - SvPVX(sv));
10030 else if (to[-1] == '\r')
10033 else if (to - SvPVX(sv) == 1 && to[-1] == '\r')
10038 /* if we're out of file, or a read fails, bail and reset the current
10039 line marker so we can report where the unterminated string began
10042 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
10044 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10047 /* we read a line, so increment our line counter */
10048 CopLINE_inc(PL_curcop);
10050 /* update debugger info */
10051 if (PERLDB_LINE && PL_curstash != PL_debstash) {
10052 SV *sv = NEWSV(88,0);
10054 sv_upgrade(sv, SVt_PVMG);
10055 sv_setsv(sv,PL_linestr);
10056 (void)SvIOK_on(sv);
10058 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
10061 /* having changed the buffer, we must update PL_bufend */
10062 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10063 PL_last_lop = PL_last_uni = Nullch;
10066 /* at this point, we have successfully read the delimited string */
10068 if (!PL_encoding || UTF) {
10070 sv_catpvn(sv, s, termlen);
10073 if (has_utf8 || PL_encoding)
10076 PL_multi_end = CopLINE(PL_curcop);
10078 /* if we allocated too much space, give some back */
10079 if (SvCUR(sv) + 5 < SvLEN(sv)) {
10080 SvLEN_set(sv, SvCUR(sv) + 1);
10081 SvPV_renew(sv, SvLEN(sv));
10084 /* decide whether this is the first or second quoted string we've read
10097 takes: pointer to position in buffer
10098 returns: pointer to new position in buffer
10099 side-effects: builds ops for the constant in yylval.op
10101 Read a number in any of the formats that Perl accepts:
10103 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
10104 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
10107 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
10109 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
10112 If it reads a number without a decimal point or an exponent, it will
10113 try converting the number to an integer and see if it can do so
10114 without loss of precision.
10118 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
10120 register const char *s = start; /* current position in buffer */
10121 register char *d; /* destination in temp buffer */
10122 register char *e; /* end of temp buffer */
10123 NV nv; /* number read, as a double */
10124 SV *sv = Nullsv; /* place to put the converted number */
10125 bool floatit; /* boolean: int or float? */
10126 const char *lastub = 0; /* position of last underbar */
10127 static char const number_too_long[] = "Number too long";
10129 /* We use the first character to decide what type of number this is */
10133 Perl_croak(aTHX_ "panic: scan_num");
10135 /* if it starts with a 0, it could be an octal number, a decimal in
10136 0.13 disguise, or a hexadecimal number, or a binary number. */
10140 u holds the "number so far"
10141 shift the power of 2 of the base
10142 (hex == 4, octal == 3, binary == 1)
10143 overflowed was the number more than we can hold?
10145 Shift is used when we add a digit. It also serves as an "are
10146 we in octal/hex/binary?" indicator to disallow hex characters
10147 when in octal mode.
10152 bool overflowed = FALSE;
10153 bool just_zero = TRUE; /* just plain 0 or binary number? */
10154 static NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
10155 static char const* bases[5] = { "", "binary", "", "octal",
10157 static char const* Bases[5] = { "", "Binary", "", "Octal",
10159 static char const *maxima[5] = { "",
10160 "0b11111111111111111111111111111111",
10164 const char *base, *Base, *max;
10166 /* check for hex */
10171 } else if (s[1] == 'b') {
10176 /* check for a decimal in disguise */
10177 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
10179 /* so it must be octal */
10186 if (ckWARN(WARN_SYNTAX))
10187 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10188 "Misplaced _ in number");
10192 base = bases[shift];
10193 Base = Bases[shift];
10194 max = maxima[shift];
10196 /* read the rest of the number */
10198 /* x is used in the overflow test,
10199 b is the digit we're adding on. */
10204 /* if we don't mention it, we're done */
10208 /* _ are ignored -- but warned about if consecutive */
10210 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10211 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10212 "Misplaced _ in number");
10216 /* 8 and 9 are not octal */
10217 case '8': case '9':
10219 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
10223 case '2': case '3': case '4':
10224 case '5': case '6': case '7':
10226 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
10229 case '0': case '1':
10230 b = *s++ & 15; /* ASCII digit -> value of digit */
10234 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
10235 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
10236 /* make sure they said 0x */
10239 b = (*s++ & 7) + 9;
10241 /* Prepare to put the digit we have onto the end
10242 of the number so far. We check for overflows.
10248 x = u << shift; /* make room for the digit */
10250 if ((x >> shift) != u
10251 && !(PL_hints & HINT_NEW_BINARY)) {
10254 if (ckWARN_d(WARN_OVERFLOW))
10255 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
10256 "Integer overflow in %s number",
10259 u = x | b; /* add the digit to the end */
10262 n *= nvshift[shift];
10263 /* If an NV has not enough bits in its
10264 * mantissa to represent an UV this summing of
10265 * small low-order numbers is a waste of time
10266 * (because the NV cannot preserve the
10267 * low-order bits anyway): we could just
10268 * remember when did we overflow and in the
10269 * end just multiply n by the right
10277 /* if we get here, we had success: make a scalar value from
10282 /* final misplaced underbar check */
10283 if (s[-1] == '_') {
10284 if (ckWARN(WARN_SYNTAX))
10285 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10290 if (ckWARN(WARN_PORTABLE) && n > 4294967295.0)
10291 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10292 "%s number > %s non-portable",
10298 if (ckWARN(WARN_PORTABLE) && u > 0xffffffff)
10299 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10300 "%s number > %s non-portable",
10305 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
10306 sv = new_constant(start, s - start, "integer",
10308 else if (PL_hints & HINT_NEW_BINARY)
10309 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
10314 handle decimal numbers.
10315 we're also sent here when we read a 0 as the first digit
10317 case '1': case '2': case '3': case '4': case '5':
10318 case '6': case '7': case '8': case '9': case '.':
10321 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
10324 /* read next group of digits and _ and copy into d */
10325 while (isDIGIT(*s) || *s == '_') {
10326 /* skip underscores, checking for misplaced ones
10330 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10331 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10332 "Misplaced _ in number");
10336 /* check for end of fixed-length buffer */
10338 Perl_croak(aTHX_ number_too_long);
10339 /* if we're ok, copy the character */
10344 /* final misplaced underbar check */
10345 if (lastub && s == lastub + 1) {
10346 if (ckWARN(WARN_SYNTAX))
10347 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10350 /* read a decimal portion if there is one. avoid
10351 3..5 being interpreted as the number 3. followed
10354 if (*s == '.' && s[1] != '.') {
10359 if (ckWARN(WARN_SYNTAX))
10360 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10361 "Misplaced _ in number");
10365 /* copy, ignoring underbars, until we run out of digits.
10367 for (; isDIGIT(*s) || *s == '_'; s++) {
10368 /* fixed length buffer check */
10370 Perl_croak(aTHX_ number_too_long);
10372 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10373 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10374 "Misplaced _ in number");
10380 /* fractional part ending in underbar? */
10381 if (s[-1] == '_') {
10382 if (ckWARN(WARN_SYNTAX))
10383 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10384 "Misplaced _ in number");
10386 if (*s == '.' && isDIGIT(s[1])) {
10387 /* oops, it's really a v-string, but without the "v" */
10393 /* read exponent part, if present */
10394 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
10398 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
10399 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
10401 /* stray preinitial _ */
10403 if (ckWARN(WARN_SYNTAX))
10404 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10405 "Misplaced _ in number");
10409 /* allow positive or negative exponent */
10410 if (*s == '+' || *s == '-')
10413 /* stray initial _ */
10415 if (ckWARN(WARN_SYNTAX))
10416 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10417 "Misplaced _ in number");
10421 /* read digits of exponent */
10422 while (isDIGIT(*s) || *s == '_') {
10425 Perl_croak(aTHX_ number_too_long);
10429 if (ckWARN(WARN_SYNTAX) &&
10430 ((lastub && s == lastub + 1) ||
10431 (!isDIGIT(s[1]) && s[1] != '_')))
10432 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10433 "Misplaced _ in number");
10440 /* make an sv from the string */
10444 We try to do an integer conversion first if no characters
10445 indicating "float" have been found.
10450 int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
10452 if (flags == IS_NUMBER_IN_UV) {
10454 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
10457 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
10458 if (uv <= (UV) IV_MIN)
10459 sv_setiv(sv, -(IV)uv);
10466 /* terminate the string */
10468 nv = Atof(PL_tokenbuf);
10472 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
10473 (PL_hints & HINT_NEW_INTEGER) )
10474 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
10475 (floatit ? "float" : "integer"),
10479 /* if it starts with a v, it could be a v-string */
10482 sv = NEWSV(92,5); /* preallocate storage space */
10483 s = scan_vstring(s,sv);
10487 /* make the op for the constant and return */
10490 lvalp->opval = newSVOP(OP_CONST, 0, sv);
10492 lvalp->opval = Nullop;
10498 S_scan_formline(pTHX_ register char *s)
10500 register char *eol;
10502 SV *stuff = newSVpvn("",0);
10503 bool needargs = FALSE;
10504 bool eofmt = FALSE;
10506 while (!needargs) {
10509 #ifdef PERL_STRICT_CR
10510 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
10512 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
10514 if (*t == '\n' || t == PL_bufend) {
10519 if (PL_in_eval && !PL_rsfp) {
10520 eol = (char *) memchr(s,'\n',PL_bufend-s);
10525 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10527 for (t = s; t < eol; t++) {
10528 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
10530 goto enough; /* ~~ must be first line in formline */
10532 if (*t == '@' || *t == '^')
10536 sv_catpvn(stuff, s, eol-s);
10537 #ifndef PERL_STRICT_CR
10538 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
10539 char *end = SvPVX(stuff) + SvCUR(stuff);
10551 s = filter_gets(PL_linestr, PL_rsfp, 0);
10552 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
10553 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
10554 PL_last_lop = PL_last_uni = Nullch;
10563 if (SvCUR(stuff)) {
10566 PL_lex_state = LEX_NORMAL;
10567 PL_nextval[PL_nexttoke].ival = 0;
10571 PL_lex_state = LEX_FORMLINE;
10573 if (UTF && is_utf8_string((U8*)SvPVX(stuff), SvCUR(stuff)))
10575 else if (PL_encoding)
10576 sv_recode_to_utf8(stuff, PL_encoding);
10578 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
10580 PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
10584 SvREFCNT_dec(stuff);
10586 PL_lex_formbrack = 0;
10597 PL_cshlen = strlen(PL_cshname);
10602 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
10604 I32 oldsavestack_ix = PL_savestack_ix;
10605 CV* outsidecv = PL_compcv;
10608 assert(SvTYPE(PL_compcv) == SVt_PVCV);
10610 SAVEI32(PL_subline);
10611 save_item(PL_subname);
10612 SAVESPTR(PL_compcv);
10614 PL_compcv = (CV*)NEWSV(1104,0);
10615 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
10616 CvFLAGS(PL_compcv) |= flags;
10618 PL_subline = CopLINE(PL_curcop);
10619 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
10620 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
10621 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
10623 return oldsavestack_ix;
10627 #pragma segment Perl_yylex
10630 Perl_yywarn(pTHX_ const char *s)
10632 PL_in_eval |= EVAL_WARNONLY;
10634 PL_in_eval &= ~EVAL_WARNONLY;
10639 Perl_yyerror(pTHX_ const char *s)
10641 const char *where = NULL;
10642 const char *context = NULL;
10646 if (!yychar || (yychar == ';' && !PL_rsfp))
10648 else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 &&
10649 PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) {
10652 The code below is removed for NetWare because it abends/crashes on NetWare
10653 when the script has error such as not having the closing quotes like:
10654 if ($var eq "value)
10655 Checking of white spaces is anyway done in NetWare code.
10658 while (isSPACE(*PL_oldoldbufptr))
10661 context = PL_oldoldbufptr;
10662 contlen = PL_bufptr - PL_oldoldbufptr;
10664 else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 &&
10665 PL_oldbufptr != PL_bufptr) {
10668 The code below is removed for NetWare because it abends/crashes on NetWare
10669 when the script has error such as not having the closing quotes like:
10670 if ($var eq "value)
10671 Checking of white spaces is anyway done in NetWare code.
10674 while (isSPACE(*PL_oldbufptr))
10677 context = PL_oldbufptr;
10678 contlen = PL_bufptr - PL_oldbufptr;
10680 else if (yychar > 255)
10681 where = "next token ???";
10682 else if (yychar == -2) { /* YYEMPTY */
10683 if (PL_lex_state == LEX_NORMAL ||
10684 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
10685 where = "at end of line";
10686 else if (PL_lex_inpat)
10687 where = "within pattern";
10689 where = "within string";
10692 SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
10694 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
10695 else if (isPRINT_LC(yychar))
10696 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
10698 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
10699 where = SvPVX(where_sv);
10701 msg = sv_2mortal(newSVpv(s, 0));
10702 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
10703 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
10705 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
10707 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
10708 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
10709 Perl_sv_catpvf(aTHX_ msg,
10710 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
10711 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
10714 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
10715 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg);
10718 if (PL_error_count >= 10) {
10719 if (PL_in_eval && SvCUR(ERRSV))
10720 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
10721 ERRSV, OutCopFILE(PL_curcop));
10723 Perl_croak(aTHX_ "%s has too many errors.\n",
10724 OutCopFILE(PL_curcop));
10727 PL_in_my_stash = Nullhv;
10731 #pragma segment Main
10735 S_swallow_bom(pTHX_ U8 *s)
10738 slen = SvCUR(PL_linestr);
10741 if (s[1] == 0xFE) {
10742 /* UTF-16 little-endian? (or UTF32-LE?) */
10743 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
10744 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
10745 #ifndef PERL_NO_UTF16_FILTER
10746 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
10749 if (PL_bufend > (char*)s) {
10753 filter_add(utf16rev_textfilter, NULL);
10754 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10755 utf16_to_utf8_reversed(s, news,
10756 PL_bufend - (char*)s - 1,
10758 sv_setpvn(PL_linestr, (const char*)news, newlen);
10760 SvUTF8_on(PL_linestr);
10761 s = (U8*)SvPVX(PL_linestr);
10762 PL_bufend = SvPVX(PL_linestr) + newlen;
10765 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
10770 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
10771 #ifndef PERL_NO_UTF16_FILTER
10772 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
10775 if (PL_bufend > (char *)s) {
10779 filter_add(utf16_textfilter, NULL);
10780 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10781 utf16_to_utf8(s, news,
10782 PL_bufend - (char*)s,
10784 sv_setpvn(PL_linestr, (const char*)news, newlen);
10786 SvUTF8_on(PL_linestr);
10787 s = (U8*)SvPVX(PL_linestr);
10788 PL_bufend = SvPVX(PL_linestr) + newlen;
10791 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
10796 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
10797 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
10798 s += 3; /* UTF-8 */
10804 if (s[2] == 0xFE && s[3] == 0xFF) {
10805 /* UTF-32 big-endian */
10806 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
10809 else if (s[2] == 0 && s[3] != 0) {
10812 * are a good indicator of UTF-16BE. */
10813 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
10818 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
10821 * are a good indicator of UTF-16LE. */
10822 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
10831 * Restore a source filter.
10835 restore_rsfp(pTHX_ void *f)
10837 PerlIO *fp = (PerlIO*)f;
10839 if (PL_rsfp == PerlIO_stdin())
10840 PerlIO_clearerr(PL_rsfp);
10841 else if (PL_rsfp && (PL_rsfp != fp))
10842 PerlIO_close(PL_rsfp);
10846 #ifndef PERL_NO_UTF16_FILTER
10848 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10850 STRLEN old = SvCUR(sv);
10851 I32 count = FILTER_READ(idx+1, sv, maxlen);
10852 DEBUG_P(PerlIO_printf(Perl_debug_log,
10853 "utf16_textfilter(%p): %d %d (%d)\n",
10854 utf16_textfilter, idx, maxlen, (int) count));
10858 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10859 Copy(SvPVX(sv), tmps, old, char);
10860 utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old,
10861 SvCUR(sv) - old, &newlen);
10862 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10864 DEBUG_P({sv_dump(sv);});
10869 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10871 STRLEN old = SvCUR(sv);
10872 I32 count = FILTER_READ(idx+1, sv, maxlen);
10873 DEBUG_P(PerlIO_printf(Perl_debug_log,
10874 "utf16rev_textfilter(%p): %d %d (%d)\n",
10875 utf16rev_textfilter, idx, maxlen, (int) count));
10879 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10880 Copy(SvPVX(sv), tmps, old, char);
10881 utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old,
10882 SvCUR(sv) - old, &newlen);
10883 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10885 DEBUG_P({ sv_dump(sv); });
10891 Returns a pointer to the next character after the parsed
10892 vstring, as well as updating the passed in sv.
10894 Function must be called like
10897 s = scan_vstring(s,sv);
10899 The sv should already be large enough to store the vstring
10900 passed in, for performance reasons.
10905 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
10907 const char *pos = s;
10908 const char *start = s;
10909 if (*pos == 'v') pos++; /* get past 'v' */
10910 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
10912 if ( *pos != '.') {
10913 /* this may not be a v-string if followed by => */
10914 const char *next = pos;
10915 while (next < PL_bufend && isSPACE(*next))
10917 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
10918 /* return string not v-string */
10919 sv_setpvn(sv,(char *)s,pos-s);
10920 return (char *)pos;
10924 if (!isALPHA(*pos)) {
10926 U8 tmpbuf[UTF8_MAXBYTES+1];
10929 if (*s == 'v') s++; /* get past 'v' */
10931 sv_setpvn(sv, "", 0);
10936 /* this is atoi() that tolerates underscores */
10937 const char *end = pos;
10939 while (--end >= s) {
10944 rev += (*end - '0') * mult;
10946 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
10947 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
10948 "Integer overflow in decimal number");
10952 if (rev > 0x7FFFFFFF)
10953 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
10955 /* Append native character for the rev point */
10956 tmpend = uvchr_to_utf8(tmpbuf, rev);
10957 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
10958 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
10960 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
10966 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
10970 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
10978 * c-indentation-style: bsd
10979 * c-basic-offset: 4
10980 * indent-tabs-mode: t
10983 * vim: shiftwidth=4: