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