Upgrade to Test-Simple-0.70
[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         if (!PL_thiswhite)
3910             PL_thiswhite = newSVpvs("");
3911         sv_catpvn(PL_thiswhite, s, 1);
3912 #endif
3913         s++;
3914         goto retry;
3915     case '#':
3916     case '\n':
3917 #ifdef PERL_MAD
3918         PL_realtokenstart = -1;
3919         if (PL_madskills)
3920             PL_faketokens = 0;
3921 #endif
3922         if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
3923             if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
3924                 /* handle eval qq[#line 1 "foo"\n ...] */
3925                 CopLINE_dec(PL_curcop);
3926                 incline(s);
3927             }
3928             if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
3929                 s = SKIPSPACE0(s);
3930                 if (!PL_in_eval || PL_rsfp)
3931                     incline(s);
3932             }
3933             else {
3934                 d = s;
3935                 while (d < PL_bufend && *d != '\n')
3936                     d++;
3937                 if (d < PL_bufend)
3938                     d++;
3939                 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3940                   Perl_croak(aTHX_ "panic: input overflow");
3941 #ifdef PERL_MAD
3942                 if (PL_madskills)
3943                     PL_thiswhite = newSVpvn(s, d - s);
3944 #endif
3945                 s = d;
3946                 incline(s);
3947             }
3948             if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
3949                 PL_bufptr = s;
3950                 PL_lex_state = LEX_FORMLINE;
3951                 return yylex();
3952             }
3953         }
3954         else {
3955 #ifdef PERL_MAD
3956             if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
3957                 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
3958                     PL_faketokens = 0;
3959                     s = SKIPSPACE0(s);
3960                     TOKEN(PEG); /* make sure any #! line is accessible */
3961                 }
3962                 s = SKIPSPACE0(s);
3963             }
3964             else {
3965 /*              if (PL_madskills && PL_lex_formbrack) { */
3966                     d = s;
3967                     while (d < PL_bufend && *d != '\n')
3968                         d++;
3969                     if (d < PL_bufend)
3970                         d++;
3971                     else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
3972                       Perl_croak(aTHX_ "panic: input overflow");
3973                     if (PL_madskills && CopLINE(PL_curcop) >= 1) {
3974                         if (!PL_thiswhite)
3975                             PL_thiswhite = newSVpvs("");
3976                         if (CopLINE(PL_curcop) == 1) {
3977                             sv_setpvn(PL_thiswhite, "", 0);
3978                             PL_faketokens = 0;
3979                         }
3980                         sv_catpvn(PL_thiswhite, s, d - s);
3981                     }
3982                     s = d;
3983 /*              }
3984                 *s = '\0';
3985                 PL_bufend = s; */
3986             }
3987 #else
3988             *s = '\0';
3989             PL_bufend = s;
3990 #endif
3991         }
3992         goto retry;
3993     case '-':
3994         if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
3995             I32 ftst = 0;
3996             char tmp;
3997
3998             s++;
3999             PL_bufptr = s;
4000             tmp = *s++;
4001
4002             while (s < PL_bufend && SPACE_OR_TAB(*s))
4003                 s++;
4004
4005             if (strnEQ(s,"=>",2)) {
4006                 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
4007                 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
4008                 OPERATOR('-');          /* unary minus */
4009             }
4010             PL_last_uni = PL_oldbufptr;
4011             switch (tmp) {
4012             case 'r': ftst = OP_FTEREAD;        break;
4013             case 'w': ftst = OP_FTEWRITE;       break;
4014             case 'x': ftst = OP_FTEEXEC;        break;
4015             case 'o': ftst = OP_FTEOWNED;       break;
4016             case 'R': ftst = OP_FTRREAD;        break;
4017             case 'W': ftst = OP_FTRWRITE;       break;
4018             case 'X': ftst = OP_FTREXEC;        break;
4019             case 'O': ftst = OP_FTROWNED;       break;
4020             case 'e': ftst = OP_FTIS;           break;
4021             case 'z': ftst = OP_FTZERO;         break;
4022             case 's': ftst = OP_FTSIZE;         break;
4023             case 'f': ftst = OP_FTFILE;         break;
4024             case 'd': ftst = OP_FTDIR;          break;
4025             case 'l': ftst = OP_FTLINK;         break;
4026             case 'p': ftst = OP_FTPIPE;         break;
4027             case 'S': ftst = OP_FTSOCK;         break;
4028             case 'u': ftst = OP_FTSUID;         break;
4029             case 'g': ftst = OP_FTSGID;         break;
4030             case 'k': ftst = OP_FTSVTX;         break;
4031             case 'b': ftst = OP_FTBLK;          break;
4032             case 'c': ftst = OP_FTCHR;          break;
4033             case 't': ftst = OP_FTTTY;          break;
4034             case 'T': ftst = OP_FTTEXT;         break;
4035             case 'B': ftst = OP_FTBINARY;       break;
4036             case 'M': case 'A': case 'C':
4037                 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
4038                 switch (tmp) {
4039                 case 'M': ftst = OP_FTMTIME;    break;
4040                 case 'A': ftst = OP_FTATIME;    break;
4041                 case 'C': ftst = OP_FTCTIME;    break;
4042                 default:                        break;
4043                 }
4044                 break;
4045             default:
4046                 break;
4047             }
4048             if (ftst) {
4049                 PL_last_lop_op = (OPCODE)ftst;
4050                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4051                         "### Saw file test %c\n", (int)tmp);
4052                 } );
4053                 FTST(ftst);
4054             }
4055             else {
4056                 /* Assume it was a minus followed by a one-letter named
4057                  * subroutine call (or a -bareword), then. */
4058                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4059                         "### '-%c' looked like a file test but was not\n",
4060                         (int) tmp);
4061                 } );
4062                 s = --PL_bufptr;
4063             }
4064         }
4065         {
4066             const char tmp = *s++;
4067             if (*s == tmp) {
4068                 s++;
4069                 if (PL_expect == XOPERATOR)
4070                     TERM(POSTDEC);
4071                 else
4072                     OPERATOR(PREDEC);
4073             }
4074             else if (*s == '>') {
4075                 s++;
4076                 s = SKIPSPACE1(s);
4077                 if (isIDFIRST_lazy_if(s,UTF)) {
4078                     s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4079                     TOKEN(ARROW);
4080                 }
4081                 else if (*s == '$')
4082                     OPERATOR(ARROW);
4083                 else
4084                     TERM(ARROW);
4085             }
4086             if (PL_expect == XOPERATOR)
4087                 Aop(OP_SUBTRACT);
4088             else {
4089                 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4090                     check_uni();
4091                 OPERATOR('-');          /* unary minus */
4092             }
4093         }
4094
4095     case '+':
4096         {
4097             const char tmp = *s++;
4098             if (*s == tmp) {
4099                 s++;
4100                 if (PL_expect == XOPERATOR)
4101                     TERM(POSTINC);
4102                 else
4103                     OPERATOR(PREINC);
4104             }
4105             if (PL_expect == XOPERATOR)
4106                 Aop(OP_ADD);
4107             else {
4108                 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4109                     check_uni();
4110                 OPERATOR('+');
4111             }
4112         }
4113
4114     case '*':
4115         if (PL_expect != XOPERATOR) {
4116             s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4117             PL_expect = XOPERATOR;
4118             force_ident(PL_tokenbuf, '*');
4119             if (!*PL_tokenbuf)
4120                 PREREF('*');
4121             TERM('*');
4122         }
4123         s++;
4124         if (*s == '*') {
4125             s++;
4126             PWop(OP_POW);
4127         }
4128         Mop(OP_MULTIPLY);
4129
4130     case '%':
4131         if (PL_expect == XOPERATOR) {
4132             ++s;
4133             Mop(OP_MODULO);
4134         }
4135         PL_tokenbuf[0] = '%';
4136         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4137                 sizeof PL_tokenbuf - 1, FALSE);
4138         if (!PL_tokenbuf[1]) {
4139             PREREF('%');
4140         }
4141         PL_pending_ident = '%';
4142         TERM('%');
4143
4144     case '^':
4145         s++;
4146         BOop(OP_BIT_XOR);
4147     case '[':
4148         PL_lex_brackets++;
4149         /* FALL THROUGH */
4150     case '~':
4151         if (s[1] == '~'
4152             && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
4153         {
4154             s += 2;
4155             Eop(OP_SMARTMATCH);
4156         }
4157     case ',':
4158         {
4159             const char tmp = *s++;
4160             OPERATOR(tmp);
4161         }
4162     case ':':
4163         if (s[1] == ':') {
4164             len = 0;
4165             goto just_a_word_zero_gv;
4166         }
4167         s++;
4168         switch (PL_expect) {
4169             OP *attrs;
4170 #ifdef PERL_MAD
4171             I32 stuffstart;
4172 #endif
4173         case XOPERATOR:
4174             if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4175                 break;
4176             PL_bufptr = s;      /* update in case we back off */
4177             goto grabattrs;
4178         case XATTRBLOCK:
4179             PL_expect = XBLOCK;
4180             goto grabattrs;
4181         case XATTRTERM:
4182             PL_expect = XTERMBLOCK;
4183          grabattrs:
4184 #ifdef PERL_MAD
4185             stuffstart = s - SvPVX(PL_linestr) - 1;
4186 #endif
4187             s = PEEKSPACE(s);
4188             attrs = NULL;
4189             while (isIDFIRST_lazy_if(s,UTF)) {
4190                 I32 tmp;
4191                 SV *sv;
4192                 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4193                 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4194                     if (tmp < 0) tmp = -tmp;
4195                     switch (tmp) {
4196                     case KEY_or:
4197                     case KEY_and:
4198                     case KEY_err:
4199                     case KEY_for:
4200                     case KEY_unless:
4201                     case KEY_if:
4202                     case KEY_while:
4203                     case KEY_until:
4204                         goto got_attrs;
4205                     default:
4206                         break;
4207                     }
4208                 }
4209                 sv = newSVpvn(s, len);
4210                 if (*d == '(') {
4211                     d = scan_str(d,TRUE,TRUE);
4212                     if (!d) {
4213                         /* MUST advance bufptr here to avoid bogus
4214                            "at end of line" context messages from yyerror().
4215                          */
4216                         PL_bufptr = s + len;
4217                         yyerror("Unterminated attribute parameter in attribute list");
4218                         if (attrs)
4219                             op_free(attrs);
4220                         sv_free(sv);
4221                         return REPORT(0);       /* EOF indicator */
4222                     }
4223                 }
4224                 if (PL_lex_stuff) {
4225                     sv_catsv(sv, PL_lex_stuff);
4226                     attrs = append_elem(OP_LIST, attrs,
4227                                         newSVOP(OP_CONST, 0, sv));
4228                     SvREFCNT_dec(PL_lex_stuff);
4229                     PL_lex_stuff = NULL;
4230                 }
4231                 else {
4232                     if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4233                         sv_free(sv);
4234                         if (PL_in_my == KEY_our) {
4235 #ifdef USE_ITHREADS
4236                             GvUNIQUE_on(cGVOPx_gv(yylval.opval));
4237 #else
4238                             /* skip to avoid loading attributes.pm */
4239 #endif
4240                             deprecate(":unique");
4241                         }
4242                         else
4243                             Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4244                     }
4245
4246                     /* NOTE: any CV attrs applied here need to be part of
4247                        the CVf_BUILTIN_ATTRS define in cv.h! */
4248                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4249                         sv_free(sv);
4250                         CvLVALUE_on(PL_compcv);
4251                     }
4252                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4253                         sv_free(sv);
4254                         CvLOCKED_on(PL_compcv);
4255                     }
4256                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4257                         sv_free(sv);
4258                         CvMETHOD_on(PL_compcv);
4259                     }
4260                     else if (!PL_in_my && len == 9 && strnEQ(SvPVX(sv), "assertion", len)) {
4261                         sv_free(sv);
4262                         CvASSERTION_on(PL_compcv);
4263                     }
4264                     /* After we've set the flags, it could be argued that
4265                        we don't need to do the attributes.pm-based setting
4266                        process, and shouldn't bother appending recognized
4267                        flags.  To experiment with that, uncomment the
4268                        following "else".  (Note that's already been
4269                        uncommented.  That keeps the above-applied built-in
4270                        attributes from being intercepted (and possibly
4271                        rejected) by a package's attribute routines, but is
4272                        justified by the performance win for the common case
4273                        of applying only built-in attributes.) */
4274                     else
4275                         attrs = append_elem(OP_LIST, attrs,
4276                                             newSVOP(OP_CONST, 0,
4277                                                     sv));
4278                 }
4279                 s = PEEKSPACE(d);
4280                 if (*s == ':' && s[1] != ':')
4281                     s = PEEKSPACE(s+1);
4282                 else if (s == d)
4283                     break;      /* require real whitespace or :'s */
4284                 /* XXX losing whitespace on sequential attributes here */
4285             }
4286             {
4287                 const char tmp
4288                     = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4289                 if (*s != ';' && *s != '}' && *s != tmp
4290                     && (tmp != '=' || *s != ')')) {
4291                     const char q = ((*s == '\'') ? '"' : '\'');
4292                     /* If here for an expression, and parsed no attrs, back
4293                        off. */
4294                     if (tmp == '=' && !attrs) {
4295                         s = PL_bufptr;
4296                         break;
4297                     }
4298                     /* MUST advance bufptr here to avoid bogus "at end of line"
4299                        context messages from yyerror().
4300                     */
4301                     PL_bufptr = s;
4302                     yyerror( (const char *)
4303                              (*s
4304                               ? Perl_form(aTHX_ "Invalid separator character "
4305                                           "%c%c%c in attribute list", q, *s, q)
4306                               : "Unterminated attribute list" ) );
4307                     if (attrs)
4308                         op_free(attrs);
4309                     OPERATOR(':');
4310                 }
4311             }
4312         got_attrs:
4313             if (attrs) {
4314                 start_force(PL_curforce);
4315                 NEXTVAL_NEXTTOKE.opval = attrs;
4316                 CURMAD('_', PL_nextwhite);
4317                 force_next(THING);
4318             }
4319 #ifdef PERL_MAD
4320             if (PL_madskills) {
4321                 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4322                                      (s - SvPVX(PL_linestr)) - stuffstart);
4323             }
4324 #endif
4325             TOKEN(COLONATTR);
4326         }
4327         OPERATOR(':');
4328     case '(':
4329         s++;
4330         if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4331             PL_oldbufptr = PL_oldoldbufptr;             /* allow print(STDOUT 123) */
4332         else
4333             PL_expect = XTERM;
4334         s = SKIPSPACE1(s);
4335         TOKEN('(');
4336     case ';':
4337         CLINE;
4338         {
4339             const char tmp = *s++;
4340             OPERATOR(tmp);
4341         }
4342     case ')':
4343         {
4344             const char tmp = *s++;
4345             s = SKIPSPACE1(s);
4346             if (*s == '{')
4347                 PREBLOCK(tmp);
4348             TERM(tmp);
4349         }
4350     case ']':
4351         s++;
4352         if (PL_lex_brackets <= 0)
4353             yyerror("Unmatched right square bracket");
4354         else
4355             --PL_lex_brackets;
4356         if (PL_lex_state == LEX_INTERPNORMAL) {
4357             if (PL_lex_brackets == 0) {
4358                 if (*s != '[' && *s != '{' && (*s != '-' || s[1] != '>'))
4359                     PL_lex_state = LEX_INTERPEND;
4360             }
4361         }
4362         TERM(']');
4363     case '{':
4364       leftbracket:
4365         s++;
4366         if (PL_lex_brackets > 100) {
4367             Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4368         }
4369         switch (PL_expect) {
4370         case XTERM:
4371             if (PL_lex_formbrack) {
4372                 s--;
4373                 PRETERMBLOCK(DO);
4374             }
4375             if (PL_oldoldbufptr == PL_last_lop)
4376                 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4377             else
4378                 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4379             OPERATOR(HASHBRACK);
4380         case XOPERATOR:
4381             while (s < PL_bufend && SPACE_OR_TAB(*s))
4382                 s++;
4383             d = s;
4384             PL_tokenbuf[0] = '\0';
4385             if (d < PL_bufend && *d == '-') {
4386                 PL_tokenbuf[0] = '-';
4387                 d++;
4388                 while (d < PL_bufend && SPACE_OR_TAB(*d))
4389                     d++;
4390             }
4391             if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4392                 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4393                               FALSE, &len);
4394                 while (d < PL_bufend && SPACE_OR_TAB(*d))
4395                     d++;
4396                 if (*d == '}') {
4397                     const char minus = (PL_tokenbuf[0] == '-');
4398                     s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4399                     if (minus)
4400                         force_next('-');
4401                 }
4402             }
4403             /* FALL THROUGH */
4404         case XATTRBLOCK:
4405         case XBLOCK:
4406             PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4407             PL_expect = XSTATE;
4408             break;
4409         case XATTRTERM:
4410         case XTERMBLOCK:
4411             PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4412             PL_expect = XSTATE;
4413             break;
4414         default: {
4415                 const char *t;
4416                 if (PL_oldoldbufptr == PL_last_lop)
4417                     PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4418                 else
4419                     PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4420                 s = SKIPSPACE1(s);
4421                 if (*s == '}') {
4422                     if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4423                         PL_expect = XTERM;
4424                         /* This hack is to get the ${} in the message. */
4425                         PL_bufptr = s+1;
4426                         yyerror("syntax error");
4427                         break;
4428                     }
4429                     OPERATOR(HASHBRACK);
4430                 }
4431                 /* This hack serves to disambiguate a pair of curlies
4432                  * as being a block or an anon hash.  Normally, expectation
4433                  * determines that, but in cases where we're not in a
4434                  * position to expect anything in particular (like inside
4435                  * eval"") we have to resolve the ambiguity.  This code
4436                  * covers the case where the first term in the curlies is a
4437                  * quoted string.  Most other cases need to be explicitly
4438                  * disambiguated by prepending a "+" before the opening
4439                  * curly in order to force resolution as an anon hash.
4440                  *
4441                  * XXX should probably propagate the outer expectation
4442                  * into eval"" to rely less on this hack, but that could
4443                  * potentially break current behavior of eval"".
4444                  * GSAR 97-07-21
4445                  */
4446                 t = s;
4447                 if (*s == '\'' || *s == '"' || *s == '`') {
4448                     /* common case: get past first string, handling escapes */
4449                     for (t++; t < PL_bufend && *t != *s;)
4450                         if (*t++ == '\\' && (*t == '\\' || *t == *s))
4451                             t++;
4452                     t++;
4453                 }
4454                 else if (*s == 'q') {
4455                     if (++t < PL_bufend
4456                         && (!isALNUM(*t)
4457                             || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4458                                 && !isALNUM(*t))))
4459                     {
4460                         /* skip q//-like construct */
4461                         const char *tmps;
4462                         char open, close, term;
4463                         I32 brackets = 1;
4464
4465                         while (t < PL_bufend && isSPACE(*t))
4466                             t++;
4467                         /* check for q => */
4468                         if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4469                             OPERATOR(HASHBRACK);
4470                         }
4471                         term = *t;
4472                         open = term;
4473                         if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4474                             term = tmps[5];
4475                         close = term;
4476                         if (open == close)
4477                             for (t++; t < PL_bufend; t++) {
4478                                 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4479                                     t++;
4480                                 else if (*t == open)
4481                                     break;
4482                             }
4483                         else {
4484                             for (t++; t < PL_bufend; t++) {
4485                                 if (*t == '\\' && t+1 < PL_bufend)
4486                                     t++;
4487                                 else if (*t == close && --brackets <= 0)
4488                                     break;
4489                                 else if (*t == open)
4490                                     brackets++;
4491                             }
4492                         }
4493                         t++;
4494                     }
4495                     else
4496                         /* skip plain q word */
4497                         while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4498                              t += UTF8SKIP(t);
4499                 }
4500                 else if (isALNUM_lazy_if(t,UTF)) {
4501                     t += UTF8SKIP(t);
4502                     while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4503                          t += UTF8SKIP(t);
4504                 }
4505                 while (t < PL_bufend && isSPACE(*t))
4506                     t++;
4507                 /* if comma follows first term, call it an anon hash */
4508                 /* XXX it could be a comma expression with loop modifiers */
4509                 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4510                                    || (*t == '=' && t[1] == '>')))
4511                     OPERATOR(HASHBRACK);
4512                 if (PL_expect == XREF)
4513                     PL_expect = XTERM;
4514                 else {
4515                     PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4516                     PL_expect = XSTATE;
4517                 }
4518             }
4519             break;
4520         }
4521         yylval.ival = CopLINE(PL_curcop);
4522         if (isSPACE(*s) || *s == '#')
4523             PL_copline = NOLINE;   /* invalidate current command line number */
4524         TOKEN('{');
4525     case '}':
4526       rightbracket:
4527         s++;
4528         if (PL_lex_brackets <= 0)
4529             yyerror("Unmatched right curly bracket");
4530         else
4531             PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4532         if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4533             PL_lex_formbrack = 0;
4534         if (PL_lex_state == LEX_INTERPNORMAL) {
4535             if (PL_lex_brackets == 0) {
4536                 if (PL_expect & XFAKEBRACK) {
4537                     PL_expect &= XENUMMASK;
4538                     PL_lex_state = LEX_INTERPEND;
4539                     PL_bufptr = s;
4540 #if 0
4541                     if (PL_madskills) {
4542                         if (!PL_thiswhite)
4543                             PL_thiswhite = newSVpvs("");
4544                         sv_catpvn(PL_thiswhite,"}",1);
4545                     }
4546 #endif
4547                     return yylex();     /* ignore fake brackets */
4548                 }
4549                 if (*s == '-' && s[1] == '>')
4550                     PL_lex_state = LEX_INTERPENDMAYBE;
4551                 else if (*s != '[' && *s != '{')
4552                     PL_lex_state = LEX_INTERPEND;
4553             }
4554         }
4555         if (PL_expect & XFAKEBRACK) {
4556             PL_expect &= XENUMMASK;
4557             PL_bufptr = s;
4558             return yylex();             /* ignore fake brackets */
4559         }
4560         start_force(PL_curforce);
4561         if (PL_madskills) {
4562             curmad('X', newSVpvn(s-1,1));
4563             CURMAD('_', PL_thiswhite);
4564         }
4565         force_next('}');
4566 #ifdef PERL_MAD
4567         if (!PL_thistoken)
4568             PL_thistoken = newSVpvs("");
4569 #endif
4570         TOKEN(';');
4571     case '&':
4572         s++;
4573         if (*s++ == '&')
4574             AOPERATOR(ANDAND);
4575         s--;
4576         if (PL_expect == XOPERATOR) {
4577             if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4578                 && isIDFIRST_lazy_if(s,UTF))
4579             {
4580                 CopLINE_dec(PL_curcop);
4581                 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
4582                 CopLINE_inc(PL_curcop);
4583             }
4584             BAop(OP_BIT_AND);
4585         }
4586
4587         s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4588         if (*PL_tokenbuf) {
4589             PL_expect = XOPERATOR;
4590             force_ident(PL_tokenbuf, '&');
4591         }
4592         else
4593             PREREF('&');
4594         yylval.ival = (OPpENTERSUB_AMPER<<8);
4595         TERM('&');
4596
4597     case '|':
4598         s++;
4599         if (*s++ == '|')
4600             AOPERATOR(OROR);
4601         s--;
4602         BOop(OP_BIT_OR);
4603     case '=':
4604         s++;
4605         {
4606             const char tmp = *s++;
4607             if (tmp == '=')
4608                 Eop(OP_EQ);
4609             if (tmp == '>')
4610                 OPERATOR(',');
4611             if (tmp == '~')
4612                 PMop(OP_MATCH);
4613             if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4614                 && strchr("+-*/%.^&|<",tmp))
4615                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4616                             "Reversed %c= operator",(int)tmp);
4617             s--;
4618             if (PL_expect == XSTATE && isALPHA(tmp) &&
4619                 (s == PL_linestart+1 || s[-2] == '\n') )
4620                 {
4621                     if (PL_in_eval && !PL_rsfp) {
4622                         d = PL_bufend;
4623                         while (s < d) {
4624                             if (*s++ == '\n') {
4625                                 incline(s);
4626                                 if (strnEQ(s,"=cut",4)) {
4627                                     s = strchr(s,'\n');
4628                                     if (s)
4629                                         s++;
4630                                     else
4631                                         s = d;
4632                                     incline(s);
4633                                     goto retry;
4634                                 }
4635                             }
4636                         }
4637                         goto retry;
4638                     }
4639 #ifdef PERL_MAD
4640                     if (PL_madskills) {
4641                         if (!PL_thiswhite)
4642                             PL_thiswhite = newSVpvs("");
4643                         sv_catpvn(PL_thiswhite, PL_linestart,
4644                                   PL_bufend - PL_linestart);
4645                     }
4646 #endif
4647                     s = PL_bufend;
4648                     PL_doextract = TRUE;
4649                     goto retry;
4650                 }
4651         }
4652         if (PL_lex_brackets < PL_lex_formbrack) {
4653             const char *t = s;
4654 #ifdef PERL_STRICT_CR
4655             while (SPACE_OR_TAB(*t))
4656 #else
4657             while (SPACE_OR_TAB(*t) || *t == '\r')
4658 #endif
4659                 t++;
4660             if (*t == '\n' || *t == '#') {
4661                 s--;
4662                 PL_expect = XBLOCK;
4663                 goto leftbracket;
4664             }
4665         }
4666         yylval.ival = 0;
4667         OPERATOR(ASSIGNOP);
4668     case '!':
4669         s++;
4670         {
4671             const char tmp = *s++;
4672             if (tmp == '=') {
4673                 /* was this !=~ where !~ was meant?
4674                  * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4675
4676                 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4677                     const char *t = s+1;
4678
4679                     while (t < PL_bufend && isSPACE(*t))
4680                         ++t;
4681
4682                     if (*t == '/' || *t == '?' ||
4683                         ((*t == 'm' || *t == 's' || *t == 'y')
4684                          && !isALNUM(t[1])) ||
4685                         (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4686                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4687                                     "!=~ should be !~");
4688                 }
4689                 Eop(OP_NE);
4690             }
4691             if (tmp == '~')
4692                 PMop(OP_NOT);
4693         }
4694         s--;
4695         OPERATOR('!');
4696     case '<':
4697         if (PL_expect != XOPERATOR) {
4698             if (s[1] != '<' && !strchr(s,'>'))
4699                 check_uni();
4700             if (s[1] == '<')
4701                 s = scan_heredoc(s);
4702             else
4703                 s = scan_inputsymbol(s);
4704             TERM(sublex_start());
4705         }
4706         s++;
4707         {
4708             char tmp = *s++;
4709             if (tmp == '<')
4710                 SHop(OP_LEFT_SHIFT);
4711             if (tmp == '=') {
4712                 tmp = *s++;
4713                 if (tmp == '>')
4714                     Eop(OP_NCMP);
4715                 s--;
4716                 Rop(OP_LE);
4717             }
4718         }
4719         s--;
4720         Rop(OP_LT);
4721     case '>':
4722         s++;
4723         {
4724             const char tmp = *s++;
4725             if (tmp == '>')
4726                 SHop(OP_RIGHT_SHIFT);
4727             else if (tmp == '=')
4728                 Rop(OP_GE);
4729         }
4730         s--;
4731         Rop(OP_GT);
4732
4733     case '$':
4734         CLINE;
4735
4736         if (PL_expect == XOPERATOR) {
4737             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4738                 PL_expect = XTERM;
4739                 deprecate_old(commaless_variable_list);
4740                 return REPORT(','); /* grandfather non-comma-format format */
4741             }
4742         }
4743
4744         if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4745             PL_tokenbuf[0] = '@';
4746             s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4747                            sizeof PL_tokenbuf - 1, FALSE);
4748             if (PL_expect == XOPERATOR)
4749                 no_op("Array length", s);
4750             if (!PL_tokenbuf[1])
4751                 PREREF(DOLSHARP);
4752             PL_expect = XOPERATOR;
4753             PL_pending_ident = '#';
4754             TOKEN(DOLSHARP);
4755         }
4756
4757         PL_tokenbuf[0] = '$';
4758         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4759                        sizeof PL_tokenbuf - 1, FALSE);
4760         if (PL_expect == XOPERATOR)
4761             no_op("Scalar", s);
4762         if (!PL_tokenbuf[1]) {
4763             if (s == PL_bufend)
4764                 yyerror("Final $ should be \\$ or $name");
4765             PREREF('$');
4766         }
4767
4768         /* This kludge not intended to be bulletproof. */
4769         if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4770             yylval.opval = newSVOP(OP_CONST, 0,
4771                                    newSViv(CopARYBASE_get(&PL_compiling)));
4772             yylval.opval->op_private = OPpCONST_ARYBASE;
4773             TERM(THING);
4774         }
4775
4776         d = s;
4777         {
4778             const char tmp = *s;
4779             if (PL_lex_state == LEX_NORMAL)
4780                 s = SKIPSPACE1(s);
4781
4782             if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4783                 && intuit_more(s)) {
4784                 if (*s == '[') {
4785                     PL_tokenbuf[0] = '@';
4786                     if (ckWARN(WARN_SYNTAX)) {
4787                         char *t = s+1;
4788
4789                         while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4790                             t++;
4791                         if (*t++ == ',') {
4792                             PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4793                             while (t < PL_bufend && *t != ']')
4794                                 t++;
4795                             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4796                                         "Multidimensional syntax %.*s not supported",
4797                                     (int)((t - PL_bufptr) + 1), PL_bufptr);
4798                         }
4799                     }
4800                 }
4801                 else if (*s == '{') {
4802                     char *t;
4803                     PL_tokenbuf[0] = '%';
4804                     if (strEQ(PL_tokenbuf+1, "SIG")  && ckWARN(WARN_SYNTAX)
4805                         && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4806                         {
4807                             char tmpbuf[sizeof PL_tokenbuf];
4808                             do {
4809                                 t++;
4810                             } while (isSPACE(*t));
4811                             if (isIDFIRST_lazy_if(t,UTF)) {
4812                                 STRLEN len;
4813                                 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4814                                               &len);
4815                                 while (isSPACE(*t))
4816                                     t++;
4817                                 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
4818                                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4819                                                 "You need to quote \"%s\"",
4820                                                 tmpbuf);
4821                             }
4822                         }
4823                 }
4824             }
4825
4826             PL_expect = XOPERATOR;
4827             if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4828                 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4829                 if (!islop || PL_last_lop_op == OP_GREPSTART)
4830                     PL_expect = XOPERATOR;
4831                 else if (strchr("$@\"'`q", *s))
4832                     PL_expect = XTERM;          /* e.g. print $fh "foo" */
4833                 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4834                     PL_expect = XTERM;          /* e.g. print $fh &sub */
4835                 else if (isIDFIRST_lazy_if(s,UTF)) {
4836                     char tmpbuf[sizeof PL_tokenbuf];
4837                     int t2;
4838                     scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4839                     if ((t2 = keyword(tmpbuf, len, 0))) {
4840                         /* binary operators exclude handle interpretations */
4841                         switch (t2) {
4842                         case -KEY_x:
4843                         case -KEY_eq:
4844                         case -KEY_ne:
4845                         case -KEY_gt:
4846                         case -KEY_lt:
4847                         case -KEY_ge:
4848                         case -KEY_le:
4849                         case -KEY_cmp:
4850                             break;
4851                         default:
4852                             PL_expect = XTERM;  /* e.g. print $fh length() */
4853                             break;
4854                         }
4855                     }
4856                     else {
4857                         PL_expect = XTERM;      /* e.g. print $fh subr() */
4858                     }
4859                 }
4860                 else if (isDIGIT(*s))
4861                     PL_expect = XTERM;          /* e.g. print $fh 3 */
4862                 else if (*s == '.' && isDIGIT(s[1]))
4863                     PL_expect = XTERM;          /* e.g. print $fh .3 */
4864                 else if ((*s == '?' || *s == '-' || *s == '+')
4865                          && !isSPACE(s[1]) && s[1] != '=')
4866                     PL_expect = XTERM;          /* e.g. print $fh -1 */
4867                 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4868                          && s[1] != '/')
4869                     PL_expect = XTERM;          /* e.g. print $fh /.../
4870                                                    XXX except DORDOR operator
4871                                                 */
4872                 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4873                          && s[2] != '=')
4874                     PL_expect = XTERM;          /* print $fh <<"EOF" */
4875             }
4876         }
4877         PL_pending_ident = '$';
4878         TOKEN('$');
4879
4880     case '@':
4881         if (PL_expect == XOPERATOR)
4882             no_op("Array", s);
4883         PL_tokenbuf[0] = '@';
4884         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
4885         if (!PL_tokenbuf[1]) {
4886             PREREF('@');
4887         }
4888         if (PL_lex_state == LEX_NORMAL)
4889             s = SKIPSPACE1(s);
4890         if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
4891             if (*s == '{')
4892                 PL_tokenbuf[0] = '%';
4893
4894             /* Warn about @ where they meant $. */
4895             if (*s == '[' || *s == '{') {
4896                 if (ckWARN(WARN_SYNTAX)) {
4897                     const char *t = s + 1;
4898                     while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
4899                         t++;
4900                     if (*t == '}' || *t == ']') {
4901                         t++;
4902                         PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4903                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4904                             "Scalar value %.*s better written as $%.*s",
4905                             (int)(t-PL_bufptr), PL_bufptr,
4906                             (int)(t-PL_bufptr-1), PL_bufptr+1);
4907                     }
4908                 }
4909             }
4910         }
4911         PL_pending_ident = '@';
4912         TERM('@');
4913
4914      case '/':                  /* may be division, defined-or, or pattern */
4915         if (PL_expect == XTERMORDORDOR && s[1] == '/') {
4916             s += 2;
4917             AOPERATOR(DORDOR);
4918         }
4919      case '?':                  /* may either be conditional or pattern */
4920          if(PL_expect == XOPERATOR) {
4921              char tmp = *s++;
4922              if(tmp == '?') {
4923                   OPERATOR('?');
4924              }
4925              else {
4926                  tmp = *s++;
4927                  if(tmp == '/') {
4928                      /* A // operator. */
4929                     AOPERATOR(DORDOR);
4930                  }
4931                  else {
4932                      s--;
4933                      Mop(OP_DIVIDE);
4934                  }
4935              }
4936          }
4937          else {
4938              /* Disable warning on "study /blah/" */
4939              if (PL_oldoldbufptr == PL_last_uni
4940               && (*PL_last_uni != 's' || s - PL_last_uni < 5
4941                   || memNE(PL_last_uni, "study", 5)
4942                   || isALNUM_lazy_if(PL_last_uni+5,UTF)
4943               ))
4944                  check_uni();
4945              s = scan_pat(s,OP_MATCH);
4946              TERM(sublex_start());
4947          }
4948
4949     case '.':
4950         if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
4951 #ifdef PERL_STRICT_CR
4952             && s[1] == '\n'
4953 #else
4954             && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
4955 #endif
4956             && (s == PL_linestart || s[-1] == '\n') )
4957         {
4958             PL_lex_formbrack = 0;
4959             PL_expect = XSTATE;
4960             goto rightbracket;
4961         }
4962         if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
4963             char tmp = *s++;
4964             if (*s == tmp) {
4965                 s++;
4966                 if (*s == tmp) {
4967                     s++;
4968                     yylval.ival = OPf_SPECIAL;
4969                 }
4970                 else
4971                     yylval.ival = 0;
4972                 OPERATOR(DOTDOT);
4973             }
4974             if (PL_expect != XOPERATOR)
4975                 check_uni();
4976             Aop(OP_CONCAT);
4977         }
4978         /* FALL THROUGH */
4979     case '0': case '1': case '2': case '3': case '4':
4980     case '5': case '6': case '7': case '8': case '9':
4981         s = scan_num(s, &yylval);
4982         DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
4983         if (PL_expect == XOPERATOR)
4984             no_op("Number",s);
4985         TERM(THING);
4986
4987     case '\'':
4988         s = scan_str(s,!!PL_madskills,FALSE);
4989         DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
4990         if (PL_expect == XOPERATOR) {
4991             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4992                 PL_expect = XTERM;
4993                 deprecate_old(commaless_variable_list);
4994                 return REPORT(','); /* grandfather non-comma-format format */
4995             }
4996             else
4997                 no_op("String",s);
4998         }
4999         if (!s)
5000             missingterm(NULL);
5001         yylval.ival = OP_CONST;
5002         TERM(sublex_start());
5003
5004     case '"':
5005         s = scan_str(s,!!PL_madskills,FALSE);
5006         DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5007         if (PL_expect == XOPERATOR) {
5008             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5009                 PL_expect = XTERM;
5010                 deprecate_old(commaless_variable_list);
5011                 return REPORT(','); /* grandfather non-comma-format format */
5012             }
5013             else
5014                 no_op("String",s);
5015         }
5016         if (!s)
5017             missingterm(NULL);
5018         yylval.ival = OP_CONST;
5019         /* FIXME. I think that this can be const if char *d is replaced by
5020            more localised variables.  */
5021         for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
5022             if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
5023                 yylval.ival = OP_STRINGIFY;
5024                 break;
5025             }
5026         }
5027         TERM(sublex_start());
5028
5029     case '`':
5030         s = scan_str(s,!!PL_madskills,FALSE);
5031         DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
5032         if (PL_expect == XOPERATOR)
5033             no_op("Backticks",s);
5034         if (!s)
5035             missingterm(NULL);
5036         readpipe_override();
5037         TERM(sublex_start());
5038
5039     case '\\':
5040         s++;
5041         if (PL_lex_inwhat && isDIGIT(*s) && ckWARN(WARN_SYNTAX))
5042             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5043                         *s, *s);
5044         if (PL_expect == XOPERATOR)
5045             no_op("Backslash",s);
5046         OPERATOR(REFGEN);
5047
5048     case 'v':
5049         if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
5050             char *start = s + 2;
5051             while (isDIGIT(*start) || *start == '_')
5052                 start++;
5053             if (*start == '.' && isDIGIT(start[1])) {
5054                 s = scan_num(s, &yylval);
5055                 TERM(THING);
5056             }
5057             /* avoid v123abc() or $h{v1}, allow C<print v10;> */
5058             else if (!isALPHA(*start) && (PL_expect == XTERM
5059                         || PL_expect == XREF || PL_expect == XSTATE
5060                         || PL_expect == XTERMORDORDOR)) {
5061                 /* XXX Use gv_fetchpvn rather than stomping on a const string */
5062                 const char c = *start;
5063                 GV *gv;
5064                 *start = '\0';
5065                 gv = gv_fetchpv(s, 0, SVt_PVCV);
5066                 *start = c;
5067                 if (!gv) {
5068                     s = scan_num(s, &yylval);
5069                     TERM(THING);
5070                 }
5071             }
5072         }
5073         goto keylookup;
5074     case 'x':
5075         if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5076             s++;
5077             Mop(OP_REPEAT);
5078         }
5079         goto keylookup;
5080
5081     case '_':
5082     case 'a': case 'A':
5083     case 'b': case 'B':
5084     case 'c': case 'C':
5085     case 'd': case 'D':
5086     case 'e': case 'E':
5087     case 'f': case 'F':
5088     case 'g': case 'G':
5089     case 'h': case 'H':
5090     case 'i': case 'I':
5091     case 'j': case 'J':
5092     case 'k': case 'K':
5093     case 'l': case 'L':
5094     case 'm': case 'M':
5095     case 'n': case 'N':
5096     case 'o': case 'O':
5097     case 'p': case 'P':
5098     case 'q': case 'Q':
5099     case 'r': case 'R':
5100     case 's': case 'S':
5101     case 't': case 'T':
5102     case 'u': case 'U':
5103               case 'V':
5104     case 'w': case 'W':
5105               case 'X':
5106     case 'y': case 'Y':
5107     case 'z': case 'Z':
5108
5109       keylookup: {
5110         I32 tmp;
5111
5112         orig_keyword = 0;
5113         gv = NULL;
5114         gvp = NULL;
5115
5116         PL_bufptr = s;
5117         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5118
5119         /* Some keywords can be followed by any delimiter, including ':' */
5120         tmp = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
5121                (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5122                              (PL_tokenbuf[0] == 'q' &&
5123                               strchr("qwxr", PL_tokenbuf[1])))));
5124
5125         /* x::* is just a word, unless x is "CORE" */
5126         if (!tmp && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
5127             goto just_a_word;
5128
5129         d = s;
5130         while (d < PL_bufend && isSPACE(*d))
5131                 d++;    /* no comments skipped here, or s### is misparsed */
5132
5133         /* Is this a label? */
5134         if (!tmp && PL_expect == XSTATE
5135               && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5136             s = d + 1;
5137             yylval.pval = CopLABEL_alloc(PL_tokenbuf);
5138             CLINE;
5139             TOKEN(LABEL);
5140         }
5141
5142         /* Check for keywords */
5143         tmp = keyword(PL_tokenbuf, len, 0);
5144
5145         /* Is this a word before a => operator? */
5146         if (*d == '=' && d[1] == '>') {
5147             CLINE;
5148             yylval.opval
5149                 = (OP*)newSVOP(OP_CONST, 0,
5150                                S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
5151             yylval.opval->op_private = OPpCONST_BARE;
5152             TERM(WORD);
5153         }
5154
5155         if (tmp < 0) {                  /* second-class keyword? */
5156             GV *ogv = NULL;     /* override (winner) */
5157             GV *hgv = NULL;     /* hidden (loser) */
5158             if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
5159                 CV *cv;
5160                 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
5161                     (cv = GvCVu(gv)))
5162                 {
5163                     if (GvIMPORTED_CV(gv))
5164                         ogv = gv;
5165                     else if (! CvMETHOD(cv))
5166                         hgv = gv;
5167                 }
5168                 if (!ogv &&
5169                     (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
5170                     (gv = *gvp) && isGV_with_GP(gv) &&
5171                     GvCVu(gv) && GvIMPORTED_CV(gv))
5172                 {
5173                     ogv = gv;
5174                 }
5175             }
5176             if (ogv) {
5177                 orig_keyword = tmp;
5178                 tmp = 0;                /* overridden by import or by GLOBAL */
5179             }
5180             else if (gv && !gvp
5181                      && -tmp==KEY_lock  /* XXX generalizable kludge */
5182                      && GvCVu(gv)
5183                      && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
5184             {
5185                 tmp = 0;                /* any sub overrides "weak" keyword */
5186             }
5187             else {                      /* no override */
5188                 tmp = -tmp;
5189                 if (tmp == KEY_dump && ckWARN(WARN_MISC)) {
5190                     Perl_warner(aTHX_ packWARN(WARN_MISC),
5191                             "dump() better written as CORE::dump()");
5192                 }
5193                 gv = NULL;
5194                 gvp = 0;
5195                 if (hgv && tmp != KEY_x && tmp != KEY_CORE
5196                         && ckWARN(WARN_AMBIGUOUS))      /* never ambiguous */
5197                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5198                         "Ambiguous call resolved as CORE::%s(), %s",
5199                          GvENAME(hgv), "qualify as such or use &");
5200             }
5201         }
5202
5203       reserved_word:
5204         switch (tmp) {
5205
5206         default:                        /* not a keyword */
5207             /* Trade off - by using this evil construction we can pull the
5208                variable gv into the block labelled keylookup. If not, then
5209                we have to give it function scope so that the goto from the
5210                earlier ':' case doesn't bypass the initialisation.  */
5211             if (0) {
5212             just_a_word_zero_gv:
5213                 gv = NULL;
5214                 gvp = NULL;
5215                 orig_keyword = 0;
5216             }
5217           just_a_word: {
5218                 SV *sv;
5219                 int pkgname = 0;
5220                 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
5221                 CV *cv;
5222 #ifdef PERL_MAD
5223                 SV *nextPL_nextwhite = 0;
5224 #endif
5225
5226
5227                 /* Get the rest if it looks like a package qualifier */
5228
5229                 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
5230                     STRLEN morelen;
5231                     s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
5232                                   TRUE, &morelen);
5233                     if (!morelen)
5234                         Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
5235                                 *s == '\'' ? "'" : "::");
5236                     len += morelen;
5237                     pkgname = 1;
5238                 }
5239
5240                 if (PL_expect == XOPERATOR) {
5241                     if (PL_bufptr == PL_linestart) {
5242                         CopLINE_dec(PL_curcop);
5243                         Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), PL_warn_nosemi);
5244                         CopLINE_inc(PL_curcop);
5245                     }
5246                     else
5247                         no_op("Bareword",s);
5248                 }
5249
5250                 /* Look for a subroutine with this name in current package,
5251                    unless name is "Foo::", in which case Foo is a bearword
5252                    (and a package name). */
5253
5254                 if (len > 2 && !PL_madskills &&
5255                     PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
5256                 {
5257                     if (ckWARN(WARN_BAREWORD)
5258                         && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
5259                         Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
5260                             "Bareword \"%s\" refers to nonexistent package",
5261                              PL_tokenbuf);
5262                     len -= 2;
5263                     PL_tokenbuf[len] = '\0';
5264                     gv = NULL;
5265                     gvp = 0;
5266                 }
5267                 else {
5268                     if (!gv) {
5269                         /* Mustn't actually add anything to a symbol table.
5270                            But also don't want to "initialise" any placeholder
5271                            constants that might already be there into full
5272                            blown PVGVs with attached PVCV.  */
5273                         gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5274                                                GV_NOADD_NOINIT, SVt_PVCV);
5275                     }
5276                     len = 0;
5277                 }
5278
5279                 /* if we saw a global override before, get the right name */
5280
5281                 if (gvp) {
5282                     sv = newSVpvs("CORE::GLOBAL::");
5283                     sv_catpv(sv,PL_tokenbuf);
5284                 }
5285                 else {
5286                     /* If len is 0, newSVpv does strlen(), which is correct.
5287                        If len is non-zero, then it will be the true length,
5288                        and so the scalar will be created correctly.  */
5289                     sv = newSVpv(PL_tokenbuf,len);
5290                 }
5291 #ifdef PERL_MAD
5292                 if (PL_madskills && !PL_thistoken) {
5293                     char *start = SvPVX(PL_linestr) + PL_realtokenstart;
5294                     PL_thistoken = newSVpv(start,s - start);
5295                     PL_realtokenstart = s - SvPVX(PL_linestr);
5296                 }
5297 #endif
5298
5299                 /* Presume this is going to be a bareword of some sort. */
5300
5301                 CLINE;
5302                 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5303                 yylval.opval->op_private = OPpCONST_BARE;
5304                 /* UTF-8 package name? */
5305                 if (UTF && !IN_BYTES &&
5306                     is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
5307                     SvUTF8_on(sv);
5308
5309                 /* And if "Foo::", then that's what it certainly is. */
5310
5311                 if (len)
5312                     goto safe_bareword;
5313
5314                 /* Do the explicit type check so that we don't need to force
5315                    the initialisation of the symbol table to have a real GV.
5316                    Beware - gv may not really be a PVGV, cv may not really be
5317                    a PVCV, (because of the space optimisations that gv_init
5318                    understands) But they're true if for this symbol there is
5319                    respectively a typeglob and a subroutine.
5320                 */
5321                 cv = gv ? ((SvTYPE(gv) == SVt_PVGV)
5322                     /* Real typeglob, so get the real subroutine: */
5323                            ? GvCVu(gv)
5324                     /* A proxy for a subroutine in this package? */
5325                            : SvOK(gv) ? (CV *) gv : NULL)
5326                     : NULL;
5327
5328                 /* See if it's the indirect object for a list operator. */
5329
5330                 if (PL_oldoldbufptr &&
5331                     PL_oldoldbufptr < PL_bufptr &&
5332                     (PL_oldoldbufptr == PL_last_lop
5333                      || PL_oldoldbufptr == PL_last_uni) &&
5334                     /* NO SKIPSPACE BEFORE HERE! */
5335                     (PL_expect == XREF ||
5336                      ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
5337                 {
5338                     bool immediate_paren = *s == '(';
5339
5340                     /* (Now we can afford to cross potential line boundary.) */
5341                     s = SKIPSPACE2(s,nextPL_nextwhite);
5342 #ifdef PERL_MAD
5343                     PL_nextwhite = nextPL_nextwhite;    /* assume no & deception */
5344 #endif
5345
5346                     /* Two barewords in a row may indicate method call. */
5347
5348                     if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
5349                         (tmp = intuit_method(s, gv, cv)))
5350                         return REPORT(tmp);
5351
5352                     /* If not a declared subroutine, it's an indirect object. */
5353                     /* (But it's an indir obj regardless for sort.) */
5354                     /* Also, if "_" follows a filetest operator, it's a bareword */
5355
5356                     if (
5357                         ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
5358                          ((!gv || !cv) &&
5359                         (PL_last_lop_op != OP_MAPSTART &&
5360                          PL_last_lop_op != OP_GREPSTART))))
5361                        || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5362                             && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5363                        )
5364                     {
5365                         PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
5366                         goto bareword;
5367                     }
5368                 }
5369
5370                 PL_expect = XOPERATOR;
5371 #ifdef PERL_MAD
5372                 if (isSPACE(*s))
5373                     s = SKIPSPACE2(s,nextPL_nextwhite);
5374                 PL_nextwhite = nextPL_nextwhite;
5375 #else
5376                 s = skipspace(s);
5377 #endif
5378
5379                 /* Is this a word before a => operator? */
5380                 if (*s == '=' && s[1] == '>' && !pkgname) {
5381                     CLINE;
5382                     sv_setpv(((SVOP*)yylval.opval)->op_sv, PL_tokenbuf);
5383                     if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
5384                       SvUTF8_on(((SVOP*)yylval.opval)->op_sv);
5385                     TERM(WORD);
5386                 }
5387
5388                 /* If followed by a paren, it's certainly a subroutine. */
5389                 if (*s == '(') {
5390                     CLINE;
5391                     if (cv) {
5392                         d = s + 1;
5393                         while (SPACE_OR_TAB(*d))
5394                             d++;
5395                         if (*d == ')' && (sv = gv_const_sv(gv))) {
5396                             s = d + 1;
5397 #ifdef PERL_MAD
5398                             if (PL_madskills) {
5399                                 char *par = SvPVX(PL_linestr) + PL_realtokenstart; 
5400                                 sv_catpvn(PL_thistoken, par, s - par);
5401                                 if (PL_nextwhite) {
5402                                     sv_free(PL_nextwhite);
5403                                     PL_nextwhite = 0;
5404                                 }
5405                             }
5406 #endif
5407                             goto its_constant;
5408                         }
5409                     }
5410 #ifdef PERL_MAD
5411                     if (PL_madskills) {
5412                         PL_nextwhite = PL_thiswhite;
5413                         PL_thiswhite = 0;
5414                     }
5415                     start_force(PL_curforce);
5416 #endif
5417                     NEXTVAL_NEXTTOKE.opval = yylval.opval;
5418                     PL_expect = XOPERATOR;
5419 #ifdef PERL_MAD
5420                     if (PL_madskills) {
5421                         PL_nextwhite = nextPL_nextwhite;
5422                         curmad('X', PL_thistoken);
5423                         PL_thistoken = newSVpvs("");
5424                     }
5425 #endif
5426                     force_next(WORD);
5427                     yylval.ival = 0;
5428                     TOKEN('&');
5429                 }
5430
5431                 /* If followed by var or block, call it a method (unless sub) */
5432
5433                 if ((*s == '$' || *s == '{') && (!gv || !cv)) {
5434                     PL_last_lop = PL_oldbufptr;
5435                     PL_last_lop_op = OP_METHOD;
5436                     PREBLOCK(METHOD);
5437                 }
5438
5439                 /* If followed by a bareword, see if it looks like indir obj. */
5440
5441                 if (!orig_keyword
5442                         && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
5443                         && (tmp = intuit_method(s, gv, cv)))
5444                     return REPORT(tmp);
5445
5446                 /* Not a method, so call it a subroutine (if defined) */
5447
5448                 if (cv) {
5449                     if (lastchar == '-' && ckWARN_d(WARN_AMBIGUOUS))
5450                         Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5451                                 "Ambiguous use of -%s resolved as -&%s()",
5452                                 PL_tokenbuf, PL_tokenbuf);
5453                     /* Check for a constant sub */
5454                     if ((sv = gv_const_sv(gv))) {
5455                   its_constant:
5456                         SvREFCNT_dec(((SVOP*)yylval.opval)->op_sv);
5457                         ((SVOP*)yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5458                         yylval.opval->op_private = 0;
5459                         TOKEN(WORD);
5460                     }
5461
5462                     /* Resolve to GV now. */
5463                     if (SvTYPE(gv) != SVt_PVGV) {
5464                         gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV);
5465                         assert (SvTYPE(gv) == SVt_PVGV);
5466                         /* cv must have been some sort of placeholder, so
5467                            now needs replacing with a real code reference.  */
5468                         cv = GvCV(gv);
5469                     }
5470
5471                     op_free(yylval.opval);
5472                     yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5473                     yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5474                     PL_last_lop = PL_oldbufptr;
5475                     PL_last_lop_op = OP_ENTERSUB;
5476                     /* Is there a prototype? */
5477                     if (
5478 #ifdef PERL_MAD
5479                         cv &&
5480 #endif
5481                         SvPOK(cv))
5482                     {
5483                         STRLEN protolen;
5484                         const char *proto = SvPV_const((SV*)cv, protolen);
5485                         if (!protolen)
5486                             TERM(FUNC0SUB);
5487                         if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
5488                             OPERATOR(UNIOPSUB);
5489                         while (*proto == ';')
5490                             proto++;
5491                         if (*proto == '&' && *s == '{') {
5492                             sv_setpv(PL_subname,
5493                                      (const char *)
5494                                      (PL_curstash ?
5495                                       "__ANON__" : "__ANON__::__ANON__"));
5496                             PREBLOCK(LSTOPSUB);
5497                         }
5498                     }
5499 #ifdef PERL_MAD
5500                     {
5501                         if (PL_madskills) {
5502                             PL_nextwhite = PL_thiswhite;
5503                             PL_thiswhite = 0;
5504                         }
5505                         start_force(PL_curforce);
5506                         NEXTVAL_NEXTTOKE.opval = yylval.opval;
5507                         PL_expect = XTERM;
5508                         if (PL_madskills) {
5509                             PL_nextwhite = nextPL_nextwhite;
5510                             curmad('X', PL_thistoken);
5511                             PL_thistoken = newSVpvs("");
5512                         }
5513                         force_next(WORD);
5514                         TOKEN(NOAMP);
5515                     }
5516                 }
5517
5518                 /* Guess harder when madskills require "best effort". */
5519                 if (PL_madskills && (!gv || !GvCVu(gv))) {
5520                     int probable_sub = 0;
5521                     if (strchr("\"'`$@%0123456789!*+{[<", *s))
5522                         probable_sub = 1;
5523                     else if (isALPHA(*s)) {
5524                         char tmpbuf[1024];
5525                         STRLEN tmplen;
5526                         d = s;
5527                         d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5528                         if (!keyword(tmpbuf, tmplen, 0))
5529                             probable_sub = 1;
5530                         else {
5531                             while (d < PL_bufend && isSPACE(*d))
5532                                 d++;
5533                             if (*d == '=' && d[1] == '>')
5534                                 probable_sub = 1;
5535                         }
5536                     }
5537                     if (probable_sub) {
5538                         gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
5539                         op_free(yylval.opval);
5540                         yylval.opval = newCVREF(0, newGVOP(OP_GV, 0, gv));
5541                         yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5542                         PL_last_lop = PL_oldbufptr;
5543                         PL_last_lop_op = OP_ENTERSUB;
5544                         PL_nextwhite = PL_thiswhite;
5545                         PL_thiswhite = 0;
5546                         start_force(PL_curforce);
5547                         NEXTVAL_NEXTTOKE.opval = yylval.opval;
5548                         PL_expect = XTERM;
5549                         PL_nextwhite = nextPL_nextwhite;
5550                         curmad('X', PL_thistoken);
5551                         PL_thistoken = newSVpvs("");
5552                         force_next(WORD);
5553                         TOKEN(NOAMP);
5554                     }
5555 #else
5556                     NEXTVAL_NEXTTOKE.opval = yylval.opval;
5557                     PL_expect = XTERM;
5558                     force_next(WORD);
5559                     TOKEN(NOAMP);
5560 #endif
5561                 }
5562
5563                 /* Call it a bare word */
5564
5565                 if (PL_hints & HINT_STRICT_SUBS)
5566                     yylval.opval->op_private |= OPpCONST_STRICT;
5567                 else {
5568                 bareword:
5569                     if (lastchar != '-') {
5570                         if (ckWARN(WARN_RESERVED)) {
5571                             d = PL_tokenbuf;
5572                             while (isLOWER(*d))
5573                                 d++;
5574                             if (!*d && !gv_stashpv(PL_tokenbuf, 0))
5575                                 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5576                                        PL_tokenbuf);
5577                         }
5578                     }
5579                 }
5580
5581             safe_bareword:
5582                 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')
5583                     && ckWARN_d(WARN_AMBIGUOUS)) {
5584                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5585                         "Operator or semicolon missing before %c%s",
5586                         lastchar, PL_tokenbuf);
5587                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5588                         "Ambiguous use of %c resolved as operator %c",
5589                         lastchar, lastchar);
5590                 }
5591                 TOKEN(WORD);
5592             }
5593
5594         case KEY___FILE__:
5595             yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5596                                         newSVpv(CopFILE(PL_curcop),0));
5597             TERM(THING);
5598
5599         case KEY___LINE__:
5600             yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5601                                     Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
5602             TERM(THING);
5603
5604         case KEY___PACKAGE__:
5605             yylval.opval = (OP*)newSVOP(OP_CONST, 0,
5606                                         (PL_curstash
5607                                          ? newSVhek(HvNAME_HEK(PL_curstash))
5608                                          : &PL_sv_undef));
5609             TERM(THING);
5610
5611         case KEY___DATA__:
5612         case KEY___END__: {
5613             GV *gv;
5614             if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
5615                 const char *pname = "main";
5616                 if (PL_tokenbuf[2] == 'D')
5617                     pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
5618                 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5619                                 SVt_PVIO);
5620                 GvMULTI_on(gv);
5621                 if (!GvIO(gv))
5622                     GvIOp(gv) = newIO();
5623                 IoIFP(GvIOp(gv)) = PL_rsfp;
5624 #if defined(HAS_FCNTL) && defined(F_SETFD)
5625                 {
5626                     const int fd = PerlIO_fileno(PL_rsfp);
5627                     fcntl(fd,F_SETFD,fd >= 3);
5628                 }
5629 #endif
5630                 /* Mark this internal pseudo-handle as clean */
5631                 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
5632                 if (PL_preprocess)
5633                     IoTYPE(GvIOp(gv)) = IoTYPE_PIPE;
5634                 else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
5635                     IoTYPE(GvIOp(gv)) = IoTYPE_STD;
5636                 else
5637                     IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
5638 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5639                 /* if the script was opened in binmode, we need to revert
5640                  * it to text mode for compatibility; but only iff it has CRs
5641                  * XXX this is a questionable hack at best. */
5642                 if (PL_bufend-PL_bufptr > 2
5643                     && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
5644                 {
5645                     Off_t loc = 0;
5646                     if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
5647                         loc = PerlIO_tell(PL_rsfp);
5648                         (void)PerlIO_seek(PL_rsfp, 0L, 0);
5649                     }
5650 #ifdef NETWARE
5651                         if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5652 #else
5653                     if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
5654 #endif  /* NETWARE */
5655 #ifdef PERLIO_IS_STDIO /* really? */
5656 #  if defined(__BORLANDC__)
5657                         /* XXX see note in do_binmode() */
5658                         ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
5659 #  endif
5660 #endif
5661                         if (loc > 0)
5662                             PerlIO_seek(PL_rsfp, loc, 0);
5663                     }
5664                 }
5665 #endif
5666 #ifdef PERLIO_LAYERS
5667                 if (!IN_BYTES) {
5668                     if (UTF)
5669                         PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5670                     else if (PL_encoding) {
5671                         SV *name;
5672                         dSP;
5673                         ENTER;
5674                         SAVETMPS;
5675                         PUSHMARK(sp);
5676                         EXTEND(SP, 1);
5677                         XPUSHs(PL_encoding);
5678                         PUTBACK;
5679                         call_method("name", G_SCALAR);
5680                         SPAGAIN;
5681                         name = POPs;
5682                         PUTBACK;
5683                         PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
5684                                             Perl_form(aTHX_ ":encoding(%"SVf")",
5685                                                       SVfARG(name)));
5686                         FREETMPS;
5687                         LEAVE;
5688                     }
5689                 }
5690 #endif
5691 #ifdef PERL_MAD
5692                 if (PL_madskills) {
5693                     if (PL_realtokenstart >= 0) {
5694                         char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5695                         if (!PL_endwhite)
5696                             PL_endwhite = newSVpvs("");
5697                         sv_catsv(PL_endwhite, PL_thiswhite);
5698                         PL_thiswhite = 0;
5699                         sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5700                         PL_realtokenstart = -1;
5701                     }
5702                     while ((s = filter_gets(PL_endwhite, PL_rsfp,
5703                                  SvCUR(PL_endwhite))) != Nullch) ;
5704                 }
5705 #endif
5706                 PL_rsfp = NULL;
5707             }
5708             goto fake_eof;
5709         }
5710
5711         case KEY_AUTOLOAD:
5712         case KEY_DESTROY:
5713         case KEY_BEGIN:
5714         case KEY_UNITCHECK:
5715         case KEY_CHECK:
5716         case KEY_INIT:
5717         case KEY_END:
5718             if (PL_expect == XSTATE) {
5719                 s = PL_bufptr;
5720                 goto really_sub;
5721             }
5722             goto just_a_word;
5723
5724         case KEY_CORE:
5725             if (*s == ':' && s[1] == ':') {
5726                 s += 2;
5727                 d = s;
5728                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5729                 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
5730                     Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
5731                 if (tmp < 0)
5732                     tmp = -tmp;
5733                 else if (tmp == KEY_require || tmp == KEY_do)
5734                     /* that's a way to remember we saw "CORE::" */
5735                     orig_keyword = tmp;
5736                 goto reserved_word;
5737             }
5738             goto just_a_word;
5739
5740         case KEY_abs:
5741             UNI(OP_ABS);
5742
5743         case KEY_alarm:
5744             UNI(OP_ALARM);
5745
5746         case KEY_accept:
5747             LOP(OP_ACCEPT,XTERM);
5748
5749         case KEY_and:
5750             OPERATOR(ANDOP);
5751
5752         case KEY_atan2:
5753             LOP(OP_ATAN2,XTERM);
5754
5755         case KEY_bind:
5756             LOP(OP_BIND,XTERM);
5757
5758         case KEY_binmode:
5759             LOP(OP_BINMODE,XTERM);
5760
5761         case KEY_bless:
5762             LOP(OP_BLESS,XTERM);
5763
5764         case KEY_break:
5765             FUN0(OP_BREAK);
5766
5767         case KEY_chop:
5768             UNI(OP_CHOP);
5769
5770         case KEY_continue:
5771             /* When 'use switch' is in effect, continue has a dual
5772                life as a control operator. */
5773             {
5774                 if (!FEATURE_IS_ENABLED("switch"))
5775                     PREBLOCK(CONTINUE);
5776                 else {
5777                     /* We have to disambiguate the two senses of
5778                       "continue". If the next token is a '{' then
5779                       treat it as the start of a continue block;
5780                       otherwise treat it as a control operator.
5781                      */
5782                     s = skipspace(s);
5783                     if (*s == '{')
5784             PREBLOCK(CONTINUE);
5785                     else
5786                         FUN0(OP_CONTINUE);
5787                 }
5788             }
5789
5790         case KEY_chdir:
5791             /* may use HOME */
5792             (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
5793             UNI(OP_CHDIR);
5794
5795         case KEY_close:
5796             UNI(OP_CLOSE);
5797
5798         case KEY_closedir:
5799             UNI(OP_CLOSEDIR);
5800
5801         case KEY_cmp:
5802             Eop(OP_SCMP);
5803
5804         case KEY_caller:
5805             UNI(OP_CALLER);
5806
5807         case KEY_crypt:
5808 #ifdef FCRYPT
5809             if (!PL_cryptseen) {
5810                 PL_cryptseen = TRUE;
5811                 init_des();
5812             }
5813 #endif
5814             LOP(OP_CRYPT,XTERM);
5815
5816         case KEY_chmod:
5817             LOP(OP_CHMOD,XTERM);
5818
5819         case KEY_chown:
5820             LOP(OP_CHOWN,XTERM);
5821
5822         case KEY_connect:
5823             LOP(OP_CONNECT,XTERM);
5824
5825         case KEY_chr:
5826             UNI(OP_CHR);
5827
5828         case KEY_cos:
5829             UNI(OP_COS);
5830
5831         case KEY_chroot:
5832             UNI(OP_CHROOT);
5833
5834         case KEY_default:
5835             PREBLOCK(DEFAULT);
5836
5837         case KEY_do:
5838             s = SKIPSPACE1(s);
5839             if (*s == '{')
5840                 PRETERMBLOCK(DO);
5841             if (*s != '\'')
5842                 s = force_word(s,WORD,TRUE,TRUE,FALSE);
5843             if (orig_keyword == KEY_do) {
5844                 orig_keyword = 0;
5845                 yylval.ival = 1;
5846             }
5847             else
5848                 yylval.ival = 0;
5849             OPERATOR(DO);
5850
5851         case KEY_die:
5852             PL_hints |= HINT_BLOCK_SCOPE;
5853             LOP(OP_DIE,XTERM);
5854
5855         case KEY_defined:
5856             UNI(OP_DEFINED);
5857
5858         case KEY_delete:
5859             UNI(OP_DELETE);
5860
5861         case KEY_dbmopen:
5862             gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
5863             LOP(OP_DBMOPEN,XTERM);
5864
5865         case KEY_dbmclose:
5866             UNI(OP_DBMCLOSE);
5867
5868         case KEY_dump:
5869             s = force_word(s,WORD,TRUE,FALSE,FALSE);
5870             LOOPX(OP_DUMP);
5871
5872         case KEY_else:
5873             PREBLOCK(ELSE);
5874
5875         case KEY_elsif:
5876             yylval.ival = CopLINE(PL_curcop);
5877             OPERATOR(ELSIF);
5878
5879         case KEY_eq:
5880             Eop(OP_SEQ);
5881
5882         case KEY_exists:
5883             UNI(OP_EXISTS);
5884         
5885         case KEY_exit:
5886             if (PL_madskills)
5887                 UNI(OP_INT);
5888             UNI(OP_EXIT);
5889
5890         case KEY_eval:
5891             s = SKIPSPACE1(s);
5892             PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
5893             UNIBRACK(OP_ENTEREVAL);
5894
5895         case KEY_eof:
5896             UNI(OP_EOF);
5897
5898         case KEY_err:
5899             OPERATOR(DOROP);
5900
5901         case KEY_exp:
5902             UNI(OP_EXP);
5903
5904         case KEY_each:
5905             UNI(OP_EACH);
5906
5907         case KEY_exec:
5908             set_csh();
5909             LOP(OP_EXEC,XREF);
5910
5911         case KEY_endhostent:
5912             FUN0(OP_EHOSTENT);
5913
5914         case KEY_endnetent:
5915             FUN0(OP_ENETENT);
5916
5917         case KEY_endservent:
5918             FUN0(OP_ESERVENT);
5919
5920         case KEY_endprotoent:
5921             FUN0(OP_EPROTOENT);
5922
5923         case KEY_endpwent:
5924             FUN0(OP_EPWENT);
5925
5926         case KEY_endgrent:
5927             FUN0(OP_EGRENT);
5928
5929         case KEY_for:
5930         case KEY_foreach:
5931             yylval.ival = CopLINE(PL_curcop);
5932             s = SKIPSPACE1(s);
5933             if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
5934                 char *p = s;
5935 #ifdef PERL_MAD
5936                 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
5937 #endif
5938
5939                 if ((PL_bufend - p) >= 3 &&
5940                     strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
5941                     p += 2;
5942                 else if ((PL_bufend - p) >= 4 &&
5943                     strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
5944                     p += 3;
5945                 p = PEEKSPACE(p);
5946                 if (isIDFIRST_lazy_if(p,UTF)) {
5947                     p = scan_ident(p, PL_bufend,
5948                         PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5949                     p = PEEKSPACE(p);
5950                 }
5951                 if (*p != '$')
5952                     Perl_croak(aTHX_ "Missing $ on loop variable");
5953 #ifdef PERL_MAD
5954                 s = SvPVX(PL_linestr) + soff;
5955 #endif
5956             }
5957             OPERATOR(FOR);
5958
5959         case KEY_formline:
5960             LOP(OP_FORMLINE,XTERM);
5961
5962         case KEY_fork:
5963             FUN0(OP_FORK);
5964
5965         case KEY_fcntl:
5966             LOP(OP_FCNTL,XTERM);
5967
5968         case KEY_fileno:
5969             UNI(OP_FILENO);
5970
5971         case KEY_flock:
5972             LOP(OP_FLOCK,XTERM);
5973
5974         case KEY_gt:
5975             Rop(OP_SGT);
5976
5977         case KEY_ge:
5978             Rop(OP_SGE);
5979
5980         case KEY_grep:
5981             LOP(OP_GREPSTART, XREF);
5982
5983         case KEY_goto:
5984             s = force_word(s,WORD,TRUE,FALSE,FALSE);
5985             LOOPX(OP_GOTO);
5986
5987         case KEY_gmtime:
5988             UNI(OP_GMTIME);
5989
5990         case KEY_getc:
5991             UNIDOR(OP_GETC);
5992
5993         case KEY_getppid:
5994             FUN0(OP_GETPPID);
5995
5996         case KEY_getpgrp:
5997             UNI(OP_GETPGRP);
5998
5999         case KEY_getpriority:
6000             LOP(OP_GETPRIORITY,XTERM);
6001
6002         case KEY_getprotobyname:
6003             UNI(OP_GPBYNAME);
6004
6005         case KEY_getprotobynumber:
6006             LOP(OP_GPBYNUMBER,XTERM);
6007
6008         case KEY_getprotoent:
6009             FUN0(OP_GPROTOENT);
6010
6011         case KEY_getpwent:
6012             FUN0(OP_GPWENT);
6013
6014         case KEY_getpwnam:
6015             UNI(OP_GPWNAM);
6016
6017         case KEY_getpwuid:
6018             UNI(OP_GPWUID);
6019
6020         case KEY_getpeername:
6021             UNI(OP_GETPEERNAME);
6022
6023         case KEY_gethostbyname:
6024             UNI(OP_GHBYNAME);
6025
6026         case KEY_gethostbyaddr:
6027             LOP(OP_GHBYADDR,XTERM);
6028
6029         case KEY_gethostent:
6030             FUN0(OP_GHOSTENT);
6031
6032         case KEY_getnetbyname:
6033             UNI(OP_GNBYNAME);
6034
6035         case KEY_getnetbyaddr:
6036             LOP(OP_GNBYADDR,XTERM);
6037
6038         case KEY_getnetent:
6039             FUN0(OP_GNETENT);
6040
6041         case KEY_getservbyname:
6042             LOP(OP_GSBYNAME,XTERM);
6043
6044         case KEY_getservbyport:
6045             LOP(OP_GSBYPORT,XTERM);
6046
6047         case KEY_getservent:
6048             FUN0(OP_GSERVENT);
6049
6050         case KEY_getsockname:
6051             UNI(OP_GETSOCKNAME);
6052
6053         case KEY_getsockopt:
6054             LOP(OP_GSOCKOPT,XTERM);
6055
6056         case KEY_getgrent:
6057             FUN0(OP_GGRENT);
6058
6059         case KEY_getgrnam:
6060             UNI(OP_GGRNAM);
6061
6062         case KEY_getgrgid:
6063             UNI(OP_GGRGID);
6064
6065         case KEY_getlogin:
6066             FUN0(OP_GETLOGIN);
6067
6068         case KEY_given:
6069             yylval.ival = CopLINE(PL_curcop);
6070             OPERATOR(GIVEN);
6071
6072         case KEY_glob:
6073             set_csh();
6074             LOP(OP_GLOB,XTERM);
6075
6076         case KEY_hex:
6077             UNI(OP_HEX);
6078
6079         case KEY_if:
6080             yylval.ival = CopLINE(PL_curcop);
6081             OPERATOR(IF);
6082
6083         case KEY_index:
6084             LOP(OP_INDEX,XTERM);
6085
6086         case KEY_int:
6087             UNI(OP_INT);
6088
6089         case KEY_ioctl:
6090             LOP(OP_IOCTL,XTERM);
6091
6092         case KEY_join:
6093             LOP(OP_JOIN,XTERM);
6094
6095         case KEY_keys:
6096             UNI(OP_KEYS);
6097
6098         case KEY_kill:
6099             LOP(OP_KILL,XTERM);
6100
6101         case KEY_last:
6102             s = force_word(s,WORD,TRUE,FALSE,FALSE);
6103             LOOPX(OP_LAST);
6104         
6105         case KEY_lc:
6106             UNI(OP_LC);
6107
6108         case KEY_lcfirst:
6109             UNI(OP_LCFIRST);
6110
6111         case KEY_local:
6112             yylval.ival = 0;
6113             OPERATOR(LOCAL);
6114
6115         case KEY_length:
6116             UNI(OP_LENGTH);
6117
6118         case KEY_lt:
6119             Rop(OP_SLT);
6120
6121         case KEY_le:
6122             Rop(OP_SLE);
6123
6124         case KEY_localtime:
6125             UNI(OP_LOCALTIME);
6126
6127         case KEY_log:
6128             UNI(OP_LOG);
6129
6130         case KEY_link:
6131             LOP(OP_LINK,XTERM);
6132
6133         case KEY_listen:
6134             LOP(OP_LISTEN,XTERM);
6135
6136         case KEY_lock:
6137             UNI(OP_LOCK);
6138
6139         case KEY_lstat:
6140             UNI(OP_LSTAT);
6141
6142         case KEY_m:
6143             s = scan_pat(s,OP_MATCH);
6144             TERM(sublex_start());
6145
6146         case KEY_map:
6147             LOP(OP_MAPSTART, XREF);
6148
6149         case KEY_mkdir:
6150             LOP(OP_MKDIR,XTERM);
6151
6152         case KEY_msgctl:
6153             LOP(OP_MSGCTL,XTERM);
6154
6155         case KEY_msgget:
6156             LOP(OP_MSGGET,XTERM);
6157
6158         case KEY_msgrcv:
6159             LOP(OP_MSGRCV,XTERM);
6160
6161         case KEY_msgsnd:
6162             LOP(OP_MSGSND,XTERM);
6163
6164         case KEY_our:
6165         case KEY_my:
6166         case KEY_state:
6167             PL_in_my = tmp;
6168             s = SKIPSPACE1(s);
6169             if (isIDFIRST_lazy_if(s,UTF)) {
6170 #ifdef PERL_MAD
6171                 char* start = s;
6172 #endif
6173                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
6174                 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6175                     goto really_sub;
6176                 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
6177                 if (!PL_in_my_stash) {
6178                     char tmpbuf[1024];
6179                     PL_bufptr = s;
6180                     my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
6181                     yyerror(tmpbuf);
6182                 }
6183 #ifdef PERL_MAD
6184                 if (PL_madskills) {     /* just add type to declarator token */
6185                     sv_catsv(PL_thistoken, PL_nextwhite);
6186                     PL_nextwhite = 0;
6187                     sv_catpvn(PL_thistoken, start, s - start);
6188                 }
6189 #endif
6190             }
6191             yylval.ival = 1;
6192             OPERATOR(MY);
6193
6194         case KEY_next:
6195             s = force_word(s,WORD,TRUE,FALSE,FALSE);
6196             LOOPX(OP_NEXT);
6197
6198         case KEY_ne:
6199             Eop(OP_SNE);
6200
6201         case KEY_no:
6202             s = tokenize_use(0, s);
6203             OPERATOR(USE);
6204
6205         case KEY_not:
6206             if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
6207                 FUN1(OP_NOT);
6208             else
6209                 OPERATOR(NOTOP);
6210
6211         case KEY_open:
6212             s = SKIPSPACE1(s);
6213             if (isIDFIRST_lazy_if(s,UTF)) {
6214                 const char *t;
6215                 for (d = s; isALNUM_lazy_if(d,UTF);)
6216                     d++;
6217                 for (t=d; isSPACE(*t);)
6218                     t++;
6219                 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
6220                     /* [perl #16184] */
6221                     && !(t[0] == '=' && t[1] == '>')
6222                 ) {
6223                     int parms_len = (int)(d-s);
6224                     Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
6225                            "Precedence problem: open %.*s should be open(%.*s)",
6226                             parms_len, s, parms_len, s);
6227                 }
6228             }
6229             LOP(OP_OPEN,XTERM);
6230
6231         case KEY_or:
6232             yylval.ival = OP_OR;
6233             OPERATOR(OROP);
6234
6235         case KEY_ord:
6236             UNI(OP_ORD);
6237
6238         case KEY_oct:
6239             UNI(OP_OCT);
6240
6241         case KEY_opendir:
6242             LOP(OP_OPEN_DIR,XTERM);
6243
6244         case KEY_print:
6245             checkcomma(s,PL_tokenbuf,"filehandle");
6246             LOP(OP_PRINT,XREF);
6247
6248         case KEY_printf:
6249             checkcomma(s,PL_tokenbuf,"filehandle");
6250             LOP(OP_PRTF,XREF);
6251
6252         case KEY_prototype:
6253             UNI(OP_PROTOTYPE);
6254
6255         case KEY_push:
6256             LOP(OP_PUSH,XTERM);
6257
6258         case KEY_pop:
6259             UNIDOR(OP_POP);
6260
6261         case KEY_pos:
6262             UNIDOR(OP_POS);
6263         
6264         case KEY_pack:
6265             LOP(OP_PACK,XTERM);
6266
6267         case KEY_package:
6268             s = force_word(s,WORD,FALSE,TRUE,FALSE);
6269             OPERATOR(PACKAGE);
6270
6271         case KEY_pipe:
6272             LOP(OP_PIPE_OP,XTERM);
6273
6274         case KEY_q:
6275             s = scan_str(s,!!PL_madskills,FALSE);
6276             if (!s)
6277                 missingterm(NULL);
6278             yylval.ival = OP_CONST;
6279             TERM(sublex_start());
6280
6281         case KEY_quotemeta:
6282             UNI(OP_QUOTEMETA);
6283
6284         case KEY_qw:
6285             s = scan_str(s,!!PL_madskills,FALSE);
6286             if (!s)
6287                 missingterm(NULL);
6288             PL_expect = XOPERATOR;
6289             force_next(')');
6290             if (SvCUR(PL_lex_stuff)) {
6291                 OP *words = NULL;
6292                 int warned = 0;
6293                 d = SvPV_force(PL_lex_stuff, len);
6294                 while (len) {
6295                     for (; isSPACE(*d) && len; --len, ++d)
6296                         /**/;
6297                     if (len) {
6298                         SV *sv;
6299                         const char *b = d;
6300                         if (!warned && ckWARN(WARN_QW)) {
6301                             for (; !isSPACE(*d) && len; --len, ++d) {
6302                                 if (*d == ',') {
6303                                     Perl_warner(aTHX_ packWARN(WARN_QW),
6304                                         "Possible attempt to separate words with commas");
6305                                     ++warned;
6306                                 }
6307                                 else if (*d == '#') {
6308                                     Perl_warner(aTHX_ packWARN(WARN_QW),
6309                                         "Possible attempt to put comments in qw() list");
6310                                     ++warned;
6311                                 }
6312                             }
6313                         }
6314                         else {
6315                             for (; !isSPACE(*d) && len; --len, ++d)
6316                                 /**/;
6317                         }
6318                         sv = newSVpvn(b, d-b);
6319                         if (DO_UTF8(PL_lex_stuff))
6320                             SvUTF8_on(sv);
6321                         words = append_elem(OP_LIST, words,
6322                                             newSVOP(OP_CONST, 0, tokeq(sv)));
6323                     }
6324                 }
6325                 if (words) {
6326                     start_force(PL_curforce);
6327                     NEXTVAL_NEXTTOKE.opval = words;
6328                     force_next(THING);
6329                 }
6330             }
6331             if (PL_lex_stuff) {
6332                 SvREFCNT_dec(PL_lex_stuff);
6333                 PL_lex_stuff = NULL;
6334             }
6335             PL_expect = XTERM;
6336             TOKEN('(');
6337
6338         case KEY_qq:
6339             s = scan_str(s,!!PL_madskills,FALSE);
6340             if (!s)
6341                 missingterm(NULL);
6342             yylval.ival = OP_STRINGIFY;
6343             if (SvIVX(PL_lex_stuff) == '\'')
6344                 SvIV_set(PL_lex_stuff, 0);      /* qq'$foo' should intepolate */
6345             TERM(sublex_start());
6346
6347         case KEY_qr:
6348             s = scan_pat(s,OP_QR);
6349             TERM(sublex_start());
6350
6351         case KEY_qx:
6352             s = scan_str(s,!!PL_madskills,FALSE);
6353             if (!s)
6354                 missingterm(NULL);
6355             readpipe_override();
6356             TERM(sublex_start());
6357
6358         case KEY_return:
6359             OLDLOP(OP_RETURN);
6360
6361         case KEY_require:
6362             s = SKIPSPACE1(s);
6363             if (isDIGIT(*s)) {
6364                 s = force_version(s, FALSE);
6365             }
6366             else if (*s != 'v' || !isDIGIT(s[1])
6367                     || (s = force_version(s, TRUE), *s == 'v'))
6368             {
6369                 *PL_tokenbuf = '\0';
6370                 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6371                 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
6372                     gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
6373                 else if (*s == '<')
6374                     yyerror("<> should be quotes");
6375             }
6376             if (orig_keyword == KEY_require) {
6377                 orig_keyword = 0;
6378                 yylval.ival = 1;
6379             }
6380             else 
6381                 yylval.ival = 0;
6382             PL_expect = XTERM;
6383             PL_bufptr = s;
6384             PL_last_uni = PL_oldbufptr;
6385             PL_last_lop_op = OP_REQUIRE;
6386             s = skipspace(s);
6387             return REPORT( (int)REQUIRE );
6388
6389         case KEY_reset:
6390             UNI(OP_RESET);
6391
6392         case KEY_redo:
6393             s = force_word(s,WORD,TRUE,FALSE,FALSE);
6394             LOOPX(OP_REDO);
6395
6396         case KEY_rename:
6397             LOP(OP_RENAME,XTERM);
6398
6399         case KEY_rand:
6400             UNI(OP_RAND);
6401
6402         case KEY_rmdir:
6403             UNI(OP_RMDIR);
6404
6405         case KEY_rindex:
6406             LOP(OP_RINDEX,XTERM);
6407
6408         case KEY_read:
6409             LOP(OP_READ,XTERM);
6410
6411         case KEY_readdir:
6412             UNI(OP_READDIR);
6413
6414         case KEY_readline:
6415             set_csh();
6416             UNIDOR(OP_READLINE);
6417
6418         case KEY_readpipe:
6419             set_csh();
6420             UNI(OP_BACKTICK);
6421
6422         case KEY_rewinddir:
6423             UNI(OP_REWINDDIR);
6424
6425         case KEY_recv:
6426             LOP(OP_RECV,XTERM);
6427
6428         case KEY_reverse:
6429             LOP(OP_REVERSE,XTERM);
6430
6431         case KEY_readlink:
6432             UNIDOR(OP_READLINK);
6433
6434         case KEY_ref:
6435             UNI(OP_REF);
6436
6437         case KEY_s:
6438             s = scan_subst(s);
6439             if (yylval.opval)
6440                 TERM(sublex_start());
6441             else
6442                 TOKEN(1);       /* force error */
6443
6444         case KEY_say:
6445             checkcomma(s,PL_tokenbuf,"filehandle");
6446             LOP(OP_SAY,XREF);
6447
6448         case KEY_chomp:
6449             UNI(OP_CHOMP);
6450         
6451         case KEY_scalar:
6452             UNI(OP_SCALAR);
6453
6454         case KEY_select:
6455             LOP(OP_SELECT,XTERM);
6456
6457         case KEY_seek:
6458             LOP(OP_SEEK,XTERM);
6459
6460         case KEY_semctl:
6461             LOP(OP_SEMCTL,XTERM);
6462
6463         case KEY_semget:
6464             LOP(OP_SEMGET,XTERM);
6465
6466         case KEY_semop:
6467             LOP(OP_SEMOP,XTERM);
6468
6469         case KEY_send:
6470             LOP(OP_SEND,XTERM);
6471
6472         case KEY_setpgrp:
6473             LOP(OP_SETPGRP,XTERM);
6474
6475         case KEY_setpriority:
6476             LOP(OP_SETPRIORITY,XTERM);
6477
6478         case KEY_sethostent:
6479             UNI(OP_SHOSTENT);
6480
6481         case KEY_setnetent:
6482             UNI(OP_SNETENT);
6483
6484         case KEY_setservent:
6485             UNI(OP_SSERVENT);
6486
6487         case KEY_setprotoent:
6488             UNI(OP_SPROTOENT);
6489
6490         case KEY_setpwent:
6491             FUN0(OP_SPWENT);
6492
6493         case KEY_setgrent:
6494             FUN0(OP_SGRENT);
6495
6496         case KEY_seekdir:
6497             LOP(OP_SEEKDIR,XTERM);
6498
6499         case KEY_setsockopt:
6500             LOP(OP_SSOCKOPT,XTERM);
6501
6502         case KEY_shift:
6503             UNIDOR(OP_SHIFT);
6504
6505         case KEY_shmctl:
6506             LOP(OP_SHMCTL,XTERM);
6507
6508         case KEY_shmget:
6509             LOP(OP_SHMGET,XTERM);
6510
6511         case KEY_shmread:
6512             LOP(OP_SHMREAD,XTERM);
6513
6514         case KEY_shmwrite:
6515             LOP(OP_SHMWRITE,XTERM);
6516
6517         case KEY_shutdown:
6518             LOP(OP_SHUTDOWN,XTERM);
6519
6520         case KEY_sin:
6521             UNI(OP_SIN);
6522
6523         case KEY_sleep:
6524             UNI(OP_SLEEP);
6525
6526         case KEY_socket:
6527             LOP(OP_SOCKET,XTERM);
6528
6529         case KEY_socketpair:
6530             LOP(OP_SOCKPAIR,XTERM);
6531
6532         case KEY_sort:
6533             checkcomma(s,PL_tokenbuf,"subroutine name");
6534             s = SKIPSPACE1(s);
6535             if (*s == ';' || *s == ')')         /* probably a close */
6536                 Perl_croak(aTHX_ "sort is now a reserved word");
6537             PL_expect = XTERM;
6538             s = force_word(s,WORD,TRUE,TRUE,FALSE);
6539             LOP(OP_SORT,XREF);
6540
6541         case KEY_split:
6542             LOP(OP_SPLIT,XTERM);
6543
6544         case KEY_sprintf:
6545             LOP(OP_SPRINTF,XTERM);
6546
6547         case KEY_splice:
6548             LOP(OP_SPLICE,XTERM);
6549
6550         case KEY_sqrt:
6551             UNI(OP_SQRT);
6552
6553         case KEY_srand:
6554             UNI(OP_SRAND);
6555
6556         case KEY_stat:
6557             UNI(OP_STAT);
6558
6559         case KEY_study:
6560             UNI(OP_STUDY);
6561
6562         case KEY_substr:
6563             LOP(OP_SUBSTR,XTERM);
6564
6565         case KEY_format:
6566         case KEY_sub:
6567           really_sub:
6568             {
6569                 char tmpbuf[sizeof PL_tokenbuf];
6570                 SSize_t tboffset = 0;
6571                 expectation attrful;
6572                 bool have_name, have_proto;
6573                 const int key = tmp;
6574
6575 #ifdef PERL_MAD
6576                 SV *tmpwhite = 0;
6577
6578                 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6579                 SV *subtoken = newSVpvn(tstart, s - tstart);
6580                 PL_thistoken = 0;
6581
6582                 d = s;
6583                 s = SKIPSPACE2(s,tmpwhite);
6584 #else
6585                 s = skipspace(s);
6586 #endif
6587
6588                 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
6589                     (*s == ':' && s[1] == ':'))
6590                 {
6591 #ifdef PERL_MAD
6592                     SV *nametoke;
6593 #endif
6594
6595                     PL_expect = XBLOCK;
6596                     attrful = XATTRBLOCK;
6597                     /* remember buffer pos'n for later force_word */
6598                     tboffset = s - PL_oldbufptr;
6599                     d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
6600 #ifdef PERL_MAD
6601                     if (PL_madskills)
6602                         nametoke = newSVpvn(s, d - s);
6603 #endif
6604                     if (memchr(tmpbuf, ':', len))
6605                         sv_setpvn(PL_subname, tmpbuf, len);
6606                     else {
6607                         sv_setsv(PL_subname,PL_curstname);
6608                         sv_catpvs(PL_subname,"::");
6609                         sv_catpvn(PL_subname,tmpbuf,len);
6610                     }
6611                     have_name = TRUE;
6612
6613 #ifdef PERL_MAD
6614
6615                     start_force(0);
6616                     CURMAD('X', nametoke);
6617                     CURMAD('_', tmpwhite);
6618                     (void) force_word(PL_oldbufptr + tboffset, WORD,
6619                                       FALSE, TRUE, TRUE);
6620
6621                     s = SKIPSPACE2(d,tmpwhite);
6622 #else
6623                     s = skipspace(d);
6624 #endif
6625                 }
6626                 else {
6627                     if (key == KEY_my)
6628                         Perl_croak(aTHX_ "Missing name in \"my sub\"");
6629                     PL_expect = XTERMBLOCK;
6630                     attrful = XATTRTERM;
6631                     sv_setpvn(PL_subname,"?",1);
6632                     have_name = FALSE;
6633                 }
6634
6635                 if (key == KEY_format) {
6636                     if (*s == '=')
6637                         PL_lex_formbrack = PL_lex_brackets + 1;
6638 #ifdef PERL_MAD
6639                     PL_thistoken = subtoken;
6640                     s = d;
6641 #else
6642                     if (have_name)
6643                         (void) force_word(PL_oldbufptr + tboffset, WORD,
6644                                           FALSE, TRUE, TRUE);
6645 #endif
6646                     OPERATOR(FORMAT);
6647                 }
6648
6649                 /* Look for a prototype */
6650                 if (*s == '(') {
6651                     char *p;
6652                     bool bad_proto = FALSE;
6653                     const bool warnsyntax = ckWARN(WARN_SYNTAX);
6654
6655                     s = scan_str(s,!!PL_madskills,FALSE);
6656                     if (!s)
6657                         Perl_croak(aTHX_ "Prototype not terminated");
6658                     /* strip spaces and check for bad characters */
6659                     d = SvPVX(PL_lex_stuff);
6660                     tmp = 0;
6661                     for (p = d; *p; ++p) {
6662                         if (!isSPACE(*p)) {
6663                             d[tmp++] = *p;
6664                             if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
6665                                 bad_proto = TRUE;
6666                         }
6667                     }
6668                     d[tmp] = '\0';
6669                     if (bad_proto)
6670                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6671                                     "Illegal character in prototype for %"SVf" : %s",
6672                                     SVfARG(PL_subname), d);
6673                     SvCUR_set(PL_lex_stuff, tmp);
6674                     have_proto = TRUE;
6675
6676 #ifdef PERL_MAD
6677                     start_force(0);
6678                     CURMAD('q', PL_thisopen);
6679                     CURMAD('_', tmpwhite);
6680                     CURMAD('=', PL_thisstuff);
6681                     CURMAD('Q', PL_thisclose);
6682                     NEXTVAL_NEXTTOKE.opval =
6683                         (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6684                     PL_lex_stuff = Nullsv;
6685                     force_next(THING);
6686
6687                     s = SKIPSPACE2(s,tmpwhite);
6688 #else
6689                     s = skipspace(s);
6690 #endif
6691                 }
6692                 else
6693                     have_proto = FALSE;
6694
6695                 if (*s == ':' && s[1] != ':')
6696                     PL_expect = attrful;
6697                 else if (*s != '{' && key == KEY_sub) {
6698                     if (!have_name)
6699                         Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6700                     else if (*s != ';')
6701                         Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
6702                 }
6703
6704 #ifdef PERL_MAD
6705                 start_force(0);
6706                 if (tmpwhite) {
6707                     if (PL_madskills)
6708                         curmad('^', newSVpvs(""));
6709                     CURMAD('_', tmpwhite);
6710                 }
6711                 force_next(0);
6712
6713                 PL_thistoken = subtoken;
6714 #else
6715                 if (have_proto) {
6716                     NEXTVAL_NEXTTOKE.opval =
6717                         (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
6718                     PL_lex_stuff = NULL;
6719                     force_next(THING);
6720                 }
6721 #endif
6722                 if (!have_name) {
6723                     sv_setpv(PL_subname,
6724                              (const char *)
6725                              (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"));
6726                     TOKEN(ANONSUB);
6727                 }
6728 #ifndef PERL_MAD
6729                 (void) force_word(PL_oldbufptr + tboffset, WORD,
6730                                   FALSE, TRUE, TRUE);
6731 #endif
6732                 if (key == KEY_my)
6733                     TOKEN(MYSUB);
6734                 TOKEN(SUB);
6735             }
6736
6737         case KEY_system:
6738             set_csh();
6739             LOP(OP_SYSTEM,XREF);
6740
6741         case KEY_symlink:
6742             LOP(OP_SYMLINK,XTERM);
6743
6744         case KEY_syscall:
6745             LOP(OP_SYSCALL,XTERM);
6746
6747         case KEY_sysopen:
6748             LOP(OP_SYSOPEN,XTERM);
6749
6750         case KEY_sysseek:
6751             LOP(OP_SYSSEEK,XTERM);
6752
6753         case KEY_sysread:
6754             LOP(OP_SYSREAD,XTERM);
6755
6756         case KEY_syswrite:
6757             LOP(OP_SYSWRITE,XTERM);
6758
6759         case KEY_tr:
6760             s = scan_trans(s);
6761             TERM(sublex_start());
6762
6763         case KEY_tell:
6764             UNI(OP_TELL);
6765
6766         case KEY_telldir:
6767             UNI(OP_TELLDIR);
6768
6769         case KEY_tie:
6770             LOP(OP_TIE,XTERM);
6771
6772         case KEY_tied:
6773             UNI(OP_TIED);
6774
6775         case KEY_time:
6776             FUN0(OP_TIME);
6777
6778         case KEY_times:
6779             FUN0(OP_TMS);
6780
6781         case KEY_truncate:
6782             LOP(OP_TRUNCATE,XTERM);
6783
6784         case KEY_uc:
6785             UNI(OP_UC);
6786
6787         case KEY_ucfirst:
6788             UNI(OP_UCFIRST);
6789
6790         case KEY_untie:
6791             UNI(OP_UNTIE);
6792
6793         case KEY_until:
6794             yylval.ival = CopLINE(PL_curcop);
6795             OPERATOR(UNTIL);
6796
6797         case KEY_unless:
6798             yylval.ival = CopLINE(PL_curcop);
6799             OPERATOR(UNLESS);
6800
6801         case KEY_unlink:
6802             LOP(OP_UNLINK,XTERM);
6803
6804         case KEY_undef:
6805             UNIDOR(OP_UNDEF);
6806
6807         case KEY_unpack:
6808             LOP(OP_UNPACK,XTERM);
6809
6810         case KEY_utime:
6811             LOP(OP_UTIME,XTERM);
6812
6813         case KEY_umask:
6814             UNIDOR(OP_UMASK);
6815
6816         case KEY_unshift:
6817             LOP(OP_UNSHIFT,XTERM);
6818
6819         case KEY_use:
6820             s = tokenize_use(1, s);
6821             OPERATOR(USE);
6822
6823         case KEY_values:
6824             UNI(OP_VALUES);
6825
6826         case KEY_vec:
6827             LOP(OP_VEC,XTERM);
6828
6829         case KEY_when:
6830             yylval.ival = CopLINE(PL_curcop);
6831             OPERATOR(WHEN);
6832
6833         case KEY_while:
6834             yylval.ival = CopLINE(PL_curcop);
6835             OPERATOR(WHILE);
6836
6837         case KEY_warn:
6838             PL_hints |= HINT_BLOCK_SCOPE;
6839             LOP(OP_WARN,XTERM);
6840
6841         case KEY_wait:
6842             FUN0(OP_WAIT);
6843
6844         case KEY_waitpid:
6845             LOP(OP_WAITPID,XTERM);
6846
6847         case KEY_wantarray:
6848             FUN0(OP_WANTARRAY);
6849
6850         case KEY_write:
6851 #ifdef EBCDIC
6852         {
6853             char ctl_l[2];
6854             ctl_l[0] = toCTRL('L');
6855             ctl_l[1] = '\0';
6856             gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
6857         }
6858 #else
6859             /* Make sure $^L is defined */
6860             gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
6861 #endif
6862             UNI(OP_ENTERWRITE);
6863
6864         case KEY_x:
6865             if (PL_expect == XOPERATOR)
6866                 Mop(OP_REPEAT);
6867             check_uni();
6868             goto just_a_word;
6869
6870         case KEY_xor:
6871             yylval.ival = OP_XOR;
6872             OPERATOR(OROP);
6873
6874         case KEY_y:
6875             s = scan_trans(s);
6876             TERM(sublex_start());
6877         }
6878     }}
6879 }
6880 #ifdef __SC__
6881 #pragma segment Main
6882 #endif
6883
6884 static int
6885 S_pending_ident(pTHX)
6886 {
6887     dVAR;
6888     register char *d;
6889     PADOFFSET tmp = 0;
6890     /* pit holds the identifier we read and pending_ident is reset */
6891     char pit = PL_pending_ident;
6892     PL_pending_ident = 0;
6893
6894     /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
6895     DEBUG_T({ PerlIO_printf(Perl_debug_log,
6896           "### Pending identifier '%s'\n", PL_tokenbuf); });
6897
6898     /* if we're in a my(), we can't allow dynamics here.
6899        $foo'bar has already been turned into $foo::bar, so
6900        just check for colons.
6901
6902        if it's a legal name, the OP is a PADANY.
6903     */
6904     if (PL_in_my) {
6905         if (PL_in_my == KEY_our) {      /* "our" is merely analogous to "my" */
6906             if (strchr(PL_tokenbuf,':'))
6907                 yyerror(Perl_form(aTHX_ "No package name allowed for "
6908                                   "variable %s in \"our\"",
6909                                   PL_tokenbuf));
6910             tmp = allocmy(PL_tokenbuf);
6911         }
6912         else {
6913             if (strchr(PL_tokenbuf,':'))
6914                 yyerror(Perl_form(aTHX_ PL_no_myglob,
6915                             PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
6916
6917             yylval.opval = newOP(OP_PADANY, 0);
6918             yylval.opval->op_targ = allocmy(PL_tokenbuf);
6919             return PRIVATEREF;
6920         }
6921     }
6922
6923     /*
6924        build the ops for accesses to a my() variable.
6925
6926        Deny my($a) or my($b) in a sort block, *if* $a or $b is
6927        then used in a comparison.  This catches most, but not
6928        all cases.  For instance, it catches
6929            sort { my($a); $a <=> $b }
6930        but not
6931            sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
6932        (although why you'd do that is anyone's guess).
6933     */
6934
6935     if (!strchr(PL_tokenbuf,':')) {
6936         if (!PL_in_my)
6937             tmp = pad_findmy(PL_tokenbuf);
6938         if (tmp != NOT_IN_PAD) {
6939             /* might be an "our" variable" */
6940             if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6941                 /* build ops for a bareword */
6942                 HV *  const stash = PAD_COMPNAME_OURSTASH(tmp);
6943                 HEK * const stashname = HvNAME_HEK(stash);
6944                 SV *  const sym = newSVhek(stashname);
6945                 sv_catpvs(sym, "::");
6946                 sv_catpv(sym, PL_tokenbuf+1);
6947                 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
6948                 yylval.opval->op_private = OPpCONST_ENTERED;
6949                 gv_fetchsv(sym,
6950                     (PL_in_eval
6951                         ? (GV_ADDMULTI | GV_ADDINEVAL)
6952                         : GV_ADDMULTI
6953                     ),
6954                     ((PL_tokenbuf[0] == '$') ? SVt_PV
6955                      : (PL_tokenbuf[0] == '@') ? SVt_PVAV
6956                      : SVt_PVHV));
6957                 return WORD;
6958             }
6959
6960             /* if it's a sort block and they're naming $a or $b */
6961             if (PL_last_lop_op == OP_SORT &&
6962                 PL_tokenbuf[0] == '$' &&
6963                 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
6964                 && !PL_tokenbuf[2])
6965             {
6966                 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
6967                      d < PL_bufend && *d != '\n';
6968                      d++)
6969                 {
6970                     if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
6971                         Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
6972                               PL_tokenbuf);
6973                     }
6974                 }
6975             }
6976
6977             yylval.opval = newOP(OP_PADANY, 0);
6978             yylval.opval->op_targ = tmp;
6979             return PRIVATEREF;
6980         }
6981     }
6982
6983     /*
6984        Whine if they've said @foo in a doublequoted string,
6985        and @foo isn't a variable we can find in the symbol
6986        table.
6987     */
6988     if (pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
6989         GV *gv = gv_fetchpv(PL_tokenbuf+1, 0, SVt_PVAV);
6990         if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
6991                 && ckWARN(WARN_AMBIGUOUS)
6992                 /* DO NOT warn for @- and @+ */
6993                 && !( PL_tokenbuf[2] == '\0' &&
6994                     ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
6995            )
6996         {
6997             /* Downgraded from fatal to warning 20000522 mjd */
6998             Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6999                         "Possible unintended interpolation of %s in string",
7000                          PL_tokenbuf);
7001         }
7002     }
7003
7004     /* build ops for a bareword */
7005     yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
7006     yylval.opval->op_private = OPpCONST_ENTERED;
7007     gv_fetchpv(
7008             PL_tokenbuf+1,
7009             /* If the identifier refers to a stash, don't autovivify it.
7010              * Change 24660 had the side effect of causing symbol table
7011              * hashes to always be defined, even if they were freshly
7012              * created and the only reference in the entire program was
7013              * the single statement with the defined %foo::bar:: test.
7014              * It appears that all code in the wild doing this actually
7015              * wants to know whether sub-packages have been loaded, so
7016              * by avoiding auto-vivifying symbol tables, we ensure that
7017              * defined %foo::bar:: continues to be false, and the existing
7018              * tests still give the expected answers, even though what
7019              * they're actually testing has now changed subtly.
7020              */
7021             (*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'
7022              ? 0
7023              : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
7024             ((PL_tokenbuf[0] == '$') ? SVt_PV
7025              : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7026              : SVt_PVHV));
7027     return WORD;
7028 }
7029
7030 /*
7031  *  The following code was generated by perl_keyword.pl.
7032  */
7033
7034 I32
7035 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
7036 {
7037     dVAR;
7038   switch (len)
7039   {
7040     case 1: /* 5 tokens of length 1 */
7041       switch (name[0])
7042       {
7043         case 'm':
7044           {                                       /* m          */
7045             return KEY_m;
7046           }
7047
7048         case 'q':
7049           {                                       /* q          */
7050             return KEY_q;
7051           }
7052
7053         case 's':
7054           {                                       /* s          */
7055             return KEY_s;
7056           }
7057
7058         case 'x':
7059           {                                       /* x          */
7060             return -KEY_x;
7061           }
7062
7063         case 'y':
7064           {                                       /* y          */
7065             return KEY_y;
7066           }
7067
7068         default:
7069           goto unknown;
7070       }
7071
7072     case 2: /* 18 tokens of length 2 */
7073       switch (name[0])
7074       {
7075         case 'd':
7076           if (name[1] == 'o')
7077           {                                       /* do         */
7078             return KEY_do;
7079           }
7080
7081           goto unknown;
7082
7083         case 'e':
7084           if (name[1] == 'q')
7085           {                                       /* eq         */
7086             return -KEY_eq;
7087           }
7088
7089           goto unknown;
7090
7091         case 'g':
7092           switch (name[1])
7093           {
7094             case 'e':
7095               {                                   /* ge         */
7096                 return -KEY_ge;
7097               }
7098
7099             case 't':
7100               {                                   /* gt         */
7101                 return -KEY_gt;
7102               }
7103
7104             default:
7105               goto unknown;
7106           }
7107
7108         case 'i':
7109           if (name[1] == 'f')
7110           {                                       /* if         */
7111             return KEY_if;
7112           }
7113
7114           goto unknown;
7115
7116         case 'l':
7117           switch (name[1])
7118           {
7119             case 'c':
7120               {                                   /* lc         */
7121                 return -KEY_lc;
7122               }
7123
7124             case 'e':
7125               {                                   /* le         */
7126                 return -KEY_le;
7127               }
7128
7129             case 't':
7130               {                                   /* lt         */
7131                 return -KEY_lt;
7132               }
7133
7134             default:
7135               goto unknown;
7136           }
7137
7138         case 'm':
7139           if (name[1] == 'y')
7140           {                                       /* my         */
7141             return KEY_my;
7142           }
7143
7144           goto unknown;
7145
7146         case 'n':
7147           switch (name[1])
7148           {
7149             case 'e':
7150               {                                   /* ne         */
7151                 return -KEY_ne;
7152               }
7153
7154             case 'o':
7155               {                                   /* no         */
7156                 return KEY_no;
7157               }
7158
7159             default:
7160               goto unknown;
7161           }
7162
7163         case 'o':
7164           if (name[1] == 'r')
7165           {                                       /* or         */
7166             return -KEY_or;
7167           }
7168
7169           goto unknown;
7170
7171         case 'q':
7172           switch (name[1])
7173           {
7174             case 'q':
7175               {                                   /* qq         */
7176                 return KEY_qq;
7177               }
7178
7179             case 'r':
7180               {                                   /* qr         */
7181                 return KEY_qr;
7182               }
7183
7184             case 'w':
7185               {                                   /* qw         */
7186                 return KEY_qw;
7187               }
7188
7189             case 'x':
7190               {                                   /* qx         */
7191                 return KEY_qx;
7192               }
7193
7194             default:
7195               goto unknown;
7196           }
7197
7198         case 't':
7199           if (name[1] == 'r')
7200           {                                       /* tr         */
7201             return KEY_tr;
7202           }
7203
7204           goto unknown;
7205
7206         case 'u':
7207           if (name[1] == 'c')
7208           {                                       /* uc         */
7209             return -KEY_uc;
7210           }
7211
7212           goto unknown;
7213
7214         default:
7215           goto unknown;
7216       }
7217
7218     case 3: /* 29 tokens of length 3 */
7219       switch (name[0])
7220       {
7221         case 'E':
7222           if (name[1] == 'N' &&
7223               name[2] == 'D')
7224           {                                       /* END        */
7225             return KEY_END;
7226           }
7227
7228           goto unknown;
7229
7230         case 'a':
7231           switch (name[1])
7232           {
7233             case 'b':
7234               if (name[2] == 's')
7235               {                                   /* abs        */
7236                 return -KEY_abs;
7237               }
7238
7239               goto unknown;
7240
7241             case 'n':
7242               if (name[2] == 'd')
7243               {                                   /* and        */
7244                 return -KEY_and;
7245               }
7246
7247               goto unknown;
7248
7249             default:
7250               goto unknown;
7251           }
7252
7253         case 'c':
7254           switch (name[1])
7255           {
7256             case 'h':
7257               if (name[2] == 'r')
7258               {                                   /* chr        */
7259                 return -KEY_chr;
7260               }
7261
7262               goto unknown;
7263
7264             case 'm':
7265               if (name[2] == 'p')
7266               {                                   /* cmp        */
7267                 return -KEY_cmp;
7268               }
7269
7270               goto unknown;
7271
7272             case 'o':
7273               if (name[2] == 's')
7274               {                                   /* cos        */
7275                 return -KEY_cos;
7276               }
7277
7278               goto unknown;
7279
7280             default:
7281               goto unknown;
7282           }
7283
7284         case 'd':
7285           if (name[1] == 'i' &&
7286               name[2] == 'e')
7287           {                                       /* die        */
7288             return -KEY_die;
7289           }
7290
7291           goto unknown;
7292
7293         case 'e':
7294           switch (name[1])
7295           {
7296             case 'o':
7297               if (name[2] == 'f')
7298               {                                   /* eof        */
7299                 return -KEY_eof;
7300               }
7301
7302               goto unknown;
7303
7304             case 'r':
7305               if (name[2] == 'r')
7306               {                                   /* err        */
7307                 return (all_keywords || FEATURE_IS_ENABLED("err") ? -KEY_err : 0);
7308               }
7309
7310               goto unknown;
7311
7312             case 'x':
7313               if (name[2] == 'p')
7314               {                                   /* exp        */
7315                 return -KEY_exp;
7316               }
7317
7318               goto unknown;
7319
7320             default:
7321               goto unknown;
7322           }
7323
7324         case 'f':
7325           if (name[1] == 'o' &&
7326               name[2] == 'r')
7327           {                                       /* for        */
7328             return KEY_for;
7329           }
7330
7331           goto unknown;
7332
7333         case 'h':
7334           if (name[1] == 'e' &&
7335               name[2] == 'x')
7336           {                                       /* hex        */
7337             return -KEY_hex;
7338           }
7339
7340           goto unknown;
7341
7342         case 'i':
7343           if (name[1] == 'n' &&
7344               name[2] == 't')
7345           {                                       /* int        */
7346             return -KEY_int;
7347           }
7348
7349           goto unknown;
7350
7351         case 'l':
7352           if (name[1] == 'o' &&
7353               name[2] == 'g')
7354           {                                       /* log        */
7355             return -KEY_log;
7356           }
7357
7358           goto unknown;
7359
7360         case 'm':
7361           if (name[1] == 'a' &&
7362               name[2] == 'p')
7363           {                                       /* map        */
7364             return KEY_map;
7365           }
7366
7367           goto unknown;
7368
7369         case 'n':
7370           if (name[1] == 'o' &&
7371               name[2] == 't')
7372           {                                       /* not        */
7373             return -KEY_not;
7374           }
7375
7376           goto unknown;
7377
7378         case 'o':
7379           switch (name[1])
7380           {
7381             case 'c':
7382               if (name[2] == 't')
7383               {                                   /* oct        */
7384                 return -KEY_oct;
7385               }
7386
7387               goto unknown;
7388
7389             case 'r':
7390               if (name[2] == 'd')
7391               {                                   /* ord        */
7392                 return -KEY_ord;
7393               }
7394
7395               goto unknown;
7396
7397             case 'u':
7398               if (name[2] == 'r')
7399               {                                   /* our        */
7400                 return KEY_our;
7401               }
7402
7403               goto unknown;
7404
7405             default:
7406               goto unknown;
7407           }
7408
7409         case 'p':
7410           if (name[1] == 'o')
7411           {
7412             switch (name[2])
7413             {
7414               case 'p':
7415                 {                                 /* pop        */
7416                   return -KEY_pop;
7417                 }
7418
7419               case 's':
7420                 {                                 /* pos        */
7421                   return KEY_pos;
7422                 }
7423
7424               default:
7425                 goto unknown;
7426             }
7427           }
7428
7429           goto unknown;
7430
7431         case 'r':
7432           if (name[1] == 'e' &&
7433               name[2] == 'f')
7434           {                                       /* ref        */
7435             return -KEY_ref;
7436           }
7437
7438           goto unknown;
7439
7440         case 's':
7441           switch (name[1])
7442           {
7443             case 'a':
7444               if (name[2] == 'y')
7445               {                                   /* say        */
7446                 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
7447               }
7448
7449               goto unknown;
7450
7451             case 'i':
7452               if (name[2] == 'n')
7453               {                                   /* sin        */
7454                 return -KEY_sin;
7455               }
7456
7457               goto unknown;
7458
7459             case 'u':
7460               if (name[2] == 'b')
7461               {                                   /* sub        */
7462                 return KEY_sub;
7463               }
7464
7465               goto unknown;
7466
7467             default:
7468               goto unknown;
7469           }
7470
7471         case 't':
7472           if (name[1] == 'i' &&
7473               name[2] == 'e')
7474           {                                       /* tie        */
7475             return KEY_tie;
7476           }
7477
7478           goto unknown;
7479
7480         case 'u':
7481           if (name[1] == 's' &&
7482               name[2] == 'e')
7483           {                                       /* use        */
7484             return KEY_use;
7485           }
7486
7487           goto unknown;
7488
7489         case 'v':
7490           if (name[1] == 'e' &&
7491               name[2] == 'c')
7492           {                                       /* vec        */
7493             return -KEY_vec;
7494           }
7495
7496           goto unknown;
7497
7498         case 'x':
7499           if (name[1] == 'o' &&
7500               name[2] == 'r')
7501           {                                       /* xor        */
7502             return -KEY_xor;
7503           }
7504
7505           goto unknown;
7506
7507         default:
7508           goto unknown;
7509       }
7510
7511     case 4: /* 41 tokens of length 4 */
7512       switch (name[0])
7513       {
7514         case 'C':
7515           if (name[1] == 'O' &&
7516               name[2] == 'R' &&
7517               name[3] == 'E')
7518           {                                       /* CORE       */
7519             return -KEY_CORE;
7520           }
7521
7522           goto unknown;
7523
7524         case 'I':
7525           if (name[1] == 'N' &&
7526               name[2] == 'I' &&
7527               name[3] == 'T')
7528           {                                       /* INIT       */
7529             return KEY_INIT;
7530           }
7531
7532           goto unknown;
7533
7534         case 'b':
7535           if (name[1] == 'i' &&
7536               name[2] == 'n' &&
7537               name[3] == 'd')
7538           {                                       /* bind       */
7539             return -KEY_bind;
7540           }
7541
7542           goto unknown;
7543
7544         case 'c':
7545           if (name[1] == 'h' &&
7546               name[2] == 'o' &&
7547               name[3] == 'p')
7548           {                                       /* chop       */
7549             return -KEY_chop;
7550           }
7551
7552           goto unknown;
7553
7554         case 'd':
7555           if (name[1] == 'u' &&
7556               name[2] == 'm' &&
7557               name[3] == 'p')
7558           {                                       /* dump       */
7559             return -KEY_dump;
7560           }
7561
7562           goto unknown;
7563
7564         case 'e':
7565           switch (name[1])
7566           {
7567             case 'a':
7568               if (name[2] == 'c' &&
7569                   name[3] == 'h')
7570               {                                   /* each       */
7571                 return -KEY_each;
7572               }
7573
7574               goto unknown;
7575
7576             case 'l':
7577               if (name[2] == 's' &&
7578                   name[3] == 'e')
7579               {                                   /* else       */
7580                 return KEY_else;
7581               }
7582
7583               goto unknown;
7584
7585             case 'v':
7586               if (name[2] == 'a' &&
7587                   name[3] == 'l')
7588               {                                   /* eval       */
7589                 return KEY_eval;
7590               }
7591
7592               goto unknown;
7593
7594             case 'x':
7595               switch (name[2])
7596               {
7597                 case 'e':
7598                   if (name[3] == 'c')
7599                   {                               /* exec       */
7600                     return -KEY_exec;
7601                   }
7602
7603                   goto unknown;
7604
7605                 case 'i':
7606                   if (name[3] == 't')
7607                   {                               /* exit       */
7608                     return -KEY_exit;
7609                   }
7610
7611                   goto unknown;
7612
7613                 default:
7614                   goto unknown;
7615               }
7616
7617             default:
7618               goto unknown;
7619           }
7620
7621         case 'f':
7622           if (name[1] == 'o' &&
7623               name[2] == 'r' &&
7624               name[3] == 'k')
7625           {                                       /* fork       */
7626             return -KEY_fork;
7627           }
7628
7629           goto unknown;
7630
7631         case 'g':
7632           switch (name[1])
7633           {
7634             case 'e':
7635               if (name[2] == 't' &&
7636                   name[3] == 'c')
7637               {                                   /* getc       */
7638                 return -KEY_getc;
7639               }
7640
7641               goto unknown;
7642
7643             case 'l':
7644               if (name[2] == 'o' &&
7645                   name[3] == 'b')
7646               {                                   /* glob       */
7647                 return KEY_glob;
7648               }
7649
7650               goto unknown;
7651
7652             case 'o':
7653               if (name[2] == 't' &&
7654                   name[3] == 'o')
7655               {                                   /* goto       */
7656                 return KEY_goto;
7657               }
7658
7659               goto unknown;
7660
7661             case 'r':
7662               if (name[2] == 'e' &&
7663                   name[3] == 'p')
7664               {                                   /* grep       */
7665                 return KEY_grep;
7666               }
7667
7668               goto unknown;
7669
7670             default:
7671               goto unknown;
7672           }
7673
7674         case 'j':
7675           if (name[1] == 'o' &&
7676               name[2] == 'i' &&
7677               name[3] == 'n')
7678           {                                       /* join       */
7679             return -KEY_join;
7680           }
7681
7682           goto unknown;
7683
7684         case 'k':
7685           switch (name[1])
7686           {
7687             case 'e':
7688               if (name[2] == 'y' &&
7689                   name[3] == 's')
7690               {                                   /* keys       */
7691                 return -KEY_keys;
7692               }
7693
7694               goto unknown;
7695
7696             case 'i':
7697               if (name[2] == 'l' &&
7698                   name[3] == 'l')
7699               {                                   /* kill       */
7700                 return -KEY_kill;
7701               }
7702
7703               goto unknown;
7704
7705             default:
7706               goto unknown;
7707           }
7708
7709         case 'l':
7710           switch (name[1])
7711           {
7712             case 'a':
7713               if (name[2] == 's' &&
7714                   name[3] == 't')
7715               {                                   /* last       */
7716                 return KEY_last;
7717               }
7718
7719               goto unknown;
7720
7721             case 'i':
7722               if (name[2] == 'n' &&
7723                   name[3] == 'k')
7724               {                                   /* link       */
7725                 return -KEY_link;
7726               }
7727
7728               goto unknown;
7729
7730             case 'o':
7731               if (name[2] == 'c' &&
7732                   name[3] == 'k')
7733               {                                   /* lock       */
7734                 return -KEY_lock;
7735               }
7736
7737               goto unknown;
7738
7739             default:
7740               goto unknown;
7741           }
7742
7743         case 'n':
7744           if (name[1] == 'e' &&
7745               name[2] == 'x' &&
7746               name[3] == 't')
7747           {                                       /* next       */
7748             return KEY_next;
7749           }
7750
7751           goto unknown;
7752
7753         case 'o':
7754           if (name[1] == 'p' &&
7755               name[2] == 'e' &&
7756               name[3] == 'n')
7757           {                                       /* open       */
7758             return -KEY_open;
7759           }
7760
7761           goto unknown;
7762
7763         case 'p':
7764           switch (name[1])
7765           {
7766             case 'a':
7767               if (name[2] == 'c' &&
7768                   name[3] == 'k')
7769               {                                   /* pack       */
7770                 return -KEY_pack;
7771               }
7772
7773               goto unknown;
7774
7775             case 'i':
7776               if (name[2] == 'p' &&
7777                   name[3] == 'e')
7778               {                                   /* pipe       */
7779                 return -KEY_pipe;
7780               }
7781
7782               goto unknown;
7783
7784             case 'u':
7785               if (name[2] == 's' &&
7786                   name[3] == 'h')
7787               {                                   /* push       */
7788                 return -KEY_push;
7789               }
7790
7791               goto unknown;
7792
7793             default:
7794               goto unknown;
7795           }
7796
7797         case 'r':
7798           switch (name[1])
7799           {
7800             case 'a':
7801               if (name[2] == 'n' &&
7802                   name[3] == 'd')
7803               {                                   /* rand       */
7804                 return -KEY_rand;
7805               }
7806
7807               goto unknown;
7808
7809             case 'e':
7810               switch (name[2])
7811               {
7812                 case 'a':
7813                   if (name[3] == 'd')
7814                   {                               /* read       */
7815                     return -KEY_read;
7816                   }
7817
7818                   goto unknown;
7819
7820                 case 'c':
7821                   if (name[3] == 'v')
7822                   {                               /* recv       */
7823                     return -KEY_recv;
7824                   }
7825
7826                   goto unknown;
7827
7828                 case 'd':
7829                   if (name[3] == 'o')
7830                   {                               /* redo       */
7831                     return KEY_redo;
7832                   }
7833
7834                   goto unknown;
7835
7836                 default:
7837                   goto unknown;
7838               }
7839
7840             default:
7841               goto unknown;
7842           }
7843
7844         case 's':
7845           switch (name[1])
7846           {
7847             case 'e':
7848               switch (name[2])
7849               {
7850                 case 'e':
7851                   if (name[3] == 'k')
7852                   {                               /* seek       */
7853                     return -KEY_seek;
7854                   }
7855
7856                   goto unknown;
7857
7858                 case 'n':
7859                   if (name[3] == 'd')
7860                   {                               /* send       */
7861                     return -KEY_send;
7862                   }
7863
7864                   goto unknown;
7865
7866                 default:
7867                   goto unknown;
7868               }
7869
7870             case 'o':
7871               if (name[2] == 'r' &&
7872                   name[3] == 't')
7873               {                                   /* sort       */
7874                 return KEY_sort;
7875               }
7876
7877               goto unknown;
7878
7879             case 'q':
7880               if (name[2] == 'r' &&
7881                   name[3] == 't')
7882               {                                   /* sqrt       */
7883                 return -KEY_sqrt;
7884               }
7885
7886               goto unknown;
7887
7888             case 't':
7889               if (name[2] == 'a' &&
7890                   name[3] == 't')
7891               {                                   /* stat       */
7892                 return -KEY_stat;
7893               }
7894
7895               goto unknown;
7896
7897             default:
7898               goto unknown;
7899           }
7900
7901         case 't':
7902           switch (name[1])
7903           {
7904             case 'e':
7905               if (name[2] == 'l' &&
7906                   name[3] == 'l')
7907               {                                   /* tell       */
7908                 return -KEY_tell;
7909               }
7910
7911               goto unknown;
7912
7913             case 'i':
7914               switch (name[2])
7915               {
7916                 case 'e':
7917                   if (name[3] == 'd')
7918                   {                               /* tied       */
7919                     return KEY_tied;
7920                   }
7921
7922                   goto unknown;
7923
7924                 case 'm':
7925                   if (name[3] == 'e')
7926                   {                               /* time       */
7927                     return -KEY_time;
7928                   }
7929
7930                   goto unknown;
7931
7932                 default:
7933                   goto unknown;
7934               }
7935
7936             default:
7937               goto unknown;
7938           }
7939
7940         case 'w':
7941           switch (name[1])
7942           {
7943             case 'a':
7944               switch (name[2])
7945               {
7946                 case 'i':
7947                   if (name[3] == 't')
7948                   {                               /* wait       */
7949                     return -KEY_wait;
7950                   }
7951
7952                   goto unknown;
7953
7954                 case 'r':
7955                   if (name[3] == 'n')
7956                   {                               /* warn       */
7957                     return -KEY_warn;
7958                   }
7959
7960                   goto unknown;
7961
7962                 default:
7963                   goto unknown;
7964               }
7965
7966             case 'h':
7967               if (name[2] == 'e' &&
7968                   name[3] == 'n')
7969               {                                   /* when       */
7970                 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
7971               }
7972
7973               goto unknown;
7974
7975             default:
7976               goto unknown;
7977           }
7978
7979         default:
7980           goto unknown;
7981       }
7982
7983     case 5: /* 39 tokens of length 5 */
7984       switch (name[0])
7985       {
7986         case 'B':
7987           if (name[1] == 'E' &&
7988               name[2] == 'G' &&
7989               name[3] == 'I' &&
7990               name[4] == 'N')
7991           {                                       /* BEGIN      */
7992             return KEY_BEGIN;
7993           }
7994
7995           goto unknown;
7996
7997         case 'C':
7998           if (name[1] == 'H' &&
7999               name[2] == 'E' &&
8000               name[3] == 'C' &&
8001               name[4] == 'K')
8002           {                                       /* CHECK      */
8003             return KEY_CHECK;
8004           }
8005
8006           goto unknown;
8007
8008         case 'a':
8009           switch (name[1])
8010           {
8011             case 'l':
8012               if (name[2] == 'a' &&
8013                   name[3] == 'r' &&
8014                   name[4] == 'm')
8015               {                                   /* alarm      */
8016                 return -KEY_alarm;
8017               }
8018
8019               goto unknown;
8020
8021             case 't':
8022               if (name[2] == 'a' &&
8023                   name[3] == 'n' &&
8024                   name[4] == '2')
8025               {                                   /* atan2      */
8026                 return -KEY_atan2;
8027               }
8028
8029               goto unknown;
8030
8031             default:
8032               goto unknown;
8033           }
8034
8035         case 'b':
8036           switch (name[1])
8037           {
8038             case 'l':
8039               if (name[2] == 'e' &&
8040                   name[3] == 's' &&
8041                   name[4] == 's')
8042               {                                   /* bless      */
8043                 return -KEY_bless;
8044               }
8045
8046               goto unknown;
8047
8048             case 'r':
8049               if (name[2] == 'e' &&
8050                   name[3] == 'a' &&
8051                   name[4] == 'k')
8052               {                                   /* break      */
8053                 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
8054               }
8055
8056               goto unknown;
8057
8058             default:
8059               goto unknown;
8060           }
8061
8062         case 'c':
8063           switch (name[1])
8064           {
8065             case 'h':
8066               switch (name[2])
8067               {
8068                 case 'd':
8069                   if (name[3] == 'i' &&
8070                       name[4] == 'r')
8071                   {                               /* chdir      */
8072                     return -KEY_chdir;
8073                   }
8074
8075                   goto unknown;
8076
8077                 case 'm':
8078                   if (name[3] == 'o' &&
8079                       name[4] == 'd')
8080                   {                               /* chmod      */
8081                     return -KEY_chmod;
8082                   }
8083
8084                   goto unknown;
8085
8086                 case 'o':
8087                   switch (name[3])
8088                   {
8089                     case 'm':
8090                       if (name[4] == 'p')
8091                       {                           /* chomp      */
8092                         return -KEY_chomp;
8093                       }
8094
8095                       goto unknown;
8096
8097                     case 'w':
8098                       if (name[4] == 'n')
8099                       {                           /* chown      */
8100                         return -KEY_chown;
8101                       }
8102
8103                       goto unknown;
8104
8105                     default:
8106                       goto unknown;
8107                   }
8108
8109                 default:
8110                   goto unknown;
8111               }
8112
8113             case 'l':
8114               if (name[2] == 'o' &&
8115                   name[3] == 's' &&
8116                   name[4] == 'e')
8117               {                                   /* close      */
8118                 return -KEY_close;
8119               }
8120
8121               goto unknown;
8122
8123             case 'r':
8124               if (name[2] == 'y' &&
8125                   name[3] == 'p' &&
8126                   name[4] == 't')
8127               {                                   /* crypt      */
8128                 return -KEY_crypt;
8129               }
8130
8131               goto unknown;
8132
8133             default:
8134               goto unknown;
8135           }
8136
8137         case 'e':
8138           if (name[1] == 'l' &&
8139               name[2] == 's' &&
8140               name[3] == 'i' &&
8141               name[4] == 'f')
8142           {                                       /* elsif      */
8143             return KEY_elsif;
8144           }
8145
8146           goto unknown;
8147
8148         case 'f':
8149           switch (name[1])
8150           {
8151             case 'c':
8152               if (name[2] == 'n' &&
8153                   name[3] == 't' &&
8154                   name[4] == 'l')
8155               {                                   /* fcntl      */
8156                 return -KEY_fcntl;
8157               }
8158
8159               goto unknown;
8160
8161             case 'l':
8162               if (name[2] == 'o' &&
8163                   name[3] == 'c' &&
8164                   name[4] == 'k')
8165               {                                   /* flock      */
8166                 return -KEY_flock;
8167               }
8168
8169               goto unknown;
8170
8171             default:
8172               goto unknown;
8173           }
8174
8175         case 'g':
8176           if (name[1] == 'i' &&
8177               name[2] == 'v' &&
8178               name[3] == 'e' &&
8179               name[4] == 'n')
8180           {                                       /* given      */
8181             return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
8182           }
8183
8184           goto unknown;
8185
8186         case 'i':
8187           switch (name[1])
8188           {
8189             case 'n':
8190               if (name[2] == 'd' &&
8191                   name[3] == 'e' &&
8192                   name[4] == 'x')
8193               {                                   /* index      */
8194                 return -KEY_index;
8195               }
8196
8197               goto unknown;
8198
8199             case 'o':
8200               if (name[2] == 'c' &&
8201                   name[3] == 't' &&
8202                   name[4] == 'l')
8203               {                                   /* ioctl      */
8204                 return -KEY_ioctl;
8205               }
8206
8207               goto unknown;
8208
8209             default:
8210               goto unknown;
8211           }
8212
8213         case 'l':
8214           switch (name[1])
8215           {
8216             case 'o':
8217               if (name[2] == 'c' &&
8218                   name[3] == 'a' &&
8219                   name[4] == 'l')
8220               {                                   /* local      */
8221                 return KEY_local;
8222               }
8223
8224               goto unknown;
8225
8226             case 's':
8227               if (name[2] == 't' &&
8228                   name[3] == 'a' &&
8229                   name[4] == 't')
8230               {                                   /* lstat      */
8231                 return -KEY_lstat;
8232               }
8233
8234               goto unknown;
8235
8236             default:
8237               goto unknown;
8238           }
8239
8240         case 'm':
8241           if (name[1] == 'k' &&
8242               name[2] == 'd' &&
8243               name[3] == 'i' &&
8244               name[4] == 'r')
8245           {                                       /* mkdir      */
8246             return -KEY_mkdir;
8247           }
8248
8249           goto unknown;
8250
8251         case 'p':
8252           if (name[1] == 'r' &&
8253               name[2] == 'i' &&
8254               name[3] == 'n' &&
8255               name[4] == 't')
8256           {                                       /* print      */
8257             return KEY_print;
8258           }
8259
8260           goto unknown;
8261
8262         case 'r':
8263           switch (name[1])
8264           {
8265             case 'e':
8266               if (name[2] == 's' &&
8267                   name[3] == 'e' &&
8268                   name[4] == 't')
8269               {                                   /* reset      */
8270                 return -KEY_reset;
8271               }
8272
8273               goto unknown;
8274
8275             case 'm':
8276               if (name[2] == 'd' &&
8277                   name[3] == 'i' &&
8278                   name[4] == 'r')
8279               {                                   /* rmdir      */
8280                 return -KEY_rmdir;
8281               }
8282
8283               goto unknown;
8284
8285             default:
8286               goto unknown;
8287           }
8288
8289         case 's':
8290           switch (name[1])
8291           {
8292             case 'e':
8293               if (name[2] == 'm' &&
8294                   name[3] == 'o' &&
8295                   name[4] == 'p')
8296               {                                   /* semop      */
8297                 return -KEY_semop;
8298               }
8299
8300               goto unknown;
8301
8302             case 'h':
8303               if (name[2] == 'i' &&
8304                   name[3] == 'f' &&
8305                   name[4] == 't')
8306               {                                   /* shift      */
8307                 return -KEY_shift;
8308               }
8309
8310               goto unknown;
8311
8312             case 'l':
8313               if (name[2] == 'e' &&
8314                   name[3] == 'e' &&
8315                   name[4] == 'p')
8316               {                                   /* sleep      */
8317                 return -KEY_sleep;
8318               }
8319
8320               goto unknown;
8321
8322             case 'p':
8323               if (name[2] == 'l' &&
8324                   name[3] == 'i' &&
8325                   name[4] == 't')
8326               {                                   /* split      */
8327                 return KEY_split;
8328               }
8329
8330               goto unknown;
8331
8332             case 'r':
8333               if (name[2] == 'a' &&
8334                   name[3] == 'n' &&
8335                   name[4] == 'd')
8336               {                                   /* srand      */
8337                 return -KEY_srand;
8338               }
8339
8340               goto unknown;
8341
8342             case 't':
8343               switch (name[2])
8344               {
8345                 case 'a':
8346                   if (name[3] == 't' &&
8347                       name[4] == 'e')
8348                   {                               /* state      */
8349                     return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
8350                   }
8351
8352                   goto unknown;
8353
8354                 case 'u':
8355                   if (name[3] == 'd' &&
8356                       name[4] == 'y')
8357                   {                               /* study      */
8358                     return KEY_study;
8359                   }
8360
8361                   goto unknown;
8362
8363                 default:
8364                   goto unknown;
8365               }
8366
8367             default:
8368               goto unknown;
8369           }
8370
8371         case 't':
8372           if (name[1] == 'i' &&
8373               name[2] == 'm' &&
8374               name[3] == 'e' &&
8375               name[4] == 's')
8376           {                                       /* times      */
8377             return -KEY_times;
8378           }
8379
8380           goto unknown;
8381
8382         case 'u':
8383           switch (name[1])
8384           {
8385             case 'm':
8386               if (name[2] == 'a' &&
8387                   name[3] == 's' &&
8388                   name[4] == 'k')
8389               {                                   /* umask      */
8390                 return -KEY_umask;
8391               }
8392
8393               goto unknown;
8394
8395             case 'n':
8396               switch (name[2])
8397               {
8398                 case 'd':
8399                   if (name[3] == 'e' &&
8400                       name[4] == 'f')
8401                   {                               /* undef      */
8402                     return KEY_undef;
8403                   }
8404
8405                   goto unknown;
8406
8407                 case 't':
8408                   if (name[3] == 'i')
8409                   {
8410                     switch (name[4])
8411                     {
8412                       case 'e':
8413                         {                         /* untie      */
8414                           return KEY_untie;
8415                         }
8416
8417                       case 'l':
8418                         {                         /* until      */
8419                           return KEY_until;
8420                         }
8421
8422                       default:
8423                         goto unknown;
8424                     }
8425                   }
8426
8427                   goto unknown;
8428
8429                 default:
8430                   goto unknown;
8431               }
8432
8433             case 't':
8434               if (name[2] == 'i' &&
8435                   name[3] == 'm' &&
8436                   name[4] == 'e')
8437               {                                   /* utime      */
8438                 return -KEY_utime;
8439               }
8440
8441               goto unknown;
8442
8443             default:
8444               goto unknown;
8445           }
8446
8447         case 'w':
8448           switch (name[1])
8449           {
8450             case 'h':
8451               if (name[2] == 'i' &&
8452                   name[3] == 'l' &&
8453                   name[4] == 'e')
8454               {                                   /* while      */
8455                 return KEY_while;
8456               }
8457
8458               goto unknown;
8459
8460             case 'r':
8461               if (name[2] == 'i' &&
8462                   name[3] == 't' &&
8463                   name[4] == 'e')
8464               {                                   /* write      */
8465                 return -KEY_write;
8466               }
8467
8468               goto unknown;
8469
8470             default:
8471               goto unknown;
8472           }
8473
8474         default:
8475           goto unknown;
8476       }
8477
8478     case 6: /* 33 tokens of length 6 */
8479       switch (name[0])
8480       {
8481         case 'a':
8482           if (name[1] == 'c' &&
8483               name[2] == 'c' &&
8484               name[3] == 'e' &&
8485               name[4] == 'p' &&
8486               name[5] == 't')
8487           {                                       /* accept     */
8488             return -KEY_accept;
8489           }
8490
8491           goto unknown;
8492
8493         case 'c':
8494           switch (name[1])
8495           {
8496             case 'a':
8497               if (name[2] == 'l' &&
8498                   name[3] == 'l' &&
8499                   name[4] == 'e' &&
8500                   name[5] == 'r')
8501               {                                   /* caller     */
8502                 return -KEY_caller;
8503               }
8504
8505               goto unknown;
8506
8507             case 'h':
8508               if (name[2] == 'r' &&
8509                   name[3] == 'o' &&
8510                   name[4] == 'o' &&
8511                   name[5] == 't')
8512               {                                   /* chroot     */
8513                 return -KEY_chroot;
8514               }
8515
8516               goto unknown;
8517
8518             default:
8519               goto unknown;
8520           }
8521
8522         case 'd':
8523           if (name[1] == 'e' &&
8524               name[2] == 'l' &&
8525               name[3] == 'e' &&
8526               name[4] == 't' &&
8527               name[5] == 'e')
8528           {                                       /* delete     */
8529             return KEY_delete;
8530           }
8531
8532           goto unknown;
8533
8534         case 'e':
8535           switch (name[1])
8536           {
8537             case 'l':
8538               if (name[2] == 's' &&
8539                   name[3] == 'e' &&
8540                   name[4] == 'i' &&
8541                   name[5] == 'f')
8542               {                                   /* elseif     */
8543                 if(ckWARN_d(WARN_SYNTAX))
8544                   Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
8545               }
8546
8547               goto unknown;
8548
8549             case 'x':
8550               if (name[2] == 'i' &&
8551                   name[3] == 's' &&
8552                   name[4] == 't' &&
8553                   name[5] == 's')
8554               {                                   /* exists     */
8555                 return KEY_exists;
8556               }
8557
8558               goto unknown;
8559
8560             default:
8561               goto unknown;
8562           }
8563
8564         case 'f':
8565           switch (name[1])
8566           {
8567             case 'i':
8568               if (name[2] == 'l' &&
8569                   name[3] == 'e' &&
8570                   name[4] == 'n' &&
8571                   name[5] == 'o')
8572               {                                   /* fileno     */
8573                 return -KEY_fileno;
8574               }
8575
8576               goto unknown;
8577
8578             case 'o':
8579               if (name[2] == 'r' &&
8580                   name[3] == 'm' &&
8581                   name[4] == 'a' &&
8582                   name[5] == 't')
8583               {                                   /* format     */
8584                 return KEY_format;
8585               }
8586
8587               goto unknown;
8588
8589             default:
8590               goto unknown;
8591           }
8592
8593         case 'g':
8594           if (name[1] == 'm' &&
8595               name[2] == 't' &&
8596               name[3] == 'i' &&
8597               name[4] == 'm' &&
8598               name[5] == 'e')
8599           {                                       /* gmtime     */
8600             return -KEY_gmtime;
8601           }
8602
8603           goto unknown;
8604
8605         case 'l':
8606           switch (name[1])
8607           {
8608             case 'e':
8609               if (name[2] == 'n' &&
8610                   name[3] == 'g' &&
8611                   name[4] == 't' &&
8612                   name[5] == 'h')
8613               {                                   /* length     */
8614                 return -KEY_length;
8615               }
8616
8617               goto unknown;
8618
8619             case 'i':
8620               if (name[2] == 's' &&
8621                   name[3] == 't' &&
8622                   name[4] == 'e' &&
8623                   name[5] == 'n')
8624               {                                   /* listen     */
8625                 return -KEY_listen;
8626               }
8627
8628               goto unknown;
8629
8630             default:
8631               goto unknown;
8632           }
8633
8634         case 'm':
8635           if (name[1] == 's' &&
8636               name[2] == 'g')
8637           {
8638             switch (name[3])
8639             {
8640               case 'c':
8641                 if (name[4] == 't' &&
8642                     name[5] == 'l')
8643                 {                                 /* msgctl     */
8644                   return -KEY_msgctl;
8645                 }
8646
8647                 goto unknown;
8648
8649               case 'g':
8650                 if (name[4] == 'e' &&
8651                     name[5] == 't')
8652                 {                                 /* msgget     */
8653                   return -KEY_msgget;
8654                 }
8655
8656                 goto unknown;
8657
8658               case 'r':
8659                 if (name[4] == 'c' &&
8660                     name[5] == 'v')
8661                 {                                 /* msgrcv     */
8662                   return -KEY_msgrcv;
8663                 }
8664
8665                 goto unknown;
8666
8667               case 's':
8668                 if (name[4] == 'n' &&
8669                     name[5] == 'd')
8670                 {                                 /* msgsnd     */
8671                   return -KEY_msgsnd;
8672                 }
8673
8674                 goto unknown;
8675
8676               default:
8677                 goto unknown;
8678             }
8679           }
8680
8681           goto unknown;
8682
8683         case 'p':
8684           if (name[1] == 'r' &&
8685               name[2] == 'i' &&
8686               name[3] == 'n' &&
8687               name[4] == 't' &&
8688               name[5] == 'f')
8689           {                                       /* printf     */
8690             return KEY_printf;
8691           }
8692
8693           goto unknown;
8694
8695         case 'r':
8696           switch (name[1])
8697           {
8698             case 'e':
8699               switch (name[2])
8700               {
8701                 case 'n':
8702                   if (name[3] == 'a' &&
8703                       name[4] == 'm' &&
8704                       name[5] == 'e')
8705                   {                               /* rename     */
8706                     return -KEY_rename;
8707                   }
8708
8709                   goto unknown;
8710
8711                 case 't':
8712                   if (name[3] == 'u' &&
8713                       name[4] == 'r' &&
8714                       name[5] == 'n')
8715                   {                               /* return     */
8716                     return KEY_return;
8717                   }
8718
8719                   goto unknown;
8720
8721                 default:
8722                   goto unknown;
8723               }
8724
8725             case 'i':
8726               if (name[2] == 'n' &&
8727                   name[3] == 'd' &&
8728                   name[4] == 'e' &&
8729                   name[5] == 'x')
8730               {                                   /* rindex     */
8731                 return -KEY_rindex;
8732               }
8733
8734               goto unknown;
8735
8736             default:
8737               goto unknown;
8738           }
8739
8740         case 's':
8741           switch (name[1])
8742           {
8743             case 'c':
8744               if (name[2] == 'a' &&
8745                   name[3] == 'l' &&
8746                   name[4] == 'a' &&
8747                   name[5] == 'r')
8748               {                                   /* scalar     */
8749                 return KEY_scalar;
8750               }
8751
8752               goto unknown;
8753
8754             case 'e':
8755               switch (name[2])
8756               {
8757                 case 'l':
8758                   if (name[3] == 'e' &&
8759                       name[4] == 'c' &&
8760                       name[5] == 't')
8761                   {                               /* select     */
8762                     return -KEY_select;
8763                   }
8764
8765                   goto unknown;
8766
8767                 case 'm':
8768                   switch (name[3])
8769                   {
8770                     case 'c':
8771                       if (name[4] == 't' &&
8772                           name[5] == 'l')
8773                       {                           /* semctl     */
8774                         return -KEY_semctl;
8775                       }
8776
8777                       goto unknown;
8778
8779                     case 'g':
8780                       if (name[4] == 'e' &&
8781                           name[5] == 't')
8782                       {                           /* semget     */
8783                         return -KEY_semget;
8784                       }
8785
8786                       goto unknown;
8787
8788                     default:
8789                       goto unknown;
8790                   }
8791
8792                 default:
8793                   goto unknown;
8794               }
8795
8796             case 'h':
8797               if (name[2] == 'm')
8798               {
8799                 switch (name[3])
8800                 {
8801                   case 'c':
8802                     if (name[4] == 't' &&
8803                         name[5] == 'l')
8804                     {                             /* shmctl     */
8805                       return -KEY_shmctl;
8806                     }
8807
8808                     goto unknown;
8809
8810                   case 'g':
8811                     if (name[4] == 'e' &&
8812                         name[5] == 't')
8813                     {                             /* shmget     */
8814                       return -KEY_shmget;
8815                     }
8816
8817                     goto unknown;
8818
8819                   default:
8820                     goto unknown;
8821                 }
8822               }
8823
8824               goto unknown;
8825
8826             case 'o':
8827               if (name[2] == 'c' &&
8828                   name[3] == 'k' &&
8829                   name[4] == 'e' &&
8830                   name[5] == 't')
8831               {                                   /* socket     */
8832                 return -KEY_socket;
8833               }
8834
8835               goto unknown;
8836
8837             case 'p':
8838               if (name[2] == 'l' &&
8839                   name[3] == 'i' &&
8840                   name[4] == 'c' &&
8841                   name[5] == 'e')
8842               {                                   /* splice     */
8843                 return -KEY_splice;
8844               }
8845
8846               goto unknown;
8847
8848             case 'u':
8849               if (name[2] == 'b' &&
8850                   name[3] == 's' &&
8851                   name[4] == 't' &&
8852                   name[5] == 'r')
8853               {                                   /* substr     */
8854                 return -KEY_substr;
8855               }
8856
8857               goto unknown;
8858
8859             case 'y':
8860               if (name[2] == 's' &&
8861                   name[3] == 't' &&
8862                   name[4] == 'e' &&
8863                   name[5] == 'm')
8864               {                                   /* system     */
8865                 return -KEY_system;
8866               }
8867
8868               goto unknown;
8869
8870             default:
8871               goto unknown;
8872           }
8873
8874         case 'u':
8875           if (name[1] == 'n')
8876           {
8877             switch (name[2])
8878             {
8879               case 'l':
8880                 switch (name[3])
8881                 {
8882                   case 'e':
8883                     if (name[4] == 's' &&
8884                         name[5] == 's')
8885                     {                             /* unless     */
8886                       return KEY_unless;
8887                     }
8888
8889                     goto unknown;
8890
8891                   case 'i':
8892                     if (name[4] == 'n' &&
8893                         name[5] == 'k')
8894                     {                             /* unlink     */
8895                       return -KEY_unlink;
8896                     }
8897
8898                     goto unknown;
8899
8900                   default:
8901                     goto unknown;
8902                 }
8903
8904               case 'p':
8905                 if (name[3] == 'a' &&
8906                     name[4] == 'c' &&
8907                     name[5] == 'k')
8908                 {                                 /* unpack     */
8909                   return -KEY_unpack;
8910                 }
8911
8912                 goto unknown;
8913
8914               default:
8915                 goto unknown;
8916             }
8917           }
8918
8919           goto unknown;
8920
8921         case 'v':
8922           if (name[1] == 'a' &&
8923               name[2] == 'l' &&
8924               name[3] == 'u' &&
8925               name[4] == 'e' &&
8926               name[5] == 's')
8927           {                                       /* values     */
8928             return -KEY_values;
8929           }
8930
8931           goto unknown;
8932
8933         default:
8934           goto unknown;
8935       }
8936
8937     case 7: /* 29 tokens of length 7 */
8938       switch (name[0])
8939       {
8940         case 'D':
8941           if (name[1] == 'E' &&
8942               name[2] == 'S' &&
8943               name[3] == 'T' &&
8944               name[4] == 'R' &&
8945               name[5] == 'O' &&
8946               name[6] == 'Y')
8947           {                                       /* DESTROY    */
8948             return KEY_DESTROY;
8949           }
8950
8951           goto unknown;
8952
8953         case '_':
8954           if (name[1] == '_' &&
8955               name[2] == 'E' &&
8956               name[3] == 'N' &&
8957               name[4] == 'D' &&
8958               name[5] == '_' &&
8959               name[6] == '_')
8960           {                                       /* __END__    */
8961             return KEY___END__;
8962           }
8963
8964           goto unknown;
8965
8966         case 'b':
8967           if (name[1] == 'i' &&
8968               name[2] == 'n' &&
8969               name[3] == 'm' &&
8970               name[4] == 'o' &&
8971               name[5] == 'd' &&
8972               name[6] == 'e')
8973           {                                       /* binmode    */
8974             return -KEY_binmode;
8975           }
8976
8977           goto unknown;
8978
8979         case 'c':
8980           if (name[1] == 'o' &&
8981               name[2] == 'n' &&
8982               name[3] == 'n' &&
8983               name[4] == 'e' &&
8984               name[5] == 'c' &&
8985               name[6] == 't')
8986           {                                       /* connect    */
8987             return -KEY_connect;
8988           }
8989
8990           goto unknown;
8991
8992         case 'd':
8993           switch (name[1])
8994           {
8995             case 'b':
8996               if (name[2] == 'm' &&
8997                   name[3] == 'o' &&
8998                   name[4] == 'p' &&
8999                   name[5] == 'e' &&
9000                   name[6] == 'n')
9001               {                                   /* dbmopen    */
9002                 return -KEY_dbmopen;
9003               }
9004
9005               goto unknown;
9006
9007             case 'e':
9008               if (name[2] == 'f')
9009               {
9010                 switch (name[3])
9011                 {
9012                   case 'a':
9013                     if (name[4] == 'u' &&
9014                         name[5] == 'l' &&
9015                         name[6] == 't')
9016                     {                             /* default    */
9017                       return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
9018                     }
9019
9020                     goto unknown;
9021
9022                   case 'i':
9023                     if (name[4] == 'n' &&
9024                         name[5] == 'e' &&
9025                         name[6] == 'd')
9026                     {                             /* defined    */
9027                       return KEY_defined;
9028                     }
9029
9030                     goto unknown;
9031
9032                   default:
9033                     goto unknown;
9034                 }
9035               }
9036
9037               goto unknown;
9038
9039             default:
9040               goto unknown;
9041           }
9042
9043         case 'f':
9044           if (name[1] == 'o' &&
9045               name[2] == 'r' &&
9046               name[3] == 'e' &&
9047               name[4] == 'a' &&
9048               name[5] == 'c' &&
9049               name[6] == 'h')
9050           {                                       /* foreach    */
9051             return KEY_foreach;
9052           }
9053
9054           goto unknown;
9055
9056         case 'g':
9057           if (name[1] == 'e' &&
9058               name[2] == 't' &&
9059               name[3] == 'p')
9060           {
9061             switch (name[4])
9062             {
9063               case 'g':
9064                 if (name[5] == 'r' &&
9065                     name[6] == 'p')
9066                 {                                 /* getpgrp    */
9067                   return -KEY_getpgrp;
9068                 }
9069
9070                 goto unknown;
9071
9072               case 'p':
9073                 if (name[5] == 'i' &&
9074                     name[6] == 'd')
9075                 {                                 /* getppid    */
9076                   return -KEY_getppid;
9077                 }
9078
9079                 goto unknown;
9080
9081               default:
9082                 goto unknown;
9083             }
9084           }
9085
9086           goto unknown;
9087
9088         case 'l':
9089           if (name[1] == 'c' &&
9090               name[2] == 'f' &&
9091               name[3] == 'i' &&
9092               name[4] == 'r' &&
9093               name[5] == 's' &&
9094               name[6] == 't')
9095           {                                       /* lcfirst    */
9096             return -KEY_lcfirst;
9097           }
9098
9099           goto unknown;
9100
9101         case 'o':
9102           if (name[1] == 'p' &&
9103               name[2] == 'e' &&
9104               name[3] == 'n' &&
9105               name[4] == 'd' &&
9106               name[5] == 'i' &&
9107               name[6] == 'r')
9108           {                                       /* opendir    */
9109             return -KEY_opendir;
9110           }
9111
9112           goto unknown;
9113
9114         case 'p':
9115           if (name[1] == 'a' &&
9116               name[2] == 'c' &&
9117               name[3] == 'k' &&
9118               name[4] == 'a' &&
9119               name[5] == 'g' &&
9120               name[6] == 'e')
9121           {                                       /* package    */
9122             return KEY_package;
9123           }
9124
9125           goto unknown;
9126
9127         case 'r':
9128           if (name[1] == 'e')
9129           {
9130             switch (name[2])
9131             {
9132               case 'a':
9133                 if (name[3] == 'd' &&
9134                     name[4] == 'd' &&
9135                     name[5] == 'i' &&
9136                     name[6] == 'r')
9137                 {                                 /* readdir    */
9138                   return -KEY_readdir;
9139                 }
9140
9141                 goto unknown;
9142
9143               case 'q':
9144                 if (name[3] == 'u' &&
9145                     name[4] == 'i' &&
9146                     name[5] == 'r' &&
9147                     name[6] == 'e')
9148                 {                                 /* require    */
9149                   return KEY_require;
9150                 }
9151
9152                 goto unknown;
9153
9154               case 'v':
9155                 if (name[3] == 'e' &&
9156                     name[4] == 'r' &&
9157                     name[5] == 's' &&
9158                     name[6] == 'e')
9159                 {                                 /* reverse    */
9160                   return -KEY_reverse;
9161                 }
9162
9163                 goto unknown;
9164
9165               default:
9166                 goto unknown;
9167             }
9168           }
9169
9170           goto unknown;
9171
9172         case 's':
9173           switch (name[1])
9174           {
9175             case 'e':
9176               switch (name[2])
9177               {
9178                 case 'e':
9179                   if (name[3] == 'k' &&
9180                       name[4] == 'd' &&
9181                       name[5] == 'i' &&
9182                       name[6] == 'r')
9183                   {                               /* seekdir    */
9184                     return -KEY_seekdir;
9185                   }
9186
9187                   goto unknown;
9188
9189                 case 't':
9190                   if (name[3] == 'p' &&
9191                       name[4] == 'g' &&
9192                       name[5] == 'r' &&
9193                       name[6] == 'p')
9194                   {                               /* setpgrp    */
9195                     return -KEY_setpgrp;
9196                   }
9197
9198                   goto unknown;
9199
9200                 default:
9201                   goto unknown;
9202               }
9203
9204             case 'h':
9205               if (name[2] == 'm' &&
9206                   name[3] == 'r' &&
9207                   name[4] == 'e' &&
9208                   name[5] == 'a' &&
9209                   name[6] == 'd')
9210               {                                   /* shmread    */
9211                 return -KEY_shmread;
9212               }
9213
9214               goto unknown;
9215
9216             case 'p':
9217               if (name[2] == 'r' &&
9218                   name[3] == 'i' &&
9219                   name[4] == 'n' &&
9220                   name[5] == 't' &&
9221                   name[6] == 'f')
9222               {                                   /* sprintf    */
9223                 return -KEY_sprintf;
9224               }
9225
9226               goto unknown;
9227
9228             case 'y':
9229               switch (name[2])
9230               {
9231                 case 'm':
9232                   if (name[3] == 'l' &&
9233                       name[4] == 'i' &&
9234                       name[5] == 'n' &&
9235                       name[6] == 'k')
9236                   {                               /* symlink    */
9237                     return -KEY_symlink;
9238                   }
9239
9240                   goto unknown;
9241
9242                 case 's':
9243                   switch (name[3])
9244                   {
9245                     case 'c':
9246                       if (name[4] == 'a' &&
9247                           name[5] == 'l' &&
9248                           name[6] == 'l')
9249                       {                           /* syscall    */
9250                         return -KEY_syscall;
9251                       }
9252
9253                       goto unknown;
9254
9255                     case 'o':
9256                       if (name[4] == 'p' &&
9257                           name[5] == 'e' &&
9258                           name[6] == 'n')
9259                       {                           /* sysopen    */
9260                         return -KEY_sysopen;
9261                       }
9262
9263                       goto unknown;
9264
9265                     case 'r':
9266                       if (name[4] == 'e' &&
9267                           name[5] == 'a' &&
9268                           name[6] == 'd')
9269                       {                           /* sysread    */
9270                         return -KEY_sysread;
9271                       }
9272
9273                       goto unknown;
9274
9275                     case 's':
9276                       if (name[4] == 'e' &&
9277                           name[5] == 'e' &&
9278                           name[6] == 'k')
9279                       {                           /* sysseek    */
9280                         return -KEY_sysseek;
9281                       }
9282
9283                       goto unknown;
9284
9285                     default:
9286                       goto unknown;
9287                   }
9288
9289                 default:
9290                   goto unknown;
9291               }
9292
9293             default:
9294               goto unknown;
9295           }
9296
9297         case 't':
9298           if (name[1] == 'e' &&
9299               name[2] == 'l' &&
9300               name[3] == 'l' &&
9301               name[4] == 'd' &&
9302               name[5] == 'i' &&
9303               name[6] == 'r')
9304           {                                       /* telldir    */
9305             return -KEY_telldir;
9306           }
9307
9308           goto unknown;
9309
9310         case 'u':
9311           switch (name[1])
9312           {
9313             case 'c':
9314               if (name[2] == 'f' &&
9315                   name[3] == 'i' &&
9316                   name[4] == 'r' &&
9317                   name[5] == 's' &&
9318                   name[6] == 't')
9319               {                                   /* ucfirst    */
9320                 return -KEY_ucfirst;
9321               }
9322
9323               goto unknown;
9324
9325             case 'n':
9326               if (name[2] == 's' &&
9327                   name[3] == 'h' &&
9328                   name[4] == 'i' &&
9329                   name[5] == 'f' &&
9330                   name[6] == 't')
9331               {                                   /* unshift    */
9332                 return -KEY_unshift;
9333               }
9334
9335               goto unknown;
9336
9337             default:
9338               goto unknown;
9339           }
9340
9341         case 'w':
9342           if (name[1] == 'a' &&
9343               name[2] == 'i' &&
9344               name[3] == 't' &&
9345               name[4] == 'p' &&
9346               name[5] == 'i' &&
9347               name[6] == 'd')
9348           {                                       /* waitpid    */
9349             return -KEY_waitpid;
9350           }
9351
9352           goto unknown;
9353
9354         default:
9355           goto unknown;
9356       }
9357
9358     case 8: /* 26 tokens of length 8 */
9359       switch (name[0])
9360       {
9361         case 'A':
9362           if (name[1] == 'U' &&
9363               name[2] == 'T' &&
9364               name[3] == 'O' &&
9365               name[4] == 'L' &&
9366               name[5] == 'O' &&
9367               name[6] == 'A' &&
9368               name[7] == 'D')
9369           {                                       /* AUTOLOAD   */
9370             return KEY_AUTOLOAD;
9371           }
9372
9373           goto unknown;
9374
9375         case '_':
9376           if (name[1] == '_')
9377           {
9378             switch (name[2])
9379             {
9380               case 'D':
9381                 if (name[3] == 'A' &&
9382                     name[4] == 'T' &&
9383                     name[5] == 'A' &&
9384                     name[6] == '_' &&
9385                     name[7] == '_')
9386                 {                                 /* __DATA__   */
9387                   return KEY___DATA__;
9388                 }
9389
9390                 goto unknown;
9391
9392               case 'F':
9393                 if (name[3] == 'I' &&
9394                     name[4] == 'L' &&
9395                     name[5] == 'E' &&
9396                     name[6] == '_' &&
9397                     name[7] == '_')
9398                 {                                 /* __FILE__   */
9399                   return -KEY___FILE__;
9400                 }
9401
9402                 goto unknown;
9403
9404               case 'L':
9405                 if (name[3] == 'I' &&
9406                     name[4] == 'N' &&
9407                     name[5] == 'E' &&
9408                     name[6] == '_' &&
9409                     name[7] == '_')
9410                 {                                 /* __LINE__   */
9411                   return -KEY___LINE__;
9412                 }
9413
9414                 goto unknown;
9415
9416               default:
9417                 goto unknown;
9418             }
9419           }
9420
9421           goto unknown;
9422
9423         case 'c':
9424           switch (name[1])
9425           {
9426             case 'l':
9427               if (name[2] == 'o' &&
9428                   name[3] == 's' &&
9429                   name[4] == 'e' &&
9430                   name[5] == 'd' &&
9431                   name[6] == 'i' &&
9432                   name[7] == 'r')
9433               {                                   /* closedir   */
9434                 return -KEY_closedir;
9435               }
9436
9437               goto unknown;
9438
9439             case 'o':
9440               if (name[2] == 'n' &&
9441                   name[3] == 't' &&
9442                   name[4] == 'i' &&
9443                   name[5] == 'n' &&
9444                   name[6] == 'u' &&
9445                   name[7] == 'e')
9446               {                                   /* continue   */
9447                 return -KEY_continue;
9448               }
9449
9450               goto unknown;
9451
9452             default:
9453               goto unknown;
9454           }
9455
9456         case 'd':
9457           if (name[1] == 'b' &&
9458               name[2] == 'm' &&
9459               name[3] == 'c' &&
9460               name[4] == 'l' &&
9461               name[5] == 'o' &&
9462               name[6] == 's' &&
9463               name[7] == 'e')
9464           {                                       /* dbmclose   */
9465             return -KEY_dbmclose;
9466           }
9467
9468           goto unknown;
9469
9470         case 'e':
9471           if (name[1] == 'n' &&
9472               name[2] == 'd')
9473           {
9474             switch (name[3])
9475             {
9476               case 'g':
9477                 if (name[4] == 'r' &&
9478                     name[5] == 'e' &&
9479                     name[6] == 'n' &&
9480                     name[7] == 't')
9481                 {                                 /* endgrent   */
9482                   return -KEY_endgrent;
9483                 }
9484
9485                 goto unknown;
9486
9487               case 'p':
9488                 if (name[4] == 'w' &&
9489                     name[5] == 'e' &&
9490                     name[6] == 'n' &&
9491                     name[7] == 't')
9492                 {                                 /* endpwent   */
9493                   return -KEY_endpwent;
9494                 }
9495
9496                 goto unknown;
9497
9498               default:
9499                 goto unknown;
9500             }
9501           }
9502
9503           goto unknown;
9504
9505         case 'f':
9506           if (name[1] == 'o' &&
9507               name[2] == 'r' &&
9508               name[3] == 'm' &&
9509               name[4] == 'l' &&
9510               name[5] == 'i' &&
9511               name[6] == 'n' &&
9512               name[7] == 'e')
9513           {                                       /* formline   */
9514             return -KEY_formline;
9515           }
9516
9517           goto unknown;
9518
9519         case 'g':
9520           if (name[1] == 'e' &&
9521               name[2] == 't')
9522           {
9523             switch (name[3])
9524             {
9525               case 'g':
9526                 if (name[4] == 'r')
9527                 {
9528                   switch (name[5])
9529                   {
9530                     case 'e':
9531                       if (name[6] == 'n' &&
9532                           name[7] == 't')
9533                       {                           /* getgrent   */
9534                         return -KEY_getgrent;
9535                       }
9536
9537                       goto unknown;
9538
9539                     case 'g':
9540                       if (name[6] == 'i' &&
9541                           name[7] == 'd')
9542                       {                           /* getgrgid   */
9543                         return -KEY_getgrgid;
9544                       }
9545
9546                       goto unknown;
9547
9548                     case 'n':
9549                       if (name[6] == 'a' &&
9550                           name[7] == 'm')
9551                       {                           /* getgrnam   */
9552                         return -KEY_getgrnam;
9553                       }
9554
9555                       goto unknown;
9556
9557                     default:
9558                       goto unknown;
9559                   }
9560                 }
9561
9562                 goto unknown;
9563
9564               case 'l':
9565                 if (name[4] == 'o' &&
9566                     name[5] == 'g' &&
9567                     name[6] == 'i' &&
9568                     name[7] == 'n')
9569                 {                                 /* getlogin   */
9570                   return -KEY_getlogin;
9571                 }
9572
9573                 goto unknown;
9574
9575               case 'p':
9576                 if (name[4] == 'w')
9577                 {
9578                   switch (name[5])
9579                   {
9580                     case 'e':
9581                       if (name[6] == 'n' &&
9582                           name[7] == 't')
9583                       {                           /* getpwent   */
9584                         return -KEY_getpwent;
9585                       }
9586
9587                       goto unknown;
9588
9589                     case 'n':
9590                       if (name[6] == 'a' &&
9591                           name[7] == 'm')
9592                       {                           /* getpwnam   */
9593                         return -KEY_getpwnam;
9594                       }
9595
9596                       goto unknown;
9597
9598                     case 'u':
9599                       if (name[6] == 'i' &&
9600                           name[7] == 'd')
9601                       {                           /* getpwuid   */
9602                         return -KEY_getpwuid;
9603                       }
9604
9605                       goto unknown;
9606
9607                     default:
9608                       goto unknown;
9609                   }
9610                 }
9611
9612                 goto unknown;
9613
9614               default:
9615                 goto unknown;
9616             }
9617           }
9618
9619           goto unknown;
9620
9621         case 'r':
9622           if (name[1] == 'e' &&
9623               name[2] == 'a' &&
9624               name[3] == 'd')
9625           {
9626             switch (name[4])
9627             {
9628               case 'l':
9629                 if (name[5] == 'i' &&
9630                     name[6] == 'n')
9631                 {
9632                   switch (name[7])
9633                   {
9634                     case 'e':
9635                       {                           /* readline   */
9636                         return -KEY_readline;
9637                       }
9638
9639                     case 'k':
9640                       {                           /* readlink   */
9641                         return -KEY_readlink;
9642                       }
9643
9644                     default:
9645                       goto unknown;
9646                   }
9647                 }
9648
9649                 goto unknown;
9650
9651               case 'p':
9652                 if (name[5] == 'i' &&
9653                     name[6] == 'p' &&
9654                     name[7] == 'e')
9655                 {                                 /* readpipe   */
9656                   return -KEY_readpipe;
9657                 }
9658
9659                 goto unknown;
9660
9661               default:
9662                 goto unknown;
9663             }
9664           }
9665
9666           goto unknown;
9667
9668         case 's':
9669           switch (name[1])
9670           {
9671             case 'e':
9672               if (name[2] == 't')
9673               {
9674                 switch (name[3])
9675                 {
9676                   case 'g':
9677                     if (name[4] == 'r' &&
9678                         name[5] == 'e' &&
9679                         name[6] == 'n' &&
9680                         name[7] == 't')
9681                     {                             /* setgrent   */
9682                       return -KEY_setgrent;
9683                     }
9684
9685                     goto unknown;
9686
9687                   case 'p':
9688                     if (name[4] == 'w' &&
9689                         name[5] == 'e' &&
9690                         name[6] == 'n' &&
9691                         name[7] == 't')
9692                     {                             /* setpwent   */
9693                       return -KEY_setpwent;
9694                     }
9695
9696                     goto unknown;
9697
9698                   default:
9699                     goto unknown;
9700                 }
9701               }
9702
9703               goto unknown;
9704
9705             case 'h':
9706               switch (name[2])
9707               {
9708                 case 'm':
9709                   if (name[3] == 'w' &&
9710                       name[4] == 'r' &&
9711                       name[5] == 'i' &&
9712                       name[6] == 't' &&
9713                       name[7] == 'e')
9714                   {                               /* shmwrite   */
9715                     return -KEY_shmwrite;
9716                   }
9717
9718                   goto unknown;
9719
9720                 case 'u':
9721                   if (name[3] == 't' &&
9722                       name[4] == 'd' &&
9723                       name[5] == 'o' &&
9724                       name[6] == 'w' &&
9725                       name[7] == 'n')
9726                   {                               /* shutdown   */
9727                     return -KEY_shutdown;
9728                   }
9729
9730                   goto unknown;
9731
9732                 default:
9733                   goto unknown;
9734               }
9735
9736             case 'y':
9737               if (name[2] == 's' &&
9738                   name[3] == 'w' &&
9739                   name[4] == 'r' &&
9740                   name[5] == 'i' &&
9741                   name[6] == 't' &&
9742                   name[7] == 'e')
9743               {                                   /* syswrite   */
9744                 return -KEY_syswrite;
9745               }
9746
9747               goto unknown;
9748
9749             default:
9750               goto unknown;
9751           }
9752
9753         case 't':
9754           if (name[1] == 'r' &&
9755               name[2] == 'u' &&
9756               name[3] == 'n' &&
9757               name[4] == 'c' &&
9758               name[5] == 'a' &&
9759               name[6] == 't' &&
9760               name[7] == 'e')
9761           {                                       /* truncate   */
9762             return -KEY_truncate;
9763           }
9764
9765           goto unknown;
9766
9767         default:
9768           goto unknown;
9769       }
9770
9771     case 9: /* 9 tokens of length 9 */
9772       switch (name[0])
9773       {
9774         case 'U':
9775           if (name[1] == 'N' &&
9776               name[2] == 'I' &&
9777               name[3] == 'T' &&
9778               name[4] == 'C' &&
9779               name[5] == 'H' &&
9780               name[6] == 'E' &&
9781               name[7] == 'C' &&
9782               name[8] == 'K')
9783           {                                       /* UNITCHECK  */
9784             return KEY_UNITCHECK;
9785           }
9786
9787           goto unknown;
9788
9789         case 'e':
9790           if (name[1] == 'n' &&
9791               name[2] == 'd' &&
9792               name[3] == 'n' &&
9793               name[4] == 'e' &&
9794               name[5] == 't' &&
9795               name[6] == 'e' &&
9796               name[7] == 'n' &&
9797               name[8] == 't')
9798           {                                       /* endnetent  */
9799             return -KEY_endnetent;
9800           }
9801
9802           goto unknown;
9803
9804         case 'g':
9805           if (name[1] == 'e' &&
9806               name[2] == 't' &&
9807               name[3] == 'n' &&
9808               name[4] == 'e' &&
9809               name[5] == 't' &&
9810               name[6] == 'e' &&
9811               name[7] == 'n' &&
9812               name[8] == 't')
9813           {                                       /* getnetent  */
9814             return -KEY_getnetent;
9815           }
9816
9817           goto unknown;
9818
9819         case 'l':
9820           if (name[1] == 'o' &&
9821               name[2] == 'c' &&
9822               name[3] == 'a' &&
9823               name[4] == 'l' &&
9824               name[5] == 't' &&
9825               name[6] == 'i' &&
9826               name[7] == 'm' &&
9827               name[8] == 'e')
9828           {                                       /* localtime  */
9829             return -KEY_localtime;
9830           }
9831
9832           goto unknown;
9833
9834         case 'p':
9835           if (name[1] == 'r' &&
9836               name[2] == 'o' &&
9837               name[3] == 't' &&
9838               name[4] == 'o' &&
9839               name[5] == 't' &&
9840               name[6] == 'y' &&
9841               name[7] == 'p' &&
9842               name[8] == 'e')
9843           {                                       /* prototype  */
9844             return KEY_prototype;
9845           }
9846
9847           goto unknown;
9848
9849         case 'q':
9850           if (name[1] == 'u' &&
9851               name[2] == 'o' &&
9852               name[3] == 't' &&
9853               name[4] == 'e' &&
9854               name[5] == 'm' &&
9855               name[6] == 'e' &&
9856               name[7] == 't' &&
9857               name[8] == 'a')
9858           {                                       /* quotemeta  */
9859             return -KEY_quotemeta;
9860           }
9861
9862           goto unknown;
9863
9864         case 'r':
9865           if (name[1] == 'e' &&
9866               name[2] == 'w' &&
9867               name[3] == 'i' &&
9868               name[4] == 'n' &&
9869               name[5] == 'd' &&
9870               name[6] == 'd' &&
9871               name[7] == 'i' &&
9872               name[8] == 'r')
9873           {                                       /* rewinddir  */
9874             return -KEY_rewinddir;
9875           }
9876
9877           goto unknown;
9878
9879         case 's':
9880           if (name[1] == 'e' &&
9881               name[2] == 't' &&
9882               name[3] == 'n' &&
9883               name[4] == 'e' &&
9884               name[5] == 't' &&
9885               name[6] == 'e' &&
9886               name[7] == 'n' &&
9887               name[8] == 't')
9888           {                                       /* setnetent  */
9889             return -KEY_setnetent;
9890           }
9891
9892           goto unknown;
9893
9894         case 'w':
9895           if (name[1] == 'a' &&
9896               name[2] == 'n' &&
9897               name[3] == 't' &&
9898               name[4] == 'a' &&
9899               name[5] == 'r' &&
9900               name[6] == 'r' &&
9901               name[7] == 'a' &&
9902               name[8] == 'y')
9903           {                                       /* wantarray  */
9904             return -KEY_wantarray;
9905           }
9906
9907           goto unknown;
9908
9909         default:
9910           goto unknown;
9911       }
9912
9913     case 10: /* 9 tokens of length 10 */
9914       switch (name[0])
9915       {
9916         case 'e':
9917           if (name[1] == 'n' &&
9918               name[2] == 'd')
9919           {
9920             switch (name[3])
9921             {
9922               case 'h':
9923                 if (name[4] == 'o' &&
9924                     name[5] == 's' &&
9925                     name[6] == 't' &&
9926                     name[7] == 'e' &&
9927                     name[8] == 'n' &&
9928                     name[9] == 't')
9929                 {                                 /* endhostent */
9930                   return -KEY_endhostent;
9931                 }
9932
9933                 goto unknown;
9934
9935               case 's':
9936                 if (name[4] == 'e' &&
9937                     name[5] == 'r' &&
9938                     name[6] == 'v' &&
9939                     name[7] == 'e' &&
9940                     name[8] == 'n' &&
9941                     name[9] == 't')
9942                 {                                 /* endservent */
9943                   return -KEY_endservent;
9944                 }
9945
9946                 goto unknown;
9947
9948               default:
9949                 goto unknown;
9950             }
9951           }
9952
9953           goto unknown;
9954
9955         case 'g':
9956           if (name[1] == 'e' &&
9957               name[2] == 't')
9958           {
9959             switch (name[3])
9960             {
9961               case 'h':
9962                 if (name[4] == 'o' &&
9963                     name[5] == 's' &&
9964                     name[6] == 't' &&
9965                     name[7] == 'e' &&
9966                     name[8] == 'n' &&
9967                     name[9] == 't')
9968                 {                                 /* gethostent */
9969                   return -KEY_gethostent;
9970                 }
9971
9972                 goto unknown;
9973
9974               case 's':
9975                 switch (name[4])
9976                 {
9977                   case 'e':
9978                     if (name[5] == 'r' &&
9979                         name[6] == 'v' &&
9980                         name[7] == 'e' &&
9981                         name[8] == 'n' &&
9982                         name[9] == 't')
9983                     {                             /* getservent */
9984                       return -KEY_getservent;
9985                     }
9986
9987                     goto unknown;
9988
9989                   case 'o':
9990                     if (name[5] == 'c' &&
9991                         name[6] == 'k' &&
9992                         name[7] == 'o' &&
9993                         name[8] == 'p' &&
9994                         name[9] == 't')
9995                     {                             /* getsockopt */
9996                       return -KEY_getsockopt;
9997                     }
9998
9999                     goto unknown;
10000
10001                   default:
10002                     goto unknown;
10003                 }
10004
10005               default:
10006                 goto unknown;
10007             }
10008           }
10009
10010           goto unknown;
10011
10012         case 's':
10013           switch (name[1])
10014           {
10015             case 'e':
10016               if (name[2] == 't')
10017               {
10018                 switch (name[3])
10019                 {
10020                   case 'h':
10021                     if (name[4] == 'o' &&
10022                         name[5] == 's' &&
10023                         name[6] == 't' &&
10024                         name[7] == 'e' &&
10025                         name[8] == 'n' &&
10026                         name[9] == 't')
10027                     {                             /* sethostent */
10028                       return -KEY_sethostent;
10029                     }
10030
10031                     goto unknown;
10032
10033                   case 's':
10034                     switch (name[4])
10035                     {
10036                       case 'e':
10037                         if (name[5] == 'r' &&
10038                             name[6] == 'v' &&
10039                             name[7] == 'e' &&
10040                             name[8] == 'n' &&
10041                             name[9] == 't')
10042                         {                         /* setservent */
10043                           return -KEY_setservent;
10044                         }
10045
10046                         goto unknown;
10047
10048                       case 'o':
10049                         if (name[5] == 'c' &&
10050                             name[6] == 'k' &&
10051                             name[7] == 'o' &&
10052                             name[8] == 'p' &&
10053                             name[9] == 't')
10054                         {                         /* setsockopt */
10055                           return -KEY_setsockopt;
10056                         }
10057
10058                         goto unknown;
10059
10060                       default:
10061                         goto unknown;
10062                     }
10063
10064                   default:
10065                     goto unknown;
10066                 }
10067               }
10068
10069               goto unknown;
10070
10071             case 'o':
10072               if (name[2] == 'c' &&
10073                   name[3] == 'k' &&
10074                   name[4] == 'e' &&
10075                   name[5] == 't' &&
10076                   name[6] == 'p' &&
10077                   name[7] == 'a' &&
10078                   name[8] == 'i' &&
10079                   name[9] == 'r')
10080               {                                   /* socketpair */
10081                 return -KEY_socketpair;
10082               }
10083
10084               goto unknown;
10085
10086             default:
10087               goto unknown;
10088           }
10089
10090         default:
10091           goto unknown;
10092       }
10093
10094     case 11: /* 8 tokens of length 11 */
10095       switch (name[0])
10096       {
10097         case '_':
10098           if (name[1] == '_' &&
10099               name[2] == 'P' &&
10100               name[3] == 'A' &&
10101               name[4] == 'C' &&
10102               name[5] == 'K' &&
10103               name[6] == 'A' &&
10104               name[7] == 'G' &&
10105               name[8] == 'E' &&
10106               name[9] == '_' &&
10107               name[10] == '_')
10108           {                                       /* __PACKAGE__ */
10109             return -KEY___PACKAGE__;
10110           }
10111
10112           goto unknown;
10113
10114         case 'e':
10115           if (name[1] == 'n' &&
10116               name[2] == 'd' &&
10117               name[3] == 'p' &&
10118               name[4] == 'r' &&
10119               name[5] == 'o' &&
10120               name[6] == 't' &&
10121               name[7] == 'o' &&
10122               name[8] == 'e' &&
10123               name[9] == 'n' &&
10124               name[10] == 't')
10125           {                                       /* endprotoent */
10126             return -KEY_endprotoent;
10127           }
10128
10129           goto unknown;
10130
10131         case 'g':
10132           if (name[1] == 'e' &&
10133               name[2] == 't')
10134           {
10135             switch (name[3])
10136             {
10137               case 'p':
10138                 switch (name[4])
10139                 {
10140                   case 'e':
10141                     if (name[5] == 'e' &&
10142                         name[6] == 'r' &&
10143                         name[7] == 'n' &&
10144                         name[8] == 'a' &&
10145                         name[9] == 'm' &&
10146                         name[10] == 'e')
10147                     {                             /* getpeername */
10148                       return -KEY_getpeername;
10149                     }
10150
10151                     goto unknown;
10152
10153                   case 'r':
10154                     switch (name[5])
10155                     {
10156                       case 'i':
10157                         if (name[6] == 'o' &&
10158                             name[7] == 'r' &&
10159                             name[8] == 'i' &&
10160                             name[9] == 't' &&
10161                             name[10] == 'y')
10162                         {                         /* getpriority */
10163                           return -KEY_getpriority;
10164                         }
10165
10166                         goto unknown;
10167
10168                       case 'o':
10169                         if (name[6] == 't' &&
10170                             name[7] == 'o' &&
10171                             name[8] == 'e' &&
10172                             name[9] == 'n' &&
10173                             name[10] == 't')
10174                         {                         /* getprotoent */
10175                           return -KEY_getprotoent;
10176                         }
10177
10178                         goto unknown;
10179
10180                       default:
10181                         goto unknown;
10182                     }
10183
10184                   default:
10185                     goto unknown;
10186                 }
10187
10188               case 's':
10189                 if (name[4] == 'o' &&
10190                     name[5] == 'c' &&
10191                     name[6] == 'k' &&
10192                     name[7] == 'n' &&
10193                     name[8] == 'a' &&
10194                     name[9] == 'm' &&
10195                     name[10] == 'e')
10196                 {                                 /* getsockname */
10197                   return -KEY_getsockname;
10198                 }
10199
10200                 goto unknown;
10201
10202               default:
10203                 goto unknown;
10204             }
10205           }
10206
10207           goto unknown;
10208
10209         case 's':
10210           if (name[1] == 'e' &&
10211               name[2] == 't' &&
10212               name[3] == 'p' &&
10213               name[4] == 'r')
10214           {
10215             switch (name[5])
10216             {
10217               case 'i':
10218                 if (name[6] == 'o' &&
10219                     name[7] == 'r' &&
10220                     name[8] == 'i' &&
10221                     name[9] == 't' &&
10222                     name[10] == 'y')
10223                 {                                 /* setpriority */
10224                   return -KEY_setpriority;
10225                 }
10226
10227                 goto unknown;
10228
10229               case 'o':
10230                 if (name[6] == 't' &&
10231                     name[7] == 'o' &&
10232                     name[8] == 'e' &&
10233                     name[9] == 'n' &&
10234                     name[10] == 't')
10235                 {                                 /* setprotoent */
10236                   return -KEY_setprotoent;
10237                 }
10238
10239                 goto unknown;
10240
10241               default:
10242                 goto unknown;
10243             }
10244           }
10245
10246           goto unknown;
10247
10248         default:
10249           goto unknown;
10250       }
10251
10252     case 12: /* 2 tokens of length 12 */
10253       if (name[0] == 'g' &&
10254           name[1] == 'e' &&
10255           name[2] == 't' &&
10256           name[3] == 'n' &&
10257           name[4] == 'e' &&
10258           name[5] == 't' &&
10259           name[6] == 'b' &&
10260           name[7] == 'y')
10261       {
10262         switch (name[8])
10263         {
10264           case 'a':
10265             if (name[9] == 'd' &&
10266                 name[10] == 'd' &&
10267                 name[11] == 'r')
10268             {                                     /* getnetbyaddr */
10269               return -KEY_getnetbyaddr;
10270             }
10271
10272             goto unknown;
10273
10274           case 'n':
10275             if (name[9] == 'a' &&
10276                 name[10] == 'm' &&
10277                 name[11] == 'e')
10278             {                                     /* getnetbyname */
10279               return -KEY_getnetbyname;
10280             }
10281
10282             goto unknown;
10283
10284           default:
10285             goto unknown;
10286         }
10287       }
10288
10289       goto unknown;
10290
10291     case 13: /* 4 tokens of length 13 */
10292       if (name[0] == 'g' &&
10293           name[1] == 'e' &&
10294           name[2] == 't')
10295       {
10296         switch (name[3])
10297         {
10298           case 'h':
10299             if (name[4] == 'o' &&
10300                 name[5] == 's' &&
10301                 name[6] == 't' &&
10302                 name[7] == 'b' &&
10303                 name[8] == 'y')
10304             {
10305               switch (name[9])
10306               {
10307                 case 'a':
10308                   if (name[10] == 'd' &&
10309                       name[11] == 'd' &&
10310                       name[12] == 'r')
10311                   {                               /* gethostbyaddr */
10312                     return -KEY_gethostbyaddr;
10313                   }
10314
10315                   goto unknown;
10316
10317                 case 'n':
10318                   if (name[10] == 'a' &&
10319                       name[11] == 'm' &&
10320                       name[12] == 'e')
10321                   {                               /* gethostbyname */
10322                     return -KEY_gethostbyname;
10323                   }
10324
10325                   goto unknown;
10326
10327                 default:
10328                   goto unknown;
10329               }
10330             }
10331
10332             goto unknown;
10333
10334           case 's':
10335             if (name[4] == 'e' &&
10336                 name[5] == 'r' &&
10337                 name[6] == 'v' &&
10338                 name[7] == 'b' &&
10339                 name[8] == 'y')
10340             {
10341               switch (name[9])
10342               {
10343                 case 'n':
10344                   if (name[10] == 'a' &&
10345                       name[11] == 'm' &&
10346                       name[12] == 'e')
10347                   {                               /* getservbyname */
10348                     return -KEY_getservbyname;
10349                   }
10350
10351                   goto unknown;
10352
10353                 case 'p':
10354                   if (name[10] == 'o' &&
10355                       name[11] == 'r' &&
10356                       name[12] == 't')
10357                   {                               /* getservbyport */
10358                     return -KEY_getservbyport;
10359                   }
10360
10361                   goto unknown;
10362
10363                 default:
10364                   goto unknown;
10365               }
10366             }
10367
10368             goto unknown;
10369
10370           default:
10371             goto unknown;
10372         }
10373       }
10374
10375       goto unknown;
10376
10377     case 14: /* 1 tokens of length 14 */
10378       if (name[0] == 'g' &&
10379           name[1] == 'e' &&
10380           name[2] == 't' &&
10381           name[3] == 'p' &&
10382           name[4] == 'r' &&
10383           name[5] == 'o' &&
10384           name[6] == 't' &&
10385           name[7] == 'o' &&
10386           name[8] == 'b' &&
10387           name[9] == 'y' &&
10388           name[10] == 'n' &&
10389           name[11] == 'a' &&
10390           name[12] == 'm' &&
10391           name[13] == 'e')
10392       {                                           /* getprotobyname */
10393         return -KEY_getprotobyname;
10394       }
10395
10396       goto unknown;
10397
10398     case 16: /* 1 tokens of length 16 */
10399       if (name[0] == 'g' &&
10400           name[1] == 'e' &&
10401           name[2] == 't' &&
10402           name[3] == 'p' &&
10403           name[4] == 'r' &&
10404           name[5] == 'o' &&
10405           name[6] == 't' &&
10406           name[7] == 'o' &&
10407           name[8] == 'b' &&
10408           name[9] == 'y' &&
10409           name[10] == 'n' &&
10410           name[11] == 'u' &&
10411           name[12] == 'm' &&
10412           name[13] == 'b' &&
10413           name[14] == 'e' &&
10414           name[15] == 'r')
10415       {                                           /* getprotobynumber */
10416         return -KEY_getprotobynumber;
10417       }
10418
10419       goto unknown;
10420
10421     default:
10422       goto unknown;
10423   }
10424
10425 unknown:
10426   return 0;
10427 }
10428
10429 STATIC void
10430 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
10431 {
10432     dVAR;
10433
10434     if (*s == ' ' && s[1] == '(') {     /* XXX gotta be a better way */
10435         if (ckWARN(WARN_SYNTAX)) {
10436             int level = 1;
10437             const char *w;
10438             for (w = s+2; *w && level; w++) {
10439                 if (*w == '(')
10440                     ++level;
10441                 else if (*w == ')')
10442                     --level;
10443             }
10444             while (isSPACE(*w))
10445                 ++w;
10446             if (!*w || !strchr(";|})]oaiuw!=", *w))     /* an advisory hack only... */
10447                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
10448                             "%s (...) interpreted as function",name);
10449         }
10450     }
10451     while (s < PL_bufend && isSPACE(*s))
10452         s++;
10453     if (*s == '(')
10454         s++;
10455     while (s < PL_bufend && isSPACE(*s))
10456         s++;
10457     if (isIDFIRST_lazy_if(s,UTF)) {
10458         const char * const w = s++;
10459         while (isALNUM_lazy_if(s,UTF))
10460             s++;
10461         while (s < PL_bufend && isSPACE(*s))
10462             s++;
10463         if (*s == ',') {
10464             GV* gv;
10465             if (keyword(w, s - w, 0))
10466                 return;
10467
10468             gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10469             if (gv && GvCVu(gv))
10470                 return;
10471             Perl_croak(aTHX_ "No comma allowed after %s", what);
10472         }
10473     }
10474 }
10475
10476 /* Either returns sv, or mortalizes sv and returns a new SV*.
10477    Best used as sv=new_constant(..., sv, ...).
10478    If s, pv are NULL, calls subroutine with one argument,
10479    and type is used with error messages only. */
10480
10481 STATIC SV *
10482 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
10483                const char *type)
10484 {
10485     dVAR; dSP;
10486     HV * const table = GvHV(PL_hintgv);          /* ^H */
10487     SV *res;
10488     SV **cvp;
10489     SV *cv, *typesv;
10490     const char *why1 = "", *why2 = "", *why3 = "";
10491
10492     if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
10493         SV *msg;
10494         
10495         why2 = (const char *)
10496             (strEQ(key,"charnames")
10497              ? "(possibly a missing \"use charnames ...\")"
10498              : "");
10499         msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
10500                             (type ? type: "undef"), why2);
10501
10502         /* This is convoluted and evil ("goto considered harmful")
10503          * but I do not understand the intricacies of all the different
10504          * failure modes of %^H in here.  The goal here is to make
10505          * the most probable error message user-friendly. --jhi */
10506
10507         goto msgdone;
10508
10509     report:
10510         msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
10511                             (type ? type: "undef"), why1, why2, why3);
10512     msgdone:
10513         yyerror(SvPVX_const(msg));
10514         SvREFCNT_dec(msg);
10515         return sv;
10516     }
10517     cvp = hv_fetch(table, key, strlen(key), FALSE);
10518     if (!cvp || !SvOK(*cvp)) {
10519         why1 = "$^H{";
10520         why2 = key;
10521         why3 = "} is not defined";
10522         goto report;
10523     }
10524     sv_2mortal(sv);                     /* Parent created it permanently */
10525     cv = *cvp;
10526     if (!pv && s)
10527         pv = sv_2mortal(newSVpvn(s, len));
10528     if (type && pv)
10529         typesv = sv_2mortal(newSVpv(type, 0));
10530     else
10531         typesv = &PL_sv_undef;
10532
10533     PUSHSTACKi(PERLSI_OVERLOAD);
10534     ENTER ;
10535     SAVETMPS;
10536
10537     PUSHMARK(SP) ;
10538     EXTEND(sp, 3);
10539     if (pv)
10540         PUSHs(pv);
10541     PUSHs(sv);
10542     if (pv)
10543         PUSHs(typesv);
10544     PUTBACK;
10545     call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
10546
10547     SPAGAIN ;
10548
10549     /* Check the eval first */
10550     if (!PL_in_eval && SvTRUE(ERRSV)) {
10551         sv_catpvs(ERRSV, "Propagated");
10552         yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
10553         (void)POPs;
10554         res = SvREFCNT_inc_simple(sv);
10555     }
10556     else {
10557         res = POPs;
10558         SvREFCNT_inc_simple_void(res);
10559     }
10560
10561     PUTBACK ;
10562     FREETMPS ;
10563     LEAVE ;
10564     POPSTACK;
10565
10566     if (!SvOK(res)) {
10567         why1 = "Call to &{$^H{";
10568         why2 = key;
10569         why3 = "}} did not return a defined value";
10570         sv = res;
10571         goto report;
10572     }
10573
10574     return res;
10575 }
10576
10577 /* Returns a NUL terminated string, with the length of the string written to
10578    *slp
10579    */
10580 STATIC char *
10581 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
10582 {
10583     dVAR;
10584     register char *d = dest;
10585     register char * const e = d + destlen - 3;  /* two-character token, ending NUL */
10586     for (;;) {
10587         if (d >= e)
10588             Perl_croak(aTHX_ ident_too_long);
10589         if (isALNUM(*s))        /* UTF handled below */
10590             *d++ = *s++;
10591         else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
10592             *d++ = ':';
10593             *d++ = ':';
10594             s++;
10595         }
10596         else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
10597             *d++ = *s++;
10598             *d++ = *s++;
10599         }
10600         else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10601             char *t = s + UTF8SKIP(s);
10602             size_t len;
10603             while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10604                 t += UTF8SKIP(t);
10605             len = t - s;
10606             if (d + len > e)
10607                 Perl_croak(aTHX_ ident_too_long);
10608             Copy(s, d, len, char);
10609             d += len;
10610             s = t;
10611         }
10612         else {
10613             *d = '\0';
10614             *slp = d - dest;
10615             return s;
10616         }
10617     }
10618 }
10619
10620 STATIC char *
10621 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
10622 {
10623     dVAR;
10624     char *bracket = NULL;
10625     char funny = *s++;
10626     register char *d = dest;
10627     register char * const e = d + destlen + 3;    /* two-character token, ending NUL */
10628
10629     if (isSPACE(*s))
10630         s = PEEKSPACE(s);
10631     if (isDIGIT(*s)) {
10632         while (isDIGIT(*s)) {
10633             if (d >= e)
10634                 Perl_croak(aTHX_ ident_too_long);
10635             *d++ = *s++;
10636         }
10637     }
10638     else {
10639         for (;;) {
10640             if (d >= e)
10641                 Perl_croak(aTHX_ ident_too_long);
10642             if (isALNUM(*s))    /* UTF handled below */
10643                 *d++ = *s++;
10644             else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
10645                 *d++ = ':';
10646                 *d++ = ':';
10647                 s++;
10648             }
10649             else if (*s == ':' && s[1] == ':') {
10650                 *d++ = *s++;
10651                 *d++ = *s++;
10652             }
10653             else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
10654                 char *t = s + UTF8SKIP(s);
10655                 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
10656                     t += UTF8SKIP(t);
10657                 if (d + (t - s) > e)
10658                     Perl_croak(aTHX_ ident_too_long);
10659                 Copy(s, d, t - s, char);
10660                 d += t - s;
10661                 s = t;
10662             }
10663             else
10664                 break;
10665         }
10666     }
10667     *d = '\0';
10668     d = dest;
10669     if (*d) {
10670         if (PL_lex_state != LEX_NORMAL)
10671             PL_lex_state = LEX_INTERPENDMAYBE;
10672         return s;
10673     }
10674     if (*s == '$' && s[1] &&
10675         (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
10676     {
10677         return s;
10678     }
10679     if (*s == '{') {
10680         bracket = s;
10681         s++;
10682     }
10683     else if (ck_uni)
10684         check_uni();
10685     if (s < send)
10686         *d = *s++;
10687     d[1] = '\0';
10688     if (*d == '^' && *s && isCONTROLVAR(*s)) {
10689         *d = toCTRL(*s);
10690         s++;
10691     }
10692     if (bracket) {
10693         if (isSPACE(s[-1])) {
10694             while (s < send) {
10695                 const char ch = *s++;
10696                 if (!SPACE_OR_TAB(ch)) {
10697                     *d = ch;
10698                     break;
10699                 }
10700             }
10701         }
10702         if (isIDFIRST_lazy_if(d,UTF)) {
10703             d++;
10704             if (UTF) {
10705                 char *end = s;
10706                 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10707                     end += UTF8SKIP(end);
10708                     while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10709                         end += UTF8SKIP(end);
10710                 }
10711                 Copy(s, d, end - s, char);
10712                 d += end - s;
10713                 s = end;
10714             }
10715             else {
10716                 while ((isALNUM(*s) || *s == ':') && d < e)
10717                     *d++ = *s++;
10718                 if (d >= e)
10719                     Perl_croak(aTHX_ ident_too_long);
10720             }
10721             *d = '\0';
10722             while (s < send && SPACE_OR_TAB(*s))
10723                 s++;
10724             if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
10725                 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10726                     const char * const brack =
10727                         (const char *)
10728                         ((*s == '[') ? "[...]" : "{...}");
10729                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10730                         "Ambiguous use of %c{%s%s} resolved to %c%s%s",
10731                         funny, dest, brack, funny, dest, brack);
10732                 }
10733                 bracket++;
10734                 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
10735                 return s;
10736             }
10737         }
10738         /* Handle extended ${^Foo} variables
10739          * 1999-02-27 mjd-perl-patch@plover.com */
10740         else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10741                  && isALNUM(*s))
10742         {
10743             d++;
10744             while (isALNUM(*s) && d < e) {
10745                 *d++ = *s++;
10746             }
10747             if (d >= e)
10748                 Perl_croak(aTHX_ ident_too_long);
10749             *d = '\0';
10750         }
10751         if (*s == '}') {
10752             s++;
10753             if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
10754                 PL_lex_state = LEX_INTERPEND;
10755                 PL_expect = XREF;
10756             }
10757             if (PL_lex_state == LEX_NORMAL) {
10758                 if (ckWARN(WARN_AMBIGUOUS) &&
10759                     (keyword(dest, d - dest, 0)
10760                      || get_cvn_flags(dest, d - dest, 0)))
10761                 {
10762                     if (funny == '#')
10763                         funny = '@';
10764                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
10765                         "Ambiguous use of %c{%s} resolved to %c%s",
10766                         funny, dest, funny, dest);
10767                 }
10768             }
10769         }
10770         else {
10771             s = bracket;                /* let the parser handle it */
10772             *dest = '\0';
10773         }
10774     }
10775     else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10776         PL_lex_state = LEX_INTERPEND;
10777     return s;
10778 }
10779
10780 void
10781 Perl_pmflag(pTHX_ U32* pmfl, int ch)
10782 {
10783     PERL_UNUSED_CONTEXT;
10784     if (ch<256) {
10785         char c = (char)ch;
10786         switch (c) {
10787             CASE_STD_PMMOD_FLAGS_PARSE_SET(pmfl);
10788             case GLOBAL_PAT_MOD:    *pmfl |= PMf_GLOBAL; break;
10789             case CONTINUE_PAT_MOD:  *pmfl |= PMf_CONTINUE; break;
10790             case ONCE_PAT_MOD:      *pmfl |= PMf_KEEP; break;
10791             case KEEPCOPY_PAT_MOD:  *pmfl |= PMf_KEEPCOPY; break;
10792         }
10793     }
10794 }
10795
10796 STATIC char *
10797 S_scan_pat(pTHX_ char *start, I32 type)
10798 {
10799     dVAR;
10800     PMOP *pm;
10801     char *s = scan_str(start,!!PL_madskills,FALSE);
10802     const char * const valid_flags =
10803         (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
10804 #ifdef PERL_MAD
10805     char *modstart;
10806 #endif
10807
10808
10809     if (!s) {
10810         const char * const delimiter = skipspace(start);
10811         Perl_croak(aTHX_
10812                    (const char *)
10813                    (*delimiter == '?'
10814                     ? "Search pattern not terminated or ternary operator parsed as search pattern"
10815                     : "Search pattern not terminated" ));
10816     }
10817
10818     pm = (PMOP*)newPMOP(type, 0);
10819     if (PL_multi_open == '?')
10820         pm->op_pmflags |= PMf_ONCE;
10821 #ifdef PERL_MAD
10822     modstart = s;
10823 #endif
10824     while (*s && strchr(valid_flags, *s))
10825         pmflag(&pm->op_pmflags,*s++);
10826 #ifdef PERL_MAD
10827     if (PL_madskills && modstart != s) {
10828         SV* tmptoken = newSVpvn(modstart, s - modstart);
10829         append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
10830     }
10831 #endif
10832     /* issue a warning if /c is specified,but /g is not */
10833     if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
10834             && ckWARN(WARN_REGEXP))
10835     {
10836         Perl_warner(aTHX_ packWARN(WARN_REGEXP), 
10837             "Use of /c modifier is meaningless without /g" );
10838     }
10839
10840     pm->op_pmpermflags = pm->op_pmflags;
10841
10842     PL_lex_op = (OP*)pm;
10843     yylval.ival = OP_MATCH;
10844     return s;
10845 }
10846
10847 STATIC char *
10848 S_scan_subst(pTHX_ char *start)
10849 {
10850     dVAR;
10851     register char *s;
10852     register PMOP *pm;
10853     I32 first_start;
10854     I32 es = 0;
10855 #ifdef PERL_MAD
10856     char *modstart;
10857 #endif
10858
10859     yylval.ival = OP_NULL;
10860
10861     s = scan_str(start,!!PL_madskills,FALSE);
10862
10863     if (!s)
10864         Perl_croak(aTHX_ "Substitution pattern not terminated");
10865
10866     if (s[-1] == PL_multi_open)
10867         s--;
10868 #ifdef PERL_MAD
10869     if (PL_madskills) {
10870         CURMAD('q', PL_thisopen);
10871         CURMAD('_', PL_thiswhite);
10872         CURMAD('E', PL_thisstuff);
10873         CURMAD('Q', PL_thisclose);
10874         PL_realtokenstart = s - SvPVX(PL_linestr);
10875     }
10876 #endif
10877
10878     first_start = PL_multi_start;
10879     s = scan_str(s,!!PL_madskills,FALSE);
10880     if (!s) {
10881         if (PL_lex_stuff) {
10882             SvREFCNT_dec(PL_lex_stuff);
10883             PL_lex_stuff = NULL;
10884         }
10885         Perl_croak(aTHX_ "Substitution replacement not terminated");
10886     }
10887     PL_multi_start = first_start;       /* so whole substitution is taken together */
10888
10889     pm = (PMOP*)newPMOP(OP_SUBST, 0);
10890
10891 #ifdef PERL_MAD
10892     if (PL_madskills) {
10893         CURMAD('z', PL_thisopen);
10894         CURMAD('R', PL_thisstuff);
10895         CURMAD('Z', PL_thisclose);
10896     }
10897     modstart = s;
10898 #endif
10899
10900     while (*s) {
10901         if (*s == EXEC_PAT_MOD) {
10902             s++;
10903             es++;
10904         }
10905         else if (strchr(S_PAT_MODS, *s))
10906             pmflag(&pm->op_pmflags,*s++);
10907         else
10908             break;
10909     }
10910
10911 #ifdef PERL_MAD
10912     if (PL_madskills) {
10913         if (modstart != s)
10914             curmad('m', newSVpvn(modstart, s - modstart));
10915         append_madprops(PL_thismad, (OP*)pm, 0);
10916         PL_thismad = 0;
10917     }
10918 #endif
10919     if ((pm->op_pmflags & PMf_CONTINUE) && ckWARN(WARN_REGEXP)) {
10920         Perl_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
10921     }
10922
10923     if (es) {
10924         SV * const repl = newSVpvs("");
10925
10926         PL_sublex_info.super_bufptr = s;
10927         PL_sublex_info.super_bufend = PL_bufend;
10928         PL_multi_end = 0;
10929         pm->op_pmflags |= PMf_EVAL;
10930         while (es-- > 0)
10931             sv_catpv(repl, (const char *)(es ? "eval " : "do "));
10932         sv_catpvs(repl, "{");
10933         sv_catsv(repl, PL_lex_repl);
10934         if (strchr(SvPVX(PL_lex_repl), '#'))
10935             sv_catpvs(repl, "\n");
10936         sv_catpvs(repl, "}");
10937         SvEVALED_on(repl);
10938         SvREFCNT_dec(PL_lex_repl);
10939         PL_lex_repl = repl;
10940     }
10941
10942     pm->op_pmpermflags = pm->op_pmflags;
10943     PL_lex_op = (OP*)pm;
10944     yylval.ival = OP_SUBST;
10945     return s;
10946 }
10947
10948 STATIC char *
10949 S_scan_trans(pTHX_ char *start)
10950 {
10951     dVAR;
10952     register char* s;
10953     OP *o;
10954     short *tbl;
10955     I32 squash;
10956     I32 del;
10957     I32 complement;
10958 #ifdef PERL_MAD
10959     char *modstart;
10960 #endif
10961
10962     yylval.ival = OP_NULL;
10963
10964     s = scan_str(start,!!PL_madskills,FALSE);
10965     if (!s)
10966         Perl_croak(aTHX_ "Transliteration pattern not terminated");
10967
10968     if (s[-1] == PL_multi_open)
10969         s--;
10970 #ifdef PERL_MAD
10971     if (PL_madskills) {
10972         CURMAD('q', PL_thisopen);
10973         CURMAD('_', PL_thiswhite);
10974         CURMAD('E', PL_thisstuff);
10975         CURMAD('Q', PL_thisclose);
10976         PL_realtokenstart = s - SvPVX(PL_linestr);
10977     }
10978 #endif
10979
10980     s = scan_str(s,!!PL_madskills,FALSE);
10981     if (!s) {
10982         if (PL_lex_stuff) {
10983             SvREFCNT_dec(PL_lex_stuff);
10984             PL_lex_stuff = NULL;
10985         }
10986         Perl_croak(aTHX_ "Transliteration replacement not terminated");
10987     }
10988     if (PL_madskills) {
10989         CURMAD('z', PL_thisopen);
10990         CURMAD('R', PL_thisstuff);
10991         CURMAD('Z', PL_thisclose);
10992     }
10993
10994     complement = del = squash = 0;
10995 #ifdef PERL_MAD
10996     modstart = s;
10997 #endif
10998     while (1) {
10999         switch (*s) {
11000         case 'c':
11001             complement = OPpTRANS_COMPLEMENT;
11002             break;
11003         case 'd':
11004             del = OPpTRANS_DELETE;
11005             break;
11006         case 's':
11007             squash = OPpTRANS_SQUASH;
11008             break;
11009         default:
11010             goto no_more;
11011         }
11012         s++;
11013     }
11014   no_more:
11015
11016     tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
11017     o = newPVOP(OP_TRANS, 0, (char*)tbl);
11018     o->op_private &= ~OPpTRANS_ALL;
11019     o->op_private |= del|squash|complement|
11020       (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
11021       (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF   : 0);
11022
11023     PL_lex_op = o;
11024     yylval.ival = OP_TRANS;
11025
11026 #ifdef PERL_MAD
11027     if (PL_madskills) {
11028         if (modstart != s)
11029             curmad('m', newSVpvn(modstart, s - modstart));
11030         append_madprops(PL_thismad, o, 0);
11031         PL_thismad = 0;
11032     }
11033 #endif
11034
11035     return s;
11036 }
11037
11038 STATIC char *
11039 S_scan_heredoc(pTHX_ register char *s)
11040 {
11041     dVAR;
11042     SV *herewas;
11043     I32 op_type = OP_SCALAR;
11044     I32 len;
11045     SV *tmpstr;
11046     char term;
11047     const char *found_newline;
11048     register char *d;
11049     register char *e;
11050     char *peek;
11051     const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
11052 #ifdef PERL_MAD
11053     I32 stuffstart = s - SvPVX(PL_linestr);
11054     char *tstart;
11055  
11056     PL_realtokenstart = -1;
11057 #endif
11058
11059     s += 2;
11060     d = PL_tokenbuf;
11061     e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
11062     if (!outer)
11063         *d++ = '\n';
11064     peek = s;
11065     while (SPACE_OR_TAB(*peek))
11066         peek++;
11067     if (*peek == '`' || *peek == '\'' || *peek =='"') {
11068         s = peek;
11069         term = *s++;
11070         s = delimcpy(d, e, s, PL_bufend, term, &len);
11071         d += len;
11072         if (s < PL_bufend)
11073             s++;
11074     }
11075     else {
11076         if (*s == '\\')
11077             s++, term = '\'';
11078         else
11079             term = '"';
11080         if (!isALNUM_lazy_if(s,UTF))
11081             deprecate_old("bare << to mean <<\"\"");
11082         for (; isALNUM_lazy_if(s,UTF); s++) {
11083             if (d < e)
11084                 *d++ = *s;
11085         }
11086     }
11087     if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
11088         Perl_croak(aTHX_ "Delimiter for here document is too long");
11089     *d++ = '\n';
11090     *d = '\0';
11091     len = d - PL_tokenbuf;
11092
11093 #ifdef PERL_MAD
11094     if (PL_madskills) {
11095         tstart = PL_tokenbuf + !outer;
11096         PL_thisclose = newSVpvn(tstart, len - !outer);
11097         tstart = SvPVX(PL_linestr) + stuffstart;
11098         PL_thisopen = newSVpvn(tstart, s - tstart);
11099         stuffstart = s - SvPVX(PL_linestr);
11100     }
11101 #endif
11102 #ifndef PERL_STRICT_CR
11103     d = strchr(s, '\r');
11104     if (d) {
11105         char * const olds = s;
11106         s = d;
11107         while (s < PL_bufend) {
11108             if (*s == '\r') {
11109                 *d++ = '\n';
11110                 if (*++s == '\n')
11111                     s++;
11112             }
11113             else if (*s == '\n' && s[1] == '\r') {      /* \015\013 on a mac? */
11114                 *d++ = *s++;
11115                 s++;
11116             }
11117             else
11118                 *d++ = *s++;
11119         }
11120         *d = '\0';
11121         PL_bufend = d;
11122         SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11123         s = olds;
11124     }
11125 #endif
11126 #ifdef PERL_MAD
11127     found_newline = 0;
11128 #endif
11129     if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
11130         herewas = newSVpvn(s,PL_bufend-s);
11131     }
11132     else {
11133 #ifdef PERL_MAD
11134         herewas = newSVpvn(s-1,found_newline-s+1);
11135 #else
11136         s--;
11137         herewas = newSVpvn(s,found_newline-s);
11138 #endif
11139     }
11140 #ifdef PERL_MAD
11141     if (PL_madskills) {
11142         tstart = SvPVX(PL_linestr) + stuffstart;
11143         if (PL_thisstuff)
11144             sv_catpvn(PL_thisstuff, tstart, s - tstart);
11145         else
11146             PL_thisstuff = newSVpvn(tstart, s - tstart);
11147     }
11148 #endif
11149     s += SvCUR(herewas);
11150
11151 #ifdef PERL_MAD
11152     stuffstart = s - SvPVX(PL_linestr);
11153
11154     if (found_newline)
11155         s--;
11156 #endif
11157
11158     tmpstr = newSV_type(SVt_PVIV);
11159     SvGROW(tmpstr, 80);
11160     if (term == '\'') {
11161         op_type = OP_CONST;
11162         SvIV_set(tmpstr, -1);
11163     }
11164     else if (term == '`') {
11165         op_type = OP_BACKTICK;
11166         SvIV_set(tmpstr, '\\');
11167     }
11168
11169     CLINE;
11170     PL_multi_start = CopLINE(PL_curcop);
11171     PL_multi_open = PL_multi_close = '<';
11172     term = *PL_tokenbuf;
11173     if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
11174         char * const bufptr = PL_sublex_info.super_bufptr;
11175         char * const bufend = PL_sublex_info.super_bufend;
11176         char * const olds = s - SvCUR(herewas);
11177         s = strchr(bufptr, '\n');
11178         if (!s)
11179             s = bufend;
11180         d = s;
11181         while (s < bufend &&
11182           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11183             if (*s++ == '\n')
11184                 CopLINE_inc(PL_curcop);
11185         }
11186         if (s >= bufend) {
11187             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11188             missingterm(PL_tokenbuf);
11189         }
11190         sv_setpvn(herewas,bufptr,d-bufptr+1);
11191         sv_setpvn(tmpstr,d+1,s-d);
11192         s += len - 1;
11193         sv_catpvn(herewas,s,bufend-s);
11194         Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
11195
11196         s = olds;
11197         goto retval;
11198     }
11199     else if (!outer) {
11200         d = s;
11201         while (s < PL_bufend &&
11202           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11203             if (*s++ == '\n')
11204                 CopLINE_inc(PL_curcop);
11205         }
11206         if (s >= PL_bufend) {
11207             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11208             missingterm(PL_tokenbuf);
11209         }
11210         sv_setpvn(tmpstr,d+1,s-d);
11211 #ifdef PERL_MAD
11212         if (PL_madskills) {
11213             if (PL_thisstuff)
11214                 sv_catpvn(PL_thisstuff, d + 1, s - d);
11215             else
11216                 PL_thisstuff = newSVpvn(d + 1, s - d);
11217             stuffstart = s - SvPVX(PL_linestr);
11218         }
11219 #endif
11220         s += len - 1;
11221         CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
11222
11223         sv_catpvn(herewas,s,PL_bufend-s);
11224         sv_setsv(PL_linestr,herewas);
11225         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11226         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11227         PL_last_lop = PL_last_uni = NULL;
11228     }
11229     else
11230         sv_setpvn(tmpstr,"",0);   /* avoid "uninitialized" warning */
11231     while (s >= PL_bufend) {    /* multiple line string? */
11232 #ifdef PERL_MAD
11233         if (PL_madskills) {
11234             tstart = SvPVX(PL_linestr) + stuffstart;
11235             if (PL_thisstuff)
11236                 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11237             else
11238                 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11239         }
11240 #endif
11241         if (!outer ||
11242          !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11243             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11244             missingterm(PL_tokenbuf);
11245         }
11246 #ifdef PERL_MAD
11247         stuffstart = s - SvPVX(PL_linestr);
11248 #endif
11249         CopLINE_inc(PL_curcop);
11250         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11251         PL_last_lop = PL_last_uni = NULL;
11252 #ifndef PERL_STRICT_CR
11253         if (PL_bufend - PL_linestart >= 2) {
11254             if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11255                 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
11256             {
11257                 PL_bufend[-2] = '\n';
11258                 PL_bufend--;
11259                 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
11260             }
11261             else if (PL_bufend[-1] == '\r')
11262                 PL_bufend[-1] = '\n';
11263         }
11264         else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11265             PL_bufend[-1] = '\n';
11266 #endif
11267         if (PERLDB_LINE && PL_curstash != PL_debstash)
11268             update_debugger_info(PL_linestr, NULL, 0);
11269         if (*s == term && memEQ(s,PL_tokenbuf,len)) {
11270             STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
11271             *(SvPVX(PL_linestr) + off ) = ' ';
11272             sv_catsv(PL_linestr,herewas);
11273             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11274             s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
11275         }
11276         else {
11277             s = PL_bufend;
11278             sv_catsv(tmpstr,PL_linestr);
11279         }
11280     }
11281     s++;
11282 retval:
11283     PL_multi_end = CopLINE(PL_curcop);
11284     if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
11285         SvPV_shrink_to_cur(tmpstr);
11286     }
11287     SvREFCNT_dec(herewas);
11288     if (!IN_BYTES) {
11289         if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
11290             SvUTF8_on(tmpstr);
11291         else if (PL_encoding)
11292             sv_recode_to_utf8(tmpstr, PL_encoding);
11293     }
11294     PL_lex_stuff = tmpstr;
11295     yylval.ival = op_type;
11296     return s;
11297 }
11298
11299 /* scan_inputsymbol
11300    takes: current position in input buffer
11301    returns: new position in input buffer
11302    side-effects: yylval and lex_op are set.
11303
11304    This code handles:
11305
11306    <>           read from ARGV
11307    <FH>         read from filehandle
11308    <pkg::FH>    read from package qualified filehandle
11309    <pkg'FH>     read from package qualified filehandle
11310    <$fh>        read from filehandle in $fh
11311    <*.h>        filename glob
11312
11313 */
11314
11315 STATIC char *
11316 S_scan_inputsymbol(pTHX_ char *start)
11317 {
11318     dVAR;
11319     register char *s = start;           /* current position in buffer */
11320     char *end;
11321     I32 len;
11322
11323     char *d = PL_tokenbuf;                                      /* start of temp holding space */
11324     const char * const e = PL_tokenbuf + sizeof PL_tokenbuf;    /* end of temp holding space */
11325
11326     end = strchr(s, '\n');
11327     if (!end)
11328         end = PL_bufend;
11329     s = delimcpy(d, e, s + 1, end, '>', &len);  /* extract until > */
11330
11331     /* die if we didn't have space for the contents of the <>,
11332        or if it didn't end, or if we see a newline
11333     */
11334
11335     if (len >= (I32)sizeof PL_tokenbuf)
11336         Perl_croak(aTHX_ "Excessively long <> operator");
11337     if (s >= end)
11338         Perl_croak(aTHX_ "Unterminated <> operator");
11339
11340     s++;
11341
11342     /* check for <$fh>
11343        Remember, only scalar variables are interpreted as filehandles by
11344        this code.  Anything more complex (e.g., <$fh{$num}>) will be
11345        treated as a glob() call.
11346        This code makes use of the fact that except for the $ at the front,
11347        a scalar variable and a filehandle look the same.
11348     */
11349     if (*d == '$' && d[1]) d++;
11350
11351     /* allow <Pkg'VALUE> or <Pkg::VALUE> */
11352     while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
11353         d++;
11354
11355     /* If we've tried to read what we allow filehandles to look like, and
11356        there's still text left, then it must be a glob() and not a getline.
11357        Use scan_str to pull out the stuff between the <> and treat it
11358        as nothing more than a string.
11359     */
11360
11361     if (d - PL_tokenbuf != len) {
11362         yylval.ival = OP_GLOB;
11363         set_csh();
11364         s = scan_str(start,!!PL_madskills,FALSE);
11365         if (!s)
11366            Perl_croak(aTHX_ "Glob not terminated");
11367         return s;
11368     }
11369     else {
11370         bool readline_overriden = FALSE;
11371         GV *gv_readline;
11372         GV **gvp;
11373         /* we're in a filehandle read situation */
11374         d = PL_tokenbuf;
11375
11376         /* turn <> into <ARGV> */
11377         if (!len)
11378             Copy("ARGV",d,5,char);
11379
11380         /* Check whether readline() is overriden */
11381         gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
11382         if ((gv_readline
11383                 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
11384                 ||
11385                 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
11386                  && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
11387                 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
11388             readline_overriden = TRUE;
11389
11390         /* if <$fh>, create the ops to turn the variable into a
11391            filehandle
11392         */
11393         if (*d == '$') {
11394             /* try to find it in the pad for this block, otherwise find
11395                add symbol table ops
11396             */
11397             const PADOFFSET tmp = pad_findmy(d);
11398             if (tmp != NOT_IN_PAD) {
11399                 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
11400                     HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11401                     HEK * const stashname = HvNAME_HEK(stash);
11402                     SV * const sym = sv_2mortal(newSVhek(stashname));
11403                     sv_catpvs(sym, "::");
11404                     sv_catpv(sym, d+1);
11405                     d = SvPVX(sym);
11406                     goto intro_sym;
11407                 }
11408                 else {
11409                     OP * const o = newOP(OP_PADSV, 0);
11410                     o->op_targ = tmp;
11411                     PL_lex_op = readline_overriden
11412                         ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11413                                 append_elem(OP_LIST, o,
11414                                     newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11415                         : (OP*)newUNOP(OP_READLINE, 0, o);
11416                 }
11417             }
11418             else {
11419                 GV *gv;
11420                 ++d;
11421 intro_sym:
11422                 gv = gv_fetchpv(d,
11423                                 (PL_in_eval
11424                                  ? (GV_ADDMULTI | GV_ADDINEVAL)
11425                                  : GV_ADDMULTI),
11426                                 SVt_PV);
11427                 PL_lex_op = readline_overriden
11428                     ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11429                             append_elem(OP_LIST,
11430                                 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11431                                 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11432                     : (OP*)newUNOP(OP_READLINE, 0,
11433                             newUNOP(OP_RV2SV, 0,
11434                                 newGVOP(OP_GV, 0, gv)));
11435             }
11436             if (!readline_overriden)
11437                 PL_lex_op->op_flags |= OPf_SPECIAL;
11438             /* we created the ops in PL_lex_op, so make yylval.ival a null op */
11439             yylval.ival = OP_NULL;
11440         }
11441
11442         /* If it's none of the above, it must be a literal filehandle
11443            (<Foo::BAR> or <FOO>) so build a simple readline OP */
11444         else {
11445             GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
11446             PL_lex_op = readline_overriden
11447                 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11448                         append_elem(OP_LIST,
11449                             newGVOP(OP_GV, 0, gv),
11450                             newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11451                 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
11452             yylval.ival = OP_NULL;
11453         }
11454     }
11455
11456     return s;
11457 }
11458
11459
11460 /* scan_str
11461    takes: start position in buffer
11462           keep_quoted preserve \ on the embedded delimiter(s)
11463           keep_delims preserve the delimiters around the string
11464    returns: position to continue reading from buffer
11465    side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11466         updates the read buffer.
11467
11468    This subroutine pulls a string out of the input.  It is called for:
11469         q               single quotes           q(literal text)
11470         '               single quotes           'literal text'
11471         qq              double quotes           qq(interpolate $here please)
11472         "               double quotes           "interpolate $here please"
11473         qx              backticks               qx(/bin/ls -l)
11474         `               backticks               `/bin/ls -l`
11475         qw              quote words             @EXPORT_OK = qw( func() $spam )
11476         m//             regexp match            m/this/
11477         s///            regexp substitute       s/this/that/
11478         tr///           string transliterate    tr/this/that/
11479         y///            string transliterate    y/this/that/
11480         ($*@)           sub prototypes          sub foo ($)
11481         (stuff)         sub attr parameters     sub foo : attr(stuff)
11482         <>              readline or globs       <FOO>, <>, <$fh>, or <*.c>
11483         
11484    In most of these cases (all but <>, patterns and transliterate)
11485    yylex() calls scan_str().  m// makes yylex() call scan_pat() which
11486    calls scan_str().  s/// makes yylex() call scan_subst() which calls
11487    scan_str().  tr/// and y/// make yylex() call scan_trans() which
11488    calls scan_str().
11489
11490    It skips whitespace before the string starts, and treats the first
11491    character as the delimiter.  If the delimiter is one of ([{< then
11492    the corresponding "close" character )]}> is used as the closing
11493    delimiter.  It allows quoting of delimiters, and if the string has
11494    balanced delimiters ([{<>}]) it allows nesting.
11495
11496    On success, the SV with the resulting string is put into lex_stuff or,
11497    if that is already non-NULL, into lex_repl. The second case occurs only
11498    when parsing the RHS of the special constructs s/// and tr/// (y///).
11499    For convenience, the terminating delimiter character is stuffed into
11500    SvIVX of the SV.
11501 */
11502
11503 STATIC char *
11504 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
11505 {
11506     dVAR;
11507     SV *sv;                             /* scalar value: string */
11508     const char *tmps;                   /* temp string, used for delimiter matching */
11509     register char *s = start;           /* current position in the buffer */
11510     register char term;                 /* terminating character */
11511     register char *to;                  /* current position in the sv's data */
11512     I32 brackets = 1;                   /* bracket nesting level */
11513     bool has_utf8 = FALSE;              /* is there any utf8 content? */
11514     I32 termcode;                       /* terminating char. code */
11515     U8 termstr[UTF8_MAXBYTES];          /* terminating string */
11516     STRLEN termlen;                     /* length of terminating string */
11517     int last_off = 0;                   /* last position for nesting bracket */
11518 #ifdef PERL_MAD
11519     int stuffstart;
11520     char *tstart;
11521 #endif
11522
11523     /* skip space before the delimiter */
11524     if (isSPACE(*s)) {
11525         s = PEEKSPACE(s);
11526     }
11527
11528 #ifdef PERL_MAD
11529     if (PL_realtokenstart >= 0) {
11530         stuffstart = PL_realtokenstart;
11531         PL_realtokenstart = -1;
11532     }
11533     else
11534         stuffstart = start - SvPVX(PL_linestr);
11535 #endif
11536     /* mark where we are, in case we need to report errors */
11537     CLINE;
11538
11539     /* after skipping whitespace, the next character is the terminator */
11540     term = *s;
11541     if (!UTF) {
11542         termcode = termstr[0] = term;
11543         termlen = 1;
11544     }
11545     else {
11546         termcode = utf8_to_uvchr((U8*)s, &termlen);
11547         Copy(s, termstr, termlen, U8);
11548         if (!UTF8_IS_INVARIANT(term))
11549             has_utf8 = TRUE;
11550     }
11551
11552     /* mark where we are */
11553     PL_multi_start = CopLINE(PL_curcop);
11554     PL_multi_open = term;
11555
11556     /* find corresponding closing delimiter */
11557     if (term && (tmps = strchr("([{< )]}> )]}>",term)))
11558         termcode = termstr[0] = term = tmps[5];
11559
11560     PL_multi_close = term;
11561
11562     /* create a new SV to hold the contents.  79 is the SV's initial length.
11563        What a random number. */
11564     sv = newSV_type(SVt_PVIV);
11565     SvGROW(sv, 80);
11566     SvIV_set(sv, termcode);
11567     (void)SvPOK_only(sv);               /* validate pointer */
11568
11569     /* move past delimiter and try to read a complete string */
11570     if (keep_delims)
11571         sv_catpvn(sv, s, termlen);
11572     s += termlen;
11573 #ifdef PERL_MAD
11574     tstart = SvPVX(PL_linestr) + stuffstart;
11575     if (!PL_thisopen && !keep_delims) {
11576         PL_thisopen = newSVpvn(tstart, s - tstart);
11577         stuffstart = s - SvPVX(PL_linestr);
11578     }
11579 #endif
11580     for (;;) {
11581         if (PL_encoding && !UTF) {
11582             bool cont = TRUE;
11583
11584             while (cont) {
11585                 int offset = s - SvPVX_const(PL_linestr);
11586                 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
11587                                            &offset, (char*)termstr, termlen);
11588                 const char * const ns = SvPVX_const(PL_linestr) + offset;
11589                 char * const svlast = SvEND(sv) - 1;
11590
11591                 for (; s < ns; s++) {
11592                     if (*s == '\n' && !PL_rsfp)
11593                         CopLINE_inc(PL_curcop);
11594                 }
11595                 if (!found)
11596                     goto read_more_line;
11597                 else {
11598                     /* handle quoted delimiters */
11599                     if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
11600                         const char *t;
11601                         for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
11602                             t--;
11603                         if ((svlast-1 - t) % 2) {
11604                             if (!keep_quoted) {
11605                                 *(svlast-1) = term;
11606                                 *svlast = '\0';
11607                                 SvCUR_set(sv, SvCUR(sv) - 1);
11608                             }
11609                             continue;
11610                         }
11611                     }
11612                     if (PL_multi_open == PL_multi_close) {
11613                         cont = FALSE;
11614                     }
11615                     else {
11616                         const char *t;
11617                         char *w;
11618                         for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
11619                             /* At here, all closes are "was quoted" one,
11620                                so we don't check PL_multi_close. */
11621                             if (*t == '\\') {
11622                                 if (!keep_quoted && *(t+1) == PL_multi_open)
11623                                     t++;
11624                                 else
11625                                     *w++ = *t++;
11626                             }
11627                             else if (*t == PL_multi_open)
11628                                 brackets++;
11629
11630                             *w = *t;
11631                         }
11632                         if (w < t) {
11633                             *w++ = term;
11634                             *w = '\0';
11635                             SvCUR_set(sv, w - SvPVX_const(sv));
11636                         }
11637                         last_off = w - SvPVX(sv);
11638                         if (--brackets <= 0)
11639                             cont = FALSE;
11640                     }
11641                 }
11642             }
11643             if (!keep_delims) {
11644                 SvCUR_set(sv, SvCUR(sv) - 1);
11645                 *SvEND(sv) = '\0';
11646             }
11647             break;
11648         }
11649
11650         /* extend sv if need be */
11651         SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
11652         /* set 'to' to the next character in the sv's string */
11653         to = SvPVX(sv)+SvCUR(sv);
11654
11655         /* if open delimiter is the close delimiter read unbridle */
11656         if (PL_multi_open == PL_multi_close) {
11657             for (; s < PL_bufend; s++,to++) {
11658                 /* embedded newlines increment the current line number */
11659                 if (*s == '\n' && !PL_rsfp)
11660                     CopLINE_inc(PL_curcop);
11661                 /* handle quoted delimiters */
11662                 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
11663                     if (!keep_quoted && s[1] == term)
11664                         s++;
11665                 /* any other quotes are simply copied straight through */
11666                     else
11667                         *to++ = *s++;
11668                 }
11669                 /* terminate when run out of buffer (the for() condition), or
11670                    have found the terminator */
11671                 else if (*s == term) {
11672                     if (termlen == 1)
11673                         break;
11674                     if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
11675                         break;
11676                 }
11677                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11678                     has_utf8 = TRUE;
11679                 *to = *s;
11680             }
11681         }
11682         
11683         /* if the terminator isn't the same as the start character (e.g.,
11684            matched brackets), we have to allow more in the quoting, and
11685            be prepared for nested brackets.
11686         */
11687         else {
11688             /* read until we run out of string, or we find the terminator */
11689             for (; s < PL_bufend; s++,to++) {
11690                 /* embedded newlines increment the line count */
11691                 if (*s == '\n' && !PL_rsfp)
11692                     CopLINE_inc(PL_curcop);
11693                 /* backslashes can escape the open or closing characters */
11694                 if (*s == '\\' && s+1 < PL_bufend) {
11695                     if (!keep_quoted &&
11696                         ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
11697                         s++;
11698                     else
11699                         *to++ = *s++;
11700                 }
11701                 /* allow nested opens and closes */
11702                 else if (*s == PL_multi_close && --brackets <= 0)
11703                     break;
11704                 else if (*s == PL_multi_open)
11705                     brackets++;
11706                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
11707                     has_utf8 = TRUE;
11708                 *to = *s;
11709             }
11710         }
11711         /* terminate the copied string and update the sv's end-of-string */
11712         *to = '\0';
11713         SvCUR_set(sv, to - SvPVX_const(sv));
11714
11715         /*
11716          * this next chunk reads more into the buffer if we're not done yet
11717          */
11718
11719         if (s < PL_bufend)
11720             break;              /* handle case where we are done yet :-) */
11721
11722 #ifndef PERL_STRICT_CR
11723         if (to - SvPVX_const(sv) >= 2) {
11724             if ((to[-2] == '\r' && to[-1] == '\n') ||
11725                 (to[-2] == '\n' && to[-1] == '\r'))
11726             {
11727                 to[-2] = '\n';
11728                 to--;
11729                 SvCUR_set(sv, to - SvPVX_const(sv));
11730             }
11731             else if (to[-1] == '\r')
11732                 to[-1] = '\n';
11733         }
11734         else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
11735             to[-1] = '\n';
11736 #endif
11737         
11738      read_more_line:
11739         /* if we're out of file, or a read fails, bail and reset the current
11740            line marker so we can report where the unterminated string began
11741         */
11742 #ifdef PERL_MAD
11743         if (PL_madskills) {
11744             char * const tstart = SvPVX(PL_linestr) + stuffstart;
11745             if (PL_thisstuff)
11746                 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
11747             else
11748                 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
11749         }
11750 #endif
11751         if (!PL_rsfp ||
11752          !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = filter_gets(PL_linestr, PL_rsfp, 0))) {
11753             sv_free(sv);
11754             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
11755             return NULL;
11756         }
11757 #ifdef PERL_MAD
11758         stuffstart = 0;
11759 #endif
11760         /* we read a line, so increment our line counter */
11761         CopLINE_inc(PL_curcop);
11762
11763         /* update debugger info */
11764         if (PERLDB_LINE && PL_curstash != PL_debstash)
11765             update_debugger_info(PL_linestr, NULL, 0);
11766
11767         /* having changed the buffer, we must update PL_bufend */
11768         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
11769         PL_last_lop = PL_last_uni = NULL;
11770     }
11771
11772     /* at this point, we have successfully read the delimited string */
11773
11774     if (!PL_encoding || UTF) {
11775 #ifdef PERL_MAD
11776         if (PL_madskills) {
11777             char * const tstart = SvPVX(PL_linestr) + stuffstart;
11778             const int len = s - tstart;
11779             if (PL_thisstuff)
11780                 sv_catpvn(PL_thisstuff, tstart, len);
11781             else
11782                 PL_thisstuff = newSVpvn(tstart, len);
11783             if (!PL_thisclose && !keep_delims)
11784                 PL_thisclose = newSVpvn(s,termlen);
11785         }
11786 #endif
11787
11788         if (keep_delims)
11789             sv_catpvn(sv, s, termlen);
11790         s += termlen;
11791     }
11792 #ifdef PERL_MAD
11793     else {
11794         if (PL_madskills) {
11795             char * const tstart = SvPVX(PL_linestr) + stuffstart;
11796             const int len = s - tstart - termlen;
11797             if (PL_thisstuff)
11798                 sv_catpvn(PL_thisstuff, tstart, len);
11799             else
11800                 PL_thisstuff = newSVpvn(tstart, len);
11801             if (!PL_thisclose && !keep_delims)
11802                 PL_thisclose = newSVpvn(s - termlen,termlen);
11803         }
11804     }
11805 #endif
11806     if (has_utf8 || PL_encoding)
11807         SvUTF8_on(sv);
11808
11809     PL_multi_end = CopLINE(PL_curcop);
11810
11811     /* if we allocated too much space, give some back */
11812     if (SvCUR(sv) + 5 < SvLEN(sv)) {
11813         SvLEN_set(sv, SvCUR(sv) + 1);
11814         SvPV_renew(sv, SvLEN(sv));
11815     }
11816
11817     /* decide whether this is the first or second quoted string we've read
11818        for this op
11819     */
11820
11821     if (PL_lex_stuff)
11822         PL_lex_repl = sv;
11823     else
11824         PL_lex_stuff = sv;
11825     return s;
11826 }
11827
11828 /*
11829   scan_num
11830   takes: pointer to position in buffer
11831   returns: pointer to new position in buffer
11832   side-effects: builds ops for the constant in yylval.op
11833
11834   Read a number in any of the formats that Perl accepts:
11835
11836   \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*)      12 12.34 12.
11837   \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*)                     .34
11838   0b[01](_?[01])*
11839   0[0-7](_?[0-7])*
11840   0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
11841
11842   Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
11843   thing it reads.
11844
11845   If it reads a number without a decimal point or an exponent, it will
11846   try converting the number to an integer and see if it can do so
11847   without loss of precision.
11848 */
11849
11850 char *
11851 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
11852 {
11853     dVAR;
11854     register const char *s = start;     /* current position in buffer */
11855     register char *d;                   /* destination in temp buffer */
11856     register char *e;                   /* end of temp buffer */
11857     NV nv;                              /* number read, as a double */
11858     SV *sv = NULL;                      /* place to put the converted number */
11859     bool floatit;                       /* boolean: int or float? */
11860     const char *lastub = NULL;          /* position of last underbar */
11861     static char const number_too_long[] = "Number too long";
11862
11863     /* We use the first character to decide what type of number this is */
11864
11865     switch (*s) {
11866     default:
11867       Perl_croak(aTHX_ "panic: scan_num");
11868
11869     /* if it starts with a 0, it could be an octal number, a decimal in
11870        0.13 disguise, or a hexadecimal number, or a binary number. */
11871     case '0':
11872         {
11873           /* variables:
11874              u          holds the "number so far"
11875              shift      the power of 2 of the base
11876                         (hex == 4, octal == 3, binary == 1)
11877              overflowed was the number more than we can hold?
11878
11879              Shift is used when we add a digit.  It also serves as an "are
11880              we in octal/hex/binary?" indicator to disallow hex characters
11881              when in octal mode.
11882            */
11883             NV n = 0.0;
11884             UV u = 0;
11885             I32 shift;
11886             bool overflowed = FALSE;
11887             bool just_zero  = TRUE;     /* just plain 0 or binary number? */
11888             static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
11889             static const char* const bases[5] =
11890               { "", "binary", "", "octal", "hexadecimal" };
11891             static const char* const Bases[5] =
11892               { "", "Binary", "", "Octal", "Hexadecimal" };
11893             static const char* const maxima[5] =
11894               { "",
11895                 "0b11111111111111111111111111111111",
11896                 "",
11897                 "037777777777",
11898                 "0xffffffff" };
11899             const char *base, *Base, *max;
11900
11901             /* check for hex */
11902             if (s[1] == 'x') {
11903                 shift = 4;
11904                 s += 2;
11905                 just_zero = FALSE;
11906             } else if (s[1] == 'b') {
11907                 shift = 1;
11908                 s += 2;
11909                 just_zero = FALSE;
11910             }
11911             /* check for a decimal in disguise */
11912             else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
11913                 goto decimal;
11914             /* so it must be octal */
11915             else {
11916                 shift = 3;
11917                 s++;
11918             }
11919
11920             if (*s == '_') {
11921                if (ckWARN(WARN_SYNTAX))
11922                    Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11923                                "Misplaced _ in number");
11924                lastub = s++;
11925             }
11926
11927             base = bases[shift];
11928             Base = Bases[shift];
11929             max  = maxima[shift];
11930
11931             /* read the rest of the number */
11932             for (;;) {
11933                 /* x is used in the overflow test,
11934                    b is the digit we're adding on. */
11935                 UV x, b;
11936
11937                 switch (*s) {
11938
11939                 /* if we don't mention it, we're done */
11940                 default:
11941                     goto out;
11942
11943                 /* _ are ignored -- but warned about if consecutive */
11944                 case '_':
11945                     if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
11946                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11947                                     "Misplaced _ in number");
11948                     lastub = s++;
11949                     break;
11950
11951                 /* 8 and 9 are not octal */
11952                 case '8': case '9':
11953                     if (shift == 3)
11954                         yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
11955                     /* FALL THROUGH */
11956
11957                 /* octal digits */
11958                 case '2': case '3': case '4':
11959                 case '5': case '6': case '7':
11960                     if (shift == 1)
11961                         yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
11962                     /* FALL THROUGH */
11963
11964                 case '0': case '1':
11965                     b = *s++ & 15;              /* ASCII digit -> value of digit */
11966                     goto digit;
11967
11968                 /* hex digits */
11969                 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
11970                 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
11971                     /* make sure they said 0x */
11972                     if (shift != 4)
11973                         goto out;
11974                     b = (*s++ & 7) + 9;
11975
11976                     /* Prepare to put the digit we have onto the end
11977                        of the number so far.  We check for overflows.
11978                     */
11979
11980                   digit:
11981                     just_zero = FALSE;
11982                     if (!overflowed) {
11983                         x = u << shift; /* make room for the digit */
11984
11985                         if ((x >> shift) != u
11986                             && !(PL_hints & HINT_NEW_BINARY)) {
11987                             overflowed = TRUE;
11988                             n = (NV) u;
11989                             if (ckWARN_d(WARN_OVERFLOW))
11990                                 Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
11991                                             "Integer overflow in %s number",
11992                                             base);
11993                         } else
11994                             u = x | b;          /* add the digit to the end */
11995                     }
11996                     if (overflowed) {
11997                         n *= nvshift[shift];
11998                         /* If an NV has not enough bits in its
11999                          * mantissa to represent an UV this summing of
12000                          * small low-order numbers is a waste of time
12001                          * (because the NV cannot preserve the
12002                          * low-order bits anyway): we could just
12003                          * remember when did we overflow and in the
12004                          * end just multiply n by the right
12005                          * amount. */
12006                         n += (NV) b;
12007                     }
12008                     break;
12009                 }
12010             }
12011
12012           /* if we get here, we had success: make a scalar value from
12013              the number.
12014           */
12015           out:
12016
12017             /* final misplaced underbar check */
12018             if (s[-1] == '_') {
12019                 if (ckWARN(WARN_SYNTAX))
12020                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12021             }
12022
12023             sv = newSV(0);
12024             if (overflowed) {
12025                 if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
12026                     Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12027                                 "%s number > %s non-portable",
12028                                 Base, max);
12029                 sv_setnv(sv, n);
12030             }
12031             else {
12032 #if UVSIZE > 4
12033                 if (u > 0xffffffff && ckWARN(WARN_PORTABLE))
12034                     Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
12035                                 "%s number > %s non-portable",
12036                                 Base, max);
12037 #endif
12038                 sv_setuv(sv, u);
12039             }
12040             if (just_zero && (PL_hints & HINT_NEW_INTEGER))
12041                 sv = new_constant(start, s - start, "integer",
12042                                   sv, NULL, NULL);
12043             else if (PL_hints & HINT_NEW_BINARY)
12044                 sv = new_constant(start, s - start, "binary", sv, NULL, NULL);
12045         }
12046         break;
12047
12048     /*
12049       handle decimal numbers.
12050       we're also sent here when we read a 0 as the first digit
12051     */
12052     case '1': case '2': case '3': case '4': case '5':
12053     case '6': case '7': case '8': case '9': case '.':
12054       decimal:
12055         d = PL_tokenbuf;
12056         e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
12057         floatit = FALSE;
12058
12059         /* read next group of digits and _ and copy into d */
12060         while (isDIGIT(*s) || *s == '_') {
12061             /* skip underscores, checking for misplaced ones
12062                if -w is on
12063             */
12064             if (*s == '_') {
12065                 if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12066                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12067                                 "Misplaced _ in number");
12068                 lastub = s++;
12069             }
12070             else {
12071                 /* check for end of fixed-length buffer */
12072                 if (d >= e)
12073                     Perl_croak(aTHX_ number_too_long);
12074                 /* if we're ok, copy the character */
12075                 *d++ = *s++;
12076             }
12077         }
12078
12079         /* final misplaced underbar check */
12080         if (lastub && s == lastub + 1) {
12081             if (ckWARN(WARN_SYNTAX))
12082                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
12083         }
12084
12085         /* read a decimal portion if there is one.  avoid
12086            3..5 being interpreted as the number 3. followed
12087            by .5
12088         */
12089         if (*s == '.' && s[1] != '.') {
12090             floatit = TRUE;
12091             *d++ = *s++;
12092
12093             if (*s == '_') {
12094                 if (ckWARN(WARN_SYNTAX))
12095                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12096                                 "Misplaced _ in number");
12097                 lastub = s;
12098             }
12099
12100             /* copy, ignoring underbars, until we run out of digits.
12101             */
12102             for (; isDIGIT(*s) || *s == '_'; s++) {
12103                 /* fixed length buffer check */
12104                 if (d >= e)
12105                     Perl_croak(aTHX_ number_too_long);
12106                 if (*s == '_') {
12107                    if (lastub && s == lastub + 1 && ckWARN(WARN_SYNTAX))
12108                        Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12109                                    "Misplaced _ in number");
12110                    lastub = s;
12111                 }
12112                 else
12113                     *d++ = *s;
12114             }
12115             /* fractional part ending in underbar? */
12116             if (s[-1] == '_') {
12117                 if (ckWARN(WARN_SYNTAX))
12118                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12119                                 "Misplaced _ in number");
12120             }
12121             if (*s == '.' && isDIGIT(s[1])) {
12122                 /* oops, it's really a v-string, but without the "v" */
12123                 s = start;
12124                 goto vstring;
12125             }
12126         }
12127
12128         /* read exponent part, if present */
12129         if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
12130             floatit = TRUE;
12131             s++;
12132
12133             /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
12134             *d++ = 'e';         /* At least some Mach atof()s don't grok 'E' */
12135
12136             /* stray preinitial _ */
12137             if (*s == '_') {
12138                 if (ckWARN(WARN_SYNTAX))
12139                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12140                                 "Misplaced _ in number");
12141                 lastub = s++;
12142             }
12143
12144             /* allow positive or negative exponent */
12145             if (*s == '+' || *s == '-')
12146                 *d++ = *s++;
12147
12148             /* stray initial _ */
12149             if (*s == '_') {
12150                 if (ckWARN(WARN_SYNTAX))
12151                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12152                                 "Misplaced _ in number");
12153                 lastub = s++;
12154             }
12155
12156             /* read digits of exponent */
12157             while (isDIGIT(*s) || *s == '_') {
12158                 if (isDIGIT(*s)) {
12159                     if (d >= e)
12160                         Perl_croak(aTHX_ number_too_long);
12161                     *d++ = *s++;
12162                 }
12163                 else {
12164                    if (((lastub && s == lastub + 1) ||
12165                         (!isDIGIT(s[1]) && s[1] != '_'))
12166                     && ckWARN(WARN_SYNTAX))
12167                        Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
12168                                    "Misplaced _ in number");
12169                    lastub = s++;
12170                 }
12171             }
12172         }
12173
12174
12175         /* make an sv from the string */
12176         sv = newSV(0);
12177
12178         /*
12179            We try to do an integer conversion first if no characters
12180            indicating "float" have been found.
12181          */
12182
12183         if (!floatit) {
12184             UV uv;
12185             const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
12186
12187             if (flags == IS_NUMBER_IN_UV) {
12188               if (uv <= IV_MAX)
12189                 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
12190               else
12191                 sv_setuv(sv, uv);
12192             } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12193               if (uv <= (UV) IV_MIN)
12194                 sv_setiv(sv, -(IV)uv);
12195               else
12196                 floatit = TRUE;
12197             } else
12198               floatit = TRUE;
12199         }
12200         if (floatit) {
12201             /* terminate the string */
12202             *d = '\0';
12203             nv = Atof(PL_tokenbuf);
12204             sv_setnv(sv, nv);
12205         }
12206
12207         if ( floatit ? (PL_hints & HINT_NEW_FLOAT) :
12208                        (PL_hints & HINT_NEW_INTEGER) )
12209             sv = new_constant(PL_tokenbuf,
12210                               d - PL_tokenbuf,
12211                               (const char *)
12212                               (floatit ? "float" : "integer"),
12213                               sv, NULL, NULL);
12214         break;
12215
12216     /* if it starts with a v, it could be a v-string */
12217     case 'v':
12218 vstring:
12219                 sv = newSV(5); /* preallocate storage space */
12220                 s = scan_vstring(s,sv);
12221         break;
12222     }
12223
12224     /* make the op for the constant and return */
12225
12226     if (sv)
12227         lvalp->opval = newSVOP(OP_CONST, 0, sv);
12228     else
12229         lvalp->opval = NULL;
12230
12231     return (char *)s;
12232 }
12233
12234 STATIC char *
12235 S_scan_formline(pTHX_ register char *s)
12236 {
12237     dVAR;
12238     register char *eol;
12239     register char *t;
12240     SV * const stuff = newSVpvs("");
12241     bool needargs = FALSE;
12242     bool eofmt = FALSE;
12243 #ifdef PERL_MAD
12244     char *tokenstart = s;
12245     SV* savewhite;
12246     
12247     if (PL_madskills) {
12248         savewhite = PL_thiswhite;
12249         PL_thiswhite = 0;
12250     }
12251 #endif
12252
12253     while (!needargs) {
12254         if (*s == '.') {
12255             t = s+1;
12256 #ifdef PERL_STRICT_CR
12257             while (SPACE_OR_TAB(*t))
12258                 t++;
12259 #else
12260             while (SPACE_OR_TAB(*t) || *t == '\r')
12261                 t++;
12262 #endif
12263             if (*t == '\n' || t == PL_bufend) {
12264                 eofmt = TRUE;
12265                 break;
12266             }
12267         }
12268         if (PL_in_eval && !PL_rsfp) {
12269             eol = (char *) memchr(s,'\n',PL_bufend-s);
12270             if (!eol++)
12271                 eol = PL_bufend;
12272         }
12273         else
12274             eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12275         if (*s != '#') {
12276             for (t = s; t < eol; t++) {
12277                 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12278                     needargs = FALSE;
12279                     goto enough;        /* ~~ must be first line in formline */
12280                 }
12281                 if (*t == '@' || *t == '^')
12282                     needargs = TRUE;
12283             }
12284             if (eol > s) {
12285                 sv_catpvn(stuff, s, eol-s);
12286 #ifndef PERL_STRICT_CR
12287                 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12288                     char *end = SvPVX(stuff) + SvCUR(stuff);
12289                     end[-2] = '\n';
12290                     end[-1] = '\0';
12291                     SvCUR_set(stuff, SvCUR(stuff) - 1);
12292                 }
12293 #endif
12294             }
12295             else
12296               break;
12297         }
12298         s = (char*)eol;
12299         if (PL_rsfp) {
12300 #ifdef PERL_MAD
12301             if (PL_madskills) {
12302                 if (PL_thistoken)
12303                     sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
12304                 else
12305                     PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
12306             }
12307 #endif
12308             s = filter_gets(PL_linestr, PL_rsfp, 0);
12309 #ifdef PERL_MAD
12310             tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12311 #else
12312             PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12313 #endif
12314             PL_bufend = PL_bufptr + SvCUR(PL_linestr);
12315             PL_last_lop = PL_last_uni = NULL;
12316             if (!s) {
12317                 s = PL_bufptr;
12318                 break;
12319             }
12320         }
12321         incline(s);
12322     }
12323   enough:
12324     if (SvCUR(stuff)) {
12325         PL_expect = XTERM;
12326         if (needargs) {
12327             PL_lex_state = LEX_NORMAL;
12328             start_force(PL_curforce);
12329             NEXTVAL_NEXTTOKE.ival = 0;
12330             force_next(',');
12331         }
12332         else
12333             PL_lex_state = LEX_FORMLINE;
12334         if (!IN_BYTES) {
12335             if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
12336                 SvUTF8_on(stuff);
12337             else if (PL_encoding)
12338                 sv_recode_to_utf8(stuff, PL_encoding);
12339         }
12340         start_force(PL_curforce);
12341         NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
12342         force_next(THING);
12343         start_force(PL_curforce);
12344         NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
12345         force_next(LSTOP);
12346     }
12347     else {
12348         SvREFCNT_dec(stuff);
12349         if (eofmt)
12350             PL_lex_formbrack = 0;
12351         PL_bufptr = s;
12352     }
12353 #ifdef PERL_MAD
12354     if (PL_madskills) {
12355         if (PL_thistoken)
12356             sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
12357         else
12358             PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12359         PL_thiswhite = savewhite;
12360     }
12361 #endif
12362     return s;
12363 }
12364
12365 STATIC void
12366 S_set_csh(pTHX)
12367 {
12368 #ifdef CSH
12369     dVAR;
12370     if (!PL_cshlen)
12371         PL_cshlen = strlen(PL_cshname);
12372 #else
12373 #if defined(USE_ITHREADS)
12374     PERL_UNUSED_CONTEXT;
12375 #endif
12376 #endif
12377 }
12378
12379 I32
12380 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
12381 {
12382     dVAR;
12383     const I32 oldsavestack_ix = PL_savestack_ix;
12384     CV* const outsidecv = PL_compcv;
12385
12386     if (PL_compcv) {
12387         assert(SvTYPE(PL_compcv) == SVt_PVCV);
12388     }
12389     SAVEI32(PL_subline);
12390     save_item(PL_subname);
12391     SAVESPTR(PL_compcv);
12392
12393     PL_compcv = (CV*)newSV_type(is_format ? SVt_PVFM : SVt_PVCV);
12394     CvFLAGS(PL_compcv) |= flags;
12395
12396     PL_subline = CopLINE(PL_curcop);
12397     CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
12398     CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
12399     CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
12400
12401     return oldsavestack_ix;
12402 }
12403
12404 #ifdef __SC__
12405 #pragma segment Perl_yylex
12406 #endif
12407 int
12408 Perl_yywarn(pTHX_ const char *s)
12409 {
12410     dVAR;
12411     PL_in_eval |= EVAL_WARNONLY;
12412     yyerror(s);
12413     PL_in_eval &= ~EVAL_WARNONLY;
12414     return 0;
12415 }
12416
12417 int
12418 Perl_yyerror(pTHX_ const char *s)
12419 {
12420     dVAR;
12421     const char *where = NULL;
12422     const char *context = NULL;
12423     int contlen = -1;
12424     SV *msg;
12425     int yychar  = PL_parser->yychar;
12426
12427     if (!yychar || (yychar == ';' && !PL_rsfp))
12428         where = "at EOF";
12429     else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12430       PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12431       PL_oldbufptr != PL_bufptr) {
12432         /*
12433                 Only for NetWare:
12434                 The code below is removed for NetWare because it abends/crashes on NetWare
12435                 when the script has error such as not having the closing quotes like:
12436                     if ($var eq "value)
12437                 Checking of white spaces is anyway done in NetWare code.
12438         */
12439 #ifndef NETWARE
12440         while (isSPACE(*PL_oldoldbufptr))
12441             PL_oldoldbufptr++;
12442 #endif
12443         context = PL_oldoldbufptr;
12444         contlen = PL_bufptr - PL_oldoldbufptr;
12445     }
12446     else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12447       PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
12448         /*
12449                 Only for NetWare:
12450                 The code below is removed for NetWare because it abends/crashes on NetWare
12451                 when the script has error such as not having the closing quotes like:
12452                     if ($var eq "value)
12453                 Checking of white spaces is anyway done in NetWare code.
12454         */
12455 #ifndef NETWARE
12456         while (isSPACE(*PL_oldbufptr))
12457             PL_oldbufptr++;
12458 #endif
12459         context = PL_oldbufptr;
12460         contlen = PL_bufptr - PL_oldbufptr;
12461     }
12462     else if (yychar > 255)
12463         where = "next token ???";
12464     else if (yychar == -2) { /* YYEMPTY */
12465         if (PL_lex_state == LEX_NORMAL ||
12466            (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
12467             where = "at end of line";
12468         else if (PL_lex_inpat)
12469             where = "within pattern";
12470         else
12471             where = "within string";
12472     }
12473     else {
12474         SV * const where_sv = sv_2mortal(newSVpvs("next char "));
12475         if (yychar < 32)
12476             Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
12477         else if (isPRINT_LC(yychar))
12478             Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar);
12479         else
12480             Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
12481         where = SvPVX_const(where_sv);
12482     }
12483     msg = sv_2mortal(newSVpv(s, 0));
12484     Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
12485         OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
12486     if (context)
12487         Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
12488     else
12489         Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
12490     if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
12491         Perl_sv_catpvf(aTHX_ msg,
12492         "  (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
12493                 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
12494         PL_multi_end = 0;
12495     }
12496     if (PL_in_eval & EVAL_WARNONLY && ckWARN_d(WARN_SYNTAX))
12497         Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
12498     else
12499         qerror(msg);
12500     if (PL_error_count >= 10) {
12501         if (PL_in_eval && SvCUR(ERRSV))
12502             Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
12503                        SVfARG(ERRSV), OutCopFILE(PL_curcop));
12504         else
12505             Perl_croak(aTHX_ "%s has too many errors.\n",
12506             OutCopFILE(PL_curcop));
12507     }
12508     PL_in_my = 0;
12509     PL_in_my_stash = NULL;
12510     return 0;
12511 }
12512 #ifdef __SC__
12513 #pragma segment Main
12514 #endif
12515
12516 STATIC char*
12517 S_swallow_bom(pTHX_ U8 *s)
12518 {
12519     dVAR;
12520     const STRLEN slen = SvCUR(PL_linestr);
12521     switch (s[0]) {
12522     case 0xFF:
12523         if (s[1] == 0xFE) {
12524             /* UTF-16 little-endian? (or UTF32-LE?) */
12525             if (s[2] == 0 && s[3] == 0)  /* UTF-32 little-endian */
12526                 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
12527 #ifndef PERL_NO_UTF16_FILTER
12528             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
12529             s += 2;
12530         utf16le:
12531             if (PL_bufend > (char*)s) {
12532                 U8 *news;
12533                 I32 newlen;
12534
12535                 filter_add(utf16rev_textfilter, NULL);
12536                 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12537                 utf16_to_utf8_reversed(s, news,
12538                                        PL_bufend - (char*)s - 1,
12539                                        &newlen);
12540                 sv_setpvn(PL_linestr, (const char*)news, newlen);
12541 #ifdef PERL_MAD
12542                 s = (U8*)SvPVX(PL_linestr);
12543                 Copy(news, s, newlen, U8);
12544                 s[newlen] = '\0';
12545 #endif
12546                 Safefree(news);
12547                 SvUTF8_on(PL_linestr);
12548                 s = (U8*)SvPVX(PL_linestr);
12549 #ifdef PERL_MAD
12550                 /* FIXME - is this a general bug fix?  */
12551                 s[newlen] = '\0';
12552 #endif
12553                 PL_bufend = SvPVX(PL_linestr) + newlen;
12554             }
12555 #else
12556             Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
12557 #endif
12558         }
12559         break;
12560     case 0xFE:
12561         if (s[1] == 0xFF) {   /* UTF-16 big-endian? */
12562 #ifndef PERL_NO_UTF16_FILTER
12563             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
12564             s += 2;
12565         utf16be:
12566             if (PL_bufend > (char *)s) {
12567                 U8 *news;
12568                 I32 newlen;
12569
12570                 filter_add(utf16_textfilter, NULL);
12571                 Newx(news, (PL_bufend - (char*)s) * 3 / 2 + 1, U8);
12572                 utf16_to_utf8(s, news,
12573                               PL_bufend - (char*)s,
12574                               &newlen);
12575                 sv_setpvn(PL_linestr, (const char*)news, newlen);
12576                 Safefree(news);
12577                 SvUTF8_on(PL_linestr);
12578                 s = (U8*)SvPVX(PL_linestr);
12579                 PL_bufend = SvPVX(PL_linestr) + newlen;
12580             }
12581 #else
12582             Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
12583 #endif
12584         }
12585         break;
12586     case 0xEF:
12587         if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
12588             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12589             s += 3;                      /* UTF-8 */
12590         }
12591         break;
12592     case 0:
12593         if (slen > 3) {
12594              if (s[1] == 0) {
12595                   if (s[2] == 0xFE && s[3] == 0xFF) {
12596                        /* UTF-32 big-endian */
12597                        Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12598                   }
12599              }
12600              else if (s[2] == 0 && s[3] != 0) {
12601                   /* Leading bytes
12602                    * 00 xx 00 xx
12603                    * are a good indicator of UTF-16BE. */
12604                   if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
12605                   goto utf16be;
12606              }
12607         }
12608 #ifdef EBCDIC
12609     case 0xDD:
12610         if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12611             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12612             s += 4;                      /* UTF-8 */
12613         }
12614         break;
12615 #endif
12616
12617     default:
12618          if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12619                   /* Leading bytes
12620                    * xx 00 xx 00
12621                    * are a good indicator of UTF-16LE. */
12622               if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
12623               goto utf16le;
12624          }
12625     }
12626     return (char*)s;
12627 }
12628
12629 /*
12630  * restore_rsfp
12631  * Restore a source filter.
12632  */
12633
12634 static void
12635 restore_rsfp(pTHX_ void *f)
12636 {
12637     dVAR;
12638     PerlIO * const fp = (PerlIO*)f;
12639
12640     if (PL_rsfp == PerlIO_stdin())
12641         PerlIO_clearerr(PL_rsfp);
12642     else if (PL_rsfp && (PL_rsfp != fp))
12643         PerlIO_close(PL_rsfp);
12644     PL_rsfp = fp;
12645 }
12646
12647 #ifndef PERL_NO_UTF16_FILTER
12648 static I32
12649 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12650 {
12651     dVAR;
12652     const STRLEN old = SvCUR(sv);
12653     const I32 count = FILTER_READ(idx+1, sv, maxlen);
12654     DEBUG_P(PerlIO_printf(Perl_debug_log,
12655                           "utf16_textfilter(%p): %d %d (%d)\n",
12656                           FPTR2DPTR(void *, utf16_textfilter),
12657                           idx, maxlen, (int) count));
12658     if (count) {
12659         U8* tmps;
12660         I32 newlen;
12661         Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12662         Copy(SvPVX_const(sv), tmps, old, char);
12663         utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12664                       SvCUR(sv) - old, &newlen);
12665         sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12666     }
12667     DEBUG_P({sv_dump(sv);});
12668     return SvCUR(sv);
12669 }
12670
12671 static I32
12672 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen)
12673 {
12674     dVAR;
12675     const STRLEN old = SvCUR(sv);
12676     const I32 count = FILTER_READ(idx+1, sv, maxlen);
12677     DEBUG_P(PerlIO_printf(Perl_debug_log,
12678                           "utf16rev_textfilter(%p): %d %d (%d)\n",
12679                           FPTR2DPTR(void *, utf16rev_textfilter),
12680                           idx, maxlen, (int) count));
12681     if (count) {
12682         U8* tmps;
12683         I32 newlen;
12684         Newx(tmps, SvCUR(sv) * 3 / 2 + 1, U8);
12685         Copy(SvPVX_const(sv), tmps, old, char);
12686         utf16_to_utf8((U8*)SvPVX_const(sv) + old, tmps + old,
12687                       SvCUR(sv) - old, &newlen);
12688         sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old);
12689     }
12690     DEBUG_P({ sv_dump(sv); });
12691     return count;
12692 }
12693 #endif
12694
12695 /*
12696 Returns a pointer to the next character after the parsed
12697 vstring, as well as updating the passed in sv.
12698
12699 Function must be called like
12700
12701         sv = newSV(5);
12702         s = scan_vstring(s,sv);
12703
12704 The sv should already be large enough to store the vstring
12705 passed in, for performance reasons.
12706
12707 */
12708
12709 char *
12710 Perl_scan_vstring(pTHX_ const char *s, SV *sv)
12711 {
12712     dVAR;
12713     const char *pos = s;
12714     const char *start = s;
12715     if (*pos == 'v') pos++;  /* get past 'v' */
12716     while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12717         pos++;
12718     if ( *pos != '.') {
12719         /* this may not be a v-string if followed by => */
12720         const char *next = pos;
12721         while (next < PL_bufend && isSPACE(*next))
12722             ++next;
12723         if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
12724             /* return string not v-string */
12725             sv_setpvn(sv,(char *)s,pos-s);
12726             return (char *)pos;
12727         }
12728     }
12729
12730     if (!isALPHA(*pos)) {
12731         U8 tmpbuf[UTF8_MAXBYTES+1];
12732
12733         if (*s == 'v')
12734             s++;  /* get past 'v' */
12735
12736         sv_setpvn(sv, "", 0);
12737
12738         for (;;) {
12739             /* this is atoi() that tolerates underscores */
12740             U8 *tmpend;
12741             UV rev = 0;
12742             const char *end = pos;
12743             UV mult = 1;
12744             while (--end >= s) {
12745                 if (*end != '_') {
12746                     const UV orev = rev;
12747                     rev += (*end - '0') * mult;
12748                     mult *= 10;
12749                     if (orev > rev && ckWARN_d(WARN_OVERFLOW))
12750                         Perl_warner(aTHX_ packWARN(WARN_OVERFLOW),
12751                                     "Integer overflow in decimal number");
12752                 }
12753             }
12754 #ifdef EBCDIC
12755             if (rev > 0x7FFFFFFF)
12756                  Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
12757 #endif
12758             /* Append native character for the rev point */
12759             tmpend = uvchr_to_utf8(tmpbuf, rev);
12760             sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
12761             if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
12762                  SvUTF8_on(sv);
12763             if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
12764                  s = ++pos;
12765             else {
12766                  s = pos;
12767                  break;
12768             }
12769             while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
12770                  pos++;
12771         }
12772         SvPOK_on(sv);
12773         sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
12774         SvRMAGICAL_on(sv);
12775     }
12776     return (char *)s;
12777 }
12778
12779 /*
12780  * Local variables:
12781  * c-indentation-style: bsd
12782  * c-basic-offset: 4
12783  * indent-tabs-mode: t
12784  * End:
12785  *
12786  * ex: set ts=8 sts=4 sw=4 noet:
12787  */