760f9780275bdb4e5dbbe05d8bfa6bfff3172c36
[p5sagit/p5-mst-13.2.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 const char ident_too_long[] =
30   "Identifier too long";
31 static const char c_without_g[] =
32   "Use of /c modifier is meaningless without /g";
33 static const char c_in_subst[] =
34   "Use of /c modifier is meaningless in s///";
35
36 static void restore_rsfp(pTHX_ void *f);
37 #ifndef PERL_NO_UTF16_FILTER
38 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
39 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
40 #endif
41
42 #define XFAKEBRACK 128
43 #define XENUMMASK 127
44
45 #ifdef USE_UTF8_SCRIPTS
46 #   define UTF (!IN_BYTES)
47 #else
48 #   define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
49 #endif
50
51 /* In variables named $^X, these are the legal values for X.
52  * 1999-02-27 mjd-perl-patch@plover.com */
53 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
54
55 /* On MacOS, respect nonbreaking spaces */
56 #ifdef MACOS_TRADITIONAL
57 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\312'||(c)=='\t')
58 #else
59 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
60 #endif
61
62 /* LEX_* are values for PL_lex_state, the state of the lexer.
63  * They are arranged oddly so that the guard on the switch statement
64  * can get by with a single comparison (if the compiler is smart enough).
65  */
66
67 /* #define LEX_NOTPARSING               11 is done in perl.h. */
68
69 #define LEX_NORMAL              10
70 #define LEX_INTERPNORMAL         9
71 #define LEX_INTERPCASEMOD        8
72 #define LEX_INTERPPUSH           7
73 #define LEX_INTERPSTART          6
74 #define LEX_INTERPEND            5
75 #define LEX_INTERPENDMAYBE       4
76 #define LEX_INTERPCONCAT         3
77 #define LEX_INTERPCONST          2
78 #define LEX_FORMLINE             1
79 #define LEX_KNOWNEXT             0
80
81 #ifdef DEBUGGING
82 static const char* const lex_state_names[] = {
83     "KNOWNEXT",
84     "FORMLINE",
85     "INTERPCONST",
86     "INTERPCONCAT",
87     "INTERPENDMAYBE",
88     "INTERPEND",
89     "INTERPSTART",
90     "INTERPPUSH",
91     "INTERPCASEMOD",
92     "INTERPNORMAL",
93     "NORMAL"
94 };
95 #endif
96
97 #ifdef ff_next
98 #undef ff_next
99 #endif
100
101 #include "keywords.h"
102
103 /* CLINE is a macro that ensures PL_copline has a sane value */
104
105 #ifdef CLINE
106 #undef CLINE
107 #endif
108 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
109
110 /*
111  * Convenience functions to return different tokens and prime the
112  * lexer for the next token.  They all take an argument.
113  *
114  * TOKEN        : generic token (used for '(', DOLSHARP, etc)
115  * OPERATOR     : generic operator
116  * AOPERATOR    : assignment operator
117  * PREBLOCK     : beginning the block after an if, while, foreach, ...
118  * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
119  * PREREF       : *EXPR where EXPR is not a simple identifier
120  * TERM         : expression term
121  * LOOPX        : loop exiting command (goto, last, dump, etc)
122  * FTST         : file test operator
123  * FUN0         : zero-argument function
124  * FUN1         : not used, except for not, which isn't a UNIOP
125  * BOop         : bitwise or or xor
126  * BAop         : bitwise and
127  * SHop         : shift operator
128  * PWop         : power operator
129  * PMop         : pattern-matching operator
130  * Aop          : addition-level operator
131  * Mop          : multiplication-level operator
132  * Eop          : equality-testing operator
133  * Rop          : relational operator <= != gt
134  *
135  * Also see LOP and lop() below.
136  */
137
138 #ifdef DEBUGGING /* Serve -DT. */
139 #   define REPORT(retval) tokereport(s,(int)retval)
140 #else
141 #   define REPORT(retval) (retval)
142 #endif
143
144 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
145 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
146 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
147 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
148 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
149 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
150 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
151 #define LOOPX(f) return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
152 #define FTST(f)  return (yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
153 #define FUN0(f)  return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
154 #define FUN1(f)  return (yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
155 #define BOop(f)  return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
156 #define BAop(f)  return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
157 #define SHop(f)  return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
158 #define PWop(f)  return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
159 #define PMop(f)  return(yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
160 #define Aop(f)   return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
161 #define Mop(f)   return ao((yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
162 #define Eop(f)   return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
163 #define Rop(f)   return (yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
164
165 /* This bit of chicanery makes a unary function followed by
166  * a parenthesis into a function with one argument, highest precedence.
167  * The UNIDOR macro is for unary functions that can be followed by the //
168  * operator (such as C<shift // 0>).
169  */
170 #define UNI2(f,x) { \
171         yylval.ival = f; \
172         PL_expect = x; \
173         PL_bufptr = s; \
174         PL_last_uni = PL_oldbufptr; \
175         PL_last_lop_op = f; \
176         if (*s == '(') \
177             return REPORT( (int)FUNC1 ); \
178         s = skipspace(s); \
179         return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
180         }
181 #define UNI(f)    UNI2(f,XTERM)
182 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
183
184 #define UNIBRACK(f) { \
185         yylval.ival = f; \
186         PL_bufptr = s; \
187         PL_last_uni = PL_oldbufptr; \
188         if (*s == '(') \
189             return REPORT( (int)FUNC1 ); \
190         s = skipspace(s); \
191         return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
192         }
193
194 /* grandfather return to old style */
195 #define OLDLOP(f) return(yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
196
197 #ifdef DEBUGGING
198
199 /* how to interpret the yylval associated with the token */
200 enum token_type {
201     TOKENTYPE_NONE,
202     TOKENTYPE_IVAL,
203     TOKENTYPE_OPNUM, /* yylval.ival contains an opcode number */
204     TOKENTYPE_PVAL,
205     TOKENTYPE_OPVAL,
206     TOKENTYPE_GVVAL
207 };
208
209 static struct debug_tokens { const int token, type; const char *name; }
210   const debug_tokens[] =
211 {
212     { ADDOP,            TOKENTYPE_OPNUM,        "ADDOP" },
213     { ANDAND,           TOKENTYPE_NONE,         "ANDAND" },
214     { ANDOP,            TOKENTYPE_NONE,         "ANDOP" },
215     { ANONSUB,          TOKENTYPE_IVAL,         "ANONSUB" },
216     { ARROW,            TOKENTYPE_NONE,         "ARROW" },
217     { ASSIGNOP,         TOKENTYPE_OPNUM,        "ASSIGNOP" },
218     { BITANDOP,         TOKENTYPE_OPNUM,        "BITANDOP" },
219     { BITOROP,          TOKENTYPE_OPNUM,        "BITOROP" },
220     { COLONATTR,        TOKENTYPE_NONE,         "COLONATTR" },
221     { CONTINUE,         TOKENTYPE_NONE,         "CONTINUE" },
222     { DO,               TOKENTYPE_NONE,         "DO" },
223     { DOLSHARP,         TOKENTYPE_NONE,         "DOLSHARP" },
224     { DORDOR,           TOKENTYPE_NONE,         "DORDOR" },
225     { DOROP,            TOKENTYPE_OPNUM,        "DOROP" },
226     { DOTDOT,           TOKENTYPE_IVAL,         "DOTDOT" },
227     { ELSE,             TOKENTYPE_NONE,         "ELSE" },
228     { ELSIF,            TOKENTYPE_IVAL,         "ELSIF" },
229     { EQOP,             TOKENTYPE_OPNUM,        "EQOP" },
230     { FOR,              TOKENTYPE_IVAL,         "FOR" },
231     { FORMAT,           TOKENTYPE_NONE,         "FORMAT" },
232     { FUNC,             TOKENTYPE_OPNUM,        "FUNC" },
233     { FUNC0,            TOKENTYPE_OPNUM,        "FUNC0" },
234     { FUNC0SUB,         TOKENTYPE_OPVAL,        "FUNC0SUB" },
235     { FUNC1,            TOKENTYPE_OPNUM,        "FUNC1" },
236     { FUNCMETH,         TOKENTYPE_OPVAL,        "FUNCMETH" },
237     { HASHBRACK,        TOKENTYPE_NONE,         "HASHBRACK" },
238     { IF,               TOKENTYPE_IVAL,         "IF" },
239     { LABEL,            TOKENTYPE_PVAL,         "LABEL" },
240     { LOCAL,            TOKENTYPE_IVAL,         "LOCAL" },
241     { LOOPEX,           TOKENTYPE_OPNUM,        "LOOPEX" },
242     { LSTOP,            TOKENTYPE_OPNUM,        "LSTOP" },
243     { LSTOPSUB,         TOKENTYPE_OPVAL,        "LSTOPSUB" },
244     { MATCHOP,          TOKENTYPE_OPNUM,        "MATCHOP" },
245     { METHOD,           TOKENTYPE_OPVAL,        "METHOD" },
246     { MULOP,            TOKENTYPE_OPNUM,        "MULOP" },
247     { MY,               TOKENTYPE_IVAL,         "MY" },
248     { MYSUB,            TOKENTYPE_NONE,         "MYSUB" },
249     { NOAMP,            TOKENTYPE_NONE,         "NOAMP" },
250     { NOTOP,            TOKENTYPE_NONE,         "NOTOP" },
251     { OROP,             TOKENTYPE_IVAL,         "OROP" },
252     { OROR,             TOKENTYPE_NONE,         "OROR" },
253     { PACKAGE,          TOKENTYPE_NONE,         "PACKAGE" },
254     { PMFUNC,           TOKENTYPE_OPVAL,        "PMFUNC" },
255     { POSTDEC,          TOKENTYPE_NONE,         "POSTDEC" },
256     { POSTINC,          TOKENTYPE_NONE,         "POSTINC" },
257     { POWOP,            TOKENTYPE_OPNUM,        "POWOP" },
258     { PREDEC,           TOKENTYPE_NONE,         "PREDEC" },
259     { PREINC,           TOKENTYPE_NONE,         "PREINC" },
260     { PRIVATEREF,       TOKENTYPE_OPVAL,        "PRIVATEREF" },
261     { REFGEN,           TOKENTYPE_NONE,         "REFGEN" },
262     { RELOP,            TOKENTYPE_OPNUM,        "RELOP" },
263     { SHIFTOP,          TOKENTYPE_OPNUM,        "SHIFTOP" },
264     { SUB,              TOKENTYPE_NONE,         "SUB" },
265     { THING,            TOKENTYPE_OPVAL,        "THING" },
266     { UMINUS,           TOKENTYPE_NONE,         "UMINUS" },
267     { UNIOP,            TOKENTYPE_OPNUM,        "UNIOP" },
268     { UNIOPSUB,         TOKENTYPE_OPVAL,        "UNIOPSUB" },
269     { UNLESS,           TOKENTYPE_IVAL,         "UNLESS" },
270     { UNTIL,            TOKENTYPE_IVAL,         "UNTIL" },
271     { USE,              TOKENTYPE_IVAL,         "USE" },
272     { WHILE,            TOKENTYPE_IVAL,         "WHILE" },
273     { WORD,             TOKENTYPE_OPVAL,        "WORD" },
274     { 0,                TOKENTYPE_NONE,         0 }
275 };
276
277 /* dump the returned token in rv, plus any optional arg in yylval */
278
279 STATIC int
280 S_tokereport(pTHX_ const char* s, I32 rv)
281 {
282     if (DEBUG_T_TEST) {
283         const char *name = Nullch;
284         enum token_type type = TOKENTYPE_NONE;
285         const struct debug_tokens *p;
286         SV* const report = newSVpvn("<== ", 4);
287
288         for (p = debug_tokens; p->token; p++) {
289             if (p->token == (int)rv) {
290                 name = p->name;
291                 type = p->type;
292                 break;
293             }
294         }
295         if (name)
296             Perl_sv_catpv(aTHX_ report, name);
297         else if ((char)rv > ' ' && (char)rv < '~')
298             Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
299         else if (!rv)
300             Perl_sv_catpv(aTHX_ report, "EOF");
301         else
302             Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
303         switch (type) {
304         case TOKENTYPE_NONE:
305         case TOKENTYPE_GVVAL: /* doesn't appear to be used */
306             break;
307         case TOKENTYPE_IVAL:
308             Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)yylval.ival);
309             break;
310         case TOKENTYPE_OPNUM:
311             Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
312                                     PL_op_name[yylval.ival]);
313             break;
314         case TOKENTYPE_PVAL:
315             Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", yylval.pval);
316             break;
317         case TOKENTYPE_OPVAL:
318             if (yylval.opval)
319                 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
320                                     PL_op_name[yylval.opval->op_type]);
321             else
322                 Perl_sv_catpv(aTHX_ report, "(opval=null)");
323             break;
324         }
325         Perl_sv_catpvf(aTHX_ report, " at line %"IVdf" [", (IV)CopLINE(PL_curcop));
326         if (s - PL_bufptr > 0)
327             sv_catpvn(report, PL_bufptr, s - PL_bufptr);
328         else {
329             if (PL_oldbufptr && *PL_oldbufptr)
330                 sv_catpv(report, PL_tokenbuf);
331         }
332         PerlIO_printf(Perl_debug_log, "### %s]\n", SvPV_nolen_const(report));
333     };
334     return (int)rv;
335 }
336
337 #endif
338
339 /*
340  * S_ao
341  *
342  * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
343  * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
344  */
345
346 STATIC int
347 S_ao(pTHX_ int toketype)
348 {
349     if (*PL_bufptr == '=') {
350         PL_bufptr++;
351         if (toketype == ANDAND)
352             yylval.ival = OP_ANDASSIGN;
353         else if (toketype == OROR)
354             yylval.ival = OP_ORASSIGN;
355         else if (toketype == DORDOR)
356             yylval.ival = OP_DORASSIGN;
357         toketype = ASSIGNOP;
358     }
359     return toketype;
360 }
361
362 /*
363  * S_no_op
364  * When Perl expects an operator and finds something else, no_op
365  * prints the warning.  It always prints "<something> found where
366  * operator expected.  It prints "Missing semicolon on previous line?"
367  * if the surprise occurs at the start of the line.  "do you need to
368  * predeclare ..." is printed out for code like "sub bar; foo bar $x"
369  * where the compiler doesn't know if foo is a method call or a function.
370  * It prints "Missing operator before end of line" if there's nothing
371  * after the missing operator, or "... before <...>" if there is something
372  * after the missing operator.
373  */
374
375 STATIC void
376 S_no_op(pTHX_ const char *what, char *s)
377 {
378     char * const oldbp = PL_bufptr;
379     const bool is_first = (PL_oldbufptr == PL_linestart);
380
381     if (!s)
382         s = oldbp;
383     else
384         PL_bufptr = s;
385     yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
386     if (ckWARN_d(WARN_SYNTAX)) {
387         if (is_first)
388             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
389                     "\t(Missing semicolon on previous line?)\n");
390         else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
391             const char *t;
392             for (t = PL_oldoldbufptr; *t && (isALNUM_lazy_if(t,UTF) || *t == ':'); t++) ;
393             if (t < PL_bufptr && isSPACE(*t))
394                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
395                         "\t(Do you need to predeclare %.*s?)\n",
396                     t - PL_oldoldbufptr, PL_oldoldbufptr);
397         }
398         else {
399             assert(s >= oldbp);
400             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
401                     "\t(Missing operator before %.*s?)\n", s - oldbp, oldbp);
402         }
403     }
404     PL_bufptr = oldbp;
405 }
406
407 /*
408  * S_missingterm
409  * Complain about missing quote/regexp/heredoc terminator.
410  * If it's called with (char *)NULL then it cauterizes the line buffer.
411  * If we're in a delimited string and the delimiter is a control
412  * character, it's reformatted into a two-char sequence like ^C.
413  * This is fatal.
414  */
415
416 STATIC void
417 S_missingterm(pTHX_ char *s)
418 {
419     char tmpbuf[3];
420     char q;
421     if (s) {
422         char * const nl = strrchr(s,'\n');
423         if (nl)
424             *nl = '\0';
425     }
426     else if (
427 #ifdef EBCDIC
428         iscntrl(PL_multi_close)
429 #else
430         PL_multi_close < 32 || PL_multi_close == 127
431 #endif
432         ) {
433         *tmpbuf = '^';
434         tmpbuf[1] = toCTRL(PL_multi_close);
435         tmpbuf[2] = '\0';
436         s = tmpbuf;
437     }
438     else {
439         *tmpbuf = (char)PL_multi_close;
440         tmpbuf[1] = '\0';
441         s = tmpbuf;
442     }
443     q = strchr(s,'"') ? '\'' : '"';
444     Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
445 }
446
447 /*
448  * Perl_deprecate
449  */
450
451 void
452 Perl_deprecate(pTHX_ const char *s)
453 {
454     if (ckWARN(WARN_DEPRECATED))
455         Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
456 }
457
458 void
459 Perl_deprecate_old(pTHX_ const char *s)
460 {
461     /* This function should NOT be called for any new deprecated warnings */
462     /* Use Perl_deprecate instead                                         */
463     /*                                                                    */
464     /* It is here to maintain backward compatibility with the pre-5.8     */
465     /* warnings category hierarchy. The "deprecated" category used to     */
466     /* live under the "syntax" category. It is now a top-level category   */
467     /* in its own right.                                                  */
468
469     if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
470         Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
471                         "Use of %s is deprecated", s);
472 }
473
474 /*
475  * depcom
476  * Deprecate a comma-less variable list.
477  */
478
479 STATIC void
480 S_depcom(pTHX)
481 {
482     deprecate_old("comma-less variable list");
483 }
484
485 /*
486  * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
487  * utf16-to-utf8-reversed.
488  */
489
490 #ifdef PERL_CR_FILTER
491 static void
492 strip_return(SV *sv)
493 {
494     register const char *s = SvPVX_const(sv);
495     register const char * const e = s + SvCUR(sv);
496     /* outer loop optimized to do nothing if there are no CR-LFs */
497     while (s < e) {
498         if (*s++ == '\r' && *s == '\n') {
499             /* hit a CR-LF, need to copy the rest */
500             register char *d = s - 1;
501             *d++ = *s++;
502             while (s < e) {
503                 if (*s == '\r' && s[1] == '\n')
504                     s++;
505                 *d++ = *s++;
506             }
507             SvCUR(sv) -= s - d;
508             return;
509         }
510     }
511 }
512
513 STATIC I32
514 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
515 {
516     const I32 count = FILTER_READ(idx+1, sv, maxlen);
517     if (count > 0 && !maxlen)
518         strip_return(sv);
519     return count;
520 }
521 #endif
522
523 /*
524  * Perl_lex_start
525  * Initialize variables.  Uses the Perl save_stack to save its state (for
526  * recursive calls to the parser).
527  */
528
529 void
530 Perl_lex_start(pTHX_ SV *line)
531 {
532     const char *s;
533     STRLEN len;
534
535     SAVEI32(PL_lex_dojoin);
536     SAVEI32(PL_lex_brackets);
537     SAVEI32(PL_lex_casemods);
538     SAVEI32(PL_lex_starts);
539     SAVEI32(PL_lex_state);
540     SAVEVPTR(PL_lex_inpat);
541     SAVEI32(PL_lex_inwhat);
542     if (PL_lex_state == LEX_KNOWNEXT) {
543         I32 toke = PL_nexttoke;
544         while (--toke >= 0) {
545             SAVEI32(PL_nexttype[toke]);
546             SAVEVPTR(PL_nextval[toke]);
547         }
548         SAVEI32(PL_nexttoke);
549     }
550     SAVECOPLINE(PL_curcop);
551     SAVEPPTR(PL_bufptr);
552     SAVEPPTR(PL_bufend);
553     SAVEPPTR(PL_oldbufptr);
554     SAVEPPTR(PL_oldoldbufptr);
555     SAVEPPTR(PL_last_lop);
556     SAVEPPTR(PL_last_uni);
557     SAVEPPTR(PL_linestart);
558     SAVESPTR(PL_linestr);
559     SAVEGENERICPV(PL_lex_brackstack);
560     SAVEGENERICPV(PL_lex_casestack);
561     SAVEDESTRUCTOR_X(restore_rsfp, PL_rsfp);
562     SAVESPTR(PL_lex_stuff);
563     SAVEI32(PL_lex_defer);
564     SAVEI32(PL_sublex_info.sub_inwhat);
565     SAVESPTR(PL_lex_repl);
566     SAVEINT(PL_expect);
567     SAVEINT(PL_lex_expect);
568
569     PL_lex_state = LEX_NORMAL;
570     PL_lex_defer = 0;
571     PL_expect = XSTATE;
572     PL_lex_brackets = 0;
573     Newx(PL_lex_brackstack, 120, char);
574     Newx(PL_lex_casestack, 12, char);
575     PL_lex_casemods = 0;
576     *PL_lex_casestack = '\0';
577     PL_lex_dojoin = 0;
578     PL_lex_starts = 0;
579     PL_lex_stuff = Nullsv;
580     PL_lex_repl = Nullsv;
581     PL_lex_inpat = 0;
582     PL_nexttoke = 0;
583     PL_lex_inwhat = 0;
584     PL_sublex_info.sub_inwhat = 0;
585     PL_linestr = line;
586     if (SvREADONLY(PL_linestr))
587         PL_linestr = sv_2mortal(newSVsv(PL_linestr));
588     s = SvPV_const(PL_linestr, len);
589     if (!len || s[len-1] != ';') {
590         if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
591             PL_linestr = sv_2mortal(newSVsv(PL_linestr));
592         sv_catpvn(PL_linestr, "\n;", 2);
593     }
594     SvTEMP_off(PL_linestr);
595     PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
596     PL_bufend = PL_bufptr + SvCUR(PL_linestr);
597     PL_last_lop = PL_last_uni = Nullch;
598     PL_rsfp = 0;
599 }
600
601 /*
602  * Perl_lex_end
603  * Finalizer for lexing operations.  Must be called when the parser is
604  * done with the lexer.
605  */
606
607 void
608 Perl_lex_end(pTHX)
609 {
610     PL_doextract = FALSE;
611 }
612
613 /*
614  * S_incline
615  * This subroutine has nothing to do with tilting, whether at windmills
616  * or pinball tables.  Its name is short for "increment line".  It
617  * increments the current line number in CopLINE(PL_curcop) and checks
618  * to see whether the line starts with a comment of the form
619  *    # line 500 "foo.pm"
620  * If so, it sets the current line number and file to the values in the comment.
621  */
622
623 STATIC void
624 S_incline(pTHX_ char *s)
625 {
626     char *t;
627     char *n;
628     char *e;
629     char ch;
630
631     CopLINE_inc(PL_curcop);
632     if (*s++ != '#')
633         return;
634     while (SPACE_OR_TAB(*s)) s++;
635     if (strnEQ(s, "line", 4))
636         s += 4;
637     else
638         return;
639     if (SPACE_OR_TAB(*s))
640         s++;
641     else
642         return;
643     while (SPACE_OR_TAB(*s)) s++;
644     if (!isDIGIT(*s))
645         return;
646     n = s;
647     while (isDIGIT(*s))
648         s++;
649     while (SPACE_OR_TAB(*s))
650         s++;
651     if (*s == '"' && (t = strchr(s+1, '"'))) {
652         s++;
653         e = t + 1;
654     }
655     else {
656         for (t = s; !isSPACE(*t); t++) ;
657         e = t;
658     }
659     while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
660         e++;
661     if (*e != '\n' && *e != '\0')
662         return;         /* false alarm */
663
664     ch = *t;
665     *t = '\0';
666     if (t - s > 0) {
667         const char *cf = CopFILE(PL_curcop);
668         if (cf && strlen(cf) > 7 && strnEQ(cf, "(eval ", 6)) {
669             /* must copy *{"::_<(eval N)[oldfilename:L]"}
670              * to *{"::_<newfilename"} */
671             char smallbuf[256], smallbuf2[256];
672             char *tmpbuf, *tmpbuf2;
673             GV *gv, *gv2;
674             STRLEN tmplen = strlen(cf);
675             STRLEN tmplen2 = strlen(s);
676             if (tmplen + 3 < sizeof smallbuf)
677                 tmpbuf = smallbuf;
678             else
679                 Newx(tmpbuf, tmplen + 3, char);
680             if (tmplen2 + 3 < sizeof smallbuf2)
681                 tmpbuf2 = smallbuf2;
682             else
683                 Newx(tmpbuf2, tmplen2 + 3, char);
684             tmpbuf[0] = tmpbuf2[0] = '_';
685             tmpbuf[1] = tmpbuf2[1] = '<';
686             memcpy(tmpbuf + 2, cf, ++tmplen);
687             memcpy(tmpbuf2 + 2, s, ++tmplen2);
688             ++tmplen; ++tmplen2;
689             gv = *(GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
690             gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
691             if (!isGV(gv2))
692                 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
693             /* adjust ${"::_<newfilename"} to store the new file name */
694             GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
695             GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(gv));
696             GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(gv));
697             if (tmpbuf != smallbuf) Safefree(tmpbuf);
698             if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
699         }
700         CopFILE_free(PL_curcop);
701         CopFILE_set(PL_curcop, s);
702     }
703     *t = ch;
704     CopLINE_set(PL_curcop, atoi(n)-1);
705 }
706
707 /*
708  * S_skipspace
709  * Called to gobble the appropriate amount and type of whitespace.
710  * Skips comments as well.
711  */
712
713 STATIC char *
714 S_skipspace(pTHX_ register char *s)
715 {
716     if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
717         while (s < PL_bufend && SPACE_OR_TAB(*s))
718             s++;
719         return s;
720     }
721     for (;;) {
722         STRLEN prevlen;
723         SSize_t oldprevlen, oldoldprevlen;
724         SSize_t oldloplen = 0, oldunilen = 0;
725         while (s < PL_bufend && isSPACE(*s)) {
726             if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
727                 incline(s);
728         }
729
730         /* comment */
731         if (s < PL_bufend && *s == '#') {
732             while (s < PL_bufend && *s != '\n')
733                 s++;
734             if (s < PL_bufend) {
735                 s++;
736                 if (PL_in_eval && !PL_rsfp) {
737                     incline(s);
738                     continue;
739                 }
740             }
741         }
742
743         /* only continue to recharge the buffer if we're at the end
744          * of the buffer, we're not reading from a source filter, and
745          * we're in normal lexing mode
746          */
747         if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
748                 PL_lex_state == LEX_FORMLINE)
749             return s;
750
751         /* try to recharge the buffer */
752         if ((s = filter_gets(PL_linestr, PL_rsfp,
753                              (prevlen = SvCUR(PL_linestr)))) == Nullch)
754         {
755             /* end of file.  Add on the -p or -n magic */
756             if (PL_minus_p) {
757                 sv_setpv(PL_linestr,
758                          ";}continue{print or die qq(-p destination: $!\\n);}");
759                 PL_minus_n = PL_minus_p = 0;
760             }
761             else if (PL_minus_n) {
762                 sv_setpvn(PL_linestr, ";}", 2);
763                 PL_minus_n = 0;
764             }
765             else
766                 sv_setpvn(PL_linestr,";", 1);
767
768             /* reset variables for next time we lex */
769             PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
770                 = SvPVX(PL_linestr);
771             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
772             PL_last_lop = PL_last_uni = Nullch;
773
774             /* Close the filehandle.  Could be from -P preprocessor,
775              * STDIN, or a regular file.  If we were reading code from
776              * STDIN (because the commandline held no -e or filename)
777              * then we don't close it, we reset it so the code can
778              * read from STDIN too.
779              */
780
781             if (PL_preprocess && !PL_in_eval)
782                 (void)PerlProc_pclose(PL_rsfp);
783             else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
784                 PerlIO_clearerr(PL_rsfp);
785             else
786                 (void)PerlIO_close(PL_rsfp);
787             PL_rsfp = Nullfp;
788             return s;
789         }
790
791         /* not at end of file, so we only read another line */
792         /* make corresponding updates to old pointers, for yyerror() */
793         oldprevlen = PL_oldbufptr - PL_bufend;
794         oldoldprevlen = PL_oldoldbufptr - PL_bufend;
795         if (PL_last_uni)
796             oldunilen = PL_last_uni - PL_bufend;
797         if (PL_last_lop)
798             oldloplen = PL_last_lop - PL_bufend;
799         PL_linestart = PL_bufptr = s + prevlen;
800         PL_bufend = s + SvCUR(PL_linestr);
801         s = PL_bufptr;
802         PL_oldbufptr = s + oldprevlen;
803         PL_oldoldbufptr = s + oldoldprevlen;
804         if (PL_last_uni)
805             PL_last_uni = s + oldunilen;
806         if (PL_last_lop)
807             PL_last_lop = s + oldloplen;
808         incline(s);
809
810         /* debugger active and we're not compiling the debugger code,
811          * so store the line into the debugger's array of lines
812          */
813         if (PERLDB_LINE && PL_curstash != PL_debstash) {
814             SV * const sv = NEWSV(85,0);
815
816             sv_upgrade(sv, SVt_PVMG);
817             sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
818             (void)SvIOK_on(sv);
819             SvIV_set(sv, 0);
820             av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
821         }
822     }
823 }
824
825 /*
826  * S_check_uni
827  * Check the unary operators to ensure there's no ambiguity in how they're
828  * used.  An ambiguous piece of code would be:
829  *     rand + 5
830  * This doesn't mean rand() + 5.  Because rand() is a unary operator,
831  * the +5 is its argument.
832  */
833
834 STATIC void
835 S_check_uni(pTHX)
836 {
837     char *s;
838     char *t;
839
840     if (PL_oldoldbufptr != PL_last_uni)
841         return;
842     while (isSPACE(*PL_last_uni))
843         PL_last_uni++;
844     for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
845     if ((t = strchr(s, '(')) && t < PL_bufptr)
846         return;
847     if (ckWARN_d(WARN_AMBIGUOUS)){
848         const char ch = *s;
849         *s = '\0';
850         Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
851                    "Warning: Use of \"%s\" without parentheses is ambiguous",
852                    PL_last_uni);
853         *s = ch;
854     }
855 }
856
857 /*
858  * LOP : macro to build a list operator.  Its behaviour has been replaced
859  * with a subroutine, S_lop() for which LOP is just another name.
860  */
861
862 #define LOP(f,x) return lop(f,x,s)
863
864 /*
865  * S_lop
866  * Build a list operator (or something that might be one).  The rules:
867  *  - if we have a next token, then it's a list operator [why?]
868  *  - if the next thing is an opening paren, then it's a function
869  *  - else it's a list operator
870  */
871
872 STATIC I32
873 S_lop(pTHX_ I32 f, int x, char *s)
874 {
875     yylval.ival = f;
876     CLINE;
877     PL_expect = x;
878     PL_bufptr = s;
879     PL_last_lop = PL_oldbufptr;
880     PL_last_lop_op = (OPCODE)f;
881     if (PL_nexttoke)
882         return REPORT(LSTOP);
883     if (*s == '(')
884         return REPORT(FUNC);
885     s = skipspace(s);
886     if (*s == '(')
887         return REPORT(FUNC);
888     else
889         return REPORT(LSTOP);
890 }
891
892 /*
893  * S_force_next
894  * When the lexer realizes it knows the next token (for instance,
895  * it is reordering tokens for the parser) then it can call S_force_next
896  * to know what token to return the next time the lexer is called.  Caller
897  * will need to set PL_nextval[], and possibly PL_expect to ensure the lexer
898  * handles the token correctly.
899  */
900
901 STATIC void
902 S_force_next(pTHX_ I32 type)
903 {
904     PL_nexttype[PL_nexttoke] = type;
905     PL_nexttoke++;
906     if (PL_lex_state != LEX_KNOWNEXT) {
907         PL_lex_defer = PL_lex_state;
908         PL_lex_expect = PL_expect;
909         PL_lex_state = LEX_KNOWNEXT;
910     }
911 }
912
913 STATIC SV *
914 S_newSV_maybe_utf8(pTHX_ const char *start, STRLEN len)
915 {
916     SV * const sv = newSVpvn(start,len);
917     if (UTF && !IN_BYTES && is_utf8_string((const U8*)start, len))
918         SvUTF8_on(sv);
919     return sv;
920 }
921
922 /*
923  * S_force_word
924  * When the lexer knows the next thing is a word (for instance, it has
925  * just seen -> and it knows that the next char is a word char, then
926  * it calls S_force_word to stick the next word into the PL_next lookahead.
927  *
928  * Arguments:
929  *   char *start : buffer position (must be within PL_linestr)
930  *   int token   : PL_next will be this type of bare word (e.g., METHOD,WORD)
931  *   int check_keyword : if true, Perl checks to make sure the word isn't
932  *       a keyword (do this if the word is a label, e.g. goto FOO)
933  *   int allow_pack : if true, : characters will also be allowed (require,
934  *       use, etc. do this)
935  *   int allow_initial_tick : used by the "sub" lexer only.
936  */
937
938 STATIC char *
939 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
940 {
941     register char *s;
942     STRLEN len;
943
944     start = skipspace(start);
945     s = start;
946     if (isIDFIRST_lazy_if(s,UTF) ||
947         (allow_pack && *s == ':') ||
948         (allow_initial_tick && *s == '\'') )
949     {
950         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
951         if (check_keyword && keyword(PL_tokenbuf, len))
952             return start;
953         if (token == METHOD) {
954             s = skipspace(s);
955             if (*s == '(')
956                 PL_expect = XTERM;
957             else {
958                 PL_expect = XOPERATOR;
959             }
960         }
961         PL_nextval[PL_nexttoke].opval
962             = (OP*)newSVOP(OP_CONST,0,
963                            S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
964         PL_nextval[PL_nexttoke].opval->op_private |= OPpCONST_BARE;
965         force_next(token);
966     }
967     return s;
968 }
969
970 /*
971  * S_force_ident
972  * Called when the lexer wants $foo *foo &foo etc, but the program
973  * text only contains the "foo" portion.  The first argument is a pointer
974  * to the "foo", and the second argument is the type symbol to prefix.
975  * Forces the next token to be a "WORD".
976  * Creates the symbol if it didn't already exist (via gv_fetchpv()).
977  */
978
979 STATIC void
980 S_force_ident(pTHX_ register const char *s, int kind)
981 {
982     if (s && *s) {
983         OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpv(s,0));
984         PL_nextval[PL_nexttoke].opval = o;
985         force_next(WORD);
986         if (kind) {
987             o->op_private = OPpCONST_ENTERED;
988             /* XXX see note in pp_entereval() for why we forgo typo
989                warnings if the symbol must be introduced in an eval.
990                GSAR 96-10-12 */
991             gv_fetchpv(s, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
992                 kind == '$' ? SVt_PV :
993                 kind == '@' ? SVt_PVAV :
994                 kind == '%' ? SVt_PVHV :
995                               SVt_PVGV
996                 );
997         }
998     }
999 }
1000
1001 NV
1002 Perl_str_to_version(pTHX_ SV *sv)
1003 {
1004     NV retval = 0.0;
1005     NV nshift = 1.0;
1006     STRLEN len;
1007     const char *start = SvPV_const(sv,len);
1008     const char * const end = start + len;
1009     const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1010     while (start < end) {
1011         STRLEN skip;
1012         UV n;
1013         if (utf)
1014             n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1015         else {
1016             n = *(U8*)start;
1017             skip = 1;
1018         }
1019         retval += ((NV)n)/nshift;
1020         start += skip;
1021         nshift *= 1000;
1022     }
1023     return retval;
1024 }
1025
1026 /*
1027  * S_force_version
1028  * Forces the next token to be a version number.
1029  * If the next token appears to be an invalid version number, (e.g. "v2b"),
1030  * and if "guessing" is TRUE, then no new token is created (and the caller
1031  * must use an alternative parsing method).
1032  */
1033
1034 STATIC char *
1035 S_force_version(pTHX_ char *s, int guessing)
1036 {
1037     OP *version = Nullop;
1038     char *d;
1039
1040     s = skipspace(s);
1041
1042     d = s;
1043     if (*d == 'v')
1044         d++;
1045     if (isDIGIT(*d)) {
1046         while (isDIGIT(*d) || *d == '_' || *d == '.')
1047             d++;
1048         if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1049             SV *ver;
1050             s = scan_num(s, &yylval);
1051             version = yylval.opval;
1052             ver = cSVOPx(version)->op_sv;
1053             if (SvPOK(ver) && !SvNIOK(ver)) {
1054                 SvUPGRADE(ver, SVt_PVNV);
1055                 SvNV_set(ver, str_to_version(ver));
1056                 SvNOK_on(ver);          /* hint that it is a version */
1057             }
1058         }
1059         else if (guessing)
1060             return s;
1061     }
1062
1063     /* NOTE: The parser sees the package name and the VERSION swapped */
1064     PL_nextval[PL_nexttoke].opval = version;
1065     force_next(WORD);
1066
1067     return s;
1068 }
1069
1070 /*
1071  * S_tokeq
1072  * Tokenize a quoted string passed in as an SV.  It finds the next
1073  * chunk, up to end of string or a backslash.  It may make a new
1074  * SV containing that chunk (if HINT_NEW_STRING is on).  It also
1075  * turns \\ into \.
1076  */
1077
1078 STATIC SV *
1079 S_tokeq(pTHX_ SV *sv)
1080 {
1081     register char *s;
1082     register char *send;
1083     register char *d;
1084     STRLEN len = 0;
1085     SV *pv = sv;
1086
1087     if (!SvLEN(sv))
1088         goto finish;
1089
1090     s = SvPV_force(sv, len);
1091     if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1092         goto finish;
1093     send = s + len;
1094     while (s < send && *s != '\\')
1095         s++;
1096     if (s == send)
1097         goto finish;
1098     d = s;
1099     if ( PL_hints & HINT_NEW_STRING ) {
1100         pv = sv_2mortal(newSVpvn(SvPVX_const(pv), len));
1101         if (SvUTF8(sv))
1102             SvUTF8_on(pv);
1103     }
1104     while (s < send) {
1105         if (*s == '\\') {
1106             if (s + 1 < send && (s[1] == '\\'))
1107                 s++;            /* all that, just for this */
1108         }
1109         *d++ = *s++;
1110     }
1111     *d = '\0';
1112     SvCUR_set(sv, d - SvPVX_const(sv));
1113   finish:
1114     if ( PL_hints & HINT_NEW_STRING )
1115        return new_constant(NULL, 0, "q", sv, pv, "q");
1116     return sv;
1117 }
1118
1119 /*
1120  * Now come three functions related to double-quote context,
1121  * S_sublex_start, S_sublex_push, and S_sublex_done.  They're used when
1122  * converting things like "\u\Lgnat" into ucfirst(lc("gnat")).  They
1123  * interact with PL_lex_state, and create fake ( ... ) argument lists
1124  * to handle functions and concatenation.
1125  * They assume that whoever calls them will be setting up a fake
1126  * join call, because each subthing puts a ',' after it.  This lets
1127  *   "lower \luPpEr"
1128  * become
1129  *  join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1130  *
1131  * (I'm not sure whether the spurious commas at the end of lcfirst's
1132  * arguments and join's arguments are created or not).
1133  */
1134
1135 /*
1136  * S_sublex_start
1137  * Assumes that yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1138  *
1139  * Pattern matching will set PL_lex_op to the pattern-matching op to
1140  * make (we return THING if yylval.ival is OP_NULL, PMFUNC otherwise).
1141  *
1142  * OP_CONST and OP_READLINE are easy--just make the new op and return.
1143  *
1144  * Everything else becomes a FUNC.
1145  *
1146  * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1147  * had an OP_CONST or OP_READLINE).  This just sets us up for a
1148  * call to S_sublex_push().
1149  */
1150
1151 STATIC I32
1152 S_sublex_start(pTHX)
1153 {
1154     const register I32 op_type = yylval.ival;
1155
1156     if (op_type == OP_NULL) {
1157         yylval.opval = PL_lex_op;
1158         PL_lex_op = Nullop;
1159         return THING;
1160     }
1161     if (op_type == OP_CONST || op_type == OP_READLINE) {
1162         SV *sv = tokeq(PL_lex_stuff);
1163
1164         if (SvTYPE(sv) == SVt_PVIV) {
1165             /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1166             STRLEN len;
1167             const char *p = SvPV_const(sv, len);
1168             SV * const nsv = newSVpvn(p, len);
1169             if (SvUTF8(sv))
1170                 SvUTF8_on(nsv);
1171             SvREFCNT_dec(sv);
1172             sv = nsv;
1173         }
1174         yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1175         PL_lex_stuff = Nullsv;
1176         /* Allow <FH> // "foo" */
1177         if (op_type == OP_READLINE)
1178             PL_expect = XTERMORDORDOR;
1179         return THING;
1180     }
1181
1182     PL_sublex_info.super_state = PL_lex_state;
1183     PL_sublex_info.sub_inwhat = op_type;
1184     PL_sublex_info.sub_op = PL_lex_op;
1185     PL_lex_state = LEX_INTERPPUSH;
1186
1187     PL_expect = XTERM;
1188     if (PL_lex_op) {
1189         yylval.opval = PL_lex_op;
1190         PL_lex_op = Nullop;
1191         return PMFUNC;
1192     }
1193     else
1194         return FUNC;
1195 }
1196
1197 /*
1198  * S_sublex_push
1199  * Create a new scope to save the lexing state.  The scope will be
1200  * ended in S_sublex_done.  Returns a '(', starting the function arguments
1201  * to the uc, lc, etc. found before.
1202  * Sets PL_lex_state to LEX_INTERPCONCAT.
1203  */
1204
1205 STATIC I32
1206 S_sublex_push(pTHX)
1207 {
1208     dVAR;
1209     ENTER;
1210
1211     PL_lex_state = PL_sublex_info.super_state;
1212     SAVEI32(PL_lex_dojoin);
1213     SAVEI32(PL_lex_brackets);
1214     SAVEI32(PL_lex_casemods);
1215     SAVEI32(PL_lex_starts);
1216     SAVEI32(PL_lex_state);
1217     SAVEVPTR(PL_lex_inpat);
1218     SAVEI32(PL_lex_inwhat);
1219     SAVECOPLINE(PL_curcop);
1220     SAVEPPTR(PL_bufptr);
1221     SAVEPPTR(PL_bufend);
1222     SAVEPPTR(PL_oldbufptr);
1223     SAVEPPTR(PL_oldoldbufptr);
1224     SAVEPPTR(PL_last_lop);
1225     SAVEPPTR(PL_last_uni);
1226     SAVEPPTR(PL_linestart);
1227     SAVESPTR(PL_linestr);
1228     SAVEGENERICPV(PL_lex_brackstack);
1229     SAVEGENERICPV(PL_lex_casestack);
1230
1231     PL_linestr = PL_lex_stuff;
1232     PL_lex_stuff = Nullsv;
1233
1234     PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1235         = SvPVX(PL_linestr);
1236     PL_bufend += SvCUR(PL_linestr);
1237     PL_last_lop = PL_last_uni = Nullch;
1238     SAVEFREESV(PL_linestr);
1239
1240     PL_lex_dojoin = FALSE;
1241     PL_lex_brackets = 0;
1242     Newx(PL_lex_brackstack, 120, char);
1243     Newx(PL_lex_casestack, 12, char);
1244     PL_lex_casemods = 0;
1245     *PL_lex_casestack = '\0';
1246     PL_lex_starts = 0;
1247     PL_lex_state = LEX_INTERPCONCAT;
1248     CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1249
1250     PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1251     if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1252         PL_lex_inpat = PL_sublex_info.sub_op;
1253     else
1254         PL_lex_inpat = Nullop;
1255
1256     return '(';
1257 }
1258
1259 /*
1260  * S_sublex_done
1261  * Restores lexer state after a S_sublex_push.
1262  */
1263
1264 STATIC I32
1265 S_sublex_done(pTHX)
1266 {
1267     dVAR;
1268     if (!PL_lex_starts++) {
1269         SV * const sv = newSVpvn("",0);
1270         if (SvUTF8(PL_linestr))
1271             SvUTF8_on(sv);
1272         PL_expect = XOPERATOR;
1273         yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1274         return THING;
1275     }
1276
1277     if (PL_lex_casemods) {              /* oops, we've got some unbalanced parens */
1278         PL_lex_state = LEX_INTERPCASEMOD;
1279         return yylex();
1280     }
1281
1282     /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1283     if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1284         PL_linestr = PL_lex_repl;
1285         PL_lex_inpat = 0;
1286         PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1287         PL_bufend += SvCUR(PL_linestr);
1288         PL_last_lop = PL_last_uni = Nullch;
1289         SAVEFREESV(PL_linestr);
1290         PL_lex_dojoin = FALSE;
1291         PL_lex_brackets = 0;
1292         PL_lex_casemods = 0;
1293         *PL_lex_casestack = '\0';
1294         PL_lex_starts = 0;
1295         if (SvEVALED(PL_lex_repl)) {
1296             PL_lex_state = LEX_INTERPNORMAL;
1297             PL_lex_starts++;
1298             /*  we don't clear PL_lex_repl here, so that we can check later
1299                 whether this is an evalled subst; that means we rely on the
1300                 logic to ensure sublex_done() is called again only via the
1301                 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1302         }
1303         else {
1304             PL_lex_state = LEX_INTERPCONCAT;
1305             PL_lex_repl = Nullsv;
1306         }
1307         return ',';
1308     }
1309     else {
1310         LEAVE;
1311         PL_bufend = SvPVX(PL_linestr);
1312         PL_bufend += SvCUR(PL_linestr);
1313         PL_expect = XOPERATOR;
1314         PL_sublex_info.sub_inwhat = 0;
1315         return ')';
1316     }
1317 }
1318
1319 /*
1320   scan_const
1321
1322   Extracts a pattern, double-quoted string, or transliteration.  This
1323   is terrifying code.
1324
1325   It looks at lex_inwhat and PL_lex_inpat to find out whether it's
1326   processing a pattern (PL_lex_inpat is true), a transliteration
1327   (lex_inwhat & OP_TRANS is true), or a double-quoted string.
1328
1329   Returns a pointer to the character scanned up to. Iff this is
1330   advanced from the start pointer supplied (ie if anything was
1331   successfully parsed), will leave an OP for the substring scanned
1332   in yylval. Caller must intuit reason for not parsing further
1333   by looking at the next characters herself.
1334
1335   In patterns:
1336     backslashes:
1337       double-quoted style: \r and \n
1338       regexp special ones: \D \s
1339       constants: \x3
1340       backrefs: \1 (deprecated in substitution replacements)
1341       case and quoting: \U \Q \E
1342     stops on @ and $, but not for $ as tail anchor
1343
1344   In transliterations:
1345     characters are VERY literal, except for - not at the start or end
1346     of the string, which indicates a range.  scan_const expands the
1347     range to the full set of intermediate characters.
1348
1349   In double-quoted strings:
1350     backslashes:
1351       double-quoted style: \r and \n
1352       constants: \x3
1353       backrefs: \1 (deprecated)
1354       case and quoting: \U \Q \E
1355     stops on @ and $
1356
1357   scan_const does *not* construct ops to handle interpolated strings.
1358   It stops processing as soon as it finds an embedded $ or @ variable
1359   and leaves it to the caller to work out what's going on.
1360
1361   @ in pattern could be: @foo, @{foo}, @$foo, @'foo, @::foo.
1362
1363   $ in pattern could be $foo or could be tail anchor.  Assumption:
1364   it's a tail anchor if $ is the last thing in the string, or if it's
1365   followed by one of ")| \n\t"
1366
1367   \1 (backreferences) are turned into $1
1368
1369   The structure of the code is
1370       while (there's a character to process) {
1371           handle transliteration ranges
1372           skip regexp comments
1373           skip # initiated comments in //x patterns
1374           check for embedded @foo
1375           check for embedded scalars
1376           if (backslash) {
1377               leave intact backslashes from leave (below)
1378               deprecate \1 in strings and sub replacements
1379               handle string-changing backslashes \l \U \Q \E, etc.
1380               switch (what was escaped) {
1381                   handle - in a transliteration (becomes a literal -)
1382                   handle \132 octal characters
1383                   handle 0x15 hex characters
1384                   handle \cV (control V)
1385                   handle printf backslashes (\f, \r, \n, etc)
1386               } (end switch)
1387           } (end if backslash)
1388     } (end while character to read)
1389                 
1390 */
1391
1392 STATIC char *
1393 S_scan_const(pTHX_ char *start)
1394 {
1395     register char *send = PL_bufend;            /* end of the constant */
1396     SV *sv = NEWSV(93, send - start);           /* sv for the constant */
1397     register char *s = start;                   /* start of the constant */
1398     register char *d = SvPVX(sv);               /* destination for copies */
1399     bool dorange = FALSE;                       /* are we in a translit range? */
1400     bool didrange = FALSE;                      /* did we just finish a range? */
1401     I32  has_utf8 = FALSE;                      /* Output constant is UTF8 */
1402     I32  this_utf8 = UTF;                       /* The source string is assumed to be UTF8 */
1403     UV uv;
1404 #ifdef EBCDIC
1405     UV literal_endpoint = 0;
1406 #endif
1407
1408     const char *leaveit =       /* set of acceptably-backslashed characters */
1409         PL_lex_inpat
1410             ? "\\.^$@AGZdDwWsSbBpPXC+*?|()-nrtfeaxz0123456789[{]} \t\n\r\f\v#"
1411             : "";
1412
1413     if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1414         /* If we are doing a trans and we know we want UTF8 set expectation */
1415         has_utf8   = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1416         this_utf8  = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1417     }
1418
1419
1420     while (s < send || dorange) {
1421         /* get transliterations out of the way (they're most literal) */
1422         if (PL_lex_inwhat == OP_TRANS) {
1423             /* expand a range A-Z to the full set of characters.  AIE! */
1424             if (dorange) {
1425                 I32 i;                          /* current expanded character */
1426                 I32 min;                        /* first character in range */
1427                 I32 max;                        /* last character in range */
1428
1429                 if (has_utf8) {
1430                     char * const c = (char*)utf8_hop((U8*)d, -1);
1431                     char *e = d++;
1432                     while (e-- > c)
1433                         *(e + 1) = *e;
1434                     *c = (char)UTF_TO_NATIVE(0xff);
1435                     /* mark the range as done, and continue */
1436                     dorange = FALSE;
1437                     didrange = TRUE;
1438                     continue;
1439                 }
1440
1441                 i = d - SvPVX_const(sv);                /* remember current offset */
1442                 SvGROW(sv, SvLEN(sv) + 256);    /* never more than 256 chars in a range */
1443                 d = SvPVX(sv) + i;              /* refresh d after realloc */
1444                 d -= 2;                         /* eat the first char and the - */
1445
1446                 min = (U8)*d;                   /* first char in range */
1447                 max = (U8)d[1];                 /* last char in range  */
1448
1449                 if (min > max) {
1450                     Perl_croak(aTHX_
1451                                "Invalid range \"%c-%c\" in transliteration operator",
1452                                (char)min, (char)max);
1453                 }
1454
1455 #ifdef EBCDIC
1456                 if (literal_endpoint == 2 &&
1457                     ((isLOWER(min) && isLOWER(max)) ||
1458                      (isUPPER(min) && isUPPER(max)))) {
1459                     if (isLOWER(min)) {
1460                         for (i = min; i <= max; i++)
1461                             if (isLOWER(i))
1462                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
1463                     } else {
1464                         for (i = min; i <= max; i++)
1465                             if (isUPPER(i))
1466                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
1467                     }
1468                 }
1469                 else
1470 #endif
1471                     for (i = min; i <= max; i++)
1472                         *d++ = (char)i;
1473
1474                 /* mark the range as done, and continue */
1475                 dorange = FALSE;
1476                 didrange = TRUE;
1477 #ifdef EBCDIC
1478                 literal_endpoint = 0;
1479 #endif
1480                 continue;
1481             }
1482
1483             /* range begins (ignore - as first or last char) */
1484             else if (*s == '-' && s+1 < send  && s != start) {
1485                 if (didrange) {
1486                     Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
1487                 }
1488                 if (has_utf8) {
1489                     *d++ = (char)UTF_TO_NATIVE(0xff);   /* use illegal utf8 byte--see pmtrans */
1490                     s++;
1491                     continue;
1492                 }
1493                 dorange = TRUE;
1494                 s++;
1495             }
1496             else {
1497                 didrange = FALSE;
1498 #ifdef EBCDIC
1499                 literal_endpoint = 0;
1500 #endif
1501             }
1502         }
1503
1504         /* if we get here, we're not doing a transliteration */
1505
1506         /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
1507            except for the last char, which will be done separately. */
1508         else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
1509             if (s[2] == '#') {
1510                 while (s+1 < send && *s != ')')
1511                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1512             }
1513             else if (s[2] == '{' /* This should match regcomp.c */
1514                      || ((s[2] == 'p' || s[2] == '?') && s[3] == '{'))
1515             {
1516                 I32 count = 1;
1517                 char *regparse = s + (s[2] == '{' ? 3 : 4);
1518                 char c;
1519
1520                 while (count && (c = *regparse)) {
1521                     if (c == '\\' && regparse[1])
1522                         regparse++;
1523                     else if (c == '{')
1524                         count++;
1525                     else if (c == '}')
1526                         count--;
1527                     regparse++;
1528                 }
1529                 if (*regparse != ')')
1530                     regparse--;         /* Leave one char for continuation. */
1531                 while (s < regparse)
1532                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1533             }
1534         }
1535
1536         /* likewise skip #-initiated comments in //x patterns */
1537         else if (*s == '#' && PL_lex_inpat &&
1538           ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
1539             while (s+1 < send && *s != '\n')
1540                 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1541         }
1542
1543         /* check for embedded arrays
1544            (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
1545            */
1546         else if (*s == '@' && s[1]
1547                  && (isALNUM_lazy_if(s+1,UTF) || strchr(":'{$+-", s[1])))
1548             break;
1549
1550         /* check for embedded scalars.  only stop if we're sure it's a
1551            variable.
1552         */
1553         else if (*s == '$') {
1554             if (!PL_lex_inpat)  /* not a regexp, so $ must be var */
1555                 break;
1556             if (s + 1 < send && !strchr("()| \r\n\t", s[1]))
1557                 break;          /* in regexp, $ might be tail anchor */
1558         }
1559
1560         /* End of else if chain - OP_TRANS rejoin rest */
1561
1562         /* backslashes */
1563         if (*s == '\\' && s+1 < send) {
1564             s++;
1565
1566             /* some backslashes we leave behind */
1567             if (*leaveit && *s && strchr(leaveit, *s)) {
1568                 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
1569                 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1570                 continue;
1571             }
1572
1573             /* deprecate \1 in strings and substitution replacements */
1574             if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
1575                 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
1576             {
1577                 if (ckWARN(WARN_SYNTAX))
1578                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
1579                 *--s = '$';
1580                 break;
1581             }
1582
1583             /* string-change backslash escapes */
1584             if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
1585                 --s;
1586                 break;
1587             }
1588
1589             /* if we get here, it's either a quoted -, or a digit */
1590             switch (*s) {
1591
1592             /* quoted - in transliterations */
1593             case '-':
1594                 if (PL_lex_inwhat == OP_TRANS) {
1595                     *d++ = *s++;
1596                     continue;
1597                 }
1598                 /* FALL THROUGH */
1599             default:
1600                 {
1601                     if (isALNUM(*s) &&
1602                         *s != '_' &&
1603                         ckWARN(WARN_MISC))
1604                         Perl_warner(aTHX_ packWARN(WARN_MISC),
1605                                "Unrecognized escape \\%c passed through",
1606                                *s);
1607                     /* default action is to copy the quoted character */
1608                     goto default_action;
1609                 }
1610
1611             /* \132 indicates an octal constant */
1612             case '0': case '1': case '2': case '3':
1613             case '4': case '5': case '6': case '7':
1614                 {
1615                     I32 flags = 0;
1616                     STRLEN len = 3;
1617                     uv = grok_oct(s, &len, &flags, NULL);
1618                     s += len;
1619                 }
1620                 goto NUM_ESCAPE_INSERT;
1621
1622             /* \x24 indicates a hex constant */
1623             case 'x':
1624                 ++s;
1625                 if (*s == '{') {
1626                     char* const e = strchr(s, '}');
1627                     I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1628                       PERL_SCAN_DISALLOW_PREFIX;
1629                     STRLEN len;
1630
1631                     ++s;
1632                     if (!e) {
1633                         yyerror("Missing right brace on \\x{}");
1634                         continue;
1635                     }
1636                     len = e - s;
1637                     uv = grok_hex(s, &len, &flags, NULL);
1638                     s = e + 1;
1639                 }
1640                 else {
1641                     {
1642                         STRLEN len = 2;
1643                         I32 flags = PERL_SCAN_DISALLOW_PREFIX;
1644                         uv = grok_hex(s, &len, &flags, NULL);
1645                         s += len;
1646                     }
1647                 }
1648
1649               NUM_ESCAPE_INSERT:
1650                 /* Insert oct or hex escaped character.
1651                  * There will always enough room in sv since such
1652                  * escapes will be longer than any UTF-8 sequence
1653                  * they can end up as. */
1654                 
1655                 /* We need to map to chars to ASCII before doing the tests
1656                    to cover EBCDIC
1657                 */
1658                 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(uv))) {
1659                     if (!has_utf8 && uv > 255) {
1660                         /* Might need to recode whatever we have
1661                          * accumulated so far if it contains any
1662                          * hibit chars.
1663                          *
1664                          * (Can't we keep track of that and avoid
1665                          *  this rescan? --jhi)
1666                          */
1667                         int hicount = 0;
1668                         U8 *c;
1669                         for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) {
1670                             if (!NATIVE_IS_INVARIANT(*c)) {
1671                                 hicount++;
1672                             }
1673                         }
1674                         if (hicount) {
1675                             const STRLEN offset = d - SvPVX_const(sv);
1676                             U8 *src, *dst;
1677                             d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset;
1678                             src = (U8 *)d - 1;
1679                             dst = src+hicount;
1680                             d  += hicount;
1681                             while (src >= (const U8 *)SvPVX_const(sv)) {
1682                                 if (!NATIVE_IS_INVARIANT(*src)) {
1683                                     const U8 ch = NATIVE_TO_ASCII(*src);
1684                                     *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch);
1685                                     *dst-- = (U8)UTF8_EIGHT_BIT_HI(ch);
1686                                 }
1687                                 else {
1688                                     *dst-- = *src;
1689                                 }
1690                                 src--;
1691                             }
1692                         }
1693                     }
1694
1695                     if (has_utf8 || uv > 255) {
1696                         d = (char*)uvchr_to_utf8((U8*)d, uv);
1697                         has_utf8 = TRUE;
1698                         if (PL_lex_inwhat == OP_TRANS &&
1699                             PL_sublex_info.sub_op) {
1700                             PL_sublex_info.sub_op->op_private |=
1701                                 (PL_lex_repl ? OPpTRANS_FROM_UTF
1702                                              : OPpTRANS_TO_UTF);
1703                         }
1704                     }
1705                     else {
1706                         *d++ = (char)uv;
1707                     }
1708                 }
1709                 else {
1710                     *d++ = (char) uv;
1711                 }
1712                 continue;
1713
1714             /* \N{LATIN SMALL LETTER A} is a named character */
1715             case 'N':
1716                 ++s;
1717                 if (*s == '{') {
1718                     char* e = strchr(s, '}');
1719                     SV *res;
1720                     STRLEN len;
1721                     const char *str;
1722
1723                     if (!e) {
1724                         yyerror("Missing right brace on \\N{}");
1725                         e = s - 1;
1726                         goto cont_scan;
1727                     }
1728                     if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
1729                         /* \N{U+...} */
1730                         I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
1731                           PERL_SCAN_DISALLOW_PREFIX;
1732                         s += 3;
1733                         len = e - s;
1734                         uv = grok_hex(s, &len, &flags, NULL);
1735                         s = e + 1;
1736                         goto NUM_ESCAPE_INSERT;
1737                     }
1738                     res = newSVpvn(s + 1, e - s - 1);
1739                     res = new_constant( Nullch, 0, "charnames",
1740                                         res, Nullsv, "\\N{...}" );
1741                     if (has_utf8)
1742                         sv_utf8_upgrade(res);
1743                     str = SvPV_const(res,len);
1744 #ifdef EBCDIC_NEVER_MIND
1745                     /* charnames uses pack U and that has been
1746                      * recently changed to do the below uni->native
1747                      * mapping, so this would be redundant (and wrong,
1748                      * the code point would be doubly converted).
1749                      * But leave this in just in case the pack U change
1750                      * gets revoked, but the semantics is still
1751                      * desireable for charnames. --jhi */
1752                     {
1753                          UV uv = utf8_to_uvchr((const U8*)str, 0);
1754
1755                          if (uv < 0x100) {
1756                               U8 tmpbuf[UTF8_MAXBYTES+1], *d;
1757
1758                               d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
1759                               sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
1760                               str = SvPV_const(res, len);
1761                          }
1762                     }
1763 #endif
1764                     if (!has_utf8 && SvUTF8(res)) {
1765                         const char * const ostart = SvPVX_const(sv);
1766                         SvCUR_set(sv, d - ostart);
1767                         SvPOK_on(sv);
1768                         *d = '\0';
1769                         sv_utf8_upgrade(sv);
1770                         /* this just broke our allocation above... */
1771                         SvGROW(sv, (STRLEN)(send - start));
1772                         d = SvPVX(sv) + SvCUR(sv);
1773                         has_utf8 = TRUE;
1774                     }
1775                     if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
1776                         const char * const odest = SvPVX_const(sv);
1777
1778                         SvGROW(sv, (SvLEN(sv) + len - (e - s + 4)));
1779                         d = SvPVX(sv) + (d - odest);
1780                     }
1781                     Copy(str, d, len, char);
1782                     d += len;
1783                     SvREFCNT_dec(res);
1784                   cont_scan:
1785                     s = e + 1;
1786                 }
1787                 else
1788                     yyerror("Missing braces on \\N{}");
1789                 continue;
1790
1791             /* \c is a control character */
1792             case 'c':
1793                 s++;
1794                 if (s < send) {
1795                     U8 c = *s++;
1796 #ifdef EBCDIC
1797                     if (isLOWER(c))
1798                         c = toUPPER(c);
1799 #endif
1800                     *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
1801                 }
1802                 else {
1803                     yyerror("Missing control char name in \\c");
1804                 }
1805                 continue;
1806
1807             /* printf-style backslashes, formfeeds, newlines, etc */
1808             case 'b':
1809                 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
1810                 break;
1811             case 'n':
1812                 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
1813                 break;
1814             case 'r':
1815                 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
1816                 break;
1817             case 'f':
1818                 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
1819                 break;
1820             case 't':
1821                 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
1822                 break;
1823             case 'e':
1824                 *d++ = ASCII_TO_NEED(has_utf8,'\033');
1825                 break;
1826             case 'a':
1827                 *d++ = ASCII_TO_NEED(has_utf8,'\007');
1828                 break;
1829             } /* end switch */
1830
1831             s++;
1832             continue;
1833         } /* end if (backslash) */
1834 #ifdef EBCDIC
1835         else
1836             literal_endpoint++;
1837 #endif
1838
1839     default_action:
1840         /* If we started with encoded form, or already know we want it
1841            and then encode the next character */
1842         if ((has_utf8 || this_utf8) && !NATIVE_IS_INVARIANT((U8)(*s))) {
1843             STRLEN len  = 1;
1844             const UV uv       = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
1845             const STRLEN need = UNISKIP(NATIVE_TO_UNI(uv));
1846             s += len;
1847             if (need > len) {
1848                 /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */
1849                 const STRLEN off = d - SvPVX_const(sv);
1850                 d = SvGROW(sv, SvLEN(sv) + (need-len)) + off;
1851             }
1852             d = (char*)uvchr_to_utf8((U8*)d, uv);
1853             has_utf8 = TRUE;
1854         }
1855         else {
1856             *d++ = NATIVE_TO_NEED(has_utf8,*s++);
1857         }
1858     } /* while loop to process each character */
1859
1860     /* terminate the string and set up the sv */
1861     *d = '\0';
1862     SvCUR_set(sv, d - SvPVX_const(sv));
1863     if (SvCUR(sv) >= SvLEN(sv))
1864         Perl_croak(aTHX_ "panic: constant overflowed allocated space");
1865
1866     SvPOK_on(sv);
1867     if (PL_encoding && !has_utf8) {
1868         sv_recode_to_utf8(sv, PL_encoding);
1869         if (SvUTF8(sv))
1870             has_utf8 = TRUE;
1871     }
1872     if (has_utf8) {
1873         SvUTF8_on(sv);
1874         if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1875             PL_sublex_info.sub_op->op_private |=
1876                     (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1877         }
1878     }
1879
1880     /* shrink the sv if we allocated more than we used */
1881     if (SvCUR(sv) + 5 < SvLEN(sv)) {
1882         SvPV_shrink_to_cur(sv);
1883     }
1884
1885     /* return the substring (via yylval) only if we parsed anything */
1886     if (s > PL_bufptr) {
1887         if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) )
1888             sv = new_constant(start, s - start, (PL_lex_inpat ? "qr" : "q"),
1889                               sv, Nullsv,
1890                               ( PL_lex_inwhat == OP_TRANS
1891                                 ? "tr"
1892                                 : ( (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat)
1893                                     ? "s"
1894                                     : "qq")));
1895         yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1896     } else
1897         SvREFCNT_dec(sv);
1898     return s;
1899 }
1900
1901 /* S_intuit_more
1902  * Returns TRUE if there's more to the expression (e.g., a subscript),
1903  * FALSE otherwise.
1904  *
1905  * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
1906  *
1907  * ->[ and ->{ return TRUE
1908  * { and [ outside a pattern are always subscripts, so return TRUE
1909  * if we're outside a pattern and it's not { or [, then return FALSE
1910  * if we're in a pattern and the first char is a {
1911  *   {4,5} (any digits around the comma) returns FALSE
1912  * if we're in a pattern and the first char is a [
1913  *   [] returns FALSE
1914  *   [SOMETHING] has a funky algorithm to decide whether it's a
1915  *      character class or not.  It has to deal with things like
1916  *      /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
1917  * anything else returns TRUE
1918  */
1919
1920 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
1921
1922 STATIC int
1923 S_intuit_more(pTHX_ register char *s)
1924 {
1925     if (PL_lex_brackets)
1926         return TRUE;
1927     if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
1928         return TRUE;
1929     if (*s != '{' && *s != '[')
1930         return FALSE;
1931     if (!PL_lex_inpat)
1932         return TRUE;
1933
1934     /* In a pattern, so maybe we have {n,m}. */
1935     if (*s == '{') {
1936         s++;
1937         if (!isDIGIT(*s))
1938             return TRUE;
1939         while (isDIGIT(*s))
1940             s++;
1941         if (*s == ',')
1942             s++;
1943         while (isDIGIT(*s))
1944             s++;
1945         if (*s == '}')
1946             return FALSE;
1947         return TRUE;
1948         
1949     }
1950
1951     /* On the other hand, maybe we have a character class */
1952
1953     s++;
1954     if (*s == ']' || *s == '^')
1955         return FALSE;
1956     else {
1957         /* this is terrifying, and it works */
1958         int weight = 2;         /* let's weigh the evidence */
1959         char seen[256];
1960         unsigned char un_char = 255, last_un_char;
1961         const char * const send = strchr(s,']');
1962         char tmpbuf[sizeof PL_tokenbuf * 4];
1963
1964         if (!send)              /* has to be an expression */
1965             return TRUE;
1966
1967         Zero(seen,256,char);
1968         if (*s == '$')
1969             weight -= 3;
1970         else if (isDIGIT(*s)) {
1971             if (s[1] != ']') {
1972                 if (isDIGIT(s[1]) && s[2] == ']')
1973                     weight -= 10;
1974             }
1975             else
1976                 weight -= 100;
1977         }
1978         for (; s < send; s++) {
1979             last_un_char = un_char;
1980             un_char = (unsigned char)*s;
1981             switch (*s) {
1982             case '@':
1983             case '&':
1984             case '$':
1985                 weight -= seen[un_char] * 10;
1986                 if (isALNUM_lazy_if(s+1,UTF)) {
1987                     scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
1988                     if ((int)strlen(tmpbuf) > 1 && gv_fetchpv(tmpbuf,FALSE, SVt_PV))
1989                         weight -= 100;
1990                     else
1991                         weight -= 10;
1992                 }
1993                 else if (*s == '$' && s[1] &&
1994                   strchr("[#!%*<>()-=",s[1])) {
1995                     if (/*{*/ strchr("])} =",s[2]))
1996                         weight -= 10;
1997                     else
1998                         weight -= 1;
1999                 }
2000                 break;
2001             case '\\':
2002                 un_char = 254;
2003                 if (s[1]) {
2004                     if (strchr("wds]",s[1]))
2005                         weight += 100;
2006                     else if (seen['\''] || seen['"'])
2007                         weight += 1;
2008                     else if (strchr("rnftbxcav",s[1]))
2009                         weight += 40;
2010                     else if (isDIGIT(s[1])) {
2011                         weight += 40;
2012                         while (s[1] && isDIGIT(s[1]))
2013                             s++;
2014                     }
2015                 }
2016                 else
2017                     weight += 100;
2018                 break;
2019             case '-':
2020                 if (s[1] == '\\')
2021                     weight += 50;
2022                 if (strchr("aA01! ",last_un_char))
2023                     weight += 30;
2024                 if (strchr("zZ79~",s[1]))
2025                     weight += 30;
2026                 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2027                     weight -= 5;        /* cope with negative subscript */
2028                 break;
2029             default:
2030                 if (!isALNUM(last_un_char)
2031                     && !(last_un_char == '$' || last_un_char == '@'
2032                          || last_un_char == '&')
2033                     && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2034                     char *d = tmpbuf;
2035                     while (isALPHA(*s))
2036                         *d++ = *s++;
2037                     *d = '\0';
2038                     if (keyword(tmpbuf, d - tmpbuf))
2039                         weight -= 150;
2040                 }
2041                 if (un_char == last_un_char + 1)
2042                     weight += 5;
2043                 weight -= seen[un_char];
2044                 break;
2045             }
2046             seen[un_char]++;
2047         }
2048         if (weight >= 0)        /* probably a character class */
2049             return FALSE;
2050     }
2051
2052     return TRUE;
2053 }
2054
2055 /*
2056  * S_intuit_method
2057  *
2058  * Does all the checking to disambiguate
2059  *   foo bar
2060  * between foo(bar) and bar->foo.  Returns 0 if not a method, otherwise
2061  * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2062  *
2063  * First argument is the stuff after the first token, e.g. "bar".
2064  *
2065  * Not a method if bar is a filehandle.
2066  * Not a method if foo is a subroutine prototyped to take a filehandle.
2067  * Not a method if it's really "Foo $bar"
2068  * Method if it's "foo $bar"
2069  * Not a method if it's really "print foo $bar"
2070  * Method if it's really "foo package::" (interpreted as package->foo)
2071  * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2072  * Not a method if bar is a filehandle or package, but is quoted with
2073  *   =>
2074  */
2075
2076 STATIC int
2077 S_intuit_method(pTHX_ char *start, GV *gv)
2078 {
2079     char *s = start + (*start == '$');
2080     char tmpbuf[sizeof PL_tokenbuf];
2081     STRLEN len;
2082     GV* indirgv;
2083
2084     if (gv) {
2085         CV *cv;
2086         if (GvIO(gv))
2087             return 0;
2088         if ((cv = GvCVu(gv))) {
2089             const char *proto = SvPVX_const(cv);
2090             if (proto) {
2091                 if (*proto == ';')
2092                     proto++;
2093                 if (*proto == '*')
2094                     return 0;
2095             }
2096         } else
2097             gv = 0;
2098     }
2099     s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2100     /* start is the beginning of the possible filehandle/object,
2101      * and s is the end of it
2102      * tmpbuf is a copy of it
2103      */
2104
2105     if (*start == '$') {
2106         if (gv || PL_last_lop_op == OP_PRINT || isUPPER(*PL_tokenbuf))
2107             return 0;
2108         s = skipspace(s);
2109         PL_bufptr = start;
2110         PL_expect = XREF;
2111         return *s == '(' ? FUNCMETH : METHOD;
2112     }
2113     if (!keyword(tmpbuf, len)) {
2114         if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2115             len -= 2;
2116             tmpbuf[len] = '\0';
2117             goto bare_package;
2118         }
2119         indirgv = gv_fetchpv(tmpbuf, FALSE, SVt_PVCV);
2120         if (indirgv && GvCVu(indirgv))
2121             return 0;
2122         /* filehandle or package name makes it a method */
2123         if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, FALSE)) {
2124             s = skipspace(s);
2125             if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2126                 return 0;       /* no assumptions -- "=>" quotes bearword */
2127       bare_package:
2128             PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0,
2129                                                    newSVpvn(tmpbuf,len));
2130             PL_nextval[PL_nexttoke].opval->op_private = OPpCONST_BARE;
2131             PL_expect = XTERM;
2132             force_next(WORD);
2133             PL_bufptr = s;
2134             return *s == '(' ? FUNCMETH : METHOD;
2135         }
2136     }
2137     return 0;
2138 }
2139
2140 /*
2141  * S_incl_perldb
2142  * Return a string of Perl code to load the debugger.  If PERL5DB
2143  * is set, it will return the contents of that, otherwise a
2144  * compile-time require of perl5db.pl.
2145  */
2146
2147 STATIC const char*
2148 S_incl_perldb(pTHX)
2149 {
2150     if (PL_perldb) {
2151         const char * const pdb = PerlEnv_getenv("PERL5DB");
2152
2153         if (pdb)
2154             return pdb;
2155         SETERRNO(0,SS_NORMAL);
2156         return "BEGIN { require 'perl5db.pl' }";
2157     }
2158     return "";
2159 }
2160
2161
2162 /* Encoded script support. filter_add() effectively inserts a
2163  * 'pre-processing' function into the current source input stream.
2164  * Note that the filter function only applies to the current source file
2165  * (e.g., it will not affect files 'require'd or 'use'd by this one).
2166  *
2167  * The datasv parameter (which may be NULL) can be used to pass
2168  * private data to this instance of the filter. The filter function
2169  * can recover the SV using the FILTER_DATA macro and use it to
2170  * store private buffers and state information.
2171  *
2172  * The supplied datasv parameter is upgraded to a PVIO type
2173  * and the IoDIRP/IoANY field is used to store the function pointer,
2174  * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2175  * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2176  * private use must be set using malloc'd pointers.
2177  */
2178
2179 SV *
2180 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2181 {
2182     if (!funcp)
2183         return Nullsv;
2184
2185     if (!PL_rsfp_filters)
2186         PL_rsfp_filters = newAV();
2187     if (!datasv)
2188         datasv = NEWSV(255,0);
2189     SvUPGRADE(datasv, SVt_PVIO);
2190     IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2191     IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2192     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2193                           IoANY(datasv), SvPV_nolen(datasv)));
2194     av_unshift(PL_rsfp_filters, 1);
2195     av_store(PL_rsfp_filters, 0, datasv) ;
2196     return(datasv);
2197 }
2198
2199
2200 /* Delete most recently added instance of this filter function. */
2201 void
2202 Perl_filter_del(pTHX_ filter_t funcp)
2203 {
2204     SV *datasv;
2205
2206 #ifdef DEBUGGING
2207     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p", FPTR2DPTR(XPVIO *, funcp)));
2208 #endif
2209     if (!PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2210         return;
2211     /* if filter is on top of stack (usual case) just pop it off */
2212     datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2213     if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2214         IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2215         IoANY(datasv) = (void *)NULL;
2216         sv_free(av_pop(PL_rsfp_filters));
2217
2218         return;
2219     }
2220     /* we need to search for the correct entry and clear it     */
2221     Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2222 }
2223
2224
2225 /* Invoke the idxth filter function for the current rsfp.        */
2226 /* maxlen 0 = read one text line */
2227 I32
2228 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2229 {
2230     filter_t funcp;
2231     SV *datasv = NULL;
2232
2233     if (!PL_rsfp_filters)
2234         return -1;
2235     if (idx > AvFILLp(PL_rsfp_filters)) {       /* Any more filters?    */
2236         /* Provide a default input filter to make life easy.    */
2237         /* Note that we append to the line. This is handy.      */
2238         DEBUG_P(PerlIO_printf(Perl_debug_log,
2239                               "filter_read %d: from rsfp\n", idx));
2240         if (maxlen) {
2241             /* Want a block */
2242             int len ;
2243             const int old_len = SvCUR(buf_sv);
2244
2245             /* ensure buf_sv is large enough */
2246             SvGROW(buf_sv, (STRLEN)(old_len + maxlen)) ;
2247             if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len, maxlen)) <= 0){
2248                 if (PerlIO_error(PL_rsfp))
2249                     return -1;          /* error */
2250                 else
2251                     return 0 ;          /* end of file */
2252             }
2253             SvCUR_set(buf_sv, old_len + len) ;
2254         } else {
2255             /* Want a line */
2256             if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2257                 if (PerlIO_error(PL_rsfp))
2258                     return -1;          /* error */
2259                 else
2260                     return 0 ;          /* end of file */
2261             }
2262         }
2263         return SvCUR(buf_sv);
2264     }
2265     /* Skip this filter slot if filter has been deleted */
2266     if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2267         DEBUG_P(PerlIO_printf(Perl_debug_log,
2268                               "filter_read %d: skipped (filter deleted)\n",
2269                               idx));
2270         return FILTER_READ(idx+1, buf_sv, maxlen); /* recurse */
2271     }
2272     /* Get function pointer hidden within datasv        */
2273     funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2274     DEBUG_P(PerlIO_printf(Perl_debug_log,
2275                           "filter_read %d: via function %p (%s)\n",
2276                           idx, datasv, SvPV_nolen_const(datasv)));
2277     /* Call function. The function is expected to       */
2278     /* call "FILTER_READ(idx+1, buf_sv)" first.         */
2279     /* Return: <0:error, =0:eof, >0:not eof             */
2280     return (*funcp)(aTHX_ idx, buf_sv, maxlen);
2281 }
2282
2283 STATIC char *
2284 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2285 {
2286 #ifdef PERL_CR_FILTER
2287     if (!PL_rsfp_filters) {
2288         filter_add(S_cr_textfilter,NULL);
2289     }
2290 #endif
2291     if (PL_rsfp_filters) {
2292         if (!append)
2293             SvCUR_set(sv, 0);   /* start with empty line        */
2294         if (FILTER_READ(0, sv, 0) > 0)
2295             return ( SvPVX(sv) ) ;
2296         else
2297             return Nullch ;
2298     }
2299     else
2300         return (sv_gets(sv, fp, append));
2301 }
2302
2303 STATIC HV *
2304 S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
2305 {
2306     GV *gv;
2307
2308     if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
2309         return PL_curstash;
2310
2311     if (len > 2 &&
2312         (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
2313         (gv = gv_fetchpv(pkgname, FALSE, SVt_PVHV)))
2314     {
2315         return GvHV(gv);                        /* Foo:: */
2316     }
2317
2318     /* use constant CLASS => 'MyClass' */
2319     if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) {
2320         SV *sv;
2321         if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
2322             pkgname = SvPV_nolen_const(sv);
2323         }
2324     }
2325
2326     return gv_stashpv(pkgname, FALSE);
2327 }
2328
2329 STATIC char *
2330 S_tokenize_use(pTHX_ int is_use, char *s) {
2331     if (PL_expect != XSTATE)
2332         yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
2333                     is_use ? "use" : "no"));
2334     s = skipspace(s);
2335     if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
2336         s = force_version(s, TRUE);
2337         if (*s == ';' || (s = skipspace(s), *s == ';')) {
2338             PL_nextval[PL_nexttoke].opval = Nullop;
2339             force_next(WORD);
2340         }
2341         else if (*s == 'v') {
2342             s = force_word(s,WORD,FALSE,TRUE,FALSE);
2343             s = force_version(s, FALSE);
2344         }
2345     }
2346     else {
2347         s = force_word(s,WORD,FALSE,TRUE,FALSE);
2348         s = force_version(s, FALSE);
2349     }
2350     yylval.ival = is_use;
2351     return s;
2352 }
2353 #ifdef DEBUGGING
2354     static const char* const exp_name[] =
2355         { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
2356           "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
2357         };
2358 #endif
2359
2360 /*
2361   yylex
2362
2363   Works out what to call the token just pulled out of the input
2364   stream.  The yacc parser takes care of taking the ops we return and
2365   stitching them into a tree.
2366
2367   Returns:
2368     PRIVATEREF
2369
2370   Structure:
2371       if read an identifier
2372           if we're in a my declaration
2373               croak if they tried to say my($foo::bar)
2374               build the ops for a my() declaration
2375           if it's an access to a my() variable
2376               are we in a sort block?
2377                   croak if my($a); $a <=> $b
2378               build ops for access to a my() variable
2379           if in a dq string, and they've said @foo and we can't find @foo
2380               croak
2381           build ops for a bareword
2382       if we already built the token before, use it.
2383 */
2384
2385
2386 #ifdef __SC__
2387 #pragma segment Perl_yylex
2388 #endif
2389 int
2390 Perl_yylex(pTHX)
2391 {
2392     register char *s = PL_bufptr;
2393     register char *d;
2394     register I32 tmp;
2395     STRLEN len;
2396     GV *gv = Nullgv;
2397     GV **gvp = 0;
2398     bool bof = FALSE;
2399     I32 orig_keyword = 0;
2400
2401     DEBUG_T( {
2402         PerlIO_printf(Perl_debug_log, "### LEX_%s\n",
2403                                         lex_state_names[PL_lex_state]);
2404     } );
2405     /* check if there's an identifier for us to look at */
2406     if (PL_pending_ident)
2407         return REPORT(S_pending_ident(aTHX));
2408
2409     /* no identifier pending identification */
2410
2411     switch (PL_lex_state) {
2412 #ifdef COMMENTARY
2413     case LEX_NORMAL:            /* Some compilers will produce faster */
2414     case LEX_INTERPNORMAL:      /* code if we comment these out. */
2415         break;
2416 #endif
2417
2418     /* when we've already built the next token, just pull it out of the queue */
2419     case LEX_KNOWNEXT:
2420         PL_nexttoke--;
2421         yylval = PL_nextval[PL_nexttoke];
2422         if (!PL_nexttoke) {
2423             PL_lex_state = PL_lex_defer;
2424             PL_expect = PL_lex_expect;
2425             PL_lex_defer = LEX_NORMAL;
2426         }
2427         DEBUG_T({ PerlIO_printf(Perl_debug_log,
2428               "### Next token after '%s' was known, type %"IVdf"\n", PL_bufptr,
2429               (IV)PL_nexttype[PL_nexttoke]); });
2430
2431         return REPORT(PL_nexttype[PL_nexttoke]);
2432
2433     /* interpolated case modifiers like \L \U, including \Q and \E.
2434        when we get here, PL_bufptr is at the \
2435     */
2436     case LEX_INTERPCASEMOD:
2437 #ifdef DEBUGGING
2438         if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
2439             Perl_croak(aTHX_ "panic: INTERPCASEMOD");
2440 #endif
2441         /* handle \E or end of string */
2442         if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
2443             /* if at a \E */
2444             if (PL_lex_casemods) {
2445                 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
2446                 PL_lex_casestack[PL_lex_casemods] = '\0';
2447
2448                 if (PL_bufptr != PL_bufend
2449                     && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
2450                     PL_bufptr += 2;
2451                     PL_lex_state = LEX_INTERPCONCAT;
2452                 }
2453                 return REPORT(')');
2454             }
2455             if (PL_bufptr != PL_bufend)
2456                 PL_bufptr += 2;
2457             PL_lex_state = LEX_INTERPCONCAT;
2458             return yylex();
2459         }
2460         else {
2461             DEBUG_T({ PerlIO_printf(Perl_debug_log,
2462               "### Saw case modifier at '%s'\n", PL_bufptr); });
2463             s = PL_bufptr + 1;
2464             if (s[1] == '\\' && s[2] == 'E') {
2465                 PL_bufptr = s + 3;
2466                 PL_lex_state = LEX_INTERPCONCAT;
2467                 return yylex();
2468             }
2469             else {
2470                 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
2471                     tmp = *s, *s = s[2], s[2] = (char)tmp;      /* misordered... */
2472                 if ((*s == 'L' || *s == 'U') &&
2473                     (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
2474                     PL_lex_casestack[--PL_lex_casemods] = '\0';
2475                     return REPORT(')');
2476                 }
2477                 if (PL_lex_casemods > 10)
2478                     Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
2479                 PL_lex_casestack[PL_lex_casemods++] = *s;
2480                 PL_lex_casestack[PL_lex_casemods] = '\0';
2481                 PL_lex_state = LEX_INTERPCONCAT;
2482                 PL_nextval[PL_nexttoke].ival = 0;
2483                 force_next('(');
2484                 if (*s == 'l')
2485                     PL_nextval[PL_nexttoke].ival = OP_LCFIRST;
2486                 else if (*s == 'u')
2487                     PL_nextval[PL_nexttoke].ival = OP_UCFIRST;
2488                 else if (*s == 'L')
2489                     PL_nextval[PL_nexttoke].ival = OP_LC;
2490                 else if (*s == 'U')
2491                     PL_nextval[PL_nexttoke].ival = OP_UC;
2492                 else if (*s == 'Q')
2493                     PL_nextval[PL_nexttoke].ival = OP_QUOTEMETA;
2494                 else
2495                     Perl_croak(aTHX_ "panic: yylex");
2496                 PL_bufptr = s + 1;
2497             }
2498             force_next(FUNC);
2499             if (PL_lex_starts) {
2500                 s = PL_bufptr;
2501                 PL_lex_starts = 0;
2502                 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2503                 if (PL_lex_casemods == 1 && PL_lex_inpat)
2504                     OPERATOR(',');
2505                 else
2506                     Aop(OP_CONCAT);
2507             }
2508             else
2509                 return yylex();
2510         }
2511
2512     case LEX_INTERPPUSH:
2513         return REPORT(sublex_push());
2514
2515     case LEX_INTERPSTART:
2516         if (PL_bufptr == PL_bufend)
2517             return REPORT(sublex_done());
2518         DEBUG_T({ PerlIO_printf(Perl_debug_log,
2519               "### Interpolated variable at '%s'\n", PL_bufptr); });
2520         PL_expect = XTERM;
2521         PL_lex_dojoin = (*PL_bufptr == '@');
2522         PL_lex_state = LEX_INTERPNORMAL;
2523         if (PL_lex_dojoin) {
2524             PL_nextval[PL_nexttoke].ival = 0;
2525             force_next(',');
2526             force_ident("\"", '$');
2527             PL_nextval[PL_nexttoke].ival = 0;
2528             force_next('$');
2529             PL_nextval[PL_nexttoke].ival = 0;
2530             force_next('(');
2531             PL_nextval[PL_nexttoke].ival = OP_JOIN;     /* emulate join($", ...) */
2532             force_next(FUNC);
2533         }
2534         if (PL_lex_starts++) {
2535             s = PL_bufptr;
2536             /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2537             if (!PL_lex_casemods && PL_lex_inpat)
2538                 OPERATOR(',');
2539             else
2540                 Aop(OP_CONCAT);
2541         }
2542         return yylex();
2543
2544     case LEX_INTERPENDMAYBE:
2545         if (intuit_more(PL_bufptr)) {
2546             PL_lex_state = LEX_INTERPNORMAL;    /* false alarm, more expr */
2547             break;
2548         }
2549         /* FALL THROUGH */
2550
2551     case LEX_INTERPEND:
2552         if (PL_lex_dojoin) {
2553             PL_lex_dojoin = FALSE;
2554             PL_lex_state = LEX_INTERPCONCAT;
2555             return REPORT(')');
2556         }
2557         if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
2558             && SvEVALED(PL_lex_repl))
2559         {
2560             if (PL_bufptr != PL_bufend)
2561                 Perl_croak(aTHX_ "Bad evalled substitution pattern");
2562             PL_lex_repl = Nullsv;
2563         }
2564         /* FALLTHROUGH */
2565     case LEX_INTERPCONCAT:
2566 #ifdef DEBUGGING
2567         if (PL_lex_brackets)
2568             Perl_croak(aTHX_ "panic: INTERPCONCAT");
2569 #endif
2570         if (PL_bufptr == PL_bufend)
2571             return REPORT(sublex_done());
2572
2573         if (SvIVX(PL_linestr) == '\'') {
2574             SV *sv = newSVsv(PL_linestr);
2575             if (!PL_lex_inpat)
2576                 sv = tokeq(sv);
2577             else if ( PL_hints & HINT_NEW_RE )
2578                 sv = new_constant(NULL, 0, "qr", sv, sv, "q");
2579             yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2580             s = PL_bufend;
2581         }
2582         else {
2583             s = scan_const(PL_bufptr);
2584             if (*s == '\\')
2585                 PL_lex_state = LEX_INTERPCASEMOD;
2586             else
2587                 PL_lex_state = LEX_INTERPSTART;
2588         }
2589
2590         if (s != PL_bufptr) {
2591             PL_nextval[PL_nexttoke] = yylval;
2592             PL_expect = XTERM;
2593             force_next(THING);
2594             if (PL_lex_starts++) {
2595                 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
2596                 if (!PL_lex_casemods && PL_lex_inpat)
2597                     OPERATOR(',');
2598                 else
2599                     Aop(OP_CONCAT);
2600             }
2601             else {
2602                 PL_bufptr = s;
2603                 return yylex();
2604             }
2605         }
2606
2607         return yylex();
2608     case LEX_FORMLINE:
2609         PL_lex_state = LEX_NORMAL;
2610         s = scan_formline(PL_bufptr);
2611         if (!PL_lex_formbrack)
2612             goto rightbracket;
2613         OPERATOR(';');
2614     }
2615
2616     s = PL_bufptr;
2617     PL_oldoldbufptr = PL_oldbufptr;
2618     PL_oldbufptr = s;
2619     DEBUG_T( {
2620         PerlIO_printf(Perl_debug_log, "### Tokener expecting %s at [%s]\n",
2621                       exp_name[PL_expect], s);
2622     } );
2623
2624   retry:
2625     switch (*s) {
2626     default:
2627         if (isIDFIRST_lazy_if(s,UTF))
2628             goto keylookup;
2629         Perl_croak(aTHX_ "Unrecognized character \\x%02X", *s & 255);
2630     case 4:
2631     case 26:
2632         goto fake_eof;                  /* emulate EOF on ^D or ^Z */
2633     case 0:
2634         if (!PL_rsfp) {
2635             PL_last_uni = 0;
2636             PL_last_lop = 0;
2637             if (PL_lex_brackets) {
2638                 if (PL_lex_formbrack)
2639                     yyerror("Format not terminated");
2640                 else
2641                     yyerror("Missing right curly or square bracket");
2642             }
2643             DEBUG_T( { PerlIO_printf(Perl_debug_log,
2644                         "### Tokener got EOF\n");
2645             } );
2646             TOKEN(0);
2647         }
2648         if (s++ < PL_bufend)
2649             goto retry;                 /* ignore stray nulls */
2650         PL_last_uni = 0;
2651         PL_last_lop = 0;
2652         if (!PL_in_eval && !PL_preambled) {
2653             PL_preambled = TRUE;
2654             sv_setpv(PL_linestr,incl_perldb());
2655             if (SvCUR(PL_linestr))
2656                 sv_catpvn(PL_linestr,";", 1);
2657             if (PL_preambleav){
2658                 while(AvFILLp(PL_preambleav) >= 0) {
2659                     SV *tmpsv = av_shift(PL_preambleav);
2660                     sv_catsv(PL_linestr, tmpsv);
2661                     sv_catpvn(PL_linestr, ";", 1);
2662                     sv_free(tmpsv);
2663                 }
2664                 sv_free((SV*)PL_preambleav);
2665                 PL_preambleav = NULL;
2666             }
2667             if (PL_minus_n || PL_minus_p) {
2668                 sv_catpv(PL_linestr, "LINE: while (<>) {");
2669                 if (PL_minus_l)
2670                     sv_catpv(PL_linestr,"chomp;");
2671                 if (PL_minus_a) {
2672                     if (PL_minus_F) {
2673                         if ((*PL_splitstr == '/' || *PL_splitstr == '\''
2674                              || *PL_splitstr == '"')
2675                               && strchr(PL_splitstr + 1, *PL_splitstr))
2676                             Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
2677                         else {
2678                             /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
2679                                bytes can be used as quoting characters.  :-) */
2680                             /* The count here deliberately includes the NUL
2681                                that terminates the C string constant.  This
2682                                embeds the opening NUL into the string.  */
2683                             const char *splits = PL_splitstr;
2684                             sv_catpvn(PL_linestr, "our @F=split(q", 15);
2685                             do {
2686                                 /* Need to \ \s  */
2687                                 if (*splits == '\\')
2688                                     sv_catpvn(PL_linestr, splits, 1);
2689                                 sv_catpvn(PL_linestr, splits, 1);
2690                             } while (*splits++);
2691                             /* This loop will embed the trailing NUL of
2692                                PL_linestr as the last thing it does before
2693                                terminating.  */
2694                             sv_catpvn(PL_linestr, ");", 2);
2695                         }
2696                     }
2697                     else
2698                         sv_catpv(PL_linestr,"our @F=split(' ');");
2699                 }
2700             }
2701             sv_catpvn(PL_linestr, "\n", 1);
2702             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2703             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2704             PL_last_lop = PL_last_uni = Nullch;
2705             if (PERLDB_LINE && PL_curstash != PL_debstash) {
2706                 SV * const sv = NEWSV(85,0);
2707
2708                 sv_upgrade(sv, SVt_PVMG);
2709                 sv_setsv(sv,PL_linestr);
2710                 (void)SvIOK_on(sv);
2711                 SvIV_set(sv, 0);
2712                 av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2713             }
2714             goto retry;
2715         }
2716         do {
2717             bof = PL_rsfp ? TRUE : FALSE;
2718             if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == Nullch) {
2719               fake_eof:
2720                 if (PL_rsfp) {
2721                     if (PL_preprocess && !PL_in_eval)
2722                         (void)PerlProc_pclose(PL_rsfp);
2723                     else if ((PerlIO *)PL_rsfp == PerlIO_stdin())
2724                         PerlIO_clearerr(PL_rsfp);
2725                     else
2726                         (void)PerlIO_close(PL_rsfp);
2727                     PL_rsfp = Nullfp;
2728                     PL_doextract = FALSE;
2729                 }
2730                 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
2731                     sv_setpv(PL_linestr,PL_minus_p
2732                              ? ";}continue{print;}" : ";}");
2733                     PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2734                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2735                     PL_last_lop = PL_last_uni = Nullch;
2736                     PL_minus_n = PL_minus_p = 0;
2737                     goto retry;
2738                 }
2739                 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2740                 PL_last_lop = PL_last_uni = Nullch;
2741                 sv_setpvn(PL_linestr,"",0);
2742                 TOKEN(';');     /* not infinite loop because rsfp is NULL now */
2743             }
2744             /* If it looks like the start of a BOM or raw UTF-16,
2745              * check if it in fact is. */
2746             else if (bof &&
2747                      (*s == 0 ||
2748                       *(U8*)s == 0xEF ||
2749                       *(U8*)s >= 0xFE ||
2750                       s[1] == 0)) {
2751 #ifdef PERLIO_IS_STDIO
2752 #  ifdef __GNU_LIBRARY__
2753 #    if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
2754 #      define FTELL_FOR_PIPE_IS_BROKEN
2755 #    endif
2756 #  else
2757 #    ifdef __GLIBC__
2758 #      if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
2759 #        define FTELL_FOR_PIPE_IS_BROKEN
2760 #      endif
2761 #    endif
2762 #  endif
2763 #endif
2764 #ifdef FTELL_FOR_PIPE_IS_BROKEN
2765                 /* This loses the possibility to detect the bof
2766                  * situation on perl -P when the libc5 is being used.
2767                  * Workaround?  Maybe attach some extra state to PL_rsfp?
2768                  */
2769                 if (!PL_preprocess)
2770                     bof = PerlIO_tell(PL_rsfp) == SvCUR(PL_linestr);
2771 #else
2772                 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
2773 #endif
2774                 if (bof) {
2775                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2776                     s = swallow_bom((U8*)s);
2777                 }
2778             }
2779             if (PL_doextract) {
2780                 /* Incest with pod. */
2781                 if (*s == '=' && strnEQ(s, "=cut", 4)) {
2782                     sv_setpvn(PL_linestr, "", 0);
2783                     PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2784                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2785                     PL_last_lop = PL_last_uni = Nullch;
2786                     PL_doextract = FALSE;
2787                 }
2788             }
2789             incline(s);
2790         } while (PL_doextract);
2791         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
2792         if (PERLDB_LINE && PL_curstash != PL_debstash) {
2793             SV * const sv = NEWSV(85,0);
2794
2795             sv_upgrade(sv, SVt_PVMG);
2796             sv_setsv(sv,PL_linestr);
2797             (void)SvIOK_on(sv);
2798             SvIV_set(sv, 0);
2799             av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
2800         }
2801         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2802         PL_last_lop = PL_last_uni = Nullch;
2803         if (CopLINE(PL_curcop) == 1) {
2804             while (s < PL_bufend && isSPACE(*s))
2805                 s++;
2806             if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
2807                 s++;
2808             d = Nullch;
2809             if (!PL_in_eval) {
2810                 if (*s == '#' && *(s+1) == '!')
2811                     d = s + 2;
2812 #ifdef ALTERNATE_SHEBANG
2813                 else {
2814                     static char const as[] = ALTERNATE_SHEBANG;
2815                     if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
2816                         d = s + (sizeof(as) - 1);
2817                 }
2818 #endif /* ALTERNATE_SHEBANG */
2819             }
2820             if (d) {
2821                 char *ipath;
2822                 char *ipathend;
2823
2824                 while (isSPACE(*d))
2825                     d++;
2826                 ipath = d;
2827                 while (*d && !isSPACE(*d))
2828                     d++;
2829                 ipathend = d;
2830
2831 #ifdef ARG_ZERO_IS_SCRIPT
2832                 if (ipathend > ipath) {
2833                     /*
2834                      * HP-UX (at least) sets argv[0] to the script name,
2835                      * which makes $^X incorrect.  And Digital UNIX and Linux,
2836                      * at least, set argv[0] to the basename of the Perl
2837                      * interpreter. So, having found "#!", we'll set it right.
2838                      */
2839                     SV *x = GvSV(gv_fetchpv("\030", TRUE, SVt_PV)); /* $^X */
2840                     assert(SvPOK(x) || SvGMAGICAL(x));
2841                     if (sv_eq(x, CopFILESV(PL_curcop))) {
2842                         sv_setpvn(x, ipath, ipathend - ipath);
2843                         SvSETMAGIC(x);
2844                     }
2845                     else {
2846                         STRLEN blen;
2847                         STRLEN llen;
2848                         const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
2849                         const char * const lstart = SvPV_const(x,llen);
2850                         if (llen < blen) {
2851                             bstart += blen - llen;
2852                             if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
2853                                 sv_setpvn(x, ipath, ipathend - ipath);
2854                                 SvSETMAGIC(x);
2855                             }
2856                         }
2857                     }
2858                     TAINT_NOT;  /* $^X is always tainted, but that's OK */
2859                 }
2860 #endif /* ARG_ZERO_IS_SCRIPT */
2861
2862                 /*
2863                  * Look for options.
2864                  */
2865                 d = instr(s,"perl -");
2866                 if (!d) {
2867                     d = instr(s,"perl");
2868 #if defined(DOSISH)
2869                     /* avoid getting into infinite loops when shebang
2870                      * line contains "Perl" rather than "perl" */
2871                     if (!d) {
2872                         for (d = ipathend-4; d >= ipath; --d) {
2873                             if ((*d == 'p' || *d == 'P')
2874                                 && !ibcmp(d, "perl", 4))
2875                             {
2876                                 break;
2877                             }
2878                         }
2879                         if (d < ipath)
2880                             d = Nullch;
2881                     }
2882 #endif
2883                 }
2884 #ifdef ALTERNATE_SHEBANG
2885                 /*
2886                  * If the ALTERNATE_SHEBANG on this system starts with a
2887                  * character that can be part of a Perl expression, then if
2888                  * we see it but not "perl", we're probably looking at the
2889                  * start of Perl code, not a request to hand off to some
2890                  * other interpreter.  Similarly, if "perl" is there, but
2891                  * not in the first 'word' of the line, we assume the line
2892                  * contains the start of the Perl program.
2893                  */
2894                 if (d && *s != '#') {
2895                     const char *c = ipath;
2896                     while (*c && !strchr("; \t\r\n\f\v#", *c))
2897                         c++;
2898                     if (c < d)
2899                         d = Nullch;     /* "perl" not in first word; ignore */
2900                     else
2901                         *s = '#';       /* Don't try to parse shebang line */
2902                 }
2903 #endif /* ALTERNATE_SHEBANG */
2904 #ifndef MACOS_TRADITIONAL
2905                 if (!d &&
2906                     *s == '#' &&
2907                     ipathend > ipath &&
2908                     !PL_minus_c &&
2909                     !instr(s,"indir") &&
2910                     instr(PL_origargv[0],"perl"))
2911                 {
2912                     dVAR;
2913                     char **newargv;
2914
2915                     *ipathend = '\0';
2916                     s = ipathend + 1;
2917                     while (s < PL_bufend && isSPACE(*s))
2918                         s++;
2919                     if (s < PL_bufend) {
2920                         Newxz(newargv,PL_origargc+3,char*);
2921                         newargv[1] = s;
2922                         while (s < PL_bufend && !isSPACE(*s))
2923                             s++;
2924                         *s = '\0';
2925                         Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
2926                     }
2927                     else
2928                         newargv = PL_origargv;
2929                     newargv[0] = ipath;
2930                     PERL_FPU_PRE_EXEC
2931                     PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
2932                     PERL_FPU_POST_EXEC
2933                     Perl_croak(aTHX_ "Can't exec %s", ipath);
2934                 }
2935 #endif
2936                 if (d) {
2937                     const U32 oldpdb = PL_perldb;
2938                     const bool oldn = PL_minus_n;
2939                     const bool oldp = PL_minus_p;
2940
2941                     while (*d && !isSPACE(*d)) d++;
2942                     while (SPACE_OR_TAB(*d)) d++;
2943
2944                     if (*d++ == '-') {
2945                         const bool switches_done = PL_doswitches;
2946                         do {
2947                             if (*d == 'M' || *d == 'm' || *d == 'C') {
2948                                 const char * const m = d;
2949                                 while (*d && !isSPACE(*d)) d++;
2950                                 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
2951                                       (int)(d - m), m);
2952                             }
2953                             d = moreswitches(d);
2954                         } while (d);
2955                         if (PL_doswitches && !switches_done) {
2956                             int argc = PL_origargc;
2957                             char **argv = PL_origargv;
2958                             do {
2959                                 argc--,argv++;
2960                             } while (argc && argv[0][0] == '-' && argv[0][1]);
2961                             init_argv_symbols(argc,argv);
2962                         }
2963                         if ((PERLDB_LINE && !oldpdb) ||
2964                             ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
2965                               /* if we have already added "LINE: while (<>) {",
2966                                  we must not do it again */
2967                         {
2968                             sv_setpvn(PL_linestr, "", 0);
2969                             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
2970                             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
2971                             PL_last_lop = PL_last_uni = Nullch;
2972                             PL_preambled = FALSE;
2973                             if (PERLDB_LINE)
2974                                 (void)gv_fetchfile(PL_origfilename);
2975                             goto retry;
2976                         }
2977                         if (PL_doswitches && !switches_done) {
2978                             int argc = PL_origargc;
2979                             char **argv = PL_origargv;
2980                             do {
2981                                 argc--,argv++;
2982                             } while (argc && argv[0][0] == '-' && argv[0][1]);
2983                             init_argv_symbols(argc,argv);
2984                         }
2985                     }
2986                 }
2987             }
2988         }
2989         if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
2990             PL_bufptr = s;
2991             PL_lex_state = LEX_FORMLINE;
2992             return yylex();
2993         }
2994         goto retry;
2995     case '\r':
2996 #ifdef PERL_STRICT_CR
2997         Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
2998         Perl_croak(aTHX_
2999       "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
3000 #endif
3001     case ' ': case '\t': case '\f': case 013:
3002 #ifdef MACOS_TRADITIONAL
3003     case '\312':
3004 #endif
3005         s++;
3006         goto retry;
3007     case '#':
3008     case '\n':
3009         if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3010             if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3011                 /* handle eval qq[#line 1 "foo"\n ...] */
3012                 CopLINE_dec(PL_curcop);
3013                 incline(s);
3014             }
3015             d = PL_bufend;
3016             while (s < d && *s != '\n')
3017                 s++;
3018             if (s < d)
3019                 s++;
3020             else if (s > d) /* Found by Ilya: feed random input to Perl. */
3021               Perl_croak(aTHX_ "panic: input overflow");
3022             incline(s);
3023             if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3024                 PL_bufptr = s;
3025                 PL_lex_state = LEX_FORMLINE;
3026                 return yylex();
3027             }
3028         }
3029         else {
3030             *s = '\0';
3031             PL_bufend = s;
3032         }
3033         goto retry;
3034     case '-':
3035         if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3036             I32 ftst = 0;
3037
3038             s++;
3039             PL_bufptr = s;
3040             tmp = *s++;
3041
3042             while (s < PL_bufend && SPACE_OR_TAB(*s))
3043                 s++;
3044
3045             if (strnEQ(s,"=>",2)) {
3046                 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
3047                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3048                             "### Saw unary minus before =>, forcing word '%s'\n", s);
3049                 } );
3050                 OPERATOR('-');          /* unary minus */
3051             }
3052             PL_last_uni = PL_oldbufptr;
3053             switch (tmp) {
3054             case 'r': ftst = OP_FTEREAD;        break;
3055             case 'w': ftst = OP_FTEWRITE;       break;
3056             case 'x': ftst = OP_FTEEXEC;        break;
3057             case 'o': ftst = OP_FTEOWNED;       break;
3058             case 'R': ftst = OP_FTRREAD;        break;
3059             case 'W': ftst = OP_FTRWRITE;       break;
3060             case 'X': ftst = OP_FTREXEC;        break;
3061             case 'O': ftst = OP_FTROWNED;       break;
3062             case 'e': ftst = OP_FTIS;           break;
3063             case 'z': ftst = OP_FTZERO;         break;
3064             case 's': ftst = OP_FTSIZE;         break;
3065             case 'f': ftst = OP_FTFILE;         break;
3066             case 'd': ftst = OP_FTDIR;          break;
3067             case 'l': ftst = OP_FTLINK;         break;
3068             case 'p': ftst = OP_FTPIPE;         break;
3069             case 'S': ftst = OP_FTSOCK;         break;
3070             case 'u': ftst = OP_FTSUID;         break;
3071             case 'g': ftst = OP_FTSGID;         break;
3072             case 'k': ftst = OP_FTSVTX;         break;
3073             case 'b': ftst = OP_FTBLK;          break;
3074             case 'c': ftst = OP_FTCHR;          break;
3075             case 't': ftst = OP_FTTTY;          break;
3076             case 'T': ftst = OP_FTTEXT;         break;
3077             case 'B': ftst = OP_FTBINARY;       break;
3078             case 'M': case 'A': case 'C':
3079                 gv_fetchpv("\024",TRUE, SVt_PV);
3080                 switch (tmp) {
3081                 case 'M': ftst = OP_FTMTIME;    break;
3082                 case 'A': ftst = OP_FTATIME;    break;
3083                 case 'C': ftst = OP_FTCTIME;    break;
3084                 default:                        break;
3085                 }
3086                 break;
3087             default:
3088                 break;
3089             }
3090             if (ftst) {
3091                 PL_last_lop_op = (OPCODE)ftst;
3092                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3093                         "### Saw file test %c\n", (int)ftst);
3094                 } );
3095                 FTST(ftst);
3096             }
3097             else {
3098                 /* Assume it was a minus followed by a one-letter named
3099                  * subroutine call (or a -bareword), then. */
3100                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
3101                         "### '-%c' looked like a file test but was not\n",
3102                         (int) tmp);
3103                 } );
3104                 s = --PL_bufptr;
3105             }
3106         }
3107         tmp = *s++;
3108         if (*s == tmp) {
3109             s++;
3110             if (PL_expect == XOPERATOR)
3111                 TERM(POSTDEC);
3112             else
3113                 OPERATOR(PREDEC);
3114         }
3115         else if (*s == '>') {
3116             s++;
3117             s = skipspace(s);
3118             if (isIDFIRST_lazy_if(s,UTF)) {
3119                 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
3120                 TOKEN(ARROW);
3121             }
3122             else if (*s == '$')
3123                 OPERATOR(ARROW);
3124             else
3125                 TERM(ARROW);
3126         }
3127         if (PL_expect == XOPERATOR)
3128             Aop(OP_SUBTRACT);
3129         else {
3130             if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3131                 check_uni();
3132             OPERATOR('-');              /* unary minus */
3133         }
3134
3135     case '+':
3136         tmp = *s++;
3137         if (*s == tmp) {
3138             s++;
3139             if (PL_expect == XOPERATOR)
3140                 TERM(POSTINC);
3141             else
3142                 OPERATOR(PREINC);
3143         }
3144         if (PL_expect == XOPERATOR)
3145             Aop(OP_ADD);
3146         else {
3147             if (isSPACE(*s) || !isSPACE(*PL_bufptr))
3148                 check_uni();
3149             OPERATOR('+');
3150         }
3151
3152     case '*':
3153         if (PL_expect != XOPERATOR) {
3154             s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3155             PL_expect = XOPERATOR;
3156             force_ident(PL_tokenbuf, '*');
3157             if (!*PL_tokenbuf)
3158                 PREREF('*');
3159             TERM('*');
3160         }
3161         s++;
3162         if (*s == '*') {
3163             s++;
3164             PWop(OP_POW);
3165         }
3166         Mop(OP_MULTIPLY);
3167
3168     case '%':
3169         if (PL_expect == XOPERATOR) {
3170             ++s;
3171             Mop(OP_MODULO);
3172         }
3173         PL_tokenbuf[0] = '%';
3174         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, TRUE);
3175         if (!PL_tokenbuf[1]) {
3176             PREREF('%');
3177         }
3178         PL_pending_ident = '%';
3179         TERM('%');
3180
3181     case '^':
3182         s++;
3183         BOop(OP_BIT_XOR);
3184     case '[':
3185         PL_lex_brackets++;
3186         /* FALL THROUGH */
3187     case '~':
3188     case ',':
3189         tmp = *s++;
3190         OPERATOR(tmp);
3191     case ':':
3192         if (s[1] == ':') {
3193             len = 0;
3194             goto just_a_word;
3195         }
3196         s++;
3197         switch (PL_expect) {
3198             OP *attrs;
3199         case XOPERATOR:
3200             if (!PL_in_my || PL_lex_state != LEX_NORMAL)
3201                 break;
3202             PL_bufptr = s;      /* update in case we back off */
3203             goto grabattrs;
3204         case XATTRBLOCK:
3205             PL_expect = XBLOCK;
3206             goto grabattrs;
3207         case XATTRTERM:
3208             PL_expect = XTERMBLOCK;
3209          grabattrs:
3210             s = skipspace(s);
3211             attrs = Nullop;
3212             while (isIDFIRST_lazy_if(s,UTF)) {
3213                 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
3214                 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len))) {
3215                     if (tmp < 0) tmp = -tmp;
3216                     switch (tmp) {
3217                     case KEY_or:
3218                     case KEY_and:
3219                     case KEY_err:
3220                     case KEY_for:
3221                     case KEY_unless:
3222                     case KEY_if:
3223                     case KEY_while:
3224                     case KEY_until:
3225                         goto got_attrs;
3226                     default:
3227                         break;
3228                     }
3229                 }
3230                 if (*d == '(') {
3231                     d = scan_str(d,TRUE,TRUE);
3232                     if (!d) {
3233                         /* MUST advance bufptr here to avoid bogus
3234                            "at end of line" context messages from yyerror().
3235                          */
3236                         PL_bufptr = s + len;
3237                         yyerror("Unterminated attribute parameter in attribute list");
3238                         if (attrs)
3239                             op_free(attrs);
3240                         return REPORT(0);       /* EOF indicator */
3241                     }
3242                 }
3243                 if (PL_lex_stuff) {
3244                     SV *sv = newSVpvn(s, len);
3245                     sv_catsv(sv, PL_lex_stuff);
3246                     attrs = append_elem(OP_LIST, attrs,
3247                                         newSVOP(OP_CONST, 0, sv));
3248                     SvREFCNT_dec(PL_lex_stuff);
3249                     PL_lex_stuff = Nullsv;
3250                 }
3251                 else {
3252                     if (len == 6 && strnEQ(s, "unique", len)) {
3253                         if (PL_in_my == KEY_our)
3254 #ifdef USE_ITHREADS
3255                             GvUNIQUE_on(cGVOPx_gv(yylval.opval));
3256 #else
3257                             ; /* skip to avoid loading attributes.pm */
3258 #endif
3259                         else
3260                             Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
3261                     }
3262
3263                     /* NOTE: any CV attrs applied here need to be part of
3264                        the CVf_BUILTIN_ATTRS define in cv.h! */
3265                     else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
3266                         CvLVALUE_on(PL_compcv);
3267                     else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
3268                         CvLOCKED_on(PL_compcv);
3269                     else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
3270                         CvMETHOD_on(PL_compcv);
3271                     else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len))
3272                         CvASSERTION_on(PL_compcv);
3273                     /* After we've set the flags, it could be argued that
3274                        we don't need to do the attributes.pm-based setting
3275                        process, and shouldn't bother appending recognized
3276                        flags.  To experiment with that, uncomment the
3277                        following "else".  (Note that's already been
3278                        uncommented.  That keeps the above-applied built-in
3279                        attributes from being intercepted (and possibly
3280                        rejected) by a package's attribute routines, but is
3281                        justified by the performance win for the common case
3282                        of applying only built-in attributes.) */
3283                     else
3284                         attrs = append_elem(OP_LIST, attrs,
3285                                             newSVOP(OP_CONST, 0,
3286                                                     newSVpvn(s, len)));
3287                 }
3288                 s = skipspace(d);
3289                 if (*s == ':' && s[1] != ':')
3290                     s = skipspace(s+1);
3291                 else if (s == d)
3292                     break;      /* require real whitespace or :'s */
3293             }
3294             tmp = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
3295             if (*s != ';' && *s != '}' && *s != tmp && (tmp != '=' || *s != ')')) {
3296                 const char q = ((*s == '\'') ? '"' : '\'');
3297                 /* If here for an expression, and parsed no attrs, back off. */
3298                 if (tmp == '=' && !attrs) {
3299                     s = PL_bufptr;
3300                     break;
3301                 }
3302                 /* MUST advance bufptr here to avoid bogus "at end of line"
3303                    context messages from yyerror().
3304                  */
3305                 PL_bufptr = s;
3306                 if (!*s)
3307                     yyerror("Unterminated attribute list");
3308                 else
3309                     yyerror(Perl_form(aTHX_ "Invalid separator character %c%c%c in attribute list",
3310                                       q, *s, q));
3311                 if (attrs)
3312                     op_free(attrs);
3313                 OPERATOR(':');
3314             }
3315         got_attrs:
3316             if (attrs) {
3317                 PL_nextval[PL_nexttoke].opval = attrs;
3318                 force_next(THING);
3319             }
3320             TOKEN(COLONATTR);
3321         }
3322         OPERATOR(':');
3323     case '(':
3324         s++;
3325         if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
3326             PL_oldbufptr = PL_oldoldbufptr;             /* allow print(STDOUT 123) */
3327         else
3328             PL_expect = XTERM;
3329         s = skipspace(s);
3330         TOKEN('(');
3331     case ';':
3332         CLINE;
3333         tmp = *s++;
3334         OPERATOR(tmp);
3335     case ')':
3336         tmp = *s++;
3337         s = skipspace(s);
3338         if (*s == '{')
3339             PREBLOCK(tmp);
3340         TERM(tmp);
3341     case ']':
3342         s++;
3343         if (PL_lex_brackets <= 0)
3344             yyerror("Unmatched right square bracket");
3345         else
3346             --PL_lex_brackets;
3347         if (PL_lex_state == LEX_INTERPNORMAL) {
3348             if (PL_lex_brackets == 0) {
3349                 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
3350                     PL_lex_state = LEX_INTERPEND;
3351             }
3352         }
3353         TERM(']');
3354     case '{':
3355       leftbracket:
3356         s++;
3357         if (PL_lex_brackets > 100) {
3358             Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
3359         }
3360         switch (PL_expect) {
3361         case XTERM:
3362             if (PL_lex_formbrack) {
3363                 s--;
3364                 PRETERMBLOCK(DO);
3365             }
3366             if (PL_oldoldbufptr == PL_last_lop)
3367                 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3368             else
3369                 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3370             OPERATOR(HASHBRACK);
3371         case XOPERATOR:
3372             while (s < PL_bufend && SPACE_OR_TAB(*s))
3373                 s++;
3374             d = s;
3375             PL_tokenbuf[0] = '\0';
3376             if (d < PL_bufend && *d == '-') {
3377                 PL_tokenbuf[0] = '-';
3378                 d++;
3379                 while (d < PL_bufend && SPACE_OR_TAB(*d))
3380                     d++;
3381             }
3382             if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3383                 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
3384                               FALSE, &len);
3385                 while (d < PL_bufend && SPACE_OR_TAB(*d))
3386                     d++;
3387                 if (*d == '}') {
3388                     const char minus = (PL_tokenbuf[0] == '-');
3389                     s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
3390                     if (minus)
3391                         force_next('-');
3392                 }
3393             }
3394             /* FALL THROUGH */
3395         case XATTRBLOCK:
3396         case XBLOCK:
3397             PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
3398             PL_expect = XSTATE;
3399             break;
3400         case XATTRTERM:
3401         case XTERMBLOCK:
3402             PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3403             PL_expect = XSTATE;
3404             break;
3405         default: {
3406                 const char *t;
3407                 if (PL_oldoldbufptr == PL_last_lop)
3408                     PL_lex_brackstack[PL_lex_brackets++] = XTERM;
3409                 else
3410                     PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
3411                 s = skipspace(s);
3412                 if (*s == '}') {
3413                     if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
3414                         PL_expect = XTERM;
3415                         /* This hack is to get the ${} in the message. */
3416                         PL_bufptr = s+1;
3417                         yyerror("syntax error");
3418                         break;
3419                     }
3420                     OPERATOR(HASHBRACK);
3421                 }
3422                 /* This hack serves to disambiguate a pair of curlies
3423                  * as being a block or an anon hash.  Normally, expectation
3424                  * determines that, but in cases where we're not in a
3425                  * position to expect anything in particular (like inside
3426                  * eval"") we have to resolve the ambiguity.  This code
3427                  * covers the case where the first term in the curlies is a
3428                  * quoted string.  Most other cases need to be explicitly
3429                  * disambiguated by prepending a "+" before the opening
3430                  * curly in order to force resolution as an anon hash.
3431                  *
3432                  * XXX should probably propagate the outer expectation
3433                  * into eval"" to rely less on this hack, but that could
3434                  * potentially break current behavior of eval"".
3435                  * GSAR 97-07-21
3436                  */
3437                 t = s;
3438                 if (*s == '\'' || *s == '"' || *s == '`') {
3439                     /* common case: get past first string, handling escapes */
3440                     for (t++; t < PL_bufend && *t != *s;)
3441                         if (*t++ == '\\' && (*t == '\\' || *t == *s))
3442                             t++;
3443                     t++;
3444                 }
3445                 else if (*s == 'q') {
3446                     if (++t < PL_bufend
3447                         && (!isALNUM(*t)
3448                             || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
3449                                 && !isALNUM(*t))))
3450                     {
3451                         /* skip q//-like construct */
3452                         const char *tmps;
3453                         char open, close, term;
3454                         I32 brackets = 1;
3455
3456                         while (t < PL_bufend && isSPACE(*t))
3457                             t++;
3458                         /* check for q => */
3459                         if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
3460                             OPERATOR(HASHBRACK);
3461                         }
3462                         term = *t;
3463                         open = term;
3464                         if (term && (tmps = strchr("([{< )]}> )]}>",term)))
3465                             term = tmps[5];
3466                         close = term;
3467                         if (open == close)
3468                             for (t++; t < PL_bufend; t++) {
3469                                 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
3470                                     t++;
3471                                 else if (*t == open)
3472                                     break;
3473                             }
3474                         else {
3475                             for (t++; t < PL_bufend; t++) {
3476                                 if (*t == '\\' && t+1 < PL_bufend)
3477                                     t++;
3478                                 else if (*t == close && --brackets <= 0)
3479                                     break;
3480                                 else if (*t == open)
3481                                     brackets++;
3482                             }
3483                         }
3484                         t++;
3485                     }
3486                     else
3487                         /* skip plain q word */
3488                         while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3489                              t += UTF8SKIP(t);
3490                 }
3491                 else if (isALNUM_lazy_if(t,UTF)) {
3492                     t += UTF8SKIP(t);
3493                     while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
3494                          t += UTF8SKIP(t);
3495                 }
3496                 while (t < PL_bufend && isSPACE(*t))
3497                     t++;
3498                 /* if comma follows first term, call it an anon hash */
3499                 /* XXX it could be a comma expression with loop modifiers */
3500                 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
3501                                    || (*t == '=' && t[1] == '>')))
3502                     OPERATOR(HASHBRACK);
3503                 if (PL_expect == XREF)
3504                     PL_expect = XTERM;
3505                 else {
3506                     PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
3507                     PL_expect = XSTATE;
3508                 }
3509             }
3510             break;
3511         }
3512         yylval.ival = CopLINE(PL_curcop);
3513         if (isSPACE(*s) || *s == '#')
3514             PL_copline = NOLINE;   /* invalidate current command line number */
3515         TOKEN('{');
3516     case '}':
3517       rightbracket:
3518         s++;
3519         if (PL_lex_brackets <= 0)
3520             yyerror("Unmatched right curly bracket");
3521         else
3522             PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
3523         if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3524             PL_lex_formbrack = 0;
3525         if (PL_lex_state == LEX_INTERPNORMAL) {
3526             if (PL_lex_brackets == 0) {
3527                 if (PL_expect & XFAKEBRACK) {
3528                     PL_expect &= XENUMMASK;
3529                     PL_lex_state = LEX_INTERPEND;
3530                     PL_bufptr = s;
3531                     return yylex();     /* ignore fake brackets */
3532                 }
3533                 if (*s == '-' && s[1] == '>')
3534                     PL_lex_state = LEX_INTERPENDMAYBE;
3535                 else if (*s != '[' && *s != '{')
3536                     PL_lex_state = LEX_INTERPEND;
3537             }
3538         }
3539         if (PL_expect & XFAKEBRACK) {
3540             PL_expect &= XENUMMASK;
3541             PL_bufptr = s;
3542             return yylex();             /* ignore fake brackets */
3543         }
3544         force_next('}');
3545         TOKEN(';');
3546     case '&':
3547         s++;
3548         tmp = *s++;
3549         if (tmp == '&')
3550             AOPERATOR(ANDAND);
3551         s--;
3552         if (PL_expect == XOPERATOR) {
3553             if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
3554                 && isIDFIRST_lazy_if(s,UTF))
3555             {
3556                 CopLINE_dec(PL_curcop);
3557                 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
3558                 CopLINE_inc(PL_curcop);
3559             }
3560             BAop(OP_BIT_AND);
3561         }
3562
3563         s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
3564         if (*PL_tokenbuf) {
3565             PL_expect = XOPERATOR;
3566             force_ident(PL_tokenbuf, '&');
3567         }
3568         else
3569             PREREF('&');
3570         yylval.ival = (OPpENTERSUB_AMPER<<8);
3571         TERM('&');
3572
3573     case '|':
3574         s++;
3575         tmp = *s++;
3576         if (tmp == '|')
3577             AOPERATOR(OROR);
3578         s--;
3579         BOop(OP_BIT_OR);
3580     case '=':
3581         s++;
3582         tmp = *s++;
3583         if (tmp == '=')
3584             Eop(OP_EQ);
3585         if (tmp == '>')
3586             OPERATOR(',');
3587         if (tmp == '~')
3588             PMop(OP_MATCH);
3589         if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX) && strchr("+-*/%.^&|<",tmp))
3590             Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Reversed %c= operator",(int)tmp);
3591         s--;
3592         if (PL_expect == XSTATE && isALPHA(tmp) &&
3593                 (s == PL_linestart+1 || s[-2] == '\n') )
3594         {
3595             if (PL_in_eval && !PL_rsfp) {
3596                 d = PL_bufend;
3597                 while (s < d) {
3598                     if (*s++ == '\n') {
3599                         incline(s);
3600                         if (strnEQ(s,"=cut",4)) {
3601                             s = strchr(s,'\n');
3602                             if (s)
3603                                 s++;
3604                             else
3605                                 s = d;
3606                             incline(s);
3607                             goto retry;
3608                         }
3609                     }
3610                 }
3611                 goto retry;
3612             }
3613             s = PL_bufend;
3614             PL_doextract = TRUE;
3615             goto retry;
3616         }
3617         if (PL_lex_brackets < PL_lex_formbrack) {
3618             const char *t;
3619 #ifdef PERL_STRICT_CR
3620             for (t = s; SPACE_OR_TAB(*t); t++) ;
3621 #else
3622             for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
3623 #endif
3624             if (*t == '\n' || *t == '#') {
3625                 s--;
3626                 PL_expect = XBLOCK;
3627                 goto leftbracket;
3628             }
3629         }
3630         yylval.ival = 0;
3631         OPERATOR(ASSIGNOP);
3632     case '!':
3633         s++;
3634         tmp = *s++;
3635         if (tmp == '=') {
3636             /* was this !=~ where !~ was meant?
3637              * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
3638
3639             if (*s == '~' && ckWARN(WARN_SYNTAX)) {
3640                 const char *t = s+1;
3641
3642                 while (t < PL_bufend && isSPACE(*t))
3643                     ++t;
3644
3645                 if (*t == '/' || *t == '?' ||
3646                     ((*t == 'm' || *t == 's' || *t == 'y') && !isALNUM(t[1])) ||
3647                     (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
3648                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3649                                 "!=~ should be !~");
3650             }
3651             Eop(OP_NE);
3652         }
3653         if (tmp == '~')
3654             PMop(OP_NOT);
3655         s--;
3656         OPERATOR('!');
3657     case '<':
3658         if (PL_expect != XOPERATOR) {
3659             if (s[1] != '<' && !strchr(s,'>'))
3660                 check_uni();
3661             if (s[1] == '<')
3662                 s = scan_heredoc(s);
3663             else
3664                 s = scan_inputsymbol(s);
3665             TERM(sublex_start());
3666         }
3667         s++;
3668         tmp = *s++;
3669         if (tmp == '<')
3670             SHop(OP_LEFT_SHIFT);
3671         if (tmp == '=') {
3672             tmp = *s++;
3673             if (tmp == '>')
3674                 Eop(OP_NCMP);
3675             s--;
3676             Rop(OP_LE);
3677         }
3678         s--;
3679         Rop(OP_LT);
3680     case '>':
3681         s++;
3682         tmp = *s++;
3683         if (tmp == '>')
3684             SHop(OP_RIGHT_SHIFT);
3685         if (tmp == '=')
3686             Rop(OP_GE);
3687         s--;
3688         Rop(OP_GT);
3689
3690     case '$':
3691         CLINE;
3692
3693         if (PL_expect == XOPERATOR) {
3694             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3695                 PL_expect = XTERM;
3696                 depcom();
3697                 return REPORT(','); /* grandfather non-comma-format format */
3698             }
3699         }
3700
3701         if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3702             PL_tokenbuf[0] = '@';
3703             s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
3704                            sizeof PL_tokenbuf - 1, FALSE);
3705             if (PL_expect == XOPERATOR)
3706                 no_op("Array length", s);
3707             if (!PL_tokenbuf[1])
3708                 PREREF(DOLSHARP);
3709             PL_expect = XOPERATOR;
3710             PL_pending_ident = '#';
3711             TOKEN(DOLSHARP);
3712         }
3713
3714         PL_tokenbuf[0] = '$';
3715         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
3716                        sizeof PL_tokenbuf - 1, FALSE);
3717         if (PL_expect == XOPERATOR)
3718             no_op("Scalar", s);
3719         if (!PL_tokenbuf[1]) {
3720             if (s == PL_bufend)
3721                 yyerror("Final $ should be \\$ or $name");
3722             PREREF('$');
3723         }
3724
3725         /* This kludge not intended to be bulletproof. */
3726         if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
3727             yylval.opval = newSVOP(OP_CONST, 0,
3728                                    newSViv(PL_compiling.cop_arybase));
3729             yylval.opval->op_private = OPpCONST_ARYBASE;
3730             TERM(THING);
3731         }
3732
3733         d = s;
3734         tmp = (I32)*s;
3735         if (PL_lex_state == LEX_NORMAL)
3736             s = skipspace(s);
3737
3738         if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3739             if (*s == '[') {
3740                 PL_tokenbuf[0] = '@';
3741                 if (ckWARN(WARN_SYNTAX)) {
3742                     char *t;
3743                     for(t = s + 1;
3744                         isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
3745                         t++) ;
3746                     if (*t++ == ',') {
3747                         PL_bufptr = skipspace(PL_bufptr);
3748                         while (t < PL_bufend && *t != ']')
3749                             t++;
3750                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3751                                 "Multidimensional syntax %.*s not supported",
3752                                 (t - PL_bufptr) + 1, PL_bufptr);
3753                     }
3754                 }
3755             }
3756             else if (*s == '{') {
3757                 char *t;
3758                 PL_tokenbuf[0] = '%';
3759                 if (strEQ(PL_tokenbuf+1, "SIG")  && ckWARN(WARN_SYNTAX)
3760                     && (t = strchr(s, '}')) && (t = strchr(t, '=')))
3761                 {
3762                     char tmpbuf[sizeof PL_tokenbuf];
3763                     for (t++; isSPACE(*t); t++) ;
3764                     if (isIDFIRST_lazy_if(t,UTF)) {
3765                         STRLEN len;
3766                         t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len);
3767                         for (; isSPACE(*t); t++) ;
3768                         if (*t == ';' && get_cv(tmpbuf, FALSE))
3769                             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3770                                 "You need to quote \"%s\"", tmpbuf);
3771                     }
3772                 }
3773             }
3774         }
3775
3776         PL_expect = XOPERATOR;
3777         if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
3778             const bool islop = (PL_last_lop == PL_oldoldbufptr);
3779             if (!islop || PL_last_lop_op == OP_GREPSTART)
3780                 PL_expect = XOPERATOR;
3781             else if (strchr("$@\"'`q", *s))
3782                 PL_expect = XTERM;              /* e.g. print $fh "foo" */
3783             else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
3784                 PL_expect = XTERM;              /* e.g. print $fh &sub */
3785             else if (isIDFIRST_lazy_if(s,UTF)) {
3786                 char tmpbuf[sizeof PL_tokenbuf];
3787                 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3788                 if ((tmp = keyword(tmpbuf, len))) {
3789                     /* binary operators exclude handle interpretations */
3790                     switch (tmp) {
3791                     case -KEY_x:
3792                     case -KEY_eq:
3793                     case -KEY_ne:
3794                     case -KEY_gt:
3795                     case -KEY_lt:
3796                     case -KEY_ge:
3797                     case -KEY_le:
3798                     case -KEY_cmp:
3799                         break;
3800                     default:
3801                         PL_expect = XTERM;      /* e.g. print $fh length() */
3802                         break;
3803                     }
3804                 }
3805                 else {
3806                     PL_expect = XTERM;          /* e.g. print $fh subr() */
3807                 }
3808             }
3809             else if (isDIGIT(*s))
3810                 PL_expect = XTERM;              /* e.g. print $fh 3 */
3811             else if (*s == '.' && isDIGIT(s[1]))
3812                 PL_expect = XTERM;              /* e.g. print $fh .3 */
3813             else if ((*s == '?' || *s == '-' || *s == '+')
3814                      && !isSPACE(s[1]) && s[1] != '=')
3815                 PL_expect = XTERM;              /* e.g. print $fh -1 */
3816             else if (*s == '/' && !isSPACE(s[1]) && s[1] != '=' && s[1] != '/')
3817                 PL_expect = XTERM;              /* e.g. print $fh /.../
3818                                                  XXX except DORDOR operator */
3819             else if (*s == '<' && s[1] == '<' && !isSPACE(s[2]) && s[2] != '=')
3820                 PL_expect = XTERM;              /* print $fh <<"EOF" */
3821         }
3822         PL_pending_ident = '$';
3823         TOKEN('$');
3824
3825     case '@':
3826         if (PL_expect == XOPERATOR)
3827             no_op("Array", s);
3828         PL_tokenbuf[0] = '@';
3829         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
3830         if (!PL_tokenbuf[1]) {
3831             PREREF('@');
3832         }
3833         if (PL_lex_state == LEX_NORMAL)
3834             s = skipspace(s);
3835         if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
3836             if (*s == '{')
3837                 PL_tokenbuf[0] = '%';
3838
3839             /* Warn about @ where they meant $. */
3840             if (*s == '[' || *s == '{') {
3841                 if (ckWARN(WARN_SYNTAX)) {
3842                     const char *t = s + 1;
3843                     while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
3844                         t++;
3845                     if (*t == '}' || *t == ']') {
3846                         t++;
3847                         PL_bufptr = skipspace(PL_bufptr);
3848                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
3849                             "Scalar value %.*s better written as $%.*s",
3850                             t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
3851                     }
3852                 }
3853             }
3854         }
3855         PL_pending_ident = '@';
3856         TERM('@');
3857
3858      case '/':                  /* may be division, defined-or, or pattern */
3859         if (PL_expect == XTERMORDORDOR && s[1] == '/') {
3860             s += 2;
3861             AOPERATOR(DORDOR);
3862         }
3863      case '?':                  /* may either be conditional or pattern */
3864          if(PL_expect == XOPERATOR) {
3865              tmp = *s++;
3866              if(tmp == '?') {
3867                   OPERATOR('?');
3868              }
3869              else {
3870                  tmp = *s++;
3871                  if(tmp == '/') {
3872                      /* A // operator. */
3873                     AOPERATOR(DORDOR);
3874                  }
3875                  else {
3876                      s--;
3877                      Mop(OP_DIVIDE);
3878                  }
3879              }
3880          }
3881          else {
3882              /* Disable warning on "study /blah/" */
3883              if (PL_oldoldbufptr == PL_last_uni
3884               && (*PL_last_uni != 's' || s - PL_last_uni < 5
3885                   || memNE(PL_last_uni, "study", 5)
3886                   || isALNUM_lazy_if(PL_last_uni+5,UTF)
3887               ))
3888                  check_uni();
3889              s = scan_pat(s,OP_MATCH);
3890              TERM(sublex_start());
3891          }
3892
3893     case '.':
3894         if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
3895 #ifdef PERL_STRICT_CR
3896             && s[1] == '\n'
3897 #else
3898             && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
3899 #endif
3900             && (s == PL_linestart || s[-1] == '\n') )
3901         {
3902             PL_lex_formbrack = 0;
3903             PL_expect = XSTATE;
3904             goto rightbracket;
3905         }
3906         if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
3907             tmp = *s++;
3908             if (*s == tmp) {
3909                 s++;
3910                 if (*s == tmp) {
3911                     s++;
3912                     yylval.ival = OPf_SPECIAL;
3913                 }
3914                 else
3915                     yylval.ival = 0;
3916                 OPERATOR(DOTDOT);
3917             }
3918             if (PL_expect != XOPERATOR)
3919                 check_uni();
3920             Aop(OP_CONCAT);
3921         }
3922         /* FALL THROUGH */
3923     case '0': case '1': case '2': case '3': case '4':
3924     case '5': case '6': case '7': case '8': case '9':
3925         s = scan_num(s, &yylval);
3926         DEBUG_T( { PerlIO_printf(Perl_debug_log,
3927                     "### Saw number in '%s'\n", s);
3928         } );
3929         if (PL_expect == XOPERATOR)
3930             no_op("Number",s);
3931         TERM(THING);
3932
3933     case '\'':
3934         s = scan_str(s,FALSE,FALSE);
3935         DEBUG_T( { PerlIO_printf(Perl_debug_log,
3936                     "### Saw string before '%s'\n", s);
3937         } );
3938         if (PL_expect == XOPERATOR) {
3939             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3940                 PL_expect = XTERM;
3941                 depcom();
3942                 return REPORT(','); /* grandfather non-comma-format format */
3943             }
3944             else
3945                 no_op("String",s);
3946         }
3947         if (!s)
3948             missingterm((char*)0);
3949         yylval.ival = OP_CONST;
3950         TERM(sublex_start());
3951
3952     case '"':
3953         s = scan_str(s,FALSE,FALSE);
3954         DEBUG_T( { PerlIO_printf(Perl_debug_log,
3955                     "### Saw string before '%s'\n", s);
3956         } );
3957         if (PL_expect == XOPERATOR) {
3958             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
3959                 PL_expect = XTERM;
3960                 depcom();
3961                 return REPORT(','); /* grandfather non-comma-format format */
3962             }
3963             else
3964                 no_op("String",s);
3965         }
3966         if (!s)
3967             missingterm((char*)0);
3968         yylval.ival = OP_CONST;
3969         /* FIXME. I think that this can be const if char *d is replaced by
3970            more localised variables.  */
3971         for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
3972             if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
3973                 yylval.ival = OP_STRINGIFY;
3974                 break;
3975             }
3976         }
3977         TERM(sublex_start());
3978
3979     case '`':
3980         s = scan_str(s,FALSE,FALSE);
3981         DEBUG_T( { PerlIO_printf(Perl_debug_log,
3982                     "### Saw backtick string before '%s'\n", s);
3983         } );
3984         if (PL_expect == XOPERATOR)
3985             no_op("Backticks",s);
3986         if (!s)
3987             missingterm((char*)0);
3988         yylval.ival = OP_BACKTICK;
3989         set_csh();
3990         TERM(sublex_start());
3991
3992     case '\\':
3993         s++;
3994         if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
3995             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
3996                         *s, *s);
3997         if (PL_expect == XOPERATOR)
3998             no_op("Backslash",s);
3999         OPERATOR(REFGEN);
4000
4001     case 'v':
4002         if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
4003             char *start = s + 2;
4004             while (isDIGIT(*start) || *start == '_')
4005                 start++;
4006             if (*start == '.' && isDIGIT(start[1])) {
4007                 s = scan_num(s, &yylval);
4008                 TERM(THING);
4009             }
4010             /* avoid v123abc() or $h{v1}, allow C<print v10;> */
4011             else if (!isALPHA(*start) && (PL_expect == XTERM
4012                         || PL_expect == XREF || PL_expect == XSTATE
4013                         || PL_expect == XTERMORDORDOR)) {
4014                 const char c = *start;
4015                 GV *gv;
4016                 *start = '\0';
4017                 gv = gv_fetchpv(s, FALSE, SVt_PVCV);
4018                 *start = c;
4019                 if (!gv) {
4020                     s = scan_num(s, &yylval);
4021                     TERM(THING);
4022                 }
4023             }
4024         }
4025         goto keylookup;
4026     case 'x':
4027         if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
4028             s++;
4029             Mop(OP_REPEAT);
4030         }
4031         goto keylookup;
4032
4033     case '_':
4034     case 'a': case 'A':
4035     case 'b': case 'B':
4036     case 'c': case 'C':
4037     case 'd': case 'D':
4038     case 'e': case 'E':
4039     case 'f': case 'F':
4040     case 'g': case 'G':
4041     case 'h': case 'H':
4042     case 'i': case 'I':
4043     case 'j': case 'J':
4044     case 'k': case 'K':
4045     case 'l': case 'L':
4046     case 'm': case 'M':
4047     case 'n': case 'N':
4048     case 'o': case 'O':
4049     case 'p': case 'P':
4050     case 'q': case 'Q':
4051     case 'r': case 'R':
4052     case 's': case 'S':
4053     case 't': case 'T':
4054     case 'u': case 'U':
4055               case 'V':
4056     case 'w': case 'W':
4057               case 'X':
4058     case 'y': case 'Y':
4059     case 'z': case 'Z':
4060
4061       keylookup: {
4062         orig_keyword = 0;
4063         gv = Nullgv;
4064         gvp = 0;
4065
4066         PL_bufptr = s;
4067         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4068
4069         /* Some keywords can be followed by any delimiter, including ':' */
4070         tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
4071                (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
4072                              (PL_tokenbuf[0] == 'q' &&
4073                               strchr("qwxr", PL_tokenbuf[1])))));
4074
4075         /* x::* is just a word, unless x is "CORE" */
4076         if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4077             goto just_a_word;
4078
4079         d = s;
4080         while (d < PL_bufend && isSPACE(*d))
4081                 d++;    /* no comments skipped here, or s### is misparsed */
4082
4083         /* Is this a label? */
4084         if (!tmp && PL_expect == XSTATE
4085               && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4086             s = d + 1;
4087             yylval.pval = savepv(PL_tokenbuf);
4088             CLINE;
4089             TOKEN(LABEL);
4090         }
4091
4092         /* Check for keywords */
4093         tmp = keyword(PL_tokenbuf, len);
4094
4095         /* Is this a word before a => operator? */
4096         if (*d == '=' && d[1] == '>') {
4097             CLINE;
4098             yylval.opval
4099                 = (OP*)newSVOP(OP_CONST, 0,
4100                                S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
4101             yylval.opval->op_private = OPpCONST_BARE;
4102             TERM(WORD);
4103         }
4104
4105         if (tmp < 0) {                  /* second-class keyword? */
4106             GV *ogv = Nullgv;   /* override (winner) */
4107             GV *hgv = Nullgv;   /* hidden (loser) */
4108             if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4109                 CV *cv;
4110                 if ((gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV)) &&
4111                     (cv = GvCVu(gv)))
4112                 {
4113                     if (GvIMPORTED_CV(gv))
4114                         ogv = gv;
4115                     else if (! CvMETHOD(cv))
4116                         hgv = gv;
4117                 }
4118                 if (!ogv &&
4119                     (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4120                     (gv = *gvp) != (GV*)&PL_sv_undef &&
4121                     GvCVu(gv) && GvIMPORTED_CV(gv))
4122                 {
4123                     ogv = gv;
4124                 }
4125             }
4126             if (ogv) {
4127                 orig_keyword = tmp;
4128                 tmp = 0;                /* overridden by import or by GLOBAL */
4129             }
4130             else if (gv && !gvp
4131                      && -tmp==KEY_lock  /* XXX generalizable kludge */
4132                      && GvCVu(gv)
4133                      && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
4134             {
4135                 tmp = 0;                /* any sub overrides "weak" keyword */
4136             }
4137             else if (gv && !gvp
4138                     && tmp == -KEY_err
4139                     && GvCVu(gv)
4140                     && PL_expect != XOPERATOR
4141                     && PL_expect != XTERMORDORDOR)
4142             {
4143                 /* any sub overrides the "err" keyword, except when really an
4144                  * operator is expected */
4145                 tmp = 0;
4146             }
4147             else {                      /* no override */
4148                 tmp = -tmp;
4149                 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
4150                     Perl_warner(aTHX_ packWARN(WARN_MISC),
4151                             "dump() better written as CORE::dump()");
4152                 }
4153                 gv = Nullgv;
4154                 gvp = 0;
4155                 if (hgv && tmp != KEY_x && tmp != KEY_CORE
4156                         && ckWARN(WARN_AMBIGUOUS))      /* never ambiguous */
4157                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4158                         "Ambiguous call resolved as CORE::%s(), %s",
4159                          GvENAME(hgv), "qualify as such or use &");
4160             }
4161         }
4162
4163       reserved_word:
4164         switch (tmp) {
4165
4166         default:                        /* not a keyword */
4167           just_a_word: {
4168                 SV *sv;
4169                 int pkgname = 0;
4170                 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
4171
4172                 /* Get the rest if it looks like a package qualifier */
4173
4174                 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
4175                     STRLEN morelen;
4176                     s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
4177                                   TRUE, &morelen);
4178                     if (!morelen)
4179                         Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
4180                                 *s == '\'' ? "'" : "::");
4181                     len += morelen;
4182                     pkgname = 1;
4183                 }
4184
4185                 if (PL_expect == XOPERATOR) {
4186                     if (PL_bufptr == PL_linestart) {
4187                         CopLINE_dec(PL_curcop);
4188                         Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4189                         CopLINE_inc(PL_curcop);
4190                     }
4191                     else
4192                         no_op("Bareword",s);
4193                 }
4194
4195                 /* Look for a subroutine with this name in current package,
4196                    unless name is "Foo::", in which case Foo is a bearword
4197                    (and a package name). */
4198
4199                 if (len > 2 &&
4200                     PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
4201                 {
4202                     if (ckWARN(WARN_BAREWORD) && ! gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVHV))
4203                         Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
4204                             "Bareword \"%s\" refers to nonexistent package",
4205                              PL_tokenbuf);
4206                     len -= 2;
4207                     PL_tokenbuf[len] = '\0';
4208                     gv = Nullgv;
4209                     gvp = 0;
4210                 }
4211                 else {
4212                     len = 0;
4213                     if (!gv)
4214                         gv = gv_fetchpv(PL_tokenbuf, FALSE, SVt_PVCV);
4215                 }
4216
4217                 /* if we saw a global override before, get the right name */
4218
4219                 if (gvp) {
4220                     sv = newSVpvn("CORE::GLOBAL::",14);
4221                     sv_catpv(sv,PL_tokenbuf);
4222                 }
4223                 else {
4224                     /* If len is 0, newSVpv does strlen(), which is correct.
4225                        If len is non-zero, then it will be the true length,
4226                        and so the scalar will be created correctly.  */
4227                     sv = newSVpv(PL_tokenbuf,len);
4228                 }
4229
4230                 /* Presume this is going to be a bareword of some sort. */
4231
4232                 CLINE;
4233                 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4234                 yylval.opval->op_private = OPpCONST_BARE;
4235                 /* UTF-8 package name? */
4236                 if (UTF && !IN_BYTES &&
4237                     is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
4238                     SvUTF8_on(sv);
4239
4240                 /* And if "Foo::", then that's what it certainly is. */
4241
4242                 if (len)
4243                     goto safe_bareword;
4244
4245                 /* See if it's the indirect object for a list operator. */
4246
4247                 if (PL_oldoldbufptr &&
4248                     PL_oldoldbufptr < PL_bufptr &&
4249                     (PL_oldoldbufptr == PL_last_lop
4250                      || PL_oldoldbufptr == PL_last_uni) &&
4251                     /* NO SKIPSPACE BEFORE HERE! */
4252                     (PL_expect == XREF ||
4253                      ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
4254                 {
4255                     bool immediate_paren = *s == '(';
4256
4257                     /* (Now we can afford to cross potential line boundary.) */
4258                     s = skipspace(s);
4259
4260                     /* Two barewords in a row may indicate method call. */
4261
4262                     if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') && (tmp=intuit_method(s,gv)))
4263                         return REPORT(tmp);
4264
4265                     /* If not a declared subroutine, it's an indirect object. */
4266                     /* (But it's an indir obj regardless for sort.) */
4267
4268                     if ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
4269                          ((!gv || !GvCVu(gv)) &&
4270                         (PL_last_lop_op != OP_MAPSTART &&
4271                          PL_last_lop_op != OP_GREPSTART))))
4272                     {
4273                         PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
4274                         goto bareword;
4275                     }
4276                 }
4277
4278                 PL_expect = XOPERATOR;
4279                 s = skipspace(s);
4280
4281                 /* Is this a word before a => operator? */
4282                 if (*s == '=' && s[1] == '>' && !pkgname) {
4283                     CLINE;
4284                     sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
4285                     if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
4286                       SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
4287                     TERM(WORD);
4288                 }
4289
4290                 /* If followed by a paren, it's certainly a subroutine. */
4291                 if (*s == '(') {
4292                     CLINE;
4293                     if (gv && GvCVu(gv)) {
4294                         for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
4295                         if (*d == ')' && (sv = cv_const_sv(GvCV(gv)))) {
4296                             s = d + 1;
4297                             goto its_constant;
4298                         }
4299                     }
4300                     PL_nextval[PL_nexttoke].opval = yylval.opval;
4301                     PL_expect = XOPERATOR;
4302                     force_next(WORD);
4303                     yylval.ival = 0;
4304                     TOKEN('&');
4305                 }
4306
4307                 /* If followed by var or block, call it a method (unless sub) */
4308
4309                 if ((*s == '$' || *s == '{') && (!gv || !GvCVu(gv))) {
4310                     PL_last_lop = PL_oldbufptr;
4311                     PL_last_lop_op = OP_METHOD;
4312                     PREBLOCK(METHOD);
4313                 }
4314
4315                 /* If followed by a bareword, see if it looks like indir obj. */
4316
4317                 if (!orig_keyword
4318                         && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
4319                         && (tmp = intuit_method(s,gv)))
4320                     return REPORT(tmp);
4321
4322                 /* Not a method, so call it a subroutine (if defined) */
4323
4324                 if (gv && GvCVu(gv)) {
4325                     CV* cv;
4326                     if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
4327                         Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4328                                 "Ambiguous use of -%s resolved as -&%s()",
4329                                 PL_tokenbuf, PL_tokenbuf);
4330                     /* Check for a constant sub */
4331                     cv = GvCV(gv);
4332                     if ((sv = cv_const_sv(cv))) {
4333                   its_constant:
4334                         SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
4335                         ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc(sv);
4336                         yylval.opval->op_private = 0;
4337                         TOKEN(WORD);
4338                     }
4339
4340                     /* Resolve to GV now. */
4341                     op_free(yylval.opval);
4342                     yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
4343                     yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
4344                     PL_last_lop = PL_oldbufptr;
4345                     PL_last_lop_op = OP_ENTERSUB;
4346                     /* Is there a prototype? */
4347                     if (SvPOK(cv)) {
4348                         STRLEN len;
4349                         const char *proto = SvPV_const((SV*)cv, len);
4350                         if (!len)
4351                             TERM(FUNC0SUB);
4352                         if (*proto == '$' && proto[1] == '\0')
4353                             OPERATOR(UNIOPSUB);
4354                         while (*proto == ';')
4355                             proto++;
4356                         if (*proto == '&' && *s == '{') {
4357                             sv_setpv(PL_subname, PL_curstash ?
4358                                         "__ANON__" : "__ANON__::__ANON__");
4359                             PREBLOCK(LSTOPSUB);
4360                         }
4361                     }
4362                     PL_nextval[PL_nexttoke].opval = yylval.opval;
4363                     PL_expect = XTERM;
4364                     force_next(WORD);
4365                     TOKEN(NOAMP);
4366                 }
4367
4368                 /* Call it a bare word */
4369
4370                 if (PL_hints & HINT_STRICT_SUBS)
4371                     yylval.opval->op_private |= OPpCONST_STRICT;
4372                 else {
4373                 bareword:
4374                     if (lastchar != '-') {
4375                         if (ckWARN(WARN_RESERVED)) {
4376                             for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
4377                             if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
4378                                 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
4379                                        PL_tokenbuf);
4380                         }
4381                     }
4382                 }
4383
4384             safe_bareword:
4385                 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
4386                     && ckWARN_d(WARN_AMBIGUOUS)) {
4387                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4388                         "Operator or semicolon missing before %c%s",
4389                         lastchar, PL_tokenbuf);
4390                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4391                         "Ambiguous use of %c resolved as operator %c",
4392                         lastchar, lastchar);
4393                 }
4394                 TOKEN(WORD);
4395             }
4396
4397         case KEY___FILE__:
4398             yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4399                                         newSVpv(CopFILE(PL_curcop),0));
4400             TERM(THING);
4401
4402         case KEY___LINE__:
4403             yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4404                                     Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
4405             TERM(THING);
4406
4407         case KEY___PACKAGE__:
4408             yylval.opval = (OP*)newSVOP(OP_CONST, 0,
4409                                         (PL_curstash
4410                                          ? newSVhek(HvNAME_HEK(PL_curstash))
4411                                          : &PL_sv_undef));
4412             TERM(THING);
4413
4414         case KEY___DATA__:
4415         case KEY___END__: {
4416             GV *gv;
4417             if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
4418                 const char *pname = "main";
4419                 if (PL_tokenbuf[2] == 'D')
4420                     pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
4421                 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);
4422                 GvMULTI_on(gv);
4423                 if (!GvIO(gv))
4424                     GvIOp(gv) = newIO();
4425                 IoIFP(GvIOp(gv)) = PL_rsfp;
4426 #if defined(HAS_FCNTL) && defined(F_SETFD)
4427                 {
4428                     const int fd = PerlIO_fileno(PL_rsfp);
4429                     fcntl(fd,F_SETFD,fd >= 3);
4430                 }
4431 #endif
4432                 /* Mark this internal pseudo-handle as clean */
4433                 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4434                 if (PL_preprocess)
4435                     IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
4436                 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
4437                     IoTYPE(GvIOp(gv)) = IoTYPE_STD;
4438                 else
4439                     IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
4440 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
4441                 /* if the script was opened in binmode, we need to revert
4442                  * it to text mode for compatibility; but only iff it has CRs
4443                  * XXX this is a questionable hack at best. */
4444                 if (PL_bufend-PL_bufptr > 2
4445                     && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
4446                 {
4447                     Off_t loc = 0;
4448                     if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
4449                         loc = PerlIO_tell(PL_rsfp);
4450                         (void)PerlIO_seek(PL_rsfp, 0L, 0);
4451                     }
4452 #ifdef NETWARE
4453                         if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
4454 #else
4455                     if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
4456 #endif  /* NETWARE */
4457 #ifdef PERLIO_IS_STDIO /* really? */
4458 #  if defined(__BORLANDC__)
4459                         /* XXX see note in do_binmode() */
4460                         ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
4461 #  endif
4462 #endif
4463                         if (loc > 0)
4464                             PerlIO_seek(PL_rsfp, loc, 0);
4465                     }
4466                 }
4467 #endif
4468 #ifdef PERLIO_LAYERS
4469                 if (!IN_BYTES) {
4470                     if (UTF)
4471                         PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
4472                     else if (PL_encoding) {
4473                         SV *name;
4474                         dSP;
4475                         ENTER;
4476                         SAVETMPS;
4477                         PUSHMARK(sp);
4478                         EXTEND(SP, 1);
4479                         XPUSHs(PL_encoding);
4480                         PUTBACK;
4481                         call_method("name", G_SCALAR);
4482                         SPAGAIN;
4483                         name = POPs;
4484                         PUTBACK;
4485                         PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
4486                                             Perl_form(aTHX_ ":encoding(%"SVf")",
4487                                                       name));
4488                         FREETMPS;
4489                         LEAVE;
4490                     }
4491                 }
4492 #endif
4493                 PL_rsfp = Nullfp;
4494             }
4495             goto fake_eof;
4496         }
4497
4498         case KEY_AUTOLOAD:
4499         case KEY_DESTROY:
4500         case KEY_BEGIN:
4501         case KEY_CHECK:
4502         case KEY_INIT:
4503         case KEY_END:
4504             if (PL_expect == XSTATE) {
4505                 s = PL_bufptr;
4506                 goto really_sub;
4507             }
4508             goto just_a_word;
4509
4510         case KEY_CORE:
4511             if (*s == ':' && s[1] == ':') {
4512                 s += 2;
4513                 d = s;
4514                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4515                 if (!(tmp = keyword(PL_tokenbuf, len)))
4516                     Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
4517                 if (tmp < 0)
4518                     tmp = -tmp;
4519                 goto reserved_word;
4520             }
4521             goto just_a_word;
4522
4523         case KEY_abs:
4524             UNI(OP_ABS);
4525
4526         case KEY_alarm:
4527             UNI(OP_ALARM);
4528
4529         case KEY_accept:
4530             LOP(OP_ACCEPT,XTERM);
4531
4532         case KEY_and:
4533             OPERATOR(ANDOP);
4534
4535         case KEY_atan2:
4536             LOP(OP_ATAN2,XTERM);
4537
4538         case KEY_bind:
4539             LOP(OP_BIND,XTERM);
4540
4541         case KEY_binmode:
4542             LOP(OP_BINMODE,XTERM);
4543
4544         case KEY_bless:
4545             LOP(OP_BLESS,XTERM);
4546
4547         case KEY_chop:
4548             UNI(OP_CHOP);
4549
4550         case KEY_continue:
4551             PREBLOCK(CONTINUE);
4552
4553         case KEY_chdir:
4554             (void)gv_fetchpv("ENV",TRUE, SVt_PVHV);     /* may use HOME */
4555             UNI(OP_CHDIR);
4556
4557         case KEY_close:
4558             UNI(OP_CLOSE);
4559
4560         case KEY_closedir:
4561             UNI(OP_CLOSEDIR);
4562
4563         case KEY_cmp:
4564             Eop(OP_SCMP);
4565
4566         case KEY_caller:
4567             UNI(OP_CALLER);
4568
4569         case KEY_crypt:
4570 #ifdef FCRYPT
4571             if (!PL_cryptseen) {
4572                 PL_cryptseen = TRUE;
4573                 init_des();
4574             }
4575 #endif
4576             LOP(OP_CRYPT,XTERM);
4577
4578         case KEY_chmod:
4579             LOP(OP_CHMOD,XTERM);
4580
4581         case KEY_chown:
4582             LOP(OP_CHOWN,XTERM);
4583
4584         case KEY_connect:
4585             LOP(OP_CONNECT,XTERM);
4586
4587         case KEY_chr:
4588             UNI(OP_CHR);
4589
4590         case KEY_cos:
4591             UNI(OP_COS);
4592
4593         case KEY_chroot:
4594             UNI(OP_CHROOT);
4595
4596         case KEY_do:
4597             s = skipspace(s);
4598             if (*s == '{')
4599                 PRETERMBLOCK(DO);
4600             if (*s != '\'')
4601                 s = force_word(s,WORD,TRUE,TRUE,FALSE);
4602             OPERATOR(DO);
4603
4604         case KEY_die:
4605             PL_hints |= HINT_BLOCK_SCOPE;
4606             LOP(OP_DIE,XTERM);
4607
4608         case KEY_defined:
4609             UNI(OP_DEFINED);
4610
4611         case KEY_delete:
4612             UNI(OP_DELETE);
4613
4614         case KEY_dbmopen:
4615             gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
4616             LOP(OP_DBMOPEN,XTERM);
4617
4618         case KEY_dbmclose:
4619             UNI(OP_DBMCLOSE);
4620
4621         case KEY_dump:
4622             s = force_word(s,WORD,TRUE,FALSE,FALSE);
4623             LOOPX(OP_DUMP);
4624
4625         case KEY_else:
4626             PREBLOCK(ELSE);
4627
4628         case KEY_elsif:
4629             yylval.ival = CopLINE(PL_curcop);
4630             OPERATOR(ELSIF);
4631
4632         case KEY_eq:
4633             Eop(OP_SEQ);
4634
4635         case KEY_exists:
4636             UNI(OP_EXISTS);
4637         
4638         case KEY_exit:
4639             UNI(OP_EXIT);
4640
4641         case KEY_eval:
4642             s = skipspace(s);
4643             PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
4644             UNIBRACK(OP_ENTEREVAL);
4645
4646         case KEY_eof:
4647             UNI(OP_EOF);
4648
4649         case KEY_err:
4650             OPERATOR(DOROP);
4651
4652         case KEY_exp:
4653             UNI(OP_EXP);
4654
4655         case KEY_each:
4656             UNI(OP_EACH);
4657
4658         case KEY_exec:
4659             set_csh();
4660             LOP(OP_EXEC,XREF);
4661
4662         case KEY_endhostent:
4663             FUN0(OP_EHOSTENT);
4664
4665         case KEY_endnetent:
4666             FUN0(OP_ENETENT);
4667
4668         case KEY_endservent:
4669             FUN0(OP_ESERVENT);
4670
4671         case KEY_endprotoent:
4672             FUN0(OP_EPROTOENT);
4673
4674         case KEY_endpwent:
4675             FUN0(OP_EPWENT);
4676
4677         case KEY_endgrent:
4678             FUN0(OP_EGRENT);
4679
4680         case KEY_for:
4681         case KEY_foreach:
4682             yylval.ival = CopLINE(PL_curcop);
4683             s = skipspace(s);
4684             if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
4685                 char *p = s;
4686                 if ((PL_bufend - p) >= 3 &&
4687                     strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
4688                     p += 2;
4689                 else if ((PL_bufend - p) >= 4 &&
4690                     strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
4691                     p += 3;
4692                 p = skipspace(p);
4693                 if (isIDFIRST_lazy_if(p,UTF)) {
4694                     p = scan_ident(p, PL_bufend,
4695                         PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4696                     p = skipspace(p);
4697                 }
4698                 if (*p != '$')
4699                     Perl_croak(aTHX_ "Missing $ on loop variable");
4700             }
4701             OPERATOR(FOR);
4702
4703         case KEY_formline:
4704             LOP(OP_FORMLINE,XTERM);
4705
4706         case KEY_fork:
4707             FUN0(OP_FORK);
4708
4709         case KEY_fcntl:
4710             LOP(OP_FCNTL,XTERM);
4711
4712         case KEY_fileno:
4713             UNI(OP_FILENO);
4714
4715         case KEY_flock:
4716             LOP(OP_FLOCK,XTERM);
4717
4718         case KEY_gt:
4719             Rop(OP_SGT);
4720
4721         case KEY_ge:
4722             Rop(OP_SGE);
4723
4724         case KEY_grep:
4725             LOP(OP_GREPSTART, XREF);
4726
4727         case KEY_goto:
4728             s = force_word(s,WORD,TRUE,FALSE,FALSE);
4729             LOOPX(OP_GOTO);
4730
4731         case KEY_gmtime:
4732             UNI(OP_GMTIME);
4733
4734         case KEY_getc:
4735             UNIDOR(OP_GETC);
4736
4737         case KEY_getppid:
4738             FUN0(OP_GETPPID);
4739
4740         case KEY_getpgrp:
4741             UNI(OP_GETPGRP);
4742
4743         case KEY_getpriority:
4744             LOP(OP_GETPRIORITY,XTERM);
4745
4746         case KEY_getprotobyname:
4747             UNI(OP_GPBYNAME);
4748
4749         case KEY_getprotobynumber:
4750             LOP(OP_GPBYNUMBER,XTERM);
4751
4752         case KEY_getprotoent:
4753             FUN0(OP_GPROTOENT);
4754
4755         case KEY_getpwent:
4756             FUN0(OP_GPWENT);
4757
4758         case KEY_getpwnam:
4759             UNI(OP_GPWNAM);
4760
4761         case KEY_getpwuid:
4762             UNI(OP_GPWUID);
4763
4764         case KEY_getpeername:
4765             UNI(OP_GETPEERNAME);
4766
4767         case KEY_gethostbyname:
4768             UNI(OP_GHBYNAME);
4769
4770         case KEY_gethostbyaddr:
4771             LOP(OP_GHBYADDR,XTERM);
4772
4773         case KEY_gethostent:
4774             FUN0(OP_GHOSTENT);
4775
4776         case KEY_getnetbyname:
4777             UNI(OP_GNBYNAME);
4778
4779         case KEY_getnetbyaddr:
4780             LOP(OP_GNBYADDR,XTERM);
4781
4782         case KEY_getnetent:
4783             FUN0(OP_GNETENT);
4784
4785         case KEY_getservbyname:
4786             LOP(OP_GSBYNAME,XTERM);
4787
4788         case KEY_getservbyport:
4789             LOP(OP_GSBYPORT,XTERM);
4790
4791         case KEY_getservent:
4792             FUN0(OP_GSERVENT);
4793
4794         case KEY_getsockname:
4795             UNI(OP_GETSOCKNAME);
4796
4797         case KEY_getsockopt:
4798             LOP(OP_GSOCKOPT,XTERM);
4799
4800         case KEY_getgrent:
4801             FUN0(OP_GGRENT);
4802
4803         case KEY_getgrnam:
4804             UNI(OP_GGRNAM);
4805
4806         case KEY_getgrgid:
4807             UNI(OP_GGRGID);
4808
4809         case KEY_getlogin:
4810             FUN0(OP_GETLOGIN);
4811
4812         case KEY_glob:
4813             set_csh();
4814             LOP(OP_GLOB,XTERM);
4815
4816         case KEY_hex:
4817             UNI(OP_HEX);
4818
4819         case KEY_if:
4820             yylval.ival = CopLINE(PL_curcop);
4821             OPERATOR(IF);
4822
4823         case KEY_index:
4824             LOP(OP_INDEX,XTERM);
4825
4826         case KEY_int:
4827             UNI(OP_INT);
4828
4829         case KEY_ioctl:
4830             LOP(OP_IOCTL,XTERM);
4831
4832         case KEY_join:
4833             LOP(OP_JOIN,XTERM);
4834
4835         case KEY_keys:
4836             UNI(OP_KEYS);
4837
4838         case KEY_kill:
4839             LOP(OP_KILL,XTERM);
4840
4841         case KEY_last:
4842             s = force_word(s,WORD,TRUE,FALSE,FALSE);
4843             LOOPX(OP_LAST);
4844         
4845         case KEY_lc:
4846             UNI(OP_LC);
4847
4848         case KEY_lcfirst:
4849             UNI(OP_LCFIRST);
4850
4851         case KEY_local:
4852             yylval.ival = 0;
4853             OPERATOR(LOCAL);
4854
4855         case KEY_length:
4856             UNI(OP_LENGTH);
4857
4858         case KEY_lt:
4859             Rop(OP_SLT);
4860
4861         case KEY_le:
4862             Rop(OP_SLE);
4863
4864         case KEY_localtime:
4865             UNI(OP_LOCALTIME);
4866
4867         case KEY_log:
4868             UNI(OP_LOG);
4869
4870         case KEY_link:
4871             LOP(OP_LINK,XTERM);
4872
4873         case KEY_listen:
4874             LOP(OP_LISTEN,XTERM);
4875
4876         case KEY_lock:
4877             UNI(OP_LOCK);
4878
4879         case KEY_lstat:
4880             UNI(OP_LSTAT);
4881
4882         case KEY_m:
4883             s = scan_pat(s,OP_MATCH);
4884             TERM(sublex_start());
4885
4886         case KEY_map:
4887             LOP(OP_MAPSTART, XREF);
4888
4889         case KEY_mkdir:
4890             LOP(OP_MKDIR,XTERM);
4891
4892         case KEY_msgctl:
4893             LOP(OP_MSGCTL,XTERM);
4894
4895         case KEY_msgget:
4896             LOP(OP_MSGGET,XTERM);
4897
4898         case KEY_msgrcv:
4899             LOP(OP_MSGRCV,XTERM);
4900
4901         case KEY_msgsnd:
4902             LOP(OP_MSGSND,XTERM);
4903
4904         case KEY_our:
4905         case KEY_my:
4906             PL_in_my = tmp;
4907             s = skipspace(s);
4908             if (isIDFIRST_lazy_if(s,UTF)) {
4909                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
4910                 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
4911                     goto really_sub;
4912                 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
4913                 if (!PL_in_my_stash) {
4914                     char tmpbuf[1024];
4915                     PL_bufptr = s;
4916                     sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
4917                     yyerror(tmpbuf);
4918                 }
4919             }
4920             yylval.ival = 1;
4921             OPERATOR(MY);
4922
4923         case KEY_next:
4924             s = force_word(s,WORD,TRUE,FALSE,FALSE);
4925             LOOPX(OP_NEXT);
4926
4927         case KEY_ne:
4928             Eop(OP_SNE);
4929
4930         case KEY_no:
4931             s = tokenize_use(0, s);
4932             OPERATOR(USE);
4933
4934         case KEY_not:
4935             if (*s == '(' || (s = skipspace(s), *s == '('))
4936                 FUN1(OP_NOT);
4937             else
4938                 OPERATOR(NOTOP);
4939
4940         case KEY_open:
4941             s = skipspace(s);
4942             if (isIDFIRST_lazy_if(s,UTF)) {
4943                 const char *t;
4944                 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
4945                 for (t=d; *t && isSPACE(*t); t++) ;
4946                 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
4947                     /* [perl #16184] */
4948                     && !(t[0] == '=' && t[1] == '>')
4949                 ) {
4950                     Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
4951                            "Precedence problem: open %.*s should be open(%.*s)",
4952                             d - s, s, d - s, s);
4953                 }
4954             }
4955             LOP(OP_OPEN,XTERM);
4956
4957         case KEY_or:
4958             yylval.ival = OP_OR;
4959             OPERATOR(OROP);
4960
4961         case KEY_ord:
4962             UNI(OP_ORD);
4963
4964         case KEY_oct:
4965             UNI(OP_OCT);
4966
4967         case KEY_opendir:
4968             LOP(OP_OPEN_DIR,XTERM);
4969
4970         case KEY_print:
4971             checkcomma(s,PL_tokenbuf,"filehandle");
4972             LOP(OP_PRINT,XREF);
4973
4974         case KEY_printf:
4975             checkcomma(s,PL_tokenbuf,"filehandle");
4976             LOP(OP_PRTF,XREF);
4977
4978         case KEY_prototype:
4979             UNI(OP_PROTOTYPE);
4980
4981         case KEY_push:
4982             LOP(OP_PUSH,XTERM);
4983
4984         case KEY_pop:
4985             UNIDOR(OP_POP);
4986
4987         case KEY_pos:
4988             UNIDOR(OP_POS);
4989         
4990         case KEY_pack:
4991             LOP(OP_PACK,XTERM);
4992
4993         case KEY_package:
4994             s = force_word(s,WORD,FALSE,TRUE,FALSE);
4995             OPERATOR(PACKAGE);
4996
4997         case KEY_pipe:
4998             LOP(OP_PIPE_OP,XTERM);
4999
5000         case KEY_q:
5001             s = scan_str(s,FALSE,FALSE);
5002             if (!s)
5003                 missingterm((char*)0);
5004             yylval.ival = OP_CONST;
5005             TERM(sublex_start());
5006
5007         case KEY_quotemeta:
5008             UNI(OP_QUOTEMETA);
5009
5010         case KEY_qw:
5011             s = scan_str(s,FALSE,FALSE);
5012             if (!s)
5013                 missingterm((char*)0);
5014             PL_expect = XOPERATOR;
5015             force_next(')');
5016             if (SvCUR(PL_lex_stuff)) {
5017                 OP *words = Nullop;
5018                 int warned = 0;
5019                 d = SvPV_force(PL_lex_stuff, len);
5020                 while (len) {
5021                     SV *sv;
5022                     for (; isSPACE(*d) && len; --len, ++d) ;
5023                     if (len) {
5024                         const char *b = d;
5025                         if (!warned && ckWARN(WARN_QW)) {
5026                             for (; !isSPACE(*d) && len; --len, ++d) {
5027                                 if (*d == ',') {
5028                                     Perl_warner(aTHX_ packWARN(WARN_QW),
5029                                         "Possible attempt to separate words with commas");
5030                                     ++warned;
5031                                 }
5032                                 else if (*d == '#') {
5033                                     Perl_warner(aTHX_ packWARN(WARN_QW),
5034                                         "Possible attempt to put comments in qw() list");
5035                                     ++warned;
5036                                 }
5037                             }
5038                         }
5039                         else {
5040                             for (; !isSPACE(*d) && len; --len, ++d) ;
5041                         }
5042                         sv = newSVpvn(b, d-b);
5043                         if (DO_UTF8(PL_lex_stuff))
5044                             SvUTF8_on(sv);
5045                         words = append_elem(OP_LIST, words,
5046                                             newSVOP(OP_CONST, 0, tokeq(sv)));
5047                     }
5048                 }
5049                 if (words) {
5050                     PL_nextval[PL_nexttoke].opval = words;
5051                     force_next(THING);
5052                 }
5053             }
5054             if (PL_lex_stuff) {
5055                 SvREFCNT_dec(PL_lex_stuff);
5056                 PL_lex_stuff = Nullsv;
5057             }
5058             PL_expect = XTERM;
5059             TOKEN('(');
5060
5061         case KEY_qq:
5062             s = scan_str(s,FALSE,FALSE);
5063             if (!s)
5064                 missingterm((char*)0);
5065             yylval.ival = OP_STRINGIFY;
5066             if (SvIVX(PL_lex_stuff) == '\'')
5067                 SvIV_set(PL_lex_stuff, 0);      /* qq'$foo' should intepolate */
5068             TERM(sublex_start());
5069
5070         case KEY_qr:
5071             s = scan_pat(s,OP_QR);
5072             TERM(sublex_start());
5073
5074         case KEY_qx:
5075             s = scan_str(s,FALSE,FALSE);
5076             if (!s)
5077                 missingterm((char*)0);
5078             yylval.ival = OP_BACKTICK;
5079             set_csh();
5080             TERM(sublex_start());
5081
5082         case KEY_return:
5083             OLDLOP(OP_RETURN);
5084
5085         case KEY_require:
5086             s = skipspace(s);
5087             if (isDIGIT(*s)) {
5088                 s = force_version(s, FALSE);
5089             }
5090             else if (*s != 'v' || !isDIGIT(s[1])
5091                     || (s = force_version(s, TRUE), *s == 'v'))
5092             {
5093                 *PL_tokenbuf = '\0';
5094                 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5095                 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
5096                     gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
5097                 else if (*s == '<')
5098                     yyerror("<> should be quotes");
5099             }
5100             UNI(OP_REQUIRE);
5101
5102         case KEY_reset:
5103             UNI(OP_RESET);
5104
5105         case KEY_redo:
5106             s = force_word(s,WORD,TRUE,FALSE,FALSE);
5107             LOOPX(OP_REDO);
5108
5109         case KEY_rename:
5110             LOP(OP_RENAME,XTERM);
5111
5112         case KEY_rand:
5113             UNI(OP_RAND);
5114
5115         case KEY_rmdir:
5116             UNI(OP_RMDIR);
5117
5118         case KEY_rindex:
5119             LOP(OP_RINDEX,XTERM);
5120
5121         case KEY_read:
5122             LOP(OP_READ,XTERM);
5123
5124         case KEY_readdir:
5125             UNI(OP_READDIR);
5126
5127         case KEY_readline:
5128             set_csh();
5129             UNIDOR(OP_READLINE);
5130
5131         case KEY_readpipe:
5132             set_csh();
5133             UNI(OP_BACKTICK);
5134
5135         case KEY_rewinddir:
5136             UNI(OP_REWINDDIR);
5137
5138         case KEY_recv:
5139             LOP(OP_RECV,XTERM);
5140
5141         case KEY_reverse:
5142             LOP(OP_REVERSE,XTERM);
5143
5144         case KEY_readlink:
5145             UNIDOR(OP_READLINK);
5146
5147         case KEY_ref:
5148             UNI(OP_REF);
5149
5150         case KEY_s:
5151             s = scan_subst(s);
5152             if (yylval.opval)
5153                 TERM(sublex_start());
5154             else
5155                 TOKEN(1);       /* force error */
5156
5157         case KEY_chomp:
5158             UNI(OP_CHOMP);
5159         
5160         case KEY_scalar:
5161             UNI(OP_SCALAR);
5162
5163         case KEY_select:
5164             LOP(OP_SELECT,XTERM);
5165
5166         case KEY_seek:
5167             LOP(OP_SEEK,XTERM);
5168
5169         case KEY_semctl:
5170             LOP(OP_SEMCTL,XTERM);
5171
5172         case KEY_semget:
5173             LOP(OP_SEMGET,XTERM);
5174
5175         case KEY_semop:
5176             LOP(OP_SEMOP,XTERM);
5177
5178         case KEY_send:
5179             LOP(OP_SEND,XTERM);
5180
5181         case KEY_setpgrp:
5182             LOP(OP_SETPGRP,XTERM);
5183
5184         case KEY_setpriority:
5185             LOP(OP_SETPRIORITY,XTERM);
5186
5187         case KEY_sethostent:
5188             UNI(OP_SHOSTENT);
5189
5190         case KEY_setnetent:
5191             UNI(OP_SNETENT);
5192
5193         case KEY_setservent:
5194             UNI(OP_SSERVENT);
5195
5196         case KEY_setprotoent:
5197             UNI(OP_SPROTOENT);
5198
5199         case KEY_setpwent:
5200             FUN0(OP_SPWENT);
5201
5202         case KEY_setgrent:
5203             FUN0(OP_SGRENT);
5204
5205         case KEY_seekdir:
5206             LOP(OP_SEEKDIR,XTERM);
5207
5208         case KEY_setsockopt:
5209             LOP(OP_SSOCKOPT,XTERM);
5210
5211         case KEY_shift:
5212             UNIDOR(OP_SHIFT);
5213
5214         case KEY_shmctl:
5215             LOP(OP_SHMCTL,XTERM);
5216
5217         case KEY_shmget:
5218             LOP(OP_SHMGET,XTERM);
5219
5220         case KEY_shmread:
5221             LOP(OP_SHMREAD,XTERM);
5222
5223         case KEY_shmwrite:
5224             LOP(OP_SHMWRITE,XTERM);
5225
5226         case KEY_shutdown:
5227             LOP(OP_SHUTDOWN,XTERM);
5228
5229         case KEY_sin:
5230             UNI(OP_SIN);
5231
5232         case KEY_sleep:
5233             UNI(OP_SLEEP);
5234
5235         case KEY_socket:
5236             LOP(OP_SOCKET,XTERM);
5237
5238         case KEY_socketpair:
5239             LOP(OP_SOCKPAIR,XTERM);
5240
5241         case KEY_sort:
5242             checkcomma(s,PL_tokenbuf,"subroutine name");
5243             s = skipspace(s);
5244             if (*s == ';' || *s == ')')         /* probably a close */
5245                 Perl_croak(aTHX_ "sort is now a reserved word");
5246             PL_expect = XTERM;
5247             s = force_word(s,WORD,TRUE,TRUE,FALSE);
5248             LOP(OP_SORT,XREF);
5249
5250         case KEY_split:
5251             LOP(OP_SPLIT,XTERM);
5252
5253         case KEY_sprintf:
5254             LOP(OP_SPRINTF,XTERM);
5255
5256         case KEY_splice:
5257             LOP(OP_SPLICE,XTERM);
5258
5259         case KEY_sqrt:
5260             UNI(OP_SQRT);
5261
5262         case KEY_srand:
5263             UNI(OP_SRAND);
5264
5265         case KEY_stat:
5266             UNI(OP_STAT);
5267
5268         case KEY_study:
5269             UNI(OP_STUDY);
5270
5271         case KEY_substr:
5272             LOP(OP_SUBSTR,XTERM);
5273
5274         case KEY_format:
5275         case KEY_sub:
5276           really_sub:
5277             {
5278                 char tmpbuf[sizeof PL_tokenbuf];
5279                 SSize_t tboffset = 0;
5280                 expectation attrful;
5281                 bool have_name, have_proto, bad_proto;
5282                 const int key = tmp;
5283
5284                 s = skipspace(s);
5285
5286                 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
5287                     (*s == ':' && s[1] == ':'))
5288                 {
5289                     PL_expect = XBLOCK;
5290                     attrful = XATTRBLOCK;
5291                     /* remember buffer pos'n for later force_word */
5292                     tboffset = s - PL_oldbufptr;
5293                     d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5294                     if (strchr(tmpbuf, ':'))
5295                         sv_setpv(PL_subname, tmpbuf);
5296                     else {
5297                         sv_setsv(PL_subname,PL_curstname);
5298                         sv_catpvn(PL_subname,"::",2);
5299                         sv_catpvn(PL_subname,tmpbuf,len);
5300                     }
5301                     s = skipspace(d);
5302                     have_name = TRUE;
5303                 }
5304                 else {
5305                     if (key == KEY_my)
5306                         Perl_croak(aTHX_ "Missing name in \"my sub\"");
5307                     PL_expect = XTERMBLOCK;
5308                     attrful = XATTRTERM;
5309                     sv_setpvn(PL_subname,"?",1);
5310                     have_name = FALSE;
5311                 }
5312
5313                 if (key == KEY_format) {
5314                     if (*s == '=')
5315                         PL_lex_formbrack = PL_lex_brackets + 1;
5316                     if (have_name)
5317                         (void) force_word(PL_oldbufptr + tboffset, WORD,
5318                                           FALSE, TRUE, TRUE);
5319                     OPERATOR(FORMAT);
5320                 }
5321
5322                 /* Look for a prototype */
5323                 if (*s == '(') {
5324                     char *p;
5325
5326                     s = scan_str(s,FALSE,FALSE);
5327                     if (!s)
5328                         Perl_croak(aTHX_ "Prototype not terminated");
5329                     /* strip spaces and check for bad characters */
5330                     d = SvPVX(PL_lex_stuff);
5331                     tmp = 0;
5332                     bad_proto = FALSE;
5333                     for (p = d; *p; ++p) {
5334                         if (!isSPACE(*p)) {
5335                             d[tmp++] = *p;
5336                             if (!strchr("$@%*;[]&\\", *p))
5337                                 bad_proto = TRUE;
5338                         }
5339                     }
5340                     d[tmp] = '\0';
5341                     if (bad_proto && ckWARN(WARN_SYNTAX))
5342                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5343                                     "Illegal character in prototype for %"SVf" : %s",
5344                                     PL_subname, d);
5345                     SvCUR_set(PL_lex_stuff, tmp);
5346                     have_proto = TRUE;
5347
5348                     s = skipspace(s);
5349                 }
5350                 else
5351                     have_proto = FALSE;
5352
5353                 if (*s == ':' && s[1] != ':')
5354                     PL_expect = attrful;
5355                 else if (*s != '{' && key == KEY_sub) {
5356                     if (!have_name)
5357                         Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
5358                     else if (*s != ';')
5359                         Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname);
5360                 }
5361
5362                 if (have_proto) {
5363                     PL_nextval[PL_nexttoke].opval =
5364                         (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
5365                     PL_lex_stuff = Nullsv;
5366                     force_next(THING);
5367                 }
5368                 if (!have_name) {
5369                     sv_setpv(PL_subname,
5370                         PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
5371                     TOKEN(ANONSUB);
5372                 }
5373                 (void) force_word(PL_oldbufptr + tboffset, WORD,
5374                                   FALSE, TRUE, TRUE);
5375                 if (key == KEY_my)
5376                     TOKEN(MYSUB);
5377                 TOKEN(SUB);
5378             }
5379
5380         case KEY_system:
5381             set_csh();
5382             LOP(OP_SYSTEM,XREF);
5383
5384         case KEY_symlink:
5385             LOP(OP_SYMLINK,XTERM);
5386
5387         case KEY_syscall:
5388             LOP(OP_SYSCALL,XTERM);
5389
5390         case KEY_sysopen:
5391             LOP(OP_SYSOPEN,XTERM);
5392
5393         case KEY_sysseek:
5394             LOP(OP_SYSSEEK,XTERM);
5395
5396         case KEY_sysread:
5397             LOP(OP_SYSREAD,XTERM);
5398
5399         case KEY_syswrite:
5400             LOP(OP_SYSWRITE,XTERM);
5401
5402         case KEY_tr:
5403             s = scan_trans(s);
5404             TERM(sublex_start());
5405
5406         case KEY_tell:
5407             UNI(OP_TELL);
5408
5409         case KEY_telldir:
5410             UNI(OP_TELLDIR);
5411
5412         case KEY_tie:
5413             LOP(OP_TIE,XTERM);
5414
5415         case KEY_tied:
5416             UNI(OP_TIED);
5417
5418         case KEY_time:
5419             FUN0(OP_TIME);
5420
5421         case KEY_times:
5422             FUN0(OP_TMS);
5423
5424         case KEY_truncate:
5425             LOP(OP_TRUNCATE,XTERM);
5426
5427         case KEY_uc:
5428             UNI(OP_UC);
5429
5430         case KEY_ucfirst:
5431             UNI(OP_UCFIRST);
5432
5433         case KEY_untie:
5434             UNI(OP_UNTIE);
5435
5436         case KEY_until:
5437             yylval.ival = CopLINE(PL_curcop);
5438             OPERATOR(UNTIL);
5439
5440         case KEY_unless:
5441             yylval.ival = CopLINE(PL_curcop);
5442             OPERATOR(UNLESS);
5443
5444         case KEY_unlink:
5445             LOP(OP_UNLINK,XTERM);
5446
5447         case KEY_undef:
5448             UNIDOR(OP_UNDEF);
5449
5450         case KEY_unpack:
5451             LOP(OP_UNPACK,XTERM);
5452
5453         case KEY_utime:
5454             LOP(OP_UTIME,XTERM);
5455
5456         case KEY_umask:
5457             UNIDOR(OP_UMASK);
5458
5459         case KEY_unshift:
5460             LOP(OP_UNSHIFT,XTERM);
5461
5462         case KEY_use:
5463             s = tokenize_use(1, s);
5464             OPERATOR(USE);
5465
5466         case KEY_values:
5467             UNI(OP_VALUES);
5468
5469         case KEY_vec:
5470             LOP(OP_VEC,XTERM);
5471
5472         case KEY_while:
5473             yylval.ival = CopLINE(PL_curcop);
5474             OPERATOR(WHILE);
5475
5476         case KEY_warn:
5477             PL_hints |= HINT_BLOCK_SCOPE;
5478             LOP(OP_WARN,XTERM);
5479
5480         case KEY_wait:
5481             FUN0(OP_WAIT);
5482
5483         case KEY_waitpid:
5484             LOP(OP_WAITPID,XTERM);
5485
5486         case KEY_wantarray:
5487             FUN0(OP_WANTARRAY);
5488
5489         case KEY_write:
5490 #ifdef EBCDIC
5491         {
5492             char ctl_l[2];
5493             ctl_l[0] = toCTRL('L');
5494             ctl_l[1] = '\0';
5495             gv_fetchpv(ctl_l,TRUE, SVt_PV);
5496         }
5497 #else
5498             gv_fetchpv("\f",TRUE, SVt_PV);      /* Make sure $^L is defined */
5499 #endif
5500             UNI(OP_ENTERWRITE);
5501
5502         case KEY_x:
5503             if (PL_expect == XOPERATOR)
5504                 Mop(OP_REPEAT);
5505             check_uni();
5506             goto just_a_word;
5507
5508         case KEY_xor:
5509             yylval.ival = OP_XOR;
5510             OPERATOR(OROP);
5511
5512         case KEY_y:
5513             s = scan_trans(s);
5514             TERM(sublex_start());
5515         }
5516     }}
5517 }
5518 #ifdef __SC__
5519 #pragma segment Main
5520 #endif
5521
5522 static int
5523 S_pending_ident(pTHX)
5524 {
5525     register char *d;
5526     register I32 tmp = 0;
5527     /* pit holds the identifier we read and pending_ident is reset */
5528     char pit = PL_pending_ident;
5529     PL_pending_ident = 0;
5530
5531     DEBUG_T({ PerlIO_printf(Perl_debug_log,
5532           "### Tokener saw identifier '%s'\n", PL_tokenbuf); });
5533
5534     /* if we're in a my(), we can't allow dynamics here.
5535        $foo'bar has already been turned into $foo::bar, so
5536        just check for colons.
5537
5538        if it's a legal name, the OP is a PADANY.
5539     */
5540     if (PL_in_my) {
5541         if (PL_in_my == KEY_our) {      /* "our" is merely analogous to "my" */
5542             if (strchr(PL_tokenbuf,':'))
5543                 yyerror(Perl_form(aTHX_ "No package name allowed for "
5544                                   "variable %s in \"our\"",
5545                                   PL_tokenbuf));
5546             tmp = allocmy(PL_tokenbuf);
5547         }
5548         else {
5549             if (strchr(PL_tokenbuf,':'))
5550                 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
5551
5552             yylval.opval = newOP(OP_PADANY, 0);
5553             yylval.opval->op_targ = allocmy(PL_tokenbuf);
5554             return PRIVATEREF;
5555         }
5556     }
5557
5558     /*
5559        build the ops for accesses to a my() variable.
5560
5561        Deny my($a) or my($b) in a sort block, *if* $a or $b is
5562        then used in a comparison.  This catches most, but not
5563        all cases.  For instance, it catches
5564            sort { my($a); $a <=> $b }
5565        but not
5566            sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
5567        (although why you'd do that is anyone's guess).
5568     */
5569
5570     if (!strchr(PL_tokenbuf,':')) {
5571         if (!PL_in_my)
5572             tmp = pad_findmy(PL_tokenbuf);
5573         if (tmp != NOT_IN_PAD) {
5574             /* might be an "our" variable" */
5575             if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
5576                 /* build ops for a bareword */
5577                 HV *  const stash = PAD_COMPNAME_OURSTASH(tmp);
5578                 HEK * const stashname = HvNAME_HEK(stash);
5579                 SV *  const sym = newSVhek(stashname);
5580                 sv_catpvn(sym, "::", 2);
5581                 sv_catpv(sym, PL_tokenbuf+1);
5582                 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
5583                 yylval.opval->op_private = OPpCONST_ENTERED;
5584                 gv_fetchsv(sym,
5585                     (PL_in_eval
5586                         ? (GV_ADDMULTI | GV_ADDINEVAL)
5587                         : GV_ADDMULTI
5588                     ),
5589                     ((PL_tokenbuf[0] == '$') ? SVt_PV
5590                      : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5591                      : SVt_PVHV));
5592                 return WORD;
5593             }
5594
5595             /* if it's a sort block and they're naming $a or $b */
5596             if (PL_last_lop_op == OP_SORT &&
5597                 PL_tokenbuf[0] == '$' &&
5598                 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
5599                 && !PL_tokenbuf[2])
5600             {
5601                 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
5602                      d < PL_bufend && *d != '\n';
5603                      d++)
5604                 {
5605                     if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
5606                         Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
5607                               PL_tokenbuf);
5608                     }
5609                 }
5610             }
5611
5612             yylval.opval = newOP(OP_PADANY, 0);
5613             yylval.opval->op_targ = tmp;
5614             return PRIVATEREF;
5615         }
5616     }
5617
5618     /*
5619        Whine if they've said @foo in a doublequoted string,
5620        and @foo isn't a variable we can find in the symbol
5621        table.
5622     */
5623     if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
5624         GV *gv = gv_fetchpv(PL_tokenbuf+1, FALSE, SVt_PVAV);
5625         if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
5626              && ckWARN(WARN_AMBIGUOUS))
5627         {
5628             /* Downgraded from fatal to warning 20000522 mjd */
5629             Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5630                         "Possible unintended interpolation of %s in string",
5631                          PL_tokenbuf);
5632         }
5633     }
5634
5635     /* build ops for a bareword */
5636     yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
5637     yylval.opval->op_private = OPpCONST_ENTERED;
5638     gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
5639                ((PL_tokenbuf[0] == '$') ? SVt_PV
5640                 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
5641                 : SVt_PVHV));
5642     return WORD;
5643 }
5644
5645 /*
5646  *  The following code was generated by perl_keyword.pl.
5647  */
5648
5649 I32
5650 Perl_keyword (pTHX_ const char *name, I32 len)
5651 {
5652   switch (len)
5653   {
5654     case 1: /* 5 tokens of length 1 */
5655       switch (name[0])
5656       {
5657         case 'm':
5658           {                                       /* m          */
5659             return KEY_m;
5660           }
5661
5662         case 'q':
5663           {                                       /* q          */
5664             return KEY_q;
5665           }
5666
5667         case 's':
5668           {                                       /* s          */
5669             return KEY_s;
5670           }
5671
5672         case 'x':
5673           {                                       /* x          */
5674             return -KEY_x;
5675           }
5676
5677         case 'y':
5678           {                                       /* y          */
5679             return KEY_y;
5680           }
5681
5682         default:
5683           goto unknown;
5684       }
5685
5686     case 2: /* 18 tokens of length 2 */
5687       switch (name[0])
5688       {
5689         case 'd':
5690           if (name[1] == 'o')
5691           {                                       /* do         */
5692             return KEY_do;
5693           }
5694
5695           goto unknown;
5696
5697         case 'e':
5698           if (name[1] == 'q')
5699           {                                       /* eq         */
5700             return -KEY_eq;
5701           }
5702
5703           goto unknown;
5704
5705         case 'g':
5706           switch (name[1])
5707           {
5708             case 'e':
5709               {                                   /* ge         */
5710                 return -KEY_ge;
5711               }
5712
5713             case 't':
5714               {                                   /* gt         */
5715                 return -KEY_gt;
5716               }
5717
5718             default:
5719               goto unknown;
5720           }
5721
5722         case 'i':
5723           if (name[1] == 'f')
5724           {                                       /* if         */
5725             return KEY_if;
5726           }
5727
5728           goto unknown;
5729
5730         case 'l':
5731           switch (name[1])
5732           {
5733             case 'c':
5734               {                                   /* lc         */
5735                 return -KEY_lc;
5736               }
5737
5738             case 'e':
5739               {                                   /* le         */
5740                 return -KEY_le;
5741               }
5742
5743             case 't':
5744               {                                   /* lt         */
5745                 return -KEY_lt;
5746               }
5747
5748             default:
5749               goto unknown;
5750           }
5751
5752         case 'm':
5753           if (name[1] == 'y')
5754           {                                       /* my         */
5755             return KEY_my;
5756           }
5757
5758           goto unknown;
5759
5760         case 'n':
5761           switch (name[1])
5762           {
5763             case 'e':
5764               {                                   /* ne         */
5765                 return -KEY_ne;
5766               }
5767
5768             case 'o':
5769               {                                   /* no         */
5770                 return KEY_no;
5771               }
5772
5773             default:
5774               goto unknown;
5775           }
5776
5777         case 'o':
5778           if (name[1] == 'r')
5779           {                                       /* or         */
5780             return -KEY_or;
5781           }
5782
5783           goto unknown;
5784
5785         case 'q':
5786           switch (name[1])
5787           {
5788             case 'q':
5789               {                                   /* qq         */
5790                 return KEY_qq;
5791               }
5792
5793             case 'r':
5794               {                                   /* qr         */
5795                 return KEY_qr;
5796               }
5797
5798             case 'w':
5799               {                                   /* qw         */
5800                 return KEY_qw;
5801               }
5802
5803             case 'x':
5804               {                                   /* qx         */
5805                 return KEY_qx;
5806               }
5807
5808             default:
5809               goto unknown;
5810           }
5811
5812         case 't':
5813           if (name[1] == 'r')
5814           {                                       /* tr         */
5815             return KEY_tr;
5816           }
5817
5818           goto unknown;
5819
5820         case 'u':
5821           if (name[1] == 'c')
5822           {                                       /* uc         */
5823             return -KEY_uc;
5824           }
5825
5826           goto unknown;
5827
5828         default:
5829           goto unknown;
5830       }
5831
5832     case 3: /* 28 tokens of length 3 */
5833       switch (name[0])
5834       {
5835         case 'E':
5836           if (name[1] == 'N' &&
5837               name[2] == 'D')
5838           {                                       /* END        */
5839             return KEY_END;
5840           }
5841
5842           goto unknown;
5843
5844         case 'a':
5845           switch (name[1])
5846           {
5847             case 'b':
5848               if (name[2] == 's')
5849               {                                   /* abs        */
5850                 return -KEY_abs;
5851               }
5852
5853               goto unknown;
5854
5855             case 'n':
5856               if (name[2] == 'd')
5857               {                                   /* and        */
5858                 return -KEY_and;
5859               }
5860
5861               goto unknown;
5862
5863             default:
5864               goto unknown;
5865           }
5866
5867         case 'c':
5868           switch (name[1])
5869           {
5870             case 'h':
5871               if (name[2] == 'r')
5872               {                                   /* chr        */
5873                 return -KEY_chr;
5874               }
5875
5876               goto unknown;
5877
5878             case 'm':
5879               if (name[2] == 'p')
5880               {                                   /* cmp        */
5881                 return -KEY_cmp;
5882               }
5883
5884               goto unknown;
5885
5886             case 'o':
5887               if (name[2] == 's')
5888               {                                   /* cos        */
5889                 return -KEY_cos;
5890               }
5891
5892               goto unknown;
5893
5894             default:
5895               goto unknown;
5896           }
5897
5898         case 'd':
5899           if (name[1] == 'i' &&
5900               name[2] == 'e')
5901           {                                       /* die        */
5902             return -KEY_die;
5903           }
5904
5905           goto unknown;
5906
5907         case 'e':
5908           switch (name[1])
5909           {
5910             case 'o':
5911               if (name[2] == 'f')
5912               {                                   /* eof        */
5913                 return -KEY_eof;
5914               }
5915
5916               goto unknown;
5917
5918             case 'r':
5919               if (name[2] == 'r')
5920               {                                   /* err        */
5921                 return -KEY_err;
5922               }
5923
5924               goto unknown;
5925
5926             case 'x':
5927               if (name[2] == 'p')
5928               {                                   /* exp        */
5929                 return -KEY_exp;
5930               }
5931
5932               goto unknown;
5933
5934             default:
5935               goto unknown;
5936           }
5937
5938         case 'f':
5939           if (name[1] == 'o' &&
5940               name[2] == 'r')
5941           {                                       /* for        */
5942             return KEY_for;
5943           }
5944
5945           goto unknown;
5946
5947         case 'h':
5948           if (name[1] == 'e' &&
5949               name[2] == 'x')
5950           {                                       /* hex        */
5951             return -KEY_hex;
5952           }
5953
5954           goto unknown;
5955
5956         case 'i':
5957           if (name[1] == 'n' &&
5958               name[2] == 't')
5959           {                                       /* int        */
5960             return -KEY_int;
5961           }
5962
5963           goto unknown;
5964
5965         case 'l':
5966           if (name[1] == 'o' &&
5967               name[2] == 'g')
5968           {                                       /* log        */
5969             return -KEY_log;
5970           }
5971
5972           goto unknown;
5973
5974         case 'm':
5975           if (name[1] == 'a' &&
5976               name[2] == 'p')
5977           {                                       /* map        */
5978             return KEY_map;
5979           }
5980
5981           goto unknown;
5982
5983         case 'n':
5984           if (name[1] == 'o' &&
5985               name[2] == 't')
5986           {                                       /* not        */
5987             return -KEY_not;
5988           }
5989
5990           goto unknown;
5991
5992         case 'o':
5993           switch (name[1])
5994           {
5995             case 'c':
5996               if (name[2] == 't')
5997               {                                   /* oct        */
5998                 return -KEY_oct;
5999               }
6000
6001               goto unknown;
6002
6003             case 'r':
6004               if (name[2] == 'd')
6005               {                                   /* ord        */
6006                 return -KEY_ord;
6007               }
6008
6009               goto unknown;
6010
6011             case 'u':
6012               if (name[2] == 'r')
6013               {                                   /* our        */
6014                 return KEY_our;
6015               }
6016
6017               goto unknown;
6018
6019             default:
6020               goto unknown;
6021           }
6022
6023         case 'p':
6024           if (name[1] == 'o')
6025           {
6026             switch (name[2])
6027             {
6028               case 'p':
6029                 {                                 /* pop        */
6030                   return -KEY_pop;
6031                 }
6032
6033               case 's':
6034                 {                                 /* pos        */
6035                   return KEY_pos;
6036                 }
6037
6038               default:
6039                 goto unknown;
6040             }
6041           }
6042
6043           goto unknown;
6044
6045         case 'r':
6046           if (name[1] == 'e' &&
6047               name[2] == 'f')
6048           {                                       /* ref        */
6049             return -KEY_ref;
6050           }
6051
6052           goto unknown;
6053
6054         case 's':
6055           switch (name[1])
6056           {
6057             case 'i':
6058               if (name[2] == 'n')
6059               {                                   /* sin        */
6060                 return -KEY_sin;
6061               }
6062
6063               goto unknown;
6064
6065             case 'u':
6066               if (name[2] == 'b')
6067               {                                   /* sub        */
6068                 return KEY_sub;
6069               }
6070
6071               goto unknown;
6072
6073             default:
6074               goto unknown;
6075           }
6076
6077         case 't':
6078           if (name[1] == 'i' &&
6079               name[2] == 'e')
6080           {                                       /* tie        */
6081             return KEY_tie;
6082           }
6083
6084           goto unknown;
6085
6086         case 'u':
6087           if (name[1] == 's' &&
6088               name[2] == 'e')
6089           {                                       /* use        */
6090             return KEY_use;
6091           }
6092
6093           goto unknown;
6094
6095         case 'v':
6096           if (name[1] == 'e' &&
6097               name[2] == 'c')
6098           {                                       /* vec        */
6099             return -KEY_vec;
6100           }
6101
6102           goto unknown;
6103
6104         case 'x':
6105           if (name[1] == 'o' &&
6106               name[2] == 'r')
6107           {                                       /* xor        */
6108             return -KEY_xor;
6109           }
6110
6111           goto unknown;
6112
6113         default:
6114           goto unknown;
6115       }
6116
6117     case 4: /* 40 tokens of length 4 */
6118       switch (name[0])
6119       {
6120         case 'C':
6121           if (name[1] == 'O' &&
6122               name[2] == 'R' &&
6123               name[3] == 'E')
6124           {                                       /* CORE       */
6125             return -KEY_CORE;
6126           }
6127
6128           goto unknown;
6129
6130         case 'I':
6131           if (name[1] == 'N' &&
6132               name[2] == 'I' &&
6133               name[3] == 'T')
6134           {                                       /* INIT       */
6135             return KEY_INIT;
6136           }
6137
6138           goto unknown;
6139
6140         case 'b':
6141           if (name[1] == 'i' &&
6142               name[2] == 'n' &&
6143               name[3] == 'd')
6144           {                                       /* bind       */
6145             return -KEY_bind;
6146           }
6147
6148           goto unknown;
6149
6150         case 'c':
6151           if (name[1] == 'h' &&
6152               name[2] == 'o' &&
6153               name[3] == 'p')
6154           {                                       /* chop       */
6155             return -KEY_chop;
6156           }
6157
6158           goto unknown;
6159
6160         case 'd':
6161           if (name[1] == 'u' &&
6162               name[2] == 'm' &&
6163               name[3] == 'p')
6164           {                                       /* dump       */
6165             return -KEY_dump;
6166           }
6167
6168           goto unknown;
6169
6170         case 'e':
6171           switch (name[1])
6172           {
6173             case 'a':
6174               if (name[2] == 'c' &&
6175                   name[3] == 'h')
6176               {                                   /* each       */
6177                 return -KEY_each;
6178               }
6179
6180               goto unknown;
6181
6182             case 'l':
6183               if (name[2] == 's' &&
6184                   name[3] == 'e')
6185               {                                   /* else       */
6186                 return KEY_else;
6187               }
6188
6189               goto unknown;
6190
6191             case 'v':
6192               if (name[2] == 'a' &&
6193                   name[3] == 'l')
6194               {                                   /* eval       */
6195                 return KEY_eval;
6196               }
6197
6198               goto unknown;
6199
6200             case 'x':
6201               switch (name[2])
6202               {
6203                 case 'e':
6204                   if (name[3] == 'c')
6205                   {                               /* exec       */
6206                     return -KEY_exec;
6207                   }
6208
6209                   goto unknown;
6210
6211                 case 'i':
6212                   if (name[3] == 't')
6213                   {                               /* exit       */
6214                     return -KEY_exit;
6215                   }
6216
6217                   goto unknown;
6218
6219                 default:
6220                   goto unknown;
6221               }
6222
6223             default:
6224               goto unknown;
6225           }
6226
6227         case 'f':
6228           if (name[1] == 'o' &&
6229               name[2] == 'r' &&
6230               name[3] == 'k')
6231           {                                       /* fork       */
6232             return -KEY_fork;
6233           }
6234
6235           goto unknown;
6236
6237         case 'g':
6238           switch (name[1])
6239           {
6240             case 'e':
6241               if (name[2] == 't' &&
6242                   name[3] == 'c')
6243               {                                   /* getc       */
6244                 return -KEY_getc;
6245               }
6246
6247               goto unknown;
6248
6249             case 'l':
6250               if (name[2] == 'o' &&
6251                   name[3] == 'b')
6252               {                                   /* glob       */
6253                 return KEY_glob;
6254               }
6255
6256               goto unknown;
6257
6258             case 'o':
6259               if (name[2] == 't' &&
6260                   name[3] == 'o')
6261               {                                   /* goto       */
6262                 return KEY_goto;
6263               }
6264
6265               goto unknown;
6266
6267             case 'r':
6268               if (name[2] == 'e' &&
6269                   name[3] == 'p')
6270               {                                   /* grep       */
6271                 return KEY_grep;
6272               }
6273
6274               goto unknown;
6275
6276             default:
6277               goto unknown;
6278           }
6279
6280         case 'j':
6281           if (name[1] == 'o' &&
6282               name[2] == 'i' &&
6283               name[3] == 'n')
6284           {                                       /* join       */
6285             return -KEY_join;
6286           }
6287
6288           goto unknown;
6289
6290         case 'k':
6291           switch (name[1])
6292           {
6293             case 'e':
6294               if (name[2] == 'y' &&
6295                   name[3] == 's')
6296               {                                   /* keys       */
6297                 return -KEY_keys;
6298               }
6299
6300               goto unknown;
6301
6302             case 'i':
6303               if (name[2] == 'l' &&
6304                   name[3] == 'l')
6305               {                                   /* kill       */
6306                 return -KEY_kill;
6307               }
6308
6309               goto unknown;
6310
6311             default:
6312               goto unknown;
6313           }
6314
6315         case 'l':
6316           switch (name[1])
6317           {
6318             case 'a':
6319               if (name[2] == 's' &&
6320                   name[3] == 't')
6321               {                                   /* last       */
6322                 return KEY_last;
6323               }
6324
6325               goto unknown;
6326
6327             case 'i':
6328               if (name[2] == 'n' &&
6329                   name[3] == 'k')
6330               {                                   /* link       */
6331                 return -KEY_link;
6332               }
6333
6334               goto unknown;
6335
6336             case 'o':
6337               if (name[2] == 'c' &&
6338                   name[3] == 'k')
6339               {                                   /* lock       */
6340                 return -KEY_lock;
6341               }
6342
6343               goto unknown;
6344
6345             default:
6346               goto unknown;
6347           }
6348
6349         case 'n':
6350           if (name[1] == 'e' &&
6351               name[2] == 'x' &&
6352               name[3] == 't')
6353           {                                       /* next       */
6354             return KEY_next;
6355           }
6356
6357           goto unknown;
6358
6359         case 'o':
6360           if (name[1] == 'p' &&
6361               name[2] == 'e' &&
6362               name[3] == 'n')
6363           {                                       /* open       */
6364             return -KEY_open;
6365           }
6366
6367           goto unknown;
6368
6369         case 'p':
6370           switch (name[1])
6371           {
6372             case 'a':
6373               if (name[2] == 'c' &&
6374                   name[3] == 'k')
6375               {                                   /* pack       */
6376                 return -KEY_pack;
6377               }
6378
6379               goto unknown;
6380
6381             case 'i':
6382               if (name[2] == 'p' &&
6383                   name[3] == 'e')
6384               {                                   /* pipe       */
6385                 return -KEY_pipe;
6386               }
6387
6388               goto unknown;
6389
6390             case 'u':
6391               if (name[2] == 's' &&
6392                   name[3] == 'h')
6393               {                                   /* push       */
6394                 return -KEY_push;
6395               }
6396
6397               goto unknown;
6398
6399             default:
6400               goto unknown;
6401           }
6402
6403         case 'r':
6404           switch (name[1])
6405           {
6406             case 'a':
6407               if (name[2] == 'n' &&
6408                   name[3] == 'd')
6409               {                                   /* rand       */
6410                 return -KEY_rand;
6411               }
6412
6413               goto unknown;
6414
6415             case 'e':
6416               switch (name[2])
6417               {
6418                 case 'a':
6419                   if (name[3] == 'd')
6420                   {                               /* read       */
6421                     return -KEY_read;
6422                   }
6423
6424                   goto unknown;
6425
6426                 case 'c':
6427                   if (name[3] == 'v')
6428                   {                               /* recv       */
6429                     return -KEY_recv;
6430                   }
6431
6432                   goto unknown;
6433
6434                 case 'd':
6435                   if (name[3] == 'o')
6436                   {                               /* redo       */
6437                     return KEY_redo;
6438                   }
6439
6440                   goto unknown;
6441
6442                 default:
6443                   goto unknown;
6444               }
6445
6446             default:
6447               goto unknown;
6448           }
6449
6450         case 's':
6451           switch (name[1])
6452           {
6453             case 'e':
6454               switch (name[2])
6455               {
6456                 case 'e':
6457                   if (name[3] == 'k')
6458                   {                               /* seek       */
6459                     return -KEY_seek;
6460                   }
6461
6462                   goto unknown;
6463
6464                 case 'n':
6465                   if (name[3] == 'd')
6466                   {                               /* send       */
6467                     return -KEY_send;
6468                   }
6469
6470                   goto unknown;
6471
6472                 default:
6473                   goto unknown;
6474               }
6475
6476             case 'o':
6477               if (name[2] == 'r' &&
6478                   name[3] == 't')
6479               {                                   /* sort       */
6480                 return KEY_sort;
6481               }
6482
6483               goto unknown;
6484
6485             case 'q':
6486               if (name[2] == 'r' &&
6487                   name[3] == 't')
6488               {                                   /* sqrt       */
6489                 return -KEY_sqrt;
6490               }
6491
6492               goto unknown;
6493
6494             case 't':
6495               if (name[2] == 'a' &&
6496                   name[3] == 't')
6497               {                                   /* stat       */
6498                 return -KEY_stat;
6499               }
6500
6501               goto unknown;
6502
6503             default:
6504               goto unknown;
6505           }
6506
6507         case 't':
6508           switch (name[1])
6509           {
6510             case 'e':
6511               if (name[2] == 'l' &&
6512                   name[3] == 'l')
6513               {                                   /* tell       */
6514                 return -KEY_tell;
6515               }
6516
6517               goto unknown;
6518
6519             case 'i':
6520               switch (name[2])
6521               {
6522                 case 'e':
6523                   if (name[3] == 'd')
6524                   {                               /* tied       */
6525                     return KEY_tied;
6526                   }
6527
6528                   goto unknown;
6529
6530                 case 'm':
6531                   if (name[3] == 'e')
6532                   {                               /* time       */
6533                     return -KEY_time;
6534                   }
6535
6536                   goto unknown;
6537
6538                 default:
6539                   goto unknown;
6540               }
6541
6542             default:
6543               goto unknown;
6544           }
6545
6546         case 'w':
6547           if (name[1] == 'a')
6548           {
6549             switch (name[2])
6550             {
6551               case 'i':
6552                 if (name[3] == 't')
6553                 {                                 /* wait       */
6554                   return -KEY_wait;
6555                 }
6556
6557                 goto unknown;
6558
6559               case 'r':
6560                 if (name[3] == 'n')
6561                 {                                 /* warn       */
6562                   return -KEY_warn;
6563                 }
6564
6565                 goto unknown;
6566
6567               default:
6568                 goto unknown;
6569             }
6570           }
6571
6572           goto unknown;
6573
6574         default:
6575           goto unknown;
6576       }
6577
6578     case 5: /* 36 tokens of length 5 */
6579       switch (name[0])
6580       {
6581         case 'B':
6582           if (name[1] == 'E' &&
6583               name[2] == 'G' &&
6584               name[3] == 'I' &&
6585               name[4] == 'N')
6586           {                                       /* BEGIN      */
6587             return KEY_BEGIN;
6588           }
6589
6590           goto unknown;
6591
6592         case 'C':
6593           if (name[1] == 'H' &&
6594               name[2] == 'E' &&
6595               name[3] == 'C' &&
6596               name[4] == 'K')
6597           {                                       /* CHECK      */
6598             return KEY_CHECK;
6599           }
6600
6601           goto unknown;
6602
6603         case 'a':
6604           switch (name[1])
6605           {
6606             case 'l':
6607               if (name[2] == 'a' &&
6608                   name[3] == 'r' &&
6609                   name[4] == 'm')
6610               {                                   /* alarm      */
6611                 return -KEY_alarm;
6612               }
6613
6614               goto unknown;
6615
6616             case 't':
6617               if (name[2] == 'a' &&
6618                   name[3] == 'n' &&
6619                   name[4] == '2')
6620               {                                   /* atan2      */
6621                 return -KEY_atan2;
6622               }
6623
6624               goto unknown;
6625
6626             default:
6627               goto unknown;
6628           }
6629
6630         case 'b':
6631           if (name[1] == 'l' &&
6632               name[2] == 'e' &&
6633               name[3] == 's' &&
6634               name[4] == 's')
6635           {                                       /* bless      */
6636             return -KEY_bless;
6637           }
6638
6639           goto unknown;
6640
6641         case 'c':
6642           switch (name[1])
6643           {
6644             case 'h':
6645               switch (name[2])
6646               {
6647                 case 'd':
6648                   if (name[3] == 'i' &&
6649                       name[4] == 'r')
6650                   {                               /* chdir      */
6651                     return -KEY_chdir;
6652                   }
6653
6654                   goto unknown;
6655
6656                 case 'm':
6657                   if (name[3] == 'o' &&
6658                       name[4] == 'd')
6659                   {                               /* chmod      */
6660                     return -KEY_chmod;
6661                   }
6662
6663                   goto unknown;
6664
6665                 case 'o':
6666                   switch (name[3])
6667                   {
6668                     case 'm':
6669                       if (name[4] == 'p')
6670                       {                           /* chomp      */
6671                         return -KEY_chomp;
6672                       }
6673
6674                       goto unknown;
6675
6676                     case 'w':
6677                       if (name[4] == 'n')
6678                       {                           /* chown      */
6679                         return -KEY_chown;
6680                       }
6681
6682                       goto unknown;
6683
6684                     default:
6685                       goto unknown;
6686                   }
6687
6688                 default:
6689                   goto unknown;
6690               }
6691
6692             case 'l':
6693               if (name[2] == 'o' &&
6694                   name[3] == 's' &&
6695                   name[4] == 'e')
6696               {                                   /* close      */
6697                 return -KEY_close;
6698               }
6699
6700               goto unknown;
6701
6702             case 'r':
6703               if (name[2] == 'y' &&
6704                   name[3] == 'p' &&
6705                   name[4] == 't')
6706               {                                   /* crypt      */
6707                 return -KEY_crypt;
6708               }
6709
6710               goto unknown;
6711
6712             default:
6713               goto unknown;
6714           }
6715
6716         case 'e':
6717           if (name[1] == 'l' &&
6718               name[2] == 's' &&
6719               name[3] == 'i' &&
6720               name[4] == 'f')
6721           {                                       /* elsif      */
6722             return KEY_elsif;
6723           }
6724
6725           goto unknown;
6726
6727         case 'f':
6728           switch (name[1])
6729           {
6730             case 'c':
6731               if (name[2] == 'n' &&
6732                   name[3] == 't' &&
6733                   name[4] == 'l')
6734               {                                   /* fcntl      */
6735                 return -KEY_fcntl;
6736               }
6737
6738               goto unknown;
6739
6740             case 'l':
6741               if (name[2] == 'o' &&
6742                   name[3] == 'c' &&
6743                   name[4] == 'k')
6744               {                                   /* flock      */
6745                 return -KEY_flock;
6746               }
6747
6748               goto unknown;
6749
6750             default:
6751               goto unknown;
6752           }
6753
6754         case 'i':
6755           switch (name[1])
6756           {
6757             case 'n':
6758               if (name[2] == 'd' &&
6759                   name[3] == 'e' &&
6760                   name[4] == 'x')
6761               {                                   /* index      */
6762                 return -KEY_index;
6763               }
6764
6765               goto unknown;
6766
6767             case 'o':
6768               if (name[2] == 'c' &&
6769                   name[3] == 't' &&
6770                   name[4] == 'l')
6771               {                                   /* ioctl      */
6772                 return -KEY_ioctl;
6773               }
6774
6775               goto unknown;
6776
6777             default:
6778               goto unknown;
6779           }
6780
6781         case 'l':
6782           switch (name[1])
6783           {
6784             case 'o':
6785               if (name[2] == 'c' &&
6786                   name[3] == 'a' &&
6787                   name[4] == 'l')
6788               {                                   /* local      */
6789                 return KEY_local;
6790               }
6791
6792               goto unknown;
6793
6794             case 's':
6795               if (name[2] == 't' &&
6796                   name[3] == 'a' &&
6797                   name[4] == 't')
6798               {                                   /* lstat      */
6799                 return -KEY_lstat;
6800               }
6801
6802               goto unknown;
6803
6804             default:
6805               goto unknown;
6806           }
6807
6808         case 'm':
6809           if (name[1] == 'k' &&
6810               name[2] == 'd' &&
6811               name[3] == 'i' &&
6812               name[4] == 'r')
6813           {                                       /* mkdir      */
6814             return -KEY_mkdir;
6815           }
6816
6817           goto unknown;
6818
6819         case 'p':
6820           if (name[1] == 'r' &&
6821               name[2] == 'i' &&
6822               name[3] == 'n' &&
6823               name[4] == 't')
6824           {                                       /* print      */
6825             return KEY_print;
6826           }
6827
6828           goto unknown;
6829
6830         case 'r':
6831           switch (name[1])
6832           {
6833             case 'e':
6834               if (name[2] == 's' &&
6835                   name[3] == 'e' &&
6836                   name[4] == 't')
6837               {                                   /* reset      */
6838                 return -KEY_reset;
6839               }
6840
6841               goto unknown;
6842
6843             case 'm':
6844               if (name[2] == 'd' &&
6845                   name[3] == 'i' &&
6846                   name[4] == 'r')
6847               {                                   /* rmdir      */
6848                 return -KEY_rmdir;
6849               }
6850
6851               goto unknown;
6852
6853             default:
6854               goto unknown;
6855           }
6856
6857         case 's':
6858           switch (name[1])
6859           {
6860             case 'e':
6861               if (name[2] == 'm' &&
6862                   name[3] == 'o' &&
6863                   name[4] == 'p')
6864               {                                   /* semop      */
6865                 return -KEY_semop;
6866               }
6867
6868               goto unknown;
6869
6870             case 'h':
6871               if (name[2] == 'i' &&
6872                   name[3] == 'f' &&
6873                   name[4] == 't')
6874               {                                   /* shift      */
6875                 return -KEY_shift;
6876               }
6877
6878               goto unknown;
6879
6880             case 'l':
6881               if (name[2] == 'e' &&
6882                   name[3] == 'e' &&
6883                   name[4] == 'p')
6884               {                                   /* sleep      */
6885                 return -KEY_sleep;
6886               }
6887
6888               goto unknown;
6889
6890             case 'p':
6891               if (name[2] == 'l' &&
6892                   name[3] == 'i' &&
6893                   name[4] == 't')
6894               {                                   /* split      */
6895                 return KEY_split;
6896               }
6897
6898               goto unknown;
6899
6900             case 'r':
6901               if (name[2] == 'a' &&
6902                   name[3] == 'n' &&
6903                   name[4] == 'd')
6904               {                                   /* srand      */
6905                 return -KEY_srand;
6906               }
6907
6908               goto unknown;
6909
6910             case 't':
6911               if (name[2] == 'u' &&
6912                   name[3] == 'd' &&
6913                   name[4] == 'y')
6914               {                                   /* study      */
6915                 return KEY_study;
6916               }
6917
6918               goto unknown;
6919
6920             default:
6921               goto unknown;
6922           }
6923
6924         case 't':
6925           if (name[1] == 'i' &&
6926               name[2] == 'm' &&
6927               name[3] == 'e' &&
6928               name[4] == 's')
6929           {                                       /* times      */
6930             return -KEY_times;
6931           }
6932
6933           goto unknown;
6934
6935         case 'u':
6936           switch (name[1])
6937           {
6938             case 'm':
6939               if (name[2] == 'a' &&
6940                   name[3] == 's' &&
6941                   name[4] == 'k')
6942               {                                   /* umask      */
6943                 return -KEY_umask;
6944               }
6945
6946               goto unknown;
6947
6948             case 'n':
6949               switch (name[2])
6950               {
6951                 case 'd':
6952                   if (name[3] == 'e' &&
6953                       name[4] == 'f')
6954                   {                               /* undef      */
6955                     return KEY_undef;
6956                   }
6957
6958                   goto unknown;
6959
6960                 case 't':
6961                   if (name[3] == 'i')
6962                   {
6963                     switch (name[4])
6964                     {
6965                       case 'e':
6966                         {                         /* untie      */
6967                           return KEY_untie;
6968                         }
6969
6970                       case 'l':
6971                         {                         /* until      */
6972                           return KEY_until;
6973                         }
6974
6975                       default:
6976                         goto unknown;
6977                     }
6978                   }
6979
6980                   goto unknown;
6981
6982                 default:
6983                   goto unknown;
6984               }
6985
6986             case 't':
6987               if (name[2] == 'i' &&
6988                   name[3] == 'm' &&
6989                   name[4] == 'e')
6990               {                                   /* utime      */
6991                 return -KEY_utime;
6992               }
6993
6994               goto unknown;
6995
6996             default:
6997               goto unknown;
6998           }
6999
7000         case 'w':
7001           switch (name[1])
7002           {
7003             case 'h':
7004               if (name[2] == 'i' &&
7005                   name[3] == 'l' &&
7006                   name[4] == 'e')
7007               {                                   /* while      */
7008                 return KEY_while;
7009               }
7010
7011               goto unknown;
7012
7013             case 'r':
7014               if (name[2] == 'i' &&
7015                   name[3] == 't' &&
7016                   name[4] == 'e')
7017               {                                   /* write      */
7018                 return -KEY_write;
7019               }
7020
7021               goto unknown;
7022
7023             default:
7024               goto unknown;
7025           }
7026
7027         default:
7028           goto unknown;
7029       }
7030
7031     case 6: /* 33 tokens of length 6 */
7032       switch (name[0])
7033       {
7034         case 'a':
7035           if (name[1] == 'c' &&
7036               name[2] == 'c' &&
7037               name[3] == 'e' &&
7038               name[4] == 'p' &&
7039               name[5] == 't')
7040           {                                       /* accept     */
7041             return -KEY_accept;
7042           }
7043
7044           goto unknown;
7045
7046         case 'c':
7047           switch (name[1])
7048           {
7049             case 'a':
7050               if (name[2] == 'l' &&
7051                   name[3] == 'l' &&
7052                   name[4] == 'e' &&
7053                   name[5] == 'r')
7054               {                                   /* caller     */
7055                 return -KEY_caller;
7056               }
7057
7058               goto unknown;
7059
7060             case 'h':
7061               if (name[2] == 'r' &&
7062                   name[3] == 'o' &&
7063                   name[4] == 'o' &&
7064                   name[5] == 't')
7065               {                                   /* chroot     */
7066                 return -KEY_chroot;
7067               }
7068
7069               goto unknown;
7070
7071             default:
7072               goto unknown;
7073           }
7074
7075         case 'd':
7076           if (name[1] == 'e' &&
7077               name[2] == 'l' &&
7078               name[3] == 'e' &&
7079               name[4] == 't' &&
7080               name[5] == 'e')
7081           {                                       /* delete     */
7082             return KEY_delete;
7083           }
7084
7085           goto unknown;
7086
7087         case 'e':
7088           switch (name[1])
7089           {
7090             case 'l':
7091               if (name[2] == 's' &&
7092                   name[3] == 'e' &&
7093                   name[4] == 'i' &&
7094                   name[5] == 'f')
7095               {                                   /* elseif     */
7096                 if(ckWARN_d(WARN_SYNTAX))
7097                   Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
7098               }
7099
7100               goto unknown;
7101
7102             case 'x':
7103               if (name[2] == 'i' &&
7104                   name[3] == 's' &&
7105                   name[4] == 't' &&
7106                   name[5] == 's')
7107               {                                   /* exists     */
7108                 return KEY_exists;
7109               }
7110
7111               goto unknown;
7112
7113             default:
7114               goto unknown;
7115           }
7116
7117         case 'f':
7118           switch (name[1])
7119           {
7120             case 'i':
7121               if (name[2] == 'l' &&
7122                   name[3] == 'e' &&
7123                   name[4] == 'n' &&
7124                   name[5] == 'o')
7125               {                                   /* fileno     */
7126                 return -KEY_fileno;
7127               }
7128
7129               goto unknown;
7130
7131             case 'o':
7132               if (name[2] == 'r' &&
7133                   name[3] == 'm' &&
7134                   name[4] == 'a' &&
7135                   name[5] == 't')
7136               {                                   /* format     */
7137                 return KEY_format;
7138               }
7139
7140               goto unknown;
7141
7142             default:
7143               goto unknown;
7144           }
7145
7146         case 'g':
7147           if (name[1] == 'm' &&
7148               name[2] == 't' &&
7149               name[3] == 'i' &&
7150               name[4] == 'm' &&
7151               name[5] == 'e')
7152           {                                       /* gmtime     */
7153             return -KEY_gmtime;
7154           }
7155
7156           goto unknown;
7157
7158         case 'l':
7159           switch (name[1])
7160           {
7161             case 'e':
7162               if (name[2] == 'n' &&
7163                   name[3] == 'g' &&
7164                   name[4] == 't' &&
7165                   name[5] == 'h')
7166               {                                   /* length     */
7167                 return -KEY_length;
7168               }
7169
7170               goto unknown;
7171
7172             case 'i':
7173               if (name[2] == 's' &&
7174                   name[3] == 't' &&
7175                   name[4] == 'e' &&
7176                   name[5] == 'n')
7177               {                                   /* listen     */
7178                 return -KEY_listen;
7179               }
7180
7181               goto unknown;
7182
7183             default:
7184               goto unknown;
7185           }
7186
7187         case 'm':
7188           if (name[1] == 's' &&
7189               name[2] == 'g')
7190           {
7191             switch (name[3])
7192             {
7193               case 'c':
7194                 if (name[4] == 't' &&
7195                     name[5] == 'l')
7196                 {                                 /* msgctl     */
7197                   return -KEY_msgctl;
7198                 }
7199
7200                 goto unknown;
7201
7202               case 'g':
7203                 if (name[4] == 'e' &&
7204                     name[5] == 't')
7205                 {                                 /* msgget     */
7206                   return -KEY_msgget;
7207                 }
7208
7209                 goto unknown;
7210
7211               case 'r':
7212                 if (name[4] == 'c' &&
7213                     name[5] == 'v')
7214                 {                                 /* msgrcv     */
7215                   return -KEY_msgrcv;
7216                 }
7217
7218                 goto unknown;
7219
7220               case 's':
7221                 if (name[4] == 'n' &&
7222                     name[5] == 'd')
7223                 {                                 /* msgsnd     */
7224                   return -KEY_msgsnd;
7225                 }
7226
7227                 goto unknown;
7228
7229               default:
7230                 goto unknown;
7231             }
7232           }
7233
7234           goto unknown;
7235
7236         case 'p':
7237           if (name[1] == 'r' &&
7238               name[2] == 'i' &&
7239               name[3] == 'n' &&
7240               name[4] == 't' &&
7241               name[5] == 'f')
7242           {                                       /* printf     */
7243             return KEY_printf;
7244           }
7245
7246           goto unknown;
7247
7248         case 'r':
7249           switch (name[1])
7250           {
7251             case 'e':
7252               switch (name[2])
7253               {
7254                 case 'n':
7255                   if (name[3] == 'a' &&
7256                       name[4] == 'm' &&
7257                       name[5] == 'e')
7258                   {                               /* rename     */
7259                     return -KEY_rename;
7260                   }
7261
7262                   goto unknown;
7263
7264                 case 't':
7265                   if (name[3] == 'u' &&
7266                       name[4] == 'r' &&
7267                       name[5] == 'n')
7268                   {                               /* return     */
7269                     return KEY_return;
7270                   }
7271
7272                   goto unknown;
7273
7274                 default:
7275                   goto unknown;
7276               }
7277
7278             case 'i':
7279               if (name[2] == 'n' &&
7280                   name[3] == 'd' &&
7281                   name[4] == 'e' &&
7282                   name[5] == 'x')
7283               {                                   /* rindex     */
7284                 return -KEY_rindex;
7285               }
7286
7287               goto unknown;
7288
7289             default:
7290               goto unknown;
7291           }
7292
7293         case 's':
7294           switch (name[1])
7295           {
7296             case 'c':
7297               if (name[2] == 'a' &&
7298                   name[3] == 'l' &&
7299                   name[4] == 'a' &&
7300                   name[5] == 'r')
7301               {                                   /* scalar     */
7302                 return KEY_scalar;
7303               }
7304
7305               goto unknown;
7306
7307             case 'e':
7308               switch (name[2])
7309               {
7310                 case 'l':
7311                   if (name[3] == 'e' &&
7312                       name[4] == 'c' &&
7313                       name[5] == 't')
7314                   {                               /* select     */
7315                     return -KEY_select;
7316                   }
7317
7318                   goto unknown;
7319
7320                 case 'm':
7321                   switch (name[3])
7322                   {
7323                     case 'c':
7324                       if (name[4] == 't' &&
7325                           name[5] == 'l')
7326                       {                           /* semctl     */
7327                         return -KEY_semctl;
7328                       }
7329
7330                       goto unknown;
7331
7332                     case 'g':
7333                       if (name[4] == 'e' &&
7334                           name[5] == 't')
7335                       {                           /* semget     */
7336                         return -KEY_semget;
7337                       }
7338
7339                       goto unknown;
7340
7341                     default:
7342                       goto unknown;
7343                   }
7344
7345                 default:
7346                   goto unknown;
7347               }
7348
7349             case 'h':
7350               if (name[2] == 'm')
7351               {
7352                 switch (name[3])
7353                 {
7354                   case 'c':
7355                     if (name[4] == 't' &&
7356                         name[5] == 'l')
7357                     {                             /* shmctl     */
7358                       return -KEY_shmctl;
7359                     }
7360
7361                     goto unknown;
7362
7363                   case 'g':
7364                     if (name[4] == 'e' &&
7365                         name[5] == 't')
7366                     {                             /* shmget     */
7367                       return -KEY_shmget;
7368                     }
7369
7370                     goto unknown;
7371
7372                   default:
7373                     goto unknown;
7374                 }
7375               }
7376
7377               goto unknown;
7378
7379             case 'o':
7380               if (name[2] == 'c' &&
7381                   name[3] == 'k' &&
7382                   name[4] == 'e' &&
7383                   name[5] == 't')
7384               {                                   /* socket     */
7385                 return -KEY_socket;
7386               }
7387
7388               goto unknown;
7389
7390             case 'p':
7391               if (name[2] == 'l' &&
7392                   name[3] == 'i' &&
7393                   name[4] == 'c' &&
7394                   name[5] == 'e')
7395               {                                   /* splice     */
7396                 return -KEY_splice;
7397               }
7398
7399               goto unknown;
7400
7401             case 'u':
7402               if (name[2] == 'b' &&
7403                   name[3] == 's' &&
7404                   name[4] == 't' &&
7405                   name[5] == 'r')
7406               {                                   /* substr     */
7407                 return -KEY_substr;
7408               }
7409
7410               goto unknown;
7411
7412             case 'y':
7413               if (name[2] == 's' &&
7414                   name[3] == 't' &&
7415                   name[4] == 'e' &&
7416                   name[5] == 'm')
7417               {                                   /* system     */
7418                 return -KEY_system;
7419               }
7420
7421               goto unknown;
7422
7423             default:
7424               goto unknown;
7425           }
7426
7427         case 'u':
7428           if (name[1] == 'n')
7429           {
7430             switch (name[2])
7431             {
7432               case 'l':
7433                 switch (name[3])
7434                 {
7435                   case 'e':
7436                     if (name[4] == 's' &&
7437                         name[5] == 's')
7438                     {                             /* unless     */
7439                       return KEY_unless;
7440                     }
7441
7442                     goto unknown;
7443
7444                   case 'i':
7445                     if (name[4] == 'n' &&
7446                         name[5] == 'k')
7447                     {                             /* unlink     */
7448                       return -KEY_unlink;
7449                     }
7450
7451                     goto unknown;
7452
7453                   default:
7454                     goto unknown;
7455                 }
7456
7457               case 'p':
7458                 if (name[3] == 'a' &&
7459                     name[4] == 'c' &&
7460                     name[5] == 'k')
7461                 {                                 /* unpack     */
7462                   return -KEY_unpack;
7463                 }
7464
7465                 goto unknown;
7466
7467               default:
7468                 goto unknown;
7469             }
7470           }
7471
7472           goto unknown;
7473
7474         case 'v':
7475           if (name[1] == 'a' &&
7476               name[2] == 'l' &&
7477               name[3] == 'u' &&
7478               name[4] == 'e' &&
7479               name[5] == 's')
7480           {                                       /* values     */
7481             return -KEY_values;
7482           }
7483
7484           goto unknown;
7485
7486         default:
7487           goto unknown;
7488       }
7489
7490     case 7: /* 28 tokens of length 7 */
7491       switch (name[0])
7492       {
7493         case 'D':
7494           if (name[1] == 'E' &&
7495               name[2] == 'S' &&
7496               name[3] == 'T' &&
7497               name[4] == 'R' &&
7498               name[5] == 'O' &&
7499               name[6] == 'Y')
7500           {                                       /* DESTROY    */
7501             return KEY_DESTROY;
7502           }
7503
7504           goto unknown;
7505
7506         case '_':
7507           if (name[1] == '_' &&
7508               name[2] == 'E' &&
7509               name[3] == 'N' &&
7510               name[4] == 'D' &&
7511               name[5] == '_' &&
7512               name[6] == '_')
7513           {                                       /* __END__    */
7514             return KEY___END__;
7515           }
7516
7517           goto unknown;
7518
7519         case 'b':
7520           if (name[1] == 'i' &&
7521               name[2] == 'n' &&
7522               name[3] == 'm' &&
7523               name[4] == 'o' &&
7524               name[5] == 'd' &&
7525               name[6] == 'e')
7526           {                                       /* binmode    */
7527             return -KEY_binmode;
7528           }
7529
7530           goto unknown;
7531
7532         case 'c':
7533           if (name[1] == 'o' &&
7534               name[2] == 'n' &&
7535               name[3] == 'n' &&
7536               name[4] == 'e' &&
7537               name[5] == 'c' &&
7538               name[6] == 't')
7539           {                                       /* connect    */
7540             return -KEY_connect;
7541           }
7542
7543           goto unknown;
7544
7545         case 'd':
7546           switch (name[1])
7547           {
7548             case 'b':
7549               if (name[2] == 'm' &&
7550                   name[3] == 'o' &&
7551                   name[4] == 'p' &&
7552                   name[5] == 'e' &&
7553                   name[6] == 'n')
7554               {                                   /* dbmopen    */
7555                 return -KEY_dbmopen;
7556               }
7557
7558               goto unknown;
7559
7560             case 'e':
7561               if (name[2] == 'f' &&
7562                   name[3] == 'i' &&
7563                   name[4] == 'n' &&
7564                   name[5] == 'e' &&
7565                   name[6] == 'd')
7566               {                                   /* defined    */
7567                 return KEY_defined;
7568               }
7569
7570               goto unknown;
7571
7572             default:
7573               goto unknown;
7574           }
7575
7576         case 'f':
7577           if (name[1] == 'o' &&
7578               name[2] == 'r' &&
7579               name[3] == 'e' &&
7580               name[4] == 'a' &&
7581               name[5] == 'c' &&
7582               name[6] == 'h')
7583           {                                       /* foreach    */
7584             return KEY_foreach;
7585           }
7586
7587           goto unknown;
7588
7589         case 'g':
7590           if (name[1] == 'e' &&
7591               name[2] == 't' &&
7592               name[3] == 'p')
7593           {
7594             switch (name[4])
7595             {
7596               case 'g':
7597                 if (name[5] == 'r' &&
7598                     name[6] == 'p')
7599                 {                                 /* getpgrp    */
7600                   return -KEY_getpgrp;
7601                 }
7602
7603                 goto unknown;
7604
7605               case 'p':
7606                 if (name[5] == 'i' &&
7607                     name[6] == 'd')
7608                 {                                 /* getppid    */
7609                   return -KEY_getppid;
7610                 }
7611
7612                 goto unknown;
7613
7614               default:
7615                 goto unknown;
7616             }
7617           }
7618
7619           goto unknown;
7620
7621         case 'l':
7622           if (name[1] == 'c' &&
7623               name[2] == 'f' &&
7624               name[3] == 'i' &&
7625               name[4] == 'r' &&
7626               name[5] == 's' &&
7627               name[6] == 't')
7628           {                                       /* lcfirst    */
7629             return -KEY_lcfirst;
7630           }
7631
7632           goto unknown;
7633
7634         case 'o':
7635           if (name[1] == 'p' &&
7636               name[2] == 'e' &&
7637               name[3] == 'n' &&
7638               name[4] == 'd' &&
7639               name[5] == 'i' &&
7640               name[6] == 'r')
7641           {                                       /* opendir    */
7642             return -KEY_opendir;
7643           }
7644
7645           goto unknown;
7646
7647         case 'p':
7648           if (name[1] == 'a' &&
7649               name[2] == 'c' &&
7650               name[3] == 'k' &&
7651               name[4] == 'a' &&
7652               name[5] == 'g' &&
7653               name[6] == 'e')
7654           {                                       /* package    */
7655             return KEY_package;
7656           }
7657
7658           goto unknown;
7659
7660         case 'r':
7661           if (name[1] == 'e')
7662           {
7663             switch (name[2])
7664             {
7665               case 'a':
7666                 if (name[3] == 'd' &&
7667                     name[4] == 'd' &&
7668                     name[5] == 'i' &&
7669                     name[6] == 'r')
7670                 {                                 /* readdir    */
7671                   return -KEY_readdir;
7672                 }
7673
7674                 goto unknown;
7675
7676               case 'q':
7677                 if (name[3] == 'u' &&
7678                     name[4] == 'i' &&
7679                     name[5] == 'r' &&
7680                     name[6] == 'e')
7681                 {                                 /* require    */
7682                   return KEY_require;
7683                 }
7684
7685                 goto unknown;
7686
7687               case 'v':
7688                 if (name[3] == 'e' &&
7689                     name[4] == 'r' &&
7690                     name[5] == 's' &&
7691                     name[6] == 'e')
7692                 {                                 /* reverse    */
7693                   return -KEY_reverse;
7694                 }
7695
7696                 goto unknown;
7697
7698               default:
7699                 goto unknown;
7700             }
7701           }
7702
7703           goto unknown;
7704
7705         case 's':
7706           switch (name[1])
7707           {
7708             case 'e':
7709               switch (name[2])
7710               {
7711                 case 'e':
7712                   if (name[3] == 'k' &&
7713                       name[4] == 'd' &&
7714                       name[5] == 'i' &&
7715                       name[6] == 'r')
7716                   {                               /* seekdir    */
7717                     return -KEY_seekdir;
7718                   }
7719
7720                   goto unknown;
7721
7722                 case 't':
7723                   if (name[3] == 'p' &&
7724                       name[4] == 'g' &&
7725                       name[5] == 'r' &&
7726                       name[6] == 'p')
7727                   {                               /* setpgrp    */
7728                     return -KEY_setpgrp;
7729                   }
7730
7731                   goto unknown;
7732
7733                 default:
7734                   goto unknown;
7735               }
7736
7737             case 'h':
7738               if (name[2] == 'm' &&
7739                   name[3] == 'r' &&
7740                   name[4] == 'e' &&
7741                   name[5] == 'a' &&
7742                   name[6] == 'd')
7743               {                                   /* shmread    */
7744                 return -KEY_shmread;
7745               }
7746
7747               goto unknown;
7748
7749             case 'p':
7750               if (name[2] == 'r' &&
7751                   name[3] == 'i' &&
7752                   name[4] == 'n' &&
7753                   name[5] == 't' &&
7754                   name[6] == 'f')
7755               {                                   /* sprintf    */
7756                 return -KEY_sprintf;
7757               }
7758
7759               goto unknown;
7760
7761             case 'y':
7762               switch (name[2])
7763               {
7764                 case 'm':
7765                   if (name[3] == 'l' &&
7766                       name[4] == 'i' &&
7767                       name[5] == 'n' &&
7768                       name[6] == 'k')
7769                   {                               /* symlink    */
7770                     return -KEY_symlink;
7771                   }
7772
7773                   goto unknown;
7774
7775                 case 's':
7776                   switch (name[3])
7777                   {
7778                     case 'c':
7779                       if (name[4] == 'a' &&
7780                           name[5] == 'l' &&
7781                           name[6] == 'l')
7782                       {                           /* syscall    */
7783                         return -KEY_syscall;
7784                       }
7785
7786                       goto unknown;
7787
7788                     case 'o':
7789                       if (name[4] == 'p' &&
7790                           name[5] == 'e' &&
7791                           name[6] == 'n')
7792                       {                           /* sysopen    */
7793                         return -KEY_sysopen;
7794                       }
7795
7796                       goto unknown;
7797
7798                     case 'r':
7799                       if (name[4] == 'e' &&
7800                           name[5] == 'a' &&
7801                           name[6] == 'd')
7802                       {                           /* sysread    */
7803                         return -KEY_sysread;
7804                       }
7805
7806                       goto unknown;
7807
7808                     case 's':
7809                       if (name[4] == 'e' &&
7810                           name[5] == 'e' &&
7811                           name[6] == 'k')
7812                       {                           /* sysseek    */
7813                         return -KEY_sysseek;
7814                       }
7815
7816                       goto unknown;
7817
7818                     default:
7819                       goto unknown;
7820                   }
7821
7822                 default:
7823                   goto unknown;
7824               }
7825
7826             default:
7827               goto unknown;
7828           }
7829
7830         case 't':
7831           if (name[1] == 'e' &&
7832               name[2] == 'l' &&
7833               name[3] == 'l' &&
7834               name[4] == 'd' &&
7835               name[5] == 'i' &&
7836               name[6] == 'r')
7837           {                                       /* telldir    */
7838             return -KEY_telldir;
7839           }
7840
7841           goto unknown;
7842
7843         case 'u':
7844           switch (name[1])
7845           {
7846             case 'c':
7847               if (name[2] == 'f' &&
7848                   name[3] == 'i' &&
7849                   name[4] == 'r' &&
7850                   name[5] == 's' &&
7851                   name[6] == 't')
7852               {                                   /* ucfirst    */
7853                 return -KEY_ucfirst;
7854               }
7855
7856               goto unknown;
7857
7858             case 'n':
7859               if (name[2] == 's' &&
7860                   name[3] == 'h' &&
7861                   name[4] == 'i' &&
7862                   name[5] == 'f' &&
7863                   name[6] == 't')
7864               {                                   /* unshift    */
7865                 return -KEY_unshift;
7866               }
7867
7868               goto unknown;
7869
7870             default:
7871               goto unknown;
7872           }
7873
7874         case 'w':
7875           if (name[1] == 'a' &&
7876               name[2] == 'i' &&
7877               name[3] == 't' &&
7878               name[4] == 'p' &&
7879               name[5] == 'i' &&
7880               name[6] == 'd')
7881           {                                       /* waitpid    */
7882             return -KEY_waitpid;
7883           }
7884
7885           goto unknown;
7886
7887         default:
7888           goto unknown;
7889       }
7890
7891     case 8: /* 26 tokens of length 8 */
7892       switch (name[0])
7893       {
7894         case 'A':
7895           if (name[1] == 'U' &&
7896               name[2] == 'T' &&
7897               name[3] == 'O' &&
7898               name[4] == 'L' &&
7899               name[5] == 'O' &&
7900               name[6] == 'A' &&
7901               name[7] == 'D')
7902           {                                       /* AUTOLOAD   */
7903             return KEY_AUTOLOAD;
7904           }
7905
7906           goto unknown;
7907
7908         case '_':
7909           if (name[1] == '_')
7910           {
7911             switch (name[2])
7912             {
7913               case 'D':
7914                 if (name[3] == 'A' &&
7915                     name[4] == 'T' &&
7916                     name[5] == 'A' &&
7917                     name[6] == '_' &&
7918                     name[7] == '_')
7919                 {                                 /* __DATA__   */
7920                   return KEY___DATA__;
7921                 }
7922
7923                 goto unknown;
7924
7925               case 'F':
7926                 if (name[3] == 'I' &&
7927                     name[4] == 'L' &&
7928                     name[5] == 'E' &&
7929                     name[6] == '_' &&
7930                     name[7] == '_')
7931                 {                                 /* __FILE__   */
7932                   return -KEY___FILE__;
7933                 }
7934
7935                 goto unknown;
7936
7937               case 'L':
7938                 if (name[3] == 'I' &&
7939                     name[4] == 'N' &&
7940                     name[5] == 'E' &&
7941                     name[6] == '_' &&
7942                     name[7] == '_')
7943                 {                                 /* __LINE__   */
7944                   return -KEY___LINE__;
7945                 }
7946
7947                 goto unknown;
7948
7949               default:
7950                 goto unknown;
7951             }
7952           }
7953
7954           goto unknown;
7955
7956         case 'c':
7957           switch (name[1])
7958           {
7959             case 'l':
7960               if (name[2] == 'o' &&
7961                   name[3] == 's' &&
7962                   name[4] == 'e' &&
7963                   name[5] == 'd' &&
7964                   name[6] == 'i' &&
7965                   name[7] == 'r')
7966               {                                   /* closedir   */
7967                 return -KEY_closedir;
7968               }
7969
7970               goto unknown;
7971
7972             case 'o':
7973               if (name[2] == 'n' &&
7974                   name[3] == 't' &&
7975                   name[4] == 'i' &&
7976                   name[5] == 'n' &&
7977                   name[6] == 'u' &&
7978                   name[7] == 'e')
7979               {                                   /* continue   */
7980                 return -KEY_continue;
7981               }
7982
7983               goto unknown;
7984
7985             default:
7986               goto unknown;
7987           }
7988
7989         case 'd':
7990           if (name[1] == 'b' &&
7991               name[2] == 'm' &&
7992               name[3] == 'c' &&
7993               name[4] == 'l' &&
7994               name[5] == 'o' &&
7995               name[6] == 's' &&
7996               name[7] == 'e')
7997           {                                       /* dbmclose   */
7998             return -KEY_dbmclose;
7999           }
8000
8001           goto unknown;
8002
8003         case 'e':
8004           if (name[1] == 'n' &&
8005               name[2] == 'd')
8006           {
8007             switch (name[3])
8008             {
8009               case 'g':
8010                 if (name[4] == 'r' &&
8011                     name[5] == 'e' &&
8012                     name[6] == 'n' &&
8013                     name[7] == 't')
8014                 {                                 /* endgrent   */
8015                   return -KEY_endgrent;
8016                 }
8017
8018                 goto unknown;
8019
8020               case 'p':
8021                 if (name[4] == 'w' &&
8022                     name[5] == 'e' &&
8023                     name[6] == 'n' &&
8024                     name[7] == 't')
8025                 {                                 /* endpwent   */
8026                   return -KEY_endpwent;
8027                 }
8028
8029                 goto unknown;
8030
8031               default:
8032                 goto unknown;
8033             }
8034           }
8035
8036           goto unknown;
8037
8038         case 'f':
8039           if (name[1] == 'o' &&
8040               name[2] == 'r' &&
8041               name[3] == 'm' &&
8042               name[4] == 'l' &&
8043               name[5] == 'i' &&
8044               name[6] == 'n' &&
8045               name[7] == 'e')
8046           {                                       /* formline   */
8047             return -KEY_formline;
8048           }
8049
8050           goto unknown;
8051
8052         case 'g':
8053           if (name[1] == 'e' &&
8054               name[2] == 't')
8055           {
8056             switch (name[3])
8057             {
8058               case 'g':
8059                 if (name[4] == 'r')
8060                 {
8061                   switch (name[5])
8062                   {
8063                     case 'e':
8064                       if (name[6] == 'n' &&
8065                           name[7] == 't')
8066                       {                           /* getgrent   */
8067                         return -KEY_getgrent;
8068                       }
8069
8070                       goto unknown;
8071
8072                     case 'g':
8073                       if (name[6] == 'i' &&
8074                           name[7] == 'd')
8075                       {                           /* getgrgid   */
8076                         return -KEY_getgrgid;
8077                       }
8078
8079                       goto unknown;
8080
8081                     case 'n':
8082                       if (name[6] == 'a' &&
8083                           name[7] == 'm')
8084                       {                           /* getgrnam   */
8085                         return -KEY_getgrnam;
8086                       }
8087
8088                       goto unknown;
8089
8090                     default:
8091                       goto unknown;
8092                   }
8093                 }
8094
8095                 goto unknown;
8096
8097               case 'l':
8098                 if (name[4] == 'o' &&
8099                     name[5] == 'g' &&
8100                     name[6] == 'i' &&
8101                     name[7] == 'n')
8102                 {                                 /* getlogin   */
8103                   return -KEY_getlogin;
8104                 }
8105
8106                 goto unknown;
8107
8108               case 'p':
8109                 if (name[4] == 'w')
8110                 {
8111                   switch (name[5])
8112                   {
8113                     case 'e':
8114                       if (name[6] == 'n' &&
8115                           name[7] == 't')
8116                       {                           /* getpwent   */
8117                         return -KEY_getpwent;
8118                       }
8119
8120                       goto unknown;
8121
8122                     case 'n':
8123                       if (name[6] == 'a' &&
8124                           name[7] == 'm')
8125                       {                           /* getpwnam   */
8126                         return -KEY_getpwnam;
8127                       }
8128
8129                       goto unknown;
8130
8131                     case 'u':
8132                       if (name[6] == 'i' &&
8133                           name[7] == 'd')
8134                       {                           /* getpwuid   */
8135                         return -KEY_getpwuid;
8136                       }
8137
8138                       goto unknown;
8139
8140                     default:
8141                       goto unknown;
8142                   }
8143                 }
8144
8145                 goto unknown;
8146
8147               default:
8148                 goto unknown;
8149             }
8150           }
8151
8152           goto unknown;
8153
8154         case 'r':
8155           if (name[1] == 'e' &&
8156               name[2] == 'a' &&
8157               name[3] == 'd')
8158           {
8159             switch (name[4])
8160             {
8161               case 'l':
8162                 if (name[5] == 'i' &&
8163                     name[6] == 'n')
8164                 {
8165                   switch (name[7])
8166                   {
8167                     case 'e':
8168                       {                           /* readline   */
8169                         return -KEY_readline;
8170                       }
8171
8172                     case 'k':
8173                       {                           /* readlink   */
8174                         return -KEY_readlink;
8175                       }
8176
8177                     default:
8178                       goto unknown;
8179                   }
8180                 }
8181
8182                 goto unknown;
8183
8184               case 'p':
8185                 if (name[5] == 'i' &&
8186                     name[6] == 'p' &&
8187                     name[7] == 'e')
8188                 {                                 /* readpipe   */
8189                   return -KEY_readpipe;
8190                 }
8191
8192                 goto unknown;
8193
8194               default:
8195                 goto unknown;
8196             }
8197           }
8198
8199           goto unknown;
8200
8201         case 's':
8202           switch (name[1])
8203           {
8204             case 'e':
8205               if (name[2] == 't')
8206               {
8207                 switch (name[3])
8208                 {
8209                   case 'g':
8210                     if (name[4] == 'r' &&
8211                         name[5] == 'e' &&
8212                         name[6] == 'n' &&
8213                         name[7] == 't')
8214                     {                             /* setgrent   */
8215                       return -KEY_setgrent;
8216                     }
8217
8218                     goto unknown;
8219
8220                   case 'p':
8221                     if (name[4] == 'w' &&
8222                         name[5] == 'e' &&
8223                         name[6] == 'n' &&
8224                         name[7] == 't')
8225                     {                             /* setpwent   */
8226                       return -KEY_setpwent;
8227                     }
8228
8229                     goto unknown;
8230
8231                   default:
8232                     goto unknown;
8233                 }
8234               }
8235
8236               goto unknown;
8237
8238             case 'h':
8239               switch (name[2])
8240               {
8241                 case 'm':
8242                   if (name[3] == 'w' &&
8243                       name[4] == 'r' &&
8244                       name[5] == 'i' &&
8245                       name[6] == 't' &&
8246                       name[7] == 'e')
8247                   {                               /* shmwrite   */
8248                     return -KEY_shmwrite;
8249                   }
8250
8251                   goto unknown;
8252
8253                 case 'u':
8254                   if (name[3] == 't' &&
8255                       name[4] == 'd' &&
8256                       name[5] == 'o' &&
8257                       name[6] == 'w' &&
8258                       name[7] == 'n')
8259                   {                               /* shutdown   */
8260                     return -KEY_shutdown;
8261                   }
8262
8263                   goto unknown;
8264
8265                 default:
8266                   goto unknown;
8267               }
8268
8269             case 'y':
8270               if (name[2] == 's' &&
8271                   name[3] == 'w' &&
8272                   name[4] == 'r' &&
8273                   name[5] == 'i' &&
8274                   name[6] == 't' &&
8275                   name[7] == 'e')
8276               {                                   /* syswrite   */
8277                 return -KEY_syswrite;
8278               }
8279
8280               goto unknown;
8281
8282             default:
8283               goto unknown;
8284           }
8285
8286         case 't':
8287           if (name[1] == 'r' &&
8288               name[2] == 'u' &&
8289               name[3] == 'n' &&
8290               name[4] == 'c' &&
8291               name[5] == 'a' &&
8292               name[6] == 't' &&
8293               name[7] == 'e')
8294           {                                       /* truncate   */
8295             return -KEY_truncate;
8296           }
8297
8298           goto unknown;
8299
8300         default:
8301           goto unknown;
8302       }
8303
8304     case 9: /* 8 tokens of length 9 */
8305       switch (name[0])
8306       {
8307         case 'e':
8308           if (name[1] == 'n' &&
8309               name[2] == 'd' &&
8310               name[3] == 'n' &&
8311               name[4] == 'e' &&
8312               name[5] == 't' &&
8313               name[6] == 'e' &&
8314               name[7] == 'n' &&
8315               name[8] == 't')
8316           {                                       /* endnetent  */
8317             return -KEY_endnetent;
8318           }
8319
8320           goto unknown;
8321
8322         case 'g':
8323           if (name[1] == 'e' &&
8324               name[2] == 't' &&
8325               name[3] == 'n' &&
8326               name[4] == 'e' &&
8327               name[5] == 't' &&
8328               name[6] == 'e' &&
8329               name[7] == 'n' &&
8330               name[8] == 't')
8331           {                                       /* getnetent  */
8332             return -KEY_getnetent;
8333           }
8334
8335           goto unknown;
8336
8337         case 'l':
8338           if (name[1] == 'o' &&
8339               name[2] == 'c' &&
8340               name[3] == 'a' &&
8341               name[4] == 'l' &&
8342               name[5] == 't' &&
8343               name[6] == 'i' &&
8344               name[7] == 'm' &&
8345               name[8] == 'e')
8346           {                                       /* localtime  */
8347             return -KEY_localtime;
8348           }
8349
8350           goto unknown;
8351
8352         case 'p':
8353           if (name[1] == 'r' &&
8354               name[2] == 'o' &&
8355               name[3] == 't' &&
8356               name[4] == 'o' &&
8357               name[5] == 't' &&
8358               name[6] == 'y' &&
8359               name[7] == 'p' &&
8360               name[8] == 'e')
8361           {                                       /* prototype  */
8362             return KEY_prototype;
8363           }
8364
8365           goto unknown;
8366
8367         case 'q':
8368           if (name[1] == 'u' &&
8369               name[2] == 'o' &&
8370               name[3] == 't' &&
8371               name[4] == 'e' &&
8372               name[5] == 'm' &&
8373               name[6] == 'e' &&
8374               name[7] == 't' &&
8375               name[8] == 'a')
8376           {                                       /* quotemeta  */
8377             return -KEY_quotemeta;
8378           }
8379
8380           goto unknown;
8381
8382         case 'r':
8383           if (name[1] == 'e' &&
8384               name[2] == 'w' &&
8385               name[3] == 'i' &&
8386               name[4] == 'n' &&
8387               name[5] == 'd' &&
8388               name[6] == 'd' &&
8389               name[7] == 'i' &&
8390               name[8] == 'r')
8391           {                                       /* rewinddir  */
8392             return -KEY_rewinddir;
8393           }
8394
8395           goto unknown;
8396
8397         case 's':
8398           if (name[1] == 'e' &&
8399               name[2] == 't' &&
8400               name[3] == 'n' &&
8401               name[4] == 'e' &&
8402               name[5] == 't' &&
8403               name[6] == 'e' &&
8404               name[7] == 'n' &&
8405               name[8] == 't')
8406           {                                       /* setnetent  */
8407             return -KEY_setnetent;
8408           }
8409
8410           goto unknown;
8411
8412         case 'w':
8413           if (name[1] == 'a' &&
8414               name[2] == 'n' &&
8415               name[3] == 't' &&
8416               name[4] == 'a' &&
8417               name[5] == 'r' &&
8418               name[6] == 'r' &&
8419               name[7] == 'a' &&
8420               name[8] == 'y')
8421           {                                       /* wantarray  */
8422             return -KEY_wantarray;
8423           }
8424
8425           goto unknown;
8426
8427         default:
8428           goto unknown;
8429       }
8430
8431     case 10: /* 9 tokens of length 10 */
8432       switch (name[0])
8433       {
8434         case 'e':
8435           if (name[1] == 'n' &&
8436               name[2] == 'd')
8437           {
8438             switch (name[3])
8439             {
8440               case 'h':
8441                 if (name[4] == 'o' &&
8442                     name[5] == 's' &&
8443                     name[6] == 't' &&
8444                     name[7] == 'e' &&
8445                     name[8] == 'n' &&
8446                     name[9] == 't')
8447                 {                                 /* endhostent */
8448                   return -KEY_endhostent;
8449                 }
8450
8451                 goto unknown;
8452
8453               case 's':
8454                 if (name[4] == 'e' &&
8455                     name[5] == 'r' &&
8456                     name[6] == 'v' &&
8457                     name[7] == 'e' &&
8458                     name[8] == 'n' &&
8459                     name[9] == 't')
8460                 {                                 /* endservent */
8461                   return -KEY_endservent;
8462                 }
8463
8464                 goto unknown;
8465
8466               default:
8467                 goto unknown;
8468             }
8469           }
8470
8471           goto unknown;
8472
8473         case 'g':
8474           if (name[1] == 'e' &&
8475               name[2] == 't')
8476           {
8477             switch (name[3])
8478             {
8479               case 'h':
8480                 if (name[4] == 'o' &&
8481                     name[5] == 's' &&
8482                     name[6] == 't' &&
8483                     name[7] == 'e' &&
8484                     name[8] == 'n' &&
8485                     name[9] == 't')
8486                 {                                 /* gethostent */
8487                   return -KEY_gethostent;
8488                 }
8489
8490                 goto unknown;
8491
8492               case 's':
8493                 switch (name[4])
8494                 {
8495                   case 'e':
8496                     if (name[5] == 'r' &&
8497                         name[6] == 'v' &&
8498                         name[7] == 'e' &&
8499                         name[8] == 'n' &&
8500                         name[9] == 't')
8501                     {                             /* getservent */
8502                       return -KEY_getservent;
8503                     }
8504
8505                     goto unknown;
8506
8507                   case 'o':
8508                     if (name[5] == 'c' &&
8509                         name[6] == 'k' &&
8510                         name[7] == 'o' &&
8511                         name[8] == 'p' &&
8512                         name[9] == 't')
8513                     {                             /* getsockopt */
8514                       return -KEY_getsockopt;
8515                     }
8516
8517                     goto unknown;
8518
8519                   default:
8520                     goto unknown;
8521                 }
8522
8523               default:
8524                 goto unknown;
8525             }
8526           }
8527
8528           goto unknown;
8529
8530         case 's':
8531           switch (name[1])
8532           {
8533             case 'e':
8534               if (name[2] == 't')
8535               {
8536                 switch (name[3])
8537                 {
8538                   case 'h':
8539                     if (name[4] == 'o' &&
8540                         name[5] == 's' &&
8541                         name[6] == 't' &&
8542                         name[7] == 'e' &&
8543                         name[8] == 'n' &&
8544                         name[9] == 't')
8545                     {                             /* sethostent */
8546                       return -KEY_sethostent;
8547                     }
8548
8549                     goto unknown;
8550
8551                   case 's':
8552                     switch (name[4])
8553                     {
8554                       case 'e':
8555                         if (name[5] == 'r' &&
8556                             name[6] == 'v' &&
8557                             name[7] == 'e' &&
8558                             name[8] == 'n' &&
8559                             name[9] == 't')
8560                         {                         /* setservent */
8561                           return -KEY_setservent;
8562                         }
8563
8564                         goto unknown;
8565
8566                       case 'o':
8567                         if (name[5] == 'c' &&
8568                             name[6] == 'k' &&
8569                             name[7] == 'o' &&
8570                             name[8] == 'p' &&
8571                             name[9] == 't')
8572                         {                         /* setsockopt */
8573                           return -KEY_setsockopt;
8574                         }
8575
8576                         goto unknown;
8577
8578                       default:
8579                         goto unknown;
8580                     }
8581
8582                   default:
8583                     goto unknown;
8584                 }
8585               }
8586
8587               goto unknown;
8588
8589             case 'o':
8590               if (name[2] == 'c' &&
8591                   name[3] == 'k' &&
8592                   name[4] == 'e' &&
8593                   name[5] == 't' &&
8594                   name[6] == 'p' &&
8595                   name[7] == 'a' &&
8596                   name[8] == 'i' &&
8597                   name[9] == 'r')
8598               {                                   /* socketpair */
8599                 return -KEY_socketpair;
8600               }
8601
8602               goto unknown;
8603
8604             default:
8605               goto unknown;
8606           }
8607
8608         default:
8609           goto unknown;
8610       }
8611
8612     case 11: /* 8 tokens of length 11 */
8613       switch (name[0])
8614       {
8615         case '_':
8616           if (name[1] == '_' &&
8617               name[2] == 'P' &&
8618               name[3] == 'A' &&
8619               name[4] == 'C' &&
8620               name[5] == 'K' &&
8621               name[6] == 'A' &&
8622               name[7] == 'G' &&
8623               name[8] == 'E' &&
8624               name[9] == '_' &&
8625               name[10] == '_')
8626           {                                       /* __PACKAGE__ */
8627             return -KEY___PACKAGE__;
8628           }
8629
8630           goto unknown;
8631
8632         case 'e':
8633           if (name[1] == 'n' &&
8634               name[2] == 'd' &&
8635               name[3] == 'p' &&
8636               name[4] == 'r' &&
8637               name[5] == 'o' &&
8638               name[6] == 't' &&
8639               name[7] == 'o' &&
8640               name[8] == 'e' &&
8641               name[9] == 'n' &&
8642               name[10] == 't')
8643           {                                       /* endprotoent */
8644             return -KEY_endprotoent;
8645           }
8646
8647           goto unknown;
8648
8649         case 'g':
8650           if (name[1] == 'e' &&
8651               name[2] == 't')
8652           {
8653             switch (name[3])
8654             {
8655               case 'p':
8656                 switch (name[4])
8657                 {
8658                   case 'e':
8659                     if (name[5] == 'e' &&
8660                         name[6] == 'r' &&
8661                         name[7] == 'n' &&
8662                         name[8] == 'a' &&
8663                         name[9] == 'm' &&
8664                         name[10] == 'e')
8665                     {                             /* getpeername */
8666                       return -KEY_getpeername;
8667                     }
8668
8669                     goto unknown;
8670
8671                   case 'r':
8672                     switch (name[5])
8673                     {
8674                       case 'i':
8675                         if (name[6] == 'o' &&
8676                             name[7] == 'r' &&
8677                             name[8] == 'i' &&
8678                             name[9] == 't' &&
8679                             name[10] == 'y')
8680                         {                         /* getpriority */
8681                           return -KEY_getpriority;
8682                         }
8683
8684                         goto unknown;
8685
8686                       case 'o':
8687                         if (name[6] == 't' &&
8688                             name[7] == 'o' &&
8689                             name[8] == 'e' &&
8690                             name[9] == 'n' &&
8691                             name[10] == 't')
8692                         {                         /* getprotoent */
8693                           return -KEY_getprotoent;
8694                         }
8695
8696                         goto unknown;
8697
8698                       default:
8699                         goto unknown;
8700                     }
8701
8702                   default:
8703                     goto unknown;
8704                 }
8705
8706               case 's':
8707                 if (name[4] == 'o' &&
8708                     name[5] == 'c' &&
8709                     name[6] == 'k' &&
8710                     name[7] == 'n' &&
8711                     name[8] == 'a' &&
8712                     name[9] == 'm' &&
8713                     name[10] == 'e')
8714                 {                                 /* getsockname */
8715                   return -KEY_getsockname;
8716                 }
8717
8718                 goto unknown;
8719
8720               default:
8721                 goto unknown;
8722             }
8723           }
8724
8725           goto unknown;
8726
8727         case 's':
8728           if (name[1] == 'e' &&
8729               name[2] == 't' &&
8730               name[3] == 'p' &&
8731               name[4] == 'r')
8732           {
8733             switch (name[5])
8734             {
8735               case 'i':
8736                 if (name[6] == 'o' &&
8737                     name[7] == 'r' &&
8738                     name[8] == 'i' &&
8739                     name[9] == 't' &&
8740                     name[10] == 'y')
8741                 {                                 /* setpriority */
8742                   return -KEY_setpriority;
8743                 }
8744
8745                 goto unknown;
8746
8747               case 'o':
8748                 if (name[6] == 't' &&
8749                     name[7] == 'o' &&
8750                     name[8] == 'e' &&
8751                     name[9] == 'n' &&
8752                     name[10] == 't')
8753                 {                                 /* setprotoent */
8754                   return -KEY_setprotoent;
8755                 }
8756
8757                 goto unknown;
8758
8759               default:
8760                 goto unknown;
8761             }
8762           }
8763
8764           goto unknown;
8765
8766         default:
8767           goto unknown;
8768       }
8769
8770     case 12: /* 2 tokens of length 12 */
8771       if (name[0] == 'g' &&
8772           name[1] == 'e' &&
8773           name[2] == 't' &&
8774           name[3] == 'n' &&
8775           name[4] == 'e' &&
8776           name[5] == 't' &&
8777           name[6] == 'b' &&
8778           name[7] == 'y')
8779       {
8780         switch (name[8])
8781         {
8782           case 'a':
8783             if (name[9] == 'd' &&
8784                 name[10] == 'd' &&
8785                 name[11] == 'r')
8786             {                                     /* getnetbyaddr */
8787               return -KEY_getnetbyaddr;
8788             }
8789
8790             goto unknown;
8791
8792           case 'n':
8793             if (name[9] == 'a' &&
8794                 name[10] == 'm' &&
8795                 name[11] == 'e')
8796             {                                     /* getnetbyname */
8797               return -KEY_getnetbyname;
8798             }
8799
8800             goto unknown;
8801
8802           default:
8803             goto unknown;
8804         }
8805       }
8806
8807       goto unknown;
8808
8809     case 13: /* 4 tokens of length 13 */
8810       if (name[0] == 'g' &&
8811           name[1] == 'e' &&
8812           name[2] == 't')
8813       {
8814         switch (name[3])
8815         {
8816           case 'h':
8817             if (name[4] == 'o' &&
8818                 name[5] == 's' &&
8819                 name[6] == 't' &&
8820                 name[7] == 'b' &&
8821                 name[8] == 'y')
8822             {
8823               switch (name[9])
8824               {
8825                 case 'a':
8826                   if (name[10] == 'd' &&
8827                       name[11] == 'd' &&
8828                       name[12] == 'r')
8829                   {                               /* gethostbyaddr */
8830                     return -KEY_gethostbyaddr;
8831                   }
8832
8833                   goto unknown;
8834
8835                 case 'n':
8836                   if (name[10] == 'a' &&
8837                       name[11] == 'm' &&
8838                       name[12] == 'e')
8839                   {                               /* gethostbyname */
8840                     return -KEY_gethostbyname;
8841                   }
8842
8843                   goto unknown;
8844
8845                 default:
8846                   goto unknown;
8847               }
8848             }
8849
8850             goto unknown;
8851
8852           case 's':
8853             if (name[4] == 'e' &&
8854                 name[5] == 'r' &&
8855                 name[6] == 'v' &&
8856                 name[7] == 'b' &&
8857                 name[8] == 'y')
8858             {
8859               switch (name[9])
8860               {
8861                 case 'n':
8862                   if (name[10] == 'a' &&
8863                       name[11] == 'm' &&
8864                       name[12] == 'e')
8865                   {                               /* getservbyname */
8866                     return -KEY_getservbyname;
8867                   }
8868
8869                   goto unknown;
8870
8871                 case 'p':
8872                   if (name[10] == 'o' &&
8873                       name[11] == 'r' &&
8874                       name[12] == 't')
8875                   {                               /* getservbyport */
8876                     return -KEY_getservbyport;
8877                   }
8878
8879                   goto unknown;
8880
8881                 default:
8882                   goto unknown;
8883               }
8884             }
8885
8886             goto unknown;
8887
8888           default:
8889             goto unknown;
8890         }
8891       }
8892
8893       goto unknown;
8894
8895     case 14: /* 1 tokens of length 14 */
8896       if (name[0] == 'g' &&
8897           name[1] == 'e' &&
8898           name[2] == 't' &&
8899           name[3] == 'p' &&
8900           name[4] == 'r' &&
8901           name[5] == 'o' &&
8902           name[6] == 't' &&
8903           name[7] == 'o' &&
8904           name[8] == 'b' &&
8905           name[9] == 'y' &&
8906           name[10] == 'n' &&
8907           name[11] == 'a' &&
8908           name[12] == 'm' &&
8909           name[13] == 'e')
8910       {                                           /* getprotobyname */
8911         return -KEY_getprotobyname;
8912       }
8913
8914       goto unknown;
8915
8916     case 16: /* 1 tokens of length 16 */
8917       if (name[0] == 'g' &&
8918           name[1] == 'e' &&
8919           name[2] == 't' &&
8920           name[3] == 'p' &&
8921           name[4] == 'r' &&
8922           name[5] == 'o' &&
8923           name[6] == 't' &&
8924           name[7] == 'o' &&
8925           name[8] == 'b' &&
8926           name[9] == 'y' &&
8927           name[10] == 'n' &&
8928           name[11] == 'u' &&
8929           name[12] == 'm' &&
8930           name[13] == 'b' &&
8931           name[14] == 'e' &&
8932           name[15] == 'r')
8933       {                                           /* getprotobynumber */
8934         return -KEY_getprotobynumber;
8935       }
8936
8937       goto unknown;
8938
8939     default:
8940       goto unknown;
8941   }
8942
8943 unknown:
8944   return 0;
8945 }
8946
8947 STATIC void
8948 S_checkcomma(pTHX_ register char *s, const char *name, const char *what)
8949 {
8950     const char *w;
8951
8952     if (*s == ' ' && s[1] == '(') {     /* XXX gotta be a better way */
8953         if (ckWARN(WARN_SYNTAX)) {
8954             int level = 1;
8955             for (w = s+2; *w && level; w++) {
8956                 if (*w == '(')
8957                     ++level;
8958                 else if (*w == ')')
8959                     --level;
8960             }
8961             if (*w)
8962                 for (; *w && isSPACE(*w); w++) ;
8963             if (!*w || !strchr(";|})]oaiuw!=", *w))     /* an advisory hack only... */
8964                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
8965                             "%s (...) interpreted as function",name);
8966         }
8967     }
8968     while (s < PL_bufend && isSPACE(*s))
8969         s++;
8970     if (*s == '(')
8971         s++;
8972     while (s < PL_bufend && isSPACE(*s))
8973         s++;
8974     if (isIDFIRST_lazy_if(s,UTF)) {
8975         w = s++;
8976         while (isALNUM_lazy_if(s,UTF))
8977             s++;
8978         while (s < PL_bufend && isSPACE(*s))
8979             s++;
8980         if (*s == ',') {
8981             int kw;
8982             *s = '\0'; /* XXX If we didn't do this, we could const a lot of toke.c */
8983             kw = keyword(w, s - w) || get_cv(w, FALSE) != 0;
8984             *s = ',';
8985             if (kw)
8986                 return;
8987             Perl_croak(aTHX_ "No comma allowed after %s", what);
8988         }
8989     }
8990 }
8991
8992 /* Either returns sv, or mortalizes sv and returns a new SV*.
8993    Best used as sv=new_constant(..., sv, ...).
8994    If s, pv are NULL, calls subroutine with one argument,
8995    and type is used with error messages only. */
8996
8997 STATIC SV *
8998 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
8999                const char *type)
9000 {
9001     dVAR; dSP;
9002     HV * const table = GvHV(PL_hintgv);          /* ^H */
9003     SV *res;
9004     SV **cvp;
9005     SV *cv, *typesv;
9006     const char *why1 = "", *why2 = "", *why3 = "";
9007
9008     if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
9009         SV *msg;
9010         
9011         why2 = strEQ(key,"charnames")
9012                ? "(possibly a missing \"use charnames ...\")"
9013                : "";
9014         msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
9015                             (type ? type: "undef"), why2);
9016
9017         /* This is convoluted and evil ("goto considered harmful")
9018          * but I do not understand the intricacies of all the different
9019          * failure modes of %^H in here.  The goal here is to make
9020          * the most probable error message user-friendly. --jhi */
9021
9022         goto msgdone;
9023
9024     report:
9025         msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
9026                             (type ? type: "undef"), why1, why2, why3);
9027     msgdone:
9028         yyerror(SvPVX_const(msg));
9029         SvREFCNT_dec(msg);
9030         return sv;
9031     }
9032     cvp = hv_fetch(table, key, strlen(key), FALSE);
9033     if (!cvp || !SvOK(*cvp)) {
9034         why1 = "$^H{";
9035         why2 = key;
9036         why3 = "} is not defined";
9037         goto report;
9038     }
9039     sv_2mortal(sv);                     /* Parent created it permanently */
9040     cv = *cvp;
9041     if (!pv && s)
9042         pv = sv_2mortal(newSVpvn(s, len));
9043     if (type && pv)
9044         typesv = sv_2mortal(newSVpv(type, 0));
9045     else
9046         typesv = &PL_sv_undef;
9047
9048     PUSHSTACKi(PERLSI_OVERLOAD);
9049     ENTER ;
9050     SAVETMPS;
9051
9052     PUSHMARK(SP) ;
9053     EXTEND(sp, 3);
9054     if (pv)
9055         PUSHs(pv);
9056     PUSHs(sv);
9057     if (pv)
9058         PUSHs(typesv);
9059     PUTBACK;
9060     call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
9061
9062     SPAGAIN ;
9063
9064     /* Check the eval first */
9065     if (!PL_in_eval && SvTRUE(ERRSV)) {
9066         sv_catpv(ERRSV, "Propagated");
9067         yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
9068         (void)POPs;
9069         res = SvREFCNT_inc(sv);
9070     }
9071     else {
9072         res = POPs;
9073         (void)SvREFCNT_inc(res);
9074     }
9075
9076     PUTBACK ;
9077     FREETMPS ;
9078     LEAVE ;
9079     POPSTACK;
9080
9081     if (!SvOK(res)) {
9082         why1 = "Call to &{$^H{";
9083         why2 = key;
9084         why3 = "}} did not return a defined value";
9085         sv = res;
9086         goto report;
9087     }
9088
9089     return res;
9090 }
9091
9092 /* Returns a NUL terminated string, with the length of the string written to
9093    *slp
9094    */
9095 STATIC char *
9096 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
9097 {
9098     register char *d = dest;
9099     register char * const e = d + destlen - 3;  /* two-character token, ending NUL */
9100     for (;;) {
9101         if (d >= e)
9102             Perl_croak(aTHX_ ident_too_long);
9103         if (isALNUM(*s))        /* UTF handled below */
9104             *d++ = *s++;
9105         else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
9106             *d++ = ':';
9107             *d++ = ':';
9108             s++;
9109         }
9110         else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
9111             *d++ = *s++;
9112             *d++ = *s++;
9113         }
9114         else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9115             char *t = s + UTF8SKIP(s);
9116             while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9117                 t += UTF8SKIP(t);
9118             if (d + (t - s) > e)
9119                 Perl_croak(aTHX_ ident_too_long);
9120             Copy(s, d, t - s, char);
9121             d += t - s;
9122             s = t;
9123         }
9124         else {
9125             *d = '\0';
9126             *slp = d - dest;
9127             return s;
9128         }
9129     }
9130 }
9131
9132 STATIC char *
9133 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
9134 {
9135     register char *d;
9136     register char *e;
9137     char *bracket = Nullch;
9138     char funny = *s++;
9139
9140     if (isSPACE(*s))
9141         s = skipspace(s);
9142     d = dest;
9143     e = d + destlen - 3;        /* two-character token, ending NUL */
9144     if (isDIGIT(*s)) {
9145         while (isDIGIT(*s)) {
9146             if (d >= e)
9147                 Perl_croak(aTHX_ ident_too_long);
9148             *d++ = *s++;
9149         }
9150     }
9151     else {
9152         for (;;) {
9153             if (d >= e)
9154                 Perl_croak(aTHX_ ident_too_long);
9155             if (isALNUM(*s))    /* UTF handled below */
9156                 *d++ = *s++;
9157             else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
9158                 *d++ = ':';
9159                 *d++ = ':';
9160                 s++;
9161             }
9162             else if (*s == ':' && s[1] == ':') {
9163                 *d++ = *s++;
9164                 *d++ = *s++;
9165             }
9166             else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
9167                 char *t = s + UTF8SKIP(s);
9168                 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
9169                     t += UTF8SKIP(t);
9170                 if (d + (t - s) > e)
9171                     Perl_croak(aTHX_ ident_too_long);
9172                 Copy(s, d, t - s, char);
9173                 d += t - s;
9174                 s = t;
9175             }
9176             else
9177                 break;
9178         }
9179     }
9180     *d = '\0';
9181     d = dest;
9182     if (*d) {
9183         if (PL_lex_state != LEX_NORMAL)
9184             PL_lex_state = LEX_INTERPENDMAYBE;
9185         return s;
9186     }
9187     if (*s == '$' && s[1] &&
9188         (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
9189     {
9190         return s;
9191     }
9192     if (*s == '{') {
9193         bracket = s;
9194         s++;
9195     }
9196     else if (ck_uni)
9197         check_uni();
9198     if (s < send)
9199         *d = *s++;
9200     d[1] = '\0';
9201     if (*d == '^' && *s && isCONTROLVAR(*s)) {
9202         *d = toCTRL(*s);
9203         s++;
9204     }
9205     if (bracket) {
9206         if (isSPACE(s[-1])) {
9207             while (s < send) {
9208                 const char ch = *s++;
9209                 if (!SPACE_OR_TAB(ch)) {
9210                     *d = ch;
9211                     break;
9212                 }
9213             }
9214         }
9215         if (isIDFIRST_lazy_if(d,UTF)) {
9216             d++;
9217             if (UTF) {
9218                 e = s;
9219                 while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') {
9220                     e += UTF8SKIP(e);
9221                     while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e))
9222                         e += UTF8SKIP(e);
9223                 }
9224                 Copy(s, d, e - s, char);
9225                 d += e - s;
9226                 s = e;
9227             }
9228             else {
9229                 while ((isALNUM(*s) || *s == ':') && d < e)
9230                     *d++ = *s++;
9231                 if (d >= e)
9232                     Perl_croak(aTHX_ ident_too_long);
9233             }
9234             *d = '\0';
9235             while (s < send && SPACE_OR_TAB(*s)) s++;
9236             if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
9237                 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
9238                     const char *brack = *s == '[' ? "[...]" : "{...}";
9239                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9240                         "Ambiguous use of %c{%s%s} resolved to %c%s%s",
9241                         funny, dest, brack, funny, dest, brack);
9242                 }
9243                 bracket++;
9244                 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
9245                 return s;
9246             }
9247         }
9248         /* Handle extended ${^Foo} variables
9249          * 1999-02-27 mjd-perl-patch@plover.com */
9250         else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
9251                  && isALNUM(*s))
9252         {
9253             d++;
9254             while (isALNUM(*s) && d < e) {
9255                 *d++ = *s++;
9256             }
9257             if (d >= e)
9258                 Perl_croak(aTHX_ ident_too_long);
9259             *d = '\0';
9260         }
9261         if (*s == '}') {
9262             s++;
9263             if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
9264                 PL_lex_state = LEX_INTERPEND;
9265                 PL_expect = XREF;
9266             }
9267             if (funny == '#')
9268                 funny = '@';
9269             if (PL_lex_state == LEX_NORMAL) {
9270                 if (ckWARN(WARN_AMBIGUOUS) &&
9271                     (keyword(dest, d - dest) || get_cv(dest, FALSE)))
9272                 {
9273                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
9274                         "Ambiguous use of %c{%s} resolved to %c%s",
9275                         funny, dest, funny, dest);
9276                 }
9277             }
9278         }
9279         else {
9280             s = bracket;                /* let the parser handle it */
9281             *dest = '\0';
9282         }
9283     }
9284     else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
9285         PL_lex_state = LEX_INTERPEND;
9286     return s;
9287 }
9288
9289 void
9290 Perl_pmflag(pTHX_ U32* pmfl, int ch)
9291 {
9292     if (ch == 'i')
9293         *pmfl |= PMf_FOLD;
9294     else if (ch == 'g')
9295         *pmfl |= PMf_GLOBAL;
9296     else if (ch == 'c')
9297         *pmfl |= PMf_CONTINUE;
9298     else if (ch == 'o')
9299         *pmfl |= PMf_KEEP;
9300     else if (ch == 'm')
9301         *pmfl |= PMf_MULTILINE;
9302     else if (ch == 's')
9303         *pmfl |= PMf_SINGLELINE;
9304     else if (ch == 'x')
9305         *pmfl |= PMf_EXTENDED;
9306 }
9307
9308 STATIC char *
9309 S_scan_pat(pTHX_ char *start, I32 type)
9310 {
9311     PMOP *pm;
9312     char *s = scan_str(start,FALSE,FALSE);
9313
9314     if (!s) {
9315         char * const delimiter = skipspace(start);
9316         Perl_croak(aTHX_ *delimiter == '?'
9317                    ? "Search pattern not terminated or ternary operator parsed as search pattern"
9318                    : "Search pattern not terminated" );
9319     }
9320
9321     pm = (PMOP*)newPMOP(type, 0);
9322     if (PL_multi_open == '?')
9323         pm->op_pmflags |= PMf_ONCE;
9324     if(type == OP_QR) {
9325         while (*s && strchr("iomsx", *s))
9326             pmflag(&pm->op_pmflags,*s++);
9327     }
9328     else {
9329         while (*s && strchr("iogcmsx", *s))
9330             pmflag(&pm->op_pmflags,*s++);
9331     }
9332     /* issue a warning if /c is specified,but /g is not */
9333     if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
9334             && ckWARN(WARN_REGEXP))
9335     {
9336         Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_without_g);
9337     }
9338
9339     pm->op_pmpermflags = pm->op_pmflags;
9340
9341     PL_lex_op = (OP*)pm;
9342     yylval.ival = OP_MATCH;
9343     return s;
9344 }
9345
9346 STATIC char *
9347 S_scan_subst(pTHX_ char *start)
9348 {
9349     dVAR;
9350     register char *s;
9351     register PMOP *pm;
9352     I32 first_start;
9353     I32 es = 0;
9354
9355     yylval.ival = OP_NULL;
9356
9357     s = scan_str(start,FALSE,FALSE);
9358
9359     if (!s)
9360         Perl_croak(aTHX_ "Substitution pattern not terminated");
9361
9362     if (s[-1] == PL_multi_open)
9363         s--;
9364
9365     first_start = PL_multi_start;
9366     s = scan_str(s,FALSE,FALSE);
9367     if (!s) {
9368         if (PL_lex_stuff) {
9369             SvREFCNT_dec(PL_lex_stuff);
9370             PL_lex_stuff = Nullsv;
9371         }
9372         Perl_croak(aTHX_ "Substitution replacement not terminated");
9373     }
9374     PL_multi_start = first_start;       /* so whole substitution is taken together */
9375
9376     pm = (PMOP*)newPMOP(OP_SUBST, 0);
9377     while (*s) {
9378         if (*s == 'e') {
9379             s++;
9380             es++;
9381         }
9382         else if (strchr("iogcmsx", *s))
9383             pmflag(&pm->op_pmflags,*s++);
9384         else
9385             break;
9386     }
9387
9388     /* /c is not meaningful with s/// */
9389     if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP))
9390     {
9391         Perl_warner(aTHX_ packWARN(WARN_REGEXP), c_in_subst);
9392     }
9393
9394     if (es) {
9395         SV *repl;
9396         PL_sublex_info.super_bufptr = s;
9397         PL_sublex_info.super_bufend = PL_bufend;
9398         PL_multi_end = 0;
9399         pm->op_pmflags |= PMf_EVAL;
9400         repl = newSVpvn("",0);
9401         while (es-- > 0)
9402             sv_catpv(repl, es ? "eval " : "do ");
9403         sv_catpvn(repl, "{ ", 2);
9404         sv_catsv(repl, PL_lex_repl);
9405         sv_catpvn(repl, " };", 2);
9406         SvEVALED_on(repl);
9407         SvREFCNT_dec(PL_lex_repl);
9408         PL_lex_repl = repl;
9409     }
9410
9411     pm->op_pmpermflags = pm->op_pmflags;
9412     PL_lex_op = (OP*)pm;
9413     yylval.ival = OP_SUBST;
9414     return s;
9415 }
9416
9417 STATIC char *
9418 S_scan_trans(pTHX_ char *start)
9419 {
9420     register char* s;
9421     OP *o;
9422     short *tbl;
9423     I32 squash;
9424     I32 del;
9425     I32 complement;
9426
9427     yylval.ival = OP_NULL;
9428
9429     s = scan_str(start,FALSE,FALSE);
9430     if (!s)
9431         Perl_croak(aTHX_ "Transliteration pattern not terminated");
9432     if (s[-1] == PL_multi_open)
9433         s--;
9434
9435     s = scan_str(s,FALSE,FALSE);
9436     if (!s) {
9437         if (PL_lex_stuff) {
9438             SvREFCNT_dec(PL_lex_stuff);
9439             PL_lex_stuff = Nullsv;
9440         }
9441         Perl_croak(aTHX_ "Transliteration replacement not terminated");
9442     }
9443
9444     complement = del = squash = 0;
9445     while (1) {
9446         switch (*s) {
9447         case 'c':
9448             complement = OPpTRANS_COMPLEMENT;
9449             break;
9450         case 'd':
9451             del = OPpTRANS_DELETE;
9452             break;
9453         case 's':
9454             squash = OPpTRANS_SQUASH;
9455             break;
9456         default:
9457             goto no_more;
9458         }
9459         s++;
9460     }
9461   no_more:
9462
9463     Newx(tbl, complement&&!del?258:256, short);
9464     o = newPVOP(OP_TRANS, 0, (char*)tbl);
9465     o->op_private &= ~OPpTRANS_ALL;
9466     o->op_private |= del|squash|complement|
9467       (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
9468       (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF   : 0);
9469
9470     PL_lex_op = o;
9471     yylval.ival = OP_TRANS;
9472     return s;
9473 }
9474
9475 STATIC char *
9476 S_scan_heredoc(pTHX_ register char *s)
9477 {
9478     SV *herewas;
9479     I32 op_type = OP_SCALAR;
9480     I32 len;
9481     SV *tmpstr;
9482     char term;
9483     const char newline[] = "\n";
9484     const char *found_newline;
9485     register char *d;
9486     register char *e;
9487     char *peek;
9488     const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
9489
9490     s += 2;
9491     d = PL_tokenbuf;
9492     e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
9493     if (!outer)
9494         *d++ = '\n';
9495     for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
9496     if (*peek == '`' || *peek == '\'' || *peek =='"') {
9497         s = peek;
9498         term = *s++;
9499         s = delimcpy(d, e, s, PL_bufend, term, &len);
9500         d += len;
9501         if (s < PL_bufend)
9502             s++;
9503     }
9504     else {
9505         if (*s == '\\')
9506             s++, term = '\'';
9507         else
9508             term = '"';
9509         if (!isALNUM_lazy_if(s,UTF))
9510             deprecate_old("bare << to mean <<\"\"");
9511         for (; isALNUM_lazy_if(s,UTF); s++) {
9512             if (d < e)
9513                 *d++ = *s;
9514         }
9515     }
9516     if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
9517         Perl_croak(aTHX_ "Delimiter for here document is too long");
9518     *d++ = '\n';
9519     *d = '\0';
9520     len = d - PL_tokenbuf;
9521 #ifndef PERL_STRICT_CR
9522     d = strchr(s, '\r');
9523     if (d) {
9524         char * const olds = s;
9525         s = d;
9526         while (s < PL_bufend) {
9527             if (*s == '\r') {
9528                 *d++ = '\n';
9529                 if (*++s == '\n')
9530                     s++;
9531             }
9532             else if (*s == '\n' && s[1] == '\r') {      /* \015\013 on a mac? */
9533                 *d++ = *s++;
9534                 s++;
9535             }
9536             else
9537                 *d++ = *s++;
9538         }
9539         *d = '\0';
9540         PL_bufend = d;
9541         SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
9542         s = olds;
9543     }
9544 #endif
9545     if ( outer || !(found_newline = ninstr(s,PL_bufend,newline,newline+1)) ) {
9546         herewas = newSVpvn(s,PL_bufend-s);
9547     }
9548     else {
9549         s--;
9550         herewas = newSVpvn(s,found_newline-s);
9551     }
9552     s += SvCUR(herewas);
9553
9554     tmpstr = NEWSV(87,79);
9555     sv_upgrade(tmpstr, SVt_PVIV);
9556     if (term == '\'') {
9557         op_type = OP_CONST;
9558         SvIV_set(tmpstr, -1);
9559     }
9560     else if (term == '`') {
9561         op_type = OP_BACKTICK;
9562         SvIV_set(tmpstr, '\\');
9563     }
9564
9565     CLINE;
9566     PL_multi_start = CopLINE(PL_curcop);
9567     PL_multi_open = PL_multi_close = '<';
9568     term = *PL_tokenbuf;
9569     if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
9570         char *bufptr = PL_sublex_info.super_bufptr;
9571         char *bufend = PL_sublex_info.super_bufend;
9572         char * const olds = s - SvCUR(herewas);
9573         s = strchr(bufptr, '\n');
9574         if (!s)
9575             s = bufend;
9576         d = s;
9577         while (s < bufend &&
9578           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9579             if (*s++ == '\n')
9580                 CopLINE_inc(PL_curcop);
9581         }
9582         if (s >= bufend) {
9583             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9584             missingterm(PL_tokenbuf);
9585         }
9586         sv_setpvn(herewas,bufptr,d-bufptr+1);
9587         sv_setpvn(tmpstr,d+1,s-d);
9588         s += len - 1;
9589         sv_catpvn(herewas,s,bufend-s);
9590         Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
9591
9592         s = olds;
9593         goto retval;
9594     }
9595     else if (!outer) {
9596         d = s;
9597         while (s < PL_bufend &&
9598           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
9599             if (*s++ == '\n')
9600                 CopLINE_inc(PL_curcop);
9601         }
9602         if (s >= PL_bufend) {
9603             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9604             missingterm(PL_tokenbuf);
9605         }
9606         sv_setpvn(tmpstr,d+1,s-d);
9607         s += len - 1;
9608         CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
9609
9610         sv_catpvn(herewas,s,PL_bufend-s);
9611         sv_setsv(PL_linestr,herewas);
9612         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
9613         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9614         PL_last_lop = PL_last_uni = Nullch;
9615     }
9616     else
9617         sv_setpvn(tmpstr,"",0);   /* avoid "uninitialized" warning */
9618     while (s >= PL_bufend) {    /* multiple line string? */
9619         if (!outer ||
9620          !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
9621             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
9622             missingterm(PL_tokenbuf);
9623         }
9624         CopLINE_inc(PL_curcop);
9625         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9626         PL_last_lop = PL_last_uni = Nullch;
9627 #ifndef PERL_STRICT_CR
9628         if (PL_bufend - PL_linestart >= 2) {
9629             if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
9630                 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
9631             {
9632                 PL_bufend[-2] = '\n';
9633                 PL_bufend--;
9634                 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
9635             }
9636             else if (PL_bufend[-1] == '\r')
9637                 PL_bufend[-1] = '\n';
9638         }
9639         else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
9640             PL_bufend[-1] = '\n';
9641 #endif
9642         if (PERLDB_LINE && PL_curstash != PL_debstash) {
9643             SV *sv = NEWSV(88,0);
9644
9645             sv_upgrade(sv, SVt_PVMG);
9646             sv_setsv(sv,PL_linestr);
9647             (void)SvIOK_on(sv);
9648             SvIV_set(sv, 0);
9649             av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
9650         }
9651         if (*s == term && memEQ(s,PL_tokenbuf,len)) {
9652             STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
9653             *(SvPVX(PL_linestr) + off ) = ' ';
9654             sv_catsv(PL_linestr,herewas);
9655             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
9656             s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
9657         }
9658         else {
9659             s = PL_bufend;
9660             sv_catsv(tmpstr,PL_linestr);
9661         }
9662     }
9663     s++;
9664 retval:
9665     PL_multi_end = CopLINE(PL_curcop);
9666     if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
9667         SvPV_shrink_to_cur(tmpstr);
9668     }
9669     SvREFCNT_dec(herewas);
9670     if (!IN_BYTES) {
9671         if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
9672             SvUTF8_on(tmpstr);
9673         else if (PL_encoding)
9674             sv_recode_to_utf8(tmpstr, PL_encoding);
9675     }
9676     PL_lex_stuff = tmpstr;
9677     yylval.ival = op_type;
9678     return s;
9679 }
9680
9681 /* scan_inputsymbol
9682    takes: current position in input buffer
9683    returns: new position in input buffer
9684    side-effects: yylval and lex_op are set.
9685
9686    This code handles:
9687
9688    <>           read from ARGV
9689    <FH>         read from filehandle
9690    <pkg::FH>    read from package qualified filehandle
9691    <pkg'FH>     read from package qualified filehandle
9692    <$fh>        read from filehandle in $fh
9693    <*.h>        filename glob
9694
9695 */
9696
9697 STATIC char *
9698 S_scan_inputsymbol(pTHX_ char *start)
9699 {
9700     register char *s = start;           /* current position in buffer */
9701     register char *d;
9702     const char *e;
9703     char *end;
9704     I32 len;
9705
9706     d = PL_tokenbuf;                    /* start of temp holding space */
9707     e = PL_tokenbuf + sizeof PL_tokenbuf;       /* end of temp holding space */
9708     end = strchr(s, '\n');
9709     if (!end)
9710         end = PL_bufend;
9711     s = delimcpy(d, e, s + 1, end, '>', &len);  /* extract until > */
9712
9713     /* die if we didn't have space for the contents of the <>,
9714        or if it didn't end, or if we see a newline
9715     */
9716
9717     if (len >= sizeof PL_tokenbuf)
9718         Perl_croak(aTHX_ "Excessively long <> operator");
9719     if (s >= end)
9720         Perl_croak(aTHX_ "Unterminated <> operator");
9721
9722     s++;
9723
9724     /* check for <$fh>
9725        Remember, only scalar variables are interpreted as filehandles by
9726        this code.  Anything more complex (e.g., <$fh{$num}>) will be
9727        treated as a glob() call.
9728        This code makes use of the fact that except for the $ at the front,
9729        a scalar variable and a filehandle look the same.
9730     */
9731     if (*d == '$' && d[1]) d++;
9732
9733     /* allow <Pkg'VALUE> or <Pkg::VALUE> */
9734     while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
9735         d++;
9736
9737     /* If we've tried to read what we allow filehandles to look like, and
9738        there's still text left, then it must be a glob() and not a getline.
9739        Use scan_str to pull out the stuff between the <> and treat it
9740        as nothing more than a string.
9741     */
9742
9743     if (d - PL_tokenbuf != len) {
9744         yylval.ival = OP_GLOB;
9745         set_csh();
9746         s = scan_str(start,FALSE,FALSE);
9747         if (!s)
9748            Perl_croak(aTHX_ "Glob not terminated");
9749         return s;
9750     }
9751     else {
9752         bool readline_overriden = FALSE;
9753         GV *gv_readline = Nullgv;
9754         GV **gvp;
9755         /* we're in a filehandle read situation */
9756         d = PL_tokenbuf;
9757
9758         /* turn <> into <ARGV> */
9759         if (!len)
9760             Copy("ARGV",d,5,char);
9761
9762         /* Check whether readline() is overriden */
9763         if (((gv_readline = gv_fetchpv("readline", FALSE, SVt_PVCV))
9764                 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
9765                 ||
9766                 ((gvp = (GV**)hv_fetch(PL_globalstash, "readline", 8, FALSE))
9767                 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
9768                 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
9769             readline_overriden = TRUE;
9770
9771         /* if <$fh>, create the ops to turn the variable into a
9772            filehandle
9773         */
9774         if (*d == '$') {
9775             I32 tmp;
9776
9777             /* try to find it in the pad for this block, otherwise find
9778                add symbol table ops
9779             */
9780             if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
9781                 if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
9782                     HV *stash = PAD_COMPNAME_OURSTASH(tmp);
9783                     HEK *stashname = HvNAME_HEK(stash);
9784                     SV *sym = sv_2mortal(newSVhek(stashname));
9785                     sv_catpvn(sym, "::", 2);
9786                     sv_catpv(sym, d+1);
9787                     d = SvPVX(sym);
9788                     goto intro_sym;
9789                 }
9790                 else {
9791                     OP *o = newOP(OP_PADSV, 0);
9792                     o->op_targ = tmp;
9793                     PL_lex_op = readline_overriden
9794                         ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9795                                 append_elem(OP_LIST, o,
9796                                     newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
9797                         : (OP*)newUNOP(OP_READLINE, 0, o);
9798                 }
9799             }
9800             else {
9801                 GV *gv;
9802                 ++d;
9803 intro_sym:
9804                 gv = gv_fetchpv(d,
9805                                 (PL_in_eval
9806                                  ? (GV_ADDMULTI | GV_ADDINEVAL)
9807                                  : GV_ADDMULTI),
9808                                 SVt_PV);
9809                 PL_lex_op = readline_overriden
9810                     ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9811                             append_elem(OP_LIST,
9812                                 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
9813                                 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9814                     : (OP*)newUNOP(OP_READLINE, 0,
9815                             newUNOP(OP_RV2SV, 0,
9816                                 newGVOP(OP_GV, 0, gv)));
9817             }
9818             if (!readline_overriden)
9819                 PL_lex_op->op_flags |= OPf_SPECIAL;
9820             /* we created the ops in PL_lex_op, so make yylval.ival a null op */
9821             yylval.ival = OP_NULL;
9822         }
9823
9824         /* If it's none of the above, it must be a literal filehandle
9825            (<Foo::BAR> or <FOO>) so build a simple readline OP */
9826         else {
9827             GV *gv = gv_fetchpv(d,TRUE, SVt_PVIO);
9828             PL_lex_op = readline_overriden
9829                 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
9830                         append_elem(OP_LIST,
9831                             newGVOP(OP_GV, 0, gv),
9832                             newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
9833                 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
9834             yylval.ival = OP_NULL;
9835         }
9836     }
9837
9838     return s;
9839 }
9840
9841
9842 /* scan_str
9843    takes: start position in buffer
9844           keep_quoted preserve \ on the embedded delimiter(s)
9845           keep_delims preserve the delimiters around the string
9846    returns: position to continue reading from buffer
9847    side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
9848         updates the read buffer.
9849
9850    This subroutine pulls a string out of the input.  It is called for:
9851         q               single quotes           q(literal text)
9852         '               single quotes           'literal text'
9853         qq              double quotes           qq(interpolate $here please)
9854         "               double quotes           "interpolate $here please"
9855         qx              backticks               qx(/bin/ls -l)
9856         `               backticks               `/bin/ls -l`
9857         qw              quote words             @EXPORT_OK = qw( func() $spam )
9858         m//             regexp match            m/this/
9859         s///            regexp substitute       s/this/that/
9860         tr///           string transliterate    tr/this/that/
9861         y///            string transliterate    y/this/that/
9862         ($*@)           sub prototypes          sub foo ($)
9863         (stuff)         sub attr parameters     sub foo : attr(stuff)
9864         <>              readline or globs       <FOO>, <>, <$fh>, or <*.c>
9865         
9866    In most of these cases (all but <>, patterns and transliterate)
9867    yylex() calls scan_str().  m// makes yylex() call scan_pat() which
9868    calls scan_str().  s/// makes yylex() call scan_subst() which calls
9869    scan_str().  tr/// and y/// make yylex() call scan_trans() which
9870    calls scan_str().
9871
9872    It skips whitespace before the string starts, and treats the first
9873    character as the delimiter.  If the delimiter is one of ([{< then
9874    the corresponding "close" character )]}> is used as the closing
9875    delimiter.  It allows quoting of delimiters, and if the string has
9876    balanced delimiters ([{<>}]) it allows nesting.
9877
9878    On success, the SV with the resulting string is put into lex_stuff or,
9879    if that is already non-NULL, into lex_repl. The second case occurs only
9880    when parsing the RHS of the special constructs s/// and tr/// (y///).
9881    For convenience, the terminating delimiter character is stuffed into
9882    SvIVX of the SV.
9883 */
9884
9885 STATIC char *
9886 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
9887 {
9888     SV *sv;                             /* scalar value: string */
9889     char *tmps;                         /* temp string, used for delimiter matching */
9890     register char *s = start;           /* current position in the buffer */
9891     register char term;                 /* terminating character */
9892     register char *to;                  /* current position in the sv's data */
9893     I32 brackets = 1;                   /* bracket nesting level */
9894     bool has_utf8 = FALSE;              /* is there any utf8 content? */
9895     I32 termcode;                       /* terminating char. code */
9896     U8 termstr[UTF8_MAXBYTES];          /* terminating string */
9897     STRLEN termlen;                     /* length of terminating string */
9898     char *last = NULL;                  /* last position for nesting bracket */
9899
9900     /* skip space before the delimiter */
9901     if (isSPACE(*s))
9902         s = skipspace(s);
9903
9904     /* mark where we are, in case we need to report errors */
9905     CLINE;
9906
9907     /* after skipping whitespace, the next character is the terminator */
9908     term = *s;
9909     if (!UTF) {
9910         termcode = termstr[0] = term;
9911         termlen = 1;
9912     }
9913     else {
9914         termcode = utf8_to_uvchr((U8*)s, &termlen);
9915         Copy(s, termstr, termlen, U8);
9916         if (!UTF8_IS_INVARIANT(term))
9917             has_utf8 = TRUE;
9918     }
9919
9920     /* mark where we are */
9921     PL_multi_start = CopLINE(PL_curcop);
9922     PL_multi_open = term;
9923
9924     /* find corresponding closing delimiter */
9925     if (term && (tmps = strchr("([{< )]}> )]}>",term)))
9926         termcode = termstr[0] = term = tmps[5];
9927
9928     PL_multi_close = term;
9929
9930     /* create a new SV to hold the contents.  87 is leak category, I'm
9931        assuming.  79 is the SV's initial length.  What a random number. */
9932     sv = NEWSV(87,79);
9933     sv_upgrade(sv, SVt_PVIV);
9934     SvIV_set(sv, termcode);
9935     (void)SvPOK_only(sv);               /* validate pointer */
9936
9937     /* move past delimiter and try to read a complete string */
9938     if (keep_delims)
9939         sv_catpvn(sv, s, termlen);
9940     s += termlen;
9941     for (;;) {
9942         if (PL_encoding && !UTF) {
9943             bool cont = TRUE;
9944
9945             while (cont) {
9946                 int offset = s - SvPVX_const(PL_linestr);
9947                 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
9948                                            &offset, (char*)termstr, termlen);
9949                 const char *ns = SvPVX_const(PL_linestr) + offset;
9950                 char *svlast = SvEND(sv) - 1;
9951
9952                 for (; s < ns; s++) {
9953                     if (*s == '\n' && !PL_rsfp)
9954                         CopLINE_inc(PL_curcop);
9955                 }
9956                 if (!found)
9957                     goto read_more_line;
9958                 else {
9959                     /* handle quoted delimiters */
9960                     if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
9961                         const char *t;
9962                         for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
9963                             t--;
9964                         if ((svlast-1 - t) % 2) {
9965                             if (!keep_quoted) {
9966                                 *(svlast-1) = term;
9967                                 *svlast = '\0';
9968                                 SvCUR_set(sv, SvCUR(sv) - 1);
9969                             }
9970                             continue;
9971                         }
9972                     }
9973                     if (PL_multi_open == PL_multi_close) {
9974                         cont = FALSE;
9975                     }
9976                     else {
9977                         const char *t;
9978                         char *w;
9979                         if (!last)
9980                             last = SvPVX(sv);
9981                         for (t = w = last; t < svlast; w++, t++) {
9982                             /* At here, all closes are "was quoted" one,
9983                                so we don't check PL_multi_close. */
9984                             if (*t == '\\') {
9985                                 if (!keep_quoted && *(t+1) == PL_multi_open)
9986                                     t++;
9987                                 else
9988                                     *w++ = *t++;
9989                             }
9990                             else if (*t == PL_multi_open)
9991                                 brackets++;
9992
9993                             *w = *t;
9994                         }
9995                         if (w < t) {
9996                             *w++ = term;
9997                             *w = '\0';
9998                             SvCUR_set(sv, w - SvPVX_const(sv));
9999                         }
10000                         last = w;
10001                         if (--brackets <= 0)
10002                             cont = FALSE;
10003                     }
10004                 }
10005             }
10006             if (!keep_delims) {
10007                 SvCUR_set(sv, SvCUR(sv) - 1);
10008                 *SvEND(sv) = '\0';
10009             }
10010             break;
10011         }
10012
10013         /* extend sv if need be */
10014         SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
10015         /* set 'to' to the next character in the sv's string */
10016         to = SvPVX(sv)+SvCUR(sv);
10017
10018         /* if open delimiter is the close delimiter read unbridle */
10019         if (PL_multi_open == PL_multi_close) {
10020             for (; s < PL_bufend; s++,to++) {
10021                 /* embedded newlines increment the current line number */
10022                 if (*s == '\n' && !PL_rsfp)
10023                     CopLINE_inc(PL_curcop);
10024                 /* handle quoted delimiters */
10025                 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
10026                     if (!keep_quoted && s[1] == term)
10027                         s++;
10028                 /* any other quotes are simply copied straight through */
10029                     else
10030                         *to++ = *s++;
10031                 }
10032                 /* terminate when run out of buffer (the for() condition), or
10033                    have found the terminator */
10034                 else if (*s == term) {
10035                     if (termlen == 1)
10036                         break;
10037                     if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
10038                         break;
10039                 }
10040                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
10041                     has_utf8 = TRUE;
10042                 *to = *s;
10043             }
10044         }
10045         
10046         /* if the terminator isn't the same as the start character (e.g.,
10047            matched brackets), we have to allow more in the quoting, and
10048            be prepared for nested brackets.
10049         */
10050         else {
10051             /* read until we run out of string, or we find the terminator */
10052             for (; s < PL_bufend; s++,to++) {
10053                 /* embedded newlines increment the line count */
10054                 if (*s == '\n' && !PL_rsfp)
10055                     CopLINE_inc(PL_curcop);
10056                 /* backslashes can escape the open or closing characters */
10057                 if (*s == '\\' && s+1 < PL_bufend) {
10058                     if (!keep_quoted &&
10059                         ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
10060                         s++;
10061                     else
10062                         *to++ = *s++;
10063                 }
10064                 /* allow nested opens and closes */
10065                 else if (*s == PL_multi_close && --brackets <= 0)
10066                     break;
10067                 else if (*s == PL_multi_open)
10068                     brackets++;
10069                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
10070                     has_utf8 = TRUE;
10071                 *to = *s;
10072             }
10073         }
10074         /* terminate the copied string and update the sv's end-of-string */
10075         *to = '\0';
10076         SvCUR_set(sv, to - SvPVX_const(sv));
10077
10078         /*
10079          * this next chunk reads more into the buffer if we're not done yet
10080          */
10081
10082         if (s < PL_bufend)
10083             break;              /* handle case where we are done yet :-) */
10084
10085 #ifndef PERL_STRICT_CR
10086         if (to - SvPVX_const(sv) >= 2) {
10087             if ((to[-2] == '\r' && to[-1] == '\n') ||
10088                 (to[-2] == '\n' && to[-1] == '\r'))
10089             {
10090                 to[-2] = '\n';
10091                 to--;
10092                 SvCUR_set(sv, to - SvPVX_const(sv));
10093             }
10094             else if (to[-1] == '\r')
10095                 to[-1] = '\n';
10096         }
10097         else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
10098             to[-1] = '\n';
10099 #endif
10100         
10101      read_more_line:
10102         /* if we're out of file, or a read fails, bail and reset the current
10103            line marker so we can report where the unterminated string began
10104         */
10105         if (!PL_rsfp ||
10106          !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
10107             sv_free(sv);
10108             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10109             return Nullch;
10110         }
10111         /* we read a line, so increment our line counter */
10112         CopLINE_inc(PL_curcop);
10113
10114         /* update debugger info */
10115         if (PERLDB_LINE && PL_curstash != PL_debstash) {
10116             SV *sv = NEWSV(88,0);
10117
10118             sv_upgrade(sv, SVt_PVMG);
10119             sv_setsv(sv,PL_linestr);
10120             (void)SvIOK_on(sv);
10121             SvIV_set(sv, 0);
10122             av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
10123         }
10124
10125         /* having changed the buffer, we must update PL_bufend */
10126         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10127         PL_last_lop = PL_last_uni = Nullch;
10128     }
10129
10130     /* at this point, we have successfully read the delimited string */
10131
10132     if (!PL_encoding || UTF) {
10133         if (keep_delims)
10134             sv_catpvn(sv, s, termlen);
10135         s += termlen;
10136     }
10137     if (has_utf8 || PL_encoding)
10138         SvUTF8_on(sv);
10139
10140     PL_multi_end = CopLINE(PL_curcop);
10141
10142     /* if we allocated too much space, give some back */
10143     if (SvCUR(sv) + 5 < SvLEN(sv)) {
10144         SvLEN_set(sv, SvCUR(sv) + 1);
10145         SvPV_renew(sv, SvLEN(sv));
10146     }
10147
10148     /* decide whether this is the first or second quoted string we've read
10149        for this op
10150     */
10151
10152     if (PL_lex_stuff)
10153         PL_lex_repl = sv;
10154     else
10155         PL_lex_stuff = sv;
10156     return s;
10157 }
10158
10159 /*
10160   scan_num
10161   takes: pointer to position in buffer
10162   returns: pointer to new position in buffer
10163   side-effects: builds ops for the constant in yylval.op
10164
10165   Read a number in any of the formats that Perl accepts:
10166
10167   \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*)      12 12.34 12.
10168   \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*)                     .34
10169   0b[01](_?[01])*
10170   0[0-7](_?[0-7])*
10171   0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
10172
10173   Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
10174   thing it reads.
10175
10176   If it reads a number without a decimal point or an exponent, it will
10177   try converting the number to an integer and see if it can do so
10178   without loss of precision.
10179 */
10180
10181 char *
10182 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
10183 {
10184     register const char *s = start;     /* current position in buffer */
10185     register char *d;                   /* destination in temp buffer */
10186     register char *e;                   /* end of temp buffer */
10187     NV nv;                              /* number read, as a double */
10188     SV *sv = Nullsv;                    /* place to put the converted number */
10189     bool floatit;                       /* boolean: int or float? */
10190     const char *lastub = 0;             /* position of last underbar */
10191     static char const number_too_long[] = "Number too long";
10192
10193     /* We use the first character to decide what type of number this is */
10194
10195     switch (*s) {
10196     default:
10197       Perl_croak(aTHX_ "panic: scan_num");
10198
10199     /* if it starts with a 0, it could be an octal number, a decimal in
10200        0.13 disguise, or a hexadecimal number, or a binary number. */
10201     case '0':
10202         {
10203           /* variables:
10204              u          holds the "number so far"
10205              shift      the power of 2 of the base
10206                         (hex == 4, octal == 3, binary == 1)
10207              overflowed was the number more than we can hold?
10208
10209              Shift is used when we add a digit.  It also serves as an "are
10210              we in octal/hex/binary?" indicator to disallow hex characters
10211              when in octal mode.
10212            */
10213             NV n = 0.0;
10214             UV u = 0;
10215             I32 shift;
10216             bool overflowed = FALSE;
10217             bool just_zero  = TRUE;     /* just plain 0 or binary number? */
10218             static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
10219             static const char* const bases[5] =
10220               { "", "binary", "", "octal", "hexadecimal" };
10221             static const char* const Bases[5] =
10222               { "", "Binary", "", "Octal", "Hexadecimal" };
10223             static const char* const maxima[5] =
10224               { "",
10225                 "0b11111111111111111111111111111111",
10226                 "",
10227                 "037777777777",
10228                 "0xffffffff" };
10229             const char *base, *Base, *max;
10230
10231             /* check for hex */
10232             if (s[1] == 'x') {
10233                 shift = 4;
10234                 s += 2;
10235                 just_zero = FALSE;
10236             } else if (s[1] == 'b') {
10237                 shift = 1;
10238                 s += 2;
10239                 just_zero = FALSE;
10240             }
10241             /* check for a decimal in disguise */
10242             else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
10243                 goto decimal;
10244             /* so it must be octal */
10245             else {
10246                 shift = 3;
10247                 s++;
10248             }
10249
10250             if (*s == '_') {
10251                if (ckWARN(WARN_SYNTAX))
10252                    Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10253                                "Misplaced _ in number");
10254                lastub = s++;
10255             }
10256
10257             base = bases[shift];
10258             Base = Bases[shift];
10259             max  = maxima[shift];
10260
10261             /* read the rest of the number */
10262             for (;;) {
10263                 /* x is used in the overflow test,
10264                    b is the digit we're adding on. */
10265                 UV x, b;
10266
10267                 switch (*s) {
10268
10269                 /* if we don't mention it, we're done */
10270                 default:
10271                     goto out;
10272
10273                 /* _ are ignored -- but warned about if consecutive */
10274                 case '_':
10275                     if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
10276                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10277                                     "Misplaced _ in number");
10278                     lastub = s++;
10279                     break;
10280
10281                 /* 8 and 9 are not octal */
10282                 case '8': case '9':
10283                     if (shift == 3)
10284                         yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
10285                     /* FALL THROUGH */
10286
10287                 /* octal digits */
10288                 case '2': case '3': case '4':
10289                 case '5': case '6': case '7':
10290                     if (shift == 1)
10291                         yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
10292                     /* FALL THROUGH */
10293
10294                 case '0': case '1':
10295                     b = *s++ & 15;              /* ASCII digit -> value of digit */
10296                     goto digit;
10297
10298                 /* hex digits */
10299                 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
10300                 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
10301                     /* make sure they said 0x */
10302                     if (shift != 4)
10303                         goto out;
10304                     b = (*s++ & 7) + 9;
10305
10306                     /* Prepare to put the digit we have onto the end
10307                        of the number so far.  We check for overflows.
10308                     */
10309
10310                   digit:
10311                     just_zero = FALSE;
10312                     if (!overflowed) {
10313                         x = u << shift; /* make room for the digit */
10314
10315                         if ((x >> shift) != u
10316                             && !(PL_hints & HINT_NEW_BINARY)) {
10317                             overflowed = TRUE;
10318                             n = (NV) u;
10319                             if (ckWARN_d(WARN_OVERFLOW))
10320                                 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
10321                                             "Integer overflow in %s number",
10322                                             base);
10323                         } else
10324                             u = x | b;          /* add the digit to the end */
10325                     }
10326                     if (overflowed) {
10327                         n *= nvshift[shift];
10328                         /* If an NV has not enough bits in its
10329                          * mantissa to represent an UV this summing of
10330                          * small low-order numbers is a waste of time
10331                          * (because the NV cannot preserve the
10332                          * low-order bits anyway): we could just
10333                          * remember when did we overflow and in the
10334                          * end just multiply n by the right
10335                          * amount. */
10336                         n += (NV) b;
10337                     }
10338                     break;
10339                 }
10340             }
10341
10342           /* if we get here, we had success: make a scalar value from
10343              the number.
10344           */
10345           out:
10346
10347             /* final misplaced underbar check */
10348             if (s[-1] == '_') {
10349                 if (ckWARN(WARN_SYNTAX))
10350                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10351             }
10352
10353             sv = NEWSV(92,0);
10354             if (overflowed) {
10355                 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
10356                     Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10357                                 "%s number > %s non-portable",
10358                                 Base, max);
10359                 sv_setnv(sv, n);
10360             }
10361             else {
10362 #if UVSIZE > 4
10363                 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
10364                     Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
10365                                 "%s number > %s non-portable",
10366                                 Base, max);
10367 #endif
10368                 sv_setuv(sv, u);
10369             }
10370             if (just_zero && (PL_hints & HINT_NEW_INTEGER))
10371                 sv = new_constant(start, s - start, "integer",
10372                                   sv, Nullsv, NULL);
10373             else if (PL_hints & HINT_NEW_BINARY)
10374                 sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
10375         }
10376         break;
10377
10378     /*
10379       handle decimal numbers.
10380       we're also sent here when we read a 0 as the first digit
10381     */
10382     case '1': case '2': case '3': case '4': case '5':
10383     case '6': case '7': case '8': case '9': case '.':
10384       decimal:
10385         d = PL_tokenbuf;
10386         e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
10387         floatit = FALSE;
10388
10389         /* read next group of digits and _ and copy into d */
10390         while (isDIGIT(*s) || *s == '_') {
10391             /* skip underscores, checking for misplaced ones
10392                if -w is on
10393             */
10394             if (*s == '_') {
10395                 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
10396                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10397                                 "Misplaced _ in number");
10398                 lastub = s++;
10399             }
10400             else {
10401                 /* check for end of fixed-length buffer */
10402                 if (d >= e)
10403                     Perl_croak(aTHX_ number_too_long);
10404                 /* if we're ok, copy the character */
10405                 *d++ = *s++;
10406             }
10407         }
10408
10409         /* final misplaced underbar check */
10410         if (lastub && s == lastub + 1) {
10411             if (ckWARN(WARN_SYNTAX))
10412                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
10413         }
10414
10415         /* read a decimal portion if there is one.  avoid
10416            3..5 being interpreted as the number 3. followed
10417            by .5
10418         */
10419         if (*s == '.' && s[1] != '.') {
10420             floatit = TRUE;
10421             *d++ = *s++;
10422
10423             if (*s == '_') {
10424                 if (ckWARN(WARN_SYNTAX))
10425                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10426                                 "Misplaced _ in number");
10427                 lastub = s;
10428             }
10429
10430             /* copy, ignoring underbars, until we run out of digits.
10431             */
10432             for (; isDIGIT(*s) || *s == '_'; s++) {
10433                 /* fixed length buffer check */
10434                 if (d >= e)
10435                     Perl_croak(aTHX_ number_too_long);
10436                 if (*s == '_') {
10437                    if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
10438                        Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10439                                    "Misplaced _ in number");
10440                    lastub = s;
10441                 }
10442                 else
10443                     *d++ = *s;
10444             }
10445             /* fractional part ending in underbar? */
10446             if (s[-1] == '_') {
10447                 if (ckWARN(WARN_SYNTAX))
10448                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10449                                 "Misplaced _ in number");
10450             }
10451             if (*s == '.' && isDIGIT(s[1])) {
10452                 /* oops, it's really a v-string, but without the "v" */
10453                 s = start;
10454                 goto vstring;
10455             }
10456         }
10457
10458         /* read exponent part, if present */
10459         if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
10460             floatit = TRUE;
10461             s++;
10462
10463             /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
10464             *d++ = 'e';         /* At least some Mach atof()s don't grok 'E' */
10465
10466             /* stray preinitial _ */
10467             if (*s == '_') {
10468                 if (ckWARN(WARN_SYNTAX))
10469                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10470                                 "Misplaced _ in number");
10471                 lastub = s++;
10472             }
10473
10474             /* allow positive or negative exponent */
10475             if (*s == '+' || *s == '-')
10476                 *d++ = *s++;
10477
10478             /* stray initial _ */
10479             if (*s == '_') {
10480                 if (ckWARN(WARN_SYNTAX))
10481                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10482                                 "Misplaced _ in number");
10483                 lastub = s++;
10484             }
10485
10486             /* read digits of exponent */
10487             while (isDIGIT(*s) || *s == '_') {
10488                 if (isDIGIT(*s)) {
10489                     if (d >= e)
10490                         Perl_croak(aTHX_ number_too_long);
10491                     *d++ = *s++;
10492                 }
10493                 else {
10494                    if (((lastub && s == lastub + 1) ||
10495                         (!isDIGIT(s[1]) && s[1] != '_'))
10496                     && ckWARN(WARN_SYNTAX))
10497                        Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10498                                    "Misplaced _ in number");
10499                    lastub = s++;
10500                 }
10501             }
10502         }
10503
10504
10505         /* make an sv from the string */
10506         sv = NEWSV(92,0);
10507
10508         /*
10509            We try to do an integer conversion first if no characters
10510            indicating "float" have been found.
10511          */
10512
10513         if (!floatit) {
10514             UV uv;
10515             int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
10516
10517             if (flags == IS_NUMBER_IN_UV) {
10518               if (uv <= IV_MAX)
10519                 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
10520               else
10521                 sv_setuv(sv, uv);
10522             } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
10523               if (uv <= (UV) IV_MIN)
10524                 sv_setiv(sv, -(IV)uv);
10525               else
10526                 floatit = TRUE;
10527             } else
10528               floatit = TRUE;
10529         }
10530         if (floatit) {
10531             /* terminate the string */
10532             *d = '\0';
10533             nv = Atof(PL_tokenbuf);
10534             sv_setnv(sv, nv);
10535         }
10536
10537         if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
10538                        (PL_hints & HINT_NEW_INTEGER) )
10539             sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
10540                               (floatit ? "float" : "integer"),
10541                               sv, Nullsv, NULL);
10542         break;
10543
10544     /* if it starts with a v, it could be a v-string */
10545     case 'v':
10546 vstring:
10547                 sv = NEWSV(92,5); /* preallocate storage space */
10548                 s = scan_vstring(s,sv);
10549         break;
10550     }
10551
10552     /* make the op for the constant and return */
10553
10554     if (sv)
10555         lvalp->opval = newSVOP(OP_CONST, 0, sv);
10556     else
10557         lvalp->opval = Nullop;
10558
10559     return (char *)s;
10560 }
10561
10562 STATIC char *
10563 S_scan_formline(pTHX_ register char *s)
10564 {
10565     register char *eol;
10566     register char *t;
10567     SV *stuff = newSVpvn("",0);
10568     bool needargs = FALSE;
10569     bool eofmt = FALSE;
10570
10571     while (!needargs) {
10572         if (*s == '.') {
10573 #ifdef PERL_STRICT_CR
10574             for (t = s+1;SPACE_OR_TAB(*t); t++) ;
10575 #else
10576             for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
10577 #endif
10578             if (*t == '\n' || t == PL_bufend) {
10579                 eofmt = TRUE;
10580                 break;
10581             }
10582         }
10583         if (PL_in_eval && !PL_rsfp) {
10584             eol = (char *) memchr(s,'\n',PL_bufend-s);
10585             if (!eol++)
10586                 eol = PL_bufend;
10587         }
10588         else
10589             eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10590         if (*s != '#') {
10591             for (t = s; t < eol; t++) {
10592                 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
10593                     needargs = FALSE;
10594                     goto enough;        /* ~~ must be first line in formline */
10595                 }
10596                 if (*t == '@' || *t == '^')
10597                     needargs = TRUE;
10598             }
10599             if (eol > s) {
10600                 sv_catpvn(stuff, s, eol-s);
10601 #ifndef PERL_STRICT_CR
10602                 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
10603                     char *end = SvPVX(stuff) + SvCUR(stuff);
10604                     end[-2] = '\n';
10605                     end[-1] = '\0';
10606                     SvCUR_set(stuff, SvCUR(stuff) - 1);
10607                 }
10608 #endif
10609             }
10610             else
10611               break;
10612         }
10613         s = (char*)eol;
10614         if (PL_rsfp) {
10615             s = filter_gets(PL_linestr, PL_rsfp, 0);
10616             PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
10617             PL_bufend = PL_bufptr + SvCUR(PL_linestr);
10618             PL_last_lop = PL_last_uni = Nullch;
10619             if (!s) {
10620                 s = PL_bufptr;
10621                 break;
10622             }
10623         }
10624         incline(s);
10625     }
10626   enough:
10627     if (SvCUR(stuff)) {
10628         PL_expect = XTERM;
10629         if (needargs) {
10630             PL_lex_state = LEX_NORMAL;
10631             PL_nextval[PL_nexttoke].ival = 0;
10632             force_next(',');
10633         }
10634         else
10635             PL_lex_state = LEX_FORMLINE;
10636         if (!IN_BYTES) {
10637             if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
10638                 SvUTF8_on(stuff);
10639             else if (PL_encoding)
10640                 sv_recode_to_utf8(stuff, PL_encoding);
10641         }
10642         PL_nextval[PL_nexttoke].opval = (OP*)newSVOP(OP_CONST, 0, stuff);
10643         force_next(THING);
10644         PL_nextval[PL_nexttoke].ival = OP_FORMLINE;
10645         force_next(LSTOP);
10646     }
10647     else {
10648         SvREFCNT_dec(stuff);
10649         if (eofmt)
10650             PL_lex_formbrack = 0;
10651         PL_bufptr = s;
10652     }
10653     return s;
10654 }
10655
10656 STATIC void
10657 S_set_csh(pTHX)
10658 {
10659 #ifdef CSH
10660     if (!PL_cshlen)
10661         PL_cshlen = strlen(PL_cshname);
10662 #endif
10663 }
10664
10665 I32
10666 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
10667 {
10668     const I32 oldsavestack_ix = PL_savestack_ix;
10669     CV* outsidecv = PL_compcv;
10670
10671     if (PL_compcv) {
10672         assert(SvTYPE(PL_compcv) == SVt_PVCV);
10673     }
10674     SAVEI32(PL_subline);
10675     save_item(PL_subname);
10676     SAVESPTR(PL_compcv);
10677
10678     PL_compcv = (CV*)NEWSV(1104,0);
10679     sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
10680     CvFLAGS(PL_compcv) |= flags;
10681
10682     PL_subline = CopLINE(PL_curcop);
10683     CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
10684     CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc(outsidecv);
10685     CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
10686
10687     return oldsavestack_ix;
10688 }
10689
10690 #ifdef __SC__
10691 #pragma segment Perl_yylex
10692 #endif
10693 int
10694 Perl_yywarn(pTHX_ const char *s)
10695 {
10696     PL_in_eval |= EVAL_WARNONLY;
10697     yyerror(s);
10698     PL_in_eval &= ~EVAL_WARNONLY;
10699     return 0;
10700 }
10701
10702 int
10703 Perl_yyerror(pTHX_ const char *s)
10704 {
10705     const char *where = NULL;
10706     const char *context = NULL;
10707     int contlen = -1;
10708     SV *msg;
10709
10710     if (!yychar || (yychar == ';' && !PL_rsfp))
10711         where = "at EOF";
10712     else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
10713       PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
10714       PL_oldbufptr != PL_bufptr) {
10715         /*
10716                 Only for NetWare:
10717                 The code below is removed for NetWare because it abends/crashes on NetWare
10718                 when the script has error such as not having the closing quotes like:
10719                     if ($var eq "value)
10720                 Checking of white spaces is anyway done in NetWare code.
10721         */
10722 #ifndef NETWARE
10723         while (isSPACE(*PL_oldoldbufptr))
10724             PL_oldoldbufptr++;
10725 #endif
10726         context = PL_oldoldbufptr;
10727         contlen = PL_bufptr - PL_oldoldbufptr;
10728     }
10729     else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
10730       PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
10731         /*
10732                 Only for NetWare:
10733                 The code below is removed for NetWare because it abends/crashes on NetWare
10734                 when the script has error such as not having the closing quotes like:
10735                     if ($var eq "value)
10736                 Checking of white spaces is anyway done in NetWare code.
10737         */
10738 #ifndef NETWARE
10739         while (isSPACE(*PL_oldbufptr))
10740             PL_oldbufptr++;
10741 #endif
10742         context = PL_oldbufptr;
10743         contlen = PL_bufptr - PL_oldbufptr;
10744     }
10745     else if (yychar > 255)
10746         where = "next token ???";
10747     else if (yychar == -2) { /* YYEMPTY */
10748         if (PL_lex_state == LEX_NORMAL ||
10749            (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
10750             where = "at end of line";
10751         else if (PL_lex_inpat)
10752             where = "within pattern";
10753         else
10754             where = "within string";
10755     }
10756     else {
10757         SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
10758         if (yychar < 32)
10759             Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
10760         else if (isPRINT_LC(yychar))
10761             Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
10762         else
10763             Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
10764         where = SvPVX_const(where_sv);
10765     }
10766     msg = sv_2mortal(newSVpv(s, 0));
10767     Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
10768         OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
10769     if (context)
10770         Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
10771     else
10772         Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
10773     if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
10774         Perl_sv_catpvf(aTHX_ msg,
10775         "  (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
10776                 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
10777         PL_multi_end = 0;
10778     }
10779     if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
10780         Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg);
10781     else
10782         qerror(msg);
10783     if (PL_error_count >= 10) {
10784         if (PL_in_eval && SvCUR(ERRSV))
10785             Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
10786             ERRSV, OutCopFILE(PL_curcop));
10787         else
10788             Perl_croak(aTHX_ "%s has too many errors.\n",
10789             OutCopFILE(PL_curcop));
10790     }
10791     PL_in_my = 0;
10792     PL_in_my_stash = Nullhv;
10793     return 0;
10794 }
10795 #ifdef __SC__
10796 #pragma segment Main
10797 #endif
10798
10799 STATIC char*
10800 S_swallow_bom(pTHX_ U8 *s)
10801 {
10802     const STRLEN slen = SvCUR(PL_linestr);
10803     switch (s[0]) {
10804     case 0xFF:
10805         if (s[1] == 0xFE) {
10806             /* UTF-16 little-endian? (or UTF32-LE?) */
10807             if (s[2] == 0 && s[3] == 0)  /* UTF-32 little-endian */
10808                 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
10809 #ifndef PERL_NO_UTF16_FILTER
10810             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
10811             s += 2;
10812         utf16le:
10813             if (PL_bufend > (char*)s) {
10814                 U8 *news;
10815                 I32 newlen;
10816
10817                 filter_add(utf16rev_textfilter, NULL);
10818                 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10819                 utf16_to_utf8_reversed(s, news,
10820                                        PL_bufend - (char*)s - 1,
10821                                        &newlen);
10822                 sv_setpvn(PL_linestr, (const char*)news, newlen);
10823                 Safefree(news);
10824                 SvUTF8_on(PL_linestr);
10825                 s = (U8*)SvPVX(PL_linestr);
10826                 PL_bufend = SvPVX(PL_linestr) + newlen;
10827             }
10828 #else
10829             Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
10830 #endif
10831         }
10832         break;
10833     case 0xFE:
10834         if (s[1] == 0xFF) {   /* UTF-16 big-endian? */
10835 #ifndef PERL_NO_UTF16_FILTER
10836             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
10837             s += 2;
10838         utf16be:
10839             if (PL_bufend > (char *)s) {
10840                 U8 *news;
10841                 I32 newlen;
10842
10843                 filter_add(utf16_textfilter, NULL);
10844                 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
10845                 utf16_to_utf8(s, news,
10846                               PL_bufend - (char*)s,
10847                               &newlen);
10848                 sv_setpvn(PL_linestr, (const char*)news, newlen);
10849                 Safefree(news);
10850                 SvUTF8_on(PL_linestr);
10851                 s = (U8*)SvPVX(PL_linestr);
10852                 PL_bufend = SvPVX(PL_linestr) + newlen;
10853             }
10854 #else
10855             Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
10856 #endif
10857         }
10858         break;
10859     case 0xEF:
10860         if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
10861             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
10862             s += 3;                      /* UTF-8 */
10863         }
10864         break;
10865     case 0:
10866         if (slen > 3) {
10867              if (s[1] == 0) {
10868                   if (s[2] == 0xFE && s[3] == 0xFF) {
10869                        /* UTF-32 big-endian */
10870                        Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
10871                   }
10872              }
10873              else if (s[2] == 0 && s[3] != 0) {
10874                   /* Leading bytes
10875                    * 00 xx 00 xx
10876                    * are a good indicator of UTF-16BE. */
10877                   if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
10878                   goto utf16be;
10879              }
10880         }
10881     default:
10882          if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
10883                   /* Leading bytes
10884                    * xx 00 xx 00
10885                    * are a good indicator of UTF-16LE. */
10886               if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
10887               goto utf16le;
10888          }
10889     }
10890     return (char*)s;
10891 }
10892
10893 /*
10894  * restore_rsfp
10895  * Restore a source filter.
10896  */
10897
10898 static void
10899 restore_rsfp(pTHX_ void *f)
10900 {
10901     PerlIO *fp = (PerlIO*)f;
10902
10903     if (PL_rsfp == PerlIO_stdin())
10904         PerlIO_clearerr(PL_rsfp);
10905     else if (PL_rsfp && (PL_rsfp != fp))
10906         PerlIO_close(PL_rsfp);
10907     PL_rsfp = fp;
10908 }
10909
10910 #ifndef PERL_NO_UTF16_FILTER
10911 static I32
10912 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10913 {
10914     const STRLEN old = SvCUR(sv);
10915     const I32 count = FILTER_READ(idx+1, sv, maxlen);
10916     DEBUG_P(PerlIO_printf(Perl_debug_log,
10917                           "utf16_textfilter(%p): %d %d (%d)\n",
10918                           utf16_textfilter, idx, maxlen, (int) count));
10919     if (count) {
10920         U8* tmps;
10921         I32 newlen;
10922         Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10923         Copy(SvPVX_const(sv), tmps, old, char);
10924         utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
10925                       SvCUR(sv) - old, &newlen);
10926         sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10927     }
10928     DEBUG_P({sv_dump(sv);});
10929     return SvCUR(sv);
10930 }
10931
10932 static I32
10933 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
10934 {
10935     const STRLEN old = SvCUR(sv);
10936     const I32 count = FILTER_READ(idx+1, sv, maxlen);
10937     DEBUG_P(PerlIO_printf(Perl_debug_log,
10938                           "utf16rev_textfilter(%p): %d %d (%d)\n",
10939                           utf16rev_textfilter, idx, maxlen, (int) count));
10940     if (count) {
10941         U8* tmps;
10942         I32 newlen;
10943         Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
10944         Copy(SvPVX_const(sv), tmps, old, char);
10945         utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
10946                       SvCUR(sv) - old, &newlen);
10947         sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
10948     }
10949     DEBUG_P({ sv_dump(sv); });
10950     return count;
10951 }
10952 #endif
10953
10954 /*
10955 Returns a pointer to the next character after the parsed
10956 vstring, as well as updating the passed in sv.
10957
10958 Function must be called like
10959
10960         sv = NEWSV(92,5);
10961         s = scan_vstring(s,sv);
10962
10963 The sv should already be large enough to store the vstring
10964 passed in, for performance reasons.
10965
10966 */
10967
10968 char *
10969 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
10970 {
10971     const char *pos = s;
10972     const char *start = s;
10973     if (*pos == 'v') pos++;  /* get past 'v' */
10974     while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
10975         pos++;
10976     if ( *pos != '.') {
10977         /* this may not be a v-string if followed by => */
10978         const char *next = pos;
10979         while (next < PL_bufend && isSPACE(*next))
10980             ++next;
10981         if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
10982             /* return string not v-string */
10983             sv_setpvn(sv,(char *)s,pos-s);
10984             return (char *)pos;
10985         }
10986     }
10987
10988     if (!isALPHA(*pos)) {
10989         UV rev;
10990         U8 tmpbuf[UTF8_MAXBYTES+1];
10991         U8 *tmpend;
10992
10993         if (*s == 'v') s++;  /* get past 'v' */
10994
10995         sv_setpvn(sv, "", 0);
10996
10997         for (;;) {
10998             rev = 0;
10999             {
11000                 /* this is atoi() that tolerates underscores */
11001                 const char *end = pos;
11002                 UV mult = 1;
11003                 while (--end >= s) {
11004                     UV orev;
11005                     if (*end == '_')
11006                         continue;
11007                     orev = rev;
11008                     rev += (*end - '0') * mult;
11009                     mult *= 10;
11010                     if (orev > rev && ckWARN_d(WARN_OVERFLOW))
11011                         Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11012                                     "Integer overflow in decimal number");
11013                 }
11014             }
11015 #ifdef EBCDIC
11016             if (rev > 0x7FFFFFFF)
11017                  Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
11018 #endif
11019             /* Append native character for the rev point */
11020             tmpend = uvchr_to_utf8(tmpbuf, rev);
11021             sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
11022             if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
11023                  SvUTF8_on(sv);
11024             if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
11025                  s = ++pos;
11026             else {
11027                  s = pos;
11028                  break;
11029             }
11030             while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
11031                  pos++;
11032         }
11033         SvPOK_on(sv);
11034         sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
11035         SvRMAGICAL_on(sv);
11036     }
11037     return (char *)s;
11038 }
11039
11040 /*
11041  * Local variables:
11042  * c-indentation-style: bsd
11043  * c-basic-offset: 4
11044  * indent-tabs-mode: t
11045  * End:
11046  *
11047  * ex: set ts=8 sts=4 sw=4 noet:
11048  */