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