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