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