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 name $^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 = 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++ = 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("()| \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 /* pit holds the identifier we read and pending_ident is reset */
2171 char pit = PL_pending_ident;
2172 PL_pending_ident = 0;
2174 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2175 "### Tokener saw identifier '%s'\n", PL_tokenbuf); });
2177 /* if we're in a my(), we can't allow dynamics here.
2178 $foo'bar has already been turned into $foo::bar, so
2179 just check for colons.
2181 if it's a legal name, the OP is a PADANY.
2184 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
2185 if (strchr(PL_tokenbuf,':'))
2186 yyerror(Perl_form(aTHX_ "No package name allowed for "
2187 "variable %s in \"our\"",
2189 tmp = pad_allocmy(PL_tokenbuf);
2192 if (strchr(PL_tokenbuf,':'))
2193 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
2195 yylval.opval = newOP(OP_PADANY, 0);
2196 yylval.opval->op_targ = pad_allocmy(PL_tokenbuf);
2202 build the ops for accesses to a my() variable.
2204 Deny my($a) or my($b) in a sort block, *if* $a or $b is
2205 then used in a comparison. This catches most, but not
2206 all cases. For instance, it catches
2207 sort { my($a); $a <=> $b }
2209 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
2210 (although why you'd do that is anyone's guess).
2213 if (!strchr(PL_tokenbuf,':')) {
2215 /* Check for single character per-thread SVs */
2216 if (PL_tokenbuf[0] == '$' && PL_tokenbuf[2] == '\0'
2217 && !isALPHA(PL_tokenbuf[1]) /* Rule out obvious non-threadsvs */
2218 && (tmp = find_threadsv(&PL_tokenbuf[1])) != NOT_IN_PAD)
2220 yylval.opval = newOP(OP_THREADSV, 0);
2221 yylval.opval->op_targ = tmp;
2224 #endif /* USE_THREADS */
2225 if ((tmp = pad_findmy(PL_tokenbuf)) != NOT_IN_PAD) {
2226 SV *namesv = AvARRAY(PL_comppad_name)[tmp];
2227 /* might be an "our" variable" */
2228 if (SvFLAGS(namesv) & SVpad_OUR) {
2229 /* build ops for a bareword */
2230 SV *sym = newSVpv(HvNAME(GvSTASH(namesv)),0);
2231 sv_catpvn(sym, "::", 2);
2232 sv_catpv(sym, PL_tokenbuf+1);
2233 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
2234 yylval.opval->op_private = OPpCONST_ENTERED;
2235 gv_fetchpv(SvPVX(sym),
2237 ? (GV_ADDMULTI | GV_ADDINEVAL)
2240 ((PL_tokenbuf[0] == '$') ? SVt_PV
2241 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
2246 /* if it's a sort block and they're naming $a or $b */
2247 if (PL_last_lop_op == OP_SORT &&
2248 PL_tokenbuf[0] == '$' &&
2249 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
2252 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
2253 d < PL_bufend && *d != '\n';
2256 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
2257 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
2263 yylval.opval = newOP(OP_PADANY, 0);
2264 yylval.opval->op_targ = tmp;
2270 Whine if they've said @foo in a doublequoted string,
2271 and @foo isn't a variable we can find in the symbol
2274 if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
2275 GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
2276 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
2277 && ckWARN(WARN_AMBIGUOUS))
2279 /* Downgraded from fatal to warning 20000522 mjd */
2280 Perl_warner(aTHX_ WARN_AMBIGUOUS,
2281 "Possible unintended interpolation of %s in string",
2286 /* build ops for a bareword */
2287 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
2288 yylval.opval->op_private = OPpCONST_ENTERED;
2289 gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
2290 ((PL_tokenbuf[0] == '$') ? SVt_PV
2291 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
2296 /* no identifier pending identification */
2298 switch (PL_lex_state) {
2300 case LEX_NORMAL: /* Some compilers will produce faster */
2301 case LEX_INTERPNORMAL: /* code if we comment these out. */
2305 /* when we've already built the next token, just pull it out of the queue */
2308 yylval = PL_nextval[PL_nexttoke];
2310 PL_lex_state = PL_lex_defer;
2311 PL_expect = PL_lex_expect;
2312 PL_lex_defer = LEX_NORMAL;
2314 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2315 "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr,
2316 (IV)PL_nexttype[PL_nexttoke]); });
2318 return(PL_nexttype[PL_nexttoke]);
2320 /* interpolated case modifiers like \L \U, including \Q and \E.
2321 when we get here, PL_bufptr is at the \
2323 case LEX_INTERPCASEMOD:
2325 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2326 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2328 /* handle \E or end of string */
2329 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2333 if (PL_lex_casemods) {
2334 oldmod = PL_lex_casestack[--PL_lex_casemods];
2335 PL_lex_casestack[PL_lex_casemods] = '\0';
2337 if (PL_bufptr != PL_bufend && strchr("LUQ", oldmod)) {
2339 PL_lex_state = LEX_INTERPCONCAT;
2343 if (PL_bufptr != PL_bufend)
2345 PL_lex_state = LEX_INTERPCONCAT;
2349 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2350 "### Saw case modifier at '%s'\n", PL_bufptr); });
2352 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2353 tmp = *s, *s = s[2], s[2] = tmp; /* misordered... */
2354 if (strchr("LU", *s) &&
2355 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U')))
2357 PL_lex_casestack[--PL_lex_casemods] = '\0';
2360 if (PL_lex_casemods > 10) {
2361 char* newlb = Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2362 if (newlb != PL_lex_casestack) {
2364 PL_lex_casestack = newlb;
2367 PL_lex_casestack[PL_lex_casemods++] = *s;
2368 PL_lex_casestack[PL_lex_casemods] = '\0';
2369 PL_lex_state = LEX_INTERPCONCAT;
2370 PL_nextval[PL_nexttoke].ival = 0;
2373 PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2375 PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2377 PL_nextval[PL_nexttoke].ival = OP_LC;
2379 PL_nextval[PL_nexttoke].ival = OP_UC;
2381 PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2383 Perl_croak(aTHX_ "panic: yylex");
2386 if (PL_lex_starts) {
2395 case LEX_INTERPPUSH:
2396 return sublex_push();
2398 case LEX_INTERPSTART:
2399 if (PL_bufptr == PL_bufend)
2400 return sublex_done();
2401 DEBUG_T({ PerlIO_printf(Perl_debug_log,
2402 "### Interpolated variable at '%s'\n", PL_bufptr); });
2404 PL_lex_dojoin = (*PL_bufptr == '@');
2405 PL_lex_state = LEX_INTERPNORMAL;
2406 if (PL_lex_dojoin) {
2407 PL_nextval[PL_nexttoke].ival = 0;
2410 PL_nextval[PL_nexttoke].opval = newOP(OP_THREADSV, 0);
2411 PL_nextval[PL_nexttoke].opval->op_targ = find_threadsv("\"");
2412 force_next(PRIVATEREF);
2414 force_ident("\"", '$');
2415 #endif /* USE_THREADS */
2416 PL_nextval[PL_nexttoke].ival = 0;
2418 PL_nextval[PL_nexttoke].ival = 0;
2420 PL_nextval[PL_nexttoke].ival = OP_JOIN; /* emulate join($", ...) */
2423 if (PL_lex_starts++) {
2429 case LEX_INTERPENDMAYBE:
2430 if (intuit_more(PL_bufptr)) {
2431 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
2437 if (PL_lex_dojoin) {
2438 PL_lex_dojoin = FALSE;
2439 PL_lex_state = LEX_INTERPCONCAT;
2442 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2443 && SvEVALED(PL_lex_repl))
2445 if (PL_bufptr != PL_bufend)
2446 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2447 PL_lex_repl = Nullsv;
2450 case LEX_INTERPCONCAT:
2452 if (PL_lex_brackets)
2453 Perl_croak(aTHX_ "panic: INTERPCONCAT");
2455 if (PL_bufptr == PL_bufend)
2456 return sublex_done();
2458 if (SvIVX(PL_linestr) == '\'') {
2459 SV *sv = newSVsv(PL_linestr);
2462 else if ( PL_hints & HINT_NEW_RE )
2463 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2464 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2468 s = scan_const(PL_bufptr);
2470 PL_lex_state = LEX_INTERPCASEMOD;
2472 PL_lex_state = LEX_INTERPSTART;
2475 if (s != PL_bufptr) {
2476 PL_nextval[PL_nexttoke] = yylval;
2479 if (PL_lex_starts++)
2489 PL_lex_state = LEX_NORMAL;
2490 s = scan_formline(PL_bufptr);
2491 if (!PL_lex_formbrack)
2497 PL_oldoldbufptr = PL_oldbufptr;
2500 PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at %s\n",
2501 exp_name[PL_expect], s);
2507 if (isIDFIRST_lazy_if(s,UTF))
2509 Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2512 goto fake_eof; /* emulate EOF on ^D or ^Z */
2517 if (PL_lex_brackets)
2518 yyerror("Missing right curly or square bracket");
2519 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2520 "### Tokener got EOF\n");
2524 if (s++ < PL_bufend)
2525 goto retry; /* ignore stray nulls */
2528 if (!PL_in_eval && !PL_preambled) {
2529 PL_preambled = TRUE;
2530 sv_setpv(PL_linestr,incl_perldb());
2531 if (SvCUR(PL_linestr))
2532 sv_catpv(PL_linestr,";");
2534 while(AvFILLp(PL_preambleav) >= 0) {
2535 SV *tmpsv = av_shift(PL_preambleav);
2536 sv_catsv(PL_linestr, tmpsv);
2537 sv_catpv(PL_linestr, ";");
2540 sv_free((SV*)PL_preambleav);
2541 PL_preambleav = NULL;
2543 if (PL_minus_n || PL_minus_p) {
2544 sv_catpv(PL_linestr, "LINE: while (<>) {");
2546 sv_catpv(PL_linestr,"chomp;");
2548 GV* gv = gv_fetchpv("::F", TRUE, SVt_PVAV);
2550 GvIMPORTED_AV_on(gv);
2552 if (strchr("/'\"", *PL_splitstr)
2553 && strchr(PL_splitstr + 1, *PL_splitstr))
2554 Perl_sv_catpvf(aTHX_ PL_linestr, "@F=split(%s);", PL_splitstr);
2557 s = "'~#\200\1'"; /* surely one char is unused...*/
2558 while (s[1] && strchr(PL_splitstr, *s)) s++;
2560 Perl_sv_catpvf(aTHX_ PL_linestr, "@F=split(%s%c",
2561 "q" + (delim == '\''), delim);
2562 for (s = PL_splitstr; *s; s++) {
2564 sv_catpvn(PL_linestr, "\\", 1);
2565 sv_catpvn(PL_linestr, s, 1);
2567 Perl_sv_catpvf(aTHX_ PL_linestr, "%c);", delim);
2571 sv_catpv(PL_linestr,"@F=split(' ');");
2574 sv_catpv(PL_linestr, "\n");
2575 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2576 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2577 PL_last_lop = PL_last_uni = Nullch;
2578 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2579 SV *sv = NEWSV(85,0);
2581 sv_upgrade(sv, SVt_PVMG);
2582 sv_setsv(sv,PL_linestr);
2583 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2588 bof = PL_rsfp ? TRUE : FALSE;
2589 if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2592 if (PL_preprocess && !PL_in_eval)
2593 (void)PerlProc_pclose(PL_rsfp);
2594 else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2595 PerlIO_clearerr(PL_rsfp);
2597 (void)PerlIO_close(PL_rsfp);
2599 PL_doextract = FALSE;
2601 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2602 sv_setpv(PL_linestr,PL_minus_p ? ";}continue{print" : "");
2603 sv_catpv(PL_linestr,";}");
2604 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2605 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2606 PL_last_lop = PL_last_uni = Nullch;
2607 PL_minus_n = PL_minus_p = 0;
2610 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2611 PL_last_lop = PL_last_uni = Nullch;
2612 sv_setpv(PL_linestr,"");
2613 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
2615 /* if it looks like the start of a BOM, check if it in fact is */
2616 else if (bof && (!*s || *(U8*)s == 0xEF || *(U8*)s >= 0xFE)) {
2617 #ifdef PERLIO_IS_STDIO
2618 # ifdef __GNU_LIBRARY__
2619 # if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
2620 # define FTELL_FOR_PIPE_IS_BROKEN
2624 # if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
2625 # define FTELL_FOR_PIPE_IS_BROKEN
2630 #ifdef FTELL_FOR_PIPE_IS_BROKEN
2631 /* This loses the possibility to detect the bof
2632 * situation on perl -P when the libc5 is being used.
2633 * Workaround? Maybe attach some extra state to PL_rsfp?
2636 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2638 bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2641 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2642 s = swallow_bom((U8*)s);
2646 if (*s == '#' && s[1] == '!' && instr(s,"perl"))
2647 PL_doextract = FALSE;
2649 /* Incest with pod. */
2650 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2651 sv_setpv(PL_linestr, "");
2652 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2653 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2654 PL_last_lop = PL_last_uni = Nullch;
2655 PL_doextract = FALSE;
2659 } while (PL_doextract);
2660 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2661 if (PERLDB_LINE && PL_curstash != PL_debstash) {
2662 SV *sv = NEWSV(85,0);
2664 sv_upgrade(sv, SVt_PVMG);
2665 sv_setsv(sv,PL_linestr);
2666 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2668 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2669 PL_last_lop = PL_last_uni = Nullch;
2670 if (CopLINE(PL_curcop) == 1) {
2671 while (s < PL_bufend && isSPACE(*s))
2673 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2677 if (*s == '#' && *(s+1) == '!')
2679 #ifdef ALTERNATE_SHEBANG
2681 static char as[] = ALTERNATE_SHEBANG;
2682 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2683 d = s + (sizeof(as) - 1);
2685 #endif /* ALTERNATE_SHEBANG */
2694 while (*d && !isSPACE(*d))
2698 #ifdef ARG_ZERO_IS_SCRIPT
2699 if (ipathend > ipath) {
2701 * HP-UX (at least) sets argv[0] to the script name,
2702 * which makes $^X incorrect. And Digital UNIX and Linux,
2703 * at least, set argv[0] to the basename of the Perl
2704 * interpreter. So, having found "#!", we'll set it right.
2706 SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV));
2707 assert(SvPOK(x) || SvGMAGICAL(x));
2708 if (sv_eq(x, CopFILESV(PL_curcop))) {
2709 sv_setpvn(x, ipath, ipathend - ipath);
2712 TAINT_NOT; /* $^X is always tainted, but that's OK */
2714 #endif /* ARG_ZERO_IS_SCRIPT */
2719 d = instr(s,"perl -");
2721 d = instr(s,"perl");
2723 /* avoid getting into infinite loops when shebang
2724 * line contains "Perl" rather than "perl" */
2726 for (d = ipathend-4; d >= ipath; --d) {
2727 if ((*d == 'p' || *d == 'P')
2728 && !ibcmp(d, "perl", 4))
2738 #ifdef ALTERNATE_SHEBANG
2740 * If the ALTERNATE_SHEBANG on this system starts with a
2741 * character that can be part of a Perl expression, then if
2742 * we see it but not "perl", we're probably looking at the
2743 * start of Perl code, not a request to hand off to some
2744 * other interpreter. Similarly, if "perl" is there, but
2745 * not in the first 'word' of the line, we assume the line
2746 * contains the start of the Perl program.
2748 if (d && *s != '#') {
2750 while (*c && !strchr("; \t\r\n\f\v#", *c))
2753 d = Nullch; /* "perl" not in first word; ignore */
2755 *s = '#'; /* Don't try to parse shebang line */
2757 #endif /* ALTERNATE_SHEBANG */
2758 #ifndef MACOS_TRADITIONAL
2763 !instr(s,"indir") &&
2764 instr(PL_origargv[0],"perl"))
2770 while (s < PL_bufend && isSPACE(*s))
2772 if (s < PL_bufend) {
2773 Newz(899,newargv,PL_origargc+3,char*);
2775 while (s < PL_bufend && !isSPACE(*s))
2778 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2781 newargv = PL_origargv;
2783 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
2784 Perl_croak(aTHX_ "Can't exec %s", ipath);
2788 U32 oldpdb = PL_perldb;
2789 bool oldn = PL_minus_n;
2790 bool oldp = PL_minus_p;
2792 while (*d && !isSPACE(*d)) d++;
2793 while (SPACE_OR_TAB(*d)) d++;
2797 if (*d == 'M' || *d == 'm') {
2799 while (*d && !isSPACE(*d)) d++;
2800 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2803 d = moreswitches(d);
2805 if ((PERLDB_LINE && !oldpdb) ||
2806 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
2807 /* if we have already added "LINE: while (<>) {",
2808 we must not do it again */
2810 sv_setpv(PL_linestr, "");
2811 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2812 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2813 PL_last_lop = PL_last_uni = Nullch;
2814 PL_preambled = FALSE;
2816 (void)gv_fetchfile(PL_origfilename);
2823 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2825 PL_lex_state = LEX_FORMLINE;
2830 #ifdef PERL_STRICT_CR
2831 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
2833 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
2835 case ' ': case '\t': case '\f': case 013:
2836 #ifdef MACOS_TRADITIONAL
2843 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
2844 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
2845 /* handle eval qq[#line 1 "foo"\n ...] */
2846 CopLINE_dec(PL_curcop);
2850 while (s < d && *s != '\n')
2854 else if (s > d) /* Found by Ilya: feed random input to Perl. */
2855 Perl_croak(aTHX_ "panic: input overflow");
2857 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2859 PL_lex_state = LEX_FORMLINE;
2869 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2876 while (s < PL_bufend && SPACE_OR_TAB(*s))
2879 if (strnEQ(s,"=>",2)) {
2880 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
2881 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2882 "### Saw unary minus before =>, forcing word '%s'\n", s);
2884 OPERATOR('-'); /* unary minus */
2886 PL_last_uni = PL_oldbufptr;
2888 case 'r': ftst = OP_FTEREAD; break;
2889 case 'w': ftst = OP_FTEWRITE; break;
2890 case 'x': ftst = OP_FTEEXEC; break;
2891 case 'o': ftst = OP_FTEOWNED; break;
2892 case 'R': ftst = OP_FTRREAD; break;
2893 case 'W': ftst = OP_FTRWRITE; break;
2894 case 'X': ftst = OP_FTREXEC; break;
2895 case 'O': ftst = OP_FTROWNED; break;
2896 case 'e': ftst = OP_FTIS; break;
2897 case 'z': ftst = OP_FTZERO; break;
2898 case 's': ftst = OP_FTSIZE; break;
2899 case 'f': ftst = OP_FTFILE; break;
2900 case 'd': ftst = OP_FTDIR; break;
2901 case 'l': ftst = OP_FTLINK; break;
2902 case 'p': ftst = OP_FTPIPE; break;
2903 case 'S': ftst = OP_FTSOCK; break;
2904 case 'u': ftst = OP_FTSUID; break;
2905 case 'g': ftst = OP_FTSGID; break;
2906 case 'k': ftst = OP_FTSVTX; break;
2907 case 'b': ftst = OP_FTBLK; break;
2908 case 'c': ftst = OP_FTCHR; break;
2909 case 't': ftst = OP_FTTTY; break;
2910 case 'T': ftst = OP_FTTEXT; break;
2911 case 'B': ftst = OP_FTBINARY; break;
2912 case 'M': case 'A': case 'C':
2913 gv_fetchpv("\024",TRUE, SVt_PV);
2915 case 'M': ftst = OP_FTMTIME; break;
2916 case 'A': ftst = OP_FTATIME; break;
2917 case 'C': ftst = OP_FTCTIME; break;
2925 PL_last_lop_op = ftst;
2926 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2927 "### Saw file test %c\n", (int)ftst);
2932 /* Assume it was a minus followed by a one-letter named
2933 * subroutine call (or a -bareword), then. */
2934 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2935 "### %c looked like a file test but was not\n",
2944 if (PL_expect == XOPERATOR)
2949 else if (*s == '>') {
2952 if (isIDFIRST_lazy_if(s,UTF)) {
2953 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
2961 if (PL_expect == XOPERATOR)
2964 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2966 OPERATOR('-'); /* unary minus */
2973 if (PL_expect == XOPERATOR)
2978 if (PL_expect == XOPERATOR)
2981 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
2987 if (PL_expect != XOPERATOR) {
2988 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
2989 PL_expect = XOPERATOR;
2990 force_ident(PL_tokenbuf, '*');
3003 if (PL_expect == XOPERATOR) {
3007 PL_tokenbuf[0] = '%';
3008 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3009 if (!PL_tokenbuf[1]) {
3011 yyerror("Final % should be \\% or %name");
3014 PL_pending_ident = '%';
3033 switch (PL_expect) {
3036 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3038 PL_bufptr = s; /* update in case we back off */
3044 PL_expect = XTERMBLOCK;
3048 while (isIDFIRST_lazy_if(s,UTF)) {
3049 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3050 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
3051 if (tmp < 0) tmp = -tmp;
3066 d = scan_str(d,TRUE,TRUE);
3068 /* MUST advance bufptr here to avoid bogus
3069 "at end of line" context messages from yyerror().
3071 PL_bufptr = s + len;
3072 yyerror("Unterminated attribute parameter in attribute list");
3075 return 0; /* EOF indicator */
3079 SV *sv = newSVpvn(s, len);
3080 sv_catsv(sv, PL_lex_stuff);
3081 attrs = append_elem(OP_LIST, attrs,
3082 newSVOP(OP_CONST, 0, sv));
3083 SvREFCNT_dec(PL_lex_stuff);
3084 PL_lex_stuff = Nullsv;
3087 if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
3088 CvLVALUE_on(PL_compcv);
3089 else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
3090 CvLOCKED_on(PL_compcv);
3091 else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
3092 CvMETHOD_on(PL_compcv);
3094 else if (PL_in_my == KEY_our && len == 6 && strnEQ(s, "shared", len))
3095 GvSHARED_on(cGVOPx_gv(yylval.opval));
3097 /* After we've set the flags, it could be argued that
3098 we don't need to do the attributes.pm-based setting
3099 process, and shouldn't bother appending recognized
3100 flags. To experiment with that, uncomment the
3101 following "else": */
3103 attrs = append_elem(OP_LIST, attrs,
3104 newSVOP(OP_CONST, 0,
3108 if (*s == ':' && s[1] != ':')
3111 break; /* require real whitespace or :'s */
3113 tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
3114 if (*s != ';' && *s != tmp && (tmp != '=' || *s != ')')) {
3115 char q = ((*s == '\'') ? '"' : '\'');
3116 /* If here for an expression, and parsed no attrs, back off. */
3117 if (tmp == '=' && !attrs) {
3121 /* MUST advance bufptr here to avoid bogus "at end of line"
3122 context messages from yyerror().
3126 yyerror("Unterminated attribute list");
3128 yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
3136 PL_nextval[PL_nexttoke].opval = attrs;
3144 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
3145 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
3161 if (PL_lex_brackets <= 0)
3162 yyerror("Unmatched right square bracket");
3165 if (PL_lex_state == LEX_INTERPNORMAL) {
3166 if (PL_lex_brackets == 0) {
3167 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3168 PL_lex_state = LEX_INTERPEND;
3175 if (PL_lex_brackets > 100) {
3176 char* newlb = Renew(PL_lex_brackstack, PL_lex_brackets + 1, char);
3177 if (newlb != PL_lex_brackstack) {
3179 PL_lex_brackstack = newlb;
3182 switch (PL_expect) {
3184 if (PL_lex_formbrack) {
3188 if (PL_oldoldbufptr == PL_last_lop)
3189 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3191 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3192 OPERATOR(HASHBRACK);
3194 while (s < PL_bufend && SPACE_OR_TAB(*s))
3197 PL_tokenbuf[0] = '\0';
3198 if (d < PL_bufend && *d == '-') {
3199 PL_tokenbuf[0] = '-';
3201 while (d < PL_bufend && SPACE_OR_TAB(*d))
3204 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3205 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
3207 while (d < PL_bufend && SPACE_OR_TAB(*d))
3210 char minus = (PL_tokenbuf[0] == '-');
3211 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
3219 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
3224 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3229 if (PL_oldoldbufptr == PL_last_lop)
3230 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3232 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3235 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
3237 /* This hack is to get the ${} in the message. */
3239 yyerror("syntax error");
3242 OPERATOR(HASHBRACK);
3244 /* This hack serves to disambiguate a pair of curlies
3245 * as being a block or an anon hash. Normally, expectation
3246 * determines that, but in cases where we're not in a
3247 * position to expect anything in particular (like inside
3248 * eval"") we have to resolve the ambiguity. This code
3249 * covers the case where the first term in the curlies is a
3250 * quoted string. Most other cases need to be explicitly
3251 * disambiguated by prepending a `+' before the opening
3252 * curly in order to force resolution as an anon hash.
3254 * XXX should probably propagate the outer expectation
3255 * into eval"" to rely less on this hack, but that could
3256 * potentially break current behavior of eval"".
3260 if (*s == '\'' || *s == '"' || *s == '`') {
3261 /* common case: get past first string, handling escapes */
3262 for (t++; t < PL_bufend && *t != *s;)
3263 if (*t++ == '\\' && (*t == '\\' || *t == *s))
3267 else if (*s == 'q') {
3270 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
3274 char open, close, term;
3277 while (t < PL_bufend && isSPACE(*t))
3281 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
3285 for (t++; t < PL_bufend; t++) {
3286 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
3288 else if (*t == open)
3292 for (t++; t < PL_bufend; t++) {
3293 if (*t == '\\' && t+1 < PL_bufend)
3295 else if (*t == close && --brackets <= 0)
3297 else if (*t == open)
3303 else if (isALNUM_lazy_if(t,UTF)) {
3305 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3308 while (t < PL_bufend && isSPACE(*t))
3310 /* if comma follows first term, call it an anon hash */
3311 /* XXX it could be a comma expression with loop modifiers */
3312 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
3313 || (*t == '=' && t[1] == '>')))
3314 OPERATOR(HASHBRACK);
3315 if (PL_expect == XREF)
3318 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3324 yylval.ival = CopLINE(PL_curcop);
3325 if (isSPACE(*s) || *s == '#')
3326 PL_copline = NOLINE; /* invalidate current command line number */
3331 if (PL_lex_brackets <= 0)
3332 yyerror("Unmatched right curly bracket");
3334 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3335 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3336 PL_lex_formbrack = 0;
3337 if (PL_lex_state == LEX_INTERPNORMAL) {
3338 if (PL_lex_brackets == 0) {
3339 if (PL_expect & XFAKEBRACK) {
3340 PL_expect &= XENUMMASK;
3341 PL_lex_state = LEX_INTERPEND;
3343 return yylex(); /* ignore fake brackets */
3345 if (*s == '-' && s[1] == '>')
3346 PL_lex_state = LEX_INTERPENDMAYBE;
3347 else if (*s != '[' && *s != '{')
3348 PL_lex_state = LEX_INTERPEND;
3351 if (PL_expect & XFAKEBRACK) {
3352 PL_expect &= XENUMMASK;
3354 return yylex(); /* ignore fake brackets */
3364 if (PL_expect == XOPERATOR) {
3365 if (ckWARN(WARN_SEMICOLON)
3366 && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart)
3368 CopLINE_dec(PL_curcop);
3369 Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi);
3370 CopLINE_inc(PL_curcop);
3375 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3377 PL_expect = XOPERATOR;
3378 force_ident(PL_tokenbuf, '&');
3382 yylval.ival = (OPpENTERSUB_AMPER<<8);
3401 if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
3402 Perl_warner(aTHX_ WARN_SYNTAX, "Reversed %c= operator",(int)tmp);
3404 if (PL_expect == XSTATE && isALPHA(tmp) &&
3405 (s == PL_linestart+1 || s[-2] == '\n') )
3407 if (PL_in_eval && !PL_rsfp) {
3412 if (strnEQ(s,"=cut",4)) {
3426 PL_doextract = TRUE;
3429 if (PL_lex_brackets < PL_lex_formbrack) {
3431 #ifdef PERL_STRICT_CR
3432 for (t = s; SPACE_OR_TAB(*t); t++) ;
3434 for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3436 if (*t == '\n' || *t == '#') {
3454 if (PL_expect != XOPERATOR) {
3455 if (s[1] != '<' && !strchr(s,'>'))
3458 s = scan_heredoc(s);
3460 s = scan_inputsymbol(s);
3461 TERM(sublex_start());
3466 SHop(OP_LEFT_SHIFT);
3480 SHop(OP_RIGHT_SHIFT);
3489 if (PL_expect == XOPERATOR) {
3490 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3493 return ','; /* grandfather non-comma-format format */
3497 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3498 PL_tokenbuf[0] = '@';
3499 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3500 sizeof PL_tokenbuf - 1, FALSE);
3501 if (PL_expect == XOPERATOR)
3502 no_op("Array length", s);
3503 if (!PL_tokenbuf[1])
3505 PL_expect = XOPERATOR;
3506 PL_pending_ident = '#';
3510 PL_tokenbuf[0] = '$';
3511 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3512 sizeof PL_tokenbuf - 1, FALSE);
3513 if (PL_expect == XOPERATOR)
3515 if (!PL_tokenbuf[1]) {
3517 yyerror("Final $ should be \\$ or $name");
3521 /* This kludge not intended to be bulletproof. */
3522 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3523 yylval.opval = newSVOP(OP_CONST, 0,
3524 newSViv(PL_compiling.cop_arybase));
3525 yylval.opval->op_private = OPpCONST_ARYBASE;
3531 if (PL_lex_state == LEX_NORMAL)
3534 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3537 PL_tokenbuf[0] = '@';
3538 if (ckWARN(WARN_SYNTAX)) {
3540 isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3543 PL_bufptr = skipspace(PL_bufptr);
3544 while (t < PL_bufend && *t != ']')
3546 Perl_warner(aTHX_ WARN_SYNTAX,
3547 "Multidimensional syntax %.*s not supported",
3548 (t - PL_bufptr) + 1, PL_bufptr);
3552 else if (*s == '{') {
3553 PL_tokenbuf[0] = '%';
3554 if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") &&
3555 (t = strchr(s, '}')) && (t = strchr(t, '=')))
3557 char tmpbuf[sizeof PL_tokenbuf];
3559 for (t++; isSPACE(*t); t++) ;
3560 if (isIDFIRST_lazy_if(t,UTF)) {
3561 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3562 for (; isSPACE(*t); t++) ;
3563 if (*t == ';' && get_cv(tmpbuf, FALSE))
3564 Perl_warner(aTHX_ WARN_SYNTAX,
3565 "You need to quote \"%s\"", tmpbuf);
3571 PL_expect = XOPERATOR;
3572 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3573 bool islop = (PL_last_lop == PL_oldoldbufptr);
3574 if (!islop || PL_last_lop_op == OP_GREPSTART)
3575 PL_expect = XOPERATOR;
3576 else if (strchr("$@\"'`q", *s))
3577 PL_expect = XTERM; /* e.g. print $fh "foo" */
3578 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3579 PL_expect = XTERM; /* e.g. print $fh &sub */
3580 else if (isIDFIRST_lazy_if(s,UTF)) {
3581 char tmpbuf[sizeof PL_tokenbuf];
3582 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3583 if ((tmp = keyword(tmpbuf, len))) {
3584 /* binary operators exclude handle interpretations */
3596 PL_expect = XTERM; /* e.g. print $fh length() */
3601 GV *gv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
3602 if (gv && GvCVu(gv))
3603 PL_expect = XTERM; /* e.g. print $fh subr() */
3606 else if (isDIGIT(*s))
3607 PL_expect = XTERM; /* e.g. print $fh 3 */
3608 else if (*s == '.' && isDIGIT(s[1]))
3609 PL_expect = XTERM; /* e.g. print $fh .3 */
3610 else if (strchr("/?-+", *s) && !isSPACE(s[1]) && s[1] != '=')
3611 PL_expect = XTERM; /* e.g. print $fh -1 */
3612 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3613 PL_expect = XTERM; /* print $fh <<"EOF" */
3615 PL_pending_ident = '$';
3619 if (PL_expect == XOPERATOR)
3621 PL_tokenbuf[0] = '@';
3622 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3623 if (!PL_tokenbuf[1]) {
3625 yyerror("Final @ should be \\@ or @name");
3628 if (PL_lex_state == LEX_NORMAL)
3630 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3632 PL_tokenbuf[0] = '%';
3634 /* Warn about @ where they meant $. */
3635 if (ckWARN(WARN_SYNTAX)) {
3636 if (*s == '[' || *s == '{') {
3638 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3640 if (*t == '}' || *t == ']') {
3642 PL_bufptr = skipspace(PL_bufptr);
3643 Perl_warner(aTHX_ WARN_SYNTAX,
3644 "Scalar value %.*s better written as $%.*s",
3645 t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3650 PL_pending_ident = '@';
3653 case '/': /* may either be division or pattern */
3654 case '?': /* may either be conditional or pattern */
3655 if (PL_expect != XOPERATOR) {
3656 /* Disable warning on "study /blah/" */
3657 if (PL_oldoldbufptr == PL_last_uni
3658 && (*PL_last_uni != 's' || s - PL_last_uni < 5
3659 || memNE(PL_last_uni, "study", 5)
3660 || isALNUM_lazy_if(PL_last_uni+5,UTF)))
3662 s = scan_pat(s,OP_MATCH);
3663 TERM(sublex_start());
3671 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3672 #ifdef PERL_STRICT_CR
3675 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3677 && (s == PL_linestart || s[-1] == '\n') )
3679 PL_lex_formbrack = 0;
3683 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3689 yylval.ival = OPf_SPECIAL;
3695 if (PL_expect != XOPERATOR)
3700 case '0': case '1': case '2': case '3': case '4':
3701 case '5': case '6': case '7': case '8': case '9':
3702 s = scan_num(s, &yylval);
3703 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3704 "### Saw number in '%s'\n", s);
3706 if (PL_expect == XOPERATOR)
3711 s = scan_str(s,FALSE,FALSE);
3712 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3713 "### Saw string before '%s'\n", s);
3715 if (PL_expect == XOPERATOR) {
3716 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3719 return ','; /* grandfather non-comma-format format */
3725 missingterm((char*)0);
3726 yylval.ival = OP_CONST;
3727 TERM(sublex_start());
3730 s = scan_str(s,FALSE,FALSE);
3731 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3732 "### Saw string before '%s'\n", s);
3734 if (PL_expect == XOPERATOR) {
3735 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3738 return ','; /* grandfather non-comma-format format */
3744 missingterm((char*)0);
3745 yylval.ival = OP_CONST;
3746 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3747 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
3748 yylval.ival = OP_STRINGIFY;
3752 TERM(sublex_start());
3755 s = scan_str(s,FALSE,FALSE);
3756 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3757 "### Saw backtick string before '%s'\n", s);
3759 if (PL_expect == XOPERATOR)
3760 no_op("Backticks",s);
3762 missingterm((char*)0);
3763 yylval.ival = OP_BACKTICK;
3765 TERM(sublex_start());
3769 if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s))
3770 Perl_warner(aTHX_ WARN_SYNTAX,"Can't use \\%c to mean $%c in expression",
3772 if (PL_expect == XOPERATOR)
3773 no_op("Backslash",s);
3777 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
3781 while (isDIGIT(*start) || *start == '_')
3783 if (*start == '.' && isDIGIT(start[1])) {
3784 s = scan_num(s, &yylval);
3787 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
3788 else if (!isALPHA(*start) && (PL_expect == XTERM || PL_expect == XREF || PL_expect == XSTATE)) {
3792 gv = gv_fetchpv(s, FALSE, SVt_PVCV);
3795 s = scan_num(s, &yylval);
3802 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
3841 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3843 /* Some keywords can be followed by any delimiter, including ':' */
3844 tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
3845 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
3846 (PL_tokenbuf[0] == 'q' &&
3847 strchr("qwxr", PL_tokenbuf[1])))));
3849 /* x::* is just a word, unless x is "CORE" */
3850 if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
3854 while (d < PL_bufend && isSPACE(*d))
3855 d++; /* no comments skipped here, or s### is misparsed */
3857 /* Is this a label? */
3858 if (!tmp && PL_expect == XSTATE
3859 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
3861 yylval.pval = savepv(PL_tokenbuf);
3866 /* Check for keywords */
3867 tmp = keyword(PL_tokenbuf, len);
3869 /* Is this a word before a => operator? */
3870 if (*d == '=' && d[1] == '>') {
3872 yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf,0));
3873 yylval.opval->op_private = OPpCONST_BARE;
3874 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
3875 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
3879 if (tmp < 0) { /* second-class keyword? */
3880 GV *ogv = Nullgv; /* override (winner) */
3881 GV *hgv = Nullgv; /* hidden (loser) */
3882 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
3884 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
3887 if (GvIMPORTED_CV(gv))
3889 else if (! CvMETHOD(cv))
3893 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
3894 (gv = *gvp) != (GV*)&PL_sv_undef &&
3895 GvCVu(gv) && GvIMPORTED_CV(gv))
3901 tmp = 0; /* overridden by import or by GLOBAL */
3904 && -tmp==KEY_lock /* XXX generalizable kludge */
3906 && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
3908 tmp = 0; /* any sub overrides "weak" keyword */
3910 else { /* no override */
3914 if (ckWARN(WARN_AMBIGUOUS) && hgv
3915 && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
3916 Perl_warner(aTHX_ WARN_AMBIGUOUS,
3917 "Ambiguous call resolved as CORE::%s(), %s",
3918 GvENAME(hgv), "qualify as such or use &");
3925 default: /* not a keyword */
3928 char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
3930 /* Get the rest if it looks like a package qualifier */
3932 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
3934 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
3937 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
3938 *s == '\'' ? "'" : "::");
3942 if (PL_expect == XOPERATOR) {
3943 if (PL_bufptr == PL_linestart) {
3944 CopLINE_dec(PL_curcop);
3945 Perl_warner(aTHX_ WARN_SEMICOLON, PL_warn_nosemi);
3946 CopLINE_inc(PL_curcop);
3949 no_op("Bareword",s);
3952 /* Look for a subroutine with this name in current package,
3953 unless name is "Foo::", in which case Foo is a bearword
3954 (and a package name). */
3957 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
3959 if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
3960 Perl_warner(aTHX_ WARN_BAREWORD,
3961 "Bareword \"%s\" refers to nonexistent package",
3964 PL_tokenbuf[len] = '\0';
3971 gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
3974 /* if we saw a global override before, get the right name */
3977 sv = newSVpvn("CORE::GLOBAL::",14);
3978 sv_catpv(sv,PL_tokenbuf);
3981 sv = newSVpv(PL_tokenbuf,0);
3983 /* Presume this is going to be a bareword of some sort. */
3986 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3987 yylval.opval->op_private = OPpCONST_BARE;
3989 /* And if "Foo::", then that's what it certainly is. */
3994 /* See if it's the indirect object for a list operator. */
3996 if (PL_oldoldbufptr &&
3997 PL_oldoldbufptr < PL_bufptr &&
3998 (PL_oldoldbufptr == PL_last_lop
3999 || PL_oldoldbufptr == PL_last_uni) &&
4000 /* NO SKIPSPACE BEFORE HERE! */
4001 (PL_expect == XREF ||
4002 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
4004 bool immediate_paren = *s == '(';
4006 /* (Now we can afford to cross potential line boundary.) */
4009 /* Two barewords in a row may indicate method call. */
4011 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv)))
4014 /* If not a declared subroutine, it's an indirect object. */
4015 /* (But it's an indir obj regardless for sort.) */
4017 if ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
4018 ((!gv || !GvCVu(gv)) &&
4019 (PL_last_lop_op != OP_MAPSTART &&
4020 PL_last_lop_op != OP_GREPSTART))))
4022 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
4028 PL_expect = XOPERATOR;
4031 /* Is this a word before a => operator? */
4032 if (*s == '=' && s[1] == '>') {
4034 sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
4035 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
4036 SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
4040 /* If followed by a paren, it's certainly a subroutine. */
4043 if (gv && GvCVu(gv)) {
4044 for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
4045 if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
4050 PL_nextval[PL_nexttoke].opval = yylval.opval;
4051 PL_expect = XOPERATOR;
4057 /* If followed by var or block, call it a method (unless sub) */
4059 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
4060 PL_last_lop = PL_oldbufptr;
4061 PL_last_lop_op = OP_METHOD;
4065 /* If followed by a bareword, see if it looks like indir obj. */
4067 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp = intuit_method(s,gv)))
4070 /* Not a method, so call it a subroutine (if defined) */
4072 if (gv && GvCVu(gv)) {
4074 if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
4075 Perl_warner(aTHX_ WARN_AMBIGUOUS,
4076 "Ambiguous use of -%s resolved as -&%s()",
4077 PL_tokenbuf, PL_tokenbuf);
4078 /* Check for a constant sub */
4080 if ((sv = cv_const_sv(cv))) {
4082 SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
4083 ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
4084 yylval.opval->op_private = 0;
4088 /* Resolve to GV now. */
4089 op_free(yylval.opval);
4090 yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4091 yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
4092 PL_last_lop = PL_oldbufptr;
4093 PL_last_lop_op = OP_ENTERSUB;
4094 /* Is there a prototype? */
4097 char *proto = SvPV((SV*)cv, len);
4100 if (strEQ(proto, "$"))
4102 if (*proto == '&' && *s == '{') {
4103 sv_setpv(PL_subname,"__ANON__");
4107 PL_nextval[PL_nexttoke].opval = yylval.opval;
4113 /* Call it a bare word */
4115 if (PL_hints & HINT_STRICT_SUBS)
4116 yylval.opval->op_private |= OPpCONST_STRICT;
4119 if (ckWARN(WARN_RESERVED)) {
4120 if (lastchar != '-') {
4121 for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
4123 Perl_warner(aTHX_ WARN_RESERVED, PL_warn_reserved,
4130 if (lastchar && strchr("*%&", lastchar) && ckWARN_d(WARN_AMBIGUOUS)) {
4131 Perl_warner(aTHX_ WARN_AMBIGUOUS,
4132 "Operator or semicolon missing before %c%s",
4133 lastchar, PL_tokenbuf);
4134 Perl_warner(aTHX_ WARN_AMBIGUOUS,
4135 "Ambiguous use of %c resolved as operator %c",
4136 lastchar, lastchar);
4142 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4143 newSVpv(CopFILE(PL_curcop),0));
4147 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4148 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
4151 case KEY___PACKAGE__:
4152 yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4154 ? newSVsv(PL_curstname)
4163 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
4164 char *pname = "main";
4165 if (PL_tokenbuf[2] == 'D')
4166 pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash);
4167 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);
4170 GvIOp(gv) = newIO();
4171 IoIFP(GvIOp(gv)) = PL_rsfp;
4172 #if defined(HAS_FCNTL) && defined(F_SETFD)
4174 int fd = PerlIO_fileno(PL_rsfp);
4175 fcntl(fd,F_SETFD,fd >= 3);
4178 /* Mark this internal pseudo-handle as clean */
4179 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4181 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
4182 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
4183 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
4185 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
4186 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
4187 /* if the script was opened in binmode, we need to revert
4188 * it to text mode for compatibility; but only iff it has CRs
4189 * XXX this is a questionable hack at best. */
4190 if (PL_bufend-PL_bufptr > 2
4191 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
4194 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
4195 loc = PerlIO_tell(PL_rsfp);
4196 (void)PerlIO_seek(PL_rsfp, 0L, 0);
4198 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
4199 #ifdef PERLIO_IS_STDIO /* really? */
4200 # if defined(__BORLANDC__)
4201 /* XXX see note in do_binmode() */
4202 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
4206 PerlIO_seek(PL_rsfp, loc, 0);
4210 #ifdef PERLIO_LAYERS
4211 if (UTF && !IN_BYTES)
4212 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
4225 if (PL_expect == XSTATE) {
4232 if (*s == ':' && s[1] == ':') {
4235 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4236 if (!(tmp = keyword(PL_tokenbuf, len)))
4237 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
4251 LOP(OP_ACCEPT,XTERM);
4257 LOP(OP_ATAN2,XTERM);
4263 LOP(OP_BINMODE,XTERM);
4266 LOP(OP_BLESS,XTERM);
4275 (void)gv_fetchpv("ENV",TRUE, SVt_PVHV); /* may use HOME */
4292 if (!PL_cryptseen) {
4293 PL_cryptseen = TRUE;
4297 LOP(OP_CRYPT,XTERM);
4300 if (ckWARN(WARN_CHMOD)) {
4301 for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ;
4302 if (*d != '0' && isDIGIT(*d))
4303 Perl_warner(aTHX_ WARN_CHMOD,
4304 "chmod() mode argument is missing initial 0");
4306 LOP(OP_CHMOD,XTERM);
4309 LOP(OP_CHOWN,XTERM);
4312 LOP(OP_CONNECT,XTERM);
4328 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4332 PL_hints |= HINT_BLOCK_SCOPE;
4342 gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
4343 LOP(OP_DBMOPEN,XTERM);
4349 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4356 yylval.ival = CopLINE(PL_curcop);
4370 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4371 UNIBRACK(OP_ENTEREVAL);
4386 case KEY_endhostent:
4392 case KEY_endservent:
4395 case KEY_endprotoent:
4406 yylval.ival = CopLINE(PL_curcop);
4408 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4410 if ((PL_bufend - p) >= 3 &&
4411 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4413 else if ((PL_bufend - p) >= 4 &&
4414 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4417 if (isIDFIRST_lazy_if(p,UTF)) {
4418 p = scan_ident(p, PL_bufend,
4419 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4423 Perl_croak(aTHX_ "Missing $ on loop variable");
4428 LOP(OP_FORMLINE,XTERM);
4434 LOP(OP_FCNTL,XTERM);
4440 LOP(OP_FLOCK,XTERM);
4449 LOP(OP_GREPSTART, XREF);
4452 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4467 case KEY_getpriority:
4468 LOP(OP_GETPRIORITY,XTERM);
4470 case KEY_getprotobyname:
4473 case KEY_getprotobynumber:
4474 LOP(OP_GPBYNUMBER,XTERM);
4476 case KEY_getprotoent:
4488 case KEY_getpeername:
4489 UNI(OP_GETPEERNAME);
4491 case KEY_gethostbyname:
4494 case KEY_gethostbyaddr:
4495 LOP(OP_GHBYADDR,XTERM);
4497 case KEY_gethostent:
4500 case KEY_getnetbyname:
4503 case KEY_getnetbyaddr:
4504 LOP(OP_GNBYADDR,XTERM);
4509 case KEY_getservbyname:
4510 LOP(OP_GSBYNAME,XTERM);
4512 case KEY_getservbyport:
4513 LOP(OP_GSBYPORT,XTERM);
4515 case KEY_getservent:
4518 case KEY_getsockname:
4519 UNI(OP_GETSOCKNAME);
4521 case KEY_getsockopt:
4522 LOP(OP_GSOCKOPT,XTERM);
4544 yylval.ival = CopLINE(PL_curcop);
4548 LOP(OP_INDEX,XTERM);
4554 LOP(OP_IOCTL,XTERM);
4566 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4598 LOP(OP_LISTEN,XTERM);
4607 s = scan_pat(s,OP_MATCH);
4608 TERM(sublex_start());
4611 LOP(OP_MAPSTART, XREF);
4614 LOP(OP_MKDIR,XTERM);
4617 LOP(OP_MSGCTL,XTERM);
4620 LOP(OP_MSGGET,XTERM);
4623 LOP(OP_MSGRCV,XTERM);
4626 LOP(OP_MSGSND,XTERM);
4632 if (isIDFIRST_lazy_if(s,UTF)) {
4633 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4634 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4636 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
4637 if (!PL_in_my_stash) {
4640 sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4648 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4655 if (PL_expect != XSTATE)
4656 yyerror("\"no\" not allowed in expression");
4657 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4658 s = force_version(s);
4663 if (*s == '(' || (s = skipspace(s), *s == '('))
4670 if (isIDFIRST_lazy_if(s,UTF)) {
4672 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
4674 if (strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE))
4675 Perl_warner(aTHX_ WARN_PRECEDENCE,
4676 "Precedence problem: open %.*s should be open(%.*s)",
4682 yylval.ival = OP_OR;
4692 LOP(OP_OPEN_DIR,XTERM);
4695 checkcomma(s,PL_tokenbuf,"filehandle");
4699 checkcomma(s,PL_tokenbuf,"filehandle");
4718 s = force_word(s,WORD,FALSE,TRUE,FALSE);
4722 LOP(OP_PIPE_OP,XTERM);
4725 s = scan_str(s,FALSE,FALSE);
4727 missingterm((char*)0);
4728 yylval.ival = OP_CONST;
4729 TERM(sublex_start());
4735 s = scan_str(s,FALSE,FALSE);
4737 missingterm((char*)0);
4739 if (SvCUR(PL_lex_stuff)) {
4742 d = SvPV_force(PL_lex_stuff, len);
4745 for (; isSPACE(*d) && len; --len, ++d) ;
4748 if (!warned && ckWARN(WARN_QW)) {
4749 for (; !isSPACE(*d) && len; --len, ++d) {
4751 Perl_warner(aTHX_ WARN_QW,
4752 "Possible attempt to separate words with commas");
4755 else if (*d == '#') {
4756 Perl_warner(aTHX_ WARN_QW,
4757 "Possible attempt to put comments in qw() list");
4763 for (; !isSPACE(*d) && len; --len, ++d) ;
4765 sv = newSVpvn(b, d-b);
4766 if (DO_UTF8(PL_lex_stuff))
4768 words = append_elem(OP_LIST, words,
4769 newSVOP(OP_CONST, 0, tokeq(sv)));
4773 PL_nextval[PL_nexttoke].opval = words;
4778 SvREFCNT_dec(PL_lex_stuff);
4779 PL_lex_stuff = Nullsv;
4785 s = scan_str(s,FALSE,FALSE);
4787 missingterm((char*)0);
4788 yylval.ival = OP_STRINGIFY;
4789 if (SvIVX(PL_lex_stuff) == '\'')
4790 SvIVX(PL_lex_stuff) = 0; /* qq'$foo' should intepolate */
4791 TERM(sublex_start());
4794 s = scan_pat(s,OP_QR);
4795 TERM(sublex_start());
4798 s = scan_str(s,FALSE,FALSE);
4800 missingterm((char*)0);
4801 yylval.ival = OP_BACKTICK;
4803 TERM(sublex_start());
4810 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
4811 s = force_version(s);
4814 *PL_tokenbuf = '\0';
4815 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4816 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
4817 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
4819 yyerror("<> should be quotes");
4827 s = force_word(s,WORD,TRUE,FALSE,FALSE);
4831 LOP(OP_RENAME,XTERM);
4840 LOP(OP_RINDEX,XTERM);
4863 LOP(OP_REVERSE,XTERM);
4874 TERM(sublex_start());
4876 TOKEN(1); /* force error */
4885 LOP(OP_SELECT,XTERM);
4891 LOP(OP_SEMCTL,XTERM);
4894 LOP(OP_SEMGET,XTERM);
4897 LOP(OP_SEMOP,XTERM);
4903 LOP(OP_SETPGRP,XTERM);
4905 case KEY_setpriority:
4906 LOP(OP_SETPRIORITY,XTERM);
4908 case KEY_sethostent:
4914 case KEY_setservent:
4917 case KEY_setprotoent:
4927 LOP(OP_SEEKDIR,XTERM);
4929 case KEY_setsockopt:
4930 LOP(OP_SSOCKOPT,XTERM);
4936 LOP(OP_SHMCTL,XTERM);
4939 LOP(OP_SHMGET,XTERM);
4942 LOP(OP_SHMREAD,XTERM);
4945 LOP(OP_SHMWRITE,XTERM);
4948 LOP(OP_SHUTDOWN,XTERM);
4957 LOP(OP_SOCKET,XTERM);
4959 case KEY_socketpair:
4960 LOP(OP_SOCKPAIR,XTERM);
4963 checkcomma(s,PL_tokenbuf,"subroutine name");
4965 if (*s == ';' || *s == ')') /* probably a close */
4966 Perl_croak(aTHX_ "sort is now a reserved word");
4968 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4972 LOP(OP_SPLIT,XTERM);
4975 LOP(OP_SPRINTF,XTERM);
4978 LOP(OP_SPLICE,XTERM);
4993 LOP(OP_SUBSTR,XTERM);
4999 char tmpbuf[sizeof PL_tokenbuf];
5000 SSize_t tboffset = 0;
5001 expectation attrful;
5002 bool have_name, have_proto;
5007 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
5008 (*s == ':' && s[1] == ':'))
5011 attrful = XATTRBLOCK;
5012 /* remember buffer pos'n for later force_word */
5013 tboffset = s - PL_oldbufptr;
5014 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5015 if (strchr(tmpbuf, ':'))
5016 sv_setpv(PL_subname, tmpbuf);
5018 sv_setsv(PL_subname,PL_curstname);
5019 sv_catpvn(PL_subname,"::",2);
5020 sv_catpvn(PL_subname,tmpbuf,len);
5027 Perl_croak(aTHX_ "Missing name in \"my sub\"");
5028 PL_expect = XTERMBLOCK;
5029 attrful = XATTRTERM;
5030 sv_setpv(PL_subname,"?");
5034 if (key == KEY_format) {
5036 PL_lex_formbrack = PL_lex_brackets + 1;
5038 (void) force_word(PL_oldbufptr + tboffset, WORD,
5043 /* Look for a prototype */
5047 s = scan_str(s,FALSE,FALSE);
5049 Perl_croak(aTHX_ "Prototype not terminated");
5051 d = SvPVX(PL_lex_stuff);
5053 for (p = d; *p; ++p) {
5058 SvCUR(PL_lex_stuff) = tmp;
5066 if (*s == ':' && s[1] != ':')
5067 PL_expect = attrful;
5070 PL_nextval[PL_nexttoke].opval =
5071 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
5072 PL_lex_stuff = Nullsv;
5076 sv_setpv(PL_subname,"__ANON__");
5079 (void) force_word(PL_oldbufptr + tboffset, WORD,
5088 LOP(OP_SYSTEM,XREF);
5091 LOP(OP_SYMLINK,XTERM);
5094 LOP(OP_SYSCALL,XTERM);
5097 LOP(OP_SYSOPEN,XTERM);
5100 LOP(OP_SYSSEEK,XTERM);
5103 LOP(OP_SYSREAD,XTERM);
5106 LOP(OP_SYSWRITE,XTERM);
5110 TERM(sublex_start());
5131 LOP(OP_TRUNCATE,XTERM);
5143 yylval.ival = CopLINE(PL_curcop);
5147 yylval.ival = CopLINE(PL_curcop);
5151 LOP(OP_UNLINK,XTERM);
5157 LOP(OP_UNPACK,XTERM);
5160 LOP(OP_UTIME,XTERM);
5163 if (ckWARN(WARN_UMASK)) {
5164 for (d = s; d < PL_bufend && (isSPACE(*d) || *d == '('); d++) ;
5165 if (*d != '0' && isDIGIT(*d))
5166 Perl_warner(aTHX_ WARN_UMASK,
5167 "umask: argument is missing initial 0");
5172 LOP(OP_UNSHIFT,XTERM);
5175 if (PL_expect != XSTATE)
5176 yyerror("\"use\" not allowed in expression");
5178 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
5179 s = force_version(s);
5180 if (*s == ';' || (s = skipspace(s), *s == ';')) {
5181 PL_nextval[PL_nexttoke].opval = Nullop;
5186 s = force_word(s,WORD,FALSE,TRUE,FALSE);
5187 s = force_version(s);
5199 yylval.ival = CopLINE(PL_curcop);
5203 PL_hints |= HINT_BLOCK_SCOPE;
5210 LOP(OP_WAITPID,XTERM);
5218 static char ctl_l[2];
5220 if (ctl_l[0] == '\0')
5221 ctl_l[0] = toCTRL('L');
5222 gv_fetchpv(ctl_l,TRUE, SVt_PV);
5225 gv_fetchpv("\f",TRUE, SVt_PV); /* Make sure $^L is defined */
5230 if (PL_expect == XOPERATOR)
5236 yylval.ival = OP_XOR;
5241 TERM(sublex_start());
5246 #pragma segment Main
5250 Perl_keyword(pTHX_ register char *d, I32 len)
5255 if (strEQ(d,"__FILE__")) return -KEY___FILE__;
5256 if (strEQ(d,"__LINE__")) return -KEY___LINE__;
5257 if (strEQ(d,"__PACKAGE__")) return -KEY___PACKAGE__;
5258 if (strEQ(d,"__DATA__")) return KEY___DATA__;
5259 if (strEQ(d,"__END__")) return KEY___END__;
5263 if (strEQ(d,"AUTOLOAD")) return KEY_AUTOLOAD;
5268 if (strEQ(d,"and")) return -KEY_and;
5269 if (strEQ(d,"abs")) return -KEY_abs;
5272 if (strEQ(d,"alarm")) return -KEY_alarm;
5273 if (strEQ(d,"atan2")) return -KEY_atan2;
5276 if (strEQ(d,"accept")) return -KEY_accept;
5281 if (strEQ(d,"BEGIN")) return KEY_BEGIN;
5284 if (strEQ(d,"bless")) return -KEY_bless;
5285 if (strEQ(d,"bind")) return -KEY_bind;
5286 if (strEQ(d,"binmode")) return -KEY_binmode;
5289 if (strEQ(d,"CORE")) return -KEY_CORE;
5290 if (strEQ(d,"CHECK")) return KEY_CHECK;
5295 if (strEQ(d,"cmp")) return -KEY_cmp;
5296 if (strEQ(d,"chr")) return -KEY_chr;
5297 if (strEQ(d,"cos")) return -KEY_cos;
5300 if (strEQ(d,"chop")) return -KEY_chop;
5303 if (strEQ(d,"close")) return -KEY_close;
5304 if (strEQ(d,"chdir")) return -KEY_chdir;
5305 if (strEQ(d,"chomp")) return -KEY_chomp;
5306 if (strEQ(d,"chmod")) return -KEY_chmod;
5307 if (strEQ(d,"chown")) return -KEY_chown;
5308 if (strEQ(d,"crypt")) return -KEY_crypt;
5311 if (strEQ(d,"chroot")) return -KEY_chroot;
5312 if (strEQ(d,"caller")) return -KEY_caller;
5315 if (strEQ(d,"connect")) return -KEY_connect;
5318 if (strEQ(d,"closedir")) return -KEY_closedir;
5319 if (strEQ(d,"continue")) return -KEY_continue;
5324 if (strEQ(d,"DESTROY")) return KEY_DESTROY;
5329 if (strEQ(d,"do")) return KEY_do;
5332 if (strEQ(d,"die")) return -KEY_die;
5335 if (strEQ(d,"dump")) return -KEY_dump;
5338 if (strEQ(d,"delete")) return KEY_delete;
5341 if (strEQ(d,"defined")) return KEY_defined;
5342 if (strEQ(d,"dbmopen")) return -KEY_dbmopen;
5345 if (strEQ(d,"dbmclose")) return -KEY_dbmclose;
5350 if (strEQ(d,"END")) return KEY_END;
5355 if (strEQ(d,"eq")) return -KEY_eq;
5358 if (strEQ(d,"eof")) return -KEY_eof;
5359 if (strEQ(d,"exp")) return -KEY_exp;
5362 if (strEQ(d,"else")) return KEY_else;
5363 if (strEQ(d,"exit")) return -KEY_exit;
5364 if (strEQ(d,"eval")) return KEY_eval;
5365 if (strEQ(d,"exec")) return -KEY_exec;
5366 if (strEQ(d,"each")) return -KEY_each;
5369 if (strEQ(d,"elsif")) return KEY_elsif;
5372 if (strEQ(d,"exists")) return KEY_exists;
5373 if (strEQ(d,"elseif")) Perl_warn(aTHX_ "elseif should be elsif");
5376 if (strEQ(d,"endgrent")) return -KEY_endgrent;
5377 if (strEQ(d,"endpwent")) return -KEY_endpwent;
5380 if (strEQ(d,"endnetent")) return -KEY_endnetent;
5383 if (strEQ(d,"endhostent")) return -KEY_endhostent;
5384 if (strEQ(d,"endservent")) return -KEY_endservent;
5387 if (strEQ(d,"endprotoent")) return -KEY_endprotoent;
5394 if (strEQ(d,"for")) return KEY_for;
5397 if (strEQ(d,"fork")) return -KEY_fork;
5400 if (strEQ(d,"fcntl")) return -KEY_fcntl;
5401 if (strEQ(d,"flock")) return -KEY_flock;
5404 if (strEQ(d,"format")) return KEY_format;
5405 if (strEQ(d,"fileno")) return -KEY_fileno;
5408 if (strEQ(d,"foreach")) return KEY_foreach;
5411 if (strEQ(d,"formline")) return -KEY_formline;
5416 if (strnEQ(d,"get",3)) {
5421 if (strEQ(d,"ppid")) return -KEY_getppid;
5422 if (strEQ(d,"pgrp")) return -KEY_getpgrp;
5425 if (strEQ(d,"pwent")) return -KEY_getpwent;
5426 if (strEQ(d,"pwnam")) return -KEY_getpwnam;
5427 if (strEQ(d,"pwuid")) return -KEY_getpwuid;
5430 if (strEQ(d,"peername")) return -KEY_getpeername;
5431 if (strEQ(d,"protoent")) return -KEY_getprotoent;
5432 if (strEQ(d,"priority")) return -KEY_getpriority;
5435 if (strEQ(d,"protobyname")) return -KEY_getprotobyname;
5438 if (strEQ(d,"protobynumber"))return -KEY_getprotobynumber;
5442 else if (*d == 'h') {
5443 if (strEQ(d,"hostbyname")) return -KEY_gethostbyname;
5444 if (strEQ(d,"hostbyaddr")) return -KEY_gethostbyaddr;
5445 if (strEQ(d,"hostent")) return -KEY_gethostent;
5447 else if (*d == 'n') {
5448 if (strEQ(d,"netbyname")) return -KEY_getnetbyname;
5449 if (strEQ(d,"netbyaddr")) return -KEY_getnetbyaddr;
5450 if (strEQ(d,"netent")) return -KEY_getnetent;
5452 else if (*d == 's') {
5453 if (strEQ(d,"servbyname")) return -KEY_getservbyname;
5454 if (strEQ(d,"servbyport")) return -KEY_getservbyport;
5455 if (strEQ(d,"servent")) return -KEY_getservent;
5456 if (strEQ(d,"sockname")) return -KEY_getsockname;
5457 if (strEQ(d,"sockopt")) return -KEY_getsockopt;
5459 else if (*d == 'g') {
5460 if (strEQ(d,"grent")) return -KEY_getgrent;
5461 if (strEQ(d,"grnam")) return -KEY_getgrnam;
5462 if (strEQ(d,"grgid")) return -KEY_getgrgid;
5464 else if (*d == 'l') {
5465 if (strEQ(d,"login")) return -KEY_getlogin;
5467 else if (strEQ(d,"c")) return -KEY_getc;
5472 if (strEQ(d,"gt")) return -KEY_gt;
5473 if (strEQ(d,"ge")) return -KEY_ge;
5476 if (strEQ(d,"grep")) return KEY_grep;
5477 if (strEQ(d,"goto")) return KEY_goto;
5478 if (strEQ(d,"glob")) return KEY_glob;
5481 if (strEQ(d,"gmtime")) return -KEY_gmtime;
5486 if (strEQ(d,"hex")) return -KEY_hex;
5489 if (strEQ(d,"INIT")) return KEY_INIT;
5494 if (strEQ(d,"if")) return KEY_if;
5497 if (strEQ(d,"int")) return -KEY_int;
5500 if (strEQ(d,"index")) return -KEY_index;
5501 if (strEQ(d,"ioctl")) return -KEY_ioctl;
5506 if (strEQ(d,"join")) return -KEY_join;
5510 if (strEQ(d,"keys")) return -KEY_keys;
5511 if (strEQ(d,"kill")) return -KEY_kill;
5517 if (strEQ(d,"lt")) return -KEY_lt;
5518 if (strEQ(d,"le")) return -KEY_le;
5519 if (strEQ(d,"lc")) return -KEY_lc;
5522 if (strEQ(d,"log")) return -KEY_log;
5525 if (strEQ(d,"last")) return KEY_last;
5526 if (strEQ(d,"link")) return -KEY_link;
5527 if (strEQ(d,"lock")) return -KEY_lock;
5530 if (strEQ(d,"local")) return KEY_local;
5531 if (strEQ(d,"lstat")) return -KEY_lstat;
5534 if (strEQ(d,"length")) return -KEY_length;
5535 if (strEQ(d,"listen")) return -KEY_listen;
5538 if (strEQ(d,"lcfirst")) return -KEY_lcfirst;
5541 if (strEQ(d,"localtime")) return -KEY_localtime;
5547 case 1: return KEY_m;
5549 if (strEQ(d,"my")) return KEY_my;
5552 if (strEQ(d,"map")) return KEY_map;
5555 if (strEQ(d,"mkdir")) return -KEY_mkdir;
5558 if (strEQ(d,"msgctl")) return -KEY_msgctl;
5559 if (strEQ(d,"msgget")) return -KEY_msgget;
5560 if (strEQ(d,"msgrcv")) return -KEY_msgrcv;
5561 if (strEQ(d,"msgsnd")) return -KEY_msgsnd;
5566 if (strEQ(d,"next")) return KEY_next;
5567 if (strEQ(d,"ne")) return -KEY_ne;
5568 if (strEQ(d,"not")) return -KEY_not;
5569 if (strEQ(d,"no")) return KEY_no;
5574 if (strEQ(d,"or")) return -KEY_or;
5577 if (strEQ(d,"ord")) return -KEY_ord;
5578 if (strEQ(d,"oct")) return -KEY_oct;
5579 if (strEQ(d,"our")) return KEY_our;
5582 if (strEQ(d,"open")) return -KEY_open;
5585 if (strEQ(d,"opendir")) return -KEY_opendir;
5592 if (strEQ(d,"pop")) return -KEY_pop;
5593 if (strEQ(d,"pos")) return KEY_pos;
5596 if (strEQ(d,"push")) return -KEY_push;
5597 if (strEQ(d,"pack")) return -KEY_pack;
5598 if (strEQ(d,"pipe")) return -KEY_pipe;
5601 if (strEQ(d,"print")) return KEY_print;
5604 if (strEQ(d,"printf")) return KEY_printf;
5607 if (strEQ(d,"package")) return KEY_package;
5610 if (strEQ(d,"prototype")) return KEY_prototype;
5615 if (strEQ(d,"q")) return KEY_q;
5616 if (strEQ(d,"qr")) return KEY_qr;
5617 if (strEQ(d,"qq")) return KEY_qq;
5618 if (strEQ(d,"qw")) return KEY_qw;
5619 if (strEQ(d,"qx")) return KEY_qx;
5621 else if (strEQ(d,"quotemeta")) return -KEY_quotemeta;
5626 if (strEQ(d,"ref")) return -KEY_ref;
5629 if (strEQ(d,"read")) return -KEY_read;
5630 if (strEQ(d,"rand")) return -KEY_rand;
5631 if (strEQ(d,"recv")) return -KEY_recv;
5632 if (strEQ(d,"redo")) return KEY_redo;
5635 if (strEQ(d,"rmdir")) return -KEY_rmdir;
5636 if (strEQ(d,"reset")) return -KEY_reset;
5639 if (strEQ(d,"return")) return KEY_return;
5640 if (strEQ(d,"rename")) return -KEY_rename;
5641 if (strEQ(d,"rindex")) return -KEY_rindex;
5644 if (strEQ(d,"require")) return KEY_require;
5645 if (strEQ(d,"reverse")) return -KEY_reverse;
5646 if (strEQ(d,"readdir")) return -KEY_readdir;
5649 if (strEQ(d,"readlink")) return -KEY_readlink;
5650 if (strEQ(d,"readline")) return -KEY_readline;
5651 if (strEQ(d,"readpipe")) return -KEY_readpipe;
5654 if (strEQ(d,"rewinddir")) return -KEY_rewinddir;
5660 case 0: return KEY_s;
5662 if (strEQ(d,"scalar")) return KEY_scalar;
5667 if (strEQ(d,"seek")) return -KEY_seek;
5668 if (strEQ(d,"send")) return -KEY_send;
5671 if (strEQ(d,"semop")) return -KEY_semop;
5674 if (strEQ(d,"select")) return -KEY_select;
5675 if (strEQ(d,"semctl")) return -KEY_semctl;
5676 if (strEQ(d,"semget")) return -KEY_semget;
5679 if (strEQ(d,"setpgrp")) return -KEY_setpgrp;
5680 if (strEQ(d,"seekdir")) return -KEY_seekdir;
5683 if (strEQ(d,"setpwent")) return -KEY_setpwent;
5684 if (strEQ(d,"setgrent")) return -KEY_setgrent;
5687 if (strEQ(d,"setnetent")) return -KEY_setnetent;
5690 if (strEQ(d,"setsockopt")) return -KEY_setsockopt;
5691 if (strEQ(d,"sethostent")) return -KEY_sethostent;
5692 if (strEQ(d,"setservent")) return -KEY_setservent;
5695 if (strEQ(d,"setpriority")) return -KEY_setpriority;
5696 if (strEQ(d,"setprotoent")) return -KEY_setprotoent;
5703 if (strEQ(d,"shift")) return -KEY_shift;
5706 if (strEQ(d,"shmctl")) return -KEY_shmctl;
5707 if (strEQ(d,"shmget")) return -KEY_shmget;
5710 if (strEQ(d,"shmread")) return -KEY_shmread;
5713 if (strEQ(d,"shmwrite")) return -KEY_shmwrite;
5714 if (strEQ(d,"shutdown")) return -KEY_shutdown;
5719 if (strEQ(d,"sin")) return -KEY_sin;
5722 if (strEQ(d,"sleep")) return -KEY_sleep;
5725 if (strEQ(d,"sort")) return KEY_sort;
5726 if (strEQ(d,"socket")) return -KEY_socket;
5727 if (strEQ(d,"socketpair")) return -KEY_socketpair;
5730 if (strEQ(d,"split")) return KEY_split;
5731 if (strEQ(d,"sprintf")) return -KEY_sprintf;
5732 if (strEQ(d,"splice")) return -KEY_splice;
5735 if (strEQ(d,"sqrt")) return -KEY_sqrt;
5738 if (strEQ(d,"srand")) return -KEY_srand;
5741 if (strEQ(d,"stat")) return -KEY_stat;
5742 if (strEQ(d,"study")) return KEY_study;
5745 if (strEQ(d,"substr")) return -KEY_substr;
5746 if (strEQ(d,"sub")) return KEY_sub;
5751 if (strEQ(d,"system")) return -KEY_system;
5754 if (strEQ(d,"symlink")) return -KEY_symlink;
5755 if (strEQ(d,"syscall")) return -KEY_syscall;
5756 if (strEQ(d,"sysopen")) return -KEY_sysopen;
5757 if (strEQ(d,"sysread")) return -KEY_sysread;
5758 if (strEQ(d,"sysseek")) return -KEY_sysseek;
5761 if (strEQ(d,"syswrite")) return -KEY_syswrite;
5770 if (strEQ(d,"tr")) return KEY_tr;
5773 if (strEQ(d,"tie")) return KEY_tie;
5776 if (strEQ(d,"tell")) return -KEY_tell;
5777 if (strEQ(d,"tied")) return KEY_tied;
5778 if (strEQ(d,"time")) return -KEY_time;
5781 if (strEQ(d,"times")) return -KEY_times;
5784 if (strEQ(d,"telldir")) return -KEY_telldir;
5787 if (strEQ(d,"truncate")) return -KEY_truncate;
5794 if (strEQ(d,"uc")) return -KEY_uc;
5797 if (strEQ(d,"use")) return KEY_use;
5800 if (strEQ(d,"undef")) return KEY_undef;
5801 if (strEQ(d,"until")) return KEY_until;
5802 if (strEQ(d,"untie")) return KEY_untie;
5803 if (strEQ(d,"utime")) return -KEY_utime;
5804 if (strEQ(d,"umask")) return -KEY_umask;
5807 if (strEQ(d,"unless")) return KEY_unless;
5808 if (strEQ(d,"unpack")) return -KEY_unpack;
5809 if (strEQ(d,"unlink")) return -KEY_unlink;
5812 if (strEQ(d,"unshift")) return -KEY_unshift;
5813 if (strEQ(d,"ucfirst")) return -KEY_ucfirst;
5818 if (strEQ(d,"values")) return -KEY_values;
5819 if (strEQ(d,"vec")) return -KEY_vec;
5824 if (strEQ(d,"warn")) return -KEY_warn;
5825 if (strEQ(d,"wait")) return -KEY_wait;
5828 if (strEQ(d,"while")) return KEY_while;
5829 if (strEQ(d,"write")) return -KEY_write;
5832 if (strEQ(d,"waitpid")) return -KEY_waitpid;
5835 if (strEQ(d,"wantarray")) return -KEY_wantarray;
5840 if (len == 1) return -KEY_x;
5841 if (strEQ(d,"xor")) return -KEY_xor;
5844 if (len == 1) return KEY_y;
5853 S_checkcomma(pTHX_ register char *s, char *name, char *what)
5857 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
5858 if (ckWARN(WARN_SYNTAX)) {
5860 for (w = s+2; *w && level; w++) {
5867 for (; *w && isSPACE(*w); w++) ;
5868 if (!*w || !strchr(";|})]oaiuw!=", *w)) /* an advisory hack only... */
5869 Perl_warner(aTHX_ WARN_SYNTAX,
5870 "%s (...) interpreted as function",name);
5873 while (s < PL_bufend && isSPACE(*s))
5877 while (s < PL_bufend && isSPACE(*s))
5879 if (isIDFIRST_lazy_if(s,UTF)) {
5881 while (isALNUM_lazy_if(s,UTF))
5883 while (s < PL_bufend && isSPACE(*s))
5888 kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
5892 Perl_croak(aTHX_ "No comma allowed after %s", what);
5897 /* Either returns sv, or mortalizes sv and returns a new SV*.
5898 Best used as sv=new_constant(..., sv, ...).
5899 If s, pv are NULL, calls subroutine with one argument,
5900 and type is used with error messages only. */
5903 S_new_constant(pTHX_ char *s, STRLEN len, const char *key, SV *sv, SV *pv,
5907 HV *table = GvHV(PL_hintgv); /* ^H */
5911 const char *why1, *why2, *why3;
5913 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
5916 why2 = strEQ(key,"charnames")
5917 ? "(possibly a missing \"use charnames ...\")"
5919 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
5920 (type ? type: "undef"), why2);
5922 /* This is convoluted and evil ("goto considered harmful")
5923 * but I do not understand the intricacies of all the different
5924 * failure modes of %^H in here. The goal here is to make
5925 * the most probable error message user-friendly. --jhi */
5930 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
5931 (type ? type: "undef"), why1, why2, why3);
5933 yyerror(SvPVX(msg));
5937 cvp = hv_fetch(table, key, strlen(key), FALSE);
5938 if (!cvp || !SvOK(*cvp)) {
5941 why3 = "} is not defined";
5944 sv_2mortal(sv); /* Parent created it permanently */
5947 pv = sv_2mortal(newSVpvn(s, len));
5949 typesv = sv_2mortal(newSVpv(type, 0));
5951 typesv = &PL_sv_undef;
5953 PUSHSTACKi(PERLSI_OVERLOAD);
5965 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
5969 /* Check the eval first */
5970 if (!PL_in_eval && SvTRUE(ERRSV)) {
5972 sv_catpv(ERRSV, "Propagated");
5973 yyerror(SvPV(ERRSV, n_a)); /* Duplicates the message inside eval */
5975 res = SvREFCNT_inc(sv);
5979 (void)SvREFCNT_inc(res);
5988 why1 = "Call to &{$^H{";
5990 why3 = "}} did not return a defined value";
5999 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
6001 register char *d = dest;
6002 register char *e = d + destlen - 3; /* two-character token, ending NUL */
6005 Perl_croak(aTHX_ ident_too_long);
6006 if (isALNUM(*s)) /* UTF handled below */
6008 else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
6013 else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
6017 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
6018 char *t = s + UTF8SKIP(s);
6019 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
6021 if (d + (t - s) > e)
6022 Perl_croak(aTHX_ ident_too_long);
6023 Copy(s, d, t - s, char);
6036 S_scan_ident(pTHX_ register char *s, register char *send, char *dest, STRLEN destlen, I32 ck_uni)
6046 e = d + destlen - 3; /* two-character token, ending NUL */
6048 while (isDIGIT(*s)) {
6050 Perl_croak(aTHX_ ident_too_long);
6057 Perl_croak(aTHX_ ident_too_long);
6058 if (isALNUM(*s)) /* UTF handled below */
6060 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
6065 else if (*s == ':' && s[1] == ':') {
6069 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
6070 char *t = s + UTF8SKIP(s);
6071 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
6073 if (d + (t - s) > e)
6074 Perl_croak(aTHX_ ident_too_long);
6075 Copy(s, d, t - s, char);
6086 if (PL_lex_state != LEX_NORMAL)
6087 PL_lex_state = LEX_INTERPENDMAYBE;
6090 if (*s == '$' && s[1] &&
6091 (isALNUM_lazy_if(s+1,UTF) || strchr("${", s[1]) || strnEQ(s+1,"::",2)) )
6104 if (*d == '^' && *s && isCONTROLVAR(*s)) {
6109 if (isSPACE(s[-1])) {
6112 if (!SPACE_OR_TAB(ch)) {
6118 if (isIDFIRST_lazy_if(d,UTF)) {
6122 while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') {
6124 while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e))
6127 Copy(s, d, e - s, char);
6132 while ((isALNUM(*s) || *s == ':') && d < e)
6135 Perl_croak(aTHX_ ident_too_long);
6138 while (s < send && SPACE_OR_TAB(*s)) s++;
6139 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
6140 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
6141 const char *brack = *s == '[' ? "[...]" : "{...}";
6142 Perl_warner(aTHX_ WARN_AMBIGUOUS,
6143 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
6144 funny, dest, brack, funny, dest, brack);
6147 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
6151 /* Handle extended ${^Foo} variables
6152 * 1999-02-27 mjd-perl-patch@plover.com */
6153 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
6157 while (isALNUM(*s) && d < e) {
6161 Perl_croak(aTHX_ ident_too_long);
6166 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets)
6167 PL_lex_state = LEX_INTERPEND;
6170 if (PL_lex_state == LEX_NORMAL) {
6171 if (ckWARN(WARN_AMBIGUOUS) &&
6172 (keyword(dest, d - dest) || get_cv(dest, FALSE)))
6174 Perl_warner(aTHX_ WARN_AMBIGUOUS,
6175 "Ambiguous use of %c{%s} resolved to %c%s",
6176 funny, dest, funny, dest);
6181 s = bracket; /* let the parser handle it */
6185 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
6186 PL_lex_state = LEX_INTERPEND;
6191 Perl_pmflag(pTHX_ U16 *pmfl, int ch)
6196 *pmfl |= PMf_GLOBAL;
6198 *pmfl |= PMf_CONTINUE;
6202 *pmfl |= PMf_MULTILINE;
6204 *pmfl |= PMf_SINGLELINE;
6206 *pmfl |= PMf_EXTENDED;
6210 S_scan_pat(pTHX_ char *start, I32 type)
6215 s = scan_str(start,FALSE,FALSE);
6217 Perl_croak(aTHX_ "Search pattern not terminated");
6219 pm = (PMOP*)newPMOP(type, 0);
6220 if (PL_multi_open == '?')
6221 pm->op_pmflags |= PMf_ONCE;
6223 while (*s && strchr("iomsx", *s))
6224 pmflag(&pm->op_pmflags,*s++);
6227 while (*s && strchr("iogcmsx", *s))
6228 pmflag(&pm->op_pmflags,*s++);
6230 pm->op_pmpermflags = pm->op_pmflags;
6232 PL_lex_op = (OP*)pm;
6233 yylval.ival = OP_MATCH;
6238 S_scan_subst(pTHX_ char *start)
6245 yylval.ival = OP_NULL;
6247 s = scan_str(start,FALSE,FALSE);
6250 Perl_croak(aTHX_ "Substitution pattern not terminated");
6252 if (s[-1] == PL_multi_open)
6255 first_start = PL_multi_start;
6256 s = scan_str(s,FALSE,FALSE);
6259 SvREFCNT_dec(PL_lex_stuff);
6260 PL_lex_stuff = Nullsv;
6262 Perl_croak(aTHX_ "Substitution replacement not terminated");
6264 PL_multi_start = first_start; /* so whole substitution is taken together */
6266 pm = (PMOP*)newPMOP(OP_SUBST, 0);
6272 else if (strchr("iogcmsx", *s))
6273 pmflag(&pm->op_pmflags,*s++);
6280 PL_sublex_info.super_bufptr = s;
6281 PL_sublex_info.super_bufend = PL_bufend;
6283 pm->op_pmflags |= PMf_EVAL;
6284 repl = newSVpvn("",0);
6286 sv_catpv(repl, es ? "eval " : "do ");
6287 sv_catpvn(repl, "{ ", 2);
6288 sv_catsv(repl, PL_lex_repl);
6289 sv_catpvn(repl, " };", 2);
6291 SvREFCNT_dec(PL_lex_repl);
6295 pm->op_pmpermflags = pm->op_pmflags;
6296 PL_lex_op = (OP*)pm;
6297 yylval.ival = OP_SUBST;
6302 S_scan_trans(pTHX_ char *start)
6311 yylval.ival = OP_NULL;
6313 s = scan_str(start,FALSE,FALSE);
6315 Perl_croak(aTHX_ "Transliteration pattern not terminated");
6316 if (s[-1] == PL_multi_open)
6319 s = scan_str(s,FALSE,FALSE);
6322 SvREFCNT_dec(PL_lex_stuff);
6323 PL_lex_stuff = Nullsv;
6325 Perl_croak(aTHX_ "Transliteration replacement not terminated");
6328 complement = del = squash = 0;
6329 while (strchr("cds", *s)) {
6331 complement = OPpTRANS_COMPLEMENT;
6333 del = OPpTRANS_DELETE;
6335 squash = OPpTRANS_SQUASH;
6339 New(803, tbl, complement&&!del?258:256, short);
6340 o = newPVOP(OP_TRANS, 0, (char*)tbl);
6341 o->op_private = del|squash|complement|
6342 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
6343 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
6346 yylval.ival = OP_TRANS;
6351 S_scan_heredoc(pTHX_ register char *s)
6354 I32 op_type = OP_SCALAR;
6361 int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
6365 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
6368 for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
6369 if (*peek && strchr("`'\"",*peek)) {
6372 s = delimcpy(d, e, s, PL_bufend, term, &len);
6382 if (!isALNUM_lazy_if(s,UTF))
6383 deprecate("bare << to mean <<\"\"");
6384 for (; isALNUM_lazy_if(s,UTF); s++) {
6389 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
6390 Perl_croak(aTHX_ "Delimiter for here document is too long");
6393 len = d - PL_tokenbuf;
6394 #ifndef PERL_STRICT_CR
6395 d = strchr(s, '\r');
6399 while (s < PL_bufend) {
6405 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
6414 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
6419 if (outer || !(d=ninstr(s,PL_bufend,d,d+1)))
6420 herewas = newSVpvn(s,PL_bufend-s);
6422 s--, herewas = newSVpvn(s,d-s);
6423 s += SvCUR(herewas);
6425 tmpstr = NEWSV(87,79);
6426 sv_upgrade(tmpstr, SVt_PVIV);
6431 else if (term == '`') {
6432 op_type = OP_BACKTICK;
6433 SvIVX(tmpstr) = '\\';
6437 PL_multi_start = CopLINE(PL_curcop);
6438 PL_multi_open = PL_multi_close = '<';
6439 term = *PL_tokenbuf;
6440 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
6441 char *bufptr = PL_sublex_info.super_bufptr;
6442 char *bufend = PL_sublex_info.super_bufend;
6443 char *olds = s - SvCUR(herewas);
6444 s = strchr(bufptr, '\n');
6448 while (s < bufend &&
6449 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
6451 CopLINE_inc(PL_curcop);
6454 CopLINE_set(PL_curcop, PL_multi_start);
6455 missingterm(PL_tokenbuf);
6457 sv_setpvn(herewas,bufptr,d-bufptr+1);
6458 sv_setpvn(tmpstr,d+1,s-d);
6460 sv_catpvn(herewas,s,bufend-s);
6461 (void)strcpy(bufptr,SvPVX(herewas));
6468 while (s < PL_bufend &&
6469 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
6471 CopLINE_inc(PL_curcop);
6473 if (s >= PL_bufend) {
6474 CopLINE_set(PL_curcop, PL_multi_start);
6475 missingterm(PL_tokenbuf);
6477 sv_setpvn(tmpstr,d+1,s-d);
6479 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
6481 sv_catpvn(herewas,s,PL_bufend-s);
6482 sv_setsv(PL_linestr,herewas);
6483 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
6484 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6485 PL_last_lop = PL_last_uni = Nullch;
6488 sv_setpvn(tmpstr,"",0); /* avoid "uninitialized" warning */
6489 while (s >= PL_bufend) { /* multiple line string? */
6491 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
6492 CopLINE_set(PL_curcop, PL_multi_start);
6493 missingterm(PL_tokenbuf);
6495 CopLINE_inc(PL_curcop);
6496 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6497 PL_last_lop = PL_last_uni = Nullch;
6498 #ifndef PERL_STRICT_CR
6499 if (PL_bufend - PL_linestart >= 2) {
6500 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
6501 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
6503 PL_bufend[-2] = '\n';
6505 SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr));
6507 else if (PL_bufend[-1] == '\r')
6508 PL_bufend[-1] = '\n';
6510 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
6511 PL_bufend[-1] = '\n';
6513 if (PERLDB_LINE && PL_curstash != PL_debstash) {
6514 SV *sv = NEWSV(88,0);
6516 sv_upgrade(sv, SVt_PVMG);
6517 sv_setsv(sv,PL_linestr);
6518 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
6520 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
6523 sv_catsv(PL_linestr,herewas);
6524 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6528 sv_catsv(tmpstr,PL_linestr);
6533 PL_multi_end = CopLINE(PL_curcop);
6534 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
6535 SvLEN_set(tmpstr, SvCUR(tmpstr) + 1);
6536 Renew(SvPVX(tmpstr), SvLEN(tmpstr), char);
6538 SvREFCNT_dec(herewas);
6539 if (UTF && !IN_BYTES && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr)))
6541 PL_lex_stuff = tmpstr;
6542 yylval.ival = op_type;
6547 takes: current position in input buffer
6548 returns: new position in input buffer
6549 side-effects: yylval and lex_op are set.
6554 <FH> read from filehandle
6555 <pkg::FH> read from package qualified filehandle
6556 <pkg'FH> read from package qualified filehandle
6557 <$fh> read from filehandle in $fh
6563 S_scan_inputsymbol(pTHX_ char *start)
6565 register char *s = start; /* current position in buffer */
6571 d = PL_tokenbuf; /* start of temp holding space */
6572 e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
6573 end = strchr(s, '\n');
6576 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
6578 /* die if we didn't have space for the contents of the <>,
6579 or if it didn't end, or if we see a newline
6582 if (len >= sizeof PL_tokenbuf)
6583 Perl_croak(aTHX_ "Excessively long <> operator");
6585 Perl_croak(aTHX_ "Unterminated <> operator");
6590 Remember, only scalar variables are interpreted as filehandles by
6591 this code. Anything more complex (e.g., <$fh{$num}>) will be
6592 treated as a glob() call.
6593 This code makes use of the fact that except for the $ at the front,
6594 a scalar variable and a filehandle look the same.
6596 if (*d == '$' && d[1]) d++;
6598 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
6599 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
6602 /* If we've tried to read what we allow filehandles to look like, and
6603 there's still text left, then it must be a glob() and not a getline.
6604 Use scan_str to pull out the stuff between the <> and treat it
6605 as nothing more than a string.
6608 if (d - PL_tokenbuf != len) {
6609 yylval.ival = OP_GLOB;
6611 s = scan_str(start,FALSE,FALSE);
6613 Perl_croak(aTHX_ "Glob not terminated");
6617 /* we're in a filehandle read situation */
6620 /* turn <> into <ARGV> */
6622 (void)strcpy(d,"ARGV");
6624 /* if <$fh>, create the ops to turn the variable into a
6630 /* try to find it in the pad for this block, otherwise find
6631 add symbol table ops
6633 if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
6634 OP *o = newOP(OP_PADSV, 0);
6636 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, o);
6639 GV *gv = gv_fetchpv(d+1,TRUE, SVt_PV);
6640 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0,
6641 newUNOP(OP_RV2SV, 0,
6642 newGVOP(OP_GV, 0, gv)));
6644 PL_lex_op->op_flags |= OPf_SPECIAL;
6645 /* we created the ops in PL_lex_op, so make yylval.ival a null op */
6646 yylval.ival = OP_NULL;
6649 /* If it's none of the above, it must be a literal filehandle
6650 (<Foo::BAR> or <FOO>) so build a simple readline OP */
6652 GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
6653 PL_lex_op = (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
6654 yylval.ival = OP_NULL;
6663 takes: start position in buffer
6664 keep_quoted preserve \ on the embedded delimiter(s)
6665 keep_delims preserve the delimiters around the string
6666 returns: position to continue reading from buffer
6667 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
6668 updates the read buffer.
6670 This subroutine pulls a string out of the input. It is called for:
6671 q single quotes q(literal text)
6672 ' single quotes 'literal text'
6673 qq double quotes qq(interpolate $here please)
6674 " double quotes "interpolate $here please"
6675 qx backticks qx(/bin/ls -l)
6676 ` backticks `/bin/ls -l`
6677 qw quote words @EXPORT_OK = qw( func() $spam )
6678 m// regexp match m/this/
6679 s/// regexp substitute s/this/that/
6680 tr/// string transliterate tr/this/that/
6681 y/// string transliterate y/this/that/
6682 ($*@) sub prototypes sub foo ($)
6683 (stuff) sub attr parameters sub foo : attr(stuff)
6684 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
6686 In most of these cases (all but <>, patterns and transliterate)
6687 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
6688 calls scan_str(). s/// makes yylex() call scan_subst() which calls
6689 scan_str(). tr/// and y/// make yylex() call scan_trans() which
6692 It skips whitespace before the string starts, and treats the first
6693 character as the delimiter. If the delimiter is one of ([{< then
6694 the corresponding "close" character )]}> is used as the closing
6695 delimiter. It allows quoting of delimiters, and if the string has
6696 balanced delimiters ([{<>}]) it allows nesting.
6698 On success, the SV with the resulting string is put into lex_stuff or,
6699 if that is already non-NULL, into lex_repl. The second case occurs only
6700 when parsing the RHS of the special constructs s/// and tr/// (y///).
6701 For convenience, the terminating delimiter character is stuffed into
6706 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
6708 SV *sv; /* scalar value: string */
6709 char *tmps; /* temp string, used for delimiter matching */
6710 register char *s = start; /* current position in the buffer */
6711 register char term; /* terminating character */
6712 register char *to; /* current position in the sv's data */
6713 I32 brackets = 1; /* bracket nesting level */
6714 bool has_utf8 = FALSE; /* is there any utf8 content? */
6716 /* skip space before the delimiter */
6720 /* mark where we are, in case we need to report errors */
6723 /* after skipping whitespace, the next character is the terminator */
6725 if (!UTF8_IS_INVARIANT((U8)term) && UTF)
6728 /* mark where we are */
6729 PL_multi_start = CopLINE(PL_curcop);
6730 PL_multi_open = term;
6732 /* find corresponding closing delimiter */
6733 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
6735 PL_multi_close = term;
6737 /* create a new SV to hold the contents. 87 is leak category, I'm
6738 assuming. 79 is the SV's initial length. What a random number. */
6740 sv_upgrade(sv, SVt_PVIV);
6742 (void)SvPOK_only(sv); /* validate pointer */
6744 /* move past delimiter and try to read a complete string */
6746 sv_catpvn(sv, s, 1);
6749 /* extend sv if need be */
6750 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
6751 /* set 'to' to the next character in the sv's string */
6752 to = SvPVX(sv)+SvCUR(sv);
6754 /* if open delimiter is the close delimiter read unbridle */
6755 if (PL_multi_open == PL_multi_close) {
6756 for (; s < PL_bufend; s++,to++) {
6757 /* embedded newlines increment the current line number */
6758 if (*s == '\n' && !PL_rsfp)
6759 CopLINE_inc(PL_curcop);
6760 /* handle quoted delimiters */
6761 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
6762 if (!keep_quoted && s[1] == term)
6764 /* any other quotes are simply copied straight through */
6768 /* terminate when run out of buffer (the for() condition), or
6769 have found the terminator */
6770 else if (*s == term)
6772 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
6778 /* if the terminator isn't the same as the start character (e.g.,
6779 matched brackets), we have to allow more in the quoting, and
6780 be prepared for nested brackets.
6783 /* read until we run out of string, or we find the terminator */
6784 for (; s < PL_bufend; s++,to++) {
6785 /* embedded newlines increment the line count */
6786 if (*s == '\n' && !PL_rsfp)
6787 CopLINE_inc(PL_curcop);
6788 /* backslashes can escape the open or closing characters */
6789 if (*s == '\\' && s+1 < PL_bufend) {
6791 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
6796 /* allow nested opens and closes */
6797 else if (*s == PL_multi_close && --brackets <= 0)
6799 else if (*s == PL_multi_open)
6801 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
6806 /* terminate the copied string and update the sv's end-of-string */
6808 SvCUR_set(sv, to - SvPVX(sv));
6811 * this next chunk reads more into the buffer if we're not done yet
6815 break; /* handle case where we are done yet :-) */
6817 #ifndef PERL_STRICT_CR
6818 if (to - SvPVX(sv) >= 2) {
6819 if ((to[-2] == '\r' && to[-1] == '\n') ||
6820 (to[-2] == '\n' && to[-1] == '\r'))
6824 SvCUR_set(sv, to - SvPVX(sv));
6826 else if (to[-1] == '\r')
6829 else if (to - SvPVX(sv) == 1 && to[-1] == '\r')
6833 /* if we're out of file, or a read fails, bail and reset the current
6834 line marker so we can report where the unterminated string began
6837 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
6839 CopLINE_set(PL_curcop, PL_multi_start);
6842 /* we read a line, so increment our line counter */
6843 CopLINE_inc(PL_curcop);
6845 /* update debugger info */
6846 if (PERLDB_LINE && PL_curstash != PL_debstash) {
6847 SV *sv = NEWSV(88,0);
6849 sv_upgrade(sv, SVt_PVMG);
6850 sv_setsv(sv,PL_linestr);
6851 av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
6854 /* having changed the buffer, we must update PL_bufend */
6855 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
6856 PL_last_lop = PL_last_uni = Nullch;
6859 /* at this point, we have successfully read the delimited string */
6862 sv_catpvn(sv, s, 1);
6865 PL_multi_end = CopLINE(PL_curcop);
6868 /* if we allocated too much space, give some back */
6869 if (SvCUR(sv) + 5 < SvLEN(sv)) {
6870 SvLEN_set(sv, SvCUR(sv) + 1);
6871 Renew(SvPVX(sv), SvLEN(sv), char);
6874 /* decide whether this is the first or second quoted string we've read
6887 takes: pointer to position in buffer
6888 returns: pointer to new position in buffer
6889 side-effects: builds ops for the constant in yylval.op
6891 Read a number in any of the formats that Perl accepts:
6893 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
6894 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
6897 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
6899 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
6902 If it reads a number without a decimal point or an exponent, it will
6903 try converting the number to an integer and see if it can do so
6904 without loss of precision.
6908 Perl_scan_num(pTHX_ char *start, YYSTYPE* lvalp)
6910 register char *s = start; /* current position in buffer */
6911 register char *d; /* destination in temp buffer */
6912 register char *e; /* end of temp buffer */
6913 NV nv; /* number read, as a double */
6914 SV *sv = Nullsv; /* place to put the converted number */
6915 bool floatit; /* boolean: int or float? */
6916 char *lastub = 0; /* position of last underbar */
6917 static char number_too_long[] = "Number too long";
6919 /* We use the first character to decide what type of number this is */
6923 Perl_croak(aTHX_ "panic: scan_num");
6925 /* if it starts with a 0, it could be an octal number, a decimal in
6926 0.13 disguise, or a hexadecimal number, or a binary number. */
6930 u holds the "number so far"
6931 shift the power of 2 of the base
6932 (hex == 4, octal == 3, binary == 1)
6933 overflowed was the number more than we can hold?
6935 Shift is used when we add a digit. It also serves as an "are
6936 we in octal/hex/binary?" indicator to disallow hex characters
6942 bool overflowed = FALSE;
6943 static NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
6944 static char* bases[5] = { "", "binary", "", "octal",
6946 static char* Bases[5] = { "", "Binary", "", "Octal",
6948 static char *maxima[5] = { "",
6949 "0b11111111111111111111111111111111",
6953 char *base, *Base, *max;
6959 } else if (s[1] == 'b') {
6963 /* check for a decimal in disguise */
6964 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
6966 /* so it must be octal */
6973 if (ckWARN(WARN_SYNTAX))
6974 Perl_warner(aTHX_ WARN_SYNTAX,
6975 "Misplaced _ in number");
6979 base = bases[shift];
6980 Base = Bases[shift];
6981 max = maxima[shift];
6983 /* read the rest of the number */
6985 /* x is used in the overflow test,
6986 b is the digit we're adding on. */
6991 /* if we don't mention it, we're done */
6995 /* _ are ignored -- but warned about if consecutive */
6997 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
6998 Perl_warner(aTHX_ WARN_SYNTAX,
6999 "Misplaced _ in number");
7003 /* 8 and 9 are not octal */
7006 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
7010 case '2': case '3': case '4':
7011 case '5': case '6': case '7':
7013 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
7017 b = *s++ & 15; /* ASCII digit -> value of digit */
7021 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
7022 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
7023 /* make sure they said 0x */
7028 /* Prepare to put the digit we have onto the end
7029 of the number so far. We check for overflows.
7034 x = u << shift; /* make room for the digit */
7036 if ((x >> shift) != u
7037 && !(PL_hints & HINT_NEW_BINARY)) {
7040 if (ckWARN_d(WARN_OVERFLOW))
7041 Perl_warner(aTHX_ WARN_OVERFLOW,
7042 "Integer overflow in %s number",
7045 u = x | b; /* add the digit to the end */
7048 n *= nvshift[shift];
7049 /* If an NV has not enough bits in its
7050 * mantissa to represent an UV this summing of
7051 * small low-order numbers is a waste of time
7052 * (because the NV cannot preserve the
7053 * low-order bits anyway): we could just
7054 * remember when did we overflow and in the
7055 * end just multiply n by the right
7063 /* if we get here, we had success: make a scalar value from
7068 /* final misplaced underbar check */
7070 if (ckWARN(WARN_SYNTAX))
7071 Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number");
7076 if (ckWARN(WARN_PORTABLE) && n > 4294967295.0)
7077 Perl_warner(aTHX_ WARN_PORTABLE,
7078 "%s number > %s non-portable",
7084 if (ckWARN(WARN_PORTABLE) && u > 0xffffffff)
7085 Perl_warner(aTHX_ WARN_PORTABLE,
7086 "%s number > %s non-portable",
7091 if (PL_hints & HINT_NEW_BINARY)
7092 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
7097 handle decimal numbers.
7098 we're also sent here when we read a 0 as the first digit
7100 case '1': case '2': case '3': case '4': case '5':
7101 case '6': case '7': case '8': case '9': case '.':
7104 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
7107 /* read next group of digits and _ and copy into d */
7108 while (isDIGIT(*s) || *s == '_') {
7109 /* skip underscores, checking for misplaced ones
7113 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
7114 Perl_warner(aTHX_ WARN_SYNTAX,
7115 "Misplaced _ in number");
7119 /* check for end of fixed-length buffer */
7121 Perl_croak(aTHX_ number_too_long);
7122 /* if we're ok, copy the character */
7127 /* final misplaced underbar check */
7128 if (lastub && s == lastub + 1) {
7129 if (ckWARN(WARN_SYNTAX))
7130 Perl_warner(aTHX_ WARN_SYNTAX, "Misplaced _ in number");
7133 /* read a decimal portion if there is one. avoid
7134 3..5 being interpreted as the number 3. followed
7137 if (*s == '.' && s[1] != '.') {
7142 if (ckWARN(WARN_SYNTAX))
7143 Perl_warner(aTHX_ WARN_SYNTAX,
7144 "Misplaced _ in number");
7148 /* copy, ignoring underbars, until we run out of digits.
7150 for (; isDIGIT(*s) || *s == '_'; s++) {
7151 /* fixed length buffer check */
7153 Perl_croak(aTHX_ number_too_long);
7155 if (ckWARN(WARN_SYNTAX) && lastub && s == lastub + 1)
7156 Perl_warner(aTHX_ WARN_SYNTAX,
7157 "Misplaced _ in number");
7163 /* fractional part ending in underbar? */
7165 if (ckWARN(WARN_SYNTAX))
7166 Perl_warner(aTHX_ WARN_SYNTAX,
7167 "Misplaced _ in number");
7169 if (*s == '.' && isDIGIT(s[1])) {
7170 /* oops, it's really a v-string, but without the "v" */
7176 /* read exponent part, if present */
7177 if (*s && strchr("eE",*s) && strchr("+-0123456789_", s[1])) {
7181 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
7182 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
7184 /* stray preinitial _ */
7186 if (ckWARN(WARN_SYNTAX))
7187 Perl_warner(aTHX_ WARN_SYNTAX,
7188 "Misplaced _ in number");
7192 /* allow positive or negative exponent */
7193 if (*s == '+' || *s == '-')
7196 /* stray initial _ */
7198 if (ckWARN(WARN_SYNTAX))
7199 Perl_warner(aTHX_ WARN_SYNTAX,
7200 "Misplaced _ in number");
7204 /* read digits of exponent */
7205 while (isDIGIT(*s) || *s == '_') {
7208 Perl_croak(aTHX_ number_too_long);
7212 if (ckWARN(WARN_SYNTAX) &&
7213 ((lastub && s == lastub + 1) ||
7214 (!isDIGIT(s[1]) && s[1] != '_')))
7215 Perl_warner(aTHX_ WARN_SYNTAX,
7216 "Misplaced _ in number");
7222 /* terminate the string */
7225 /* make an sv from the string */
7228 #if defined(Strtol) && defined(Strtoul)
7231 strtol/strtoll sets errno to ERANGE if the number is too big
7232 for an integer. We try to do an integer conversion first
7233 if no characters indicating "float" have been found.
7240 if (*PL_tokenbuf == '-')
7241 iv = Strtol(PL_tokenbuf, (char**)NULL, 10);
7243 uv = Strtoul(PL_tokenbuf, (char**)NULL, 10);
7245 floatit = TRUE; /* Probably just too large. */
7246 else if (*PL_tokenbuf == '-')
7248 else if (uv <= IV_MAX)
7249 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
7254 nv = Atof(PL_tokenbuf);
7259 No working strtou?ll?.
7261 Unfortunately atol() doesn't do range checks (returning
7262 LONG_MIN/LONG_MAX, and setting errno to ERANGE on overflows)
7263 everywhere [1], so we cannot use use atol() (or atoll()).
7264 If we could, they would be used, as Atol(), very much like
7265 Strtol() and Strtoul() are used above.
7267 [1] XXX Configure test needed to check for atol()
7268 (and atoll()) overflow behaviour XXX
7272 We need to do this the hard way. */
7274 nv = Atof(PL_tokenbuf);
7276 /* See if we can make do with an integer value without loss of
7277 precision. We use U_V to cast to a UV, because some
7278 compilers have issues. Then we try casting it back and see
7279 if it was the same [1]. We only do this if we know we
7280 specifically read an integer. If floatit is true, then we
7281 don't need to do the conversion at all.
7283 [1] Note that this is lossy if our NVs cannot preserve our
7284 UVs. There are metaconfig defines NV_PRESERVES_UV (a boolean)
7285 and NV_PRESERVES_UV_BITS (a number), but in general we really
7286 do hope all such potentially lossy platforms have strtou?ll?
7287 to do a lossless IV/UV conversion.
7289 Maybe could do some tricks with DBL_DIG, LDBL_DIG and
7290 DBL_MANT_DIG and LDBL_MANT_DIG (these are already available
7291 as NV_DIG and NV_MANT_DIG)?
7297 if (!floatit && (NV)uv == nv) {
7299 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
7307 if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
7308 (PL_hints & HINT_NEW_INTEGER) )
7309 sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
7310 (floatit ? "float" : "integer"),
7314 /* if it starts with a v, it could be a v-string */
7320 while (isDIGIT(*pos) || *pos == '_')
7322 if (!isALPHA(*pos)) {
7324 U8 tmpbuf[UTF8_MAXLEN+1];
7326 s++; /* get past 'v' */
7329 sv_setpvn(sv, "", 0);
7332 if (*s == '0' && isDIGIT(s[1]))
7333 yyerror("Octal number in vector unsupported");
7336 /* this is atoi() that tolerates underscores */
7339 while (--end >= s) {
7344 rev += (*end - '0') * mult;
7346 if (orev > rev && ckWARN_d(WARN_OVERFLOW))
7347 Perl_warner(aTHX_ WARN_OVERFLOW,
7348 "Integer overflow in decimal number");
7351 /* Append native character for the rev point */
7352 tmpend = uvchr_to_utf8(tmpbuf, rev);
7353 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
7354 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
7356 if (*pos == '.' && isDIGIT(pos[1]))
7362 while (isDIGIT(*pos) || *pos == '_')
7372 /* make the op for the constant and return */
7375 lvalp->opval = newSVOP(OP_CONST, 0, sv);
7377 lvalp->opval = Nullop;
7383 S_scan_formline(pTHX_ register char *s)
7387 SV *stuff = newSVpvn("",0);
7388 bool needargs = FALSE;
7391 if (*s == '.' || *s == /*{*/'}') {
7393 #ifdef PERL_STRICT_CR
7394 for (t = s+1;SPACE_OR_TAB(*t); t++) ;
7396 for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
7398 if (*t == '\n' || t == PL_bufend)
7401 if (PL_in_eval && !PL_rsfp) {
7402 eol = strchr(s,'\n');
7407 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
7409 for (t = s; t < eol; t++) {
7410 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
7412 goto enough; /* ~~ must be first line in formline */
7414 if (*t == '@' || *t == '^')
7417 sv_catpvn(stuff, s, eol-s);
7418 #ifndef PERL_STRICT_CR
7419 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
7420 char *end = SvPVX(stuff) + SvCUR(stuff);
7429 s = filter_gets(PL_linestr, PL_rsfp, 0);
7430 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
7431 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
7432 PL_last_lop = PL_last_uni = Nullch;
7435 yyerror("Format not terminated");
7445 PL_lex_state = LEX_NORMAL;
7446 PL_nextval[PL_nexttoke].ival = 0;
7450 PL_lex_state = LEX_FORMLINE;
7451 PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
7453 PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
7457 SvREFCNT_dec(stuff);
7458 PL_lex_formbrack = 0;
7469 PL_cshlen = strlen(PL_cshname);
7474 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
7476 I32 oldsavestack_ix = PL_savestack_ix;
7477 CV* outsidecv = PL_compcv;
7481 assert(SvTYPE(PL_compcv) == SVt_PVCV);
7483 SAVEI32(PL_subline);
7484 save_item(PL_subname);
7487 SAVESPTR(PL_comppad_name);
7488 SAVESPTR(PL_compcv);
7489 SAVEI32(PL_comppad_name_fill);
7490 SAVEI32(PL_min_intro_pending);
7491 SAVEI32(PL_max_intro_pending);
7492 SAVEI32(PL_pad_reset_pending);
7494 PL_compcv = (CV*)NEWSV(1104,0);
7495 sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
7496 CvFLAGS(PL_compcv) |= flags;
7498 PL_comppad = newAV();
7499 av_push(PL_comppad, Nullsv);
7500 PL_curpad = AvARRAY(PL_comppad);
7501 PL_comppad_name = newAV();
7502 PL_comppad_name_fill = 0;
7503 PL_min_intro_pending = 0;
7505 PL_subline = CopLINE(PL_curcop);
7507 av_store(PL_comppad_name, 0, newSVpvn("@_", 2));
7508 PL_curpad[0] = (SV*)newAV();
7509 SvPADMY_on(PL_curpad[0]); /* XXX Needed? */
7510 #endif /* USE_THREADS */
7512 comppadlist = newAV();
7513 AvREAL_off(comppadlist);
7514 av_store(comppadlist, 0, (SV*)PL_comppad_name);
7515 av_store(comppadlist, 1, (SV*)PL_comppad);
7517 CvPADLIST(PL_compcv) = comppadlist;
7518 CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
7520 CvOWNER(PL_compcv) = 0;
7521 New(666, CvMUTEXP(PL_compcv), 1, perl_mutex);
7522 MUTEX_INIT(CvMUTEXP(PL_compcv));
7523 #endif /* USE_THREADS */
7525 return oldsavestack_ix;
7529 #pragma segment Perl_yylex
7532 Perl_yywarn(pTHX_ char *s)
7534 PL_in_eval |= EVAL_WARNONLY;
7536 PL_in_eval &= ~EVAL_WARNONLY;
7541 Perl_yyerror(pTHX_ char *s)
7544 char *context = NULL;
7548 if (!yychar || (yychar == ';' && !PL_rsfp))
7550 else if (PL_bufptr > PL_oldoldbufptr && PL_bufptr - PL_oldoldbufptr < 200 &&
7551 PL_oldoldbufptr != PL_oldbufptr && PL_oldbufptr != PL_bufptr) {
7552 while (isSPACE(*PL_oldoldbufptr))
7554 context = PL_oldoldbufptr;
7555 contlen = PL_bufptr - PL_oldoldbufptr;
7557 else if (PL_bufptr > PL_oldbufptr && PL_bufptr - PL_oldbufptr < 200 &&
7558 PL_oldbufptr != PL_bufptr) {
7559 while (isSPACE(*PL_oldbufptr))
7561 context = PL_oldbufptr;
7562 contlen = PL_bufptr - PL_oldbufptr;
7564 else if (yychar > 255)
7565 where = "next token ???";
7566 #ifdef USE_PURE_BISON
7567 /* GNU Bison sets the value -2 */
7568 else if (yychar == -2) {
7570 else if ((yychar & 127) == 127) {
7572 if (PL_lex_state == LEX_NORMAL ||
7573 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
7574 where = "at end of line";
7575 else if (PL_lex_inpat)
7576 where = "within pattern";
7578 where = "within string";
7581 SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
7583 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
7584 else if (isPRINT_LC(yychar))
7585 Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
7587 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
7588 where = SvPVX(where_sv);
7590 msg = sv_2mortal(newSVpv(s, 0));
7591 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
7592 CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
7594 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
7596 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
7597 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
7598 Perl_sv_catpvf(aTHX_ msg,
7599 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
7600 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
7603 if (PL_in_eval & EVAL_WARNONLY)
7604 Perl_warn(aTHX_ "%"SVf, msg);
7607 if (PL_error_count >= 10) {
7608 if (PL_in_eval && SvCUR(ERRSV))
7609 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
7610 ERRSV, CopFILE(PL_curcop));
7612 Perl_croak(aTHX_ "%s has too many errors.\n",
7613 CopFILE(PL_curcop));
7616 PL_in_my_stash = Nullhv;
7620 #pragma segment Main
7624 S_swallow_bom(pTHX_ U8 *s)
7627 slen = SvCUR(PL_linestr);
7631 /* UTF-16 little-endian */
7632 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
7633 Perl_croak(aTHX_ "Unsupported script encoding");
7634 #ifndef PERL_NO_UTF16_FILTER
7635 DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-LE script encoding\n"));
7637 if (PL_bufend > (char*)s) {
7641 filter_add(utf16rev_textfilter, NULL);
7642 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
7643 PL_bufend = (char*)utf16_to_utf8_reversed(s, news,
7644 PL_bufend - (char*)s - 1,
7646 Copy(news, s, newlen, U8);
7647 SvCUR_set(PL_linestr, newlen);
7648 PL_bufend = SvPVX(PL_linestr) + newlen;
7649 news[newlen++] = '\0';
7653 Perl_croak(aTHX_ "Unsupported script encoding");
7658 if (s[1] == 0xFF) { /* UTF-16 big-endian */
7659 #ifndef PERL_NO_UTF16_FILTER
7660 DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding\n"));
7662 if (PL_bufend > (char *)s) {
7666 filter_add(utf16_textfilter, NULL);
7667 New(898, news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
7668 PL_bufend = (char*)utf16_to_utf8(s, news,
7669 PL_bufend - (char*)s,
7671 Copy(news, s, newlen, U8);
7672 SvCUR_set(PL_linestr, newlen);
7673 PL_bufend = SvPVX(PL_linestr) + newlen;
7674 news[newlen++] = '\0';
7678 Perl_croak(aTHX_ "Unsupported script encoding");
7683 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
7684 DEBUG_p(PerlIO_printf(Perl_debug_log, "UTF-8 script encoding\n"));
7689 if (slen > 3 && s[1] == 0 && /* UTF-32 big-endian */
7690 s[2] == 0xFE && s[3] == 0xFF)
7692 Perl_croak(aTHX_ "Unsupported script encoding");
7704 * Restore a source filter.
7708 restore_rsfp(pTHXo_ void *f)
7710 PerlIO *fp = (PerlIO*)f;
7712 if (PL_rsfp == PerlIO_stdin())
7713 PerlIO_clearerr(PL_rsfp);
7714 else if (PL_rsfp && (PL_rsfp != fp))
7715 PerlIO_close(PL_rsfp);
7719 #ifndef PERL_NO_UTF16_FILTER
7721 utf16_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
7723 I32 count = FILTER_READ(idx+1, sv, maxlen);
7728 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
7729 if (!*SvPV_nolen(sv))
7730 /* Game over, but don't feed an odd-length string to utf16_to_utf8 */
7733 tend = utf16_to_utf8((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen);
7734 sv_usepvn(sv, (char*)tmps, tend - tmps);
7740 utf16rev_textfilter(pTHXo_ int idx, SV *sv, int maxlen)
7742 I32 count = FILTER_READ(idx+1, sv, maxlen);
7747 if (!*SvPV_nolen(sv))
7748 /* Game over, but don't feed an odd-length string to utf16_to_utf8 */
7751 New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8);
7752 tend = utf16_to_utf8_reversed((U8*)SvPVX(sv), tmps, SvCUR(sv), &newlen);
7753 sv_usepvn(sv, (char*)tmps, tend - tmps);