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);
38 #define XFAKEBRACK 128
41 #ifdef USE_UTF8_SCRIPTS
42 # define UTF (!IN_BYTES)
44 # define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
47 /* In variables named $^X, these are the legal values for X.
48 * 1999-02-27 mjd-perl-patch@plover.com */
49 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
51 /* On MacOS, respect nonbreaking spaces */
52 #ifdef MACOS_TRADITIONAL
53 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
55 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
58 /* LEX_* are values for PL_lex_state, the state of the lexer.
59 * They are arranged oddly so that the guard on the switch statement
60 * can get by with a single comparison (if the compiler is smart enough).
63 /* #define LEX_NOTPARSING 11 is done in perl.h. */
65 #define LEX_NORMAL 10 /* normal code (ie not within "...") */
66 #define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
67 #define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
68 #define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
69 #define LEX_INTERPSTART 6 /* expecting the start of a $var */
71 /* at end of code, eg "$x" followed by: */
72 #define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
73 #define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
75 #define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
76 string or after \E, $foo, etc */
77 #define LEX_INTERPCONST 2 /* NOT USED */
78 #define LEX_FORMLINE 1 /* expecting a format line */
79 #define LEX_KNOWNEXT 0 /* next token known; just return it */
83 static const char* const lex_state_names[] = {
102 #include "keywords.h"
104 /* CLINE is a macro that ensures PL_copline has a sane value */
109 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
112 * Convenience functions to return different tokens and prime the
113 * lexer for the next token. They all take an argument.
115 * TOKEN : generic token (used for '(', DOLSHARP, etc)
116 * OPERATOR : generic operator
117 * AOPERATOR : assignment operator
118 * PREBLOCK : beginning the block after an if, while, foreach, ...
119 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
120 * PREREF : *EXPR where EXPR is not a simple identifier
121 * TERM : expression term
122 * LOOPX : loop exiting command (goto, last, dump, etc)
123 * FTST : file test operator
124 * FUN0 : zero-argument function
125 * FUN1 : not used, except for not, which isn't a UNIOP
126 * BOop : bitwise or or xor
128 * SHop : shift operator
129 * PWop : power operator
130 * PMop : pattern-matching operator
131 * Aop : addition-level operator
132 * Mop : multiplication-level operator
133 * Eop : equality-testing operator
134 * Rop : relational operator <= != gt
136 * Also see LOP and lop() below.
139 #ifdef DEBUGGING /* Serve -DT. */
140 # define REPORT(retval) tokereport((I32)retval)
142 # define REPORT(retval) (retval)
145 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
146 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
147 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
148 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
149 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
150 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
151 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
152 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
153 #define FTST(f) return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
154 #define FUN0(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
155 #define FUN1(f) return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
156 #define BOop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
157 #define BAop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
158 #define SHop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
159 #define PWop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
160 #define PMop(f) return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
161 #define Aop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
162 #define Mop(f) return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
163 #define Eop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
164 #define Rop(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
166 /* This bit of chicanery makes a unary function followed by
167 * a parenthesis into a function with one argument, highest precedence.
168 * The UNIDOR macro is for unary functions that can be followed by the //
169 * operator (such as C<shift // 0>).
171 #define UNI2(f,x) { \
175 PL_last_uni = PL_oldbufptr; \
176 PL_last_lop_op = f; \
178 return REPORT( (int)FUNC1 ); \
180 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
182 #define UNI(f) UNI2(f,XTERM)
183 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
185 #define UNIBRACK(f) { \
188 PL_last_uni = PL_oldbufptr; \
190 return REPORT( (int)FUNC1 ); \
192 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
195 /* grandfather return to old style */
196 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
200 /* how to interpret the yylval associated with the token */
204 TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
210 static struct debug_tokens {
212 enum token_type type;
214 } const debug_tokens[] =
216 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
217 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
218 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
219 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
220 { ARROW, TOKENTYPE_NONE, "ARROW" },
221 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
222 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
223 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
224 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
225 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
226 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
227 { DO, TOKENTYPE_NONE, "DO" },
228 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
229 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
230 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
231 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
232 { ELSE, TOKENTYPE_NONE, "ELSE" },
233 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
234 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
235 { FOR, TOKENTYPE_IVAL, "FOR" },
236 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
237 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
238 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
239 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
240 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
241 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
242 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
243 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
244 { IF, TOKENTYPE_IVAL, "IF" },
245 { LABEL, TOKENTYPE_PVAL, "LABEL" },
246 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
247 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
248 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
249 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
250 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
251 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
252 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
253 { MY, TOKENTYPE_IVAL, "MY" },
254 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
255 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
256 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
257 { OROP, TOKENTYPE_IVAL, "OROP" },
258 { OROR, TOKENTYPE_NONE, "OROR" },
259 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
260 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
261 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
262 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
263 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
264 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
265 { PREINC, TOKENTYPE_NONE, "PREINC" },
266 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
267 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
268 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
269 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
270 { SUB, TOKENTYPE_NONE, "SUB" },
271 { THING, TOKENTYPE_OPVAL, "THING" },
272 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
273 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
274 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
275 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
276 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
277 { USE, TOKENTYPE_IVAL, "USE" },
278 { WHEN, TOKENTYPE_IVAL, "WHEN" },
279 { WHILE, TOKENTYPE_IVAL, "WHILE" },
280 { WORD, TOKENTYPE_OPVAL, "WORD" },
281 { 0, TOKENTYPE_NONE, 0 }
284 /* dump the returned token in rv, plus any optional arg in yylval */
287 S_tokereport(pTHX_ I32 rv)
291 const char *name = Nullch;
292 enum token_type type = TOKENTYPE_NONE;
293 const struct debug_tokens *p;
294 SV* const report = newSVpvs("<== ");
296 for (p = debug_tokens; p->token; p++) {
297 if (p->token == (int)rv) {
304 Perl_sv_catpv(aTHX_ report, name);
305 else if ((char)rv > ' ' && (char)rv < '~')
306 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
308 sv_catpvs(report, "EOF");
310 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
313 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
316 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
318 case TOKENTYPE_OPNUM:
319 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
320 PL_op_name[yylval.ival]);
323 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
325 case TOKENTYPE_OPVAL:
327 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
328 PL_op_name[yylval.opval->op_type]);
329 if (yylval.opval->op_type == OP_CONST) {
330 Perl_sv_catpvf(aTHX_ report, " %s",
331 SvPEEK(cSVOPx_sv(yylval.opval)));
336 sv_catpvs(report, "(opval=null)");
339 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
345 /* print the buffer with suitable escapes */
348 S_printbuf(pTHX_ const char* fmt, const char* s)
350 SV* const tmp = newSVpvs("");
351 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
360 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
361 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
365 S_ao(pTHX_ int toketype)
368 if (*PL_bufptr == '=') {
370 if (toketype == ANDAND)
371 yylval.ival = OP_ANDASSIGN;
372 else if (toketype == OROR)
373 yylval.ival = OP_ORASSIGN;
374 else if (toketype == DORDOR)
375 yylval.ival = OP_DORASSIGN;
383 * When Perl expects an operator and finds something else, no_op
384 * prints the warning. It always prints "<something> found where
385 * operator expected. It prints "Missing semicolon on previous line?"
386 * if the surprise occurs at the start of the line. "do you need to
387 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
388 * where the compiler doesn't know if foo is a method call or a function.
389 * It prints "Missing operator before end of line" if there's nothing
390 * after the missing operator, or "... before <...>" if there is something
391 * after the missing operator.
395 S_no_op(pTHX_ const char *what, char *s)
398 char * const oldbp = PL_bufptr;
399 const bool is_first = (PL_oldbufptr == PL_linestart);
405 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
406 if (ckWARN_d(WARN_SYNTAX)) {
408 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
409 "\t(Missing semicolon on previous line?)\n");
410 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
412 for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
413 if (t < PL_bufptr && isSPACE(*t))
414 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
415 "\t(Do you need to predeclare %.*s?)\n",
416 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
420 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
421 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
429 * Complain about missing quote/regexp/heredoc terminator.
430 * If it's called with (char *)NULL then it cauterizes the line buffer.
431 * If we're in a delimited string and the delimiter is a control
432 * character, it's reformatted into a two-char sequence like ^C.
437 S_missingterm(pTHX_ char *s)
443 char * const nl = strrchr(s,'\n');
449 iscntrl(PL_multi_close)
451 PL_multi_close < 32 || PL_multi_close == 127
455 tmpbuf[1] = (char)toCTRL(PL_multi_close);
460 *tmpbuf = (char)PL_multi_close;
464 q = strchr(s,'"') ? '\'' : '"';
465 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
468 #define FEATURE_IS_ENABLED(name) \
469 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
470 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
472 * S_feature_is_enabled
473 * Check whether the named feature is enabled.
476 S_feature_is_enabled(pTHX_ char *name, STRLEN namelen)
479 HV * const hinthv = GvHV(PL_hintgv);
480 char he_name[32] = "feature_";
481 (void) strncpy(&he_name[8], name, 24);
483 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
491 Perl_deprecate(pTHX_ const char *s)
493 if (ckWARN(WARN_DEPRECATED))
494 Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
498 Perl_deprecate_old(pTHX_ const char *s)
500 /* This function should NOT be called for any new deprecated warnings */
501 /* Use Perl_deprecate instead */
503 /* It is here to maintain backward compatibility with the pre-5.8 */
504 /* warnings category hierarchy. The "deprecated" category used to */
505 /* live under the "syntax" category. It is now a top-level category */
506 /* in its own right. */
508 if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
509 Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
510 "Use of %s is deprecated", s);
514 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
515 * utf16-to-utf8-reversed.
518 #ifdef PERL_CR_FILTER
522 register const char *s = SvPVX_const(sv);
523 register const char * const e = s + SvCUR(sv);
524 /* outer loop optimized to do nothing if there are no CR-LFs */
526 if (*s++ == '\r' && *s == '\n') {
527 /* hit a CR-LF, need to copy the rest */
528 register char *d = s - 1;
531 if (*s == '\r' && s[1] == '\n')
542 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
544 const I32 count = FILTER_READ(idx+1, sv, maxlen);
545 if (count > 0 && !maxlen)
553 * Initialize variables. Uses the Perl save_stack to save its state (for
554 * recursive calls to the parser).
558 Perl_lex_start(pTHX_ SV *line)
564 SAVEI32(PL_lex_dojoin);
565 SAVEI32(PL_lex_brackets);
566 SAVEI32(PL_lex_casemods);
567 SAVEI32(PL_lex_starts);
568 SAVEI32(PL_lex_state);
569 SAVEVPTR(PL_lex_inpat);
570 SAVEI32(PL_lex_inwhat);
571 if (PL_lex_state == LEX_KNOWNEXT) {
572 I32 toke = PL_nexttoke;
573 while (--toke >= 0) {
574 SAVEI32(PL_nexttype[toke]);
575 SAVEVPTR(PL_nextval[toke]);
577 SAVEI32(PL_nexttoke);
579 SAVECOPLINE(PL_curcop);
582 SAVEPPTR(PL_oldbufptr);
583 SAVEPPTR(PL_oldoldbufptr);
584 SAVEPPTR(PL_last_lop);
585 SAVEPPTR(PL_last_uni);
586 SAVEPPTR(PL_linestart);
587 SAVESPTR(PL_linestr);
588 SAVEGENERICPV(PL_lex_brackstack);
589 SAVEGENERICPV(PL_lex_casestack);
590 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
591 SAVESPTR(PL_lex_stuff);
592 SAVEI32(PL_lex_defer);
593 SAVEI32(PL_sublex_info.sub_inwhat);
594 SAVESPTR(PL_lex_repl);
596 SAVEINT(PL_lex_expect);
598 PL_lex_state = LEX_NORMAL;
602 Newx(PL_lex_brackstack, 120, char);
603 Newx(PL_lex_casestack, 12, char);
605 *PL_lex_casestack = '\0';
608 PL_lex_stuff = Nullsv;
609 PL_lex_repl = Nullsv;
613 PL_sublex_info.sub_inwhat = 0;
615 if (SvREADONLY(PL_linestr))
616 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
617 s = SvPV_const(PL_linestr, len);
618 if (!len || s[len-1] != ';') {
619 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
620 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
621 sv_catpvs(PL_linestr, "\n;");
623 SvTEMP_off(PL_linestr);
624 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
625 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
626 PL_last_lop = PL_last_uni = Nullch;
632 * Finalizer for lexing operations. Must be called when the parser is
633 * done with the lexer.
640 PL_doextract = FALSE;
645 * This subroutine has nothing to do with tilting, whether at windmills
646 * or pinball tables. Its name is short for "increment line". It
647 * increments the current line number in CopLINE(PL_curcop) and checks
648 * to see whether the line starts with a comment of the form
649 * # line 500 "foo.pm"
650 * If so, it sets the current line number and file to the values in the comment.
654 S_incline(pTHX_ char *s)
662 CopLINE_inc(PL_curcop);
665 while (SPACE_OR_TAB(*s)) s++;
666 if (strnEQ(s, "line", 4))
670 if (SPACE_OR_TAB(*s))
674 while (SPACE_OR_TAB(*s)) s++;
680 while (SPACE_OR_TAB(*s))
682 if (*s == '"' && (t = strchr(s+1, '"'))) {
687 for (t = s; !isSPACE(*t); t++) ;
690 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
692 if (*e != '\n' && *e != '\0')
693 return; /* false alarm */
699 const char * const cf = CopFILE(PL_curcop);
700 STRLEN tmplen = cf ? strlen(cf) : 0;
701 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
702 /* must copy *{"::_<(eval N)[oldfilename:L]"}
703 * to *{"::_<newfilename"} */
704 char smallbuf[256], smallbuf2[256];
705 char *tmpbuf, *tmpbuf2;
707 STRLEN tmplen2 = strlen(s);
708 if (tmplen + 3 < sizeof smallbuf)
711 Newx(tmpbuf, tmplen + 3, char);
712 if (tmplen2 + 3 < sizeof smallbuf2)
715 Newx(tmpbuf2, tmplen2 + 3, char);
716 tmpbuf[0] = tmpbuf2[0] = '_';
717 tmpbuf[1] = tmpbuf2[1] = '<';
718 memcpy(tmpbuf + 2, cf, ++tmplen);
719 memcpy(tmpbuf2 + 2, s, ++tmplen2);
721 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
723 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
725 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
726 /* adjust ${"::_<newfilename"} to store the new file name */
727 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
728 GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
729 GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
731 if (tmpbuf != smallbuf) Safefree(tmpbuf);
732 if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
735 CopFILE_free(PL_curcop);
736 CopFILE_set(PL_curcop, s);
739 CopLINE_set(PL_curcop, atoi(n)-1);
744 * Called to gobble the appropriate amount and type of whitespace.
745 * Skips comments as well.
749 S_skipspace(pTHX_ register char *s)
752 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
753 while (s < PL_bufend && SPACE_OR_TAB(*s))
759 SSize_t oldprevlen, oldoldprevlen;
760 SSize_t oldloplen = 0, oldunilen = 0;
761 while (s < PL_bufend && isSPACE(*s)) {
762 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
767 if (s < PL_bufend && *s == '#') {
768 while (s < PL_bufend && *s != '\n')
772 if (PL_in_eval && !PL_rsfp) {
779 /* only continue to recharge the buffer if we're at the end
780 * of the buffer, we're not reading from a source filter, and
781 * we're in normal lexing mode
783 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
784 PL_lex_state == LEX_FORMLINE)
787 /* try to recharge the buffer */
788 if ((s = filter_gets(PL_linestr, PL_rsfp,
789 (prevlen = SvCUR(PL_linestr)))) == Nullch)
791 /* end of file. Add on the -p or -n magic */
794 ";}continue{print or die qq(-p destination: $!\\n);}");
795 PL_minus_n = PL_minus_p = 0;
797 else if (PL_minus_n) {
798 sv_setpvn(PL_linestr, ";}", 2);
802 sv_setpvn(PL_linestr,";", 1);
804 /* reset variables for next time we lex */
805 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
807 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
808 PL_last_lop = PL_last_uni = Nullch;
810 /* Close the filehandle. Could be from -P preprocessor,
811 * STDIN, or a regular file. If we were reading code from
812 * STDIN (because the commandline held no -e or filename)
813 * then we don't close it, we reset it so the code can
814 * read from STDIN too.
817 if (PL_preprocess && !PL_in_eval)
818 (void)PerlProc_pclose(PL_rsfp);
819 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
820 PerlIO_clearerr(PL_rsfp);
822 (void)PerlIO_close(PL_rsfp);
827 /* not at end of file, so we only read another line */
828 /* make corresponding updates to old pointers, for yyerror() */
829 oldprevlen = PL_oldbufptr - PL_bufend;
830 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
832 oldunilen = PL_last_uni - PL_bufend;
834 oldloplen = PL_last_lop - PL_bufend;
835 PL_linestart = PL_bufptr = s + prevlen;
836 PL_bufend = s + SvCUR(PL_linestr);
838 PL_oldbufptr = s + oldprevlen;
839 PL_oldoldbufptr = s + oldoldprevlen;
841 PL_last_uni = s + oldunilen;
843 PL_last_lop = s + oldloplen;
846 /* debugger active and we're not compiling the debugger code,
847 * so store the line into the debugger's array of lines
849 if (PERLDB_LINE && PL_curstash != PL_debstash) {
850 SV * const sv = newSV(0);
852 sv_upgrade(sv, SVt_PVMG);
853 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
856 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
863 * Check the unary operators to ensure there's no ambiguity in how they're
864 * used. An ambiguous piece of code would be:
866 * This doesn't mean rand() + 5. Because rand() is a unary operator,
867 * the +5 is its argument.
877 if (PL_oldoldbufptr != PL_last_uni)
879 while (isSPACE(*PL_last_uni))
881 for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
882 if ((t = strchr(s, '(')) && t < PL_bufptr)
885 /* XXX Things like this are just so nasty. We shouldn't be modifying
886 source code, even if we realquick set it back. */
887 if (ckWARN_d(WARN_AMBIGUOUS)){
890 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
891 "Warning: Use of \"%s\" without parentheses is ambiguous",
898 * LOP : macro to build a list operator. Its behaviour has been replaced
899 * with a subroutine, S_lop() for which LOP is just another name.
902 #define LOP(f,x) return lop(f,x,s)
906 * Build a list operator (or something that might be one). The rules:
907 * - if we have a next token, then it's a list operator [why?]
908 * - if the next thing is an opening paren, then it's a function
909 * - else it's a list operator
913 S_lop(pTHX_ I32 f, int x, char *s)
920 PL_last_lop = PL_oldbufptr;
921 PL_last_lop_op = (OPCODE)f;
923 return REPORT(LSTOP);
930 return REPORT(LSTOP);
935 * When the lexer realizes it knows the next token (for instance,
936 * it is reordering tokens for the parser) then it can call S_force_next
937 * to know what token to return the next time the lexer is called. Caller
938 * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer
939 * handles the token correctly.
943 S_force_next(pTHX_ I32 type)
946 PL_nexttype[PL_nexttoke] = type;
948 if (PL_lex_state != LEX_KNOWNEXT) {
949 PL_lex_defer = PL_lex_state;
950 PL_lex_expect = PL_expect;
951 PL_lex_state = LEX_KNOWNEXT;
956 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
959 SV * const sv = newSVpvn(start,len);
960 if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
967 * When the lexer knows the next thing is a word (for instance, it has
968 * just seen -> and it knows that the next char is a word char, then
969 * it calls S_force_word to stick the next word into the PL_next lookahead.
972 * char *start : buffer position (must be within PL_linestr)
973 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
974 * int check_keyword : if true, Perl checks to make sure the word isn't
975 * a keyword (do this if the word is a label, e.g. goto FOO)
976 * int allow_pack : if true, : characters will also be allowed (require,
978 * int allow_initial_tick : used by the "sub" lexer only.
982 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
988 start = skipspace(start);
990 if (isIDFIRST_lazy_if(s,UTF) ||
991 (allow_pack && *s == ':') ||
992 (allow_initial_tick && *s == '\'') )
994 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
995 if (check_keyword && keyword(PL_tokenbuf, len))
997 if (token == METHOD) {
1002 PL_expect = XOPERATOR;
1005 PL_nextval[PL_nexttoke].opval
1006 = (OP*)newSVOP(OP_CONST,0,
1007 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1008 PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
1016 * Called when the lexer wants $foo *foo &foo etc, but the program
1017 * text only contains the "foo" portion. The first argument is a pointer
1018 * to the "foo", and the second argument is the type symbol to prefix.
1019 * Forces the next token to be a "WORD".
1020 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1024 S_force_ident(pTHX_ register const char *s, int kind)
1028 const STRLEN len = strlen(s);
1029 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1030 PL_nextval[PL_nexttoke].opval = o;
1033 o->op_private = OPpCONST_ENTERED;
1034 /* XXX see note in pp_entereval() for why we forgo typo
1035 warnings if the symbol must be introduced in an eval.
1037 gv_fetchpvn_flags(s, len,
1038 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1040 kind == '$' ? SVt_PV :
1041 kind == '@' ? SVt_PVAV :
1042 kind == '%' ? SVt_PVHV :
1050 Perl_str_to_version(pTHX_ SV *sv)
1055 const char *start = SvPV_const(sv,len);
1056 const char * const end = start + len;
1057 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1058 while (start < end) {
1062 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1067 retval += ((NV)n)/nshift;
1076 * Forces the next token to be a version number.
1077 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1078 * and if "guessing" is TRUE, then no new token is created (and the caller
1079 * must use an alternative parsing method).
1083 S_force_version(pTHX_ char *s, int guessing)
1086 OP *version = Nullop;
1095 while (isDIGIT(*d) || *d == '_' || *d == '.')
1097 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1099 s = scan_num(s, &yylval);
1100 version = yylval.opval;
1101 ver = cSVOPx(version)->op_sv;
1102 if (SvPOK(ver) && !SvNIOK(ver)) {
1103 SvUPGRADE(ver, SVt_PVNV);
1104 SvNV_set(ver, str_to_version(ver));
1105 SvNOK_on(ver); /* hint that it is a version */
1112 /* NOTE: The parser sees the package name and the VERSION swapped */
1113 PL_nextval[PL_nexttoke].opval = version;
1121 * Tokenize a quoted string passed in as an SV. It finds the next
1122 * chunk, up to end of string or a backslash. It may make a new
1123 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1128 S_tokeq(pTHX_ SV *sv)
1132 register char *send;
1140 s = SvPV_force(sv, len);
1141 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1144 while (s < send && *s != '\\')
1149 if ( PL_hints & HINT_NEW_STRING ) {
1150 pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1156 if (s + 1 < send && (s[1] == '\\'))
1157 s++; /* all that, just for this */
1162 SvCUR_set(sv, d - SvPVX_const(sv));
1164 if ( PL_hints & HINT_NEW_STRING )
1165 return new_constant(NULL, 0, "q", sv, pv, "q");
1170 * Now come three functions related to double-quote context,
1171 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1172 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1173 * interact with PL_lex_state, and create fake ( ... ) argument lists
1174 * to handle functions and concatenation.
1175 * They assume that whoever calls them will be setting up a fake
1176 * join call, because each subthing puts a ',' after it. This lets
1179 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1181 * (I'm not sure whether the spurious commas at the end of lcfirst's
1182 * arguments and join's arguments are created or not).
1187 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1189 * Pattern matching will set PL_lex_op to the pattern-matching op to
1190 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1192 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1194 * Everything else becomes a FUNC.
1196 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1197 * had an OP_CONST or OP_READLINE). This just sets us up for a
1198 * call to S_sublex_push().
1202 S_sublex_start(pTHX)
1205 register const I32 op_type = yylval.ival;
1207 if (op_type == OP_NULL) {
1208 yylval.opval = PL_lex_op;
1212 if (op_type == OP_CONST || op_type == OP_READLINE) {
1213 SV *sv = tokeq(PL_lex_stuff);
1215 if (SvTYPE(sv) == SVt_PVIV) {
1216 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1218 const char *p = SvPV_const(sv, len);
1219 SV * const nsv = newSVpvn(p, len);
1225 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1226 PL_lex_stuff = Nullsv;
1227 /* Allow <FH> // "foo" */
1228 if (op_type == OP_READLINE)
1229 PL_expect = XTERMORDORDOR;
1233 PL_sublex_info.super_state = PL_lex_state;
1234 PL_sublex_info.sub_inwhat = op_type;
1235 PL_sublex_info.sub_op = PL_lex_op;
1236 PL_lex_state = LEX_INTERPPUSH;
1240 yylval.opval = PL_lex_op;
1250 * Create a new scope to save the lexing state. The scope will be
1251 * ended in S_sublex_done. Returns a '(', starting the function arguments
1252 * to the uc, lc, etc. found before.
1253 * Sets PL_lex_state to LEX_INTERPCONCAT.
1262 PL_lex_state = PL_sublex_info.super_state;
1263 SAVEI32(PL_lex_dojoin);
1264 SAVEI32(PL_lex_brackets);
1265 SAVEI32(PL_lex_casemods);
1266 SAVEI32(PL_lex_starts);
1267 SAVEI32(PL_lex_state);
1268 SAVEVPTR(PL_lex_inpat);
1269 SAVEI32(PL_lex_inwhat);
1270 SAVECOPLINE(PL_curcop);
1271 SAVEPPTR(PL_bufptr);
1272 SAVEPPTR(PL_bufend);
1273 SAVEPPTR(PL_oldbufptr);
1274 SAVEPPTR(PL_oldoldbufptr);
1275 SAVEPPTR(PL_last_lop);
1276 SAVEPPTR(PL_last_uni);
1277 SAVEPPTR(PL_linestart);
1278 SAVESPTR(PL_linestr);
1279 SAVEGENERICPV(PL_lex_brackstack);
1280 SAVEGENERICPV(PL_lex_casestack);
1282 PL_linestr = PL_lex_stuff;
1283 PL_lex_stuff = Nullsv;
1285 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1286 = SvPVX(PL_linestr);
1287 PL_bufend += SvCUR(PL_linestr);
1288 PL_last_lop = PL_last_uni = Nullch;
1289 SAVEFREESV(PL_linestr);
1291 PL_lex_dojoin = FALSE;
1292 PL_lex_brackets = 0;
1293 Newx(PL_lex_brackstack, 120, char);
1294 Newx(PL_lex_casestack, 12, char);
1295 PL_lex_casemods = 0;
1296 *PL_lex_casestack = '\0';
1298 PL_lex_state = LEX_INTERPCONCAT;
1299 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1301 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1302 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1303 PL_lex_inpat = PL_sublex_info.sub_op;
1305 PL_lex_inpat = Nullop;
1312 * Restores lexer state after a S_sublex_push.
1319 if (!PL_lex_starts++) {
1320 SV * const sv = newSVpvs("");
1321 if (SvUTF8(PL_linestr))
1323 PL_expect = XOPERATOR;
1324 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1328 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1329 PL_lex_state = LEX_INTERPCASEMOD;
1333 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1334 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1335 PL_linestr = PL_lex_repl;
1337 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1338 PL_bufend += SvCUR(PL_linestr);
1339 PL_last_lop = PL_last_uni = Nullch;
1340 SAVEFREESV(PL_linestr);
1341 PL_lex_dojoin = FALSE;
1342 PL_lex_brackets = 0;
1343 PL_lex_casemods = 0;
1344 *PL_lex_casestack = '\0';
1346 if (SvEVALED(PL_lex_repl)) {
1347 PL_lex_state = LEX_INTERPNORMAL;
1349 /* we don't clear PL_lex_repl here, so that we can check later
1350 whether this is an evalled subst; that means we rely on the
1351 logic to ensure sublex_done() is called again only via the
1352 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1355 PL_lex_state = LEX_INTERPCONCAT;
1356 PL_lex_repl = Nullsv;
1362 PL_bufend = SvPVX(PL_linestr);
1363 PL_bufend += SvCUR(PL_linestr);
1364 PL_expect = XOPERATOR;
1365 PL_sublex_info.sub_inwhat = 0;
1373 Extracts a pattern, double-quoted string, or transliteration. This
1376 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1377 processing a pattern (PL_lex_inpat is true), a transliteration
1378 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1380 Returns a pointer to the character scanned up to. Iff this is
1381 advanced from the start pointer supplied (ie if anything was
1382 successfully parsed), will leave an OP for the substring scanned
1383 in yylval. Caller must intuit reason for not parsing further
1384 by looking at the next characters herself.
1388 double-quoted style: \r and \n
1389 regexp special ones: \D \s
1391 backrefs: \1 (deprecated in substitution replacements)
1392 case and quoting: \U \Q \E
1393 stops on @ and $, but not for $ as tail anchor
1395 In transliterations:
1396 characters are VERY literal, except for - not at the start or end
1397 of the string, which indicates a range. scan_const expands the
1398 range to the full set of intermediate characters.
1400 In double-quoted strings:
1402 double-quoted style: \r and \n
1404 backrefs: \1 (deprecated)
1405 case and quoting: \U \Q \E
1408 scan_const does *not* construct ops to handle interpolated strings.
1409 It stops processing as soon as it finds an embedded $ or @ variable
1410 and leaves it to the caller to work out what's going on.
1412 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo.
1414 $ in pattern could be $foo or could be tail anchor. Assumption:
1415 it's a tail anchor if $ is the last thing in the string, or if it's
1416 followed by one of ")| \n\t"
1418 \1 (backreferences) are turned into $1
1420 The structure of the code is
1421 while (there's a character to process) {
1422 handle transliteration ranges
1423 skip regexp comments
1424 skip # initiated comments in //x patterns
1425 check for embedded @foo
1426 check for embedded scalars
1428 leave intact backslashes from leave (below)
1429 deprecate \1 in strings and sub replacements
1430 handle string-changing backslashes \l \U \Q \E, etc.
1431 switch (what was escaped) {
1432 handle - in a transliteration (becomes a literal -)
1433 handle \132 octal characters
1434 handle 0x15 hex characters
1435 handle \cV (control V)
1436 handle printf backslashes (\f, \r, \n, etc)
1438 } (end if backslash)
1439 } (end while character to read)
1444 S_scan_const(pTHX_ char *start)
1447 register char *send = PL_bufend; /* end of the constant */
1448 SV *sv = newSV(send - start); /* sv for the constant */
1449 register char *s = start; /* start of the constant */
1450 register char *d = SvPVX(sv); /* destination for copies */
1451 bool dorange = FALSE; /* are we in a translit range? */
1452 bool didrange = FALSE; /* did we just finish a range? */
1453 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1454 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1457 UV literal_endpoint = 0;
1460 const char *leaveit = /* set of acceptably-backslashed characters */
1462 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#"
1465 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1466 /* If we are doing a trans and we know we want UTF8 set expectation */
1467 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1468 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1472 while (s < send || dorange) {
1473 /* get transliterations out of the way (they're most literal) */
1474 if (PL_lex_inwhat == OP_TRANS) {
1475 /* expand a range A-Z to the full set of characters. AIE! */
1477 I32 i; /* current expanded character */
1478 I32 min; /* first character in range */
1479 I32 max; /* last character in range */
1482 char * const c = (char*)utf8_hop((U8*)d, -1);
1486 *c = (char)UTF_TO_NATIVE(0xff);
1487 /* mark the range as done, and continue */
1493 i = d - SvPVX_const(sv); /* remember current offset */
1494 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1495 d = SvPVX(sv) + i; /* refresh d after realloc */
1496 d -= 2; /* eat the first char and the - */
1498 min = (U8)*d; /* first char in range */
1499 max = (U8)d[1]; /* last char in range */
1503 "Invalid range \"%c-%c\" in transliteration operator",
1504 (char)min, (char)max);
1508 if (literal_endpoint == 2 &&
1509 ((isLOWER(min) && isLOWER(max)) ||
1510 (isUPPER(min) && isUPPER(max)))) {
1512 for (i = min; i <= max; i++)
1514 *d++ = NATIVE_TO_NEED(has_utf8,i);
1516 for (i = min; i <= max; i++)
1518 *d++ = NATIVE_TO_NEED(has_utf8,i);
1523 for (i = min; i <= max; i++)
1526 /* mark the range as done, and continue */
1530 literal_endpoint = 0;
1535 /* range begins (ignore - as first or last char) */
1536 else if (*s == '-' && s+1 < send && s != start) {
1538 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1541 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1551 literal_endpoint = 0;
1556 /* if we get here, we're not doing a transliteration */
1558 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1559 except for the last char, which will be done separately. */
1560 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1562 while (s+1 < send && *s != ')')
1563 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1565 else if (s[2] == '{' /* This should match regcomp.c */
1566 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1569 char *regparse = s + (s[2] == '{' ? 3 : 4);
1572 while (count && (c = *regparse)) {
1573 if (c == '\\' && regparse[1])
1581 if (*regparse != ')')
1582 regparse--; /* Leave one char for continuation. */
1583 while (s < regparse)
1584 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1588 /* likewise skip #-initiated comments in //x patterns */
1589 else if (*s == '#' && PL_lex_inpat &&
1590 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1591 while (s+1 < send && *s != '\n')
1592 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1595 /* check for embedded arrays
1596 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1598 else if (*s == '@' && s[1]
1599 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1602 /* check for embedded scalars. only stop if we're sure it's a
1605 else if (*s == '$') {
1606 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1608 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1609 break; /* in regexp, $ might be tail anchor */
1612 /* End of else if chain - OP_TRANS rejoin rest */
1615 if (*s == '\\' && s+1 < send) {
1618 /* some backslashes we leave behind */
1619 if (*leaveit && *s && strchr(leaveit, *s)) {
1620 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1621 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1625 /* deprecate \1 in strings and substitution replacements */
1626 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1627 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1629 if (ckWARN(WARN_SYNTAX))
1630 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
1635 /* string-change backslash escapes */
1636 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1641 /* if we get here, it's either a quoted -, or a digit */
1644 /* quoted - in transliterations */
1646 if (PL_lex_inwhat == OP_TRANS) {
1656 Perl_warner(aTHX_ packWARN(WARN_MISC),
1657 "Unrecognized escape \\%c passed through",
1659 /* default action is to copy the quoted character */
1660 goto default_action;
1663 /* \132 indicates an octal constant */
1664 case '0': case '1': case '2': case '3':
1665 case '4': case '5': case '6': case '7':
1669 uv = grok_oct(s, &len, &flags, NULL);
1672 goto NUM_ESCAPE_INSERT;
1674 /* \x24 indicates a hex constant */
1678 char* const e = strchr(s, '}');
1679 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1680 PERL_SCAN_DISALLOW_PREFIX;
1685 yyerror("Missing right brace on \\x{}");
1689 uv = grok_hex(s, &len, &flags, NULL);
1695 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
1696 uv = grok_hex(s, &len, &flags, NULL);
1702 /* Insert oct or hex escaped character.
1703 * There will always enough room in sv since such
1704 * escapes will be longer than any UTF-8 sequence
1705 * they can end up as. */
1707 /* We need to map to chars to ASCII before doing the tests
1710 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
1711 if (!has_utf8 && uv > 255) {
1712 /* Might need to recode whatever we have
1713 * accumulated so far if it contains any
1716 * (Can't we keep track of that and avoid
1717 * this rescan? --jhi)
1721 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
1722 if (!NATIVE_IS_INVARIANT(*c)) {
1727 const STRLEN offset = d - SvPVX_const(sv);
1729 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
1733 while (src >= (const U8 *)SvPVX_const(sv)) {
1734 if (!NATIVE_IS_INVARIANT(*src)) {
1735 const U8 ch = NATIVE_TO_ASCII(*src);
1736 *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
1737 *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
1747 if (has_utf8 || uv > 255) {
1748 d = (char*)uvchr_to_utf8((U8*)d, uv);
1750 if (PL_lex_inwhat == OP_TRANS &&
1751 PL_sublex_info.sub_op) {
1752 PL_sublex_info.sub_op->op_private |=
1753 (PL_lex_repl ? OPpTRANS_FROM_UTF
1766 /* \N{LATIN SMALL LETTER A} is a named character */
1770 char* e = strchr(s, '}');
1776 yyerror("Missing right brace on \\N{}");
1780 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
1782 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1783 PERL_SCAN_DISALLOW_PREFIX;
1786 uv = grok_hex(s, &len, &flags, NULL);
1788 goto NUM_ESCAPE_INSERT;
1790 res = newSVpvn(s + 1, e - s - 1);
1791 res = new_constant( Nullch, 0, "charnames",
1792 res, Nullsv, "\\N{...}" );
1794 sv_utf8_upgrade(res);
1795 str = SvPV_const(res,len);
1796 #ifdef EBCDIC_NEVER_MIND
1797 /* charnames uses pack U and that has been
1798 * recently changed to do the below uni->native
1799 * mapping, so this would be redundant (and wrong,
1800 * the code point would be doubly converted).
1801 * But leave this in just in case the pack U change
1802 * gets revoked, but the semantics is still
1803 * desireable for charnames. --jhi */
1805 UV uv = utf8_to_uvchr((const U8*)str, 0);
1808 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
1810 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
1811 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
1812 str = SvPV_const(res, len);
1816 if (!has_utf8 && SvUTF8(res)) {
1817 const char * const ostart = SvPVX_const(sv);
1818 SvCUR_set(sv, d - ostart);
1821 sv_utf8_upgrade(sv);
1822 /* this just broke our allocation above... */
1823 SvGROW(sv, (STRLEN)(send - start));
1824 d = SvPVX(sv) + SvCUR(sv);
1827 if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
1828 const char * const odest = SvPVX_const(sv);
1830 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
1831 d = SvPVX(sv) + (d - odest);
1833 Copy(str, d, len, char);
1840 yyerror("Missing braces on \\N{}");
1843 /* \c is a control character */
1852 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
1855 yyerror("Missing control char name in \\c");
1859 /* printf-style backslashes, formfeeds, newlines, etc */
1861 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
1864 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
1867 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
1870 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
1873 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
1876 *d++ = ASCII_TO_NEED(has_utf8,'\033');
1879 *d++ = ASCII_TO_NEED(has_utf8,'\007');
1885 } /* end if (backslash) */
1892 /* If we started with encoded form, or already know we want it
1893 and then encode the next character */
1894 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
1896 const UV uv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
1897 const STRLEN need = UNISKIP(NATIVE_TO_UNI(uv));
1900 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
1901 const STRLEN off = d - SvPVX_const(sv);
1902 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
1904 d = (char*)uvchr_to_utf8((U8*)d, uv);
1908 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1910 } /* while loop to process each character */
1912 /* terminate the string and set up the sv */
1914 SvCUR_set(sv, d - SvPVX_const(sv));
1915 if (SvCUR(sv) >= SvLEN(sv))
1916 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
1919 if (PL_encoding && !has_utf8) {
1920 sv_recode_to_utf8(sv, PL_encoding);
1926 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1927 PL_sublex_info.sub_op->op_private |=
1928 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1932 /* shrink the sv if we allocated more than we used */
1933 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1934 SvPV_shrink_to_cur(sv);
1937 /* return the substring (via yylval) only if we parsed anything */
1938 if (s > PL_bufptr) {
1939 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1940 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1942 ( PL_lex_inwhat == OP_TRANS
1944 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1947 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1954 * Returns TRUE if there's more to the expression (e.g., a subscript),
1957 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
1959 * ->[ and ->{ return TRUE
1960 * { and [ outside a pattern are always subscripts, so return TRUE
1961 * if we're outside a pattern and it's not { or [, then return FALSE
1962 * if we're in a pattern and the first char is a {
1963 * {4,5} (any digits around the comma) returns FALSE
1964 * if we're in a pattern and the first char is a [
1966 * [SOMETHING] has a funky algorithm to decide whether it's a
1967 * character class or not. It has to deal with things like
1968 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
1969 * anything else returns TRUE
1972 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1975 S_intuit_more(pTHX_ register char *s)
1978 if (PL_lex_brackets)
1980 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1982 if (*s != '{' && *s != '[')
1987 /* In a pattern, so maybe we have {n,m}. */
2004 /* On the other hand, maybe we have a character class */
2007 if (*s == ']' || *s == '^')
2010 /* this is terrifying, and it works */
2011 int weight = 2; /* let's weigh the evidence */
2013 unsigned char un_char = 255, last_un_char;
2014 const char * const send = strchr(s,']');
2015 char tmpbuf[sizeof PL_tokenbuf * 4];
2017 if (!send) /* has to be an expression */
2020 Zero(seen,256,char);
2023 else if (isDIGIT(*s)) {
2025 if (isDIGIT(s[1]) && s[2] == ']')
2031 for (; s < send; s++) {
2032 last_un_char = un_char;
2033 un_char = (unsigned char)*s;
2038 weight -= seen[un_char] * 10;
2039 if (isALNUM_lazy_if(s+1,UTF)) {
2041 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2042 len = (int)strlen(tmpbuf);
2043 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2048 else if (*s == '$' && s[1] &&
2049 strchr("[#!%*<>()-=",s[1])) {
2050 if (/*{*/ strchr("])} =",s[2]))
2059 if (strchr("wds]",s[1]))
2061 else if (seen['\''] || seen['"'])
2063 else if (strchr("rnftbxcav",s[1]))
2065 else if (isDIGIT(s[1])) {
2067 while (s[1] && isDIGIT(s[1]))
2077 if (strchr("aA01! ",last_un_char))
2079 if (strchr("zZ79~",s[1]))
2081 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2082 weight -= 5; /* cope with negative subscript */
2085 if (!isALNUM(last_un_char)
2086 && !(last_un_char == '$' || last_un_char == '@'
2087 || last_un_char == '&')
2088 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2093 if (keyword(tmpbuf, d - tmpbuf))
2096 if (un_char == last_un_char + 1)
2098 weight -= seen[un_char];
2103 if (weight >= 0) /* probably a character class */
2113 * Does all the checking to disambiguate
2115 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2116 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2118 * First argument is the stuff after the first token, e.g. "bar".
2120 * Not a method if bar is a filehandle.
2121 * Not a method if foo is a subroutine prototyped to take a filehandle.
2122 * Not a method if it's really "Foo $bar"
2123 * Method if it's "foo $bar"
2124 * Not a method if it's really "print foo $bar"
2125 * Method if it's really "foo package::" (interpreted as package->foo)
2126 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2127 * Not a method if bar is a filehandle or package, but is quoted with
2132 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2135 char *s = start + (*start == '$');
2136 char tmpbuf[sizeof PL_tokenbuf];
2141 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2145 const char *proto = SvPVX_const(cv);
2156 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2157 /* start is the beginning of the possible filehandle/object,
2158 * and s is the end of it
2159 * tmpbuf is a copy of it
2162 if (*start == '$') {
2163 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2168 return *s == '(' ? FUNCMETH : METHOD;
2170 if (!keyword(tmpbuf, len)) {
2171 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2176 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2177 if (indirgv && GvCVu(indirgv))
2179 /* filehandle or package name makes it a method */
2180 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2182 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2183 return 0; /* no assumptions -- "=>" quotes bearword */
2185 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
2186 newSVpvn(tmpbuf,len));
2187 PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
2191 return *s == '(' ? FUNCMETH : METHOD;
2199 * Return a string of Perl code to load the debugger. If PERL5DB
2200 * is set, it will return the contents of that, otherwise a
2201 * compile-time require of perl5db.pl.
2209 const char * const pdb = PerlEnv_getenv("PERL5DB");
2213 SETERRNO(0,SS_NORMAL);
2214 return "BEGIN { require 'perl5db.pl' }";
2220 /* Encoded script support. filter_add() effectively inserts a
2221 * 'pre-processing' function into the current source input stream.
2222 * Note that the filter function only applies to the current source file
2223 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2225 * The datasv parameter (which may be NULL) can be used to pass
2226 * private data to this instance of the filter. The filter function
2227 * can recover the SV using the FILTER_DATA macro and use it to
2228 * store private buffers and state information.
2230 * The supplied datasv parameter is upgraded to a PVIO type
2231 * and the IoDIRP/IoANY field is used to store the function pointer,
2232 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2233 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2234 * private use must be set using malloc'd pointers.
2238 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2244 if (!PL_rsfp_filters)
2245 PL_rsfp_filters = newAV();
2248 SvUPGRADE(datasv, SVt_PVIO);
2249 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2250 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2251 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2252 IoANY(datasv), SvPV_nolen(datasv)));
2253 av_unshift(PL_rsfp_filters, 1);
2254 av_store(PL_rsfp_filters, 0, datasv) ;
2259 /* Delete most recently added instance of this filter function. */
2261 Perl_filter_del(pTHX_ filter_t funcp)
2267 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", FPTR2DPTR(XPVIO *, funcp)));
2269 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2271 /* if filter is on top of stack (usual case) just pop it off */
2272 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2273 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2274 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2275 IoANY(datasv) = (void *)NULL;
2276 sv_free(av_pop(PL_rsfp_filters));
2280 /* we need to search for the correct entry and clear it */
2281 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2285 /* Invoke the idxth filter function for the current rsfp. */
2286 /* maxlen 0 = read one text line */
2288 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2294 if (!PL_rsfp_filters)
2296 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
2297 /* Provide a default input filter to make life easy. */
2298 /* Note that we append to the line. This is handy. */
2299 DEBUG_P(PerlIO_printf(Perl_debug_log,
2300 "filter_read %d: from rsfp\n", idx));
2304 const int old_len = SvCUR(buf_sv);
2306 /* ensure buf_sv is large enough */
2307 SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ;
2308 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
2309 if (PerlIO_error(PL_rsfp))
2310 return -1; /* error */
2312 return 0 ; /* end of file */
2314 SvCUR_set(buf_sv, old_len + len) ;
2317 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2318 if (PerlIO_error(PL_rsfp))
2319 return -1; /* error */
2321 return 0 ; /* end of file */
2324 return SvCUR(buf_sv);
2326 /* Skip this filter slot if filter has been deleted */
2327 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2328 DEBUG_P(PerlIO_printf(Perl_debug_log,
2329 "filter_read %d: skipped (filter deleted)\n",
2331 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
2333 /* Get function pointer hidden within datasv */
2334 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2335 DEBUG_P(PerlIO_printf(Perl_debug_log,
2336 "filter_read %d: via function %p (%s)\n",
2337 idx, datasv, SvPV_nolen_const(datasv)));
2338 /* Call function. The function is expected to */
2339 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2340 /* Return: <0:error, =0:eof, >0:not eof */
2341 return (*funcp)(aTHX_ idx, buf_sv, maxlen);
2345 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2348 #ifdef PERL_CR_FILTER
2349 if (!PL_rsfp_filters) {
2350 filter_add(S_cr_textfilter,NULL);
2353 if (PL_rsfp_filters) {
2355 SvCUR_set(sv, 0); /* start with empty line */
2356 if (FILTER_READ(0, sv, 0) > 0)
2357 return ( SvPVX(sv) ) ;
2362 return (sv_gets(sv, fp, append));
2366 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2371 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2375 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2376 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
2378 return GvHV(gv); /* Foo:: */
2381 /* use constant CLASS => 'MyClass' */
2382 if ((gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV))) {
2384 if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2385 pkgname = SvPV_nolen_const(sv);
2389 return gv_stashpv(pkgname, FALSE);
2393 S_tokenize_use(pTHX_ int is_use, char *s) {
2395 if (PL_expect != XSTATE)
2396 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
2397 is_use ? "use" : "no"));
2399 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
2400 s = force_version(s, TRUE);
2401 if (*s == ';' || (s = skipspace(s), *s == ';')) {
2402 PL_nextval[PL_nexttoke].opval = Nullop;
2405 else if (*s == 'v') {
2406 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2407 s = force_version(s, FALSE);
2411 s = force_word(s,WORD,FALSE,TRUE,FALSE);
2412 s = force_version(s, FALSE);
2414 yylval.ival = is_use;
2418 static const char* const exp_name[] =
2419 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2420 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
2427 Works out what to call the token just pulled out of the input
2428 stream. The yacc parser takes care of taking the ops we return and
2429 stitching them into a tree.
2435 if read an identifier
2436 if we're in a my declaration
2437 croak if they tried to say my($foo::bar)
2438 build the ops for a my() declaration
2439 if it's an access to a my() variable
2440 are we in a sort block?
2441 croak if my($a); $a <=> $b
2442 build ops for access to a my() variable
2443 if in a dq string, and they've said @foo and we can't find @foo
2445 build ops for a bareword
2446 if we already built the token before, use it.
2451 #pragma segment Perl_yylex
2457 register char *s = PL_bufptr;
2463 SV* tmp = newSVpvs("");
2464 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
2465 (IV)CopLINE(PL_curcop),
2466 lex_state_names[PL_lex_state],
2467 exp_name[PL_expect],
2468 pv_display(tmp, s, strlen(s), 0, 60));
2471 /* check if there's an identifier for us to look at */
2472 if (PL_pending_ident)
2473 return REPORT(S_pending_ident(aTHX));
2475 /* no identifier pending identification */
2477 switch (PL_lex_state) {
2479 case LEX_NORMAL: /* Some compilers will produce faster */
2480 case LEX_INTERPNORMAL: /* code if we comment these out. */
2484 /* when we've already built the next token, just pull it out of the queue */
2487 yylval = PL_nextval[PL_nexttoke];
2489 PL_lex_state = PL_lex_defer;
2490 PL_expect = PL_lex_expect;
2491 PL_lex_defer = LEX_NORMAL;
2493 return REPORT(PL_nexttype[PL_nexttoke]);
2495 /* interpolated case modifiers like \L \U, including \Q and \E.
2496 when we get here, PL_bufptr is at the \
2498 case LEX_INTERPCASEMOD:
2500 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2501 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2503 /* handle \E or end of string */
2504 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2506 if (PL_lex_casemods) {
2507 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
2508 PL_lex_casestack[PL_lex_casemods] = '\0';
2510 if (PL_bufptr != PL_bufend
2511 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
2513 PL_lex_state = LEX_INTERPCONCAT;
2517 if (PL_bufptr != PL_bufend)
2519 PL_lex_state = LEX_INTERPCONCAT;
2523 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2524 "### Saw case modifier\n"); });
2526 if (s[1] == '\\' && s[2] == 'E') {
2528 PL_lex_state = LEX_INTERPCONCAT;
2533 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2534 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
2535 if ((*s == 'L' || *s == 'U') &&
2536 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
2537 PL_lex_casestack[--PL_lex_casemods] = '\0';
2540 if (PL_lex_casemods > 10)
2541 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2542 PL_lex_casestack[PL_lex_casemods++] = *s;
2543 PL_lex_casestack[PL_lex_casemods] = '\0';
2544 PL_lex_state = LEX_INTERPCONCAT;
2545 PL_nextval[PL_nexttoke].ival = 0;
2548 PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2550 PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2552 PL_nextval[PL_nexttoke].ival = OP_LC;
2554 PL_nextval[PL_nexttoke].ival = OP_UC;
2556 PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2558 Perl_croak(aTHX_ "panic: yylex");
2562 if (PL_lex_starts) {
2565 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2566 if (PL_lex_casemods == 1 && PL_lex_inpat)
2575 case LEX_INTERPPUSH:
2576 return REPORT(sublex_push());
2578 case LEX_INTERPSTART:
2579 if (PL_bufptr == PL_bufend)
2580 return REPORT(sublex_done());
2581 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2582 "### Interpolated variable\n"); });
2584 PL_lex_dojoin = (*PL_bufptr == '@');
2585 PL_lex_state = LEX_INTERPNORMAL;
2586 if (PL_lex_dojoin) {
2587 PL_nextval[PL_nexttoke].ival = 0;
2589 force_ident("\"", '$');
2590 PL_nextval[PL_nexttoke].ival = 0;
2592 PL_nextval[PL_nexttoke].ival = 0;
2594 PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
2597 if (PL_lex_starts++) {
2599 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2600 if (!PL_lex_casemods && PL_lex_inpat)
2607 case LEX_INTERPENDMAYBE:
2608 if (intuit_more(PL_bufptr)) {
2609 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
2615 if (PL_lex_dojoin) {
2616 PL_lex_dojoin = FALSE;
2617 PL_lex_state = LEX_INTERPCONCAT;
2620 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2621 && SvEVALED(PL_lex_repl))
2623 if (PL_bufptr != PL_bufend)
2624 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2625 PL_lex_repl = Nullsv;
2628 case LEX_INTERPCONCAT:
2630 if (PL_lex_brackets)
2631 Perl_croak(aTHX_ "panic: INTERPCONCAT");
2633 if (PL_bufptr == PL_bufend)
2634 return REPORT(sublex_done());
2636 if (SvIVX(PL_linestr) == '\'') {
2637 SV *sv = newSVsv(PL_linestr);
2640 else if ( PL_hints & HINT_NEW_RE )
2641 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2642 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2646 s = scan_const(PL_bufptr);
2648 PL_lex_state = LEX_INTERPCASEMOD;
2650 PL_lex_state = LEX_INTERPSTART;
2653 if (s != PL_bufptr) {
2654 PL_nextval[PL_nexttoke] = yylval;
2657 if (PL_lex_starts++) {
2658 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2659 if (!PL_lex_casemods && PL_lex_inpat)
2672 PL_lex_state = LEX_NORMAL;
2673 s = scan_formline(PL_bufptr);
2674 if (!PL_lex_formbrack)
2680 PL_oldoldbufptr = PL_oldbufptr;
2686 if (isIDFIRST_lazy_if(s,UTF))
2688 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2691 goto fake_eof; /* emulate EOF on ^D or ^Z */
2696 if (PL_lex_brackets) {
2697 yyerror(PL_lex_formbrack
2698 ? "Format not terminated"
2699 : "Missing right curly or square bracket");
2701 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2702 "### Tokener got EOF\n");
2706 if (s++ < PL_bufend)
2707 goto retry; /* ignore stray nulls */
2710 if (!PL_in_eval && !PL_preambled) {
2711 PL_preambled = TRUE;
2712 sv_setpv(PL_linestr,incl_perldb());
2713 if (SvCUR(PL_linestr))
2714 sv_catpvs(PL_linestr,";");
2716 while(AvFILLp(PL_preambleav) >= 0) {
2717 SV *tmpsv = av_shift(PL_preambleav);
2718 sv_catsv(PL_linestr, tmpsv);
2719 sv_catpvs(PL_linestr, ";");
2722 sv_free((SV*)PL_preambleav);
2723 PL_preambleav = NULL;
2725 if (PL_minus_n || PL_minus_p) {
2726 sv_catpvs(PL_linestr, "LINE: while (<>) {");
2728 sv_catpvs(PL_linestr,"chomp;");
2731 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
2732 || *PL_splitstr == '"')
2733 && strchr(PL_splitstr + 1, *PL_splitstr))
2734 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
2736 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
2737 bytes can be used as quoting characters. :-) */
2738 const char *splits = PL_splitstr;
2739 sv_catpvs(PL_linestr, "our @F=split(q\0");
2742 if (*splits == '\\')
2743 sv_catpvn(PL_linestr, splits, 1);
2744 sv_catpvn(PL_linestr, splits, 1);
2745 } while (*splits++);
2746 /* This loop will embed the trailing NUL of
2747 PL_linestr as the last thing it does before
2749 sv_catpvs(PL_linestr, ");");
2753 sv_catpvs(PL_linestr,"our @F=split(' ');");
2757 sv_catpvs(PL_linestr,"use feature ':5.10';");
2758 sv_catpvs(PL_linestr, "\n");
2759 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2760 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2761 PL_last_lop = PL_last_uni = Nullch;
2762 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2763 SV * const sv = newSV(0);
2765 sv_upgrade(sv, SVt_PVMG);
2766 sv_setsv(sv,PL_linestr);
2769 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2774 bof = PL_rsfp ? TRUE : FALSE;
2775 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2778 if (PL_preprocess && !PL_in_eval)
2779 (void)PerlProc_pclose(PL_rsfp);
2780 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2781 PerlIO_clearerr(PL_rsfp);
2783 (void)PerlIO_close(PL_rsfp);
2785 PL_doextract = FALSE;
2787 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2788 sv_setpv(PL_linestr,PL_minus_p
2789 ? ";}continue{print;}" : ";}");
2790 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2791 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2792 PL_last_lop = PL_last_uni = Nullch;
2793 PL_minus_n = PL_minus_p = 0;
2796 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2797 PL_last_lop = PL_last_uni = Nullch;
2798 sv_setpvn(PL_linestr,"",0);
2799 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
2801 /* If it looks like the start of a BOM or raw UTF-16,
2802 * check if it in fact is. */
2808 #ifdef PERLIO_IS_STDIO
2809 # ifdef __GNU_LIBRARY__
2810 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
2811 # define FTELL_FOR_PIPE_IS_BROKEN
2815 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
2816 # define FTELL_FOR_PIPE_IS_BROKEN
2821 #ifdef FTELL_FOR_PIPE_IS_BROKEN
2822 /* This loses the possibility to detect the bof
2823 * situation on perl -P when the libc5 is being used.
2824 * Workaround? Maybe attach some extra state to PL_rsfp?
2827 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2829 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
2832 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2833 s = swallow_bom((U8*)s);
2837 /* Incest with pod. */
2838 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2839 sv_setpvn(PL_linestr, "", 0);
2840 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2841 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2842 PL_last_lop = PL_last_uni = Nullch;
2843 PL_doextract = FALSE;
2847 } while (PL_doextract);
2848 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2849 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2850 SV * const sv = newSV(0);
2852 sv_upgrade(sv, SVt_PVMG);
2853 sv_setsv(sv,PL_linestr);
2856 av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2858 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2859 PL_last_lop = PL_last_uni = Nullch;
2860 if (CopLINE(PL_curcop) == 1) {
2861 while (s < PL_bufend && isSPACE(*s))
2863 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2867 if (*s == '#' && *(s+1) == '!')
2869 #ifdef ALTERNATE_SHEBANG
2871 static char const as[] = ALTERNATE_SHEBANG;
2872 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2873 d = s + (sizeof(as) - 1);
2875 #endif /* ALTERNATE_SHEBANG */
2884 while (*d && !isSPACE(*d))
2888 #ifdef ARG_ZERO_IS_SCRIPT
2889 if (ipathend > ipath) {
2891 * HP-UX (at least) sets argv[0] to the script name,
2892 * which makes $^X incorrect. And Digital UNIX and Linux,
2893 * at least, set argv[0] to the basename of the Perl
2894 * interpreter. So, having found "#!", we'll set it right.
2897 = GvSV(gv_fetchpvs("\030", GV_ADD, SVt_PV)); /* $^X */
2898 assert(SvPOK(x) || SvGMAGICAL(x));
2899 if (sv_eq(x, CopFILESV(PL_curcop))) {
2900 sv_setpvn(x, ipath, ipathend - ipath);
2906 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
2907 const char * const lstart = SvPV_const(x,llen);
2909 bstart += blen - llen;
2910 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
2911 sv_setpvn(x, ipath, ipathend - ipath);
2916 TAINT_NOT; /* $^X is always tainted, but that's OK */
2918 #endif /* ARG_ZERO_IS_SCRIPT */
2923 d = instr(s,"perl -");
2925 d = instr(s,"perl");
2927 /* avoid getting into infinite loops when shebang
2928 * line contains "Perl" rather than "perl" */
2930 for (d = ipathend-4; d >= ipath; --d) {
2931 if ((*d == 'p' || *d == 'P')
2932 && !ibcmp(d, "perl", 4))
2942 #ifdef ALTERNATE_SHEBANG
2944 * If the ALTERNATE_SHEBANG on this system starts with a
2945 * character that can be part of a Perl expression, then if
2946 * we see it but not "perl", we're probably looking at the
2947 * start of Perl code, not a request to hand off to some
2948 * other interpreter. Similarly, if "perl" is there, but
2949 * not in the first 'word' of the line, we assume the line
2950 * contains the start of the Perl program.
2952 if (d && *s != '#') {
2953 const char *c = ipath;
2954 while (*c && !strchr("; \t\r\n\f\v#", *c))
2957 d = Nullch; /* "perl" not in first word; ignore */
2959 *s = '#'; /* Don't try to parse shebang line */
2961 #endif /* ALTERNATE_SHEBANG */
2962 #ifndef MACOS_TRADITIONAL
2967 !instr(s,"indir") &&
2968 instr(PL_origargv[0],"perl"))
2975 while (s < PL_bufend && isSPACE(*s))
2977 if (s < PL_bufend) {
2978 Newxz(newargv,PL_origargc+3,char*);
2980 while (s < PL_bufend && !isSPACE(*s))
2983 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2986 newargv = PL_origargv;
2989 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
2991 Perl_croak(aTHX_ "Can't exec %s", ipath);
2995 while (*d && !isSPACE(*d)) d++;
2996 while (SPACE_OR_TAB(*d)) d++;
2999 const bool switches_done = PL_doswitches;
3000 const U32 oldpdb = PL_perldb;
3001 const bool oldn = PL_minus_n;
3002 const bool oldp = PL_minus_p;
3005 if (*d == 'M' || *d == 'm' || *d == 'C') {
3006 const char * const m = d;
3007 while (*d && !isSPACE(*d)) d++;
3008 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3011 d = moreswitches(d);
3013 if (PL_doswitches && !switches_done) {
3014 int argc = PL_origargc;
3015 char **argv = PL_origargv;
3018 } while (argc && argv[0][0] == '-' && argv[0][1]);
3019 init_argv_symbols(argc,argv);
3021 if ((PERLDB_LINE && !oldpdb) ||
3022 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
3023 /* if we have already added "LINE: while (<>) {",
3024 we must not do it again */
3026 sv_setpvn(PL_linestr, "", 0);
3027 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3028 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3029 PL_last_lop = PL_last_uni = Nullch;
3030 PL_preambled = FALSE;
3032 (void)gv_fetchfile(PL_origfilename);
3039 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3041 PL_lex_state = LEX_FORMLINE;
3046 #ifdef PERL_STRICT_CR
3047 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
3049 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3051 case ' ': case '\t': case '\f': case 013:
3052 #ifdef MACOS_TRADITIONAL
3059 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3060 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3061 /* handle eval qq[#line 1 "foo"\n ...] */
3062 CopLINE_dec(PL_curcop);
3066 while (s < d && *s != '\n')
3070 else if (s > d) /* Found by Ilya: feed random input to Perl. */
3071 Perl_croak(aTHX_ "panic: input overflow");
3073 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3075 PL_lex_state = LEX_FORMLINE;
3085 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3093 while (s < PL_bufend && SPACE_OR_TAB(*s))
3096 if (strnEQ(s,"=>",2)) {
3097 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3098 DEBUG_T( { S_printbuf(aTHX_
3099 "### Saw unary minus before =>, forcing word %s\n", s);
3101 OPERATOR('-'); /* unary minus */
3103 PL_last_uni = PL_oldbufptr;
3105 case 'r': ftst = OP_FTEREAD; break;
3106 case 'w': ftst = OP_FTEWRITE; break;
3107 case 'x': ftst = OP_FTEEXEC; break;
3108 case 'o': ftst = OP_FTEOWNED; break;
3109 case 'R': ftst = OP_FTRREAD; break;
3110 case 'W': ftst = OP_FTRWRITE; break;
3111 case 'X': ftst = OP_FTREXEC; break;
3112 case 'O': ftst = OP_FTROWNED; break;
3113 case 'e': ftst = OP_FTIS; break;
3114 case 'z': ftst = OP_FTZERO; break;
3115 case 's': ftst = OP_FTSIZE; break;
3116 case 'f': ftst = OP_FTFILE; break;
3117 case 'd': ftst = OP_FTDIR; break;
3118 case 'l': ftst = OP_FTLINK; break;
3119 case 'p': ftst = OP_FTPIPE; break;
3120 case 'S': ftst = OP_FTSOCK; break;
3121 case 'u': ftst = OP_FTSUID; break;
3122 case 'g': ftst = OP_FTSGID; break;
3123 case 'k': ftst = OP_FTSVTX; break;
3124 case 'b': ftst = OP_FTBLK; break;
3125 case 'c': ftst = OP_FTCHR; break;
3126 case 't': ftst = OP_FTTTY; break;
3127 case 'T': ftst = OP_FTTEXT; break;
3128 case 'B': ftst = OP_FTBINARY; break;
3129 case 'M': case 'A': case 'C':
3130 gv_fetchpvs("\024",GV_ADD, SVt_PV);
3132 case 'M': ftst = OP_FTMTIME; break;
3133 case 'A': ftst = OP_FTATIME; break;
3134 case 'C': ftst = OP_FTCTIME; break;
3142 PL_last_lop_op = (OPCODE)ftst;
3143 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3144 "### Saw file test %c\n", (int)tmp);
3149 /* Assume it was a minus followed by a one-letter named
3150 * subroutine call (or a -bareword), then. */
3151 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3152 "### '-%c' looked like a file test but was not\n",
3159 const char tmp = *s++;
3162 if (PL_expect == XOPERATOR)
3167 else if (*s == '>') {
3170 if (isIDFIRST_lazy_if(s,UTF)) {
3171 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3179 if (PL_expect == XOPERATOR)
3182 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3184 OPERATOR('-'); /* unary minus */
3190 const char tmp = *s++;
3193 if (PL_expect == XOPERATOR)
3198 if (PL_expect == XOPERATOR)
3201 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3208 if (PL_expect != XOPERATOR) {
3209 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3210 PL_expect = XOPERATOR;
3211 force_ident(PL_tokenbuf, '*');
3224 if (PL_expect == XOPERATOR) {
3228 PL_tokenbuf[0] = '%';
3229 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3230 if (!PL_tokenbuf[1]) {
3233 PL_pending_ident = '%';
3244 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR)
3245 && FEATURE_IS_ENABLED("~~"))
3252 const char tmp = *s++;
3258 goto just_a_word_zero_gv;
3261 switch (PL_expect) {
3264 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3266 PL_bufptr = s; /* update in case we back off */
3272 PL_expect = XTERMBLOCK;
3276 while (isIDFIRST_lazy_if(s,UTF)) {
3278 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3279 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
3280 if (tmp < 0) tmp = -tmp;
3296 d = scan_str(d,TRUE,TRUE);
3298 /* MUST advance bufptr here to avoid bogus
3299 "at end of line" context messages from yyerror().
3301 PL_bufptr = s + len;
3302 yyerror("Unterminated attribute parameter in attribute list");
3305 return REPORT(0); /* EOF indicator */
3309 SV *sv = newSVpvn(s, len);
3310 sv_catsv(sv, PL_lex_stuff);
3311 attrs = append_elem(OP_LIST, attrs,
3312 newSVOP(OP_CONST, 0, sv));
3313 SvREFCNT_dec(PL_lex_stuff);
3314 PL_lex_stuff = Nullsv;
3317 if (len == 6 && strnEQ(s, "unique", len)) {
3318 if (PL_in_my == KEY_our)
3320 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
3322 ; /* skip to avoid loading attributes.pm */
3325 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
3328 /* NOTE: any CV attrs applied here need to be part of
3329 the CVf_BUILTIN_ATTRS define in cv.h! */
3330 else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
3331 CvLVALUE_on(PL_compcv);
3332 else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
3333 CvLOCKED_on(PL_compcv);
3334 else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
3335 CvMETHOD_on(PL_compcv);
3336 else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len))
3337 CvASSERTION_on(PL_compcv);
3338 /* After we've set the flags, it could be argued that
3339 we don't need to do the attributes.pm-based setting
3340 process, and shouldn't bother appending recognized
3341 flags. To experiment with that, uncomment the
3342 following "else". (Note that's already been
3343 uncommented. That keeps the above-applied built-in
3344 attributes from being intercepted (and possibly
3345 rejected) by a package's attribute routines, but is
3346 justified by the performance win for the common case
3347 of applying only built-in attributes.) */
3349 attrs = append_elem(OP_LIST, attrs,
3350 newSVOP(OP_CONST, 0,
3354 if (*s == ':' && s[1] != ':')
3357 break; /* require real whitespace or :'s */
3361 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
3362 if (*s != ';' && *s != '}' && *s != tmp
3363 && (tmp != '=' || *s != ')')) {
3364 const char q = ((*s == '\'') ? '"' : '\'');
3365 /* If here for an expression, and parsed no attrs, back
3367 if (tmp == '=' && !attrs) {
3371 /* MUST advance bufptr here to avoid bogus "at end of line"
3372 context messages from yyerror().
3376 ? Perl_form(aTHX_ "Invalid separator character "
3377 "%c%c%c in attribute list", q, *s, q)
3378 : "Unterminated attribute list" );
3386 PL_nextval[PL_nexttoke].opval = attrs;
3394 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
3395 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
3403 const char tmp = *s++;
3408 const char tmp = *s++;
3416 if (PL_lex_brackets <= 0)
3417 yyerror("Unmatched right square bracket");
3420 if (PL_lex_state == LEX_INTERPNORMAL) {
3421 if (PL_lex_brackets == 0) {
3422 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3423 PL_lex_state = LEX_INTERPEND;
3430 if (PL_lex_brackets > 100) {
3431 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
3433 switch (PL_expect) {
3435 if (PL_lex_formbrack) {
3439 if (PL_oldoldbufptr == PL_last_lop)
3440 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3442 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3443 OPERATOR(HASHBRACK);
3445 while (s < PL_bufend && SPACE_OR_TAB(*s))
3448 PL_tokenbuf[0] = '\0';
3449 if (d < PL_bufend && *d == '-') {
3450 PL_tokenbuf[0] = '-';
3452 while (d < PL_bufend && SPACE_OR_TAB(*d))
3455 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3456 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
3458 while (d < PL_bufend && SPACE_OR_TAB(*d))
3461 const char minus = (PL_tokenbuf[0] == '-');
3462 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
3470 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
3475 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3480 if (PL_oldoldbufptr == PL_last_lop)
3481 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3483 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3486 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
3488 /* This hack is to get the ${} in the message. */
3490 yyerror("syntax error");
3493 OPERATOR(HASHBRACK);
3495 /* This hack serves to disambiguate a pair of curlies
3496 * as being a block or an anon hash. Normally, expectation
3497 * determines that, but in cases where we're not in a
3498 * position to expect anything in particular (like inside
3499 * eval"") we have to resolve the ambiguity. This code
3500 * covers the case where the first term in the curlies is a
3501 * quoted string. Most other cases need to be explicitly
3502 * disambiguated by prepending a "+" before the opening
3503 * curly in order to force resolution as an anon hash.
3505 * XXX should probably propagate the outer expectation
3506 * into eval"" to rely less on this hack, but that could
3507 * potentially break current behavior of eval"".
3511 if (*s == '\'' || *s == '"' || *s == '`') {
3512 /* common case: get past first string, handling escapes */
3513 for (t++; t < PL_bufend && *t != *s;)
3514 if (*t++ == '\\' && (*t == '\\' || *t == *s))
3518 else if (*s == 'q') {
3521 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
3524 /* skip q//-like construct */
3526 char open, close, term;
3529 while (t < PL_bufend && isSPACE(*t))
3531 /* check for q => */
3532 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
3533 OPERATOR(HASHBRACK);
3537 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
3541 for (t++; t < PL_bufend; t++) {
3542 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
3544 else if (*t == open)
3548 for (t++; t < PL_bufend; t++) {
3549 if (*t == '\\' && t+1 < PL_bufend)
3551 else if (*t == close && --brackets <= 0)
3553 else if (*t == open)
3560 /* skip plain q word */
3561 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3564 else if (isALNUM_lazy_if(t,UTF)) {
3566 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3569 while (t < PL_bufend && isSPACE(*t))
3571 /* if comma follows first term, call it an anon hash */
3572 /* XXX it could be a comma expression with loop modifiers */
3573 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
3574 || (*t == '=' && t[1] == '>')))
3575 OPERATOR(HASHBRACK);
3576 if (PL_expect == XREF)
3579 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3585 yylval.ival = CopLINE(PL_curcop);
3586 if (isSPACE(*s) || *s == '#')
3587 PL_copline = NOLINE; /* invalidate current command line number */
3592 if (PL_lex_brackets <= 0)
3593 yyerror("Unmatched right curly bracket");
3595 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3596 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3597 PL_lex_formbrack = 0;
3598 if (PL_lex_state == LEX_INTERPNORMAL) {
3599 if (PL_lex_brackets == 0) {
3600 if (PL_expect & XFAKEBRACK) {
3601 PL_expect &= XENUMMASK;
3602 PL_lex_state = LEX_INTERPEND;
3604 return yylex(); /* ignore fake brackets */
3606 if (*s == '-' && s[1] == '>')
3607 PL_lex_state = LEX_INTERPENDMAYBE;
3608 else if (*s != '[' && *s != '{')
3609 PL_lex_state = LEX_INTERPEND;
3612 if (PL_expect & XFAKEBRACK) {
3613 PL_expect &= XENUMMASK;
3615 return yylex(); /* ignore fake brackets */
3624 if (PL_expect == XOPERATOR) {
3625 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
3626 && isIDFIRST_lazy_if(s,UTF))
3628 CopLINE_dec(PL_curcop);
3629 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
3630 CopLINE_inc(PL_curcop);
3635 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3637 PL_expect = XOPERATOR;
3638 force_ident(PL_tokenbuf, '&');
3642 yylval.ival = (OPpENTERSUB_AMPER<<8);
3654 const char tmp = *s++;
3661 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
3662 && strchr("+-*/%.^&|<",tmp))
3663 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3664 "Reversed %c= operator",(int)tmp);
3666 if (PL_expect == XSTATE && isALPHA(tmp) &&
3667 (s == PL_linestart+1 || s[-2] == '\n') )
3669 if (PL_in_eval && !PL_rsfp) {
3674 if (strnEQ(s,"=cut",4)) {
3688 PL_doextract = TRUE;
3692 if (PL_lex_brackets < PL_lex_formbrack) {
3694 #ifdef PERL_STRICT_CR
3695 for (t = s; SPACE_OR_TAB(*t); t++) ;
3697 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3699 if (*t == '\n' || *t == '#') {
3710 const char tmp = *s++;
3712 /* was this !=~ where !~ was meant?
3713 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
3715 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
3716 const char *t = s+1;
3718 while (t < PL_bufend && isSPACE(*t))
3721 if (*t == '/' || *t == '?' ||
3722 ((*t == 'm' || *t == 's' || *t == 'y')
3723 && !isALNUM(t[1])) ||
3724 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
3725 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3726 "!=~ should be !~");
3736 if (PL_expect != XOPERATOR) {
3737 if (s[1] != '<' && !strchr(s,'>'))
3740 s = scan_heredoc(s);
3742 s = scan_inputsymbol(s);
3743 TERM(sublex_start());
3749 SHop(OP_LEFT_SHIFT);
3763 const char tmp = *s++;
3765 SHop(OP_RIGHT_SHIFT);
3775 if (PL_expect == XOPERATOR) {
3776 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3778 deprecate_old(commaless_variable_list);
3779 return REPORT(','); /* grandfather non-comma-format format */
3783 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3784 PL_tokenbuf[0] = '@';
3785 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3786 sizeof PL_tokenbuf - 1, FALSE);
3787 if (PL_expect == XOPERATOR)
3788 no_op("Array length", s);
3789 if (!PL_tokenbuf[1])
3791 PL_expect = XOPERATOR;
3792 PL_pending_ident = '#';
3796 PL_tokenbuf[0] = '$';
3797 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3798 sizeof PL_tokenbuf - 1, FALSE);
3799 if (PL_expect == XOPERATOR)
3801 if (!PL_tokenbuf[1]) {
3803 yyerror("Final $ should be \\$ or $name");
3807 /* This kludge not intended to be bulletproof. */
3808 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3809 yylval.opval = newSVOP(OP_CONST, 0,
3810 newSViv(PL_compiling.cop_arybase));
3811 yylval.opval->op_private = OPpCONST_ARYBASE;
3817 const char tmp = *s;
3818 if (PL_lex_state == LEX_NORMAL)
3821 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
3822 && intuit_more(s)) {
3824 PL_tokenbuf[0] = '@';
3825 if (ckWARN(WARN_SYNTAX)) {
3828 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3831 PL_bufptr = skipspace(PL_bufptr);
3832 while (t < PL_bufend && *t != ']')
3834 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3835 "Multidimensional syntax %.*s not supported",
3836 (int)((t - PL_bufptr) + 1), PL_bufptr);
3840 else if (*s == '{') {
3842 PL_tokenbuf[0] = '%';
3843 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
3844 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
3846 char tmpbuf[sizeof PL_tokenbuf];
3847 for (t++; isSPACE(*t); t++) ;
3848 if (isIDFIRST_lazy_if(t,UTF)) {
3850 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
3852 for (; isSPACE(*t); t++) ;
3853 if (*t == ';' && get_cv(tmpbuf, FALSE))
3854 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3855 "You need to quote \"%s\"",
3862 PL_expect = XOPERATOR;
3863 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3864 const bool islop = (PL_last_lop == PL_oldoldbufptr);
3865 if (!islop || PL_last_lop_op == OP_GREPSTART)
3866 PL_expect = XOPERATOR;
3867 else if (strchr("$@\"'`q", *s))
3868 PL_expect = XTERM; /* e.g. print $fh "foo" */
3869 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3870 PL_expect = XTERM; /* e.g. print $fh &sub */
3871 else if (isIDFIRST_lazy_if(s,UTF)) {
3872 char tmpbuf[sizeof PL_tokenbuf];
3874 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3875 if ((t2 = keyword(tmpbuf, len))) {
3876 /* binary operators exclude handle interpretations */
3888 PL_expect = XTERM; /* e.g. print $fh length() */
3893 PL_expect = XTERM; /* e.g. print $fh subr() */
3896 else if (isDIGIT(*s))
3897 PL_expect = XTERM; /* e.g. print $fh 3 */
3898 else if (*s == '.' && isDIGIT(s[1]))
3899 PL_expect = XTERM; /* e.g. print $fh .3 */
3900 else if ((*s == '?' || *s == '-' || *s == '+')
3901 && !isSPACE(s[1]) && s[1] != '=')
3902 PL_expect = XTERM; /* e.g. print $fh -1 */
3903 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
3905 PL_expect = XTERM; /* e.g. print $fh /.../
3906 XXX except DORDOR operator
3908 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
3910 PL_expect = XTERM; /* print $fh <<"EOF" */
3913 PL_pending_ident = '$';
3917 if (PL_expect == XOPERATOR)
3919 PL_tokenbuf[0] = '@';
3920 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3921 if (!PL_tokenbuf[1]) {
3924 if (PL_lex_state == LEX_NORMAL)
3926 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3928 PL_tokenbuf[0] = '%';
3930 /* Warn about @ where they meant $. */
3931 if (*s == '[' || *s == '{') {
3932 if (ckWARN(WARN_SYNTAX)) {
3933 const char *t = s + 1;
3934 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3936 if (*t == '}' || *t == ']') {
3938 PL_bufptr = skipspace(PL_bufptr);
3939 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3940 "Scalar value %.*s better written as $%.*s",
3941 (int)(t-PL_bufptr), PL_bufptr,
3942 (int)(t-PL_bufptr-1), PL_bufptr+1);
3947 PL_pending_ident = '@';
3950 case '/': /* may be division, defined-or, or pattern */
3951 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
3955 case '?': /* may either be conditional or pattern */
3956 if(PL_expect == XOPERATOR) {
3964 /* A // operator. */
3974 /* Disable warning on "study /blah/" */
3975 if (PL_oldoldbufptr == PL_last_uni
3976 && (*PL_last_uni != 's' || s - PL_last_uni < 5
3977 || memNE(PL_last_uni, "study", 5)
3978 || isALNUM_lazy_if(PL_last_uni+5,UTF)
3981 s = scan_pat(s,OP_MATCH);
3982 TERM(sublex_start());
3986 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3987 #ifdef PERL_STRICT_CR
3990 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3992 && (s == PL_linestart || s[-1] == '\n') )
3994 PL_lex_formbrack = 0;
3998 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4004 yylval.ival = OPf_SPECIAL;
4010 if (PL_expect != XOPERATOR)
4015 case '0': case '1': case '2': case '3': case '4':
4016 case '5': case '6': case '7': case '8': case '9':
4017 s = scan_num(s, &yylval);
4018 DEBUG_T( { S_printbuf(aTHX_ "### Saw number in %s\n", s); } );
4019 if (PL_expect == XOPERATOR)
4024 s = scan_str(s,FALSE,FALSE);
4025 DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } );
4026 if (PL_expect == XOPERATOR) {
4027 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4029 deprecate_old(commaless_variable_list);
4030 return REPORT(','); /* grandfather non-comma-format format */
4036 missingterm((char*)0);
4037 yylval.ival = OP_CONST;
4038 TERM(sublex_start());
4041 s = scan_str(s,FALSE,FALSE);
4042 DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } );
4043 if (PL_expect == XOPERATOR) {
4044 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4046 deprecate_old(commaless_variable_list);
4047 return REPORT(','); /* grandfather non-comma-format format */
4053 missingterm((char*)0);
4054 yylval.ival = OP_CONST;
4055 /* FIXME. I think that this can be const if char *d is replaced by
4056 more localised variables. */
4057 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4058 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4059 yylval.ival = OP_STRINGIFY;
4063 TERM(sublex_start());
4066 s = scan_str(s,FALSE,FALSE);
4067 DEBUG_T( { S_printbuf(aTHX_ "### Saw backtick string before %s\n", s); } );
4068 if (PL_expect == XOPERATOR)
4069 no_op("Backticks",s);
4071 missingterm((char*)0);
4072 yylval.ival = OP_BACKTICK;
4074 TERM(sublex_start());
4078 if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
4079 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
4081 if (PL_expect == XOPERATOR)
4082 no_op("Backslash",s);
4086 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
4087 char *start = s + 2;
4088 while (isDIGIT(*start) || *start == '_')
4090 if (*start == '.' && isDIGIT(start[1])) {
4091 s = scan_num(s, &yylval);
4094 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
4095 else if (!isALPHA(*start) && (PL_expect == XTERM
4096 || PL_expect == XREF || PL_expect == XSTATE
4097 || PL_expect == XTERMORDORDOR)) {
4098 const char c = *start;
4101 gv = gv_fetchpv(s, 0, SVt_PVCV);
4104 s = scan_num(s, &yylval);
4111 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
4147 I32 orig_keyword = 0;
4152 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4154 /* Some keywords can be followed by any delimiter, including ':' */
4155 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
4156 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
4157 (PL_tokenbuf[0] == 'q' &&
4158 strchr("qwxr", PL_tokenbuf[1])))));
4160 /* x::* is just a word, unless x is "CORE" */
4161 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4165 while (d < PL_bufend && isSPACE(*d))
4166 d++; /* no comments skipped here, or s### is misparsed */
4168 /* Is this a label? */
4169 if (!tmp && PL_expect == XSTATE
4170 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4172 yylval.pval = savepv(PL_tokenbuf);
4177 /* Check for keywords */
4178 tmp = keyword(PL_tokenbuf, len);
4180 /* Is this a word before a => operator? */
4181 if (*d == '=' && d[1] == '>') {
4184 = (OP*)newSVOP(OP_CONST, 0,
4185 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
4186 yylval.opval->op_private = OPpCONST_BARE;
4190 if (tmp < 0) { /* second-class keyword? */
4191 GV *ogv = NULL; /* override (winner) */
4192 GV *hgv = NULL; /* hidden (loser) */
4193 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4195 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
4198 if (GvIMPORTED_CV(gv))
4200 else if (! CvMETHOD(cv))
4204 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4205 (gv = *gvp) != (GV*)&PL_sv_undef &&
4206 GvCVu(gv) && GvIMPORTED_CV(gv))
4213 tmp = 0; /* overridden by import or by GLOBAL */
4216 && -tmp==KEY_lock /* XXX generalizable kludge */
4218 && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
4220 tmp = 0; /* any sub overrides "weak" keyword */
4222 else { /* no override */
4224 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
4225 Perl_warner(aTHX_ packWARN(WARN_MISC),
4226 "dump() better written as CORE::dump()");
4230 if (hgv && tmp != KEY_x && tmp != KEY_CORE
4231 && ckWARN(WARN_AMBIGUOUS)) /* never ambiguous */
4232 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4233 "Ambiguous call resolved as CORE::%s(), %s",
4234 GvENAME(hgv), "qualify as such or use &");
4241 default: /* not a keyword */
4242 /* Trade off - by using this evil construction we can pull the
4243 variable gv into the block labelled keylookup. If not, then
4244 we have to give it function scope so that the goto from the
4245 earlier ':' case doesn't bypass the initialisation. */
4247 just_a_word_zero_gv:
4255 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
4258 /* Get the rest if it looks like a package qualifier */
4260 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
4262 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
4265 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
4266 *s == '\'' ? "'" : "::");
4271 if (PL_expect == XOPERATOR) {
4272 if (PL_bufptr == PL_linestart) {
4273 CopLINE_dec(PL_curcop);
4274 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4275 CopLINE_inc(PL_curcop);
4278 no_op("Bareword",s);
4281 /* Look for a subroutine with this name in current package,
4282 unless name is "Foo::", in which case Foo is a bearword
4283 (and a package name). */
4286 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
4288 if (ckWARN(WARN_BAREWORD)
4289 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
4290 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
4291 "Bareword \"%s\" refers to nonexistent package",
4294 PL_tokenbuf[len] = '\0';
4301 /* Mustn't actually add anything to a symbol table.
4302 But also don't want to "initialise" any placeholder
4303 constants that might already be there into full
4304 blown PVGVs with attached PVCV. */
4305 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
4306 GV_NOADD_NOINIT, SVt_PVCV);
4310 /* if we saw a global override before, get the right name */
4313 sv = newSVpvs("CORE::GLOBAL::");
4314 sv_catpv(sv,PL_tokenbuf);
4317 /* If len is 0, newSVpv does strlen(), which is correct.
4318 If len is non-zero, then it will be the true length,
4319 and so the scalar will be created correctly. */
4320 sv = newSVpv(PL_tokenbuf,len);
4323 /* Presume this is going to be a bareword of some sort. */
4326 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4327 yylval.opval->op_private = OPpCONST_BARE;
4328 /* UTF-8 package name? */
4329 if (UTF && !IN_BYTES &&
4330 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
4333 /* And if "Foo::", then that's what it certainly is. */
4338 /* Do the explicit type check so that we don't need to force
4339 the initialisation of the symbol table to have a real GV.
4340 Beware - gv may not really be a PVGV, cv may not really be
4341 a PVCV, (because of the space optimisations that gv_init
4342 understands) But they're true if for this symbol there is
4343 respectively a typeglob and a subroutine.
4345 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
4346 /* Real typeglob, so get the real subroutine: */
4348 /* A proxy for a subroutine in this package? */
4349 : SvOK(gv) ? (CV *) gv : NULL)
4352 /* See if it's the indirect object for a list operator. */
4354 if (PL_oldoldbufptr &&
4355 PL_oldoldbufptr < PL_bufptr &&
4356 (PL_oldoldbufptr == PL_last_lop
4357 || PL_oldoldbufptr == PL_last_uni) &&
4358 /* NO SKIPSPACE BEFORE HERE! */
4359 (PL_expect == XREF ||
4360 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
4362 bool immediate_paren = *s == '(';
4364 /* (Now we can afford to cross potential line boundary.) */
4367 /* Two barewords in a row may indicate method call. */
4369 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
4370 (tmp = intuit_method(s, gv, cv)))
4373 /* If not a declared subroutine, it's an indirect object. */
4374 /* (But it's an indir obj regardless for sort.) */
4375 /* Also, if "_" follows a filetest operator, it's a bareword */
4378 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
4380 (PL_last_lop_op != OP_MAPSTART &&
4381 PL_last_lop_op != OP_GREPSTART))))
4382 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
4383 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
4386 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
4391 PL_expect = XOPERATOR;
4394 /* Is this a word before a => operator? */
4395 if (*s == '=' && s[1] == '>' && !pkgname) {
4397 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
4398 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
4399 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
4403 /* If followed by a paren, it's certainly a subroutine. */
4407 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
4408 if (*d == ')' && (sv = gv_const_sv(gv))) {
4413 PL_nextval[PL_nexttoke].opval = yylval.opval;
4414 PL_expect = XOPERATOR;
4420 /* If followed by var or block, call it a method (unless sub) */
4422 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
4423 PL_last_lop = PL_oldbufptr;
4424 PL_last_lop_op = OP_METHOD;
4428 /* If followed by a bareword, see if it looks like indir obj. */
4431 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
4432 && (tmp = intuit_method(s, gv, cv)))
4435 /* Not a method, so call it a subroutine (if defined) */
4438 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
4439 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4440 "Ambiguous use of -%s resolved as -&%s()",
4441 PL_tokenbuf, PL_tokenbuf);
4442 /* Check for a constant sub */
4443 if ((sv = gv_const_sv(gv))) {
4445 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
4446 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
4447 yylval.opval->op_private = 0;
4451 /* Resolve to GV now. */
4452 if (SvTYPE(gv) != SVt_PVGV) {
4453 gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV);
4454 assert (SvTYPE(gv) == SVt_PVGV);
4455 /* cv must have been some sort of placeholder, so
4456 now needs replacing with a real code reference. */
4460 op_free(yylval.opval);
4461 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4462 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
4463 PL_last_lop = PL_oldbufptr;
4464 PL_last_lop_op = OP_ENTERSUB;
4465 /* Is there a prototype? */
4468 const char *proto = SvPV_const((SV*)cv, len);
4471 if (*proto == '$' && proto[1] == '\0')
4473 while (*proto == ';')
4475 if (*proto == '&' && *s == '{') {
4476 sv_setpv(PL_subname, PL_curstash ?
4477 "__ANON__" : "__ANON__::__ANON__");
4481 PL_nextval[PL_nexttoke].opval = yylval.opval;
4487 /* Call it a bare word */
4489 if (PL_hints & HINT_STRICT_SUBS)
4490 yylval.opval->op_private |= OPpCONST_STRICT;
4493 if (lastchar != '-') {
4494 if (ckWARN(WARN_RESERVED)) {
4495 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
4496 if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
4497 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
4504 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
4505 && ckWARN_d(WARN_AMBIGUOUS)) {
4506 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4507 "Operator or semicolon missing before %c%s",
4508 lastchar, PL_tokenbuf);
4509 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4510 "Ambiguous use of %c resolved as operator %c",
4511 lastchar, lastchar);
4517 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4518 newSVpv(CopFILE(PL_curcop),0));
4522 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4523 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
4526 case KEY___PACKAGE__:
4527 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4529 ? newSVhek(HvNAME_HEK(PL_curstash))
4536 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
4537 const char *pname = "main";
4538 if (PL_tokenbuf[2] == 'D')
4539 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
4540 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
4544 GvIOp(gv) = newIO();
4545 IoIFP(GvIOp(gv)) = PL_rsfp;
4546 #if defined(HAS_FCNTL) && defined(F_SETFD)
4548 const int fd = PerlIO_fileno(PL_rsfp);
4549 fcntl(fd,F_SETFD,fd >= 3);
4552 /* Mark this internal pseudo-handle as clean */
4553 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4555 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
4556 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
4557 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
4559 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
4560 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
4561 /* if the script was opened in binmode, we need to revert
4562 * it to text mode for compatibility; but only iff it has CRs
4563 * XXX this is a questionable hack at best. */
4564 if (PL_bufend-PL_bufptr > 2
4565 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
4568 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
4569 loc = PerlIO_tell(PL_rsfp);
4570 (void)PerlIO_seek(PL_rsfp, 0L, 0);
4573 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
4575 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
4576 #endif /* NETWARE */
4577 #ifdef PERLIO_IS_STDIO /* really? */
4578 # if defined(__BORLANDC__)
4579 /* XXX see note in do_binmode() */
4580 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
4584 PerlIO_seek(PL_rsfp, loc, 0);
4588 #ifdef PERLIO_LAYERS
4591 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
4592 else if (PL_encoding) {
4599 XPUSHs(PL_encoding);
4601 call_method("name", G_SCALAR);
4605 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
4606 Perl_form(aTHX_ ":encoding(%"SVf")",
4624 if (PL_expect == XSTATE) {
4631 if (*s == ':' && s[1] == ':') {
4634 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4635 if (!(tmp = keyword(PL_tokenbuf, len)))
4636 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
4639 else if (tmp == KEY_require || tmp == KEY_do)
4640 /* that's a way to remember we saw "CORE::" */
4653 LOP(OP_ACCEPT,XTERM);
4659 LOP(OP_ATAN2,XTERM);
4665 LOP(OP_BINMODE,XTERM);
4668 LOP(OP_BLESS,XTERM);
4677 /* When 'use switch' is in effect, continue has a dual
4678 life as a control operator. */
4680 if (!FEATURE_IS_ENABLED("switch"))
4683 /* We have to disambiguate the two senses of
4684 "continue". If the next token is a '{' then
4685 treat it as the start of a continue block;
4686 otherwise treat it as a control operator.
4697 (void)gv_fetchpvs("ENV", GV_ADD, SVt_PVHV); /* may use HOME */
4714 if (!PL_cryptseen) {
4715 PL_cryptseen = TRUE;
4719 LOP(OP_CRYPT,XTERM);
4722 LOP(OP_CHMOD,XTERM);
4725 LOP(OP_CHOWN,XTERM);
4728 LOP(OP_CONNECT,XTERM);
4747 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4748 if (orig_keyword == KEY_do) {
4757 PL_hints |= HINT_BLOCK_SCOPE;
4767 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
4768 LOP(OP_DBMOPEN,XTERM);
4774 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4781 yylval.ival = CopLINE(PL_curcop);
4795 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4796 UNIBRACK(OP_ENTEREVAL);
4814 case KEY_endhostent:
4820 case KEY_endservent:
4823 case KEY_endprotoent:
4834 yylval.ival = CopLINE(PL_curcop);
4836 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4838 if ((PL_bufend - p) >= 3 &&
4839 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4841 else if ((PL_bufend - p) >= 4 &&
4842 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4845 if (isIDFIRST_lazy_if(p,UTF)) {
4846 p = scan_ident(p, PL_bufend,
4847 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4851 Perl_croak(aTHX_ "Missing $ on loop variable");
4856 LOP(OP_FORMLINE,XTERM);
4862 LOP(OP_FCNTL,XTERM);
4868 LOP(OP_FLOCK,XTERM);
4877 LOP(OP_GREPSTART, XREF);
4880 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4895 case KEY_getpriority:
4896 LOP(OP_GETPRIORITY,XTERM);
4898 case KEY_getprotobyname:
4901 case KEY_getprotobynumber:
4902 LOP(OP_GPBYNUMBER,XTERM);
4904 case KEY_getprotoent:
4916 case KEY_getpeername:
4917 UNI(OP_GETPEERNAME);
4919 case KEY_gethostbyname:
4922 case KEY_gethostbyaddr:
4923 LOP(OP_GHBYADDR,XTERM);
4925 case KEY_gethostent:
4928 case KEY_getnetbyname:
4931 case KEY_getnetbyaddr:
4932 LOP(OP_GNBYADDR,XTERM);
4937 case KEY_getservbyname:
4938 LOP(OP_GSBYNAME,XTERM);
4940 case KEY_getservbyport:
4941 LOP(OP_GSBYPORT,XTERM);
4943 case KEY_getservent:
4946 case KEY_getsockname:
4947 UNI(OP_GETSOCKNAME);
4949 case KEY_getsockopt:
4950 LOP(OP_GSOCKOPT,XTERM);
4965 yylval.ival = CopLINE(PL_curcop);
4976 yylval.ival = CopLINE(PL_curcop);
4980 LOP(OP_INDEX,XTERM);
4986 LOP(OP_IOCTL,XTERM);
4998 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5030 LOP(OP_LISTEN,XTERM);
5039 s = scan_pat(s,OP_MATCH);
5040 TERM(sublex_start());
5043 LOP(OP_MAPSTART, XREF);
5046 LOP(OP_MKDIR,XTERM);
5049 LOP(OP_MSGCTL,XTERM);
5052 LOP(OP_MSGGET,XTERM);
5055 LOP(OP_MSGRCV,XTERM);
5058 LOP(OP_MSGSND,XTERM);
5064 if (isIDFIRST_lazy_if(s,UTF)) {
5065 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
5066 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
5068 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
5069 if (!PL_in_my_stash) {
5072 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
5080 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5087 s = tokenize_use(0, s);
5091 if (*s == '(' || (s = skipspace(s), *s == '('))
5098 if (isIDFIRST_lazy_if(s,UTF)) {
5100 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
5101 for (t=d; *t && isSPACE(*t); t++) ;
5102 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
5104 && !(t[0] == '=' && t[1] == '>')
5106 int len = (int)(d-s);
5107 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
5108 "Precedence problem: open %.*s should be open(%.*s)",
5115 yylval.ival = OP_OR;
5125 LOP(OP_OPEN_DIR,XTERM);
5128 checkcomma(s,PL_tokenbuf,"filehandle");
5132 checkcomma(s,PL_tokenbuf,"filehandle");
5151 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5155 LOP(OP_PIPE_OP,XTERM);
5158 s = scan_str(s,FALSE,FALSE);
5160 missingterm((char*)0);
5161 yylval.ival = OP_CONST;
5162 TERM(sublex_start());
5168 s = scan_str(s,FALSE,FALSE);
5170 missingterm((char*)0);
5171 PL_expect = XOPERATOR;
5173 if (SvCUR(PL_lex_stuff)) {
5176 d = SvPV_force(PL_lex_stuff, len);
5179 for (; isSPACE(*d) && len; --len, ++d) ;
5182 if (!warned && ckWARN(WARN_QW)) {
5183 for (; !isSPACE(*d) && len; --len, ++d) {
5185 Perl_warner(aTHX_ packWARN(WARN_QW),
5186 "Possible attempt to separate words with commas");
5189 else if (*d == '#') {
5190 Perl_warner(aTHX_ packWARN(WARN_QW),
5191 "Possible attempt to put comments in qw() list");
5197 for (; !isSPACE(*d) && len; --len, ++d) ;
5199 sv = newSVpvn(b, d-b);
5200 if (DO_UTF8(PL_lex_stuff))
5202 words = append_elem(OP_LIST, words,
5203 newSVOP(OP_CONST, 0, tokeq(sv)));
5207 PL_nextval[PL_nexttoke].opval = words;
5212 SvREFCNT_dec(PL_lex_stuff);
5213 PL_lex_stuff = Nullsv;
5219 s = scan_str(s,FALSE,FALSE);
5221 missingterm((char*)0);
5222 yylval.ival = OP_STRINGIFY;
5223 if (SvIVX(PL_lex_stuff) == '\'')
5224 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
5225 TERM(sublex_start());
5228 s = scan_pat(s,OP_QR);
5229 TERM(sublex_start());
5232 s = scan_str(s,FALSE,FALSE);
5234 missingterm((char*)0);
5235 yylval.ival = OP_BACKTICK;
5237 TERM(sublex_start());
5245 s = force_version(s, FALSE);
5247 else if (*s != 'v' || !isDIGIT(s[1])
5248 || (s = force_version(s, TRUE), *s == 'v'))
5250 *PL_tokenbuf = '\0';
5251 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5252 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
5253 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
5255 yyerror("<> should be quotes");
5257 if (orig_keyword == KEY_require) {
5265 PL_last_uni = PL_oldbufptr;
5266 PL_last_lop_op = OP_REQUIRE;
5268 return REPORT( (int)REQUIRE );
5274 s = force_word(s,WORD,TRUE,FALSE,FALSE);
5278 LOP(OP_RENAME,XTERM);
5287 LOP(OP_RINDEX,XTERM);
5297 UNIDOR(OP_READLINE);
5310 LOP(OP_REVERSE,XTERM);
5313 UNIDOR(OP_READLINK);
5321 TERM(sublex_start());
5323 TOKEN(1); /* force error */
5326 checkcomma(s,PL_tokenbuf,"filehandle");
5336 LOP(OP_SELECT,XTERM);
5342 LOP(OP_SEMCTL,XTERM);
5345 LOP(OP_SEMGET,XTERM);
5348 LOP(OP_SEMOP,XTERM);
5354 LOP(OP_SETPGRP,XTERM);
5356 case KEY_setpriority:
5357 LOP(OP_SETPRIORITY,XTERM);
5359 case KEY_sethostent:
5365 case KEY_setservent:
5368 case KEY_setprotoent:
5378 LOP(OP_SEEKDIR,XTERM);
5380 case KEY_setsockopt:
5381 LOP(OP_SSOCKOPT,XTERM);
5387 LOP(OP_SHMCTL,XTERM);
5390 LOP(OP_SHMGET,XTERM);
5393 LOP(OP_SHMREAD,XTERM);
5396 LOP(OP_SHMWRITE,XTERM);
5399 LOP(OP_SHUTDOWN,XTERM);
5408 LOP(OP_SOCKET,XTERM);
5410 case KEY_socketpair:
5411 LOP(OP_SOCKPAIR,XTERM);
5414 checkcomma(s,PL_tokenbuf,"subroutine name");
5416 if (*s == ';' || *s == ')') /* probably a close */
5417 Perl_croak(aTHX_ "sort is now a reserved word");
5419 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5423 LOP(OP_SPLIT,XTERM);
5426 LOP(OP_SPRINTF,XTERM);
5429 LOP(OP_SPLICE,XTERM);
5444 LOP(OP_SUBSTR,XTERM);
5450 char tmpbuf[sizeof PL_tokenbuf];
5451 SSize_t tboffset = 0;
5452 expectation attrful;
5453 bool have_name, have_proto, bad_proto;
5454 const int key = tmp;
5458 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
5459 (*s == ':' && s[1] == ':'))
5462 attrful = XATTRBLOCK;
5463 /* remember buffer pos'n for later force_word */
5464 tboffset = s - PL_oldbufptr;
5465 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5466 if (strchr(tmpbuf, ':'))
5467 sv_setpv(PL_subname, tmpbuf);
5469 sv_setsv(PL_subname,PL_curstname);
5470 sv_catpvs(PL_subname,"::");
5471 sv_catpvn(PL_subname,tmpbuf,len);
5478 Perl_croak(aTHX_ "Missing name in \"my sub\"");
5479 PL_expect = XTERMBLOCK;
5480 attrful = XATTRTERM;
5481 sv_setpvn(PL_subname,"?",1);
5485 if (key == KEY_format) {
5487 PL_lex_formbrack = PL_lex_brackets + 1;
5489 (void) force_word(PL_oldbufptr + tboffset, WORD,
5494 /* Look for a prototype */
5498 s = scan_str(s,FALSE,FALSE);
5500 Perl_croak(aTHX_ "Prototype not terminated");
5501 /* strip spaces and check for bad characters */
5502 d = SvPVX(PL_lex_stuff);
5505 for (p = d; *p; ++p) {
5508 if (!strchr("$@%*;[]&\\", *p))
5513 if (bad_proto && ckWARN(WARN_SYNTAX))
5514 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5515 "Illegal character in prototype for %"SVf" : %s",
5517 SvCUR_set(PL_lex_stuff, tmp);
5525 if (*s == ':' && s[1] != ':')
5526 PL_expect = attrful;
5527 else if (*s != '{' && key == KEY_sub) {
5529 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
5531 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname);
5535 PL_nextval[PL_nexttoke].opval =
5536 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
5537 PL_lex_stuff = Nullsv;
5541 sv_setpv(PL_subname,
5542 PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
5545 (void) force_word(PL_oldbufptr + tboffset, WORD,
5554 LOP(OP_SYSTEM,XREF);
5557 LOP(OP_SYMLINK,XTERM);
5560 LOP(OP_SYSCALL,XTERM);
5563 LOP(OP_SYSOPEN,XTERM);
5566 LOP(OP_SYSSEEK,XTERM);
5569 LOP(OP_SYSREAD,XTERM);
5572 LOP(OP_SYSWRITE,XTERM);
5576 TERM(sublex_start());
5597 LOP(OP_TRUNCATE,XTERM);
5609 yylval.ival = CopLINE(PL_curcop);
5613 yylval.ival = CopLINE(PL_curcop);
5617 LOP(OP_UNLINK,XTERM);
5623 LOP(OP_UNPACK,XTERM);
5626 LOP(OP_UTIME,XTERM);
5632 LOP(OP_UNSHIFT,XTERM);
5635 s = tokenize_use(1, s);
5645 yylval.ival = CopLINE(PL_curcop);
5649 yylval.ival = CopLINE(PL_curcop);
5653 PL_hints |= HINT_BLOCK_SCOPE;
5660 LOP(OP_WAITPID,XTERM);
5669 ctl_l[0] = toCTRL('L');
5671 gv_fetchpvn_flags(ctl_l, 1, GV_ADD, SVt_PV);
5674 gv_fetchpvs("\f", GV_ADD, SVt_PV); /* Make sure $^L is defined */
5679 if (PL_expect == XOPERATOR)
5685 yylval.ival = OP_XOR;
5690 TERM(sublex_start());
5695 #pragma segment Main
5699 S_pending_ident(pTHX)
5703 register I32 tmp = 0;
5704 /* pit holds the identifier we read and pending_ident is reset */
5705 char pit = PL_pending_ident;
5706 PL_pending_ident = 0;
5708 DEBUG_T({ PerlIO_printf(Perl_debug_log,
5709 "### Pending identifier '%s'\n", PL_tokenbuf); });
5711 /* if we're in a my(), we can't allow dynamics here.
5712 $foo'bar has already been turned into $foo::bar, so
5713 just check for colons.
5715 if it's a legal name, the OP is a PADANY.
5718 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
5719 if (strchr(PL_tokenbuf,':'))
5720 yyerror(Perl_form(aTHX_ "No package name allowed for "
5721 "variable %s in \"our\"",
5723 tmp = allocmy(PL_tokenbuf);
5726 if (strchr(PL_tokenbuf,':'))
5727 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
5729 yylval.opval = newOP(OP_PADANY, 0);
5730 yylval.opval->op_targ = allocmy(PL_tokenbuf);
5736 build the ops for accesses to a my() variable.
5738 Deny my($a) or my($b) in a sort block, *if* $a or $b is
5739 then used in a comparison. This catches most, but not
5740 all cases. For instance, it catches
5741 sort { my($a); $a <=> $b }
5743 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
5744 (although why you'd do that is anyone's guess).
5747 if (!strchr(PL_tokenbuf,':')) {
5749 tmp = pad_findmy(PL_tokenbuf);
5750 if (tmp != NOT_IN_PAD) {
5751 /* might be an "our" variable" */
5752 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
5753 /* build ops for a bareword */
5754 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
5755 HEK * const stashname = HvNAME_HEK(stash);
5756 SV * const sym = newSVhek(stashname);
5757 sv_catpvs(sym, "::");
5758 sv_catpv(sym, PL_tokenbuf+1);
5759 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
5760 yylval.opval->op_private = OPpCONST_ENTERED;
5763 ? (GV_ADDMULTI | GV_ADDINEVAL)
5766 ((PL_tokenbuf[0] == '$') ? SVt_PV
5767 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5772 /* if it's a sort block and they're naming $a or $b */
5773 if (PL_last_lop_op == OP_SORT &&
5774 PL_tokenbuf[0] == '$' &&
5775 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
5778 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
5779 d < PL_bufend && *d != '\n';
5782 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
5783 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
5789 yylval.opval = newOP(OP_PADANY, 0);
5790 yylval.opval->op_targ = tmp;
5796 Whine if they've said @foo in a doublequoted string,
5797 and @foo isn't a variable we can find in the symbol
5800 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
5801 GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
5802 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
5803 && ckWARN(WARN_AMBIGUOUS))
5805 /* Downgraded from fatal to warning 20000522 mjd */
5806 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5807 "Possible unintended interpolation of %s in string",
5812 /* build ops for a bareword */
5813 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
5814 yylval.opval->op_private = OPpCONST_ENTERED;
5817 /* If the identifier refers to a stash, don't autovivify it.
5818 * Change 24660 had the side effect of causing symbol table
5819 * hashes to always be defined, even if they were freshly
5820 * created and the only reference in the entire program was
5821 * the single statement with the defined %foo::bar:: test.
5822 * It appears that all code in the wild doing this actually
5823 * wants to know whether sub-packages have been loaded, so
5824 * by avoiding auto-vivifying symbol tables, we ensure that
5825 * defined %foo::bar:: continues to be false, and the existing
5826 * tests still give the expected answers, even though what
5827 * they're actually testing has now changed subtly.
5829 (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
5831 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
5832 ((PL_tokenbuf[0] == '$') ? SVt_PV
5833 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5839 * The following code was generated by perl_keyword.pl.
5843 Perl_keyword (pTHX_ const char *name, I32 len)
5848 case 1: /* 5 tokens of length 1 */
5880 case 2: /* 18 tokens of length 2 */
6026 case 3: /* 29 tokens of length 3 */
6030 if (name[1] == 'N' &&
6093 if (name[1] == 'i' &&
6115 return (FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
6133 if (name[1] == 'o' &&
6142 if (name[1] == 'e' &&
6151 if (name[1] == 'n' &&
6160 if (name[1] == 'o' &&
6169 if (name[1] == 'a' &&
6178 if (name[1] == 'o' &&
6240 if (name[1] == 'e' &&
6254 return (FEATURE_IS_ENABLED("say") ? -KEY_say : 0);
6280 if (name[1] == 'i' &&
6289 if (name[1] == 's' &&
6298 if (name[1] == 'e' &&
6307 if (name[1] == 'o' &&
6319 case 4: /* 41 tokens of length 4 */
6323 if (name[1] == 'O' &&
6333 if (name[1] == 'N' &&
6343 if (name[1] == 'i' &&
6353 if (name[1] == 'h' &&
6363 if (name[1] == 'u' &&
6376 if (name[2] == 'c' &&
6385 if (name[2] == 's' &&
6394 if (name[2] == 'a' &&
6430 if (name[1] == 'o' &&
6443 if (name[2] == 't' &&
6452 if (name[2] == 'o' &&
6461 if (name[2] == 't' &&
6470 if (name[2] == 'e' &&
6483 if (name[1] == 'o' &&
6496 if (name[2] == 'y' &&
6505 if (name[2] == 'l' &&
6521 if (name[2] == 's' &&
6530 if (name[2] == 'n' &&
6539 if (name[2] == 'c' &&
6552 if (name[1] == 'e' &&
6562 if (name[1] == 'p' &&
6575 if (name[2] == 'c' &&
6584 if (name[2] == 'p' &&
6593 if (name[2] == 's' &&
6609 if (name[2] == 'n' &&
6679 if (name[2] == 'r' &&
6688 if (name[2] == 'r' &&
6697 if (name[2] == 'a' &&
6713 if (name[2] == 'l' &&
6775 if (name[2] == 'e' &&
6778 return (FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
6791 case 5: /* 38 tokens of length 5 */
6795 if (name[1] == 'E' &&
6806 if (name[1] == 'H' &&
6820 if (name[2] == 'a' &&
6830 if (name[2] == 'a' &&
6847 if (name[2] == 'e' &&
6857 if (name[2] == 'e' &&
6861 return (FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
6877 if (name[3] == 'i' &&
6886 if (name[3] == 'o' &&
6922 if (name[2] == 'o' &&
6932 if (name[2] == 'y' &&
6946 if (name[1] == 'l' &&
6960 if (name[2] == 'n' &&
6970 if (name[2] == 'o' &&
6984 if (name[1] == 'i' &&
6989 return (FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
6998 if (name[2] == 'd' &&
7008 if (name[2] == 'c' &&
7025 if (name[2] == 'c' &&
7035 if (name[2] == 't' &&
7049 if (name[1] == 'k' &&
7060 if (name[1] == 'r' &&
7074 if (name[2] == 's' &&
7084 if (name[2] == 'd' &&
7101 if (name[2] == 'm' &&
7111 if (name[2] == 'i' &&
7121 if (name[2] == 'e' &&
7131 if (name[2] == 'l' &&
7141 if (name[2] == 'a' &&
7151 if (name[2] == 'u' &&
7165 if (name[1] == 'i' &&
7179 if (name[2] == 'a' &&
7192 if (name[3] == 'e' &&
7227 if (name[2] == 'i' &&
7244 if (name[2] == 'i' &&
7254 if (name[2] == 'i' &&
7271 case 6: /* 33 tokens of length 6 */
7275 if (name[1] == 'c' &&
7290 if (name[2] == 'l' &&
7301 if (name[2] == 'r' &&
7316 if (name[1] == 'e' &&
7331 if (name[2] == 's' &&
7336 if(ckWARN_d(WARN_SYNTAX))
7337 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
7343 if (name[2] == 'i' &&
7361 if (name[2] == 'l' &&
7372 if (name[2] == 'r' &&
7387 if (name[1] == 'm' &&
7402 if (name[2] == 'n' &&
7413 if (name[2] == 's' &&
7428 if (name[1] == 's' &&
7434 if (name[4] == 't' &&
7443 if (name[4] == 'e' &&
7452 if (name[4] == 'c' &&
7461 if (name[4] == 'n' &&
7477 if (name[1] == 'r' &&
7495 if (name[3] == 'a' &&
7505 if (name[3] == 'u' &&
7519 if (name[2] == 'n' &&
7537 if (name[2] == 'a' &&
7551 if (name[3] == 'e' &&
7564 if (name[4] == 't' &&
7573 if (name[4] == 'e' &&
7595 if (name[4] == 't' &&
7604 if (name[4] == 'e' &&
7620 if (name[2] == 'c' &&
7631 if (name[2] == 'l' &&
7642 if (name[2] == 'b' &&
7653 if (name[2] == 's' &&
7676 if (name[4] == 's' &&
7685 if (name[4] == 'n' &&
7698 if (name[3] == 'a' &&
7715 if (name[1] == 'a' &&
7730 case 7: /* 29 tokens of length 7 */
7734 if (name[1] == 'E' &&
7747 if (name[1] == '_' &&
7760 if (name[1] == 'i' &&
7767 return -KEY_binmode;
7773 if (name[1] == 'o' &&
7780 return -KEY_connect;
7789 if (name[2] == 'm' &&
7795 return -KEY_dbmopen;
7806 if (name[4] == 'u' &&
7810 return (FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
7816 if (name[4] == 'n' &&
7837 if (name[1] == 'o' &&
7850 if (name[1] == 'e' &&
7857 if (name[5] == 'r' &&
7860 return -KEY_getpgrp;
7866 if (name[5] == 'i' &&
7869 return -KEY_getppid;
7882 if (name[1] == 'c' &&
7889 return -KEY_lcfirst;
7895 if (name[1] == 'p' &&
7902 return -KEY_opendir;
7908 if (name[1] == 'a' &&
7926 if (name[3] == 'd' &&
7931 return -KEY_readdir;
7937 if (name[3] == 'u' &&
7948 if (name[3] == 'e' &&
7953 return -KEY_reverse;
7972 if (name[3] == 'k' &&
7977 return -KEY_seekdir;
7983 if (name[3] == 'p' &&
7988 return -KEY_setpgrp;
7998 if (name[2] == 'm' &&
8004 return -KEY_shmread;
8010 if (name[2] == 'r' &&
8016 return -KEY_sprintf;
8025 if (name[3] == 'l' &&
8030 return -KEY_symlink;
8039 if (name[4] == 'a' &&
8043 return -KEY_syscall;
8049 if (name[4] == 'p' &&
8053 return -KEY_sysopen;
8059 if (name[4] == 'e' &&
8063 return -KEY_sysread;
8069 if (name[4] == 'e' &&
8073 return -KEY_sysseek;
8091 if (name[1] == 'e' &&
8098 return -KEY_telldir;
8107 if (name[2] == 'f' &&
8113 return -KEY_ucfirst;
8119 if (name[2] == 's' &&
8125 return -KEY_unshift;
8135 if (name[1] == 'a' &&
8142 return -KEY_waitpid;
8151 case 8: /* 26 tokens of length 8 */
8155 if (name[1] == 'U' &&
8163 return KEY_AUTOLOAD;
8174 if (name[3] == 'A' &&
8180 return KEY___DATA__;
8186 if (name[3] == 'I' &&
8192 return -KEY___FILE__;
8198 if (name[3] == 'I' &&
8204 return -KEY___LINE__;
8220 if (name[2] == 'o' &&
8227 return -KEY_closedir;
8233 if (name[2] == 'n' &&
8240 return -KEY_continue;
8250 if (name[1] == 'b' &&
8258 return -KEY_dbmclose;
8264 if (name[1] == 'n' &&
8270 if (name[4] == 'r' &&
8275 return -KEY_endgrent;
8281 if (name[4] == 'w' &&
8286 return -KEY_endpwent;
8299 if (name[1] == 'o' &&
8307 return -KEY_formline;
8313 if (name[1] == 'e' &&
8324 if (name[6] == 'n' &&
8327 return -KEY_getgrent;
8333 if (name[6] == 'i' &&
8336 return -KEY_getgrgid;
8342 if (name[6] == 'a' &&
8345 return -KEY_getgrnam;
8358 if (name[4] == 'o' &&
8363 return -KEY_getlogin;
8374 if (name[6] == 'n' &&
8377 return -KEY_getpwent;
8383 if (name[6] == 'a' &&
8386 return -KEY_getpwnam;
8392 if (name[6] == 'i' &&
8395 return -KEY_getpwuid;
8415 if (name[1] == 'e' &&
8422 if (name[5] == 'i' &&
8429 return -KEY_readline;
8434 return -KEY_readlink;
8445 if (name[5] == 'i' &&
8449 return -KEY_readpipe;
8470 if (name[4] == 'r' &&
8475 return -KEY_setgrent;
8481 if (name[4] == 'w' &&
8486 return -KEY_setpwent;
8502 if (name[3] == 'w' &&
8508 return -KEY_shmwrite;
8514 if (name[3] == 't' &&
8520 return -KEY_shutdown;
8530 if (name[2] == 's' &&
8537 return -KEY_syswrite;
8547 if (name[1] == 'r' &&
8555 return -KEY_truncate;
8564 case 9: /* 8 tokens of length 9 */
8568 if (name[1] == 'n' &&
8577 return -KEY_endnetent;
8583 if (name[1] == 'e' &&
8592 return -KEY_getnetent;
8598 if (name[1] == 'o' &&
8607 return -KEY_localtime;
8613 if (name[1] == 'r' &&
8622 return KEY_prototype;
8628 if (name[1] == 'u' &&
8637 return -KEY_quotemeta;
8643 if (name[1] == 'e' &&
8652 return -KEY_rewinddir;
8658 if (name[1] == 'e' &&
8667 return -KEY_setnetent;
8673 if (name[1] == 'a' &&
8682 return -KEY_wantarray;
8691 case 10: /* 9 tokens of length 10 */
8695 if (name[1] == 'n' &&
8701 if (name[4] == 'o' &&
8708 return -KEY_endhostent;
8714 if (name[4] == 'e' &&
8721 return -KEY_endservent;
8734 if (name[1] == 'e' &&
8740 if (name[4] == 'o' &&
8747 return -KEY_gethostent;
8756 if (name[5] == 'r' &&
8762 return -KEY_getservent;
8768 if (name[5] == 'c' &&
8774 return -KEY_getsockopt;
8799 if (name[4] == 'o' &&
8806 return -KEY_sethostent;
8815 if (name[5] == 'r' &&
8821 return -KEY_setservent;
8827 if (name[5] == 'c' &&
8833 return -KEY_setsockopt;
8850 if (name[2] == 'c' &&
8859 return -KEY_socketpair;
8872 case 11: /* 8 tokens of length 11 */
8876 if (name[1] == '_' &&
8887 return -KEY___PACKAGE__;
8893 if (name[1] == 'n' &&
8904 return -KEY_endprotoent;
8910 if (name[1] == 'e' &&
8919 if (name[5] == 'e' &&
8926 return -KEY_getpeername;
8935 if (name[6] == 'o' &&
8941 return -KEY_getpriority;
8947 if (name[6] == 't' &&
8953 return -KEY_getprotoent;
8967 if (name[4] == 'o' &&
8975 return -KEY_getsockname;
8988 if (name[1] == 'e' &&
8996 if (name[6] == 'o' &&
9002 return -KEY_setpriority;
9008 if (name[6] == 't' &&
9014 return -KEY_setprotoent;
9030 case 12: /* 2 tokens of length 12 */
9031 if (name[0] == 'g' &&
9043 if (name[9] == 'd' &&
9046 { /* getnetbyaddr */
9047 return -KEY_getnetbyaddr;
9053 if (name[9] == 'a' &&
9056 { /* getnetbyname */
9057 return -KEY_getnetbyname;
9069 case 13: /* 4 tokens of length 13 */
9070 if (name[0] == 'g' &&
9077 if (name[4] == 'o' &&
9086 if (name[10] == 'd' &&
9089 { /* gethostbyaddr */
9090 return -KEY_gethostbyaddr;
9096 if (name[10] == 'a' &&
9099 { /* gethostbyname */
9100 return -KEY_gethostbyname;
9113 if (name[4] == 'e' &&
9122 if (name[10] == 'a' &&
9125 { /* getservbyname */
9126 return -KEY_getservbyname;
9132 if (name[10] == 'o' &&
9135 { /* getservbyport */
9136 return -KEY_getservbyport;
9155 case 14: /* 1 tokens of length 14 */
9156 if (name[0] == 'g' &&
9170 { /* getprotobyname */
9171 return -KEY_getprotobyname;
9176 case 16: /* 1 tokens of length 16 */
9177 if (name[0] == 'g' &&
9193 { /* getprotobynumber */
9194 return -KEY_getprotobynumber;
9208 S_checkcomma(pTHX_ register char *s, const char *name, const char *what)
9213 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
9214 if (ckWARN(WARN_SYNTAX)) {
9216 for (w = s+2; *w && level; w++) {
9223 for (; *w && isSPACE(*w); w++) ;
9224 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
9225 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
9226 "%s (...) interpreted as function",name);
9229 while (s < PL_bufend && isSPACE(*s))
9233 while (s < PL_bufend && isSPACE(*s))
9235 if (isIDFIRST_lazy_if(s,UTF)) {
9237 while (isALNUM_lazy_if(s,UTF))
9239 while (s < PL_bufend && isSPACE(*s))
9243 *s = '\0'; /* XXX If we didn't do this, we could const a lot of toke.c */
9244 kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
9248 Perl_croak(aTHX_ "No comma allowed after %s", what);
9253 /* Either returns sv, or mortalizes sv and returns a new SV*.
9254 Best used as sv=new_constant(..., sv, ...).
9255 If s, pv are NULL, calls subroutine with one argument,
9256 and type is used with error messages only. */
9259 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
9263 HV * const table = GvHV(PL_hintgv); /* ^H */
9267 const char *why1 = "", *why2 = "", *why3 = "";
9269 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
9272 why2 = strEQ(key,"charnames")
9273 ? "(possibly a missing \"use charnames ...\")"
9275 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
9276 (type ? type: "undef"), why2);
9278 /* This is convoluted and evil ("goto considered harmful")
9279 * but I do not understand the intricacies of all the different
9280 * failure modes of %^H in here. The goal here is to make
9281 * the most probable error message user-friendly. --jhi */
9286 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
9287 (type ? type: "undef"), why1, why2, why3);
9289 yyerror(SvPVX_const(msg));
9293 cvp = hv_fetch(table, key, strlen(key), FALSE);
9294 if (!cvp || !SvOK(*cvp)) {
9297 why3 = "} is not defined";
9300 sv_2mortal(sv); /* Parent created it permanently */
9303 pv = sv_2mortal(newSVpvn(s, len));
9305 typesv = sv_2mortal(newSVpv(type, 0));
9307 typesv = &PL_sv_undef;
9309 PUSHSTACKi(PERLSI_OVERLOAD);
9321 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
9325 /* Check the eval first */
9326 if (!PL_in_eval && SvTRUE(ERRSV)) {
9327 sv_catpvs(ERRSV, "Propagated");
9328 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
9330 res = SvREFCNT_inc(sv);
9334 (void)SvREFCNT_inc(res);
9343 why1 = "Call to &{$^H{";
9345 why3 = "}} did not return a defined value";
9353 /* Returns a NUL terminated string, with the length of the string written to
9357 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
9360 register char *d = dest;
9361 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
9364 Perl_croak(aTHX_ ident_too_long);
9365 if (isALNUM(*s)) /* UTF handled below */
9367 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
9372 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
9376 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9377 char *t = s + UTF8SKIP(s);
9378 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9380 if (d + (t - s) > e)
9381 Perl_croak(aTHX_ ident_too_long);
9382 Copy(s, d, t - s, char);
9395 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
9398 char *bracket = NULL;
9400 register char *d = dest;
9401 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
9406 while (isDIGIT(*s)) {
9408 Perl_croak(aTHX_ ident_too_long);
9415 Perl_croak(aTHX_ ident_too_long);
9416 if (isALNUM(*s)) /* UTF handled below */
9418 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
9423 else if (*s == ':' && s[1] == ':') {
9427 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9428 char *t = s + UTF8SKIP(s);
9429 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9431 if (d + (t - s) > e)
9432 Perl_croak(aTHX_ ident_too_long);
9433 Copy(s, d, t - s, char);
9444 if (PL_lex_state != LEX_NORMAL)
9445 PL_lex_state = LEX_INTERPENDMAYBE;
9448 if (*s == '$' && s[1] &&
9449 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
9462 if (*d == '^' && *s && isCONTROLVAR(*s)) {
9467 if (isSPACE(s[-1])) {
9469 const char ch = *s++;
9470 if (!SPACE_OR_TAB(ch)) {
9476 if (isIDFIRST_lazy_if(d,UTF)) {
9480 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
9481 end += UTF8SKIP(end);
9482 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
9483 end += UTF8SKIP(end);
9485 Copy(s, d, end - s, char);
9490 while ((isALNUM(*s) || *s == ':') && d < e)
9493 Perl_croak(aTHX_ ident_too_long);
9496 while (s < send && SPACE_OR_TAB(*s)) s++;
9497 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
9498 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
9499 const char *brack = *s == '[' ? "[...]" : "{...}";
9500 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9501 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
9502 funny, dest, brack, funny, dest, brack);
9505 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
9509 /* Handle extended ${^Foo} variables
9510 * 1999-02-27 mjd-perl-patch@plover.com */
9511 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
9515 while (isALNUM(*s) && d < e) {
9519 Perl_croak(aTHX_ ident_too_long);
9524 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
9525 PL_lex_state = LEX_INTERPEND;
9530 if (PL_lex_state == LEX_NORMAL) {
9531 if (ckWARN(WARN_AMBIGUOUS) &&
9532 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
9534 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9535 "Ambiguous use of %c{%s} resolved to %c%s",
9536 funny, dest, funny, dest);
9541 s = bracket; /* let the parser handle it */
9545 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
9546 PL_lex_state = LEX_INTERPEND;
9551 Perl_pmflag(pTHX_ U32* pmfl, int ch)
9556 *pmfl |= PMf_GLOBAL;
9558 *pmfl |= PMf_CONTINUE;
9562 *pmfl |= PMf_MULTILINE;
9564 *pmfl |= PMf_SINGLELINE;
9566 *pmfl |= PMf_EXTENDED;
9570 S_scan_pat(pTHX_ char *start, I32 type)
9574 char *s = scan_str(start,FALSE,FALSE);
9575 const char * const valid_flags = (type == OP_QR) ? "iomsx" : "iogcmsx";
9578 const char * const delimiter = skipspace(start);
9579 Perl_croak(aTHX_ *delimiter == '?'
9580 ? "Search pattern not terminated or ternary operator parsed as search pattern"
9581 : "Search pattern not terminated" );
9584 pm = (PMOP*)newPMOP(type, 0);
9585 if (PL_multi_open == '?')
9586 pm->op_pmflags |= PMf_ONCE;
9587 while (*s && strchr(valid_flags, *s))
9588 pmflag(&pm->op_pmflags,*s++);
9589 /* issue a warning if /c is specified,but /g is not */
9590 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
9591 && ckWARN(WARN_REGEXP))
9593 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
9596 pm->op_pmpermflags = pm->op_pmflags;
9598 PL_lex_op = (OP*)pm;
9599 yylval.ival = OP_MATCH;
9604 S_scan_subst(pTHX_ char *start)
9612 yylval.ival = OP_NULL;
9614 s = scan_str(start,FALSE,FALSE);
9617 Perl_croak(aTHX_ "Substitution pattern not terminated");
9619 if (s[-1] == PL_multi_open)
9622 first_start = PL_multi_start;
9623 s = scan_str(s,FALSE,FALSE);
9626 SvREFCNT_dec(PL_lex_stuff);
9627 PL_lex_stuff = Nullsv;
9629 Perl_croak(aTHX_ "Substitution replacement not terminated");
9631 PL_multi_start = first_start; /* so whole substitution is taken together */
9633 pm = (PMOP*)newPMOP(OP_SUBST, 0);
9639 else if (strchr("iogcmsx", *s))
9640 pmflag(&pm->op_pmflags,*s++);
9645 if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
9646 Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
9650 SV * const repl = newSVpvs("");
9652 PL_sublex_info.super_bufptr = s;
9653 PL_sublex_info.super_bufend = PL_bufend;
9655 pm->op_pmflags |= PMf_EVAL;
9657 sv_catpv(repl, es ? "eval " : "do ");
9658 sv_catpvs(repl, "{ ");
9659 sv_catsv(repl, PL_lex_repl);
9660 sv_catpvs(repl, " }");
9662 SvREFCNT_dec(PL_lex_repl);
9666 pm->op_pmpermflags = pm->op_pmflags;
9667 PL_lex_op = (OP*)pm;
9668 yylval.ival = OP_SUBST;
9673 S_scan_trans(pTHX_ char *start)
9683 yylval.ival = OP_NULL;
9685 s = scan_str(start,FALSE,FALSE);
9687 Perl_croak(aTHX_ "Transliteration pattern not terminated");
9688 if (s[-1] == PL_multi_open)
9691 s = scan_str(s,FALSE,FALSE);
9694 SvREFCNT_dec(PL_lex_stuff);
9695 PL_lex_stuff = Nullsv;
9697 Perl_croak(aTHX_ "Transliteration replacement not terminated");
9700 complement = del = squash = 0;
9704 complement = OPpTRANS_COMPLEMENT;
9707 del = OPpTRANS_DELETE;
9710 squash = OPpTRANS_SQUASH;
9719 Newx(tbl, complement&&!del?258:256, short);
9720 o = newPVOP(OP_TRANS, 0, (char*)tbl);
9721 o->op_private &= ~OPpTRANS_ALL;
9722 o->op_private |= del|squash|complement|
9723 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
9724 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
9727 yylval.ival = OP_TRANS;
9732 S_scan_heredoc(pTHX_ register char *s)
9736 I32 op_type = OP_SCALAR;
9740 const char *found_newline;
9744 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
9748 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
9751 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
9752 if (*peek == '`' || *peek == '\'' || *peek =='"') {
9755 s = delimcpy(d, e, s, PL_bufend, term, &len);
9765 if (!isALNUM_lazy_if(s,UTF))
9766 deprecate_old("bare << to mean <<\"\"");
9767 for (; isALNUM_lazy_if(s,UTF); s++) {
9772 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
9773 Perl_croak(aTHX_ "Delimiter for here document is too long");
9776 len = d - PL_tokenbuf;
9777 #ifndef PERL_STRICT_CR
9778 d = strchr(s, '\r');
9780 char * const olds = s;
9782 while (s < PL_bufend) {
9788 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
9797 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
9801 if ( outer || !(found_newline = memchr(s, '\n', PL_bufend - s)) ) {
9802 herewas = newSVpvn(s,PL_bufend-s);
9806 herewas = newSVpvn(s,found_newline-s);
9808 s += SvCUR(herewas);
9811 sv_upgrade(tmpstr, SVt_PVIV);
9814 SvIV_set(tmpstr, -1);
9816 else if (term == '`') {
9817 op_type = OP_BACKTICK;
9818 SvIV_set(tmpstr, '\\');
9822 PL_multi_start = CopLINE(PL_curcop);
9823 PL_multi_open = PL_multi_close = '<';
9824 term = *PL_tokenbuf;
9825 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
9826 char * const bufptr = PL_sublex_info.super_bufptr;
9827 char * const bufend = PL_sublex_info.super_bufend;
9828 char * const olds = s - SvCUR(herewas);
9829 s = strchr(bufptr, '\n');
9833 while (s < bufend &&
9834 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9836 CopLINE_inc(PL_curcop);
9839 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9840 missingterm(PL_tokenbuf);
9842 sv_setpvn(herewas,bufptr,d-bufptr+1);
9843 sv_setpvn(tmpstr,d+1,s-d);
9845 sv_catpvn(herewas,s,bufend-s);
9846 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
9853 while (s < PL_bufend &&
9854 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9856 CopLINE_inc(PL_curcop);
9858 if (s >= PL_bufend) {
9859 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9860 missingterm(PL_tokenbuf);
9862 sv_setpvn(tmpstr,d+1,s-d);
9864 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
9866 sv_catpvn(herewas,s,PL_bufend-s);
9867 sv_setsv(PL_linestr,herewas);
9868 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
9869 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9870 PL_last_lop = PL_last_uni = Nullch;
9873 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
9874 while (s >= PL_bufend) { /* multiple line string? */
9876 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
9877 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9878 missingterm(PL_tokenbuf);
9880 CopLINE_inc(PL_curcop);
9881 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9882 PL_last_lop = PL_last_uni = Nullch;
9883 #ifndef PERL_STRICT_CR
9884 if (PL_bufend - PL_linestart >= 2) {
9885 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
9886 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
9888 PL_bufend[-2] = '\n';
9890 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
9892 else if (PL_bufend[-1] == '\r')
9893 PL_bufend[-1] = '\n';
9895 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
9896 PL_bufend[-1] = '\n';
9898 if (PERLDB_LINE && PL_curstash != PL_debstash) {
9899 SV * const sv = newSV(0);
9901 sv_upgrade(sv, SVt_PVMG);
9902 sv_setsv(sv,PL_linestr);
9905 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop),sv);
9907 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
9908 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
9909 *(SvPVX(PL_linestr) + off ) = ' ';
9910 sv_catsv(PL_linestr,herewas);
9911 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9912 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
9916 sv_catsv(tmpstr,PL_linestr);
9921 PL_multi_end = CopLINE(PL_curcop);
9922 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
9923 SvPV_shrink_to_cur(tmpstr);
9925 SvREFCNT_dec(herewas);
9927 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
9929 else if (PL_encoding)
9930 sv_recode_to_utf8(tmpstr, PL_encoding);
9932 PL_lex_stuff = tmpstr;
9933 yylval.ival = op_type;
9938 takes: current position in input buffer
9939 returns: new position in input buffer
9940 side-effects: yylval and lex_op are set.
9945 <FH> read from filehandle
9946 <pkg::FH> read from package qualified filehandle
9947 <pkg'FH> read from package qualified filehandle
9948 <$fh> read from filehandle in $fh
9954 S_scan_inputsymbol(pTHX_ char *start)
9957 register char *s = start; /* current position in buffer */
9961 char *d = PL_tokenbuf; /* start of temp holding space */
9962 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
9964 end = strchr(s, '\n');
9967 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
9969 /* die if we didn't have space for the contents of the <>,
9970 or if it didn't end, or if we see a newline
9973 if (len >= sizeof PL_tokenbuf)
9974 Perl_croak(aTHX_ "Excessively long <> operator");
9976 Perl_croak(aTHX_ "Unterminated <> operator");
9981 Remember, only scalar variables are interpreted as filehandles by
9982 this code. Anything more complex (e.g., <$fh{$num}>) will be
9983 treated as a glob() call.
9984 This code makes use of the fact that except for the $ at the front,
9985 a scalar variable and a filehandle look the same.
9987 if (*d == '$' && d[1]) d++;
9989 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
9990 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
9993 /* If we've tried to read what we allow filehandles to look like, and
9994 there's still text left, then it must be a glob() and not a getline.
9995 Use scan_str to pull out the stuff between the <> and treat it
9996 as nothing more than a string.
9999 if (d - PL_tokenbuf != len) {
10000 yylval.ival = OP_GLOB;
10002 s = scan_str(start,FALSE,FALSE);
10004 Perl_croak(aTHX_ "Glob not terminated");
10008 bool readline_overriden = FALSE;
10011 /* we're in a filehandle read situation */
10014 /* turn <> into <ARGV> */
10016 Copy("ARGV",d,5,char);
10018 /* Check whether readline() is overriden */
10019 gv_readline = gv_fetchpvs("readline", 0, SVt_PVCV);
10021 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
10023 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
10024 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
10025 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
10026 readline_overriden = TRUE;
10028 /* if <$fh>, create the ops to turn the variable into a
10034 /* try to find it in the pad for this block, otherwise find
10035 add symbol table ops
10037 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
10038 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
10039 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
10040 HEK * const stashname = HvNAME_HEK(stash);
10041 SV * const sym = sv_2mortal(newSVhek(stashname));
10042 sv_catpvs(sym, "::");
10043 sv_catpv(sym, d+1);
10048 OP * const o = newOP(OP_PADSV, 0);
10050 PL_lex_op = readline_overriden
10051 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
10052 append_elem(OP_LIST, o,
10053 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
10054 : (OP*)newUNOP(OP_READLINE, 0, o);
10063 ? (GV_ADDMULTI | GV_ADDINEVAL)
10066 PL_lex_op = readline_overriden
10067 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
10068 append_elem(OP_LIST,
10069 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
10070 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
10071 : (OP*)newUNOP(OP_READLINE, 0,
10072 newUNOP(OP_RV2SV, 0,
10073 newGVOP(OP_GV, 0, gv)));
10075 if (!readline_overriden)
10076 PL_lex_op->op_flags |= OPf_SPECIAL;
10077 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
10078 yylval.ival = OP_NULL;
10081 /* If it's none of the above, it must be a literal filehandle
10082 (<Foo::BAR> or <FOO>) so build a simple readline OP */
10084 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
10085 PL_lex_op = readline_overriden
10086 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
10087 append_elem(OP_LIST,
10088 newGVOP(OP_GV, 0, gv),
10089 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
10090 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
10091 yylval.ival = OP_NULL;
10100 takes: start position in buffer
10101 keep_quoted preserve \ on the embedded delimiter(s)
10102 keep_delims preserve the delimiters around the string
10103 returns: position to continue reading from buffer
10104 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
10105 updates the read buffer.
10107 This subroutine pulls a string out of the input. It is called for:
10108 q single quotes q(literal text)
10109 ' single quotes 'literal text'
10110 qq double quotes qq(interpolate $here please)
10111 " double quotes "interpolate $here please"
10112 qx backticks qx(/bin/ls -l)
10113 ` backticks `/bin/ls -l`
10114 qw quote words @EXPORT_OK = qw( func() $spam )
10115 m// regexp match m/this/
10116 s/// regexp substitute s/this/that/
10117 tr/// string transliterate tr/this/that/
10118 y/// string transliterate y/this/that/
10119 ($*@) sub prototypes sub foo ($)
10120 (stuff) sub attr parameters sub foo : attr(stuff)
10121 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
10123 In most of these cases (all but <>, patterns and transliterate)
10124 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
10125 calls scan_str(). s/// makes yylex() call scan_subst() which calls
10126 scan_str(). tr/// and y/// make yylex() call scan_trans() which
10129 It skips whitespace before the string starts, and treats the first
10130 character as the delimiter. If the delimiter is one of ([{< then
10131 the corresponding "close" character )]}> is used as the closing
10132 delimiter. It allows quoting of delimiters, and if the string has
10133 balanced delimiters ([{<>}]) it allows nesting.
10135 On success, the SV with the resulting string is put into lex_stuff or,
10136 if that is already non-NULL, into lex_repl. The second case occurs only
10137 when parsing the RHS of the special constructs s/// and tr/// (y///).
10138 For convenience, the terminating delimiter character is stuffed into
10143 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
10146 SV *sv; /* scalar value: string */
10147 char *tmps; /* temp string, used for delimiter matching */
10148 register char *s = start; /* current position in the buffer */
10149 register char term; /* terminating character */
10150 register char *to; /* current position in the sv's data */
10151 I32 brackets = 1; /* bracket nesting level */
10152 bool has_utf8 = FALSE; /* is there any utf8 content? */
10153 I32 termcode; /* terminating char. code */
10154 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
10155 STRLEN termlen; /* length of terminating string */
10156 char *last = NULL; /* last position for nesting bracket */
10158 /* skip space before the delimiter */
10162 /* mark where we are, in case we need to report errors */
10165 /* after skipping whitespace, the next character is the terminator */
10168 termcode = termstr[0] = term;
10172 termcode = utf8_to_uvchr((U8*)s, &termlen);
10173 Copy(s, termstr, termlen, U8);
10174 if (!UTF8_IS_INVARIANT(term))
10178 /* mark where we are */
10179 PL_multi_start = CopLINE(PL_curcop);
10180 PL_multi_open = term;
10182 /* find corresponding closing delimiter */
10183 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
10184 termcode = termstr[0] = term = tmps[5];
10186 PL_multi_close = term;
10188 /* create a new SV to hold the contents. 79 is the SV's initial length.
10189 What a random number. */
10191 sv_upgrade(sv, SVt_PVIV);
10192 SvIV_set(sv, termcode);
10193 (void)SvPOK_only(sv); /* validate pointer */
10195 /* move past delimiter and try to read a complete string */
10197 sv_catpvn(sv, s, termlen);
10200 if (PL_encoding && !UTF) {
10204 int offset = s - SvPVX_const(PL_linestr);
10205 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
10206 &offset, (char*)termstr, termlen);
10207 const char * const ns = SvPVX_const(PL_linestr) + offset;
10208 char * const svlast = SvEND(sv) - 1;
10210 for (; s < ns; s++) {
10211 if (*s == '\n' && !PL_rsfp)
10212 CopLINE_inc(PL_curcop);
10215 goto read_more_line;
10217 /* handle quoted delimiters */
10218 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
10220 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
10222 if ((svlast-1 - t) % 2) {
10223 if (!keep_quoted) {
10224 *(svlast-1) = term;
10226 SvCUR_set(sv, SvCUR(sv) - 1);
10231 if (PL_multi_open == PL_multi_close) {
10239 for (t = w = last; t < svlast; w++, t++) {
10240 /* At here, all closes are "was quoted" one,
10241 so we don't check PL_multi_close. */
10243 if (!keep_quoted && *(t+1) == PL_multi_open)
10248 else if (*t == PL_multi_open)
10256 SvCUR_set(sv, w - SvPVX_const(sv));
10259 if (--brackets <= 0)
10264 if (!keep_delims) {
10265 SvCUR_set(sv, SvCUR(sv) - 1);
10271 /* extend sv if need be */
10272 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
10273 /* set 'to' to the next character in the sv's string */
10274 to = SvPVX(sv)+SvCUR(sv);
10276 /* if open delimiter is the close delimiter read unbridle */
10277 if (PL_multi_open == PL_multi_close) {
10278 for (; s < PL_bufend; s++,to++) {
10279 /* embedded newlines increment the current line number */
10280 if (*s == '\n' && !PL_rsfp)
10281 CopLINE_inc(PL_curcop);
10282 /* handle quoted delimiters */
10283 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
10284 if (!keep_quoted && s[1] == term)
10286 /* any other quotes are simply copied straight through */
10290 /* terminate when run out of buffer (the for() condition), or
10291 have found the terminator */
10292 else if (*s == term) {
10295 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
10298 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
10304 /* if the terminator isn't the same as the start character (e.g.,
10305 matched brackets), we have to allow more in the quoting, and
10306 be prepared for nested brackets.
10309 /* read until we run out of string, or we find the terminator */
10310 for (; s < PL_bufend; s++,to++) {
10311 /* embedded newlines increment the line count */
10312 if (*s == '\n' && !PL_rsfp)
10313 CopLINE_inc(PL_curcop);
10314 /* backslashes can escape the open or closing characters */
10315 if (*s == '\\' && s+1 < PL_bufend) {
10316 if (!keep_quoted &&
10317 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
10322 /* allow nested opens and closes */
10323 else if (*s == PL_multi_close && --brackets <= 0)
10325 else if (*s == PL_multi_open)
10327 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
10332 /* terminate the copied string and update the sv's end-of-string */
10334 SvCUR_set(sv, to - SvPVX_const(sv));
10337 * this next chunk reads more into the buffer if we're not done yet
10341 break; /* handle case where we are done yet :-) */
10343 #ifndef PERL_STRICT_CR
10344 if (to - SvPVX_const(sv) >= 2) {
10345 if ((to[-2] == '\r' && to[-1] == '\n') ||
10346 (to[-2] == '\n' && to[-1] == '\r'))
10350 SvCUR_set(sv, to - SvPVX_const(sv));
10352 else if (to[-1] == '\r')
10355 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
10360 /* if we're out of file, or a read fails, bail and reset the current
10361 line marker so we can report where the unterminated string began
10364 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
10366 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10369 /* we read a line, so increment our line counter */
10370 CopLINE_inc(PL_curcop);
10372 /* update debugger info */
10373 if (PERLDB_LINE && PL_curstash != PL_debstash) {
10374 SV * const sv = newSV(0);
10376 sv_upgrade(sv, SVt_PVMG);
10377 sv_setsv(sv,PL_linestr);
10378 (void)SvIOK_on(sv);
10380 av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop), sv);
10383 /* having changed the buffer, we must update PL_bufend */
10384 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10385 PL_last_lop = PL_last_uni = Nullch;
10388 /* at this point, we have successfully read the delimited string */
10390 if (!PL_encoding || UTF) {
10392 sv_catpvn(sv, s, termlen);
10395 if (has_utf8 || PL_encoding)
10398 PL_multi_end = CopLINE(PL_curcop);
10400 /* if we allocated too much space, give some back */
10401 if (SvCUR(sv) + 5 < SvLEN(sv)) {
10402 SvLEN_set(sv, SvCUR(sv) + 1);
10403 SvPV_renew(sv, SvLEN(sv));
10406 /* decide whether this is the first or second quoted string we've read
10419 takes: pointer to position in buffer
10420 returns: pointer to new position in buffer
10421 side-effects: builds ops for the constant in yylval.op
10423 Read a number in any of the formats that Perl accepts:
10425 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
10426 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
10429 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
10431 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
10434 If it reads a number without a decimal point or an exponent, it will
10435 try converting the number to an integer and see if it can do so
10436 without loss of precision.
10440 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
10443 register const char *s = start; /* current position in buffer */
10444 register char *d; /* destination in temp buffer */
10445 register char *e; /* end of temp buffer */
10446 NV nv; /* number read, as a double */
10447 SV *sv = Nullsv; /* place to put the converted number */
10448 bool floatit; /* boolean: int or float? */
10449 const char *lastub = NULL; /* position of last underbar */
10450 static char const number_too_long[] = "Number too long";
10452 /* We use the first character to decide what type of number this is */
10456 Perl_croak(aTHX_ "panic: scan_num");
10458 /* if it starts with a 0, it could be an octal number, a decimal in
10459 0.13 disguise, or a hexadecimal number, or a binary number. */
10463 u holds the "number so far"
10464 shift the power of 2 of the base
10465 (hex == 4, octal == 3, binary == 1)
10466 overflowed was the number more than we can hold?
10468 Shift is used when we add a digit. It also serves as an "are
10469 we in octal/hex/binary?" indicator to disallow hex characters
10470 when in octal mode.
10475 bool overflowed = FALSE;
10476 bool just_zero = TRUE; /* just plain 0 or binary number? */
10477 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
10478 static const char* const bases[5] =
10479 { "", "binary", "", "octal", "hexadecimal" };
10480 static const char* const Bases[5] =
10481 { "", "Binary", "", "Octal", "Hexadecimal" };
10482 static const char* const maxima[5] =
10484 "0b11111111111111111111111111111111",
10488 const char *base, *Base, *max;
10490 /* check for hex */
10495 } else if (s[1] == 'b') {
10500 /* check for a decimal in disguise */
10501 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
10503 /* so it must be octal */
10510 if (ckWARN(WARN_SYNTAX))
10511 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10512 "Misplaced _ in number");
10516 base = bases[shift];
10517 Base = Bases[shift];
10518 max = maxima[shift];
10520 /* read the rest of the number */
10522 /* x is used in the overflow test,
10523 b is the digit we're adding on. */
10528 /* if we don't mention it, we're done */
10532 /* _ are ignored -- but warned about if consecutive */
10534 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
10535 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10536 "Misplaced _ in number");
10540 /* 8 and 9 are not octal */
10541 case '8': case '9':
10543 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
10547 case '2': case '3': case '4':
10548 case '5': case '6': case '7':
10550 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
10553 case '0': case '1':
10554 b = *s++ & 15; /* ASCII digit -> value of digit */
10558 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
10559 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
10560 /* make sure they said 0x */
10563 b = (*s++ & 7) + 9;
10565 /* Prepare to put the digit we have onto the end
10566 of the number so far. We check for overflows.
10572 x = u << shift; /* make room for the digit */
10574 if ((x >> shift) != u
10575 && !(PL_hints & HINT_NEW_BINARY)) {
10578 if (ckWARN_d(WARN_OVERFLOW))
10579 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
10580 "Integer overflow in %s number",
10583 u = x | b; /* add the digit to the end */
10586 n *= nvshift[shift];
10587 /* If an NV has not enough bits in its
10588 * mantissa to represent an UV this summing of
10589 * small low-order numbers is a waste of time
10590 * (because the NV cannot preserve the
10591 * low-order bits anyway): we could just
10592 * remember when did we overflow and in the
10593 * end just multiply n by the right
10601 /* if we get here, we had success: make a scalar value from
10606 /* final misplaced underbar check */
10607 if (s[-1] == '_') {
10608 if (ckWARN(WARN_SYNTAX))
10609 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10614 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
10615 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10616 "%s number > %s non-portable",
10622 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
10623 Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10624 "%s number > %s non-portable",
10629 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
10630 sv = new_constant(start, s - start, "integer",
10632 else if (PL_hints & HINT_NEW_BINARY)
10633 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
10638 handle decimal numbers.
10639 we're also sent here when we read a 0 as the first digit
10641 case '1': case '2': case '3': case '4': case '5':
10642 case '6': case '7': case '8': case '9': case '.':
10645 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
10648 /* read next group of digits and _ and copy into d */
10649 while (isDIGIT(*s) || *s == '_') {
10650 /* skip underscores, checking for misplaced ones
10654 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
10655 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10656 "Misplaced _ in number");
10660 /* check for end of fixed-length buffer */
10662 Perl_croak(aTHX_ number_too_long);
10663 /* if we're ok, copy the character */
10668 /* final misplaced underbar check */
10669 if (lastub && s == lastub + 1) {
10670 if (ckWARN(WARN_SYNTAX))
10671 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10674 /* read a decimal portion if there is one. avoid
10675 3..5 being interpreted as the number 3. followed
10678 if (*s == '.' && s[1] != '.') {
10683 if (ckWARN(WARN_SYNTAX))
10684 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10685 "Misplaced _ in number");
10689 /* copy, ignoring underbars, until we run out of digits.
10691 for (; isDIGIT(*s) || *s == '_'; s++) {
10692 /* fixed length buffer check */
10694 Perl_croak(aTHX_ number_too_long);
10696 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
10697 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10698 "Misplaced _ in number");
10704 /* fractional part ending in underbar? */
10705 if (s[-1] == '_') {
10706 if (ckWARN(WARN_SYNTAX))
10707 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10708 "Misplaced _ in number");
10710 if (*s == '.' && isDIGIT(s[1])) {
10711 /* oops, it's really a v-string, but without the "v" */
10717 /* read exponent part, if present */
10718 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
10722 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
10723 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
10725 /* stray preinitial _ */
10727 if (ckWARN(WARN_SYNTAX))
10728 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10729 "Misplaced _ in number");
10733 /* allow positive or negative exponent */
10734 if (*s == '+' || *s == '-')
10737 /* stray initial _ */
10739 if (ckWARN(WARN_SYNTAX))
10740 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10741 "Misplaced _ in number");
10745 /* read digits of exponent */
10746 while (isDIGIT(*s) || *s == '_') {
10749 Perl_croak(aTHX_ number_too_long);
10753 if (((lastub && s == lastub + 1) ||
10754 (!isDIGIT(s[1]) && s[1] != '_'))
10755 && ckWARN(WARN_SYNTAX))
10756 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10757 "Misplaced _ in number");
10764 /* make an sv from the string */
10768 We try to do an integer conversion first if no characters
10769 indicating "float" have been found.
10774 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
10776 if (flags == IS_NUMBER_IN_UV) {
10778 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
10781 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
10782 if (uv <= (UV) IV_MIN)
10783 sv_setiv(sv, -(IV)uv);
10790 /* terminate the string */
10792 nv = Atof(PL_tokenbuf);
10796 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
10797 (PL_hints & HINT_NEW_INTEGER) )
10798 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
10799 (floatit ? "float" : "integer"),
10803 /* if it starts with a v, it could be a v-string */
10806 sv = newSV(5); /* preallocate storage space */
10807 s = scan_vstring(s,sv);
10811 /* make the op for the constant and return */
10814 lvalp->opval = newSVOP(OP_CONST, 0, sv);
10816 lvalp->opval = Nullop;
10822 S_scan_formline(pTHX_ register char *s)
10825 register char *eol;
10827 SV * const stuff = newSVpvs("");
10828 bool needargs = FALSE;
10829 bool eofmt = FALSE;
10831 while (!needargs) {
10833 #ifdef PERL_STRICT_CR
10834 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
10836 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
10838 if (*t == '\n' || t == PL_bufend) {
10843 if (PL_in_eval && !PL_rsfp) {
10844 eol = (char *) memchr(s,'\n',PL_bufend-s);
10849 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10851 for (t = s; t < eol; t++) {
10852 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
10854 goto enough; /* ~~ must be first line in formline */
10856 if (*t == '@' || *t == '^')
10860 sv_catpvn(stuff, s, eol-s);
10861 #ifndef PERL_STRICT_CR
10862 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
10863 char *end = SvPVX(stuff) + SvCUR(stuff);
10866 SvCUR_set(stuff, SvCUR(stuff) - 1);
10875 s = filter_gets(PL_linestr, PL_rsfp, 0);
10876 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
10877 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
10878 PL_last_lop = PL_last_uni = Nullch;
10887 if (SvCUR(stuff)) {
10890 PL_lex_state = LEX_NORMAL;
10891 PL_nextval[PL_nexttoke].ival = 0;
10895 PL_lex_state = LEX_FORMLINE;
10897 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
10899 else if (PL_encoding)
10900 sv_recode_to_utf8(stuff, PL_encoding);
10902 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
10904 PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
10908 SvREFCNT_dec(stuff);
10910 PL_lex_formbrack = 0;
10922 PL_cshlen = strlen(PL_cshname);
10927 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
10930 const I32 oldsavestack_ix = PL_savestack_ix;
10931 CV* const outsidecv = PL_compcv;
10934 assert(SvTYPE(PL_compcv) == SVt_PVCV);
10936 SAVEI32(PL_subline);
10937 save_item(PL_subname);
10938 SAVESPTR(PL_compcv);
10940 PL_compcv = (CV*)newSV(0);
10941 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
10942 CvFLAGS(PL_compcv) |= flags;
10944 PL_subline = CopLINE(PL_curcop);
10945 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
10946 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
10947 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
10949 return oldsavestack_ix;
10953 #pragma segment Perl_yylex
10956 Perl_yywarn(pTHX_ const char *s)
10959 PL_in_eval |= EVAL_WARNONLY;
10961 PL_in_eval &= ~EVAL_WARNONLY;
10966 Perl_yyerror(pTHX_ const char *s)
10969 const char *where = NULL;
10970 const char *context = NULL;
10974 if (!yychar || (yychar == ';' && !PL_rsfp))
10976 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
10977 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
10978 PL_oldbufptr != PL_bufptr) {
10981 The code below is removed for NetWare because it abends/crashes on NetWare
10982 when the script has error such as not having the closing quotes like:
10983 if ($var eq "value)
10984 Checking of white spaces is anyway done in NetWare code.
10987 while (isSPACE(*PL_oldoldbufptr))
10990 context = PL_oldoldbufptr;
10991 contlen = PL_bufptr - PL_oldoldbufptr;
10993 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
10994 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
10997 The code below is removed for NetWare because it abends/crashes on NetWare
10998 when the script has error such as not having the closing quotes like:
10999 if ($var eq "value)
11000 Checking of white spaces is anyway done in NetWare code.
11003 while (isSPACE(*PL_oldbufptr))
11006 context = PL_oldbufptr;
11007 contlen = PL_bufptr - PL_oldbufptr;
11009 else if (yychar > 255)
11010 where = "next token ???";
11011 else if (yychar == -2) { /* YYEMPTY */
11012 if (PL_lex_state == LEX_NORMAL ||
11013 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
11014 where = "at end of line";
11015 else if (PL_lex_inpat)
11016 where = "within pattern";
11018 where = "within string";
11021 SV * const where_sv = sv_2mortal(newSVpvs("next char "));
11023 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
11024 else if (isPRINT_LC(yychar))
11025 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
11027 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
11028 where = SvPVX_const(where_sv);
11030 msg = sv_2mortal(newSVpv(s, 0));
11031 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
11032 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
11034 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
11036 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
11037 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
11038 Perl_sv_catpvf(aTHX_ msg,
11039 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
11040 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
11043 if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
11044 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg);
11047 if (PL_error_count >= 10) {
11048 if (PL_in_eval && SvCUR(ERRSV))
11049 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
11050 ERRSV, OutCopFILE(PL_curcop));
11052 Perl_croak(aTHX_ "%s has too many errors.\n",
11053 OutCopFILE(PL_curcop));
11056 PL_in_my_stash = NULL;
11060 #pragma segment Main
11064 S_swallow_bom(pTHX_ U8 *s)
11067 const STRLEN slen = SvCUR(PL_linestr);
11070 if (s[1] == 0xFE) {
11071 /* UTF-16 little-endian? (or UTF32-LE?) */
11072 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
11073 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
11074 #ifndef PERL_NO_UTF16_FILTER
11075 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
11078 if (PL_bufend > (char*)s) {
11082 filter_add(utf16rev_textfilter, NULL);
11083 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
11084 utf16_to_utf8_reversed(s, news,
11085 PL_bufend - (char*)s - 1,
11087 sv_setpvn(PL_linestr, (const char*)news, newlen);
11089 SvUTF8_on(PL_linestr);
11090 s = (U8*)SvPVX(PL_linestr);
11091 PL_bufend = SvPVX(PL_linestr) + newlen;
11094 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
11099 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
11100 #ifndef PERL_NO_UTF16_FILTER
11101 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
11104 if (PL_bufend > (char *)s) {
11108 filter_add(utf16_textfilter, NULL);
11109 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
11110 utf16_to_utf8(s, news,
11111 PL_bufend - (char*)s,
11113 sv_setpvn(PL_linestr, (const char*)news, newlen);
11115 SvUTF8_on(PL_linestr);
11116 s = (U8*)SvPVX(PL_linestr);
11117 PL_bufend = SvPVX(PL_linestr) + newlen;
11120 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
11125 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
11126 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
11127 s += 3; /* UTF-8 */
11133 if (s[2] == 0xFE && s[3] == 0xFF) {
11134 /* UTF-32 big-endian */
11135 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
11138 else if (s[2] == 0 && s[3] != 0) {
11141 * are a good indicator of UTF-16BE. */
11142 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
11147 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
11150 * are a good indicator of UTF-16LE. */
11151 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
11160 * Restore a source filter.
11164 restore_rsfp(pTHX_ void *f)
11167 PerlIO * const fp = (PerlIO*)f;
11169 if (PL_rsfp == PerlIO_stdin())
11170 PerlIO_clearerr(PL_rsfp);
11171 else if (PL_rsfp && (PL_rsfp != fp))
11172 PerlIO_close(PL_rsfp);
11176 #ifndef PERL_NO_UTF16_FILTER
11178 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
11181 const STRLEN old = SvCUR(sv);
11182 const I32 count = FILTER_READ(idx+1, sv, maxlen);
11183 DEBUG_P(PerlIO_printf(Perl_debug_log,
11184 "utf16_textfilter(%p): %d %d (%d)\n",
11185 utf16_textfilter, idx, maxlen, (int) count));
11189 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
11190 Copy(SvPVX_const(sv), tmps, old, char);
11191 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
11192 SvCUR(sv) - old, &newlen);
11193 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
11195 DEBUG_P({sv_dump(sv);});
11200 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
11203 const STRLEN old = SvCUR(sv);
11204 const I32 count = FILTER_READ(idx+1, sv, maxlen);
11205 DEBUG_P(PerlIO_printf(Perl_debug_log,
11206 "utf16rev_textfilter(%p): %d %d (%d)\n",
11207 utf16rev_textfilter, idx, maxlen, (int) count));
11211 Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
11212 Copy(SvPVX_const(sv), tmps, old, char);
11213 utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
11214 SvCUR(sv) - old, &newlen);
11215 sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
11217 DEBUG_P({ sv_dump(sv); });
11223 Returns a pointer to the next character after the parsed
11224 vstring, as well as updating the passed in sv.
11226 Function must be called like
11229 s = scan_vstring(s,sv);
11231 The sv should already be large enough to store the vstring
11232 passed in, for performance reasons.
11237 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
11240 const char *pos = s;
11241 const char *start = s;
11242 if (*pos == 'v') pos++; /* get past 'v' */
11243 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
11245 if ( *pos != '.') {
11246 /* this may not be a v-string if followed by => */
11247 const char *next = pos;
11248 while (next < PL_bufend && isSPACE(*next))
11250 if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
11251 /* return string not v-string */
11252 sv_setpvn(sv,(char *)s,pos-s);
11253 return (char *)pos;
11257 if (!isALPHA(*pos)) {
11258 U8 tmpbuf[UTF8_MAXBYTES+1];
11260 if (*s == 'v') s++; /* get past 'v' */
11262 sv_setpvn(sv, "", 0);
11268 /* this is atoi() that tolerates underscores */
11269 const char *end = pos;
11271 while (--end >= s) {
11276 rev += (*end - '0') * mult;
11278 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
11279 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11280 "Integer overflow in decimal number");
11284 if (rev > 0x7FFFFFFF)
11285 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
11287 /* Append native character for the rev point */
11288 tmpend = uvchr_to_utf8(tmpbuf, rev);
11289 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
11290 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
11292 if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
11298 while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
11302 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
11310 * c-indentation-style: bsd
11311 * c-basic-offset: 4
11312 * indent-tabs-mode: t
11315 * ex: set ts=8 sts=4 sw=4 noet: