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 if (ckWARN(WARN_CHMOD)) {
4179 for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ;
4180 if (*d != '0' && isDIGIT(*d))
4181 Perl_warner(aTHX_ WARN_CHMOD,
4182 "chmod() mode argument is missing initial 0");
4184 LOP(OP_CHMOD,XTERM);
4187 LOP(OP_CHOWN,XTERM);
4190 LOP(OP_CONNECT,XTERM);
4206 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4210 PL_hints |= HINT_BLOCK_SCOPE;
4220 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
4221 LOP(OP_DBMOPEN,XTERM);
4227 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4234 yylval.ival = CopLINE(PL_curcop);
4248 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4249 UNIBRACK(OP_ENTEREVAL);
4264 case KEY_endhostent:
4270 case KEY_endservent:
4273 case KEY_endprotoent:
4284 yylval.ival = CopLINE(PL_curcop);
4286 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4288 if ((PL_bufend - p) >= 3 &&
4289 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4291 else if ((PL_bufend - p) >= 4 &&
4292 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4295 if (isIDFIRST_lazy_if(p,UTF)) {
4296 p = scan_ident(p, PL_bufend,
4297 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4301 Perl_croak(aTHX_ "Missing $ on loop variable");
4306 LOP(OP_FORMLINE,XTERM);
4312 LOP(OP_FCNTL,XTERM);
4318 LOP(OP_FLOCK,XTERM);
4327 LOP(OP_GREPSTART, XREF);
4330 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4345 case KEY_getpriority:
4346 LOP(OP_GETPRIORITY,XTERM);
4348 case KEY_getprotobyname:
4351 case KEY_getprotobynumber:
4352 LOP(OP_GPBYNUMBER,XTERM);
4354 case KEY_getprotoent:
4366 case KEY_getpeername:
4367 UNI(OP_GETPEERNAME);
4369 case KEY_gethostbyname:
4372 case KEY_gethostbyaddr:
4373 LOP(OP_GHBYADDR,XTERM);
4375 case KEY_gethostent:
4378 case KEY_getnetbyname:
4381 case KEY_getnetbyaddr:
4382 LOP(OP_GNBYADDR,XTERM);
4387 case KEY_getservbyname:
4388 LOP(OP_GSBYNAME,XTERM);
4390 case KEY_getservbyport:
4391 LOP(OP_GSBYPORT,XTERM);
4393 case KEY_getservent:
4396 case KEY_getsockname:
4397 UNI(OP_GETSOCKNAME);
4399 case KEY_getsockopt:
4400 LOP(OP_GSOCKOPT,XTERM);
4422 yylval.ival = CopLINE(PL_curcop);
4426 LOP(OP_INDEX,XTERM);
4432 LOP(OP_IOCTL,XTERM);
4444 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4476 LOP(OP_LISTEN,XTERM);
4485 s = scan_pat(s,OP_MATCH);
4486 TERM(sublex_start());
4489 LOP(OP_MAPSTART, XREF);
4492 LOP(OP_MKDIR,XTERM);
4495 LOP(OP_MSGCTL,XTERM);
4498 LOP(OP_MSGGET,XTERM);
4501 LOP(OP_MSGRCV,XTERM);
4504 LOP(OP_MSGSND,XTERM);
4510 if (isIDFIRST_lazy_if(s,UTF)) {
4511 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4512 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4514 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
4515 if (!PL_in_my_stash) {
4518 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4526 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4533 if (PL_expect != XSTATE)
4534 yyerror("\"no\" not allowed in expression");
4535 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4536 s = force_version(s);
4541 if (*s == '(' || (s = skipspace(s), *s == '('))
4548 if (isIDFIRST_lazy_if(s,UTF)) {
4550 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
4552 if (strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE))
4553 Perl_warner(aTHX_ WARN_PRECEDENCE,
4554 "Precedence problem: open %.*s should be open(%.*s)",
4560 yylval.ival = OP_OR;
4570 LOP(OP_OPEN_DIR,XTERM);
4573 checkcomma(s,PL_tokenbuf,"filehandle");
4577 checkcomma(s,PL_tokenbuf,"filehandle");
4596 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4600 LOP(OP_PIPE_OP,XTERM);
4603 s = scan_str(s,FALSE,FALSE);
4605 missingterm((char*)0);
4606 yylval.ival = OP_CONST;
4607 TERM(sublex_start());
4613 s = scan_str(s,FALSE,FALSE);
4615 missingterm((char*)0);
4617 if (SvCUR(PL_lex_stuff)) {
4620 d = SvPV_force(PL_lex_stuff, len);
4623 for (; isSPACE(*d) && len; --len, ++d) ;
4626 if (!warned && ckWARN(WARN_QW)) {
4627 for (; !isSPACE(*d) && len; --len, ++d) {
4629 Perl_warner(aTHX_ WARN_QW,
4630 "Possible attempt to separate words with commas");
4633 else if (*d == '#') {
4634 Perl_warner(aTHX_ WARN_QW,
4635 "Possible attempt to put comments in qw() list");
4641 for (; !isSPACE(*d) && len; --len, ++d) ;
4643 sv = newSVpvn(b, d-b);
4644 if (DO_UTF8(PL_lex_stuff))
4646 words = append_elem(OP_LIST, words,
4647 newSVOP(OP_CONST, 0, tokeq(sv)));
4651 PL_nextval[PL_nexttoke].opval = words;
4656 SvREFCNT_dec(PL_lex_stuff);
4657 PL_lex_stuff = Nullsv;
4663 s = scan_str(s,FALSE,FALSE);
4665 missingterm((char*)0);
4666 yylval.ival = OP_STRINGIFY;
4667 if (SvIVX(PL_lex_stuff) == '\'')
4668 SvIVX(PL_lex_stuff) = 0; /* qq'$foo' should intepolate */
4669 TERM(sublex_start());
4672 s = scan_pat(s,OP_QR);
4673 TERM(sublex_start());
4676 s = scan_str(s,FALSE,FALSE);
4678 missingterm((char*)0);
4679 yylval.ival = OP_BACKTICK;
4681 TERM(sublex_start());
4688 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
4689 s = force_version(s);
4692 *PL_tokenbuf = '\0';
4693 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4694 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
4695 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
4697 yyerror("<> should be quotes");
4705 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4709 LOP(OP_RENAME,XTERM);
4718 LOP(OP_RINDEX,XTERM);
4741 LOP(OP_REVERSE,XTERM);
4752 TERM(sublex_start());
4754 TOKEN(1); /* force error */
4763 LOP(OP_SELECT,XTERM);
4769 LOP(OP_SEMCTL,XTERM);
4772 LOP(OP_SEMGET,XTERM);
4775 LOP(OP_SEMOP,XTERM);
4781 LOP(OP_SETPGRP,XTERM);
4783 case KEY_setpriority:
4784 LOP(OP_SETPRIORITY,XTERM);
4786 case KEY_sethostent:
4792 case KEY_setservent:
4795 case KEY_setprotoent:
4805 LOP(OP_SEEKDIR,XTERM);
4807 case KEY_setsockopt:
4808 LOP(OP_SSOCKOPT,XTERM);
4814 LOP(OP_SHMCTL,XTERM);
4817 LOP(OP_SHMGET,XTERM);
4820 LOP(OP_SHMREAD,XTERM);
4823 LOP(OP_SHMWRITE,XTERM);
4826 LOP(OP_SHUTDOWN,XTERM);
4835 LOP(OP_SOCKET,XTERM);
4837 case KEY_socketpair:
4838 LOP(OP_SOCKPAIR,XTERM);
4841 checkcomma(s,PL_tokenbuf,"subroutine name");
4843 if (*s == ';' || *s == ')') /* probably a close */
4844 Perl_croak(aTHX_ "sort is now a reserved word");
4846 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4850 LOP(OP_SPLIT,XTERM);
4853 LOP(OP_SPRINTF,XTERM);
4856 LOP(OP_SPLICE,XTERM);
4871 LOP(OP_SUBSTR,XTERM);
4877 char tmpbuf[sizeof PL_tokenbuf];
4878 SSize_t tboffset = 0;
4879 expectation attrful;
4880 bool have_name, have_proto;
4885 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
4886 (*s == ':' && s[1] == ':'))
4889 attrful = XATTRBLOCK;
4890 /* remember buffer pos'n for later force_word */
4891 tboffset = s - PL_oldbufptr;
4892 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4893 if (strchr(tmpbuf, ':'))
4894 sv_setpv(PL_subname, tmpbuf);
4896 sv_setsv(PL_subname,PL_curstname);
4897 sv_catpvn(PL_subname,"::",2);
4898 sv_catpvn(PL_subname,tmpbuf,len);
4905 Perl_croak(aTHX_ "Missing name in \"my sub\"");
4906 PL_expect = XTERMBLOCK;
4907 attrful = XATTRTERM;
4908 sv_setpv(PL_subname,"?");
4912 if (key == KEY_format) {
4914 PL_lex_formbrack = PL_lex_brackets + 1;
4916 (void) force_word(PL_oldbufptr + tboffset, WORD,
4921 /* Look for a prototype */
4925 s = scan_str(s,FALSE,FALSE);
4927 Perl_croak(aTHX_ "Prototype not terminated");
4929 d = SvPVX(PL_lex_stuff);
4931 for (p = d; *p; ++p) {
4936 SvCUR(PL_lex_stuff) = tmp;
4944 if (*s == ':' && s[1] != ':')
4945 PL_expect = attrful;
4948 PL_nextval[PL_nexttoke].opval =
4949 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
4950 PL_lex_stuff = Nullsv;
4954 sv_setpv(PL_subname,"__ANON__");
4957 (void) force_word(PL_oldbufptr + tboffset, WORD,
4966 LOP(OP_SYSTEM,XREF);
4969 LOP(OP_SYMLINK,XTERM);
4972 LOP(OP_SYSCALL,XTERM);
4975 LOP(OP_SYSOPEN,XTERM);
4978 LOP(OP_SYSSEEK,XTERM);
4981 LOP(OP_SYSREAD,XTERM);
4984 LOP(OP_SYSWRITE,XTERM);
4988 TERM(sublex_start());
5009 LOP(OP_TRUNCATE,XTERM);
5021 yylval.ival = CopLINE(PL_curcop);
5025 yylval.ival = CopLINE(PL_curcop);
5029 LOP(OP_UNLINK,XTERM);
5035 LOP(OP_UNPACK,XTERM);
5038 LOP(OP_UTIME,XTERM);
5041 if (ckWARN(WARN_UMASK)) {
5042 for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ;
5043 if (*d != '0' && isDIGIT(*d))
5044 Perl_warner(aTHX_ WARN_UMASK,
5045 "umask: argument is missing initial 0");
5050 LOP(OP_UNSHIFT,XTERM);
5053 if (PL_expect != XSTATE)
5054 yyerror("\"use\" not allowed in expression");
5056 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
5057 s = force_version(s);
5058 if (*s == ';' || (s = skipspace(s), *s == ';')) {
5059 PL_nextval[PL_nexttoke].opval = Nullop;
5064 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5065 s = force_version(s);
5077 yylval.ival = CopLINE(PL_curcop);
5081 PL_hints |= HINT_BLOCK_SCOPE;
5088 LOP(OP_WAITPID,XTERM);
5096 static char ctl_l[2];
5098 if (ctl_l[0] == '\0')
5099 ctl_l[0] = toCTRL('L');
5100 gv_fetchpv(ctl_l,TRUE, SVt_PV);
5103 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
5108 if (PL_expect == XOPERATOR)
5114 yylval.ival = OP_XOR;
5119 TERM(sublex_start());
5124 #pragma segment Main
5128 S_pending_ident(pTHX)
5132 /* pit holds the identifier we read and pending_ident is reset */
5133 char pit = PL_pending_ident;
5134 PL_pending_ident = 0;
5136 DEBUG_T({ PerlIO_printf(Perl_debug_log,
5137 "### Tokener saw identifier '%s'\n", PL_tokenbuf); });
5139 /* if we're in a my(), we can't allow dynamics here.
5140 $foo'bar has already been turned into $foo::bar, so
5141 just check for colons.
5143 if it's a legal name, the OP is a PADANY.
5146 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
5147 if (strchr(PL_tokenbuf,':'))
5148 yyerror(Perl_form(aTHX_ "No package name allowed for "
5149 "variable %s in \"our\"",
5151 tmp = pad_allocmy(PL_tokenbuf);
5154 if (strchr(PL_tokenbuf,':'))
5155 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
5157 yylval.opval = newOP(OP_PADANY, 0);
5158 yylval.opval->op_targ = pad_allocmy(PL_tokenbuf);
5164 build the ops for accesses to a my() variable.
5166 Deny my($a) or my($b) in a sort block, *if* $a or $b is
5167 then used in a comparison. This catches most, but not
5168 all cases. For instance, it catches
5169 sort { my($a); $a <=> $b }
5171 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
5172 (although why you'd do that is anyone's guess).
5175 if (!strchr(PL_tokenbuf,':')) {
5177 /* Check for single character per-thread SVs */
5178 if (PL_tokenbuf[0] == '$' && PL_tokenbuf[2] == '\0'
5179 && !isALPHA(PL_tokenbuf[1]) /* Rule out obvious non-threadsvs */
5180 && (tmp = find_threadsv(&PL_tokenbuf[1])) != NOT_IN_PAD)
5182 yylval.opval = newOP(OP_THREADSV, 0);
5183 yylval.opval->op_targ = tmp;
5186 #endif /* USE_THREADS */
5187 if ((tmp = pad_findmy(PL_tokenbuf)) != NOT_IN_PAD) {
5188 SV *namesv = AvARRAY(PL_comppad_name)[tmp];
5189 /* might be an "our" variable" */
5190 if (SvFLAGS(namesv) & SVpad_OUR) {
5191 /* build ops for a bareword */
5192 SV *sym = newSVpv(HvNAME(GvSTASH(namesv)),0);
5193 sv_catpvn(sym, "::", 2);
5194 sv_catpv(sym, PL_tokenbuf+1);
5195 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
5196 yylval.opval->op_private = OPpCONST_ENTERED;
5197 gv_fetchpv(SvPVX(sym),
5199 ? (GV_ADDMULTI | GV_ADDINEVAL)
5202 ((PL_tokenbuf[0] == '$') ? SVt_PV
5203 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5208 /* if it's a sort block and they're naming $a or $b */
5209 if (PL_last_lop_op == OP_SORT &&
5210 PL_tokenbuf[0] == '$' &&
5211 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
5214 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
5215 d < PL_bufend && *d != '\n';
5218 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
5219 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
5225 yylval.opval = newOP(OP_PADANY, 0);
5226 yylval.opval->op_targ = tmp;
5232 Whine if they've said @foo in a doublequoted string,
5233 and @foo isn't a variable we can find in the symbol
5236 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
5237 GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
5238 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
5239 && ckWARN(WARN_AMBIGUOUS))
5241 /* Downgraded from fatal to warning 20000522 mjd */
5242 Perl_warner(aTHX_ WARN_AMBIGUOUS,
5243 "Possible unintended interpolation of %s in string",
5248 /* build ops for a bareword */
5249 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
5250 yylval.opval->op_private = OPpCONST_ENTERED;
5251 gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
5252 ((PL_tokenbuf[0] == '$') ? SVt_PV
5253 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5259 Perl_keyword(pTHX_ register char *d, I32 len)
5264 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
5265 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
5266 if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__;
5267 if (strEQ(d,"__DATA__")) return KEY___DATA__;
5268 if (strEQ(d,"__END__")) return KEY___END__;
5272 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
5277 if (strEQ(d,"and")) return -KEY_and;
5278 if (strEQ(d,"abs")) return -KEY_abs;
5281 if (strEQ(d,"alarm")) return -KEY_alarm;
5282 if (strEQ(d,"atan2")) return -KEY_atan2;
5285 if (strEQ(d,"accept")) return -KEY_accept;
5290 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
5293 if (strEQ(d,"bless")) return -KEY_bless;
5294 if (strEQ(d,"bind")) return -KEY_bind;
5295 if (strEQ(d,"binmode")) return -KEY_binmode;
5298 if (strEQ(d,"CORE")) return -KEY_CORE;
5299 if (strEQ(d,"CHECK")) return KEY_CHECK;
5304 if (strEQ(d,"cmp")) return -KEY_cmp;
5305 if (strEQ(d,"chr")) return -KEY_chr;
5306 if (strEQ(d,"cos")) return -KEY_cos;
5309 if (strEQ(d,"chop")) return -KEY_chop;
5312 if (strEQ(d,"close")) return -KEY_close;
5313 if (strEQ(d,"chdir")) return -KEY_chdir;
5314 if (strEQ(d,"chomp")) return -KEY_chomp;
5315 if (strEQ(d,"chmod")) return -KEY_chmod;
5316 if (strEQ(d,"chown")) return -KEY_chown;
5317 if (strEQ(d,"crypt")) return -KEY_crypt;
5320 if (strEQ(d,"chroot")) return -KEY_chroot;
5321 if (strEQ(d,"caller")) return -KEY_caller;
5324 if (strEQ(d,"connect")) return -KEY_connect;
5327 if (strEQ(d,"closedir")) return -KEY_closedir;
5328 if (strEQ(d,"continue")) return -KEY_continue;
5333 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
5338 if (strEQ(d,"do")) return KEY_do;
5341 if (strEQ(d,"die")) return -KEY_die;
5344 if (strEQ(d,"dump")) return -KEY_dump;
5347 if (strEQ(d,"delete")) return KEY_delete;
5350 if (strEQ(d,"defined")) return KEY_defined;
5351 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
5354 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
5359 if (strEQ(d,"END")) return KEY_END;
5364 if (strEQ(d,"eq")) return -KEY_eq;
5367 if (strEQ(d,"eof")) return -KEY_eof;
5368 if (strEQ(d,"exp")) return -KEY_exp;
5371 if (strEQ(d,"else")) return KEY_else;
5372 if (strEQ(d,"exit")) return -KEY_exit;
5373 if (strEQ(d,"eval")) return KEY_eval;
5374 if (strEQ(d,"exec")) return -KEY_exec;
5375 if (strEQ(d,"each")) return -KEY_each;
5378 if (strEQ(d,"elsif")) return KEY_elsif;
5381 if (strEQ(d,"exists")) return KEY_exists;
5382 if (strEQ(d,"elseif")) Perl_warn(aTHX_ "elseif should be elsif");
5385 if (strEQ(d,"endgrent")) return -KEY_endgrent;
5386 if (strEQ(d,"endpwent")) return -KEY_endpwent;
5389 if (strEQ(d,"endnetent")) return -KEY_endnetent;
5392 if (strEQ(d,"endhostent")) return -KEY_endhostent;
5393 if (strEQ(d,"endservent")) return -KEY_endservent;
5396 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
5403 if (strEQ(d,"for")) return KEY_for;
5406 if (strEQ(d,"fork")) return -KEY_fork;
5409 if (strEQ(d,"fcntl")) return -KEY_fcntl;
5410 if (strEQ(d,"flock")) return -KEY_flock;
5413 if (strEQ(d,"format")) return KEY_format;
5414 if (strEQ(d,"fileno")) return -KEY_fileno;
5417 if (strEQ(d,"foreach")) return KEY_foreach;
5420 if (strEQ(d,"formline")) return -KEY_formline;
5425 if (strnEQ(d,"get",3)) {
5430 if (strEQ(d,"ppid")) return -KEY_getppid;
5431 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
5434 if (strEQ(d,"pwent")) return -KEY_getpwent;
5435 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
5436 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
5439 if (strEQ(d,"peername")) return -KEY_getpeername;
5440 if (strEQ(d,"protoent")) return -KEY_getprotoent;
5441 if (strEQ(d,"priority")) return -KEY_getpriority;
5444 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
5447 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
5451 else if (*d == 'h') {
5452 if (strEQ(d,"hostbyname")) return -KEY_gethostbyname;
5453 if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr;
5454 if (strEQ(d,"hostent")) return -KEY_gethostent;
5456 else if (*d == 'n') {
5457 if (strEQ(d,"netbyname")) return -KEY_getnetbyname;
5458 if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr;
5459 if (strEQ(d,"netent")) return -KEY_getnetent;
5461 else if (*d == 's') {
5462 if (strEQ(d,"servbyname")) return -KEY_getservbyname;
5463 if (strEQ(d,"servbyport")) return -KEY_getservbyport;
5464 if (strEQ(d,"servent")) return -KEY_getservent;
5465 if (strEQ(d,"sockname")) return -KEY_getsockname;
5466 if (strEQ(d,"sockopt")) return -KEY_getsockopt;
5468 else if (*d == 'g') {
5469 if (strEQ(d,"grent")) return -KEY_getgrent;
5470 if (strEQ(d,"grnam")) return -KEY_getgrnam;
5471 if (strEQ(d,"grgid")) return -KEY_getgrgid;
5473 else if (*d == 'l') {
5474 if (strEQ(d,"login")) return -KEY_getlogin;
5476 else if (strEQ(d,"c")) return -KEY_getc;
5481 if (strEQ(d,"gt")) return -KEY_gt;
5482 if (strEQ(d,"ge")) return -KEY_ge;
5485 if (strEQ(d,"grep")) return KEY_grep;
5486 if (strEQ(d,"goto")) return KEY_goto;
5487 if (strEQ(d,"glob")) return KEY_glob;
5490 if (strEQ(d,"gmtime")) return -KEY_gmtime;
5495 if (strEQ(d,"hex")) return -KEY_hex;
5498 if (strEQ(d,"INIT")) return KEY_INIT;
5503 if (strEQ(d,"if")) return KEY_if;
5506 if (strEQ(d,"int")) return -KEY_int;
5509 if (strEQ(d,"index")) return -KEY_index;
5510 if (strEQ(d,"ioctl")) return -KEY_ioctl;
5515 if (strEQ(d,"join")) return -KEY_join;
5519 if (strEQ(d,"keys")) return -KEY_keys;
5520 if (strEQ(d,"kill")) return -KEY_kill;
5526 if (strEQ(d,"lt")) return -KEY_lt;
5527 if (strEQ(d,"le")) return -KEY_le;
5528 if (strEQ(d,"lc")) return -KEY_lc;
5531 if (strEQ(d,"log")) return -KEY_log;
5534 if (strEQ(d,"last")) return KEY_last;
5535 if (strEQ(d,"link")) return -KEY_link;
5536 if (strEQ(d,"lock")) return -KEY_lock;
5539 if (strEQ(d,"local")) return KEY_local;
5540 if (strEQ(d,"lstat")) return -KEY_lstat;
5543 if (strEQ(d,"length")) return -KEY_length;
5544 if (strEQ(d,"listen")) return -KEY_listen;
5547 if (strEQ(d,"lcfirst")) return -KEY_lcfirst;
5550 if (strEQ(d,"localtime")) return -KEY_localtime;
5556 case 1: return KEY_m;
5558 if (strEQ(d,"my")) return KEY_my;
5561 if (strEQ(d,"map")) return KEY_map;
5564 if (strEQ(d,"mkdir")) return -KEY_mkdir;
5567 if (strEQ(d,"msgctl")) return -KEY_msgctl;
5568 if (strEQ(d,"msgget")) return -KEY_msgget;
5569 if (strEQ(d,"msgrcv")) return -KEY_msgrcv;
5570 if (strEQ(d,"msgsnd")) return -KEY_msgsnd;
5575 if (strEQ(d,"next")) return KEY_next;
5576 if (strEQ(d,"ne")) return -KEY_ne;
5577 if (strEQ(d,"not")) return -KEY_not;
5578 if (strEQ(d,"no")) return KEY_no;
5583 if (strEQ(d,"or")) return -KEY_or;
5586 if (strEQ(d,"ord")) return -KEY_ord;
5587 if (strEQ(d,"oct")) return -KEY_oct;
5588 if (strEQ(d,"our")) return KEY_our;
5591 if (strEQ(d,"open")) return -KEY_open;
5594 if (strEQ(d,"opendir")) return -KEY_opendir;
5601 if (strEQ(d,"pop")) return -KEY_pop;
5602 if (strEQ(d,"pos")) return KEY_pos;
5605 if (strEQ(d,"push")) return -KEY_push;
5606 if (strEQ(d,"pack")) return -KEY_pack;
5607 if (strEQ(d,"pipe")) return -KEY_pipe;
5610 if (strEQ(d,"print")) return KEY_print;
5613 if (strEQ(d,"printf")) return KEY_printf;
5616 if (strEQ(d,"package")) return KEY_package;
5619 if (strEQ(d,"prototype")) return KEY_prototype;
5624 if (strEQ(d,"q")) return KEY_q;
5625 if (strEQ(d,"qr")) return KEY_qr;
5626 if (strEQ(d,"qq")) return KEY_qq;
5627 if (strEQ(d,"qw")) return KEY_qw;
5628 if (strEQ(d,"qx")) return KEY_qx;
5630 else if (strEQ(d,"quotemeta")) return -KEY_quotemeta;
5635 if (strEQ(d,"ref")) return -KEY_ref;
5638 if (strEQ(d,"read")) return -KEY_read;
5639 if (strEQ(d,"rand")) return -KEY_rand;
5640 if (strEQ(d,"recv")) return -KEY_recv;
5641 if (strEQ(d,"redo")) return KEY_redo;
5644 if (strEQ(d,"rmdir")) return -KEY_rmdir;
5645 if (strEQ(d,"reset")) return -KEY_reset;
5648 if (strEQ(d,"return")) return KEY_return;
5649 if (strEQ(d,"rename")) return -KEY_rename;
5650 if (strEQ(d,"rindex")) return -KEY_rindex;
5653 if (strEQ(d,"require")) return KEY_require;
5654 if (strEQ(d,"reverse")) return -KEY_reverse;
5655 if (strEQ(d,"readdir")) return -KEY_readdir;
5658 if (strEQ(d,"readlink")) return -KEY_readlink;
5659 if (strEQ(d,"readline")) return -KEY_readline;
5660 if (strEQ(d,"readpipe")) return -KEY_readpipe;
5663 if (strEQ(d,"rewinddir")) return -KEY_rewinddir;
5669 case 0: return KEY_s;
5671 if (strEQ(d,"scalar")) return KEY_scalar;
5676 if (strEQ(d,"seek")) return -KEY_seek;
5677 if (strEQ(d,"send")) return -KEY_send;
5680 if (strEQ(d,"semop")) return -KEY_semop;
5683 if (strEQ(d,"select")) return -KEY_select;
5684 if (strEQ(d,"semctl")) return -KEY_semctl;
5685 if (strEQ(d,"semget")) return -KEY_semget;
5688 if (strEQ(d,"setpgrp")) return -KEY_setpgrp;
5689 if (strEQ(d,"seekdir")) return -KEY_seekdir;
5692 if (strEQ(d,"setpwent")) return -KEY_setpwent;
5693 if (strEQ(d,"setgrent")) return -KEY_setgrent;
5696 if (strEQ(d,"setnetent")) return -KEY_setnetent;
5699 if (strEQ(d,"setsockopt")) return -KEY_setsockopt;
5700 if (strEQ(d,"sethostent")) return -KEY_sethostent;
5701 if (strEQ(d,"setservent")) return -KEY_setservent;
5704 if (strEQ(d,"setpriority")) return -KEY_setpriority;
5705 if (strEQ(d,"setprotoent")) return -KEY_setprotoent;
5712 if (strEQ(d,"shift")) return -KEY_shift;
5715 if (strEQ(d,"shmctl")) return -KEY_shmctl;
5716 if (strEQ(d,"shmget")) return -KEY_shmget;
5719 if (strEQ(d,"shmread")) return -KEY_shmread;
5722 if (strEQ(d,"shmwrite")) return -KEY_shmwrite;
5723 if (strEQ(d,"shutdown")) return -KEY_shutdown;
5728 if (strEQ(d,"sin")) return -KEY_sin;
5731 if (strEQ(d,"sleep")) return -KEY_sleep;
5734 if (strEQ(d,"sort")) return KEY_sort;
5735 if (strEQ(d,"socket")) return -KEY_socket;
5736 if (strEQ(d,"socketpair")) return -KEY_socketpair;
5739 if (strEQ(d,"split")) return KEY_split;
5740 if (strEQ(d,"sprintf")) return -KEY_sprintf;
5741 if (strEQ(d,"splice")) return -KEY_splice;
5744 if (strEQ(d,"sqrt")) return -KEY_sqrt;
5747 if (strEQ(d,"srand")) return -KEY_srand;
5750 if (strEQ(d,"stat")) return -KEY_stat;
5751 if (strEQ(d,"study")) return KEY_study;
5754 if (strEQ(d,"substr")) return -KEY_substr;
5755 if (strEQ(d,"sub")) return KEY_sub;
5760 if (strEQ(d,"system")) return -KEY_system;
5763 if (strEQ(d,"symlink")) return -KEY_symlink;
5764 if (strEQ(d,"syscall")) return -KEY_syscall;
5765 if (strEQ(d,"sysopen")) return -KEY_sysopen;
5766 if (strEQ(d,"sysread")) return -KEY_sysread;
5767 if (strEQ(d,"sysseek")) return -KEY_sysseek;
5770 if (strEQ(d,"syswrite")) return -KEY_syswrite;
5779 if (strEQ(d,"tr")) return KEY_tr;
5782 if (strEQ(d,"tie")) return KEY_tie;
5785 if (strEQ(d,"tell")) return -KEY_tell;
5786 if (strEQ(d,"tied")) return KEY_tied;
5787 if (strEQ(d,"time")) return -KEY_time;
5790 if (strEQ(d,"times")) return -KEY_times;
5793 if (strEQ(d,"telldir")) return -KEY_telldir;
5796 if (strEQ(d,"truncate")) return -KEY_truncate;
5803 if (strEQ(d,"uc")) return -KEY_uc;
5806 if (strEQ(d,"use")) return KEY_use;
5809 if (strEQ(d,"undef")) return KEY_undef;
5810 if (strEQ(d,"until")) return KEY_until;
5811 if (strEQ(d,"untie")) return KEY_untie;
5812 if (strEQ(d,"utime")) return -KEY_utime;
5813 if (strEQ(d,"umask")) return -KEY_umask;
5816 if (strEQ(d,"unless")) return KEY_unless;
5817 if (strEQ(d,"unpack")) return -KEY_unpack;
5818 if (strEQ(d,"unlink")) return -KEY_unlink;
5821 if (strEQ(d,"unshift")) return -KEY_unshift;
5822 if (strEQ(d,"ucfirst")) return -KEY_ucfirst;
5827 if (strEQ(d,"values")) return -KEY_values;
5828 if (strEQ(d,"vec")) return -KEY_vec;
5833 if (strEQ(d,"warn")) return -KEY_warn;
5834 if (strEQ(d,"wait")) return -KEY_wait;
5837 if (strEQ(d,"while")) return KEY_while;
5838 if (strEQ(d,"write")) return -KEY_write;
5841 if (strEQ(d,"waitpid")) return -KEY_waitpid;
5844 if (strEQ(d,"wantarray")) return -KEY_wantarray;
5849 if (len == 1) return -KEY_x;
5850 if (strEQ(d,"xor")) return -KEY_xor;
5853 if (len == 1) return KEY_y;
5862 S_checkcomma(pTHX_ register char *s, char *name, char *what)
5866 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
5867 if (ckWARN(WARN_SYNTAX)) {
5869 for (w = s+2; *w && level; w++) {
5876 for (; *w && isSPACE(*w); w++) ;
5877 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
5878 Perl_warner(aTHX_ WARN_SYNTAX,
5879 "%s (...) interpreted as function",name);
5882 while (s < PL_bufend && isSPACE(*s))
5886 while (s < PL_bufend && isSPACE(*s))
5888 if (isIDFIRST_lazy_if(s,UTF)) {
5890 while (isALNUM_lazy_if(s,UTF))
5892 while (s < PL_bufend && isSPACE(*s))
5897 kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
5901 Perl_croak(aTHX_ "No comma allowed after %s", what);
5906 /* Either returns sv, or mortalizes sv and returns a new SV*.
5907 Best used as sv=new_constant(..., sv, ...).
5908 If s, pv are NULL, calls subroutine with one argument,
5909 and type is used with error messages only. */
5912 S_new_constant(pTHX_ char *s, STRLEN len, const char *key, SV *sv, SV *pv,
5916 HV *table = GvHV(PL_hintgv); /* ^H */
5920 const char *why1, *why2, *why3;
5922 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
5925 why2 = strEQ(key,"charnames")
5926 ? "(possibly a missing \"use charnames ...\")"
5928 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
5929 (type ? type: "undef"), why2);
5931 /* This is convoluted and evil ("goto considered harmful")
5932 * but I do not understand the intricacies of all the different
5933 * failure modes of %^H in here. The goal here is to make
5934 * the most probable error message user-friendly. --jhi */
5939 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
5940 (type ? type: "undef"), why1, why2, why3);
5942 yyerror(SvPVX(msg));
5946 cvp = hv_fetch(table, key, strlen(key), FALSE);
5947 if (!cvp || !SvOK(*cvp)) {
5950 why3 = "} is not defined";
5953 sv_2mortal(sv); /* Parent created it permanently */
5956 pv = sv_2mortal(newSVpvn(s, len));
5958 typesv = sv_2mortal(newSVpv(type, 0));
5960 typesv = &PL_sv_undef;
5962 PUSHSTACKi(PERLSI_OVERLOAD);
5974 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
5978 /* Check the eval first */
5979 if (!PL_in_eval && SvTRUE(ERRSV)) {
5981 sv_catpv(ERRSV, "Propagated");
5982 yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */
5984 res = SvREFCNT_inc(sv);
5988 (void)SvREFCNT_inc(res);
5997 why1 = "Call to &{$^H{";
5999 why3 = "}} did not return a defined value";
6008 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
6010 register char *d = dest;
6011 register char *e = d + destlen - 3; /* two-character token, ending NUL */
6014 Perl_croak(aTHX_ ident_too_long);
6015 if (isALNUM(*s)) /* UTF handled below */
6017 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
6022 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
6026 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
6027 char *t = s + UTF8SKIP(s);
6028 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
6030 if (d + (t - s) > e)
6031 Perl_croak(aTHX_ ident_too_long);
6032 Copy(s, d, t - s, char);
6045 S_scan_ident(pTHX_ register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni)
6055 e = d + destlen - 3; /* two-character token, ending NUL */
6057 while (isDIGIT(*s)) {
6059 Perl_croak(aTHX_ ident_too_long);
6066 Perl_croak(aTHX_ ident_too_long);
6067 if (isALNUM(*s)) /* UTF handled below */
6069 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
6074 else if (*s == ':' && s[1] == ':') {
6078 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
6079 char *t = s + UTF8SKIP(s);
6080 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
6082 if (d + (t - s) > e)
6083 Perl_croak(aTHX_ ident_too_long);
6084 Copy(s, d, t - s, char);
6095 if (PL_lex_state != LEX_NORMAL)
6096 PL_lex_state = LEX_INTERPENDMAYBE;
6099 if (*s == '$' && s[1] &&
6100 (isALNUM_lazy_if(s+1,UTF) || strchr("${", s[1]) || strnEQ(s+1,"::",2)) )
6113 if (*d == '^' && *s && isCONTROLVAR(*s)) {
6118 if (isSPACE(s[-1])) {
6121 if (!SPACE_OR_TAB(ch)) {
6127 if (isIDFIRST_lazy_if(d,UTF)) {
6131 while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') {
6133 while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e))
6136 Copy(s, d, e - s, char);
6141 while ((isALNUM(*s) || *s == ':') && d < e)
6144 Perl_croak(aTHX_ ident_too_long);
6147 while (s < send && SPACE_OR_TAB(*s)) s++;
6148 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
6149 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
6150 const char *brack = *s == '[' ? "[...]" : "{...}";
6151 Perl_warner(aTHX_ WARN_AMBIGUOUS,
6152 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
6153 funny, dest, brack, funny, dest, brack);
6156 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
6160 /* Handle extended ${^Foo} variables
6161 * 1999-02-27 mjd-perl-patch@plover.com */
6162 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
6166 while (isALNUM(*s) && d < e) {
6170 Perl_croak(aTHX_ ident_too_long);
6175 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets)
6176 PL_lex_state = LEX_INTERPEND;
6179 if (PL_lex_state == LEX_NORMAL) {
6180 if (ckWARN(WARN_AMBIGUOUS) &&
6181 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
6183 Perl_warner(aTHX_ WARN_AMBIGUOUS,
6184 "Ambiguous use of %c{%s} resolved to %c%s",
6185 funny, dest, funny, dest);
6190 s = bracket; /* let the parser handle it */
6194 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
6195 PL_lex_state = LEX_INTERPEND;
6200 Perl_pmflag(pTHX_ U16 *pmfl, int ch)
6205 *pmfl |= PMf_GLOBAL;
6207 *pmfl |= PMf_CONTINUE;
6211 *pmfl |= PMf_MULTILINE;
6213 *pmfl |= PMf_SINGLELINE;
6215 *pmfl |= PMf_EXTENDED;
6219 S_scan_pat(pTHX_ char *start, I32 type)
6224 s = scan_str(start,FALSE,FALSE);
6226 Perl_croak(aTHX_ "Search pattern not terminated");
6228 pm = (PMOP*)newPMOP(type, 0);
6229 if (PL_multi_open == '?')
6230 pm->op_pmflags |= PMf_ONCE;
6232 while (*s && strchr("iomsx", *s))
6233 pmflag(&pm->op_pmflags,*s++);
6236 while (*s && strchr("iogcmsx", *s))
6237 pmflag(&pm->op_pmflags,*s++);
6239 pm->op_pmpermflags = pm->op_pmflags;
6241 PL_lex_op = (OP*)pm;
6242 yylval.ival = OP_MATCH;
6247 S_scan_subst(pTHX_ char *start)
6254 yylval.ival = OP_NULL;
6256 s = scan_str(start,FALSE,FALSE);
6259 Perl_croak(aTHX_ "Substitution pattern not terminated");
6261 if (s[-1] == PL_multi_open)
6264 first_start = PL_multi_start;
6265 s = scan_str(s,FALSE,FALSE);
6268 SvREFCNT_dec(PL_lex_stuff);
6269 PL_lex_stuff = Nullsv;
6271 Perl_croak(aTHX_ "Substitution replacement not terminated");
6273 PL_multi_start = first_start; /* so whole substitution is taken together */
6275 pm = (PMOP*)newPMOP(OP_SUBST, 0);
6281 else if (strchr("iogcmsx", *s))
6282 pmflag(&pm->op_pmflags,*s++);
6289 PL_sublex_info.super_bufptr = s;
6290 PL_sublex_info.super_bufend = PL_bufend;
6292 pm->op_pmflags |= PMf_EVAL;
6293 repl = newSVpvn("",0);
6295 sv_catpv(repl, es ? "eval " : "do ");
6296 sv_catpvn(repl, "{ ", 2);
6297 sv_catsv(repl, PL_lex_repl);
6298 sv_catpvn(repl, " };", 2);
6300 SvREFCNT_dec(PL_lex_repl);
6304 pm->op_pmpermflags = pm->op_pmflags;
6305 PL_lex_op = (OP*)pm;
6306 yylval.ival = OP_SUBST;
6311 S_scan_trans(pTHX_ char *start)
6320 yylval.ival = OP_NULL;
6322 s = scan_str(start,FALSE,FALSE);
6324 Perl_croak(aTHX_ "Transliteration pattern not terminated");
6325 if (s[-1] == PL_multi_open)
6328 s = scan_str(s,FALSE,FALSE);
6331 SvREFCNT_dec(PL_lex_stuff);
6332 PL_lex_stuff = Nullsv;
6334 Perl_croak(aTHX_ "Transliteration replacement not terminated");
6337 complement = del = squash = 0;
6338 while (strchr("cds", *s)) {
6340 complement = OPpTRANS_COMPLEMENT;
6342 del = OPpTRANS_DELETE;
6344 squash = OPpTRANS_SQUASH;
6348 New(803, tbl, complement&&!del?258:256, short);
6349 o = newPVOP(OP_TRANS, 0, (char*)tbl);
6350 o->op_private = del|squash|complement|
6351 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
6352 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
6355 yylval.ival = OP_TRANS;
6360 S_scan_heredoc(pTHX_ register char *s)
6363 I32 op_type = OP_SCALAR;
6370 int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
6374 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
6377 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
6378 if (*peek && strchr("`'\"",*peek)) {
6381 s = delimcpy(d, e, s, PL_bufend, term, &len);
6391 if (!isALNUM_lazy_if(s,UTF))
6392 deprecate("bare << to mean <<\"\"");
6393 for (; isALNUM_lazy_if(s,UTF); s++) {
6398 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
6399 Perl_croak(aTHX_ "Delimiter for here document is too long");
6402 len = d - PL_tokenbuf;
6403 #ifndef PERL_STRICT_CR
6404 d = strchr(s, '\r');
6408 while (s < PL_bufend) {
6414 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
6423 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
6428 if (outer || !(d=ninstr(s,PL_bufend,d,d+1)))
6429 herewas = newSVpvn(s,PL_bufend-s);
6431 s--, herewas = newSVpvn(s,d-s);
6432 s += SvCUR(herewas);
6434 tmpstr = NEWSV(87,79);
6435 sv_upgrade(tmpstr, SVt_PVIV);
6440 else if (term == '`') {
6441 op_type = OP_BACKTICK;
6442 SvIVX(tmpstr) = '\\';
6446 PL_multi_start = CopLINE(PL_curcop);
6447 PL_multi_open = PL_multi_close = '<';
6448 term = *PL_tokenbuf;
6449 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
6450 char *bufptr = PL_sublex_info.super_bufptr;
6451 char *bufend = PL_sublex_info.super_bufend;
6452 char *olds = s - SvCUR(herewas);
6453 s = strchr(bufptr, '\n');
6457 while (s < bufend &&
6458 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
6460 CopLINE_inc(PL_curcop);
6463 CopLINE_set(PL_curcop, PL_multi_start);
6464 missingterm(PL_tokenbuf);
6466 sv_setpvn(herewas,bufptr,d-bufptr+1);
6467 sv_setpvn(tmpstr,d+1,s-d);
6469 sv_catpvn(herewas,s,bufend-s);
6470 (void)strcpy(bufptr,SvPVX(herewas));
6477 while (s < PL_bufend &&
6478 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
6480 CopLINE_inc(PL_curcop);
6482 if (s >= PL_bufend) {
6483 CopLINE_set(PL_curcop, PL_multi_start);
6484 missingterm(PL_tokenbuf);
6486 sv_setpvn(tmpstr,d+1,s-d);
6488 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
6490 sv_catpvn(herewas,s,PL_bufend-s);
6491 sv_setsv(PL_linestr,herewas);
6492 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
6493 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6494 PL_last_lop = PL_last_uni = Nullch;
6497 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
6498 while (s >= PL_bufend) { /* multiple line string? */
6500 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
6501 CopLINE_set(PL_curcop, PL_multi_start);
6502 missingterm(PL_tokenbuf);
6504 CopLINE_inc(PL_curcop);
6505 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6506 PL_last_lop = PL_last_uni = Nullch;
6507 #ifndef PERL_STRICT_CR
6508 if (PL_bufend - PL_linestart >= 2) {
6509 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
6510 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
6512 PL_bufend[-2] = '\n';
6514 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
6516 else if (PL_bufend[-1] == '\r')
6517 PL_bufend[-1] = '\n';
6519 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
6520 PL_bufend[-1] = '\n';
6522 if (PERLDB_LINE && PL_curstash != PL_debstash) {
6523 SV *sv = NEWSV(88,0);
6525 sv_upgrade(sv, SVt_PVMG);
6526 sv_setsv(sv,PL_linestr);
6527 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
6529 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
6532 sv_catsv(PL_linestr,herewas);
6533 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6537 sv_catsv(tmpstr,PL_linestr);
6542 PL_multi_end = CopLINE(PL_curcop);
6543 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
6544 SvLEN_set(tmpstr, SvCUR(tmpstr) + 1);
6545 Renew(SvPVX(tmpstr), SvLEN(tmpstr), char);
6547 SvREFCNT_dec(herewas);
6548 if (UTF && !IN_BYTES && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr)))
6550 PL_lex_stuff = tmpstr;
6551 yylval.ival = op_type;
6556 takes: current position in input buffer
6557 returns: new position in input buffer
6558 side-effects: yylval and lex_op are set.
6563 <FH> read from filehandle
6564 <pkg::FH> read from package qualified filehandle
6565 <pkg'FH> read from package qualified filehandle
6566 <$fh> read from filehandle in $fh
6572 S_scan_inputsymbol(pTHX_ char *start)
6574 register char *s = start; /* current position in buffer */
6580 d = PL_tokenbuf; /* start of temp holding space */
6581 e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
6582 end = strchr(s, '\n');
6585 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
6587 /* die if we didn't have space for the contents of the <>,
6588 or if it didn't end, or if we see a newline
6591 if (len >= sizeof PL_tokenbuf)
6592 Perl_croak(aTHX_ "Excessively long <> operator");
6594 Perl_croak(aTHX_ "Unterminated <> operator");
6599 Remember, only scalar variables are interpreted as filehandles by
6600 this code. Anything more complex (e.g., <$fh{$num}>) will be
6601 treated as a glob() call.
6602 This code makes use of the fact that except for the $ at the front,
6603 a scalar variable and a filehandle look the same.
6605 if (*d == '$' && d[1]) d++;
6607 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
6608 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
6611 /* If we've tried to read what we allow filehandles to look like, and
6612 there's still text left, then it must be a glob() and not a getline.
6613 Use scan_str to pull out the stuff between the <> and treat it
6614 as nothing more than a string.
6617 if (d - PL_tokenbuf != len) {
6618 yylval.ival = OP_GLOB;
6620 s = scan_str(start,FALSE,FALSE);
6622 Perl_croak(aTHX_ "Glob not terminated");
6626 /* we're in a filehandle read situation */
6629 /* turn <> into <ARGV> */
6631 (void)strcpy(d,"ARGV");
6633 /* if <$fh>, create the ops to turn the variable into a
6639 /* try to find it in the pad for this block, otherwise find
6640 add symbol table ops
6642 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
6643 OP *o = newOP(OP_PADSV, 0);
6645 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, o);
6648 GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV);
6649 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0,
6650 newUNOP(OP_RV2SV, 0,
6651 newGVOP(OP_GV, 0, gv)));
6653 PL_lex_op->op_flags |= OPf_SPECIAL;
6654 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
6655 yylval.ival = OP_NULL;
6658 /* If it's none of the above, it must be a literal filehandle
6659 (<Foo::BAR> or <FOO>) so build a simple readline OP */
6661 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
6662 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
6663 yylval.ival = OP_NULL;
6672 takes: start position in buffer
6673 keep_quoted preserve \ on the embedded delimiter(s)
6674 keep_delims preserve the delimiters around the string
6675 returns: position to continue reading from buffer
6676 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
6677 updates the read buffer.
6679 This subroutine pulls a string out of the input. It is called for:
6680 q single quotes q(literal text)
6681 ' single quotes 'literal text'
6682 qq double quotes qq(interpolate $here please)
6683 " double quotes "interpolate $here please"
6684 qx backticks qx(/bin/ls -l)
6685 ` backticks `/bin/ls -l`
6686 qw quote words @EXPORT_OK = qw( func() $spam )
6687 m// regexp match m/this/
6688 s/// regexp substitute s/this/that/
6689 tr/// string transliterate tr/this/that/
6690 y/// string transliterate y/this/that/
6691 ($*@) sub prototypes sub foo ($)
6692 (stuff) sub attr parameters sub foo : attr(stuff)
6693 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
6695 In most of these cases (all but <>, patterns and transliterate)
6696 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
6697 calls scan_str(). s/// makes yylex() call scan_subst() which calls
6698 scan_str(). tr/// and y/// make yylex() call scan_trans() which
6701 It skips whitespace before the string starts, and treats the first
6702 character as the delimiter. If the delimiter is one of ([{< then
6703 the corresponding "close" character )]}> is used as the closing
6704 delimiter. It allows quoting of delimiters, and if the string has
6705 balanced delimiters ([{<>}]) it allows nesting.
6707 On success, the SV with the resulting string is put into lex_stuff or,
6708 if that is already non-NULL, into lex_repl. The second case occurs only
6709 when parsing the RHS of the special constructs s/// and tr/// (y///).
6710 For convenience, the terminating delimiter character is stuffed into
6715 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
6717 SV *sv; /* scalar value: string */
6718 char *tmps; /* temp string, used for delimiter matching */
6719 register char *s = start; /* current position in the buffer */
6720 register char term; /* terminating character */
6721 register char *to; /* current position in the sv's data */
6722 I32 brackets = 1; /* bracket nesting level */
6723 bool has_utf8 = FALSE; /* is there any utf8 content? */
6725 /* skip space before the delimiter */
6729 /* mark where we are, in case we need to report errors */
6732 /* after skipping whitespace, the next character is the terminator */
6734 if (!UTF8_IS_INVARIANT((U8)term) && UTF)
6737 /* mark where we are */
6738 PL_multi_start = CopLINE(PL_curcop);
6739 PL_multi_open = term;
6741 /* find corresponding closing delimiter */
6742 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
6744 PL_multi_close = term;
6746 /* create a new SV to hold the contents. 87 is leak category, I'm
6747 assuming. 79 is the SV's initial length. What a random number. */
6749 sv_upgrade(sv, SVt_PVIV);
6751 (void)SvPOK_only(sv); /* validate pointer */
6753 /* move past delimiter and try to read a complete string */
6755 sv_catpvn(sv, s, 1);
6758 /* extend sv if need be */
6759 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
6760 /* set 'to' to the next character in the sv's string */
6761 to = SvPVX(sv)+SvCUR(sv);
6763 /* if open delimiter is the close delimiter read unbridle */
6764 if (PL_multi_open == PL_multi_close) {
6765 for (; s < PL_bufend; s++,to++) {
6766 /* embedded newlines increment the current line number */
6767 if (*s == '\n' && !PL_rsfp)
6768 CopLINE_inc(PL_curcop);
6769 /* handle quoted delimiters */
6770 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
6771 if (!keep_quoted && s[1] == term)
6773 /* any other quotes are simply copied straight through */
6777 /* terminate when run out of buffer (the for() condition), or
6778 have found the terminator */
6779 else if (*s == term)
6781 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
6787 /* if the terminator isn't the same as the start character (e.g.,
6788 matched brackets), we have to allow more in the quoting, and
6789 be prepared for nested brackets.
6792 /* read until we run out of string, or we find the terminator */
6793 for (; s < PL_bufend; s++,to++) {
6794 /* embedded newlines increment the line count */
6795 if (*s == '\n' && !PL_rsfp)
6796 CopLINE_inc(PL_curcop);
6797 /* backslashes can escape the open or closing characters */
6798 if (*s == '\\' && s+1 < PL_bufend) {
6800 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
6805 /* allow nested opens and closes */
6806 else if (*s == PL_multi_close && --brackets <= 0)
6808 else if (*s == PL_multi_open)
6810 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
6815 /* terminate the copied string and update the sv's end-of-string */
6817 SvCUR_set(sv, to - SvPVX(sv));
6820 * this next chunk reads more into the buffer if we're not done yet
6824 break; /* handle case where we are done yet :-) */
6826 #ifndef PERL_STRICT_CR
6827 if (to - SvPVX(sv) >= 2) {
6828 if ((to[-2] == '\r' && to[-1] == '\n') ||
6829 (to[-2] == '\n' && to[-1] == '\r'))
6833 SvCUR_set(sv, to - SvPVX(sv));
6835 else if (to[-1] == '\r')
6838 else if (to - SvPVX(sv) == 1 && to[-1] == '\r')
6842 /* if we're out of file, or a read fails, bail and reset the current
6843 line marker so we can report where the unterminated string began
6846 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
6848 CopLINE_set(PL_curcop, PL_multi_start);
6851 /* we read a line, so increment our line counter */
6852 CopLINE_inc(PL_curcop);
6854 /* update debugger info */
6855 if (PERLDB_LINE && PL_curstash != PL_debstash) {
6856 SV *sv = NEWSV(88,0);
6858 sv_upgrade(sv, SVt_PVMG);
6859 sv_setsv(sv,PL_linestr);
6860 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
6863 /* having changed the buffer, we must update PL_bufend */
6864 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6865 PL_last_lop = PL_last_uni = Nullch;
6868 /* at this point, we have successfully read the delimited string */
6871 sv_catpvn(sv, s, 1);
6874 PL_multi_end = CopLINE(PL_curcop);
6877 /* if we allocated too much space, give some back */
6878 if (SvCUR(sv) + 5 < SvLEN(sv)) {
6879 SvLEN_set(sv, SvCUR(sv) + 1);
6880 Renew(SvPVX(sv), SvLEN(sv), char);
6883 /* decide whether this is the first or second quoted string we've read
6896 takes: pointer to position in buffer
6897 returns: pointer to new position in buffer
6898 side-effects: builds ops for the constant in yylval.op
6900 Read a number in any of the formats that Perl accepts:
6902 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
6903 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
6906 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
6908 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
6911 If it reads a number without a decimal point or an exponent, it will
6912 try converting the number to an integer and see if it can do so
6913 without loss of precision.
6917 Perl_scan_num(pTHX_ char *start, YYSTYPE* lvalp)
6919 register char *s = start; /* current position in buffer */
6920 register char *d; /* destination in temp buffer */
6921 register char *e; /* end of temp buffer */
6922 NV nv; /* number read, as a double */
6923 SV *sv = Nullsv; /* place to put the converted number */
6924 bool floatit; /* boolean: int or float? */
6925 char *lastub = 0; /* position of last underbar */
6926 static char number_too_long[] = "Number too long";
6928 /* We use the first character to decide what type of number this is */
6932 Perl_croak(aTHX_ "panic: scan_num");
6934 /* if it starts with a 0, it could be an octal number, a decimal in
6935 0.13 disguise, or a hexadecimal number, or a binary number. */
6939 u holds the "number so far"
6940 shift the power of 2 of the base
6941 (hex == 4, octal == 3, binary == 1)
6942 overflowed was the number more than we can hold?
6944 Shift is used when we add a digit. It also serves as an "are
6945 we in octal/hex/binary?" indicator to disallow hex characters
6951 bool overflowed = FALSE;
6952 static NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
6953 static char* bases[5] = { "", "binary", "", "octal",
6955 static char* Bases[5] = { "", "Binary", "", "Octal",
6957 static char *maxima[5] = { "",
6958 "0b11111111111111111111111111111111",
6962 char *base, *Base, *max;
6968 } else if (s[1] == 'b') {
6972 /* check for a decimal in disguise */
6973 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
6975 /* so it must be octal */
6982 if (ckWARN(WARN_SYNTAX))
6983 Perl_warner(aTHX_ WARN_SYNTAX,
6984 "Misplaced _ in number");
6988 base = bases[shift];
6989 Base = Bases[shift];
6990 max = maxima[shift];
6992 /* read the rest of the number */
6994 /* x is used in the overflow test,
6995 b is the digit we're adding on. */
7000 /* if we don't mention it, we're done */
7004 /* _ are ignored -- but warned about if consecutive */
7006 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
7007 Perl_warner(aTHX_ WARN_SYNTAX,
7008 "Misplaced _ in number");
7012 /* 8 and 9 are not octal */
7015 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
7019 case '2': case '3': case '4':
7020 case '5': case '6': case '7':
7022 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
7026 b = *s++ & 15; /* ASCII digit -> value of digit */
7030 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
7031 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
7032 /* make sure they said 0x */
7037 /* Prepare to put the digit we have onto the end
7038 of the number so far. We check for overflows.
7043 x = u << shift; /* make room for the digit */
7045 if ((x >> shift) != u
7046 && !(PL_hints & HINT_NEW_BINARY)) {
7049 if (ckWARN_d(WARN_OVERFLOW))
7050 Perl_warner(aTHX_ WARN_OVERFLOW,
7051 "Integer overflow in %s number",
7054 u = x | b; /* add the digit to the end */
7057 n *= nvshift[shift];
7058 /* If an NV has not enough bits in its
7059 * mantissa to represent an UV this summing of
7060 * small low-order numbers is a waste of time
7061 * (because the NV cannot preserve the
7062 * low-order bits anyway): we could just
7063 * remember when did we overflow and in the
7064 * end just multiply n by the right
7072 /* if we get here, we had success: make a scalar value from
7077 /* final misplaced underbar check */
7079 if (ckWARN(WARN_SYNTAX))
7080 Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number");
7085 if (ckWARN(WARN_PORTABLE) && n > 4294967295.0)
7086 Perl_warner(aTHX_ WARN_PORTABLE,
7087 "%s number > %s non-portable",
7093 if (ckWARN(WARN_PORTABLE) && u > 0xffffffff)
7094 Perl_warner(aTHX_ WARN_PORTABLE,
7095 "%s number > %s non-portable",
7100 if (PL_hints & HINT_NEW_BINARY)
7101 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
7106 handle decimal numbers.
7107 we're also sent here when we read a 0 as the first digit
7109 case '1': case '2': case '3': case '4': case '5':
7110 case '6': case '7': case '8': case '9': case '.':
7113 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
7116 /* read next group of digits and _ and copy into d */
7117 while (isDIGIT(*s) || *s == '_') {
7118 /* skip underscores, checking for misplaced ones
7122 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
7123 Perl_warner(aTHX_ WARN_SYNTAX,
7124 "Misplaced _ in number");
7128 /* check for end of fixed-length buffer */
7130 Perl_croak(aTHX_ number_too_long);
7131 /* if we're ok, copy the character */
7136 /* final misplaced underbar check */
7137 if (lastub && s == lastub + 1) {
7138 if (ckWARN(WARN_SYNTAX))
7139 Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number");
7142 /* read a decimal portion if there is one. avoid
7143 3..5 being interpreted as the number 3. followed
7146 if (*s == '.' && s[1] != '.') {
7151 if (ckWARN(WARN_SYNTAX))
7152 Perl_warner(aTHX_ WARN_SYNTAX,
7153 "Misplaced _ in number");
7157 /* copy, ignoring underbars, until we run out of digits.
7159 for (; isDIGIT(*s) || *s == '_'; s++) {
7160 /* fixed length buffer check */
7162 Perl_croak(aTHX_ number_too_long);
7164 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
7165 Perl_warner(aTHX_ WARN_SYNTAX,
7166 "Misplaced _ in number");
7172 /* fractional part ending in underbar? */
7174 if (ckWARN(WARN_SYNTAX))
7175 Perl_warner(aTHX_ WARN_SYNTAX,
7176 "Misplaced _ in number");
7178 if (*s == '.' && isDIGIT(s[1])) {
7179 /* oops, it's really a v-string, but without the "v" */
7185 /* read exponent part, if present */
7186 if (*s && strchr("eE",*s) && strchr("+-0123456789_", s[1])) {
7190 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
7191 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
7193 /* stray preinitial _ */
7195 if (ckWARN(WARN_SYNTAX))
7196 Perl_warner(aTHX_ WARN_SYNTAX,
7197 "Misplaced _ in number");
7201 /* allow positive or negative exponent */
7202 if (*s == '+' || *s == '-')
7205 /* stray initial _ */
7207 if (ckWARN(WARN_SYNTAX))
7208 Perl_warner(aTHX_ WARN_SYNTAX,
7209 "Misplaced _ in number");
7213 /* read digits of exponent */
7214 while (isDIGIT(*s) || *s == '_') {
7217 Perl_croak(aTHX_ number_too_long);
7221 if (ckWARN(WARN_SYNTAX) &&
7222 ((lastub && s == lastub + 1) ||
7223 (!isDIGIT(s[1]) && s[1] != '_')))
7224 Perl_warner(aTHX_ WARN_SYNTAX,
7225 "Misplaced _ in number");
7232 /* make an sv from the string */
7236 We try to do an integer conversion first if no characters
7237 indicating "float" have been found.
7242 int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
7244 if (flags == IS_NUMBER_IN_UV) {
7246 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
7249 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
7250 if (uv <= (UV) IV_MIN)
7251 sv_setiv(sv, -(IV)uv);
7258 /* terminate the string */
7260 nv = Atof(PL_tokenbuf);
7264 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
7265 (PL_hints & HINT_NEW_INTEGER) )
7266 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
7267 (floatit ? "float" : "integer"),
7271 /* if it starts with a v, it could be a v-string */
7277 while (isDIGIT(*pos) || *pos == '_')
7279 if (!isALPHA(*pos)) {
7281 U8 tmpbuf[UTF8_MAXLEN+1];
7283 s++; /* get past 'v' */
7286 sv_setpvn(sv, "", 0);
7289 if (*s == '0' && isDIGIT(s[1]))
7290 yyerror("Octal number in vector unsupported");
7293 /* this is atoi() that tolerates underscores */
7296 while (--end >= s) {
7301 rev += (*end - '0') * mult;
7303 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
7304 Perl_warner(aTHX_ WARN_OVERFLOW,
7305 "Integer overflow in decimal number");
7308 /* Append native character for the rev point */
7309 tmpend = uvchr_to_utf8(tmpbuf, rev);
7310 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
7311 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
7313 if (*pos == '.' && isDIGIT(pos[1]))
7319 while (isDIGIT(*pos) || *pos == '_')
7329 /* make the op for the constant and return */
7332 lvalp->opval = newSVOP(OP_CONST, 0, sv);
7334 lvalp->opval = Nullop;
7340 S_scan_formline(pTHX_ register char *s)
7344 SV *stuff = newSVpvn("",0);
7345 bool needargs = FALSE;
7348 if (*s == '.' || *s == /*{*/'}') {
7350 #ifdef PERL_STRICT_CR
7351 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
7353 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
7355 if (*t == '\n' || t == PL_bufend)
7358 if (PL_in_eval && !PL_rsfp) {
7359 eol = strchr(s,'\n');
7364 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
7366 for (t = s; t < eol; t++) {
7367 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
7369 goto enough; /* ~~ must be first line in formline */
7371 if (*t == '@' || *t == '^')
7374 sv_catpvn(stuff, s, eol-s);
7375 #ifndef PERL_STRICT_CR
7376 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
7377 char *end = SvPVX(stuff) + SvCUR(stuff);
7386 s = filter_gets(PL_linestr, PL_rsfp, 0);
7387 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
7388 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
7389 PL_last_lop = PL_last_uni = Nullch;
7392 yyerror("Format not terminated");
7402 PL_lex_state = LEX_NORMAL;
7403 PL_nextval[PL_nexttoke].ival = 0;
7407 PL_lex_state = LEX_FORMLINE;
7408 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
7410 PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
7414 SvREFCNT_dec(stuff);
7415 PL_lex_formbrack = 0;
7426 PL_cshlen = strlen(PL_cshname);
7431 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
7433 I32 oldsavestack_ix = PL_savestack_ix;
7434 CV* outsidecv = PL_compcv;
7438 assert(SvTYPE(PL_compcv) == SVt_PVCV);
7440 SAVEI32(PL_subline);
7441 save_item(PL_subname);
7444 SAVESPTR(PL_comppad_name);
7445 SAVESPTR(PL_compcv);
7446 SAVEI32(PL_comppad_name_fill);
7447 SAVEI32(PL_min_intro_pending);
7448 SAVEI32(PL_max_intro_pending);
7449 SAVEI32(PL_pad_reset_pending);
7451 PL_compcv = (CV*)NEWSV(1104,0);
7452 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
7453 CvFLAGS(PL_compcv) |= flags;
7455 PL_comppad = newAV();
7456 av_push(PL_comppad, Nullsv);
7457 PL_curpad = AvARRAY(PL_comppad);
7458 PL_comppad_name = newAV();
7459 PL_comppad_name_fill = 0;
7460 PL_min_intro_pending = 0;
7462 PL_subline = CopLINE(PL_curcop);
7464 av_store(PL_comppad_name, 0, newSVpvn("@_", 2));
7465 PL_curpad[0] = (SV*)newAV();
7466 SvPADMY_on(PL_curpad[0]); /* XXX Needed? */
7467 #endif /* USE_THREADS */
7469 comppadlist = newAV();
7470 AvREAL_off(comppadlist);
7471 av_store(comppadlist, 0, (SV*)PL_comppad_name);
7472 av_store(comppadlist, 1, (SV*)PL_comppad);
7474 CvPADLIST(PL_compcv) = comppadlist;
7475 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
7477 CvOWNER(PL_compcv) = 0;
7478 New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
7479 MUTEX_INIT(CvMUTEXP(PL_compcv));
7480 #endif /* USE_THREADS */
7482 return oldsavestack_ix;
7486 #pragma segment Perl_yylex
7489 Perl_yywarn(pTHX_ char *s)
7491 PL_in_eval |= EVAL_WARNONLY;
7493 PL_in_eval &= ~EVAL_WARNONLY;
7498 Perl_yyerror(pTHX_ char *s)
7501 char *context = NULL;
7505 if (!yychar || (yychar == ';' && !PL_rsfp))
7507 else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 &&
7508 PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) {
7509 while (isSPACE(*PL_oldoldbufptr))
7511 context = PL_oldoldbufptr;
7512 contlen = PL_bufptr - PL_oldoldbufptr;
7514 else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 &&
7515 PL_oldbufptr != PL_bufptr) {
7516 while (isSPACE(*PL_oldbufptr))
7518 context = PL_oldbufptr;
7519 contlen = PL_bufptr - PL_oldbufptr;
7521 else if (yychar > 255)
7522 where = "next token ???";
7523 #ifdef USE_PURE_BISON
7524 /* GNU Bison sets the value -2 */
7525 else if (yychar == -2) {
7527 else if ((yychar & 127) == 127) {
7529 if (PL_lex_state == LEX_NORMAL ||
7530 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
7531 where = "at end of line";
7532 else if (PL_lex_inpat)
7533 where = "within pattern";
7535 where = "within string";
7538 SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
7540 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
7541 else if (isPRINT_LC(yychar))
7542 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
7544 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
7545 where = SvPVX(where_sv);
7547 msg = sv_2mortal(newSVpv(s, 0));
7548 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
7549 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
7551 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
7553 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
7554 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
7555 Perl_sv_catpvf(aTHX_ msg,
7556 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
7557 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
7560 if (PL_in_eval & EVAL_WARNONLY)
7561 Perl_warn(aTHX_ "%"SVf, msg);
7564 if (PL_error_count >= 10) {
7565 if (PL_in_eval && SvCUR(ERRSV))
7566 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
7567 ERRSV, CopFILE(PL_curcop));
7569 Perl_croak(aTHX_ "%s has too many errors.\n",
7570 CopFILE(PL_curcop));
7573 PL_in_my_stash = Nullhv;
7577 #pragma segment Main
7581 S_swallow_bom(pTHX_ U8 *s)
7584 slen = SvCUR(PL_linestr);
7588 /* UTF-16 little-endian */
7589 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
7590 Perl_croak(aTHX_ "Unsupported script encoding");
7591 #ifndef PERL_NO_UTF16_FILTER
7592 DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-LE script encoding\n"));
7594 if (PL_bufend > (char*)s) {
7598 filter_add(utf16rev_textfilter, NULL);
7599 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
7600 PL_bufend = (char*)utf16_to_utf8_reversed(s, news,
7601 PL_bufend - (char*)s - 1,
7603 Copy(news, s, newlen, U8);
7604 SvCUR_set(PL_linestr, newlen);
7605 PL_bufend = SvPVX(PL_linestr) + newlen;
7606 news[newlen++] = '\0';
7610 Perl_croak(aTHX_ "Unsupported script encoding");
7615 if (s[1] == 0xFF) { /* UTF-16 big-endian */
7616 #ifndef PERL_NO_UTF16_FILTER
7617 DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding\n"));
7619 if (PL_bufend > (char *)s) {
7623 filter_add(utf16_textfilter, NULL);
7624 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
7625 PL_bufend = (char*)utf16_to_utf8(s, news,
7626 PL_bufend - (char*)s,
7628 Copy(news, s, newlen, U8);
7629 SvCUR_set(PL_linestr, newlen);
7630 PL_bufend = SvPVX(PL_linestr) + newlen;
7631 news[newlen++] = '\0';
7635 Perl_croak(aTHX_ "Unsupported script encoding");
7640 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
7641 DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-8 script encoding\n"));
7646 if (slen > 3 && s[1] == 0 && /* UTF-32 big-endian */
7647 s[2] == 0xFE && s[3] == 0xFF)
7649 Perl_croak(aTHX_ "Unsupported script encoding");
7661 * Restore a source filter.
7665 restore_rsfp(pTHXo_ void *f)
7667 PerlIO *fp = (PerlIO*)f;
7669 if (PL_rsfp == PerlIO_stdin())
7670 PerlIO_clearerr(PL_rsfp);
7671 else if (PL_rsfp && (PL_rsfp != fp))
7672 PerlIO_close(PL_rsfp);
7676 #ifndef PERL_NO_UTF16_FILTER
7678 utf16_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
7680 I32 count = FILTER_READ(idx+1, sv, maxlen);
7685 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
7686 if (!*SvPV_nolen(sv))
7687 /* Game over, but don't feed an odd-length string to utf16_to_utf8 */
7690 tend = utf16_to_utf8((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen);
7691 sv_usepvn(sv, (char*)tmps, tend - tmps);
7697 utf16rev_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
7699 I32 count = FILTER_READ(idx+1, sv, maxlen);
7704 if (!*SvPV_nolen(sv))
7705 /* Game over, but don't feed an odd-length string to utf16_to_utf8 */
7708 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
7709 tend = utf16_to_utf8_reversed((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen);
7710 sv_usepvn(sv, (char*)tmps, tend - tmps);