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