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