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