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