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