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