3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 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[] = "Identifier too long";
30 static const char commaless_variable_list[] = "comma-less variable list";
32 static void restore_rsfp(pTHX_ void *f);
33 #ifndef PERL_NO_UTF16_FILTER
34 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
35 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
39 # define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
40 # define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
42 # define CURMAD(slot,sv)
43 # define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
46 #define XFAKEBRACK 128
49 #ifdef USE_UTF8_SCRIPTS
50 # define UTF (!IN_BYTES)
52 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
55 /* In variables named $^X, these are the legal values for X.
56 * 1999-02-27 mjd-perl-patch@plover.com */
57 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
59 /* On MacOS, respect nonbreaking spaces */
60 #ifdef MACOS_TRADITIONAL
61 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
63 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
66 /* LEX_* are values for PL_lex_state, the state of the lexer.
67 * They are arranged oddly so that the guard on the switch statement
68 * can get by with a single comparison (if the compiler is smart enough).
71 /* #define LEX_NOTPARSING 11 is done in perl.h. */
73 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
74 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
75 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
76 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
77 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
79 /* at end of code, eg "$x" followed by: */
80 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
81 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
83 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
84 string or after \E, $foo, etc */
85 #define LEX_INTERPCONST 2 /* NOT USED */
86 #define LEX_FORMLINE 1 /* expecting a format line */
87 #define LEX_KNOWNEXT 0 /* next token known; just return it */
91 static const char* const lex_state_names[] = {
110 #include "keywords.h"
112 /* CLINE is a macro that ensures PL_copline has a sane value */
117 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
120 # define SKIPSPACE0(s) skipspace0(s)
121 # define SKIPSPACE1(s) skipspace1(s)
122 # define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
123 # define PEEKSPACE(s) skipspace2(s,0)
125 # define SKIPSPACE0(s) skipspace(s)
126 # define SKIPSPACE1(s) skipspace(s)
127 # define SKIPSPACE2(s,tsv) skipspace(s)
128 # define PEEKSPACE(s) skipspace(s)
132 * Convenience functions to return different tokens and prime the
133 * lexer for the next token. They all take an argument.
135 * TOKEN : generic token (used for '(', DOLSHARP, etc)
136 * OPERATOR : generic operator
137 * AOPERATOR : assignment operator
138 * PREBLOCK : beginning the block after an if, while, foreach, ...
139 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
140 * PREREF : *EXPR where EXPR is not a simple identifier
141 * TERM : expression term
142 * LOOPX : loop exiting command (goto, last, dump, etc)
143 * FTST : file test operator
144 * FUN0 : zero-argument function
145 * FUN1 : not used, except for not, which isn't a UNIOP
146 * BOop : bitwise or or xor
148 * SHop : shift operator
149 * PWop : power operator
150 * PMop : pattern-matching operator
151 * Aop : addition-level operator
152 * Mop : multiplication-level operator
153 * Eop : equality-testing operator
154 * Rop : relational operator <= != gt
156 * Also see LOP and lop() below.
159 #ifdef DEBUGGING /* Serve -DT. */
160 # define REPORT(retval) tokereport((I32)retval)
162 # define REPORT(retval) (retval)
165 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
166 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
167 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
168 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
169 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
170 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
171 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
172 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
173 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
174 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
175 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
176 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
177 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
178 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
179 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
180 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
181 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
182 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
183 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
184 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
186 /* This bit of chicanery makes a unary function followed by
187 * a parenthesis into a function with one argument, highest precedence.
188 * The UNIDOR macro is for unary functions that can be followed by the //
189 * operator (such as C<shift // 0>).
191 #define UNI2(f,x) { \
195 PL_last_uni = PL_oldbufptr; \
196 PL_last_lop_op = f; \
198 return REPORT( (int)FUNC1 ); \
200 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
202 #define UNI(f) UNI2(f,XTERM)
203 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
205 #define UNIBRACK(f) { \
208 PL_last_uni = PL_oldbufptr; \
210 return REPORT( (int)FUNC1 ); \
212 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
215 /* grandfather return to old style */
216 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
220 /* how to interpret the yylval associated with the token */
224 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
230 static struct debug_tokens {
232 enum token_type type;
234 } const debug_tokens[] =
236 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
237 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
238 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
239 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
240 { ARROW, TOKENTYPE_NONE, "ARROW" },
241 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
242 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
243 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
244 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
245 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
246 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
247 { DO, TOKENTYPE_NONE, "DO" },
248 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
249 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
250 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
251 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
252 { ELSE, TOKENTYPE_NONE, "ELSE" },
253 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
254 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
255 { FOR, TOKENTYPE_IVAL, "FOR" },
256 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
257 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
258 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
259 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
260 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
261 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
262 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
263 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
264 { IF, TOKENTYPE_IVAL, "IF" },
265 { LABEL, TOKENTYPE_PVAL, "LABEL" },
266 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
267 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
268 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
269 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
270 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
271 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
272 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
273 { MY, TOKENTYPE_IVAL, "MY" },
274 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
275 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
276 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
277 { OROP, TOKENTYPE_IVAL, "OROP" },
278 { OROR, TOKENTYPE_NONE, "OROR" },
279 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
280 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
281 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
282 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
283 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
284 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
285 { PREINC, TOKENTYPE_NONE, "PREINC" },
286 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
287 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
288 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
289 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
290 { SUB, TOKENTYPE_NONE, "SUB" },
291 { THING, TOKENTYPE_OPVAL, "THING" },
292 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
293 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
294 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
295 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
296 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
297 { USE, TOKENTYPE_IVAL, "USE" },
298 { WHEN, TOKENTYPE_IVAL, "WHEN" },
299 { WHILE, TOKENTYPE_IVAL, "WHILE" },
300 { WORD, TOKENTYPE_OPVAL, "WORD" },
301 { 0, TOKENTYPE_NONE, 0 }
304 /* dump the returned token in rv, plus any optional arg in yylval */
307 S_tokereport(pTHX_ I32 rv)
311 const char *name = NULL;
312 enum token_type type = TOKENTYPE_NONE;
313 const struct debug_tokens *p;
314 SV* const report = newSVpvs("<== ");
316 for (p = debug_tokens; p->token; p++) {
317 if (p->token == (int)rv) {
324 Perl_sv_catpv(aTHX_ report, name);
325 else if ((char)rv > ' ' && (char)rv < '~')
326 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
328 sv_catpvs(report, "EOF");
330 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
333 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
336 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
338 case TOKENTYPE_OPNUM:
339 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
340 PL_op_name[yylval.ival]);
343 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
345 case TOKENTYPE_OPVAL:
347 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
348 PL_op_name[yylval.opval->op_type]);
349 if (yylval.opval->op_type == OP_CONST) {
350 Perl_sv_catpvf(aTHX_ report, " %s",
351 SvPEEK(cSVOPx_sv(yylval.opval)));
356 sv_catpvs(report, "(opval=null)");
359 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
365 /* print the buffer with suitable escapes */
368 S_printbuf(pTHX_ const char* fmt, const char* s)
370 SV* const tmp = newSVpvs("");
371 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
380 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
381 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
385 S_ao(pTHX_ int toketype)
388 if (*PL_bufptr == '=') {
390 if (toketype == ANDAND)
391 yylval.ival = OP_ANDASSIGN;
392 else if (toketype == OROR)
393 yylval.ival = OP_ORASSIGN;
394 else if (toketype == DORDOR)
395 yylval.ival = OP_DORASSIGN;
403 * When Perl expects an operator and finds something else, no_op
404 * prints the warning. It always prints "<something> found where
405 * operator expected. It prints "Missing semicolon on previous line?"
406 * if the surprise occurs at the start of the line. "do you need to
407 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
408 * where the compiler doesn't know if foo is a method call or a function.
409 * It prints "Missing operator before end of line" if there's nothing
410 * after the missing operator, or "... before <...>" if there is something
411 * after the missing operator.
415 S_no_op(pTHX_ const char *what, char *s)
418 char * const oldbp = PL_bufptr;
419 const bool is_first = (PL_oldbufptr == PL_linestart);
425 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
426 if (ckWARN_d(WARN_SYNTAX)) {
428 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
429 "\t(Missing semicolon on previous line?)\n");
430 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
432 for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
434 if (t < PL_bufptr && isSPACE(*t))
435 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
436 "\t(Do you need to predeclare %.*s?)\n",
437 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
441 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
442 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
450 * Complain about missing quote/regexp/heredoc terminator.
451 * If it's called with NULL then it cauterizes the line buffer.
452 * If we're in a delimited string and the delimiter is a control
453 * character, it's reformatted into a two-char sequence like ^C.
458 S_missingterm(pTHX_ char *s)
464 char * const nl = strrchr(s,'\n');
470 iscntrl(PL_multi_close)
472 PL_multi_close < 32 || PL_multi_close == 127
476 tmpbuf[1] = (char)toCTRL(PL_multi_close);
481 *tmpbuf = (char)PL_multi_close;
485 q = strchr(s,'"') ? '\'' : '"';
486 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
489 #define FEATURE_IS_ENABLED(name) \
490 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
491 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
493 * S_feature_is_enabled
494 * Check whether the named feature is enabled.
497 S_feature_is_enabled(pTHX_ const char *name, STRLEN namelen)
500 HV * const hinthv = GvHV(PL_hintgv);
501 char he_name[32] = "feature_";
502 (void) strncpy(&he_name[8], name, 24);
504 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
512 Perl_deprecate(pTHX_ const char *s)
514 if (ckWARN(WARN_DEPRECATED))
515 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
519 Perl_deprecate_old(pTHX_ const char *s)
521 /* This function should NOT be called for any new deprecated warnings */
522 /* Use Perl_deprecate instead */
524 /* It is here to maintain backward compatibility with the pre-5.8 */
525 /* warnings category hierarchy. The "deprecated" category used to */
526 /* live under the "syntax" category. It is now a top-level category */
527 /* in its own right. */
529 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
530 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
531 "Use of %s is deprecated", s);
535 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
536 * utf16-to-utf8-reversed.
539 #ifdef PERL_CR_FILTER
543 register const char *s = SvPVX_const(sv);
544 register const char * const e = s + SvCUR(sv);
545 /* outer loop optimized to do nothing if there are no CR-LFs */
547 if (*s++ == '\r' && *s == '\n') {
548 /* hit a CR-LF, need to copy the rest */
549 register char *d = s - 1;
552 if (*s == '\r' && s[1] == '\n')
563 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
565 const I32 count = FILTER_READ(idx+1, sv, maxlen);
566 if (count > 0 && !maxlen)
574 * Initialize variables. Uses the Perl save_stack to save its state (for
575 * recursive calls to the parser).
579 Perl_lex_start(pTHX_ SV *line)
585 SAVEI32(PL_lex_dojoin);
586 SAVEI32(PL_lex_brackets);
587 SAVEI32(PL_lex_casemods);
588 SAVEI32(PL_lex_starts);
589 SAVEI32(PL_lex_state);
590 SAVEVPTR(PL_lex_inpat);
591 SAVEI32(PL_lex_inwhat);
593 if (PL_lex_state == LEX_KNOWNEXT) {
594 I32 toke = PL_lasttoke;
595 while (--toke >= 0) {
596 SAVEI32(PL_nexttoke[toke].next_type);
597 SAVEVPTR(PL_nexttoke[toke].next_val);
599 SAVEVPTR(PL_nexttoke[toke].next_mad);
601 SAVEI32(PL_lasttoke);
604 SAVESPTR(PL_thistoken);
605 SAVESPTR(PL_thiswhite);
606 SAVESPTR(PL_nextwhite);
607 SAVESPTR(PL_thisopen);
608 SAVESPTR(PL_thisclose);
609 SAVESPTR(PL_thisstuff);
610 SAVEVPTR(PL_thismad);
611 SAVEI32(PL_realtokenstart);
612 SAVEI32(PL_faketokens);
614 SAVEI32(PL_curforce);
616 if (PL_lex_state == LEX_KNOWNEXT) {
617 I32 toke = PL_nexttoke;
618 while (--toke >= 0) {
619 SAVEI32(PL_nexttype[toke]);
620 SAVEVPTR(PL_nextval[toke]);
622 SAVEI32(PL_nexttoke);
625 SAVECOPLINE(PL_curcop);
628 SAVEPPTR(PL_oldbufptr);
629 SAVEPPTR(PL_oldoldbufptr);
630 SAVEPPTR(PL_last_lop);
631 SAVEPPTR(PL_last_uni);
632 SAVEPPTR(PL_linestart);
633 SAVESPTR(PL_linestr);
634 SAVEGENERICPV(PL_lex_brackstack);
635 SAVEGENERICPV(PL_lex_casestack);
636 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
637 SAVESPTR(PL_lex_stuff);
638 SAVEI32(PL_lex_defer);
639 SAVEI32(PL_sublex_info.sub_inwhat);
640 SAVESPTR(PL_lex_repl);
642 SAVEINT(PL_lex_expect);
644 PL_lex_state = LEX_NORMAL;
648 Newx(PL_lex_brackstack, 120, char);
649 Newx(PL_lex_casestack, 12, char);
651 *PL_lex_casestack = '\0';
663 PL_sublex_info.sub_inwhat = 0;
665 if (SvREADONLY(PL_linestr))
666 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
667 s = SvPV_const(PL_linestr, len);
668 if (!len || s[len-1] != ';') {
669 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
670 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
671 sv_catpvs(PL_linestr, "\n;");
673 SvTEMP_off(PL_linestr);
674 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
675 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
676 PL_last_lop = PL_last_uni = NULL;
682 * Finalizer for lexing operations. Must be called when the parser is
683 * done with the lexer.
690 PL_doextract = FALSE;
695 * This subroutine has nothing to do with tilting, whether at windmills
696 * or pinball tables. Its name is short for "increment line". It
697 * increments the current line number in CopLINE(PL_curcop) and checks
698 * to see whether the line starts with a comment of the form
699 * # line 500 "foo.pm"
700 * If so, it sets the current line number and file to the values in the comment.
704 S_incline(pTHX_ char *s)
712 CopLINE_inc(PL_curcop);
715 while (SPACE_OR_TAB(*s))
717 if (strnEQ(s, "line", 4))
721 if (SPACE_OR_TAB(*s))
725 while (SPACE_OR_TAB(*s))
733 while (SPACE_OR_TAB(*s))
735 if (*s == '"' && (t = strchr(s+1, '"'))) {
740 for (t = s; !isSPACE(*t); t++) ;
743 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
745 if (*e != '\n' && *e != '\0')
746 return; /* false alarm */
752 const char * const cf = CopFILE(PL_curcop);
753 STRLEN tmplen = cf ? strlen(cf) : 0;
754 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
755 /* must copy *{"::_<(eval N)[oldfilename:L]"}
756 * to *{"::_<newfilename"} */
757 char smallbuf[256], smallbuf2[256];
758 char *tmpbuf, *tmpbuf2;
760 STRLEN tmplen2 = strlen(s);
761 if (tmplen + 3 < sizeof smallbuf)
764 Newx(tmpbuf, tmplen + 3, char);
765 if (tmplen2 + 3 < sizeof smallbuf2)
768 Newx(tmpbuf2, tmplen2 + 3, char);
769 tmpbuf[0] = tmpbuf2[0] = '_';
770 tmpbuf[1] = tmpbuf2[1] = '<';
771 memcpy(tmpbuf + 2, cf, ++tmplen);
772 memcpy(tmpbuf2 + 2, s, ++tmplen2);
774 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
776 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
778 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
779 /* adjust ${"::_<newfilename"} to store the new file name */
780 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
781 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
782 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
784 if (tmpbuf != smallbuf) Safefree(tmpbuf);
785 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
788 CopFILE_free(PL_curcop);
789 CopFILE_set(PL_curcop, s);
792 CopLINE_set(PL_curcop, atoi(n)-1);
796 /* skip space before PL_thistoken */
799 S_skipspace0(pTHX_ register char *s)
806 PL_thiswhite = newSVpvn("",0);
807 sv_catsv(PL_thiswhite, PL_skipwhite);
808 sv_free(PL_skipwhite);
811 PL_realtokenstart = s - SvPVX(PL_linestr);
815 /* skip space after PL_thistoken */
818 S_skipspace1(pTHX_ register char *s)
820 const char *start = s;
821 I32 startoff = start - SvPVX(PL_linestr);
826 start = SvPVX(PL_linestr) + startoff;
827 if (!PL_thistoken && PL_realtokenstart >= 0) {
828 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
829 PL_thistoken = newSVpvn(tstart, start - tstart);
831 PL_realtokenstart = -1;
834 PL_nextwhite = newSVpvn("",0);
835 sv_catsv(PL_nextwhite, PL_skipwhite);
836 sv_free(PL_skipwhite);
843 S_skipspace2(pTHX_ register char *s, SV **svp)
846 I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
847 I32 startoff = start - SvPVX(PL_linestr);
849 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
850 if (!PL_madskills || !svp)
852 start = SvPVX(PL_linestr) + startoff;
853 if (!PL_thistoken && PL_realtokenstart >= 0) {
854 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
855 PL_thistoken = newSVpvn(tstart, start - tstart);
856 PL_realtokenstart = -1;
860 *svp = newSVpvn("",0);
861 sv_setsv(*svp, PL_skipwhite);
862 sv_free(PL_skipwhite);
872 * Called to gobble the appropriate amount and type of whitespace.
873 * Skips comments as well.
877 S_skipspace(pTHX_ register char *s)
882 int startoff = s - SvPVX(PL_linestr);
885 sv_free(PL_skipwhite);
890 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
891 while (s < PL_bufend && SPACE_OR_TAB(*s))
901 SSize_t oldprevlen, oldoldprevlen;
902 SSize_t oldloplen = 0, oldunilen = 0;
903 while (s < PL_bufend && isSPACE(*s)) {
904 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
909 if (s < PL_bufend && *s == '#') {
910 while (s < PL_bufend && *s != '\n')
914 if (PL_in_eval && !PL_rsfp) {
921 /* only continue to recharge the buffer if we're at the end
922 * of the buffer, we're not reading from a source filter, and
923 * we're in normal lexing mode
925 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
926 PL_lex_state == LEX_FORMLINE)
933 /* try to recharge the buffer */
935 curoff = s - SvPVX(PL_linestr);
938 if ((s = filter_gets(PL_linestr, PL_rsfp,
939 (prevlen = SvCUR(PL_linestr)))) == NULL)
942 if (PL_madskills && curoff != startoff) {
944 PL_skipwhite = newSVpvn("",0);
945 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
949 /* mustn't throw out old stuff yet if madpropping */
950 SvCUR(PL_linestr) = curoff;
951 s = SvPVX(PL_linestr) + curoff;
953 if (curoff && s[-1] == '\n')
957 /* end of file. Add on the -p or -n magic */
958 /* XXX these shouldn't really be added here, can't set PL_faketokens */
962 ";}continue{print or die qq(-p destination: $!\\n);}");
965 ";}continue{print or die qq(-p destination: $!\\n);}");
967 PL_minus_n = PL_minus_p = 0;
969 else if (PL_minus_n) {
971 sv_catpvn(PL_linestr, ";}", 2);
973 sv_setpvn(PL_linestr, ";}", 2);
979 sv_catpvn(PL_linestr,";", 1);
981 sv_setpvn(PL_linestr,";", 1);
984 /* reset variables for next time we lex */
985 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
991 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
992 PL_last_lop = PL_last_uni = NULL;
994 /* Close the filehandle. Could be from -P preprocessor,
995 * STDIN, or a regular file. If we were reading code from
996 * STDIN (because the commandline held no -e or filename)
997 * then we don't close it, we reset it so the code can
998 * read from STDIN too.
1001 if (PL_preprocess && !PL_in_eval)
1002 (void)PerlProc_pclose(PL_rsfp);
1003 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1004 PerlIO_clearerr(PL_rsfp);
1006 (void)PerlIO_close(PL_rsfp);
1011 /* not at end of file, so we only read another line */
1012 /* make corresponding updates to old pointers, for yyerror() */
1013 oldprevlen = PL_oldbufptr - PL_bufend;
1014 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1016 oldunilen = PL_last_uni - PL_bufend;
1018 oldloplen = PL_last_lop - PL_bufend;
1019 PL_linestart = PL_bufptr = s + prevlen;
1020 PL_bufend = s + SvCUR(PL_linestr);
1022 PL_oldbufptr = s + oldprevlen;
1023 PL_oldoldbufptr = s + oldoldprevlen;
1025 PL_last_uni = s + oldunilen;
1027 PL_last_lop = s + oldloplen;
1030 /* debugger active and we're not compiling the debugger code,
1031 * so store the line into the debugger's array of lines
1033 if (PERLDB_LINE && PL_curstash != PL_debstash) {
1034 SV * const sv = newSV(0);
1036 sv_upgrade(sv, SVt_PVMG);
1037 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
1040 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
1048 PL_skipwhite = newSVpvn("",0);
1049 curoff = s - SvPVX(PL_linestr);
1050 if (curoff - startoff)
1051 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1060 * Check the unary operators to ensure there's no ambiguity in how they're
1061 * used. An ambiguous piece of code would be:
1063 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1064 * the +5 is its argument.
1074 if (PL_oldoldbufptr != PL_last_uni)
1076 while (isSPACE(*PL_last_uni))
1078 for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++)
1080 if ((t = strchr(s, '(')) && t < PL_bufptr)
1083 if (ckWARN_d(WARN_AMBIGUOUS)){
1084 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
1085 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1086 (int)(s - PL_last_uni), PL_last_uni);
1091 * LOP : macro to build a list operator. Its behaviour has been replaced
1092 * with a subroutine, S_lop() for which LOP is just another name.
1095 #define LOP(f,x) return lop(f,x,s)
1099 * Build a list operator (or something that might be one). The rules:
1100 * - if we have a next token, then it's a list operator [why?]
1101 * - if the next thing is an opening paren, then it's a function
1102 * - else it's a list operator
1106 S_lop(pTHX_ I32 f, int x, char *s)
1113 PL_last_lop = PL_oldbufptr;
1114 PL_last_lop_op = (OPCODE)f;
1117 return REPORT(LSTOP);
1120 return REPORT(LSTOP);
1123 return REPORT(FUNC);
1126 return REPORT(FUNC);
1128 return REPORT(LSTOP);
1134 * Sets up for an eventual force_next(). start_force(0) basically does
1135 * an unshift, while start_force(-1) does a push. yylex removes items
1140 S_start_force(pTHX_ int where)
1144 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
1145 where = PL_lasttoke;
1146 assert(PL_curforce < 0 || PL_curforce == where);
1147 if (PL_curforce != where) {
1148 for (i = PL_lasttoke; i > where; --i) {
1149 PL_nexttoke[i] = PL_nexttoke[i-1];
1153 if (PL_curforce < 0) /* in case of duplicate start_force() */
1154 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1155 PL_curforce = where;
1158 curmad('^', newSVpvn("",0));
1159 CURMAD('_', PL_nextwhite);
1164 S_curmad(pTHX_ char slot, SV *sv)
1170 if (PL_curforce < 0)
1171 where = &PL_thismad;
1173 where = &PL_nexttoke[PL_curforce].next_mad;
1176 sv_setpvn(sv, "", 0);
1179 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1181 else if (PL_encoding) {
1182 sv_recode_to_utf8(sv, PL_encoding);
1187 /* keep a slot open for the head of the list? */
1188 if (slot != '_' && *where && (*where)->mad_key == '^') {
1189 (*where)->mad_key = slot;
1190 sv_free((*where)->mad_val);
1191 (*where)->mad_val = (void*)sv;
1194 addmad(newMADsv(slot, sv), where, 0);
1197 # define start_force(where) /*EMPTY*/
1198 # define curmad(slot, sv) /*EMPTY*/
1203 * When the lexer realizes it knows the next token (for instance,
1204 * it is reordering tokens for the parser) then it can call S_force_next
1205 * to know what token to return the next time the lexer is called. Caller
1206 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1207 * and possibly PL_expect to ensure the lexer handles the token correctly.
1211 S_force_next(pTHX_ I32 type)
1215 if (PL_curforce < 0)
1216 start_force(PL_lasttoke);
1217 PL_nexttoke[PL_curforce].next_type = type;
1218 if (PL_lex_state != LEX_KNOWNEXT)
1219 PL_lex_defer = PL_lex_state;
1220 PL_lex_state = LEX_KNOWNEXT;
1221 PL_lex_expect = PL_expect;
1224 PL_nexttype[PL_nexttoke] = type;
1226 if (PL_lex_state != LEX_KNOWNEXT) {
1227 PL_lex_defer = PL_lex_state;
1228 PL_lex_expect = PL_expect;
1229 PL_lex_state = LEX_KNOWNEXT;
1235 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
1238 SV * const sv = newSVpvn(start,len);
1239 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
1246 * When the lexer knows the next thing is a word (for instance, it has
1247 * just seen -> and it knows that the next char is a word char, then
1248 * it calls S_force_word to stick the next word into the PL_next lookahead.
1251 * char *start : buffer position (must be within PL_linestr)
1252 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
1253 * int check_keyword : if true, Perl checks to make sure the word isn't
1254 * a keyword (do this if the word is a label, e.g. goto FOO)
1255 * int allow_pack : if true, : characters will also be allowed (require,
1256 * use, etc. do this)
1257 * int allow_initial_tick : used by the "sub" lexer only.
1261 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1267 start = SKIPSPACE1(start);
1269 if (isIDFIRST_lazy_if(s,UTF) ||
1270 (allow_pack && *s == ':') ||
1271 (allow_initial_tick && *s == '\'') )
1273 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1274 if (check_keyword && keyword(PL_tokenbuf, len))
1276 start_force(PL_curforce);
1278 curmad('X', newSVpvn(start,s-start));
1279 if (token == METHOD) {
1284 PL_expect = XOPERATOR;
1287 NEXTVAL_NEXTTOKE.opval
1288 = (OP*)newSVOP(OP_CONST,0,
1289 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1290 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1298 * Called when the lexer wants $foo *foo &foo etc, but the program
1299 * text only contains the "foo" portion. The first argument is a pointer
1300 * to the "foo", and the second argument is the type symbol to prefix.
1301 * Forces the next token to be a "WORD".
1302 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1306 S_force_ident(pTHX_ register const char *s, int kind)
1310 const STRLEN len = strlen(s);
1311 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1312 start_force(PL_curforce);
1313 NEXTVAL_NEXTTOKE.opval = o;
1316 o->op_private = OPpCONST_ENTERED;
1317 /* XXX see note in pp_entereval() for why we forgo typo
1318 warnings if the symbol must be introduced in an eval.
1320 gv_fetchpvn_flags(s, len,
1321 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1323 kind == '$' ? SVt_PV :
1324 kind == '@' ? SVt_PVAV :
1325 kind == '%' ? SVt_PVHV :
1333 Perl_str_to_version(pTHX_ SV *sv)
1338 const char *start = SvPV_const(sv,len);
1339 const char * const end = start + len;
1340 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1341 while (start < end) {
1345 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1350 retval += ((NV)n)/nshift;
1359 * Forces the next token to be a version number.
1360 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1361 * and if "guessing" is TRUE, then no new token is created (and the caller
1362 * must use an alternative parsing method).
1366 S_force_version(pTHX_ char *s, int guessing)
1372 I32 startoff = s - SvPVX(PL_linestr);
1381 while (isDIGIT(*d) || *d == '_' || *d == '.')
1385 start_force(PL_curforce);
1386 curmad('X', newSVpvn(s,d-s));
1389 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1391 s = scan_num(s, &yylval);
1392 version = yylval.opval;
1393 ver = cSVOPx(version)->op_sv;
1394 if (SvPOK(ver) && !SvNIOK(ver)) {
1395 SvUPGRADE(ver, SVt_PVNV);
1396 SvNV_set(ver, str_to_version(ver));
1397 SvNOK_on(ver); /* hint that it is a version */
1400 else if (guessing) {
1403 sv_free(PL_nextwhite); /* let next token collect whitespace */
1405 s = SvPVX(PL_linestr) + startoff;
1413 if (PL_madskills && !version) {
1414 sv_free(PL_nextwhite); /* let next token collect whitespace */
1416 s = SvPVX(PL_linestr) + startoff;
1419 /* NOTE: The parser sees the package name and the VERSION swapped */
1420 start_force(PL_curforce);
1421 NEXTVAL_NEXTTOKE.opval = version;
1429 * Tokenize a quoted string passed in as an SV. It finds the next
1430 * chunk, up to end of string or a backslash. It may make a new
1431 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1436 S_tokeq(pTHX_ SV *sv)
1440 register char *send;
1448 s = SvPV_force(sv, len);
1449 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1452 while (s < send && *s != '\\')
1457 if ( PL_hints & HINT_NEW_STRING ) {
1458 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1464 if (s + 1 < send && (s[1] == '\\'))
1465 s++; /* all that, just for this */
1470 SvCUR_set(sv, d - SvPVX_const(sv));
1472 if ( PL_hints & HINT_NEW_STRING )
1473 return new_constant(NULL, 0, "q", sv, pv, "q");
1478 * Now come three functions related to double-quote context,
1479 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1480 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1481 * interact with PL_lex_state, and create fake ( ... ) argument lists
1482 * to handle functions and concatenation.
1483 * They assume that whoever calls them will be setting up a fake
1484 * join call, because each subthing puts a ',' after it. This lets
1487 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1489 * (I'm not sure whether the spurious commas at the end of lcfirst's
1490 * arguments and join's arguments are created or not).
1495 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1497 * Pattern matching will set PL_lex_op to the pattern-matching op to
1498 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1500 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1502 * Everything else becomes a FUNC.
1504 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1505 * had an OP_CONST or OP_READLINE). This just sets us up for a
1506 * call to S_sublex_push().
1510 S_sublex_start(pTHX)
1513 register const I32 op_type = yylval.ival;
1515 if (op_type == OP_NULL) {
1516 yylval.opval = PL_lex_op;
1520 if (op_type == OP_CONST || op_type == OP_READLINE) {
1521 SV *sv = tokeq(PL_lex_stuff);
1523 if (SvTYPE(sv) == SVt_PVIV) {
1524 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1526 const char * const p = SvPV_const(sv, len);
1527 SV * const nsv = newSVpvn(p, len);
1533 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1534 PL_lex_stuff = NULL;
1535 /* Allow <FH> // "foo" */
1536 if (op_type == OP_READLINE)
1537 PL_expect = XTERMORDORDOR;
1541 PL_sublex_info.super_state = PL_lex_state;
1542 PL_sublex_info.sub_inwhat = op_type;
1543 PL_sublex_info.sub_op = PL_lex_op;
1544 PL_lex_state = LEX_INTERPPUSH;
1548 yylval.opval = PL_lex_op;
1558 * Create a new scope to save the lexing state. The scope will be
1559 * ended in S_sublex_done. Returns a '(', starting the function arguments
1560 * to the uc, lc, etc. found before.
1561 * Sets PL_lex_state to LEX_INTERPCONCAT.
1570 PL_lex_state = PL_sublex_info.super_state;
1571 SAVEI32(PL_lex_dojoin);
1572 SAVEI32(PL_lex_brackets);
1573 SAVEI32(PL_lex_casemods);
1574 SAVEI32(PL_lex_starts);
1575 SAVEI32(PL_lex_state);
1576 SAVEVPTR(PL_lex_inpat);
1577 SAVEI32(PL_lex_inwhat);
1578 SAVECOPLINE(PL_curcop);
1579 SAVEPPTR(PL_bufptr);
1580 SAVEPPTR(PL_bufend);
1581 SAVEPPTR(PL_oldbufptr);
1582 SAVEPPTR(PL_oldoldbufptr);
1583 SAVEPPTR(PL_last_lop);
1584 SAVEPPTR(PL_last_uni);
1585 SAVEPPTR(PL_linestart);
1586 SAVESPTR(PL_linestr);
1587 SAVEGENERICPV(PL_lex_brackstack);
1588 SAVEGENERICPV(PL_lex_casestack);
1590 PL_linestr = PL_lex_stuff;
1591 PL_lex_stuff = NULL;
1593 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1594 = SvPVX(PL_linestr);
1595 PL_bufend += SvCUR(PL_linestr);
1596 PL_last_lop = PL_last_uni = NULL;
1597 SAVEFREESV(PL_linestr);
1599 PL_lex_dojoin = FALSE;
1600 PL_lex_brackets = 0;
1601 Newx(PL_lex_brackstack, 120, char);
1602 Newx(PL_lex_casestack, 12, char);
1603 PL_lex_casemods = 0;
1604 *PL_lex_casestack = '\0';
1606 PL_lex_state = LEX_INTERPCONCAT;
1607 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1609 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1610 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1611 PL_lex_inpat = PL_sublex_info.sub_op;
1613 PL_lex_inpat = NULL;
1620 * Restores lexer state after a S_sublex_push.
1627 if (!PL_lex_starts++) {
1628 SV * const sv = newSVpvs("");
1629 if (SvUTF8(PL_linestr))
1631 PL_expect = XOPERATOR;
1632 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1636 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1637 PL_lex_state = LEX_INTERPCASEMOD;
1641 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1642 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1643 PL_linestr = PL_lex_repl;
1645 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1646 PL_bufend += SvCUR(PL_linestr);
1647 PL_last_lop = PL_last_uni = NULL;
1648 SAVEFREESV(PL_linestr);
1649 PL_lex_dojoin = FALSE;
1650 PL_lex_brackets = 0;
1651 PL_lex_casemods = 0;
1652 *PL_lex_casestack = '\0';
1654 if (SvEVALED(PL_lex_repl)) {
1655 PL_lex_state = LEX_INTERPNORMAL;
1657 /* we don't clear PL_lex_repl here, so that we can check later
1658 whether this is an evalled subst; that means we rely on the
1659 logic to ensure sublex_done() is called again only via the
1660 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1663 PL_lex_state = LEX_INTERPCONCAT;
1673 PL_endwhite = newSVpvn("",0);
1674 sv_catsv(PL_endwhite, PL_thiswhite);
1678 sv_setpvn(PL_thistoken,"",0);
1680 PL_realtokenstart = -1;
1684 PL_bufend = SvPVX(PL_linestr);
1685 PL_bufend += SvCUR(PL_linestr);
1686 PL_expect = XOPERATOR;
1687 PL_sublex_info.sub_inwhat = 0;
1695 Extracts a pattern, double-quoted string, or transliteration. This
1698 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1699 processing a pattern (PL_lex_inpat is true), a transliteration
1700 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1702 Returns a pointer to the character scanned up to. Iff this is
1703 advanced from the start pointer supplied (ie if anything was
1704 successfully parsed), will leave an OP for the substring scanned
1705 in yylval. Caller must intuit reason for not parsing further
1706 by looking at the next characters herself.
1710 double-quoted style: \r and \n
1711 regexp special ones: \D \s
1713 backrefs: \1 (deprecated in substitution replacements)
1714 case and quoting: \U \Q \E
1715 stops on @ and $, but not for $ as tail anchor
1717 In transliterations:
1718 characters are VERY literal, except for - not at the start or end
1719 of the string, which indicates a range. scan_const expands the
1720 range to the full set of intermediate characters.
1722 In double-quoted strings:
1724 double-quoted style: \r and \n
1726 backrefs: \1 (deprecated)
1727 case and quoting: \U \Q \E
1730 scan_const does *not* construct ops to handle interpolated strings.
1731 It stops processing as soon as it finds an embedded $ or @ variable
1732 and leaves it to the caller to work out what's going on.
1734 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo.
1736 $ in pattern could be $foo or could be tail anchor. Assumption:
1737 it's a tail anchor if $ is the last thing in the string, or if it's
1738 followed by one of ")| \n\t"
1740 \1 (backreferences) are turned into $1
1742 The structure of the code is
1743 while (there's a character to process) {
1744 handle transliteration ranges
1745 skip regexp comments
1746 skip # initiated comments in //x patterns
1747 check for embedded @foo
1748 check for embedded scalars
1750 leave intact backslashes from leave (below)
1751 deprecate \1 in strings and sub replacements
1752 handle string-changing backslashes \l \U \Q \E, etc.
1753 switch (what was escaped) {
1754 handle - in a transliteration (becomes a literal -)
1755 handle \132 octal characters
1756 handle 0x15 hex characters
1757 handle \cV (control V)
1758 handle printf backslashes (\f, \r, \n, etc)
1760 } (end if backslash)
1761 } (end while character to read)
1766 S_scan_const(pTHX_ char *start)
1769 register char *send = PL_bufend; /* end of the constant */
1770 SV *sv = newSV(send - start); /* sv for the constant */
1771 register char *s = start; /* start of the constant */
1772 register char *d = SvPVX(sv); /* destination for copies */
1773 bool dorange = FALSE; /* are we in a translit range? */
1774 bool didrange = FALSE; /* did we just finish a range? */
1775 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1776 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1779 UV literal_endpoint = 0;
1782 const char * const leaveit = /* set of acceptably-backslashed characters */
1784 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#"
1787 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1788 /* If we are doing a trans and we know we want UTF8 set expectation */
1789 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1790 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1794 while (s < send || dorange) {
1795 /* get transliterations out of the way (they're most literal) */
1796 if (PL_lex_inwhat == OP_TRANS) {
1797 /* expand a range A-Z to the full set of characters. AIE! */
1799 I32 i; /* current expanded character */
1800 I32 min; /* first character in range */
1801 I32 max; /* last character in range */
1804 char * const c = (char*)utf8_hop((U8*)d, -1);
1808 *c = (char)UTF_TO_NATIVE(0xff);
1809 /* mark the range as done, and continue */
1815 i = d - SvPVX_const(sv); /* remember current offset */
1816 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1817 d = SvPVX(sv) + i; /* refresh d after realloc */
1818 d -= 2; /* eat the first char and the - */
1820 min = (U8)*d; /* first char in range */
1821 max = (U8)d[1]; /* last char in range */
1825 "Invalid range \"%c-%c\" in transliteration operator",
1826 (char)min, (char)max);
1830 if (literal_endpoint == 2 &&
1831 ((isLOWER(min) && isLOWER(max)) ||
1832 (isUPPER(min) && isUPPER(max)))) {
1834 for (i = min; i <= max; i++)
1836 *d++ = NATIVE_TO_NEED(has_utf8,i);
1838 for (i = min; i <= max; i++)
1840 *d++ = NATIVE_TO_NEED(has_utf8,i);
1845 for (i = min; i <= max; i++)
1848 /* mark the range as done, and continue */
1852 literal_endpoint = 0;
1857 /* range begins (ignore - as first or last char) */
1858 else if (*s == '-' && s+1 < send && s != start) {
1860 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1863 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1873 literal_endpoint = 0;
1878 /* if we get here, we're not doing a transliteration */
1880 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1881 except for the last char, which will be done separately. */
1882 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1884 while (s+1 < send && *s != ')')
1885 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1887 else if (s[2] == '{' /* This should match regcomp.c */
1888 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1891 char *regparse = s + (s[2] == '{' ? 3 : 4);
1894 while (count && (c = *regparse)) {
1895 if (c == '\\' && regparse[1])
1903 if (*regparse != ')')
1904 regparse--; /* Leave one char for continuation. */
1905 while (s < regparse)
1906 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1910 /* likewise skip #-initiated comments in //x patterns */
1911 else if (*s == '#' && PL_lex_inpat &&
1912 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1913 while (s+1 < send && *s != '\n')
1914 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1917 /* check for embedded arrays
1918 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1920 else if (*s == '@' && s[1]
1921 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1924 /* check for embedded scalars. only stop if we're sure it's a
1927 else if (*s == '$') {
1928 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1930 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1931 break; /* in regexp, $ might be tail anchor */
1934 /* End of else if chain - OP_TRANS rejoin rest */
1937 if (*s == '\\' && s+1 < send) {
1940 /* some backslashes we leave behind */
1941 if (*leaveit && *s && strchr(leaveit, *s)) {
1942 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1943 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1947 /* deprecate \1 in strings and substitution replacements */
1948 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1949 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1951 if (ckWARN(WARN_SYNTAX))
1952 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
1957 /* string-change backslash escapes */
1958 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1963 /* if we get here, it's either a quoted -, or a digit */
1966 /* quoted - in transliterations */
1968 if (PL_lex_inwhat == OP_TRANS) {
1978 Perl_warner(aTHX_ packWARN(WARN_MISC),
1979 "Unrecognized escape \\%c passed through",
1981 /* default action is to copy the quoted character */
1982 goto default_action;
1985 /* \132 indicates an octal constant */
1986 case '0': case '1': case '2': case '3':
1987 case '4': case '5': case '6': case '7':
1991 uv = grok_oct(s, &len, &flags, NULL);
1994 goto NUM_ESCAPE_INSERT;
1996 /* \x24 indicates a hex constant */
2000 char* const e = strchr(s, '}');
2001 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2002 PERL_SCAN_DISALLOW_PREFIX;
2007 yyerror("Missing right brace on \\x{}");
2011 uv = grok_hex(s, &len, &flags, NULL);
2017 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2018 uv = grok_hex(s, &len, &flags, NULL);
2024 /* Insert oct or hex escaped character.
2025 * There will always enough room in sv since such
2026 * escapes will be longer than any UTF-8 sequence
2027 * they can end up as. */
2029 /* We need to map to chars to ASCII before doing the tests
2032 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
2033 if (!has_utf8 && uv > 255) {
2034 /* Might need to recode whatever we have
2035 * accumulated so far if it contains any
2038 * (Can't we keep track of that and avoid
2039 * this rescan? --jhi)
2043 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
2044 if (!NATIVE_IS_INVARIANT(*c)) {
2049 const STRLEN offset = d - SvPVX_const(sv);
2051 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
2055 while (src >= (const U8 *)SvPVX_const(sv)) {
2056 if (!NATIVE_IS_INVARIANT(*src)) {
2057 const U8 ch = NATIVE_TO_ASCII(*src);
2058 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
2059 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
2069 if (has_utf8 || uv > 255) {
2070 d = (char*)uvchr_to_utf8((U8*)d, uv);
2072 if (PL_lex_inwhat == OP_TRANS &&
2073 PL_sublex_info.sub_op) {
2074 PL_sublex_info.sub_op->op_private |=
2075 (PL_lex_repl ? OPpTRANS_FROM_UTF
2088 /* \N{LATIN SMALL LETTER A} is a named character */
2092 char* e = strchr(s, '}');
2098 yyerror("Missing right brace on \\N{}");
2102 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2104 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2105 PERL_SCAN_DISALLOW_PREFIX;
2108 uv = grok_hex(s, &len, &flags, NULL);
2110 goto NUM_ESCAPE_INSERT;
2112 res = newSVpvn(s + 1, e - s - 1);
2113 res = new_constant( NULL, 0, "charnames",
2114 res, NULL, "\\N{...}" );
2116 sv_utf8_upgrade(res);
2117 str = SvPV_const(res,len);
2118 #ifdef EBCDIC_NEVER_MIND
2119 /* charnames uses pack U and that has been
2120 * recently changed to do the below uni->native
2121 * mapping, so this would be redundant (and wrong,
2122 * the code point would be doubly converted).
2123 * But leave this in just in case the pack U change
2124 * gets revoked, but the semantics is still
2125 * desireable for charnames. --jhi */
2127 UV uv = utf8_to_uvchr((const U8*)str, 0);
2130 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2132 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2133 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2134 str = SvPV_const(res, len);
2138 if (!has_utf8 && SvUTF8(res)) {
2139 const char * const ostart = SvPVX_const(sv);
2140 SvCUR_set(sv, d - ostart);
2143 sv_utf8_upgrade(sv);
2144 /* this just broke our allocation above... */
2145 SvGROW(sv, (STRLEN)(send - start));
2146 d = SvPVX(sv) + SvCUR(sv);
2149 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2150 const char * const odest = SvPVX_const(sv);
2152 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
2153 d = SvPVX(sv) + (d - odest);
2155 Copy(str, d, len, char);
2162 yyerror("Missing braces on \\N{}");
2165 /* \c is a control character */
2174 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2177 yyerror("Missing control char name in \\c");
2181 /* printf-style backslashes, formfeeds, newlines, etc */
2183 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2186 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2189 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2192 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2195 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2198 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2201 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2207 } /* end if (backslash) */
2214 /* If we started with encoded form, or already know we want it
2215 and then encode the next character */
2216 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
2218 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2219 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2222 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
2223 const STRLEN off = d - SvPVX_const(sv);
2224 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
2226 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2230 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2232 } /* while loop to process each character */
2234 /* terminate the string and set up the sv */
2236 SvCUR_set(sv, d - SvPVX_const(sv));
2237 if (SvCUR(sv) >= SvLEN(sv))
2238 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2241 if (PL_encoding && !has_utf8) {
2242 sv_recode_to_utf8(sv, PL_encoding);
2248 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2249 PL_sublex_info.sub_op->op_private |=
2250 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2254 /* shrink the sv if we allocated more than we used */
2255 if (SvCUR(sv) + 5 < SvLEN(sv)) {
2256 SvPV_shrink_to_cur(sv);
2259 /* return the substring (via yylval) only if we parsed anything */
2260 if (s > PL_bufptr) {
2261 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
2262 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
2264 ( PL_lex_inwhat == OP_TRANS
2266 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
2269 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2276 * Returns TRUE if there's more to the expression (e.g., a subscript),
2279 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2281 * ->[ and ->{ return TRUE
2282 * { and [ outside a pattern are always subscripts, so return TRUE
2283 * if we're outside a pattern and it's not { or [, then return FALSE
2284 * if we're in a pattern and the first char is a {
2285 * {4,5} (any digits around the comma) returns FALSE
2286 * if we're in a pattern and the first char is a [
2288 * [SOMETHING] has a funky algorithm to decide whether it's a
2289 * character class or not. It has to deal with things like
2290 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2291 * anything else returns TRUE
2294 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2297 S_intuit_more(pTHX_ register char *s)
2300 if (PL_lex_brackets)
2302 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2304 if (*s != '{' && *s != '[')
2309 /* In a pattern, so maybe we have {n,m}. */
2326 /* On the other hand, maybe we have a character class */
2329 if (*s == ']' || *s == '^')
2332 /* this is terrifying, and it works */
2333 int weight = 2; /* let's weigh the evidence */
2335 unsigned char un_char = 255, last_un_char;
2336 const char * const send = strchr(s,']');
2337 char tmpbuf[sizeof PL_tokenbuf * 4];
2339 if (!send) /* has to be an expression */
2342 Zero(seen,256,char);
2345 else if (isDIGIT(*s)) {
2347 if (isDIGIT(s[1]) && s[2] == ']')
2353 for (; s < send; s++) {
2354 last_un_char = un_char;
2355 un_char = (unsigned char)*s;
2360 weight -= seen[un_char] * 10;
2361 if (isALNUM_lazy_if(s+1,UTF)) {
2363 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2364 len = (int)strlen(tmpbuf);
2365 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2370 else if (*s == '$' && s[1] &&
2371 strchr("[#!%*<>()-=",s[1])) {
2372 if (/*{*/ strchr("])} =",s[2]))
2381 if (strchr("wds]",s[1]))
2383 else if (seen['\''] || seen['"'])
2385 else if (strchr("rnftbxcav",s[1]))
2387 else if (isDIGIT(s[1])) {
2389 while (s[1] && isDIGIT(s[1]))
2399 if (strchr("aA01! ",last_un_char))
2401 if (strchr("zZ79~",s[1]))
2403 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2404 weight -= 5; /* cope with negative subscript */
2407 if (!isALNUM(last_un_char)
2408 && !(last_un_char == '$' || last_un_char == '@'
2409 || last_un_char == '&')
2410 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2415 if (keyword(tmpbuf, d - tmpbuf))
2418 if (un_char == last_un_char + 1)
2420 weight -= seen[un_char];
2425 if (weight >= 0) /* probably a character class */
2435 * Does all the checking to disambiguate
2437 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2438 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2440 * First argument is the stuff after the first token, e.g. "bar".
2442 * Not a method if bar is a filehandle.
2443 * Not a method if foo is a subroutine prototyped to take a filehandle.
2444 * Not a method if it's really "Foo $bar"
2445 * Method if it's "foo $bar"
2446 * Not a method if it's really "print foo $bar"
2447 * Method if it's really "foo package::" (interpreted as package->foo)
2448 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2449 * Not a method if bar is a filehandle or package, but is quoted with
2454 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2457 char *s = start + (*start == '$');
2458 char tmpbuf[sizeof PL_tokenbuf];
2466 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2470 const char *proto = SvPVX_const(cv);
2481 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2482 /* start is the beginning of the possible filehandle/object,
2483 * and s is the end of it
2484 * tmpbuf is a copy of it
2487 if (*start == '$') {
2488 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2491 len = start - SvPVX(PL_linestr);
2495 start = SvPVX(PL_linestr) + len;
2499 return *s == '(' ? FUNCMETH : METHOD;
2501 if (!keyword(tmpbuf, len)) {
2502 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2506 soff = s - SvPVX(PL_linestr);
2510 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2511 if (indirgv && GvCVu(indirgv))
2513 /* filehandle or package name makes it a method */
2514 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2516 soff = s - SvPVX(PL_linestr);
2519 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2520 return 0; /* no assumptions -- "=>" quotes bearword */
2522 start_force(PL_curforce);
2523 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2524 newSVpvn(tmpbuf,len));
2525 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2527 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2532 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2534 return *s == '(' ? FUNCMETH : METHOD;
2542 * Return a string of Perl code to load the debugger. If PERL5DB
2543 * is set, it will return the contents of that, otherwise a
2544 * compile-time require of perl5db.pl.
2552 const char * const pdb = PerlEnv_getenv("PERL5DB");
2556 SETERRNO(0,SS_NORMAL);
2557 return "BEGIN { require 'perl5db.pl' }";
2563 /* Encoded script support. filter_add() effectively inserts a
2564 * 'pre-processing' function into the current source input stream.
2565 * Note that the filter function only applies to the current source file
2566 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2568 * The datasv parameter (which may be NULL) can be used to pass
2569 * private data to this instance of the filter. The filter function
2570 * can recover the SV using the FILTER_DATA macro and use it to
2571 * store private buffers and state information.
2573 * The supplied datasv parameter is upgraded to a PVIO type
2574 * and the IoDIRP/IoANY field is used to store the function pointer,
2575 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2576 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2577 * private use must be set using malloc'd pointers.
2581 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2587 if (!PL_rsfp_filters)
2588 PL_rsfp_filters = newAV();
2591 SvUPGRADE(datasv, SVt_PVIO);
2592 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2593 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2594 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2595 IoANY(datasv), SvPV_nolen(datasv)));
2596 av_unshift(PL_rsfp_filters, 1);
2597 av_store(PL_rsfp_filters, 0, datasv) ;
2602 /* Delete most recently added instance of this filter function. */
2604 Perl_filter_del(pTHX_ filter_t funcp)
2610 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", FPTR2DPTR(XPVIO *, funcp)));
2612 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2614 /* if filter is on top of stack (usual case) just pop it off */
2615 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2616 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2617 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2618 IoANY(datasv) = (void *)NULL;
2619 sv_free(av_pop(PL_rsfp_filters));
2623 /* we need to search for the correct entry and clear it */
2624 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2628 /* Invoke the idxth filter function for the current rsfp. */
2629 /* maxlen 0 = read one text line */
2631 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2636 /* This API is bad. It should have been using unsigned int for maxlen.
2637 Not sure if we want to change the API, but if not we should sanity
2638 check the value here. */
2639 const unsigned int correct_length = maxlen < 0 ? INT_MAX : maxlen;
2641 if (!PL_rsfp_filters)
2643 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2644 /* Provide a default input filter to make life easy. */
2645 /* Note that we append to the line. This is handy. */
2646 DEBUG_P(PerlIO_printf(Perl_debug_log,
2647 "filter_read %d: from rsfp\n", idx));
2648 if (correct_length) {
2651 const int old_len = SvCUR(buf_sv);
2653 /* ensure buf_sv is large enough */
2654 SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2655 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2656 correct_length)) <= 0) {
2657 if (PerlIO_error(PL_rsfp))
2658 return -1; /* error */
2660 return 0 ; /* end of file */
2662 SvCUR_set(buf_sv, old_len + len) ;
2665 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2666 if (PerlIO_error(PL_rsfp))
2667 return -1; /* error */
2669 return 0 ; /* end of file */
2672 return SvCUR(buf_sv);
2674 /* Skip this filter slot if filter has been deleted */
2675 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2676 DEBUG_P(PerlIO_printf(Perl_debug_log,
2677 "filter_read %d: skipped (filter deleted)\n",
2679 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2681 /* Get function pointer hidden within datasv */
2682 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2683 DEBUG_P(PerlIO_printf(Perl_debug_log,
2684 "filter_read %d: via function %p (%s)\n",
2685 idx, datasv, SvPV_nolen_const(datasv)));
2686 /* Call function. The function is expected to */
2687 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2688 /* Return: <0:error, =0:eof, >0:not eof */
2689 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2693 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2696 #ifdef PERL_CR_FILTER
2697 if (!PL_rsfp_filters) {
2698 filter_add(S_cr_textfilter,NULL);
2701 if (PL_rsfp_filters) {
2703 SvCUR_set(sv, 0); /* start with empty line */
2704 if (FILTER_READ(0, sv, 0) > 0)
2705 return ( SvPVX(sv) ) ;
2710 return (sv_gets(sv, fp, append));
2714 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2719 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2723 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2724 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2726 return GvHV(gv); /* Foo:: */
2729 /* use constant CLASS => 'MyClass' */
2730 if ((gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV))) {
2732 if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2733 pkgname = SvPV_nolen_const(sv);
2737 return gv_stashpv(pkgname, FALSE);
2743 * The intent of this yylex wrapper is to minimize the changes to the
2744 * tokener when we aren't interested in collecting madprops. It remains
2745 * to be seen how successful this strategy will be...
2752 char *s = PL_bufptr;
2754 /* make sure PL_thiswhite is initialized */
2758 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
2759 if (PL_pending_ident)
2760 return S_pending_ident(aTHX);
2762 /* previous token ate up our whitespace? */
2763 if (!PL_lasttoke && PL_nextwhite) {
2764 PL_thiswhite = PL_nextwhite;
2768 /* isolate the token, and figure out where it is without whitespace */
2769 PL_realtokenstart = -1;
2773 assert(PL_curforce < 0);
2775 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
2776 if (!PL_thistoken) {
2777 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
2778 PL_thistoken = newSVpvn("",0);
2780 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
2781 PL_thistoken = newSVpvn(tstart, s - tstart);
2784 if (PL_thismad) /* install head */
2785 CURMAD('X', PL_thistoken);
2788 /* last whitespace of a sublex? */
2789 if (optype == ')' && PL_endwhite) {
2790 CURMAD('X', PL_endwhite);
2795 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
2796 if (!PL_thiswhite && !PL_endwhite && !optype) {
2797 sv_free(PL_thistoken);
2802 /* put off final whitespace till peg */
2803 if (optype == ';' && !PL_rsfp) {
2804 PL_nextwhite = PL_thiswhite;
2807 else if (PL_thisopen) {
2808 CURMAD('q', PL_thisopen);
2810 sv_free(PL_thistoken);
2814 /* Store actual token text as madprop X */
2815 CURMAD('X', PL_thistoken);
2819 /* add preceding whitespace as madprop _ */
2820 CURMAD('_', PL_thiswhite);
2824 /* add quoted material as madprop = */
2825 CURMAD('=', PL_thisstuff);
2829 /* add terminating quote as madprop Q */
2830 CURMAD('Q', PL_thisclose);
2834 /* special processing based on optype */
2838 /* opval doesn't need a TOKEN since it can already store mp */
2849 append_madprops(PL_thismad, yylval.opval, 0);
2857 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
2866 /* remember any fake bracket that lexer is about to discard */
2867 if (PL_lex_brackets == 1 &&
2868 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
2871 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2874 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
2875 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
2878 break; /* don't bother looking for trailing comment */
2887 /* attach a trailing comment to its statement instead of next token */
2891 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
2893 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
2895 if (*s == '\n' || *s == '#') {
2896 while (s < PL_bufend && *s != '\n')
2900 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
2901 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
2918 /* Create new token struct. Note: opvals return early above. */
2919 yylval.tkval = newTOKEN(optype, yylval, PL_thismad);
2926 S_tokenize_use(pTHX_ int is_use, char *s) {
2928 if (PL_expect != XSTATE)
2929 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
2930 is_use ? "use" : "no"));
2932 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
2933 s = force_version(s, TRUE);
2934 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
2935 start_force(PL_curforce);
2936 NEXTVAL_NEXTTOKE.opval = NULL;
2939 else if (*s == 'v') {
2940 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2941 s = force_version(s, FALSE);
2945 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2946 s = force_version(s, FALSE);
2948 yylval.ival = is_use;
2952 static const char* const exp_name[] =
2953 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2954 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
2961 Works out what to call the token just pulled out of the input
2962 stream. The yacc parser takes care of taking the ops we return and
2963 stitching them into a tree.
2969 if read an identifier
2970 if we're in a my declaration
2971 croak if they tried to say my($foo::bar)
2972 build the ops for a my() declaration
2973 if it's an access to a my() variable
2974 are we in a sort block?
2975 croak if my($a); $a <=> $b
2976 build ops for access to a my() variable
2977 if in a dq string, and they've said @foo and we can't find @foo
2979 build ops for a bareword
2980 if we already built the token before, use it.
2985 #pragma segment Perl_yylex
2991 register char *s = PL_bufptr;
2997 SV* tmp = newSVpvs("");
2998 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
2999 (IV)CopLINE(PL_curcop),
3000 lex_state_names[PL_lex_state],
3001 exp_name[PL_expect],
3002 pv_display(tmp, s, strlen(s), 0, 60));
3005 /* check if there's an identifier for us to look at */
3006 if (PL_pending_ident)
3007 return REPORT(S_pending_ident(aTHX));
3009 /* no identifier pending identification */
3011 switch (PL_lex_state) {
3013 case LEX_NORMAL: /* Some compilers will produce faster */
3014 case LEX_INTERPNORMAL: /* code if we comment these out. */
3018 /* when we've already built the next token, just pull it out of the queue */
3022 yylval = PL_nexttoke[PL_lasttoke].next_val;
3024 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3025 PL_nexttoke[PL_lasttoke].next_mad = 0;
3026 if (PL_thismad && PL_thismad->mad_key == '_') {
3027 PL_thiswhite = (SV*)PL_thismad->mad_val;
3028 PL_thismad->mad_val = 0;
3029 mad_free(PL_thismad);
3034 PL_lex_state = PL_lex_defer;
3035 PL_expect = PL_lex_expect;
3036 PL_lex_defer = LEX_NORMAL;
3037 if (!PL_nexttoke[PL_lasttoke].next_type)
3042 yylval = PL_nextval[PL_nexttoke];
3044 PL_lex_state = PL_lex_defer;
3045 PL_expect = PL_lex_expect;
3046 PL_lex_defer = LEX_NORMAL;
3050 /* FIXME - can these be merged? */
3051 return(PL_nexttoke[PL_lasttoke].next_type);
3053 return REPORT(PL_nexttype[PL_nexttoke]);
3056 /* interpolated case modifiers like \L \U, including \Q and \E.
3057 when we get here, PL_bufptr is at the \
3059 case LEX_INTERPCASEMOD:
3061 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3062 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3064 /* handle \E or end of string */
3065 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3067 if (PL_lex_casemods) {
3068 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3069 PL_lex_casestack[PL_lex_casemods] = '\0';
3071 if (PL_bufptr != PL_bufend
3072 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3074 PL_lex_state = LEX_INTERPCONCAT;
3077 PL_thistoken = newSVpvn("\\E",2);
3083 while (PL_bufptr != PL_bufend &&
3084 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3086 PL_thiswhite = newSVpvn("",0);
3087 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3091 if (PL_bufptr != PL_bufend)
3094 PL_lex_state = LEX_INTERPCONCAT;
3098 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3099 "### Saw case modifier\n"); });
3101 if (s[1] == '\\' && s[2] == 'E') {
3104 PL_thiswhite = newSVpvn("",0);
3105 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3108 PL_lex_state = LEX_INTERPCONCAT;
3113 if (!PL_madskills) /* when just compiling don't need correct */
3114 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3115 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3116 if ((*s == 'L' || *s == 'U') &&
3117 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3118 PL_lex_casestack[--PL_lex_casemods] = '\0';
3121 if (PL_lex_casemods > 10)
3122 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3123 PL_lex_casestack[PL_lex_casemods++] = *s;
3124 PL_lex_casestack[PL_lex_casemods] = '\0';
3125 PL_lex_state = LEX_INTERPCONCAT;
3126 start_force(PL_curforce);
3127 NEXTVAL_NEXTTOKE.ival = 0;
3129 start_force(PL_curforce);
3131 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3133 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3135 NEXTVAL_NEXTTOKE.ival = OP_LC;
3137 NEXTVAL_NEXTTOKE.ival = OP_UC;
3139 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3141 Perl_croak(aTHX_ "panic: yylex");
3143 SV* const tmpsv = newSVpvn("",0);
3144 Perl_sv_catpvf(aTHX_ tmpsv, "\\%c", *s);
3150 if (PL_lex_starts) {
3156 sv_free(PL_thistoken);
3157 PL_thistoken = newSVpvn("",0);
3160 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3161 if (PL_lex_casemods == 1 && PL_lex_inpat)
3170 case LEX_INTERPPUSH:
3171 return REPORT(sublex_push());
3173 case LEX_INTERPSTART:
3174 if (PL_bufptr == PL_bufend)
3175 return REPORT(sublex_done());
3176 DEBUG_T({ PerlIO_printf(Perl_debug_log,
3177 "### Interpolated variable\n"); });
3179 PL_lex_dojoin = (*PL_bufptr == '@');
3180 PL_lex_state = LEX_INTERPNORMAL;
3181 if (PL_lex_dojoin) {
3182 start_force(PL_curforce);
3183 NEXTVAL_NEXTTOKE.ival = 0;
3185 start_force(PL_curforce);
3186 force_ident("\"", '$');
3187 start_force(PL_curforce);
3188 NEXTVAL_NEXTTOKE.ival = 0;
3190 start_force(PL_curforce);
3191 NEXTVAL_NEXTTOKE.ival = 0;
3193 start_force(PL_curforce);
3194 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
3197 if (PL_lex_starts++) {
3202 sv_free(PL_thistoken);
3203 PL_thistoken = newSVpvn("",0);
3206 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3207 if (!PL_lex_casemods && PL_lex_inpat)
3214 case LEX_INTERPENDMAYBE:
3215 if (intuit_more(PL_bufptr)) {
3216 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
3222 if (PL_lex_dojoin) {
3223 PL_lex_dojoin = FALSE;
3224 PL_lex_state = LEX_INTERPCONCAT;
3228 sv_free(PL_thistoken);
3229 PL_thistoken = newSVpvn("",0);
3234 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3235 && SvEVALED(PL_lex_repl))
3237 if (PL_bufptr != PL_bufend)
3238 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3242 case LEX_INTERPCONCAT:
3244 if (PL_lex_brackets)
3245 Perl_croak(aTHX_ "panic: INTERPCONCAT");
3247 if (PL_bufptr == PL_bufend)
3248 return REPORT(sublex_done());
3250 if (SvIVX(PL_linestr) == '\'') {
3251 SV *sv = newSVsv(PL_linestr);
3254 else if ( PL_hints & HINT_NEW_RE )
3255 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
3256 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3260 s = scan_const(PL_bufptr);
3262 PL_lex_state = LEX_INTERPCASEMOD;
3264 PL_lex_state = LEX_INTERPSTART;
3267 if (s != PL_bufptr) {
3268 start_force(PL_curforce);
3270 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3272 NEXTVAL_NEXTTOKE = yylval;
3275 if (PL_lex_starts++) {
3279 sv_free(PL_thistoken);
3280 PL_thistoken = newSVpvn("",0);
3283 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3284 if (!PL_lex_casemods && PL_lex_inpat)
3297 PL_lex_state = LEX_NORMAL;
3298 s = scan_formline(PL_bufptr);
3299 if (!PL_lex_formbrack)
3305 PL_oldoldbufptr = PL_oldbufptr;
3311 sv_free(PL_thistoken);
3314 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
3318 if (isIDFIRST_lazy_if(s,UTF))
3320 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
3323 goto fake_eof; /* emulate EOF on ^D or ^Z */
3332 if (PL_lex_brackets) {
3333 yyerror(PL_lex_formbrack
3334 ? "Format not terminated"
3335 : "Missing right curly or square bracket");
3337 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3338 "### Tokener got EOF\n");
3342 if (s++ < PL_bufend)
3343 goto retry; /* ignore stray nulls */
3346 if (!PL_in_eval && !PL_preambled) {
3347 PL_preambled = TRUE;
3352 sv_setpv(PL_linestr,incl_perldb());
3353 if (SvCUR(PL_linestr))
3354 sv_catpvs(PL_linestr,";");
3356 while(AvFILLp(PL_preambleav) >= 0) {
3357 SV *tmpsv = av_shift(PL_preambleav);
3358 sv_catsv(PL_linestr, tmpsv);
3359 sv_catpvs(PL_linestr, ";");
3362 sv_free((SV*)PL_preambleav);
3363 PL_preambleav = NULL;
3365 if (PL_minus_n || PL_minus_p) {
3366 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3368 sv_catpvs(PL_linestr,"chomp;");
3371 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3372 || *PL_splitstr == '"')
3373 && strchr(PL_splitstr + 1, *PL_splitstr))
3374 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3376 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3377 bytes can be used as quoting characters. :-) */
3378 const char *splits = PL_splitstr;
3379 sv_catpvs(PL_linestr, "our @F=split(q\0");
3382 if (*splits == '\\')
3383 sv_catpvn(PL_linestr, splits, 1);
3384 sv_catpvn(PL_linestr, splits, 1);
3385 } while (*splits++);
3386 /* This loop will embed the trailing NUL of
3387 PL_linestr as the last thing it does before
3389 sv_catpvs(PL_linestr, ");");
3393 sv_catpvs(PL_linestr,"our @F=split(' ');");
3397 sv_catpvs(PL_linestr,"use feature ':5.10';");
3398 sv_catpvs(PL_linestr, "\n");
3399 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3400 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3401 PL_last_lop = PL_last_uni = NULL;
3402 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3403 SV * const sv = newSV(0);
3405 sv_upgrade(sv, SVt_PVMG);
3406 sv_setsv(sv,PL_linestr);
3409 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3414 bof = PL_rsfp ? TRUE : FALSE;
3415 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3418 PL_realtokenstart = -1;
3421 if (PL_preprocess && !PL_in_eval)
3422 (void)PerlProc_pclose(PL_rsfp);
3423 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3424 PerlIO_clearerr(PL_rsfp);
3426 (void)PerlIO_close(PL_rsfp);
3428 PL_doextract = FALSE;
3430 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3435 sv_setpv(PL_linestr,PL_minus_p
3436 ? ";}continue{print;}" : ";}");
3437 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3438 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3439 PL_last_lop = PL_last_uni = NULL;
3440 PL_minus_n = PL_minus_p = 0;
3443 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3444 PL_last_lop = PL_last_uni = NULL;
3445 sv_setpvn(PL_linestr,"",0);
3446 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3448 /* If it looks like the start of a BOM or raw UTF-16,
3449 * check if it in fact is. */
3455 #ifdef PERLIO_IS_STDIO
3456 # ifdef __GNU_LIBRARY__
3457 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3458 # define FTELL_FOR_PIPE_IS_BROKEN
3462 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3463 # define FTELL_FOR_PIPE_IS_BROKEN
3468 #ifdef FTELL_FOR_PIPE_IS_BROKEN
3469 /* This loses the possibility to detect the bof
3470 * situation on perl -P when the libc5 is being used.
3471 * Workaround? Maybe attach some extra state to PL_rsfp?
3474 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
3476 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3479 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3480 s = swallow_bom((U8*)s);
3484 /* Incest with pod. */
3487 sv_catsv(PL_thiswhite, PL_linestr);
3489 if (*s == '=' && strnEQ(s, "=cut", 4)) {
3490 sv_setpvn(PL_linestr, "", 0);
3491 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3492 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3493 PL_last_lop = PL_last_uni = NULL;
3494 PL_doextract = FALSE;
3498 } while (PL_doextract);
3499 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3500 if (PERLDB_LINE && PL_curstash != PL_debstash) {
3501 SV * const sv = newSV(0);
3503 sv_upgrade(sv, SVt_PVMG);
3504 sv_setsv(sv,PL_linestr);
3507 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
3509 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3510 PL_last_lop = PL_last_uni = NULL;
3511 if (CopLINE(PL_curcop) == 1) {
3512 while (s < PL_bufend && isSPACE(*s))
3514 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3518 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3522 if (*s == '#' && *(s+1) == '!')
3524 #ifdef ALTERNATE_SHEBANG
3526 static char const as[] = ALTERNATE_SHEBANG;
3527 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3528 d = s + (sizeof(as) - 1);
3530 #endif /* ALTERNATE_SHEBANG */
3539 while (*d && !isSPACE(*d))
3543 #ifdef ARG_ZERO_IS_SCRIPT
3544 if (ipathend > ipath) {
3546 * HP-UX (at least) sets argv[0] to the script name,
3547 * which makes $^X incorrect. And Digital UNIX and Linux,
3548 * at least, set argv[0] to the basename of the Perl
3549 * interpreter. So, having found "#!", we'll set it right.
3551 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3553 assert(SvPOK(x) || SvGMAGICAL(x));
3554 if (sv_eq(x, CopFILESV(PL_curcop))) {
3555 sv_setpvn(x, ipath, ipathend - ipath);
3561 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3562 const char * const lstart = SvPV_const(x,llen);
3564 bstart += blen - llen;
3565 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3566 sv_setpvn(x, ipath, ipathend - ipath);
3571 TAINT_NOT; /* $^X is always tainted, but that's OK */
3573 #endif /* ARG_ZERO_IS_SCRIPT */
3578 d = instr(s,"perl -");
3580 d = instr(s,"perl");
3582 /* avoid getting into infinite loops when shebang
3583 * line contains "Perl" rather than "perl" */
3585 for (d = ipathend-4; d >= ipath; --d) {
3586 if ((*d == 'p' || *d == 'P')
3587 && !ibcmp(d, "perl", 4))
3597 #ifdef ALTERNATE_SHEBANG
3599 * If the ALTERNATE_SHEBANG on this system starts with a
3600 * character that can be part of a Perl expression, then if
3601 * we see it but not "perl", we're probably looking at the
3602 * start of Perl code, not a request to hand off to some
3603 * other interpreter. Similarly, if "perl" is there, but
3604 * not in the first 'word' of the line, we assume the line
3605 * contains the start of the Perl program.
3607 if (d && *s != '#') {
3608 const char *c = ipath;
3609 while (*c && !strchr("; \t\r\n\f\v#", *c))
3612 d = NULL; /* "perl" not in first word; ignore */
3614 *s = '#'; /* Don't try to parse shebang line */
3616 #endif /* ALTERNATE_SHEBANG */
3617 #ifndef MACOS_TRADITIONAL
3622 !instr(s,"indir") &&
3623 instr(PL_origargv[0],"perl"))
3630 while (s < PL_bufend && isSPACE(*s))
3632 if (s < PL_bufend) {
3633 Newxz(newargv,PL_origargc+3,char*);
3635 while (s < PL_bufend && !isSPACE(*s))
3638 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3641 newargv = PL_origargv;
3644 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3646 Perl_croak(aTHX_ "Can't exec %s", ipath);
3650 while (*d && !isSPACE(*d)) d++;
3651 while (SPACE_OR_TAB(*d)) d++;
3654 const bool switches_done = PL_doswitches;
3655 const U32 oldpdb = PL_perldb;
3656 const bool oldn = PL_minus_n;
3657 const bool oldp = PL_minus_p;
3660 if (*d == 'M' || *d == 'm' || *d == 'C') {
3661 const char * const m = d;
3662 while (*d && !isSPACE(*d))
3664 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3667 d = moreswitches(d);
3669 if (PL_doswitches && !switches_done) {
3670 int argc = PL_origargc;
3671 char **argv = PL_origargv;
3674 } while (argc && argv[0][0] == '-' && argv[0][1]);
3675 init_argv_symbols(argc,argv);
3677 if ((PERLDB_LINE && !oldpdb) ||
3678 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3679 /* if we have already added "LINE: while (<>) {",
3680 we must not do it again */
3682 sv_setpvn(PL_linestr, "", 0);
3683 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3684 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3685 PL_last_lop = PL_last_uni = NULL;
3686 PL_preambled = FALSE;
3688 (void)gv_fetchfile(PL_origfilename);
3695 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3697 PL_lex_state = LEX_FORMLINE;
3702 #ifdef PERL_STRICT_CR
3703 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3705 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3707 case ' ': case '\t': case '\f': case 013:
3708 #ifdef MACOS_TRADITIONAL
3712 PL_realtokenstart = -1;
3721 PL_realtokenstart = -1;
3725 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3726 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3727 /* handle eval qq[#line 1 "foo"\n ...] */
3728 CopLINE_dec(PL_curcop);
3731 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3733 if (!PL_in_eval || PL_rsfp)
3738 while (d < PL_bufend && *d != '\n')
3742 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3743 Perl_croak(aTHX_ "panic: input overflow");
3746 PL_thiswhite = newSVpvn(s, d - s);
3751 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3753 PL_lex_state = LEX_FORMLINE;
3759 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3760 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3763 TOKEN(PEG); /* make sure any #! line is accessible */
3768 /* if (PL_madskills && PL_lex_formbrack) { */
3770 while (d < PL_bufend && *d != '\n')
3774 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3775 Perl_croak(aTHX_ "panic: input overflow");
3776 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3778 PL_thiswhite = newSVpvn("",0);
3779 if (CopLINE(PL_curcop) == 1) {
3780 sv_setpvn(PL_thiswhite, "", 0);
3783 sv_catpvn(PL_thiswhite, s, d - s);
3797 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3805 while (s < PL_bufend && SPACE_OR_TAB(*s))
3808 if (strnEQ(s,"=>",2)) {
3809 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3810 DEBUG_T( { S_printbuf(aTHX_
3811 "### Saw unary minus before =>, forcing word %s\n", s);
3813 OPERATOR('-'); /* unary minus */
3815 PL_last_uni = PL_oldbufptr;
3817 case 'r': ftst = OP_FTEREAD; break;
3818 case 'w': ftst = OP_FTEWRITE; break;
3819 case 'x': ftst = OP_FTEEXEC; break;
3820 case 'o': ftst = OP_FTEOWNED; break;
3821 case 'R': ftst = OP_FTRREAD; break;
3822 case 'W': ftst = OP_FTRWRITE; break;
3823 case 'X': ftst = OP_FTREXEC; break;
3824 case 'O': ftst = OP_FTROWNED; break;
3825 case 'e': ftst = OP_FTIS; break;
3826 case 'z': ftst = OP_FTZERO; break;
3827 case 's': ftst = OP_FTSIZE; break;
3828 case 'f': ftst = OP_FTFILE; break;
3829 case 'd': ftst = OP_FTDIR; break;
3830 case 'l': ftst = OP_FTLINK; break;
3831 case 'p': ftst = OP_FTPIPE; break;
3832 case 'S': ftst = OP_FTSOCK; break;
3833 case 'u': ftst = OP_FTSUID; break;
3834 case 'g': ftst = OP_FTSGID; break;
3835 case 'k': ftst = OP_FTSVTX; break;
3836 case 'b': ftst = OP_FTBLK; break;
3837 case 'c': ftst = OP_FTCHR; break;
3838 case 't': ftst = OP_FTTTY; break;
3839 case 'T': ftst = OP_FTTEXT; break;
3840 case 'B': ftst = OP_FTBINARY; break;
3841 case 'M': case 'A': case 'C':
3842 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
3844 case 'M': ftst = OP_FTMTIME; break;
3845 case 'A': ftst = OP_FTATIME; break;
3846 case 'C': ftst = OP_FTCTIME; break;
3854 PL_last_lop_op = (OPCODE)ftst;
3855 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3856 "### Saw file test %c\n", (int)tmp);
3861 /* Assume it was a minus followed by a one-letter named
3862 * subroutine call (or a -bareword), then. */
3863 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3864 "### '-%c' looked like a file test but was not\n",
3871 const char tmp = *s++;
3874 if (PL_expect == XOPERATOR)
3879 else if (*s == '>') {
3882 if (isIDFIRST_lazy_if(s,UTF)) {
3883 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3891 if (PL_expect == XOPERATOR)
3894 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3896 OPERATOR('-'); /* unary minus */
3902 const char tmp = *s++;
3905 if (PL_expect == XOPERATOR)
3910 if (PL_expect == XOPERATOR)
3913 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3920 if (PL_expect != XOPERATOR) {
3921 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3922 PL_expect = XOPERATOR;
3923 force_ident(PL_tokenbuf, '*');
3936 if (PL_expect == XOPERATOR) {
3940 PL_tokenbuf[0] = '%';
3941 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3942 if (!PL_tokenbuf[1]) {
3945 PL_pending_ident = '%';
3956 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
3957 && FEATURE_IS_ENABLED("~~"))
3964 const char tmp = *s++;
3970 goto just_a_word_zero_gv;
3973 switch (PL_expect) {
3979 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3981 PL_bufptr = s; /* update in case we back off */
3987 PL_expect = XTERMBLOCK;
3990 stuffstart = s - SvPVX(PL_linestr) - 1;
3994 while (isIDFIRST_lazy_if(s,UTF)) {
3996 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3997 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
3998 if (tmp < 0) tmp = -tmp;
4014 d = scan_str(d,TRUE,TRUE);
4016 /* MUST advance bufptr here to avoid bogus
4017 "at end of line" context messages from yyerror().
4019 PL_bufptr = s + len;
4020 yyerror("Unterminated attribute parameter in attribute list");
4023 return REPORT(0); /* EOF indicator */
4027 SV *sv = newSVpvn(s, len);
4028 sv_catsv(sv, PL_lex_stuff);
4029 attrs = append_elem(OP_LIST, attrs,
4030 newSVOP(OP_CONST, 0, sv));
4031 SvREFCNT_dec(PL_lex_stuff);
4032 PL_lex_stuff = NULL;
4035 if (len == 6 && strnEQ(s, "unique", len)) {
4036 if (PL_in_my == KEY_our) {
4038 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4040 /* skip to avoid loading attributes.pm */
4042 deprecate(":unique");
4045 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4048 /* NOTE: any CV attrs applied here need to be part of
4049 the CVf_BUILTIN_ATTRS define in cv.h! */
4050 else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
4051 CvLVALUE_on(PL_compcv);
4052 else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
4053 CvLOCKED_on(PL_compcv);
4054 else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
4055 CvMETHOD_on(PL_compcv);
4056 else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len))
4057 CvASSERTION_on(PL_compcv);
4058 /* After we've set the flags, it could be argued that
4059 we don't need to do the attributes.pm-based setting
4060 process, and shouldn't bother appending recognized
4061 flags. To experiment with that, uncomment the
4062 following "else". (Note that's already been
4063 uncommented. That keeps the above-applied built-in
4064 attributes from being intercepted (and possibly
4065 rejected) by a package's attribute routines, but is
4066 justified by the performance win for the common case
4067 of applying only built-in attributes.) */
4069 attrs = append_elem(OP_LIST, attrs,
4070 newSVOP(OP_CONST, 0,
4074 if (*s == ':' && s[1] != ':')
4077 break; /* require real whitespace or :'s */
4078 /* XXX losing whitespace on sequential attributes here */
4082 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4083 if (*s != ';' && *s != '}' && *s != tmp
4084 && (tmp != '=' || *s != ')')) {
4085 const char q = ((*s == '\'') ? '"' : '\'');
4086 /* If here for an expression, and parsed no attrs, back
4088 if (tmp == '=' && !attrs) {
4092 /* MUST advance bufptr here to avoid bogus "at end of line"
4093 context messages from yyerror().
4097 ? Perl_form(aTHX_ "Invalid separator character "
4098 "%c%c%c in attribute list", q, *s, q)
4099 : "Unterminated attribute list" );
4107 start_force(PL_curforce);
4108 NEXTVAL_NEXTTOKE.opval = attrs;
4109 CURMAD('_', PL_nextwhite);
4114 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4115 (s - SvPVX(PL_linestr)) - stuffstart);
4123 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4124 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
4132 const char tmp = *s++;
4137 const char tmp = *s++;
4145 if (PL_lex_brackets <= 0)
4146 yyerror("Unmatched right square bracket");
4149 if (PL_lex_state == LEX_INTERPNORMAL) {
4150 if (PL_lex_brackets == 0) {
4151 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4152 PL_lex_state = LEX_INTERPEND;
4159 if (PL_lex_brackets > 100) {
4160 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4162 switch (PL_expect) {
4164 if (PL_lex_formbrack) {
4168 if (PL_oldoldbufptr == PL_last_lop)
4169 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4171 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4172 OPERATOR(HASHBRACK);
4174 while (s < PL_bufend && SPACE_OR_TAB(*s))
4177 PL_tokenbuf[0] = '\0';
4178 if (d < PL_bufend && *d == '-') {
4179 PL_tokenbuf[0] = '-';
4181 while (d < PL_bufend && SPACE_OR_TAB(*d))
4184 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4185 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4187 while (d < PL_bufend && SPACE_OR_TAB(*d))
4190 const char minus = (PL_tokenbuf[0] == '-');
4191 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4199 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4204 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4209 if (PL_oldoldbufptr == PL_last_lop)
4210 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4212 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4215 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4217 /* This hack is to get the ${} in the message. */
4219 yyerror("syntax error");
4222 OPERATOR(HASHBRACK);
4224 /* This hack serves to disambiguate a pair of curlies
4225 * as being a block or an anon hash. Normally, expectation
4226 * determines that, but in cases where we're not in a
4227 * position to expect anything in particular (like inside
4228 * eval"") we have to resolve the ambiguity. This code
4229 * covers the case where the first term in the curlies is a
4230 * quoted string. Most other cases need to be explicitly
4231 * disambiguated by prepending a "+" before the opening
4232 * curly in order to force resolution as an anon hash.
4234 * XXX should probably propagate the outer expectation
4235 * into eval"" to rely less on this hack, but that could
4236 * potentially break current behavior of eval"".
4240 if (*s == '\'' || *s == '"' || *s == '`') {
4241 /* common case: get past first string, handling escapes */
4242 for (t++; t < PL_bufend && *t != *s;)
4243 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4247 else if (*s == 'q') {
4250 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4253 /* skip q//-like construct */
4255 char open, close, term;
4258 while (t < PL_bufend && isSPACE(*t))
4260 /* check for q => */
4261 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4262 OPERATOR(HASHBRACK);
4266 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4270 for (t++; t < PL_bufend; t++) {
4271 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4273 else if (*t == open)
4277 for (t++; t < PL_bufend; t++) {
4278 if (*t == '\\' && t+1 < PL_bufend)
4280 else if (*t == close && --brackets <= 0)
4282 else if (*t == open)
4289 /* skip plain q word */
4290 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4293 else if (isALNUM_lazy_if(t,UTF)) {
4295 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4298 while (t < PL_bufend && isSPACE(*t))
4300 /* if comma follows first term, call it an anon hash */
4301 /* XXX it could be a comma expression with loop modifiers */
4302 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4303 || (*t == '=' && t[1] == '>')))
4304 OPERATOR(HASHBRACK);
4305 if (PL_expect == XREF)
4308 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4314 yylval.ival = CopLINE(PL_curcop);
4315 if (isSPACE(*s) || *s == '#')
4316 PL_copline = NOLINE; /* invalidate current command line number */
4321 if (PL_lex_brackets <= 0)
4322 yyerror("Unmatched right curly bracket");
4324 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4325 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4326 PL_lex_formbrack = 0;
4327 if (PL_lex_state == LEX_INTERPNORMAL) {
4328 if (PL_lex_brackets == 0) {
4329 if (PL_expect & XFAKEBRACK) {
4330 PL_expect &= XENUMMASK;
4331 PL_lex_state = LEX_INTERPEND;
4336 PL_thiswhite = newSVpvn("",0);
4337 sv_catpvn(PL_thiswhite,"}",1);
4340 return yylex(); /* ignore fake brackets */
4342 if (*s == '-' && s[1] == '>')
4343 PL_lex_state = LEX_INTERPENDMAYBE;
4344 else if (*s != '[' && *s != '{')
4345 PL_lex_state = LEX_INTERPEND;
4348 if (PL_expect & XFAKEBRACK) {
4349 PL_expect &= XENUMMASK;
4351 return yylex(); /* ignore fake brackets */
4353 start_force(PL_curforce);
4355 curmad('X', newSVpvn(s-1,1));
4356 CURMAD('_', PL_thiswhite);
4361 PL_thistoken = newSVpvn("",0);
4369 if (PL_expect == XOPERATOR) {
4370 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4371 && isIDFIRST_lazy_if(s,UTF))
4373 CopLINE_dec(PL_curcop);
4374 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4375 CopLINE_inc(PL_curcop);
4380 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4382 PL_expect = XOPERATOR;
4383 force_ident(PL_tokenbuf, '&');
4387 yylval.ival = (OPpENTERSUB_AMPER<<8);
4399 const char tmp = *s++;
4406 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4407 && strchr("+-*/%.^&|<",tmp))
4408 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4409 "Reversed %c= operator",(int)tmp);
4411 if (PL_expect == XSTATE && isALPHA(tmp) &&
4412 (s == PL_linestart+1 || s[-2] == '\n') )
4414 if (PL_in_eval && !PL_rsfp) {
4419 if (strnEQ(s,"=cut",4)) {
4435 PL_thiswhite = newSVpvn("",0);
4436 sv_catpvn(PL_thiswhite, PL_linestart,
4437 PL_bufend - PL_linestart);
4441 PL_doextract = TRUE;
4445 if (PL_lex_brackets < PL_lex_formbrack) {
4447 #ifdef PERL_STRICT_CR
4448 for (t = s; SPACE_OR_TAB(*t); t++) ;
4450 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
4452 if (*t == '\n' || *t == '#') {
4463 const char tmp = *s++;
4465 /* was this !=~ where !~ was meant?
4466 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4468 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4469 const char *t = s+1;
4471 while (t < PL_bufend && isSPACE(*t))
4474 if (*t == '/' || *t == '?' ||
4475 ((*t == 'm' || *t == 's' || *t == 'y')
4476 && !isALNUM(t[1])) ||
4477 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4478 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4479 "!=~ should be !~");
4489 if (PL_expect != XOPERATOR) {
4490 if (s[1] != '<' && !strchr(s,'>'))
4493 s = scan_heredoc(s);
4495 s = scan_inputsymbol(s);
4496 TERM(sublex_start());
4502 SHop(OP_LEFT_SHIFT);
4516 const char tmp = *s++;
4518 SHop(OP_RIGHT_SHIFT);
4519 else if (tmp == '=')
4528 if (PL_expect == XOPERATOR) {
4529 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4531 deprecate_old(commaless_variable_list);
4532 return REPORT(','); /* grandfather non-comma-format format */
4536 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4537 PL_tokenbuf[0] = '@';
4538 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4539 sizeof PL_tokenbuf - 1, FALSE);
4540 if (PL_expect == XOPERATOR)
4541 no_op("Array length", s);
4542 if (!PL_tokenbuf[1])
4544 PL_expect = XOPERATOR;
4545 PL_pending_ident = '#';
4549 PL_tokenbuf[0] = '$';
4550 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4551 sizeof PL_tokenbuf - 1, FALSE);
4552 if (PL_expect == XOPERATOR)
4554 if (!PL_tokenbuf[1]) {
4556 yyerror("Final $ should be \\$ or $name");
4560 /* This kludge not intended to be bulletproof. */
4561 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4562 yylval.opval = newSVOP(OP_CONST, 0,
4563 newSViv(CopARYBASE_get(&PL_compiling)));
4564 yylval.opval->op_private = OPpCONST_ARYBASE;
4570 const char tmp = *s;
4571 if (PL_lex_state == LEX_NORMAL)
4574 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4575 && intuit_more(s)) {
4577 PL_tokenbuf[0] = '@';
4578 if (ckWARN(WARN_SYNTAX)) {
4581 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
4584 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4585 while (t < PL_bufend && *t != ']')
4587 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4588 "Multidimensional syntax %.*s not supported",
4589 (int)((t - PL_bufptr) + 1), PL_bufptr);
4593 else if (*s == '{') {
4595 PL_tokenbuf[0] = '%';
4596 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4597 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4599 char tmpbuf[sizeof PL_tokenbuf];
4600 for (t++; isSPACE(*t); t++) ;
4601 if (isIDFIRST_lazy_if(t,UTF)) {
4603 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4605 for (; isSPACE(*t); t++) ;
4606 if (*t == ';' && get_cv(tmpbuf, FALSE))
4607 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4608 "You need to quote \"%s\"",
4615 PL_expect = XOPERATOR;
4616 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4617 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4618 if (!islop || PL_last_lop_op == OP_GREPSTART)
4619 PL_expect = XOPERATOR;
4620 else if (strchr("$@\"'`q", *s))
4621 PL_expect = XTERM; /* e.g. print $fh "foo" */
4622 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4623 PL_expect = XTERM; /* e.g. print $fh &sub */
4624 else if (isIDFIRST_lazy_if(s,UTF)) {
4625 char tmpbuf[sizeof PL_tokenbuf];
4627 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4628 if ((t2 = keyword(tmpbuf, len))) {
4629 /* binary operators exclude handle interpretations */
4641 PL_expect = XTERM; /* e.g. print $fh length() */
4646 PL_expect = XTERM; /* e.g. print $fh subr() */
4649 else if (isDIGIT(*s))
4650 PL_expect = XTERM; /* e.g. print $fh 3 */
4651 else if (*s == '.' && isDIGIT(s[1]))
4652 PL_expect = XTERM; /* e.g. print $fh .3 */
4653 else if ((*s == '?' || *s == '-' || *s == '+')
4654 && !isSPACE(s[1]) && s[1] != '=')
4655 PL_expect = XTERM; /* e.g. print $fh -1 */
4656 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4658 PL_expect = XTERM; /* e.g. print $fh /.../
4659 XXX except DORDOR operator
4661 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4663 PL_expect = XTERM; /* print $fh <<"EOF" */
4666 PL_pending_ident = '$';
4670 if (PL_expect == XOPERATOR)
4672 PL_tokenbuf[0] = '@';
4673 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4674 if (!PL_tokenbuf[1]) {
4677 if (PL_lex_state == LEX_NORMAL)
4679 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4681 PL_tokenbuf[0] = '%';
4683 /* Warn about @ where they meant $. */
4684 if (*s == '[' || *s == '{') {
4685 if (ckWARN(WARN_SYNTAX)) {
4686 const char *t = s + 1;
4687 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4689 if (*t == '}' || *t == ']') {
4691 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4692 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4693 "Scalar value %.*s better written as $%.*s",
4694 (int)(t-PL_bufptr), PL_bufptr,
4695 (int)(t-PL_bufptr-1), PL_bufptr+1);
4700 PL_pending_ident = '@';
4703 case '/': /* may be division, defined-or, or pattern */
4704 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4708 case '?': /* may either be conditional or pattern */
4709 if(PL_expect == XOPERATOR) {
4717 /* A // operator. */
4727 /* Disable warning on "study /blah/" */
4728 if (PL_oldoldbufptr == PL_last_uni
4729 && (*PL_last_uni != 's' || s - PL_last_uni < 5
4730 || memNE(PL_last_uni, "study", 5)
4731 || isALNUM_lazy_if(PL_last_uni+5,UTF)
4734 s = scan_pat(s,OP_MATCH);
4735 TERM(sublex_start());
4739 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4740 #ifdef PERL_STRICT_CR
4743 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4745 && (s == PL_linestart || s[-1] == '\n') )
4747 PL_lex_formbrack = 0;
4751 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4757 yylval.ival = OPf_SPECIAL;
4763 if (PL_expect != XOPERATOR)
4768 case '0': case '1': case '2': case '3': case '4':
4769 case '5': case '6': case '7': case '8': case '9':
4770 s = scan_num(s, &yylval);
4771 DEBUG_T( { S_printbuf(aTHX_ "### Saw number in %s\n", s); } );
4772 if (PL_expect == XOPERATOR)
4777 s = scan_str(s,!!PL_madskills,FALSE);
4778 DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } );
4779 if (PL_expect == XOPERATOR) {
4780 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4782 deprecate_old(commaless_variable_list);
4783 return REPORT(','); /* grandfather non-comma-format format */
4790 yylval.ival = OP_CONST;
4791 TERM(sublex_start());
4794 s = scan_str(s,!!PL_madskills,FALSE);
4795 DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } );
4796 if (PL_expect == XOPERATOR) {
4797 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4799 deprecate_old(commaless_variable_list);
4800 return REPORT(','); /* grandfather non-comma-format format */
4807 yylval.ival = OP_CONST;
4808 /* FIXME. I think that this can be const if char *d is replaced by
4809 more localised variables. */
4810 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4811 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4812 yylval.ival = OP_STRINGIFY;
4816 TERM(sublex_start());
4819 s = scan_str(s,!!PL_madskills,FALSE);
4820 DEBUG_T( { S_printbuf(aTHX_ "### Saw backtick string before %s\n", s); } );
4821 if (PL_expect == XOPERATOR)
4822 no_op("Backticks",s);
4825 yylval.ival = OP_BACKTICK;
4827 TERM(sublex_start());
4831 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
4832 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
4834 if (PL_expect == XOPERATOR)
4835 no_op("Backslash",s);
4839 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
4840 char *start = s + 2;
4841 while (isDIGIT(*start) || *start == '_')
4843 if (*start == '.' && isDIGIT(start[1])) {
4844 s = scan_num(s, &yylval);
4847 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
4848 else if (!isALPHA(*start) && (PL_expect == XTERM
4849 || PL_expect == XREF || PL_expect == XSTATE
4850 || PL_expect == XTERMORDORDOR)) {
4851 /* XXX Use gv_fetchpvn rather than stomping on a const string */
4852 const char c = *start;
4855 gv = gv_fetchpv(s, 0, SVt_PVCV);
4858 s = scan_num(s, &yylval);
4865 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
4901 I32 orig_keyword = 0;
4906 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4908 /* Some keywords can be followed by any delimiter, including ':' */
4909 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
4910 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
4911 (PL_tokenbuf[0] == 'q' &&
4912 strchr("qwxr", PL_tokenbuf[1])))));
4914 /* x::* is just a word, unless x is "CORE" */
4915 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4919 while (d < PL_bufend && isSPACE(*d))
4920 d++; /* no comments skipped here, or s### is misparsed */
4922 /* Is this a label? */
4923 if (!tmp && PL_expect == XSTATE
4924 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4926 yylval.pval = savepv(PL_tokenbuf);
4931 /* Check for keywords */
4932 tmp = keyword(PL_tokenbuf, len);
4934 /* Is this a word before a => operator? */
4935 if (*d == '=' && d[1] == '>') {
4938 = (OP*)newSVOP(OP_CONST, 0,
4939 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
4940 yylval.opval->op_private = OPpCONST_BARE;
4944 if (tmp < 0) { /* second-class keyword? */
4945 GV *ogv = NULL; /* override (winner) */
4946 GV *hgv = NULL; /* hidden (loser) */
4947 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4949 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
4952 if (GvIMPORTED_CV(gv))
4954 else if (! CvMETHOD(cv))
4958 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4959 (gv = *gvp) != (GV*)&PL_sv_undef &&
4960 GvCVu(gv) && GvIMPORTED_CV(gv))
4967 tmp = 0; /* overridden by import or by GLOBAL */
4970 && -tmp==KEY_lock /* XXX generalizable kludge */
4972 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
4974 tmp = 0; /* any sub overrides "weak" keyword */
4976 else { /* no override */
4978 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
4979 Perl_warner(aTHX_ packWARN(WARN_MISC),
4980 "dump() better written as CORE::dump()");
4984 if (hgv && tmp != KEY_x && tmp != KEY_CORE
4985 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
4986 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4987 "Ambiguous call resolved as CORE::%s(), %s",
4988 GvENAME(hgv), "qualify as such or use &");
4995 default: /* not a keyword */
4996 /* Trade off - by using this evil construction we can pull the
4997 variable gv into the block labelled keylookup. If not, then
4998 we have to give it function scope so that the goto from the
4999 earlier ':' case doesn't bypass the initialisation. */
5001 just_a_word_zero_gv:
5009 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5012 SV *nextPL_nextwhite = 0;
5016 /* Get the rest if it looks like a package qualifier */
5018 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5020 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5023 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5024 *s == '\'' ? "'" : "::");
5029 if (PL_expect == XOPERATOR) {
5030 if (PL_bufptr == PL_linestart) {
5031 CopLINE_dec(PL_curcop);
5032 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5033 CopLINE_inc(PL_curcop);
5036 no_op("Bareword",s);
5039 /* Look for a subroutine with this name in current package,
5040 unless name is "Foo::", in which case Foo is a bearword
5041 (and a package name). */
5043 if (len > 2 && !PL_madskills &&
5044 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5046 if (ckWARN(WARN_BAREWORD)
5047 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5048 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5049 "Bareword \"%s\" refers to nonexistent package",
5052 PL_tokenbuf[len] = '\0';
5058 /* Mustn't actually add anything to a symbol table.
5059 But also don't want to "initialise" any placeholder
5060 constants that might already be there into full
5061 blown PVGVs with attached PVCV. */
5062 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5063 GV_NOADD_NOINIT, SVt_PVCV);
5068 /* if we saw a global override before, get the right name */
5071 sv = newSVpvs("CORE::GLOBAL::");
5072 sv_catpv(sv,PL_tokenbuf);
5075 /* If len is 0, newSVpv does strlen(), which is correct.
5076 If len is non-zero, then it will be the true length,
5077 and so the scalar will be created correctly. */
5078 sv = newSVpv(PL_tokenbuf,len);
5081 if (PL_madskills && !PL_thistoken) {
5082 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5083 PL_thistoken = newSVpv(start,s - start);
5084 PL_realtokenstart = s - SvPVX(PL_linestr);
5088 /* Presume this is going to be a bareword of some sort. */
5091 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5092 yylval.opval->op_private = OPpCONST_BARE;
5093 /* UTF-8 package name? */
5094 if (UTF && !IN_BYTES &&
5095 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5098 /* And if "Foo::", then that's what it certainly is. */
5103 /* Do the explicit type check so that we don't need to force
5104 the initialisation of the symbol table to have a real GV.
5105 Beware - gv may not really be a PVGV, cv may not really be
5106 a PVCV, (because of the space optimisations that gv_init
5107 understands) But they're true if for this symbol there is
5108 respectively a typeglob and a subroutine.
5110 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5111 /* Real typeglob, so get the real subroutine: */
5113 /* A proxy for a subroutine in this package? */
5114 : SvOK(gv) ? (CV *) gv : NULL)
5117 /* See if it's the indirect object for a list operator. */
5119 if (PL_oldoldbufptr &&
5120 PL_oldoldbufptr < PL_bufptr &&
5121 (PL_oldoldbufptr == PL_last_lop
5122 || PL_oldoldbufptr == PL_last_uni) &&
5123 /* NO SKIPSPACE BEFORE HERE! */
5124 (PL_expect == XREF ||
5125 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5127 bool immediate_paren = *s == '(';
5129 /* (Now we can afford to cross potential line boundary.) */
5130 s = SKIPSPACE2(s,nextPL_nextwhite);
5132 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5135 /* Two barewords in a row may indicate method call. */
5137 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5138 (tmp = intuit_method(s, gv, cv)))
5141 /* If not a declared subroutine, it's an indirect object. */
5142 /* (But it's an indir obj regardless for sort.) */
5143 /* Also, if "_" follows a filetest operator, it's a bareword */
5146 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5148 (PL_last_lop_op != OP_MAPSTART &&
5149 PL_last_lop_op != OP_GREPSTART))))
5150 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5151 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5154 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5159 PL_expect = XOPERATOR;
5162 s = SKIPSPACE2(s,nextPL_nextwhite);
5163 PL_nextwhite = nextPL_nextwhite;
5168 /* Is this a word before a => operator? */
5169 if (*s == '=' && s[1] == '>' && !pkgname) {
5171 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5172 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5173 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5177 /* If followed by a paren, it's certainly a subroutine. */
5181 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
5182 if (*d == ')' && (sv = gv_const_sv(gv))) {
5186 char *par = SvPVX(PL_linestr) + PL_realtokenstart;
5187 sv_catpvn(PL_thistoken, par, s - par);
5189 sv_free(PL_nextwhite);
5199 PL_nextwhite = PL_thiswhite;
5202 start_force(PL_curforce);
5204 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5205 PL_expect = XOPERATOR;
5208 PL_nextwhite = nextPL_nextwhite;
5209 curmad('X', PL_thistoken);
5210 PL_thistoken = newSVpvn("",0);
5218 /* If followed by var or block, call it a method (unless sub) */
5220 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5221 PL_last_lop = PL_oldbufptr;
5222 PL_last_lop_op = OP_METHOD;
5226 /* If followed by a bareword, see if it looks like indir obj. */
5229 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5230 && (tmp = intuit_method(s, gv, cv)))
5233 /* Not a method, so call it a subroutine (if defined) */
5236 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5237 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5238 "Ambiguous use of -%s resolved as -&%s()",
5239 PL_tokenbuf, PL_tokenbuf);
5240 /* Check for a constant sub */
5241 if ((sv = gv_const_sv(gv))) {
5243 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5244 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5245 yylval.opval->op_private = 0;
5249 /* Resolve to GV now. */
5250 if (SvTYPE(gv) != SVt_PVGV) {
5251 gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5252 assert (SvTYPE(gv) == SVt_PVGV);
5253 /* cv must have been some sort of placeholder, so
5254 now needs replacing with a real code reference. */
5258 op_free(yylval.opval);
5259 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5260 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5261 PL_last_lop = PL_oldbufptr;
5262 PL_last_lop_op = OP_ENTERSUB;
5263 /* Is there a prototype? */
5270 const char *proto = SvPV_const((SV*)cv, protolen);
5273 if (*proto == '$' && proto[1] == '\0')
5275 while (*proto == ';')
5277 if (*proto == '&' && *s == '{') {
5278 sv_setpv(PL_subname, PL_curstash ?
5279 "__ANON__" : "__ANON__::__ANON__");
5286 PL_nextwhite = PL_thiswhite;
5289 start_force(PL_curforce);
5290 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5293 PL_nextwhite = nextPL_nextwhite;
5294 curmad('X', PL_thistoken);
5295 PL_thistoken = newSVpvn("",0);
5302 /* Guess harder when madskills require "best effort". */
5303 if (PL_madskills && (!gv || !GvCVu(gv))) {
5304 int probable_sub = 0;
5305 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5307 else if (isALPHA(*s)) {
5311 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5312 if (!keyword(tmpbuf,tmplen))
5315 while (d < PL_bufend && isSPACE(*d))
5317 if (*d == '=' && d[1] == '>')
5322 gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5323 op_free(yylval.opval);
5324 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5325 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5326 PL_last_lop = PL_oldbufptr;
5327 PL_last_lop_op = OP_ENTERSUB;
5328 PL_nextwhite = PL_thiswhite;
5330 start_force(PL_curforce);
5331 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5333 PL_nextwhite = nextPL_nextwhite;
5334 curmad('X', PL_thistoken);
5335 PL_thistoken = newSVpvn("",0);
5340 NEXTVAL_NEXTTOKE.opval = yylval.opval;
5347 /* Call it a bare word */
5349 if (PL_hints & HINT_STRICT_SUBS)
5350 yylval.opval->op_private |= OPpCONST_STRICT;
5353 if (lastchar != '-') {
5354 if (ckWARN(WARN_RESERVED)) {
5355 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
5356 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
5357 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5364 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5365 && ckWARN_d(WARN_AMBIGUOUS)) {
5366 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5367 "Operator or semicolon missing before %c%s",
5368 lastchar, PL_tokenbuf);
5369 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5370 "Ambiguous use of %c resolved as operator %c",
5371 lastchar, lastchar);
5377 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5378 newSVpv(CopFILE(PL_curcop),0));
5382 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5383 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5386 case KEY___PACKAGE__:
5387 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5389 ? newSVhek(HvNAME_HEK(PL_curstash))
5396 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5397 const char *pname = "main";
5398 if (PL_tokenbuf[2] == 'D')
5399 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5400 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5404 GvIOp(gv) = newIO();
5405 IoIFP(GvIOp(gv)) = PL_rsfp;
5406 #if defined(HAS_FCNTL) && defined(F_SETFD)
5408 const int fd = PerlIO_fileno(PL_rsfp);
5409 fcntl(fd,F_SETFD,fd >= 3);
5412 /* Mark this internal pseudo-handle as clean */
5413 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5415 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5416 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5417 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5419 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5420 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5421 /* if the script was opened in binmode, we need to revert
5422 * it to text mode for compatibility; but only iff it has CRs
5423 * XXX this is a questionable hack at best. */
5424 if (PL_bufend-PL_bufptr > 2
5425 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5428 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5429 loc = PerlIO_tell(PL_rsfp);
5430 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5433 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5435 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5436 #endif /* NETWARE */
5437 #ifdef PERLIO_IS_STDIO /* really? */
5438 # if defined(__BORLANDC__)
5439 /* XXX see note in do_binmode() */
5440 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5444 PerlIO_seek(PL_rsfp, loc, 0);
5448 #ifdef PERLIO_LAYERS
5451 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5452 else if (PL_encoding) {
5459 XPUSHs(PL_encoding);
5461 call_method("name", G_SCALAR);
5465 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5466 Perl_form(aTHX_ ":encoding(%"SVf")",
5475 if (PL_realtokenstart >= 0) {
5476 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5478 PL_endwhite = newSVpvn("",0);
5479 sv_catsv(PL_endwhite, PL_thiswhite);
5481 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5482 PL_realtokenstart = -1;
5484 while ((s = filter_gets(PL_endwhite, PL_rsfp,
5485 SvCUR(PL_endwhite))) != Nullch) ;
5499 if (PL_expect == XSTATE) {
5506 if (*s == ':' && s[1] == ':') {
5509 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5510 if (!(tmp = keyword(PL_tokenbuf, len)))
5511 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5514 else if (tmp == KEY_require || tmp == KEY_do)
5515 /* that's a way to remember we saw "CORE::" */
5528 LOP(OP_ACCEPT,XTERM);
5534 LOP(OP_ATAN2,XTERM);
5540 LOP(OP_BINMODE,XTERM);
5543 LOP(OP_BLESS,XTERM);
5552 /* When 'use switch' is in effect, continue has a dual
5553 life as a control operator. */
5555 if (!FEATURE_IS_ENABLED("switch"))
5558 /* We have to disambiguate the two senses of
5559 "continue". If the next token is a '{' then
5560 treat it as the start of a continue block;
5561 otherwise treat it as a control operator.
5573 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5590 if (!PL_cryptseen) {
5591 PL_cryptseen = TRUE;
5595 LOP(OP_CRYPT,XTERM);
5598 LOP(OP_CHMOD,XTERM);
5601 LOP(OP_CHOWN,XTERM);
5604 LOP(OP_CONNECT,XTERM);
5623 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5624 if (orig_keyword == KEY_do) {
5633 PL_hints |= HINT_BLOCK_SCOPE;
5643 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5644 LOP(OP_DBMOPEN,XTERM);
5650 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5657 yylval.ival = CopLINE(PL_curcop);
5673 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5674 UNIBRACK(OP_ENTEREVAL);
5692 case KEY_endhostent:
5698 case KEY_endservent:
5701 case KEY_endprotoent:
5712 yylval.ival = CopLINE(PL_curcop);
5714 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5717 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5720 if ((PL_bufend - p) >= 3 &&
5721 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5723 else if ((PL_bufend - p) >= 4 &&
5724 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5727 if (isIDFIRST_lazy_if(p,UTF)) {
5728 p = scan_ident(p, PL_bufend,
5729 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5733 Perl_croak(aTHX_ "Missing $ on loop variable");
5735 s = SvPVX(PL_linestr) + soff;
5741 LOP(OP_FORMLINE,XTERM);
5747 LOP(OP_FCNTL,XTERM);
5753 LOP(OP_FLOCK,XTERM);
5762 LOP(OP_GREPSTART, XREF);
5765 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5780 case KEY_getpriority:
5781 LOP(OP_GETPRIORITY,XTERM);
5783 case KEY_getprotobyname:
5786 case KEY_getprotobynumber:
5787 LOP(OP_GPBYNUMBER,XTERM);
5789 case KEY_getprotoent:
5801 case KEY_getpeername:
5802 UNI(OP_GETPEERNAME);
5804 case KEY_gethostbyname:
5807 case KEY_gethostbyaddr:
5808 LOP(OP_GHBYADDR,XTERM);
5810 case KEY_gethostent:
5813 case KEY_getnetbyname:
5816 case KEY_getnetbyaddr:
5817 LOP(OP_GNBYADDR,XTERM);
5822 case KEY_getservbyname:
5823 LOP(OP_GSBYNAME,XTERM);
5825 case KEY_getservbyport:
5826 LOP(OP_GSBYPORT,XTERM);
5828 case KEY_getservent:
5831 case KEY_getsockname:
5832 UNI(OP_GETSOCKNAME);
5834 case KEY_getsockopt:
5835 LOP(OP_GSOCKOPT,XTERM);
5850 yylval.ival = CopLINE(PL_curcop);
5861 yylval.ival = CopLINE(PL_curcop);
5865 LOP(OP_INDEX,XTERM);
5871 LOP(OP_IOCTL,XTERM);
5883 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5915 LOP(OP_LISTEN,XTERM);
5924 s = scan_pat(s,OP_MATCH);
5925 TERM(sublex_start());
5928 LOP(OP_MAPSTART, XREF);
5931 LOP(OP_MKDIR,XTERM);
5934 LOP(OP_MSGCTL,XTERM);
5937 LOP(OP_MSGGET,XTERM);
5940 LOP(OP_MSGRCV,XTERM);
5943 LOP(OP_MSGSND,XTERM);
5949 if (isIDFIRST_lazy_if(s,UTF)) {
5953 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
5954 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
5956 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
5957 if (!PL_in_my_stash) {
5960 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
5964 if (PL_madskills) { /* just add type to declarator token */
5965 sv_catsv(PL_thistoken, PL_nextwhite);
5967 sv_catpvn(PL_thistoken, start, s - start);
5975 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5982 s = tokenize_use(0, s);
5986 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
5993 if (isIDFIRST_lazy_if(s,UTF)) {
5995 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
5996 for (t=d; *t && isSPACE(*t); t++) ;
5997 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
5999 && !(t[0] == '=' && t[1] == '>')
6001 int parms_len = (int)(d-s);
6002 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6003 "Precedence problem: open %.*s should be open(%.*s)",
6004 parms_len, s, parms_len, s);
6010 yylval.ival = OP_OR;
6020 LOP(OP_OPEN_DIR,XTERM);
6023 checkcomma(s,PL_tokenbuf,"filehandle");
6027 checkcomma(s,PL_tokenbuf,"filehandle");
6046 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6050 LOP(OP_PIPE_OP,XTERM);
6053 s = scan_str(s,!!PL_madskills,FALSE);
6056 yylval.ival = OP_CONST;
6057 TERM(sublex_start());
6063 s = scan_str(s,!!PL_madskills,FALSE);
6066 PL_expect = XOPERATOR;
6068 if (SvCUR(PL_lex_stuff)) {
6071 d = SvPV_force(PL_lex_stuff, len);
6073 for (; isSPACE(*d) && len; --len, ++d)
6078 if (!warned && ckWARN(WARN_QW)) {
6079 for (; !isSPACE(*d) && len; --len, ++d) {
6081 Perl_warner(aTHX_ packWARN(WARN_QW),
6082 "Possible attempt to separate words with commas");
6085 else if (*d == '#') {
6086 Perl_warner(aTHX_ packWARN(WARN_QW),
6087 "Possible attempt to put comments in qw() list");
6093 for (; !isSPACE(*d) && len; --len, ++d)
6096 sv = newSVpvn(b, d-b);
6097 if (DO_UTF8(PL_lex_stuff))
6099 words = append_elem(OP_LIST, words,
6100 newSVOP(OP_CONST, 0, tokeq(sv)));
6104 start_force(PL_curforce);
6105 NEXTVAL_NEXTTOKE.opval = words;
6110 SvREFCNT_dec(PL_lex_stuff);
6111 PL_lex_stuff = NULL;
6117 s = scan_str(s,!!PL_madskills,FALSE);
6120 yylval.ival = OP_STRINGIFY;
6121 if (SvIVX(PL_lex_stuff) == '\'')
6122 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
6123 TERM(sublex_start());
6126 s = scan_pat(s,OP_QR);
6127 TERM(sublex_start());
6130 s = scan_str(s,!!PL_madskills,FALSE);
6133 yylval.ival = OP_BACKTICK;
6135 TERM(sublex_start());
6143 s = force_version(s, FALSE);
6145 else if (*s != 'v' || !isDIGIT(s[1])
6146 || (s = force_version(s, TRUE), *s == 'v'))
6148 *PL_tokenbuf = '\0';
6149 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6150 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6151 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6153 yyerror("<> should be quotes");
6155 if (orig_keyword == KEY_require) {
6163 PL_last_uni = PL_oldbufptr;
6164 PL_last_lop_op = OP_REQUIRE;
6166 return REPORT( (int)REQUIRE );
6172 s = force_word(s,WORD,TRUE,FALSE,FALSE);
6176 LOP(OP_RENAME,XTERM);
6185 LOP(OP_RINDEX,XTERM);
6195 UNIDOR(OP_READLINE);
6208 LOP(OP_REVERSE,XTERM);
6211 UNIDOR(OP_READLINK);
6219 TERM(sublex_start());
6221 TOKEN(1); /* force error */
6224 checkcomma(s,PL_tokenbuf,"filehandle");
6234 LOP(OP_SELECT,XTERM);
6240 LOP(OP_SEMCTL,XTERM);
6243 LOP(OP_SEMGET,XTERM);
6246 LOP(OP_SEMOP,XTERM);
6252 LOP(OP_SETPGRP,XTERM);
6254 case KEY_setpriority:
6255 LOP(OP_SETPRIORITY,XTERM);
6257 case KEY_sethostent:
6263 case KEY_setservent:
6266 case KEY_setprotoent:
6276 LOP(OP_SEEKDIR,XTERM);
6278 case KEY_setsockopt:
6279 LOP(OP_SSOCKOPT,XTERM);
6285 LOP(OP_SHMCTL,XTERM);
6288 LOP(OP_SHMGET,XTERM);
6291 LOP(OP_SHMREAD,XTERM);
6294 LOP(OP_SHMWRITE,XTERM);
6297 LOP(OP_SHUTDOWN,XTERM);
6306 LOP(OP_SOCKET,XTERM);
6308 case KEY_socketpair:
6309 LOP(OP_SOCKPAIR,XTERM);
6312 checkcomma(s,PL_tokenbuf,"subroutine name");
6314 if (*s == ';' || *s == ')') /* probably a close */
6315 Perl_croak(aTHX_ "sort is now a reserved word");
6317 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6321 LOP(OP_SPLIT,XTERM);
6324 LOP(OP_SPRINTF,XTERM);
6327 LOP(OP_SPLICE,XTERM);
6342 LOP(OP_SUBSTR,XTERM);
6348 char tmpbuf[sizeof PL_tokenbuf];
6349 SSize_t tboffset = 0;
6350 expectation attrful;
6351 bool have_name, have_proto, bad_proto;
6352 const int key = tmp;
6357 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6358 SV *subtoken = newSVpvn(tstart, s - tstart);
6362 s = SKIPSPACE2(s,tmpwhite);
6367 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6368 (*s == ':' && s[1] == ':'))
6375 attrful = XATTRBLOCK;
6376 /* remember buffer pos'n for later force_word */
6377 tboffset = s - PL_oldbufptr;
6378 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6381 nametoke = newSVpvn(s, d - s);
6383 if (strchr(tmpbuf, ':'))
6384 sv_setpv(PL_subname, tmpbuf);
6386 sv_setsv(PL_subname,PL_curstname);
6387 sv_catpvs(PL_subname,"::");
6388 sv_catpvn(PL_subname,tmpbuf,len);
6395 CURMAD('X', nametoke);
6396 CURMAD('_', tmpwhite);
6397 (void) force_word(PL_oldbufptr + tboffset, WORD,
6400 s = SKIPSPACE2(d,tmpwhite);
6407 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6408 PL_expect = XTERMBLOCK;
6409 attrful = XATTRTERM;
6410 sv_setpvn(PL_subname,"?",1);
6414 if (key == KEY_format) {
6416 PL_lex_formbrack = PL_lex_brackets + 1;
6418 PL_thistoken = subtoken;
6422 (void) force_word(PL_oldbufptr + tboffset, WORD,
6428 /* Look for a prototype */
6432 s = scan_str(s,!!PL_madskills,FALSE);
6434 Perl_croak(aTHX_ "Prototype not terminated");
6435 /* strip spaces and check for bad characters */
6436 d = SvPVX(PL_lex_stuff);
6439 for (p = d; *p; ++p) {
6442 if (!strchr("$@%*;[]&\\", *p))
6447 if (bad_proto && ckWARN(WARN_SYNTAX))
6448 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6449 "Illegal character in prototype for %"SVf" : %s",
6451 SvCUR_set(PL_lex_stuff, tmp);
6456 CURMAD('q', PL_thisopen);
6457 CURMAD('_', tmpwhite);
6458 CURMAD('=', PL_thisstuff);
6459 CURMAD('Q', PL_thisclose);
6460 NEXTVAL_NEXTTOKE.opval =
6461 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6462 PL_lex_stuff = Nullsv;
6465 s = SKIPSPACE2(s,tmpwhite);
6473 if (*s == ':' && s[1] != ':')
6474 PL_expect = attrful;
6475 else if (*s != '{' && key == KEY_sub) {
6477 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6479 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname);
6486 curmad('^', newSVpvn("",0));
6487 CURMAD('_', tmpwhite);
6491 PL_thistoken = subtoken;
6494 NEXTVAL_NEXTTOKE.opval =
6495 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6496 PL_lex_stuff = NULL;
6501 sv_setpv(PL_subname,
6502 PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
6506 (void) force_word(PL_oldbufptr + tboffset, WORD,
6516 LOP(OP_SYSTEM,XREF);
6519 LOP(OP_SYMLINK,XTERM);
6522 LOP(OP_SYSCALL,XTERM);
6525 LOP(OP_SYSOPEN,XTERM);
6528 LOP(OP_SYSSEEK,XTERM);
6531 LOP(OP_SYSREAD,XTERM);
6534 LOP(OP_SYSWRITE,XTERM);
6538 TERM(sublex_start());
6559 LOP(OP_TRUNCATE,XTERM);
6571 yylval.ival = CopLINE(PL_curcop);
6575 yylval.ival = CopLINE(PL_curcop);
6579 LOP(OP_UNLINK,XTERM);
6585 LOP(OP_UNPACK,XTERM);
6588 LOP(OP_UTIME,XTERM);
6594 LOP(OP_UNSHIFT,XTERM);
6597 s = tokenize_use(1, s);
6607 yylval.ival = CopLINE(PL_curcop);
6611 yylval.ival = CopLINE(PL_curcop);
6615 PL_hints |= HINT_BLOCK_SCOPE;
6622 LOP(OP_WAITPID,XTERM);
6631 ctl_l[0] = toCTRL('L');
6633 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6636 /* Make sure $^L is defined */
6637 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6642 if (PL_expect == XOPERATOR)
6648 yylval.ival = OP_XOR;
6653 TERM(sublex_start());
6658 #pragma segment Main
6662 S_pending_ident(pTHX)
6666 register I32 tmp = 0;
6667 /* pit holds the identifier we read and pending_ident is reset */
6668 char pit = PL_pending_ident;
6669 PL_pending_ident = 0;
6671 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6672 DEBUG_T({ PerlIO_printf(Perl_debug_log,
6673 "### Pending identifier '%s'\n", PL_tokenbuf); });
6675 /* if we're in a my(), we can't allow dynamics here.
6676 $foo'bar has already been turned into $foo::bar, so
6677 just check for colons.
6679 if it's a legal name, the OP is a PADANY.
6682 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
6683 if (strchr(PL_tokenbuf,':'))
6684 yyerror(Perl_form(aTHX_ "No package name allowed for "
6685 "variable %s in \"our\"",
6687 tmp = allocmy(PL_tokenbuf);
6690 if (strchr(PL_tokenbuf,':'))
6691 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
6693 yylval.opval = newOP(OP_PADANY, 0);
6694 yylval.opval->op_targ = allocmy(PL_tokenbuf);
6700 build the ops for accesses to a my() variable.
6702 Deny my($a) or my($b) in a sort block, *if* $a or $b is
6703 then used in a comparison. This catches most, but not
6704 all cases. For instance, it catches
6705 sort { my($a); $a <=> $b }
6707 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6708 (although why you'd do that is anyone's guess).
6711 if (!strchr(PL_tokenbuf,':')) {
6713 tmp = pad_findmy(PL_tokenbuf);
6714 if (tmp != NOT_IN_PAD) {
6715 /* might be an "our" variable" */
6716 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6717 /* build ops for a bareword */
6718 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
6719 HEK * const stashname = HvNAME_HEK(stash);
6720 SV * const sym = newSVhek(stashname);
6721 sv_catpvs(sym, "::");
6722 sv_catpv(sym, PL_tokenbuf+1);
6723 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6724 yylval.opval->op_private = OPpCONST_ENTERED;
6727 ? (GV_ADDMULTI | GV_ADDINEVAL)
6730 ((PL_tokenbuf[0] == '$') ? SVt_PV
6731 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6736 /* if it's a sort block and they're naming $a or $b */
6737 if (PL_last_lop_op == OP_SORT &&
6738 PL_tokenbuf[0] == '$' &&
6739 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6742 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6743 d < PL_bufend && *d != '\n';
6746 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6747 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6753 yylval.opval = newOP(OP_PADANY, 0);
6754 yylval.opval->op_targ = tmp;
6760 Whine if they've said @foo in a doublequoted string,
6761 and @foo isn't a variable we can find in the symbol
6764 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6765 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6766 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6767 && ckWARN(WARN_AMBIGUOUS))
6769 /* Downgraded from fatal to warning 20000522 mjd */
6770 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6771 "Possible unintended interpolation of %s in string",
6776 /* build ops for a bareword */
6777 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6778 yylval.opval->op_private = OPpCONST_ENTERED;
6781 /* If the identifier refers to a stash, don't autovivify it.
6782 * Change 24660 had the side effect of causing symbol table
6783 * hashes to always be defined, even if they were freshly
6784 * created and the only reference in the entire program was
6785 * the single statement with the defined %foo::bar:: test.
6786 * It appears that all code in the wild doing this actually
6787 * wants to know whether sub-packages have been loaded, so
6788 * by avoiding auto-vivifying symbol tables, we ensure that
6789 * defined %foo::bar:: continues to be false, and the existing
6790 * tests still give the expected answers, even though what
6791 * they're actually testing has now changed subtly.
6793 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6795 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
6796 ((PL_tokenbuf[0] == '$') ? SVt_PV
6797 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6803 * The following code was generated by perl_keyword.pl.
6807 Perl_keyword (pTHX_ const char *name, I32 len)
6812 case 1: /* 5 tokens of length 1 */
6844 case 2: /* 18 tokens of length 2 */
6990 case 3: /* 29 tokens of length 3 */
6994 if (name[1] == 'N' &&
7057 if (name[1] == 'i' &&
7079 return (FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7097 if (name[1] == 'o' &&
7106 if (name[1] == 'e' &&
7115 if (name[1] == 'n' &&
7124 if (name[1] == 'o' &&
7133 if (name[1] == 'a' &&
7142 if (name[1] == 'o' &&
7204 if (name[1] == 'e' &&
7218 return (FEATURE_IS_ENABLED("say") ? -KEY_say : 0);
7244 if (name[1] == 'i' &&
7253 if (name[1] == 's' &&
7262 if (name[1] == 'e' &&
7271 if (name[1] == 'o' &&
7283 case 4: /* 41 tokens of length 4 */
7287 if (name[1] == 'O' &&
7297 if (name[1] == 'N' &&
7307 if (name[1] == 'i' &&
7317 if (name[1] == 'h' &&
7327 if (name[1] == 'u' &&
7340 if (name[2] == 'c' &&
7349 if (name[2] == 's' &&
7358 if (name[2] == 'a' &&
7394 if (name[1] == 'o' &&
7407 if (name[2] == 't' &&
7416 if (name[2] == 'o' &&
7425 if (name[2] == 't' &&
7434 if (name[2] == 'e' &&
7447 if (name[1] == 'o' &&
7460 if (name[2] == 'y' &&
7469 if (name[2] == 'l' &&
7485 if (name[2] == 's' &&
7494 if (name[2] == 'n' &&
7503 if (name[2] == 'c' &&
7516 if (name[1] == 'e' &&
7526 if (name[1] == 'p' &&
7539 if (name[2] == 'c' &&
7548 if (name[2] == 'p' &&
7557 if (name[2] == 's' &&
7573 if (name[2] == 'n' &&
7643 if (name[2] == 'r' &&
7652 if (name[2] == 'r' &&
7661 if (name[2] == 'a' &&
7677 if (name[2] == 'l' &&
7739 if (name[2] == 'e' &&
7742 return (FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7755 case 5: /* 38 tokens of length 5 */
7759 if (name[1] == 'E' &&
7770 if (name[1] == 'H' &&
7784 if (name[2] == 'a' &&
7794 if (name[2] == 'a' &&
7811 if (name[2] == 'e' &&
7821 if (name[2] == 'e' &&
7825 return (FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
7841 if (name[3] == 'i' &&
7850 if (name[3] == 'o' &&
7886 if (name[2] == 'o' &&
7896 if (name[2] == 'y' &&
7910 if (name[1] == 'l' &&
7924 if (name[2] == 'n' &&
7934 if (name[2] == 'o' &&
7948 if (name[1] == 'i' &&
7953 return (FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
7962 if (name[2] == 'd' &&
7972 if (name[2] == 'c' &&
7989 if (name[2] == 'c' &&
7999 if (name[2] == 't' &&
8013 if (name[1] == 'k' &&
8024 if (name[1] == 'r' &&
8038 if (name[2] == 's' &&
8048 if (name[2] == 'd' &&
8065 if (name[2] == 'm' &&
8075 if (name[2] == 'i' &&
8085 if (name[2] == 'e' &&
8095 if (name[2] == 'l' &&
8105 if (name[2] == 'a' &&
8115 if (name[2] == 'u' &&
8129 if (name[1] == 'i' &&
8143 if (name[2] == 'a' &&
8156 if (name[3] == 'e' &&
8191 if (name[2] == 'i' &&
8208 if (name[2] == 'i' &&
8218 if (name[2] == 'i' &&
8235 case 6: /* 33 tokens of length 6 */
8239 if (name[1] == 'c' &&
8254 if (name[2] == 'l' &&
8265 if (name[2] == 'r' &&
8280 if (name[1] == 'e' &&
8295 if (name[2] == 's' &&
8300 if(ckWARN_d(WARN_SYNTAX))
8301 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8307 if (name[2] == 'i' &&
8325 if (name[2] == 'l' &&
8336 if (name[2] == 'r' &&
8351 if (name[1] == 'm' &&
8366 if (name[2] == 'n' &&
8377 if (name[2] == 's' &&
8392 if (name[1] == 's' &&
8398 if (name[4] == 't' &&
8407 if (name[4] == 'e' &&
8416 if (name[4] == 'c' &&
8425 if (name[4] == 'n' &&
8441 if (name[1] == 'r' &&
8459 if (name[3] == 'a' &&
8469 if (name[3] == 'u' &&
8483 if (name[2] == 'n' &&
8501 if (name[2] == 'a' &&
8515 if (name[3] == 'e' &&
8528 if (name[4] == 't' &&
8537 if (name[4] == 'e' &&
8559 if (name[4] == 't' &&
8568 if (name[4] == 'e' &&
8584 if (name[2] == 'c' &&
8595 if (name[2] == 'l' &&
8606 if (name[2] == 'b' &&
8617 if (name[2] == 's' &&
8640 if (name[4] == 's' &&
8649 if (name[4] == 'n' &&
8662 if (name[3] == 'a' &&
8679 if (name[1] == 'a' &&
8694 case 7: /* 29 tokens of length 7 */
8698 if (name[1] == 'E' &&
8711 if (name[1] == '_' &&
8724 if (name[1] == 'i' &&
8731 return -KEY_binmode;
8737 if (name[1] == 'o' &&
8744 return -KEY_connect;
8753 if (name[2] == 'm' &&
8759 return -KEY_dbmopen;
8770 if (name[4] == 'u' &&
8774 return (FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
8780 if (name[4] == 'n' &&
8801 if (name[1] == 'o' &&
8814 if (name[1] == 'e' &&
8821 if (name[5] == 'r' &&
8824 return -KEY_getpgrp;
8830 if (name[5] == 'i' &&
8833 return -KEY_getppid;
8846 if (name[1] == 'c' &&
8853 return -KEY_lcfirst;
8859 if (name[1] == 'p' &&
8866 return -KEY_opendir;
8872 if (name[1] == 'a' &&
8890 if (name[3] == 'd' &&
8895 return -KEY_readdir;
8901 if (name[3] == 'u' &&
8912 if (name[3] == 'e' &&
8917 return -KEY_reverse;
8936 if (name[3] == 'k' &&
8941 return -KEY_seekdir;
8947 if (name[3] == 'p' &&
8952 return -KEY_setpgrp;
8962 if (name[2] == 'm' &&
8968 return -KEY_shmread;
8974 if (name[2] == 'r' &&
8980 return -KEY_sprintf;
8989 if (name[3] == 'l' &&
8994 return -KEY_symlink;
9003 if (name[4] == 'a' &&
9007 return -KEY_syscall;
9013 if (name[4] == 'p' &&
9017 return -KEY_sysopen;
9023 if (name[4] == 'e' &&
9027 return -KEY_sysread;
9033 if (name[4] == 'e' &&
9037 return -KEY_sysseek;
9055 if (name[1] == 'e' &&
9062 return -KEY_telldir;
9071 if (name[2] == 'f' &&
9077 return -KEY_ucfirst;
9083 if (name[2] == 's' &&
9089 return -KEY_unshift;
9099 if (name[1] == 'a' &&
9106 return -KEY_waitpid;
9115 case 8: /* 26 tokens of length 8 */
9119 if (name[1] == 'U' &&
9127 return KEY_AUTOLOAD;
9138 if (name[3] == 'A' &&
9144 return KEY___DATA__;
9150 if (name[3] == 'I' &&
9156 return -KEY___FILE__;
9162 if (name[3] == 'I' &&
9168 return -KEY___LINE__;
9184 if (name[2] == 'o' &&
9191 return -KEY_closedir;
9197 if (name[2] == 'n' &&
9204 return -KEY_continue;
9214 if (name[1] == 'b' &&
9222 return -KEY_dbmclose;
9228 if (name[1] == 'n' &&
9234 if (name[4] == 'r' &&
9239 return -KEY_endgrent;
9245 if (name[4] == 'w' &&
9250 return -KEY_endpwent;
9263 if (name[1] == 'o' &&
9271 return -KEY_formline;
9277 if (name[1] == 'e' &&
9288 if (name[6] == 'n' &&
9291 return -KEY_getgrent;
9297 if (name[6] == 'i' &&
9300 return -KEY_getgrgid;
9306 if (name[6] == 'a' &&
9309 return -KEY_getgrnam;
9322 if (name[4] == 'o' &&
9327 return -KEY_getlogin;
9338 if (name[6] == 'n' &&
9341 return -KEY_getpwent;
9347 if (name[6] == 'a' &&
9350 return -KEY_getpwnam;
9356 if (name[6] == 'i' &&
9359 return -KEY_getpwuid;
9379 if (name[1] == 'e' &&
9386 if (name[5] == 'i' &&
9393 return -KEY_readline;
9398 return -KEY_readlink;
9409 if (name[5] == 'i' &&
9413 return -KEY_readpipe;
9434 if (name[4] == 'r' &&
9439 return -KEY_setgrent;
9445 if (name[4] == 'w' &&
9450 return -KEY_setpwent;
9466 if (name[3] == 'w' &&
9472 return -KEY_shmwrite;
9478 if (name[3] == 't' &&
9484 return -KEY_shutdown;
9494 if (name[2] == 's' &&
9501 return -KEY_syswrite;
9511 if (name[1] == 'r' &&
9519 return -KEY_truncate;
9528 case 9: /* 8 tokens of length 9 */
9532 if (name[1] == 'n' &&
9541 return -KEY_endnetent;
9547 if (name[1] == 'e' &&
9556 return -KEY_getnetent;
9562 if (name[1] == 'o' &&
9571 return -KEY_localtime;
9577 if (name[1] == 'r' &&
9586 return KEY_prototype;
9592 if (name[1] == 'u' &&
9601 return -KEY_quotemeta;
9607 if (name[1] == 'e' &&
9616 return -KEY_rewinddir;
9622 if (name[1] == 'e' &&
9631 return -KEY_setnetent;
9637 if (name[1] == 'a' &&
9646 return -KEY_wantarray;
9655 case 10: /* 9 tokens of length 10 */
9659 if (name[1] == 'n' &&
9665 if (name[4] == 'o' &&
9672 return -KEY_endhostent;
9678 if (name[4] == 'e' &&
9685 return -KEY_endservent;
9698 if (name[1] == 'e' &&
9704 if (name[4] == 'o' &&
9711 return -KEY_gethostent;
9720 if (name[5] == 'r' &&
9726 return -KEY_getservent;
9732 if (name[5] == 'c' &&
9738 return -KEY_getsockopt;
9763 if (name[4] == 'o' &&
9770 return -KEY_sethostent;
9779 if (name[5] == 'r' &&
9785 return -KEY_setservent;
9791 if (name[5] == 'c' &&
9797 return -KEY_setsockopt;
9814 if (name[2] == 'c' &&
9823 return -KEY_socketpair;
9836 case 11: /* 8 tokens of length 11 */
9840 if (name[1] == '_' &&
9851 return -KEY___PACKAGE__;
9857 if (name[1] == 'n' &&
9868 return -KEY_endprotoent;
9874 if (name[1] == 'e' &&
9883 if (name[5] == 'e' &&
9890 return -KEY_getpeername;
9899 if (name[6] == 'o' &&
9905 return -KEY_getpriority;
9911 if (name[6] == 't' &&
9917 return -KEY_getprotoent;
9931 if (name[4] == 'o' &&
9939 return -KEY_getsockname;
9952 if (name[1] == 'e' &&
9960 if (name[6] == 'o' &&
9966 return -KEY_setpriority;
9972 if (name[6] == 't' &&
9978 return -KEY_setprotoent;
9994 case 12: /* 2 tokens of length 12 */
9995 if (name[0] == 'g' &&
10007 if (name[9] == 'd' &&
10010 { /* getnetbyaddr */
10011 return -KEY_getnetbyaddr;
10017 if (name[9] == 'a' &&
10020 { /* getnetbyname */
10021 return -KEY_getnetbyname;
10033 case 13: /* 4 tokens of length 13 */
10034 if (name[0] == 'g' &&
10041 if (name[4] == 'o' &&
10050 if (name[10] == 'd' &&
10053 { /* gethostbyaddr */
10054 return -KEY_gethostbyaddr;
10060 if (name[10] == 'a' &&
10063 { /* gethostbyname */
10064 return -KEY_gethostbyname;
10077 if (name[4] == 'e' &&
10086 if (name[10] == 'a' &&
10089 { /* getservbyname */
10090 return -KEY_getservbyname;
10096 if (name[10] == 'o' &&
10099 { /* getservbyport */
10100 return -KEY_getservbyport;
10119 case 14: /* 1 tokens of length 14 */
10120 if (name[0] == 'g' &&
10134 { /* getprotobyname */
10135 return -KEY_getprotobyname;
10140 case 16: /* 1 tokens of length 16 */
10141 if (name[0] == 'g' &&
10157 { /* getprotobynumber */
10158 return -KEY_getprotobynumber;
10172 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10176 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
10177 if (ckWARN(WARN_SYNTAX)) {
10180 for (w = s+2; *w && level; w++) {
10183 else if (*w == ')')
10186 while (isSPACE(*w))
10188 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
10189 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10190 "%s (...) interpreted as function",name);
10193 while (s < PL_bufend && isSPACE(*s))
10197 while (s < PL_bufend && isSPACE(*s))
10199 if (isIDFIRST_lazy_if(s,UTF)) {
10200 const char * const w = s++;
10201 while (isALNUM_lazy_if(s,UTF))
10203 while (s < PL_bufend && isSPACE(*s))
10207 if (keyword(w, s - w))
10210 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10211 if (gv && GvCVu(gv))
10213 Perl_croak(aTHX_ "No comma allowed after %s", what);
10218 /* Either returns sv, or mortalizes sv and returns a new SV*.
10219 Best used as sv=new_constant(..., sv, ...).
10220 If s, pv are NULL, calls subroutine with one argument,
10221 and type is used with error messages only. */
10224 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10228 HV * const table = GvHV(PL_hintgv); /* ^H */
10232 const char *why1 = "", *why2 = "", *why3 = "";
10234 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10237 why2 = strEQ(key,"charnames")
10238 ? "(possibly a missing \"use charnames ...\")"
10240 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10241 (type ? type: "undef"), why2);
10243 /* This is convoluted and evil ("goto considered harmful")
10244 * but I do not understand the intricacies of all the different
10245 * failure modes of %^H in here. The goal here is to make
10246 * the most probable error message user-friendly. --jhi */
10251 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10252 (type ? type: "undef"), why1, why2, why3);
10254 yyerror(SvPVX_const(msg));
10258 cvp = hv_fetch(table, key, strlen(key), FALSE);
10259 if (!cvp || !SvOK(*cvp)) {
10262 why3 = "} is not defined";
10265 sv_2mortal(sv); /* Parent created it permanently */
10268 pv = sv_2mortal(newSVpvn(s, len));
10270 typesv = sv_2mortal(newSVpv(type, 0));
10272 typesv = &PL_sv_undef;
10274 PUSHSTACKi(PERLSI_OVERLOAD);
10286 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10290 /* Check the eval first */
10291 if (!PL_in_eval && SvTRUE(ERRSV)) {
10292 sv_catpvs(ERRSV, "Propagated");
10293 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10295 res = SvREFCNT_inc_simple(sv);
10299 SvREFCNT_inc_simple_void(res);
10308 why1 = "Call to &{$^H{";
10310 why3 = "}} did not return a defined value";
10318 /* Returns a NUL terminated string, with the length of the string written to
10322 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10325 register char *d = dest;
10326 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
10329 Perl_croak(aTHX_ ident_too_long);
10330 if (isALNUM(*s)) /* UTF handled below */
10332 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
10337 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
10341 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10342 char *t = s + UTF8SKIP(s);
10343 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10345 if (d + (t - s) > e)
10346 Perl_croak(aTHX_ ident_too_long);
10347 Copy(s, d, t - s, char);
10360 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10363 char *bracket = NULL;
10365 register char *d = dest;
10366 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
10371 while (isDIGIT(*s)) {
10373 Perl_croak(aTHX_ ident_too_long);
10380 Perl_croak(aTHX_ ident_too_long);
10381 if (isALNUM(*s)) /* UTF handled below */
10383 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10388 else if (*s == ':' && s[1] == ':') {
10392 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10393 char *t = s + UTF8SKIP(s);
10394 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10396 if (d + (t - s) > e)
10397 Perl_croak(aTHX_ ident_too_long);
10398 Copy(s, d, t - s, char);
10409 if (PL_lex_state != LEX_NORMAL)
10410 PL_lex_state = LEX_INTERPENDMAYBE;
10413 if (*s == '$' && s[1] &&
10414 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10427 if (*d == '^' && *s && isCONTROLVAR(*s)) {
10432 if (isSPACE(s[-1])) {
10434 const char ch = *s++;
10435 if (!SPACE_OR_TAB(ch)) {
10441 if (isIDFIRST_lazy_if(d,UTF)) {
10445 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10446 end += UTF8SKIP(end);
10447 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10448 end += UTF8SKIP(end);
10450 Copy(s, d, end - s, char);
10455 while ((isALNUM(*s) || *s == ':') && d < e)
10458 Perl_croak(aTHX_ ident_too_long);
10461 while (s < send && SPACE_OR_TAB(*s)) s++;
10462 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10463 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
10464 const char *brack = *s == '[' ? "[...]" : "{...}";
10465 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10466 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10467 funny, dest, brack, funny, dest, brack);
10470 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10474 /* Handle extended ${^Foo} variables
10475 * 1999-02-27 mjd-perl-patch@plover.com */
10476 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10480 while (isALNUM(*s) && d < e) {
10484 Perl_croak(aTHX_ ident_too_long);
10489 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10490 PL_lex_state = LEX_INTERPEND;
10495 if (PL_lex_state == LEX_NORMAL) {
10496 if (ckWARN(WARN_AMBIGUOUS) &&
10497 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
10499 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10500 "Ambiguous use of %c{%s} resolved to %c%s",
10501 funny, dest, funny, dest);
10506 s = bracket; /* let the parser handle it */
10510 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10511 PL_lex_state = LEX_INTERPEND;
10516 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10518 PERL_UNUSED_CONTEXT;
10521 else if (ch == 'g')
10522 *pmfl |= PMf_GLOBAL;
10523 else if (ch == 'c')
10524 *pmfl |= PMf_CONTINUE;
10525 else if (ch == 'o')
10527 else if (ch == 'm')
10528 *pmfl |= PMf_MULTILINE;
10529 else if (ch == 's')
10530 *pmfl |= PMf_SINGLELINE;
10531 else if (ch == 'x')
10532 *pmfl |= PMf_EXTENDED;
10536 S_scan_pat(pTHX_ char *start, I32 type)
10540 char *s = scan_str(start,!!PL_madskills,FALSE);
10541 const char * const valid_flags = (type == OP_QR) ? "iomsx" : "iogcmsx";
10548 const char * const delimiter = skipspace(start);
10549 Perl_croak(aTHX_ *delimiter == '?'
10550 ? "Search pattern not terminated or ternary operator parsed as search pattern"
10551 : "Search pattern not terminated" );
10554 pm = (PMOP*)newPMOP(type, 0);
10555 if (PL_multi_open == '?')
10556 pm->op_pmflags |= PMf_ONCE;
10560 while (*s && strchr(valid_flags, *s))
10561 pmflag(&pm->op_pmflags,*s++);
10563 if (PL_madskills && modstart != s) {
10564 SV* tmptoken = newSVpvn(modstart, s - modstart);
10565 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10568 /* issue a warning if /c is specified,but /g is not */
10569 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10570 && ckWARN(WARN_REGEXP))
10572 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
10575 pm->op_pmpermflags = pm->op_pmflags;
10577 PL_lex_op = (OP*)pm;
10578 yylval.ival = OP_MATCH;
10583 S_scan_subst(pTHX_ char *start)
10594 yylval.ival = OP_NULL;
10596 s = scan_str(start,!!PL_madskills,FALSE);
10599 Perl_croak(aTHX_ "Substitution pattern not terminated");
10601 if (s[-1] == PL_multi_open)
10604 if (PL_madskills) {
10605 CURMAD('q', PL_thisopen);
10606 CURMAD('_', PL_thiswhite);
10607 CURMAD('E', PL_thisstuff);
10608 CURMAD('Q', PL_thisclose);
10609 PL_realtokenstart = s - SvPVX(PL_linestr);
10613 first_start = PL_multi_start;
10614 s = scan_str(s,!!PL_madskills,FALSE);
10616 if (PL_lex_stuff) {
10617 SvREFCNT_dec(PL_lex_stuff);
10618 PL_lex_stuff = NULL;
10620 Perl_croak(aTHX_ "Substitution replacement not terminated");
10622 PL_multi_start = first_start; /* so whole substitution is taken together */
10624 pm = (PMOP*)newPMOP(OP_SUBST, 0);
10627 if (PL_madskills) {
10628 CURMAD('z', PL_thisopen);
10629 CURMAD('R', PL_thisstuff);
10630 CURMAD('Z', PL_thisclose);
10640 else if (strchr("iogcmsx", *s))
10641 pmflag(&pm->op_pmflags,*s++);
10647 if (PL_madskills) {
10649 curmad('m', newSVpvn(modstart, s - modstart));
10650 append_madprops(PL_thismad, (OP*)pm, 0);
10654 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10655 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10659 SV * const repl = newSVpvs("");
10661 PL_sublex_info.super_bufptr = s;
10662 PL_sublex_info.super_bufend = PL_bufend;
10664 pm->op_pmflags |= PMf_EVAL;
10666 sv_catpv(repl, es ? "eval " : "do ");
10667 sv_catpvs(repl, "{");
10668 sv_catsv(repl, PL_lex_repl);
10669 sv_catpvs(repl, "}");
10671 SvREFCNT_dec(PL_lex_repl);
10672 PL_lex_repl = repl;
10675 pm->op_pmpermflags = pm->op_pmflags;
10676 PL_lex_op = (OP*)pm;
10677 yylval.ival = OP_SUBST;
10682 S_scan_trans(pTHX_ char *start)
10695 yylval.ival = OP_NULL;
10697 s = scan_str(start,!!PL_madskills,FALSE);
10699 Perl_croak(aTHX_ "Transliteration pattern not terminated");
10701 if (s[-1] == PL_multi_open)
10704 if (PL_madskills) {
10705 CURMAD('q', PL_thisopen);
10706 CURMAD('_', PL_thiswhite);
10707 CURMAD('E', PL_thisstuff);
10708 CURMAD('Q', PL_thisclose);
10709 PL_realtokenstart = s - SvPVX(PL_linestr);
10713 s = scan_str(s,!!PL_madskills,FALSE);
10715 if (PL_lex_stuff) {
10716 SvREFCNT_dec(PL_lex_stuff);
10717 PL_lex_stuff = NULL;
10719 Perl_croak(aTHX_ "Transliteration replacement not terminated");
10721 if (PL_madskills) {
10722 CURMAD('z', PL_thisopen);
10723 CURMAD('R', PL_thisstuff);
10724 CURMAD('Z', PL_thisclose);
10727 complement = del = squash = 0;
10734 complement = OPpTRANS_COMPLEMENT;
10737 del = OPpTRANS_DELETE;
10740 squash = OPpTRANS_SQUASH;
10749 Newx(tbl, complement&&!del?258:256, short);
10750 o = newPVOP(OP_TRANS, 0, (char*)tbl);
10751 o->op_private &= ~OPpTRANS_ALL;
10752 o->op_private |= del|squash|complement|
10753 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10754 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
10757 yylval.ival = OP_TRANS;
10760 if (PL_madskills) {
10762 curmad('m', newSVpvn(modstart, s - modstart));
10763 append_madprops(PL_thismad, o, 0);
10772 S_scan_heredoc(pTHX_ register char *s)
10776 I32 op_type = OP_SCALAR;
10780 const char *found_newline;
10784 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
10786 I32 stuffstart = s - SvPVX(PL_linestr);
10789 PL_realtokenstart = -1;
10794 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
10797 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
10798 if (*peek == '`' || *peek == '\'' || *peek =='"') {
10801 s = delimcpy(d, e, s, PL_bufend, term, &len);
10811 if (!isALNUM_lazy_if(s,UTF))
10812 deprecate_old("bare << to mean <<\"\"");
10813 for (; isALNUM_lazy_if(s,UTF); s++) {
10818 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
10819 Perl_croak(aTHX_ "Delimiter for here document is too long");
10822 len = d - PL_tokenbuf;
10825 if (PL_madskills) {
10826 tstart = PL_tokenbuf + !outer;
10827 PL_thisclose = newSVpvn(tstart, len - !outer);
10828 tstart = SvPVX(PL_linestr) + stuffstart;
10829 PL_thisopen = newSVpvn(tstart, s - tstart);
10830 stuffstart = s - SvPVX(PL_linestr);
10833 #ifndef PERL_STRICT_CR
10834 d = strchr(s, '\r');
10836 char * const olds = s;
10838 while (s < PL_bufend) {
10844 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
10853 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
10860 if ( outer || !(found_newline = memchr(s, '\n', PL_bufend - s)) ) {
10861 herewas = newSVpvn(s,PL_bufend-s);
10865 herewas = newSVpvn(s-1,found_newline-s+1);
10868 herewas = newSVpvn(s,found_newline-s);
10872 if (PL_madskills) {
10873 tstart = SvPVX(PL_linestr) + stuffstart;
10875 sv_catpvn(PL_thisstuff, tstart, s - tstart);
10877 PL_thisstuff = newSVpvn(tstart, s - tstart);
10880 s += SvCUR(herewas);
10883 stuffstart = s - SvPVX(PL_linestr);
10889 tmpstr = newSV(79);
10890 sv_upgrade(tmpstr, SVt_PVIV);
10891 if (term == '\'') {
10892 op_type = OP_CONST;
10893 SvIV_set(tmpstr, -1);
10895 else if (term == '`') {
10896 op_type = OP_BACKTICK;
10897 SvIV_set(tmpstr, '\\');
10901 PL_multi_start = CopLINE(PL_curcop);
10902 PL_multi_open = PL_multi_close = '<';
10903 term = *PL_tokenbuf;
10904 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
10905 char * const bufptr = PL_sublex_info.super_bufptr;
10906 char * const bufend = PL_sublex_info.super_bufend;
10907 char * const olds = s - SvCUR(herewas);
10908 s = strchr(bufptr, '\n');
10912 while (s < bufend &&
10913 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
10915 CopLINE_inc(PL_curcop);
10918 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10919 missingterm(PL_tokenbuf);
10921 sv_setpvn(herewas,bufptr,d-bufptr+1);
10922 sv_setpvn(tmpstr,d+1,s-d);
10924 sv_catpvn(herewas,s,bufend-s);
10925 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
10932 while (s < PL_bufend &&
10933 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
10935 CopLINE_inc(PL_curcop);
10937 if (s >= PL_bufend) {
10938 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10939 missingterm(PL_tokenbuf);
10941 sv_setpvn(tmpstr,d+1,s-d);
10943 if (PL_madskills) {
10945 sv_catpvn(PL_thisstuff, d + 1, s - d);
10947 PL_thisstuff = newSVpvn(d + 1, s - d);
10948 stuffstart = s - SvPVX(PL_linestr);
10952 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
10954 sv_catpvn(herewas,s,PL_bufend-s);
10955 sv_setsv(PL_linestr,herewas);
10956 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
10957 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10958 PL_last_lop = PL_last_uni = NULL;
10961 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
10962 while (s >= PL_bufend) { /* multiple line string? */
10964 if (PL_madskills) {
10965 tstart = SvPVX(PL_linestr) + stuffstart;
10967 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
10969 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
10973 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
10974 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10975 missingterm(PL_tokenbuf);
10978 stuffstart = s - SvPVX(PL_linestr);
10980 CopLINE_inc(PL_curcop);
10981 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10982 PL_last_lop = PL_last_uni = NULL;
10983 #ifndef PERL_STRICT_CR
10984 if (PL_bufend - PL_linestart >= 2) {
10985 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
10986 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
10988 PL_bufend[-2] = '\n';
10990 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
10992 else if (PL_bufend[-1] == '\r')
10993 PL_bufend[-1] = '\n';
10995 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
10996 PL_bufend[-1] = '\n';
10998 if (PERLDB_LINE && PL_curstash != PL_debstash) {
10999 SV * const sv = newSV(0);
11001 sv_upgrade(sv, SVt_PVMG);
11002 sv_setsv(sv,PL_linestr);
11003 (void)SvIOK_on(sv);
11005 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop),sv);
11007 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11008 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11009 *(SvPVX(PL_linestr) + off ) = ' ';
11010 sv_catsv(PL_linestr,herewas);
11011 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11012 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11016 sv_catsv(tmpstr,PL_linestr);
11021 PL_multi_end = CopLINE(PL_curcop);
11022 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11023 SvPV_shrink_to_cur(tmpstr);
11025 SvREFCNT_dec(herewas);
11027 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11029 else if (PL_encoding)
11030 sv_recode_to_utf8(tmpstr, PL_encoding);
11032 PL_lex_stuff = tmpstr;
11033 yylval.ival = op_type;
11037 /* scan_inputsymbol
11038 takes: current position in input buffer
11039 returns: new position in input buffer
11040 side-effects: yylval and lex_op are set.
11045 <FH> read from filehandle
11046 <pkg::FH> read from package qualified filehandle
11047 <pkg'FH> read from package qualified filehandle
11048 <$fh> read from filehandle in $fh
11049 <*.h> filename glob
11054 S_scan_inputsymbol(pTHX_ char *start)
11057 register char *s = start; /* current position in buffer */
11061 char *d = PL_tokenbuf; /* start of temp holding space */
11062 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11064 end = strchr(s, '\n');
11067 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
11069 /* die if we didn't have space for the contents of the <>,
11070 or if it didn't end, or if we see a newline
11073 if (len >= sizeof PL_tokenbuf)
11074 Perl_croak(aTHX_ "Excessively long <> operator");
11076 Perl_croak(aTHX_ "Unterminated <> operator");
11081 Remember, only scalar variables are interpreted as filehandles by
11082 this code. Anything more complex (e.g., <$fh{$num}>) will be
11083 treated as a glob() call.
11084 This code makes use of the fact that except for the $ at the front,
11085 a scalar variable and a filehandle look the same.
11087 if (*d == '$' && d[1]) d++;
11089 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11090 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11093 /* If we've tried to read what we allow filehandles to look like, and
11094 there's still text left, then it must be a glob() and not a getline.
11095 Use scan_str to pull out the stuff between the <> and treat it
11096 as nothing more than a string.
11099 if (d - PL_tokenbuf != len) {
11100 yylval.ival = OP_GLOB;
11102 s = scan_str(start,!!PL_madskills,FALSE);
11104 Perl_croak(aTHX_ "Glob not terminated");
11108 bool readline_overriden = FALSE;
11111 /* we're in a filehandle read situation */
11114 /* turn <> into <ARGV> */
11116 Copy("ARGV",d,5,char);
11118 /* Check whether readline() is overriden */
11119 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11121 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11123 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11124 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
11125 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11126 readline_overriden = TRUE;
11128 /* if <$fh>, create the ops to turn the variable into a
11134 /* try to find it in the pad for this block, otherwise find
11135 add symbol table ops
11137 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
11138 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11139 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11140 HEK * const stashname = HvNAME_HEK(stash);
11141 SV * const sym = sv_2mortal(newSVhek(stashname));
11142 sv_catpvs(sym, "::");
11143 sv_catpv(sym, d+1);
11148 OP * const o = newOP(OP_PADSV, 0);
11150 PL_lex_op = readline_overriden
11151 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11152 append_elem(OP_LIST, o,
11153 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11154 : (OP*)newUNOP(OP_READLINE, 0, o);
11163 ? (GV_ADDMULTI | GV_ADDINEVAL)
11166 PL_lex_op = readline_overriden
11167 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11168 append_elem(OP_LIST,
11169 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11170 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11171 : (OP*)newUNOP(OP_READLINE, 0,
11172 newUNOP(OP_RV2SV, 0,
11173 newGVOP(OP_GV, 0, gv)));
11175 if (!readline_overriden)
11176 PL_lex_op->op_flags |= OPf_SPECIAL;
11177 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11178 yylval.ival = OP_NULL;
11181 /* If it's none of the above, it must be a literal filehandle
11182 (<Foo::BAR> or <FOO>) so build a simple readline OP */
11184 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11185 PL_lex_op = readline_overriden
11186 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11187 append_elem(OP_LIST,
11188 newGVOP(OP_GV, 0, gv),
11189 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11190 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11191 yylval.ival = OP_NULL;
11200 takes: start position in buffer
11201 keep_quoted preserve \ on the embedded delimiter(s)
11202 keep_delims preserve the delimiters around the string
11203 returns: position to continue reading from buffer
11204 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11205 updates the read buffer.
11207 This subroutine pulls a string out of the input. It is called for:
11208 q single quotes q(literal text)
11209 ' single quotes 'literal text'
11210 qq double quotes qq(interpolate $here please)
11211 " double quotes "interpolate $here please"
11212 qx backticks qx(/bin/ls -l)
11213 ` backticks `/bin/ls -l`
11214 qw quote words @EXPORT_OK = qw( func() $spam )
11215 m// regexp match m/this/
11216 s/// regexp substitute s/this/that/
11217 tr/// string transliterate tr/this/that/
11218 y/// string transliterate y/this/that/
11219 ($*@) sub prototypes sub foo ($)
11220 (stuff) sub attr parameters sub foo : attr(stuff)
11221 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11223 In most of these cases (all but <>, patterns and transliterate)
11224 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11225 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11226 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11229 It skips whitespace before the string starts, and treats the first
11230 character as the delimiter. If the delimiter is one of ([{< then
11231 the corresponding "close" character )]}> is used as the closing
11232 delimiter. It allows quoting of delimiters, and if the string has
11233 balanced delimiters ([{<>}]) it allows nesting.
11235 On success, the SV with the resulting string is put into lex_stuff or,
11236 if that is already non-NULL, into lex_repl. The second case occurs only
11237 when parsing the RHS of the special constructs s/// and tr/// (y///).
11238 For convenience, the terminating delimiter character is stuffed into
11243 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11246 SV *sv; /* scalar value: string */
11247 char *tmps; /* temp string, used for delimiter matching */
11248 register char *s = start; /* current position in the buffer */
11249 register char term; /* terminating character */
11250 register char *to; /* current position in the sv's data */
11251 I32 brackets = 1; /* bracket nesting level */
11252 bool has_utf8 = FALSE; /* is there any utf8 content? */
11253 I32 termcode; /* terminating char. code */
11254 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
11255 STRLEN termlen; /* length of terminating string */
11256 char *last = NULL; /* last position for nesting bracket */
11262 /* skip space before the delimiter */
11268 if (PL_realtokenstart >= 0) {
11269 stuffstart = PL_realtokenstart;
11270 PL_realtokenstart = -1;
11273 stuffstart = start - SvPVX(PL_linestr);
11275 /* mark where we are, in case we need to report errors */
11278 /* after skipping whitespace, the next character is the terminator */
11281 termcode = termstr[0] = term;
11285 termcode = utf8_to_uvchr((U8*)s, &termlen);
11286 Copy(s, termstr, termlen, U8);
11287 if (!UTF8_IS_INVARIANT(term))
11291 /* mark where we are */
11292 PL_multi_start = CopLINE(PL_curcop);
11293 PL_multi_open = term;
11295 /* find corresponding closing delimiter */
11296 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11297 termcode = termstr[0] = term = tmps[5];
11299 PL_multi_close = term;
11301 /* create a new SV to hold the contents. 79 is the SV's initial length.
11302 What a random number. */
11304 sv_upgrade(sv, SVt_PVIV);
11305 SvIV_set(sv, termcode);
11306 (void)SvPOK_only(sv); /* validate pointer */
11308 /* move past delimiter and try to read a complete string */
11310 sv_catpvn(sv, s, termlen);
11313 tstart = SvPVX(PL_linestr) + stuffstart;
11314 if (!PL_thisopen && !keep_delims) {
11315 PL_thisopen = newSVpvn(tstart, s - tstart);
11316 stuffstart = s - SvPVX(PL_linestr);
11320 if (PL_encoding && !UTF) {
11324 int offset = s - SvPVX_const(PL_linestr);
11325 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11326 &offset, (char*)termstr, termlen);
11327 const char * const ns = SvPVX_const(PL_linestr) + offset;
11328 char * const svlast = SvEND(sv) - 1;
11330 for (; s < ns; s++) {
11331 if (*s == '\n' && !PL_rsfp)
11332 CopLINE_inc(PL_curcop);
11335 goto read_more_line;
11337 /* handle quoted delimiters */
11338 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11340 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11342 if ((svlast-1 - t) % 2) {
11343 if (!keep_quoted) {
11344 *(svlast-1) = term;
11346 SvCUR_set(sv, SvCUR(sv) - 1);
11351 if (PL_multi_open == PL_multi_close) {
11359 for (t = w = last; t < svlast; w++, t++) {
11360 /* At here, all closes are "was quoted" one,
11361 so we don't check PL_multi_close. */
11363 if (!keep_quoted && *(t+1) == PL_multi_open)
11368 else if (*t == PL_multi_open)
11376 SvCUR_set(sv, w - SvPVX_const(sv));
11379 if (--brackets <= 0)
11384 if (!keep_delims) {
11385 SvCUR_set(sv, SvCUR(sv) - 1);
11391 /* extend sv if need be */
11392 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11393 /* set 'to' to the next character in the sv's string */
11394 to = SvPVX(sv)+SvCUR(sv);
11396 /* if open delimiter is the close delimiter read unbridle */
11397 if (PL_multi_open == PL_multi_close) {
11398 for (; s < PL_bufend; s++,to++) {
11399 /* embedded newlines increment the current line number */
11400 if (*s == '\n' && !PL_rsfp)
11401 CopLINE_inc(PL_curcop);
11402 /* handle quoted delimiters */
11403 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11404 if (!keep_quoted && s[1] == term)
11406 /* any other quotes are simply copied straight through */
11410 /* terminate when run out of buffer (the for() condition), or
11411 have found the terminator */
11412 else if (*s == term) {
11415 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11418 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11424 /* if the terminator isn't the same as the start character (e.g.,
11425 matched brackets), we have to allow more in the quoting, and
11426 be prepared for nested brackets.
11429 /* read until we run out of string, or we find the terminator */
11430 for (; s < PL_bufend; s++,to++) {
11431 /* embedded newlines increment the line count */
11432 if (*s == '\n' && !PL_rsfp)
11433 CopLINE_inc(PL_curcop);
11434 /* backslashes can escape the open or closing characters */
11435 if (*s == '\\' && s+1 < PL_bufend) {
11436 if (!keep_quoted &&
11437 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11442 /* allow nested opens and closes */
11443 else if (*s == PL_multi_close && --brackets <= 0)
11445 else if (*s == PL_multi_open)
11447 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11452 /* terminate the copied string and update the sv's end-of-string */
11454 SvCUR_set(sv, to - SvPVX_const(sv));
11457 * this next chunk reads more into the buffer if we're not done yet
11461 break; /* handle case where we are done yet :-) */
11463 #ifndef PERL_STRICT_CR
11464 if (to - SvPVX_const(sv) >= 2) {
11465 if ((to[-2] == '\r' && to[-1] == '\n') ||
11466 (to[-2] == '\n' && to[-1] == '\r'))
11470 SvCUR_set(sv, to - SvPVX_const(sv));
11472 else if (to[-1] == '\r')
11475 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11480 /* if we're out of file, or a read fails, bail and reset the current
11481 line marker so we can report where the unterminated string began
11484 if (PL_madskills) {
11485 char *tstart = SvPVX(PL_linestr) + stuffstart;
11487 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11489 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11493 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11495 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11501 /* we read a line, so increment our line counter */
11502 CopLINE_inc(PL_curcop);
11504 /* update debugger info */
11505 if (PERLDB_LINE && PL_curstash != PL_debstash) {
11506 SV * const line_sv = newSV(0);
11508 sv_upgrade(line_sv, SVt_PVMG);
11509 sv_setsv(line_sv,PL_linestr);
11510 (void)SvIOK_on(line_sv);
11511 SvIV_set(line_sv, 0);
11512 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop), line_sv);
11515 /* having changed the buffer, we must update PL_bufend */
11516 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11517 PL_last_lop = PL_last_uni = NULL;
11520 /* at this point, we have successfully read the delimited string */
11522 if (!PL_encoding || UTF) {
11524 if (PL_madskills) {
11525 char *tstart = SvPVX(PL_linestr) + stuffstart;
11527 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11529 PL_thisstuff = newSVpvn(tstart, s - tstart);
11530 if (!PL_thisclose && !keep_delims)
11531 PL_thisclose = newSVpvn(s,termlen);
11536 sv_catpvn(sv, s, termlen);
11541 if (PL_madskills) {
11542 char *tstart = SvPVX(PL_linestr) + stuffstart;
11544 sv_catpvn(PL_thisstuff, tstart, s - tstart - termlen);
11546 PL_thisstuff = newSVpvn(tstart, s - tstart - termlen);
11547 if (!PL_thisclose && !keep_delims)
11548 PL_thisclose = newSVpvn(s - termlen,termlen);
11552 if (has_utf8 || PL_encoding)
11555 PL_multi_end = CopLINE(PL_curcop);
11557 /* if we allocated too much space, give some back */
11558 if (SvCUR(sv) + 5 < SvLEN(sv)) {
11559 SvLEN_set(sv, SvCUR(sv) + 1);
11560 SvPV_renew(sv, SvLEN(sv));
11563 /* decide whether this is the first or second quoted string we've read
11576 takes: pointer to position in buffer
11577 returns: pointer to new position in buffer
11578 side-effects: builds ops for the constant in yylval.op
11580 Read a number in any of the formats that Perl accepts:
11582 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
11583 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
11586 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11588 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11591 If it reads a number without a decimal point or an exponent, it will
11592 try converting the number to an integer and see if it can do so
11593 without loss of precision.
11597 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11600 register const char *s = start; /* current position in buffer */
11601 register char *d; /* destination in temp buffer */
11602 register char *e; /* end of temp buffer */
11603 NV nv; /* number read, as a double */
11604 SV *sv = NULL; /* place to put the converted number */
11605 bool floatit; /* boolean: int or float? */
11606 const char *lastub = NULL; /* position of last underbar */
11607 static char const number_too_long[] = "Number too long";
11609 /* We use the first character to decide what type of number this is */
11613 Perl_croak(aTHX_ "panic: scan_num");
11615 /* if it starts with a 0, it could be an octal number, a decimal in
11616 0.13 disguise, or a hexadecimal number, or a binary number. */
11620 u holds the "number so far"
11621 shift the power of 2 of the base
11622 (hex == 4, octal == 3, binary == 1)
11623 overflowed was the number more than we can hold?
11625 Shift is used when we add a digit. It also serves as an "are
11626 we in octal/hex/binary?" indicator to disallow hex characters
11627 when in octal mode.
11632 bool overflowed = FALSE;
11633 bool just_zero = TRUE; /* just plain 0 or binary number? */
11634 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11635 static const char* const bases[5] =
11636 { "", "binary", "", "octal", "hexadecimal" };
11637 static const char* const Bases[5] =
11638 { "", "Binary", "", "Octal", "Hexadecimal" };
11639 static const char* const maxima[5] =
11641 "0b11111111111111111111111111111111",
11645 const char *base, *Base, *max;
11647 /* check for hex */
11652 } else if (s[1] == 'b') {
11657 /* check for a decimal in disguise */
11658 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11660 /* so it must be octal */
11667 if (ckWARN(WARN_SYNTAX))
11668 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11669 "Misplaced _ in number");
11673 base = bases[shift];
11674 Base = Bases[shift];
11675 max = maxima[shift];
11677 /* read the rest of the number */
11679 /* x is used in the overflow test,
11680 b is the digit we're adding on. */
11685 /* if we don't mention it, we're done */
11689 /* _ are ignored -- but warned about if consecutive */
11691 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11692 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11693 "Misplaced _ in number");
11697 /* 8 and 9 are not octal */
11698 case '8': case '9':
11700 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11704 case '2': case '3': case '4':
11705 case '5': case '6': case '7':
11707 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11710 case '0': case '1':
11711 b = *s++ & 15; /* ASCII digit -> value of digit */
11715 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11716 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11717 /* make sure they said 0x */
11720 b = (*s++ & 7) + 9;
11722 /* Prepare to put the digit we have onto the end
11723 of the number so far. We check for overflows.
11729 x = u << shift; /* make room for the digit */
11731 if ((x >> shift) != u
11732 && !(PL_hints & HINT_NEW_BINARY)) {
11735 if (ckWARN_d(WARN_OVERFLOW))
11736 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11737 "Integer overflow in %s number",
11740 u = x | b; /* add the digit to the end */
11743 n *= nvshift[shift];
11744 /* If an NV has not enough bits in its
11745 * mantissa to represent an UV this summing of
11746 * small low-order numbers is a waste of time
11747 * (because the NV cannot preserve the
11748 * low-order bits anyway): we could just
11749 * remember when did we overflow and in the
11750 * end just multiply n by the right
11758 /* if we get here, we had success: make a scalar value from
11763 /* final misplaced underbar check */
11764 if (s[-1] == '_') {
11765 if (ckWARN(WARN_SYNTAX))
11766 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11771 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
11772 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11773 "%s number > %s non-portable",
11779 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
11780 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11781 "%s number > %s non-portable",
11786 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
11787 sv = new_constant(start, s - start, "integer",
11789 else if (PL_hints & HINT_NEW_BINARY)
11790 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
11795 handle decimal numbers.
11796 we're also sent here when we read a 0 as the first digit
11798 case '1': case '2': case '3': case '4': case '5':
11799 case '6': case '7': case '8': case '9': case '.':
11802 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
11805 /* read next group of digits and _ and copy into d */
11806 while (isDIGIT(*s) || *s == '_') {
11807 /* skip underscores, checking for misplaced ones
11811 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11812 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11813 "Misplaced _ in number");
11817 /* check for end of fixed-length buffer */
11819 Perl_croak(aTHX_ number_too_long);
11820 /* if we're ok, copy the character */
11825 /* final misplaced underbar check */
11826 if (lastub && s == lastub + 1) {
11827 if (ckWARN(WARN_SYNTAX))
11828 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11831 /* read a decimal portion if there is one. avoid
11832 3..5 being interpreted as the number 3. followed
11835 if (*s == '.' && s[1] != '.') {
11840 if (ckWARN(WARN_SYNTAX))
11841 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11842 "Misplaced _ in number");
11846 /* copy, ignoring underbars, until we run out of digits.
11848 for (; isDIGIT(*s) || *s == '_'; s++) {
11849 /* fixed length buffer check */
11851 Perl_croak(aTHX_ number_too_long);
11853 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11854 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11855 "Misplaced _ in number");
11861 /* fractional part ending in underbar? */
11862 if (s[-1] == '_') {
11863 if (ckWARN(WARN_SYNTAX))
11864 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11865 "Misplaced _ in number");
11867 if (*s == '.' && isDIGIT(s[1])) {
11868 /* oops, it's really a v-string, but without the "v" */
11874 /* read exponent part, if present */
11875 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
11879 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
11880 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
11882 /* stray preinitial _ */
11884 if (ckWARN(WARN_SYNTAX))
11885 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11886 "Misplaced _ in number");
11890 /* allow positive or negative exponent */
11891 if (*s == '+' || *s == '-')
11894 /* stray initial _ */
11896 if (ckWARN(WARN_SYNTAX))
11897 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11898 "Misplaced _ in number");
11902 /* read digits of exponent */
11903 while (isDIGIT(*s) || *s == '_') {
11906 Perl_croak(aTHX_ number_too_long);
11910 if (((lastub && s == lastub + 1) ||
11911 (!isDIGIT(s[1]) && s[1] != '_'))
11912 && ckWARN(WARN_SYNTAX))
11913 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11914 "Misplaced _ in number");
11921 /* make an sv from the string */
11925 We try to do an integer conversion first if no characters
11926 indicating "float" have been found.
11931 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
11933 if (flags == IS_NUMBER_IN_UV) {
11935 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
11938 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
11939 if (uv <= (UV) IV_MIN)
11940 sv_setiv(sv, -(IV)uv);
11947 /* terminate the string */
11949 nv = Atof(PL_tokenbuf);
11953 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
11954 (PL_hints & HINT_NEW_INTEGER) )
11955 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
11956 (floatit ? "float" : "integer"),
11960 /* if it starts with a v, it could be a v-string */
11963 sv = newSV(5); /* preallocate storage space */
11964 s = scan_vstring(s,sv);
11968 /* make the op for the constant and return */
11971 lvalp->opval = newSVOP(OP_CONST, 0, sv);
11973 lvalp->opval = NULL;
11979 S_scan_formline(pTHX_ register char *s)
11982 register char *eol;
11984 SV * const stuff = newSVpvs("");
11985 bool needargs = FALSE;
11986 bool eofmt = FALSE;
11988 char *tokenstart = s;
11991 if (PL_madskills) {
11992 savewhite = PL_thiswhite;
11997 while (!needargs) {
11999 #ifdef PERL_STRICT_CR
12000 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
12002 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
12004 if (*t == '\n' || t == PL_bufend) {
12009 if (PL_in_eval && !PL_rsfp) {
12010 eol = (char *) memchr(s,'\n',PL_bufend-s);
12015 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12017 for (t = s; t < eol; t++) {
12018 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12020 goto enough; /* ~~ must be first line in formline */
12022 if (*t == '@' || *t == '^')
12026 sv_catpvn(stuff, s, eol-s);
12027 #ifndef PERL_STRICT_CR
12028 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12029 char *end = SvPVX(stuff) + SvCUR(stuff);
12032 SvCUR_set(stuff, SvCUR(stuff) - 1);
12042 if (PL_madskills) {
12044 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12046 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12049 s = filter_gets(PL_linestr, PL_rsfp, 0);
12051 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12053 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12055 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12056 PL_last_lop = PL_last_uni = NULL;
12065 if (SvCUR(stuff)) {
12068 PL_lex_state = LEX_NORMAL;
12069 start_force(PL_curforce);
12070 NEXTVAL_NEXTTOKE.ival = 0;
12074 PL_lex_state = LEX_FORMLINE;
12076 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12078 else if (PL_encoding)
12079 sv_recode_to_utf8(stuff, PL_encoding);
12081 start_force(PL_curforce);
12082 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12084 start_force(PL_curforce);
12085 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12089 SvREFCNT_dec(stuff);
12091 PL_lex_formbrack = 0;
12095 if (PL_madskills) {
12097 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12099 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12100 PL_thiswhite = savewhite;
12112 PL_cshlen = strlen(PL_cshname);
12114 #if defined(USE_ITHREADS)
12115 PERL_UNUSED_CONTEXT;
12121 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12124 const I32 oldsavestack_ix = PL_savestack_ix;
12125 CV* const outsidecv = PL_compcv;
12128 assert(SvTYPE(PL_compcv) == SVt_PVCV);
12130 SAVEI32(PL_subline);
12131 save_item(PL_subname);
12132 SAVESPTR(PL_compcv);
12134 PL_compcv = (CV*)newSV(0);
12135 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12136 CvFLAGS(PL_compcv) |= flags;
12138 PL_subline = CopLINE(PL_curcop);
12139 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12140 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12141 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12143 return oldsavestack_ix;
12147 #pragma segment Perl_yylex
12150 Perl_yywarn(pTHX_ const char *s)
12153 PL_in_eval |= EVAL_WARNONLY;
12155 PL_in_eval &= ~EVAL_WARNONLY;
12160 Perl_yyerror(pTHX_ const char *s)
12163 const char *where = NULL;
12164 const char *context = NULL;
12168 if (!yychar || (yychar == ';' && !PL_rsfp))
12170 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12171 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12172 PL_oldbufptr != PL_bufptr) {
12175 The code below is removed for NetWare because it abends/crashes on NetWare
12176 when the script has error such as not having the closing quotes like:
12177 if ($var eq "value)
12178 Checking of white spaces is anyway done in NetWare code.
12181 while (isSPACE(*PL_oldoldbufptr))
12184 context = PL_oldoldbufptr;
12185 contlen = PL_bufptr - PL_oldoldbufptr;
12187 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12188 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12191 The code below is removed for NetWare because it abends/crashes on NetWare
12192 when the script has error such as not having the closing quotes like:
12193 if ($var eq "value)
12194 Checking of white spaces is anyway done in NetWare code.
12197 while (isSPACE(*PL_oldbufptr))
12200 context = PL_oldbufptr;
12201 contlen = PL_bufptr - PL_oldbufptr;
12203 else if (yychar > 255)
12204 where = "next token ???";
12205 else if (yychar == -2) { /* YYEMPTY */
12206 if (PL_lex_state == LEX_NORMAL ||
12207 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12208 where = "at end of line";
12209 else if (PL_lex_inpat)
12210 where = "within pattern";
12212 where = "within string";
12215 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12217 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12218 else if (isPRINT_LC(yychar))
12219 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12221 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12222 where = SvPVX_const(where_sv);
12224 msg = sv_2mortal(newSVpv(s, 0));
12225 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12226 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12228 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12230 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12231 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12232 Perl_sv_catpvf(aTHX_ msg,
12233 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12234 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12237 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12238 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg);
12241 if (PL_error_count >= 10) {
12242 if (PL_in_eval && SvCUR(ERRSV))
12243 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12244 ERRSV, OutCopFILE(PL_curcop));
12246 Perl_croak(aTHX_ "%s has too many errors.\n",
12247 OutCopFILE(PL_curcop));
12250 PL_in_my_stash = NULL;
12254 #pragma segment Main
12258 S_swallow_bom(pTHX_ U8 *s)
12261 const STRLEN slen = SvCUR(PL_linestr);
12264 if (s[1] == 0xFE) {
12265 /* UTF-16 little-endian? (or UTF32-LE?) */
12266 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
12267 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12268 #ifndef PERL_NO_UTF16_FILTER
12269 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12272 if (PL_bufend > (char*)s) {
12276 filter_add(utf16rev_textfilter, NULL);
12277 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12278 utf16_to_utf8_reversed(s, news,
12279 PL_bufend - (char*)s - 1,
12281 sv_setpvn(PL_linestr, (const char*)news, newlen);
12283 s = (U8*)SvPVX(PL_linestr);
12284 Copy(news, s, newlen, U8);
12288 SvUTF8_on(PL_linestr);
12289 s = (U8*)SvPVX(PL_linestr);
12291 /* FIXME - is this a general bug fix? */
12294 PL_bufend = SvPVX(PL_linestr) + newlen;
12297 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12302 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
12303 #ifndef PERL_NO_UTF16_FILTER
12304 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12307 if (PL_bufend > (char *)s) {
12311 filter_add(utf16_textfilter, NULL);
12312 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12313 utf16_to_utf8(s, news,
12314 PL_bufend - (char*)s,
12316 sv_setpvn(PL_linestr, (const char*)news, newlen);
12318 SvUTF8_on(PL_linestr);
12319 s = (U8*)SvPVX(PL_linestr);
12320 PL_bufend = SvPVX(PL_linestr) + newlen;
12323 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12328 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12329 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12330 s += 3; /* UTF-8 */
12336 if (s[2] == 0xFE && s[3] == 0xFF) {
12337 /* UTF-32 big-endian */
12338 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12341 else if (s[2] == 0 && s[3] != 0) {
12344 * are a good indicator of UTF-16BE. */
12345 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12350 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12353 * are a good indicator of UTF-16LE. */
12354 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12363 * Restore a source filter.
12367 restore_rsfp(pTHX_ void *f)
12370 PerlIO * const fp = (PerlIO*)f;
12372 if (PL_rsfp == PerlIO_stdin())
12373 PerlIO_clearerr(PL_rsfp);
12374 else if (PL_rsfp && (PL_rsfp != fp))
12375 PerlIO_close(PL_rsfp);
12379 #ifndef PERL_NO_UTF16_FILTER
12381 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12384 const STRLEN old = SvCUR(sv);
12385 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12386 DEBUG_P(PerlIO_printf(Perl_debug_log,
12387 "utf16_textfilter(%p): %d %d (%d)\n",
12388 utf16_textfilter, idx, maxlen, (int) count));
12392 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12393 Copy(SvPVX_const(sv), tmps, old, char);
12394 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12395 SvCUR(sv) - old, &newlen);
12396 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12398 DEBUG_P({sv_dump(sv);});
12403 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12406 const STRLEN old = SvCUR(sv);
12407 const I32 count = FILTER_READ(idx+1, sv, maxlen);
12408 DEBUG_P(PerlIO_printf(Perl_debug_log,
12409 "utf16rev_textfilter(%p): %d %d (%d)\n",
12410 utf16rev_textfilter, idx, maxlen, (int) count));
12414 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12415 Copy(SvPVX_const(sv), tmps, old, char);
12416 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12417 SvCUR(sv) - old, &newlen);
12418 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12420 DEBUG_P({ sv_dump(sv); });
12426 Returns a pointer to the next character after the parsed
12427 vstring, as well as updating the passed in sv.
12429 Function must be called like
12432 s = scan_vstring(s,sv);
12434 The sv should already be large enough to store the vstring
12435 passed in, for performance reasons.
12440 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12443 const char *pos = s;
12444 const char *start = s;
12445 if (*pos == 'v') pos++; /* get past 'v' */
12446 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12448 if ( *pos != '.') {
12449 /* this may not be a v-string if followed by => */
12450 const char *next = pos;
12451 while (next < PL_bufend && isSPACE(*next))
12453 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12454 /* return string not v-string */
12455 sv_setpvn(sv,(char *)s,pos-s);
12456 return (char *)pos;
12460 if (!isALPHA(*pos)) {
12461 U8 tmpbuf[UTF8_MAXBYTES+1];
12464 s++; /* get past 'v' */
12466 sv_setpvn(sv, "", 0);
12469 /* this is atoi() that tolerates underscores */
12472 const char *end = pos;
12474 while (--end >= s) {
12476 const UV orev = rev;
12477 rev += (*end - '0') * mult;
12479 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12480 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12481 "Integer overflow in decimal number");
12485 if (rev > 0x7FFFFFFF)
12486 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12488 /* Append native character for the rev point */
12489 tmpend = uvchr_to_utf8(tmpbuf, rev);
12490 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12491 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12493 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12499 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12503 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12511 * c-indentation-style: bsd
12512 * c-basic-offset: 4
12513 * indent-tabs-mode: t
12516 * ex: set ts=8 sts=4 sw=4 noet: