Upgrade to Module-Build-0.27_09
[p5sagit/p5-mst-13.2.git] / toke.c
1 /*    toke.c
2  *
3  *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4  *    2000, 2001, 2002, 2003, 2004, 2005, 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                             /*EMPTY*/;    /* skip to avoid loading attributes.pm */
4030 #endif
4031                         else
4032                             Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4033                     }
4034
4035                     /* NOTE: any CV attrs applied here need to be part of
4036                        the CVf_BUILTIN_ATTRS define in cv.h! */
4037                     else if (!PL_in_my && len == 6 && strnEQ(s, "lvalue", len))
4038                         CvLVALUE_on(PL_compcv);
4039                     else if (!PL_in_my && len == 6 && strnEQ(s, "locked", len))
4040                         CvLOCKED_on(PL_compcv);
4041                     else if (!PL_in_my && len == 6 && strnEQ(s, "method", len))
4042                         CvMETHOD_on(PL_compcv);
4043                     else if (!PL_in_my && len == 9 && strnEQ(s, "assertion", len))
4044                         CvASSERTION_on(PL_compcv);
4045                     /* After we've set the flags, it could be argued that
4046                        we don't need to do the attributes.pm-based setting
4047                        process, and shouldn't bother appending recognized
4048                        flags.  To experiment with that, uncomment the
4049                        following "else".  (Note that's already been
4050                        uncommented.  That keeps the above-applied built-in
4051                        attributes from being intercepted (and possibly
4052                        rejected) by a package's attribute routines, but is
4053                        justified by the performance win for the common case
4054                        of applying only built-in attributes.) */
4055                     else
4056                         attrs = append_elem(OP_LIST, attrs,
4057                                             newSVOP(OP_CONST, 0,
4058                                                     newSVpvn(s, len)));
4059                 }
4060                 s = PEEKSPACE(d);
4061                 if (*s == ':' && s[1] != ':')
4062                     s = PEEKSPACE(s+1);
4063                 else if (s == d)
4064                     break;      /* require real whitespace or :'s */
4065                 /* XXX losing whitespace on sequential attributes here */
4066             }
4067             {
4068                 const char tmp
4069                     = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4070                 if (*s != ';' && *s != '}' && *s != tmp
4071                     && (tmp != '=' || *s != ')')) {
4072                     const char q = ((*s == '\'') ? '"' : '\'');
4073                     /* If here for an expression, and parsed no attrs, back
4074                        off. */
4075                     if (tmp == '=' && !attrs) {
4076                         s = PL_bufptr;
4077                         break;
4078                     }
4079                     /* MUST advance bufptr here to avoid bogus "at end of line"
4080                        context messages from yyerror().
4081                     */
4082                     PL_bufptr = s;
4083                     yyerror( *s
4084                              ? Perl_form(aTHX_ "Invalid separator character "
4085                                          "%c%c%c in attribute list", q, *s, q)
4086                              : "Unterminated attribute list" );
4087                     if (attrs)
4088                         op_free(attrs);
4089                     OPERATOR(':');
4090                 }
4091             }
4092         got_attrs:
4093             if (attrs) {
4094                 start_force(PL_curforce);
4095                 NEXTVAL_NEXTTOKE.opval = attrs;
4096                 CURMAD('_', PL_nextwhite);
4097                 force_next(THING);
4098             }
4099 #ifdef PERL_MAD
4100             if (PL_madskills) {
4101                 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4102                                      (s - SvPVX(PL_linestr)) - stuffstart);
4103             }
4104 #endif
4105             TOKEN(COLONATTR);
4106         }
4107         OPERATOR(':');
4108     case '(':
4109         s++;
4110         if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4111             PL_oldbufptr = PL_oldoldbufptr;             /* allow print(STDOUT 123) */
4112         else
4113             PL_expect = XTERM;
4114         s = SKIPSPACE1(s);
4115         TOKEN('(');
4116     case ';':
4117         CLINE;
4118         {
4119             const char tmp = *s++;
4120             OPERATOR(tmp);
4121         }
4122     case ')':
4123         {
4124             const char tmp = *s++;
4125             s = SKIPSPACE1(s);
4126             if (*s == '{')
4127                 PREBLOCK(tmp);
4128             TERM(tmp);
4129         }
4130     case ']':
4131         s++;
4132         if (PL_lex_brackets <= 0)
4133             yyerror("Unmatched right square bracket");
4134         else
4135             --PL_lex_brackets;
4136         if (PL_lex_state == LEX_INTERPNORMAL) {
4137             if (PL_lex_brackets == 0) {
4138                 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4139                     PL_lex_state = LEX_INTERPEND;
4140             }
4141         }
4142         TERM(']');
4143     case '{':
4144       leftbracket:
4145         s++;
4146         if (PL_lex_brackets > 100) {
4147             Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4148         }
4149         switch (PL_expect) {
4150         case XTERM:
4151             if (PL_lex_formbrack) {
4152                 s--;
4153                 PRETERMBLOCK(DO);
4154             }
4155             if (PL_oldoldbufptr == PL_last_lop)
4156                 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4157             else
4158                 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4159             OPERATOR(HASHBRACK);
4160         case XOPERATOR:
4161             while (s < PL_bufend && SPACE_OR_TAB(*s))
4162                 s++;
4163             d = s;
4164             PL_tokenbuf[0] = '\0';
4165             if (d < PL_bufend && *d == '-') {
4166                 PL_tokenbuf[0] = '-';
4167                 d++;
4168                 while (d < PL_bufend && SPACE_OR_TAB(*d))
4169                     d++;
4170             }
4171             if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4172                 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4173                               FALSE, &len);
4174                 while (d < PL_bufend && SPACE_OR_TAB(*d))
4175                     d++;
4176                 if (*d == '}') {
4177                     const char minus = (PL_tokenbuf[0] == '-');
4178                     s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4179                     if (minus)
4180                         force_next('-');
4181                 }
4182             }
4183             /* FALL THROUGH */
4184         case XATTRBLOCK:
4185         case XBLOCK:
4186             PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4187             PL_expect = XSTATE;
4188             break;
4189         case XATTRTERM:
4190         case XTERMBLOCK:
4191             PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4192             PL_expect = XSTATE;
4193             break;
4194         default: {
4195                 const char *t;
4196                 if (PL_oldoldbufptr == PL_last_lop)
4197                     PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4198                 else
4199                     PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4200                 s = SKIPSPACE1(s);
4201                 if (*s == '}') {
4202                     if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4203                         PL_expect = XTERM;
4204                         /* This hack is to get the ${} in the message. */
4205                         PL_bufptr = s+1;
4206                         yyerror("syntax error");
4207                         break;
4208                     }
4209                     OPERATOR(HASHBRACK);
4210                 }
4211                 /* This hack serves to disambiguate a pair of curlies
4212                  * as being a block or an anon hash.  Normally, expectation
4213                  * determines that, but in cases where we're not in a
4214                  * position to expect anything in particular (like inside
4215                  * eval"") we have to resolve the ambiguity.  This code
4216                  * covers the case where the first term in the curlies is a
4217                  * quoted string.  Most other cases need to be explicitly
4218                  * disambiguated by prepending a "+" before the opening
4219                  * curly in order to force resolution as an anon hash.
4220                  *
4221                  * XXX should probably propagate the outer expectation
4222                  * into eval"" to rely less on this hack, but that could
4223                  * potentially break current behavior of eval"".
4224                  * GSAR 97-07-21
4225                  */
4226                 t = s;
4227                 if (*s == '\'' || *s == '"' || *s == '`') {
4228                     /* common case: get past first string, handling escapes */
4229                     for (t++; t < PL_bufend && *t != *s;)
4230                         if (*t++ == '\\' && (*t == '\\' || *t == *s))
4231                             t++;
4232                     t++;
4233                 }
4234                 else if (*s == 'q') {
4235                     if (++t < PL_bufend
4236                         && (!isALNUM(*t)
4237                             || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4238                                 && !isALNUM(*t))))
4239                     {
4240                         /* skip q//-like construct */
4241                         const char *tmps;
4242                         char open, close, term;
4243                         I32 brackets = 1;
4244
4245                         while (t < PL_bufend && isSPACE(*t))
4246                             t++;
4247                         /* check for q => */
4248                         if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4249                             OPERATOR(HASHBRACK);
4250                         }
4251                         term = *t;
4252                         open = term;
4253                         if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4254                             term = tmps[5];
4255                         close = term;
4256                         if (open == close)
4257                             for (t++; t < PL_bufend; t++) {
4258                                 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4259                                     t++;
4260                                 else if (*t == open)
4261                                     break;
4262                             }
4263                         else {
4264                             for (t++; t < PL_bufend; t++) {
4265                                 if (*t == '\\' && t+1 < PL_bufend)
4266                                     t++;
4267                                 else if (*t == close && --brackets <= 0)
4268                                     break;
4269                                 else if (*t == open)
4270                                     brackets++;
4271                             }
4272                         }
4273                         t++;
4274                     }
4275                     else
4276                         /* skip plain q word */
4277                         while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4278                              t += UTF8SKIP(t);
4279                 }
4280                 else if (isALNUM_lazy_if(t,UTF)) {
4281                     t += UTF8SKIP(t);
4282                     while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4283                          t += UTF8SKIP(t);
4284                 }
4285                 while (t < PL_bufend && isSPACE(*t))
4286                     t++;
4287                 /* if comma follows first term, call it an anon hash */
4288                 /* XXX it could be a comma expression with loop modifiers */
4289                 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4290                                    || (*t == '=' && t[1] == '>')))
4291                     OPERATOR(HASHBRACK);
4292                 if (PL_expect == XREF)
4293                     PL_expect = XTERM;
4294                 else {
4295                     PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4296                     PL_expect = XSTATE;
4297                 }
4298             }
4299             break;
4300         }
4301         yylval.ival = CopLINE(PL_curcop);
4302         if (isSPACE(*s) || *s == '#')
4303             PL_copline = NOLINE;   /* invalidate current command line number */
4304         TOKEN('{');
4305     case '}':
4306       rightbracket:
4307         s++;
4308         if (PL_lex_brackets <= 0)
4309             yyerror("Unmatched right curly bracket");
4310         else
4311             PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4312         if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4313             PL_lex_formbrack = 0;
4314         if (PL_lex_state == LEX_INTERPNORMAL) {
4315             if (PL_lex_brackets == 0) {
4316                 if (PL_expect & XFAKEBRACK) {
4317                     PL_expect &= XENUMMASK;
4318                     PL_lex_state = LEX_INTERPEND;
4319                     PL_bufptr = s;
4320 #if 0
4321                     if (PL_madskills) {
4322                         if (!PL_thiswhite)
4323                             PL_thiswhite = newSVpvn("",0);
4324                         sv_catpvn(PL_thiswhite,"}",1);
4325                     }
4326 #endif
4327                     return yylex();     /* ignore fake brackets */
4328                 }
4329                 if (*s == '-' && s[1] == '>')
4330                     PL_lex_state = LEX_INTERPENDMAYBE;
4331                 else if (*s != '[' && *s != '{')
4332                     PL_lex_state = LEX_INTERPEND;
4333             }
4334         }
4335         if (PL_expect & XFAKEBRACK) {
4336             PL_expect &= XENUMMASK;
4337             PL_bufptr = s;
4338             return yylex();             /* ignore fake brackets */
4339         }
4340         start_force(PL_curforce);
4341         if (PL_madskills) {
4342             curmad('X', newSVpvn(s-1,1));
4343             CURMAD('_', PL_thiswhite);
4344         }
4345         force_next('}');
4346 #ifdef PERL_MAD
4347         if (!PL_thistoken)
4348             PL_thistoken = newSVpvn("",0);
4349 #endif
4350         TOKEN(';');
4351     case '&':
4352         s++;
4353         if (*s++ == '&')
4354             AOPERATOR(ANDAND);
4355         s--;
4356         if (PL_expect == XOPERATOR) {
4357             if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4358                 && isIDFIRST_lazy_if(s,UTF))
4359             {
4360                 CopLINE_dec(PL_curcop);
4361                 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4362                 CopLINE_inc(PL_curcop);
4363             }
4364             BAop(OP_BIT_AND);
4365         }
4366
4367         s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4368         if (*PL_tokenbuf) {
4369             PL_expect = XOPERATOR;
4370             force_ident(PL_tokenbuf, '&');
4371         }
4372         else
4373             PREREF('&');
4374         yylval.ival = (OPpENTERSUB_AMPER<<8);
4375         TERM('&');
4376
4377     case '|':
4378         s++;
4379         if (*s++ == '|')
4380             AOPERATOR(OROR);
4381         s--;
4382         BOop(OP_BIT_OR);
4383     case '=':
4384         s++;
4385         {
4386             const char tmp = *s++;
4387             if (tmp == '=')
4388                 Eop(OP_EQ);
4389             if (tmp == '>')
4390                 OPERATOR(',');
4391             if (tmp == '~')
4392                 PMop(OP_MATCH);
4393             if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4394                 && strchr("+-*/%.^&|<",tmp))
4395                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4396                             "Reversed %c= operator",(int)tmp);
4397             s--;
4398             if (PL_expect == XSTATE && isALPHA(tmp) &&
4399                 (s == PL_linestart+1 || s[-2] == '\n') )
4400                 {
4401                     if (PL_in_eval && !PL_rsfp) {
4402                         d = PL_bufend;
4403                         while (s < d) {
4404                             if (*s++ == '\n') {
4405                                 incline(s);
4406                                 if (strnEQ(s,"=cut",4)) {
4407                                     s = strchr(s,'\n');
4408                                     if (s)
4409                                         s++;
4410                                     else
4411                                         s = d;
4412                                     incline(s);
4413                                     goto retry;
4414                                 }
4415                             }
4416                         }
4417                         goto retry;
4418                     }
4419 #ifdef PERL_MAD
4420                     if (PL_madskills) {
4421                         if (!PL_thiswhite)
4422                             PL_thiswhite = newSVpvn("",0);
4423                         sv_catpvn(PL_thiswhite, PL_linestart,
4424                                   PL_bufend - PL_linestart);
4425                     }
4426 #endif
4427                     s = PL_bufend;
4428                     PL_doextract = TRUE;
4429                     goto retry;
4430                 }
4431         }
4432         if (PL_lex_brackets < PL_lex_formbrack) {
4433             const char *t;
4434 #ifdef PERL_STRICT_CR
4435             for (t = s; SPACE_OR_TAB(*t); t++) ;
4436 #else
4437             for (t = s; SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
4438 #endif
4439             if (*t == '\n' || *t == '#') {
4440                 s--;
4441                 PL_expect = XBLOCK;
4442                 goto leftbracket;
4443             }
4444         }
4445         yylval.ival = 0;
4446         OPERATOR(ASSIGNOP);
4447     case '!':
4448         s++;
4449         {
4450             const char tmp = *s++;
4451             if (tmp == '=') {
4452                 /* was this !=~ where !~ was meant?
4453                  * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4454
4455                 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4456                     const char *t = s+1;
4457
4458                     while (t < PL_bufend && isSPACE(*t))
4459                         ++t;
4460
4461                     if (*t == '/' || *t == '?' ||
4462                         ((*t == 'm' || *t == 's' || *t == 'y')
4463                          && !isALNUM(t[1])) ||
4464                         (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4465                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4466                                     "!=~ should be !~");
4467                 }
4468                 Eop(OP_NE);
4469             }
4470             if (tmp == '~')
4471                 PMop(OP_NOT);
4472         }
4473         s--;
4474         OPERATOR('!');
4475     case '<':
4476         if (PL_expect != XOPERATOR) {
4477             if (s[1] != '<' && !strchr(s,'>'))
4478                 check_uni();
4479             if (s[1] == '<')
4480                 s = scan_heredoc(s);
4481             else
4482                 s = scan_inputsymbol(s);
4483             TERM(sublex_start());
4484         }
4485         s++;
4486         {
4487             char tmp = *s++;
4488             if (tmp == '<')
4489                 SHop(OP_LEFT_SHIFT);
4490             if (tmp == '=') {
4491                 tmp = *s++;
4492                 if (tmp == '>')
4493                     Eop(OP_NCMP);
4494                 s--;
4495                 Rop(OP_LE);
4496             }
4497         }
4498         s--;
4499         Rop(OP_LT);
4500     case '>':
4501         s++;
4502         {
4503             const char tmp = *s++;
4504             if (tmp == '>')
4505                 SHop(OP_RIGHT_SHIFT);
4506             if (tmp == '=')
4507                 Rop(OP_GE);
4508         }
4509         s--;
4510         Rop(OP_GT);
4511
4512     case '$':
4513         CLINE;
4514
4515         if (PL_expect == XOPERATOR) {
4516             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4517                 PL_expect = XTERM;
4518                 deprecate_old(commaless_variable_list);
4519                 return REPORT(','); /* grandfather non-comma-format format */
4520             }
4521         }
4522
4523         if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4524             PL_tokenbuf[0] = '@';
4525             s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4526                            sizeof PL_tokenbuf - 1, FALSE);
4527             if (PL_expect == XOPERATOR)
4528                 no_op("Array length", s);
4529             if (!PL_tokenbuf[1])
4530                 PREREF(DOLSHARP);
4531             PL_expect = XOPERATOR;
4532             PL_pending_ident = '#';
4533             TOKEN(DOLSHARP);
4534         }
4535
4536         PL_tokenbuf[0] = '$';
4537         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4538                        sizeof PL_tokenbuf - 1, FALSE);
4539         if (PL_expect == XOPERATOR)
4540             no_op("Scalar", s);
4541         if (!PL_tokenbuf[1]) {
4542             if (s == PL_bufend)
4543                 yyerror("Final $ should be \\$ or $name");
4544             PREREF('$');
4545         }
4546
4547         /* This kludge not intended to be bulletproof. */
4548         if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4549             yylval.opval = newSVOP(OP_CONST, 0,
4550                                    newSViv(PL_compiling.cop_arybase));
4551             yylval.opval->op_private = OPpCONST_ARYBASE;
4552             TERM(THING);
4553         }
4554
4555         d = s;
4556         {
4557             const char tmp = *s;
4558             if (PL_lex_state == LEX_NORMAL)
4559                 s = SKIPSPACE1(s);
4560
4561             if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4562                 && intuit_more(s)) {
4563                 if (*s == '[') {
4564                     PL_tokenbuf[0] = '@';
4565                     if (ckWARN(WARN_SYNTAX)) {
4566                         char *t;
4567                         for(t = s + 1;
4568                             isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$';
4569                             t++) ;
4570                         if (*t++ == ',') {
4571                             PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4572                             while (t < PL_bufend && *t != ']')
4573                                 t++;
4574                             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4575                                         "Multidimensional syntax %.*s not supported",
4576                                     (int)((t - PL_bufptr) + 1), PL_bufptr);
4577                         }
4578                     }
4579                 }
4580                 else if (*s == '{') {
4581                     char *t;
4582                     PL_tokenbuf[0] = '%';
4583                     if (strEQ(PL_tokenbuf+1, "SIG")  && ckWARN(WARN_SYNTAX)
4584                         && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4585                         {
4586                             char tmpbuf[sizeof PL_tokenbuf];
4587                             for (t++; isSPACE(*t); t++) ;
4588                             if (isIDFIRST_lazy_if(t,UTF)) {
4589                                 STRLEN dummylen;
4590                                 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4591                                               &dummylen);
4592                                 for (; isSPACE(*t); t++) ;
4593                                 if (*t == ';' && get_cv(tmpbuf, FALSE))
4594                                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4595                                                 "You need to quote \"%s\"",
4596                                                 tmpbuf);
4597                             }
4598                         }
4599                 }
4600             }
4601
4602             PL_expect = XOPERATOR;
4603             if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4604                 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4605                 if (!islop || PL_last_lop_op == OP_GREPSTART)
4606                     PL_expect = XOPERATOR;
4607                 else if (strchr("$@\"'`q", *s))
4608                     PL_expect = XTERM;          /* e.g. print $fh "foo" */
4609                 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4610                     PL_expect = XTERM;          /* e.g. print $fh &sub */
4611                 else if (isIDFIRST_lazy_if(s,UTF)) {
4612                     char tmpbuf[sizeof PL_tokenbuf];
4613                     int t2;
4614                     scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4615                     if ((t2 = keyword(tmpbuf, len))) {
4616                         /* binary operators exclude handle interpretations */
4617                         switch (t2) {
4618                         case -KEY_x:
4619                         case -KEY_eq:
4620                         case -KEY_ne:
4621                         case -KEY_gt:
4622                         case -KEY_lt:
4623                         case -KEY_ge:
4624                         case -KEY_le:
4625                         case -KEY_cmp:
4626                             break;
4627                         default:
4628                             PL_expect = XTERM;  /* e.g. print $fh length() */
4629                             break;
4630                         }
4631                     }
4632                     else {
4633                         PL_expect = XTERM;      /* e.g. print $fh subr() */
4634                     }
4635                 }
4636                 else if (isDIGIT(*s))
4637                     PL_expect = XTERM;          /* e.g. print $fh 3 */
4638                 else if (*s == '.' && isDIGIT(s[1]))
4639                     PL_expect = XTERM;          /* e.g. print $fh .3 */
4640                 else if ((*s == '?' || *s == '-' || *s == '+')
4641                          && !isSPACE(s[1]) && s[1] != '=')
4642                     PL_expect = XTERM;          /* e.g. print $fh -1 */
4643                 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4644                          && s[1] != '/')
4645                     PL_expect = XTERM;          /* e.g. print $fh /.../
4646                                                    XXX except DORDOR operator
4647                                                 */
4648                 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4649                          && s[2] != '=')
4650                     PL_expect = XTERM;          /* print $fh <<"EOF" */
4651             }
4652         }
4653         PL_pending_ident = '$';
4654         TOKEN('$');
4655
4656     case '@':
4657         if (PL_expect == XOPERATOR)
4658             no_op("Array", s);
4659         PL_tokenbuf[0] = '@';
4660         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4661         if (!PL_tokenbuf[1]) {
4662             PREREF('@');
4663         }
4664         if (PL_lex_state == LEX_NORMAL)
4665             s = SKIPSPACE1(s);
4666         if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4667             if (*s == '{')
4668                 PL_tokenbuf[0] = '%';
4669
4670             /* Warn about @ where they meant $. */
4671             if (*s == '[' || *s == '{') {
4672                 if (ckWARN(WARN_SYNTAX)) {
4673                     const char *t = s + 1;
4674                     while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4675                         t++;
4676                     if (*t == '}' || *t == ']') {
4677                         t++;
4678                         PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4679                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4680                             "Scalar value %.*s better written as $%.*s",
4681                             (int)(t-PL_bufptr), PL_bufptr,
4682                             (int)(t-PL_bufptr-1), PL_bufptr+1);
4683                     }
4684                 }
4685             }
4686         }
4687         PL_pending_ident = '@';
4688         TERM('@');
4689
4690      case '/':                  /* may be division, defined-or, or pattern */
4691         if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4692             s += 2;
4693             AOPERATOR(DORDOR);
4694         }
4695      case '?':                  /* may either be conditional or pattern */
4696          if(PL_expect == XOPERATOR) {
4697              char tmp = *s++;
4698              if(tmp == '?') {
4699                   OPERATOR('?');
4700              }
4701              else {
4702                  tmp = *s++;
4703                  if(tmp == '/') {
4704                      /* A // operator. */
4705                     AOPERATOR(DORDOR);
4706                  }
4707                  else {
4708                      s--;
4709                      Mop(OP_DIVIDE);
4710                  }
4711              }
4712          }
4713          else {
4714              /* Disable warning on "study /blah/" */
4715              if (PL_oldoldbufptr == PL_last_uni
4716               && (*PL_last_uni != 's' || s - PL_last_uni < 5
4717                   || memNE(PL_last_uni, "study", 5)
4718                   || isALNUM_lazy_if(PL_last_uni+5,UTF)
4719               ))
4720                  check_uni();
4721              s = scan_pat(s,OP_MATCH);
4722              TERM(sublex_start());
4723          }
4724
4725     case '.':
4726         if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4727 #ifdef PERL_STRICT_CR
4728             && s[1] == '\n'
4729 #else
4730             && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4731 #endif
4732             && (s == PL_linestart || s[-1] == '\n') )
4733         {
4734             PL_lex_formbrack = 0;
4735             PL_expect = XSTATE;
4736             goto rightbracket;
4737         }
4738         if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4739             char tmp = *s++;
4740             if (*s == tmp) {
4741                 s++;
4742                 if (*s == tmp) {
4743                     s++;
4744                     yylval.ival = OPf_SPECIAL;
4745                 }
4746                 else
4747                     yylval.ival = 0;
4748                 OPERATOR(DOTDOT);
4749             }
4750             if (PL_expect != XOPERATOR)
4751                 check_uni();
4752             Aop(OP_CONCAT);
4753         }
4754         /* FALL THROUGH */
4755     case '0': case '1': case '2': case '3': case '4':
4756     case '5': case '6': case '7': case '8': case '9':
4757         s = scan_num(s, &yylval);
4758         DEBUG_T( { S_printbuf(aTHX_ "### Saw number in %s\n", s); } );
4759         if (PL_expect == XOPERATOR)
4760             no_op("Number",s);
4761         TERM(THING);
4762
4763     case '\'':
4764         s = scan_str(s,!!PL_madskills,FALSE);
4765         DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } );
4766         if (PL_expect == XOPERATOR) {
4767             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4768                 PL_expect = XTERM;
4769                 deprecate_old(commaless_variable_list);
4770                 return REPORT(','); /* grandfather non-comma-format format */
4771             }
4772             else
4773                 no_op("String",s);
4774         }
4775         if (!s)
4776             missingterm((char*)0);
4777         yylval.ival = OP_CONST;
4778         TERM(sublex_start());
4779
4780     case '"':
4781         s = scan_str(s,!!PL_madskills,FALSE);
4782         DEBUG_T( { S_printbuf(aTHX_ "### Saw string before %s\n", s); } );
4783         if (PL_expect == XOPERATOR) {
4784             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4785                 PL_expect = XTERM;
4786                 deprecate_old(commaless_variable_list);
4787                 return REPORT(','); /* grandfather non-comma-format format */
4788             }
4789             else
4790                 no_op("String",s);
4791         }
4792         if (!s)
4793             missingterm((char*)0);
4794         yylval.ival = OP_CONST;
4795         /* FIXME. I think that this can be const if char *d is replaced by
4796            more localised variables.  */
4797         for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
4798             if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
4799                 yylval.ival = OP_STRINGIFY;
4800                 break;
4801             }
4802         }
4803         TERM(sublex_start());
4804
4805     case '`':
4806         s = scan_str(s,!!PL_madskills,FALSE);
4807         DEBUG_T( { S_printbuf(aTHX_ "### Saw backtick string before %s\n", s); } );
4808         if (PL_expect == XOPERATOR)
4809             no_op("Backticks",s);
4810         if (!s)
4811             missingterm((char*)0);
4812         yylval.ival = OP_BACKTICK;
4813         set_csh();
4814         TERM(sublex_start());
4815
4816     case '\\':
4817         s++;
4818         if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
4819             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
4820                         *s, *s);
4821         if (PL_expect == XOPERATOR)
4822             no_op("Backslash",s);
4823         OPERATOR(REFGEN);
4824
4825     case 'v':
4826         if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
4827             char *start = s + 2;
4828             while (isDIGIT(*start) || *start == '_')
4829                 start++;
4830             if (*start == '.' && isDIGIT(start[1])) {
4831                 s = scan_num(s, &yylval);
4832                 TERM(THING);
4833             }
4834             /* avoid v123abc() or $h{v1}, allow C<print v10;> */
4835             else if (!isALPHA(*start) && (PL_expect == XTERM
4836                         || PL_expect == XREF || PL_expect == XSTATE
4837                         || PL_expect == XTERMORDORDOR)) {
4838                 const char c = *start;
4839                 GV *gv;
4840                 *start = '\0';
4841                 gv = gv_fetchpv(s, 0, SVt_PVCV);
4842                 *start = c;
4843                 if (!gv) {
4844                     s = scan_num(s, &yylval);
4845                     TERM(THING);
4846                 }
4847             }
4848         }
4849         goto keylookup;
4850     case 'x':
4851         if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
4852             s++;
4853             Mop(OP_REPEAT);
4854         }
4855         goto keylookup;
4856
4857     case '_':
4858     case 'a': case 'A':
4859     case 'b': case 'B':
4860     case 'c': case 'C':
4861     case 'd': case 'D':
4862     case 'e': case 'E':
4863     case 'f': case 'F':
4864     case 'g': case 'G':
4865     case 'h': case 'H':
4866     case 'i': case 'I':
4867     case 'j': case 'J':
4868     case 'k': case 'K':
4869     case 'l': case 'L':
4870     case 'm': case 'M':
4871     case 'n': case 'N':
4872     case 'o': case 'O':
4873     case 'p': case 'P':
4874     case 'q': case 'Q':
4875     case 'r': case 'R':
4876     case 's': case 'S':
4877     case 't': case 'T':
4878     case 'u': case 'U':
4879               case 'V':
4880     case 'w': case 'W':
4881               case 'X':
4882     case 'y': case 'Y':
4883     case 'z': case 'Z':
4884
4885       keylookup: {
4886         I32 tmp;
4887         I32 orig_keyword = 0;
4888         GV *gv = NULL;
4889         GV **gvp = NULL;
4890
4891         PL_bufptr = s;
4892         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4893
4894         /* Some keywords can be followed by any delimiter, including ':' */
4895         tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
4896                (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
4897                              (PL_tokenbuf[0] == 'q' &&
4898                               strchr("qwxr", PL_tokenbuf[1])))));
4899
4900         /* x::* is just a word, unless x is "CORE" */
4901         if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4902             goto just_a_word;
4903
4904         d = s;
4905         while (d < PL_bufend && isSPACE(*d))
4906                 d++;    /* no comments skipped here, or s### is misparsed */
4907
4908         /* Is this a label? */
4909         if (!tmp && PL_expect == XSTATE
4910               && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
4911             s = d + 1;
4912             yylval.pval = savepv(PL_tokenbuf);
4913             CLINE;
4914             TOKEN(LABEL);
4915         }
4916
4917         /* Check for keywords */
4918         tmp = keyword(PL_tokenbuf, len);
4919
4920         /* Is this a word before a => operator? */
4921         if (*d == '=' && d[1] == '>') {
4922             CLINE;
4923             yylval.opval
4924                 = (OP*)newSVOP(OP_CONST, 0,
4925                                S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
4926             yylval.opval->op_private = OPpCONST_BARE;
4927             TERM(WORD);
4928         }
4929
4930         if (tmp < 0) {                  /* second-class keyword? */
4931             GV *ogv = NULL;     /* override (winner) */
4932             GV *hgv = NULL;     /* hidden (loser) */
4933             if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
4934                 CV *cv;
4935                 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
4936                     (cv = GvCVu(gv)))
4937                 {
4938                     if (GvIMPORTED_CV(gv))
4939                         ogv = gv;
4940                     else if (! CvMETHOD(cv))
4941                         hgv = gv;
4942                 }
4943                 if (!ogv &&
4944                     (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
4945                     (gv = *gvp) != (GV*)&PL_sv_undef &&
4946                     GvCVu(gv) && GvIMPORTED_CV(gv))
4947                 {
4948                     ogv = gv;
4949                 }
4950             }
4951             if (ogv) {
4952                 orig_keyword = tmp;
4953                 tmp = 0;                /* overridden by import or by GLOBAL */
4954             }
4955             else if (gv && !gvp
4956                      && -tmp==KEY_lock  /* XXX generalizable kludge */
4957                      && GvCVu(gv)
4958                      && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
4959             {
4960                 tmp = 0;                /* any sub overrides "weak" keyword */
4961             }
4962             else {                      /* no override */
4963                 tmp = -tmp;
4964                 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
4965                     Perl_warner(aTHX_ packWARN(WARN_MISC),
4966                             "dump() better written as CORE::dump()");
4967                 }
4968                 gv = NULL;
4969                 gvp = 0;
4970                 if (hgv && tmp != KEY_x && tmp != KEY_CORE
4971                         && ckWARN(WARN_AMBIGUOUS))      /* never ambiguous */
4972                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
4973                         "Ambiguous call resolved as CORE::%s(), %s",
4974                          GvENAME(hgv), "qualify as such or use &");
4975             }
4976         }
4977
4978       reserved_word:
4979         switch (tmp) {
4980
4981         default:                        /* not a keyword */
4982             /* Trade off - by using this evil construction we can pull the
4983                variable gv into the block labelled keylookup. If not, then
4984                we have to give it function scope so that the goto from the
4985                earlier ':' case doesn't bypass the initialisation.  */
4986             if (0) {
4987             just_a_word_zero_gv:
4988                 gv = NULL;
4989                 gvp = NULL;
4990                 orig_keyword = 0;
4991             }
4992           just_a_word: {
4993                 SV *sv;
4994                 int pkgname = 0;
4995                 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
4996                 CV *cv;
4997 #ifdef PERL_MAD
4998                 SV *nextPL_nextwhite = 0;
4999 #endif
5000
5001
5002                 /* Get the rest if it looks like a package qualifier */
5003
5004                 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5005                     STRLEN morelen;
5006                     s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5007                                   TRUE, &morelen);
5008                     if (!morelen)
5009                         Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5010                                 *s == '\'' ? "'" : "::");
5011                     len += morelen;
5012                     pkgname = 1;
5013                 }
5014
5015                 if (PL_expect == XOPERATOR) {
5016                     if (PL_bufptr == PL_linestart) {
5017                         CopLINE_dec(PL_curcop);
5018                         Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5019                         CopLINE_inc(PL_curcop);
5020                     }
5021                     else
5022                         no_op("Bareword",s);
5023                 }
5024
5025                 /* Look for a subroutine with this name in current package,
5026                    unless name is "Foo::", in which case Foo is a bearword
5027                    (and a package name). */
5028
5029                 if (len > 2 && !PL_madskills &&
5030                     PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5031                 {
5032                     if (ckWARN(WARN_BAREWORD)
5033                         && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5034                         Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5035                             "Bareword \"%s\" refers to nonexistent package",
5036                              PL_tokenbuf);
5037                     len -= 2;
5038                     PL_tokenbuf[len] = '\0';
5039                     gv = NULL;
5040                     gvp = 0;
5041                 }
5042                 else {
5043                     if (!gv) {
5044                         /* Mustn't actually add anything to a symbol table.
5045                            But also don't want to "initialise" any placeholder
5046                            constants that might already be there into full
5047                            blown PVGVs with attached PVCV.  */
5048                         gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5049                                                GV_NOADD_NOINIT, SVt_PVCV);
5050                     }
5051                     len = 0;
5052                 }
5053
5054                 /* if we saw a global override before, get the right name */
5055
5056                 if (gvp) {
5057                     sv = newSVpvs("CORE::GLOBAL::");
5058                     sv_catpv(sv,PL_tokenbuf);
5059                 }
5060                 else {
5061                     /* If len is 0, newSVpv does strlen(), which is correct.
5062                        If len is non-zero, then it will be the true length,
5063                        and so the scalar will be created correctly.  */
5064                     sv = newSVpv(PL_tokenbuf,len);
5065                 }
5066 #ifdef PERL_MAD
5067                 if (PL_madskills && !PL_thistoken) {
5068                     char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5069                     PL_thistoken = newSVpv(start,s - start);
5070                     PL_realtokenstart = s - SvPVX(PL_linestr);
5071                 }
5072 #endif
5073
5074                 /* Presume this is going to be a bareword of some sort. */
5075
5076                 CLINE;
5077                 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5078                 yylval.opval->op_private = OPpCONST_BARE;
5079                 /* UTF-8 package name? */
5080                 if (UTF && !IN_BYTES &&
5081                     is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5082                     SvUTF8_on(sv);
5083
5084                 /* And if "Foo::", then that's what it certainly is. */
5085
5086                 if (len)
5087                     goto safe_bareword;
5088
5089                 /* Do the explicit type check so that we don't need to force
5090                    the initialisation of the symbol table to have a real GV.
5091                    Beware - gv may not really be a PVGV, cv may not really be
5092                    a PVCV, (because of the space optimisations that gv_init
5093                    understands) But they're true if for this symbol there is
5094                    respectively a typeglob and a subroutine.
5095                 */
5096                 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5097                     /* Real typeglob, so get the real subroutine: */
5098                            ? GvCVu(gv)
5099                     /* A proxy for a subroutine in this package? */
5100                            : SvOK(gv) ? (CV *) gv : NULL)
5101                     : NULL;
5102
5103                 /* See if it's the indirect object for a list operator. */
5104
5105                 if (PL_oldoldbufptr &&
5106                     PL_oldoldbufptr < PL_bufptr &&
5107                     (PL_oldoldbufptr == PL_last_lop
5108                      || PL_oldoldbufptr == PL_last_uni) &&
5109                     /* NO SKIPSPACE BEFORE HERE! */
5110                     (PL_expect == XREF ||
5111                      ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5112                 {
5113                     bool immediate_paren = *s == '(';
5114
5115                     /* (Now we can afford to cross potential line boundary.) */
5116                     s = SKIPSPACE2(s,nextPL_nextwhite);
5117 #ifdef PERL_MAD
5118                     PL_nextwhite = nextPL_nextwhite;    /* assume no & deception */
5119 #endif
5120
5121                     /* Two barewords in a row may indicate method call. */
5122
5123                     if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5124                         (tmp = intuit_method(s, gv, cv)))
5125                         return REPORT(tmp);
5126
5127                     /* If not a declared subroutine, it's an indirect object. */
5128                     /* (But it's an indir obj regardless for sort.) */
5129                     /* Also, if "_" follows a filetest operator, it's a bareword */
5130
5131                     if (
5132                         ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5133                          ((!gv || !cv) &&
5134                         (PL_last_lop_op != OP_MAPSTART &&
5135                          PL_last_lop_op != OP_GREPSTART))))
5136                        || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5137                             && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5138                        )
5139                     {
5140                         PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5141                         goto bareword;
5142                     }
5143                 }
5144
5145                 PL_expect = XOPERATOR;
5146 #ifdef PERL_MAD
5147                 if (isSPACE(*s))
5148                     s = SKIPSPACE2(s,nextPL_nextwhite);
5149                 PL_nextwhite = nextPL_nextwhite;
5150 #else
5151                 s = skipspace(s);
5152 #endif
5153
5154                 /* Is this a word before a => operator? */
5155                 if (*s == '=' && s[1] == '>' && !pkgname) {
5156                     CLINE;
5157                     sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5158                     if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5159                       SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5160                     TERM(WORD);
5161                 }
5162
5163                 /* If followed by a paren, it's certainly a subroutine. */
5164                 if (*s == '(') {
5165                     CLINE;
5166                     if (cv) {
5167                         for (d = s + 1; SPACE_OR_TAB(*d); d++) ;
5168                         if (*d == ')' && (sv = gv_const_sv(gv))) {
5169                             s = d + 1;
5170 #ifdef PERL_MAD
5171                             if (PL_madskills) {
5172                                 char *par = SvPVX(PL_linestr) + PL_realtokenstart; 
5173                                 sv_catpvn(PL_thistoken, par, s - par);
5174                                 if (PL_nextwhite) {
5175                                     sv_free(PL_nextwhite);
5176                                     PL_nextwhite = 0;
5177                                 }
5178                             }
5179 #endif
5180                             goto its_constant;
5181                         }
5182                     }
5183 #ifdef PERL_MAD
5184                     if (PL_madskills) {
5185                         PL_nextwhite = PL_thiswhite;
5186                         PL_thiswhite = 0;
5187                     }
5188                     start_force(PL_curforce);
5189 #endif
5190                     NEXTVAL_NEXTTOKE.opval = yylval.opval;
5191                     PL_expect = XOPERATOR;
5192 #ifdef PERL_MAD
5193                     if (PL_madskills) {
5194                         PL_nextwhite = nextPL_nextwhite;
5195                         curmad('X', PL_thistoken);
5196                         PL_thistoken = newSVpvn("",0);
5197                     }
5198 #endif
5199                     force_next(WORD);
5200                     yylval.ival = 0;
5201                     TOKEN('&');
5202                 }
5203
5204                 /* If followed by var or block, call it a method (unless sub) */
5205
5206                 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5207                     PL_last_lop = PL_oldbufptr;
5208                     PL_last_lop_op = OP_METHOD;
5209                     PREBLOCK(METHOD);
5210                 }
5211
5212                 /* If followed by a bareword, see if it looks like indir obj. */
5213
5214                 if (!orig_keyword
5215                         && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5216                         && (tmp = intuit_method(s, gv, cv)))
5217                     return REPORT(tmp);
5218
5219                 /* Not a method, so call it a subroutine (if defined) */
5220
5221                 if (cv) {
5222                     if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5223                         Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5224                                 "Ambiguous use of -%s resolved as -&%s()",
5225                                 PL_tokenbuf, PL_tokenbuf);
5226                     /* Check for a constant sub */
5227                     if ((sv = gv_const_sv(gv))) {
5228                   its_constant:
5229                         SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5230                         ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5231                         yylval.opval->op_private = 0;
5232                         TOKEN(WORD);
5233                     }
5234
5235                     /* Resolve to GV now. */
5236                     if (SvTYPE(gv) != SVt_PVGV) {
5237                         gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5238                         assert (SvTYPE(gv) == SVt_PVGV);
5239                         /* cv must have been some sort of placeholder, so
5240                            now needs replacing with a real code reference.  */
5241                         cv = GvCV(gv);
5242                     }
5243
5244                     op_free(yylval.opval);
5245                     yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5246                     yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5247                     PL_last_lop = PL_oldbufptr;
5248                     PL_last_lop_op = OP_ENTERSUB;
5249                     /* Is there a prototype? */
5250                     if (
5251 #ifdef PERL_MAD
5252                         cv &&
5253 #endif
5254                         SvPOK(cv)) {
5255                         STRLEN protolen;
5256                         const char *proto = SvPV_const((SV*)cv, protolen);
5257                         if (!protolen)
5258                             TERM(FUNC0SUB);
5259                         if (*proto == '$' && proto[1] == '\0')
5260                             OPERATOR(UNIOPSUB);
5261                         while (*proto == ';')
5262                             proto++;
5263                         if (*proto == '&' && *s == '{') {
5264                             sv_setpv(PL_subname, PL_curstash ?
5265                                         "__ANON__" : "__ANON__::__ANON__");
5266                             PREBLOCK(LSTOPSUB);
5267                         }
5268                     }
5269 #ifdef PERL_MAD
5270                     {
5271                         if (PL_madskills) {
5272                             PL_nextwhite = PL_thiswhite;
5273                             PL_thiswhite = 0;
5274                         }
5275                         start_force(PL_curforce);
5276                         NEXTVAL_NEXTTOKE.opval = yylval.opval;
5277                         PL_expect = XTERM;
5278                         if (PL_madskills) {
5279                             PL_nextwhite = nextPL_nextwhite;
5280                             curmad('X', PL_thistoken);
5281                             PL_thistoken = newSVpvn("",0);
5282                         }
5283                         force_next(WORD);
5284                         TOKEN(NOAMP);
5285                     }
5286                 }
5287
5288                 /* Guess harder when madskills require "best effort". */
5289                 if (PL_madskills && (!gv || !GvCVu(gv))) {
5290                     int probable_sub = 0;
5291                     if (strchr("\"'`$@%0123456789!*+{[<", *s))
5292                         probable_sub = 1;
5293                     else if (isALPHA(*s)) {
5294                         char tmpbuf[1024];
5295                         STRLEN tmplen;
5296                         d = s;
5297                         d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5298                         if (!keyword(tmpbuf,tmplen))
5299                             probable_sub = 1;
5300                         else {
5301                             while (d < PL_bufend && isSPACE(*d))
5302                                 d++;
5303                             if (*d == '=' && d[1] == '>')
5304                                 probable_sub = 1;
5305                         }
5306                     }
5307                     if (probable_sub) {
5308                         gv = gv_fetchpv(PL_tokenbuf, TRUE, SVt_PVCV);
5309                         op_free(yylval.opval);
5310                         yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5311                         yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5312                         PL_last_lop = PL_oldbufptr;
5313                         PL_last_lop_op = OP_ENTERSUB;
5314                         PL_nextwhite = PL_thiswhite;
5315                         PL_thiswhite = 0;
5316                         start_force(PL_curforce);
5317                         NEXTVAL_NEXTTOKE.opval = yylval.opval;
5318                         PL_expect = XTERM;
5319                         PL_nextwhite = nextPL_nextwhite;
5320                         curmad('X', PL_thistoken);
5321                         PL_thistoken = newSVpvn("",0);
5322                         force_next(WORD);
5323                         TOKEN(NOAMP);
5324                     }
5325 #else
5326                     NEXTVAL_NEXTTOKE.opval = yylval.opval;
5327                     PL_expect = XTERM;
5328                     force_next(WORD);
5329                     TOKEN(NOAMP);
5330 #endif
5331                 }
5332
5333                 /* Call it a bare word */
5334
5335                 if (PL_hints & HINT_STRICT_SUBS)
5336                     yylval.opval->op_private |= OPpCONST_STRICT;
5337                 else {
5338                 bareword:
5339                     if (lastchar != '-') {
5340                         if (ckWARN(WARN_RESERVED)) {
5341                             for (d = PL_tokenbuf; *d && isLOWER(*d); d++) ;
5342                             if (!*d && !gv_stashpv(PL_tokenbuf,FALSE))
5343                                 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5344                                        PL_tokenbuf);
5345                         }
5346                     }
5347                 }
5348
5349             safe_bareword:
5350                 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5351                     && ckWARN_d(WARN_AMBIGUOUS)) {
5352                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5353                         "Operator or semicolon missing before %c%s",
5354                         lastchar, PL_tokenbuf);
5355                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5356                         "Ambiguous use of %c resolved as operator %c",
5357                         lastchar, lastchar);
5358                 }
5359                 TOKEN(WORD);
5360             }
5361
5362         case KEY___FILE__:
5363             yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5364                                         newSVpv(CopFILE(PL_curcop),0));
5365             TERM(THING);
5366
5367         case KEY___LINE__:
5368             yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5369                                     Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5370             TERM(THING);
5371
5372         case KEY___PACKAGE__:
5373             yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5374                                         (PL_curstash
5375                                          ? newSVhek(HvNAME_HEK(PL_curstash))
5376                                          : &PL_sv_undef));
5377             TERM(THING);
5378
5379         case KEY___DATA__:
5380         case KEY___END__: {
5381             GV *gv;
5382             if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5383                 const char *pname = "main";
5384                 if (PL_tokenbuf[2] == 'D')
5385                     pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5386                 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5387                                 SVt_PVIO);
5388                 GvMULTI_on(gv);
5389                 if (!GvIO(gv))
5390                     GvIOp(gv) = newIO();
5391                 IoIFP(GvIOp(gv)) = PL_rsfp;
5392 #if defined(HAS_FCNTL) && defined(F_SETFD)
5393                 {
5394                     const int fd = PerlIO_fileno(PL_rsfp);
5395                     fcntl(fd,F_SETFD,fd >= 3);
5396                 }
5397 #endif
5398                 /* Mark this internal pseudo-handle as clean */
5399                 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5400                 if (PL_preprocess)
5401                     IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5402                 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5403                     IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5404                 else
5405                     IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5406 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5407                 /* if the script was opened in binmode, we need to revert
5408                  * it to text mode for compatibility; but only iff it has CRs
5409                  * XXX this is a questionable hack at best. */
5410                 if (PL_bufend-PL_bufptr > 2
5411                     && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5412                 {
5413                     Off_t loc = 0;
5414                     if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5415                         loc = PerlIO_tell(PL_rsfp);
5416                         (void)PerlIO_seek(PL_rsfp, 0L, 0);
5417                     }
5418 #ifdef NETWARE
5419                         if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5420 #else
5421                     if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5422 #endif  /* NETWARE */
5423 #ifdef PERLIO_IS_STDIO /* really? */
5424 #  if defined(__BORLANDC__)
5425                         /* XXX see note in do_binmode() */
5426                         ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5427 #  endif
5428 #endif
5429                         if (loc > 0)
5430                             PerlIO_seek(PL_rsfp, loc, 0);
5431                     }
5432                 }
5433 #endif
5434 #ifdef PERLIO_LAYERS
5435                 if (!IN_BYTES) {
5436                     if (UTF)
5437                         PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5438                     else if (PL_encoding) {
5439                         SV *name;
5440                         dSP;
5441                         ENTER;
5442                         SAVETMPS;
5443                         PUSHMARK(sp);
5444                         EXTEND(SP, 1);
5445                         XPUSHs(PL_encoding);
5446                         PUTBACK;
5447                         call_method("name", G_SCALAR);
5448                         SPAGAIN;
5449                         name = POPs;
5450                         PUTBACK;
5451                         PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5452                                             Perl_form(aTHX_ ":encoding(%"SVf")",
5453                                                       name));
5454                         FREETMPS;
5455                         LEAVE;
5456                     }
5457                 }
5458 #endif
5459 #ifdef PERL_MAD
5460                 if (PL_madskills) {
5461                     if (PL_realtokenstart >= 0) {
5462                         char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5463                         if (!PL_endwhite)
5464                             PL_endwhite = newSVpvn("",0);
5465                         sv_catsv(PL_endwhite, PL_thiswhite);
5466                         PL_thiswhite = 0;
5467                         sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5468                         PL_realtokenstart = -1;
5469                     }
5470                     while ((s = filter_gets(PL_endwhite, PL_rsfp,
5471                                  SvCUR(PL_endwhite))) != Nullch) ;
5472                 }
5473 #endif
5474                 PL_rsfp = NULL;
5475             }
5476             goto fake_eof;
5477         }
5478
5479         case KEY_AUTOLOAD:
5480         case KEY_DESTROY:
5481         case KEY_BEGIN:
5482         case KEY_CHECK:
5483         case KEY_INIT:
5484         case KEY_END:
5485             if (PL_expect == XSTATE) {
5486                 s = PL_bufptr;
5487                 goto really_sub;
5488             }
5489             goto just_a_word;
5490
5491         case KEY_CORE:
5492             if (*s == ':' && s[1] == ':') {
5493                 s += 2;
5494                 d = s;
5495                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5496                 if (!(tmp = keyword(PL_tokenbuf, len)))
5497                     Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5498                 if (tmp < 0)
5499                     tmp = -tmp;
5500                 else if (tmp == KEY_require || tmp == KEY_do)
5501                     /* that's a way to remember we saw "CORE::" */
5502                     orig_keyword = tmp;
5503                 goto reserved_word;
5504             }
5505             goto just_a_word;
5506
5507         case KEY_abs:
5508             UNI(OP_ABS);
5509
5510         case KEY_alarm:
5511             UNI(OP_ALARM);
5512
5513         case KEY_accept:
5514             LOP(OP_ACCEPT,XTERM);
5515
5516         case KEY_and:
5517             OPERATOR(ANDOP);
5518
5519         case KEY_atan2:
5520             LOP(OP_ATAN2,XTERM);
5521
5522         case KEY_bind:
5523             LOP(OP_BIND,XTERM);
5524
5525         case KEY_binmode:
5526             LOP(OP_BINMODE,XTERM);
5527
5528         case KEY_bless:
5529             LOP(OP_BLESS,XTERM);
5530
5531         case KEY_break:
5532             FUN0(OP_BREAK);
5533
5534         case KEY_chop:
5535             UNI(OP_CHOP);
5536
5537         case KEY_continue:
5538             /* When 'use switch' is in effect, continue has a dual
5539                life as a control operator. */
5540             {
5541                 if (!FEATURE_IS_ENABLED("switch"))
5542                     PREBLOCK(CONTINUE);
5543                 else {
5544                     /* We have to disambiguate the two senses of
5545                       "continue". If the next token is a '{' then
5546                       treat it as the start of a continue block;
5547                       otherwise treat it as a control operator.
5548                      */
5549                     s = skipspace(s);
5550                     if (*s == '{')
5551             PREBLOCK(CONTINUE);
5552                     else
5553                         FUN0(OP_CONTINUE);
5554                 }
5555             }
5556
5557         case KEY_chdir:
5558             /* may use HOME */
5559             (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5560             UNI(OP_CHDIR);
5561
5562         case KEY_close:
5563             UNI(OP_CLOSE);
5564
5565         case KEY_closedir:
5566             UNI(OP_CLOSEDIR);
5567
5568         case KEY_cmp:
5569             Eop(OP_SCMP);
5570
5571         case KEY_caller:
5572             UNI(OP_CALLER);
5573
5574         case KEY_crypt:
5575 #ifdef FCRYPT
5576             if (!PL_cryptseen) {
5577                 PL_cryptseen = TRUE;
5578                 init_des();
5579             }
5580 #endif
5581             LOP(OP_CRYPT,XTERM);
5582
5583         case KEY_chmod:
5584             LOP(OP_CHMOD,XTERM);
5585
5586         case KEY_chown:
5587             LOP(OP_CHOWN,XTERM);
5588
5589         case KEY_connect:
5590             LOP(OP_CONNECT,XTERM);
5591
5592         case KEY_chr:
5593             UNI(OP_CHR);
5594
5595         case KEY_cos:
5596             UNI(OP_COS);
5597
5598         case KEY_chroot:
5599             UNI(OP_CHROOT);
5600
5601         case KEY_default:
5602             PREBLOCK(DEFAULT);
5603
5604         case KEY_do:
5605             s = SKIPSPACE1(s);
5606             if (*s == '{')
5607                 PRETERMBLOCK(DO);
5608             if (*s != '\'')
5609                 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5610             if (orig_keyword == KEY_do) {
5611                 orig_keyword = 0;
5612                 yylval.ival = 1;
5613             }
5614             else
5615                 yylval.ival = 0;
5616             OPERATOR(DO);
5617
5618         case KEY_die:
5619             PL_hints |= HINT_BLOCK_SCOPE;
5620             LOP(OP_DIE,XTERM);
5621
5622         case KEY_defined:
5623             UNI(OP_DEFINED);
5624
5625         case KEY_delete:
5626             UNI(OP_DELETE);
5627
5628         case KEY_dbmopen:
5629             gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5630             LOP(OP_DBMOPEN,XTERM);
5631
5632         case KEY_dbmclose:
5633             UNI(OP_DBMCLOSE);
5634
5635         case KEY_dump:
5636             s = force_word(s,WORD,TRUE,FALSE,FALSE);
5637             LOOPX(OP_DUMP);
5638
5639         case KEY_else:
5640             PREBLOCK(ELSE);
5641
5642         case KEY_elsif:
5643             yylval.ival = CopLINE(PL_curcop);
5644             OPERATOR(ELSIF);
5645
5646         case KEY_eq:
5647             Eop(OP_SEQ);
5648
5649         case KEY_exists:
5650             UNI(OP_EXISTS);
5651         
5652         case KEY_exit:
5653             if (PL_madskills)
5654                 UNI(OP_INT);
5655             UNI(OP_EXIT);
5656
5657         case KEY_eval:
5658             s = SKIPSPACE1(s);
5659             PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5660             UNIBRACK(OP_ENTEREVAL);
5661
5662         case KEY_eof:
5663             UNI(OP_EOF);
5664
5665         case KEY_err:
5666             OPERATOR(DOROP);
5667
5668         case KEY_exp:
5669             UNI(OP_EXP);
5670
5671         case KEY_each:
5672             UNI(OP_EACH);
5673
5674         case KEY_exec:
5675             set_csh();
5676             LOP(OP_EXEC,XREF);
5677
5678         case KEY_endhostent:
5679             FUN0(OP_EHOSTENT);
5680
5681         case KEY_endnetent:
5682             FUN0(OP_ENETENT);
5683
5684         case KEY_endservent:
5685             FUN0(OP_ESERVENT);
5686
5687         case KEY_endprotoent:
5688             FUN0(OP_EPROTOENT);
5689
5690         case KEY_endpwent:
5691             FUN0(OP_EPWENT);
5692
5693         case KEY_endgrent:
5694             FUN0(OP_EGRENT);
5695
5696         case KEY_for:
5697         case KEY_foreach:
5698             yylval.ival = CopLINE(PL_curcop);
5699             s = SKIPSPACE1(s);
5700             if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5701                 char *p = s;
5702 #ifdef PERL_MAD
5703                 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5704 #endif
5705
5706                 if ((PL_bufend - p) >= 3 &&
5707                     strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5708                     p += 2;
5709                 else if ((PL_bufend - p) >= 4 &&
5710                     strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5711                     p += 3;
5712                 p = PEEKSPACE(p);
5713                 if (isIDFIRST_lazy_if(p,UTF)) {
5714                     p = scan_ident(p, PL_bufend,
5715                         PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5716                     p = PEEKSPACE(p);
5717                 }
5718                 if (*p != '$')
5719                     Perl_croak(aTHX_ "Missing $ on loop variable");
5720 #ifdef PERL_MAD
5721                 s = SvPVX(PL_linestr) + soff;
5722 #endif
5723             }
5724             OPERATOR(FOR);
5725
5726         case KEY_formline:
5727             LOP(OP_FORMLINE,XTERM);
5728
5729         case KEY_fork:
5730             FUN0(OP_FORK);
5731
5732         case KEY_fcntl:
5733             LOP(OP_FCNTL,XTERM);
5734
5735         case KEY_fileno:
5736             UNI(OP_FILENO);
5737
5738         case KEY_flock:
5739             LOP(OP_FLOCK,XTERM);
5740
5741         case KEY_gt:
5742             Rop(OP_SGT);
5743
5744         case KEY_ge:
5745             Rop(OP_SGE);
5746
5747         case KEY_grep:
5748             LOP(OP_GREPSTART, XREF);
5749
5750         case KEY_goto:
5751             s = force_word(s,WORD,TRUE,FALSE,FALSE);
5752             LOOPX(OP_GOTO);
5753
5754         case KEY_gmtime:
5755             UNI(OP_GMTIME);
5756
5757         case KEY_getc:
5758             UNIDOR(OP_GETC);
5759
5760         case KEY_getppid:
5761             FUN0(OP_GETPPID);
5762
5763         case KEY_getpgrp:
5764             UNI(OP_GETPGRP);
5765
5766         case KEY_getpriority:
5767             LOP(OP_GETPRIORITY,XTERM);
5768
5769         case KEY_getprotobyname:
5770             UNI(OP_GPBYNAME);
5771
5772         case KEY_getprotobynumber:
5773             LOP(OP_GPBYNUMBER,XTERM);
5774
5775         case KEY_getprotoent:
5776             FUN0(OP_GPROTOENT);
5777
5778         case KEY_getpwent:
5779             FUN0(OP_GPWENT);
5780
5781         case KEY_getpwnam:
5782             UNI(OP_GPWNAM);
5783
5784         case KEY_getpwuid:
5785             UNI(OP_GPWUID);
5786
5787         case KEY_getpeername:
5788             UNI(OP_GETPEERNAME);
5789
5790         case KEY_gethostbyname:
5791             UNI(OP_GHBYNAME);
5792
5793         case KEY_gethostbyaddr:
5794             LOP(OP_GHBYADDR,XTERM);
5795
5796         case KEY_gethostent:
5797             FUN0(OP_GHOSTENT);
5798
5799         case KEY_getnetbyname:
5800             UNI(OP_GNBYNAME);
5801
5802         case KEY_getnetbyaddr:
5803             LOP(OP_GNBYADDR,XTERM);
5804
5805         case KEY_getnetent:
5806             FUN0(OP_GNETENT);
5807
5808         case KEY_getservbyname:
5809             LOP(OP_GSBYNAME,XTERM);
5810
5811         case KEY_getservbyport:
5812             LOP(OP_GSBYPORT,XTERM);
5813
5814         case KEY_getservent:
5815             FUN0(OP_GSERVENT);
5816
5817         case KEY_getsockname:
5818             UNI(OP_GETSOCKNAME);
5819
5820         case KEY_getsockopt:
5821             LOP(OP_GSOCKOPT,XTERM);
5822
5823         case KEY_getgrent:
5824             FUN0(OP_GGRENT);
5825
5826         case KEY_getgrnam:
5827             UNI(OP_GGRNAM);
5828
5829         case KEY_getgrgid:
5830             UNI(OP_GGRGID);
5831
5832         case KEY_getlogin:
5833             FUN0(OP_GETLOGIN);
5834
5835         case KEY_given:
5836             yylval.ival = CopLINE(PL_curcop);
5837             OPERATOR(GIVEN);
5838
5839         case KEY_glob:
5840             set_csh();
5841             LOP(OP_GLOB,XTERM);
5842
5843         case KEY_hex:
5844             UNI(OP_HEX);
5845
5846         case KEY_if:
5847             yylval.ival = CopLINE(PL_curcop);
5848             OPERATOR(IF);
5849
5850         case KEY_index:
5851             LOP(OP_INDEX,XTERM);
5852
5853         case KEY_int:
5854             UNI(OP_INT);
5855
5856         case KEY_ioctl:
5857             LOP(OP_IOCTL,XTERM);
5858
5859         case KEY_join:
5860             LOP(OP_JOIN,XTERM);
5861
5862         case KEY_keys:
5863             UNI(OP_KEYS);
5864
5865         case KEY_kill:
5866             LOP(OP_KILL,XTERM);
5867
5868         case KEY_last:
5869             s = force_word(s,WORD,TRUE,FALSE,FALSE);
5870             LOOPX(OP_LAST);
5871         
5872         case KEY_lc:
5873             UNI(OP_LC);
5874
5875         case KEY_lcfirst:
5876             UNI(OP_LCFIRST);
5877
5878         case KEY_local:
5879             yylval.ival = 0;
5880             OPERATOR(LOCAL);
5881
5882         case KEY_length:
5883             UNI(OP_LENGTH);
5884
5885         case KEY_lt:
5886             Rop(OP_SLT);
5887
5888         case KEY_le:
5889             Rop(OP_SLE);
5890
5891         case KEY_localtime:
5892             UNI(OP_LOCALTIME);
5893
5894         case KEY_log:
5895             UNI(OP_LOG);
5896
5897         case KEY_link:
5898             LOP(OP_LINK,XTERM);
5899
5900         case KEY_listen:
5901             LOP(OP_LISTEN,XTERM);
5902
5903         case KEY_lock:
5904             UNI(OP_LOCK);
5905
5906         case KEY_lstat:
5907             UNI(OP_LSTAT);
5908
5909         case KEY_m:
5910             s = scan_pat(s,OP_MATCH);
5911             TERM(sublex_start());
5912
5913         case KEY_map:
5914             LOP(OP_MAPSTART, XREF);
5915
5916         case KEY_mkdir:
5917             LOP(OP_MKDIR,XTERM);
5918
5919         case KEY_msgctl:
5920             LOP(OP_MSGCTL,XTERM);
5921
5922         case KEY_msgget:
5923             LOP(OP_MSGGET,XTERM);
5924
5925         case KEY_msgrcv:
5926             LOP(OP_MSGRCV,XTERM);
5927
5928         case KEY_msgsnd:
5929             LOP(OP_MSGSND,XTERM);
5930
5931         case KEY_our:
5932         case KEY_my:
5933             PL_in_my = tmp;
5934             s = SKIPSPACE1(s);
5935             if (isIDFIRST_lazy_if(s,UTF)) {
5936 #ifdef PERL_MAD
5937                 char* start = s;
5938 #endif
5939                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
5940                 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
5941                     goto really_sub;
5942                 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
5943                 if (!PL_in_my_stash) {
5944                     char tmpbuf[1024];
5945                     PL_bufptr = s;
5946                     sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
5947                     yyerror(tmpbuf);
5948                 }
5949 #ifdef PERL_MAD
5950                 if (PL_madskills) {     /* just add type to declarator token */
5951                     sv_catsv(PL_thistoken, PL_nextwhite);
5952                     PL_nextwhite = 0;
5953                     sv_catpvn(PL_thistoken, start, s - start);
5954                 }
5955 #endif
5956             }
5957             yylval.ival = 1;
5958             OPERATOR(MY);
5959
5960         case KEY_next:
5961             s = force_word(s,WORD,TRUE,FALSE,FALSE);
5962             LOOPX(OP_NEXT);
5963
5964         case KEY_ne:
5965             Eop(OP_SNE);
5966
5967         case KEY_no:
5968             s = tokenize_use(0, s);
5969             OPERATOR(USE);
5970
5971         case KEY_not:
5972             if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
5973                 FUN1(OP_NOT);
5974             else
5975                 OPERATOR(NOTOP);
5976
5977         case KEY_open:
5978             s = SKIPSPACE1(s);
5979             if (isIDFIRST_lazy_if(s,UTF)) {
5980                 const char *t;
5981                 for (d = s; isALNUM_lazy_if(d,UTF); d++) ;
5982                 for (t=d; *t && isSPACE(*t); t++) ;
5983                 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
5984                     /* [perl #16184] */
5985                     && !(t[0] == '=' && t[1] == '>')
5986                 ) {
5987                     int parms_len = (int)(d-s);
5988                     Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
5989                            "Precedence problem: open %.*s should be open(%.*s)",
5990                             parms_len, s, parms_len, s);
5991                 }
5992             }
5993             LOP(OP_OPEN,XTERM);
5994
5995         case KEY_or:
5996             yylval.ival = OP_OR;
5997             OPERATOR(OROP);
5998
5999         case KEY_ord:
6000             UNI(OP_ORD);
6001
6002         case KEY_oct:
6003             UNI(OP_OCT);
6004
6005         case KEY_opendir:
6006             LOP(OP_OPEN_DIR,XTERM);
6007
6008         case KEY_print:
6009             checkcomma(s,PL_tokenbuf,"filehandle");
6010             LOP(OP_PRINT,XREF);
6011
6012         case KEY_printf:
6013             checkcomma(s,PL_tokenbuf,"filehandle");
6014             LOP(OP_PRTF,XREF);
6015
6016         case KEY_prototype:
6017             UNI(OP_PROTOTYPE);
6018
6019         case KEY_push:
6020             LOP(OP_PUSH,XTERM);
6021
6022         case KEY_pop:
6023             UNIDOR(OP_POP);
6024
6025         case KEY_pos:
6026             UNIDOR(OP_POS);
6027         
6028         case KEY_pack:
6029             LOP(OP_PACK,XTERM);
6030
6031         case KEY_package:
6032             s = force_word(s,WORD,FALSE,TRUE,FALSE);
6033             OPERATOR(PACKAGE);
6034
6035         case KEY_pipe:
6036             LOP(OP_PIPE_OP,XTERM);
6037
6038         case KEY_q:
6039             s = scan_str(s,!!PL_madskills,FALSE);
6040             if (!s)
6041                 missingterm((char*)0);
6042             yylval.ival = OP_CONST;
6043             TERM(sublex_start());
6044
6045         case KEY_quotemeta:
6046             UNI(OP_QUOTEMETA);
6047
6048         case KEY_qw:
6049             s = scan_str(s,!!PL_madskills,FALSE);
6050             if (!s)
6051                 missingterm((char*)0);
6052             PL_expect = XOPERATOR;
6053             force_next(')');
6054             if (SvCUR(PL_lex_stuff)) {
6055                 OP *words = NULL;
6056                 int warned = 0;
6057                 d = SvPV_force(PL_lex_stuff, len);
6058                 while (len) {
6059                     SV *sv;
6060                     for (; isSPACE(*d) && len; --len, ++d) ;
6061                     if (len) {
6062                         const char *b = d;
6063                         if (!warned && ckWARN(WARN_QW)) {
6064                             for (; !isSPACE(*d) && len; --len, ++d) {
6065                                 if (*d == ',') {
6066                                     Perl_warner(aTHX_ packWARN(WARN_QW),
6067                                         "Possible attempt to separate words with commas");
6068                                     ++warned;
6069                                 }
6070                                 else if (*d == '#') {
6071                                     Perl_warner(aTHX_ packWARN(WARN_QW),
6072                                         "Possible attempt to put comments in qw() list");
6073                                     ++warned;
6074                                 }
6075                             }
6076                         }
6077                         else {
6078                             for (; !isSPACE(*d) && len; --len, ++d) ;
6079                         }
6080                         sv = newSVpvn(b, d-b);
6081                         if (DO_UTF8(PL_lex_stuff))
6082                             SvUTF8_on(sv);
6083                         words = append_elem(OP_LIST, words,
6084                                             newSVOP(OP_CONST, 0, tokeq(sv)));
6085                     }
6086                 }
6087                 if (words) {
6088                     start_force(PL_curforce);
6089                     NEXTVAL_NEXTTOKE.opval = words;
6090                     force_next(THING);
6091                 }
6092             }
6093             if (PL_lex_stuff) {
6094                 SvREFCNT_dec(PL_lex_stuff);
6095                 PL_lex_stuff = NULL;
6096             }
6097             PL_expect = XTERM;
6098             TOKEN('(');
6099
6100         case KEY_qq:
6101             s = scan_str(s,!!PL_madskills,FALSE);
6102             if (!s)
6103                 missingterm((char*)0);
6104             yylval.ival = OP_STRINGIFY;
6105             if (SvIVX(PL_lex_stuff) == '\'')
6106                 SvIV_set(PL_lex_stuff, 0);      /* qq'$foo' should intepolate */
6107             TERM(sublex_start());
6108
6109         case KEY_qr:
6110             s = scan_pat(s,OP_QR);
6111             TERM(sublex_start());
6112
6113         case KEY_qx:
6114             s = scan_str(s,!!PL_madskills,FALSE);
6115             if (!s)
6116                 missingterm((char*)0);
6117             yylval.ival = OP_BACKTICK;
6118             set_csh();
6119             TERM(sublex_start());
6120
6121         case KEY_return:
6122             OLDLOP(OP_RETURN);
6123
6124         case KEY_require:
6125             s = SKIPSPACE1(s);
6126             if (isDIGIT(*s)) {
6127                 s = force_version(s, FALSE);
6128             }
6129             else if (*s != 'v' || !isDIGIT(s[1])
6130                     || (s = force_version(s, TRUE), *s == 'v'))
6131             {
6132                 *PL_tokenbuf = '\0';
6133                 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6134                 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6135                     gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), TRUE);
6136                 else if (*s == '<')
6137                     yyerror("<> should be quotes");
6138             }
6139             if (orig_keyword == KEY_require) {
6140                 orig_keyword = 0;
6141                 yylval.ival = 1;
6142             }
6143             else 
6144                 yylval.ival = 0;
6145             PL_expect = XTERM;
6146             PL_bufptr = s;
6147             PL_last_uni = PL_oldbufptr;
6148             PL_last_lop_op = OP_REQUIRE;
6149             s = skipspace(s);
6150             return REPORT( (int)REQUIRE );
6151
6152         case KEY_reset:
6153             UNI(OP_RESET);
6154
6155         case KEY_redo:
6156             s = force_word(s,WORD,TRUE,FALSE,FALSE);
6157             LOOPX(OP_REDO);
6158
6159         case KEY_rename:
6160             LOP(OP_RENAME,XTERM);
6161
6162         case KEY_rand:
6163             UNI(OP_RAND);
6164
6165         case KEY_rmdir:
6166             UNI(OP_RMDIR);
6167
6168         case KEY_rindex:
6169             LOP(OP_RINDEX,XTERM);
6170
6171         case KEY_read:
6172             LOP(OP_READ,XTERM);
6173
6174         case KEY_readdir:
6175             UNI(OP_READDIR);
6176
6177         case KEY_readline:
6178             set_csh();
6179             UNIDOR(OP_READLINE);
6180
6181         case KEY_readpipe:
6182             set_csh();
6183             UNI(OP_BACKTICK);
6184
6185         case KEY_rewinddir:
6186             UNI(OP_REWINDDIR);
6187
6188         case KEY_recv:
6189             LOP(OP_RECV,XTERM);
6190
6191         case KEY_reverse:
6192             LOP(OP_REVERSE,XTERM);
6193
6194         case KEY_readlink:
6195             UNIDOR(OP_READLINK);
6196
6197         case KEY_ref:
6198             UNI(OP_REF);
6199
6200         case KEY_s:
6201             s = scan_subst(s);
6202             if (yylval.opval)
6203                 TERM(sublex_start());
6204             else
6205                 TOKEN(1);       /* force error */
6206
6207         case KEY_say:
6208             checkcomma(s,PL_tokenbuf,"filehandle");
6209             LOP(OP_SAY,XREF);
6210
6211         case KEY_chomp:
6212             UNI(OP_CHOMP);
6213         
6214         case KEY_scalar:
6215             UNI(OP_SCALAR);
6216
6217         case KEY_select:
6218             LOP(OP_SELECT,XTERM);
6219
6220         case KEY_seek:
6221             LOP(OP_SEEK,XTERM);
6222
6223         case KEY_semctl:
6224             LOP(OP_SEMCTL,XTERM);
6225
6226         case KEY_semget:
6227             LOP(OP_SEMGET,XTERM);
6228
6229         case KEY_semop:
6230             LOP(OP_SEMOP,XTERM);
6231
6232         case KEY_send:
6233             LOP(OP_SEND,XTERM);
6234
6235         case KEY_setpgrp:
6236             LOP(OP_SETPGRP,XTERM);
6237
6238         case KEY_setpriority:
6239             LOP(OP_SETPRIORITY,XTERM);
6240
6241         case KEY_sethostent:
6242             UNI(OP_SHOSTENT);
6243
6244         case KEY_setnetent:
6245             UNI(OP_SNETENT);
6246
6247         case KEY_setservent:
6248             UNI(OP_SSERVENT);
6249
6250         case KEY_setprotoent:
6251             UNI(OP_SPROTOENT);
6252
6253         case KEY_setpwent:
6254             FUN0(OP_SPWENT);
6255
6256         case KEY_setgrent:
6257             FUN0(OP_SGRENT);
6258
6259         case KEY_seekdir:
6260             LOP(OP_SEEKDIR,XTERM);
6261
6262         case KEY_setsockopt:
6263             LOP(OP_SSOCKOPT,XTERM);
6264
6265         case KEY_shift:
6266             UNIDOR(OP_SHIFT);
6267
6268         case KEY_shmctl:
6269             LOP(OP_SHMCTL,XTERM);
6270
6271         case KEY_shmget:
6272             LOP(OP_SHMGET,XTERM);
6273
6274         case KEY_shmread:
6275             LOP(OP_SHMREAD,XTERM);
6276
6277         case KEY_shmwrite:
6278             LOP(OP_SHMWRITE,XTERM);
6279
6280         case KEY_shutdown:
6281             LOP(OP_SHUTDOWN,XTERM);
6282
6283         case KEY_sin:
6284             UNI(OP_SIN);
6285
6286         case KEY_sleep:
6287             UNI(OP_SLEEP);
6288
6289         case KEY_socket:
6290             LOP(OP_SOCKET,XTERM);
6291
6292         case KEY_socketpair:
6293             LOP(OP_SOCKPAIR,XTERM);
6294
6295         case KEY_sort:
6296             checkcomma(s,PL_tokenbuf,"subroutine name");
6297             s = SKIPSPACE1(s);
6298             if (*s == ';' || *s == ')')         /* probably a close */
6299                 Perl_croak(aTHX_ "sort is now a reserved word");
6300             PL_expect = XTERM;
6301             s = force_word(s,WORD,TRUE,TRUE,FALSE);
6302             LOP(OP_SORT,XREF);
6303
6304         case KEY_split:
6305             LOP(OP_SPLIT,XTERM);
6306
6307         case KEY_sprintf:
6308             LOP(OP_SPRINTF,XTERM);
6309
6310         case KEY_splice:
6311             LOP(OP_SPLICE,XTERM);
6312
6313         case KEY_sqrt:
6314             UNI(OP_SQRT);
6315
6316         case KEY_srand:
6317             UNI(OP_SRAND);
6318
6319         case KEY_stat:
6320             UNI(OP_STAT);
6321
6322         case KEY_study:
6323             UNI(OP_STUDY);
6324
6325         case KEY_substr:
6326             LOP(OP_SUBSTR,XTERM);
6327
6328         case KEY_format:
6329         case KEY_sub:
6330           really_sub:
6331             {
6332                 char tmpbuf[sizeof PL_tokenbuf];
6333                 SSize_t tboffset = 0;
6334                 expectation attrful;
6335                 bool have_name, have_proto, bad_proto;
6336                 const int key = tmp;
6337
6338 #ifdef PERL_MAD
6339                 SV *tmpwhite = 0;
6340
6341                 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6342                 SV *subtoken = newSVpvn(tstart, s - tstart);
6343                 PL_thistoken = 0;
6344
6345                 d = s;
6346                 s = SKIPSPACE2(s,tmpwhite);
6347 #else
6348                 s = skipspace(s);
6349 #endif
6350
6351                 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6352                     (*s == ':' && s[1] == ':'))
6353                 {
6354 #ifdef PERL_MAD
6355                     SV *nametoke;
6356 #endif
6357
6358                     PL_expect = XBLOCK;
6359                     attrful = XATTRBLOCK;
6360                     /* remember buffer pos'n for later force_word */
6361                     tboffset = s - PL_oldbufptr;
6362                     d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6363 #ifdef PERL_MAD
6364                     if (PL_madskills)
6365                         nametoke = newSVpvn(s, d - s);
6366 #endif
6367                     if (strchr(tmpbuf, ':'))
6368                         sv_setpv(PL_subname, tmpbuf);
6369                     else {
6370                         sv_setsv(PL_subname,PL_curstname);
6371                         sv_catpvs(PL_subname,"::");
6372                         sv_catpvn(PL_subname,tmpbuf,len);
6373                     }
6374                     have_name = TRUE;
6375
6376 #ifdef PERL_MAD
6377
6378                     start_force(0);
6379                     CURMAD('X', nametoke);
6380                     CURMAD('_', tmpwhite);
6381                     (void) force_word(PL_oldbufptr + tboffset, WORD,
6382                                       FALSE, TRUE, TRUE);
6383
6384                     s = SKIPSPACE2(d,tmpwhite);
6385 #else
6386                     s = skipspace(d);
6387 #endif
6388                 }
6389                 else {
6390                     if (key == KEY_my)
6391                         Perl_croak(aTHX_ "Missing name in \"my sub\"");
6392                     PL_expect = XTERMBLOCK;
6393                     attrful = XATTRTERM;
6394                     sv_setpvn(PL_subname,"?",1);
6395                     have_name = FALSE;
6396                 }
6397
6398                 if (key == KEY_format) {
6399                     if (*s == '=')
6400                         PL_lex_formbrack = PL_lex_brackets + 1;
6401 #ifdef PERL_MAD
6402                     PL_thistoken = subtoken;
6403                     s = d;
6404 #else
6405                     if (have_name)
6406                         (void) force_word(PL_oldbufptr + tboffset, WORD,
6407                                           FALSE, TRUE, TRUE);
6408 #endif
6409                     OPERATOR(FORMAT);
6410                 }
6411
6412                 /* Look for a prototype */
6413                 if (*s == '(') {
6414                     char *p;
6415
6416                     s = scan_str(s,!!PL_madskills,FALSE);
6417                     if (!s)
6418                         Perl_croak(aTHX_ "Prototype not terminated");
6419                     /* strip spaces and check for bad characters */
6420                     d = SvPVX(PL_lex_stuff);
6421                     tmp = 0;
6422                     bad_proto = FALSE;
6423                     for (p = d; *p; ++p) {
6424                         if (!isSPACE(*p)) {
6425                             d[tmp++] = *p;
6426                             if (!strchr("$@%*;[]&\\", *p))
6427                                 bad_proto = TRUE;
6428                         }
6429                     }
6430                     d[tmp] = '\0';
6431                     if (bad_proto && ckWARN(WARN_SYNTAX))
6432                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6433                                     "Illegal character in prototype for %"SVf" : %s",
6434                                     PL_subname, d);
6435                     SvCUR_set(PL_lex_stuff, tmp);
6436                     have_proto = TRUE;
6437
6438 #ifdef PERL_MAD
6439                     start_force(0);
6440                     CURMAD('q', PL_thisopen);
6441                     CURMAD('_', tmpwhite);
6442                     CURMAD('=', PL_thisstuff);
6443                     CURMAD('Q', PL_thisclose);
6444                     NEXTVAL_NEXTTOKE.opval =
6445                         (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6446                     PL_lex_stuff = Nullsv;
6447                     force_next(THING);
6448
6449                     s = SKIPSPACE2(s,tmpwhite);
6450 #else
6451                     s = skipspace(s);
6452 #endif
6453                 }
6454                 else
6455                     have_proto = FALSE;
6456
6457                 if (*s == ':' && s[1] != ':')
6458                     PL_expect = attrful;
6459                 else if (*s != '{' && key == KEY_sub) {
6460                     if (!have_name)
6461                         Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6462                     else if (*s != ';')
6463                         Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, PL_subname);
6464                 }
6465
6466 #ifdef PERL_MAD
6467                 start_force(0);
6468                 if (tmpwhite) {
6469                     if (PL_madskills)
6470                         curmad('^', newSVpvn("",0));
6471                     CURMAD('_', tmpwhite);
6472                 }
6473                 force_next(0);
6474
6475                 PL_thistoken = subtoken;
6476 #else
6477                 if (have_proto) {
6478                     NEXTVAL_NEXTTOKE.opval =
6479                         (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6480                     PL_lex_stuff = NULL;
6481                     force_next(THING);
6482                 }
6483 #endif
6484                 if (!have_name) {
6485                     sv_setpv(PL_subname,
6486                         PL_curstash ? "__ANON__" : "__ANON__::__ANON__");
6487                     TOKEN(ANONSUB);
6488                 }
6489 #ifndef PERL_MAD
6490                 (void) force_word(PL_oldbufptr + tboffset, WORD,
6491                                   FALSE, TRUE, TRUE);
6492 #endif
6493                 if (key == KEY_my)
6494                     TOKEN(MYSUB);
6495                 TOKEN(SUB);
6496             }
6497
6498         case KEY_system:
6499             set_csh();
6500             LOP(OP_SYSTEM,XREF);
6501
6502         case KEY_symlink:
6503             LOP(OP_SYMLINK,XTERM);
6504
6505         case KEY_syscall:
6506             LOP(OP_SYSCALL,XTERM);
6507
6508         case KEY_sysopen:
6509             LOP(OP_SYSOPEN,XTERM);
6510
6511         case KEY_sysseek:
6512             LOP(OP_SYSSEEK,XTERM);
6513
6514         case KEY_sysread:
6515             LOP(OP_SYSREAD,XTERM);
6516
6517         case KEY_syswrite:
6518             LOP(OP_SYSWRITE,XTERM);
6519
6520         case KEY_tr:
6521             s = scan_trans(s);
6522             TERM(sublex_start());
6523
6524         case KEY_tell:
6525             UNI(OP_TELL);
6526
6527         case KEY_telldir:
6528             UNI(OP_TELLDIR);
6529
6530         case KEY_tie:
6531             LOP(OP_TIE,XTERM);
6532
6533         case KEY_tied:
6534             UNI(OP_TIED);
6535
6536         case KEY_time:
6537             FUN0(OP_TIME);
6538
6539         case KEY_times:
6540             FUN0(OP_TMS);
6541
6542         case KEY_truncate:
6543             LOP(OP_TRUNCATE,XTERM);
6544
6545         case KEY_uc:
6546             UNI(OP_UC);
6547
6548         case KEY_ucfirst:
6549             UNI(OP_UCFIRST);
6550
6551         case KEY_untie:
6552             UNI(OP_UNTIE);
6553
6554         case KEY_until:
6555             yylval.ival = CopLINE(PL_curcop);
6556             OPERATOR(UNTIL);
6557
6558         case KEY_unless:
6559             yylval.ival = CopLINE(PL_curcop);
6560             OPERATOR(UNLESS);
6561
6562         case KEY_unlink:
6563             LOP(OP_UNLINK,XTERM);
6564
6565         case KEY_undef:
6566             UNIDOR(OP_UNDEF);
6567
6568         case KEY_unpack:
6569             LOP(OP_UNPACK,XTERM);
6570
6571         case KEY_utime:
6572             LOP(OP_UTIME,XTERM);
6573
6574         case KEY_umask:
6575             UNIDOR(OP_UMASK);
6576
6577         case KEY_unshift:
6578             LOP(OP_UNSHIFT,XTERM);
6579
6580         case KEY_use:
6581             s = tokenize_use(1, s);
6582             OPERATOR(USE);
6583
6584         case KEY_values:
6585             UNI(OP_VALUES);
6586
6587         case KEY_vec:
6588             LOP(OP_VEC,XTERM);
6589
6590         case KEY_when:
6591             yylval.ival = CopLINE(PL_curcop);
6592             OPERATOR(WHEN);
6593
6594         case KEY_while:
6595             yylval.ival = CopLINE(PL_curcop);
6596             OPERATOR(WHILE);
6597
6598         case KEY_warn:
6599             PL_hints |= HINT_BLOCK_SCOPE;
6600             LOP(OP_WARN,XTERM);
6601
6602         case KEY_wait:
6603             FUN0(OP_WAIT);
6604
6605         case KEY_waitpid:
6606             LOP(OP_WAITPID,XTERM);
6607
6608         case KEY_wantarray:
6609             FUN0(OP_WANTARRAY);
6610
6611         case KEY_write:
6612 #ifdef EBCDIC
6613         {
6614             char ctl_l[2];
6615             ctl_l[0] = toCTRL('L');
6616             ctl_l[1] = '\0';
6617             gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6618         }
6619 #else
6620             /* Make sure $^L is defined */
6621             gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6622 #endif
6623             UNI(OP_ENTERWRITE);
6624
6625         case KEY_x:
6626             if (PL_expect == XOPERATOR)
6627                 Mop(OP_REPEAT);
6628             check_uni();
6629             goto just_a_word;
6630
6631         case KEY_xor:
6632             yylval.ival = OP_XOR;
6633             OPERATOR(OROP);
6634
6635         case KEY_y:
6636             s = scan_trans(s);
6637             TERM(sublex_start());
6638         }
6639     }}
6640 }
6641 #ifdef __SC__
6642 #pragma segment Main
6643 #endif
6644
6645 static int
6646 S_pending_ident(pTHX)
6647 {
6648     dVAR;
6649     register char *d;
6650     register I32 tmp = 0;
6651     /* pit holds the identifier we read and pending_ident is reset */
6652     char pit = PL_pending_ident;
6653     PL_pending_ident = 0;
6654
6655     /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6656     DEBUG_T({ PerlIO_printf(Perl_debug_log,
6657           "### Pending identifier '%s'\n", PL_tokenbuf); });
6658
6659     /* if we're in a my(), we can't allow dynamics here.
6660        $foo'bar has already been turned into $foo::bar, so
6661        just check for colons.
6662
6663        if it's a legal name, the OP is a PADANY.
6664     */
6665     if (PL_in_my) {
6666         if (PL_in_my == KEY_our) {      /* "our" is merely analogous to "my" */
6667             if (strchr(PL_tokenbuf,':'))
6668                 yyerror(Perl_form(aTHX_ "No package name allowed for "
6669                                   "variable %s in \"our\"",
6670                                   PL_tokenbuf));
6671             tmp = allocmy(PL_tokenbuf);
6672         }
6673         else {
6674             if (strchr(PL_tokenbuf,':'))
6675                 yyerror(Perl_form(aTHX_ PL_no_myglob,PL_tokenbuf));
6676
6677             yylval.opval = newOP(OP_PADANY, 0);
6678             yylval.opval->op_targ = allocmy(PL_tokenbuf);
6679             return PRIVATEREF;
6680         }
6681     }
6682
6683     /*
6684        build the ops for accesses to a my() variable.
6685
6686        Deny my($a) or my($b) in a sort block, *if* $a or $b is
6687        then used in a comparison.  This catches most, but not
6688        all cases.  For instance, it catches
6689            sort { my($a); $a <=> $b }
6690        but not
6691            sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6692        (although why you'd do that is anyone's guess).
6693     */
6694
6695     if (!strchr(PL_tokenbuf,':')) {
6696         if (!PL_in_my)
6697             tmp = pad_findmy(PL_tokenbuf);
6698         if (tmp != NOT_IN_PAD) {
6699             /* might be an "our" variable" */
6700             if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6701                 /* build ops for a bareword */
6702                 HV *  const stash = PAD_COMPNAME_OURSTASH(tmp);
6703                 HEK * const stashname = HvNAME_HEK(stash);
6704                 SV *  const sym = newSVhek(stashname);
6705                 sv_catpvs(sym, "::");
6706                 sv_catpv(sym, PL_tokenbuf+1);
6707                 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6708                 yylval.opval->op_private = OPpCONST_ENTERED;
6709                 gv_fetchsv(sym,
6710                     (PL_in_eval
6711                         ? (GV_ADDMULTI | GV_ADDINEVAL)
6712                         : GV_ADDMULTI
6713                     ),
6714                     ((PL_tokenbuf[0] == '$') ? SVt_PV
6715                      : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6716                      : SVt_PVHV));
6717                 return WORD;
6718             }
6719
6720             /* if it's a sort block and they're naming $a or $b */
6721             if (PL_last_lop_op == OP_SORT &&
6722                 PL_tokenbuf[0] == '$' &&
6723                 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6724                 && !PL_tokenbuf[2])
6725             {
6726                 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6727                      d < PL_bufend && *d != '\n';
6728                      d++)
6729                 {
6730                     if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6731                         Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6732                               PL_tokenbuf);
6733                     }
6734                 }
6735             }
6736
6737             yylval.opval = newOP(OP_PADANY, 0);
6738             yylval.opval->op_targ = tmp;
6739             return PRIVATEREF;
6740         }
6741     }
6742
6743     /*
6744        Whine if they've said @foo in a doublequoted string,
6745        and @foo isn't a variable we can find in the symbol
6746        table.
6747     */
6748     if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6749         GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6750         if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6751              && ckWARN(WARN_AMBIGUOUS))
6752         {
6753             /* Downgraded from fatal to warning 20000522 mjd */
6754             Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6755                         "Possible unintended interpolation of %s in string",
6756                          PL_tokenbuf);
6757         }
6758     }
6759
6760     /* build ops for a bareword */
6761     yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
6762     yylval.opval->op_private = OPpCONST_ENTERED;
6763     gv_fetchpv(
6764             PL_tokenbuf+1,
6765             /* If the identifier refers to a stash, don't autovivify it.
6766              * Change 24660 had the side effect of causing symbol table
6767              * hashes to always be defined, even if they were freshly
6768              * created and the only reference in the entire program was
6769              * the single statement with the defined %foo::bar:: test.
6770              * It appears that all code in the wild doing this actually
6771              * wants to know whether sub-packages have been loaded, so
6772              * by avoiding auto-vivifying symbol tables, we ensure that
6773              * defined %foo::bar:: continues to be false, and the existing
6774              * tests still give the expected answers, even though what
6775              * they're actually testing has now changed subtly.
6776              */
6777             (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
6778              ? 0
6779              : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
6780             ((PL_tokenbuf[0] == '$') ? SVt_PV
6781              : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6782              : SVt_PVHV));
6783     return WORD;
6784 }
6785
6786 /*
6787  *  The following code was generated by perl_keyword.pl.
6788  */
6789
6790 I32
6791 Perl_keyword (pTHX_ const char *name, I32 len)
6792 {
6793   dVAR;
6794   switch (len)
6795   {
6796     case 1: /* 5 tokens of length 1 */
6797       switch (name[0])
6798       {
6799         case 'm':
6800           {                                       /* m          */
6801             return KEY_m;
6802           }
6803
6804         case 'q':
6805           {                                       /* q          */
6806             return KEY_q;
6807           }
6808
6809         case 's':
6810           {                                       /* s          */
6811             return KEY_s;
6812           }
6813
6814         case 'x':
6815           {                                       /* x          */
6816             return -KEY_x;
6817           }
6818
6819         case 'y':
6820           {                                       /* y          */
6821             return KEY_y;
6822           }
6823
6824         default:
6825           goto unknown;
6826       }
6827
6828     case 2: /* 18 tokens of length 2 */
6829       switch (name[0])
6830       {
6831         case 'd':
6832           if (name[1] == 'o')
6833           {                                       /* do         */
6834             return KEY_do;
6835           }
6836
6837           goto unknown;
6838
6839         case 'e':
6840           if (name[1] == 'q')
6841           {                                       /* eq         */
6842             return -KEY_eq;
6843           }
6844
6845           goto unknown;
6846
6847         case 'g':
6848           switch (name[1])
6849           {
6850             case 'e':
6851               {                                   /* ge         */
6852                 return -KEY_ge;
6853               }
6854
6855             case 't':
6856               {                                   /* gt         */
6857                 return -KEY_gt;
6858               }
6859
6860             default:
6861               goto unknown;
6862           }
6863
6864         case 'i':
6865           if (name[1] == 'f')
6866           {                                       /* if         */
6867             return KEY_if;
6868           }
6869
6870           goto unknown;
6871
6872         case 'l':
6873           switch (name[1])
6874           {
6875             case 'c':
6876               {                                   /* lc         */
6877                 return -KEY_lc;
6878               }
6879
6880             case 'e':
6881               {                                   /* le         */
6882                 return -KEY_le;
6883               }
6884
6885             case 't':
6886               {                                   /* lt         */
6887                 return -KEY_lt;
6888               }
6889
6890             default:
6891               goto unknown;
6892           }
6893
6894         case 'm':
6895           if (name[1] == 'y')
6896           {                                       /* my         */
6897             return KEY_my;
6898           }
6899
6900           goto unknown;
6901
6902         case 'n':
6903           switch (name[1])
6904           {
6905             case 'e':
6906               {                                   /* ne         */
6907                 return -KEY_ne;
6908               }
6909
6910             case 'o':
6911               {                                   /* no         */
6912                 return KEY_no;
6913               }
6914
6915             default:
6916               goto unknown;
6917           }
6918
6919         case 'o':
6920           if (name[1] == 'r')
6921           {                                       /* or         */
6922             return -KEY_or;
6923           }
6924
6925           goto unknown;
6926
6927         case 'q':
6928           switch (name[1])
6929           {
6930             case 'q':
6931               {                                   /* qq         */
6932                 return KEY_qq;
6933               }
6934
6935             case 'r':
6936               {                                   /* qr         */
6937                 return KEY_qr;
6938               }
6939
6940             case 'w':
6941               {                                   /* qw         */
6942                 return KEY_qw;
6943               }
6944
6945             case 'x':
6946               {                                   /* qx         */
6947                 return KEY_qx;
6948               }
6949
6950             default:
6951               goto unknown;
6952           }
6953
6954         case 't':
6955           if (name[1] == 'r')
6956           {                                       /* tr         */
6957             return KEY_tr;
6958           }
6959
6960           goto unknown;
6961
6962         case 'u':
6963           if (name[1] == 'c')
6964           {                                       /* uc         */
6965             return -KEY_uc;
6966           }
6967
6968           goto unknown;
6969
6970         default:
6971           goto unknown;
6972       }
6973
6974     case 3: /* 29 tokens of length 3 */
6975       switch (name[0])
6976       {
6977         case 'E':
6978           if (name[1] == 'N' &&
6979               name[2] == 'D')
6980           {                                       /* END        */
6981             return KEY_END;
6982           }
6983
6984           goto unknown;
6985
6986         case 'a':
6987           switch (name[1])
6988           {
6989             case 'b':
6990               if (name[2] == 's')
6991               {                                   /* abs        */
6992                 return -KEY_abs;
6993               }
6994
6995               goto unknown;
6996
6997             case 'n':
6998               if (name[2] == 'd')
6999               {                                   /* and        */
7000                 return -KEY_and;
7001               }
7002
7003               goto unknown;
7004
7005             default:
7006               goto unknown;
7007           }
7008
7009         case 'c':
7010           switch (name[1])
7011           {
7012             case 'h':
7013               if (name[2] == 'r')
7014               {                                   /* chr        */
7015                 return -KEY_chr;
7016               }
7017
7018               goto unknown;
7019
7020             case 'm':
7021               if (name[2] == 'p')
7022               {                                   /* cmp        */
7023                 return -KEY_cmp;
7024               }
7025
7026               goto unknown;
7027
7028             case 'o':
7029               if (name[2] == 's')
7030               {                                   /* cos        */
7031                 return -KEY_cos;
7032               }
7033
7034               goto unknown;
7035
7036             default:
7037               goto unknown;
7038           }
7039
7040         case 'd':
7041           if (name[1] == 'i' &&
7042               name[2] == 'e')
7043           {                                       /* die        */
7044             return -KEY_die;
7045           }
7046
7047           goto unknown;
7048
7049         case 'e':
7050           switch (name[1])
7051           {
7052             case 'o':
7053               if (name[2] == 'f')
7054               {                                   /* eof        */
7055                 return -KEY_eof;
7056               }
7057
7058               goto unknown;
7059
7060             case 'r':
7061               if (name[2] == 'r')
7062               {                                   /* err        */
7063                 return (FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7064               }
7065
7066               goto unknown;
7067
7068             case 'x':
7069               if (name[2] == 'p')
7070               {                                   /* exp        */
7071                 return -KEY_exp;
7072               }
7073
7074               goto unknown;
7075
7076             default:
7077               goto unknown;
7078           }
7079
7080         case 'f':
7081           if (name[1] == 'o' &&
7082               name[2] == 'r')
7083           {                                       /* for        */
7084             return KEY_for;
7085           }
7086
7087           goto unknown;
7088
7089         case 'h':
7090           if (name[1] == 'e' &&
7091               name[2] == 'x')
7092           {                                       /* hex        */
7093             return -KEY_hex;
7094           }
7095
7096           goto unknown;
7097
7098         case 'i':
7099           if (name[1] == 'n' &&
7100               name[2] == 't')
7101           {                                       /* int        */
7102             return -KEY_int;
7103           }
7104
7105           goto unknown;
7106
7107         case 'l':
7108           if (name[1] == 'o' &&
7109               name[2] == 'g')
7110           {                                       /* log        */
7111             return -KEY_log;
7112           }
7113
7114           goto unknown;
7115
7116         case 'm':
7117           if (name[1] == 'a' &&
7118               name[2] == 'p')
7119           {                                       /* map        */
7120             return KEY_map;
7121           }
7122
7123           goto unknown;
7124
7125         case 'n':
7126           if (name[1] == 'o' &&
7127               name[2] == 't')
7128           {                                       /* not        */
7129             return -KEY_not;
7130           }
7131
7132           goto unknown;
7133
7134         case 'o':
7135           switch (name[1])
7136           {
7137             case 'c':
7138               if (name[2] == 't')
7139               {                                   /* oct        */
7140                 return -KEY_oct;
7141               }
7142
7143               goto unknown;
7144
7145             case 'r':
7146               if (name[2] == 'd')
7147               {                                   /* ord        */
7148                 return -KEY_ord;
7149               }
7150
7151               goto unknown;
7152
7153             case 'u':
7154               if (name[2] == 'r')
7155               {                                   /* our        */
7156                 return KEY_our;
7157               }
7158
7159               goto unknown;
7160
7161             default:
7162               goto unknown;
7163           }
7164
7165         case 'p':
7166           if (name[1] == 'o')
7167           {
7168             switch (name[2])
7169             {
7170               case 'p':
7171                 {                                 /* pop        */
7172                   return -KEY_pop;
7173                 }
7174
7175               case 's':
7176                 {                                 /* pos        */
7177                   return KEY_pos;
7178                 }
7179
7180               default:
7181                 goto unknown;
7182             }
7183           }
7184
7185           goto unknown;
7186
7187         case 'r':
7188           if (name[1] == 'e' &&
7189               name[2] == 'f')
7190           {                                       /* ref        */
7191             return -KEY_ref;
7192           }
7193
7194           goto unknown;
7195
7196         case 's':
7197           switch (name[1])
7198           {
7199             case 'a':
7200               if (name[2] == 'y')
7201               {                                   /* say        */
7202                 return (FEATURE_IS_ENABLED("say") ? -KEY_say : 0);
7203               }
7204
7205               goto unknown;
7206
7207             case 'i':
7208               if (name[2] == 'n')
7209               {                                   /* sin        */
7210                 return -KEY_sin;
7211               }
7212
7213               goto unknown;
7214
7215             case 'u':
7216               if (name[2] == 'b')
7217               {                                   /* sub        */
7218                 return KEY_sub;
7219               }
7220
7221               goto unknown;
7222
7223             default:
7224               goto unknown;
7225           }
7226
7227         case 't':
7228           if (name[1] == 'i' &&
7229               name[2] == 'e')
7230           {                                       /* tie        */
7231             return KEY_tie;
7232           }
7233
7234           goto unknown;
7235
7236         case 'u':
7237           if (name[1] == 's' &&
7238               name[2] == 'e')
7239           {                                       /* use        */
7240             return KEY_use;
7241           }
7242
7243           goto unknown;
7244
7245         case 'v':
7246           if (name[1] == 'e' &&
7247               name[2] == 'c')
7248           {                                       /* vec        */
7249             return -KEY_vec;
7250           }
7251
7252           goto unknown;
7253
7254         case 'x':
7255           if (name[1] == 'o' &&
7256               name[2] == 'r')
7257           {                                       /* xor        */
7258             return -KEY_xor;
7259           }
7260
7261           goto unknown;
7262
7263         default:
7264           goto unknown;
7265       }
7266
7267     case 4: /* 41 tokens of length 4 */
7268       switch (name[0])
7269       {
7270         case 'C':
7271           if (name[1] == 'O' &&
7272               name[2] == 'R' &&
7273               name[3] == 'E')
7274           {                                       /* CORE       */
7275             return -KEY_CORE;
7276           }
7277
7278           goto unknown;
7279
7280         case 'I':
7281           if (name[1] == 'N' &&
7282               name[2] == 'I' &&
7283               name[3] == 'T')
7284           {                                       /* INIT       */
7285             return KEY_INIT;
7286           }
7287
7288           goto unknown;
7289
7290         case 'b':
7291           if (name[1] == 'i' &&
7292               name[2] == 'n' &&
7293               name[3] == 'd')
7294           {                                       /* bind       */
7295             return -KEY_bind;
7296           }
7297
7298           goto unknown;
7299
7300         case 'c':
7301           if (name[1] == 'h' &&
7302               name[2] == 'o' &&
7303               name[3] == 'p')
7304           {                                       /* chop       */
7305             return -KEY_chop;
7306           }
7307
7308           goto unknown;
7309
7310         case 'd':
7311           if (name[1] == 'u' &&
7312               name[2] == 'm' &&
7313               name[3] == 'p')
7314           {                                       /* dump       */
7315             return -KEY_dump;
7316           }
7317
7318           goto unknown;
7319
7320         case 'e':
7321           switch (name[1])
7322           {
7323             case 'a':
7324               if (name[2] == 'c' &&
7325                   name[3] == 'h')
7326               {                                   /* each       */
7327                 return -KEY_each;
7328               }
7329
7330               goto unknown;
7331
7332             case 'l':
7333               if (name[2] == 's' &&
7334                   name[3] == 'e')
7335               {                                   /* else       */
7336                 return KEY_else;
7337               }
7338
7339               goto unknown;
7340
7341             case 'v':
7342               if (name[2] == 'a' &&
7343                   name[3] == 'l')
7344               {                                   /* eval       */
7345                 return KEY_eval;
7346               }
7347
7348               goto unknown;
7349
7350             case 'x':
7351               switch (name[2])
7352               {
7353                 case 'e':
7354                   if (name[3] == 'c')
7355                   {                               /* exec       */
7356                     return -KEY_exec;
7357                   }
7358
7359                   goto unknown;
7360
7361                 case 'i':
7362                   if (name[3] == 't')
7363                   {                               /* exit       */
7364                     return -KEY_exit;
7365                   }
7366
7367                   goto unknown;
7368
7369                 default:
7370                   goto unknown;
7371               }
7372
7373             default:
7374               goto unknown;
7375           }
7376
7377         case 'f':
7378           if (name[1] == 'o' &&
7379               name[2] == 'r' &&
7380               name[3] == 'k')
7381           {                                       /* fork       */
7382             return -KEY_fork;
7383           }
7384
7385           goto unknown;
7386
7387         case 'g':
7388           switch (name[1])
7389           {
7390             case 'e':
7391               if (name[2] == 't' &&
7392                   name[3] == 'c')
7393               {                                   /* getc       */
7394                 return -KEY_getc;
7395               }
7396
7397               goto unknown;
7398
7399             case 'l':
7400               if (name[2] == 'o' &&
7401                   name[3] == 'b')
7402               {                                   /* glob       */
7403                 return KEY_glob;
7404               }
7405
7406               goto unknown;
7407
7408             case 'o':
7409               if (name[2] == 't' &&
7410                   name[3] == 'o')
7411               {                                   /* goto       */
7412                 return KEY_goto;
7413               }
7414
7415               goto unknown;
7416
7417             case 'r':
7418               if (name[2] == 'e' &&
7419                   name[3] == 'p')
7420               {                                   /* grep       */
7421                 return KEY_grep;
7422               }
7423
7424               goto unknown;
7425
7426             default:
7427               goto unknown;
7428           }
7429
7430         case 'j':
7431           if (name[1] == 'o' &&
7432               name[2] == 'i' &&
7433               name[3] == 'n')
7434           {                                       /* join       */
7435             return -KEY_join;
7436           }
7437
7438           goto unknown;
7439
7440         case 'k':
7441           switch (name[1])
7442           {
7443             case 'e':
7444               if (name[2] == 'y' &&
7445                   name[3] == 's')
7446               {                                   /* keys       */
7447                 return -KEY_keys;
7448               }
7449
7450               goto unknown;
7451
7452             case 'i':
7453               if (name[2] == 'l' &&
7454                   name[3] == 'l')
7455               {                                   /* kill       */
7456                 return -KEY_kill;
7457               }
7458
7459               goto unknown;
7460
7461             default:
7462               goto unknown;
7463           }
7464
7465         case 'l':
7466           switch (name[1])
7467           {
7468             case 'a':
7469               if (name[2] == 's' &&
7470                   name[3] == 't')
7471               {                                   /* last       */
7472                 return KEY_last;
7473               }
7474
7475               goto unknown;
7476
7477             case 'i':
7478               if (name[2] == 'n' &&
7479                   name[3] == 'k')
7480               {                                   /* link       */
7481                 return -KEY_link;
7482               }
7483
7484               goto unknown;
7485
7486             case 'o':
7487               if (name[2] == 'c' &&
7488                   name[3] == 'k')
7489               {                                   /* lock       */
7490                 return -KEY_lock;
7491               }
7492
7493               goto unknown;
7494
7495             default:
7496               goto unknown;
7497           }
7498
7499         case 'n':
7500           if (name[1] == 'e' &&
7501               name[2] == 'x' &&
7502               name[3] == 't')
7503           {                                       /* next       */
7504             return KEY_next;
7505           }
7506
7507           goto unknown;
7508
7509         case 'o':
7510           if (name[1] == 'p' &&
7511               name[2] == 'e' &&
7512               name[3] == 'n')
7513           {                                       /* open       */
7514             return -KEY_open;
7515           }
7516
7517           goto unknown;
7518
7519         case 'p':
7520           switch (name[1])
7521           {
7522             case 'a':
7523               if (name[2] == 'c' &&
7524                   name[3] == 'k')
7525               {                                   /* pack       */
7526                 return -KEY_pack;
7527               }
7528
7529               goto unknown;
7530
7531             case 'i':
7532               if (name[2] == 'p' &&
7533                   name[3] == 'e')
7534               {                                   /* pipe       */
7535                 return -KEY_pipe;
7536               }
7537
7538               goto unknown;
7539
7540             case 'u':
7541               if (name[2] == 's' &&
7542                   name[3] == 'h')
7543               {                                   /* push       */
7544                 return -KEY_push;
7545               }
7546
7547               goto unknown;
7548
7549             default:
7550               goto unknown;
7551           }
7552
7553         case 'r':
7554           switch (name[1])
7555           {
7556             case 'a':
7557               if (name[2] == 'n' &&
7558                   name[3] == 'd')
7559               {                                   /* rand       */
7560                 return -KEY_rand;
7561               }
7562
7563               goto unknown;
7564
7565             case 'e':
7566               switch (name[2])
7567               {
7568                 case 'a':
7569                   if (name[3] == 'd')
7570                   {                               /* read       */
7571                     return -KEY_read;
7572                   }
7573
7574                   goto unknown;
7575
7576                 case 'c':
7577                   if (name[3] == 'v')
7578                   {                               /* recv       */
7579                     return -KEY_recv;
7580                   }
7581
7582                   goto unknown;
7583
7584                 case 'd':
7585                   if (name[3] == 'o')
7586                   {                               /* redo       */
7587                     return KEY_redo;
7588                   }
7589
7590                   goto unknown;
7591
7592                 default:
7593                   goto unknown;
7594               }
7595
7596             default:
7597               goto unknown;
7598           }
7599
7600         case 's':
7601           switch (name[1])
7602           {
7603             case 'e':
7604               switch (name[2])
7605               {
7606                 case 'e':
7607                   if (name[3] == 'k')
7608                   {                               /* seek       */
7609                     return -KEY_seek;
7610                   }
7611
7612                   goto unknown;
7613
7614                 case 'n':
7615                   if (name[3] == 'd')
7616                   {                               /* send       */
7617                     return -KEY_send;
7618                   }
7619
7620                   goto unknown;
7621
7622                 default:
7623                   goto unknown;
7624               }
7625
7626             case 'o':
7627               if (name[2] == 'r' &&
7628                   name[3] == 't')
7629               {                                   /* sort       */
7630                 return KEY_sort;
7631               }
7632
7633               goto unknown;
7634
7635             case 'q':
7636               if (name[2] == 'r' &&
7637                   name[3] == 't')
7638               {                                   /* sqrt       */
7639                 return -KEY_sqrt;
7640               }
7641
7642               goto unknown;
7643
7644             case 't':
7645               if (name[2] == 'a' &&
7646                   name[3] == 't')
7647               {                                   /* stat       */
7648                 return -KEY_stat;
7649               }
7650
7651               goto unknown;
7652
7653             default:
7654               goto unknown;
7655           }
7656
7657         case 't':
7658           switch (name[1])
7659           {
7660             case 'e':
7661               if (name[2] == 'l' &&
7662                   name[3] == 'l')
7663               {                                   /* tell       */
7664                 return -KEY_tell;
7665               }
7666
7667               goto unknown;
7668
7669             case 'i':
7670               switch (name[2])
7671               {
7672                 case 'e':
7673                   if (name[3] == 'd')
7674                   {                               /* tied       */
7675                     return KEY_tied;
7676                   }
7677
7678                   goto unknown;
7679
7680                 case 'm':
7681                   if (name[3] == 'e')
7682                   {                               /* time       */
7683                     return -KEY_time;
7684                   }
7685
7686                   goto unknown;
7687
7688                 default:
7689                   goto unknown;
7690               }
7691
7692             default:
7693               goto unknown;
7694           }
7695
7696         case 'w':
7697           switch (name[1])
7698           {
7699             case 'a':
7700             switch (name[2])
7701             {
7702               case 'i':
7703                 if (name[3] == 't')
7704                 {                                 /* wait       */
7705                   return -KEY_wait;
7706                 }
7707
7708                 goto unknown;
7709
7710               case 'r':
7711                 if (name[3] == 'n')
7712                 {                                 /* warn       */
7713                   return -KEY_warn;
7714                 }
7715
7716                 goto unknown;
7717
7718               default:
7719                 goto unknown;
7720             }
7721
7722             case 'h':
7723               if (name[2] == 'e' &&
7724                   name[3] == 'n')
7725               {                                   /* when       */
7726                 return (FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7727           }
7728
7729           goto unknown;
7730
7731         default:
7732           goto unknown;
7733       }
7734
7735         default:
7736           goto unknown;
7737       }
7738
7739     case 5: /* 38 tokens of length 5 */
7740       switch (name[0])
7741       {
7742         case 'B':
7743           if (name[1] == 'E' &&
7744               name[2] == 'G' &&
7745               name[3] == 'I' &&
7746               name[4] == 'N')
7747           {                                       /* BEGIN      */
7748             return KEY_BEGIN;
7749           }
7750
7751           goto unknown;
7752
7753         case 'C':
7754           if (name[1] == 'H' &&
7755               name[2] == 'E' &&
7756               name[3] == 'C' &&
7757               name[4] == 'K')
7758           {                                       /* CHECK      */
7759             return KEY_CHECK;
7760           }
7761
7762           goto unknown;
7763
7764         case 'a':
7765           switch (name[1])
7766           {
7767             case 'l':
7768               if (name[2] == 'a' &&
7769                   name[3] == 'r' &&
7770                   name[4] == 'm')
7771               {                                   /* alarm      */
7772                 return -KEY_alarm;
7773               }
7774
7775               goto unknown;
7776
7777             case 't':
7778               if (name[2] == 'a' &&
7779                   name[3] == 'n' &&
7780                   name[4] == '2')
7781               {                                   /* atan2      */
7782                 return -KEY_atan2;
7783               }
7784
7785               goto unknown;
7786
7787             default:
7788               goto unknown;
7789           }
7790
7791         case 'b':
7792           switch (name[1])
7793           {
7794             case 'l':
7795               if (name[2] == 'e' &&
7796               name[3] == 's' &&
7797               name[4] == 's')
7798           {                                       /* bless      */
7799             return -KEY_bless;
7800           }
7801
7802           goto unknown;
7803
7804             case 'r':
7805               if (name[2] == 'e' &&
7806                   name[3] == 'a' &&
7807                   name[4] == 'k')
7808               {                                   /* break      */
7809                 return (FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
7810               }
7811
7812               goto unknown;
7813
7814             default:
7815               goto unknown;
7816           }
7817
7818         case 'c':
7819           switch (name[1])
7820           {
7821             case 'h':
7822               switch (name[2])
7823               {
7824                 case 'd':
7825                   if (name[3] == 'i' &&
7826                       name[4] == 'r')
7827                   {                               /* chdir      */
7828                     return -KEY_chdir;
7829                   }
7830
7831                   goto unknown;
7832
7833                 case 'm':
7834                   if (name[3] == 'o' &&
7835                       name[4] == 'd')
7836                   {                               /* chmod      */
7837                     return -KEY_chmod;
7838                   }
7839
7840                   goto unknown;
7841
7842                 case 'o':
7843                   switch (name[3])
7844                   {
7845                     case 'm':
7846                       if (name[4] == 'p')
7847                       {                           /* chomp      */
7848                         return -KEY_chomp;
7849                       }
7850
7851                       goto unknown;
7852
7853                     case 'w':
7854                       if (name[4] == 'n')
7855                       {                           /* chown      */
7856                         return -KEY_chown;
7857                       }
7858
7859                       goto unknown;
7860
7861                     default:
7862                       goto unknown;
7863                   }
7864
7865                 default:
7866                   goto unknown;
7867               }
7868
7869             case 'l':
7870               if (name[2] == 'o' &&
7871                   name[3] == 's' &&
7872                   name[4] == 'e')
7873               {                                   /* close      */
7874                 return -KEY_close;
7875               }
7876
7877               goto unknown;
7878
7879             case 'r':
7880               if (name[2] == 'y' &&
7881                   name[3] == 'p' &&
7882                   name[4] == 't')
7883               {                                   /* crypt      */
7884                 return -KEY_crypt;
7885               }
7886
7887               goto unknown;
7888
7889             default:
7890               goto unknown;
7891           }
7892
7893         case 'e':
7894           if (name[1] == 'l' &&
7895               name[2] == 's' &&
7896               name[3] == 'i' &&
7897               name[4] == 'f')
7898           {                                       /* elsif      */
7899             return KEY_elsif;
7900           }
7901
7902           goto unknown;
7903
7904         case 'f':
7905           switch (name[1])
7906           {
7907             case 'c':
7908               if (name[2] == 'n' &&
7909                   name[3] == 't' &&
7910                   name[4] == 'l')
7911               {                                   /* fcntl      */
7912                 return -KEY_fcntl;
7913               }
7914
7915               goto unknown;
7916
7917             case 'l':
7918               if (name[2] == 'o' &&
7919                   name[3] == 'c' &&
7920                   name[4] == 'k')
7921               {                                   /* flock      */
7922                 return -KEY_flock;
7923               }
7924
7925               goto unknown;
7926
7927             default:
7928               goto unknown;
7929           }
7930
7931         case 'g':
7932           if (name[1] == 'i' &&
7933               name[2] == 'v' &&
7934               name[3] == 'e' &&
7935               name[4] == 'n')
7936           {                                       /* given      */
7937             return (FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
7938           }
7939
7940           goto unknown;
7941
7942         case 'i':
7943           switch (name[1])
7944           {
7945             case 'n':
7946               if (name[2] == 'd' &&
7947                   name[3] == 'e' &&
7948                   name[4] == 'x')
7949               {                                   /* index      */
7950                 return -KEY_index;
7951               }
7952
7953               goto unknown;
7954
7955             case 'o':
7956               if (name[2] == 'c' &&
7957                   name[3] == 't' &&
7958                   name[4] == 'l')
7959               {                                   /* ioctl      */
7960                 return -KEY_ioctl;
7961               }
7962
7963               goto unknown;
7964
7965             default:
7966               goto unknown;
7967           }
7968
7969         case 'l':
7970           switch (name[1])
7971           {
7972             case 'o':
7973               if (name[2] == 'c' &&
7974                   name[3] == 'a' &&
7975                   name[4] == 'l')
7976               {                                   /* local      */
7977                 return KEY_local;
7978               }
7979
7980               goto unknown;
7981
7982             case 's':
7983               if (name[2] == 't' &&
7984                   name[3] == 'a' &&
7985                   name[4] == 't')
7986               {                                   /* lstat      */
7987                 return -KEY_lstat;
7988               }
7989
7990               goto unknown;
7991
7992             default:
7993               goto unknown;
7994           }
7995
7996         case 'm':
7997           if (name[1] == 'k' &&
7998               name[2] == 'd' &&
7999               name[3] == 'i' &&
8000               name[4] == 'r')
8001           {                                       /* mkdir      */
8002             return -KEY_mkdir;
8003           }
8004
8005           goto unknown;
8006
8007         case 'p':
8008           if (name[1] == 'r' &&
8009               name[2] == 'i' &&
8010               name[3] == 'n' &&
8011               name[4] == 't')
8012           {                                       /* print      */
8013             return KEY_print;
8014           }
8015
8016           goto unknown;
8017
8018         case 'r':
8019           switch (name[1])
8020           {
8021             case 'e':
8022               if (name[2] == 's' &&
8023                   name[3] == 'e' &&
8024                   name[4] == 't')
8025               {                                   /* reset      */
8026                 return -KEY_reset;
8027               }
8028
8029               goto unknown;
8030
8031             case 'm':
8032               if (name[2] == 'd' &&
8033                   name[3] == 'i' &&
8034                   name[4] == 'r')
8035               {                                   /* rmdir      */
8036                 return -KEY_rmdir;
8037               }
8038
8039               goto unknown;
8040
8041             default:
8042               goto unknown;
8043           }
8044
8045         case 's':
8046           switch (name[1])
8047           {
8048             case 'e':
8049               if (name[2] == 'm' &&
8050                   name[3] == 'o' &&
8051                   name[4] == 'p')
8052               {                                   /* semop      */
8053                 return -KEY_semop;
8054               }
8055
8056               goto unknown;
8057
8058             case 'h':
8059               if (name[2] == 'i' &&
8060                   name[3] == 'f' &&
8061                   name[4] == 't')
8062               {                                   /* shift      */
8063                 return -KEY_shift;
8064               }
8065
8066               goto unknown;
8067
8068             case 'l':
8069               if (name[2] == 'e' &&
8070                   name[3] == 'e' &&
8071                   name[4] == 'p')
8072               {                                   /* sleep      */
8073                 return -KEY_sleep;
8074               }
8075
8076               goto unknown;
8077
8078             case 'p':
8079               if (name[2] == 'l' &&
8080                   name[3] == 'i' &&
8081                   name[4] == 't')
8082               {                                   /* split      */
8083                 return KEY_split;
8084               }
8085
8086               goto unknown;
8087
8088             case 'r':
8089               if (name[2] == 'a' &&
8090                   name[3] == 'n' &&
8091                   name[4] == 'd')
8092               {                                   /* srand      */
8093                 return -KEY_srand;
8094               }
8095
8096               goto unknown;
8097
8098             case 't':
8099               if (name[2] == 'u' &&
8100                   name[3] == 'd' &&
8101                   name[4] == 'y')
8102               {                                   /* study      */
8103                 return KEY_study;
8104               }
8105
8106               goto unknown;
8107
8108             default:
8109               goto unknown;
8110           }
8111
8112         case 't':
8113           if (name[1] == 'i' &&
8114               name[2] == 'm' &&
8115               name[3] == 'e' &&
8116               name[4] == 's')
8117           {                                       /* times      */
8118             return -KEY_times;
8119           }
8120
8121           goto unknown;
8122
8123         case 'u':
8124           switch (name[1])
8125           {
8126             case 'm':
8127               if (name[2] == 'a' &&
8128                   name[3] == 's' &&
8129                   name[4] == 'k')
8130               {                                   /* umask      */
8131                 return -KEY_umask;
8132               }
8133
8134               goto unknown;
8135
8136             case 'n':
8137               switch (name[2])
8138               {
8139                 case 'd':
8140                   if (name[3] == 'e' &&
8141                       name[4] == 'f')
8142                   {                               /* undef      */
8143                     return KEY_undef;
8144                   }
8145
8146                   goto unknown;
8147
8148                 case 't':
8149                   if (name[3] == 'i')
8150                   {
8151                     switch (name[4])
8152                     {
8153                       case 'e':
8154                         {                         /* untie      */
8155                           return KEY_untie;
8156                         }
8157
8158                       case 'l':
8159                         {                         /* until      */
8160                           return KEY_until;
8161                         }
8162
8163                       default:
8164                         goto unknown;
8165                     }
8166                   }
8167
8168                   goto unknown;
8169
8170                 default:
8171                   goto unknown;
8172               }
8173
8174             case 't':
8175               if (name[2] == 'i' &&
8176                   name[3] == 'm' &&
8177                   name[4] == 'e')
8178               {                                   /* utime      */
8179                 return -KEY_utime;
8180               }
8181
8182               goto unknown;
8183
8184             default:
8185               goto unknown;
8186           }
8187
8188         case 'w':
8189           switch (name[1])
8190           {
8191             case 'h':
8192               if (name[2] == 'i' &&
8193                   name[3] == 'l' &&
8194                   name[4] == 'e')
8195               {                                   /* while      */
8196                 return KEY_while;
8197               }
8198
8199               goto unknown;
8200
8201             case 'r':
8202               if (name[2] == 'i' &&
8203                   name[3] == 't' &&
8204                   name[4] == 'e')
8205               {                                   /* write      */
8206                 return -KEY_write;
8207               }
8208
8209               goto unknown;
8210
8211             default:
8212               goto unknown;
8213           }
8214
8215         default:
8216           goto unknown;
8217       }
8218
8219     case 6: /* 33 tokens of length 6 */
8220       switch (name[0])
8221       {
8222         case 'a':
8223           if (name[1] == 'c' &&
8224               name[2] == 'c' &&
8225               name[3] == 'e' &&
8226               name[4] == 'p' &&
8227               name[5] == 't')
8228           {                                       /* accept     */
8229             return -KEY_accept;
8230           }
8231
8232           goto unknown;
8233
8234         case 'c':
8235           switch (name[1])
8236           {
8237             case 'a':
8238               if (name[2] == 'l' &&
8239                   name[3] == 'l' &&
8240                   name[4] == 'e' &&
8241                   name[5] == 'r')
8242               {                                   /* caller     */
8243                 return -KEY_caller;
8244               }
8245
8246               goto unknown;
8247
8248             case 'h':
8249               if (name[2] == 'r' &&
8250                   name[3] == 'o' &&
8251                   name[4] == 'o' &&
8252                   name[5] == 't')
8253               {                                   /* chroot     */
8254                 return -KEY_chroot;
8255               }
8256
8257               goto unknown;
8258
8259             default:
8260               goto unknown;
8261           }
8262
8263         case 'd':
8264           if (name[1] == 'e' &&
8265               name[2] == 'l' &&
8266               name[3] == 'e' &&
8267               name[4] == 't' &&
8268               name[5] == 'e')
8269           {                                       /* delete     */
8270             return KEY_delete;
8271           }
8272
8273           goto unknown;
8274
8275         case 'e':
8276           switch (name[1])
8277           {
8278             case 'l':
8279               if (name[2] == 's' &&
8280                   name[3] == 'e' &&
8281                   name[4] == 'i' &&
8282                   name[5] == 'f')
8283               {                                   /* elseif     */
8284                 if(ckWARN_d(WARN_SYNTAX))
8285                   Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8286               }
8287
8288               goto unknown;
8289
8290             case 'x':
8291               if (name[2] == 'i' &&
8292                   name[3] == 's' &&
8293                   name[4] == 't' &&
8294                   name[5] == 's')
8295               {                                   /* exists     */
8296                 return KEY_exists;
8297               }
8298
8299               goto unknown;
8300
8301             default:
8302               goto unknown;
8303           }
8304
8305         case 'f':
8306           switch (name[1])
8307           {
8308             case 'i':
8309               if (name[2] == 'l' &&
8310                   name[3] == 'e' &&
8311                   name[4] == 'n' &&
8312                   name[5] == 'o')
8313               {                                   /* fileno     */
8314                 return -KEY_fileno;
8315               }
8316
8317               goto unknown;
8318
8319             case 'o':
8320               if (name[2] == 'r' &&
8321                   name[3] == 'm' &&
8322                   name[4] == 'a' &&
8323                   name[5] == 't')
8324               {                                   /* format     */
8325                 return KEY_format;
8326               }
8327
8328               goto unknown;
8329
8330             default:
8331               goto unknown;
8332           }
8333
8334         case 'g':
8335           if (name[1] == 'm' &&
8336               name[2] == 't' &&
8337               name[3] == 'i' &&
8338               name[4] == 'm' &&
8339               name[5] == 'e')
8340           {                                       /* gmtime     */
8341             return -KEY_gmtime;
8342           }
8343
8344           goto unknown;
8345
8346         case 'l':
8347           switch (name[1])
8348           {
8349             case 'e':
8350               if (name[2] == 'n' &&
8351                   name[3] == 'g' &&
8352                   name[4] == 't' &&
8353                   name[5] == 'h')
8354               {                                   /* length     */
8355                 return -KEY_length;
8356               }
8357
8358               goto unknown;
8359
8360             case 'i':
8361               if (name[2] == 's' &&
8362                   name[3] == 't' &&
8363                   name[4] == 'e' &&
8364                   name[5] == 'n')
8365               {                                   /* listen     */
8366                 return -KEY_listen;
8367               }
8368
8369               goto unknown;
8370
8371             default:
8372               goto unknown;
8373           }
8374
8375         case 'm':
8376           if (name[1] == 's' &&
8377               name[2] == 'g')
8378           {
8379             switch (name[3])
8380             {
8381               case 'c':
8382                 if (name[4] == 't' &&
8383                     name[5] == 'l')
8384                 {                                 /* msgctl     */
8385                   return -KEY_msgctl;
8386                 }
8387
8388                 goto unknown;
8389
8390               case 'g':
8391                 if (name[4] == 'e' &&
8392                     name[5] == 't')
8393                 {                                 /* msgget     */
8394                   return -KEY_msgget;
8395                 }
8396
8397                 goto unknown;
8398
8399               case 'r':
8400                 if (name[4] == 'c' &&
8401                     name[5] == 'v')
8402                 {                                 /* msgrcv     */
8403                   return -KEY_msgrcv;
8404                 }
8405
8406                 goto unknown;
8407
8408               case 's':
8409                 if (name[4] == 'n' &&
8410                     name[5] == 'd')
8411                 {                                 /* msgsnd     */
8412                   return -KEY_msgsnd;
8413                 }
8414
8415                 goto unknown;
8416
8417               default:
8418                 goto unknown;
8419             }
8420           }
8421
8422           goto unknown;
8423
8424         case 'p':
8425           if (name[1] == 'r' &&
8426               name[2] == 'i' &&
8427               name[3] == 'n' &&
8428               name[4] == 't' &&
8429               name[5] == 'f')
8430           {                                       /* printf     */
8431             return KEY_printf;
8432           }
8433
8434           goto unknown;
8435
8436         case 'r':
8437           switch (name[1])
8438           {
8439             case 'e':
8440               switch (name[2])
8441               {
8442                 case 'n':
8443                   if (name[3] == 'a' &&
8444                       name[4] == 'm' &&
8445                       name[5] == 'e')
8446                   {                               /* rename     */
8447                     return -KEY_rename;
8448                   }
8449
8450                   goto unknown;
8451
8452                 case 't':
8453                   if (name[3] == 'u' &&
8454                       name[4] == 'r' &&
8455                       name[5] == 'n')
8456                   {                               /* return     */
8457                     return KEY_return;
8458                   }
8459
8460                   goto unknown;
8461
8462                 default:
8463                   goto unknown;
8464               }
8465
8466             case 'i':
8467               if (name[2] == 'n' &&
8468                   name[3] == 'd' &&
8469                   name[4] == 'e' &&
8470                   name[5] == 'x')
8471               {                                   /* rindex     */
8472                 return -KEY_rindex;
8473               }
8474
8475               goto unknown;
8476
8477             default:
8478               goto unknown;
8479           }
8480
8481         case 's':
8482           switch (name[1])
8483           {
8484             case 'c':
8485               if (name[2] == 'a' &&
8486                   name[3] == 'l' &&
8487                   name[4] == 'a' &&
8488                   name[5] == 'r')
8489               {                                   /* scalar     */
8490                 return KEY_scalar;
8491               }
8492
8493               goto unknown;
8494
8495             case 'e':
8496               switch (name[2])
8497               {
8498                 case 'l':
8499                   if (name[3] == 'e' &&
8500                       name[4] == 'c' &&
8501                       name[5] == 't')
8502                   {                               /* select     */
8503                     return -KEY_select;
8504                   }
8505
8506                   goto unknown;
8507
8508                 case 'm':
8509                   switch (name[3])
8510                   {
8511                     case 'c':
8512                       if (name[4] == 't' &&
8513                           name[5] == 'l')
8514                       {                           /* semctl     */
8515                         return -KEY_semctl;
8516                       }
8517
8518                       goto unknown;
8519
8520                     case 'g':
8521                       if (name[4] == 'e' &&
8522                           name[5] == 't')
8523                       {                           /* semget     */
8524                         return -KEY_semget;
8525                       }
8526
8527                       goto unknown;
8528
8529                     default:
8530                       goto unknown;
8531                   }
8532
8533                 default:
8534                   goto unknown;
8535               }
8536
8537             case 'h':
8538               if (name[2] == 'm')
8539               {
8540                 switch (name[3])
8541                 {
8542                   case 'c':
8543                     if (name[4] == 't' &&
8544                         name[5] == 'l')
8545                     {                             /* shmctl     */
8546                       return -KEY_shmctl;
8547                     }
8548
8549                     goto unknown;
8550
8551                   case 'g':
8552                     if (name[4] == 'e' &&
8553                         name[5] == 't')
8554                     {                             /* shmget     */
8555                       return -KEY_shmget;
8556                     }
8557
8558                     goto unknown;
8559
8560                   default:
8561                     goto unknown;
8562                 }
8563               }
8564
8565               goto unknown;
8566
8567             case 'o':
8568               if (name[2] == 'c' &&
8569                   name[3] == 'k' &&
8570                   name[4] == 'e' &&
8571                   name[5] == 't')
8572               {                                   /* socket     */
8573                 return -KEY_socket;
8574               }
8575
8576               goto unknown;
8577
8578             case 'p':
8579               if (name[2] == 'l' &&
8580                   name[3] == 'i' &&
8581                   name[4] == 'c' &&
8582                   name[5] == 'e')
8583               {                                   /* splice     */
8584                 return -KEY_splice;
8585               }
8586
8587               goto unknown;
8588
8589             case 'u':
8590               if (name[2] == 'b' &&
8591                   name[3] == 's' &&
8592                   name[4] == 't' &&
8593                   name[5] == 'r')
8594               {                                   /* substr     */
8595                 return -KEY_substr;
8596               }
8597
8598               goto unknown;
8599
8600             case 'y':
8601               if (name[2] == 's' &&
8602                   name[3] == 't' &&
8603                   name[4] == 'e' &&
8604                   name[5] == 'm')
8605               {                                   /* system     */
8606                 return -KEY_system;
8607               }
8608
8609               goto unknown;
8610
8611             default:
8612               goto unknown;
8613           }
8614
8615         case 'u':
8616           if (name[1] == 'n')
8617           {
8618             switch (name[2])
8619             {
8620               case 'l':
8621                 switch (name[3])
8622                 {
8623                   case 'e':
8624                     if (name[4] == 's' &&
8625                         name[5] == 's')
8626                     {                             /* unless     */
8627                       return KEY_unless;
8628                     }
8629
8630                     goto unknown;
8631
8632                   case 'i':
8633                     if (name[4] == 'n' &&
8634                         name[5] == 'k')
8635                     {                             /* unlink     */
8636                       return -KEY_unlink;
8637                     }
8638
8639                     goto unknown;
8640
8641                   default:
8642                     goto unknown;
8643                 }
8644
8645               case 'p':
8646                 if (name[3] == 'a' &&
8647                     name[4] == 'c' &&
8648                     name[5] == 'k')
8649                 {                                 /* unpack     */
8650                   return -KEY_unpack;
8651                 }
8652
8653                 goto unknown;
8654
8655               default:
8656                 goto unknown;
8657             }
8658           }
8659
8660           goto unknown;
8661
8662         case 'v':
8663           if (name[1] == 'a' &&
8664               name[2] == 'l' &&
8665               name[3] == 'u' &&
8666               name[4] == 'e' &&
8667               name[5] == 's')
8668           {                                       /* values     */
8669             return -KEY_values;
8670           }
8671
8672           goto unknown;
8673
8674         default:
8675           goto unknown;
8676       }
8677
8678     case 7: /* 29 tokens of length 7 */
8679       switch (name[0])
8680       {
8681         case 'D':
8682           if (name[1] == 'E' &&
8683               name[2] == 'S' &&
8684               name[3] == 'T' &&
8685               name[4] == 'R' &&
8686               name[5] == 'O' &&
8687               name[6] == 'Y')
8688           {                                       /* DESTROY    */
8689             return KEY_DESTROY;
8690           }
8691
8692           goto unknown;
8693
8694         case '_':
8695           if (name[1] == '_' &&
8696               name[2] == 'E' &&
8697               name[3] == 'N' &&
8698               name[4] == 'D' &&
8699               name[5] == '_' &&
8700               name[6] == '_')
8701           {                                       /* __END__    */
8702             return KEY___END__;
8703           }
8704
8705           goto unknown;
8706
8707         case 'b':
8708           if (name[1] == 'i' &&
8709               name[2] == 'n' &&
8710               name[3] == 'm' &&
8711               name[4] == 'o' &&
8712               name[5] == 'd' &&
8713               name[6] == 'e')
8714           {                                       /* binmode    */
8715             return -KEY_binmode;
8716           }
8717
8718           goto unknown;
8719
8720         case 'c':
8721           if (name[1] == 'o' &&
8722               name[2] == 'n' &&
8723               name[3] == 'n' &&
8724               name[4] == 'e' &&
8725               name[5] == 'c' &&
8726               name[6] == 't')
8727           {                                       /* connect    */
8728             return -KEY_connect;
8729           }
8730
8731           goto unknown;
8732
8733         case 'd':
8734           switch (name[1])
8735           {
8736             case 'b':
8737               if (name[2] == 'm' &&
8738                   name[3] == 'o' &&
8739                   name[4] == 'p' &&
8740                   name[5] == 'e' &&
8741                   name[6] == 'n')
8742               {                                   /* dbmopen    */
8743                 return -KEY_dbmopen;
8744               }
8745
8746               goto unknown;
8747
8748             case 'e':
8749               if (name[2] == 'f')
8750               {
8751                 switch (name[3])
8752                 {
8753                   case 'a':
8754                     if (name[4] == 'u' &&
8755                         name[5] == 'l' &&
8756                         name[6] == 't')
8757                     {                             /* default    */
8758                       return (FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
8759                     }
8760
8761                     goto unknown;
8762
8763                   case 'i':
8764                     if (name[4] == 'n' &&
8765                   name[5] == 'e' &&
8766                   name[6] == 'd')
8767               {                                   /* defined    */
8768                 return KEY_defined;
8769               }
8770
8771               goto unknown;
8772
8773             default:
8774               goto unknown;
8775           }
8776               }
8777
8778               goto unknown;
8779
8780             default:
8781               goto unknown;
8782           }
8783
8784         case 'f':
8785           if (name[1] == 'o' &&
8786               name[2] == 'r' &&
8787               name[3] == 'e' &&
8788               name[4] == 'a' &&
8789               name[5] == 'c' &&
8790               name[6] == 'h')
8791           {                                       /* foreach    */
8792             return KEY_foreach;
8793           }
8794
8795           goto unknown;
8796
8797         case 'g':
8798           if (name[1] == 'e' &&
8799               name[2] == 't' &&
8800               name[3] == 'p')
8801           {
8802             switch (name[4])
8803             {
8804               case 'g':
8805                 if (name[5] == 'r' &&
8806                     name[6] == 'p')
8807                 {                                 /* getpgrp    */
8808                   return -KEY_getpgrp;
8809                 }
8810
8811                 goto unknown;
8812
8813               case 'p':
8814                 if (name[5] == 'i' &&
8815                     name[6] == 'd')
8816                 {                                 /* getppid    */
8817                   return -KEY_getppid;
8818                 }
8819
8820                 goto unknown;
8821
8822               default:
8823                 goto unknown;
8824             }
8825           }
8826
8827           goto unknown;
8828
8829         case 'l':
8830           if (name[1] == 'c' &&
8831               name[2] == 'f' &&
8832               name[3] == 'i' &&
8833               name[4] == 'r' &&
8834               name[5] == 's' &&
8835               name[6] == 't')
8836           {                                       /* lcfirst    */
8837             return -KEY_lcfirst;
8838           }
8839
8840           goto unknown;
8841
8842         case 'o':
8843           if (name[1] == 'p' &&
8844               name[2] == 'e' &&
8845               name[3] == 'n' &&
8846               name[4] == 'd' &&
8847               name[5] == 'i' &&
8848               name[6] == 'r')
8849           {                                       /* opendir    */
8850             return -KEY_opendir;
8851           }
8852
8853           goto unknown;
8854
8855         case 'p':
8856           if (name[1] == 'a' &&
8857               name[2] == 'c' &&
8858               name[3] == 'k' &&
8859               name[4] == 'a' &&
8860               name[5] == 'g' &&
8861               name[6] == 'e')
8862           {                                       /* package    */
8863             return KEY_package;
8864           }
8865
8866           goto unknown;
8867
8868         case 'r':
8869           if (name[1] == 'e')
8870           {
8871             switch (name[2])
8872             {
8873               case 'a':
8874                 if (name[3] == 'd' &&
8875                     name[4] == 'd' &&
8876                     name[5] == 'i' &&
8877                     name[6] == 'r')
8878                 {                                 /* readdir    */
8879                   return -KEY_readdir;
8880                 }
8881
8882                 goto unknown;
8883
8884               case 'q':
8885                 if (name[3] == 'u' &&
8886                     name[4] == 'i' &&
8887                     name[5] == 'r' &&
8888                     name[6] == 'e')
8889                 {                                 /* require    */
8890                   return KEY_require;
8891                 }
8892
8893                 goto unknown;
8894
8895               case 'v':
8896                 if (name[3] == 'e' &&
8897                     name[4] == 'r' &&
8898                     name[5] == 's' &&
8899                     name[6] == 'e')
8900                 {                                 /* reverse    */
8901                   return -KEY_reverse;
8902                 }
8903
8904                 goto unknown;
8905
8906               default:
8907                 goto unknown;
8908             }
8909           }
8910
8911           goto unknown;
8912
8913         case 's':
8914           switch (name[1])
8915           {
8916             case 'e':
8917               switch (name[2])
8918               {
8919                 case 'e':
8920                   if (name[3] == 'k' &&
8921                       name[4] == 'd' &&
8922                       name[5] == 'i' &&
8923                       name[6] == 'r')
8924                   {                               /* seekdir    */
8925                     return -KEY_seekdir;
8926                   }
8927
8928                   goto unknown;
8929
8930                 case 't':
8931                   if (name[3] == 'p' &&
8932                       name[4] == 'g' &&
8933                       name[5] == 'r' &&
8934                       name[6] == 'p')
8935                   {                               /* setpgrp    */
8936                     return -KEY_setpgrp;
8937                   }
8938
8939                   goto unknown;
8940
8941                 default:
8942                   goto unknown;
8943               }
8944
8945             case 'h':
8946               if (name[2] == 'm' &&
8947                   name[3] == 'r' &&
8948                   name[4] == 'e' &&
8949                   name[5] == 'a' &&
8950                   name[6] == 'd')
8951               {                                   /* shmread    */
8952                 return -KEY_shmread;
8953               }
8954
8955               goto unknown;
8956
8957             case 'p':
8958               if (name[2] == 'r' &&
8959                   name[3] == 'i' &&
8960                   name[4] == 'n' &&
8961                   name[5] == 't' &&
8962                   name[6] == 'f')
8963               {                                   /* sprintf    */
8964                 return -KEY_sprintf;
8965               }
8966
8967               goto unknown;
8968
8969             case 'y':
8970               switch (name[2])
8971               {
8972                 case 'm':
8973                   if (name[3] == 'l' &&
8974                       name[4] == 'i' &&
8975                       name[5] == 'n' &&
8976                       name[6] == 'k')
8977                   {                               /* symlink    */
8978                     return -KEY_symlink;
8979                   }
8980
8981                   goto unknown;
8982
8983                 case 's':
8984                   switch (name[3])
8985                   {
8986                     case 'c':
8987                       if (name[4] == 'a' &&
8988                           name[5] == 'l' &&
8989                           name[6] == 'l')
8990                       {                           /* syscall    */
8991                         return -KEY_syscall;
8992                       }
8993
8994                       goto unknown;
8995
8996                     case 'o':
8997                       if (name[4] == 'p' &&
8998                           name[5] == 'e' &&
8999                           name[6] == 'n')
9000                       {                           /* sysopen    */
9001                         return -KEY_sysopen;
9002                       }
9003
9004                       goto unknown;
9005
9006                     case 'r':
9007                       if (name[4] == 'e' &&
9008                           name[5] == 'a' &&
9009                           name[6] == 'd')
9010                       {                           /* sysread    */
9011                         return -KEY_sysread;
9012                       }
9013
9014                       goto unknown;
9015
9016                     case 's':
9017                       if (name[4] == 'e' &&
9018                           name[5] == 'e' &&
9019                           name[6] == 'k')
9020                       {                           /* sysseek    */
9021                         return -KEY_sysseek;
9022                       }
9023
9024                       goto unknown;
9025
9026                     default:
9027                       goto unknown;
9028                   }
9029
9030                 default:
9031                   goto unknown;
9032               }
9033
9034             default:
9035               goto unknown;
9036           }
9037
9038         case 't':
9039           if (name[1] == 'e' &&
9040               name[2] == 'l' &&
9041               name[3] == 'l' &&
9042               name[4] == 'd' &&
9043               name[5] == 'i' &&
9044               name[6] == 'r')
9045           {                                       /* telldir    */
9046             return -KEY_telldir;
9047           }
9048
9049           goto unknown;
9050
9051         case 'u':
9052           switch (name[1])
9053           {
9054             case 'c':
9055               if (name[2] == 'f' &&
9056                   name[3] == 'i' &&
9057                   name[4] == 'r' &&
9058                   name[5] == 's' &&
9059                   name[6] == 't')
9060               {                                   /* ucfirst    */
9061                 return -KEY_ucfirst;
9062               }
9063
9064               goto unknown;
9065
9066             case 'n':
9067               if (name[2] == 's' &&
9068                   name[3] == 'h' &&
9069                   name[4] == 'i' &&
9070                   name[5] == 'f' &&
9071                   name[6] == 't')
9072               {                                   /* unshift    */
9073                 return -KEY_unshift;
9074               }
9075
9076               goto unknown;
9077
9078             default:
9079               goto unknown;
9080           }
9081
9082         case 'w':
9083           if (name[1] == 'a' &&
9084               name[2] == 'i' &&
9085               name[3] == 't' &&
9086               name[4] == 'p' &&
9087               name[5] == 'i' &&
9088               name[6] == 'd')
9089           {                                       /* waitpid    */
9090             return -KEY_waitpid;
9091           }
9092
9093           goto unknown;
9094
9095         default:
9096           goto unknown;
9097       }
9098
9099     case 8: /* 26 tokens of length 8 */
9100       switch (name[0])
9101       {
9102         case 'A':
9103           if (name[1] == 'U' &&
9104               name[2] == 'T' &&
9105               name[3] == 'O' &&
9106               name[4] == 'L' &&
9107               name[5] == 'O' &&
9108               name[6] == 'A' &&
9109               name[7] == 'D')
9110           {                                       /* AUTOLOAD   */
9111             return KEY_AUTOLOAD;
9112           }
9113
9114           goto unknown;
9115
9116         case '_':
9117           if (name[1] == '_')
9118           {
9119             switch (name[2])
9120             {
9121               case 'D':
9122                 if (name[3] == 'A' &&
9123                     name[4] == 'T' &&
9124                     name[5] == 'A' &&
9125                     name[6] == '_' &&
9126                     name[7] == '_')
9127                 {                                 /* __DATA__   */
9128                   return KEY___DATA__;
9129                 }
9130
9131                 goto unknown;
9132
9133               case 'F':
9134                 if (name[3] == 'I' &&
9135                     name[4] == 'L' &&
9136                     name[5] == 'E' &&
9137                     name[6] == '_' &&
9138                     name[7] == '_')
9139                 {                                 /* __FILE__   */
9140                   return -KEY___FILE__;
9141                 }
9142
9143                 goto unknown;
9144
9145               case 'L':
9146                 if (name[3] == 'I' &&
9147                     name[4] == 'N' &&
9148                     name[5] == 'E' &&
9149                     name[6] == '_' &&
9150                     name[7] == '_')
9151                 {                                 /* __LINE__   */
9152                   return -KEY___LINE__;
9153                 }
9154
9155                 goto unknown;
9156
9157               default:
9158                 goto unknown;
9159             }
9160           }
9161
9162           goto unknown;
9163
9164         case 'c':
9165           switch (name[1])
9166           {
9167             case 'l':
9168               if (name[2] == 'o' &&
9169                   name[3] == 's' &&
9170                   name[4] == 'e' &&
9171                   name[5] == 'd' &&
9172                   name[6] == 'i' &&
9173                   name[7] == 'r')
9174               {                                   /* closedir   */
9175                 return -KEY_closedir;
9176               }
9177
9178               goto unknown;
9179
9180             case 'o':
9181               if (name[2] == 'n' &&
9182                   name[3] == 't' &&
9183                   name[4] == 'i' &&
9184                   name[5] == 'n' &&
9185                   name[6] == 'u' &&
9186                   name[7] == 'e')
9187               {                                   /* continue   */
9188                 return -KEY_continue;
9189               }
9190
9191               goto unknown;
9192
9193             default:
9194               goto unknown;
9195           }
9196
9197         case 'd':
9198           if (name[1] == 'b' &&
9199               name[2] == 'm' &&
9200               name[3] == 'c' &&
9201               name[4] == 'l' &&
9202               name[5] == 'o' &&
9203               name[6] == 's' &&
9204               name[7] == 'e')
9205           {                                       /* dbmclose   */
9206             return -KEY_dbmclose;
9207           }
9208
9209           goto unknown;
9210
9211         case 'e':
9212           if (name[1] == 'n' &&
9213               name[2] == 'd')
9214           {
9215             switch (name[3])
9216             {
9217               case 'g':
9218                 if (name[4] == 'r' &&
9219                     name[5] == 'e' &&
9220                     name[6] == 'n' &&
9221                     name[7] == 't')
9222                 {                                 /* endgrent   */
9223                   return -KEY_endgrent;
9224                 }
9225
9226                 goto unknown;
9227
9228               case 'p':
9229                 if (name[4] == 'w' &&
9230                     name[5] == 'e' &&
9231                     name[6] == 'n' &&
9232                     name[7] == 't')
9233                 {                                 /* endpwent   */
9234                   return -KEY_endpwent;
9235                 }
9236
9237                 goto unknown;
9238
9239               default:
9240                 goto unknown;
9241             }
9242           }
9243
9244           goto unknown;
9245
9246         case 'f':
9247           if (name[1] == 'o' &&
9248               name[2] == 'r' &&
9249               name[3] == 'm' &&
9250               name[4] == 'l' &&
9251               name[5] == 'i' &&
9252               name[6] == 'n' &&
9253               name[7] == 'e')
9254           {                                       /* formline   */
9255             return -KEY_formline;
9256           }
9257
9258           goto unknown;
9259
9260         case 'g':
9261           if (name[1] == 'e' &&
9262               name[2] == 't')
9263           {
9264             switch (name[3])
9265             {
9266               case 'g':
9267                 if (name[4] == 'r')
9268                 {
9269                   switch (name[5])
9270                   {
9271                     case 'e':
9272                       if (name[6] == 'n' &&
9273                           name[7] == 't')
9274                       {                           /* getgrent   */
9275                         return -KEY_getgrent;
9276                       }
9277
9278                       goto unknown;
9279
9280                     case 'g':
9281                       if (name[6] == 'i' &&
9282                           name[7] == 'd')
9283                       {                           /* getgrgid   */
9284                         return -KEY_getgrgid;
9285                       }
9286
9287                       goto unknown;
9288
9289                     case 'n':
9290                       if (name[6] == 'a' &&
9291                           name[7] == 'm')
9292                       {                           /* getgrnam   */
9293                         return -KEY_getgrnam;
9294                       }
9295
9296                       goto unknown;
9297
9298                     default:
9299                       goto unknown;
9300                   }
9301                 }
9302
9303                 goto unknown;
9304
9305               case 'l':
9306                 if (name[4] == 'o' &&
9307                     name[5] == 'g' &&
9308                     name[6] == 'i' &&
9309                     name[7] == 'n')
9310                 {                                 /* getlogin   */
9311                   return -KEY_getlogin;
9312                 }
9313
9314                 goto unknown;
9315
9316               case 'p':
9317                 if (name[4] == 'w')
9318                 {
9319                   switch (name[5])
9320                   {
9321                     case 'e':
9322                       if (name[6] == 'n' &&
9323                           name[7] == 't')
9324                       {                           /* getpwent   */
9325                         return -KEY_getpwent;
9326                       }
9327
9328                       goto unknown;
9329
9330                     case 'n':
9331                       if (name[6] == 'a' &&
9332                           name[7] == 'm')
9333                       {                           /* getpwnam   */
9334                         return -KEY_getpwnam;
9335                       }
9336
9337                       goto unknown;
9338
9339                     case 'u':
9340                       if (name[6] == 'i' &&
9341                           name[7] == 'd')
9342                       {                           /* getpwuid   */
9343                         return -KEY_getpwuid;
9344                       }
9345
9346                       goto unknown;
9347
9348                     default:
9349                       goto unknown;
9350                   }
9351                 }
9352
9353                 goto unknown;
9354
9355               default:
9356                 goto unknown;
9357             }
9358           }
9359
9360           goto unknown;
9361
9362         case 'r':
9363           if (name[1] == 'e' &&
9364               name[2] == 'a' &&
9365               name[3] == 'd')
9366           {
9367             switch (name[4])
9368             {
9369               case 'l':
9370                 if (name[5] == 'i' &&
9371                     name[6] == 'n')
9372                 {
9373                   switch (name[7])
9374                   {
9375                     case 'e':
9376                       {                           /* readline   */
9377                         return -KEY_readline;
9378                       }
9379
9380                     case 'k':
9381                       {                           /* readlink   */
9382                         return -KEY_readlink;
9383                       }
9384
9385                     default:
9386                       goto unknown;
9387                   }
9388                 }
9389
9390                 goto unknown;
9391
9392               case 'p':
9393                 if (name[5] == 'i' &&
9394                     name[6] == 'p' &&
9395                     name[7] == 'e')
9396                 {                                 /* readpipe   */
9397                   return -KEY_readpipe;
9398                 }
9399
9400                 goto unknown;
9401
9402               default:
9403                 goto unknown;
9404             }
9405           }
9406
9407           goto unknown;
9408
9409         case 's':
9410           switch (name[1])
9411           {
9412             case 'e':
9413               if (name[2] == 't')
9414               {
9415                 switch (name[3])
9416                 {
9417                   case 'g':
9418                     if (name[4] == 'r' &&
9419                         name[5] == 'e' &&
9420                         name[6] == 'n' &&
9421                         name[7] == 't')
9422                     {                             /* setgrent   */
9423                       return -KEY_setgrent;
9424                     }
9425
9426                     goto unknown;
9427
9428                   case 'p':
9429                     if (name[4] == 'w' &&
9430                         name[5] == 'e' &&
9431                         name[6] == 'n' &&
9432                         name[7] == 't')
9433                     {                             /* setpwent   */
9434                       return -KEY_setpwent;
9435                     }
9436
9437                     goto unknown;
9438
9439                   default:
9440                     goto unknown;
9441                 }
9442               }
9443
9444               goto unknown;
9445
9446             case 'h':
9447               switch (name[2])
9448               {
9449                 case 'm':
9450                   if (name[3] == 'w' &&
9451                       name[4] == 'r' &&
9452                       name[5] == 'i' &&
9453                       name[6] == 't' &&
9454                       name[7] == 'e')
9455                   {                               /* shmwrite   */
9456                     return -KEY_shmwrite;
9457                   }
9458
9459                   goto unknown;
9460
9461                 case 'u':
9462                   if (name[3] == 't' &&
9463                       name[4] == 'd' &&
9464                       name[5] == 'o' &&
9465                       name[6] == 'w' &&
9466                       name[7] == 'n')
9467                   {                               /* shutdown   */
9468                     return -KEY_shutdown;
9469                   }
9470
9471                   goto unknown;
9472
9473                 default:
9474                   goto unknown;
9475               }
9476
9477             case 'y':
9478               if (name[2] == 's' &&
9479                   name[3] == 'w' &&
9480                   name[4] == 'r' &&
9481                   name[5] == 'i' &&
9482                   name[6] == 't' &&
9483                   name[7] == 'e')
9484               {                                   /* syswrite   */
9485                 return -KEY_syswrite;
9486               }
9487
9488               goto unknown;
9489
9490             default:
9491               goto unknown;
9492           }
9493
9494         case 't':
9495           if (name[1] == 'r' &&
9496               name[2] == 'u' &&
9497               name[3] == 'n' &&
9498               name[4] == 'c' &&
9499               name[5] == 'a' &&
9500               name[6] == 't' &&
9501               name[7] == 'e')
9502           {                                       /* truncate   */
9503             return -KEY_truncate;
9504           }
9505
9506           goto unknown;
9507
9508         default:
9509           goto unknown;
9510       }
9511
9512     case 9: /* 8 tokens of length 9 */
9513       switch (name[0])
9514       {
9515         case 'e':
9516           if (name[1] == 'n' &&
9517               name[2] == 'd' &&
9518               name[3] == 'n' &&
9519               name[4] == 'e' &&
9520               name[5] == 't' &&
9521               name[6] == 'e' &&
9522               name[7] == 'n' &&
9523               name[8] == 't')
9524           {                                       /* endnetent  */
9525             return -KEY_endnetent;
9526           }
9527
9528           goto unknown;
9529
9530         case 'g':
9531           if (name[1] == 'e' &&
9532               name[2] == 't' &&
9533               name[3] == 'n' &&
9534               name[4] == 'e' &&
9535               name[5] == 't' &&
9536               name[6] == 'e' &&
9537               name[7] == 'n' &&
9538               name[8] == 't')
9539           {                                       /* getnetent  */
9540             return -KEY_getnetent;
9541           }
9542
9543           goto unknown;
9544
9545         case 'l':
9546           if (name[1] == 'o' &&
9547               name[2] == 'c' &&
9548               name[3] == 'a' &&
9549               name[4] == 'l' &&
9550               name[5] == 't' &&
9551               name[6] == 'i' &&
9552               name[7] == 'm' &&
9553               name[8] == 'e')
9554           {                                       /* localtime  */
9555             return -KEY_localtime;
9556           }
9557
9558           goto unknown;
9559
9560         case 'p':
9561           if (name[1] == 'r' &&
9562               name[2] == 'o' &&
9563               name[3] == 't' &&
9564               name[4] == 'o' &&
9565               name[5] == 't' &&
9566               name[6] == 'y' &&
9567               name[7] == 'p' &&
9568               name[8] == 'e')
9569           {                                       /* prototype  */
9570             return KEY_prototype;
9571           }
9572
9573           goto unknown;
9574
9575         case 'q':
9576           if (name[1] == 'u' &&
9577               name[2] == 'o' &&
9578               name[3] == 't' &&
9579               name[4] == 'e' &&
9580               name[5] == 'm' &&
9581               name[6] == 'e' &&
9582               name[7] == 't' &&
9583               name[8] == 'a')
9584           {                                       /* quotemeta  */
9585             return -KEY_quotemeta;
9586           }
9587
9588           goto unknown;
9589
9590         case 'r':
9591           if (name[1] == 'e' &&
9592               name[2] == 'w' &&
9593               name[3] == 'i' &&
9594               name[4] == 'n' &&
9595               name[5] == 'd' &&
9596               name[6] == 'd' &&
9597               name[7] == 'i' &&
9598               name[8] == 'r')
9599           {                                       /* rewinddir  */
9600             return -KEY_rewinddir;
9601           }
9602
9603           goto unknown;
9604
9605         case 's':
9606           if (name[1] == 'e' &&
9607               name[2] == 't' &&
9608               name[3] == 'n' &&
9609               name[4] == 'e' &&
9610               name[5] == 't' &&
9611               name[6] == 'e' &&
9612               name[7] == 'n' &&
9613               name[8] == 't')
9614           {                                       /* setnetent  */
9615             return -KEY_setnetent;
9616           }
9617
9618           goto unknown;
9619
9620         case 'w':
9621           if (name[1] == 'a' &&
9622               name[2] == 'n' &&
9623               name[3] == 't' &&
9624               name[4] == 'a' &&
9625               name[5] == 'r' &&
9626               name[6] == 'r' &&
9627               name[7] == 'a' &&
9628               name[8] == 'y')
9629           {                                       /* wantarray  */
9630             return -KEY_wantarray;
9631           }
9632
9633           goto unknown;
9634
9635         default:
9636           goto unknown;
9637       }
9638
9639     case 10: /* 9 tokens of length 10 */
9640       switch (name[0])
9641       {
9642         case 'e':
9643           if (name[1] == 'n' &&
9644               name[2] == 'd')
9645           {
9646             switch (name[3])
9647             {
9648               case 'h':
9649                 if (name[4] == 'o' &&
9650                     name[5] == 's' &&
9651                     name[6] == 't' &&
9652                     name[7] == 'e' &&
9653                     name[8] == 'n' &&
9654                     name[9] == 't')
9655                 {                                 /* endhostent */
9656                   return -KEY_endhostent;
9657                 }
9658
9659                 goto unknown;
9660
9661               case 's':
9662                 if (name[4] == 'e' &&
9663                     name[5] == 'r' &&
9664                     name[6] == 'v' &&
9665                     name[7] == 'e' &&
9666                     name[8] == 'n' &&
9667                     name[9] == 't')
9668                 {                                 /* endservent */
9669                   return -KEY_endservent;
9670                 }
9671
9672                 goto unknown;
9673
9674               default:
9675                 goto unknown;
9676             }
9677           }
9678
9679           goto unknown;
9680
9681         case 'g':
9682           if (name[1] == 'e' &&
9683               name[2] == 't')
9684           {
9685             switch (name[3])
9686             {
9687               case 'h':
9688                 if (name[4] == 'o' &&
9689                     name[5] == 's' &&
9690                     name[6] == 't' &&
9691                     name[7] == 'e' &&
9692                     name[8] == 'n' &&
9693                     name[9] == 't')
9694                 {                                 /* gethostent */
9695                   return -KEY_gethostent;
9696                 }
9697
9698                 goto unknown;
9699
9700               case 's':
9701                 switch (name[4])
9702                 {
9703                   case 'e':
9704                     if (name[5] == 'r' &&
9705                         name[6] == 'v' &&
9706                         name[7] == 'e' &&
9707                         name[8] == 'n' &&
9708                         name[9] == 't')
9709                     {                             /* getservent */
9710                       return -KEY_getservent;
9711                     }
9712
9713                     goto unknown;
9714
9715                   case 'o':
9716                     if (name[5] == 'c' &&
9717                         name[6] == 'k' &&
9718                         name[7] == 'o' &&
9719                         name[8] == 'p' &&
9720                         name[9] == 't')
9721                     {                             /* getsockopt */
9722                       return -KEY_getsockopt;
9723                     }
9724
9725                     goto unknown;
9726
9727                   default:
9728                     goto unknown;
9729                 }
9730
9731               default:
9732                 goto unknown;
9733             }
9734           }
9735
9736           goto unknown;
9737
9738         case 's':
9739           switch (name[1])
9740           {
9741             case 'e':
9742               if (name[2] == 't')
9743               {
9744                 switch (name[3])
9745                 {
9746                   case 'h':
9747                     if (name[4] == 'o' &&
9748                         name[5] == 's' &&
9749                         name[6] == 't' &&
9750                         name[7] == 'e' &&
9751                         name[8] == 'n' &&
9752                         name[9] == 't')
9753                     {                             /* sethostent */
9754                       return -KEY_sethostent;
9755                     }
9756
9757                     goto unknown;
9758
9759                   case 's':
9760                     switch (name[4])
9761                     {
9762                       case 'e':
9763                         if (name[5] == 'r' &&
9764                             name[6] == 'v' &&
9765                             name[7] == 'e' &&
9766                             name[8] == 'n' &&
9767                             name[9] == 't')
9768                         {                         /* setservent */
9769                           return -KEY_setservent;
9770                         }
9771
9772                         goto unknown;
9773
9774                       case 'o':
9775                         if (name[5] == 'c' &&
9776                             name[6] == 'k' &&
9777                             name[7] == 'o' &&
9778                             name[8] == 'p' &&
9779                             name[9] == 't')
9780                         {                         /* setsockopt */
9781                           return -KEY_setsockopt;
9782                         }
9783
9784                         goto unknown;
9785
9786                       default:
9787                         goto unknown;
9788                     }
9789
9790                   default:
9791                     goto unknown;
9792                 }
9793               }
9794
9795               goto unknown;
9796
9797             case 'o':
9798               if (name[2] == 'c' &&
9799                   name[3] == 'k' &&
9800                   name[4] == 'e' &&
9801                   name[5] == 't' &&
9802                   name[6] == 'p' &&
9803                   name[7] == 'a' &&
9804                   name[8] == 'i' &&
9805                   name[9] == 'r')
9806               {                                   /* socketpair */
9807                 return -KEY_socketpair;
9808               }
9809
9810               goto unknown;
9811
9812             default:
9813               goto unknown;
9814           }
9815
9816         default:
9817           goto unknown;
9818       }
9819
9820     case 11: /* 8 tokens of length 11 */
9821       switch (name[0])
9822       {
9823         case '_':
9824           if (name[1] == '_' &&
9825               name[2] == 'P' &&
9826               name[3] == 'A' &&
9827               name[4] == 'C' &&
9828               name[5] == 'K' &&
9829               name[6] == 'A' &&
9830               name[7] == 'G' &&
9831               name[8] == 'E' &&
9832               name[9] == '_' &&
9833               name[10] == '_')
9834           {                                       /* __PACKAGE__ */
9835             return -KEY___PACKAGE__;
9836           }
9837
9838           goto unknown;
9839
9840         case 'e':
9841           if (name[1] == 'n' &&
9842               name[2] == 'd' &&
9843               name[3] == 'p' &&
9844               name[4] == 'r' &&
9845               name[5] == 'o' &&
9846               name[6] == 't' &&
9847               name[7] == 'o' &&
9848               name[8] == 'e' &&
9849               name[9] == 'n' &&
9850               name[10] == 't')
9851           {                                       /* endprotoent */
9852             return -KEY_endprotoent;
9853           }
9854
9855           goto unknown;
9856
9857         case 'g':
9858           if (name[1] == 'e' &&
9859               name[2] == 't')
9860           {
9861             switch (name[3])
9862             {
9863               case 'p':
9864                 switch (name[4])
9865                 {
9866                   case 'e':
9867                     if (name[5] == 'e' &&
9868                         name[6] == 'r' &&
9869                         name[7] == 'n' &&
9870                         name[8] == 'a' &&
9871                         name[9] == 'm' &&
9872                         name[10] == 'e')
9873                     {                             /* getpeername */
9874                       return -KEY_getpeername;
9875                     }
9876
9877                     goto unknown;
9878
9879                   case 'r':
9880                     switch (name[5])
9881                     {
9882                       case 'i':
9883                         if (name[6] == 'o' &&
9884                             name[7] == 'r' &&
9885                             name[8] == 'i' &&
9886                             name[9] == 't' &&
9887                             name[10] == 'y')
9888                         {                         /* getpriority */
9889                           return -KEY_getpriority;
9890                         }
9891
9892                         goto unknown;
9893
9894                       case 'o':
9895                         if (name[6] == 't' &&
9896                             name[7] == 'o' &&
9897                             name[8] == 'e' &&
9898                             name[9] == 'n' &&
9899                             name[10] == 't')
9900                         {                         /* getprotoent */
9901                           return -KEY_getprotoent;
9902                         }
9903
9904                         goto unknown;
9905
9906                       default:
9907                         goto unknown;
9908                     }
9909
9910                   default:
9911                     goto unknown;
9912                 }
9913
9914               case 's':
9915                 if (name[4] == 'o' &&
9916                     name[5] == 'c' &&
9917                     name[6] == 'k' &&
9918                     name[7] == 'n' &&
9919                     name[8] == 'a' &&
9920                     name[9] == 'm' &&
9921                     name[10] == 'e')
9922                 {                                 /* getsockname */
9923                   return -KEY_getsockname;
9924                 }
9925
9926                 goto unknown;
9927
9928               default:
9929                 goto unknown;
9930             }
9931           }
9932
9933           goto unknown;
9934
9935         case 's':
9936           if (name[1] == 'e' &&
9937               name[2] == 't' &&
9938               name[3] == 'p' &&
9939               name[4] == 'r')
9940           {
9941             switch (name[5])
9942             {
9943               case 'i':
9944                 if (name[6] == 'o' &&
9945                     name[7] == 'r' &&
9946                     name[8] == 'i' &&
9947                     name[9] == 't' &&
9948                     name[10] == 'y')
9949                 {                                 /* setpriority */
9950                   return -KEY_setpriority;
9951                 }
9952
9953                 goto unknown;
9954
9955               case 'o':
9956                 if (name[6] == 't' &&
9957                     name[7] == 'o' &&
9958                     name[8] == 'e' &&
9959                     name[9] == 'n' &&
9960                     name[10] == 't')
9961                 {                                 /* setprotoent */
9962                   return -KEY_setprotoent;
9963                 }
9964
9965                 goto unknown;
9966
9967               default:
9968                 goto unknown;
9969             }
9970           }
9971
9972           goto unknown;
9973
9974         default:
9975           goto unknown;
9976       }
9977
9978     case 12: /* 2 tokens of length 12 */
9979       if (name[0] == 'g' &&
9980           name[1] == 'e' &&
9981           name[2] == 't' &&
9982           name[3] == 'n' &&
9983           name[4] == 'e' &&
9984           name[5] == 't' &&
9985           name[6] == 'b' &&
9986           name[7] == 'y')
9987       {
9988         switch (name[8])
9989         {
9990           case 'a':
9991             if (name[9] == 'd' &&
9992                 name[10] == 'd' &&
9993                 name[11] == 'r')
9994             {                                     /* getnetbyaddr */
9995               return -KEY_getnetbyaddr;
9996             }
9997
9998             goto unknown;
9999
10000           case 'n':
10001             if (name[9] == 'a' &&
10002                 name[10] == 'm' &&
10003                 name[11] == 'e')
10004             {                                     /* getnetbyname */
10005               return -KEY_getnetbyname;
10006             }
10007
10008             goto unknown;
10009
10010           default:
10011             goto unknown;
10012         }
10013       }
10014
10015       goto unknown;
10016
10017     case 13: /* 4 tokens of length 13 */
10018       if (name[0] == 'g' &&
10019           name[1] == 'e' &&
10020           name[2] == 't')
10021       {
10022         switch (name[3])
10023         {
10024           case 'h':
10025             if (name[4] == 'o' &&
10026                 name[5] == 's' &&
10027                 name[6] == 't' &&
10028                 name[7] == 'b' &&
10029                 name[8] == 'y')
10030             {
10031               switch (name[9])
10032               {
10033                 case 'a':
10034                   if (name[10] == 'd' &&
10035                       name[11] == 'd' &&
10036                       name[12] == 'r')
10037                   {                               /* gethostbyaddr */
10038                     return -KEY_gethostbyaddr;
10039                   }
10040
10041                   goto unknown;
10042
10043                 case 'n':
10044                   if (name[10] == 'a' &&
10045                       name[11] == 'm' &&
10046                       name[12] == 'e')
10047                   {                               /* gethostbyname */
10048                     return -KEY_gethostbyname;
10049                   }
10050
10051                   goto unknown;
10052
10053                 default:
10054                   goto unknown;
10055               }
10056             }
10057
10058             goto unknown;
10059
10060           case 's':
10061             if (name[4] == 'e' &&
10062                 name[5] == 'r' &&
10063                 name[6] == 'v' &&
10064                 name[7] == 'b' &&
10065                 name[8] == 'y')
10066             {
10067               switch (name[9])
10068               {
10069                 case 'n':
10070                   if (name[10] == 'a' &&
10071                       name[11] == 'm' &&
10072                       name[12] == 'e')
10073                   {                               /* getservbyname */
10074                     return -KEY_getservbyname;
10075                   }
10076
10077                   goto unknown;
10078
10079                 case 'p':
10080                   if (name[10] == 'o' &&
10081                       name[11] == 'r' &&
10082                       name[12] == 't')
10083                   {                               /* getservbyport */
10084                     return -KEY_getservbyport;
10085                   }
10086
10087                   goto unknown;
10088
10089                 default:
10090                   goto unknown;
10091               }
10092             }
10093
10094             goto unknown;
10095
10096           default:
10097             goto unknown;
10098         }
10099       }
10100
10101       goto unknown;
10102
10103     case 14: /* 1 tokens of length 14 */
10104       if (name[0] == 'g' &&
10105           name[1] == 'e' &&
10106           name[2] == 't' &&
10107           name[3] == 'p' &&
10108           name[4] == 'r' &&
10109           name[5] == 'o' &&
10110           name[6] == 't' &&
10111           name[7] == 'o' &&
10112           name[8] == 'b' &&
10113           name[9] == 'y' &&
10114           name[10] == 'n' &&
10115           name[11] == 'a' &&
10116           name[12] == 'm' &&
10117           name[13] == 'e')
10118       {                                           /* getprotobyname */
10119         return -KEY_getprotobyname;
10120       }
10121
10122       goto unknown;
10123
10124     case 16: /* 1 tokens of length 16 */
10125       if (name[0] == 'g' &&
10126           name[1] == 'e' &&
10127           name[2] == 't' &&
10128           name[3] == 'p' &&
10129           name[4] == 'r' &&
10130           name[5] == 'o' &&
10131           name[6] == 't' &&
10132           name[7] == 'o' &&
10133           name[8] == 'b' &&
10134           name[9] == 'y' &&
10135           name[10] == 'n' &&
10136           name[11] == 'u' &&
10137           name[12] == 'm' &&
10138           name[13] == 'b' &&
10139           name[14] == 'e' &&
10140           name[15] == 'r')
10141       {                                           /* getprotobynumber */
10142         return -KEY_getprotobynumber;
10143       }
10144
10145       goto unknown;
10146
10147     default:
10148       goto unknown;
10149   }
10150
10151 unknown:
10152   return 0;
10153 }
10154
10155 STATIC void
10156 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10157 {
10158     dVAR;
10159
10160     if (*s == ' ' && s[1] == '(') {     /* XXX gotta be a better way */
10161         if (ckWARN(WARN_SYNTAX)) {
10162             int level = 1;
10163             const char *w;
10164             for (w = s+2; *w && level; w++) {
10165                 if (*w == '(')
10166                     ++level;
10167                 else if (*w == ')')
10168                     --level;
10169             }
10170             while (isSPACE(*w))
10171                 ++w;
10172             if (!*w || !strchr(";|})]oaiuw!=", *w))     /* an advisory hack only... */
10173                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10174                             "%s (...) interpreted as function",name);
10175         }
10176     }
10177     while (s < PL_bufend && isSPACE(*s))
10178         s++;
10179     if (*s == '(')
10180         s++;
10181     while (s < PL_bufend && isSPACE(*s))
10182         s++;
10183     if (isIDFIRST_lazy_if(s,UTF)) {
10184         const char * const w = s++;
10185         while (isALNUM_lazy_if(s,UTF))
10186             s++;
10187         while (s < PL_bufend && isSPACE(*s))
10188             s++;
10189         if (*s == ',') {
10190             GV* gv;
10191             if (keyword(w, s - w))
10192                 return;
10193
10194             gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10195             if (gv && GvCVu(gv))
10196                 return;
10197             Perl_croak(aTHX_ "No comma allowed after %s", what);
10198         }
10199     }
10200 }
10201
10202 /* Either returns sv, or mortalizes sv and returns a new SV*.
10203    Best used as sv=new_constant(..., sv, ...).
10204    If s, pv are NULL, calls subroutine with one argument,
10205    and type is used with error messages only. */
10206
10207 STATIC SV *
10208 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10209                const char *type)
10210 {
10211     dVAR; dSP;
10212     HV * const table = GvHV(PL_hintgv);          /* ^H */
10213     SV *res;
10214     SV **cvp;
10215     SV *cv, *typesv;
10216     const char *why1 = "", *why2 = "", *why3 = "";
10217
10218     if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10219         SV *msg;
10220         
10221         why2 = strEQ(key,"charnames")
10222                ? "(possibly a missing \"use charnames ...\")"
10223                : "";
10224         msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10225                             (type ? type: "undef"), why2);
10226
10227         /* This is convoluted and evil ("goto considered harmful")
10228          * but I do not understand the intricacies of all the different
10229          * failure modes of %^H in here.  The goal here is to make
10230          * the most probable error message user-friendly. --jhi */
10231
10232         goto msgdone;
10233
10234     report:
10235         msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10236                             (type ? type: "undef"), why1, why2, why3);
10237     msgdone:
10238         yyerror(SvPVX_const(msg));
10239         SvREFCNT_dec(msg);
10240         return sv;
10241     }
10242     cvp = hv_fetch(table, key, strlen(key), FALSE);
10243     if (!cvp || !SvOK(*cvp)) {
10244         why1 = "$^H{";
10245         why2 = key;
10246         why3 = "} is not defined";
10247         goto report;
10248     }
10249     sv_2mortal(sv);                     /* Parent created it permanently */
10250     cv = *cvp;
10251     if (!pv && s)
10252         pv = sv_2mortal(newSVpvn(s, len));
10253     if (type && pv)
10254         typesv = sv_2mortal(newSVpv(type, 0));
10255     else
10256         typesv = &PL_sv_undef;
10257
10258     PUSHSTACKi(PERLSI_OVERLOAD);
10259     ENTER ;
10260     SAVETMPS;
10261
10262     PUSHMARK(SP) ;
10263     EXTEND(sp, 3);
10264     if (pv)
10265         PUSHs(pv);
10266     PUSHs(sv);
10267     if (pv)
10268         PUSHs(typesv);
10269     PUTBACK;
10270     call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10271
10272     SPAGAIN ;
10273
10274     /* Check the eval first */
10275     if (!PL_in_eval && SvTRUE(ERRSV)) {
10276         sv_catpvs(ERRSV, "Propagated");
10277         yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10278         (void)POPs;
10279         res = SvREFCNT_inc_simple(sv);
10280     }
10281     else {
10282         res = POPs;
10283         SvREFCNT_inc_simple_void(res);
10284     }
10285
10286     PUTBACK ;
10287     FREETMPS ;
10288     LEAVE ;
10289     POPSTACK;
10290
10291     if (!SvOK(res)) {
10292         why1 = "Call to &{$^H{";
10293         why2 = key;
10294         why3 = "}} did not return a defined value";
10295         sv = res;
10296         goto report;
10297     }
10298
10299     return res;
10300 }
10301
10302 /* Returns a NUL terminated string, with the length of the string written to
10303    *slp
10304    */
10305 STATIC char *
10306 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10307 {
10308     dVAR;
10309     register char *d = dest;
10310     register char * const e = d + destlen - 3;  /* two-character token, ending NUL */
10311     for (;;) {
10312         if (d >= e)
10313             Perl_croak(aTHX_ ident_too_long);
10314         if (isALNUM(*s))        /* UTF handled below */
10315             *d++ = *s++;
10316         else if (*s == '\'' && allow_package && isIDFIRST_lazy_if(s+1,UTF)) {
10317             *d++ = ':';
10318             *d++ = ':';
10319             s++;
10320         }
10321         else if (*s == ':' && s[1] == ':' && allow_package && s[2] != '$') {
10322             *d++ = *s++;
10323             *d++ = *s++;
10324         }
10325         else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10326             char *t = s + UTF8SKIP(s);
10327             while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10328                 t += UTF8SKIP(t);
10329             if (d + (t - s) > e)
10330                 Perl_croak(aTHX_ ident_too_long);
10331             Copy(s, d, t - s, char);
10332             d += t - s;
10333             s = t;
10334         }
10335         else {
10336             *d = '\0';
10337             *slp = d - dest;
10338             return s;
10339         }
10340     }
10341 }
10342
10343 STATIC char *
10344 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10345 {
10346     dVAR;
10347     char *bracket = NULL;
10348     char funny = *s++;
10349     register char *d = dest;
10350     register char * const e = d + destlen + 3;    /* two-character token, ending NUL */
10351
10352     if (isSPACE(*s))
10353         s = PEEKSPACE(s);
10354     if (isDIGIT(*s)) {
10355         while (isDIGIT(*s)) {
10356             if (d >= e)
10357                 Perl_croak(aTHX_ ident_too_long);
10358             *d++ = *s++;
10359         }
10360     }
10361     else {
10362         for (;;) {
10363             if (d >= e)
10364                 Perl_croak(aTHX_ ident_too_long);
10365             if (isALNUM(*s))    /* UTF handled below */
10366                 *d++ = *s++;
10367             else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10368                 *d++ = ':';
10369                 *d++ = ':';
10370                 s++;
10371             }
10372             else if (*s == ':' && s[1] == ':') {
10373                 *d++ = *s++;
10374                 *d++ = *s++;
10375             }
10376             else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10377                 char *t = s + UTF8SKIP(s);
10378                 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10379                     t += UTF8SKIP(t);
10380                 if (d + (t - s) > e)
10381                     Perl_croak(aTHX_ ident_too_long);
10382                 Copy(s, d, t - s, char);
10383                 d += t - s;
10384                 s = t;
10385             }
10386             else
10387                 break;
10388         }
10389     }
10390     *d = '\0';
10391     d = dest;
10392     if (*d) {
10393         if (PL_lex_state != LEX_NORMAL)
10394             PL_lex_state = LEX_INTERPENDMAYBE;
10395         return s;
10396     }
10397     if (*s == '$' && s[1] &&
10398         (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10399     {
10400         return s;
10401     }
10402     if (*s == '{') {
10403         bracket = s;
10404         s++;
10405     }
10406     else if (ck_uni)
10407         check_uni();
10408     if (s < send)
10409         *d = *s++;
10410     d[1] = '\0';
10411     if (*d == '^' && *s && isCONTROLVAR(*s)) {
10412         *d = toCTRL(*s);
10413         s++;
10414     }
10415     if (bracket) {
10416         if (isSPACE(s[-1])) {
10417             while (s < send) {
10418                 const char ch = *s++;
10419                 if (!SPACE_OR_TAB(ch)) {
10420                     *d = ch;
10421                     break;
10422                 }
10423             }
10424         }
10425         if (isIDFIRST_lazy_if(d,UTF)) {
10426             d++;
10427             if (UTF) {
10428                 char *end = s;
10429                 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10430                     end += UTF8SKIP(end);
10431                     while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10432                         end += UTF8SKIP(end);
10433                 }
10434                 Copy(s, d, end - s, char);
10435                 d += end - s;
10436                 s = end;
10437             }
10438             else {
10439                 while ((isALNUM(*s) || *s == ':') && d < e)
10440                     *d++ = *s++;
10441                 if (d >= e)
10442                     Perl_croak(aTHX_ ident_too_long);
10443             }
10444             *d = '\0';
10445             while (s < send && SPACE_OR_TAB(*s)) s++;
10446             if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10447                 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest)) {
10448                     const char *brack = *s == '[' ? "[...]" : "{...}";
10449                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10450                         "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10451                         funny, dest, brack, funny, dest, brack);
10452                 }
10453                 bracket++;
10454                 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10455                 return s;
10456             }
10457         }
10458         /* Handle extended ${^Foo} variables
10459          * 1999-02-27 mjd-perl-patch@plover.com */
10460         else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10461                  && isALNUM(*s))
10462         {
10463             d++;
10464             while (isALNUM(*s) && d < e) {
10465                 *d++ = *s++;
10466             }
10467             if (d >= e)
10468                 Perl_croak(aTHX_ ident_too_long);
10469             *d = '\0';
10470         }
10471         if (*s == '}') {
10472             s++;
10473             if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10474                 PL_lex_state = LEX_INTERPEND;
10475                 PL_expect = XREF;
10476             }
10477             if (funny == '#')
10478                 funny = '@';
10479             if (PL_lex_state == LEX_NORMAL) {
10480                 if (ckWARN(WARN_AMBIGUOUS) &&
10481                     (keyword(dest, d - dest) || get_cv(dest, FALSE)))
10482                 {
10483                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10484                         "Ambiguous use of %c{%s} resolved to %c%s",
10485                         funny, dest, funny, dest);
10486                 }
10487             }
10488         }
10489         else {
10490             s = bracket;                /* let the parser handle it */
10491             *dest = '\0';
10492         }
10493     }
10494     else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10495         PL_lex_state = LEX_INTERPEND;
10496     return s;
10497 }
10498
10499 void
10500 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10501 {
10502     PERL_UNUSED_CONTEXT;
10503     if (ch == 'i')
10504         *pmfl |= PMf_FOLD;
10505     else if (ch == 'g')
10506         *pmfl |= PMf_GLOBAL;
10507     else if (ch == 'c')
10508         *pmfl |= PMf_CONTINUE;
10509     else if (ch == 'o')
10510         *pmfl |= PMf_KEEP;
10511     else if (ch == 'm')
10512         *pmfl |= PMf_MULTILINE;
10513     else if (ch == 's')
10514         *pmfl |= PMf_SINGLELINE;
10515     else if (ch == 'x')
10516         *pmfl |= PMf_EXTENDED;
10517 }
10518
10519 STATIC char *
10520 S_scan_pat(pTHX_ char *start, I32 type)
10521 {
10522     dVAR;
10523     PMOP *pm;
10524     char *s = scan_str(start,!!PL_madskills,FALSE);
10525     const char * const valid_flags = (type == OP_QR) ? "iomsx" : "iogcmsx";
10526 #ifdef PERL_MAD
10527     char *modstart;
10528 #endif
10529
10530
10531     if (!s) {
10532         const char * const delimiter = skipspace(start);
10533         Perl_croak(aTHX_ *delimiter == '?'
10534                    ? "Search pattern not terminated or ternary operator parsed as search pattern"
10535                    : "Search pattern not terminated" );
10536     }
10537
10538     pm = (PMOP*)newPMOP(type, 0);
10539     if (PL_multi_open == '?')
10540         pm->op_pmflags |= PMf_ONCE;
10541 #ifdef PERL_MAD
10542     modstart = s;
10543 #endif
10544     while (*s && strchr(valid_flags, *s))
10545         pmflag(&pm->op_pmflags,*s++);
10546 #ifdef PERL_MAD
10547     if (PL_madskills && modstart != s) {
10548         SV* tmptoken = newSVpvn(modstart, s - modstart);
10549         append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10550     }
10551 #endif
10552     /* issue a warning if /c is specified,but /g is not */
10553     if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10554             && ckWARN(WARN_REGEXP))
10555     {
10556         Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless without /g" );
10557     }
10558
10559     pm->op_pmpermflags = pm->op_pmflags;
10560
10561     PL_lex_op = (OP*)pm;
10562     yylval.ival = OP_MATCH;
10563     return s;
10564 }
10565
10566 STATIC char *
10567 S_scan_subst(pTHX_ char *start)
10568 {
10569     dVAR;
10570     register char *s;
10571     register PMOP *pm;
10572     I32 first_start;
10573     I32 es = 0;
10574 #ifdef PERL_MAD
10575     char *modstart;
10576 #endif
10577
10578     yylval.ival = OP_NULL;
10579
10580     s = scan_str(start,!!PL_madskills,FALSE);
10581
10582     if (!s)
10583         Perl_croak(aTHX_ "Substitution pattern not terminated");
10584
10585     if (s[-1] == PL_multi_open)
10586         s--;
10587 #ifdef PERL_MAD
10588     if (PL_madskills) {
10589         CURMAD('q', PL_thisopen);
10590         CURMAD('_', PL_thiswhite);
10591         CURMAD('E', PL_thisstuff);
10592         CURMAD('Q', PL_thisclose);
10593         PL_realtokenstart = s - SvPVX(PL_linestr);
10594     }
10595 #endif
10596
10597     first_start = PL_multi_start;
10598     s = scan_str(s,!!PL_madskills,FALSE);
10599     if (!s) {
10600         if (PL_lex_stuff) {
10601             SvREFCNT_dec(PL_lex_stuff);
10602             PL_lex_stuff = NULL;
10603         }
10604         Perl_croak(aTHX_ "Substitution replacement not terminated");
10605     }
10606     PL_multi_start = first_start;       /* so whole substitution is taken together */
10607
10608     pm = (PMOP*)newPMOP(OP_SUBST, 0);
10609
10610 #ifdef PERL_MAD
10611     if (PL_madskills) {
10612         CURMAD('z', PL_thisopen);
10613         CURMAD('R', PL_thisstuff);
10614         CURMAD('Z', PL_thisclose);
10615     }
10616     modstart = s;
10617 #endif
10618
10619     while (*s) {
10620         if (*s == 'e') {
10621             s++;
10622             es++;
10623         }
10624         else if (strchr("iogcmsx", *s))
10625             pmflag(&pm->op_pmflags,*s++);
10626         else
10627             break;
10628     }
10629
10630 #ifdef PERL_MAD
10631     if (PL_madskills) {
10632         if (modstart != s)
10633             curmad('m', newSVpvn(modstart, s - modstart));
10634         append_madprops(PL_thismad, (OP*)pm, 0);
10635         PL_thismad = 0;
10636     }
10637 #endif
10638     if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10639         Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10640     }
10641
10642     if (es) {
10643         SV * const repl = newSVpvs("");
10644
10645         PL_sublex_info.super_bufptr = s;
10646         PL_sublex_info.super_bufend = PL_bufend;
10647         PL_multi_end = 0;
10648         pm->op_pmflags |= PMf_EVAL;
10649         while (es-- > 0)
10650             sv_catpv(repl, es ? "eval " : "do ");
10651         sv_catpvs(repl, "{");
10652         sv_catsv(repl, PL_lex_repl);
10653         sv_catpvs(repl, "}");
10654         SvEVALED_on(repl);
10655         SvREFCNT_dec(PL_lex_repl);
10656         PL_lex_repl = repl;
10657     }
10658
10659     pm->op_pmpermflags = pm->op_pmflags;
10660     PL_lex_op = (OP*)pm;
10661     yylval.ival = OP_SUBST;
10662     return s;
10663 }
10664
10665 STATIC char *
10666 S_scan_trans(pTHX_ char *start)
10667 {
10668     dVAR;
10669     register char* s;
10670     OP *o;
10671     short *tbl;
10672     I32 squash;
10673     I32 del;
10674     I32 complement;
10675 #ifdef PERL_MAD
10676     char *modstart;
10677 #endif
10678
10679     yylval.ival = OP_NULL;
10680
10681     s = scan_str(start,!!PL_madskills,FALSE);
10682     if (!s)
10683         Perl_croak(aTHX_ "Transliteration pattern not terminated");
10684
10685     if (s[-1] == PL_multi_open)
10686         s--;
10687 #ifdef PERL_MAD
10688     if (PL_madskills) {
10689         CURMAD('q', PL_thisopen);
10690         CURMAD('_', PL_thiswhite);
10691         CURMAD('E', PL_thisstuff);
10692         CURMAD('Q', PL_thisclose);
10693         PL_realtokenstart = s - SvPVX(PL_linestr);
10694     }
10695 #endif
10696
10697     s = scan_str(s,!!PL_madskills,FALSE);
10698     if (!s) {
10699         if (PL_lex_stuff) {
10700             SvREFCNT_dec(PL_lex_stuff);
10701             PL_lex_stuff = NULL;
10702         }
10703         Perl_croak(aTHX_ "Transliteration replacement not terminated");
10704     }
10705     if (PL_madskills) {
10706         CURMAD('z', PL_thisopen);
10707         CURMAD('R', PL_thisstuff);
10708         CURMAD('Z', PL_thisclose);
10709     }
10710
10711     complement = del = squash = 0;
10712 #ifdef PERL_MAD
10713     modstart = s;
10714 #endif
10715     while (1) {
10716         switch (*s) {
10717         case 'c':
10718             complement = OPpTRANS_COMPLEMENT;
10719             break;
10720         case 'd':
10721             del = OPpTRANS_DELETE;
10722             break;
10723         case 's':
10724             squash = OPpTRANS_SQUASH;
10725             break;
10726         default:
10727             goto no_more;
10728         }
10729         s++;
10730     }
10731   no_more:
10732
10733     Newx(tbl, complement&&!del?258:256, short);
10734     o = newPVOP(OP_TRANS, 0, (char*)tbl);
10735     o->op_private &= ~OPpTRANS_ALL;
10736     o->op_private |= del|squash|complement|
10737       (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
10738       (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF   : 0);
10739
10740     PL_lex_op = o;
10741     yylval.ival = OP_TRANS;
10742
10743 #ifdef PERL_MAD
10744     if (PL_madskills) {
10745         if (modstart != s)
10746             curmad('m', newSVpvn(modstart, s - modstart));
10747         append_madprops(PL_thismad, o, 0);
10748         PL_thismad = 0;
10749     }
10750 #endif
10751
10752     return s;
10753 }
10754
10755 STATIC char *
10756 S_scan_heredoc(pTHX_ register char *s)
10757 {
10758     dVAR;
10759     SV *herewas;
10760     I32 op_type = OP_SCALAR;
10761     I32 len;
10762     SV *tmpstr;
10763     char term;
10764     const char *found_newline;
10765     register char *d;
10766     register char *e;
10767     char *peek;
10768     const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
10769 #ifdef PERL_MAD
10770     I32 stuffstart = s - SvPVX(PL_linestr);
10771     char *tstart;
10772  
10773     PL_realtokenstart = -1;
10774 #endif
10775
10776     s += 2;
10777     d = PL_tokenbuf;
10778     e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
10779     if (!outer)
10780         *d++ = '\n';
10781     for (peek = s; SPACE_OR_TAB(*peek); peek++) ;
10782     if (*peek == '`' || *peek == '\'' || *peek =='"') {
10783         s = peek;
10784         term = *s++;
10785         s = delimcpy(d, e, s, PL_bufend, term, &len);
10786         d += len;
10787         if (s < PL_bufend)
10788             s++;
10789     }
10790     else {
10791         if (*s == '\\')
10792             s++, term = '\'';
10793         else
10794             term = '"';
10795         if (!isALNUM_lazy_if(s,UTF))
10796             deprecate_old("bare << to mean <<\"\"");
10797         for (; isALNUM_lazy_if(s,UTF); s++) {
10798             if (d < e)
10799                 *d++ = *s;
10800         }
10801     }
10802     if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
10803         Perl_croak(aTHX_ "Delimiter for here document is too long");
10804     *d++ = '\n';
10805     *d = '\0';
10806     len = d - PL_tokenbuf;
10807
10808 #ifdef PERL_MAD
10809     if (PL_madskills) {
10810         tstart = PL_tokenbuf + !outer;
10811         PL_thisclose = newSVpvn(tstart, len - !outer);
10812         tstart = SvPVX(PL_linestr) + stuffstart;
10813         PL_thisopen = newSVpvn(tstart, s - tstart);
10814         stuffstart = s - SvPVX(PL_linestr);
10815     }
10816 #endif
10817 #ifndef PERL_STRICT_CR
10818     d = strchr(s, '\r');
10819     if (d) {
10820         char * const olds = s;
10821         s = d;
10822         while (s < PL_bufend) {
10823             if (*s == '\r') {
10824                 *d++ = '\n';
10825                 if (*++s == '\n')
10826                     s++;
10827             }
10828             else if (*s == '\n' && s[1] == '\r') {      /* \015\013 on a mac? */
10829                 *d++ = *s++;
10830                 s++;
10831             }
10832             else
10833                 *d++ = *s++;
10834         }
10835         *d = '\0';
10836         PL_bufend = d;
10837         SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
10838         s = olds;
10839     }
10840 #endif
10841 #ifdef PERL_MAD
10842     found_newline = 0;
10843 #endif
10844     if ( outer || !(found_newline = memchr(s, '\n', PL_bufend - s)) ) {
10845         herewas = newSVpvn(s,PL_bufend-s);
10846     }
10847     else {
10848 #ifdef PERL_MAD
10849         herewas = newSVpvn(s-1,found_newline-s+1);
10850 #else
10851         s--;
10852         herewas = newSVpvn(s,found_newline-s);
10853 #endif
10854     }
10855 #ifdef PERL_MAD
10856     if (PL_madskills) {
10857         tstart = SvPVX(PL_linestr) + stuffstart;
10858         if (PL_thisstuff)
10859             sv_catpvn(PL_thisstuff, tstart, s - tstart);
10860         else
10861             PL_thisstuff = newSVpvn(tstart, s - tstart);
10862     }
10863 #endif
10864     s += SvCUR(herewas);
10865
10866 #ifdef PERL_MAD
10867     stuffstart = s - SvPVX(PL_linestr);
10868
10869     if (found_newline)
10870         s--;
10871 #endif
10872
10873     tmpstr = newSV(79);
10874     sv_upgrade(tmpstr, SVt_PVIV);
10875     if (term == '\'') {
10876         op_type = OP_CONST;
10877         SvIV_set(tmpstr, -1);
10878     }
10879     else if (term == '`') {
10880         op_type = OP_BACKTICK;
10881         SvIV_set(tmpstr, '\\');
10882     }
10883
10884     CLINE;
10885     PL_multi_start = CopLINE(PL_curcop);
10886     PL_multi_open = PL_multi_close = '<';
10887     term = *PL_tokenbuf;
10888     if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
10889         char * const bufptr = PL_sublex_info.super_bufptr;
10890         char * const bufend = PL_sublex_info.super_bufend;
10891         char * const olds = s - SvCUR(herewas);
10892         s = strchr(bufptr, '\n');
10893         if (!s)
10894             s = bufend;
10895         d = s;
10896         while (s < bufend &&
10897           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
10898             if (*s++ == '\n')
10899                 CopLINE_inc(PL_curcop);
10900         }
10901         if (s >= bufend) {
10902             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10903             missingterm(PL_tokenbuf);
10904         }
10905         sv_setpvn(herewas,bufptr,d-bufptr+1);
10906         sv_setpvn(tmpstr,d+1,s-d);
10907         s += len - 1;
10908         sv_catpvn(herewas,s,bufend-s);
10909         Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
10910
10911         s = olds;
10912         goto retval;
10913     }
10914     else if (!outer) {
10915         d = s;
10916         while (s < PL_bufend &&
10917           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
10918             if (*s++ == '\n')
10919                 CopLINE_inc(PL_curcop);
10920         }
10921         if (s >= PL_bufend) {
10922             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10923             missingterm(PL_tokenbuf);
10924         }
10925         sv_setpvn(tmpstr,d+1,s-d);
10926 #ifdef PERL_MAD
10927         if (PL_madskills) {
10928             if (PL_thisstuff)
10929                 sv_catpvn(PL_thisstuff, d + 1, s - d);
10930             else
10931                 PL_thisstuff = newSVpvn(d + 1, s - d);
10932             stuffstart = s - SvPVX(PL_linestr);
10933         }
10934 #endif
10935         s += len - 1;
10936         CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
10937
10938         sv_catpvn(herewas,s,PL_bufend-s);
10939         sv_setsv(PL_linestr,herewas);
10940         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
10941         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10942         PL_last_lop = PL_last_uni = NULL;
10943     }
10944     else
10945         sv_setpvn(tmpstr,"",0);   /* avoid "uninitialized" warning */
10946     while (s >= PL_bufend) {    /* multiple line string? */
10947 #ifdef PERL_MAD
10948         if (PL_madskills) {
10949             tstart = SvPVX(PL_linestr) + stuffstart;
10950             if (PL_thisstuff)
10951                 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
10952             else
10953                 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
10954         }
10955 #endif
10956         if (!outer ||
10957          !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
10958             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
10959             missingterm(PL_tokenbuf);
10960         }
10961 #ifdef PERL_MAD
10962         stuffstart = s - SvPVX(PL_linestr);
10963 #endif
10964         CopLINE_inc(PL_curcop);
10965         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10966         PL_last_lop = PL_last_uni = NULL;
10967 #ifndef PERL_STRICT_CR
10968         if (PL_bufend - PL_linestart >= 2) {
10969             if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
10970                 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
10971             {
10972                 PL_bufend[-2] = '\n';
10973                 PL_bufend--;
10974                 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
10975             }
10976             else if (PL_bufend[-1] == '\r')
10977                 PL_bufend[-1] = '\n';
10978         }
10979         else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
10980             PL_bufend[-1] = '\n';
10981 #endif
10982         if (PERLDB_LINE && PL_curstash != PL_debstash) {
10983             SV * const sv = newSV(0);
10984
10985             sv_upgrade(sv, SVt_PVMG);
10986             sv_setsv(sv,PL_linestr);
10987             (void)SvIOK_on(sv);
10988             SvIV_set(sv, 0);
10989             av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop),sv);
10990         }
10991         if (*s == term && memEQ(s,PL_tokenbuf,len)) {
10992             STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
10993             *(SvPVX(PL_linestr) + off ) = ' ';
10994             sv_catsv(PL_linestr,herewas);
10995             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
10996             s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
10997         }
10998         else {
10999             s = PL_bufend;
11000             sv_catsv(tmpstr,PL_linestr);
11001         }
11002     }
11003     s++;
11004 retval:
11005     PL_multi_end = CopLINE(PL_curcop);
11006     if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11007         SvPV_shrink_to_cur(tmpstr);
11008     }
11009     SvREFCNT_dec(herewas);
11010     if (!IN_BYTES) {
11011         if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11012             SvUTF8_on(tmpstr);
11013         else if (PL_encoding)
11014             sv_recode_to_utf8(tmpstr, PL_encoding);
11015     }
11016     PL_lex_stuff = tmpstr;
11017     yylval.ival = op_type;
11018     return s;
11019 }
11020
11021 /* scan_inputsymbol
11022    takes: current position in input buffer
11023    returns: new position in input buffer
11024    side-effects: yylval and lex_op are set.
11025
11026    This code handles:
11027
11028    <>           read from ARGV
11029    <FH>         read from filehandle
11030    <pkg::FH>    read from package qualified filehandle
11031    <pkg'FH>     read from package qualified filehandle
11032    <$fh>        read from filehandle in $fh
11033    <*.h>        filename glob
11034
11035 */
11036
11037 STATIC char *
11038 S_scan_inputsymbol(pTHX_ char *start)
11039 {
11040     dVAR;
11041     register char *s = start;           /* current position in buffer */
11042     char *end;
11043     I32 len;
11044
11045     char *d = PL_tokenbuf;                                      /* start of temp holding space */
11046     const char * const e = PL_tokenbuf + sizeof PL_tokenbuf;    /* end of temp holding space */
11047
11048     end = strchr(s, '\n');
11049     if (!end)
11050         end = PL_bufend;
11051     s = delimcpy(d, e, s + 1, end, '>', &len);  /* extract until > */
11052
11053     /* die if we didn't have space for the contents of the <>,
11054        or if it didn't end, or if we see a newline
11055     */
11056
11057     if (len >= sizeof PL_tokenbuf)
11058         Perl_croak(aTHX_ "Excessively long <> operator");
11059     if (s >= end)
11060         Perl_croak(aTHX_ "Unterminated <> operator");
11061
11062     s++;
11063
11064     /* check for <$fh>
11065        Remember, only scalar variables are interpreted as filehandles by
11066        this code.  Anything more complex (e.g., <$fh{$num}>) will be
11067        treated as a glob() call.
11068        This code makes use of the fact that except for the $ at the front,
11069        a scalar variable and a filehandle look the same.
11070     */
11071     if (*d == '$' && d[1]) d++;
11072
11073     /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11074     while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11075         d++;
11076
11077     /* If we've tried to read what we allow filehandles to look like, and
11078        there's still text left, then it must be a glob() and not a getline.
11079        Use scan_str to pull out the stuff between the <> and treat it
11080        as nothing more than a string.
11081     */
11082
11083     if (d - PL_tokenbuf != len) {
11084         yylval.ival = OP_GLOB;
11085         set_csh();
11086         s = scan_str(start,!!PL_madskills,FALSE);
11087         if (!s)
11088            Perl_croak(aTHX_ "Glob not terminated");
11089         return s;
11090     }
11091     else {
11092         bool readline_overriden = FALSE;
11093         GV *gv_readline;
11094         GV **gvp;
11095         /* we're in a filehandle read situation */
11096         d = PL_tokenbuf;
11097
11098         /* turn <> into <ARGV> */
11099         if (!len)
11100             Copy("ARGV",d,5,char);
11101
11102         /* Check whether readline() is overriden */
11103         gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11104         if ((gv_readline
11105                 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11106                 ||
11107                 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11108                 && (gv_readline = *gvp) != (GV*)&PL_sv_undef
11109                 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11110             readline_overriden = TRUE;
11111
11112         /* if <$fh>, create the ops to turn the variable into a
11113            filehandle
11114         */
11115         if (*d == '$') {
11116             I32 tmp;
11117
11118             /* try to find it in the pad for this block, otherwise find
11119                add symbol table ops
11120             */
11121             if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
11122                 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11123                     HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11124                     HEK * const stashname = HvNAME_HEK(stash);
11125                     SV * const sym = sv_2mortal(newSVhek(stashname));
11126                     sv_catpvs(sym, "::");
11127                     sv_catpv(sym, d+1);
11128                     d = SvPVX(sym);
11129                     goto intro_sym;
11130                 }
11131                 else {
11132                     OP * const o = newOP(OP_PADSV, 0);
11133                     o->op_targ = tmp;
11134                     PL_lex_op = readline_overriden
11135                         ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11136                                 append_elem(OP_LIST, o,
11137                                     newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11138                         : (OP*)newUNOP(OP_READLINE, 0, o);
11139                 }
11140             }
11141             else {
11142                 GV *gv;
11143                 ++d;
11144 intro_sym:
11145                 gv = gv_fetchpv(d,
11146                                 (PL_in_eval
11147                                  ? (GV_ADDMULTI | GV_ADDINEVAL)
11148                                  : GV_ADDMULTI),
11149                                 SVt_PV);
11150                 PL_lex_op = readline_overriden
11151                     ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11152                             append_elem(OP_LIST,
11153                                 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11154                                 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11155                     : (OP*)newUNOP(OP_READLINE, 0,
11156                             newUNOP(OP_RV2SV, 0,
11157                                 newGVOP(OP_GV, 0, gv)));
11158             }
11159             if (!readline_overriden)
11160                 PL_lex_op->op_flags |= OPf_SPECIAL;
11161             /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11162             yylval.ival = OP_NULL;
11163         }
11164
11165         /* If it's none of the above, it must be a literal filehandle
11166            (<Foo::BAR> or <FOO>) so build a simple readline OP */
11167         else {
11168             GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11169             PL_lex_op = readline_overriden
11170                 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11171                         append_elem(OP_LIST,
11172                             newGVOP(OP_GV, 0, gv),
11173                             newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11174                 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11175             yylval.ival = OP_NULL;
11176         }
11177     }
11178
11179     return s;
11180 }
11181
11182
11183 /* scan_str
11184    takes: start position in buffer
11185           keep_quoted preserve \ on the embedded delimiter(s)
11186           keep_delims preserve the delimiters around the string
11187    returns: position to continue reading from buffer
11188    side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11189         updates the read buffer.
11190
11191    This subroutine pulls a string out of the input.  It is called for:
11192         q               single quotes           q(literal text)
11193         '               single quotes           'literal text'
11194         qq              double quotes           qq(interpolate $here please)
11195         "               double quotes           "interpolate $here please"
11196         qx              backticks               qx(/bin/ls -l)
11197         `               backticks               `/bin/ls -l`
11198         qw              quote words             @EXPORT_OK = qw( func() $spam )
11199         m//             regexp match            m/this/
11200         s///            regexp substitute       s/this/that/
11201         tr///           string transliterate    tr/this/that/
11202         y///            string transliterate    y/this/that/
11203         ($*@)           sub prototypes          sub foo ($)
11204         (stuff)         sub attr parameters     sub foo : attr(stuff)
11205         <>              readline or globs       <FOO>, <>, <$fh>, or <*.c>
11206         
11207    In most of these cases (all but <>, patterns and transliterate)
11208    yylex() calls scan_str().  m// makes yylex() call scan_pat() which
11209    calls scan_str().  s/// makes yylex() call scan_subst() which calls
11210    scan_str().  tr/// and y/// make yylex() call scan_trans() which
11211    calls scan_str().
11212
11213    It skips whitespace before the string starts, and treats the first
11214    character as the delimiter.  If the delimiter is one of ([{< then
11215    the corresponding "close" character )]}> is used as the closing
11216    delimiter.  It allows quoting of delimiters, and if the string has
11217    balanced delimiters ([{<>}]) it allows nesting.
11218
11219    On success, the SV with the resulting string is put into lex_stuff or,
11220    if that is already non-NULL, into lex_repl. The second case occurs only
11221    when parsing the RHS of the special constructs s/// and tr/// (y///).
11222    For convenience, the terminating delimiter character is stuffed into
11223    SvIVX of the SV.
11224 */
11225
11226 STATIC char *
11227 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11228 {
11229     dVAR;
11230     SV *sv;                             /* scalar value: string */
11231     char *tmps;                         /* temp string, used for delimiter matching */
11232     register char *s = start;           /* current position in the buffer */
11233     register char term;                 /* terminating character */
11234     register char *to;                  /* current position in the sv's data */
11235     I32 brackets = 1;                   /* bracket nesting level */
11236     bool has_utf8 = FALSE;              /* is there any utf8 content? */
11237     I32 termcode;                       /* terminating char. code */
11238     U8 termstr[UTF8_MAXBYTES];          /* terminating string */
11239     STRLEN termlen;                     /* length of terminating string */
11240     char *last = NULL;                  /* last position for nesting bracket */
11241 #ifdef PERL_MAD
11242     int stuffstart;
11243     char *tstart;
11244 #endif
11245
11246     /* skip space before the delimiter */
11247     if (isSPACE(*s)) {
11248         s = PEEKSPACE(s);
11249     }
11250
11251 #ifdef PERL_MAD
11252     if (PL_realtokenstart >= 0) {
11253         stuffstart = PL_realtokenstart;
11254         PL_realtokenstart = -1;
11255     }
11256     else
11257         stuffstart = start - SvPVX(PL_linestr);
11258 #endif
11259     /* mark where we are, in case we need to report errors */
11260     CLINE;
11261
11262     /* after skipping whitespace, the next character is the terminator */
11263     term = *s;
11264     if (!UTF) {
11265         termcode = termstr[0] = term;
11266         termlen = 1;
11267     }
11268     else {
11269         termcode = utf8_to_uvchr((U8*)s, &termlen);
11270         Copy(s, termstr, termlen, U8);
11271         if (!UTF8_IS_INVARIANT(term))
11272             has_utf8 = TRUE;
11273     }
11274
11275     /* mark where we are */
11276     PL_multi_start = CopLINE(PL_curcop);
11277     PL_multi_open = term;
11278
11279     /* find corresponding closing delimiter */
11280     if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11281         termcode = termstr[0] = term = tmps[5];
11282
11283     PL_multi_close = term;
11284
11285     /* create a new SV to hold the contents.  79 is the SV's initial length.
11286        What a random number. */
11287     sv = newSV(79);
11288     sv_upgrade(sv, SVt_PVIV);
11289     SvIV_set(sv, termcode);
11290     (void)SvPOK_only(sv);               /* validate pointer */
11291
11292     /* move past delimiter and try to read a complete string */
11293     if (keep_delims)
11294         sv_catpvn(sv, s, termlen);
11295     s += termlen;
11296 #ifdef PERL_MAD
11297     tstart = SvPVX(PL_linestr) + stuffstart;
11298     if (!PL_thisopen && !keep_delims) {
11299         PL_thisopen = newSVpvn(tstart, s - tstart);
11300         stuffstart = s - SvPVX(PL_linestr);
11301     }
11302 #endif
11303     for (;;) {
11304         if (PL_encoding && !UTF) {
11305             bool cont = TRUE;
11306
11307             while (cont) {
11308                 int offset = s - SvPVX_const(PL_linestr);
11309                 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11310                                            &offset, (char*)termstr, termlen);
11311                 const char * const ns = SvPVX_const(PL_linestr) + offset;
11312                 char * const svlast = SvEND(sv) - 1;
11313
11314                 for (; s < ns; s++) {
11315                     if (*s == '\n' && !PL_rsfp)
11316                         CopLINE_inc(PL_curcop);
11317                 }
11318                 if (!found)
11319                     goto read_more_line;
11320                 else {
11321                     /* handle quoted delimiters */
11322                     if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11323                         const char *t;
11324                         for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11325                             t--;
11326                         if ((svlast-1 - t) % 2) {
11327                             if (!keep_quoted) {
11328                                 *(svlast-1) = term;
11329                                 *svlast = '\0';
11330                                 SvCUR_set(sv, SvCUR(sv) - 1);
11331                             }
11332                             continue;
11333                         }
11334                     }
11335                     if (PL_multi_open == PL_multi_close) {
11336                         cont = FALSE;
11337                     }
11338                     else {
11339                         const char *t;
11340                         char *w;
11341                         if (!last)
11342                             last = SvPVX(sv);
11343                         for (t = w = last; t < svlast; w++, t++) {
11344                             /* At here, all closes are "was quoted" one,
11345                                so we don't check PL_multi_close. */
11346                             if (*t == '\\') {
11347                                 if (!keep_quoted && *(t+1) == PL_multi_open)
11348                                     t++;
11349                                 else
11350                                     *w++ = *t++;
11351                             }
11352                             else if (*t == PL_multi_open)
11353                                 brackets++;
11354
11355                             *w = *t;
11356                         }
11357                         if (w < t) {
11358                             *w++ = term;
11359                             *w = '\0';
11360                             SvCUR_set(sv, w - SvPVX_const(sv));
11361                         }
11362                         last = w;
11363                         if (--brackets <= 0)
11364                             cont = FALSE;
11365                     }
11366                 }
11367             }
11368             if (!keep_delims) {
11369                 SvCUR_set(sv, SvCUR(sv) - 1);
11370                 *SvEND(sv) = '\0';
11371             }
11372             break;
11373         }
11374
11375         /* extend sv if need be */
11376         SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11377         /* set 'to' to the next character in the sv's string */
11378         to = SvPVX(sv)+SvCUR(sv);
11379
11380         /* if open delimiter is the close delimiter read unbridle */
11381         if (PL_multi_open == PL_multi_close) {
11382             for (; s < PL_bufend; s++,to++) {
11383                 /* embedded newlines increment the current line number */
11384                 if (*s == '\n' && !PL_rsfp)
11385                     CopLINE_inc(PL_curcop);
11386                 /* handle quoted delimiters */
11387                 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11388                     if (!keep_quoted && s[1] == term)
11389                         s++;
11390                 /* any other quotes are simply copied straight through */
11391                     else
11392                         *to++ = *s++;
11393                 }
11394                 /* terminate when run out of buffer (the for() condition), or
11395                    have found the terminator */
11396                 else if (*s == term) {
11397                     if (termlen == 1)
11398                         break;
11399                     if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11400                         break;
11401                 }
11402                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11403                     has_utf8 = TRUE;
11404                 *to = *s;
11405             }
11406         }
11407         
11408         /* if the terminator isn't the same as the start character (e.g.,
11409            matched brackets), we have to allow more in the quoting, and
11410            be prepared for nested brackets.
11411         */
11412         else {
11413             /* read until we run out of string, or we find the terminator */
11414             for (; s < PL_bufend; s++,to++) {
11415                 /* embedded newlines increment the line count */
11416                 if (*s == '\n' && !PL_rsfp)
11417                     CopLINE_inc(PL_curcop);
11418                 /* backslashes can escape the open or closing characters */
11419                 if (*s == '\\' && s+1 < PL_bufend) {
11420                     if (!keep_quoted &&
11421                         ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11422                         s++;
11423                     else
11424                         *to++ = *s++;
11425                 }
11426                 /* allow nested opens and closes */
11427                 else if (*s == PL_multi_close && --brackets <= 0)
11428                     break;
11429                 else if (*s == PL_multi_open)
11430                     brackets++;
11431                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11432                     has_utf8 = TRUE;
11433                 *to = *s;
11434             }
11435         }
11436         /* terminate the copied string and update the sv's end-of-string */
11437         *to = '\0';
11438         SvCUR_set(sv, to - SvPVX_const(sv));
11439
11440         /*
11441          * this next chunk reads more into the buffer if we're not done yet
11442          */
11443
11444         if (s < PL_bufend)
11445             break;              /* handle case where we are done yet :-) */
11446
11447 #ifndef PERL_STRICT_CR
11448         if (to - SvPVX_const(sv) >= 2) {
11449             if ((to[-2] == '\r' && to[-1] == '\n') ||
11450                 (to[-2] == '\n' && to[-1] == '\r'))
11451             {
11452                 to[-2] = '\n';
11453                 to--;
11454                 SvCUR_set(sv, to - SvPVX_const(sv));
11455             }
11456             else if (to[-1] == '\r')
11457                 to[-1] = '\n';
11458         }
11459         else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11460             to[-1] = '\n';
11461 #endif
11462         
11463      read_more_line:
11464         /* if we're out of file, or a read fails, bail and reset the current
11465            line marker so we can report where the unterminated string began
11466         */
11467 #ifdef PERL_MAD
11468         if (PL_madskills) {
11469             char *tstart = SvPVX(PL_linestr) + stuffstart;
11470             if (PL_thisstuff)
11471                 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11472             else
11473                 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11474         }
11475 #endif
11476         if (!PL_rsfp ||
11477          !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11478             sv_free(sv);
11479             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11480             return NULL;
11481         }
11482 #ifdef PERL_MAD
11483         stuffstart = 0;
11484 #endif
11485         /* we read a line, so increment our line counter */
11486         CopLINE_inc(PL_curcop);
11487
11488         /* update debugger info */
11489         if (PERLDB_LINE && PL_curstash != PL_debstash) {
11490             SV * const line_sv = newSV(0);
11491
11492             sv_upgrade(line_sv, SVt_PVMG);
11493             sv_setsv(line_sv,PL_linestr);
11494             (void)SvIOK_on(line_sv);
11495             SvIV_set(line_sv, 0);
11496             av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop), line_sv);
11497         }
11498
11499         /* having changed the buffer, we must update PL_bufend */
11500         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11501         PL_last_lop = PL_last_uni = NULL;
11502     }
11503
11504     /* at this point, we have successfully read the delimited string */
11505
11506     if (!PL_encoding || UTF) {
11507 #ifdef PERL_MAD
11508         if (PL_madskills) {
11509             char *tstart = SvPVX(PL_linestr) + stuffstart;
11510             if (PL_thisstuff)
11511                 sv_catpvn(PL_thisstuff, tstart, s - tstart);
11512             else
11513                 PL_thisstuff = newSVpvn(tstart, s - tstart);
11514             if (!PL_thisclose && !keep_delims)
11515                 PL_thisclose = newSVpvn(s,termlen);
11516         }
11517 #endif
11518
11519         if (keep_delims)
11520             sv_catpvn(sv, s, termlen);
11521         s += termlen;
11522     }
11523 #ifdef PERL_MAD
11524     else {
11525         if (PL_madskills) {
11526             char *tstart = SvPVX(PL_linestr) + stuffstart;
11527             if (PL_thisstuff)
11528                 sv_catpvn(PL_thisstuff, tstart, s - tstart - termlen);
11529             else
11530                 PL_thisstuff = newSVpvn(tstart, s - tstart - termlen);
11531             if (!PL_thisclose && !keep_delims)
11532                 PL_thisclose = newSVpvn(s - termlen,termlen);
11533         }
11534     }
11535 #endif
11536     if (has_utf8 || PL_encoding)
11537         SvUTF8_on(sv);
11538
11539     PL_multi_end = CopLINE(PL_curcop);
11540
11541     /* if we allocated too much space, give some back */
11542     if (SvCUR(sv) + 5 < SvLEN(sv)) {
11543         SvLEN_set(sv, SvCUR(sv) + 1);
11544         SvPV_renew(sv, SvLEN(sv));
11545     }
11546
11547     /* decide whether this is the first or second quoted string we've read
11548        for this op
11549     */
11550
11551     if (PL_lex_stuff)
11552         PL_lex_repl = sv;
11553     else
11554         PL_lex_stuff = sv;
11555     return s;
11556 }
11557
11558 /*
11559   scan_num
11560   takes: pointer to position in buffer
11561   returns: pointer to new position in buffer
11562   side-effects: builds ops for the constant in yylval.op
11563
11564   Read a number in any of the formats that Perl accepts:
11565
11566   \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*)      12 12.34 12.
11567   \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*)                     .34
11568   0b[01](_?[01])*
11569   0[0-7](_?[0-7])*
11570   0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11571
11572   Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11573   thing it reads.
11574
11575   If it reads a number without a decimal point or an exponent, it will
11576   try converting the number to an integer and see if it can do so
11577   without loss of precision.
11578 */
11579
11580 char *
11581 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11582 {
11583     dVAR;
11584     register const char *s = start;     /* current position in buffer */
11585     register char *d;                   /* destination in temp buffer */
11586     register char *e;                   /* end of temp buffer */
11587     NV nv;                              /* number read, as a double */
11588     SV *sv = NULL;                      /* place to put the converted number */
11589     bool floatit;                       /* boolean: int or float? */
11590     const char *lastub = NULL;          /* position of last underbar */
11591     static char const number_too_long[] = "Number too long";
11592
11593     /* We use the first character to decide what type of number this is */
11594
11595     switch (*s) {
11596     default:
11597       Perl_croak(aTHX_ "panic: scan_num");
11598
11599     /* if it starts with a 0, it could be an octal number, a decimal in
11600        0.13 disguise, or a hexadecimal number, or a binary number. */
11601     case '0':
11602         {
11603           /* variables:
11604              u          holds the "number so far"
11605              shift      the power of 2 of the base
11606                         (hex == 4, octal == 3, binary == 1)
11607              overflowed was the number more than we can hold?
11608
11609              Shift is used when we add a digit.  It also serves as an "are
11610              we in octal/hex/binary?" indicator to disallow hex characters
11611              when in octal mode.
11612            */
11613             NV n = 0.0;
11614             UV u = 0;
11615             I32 shift;
11616             bool overflowed = FALSE;
11617             bool just_zero  = TRUE;     /* just plain 0 or binary number? */
11618             static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11619             static const char* const bases[5] =
11620               { "", "binary", "", "octal", "hexadecimal" };
11621             static const char* const Bases[5] =
11622               { "", "Binary", "", "Octal", "Hexadecimal" };
11623             static const char* const maxima[5] =
11624               { "",
11625                 "0b11111111111111111111111111111111",
11626                 "",
11627                 "037777777777",
11628                 "0xffffffff" };
11629             const char *base, *Base, *max;
11630
11631             /* check for hex */
11632             if (s[1] == 'x') {
11633                 shift = 4;
11634                 s += 2;
11635                 just_zero = FALSE;
11636             } else if (s[1] == 'b') {
11637                 shift = 1;
11638                 s += 2;
11639                 just_zero = FALSE;
11640             }
11641             /* check for a decimal in disguise */
11642             else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11643                 goto decimal;
11644             /* so it must be octal */
11645             else {
11646                 shift = 3;
11647                 s++;
11648             }
11649
11650             if (*s == '_') {
11651                if (ckWARN(WARN_SYNTAX))
11652                    Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11653                                "Misplaced _ in number");
11654                lastub = s++;
11655             }
11656
11657             base = bases[shift];
11658             Base = Bases[shift];
11659             max  = maxima[shift];
11660
11661             /* read the rest of the number */
11662             for (;;) {
11663                 /* x is used in the overflow test,
11664                    b is the digit we're adding on. */
11665                 UV x, b;
11666
11667                 switch (*s) {
11668
11669                 /* if we don't mention it, we're done */
11670                 default:
11671                     goto out;
11672
11673                 /* _ are ignored -- but warned about if consecutive */
11674                 case '_':
11675                     if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11676                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11677                                     "Misplaced _ in number");
11678                     lastub = s++;
11679                     break;
11680
11681                 /* 8 and 9 are not octal */
11682                 case '8': case '9':
11683                     if (shift == 3)
11684                         yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11685                     /* FALL THROUGH */
11686
11687                 /* octal digits */
11688                 case '2': case '3': case '4':
11689                 case '5': case '6': case '7':
11690                     if (shift == 1)
11691                         yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11692                     /* FALL THROUGH */
11693
11694                 case '0': case '1':
11695                     b = *s++ & 15;              /* ASCII digit -> value of digit */
11696                     goto digit;
11697
11698                 /* hex digits */
11699                 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11700                 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11701                     /* make sure they said 0x */
11702                     if (shift != 4)
11703                         goto out;
11704                     b = (*s++ & 7) + 9;
11705
11706                     /* Prepare to put the digit we have onto the end
11707                        of the number so far.  We check for overflows.
11708                     */
11709
11710                   digit:
11711                     just_zero = FALSE;
11712                     if (!overflowed) {
11713                         x = u << shift; /* make room for the digit */
11714
11715                         if ((x >> shift) != u
11716                             && !(PL_hints & HINT_NEW_BINARY)) {
11717                             overflowed = TRUE;
11718                             n = (NV) u;
11719                             if (ckWARN_d(WARN_OVERFLOW))
11720                                 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11721                                             "Integer overflow in %s number",
11722                                             base);
11723                         } else
11724                             u = x | b;          /* add the digit to the end */
11725                     }
11726                     if (overflowed) {
11727                         n *= nvshift[shift];
11728                         /* If an NV has not enough bits in its
11729                          * mantissa to represent an UV this summing of
11730                          * small low-order numbers is a waste of time
11731                          * (because the NV cannot preserve the
11732                          * low-order bits anyway): we could just
11733                          * remember when did we overflow and in the
11734                          * end just multiply n by the right
11735                          * amount. */
11736                         n += (NV) b;
11737                     }
11738                     break;
11739                 }
11740             }
11741
11742           /* if we get here, we had success: make a scalar value from
11743              the number.
11744           */
11745           out:
11746
11747             /* final misplaced underbar check */
11748             if (s[-1] == '_') {
11749                 if (ckWARN(WARN_SYNTAX))
11750                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11751             }
11752
11753             sv = newSV(0);
11754             if (overflowed) {
11755                 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
11756                     Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11757                                 "%s number > %s non-portable",
11758                                 Base, max);
11759                 sv_setnv(sv, n);
11760             }
11761             else {
11762 #if UVSIZE > 4
11763                 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
11764                     Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
11765                                 "%s number > %s non-portable",
11766                                 Base, max);
11767 #endif
11768                 sv_setuv(sv, u);
11769             }
11770             if (just_zero && (PL_hints & HINT_NEW_INTEGER))
11771                 sv = new_constant(start, s - start, "integer",
11772                                   sv, NULL, NULL);
11773             else if (PL_hints & HINT_NEW_BINARY)
11774                 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
11775         }
11776         break;
11777
11778     /*
11779       handle decimal numbers.
11780       we're also sent here when we read a 0 as the first digit
11781     */
11782     case '1': case '2': case '3': case '4': case '5':
11783     case '6': case '7': case '8': case '9': case '.':
11784       decimal:
11785         d = PL_tokenbuf;
11786         e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
11787         floatit = FALSE;
11788
11789         /* read next group of digits and _ and copy into d */
11790         while (isDIGIT(*s) || *s == '_') {
11791             /* skip underscores, checking for misplaced ones
11792                if -w is on
11793             */
11794             if (*s == '_') {
11795                 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11796                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11797                                 "Misplaced _ in number");
11798                 lastub = s++;
11799             }
11800             else {
11801                 /* check for end of fixed-length buffer */
11802                 if (d >= e)
11803                     Perl_croak(aTHX_ number_too_long);
11804                 /* if we're ok, copy the character */
11805                 *d++ = *s++;
11806             }
11807         }
11808
11809         /* final misplaced underbar check */
11810         if (lastub && s == lastub + 1) {
11811             if (ckWARN(WARN_SYNTAX))
11812                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
11813         }
11814
11815         /* read a decimal portion if there is one.  avoid
11816            3..5 being interpreted as the number 3. followed
11817            by .5
11818         */
11819         if (*s == '.' && s[1] != '.') {
11820             floatit = TRUE;
11821             *d++ = *s++;
11822
11823             if (*s == '_') {
11824                 if (ckWARN(WARN_SYNTAX))
11825                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11826                                 "Misplaced _ in number");
11827                 lastub = s;
11828             }
11829
11830             /* copy, ignoring underbars, until we run out of digits.
11831             */
11832             for (; isDIGIT(*s) || *s == '_'; s++) {
11833                 /* fixed length buffer check */
11834                 if (d >= e)
11835                     Perl_croak(aTHX_ number_too_long);
11836                 if (*s == '_') {
11837                    if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11838                        Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11839                                    "Misplaced _ in number");
11840                    lastub = s;
11841                 }
11842                 else
11843                     *d++ = *s;
11844             }
11845             /* fractional part ending in underbar? */
11846             if (s[-1] == '_') {
11847                 if (ckWARN(WARN_SYNTAX))
11848                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11849                                 "Misplaced _ in number");
11850             }
11851             if (*s == '.' && isDIGIT(s[1])) {
11852                 /* oops, it's really a v-string, but without the "v" */
11853                 s = start;
11854                 goto vstring;
11855             }
11856         }
11857
11858         /* read exponent part, if present */
11859         if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
11860             floatit = TRUE;
11861             s++;
11862
11863             /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
11864             *d++ = 'e';         /* At least some Mach atof()s don't grok 'E' */
11865
11866             /* stray preinitial _ */
11867             if (*s == '_') {
11868                 if (ckWARN(WARN_SYNTAX))
11869                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11870                                 "Misplaced _ in number");
11871                 lastub = s++;
11872             }
11873
11874             /* allow positive or negative exponent */
11875             if (*s == '+' || *s == '-')
11876                 *d++ = *s++;
11877
11878             /* stray initial _ */
11879             if (*s == '_') {
11880                 if (ckWARN(WARN_SYNTAX))
11881                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11882                                 "Misplaced _ in number");
11883                 lastub = s++;
11884             }
11885
11886             /* read digits of exponent */
11887             while (isDIGIT(*s) || *s == '_') {
11888                 if (isDIGIT(*s)) {
11889                     if (d >= e)
11890                         Perl_croak(aTHX_ number_too_long);
11891                     *d++ = *s++;
11892                 }
11893                 else {
11894                    if (((lastub && s == lastub + 1) ||
11895                         (!isDIGIT(s[1]) && s[1] != '_'))
11896                     && ckWARN(WARN_SYNTAX))
11897                        Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11898                                    "Misplaced _ in number");
11899                    lastub = s++;
11900                 }
11901             }
11902         }
11903
11904
11905         /* make an sv from the string */
11906         sv = newSV(0);
11907
11908         /*
11909            We try to do an integer conversion first if no characters
11910            indicating "float" have been found.
11911          */
11912
11913         if (!floatit) {
11914             UV uv;
11915             const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
11916
11917             if (flags == IS_NUMBER_IN_UV) {
11918               if (uv <= IV_MAX)
11919                 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
11920               else
11921                 sv_setuv(sv, uv);
11922             } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
11923               if (uv <= (UV) IV_MIN)
11924                 sv_setiv(sv, -(IV)uv);
11925               else
11926                 floatit = TRUE;
11927             } else
11928               floatit = TRUE;
11929         }
11930         if (floatit) {
11931             /* terminate the string */
11932             *d = '\0';
11933             nv = Atof(PL_tokenbuf);
11934             sv_setnv(sv, nv);
11935         }
11936
11937         if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
11938                        (PL_hints & HINT_NEW_INTEGER) )
11939             sv = new_constant(PL_tokenbuf, d - PL_tokenbuf,
11940                               (floatit ? "float" : "integer"),
11941                               sv, NULL, NULL);
11942         break;
11943
11944     /* if it starts with a v, it could be a v-string */
11945     case 'v':
11946 vstring:
11947                 sv = newSV(5); /* preallocate storage space */
11948                 s = scan_vstring(s,sv);
11949         break;
11950     }
11951
11952     /* make the op for the constant and return */
11953
11954     if (sv)
11955         lvalp->opval = newSVOP(OP_CONST, 0, sv);
11956     else
11957         lvalp->opval = NULL;
11958
11959     return (char *)s;
11960 }
11961
11962 STATIC char *
11963 S_scan_formline(pTHX_ register char *s)
11964 {
11965     dVAR;
11966     register char *eol;
11967     register char *t;
11968     SV * const stuff = newSVpvs("");
11969     bool needargs = FALSE;
11970     bool eofmt = FALSE;
11971 #ifdef PERL_MAD
11972     char *tokenstart = s;
11973     SV* savewhite;
11974     
11975     if (PL_madskills) {
11976         savewhite = PL_thiswhite;
11977         PL_thiswhite = 0;
11978     }
11979 #endif
11980
11981     while (!needargs) {
11982         if (*s == '.') {
11983 #ifdef PERL_STRICT_CR
11984             for (t = s+1;SPACE_OR_TAB(*t); t++) ;
11985 #else
11986             for (t = s+1;SPACE_OR_TAB(*t) || *t == '\r'; t++) ;
11987 #endif
11988             if (*t == '\n' || t == PL_bufend) {
11989                 eofmt = TRUE;
11990                 break;
11991             }
11992         }
11993         if (PL_in_eval && !PL_rsfp) {
11994             eol = (char *) memchr(s,'\n',PL_bufend-s);
11995             if (!eol++)
11996                 eol = PL_bufend;
11997         }
11998         else
11999             eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12000         if (*s != '#') {
12001             for (t = s; t < eol; t++) {
12002                 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12003                     needargs = FALSE;
12004                     goto enough;        /* ~~ must be first line in formline */
12005                 }
12006                 if (*t == '@' || *t == '^')
12007                     needargs = TRUE;
12008             }
12009             if (eol > s) {
12010                 sv_catpvn(stuff, s, eol-s);
12011 #ifndef PERL_STRICT_CR
12012                 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12013                     char *end = SvPVX(stuff) + SvCUR(stuff);
12014                     end[-2] = '\n';
12015                     end[-1] = '\0';
12016                     SvCUR_set(stuff, SvCUR(stuff) - 1);
12017                 }
12018 #endif
12019             }
12020             else
12021               break;
12022         }
12023         s = (char*)eol;
12024         if (PL_rsfp) {
12025 #ifdef PERL_MAD
12026             if (PL_madskills) {
12027                 if (PL_thistoken)
12028                     sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12029                 else
12030                     PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12031             }
12032 #endif
12033             s = filter_gets(PL_linestr, PL_rsfp, 0);
12034 #ifdef PERL_MAD
12035             tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12036 #else
12037             PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12038 #endif
12039             PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12040             PL_last_lop = PL_last_uni = NULL;
12041             if (!s) {
12042                 s = PL_bufptr;
12043                 break;
12044             }
12045         }
12046         incline(s);
12047     }
12048   enough:
12049     if (SvCUR(stuff)) {
12050         PL_expect = XTERM;
12051         if (needargs) {
12052             PL_lex_state = LEX_NORMAL;
12053             start_force(PL_curforce);
12054             NEXTVAL_NEXTTOKE.ival = 0;
12055             force_next(',');
12056         }
12057         else
12058             PL_lex_state = LEX_FORMLINE;
12059         if (!IN_BYTES) {
12060             if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12061                 SvUTF8_on(stuff);
12062             else if (PL_encoding)
12063                 sv_recode_to_utf8(stuff, PL_encoding);
12064         }
12065         start_force(PL_curforce);
12066         NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12067         force_next(THING);
12068         start_force(PL_curforce);
12069         NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12070         force_next(LSTOP);
12071     }
12072     else {
12073         SvREFCNT_dec(stuff);
12074         if (eofmt)
12075             PL_lex_formbrack = 0;
12076         PL_bufptr = s;
12077     }
12078 #ifdef PERL_MAD
12079     if (PL_madskills) {
12080         if (PL_thistoken)
12081             sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12082         else
12083             PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12084         PL_thiswhite = savewhite;
12085     }
12086 #endif
12087     return s;
12088 }
12089
12090 STATIC void
12091 S_set_csh(pTHX)
12092 {
12093 #ifdef CSH
12094     dVAR;
12095     if (!PL_cshlen)
12096         PL_cshlen = strlen(PL_cshname);
12097 #else
12098 #if defined(USE_ITHREADS)
12099     PERL_UNUSED_CONTEXT;
12100 #endif
12101 #endif
12102 }
12103
12104 I32
12105 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12106 {
12107     dVAR;
12108     const I32 oldsavestack_ix = PL_savestack_ix;
12109     CV* const outsidecv = PL_compcv;
12110
12111     if (PL_compcv) {
12112         assert(SvTYPE(PL_compcv) == SVt_PVCV);
12113     }
12114     SAVEI32(PL_subline);
12115     save_item(PL_subname);
12116     SAVESPTR(PL_compcv);
12117
12118     PL_compcv = (CV*)newSV(0);
12119     sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
12120     CvFLAGS(PL_compcv) |= flags;
12121
12122     PL_subline = CopLINE(PL_curcop);
12123     CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12124     CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12125     CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12126
12127     return oldsavestack_ix;
12128 }
12129
12130 #ifdef __SC__
12131 #pragma segment Perl_yylex
12132 #endif
12133 int
12134 Perl_yywarn(pTHX_ const char *s)
12135 {
12136     dVAR;
12137     PL_in_eval |= EVAL_WARNONLY;
12138     yyerror(s);
12139     PL_in_eval &= ~EVAL_WARNONLY;
12140     return 0;
12141 }
12142
12143 int
12144 Perl_yyerror(pTHX_ const char *s)
12145 {
12146     dVAR;
12147     const char *where = NULL;
12148     const char *context = NULL;
12149     int contlen = -1;
12150     SV *msg;
12151
12152     if (!yychar || (yychar == ';' && !PL_rsfp))
12153         where = "at EOF";
12154     else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12155       PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12156       PL_oldbufptr != PL_bufptr) {
12157         /*
12158                 Only for NetWare:
12159                 The code below is removed for NetWare because it abends/crashes on NetWare
12160                 when the script has error such as not having the closing quotes like:
12161                     if ($var eq "value)
12162                 Checking of white spaces is anyway done in NetWare code.
12163         */
12164 #ifndef NETWARE
12165         while (isSPACE(*PL_oldoldbufptr))
12166             PL_oldoldbufptr++;
12167 #endif
12168         context = PL_oldoldbufptr;
12169         contlen = PL_bufptr - PL_oldoldbufptr;
12170     }
12171     else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12172       PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12173         /*
12174                 Only for NetWare:
12175                 The code below is removed for NetWare because it abends/crashes on NetWare
12176                 when the script has error such as not having the closing quotes like:
12177                     if ($var eq "value)
12178                 Checking of white spaces is anyway done in NetWare code.
12179         */
12180 #ifndef NETWARE
12181         while (isSPACE(*PL_oldbufptr))
12182             PL_oldbufptr++;
12183 #endif
12184         context = PL_oldbufptr;
12185         contlen = PL_bufptr - PL_oldbufptr;
12186     }
12187     else if (yychar > 255)
12188         where = "next token ???";
12189     else if (yychar == -2) { /* YYEMPTY */
12190         if (PL_lex_state == LEX_NORMAL ||
12191            (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12192             where = "at end of line";
12193         else if (PL_lex_inpat)
12194             where = "within pattern";
12195         else
12196             where = "within string";
12197     }
12198     else {
12199         SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12200         if (yychar < 32)
12201             Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12202         else if (isPRINT_LC(yychar))
12203             Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12204         else
12205             Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12206         where = SvPVX_const(where_sv);
12207     }
12208     msg = sv_2mortal(newSVpv(s, 0));
12209     Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12210         OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12211     if (context)
12212         Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12213     else
12214         Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12215     if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12216         Perl_sv_catpvf(aTHX_ msg,
12217         "  (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12218                 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12219         PL_multi_end = 0;
12220     }
12221     if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12222         Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, msg);
12223     else
12224         qerror(msg);
12225     if (PL_error_count >= 10) {
12226         if (PL_in_eval && SvCUR(ERRSV))
12227             Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12228             ERRSV, OutCopFILE(PL_curcop));
12229         else
12230             Perl_croak(aTHX_ "%s has too many errors.\n",
12231             OutCopFILE(PL_curcop));
12232     }
12233     PL_in_my = 0;
12234     PL_in_my_stash = NULL;
12235     return 0;
12236 }
12237 #ifdef __SC__
12238 #pragma segment Main
12239 #endif
12240
12241 STATIC char*
12242 S_swallow_bom(pTHX_ U8 *s)
12243 {
12244     dVAR;
12245     const STRLEN slen = SvCUR(PL_linestr);
12246     switch (s[0]) {
12247     case 0xFF:
12248         if (s[1] == 0xFE) {
12249             /* UTF-16 little-endian? (or UTF32-LE?) */
12250             if (s[2] == 0 && s[3] == 0)  /* UTF-32 little-endian */
12251                 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12252 #ifndef PERL_NO_UTF16_FILTER
12253             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12254             s += 2;
12255         utf16le:
12256             if (PL_bufend > (char*)s) {
12257                 U8 *news;
12258                 I32 newlen;
12259
12260                 filter_add(utf16rev_textfilter, NULL);
12261                 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12262                 utf16_to_utf8_reversed(s, news,
12263                                        PL_bufend - (char*)s - 1,
12264                                        &newlen);
12265                 sv_setpvn(PL_linestr, (const char*)news, newlen);
12266 #ifdef PERL_MAD
12267                 s = (U8*)SvPVX(PL_linestr);
12268                 Copy(news, s, newlen, U8);
12269                 s[newlen] = '\0';
12270 #endif
12271                 Safefree(news);
12272                 SvUTF8_on(PL_linestr);
12273                 s = (U8*)SvPVX(PL_linestr);
12274 #ifdef PERL_MAD
12275                 /* FIXME - is this a general bug fix?  */
12276                 s[newlen] = '\0';
12277 #endif
12278                 PL_bufend = SvPVX(PL_linestr) + newlen;
12279             }
12280 #else
12281             Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12282 #endif
12283         }
12284         break;
12285     case 0xFE:
12286         if (s[1] == 0xFF) {   /* UTF-16 big-endian? */
12287 #ifndef PERL_NO_UTF16_FILTER
12288             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12289             s += 2;
12290         utf16be:
12291             if (PL_bufend > (char *)s) {
12292                 U8 *news;
12293                 I32 newlen;
12294
12295                 filter_add(utf16_textfilter, NULL);
12296                 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12297                 utf16_to_utf8(s, news,
12298                               PL_bufend - (char*)s,
12299                               &newlen);
12300                 sv_setpvn(PL_linestr, (const char*)news, newlen);
12301                 Safefree(news);
12302                 SvUTF8_on(PL_linestr);
12303                 s = (U8*)SvPVX(PL_linestr);
12304                 PL_bufend = SvPVX(PL_linestr) + newlen;
12305             }
12306 #else
12307             Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12308 #endif
12309         }
12310         break;
12311     case 0xEF:
12312         if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12313             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12314             s += 3;                      /* UTF-8 */
12315         }
12316         break;
12317     case 0:
12318         if (slen > 3) {
12319              if (s[1] == 0) {
12320                   if (s[2] == 0xFE && s[3] == 0xFF) {
12321                        /* UTF-32 big-endian */
12322                        Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12323                   }
12324              }
12325              else if (s[2] == 0 && s[3] != 0) {
12326                   /* Leading bytes
12327                    * 00 xx 00 xx
12328                    * are a good indicator of UTF-16BE. */
12329                   if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12330                   goto utf16be;
12331              }
12332         }
12333     default:
12334          if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12335                   /* Leading bytes
12336                    * xx 00 xx 00
12337                    * are a good indicator of UTF-16LE. */
12338               if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12339               goto utf16le;
12340          }
12341     }
12342     return (char*)s;
12343 }
12344
12345 /*
12346  * restore_rsfp
12347  * Restore a source filter.
12348  */
12349
12350 static void
12351 restore_rsfp(pTHX_ void *f)
12352 {
12353     dVAR;
12354     PerlIO * const fp = (PerlIO*)f;
12355
12356     if (PL_rsfp == PerlIO_stdin())
12357         PerlIO_clearerr(PL_rsfp);
12358     else if (PL_rsfp && (PL_rsfp != fp))
12359         PerlIO_close(PL_rsfp);
12360     PL_rsfp = fp;
12361 }
12362
12363 #ifndef PERL_NO_UTF16_FILTER
12364 static I32
12365 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12366 {
12367     dVAR;
12368     const STRLEN old = SvCUR(sv);
12369     const I32 count = FILTER_READ(idx+1, sv, maxlen);
12370     DEBUG_P(PerlIO_printf(Perl_debug_log,
12371                           "utf16_textfilter(%p): %d %d (%d)\n",
12372                           utf16_textfilter, idx, maxlen, (int) count));
12373     if (count) {
12374         U8* tmps;
12375         I32 newlen;
12376         Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12377         Copy(SvPVX_const(sv), tmps, old, char);
12378         utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12379                       SvCUR(sv) - old, &newlen);
12380         sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12381     }
12382     DEBUG_P({sv_dump(sv);});
12383     return SvCUR(sv);
12384 }
12385
12386 static I32
12387 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12388 {
12389     dVAR;
12390     const STRLEN old = SvCUR(sv);
12391     const I32 count = FILTER_READ(idx+1, sv, maxlen);
12392     DEBUG_P(PerlIO_printf(Perl_debug_log,
12393                           "utf16rev_textfilter(%p): %d %d (%d)\n",
12394                           utf16rev_textfilter, idx, maxlen, (int) count));
12395     if (count) {
12396         U8* tmps;
12397         I32 newlen;
12398         Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12399         Copy(SvPVX_const(sv), tmps, old, char);
12400         utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12401                       SvCUR(sv) - old, &newlen);
12402         sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12403     }
12404     DEBUG_P({ sv_dump(sv); });
12405     return count;
12406 }
12407 #endif
12408
12409 /*
12410 Returns a pointer to the next character after the parsed
12411 vstring, as well as updating the passed in sv.
12412
12413 Function must be called like
12414
12415         sv = newSV(5);
12416         s = scan_vstring(s,sv);
12417
12418 The sv should already be large enough to store the vstring
12419 passed in, for performance reasons.
12420
12421 */
12422
12423 char *
12424 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12425 {
12426     dVAR;
12427     const char *pos = s;
12428     const char *start = s;
12429     if (*pos == 'v') pos++;  /* get past 'v' */
12430     while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12431         pos++;
12432     if ( *pos != '.') {
12433         /* this may not be a v-string if followed by => */
12434         const char *next = pos;
12435         while (next < PL_bufend && isSPACE(*next))
12436             ++next;
12437         if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12438             /* return string not v-string */
12439             sv_setpvn(sv,(char *)s,pos-s);
12440             return (char *)pos;
12441         }
12442     }
12443
12444     if (!isALPHA(*pos)) {
12445         U8 tmpbuf[UTF8_MAXBYTES+1];
12446
12447         if (*s == 'v') s++;  /* get past 'v' */
12448
12449         sv_setpvn(sv, "", 0);
12450
12451         for (;;) {
12452             U8 *tmpend;
12453             UV rev = 0;
12454             {
12455                 /* this is atoi() that tolerates underscores */
12456                 const char *end = pos;
12457                 UV mult = 1;
12458                 while (--end >= s) {
12459                     UV orev;
12460                     if (*end == '_')
12461                         continue;
12462                     orev = rev;
12463                     rev += (*end - '0') * mult;
12464                     mult *= 10;
12465                     if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12466                         Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12467                                     "Integer overflow in decimal number");
12468                 }
12469             }
12470 #ifdef EBCDIC
12471             if (rev > 0x7FFFFFFF)
12472                  Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12473 #endif
12474             /* Append native character for the rev point */
12475             tmpend = uvchr_to_utf8(tmpbuf, rev);
12476             sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12477             if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12478                  SvUTF8_on(sv);
12479             if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12480                  s = ++pos;
12481             else {
12482                  s = pos;
12483                  break;
12484             }
12485             while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12486                  pos++;
12487         }
12488         SvPOK_on(sv);
12489         sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12490         SvRMAGICAL_on(sv);
12491     }
12492     return (char *)s;
12493 }
12494
12495 /*
12496  * Local variables:
12497  * c-indentation-style: bsd
12498  * c-basic-offset: 4
12499  * indent-tabs-mode: t
12500  * End:
12501  *
12502  * ex: set ts=8 sts=4 sw=4 noet:
12503  */