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