This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
99757a6e6fbd75aa925b345dc2d100caa98e6e96
[perl5.git] / toke.c
1 /*    toke.c
2  *
3  *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4  *    2000, 2001, 2002, 2003, 2004, 2005, by Larry Wall and others
5  *
6  *    You may distribute under the terms of either the GNU General Public
7  *    License or the Artistic License, as specified in the README file.
8  *
9  */
10
11 /*
12  *   "It all comes from here, the stench and the peril."  --Frodo
13  */
14
15 /*
16  * This file is the lexer for Perl.  It's closely linked to the
17  * parser, perly.y.
18  *
19  * The main routine is yylex(), which returns the next token.
20  */
21
22 #include "EXTERN.h"
23 #define PERL_IN_TOKE_C
24 #include "perl.h"
25
26 #define yychar  (*PL_yycharp)
27 #define yylval  (*PL_yylvalp)
28
29 static char ident_too_long[] = "Identifier too long";
30 static char c_without_g[] = "Use of /c modifier is meaningless without /g";
31 static char c_in_subst[] = "Use of /c modifier is meaningless in s///";
32
33 static void restore_rsfp(pTHX_ void *f);
34 #ifndef PERL_NO_UTF16_FILTER
35 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
36 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
37 #endif
38
39 #define XFAKEBRACK 128
40 #define XENUMMASK 127
41
42 #ifdef USE_UTF8_SCRIPTS
43 #   define UTF (!IN_BYTES)
44 #else
45 #   define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
46 #endif
47
48 /* In variables named $^X, these are the legal values for X.
49  * 1999-02-27 mjd-perl-patch@plover.com */
50 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
51
52 /* On MacOS, respect nonbreaking spaces */
53 #ifdef MACOS_TRADITIONAL
54 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
55 #else
56 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
57 #endif
58
59 /* LEX_* are values for PL_lex_state, the state of the lexer.
60  * They are arranged oddly so that the guard on the switch statement
61  * can get by with a single comparison (if the compiler is smart enough).
62  */
63
64 /* #define LEX_NOTPARSING               11 is done in perl.h. */
65
66 #define LEX_NORMAL              10
67 #define LEX_INTERPNORMAL         9
68 #define LEX_INTERPCASEMOD        8
69 #define LEX_INTERPPUSH           7
70 #define LEX_INTERPSTART          6
71 #define LEX_INTERPEND            5
72 #define LEX_INTERPENDMAYBE       4
73 #define LEX_INTERPCONCAT         3
74 #define LEX_INTERPCONST          2
75 #define LEX_FORMLINE             1
76 #define LEX_KNOWNEXT             0
77
78 #ifdef DEBUGGING
79 static char* lex_state_names[] = {
80     "KNOWNEXT",
81     "FORMLINE",
82     "INTERPCONST",
83     "INTERPCONCAT",
84     "INTERPENDMAYBE",
85     "INTERPEND",
86     "INTERPSTART",
87     "INTERPPUSH",
88     "INTERPCASEMOD",
89     "INTERPNORMAL",
90     "NORMAL"
91 };
92 #endif
93
94 #ifdef ff_next
95 #undef ff_next
96 #endif
97
98 #include "keywords.h"
99
100 /* CLINE is a macro that ensures PL_copline has a sane value */
101
102 #ifdef CLINE
103 #undef CLINE
104 #endif
105 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
106
107 /*
108  * Convenience functions to return different tokens and prime the
109  * lexer for the next token.  They all take an argument.
110  *
111  * TOKEN        : generic token (used for '(', DOLSHARP, etc)
112  * OPERATOR     : generic operator
113  * AOPERATOR    : assignment operator
114  * PREBLOCK     : beginning the block after an if, while, foreach, ...
115  * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
116  * PREREF       : *EXPR where EXPR is not a simple identifier
117  * TERM         : expression term
118  * LOOPX        : loop exiting command (goto, last, dump, etc)
119  * FTST         : file test operator
120  * FUN0         : zero-argument function
121  * FUN1         : not used, except for not, which isn't a UNIOP
122  * BOop         : bitwise or or xor
123  * BAop         : bitwise and
124  * SHop         : shift operator
125  * PWop         : power operator
126  * PMop         : pattern-matching operator
127  * Aop          : addition-level operator
128  * Mop          : multiplication-level operator
129  * Eop          : equality-testing operator
130  * Rop          : relational operator <= != gt
131  *
132  * Also see LOP and lop() below.
133  */
134
135 #ifdef DEBUGGING /* Serve -DT. */
136 #   define REPORT(retval) tokereport(s,(int)retval)
137 #else
138 #   define REPORT(retval) (retval)
139 #endif
140
141 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
142 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
143 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
144 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
145 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
146 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
147 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
148 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
149 #define FTST(f)  return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
150 #define FUN0(f)  return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
151 #define FUN1(f)  return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
152 #define BOop(f)  return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
153 #define BAop(f)  return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
154 #define SHop(f)  return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
155 #define PWop(f)  return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
156 #define PMop(f)  return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
157 #define Aop(f)   return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
158 #define Mop(f)   return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
159 #define Eop(f)   return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
160 #define Rop(f)   return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
161
162 /* This bit of chicanery makes a unary function followed by
163  * a parenthesis into a function with one argument, highest precedence.
164  * The UNIDOR macro is for unary functions that can be followed by the //
165  * operator (such as C<shift // 0>).
166  */
167 #define UNI2(f,x) return ( \
168         yylval.ival = f, \
169         PL_expect = x, \
170         PL_bufptr = s, \
171         PL_last_uni = PL_oldbufptr, \
172         PL_last_lop_op = f, \
173         REPORT( \
174             (*s == '(' || (s = skipspace(s), *s == '(')  \
175             ? (int)FUNC1 : (int)UNIOP)))
176 #define UNI(f)    UNI2(f,XTERM)
177 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
178
179 #define UNIBRACK(f) return ( \
180         yylval.ival = f, \
181         PL_bufptr = s, \
182         PL_last_uni = PL_oldbufptr, \
183         REPORT( \
184             (*s == '(' || (s = skipspace(s), *s == '(') \
185         ? (int)FUNC1 : (int)UNIOP)))
186
187 /* grandfather return to old style */
188 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
189
190 #ifdef DEBUGGING
191
192 /* how to interpret the yylval associated with the token */
193 enum token_type {
194     TOKENTYPE_NONE,
195     TOKENTYPE_IVAL,
196     TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
197     TOKENTYPE_PVAL,
198     TOKENTYPE_OPVAL,
199     TOKENTYPE_GVVAL
200 };
201
202 static struct debug_tokens { int token, type; char *name;} debug_tokens[] =
203 {
204     { ADDOP,            TOKENTYPE_OPNUM,        "ADDOP" },
205     { ANDAND,           TOKENTYPE_NONE,         "ANDAND" },
206     { ANDOP,            TOKENTYPE_NONE,         "ANDOP" },
207     { ANONSUB,          TOKENTYPE_IVAL,         "ANONSUB" },
208     { ARROW,            TOKENTYPE_NONE,         "ARROW" },
209     { ASSIGNOP,         TOKENTYPE_OPNUM,        "ASSIGNOP" },
210     { BITANDOP,         TOKENTYPE_OPNUM,        "BITANDOP" },
211     { BITOROP,          TOKENTYPE_OPNUM,        "BITOROP" },
212     { COLONATTR,        TOKENTYPE_NONE,         "COLONATTR" },
213     { CONTINUE,         TOKENTYPE_NONE,         "CONTINUE" },
214     { DO,               TOKENTYPE_NONE,         "DO" },
215     { DOLSHARP,         TOKENTYPE_NONE,         "DOLSHARP" },
216     { DORDOR,           TOKENTYPE_NONE,         "DORDOR" },
217     { DOROP,            TOKENTYPE_OPNUM,        "DOROP" },
218     { DOTDOT,           TOKENTYPE_IVAL,         "DOTDOT" },
219     { ELSE,             TOKENTYPE_NONE,         "ELSE" },
220     { ELSIF,            TOKENTYPE_IVAL,         "ELSIF" },
221     { EQOP,             TOKENTYPE_OPNUM,        "EQOP" },
222     { FOR,              TOKENTYPE_IVAL,         "FOR" },
223     { FORMAT,           TOKENTYPE_NONE,         "FORMAT" },
224     { FUNC,             TOKENTYPE_OPNUM,        "FUNC" },
225     { FUNC0,            TOKENTYPE_OPNUM,        "FUNC0" },
226     { FUNC0SUB,         TOKENTYPE_OPVAL,        "FUNC0SUB" },
227     { FUNC1,            TOKENTYPE_OPNUM,        "FUNC1" },
228     { FUNCMETH,         TOKENTYPE_OPVAL,        "FUNCMETH" },
229     { HASHBRACK,        TOKENTYPE_NONE,         "HASHBRACK" },
230     { IF,               TOKENTYPE_IVAL,         "IF" },
231     { LABEL,            TOKENTYPE_PVAL,         "LABEL" },
232     { LOCAL,            TOKENTYPE_IVAL,         "LOCAL" },
233     { LOOPEX,           TOKENTYPE_OPNUM,        "LOOPEX" },
234     { LSTOP,            TOKENTYPE_OPNUM,        "LSTOP" },
235     { LSTOPSUB,         TOKENTYPE_OPVAL,        "LSTOPSUB" },
236     { MATCHOP,          TOKENTYPE_OPNUM,        "MATCHOP" },
237     { METHOD,           TOKENTYPE_OPVAL,        "METHOD" },
238     { MULOP,            TOKENTYPE_OPNUM,        "MULOP" },
239     { MY,               TOKENTYPE_IVAL,         "MY" },
240     { MYSUB,            TOKENTYPE_NONE,         "MYSUB" },
241     { NOAMP,            TOKENTYPE_NONE,         "NOAMP" },
242     { NOTOP,            TOKENTYPE_NONE,         "NOTOP" },
243     { OROP,             TOKENTYPE_IVAL,         "OROP" },
244     { OROR,             TOKENTYPE_NONE,         "OROR" },
245     { PACKAGE,          TOKENTYPE_NONE,         "PACKAGE" },
246     { PMFUNC,           TOKENTYPE_OPVAL,        "PMFUNC" },
247     { POSTDEC,          TOKENTYPE_NONE,         "POSTDEC" },
248     { POSTINC,          TOKENTYPE_NONE,         "POSTINC" },
249     { POWOP,            TOKENTYPE_OPNUM,        "POWOP" },
250     { PREDEC,           TOKENTYPE_NONE,         "PREDEC" },
251     { PREINC,           TOKENTYPE_NONE,         "PREINC" },
252     { PRIVATEREF,       TOKENTYPE_OPVAL,        "PRIVATEREF" },
253     { REFGEN,           TOKENTYPE_NONE,         "REFGEN" },
254     { RELOP,            TOKENTYPE_OPNUM,        "RELOP" },
255     { SHIFTOP,          TOKENTYPE_OPNUM,        "SHIFTOP" },
256     { SUB,              TOKENTYPE_NONE,         "SUB" },
257     { THING,            TOKENTYPE_OPVAL,        "THING" },
258     { UMINUS,           TOKENTYPE_NONE,         "UMINUS" },
259     { UNIOP,            TOKENTYPE_OPNUM,        "UNIOP" },
260     { UNIOPSUB,         TOKENTYPE_OPVAL,        "UNIOPSUB" },
261     { UNLESS,           TOKENTYPE_IVAL,         "UNLESS" },
262     { UNTIL,            TOKENTYPE_IVAL,         "UNTIL" },
263     { USE,              TOKENTYPE_IVAL,         "USE" },
264     { WHILE,            TOKENTYPE_IVAL,         "WHILE" },
265     { WORD,             TOKENTYPE_OPVAL,        "WORD" },
266     { 0,                TOKENTYPE_NONE,         0 }
267 };
268
269 /* dump the returned token in rv, plus any optional arg in yylval */
270
271 STATIC int
272 S_tokereport(pTHX_ char* s, I32 rv)
273 {
274     if (DEBUG_T_TEST) {
275         char *name = Nullch;
276         enum token_type type = TOKENTYPE_NONE;
277         struct debug_tokens *p;
278         SV* report = NEWSV(0, 60);
279
280         Perl_sv_catpvf(aTHX_ report, "<== ");
281
282         for (p = debug_tokens; p->token; p++) {
283             if (p->token == (int)rv) {
284                 name = p->name;
285                 type = p->type;
286                 break;
287             }
288         }
289         if (name)
290             Perl_sv_catpvf(aTHX_ report, "%s", name);
291         else if ((char)rv > ' ' && (char)rv < '~')
292             Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
293         else if (!rv)
294             Perl_sv_catpvf(aTHX_ report, "EOF");
295         else
296             Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
297         switch (type) {
298         case TOKENTYPE_NONE:
299         case TOKENTYPE_GVVAL: /* doesn't appear to be used */
300             break;
301         case TOKENTYPE_IVAL:
302             Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", yylval.ival);
303             break;
304         case TOKENTYPE_OPNUM:
305             Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
306                                     PL_op_name[yylval.ival]);
307             break;
308         case TOKENTYPE_PVAL:
309             Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
310             break;
311         case TOKENTYPE_OPVAL:
312             if (yylval.opval)
313                 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
314                                     PL_op_name[yylval.opval->op_type]);
315             else
316                 Perl_sv_catpv(aTHX_ report, "(opval=null)");
317             break;
318         }
319         Perl_sv_catpvf(aTHX_ report, " at line %d [", CopLINE(PL_curcop));
320         if (s - PL_bufptr > 0)
321             sv_catpvn(report, PL_bufptr, s - PL_bufptr);
322         else {
323             if (PL_oldbufptr && *PL_oldbufptr)
324                 sv_catpv(report, PL_tokenbuf);
325         }
326         PerlIO_printf(Perl_debug_log, "### %s]\n", SvPV_nolen(report));
327     };
328     return (int)rv;
329 }
330
331 #endif
332
333 /*
334  * S_ao
335  *
336  * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
337  * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
338  */
339
340 STATIC int
341 S_ao(pTHX_ int toketype)
342 {
343     if (*PL_bufptr == '=') {
344         PL_bufptr++;
345         if (toketype == ANDAND)
346             yylval.ival = OP_ANDASSIGN;
347         else if (toketype == OROR)
348             yylval.ival = OP_ORASSIGN;
349         else if (toketype == DORDOR)
350             yylval.ival = OP_DORASSIGN;
351         toketype = ASSIGNOP;
352     }
353     return toketype;
354 }
355
356 /*
357  * S_no_op
358  * When Perl expects an operator and finds something else, no_op
359  * prints the warning.  It always prints "<something> found where
360  * operator expected.  It prints "Missing semicolon on previous line?"
361  * if the surprise occurs at the start of the line.  "do you need to
362  * predeclare ..." is printed out for code like "sub bar; foo bar $x"
363  * where the compiler doesn't know if foo is a method call or a function.
364  * It prints "Missing operator before end of line" if there's nothing
365  * after the missing operator, or "... before <...>" if there is something
366  * after the missing operator.
367  */
368
369 STATIC void
370 S_no_op(pTHX_ char *what, char *s)
371 {
372     char *oldbp = PL_bufptr;
373     bool is_first = (PL_oldbufptr == PL_linestart);
374
375     if (!s)
376         s = oldbp;
377     else
378         PL_bufptr = s;
379     yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
380     if (ckWARN_d(WARN_SYNTAX)) {
381         if (is_first)
382             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
383                     "\t(Missing semicolon on previous line?)\n");
384         else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
385             char *t;
386             for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
387             if (t < PL_bufptr && isSPACE(*t))
388                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
389                         "\t(Do you need to predeclare %.*s?)\n",
390                     t - PL_oldoldbufptr, PL_oldoldbufptr);
391         }
392         else {
393             assert(s >= oldbp);
394             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
395                     "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
396         }
397     }
398     PL_bufptr = oldbp;
399 }
400
401 /*
402  * S_missingterm
403  * Complain about missing quote/regexp/heredoc terminator.
404  * If it's called with (char *)NULL then it cauterizes the line buffer.
405  * If we're in a delimited string and the delimiter is a control
406  * character, it's reformatted into a two-char sequence like ^C.
407  * This is fatal.
408  */
409
410 STATIC void
411 S_missingterm(pTHX_ char *s)
412 {
413     char tmpbuf[3];
414     char q;
415     if (s) {
416         char *nl = strrchr(s,'\n');
417         if (nl)
418             *nl = '\0';
419     }
420     else if (
421 #ifdef EBCDIC
422         iscntrl(PL_multi_close)
423 #else
424         PL_multi_close < 32 || PL_multi_close == 127
425 #endif
426         ) {
427         *tmpbuf = '^';
428         tmpbuf[1] = toCTRL(PL_multi_close);
429         s = "\\n";
430         tmpbuf[2] = '\0';
431         s = tmpbuf;
432     }
433     else {
434         *tmpbuf = (char)PL_multi_close;
435         tmpbuf[1] = '\0';
436         s = tmpbuf;
437     }
438     q = strchr(s,'"') ? '\'' : '"';
439     Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
440 }
441
442 /*
443  * Perl_deprecate
444  */
445
446 void
447 Perl_deprecate(pTHX_ char *s)
448 {
449     if (ckWARN(WARN_DEPRECATED))
450         Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
451 }
452
453 void
454 Perl_deprecate_old(pTHX_ char *s)
455 {
456     /* This function should NOT be called for any new deprecated warnings */
457     /* Use Perl_deprecate instead                                         */
458     /*                                                                    */
459     /* It is here to maintain backward compatibility with the pre-5.8     */
460     /* warnings category hierarchy. The "deprecated" category used to     */
461     /* live under the "syntax" category. It is now a top-level category   */
462     /* in its own right.                                                  */
463
464     if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
465         Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX), 
466                         "Use of %s is deprecated", s);
467 }
468
469 /*
470  * depcom
471  * Deprecate a comma-less variable list.
472  */
473
474 STATIC void
475 S_depcom(pTHX)
476 {
477     deprecate_old("comma-less variable list");
478 }
479
480 /*
481  * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
482  * utf16-to-utf8-reversed.
483  */
484
485 #ifdef PERL_CR_FILTER
486 static void
487 strip_return(SV *sv)
488 {
489     register char *s = SvPVX(sv);
490     register char *e = s + SvCUR(sv);
491     /* outer loop optimized to do nothing if there are no CR-LFs */
492     while (s < e) {
493         if (*s++ == '\r' && *s == '\n') {
494             /* hit a CR-LF, need to copy the rest */
495             register char *d = s - 1;
496             *d++ = *s++;
497             while (s < e) {
498                 if (*s == '\r' && s[1] == '\n')
499                     s++;
500                 *d++ = *s++;
501             }
502             SvCUR(sv) -= s - d;
503             return;
504         }
505     }
506 }
507
508 STATIC I32
509 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
510 {
511     I32 count = FILTER_READ(idx+1, sv, maxlen);
512     if (count > 0 && !maxlen)
513         strip_return(sv);
514     return count;
515 }
516 #endif
517
518 /*
519  * Perl_lex_start
520  * Initialize variables.  Uses the Perl save_stack to save its state (for
521  * recursive calls to the parser).
522  */
523
524 void
525 Perl_lex_start(pTHX_ SV *line)
526 {
527     char *s;
528     STRLEN len;
529
530     SAVEI32(PL_lex_dojoin);
531     SAVEI32(PL_lex_brackets);
532     SAVEI32(PL_lex_casemods);
533     SAVEI32(PL_lex_starts);
534     SAVEI32(PL_lex_state);
535     SAVEVPTR(PL_lex_inpat);
536     SAVEI32(PL_lex_inwhat);
537     if (PL_lex_state == LEX_KNOWNEXT) {
538         I32 toke = PL_nexttoke;
539         while (--toke >= 0) {
540             SAVEI32(PL_nexttype[toke]);
541             SAVEVPTR(PL_nextval[toke]);
542         }
543         SAVEI32(PL_nexttoke);
544     }
545     SAVECOPLINE(PL_curcop);
546     SAVEPPTR(PL_bufptr);
547     SAVEPPTR(PL_bufend);
548     SAVEPPTR(PL_oldbufptr);
549     SAVEPPTR(PL_oldoldbufptr);
550     SAVEPPTR(PL_last_lop);
551     SAVEPPTR(PL_last_uni);
552     SAVEPPTR(PL_linestart);
553     SAVESPTR(PL_linestr);
554     SAVEGENERICPV(PL_lex_brackstack);
555     SAVEGENERICPV(PL_lex_casestack);
556     SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
557     SAVESPTR(PL_lex_stuff);
558     SAVEI32(PL_lex_defer);
559     SAVEI32(PL_sublex_info.sub_inwhat);
560     SAVESPTR(PL_lex_repl);
561     SAVEINT(PL_expect);
562     SAVEINT(PL_lex_expect);
563
564     PL_lex_state = LEX_NORMAL;
565     PL_lex_defer = 0;
566     PL_expect = XSTATE;
567     PL_lex_brackets = 0;
568     New(899, PL_lex_brackstack, 120, char);
569     New(899, PL_lex_casestack, 12, char);
570     PL_lex_casemods = 0;
571     *PL_lex_casestack = '\0';
572     PL_lex_dojoin = 0;
573     PL_lex_starts = 0;
574     PL_lex_stuff = Nullsv;
575     PL_lex_repl = Nullsv;
576     PL_lex_inpat = 0;
577     PL_nexttoke = 0;
578     PL_lex_inwhat = 0;
579     PL_sublex_info.sub_inwhat = 0;
580     PL_linestr = line;
581     if (SvREADONLY(PL_linestr))
582         PL_linestr = sv_2mortal(newSVsv(PL_linestr));
583     s = SvPV(PL_linestr, len);
584     if (!len || s[len-1] != ';') {
585         if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
586             PL_linestr = sv_2mortal(newSVsv(PL_linestr));
587         sv_catpvn(PL_linestr, "\n;", 2);
588     }
589     SvTEMP_off(PL_linestr);
590     PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
591     PL_bufend = PL_bufptr + SvCUR(PL_linestr);
592     PL_last_lop = PL_last_uni = Nullch;
593     PL_rsfp = 0;
594 }
595
596 /*
597  * Perl_lex_end
598  * Finalizer for lexing operations.  Must be called when the parser is
599  * done with the lexer.
600  */
601
602 void
603 Perl_lex_end(pTHX)
604 {
605     PL_doextract = FALSE;
606 }
607
608 /*
609  * S_incline
610  * This subroutine has nothing to do with tilting, whether at windmills
611  * or pinball tables.  Its name is short for "increment line".  It
612  * increments the current line number in CopLINE(PL_curcop) and checks
613  * to see whether the line starts with a comment of the form
614  *    # line 500 "foo.pm"
615  * If so, it sets the current line number and file to the values in the comment.
616  */
617
618 STATIC void
619 S_incline(pTHX_ char *s)
620 {
621     char *t;
622     char *n;
623     char *e;
624     char ch;
625
626     CopLINE_inc(PL_curcop);
627     if (*s++ != '#')
628         return;
629     while (SPACE_OR_TAB(*s)) s++;
630     if (strnEQ(s, "line", 4))
631         s += 4;
632     else
633         return;
634     if (SPACE_OR_TAB(*s))
635         s++;
636     else
637         return;
638     while (SPACE_OR_TAB(*s)) s++;
639     if (!isDIGIT(*s))
640         return;
641     n = s;
642     while (isDIGIT(*s))
643         s++;
644     while (SPACE_OR_TAB(*s))
645         s++;
646     if (*s == '"' && (t = strchr(s+1, '"'))) {
647         s++;
648         e = t + 1;
649     }
650     else {
651         for (t = s; !isSPACE(*t); t++) ;
652         e = t;
653     }
654     while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
655         e++;
656     if (*e != '\n' && *e != '\0')
657         return;         /* false alarm */
658
659     ch = *t;
660     *t = '\0';
661     if (t - s > 0) {
662         CopFILE_free(PL_curcop);
663         CopFILE_set(PL_curcop, s);
664     }
665     *t = ch;
666     CopLINE_set(PL_curcop, atoi(n)-1);
667 }
668
669 /*
670  * S_skipspace
671  * Called to gobble the appropriate amount and type of whitespace.
672  * Skips comments as well.
673  */
674
675 STATIC char *
676 S_skipspace(pTHX_ register char *s)
677 {
678     if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
679         while (s < PL_bufend && SPACE_OR_TAB(*s))
680             s++;
681         return s;
682     }
683     for (;;) {
684         STRLEN prevlen;
685         SSize_t oldprevlen, oldoldprevlen;
686         SSize_t oldloplen = 0, oldunilen = 0;
687         while (s < PL_bufend && isSPACE(*s)) {
688             if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
689                 incline(s);
690         }
691
692         /* comment */
693         if (s < PL_bufend && *s == '#') {
694             while (s < PL_bufend && *s != '\n')
695                 s++;
696             if (s < PL_bufend) {
697                 s++;
698                 if (PL_in_eval && !PL_rsfp) {
699                     incline(s);
700                     continue;
701                 }
702             }
703         }
704
705         /* only continue to recharge the buffer if we're at the end
706          * of the buffer, we're not reading from a source filter, and
707          * we're in normal lexing mode
708          */
709         if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
710                 PL_lex_state == LEX_FORMLINE)
711             return s;
712
713         /* try to recharge the buffer */
714         if ((s = filter_gets(PL_linestr, PL_rsfp,
715                              (prevlen = SvCUR(PL_linestr)))) == Nullch)
716         {
717             /* end of file.  Add on the -p or -n magic */
718             if (PL_minus_p) {
719                 sv_setpv(PL_linestr,
720                          ";}continue{print or die qq(-p destination: $!\\n);}");
721                 PL_minus_n = PL_minus_p = 0;
722             }
723             else if (PL_minus_n) {
724                 sv_setpvn(PL_linestr, ";}", 2);
725                 PL_minus_n = 0;
726             }
727             else
728                 sv_setpvn(PL_linestr,";", 1);
729
730             /* reset variables for next time we lex */
731             PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
732                 = SvPVX(PL_linestr);
733             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
734             PL_last_lop = PL_last_uni = Nullch;
735
736             /* Close the filehandle.  Could be from -P preprocessor,
737              * STDIN, or a regular file.  If we were reading code from
738              * STDIN (because the commandline held no -e or filename)
739              * then we don't close it, we reset it so the code can
740              * read from STDIN too.
741              */
742
743             if (PL_preprocess && !PL_in_eval)
744                 (void)PerlProc_pclose(PL_rsfp);
745             else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
746                 PerlIO_clearerr(PL_rsfp);
747             else
748                 (void)PerlIO_close(PL_rsfp);
749             PL_rsfp = Nullfp;
750             return s;
751         }
752
753         /* not at end of file, so we only read another line */
754         /* make corresponding updates to old pointers, for yyerror() */
755         oldprevlen = PL_oldbufptr - PL_bufend;
756         oldoldprevlen = PL_oldoldbufptr - PL_bufend;
757         if (PL_last_uni)
758             oldunilen = PL_last_uni - PL_bufend;
759         if (PL_last_lop)
760             oldloplen = PL_last_lop - PL_bufend;
761         PL_linestart = PL_bufptr = s + prevlen;
762         PL_bufend = s + SvCUR(PL_linestr);
763         s = PL_bufptr;
764         PL_oldbufptr = s + oldprevlen;
765         PL_oldoldbufptr = s + oldoldprevlen;
766         if (PL_last_uni)
767             PL_last_uni = s + oldunilen;
768         if (PL_last_lop)
769             PL_last_lop = s + oldloplen;
770         incline(s);
771
772         /* debugger active and we're not compiling the debugger code,
773          * so store the line into the debugger's array of lines
774          */
775         if (PERLDB_LINE && PL_curstash != PL_debstash) {
776             SV *sv = NEWSV(85,0);
777
778             sv_upgrade(sv, SVt_PVMG);
779             sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
780             (void)SvIOK_on(sv);
781             SvIVX(sv) = 0;
782             av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
783         }
784     }
785 }
786
787 /*
788  * S_check_uni
789  * Check the unary operators to ensure there's no ambiguity in how they're
790  * used.  An ambiguous piece of code would be:
791  *     rand + 5
792  * This doesn't mean rand() + 5.  Because rand() is a unary operator,
793  * the +5 is its argument.
794  */
795
796 STATIC void
797 S_check_uni(pTHX)
798 {
799     char *s;
800     char *t;
801
802     if (PL_oldoldbufptr != PL_last_uni)
803         return;
804     while (isSPACE(*PL_last_uni))
805         PL_last_uni++;
806     for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
807     if ((t = strchr(s, '(')) && t < PL_bufptr)
808         return;
809     if (ckWARN_d(WARN_AMBIGUOUS)){
810         char ch = *s;
811         *s = '\0';
812         Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
813                    "Warning: Use of \"%s\" without parentheses is ambiguous",
814                    PL_last_uni);
815         *s = ch;
816     }
817 }
818
819 /*
820  * LOP : macro to build a list operator.  Its behaviour has been replaced
821  * with a subroutine, S_lop() for which LOP is just another name.
822  */
823
824 #define LOP(f,x) return lop(f,x,s)
825
826 /*
827  * S_lop
828  * Build a list operator (or something that might be one).  The rules:
829  *  - if we have a next token, then it's a list operator [why?]
830  *  - if the next thing is an opening paren, then it's a function
831  *  - else it's a list operator
832  */
833
834 STATIC I32
835 S_lop(pTHX_ I32 f, int x, char *s)
836 {
837     yylval.ival = f;
838     CLINE;
839     PL_expect = x;
840     PL_bufptr = s;
841     PL_last_lop = PL_oldbufptr;
842     PL_last_lop_op = (OPCODE)f;
843     if (PL_nexttoke)
844         return REPORT(LSTOP);
845     if (*s == '(')
846         return REPORT(FUNC);
847     s = skipspace(s);
848     if (*s == '(')
849         return REPORT(FUNC);
850     else
851         return REPORT(LSTOP);
852 }
853
854 /*
855  * S_force_next
856  * When the lexer realizes it knows the next token (for instance,
857  * it is reordering tokens for the parser) then it can call S_force_next
858  * to know what token to return the next time the lexer is called.  Caller
859  * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer
860  * handles the token correctly.
861  */
862
863 STATIC void
864 S_force_next(pTHX_ I32 type)
865 {
866     PL_nexttype[PL_nexttoke] = type;
867     PL_nexttoke++;
868     if (PL_lex_state != LEX_KNOWNEXT) {
869         PL_lex_defer = PL_lex_state;
870         PL_lex_expect = PL_expect;
871         PL_lex_state = LEX_KNOWNEXT;
872     }
873 }
874
875 /*
876  * S_force_word
877  * When the lexer knows the next thing is a word (for instance, it has
878  * just seen -> and it knows that the next char is a word char, then
879  * it calls S_force_word to stick the next word into the PL_next lookahead.
880  *
881  * Arguments:
882  *   char *start : buffer position (must be within PL_linestr)
883  *   int token   : PL_next will be this type of bare word (e.g., METHOD,WORD)
884  *   int check_keyword : if true, Perl checks to make sure the word isn't
885  *       a keyword (do this if the word is a label, e.g. goto FOO)
886  *   int allow_pack : if true, : characters will also be allowed (require,
887  *       use, etc. do this)
888  *   int allow_initial_tick : used by the "sub" lexer only.
889  */
890
891 STATIC char *
892 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
893 {
894     register char *s;
895     STRLEN len;
896
897     start = skipspace(start);
898     s = start;
899     if (isIDFIRST_lazy_if(s,UTF) ||
900         (allow_pack && *s == ':') ||
901         (allow_initial_tick && *s == '\'') )
902     {
903         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
904         if (check_keyword && keyword(PL_tokenbuf, len))
905             return start;
906         if (token == METHOD) {
907             s = skipspace(s);
908             if (*s == '(')
909                 PL_expect = XTERM;
910             else {
911                 PL_expect = XOPERATOR;
912             }
913         }
914         PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST,0, newSVpv(PL_tokenbuf,0));
915         PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
916         if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
917             SvUTF8_on(((SVOP*)PL_nextval[PL_nexttoke].opval)->op_sv);
918         force_next(token);
919     }
920     return s;
921 }
922
923 /*
924  * S_force_ident
925  * Called when the lexer wants $foo *foo &foo etc, but the program
926  * text only contains the "foo" portion.  The first argument is a pointer
927  * to the "foo", and the second argument is the type symbol to prefix.
928  * Forces the next token to be a "WORD".
929  * Creates the symbol if it didn't already exist (via gv_fetchpv()).
930  */
931
932 STATIC void
933 S_force_ident(pTHX_ register char *s, int kind)
934 {
935     if (s && *s) {
936         OP* o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
937         PL_nextval[PL_nexttoke].opval = o;
938         force_next(WORD);
939         if (kind) {
940             o->op_private = OPpCONST_ENTERED;
941             /* XXX see note in pp_entereval() for why we forgo typo
942                warnings if the symbol must be introduced in an eval.
943                GSAR 96-10-12 */
944             gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
945                 kind == '$' ? SVt_PV :
946                 kind == '@' ? SVt_PVAV :
947                 kind == '%' ? SVt_PVHV :
948                               SVt_PVGV
949                 );
950         }
951     }
952 }
953
954 NV
955 Perl_str_to_version(pTHX_ SV *sv)
956 {
957     NV retval = 0.0;
958     NV nshift = 1.0;
959     STRLEN len;
960     char *start = SvPVx(sv,len);
961     bool utf = SvUTF8(sv) ? TRUE : FALSE;
962     char *end = start + len;
963     while (start < end) {
964         STRLEN skip;
965         UV n;
966         if (utf)
967             n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
968         else {
969             n = *(U8*)start;
970             skip = 1;
971         }
972         retval += ((NV)n)/nshift;
973         start += skip;
974         nshift *= 1000;
975     }
976     return retval;
977 }
978
979 /*
980  * S_force_version
981  * Forces the next token to be a version number.
982  * If the next token appears to be an invalid version number, (e.g. "v2b"),
983  * and if "guessing" is TRUE, then no new token is created (and the caller
984  * must use an alternative parsing method).
985  */
986
987 STATIC char *
988 S_force_version(pTHX_ char *s, int guessing)
989 {
990     OP *version = Nullop;
991     char *d;
992
993     s = skipspace(s);
994
995     d = s;
996     if (*d == 'v')
997         d++;
998     if (isDIGIT(*d)) {
999         while (isDIGIT(*d) || *d == '_' || *d == '.')
1000             d++;
1001         if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1002             SV *ver;
1003             s = scan_num(s, &yylval);
1004             version = yylval.opval;
1005             ver = cSVOPx(version)->op_sv;
1006             if (SvPOK(ver) && !SvNIOK(ver)) {
1007                 (void)SvUPGRADE(ver, SVt_PVNV);
1008                 SvNVX(ver) = str_to_version(ver);
1009                 SvNOK_on(ver);          /* hint that it is a version */
1010             }
1011         }
1012         else if (guessing)
1013             return s;
1014     }
1015
1016     /* NOTE: The parser sees the package name and the VERSION swapped */
1017     PL_nextval[PL_nexttoke].opval = version;
1018     force_next(WORD);
1019
1020     return s;
1021 }
1022
1023 /*
1024  * S_tokeq
1025  * Tokenize a quoted string passed in as an SV.  It finds the next
1026  * chunk, up to end of string or a backslash.  It may make a new
1027  * SV containing that chunk (if HINT_NEW_STRING is on).  It also
1028  * turns \\ into \.
1029  */
1030
1031 STATIC SV *
1032 S_tokeq(pTHX_ SV *sv)
1033 {
1034     register char *s;
1035     register char *send;
1036     register char *d;
1037     STRLEN len = 0;
1038     SV *pv = sv;
1039
1040     if (!SvLEN(sv))
1041         goto finish;
1042
1043     s = SvPV_force(sv, len);
1044     if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1045         goto finish;
1046     send = s + len;
1047     while (s < send && *s != '\\')
1048         s++;
1049     if (s == send)
1050         goto finish;
1051     d = s;
1052     if ( PL_hints & HINT_NEW_STRING ) {
1053         pv = sv_2mortal(newSVpvn(SvPVX(pv), len));
1054         if (SvUTF8(sv))
1055             SvUTF8_on(pv);
1056     }
1057     while (s < send) {
1058         if (*s == '\\') {
1059             if (s + 1 < send && (s[1] == '\\'))
1060                 s++;            /* all that, just for this */
1061         }
1062         *d++ = *s++;
1063     }
1064     *d = '\0';
1065     SvCUR_set(sv, d - SvPVX(sv));
1066   finish:
1067     if ( PL_hints & HINT_NEW_STRING )
1068        return new_constant(NULL, 0, "q", sv, pv, "q");
1069     return sv;
1070 }
1071
1072 /*
1073  * Now come three functions related to double-quote context,
1074  * S_sublex_start, S_sublex_push, and S_sublex_done.  They're used when
1075  * converting things like "\u\Lgnat" into ucfirst(lc("gnat")).  They
1076  * interact with PL_lex_state, and create fake ( ... ) argument lists
1077  * to handle functions and concatenation.
1078  * They assume that whoever calls them will be setting up a fake
1079  * join call, because each subthing puts a ',' after it.  This lets
1080  *   "lower \luPpEr"
1081  * become
1082  *  join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1083  *
1084  * (I'm not sure whether the spurious commas at the end of lcfirst's
1085  * arguments and join's arguments are created or not).
1086  */
1087
1088 /*
1089  * S_sublex_start
1090  * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1091  *
1092  * Pattern matching will set PL_lex_op to the pattern-matching op to
1093  * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1094  *
1095  * OP_CONST and OP_READLINE are easy--just make the new op and return.
1096  *
1097  * Everything else becomes a FUNC.
1098  *
1099  * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1100  * had an OP_CONST or OP_READLINE).  This just sets us up for a
1101  * call to S_sublex_push().
1102  */
1103
1104 STATIC I32
1105 S_sublex_start(pTHX)
1106 {
1107     register I32 op_type = yylval.ival;
1108
1109     if (op_type == OP_NULL) {
1110         yylval.opval = PL_lex_op;
1111         PL_lex_op = Nullop;
1112         return THING;
1113     }
1114     if (op_type == OP_CONST || op_type == OP_READLINE) {
1115         SV *sv = tokeq(PL_lex_stuff);
1116
1117         if (SvTYPE(sv) == SVt_PVIV) {
1118             /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1119             STRLEN len;
1120             char *p;
1121             SV *nsv;
1122
1123             p = SvPV(sv, len);
1124             nsv = newSVpvn(p, len);
1125             if (SvUTF8(sv))
1126                 SvUTF8_on(nsv);
1127             SvREFCNT_dec(sv);
1128             sv = nsv;
1129         }
1130         yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1131         PL_lex_stuff = Nullsv;
1132         /* Allow <FH> // "foo" */
1133         if (op_type == OP_READLINE)
1134             PL_expect = XTERMORDORDOR;
1135         return THING;
1136     }
1137
1138     PL_sublex_info.super_state = PL_lex_state;
1139     PL_sublex_info.sub_inwhat = op_type;
1140     PL_sublex_info.sub_op = PL_lex_op;
1141     PL_lex_state = LEX_INTERPPUSH;
1142
1143     PL_expect = XTERM;
1144     if (PL_lex_op) {
1145         yylval.opval = PL_lex_op;
1146         PL_lex_op = Nullop;
1147         return PMFUNC;
1148     }
1149     else
1150         return FUNC;
1151 }
1152
1153 /*
1154  * S_sublex_push
1155  * Create a new scope to save the lexing state.  The scope will be
1156  * ended in S_sublex_done.  Returns a '(', starting the function arguments
1157  * to the uc, lc, etc. found before.
1158  * Sets PL_lex_state to LEX_INTERPCONCAT.
1159  */
1160
1161 STATIC I32
1162 S_sublex_push(pTHX)
1163 {
1164     ENTER;
1165
1166     PL_lex_state = PL_sublex_info.super_state;
1167     SAVEI32(PL_lex_dojoin);
1168     SAVEI32(PL_lex_brackets);
1169     SAVEI32(PL_lex_casemods);
1170     SAVEI32(PL_lex_starts);
1171     SAVEI32(PL_lex_state);
1172     SAVEVPTR(PL_lex_inpat);
1173     SAVEI32(PL_lex_inwhat);
1174     SAVECOPLINE(PL_curcop);
1175     SAVEPPTR(PL_bufptr);
1176     SAVEPPTR(PL_bufend);
1177     SAVEPPTR(PL_oldbufptr);
1178     SAVEPPTR(PL_oldoldbufptr);
1179     SAVEPPTR(PL_last_lop);
1180     SAVEPPTR(PL_last_uni);
1181     SAVEPPTR(PL_linestart);
1182     SAVESPTR(PL_linestr);
1183     SAVEGENERICPV(PL_lex_brackstack);
1184     SAVEGENERICPV(PL_lex_casestack);
1185
1186     PL_linestr = PL_lex_stuff;
1187     PL_lex_stuff = Nullsv;
1188
1189     PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1190         = SvPVX(PL_linestr);
1191     PL_bufend += SvCUR(PL_linestr);
1192     PL_last_lop = PL_last_uni = Nullch;
1193     SAVEFREESV(PL_linestr);
1194
1195     PL_lex_dojoin = FALSE;
1196     PL_lex_brackets = 0;
1197     New(899, PL_lex_brackstack, 120, char);
1198     New(899, PL_lex_casestack, 12, char);
1199     PL_lex_casemods = 0;
1200     *PL_lex_casestack = '\0';
1201     PL_lex_starts = 0;
1202     PL_lex_state = LEX_INTERPCONCAT;
1203     CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1204
1205     PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1206     if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1207         PL_lex_inpat = PL_sublex_info.sub_op;
1208     else
1209         PL_lex_inpat = Nullop;
1210
1211     return '(';
1212 }
1213
1214 /*
1215  * S_sublex_done
1216  * Restores lexer state after a S_sublex_push.
1217  */
1218
1219 STATIC I32
1220 S_sublex_done(pTHX)
1221 {
1222     if (!PL_lex_starts++) {
1223         SV *sv = newSVpvn("",0);
1224         if (SvUTF8(PL_linestr))
1225             SvUTF8_on(sv);
1226         PL_expect = XOPERATOR;
1227         yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1228         return THING;
1229     }
1230
1231     if (PL_lex_casemods) {              /* oops, we've got some unbalanced parens */
1232         PL_lex_state = LEX_INTERPCASEMOD;
1233         return yylex();
1234     }
1235
1236     /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1237     if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1238         PL_linestr = PL_lex_repl;
1239         PL_lex_inpat = 0;
1240         PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1241         PL_bufend += SvCUR(PL_linestr);
1242         PL_last_lop = PL_last_uni = Nullch;
1243         SAVEFREESV(PL_linestr);
1244         PL_lex_dojoin = FALSE;
1245         PL_lex_brackets = 0;
1246         PL_lex_casemods = 0;
1247         *PL_lex_casestack = '\0';
1248         PL_lex_starts = 0;
1249         if (SvEVALED(PL_lex_repl)) {
1250             PL_lex_state = LEX_INTERPNORMAL;
1251             PL_lex_starts++;
1252             /*  we don't clear PL_lex_repl here, so that we can check later
1253                 whether this is an evalled subst; that means we rely on the
1254                 logic to ensure sublex_done() is called again only via the
1255                 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1256         }
1257         else {
1258             PL_lex_state = LEX_INTERPCONCAT;
1259             PL_lex_repl = Nullsv;
1260         }
1261         return ',';
1262     }
1263     else {
1264         LEAVE;
1265         PL_bufend = SvPVX(PL_linestr);
1266         PL_bufend += SvCUR(PL_linestr);
1267         PL_expect = XOPERATOR;
1268         PL_sublex_info.sub_inwhat = 0;
1269         return ')';
1270     }
1271 }
1272
1273 /*
1274   scan_const
1275
1276   Extracts a pattern, double-quoted string, or transliteration.  This
1277   is terrifying code.
1278
1279   It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1280   processing a pattern (PL_lex_inpat is true), a transliteration
1281   (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1282
1283   Returns a pointer to the character scanned up to. Iff this is
1284   advanced from the start pointer supplied (ie if anything was
1285   successfully parsed), will leave an OP for the substring scanned
1286   in yylval. Caller must intuit reason for not parsing further
1287   by looking at the next characters herself.
1288
1289   In patterns:
1290     backslashes:
1291       double-quoted style: \r and \n
1292       regexp special ones: \D \s
1293       constants: \x3
1294       backrefs: \1 (deprecated in substitution replacements)
1295       case and quoting: \U \Q \E
1296     stops on @ and $, but not for $ as tail anchor
1297
1298   In transliterations:
1299     characters are VERY literal, except for - not at the start or end
1300     of the string, which indicates a range.  scan_const expands the
1301     range to the full set of intermediate characters.
1302
1303   In double-quoted strings:
1304     backslashes:
1305       double-quoted style: \r and \n
1306       constants: \x3
1307       backrefs: \1 (deprecated)
1308       case and quoting: \U \Q \E
1309     stops on @ and $
1310
1311   scan_const does *not* construct ops to handle interpolated strings.
1312   It stops processing as soon as it finds an embedded $ or @ variable
1313   and leaves it to the caller to work out what's going on.
1314
1315   @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo.
1316
1317   $ in pattern could be $foo or could be tail anchor.  Assumption:
1318   it's a tail anchor if $ is the last thing in the string, or if it's
1319   followed by one of ")| \n\t"
1320
1321   \1 (backreferences) are turned into $1
1322
1323   The structure of the code is
1324       while (there's a character to process) {
1325           handle transliteration ranges
1326           skip regexp comments
1327           skip # initiated comments in //x patterns
1328           check for embedded @foo
1329           check for embedded scalars
1330           if (backslash) {
1331               leave intact backslashes from leave (below)
1332               deprecate \1 in strings and sub replacements
1333               handle string-changing backslashes \l \U \Q \E, etc.
1334               switch (what was escaped) {
1335                   handle - in a transliteration (becomes a literal -)
1336                   handle \132 octal characters
1337                   handle 0x15 hex characters
1338                   handle \cV (control V)
1339                   handle printf backslashes (\f, \r, \n, etc)
1340               } (end switch)
1341           } (end if backslash)
1342     } (end while character to read)
1343                 
1344 */
1345
1346 STATIC char *
1347 S_scan_const(pTHX_ char *start)
1348 {
1349     register char *send = PL_bufend;            /* end of the constant */
1350     SV *sv = NEWSV(93, send - start);           /* sv for the constant */
1351     register char *s = start;                   /* start of the constant */
1352     register char *d = SvPVX(sv);               /* destination for copies */
1353     bool dorange = FALSE;                       /* are we in a translit range? */
1354     bool didrange = FALSE;                      /* did we just finish a range? */
1355     I32  has_utf8 = FALSE;                      /* Output constant is UTF8 */
1356     I32  this_utf8 = UTF;                       /* The source string is assumed to be UTF8 */
1357     UV uv;
1358
1359     const char *leaveit =       /* set of acceptably-backslashed characters */
1360         PL_lex_inpat
1361             ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#"
1362             : "";
1363
1364     if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1365         /* If we are doing a trans and we know we want UTF8 set expectation */
1366         has_utf8   = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1367         this_utf8  = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1368     }
1369
1370
1371     while (s < send || dorange) {
1372         /* get transliterations out of the way (they're most literal) */
1373         if (PL_lex_inwhat == OP_TRANS) {
1374             /* expand a range A-Z to the full set of characters.  AIE! */
1375             if (dorange) {
1376                 I32 i;                          /* current expanded character */
1377                 I32 min;                        /* first character in range */
1378                 I32 max;                        /* last character in range */
1379
1380                 if (has_utf8) {
1381                     char *c = (char*)utf8_hop((U8*)d, -1);
1382                     char *e = d++;
1383                     while (e-- > c)
1384                         *(e + 1) = *e;
1385                     *c = (char)UTF_TO_NATIVE(0xff);
1386                     /* mark the range as done, and continue */
1387                     dorange = FALSE;
1388                     didrange = TRUE;
1389                     continue;
1390                 }
1391
1392                 i = d - SvPVX(sv);              /* remember current offset */
1393                 SvGROW(sv, SvLEN(sv) + 256);    /* never more than 256 chars in a range */
1394                 d = SvPVX(sv) + i;              /* refresh d after realloc */
1395                 d -= 2;                         /* eat the first char and the - */
1396
1397                 min = (U8)*d;                   /* first char in range */
1398                 max = (U8)d[1];                 /* last char in range  */
1399
1400                 if (min > max) {
1401                     Perl_croak(aTHX_
1402                                "Invalid range \"%c-%c\" in transliteration operator",
1403                                (char)min, (char)max);
1404                 }
1405
1406 #ifdef EBCDIC
1407                 if ((isLOWER(min) && isLOWER(max)) ||
1408                     (isUPPER(min) && isUPPER(max))) {
1409                     if (isLOWER(min)) {
1410                         for (i = min; i <= max; i++)
1411                             if (isLOWER(i))
1412                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
1413                     } else {
1414                         for (i = min; i <= max; i++)
1415                             if (isUPPER(i))
1416                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
1417                     }
1418                 }
1419                 else
1420 #endif
1421                     for (i = min; i <= max; i++)
1422                         *d++ = (char)i;
1423
1424                 /* mark the range as done, and continue */
1425                 dorange = FALSE;
1426                 didrange = TRUE;
1427                 continue;
1428             }
1429
1430             /* range begins (ignore - as first or last char) */
1431             else if (*s == '-' && s+1 < send  && s != start) {
1432                 if (didrange) {
1433                     Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1434                 }
1435                 if (has_utf8) {
1436                     *d++ = (char)UTF_TO_NATIVE(0xff);   /* use illegal utf8 byte--see pmtrans */
1437                     s++;
1438                     continue;
1439                 }
1440                 dorange = TRUE;
1441                 s++;
1442             }
1443             else {
1444                 didrange = FALSE;
1445             }
1446         }
1447
1448         /* if we get here, we're not doing a transliteration */
1449
1450         /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1451            except for the last char, which will be done separately. */
1452         else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1453             if (s[2] == '#') {
1454                 while (s+1 < send && *s != ')')
1455                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1456             }
1457             else if (s[2] == '{' /* This should match regcomp.c */
1458                      || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1459             {
1460                 I32 count = 1;
1461                 char *regparse = s + (s[2] == '{' ? 3 : 4);
1462                 char c;
1463
1464                 while (count && (c = *regparse)) {
1465                     if (c == '\\' && regparse[1])
1466                         regparse++;
1467                     else if (c == '{')
1468                         count++;
1469                     else if (c == '}')
1470                         count--;
1471                     regparse++;
1472                 }
1473                 if (*regparse != ')')
1474                     regparse--;         /* Leave one char for continuation. */
1475                 while (s < regparse)
1476                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1477             }
1478         }
1479
1480         /* likewise skip #-initiated comments in //x patterns */
1481         else if (*s == '#' && PL_lex_inpat &&
1482           ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1483             while (s+1 < send && *s != '\n')
1484                 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1485         }
1486
1487         /* check for embedded arrays
1488            (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1489            */
1490         else if (*s == '@' && s[1]
1491                  && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1492             break;
1493
1494         /* check for embedded scalars.  only stop if we're sure it's a
1495            variable.
1496         */
1497         else if (*s == '$') {
1498             if (!PL_lex_inpat)  /* not a regexp, so $ must be var */
1499                 break;
1500             if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1501                 break;          /* in regexp, $ might be tail anchor */
1502         }
1503
1504         /* End of else if chain - OP_TRANS rejoin rest */
1505
1506         /* backslashes */
1507         if (*s == '\\' && s+1 < send) {
1508             s++;
1509
1510             /* some backslashes we leave behind */
1511             if (*leaveit && *s && strchr(leaveit, *s)) {
1512                 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1513                 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1514                 continue;
1515             }
1516
1517             /* deprecate \1 in strings and substitution replacements */
1518             if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1519                 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1520             {
1521                 if (ckWARN(WARN_SYNTAX))
1522                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
1523                 *--s = '$';
1524                 break;
1525             }
1526
1527             /* string-change backslash escapes */
1528             if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1529                 --s;
1530                 break;
1531             }
1532
1533             /* if we get here, it's either a quoted -, or a digit */
1534             switch (*s) {
1535
1536             /* quoted - in transliterations */
1537             case '-':
1538                 if (PL_lex_inwhat == OP_TRANS) {
1539                     *d++ = *s++;
1540                     continue;
1541                 }
1542                 /* FALL THROUGH */
1543             default:
1544                 {
1545                     if (ckWARN(WARN_MISC) &&
1546                         isALNUM(*s) && 
1547                         *s != '_')
1548                         Perl_warner(aTHX_ packWARN(WARN_MISC),
1549                                "Unrecognized escape \\%c passed through",
1550                                *s);
1551                     /* default action is to copy the quoted character */
1552                     goto default_action;
1553                 }
1554
1555             /* \132 indicates an octal constant */
1556             case '0': case '1': case '2': case '3':
1557             case '4': case '5': case '6': case '7':
1558                 {
1559                     I32 flags = 0;
1560                     STRLEN len = 3;
1561                     uv = grok_oct(s, &len, &flags, NULL);
1562                     s += len;
1563                 }
1564                 goto NUM_ESCAPE_INSERT;
1565
1566             /* \x24 indicates a hex constant */
1567             case 'x':
1568                 ++s;
1569                 if (*s == '{') {
1570                     char* e = strchr(s, '}');
1571                     I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1572                       PERL_SCAN_DISALLOW_PREFIX;
1573                     STRLEN len;
1574
1575                     ++s;
1576                     if (!e) {
1577                         yyerror("Missing right brace on \\x{}");
1578                         continue;
1579                     }
1580                     len = e - s;
1581                     uv = grok_hex(s, &len, &flags, NULL);
1582                     s = e + 1;
1583                 }
1584                 else {
1585                     {
1586                         STRLEN len = 2;
1587                         I32 flags = PERL_SCAN_DISALLOW_PREFIX;
1588                         uv = grok_hex(s, &len, &flags, NULL);
1589                         s += len;
1590                     }
1591                 }
1592
1593               NUM_ESCAPE_INSERT:
1594                 /* Insert oct or hex escaped character.
1595                  * There will always enough room in sv since such
1596                  * escapes will be longer than any UTF-8 sequence
1597                  * they can end up as. */
1598                 
1599                 /* We need to map to chars to ASCII before doing the tests
1600                    to cover EBCDIC
1601                 */
1602                 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
1603                     if (!has_utf8 && uv > 255) {
1604                         /* Might need to recode whatever we have
1605                          * accumulated so far if it contains any
1606                          * hibit chars.
1607                          *
1608                          * (Can't we keep track of that and avoid
1609                          *  this rescan? --jhi)
1610                          */
1611                         int hicount = 0;
1612                         U8 *c;
1613                         for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
1614                             if (!NATIVE_IS_INVARIANT(*c)) {
1615                                 hicount++;
1616                             }
1617                         }
1618                         if (hicount) {
1619                             STRLEN offset = d - SvPVX(sv);
1620                             U8 *src, *dst;
1621                             d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
1622                             src = (U8 *)d - 1;
1623                             dst = src+hicount;
1624                             d  += hicount;
1625                             while (src >= (U8 *)SvPVX(sv)) {
1626                                 if (!NATIVE_IS_INVARIANT(*src)) {
1627                                     U8 ch = NATIVE_TO_ASCII(*src);
1628                                     *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
1629                                     *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
1630                                 }
1631                                 else {
1632                                     *dst-- = *src;
1633                                 }
1634                                 src--;
1635                             }
1636                         }
1637                     }
1638
1639                     if (has_utf8 || uv > 255) {
1640                         d = (char*)uvchr_to_utf8((U8*)d, uv);
1641                         has_utf8 = TRUE;
1642                         if (PL_lex_inwhat == OP_TRANS &&
1643                             PL_sublex_info.sub_op) {
1644                             PL_sublex_info.sub_op->op_private |=
1645                                 (PL_lex_repl ? OPpTRANS_FROM_UTF
1646                                              : OPpTRANS_TO_UTF);
1647                         }
1648                     }
1649                     else {
1650                         *d++ = (char)uv;
1651                     }
1652                 }
1653                 else {
1654                     *d++ = (char) uv;
1655                 }
1656                 continue;
1657
1658             /* \N{LATIN SMALL LETTER A} is a named character */
1659             case 'N':
1660                 ++s;
1661                 if (*s == '{') {
1662                     char* e = strchr(s, '}');
1663                     SV *res;
1664                     STRLEN len;
1665                     char *str;
1666
1667                     if (!e) {
1668                         yyerror("Missing right brace on \\N{}");
1669                         e = s - 1;
1670                         goto cont_scan;
1671                     }
1672                     if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
1673                         /* \N{U+...} */
1674                         I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1675                           PERL_SCAN_DISALLOW_PREFIX;
1676                         s += 3;
1677                         len = e - s;
1678                         uv = grok_hex(s, &len, &flags, NULL);
1679                         s = e + 1;
1680                         goto NUM_ESCAPE_INSERT;
1681                     }
1682                     res = newSVpvn(s + 1, e - s - 1);
1683                     res = new_constant( Nullch, 0, "charnames",
1684                                         res, Nullsv, "\\N{...}" );
1685                     if (has_utf8)
1686                         sv_utf8_upgrade(res);
1687                     str = SvPV(res,len);
1688 #ifdef EBCDIC_NEVER_MIND
1689                     /* charnames uses pack U and that has been
1690                      * recently changed to do the below uni->native
1691                      * mapping, so this would be redundant (and wrong,
1692                      * the code point would be doubly converted).
1693                      * But leave this in just in case the pack U change
1694                      * gets revoked, but the semantics is still
1695                      * desireable for charnames. --jhi */
1696                     {
1697                          UV uv = utf8_to_uvchr((U8*)str, 0);
1698
1699                          if (uv < 0x100) {
1700                               U8 tmpbuf[UTF8_MAXLEN+1], *d;
1701
1702                               d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
1703                               sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
1704                               str = SvPV(res, len);
1705                          }
1706                     }
1707 #endif
1708                     if (!has_utf8 && SvUTF8(res)) {
1709                         char *ostart = SvPVX(sv);
1710                         SvCUR_set(sv, d - ostart);
1711                         SvPOK_on(sv);
1712                         *d = '\0';
1713                         sv_utf8_upgrade(sv);
1714                         /* this just broke our allocation above... */
1715                         SvGROW(sv, (STRLEN)(send - start));
1716                         d = SvPVX(sv) + SvCUR(sv);
1717                         has_utf8 = TRUE;
1718                     }
1719                     if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
1720                         char *odest = SvPVX(sv);
1721
1722                         SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
1723                         d = SvPVX(sv) + (d - odest);
1724                     }
1725                     Copy(str, d, len, char);
1726                     d += len;
1727                     SvREFCNT_dec(res);
1728                   cont_scan:
1729                     s = e + 1;
1730                 }
1731                 else
1732                     yyerror("Missing braces on \\N{}");
1733                 continue;
1734
1735             /* \c is a control character */
1736             case 'c':
1737                 s++;
1738                 if (s < send) {
1739                     U8 c = *s++;
1740 #ifdef EBCDIC
1741                     if (isLOWER(c))
1742                         c = toUPPER(c);
1743 #endif
1744                     *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
1745                 }
1746                 else {
1747                     yyerror("Missing control char name in \\c");
1748                 }
1749                 continue;
1750
1751             /* printf-style backslashes, formfeeds, newlines, etc */
1752             case 'b':
1753                 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
1754                 break;
1755             case 'n':
1756                 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
1757                 break;
1758             case 'r':
1759                 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
1760                 break;
1761             case 'f':
1762                 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
1763                 break;
1764             case 't':
1765                 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
1766                 break;
1767             case 'e':
1768                 *d++ = ASCII_TO_NEED(has_utf8,'\033');
1769                 break;
1770             case 'a':
1771                 *d++ = ASCII_TO_NEED(has_utf8,'\007');
1772                 break;
1773             } /* end switch */
1774
1775             s++;
1776             continue;
1777         } /* end if (backslash) */
1778
1779     default_action:
1780         /* If we started with encoded form, or already know we want it
1781            and then encode the next character */
1782         if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
1783             STRLEN len  = 1;
1784             UV uv       = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
1785             STRLEN need = UNISKIP(NATIVE_TO_UNI(uv));
1786             s += len;
1787             if (need > len) {
1788                 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
1789                 STRLEN off = d - SvPVX(sv);
1790                 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
1791             }
1792             d = (char*)uvchr_to_utf8((U8*)d, uv);
1793             has_utf8 = TRUE;
1794         }
1795         else {
1796             *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1797         }
1798     } /* while loop to process each character */
1799
1800     /* terminate the string and set up the sv */
1801     *d = '\0';
1802     SvCUR_set(sv, d - SvPVX(sv));
1803     if (SvCUR(sv) >= SvLEN(sv))
1804         Perl_croak(aTHX_ "panic: constant overflowed allocated space");
1805
1806     SvPOK_on(sv);
1807     if (PL_encoding && !has_utf8) {
1808         sv_recode_to_utf8(sv, PL_encoding);
1809         if (SvUTF8(sv))
1810             has_utf8 = TRUE;
1811     }
1812     if (has_utf8) {
1813         SvUTF8_on(sv);
1814         if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1815             PL_sublex_info.sub_op->op_private |=
1816                     (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1817         }
1818     }
1819
1820     /* shrink the sv if we allocated more than we used */
1821     if (SvCUR(sv) + 5 < SvLEN(sv)) {
1822         SvLEN_set(sv, SvCUR(sv) + 1);
1823         Renew(SvPVX(sv), SvLEN(sv), char);
1824     }
1825
1826     /* return the substring (via yylval) only if we parsed anything */
1827     if (s > PL_bufptr) {
1828         if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1829             sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1830                               sv, Nullsv,
1831                               ( PL_lex_inwhat == OP_TRANS
1832                                 ? "tr"
1833                                 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1834                                     ? "s"
1835                                     : "qq")));
1836         yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1837     } else
1838         SvREFCNT_dec(sv);
1839     return s;
1840 }
1841
1842 /* S_intuit_more
1843  * Returns TRUE if there's more to the expression (e.g., a subscript),
1844  * FALSE otherwise.
1845  *
1846  * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
1847  *
1848  * ->[ and ->{ return TRUE
1849  * { and [ outside a pattern are always subscripts, so return TRUE
1850  * if we're outside a pattern and it's not { or [, then return FALSE
1851  * if we're in a pattern and the first char is a {
1852  *   {4,5} (any digits around the comma) returns FALSE
1853  * if we're in a pattern and the first char is a [
1854  *   [] returns FALSE
1855  *   [SOMETHING] has a funky algorithm to decide whether it's a
1856  *      character class or not.  It has to deal with things like
1857  *      /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
1858  * anything else returns TRUE
1859  */
1860
1861 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1862
1863 STATIC int
1864 S_intuit_more(pTHX_ register char *s)
1865 {
1866     if (PL_lex_brackets)
1867         return TRUE;
1868     if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1869         return TRUE;
1870     if (*s != '{' && *s != '[')
1871         return FALSE;
1872     if (!PL_lex_inpat)
1873         return TRUE;
1874
1875     /* In a pattern, so maybe we have {n,m}. */
1876     if (*s == '{') {
1877         s++;
1878         if (!isDIGIT(*s))
1879             return TRUE;
1880         while (isDIGIT(*s))
1881             s++;
1882         if (*s == ',')
1883             s++;
1884         while (isDIGIT(*s))
1885             s++;
1886         if (*s == '}')
1887             return FALSE;
1888         return TRUE;
1889         
1890     }
1891
1892     /* On the other hand, maybe we have a character class */
1893
1894     s++;
1895     if (*s == ']' || *s == '^')
1896         return FALSE;
1897     else {
1898         /* this is terrifying, and it works */
1899         int weight = 2;         /* let's weigh the evidence */
1900         char seen[256];
1901         unsigned char un_char = 255, last_un_char;
1902         char *send = strchr(s,']');
1903         char tmpbuf[sizeof PL_tokenbuf * 4];
1904
1905         if (!send)              /* has to be an expression */
1906             return TRUE;
1907
1908         Zero(seen,256,char);
1909         if (*s == '$')
1910             weight -= 3;
1911         else if (isDIGIT(*s)) {
1912             if (s[1] != ']') {
1913                 if (isDIGIT(s[1]) && s[2] == ']')
1914                     weight -= 10;
1915             }
1916             else
1917                 weight -= 100;
1918         }
1919         for (; s < send; s++) {
1920             last_un_char = un_char;
1921             un_char = (unsigned char)*s;
1922             switch (*s) {
1923             case '@':
1924             case '&':
1925             case '$':
1926                 weight -= seen[un_char] * 10;
1927                 if (isALNUM_lazy_if(s+1,UTF)) {
1928                     scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
1929                     if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
1930                         weight -= 100;
1931                     else
1932                         weight -= 10;
1933                 }
1934                 else if (*s == '$' && s[1] &&
1935                   strchr("[#!%*<>()-=",s[1])) {
1936                     if (/*{*/ strchr("])} =",s[2]))
1937                         weight -= 10;
1938                     else
1939                         weight -= 1;
1940                 }
1941                 break;
1942             case '\\':
1943                 un_char = 254;
1944                 if (s[1]) {
1945                     if (strchr("wds]",s[1]))
1946                         weight += 100;
1947                     else if (seen['\''] || seen['"'])
1948                         weight += 1;
1949                     else if (strchr("rnftbxcav",s[1]))
1950                         weight += 40;
1951                     else if (isDIGIT(s[1])) {
1952                         weight += 40;
1953                         while (s[1] && isDIGIT(s[1]))
1954                             s++;
1955                     }
1956                 }
1957                 else
1958                     weight += 100;
1959                 break;
1960             case '-':
1961                 if (s[1] == '\\')
1962                     weight += 50;
1963                 if (strchr("aA01! ",last_un_char))
1964                     weight += 30;
1965                 if (strchr("zZ79~",s[1]))
1966                     weight += 30;
1967                 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
1968                     weight -= 5;        /* cope with negative subscript */
1969                 break;
1970             default:
1971                 if (!isALNUM(last_un_char)
1972                     && !(last_un_char == '$' || last_un_char == '@'
1973                          || last_un_char == '&')
1974                     && isALPHA(*s) && s[1] && isALPHA(s[1])) {
1975                     char *d = tmpbuf;
1976                     while (isALPHA(*s))
1977                         *d++ = *s++;
1978                     *d = '\0';
1979                     if (keyword(tmpbuf, d - tmpbuf))
1980                         weight -= 150;
1981                 }
1982                 if (un_char == last_un_char + 1)
1983                     weight += 5;
1984                 weight -= seen[un_char];
1985                 break;
1986             }
1987             seen[un_char]++;
1988         }
1989         if (weight >= 0)        /* probably a character class */
1990             return FALSE;
1991     }
1992
1993     return TRUE;
1994 }
1995
1996 /*
1997  * S_intuit_method
1998  *
1999  * Does all the checking to disambiguate
2000  *   foo bar
2001  * between foo(bar) and bar->foo.  Returns 0 if not a method, otherwise
2002  * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2003  *
2004  * First argument is the stuff after the first token, e.g. "bar".
2005  *
2006  * Not a method if bar is a filehandle.
2007  * Not a method if foo is a subroutine prototyped to take a filehandle.
2008  * Not a method if it's really "Foo $bar"
2009  * Method if it's "foo $bar"
2010  * Not a method if it's really "print foo $bar"
2011  * Method if it's really "foo package::" (interpreted as package->foo)
2012  * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2013  * Not a method if bar is a filehandle or package, but is quoted with
2014  *   =>
2015  */
2016
2017 STATIC int
2018 S_intuit_method(pTHX_ char *start, GV *gv)
2019 {
2020     char *s = start + (*start == '$');
2021     char tmpbuf[sizeof PL_tokenbuf];
2022     STRLEN len;
2023     GV* indirgv;
2024
2025     if (gv) {
2026         CV *cv;
2027         if (GvIO(gv))
2028             return 0;
2029         if ((cv = GvCVu(gv))) {
2030             char *proto = SvPVX(cv);
2031             if (proto) {
2032                 if (*proto == ';')
2033                     proto++;
2034                 if (*proto == '*')
2035                     return 0;
2036             }
2037         } else
2038             gv = 0;
2039     }
2040     s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2041     /* start is the beginning of the possible filehandle/object,
2042      * and s is the end of it
2043      * tmpbuf is a copy of it
2044      */
2045
2046     if (*start == '$') {
2047         if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2048             return 0;
2049         s = skipspace(s);
2050         PL_bufptr = start;
2051         PL_expect = XREF;
2052         return *s == '(' ? FUNCMETH : METHOD;
2053     }
2054     if (!keyword(tmpbuf, len)) {
2055         if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2056             len -= 2;
2057             tmpbuf[len] = '\0';
2058             goto bare_package;
2059         }
2060         indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2061         if (indirgv && GvCVu(indirgv))
2062             return 0;
2063         /* filehandle or package name makes it a method */
2064         if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2065             s = skipspace(s);
2066             if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2067                 return 0;       /* no assumptions -- "=>" quotes bearword */
2068       bare_package:
2069             PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
2070                                                    newSVpvn(tmpbuf,len));
2071             PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
2072             PL_expect = XTERM;
2073             force_next(WORD);
2074             PL_bufptr = s;
2075             return *s == '(' ? FUNCMETH : METHOD;
2076         }
2077     }
2078     return 0;
2079 }
2080
2081 /*
2082  * S_incl_perldb
2083  * Return a string of Perl code to load the debugger.  If PERL5DB
2084  * is set, it will return the contents of that, otherwise a
2085  * compile-time require of perl5db.pl.
2086  */
2087
2088 STATIC char*
2089 S_incl_perldb(pTHX)
2090 {
2091     if (PL_perldb) {
2092         char *pdb = PerlEnv_getenv("PERL5DB");
2093
2094         if (pdb)
2095             return pdb;
2096         SETERRNO(0,SS_NORMAL);
2097         return "BEGIN { require 'perl5db.pl' }";
2098     }
2099     return "";
2100 }
2101
2102
2103 /* Encoded script support. filter_add() effectively inserts a
2104  * 'pre-processing' function into the current source input stream.
2105  * Note that the filter function only applies to the current source file
2106  * (e.g., it will not affect files 'require'd or 'use'd by this one).
2107  *
2108  * The datasv parameter (which may be NULL) can be used to pass
2109  * private data to this instance of the filter. The filter function
2110  * can recover the SV using the FILTER_DATA macro and use it to
2111  * store private buffers and state information.
2112  *
2113  * The supplied datasv parameter is upgraded to a PVIO type
2114  * and the IoDIRP/IoANY field is used to store the function pointer,
2115  * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2116  * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2117  * private use must be set using malloc'd pointers.
2118  */
2119
2120 SV *
2121 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2122 {
2123     if (!funcp)
2124         return Nullsv;
2125
2126     if (!PL_rsfp_filters)
2127         PL_rsfp_filters = newAV();
2128     if (!datasv)
2129         datasv = NEWSV(255,0);
2130     if (!SvUPGRADE(datasv, SVt_PVIO))
2131         Perl_die(aTHX_ "Can't upgrade filter_add data to SVt_PVIO");
2132     IoANY(datasv) = (void *)funcp; /* stash funcp into spare field */
2133     IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2134     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2135                           (void*)funcp, SvPV_nolen(datasv)));
2136     av_unshift(PL_rsfp_filters, 1);
2137     av_store(PL_rsfp_filters, 0, datasv) ;
2138     return(datasv);
2139 }
2140
2141
2142 /* Delete most recently added instance of this filter function. */
2143 void
2144 Perl_filter_del(pTHX_ filter_t funcp)
2145 {
2146     SV *datasv;
2147     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", (void*)funcp));
2148     if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2149         return;
2150     /* if filter is on top of stack (usual case) just pop it off */
2151     datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2152     if (IoANY(datasv) == (void *)funcp) {
2153         IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2154         IoANY(datasv) = (void *)NULL;
2155         sv_free(av_pop(PL_rsfp_filters));
2156
2157         return;
2158     }
2159     /* we need to search for the correct entry and clear it     */
2160     Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2161 }
2162
2163
2164 /* Invoke the idxth filter function for the current rsfp.        */
2165 /* maxlen 0 = read one text line */
2166 I32
2167 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2168 {
2169     filter_t funcp;
2170     SV *datasv = NULL;
2171
2172     if (!PL_rsfp_filters)
2173         return -1;
2174     if (idx > AvFILLp(PL_rsfp_filters)) {       /* Any more filters?    */
2175         /* Provide a default input filter to make life easy.    */
2176         /* Note that we append to the line. This is handy.      */
2177         DEBUG_P(PerlIO_printf(Perl_debug_log,
2178                               "filter_read %d: from rsfp\n", idx));
2179         if (maxlen) {
2180             /* Want a block */
2181             int len ;
2182             int old_len = SvCUR(buf_sv) ;
2183
2184             /* ensure buf_sv is large enough */
2185             SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ;
2186             if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
2187                 if (PerlIO_error(PL_rsfp))
2188                     return -1;          /* error */
2189                 else
2190                     return 0 ;          /* end of file */
2191             }
2192             SvCUR_set(buf_sv, old_len + len) ;
2193         } else {
2194             /* Want a line */
2195             if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2196                 if (PerlIO_error(PL_rsfp))
2197                     return -1;          /* error */
2198                 else
2199                     return 0 ;          /* end of file */
2200             }
2201         }
2202         return SvCUR(buf_sv);
2203     }
2204     /* Skip this filter slot if filter has been deleted */
2205     if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2206         DEBUG_P(PerlIO_printf(Perl_debug_log,
2207                               "filter_read %d: skipped (filter deleted)\n",
2208                               idx));
2209         return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
2210     }
2211     /* Get function pointer hidden within datasv        */
2212     funcp = (filter_t)IoANY(datasv);
2213     DEBUG_P(PerlIO_printf(Perl_debug_log,
2214                           "filter_read %d: via function %p (%s)\n",
2215                           idx, (void*)funcp, SvPV_nolen(datasv)));
2216     /* Call function. The function is expected to       */
2217     /* call "FILTER_READ(idx+1, buf_sv)" first.         */
2218     /* Return: <0:error, =0:eof, >0:not eof             */
2219     return (*funcp)(aTHX_ idx, buf_sv, maxlen);
2220 }
2221
2222 STATIC char *
2223 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2224 {
2225 #ifdef PERL_CR_FILTER
2226     if (!PL_rsfp_filters) {
2227         filter_add(S_cr_textfilter,NULL);
2228     }
2229 #endif
2230     if (PL_rsfp_filters) {
2231         if (!append)
2232             SvCUR_set(sv, 0);   /* start with empty line        */
2233         if (FILTER_READ(0, sv, 0) > 0)
2234             return ( SvPVX(sv) ) ;
2235         else
2236             return Nullch ;
2237     }
2238     else
2239         return (sv_gets(sv, fp, append));
2240 }
2241
2242 STATIC HV *
2243 S_find_in_my_stash(pTHX_ char *pkgname, I32 len)
2244 {
2245     GV *gv;
2246
2247     if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2248         return PL_curstash;
2249
2250     if (len > 2 &&
2251         (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2252         (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV)))
2253     {
2254         return GvHV(gv);                        /* Foo:: */
2255     }
2256
2257     /* use constant CLASS => 'MyClass' */
2258     if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) {
2259         SV *sv;
2260         if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2261             pkgname = SvPV_nolen(sv);
2262         }
2263     }
2264
2265     return gv_stashpv(pkgname, FALSE);
2266 }
2267
2268 #ifdef DEBUGGING
2269     static char* exp_name[] =
2270         { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2271           "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
2272         };
2273 #endif
2274
2275 /*
2276   yylex
2277
2278   Works out what to call the token just pulled out of the input
2279   stream.  The yacc parser takes care of taking the ops we return and
2280   stitching them into a tree.
2281
2282   Returns:
2283     PRIVATEREF
2284
2285   Structure:
2286       if read an identifier
2287           if we're in a my declaration
2288               croak if they tried to say my($foo::bar)
2289               build the ops for a my() declaration
2290           if it's an access to a my() variable
2291               are we in a sort block?
2292                   croak if my($a); $a <=> $b
2293               build ops for access to a my() variable
2294           if in a dq string, and they've said @foo and we can't find @foo
2295               croak
2296           build ops for a bareword
2297       if we already built the token before, use it.
2298 */
2299
2300
2301 #ifdef __SC__
2302 #pragma segment Perl_yylex
2303 #endif
2304 int
2305 Perl_yylex(pTHX)
2306 {
2307     register char *s = PL_bufptr;
2308     register char *d;
2309     register I32 tmp;
2310     STRLEN len;
2311     GV *gv = Nullgv;
2312     GV **gvp = 0;
2313     bool bof = FALSE;
2314     I32 orig_keyword = 0;
2315
2316     DEBUG_T( {
2317         PerlIO_printf(Perl_debug_log, "### LEX_%s\n",
2318                                         lex_state_names[PL_lex_state]);
2319     } );
2320     /* check if there's an identifier for us to look at */
2321     if (PL_pending_ident)
2322         return REPORT(S_pending_ident(aTHX));
2323
2324     /* no identifier pending identification */
2325
2326     switch (PL_lex_state) {
2327 #ifdef COMMENTARY
2328     case LEX_NORMAL:            /* Some compilers will produce faster */
2329     case LEX_INTERPNORMAL:      /* code if we comment these out. */
2330         break;
2331 #endif
2332
2333     /* when we've already built the next token, just pull it out of the queue */
2334     case LEX_KNOWNEXT:
2335         PL_nexttoke--;
2336         yylval = PL_nextval[PL_nexttoke];
2337         if (!PL_nexttoke) {
2338             PL_lex_state = PL_lex_defer;
2339             PL_expect = PL_lex_expect;
2340             PL_lex_defer = LEX_NORMAL;
2341         }
2342         DEBUG_T({ PerlIO_printf(Perl_debug_log,
2343               "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr,
2344               (IV)PL_nexttype[PL_nexttoke]); });
2345
2346         return REPORT(PL_nexttype[PL_nexttoke]);
2347
2348     /* interpolated case modifiers like \L \U, including \Q and \E.
2349        when we get here, PL_bufptr is at the \
2350     */
2351     case LEX_INTERPCASEMOD:
2352 #ifdef DEBUGGING
2353         if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2354             Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2355 #endif
2356         /* handle \E or end of string */
2357         if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2358             char oldmod;
2359
2360             /* if at a \E */
2361             if (PL_lex_casemods) {
2362                 oldmod = PL_lex_casestack[--PL_lex_casemods];
2363                 PL_lex_casestack[PL_lex_casemods] = '\0';
2364
2365                 if (PL_bufptr != PL_bufend
2366                     && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
2367                     PL_bufptr += 2;
2368                     PL_lex_state = LEX_INTERPCONCAT;
2369                 }
2370                 return REPORT(')');
2371             }
2372             if (PL_bufptr != PL_bufend)
2373                 PL_bufptr += 2;
2374             PL_lex_state = LEX_INTERPCONCAT;
2375             return yylex();
2376         }
2377         else {
2378             DEBUG_T({ PerlIO_printf(Perl_debug_log,
2379               "### Saw case modifier at '%s'\n", PL_bufptr); });
2380             s = PL_bufptr + 1;
2381             if (s[1] == '\\' && s[2] == 'E') {
2382                 PL_bufptr = s + 3;
2383                 PL_lex_state = LEX_INTERPCONCAT;
2384                 return yylex();
2385             }
2386             else {
2387                 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2388                     tmp = *s, *s = s[2], s[2] = (char)tmp;      /* misordered... */
2389                 if ((*s == 'L' || *s == 'U') &&
2390                     (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
2391                     PL_lex_casestack[--PL_lex_casemods] = '\0';
2392                     return REPORT(')');
2393                 }
2394                 if (PL_lex_casemods > 10)
2395                     Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2396                 PL_lex_casestack[PL_lex_casemods++] = *s;
2397                 PL_lex_casestack[PL_lex_casemods] = '\0';
2398                 PL_lex_state = LEX_INTERPCONCAT;
2399                 PL_nextval[PL_nexttoke].ival = 0;
2400                 force_next('(');
2401                 if (*s == 'l')
2402                     PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2403                 else if (*s == 'u')
2404                     PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2405                 else if (*s == 'L')
2406                     PL_nextval[PL_nexttoke].ival = OP_LC;
2407                 else if (*s == 'U')
2408                     PL_nextval[PL_nexttoke].ival = OP_UC;
2409                 else if (*s == 'Q')
2410                     PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2411                 else
2412                     Perl_croak(aTHX_ "panic: yylex");
2413                 PL_bufptr = s + 1;
2414             }
2415             force_next(FUNC);
2416             if (PL_lex_starts) {
2417                 s = PL_bufptr;
2418                 PL_lex_starts = 0;
2419                 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2420                 if (PL_lex_casemods == 1 && PL_lex_inpat)
2421                     OPERATOR(',');
2422                 else
2423                     Aop(OP_CONCAT);
2424             }
2425             else
2426                 return yylex();
2427         }
2428
2429     case LEX_INTERPPUSH:
2430         return REPORT(sublex_push());
2431
2432     case LEX_INTERPSTART:
2433         if (PL_bufptr == PL_bufend)
2434             return REPORT(sublex_done());
2435         DEBUG_T({ PerlIO_printf(Perl_debug_log,
2436               "### Interpolated variable at '%s'\n", PL_bufptr); });
2437         PL_expect = XTERM;
2438         PL_lex_dojoin = (*PL_bufptr == '@');
2439         PL_lex_state = LEX_INTERPNORMAL;
2440         if (PL_lex_dojoin) {
2441             PL_nextval[PL_nexttoke].ival = 0;
2442             force_next(',');
2443             force_ident("\"", '$');
2444             PL_nextval[PL_nexttoke].ival = 0;
2445             force_next('$');
2446             PL_nextval[PL_nexttoke].ival = 0;
2447             force_next('(');
2448             PL_nextval[PL_nexttoke].ival = OP_JOIN;     /* emulate join($", ...) */
2449             force_next(FUNC);
2450         }
2451         if (PL_lex_starts++) {
2452             s = PL_bufptr;
2453             /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2454             if (!PL_lex_casemods && PL_lex_inpat)
2455                 OPERATOR(',');
2456             else
2457                 Aop(OP_CONCAT);
2458         }
2459         return yylex();
2460
2461     case LEX_INTERPENDMAYBE:
2462         if (intuit_more(PL_bufptr)) {
2463             PL_lex_state = LEX_INTERPNORMAL;    /* false alarm, more expr */
2464             break;
2465         }
2466         /* FALL THROUGH */
2467
2468     case LEX_INTERPEND:
2469         if (PL_lex_dojoin) {
2470             PL_lex_dojoin = FALSE;
2471             PL_lex_state = LEX_INTERPCONCAT;
2472             return REPORT(')');
2473         }
2474         if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2475             && SvEVALED(PL_lex_repl))
2476         {
2477             if (PL_bufptr != PL_bufend)
2478                 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2479             PL_lex_repl = Nullsv;
2480         }
2481         /* FALLTHROUGH */
2482     case LEX_INTERPCONCAT:
2483 #ifdef DEBUGGING
2484         if (PL_lex_brackets)
2485             Perl_croak(aTHX_ "panic: INTERPCONCAT");
2486 #endif
2487         if (PL_bufptr == PL_bufend)
2488             return REPORT(sublex_done());
2489
2490         if (SvIVX(PL_linestr) == '\'') {
2491             SV *sv = newSVsv(PL_linestr);
2492             if (!PL_lex_inpat)
2493                 sv = tokeq(sv);
2494             else if ( PL_hints & HINT_NEW_RE )
2495                 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2496             yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2497             s = PL_bufend;
2498         }
2499         else {
2500             s = scan_const(PL_bufptr);
2501             if (*s == '\\')
2502                 PL_lex_state = LEX_INTERPCASEMOD;
2503             else
2504                 PL_lex_state = LEX_INTERPSTART;
2505         }
2506
2507         if (s != PL_bufptr) {
2508             PL_nextval[PL_nexttoke] = yylval;
2509             PL_expect = XTERM;
2510             force_next(THING);
2511             if (PL_lex_starts++) {
2512                 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2513                 if (!PL_lex_casemods && PL_lex_inpat)
2514                     OPERATOR(',');
2515                 else
2516                     Aop(OP_CONCAT);
2517             }
2518             else {
2519                 PL_bufptr = s;
2520                 return yylex();
2521             }
2522         }
2523
2524         return yylex();
2525     case LEX_FORMLINE:
2526         PL_lex_state = LEX_NORMAL;
2527         s = scan_formline(PL_bufptr);
2528         if (!PL_lex_formbrack)
2529             goto rightbracket;
2530         OPERATOR(';');
2531     }
2532
2533     s = PL_bufptr;
2534     PL_oldoldbufptr = PL_oldbufptr;
2535     PL_oldbufptr = s;
2536     DEBUG_T( {
2537         PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at [%s]\n",
2538                       exp_name[PL_expect], s);
2539     } );
2540
2541   retry:
2542     switch (*s) {
2543     default:
2544         if (isIDFIRST_lazy_if(s,UTF))
2545             goto keylookup;
2546         Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2547     case 4:
2548     case 26:
2549         goto fake_eof;                  /* emulate EOF on ^D or ^Z */
2550     case 0:
2551         if (!PL_rsfp) {
2552             PL_last_uni = 0;
2553             PL_last_lop = 0;
2554             if (PL_lex_brackets) {
2555                 if (PL_lex_formbrack)
2556                     yyerror("Format not terminated");
2557                 else
2558                     yyerror("Missing right curly or square bracket");
2559             }
2560             DEBUG_T( { PerlIO_printf(Perl_debug_log,
2561                         "### Tokener got EOF\n");
2562             } );
2563             TOKEN(0);
2564         }
2565         if (s++ < PL_bufend)
2566             goto retry;                 /* ignore stray nulls */
2567         PL_last_uni = 0;
2568         PL_last_lop = 0;
2569         if (!PL_in_eval && !PL_preambled) {
2570             PL_preambled = TRUE;
2571             sv_setpv(PL_linestr,incl_perldb());
2572             if (SvCUR(PL_linestr))
2573                 sv_catpvn(PL_linestr,";", 1);
2574             if (PL_preambleav){
2575                 while(AvFILLp(PL_preambleav) >= 0) {
2576                     SV *tmpsv = av_shift(PL_preambleav);
2577                     sv_catsv(PL_linestr, tmpsv);
2578                     sv_catpvn(PL_linestr, ";", 1);
2579                     sv_free(tmpsv);
2580                 }
2581                 sv_free((SV*)PL_preambleav);
2582                 PL_preambleav = NULL;
2583             }
2584             if (PL_minus_n || PL_minus_p) {
2585                 sv_catpv(PL_linestr, "LINE: while (<>) {");
2586                 if (PL_minus_l)
2587                     sv_catpv(PL_linestr,"chomp;");
2588                 if (PL_minus_a) {
2589                     if (PL_minus_F) {
2590                         if ((*PL_splitstr == '/' || *PL_splitstr == '\''
2591                              || *PL_splitstr == '"')
2592                               && strchr(PL_splitstr + 1, *PL_splitstr))
2593                             Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
2594                         else {
2595                             /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
2596                                bytes can be used as quoting characters.  :-) */
2597                             /* The count here deliberately includes the NUL
2598                                that terminates the C string constant.  This
2599                                embeds the opening NUL into the string.  */
2600                             sv_catpvn(PL_linestr, "our @F=split(q", 15);
2601                             s = PL_splitstr;
2602                             do {
2603                                 /* Need to \ \s  */
2604                                 if (*s == '\\')
2605                                     sv_catpvn(PL_linestr, s, 1);
2606                                 sv_catpvn(PL_linestr, s, 1);
2607                             } while (*s++);
2608                             /* This loop will embed the trailing NUL of
2609                                PL_linestr as the last thing it does before
2610                                terminating.  */
2611                             sv_catpvn(PL_linestr, ");", 2);
2612                         }
2613                     }
2614                     else
2615                         sv_catpv(PL_linestr,"our @F=split(' ');");
2616                 }
2617             }
2618             sv_catpvn(PL_linestr, "\n", 1);
2619             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2620             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2621             PL_last_lop = PL_last_uni = Nullch;
2622             if (PERLDB_LINE && PL_curstash != PL_debstash) {
2623                 SV *sv = NEWSV(85,0);
2624
2625                 sv_upgrade(sv, SVt_PVMG);
2626                 sv_setsv(sv,PL_linestr);
2627                 (void)SvIOK_on(sv);
2628                 SvIVX(sv) = 0;
2629                 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2630             }
2631             goto retry;
2632         }
2633         do {
2634             bof = PL_rsfp ? TRUE : FALSE;
2635             if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2636               fake_eof:
2637                 if (PL_rsfp) {
2638                     if (PL_preprocess && !PL_in_eval)
2639                         (void)PerlProc_pclose(PL_rsfp);
2640                     else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2641                         PerlIO_clearerr(PL_rsfp);
2642                     else
2643                         (void)PerlIO_close(PL_rsfp);
2644                     PL_rsfp = Nullfp;
2645                     PL_doextract = FALSE;
2646                 }
2647                 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2648                     sv_setpv(PL_linestr,PL_minus_p
2649                              ? ";}continue{print;}" : ";}");
2650                     PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2651                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2652                     PL_last_lop = PL_last_uni = Nullch;
2653                     PL_minus_n = PL_minus_p = 0;
2654                     goto retry;
2655                 }
2656                 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2657                 PL_last_lop = PL_last_uni = Nullch;
2658                 sv_setpv(PL_linestr,"");
2659                 TOKEN(';');     /* not infinite loop because rsfp is NULL now */
2660             }
2661             /* If it looks like the start of a BOM or raw UTF-16,
2662              * check if it in fact is. */
2663             else if (bof &&
2664                      (*s == 0 ||
2665                       *(U8*)s == 0xEF ||
2666                       *(U8*)s >= 0xFE ||
2667                       s[1] == 0)) {
2668 #ifdef PERLIO_IS_STDIO
2669 #  ifdef __GNU_LIBRARY__
2670 #    if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
2671 #      define FTELL_FOR_PIPE_IS_BROKEN
2672 #    endif
2673 #  else
2674 #    ifdef __GLIBC__
2675 #      if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
2676 #        define FTELL_FOR_PIPE_IS_BROKEN
2677 #      endif
2678 #    endif
2679 #  endif
2680 #endif
2681 #ifdef FTELL_FOR_PIPE_IS_BROKEN
2682                 /* This loses the possibility to detect the bof
2683                  * situation on perl -P when the libc5 is being used.
2684                  * Workaround?  Maybe attach some extra state to PL_rsfp?
2685                  */
2686                 if (!PL_preprocess)
2687                     bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2688 #else
2689                 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
2690 #endif
2691                 if (bof) {
2692                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2693                     s = swallow_bom((U8*)s);
2694                 }
2695             }
2696             if (PL_doextract) {
2697                 /* Incest with pod. */
2698                 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2699                     sv_setpv(PL_linestr, "");
2700                     PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2701                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2702                     PL_last_lop = PL_last_uni = Nullch;
2703                     PL_doextract = FALSE;
2704                 }
2705             }
2706             incline(s);
2707         } while (PL_doextract);
2708         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2709         if (PERLDB_LINE && PL_curstash != PL_debstash) {
2710             SV *sv = NEWSV(85,0);
2711
2712             sv_upgrade(sv, SVt_PVMG);
2713             sv_setsv(sv,PL_linestr);
2714             (void)SvIOK_on(sv);
2715             SvIVX(sv) = 0;
2716             av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2717         }
2718         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2719         PL_last_lop = PL_last_uni = Nullch;
2720         if (CopLINE(PL_curcop) == 1) {
2721             while (s < PL_bufend && isSPACE(*s))
2722                 s++;
2723             if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2724                 s++;
2725             d = Nullch;
2726             if (!PL_in_eval) {
2727                 if (*s == '#' && *(s+1) == '!')
2728                     d = s + 2;
2729 #ifdef ALTERNATE_SHEBANG
2730                 else {
2731                     static char as[] = ALTERNATE_SHEBANG;
2732                     if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2733                         d = s + (sizeof(as) - 1);
2734                 }
2735 #endif /* ALTERNATE_SHEBANG */
2736             }
2737             if (d) {
2738                 char *ipath;
2739                 char *ipathend;
2740
2741                 while (isSPACE(*d))
2742                     d++;
2743                 ipath = d;
2744                 while (*d && !isSPACE(*d))
2745                     d++;
2746                 ipathend = d;
2747
2748 #ifdef ARG_ZERO_IS_SCRIPT
2749                 if (ipathend > ipath) {
2750                     /*
2751                      * HP-UX (at least) sets argv[0] to the script name,
2752                      * which makes $^X incorrect.  And Digital UNIX and Linux,
2753                      * at least, set argv[0] to the basename of the Perl
2754                      * interpreter. So, having found "#!", we'll set it right.
2755                      */
2756                     SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); /* $^X */
2757                     assert(SvPOK(x) || SvGMAGICAL(x));
2758                     if (sv_eq(x, CopFILESV(PL_curcop))) {
2759                         sv_setpvn(x, ipath, ipathend - ipath);
2760                         SvSETMAGIC(x);
2761                     }
2762                     else {
2763                         STRLEN blen;
2764                         STRLEN llen;
2765                         char *bstart = SvPV(CopFILESV(PL_curcop),blen);
2766                         char *lstart = SvPV(x,llen);
2767                         if (llen < blen) {
2768                             bstart += blen - llen;
2769                             if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
2770                                 sv_setpvn(x, ipath, ipathend - ipath);
2771                                 SvSETMAGIC(x);
2772                             }
2773                         }
2774                     }
2775                     TAINT_NOT;  /* $^X is always tainted, but that's OK */
2776                 }
2777 #endif /* ARG_ZERO_IS_SCRIPT */
2778
2779                 /*
2780                  * Look for options.
2781                  */
2782                 d = instr(s,"perl -");
2783                 if (!d) {
2784                     d = instr(s,"perl");
2785 #if defined(DOSISH)
2786                     /* avoid getting into infinite loops when shebang
2787                      * line contains "Perl" rather than "perl" */
2788                     if (!d) {
2789                         for (d = ipathend-4; d >= ipath; --d) {
2790                             if ((*d == 'p' || *d == 'P')
2791                                 && !ibcmp(d, "perl", 4))
2792                             {
2793                                 break;
2794                             }
2795                         }
2796                         if (d < ipath)
2797                             d = Nullch;
2798                     }
2799 #endif
2800                 }
2801 #ifdef ALTERNATE_SHEBANG
2802                 /*
2803                  * If the ALTERNATE_SHEBANG on this system starts with a
2804                  * character that can be part of a Perl expression, then if
2805                  * we see it but not "perl", we're probably looking at the
2806                  * start of Perl code, not a request to hand off to some
2807                  * other interpreter.  Similarly, if "perl" is there, but
2808                  * not in the first 'word' of the line, we assume the line
2809                  * contains the start of the Perl program.
2810                  */
2811                 if (d && *s != '#') {
2812                     char *c = ipath;
2813                     while (*c && !strchr("; \t\r\n\f\v#", *c))
2814                         c++;
2815                     if (c < d)
2816                         d = Nullch;     /* "perl" not in first word; ignore */
2817                     else
2818                         *s = '#';       /* Don't try to parse shebang line */
2819                 }
2820 #endif /* ALTERNATE_SHEBANG */
2821 #ifndef MACOS_TRADITIONAL
2822                 if (!d &&
2823                     *s == '#' &&
2824                     ipathend > ipath &&
2825                     !PL_minus_c &&
2826                     !instr(s,"indir") &&
2827                     instr(PL_origargv[0],"perl"))
2828                 {
2829                     char **newargv;
2830
2831                     *ipathend = '\0';
2832                     s = ipathend + 1;
2833                     while (s < PL_bufend && isSPACE(*s))
2834                         s++;
2835                     if (s < PL_bufend) {
2836                         Newz(899,newargv,PL_origargc+3,char*);
2837                         newargv[1] = s;
2838                         while (s < PL_bufend && !isSPACE(*s))
2839                             s++;
2840                         *s = '\0';
2841                         Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2842                     }
2843                     else
2844                         newargv = PL_origargv;
2845                     newargv[0] = ipath;
2846                     PERL_FPU_PRE_EXEC
2847                     PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
2848                     PERL_FPU_POST_EXEC
2849                     Perl_croak(aTHX_ "Can't exec %s", ipath);
2850                 }
2851 #endif
2852                 if (d) {
2853                     U32 oldpdb = PL_perldb;
2854                     bool oldn = PL_minus_n;
2855                     bool oldp = PL_minus_p;
2856
2857                     while (*d && !isSPACE(*d)) d++;
2858                     while (SPACE_OR_TAB(*d)) d++;
2859
2860                     if (*d++ == '-') {
2861                         bool switches_done = PL_doswitches;
2862                         do {
2863                             if (*d == 'M' || *d == 'm') {
2864                                 char *m = d;
2865                                 while (*d && !isSPACE(*d)) d++;
2866                                 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2867                                       (int)(d - m), m);
2868                             }
2869                             d = moreswitches(d);
2870                         } while (d);
2871                         if (PL_doswitches && !switches_done) {
2872                             int argc = PL_origargc;
2873                             char **argv = PL_origargv;
2874                             do {
2875                                 argc--,argv++;
2876                             } while (argc && argv[0][0] == '-' && argv[0][1]);
2877                             init_argv_symbols(argc,argv);
2878                         }
2879                         if ((PERLDB_LINE && !oldpdb) ||
2880                             ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
2881                               /* if we have already added "LINE: while (<>) {",
2882                                  we must not do it again */
2883                         {
2884                             sv_setpv(PL_linestr, "");
2885                             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2886                             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2887                             PL_last_lop = PL_last_uni = Nullch;
2888                             PL_preambled = FALSE;
2889                             if (PERLDB_LINE)
2890                                 (void)gv_fetchfile(PL_origfilename);
2891                             goto retry;
2892                         }
2893                         if (PL_doswitches && !switches_done) {
2894                             int argc = PL_origargc;
2895                             char **argv = PL_origargv;
2896                             do {
2897                                 argc--,argv++;
2898                             } while (argc && argv[0][0] == '-' && argv[0][1]);
2899                             init_argv_symbols(argc,argv);
2900                         }
2901                     }
2902                 }
2903             }
2904         }
2905         if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2906             PL_bufptr = s;
2907             PL_lex_state = LEX_FORMLINE;
2908             return yylex();
2909         }
2910         goto retry;
2911     case '\r':
2912 #ifdef PERL_STRICT_CR
2913         Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
2914         Perl_croak(aTHX_
2915       "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
2916 #endif
2917     case ' ': case '\t': case '\f': case 013:
2918 #ifdef MACOS_TRADITIONAL
2919     case '\312':
2920 #endif
2921         s++;
2922         goto retry;
2923     case '#':
2924     case '\n':
2925         if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
2926             if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
2927                 /* handle eval qq[#line 1 "foo"\n ...] */
2928                 CopLINE_dec(PL_curcop);
2929                 incline(s);
2930             }
2931             d = PL_bufend;
2932             while (s < d && *s != '\n')
2933                 s++;
2934             if (s < d)
2935                 s++;
2936             else if (s > d) /* Found by Ilya: feed random input to Perl. */
2937               Perl_croak(aTHX_ "panic: input overflow");
2938             incline(s);
2939             if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2940                 PL_bufptr = s;
2941                 PL_lex_state = LEX_FORMLINE;
2942                 return yylex();
2943             }
2944         }
2945         else {
2946             *s = '\0';
2947             PL_bufend = s;
2948         }
2949         goto retry;
2950     case '-':
2951         if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
2952             I32 ftst = 0;
2953
2954             s++;
2955             PL_bufptr = s;
2956             tmp = *s++;
2957
2958             while (s < PL_bufend && SPACE_OR_TAB(*s))
2959                 s++;
2960
2961             if (strnEQ(s,"=>",2)) {
2962                 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
2963                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
2964                             "### Saw unary minus before =>, forcing word '%s'\n", s);
2965                 } );
2966                 OPERATOR('-');          /* unary minus */
2967             }
2968             PL_last_uni = PL_oldbufptr;
2969             switch (tmp) {
2970             case 'r': ftst = OP_FTEREAD;        break;
2971             case 'w': ftst = OP_FTEWRITE;       break;
2972             case 'x': ftst = OP_FTEEXEC;        break;
2973             case 'o': ftst = OP_FTEOWNED;       break;
2974             case 'R': ftst = OP_FTRREAD;        break;
2975             case 'W': ftst = OP_FTRWRITE;       break;
2976             case 'X': ftst = OP_FTREXEC;        break;
2977             case 'O': ftst = OP_FTROWNED;       break;
2978             case 'e': ftst = OP_FTIS;           break;
2979             case 'z': ftst = OP_FTZERO;         break;
2980             case 's': ftst = OP_FTSIZE;         break;
2981             case 'f': ftst = OP_FTFILE;         break;
2982             case 'd': ftst = OP_FTDIR;          break;
2983             case 'l': ftst = OP_FTLINK;         break;
2984             case 'p': ftst = OP_FTPIPE;         break;
2985             case 'S': ftst = OP_FTSOCK;         break;
2986             case 'u': ftst = OP_FTSUID;         break;
2987             case 'g': ftst = OP_FTSGID;         break;
2988             case 'k': ftst = OP_FTSVTX;         break;
2989             case 'b': ftst = OP_FTBLK;          break;
2990             case 'c': ftst = OP_FTCHR;          break;
2991             case 't': ftst = OP_FTTTY;          break;
2992             case 'T': ftst = OP_FTTEXT;         break;
2993             case 'B': ftst = OP_FTBINARY;       break;
2994             case 'M': case 'A': case 'C':
2995                 gv_fetchpv("\024",TRUE, SVt_PV);
2996                 switch (tmp) {
2997                 case 'M': ftst = OP_FTMTIME;    break;
2998                 case 'A': ftst = OP_FTATIME;    break;
2999                 case 'C': ftst = OP_FTCTIME;    break;
3000                 default:                        break;
3001                 }
3002                 break;
3003             default:
3004                 break;
3005             }
3006             if (ftst) {
3007                 PL_last_lop_op = (OPCODE)ftst;
3008                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3009                         "### Saw file test %c\n", (int)ftst);
3010                 } );
3011                 FTST(ftst);
3012             }
3013             else {
3014                 /* Assume it was a minus followed by a one-letter named
3015                  * subroutine call (or a -bareword), then. */
3016                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3017                         "### '-%c' looked like a file test but was not\n",
3018                         (int) tmp);
3019                 } );
3020                 s = --PL_bufptr;
3021             }
3022         }
3023         tmp = *s++;
3024         if (*s == tmp) {
3025             s++;
3026             if (PL_expect == XOPERATOR)
3027                 TERM(POSTDEC);
3028             else
3029                 OPERATOR(PREDEC);
3030         }
3031         else if (*s == '>') {
3032             s++;
3033             s = skipspace(s);
3034             if (isIDFIRST_lazy_if(s,UTF)) {
3035                 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3036                 TOKEN(ARROW);
3037             }
3038             else if (*s == '$')
3039                 OPERATOR(ARROW);
3040             else
3041                 TERM(ARROW);
3042         }
3043         if (PL_expect == XOPERATOR)
3044             Aop(OP_SUBTRACT);
3045         else {
3046             if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3047                 check_uni();
3048             OPERATOR('-');              /* unary minus */
3049         }
3050
3051     case '+':
3052         tmp = *s++;
3053         if (*s == tmp) {
3054             s++;
3055             if (PL_expect == XOPERATOR)
3056                 TERM(POSTINC);
3057             else
3058                 OPERATOR(PREINC);
3059         }
3060         if (PL_expect == XOPERATOR)
3061             Aop(OP_ADD);
3062         else {
3063             if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3064                 check_uni();
3065             OPERATOR('+');
3066         }
3067
3068     case '*':
3069         if (PL_expect != XOPERATOR) {
3070             s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3071             PL_expect = XOPERATOR;
3072             force_ident(PL_tokenbuf, '*');
3073             if (!*PL_tokenbuf)
3074                 PREREF('*');
3075             TERM('*');
3076         }
3077         s++;
3078         if (*s == '*') {
3079             s++;
3080             PWop(OP_POW);
3081         }
3082         Mop(OP_MULTIPLY);
3083
3084     case '%':
3085         if (PL_expect == XOPERATOR) {
3086             ++s;
3087             Mop(OP_MODULO);
3088         }
3089         PL_tokenbuf[0] = '%';
3090         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3091         if (!PL_tokenbuf[1]) {
3092             PREREF('%');
3093         }
3094         PL_pending_ident = '%';
3095         TERM('%');
3096
3097     case '^':
3098         s++;
3099         BOop(OP_BIT_XOR);
3100     case '[':
3101         PL_lex_brackets++;
3102         /* FALL THROUGH */
3103     case '~':
3104     case ',':
3105         tmp = *s++;
3106         OPERATOR(tmp);
3107     case ':':
3108         if (s[1] == ':') {
3109             len = 0;
3110             goto just_a_word;
3111         }
3112         s++;
3113         switch (PL_expect) {
3114             OP *attrs;
3115         case XOPERATOR:
3116             if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3117                 break;
3118             PL_bufptr = s;      /* update in case we back off */
3119             goto grabattrs;
3120         case XATTRBLOCK:
3121             PL_expect = XBLOCK;
3122             goto grabattrs;
3123         case XATTRTERM:
3124             PL_expect = XTERMBLOCK;
3125          grabattrs:
3126             s = skipspace(s);
3127             attrs = Nullop;
3128             while (isIDFIRST_lazy_if(s,UTF)) {
3129                 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3130                 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
3131                     if (tmp < 0) tmp = -tmp;
3132                     switch (tmp) {
3133                     case KEY_or:
3134                     case KEY_and:
3135                     case KEY_err:
3136                     case KEY_for:
3137                     case KEY_unless:
3138                     case KEY_if:
3139                     case KEY_while:
3140                     case KEY_until:
3141                         goto got_attrs;
3142                     default:
3143                         break;
3144                     }
3145                 }
3146                 if (*d == '(') {
3147                     d = scan_str(d,TRUE,TRUE);
3148                     if (!d) {
3149                         /* MUST advance bufptr here to avoid bogus
3150                            "at end of line" context messages from yyerror().
3151                          */
3152                         PL_bufptr = s + len;
3153                         yyerror("Unterminated attribute parameter in attribute list");
3154                         if (attrs)
3155                             op_free(attrs);
3156                         return REPORT(0);       /* EOF indicator */
3157                     }
3158                 }
3159                 if (PL_lex_stuff) {
3160                     SV *sv = newSVpvn(s, len);
3161                     sv_catsv(sv, PL_lex_stuff);
3162                     attrs = append_elem(OP_LIST, attrs,
3163                                         newSVOP(OP_CONST, 0, sv));
3164                     SvREFCNT_dec(PL_lex_stuff);
3165                     PL_lex_stuff = Nullsv;
3166                 }
3167                 else {
3168                     if (len == 6 && strnEQ(s, "unique", len)) {
3169                         if (PL_in_my == KEY_our)
3170 #ifdef USE_ITHREADS
3171                             GvUNIQUE_on(cGVOPx_gv(yylval.opval));
3172 #else
3173                             ; /* skip to avoid loading attributes.pm */
3174 #endif
3175                         else 
3176                             Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
3177                     }
3178
3179                     /* NOTE: any CV attrs applied here need to be part of
3180                        the CVf_BUILTIN_ATTRS define in cv.h! */
3181                     else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
3182                         CvLVALUE_on(PL_compcv);
3183                     else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
3184                         CvLOCKED_on(PL_compcv);
3185                     else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
3186                         CvMETHOD_on(PL_compcv);
3187                     else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len))
3188                         CvASSERTION_on(PL_compcv);
3189                     /* After we've set the flags, it could be argued that
3190                        we don't need to do the attributes.pm-based setting
3191                        process, and shouldn't bother appending recognized
3192                        flags.  To experiment with that, uncomment the
3193                        following "else".  (Note that's already been
3194                        uncommented.  That keeps the above-applied built-in
3195                        attributes from being intercepted (and possibly
3196                        rejected) by a package's attribute routines, but is
3197                        justified by the performance win for the common case
3198                        of applying only built-in attributes.) */
3199                     else
3200                         attrs = append_elem(OP_LIST, attrs,
3201                                             newSVOP(OP_CONST, 0,
3202                                                     newSVpvn(s, len)));
3203                 }
3204                 s = skipspace(d);
3205                 if (*s == ':' && s[1] != ':')
3206                     s = skipspace(s+1);
3207                 else if (s == d)
3208                     break;      /* require real whitespace or :'s */
3209             }
3210             tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
3211             if (*s != ';' && *s != '}' && *s != tmp && (tmp != '=' || *s != ')')) {
3212                 char q = ((*s == '\'') ? '"' : '\'');
3213                 /* If here for an expression, and parsed no attrs, back off. */
3214                 if (tmp == '=' && !attrs) {
3215                     s = PL_bufptr;
3216                     break;
3217                 }
3218                 /* MUST advance bufptr here to avoid bogus "at end of line"
3219                    context messages from yyerror().
3220                  */
3221                 PL_bufptr = s;
3222                 if (!*s)
3223                     yyerror("Unterminated attribute list");
3224                 else
3225                     yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
3226                                       q, *s, q));
3227                 if (attrs)
3228                     op_free(attrs);
3229                 OPERATOR(':');
3230             }
3231         got_attrs:
3232             if (attrs) {
3233                 PL_nextval[PL_nexttoke].opval = attrs;
3234                 force_next(THING);
3235             }
3236             TOKEN(COLONATTR);
3237         }
3238         OPERATOR(':');
3239     case '(':
3240         s++;
3241         if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
3242             PL_oldbufptr = PL_oldoldbufptr;             /* allow print(STDOUT 123) */
3243         else
3244             PL_expect = XTERM;
3245         s = skipspace(s);
3246         TOKEN('(');
3247     case ';':
3248         CLINE;
3249         tmp = *s++;
3250         OPERATOR(tmp);
3251     case ')':
3252         tmp = *s++;
3253         s = skipspace(s);
3254         if (*s == '{')
3255             PREBLOCK(tmp);
3256         TERM(tmp);
3257     case ']':
3258         s++;
3259         if (PL_lex_brackets <= 0)
3260             yyerror("Unmatched right square bracket");
3261         else
3262             --PL_lex_brackets;
3263         if (PL_lex_state == LEX_INTERPNORMAL) {
3264             if (PL_lex_brackets == 0) {
3265                 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3266                     PL_lex_state = LEX_INTERPEND;
3267             }
3268         }
3269         TERM(']');
3270     case '{':
3271       leftbracket:
3272         s++;
3273         if (PL_lex_brackets > 100) {
3274             Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
3275         }
3276         switch (PL_expect) {
3277         case XTERM:
3278             if (PL_lex_formbrack) {
3279                 s--;
3280                 PRETERMBLOCK(DO);
3281             }
3282             if (PL_oldoldbufptr == PL_last_lop)
3283                 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3284             else
3285                 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3286             OPERATOR(HASHBRACK);
3287         case XOPERATOR:
3288             while (s < PL_bufend && SPACE_OR_TAB(*s))
3289                 s++;
3290             d = s;
3291             PL_tokenbuf[0] = '\0';
3292             if (d < PL_bufend && *d == '-') {
3293                 PL_tokenbuf[0] = '-';
3294                 d++;
3295                 while (d < PL_bufend && SPACE_OR_TAB(*d))
3296                     d++;
3297             }
3298             if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3299                 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
3300                               FALSE, &len);
3301                 while (d < PL_bufend && SPACE_OR_TAB(*d))
3302                     d++;
3303                 if (*d == '}') {
3304                     char minus = (PL_tokenbuf[0] == '-');
3305                     s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
3306                     if (minus)
3307                         force_next('-');
3308                 }
3309             }
3310             /* FALL THROUGH */
3311         case XATTRBLOCK:
3312         case XBLOCK:
3313             PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
3314             PL_expect = XSTATE;
3315             break;
3316         case XATTRTERM:
3317         case XTERMBLOCK:
3318             PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3319             PL_expect = XSTATE;
3320             break;
3321         default: {
3322                 char *t;
3323                 if (PL_oldoldbufptr == PL_last_lop)
3324                     PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3325                 else
3326                     PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3327                 s = skipspace(s);
3328                 if (*s == '}') {
3329                     if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
3330                         PL_expect = XTERM;
3331                         /* This hack is to get the ${} in the message. */
3332                         PL_bufptr = s+1;
3333                         yyerror("syntax error");
3334                         break;
3335                     }
3336                     OPERATOR(HASHBRACK);
3337                 }
3338                 /* This hack serves to disambiguate a pair of curlies
3339                  * as being a block or an anon hash.  Normally, expectation
3340                  * determines that, but in cases where we're not in a
3341                  * position to expect anything in particular (like inside
3342                  * eval"") we have to resolve the ambiguity.  This code
3343                  * covers the case where the first term in the curlies is a
3344                  * quoted string.  Most other cases need to be explicitly
3345                  * disambiguated by prepending a `+' before the opening
3346                  * curly in order to force resolution as an anon hash.
3347                  *
3348                  * XXX should probably propagate the outer expectation
3349                  * into eval"" to rely less on this hack, but that could
3350                  * potentially break current behavior of eval"".
3351                  * GSAR 97-07-21
3352                  */
3353                 t = s;
3354                 if (*s == '\'' || *s == '"' || *s == '`') {
3355                     /* common case: get past first string, handling escapes */
3356                     for (t++; t < PL_bufend && *t != *s;)
3357                         if (*t++ == '\\' && (*t == '\\' || *t == *s))
3358                             t++;
3359                     t++;
3360                 }
3361                 else if (*s == 'q') {
3362                     if (++t < PL_bufend
3363                         && (!isALNUM(*t)
3364                             || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
3365                                 && !isALNUM(*t))))
3366                     {
3367                         /* skip q//-like construct */
3368                         char *tmps;
3369                         char open, close, term;
3370                         I32 brackets = 1;
3371
3372                         while (t < PL_bufend && isSPACE(*t))
3373                             t++;
3374                         /* check for q => */
3375                         if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
3376                             OPERATOR(HASHBRACK);
3377                         }
3378                         term = *t;
3379                         open = term;
3380                         if (term && (tmps = strchr("([{< )]}> )]}>",term)))
3381                             term = tmps[5];
3382                         close = term;
3383                         if (open == close)
3384                             for (t++; t < PL_bufend; t++) {
3385                                 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
3386                                     t++;
3387                                 else if (*t == open)
3388                                     break;
3389                             }
3390                         else {
3391                             for (t++; t < PL_bufend; t++) {
3392                                 if (*t == '\\' && t+1 < PL_bufend)
3393                                     t++;
3394                                 else if (*t == close && --brackets <= 0)
3395                                     break;
3396                                 else if (*t == open)
3397                                     brackets++;
3398                             }
3399                         }
3400                         t++;
3401                     }
3402                     else
3403                         /* skip plain q word */
3404                         while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3405                              t += UTF8SKIP(t);
3406                 }
3407                 else if (isALNUM_lazy_if(t,UTF)) {
3408                     t += UTF8SKIP(t);
3409                     while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3410                          t += UTF8SKIP(t);
3411                 }
3412                 while (t < PL_bufend && isSPACE(*t))
3413                     t++;
3414                 /* if comma follows first term, call it an anon hash */
3415                 /* XXX it could be a comma expression with loop modifiers */
3416                 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
3417                                    || (*t == '=' && t[1] == '>')))
3418                     OPERATOR(HASHBRACK);
3419                 if (PL_expect == XREF)
3420                     PL_expect = XTERM;
3421                 else {
3422                     PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3423                     PL_expect = XSTATE;
3424                 }
3425             }
3426             break;
3427         }
3428         yylval.ival = CopLINE(PL_curcop);
3429         if (isSPACE(*s) || *s == '#')
3430             PL_copline = NOLINE;   /* invalidate current command line number */
3431         TOKEN('{');
3432     case '}':
3433       rightbracket:
3434         s++;
3435         if (PL_lex_brackets <= 0)
3436             yyerror("Unmatched right curly bracket");
3437         else
3438             PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3439         if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3440             PL_lex_formbrack = 0;
3441         if (PL_lex_state == LEX_INTERPNORMAL) {
3442             if (PL_lex_brackets == 0) {
3443                 if (PL_expect & XFAKEBRACK) {
3444                     PL_expect &= XENUMMASK;
3445                     PL_lex_state = LEX_INTERPEND;
3446                     PL_bufptr = s;
3447                     return yylex();     /* ignore fake brackets */
3448                 }
3449                 if (*s == '-' && s[1] == '>')
3450                     PL_lex_state = LEX_INTERPENDMAYBE;
3451                 else if (*s != '[' && *s != '{')
3452                     PL_lex_state = LEX_INTERPEND;
3453             }
3454         }
3455         if (PL_expect & XFAKEBRACK) {
3456             PL_expect &= XENUMMASK;
3457             PL_bufptr = s;
3458             return yylex();             /* ignore fake brackets */
3459         }
3460         force_next('}');
3461         TOKEN(';');
3462     case '&':
3463         s++;
3464         tmp = *s++;
3465         if (tmp == '&')
3466             AOPERATOR(ANDAND);
3467         s--;
3468         if (PL_expect == XOPERATOR) {
3469             if (ckWARN(WARN_SEMICOLON)
3470                 && isIDFIRST_lazy_if(s,UTF) && PL_bufptr == PL_linestart)
3471             {
3472                 CopLINE_dec(PL_curcop);
3473                 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
3474                 CopLINE_inc(PL_curcop);
3475             }
3476             BAop(OP_BIT_AND);
3477         }
3478
3479         s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3480         if (*PL_tokenbuf) {
3481             PL_expect = XOPERATOR;
3482             force_ident(PL_tokenbuf, '&');
3483         }
3484         else
3485             PREREF('&');
3486         yylval.ival = (OPpENTERSUB_AMPER<<8);
3487         TERM('&');
3488
3489     case '|':
3490         s++;
3491         tmp = *s++;
3492         if (tmp == '|')
3493             AOPERATOR(OROR);
3494         s--;
3495         BOop(OP_BIT_OR);
3496     case '=':
3497         s++;
3498         tmp = *s++;
3499         if (tmp == '=')
3500             Eop(OP_EQ);
3501         if (tmp == '>')
3502             OPERATOR(',');
3503         if (tmp == '~')
3504             PMop(OP_MATCH);
3505         if (ckWARN(WARN_SYNTAX) && tmp && isSPACE(*s) && strchr("+-*/%.^&|<",tmp))
3506             Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Reversed %c= operator",(int)tmp);
3507         s--;
3508         if (PL_expect == XSTATE && isALPHA(tmp) &&
3509                 (s == PL_linestart+1 || s[-2] == '\n') )
3510         {
3511             if (PL_in_eval && !PL_rsfp) {
3512                 d = PL_bufend;
3513                 while (s < d) {
3514                     if (*s++ == '\n') {
3515                         incline(s);
3516                         if (strnEQ(s,"=cut",4)) {
3517                             s = strchr(s,'\n');
3518                             if (s)
3519                                 s++;
3520                             else
3521                                 s = d;
3522                             incline(s);
3523                             goto retry;
3524                         }
3525                     }
3526                 }
3527                 goto retry;
3528             }
3529             s = PL_bufend;
3530             PL_doextract = TRUE;
3531             goto retry;
3532         }
3533         if (PL_lex_brackets < PL_lex_formbrack) {
3534             char *t;
3535 #ifdef PERL_STRICT_CR
3536             for (t = s; SPACE_OR_TAB(*t); t++) ;
3537 #else
3538             for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3539 #endif
3540             if (*t == '\n' || *t == '#') {
3541                 s--;
3542                 PL_expect = XBLOCK;
3543                 goto leftbracket;
3544             }
3545         }
3546         yylval.ival = 0;
3547         OPERATOR(ASSIGNOP);
3548     case '!':
3549         s++;
3550         tmp = *s++;
3551         if (tmp == '=') {
3552             /* was this !=~ where !~ was meant?
3553              * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
3554
3555             if (*s == '~' && ckWARN(WARN_SYNTAX)) {
3556                 char *t = s+1;
3557
3558                 while (t < PL_bufend && isSPACE(*t))
3559                     ++t;
3560
3561                 if (*t == '/' || *t == '?' ||
3562                     ((*t == 'm' || *t == 's' || *t == 'y') && !isALNUM(t[1])) ||
3563                     (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
3564                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3565                                 "!=~ should be !~");
3566             }
3567             Eop(OP_NE);
3568         }
3569         if (tmp == '~')
3570             PMop(OP_NOT);
3571         s--;
3572         OPERATOR('!');
3573     case '<':
3574         if (PL_expect != XOPERATOR) {
3575             if (s[1] != '<' && !strchr(s,'>'))
3576                 check_uni();
3577             if (s[1] == '<')
3578                 s = scan_heredoc(s);
3579             else
3580                 s = scan_inputsymbol(s);
3581             TERM(sublex_start());
3582         }
3583         s++;
3584         tmp = *s++;
3585         if (tmp == '<')
3586             SHop(OP_LEFT_SHIFT);
3587         if (tmp == '=') {
3588             tmp = *s++;
3589             if (tmp == '>')
3590                 Eop(OP_NCMP);
3591             s--;
3592             Rop(OP_LE);
3593         }
3594         s--;
3595         Rop(OP_LT);
3596     case '>':
3597         s++;
3598         tmp = *s++;
3599         if (tmp == '>')
3600             SHop(OP_RIGHT_SHIFT);
3601         if (tmp == '=')
3602             Rop(OP_GE);
3603         s--;
3604         Rop(OP_GT);
3605
3606     case '$':
3607         CLINE;
3608
3609         if (PL_expect == XOPERATOR) {
3610             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3611                 PL_expect = XTERM;
3612                 depcom();
3613                 return REPORT(','); /* grandfather non-comma-format format */
3614             }
3615         }
3616
3617         if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3618             PL_tokenbuf[0] = '@';
3619             s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3620                            sizeof PL_tokenbuf - 1, FALSE);
3621             if (PL_expect == XOPERATOR)
3622                 no_op("Array length", s);
3623             if (!PL_tokenbuf[1])
3624                 PREREF(DOLSHARP);
3625             PL_expect = XOPERATOR;
3626             PL_pending_ident = '#';
3627             TOKEN(DOLSHARP);
3628         }
3629
3630         PL_tokenbuf[0] = '$';
3631         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3632                        sizeof PL_tokenbuf - 1, FALSE);
3633         if (PL_expect == XOPERATOR)
3634             no_op("Scalar", s);
3635         if (!PL_tokenbuf[1]) {
3636             if (s == PL_bufend)
3637                 yyerror("Final $ should be \\$ or $name");
3638             PREREF('$');
3639         }
3640
3641         /* This kludge not intended to be bulletproof. */
3642         if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3643             yylval.opval = newSVOP(OP_CONST, 0,
3644                                    newSViv(PL_compiling.cop_arybase));
3645             yylval.opval->op_private = OPpCONST_ARYBASE;
3646             TERM(THING);
3647         }
3648
3649         d = s;
3650         tmp = (I32)*s;
3651         if (PL_lex_state == LEX_NORMAL)
3652             s = skipspace(s);
3653
3654         if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3655             char *t;
3656             if (*s == '[') {
3657                 PL_tokenbuf[0] = '@';
3658                 if (ckWARN(WARN_SYNTAX)) {
3659                     for(t = s + 1;
3660                         isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3661                         t++) ;
3662                     if (*t++ == ',') {
3663                         PL_bufptr = skipspace(PL_bufptr);
3664                         while (t < PL_bufend && *t != ']')
3665                             t++;
3666                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3667                                 "Multidimensional syntax %.*s not supported",
3668                                 (t - PL_bufptr) + 1, PL_bufptr);
3669                     }
3670                 }
3671             }
3672             else if (*s == '{') {
3673                 PL_tokenbuf[0] = '%';
3674                 if (ckWARN(WARN_SYNTAX) && strEQ(PL_tokenbuf+1, "SIG") &&
3675                     (t = strchr(s, '}')) && (t = strchr(t, '=')))
3676                 {
3677                     char tmpbuf[sizeof PL_tokenbuf];
3678                     STRLEN len;
3679                     for (t++; isSPACE(*t); t++) ;
3680                     if (isIDFIRST_lazy_if(t,UTF)) {
3681                         t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3682                         for (; isSPACE(*t); t++) ;
3683                         if (*t == ';' && get_cv(tmpbuf, FALSE))
3684                             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3685                                 "You need to quote \"%s\"", tmpbuf);
3686                     }
3687                 }
3688             }
3689         }
3690
3691         PL_expect = XOPERATOR;
3692         if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3693             bool islop = (PL_last_lop == PL_oldoldbufptr);
3694             if (!islop || PL_last_lop_op == OP_GREPSTART)
3695                 PL_expect = XOPERATOR;
3696             else if (strchr("$@\"'`q", *s))
3697                 PL_expect = XTERM;              /* e.g. print $fh "foo" */
3698             else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3699                 PL_expect = XTERM;              /* e.g. print $fh &sub */
3700             else if (isIDFIRST_lazy_if(s,UTF)) {
3701                 char tmpbuf[sizeof PL_tokenbuf];
3702                 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3703                 if ((tmp = keyword(tmpbuf, len))) {
3704                     /* binary operators exclude handle interpretations */
3705                     switch (tmp) {
3706                     case -KEY_x:
3707                     case -KEY_eq:
3708                     case -KEY_ne:
3709                     case -KEY_gt:
3710                     case -KEY_lt:
3711                     case -KEY_ge:
3712                     case -KEY_le:
3713                     case -KEY_cmp:
3714                         break;
3715                     default:
3716                         PL_expect = XTERM;      /* e.g. print $fh length() */
3717                         break;
3718                     }
3719                 }
3720                 else {
3721                     PL_expect = XTERM;          /* e.g. print $fh subr() */
3722                 }
3723             }
3724             else if (isDIGIT(*s))
3725                 PL_expect = XTERM;              /* e.g. print $fh 3 */
3726             else if (*s == '.' && isDIGIT(s[1]))
3727                 PL_expect = XTERM;              /* e.g. print $fh .3 */
3728             else if ((*s == '?' || *s == '-' || *s == '+')
3729                      && !isSPACE(s[1]) && s[1] != '=')
3730                 PL_expect = XTERM;              /* e.g. print $fh -1 */
3731             else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' && s[1] != '/')
3732                 PL_expect = XTERM;              /* e.g. print $fh /.../
3733                                                  XXX except DORDOR operator */
3734             else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3735                 PL_expect = XTERM;              /* print $fh <<"EOF" */
3736         }
3737         PL_pending_ident = '$';
3738         TOKEN('$');
3739
3740     case '@':
3741         if (PL_expect == XOPERATOR)
3742             no_op("Array", s);
3743         PL_tokenbuf[0] = '@';
3744         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3745         if (!PL_tokenbuf[1]) {
3746             PREREF('@');
3747         }
3748         if (PL_lex_state == LEX_NORMAL)
3749             s = skipspace(s);
3750         if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3751             if (*s == '{')
3752                 PL_tokenbuf[0] = '%';
3753
3754             /* Warn about @ where they meant $. */
3755             if (ckWARN(WARN_SYNTAX)) {
3756                 if (*s == '[' || *s == '{') {
3757                     char *t = s + 1;
3758                     while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3759                         t++;
3760                     if (*t == '}' || *t == ']') {
3761                         t++;
3762                         PL_bufptr = skipspace(PL_bufptr);
3763                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3764                             "Scalar value %.*s better written as $%.*s",
3765                             t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3766                     }
3767                 }
3768             }
3769         }
3770         PL_pending_ident = '@';
3771         TERM('@');
3772
3773      case '/':                  /* may be division, defined-or, or pattern */
3774         if (PL_expect == XTERMORDORDOR && s[1] == '/') {
3775             s += 2;
3776             AOPERATOR(DORDOR);
3777         }
3778      case '?':                  /* may either be conditional or pattern */
3779          if(PL_expect == XOPERATOR) {
3780              tmp = *s++;
3781              if(tmp == '?') {
3782                   OPERATOR('?');
3783              }
3784              else {
3785                  tmp = *s++;
3786                  if(tmp == '/') {
3787                      /* A // operator. */
3788                     AOPERATOR(DORDOR);
3789                  }
3790                  else {
3791                      s--;
3792                      Mop(OP_DIVIDE);
3793                  }
3794              }
3795          }
3796          else {
3797              /* Disable warning on "study /blah/" */
3798              if (PL_oldoldbufptr == PL_last_uni
3799               && (*PL_last_uni != 's' || s - PL_last_uni < 5
3800                   || memNE(PL_last_uni, "study", 5)
3801                   || isALNUM_lazy_if(PL_last_uni+5,UTF)
3802               ))
3803                  check_uni();
3804              s = scan_pat(s,OP_MATCH);
3805              TERM(sublex_start());
3806          }
3807
3808     case '.':
3809         if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3810 #ifdef PERL_STRICT_CR
3811             && s[1] == '\n'
3812 #else
3813             && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3814 #endif
3815             && (s == PL_linestart || s[-1] == '\n') )
3816         {
3817             PL_lex_formbrack = 0;
3818             PL_expect = XSTATE;
3819             goto rightbracket;
3820         }
3821         if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3822             tmp = *s++;
3823             if (*s == tmp) {
3824                 s++;
3825                 if (*s == tmp) {
3826                     s++;
3827                     yylval.ival = OPf_SPECIAL;
3828                 }
3829                 else
3830                     yylval.ival = 0;
3831                 OPERATOR(DOTDOT);
3832             }
3833             if (PL_expect != XOPERATOR)
3834                 check_uni();
3835             Aop(OP_CONCAT);
3836         }
3837         /* FALL THROUGH */
3838     case '0': case '1': case '2': case '3': case '4':
3839     case '5': case '6': case '7': case '8': case '9':
3840         s = scan_num(s, &yylval);
3841         DEBUG_T( { PerlIO_printf(Perl_debug_log,
3842                     "### Saw number in '%s'\n", s);
3843         } );
3844         if (PL_expect == XOPERATOR)
3845             no_op("Number",s);
3846         TERM(THING);
3847
3848     case '\'':
3849         s = scan_str(s,FALSE,FALSE);
3850         DEBUG_T( { PerlIO_printf(Perl_debug_log,
3851                     "### Saw string before '%s'\n", s);
3852         } );
3853         if (PL_expect == XOPERATOR) {
3854             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3855                 PL_expect = XTERM;
3856                 depcom();
3857                 return REPORT(','); /* grandfather non-comma-format format */
3858             }
3859             else
3860                 no_op("String",s);
3861         }
3862         if (!s)
3863             missingterm((char*)0);
3864         yylval.ival = OP_CONST;
3865         TERM(sublex_start());
3866
3867     case '"':
3868         s = scan_str(s,FALSE,FALSE);
3869         DEBUG_T( { PerlIO_printf(Perl_debug_log,
3870                     "### Saw string before '%s'\n", s);
3871         } );
3872         if (PL_expect == XOPERATOR) {
3873             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3874                 PL_expect = XTERM;
3875                 depcom();
3876                 return REPORT(','); /* grandfather non-comma-format format */
3877             }
3878             else
3879                 no_op("String",s);
3880         }
3881         if (!s)
3882             missingterm((char*)0);
3883         yylval.ival = OP_CONST;
3884         for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3885             if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
3886                 yylval.ival = OP_STRINGIFY;
3887                 break;
3888             }
3889         }
3890         TERM(sublex_start());
3891
3892     case '`':
3893         s = scan_str(s,FALSE,FALSE);
3894         DEBUG_T( { PerlIO_printf(Perl_debug_log,
3895                     "### Saw backtick string before '%s'\n", s);
3896         } );
3897         if (PL_expect == XOPERATOR)
3898             no_op("Backticks",s);
3899         if (!s)
3900             missingterm((char*)0);
3901         yylval.ival = OP_BACKTICK;
3902         set_csh();
3903         TERM(sublex_start());
3904
3905     case '\\':
3906         s++;
3907         if (ckWARN(WARN_SYNTAX) && PL_lex_inwhat && isDIGIT(*s))
3908             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
3909                         *s, *s);
3910         if (PL_expect == XOPERATOR)
3911             no_op("Backslash",s);
3912         OPERATOR(REFGEN);
3913
3914     case 'v':
3915         if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
3916             char *start = s;
3917             start++;
3918             start++;
3919             while (isDIGIT(*start) || *start == '_')
3920                 start++;
3921             if (*start == '.' && isDIGIT(start[1])) {
3922                 s = scan_num(s, &yylval);
3923                 TERM(THING);
3924             }
3925             /* avoid v123abc() or $h{v1}, allow C<print v10;> */
3926             else if (!isALPHA(*start) && (PL_expect == XTERM
3927                         || PL_expect == XREF || PL_expect == XSTATE
3928                         || PL_expect == XTERMORDORDOR)) {
3929                 char c = *start;
3930                 GV *gv;
3931                 *start = '\0';
3932                 gv = gv_fetchpv(s, FALSE, SVt_PVCV);
3933                 *start = c;
3934                 if (!gv) {
3935                     s = scan_num(s, &yylval);
3936                     TERM(THING);
3937                 }
3938             }
3939         }
3940         goto keylookup;
3941     case 'x':
3942         if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
3943             s++;
3944             Mop(OP_REPEAT);
3945         }
3946         goto keylookup;
3947
3948     case '_':
3949     case 'a': case 'A':
3950     case 'b': case 'B':
3951     case 'c': case 'C':
3952     case 'd': case 'D':
3953     case 'e': case 'E':
3954     case 'f': case 'F':
3955     case 'g': case 'G':
3956     case 'h': case 'H':
3957     case 'i': case 'I':
3958     case 'j': case 'J':
3959     case 'k': case 'K':
3960     case 'l': case 'L':
3961     case 'm': case 'M':
3962     case 'n': case 'N':
3963     case 'o': case 'O':
3964     case 'p': case 'P':
3965     case 'q': case 'Q':
3966     case 'r': case 'R':
3967     case 's': case 'S':
3968     case 't': case 'T':
3969     case 'u': case 'U':
3970               case 'V':
3971     case 'w': case 'W':
3972               case 'X':
3973     case 'y': case 'Y':
3974     case 'z': case 'Z':
3975
3976       keylookup: {
3977         orig_keyword = 0;
3978         gv = Nullgv;
3979         gvp = 0;
3980
3981         PL_bufptr = s;
3982         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3983
3984         /* Some keywords can be followed by any delimiter, including ':' */
3985         tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
3986                (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
3987                              (PL_tokenbuf[0] == 'q' &&
3988                               strchr("qwxr", PL_tokenbuf[1])))));
3989
3990         /* x::* is just a word, unless x is "CORE" */
3991         if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
3992             goto just_a_word;
3993
3994         d = s;
3995         while (d < PL_bufend && isSPACE(*d))
3996                 d++;    /* no comments skipped here, or s### is misparsed */
3997
3998         /* Is this a label? */
3999         if (!tmp && PL_expect == XSTATE
4000               && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4001             s = d + 1;
4002             yylval.pval = savepv(PL_tokenbuf);
4003             CLINE;
4004             TOKEN(LABEL);
4005         }
4006
4007         /* Check for keywords */
4008         tmp = keyword(PL_tokenbuf, len);
4009
4010         /* Is this a word before a => operator? */
4011         if (*d == '=' && d[1] == '>') {
4012             CLINE;
4013             yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf,0));
4014             yylval.opval->op_private = OPpCONST_BARE;
4015             if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
4016               SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
4017             TERM(WORD);
4018         }
4019
4020         if (tmp < 0) {                  /* second-class keyword? */
4021             GV *ogv = Nullgv;   /* override (winner) */
4022             GV *hgv = Nullgv;   /* hidden (loser) */
4023             if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4024                 CV *cv;
4025                 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
4026                     (cv = GvCVu(gv)))
4027                 {
4028                     if (GvIMPORTED_CV(gv))
4029                         ogv = gv;
4030                     else if (! CvMETHOD(cv))
4031                         hgv = gv;
4032                 }
4033                 if (!ogv &&
4034                     (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4035                     (gv = *gvp) != (GV*)&PL_sv_undef &&
4036                     GvCVu(gv) && GvIMPORTED_CV(gv))
4037                 {
4038                     ogv = gv;
4039                 }
4040             }
4041             if (ogv) {
4042                 orig_keyword = tmp;
4043                 tmp = 0;                /* overridden by import or by GLOBAL */
4044             }
4045             else if (gv && !gvp
4046                      && -tmp==KEY_lock  /* XXX generalizable kludge */
4047                      && GvCVu(gv)
4048                      && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
4049             {
4050                 tmp = 0;                /* any sub overrides "weak" keyword */
4051             }
4052             else if (gv && !gvp
4053                     && tmp == -KEY_err
4054                     && GvCVu(gv)
4055                     && PL_expect != XOPERATOR
4056                     && PL_expect != XTERMORDORDOR)
4057             {
4058                 /* any sub overrides the "err" keyword, except when really an
4059                  * operator is expected */
4060                 tmp = 0;
4061             }
4062             else {                      /* no override */
4063                 tmp = -tmp;
4064                 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
4065                     Perl_warner(aTHX_ packWARN(WARN_MISC),
4066                             "dump() better written as CORE::dump()");
4067                 }
4068                 gv = Nullgv;
4069                 gvp = 0;
4070                 if (ckWARN(WARN_AMBIGUOUS) && hgv
4071                     && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
4072                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4073                         "Ambiguous call resolved as CORE::%s(), %s",
4074                          GvENAME(hgv), "qualify as such or use &");
4075             }
4076         }
4077
4078       reserved_word:
4079         switch (tmp) {
4080
4081         default:                        /* not a keyword */
4082           just_a_word: {
4083                 SV *sv;
4084                 int pkgname = 0;
4085                 char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
4086
4087                 /* Get the rest if it looks like a package qualifier */
4088
4089                 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
4090                     STRLEN morelen;
4091                     s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
4092                                   TRUE, &morelen);
4093                     if (!morelen)
4094                         Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
4095                                 *s == '\'' ? "'" : "::");
4096                     len += morelen;
4097                     pkgname = 1;
4098                 }
4099
4100                 if (PL_expect == XOPERATOR) {
4101                     if (PL_bufptr == PL_linestart) {
4102                         CopLINE_dec(PL_curcop);
4103                         Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4104                         CopLINE_inc(PL_curcop);
4105                     }
4106                     else
4107                         no_op("Bareword",s);
4108                 }
4109
4110                 /* Look for a subroutine with this name in current package,
4111                    unless name is "Foo::", in which case Foo is a bearword
4112                    (and a package name). */
4113
4114                 if (len > 2 &&
4115                     PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
4116                 {
4117                     if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
4118                         Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
4119                             "Bareword \"%s\" refers to nonexistent package",
4120                              PL_tokenbuf);
4121                     len -= 2;
4122                     PL_tokenbuf[len] = '\0';
4123                     gv = Nullgv;
4124                     gvp = 0;
4125                 }
4126                 else {
4127                     len = 0;
4128                     if (!gv)
4129                         gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
4130                 }
4131
4132                 /* if we saw a global override before, get the right name */
4133
4134                 if (gvp) {
4135                     sv = newSVpvn("CORE::GLOBAL::",14);
4136                     sv_catpv(sv,PL_tokenbuf);
4137                 }
4138                 else
4139                     sv = newSVpv(PL_tokenbuf,0);
4140
4141                 /* Presume this is going to be a bareword of some sort. */
4142
4143                 CLINE;
4144                 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4145                 yylval.opval->op_private = OPpCONST_BARE;
4146                 /* UTF-8 package name? */
4147                 if (UTF && !IN_BYTES &&
4148                     is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
4149                     SvUTF8_on(sv);
4150
4151                 /* And if "Foo::", then that's what it certainly is. */
4152
4153                 if (len)
4154                     goto safe_bareword;
4155
4156                 /* See if it's the indirect object for a list operator. */
4157
4158                 if (PL_oldoldbufptr &&
4159                     PL_oldoldbufptr < PL_bufptr &&
4160                     (PL_oldoldbufptr == PL_last_lop
4161                      || PL_oldoldbufptr == PL_last_uni) &&
4162                     /* NO SKIPSPACE BEFORE HERE! */
4163                     (PL_expect == XREF ||
4164                      ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
4165                 {
4166                     bool immediate_paren = *s == '(';
4167
4168                     /* (Now we can afford to cross potential line boundary.) */
4169                     s = skipspace(s);
4170
4171                     /* Two barewords in a row may indicate method call. */
4172
4173                     if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv)))
4174                         return REPORT(tmp);
4175
4176                     /* If not a declared subroutine, it's an indirect object. */
4177                     /* (But it's an indir obj regardless for sort.) */
4178
4179                     if ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
4180                          ((!gv || !GvCVu(gv)) &&
4181                         (PL_last_lop_op != OP_MAPSTART &&
4182                          PL_last_lop_op != OP_GREPSTART))))
4183                     {
4184                         PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
4185                         goto bareword;
4186                     }
4187                 }
4188
4189                 PL_expect = XOPERATOR;
4190                 s = skipspace(s);
4191
4192                 /* Is this a word before a => operator? */
4193                 if (*s == '=' && s[1] == '>' && !pkgname) {
4194                     CLINE;
4195                     sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
4196                     if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
4197                       SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
4198                     TERM(WORD);
4199                 }
4200
4201                 /* If followed by a paren, it's certainly a subroutine. */
4202                 if (*s == '(') {
4203                     CLINE;
4204                     if (gv && GvCVu(gv)) {
4205                         for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
4206                         if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
4207                             s = d + 1;
4208                             goto its_constant;
4209                         }
4210                     }
4211                     PL_nextval[PL_nexttoke].opval = yylval.opval;
4212                     PL_expect = XOPERATOR;
4213                     force_next(WORD);
4214                     yylval.ival = 0;
4215                     TOKEN('&');
4216                 }
4217
4218                 /* If followed by var or block, call it a method (unless sub) */
4219
4220                 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
4221                     PL_last_lop = PL_oldbufptr;
4222                     PL_last_lop_op = OP_METHOD;
4223                     PREBLOCK(METHOD);
4224                 }
4225
4226                 /* If followed by a bareword, see if it looks like indir obj. */
4227
4228                 if (!orig_keyword
4229                         && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
4230                         && (tmp = intuit_method(s,gv)))
4231                     return REPORT(tmp);
4232
4233                 /* Not a method, so call it a subroutine (if defined) */
4234
4235                 if (gv && GvCVu(gv)) {
4236                     CV* cv;
4237                     if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
4238                         Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4239                                 "Ambiguous use of -%s resolved as -&%s()",
4240                                 PL_tokenbuf, PL_tokenbuf);
4241                     /* Check for a constant sub */
4242                     cv = GvCV(gv);
4243                     if ((sv = cv_const_sv(cv))) {
4244                   its_constant:
4245                         SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
4246                         ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
4247                         yylval.opval->op_private = 0;