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