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