3 * Copyright (c) 1991-2001, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "It all comes from here, the stench and the peril." --Frodo
15 * This file is the lexer for Perl. It's closely linked to the
18 * The main routine is yylex(), which returns the next token.
22 #define PERL_IN_TOKE_C
25 #define yychar PL_yychar
26 #define yylval PL_yylval
28 static char ident_too_long[] = "Identifier too long";
30 static void restore_rsfp(pTHXo_ void *f);
31 #ifndef PERL_NO_UTF16_FILTER
32 static I32 utf16_textfilter(pTHXo_ int idx, SV *sv, int maxlen);
33 static I32 utf16rev_textfilter(pTHXo_ int idx, SV *sv, int maxlen);
36 #define XFAKEBRACK 128
40 /* For now 'use utf8' does not affect tokenizer on EBCDIC */
41 #define UTF (PL_linestr && DO_UTF8(PL_linestr))
43 #define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
46 /* In variables named $^X, these are the legal values for X.
47 * 1999-02-27 mjd-perl-patch@plover.com */
48 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
50 /* On MacOS, respect nonbreaking spaces */
51 #ifdef MACOS_TRADITIONAL
52 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
54 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
57 /* LEX_* are values for PL_lex_state, the state of the lexer.
58 * They are arranged oddly so that the guard on the switch statement
59 * can get by with a single comparison (if the compiler is smart enough).
62 /* #define LEX_NOTPARSING 11 is done in perl.h. */
65 #define LEX_INTERPNORMAL 9
66 #define LEX_INTERPCASEMOD 8
67 #define LEX_INTERPPUSH 7
68 #define LEX_INTERPSTART 6
69 #define LEX_INTERPEND 5
70 #define LEX_INTERPENDMAYBE 4
71 #define LEX_INTERPCONCAT 3
72 #define LEX_INTERPCONST 2
73 #define LEX_FORMLINE 1
74 #define LEX_KNOWNEXT 0
82 # define YYMAXLEVEL 100
84 YYSTYPE* yylval_pointer[YYMAXLEVEL];
85 int* yychar_pointer[YYMAXLEVEL];
89 # define yylval (*yylval_pointer[yyactlevel])
90 # define yychar (*yychar_pointer[yyactlevel])
91 # define PERL_YYLEX_PARAM yylval_pointer[yyactlevel],yychar_pointer[yyactlevel]
93 # define yylex() Perl_yylex_r(aTHX_ yylval_pointer[yyactlevel],yychar_pointer[yyactlevel])
98 /* CLINE is a macro that ensures PL_copline has a sane value */
103 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
106 * Convenience functions to return different tokens and prime the
107 * lexer for the next token. They all take an argument.
109 * TOKEN : generic token (used for '(', DOLSHARP, etc)
110 * OPERATOR : generic operator
111 * AOPERATOR : assignment operator
112 * PREBLOCK : beginning the block after an if, while, foreach, ...
113 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
114 * PREREF : *EXPR where EXPR is not a simple identifier
115 * TERM : expression term
116 * LOOPX : loop exiting command (goto, last, dump, etc)
117 * FTST : file test operator
118 * FUN0 : zero-argument function
119 * FUN1 : not used, except for not, which isn't a UNIOP
120 * BOop : bitwise or or xor
122 * SHop : shift operator
123 * PWop : power operator
124 * PMop : pattern-matching operator
125 * Aop : addition-level operator
126 * Mop : multiplication-level operator
127 * Eop : equality-testing operator
128 * Rop : relational operator <= != gt
130 * Also see LOP and lop() below.
133 /* Note that REPORT() and REPORT2() will be expressions that supply
134 * their own trailing comma, not suitable for statements as such. */
135 #ifdef DEBUGGING /* Serve -DT. */
136 # define REPORT(x,retval) tokereport(x,s,(int)retval),
137 # define REPORT2(x,retval) tokereport(x,s, yylval.ival),
139 # define REPORT(x,retval)
140 # define REPORT2(x,retval)
143 #define TOKEN(retval) return (REPORT2("token",retval) PL_bufptr = s,(int)retval)
144 #define OPERATOR(retval) return (REPORT2("operator",retval) PL_expect = XTERM, PL_bufptr = s,(int)retval)
145 #define AOPERATOR(retval) return ao((REPORT2("aop",retval) PL_expect = XTERM, PL_bufptr = s,(int)retval))
146 #define PREBLOCK(retval) return (REPORT2("preblock",retval) PL_expect = XBLOCK,PL_bufptr = s,(int)retval)
147 #define PRETERMBLOCK(retval) return (REPORT2("pretermblock",retval) PL_expect = XTERMBLOCK,PL_bufptr = s,(int)retval)
148 #define PREREF(retval) return (REPORT2("preref",retval) PL_expect = XREF,PL_bufptr = s,(int)retval)
149 #define TERM(retval) return (CLINE, REPORT2("term",retval) PL_expect = XOPERATOR, PL_bufptr = s,(int)retval)
150 #define LOOPX(f) return(yylval.ival=f, REPORT("loopx",f) PL_expect = XTERM,PL_bufptr = s,(int)LOOPEX)
151 #define FTST(f) return(yylval.ival=f, REPORT("ftst",f) PL_expect = XTERM,PL_bufptr = s,(int)UNIOP)
152 #define FUN0(f) return(yylval.ival = f, REPORT("fun0",f) PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC0)
153 #define FUN1(f) return(yylval.ival = f, REPORT("fun1",f) PL_expect = XOPERATOR,PL_bufptr = s,(int)FUNC1)
154 #define BOop(f) return ao((yylval.ival=f, REPORT("bitorop",f) PL_expect = XTERM,PL_bufptr = s,(int)BITOROP))
155 #define BAop(f) return ao((yylval.ival=f, REPORT("bitandop",f) PL_expect = XTERM,PL_bufptr = s,(int)BITANDOP))
156 #define SHop(f) return ao((yylval.ival=f, REPORT("shiftop",f) PL_expect = XTERM,PL_bufptr = s,(int)SHIFTOP))
157 #define PWop(f) return ao((yylval.ival=f, REPORT("powop",f) PL_expect = XTERM,PL_bufptr = s,(int)POWOP))
158 #define PMop(f) return(yylval.ival=f, REPORT("matchop",f) PL_expect = XTERM,PL_bufptr = s,(int)MATCHOP)
159 #define Aop(f) return ao((yylval.ival=f, REPORT("add",f) PL_expect = XTERM,PL_bufptr = s,(int)ADDOP))
160 #define Mop(f) return ao((yylval.ival=f, REPORT("mul",f) PL_expect = XTERM,PL_bufptr = s,(int)MULOP))
161 #define Eop(f) return(yylval.ival=f, REPORT("eq",f) PL_expect = XTERM,PL_bufptr = s,(int)EQOP)
162 #define Rop(f) return(yylval.ival=f, REPORT("rel",f) PL_expect = XTERM,PL_bufptr = s,(int)RELOP)
164 /* This bit of chicanery makes a unary function followed by
165 * a parenthesis into a function with one argument, highest precedence.
167 #define UNI(f) return(yylval.ival = f, \
171 PL_last_uni = PL_oldbufptr, \
172 PL_last_lop_op = f, \
173 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
175 #define UNIBRACK(f) return(yylval.ival = f, \
178 PL_last_uni = PL_oldbufptr, \
179 (*s == '(' || (s = skipspace(s), *s == '(') ? (int)FUNC1 : (int)UNIOP) )
181 /* grandfather return to old style */
182 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
187 S_tokereport(pTHX_ char *thing, char* s, I32 rv)
190 SV* report = newSVpv(thing, 0);
191 Perl_sv_catpvf(aTHX_ report, ":line %d:%"IVdf":", CopLINE(PL_curcop),
194 if (s - PL_bufptr > 0)
195 sv_catpvn(report, PL_bufptr, s - PL_bufptr);
197 if (PL_oldbufptr && *PL_oldbufptr)
198 sv_catpv(report, PL_tokenbuf);
200 PerlIO_printf(Perl_debug_log, "### %s\n", SvPV_nolen(report));
209 * This subroutine detects &&= and ||= and turns an ANDAND or OROR
210 * into an OP_ANDASSIGN or OP_ORASSIGN
214 S_ao(pTHX_ int toketype)
216 if (*PL_bufptr == '=') {
218 if (toketype == ANDAND)
219 yylval.ival = OP_ANDASSIGN;
220 else if (toketype == OROR)
221 yylval.ival = OP_ORASSIGN;
229 * When Perl expects an operator and finds something else, no_op
230 * prints the warning. It always prints "<something> found where
231 * operator expected. It prints "Missing semicolon on previous line?"
232 * if the surprise occurs at the start of the line. "do you need to
233 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
234 * where the compiler doesn't know if foo is a method call or a function.
235 * It prints "Missing operator before end of line" if there's nothing
236 * after the missing operator, or "... before <...>" if there is something
237 * after the missing operator.
241 S_no_op(pTHX_ char *what, char *s)
243 char *oldbp = PL_bufptr;
244 bool is_first = (PL_oldbufptr == PL_linestart);
250 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
252 Perl_warn(aTHX_ "\t(Missing semicolon on previous line?)\n");
253 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
255 for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
256 if (t < PL_bufptr && isSPACE(*t))
257 Perl_warn(aTHX_ "\t(Do you need to predeclare %.*s?)\n",
258 t - PL_oldoldbufptr, PL_oldoldbufptr);
262 Perl_warn(aTHX_ "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
269 * Complain about missing quote/regexp/heredoc terminator.
270 * If it's called with (char *)NULL then it cauterizes the line buffer.
271 * If we're in a delimited string and the delimiter is a control
272 * character, it's reformatted into a two-char sequence like ^C.
277 S_missingterm(pTHX_ char *s)
282 char *nl = strrchr(s,'\n');
288 iscntrl(PL_multi_close)
290 PL_multi_close < 32 || PL_multi_close == 127
294 tmpbuf[1] = toCTRL(PL_multi_close);
300 *tmpbuf = PL_multi_close;
304 q = strchr(s,'"') ? '\'' : '"';
305 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
313 Perl_deprecate(pTHX_ char *s)
315 if (ckWARN(WARN_DEPRECATED))
316 Perl_warner(aTHX_ WARN_DEPRECATED, "Use of %s is deprecated", s);
321 * Deprecate a comma-less variable list.
327 deprecate("comma-less variable list");
331 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
332 * utf16-to-utf8-reversed.
335 #ifdef PERL_CR_FILTER
339 register char *s = SvPVX(sv);
340 register char *e = s + SvCUR(sv);
341 /* outer loop optimized to do nothing if there are no CR-LFs */
343 if (*s++ == '\r' && *s == '\n') {
344 /* hit a CR-LF, need to copy the rest */
345 register char *d = s - 1;
348 if (*s == '\r' && s[1] == '\n')
359 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
361 I32 count = FILTER_READ(idx+1, sv, maxlen);
362 if (count > 0 && !maxlen)
370 * Initialize variables. Uses the Perl save_stack to save its state (for
371 * recursive calls to the parser).
375 Perl_lex_start(pTHX_ SV *line)
380 SAVEI32(PL_lex_dojoin);
381 SAVEI32(PL_lex_brackets);
382 SAVEI32(PL_lex_casemods);
383 SAVEI32(PL_lex_starts);
384 SAVEI32(PL_lex_state);
385 SAVEVPTR(PL_lex_inpat);
386 SAVEI32(PL_lex_inwhat);
387 if (PL_lex_state == LEX_KNOWNEXT) {
388 I32 toke = PL_nexttoke;
389 while (--toke >= 0) {
390 SAVEI32(PL_nexttype[toke]);
391 SAVEVPTR(PL_nextval[toke]);
393 SAVEI32(PL_nexttoke);
395 SAVECOPLINE(PL_curcop);
398 SAVEPPTR(PL_oldbufptr);
399 SAVEPPTR(PL_oldoldbufptr);
400 SAVEPPTR(PL_last_lop);
401 SAVEPPTR(PL_last_uni);
402 SAVEPPTR(PL_linestart);
403 SAVESPTR(PL_linestr);
404 SAVEPPTR(PL_lex_brackstack);
405 SAVEPPTR(PL_lex_casestack);
406 SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
407 SAVESPTR(PL_lex_stuff);
408 SAVEI32(PL_lex_defer);
409 SAVEI32(PL_sublex_info.sub_inwhat);
410 SAVESPTR(PL_lex_repl);
412 SAVEINT(PL_lex_expect);
414 PL_lex_state = LEX_NORMAL;
418 New(899, PL_lex_brackstack, 120, char);
419 New(899, PL_lex_casestack, 12, char);
420 SAVEFREEPV(PL_lex_brackstack);
421 SAVEFREEPV(PL_lex_casestack);
423 *PL_lex_casestack = '\0';
426 PL_lex_stuff = Nullsv;
427 PL_lex_repl = Nullsv;
431 PL_sublex_info.sub_inwhat = 0;
433 if (SvREADONLY(PL_linestr))
434 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
435 s = SvPV(PL_linestr, len);
436 if (len && s[len-1] != ';') {
437 if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
438 PL_linestr = sv_2mortal(newSVsv(PL_linestr));
439 sv_catpvn(PL_linestr, "\n;", 2);
441 SvTEMP_off(PL_linestr);
442 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
443 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
444 PL_last_lop = PL_last_uni = Nullch;
446 PL_rs = newSVpvn("\n", 1);
452 * Finalizer for lexing operations. Must be called when the parser is
453 * done with the lexer.
459 PL_doextract = FALSE;
464 * This subroutine has nothing to do with tilting, whether at windmills
465 * or pinball tables. Its name is short for "increment line". It
466 * increments the current line number in CopLINE(PL_curcop) and checks
467 * to see whether the line starts with a comment of the form
468 * # line 500 "foo.pm"
469 * If so, it sets the current line number and file to the values in the comment.
473 S_incline(pTHX_ char *s)
480 CopLINE_inc(PL_curcop);
483 while (SPACE_OR_TAB(*s)) s++;
484 if (strnEQ(s, "line", 4))
488 if (SPACE_OR_TAB(*s))
492 while (SPACE_OR_TAB(*s)) s++;
498 while (SPACE_OR_TAB(*s))
500 if (*s == '"' && (t = strchr(s+1, '"'))) {
505 for (t = s; !isSPACE(*t); t++) ;
508 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
510 if (*e != '\n' && *e != '\0')
511 return; /* false alarm */
517 Safefree(CopFILE(PL_curcop));
519 SvREFCNT_dec(CopFILEGV(PL_curcop));
521 CopFILE_set(PL_curcop, s);
524 CopLINE_set(PL_curcop, atoi(n)-1);
529 * Called to gobble the appropriate amount and type of whitespace.
530 * Skips comments as well.
534 S_skipspace(pTHX_ register char *s)
536 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
537 while (s < PL_bufend && SPACE_OR_TAB(*s))
543 SSize_t oldprevlen, oldoldprevlen;
544 SSize_t oldloplen = 0, oldunilen = 0;
545 while (s < PL_bufend && isSPACE(*s)) {
546 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
551 if (s < PL_bufend && *s == '#') {
552 while (s < PL_bufend && *s != '\n')
556 if (PL_in_eval && !PL_rsfp) {
563 /* only continue to recharge the buffer if we're at the end
564 * of the buffer, we're not reading from a source filter, and
565 * we're in normal lexing mode
567 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
568 PL_lex_state == LEX_FORMLINE)
571 /* try to recharge the buffer */
572 if ((s = filter_gets(PL_linestr, PL_rsfp,
573 (prevlen = SvCUR(PL_linestr)))) == Nullch)
575 /* end of file. Add on the -p or -n magic */
576 if (PL_minus_n || PL_minus_p) {
577 sv_setpv(PL_linestr,PL_minus_p ?
578 ";}continue{print or die qq(-p destination: $!\\n)" :
580 sv_catpv(PL_linestr,";}");
581 PL_minus_n = PL_minus_p = 0;
584 sv_setpv(PL_linestr,";");
586 /* reset variables for next time we lex */
587 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
589 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
590 PL_last_lop = PL_last_uni = Nullch;
592 /* Close the filehandle. Could be from -P preprocessor,
593 * STDIN, or a regular file. If we were reading code from
594 * STDIN (because the commandline held no -e or filename)
595 * then we don't close it, we reset it so the code can
596 * read from STDIN too.
599 if (PL_preprocess && !PL_in_eval)
600 (void)PerlProc_pclose(PL_rsfp);
601 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
602 PerlIO_clearerr(PL_rsfp);
604 (void)PerlIO_close(PL_rsfp);
609 /* not at end of file, so we only read another line */
610 /* make corresponding updates to old pointers, for yyerror() */
611 oldprevlen = PL_oldbufptr - PL_bufend;
612 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
614 oldunilen = PL_last_uni - PL_bufend;
616 oldloplen = PL_last_lop - PL_bufend;
617 PL_linestart = PL_bufptr = s + prevlen;
618 PL_bufend = s + SvCUR(PL_linestr);
620 PL_oldbufptr = s + oldprevlen;
621 PL_oldoldbufptr = s + oldoldprevlen;
623 PL_last_uni = s + oldunilen;
625 PL_last_lop = s + oldloplen;
628 /* debugger active and we're not compiling the debugger code,
629 * so store the line into the debugger's array of lines
631 if (PERLDB_LINE && PL_curstash != PL_debstash) {
632 SV *sv = NEWSV(85,0);
634 sv_upgrade(sv, SVt_PVMG);
635 sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
636 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
643 * Check the unary operators to ensure there's no ambiguity in how they're
644 * used. An ambiguous piece of code would be:
646 * This doesn't mean rand() + 5. Because rand() is a unary operator,
647 * the +5 is its argument.
656 if (PL_oldoldbufptr != PL_last_uni)
658 while (isSPACE(*PL_last_uni))
660 for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
661 if ((t = strchr(s, '(')) && t < PL_bufptr)
663 if (ckWARN_d(WARN_AMBIGUOUS)){
666 Perl_warner(aTHX_ WARN_AMBIGUOUS,
667 "Warning: Use of \"%s\" without parens is ambiguous",
673 /* workaround to replace the UNI() macro with a function. Only the
674 * hints/uts.sh file mentions this. Other comments elsewhere in the
675 * source indicate Microport Unix might need it too.
681 #define UNI(f) return uni(f,s)
684 S_uni(pTHX_ I32 f, char *s)
689 PL_last_uni = PL_oldbufptr;
700 #endif /* CRIPPLED_CC */
703 * LOP : macro to build a list operator. Its behaviour has been replaced
704 * with a subroutine, S_lop() for which LOP is just another name.
707 #define LOP(f,x) return lop(f,x,s)
711 * Build a list operator (or something that might be one). The rules:
712 * - if we have a next token, then it's a list operator [why?]
713 * - if the next thing is an opening paren, then it's a function
714 * - else it's a list operator
718 S_lop(pTHX_ I32 f, int x, char *s)
725 PL_last_lop = PL_oldbufptr;
740 * When the lexer realizes it knows the next token (for instance,
741 * it is reordering tokens for the parser) then it can call S_force_next
742 * to know what token to return the next time the lexer is called. Caller
743 * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer
744 * handles the token correctly.
748 S_force_next(pTHX_ I32 type)
750 PL_nexttype[PL_nexttoke] = type;
752 if (PL_lex_state != LEX_KNOWNEXT) {
753 PL_lex_defer = PL_lex_state;
754 PL_lex_expect = PL_expect;
755 PL_lex_state = LEX_KNOWNEXT;
761 * When the lexer knows the next thing is a word (for instance, it has
762 * just seen -> and it knows that the next char is a word char, then
763 * it calls S_force_word to stick the next word into the PL_next lookahead.
766 * char *start : buffer position (must be within PL_linestr)
767 * int token : PL_next will be this type of bare word (e.g., METHOD,WORD)
768 * int check_keyword : if true, Perl checks to make sure the word isn't
769 * a keyword (do this if the word is a label, e.g. goto FOO)
770 * int allow_pack : if true, : characters will also be allowed (require,
772 * int allow_initial_tick : used by the "sub" lexer only.
776 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
781 start = skipspace(start);
783 if (isIDFIRST_lazy_if(s,UTF) ||
784 (allow_pack && *s == ':') ||
785 (allow_initial_tick && *s == '\'') )
787 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
788 if (check_keyword && keyword(PL_tokenbuf, len))
790 if (token == METHOD) {
795 PL_expect = XOPERATOR;
798 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(PL_tokenbuf,0));
799 PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
807 * Called when the lexer wants $foo *foo &foo etc, but the program
808 * text only contains the "foo" portion. The first argument is a pointer
809 * to the "foo", and the second argument is the type symbol to prefix.
810 * Forces the next token to be a "WORD".
811 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
815 S_force_ident(pTHX_ register char *s, int kind)
818 OP* o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
819 PL_nextval[PL_nexttoke].opval = o;
822 o->op_private = OPpCONST_ENTERED;
823 /* XXX see note in pp_entereval() for why we forgo typo
824 warnings if the symbol must be introduced in an eval.
826 gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
827 kind == '$' ? SVt_PV :
828 kind == '@' ? SVt_PVAV :
829 kind == '%' ? SVt_PVHV :
837 Perl_str_to_version(pTHX_ SV *sv)
842 char *start = SvPVx(sv,len);
843 bool utf = SvUTF8(sv) ? TRUE : FALSE;
844 char *end = start + len;
845 while (start < end) {
849 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
854 retval += ((NV)n)/nshift;
863 * Forces the next token to be a version number.
867 S_force_version(pTHX_ char *s)
869 OP *version = Nullop;
878 for (; isDIGIT(*d) || *d == '_' || *d == '.'; d++);
879 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
881 s = scan_num(s, &yylval);
882 version = yylval.opval;
883 ver = cSVOPx(version)->op_sv;
884 if (SvPOK(ver) && !SvNIOK(ver)) {
885 (void)SvUPGRADE(ver, SVt_PVNV);
886 SvNVX(ver) = str_to_version(ver);
887 SvNOK_on(ver); /* hint that it is a version */
892 /* NOTE: The parser sees the package name and the VERSION swapped */
893 PL_nextval[PL_nexttoke].opval = version;
901 * Tokenize a quoted string passed in as an SV. It finds the next
902 * chunk, up to end of string or a backslash. It may make a new
903 * SV containing that chunk (if HINT_NEW_STRING is on). It also
908 S_tokeq(pTHX_ SV *sv)
919 s = SvPV_force(sv, len);
920 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
923 while (s < send && *s != '\\')
928 if ( PL_hints & HINT_NEW_STRING ) {
929 pv = sv_2mortal(newSVpvn(SvPVX(pv), len));
935 if (s + 1 < send && (s[1] == '\\'))
936 s++; /* all that, just for this */
941 SvCUR_set(sv, d - SvPVX(sv));
943 if ( PL_hints & HINT_NEW_STRING )
944 return new_constant(NULL, 0, "q", sv, pv, "q");
949 * Now come three functions related to double-quote context,
950 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
951 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
952 * interact with PL_lex_state, and create fake ( ... ) argument lists
953 * to handle functions and concatenation.
954 * They assume that whoever calls them will be setting up a fake
955 * join call, because each subthing puts a ',' after it. This lets
958 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
960 * (I'm not sure whether the spurious commas at the end of lcfirst's
961 * arguments and join's arguments are created or not).
966 * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
968 * Pattern matching will set PL_lex_op to the pattern-matching op to
969 * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
971 * OP_CONST and OP_READLINE are easy--just make the new op and return.
973 * Everything else becomes a FUNC.
975 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
976 * had an OP_CONST or OP_READLINE). This just sets us up for a
977 * call to S_sublex_push().
983 register I32 op_type = yylval.ival;
985 if (op_type == OP_NULL) {
986 yylval.opval = PL_lex_op;
990 if (op_type == OP_CONST || op_type == OP_READLINE) {
991 SV *sv = tokeq(PL_lex_stuff);
993 if (SvTYPE(sv) == SVt_PVIV) {
994 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1000 nsv = newSVpvn(p, len);
1006 yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1007 PL_lex_stuff = Nullsv;
1011 PL_sublex_info.super_state = PL_lex_state;
1012 PL_sublex_info.sub_inwhat = op_type;
1013 PL_sublex_info.sub_op = PL_lex_op;
1014 PL_lex_state = LEX_INTERPPUSH;
1018 yylval.opval = PL_lex_op;
1028 * Create a new scope to save the lexing state. The scope will be
1029 * ended in S_sublex_done. Returns a '(', starting the function arguments
1030 * to the uc, lc, etc. found before.
1031 * Sets PL_lex_state to LEX_INTERPCONCAT.
1039 PL_lex_state = PL_sublex_info.super_state;
1040 SAVEI32(PL_lex_dojoin);
1041 SAVEI32(PL_lex_brackets);
1042 SAVEI32(PL_lex_casemods);
1043 SAVEI32(PL_lex_starts);
1044 SAVEI32(PL_lex_state);
1045 SAVEVPTR(PL_lex_inpat);
1046 SAVEI32(PL_lex_inwhat);
1047 SAVECOPLINE(PL_curcop);
1048 SAVEPPTR(PL_bufptr);
1049 SAVEPPTR(PL_bufend);
1050 SAVEPPTR(PL_oldbufptr);
1051 SAVEPPTR(PL_oldoldbufptr);
1052 SAVEPPTR(PL_last_lop);
1053 SAVEPPTR(PL_last_uni);
1054 SAVEPPTR(PL_linestart);
1055 SAVESPTR(PL_linestr);
1056 SAVEPPTR(PL_lex_brackstack);
1057 SAVEPPTR(PL_lex_casestack);
1059 PL_linestr = PL_lex_stuff;
1060 PL_lex_stuff = Nullsv;
1062 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1063 = SvPVX(PL_linestr);
1064 PL_bufend += SvCUR(PL_linestr);
1065 PL_last_lop = PL_last_uni = Nullch;
1066 SAVEFREESV(PL_linestr);
1068 PL_lex_dojoin = FALSE;
1069 PL_lex_brackets = 0;
1070 New(899, PL_lex_brackstack, 120, char);
1071 New(899, PL_lex_casestack, 12, char);
1072 SAVEFREEPV(PL_lex_brackstack);
1073 SAVEFREEPV(PL_lex_casestack);
1074 PL_lex_casemods = 0;
1075 *PL_lex_casestack = '\0';
1077 PL_lex_state = LEX_INTERPCONCAT;
1078 CopLINE_set(PL_curcop, PL_multi_start);
1080 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1081 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1082 PL_lex_inpat = PL_sublex_info.sub_op;
1084 PL_lex_inpat = Nullop;
1091 * Restores lexer state after a S_sublex_push.
1097 if (!PL_lex_starts++) {
1098 SV *sv = newSVpvn("",0);
1099 if (SvUTF8(PL_linestr))
1101 PL_expect = XOPERATOR;
1102 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1106 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1107 PL_lex_state = LEX_INTERPCASEMOD;
1111 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1112 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1113 PL_linestr = PL_lex_repl;
1115 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1116 PL_bufend += SvCUR(PL_linestr);
1117 PL_last_lop = PL_last_uni = Nullch;
1118 SAVEFREESV(PL_linestr);
1119 PL_lex_dojoin = FALSE;
1120 PL_lex_brackets = 0;
1121 PL_lex_casemods = 0;
1122 *PL_lex_casestack = '\0';
1124 if (SvEVALED(PL_lex_repl)) {
1125 PL_lex_state = LEX_INTERPNORMAL;
1127 /* we don't clear PL_lex_repl here, so that we can check later
1128 whether this is an evalled subst; that means we rely on the
1129 logic to ensure sublex_done() is called again only via the
1130 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1133 PL_lex_state = LEX_INTERPCONCAT;
1134 PL_lex_repl = Nullsv;
1140 PL_bufend = SvPVX(PL_linestr);
1141 PL_bufend += SvCUR(PL_linestr);
1142 PL_expect = XOPERATOR;
1143 PL_sublex_info.sub_inwhat = 0;
1151 Extracts a pattern, double-quoted string, or transliteration. This
1154 It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1155 processing a pattern (PL_lex_inpat is true), a transliteration
1156 (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1158 Returns a pointer to the character scanned up to. Iff this is
1159 advanced from the start pointer supplied (ie if anything was
1160 successfully parsed), will leave an OP for the substring scanned
1161 in yylval. Caller must intuit reason for not parsing further
1162 by looking at the next characters herself.
1166 double-quoted style: \r and \n
1167 regexp special ones: \D \s
1169 backrefs: \1 (deprecated in substitution replacements)
1170 case and quoting: \U \Q \E
1171 stops on @ and $, but not for $ as tail anchor
1173 In transliterations:
1174 characters are VERY literal, except for - not at the start or end
1175 of the string, which indicates a range. scan_const expands the
1176 range to the full set of intermediate characters.
1178 In double-quoted strings:
1180 double-quoted style: \r and \n
1182 backrefs: \1 (deprecated)
1183 case and quoting: \U \Q \E
1186 scan_const does *not* construct ops to handle interpolated strings.
1187 It stops processing as soon as it finds an embedded $ or @ variable
1188 and leaves it to the caller to work out what's going on.
1190 @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @:foo.
1192 $ in pattern could be $foo or could be tail anchor. Assumption:
1193 it's a tail anchor if $ is the last thing in the string, or if it's
1194 followed by one of ")| \n\t"
1196 \1 (backreferences) are turned into $1
1198 The structure of the code is
1199 while (there's a character to process) {
1200 handle transliteration ranges
1201 skip regexp comments
1202 skip # initiated comments in //x patterns
1203 check for embedded @foo
1204 check for embedded scalars
1206 leave intact backslashes from leave (below)
1207 deprecate \1 in strings and sub replacements
1208 handle string-changing backslashes \l \U \Q \E, etc.
1209 switch (what was escaped) {
1210 handle - in a transliteration (becomes a literal -)
1211 handle \132 octal characters
1212 handle 0x15 hex characters
1213 handle \cV (control V)
1214 handle printf backslashes (\f, \r, \n, etc)
1216 } (end if backslash)
1217 } (end while character to read)
1222 S_scan_const(pTHX_ char *start)
1224 register char *send = PL_bufend; /* end of the constant */
1225 SV *sv = NEWSV(93, send - start); /* sv for the constant */
1226 register char *s = start; /* start of the constant */
1227 register char *d = SvPVX(sv); /* destination for copies */
1228 bool dorange = FALSE; /* are we in a translit range? */
1229 bool didrange = FALSE; /* did we just finish a range? */
1230 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
1231 I32 this_utf8 = UTF; /* The source string is assumed to be UTF8 */
1234 const char *leaveit = /* set of acceptably-backslashed characters */
1236 ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxcz0123456789[{]} \t\n\r\f\v#"
1239 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1240 /* If we are doing a trans and we know we want UTF8 set expectation */
1241 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1242 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1246 while (s < send || dorange) {
1247 /* get transliterations out of the way (they're most literal) */
1248 if (PL_lex_inwhat == OP_TRANS) {
1249 /* expand a range A-Z to the full set of characters. AIE! */
1251 I32 i; /* current expanded character */
1252 I32 min; /* first character in range */
1253 I32 max; /* last character in range */
1256 char *c = (char*)utf8_hop((U8*)d, -1);
1260 *c = (char)UTF_TO_NATIVE(0xff);
1261 /* mark the range as done, and continue */
1267 i = d - SvPVX(sv); /* remember current offset */
1268 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
1269 d = SvPVX(sv) + i; /* refresh d after realloc */
1270 d -= 2; /* eat the first char and the - */
1272 min = (U8)*d; /* first char in range */
1273 max = (U8)d[1]; /* last char in range */
1277 "Invalid [] range \"%c-%c\" in transliteration operator",
1278 (char)min, (char)max);
1282 if ((isLOWER(min) && isLOWER(max)) ||
1283 (isUPPER(min) && isUPPER(max))) {
1285 for (i = min; i <= max; i++)
1287 *d++ = NATIVE_TO_NEED(has_utf8,i);
1289 for (i = min; i <= max; i++)
1291 *d++ = NATIVE_TO_NEED(has_utf8,i);
1296 for (i = min; i <= max; i++)
1299 /* mark the range as done, and continue */
1305 /* range begins (ignore - as first or last char) */
1306 else if (*s == '-' && s+1 < send && s != start) {
1308 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1311 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
1323 /* if we get here, we're not doing a transliteration */
1325 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1326 except for the last char, which will be done separately. */
1327 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1329 while (s < send && *s != ')')
1330 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1332 else if (s[2] == '{' /* This should match regcomp.c */
1333 || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1336 char *regparse = s + (s[2] == '{' ? 3 : 4);
1339 while (count && (c = *regparse)) {
1340 if (c == '\\' && regparse[1])
1348 if (*regparse != ')') {
1349 regparse--; /* Leave one char for continuation. */
1350 yyerror("Sequence (?{...}) not terminated or not {}-balanced");
1352 while (s < regparse)
1353 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1357 /* likewise skip #-initiated comments in //x patterns */
1358 else if (*s == '#' && PL_lex_inpat &&
1359 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1360 while (s+1 < send && *s != '\n')
1361 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1364 /* check for embedded arrays
1365 (@foo, @:foo, @'foo, @{foo}, @$foo, @+, @-)
1367 else if (*s == '@' && s[1]
1368 && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1371 /* check for embedded scalars. only stop if we're sure it's a
1374 else if (*s == '$') {
1375 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
1377 if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1378 break; /* in regexp, $ might be tail anchor */
1381 /* End of else if chain - OP_TRANS rejoin rest */
1384 if (*s == '\\' && s+1 < send) {
1387 /* some backslashes we leave behind */
1388 if (*leaveit && *s && strchr(leaveit, *s)) {
1389 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1390 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1394 /* deprecate \1 in strings and substitution replacements */
1395 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1396 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1398 if (ckWARN(WARN_SYNTAX))
1399 Perl_warner(aTHX_ WARN_SYNTAX, "\\%c better written as $%c", *s, *s);
1404 /* string-change backslash escapes */
1405 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1410 /* if we get here, it's either a quoted -, or a digit */
1413 /* quoted - in transliterations */
1415 if (PL_lex_inwhat == OP_TRANS) {
1422 if (ckWARN(WARN_MISC) && isALNUM(*s))
1423 Perl_warner(aTHX_ WARN_MISC,
1424 "Unrecognized escape \\%c passed through",
1426 /* default action is to copy the quoted character */
1427 goto default_action;
1430 /* \132 indicates an octal constant */
1431 case '0': case '1': case '2': case '3':
1432 case '4': case '5': case '6': case '7':
1434 STRLEN len = 0; /* disallow underscores */
1435 uv = (UV)scan_oct(s, 3, &len);
1438 goto NUM_ESCAPE_INSERT;
1440 /* \x24 indicates a hex constant */
1444 char* e = strchr(s, '}');
1445 STRLEN len = 1; /* allow underscores */
1448 yyerror("Missing right brace on \\x{}");
1452 uv = (UV)scan_hex(s + 1, e - s - 1, &len);
1457 STRLEN len = 0; /* disallow underscores */
1458 uv = (UV)scan_hex(s, 2, &len);
1464 /* Insert oct or hex escaped character.
1465 * There will always enough room in sv since such
1466 * escapes will be longer than any UTF-8 sequence
1467 * they can end up as. */
1469 /* We need to map to chars to ASCII before doing the tests
1472 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
1473 if (!has_utf8 && uv > 255) {
1474 /* Might need to recode whatever we have
1475 * accumulated so far if it contains any
1478 * (Can't we keep track of that and avoid
1479 * this rescan? --jhi)
1483 for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
1484 if (!NATIVE_IS_INVARIANT(*c)) {
1489 STRLEN offset = d - SvPVX(sv);
1491 d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
1495 while (src >= (U8 *)SvPVX(sv)) {
1496 if (!NATIVE_IS_INVARIANT(*src)) {
1497 U8 ch = NATIVE_TO_ASCII(*src);
1498 *dst-- = UTF8_EIGHT_BIT_LO(ch);
1499 *dst-- = UTF8_EIGHT_BIT_HI(ch);
1509 if (has_utf8 || uv > 255) {
1510 d = (char*)uvchr_to_utf8((U8*)d, uv);
1512 if (PL_lex_inwhat == OP_TRANS &&
1513 PL_sublex_info.sub_op) {
1514 PL_sublex_info.sub_op->op_private |=
1515 (PL_lex_repl ? OPpTRANS_FROM_UTF
1528 /* \N{latin small letter a} is a named character */
1532 char* e = strchr(s, '}');
1538 yyerror("Missing right brace on \\N{}");
1542 res = newSVpvn(s + 1, e - s - 1);
1543 res = new_constant( Nullch, 0, "charnames",
1544 res, Nullsv, "\\N{...}" );
1546 sv_utf8_upgrade(res);
1547 str = SvPV(res,len);
1548 if (!has_utf8 && SvUTF8(res)) {
1549 char *ostart = SvPVX(sv);
1550 SvCUR_set(sv, d - ostart);
1553 sv_utf8_upgrade(sv);
1554 /* this just broke our allocation above... */
1555 SvGROW(sv, send - start);
1556 d = SvPVX(sv) + SvCUR(sv);
1559 if (len > e - s + 4) {
1560 char *odest = SvPVX(sv);
1562 SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
1563 d = SvPVX(sv) + (d - odest);
1565 Copy(str, d, len, char);
1572 yyerror("Missing braces on \\N{}");
1575 /* \c is a control character */
1584 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
1588 /* printf-style backslashes, formfeeds, newlines, etc */
1590 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
1593 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
1596 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
1599 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
1602 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
1605 *d++ = ASCII_TO_NEED(has_utf8,'\033');
1608 *d++ = ASCII_TO_NEED(has_utf8,'\007');
1614 } /* end if (backslash) */
1617 /* If we started with encoded form, or already know we want it
1618 and then encode the next character */
1619 if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
1621 UV uv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
1622 STRLEN need = UNISKIP(NATIVE_TO_UNI(uv));
1625 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
1626 STRLEN off = d - SvPVX(sv);
1627 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
1629 d = (char*)uvchr_to_utf8((U8*)d, uv);
1633 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1635 } /* while loop to process each character */
1637 /* terminate the string and set up the sv */
1639 SvCUR_set(sv, d - SvPVX(sv));
1640 if (SvCUR(sv) >= SvLEN(sv))
1641 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
1646 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1647 PL_sublex_info.sub_op->op_private |=
1648 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1652 /* shrink the sv if we allocated more than we used */
1653 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1654 SvLEN_set(sv, SvCUR(sv) + 1);
1655 Renew(SvPVX(sv), SvLEN(sv), char);
1658 /* return the substring (via yylval) only if we parsed anything */
1659 if (s > PL_bufptr) {
1660 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1661 sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1663 ( PL_lex_inwhat == OP_TRANS
1665 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1668 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1675 * Returns TRUE if there's more to the expression (e.g., a subscript),
1678 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
1680 * ->[ and ->{ return TRUE
1681 * { and [ outside a pattern are always subscripts, so return TRUE
1682 * if we're outside a pattern and it's not { or [, then return FALSE
1683 * if we're in a pattern and the first char is a {
1684 * {4,5} (any digits around the comma) returns FALSE
1685 * if we're in a pattern and the first char is a [
1687 * [SOMETHING] has a funky algorithm to decide whether it's a
1688 * character class or not. It has to deal with things like
1689 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
1690 * anything else returns TRUE
1693 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1696 S_intuit_more(pTHX_ register char *s)
1698 if (PL_lex_brackets)
1700 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1702 if (*s != '{' && *s != '[')
1707 /* In a pattern, so maybe we have {n,m}. */
1724 /* On the other hand, maybe we have a character class */
1727 if (*s == ']' || *s == '^')
1730 /* this is terrifying, and it works */
1731 int weight = 2; /* let's weigh the evidence */
1733 unsigned char un_char = 255, last_un_char;
1734 char *send = strchr(s,']');
1735 char tmpbuf[sizeof PL_tokenbuf * 4];
1737 if (!send) /* has to be an expression */
1740 Zero(seen,256,char);
1743 else if (isDIGIT(*s)) {
1745 if (isDIGIT(s[1]) && s[2] == ']')
1751 for (; s < send; s++) {
1752 last_un_char = un_char;
1753 un_char = (unsigned char)*s;
1758 weight -= seen[un_char] * 10;
1759 if (isALNUM_lazy_if(s+1,UTF)) {
1760 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
1761 if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
1766 else if (*s == '$' && s[1] &&
1767 strchr("[#!%*<>()-=",s[1])) {
1768 if (/*{*/ strchr("])} =",s[2]))
1777 if (strchr("wds]",s[1]))
1779 else if (seen['\''] || seen['"'])
1781 else if (strchr("rnftbxcav",s[1]))
1783 else if (isDIGIT(s[1])) {
1785 while (s[1] && isDIGIT(s[1]))
1795 if (strchr("aA01! ",last_un_char))
1797 if (strchr("zZ79~",s[1]))
1799 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
1800 weight -= 5; /* cope with negative subscript */
1803 if (!isALNUM(last_un_char) && !strchr("$@&",last_un_char) &&
1804 isALPHA(*s) && s[1] && isALPHA(s[1])) {
1809 if (keyword(tmpbuf, d - tmpbuf))
1812 if (un_char == last_un_char + 1)
1814 weight -= seen[un_char];
1819 if (weight >= 0) /* probably a character class */
1829 * Does all the checking to disambiguate
1831 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
1832 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
1834 * First argument is the stuff after the first token, e.g. "bar".
1836 * Not a method if bar is a filehandle.
1837 * Not a method if foo is a subroutine prototyped to take a filehandle.
1838 * Not a method if it's really "Foo $bar"
1839 * Method if it's "foo $bar"
1840 * Not a method if it's really "print foo $bar"
1841 * Method if it's really "foo package::" (interpreted as package->foo)
1842 * Not a method if bar is known to be a subroutne ("sub bar; foo bar")
1843 * Not a method if bar is a filehandle or package, but is quoted with
1848 S_intuit_method(pTHX_ char *start, GV *gv)
1850 char *s = start + (*start == '$');
1851 char tmpbuf[sizeof PL_tokenbuf];
1859 if ((cv = GvCVu(gv))) {
1860 char *proto = SvPVX(cv);
1870 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
1871 /* start is the beginning of the possible filehandle/object,
1872 * and s is the end of it
1873 * tmpbuf is a copy of it
1876 if (*start == '$') {
1877 if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
1882 return *s == '(' ? FUNCMETH : METHOD;
1884 if (!keyword(tmpbuf, len)) {
1885 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
1890 indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
1891 if (indirgv && GvCVu(indirgv))
1893 /* filehandle or package name makes it a method */
1894 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
1896 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
1897 return 0; /* no assumptions -- "=>" quotes bearword */
1899 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
1900 newSVpvn(tmpbuf,len));
1901 PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
1905 return *s == '(' ? FUNCMETH : METHOD;
1913 * Return a string of Perl code to load the debugger. If PERL5DB
1914 * is set, it will return the contents of that, otherwise a
1915 * compile-time require of perl5db.pl.
1922 char *pdb = PerlEnv_getenv("PERL5DB");
1926 SETERRNO(0,SS$_NORMAL);
1927 return "BEGIN { require 'perl5db.pl' }";
1933 /* Encoded script support. filter_add() effectively inserts a
1934 * 'pre-processing' function into the current source input stream.
1935 * Note that the filter function only applies to the current source file
1936 * (e.g., it will not affect files 'require'd or 'use'd by this one).
1938 * The datasv parameter (which may be NULL) can be used to pass
1939 * private data to this instance of the filter. The filter function
1940 * can recover the SV using the FILTER_DATA macro and use it to
1941 * store private buffers and state information.
1943 * The supplied datasv parameter is upgraded to a PVIO type
1944 * and the IoDIRP/IoANY field is used to store the function pointer,
1945 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
1946 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
1947 * private use must be set using malloc'd pointers.
1951 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
1956 if (!PL_rsfp_filters)
1957 PL_rsfp_filters = newAV();
1959 datasv = NEWSV(255,0);
1960 if (!SvUPGRADE(datasv, SVt_PVIO))
1961 Perl_die(aTHX_ "Can't upgrade filter_add data to SVt_PVIO");
1962 IoANY(datasv) = (void *)funcp; /* stash funcp into spare field */
1963 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
1964 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
1965 funcp, SvPV_nolen(datasv)));
1966 av_unshift(PL_rsfp_filters, 1);
1967 av_store(PL_rsfp_filters, 0, datasv) ;
1972 /* Delete most recently added instance of this filter function. */
1974 Perl_filter_del(pTHX_ filter_t funcp)
1977 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", funcp));
1978 if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
1980 /* if filter is on top of stack (usual case) just pop it off */
1981 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
1982 if (IoANY(datasv) == (void *)funcp) {
1983 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
1984 IoANY(datasv) = (void *)NULL;
1985 sv_free(av_pop(PL_rsfp_filters));
1989 /* we need to search for the correct entry and clear it */
1990 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
1994 /* Invoke the n'th filter function for the current rsfp. */
1996 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
1999 /* 0 = read one text line */
2004 if (!PL_rsfp_filters)
2006 if (idx > AvFILLp(PL_rsfp_filters)){ /* Any more filters? */
2007 /* Provide a default input filter to make life easy. */
2008 /* Note that we append to the line. This is handy. */
2009 DEBUG_P(PerlIO_printf(Perl_debug_log,
2010 "filter_read %d: from rsfp\n", idx));
2014 int old_len = SvCUR(buf_sv) ;
2016 /* ensure buf_sv is large enough */
2017 SvGROW(buf_sv, old_len + maxlen) ;
2018 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
2019 if (PerlIO_error(PL_rsfp))
2020 return -1; /* error */
2022 return 0 ; /* end of file */
2024 SvCUR_set(buf_sv, old_len + len) ;
2027 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2028 if (PerlIO_error(PL_rsfp))
2029 return -1; /* error */
2031 return 0 ; /* end of file */
2034 return SvCUR(buf_sv);
2036 /* Skip this filter slot if filter has been deleted */
2037 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef){
2038 DEBUG_P(PerlIO_printf(Perl_debug_log,
2039 "filter_read %d: skipped (filter deleted)\n",
2041 return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
2043 /* Get function pointer hidden within datasv */
2044 funcp = (filter_t)IoANY(datasv);
2045 DEBUG_P(PerlIO_printf(Perl_debug_log,
2046 "filter_read %d: via function %p (%s)\n",
2047 idx, funcp, SvPV_nolen(datasv)));
2048 /* Call function. The function is expected to */
2049 /* call "FILTER_READ(idx+1, buf_sv)" first. */
2050 /* Return: <0:error, =0:eof, >0:not eof */
2051 return (*funcp)(aTHXo_ idx, buf_sv, maxlen);
2055 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2057 #ifdef PERL_CR_FILTER
2058 if (!PL_rsfp_filters) {
2059 filter_add(S_cr_textfilter,NULL);
2062 if (PL_rsfp_filters) {
2065 SvCUR_set(sv, 0); /* start with empty line */
2066 if (FILTER_READ(0, sv, 0) > 0)
2067 return ( SvPVX(sv) ) ;
2072 return (sv_gets(sv, fp, append));
2076 S_find_in_my_stash(pTHX_ char *pkgname, I32 len)
2080 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2084 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2085 (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV)))
2087 return GvHV(gv); /* Foo:: */
2090 /* use constant CLASS => 'MyClass' */
2091 if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) {
2093 if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2094 pkgname = SvPV_nolen(sv);
2098 return gv_stashpv(pkgname, FALSE);
2102 static char* exp_name[] =
2103 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2104 "ATTRTERM", "TERMBLOCK"
2111 Works out what to call the token just pulled out of the input
2112 stream. The yacc parser takes care of taking the ops we return and
2113 stitching them into a tree.
2119 if read an identifier
2120 if we're in a my declaration
2121 croak if they tried to say my($foo::bar)
2122 build the ops for a my() declaration
2123 if it's an access to a my() variable
2124 are we in a sort block?
2125 croak if my($a); $a <=> $b
2126 build ops for access to a my() variable
2127 if in a dq string, and they've said @foo and we can't find @foo
2129 build ops for a bareword
2130 if we already built the token before, use it.
2133 #ifdef USE_PURE_BISON
2135 Perl_yylex_r(pTHX_ YYSTYPE *lvalp, int *lcharp)
2140 yylval_pointer[yyactlevel] = lvalp;
2141 yychar_pointer[yyactlevel] = lcharp;
2142 if (yyactlevel >= YYMAXLEVEL)
2143 Perl_croak(aTHX_ "panic: YYMAXLEVEL");
2145 r = Perl_yylex(aTHX);
2155 #pragma segment Perl_yylex
2168 /* check if there's an identifier for us to look at */
2169 if (PL_pending_ident)
2170 return S_pending_ident(aTHX);
2172 /* no identifier pending identification */
2174 switch (PL_lex_state) {
2176 case LEX_NORMAL: /* Some compilers will produce faster */
2177 case LEX_INTERPNORMAL: /* code if we comment these out. */
2181 /* when we've already built the next token, just pull it out of the queue */
2184 yylval = PL_nextval[PL_nexttoke];
2186 PL_lex_state = PL_lex_defer;
2187 PL_expect = PL_lex_expect;
2188 PL_lex_defer = LEX_NORMAL;
2190 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2191 "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr,
2192 (IV)PL_nexttype[PL_nexttoke]); });
2194 return(PL_nexttype[PL_nexttoke]);
2196 /* interpolated case modifiers like \L \U, including \Q and \E.
2197 when we get here, PL_bufptr is at the \
2199 case LEX_INTERPCASEMOD:
2201 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2202 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2204 /* handle \E or end of string */
2205 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2209 if (PL_lex_casemods) {
2210 oldmod = PL_lex_casestack[--PL_lex_casemods];
2211 PL_lex_casestack[PL_lex_casemods] = '\0';
2213 if (PL_bufptr != PL_bufend && strchr("LUQ", oldmod)) {
2215 PL_lex_state = LEX_INTERPCONCAT;
2219 if (PL_bufptr != PL_bufend)
2221 PL_lex_state = LEX_INTERPCONCAT;
2225 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2226 "### Saw case modifier at '%s'\n", PL_bufptr); });
2228 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2229 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
2230 if (strchr("LU", *s) &&
2231 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U')))
2233 PL_lex_casestack[--PL_lex_casemods] = '\0';
2236 if (PL_lex_casemods > 10) {
2237 char* newlb = Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2238 if (newlb != PL_lex_casestack) {
2240 PL_lex_casestack = newlb;
2243 PL_lex_casestack[PL_lex_casemods++] = *s;
2244 PL_lex_casestack[PL_lex_casemods] = '\0';
2245 PL_lex_state = LEX_INTERPCONCAT;
2246 PL_nextval[PL_nexttoke].ival = 0;
2249 PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2251 PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2253 PL_nextval[PL_nexttoke].ival = OP_LC;
2255 PL_nextval[PL_nexttoke].ival = OP_UC;
2257 PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2259 Perl_croak(aTHX_ "panic: yylex");
2262 if (PL_lex_starts) {
2271 case LEX_INTERPPUSH:
2272 return sublex_push();
2274 case LEX_INTERPSTART:
2275 if (PL_bufptr == PL_bufend)
2276 return sublex_done();
2277 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2278 "### Interpolated variable at '%s'\n", PL_bufptr); });
2280 PL_lex_dojoin = (*PL_bufptr == '@');
2281 PL_lex_state = LEX_INTERPNORMAL;
2282 if (PL_lex_dojoin) {
2283 PL_nextval[PL_nexttoke].ival = 0;
2286 PL_nextval[PL_nexttoke].opval = newOP(OP_THREADSV, 0);
2287 PL_nextval[PL_nexttoke].opval->op_targ = find_threadsv("\"");
2288 force_next(PRIVATEREF);
2290 force_ident("\"", '$');
2291 #endif /* USE_THREADS */
2292 PL_nextval[PL_nexttoke].ival = 0;
2294 PL_nextval[PL_nexttoke].ival = 0;
2296 PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
2299 if (PL_lex_starts++) {
2305 case LEX_INTERPENDMAYBE:
2306 if (intuit_more(PL_bufptr)) {
2307 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
2313 if (PL_lex_dojoin) {
2314 PL_lex_dojoin = FALSE;
2315 PL_lex_state = LEX_INTERPCONCAT;
2318 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2319 && SvEVALED(PL_lex_repl))
2321 if (PL_bufptr != PL_bufend)
2322 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2323 PL_lex_repl = Nullsv;
2326 case LEX_INTERPCONCAT:
2328 if (PL_lex_brackets)
2329 Perl_croak(aTHX_ "panic: INTERPCONCAT");
2331 if (PL_bufptr == PL_bufend)
2332 return sublex_done();
2334 if (SvIVX(PL_linestr) == '\'') {
2335 SV *sv = newSVsv(PL_linestr);
2338 else if ( PL_hints & HINT_NEW_RE )
2339 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2340 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2344 s = scan_const(PL_bufptr);
2346 PL_lex_state = LEX_INTERPCASEMOD;
2348 PL_lex_state = LEX_INTERPSTART;
2351 if (s != PL_bufptr) {
2352 PL_nextval[PL_nexttoke] = yylval;
2355 if (PL_lex_starts++)
2365 PL_lex_state = LEX_NORMAL;
2366 s = scan_formline(PL_bufptr);
2367 if (!PL_lex_formbrack)
2373 PL_oldoldbufptr = PL_oldbufptr;
2376 PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at %s\n",
2377 exp_name[PL_expect], s);
2383 if (isIDFIRST_lazy_if(s,UTF))
2385 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2388 goto fake_eof; /* emulate EOF on ^D or ^Z */
2393 if (PL_lex_brackets)
2394 yyerror("Missing right curly or square bracket");
2395 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2396 "### Tokener got EOF\n");
2400 if (s++ < PL_bufend)
2401 goto retry; /* ignore stray nulls */
2404 if (!PL_in_eval && !PL_preambled) {
2405 PL_preambled = TRUE;
2406 sv_setpv(PL_linestr,incl_perldb());
2407 if (SvCUR(PL_linestr))
2408 sv_catpv(PL_linestr,";");
2410 while(AvFILLp(PL_preambleav) >= 0) {
2411 SV *tmpsv = av_shift(PL_preambleav);
2412 sv_catsv(PL_linestr, tmpsv);
2413 sv_catpv(PL_linestr, ";");
2416 sv_free((SV*)PL_preambleav);
2417 PL_preambleav = NULL;
2419 if (PL_minus_n || PL_minus_p) {
2420 sv_catpv(PL_linestr, "LINE: while (<>) {");
2422 sv_catpv(PL_linestr,"chomp;");
2425 if (strchr("/'\"", *PL_splitstr)
2426 && strchr(PL_splitstr + 1, *PL_splitstr))
2427 Perl_sv_catpvf(aTHX_ PL_linestr, "@F=split(%s);", PL_splitstr);
2430 s = "'~#\200\1'"; /* surely one char is unused...*/
2431 while (s[1] && strchr(PL_splitstr, *s)) s++;
2433 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s%c",
2434 "q" + (delim == '\''), delim);
2435 for (s = PL_splitstr; *s; s++) {
2437 sv_catpvn(PL_linestr, "\\", 1);
2438 sv_catpvn(PL_linestr, s, 1);
2440 Perl_sv_catpvf(aTHX_ PL_linestr, "%c);", delim);
2444 sv_catpv(PL_linestr,"our @F=split(' ');");
2447 sv_catpv(PL_linestr, "\n");
2448 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2449 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2450 PL_last_lop = PL_last_uni = Nullch;
2451 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2452 SV *sv = NEWSV(85,0);
2454 sv_upgrade(sv, SVt_PVMG);
2455 sv_setsv(sv,PL_linestr);
2456 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2461 bof = PL_rsfp ? TRUE : FALSE;
2462 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2465 if (PL_preprocess && !PL_in_eval)
2466 (void)PerlProc_pclose(PL_rsfp);
2467 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2468 PerlIO_clearerr(PL_rsfp);
2470 (void)PerlIO_close(PL_rsfp);
2472 PL_doextract = FALSE;
2474 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2475 sv_setpv(PL_linestr,PL_minus_p ? ";}continue{print" : "");
2476 sv_catpv(PL_linestr,";}");
2477 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2478 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2479 PL_last_lop = PL_last_uni = Nullch;
2480 PL_minus_n = PL_minus_p = 0;
2483 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2484 PL_last_lop = PL_last_uni = Nullch;
2485 sv_setpv(PL_linestr,"");
2486 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
2488 /* if it looks like the start of a BOM, check if it in fact is */
2489 else if (bof && (!*s || *(U8*)s == 0xEF || *(U8*)s >= 0xFE)) {
2490 #ifdef PERLIO_IS_STDIO
2491 # ifdef __GNU_LIBRARY__
2492 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
2493 # define FTELL_FOR_PIPE_IS_BROKEN
2497 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
2498 # define FTELL_FOR_PIPE_IS_BROKEN
2503 #ifdef FTELL_FOR_PIPE_IS_BROKEN
2504 /* This loses the possibility to detect the bof
2505 * situation on perl -P when the libc5 is being used.
2506 * Workaround? Maybe attach some extra state to PL_rsfp?
2509 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2511 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2514 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2515 s = swallow_bom((U8*)s);
2519 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
2520 PL_doextract = FALSE;
2522 /* Incest with pod. */
2523 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2524 sv_setpv(PL_linestr, "");
2525 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2526 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2527 PL_last_lop = PL_last_uni = Nullch;
2528 PL_doextract = FALSE;
2532 } while (PL_doextract);
2533 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2534 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2535 SV *sv = NEWSV(85,0);
2537 sv_upgrade(sv, SVt_PVMG);
2538 sv_setsv(sv,PL_linestr);
2539 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2541 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2542 PL_last_lop = PL_last_uni = Nullch;
2543 if (CopLINE(PL_curcop) == 1) {
2544 while (s < PL_bufend && isSPACE(*s))
2546 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2550 if (*s == '#' && *(s+1) == '!')
2552 #ifdef ALTERNATE_SHEBANG
2554 static char as[] = ALTERNATE_SHEBANG;
2555 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2556 d = s + (sizeof(as) - 1);
2558 #endif /* ALTERNATE_SHEBANG */
2567 while (*d && !isSPACE(*d))
2571 #ifdef ARG_ZERO_IS_SCRIPT
2572 if (ipathend > ipath) {
2574 * HP-UX (at least) sets argv[0] to the script name,
2575 * which makes $^X incorrect. And Digital UNIX and Linux,
2576 * at least, set argv[0] to the basename of the Perl
2577 * interpreter. So, having found "#!", we'll set it right.
2579 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV));
2580 assert(SvPOK(x) || SvGMAGICAL(x));
2581 if (sv_eq(x, CopFILESV(PL_curcop))) {
2582 sv_setpvn(x, ipath, ipathend - ipath);
2585 TAINT_NOT; /* $^X is always tainted, but that's OK */
2587 #endif /* ARG_ZERO_IS_SCRIPT */
2592 d = instr(s,"perl -");
2594 d = instr(s,"perl");
2596 /* avoid getting into infinite loops when shebang
2597 * line contains "Perl" rather than "perl" */
2599 for (d = ipathend-4; d >= ipath; --d) {
2600 if ((*d == 'p' || *d == 'P')
2601 && !ibcmp(d, "perl", 4))
2611 #ifdef ALTERNATE_SHEBANG
2613 * If the ALTERNATE_SHEBANG on this system starts with a
2614 * character that can be part of a Perl expression, then if
2615 * we see it but not "perl", we're probably looking at the
2616 * start of Perl code, not a request to hand off to some
2617 * other interpreter. Similarly, if "perl" is there, but
2618 * not in the first 'word' of the line, we assume the line
2619 * contains the start of the Perl program.
2621 if (d && *s != '#') {
2623 while (*c && !strchr("; \t\r\n\f\v#", *c))
2626 d = Nullch; /* "perl" not in first word; ignore */
2628 *s = '#'; /* Don't try to parse shebang line */
2630 #endif /* ALTERNATE_SHEBANG */
2631 #ifndef MACOS_TRADITIONAL
2636 !instr(s,"indir") &&
2637 instr(PL_origargv[0],"perl"))
2643 while (s < PL_bufend && isSPACE(*s))
2645 if (s < PL_bufend) {
2646 Newz(899,newargv,PL_origargc+3,char*);
2648 while (s < PL_bufend && !isSPACE(*s))
2651 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2654 newargv = PL_origargv;
2656 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
2657 Perl_croak(aTHX_ "Can't exec %s", ipath);
2661 U32 oldpdb = PL_perldb;
2662 bool oldn = PL_minus_n;
2663 bool oldp = PL_minus_p;
2665 while (*d && !isSPACE(*d)) d++;
2666 while (SPACE_OR_TAB(*d)) d++;
2670 if (*d == 'M' || *d == 'm') {
2672 while (*d && !isSPACE(*d)) d++;
2673 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2676 d = moreswitches(d);
2678 if ((PERLDB_LINE && !oldpdb) ||
2679 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
2680 /* if we have already added "LINE: while (<>) {",
2681 we must not do it again */
2683 sv_setpv(PL_linestr, "");
2684 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2685 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2686 PL_last_lop = PL_last_uni = Nullch;
2687 PL_preambled = FALSE;
2689 (void)gv_fetchfile(PL_origfilename);
2696 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2698 PL_lex_state = LEX_FORMLINE;
2703 #ifdef PERL_STRICT_CR
2704 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
2706 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
2708 case ' ': case '\t': case '\f': case 013:
2709 #ifdef MACOS_TRADITIONAL
2716 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
2717 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
2718 /* handle eval qq[#line 1 "foo"\n ...] */
2719 CopLINE_dec(PL_curcop);
2723 while (s < d && *s != '\n')
2727 else if (s > d) /* Found by Ilya: feed random input to Perl. */
2728 Perl_croak(aTHX_ "panic: input overflow");
2730 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2732 PL_lex_state = LEX_FORMLINE;
2742 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2749 while (s < PL_bufend && SPACE_OR_TAB(*s))
2752 if (strnEQ(s,"=>",2)) {
2753 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
2754 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2755 "### Saw unary minus before =>, forcing word '%s'\n", s);
2757 OPERATOR('-'); /* unary minus */
2759 PL_last_uni = PL_oldbufptr;
2761 case 'r': ftst = OP_FTEREAD; break;
2762 case 'w': ftst = OP_FTEWRITE; break;
2763 case 'x': ftst = OP_FTEEXEC; break;
2764 case 'o': ftst = OP_FTEOWNED; break;
2765 case 'R': ftst = OP_FTRREAD; break;
2766 case 'W': ftst = OP_FTRWRITE; break;
2767 case 'X': ftst = OP_FTREXEC; break;
2768 case 'O': ftst = OP_FTROWNED; break;
2769 case 'e': ftst = OP_FTIS; break;
2770 case 'z': ftst = OP_FTZERO; break;
2771 case 's': ftst = OP_FTSIZE; break;
2772 case 'f': ftst = OP_FTFILE; break;
2773 case 'd': ftst = OP_FTDIR; break;
2774 case 'l': ftst = OP_FTLINK; break;
2775 case 'p': ftst = OP_FTPIPE; break;
2776 case 'S': ftst = OP_FTSOCK; break;
2777 case 'u': ftst = OP_FTSUID; break;
2778 case 'g': ftst = OP_FTSGID; break;
2779 case 'k': ftst = OP_FTSVTX; break;
2780 case 'b': ftst = OP_FTBLK; break;
2781 case 'c': ftst = OP_FTCHR; break;
2782 case 't': ftst = OP_FTTTY; break;
2783 case 'T': ftst = OP_FTTEXT; break;
2784 case 'B': ftst = OP_FTBINARY; break;
2785 case 'M': case 'A': case 'C':
2786 gv_fetchpv("\024",TRUE, SVt_PV);
2788 case 'M': ftst = OP_FTMTIME; break;
2789 case 'A': ftst = OP_FTATIME; break;
2790 case 'C': ftst = OP_FTCTIME; break;
2798 PL_last_lop_op = ftst;
2799 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2800 "### Saw file test %c\n", (int)ftst);
2805 /* Assume it was a minus followed by a one-letter named
2806 * subroutine call (or a -bareword), then. */
2807 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2808 "### %c looked like a file test but was not\n",
2817 if (PL_expect == XOPERATOR)
2822 else if (*s == '>') {
2825 if (isIDFIRST_lazy_if(s,UTF)) {
2826 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
2834 if (PL_expect == XOPERATOR)
2837 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2839 OPERATOR('-'); /* unary minus */
2846 if (PL_expect == XOPERATOR)
2851 if (PL_expect == XOPERATOR)
2854 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2860 if (PL_expect != XOPERATOR) {
2861 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
2862 PL_expect = XOPERATOR;
2863 force_ident(PL_tokenbuf, '*');
2876 if (PL_expect == XOPERATOR) {
2880 PL_tokenbuf[0] = '%';
2881 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
2882 if (!PL_tokenbuf[1]) {
2884 yyerror("Final % should be \\% or %name");
2887 PL_pending_ident = '%';
2906 switch (PL_expect) {
2909 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
2911 PL_bufptr = s; /* update in case we back off */
2917 PL_expect = XTERMBLOCK;
2921 while (isIDFIRST_lazy_if(s,UTF)) {
2922 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
2923 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
2924 if (tmp < 0) tmp = -tmp;
2939 d = scan_str(d,TRUE,TRUE);
2941 /* MUST advance bufptr here to avoid bogus
2942 "at end of line" context messages from yyerror().
2944 PL_bufptr = s + len;
2945 yyerror("Unterminated attribute parameter in attribute list");
2948 return 0; /* EOF indicator */
2952 SV *sv = newSVpvn(s, len);
2953 sv_catsv(sv, PL_lex_stuff);
2954 attrs = append_elem(OP_LIST, attrs,
2955 newSVOP(OP_CONST, 0, sv));
2956 SvREFCNT_dec(PL_lex_stuff);
2957 PL_lex_stuff = Nullsv;
2960 if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
2961 CvLVALUE_on(PL_compcv);
2962 else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
2963 CvLOCKED_on(PL_compcv);
2964 else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
2965 CvMETHOD_on(PL_compcv);
2967 else if (PL_in_my == KEY_our && len == 6 && strnEQ(s, "unique", len))
2968 GvUNIQUE_on(cGVOPx_gv(yylval.opval));
2970 /* After we've set the flags, it could be argued that
2971 we don't need to do the attributes.pm-based setting
2972 process, and shouldn't bother appending recognized
2973 flags. To experiment with that, uncomment the
2974 following "else": */
2976 attrs = append_elem(OP_LIST, attrs,
2977 newSVOP(OP_CONST, 0,
2981 if (*s == ':' && s[1] != ':')
2984 break; /* require real whitespace or :'s */
2986 tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
2987 if (*s != ';' && *s != tmp && (tmp != '=' || *s != ')')) {
2988 char q = ((*s == '\'') ? '"' : '\'');
2989 /* If here for an expression, and parsed no attrs, back off. */
2990 if (tmp == '=' && !attrs) {
2994 /* MUST advance bufptr here to avoid bogus "at end of line"
2995 context messages from yyerror().
2999 yyerror("Unterminated attribute list");
3001 yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
3009 PL_nextval[PL_nexttoke].opval = attrs;
3017 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
3018 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
3034 if (PL_lex_brackets <= 0)
3035 yyerror("Unmatched right square bracket");
3038 if (PL_lex_state == LEX_INTERPNORMAL) {
3039 if (PL_lex_brackets == 0) {
3040 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3041 PL_lex_state = LEX_INTERPEND;
3048 if (PL_lex_brackets > 100) {
3049 char* newlb = Renew(PL_lex_brackstack, PL_lex_brackets + 1, char);
3050 if (newlb != PL_lex_brackstack) {
3052 PL_lex_brackstack = newlb;
3055 switch (PL_expect) {
3057 if (PL_lex_formbrack) {
3061 if (PL_oldoldbufptr == PL_last_lop)
3062 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3064 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3065 OPERATOR(HASHBRACK);
3067 while (s < PL_bufend && SPACE_OR_TAB(*s))
3070 PL_tokenbuf[0] = '\0';
3071 if (d < PL_bufend && *d == '-') {
3072 PL_tokenbuf[0] = '-';
3074 while (d < PL_bufend && SPACE_OR_TAB(*d))
3077 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3078 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
3080 while (d < PL_bufend && SPACE_OR_TAB(*d))
3083 char minus = (PL_tokenbuf[0] == '-');
3084 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
3092 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
3097 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3102 if (PL_oldoldbufptr == PL_last_lop)
3103 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3105 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3108 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
3110 /* This hack is to get the ${} in the message. */
3112 yyerror("syntax error");
3115 OPERATOR(HASHBRACK);
3117 /* This hack serves to disambiguate a pair of curlies
3118 * as being a block or an anon hash. Normally, expectation
3119 * determines that, but in cases where we're not in a
3120 * position to expect anything in particular (like inside
3121 * eval"") we have to resolve the ambiguity. This code
3122 * covers the case where the first term in the curlies is a
3123 * quoted string. Most other cases need to be explicitly
3124 * disambiguated by prepending a `+' before the opening
3125 * curly in order to force resolution as an anon hash.
3127 * XXX should probably propagate the outer expectation
3128 * into eval"" to rely less on this hack, but that could
3129 * potentially break current behavior of eval"".
3133 if (*s == '\'' || *s == '"' || *s == '`') {
3134 /* common case: get past first string, handling escapes */
3135 for (t++; t < PL_bufend && *t != *s;)
3136 if (*t++ == '\\' && (*t == '\\' || *t == *s))
3140 else if (*s == 'q') {
3143 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
3147 char open, close, term;
3150 while (t < PL_bufend && isSPACE(*t))
3154 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
3158 for (t++; t < PL_bufend; t++) {
3159 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
3161 else if (*t == open)
3165 for (t++; t < PL_bufend; t++) {
3166 if (*t == '\\' && t+1 < PL_bufend)
3168 else if (*t == close && --brackets <= 0)
3170 else if (*t == open)
3176 else if (isALNUM_lazy_if(t,UTF)) {
3178 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3181 while (t < PL_bufend && isSPACE(*t))
3183 /* if comma follows first term, call it an anon hash */
3184 /* XXX it could be a comma expression with loop modifiers */
3185 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
3186 || (*t == '=' && t[1] == '>')))
3187 OPERATOR(HASHBRACK);
3188 if (PL_expect == XREF)
3191 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3197 yylval.ival = CopLINE(PL_curcop);
3198 if (isSPACE(*s) || *s == '#')
3199 PL_copline = NOLINE; /* invalidate current command line number */
3204 if (PL_lex_brackets <= 0)
3205 yyerror("Unmatched right curly bracket");
3207 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3208 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3209 PL_lex_formbrack = 0;
3210 if (PL_lex_state == LEX_INTERPNORMAL) {
3211 if (PL_lex_brackets == 0) {
3212 if (PL_expect & XFAKEBRACK) {
3213 PL_expect &= XENUMMASK;
3214 PL_lex_state = LEX_INTERPEND;
3216 return yylex(); /* ignore fake brackets */
3218 if (*s == '-' && s[1] == '>')
3219 PL_lex_state = LEX_INTERPENDMAYBE;
3220 else if (*s != '[' && *s != '{')
3221 PL_lex_state = LEX_INTERPEND;
3224 if (PL_expect & XFAKEBRACK) {
3225 PL_expect &= XENUMMASK;
3227 return yylex(); /* ignore fake brackets */
3237 if (PL_expect == XOPERATOR) {
3238 if (ckWARN(WARN_SEMICOLON)
3239 && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart)
3241 CopLINE_dec(PL_curcop);
3242 Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi);
3243 CopLINE_inc(PL_curcop);
3248 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3250 PL_expect = XOPERATOR;
3251 force_ident(PL_tokenbuf, '&');
3255 yylval.ival = (OPpENTERSUB_AMPER<<8);
3274 if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
3275 Perl_warner(aTHX_ WARN_SYNTAX, "Reversed %c= operator",(int)tmp);
3277 if (PL_expect == XSTATE && isALPHA(tmp) &&
3278 (s == PL_linestart+1 || s[-2] == '\n') )
3280 if (PL_in_eval && !PL_rsfp) {
3285 if (strnEQ(s,"=cut",4)) {
3299 PL_doextract = TRUE;
3302 if (PL_lex_brackets < PL_lex_formbrack) {
3304 #ifdef PERL_STRICT_CR
3305 for (t = s; SPACE_OR_TAB(*t); t++) ;
3307 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3309 if (*t == '\n' || *t == '#') {
3327 if (PL_expect != XOPERATOR) {
3328 if (s[1] != '<' && !strchr(s,'>'))
3331 s = scan_heredoc(s);
3333 s = scan_inputsymbol(s);
3334 TERM(sublex_start());
3339 SHop(OP_LEFT_SHIFT);
3353 SHop(OP_RIGHT_SHIFT);
3362 if (PL_expect == XOPERATOR) {
3363 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3366 return ','; /* grandfather non-comma-format format */
3370 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3371 PL_tokenbuf[0] = '@';
3372 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3373 sizeof PL_tokenbuf - 1, FALSE);
3374 if (PL_expect == XOPERATOR)
3375 no_op("Array length", s);
3376 if (!PL_tokenbuf[1])
3378 PL_expect = XOPERATOR;
3379 PL_pending_ident = '#';
3383 PL_tokenbuf[0] = '$';
3384 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3385 sizeof PL_tokenbuf - 1, FALSE);
3386 if (PL_expect == XOPERATOR)
3388 if (!PL_tokenbuf[1]) {
3390 yyerror("Final $ should be \\$ or $name");
3394 /* This kludge not intended to be bulletproof. */
3395 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3396 yylval.opval = newSVOP(OP_CONST, 0,
3397 newSViv(PL_compiling.cop_arybase));
3398 yylval.opval->op_private = OPpCONST_ARYBASE;
3404 if (PL_lex_state == LEX_NORMAL)
3407 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3410 PL_tokenbuf[0] = '@';
3411 if (ckWARN(WARN_SYNTAX)) {
3413 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3416 PL_bufptr = skipspace(PL_bufptr);
3417 while (t < PL_bufend && *t != ']')
3419 Perl_warner(aTHX_ WARN_SYNTAX,
3420 "Multidimensional syntax %.*s not supported",
3421 (t - PL_bufptr) + 1, PL_bufptr);
3425 else if (*s == '{') {
3426 PL_tokenbuf[0] = '%';
3427 if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") &&
3428 (t = strchr(s, '}')) && (t = strchr(t, '=')))
3430 char tmpbuf[sizeof PL_tokenbuf];
3432 for (t++; isSPACE(*t); t++) ;
3433 if (isIDFIRST_lazy_if(t,UTF)) {
3434 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3435 for (; isSPACE(*t); t++) ;
3436 if (*t == ';' && get_cv(tmpbuf, FALSE))
3437 Perl_warner(aTHX_ WARN_SYNTAX,
3438 "You need to quote \"%s\"", tmpbuf);
3444 PL_expect = XOPERATOR;
3445 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3446 bool islop = (PL_last_lop == PL_oldoldbufptr);
3447 if (!islop || PL_last_lop_op == OP_GREPSTART)
3448 PL_expect = XOPERATOR;
3449 else if (strchr("$@\"'`q", *s))
3450 PL_expect = XTERM; /* e.g. print $fh "foo" */
3451 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3452 PL_expect = XTERM; /* e.g. print $fh &sub */
3453 else if (isIDFIRST_lazy_if(s,UTF)) {
3454 char tmpbuf[sizeof PL_tokenbuf];
3455 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3456 if ((tmp = keyword(tmpbuf, len))) {
3457 /* binary operators exclude handle interpretations */
3469 PL_expect = XTERM; /* e.g. print $fh length() */
3474 GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
3475 if (gv && GvCVu(gv))
3476 PL_expect = XTERM; /* e.g. print $fh subr() */
3479 else if (isDIGIT(*s))
3480 PL_expect = XTERM; /* e.g. print $fh 3 */
3481 else if (*s == '.' && isDIGIT(s[1]))
3482 PL_expect = XTERM; /* e.g. print $fh .3 */
3483 else if (strchr("/?-+", *s) && !isSPACE(s[1]) && s[1] != '=')
3484 PL_expect = XTERM; /* e.g. print $fh -1 */
3485 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3486 PL_expect = XTERM; /* print $fh <<"EOF" */
3488 PL_pending_ident = '$';
3492 if (PL_expect == XOPERATOR)
3494 PL_tokenbuf[0] = '@';
3495 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3496 if (!PL_tokenbuf[1]) {
3498 yyerror("Final @ should be \\@ or @name");
3501 if (PL_lex_state == LEX_NORMAL)
3503 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3505 PL_tokenbuf[0] = '%';
3507 /* Warn about @ where they meant $. */
3508 if (ckWARN(WARN_SYNTAX)) {
3509 if (*s == '[' || *s == '{') {
3511 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3513 if (*t == '}' || *t == ']') {
3515 PL_bufptr = skipspace(PL_bufptr);
3516 Perl_warner(aTHX_ WARN_SYNTAX,
3517 "Scalar value %.*s better written as $%.*s",
3518 t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3523 PL_pending_ident = '@';
3526 case '/': /* may either be division or pattern */
3527 case '?': /* may either be conditional or pattern */
3528 if (PL_expect != XOPERATOR) {
3529 /* Disable warning on "study /blah/" */
3530 if (PL_oldoldbufptr == PL_last_uni
3531 && (*PL_last_uni != 's' || s - PL_last_uni < 5
3532 || memNE(PL_last_uni, "study", 5)
3533 || isALNUM_lazy_if(PL_last_uni+5,UTF)))
3535 s = scan_pat(s,OP_MATCH);
3536 TERM(sublex_start());
3544 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3545 #ifdef PERL_STRICT_CR
3548 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3550 && (s == PL_linestart || s[-1] == '\n') )
3552 PL_lex_formbrack = 0;
3556 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3562 yylval.ival = OPf_SPECIAL;
3568 if (PL_expect != XOPERATOR)
3573 case '0': case '1': case '2': case '3': case '4':
3574 case '5': case '6': case '7': case '8': case '9':
3575 s = scan_num(s, &yylval);
3576 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3577 "### Saw number in '%s'\n", s);
3579 if (PL_expect == XOPERATOR)
3584 s = scan_str(s,FALSE,FALSE);
3585 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3586 "### Saw string before '%s'\n", s);
3588 if (PL_expect == XOPERATOR) {
3589 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3592 return ','; /* grandfather non-comma-format format */
3598 missingterm((char*)0);
3599 yylval.ival = OP_CONST;
3600 TERM(sublex_start());
3603 s = scan_str(s,FALSE,FALSE);
3604 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3605 "### Saw string before '%s'\n", s);
3607 if (PL_expect == XOPERATOR) {
3608 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3611 return ','; /* grandfather non-comma-format format */
3617 missingterm((char*)0);
3618 yylval.ival = OP_CONST;
3619 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3620 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
3621 yylval.ival = OP_STRINGIFY;
3625 TERM(sublex_start());
3628 s = scan_str(s,FALSE,FALSE);
3629 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3630 "### Saw backtick string before '%s'\n", s);
3632 if (PL_expect == XOPERATOR)
3633 no_op("Backticks",s);
3635 missingterm((char*)0);
3636 yylval.ival = OP_BACKTICK;
3638 TERM(sublex_start());
3642 if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s))
3643 Perl_warner(aTHX_ WARN_SYNTAX,"Can't use \\%c to mean $%c in expression",
3645 if (PL_expect == XOPERATOR)
3646 no_op("Backslash",s);
3650 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
3654 while (isDIGIT(*start) || *start == '_')
3656 if (*start == '.' && isDIGIT(start[1])) {
3657 s = scan_num(s, &yylval);
3660 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
3661 else if (!isALPHA(*start) && (PL_expect == XTERM || PL_expect == XREF || PL_expect == XSTATE)) {
3665 gv = gv_fetchpv(s, FALSE, SVt_PVCV);
3668 s = scan_num(s, &yylval);
3675 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
3714 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3716 /* Some keywords can be followed by any delimiter, including ':' */
3717 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
3718 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
3719 (PL_tokenbuf[0] == 'q' &&
3720 strchr("qwxr", PL_tokenbuf[1])))));
3722 /* x::* is just a word, unless x is "CORE" */
3723 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
3727 while (d < PL_bufend && isSPACE(*d))
3728 d++; /* no comments skipped here, or s### is misparsed */
3730 /* Is this a label? */
3731 if (!tmp && PL_expect == XSTATE
3732 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
3734 yylval.pval = savepv(PL_tokenbuf);
3739 /* Check for keywords */
3740 tmp = keyword(PL_tokenbuf, len);
3742 /* Is this a word before a => operator? */
3743 if (*d == '=' && d[1] == '>') {
3745 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf,0));
3746 yylval.opval->op_private = OPpCONST_BARE;
3747 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
3748 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
3752 if (tmp < 0) { /* second-class keyword? */
3753 GV *ogv = Nullgv; /* override (winner) */
3754 GV *hgv = Nullgv; /* hidden (loser) */
3755 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
3757 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
3760 if (GvIMPORTED_CV(gv))
3762 else if (! CvMETHOD(cv))
3766 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
3767 (gv = *gvp) != (GV*)&PL_sv_undef &&
3768 GvCVu(gv) && GvIMPORTED_CV(gv))
3774 tmp = 0; /* overridden by import or by GLOBAL */
3777 && -tmp==KEY_lock /* XXX generalizable kludge */
3779 && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
3781 tmp = 0; /* any sub overrides "weak" keyword */
3783 else { /* no override */
3787 if (ckWARN(WARN_AMBIGUOUS) && hgv
3788 && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
3789 Perl_warner(aTHX_ WARN_AMBIGUOUS,
3790 "Ambiguous call resolved as CORE::%s(), %s",
3791 GvENAME(hgv), "qualify as such or use &");
3798 default: /* not a keyword */
3802 char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
3804 /* Get the rest if it looks like a package qualifier */
3806 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
3808 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
3811 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
3812 *s == '\'' ? "'" : "::");
3817 if (PL_expect == XOPERATOR) {
3818 if (PL_bufptr == PL_linestart) {
3819 CopLINE_dec(PL_curcop);
3820 Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi);
3821 CopLINE_inc(PL_curcop);
3824 no_op("Bareword",s);
3827 /* Look for a subroutine with this name in current package,
3828 unless name is "Foo::", in which case Foo is a bearword
3829 (and a package name). */
3832 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
3834 if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
3835 Perl_warner(aTHX_ WARN_BAREWORD,
3836 "Bareword \"%s\" refers to nonexistent package",
3839 PL_tokenbuf[len] = '\0';
3846 gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
3849 /* if we saw a global override before, get the right name */
3852 sv = newSVpvn("CORE::GLOBAL::",14);
3853 sv_catpv(sv,PL_tokenbuf);
3856 sv = newSVpv(PL_tokenbuf,0);
3858 /* Presume this is going to be a bareword of some sort. */
3861 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3862 yylval.opval->op_private = OPpCONST_BARE;
3864 /* And if "Foo::", then that's what it certainly is. */
3869 /* See if it's the indirect object for a list operator. */
3871 if (PL_oldoldbufptr &&
3872 PL_oldoldbufptr < PL_bufptr &&
3873 (PL_oldoldbufptr == PL_last_lop
3874 || PL_oldoldbufptr == PL_last_uni) &&
3875 /* NO SKIPSPACE BEFORE HERE! */
3876 (PL_expect == XREF ||
3877 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
3879 bool immediate_paren = *s == '(';
3881 /* (Now we can afford to cross potential line boundary.) */
3884 /* Two barewords in a row may indicate method call. */
3886 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv)))
3889 /* If not a declared subroutine, it's an indirect object. */
3890 /* (But it's an indir obj regardless for sort.) */
3892 if ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
3893 ((!gv || !GvCVu(gv)) &&
3894 (PL_last_lop_op != OP_MAPSTART &&
3895 PL_last_lop_op != OP_GREPSTART))))
3897 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
3902 PL_expect = XOPERATOR;
3905 /* Is this a word before a => operator? */
3906 if (*s == '=' && s[1] == '>' && !pkgname) {
3908 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
3909 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
3910 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
3914 /* If followed by a paren, it's certainly a subroutine. */
3917 if (gv && GvCVu(gv)) {
3918 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
3919 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
3924 PL_nextval[PL_nexttoke].opval = yylval.opval;
3925 PL_expect = XOPERATOR;
3931 /* If followed by var or block, call it a method (unless sub) */
3933 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
3934 PL_last_lop = PL_oldbufptr;
3935 PL_last_lop_op = OP_METHOD;
3939 /* If followed by a bareword, see if it looks like indir obj. */
3941 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp = intuit_method(s,gv)))
3944 /* Not a method, so call it a subroutine (if defined) */
3946 if (gv && GvCVu(gv)) {
3948 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
3949 Perl_warner(aTHX_ WARN_AMBIGUOUS,
3950 "Ambiguous use of -%s resolved as -&%s()",
3951 PL_tokenbuf, PL_tokenbuf);
3952 /* Check for a constant sub */
3954 if ((sv = cv_const_sv(cv))) {
3956 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
3957 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
3958 yylval.opval->op_private = 0;
3962 /* Resolve to GV now. */
3963 op_free(yylval.opval);
3964 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
3965 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
3966 PL_last_lop = PL_oldbufptr;
3967 PL_last_lop_op = OP_ENTERSUB;
3968 /* Is there a prototype? */
3971 char *proto = SvPV((SV*)cv, len);
3974 if (strEQ(proto, "$"))
3976 if (*proto == '&' && *s == '{') {
3977 sv_setpv(PL_subname,"__ANON__");
3981 PL_nextval[PL_nexttoke].opval = yylval.opval;
3987 /* Call it a bare word */
3989 if (PL_hints & HINT_STRICT_SUBS)
3990 yylval.opval->op_private |= OPpCONST_STRICT;
3993 if (ckWARN(WARN_RESERVED)) {
3994 if (lastchar != '-') {
3995 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
3997 Perl_warner(aTHX_ WARN_RESERVED, PL_warn_reserved,
4004 if (lastchar && strchr("*%&", lastchar) && ckWARN_d(WARN_AMBIGUOUS)) {
4005 Perl_warner(aTHX_ WARN_AMBIGUOUS,
4006 "Operator or semicolon missing before %c%s",
4007 lastchar, PL_tokenbuf);
4008 Perl_warner(aTHX_ WARN_AMBIGUOUS,
4009 "Ambiguous use of %c resolved as operator %c",
4010 lastchar, lastchar);
4016 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4017 newSVpv(CopFILE(PL_curcop),0));
4021 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4022 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
4025 case KEY___PACKAGE__:
4026 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4028 ? newSVsv(PL_curstname)
4037 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
4038 char *pname = "main";
4039 if (PL_tokenbuf[2] == 'D')
4040 pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash);
4041 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);
4044 GvIOp(gv) = newIO();
4045 IoIFP(GvIOp(gv)) = PL_rsfp;
4046 #if defined(HAS_FCNTL) && defined(F_SETFD)
4048 int fd = PerlIO_fileno(PL_rsfp);
4049 fcntl(fd,F_SETFD,fd >= 3);
4052 /* Mark this internal pseudo-handle as clean */
4053 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4055 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
4056 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
4057 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
4059 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
4060 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
4061 /* if the script was opened in binmode, we need to revert
4062 * it to text mode for compatibility; but only iff it has CRs
4063 * XXX this is a questionable hack at best. */
4064 if (PL_bufend-PL_bufptr > 2
4065 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
4068 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
4069 loc = PerlIO_tell(PL_rsfp);
4070 (void)PerlIO_seek(PL_rsfp, 0L, 0);
4073 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
4075 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
4076 #endif /* NETWARE */
4077 #ifdef PERLIO_IS_STDIO /* really? */
4078 # if defined(__BORLANDC__)
4079 /* XXX see note in do_binmode() */
4080 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
4084 PerlIO_seek(PL_rsfp, loc, 0);
4088 #ifdef PERLIO_LAYERS
4089 if (UTF && !IN_BYTES)
4090 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
4103 if (PL_expect == XSTATE) {
4110 if (*s == ':' && s[1] == ':') {
4113 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4114 if (!(tmp = keyword(PL_tokenbuf, len)))
4115 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
4129 LOP(OP_ACCEPT,XTERM);
4135 LOP(OP_ATAN2,XTERM);
4141 LOP(OP_BINMODE,XTERM);
4144 LOP(OP_BLESS,XTERM);
4153 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
4170 if (!PL_cryptseen) {
4171 PL_cryptseen = TRUE;
4175 LOP(OP_CRYPT,XTERM);
4178 LOP(OP_CHMOD,XTERM);
4181 LOP(OP_CHOWN,XTERM);
4184 LOP(OP_CONNECT,XTERM);
4200 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4204 PL_hints |= HINT_BLOCK_SCOPE;
4214 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
4215 LOP(OP_DBMOPEN,XTERM);
4221 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4228 yylval.ival = CopLINE(PL_curcop);
4242 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4243 UNIBRACK(OP_ENTEREVAL);
4258 case KEY_endhostent:
4264 case KEY_endservent:
4267 case KEY_endprotoent:
4278 yylval.ival = CopLINE(PL_curcop);
4280 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4282 if ((PL_bufend - p) >= 3 &&
4283 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4285 else if ((PL_bufend - p) >= 4 &&
4286 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4289 if (isIDFIRST_lazy_if(p,UTF)) {
4290 p = scan_ident(p, PL_bufend,
4291 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4295 Perl_croak(aTHX_ "Missing $ on loop variable");
4300 LOP(OP_FORMLINE,XTERM);
4306 LOP(OP_FCNTL,XTERM);
4312 LOP(OP_FLOCK,XTERM);
4321 LOP(OP_GREPSTART, XREF);
4324 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4339 case KEY_getpriority:
4340 LOP(OP_GETPRIORITY,XTERM);
4342 case KEY_getprotobyname:
4345 case KEY_getprotobynumber:
4346 LOP(OP_GPBYNUMBER,XTERM);
4348 case KEY_getprotoent:
4360 case KEY_getpeername:
4361 UNI(OP_GETPEERNAME);
4363 case KEY_gethostbyname:
4366 case KEY_gethostbyaddr:
4367 LOP(OP_GHBYADDR,XTERM);
4369 case KEY_gethostent:
4372 case KEY_getnetbyname:
4375 case KEY_getnetbyaddr:
4376 LOP(OP_GNBYADDR,XTERM);
4381 case KEY_getservbyname:
4382 LOP(OP_GSBYNAME,XTERM);
4384 case KEY_getservbyport:
4385 LOP(OP_GSBYPORT,XTERM);
4387 case KEY_getservent:
4390 case KEY_getsockname:
4391 UNI(OP_GETSOCKNAME);
4393 case KEY_getsockopt:
4394 LOP(OP_GSOCKOPT,XTERM);
4416 yylval.ival = CopLINE(PL_curcop);
4420 LOP(OP_INDEX,XTERM);
4426 LOP(OP_IOCTL,XTERM);
4438 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4470 LOP(OP_LISTEN,XTERM);
4479 s = scan_pat(s,OP_MATCH);
4480 TERM(sublex_start());
4483 LOP(OP_MAPSTART, XREF);
4486 LOP(OP_MKDIR,XTERM);
4489 LOP(OP_MSGCTL,XTERM);
4492 LOP(OP_MSGGET,XTERM);
4495 LOP(OP_MSGRCV,XTERM);
4498 LOP(OP_MSGSND,XTERM);
4504 if (isIDFIRST_lazy_if(s,UTF)) {
4505 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4506 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4508 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
4509 if (!PL_in_my_stash) {
4512 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4520 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4527 if (PL_expect != XSTATE)
4528 yyerror("\"no\" not allowed in expression");
4529 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4530 s = force_version(s);
4535 if (*s == '(' || (s = skipspace(s), *s == '('))
4542 if (isIDFIRST_lazy_if(s,UTF)) {
4544 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
4546 if (strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE))
4547 Perl_warner(aTHX_ WARN_PRECEDENCE,
4548 "Precedence problem: open %.*s should be open(%.*s)",
4554 yylval.ival = OP_OR;
4564 LOP(OP_OPEN_DIR,XTERM);
4567 checkcomma(s,PL_tokenbuf,"filehandle");
4571 checkcomma(s,PL_tokenbuf,"filehandle");
4590 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4594 LOP(OP_PIPE_OP,XTERM);
4597 s = scan_str(s,FALSE,FALSE);
4599 missingterm((char*)0);
4600 yylval.ival = OP_CONST;
4601 TERM(sublex_start());
4607 s = scan_str(s,FALSE,FALSE);
4609 missingterm((char*)0);
4611 if (SvCUR(PL_lex_stuff)) {
4614 d = SvPV_force(PL_lex_stuff, len);
4617 for (; isSPACE(*d) && len; --len, ++d) ;
4620 if (!warned && ckWARN(WARN_QW)) {
4621 for (; !isSPACE(*d) && len; --len, ++d) {
4623 Perl_warner(aTHX_ WARN_QW,
4624 "Possible attempt to separate words with commas");
4627 else if (*d == '#') {
4628 Perl_warner(aTHX_ WARN_QW,
4629 "Possible attempt to put comments in qw() list");
4635 for (; !isSPACE(*d) && len; --len, ++d) ;
4637 sv = newSVpvn(b, d-b);
4638 if (DO_UTF8(PL_lex_stuff))
4640 words = append_elem(OP_LIST, words,
4641 newSVOP(OP_CONST, 0, tokeq(sv)));
4645 PL_nextval[PL_nexttoke].opval = words;
4650 SvREFCNT_dec(PL_lex_stuff);
4651 PL_lex_stuff = Nullsv;
4657 s = scan_str(s,FALSE,FALSE);
4659 missingterm((char*)0);
4660 yylval.ival = OP_STRINGIFY;
4661 if (SvIVX(PL_lex_stuff) == '\'')
4662 SvIVX(PL_lex_stuff) = 0; /* qq'$foo' should intepolate */
4663 TERM(sublex_start());
4666 s = scan_pat(s,OP_QR);
4667 TERM(sublex_start());
4670 s = scan_str(s,FALSE,FALSE);
4672 missingterm((char*)0);
4673 yylval.ival = OP_BACKTICK;
4675 TERM(sublex_start());
4682 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
4683 s = force_version(s);
4686 *PL_tokenbuf = '\0';
4687 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4688 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
4689 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
4691 yyerror("<> should be quotes");
4699 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4703 LOP(OP_RENAME,XTERM);
4712 LOP(OP_RINDEX,XTERM);
4735 LOP(OP_REVERSE,XTERM);
4746 TERM(sublex_start());
4748 TOKEN(1); /* force error */
4757 LOP(OP_SELECT,XTERM);
4763 LOP(OP_SEMCTL,XTERM);
4766 LOP(OP_SEMGET,XTERM);
4769 LOP(OP_SEMOP,XTERM);
4775 LOP(OP_SETPGRP,XTERM);
4777 case KEY_setpriority:
4778 LOP(OP_SETPRIORITY,XTERM);
4780 case KEY_sethostent:
4786 case KEY_setservent:
4789 case KEY_setprotoent:
4799 LOP(OP_SEEKDIR,XTERM);
4801 case KEY_setsockopt:
4802 LOP(OP_SSOCKOPT,XTERM);
4808 LOP(OP_SHMCTL,XTERM);
4811 LOP(OP_SHMGET,XTERM);
4814 LOP(OP_SHMREAD,XTERM);
4817 LOP(OP_SHMWRITE,XTERM);
4820 LOP(OP_SHUTDOWN,XTERM);
4829 LOP(OP_SOCKET,XTERM);
4831 case KEY_socketpair:
4832 LOP(OP_SOCKPAIR,XTERM);
4835 checkcomma(s,PL_tokenbuf,"subroutine name");
4837 if (*s == ';' || *s == ')') /* probably a close */
4838 Perl_croak(aTHX_ "sort is now a reserved word");
4840 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4844 LOP(OP_SPLIT,XTERM);
4847 LOP(OP_SPRINTF,XTERM);
4850 LOP(OP_SPLICE,XTERM);
4865 LOP(OP_SUBSTR,XTERM);
4871 char tmpbuf[sizeof PL_tokenbuf];
4872 SSize_t tboffset = 0;
4873 expectation attrful;
4874 bool have_name, have_proto;
4879 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
4880 (*s == ':' && s[1] == ':'))
4883 attrful = XATTRBLOCK;
4884 /* remember buffer pos'n for later force_word */
4885 tboffset = s - PL_oldbufptr;
4886 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4887 if (strchr(tmpbuf, ':'))
4888 sv_setpv(PL_subname, tmpbuf);
4890 sv_setsv(PL_subname,PL_curstname);
4891 sv_catpvn(PL_subname,"::",2);
4892 sv_catpvn(PL_subname,tmpbuf,len);
4899 Perl_croak(aTHX_ "Missing name in \"my sub\"");
4900 PL_expect = XTERMBLOCK;
4901 attrful = XATTRTERM;
4902 sv_setpv(PL_subname,"?");
4906 if (key == KEY_format) {
4908 PL_lex_formbrack = PL_lex_brackets + 1;
4910 (void) force_word(PL_oldbufptr + tboffset, WORD,
4915 /* Look for a prototype */
4919 s = scan_str(s,FALSE,FALSE);
4921 Perl_croak(aTHX_ "Prototype not terminated");
4923 d = SvPVX(PL_lex_stuff);
4925 for (p = d; *p; ++p) {
4930 SvCUR(PL_lex_stuff) = tmp;
4938 if (*s == ':' && s[1] != ':')
4939 PL_expect = attrful;
4942 PL_nextval[PL_nexttoke].opval =
4943 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
4944 PL_lex_stuff = Nullsv;
4948 sv_setpv(PL_subname,"__ANON__");
4951 (void) force_word(PL_oldbufptr + tboffset, WORD,
4960 LOP(OP_SYSTEM,XREF);
4963 LOP(OP_SYMLINK,XTERM);
4966 LOP(OP_SYSCALL,XTERM);
4969 LOP(OP_SYSOPEN,XTERM);
4972 LOP(OP_SYSSEEK,XTERM);
4975 LOP(OP_SYSREAD,XTERM);
4978 LOP(OP_SYSWRITE,XTERM);
4982 TERM(sublex_start());
5003 LOP(OP_TRUNCATE,XTERM);
5015 yylval.ival = CopLINE(PL_curcop);
5019 yylval.ival = CopLINE(PL_curcop);
5023 LOP(OP_UNLINK,XTERM);
5029 LOP(OP_UNPACK,XTERM);
5032 LOP(OP_UTIME,XTERM);
5038 LOP(OP_UNSHIFT,XTERM);
5041 if (PL_expect != XSTATE)
5042 yyerror("\"use\" not allowed in expression");
5044 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
5045 s = force_version(s);
5046 if (*s == ';' || (s = skipspace(s), *s == ';')) {
5047 PL_nextval[PL_nexttoke].opval = Nullop;
5052 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5053 s = force_version(s);
5065 yylval.ival = CopLINE(PL_curcop);
5069 PL_hints |= HINT_BLOCK_SCOPE;
5076 LOP(OP_WAITPID,XTERM);
5084 static char ctl_l[2];
5086 if (ctl_l[0] == '\0')
5087 ctl_l[0] = toCTRL('L');
5088 gv_fetchpv(ctl_l,TRUE, SVt_PV);
5091 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
5096 if (PL_expect == XOPERATOR)
5102 yylval.ival = OP_XOR;
5107 TERM(sublex_start());
5112 #pragma segment Main
5116 S_pending_ident(pTHX)
5120 /* pit holds the identifier we read and pending_ident is reset */
5121 char pit = PL_pending_ident;
5122 PL_pending_ident = 0;
5124 DEBUG_T({ PerlIO_printf(Perl_debug_log,
5125 "### Tokener saw identifier '%s'\n", PL_tokenbuf); });
5127 /* if we're in a my(), we can't allow dynamics here.
5128 $foo'bar has already been turned into $foo::bar, so
5129 just check for colons.
5131 if it's a legal name, the OP is a PADANY.
5134 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
5135 if (strchr(PL_tokenbuf,':'))
5136 yyerror(Perl_form(aTHX_ "No package name allowed for "
5137 "variable %s in \"our\"",
5139 tmp = pad_allocmy(PL_tokenbuf);
5142 if (strchr(PL_tokenbuf,':'))
5143 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
5145 yylval.opval = newOP(OP_PADANY, 0);
5146 yylval.opval->op_targ = pad_allocmy(PL_tokenbuf);
5152 build the ops for accesses to a my() variable.
5154 Deny my($a) or my($b) in a sort block, *if* $a or $b is
5155 then used in a comparison. This catches most, but not
5156 all cases. For instance, it catches
5157 sort { my($a); $a <=> $b }
5159 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
5160 (although why you'd do that is anyone's guess).
5163 if (!strchr(PL_tokenbuf,':')) {
5165 /* Check for single character per-thread SVs */
5166 if (PL_tokenbuf[0] == '$' && PL_tokenbuf[2] == '\0'
5167 && !isALPHA(PL_tokenbuf[1]) /* Rule out obvious non-threadsvs */
5168 && (tmp = find_threadsv(&PL_tokenbuf[1])) != NOT_IN_PAD)
5170 yylval.opval = newOP(OP_THREADSV, 0);
5171 yylval.opval->op_targ = tmp;
5174 #endif /* USE_THREADS */
5175 if ((tmp = pad_findmy(PL_tokenbuf)) != NOT_IN_PAD) {
5176 SV *namesv = AvARRAY(PL_comppad_name)[tmp];
5177 /* might be an "our" variable" */
5178 if (SvFLAGS(namesv) & SVpad_OUR) {
5179 /* build ops for a bareword */
5180 SV *sym = newSVpv(HvNAME(GvSTASH(namesv)),0);
5181 sv_catpvn(sym, "::", 2);
5182 sv_catpv(sym, PL_tokenbuf+1);
5183 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
5184 yylval.opval->op_private = OPpCONST_ENTERED;
5185 gv_fetchpv(SvPVX(sym),
5187 ? (GV_ADDMULTI | GV_ADDINEVAL)
5190 ((PL_tokenbuf[0] == '$') ? SVt_PV
5191 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5196 /* if it's a sort block and they're naming $a or $b */
5197 if (PL_last_lop_op == OP_SORT &&
5198 PL_tokenbuf[0] == '$' &&
5199 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
5202 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
5203 d < PL_bufend && *d != '\n';
5206 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
5207 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
5213 yylval.opval = newOP(OP_PADANY, 0);
5214 yylval.opval->op_targ = tmp;
5220 Whine if they've said @foo in a doublequoted string,
5221 and @foo isn't a variable we can find in the symbol
5224 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
5225 GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
5226 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
5227 && ckWARN(WARN_AMBIGUOUS))
5229 /* Downgraded from fatal to warning 20000522 mjd */
5230 Perl_warner(aTHX_ WARN_AMBIGUOUS,
5231 "Possible unintended interpolation of %s in string",
5236 /* build ops for a bareword */
5237 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
5238 yylval.opval->op_private = OPpCONST_ENTERED;
5239 gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
5240 ((PL_tokenbuf[0] == '$') ? SVt_PV
5241 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5247 Perl_keyword(pTHX_ register char *d, I32 len)
5252 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
5253 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
5254 if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__;
5255 if (strEQ(d,"__DATA__")) return KEY___DATA__;
5256 if (strEQ(d,"__END__")) return KEY___END__;
5260 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
5265 if (strEQ(d,"and")) return -KEY_and;
5266 if (strEQ(d,"abs")) return -KEY_abs;
5269 if (strEQ(d,"alarm")) return -KEY_alarm;
5270 if (strEQ(d,"atan2")) return -KEY_atan2;
5273 if (strEQ(d,"accept")) return -KEY_accept;
5278 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
5281 if (strEQ(d,"bless")) return -KEY_bless;
5282 if (strEQ(d,"bind")) return -KEY_bind;
5283 if (strEQ(d,"binmode")) return -KEY_binmode;
5286 if (strEQ(d,"CORE")) return -KEY_CORE;
5287 if (strEQ(d,"CHECK")) return KEY_CHECK;
5292 if (strEQ(d,"cmp")) return -KEY_cmp;
5293 if (strEQ(d,"chr")) return -KEY_chr;
5294 if (strEQ(d,"cos")) return -KEY_cos;
5297 if (strEQ(d,"chop")) return -KEY_chop;
5300 if (strEQ(d,"close")) return -KEY_close;
5301 if (strEQ(d,"chdir")) return -KEY_chdir;
5302 if (strEQ(d,"chomp")) return -KEY_chomp;
5303 if (strEQ(d,"chmod")) return -KEY_chmod;
5304 if (strEQ(d,"chown")) return -KEY_chown;
5305 if (strEQ(d,"crypt")) return -KEY_crypt;
5308 if (strEQ(d,"chroot")) return -KEY_chroot;
5309 if (strEQ(d,"caller")) return -KEY_caller;
5312 if (strEQ(d,"connect")) return -KEY_connect;
5315 if (strEQ(d,"closedir")) return -KEY_closedir;
5316 if (strEQ(d,"continue")) return -KEY_continue;
5321 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
5326 if (strEQ(d,"do")) return KEY_do;
5329 if (strEQ(d,"die")) return -KEY_die;
5332 if (strEQ(d,"dump")) return -KEY_dump;
5335 if (strEQ(d,"delete")) return KEY_delete;
5338 if (strEQ(d,"defined")) return KEY_defined;
5339 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
5342 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
5347 if (strEQ(d,"END")) return KEY_END;
5352 if (strEQ(d,"eq")) return -KEY_eq;
5355 if (strEQ(d,"eof")) return -KEY_eof;
5356 if (strEQ(d,"exp")) return -KEY_exp;
5359 if (strEQ(d,"else")) return KEY_else;
5360 if (strEQ(d,"exit")) return -KEY_exit;
5361 if (strEQ(d,"eval")) return KEY_eval;
5362 if (strEQ(d,"exec")) return -KEY_exec;
5363 if (strEQ(d,"each")) return -KEY_each;
5366 if (strEQ(d,"elsif")) return KEY_elsif;
5369 if (strEQ(d,"exists")) return KEY_exists;
5370 if (strEQ(d,"elseif")) Perl_warn(aTHX_ "elseif should be elsif");
5373 if (strEQ(d,"endgrent")) return -KEY_endgrent;
5374 if (strEQ(d,"endpwent")) return -KEY_endpwent;
5377 if (strEQ(d,"endnetent")) return -KEY_endnetent;
5380 if (strEQ(d,"endhostent")) return -KEY_endhostent;
5381 if (strEQ(d,"endservent")) return -KEY_endservent;
5384 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
5391 if (strEQ(d,"for")) return KEY_for;
5394 if (strEQ(d,"fork")) return -KEY_fork;
5397 if (strEQ(d,"fcntl")) return -KEY_fcntl;
5398 if (strEQ(d,"flock")) return -KEY_flock;
5401 if (strEQ(d,"format")) return KEY_format;
5402 if (strEQ(d,"fileno")) return -KEY_fileno;
5405 if (strEQ(d,"foreach")) return KEY_foreach;
5408 if (strEQ(d,"formline")) return -KEY_formline;
5413 if (strnEQ(d,"get",3)) {
5418 if (strEQ(d,"ppid")) return -KEY_getppid;
5419 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
5422 if (strEQ(d,"pwent")) return -KEY_getpwent;
5423 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
5424 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
5427 if (strEQ(d,"peername")) return -KEY_getpeername;
5428 if (strEQ(d,"protoent")) return -KEY_getprotoent;
5429 if (strEQ(d,"priority")) return -KEY_getpriority;
5432 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
5435 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
5439 else if (*d == 'h') {
5440 if (strEQ(d,"hostbyname")) return -KEY_gethostbyname;
5441 if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr;
5442 if (strEQ(d,"hostent")) return -KEY_gethostent;
5444 else if (*d == 'n') {
5445 if (strEQ(d,"netbyname")) return -KEY_getnetbyname;
5446 if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr;
5447 if (strEQ(d,"netent")) return -KEY_getnetent;
5449 else if (*d == 's') {
5450 if (strEQ(d,"servbyname")) return -KEY_getservbyname;
5451 if (strEQ(d,"servbyport")) return -KEY_getservbyport;
5452 if (strEQ(d,"servent")) return -KEY_getservent;
5453 if (strEQ(d,"sockname")) return -KEY_getsockname;
5454 if (strEQ(d,"sockopt")) return -KEY_getsockopt;
5456 else if (*d == 'g') {
5457 if (strEQ(d,"grent")) return -KEY_getgrent;
5458 if (strEQ(d,"grnam")) return -KEY_getgrnam;
5459 if (strEQ(d,"grgid")) return -KEY_getgrgid;
5461 else if (*d == 'l') {
5462 if (strEQ(d,"login")) return -KEY_getlogin;
5464 else if (strEQ(d,"c")) return -KEY_getc;
5469 if (strEQ(d,"gt")) return -KEY_gt;
5470 if (strEQ(d,"ge")) return -KEY_ge;
5473 if (strEQ(d,"grep")) return KEY_grep;
5474 if (strEQ(d,"goto")) return KEY_goto;
5475 if (strEQ(d,"glob")) return KEY_glob;
5478 if (strEQ(d,"gmtime")) return -KEY_gmtime;
5483 if (strEQ(d,"hex")) return -KEY_hex;
5486 if (strEQ(d,"INIT")) return KEY_INIT;
5491 if (strEQ(d,"if")) return KEY_if;
5494 if (strEQ(d,"int")) return -KEY_int;
5497 if (strEQ(d,"index")) return -KEY_index;
5498 if (strEQ(d,"ioctl")) return -KEY_ioctl;
5503 if (strEQ(d,"join")) return -KEY_join;
5507 if (strEQ(d,"keys")) return -KEY_keys;
5508 if (strEQ(d,"kill")) return -KEY_kill;
5514 if (strEQ(d,"lt")) return -KEY_lt;
5515 if (strEQ(d,"le")) return -KEY_le;
5516 if (strEQ(d,"lc")) return -KEY_lc;
5519 if (strEQ(d,"log")) return -KEY_log;
5522 if (strEQ(d,"last")) return KEY_last;
5523 if (strEQ(d,"link")) return -KEY_link;
5524 if (strEQ(d,"lock")) return -KEY_lock;
5527 if (strEQ(d,"local")) return KEY_local;
5528 if (strEQ(d,"lstat")) return -KEY_lstat;
5531 if (strEQ(d,"length")) return -KEY_length;
5532 if (strEQ(d,"listen")) return -KEY_listen;
5535 if (strEQ(d,"lcfirst")) return -KEY_lcfirst;
5538 if (strEQ(d,"localtime")) return -KEY_localtime;
5544 case 1: return KEY_m;
5546 if (strEQ(d,"my")) return KEY_my;
5549 if (strEQ(d,"map")) return KEY_map;
5552 if (strEQ(d,"mkdir")) return -KEY_mkdir;
5555 if (strEQ(d,"msgctl")) return -KEY_msgctl;
5556 if (strEQ(d,"msgget")) return -KEY_msgget;
5557 if (strEQ(d,"msgrcv")) return -KEY_msgrcv;
5558 if (strEQ(d,"msgsnd")) return -KEY_msgsnd;
5563 if (strEQ(d,"next")) return KEY_next;
5564 if (strEQ(d,"ne")) return -KEY_ne;
5565 if (strEQ(d,"not")) return -KEY_not;
5566 if (strEQ(d,"no")) return KEY_no;
5571 if (strEQ(d,"or")) return -KEY_or;
5574 if (strEQ(d,"ord")) return -KEY_ord;
5575 if (strEQ(d,"oct")) return -KEY_oct;
5576 if (strEQ(d,"our")) return KEY_our;
5579 if (strEQ(d,"open")) return -KEY_open;
5582 if (strEQ(d,"opendir")) return -KEY_opendir;
5589 if (strEQ(d,"pop")) return -KEY_pop;
5590 if (strEQ(d,"pos")) return KEY_pos;
5593 if (strEQ(d,"push")) return -KEY_push;
5594 if (strEQ(d,"pack")) return -KEY_pack;
5595 if (strEQ(d,"pipe")) return -KEY_pipe;
5598 if (strEQ(d,"print")) return KEY_print;
5601 if (strEQ(d,"printf")) return KEY_printf;
5604 if (strEQ(d,"package")) return KEY_package;
5607 if (strEQ(d,"prototype")) return KEY_prototype;
5612 if (strEQ(d,"q")) return KEY_q;
5613 if (strEQ(d,"qr")) return KEY_qr;
5614 if (strEQ(d,"qq")) return KEY_qq;
5615 if (strEQ(d,"qw")) return KEY_qw;
5616 if (strEQ(d,"qx")) return KEY_qx;
5618 else if (strEQ(d,"quotemeta")) return -KEY_quotemeta;
5623 if (strEQ(d,"ref")) return -KEY_ref;
5626 if (strEQ(d,"read")) return -KEY_read;
5627 if (strEQ(d,"rand")) return -KEY_rand;
5628 if (strEQ(d,"recv")) return -KEY_recv;
5629 if (strEQ(d,"redo")) return KEY_redo;
5632 if (strEQ(d,"rmdir")) return -KEY_rmdir;
5633 if (strEQ(d,"reset")) return -KEY_reset;
5636 if (strEQ(d,"return")) return KEY_return;
5637 if (strEQ(d,"rename")) return -KEY_rename;
5638 if (strEQ(d,"rindex")) return -KEY_rindex;
5641 if (strEQ(d,"require")) return KEY_require;
5642 if (strEQ(d,"reverse")) return -KEY_reverse;
5643 if (strEQ(d,"readdir")) return -KEY_readdir;
5646 if (strEQ(d,"readlink")) return -KEY_readlink;
5647 if (strEQ(d,"readline")) return -KEY_readline;
5648 if (strEQ(d,"readpipe")) return -KEY_readpipe;
5651 if (strEQ(d,"rewinddir")) return -KEY_rewinddir;
5657 case 0: return KEY_s;
5659 if (strEQ(d,"scalar")) return KEY_scalar;
5664 if (strEQ(d,"seek")) return -KEY_seek;
5665 if (strEQ(d,"send")) return -KEY_send;
5668 if (strEQ(d,"semop")) return -KEY_semop;
5671 if (strEQ(d,"select")) return -KEY_select;
5672 if (strEQ(d,"semctl")) return -KEY_semctl;
5673 if (strEQ(d,"semget")) return -KEY_semget;
5676 if (strEQ(d,"setpgrp")) return -KEY_setpgrp;
5677 if (strEQ(d,"seekdir")) return -KEY_seekdir;
5680 if (strEQ(d,"setpwent")) return -KEY_setpwent;
5681 if (strEQ(d,"setgrent")) return -KEY_setgrent;
5684 if (strEQ(d,"setnetent")) return -KEY_setnetent;
5687 if (strEQ(d,"setsockopt")) return -KEY_setsockopt;
5688 if (strEQ(d,"sethostent")) return -KEY_sethostent;
5689 if (strEQ(d,"setservent")) return -KEY_setservent;
5692 if (strEQ(d,"setpriority")) return -KEY_setpriority;
5693 if (strEQ(d,"setprotoent")) return -KEY_setprotoent;
5700 if (strEQ(d,"shift")) return -KEY_shift;
5703 if (strEQ(d,"shmctl")) return -KEY_shmctl;
5704 if (strEQ(d,"shmget")) return -KEY_shmget;
5707 if (strEQ(d,"shmread")) return -KEY_shmread;
5710 if (strEQ(d,"shmwrite")) return -KEY_shmwrite;
5711 if (strEQ(d,"shutdown")) return -KEY_shutdown;
5716 if (strEQ(d,"sin")) return -KEY_sin;
5719 if (strEQ(d,"sleep")) return -KEY_sleep;
5722 if (strEQ(d,"sort")) return KEY_sort;
5723 if (strEQ(d,"socket")) return -KEY_socket;
5724 if (strEQ(d,"socketpair")) return -KEY_socketpair;
5727 if (strEQ(d,"split")) return KEY_split;
5728 if (strEQ(d,"sprintf")) return -KEY_sprintf;
5729 if (strEQ(d,"splice")) return -KEY_splice;
5732 if (strEQ(d,"sqrt")) return -KEY_sqrt;
5735 if (strEQ(d,"srand")) return -KEY_srand;
5738 if (strEQ(d,"stat")) return -KEY_stat;
5739 if (strEQ(d,"study")) return KEY_study;
5742 if (strEQ(d,"substr")) return -KEY_substr;
5743 if (strEQ(d,"sub")) return KEY_sub;
5748 if (strEQ(d,"system")) return -KEY_system;
5751 if (strEQ(d,"symlink")) return -KEY_symlink;
5752 if (strEQ(d,"syscall")) return -KEY_syscall;
5753 if (strEQ(d,"sysopen")) return -KEY_sysopen;
5754 if (strEQ(d,"sysread")) return -KEY_sysread;
5755 if (strEQ(d,"sysseek")) return -KEY_sysseek;
5758 if (strEQ(d,"syswrite")) return -KEY_syswrite;
5767 if (strEQ(d,"tr")) return KEY_tr;
5770 if (strEQ(d,"tie")) return KEY_tie;
5773 if (strEQ(d,"tell")) return -KEY_tell;
5774 if (strEQ(d,"tied")) return KEY_tied;
5775 if (strEQ(d,"time")) return -KEY_time;
5778 if (strEQ(d,"times")) return -KEY_times;
5781 if (strEQ(d,"telldir")) return -KEY_telldir;
5784 if (strEQ(d,"truncate")) return -KEY_truncate;
5791 if (strEQ(d,"uc")) return -KEY_uc;
5794 if (strEQ(d,"use")) return KEY_use;
5797 if (strEQ(d,"undef")) return KEY_undef;
5798 if (strEQ(d,"until")) return KEY_until;
5799 if (strEQ(d,"untie")) return KEY_untie;
5800 if (strEQ(d,"utime")) return -KEY_utime;
5801 if (strEQ(d,"umask")) return -KEY_umask;
5804 if (strEQ(d,"unless")) return KEY_unless;
5805 if (strEQ(d,"unpack")) return -KEY_unpack;
5806 if (strEQ(d,"unlink")) return -KEY_unlink;
5809 if (strEQ(d,"unshift")) return -KEY_unshift;
5810 if (strEQ(d,"ucfirst")) return -KEY_ucfirst;
5815 if (strEQ(d,"values")) return -KEY_values;
5816 if (strEQ(d,"vec")) return -KEY_vec;
5821 if (strEQ(d,"warn")) return -KEY_warn;
5822 if (strEQ(d,"wait")) return -KEY_wait;
5825 if (strEQ(d,"while")) return KEY_while;
5826 if (strEQ(d,"write")) return -KEY_write;
5829 if (strEQ(d,"waitpid")) return -KEY_waitpid;
5832 if (strEQ(d,"wantarray")) return -KEY_wantarray;
5837 if (len == 1) return -KEY_x;
5838 if (strEQ(d,"xor")) return -KEY_xor;
5841 if (len == 1) return KEY_y;
5850 S_checkcomma(pTHX_ register char *s, char *name, char *what)
5854 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
5855 if (ckWARN(WARN_SYNTAX)) {
5857 for (w = s+2; *w && level; w++) {
5864 for (; *w && isSPACE(*w); w++) ;
5865 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
5866 Perl_warner(aTHX_ WARN_SYNTAX,
5867 "%s (...) interpreted as function",name);
5870 while (s < PL_bufend && isSPACE(*s))
5874 while (s < PL_bufend && isSPACE(*s))
5876 if (isIDFIRST_lazy_if(s,UTF)) {
5878 while (isALNUM_lazy_if(s,UTF))
5880 while (s < PL_bufend && isSPACE(*s))
5885 kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
5889 Perl_croak(aTHX_ "No comma allowed after %s", what);
5894 /* Either returns sv, or mortalizes sv and returns a new SV*.
5895 Best used as sv=new_constant(..., sv, ...).
5896 If s, pv are NULL, calls subroutine with one argument,
5897 and type is used with error messages only. */
5900 S_new_constant(pTHX_ char *s, STRLEN len, const char *key, SV *sv, SV *pv,
5904 HV *table = GvHV(PL_hintgv); /* ^H */
5908 const char *why1, *why2, *why3;
5910 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
5913 why2 = strEQ(key,"charnames")
5914 ? "(possibly a missing \"use charnames ...\")"
5916 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
5917 (type ? type: "undef"), why2);
5919 /* This is convoluted and evil ("goto considered harmful")
5920 * but I do not understand the intricacies of all the different
5921 * failure modes of %^H in here. The goal here is to make
5922 * the most probable error message user-friendly. --jhi */
5927 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
5928 (type ? type: "undef"), why1, why2, why3);
5930 yyerror(SvPVX(msg));
5934 cvp = hv_fetch(table, key, strlen(key), FALSE);
5935 if (!cvp || !SvOK(*cvp)) {
5938 why3 = "} is not defined";
5941 sv_2mortal(sv); /* Parent created it permanently */
5944 pv = sv_2mortal(newSVpvn(s, len));
5946 typesv = sv_2mortal(newSVpv(type, 0));
5948 typesv = &PL_sv_undef;
5950 PUSHSTACKi(PERLSI_OVERLOAD);
5962 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
5966 /* Check the eval first */
5967 if (!PL_in_eval && SvTRUE(ERRSV)) {
5969 sv_catpv(ERRSV, "Propagated");
5970 yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */
5972 res = SvREFCNT_inc(sv);
5976 (void)SvREFCNT_inc(res);
5985 why1 = "Call to &{$^H{";
5987 why3 = "}} did not return a defined value";
5996 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
5998 register char *d = dest;
5999 register char *e = d + destlen - 3; /* two-character token, ending NUL */
6002 Perl_croak(aTHX_ ident_too_long);
6003 if (isALNUM(*s)) /* UTF handled below */
6005 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
6010 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
6014 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
6015 char *t = s + UTF8SKIP(s);
6016 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
6018 if (d + (t - s) > e)
6019 Perl_croak(aTHX_ ident_too_long);
6020 Copy(s, d, t - s, char);
6033 S_scan_ident(pTHX_ register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni)
6043 e = d + destlen - 3; /* two-character token, ending NUL */
6045 while (isDIGIT(*s)) {
6047 Perl_croak(aTHX_ ident_too_long);
6054 Perl_croak(aTHX_ ident_too_long);
6055 if (isALNUM(*s)) /* UTF handled below */
6057 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
6062 else if (*s == ':' && s[1] == ':') {
6066 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
6067 char *t = s + UTF8SKIP(s);
6068 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
6070 if (d + (t - s) > e)
6071 Perl_croak(aTHX_ ident_too_long);
6072 Copy(s, d, t - s, char);
6083 if (PL_lex_state != LEX_NORMAL)
6084 PL_lex_state = LEX_INTERPENDMAYBE;
6087 if (*s == '$' && s[1] &&
6088 (isALNUM_lazy_if(s+1,UTF) || strchr("${", s[1]) || strnEQ(s+1,"::",2)) )
6101 if (*d == '^' && *s && isCONTROLVAR(*s)) {
6106 if (isSPACE(s[-1])) {
6109 if (!SPACE_OR_TAB(ch)) {
6115 if (isIDFIRST_lazy_if(d,UTF)) {
6119 while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') {
6121 while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e))
6124 Copy(s, d, e - s, char);
6129 while ((isALNUM(*s) || *s == ':') && d < e)
6132 Perl_croak(aTHX_ ident_too_long);
6135 while (s < send && SPACE_OR_TAB(*s)) s++;
6136 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
6137 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
6138 const char *brack = *s == '[' ? "[...]" : "{...}";
6139 Perl_warner(aTHX_ WARN_AMBIGUOUS,
6140 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
6141 funny, dest, brack, funny, dest, brack);
6144 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
6148 /* Handle extended ${^Foo} variables
6149 * 1999-02-27 mjd-perl-patch@plover.com */
6150 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
6154 while (isALNUM(*s) && d < e) {
6158 Perl_croak(aTHX_ ident_too_long);
6163 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets)
6164 PL_lex_state = LEX_INTERPEND;
6167 if (PL_lex_state == LEX_NORMAL) {
6168 if (ckWARN(WARN_AMBIGUOUS) &&
6169 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
6171 Perl_warner(aTHX_ WARN_AMBIGUOUS,
6172 "Ambiguous use of %c{%s} resolved to %c%s",
6173 funny, dest, funny, dest);
6178 s = bracket; /* let the parser handle it */
6182 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
6183 PL_lex_state = LEX_INTERPEND;
6188 Perl_pmflag(pTHX_ U16 *pmfl, int ch)
6193 *pmfl |= PMf_GLOBAL;
6195 *pmfl |= PMf_CONTINUE;
6199 *pmfl |= PMf_MULTILINE;
6201 *pmfl |= PMf_SINGLELINE;
6203 *pmfl |= PMf_EXTENDED;
6207 S_scan_pat(pTHX_ char *start, I32 type)
6212 s = scan_str(start,FALSE,FALSE);
6214 Perl_croak(aTHX_ "Search pattern not terminated");
6216 pm = (PMOP*)newPMOP(type, 0);
6217 if (PL_multi_open == '?')
6218 pm->op_pmflags |= PMf_ONCE;
6220 while (*s && strchr("iomsx", *s))
6221 pmflag(&pm->op_pmflags,*s++);
6224 while (*s && strchr("iogcmsx", *s))
6225 pmflag(&pm->op_pmflags,*s++);
6227 pm->op_pmpermflags = pm->op_pmflags;
6229 PL_lex_op = (OP*)pm;
6230 yylval.ival = OP_MATCH;
6235 S_scan_subst(pTHX_ char *start)
6242 yylval.ival = OP_NULL;
6244 s = scan_str(start,FALSE,FALSE);
6247 Perl_croak(aTHX_ "Substitution pattern not terminated");
6249 if (s[-1] == PL_multi_open)
6252 first_start = PL_multi_start;
6253 s = scan_str(s,FALSE,FALSE);
6256 SvREFCNT_dec(PL_lex_stuff);
6257 PL_lex_stuff = Nullsv;
6259 Perl_croak(aTHX_ "Substitution replacement not terminated");
6261 PL_multi_start = first_start; /* so whole substitution is taken together */
6263 pm = (PMOP*)newPMOP(OP_SUBST, 0);
6269 else if (strchr("iogcmsx", *s))
6270 pmflag(&pm->op_pmflags,*s++);
6277 PL_sublex_info.super_bufptr = s;
6278 PL_sublex_info.super_bufend = PL_bufend;
6280 pm->op_pmflags |= PMf_EVAL;
6281 repl = newSVpvn("",0);
6283 sv_catpv(repl, es ? "eval " : "do ");
6284 sv_catpvn(repl, "{ ", 2);
6285 sv_catsv(repl, PL_lex_repl);
6286 sv_catpvn(repl, " };", 2);
6288 SvREFCNT_dec(PL_lex_repl);
6292 pm->op_pmpermflags = pm->op_pmflags;
6293 PL_lex_op = (OP*)pm;
6294 yylval.ival = OP_SUBST;
6299 S_scan_trans(pTHX_ char *start)
6308 yylval.ival = OP_NULL;
6310 s = scan_str(start,FALSE,FALSE);
6312 Perl_croak(aTHX_ "Transliteration pattern not terminated");
6313 if (s[-1] == PL_multi_open)
6316 s = scan_str(s,FALSE,FALSE);
6319 SvREFCNT_dec(PL_lex_stuff);
6320 PL_lex_stuff = Nullsv;
6322 Perl_croak(aTHX_ "Transliteration replacement not terminated");
6325 complement = del = squash = 0;
6326 while (strchr("cds", *s)) {
6328 complement = OPpTRANS_COMPLEMENT;
6330 del = OPpTRANS_DELETE;
6332 squash = OPpTRANS_SQUASH;
6336 New(803, tbl, complement&&!del?258:256, short);
6337 o = newPVOP(OP_TRANS, 0, (char*)tbl);
6338 o->op_private = del|squash|complement|
6339 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
6340 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
6343 yylval.ival = OP_TRANS;
6348 S_scan_heredoc(pTHX_ register char *s)
6351 I32 op_type = OP_SCALAR;
6358 int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
6362 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
6365 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
6366 if (*peek && strchr("`'\"",*peek)) {
6369 s = delimcpy(d, e, s, PL_bufend, term, &len);
6379 if (!isALNUM_lazy_if(s,UTF))
6380 deprecate("bare << to mean <<\"\"");
6381 for (; isALNUM_lazy_if(s,UTF); s++) {
6386 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
6387 Perl_croak(aTHX_ "Delimiter for here document is too long");
6390 len = d - PL_tokenbuf;
6391 #ifndef PERL_STRICT_CR
6392 d = strchr(s, '\r');
6396 while (s < PL_bufend) {
6402 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
6411 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
6416 if (outer || !(d=ninstr(s,PL_bufend,d,d+1)))
6417 herewas = newSVpvn(s,PL_bufend-s);
6419 s--, herewas = newSVpvn(s,d-s);
6420 s += SvCUR(herewas);
6422 tmpstr = NEWSV(87,79);
6423 sv_upgrade(tmpstr, SVt_PVIV);
6428 else if (term == '`') {
6429 op_type = OP_BACKTICK;
6430 SvIVX(tmpstr) = '\\';
6434 PL_multi_start = CopLINE(PL_curcop);
6435 PL_multi_open = PL_multi_close = '<';
6436 term = *PL_tokenbuf;
6437 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
6438 char *bufptr = PL_sublex_info.super_bufptr;
6439 char *bufend = PL_sublex_info.super_bufend;
6440 char *olds = s - SvCUR(herewas);
6441 s = strchr(bufptr, '\n');
6445 while (s < bufend &&
6446 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
6448 CopLINE_inc(PL_curcop);
6451 CopLINE_set(PL_curcop, PL_multi_start);
6452 missingterm(PL_tokenbuf);
6454 sv_setpvn(herewas,bufptr,d-bufptr+1);
6455 sv_setpvn(tmpstr,d+1,s-d);
6457 sv_catpvn(herewas,s,bufend-s);
6458 (void)strcpy(bufptr,SvPVX(herewas));
6465 while (s < PL_bufend &&
6466 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
6468 CopLINE_inc(PL_curcop);
6470 if (s >= PL_bufend) {
6471 CopLINE_set(PL_curcop, PL_multi_start);
6472 missingterm(PL_tokenbuf);
6474 sv_setpvn(tmpstr,d+1,s-d);
6476 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
6478 sv_catpvn(herewas,s,PL_bufend-s);
6479 sv_setsv(PL_linestr,herewas);
6480 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
6481 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6482 PL_last_lop = PL_last_uni = Nullch;
6485 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
6486 while (s >= PL_bufend) { /* multiple line string? */
6488 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
6489 CopLINE_set(PL_curcop, PL_multi_start);
6490 missingterm(PL_tokenbuf);
6492 CopLINE_inc(PL_curcop);
6493 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6494 PL_last_lop = PL_last_uni = Nullch;
6495 #ifndef PERL_STRICT_CR
6496 if (PL_bufend - PL_linestart >= 2) {
6497 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
6498 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
6500 PL_bufend[-2] = '\n';
6502 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
6504 else if (PL_bufend[-1] == '\r')
6505 PL_bufend[-1] = '\n';
6507 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
6508 PL_bufend[-1] = '\n';
6510 if (PERLDB_LINE && PL_curstash != PL_debstash) {
6511 SV *sv = NEWSV(88,0);
6513 sv_upgrade(sv, SVt_PVMG);
6514 sv_setsv(sv,PL_linestr);
6515 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
6517 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
6520 sv_catsv(PL_linestr,herewas);
6521 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6525 sv_catsv(tmpstr,PL_linestr);
6530 PL_multi_end = CopLINE(PL_curcop);
6531 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
6532 SvLEN_set(tmpstr, SvCUR(tmpstr) + 1);
6533 Renew(SvPVX(tmpstr), SvLEN(tmpstr), char);
6535 SvREFCNT_dec(herewas);
6536 if (UTF && !IN_BYTES && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr)))
6538 PL_lex_stuff = tmpstr;
6539 yylval.ival = op_type;
6544 takes: current position in input buffer
6545 returns: new position in input buffer
6546 side-effects: yylval and lex_op are set.
6551 <FH> read from filehandle
6552 <pkg::FH> read from package qualified filehandle
6553 <pkg'FH> read from package qualified filehandle
6554 <$fh> read from filehandle in $fh
6560 S_scan_inputsymbol(pTHX_ char *start)
6562 register char *s = start; /* current position in buffer */
6568 d = PL_tokenbuf; /* start of temp holding space */
6569 e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
6570 end = strchr(s, '\n');
6573 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
6575 /* die if we didn't have space for the contents of the <>,
6576 or if it didn't end, or if we see a newline
6579 if (len >= sizeof PL_tokenbuf)
6580 Perl_croak(aTHX_ "Excessively long <> operator");
6582 Perl_croak(aTHX_ "Unterminated <> operator");
6587 Remember, only scalar variables are interpreted as filehandles by
6588 this code. Anything more complex (e.g., <$fh{$num}>) will be
6589 treated as a glob() call.
6590 This code makes use of the fact that except for the $ at the front,
6591 a scalar variable and a filehandle look the same.
6593 if (*d == '$' && d[1]) d++;
6595 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
6596 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
6599 /* If we've tried to read what we allow filehandles to look like, and
6600 there's still text left, then it must be a glob() and not a getline.
6601 Use scan_str to pull out the stuff between the <> and treat it
6602 as nothing more than a string.
6605 if (d - PL_tokenbuf != len) {
6606 yylval.ival = OP_GLOB;
6608 s = scan_str(start,FALSE,FALSE);
6610 Perl_croak(aTHX_ "Glob not terminated");
6614 /* we're in a filehandle read situation */
6617 /* turn <> into <ARGV> */
6619 (void)strcpy(d,"ARGV");
6621 /* if <$fh>, create the ops to turn the variable into a
6627 /* try to find it in the pad for this block, otherwise find
6628 add symbol table ops
6630 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
6631 OP *o = newOP(OP_PADSV, 0);
6633 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, o);
6636 GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV);
6637 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0,
6638 newUNOP(OP_RV2SV, 0,
6639 newGVOP(OP_GV, 0, gv)));
6641 PL_lex_op->op_flags |= OPf_SPECIAL;
6642 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
6643 yylval.ival = OP_NULL;
6646 /* If it's none of the above, it must be a literal filehandle
6647 (<Foo::BAR> or <FOO>) so build a simple readline OP */
6649 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
6650 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
6651 yylval.ival = OP_NULL;
6660 takes: start position in buffer
6661 keep_quoted preserve \ on the embedded delimiter(s)
6662 keep_delims preserve the delimiters around the string
6663 returns: position to continue reading from buffer
6664 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
6665 updates the read buffer.
6667 This subroutine pulls a string out of the input. It is called for:
6668 q single quotes q(literal text)
6669 ' single quotes 'literal text'
6670 qq double quotes qq(interpolate $here please)
6671 " double quotes "interpolate $here please"
6672 qx backticks qx(/bin/ls -l)
6673 ` backticks `/bin/ls -l`
6674 qw quote words @EXPORT_OK = qw( func() $spam )
6675 m// regexp match m/this/
6676 s/// regexp substitute s/this/that/
6677 tr/// string transliterate tr/this/that/
6678 y/// string transliterate y/this/that/
6679 ($*@) sub prototypes sub foo ($)
6680 (stuff) sub attr parameters sub foo : attr(stuff)
6681 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
6683 In most of these cases (all but <>, patterns and transliterate)
6684 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
6685 calls scan_str(). s/// makes yylex() call scan_subst() which calls
6686 scan_str(). tr/// and y/// make yylex() call scan_trans() which
6689 It skips whitespace before the string starts, and treats the first
6690 character as the delimiter. If the delimiter is one of ([{< then
6691 the corresponding "close" character )]}> is used as the closing
6692 delimiter. It allows quoting of delimiters, and if the string has
6693 balanced delimiters ([{<>}]) it allows nesting.
6695 On success, the SV with the resulting string is put into lex_stuff or,
6696 if that is already non-NULL, into lex_repl. The second case occurs only
6697 when parsing the RHS of the special constructs s/// and tr/// (y///).
6698 For convenience, the terminating delimiter character is stuffed into
6703 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
6705 SV *sv; /* scalar value: string */
6706 char *tmps; /* temp string, used for delimiter matching */
6707 register char *s = start; /* current position in the buffer */
6708 register char term; /* terminating character */
6709 register char *to; /* current position in the sv's data */
6710 I32 brackets = 1; /* bracket nesting level */
6711 bool has_utf8 = FALSE; /* is there any utf8 content? */
6713 /* skip space before the delimiter */
6717 /* mark where we are, in case we need to report errors */
6720 /* after skipping whitespace, the next character is the terminator */
6722 if (!UTF8_IS_INVARIANT((U8)term) && UTF)
6725 /* mark where we are */
6726 PL_multi_start = CopLINE(PL_curcop);
6727 PL_multi_open = term;
6729 /* find corresponding closing delimiter */
6730 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
6732 PL_multi_close = term;
6734 /* create a new SV to hold the contents. 87 is leak category, I'm
6735 assuming. 79 is the SV's initial length. What a random number. */
6737 sv_upgrade(sv, SVt_PVIV);
6739 (void)SvPOK_only(sv); /* validate pointer */
6741 /* move past delimiter and try to read a complete string */
6743 sv_catpvn(sv, s, 1);
6746 /* extend sv if need be */
6747 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
6748 /* set 'to' to the next character in the sv's string */
6749 to = SvPVX(sv)+SvCUR(sv);
6751 /* if open delimiter is the close delimiter read unbridle */
6752 if (PL_multi_open == PL_multi_close) {
6753 for (; s < PL_bufend; s++,to++) {
6754 /* embedded newlines increment the current line number */
6755 if (*s == '\n' && !PL_rsfp)
6756 CopLINE_inc(PL_curcop);
6757 /* handle quoted delimiters */
6758 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
6759 if (!keep_quoted && s[1] == term)
6761 /* any other quotes are simply copied straight through */
6765 /* terminate when run out of buffer (the for() condition), or
6766 have found the terminator */
6767 else if (*s == term)
6769 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
6775 /* if the terminator isn't the same as the start character (e.g.,
6776 matched brackets), we have to allow more in the quoting, and
6777 be prepared for nested brackets.
6780 /* read until we run out of string, or we find the terminator */
6781 for (; s < PL_bufend; s++,to++) {
6782 /* embedded newlines increment the line count */
6783 if (*s == '\n' && !PL_rsfp)
6784 CopLINE_inc(PL_curcop);
6785 /* backslashes can escape the open or closing characters */
6786 if (*s == '\\' && s+1 < PL_bufend) {
6788 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
6793 /* allow nested opens and closes */
6794 else if (*s == PL_multi_close && --brackets <= 0)
6796 else if (*s == PL_multi_open)
6798 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
6803 /* terminate the copied string and update the sv's end-of-string */
6805 SvCUR_set(sv, to - SvPVX(sv));
6808 * this next chunk reads more into the buffer if we're not done yet
6812 break; /* handle case where we are done yet :-) */
6814 #ifndef PERL_STRICT_CR
6815 if (to - SvPVX(sv) >= 2) {
6816 if ((to[-2] == '\r' && to[-1] == '\n') ||
6817 (to[-2] == '\n' && to[-1] == '\r'))
6821 SvCUR_set(sv, to - SvPVX(sv));
6823 else if (to[-1] == '\r')
6826 else if (to - SvPVX(sv) == 1 && to[-1] == '\r')
6830 /* if we're out of file, or a read fails, bail and reset the current
6831 line marker so we can report where the unterminated string began
6834 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
6836 CopLINE_set(PL_curcop, PL_multi_start);
6839 /* we read a line, so increment our line counter */
6840 CopLINE_inc(PL_curcop);
6842 /* update debugger info */
6843 if (PERLDB_LINE && PL_curstash != PL_debstash) {
6844 SV *sv = NEWSV(88,0);
6846 sv_upgrade(sv, SVt_PVMG);
6847 sv_setsv(sv,PL_linestr);
6848 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
6851 /* having changed the buffer, we must update PL_bufend */
6852 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6853 PL_last_lop = PL_last_uni = Nullch;
6856 /* at this point, we have successfully read the delimited string */
6859 sv_catpvn(sv, s, 1);
6862 PL_multi_end = CopLINE(PL_curcop);
6865 /* if we allocated too much space, give some back */
6866 if (SvCUR(sv) + 5 < SvLEN(sv)) {
6867 SvLEN_set(sv, SvCUR(sv) + 1);
6868 Renew(SvPVX(sv), SvLEN(sv), char);
6871 /* decide whether this is the first or second quoted string we've read
6884 takes: pointer to position in buffer
6885 returns: pointer to new position in buffer
6886 side-effects: builds ops for the constant in yylval.op
6888 Read a number in any of the formats that Perl accepts:
6890 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
6891 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
6894 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
6896 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
6899 If it reads a number without a decimal point or an exponent, it will
6900 try converting the number to an integer and see if it can do so
6901 without loss of precision.
6905 Perl_scan_num(pTHX_ char *start, YYSTYPE* lvalp)
6907 register char *s = start; /* current position in buffer */
6908 register char *d; /* destination in temp buffer */
6909 register char *e; /* end of temp buffer */
6910 NV nv; /* number read, as a double */
6911 SV *sv = Nullsv; /* place to put the converted number */
6912 bool floatit, /* boolean: int or float? */
6913 octal = 0; /* Is this an octal number? */
6914 char *lastub = 0; /* position of last underbar */
6915 static char number_too_long[] = "Number too long";
6917 /* We use the first character to decide what type of number this is */
6921 Perl_croak(aTHX_ "panic: scan_num");
6923 /* if it starts with a 0, it could be an octal number, a decimal in
6924 0.13 disguise, or a hexadecimal number, or a binary number. */
6928 u holds the "number so far"
6929 shift the power of 2 of the base
6930 (hex == 4, octal == 3, binary == 1)
6931 overflowed was the number more than we can hold?
6933 Shift is used when we add a digit. It also serves as an "are
6934 we in octal/hex/binary?" indicator to disallow hex characters
6940 bool overflowed = FALSE;
6941 static NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
6942 static char* bases[5] = { "", "binary", "", "octal",
6944 static char* Bases[5] = { "", "Binary", "", "Octal",
6946 static char *maxima[5] = { "",
6947 "0b11111111111111111111111111111111",
6951 char *base, *Base, *max;
6957 } else if (s[1] == 'b') {
6961 /* check for a decimal in disguise */
6962 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
6964 /* so it must be octal */
6972 if (ckWARN(WARN_SYNTAX))
6973 Perl_warner(aTHX_ WARN_SYNTAX,
6974 "Misplaced _ in number");
6978 base = bases[shift];
6979 Base = Bases[shift];
6980 max = maxima[shift];
6982 /* read the rest of the number */
6984 /* x is used in the overflow test,
6985 b is the digit we're adding on. */
6990 /* if we don't mention it, we're done */
6994 /* _ are ignored -- but warned about if consecutive */
6996 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
6997 Perl_warner(aTHX_ WARN_SYNTAX,
6998 "Misplaced _ in number");
7002 /* 8 and 9 are not octal */
7005 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
7009 case '2': case '3': case '4':
7010 case '5': case '6': case '7':
7012 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
7016 b = *s++ & 15; /* ASCII digit -> value of digit */
7020 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
7021 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
7022 /* make sure they said 0x */
7027 /* Prepare to put the digit we have onto the end
7028 of the number so far. We check for overflows.
7033 x = u << shift; /* make room for the digit */
7035 if ((x >> shift) != u
7036 && !(PL_hints & HINT_NEW_BINARY)) {
7039 if (ckWARN_d(WARN_OVERFLOW))
7040 Perl_warner(aTHX_ WARN_OVERFLOW,
7041 "Integer overflow in %s number",
7044 u = x | b; /* add the digit to the end */
7047 n *= nvshift[shift];
7048 /* If an NV has not enough bits in its
7049 * mantissa to represent an UV this summing of
7050 * small low-order numbers is a waste of time
7051 * (because the NV cannot preserve the
7052 * low-order bits anyway): we could just
7053 * remember when did we overflow and in the
7054 * end just multiply n by the right
7062 /* if we get here, we had success: make a scalar value from
7067 /* final misplaced underbar check */
7069 if (ckWARN(WARN_SYNTAX))
7070 Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number");
7075 if (ckWARN(WARN_PORTABLE) && n > 4294967295.0)
7076 Perl_warner(aTHX_ WARN_PORTABLE,
7077 "%s number > %s non-portable",
7083 if (ckWARN(WARN_PORTABLE) && u > 0xffffffff)
7084 Perl_warner(aTHX_ WARN_PORTABLE,
7085 "%s number > %s non-portable",
7090 if (PL_hints & HINT_NEW_BINARY)
7091 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
7096 handle decimal numbers.
7097 we're also sent here when we read a 0 as the first digit
7099 case '1': case '2': case '3': case '4': case '5':
7100 case '6': case '7': case '8': case '9': case '.':
7103 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
7106 /* read next group of digits and _ and copy into d */
7107 while (isDIGIT(*s) || *s == '_') {
7108 /* skip underscores, checking for misplaced ones
7112 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
7113 Perl_warner(aTHX_ WARN_SYNTAX,
7114 "Misplaced _ in number");
7118 /* check for end of fixed-length buffer */
7120 Perl_croak(aTHX_ number_too_long);
7121 /* if we're ok, copy the character */
7126 /* final misplaced underbar check */
7127 if (lastub && s == lastub + 1) {
7128 if (ckWARN(WARN_SYNTAX))
7129 Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number");
7132 /* read a decimal portion if there is one. avoid
7133 3..5 being interpreted as the number 3. followed
7136 if (*s == '.' && s[1] != '.') {
7141 if (ckWARN(WARN_SYNTAX))
7142 Perl_warner(aTHX_ WARN_SYNTAX,
7143 "Misplaced _ in number");
7147 /* copy, ignoring underbars, until we run out of digits.
7149 for (; isDIGIT(*s) || *s == '_'; s++) {
7150 /* fixed length buffer check */
7152 Perl_croak(aTHX_ number_too_long);
7154 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
7155 Perl_warner(aTHX_ WARN_SYNTAX,
7156 "Misplaced _ in number");
7162 /* fractional part ending in underbar? */
7164 if (ckWARN(WARN_SYNTAX))
7165 Perl_warner(aTHX_ WARN_SYNTAX,
7166 "Misplaced _ in number");
7168 if (*s == '.' && isDIGIT(s[1])) {
7169 /* oops, it's really a v-string, but without the "v" */
7175 /* read exponent part, if present */
7176 if (*s && strchr("eE",*s) && strchr("+-0123456789_", s[1])) {
7180 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
7181 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
7183 /* stray preinitial _ */
7185 if (ckWARN(WARN_SYNTAX))
7186 Perl_warner(aTHX_ WARN_SYNTAX,
7187 "Misplaced _ in number");
7191 /* allow positive or negative exponent */
7192 if (*s == '+' || *s == '-')
7195 /* stray initial _ */
7197 if (ckWARN(WARN_SYNTAX))
7198 Perl_warner(aTHX_ WARN_SYNTAX,
7199 "Misplaced _ in number");
7203 /* read digits of exponent */
7204 while (isDIGIT(*s) || *s == '_') {
7207 Perl_croak(aTHX_ number_too_long);
7211 if (ckWARN(WARN_SYNTAX) &&
7212 ((lastub && s == lastub + 1) ||
7213 (!isDIGIT(s[1]) && s[1] != '_')))
7214 Perl_warner(aTHX_ WARN_SYNTAX,
7215 "Misplaced _ in number");
7222 /* make an sv from the string */
7226 We try to do an integer conversion first if no characters
7227 indicating "float" have been found.
7232 int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
7234 if (flags == IS_NUMBER_IN_UV) {
7236 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
7239 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
7240 if (uv <= (UV) IV_MIN)
7241 sv_setiv(sv, -(IV)uv);
7248 /* terminate the string */
7250 nv = Atof(PL_tokenbuf);
7254 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
7255 (PL_hints & HINT_NEW_INTEGER) )
7256 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
7257 (floatit ? "float" : "integer"),
7261 /* if it starts with a v, it could be a v-string */
7267 while (isDIGIT(*pos) || *pos == '_')
7269 if (!isALPHA(*pos)) {
7271 U8 tmpbuf[UTF8_MAXLEN+1];
7273 s++; /* get past 'v' */
7276 sv_setpvn(sv, "", 0);
7279 if (*s == '0' && isDIGIT(s[1]))
7280 yyerror("Octal number in vector unsupported");
7283 /* this is atoi() that tolerates underscores */
7286 while (--end >= s) {
7291 rev += (*end - '0') * mult;
7293 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
7294 Perl_warner(aTHX_ WARN_OVERFLOW,
7295 "Integer overflow in decimal number");
7298 /* Append native character for the rev point */
7299 tmpend = uvchr_to_utf8(tmpbuf, rev);
7300 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
7301 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
7303 if (*pos == '.' && isDIGIT(pos[1]))
7309 while (isDIGIT(*pos) || *pos == '_')
7319 /* make the op for the constant and return */
7322 lvalp->opval = newSVOP(OP_CONST, 0, sv);
7324 ((SVOP *)lvalp->opval)->op_private |= OPpCONST_OCTAL;
7327 lvalp->opval = Nullop;
7333 S_scan_formline(pTHX_ register char *s)
7337 SV *stuff = newSVpvn("",0);
7338 bool needargs = FALSE;
7341 if (*s == '.' || *s == /*{*/'}') {
7343 #ifdef PERL_STRICT_CR
7344 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
7346 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
7348 if (*t == '\n' || t == PL_bufend)
7351 if (PL_in_eval && !PL_rsfp) {
7352 eol = strchr(s,'\n');
7357 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
7359 for (t = s; t < eol; t++) {
7360 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
7362 goto enough; /* ~~ must be first line in formline */
7364 if (*t == '@' || *t == '^')
7367 sv_catpvn(stuff, s, eol-s);
7368 #ifndef PERL_STRICT_CR
7369 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
7370 char *end = SvPVX(stuff) + SvCUR(stuff);
7379 s = filter_gets(PL_linestr, PL_rsfp, 0);
7380 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
7381 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
7382 PL_last_lop = PL_last_uni = Nullch;
7385 yyerror("Format not terminated");
7395 PL_lex_state = LEX_NORMAL;
7396 PL_nextval[PL_nexttoke].ival = 0;
7400 PL_lex_state = LEX_FORMLINE;
7401 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
7403 PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
7407 SvREFCNT_dec(stuff);
7408 PL_lex_formbrack = 0;
7419 PL_cshlen = strlen(PL_cshname);
7424 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
7426 I32 oldsavestack_ix = PL_savestack_ix;
7427 CV* outsidecv = PL_compcv;
7431 assert(SvTYPE(PL_compcv) == SVt_PVCV);
7433 SAVEI32(PL_subline);
7434 save_item(PL_subname);
7437 SAVESPTR(PL_comppad_name);
7438 SAVESPTR(PL_compcv);
7439 SAVEI32(PL_comppad_name_fill);
7440 SAVEI32(PL_min_intro_pending);
7441 SAVEI32(PL_max_intro_pending);
7442 SAVEI32(PL_pad_reset_pending);
7444 PL_compcv = (CV*)NEWSV(1104,0);
7445 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
7446 CvFLAGS(PL_compcv) |= flags;
7448 PL_comppad = newAV();
7449 av_push(PL_comppad, Nullsv);
7450 PL_curpad = AvARRAY(PL_comppad);
7451 PL_comppad_name = newAV();
7452 PL_comppad_name_fill = 0;
7453 PL_min_intro_pending = 0;
7455 PL_subline = CopLINE(PL_curcop);
7457 av_store(PL_comppad_name, 0, newSVpvn("@_", 2));
7458 PL_curpad[0] = (SV*)newAV();
7459 SvPADMY_on(PL_curpad[0]); /* XXX Needed? */
7460 #endif /* USE_THREADS */
7462 comppadlist = newAV();
7463 AvREAL_off(comppadlist);
7464 av_store(comppadlist, 0, (SV*)PL_comppad_name);
7465 av_store(comppadlist, 1, (SV*)PL_comppad);
7467 CvPADLIST(PL_compcv) = comppadlist;
7468 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
7470 CvOWNER(PL_compcv) = 0;
7471 New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
7472 MUTEX_INIT(CvMUTEXP(PL_compcv));
7473 #endif /* USE_THREADS */
7475 return oldsavestack_ix;
7479 #pragma segment Perl_yylex
7482 Perl_yywarn(pTHX_ char *s)
7484 PL_in_eval |= EVAL_WARNONLY;
7486 PL_in_eval &= ~EVAL_WARNONLY;
7491 Perl_yyerror(pTHX_ char *s)
7494 char *context = NULL;
7498 if (!yychar || (yychar == ';' && !PL_rsfp))
7500 else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 &&
7501 PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) {
7502 while (isSPACE(*PL_oldoldbufptr))
7504 context = PL_oldoldbufptr;
7505 contlen = PL_bufptr - PL_oldoldbufptr;
7507 else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 &&
7508 PL_oldbufptr != PL_bufptr) {
7509 while (isSPACE(*PL_oldbufptr))
7511 context = PL_oldbufptr;
7512 contlen = PL_bufptr - PL_oldbufptr;
7514 else if (yychar > 255)
7515 where = "next token ???";
7516 #ifdef USE_PURE_BISON
7517 /* GNU Bison sets the value -2 */
7518 else if (yychar == -2) {
7520 else if ((yychar & 127) == 127) {
7522 if (PL_lex_state == LEX_NORMAL ||
7523 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
7524 where = "at end of line";
7525 else if (PL_lex_inpat)
7526 where = "within pattern";
7528 where = "within string";
7531 SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
7533 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
7534 else if (isPRINT_LC(yychar))
7535 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
7537 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
7538 where = SvPVX(where_sv);
7540 msg = sv_2mortal(newSVpv(s, 0));
7541 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
7542 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
7544 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
7546 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
7547 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
7548 Perl_sv_catpvf(aTHX_ msg,
7549 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
7550 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
7553 if (PL_in_eval & EVAL_WARNONLY)
7554 Perl_warn(aTHX_ "%"SVf, msg);
7557 if (PL_error_count >= 10) {
7558 if (PL_in_eval && SvCUR(ERRSV))
7559 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
7560 ERRSV, CopFILE(PL_curcop));
7562 Perl_croak(aTHX_ "%s has too many errors.\n",
7563 CopFILE(PL_curcop));
7566 PL_in_my_stash = Nullhv;
7570 #pragma segment Main
7574 S_swallow_bom(pTHX_ U8 *s)
7577 slen = SvCUR(PL_linestr);
7581 /* UTF-16 little-endian */
7582 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
7583 Perl_croak(aTHX_ "Unsupported script encoding");
7584 #ifndef PERL_NO_UTF16_FILTER
7585 DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-LE script encoding\n"));
7587 if (PL_bufend > (char*)s) {
7591 filter_add(utf16rev_textfilter, NULL);
7592 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
7593 PL_bufend = (char*)utf16_to_utf8_reversed(s, news,
7594 PL_bufend - (char*)s - 1,
7596 Copy(news, s, newlen, U8);
7597 SvCUR_set(PL_linestr, newlen);
7598 PL_bufend = SvPVX(PL_linestr) + newlen;
7599 news[newlen++] = '\0';
7603 Perl_croak(aTHX_ "Unsupported script encoding");
7608 if (s[1] == 0xFF) { /* UTF-16 big-endian */
7609 #ifndef PERL_NO_UTF16_FILTER
7610 DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding\n"));
7612 if (PL_bufend > (char *)s) {
7616 filter_add(utf16_textfilter, NULL);
7617 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
7618 PL_bufend = (char*)utf16_to_utf8(s, news,
7619 PL_bufend - (char*)s,
7621 Copy(news, s, newlen, U8);
7622 SvCUR_set(PL_linestr, newlen);
7623 PL_bufend = SvPVX(PL_linestr) + newlen;
7624 news[newlen++] = '\0';
7628 Perl_croak(aTHX_ "Unsupported script encoding");
7633 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
7634 DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-8 script encoding\n"));
7639 if (slen > 3 && s[1] == 0 && /* UTF-32 big-endian */
7640 s[2] == 0xFE && s[3] == 0xFF)
7642 Perl_croak(aTHX_ "Unsupported script encoding");
7654 * Restore a source filter.
7658 restore_rsfp(pTHXo_ void *f)
7660 PerlIO *fp = (PerlIO*)f;
7662 if (PL_rsfp == PerlIO_stdin())
7663 PerlIO_clearerr(PL_rsfp);
7664 else if (PL_rsfp && (PL_rsfp != fp))
7665 PerlIO_close(PL_rsfp);
7669 #ifndef PERL_NO_UTF16_FILTER
7671 utf16_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
7673 I32 count = FILTER_READ(idx+1, sv, maxlen);
7678 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
7679 if (!*SvPV_nolen(sv))
7680 /* Game over, but don't feed an odd-length string to utf16_to_utf8 */
7683 tend = utf16_to_utf8((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen);
7684 sv_usepvn(sv, (char*)tmps, tend - tmps);
7690 utf16rev_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
7692 I32 count = FILTER_READ(idx+1, sv, maxlen);
7697 if (!*SvPV_nolen(sv))
7698 /* Game over, but don't feed an odd-length string to utf16_to_utf8 */
7701 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
7702 tend = utf16_to_utf8_reversed((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen);
7703 sv_usepvn(sv, (char*)tmps, tend - tmps);