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