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