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