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