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