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