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