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