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