3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "It all comes from here, the stench and the peril." --Frodo
16 * This file is the lexer for Perl. It's closely linked to the
19 * The main routine is yylex(), which returns the next token.
23 #define PERL_IN_TOKE_C
26 #define yychar (*PL_yycharp)
27 #define yylval (*PL_yylvalp)
29 static const char ident_too_long[] =
30 "Identifier too long";
31 static const char c_without_g[] =
32 "Use of /c modifier is meaningless without /g";
33 static const char c_in_subst[] =
34 "Use of /c modifier is meaningless in s///";
36 static void restore_rsfp(pTHX_ void *f);
37 #ifndef PERL_NO_UTF16_FILTER
38 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
39 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
42 #define XFAKEBRACK 128
45 #ifdef USE_UTF8_SCRIPTS
46 # define UTF (!IN_BYTES)
48 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
51 /* In variables named $^X, these are the legal values for X.
52 * 1999-02-27 mjd-perl-patch@plover.com */
53 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
55 /* On MacOS, respect nonbreaking spaces */
56 #ifdef MACOS_TRADITIONAL
57 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
59 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
62 /* LEX_* are values for PL_lex_state, the state of the lexer.
63 * They are arranged oddly so that the guard on the switch statement
64 * can get by with a single comparison (if the compiler is smart enough).
67 /* #define LEX_NOTPARSING 11 is done in perl.h. */
70 #define LEX_INTERPNORMAL 9
71 #define LEX_INTERPCASEMOD 8
72 #define LEX_INTERPPUSH 7
73 #define LEX_INTERPSTART 6
74 #define LEX_INTERPEND 5
75 #define LEX_INTERPENDMAYBE 4
76 #define LEX_INTERPCONCAT 3
77 #define LEX_INTERPCONST 2
78 #define LEX_FORMLINE 1
79 #define LEX_KNOWNEXT 0
82 static const char* const lex_state_names[] = {
101 #include "keywords.h"
103 /* CLINE is a macro that ensures PL_copline has a sane value */
108 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
111 * Convenience functions to return different tokens and prime the
112 * lexer for the next token. They all take an argument.
114 * TOKEN : generic token (used for '(', DOLSHARP, etc)
115 * OPERATOR : generic operator
116 * AOPERATOR : assignment operator
117 * PREBLOCK : beginning the block after an if, while, foreach, ...
118 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
119 * PREREF : *EXPR where EXPR is not a simple identifier
120 * TERM : expression term
121 * LOOPX : loop exiting command (goto, last, dump, etc)
122 * FTST : file test operator
123 * FUN0 : zero-argument function
124 * FUN1 : not used, except for not, which isn't a UNIOP
125 * BOop : bitwise or or xor
127 * SHop : shift operator
128 * PWop : power operator
129 * PMop : pattern-matching operator
130 * Aop : addition-level operator
131 * Mop : multiplication-level operator
132 * Eop : equality-testing operator
133 * Rop : relational operator <= != gt
135 * Also see LOP and lop() below.
138 #ifdef DEBUGGING /* Serve -DT. */
139 # define REPORT(retval) tokereport(s,(int)retval)
141 # define REPORT(retval) (retval)
144 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
145 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
146 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
147 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
148 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
149 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
150 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
151 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
152 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
153 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
154 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
155 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
156 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
157 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
158 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
159 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
160 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
161 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
162 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
163 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
165 /* This bit of chicanery makes a unary function followed by
166 * a parenthesis into a function with one argument, highest precedence.
167 * The UNIDOR macro is for unary functions that can be followed by the //
168 * operator (such as C<shift // 0>).
170 #define UNI2(f,x) return ( \
174 PL_last_uni = PL_oldbufptr, \
175 PL_last_lop_op = f, \
177 (*s == '(' || (s = skipspace(s), *s == '(') \
178 ? (int)FUNC1 : (int)UNIOP)))
179 #define UNI(f) UNI2(f,XTERM)
180 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
182 #define UNIBRACK(f) return ( \
185 PL_last_uni = PL_oldbufptr, \
187 (*s == '(' || (s = skipspace(s), *s == '(') \
188 ? (int)FUNC1 : (int)UNIOP)))
190 /* grandfather return to old style */
191 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
195 /* how to interpret the yylval associated with the token */
199 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
205 static struct debug_tokens { const int token, type; const char *name; }
206 const debug_tokens[] =
208 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
209 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
210 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
211 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
212 { ARROW, TOKENTYPE_NONE, "ARROW" },
213 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
214 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
215 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
216 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
217 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
218 { DO, TOKENTYPE_NONE, "DO" },
219 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
220 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
221 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
222 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
223 { ELSE, TOKENTYPE_NONE, "ELSE" },
224 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
225 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
226 { FOR, TOKENTYPE_IVAL, "FOR" },
227 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
228 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
229 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
230 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
231 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
232 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
233 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
234 { IF, TOKENTYPE_IVAL, "IF" },
235 { LABEL, TOKENTYPE_PVAL, "LABEL" },
236 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
237 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
238 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
239 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
240 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
241 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
242 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
243 { MY, TOKENTYPE_IVAL, "MY" },
244 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
245 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
246 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
247 { OROP, TOKENTYPE_IVAL, "OROP" },
248 { OROR, TOKENTYPE_NONE, "OROR" },
249 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
250 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
251 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
252 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
253 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
254 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
255 { PREINC, TOKENTYPE_NONE, "PREINC" },
256 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
257 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
258 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
259 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
260 { SUB, TOKENTYPE_NONE, "SUB" },
261 { THING, TOKENTYPE_OPVAL, "THING" },
262 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
263 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
264 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
265 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
266 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
267 { USE, TOKENTYPE_IVAL, "USE" },
268 { WHILE, TOKENTYPE_IVAL, "WHILE" },
269 { WORD, TOKENTYPE_OPVAL, "WORD" },
270 { 0, TOKENTYPE_NONE, 0 }
273 /* dump the returned token in rv, plus any optional arg in yylval */
276 S_tokereport(pTHX_ const char* s, I32 rv)
279 const char *name = Nullch;
280 enum token_type type = TOKENTYPE_NONE;
281 struct debug_tokens *p;
282 SV* report = newSVpvn("<== ", 4);
284 for (p = (struct debug_tokens *)debug_tokens; p->token; p++) {
285 if (p->token == (int)rv) {
292 Perl_sv_catpv(aTHX_ report, name);
293 else if ((char)rv > ' ' && (char)rv < '~')
294 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
296 Perl_sv_catpv(aTHX_ report, "EOF");
298 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
301 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
304 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
306 case TOKENTYPE_OPNUM:
307 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
308 PL_op_name[yylval.ival]);
311 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
313 case TOKENTYPE_OPVAL:
315 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
316 PL_op_name[yylval.opval->op_type]);
318 Perl_sv_catpv(aTHX_ report, "(opval=null)");
321 Perl_sv_catpvf(aTHX_ report, " at line %"IVdf" [", (IV)CopLINE(PL_curcop));
322 if (s - PL_bufptr > 0)
323 sv_catpvn(report, PL_bufptr, s - PL_bufptr);
325 if (PL_oldbufptr && *PL_oldbufptr)
326 sv_catpv(report, PL_tokenbuf);
328 PerlIO_printf(Perl_debug_log, "### %s]\n", SvPV_nolen(report));
338 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
339 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
343 S_ao(pTHX_ int toketype)
345 if (*PL_bufptr == '=') {
347 if (toketype == ANDAND)
348 yylval.ival = OP_ANDASSIGN;
349 else if (toketype == OROR)
350 yylval.ival = OP_ORASSIGN;
351 else if (toketype == DORDOR)
352 yylval.ival = OP_DORASSIGN;
360 * When Perl expects an operator and finds something else, no_op
361 * prints the warning. It always prints "<something> found where
362 * operator expected. It prints "Missing semicolon on previous line?"
363 * if the surprise occurs at the start of the line. "do you need to
364 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
365 * where the compiler doesn't know if foo is a method call or a function.
366 * It prints "Missing operator before end of line" if there's nothing
367 * after the missing operator, or "... before <...>" if there is something
368 * after the missing operator.
372 S_no_op(pTHX_ const char *what, char *s)
374 char *oldbp = PL_bufptr;
375 bool is_first = (PL_oldbufptr == PL_linestart);
381 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
382 if (ckWARN_d(WARN_SYNTAX)) {
384 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
385 "\t(Missing semicolon on previous line?)\n");
386 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
388 for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
389 if (t < PL_bufptr && isSPACE(*t))
390 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
391 "\t(Do you need to predeclare %.*s?)\n",
392 t - PL_oldoldbufptr, PL_oldoldbufptr);
396 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
397 "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
405 * Complain about missing quote/regexp/heredoc terminator.
406 * If it's called with (char *)NULL then it cauterizes the line buffer.
407 * If we're in a delimited string and the delimiter is a control
408 * character, it's reformatted into a two-char sequence like ^C.
413 S_missingterm(pTHX_ char *s)
418 char *nl = strrchr(s,'\n');
424 iscntrl(PL_multi_close)
426 PL_multi_close < 32 || PL_multi_close == 127
430 tmpbuf[1] = toCTRL(PL_multi_close);
435 *tmpbuf = (char)PL_multi_close;
439 q = strchr(s,'"') ? '\'' : '"';
440 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
448 Perl_deprecate(pTHX_ const char *s)
450 if (ckWARN(WARN_DEPRECATED))
451 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
455 Perl_deprecate_old(pTHX_ const char *s)
457 /* This function should NOT be called for any new deprecated warnings */
458 /* Use Perl_deprecate instead */
460 /* It is here to maintain backward compatibility with the pre-5.8 */
461 /* warnings category hierarchy. The "deprecated" category used to */
462 /* live under the "syntax" category. It is now a top-level category */
463 /* in its own right. */
465 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
466 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
467 "Use of %s is deprecated", s);
472 * Deprecate a comma-less variable list.
478 deprecate_old("comma-less variable list");
482 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
483 * utf16-to-utf8-reversed.
486 #ifdef PERL_CR_FILTER
490 register char *s = SvPVX(sv);
491 register char *e = s + SvCUR(sv);
492 /* outer loop optimized to do nothing if there are no CR-LFs */
494 if (*s++ == '\r' && *s == '\n') {
495 /* hit a CR-LF, need to copy the rest */
496 register char *d = s - 1;
499 if (*s == '\r' && s[1] == '\n')
510 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
512 I32 count = FILTER_READ(idx+1, sv, maxlen);
513 if (count > 0 && !maxlen)
521 * Initialize variables. Uses the Perl save_stack to save its state (for
522 * recursive calls to the parser).
526 Perl_lex_start(pTHX_ SV *line)
531 SAVEI32(PL_lex_dojoin);
532 SAVEI32(PL_lex_brackets);
533 SAVEI32(PL_lex_casemods);
534 SAVEI32(PL_lex_starts);
535 SAVEI32(PL_lex_state);
536 SAVEVPTR(PL_lex_inpat);
537 SAVEI32(PL_lex_inwhat);
538 if (PL_lex_state == LEX_KNOWNEXT) {
539 I32 toke = PL_nexttoke;
540 while (--toke >= 0) {
541 SAVEI32(PL_nexttype[toke]);
542 SAVEVPTR(PL_nextval[toke]);
544 SAVEI32(PL_nexttoke);
546 SAVECOPLINE(PL_curcop);
549 SAVEPPTR(PL_oldbufptr);
550 SAVEPPTR(PL_oldoldbufptr);
551 SAVEPPTR(PL_last_lop);
552 SAVEPPTR(PL_last_uni);
553 SAVEPPTR(PL_linestart);
554 SAVESPTR(PL_linestr);
555 SAVEGENERICPV(PL_lex_brackstack);
556 SAVEGENERICPV(PL_lex_casestack);
557 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
558 SAVESPTR(PL_lex_stuff);
559 SAVEI32(PL_lex_defer);
560 SAVEI32(PL_sublex_info.sub_inwhat);
561 SAVESPTR(PL_lex_repl);
563 SAVEINT(PL_lex_expect);
565 PL_lex_state = LEX_NORMAL;
569 New(899, PL_lex_brackstack, 120, char);
570 New(899, PL_lex_casestack, 12, char);
572 *PL_lex_casestack = '\0';
575 PL_lex_stuff = Nullsv;
576 PL_lex_repl = Nullsv;
580 PL_sublex_info.sub_inwhat = 0;
582 if (SvREADONLY(PL_linestr))
583 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
584 s = SvPV(PL_linestr, len);
585 if (!len || s[len-1] != ';') {
586 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
587 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
588 sv_catpvn(PL_linestr, "\n;", 2);
590 SvTEMP_off(PL_linestr);
591 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
592 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
593 PL_last_lop = PL_last_uni = Nullch;
599 * Finalizer for lexing operations. Must be called when the parser is
600 * done with the lexer.
606 PL_doextract = FALSE;
611 * This subroutine has nothing to do with tilting, whether at windmills
612 * or pinball tables. Its name is short for "increment line". It
613 * increments the current line number in CopLINE(PL_curcop) and checks
614 * to see whether the line starts with a comment of the form
615 * # line 500 "foo.pm"
616 * If so, it sets the current line number and file to the values in the comment.
620 S_incline(pTHX_ char *s)
627 CopLINE_inc(PL_curcop);
630 while (SPACE_OR_TAB(*s)) s++;
631 if (strnEQ(s, "line", 4))
635 if (SPACE_OR_TAB(*s))
639 while (SPACE_OR_TAB(*s)) s++;
645 while (SPACE_OR_TAB(*s))
647 if (*s == '"' && (t = strchr(s+1, '"'))) {
652 for (t = s; !isSPACE(*t); t++) ;
655 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
657 if (*e != '\n' && *e != '\0')
658 return; /* false alarm */
663 CopFILE_free(PL_curcop);
664 CopFILE_set(PL_curcop, s);
667 CopLINE_set(PL_curcop, atoi(n)-1);
672 * Called to gobble the appropriate amount and type of whitespace.
673 * Skips comments as well.
677 S_skipspace(pTHX_ register char *s)
679 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
680 while (s < PL_bufend && SPACE_OR_TAB(*s))
686 SSize_t oldprevlen, oldoldprevlen;
687 SSize_t oldloplen = 0, oldunilen = 0;
688 while (s < PL_bufend && isSPACE(*s)) {
689 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
694 if (s < PL_bufend && *s == '#') {
695 while (s < PL_bufend && *s != '\n')
699 if (PL_in_eval && !PL_rsfp) {
706 /* only continue to recharge the buffer if we're at the end
707 * of the buffer, we're not reading from a source filter, and
708 * we're in normal lexing mode
710 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
711 PL_lex_state == LEX_FORMLINE)
714 /* try to recharge the buffer */
715 if ((s = filter_gets(PL_linestr, PL_rsfp,
716 (prevlen = SvCUR(PL_linestr)))) == Nullch)
718 /* end of file. Add on the -p or -n magic */
721 ";}continue{print or die qq(-p destination: $!\\n);}");
722 PL_minus_n = PL_minus_p = 0;
724 else if (PL_minus_n) {
725 sv_setpvn(PL_linestr, ";}", 2);
729 sv_setpvn(PL_linestr,";", 1);
731 /* reset variables for next time we lex */
732 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
734 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
735 PL_last_lop = PL_last_uni = Nullch;
737 /* Close the filehandle. Could be from -P preprocessor,
738 * STDIN, or a regular file. If we were reading code from
739 * STDIN (because the commandline held no -e or filename)
740 * then we don't close it, we reset it so the code can
741 * read from STDIN too.
744 if (PL_preprocess && !PL_in_eval)
745 (void)PerlProc_pclose(PL_rsfp);
746 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
747 PerlIO_clearerr(PL_rsfp);
749 (void)PerlIO_close(PL_rsfp);
754 /* not at end of file, so we only read another line */
755 /* make corresponding updates to old pointers, for yyerror() */
756 oldprevlen = PL_oldbufptr - PL_bufend;
757 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
759 oldunilen = PL_last_uni - PL_bufend;
761 oldloplen = PL_last_lop - PL_bufend;
762 PL_linestart = PL_bufptr = s + prevlen;
763 PL_bufend = s + SvCUR(PL_linestr);
765 PL_oldbufptr = s + oldprevlen;
766 PL_oldoldbufptr = s + oldoldprevlen;
768 PL_last_uni = s + oldunilen;
770 PL_last_lop = s + oldloplen;
773 /* debugger active and we're not compiling the debugger code,
774 * so store the line into the debugger's array of lines
776 if (PERLDB_LINE && PL_curstash != PL_debstash) {
777 SV *sv = NEWSV(85,0);
779 sv_upgrade(sv, SVt_PVMG);
780 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
783 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
790 * Check the unary operators to ensure there's no ambiguity in how they're
791 * used. An ambiguous piece of code would be:
793 * This doesn't mean rand() + 5. Because rand() is a unary operator,
794 * the +5 is its argument.
803 if (PL_oldoldbufptr != PL_last_uni)
805 while (isSPACE(*PL_last_uni))
807 for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
808 if ((t = strchr(s, '(')) && t < PL_bufptr)
810 if (ckWARN_d(WARN_AMBIGUOUS)){
813 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
814 "Warning: Use of \"%s\" without parentheses is ambiguous",
821 * LOP : macro to build a list operator. Its behaviour has been replaced
822 * with a subroutine, S_lop() for which LOP is just another name.
825 #define LOP(f,x) return lop(f,x,s)
829 * Build a list operator (or something that might be one). The rules:
830 * - if we have a next token, then it's a list operator [why?]
831 * - if the next thing is an opening paren, then it's a function
832 * - else it's a list operator
836 S_lop(pTHX_ I32 f, int x, char *s)
842 PL_last_lop = PL_oldbufptr;
843 PL_last_lop_op = (OPCODE)f;
845 return REPORT(LSTOP);
852 return REPORT(LSTOP);
857 * When the lexer realizes it knows the next token (for instance,
858 * it is reordering tokens for the parser) then it can call S_force_next
859 * to know what token to return the next time the lexer is called. Caller
860 * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer
861 * handles the token correctly.
865 S_force_next(pTHX_ I32 type)
867 PL_nexttype[PL_nexttoke] = type;
869 if (PL_lex_state != LEX_KNOWNEXT) {
870 PL_lex_defer = PL_lex_state;
871 PL_lex_expect = PL_expect;
872 PL_lex_state = LEX_KNOWNEXT;
877 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
879 SV *sv = newSVpvn(start,len);
880 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
887 * When the lexer knows the next thing is a word (for instance, it has
888 * just seen -> and it knows that the next char is a word char, then
889 * it calls S_force_word to stick the next word into the PL_next lookahead.
892 * char *start : buffer position (must be within PL_linestr)
893 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
894 * int check_keyword : if true, Perl checks to make sure the word isn't
895 * a keyword (do this if the word is a label, e.g. goto FOO)
896 * int allow_pack : if true, : characters will also be allowed (require,
898 * int allow_initial_tick : used by the "sub" lexer only.
902 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
907 start = skipspace(start);
909 if (isIDFIRST_lazy_if(s,UTF) ||
910 (allow_pack && *s == ':') ||
911 (allow_initial_tick && *s == '\'') )
913 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
914 if (check_keyword && keyword(PL_tokenbuf, len))
916 if (token == METHOD) {
921 PL_expect = XOPERATOR;
924 PL_nextval[PL_nexttoke].opval
925 = (OP*)newSVOP(OP_CONST,0,
926 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
927 PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
935 * Called when the lexer wants $foo *foo &foo etc, but the program
936 * text only contains the "foo" portion. The first argument is a pointer
937 * to the "foo", and the second argument is the type symbol to prefix.
938 * Forces the next token to be a "WORD".
939 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
943 S_force_ident(pTHX_ register const char *s, int kind)
946 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
947 PL_nextval[PL_nexttoke].opval = o;
950 o->op_private = OPpCONST_ENTERED;
951 /* XXX see note in pp_entereval() for why we forgo typo
952 warnings if the symbol must be introduced in an eval.
954 gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
955 kind == '$' ? SVt_PV :
956 kind == '@' ? SVt_PVAV :
957 kind == '%' ? SVt_PVHV :
965 Perl_str_to_version(pTHX_ SV *sv)
970 char *start = SvPVx(sv,len);
971 bool utf = SvUTF8(sv) ? TRUE : FALSE;
972 char *end = start + len;
973 while (start < end) {
977 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
982 retval += ((NV)n)/nshift;
991 * Forces the next token to be a version number.
992 * If the next token appears to be an invalid version number, (e.g. "v2b"),
993 * and if "guessing" is TRUE, then no new token is created (and the caller
994 * must use an alternative parsing method).
998 S_force_version(pTHX_ char *s, int guessing)
1000 OP *version = Nullop;
1009 while (isDIGIT(*d) || *d == '_' || *d == '.')
1011 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1013 s = scan_num(s, &yylval);
1014 version = yylval.opval;
1015 ver = cSVOPx(version)->op_sv;
1016 if (SvPOK(ver) && !SvNIOK(ver)) {
1017 (void)SvUPGRADE(ver, SVt_PVNV);
1018 SvNV_set(ver, str_to_version(ver));
1019 SvNOK_on(ver); /* hint that it is a version */
1026 /* NOTE: The parser sees the package name and the VERSION swapped */
1027 PL_nextval[PL_nexttoke].opval = version;
1035 * Tokenize a quoted string passed in as an SV. It finds the next
1036 * chunk, up to end of string or a backslash. It may make a new
1037 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1042 S_tokeq(pTHX_ SV *sv)
1045 register char *send;
1053 s = SvPV_force(sv, len);
1054 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1057 while (s < send && *s != '\\')
1062 if ( PL_hints & HINT_NEW_STRING ) {
1063 pv = sv_2mortal(newSVpvn(SvPVX(pv), len));
1069 if (s + 1 < send && (s[1] == '\\'))
1070 s++; /* all that, just for this */
1075 SvCUR_set(sv, d - SvPVX(sv));
1077 if ( PL_hints & HINT_NEW_STRING )
1078 return new_constant(NULL, 0, "q", sv, pv, "q");
1083 * Now come three functions related to double-quote context,
1084 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1085 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1086 * interact with PL_lex_state, and create fake ( ... ) argument lists
1087 * to handle functions and concatenation.
1088 * They assume that whoever calls them will be setting up a fake
1089 * join call, because each subthing puts a ',' after it. This lets
1092 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1094 * (I'm not sure whether the spurious commas at the end of lcfirst's
1095 * arguments and join's arguments are created or not).
1100 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1102 * Pattern matching will set PL_lex_op to the pattern-matching op to
1103 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1105 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1107 * Everything else becomes a FUNC.
1109 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1110 * had an OP_CONST or OP_READLINE). This just sets us up for a
1111 * call to S_sublex_push().
1115 S_sublex_start(pTHX)
1117 register I32 op_type = yylval.ival;
1119 if (op_type == OP_NULL) {
1120 yylval.opval = PL_lex_op;
1124 if (op_type == OP_CONST || op_type == OP_READLINE) {
1125 SV *sv = tokeq(PL_lex_stuff);
1127 if (SvTYPE(sv) == SVt_PVIV) {
1128 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1134 nsv = newSVpvn(p, len);
1140 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1141 PL_lex_stuff = Nullsv;
1142 /* Allow <FH> // "foo" */
1143 if (op_type == OP_READLINE)
1144 PL_expect = XTERMORDORDOR;
1148 PL_sublex_info.super_state = PL_lex_state;
1149 PL_sublex_info.sub_inwhat = op_type;
1150 PL_sublex_info.sub_op = PL_lex_op;
1151 PL_lex_state = LEX_INTERPPUSH;
1155 yylval.opval = PL_lex_op;
1165 * Create a new scope to save the lexing state. The scope will be
1166 * ended in S_sublex_done. Returns a '(', starting the function arguments
1167 * to the uc, lc, etc. found before.
1168 * Sets PL_lex_state to LEX_INTERPCONCAT.
1177 PL_lex_state = PL_sublex_info.super_state;
1178 SAVEI32(PL_lex_dojoin);
1179 SAVEI32(PL_lex_brackets);
1180 SAVEI32(PL_lex_casemods);
1181 SAVEI32(PL_lex_starts);
1182 SAVEI32(PL_lex_state);
1183 SAVEVPTR(PL_lex_inpat);
1184 SAVEI32(PL_lex_inwhat);
1185 SAVECOPLINE(PL_curcop);
1186 SAVEPPTR(PL_bufptr);
1187 SAVEPPTR(PL_bufend);
1188 SAVEPPTR(PL_oldbufptr);
1189 SAVEPPTR(PL_oldoldbufptr);
1190 SAVEPPTR(PL_last_lop);
1191 SAVEPPTR(PL_last_uni);
1192 SAVEPPTR(PL_linestart);
1193 SAVESPTR(PL_linestr);
1194 SAVEGENERICPV(PL_lex_brackstack);
1195 SAVEGENERICPV(PL_lex_casestack);
1197 PL_linestr = PL_lex_stuff;
1198 PL_lex_stuff = Nullsv;
1200 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1201 = SvPVX(PL_linestr);
1202 PL_bufend += SvCUR(PL_linestr);
1203 PL_last_lop = PL_last_uni = Nullch;
1204 SAVEFREESV(PL_linestr);
1206 PL_lex_dojoin = FALSE;
1207 PL_lex_brackets = 0;
1208 New(899, PL_lex_brackstack, 120, char);
1209 New(899, PL_lex_casestack, 12, char);
1210 PL_lex_casemods = 0;
1211 *PL_lex_casestack = '\0';
1213 PL_lex_state = LEX_INTERPCONCAT;
1214 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1216 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1217 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1218 PL_lex_inpat = PL_sublex_info.sub_op;
1220 PL_lex_inpat = Nullop;
1227 * Restores lexer state after a S_sublex_push.
1234 if (!PL_lex_starts++) {
1235 SV *sv = newSVpvn("",0);
1236 if (SvUTF8(PL_linestr))
1238 PL_expect = XOPERATOR;
1239 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1243 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1244 PL_lex_state = LEX_INTERPCASEMOD;
1248 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1249 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1250 PL_linestr = PL_lex_repl;
1252 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1253 PL_bufend += SvCUR(PL_linestr);
1254 PL_last_lop = PL_last_uni = Nullch;
1255 SAVEFREESV(PL_linestr);
1256 PL_lex_dojoin = FALSE;
1257 PL_lex_brackets = 0;
1258 PL_lex_casemods = 0;
1259 *PL_lex_casestack = '\0';
1261 if (SvEVALED(PL_lex_repl)) {
1262 PL_lex_state = LEX_INTERPNORMAL;
1264 /* we don't clear PL_lex_repl here, so that we can check later
1265 whether this is an evalled subst; that means we rely on the
1266 logic to ensure sublex_done() is called again only via the
1267 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1270 PL_lex_state = LEX_INTERPCONCAT;
1271 PL_lex_repl = Nullsv;
1277 PL_bufend = SvPVX(PL_linestr);
1278 PL_bufend += SvCUR(PL_linestr);
1279 PL_expect = XOPERATOR;
1280 PL_sublex_info.sub_inwhat = 0;
1288 Extracts a pattern, double-quoted string, or transliteration. This
1291 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1292 processing a pattern (PL_lex_inpat is true), a transliteration
1293 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1295 Returns a pointer to the character scanned up to. Iff this is
1296 advanced from the start pointer supplied (ie if anything was
1297 successfully parsed), will leave an OP for the substring scanned
1298 in yylval. Caller must intuit reason for not parsing further
1299 by looking at the next characters herself.
1303 double-quoted style: \r and \n
1304 regexp special ones: \D \s
1306 backrefs: \1 (deprecated in substitution replacements)
1307 case and quoting: \U \Q \E
1308 stops on @ and $, but not for $ as tail anchor
1310 In transliterations:
1311 characters are VERY literal, except for - not at the start or end
1312 of the string, which indicates a range. scan_const expands the
1313 range to the full set of intermediate characters.
1315 In double-quoted strings:
1317 double-quoted style: \r and \n
1319 backrefs: \1 (deprecated)
1320 case and quoting: \U \Q \E
1323 scan_const does *not* construct ops to handle interpolated strings.
1324 It stops processing as soon as it finds an embedded $ or @ variable
1325 and leaves it to the caller to work out what's going on.
1327 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo.
1329 $ in pattern could be $foo or could be tail anchor. Assumption:
1330 it's a tail anchor if $ is the last thing in the string, or if it's
1331 followed by one of ")| \n\t"
1333 \1 (backreferences) are turned into $1
1335 The structure of the code is
1336 while (there's a character to process) {
1337 handle transliteration ranges
1338 skip regexp comments
1339 skip # initiated comments in //x patterns
1340 check for embedded @foo
1341 check for embedded scalars
1343 leave intact backslashes from leave (below)
1344 deprecate \1 in strings and sub replacements
1345 handle string-changing backslashes \l \U \Q \E, etc.
1346 switch (what was escaped) {
1347 handle - in a transliteration (becomes a literal -)
1348 handle \132 octal characters
1349 handle 0x15 hex characters
1350 handle \cV (control V)
1351 handle printf backslashes (\f, \r, \n, etc)
1353 } (end if backslash)
1354 } (end while character to read)
1359 S_scan_const(pTHX_ char *start)
1361 register char *send = PL_bufend; /* end of the constant */
1362 SV *sv = NEWSV(93, send - start); /* sv for the constant */
1363 register char *s = start; /* start of the constant */
1364 register char *d = SvPVX(sv); /* destination for copies */
1365 bool dorange = FALSE; /* are we in a translit range? */
1366 bool didrange = FALSE; /* did we just finish a range? */
1367 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1368 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1371 const char *leaveit = /* set of acceptably-backslashed characters */
1373 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#"
1376 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1377 /* If we are doing a trans and we know we want UTF8 set expectation */
1378 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1379 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1383 while (s < send || dorange) {
1384 /* get transliterations out of the way (they're most literal) */
1385 if (PL_lex_inwhat == OP_TRANS) {
1386 /* expand a range A-Z to the full set of characters. AIE! */
1388 I32 i; /* current expanded character */
1389 I32 min; /* first character in range */
1390 I32 max; /* last character in range */
1393 char *c = (char*)utf8_hop((U8*)d, -1);
1397 *c = (char)UTF_TO_NATIVE(0xff);
1398 /* mark the range as done, and continue */
1404 i = d - SvPVX(sv); /* remember current offset */
1405 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1406 d = SvPVX(sv) + i; /* refresh d after realloc */
1407 d -= 2; /* eat the first char and the - */
1409 min = (U8)*d; /* first char in range */
1410 max = (U8)d[1]; /* last char in range */
1414 "Invalid range \"%c-%c\" in transliteration operator",
1415 (char)min, (char)max);
1419 if ((isLOWER(min) && isLOWER(max)) ||
1420 (isUPPER(min) && isUPPER(max))) {
1422 for (i = min; i <= max; i++)
1424 *d++ = NATIVE_TO_NEED(has_utf8,i);
1426 for (i = min; i <= max; i++)
1428 *d++ = NATIVE_TO_NEED(has_utf8,i);
1433 for (i = min; i <= max; i++)
1436 /* mark the range as done, and continue */
1442 /* range begins (ignore - as first or last char) */
1443 else if (*s == '-' && s+1 < send && s != start) {
1445 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1448 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1460 /* if we get here, we're not doing a transliteration */
1462 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1463 except for the last char, which will be done separately. */
1464 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1466 while (s+1 < send && *s != ')')
1467 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1469 else if (s[2] == '{' /* This should match regcomp.c */
1470 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1473 char *regparse = s + (s[2] == '{' ? 3 : 4);
1476 while (count && (c = *regparse)) {
1477 if (c == '\\' && regparse[1])
1485 if (*regparse != ')')
1486 regparse--; /* Leave one char for continuation. */
1487 while (s < regparse)
1488 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1492 /* likewise skip #-initiated comments in //x patterns */
1493 else if (*s == '#' && PL_lex_inpat &&
1494 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1495 while (s+1 < send && *s != '\n')
1496 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1499 /* check for embedded arrays
1500 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1502 else if (*s == '@' && s[1]
1503 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1506 /* check for embedded scalars. only stop if we're sure it's a
1509 else if (*s == '$') {
1510 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1512 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1513 break; /* in regexp, $ might be tail anchor */
1516 /* End of else if chain - OP_TRANS rejoin rest */
1519 if (*s == '\\' && s+1 < send) {
1522 /* some backslashes we leave behind */
1523 if (*leaveit && *s && strchr(leaveit, *s)) {
1524 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1525 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1529 /* deprecate \1 in strings and substitution replacements */
1530 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1531 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1533 if (ckWARN(WARN_SYNTAX))
1534 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
1539 /* string-change backslash escapes */
1540 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1545 /* if we get here, it's either a quoted -, or a digit */
1548 /* quoted - in transliterations */
1550 if (PL_lex_inwhat == OP_TRANS) {
1557 if (ckWARN(WARN_MISC) &&
1560 Perl_warner(aTHX_ packWARN(WARN_MISC),
1561 "Unrecognized escape \\%c passed through",
1563 /* default action is to copy the quoted character */
1564 goto default_action;
1567 /* \132 indicates an octal constant */
1568 case '0': case '1': case '2': case '3':
1569 case '4': case '5': case '6': case '7':
1573 uv = grok_oct(s, &len, &flags, NULL);
1576 goto NUM_ESCAPE_INSERT;
1578 /* \x24 indicates a hex constant */
1582 char* e = strchr(s, '}');
1583 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1584 PERL_SCAN_DISALLOW_PREFIX;
1589 yyerror("Missing right brace on \\x{}");
1593 uv = grok_hex(s, &len, &flags, NULL);
1599 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
1600 uv = grok_hex(s, &len, &flags, NULL);
1606 /* Insert oct or hex escaped character.
1607 * There will always enough room in sv since such
1608 * escapes will be longer than any UTF-8 sequence
1609 * they can end up as. */
1611 /* We need to map to chars to ASCII before doing the tests
1614 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
1615 if (!has_utf8 && uv > 255) {
1616 /* Might need to recode whatever we have
1617 * accumulated so far if it contains any
1620 * (Can't we keep track of that and avoid
1621 * this rescan? --jhi)
1625 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
1626 if (!NATIVE_IS_INVARIANT(*c)) {
1631 STRLEN offset = d - SvPVX(sv);
1633 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
1637 while (src >= (U8 *)SvPVX(sv)) {
1638 if (!NATIVE_IS_INVARIANT(*src)) {
1639 U8 ch = NATIVE_TO_ASCII(*src);
1640 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
1641 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
1651 if (has_utf8 || uv > 255) {
1652 d = (char*)uvchr_to_utf8((U8*)d, uv);
1654 if (PL_lex_inwhat == OP_TRANS &&
1655 PL_sublex_info.sub_op) {
1656 PL_sublex_info.sub_op->op_private |=
1657 (PL_lex_repl ? OPpTRANS_FROM_UTF
1670 /* \N{LATIN SMALL LETTER A} is a named character */
1674 char* e = strchr(s, '}');
1680 yyerror("Missing right brace on \\N{}");
1684 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
1686 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1687 PERL_SCAN_DISALLOW_PREFIX;
1690 uv = grok_hex(s, &len, &flags, NULL);
1692 goto NUM_ESCAPE_INSERT;
1694 res = newSVpvn(s + 1, e - s - 1);
1695 res = new_constant( Nullch, 0, "charnames",
1696 res, Nullsv, "\\N{...}" );
1698 sv_utf8_upgrade(res);
1699 str = SvPV(res,len);
1700 #ifdef EBCDIC_NEVER_MIND
1701 /* charnames uses pack U and that has been
1702 * recently changed to do the below uni->native
1703 * mapping, so this would be redundant (and wrong,
1704 * the code point would be doubly converted).
1705 * But leave this in just in case the pack U change
1706 * gets revoked, but the semantics is still
1707 * desireable for charnames. --jhi */
1709 UV uv = utf8_to_uvchr((U8*)str, 0);
1712 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
1714 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
1715 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
1716 str = SvPV(res, len);
1720 if (!has_utf8 && SvUTF8(res)) {
1721 char *ostart = SvPVX(sv);
1722 SvCUR_set(sv, d - ostart);
1725 sv_utf8_upgrade(sv);
1726 /* this just broke our allocation above... */
1727 SvGROW(sv, (STRLEN)(send - start));
1728 d = SvPVX(sv) + SvCUR(sv);
1731 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
1732 char *odest = SvPVX(sv);
1734 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
1735 d = SvPVX(sv) + (d - odest);
1737 Copy(str, d, len, char);
1744 yyerror("Missing braces on \\N{}");
1747 /* \c is a control character */
1756 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
1759 yyerror("Missing control char name in \\c");
1763 /* printf-style backslashes, formfeeds, newlines, etc */
1765 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
1768 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
1771 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
1774 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
1777 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
1780 *d++ = ASCII_TO_NEED(has_utf8,'\033');
1783 *d++ = ASCII_TO_NEED(has_utf8,'\007');
1789 } /* end if (backslash) */
1792 /* If we started with encoded form, or already know we want it
1793 and then encode the next character */
1794 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
1796 UV uv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
1797 STRLEN need = UNISKIP(NATIVE_TO_UNI(uv));
1800 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
1801 STRLEN off = d - SvPVX(sv);
1802 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
1804 d = (char*)uvchr_to_utf8((U8*)d, uv);
1808 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1810 } /* while loop to process each character */
1812 /* terminate the string and set up the sv */
1814 SvCUR_set(sv, d - SvPVX(sv));
1815 if (SvCUR(sv) >= SvLEN(sv))
1816 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
1819 if (PL_encoding && !has_utf8) {
1820 sv_recode_to_utf8(sv, PL_encoding);
1826 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1827 PL_sublex_info.sub_op->op_private |=
1828 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1832 /* shrink the sv if we allocated more than we used */
1833 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1834 SvPV_shrink_to_cur(sv);
1837 /* return the substring (via yylval) only if we parsed anything */
1838 if (s > PL_bufptr) {
1839 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1840 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1842 ( PL_lex_inwhat == OP_TRANS
1844 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1847 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1854 * Returns TRUE if there's more to the expression (e.g., a subscript),
1857 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
1859 * ->[ and ->{ return TRUE
1860 * { and [ outside a pattern are always subscripts, so return TRUE
1861 * if we're outside a pattern and it's not { or [, then return FALSE
1862 * if we're in a pattern and the first char is a {
1863 * {4,5} (any digits around the comma) returns FALSE
1864 * if we're in a pattern and the first char is a [
1866 * [SOMETHING] has a funky algorithm to decide whether it's a
1867 * character class or not. It has to deal with things like
1868 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
1869 * anything else returns TRUE
1872 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1875 S_intuit_more(pTHX_ register char *s)
1877 if (PL_lex_brackets)
1879 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1881 if (*s != '{' && *s != '[')
1886 /* In a pattern, so maybe we have {n,m}. */
1903 /* On the other hand, maybe we have a character class */
1906 if (*s == ']' || *s == '^')
1909 /* this is terrifying, and it works */
1910 int weight = 2; /* let's weigh the evidence */
1912 unsigned char un_char = 255, last_un_char;
1913 char *send = strchr(s,']');
1914 char tmpbuf[sizeof PL_tokenbuf * 4];
1916 if (!send) /* has to be an expression */
1919 Zero(seen,256,char);
1922 else if (isDIGIT(*s)) {
1924 if (isDIGIT(s[1]) && s[2] == ']')
1930 for (; s < send; s++) {
1931 last_un_char = un_char;
1932 un_char = (unsigned char)*s;
1937 weight -= seen[un_char] * 10;
1938 if (isALNUM_lazy_if(s+1,UTF)) {
1939 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
1940 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
1945 else if (*s == '$' && s[1] &&
1946 strchr("[#!%*<>()-=",s[1])) {
1947 if (/*{*/ strchr("])} =",s[2]))
1956 if (strchr("wds]",s[1]))
1958 else if (seen['\''] || seen['"'])
1960 else if (strchr("rnftbxcav",s[1]))
1962 else if (isDIGIT(s[1])) {
1964 while (s[1] && isDIGIT(s[1]))
1974 if (strchr("aA01! ",last_un_char))
1976 if (strchr("zZ79~",s[1]))
1978 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
1979 weight -= 5; /* cope with negative subscript */
1982 if (!isALNUM(last_un_char)
1983 && !(last_un_char == '$' || last_un_char == '@'
1984 || last_un_char == '&')
1985 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
1990 if (keyword(tmpbuf, d - tmpbuf))
1993 if (un_char == last_un_char + 1)
1995 weight -= seen[un_char];
2000 if (weight >= 0) /* probably a character class */
2010 * Does all the checking to disambiguate
2012 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2013 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2015 * First argument is the stuff after the first token, e.g. "bar".
2017 * Not a method if bar is a filehandle.
2018 * Not a method if foo is a subroutine prototyped to take a filehandle.
2019 * Not a method if it's really "Foo $bar"
2020 * Method if it's "foo $bar"
2021 * Not a method if it's really "print foo $bar"
2022 * Method if it's really "foo package::" (interpreted as package->foo)
2023 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2024 * Not a method if bar is a filehandle or package, but is quoted with
2029 S_intuit_method(pTHX_ char *start, GV *gv)
2031 char *s = start + (*start == '$');
2032 char tmpbuf[sizeof PL_tokenbuf];
2040 if ((cv = GvCVu(gv))) {
2041 char *proto = SvPVX(cv);
2051 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2052 /* start is the beginning of the possible filehandle/object,
2053 * and s is the end of it
2054 * tmpbuf is a copy of it
2057 if (*start == '$') {
2058 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2063 return *s == '(' ? FUNCMETH : METHOD;
2065 if (!keyword(tmpbuf, len)) {
2066 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2071 indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2072 if (indirgv && GvCVu(indirgv))
2074 /* filehandle or package name makes it a method */
2075 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2077 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2078 return 0; /* no assumptions -- "=>" quotes bearword */
2080 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
2081 newSVpvn(tmpbuf,len));
2082 PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
2086 return *s == '(' ? FUNCMETH : METHOD;
2094 * Return a string of Perl code to load the debugger. If PERL5DB
2095 * is set, it will return the contents of that, otherwise a
2096 * compile-time require of perl5db.pl.
2103 const char *pdb = PerlEnv_getenv("PERL5DB");
2107 SETERRNO(0,SS_NORMAL);
2108 return "BEGIN { require 'perl5db.pl' }";
2114 /* Encoded script support. filter_add() effectively inserts a
2115 * 'pre-processing' function into the current source input stream.
2116 * Note that the filter function only applies to the current source file
2117 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2119 * The datasv parameter (which may be NULL) can be used to pass
2120 * private data to this instance of the filter. The filter function
2121 * can recover the SV using the FILTER_DATA macro and use it to
2122 * store private buffers and state information.
2124 * The supplied datasv parameter is upgraded to a PVIO type
2125 * and the IoDIRP/IoANY field is used to store the function pointer,
2126 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2127 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2128 * private use must be set using malloc'd pointers.
2132 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2137 if (!PL_rsfp_filters)
2138 PL_rsfp_filters = newAV();
2140 datasv = NEWSV(255,0);
2141 if (!SvUPGRADE(datasv, SVt_PVIO))
2142 Perl_die(aTHX_ "Can't upgrade filter_add data to SVt_PVIO");
2143 IoANY(datasv) = (void *)funcp; /* stash funcp into spare field */
2144 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2145 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2146 (void*)funcp, SvPV_nolen(datasv)));
2147 av_unshift(PL_rsfp_filters, 1);
2148 av_store(PL_rsfp_filters, 0, datasv) ;
2153 /* Delete most recently added instance of this filter function. */
2155 Perl_filter_del(pTHX_ filter_t funcp)
2158 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", (void*)funcp));
2159 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2161 /* if filter is on top of stack (usual case) just pop it off */
2162 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2163 if (IoANY(datasv) == (void *)funcp) {
2164 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2165 IoANY(datasv) = (void *)NULL;
2166 sv_free(av_pop(PL_rsfp_filters));
2170 /* we need to search for the correct entry and clear it */
2171 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2175 /* Invoke the idxth filter function for the current rsfp. */
2176 /* maxlen 0 = read one text line */
2178 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2183 if (!PL_rsfp_filters)
2185 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2186 /* Provide a default input filter to make life easy. */
2187 /* Note that we append to the line. This is handy. */
2188 DEBUG_P(PerlIO_printf(Perl_debug_log,
2189 "filter_read %d: from rsfp\n", idx));
2193 int old_len = SvCUR(buf_sv) ;
2195 /* ensure buf_sv is large enough */
2196 SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ;
2197 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
2198 if (PerlIO_error(PL_rsfp))
2199 return -1; /* error */
2201 return 0 ; /* end of file */
2203 SvCUR_set(buf_sv, old_len + len) ;
2206 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2207 if (PerlIO_error(PL_rsfp))
2208 return -1; /* error */
2210 return 0 ; /* end of file */
2213 return SvCUR(buf_sv);
2215 /* Skip this filter slot if filter has been deleted */
2216 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2217 DEBUG_P(PerlIO_printf(Perl_debug_log,
2218 "filter_read %d: skipped (filter deleted)\n",
2220 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
2222 /* Get function pointer hidden within datasv */
2223 funcp = (filter_t)IoANY(datasv);
2224 DEBUG_P(PerlIO_printf(Perl_debug_log,
2225 "filter_read %d: via function %p (%s)\n",
2226 idx, (void*)funcp, SvPV_nolen(datasv)));
2227 /* Call function. The function is expected to */
2228 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2229 /* Return: <0:error, =0:eof, >0:not eof */
2230 return (*funcp)(aTHX_ idx, buf_sv, maxlen);
2234 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2236 #ifdef PERL_CR_FILTER
2237 if (!PL_rsfp_filters) {
2238 filter_add(S_cr_textfilter,NULL);
2241 if (PL_rsfp_filters) {
2243 SvCUR_set(sv, 0); /* start with empty line */
2244 if (FILTER_READ(0, sv, 0) > 0)
2245 return ( SvPVX(sv) ) ;
2250 return (sv_gets(sv, fp, append));
2254 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2258 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2262 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2263 (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV)))
2265 return GvHV(gv); /* Foo:: */
2268 /* use constant CLASS => 'MyClass' */
2269 if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) {
2271 if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2272 pkgname = SvPV_nolen(sv);
2276 return gv_stashpv(pkgname, FALSE);
2280 static const char* const exp_name[] =
2281 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2282 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
2289 Works out what to call the token just pulled out of the input
2290 stream. The yacc parser takes care of taking the ops we return and
2291 stitching them into a tree.
2297 if read an identifier
2298 if we're in a my declaration
2299 croak if they tried to say my($foo::bar)
2300 build the ops for a my() declaration
2301 if it's an access to a my() variable
2302 are we in a sort block?
2303 croak if my($a); $a <=> $b
2304 build ops for access to a my() variable
2305 if in a dq string, and they've said @foo and we can't find @foo
2307 build ops for a bareword
2308 if we already built the token before, use it.
2313 #pragma segment Perl_yylex
2318 register char *s = PL_bufptr;
2325 I32 orig_keyword = 0;
2328 PerlIO_printf(Perl_debug_log, "### LEX_%s\n",
2329 lex_state_names[PL_lex_state]);
2331 /* check if there's an identifier for us to look at */
2332 if (PL_pending_ident)
2333 return REPORT(S_pending_ident(aTHX));
2335 /* no identifier pending identification */
2337 switch (PL_lex_state) {
2339 case LEX_NORMAL: /* Some compilers will produce faster */
2340 case LEX_INTERPNORMAL: /* code if we comment these out. */
2344 /* when we've already built the next token, just pull it out of the queue */
2347 yylval = PL_nextval[PL_nexttoke];
2349 PL_lex_state = PL_lex_defer;
2350 PL_expect = PL_lex_expect;
2351 PL_lex_defer = LEX_NORMAL;
2353 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2354 "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr,
2355 (IV)PL_nexttype[PL_nexttoke]); });
2357 return REPORT(PL_nexttype[PL_nexttoke]);
2359 /* interpolated case modifiers like \L \U, including \Q and \E.
2360 when we get here, PL_bufptr is at the \
2362 case LEX_INTERPCASEMOD:
2364 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2365 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2367 /* handle \E or end of string */
2368 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2372 if (PL_lex_casemods) {
2373 oldmod = PL_lex_casestack[--PL_lex_casemods];
2374 PL_lex_casestack[PL_lex_casemods] = '\0';
2376 if (PL_bufptr != PL_bufend
2377 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
2379 PL_lex_state = LEX_INTERPCONCAT;
2383 if (PL_bufptr != PL_bufend)
2385 PL_lex_state = LEX_INTERPCONCAT;
2389 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2390 "### Saw case modifier at '%s'\n", PL_bufptr); });
2392 if (s[1] == '\\' && s[2] == 'E') {
2394 PL_lex_state = LEX_INTERPCONCAT;
2398 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2399 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
2400 if ((*s == 'L' || *s == 'U') &&
2401 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
2402 PL_lex_casestack[--PL_lex_casemods] = '\0';
2405 if (PL_lex_casemods > 10)
2406 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2407 PL_lex_casestack[PL_lex_casemods++] = *s;
2408 PL_lex_casestack[PL_lex_casemods] = '\0';
2409 PL_lex_state = LEX_INTERPCONCAT;
2410 PL_nextval[PL_nexttoke].ival = 0;
2413 PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2415 PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2417 PL_nextval[PL_nexttoke].ival = OP_LC;
2419 PL_nextval[PL_nexttoke].ival = OP_UC;
2421 PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2423 Perl_croak(aTHX_ "panic: yylex");
2427 if (PL_lex_starts) {
2430 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2431 if (PL_lex_casemods == 1 && PL_lex_inpat)
2440 case LEX_INTERPPUSH:
2441 return REPORT(sublex_push());
2443 case LEX_INTERPSTART:
2444 if (PL_bufptr == PL_bufend)
2445 return REPORT(sublex_done());
2446 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2447 "### Interpolated variable at '%s'\n", PL_bufptr); });
2449 PL_lex_dojoin = (*PL_bufptr == '@');
2450 PL_lex_state = LEX_INTERPNORMAL;
2451 if (PL_lex_dojoin) {
2452 PL_nextval[PL_nexttoke].ival = 0;
2454 force_ident("\"", '$');
2455 PL_nextval[PL_nexttoke].ival = 0;
2457 PL_nextval[PL_nexttoke].ival = 0;
2459 PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
2462 if (PL_lex_starts++) {
2464 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2465 if (!PL_lex_casemods && PL_lex_inpat)
2472 case LEX_INTERPENDMAYBE:
2473 if (intuit_more(PL_bufptr)) {
2474 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
2480 if (PL_lex_dojoin) {
2481 PL_lex_dojoin = FALSE;
2482 PL_lex_state = LEX_INTERPCONCAT;
2485 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2486 && SvEVALED(PL_lex_repl))
2488 if (PL_bufptr != PL_bufend)
2489 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2490 PL_lex_repl = Nullsv;
2493 case LEX_INTERPCONCAT:
2495 if (PL_lex_brackets)
2496 Perl_croak(aTHX_ "panic: INTERPCONCAT");
2498 if (PL_bufptr == PL_bufend)
2499 return REPORT(sublex_done());
2501 if (SvIVX(PL_linestr) == '\'') {
2502 SV *sv = newSVsv(PL_linestr);
2505 else if ( PL_hints & HINT_NEW_RE )
2506 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2507 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2511 s = scan_const(PL_bufptr);
2513 PL_lex_state = LEX_INTERPCASEMOD;
2515 PL_lex_state = LEX_INTERPSTART;
2518 if (s != PL_bufptr) {
2519 PL_nextval[PL_nexttoke] = yylval;
2522 if (PL_lex_starts++) {
2523 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2524 if (!PL_lex_casemods && PL_lex_inpat)
2537 PL_lex_state = LEX_NORMAL;
2538 s = scan_formline(PL_bufptr);
2539 if (!PL_lex_formbrack)
2545 PL_oldoldbufptr = PL_oldbufptr;
2548 PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at [%s]\n",
2549 exp_name[PL_expect], s);
2555 if (isIDFIRST_lazy_if(s,UTF))
2557 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2560 goto fake_eof; /* emulate EOF on ^D or ^Z */
2565 if (PL_lex_brackets) {
2566 if (PL_lex_formbrack)
2567 yyerror("Format not terminated");
2569 yyerror("Missing right curly or square bracket");
2571 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2572 "### Tokener got EOF\n");
2576 if (s++ < PL_bufend)
2577 goto retry; /* ignore stray nulls */
2580 if (!PL_in_eval && !PL_preambled) {
2581 PL_preambled = TRUE;
2582 sv_setpv(PL_linestr,incl_perldb());
2583 if (SvCUR(PL_linestr))
2584 sv_catpvn(PL_linestr,";", 1);
2586 while(AvFILLp(PL_preambleav) >= 0) {
2587 SV *tmpsv = av_shift(PL_preambleav);
2588 sv_catsv(PL_linestr, tmpsv);
2589 sv_catpvn(PL_linestr, ";", 1);
2592 sv_free((SV*)PL_preambleav);
2593 PL_preambleav = NULL;
2595 if (PL_minus_n || PL_minus_p) {
2596 sv_catpv(PL_linestr, "LINE: while (<>) {");
2598 sv_catpv(PL_linestr,"chomp;");
2601 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
2602 || *PL_splitstr == '"')
2603 && strchr(PL_splitstr + 1, *PL_splitstr))
2604 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
2606 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
2607 bytes can be used as quoting characters. :-) */
2608 /* The count here deliberately includes the NUL
2609 that terminates the C string constant. This
2610 embeds the opening NUL into the string. */
2611 const char *splits = PL_splitstr;
2612 sv_catpvn(PL_linestr, "our @F=split(q", 15);
2615 if (*splits == '\\')
2616 sv_catpvn(PL_linestr, splits, 1);
2617 sv_catpvn(PL_linestr, splits, 1);
2618 } while (*splits++);
2619 /* This loop will embed the trailing NUL of
2620 PL_linestr as the last thing it does before
2622 sv_catpvn(PL_linestr, ");", 2);
2626 sv_catpv(PL_linestr,"our @F=split(' ');");
2629 sv_catpvn(PL_linestr, "\n", 1);
2630 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2631 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2632 PL_last_lop = PL_last_uni = Nullch;
2633 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2634 SV *sv = NEWSV(85,0);
2636 sv_upgrade(sv, SVt_PVMG);
2637 sv_setsv(sv,PL_linestr);
2640 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2645 bof = PL_rsfp ? TRUE : FALSE;
2646 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2649 if (PL_preprocess && !PL_in_eval)
2650 (void)PerlProc_pclose(PL_rsfp);
2651 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2652 PerlIO_clearerr(PL_rsfp);
2654 (void)PerlIO_close(PL_rsfp);
2656 PL_doextract = FALSE;
2658 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2659 sv_setpv(PL_linestr,PL_minus_p
2660 ? ";}continue{print;}" : ";}");
2661 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2662 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2663 PL_last_lop = PL_last_uni = Nullch;
2664 PL_minus_n = PL_minus_p = 0;
2667 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2668 PL_last_lop = PL_last_uni = Nullch;
2669 sv_setpv(PL_linestr,"");
2670 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
2672 /* If it looks like the start of a BOM or raw UTF-16,
2673 * check if it in fact is. */
2679 #ifdef PERLIO_IS_STDIO
2680 # ifdef __GNU_LIBRARY__
2681 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
2682 # define FTELL_FOR_PIPE_IS_BROKEN
2686 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
2687 # define FTELL_FOR_PIPE_IS_BROKEN
2692 #ifdef FTELL_FOR_PIPE_IS_BROKEN
2693 /* This loses the possibility to detect the bof
2694 * situation on perl -P when the libc5 is being used.
2695 * Workaround? Maybe attach some extra state to PL_rsfp?
2698 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2700 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
2703 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2704 s = swallow_bom((U8*)s);
2708 /* Incest with pod. */
2709 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2710 sv_setpv(PL_linestr, "");
2711 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2712 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2713 PL_last_lop = PL_last_uni = Nullch;
2714 PL_doextract = FALSE;
2718 } while (PL_doextract);
2719 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2720 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2721 SV *sv = NEWSV(85,0);
2723 sv_upgrade(sv, SVt_PVMG);
2724 sv_setsv(sv,PL_linestr);
2727 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2729 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2730 PL_last_lop = PL_last_uni = Nullch;
2731 if (CopLINE(PL_curcop) == 1) {
2732 while (s < PL_bufend && isSPACE(*s))
2734 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2738 if (*s == '#' && *(s+1) == '!')
2740 #ifdef ALTERNATE_SHEBANG
2742 static char const as[] = ALTERNATE_SHEBANG;
2743 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2744 d = s + (sizeof(as) - 1);
2746 #endif /* ALTERNATE_SHEBANG */
2755 while (*d && !isSPACE(*d))
2759 #ifdef ARG_ZERO_IS_SCRIPT
2760 if (ipathend > ipath) {
2762 * HP-UX (at least) sets argv[0] to the script name,
2763 * which makes $^X incorrect. And Digital UNIX and Linux,
2764 * at least, set argv[0] to the basename of the Perl
2765 * interpreter. So, having found "#!", we'll set it right.
2767 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); /* $^X */
2768 assert(SvPOK(x) || SvGMAGICAL(x));
2769 if (sv_eq(x, CopFILESV(PL_curcop))) {
2770 sv_setpvn(x, ipath, ipathend - ipath);
2776 char *bstart = SvPV(CopFILESV(PL_curcop),blen);
2777 char *lstart = SvPV(x,llen);
2779 bstart += blen - llen;
2780 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
2781 sv_setpvn(x, ipath, ipathend - ipath);
2786 TAINT_NOT; /* $^X is always tainted, but that's OK */
2788 #endif /* ARG_ZERO_IS_SCRIPT */
2793 d = instr(s,"perl -");
2795 d = instr(s,"perl");
2797 /* avoid getting into infinite loops when shebang
2798 * line contains "Perl" rather than "perl" */
2800 for (d = ipathend-4; d >= ipath; --d) {
2801 if ((*d == 'p' || *d == 'P')
2802 && !ibcmp(d, "perl", 4))
2812 #ifdef ALTERNATE_SHEBANG
2814 * If the ALTERNATE_SHEBANG on this system starts with a
2815 * character that can be part of a Perl expression, then if
2816 * we see it but not "perl", we're probably looking at the
2817 * start of Perl code, not a request to hand off to some
2818 * other interpreter. Similarly, if "perl" is there, but
2819 * not in the first 'word' of the line, we assume the line
2820 * contains the start of the Perl program.
2822 if (d && *s != '#') {
2824 while (*c && !strchr("; \t\r\n\f\v#", *c))
2827 d = Nullch; /* "perl" not in first word; ignore */
2829 *s = '#'; /* Don't try to parse shebang line */
2831 #endif /* ALTERNATE_SHEBANG */
2832 #ifndef MACOS_TRADITIONAL
2837 !instr(s,"indir") &&
2838 instr(PL_origargv[0],"perl"))
2845 while (s < PL_bufend && isSPACE(*s))
2847 if (s < PL_bufend) {
2848 Newz(899,newargv,PL_origargc+3,char*);
2850 while (s < PL_bufend && !isSPACE(*s))
2853 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2856 newargv = PL_origargv;
2859 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
2861 Perl_croak(aTHX_ "Can't exec %s", ipath);
2865 U32 oldpdb = PL_perldb;
2866 bool oldn = PL_minus_n;
2867 bool oldp = PL_minus_p;
2869 while (*d && !isSPACE(*d)) d++;
2870 while (SPACE_OR_TAB(*d)) d++;
2873 bool switches_done = PL_doswitches;
2875 if (*d == 'M' || *d == 'm' || *d == 'C') {
2877 while (*d && !isSPACE(*d)) d++;
2878 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2881 d = moreswitches(d);
2883 if (PL_doswitches && !switches_done) {
2884 int argc = PL_origargc;
2885 char **argv = PL_origargv;
2888 } while (argc && argv[0][0] == '-' && argv[0][1]);
2889 init_argv_symbols(argc,argv);
2891 if ((PERLDB_LINE && !oldpdb) ||
2892 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
2893 /* if we have already added "LINE: while (<>) {",
2894 we must not do it again */
2896 sv_setpv(PL_linestr, "");
2897 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2898 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2899 PL_last_lop = PL_last_uni = Nullch;
2900 PL_preambled = FALSE;
2902 (void)gv_fetchfile(PL_origfilename);
2905 if (PL_doswitches && !switches_done) {
2906 int argc = PL_origargc;
2907 char **argv = PL_origargv;
2910 } while (argc && argv[0][0] == '-' && argv[0][1]);
2911 init_argv_symbols(argc,argv);
2917 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2919 PL_lex_state = LEX_FORMLINE;
2924 #ifdef PERL_STRICT_CR
2925 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
2927 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
2929 case ' ': case '\t': case '\f': case 013:
2930 #ifdef MACOS_TRADITIONAL
2937 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
2938 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
2939 /* handle eval qq[#line 1 "foo"\n ...] */
2940 CopLINE_dec(PL_curcop);
2944 while (s < d && *s != '\n')
2948 else if (s > d) /* Found by Ilya: feed random input to Perl. */
2949 Perl_croak(aTHX_ "panic: input overflow");
2951 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2953 PL_lex_state = LEX_FORMLINE;
2963 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2970 while (s < PL_bufend && SPACE_OR_TAB(*s))
2973 if (strnEQ(s,"=>",2)) {
2974 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
2975 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2976 "### Saw unary minus before =>, forcing word '%s'\n", s);
2978 OPERATOR('-'); /* unary minus */
2980 PL_last_uni = PL_oldbufptr;
2982 case 'r': ftst = OP_FTEREAD; break;
2983 case 'w': ftst = OP_FTEWRITE; break;
2984 case 'x': ftst = OP_FTEEXEC; break;
2985 case 'o': ftst = OP_FTEOWNED; break;
2986 case 'R': ftst = OP_FTRREAD; break;
2987 case 'W': ftst = OP_FTRWRITE; break;
2988 case 'X': ftst = OP_FTREXEC; break;
2989 case 'O': ftst = OP_FTROWNED; break;
2990 case 'e': ftst = OP_FTIS; break;
2991 case 'z': ftst = OP_FTZERO; break;
2992 case 's': ftst = OP_FTSIZE; break;
2993 case 'f': ftst = OP_FTFILE; break;
2994 case 'd': ftst = OP_FTDIR; break;
2995 case 'l': ftst = OP_FTLINK; break;
2996 case 'p': ftst = OP_FTPIPE; break;
2997 case 'S': ftst = OP_FTSOCK; break;
2998 case 'u': ftst = OP_FTSUID; break;
2999 case 'g': ftst = OP_FTSGID; break;
3000 case 'k': ftst = OP_FTSVTX; break;
3001 case 'b': ftst = OP_FTBLK; break;
3002 case 'c': ftst = OP_FTCHR; break;
3003 case 't': ftst = OP_FTTTY; break;
3004 case 'T': ftst = OP_FTTEXT; break;
3005 case 'B': ftst = OP_FTBINARY; break;
3006 case 'M': case 'A': case 'C':
3007 gv_fetchpv("\024",TRUE, SVt_PV);
3009 case 'M': ftst = OP_FTMTIME; break;
3010 case 'A': ftst = OP_FTATIME; break;
3011 case 'C': ftst = OP_FTCTIME; break;
3019 PL_last_lop_op = (OPCODE)ftst;
3020 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3021 "### Saw file test %c\n", (int)ftst);
3026 /* Assume it was a minus followed by a one-letter named
3027 * subroutine call (or a -bareword), then. */
3028 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3029 "### '-%c' looked like a file test but was not\n",
3038 if (PL_expect == XOPERATOR)
3043 else if (*s == '>') {
3046 if (isIDFIRST_lazy_if(s,UTF)) {
3047 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3055 if (PL_expect == XOPERATOR)
3058 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3060 OPERATOR('-'); /* unary minus */
3067 if (PL_expect == XOPERATOR)
3072 if (PL_expect == XOPERATOR)
3075 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3081 if (PL_expect != XOPERATOR) {
3082 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3083 PL_expect = XOPERATOR;
3084 force_ident(PL_tokenbuf, '*');
3097 if (PL_expect == XOPERATOR) {
3101 PL_tokenbuf[0] = '%';
3102 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3103 if (!PL_tokenbuf[1]) {
3106 PL_pending_ident = '%';
3125 switch (PL_expect) {
3128 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3130 PL_bufptr = s; /* update in case we back off */
3136 PL_expect = XTERMBLOCK;
3140 while (isIDFIRST_lazy_if(s,UTF)) {
3141 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3142 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
3143 if (tmp < 0) tmp = -tmp;
3159 d = scan_str(d,TRUE,TRUE);
3161 /* MUST advance bufptr here to avoid bogus
3162 "at end of line" context messages from yyerror().
3164 PL_bufptr = s + len;
3165 yyerror("Unterminated attribute parameter in attribute list");
3168 return REPORT(0); /* EOF indicator */
3172 SV *sv = newSVpvn(s, len);
3173 sv_catsv(sv, PL_lex_stuff);
3174 attrs = append_elem(OP_LIST, attrs,
3175 newSVOP(OP_CONST, 0, sv));
3176 SvREFCNT_dec(PL_lex_stuff);
3177 PL_lex_stuff = Nullsv;
3180 if (len == 6 && strnEQ(s, "unique", len)) {
3181 if (PL_in_my == KEY_our)
3183 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
3185 ; /* skip to avoid loading attributes.pm */
3188 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
3191 /* NOTE: any CV attrs applied here need to be part of
3192 the CVf_BUILTIN_ATTRS define in cv.h! */
3193 else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
3194 CvLVALUE_on(PL_compcv);
3195 else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
3196 CvLOCKED_on(PL_compcv);
3197 else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
3198 CvMETHOD_on(PL_compcv);
3199 else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len))
3200 CvASSERTION_on(PL_compcv);
3201 /* After we've set the flags, it could be argued that
3202 we don't need to do the attributes.pm-based setting
3203 process, and shouldn't bother appending recognized
3204 flags. To experiment with that, uncomment the
3205 following "else". (Note that's already been
3206 uncommented. That keeps the above-applied built-in
3207 attributes from being intercepted (and possibly
3208 rejected) by a package's attribute routines, but is
3209 justified by the performance win for the common case
3210 of applying only built-in attributes.) */
3212 attrs = append_elem(OP_LIST, attrs,
3213 newSVOP(OP_CONST, 0,
3217 if (*s == ':' && s[1] != ':')
3220 break; /* require real whitespace or :'s */
3222 tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
3223 if (*s != ';' && *s != '}' && *s != tmp && (tmp != '=' || *s != ')')) {
3224 char q = ((*s == '\'') ? '"' : '\'');
3225 /* If here for an expression, and parsed no attrs, back off. */
3226 if (tmp == '=' && !attrs) {
3230 /* MUST advance bufptr here to avoid bogus "at end of line"
3231 context messages from yyerror().
3235 yyerror("Unterminated attribute list");
3237 yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
3245 PL_nextval[PL_nexttoke].opval = attrs;
3253 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
3254 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
3271 if (PL_lex_brackets <= 0)
3272 yyerror("Unmatched right square bracket");
3275 if (PL_lex_state == LEX_INTERPNORMAL) {
3276 if (PL_lex_brackets == 0) {
3277 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3278 PL_lex_state = LEX_INTERPEND;
3285 if (PL_lex_brackets > 100) {
3286 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
3288 switch (PL_expect) {
3290 if (PL_lex_formbrack) {
3294 if (PL_oldoldbufptr == PL_last_lop)
3295 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3297 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3298 OPERATOR(HASHBRACK);
3300 while (s < PL_bufend && SPACE_OR_TAB(*s))
3303 PL_tokenbuf[0] = '\0';
3304 if (d < PL_bufend && *d == '-') {
3305 PL_tokenbuf[0] = '-';
3307 while (d < PL_bufend && SPACE_OR_TAB(*d))
3310 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3311 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
3313 while (d < PL_bufend && SPACE_OR_TAB(*d))
3316 char minus = (PL_tokenbuf[0] == '-');
3317 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
3325 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
3330 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3335 if (PL_oldoldbufptr == PL_last_lop)
3336 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3338 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3341 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
3343 /* This hack is to get the ${} in the message. */
3345 yyerror("syntax error");
3348 OPERATOR(HASHBRACK);
3350 /* This hack serves to disambiguate a pair of curlies
3351 * as being a block or an anon hash. Normally, expectation
3352 * determines that, but in cases where we're not in a
3353 * position to expect anything in particular (like inside
3354 * eval"") we have to resolve the ambiguity. This code
3355 * covers the case where the first term in the curlies is a
3356 * quoted string. Most other cases need to be explicitly
3357 * disambiguated by prepending a `+' before the opening
3358 * curly in order to force resolution as an anon hash.
3360 * XXX should probably propagate the outer expectation
3361 * into eval"" to rely less on this hack, but that could
3362 * potentially break current behavior of eval"".
3366 if (*s == '\'' || *s == '"' || *s == '`') {
3367 /* common case: get past first string, handling escapes */
3368 for (t++; t < PL_bufend && *t != *s;)
3369 if (*t++ == '\\' && (*t == '\\' || *t == *s))
3373 else if (*s == 'q') {
3376 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
3379 /* skip q//-like construct */
3381 char open, close, term;
3384 while (t < PL_bufend && isSPACE(*t))
3386 /* check for q => */
3387 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
3388 OPERATOR(HASHBRACK);
3392 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
3396 for (t++; t < PL_bufend; t++) {
3397 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
3399 else if (*t == open)
3403 for (t++; t < PL_bufend; t++) {
3404 if (*t == '\\' && t+1 < PL_bufend)
3406 else if (*t == close && --brackets <= 0)
3408 else if (*t == open)
3415 /* skip plain q word */
3416 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3419 else if (isALNUM_lazy_if(t,UTF)) {
3421 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3424 while (t < PL_bufend && isSPACE(*t))
3426 /* if comma follows first term, call it an anon hash */
3427 /* XXX it could be a comma expression with loop modifiers */
3428 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
3429 || (*t == '=' && t[1] == '>')))
3430 OPERATOR(HASHBRACK);
3431 if (PL_expect == XREF)
3434 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3440 yylval.ival = CopLINE(PL_curcop);
3441 if (isSPACE(*s) || *s == '#')
3442 PL_copline = NOLINE; /* invalidate current command line number */
3447 if (PL_lex_brackets <= 0)
3448 yyerror("Unmatched right curly bracket");
3450 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3451 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3452 PL_lex_formbrack = 0;
3453 if (PL_lex_state == LEX_INTERPNORMAL) {
3454 if (PL_lex_brackets == 0) {
3455 if (PL_expect & XFAKEBRACK) {
3456 PL_expect &= XENUMMASK;
3457 PL_lex_state = LEX_INTERPEND;
3459 return yylex(); /* ignore fake brackets */
3461 if (*s == '-' && s[1] == '>')
3462 PL_lex_state = LEX_INTERPENDMAYBE;
3463 else if (*s != '[' && *s != '{')
3464 PL_lex_state = LEX_INTERPEND;
3467 if (PL_expect & XFAKEBRACK) {
3468 PL_expect &= XENUMMASK;
3470 return yylex(); /* ignore fake brackets */
3480 if (PL_expect == XOPERATOR) {
3481 if (ckWARN(WARN_SEMICOLON)
3482 && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart)
3484 CopLINE_dec(PL_curcop);
3485 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
3486 CopLINE_inc(PL_curcop);
3491 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3493 PL_expect = XOPERATOR;
3494 force_ident(PL_tokenbuf, '&');
3498 yylval.ival = (OPpENTERSUB_AMPER<<8);
3517 if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
3518 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Reversed %c= operator",(int)tmp);
3520 if (PL_expect == XSTATE && isALPHA(tmp) &&
3521 (s == PL_linestart+1 || s[-2] == '\n') )
3523 if (PL_in_eval && !PL_rsfp) {
3528 if (strnEQ(s,"=cut",4)) {
3542 PL_doextract = TRUE;
3545 if (PL_lex_brackets < PL_lex_formbrack) {
3547 #ifdef PERL_STRICT_CR
3548 for (t = s; SPACE_OR_TAB(*t); t++) ;
3550 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3552 if (*t == '\n' || *t == '#') {
3564 /* was this !=~ where !~ was meant?
3565 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
3567 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
3570 while (t < PL_bufend && isSPACE(*t))
3573 if (*t == '/' || *t == '?' ||
3574 ((*t == 'm' || *t == 's' || *t == 'y') && !isALNUM(t[1])) ||
3575 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
3576 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3577 "!=~ should be !~");
3586 if (PL_expect != XOPERATOR) {
3587 if (s[1] != '<' && !strchr(s,'>'))
3590 s = scan_heredoc(s);
3592 s = scan_inputsymbol(s);
3593 TERM(sublex_start());
3598 SHop(OP_LEFT_SHIFT);
3612 SHop(OP_RIGHT_SHIFT);
3621 if (PL_expect == XOPERATOR) {
3622 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3625 return REPORT(','); /* grandfather non-comma-format format */
3629 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3630 PL_tokenbuf[0] = '@';
3631 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3632 sizeof PL_tokenbuf - 1, FALSE);
3633 if (PL_expect == XOPERATOR)
3634 no_op("Array length", s);
3635 if (!PL_tokenbuf[1])
3637 PL_expect = XOPERATOR;
3638 PL_pending_ident = '#';
3642 PL_tokenbuf[0] = '$';
3643 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3644 sizeof PL_tokenbuf - 1, FALSE);
3645 if (PL_expect == XOPERATOR)
3647 if (!PL_tokenbuf[1]) {
3649 yyerror("Final $ should be \\$ or $name");
3653 /* This kludge not intended to be bulletproof. */
3654 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3655 yylval.opval = newSVOP(OP_CONST, 0,
3656 newSViv(PL_compiling.cop_arybase));
3657 yylval.opval->op_private = OPpCONST_ARYBASE;
3663 if (PL_lex_state == LEX_NORMAL)
3666 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3669 PL_tokenbuf[0] = '@';
3670 if (ckWARN(WARN_SYNTAX)) {
3672 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3675 PL_bufptr = skipspace(PL_bufptr);
3676 while (t < PL_bufend && *t != ']')
3678 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3679 "Multidimensional syntax %.*s not supported",
3680 (t - PL_bufptr) + 1, PL_bufptr);
3684 else if (*s == '{') {
3685 PL_tokenbuf[0] = '%';
3686 if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") &&
3687 (t = strchr(s, '}')) && (t = strchr(t, '=')))
3689 char tmpbuf[sizeof PL_tokenbuf];
3691 for (t++; isSPACE(*t); t++) ;
3692 if (isIDFIRST_lazy_if(t,UTF)) {
3693 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3694 for (; isSPACE(*t); t++) ;
3695 if (*t == ';' && get_cv(tmpbuf, FALSE))
3696 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3697 "You need to quote \"%s\"", tmpbuf);
3703 PL_expect = XOPERATOR;
3704 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3705 bool islop = (PL_last_lop == PL_oldoldbufptr);
3706 if (!islop || PL_last_lop_op == OP_GREPSTART)
3707 PL_expect = XOPERATOR;
3708 else if (strchr("$@\"'`q", *s))
3709 PL_expect = XTERM; /* e.g. print $fh "foo" */
3710 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3711 PL_expect = XTERM; /* e.g. print $fh &sub */
3712 else if (isIDFIRST_lazy_if(s,UTF)) {
3713 char tmpbuf[sizeof PL_tokenbuf];
3714 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3715 if ((tmp = keyword(tmpbuf, len))) {
3716 /* binary operators exclude handle interpretations */
3728 PL_expect = XTERM; /* e.g. print $fh length() */
3733 PL_expect = XTERM; /* e.g. print $fh subr() */
3736 else if (isDIGIT(*s))
3737 PL_expect = XTERM; /* e.g. print $fh 3 */
3738 else if (*s == '.' && isDIGIT(s[1]))
3739 PL_expect = XTERM; /* e.g. print $fh .3 */
3740 else if ((*s == '?' || *s == '-' || *s == '+')
3741 && !isSPACE(s[1]) && s[1] != '=')
3742 PL_expect = XTERM; /* e.g. print $fh -1 */
3743 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' && s[1] != '/')
3744 PL_expect = XTERM; /* e.g. print $fh /.../
3745 XXX except DORDOR operator */
3746 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3747 PL_expect = XTERM; /* print $fh <<"EOF" */
3749 PL_pending_ident = '$';
3753 if (PL_expect == XOPERATOR)
3755 PL_tokenbuf[0] = '@';
3756 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3757 if (!PL_tokenbuf[1]) {
3760 if (PL_lex_state == LEX_NORMAL)
3762 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3764 PL_tokenbuf[0] = '%';
3766 /* Warn about @ where they meant $. */
3767 if (ckWARN(WARN_SYNTAX)) {
3768 if (*s == '[' || *s == '{') {
3770 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3772 if (*t == '}' || *t == ']') {
3774 PL_bufptr = skipspace(PL_bufptr);
3775 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3776 "Scalar value %.*s better written as $%.*s",
3777 t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3782 PL_pending_ident = '@';
3785 case '/': /* may be division, defined-or, or pattern */
3786 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
3790 case '?': /* may either be conditional or pattern */
3791 if(PL_expect == XOPERATOR) {
3799 /* A // operator. */
3809 /* Disable warning on "study /blah/" */
3810 if (PL_oldoldbufptr == PL_last_uni
3811 && (*PL_last_uni != 's' || s - PL_last_uni < 5
3812 || memNE(PL_last_uni, "study", 5)
3813 || isALNUM_lazy_if(PL_last_uni+5,UTF)
3816 s = scan_pat(s,OP_MATCH);
3817 TERM(sublex_start());
3821 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3822 #ifdef PERL_STRICT_CR
3825 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3827 && (s == PL_linestart || s[-1] == '\n') )
3829 PL_lex_formbrack = 0;
3833 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3839 yylval.ival = OPf_SPECIAL;
3845 if (PL_expect != XOPERATOR)
3850 case '0': case '1': case '2': case '3': case '4':
3851 case '5': case '6': case '7': case '8': case '9':
3852 s = scan_num(s, &yylval);
3853 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3854 "### Saw number in '%s'\n", s);
3856 if (PL_expect == XOPERATOR)
3861 s = scan_str(s,FALSE,FALSE);
3862 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3863 "### Saw string before '%s'\n", s);
3865 if (PL_expect == XOPERATOR) {
3866 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3869 return REPORT(','); /* grandfather non-comma-format format */
3875 missingterm((char*)0);
3876 yylval.ival = OP_CONST;
3877 TERM(sublex_start());
3880 s = scan_str(s,FALSE,FALSE);
3881 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3882 "### Saw string before '%s'\n", s);
3884 if (PL_expect == XOPERATOR) {
3885 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3888 return REPORT(','); /* grandfather non-comma-format format */
3894 missingterm((char*)0);
3895 yylval.ival = OP_CONST;
3896 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3897 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
3898 yylval.ival = OP_STRINGIFY;
3902 TERM(sublex_start());
3905 s = scan_str(s,FALSE,FALSE);
3906 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3907 "### Saw backtick string before '%s'\n", s);
3909 if (PL_expect == XOPERATOR)
3910 no_op("Backticks",s);
3912 missingterm((char*)0);
3913 yylval.ival = OP_BACKTICK;
3915 TERM(sublex_start());
3919 if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s))
3920 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
3922 if (PL_expect == XOPERATOR)
3923 no_op("Backslash",s);
3927 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
3931 while (isDIGIT(*start) || *start == '_')
3933 if (*start == '.' && isDIGIT(start[1])) {
3934 s = scan_num(s, &yylval);
3937 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
3938 else if (!isALPHA(*start) && (PL_expect == XTERM
3939 || PL_expect == XREF || PL_expect == XSTATE
3940 || PL_expect == XTERMORDORDOR)) {
3944 gv = gv_fetchpv(s, FALSE, SVt_PVCV);
3947 s = scan_num(s, &yylval);
3954 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
3994 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3996 /* Some keywords can be followed by any delimiter, including ':' */
3997 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
3998 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
3999 (PL_tokenbuf[0] == 'q' &&
4000 strchr("qwxr", PL_tokenbuf[1])))));
4002 /* x::* is just a word, unless x is "CORE" */
4003 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4007 while (d < PL_bufend && isSPACE(*d))
4008 d++; /* no comments skipped here, or s### is misparsed */
4010 /* Is this a label? */
4011 if (!tmp && PL_expect == XSTATE
4012 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4014 yylval.pval = savepv(PL_tokenbuf);
4019 /* Check for keywords */
4020 tmp = keyword(PL_tokenbuf, len);
4022 /* Is this a word before a => operator? */
4023 if (*d == '=' && d[1] == '>') {
4026 = (OP*)newSVOP(OP_CONST, 0,
4027 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
4028 yylval.opval->op_private = OPpCONST_BARE;
4032 if (tmp < 0) { /* second-class keyword? */
4033 GV *ogv = Nullgv; /* override (winner) */
4034 GV *hgv = Nullgv; /* hidden (loser) */
4035 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4037 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
4040 if (GvIMPORTED_CV(gv))
4042 else if (! CvMETHOD(cv))
4046 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4047 (gv = *gvp) != (GV*)&PL_sv_undef &&
4048 GvCVu(gv) && GvIMPORTED_CV(gv))
4055 tmp = 0; /* overridden by import or by GLOBAL */
4058 && -tmp==KEY_lock /* XXX generalizable kludge */
4060 && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
4062 tmp = 0; /* any sub overrides "weak" keyword */
4067 && PL_expect != XOPERATOR
4068 && PL_expect != XTERMORDORDOR)
4070 /* any sub overrides the "err" keyword, except when really an
4071 * operator is expected */
4074 else { /* no override */
4076 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
4077 Perl_warner(aTHX_ packWARN(WARN_MISC),
4078 "dump() better written as CORE::dump()");
4082 if (ckWARN(WARN_AMBIGUOUS) && hgv
4083 && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
4084 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4085 "Ambiguous call resolved as CORE::%s(), %s",
4086 GvENAME(hgv), "qualify as such or use &");
4093 default: /* not a keyword */
4097 char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
4099 /* Get the rest if it looks like a package qualifier */
4101 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
4103 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
4106 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
4107 *s == '\'' ? "'" : "::");
4112 if (PL_expect == XOPERATOR) {
4113 if (PL_bufptr == PL_linestart) {
4114 CopLINE_dec(PL_curcop);
4115 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4116 CopLINE_inc(PL_curcop);
4119 no_op("Bareword",s);
4122 /* Look for a subroutine with this name in current package,
4123 unless name is "Foo::", in which case Foo is a bearword
4124 (and a package name). */
4127 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
4129 if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
4130 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
4131 "Bareword \"%s\" refers to nonexistent package",
4134 PL_tokenbuf[len] = '\0';
4141 gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
4144 /* if we saw a global override before, get the right name */
4147 sv = newSVpvn("CORE::GLOBAL::",14);
4148 sv_catpv(sv,PL_tokenbuf);
4151 /* If len is 0, newSVpv does strlen(), which is correct.
4152 If len is non-zero, then it will be the true length,
4153 and so the scalar will be created correctly. */
4154 sv = newSVpv(PL_tokenbuf,len);
4157 /* Presume this is going to be a bareword of some sort. */
4160 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4161 yylval.opval->op_private = OPpCONST_BARE;
4162 /* UTF-8 package name? */
4163 if (UTF && !IN_BYTES &&
4164 is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
4167 /* And if "Foo::", then that's what it certainly is. */
4172 /* See if it's the indirect object for a list operator. */
4174 if (PL_oldoldbufptr &&
4175 PL_oldoldbufptr < PL_bufptr &&
4176 (PL_oldoldbufptr == PL_last_lop
4177 || PL_oldoldbufptr == PL_last_uni) &&
4178 /* NO SKIPSPACE BEFORE HERE! */
4179 (PL_expect == XREF ||
4180 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
4182 bool immediate_paren = *s == '(';
4184 /* (Now we can afford to cross potential line boundary.) */
4187 /* Two barewords in a row may indicate method call. */
4189 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv)))
4192 /* If not a declared subroutine, it's an indirect object. */
4193 /* (But it's an indir obj regardless for sort.) */
4195 if ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
4196 ((!gv || !GvCVu(gv)) &&
4197 (PL_last_lop_op != OP_MAPSTART &&
4198 PL_last_lop_op != OP_GREPSTART))))
4200 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
4205 PL_expect = XOPERATOR;
4208 /* Is this a word before a => operator? */
4209 if (*s == '=' && s[1] == '>' && !pkgname) {
4211 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
4212 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
4213 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
4217 /* If followed by a paren, it's certainly a subroutine. */
4220 if (gv && GvCVu(gv)) {
4221 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
4222 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
4227 PL_nextval[PL_nexttoke].opval = yylval.opval;
4228 PL_expect = XOPERATOR;
4234 /* If followed by var or block, call it a method (unless sub) */
4236 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
4237 PL_last_lop = PL_oldbufptr;
4238 PL_last_lop_op = OP_METHOD;
4242 /* If followed by a bareword, see if it looks like indir obj. */
4245 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
4246 && (tmp = intuit_method(s,gv)))
4249 /* Not a method, so call it a subroutine (if defined) */
4251 if (gv && GvCVu(gv)) {
4253 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
4254 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4255 "Ambiguous use of -%s resolved as -&%s()",
4256 PL_tokenbuf, PL_tokenbuf);
4257 /* Check for a constant sub */
4259 if ((sv = cv_const_sv(cv))) {
4261 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
4262 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
4263 yylval.opval->op_private = 0;
4267 /* Resolve to GV now. */
4268 op_free(yylval.opval);
4269 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4270 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
4271 PL_last_lop = PL_oldbufptr;
4272 PL_last_lop_op = OP_ENTERSUB;
4273 /* Is there a prototype? */
4276 char *proto = SvPV((SV*)cv, len);
4279 if (*proto == '$' && proto[1] == '\0')
4281 while (*proto == ';')
4283 if (*proto == '&' && *s == '{') {
4284 sv_setpv(PL_subname, PL_curstash ?
4285 "__ANON__" : "__ANON__::__ANON__");
4289 PL_nextval[PL_nexttoke].opval = yylval.opval;
4295 /* Call it a bare word */
4297 if (PL_hints & HINT_STRICT_SUBS)
4298 yylval.opval->op_private |= OPpCONST_STRICT;
4301 if (ckWARN(WARN_RESERVED)) {
4302 if (lastchar != '-') {
4303 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
4304 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
4305 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
4312 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
4313 && ckWARN_d(WARN_AMBIGUOUS)) {
4314 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4315 "Operator or semicolon missing before %c%s",
4316 lastchar, PL_tokenbuf);
4317 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4318 "Ambiguous use of %c resolved as operator %c",
4319 lastchar, lastchar);
4325 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4326 newSVpv(CopFILE(PL_curcop),0));
4330 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4331 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
4334 case KEY___PACKAGE__:
4335 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4337 ? newSVpv(HvNAME(PL_curstash), 0)
4346 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
4347 const char *pname = "main";
4348 if (PL_tokenbuf[2] == 'D')
4349 pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash);
4350 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);
4353 GvIOp(gv) = newIO();
4354 IoIFP(GvIOp(gv)) = PL_rsfp;
4355 #if defined(HAS_FCNTL) && defined(F_SETFD)
4357 int fd = PerlIO_fileno(PL_rsfp);
4358 fcntl(fd,F_SETFD,fd >= 3);
4361 /* Mark this internal pseudo-handle as clean */
4362 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4364 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
4365 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
4366 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
4368 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
4369 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
4370 /* if the script was opened in binmode, we need to revert
4371 * it to text mode for compatibility; but only iff it has CRs
4372 * XXX this is a questionable hack at best. */
4373 if (PL_bufend-PL_bufptr > 2
4374 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
4377 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
4378 loc = PerlIO_tell(PL_rsfp);
4379 (void)PerlIO_seek(PL_rsfp, 0L, 0);
4382 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
4384 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
4385 #endif /* NETWARE */
4386 #ifdef PERLIO_IS_STDIO /* really? */
4387 # if defined(__BORLANDC__)
4388 /* XXX see note in do_binmode() */
4389 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
4393 PerlIO_seek(PL_rsfp, loc, 0);
4397 #ifdef PERLIO_LAYERS
4400 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
4401 else if (PL_encoding) {
4408 XPUSHs(PL_encoding);
4410 call_method("name", G_SCALAR);
4414 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
4415 Perl_form(aTHX_ ":encoding(%"SVf")",
4433 if (PL_expect == XSTATE) {
4440 if (*s == ':' && s[1] == ':') {
4443 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4444 if (!(tmp = keyword(PL_tokenbuf, len)))
4445 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
4459 LOP(OP_ACCEPT,XTERM);
4465 LOP(OP_ATAN2,XTERM);
4471 LOP(OP_BINMODE,XTERM);
4474 LOP(OP_BLESS,XTERM);
4483 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
4500 if (!PL_cryptseen) {
4501 PL_cryptseen = TRUE;
4505 LOP(OP_CRYPT,XTERM);
4508 LOP(OP_CHMOD,XTERM);
4511 LOP(OP_CHOWN,XTERM);
4514 LOP(OP_CONNECT,XTERM);
4530 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4534 PL_hints |= HINT_BLOCK_SCOPE;
4544 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
4545 LOP(OP_DBMOPEN,XTERM);
4551 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4558 yylval.ival = CopLINE(PL_curcop);
4572 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4573 UNIBRACK(OP_ENTEREVAL);
4591 case KEY_endhostent:
4597 case KEY_endservent:
4600 case KEY_endprotoent:
4611 yylval.ival = CopLINE(PL_curcop);
4613 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4615 if ((PL_bufend - p) >= 3 &&
4616 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4618 else if ((PL_bufend - p) >= 4 &&
4619 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4622 if (isIDFIRST_lazy_if(p,UTF)) {
4623 p = scan_ident(p, PL_bufend,
4624 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4628 Perl_croak(aTHX_ "Missing $ on loop variable");
4633 LOP(OP_FORMLINE,XTERM);
4639 LOP(OP_FCNTL,XTERM);
4645 LOP(OP_FLOCK,XTERM);
4654 LOP(OP_GREPSTART, XREF);
4657 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4672 case KEY_getpriority:
4673 LOP(OP_GETPRIORITY,XTERM);
4675 case KEY_getprotobyname:
4678 case KEY_getprotobynumber:
4679 LOP(OP_GPBYNUMBER,XTERM);
4681 case KEY_getprotoent:
4693 case KEY_getpeername:
4694 UNI(OP_GETPEERNAME);
4696 case KEY_gethostbyname:
4699 case KEY_gethostbyaddr:
4700 LOP(OP_GHBYADDR,XTERM);
4702 case KEY_gethostent:
4705 case KEY_getnetbyname:
4708 case KEY_getnetbyaddr:
4709 LOP(OP_GNBYADDR,XTERM);
4714 case KEY_getservbyname:
4715 LOP(OP_GSBYNAME,XTERM);
4717 case KEY_getservbyport:
4718 LOP(OP_GSBYPORT,XTERM);
4720 case KEY_getservent:
4723 case KEY_getsockname:
4724 UNI(OP_GETSOCKNAME);
4726 case KEY_getsockopt:
4727 LOP(OP_GSOCKOPT,XTERM);
4749 yylval.ival = CopLINE(PL_curcop);
4753 LOP(OP_INDEX,XTERM);
4759 LOP(OP_IOCTL,XTERM);
4771 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4803 LOP(OP_LISTEN,XTERM);
4812 s = scan_pat(s,OP_MATCH);
4813 TERM(sublex_start());
4816 LOP(OP_MAPSTART, XREF);
4819 LOP(OP_MKDIR,XTERM);
4822 LOP(OP_MSGCTL,XTERM);
4825 LOP(OP_MSGGET,XTERM);
4828 LOP(OP_MSGRCV,XTERM);
4831 LOP(OP_MSGSND,XTERM);
4837 if (isIDFIRST_lazy_if(s,UTF)) {
4838 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4839 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4841 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
4842 if (!PL_in_my_stash) {
4845 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4853 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4860 if (PL_expect != XSTATE)
4861 yyerror("\"no\" not allowed in expression");
4862 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4863 s = force_version(s, FALSE);
4868 if (*s == '(' || (s = skipspace(s), *s == '('))
4875 if (isIDFIRST_lazy_if(s,UTF)) {
4877 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
4878 for (t=d; *t && isSPACE(*t); t++) ;
4879 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
4881 && !(t[0] == '=' && t[1] == '>')
4883 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
4884 "Precedence problem: open %.*s should be open(%.*s)",
4885 d - s, s, d - s, s);
4891 yylval.ival = OP_OR;
4901 LOP(OP_OPEN_DIR,XTERM);
4904 checkcomma(s,PL_tokenbuf,"filehandle");
4908 checkcomma(s,PL_tokenbuf,"filehandle");
4927 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4931 LOP(OP_PIPE_OP,XTERM);
4934 s = scan_str(s,FALSE,FALSE);
4936 missingterm((char*)0);
4937 yylval.ival = OP_CONST;
4938 TERM(sublex_start());
4944 s = scan_str(s,FALSE,FALSE);
4946 missingterm((char*)0);
4948 if (SvCUR(PL_lex_stuff)) {
4951 d = SvPV_force(PL_lex_stuff, len);
4954 for (; isSPACE(*d) && len; --len, ++d) ;
4957 if (!warned && ckWARN(WARN_QW)) {
4958 for (; !isSPACE(*d) && len; --len, ++d) {
4960 Perl_warner(aTHX_ packWARN(WARN_QW),
4961 "Possible attempt to separate words with commas");
4964 else if (*d == '#') {
4965 Perl_warner(aTHX_ packWARN(WARN_QW),
4966 "Possible attempt to put comments in qw() list");
4972 for (; !isSPACE(*d) && len; --len, ++d) ;
4974 sv = newSVpvn(b, d-b);
4975 if (DO_UTF8(PL_lex_stuff))
4977 words = append_elem(OP_LIST, words,
4978 newSVOP(OP_CONST, 0, tokeq(sv)));
4982 PL_nextval[PL_nexttoke].opval = words;
4987 SvREFCNT_dec(PL_lex_stuff);
4988 PL_lex_stuff = Nullsv;
4994 s = scan_str(s,FALSE,FALSE);
4996 missingterm((char*)0);
4997 yylval.ival = OP_STRINGIFY;
4998 if (SvIVX(PL_lex_stuff) == '\'')
4999 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
5000 TERM(sublex_start());
5003 s = scan_pat(s,OP_QR);
5004 TERM(sublex_start());
5007 s = scan_str(s,FALSE,FALSE);
5009 missingterm((char*)0);
5010 yylval.ival = OP_BACKTICK;
5012 TERM(sublex_start());
5020 s = force_version(s, FALSE);
5022 else if (*s != 'v' || !isDIGIT(s[1])
5023 || (s = force_version(s, TRUE), *s == 'v'))
5025 *PL_tokenbuf = '\0';
5026 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5027 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
5028 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
5030 yyerror("<> should be quotes");
5038 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5042 LOP(OP_RENAME,XTERM);
5051 LOP(OP_RINDEX,XTERM);
5061 UNIDOR(OP_READLINE);
5074 LOP(OP_REVERSE,XTERM);
5077 UNIDOR(OP_READLINK);
5085 TERM(sublex_start());
5087 TOKEN(1); /* force error */
5096 LOP(OP_SELECT,XTERM);
5102 LOP(OP_SEMCTL,XTERM);
5105 LOP(OP_SEMGET,XTERM);
5108 LOP(OP_SEMOP,XTERM);
5114 LOP(OP_SETPGRP,XTERM);
5116 case KEY_setpriority:
5117 LOP(OP_SETPRIORITY,XTERM);
5119 case KEY_sethostent:
5125 case KEY_setservent:
5128 case KEY_setprotoent:
5138 LOP(OP_SEEKDIR,XTERM);
5140 case KEY_setsockopt:
5141 LOP(OP_SSOCKOPT,XTERM);
5147 LOP(OP_SHMCTL,XTERM);
5150 LOP(OP_SHMGET,XTERM);
5153 LOP(OP_SHMREAD,XTERM);
5156 LOP(OP_SHMWRITE,XTERM);
5159 LOP(OP_SHUTDOWN,XTERM);
5168 LOP(OP_SOCKET,XTERM);
5170 case KEY_socketpair:
5171 LOP(OP_SOCKPAIR,XTERM);
5174 checkcomma(s,PL_tokenbuf,"subroutine name");
5176 if (*s == ';' || *s == ')') /* probably a close */
5177 Perl_croak(aTHX_ "sort is now a reserved word");
5179 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5183 LOP(OP_SPLIT,XTERM);
5186 LOP(OP_SPRINTF,XTERM);
5189 LOP(OP_SPLICE,XTERM);
5204 LOP(OP_SUBSTR,XTERM);
5210 char tmpbuf[sizeof PL_tokenbuf];
5211 SSize_t tboffset = 0;
5212 expectation attrful;
5213 bool have_name, have_proto, bad_proto;
5218 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
5219 (*s == ':' && s[1] == ':'))
5222 attrful = XATTRBLOCK;
5223 /* remember buffer pos'n for later force_word */
5224 tboffset = s - PL_oldbufptr;
5225 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5226 if (strchr(tmpbuf, ':'))
5227 sv_setpv(PL_subname, tmpbuf);
5229 sv_setsv(PL_subname,PL_curstname);
5230 sv_catpvn(PL_subname,"::",2);
5231 sv_catpvn(PL_subname,tmpbuf,len);
5238 Perl_croak(aTHX_ "Missing name in \"my sub\"");
5239 PL_expect = XTERMBLOCK;
5240 attrful = XATTRTERM;
5241 sv_setpv(PL_subname,"?");
5245 if (key == KEY_format) {
5247 PL_lex_formbrack = PL_lex_brackets + 1;
5249 (void) force_word(PL_oldbufptr + tboffset, WORD,
5254 /* Look for a prototype */
5258 s = scan_str(s,FALSE,FALSE);
5260 Perl_croak(aTHX_ "Prototype not terminated");
5261 /* strip spaces and check for bad characters */
5262 d = SvPVX(PL_lex_stuff);
5265 for (p = d; *p; ++p) {
5268 if (!strchr("$@%*;[]&\\", *p))
5273 if (bad_proto && ckWARN(WARN_SYNTAX))
5274 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5275 "Illegal character in prototype for %"SVf" : %s",
5277 SvCUR_set(PL_lex_stuff, tmp);
5285 if (*s == ':' && s[1] != ':')
5286 PL_expect = attrful;
5287 else if (*s != '{' && key == KEY_sub) {
5289 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
5291 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname);
5295 PL_nextval[PL_nexttoke].opval =
5296 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
5297 PL_lex_stuff = Nullsv;
5301 sv_setpv(PL_subname,
5302 PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
5305 (void) force_word(PL_oldbufptr + tboffset, WORD,
5314 LOP(OP_SYSTEM,XREF);
5317 LOP(OP_SYMLINK,XTERM);
5320 LOP(OP_SYSCALL,XTERM);
5323 LOP(OP_SYSOPEN,XTERM);
5326 LOP(OP_SYSSEEK,XTERM);
5329 LOP(OP_SYSREAD,XTERM);
5332 LOP(OP_SYSWRITE,XTERM);
5336 TERM(sublex_start());
5357 LOP(OP_TRUNCATE,XTERM);
5369 yylval.ival = CopLINE(PL_curcop);
5373 yylval.ival = CopLINE(PL_curcop);
5377 LOP(OP_UNLINK,XTERM);
5383 LOP(OP_UNPACK,XTERM);
5386 LOP(OP_UTIME,XTERM);
5392 LOP(OP_UNSHIFT,XTERM);
5395 if (PL_expect != XSTATE)
5396 yyerror("\"use\" not allowed in expression");
5398 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
5399 s = force_version(s, TRUE);
5400 if (*s == ';' || (s = skipspace(s), *s == ';')) {
5401 PL_nextval[PL_nexttoke].opval = Nullop;
5404 else if (*s == 'v') {
5405 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5406 s = force_version(s, FALSE);
5410 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5411 s = force_version(s, FALSE);
5423 yylval.ival = CopLINE(PL_curcop);
5427 PL_hints |= HINT_BLOCK_SCOPE;
5434 LOP(OP_WAITPID,XTERM);
5443 ctl_l[0] = toCTRL('L');
5445 gv_fetchpv(ctl_l,TRUE, SVt_PV);
5448 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
5453 if (PL_expect == XOPERATOR)
5459 yylval.ival = OP_XOR;
5464 TERM(sublex_start());
5469 #pragma segment Main
5473 S_pending_ident(pTHX)
5476 register I32 tmp = 0;
5477 /* pit holds the identifier we read and pending_ident is reset */
5478 char pit = PL_pending_ident;
5479 PL_pending_ident = 0;
5481 DEBUG_T({ PerlIO_printf(Perl_debug_log,
5482 "### Tokener saw identifier '%s'\n", PL_tokenbuf); });
5484 /* if we're in a my(), we can't allow dynamics here.
5485 $foo'bar has already been turned into $foo::bar, so
5486 just check for colons.
5488 if it's a legal name, the OP is a PADANY.
5491 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
5492 if (strchr(PL_tokenbuf,':'))
5493 yyerror(Perl_form(aTHX_ "No package name allowed for "
5494 "variable %s in \"our\"",
5496 tmp = allocmy(PL_tokenbuf);
5499 if (strchr(PL_tokenbuf,':'))
5500 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
5502 yylval.opval = newOP(OP_PADANY, 0);
5503 yylval.opval->op_targ = allocmy(PL_tokenbuf);
5509 build the ops for accesses to a my() variable.
5511 Deny my($a) or my($b) in a sort block, *if* $a or $b is
5512 then used in a comparison. This catches most, but not
5513 all cases. For instance, it catches
5514 sort { my($a); $a <=> $b }
5516 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
5517 (although why you'd do that is anyone's guess).
5520 if (!strchr(PL_tokenbuf,':')) {
5522 tmp = pad_findmy(PL_tokenbuf);
5523 if (tmp != NOT_IN_PAD) {
5524 /* might be an "our" variable" */
5525 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
5526 /* build ops for a bareword */
5527 SV *sym = newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)), 0);
5528 sv_catpvn(sym, "::", 2);
5529 sv_catpv(sym, PL_tokenbuf+1);
5530 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
5531 yylval.opval->op_private = OPpCONST_ENTERED;
5534 ? (GV_ADDMULTI | GV_ADDINEVAL)
5537 ((PL_tokenbuf[0] == '$') ? SVt_PV
5538 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5543 /* if it's a sort block and they're naming $a or $b */
5544 if (PL_last_lop_op == OP_SORT &&
5545 PL_tokenbuf[0] == '$' &&
5546 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
5549 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
5550 d < PL_bufend && *d != '\n';
5553 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
5554 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
5560 yylval.opval = newOP(OP_PADANY, 0);
5561 yylval.opval->op_targ = tmp;
5567 Whine if they've said @foo in a doublequoted string,
5568 and @foo isn't a variable we can find in the symbol
5571 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
5572 GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
5573 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
5574 && ckWARN(WARN_AMBIGUOUS))
5576 /* Downgraded from fatal to warning 20000522 mjd */
5577 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5578 "Possible unintended interpolation of %s in string",
5583 /* build ops for a bareword */
5584 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
5585 yylval.opval->op_private = OPpCONST_ENTERED;
5586 gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
5587 ((PL_tokenbuf[0] == '$') ? SVt_PV
5588 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5594 * The following code was generated by perl_keyword.pl.
5598 Perl_keyword (pTHX_ char *name, I32 len)
5602 case 1: /* 5 tokens of length 1 */
5634 case 2: /* 18 tokens of length 2 */
5780 case 3: /* 28 tokens of length 3 */
5784 if (name[1] == 'N' &&
5847 if (name[1] == 'i' &&
5887 if (name[1] == 'o' &&
5896 if (name[1] == 'e' &&
5905 if (name[1] == 'n' &&
5914 if (name[1] == 'o' &&
5923 if (name[1] == 'a' &&
5932 if (name[1] == 'o' &&
5994 if (name[1] == 'e' &&
6026 if (name[1] == 'i' &&
6035 if (name[1] == 's' &&
6044 if (name[1] == 'e' &&
6053 if (name[1] == 'o' &&
6065 case 4: /* 40 tokens of length 4 */
6069 if (name[1] == 'O' &&
6079 if (name[1] == 'N' &&
6089 if (name[1] == 'i' &&
6099 if (name[1] == 'h' &&
6109 if (name[1] == 'u' &&
6122 if (name[2] == 'c' &&
6131 if (name[2] == 's' &&
6140 if (name[2] == 'a' &&
6176 if (name[1] == 'o' &&
6189 if (name[2] == 't' &&
6198 if (name[2] == 'o' &&
6207 if (name[2] == 't' &&
6216 if (name[2] == 'e' &&
6229 if (name[1] == 'o' &&
6242 if (name[2] == 'y' &&
6251 if (name[2] == 'l' &&
6267 if (name[2] == 's' &&
6276 if (name[2] == 'n' &&
6285 if (name[2] == 'c' &&
6298 if (name[1] == 'e' &&
6308 if (name[1] == 'p' &&
6321 if (name[2] == 'c' &&
6330 if (name[2] == 'p' &&
6339 if (name[2] == 's' &&
6355 if (name[2] == 'n' &&
6425 if (name[2] == 'r' &&
6434 if (name[2] == 'r' &&
6443 if (name[2] == 'a' &&
6459 if (name[2] == 'l' &&
6526 case 5: /* 36 tokens of length 5 */
6530 if (name[1] == 'E' &&
6541 if (name[1] == 'H' &&
6555 if (name[2] == 'a' &&
6565 if (name[2] == 'a' &&
6579 if (name[1] == 'l' &&
6596 if (name[3] == 'i' &&
6605 if (name[3] == 'o' &&
6641 if (name[2] == 'o' &&
6651 if (name[2] == 'y' &&
6665 if (name[1] == 'l' &&
6679 if (name[2] == 'n' &&
6689 if (name[2] == 'o' &&
6706 if (name[2] == 'd' &&
6716 if (name[2] == 'c' &&
6733 if (name[2] == 'c' &&
6743 if (name[2] == 't' &&
6757 if (name[1] == 'k' &&
6768 if (name[1] == 'r' &&
6782 if (name[2] == 's' &&
6792 if (name[2] == 'd' &&
6809 if (name[2] == 'm' &&
6819 if (name[2] == 'i' &&
6829 if (name[2] == 'e' &&
6839 if (name[2] == 'l' &&
6849 if (name[2] == 'a' &&
6859 if (name[2] == 'u' &&
6873 if (name[1] == 'i' &&
6887 if (name[2] == 'a' &&
6900 if (name[3] == 'e' &&
6935 if (name[2] == 'i' &&
6952 if (name[2] == 'i' &&
6962 if (name[2] == 'i' &&
6979 case 6: /* 33 tokens of length 6 */
6983 if (name[1] == 'c' &&
6998 if (name[2] == 'l' &&
7009 if (name[2] == 'r' &&
7024 if (name[1] == 'e' &&
7039 if (name[2] == 's' &&
7044 if(ckWARN_d(WARN_SYNTAX))
7045 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
7051 if (name[2] == 'i' &&
7069 if (name[2] == 'l' &&
7080 if (name[2] == 'r' &&
7095 if (name[1] == 'm' &&
7110 if (name[2] == 'n' &&
7121 if (name[2] == 's' &&
7136 if (name[1] == 's' &&
7142 if (name[4] == 't' &&
7151 if (name[4] == 'e' &&
7160 if (name[4] == 'c' &&
7169 if (name[4] == 'n' &&
7185 if (name[1] == 'r' &&
7203 if (name[3] == 'a' &&
7213 if (name[3] == 'u' &&
7227 if (name[2] == 'n' &&
7245 if (name[2] == 'a' &&
7259 if (name[3] == 'e' &&
7272 if (name[4] == 't' &&
7281 if (name[4] == 'e' &&
7303 if (name[4] == 't' &&
7312 if (name[4] == 'e' &&
7328 if (name[2] == 'c' &&
7339 if (name[2] == 'l' &&
7350 if (name[2] == 'b' &&
7361 if (name[2] == 's' &&
7384 if (name[4] == 's' &&
7393 if (name[4] == 'n' &&
7406 if (name[3] == 'a' &&
7423 if (name[1] == 'a' &&
7438 case 7: /* 28 tokens of length 7 */
7442 if (name[1] == 'E' &&
7455 if (name[1] == '_' &&
7468 if (name[1] == 'i' &&
7475 return -KEY_binmode;
7481 if (name[1] == 'o' &&
7488 return -KEY_connect;
7497 if (name[2] == 'm' &&
7503 return -KEY_dbmopen;
7509 if (name[2] == 'f' &&
7525 if (name[1] == 'o' &&
7538 if (name[1] == 'e' &&
7545 if (name[5] == 'r' &&
7548 return -KEY_getpgrp;
7554 if (name[5] == 'i' &&
7557 return -KEY_getppid;
7570 if (name[1] == 'c' &&
7577 return -KEY_lcfirst;
7583 if (name[1] == 'p' &&
7590 return -KEY_opendir;
7596 if (name[1] == 'a' &&
7614 if (name[3] == 'd' &&
7619 return -KEY_readdir;
7625 if (name[3] == 'u' &&
7636 if (name[3] == 'e' &&
7641 return -KEY_reverse;
7660 if (name[3] == 'k' &&
7665 return -KEY_seekdir;
7671 if (name[3] == 'p' &&
7676 return -KEY_setpgrp;
7686 if (name[2] == 'm' &&
7692 return -KEY_shmread;
7698 if (name[2] == 'r' &&
7704 return -KEY_sprintf;
7713 if (name[3] == 'l' &&
7718 return -KEY_symlink;
7727 if (name[4] == 'a' &&
7731 return -KEY_syscall;
7737 if (name[4] == 'p' &&
7741 return -KEY_sysopen;
7747 if (name[4] == 'e' &&
7751 return -KEY_sysread;
7757 if (name[4] == 'e' &&
7761 return -KEY_sysseek;
7779 if (name[1] == 'e' &&
7786 return -KEY_telldir;
7795 if (name[2] == 'f' &&
7801 return -KEY_ucfirst;
7807 if (name[2] == 's' &&
7813 return -KEY_unshift;
7823 if (name[1] == 'a' &&
7830 return -KEY_waitpid;
7839 case 8: /* 26 tokens of length 8 */
7843 if (name[1] == 'U' &&
7851 return KEY_AUTOLOAD;
7862 if (name[3] == 'A' &&
7868 return KEY___DATA__;
7874 if (name[3] == 'I' &&
7880 return -KEY___FILE__;
7886 if (name[3] == 'I' &&
7892 return -KEY___LINE__;
7908 if (name[2] == 'o' &&
7915 return -KEY_closedir;
7921 if (name[2] == 'n' &&
7928 return -KEY_continue;
7938 if (name[1] == 'b' &&
7946 return -KEY_dbmclose;
7952 if (name[1] == 'n' &&
7958 if (name[4] == 'r' &&
7963 return -KEY_endgrent;
7969 if (name[4] == 'w' &&
7974 return -KEY_endpwent;
7987 if (name[1] == 'o' &&
7995 return -KEY_formline;
8001 if (name[1] == 'e' &&
8012 if (name[6] == 'n' &&
8015 return -KEY_getgrent;
8021 if (name[6] == 'i' &&
8024 return -KEY_getgrgid;
8030 if (name[6] == 'a' &&
8033 return -KEY_getgrnam;
8046 if (name[4] == 'o' &&
8051 return -KEY_getlogin;
8062 if (name[6] == 'n' &&
8065 return -KEY_getpwent;
8071 if (name[6] == 'a' &&
8074 return -KEY_getpwnam;
8080 if (name[6] == 'i' &&
8083 return -KEY_getpwuid;
8103 if (name[1] == 'e' &&
8110 if (name[5] == 'i' &&
8117 return -KEY_readline;
8122 return -KEY_readlink;
8133 if (name[5] == 'i' &&
8137 return -KEY_readpipe;
8158 if (name[4] == 'r' &&
8163 return -KEY_setgrent;
8169 if (name[4] == 'w' &&
8174 return -KEY_setpwent;
8190 if (name[3] == 'w' &&
8196 return -KEY_shmwrite;
8202 if (name[3] == 't' &&
8208 return -KEY_shutdown;
8218 if (name[2] == 's' &&
8225 return -KEY_syswrite;
8235 if (name[1] == 'r' &&
8243 return -KEY_truncate;
8252 case 9: /* 8 tokens of length 9 */
8256 if (name[1] == 'n' &&
8265 return -KEY_endnetent;
8271 if (name[1] == 'e' &&
8280 return -KEY_getnetent;
8286 if (name[1] == 'o' &&
8295 return -KEY_localtime;
8301 if (name[1] == 'r' &&
8310 return KEY_prototype;
8316 if (name[1] == 'u' &&
8325 return -KEY_quotemeta;
8331 if (name[1] == 'e' &&
8340 return -KEY_rewinddir;
8346 if (name[1] == 'e' &&
8355 return -KEY_setnetent;
8361 if (name[1] == 'a' &&
8370 return -KEY_wantarray;
8379 case 10: /* 9 tokens of length 10 */
8383 if (name[1] == 'n' &&
8389 if (name[4] == 'o' &&
8396 return -KEY_endhostent;
8402 if (name[4] == 'e' &&
8409 return -KEY_endservent;
8422 if (name[1] == 'e' &&
8428 if (name[4] == 'o' &&
8435 return -KEY_gethostent;
8444 if (name[5] == 'r' &&
8450 return -KEY_getservent;
8456 if (name[5] == 'c' &&
8462 return -KEY_getsockopt;
8487 if (name[4] == 'o' &&
8494 return -KEY_sethostent;
8503 if (name[5] == 'r' &&
8509 return -KEY_setservent;
8515 if (name[5] == 'c' &&
8521 return -KEY_setsockopt;
8538 if (name[2] == 'c' &&
8547 return -KEY_socketpair;
8560 case 11: /* 8 tokens of length 11 */
8564 if (name[1] == '_' &&
8575 return -KEY___PACKAGE__;
8581 if (name[1] == 'n' &&
8592 return -KEY_endprotoent;
8598 if (name[1] == 'e' &&
8607 if (name[5] == 'e' &&
8614 return -KEY_getpeername;
8623 if (name[6] == 'o' &&
8629 return -KEY_getpriority;
8635 if (name[6] == 't' &&
8641 return -KEY_getprotoent;
8655 if (name[4] == 'o' &&
8663 return -KEY_getsockname;
8676 if (name[1] == 'e' &&
8684 if (name[6] == 'o' &&
8690 return -KEY_setpriority;
8696 if (name[6] == 't' &&
8702 return -KEY_setprotoent;
8718 case 12: /* 2 tokens of length 12 */
8719 if (name[0] == 'g' &&
8731 if (name[9] == 'd' &&
8734 { /* getnetbyaddr */
8735 return -KEY_getnetbyaddr;
8741 if (name[9] == 'a' &&
8744 { /* getnetbyname */
8745 return -KEY_getnetbyname;
8757 case 13: /* 4 tokens of length 13 */
8758 if (name[0] == 'g' &&
8765 if (name[4] == 'o' &&
8774 if (name[10] == 'd' &&
8777 { /* gethostbyaddr */
8778 return -KEY_gethostbyaddr;
8784 if (name[10] == 'a' &&
8787 { /* gethostbyname */
8788 return -KEY_gethostbyname;
8801 if (name[4] == 'e' &&
8810 if (name[10] == 'a' &&
8813 { /* getservbyname */
8814 return -KEY_getservbyname;
8820 if (name[10] == 'o' &&
8823 { /* getservbyport */
8824 return -KEY_getservbyport;
8843 case 14: /* 1 tokens of length 14 */
8844 if (name[0] == 'g' &&
8858 { /* getprotobyname */
8859 return -KEY_getprotobyname;
8864 case 16: /* 1 tokens of length 16 */
8865 if (name[0] == 'g' &&
8881 { /* getprotobynumber */
8882 return -KEY_getprotobynumber;
8896 S_checkcomma(pTHX_ register char *s, char *name, const char *what)
8900 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
8901 if (ckWARN(WARN_SYNTAX)) {
8903 for (w = s+2; *w && level; w++) {
8910 for (; *w && isSPACE(*w); w++) ;
8911 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
8912 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
8913 "%s (...) interpreted as function",name);
8916 while (s < PL_bufend && isSPACE(*s))
8920 while (s < PL_bufend && isSPACE(*s))
8922 if (isIDFIRST_lazy_if(s,UTF)) {
8924 while (isALNUM_lazy_if(s,UTF))
8926 while (s < PL_bufend && isSPACE(*s))
8931 kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
8935 Perl_croak(aTHX_ "No comma allowed after %s", what);
8940 /* Either returns sv, or mortalizes sv and returns a new SV*.
8941 Best used as sv=new_constant(..., sv, ...).
8942 If s, pv are NULL, calls subroutine with one argument,
8943 and type is used with error messages only. */
8946 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
8950 HV *table = GvHV(PL_hintgv); /* ^H */
8954 const char *why1, *why2, *why3;
8956 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
8959 why2 = strEQ(key,"charnames")
8960 ? "(possibly a missing \"use charnames ...\")"
8962 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
8963 (type ? type: "undef"), why2);
8965 /* This is convoluted and evil ("goto considered harmful")
8966 * but I do not understand the intricacies of all the different
8967 * failure modes of %^H in here. The goal here is to make
8968 * the most probable error message user-friendly. --jhi */
8973 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
8974 (type ? type: "undef"), why1, why2, why3);
8976 yyerror(SvPVX(msg));
8980 cvp = hv_fetch(table, key, strlen(key), FALSE);
8981 if (!cvp || !SvOK(*cvp)) {
8984 why3 = "} is not defined";
8987 sv_2mortal(sv); /* Parent created it permanently */
8990 pv = sv_2mortal(newSVpvn(s, len));
8992 typesv = sv_2mortal(newSVpv(type, 0));
8994 typesv = &PL_sv_undef;
8996 PUSHSTACKi(PERLSI_OVERLOAD);
9008 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
9012 /* Check the eval first */
9013 if (!PL_in_eval && SvTRUE(ERRSV)) {
9015 sv_catpv(ERRSV, "Propagated");
9016 yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */
9018 res = SvREFCNT_inc(sv);
9022 (void)SvREFCNT_inc(res);
9031 why1 = "Call to &{$^H{";
9033 why3 = "}} did not return a defined value";
9041 /* Returns a NUL terminated string, with the length of the string written to
9045 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
9047 register char *d = dest;
9048 register char *e = d + destlen - 3; /* two-character token, ending NUL */
9051 Perl_croak(aTHX_ ident_too_long);
9052 if (isALNUM(*s)) /* UTF handled below */
9054 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
9059 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
9063 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9064 char *t = s + UTF8SKIP(s);
9065 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9067 if (d + (t - s) > e)
9068 Perl_croak(aTHX_ ident_too_long);
9069 Copy(s, d, t - s, char);
9082 S_scan_ident(pTHX_ register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni)
9092 e = d + destlen - 3; /* two-character token, ending NUL */
9094 while (isDIGIT(*s)) {
9096 Perl_croak(aTHX_ ident_too_long);
9103 Perl_croak(aTHX_ ident_too_long);
9104 if (isALNUM(*s)) /* UTF handled below */
9106 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
9111 else if (*s == ':' && s[1] == ':') {
9115 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9116 char *t = s + UTF8SKIP(s);
9117 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9119 if (d + (t - s) > e)
9120 Perl_croak(aTHX_ ident_too_long);
9121 Copy(s, d, t - s, char);
9132 if (PL_lex_state != LEX_NORMAL)
9133 PL_lex_state = LEX_INTERPENDMAYBE;
9136 if (*s == '$' && s[1] &&
9137 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
9150 if (*d == '^' && *s && isCONTROLVAR(*s)) {
9155 if (isSPACE(s[-1])) {
9158 if (!SPACE_OR_TAB(ch)) {
9164 if (isIDFIRST_lazy_if(d,UTF)) {
9168 while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') {
9170 while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e))
9173 Copy(s, d, e - s, char);
9178 while ((isALNUM(*s) || *s == ':') && d < e)
9181 Perl_croak(aTHX_ ident_too_long);
9184 while (s < send && SPACE_OR_TAB(*s)) s++;
9185 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
9186 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
9187 const char *brack = *s == '[' ? "[...]" : "{...}";
9188 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9189 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
9190 funny, dest, brack, funny, dest, brack);
9193 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
9197 /* Handle extended ${^Foo} variables
9198 * 1999-02-27 mjd-perl-patch@plover.com */
9199 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
9203 while (isALNUM(*s) && d < e) {
9207 Perl_croak(aTHX_ ident_too_long);
9212 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
9213 PL_lex_state = LEX_INTERPEND;
9218 if (PL_lex_state == LEX_NORMAL) {
9219 if (ckWARN(WARN_AMBIGUOUS) &&
9220 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
9222 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9223 "Ambiguous use of %c{%s} resolved to %c%s",
9224 funny, dest, funny, dest);
9229 s = bracket; /* let the parser handle it */
9233 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
9234 PL_lex_state = LEX_INTERPEND;
9239 Perl_pmflag(pTHX_ U32* pmfl, int ch)
9244 *pmfl |= PMf_GLOBAL;
9246 *pmfl |= PMf_CONTINUE;
9250 *pmfl |= PMf_MULTILINE;
9252 *pmfl |= PMf_SINGLELINE;
9254 *pmfl |= PMf_EXTENDED;
9258 S_scan_pat(pTHX_ char *start, I32 type)
9263 s = scan_str(start,FALSE,FALSE);
9265 Perl_croak(aTHX_ "Search pattern not terminated");
9267 pm = (PMOP*)newPMOP(type, 0);
9268 if (PL_multi_open == '?')
9269 pm->op_pmflags |= PMf_ONCE;
9271 while (*s && strchr("iomsx", *s))
9272 pmflag(&pm->op_pmflags,*s++);
9275 while (*s && strchr("iogcmsx", *s))
9276 pmflag(&pm->op_pmflags,*s++);
9278 /* issue a warning if /c is specified,but /g is not */
9279 if (ckWARN(WARN_REGEXP) &&
9280 (pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
9282 Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_without_g);
9285 pm->op_pmpermflags = pm->op_pmflags;
9287 PL_lex_op = (OP*)pm;
9288 yylval.ival = OP_MATCH;
9293 S_scan_subst(pTHX_ char *start)
9301 yylval.ival = OP_NULL;
9303 s = scan_str(start,FALSE,FALSE);
9306 Perl_croak(aTHX_ "Substitution pattern not terminated");
9308 if (s[-1] == PL_multi_open)
9311 first_start = PL_multi_start;
9312 s = scan_str(s,FALSE,FALSE);
9315 SvREFCNT_dec(PL_lex_stuff);
9316 PL_lex_stuff = Nullsv;
9318 Perl_croak(aTHX_ "Substitution replacement not terminated");
9320 PL_multi_start = first_start; /* so whole substitution is taken together */
9322 pm = (PMOP*)newPMOP(OP_SUBST, 0);
9328 else if (strchr("iogcmsx", *s))
9329 pmflag(&pm->op_pmflags,*s++);
9334 /* /c is not meaningful with s/// */
9335 if (ckWARN(WARN_REGEXP) && (pm->op_pmflags & PMf_CONTINUE))
9337 Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_in_subst);
9342 PL_sublex_info.super_bufptr = s;
9343 PL_sublex_info.super_bufend = PL_bufend;
9345 pm->op_pmflags |= PMf_EVAL;
9346 repl = newSVpvn("",0);
9348 sv_catpv(repl, es ? "eval " : "do ");
9349 sv_catpvn(repl, "{ ", 2);
9350 sv_catsv(repl, PL_lex_repl);
9351 sv_catpvn(repl, " };", 2);
9353 SvREFCNT_dec(PL_lex_repl);
9357 pm->op_pmpermflags = pm->op_pmflags;
9358 PL_lex_op = (OP*)pm;
9359 yylval.ival = OP_SUBST;
9364 S_scan_trans(pTHX_ char *start)
9373 yylval.ival = OP_NULL;
9375 s = scan_str(start,FALSE,FALSE);
9377 Perl_croak(aTHX_ "Transliteration pattern not terminated");
9378 if (s[-1] == PL_multi_open)
9381 s = scan_str(s,FALSE,FALSE);
9384 SvREFCNT_dec(PL_lex_stuff);
9385 PL_lex_stuff = Nullsv;
9387 Perl_croak(aTHX_ "Transliteration replacement not terminated");
9390 complement = del = squash = 0;
9394 complement = OPpTRANS_COMPLEMENT;
9397 del = OPpTRANS_DELETE;
9400 squash = OPpTRANS_SQUASH;
9409 New(803, tbl, complement&&!del?258:256, short);
9410 o = newPVOP(OP_TRANS, 0, (char*)tbl);
9411 o->op_private &= ~OPpTRANS_ALL;
9412 o->op_private |= del|squash|complement|
9413 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
9414 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
9417 yylval.ival = OP_TRANS;
9422 S_scan_heredoc(pTHX_ register char *s)
9425 I32 op_type = OP_SCALAR;
9429 const char newline[] = "\n";
9430 const char *found_newline;
9434 int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
9438 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
9441 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
9442 if (*peek == '`' || *peek == '\'' || *peek =='"') {
9445 s = delimcpy(d, e, s, PL_bufend, term, &len);
9455 if (!isALNUM_lazy_if(s,UTF))
9456 deprecate_old("bare << to mean <<\"\"");
9457 for (; isALNUM_lazy_if(s,UTF); s++) {
9462 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
9463 Perl_croak(aTHX_ "Delimiter for here document is too long");
9466 len = d - PL_tokenbuf;
9467 #ifndef PERL_STRICT_CR
9468 d = strchr(s, '\r');
9472 while (s < PL_bufend) {
9478 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
9487 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
9491 if ( outer || !(found_newline = ninstr(s,PL_bufend,newline,newline+1)) ) {
9492 herewas = newSVpvn(s,PL_bufend-s);
9496 herewas = newSVpvn(s,found_newline-s);
9498 s += SvCUR(herewas);
9500 tmpstr = NEWSV(87,79);
9501 sv_upgrade(tmpstr, SVt_PVIV);
9504 SvIV_set(tmpstr, -1);
9506 else if (term == '`') {
9507 op_type = OP_BACKTICK;
9508 SvIV_set(tmpstr, '\\');
9512 PL_multi_start = CopLINE(PL_curcop);
9513 PL_multi_open = PL_multi_close = '<';
9514 term = *PL_tokenbuf;
9515 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
9516 char *bufptr = PL_sublex_info.super_bufptr;
9517 char *bufend = PL_sublex_info.super_bufend;
9518 char *olds = s - SvCUR(herewas);
9519 s = strchr(bufptr, '\n');
9523 while (s < bufend &&
9524 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9526 CopLINE_inc(PL_curcop);
9529 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9530 missingterm(PL_tokenbuf);
9532 sv_setpvn(herewas,bufptr,d-bufptr+1);
9533 sv_setpvn(tmpstr,d+1,s-d);
9535 sv_catpvn(herewas,s,bufend-s);
9536 Copy(SvPVX(herewas),bufptr,SvCUR(herewas) + 1,char);
9543 while (s < PL_bufend &&
9544 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9546 CopLINE_inc(PL_curcop);
9548 if (s >= PL_bufend) {
9549 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9550 missingterm(PL_tokenbuf);
9552 sv_setpvn(tmpstr,d+1,s-d);
9554 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
9556 sv_catpvn(herewas,s,PL_bufend-s);
9557 sv_setsv(PL_linestr,herewas);
9558 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
9559 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9560 PL_last_lop = PL_last_uni = Nullch;
9563 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
9564 while (s >= PL_bufend) { /* multiple line string? */
9566 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
9567 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9568 missingterm(PL_tokenbuf);
9570 CopLINE_inc(PL_curcop);
9571 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9572 PL_last_lop = PL_last_uni = Nullch;
9573 #ifndef PERL_STRICT_CR
9574 if (PL_bufend - PL_linestart >= 2) {
9575 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
9576 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
9578 PL_bufend[-2] = '\n';
9580 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
9582 else if (PL_bufend[-1] == '\r')
9583 PL_bufend[-1] = '\n';
9585 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
9586 PL_bufend[-1] = '\n';
9588 if (PERLDB_LINE && PL_curstash != PL_debstash) {
9589 SV *sv = NEWSV(88,0);
9591 sv_upgrade(sv, SVt_PVMG);
9592 sv_setsv(sv,PL_linestr);
9595 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
9597 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
9598 STRLEN off = PL_bufend - 1 - SvPVX(PL_linestr);
9599 *(SvPVX(PL_linestr) + off ) = ' ';
9600 sv_catsv(PL_linestr,herewas);
9601 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9602 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
9606 sv_catsv(tmpstr,PL_linestr);
9611 PL_multi_end = CopLINE(PL_curcop);
9612 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
9613 SvPV_shrink_to_cur(tmpstr);
9615 SvREFCNT_dec(herewas);
9617 if (UTF && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr)))
9619 else if (PL_encoding)
9620 sv_recode_to_utf8(tmpstr, PL_encoding);
9622 PL_lex_stuff = tmpstr;
9623 yylval.ival = op_type;
9628 takes: current position in input buffer
9629 returns: new position in input buffer
9630 side-effects: yylval and lex_op are set.
9635 <FH> read from filehandle
9636 <pkg::FH> read from package qualified filehandle
9637 <pkg'FH> read from package qualified filehandle
9638 <$fh> read from filehandle in $fh
9644 S_scan_inputsymbol(pTHX_ char *start)
9646 register char *s = start; /* current position in buffer */
9652 d = PL_tokenbuf; /* start of temp holding space */
9653 e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
9654 end = strchr(s, '\n');
9657 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
9659 /* die if we didn't have space for the contents of the <>,
9660 or if it didn't end, or if we see a newline
9663 if (len >= sizeof PL_tokenbuf)
9664 Perl_croak(aTHX_ "Excessively long <> operator");
9666 Perl_croak(aTHX_ "Unterminated <> operator");
9671 Remember, only scalar variables are interpreted as filehandles by
9672 this code. Anything more complex (e.g., <$fh{$num}>) will be
9673 treated as a glob() call.
9674 This code makes use of the fact that except for the $ at the front,
9675 a scalar variable and a filehandle look the same.
9677 if (*d == '$' && d[1]) d++;
9679 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
9680 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
9683 /* If we've tried to read what we allow filehandles to look like, and
9684 there's still text left, then it must be a glob() and not a getline.
9685 Use scan_str to pull out the stuff between the <> and treat it
9686 as nothing more than a string.
9689 if (d - PL_tokenbuf != len) {
9690 yylval.ival = OP_GLOB;
9692 s = scan_str(start,FALSE,FALSE);
9694 Perl_croak(aTHX_ "Glob not terminated");
9698 bool readline_overriden = FALSE;
9699 GV *gv_readline = Nullgv;
9701 /* we're in a filehandle read situation */
9704 /* turn <> into <ARGV> */
9706 Copy("ARGV",d,5,char);
9708 /* Check whether readline() is overriden */
9709 if (((gv_readline = gv_fetchpv("readline", FALSE, SVt_PVCV))
9710 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
9712 ((gvp = (GV**)hv_fetch(PL_globalstash, "readline", 8, FALSE))
9713 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
9714 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
9715 readline_overriden = TRUE;
9717 /* if <$fh>, create the ops to turn the variable into a
9723 /* try to find it in the pad for this block, otherwise find
9724 add symbol table ops
9726 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
9727 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
9728 SV *sym = sv_2mortal(
9729 newSVpv(HvNAME(PAD_COMPNAME_OURSTASH(tmp)),0));
9730 sv_catpvn(sym, "::", 2);
9736 OP *o = newOP(OP_PADSV, 0);
9738 PL_lex_op = readline_overriden
9739 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9740 append_elem(OP_LIST, o,
9741 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
9742 : (OP*)newUNOP(OP_READLINE, 0, o);
9751 ? (GV_ADDMULTI | GV_ADDINEVAL)
9754 PL_lex_op = readline_overriden
9755 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9756 append_elem(OP_LIST,
9757 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
9758 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9759 : (OP*)newUNOP(OP_READLINE, 0,
9760 newUNOP(OP_RV2SV, 0,
9761 newGVOP(OP_GV, 0, gv)));
9763 if (!readline_overriden)
9764 PL_lex_op->op_flags |= OPf_SPECIAL;
9765 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
9766 yylval.ival = OP_NULL;
9769 /* If it's none of the above, it must be a literal filehandle
9770 (<Foo::BAR> or <FOO>) so build a simple readline OP */
9772 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
9773 PL_lex_op = readline_overriden
9774 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9775 append_elem(OP_LIST,
9776 newGVOP(OP_GV, 0, gv),
9777 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9778 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
9779 yylval.ival = OP_NULL;
9788 takes: start position in buffer
9789 keep_quoted preserve \ on the embedded delimiter(s)
9790 keep_delims preserve the delimiters around the string
9791 returns: position to continue reading from buffer
9792 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
9793 updates the read buffer.
9795 This subroutine pulls a string out of the input. It is called for:
9796 q single quotes q(literal text)
9797 ' single quotes 'literal text'
9798 qq double quotes qq(interpolate $here please)
9799 " double quotes "interpolate $here please"
9800 qx backticks qx(/bin/ls -l)
9801 ` backticks `/bin/ls -l`
9802 qw quote words @EXPORT_OK = qw( func() $spam )
9803 m// regexp match m/this/
9804 s/// regexp substitute s/this/that/
9805 tr/// string transliterate tr/this/that/
9806 y/// string transliterate y/this/that/
9807 ($*@) sub prototypes sub foo ($)
9808 (stuff) sub attr parameters sub foo : attr(stuff)
9809 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
9811 In most of these cases (all but <>, patterns and transliterate)
9812 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
9813 calls scan_str(). s/// makes yylex() call scan_subst() which calls
9814 scan_str(). tr/// and y/// make yylex() call scan_trans() which
9817 It skips whitespace before the string starts, and treats the first
9818 character as the delimiter. If the delimiter is one of ([{< then
9819 the corresponding "close" character )]}> is used as the closing
9820 delimiter. It allows quoting of delimiters, and if the string has
9821 balanced delimiters ([{<>}]) it allows nesting.
9823 On success, the SV with the resulting string is put into lex_stuff or,
9824 if that is already non-NULL, into lex_repl. The second case occurs only
9825 when parsing the RHS of the special constructs s/// and tr/// (y///).
9826 For convenience, the terminating delimiter character is stuffed into
9831 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
9833 SV *sv; /* scalar value: string */
9834 char *tmps; /* temp string, used for delimiter matching */
9835 register char *s = start; /* current position in the buffer */
9836 register char term; /* terminating character */
9837 register char *to; /* current position in the sv's data */
9838 I32 brackets = 1; /* bracket nesting level */
9839 bool has_utf8 = FALSE; /* is there any utf8 content? */
9840 I32 termcode; /* terminating char. code */
9841 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
9842 STRLEN termlen; /* length of terminating string */
9843 char *last = NULL; /* last position for nesting bracket */
9845 /* skip space before the delimiter */
9849 /* mark where we are, in case we need to report errors */
9852 /* after skipping whitespace, the next character is the terminator */
9855 termcode = termstr[0] = term;
9859 termcode = utf8_to_uvchr((U8*)s, &termlen);
9860 Copy(s, termstr, termlen, U8);
9861 if (!UTF8_IS_INVARIANT(term))
9865 /* mark where we are */
9866 PL_multi_start = CopLINE(PL_curcop);
9867 PL_multi_open = term;
9869 /* find corresponding closing delimiter */
9870 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
9871 termcode = termstr[0] = term = tmps[5];
9873 PL_multi_close = term;
9875 /* create a new SV to hold the contents. 87 is leak category, I'm
9876 assuming. 79 is the SV's initial length. What a random number. */
9878 sv_upgrade(sv, SVt_PVIV);
9879 SvIV_set(sv, termcode);
9880 (void)SvPOK_only(sv); /* validate pointer */
9882 /* move past delimiter and try to read a complete string */
9884 sv_catpvn(sv, s, termlen);
9887 if (PL_encoding && !UTF) {
9891 int offset = s - SvPVX(PL_linestr);
9892 bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
9893 &offset, (char*)termstr, termlen);
9894 char *ns = SvPVX(PL_linestr) + offset;
9895 char *svlast = SvEND(sv) - 1;
9897 for (; s < ns; s++) {
9898 if (*s == '\n' && !PL_rsfp)
9899 CopLINE_inc(PL_curcop);
9902 goto read_more_line;
9904 /* handle quoted delimiters */
9905 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
9907 for (t = svlast-2; t >= SvPVX(sv) && *t == '\\';)
9909 if ((svlast-1 - t) % 2) {
9913 SvCUR_set(sv, SvCUR(sv) - 1);
9918 if (PL_multi_open == PL_multi_close) {
9925 for (w = t = last; t < svlast; w++, t++) {
9926 /* At here, all closes are "was quoted" one,
9927 so we don't check PL_multi_close. */
9929 if (!keep_quoted && *(t+1) == PL_multi_open)
9934 else if (*t == PL_multi_open)
9942 SvCUR_set(sv, w - SvPVX(sv));
9945 if (--brackets <= 0)
9951 SvCUR_set(sv, SvCUR(sv) - 1);
9957 /* extend sv if need be */
9958 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
9959 /* set 'to' to the next character in the sv's string */
9960 to = SvPVX(sv)+SvCUR(sv);
9962 /* if open delimiter is the close delimiter read unbridle */
9963 if (PL_multi_open == PL_multi_close) {
9964 for (; s < PL_bufend; s++,to++) {
9965 /* embedded newlines increment the current line number */
9966 if (*s == '\n' && !PL_rsfp)
9967 CopLINE_inc(PL_curcop);
9968 /* handle quoted delimiters */
9969 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
9970 if (!keep_quoted && s[1] == term)
9972 /* any other quotes are simply copied straight through */
9976 /* terminate when run out of buffer (the for() condition), or
9977 have found the terminator */
9978 else if (*s == term) {
9981 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
9984 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
9990 /* if the terminator isn't the same as the start character (e.g.,
9991 matched brackets), we have to allow more in the quoting, and
9992 be prepared for nested brackets.
9995 /* read until we run out of string, or we find the terminator */
9996 for (; s < PL_bufend; s++,to++) {
9997 /* embedded newlines increment the line count */
9998 if (*s == '\n' && !PL_rsfp)
9999 CopLINE_inc(PL_curcop);
10000 /* backslashes can escape the open or closing characters */
10001 if (*s == '\\' && s+1 < PL_bufend) {
10002 if (!keep_quoted &&
10003 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
10008 /* allow nested opens and closes */
10009 else if (*s == PL_multi_close && --brackets <= 0)
10011 else if (*s == PL_multi_open)
10013 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
10018 /* terminate the copied string and update the sv's end-of-string */
10020 SvCUR_set(sv, to - SvPVX(sv));
10023 * this next chunk reads more into the buffer if we're not done yet
10027 break; /* handle case where we are done yet :-) */
10029 #ifndef PERL_STRICT_CR
10030 if (to - SvPVX(sv) >= 2) {
10031 if ((to[-2] == '\r' && to[-1] == '\n') ||
10032 (to[-2] == '\n' && to[-1] == '\r'))
10036 SvCUR_set(sv, to - SvPVX(sv));
10038 else if (to[-1] == '\r')
10041 else if (to - SvPVX(sv) == 1 && to[-1] == '\r')
10046 /* if we're out of file, or a read fails, bail and reset the current
10047 line marker so we can report where the unterminated string began
10050 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
10052 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10055 /* we read a line, so increment our line counter */
10056 CopLINE_inc(PL_curcop);
10058 /* update debugger info */
10059 if (PERLDB_LINE && PL_curstash != PL_debstash) {
10060 SV *sv = NEWSV(88,0);
10062 sv_upgrade(sv, SVt_PVMG);
10063 sv_setsv(sv,PL_linestr);
10064 (void)SvIOK_on(sv);
10066 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
10069 /* having changed the buffer, we must update PL_bufend */
10070 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10071 PL_last_lop = PL_last_uni = Nullch;
10074 /* at this point, we have successfully read the delimited string */
10076 if (!PL_encoding || UTF) {
10078 sv_catpvn(sv, s, termlen);
10081 if (has_utf8 || PL_encoding)
10084 PL_multi_end = CopLINE(PL_curcop);
10086 /* if we allocated too much space, give some back */
10087 if (SvCUR(sv) + 5 < SvLEN(sv)) {
10088 SvLEN_set(sv, SvCUR(sv) + 1);
10089 SvPV_renew(sv, SvLEN(sv));
10092 /* decide whether this is the first or second quoted string we've read
10105 takes: pointer to position in buffer
10106 returns: pointer to new position in buffer
10107 side-effects: builds ops for the constant in yylval.op
10109 Read a number in any of the formats that Perl accepts:
10111 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
10112 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
10115 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
10117 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
10120 If it reads a number without a decimal point or an exponent, it will
10121 try converting the number to an integer and see if it can do so
10122 without loss of precision.
10126 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
10128 register const char *s = start; /* current position in buffer */
10129 register char *d; /* destination in temp buffer */
10130 register char *e; /* end of temp buffer */
10131 NV nv; /* number read, as a double */
10132 SV *sv = Nullsv; /* place to put the converted number */
10133 bool floatit; /* boolean: int or float? */
10134 const char *lastub = 0; /* position of last underbar */
10135 static char const number_too_long[] = "Number too long";
10137 /* We use the first character to decide what type of number this is */
10141 Perl_croak(aTHX_ "panic: scan_num");
10143 /* if it starts with a 0, it could be an octal number, a decimal in
10144 0.13 disguise, or a hexadecimal number, or a binary number. */
10148 u holds the "number so far"
10149 shift the power of 2 of the base
10150 (hex == 4, octal == 3, binary == 1)
10151 overflowed was the number more than we can hold?
10153 Shift is used when we add a digit. It also serves as an "are
10154 we in octal/hex/binary?" indicator to disallow hex characters
10155 when in octal mode.
10160 bool overflowed = FALSE;
10161 bool just_zero = TRUE; /* just plain 0 or binary number? */
10162 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
10163 static const char* const bases[5] =
10164 { "", "binary", "", "octal", "hexadecimal" };
10165 static const char* const Bases[5] =
10166 { "", "Binary", "", "Octal", "Hexadecimal" };
10167 static const char* const maxima[5] =
10169 "0b11111111111111111111111111111111",
10173 const char *base, *Base, *max;
10175 /* check for hex */
10180 } else if (s[1] == 'b') {
10185 /* check for a decimal in disguise */
10186 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
10188 /* so it must be octal */
10195 if (ckWARN(WARN_SYNTAX))
10196 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10197 "Misplaced _ in number");
10201 base = bases[shift];
10202 Base = Bases[shift];
10203 max = maxima[shift];
10205 /* read the rest of the number */
10207 /* x is used in the overflow test,
10208 b is the digit we're adding on. */
10213 /* if we don't mention it, we're done */
10217 /* _ are ignored -- but warned about if consecutive */
10219 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10220 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10221 "Misplaced _ in number");
10225 /* 8 and 9 are not octal */
10226 case '8': case '9':
10228 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
10232 case '2': case '3': case '4':
10233 case '5': case '6': case '7':
10235 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
10238 case '0': case '1':
10239 b = *s++ & 15; /* ASCII digit -> value of digit */
10243 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
10244 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
10245 /* make sure they said 0x */
10248 b = (*s++ & 7) + 9;
10250 /* Prepare to put the digit we have onto the end
10251 of the number so far. We check for overflows.
10257 x = u << shift; /* make room for the digit */
10259 if ((x >> shift) != u
10260 && !(PL_hints & HINT_NEW_BINARY)) {
10263 if (ckWARN_d(WARN_OVERFLOW))
10264 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
10265 "Integer overflow in %s number",
10268 u = x | b; /* add the digit to the end */
10271 n *= nvshift[shift];
10272 /* If an NV has not enough bits in its
10273 * mantissa to represent an UV this summing of
10274 * small low-order numbers is a waste of time
10275 * (because the NV cannot preserve the
10276 * low-order bits anyway): we could just
10277 * remember when did we overflow and in the
10278 * end just multiply n by the right
10286 /* if we get here, we had success: make a scalar value from
10291 /* final misplaced underbar check */
10292 if (s[-1] == '_') {
10293 if (ckWARN(WARN_SYNTAX))
10294 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10299 if (ckWARN(WARN_PORTABLE) && n > 4294967295.0)
10300 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10301 "%s number > %s non-portable",
10307 if (ckWARN(WARN_PORTABLE) && u > 0xffffffff)
10308 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10309 "%s number > %s non-portable",
10314 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
10315 sv = new_constant(start, s - start, "integer",
10317 else if (PL_hints & HINT_NEW_BINARY)
10318 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
10323 handle decimal numbers.
10324 we're also sent here when we read a 0 as the first digit
10326 case '1': case '2': case '3': case '4': case '5':
10327 case '6': case '7': case '8': case '9': case '.':
10330 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
10333 /* read next group of digits and _ and copy into d */
10334 while (isDIGIT(*s) || *s == '_') {
10335 /* skip underscores, checking for misplaced ones
10339 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10340 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10341 "Misplaced _ in number");
10345 /* check for end of fixed-length buffer */
10347 Perl_croak(aTHX_ number_too_long);
10348 /* if we're ok, copy the character */
10353 /* final misplaced underbar check */
10354 if (lastub && s == lastub + 1) {
10355 if (ckWARN(WARN_SYNTAX))
10356 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10359 /* read a decimal portion if there is one. avoid
10360 3..5 being interpreted as the number 3. followed
10363 if (*s == '.' && s[1] != '.') {
10368 if (ckWARN(WARN_SYNTAX))
10369 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10370 "Misplaced _ in number");
10374 /* copy, ignoring underbars, until we run out of digits.
10376 for (; isDIGIT(*s) || *s == '_'; s++) {
10377 /* fixed length buffer check */
10379 Perl_croak(aTHX_ number_too_long);
10381 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
10382 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10383 "Misplaced _ in number");
10389 /* fractional part ending in underbar? */
10390 if (s[-1] == '_') {
10391 if (ckWARN(WARN_SYNTAX))
10392 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10393 "Misplaced _ in number");
10395 if (*s == '.' && isDIGIT(s[1])) {
10396 /* oops, it's really a v-string, but without the "v" */
10402 /* read exponent part, if present */
10403 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
10407 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
10408 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
10410 /* stray preinitial _ */
10412 if (ckWARN(WARN_SYNTAX))
10413 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10414 "Misplaced _ in number");
10418 /* allow positive or negative exponent */
10419 if (*s == '+' || *s == '-')
10422 /* stray initial _ */
10424 if (ckWARN(WARN_SYNTAX))
10425 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10426 "Misplaced _ in number");
10430 /* read digits of exponent */
10431 while (isDIGIT(*s) || *s == '_') {
10434 Perl_croak(aTHX_ number_too_long);
10438 if (ckWARN(WARN_SYNTAX) &&
10439 ((lastub && s == lastub + 1) ||
10440 (!isDIGIT(s[1]) && s[1] != '_')))
10441 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10442 "Misplaced _ in number");
10449 /* make an sv from the string */
10453 We try to do an integer conversion first if no characters
10454 indicating "float" have been found.
10459 int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
10461 if (flags == IS_NUMBER_IN_UV) {
10463 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
10466 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
10467 if (uv <= (UV) IV_MIN)
10468 sv_setiv(sv, -(IV)uv);
10475 /* terminate the string */
10477 nv = Atof(PL_tokenbuf);
10481 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
10482 (PL_hints & HINT_NEW_INTEGER) )
10483 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
10484 (floatit ? "float" : "integer"),
10488 /* if it starts with a v, it could be a v-string */
10491 sv = NEWSV(92,5); /* preallocate storage space */
10492 s = scan_vstring(s,sv);
10496 /* make the op for the constant and return */
10499 lvalp->opval = newSVOP(OP_CONST, 0, sv);
10501 lvalp->opval = Nullop;
10507 S_scan_formline(pTHX_ register char *s)
10509 register char *eol;
10511 SV *stuff = newSVpvn("",0);
10512 bool needargs = FALSE;
10513 bool eofmt = FALSE;
10515 while (!needargs) {
10518 #ifdef PERL_STRICT_CR
10519 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
10521 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
10523 if (*t == '\n' || t == PL_bufend) {
10528 if (PL_in_eval && !PL_rsfp) {
10529 eol = (char *) memchr(s,'\n',PL_bufend-s);
10534 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10536 for (t = s; t < eol; t++) {
10537 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
10539 goto enough; /* ~~ must be first line in formline */
10541 if (*t == '@' || *t == '^')
10545 sv_catpvn(stuff, s, eol-s);
10546 #ifndef PERL_STRICT_CR
10547 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
10548 char *end = SvPVX(stuff) + SvCUR(stuff);
10551 SvCUR_set(stuff, SvCUR(stuff) - 1);
10560 s = filter_gets(PL_linestr, PL_rsfp, 0);
10561 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
10562 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
10563 PL_last_lop = PL_last_uni = Nullch;
10572 if (SvCUR(stuff)) {
10575 PL_lex_state = LEX_NORMAL;
10576 PL_nextval[PL_nexttoke].ival = 0;
10580 PL_lex_state = LEX_FORMLINE;
10582 if (UTF && is_utf8_string((U8*)SvPVX(stuff), SvCUR(stuff)))
10584 else if (PL_encoding)
10585 sv_recode_to_utf8(stuff, PL_encoding);
10587 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
10589 PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
10593 SvREFCNT_dec(stuff);
10595 PL_lex_formbrack = 0;
10606 PL_cshlen = strlen(PL_cshname);
10611 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
10613 I32 oldsavestack_ix = PL_savestack_ix;
10614 CV* outsidecv = PL_compcv;
10617 assert(SvTYPE(PL_compcv) == SVt_PVCV);
10619 SAVEI32(PL_subline);
10620 save_item(PL_subname);
10621 SAVESPTR(PL_compcv);
10623 PL_compcv = (CV*)NEWSV(1104,0);
10624 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
10625 CvFLAGS(PL_compcv) |= flags;
10627 PL_subline = CopLINE(PL_curcop);
10628 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
10629 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
10630 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
10632 return oldsavestack_ix;
10636 #pragma segment Perl_yylex
10639 Perl_yywarn(pTHX_ const char *s)
10641 PL_in_eval |= EVAL_WARNONLY;
10643 PL_in_eval &= ~EVAL_WARNONLY;
10648 Perl_yyerror(pTHX_ const char *s)
10650 const char *where = NULL;
10651 const char *context = NULL;
10655 if (!yychar || (yychar == ';' && !PL_rsfp))
10657 else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 &&
10658 PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) {
10661 The code below is removed for NetWare because it abends/crashes on NetWare
10662 when the script has error such as not having the closing quotes like:
10663 if ($var eq "value)
10664 Checking of white spaces is anyway done in NetWare code.
10667 while (isSPACE(*PL_oldoldbufptr))
10670 context = PL_oldoldbufptr;
10671 contlen = PL_bufptr - PL_oldoldbufptr;
10673 else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 &&
10674 PL_oldbufptr != PL_bufptr) {
10677 The code below is removed for NetWare because it abends/crashes on NetWare
10678 when the script has error such as not having the closing quotes like:
10679 if ($var eq "value)
10680 Checking of white spaces is anyway done in NetWare code.
10683 while (isSPACE(*PL_oldbufptr))
10686 context = PL_oldbufptr;
10687 contlen = PL_bufptr - PL_oldbufptr;
10689 else if (yychar > 255)
10690 where = "next token ???";
10691 else if (yychar == -2) { /* YYEMPTY */
10692 if (PL_lex_state == LEX_NORMAL ||
10693 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
10694 where = "at end of line";
10695 else if (PL_lex_inpat)
10696 where = "within pattern";
10698 where = "within string";
10701 SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
10703 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
10704 else if (isPRINT_LC(yychar))
10705 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
10707 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
10708 where = SvPVX(where_sv);
10710 msg = sv_2mortal(newSVpv(s, 0));
10711 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
10712 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
10714 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
10716 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
10717 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
10718 Perl_sv_catpvf(aTHX_ msg,
10719 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
10720 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
10723 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
10724 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg);
10727 if (PL_error_count >= 10) {
10728 if (PL_in_eval && SvCUR(ERRSV))
10729 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
10730 ERRSV, OutCopFILE(PL_curcop));
10732 Perl_croak(aTHX_ "%s has too many errors.\n",
10733 OutCopFILE(PL_curcop));
10736 PL_in_my_stash = Nullhv;
10740 #pragma segment Main
10744 S_swallow_bom(pTHX_ U8 *s)
10747 slen = SvCUR(PL_linestr);
10750 if (s[1] == 0xFE) {
10751 /* UTF-16 little-endian? (or UTF32-LE?) */
10752 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
10753 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
10754 #ifndef PERL_NO_UTF16_FILTER
10755 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
10758 if (PL_bufend > (char*)s) {
10762 filter_add(utf16rev_textfilter, NULL);
10763 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10764 utf16_to_utf8_reversed(s, news,
10765 PL_bufend - (char*)s - 1,
10767 sv_setpvn(PL_linestr, (const char*)news, newlen);
10769 SvUTF8_on(PL_linestr);
10770 s = (U8*)SvPVX(PL_linestr);
10771 PL_bufend = SvPVX(PL_linestr) + newlen;
10774 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
10779 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
10780 #ifndef PERL_NO_UTF16_FILTER
10781 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
10784 if (PL_bufend > (char *)s) {
10788 filter_add(utf16_textfilter, NULL);
10789 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10790 utf16_to_utf8(s, news,
10791 PL_bufend - (char*)s,
10793 sv_setpvn(PL_linestr, (const char*)news, newlen);
10795 SvUTF8_on(PL_linestr);
10796 s = (U8*)SvPVX(PL_linestr);
10797 PL_bufend = SvPVX(PL_linestr) + newlen;
10800 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
10805 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
10806 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
10807 s += 3; /* UTF-8 */
10813 if (s[2] == 0xFE && s[3] == 0xFF) {
10814 /* UTF-32 big-endian */
10815 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
10818 else if (s[2] == 0 && s[3] != 0) {
10821 * are a good indicator of UTF-16BE. */
10822 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
10827 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
10830 * are a good indicator of UTF-16LE. */
10831 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
10840 * Restore a source filter.
10844 restore_rsfp(pTHX_ void *f)
10846 PerlIO *fp = (PerlIO*)f;
10848 if (PL_rsfp == PerlIO_stdin())
10849 PerlIO_clearerr(PL_rsfp);
10850 else if (PL_rsfp && (PL_rsfp != fp))
10851 PerlIO_close(PL_rsfp);
10855 #ifndef PERL_NO_UTF16_FILTER
10857 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10859 STRLEN old = SvCUR(sv);
10860 I32 count = FILTER_READ(idx+1, sv, maxlen);
10861 DEBUG_P(PerlIO_printf(Perl_debug_log,
10862 "utf16_textfilter(%p): %d %d (%d)\n",
10863 utf16_textfilter, idx, maxlen, (int) count));
10867 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10868 Copy(SvPVX(sv), tmps, old, char);
10869 utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old,
10870 SvCUR(sv) - old, &newlen);
10871 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10873 DEBUG_P({sv_dump(sv);});
10878 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10880 STRLEN old = SvCUR(sv);
10881 I32 count = FILTER_READ(idx+1, sv, maxlen);
10882 DEBUG_P(PerlIO_printf(Perl_debug_log,
10883 "utf16rev_textfilter(%p): %d %d (%d)\n",
10884 utf16rev_textfilter, idx, maxlen, (int) count));
10888 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10889 Copy(SvPVX(sv), tmps, old, char);
10890 utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old,
10891 SvCUR(sv) - old, &newlen);
10892 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10894 DEBUG_P({ sv_dump(sv); });
10900 Returns a pointer to the next character after the parsed
10901 vstring, as well as updating the passed in sv.
10903 Function must be called like
10906 s = scan_vstring(s,sv);
10908 The sv should already be large enough to store the vstring
10909 passed in, for performance reasons.
10914 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
10916 const char *pos = s;
10917 const char *start = s;
10918 if (*pos == 'v') pos++; /* get past 'v' */
10919 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
10921 if ( *pos != '.') {
10922 /* this may not be a v-string if followed by => */
10923 const char *next = pos;
10924 while (next < PL_bufend && isSPACE(*next))
10926 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
10927 /* return string not v-string */
10928 sv_setpvn(sv,(char *)s,pos-s);
10929 return (char *)pos;
10933 if (!isALPHA(*pos)) {
10935 U8 tmpbuf[UTF8_MAXBYTES+1];
10938 if (*s == 'v') s++; /* get past 'v' */
10940 sv_setpvn(sv, "", 0);
10945 /* this is atoi() that tolerates underscores */
10946 const char *end = pos;
10948 while (--end >= s) {
10953 rev += (*end - '0') * mult;
10955 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
10956 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
10957 "Integer overflow in decimal number");
10961 if (rev > 0x7FFFFFFF)
10962 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
10964 /* Append native character for the rev point */
10965 tmpend = uvchr_to_utf8(tmpbuf, rev);
10966 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
10967 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
10969 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
10975 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
10979 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
10987 * c-indentation-style: bsd
10988 * c-basic-offset: 4
10989 * indent-tabs-mode: t
10992 * vim: shiftwidth=4: