This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.sym: Clarify comment
[perl5.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 /*
25 =head1 Lexer interface
26
27 This is the lower layer of the Perl parser, managing characters and tokens.
28
29 =for apidoc AmU|yy_parser *|PL_parser
30
31 Pointer to a structure encapsulating the state of the parsing operation
32 currently in progress.  The pointer can be locally changed to perform
33 a nested parse without interfering with the state of an outer parse.
34 Individual members of C<PL_parser> have their own documentation.
35
36 =cut
37 */
38
39 #include "EXTERN.h"
40 #define PERL_IN_TOKE_C
41 #include "perl.h"
42 #include "dquote_static.c"
43
44 #define new_constant(a,b,c,d,e,f,g)     \
45         S_new_constant(aTHX_ a,b,STR_WITH_LEN(c),d,e,f, g)
46
47 #define pl_yylval       (PL_parser->yylval)
48
49 /* XXX temporary backwards compatibility */
50 #define PL_lex_brackets         (PL_parser->lex_brackets)
51 #define PL_lex_brackstack       (PL_parser->lex_brackstack)
52 #define PL_lex_casemods         (PL_parser->lex_casemods)
53 #define PL_lex_casestack        (PL_parser->lex_casestack)
54 #define PL_lex_defer            (PL_parser->lex_defer)
55 #define PL_lex_dojoin           (PL_parser->lex_dojoin)
56 #define PL_lex_expect           (PL_parser->lex_expect)
57 #define PL_lex_formbrack        (PL_parser->lex_formbrack)
58 #define PL_lex_inpat            (PL_parser->lex_inpat)
59 #define PL_lex_inwhat           (PL_parser->lex_inwhat)
60 #define PL_lex_op               (PL_parser->lex_op)
61 #define PL_lex_repl             (PL_parser->lex_repl)
62 #define PL_lex_starts           (PL_parser->lex_starts)
63 #define PL_lex_stuff            (PL_parser->lex_stuff)
64 #define PL_multi_start          (PL_parser->multi_start)
65 #define PL_multi_open           (PL_parser->multi_open)
66 #define PL_multi_close          (PL_parser->multi_close)
67 #define PL_pending_ident        (PL_parser->pending_ident)
68 #define PL_preambled            (PL_parser->preambled)
69 #define PL_sublex_info          (PL_parser->sublex_info)
70 #define PL_linestr              (PL_parser->linestr)
71 #define PL_expect               (PL_parser->expect)
72 #define PL_copline              (PL_parser->copline)
73 #define PL_bufptr               (PL_parser->bufptr)
74 #define PL_oldbufptr            (PL_parser->oldbufptr)
75 #define PL_oldoldbufptr         (PL_parser->oldoldbufptr)
76 #define PL_linestart            (PL_parser->linestart)
77 #define PL_bufend               (PL_parser->bufend)
78 #define PL_last_uni             (PL_parser->last_uni)
79 #define PL_last_lop             (PL_parser->last_lop)
80 #define PL_last_lop_op          (PL_parser->last_lop_op)
81 #define PL_lex_state            (PL_parser->lex_state)
82 #define PL_rsfp                 (PL_parser->rsfp)
83 #define PL_rsfp_filters         (PL_parser->rsfp_filters)
84 #define PL_in_my                (PL_parser->in_my)
85 #define PL_in_my_stash          (PL_parser->in_my_stash)
86 #define PL_tokenbuf             (PL_parser->tokenbuf)
87 #define PL_multi_end            (PL_parser->multi_end)
88 #define PL_error_count          (PL_parser->error_count)
89
90 #ifdef PERL_MAD
91 #  define PL_endwhite           (PL_parser->endwhite)
92 #  define PL_faketokens         (PL_parser->faketokens)
93 #  define PL_lasttoke           (PL_parser->lasttoke)
94 #  define PL_nextwhite          (PL_parser->nextwhite)
95 #  define PL_realtokenstart     (PL_parser->realtokenstart)
96 #  define PL_skipwhite          (PL_parser->skipwhite)
97 #  define PL_thisclose          (PL_parser->thisclose)
98 #  define PL_thismad            (PL_parser->thismad)
99 #  define PL_thisopen           (PL_parser->thisopen)
100 #  define PL_thisstuff          (PL_parser->thisstuff)
101 #  define PL_thistoken          (PL_parser->thistoken)
102 #  define PL_thiswhite          (PL_parser->thiswhite)
103 #  define PL_thiswhite          (PL_parser->thiswhite)
104 #  define PL_nexttoke           (PL_parser->nexttoke)
105 #  define PL_curforce           (PL_parser->curforce)
106 #else
107 #  define PL_nexttoke           (PL_parser->nexttoke)
108 #  define PL_nexttype           (PL_parser->nexttype)
109 #  define PL_nextval            (PL_parser->nextval)
110 #endif
111
112 /* This can't be done with embed.fnc, because struct yy_parser contains a
113    member named pending_ident, which clashes with the generated #define  */
114 static int
115 S_pending_ident(pTHX);
116
117 static const char ident_too_long[] = "Identifier too long";
118
119 #ifdef PERL_MAD
120 #  define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
121 #  define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
122 #else
123 #  define CURMAD(slot,sv)
124 #  define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
125 #endif
126
127 #define XENUMMASK  0x3f
128 #define XFAKEEOF   0x40
129 #define XFAKEBRACK 0x80
130
131 #ifdef USE_UTF8_SCRIPTS
132 #   define UTF (!IN_BYTES)
133 #else
134 #   define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
135 #endif
136
137 /* The maximum number of characters preceding the unrecognized one to display */
138 #define UNRECOGNIZED_PRECEDE_COUNT 10
139
140 /* In variables named $^X, these are the legal values for X.
141  * 1999-02-27 mjd-perl-patch@plover.com */
142 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
143
144 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
145
146 /* LEX_* are values for PL_lex_state, the state of the lexer.
147  * They are arranged oddly so that the guard on the switch statement
148  * can get by with a single comparison (if the compiler is smart enough).
149  */
150
151 /* #define LEX_NOTPARSING               11 is done in perl.h. */
152
153 #define LEX_NORMAL              10 /* normal code (ie not within "...")     */
154 #define LEX_INTERPNORMAL         9 /* code within a string, eg "$foo[$x+1]" */
155 #define LEX_INTERPCASEMOD        8 /* expecting a \U, \Q or \E etc          */
156 #define LEX_INTERPPUSH           7 /* starting a new sublex parse level     */
157 #define LEX_INTERPSTART          6 /* expecting the start of a $var         */
158
159                                    /* at end of code, eg "$x" followed by:  */
160 #define LEX_INTERPEND            5 /* ... eg not one of [, { or ->          */
161 #define LEX_INTERPENDMAYBE       4 /* ... eg one of [, { or ->              */
162
163 #define LEX_INTERPCONCAT         3 /* expecting anything, eg at start of
164                                         string or after \E, $foo, etc       */
165 #define LEX_INTERPCONST          2 /* NOT USED */
166 #define LEX_FORMLINE             1 /* expecting a format line               */
167 #define LEX_KNOWNEXT             0 /* next token known; just return it      */
168
169
170 #ifdef DEBUGGING
171 static const char* const lex_state_names[] = {
172     "KNOWNEXT",
173     "FORMLINE",
174     "INTERPCONST",
175     "INTERPCONCAT",
176     "INTERPENDMAYBE",
177     "INTERPEND",
178     "INTERPSTART",
179     "INTERPPUSH",
180     "INTERPCASEMOD",
181     "INTERPNORMAL",
182     "NORMAL"
183 };
184 #endif
185
186 #ifdef ff_next
187 #undef ff_next
188 #endif
189
190 #include "keywords.h"
191
192 /* CLINE is a macro that ensures PL_copline has a sane value */
193
194 #ifdef CLINE
195 #undef CLINE
196 #endif
197 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
198
199 #ifdef PERL_MAD
200 #  define SKIPSPACE0(s) skipspace0(s)
201 #  define SKIPSPACE1(s) skipspace1(s)
202 #  define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
203 #  define PEEKSPACE(s) skipspace2(s,0)
204 #else
205 #  define SKIPSPACE0(s) skipspace(s)
206 #  define SKIPSPACE1(s) skipspace(s)
207 #  define SKIPSPACE2(s,tsv) skipspace(s)
208 #  define PEEKSPACE(s) skipspace(s)
209 #endif
210
211 /*
212  * Convenience functions to return different tokens and prime the
213  * lexer for the next token.  They all take an argument.
214  *
215  * TOKEN        : generic token (used for '(', DOLSHARP, etc)
216  * OPERATOR     : generic operator
217  * AOPERATOR    : assignment operator
218  * PREBLOCK     : beginning the block after an if, while, foreach, ...
219  * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
220  * PREREF       : *EXPR where EXPR is not a simple identifier
221  * TERM         : expression term
222  * LOOPX        : loop exiting command (goto, last, dump, etc)
223  * FTST         : file test operator
224  * FUN0         : zero-argument function
225  * FUN1         : not used, except for not, which isn't a UNIOP
226  * BOop         : bitwise or or xor
227  * BAop         : bitwise and
228  * SHop         : shift operator
229  * PWop         : power operator
230  * PMop         : pattern-matching operator
231  * Aop          : addition-level operator
232  * Mop          : multiplication-level operator
233  * Eop          : equality-testing operator
234  * Rop          : relational operator <= != gt
235  *
236  * Also see LOP and lop() below.
237  */
238
239 #ifdef DEBUGGING /* Serve -DT. */
240 #   define REPORT(retval) tokereport((I32)retval, &pl_yylval)
241 #else
242 #   define REPORT(retval) (retval)
243 #endif
244
245 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
246 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
247 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
248 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
249 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
250 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
251 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
252 #define LOOPX(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
253 #define FTST(f)  return (pl_yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
254 #define FUN0(f)  return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
255 #define FUN1(f)  return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
256 #define BOop(f)  return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
257 #define BAop(f)  return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
258 #define SHop(f)  return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
259 #define PWop(f)  return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
260 #define PMop(f)  return(pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
261 #define Aop(f)   return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
262 #define Mop(f)   return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
263 #define Eop(f)   return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
264 #define Rop(f)   return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
265
266 /* This bit of chicanery makes a unary function followed by
267  * a parenthesis into a function with one argument, highest precedence.
268  * The UNIDOR macro is for unary functions that can be followed by the //
269  * operator (such as C<shift // 0>).
270  */
271 #define UNI2(f,x) { \
272         pl_yylval.ival = f; \
273         PL_expect = x; \
274         PL_bufptr = s; \
275         PL_last_uni = PL_oldbufptr; \
276         PL_last_lop_op = f; \
277         if (*s == '(') \
278             return REPORT( (int)FUNC1 ); \
279         s = PEEKSPACE(s); \
280         return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
281         }
282 #define UNI(f)    UNI2(f,XTERM)
283 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
284
285 #define UNIBRACK(f) { \
286         pl_yylval.ival = f; \
287         PL_bufptr = s; \
288         PL_last_uni = PL_oldbufptr; \
289         if (*s == '(') \
290             return REPORT( (int)FUNC1 ); \
291         s = PEEKSPACE(s); \
292         return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
293         }
294
295 /* grandfather return to old style */
296 #define OLDLOP(f) return(pl_yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
297
298 #ifdef DEBUGGING
299
300 /* how to interpret the pl_yylval associated with the token */
301 enum token_type {
302     TOKENTYPE_NONE,
303     TOKENTYPE_IVAL,
304     TOKENTYPE_OPNUM, /* pl_yylval.ival contains an opcode number */
305     TOKENTYPE_PVAL,
306     TOKENTYPE_OPVAL,
307     TOKENTYPE_GVVAL
308 };
309
310 static struct debug_tokens {
311     const int token;
312     enum token_type type;
313     const char *name;
314 } const debug_tokens[] =
315 {
316     { ADDOP,            TOKENTYPE_OPNUM,        "ADDOP" },
317     { ANDAND,           TOKENTYPE_NONE,         "ANDAND" },
318     { ANDOP,            TOKENTYPE_NONE,         "ANDOP" },
319     { ANONSUB,          TOKENTYPE_IVAL,         "ANONSUB" },
320     { ARROW,            TOKENTYPE_NONE,         "ARROW" },
321     { ASSIGNOP,         TOKENTYPE_OPNUM,        "ASSIGNOP" },
322     { BITANDOP,         TOKENTYPE_OPNUM,        "BITANDOP" },
323     { BITOROP,          TOKENTYPE_OPNUM,        "BITOROP" },
324     { COLONATTR,        TOKENTYPE_NONE,         "COLONATTR" },
325     { CONTINUE,         TOKENTYPE_NONE,         "CONTINUE" },
326     { DEFAULT,          TOKENTYPE_NONE,         "DEFAULT" },
327     { DO,               TOKENTYPE_NONE,         "DO" },
328     { DOLSHARP,         TOKENTYPE_NONE,         "DOLSHARP" },
329     { DORDOR,           TOKENTYPE_NONE,         "DORDOR" },
330     { DOROP,            TOKENTYPE_OPNUM,        "DOROP" },
331     { DOTDOT,           TOKENTYPE_IVAL,         "DOTDOT" },
332     { ELSE,             TOKENTYPE_NONE,         "ELSE" },
333     { ELSIF,            TOKENTYPE_IVAL,         "ELSIF" },
334     { EQOP,             TOKENTYPE_OPNUM,        "EQOP" },
335     { FOR,              TOKENTYPE_IVAL,         "FOR" },
336     { FORMAT,           TOKENTYPE_NONE,         "FORMAT" },
337     { FUNC,             TOKENTYPE_OPNUM,        "FUNC" },
338     { FUNC0,            TOKENTYPE_OPNUM,        "FUNC0" },
339     { FUNC0SUB,         TOKENTYPE_OPVAL,        "FUNC0SUB" },
340     { FUNC1,            TOKENTYPE_OPNUM,        "FUNC1" },
341     { FUNCMETH,         TOKENTYPE_OPVAL,        "FUNCMETH" },
342     { GIVEN,            TOKENTYPE_IVAL,         "GIVEN" },
343     { HASHBRACK,        TOKENTYPE_NONE,         "HASHBRACK" },
344     { IF,               TOKENTYPE_IVAL,         "IF" },
345     { LABEL,            TOKENTYPE_PVAL,         "LABEL" },
346     { LOCAL,            TOKENTYPE_IVAL,         "LOCAL" },
347     { LOOPEX,           TOKENTYPE_OPNUM,        "LOOPEX" },
348     { LSTOP,            TOKENTYPE_OPNUM,        "LSTOP" },
349     { LSTOPSUB,         TOKENTYPE_OPVAL,        "LSTOPSUB" },
350     { MATCHOP,          TOKENTYPE_OPNUM,        "MATCHOP" },
351     { METHOD,           TOKENTYPE_OPVAL,        "METHOD" },
352     { MULOP,            TOKENTYPE_OPNUM,        "MULOP" },
353     { MY,               TOKENTYPE_IVAL,         "MY" },
354     { MYSUB,            TOKENTYPE_NONE,         "MYSUB" },
355     { NOAMP,            TOKENTYPE_NONE,         "NOAMP" },
356     { NOTOP,            TOKENTYPE_NONE,         "NOTOP" },
357     { OROP,             TOKENTYPE_IVAL,         "OROP" },
358     { OROR,             TOKENTYPE_NONE,         "OROR" },
359     { PACKAGE,          TOKENTYPE_NONE,         "PACKAGE" },
360     { PLUGEXPR,         TOKENTYPE_OPVAL,        "PLUGEXPR" },
361     { PLUGSTMT,         TOKENTYPE_OPVAL,        "PLUGSTMT" },
362     { PMFUNC,           TOKENTYPE_OPVAL,        "PMFUNC" },
363     { POSTDEC,          TOKENTYPE_NONE,         "POSTDEC" },
364     { POSTINC,          TOKENTYPE_NONE,         "POSTINC" },
365     { POWOP,            TOKENTYPE_OPNUM,        "POWOP" },
366     { PREDEC,           TOKENTYPE_NONE,         "PREDEC" },
367     { PREINC,           TOKENTYPE_NONE,         "PREINC" },
368     { PRIVATEREF,       TOKENTYPE_OPVAL,        "PRIVATEREF" },
369     { REFGEN,           TOKENTYPE_NONE,         "REFGEN" },
370     { RELOP,            TOKENTYPE_OPNUM,        "RELOP" },
371     { SHIFTOP,          TOKENTYPE_OPNUM,        "SHIFTOP" },
372     { SUB,              TOKENTYPE_NONE,         "SUB" },
373     { THING,            TOKENTYPE_OPVAL,        "THING" },
374     { UMINUS,           TOKENTYPE_NONE,         "UMINUS" },
375     { UNIOP,            TOKENTYPE_OPNUM,        "UNIOP" },
376     { UNIOPSUB,         TOKENTYPE_OPVAL,        "UNIOPSUB" },
377     { UNLESS,           TOKENTYPE_IVAL,         "UNLESS" },
378     { UNTIL,            TOKENTYPE_IVAL,         "UNTIL" },
379     { USE,              TOKENTYPE_IVAL,         "USE" },
380     { WHEN,             TOKENTYPE_IVAL,         "WHEN" },
381     { WHILE,            TOKENTYPE_IVAL,         "WHILE" },
382     { WORD,             TOKENTYPE_OPVAL,        "WORD" },
383     { YADAYADA,         TOKENTYPE_IVAL,         "YADAYADA" },
384     { 0,                TOKENTYPE_NONE,         NULL }
385 };
386
387 /* dump the returned token in rv, plus any optional arg in pl_yylval */
388
389 STATIC int
390 S_tokereport(pTHX_ I32 rv, const YYSTYPE* lvalp)
391 {
392     dVAR;
393
394     PERL_ARGS_ASSERT_TOKEREPORT;
395
396     if (DEBUG_T_TEST) {
397         const char *name = NULL;
398         enum token_type type = TOKENTYPE_NONE;
399         const struct debug_tokens *p;
400         SV* const report = newSVpvs("<== ");
401
402         for (p = debug_tokens; p->token; p++) {
403             if (p->token == (int)rv) {
404                 name = p->name;
405                 type = p->type;
406                 break;
407             }
408         }
409         if (name)
410             Perl_sv_catpv(aTHX_ report, name);
411         else if ((char)rv > ' ' && (char)rv < '~')
412             Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
413         else if (!rv)
414             sv_catpvs(report, "EOF");
415         else
416             Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
417         switch (type) {
418         case TOKENTYPE_NONE:
419         case TOKENTYPE_GVVAL: /* doesn't appear to be used */
420             break;
421         case TOKENTYPE_IVAL:
422             Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)lvalp->ival);
423             break;
424         case TOKENTYPE_OPNUM:
425             Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
426                                     PL_op_name[lvalp->ival]);
427             break;
428         case TOKENTYPE_PVAL:
429             Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", lvalp->pval);
430             break;
431         case TOKENTYPE_OPVAL:
432             if (lvalp->opval) {
433                 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
434                                     PL_op_name[lvalp->opval->op_type]);
435                 if (lvalp->opval->op_type == OP_CONST) {
436                     Perl_sv_catpvf(aTHX_ report, " %s",
437                         SvPEEK(cSVOPx_sv(lvalp->opval)));
438                 }
439
440             }
441             else
442                 sv_catpvs(report, "(opval=null)");
443             break;
444         }
445         PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
446     };
447     return (int)rv;
448 }
449
450
451 /* print the buffer with suitable escapes */
452
453 STATIC void
454 S_printbuf(pTHX_ const char *const fmt, const char *const s)
455 {
456     SV* const tmp = newSVpvs("");
457
458     PERL_ARGS_ASSERT_PRINTBUF;
459
460     PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
461     SvREFCNT_dec(tmp);
462 }
463
464 #endif
465
466 static int
467 S_deprecate_commaless_var_list(pTHX) {
468     PL_expect = XTERM;
469     deprecate("comma-less variable list");
470     return REPORT(','); /* grandfather non-comma-format format */
471 }
472
473 /*
474  * S_ao
475  *
476  * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
477  * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
478  */
479
480 STATIC int
481 S_ao(pTHX_ int toketype)
482 {
483     dVAR;
484     if (*PL_bufptr == '=') {
485         PL_bufptr++;
486         if (toketype == ANDAND)
487             pl_yylval.ival = OP_ANDASSIGN;
488         else if (toketype == OROR)
489             pl_yylval.ival = OP_ORASSIGN;
490         else if (toketype == DORDOR)
491             pl_yylval.ival = OP_DORASSIGN;
492         toketype = ASSIGNOP;
493     }
494     return toketype;
495 }
496
497 /*
498  * S_no_op
499  * When Perl expects an operator and finds something else, no_op
500  * prints the warning.  It always prints "<something> found where
501  * operator expected.  It prints "Missing semicolon on previous line?"
502  * if the surprise occurs at the start of the line.  "do you need to
503  * predeclare ..." is printed out for code like "sub bar; foo bar $x"
504  * where the compiler doesn't know if foo is a method call or a function.
505  * It prints "Missing operator before end of line" if there's nothing
506  * after the missing operator, or "... before <...>" if there is something
507  * after the missing operator.
508  */
509
510 STATIC void
511 S_no_op(pTHX_ const char *const what, char *s)
512 {
513     dVAR;
514     char * const oldbp = PL_bufptr;
515     const bool is_first = (PL_oldbufptr == PL_linestart);
516
517     PERL_ARGS_ASSERT_NO_OP;
518
519     if (!s)
520         s = oldbp;
521     else
522         PL_bufptr = s;
523     yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
524     if (ckWARN_d(WARN_SYNTAX)) {
525         if (is_first)
526             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
527                     "\t(Missing semicolon on previous line?)\n");
528         else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
529             const char *t;
530             for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
531                 NOOP;
532             if (t < PL_bufptr && isSPACE(*t))
533                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
534                         "\t(Do you need to predeclare %.*s?)\n",
535                     (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
536         }
537         else {
538             assert(s >= oldbp);
539             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
540                     "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
541         }
542     }
543     PL_bufptr = oldbp;
544 }
545
546 /*
547  * S_missingterm
548  * Complain about missing quote/regexp/heredoc terminator.
549  * If it's called with NULL then it cauterizes the line buffer.
550  * If we're in a delimited string and the delimiter is a control
551  * character, it's reformatted into a two-char sequence like ^C.
552  * This is fatal.
553  */
554
555 STATIC void
556 S_missingterm(pTHX_ char *s)
557 {
558     dVAR;
559     char tmpbuf[3];
560     char q;
561     if (s) {
562         char * const nl = strrchr(s,'\n');
563         if (nl)
564             *nl = '\0';
565     }
566     else if (isCNTRL(PL_multi_close)) {
567         *tmpbuf = '^';
568         tmpbuf[1] = (char)toCTRL(PL_multi_close);
569         tmpbuf[2] = '\0';
570         s = tmpbuf;
571     }
572     else {
573         *tmpbuf = (char)PL_multi_close;
574         tmpbuf[1] = '\0';
575         s = tmpbuf;
576     }
577     q = strchr(s,'"') ? '\'' : '"';
578     Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
579 }
580
581 #define FEATURE_IS_ENABLED(name)                                        \
582         ((0 != (PL_hints & HINT_LOCALIZE_HH))                           \
583             && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
584 /* The longest string we pass in.  */
585 #define MAX_FEATURE_LEN (sizeof("unicode_strings")-1)
586
587 /*
588  * S_feature_is_enabled
589  * Check whether the named feature is enabled.
590  */
591 STATIC bool
592 S_feature_is_enabled(pTHX_ const char *const name, STRLEN namelen)
593 {
594     dVAR;
595     HV * const hinthv = GvHV(PL_hintgv);
596     char he_name[8 + MAX_FEATURE_LEN] = "feature_";
597
598     PERL_ARGS_ASSERT_FEATURE_IS_ENABLED;
599
600     assert(namelen <= MAX_FEATURE_LEN);
601     memcpy(&he_name[8], name, namelen);
602
603     return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
604 }
605
606 /*
607  * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
608  * utf16-to-utf8-reversed.
609  */
610
611 #ifdef PERL_CR_FILTER
612 static void
613 strip_return(SV *sv)
614 {
615     register const char *s = SvPVX_const(sv);
616     register const char * const e = s + SvCUR(sv);
617
618     PERL_ARGS_ASSERT_STRIP_RETURN;
619
620     /* outer loop optimized to do nothing if there are no CR-LFs */
621     while (s < e) {
622         if (*s++ == '\r' && *s == '\n') {
623             /* hit a CR-LF, need to copy the rest */
624             register char *d = s - 1;
625             *d++ = *s++;
626             while (s < e) {
627                 if (*s == '\r' && s[1] == '\n')
628                     s++;
629                 *d++ = *s++;
630             }
631             SvCUR(sv) -= s - d;
632             return;
633         }
634     }
635 }
636
637 STATIC I32
638 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
639 {
640     const I32 count = FILTER_READ(idx+1, sv, maxlen);
641     if (count > 0 && !maxlen)
642         strip_return(sv);
643     return count;
644 }
645 #endif
646
647 /*
648 =for apidoc Amx|void|lex_start|SV *line|PerlIO *rsfp|U32 flags
649
650 Creates and initialises a new lexer/parser state object, supplying
651 a context in which to lex and parse from a new source of Perl code.
652 A pointer to the new state object is placed in L</PL_parser>.  An entry
653 is made on the save stack so that upon unwinding the new state object
654 will be destroyed and the former value of L</PL_parser> will be restored.
655 Nothing else need be done to clean up the parsing context.
656
657 The code to be parsed comes from I<line> and I<rsfp>.  I<line>, if
658 non-null, provides a string (in SV form) containing code to be parsed.
659 A copy of the string is made, so subsequent modification of I<line>
660 does not affect parsing.  I<rsfp>, if non-null, provides an input stream
661 from which code will be read to be parsed.  If both are non-null, the
662 code in I<line> comes first and must consist of complete lines of input,
663 and I<rsfp> supplies the remainder of the source.
664
665 The I<flags> parameter is reserved for future use, and must always
666 be zero.
667
668 =cut
669 */
670
671 void
672 Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, U32 flags)
673 {
674     dVAR;
675     const char *s = NULL;
676     STRLEN len;
677     yy_parser *parser, *oparser;
678     if (flags)
679         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_start");
680
681     /* create and initialise a parser */
682
683     Newxz(parser, 1, yy_parser);
684     parser->old_parser = oparser = PL_parser;
685     PL_parser = parser;
686
687     parser->stack = NULL;
688     parser->ps = NULL;
689     parser->stack_size = 0;
690
691     /* on scope exit, free this parser and restore any outer one */
692     SAVEPARSER(parser);
693     parser->saved_curcop = PL_curcop;
694
695     /* initialise lexer state */
696
697 #ifdef PERL_MAD
698     parser->curforce = -1;
699 #else
700     parser->nexttoke = 0;
701 #endif
702     parser->error_count = oparser ? oparser->error_count : 0;
703     parser->copline = NOLINE;
704     parser->lex_state = LEX_NORMAL;
705     parser->expect = XSTATE;
706     parser->rsfp = rsfp;
707     parser->rsfp_filters = newAV();
708
709     Newx(parser->lex_brackstack, 120, char);
710     Newx(parser->lex_casestack, 12, char);
711     *parser->lex_casestack = '\0';
712
713     if (line) {
714         s = SvPV_const(line, len);
715     } else {
716         len = 0;
717     }
718
719     if (!len) {
720         parser->linestr = newSVpvs("\n;");
721     } else {
722         parser->linestr = newSVpvn_flags(s, len, SvUTF8(line));
723         if (s[len-1] != ';')
724             sv_catpvs(parser->linestr, "\n;");
725     }
726     parser->oldoldbufptr =
727         parser->oldbufptr =
728         parser->bufptr =
729         parser->linestart = SvPVX(parser->linestr);
730     parser->bufend = parser->bufptr + SvCUR(parser->linestr);
731     parser->last_lop = parser->last_uni = NULL;
732
733     parser->in_pod = 0;
734 }
735
736
737 /* delete a parser object */
738
739 void
740 Perl_parser_free(pTHX_  const yy_parser *parser)
741 {
742     PERL_ARGS_ASSERT_PARSER_FREE;
743
744     PL_curcop = parser->saved_curcop;
745     SvREFCNT_dec(parser->linestr);
746
747     if (parser->rsfp == PerlIO_stdin())
748         PerlIO_clearerr(parser->rsfp);
749     else if (parser->rsfp && (!parser->old_parser ||
750                 (parser->old_parser && parser->rsfp != parser->old_parser->rsfp)))
751         PerlIO_close(parser->rsfp);
752     SvREFCNT_dec(parser->rsfp_filters);
753
754     Safefree(parser->lex_brackstack);
755     Safefree(parser->lex_casestack);
756     PL_parser = parser->old_parser;
757     Safefree(parser);
758 }
759
760
761 /*
762 =for apidoc AmxU|SV *|PL_parser-E<gt>linestr
763
764 Buffer scalar containing the chunk currently under consideration of the
765 text currently being lexed.  This is always a plain string scalar (for
766 which C<SvPOK> is true).  It is not intended to be used as a scalar by
767 normal scalar means; instead refer to the buffer directly by the pointer
768 variables described below.
769
770 The lexer maintains various C<char*> pointers to things in the
771 C<PL_parser-E<gt>linestr> buffer.  If C<PL_parser-E<gt>linestr> is ever
772 reallocated, all of these pointers must be updated.  Don't attempt to
773 do this manually, but rather use L</lex_grow_linestr> if you need to
774 reallocate the buffer.
775
776 The content of the text chunk in the buffer is commonly exactly one
777 complete line of input, up to and including a newline terminator,
778 but there are situations where it is otherwise.  The octets of the
779 buffer may be intended to be interpreted as either UTF-8 or Latin-1.
780 The function L</lex_bufutf8> tells you which.  Do not use the C<SvUTF8>
781 flag on this scalar, which may disagree with it.
782
783 For direct examination of the buffer, the variable
784 L</PL_parser-E<gt>bufend> points to the end of the buffer.  The current
785 lexing position is pointed to by L</PL_parser-E<gt>bufptr>.  Direct use
786 of these pointers is usually preferable to examination of the scalar
787 through normal scalar means.
788
789 =for apidoc AmxU|char *|PL_parser-E<gt>bufend
790
791 Direct pointer to the end of the chunk of text currently being lexed, the
792 end of the lexer buffer.  This is equal to C<SvPVX(PL_parser-E<gt>linestr)
793 + SvCUR(PL_parser-E<gt>linestr)>.  A NUL character (zero octet) is
794 always located at the end of the buffer, and does not count as part of
795 the buffer's contents.
796
797 =for apidoc AmxU|char *|PL_parser-E<gt>bufptr
798
799 Points to the current position of lexing inside the lexer buffer.
800 Characters around this point may be freely examined, within
801 the range delimited by C<SvPVX(L</PL_parser-E<gt>linestr>)> and
802 L</PL_parser-E<gt>bufend>.  The octets of the buffer may be intended to be
803 interpreted as either UTF-8 or Latin-1, as indicated by L</lex_bufutf8>.
804
805 Lexing code (whether in the Perl core or not) moves this pointer past
806 the characters that it consumes.  It is also expected to perform some
807 bookkeeping whenever a newline character is consumed.  This movement
808 can be more conveniently performed by the function L</lex_read_to>,
809 which handles newlines appropriately.
810
811 Interpretation of the buffer's octets can be abstracted out by
812 using the slightly higher-level functions L</lex_peek_unichar> and
813 L</lex_read_unichar>.
814
815 =for apidoc AmxU|char *|PL_parser-E<gt>linestart
816
817 Points to the start of the current line inside the lexer buffer.
818 This is useful for indicating at which column an error occurred, and
819 not much else.  This must be updated by any lexing code that consumes
820 a newline; the function L</lex_read_to> handles this detail.
821
822 =cut
823 */
824
825 /*
826 =for apidoc Amx|bool|lex_bufutf8
827
828 Indicates whether the octets in the lexer buffer
829 (L</PL_parser-E<gt>linestr>) should be interpreted as the UTF-8 encoding
830 of Unicode characters.  If not, they should be interpreted as Latin-1
831 characters.  This is analogous to the C<SvUTF8> flag for scalars.
832
833 In UTF-8 mode, it is not guaranteed that the lexer buffer actually
834 contains valid UTF-8.  Lexing code must be robust in the face of invalid
835 encoding.
836
837 The actual C<SvUTF8> flag of the L</PL_parser-E<gt>linestr> scalar
838 is significant, but not the whole story regarding the input character
839 encoding.  Normally, when a file is being read, the scalar contains octets
840 and its C<SvUTF8> flag is off, but the octets should be interpreted as
841 UTF-8 if the C<use utf8> pragma is in effect.  During a string eval,
842 however, the scalar may have the C<SvUTF8> flag on, and in this case its
843 octets should be interpreted as UTF-8 unless the C<use bytes> pragma
844 is in effect.  This logic may change in the future; use this function
845 instead of implementing the logic yourself.
846
847 =cut
848 */
849
850 bool
851 Perl_lex_bufutf8(pTHX)
852 {
853     return UTF;
854 }
855
856 /*
857 =for apidoc Amx|char *|lex_grow_linestr|STRLEN len
858
859 Reallocates the lexer buffer (L</PL_parser-E<gt>linestr>) to accommodate
860 at least I<len> octets (including terminating NUL).  Returns a
861 pointer to the reallocated buffer.  This is necessary before making
862 any direct modification of the buffer that would increase its length.
863 L</lex_stuff_pvn> provides a more convenient way to insert text into
864 the buffer.
865
866 Do not use C<SvGROW> or C<sv_grow> directly on C<PL_parser-E<gt>linestr>;
867 this function updates all of the lexer's variables that point directly
868 into the buffer.
869
870 =cut
871 */
872
873 char *
874 Perl_lex_grow_linestr(pTHX_ STRLEN len)
875 {
876     SV *linestr;
877     char *buf;
878     STRLEN bufend_pos, bufptr_pos, oldbufptr_pos, oldoldbufptr_pos;
879     STRLEN linestart_pos, last_uni_pos, last_lop_pos;
880     linestr = PL_parser->linestr;
881     buf = SvPVX(linestr);
882     if (len <= SvLEN(linestr))
883         return buf;
884     bufend_pos = PL_parser->bufend - buf;
885     bufptr_pos = PL_parser->bufptr - buf;
886     oldbufptr_pos = PL_parser->oldbufptr - buf;
887     oldoldbufptr_pos = PL_parser->oldoldbufptr - buf;
888     linestart_pos = PL_parser->linestart - buf;
889     last_uni_pos = PL_parser->last_uni ? PL_parser->last_uni - buf : 0;
890     last_lop_pos = PL_parser->last_lop ? PL_parser->last_lop - buf : 0;
891     buf = sv_grow(linestr, len);
892     PL_parser->bufend = buf + bufend_pos;
893     PL_parser->bufptr = buf + bufptr_pos;
894     PL_parser->oldbufptr = buf + oldbufptr_pos;
895     PL_parser->oldoldbufptr = buf + oldoldbufptr_pos;
896     PL_parser->linestart = buf + linestart_pos;
897     if (PL_parser->last_uni)
898         PL_parser->last_uni = buf + last_uni_pos;
899     if (PL_parser->last_lop)
900         PL_parser->last_lop = buf + last_lop_pos;
901     return buf;
902 }
903
904 /*
905 =for apidoc Amx|void|lex_stuff_pvn|const char *pv|STRLEN len|U32 flags
906
907 Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>),
908 immediately after the current lexing point (L</PL_parser-E<gt>bufptr>),
909 reallocating the buffer if necessary.  This means that lexing code that
910 runs later will see the characters as if they had appeared in the input.
911 It is not recommended to do this as part of normal parsing, and most
912 uses of this facility run the risk of the inserted characters being
913 interpreted in an unintended manner.
914
915 The string to be inserted is represented by I<len> octets starting
916 at I<pv>.  These octets are interpreted as either UTF-8 or Latin-1,
917 according to whether the C<LEX_STUFF_UTF8> flag is set in I<flags>.
918 The characters are recoded for the lexer buffer, according to how the
919 buffer is currently being interpreted (L</lex_bufutf8>).  If a string
920 to be inserted is available as a Perl scalar, the L</lex_stuff_sv>
921 function is more convenient.
922
923 =cut
924 */
925
926 void
927 Perl_lex_stuff_pvn(pTHX_ const char *pv, STRLEN len, U32 flags)
928 {
929     dVAR;
930     char *bufptr;
931     PERL_ARGS_ASSERT_LEX_STUFF_PVN;
932     if (flags & ~(LEX_STUFF_UTF8))
933         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_stuff_pvn");
934     if (UTF) {
935         if (flags & LEX_STUFF_UTF8) {
936             goto plain_copy;
937         } else {
938             STRLEN highhalf = 0;
939             const char *p, *e = pv+len;
940             for (p = pv; p != e; p++)
941                 highhalf += !!(((U8)*p) & 0x80);
942             if (!highhalf)
943                 goto plain_copy;
944             lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len+highhalf);
945             bufptr = PL_parser->bufptr;
946             Move(bufptr, bufptr+len+highhalf, PL_parser->bufend+1-bufptr, char);
947             SvCUR_set(PL_parser->linestr,
948                 SvCUR(PL_parser->linestr) + len+highhalf);
949             PL_parser->bufend += len+highhalf;
950             for (p = pv; p != e; p++) {
951                 U8 c = (U8)*p;
952                 if (c & 0x80) {
953                     *bufptr++ = (char)(0xc0 | (c >> 6));
954                     *bufptr++ = (char)(0x80 | (c & 0x3f));
955                 } else {
956                     *bufptr++ = (char)c;
957                 }
958             }
959         }
960     } else {
961         if (flags & LEX_STUFF_UTF8) {
962             STRLEN highhalf = 0;
963             const char *p, *e = pv+len;
964             for (p = pv; p != e; p++) {
965                 U8 c = (U8)*p;
966                 if (c >= 0xc4) {
967                     Perl_croak(aTHX_ "Lexing code attempted to stuff "
968                                 "non-Latin-1 character into Latin-1 input");
969                 } else if (c >= 0xc2 && p+1 != e &&
970                             (((U8)p[1]) & 0xc0) == 0x80) {
971                     p++;
972                     highhalf++;
973                 } else if (c >= 0x80) {
974                     /* malformed UTF-8 */
975                     ENTER;
976                     SAVESPTR(PL_warnhook);
977                     PL_warnhook = PERL_WARNHOOK_FATAL;
978                     utf8n_to_uvuni((U8*)p, e-p, NULL, 0);
979                     LEAVE;
980                 }
981             }
982             if (!highhalf)
983                 goto plain_copy;
984             lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len-highhalf);
985             bufptr = PL_parser->bufptr;
986             Move(bufptr, bufptr+len-highhalf, PL_parser->bufend+1-bufptr, char);
987             SvCUR_set(PL_parser->linestr,
988                 SvCUR(PL_parser->linestr) + len-highhalf);
989             PL_parser->bufend += len-highhalf;
990             for (p = pv; p != e; p++) {
991                 U8 c = (U8)*p;
992                 if (c & 0x80) {
993                     *bufptr++ = (char)(((c & 0x3) << 6) | (p[1] & 0x3f));
994                     p++;
995                 } else {
996                     *bufptr++ = (char)c;
997                 }
998             }
999         } else {
1000             plain_copy:
1001             lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len);
1002             bufptr = PL_parser->bufptr;
1003             Move(bufptr, bufptr+len, PL_parser->bufend+1-bufptr, char);
1004             SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) + len);
1005             PL_parser->bufend += len;
1006             Copy(pv, bufptr, len, char);
1007         }
1008     }
1009 }
1010
1011 /*
1012 =for apidoc Amx|void|lex_stuff_pv|const char *pv|U32 flags
1013
1014 Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>),
1015 immediately after the current lexing point (L</PL_parser-E<gt>bufptr>),
1016 reallocating the buffer if necessary.  This means that lexing code that
1017 runs later will see the characters as if they had appeared in the input.
1018 It is not recommended to do this as part of normal parsing, and most
1019 uses of this facility run the risk of the inserted characters being
1020 interpreted in an unintended manner.
1021
1022 The string to be inserted is represented by octets starting at I<pv>
1023 and continuing to the first nul.  These octets are interpreted as either
1024 UTF-8 or Latin-1, according to whether the C<LEX_STUFF_UTF8> flag is set
1025 in I<flags>.  The characters are recoded for the lexer buffer, according
1026 to how the buffer is currently being interpreted (L</lex_bufutf8>).
1027 If it is not convenient to nul-terminate a string to be inserted, the
1028 L</lex_stuff_pvn> function is more appropriate.
1029
1030 =cut
1031 */
1032
1033 void
1034 Perl_lex_stuff_pv(pTHX_ const char *pv, U32 flags)
1035 {
1036     PERL_ARGS_ASSERT_LEX_STUFF_PV;
1037     lex_stuff_pvn(pv, strlen(pv), flags);
1038 }
1039
1040 /*
1041 =for apidoc Amx|void|lex_stuff_sv|SV *sv|U32 flags
1042
1043 Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>),
1044 immediately after the current lexing point (L</PL_parser-E<gt>bufptr>),
1045 reallocating the buffer if necessary.  This means that lexing code that
1046 runs later will see the characters as if they had appeared in the input.
1047 It is not recommended to do this as part of normal parsing, and most
1048 uses of this facility run the risk of the inserted characters being
1049 interpreted in an unintended manner.
1050
1051 The string to be inserted is the string value of I<sv>.  The characters
1052 are recoded for the lexer buffer, according to how the buffer is currently
1053 being interpreted (L</lex_bufutf8>).  If a string to be inserted is
1054 not already a Perl scalar, the L</lex_stuff_pvn> function avoids the
1055 need to construct a scalar.
1056
1057 =cut
1058 */
1059
1060 void
1061 Perl_lex_stuff_sv(pTHX_ SV *sv, U32 flags)
1062 {
1063     char *pv;
1064     STRLEN len;
1065     PERL_ARGS_ASSERT_LEX_STUFF_SV;
1066     if (flags)
1067         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_stuff_sv");
1068     pv = SvPV(sv, len);
1069     lex_stuff_pvn(pv, len, flags | (SvUTF8(sv) ? LEX_STUFF_UTF8 : 0));
1070 }
1071
1072 /*
1073 =for apidoc Amx|void|lex_unstuff|char *ptr
1074
1075 Discards text about to be lexed, from L</PL_parser-E<gt>bufptr> up to
1076 I<ptr>.  Text following I<ptr> will be moved, and the buffer shortened.
1077 This hides the discarded text from any lexing code that runs later,
1078 as if the text had never appeared.
1079
1080 This is not the normal way to consume lexed text.  For that, use
1081 L</lex_read_to>.
1082
1083 =cut
1084 */
1085
1086 void
1087 Perl_lex_unstuff(pTHX_ char *ptr)
1088 {
1089     char *buf, *bufend;
1090     STRLEN unstuff_len;
1091     PERL_ARGS_ASSERT_LEX_UNSTUFF;
1092     buf = PL_parser->bufptr;
1093     if (ptr < buf)
1094         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_unstuff");
1095     if (ptr == buf)
1096         return;
1097     bufend = PL_parser->bufend;
1098     if (ptr > bufend)
1099         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_unstuff");
1100     unstuff_len = ptr - buf;
1101     Move(ptr, buf, bufend+1-ptr, char);
1102     SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) - unstuff_len);
1103     PL_parser->bufend = bufend - unstuff_len;
1104 }
1105
1106 /*
1107 =for apidoc Amx|void|lex_read_to|char *ptr
1108
1109 Consume text in the lexer buffer, from L</PL_parser-E<gt>bufptr> up
1110 to I<ptr>.  This advances L</PL_parser-E<gt>bufptr> to match I<ptr>,
1111 performing the correct bookkeeping whenever a newline character is passed.
1112 This is the normal way to consume lexed text.
1113
1114 Interpretation of the buffer's octets can be abstracted out by
1115 using the slightly higher-level functions L</lex_peek_unichar> and
1116 L</lex_read_unichar>.
1117
1118 =cut
1119 */
1120
1121 void
1122 Perl_lex_read_to(pTHX_ char *ptr)
1123 {
1124     char *s;
1125     PERL_ARGS_ASSERT_LEX_READ_TO;
1126     s = PL_parser->bufptr;
1127     if (ptr < s || ptr > PL_parser->bufend)
1128         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_to");
1129     for (; s != ptr; s++)
1130         if (*s == '\n') {
1131             CopLINE_inc(PL_curcop);
1132             PL_parser->linestart = s+1;
1133         }
1134     PL_parser->bufptr = ptr;
1135 }
1136
1137 /*
1138 =for apidoc Amx|void|lex_discard_to|char *ptr
1139
1140 Discards the first part of the L</PL_parser-E<gt>linestr> buffer,
1141 up to I<ptr>.  The remaining content of the buffer will be moved, and
1142 all pointers into the buffer updated appropriately.  I<ptr> must not
1143 be later in the buffer than the position of L</PL_parser-E<gt>bufptr>:
1144 it is not permitted to discard text that has yet to be lexed.
1145
1146 Normally it is not necessarily to do this directly, because it suffices to
1147 use the implicit discarding behaviour of L</lex_next_chunk> and things
1148 based on it.  However, if a token stretches across multiple lines,
1149 and the lexing code has kept multiple lines of text in the buffer for
1150 that purpose, then after completion of the token it would be wise to
1151 explicitly discard the now-unneeded earlier lines, to avoid future
1152 multi-line tokens growing the buffer without bound.
1153
1154 =cut
1155 */
1156
1157 void
1158 Perl_lex_discard_to(pTHX_ char *ptr)
1159 {
1160     char *buf;
1161     STRLEN discard_len;
1162     PERL_ARGS_ASSERT_LEX_DISCARD_TO;
1163     buf = SvPVX(PL_parser->linestr);
1164     if (ptr < buf)
1165         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_discard_to");
1166     if (ptr == buf)
1167         return;
1168     if (ptr > PL_parser->bufptr)
1169         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_discard_to");
1170     discard_len = ptr - buf;
1171     if (PL_parser->oldbufptr < ptr)
1172         PL_parser->oldbufptr = ptr;
1173     if (PL_parser->oldoldbufptr < ptr)
1174         PL_parser->oldoldbufptr = ptr;
1175     if (PL_parser->last_uni && PL_parser->last_uni < ptr)
1176         PL_parser->last_uni = NULL;
1177     if (PL_parser->last_lop && PL_parser->last_lop < ptr)
1178         PL_parser->last_lop = NULL;
1179     Move(ptr, buf, PL_parser->bufend+1-ptr, char);
1180     SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) - discard_len);
1181     PL_parser->bufend -= discard_len;
1182     PL_parser->bufptr -= discard_len;
1183     PL_parser->oldbufptr -= discard_len;
1184     PL_parser->oldoldbufptr -= discard_len;
1185     if (PL_parser->last_uni)
1186         PL_parser->last_uni -= discard_len;
1187     if (PL_parser->last_lop)
1188         PL_parser->last_lop -= discard_len;
1189 }
1190
1191 /*
1192 =for apidoc Amx|bool|lex_next_chunk|U32 flags
1193
1194 Reads in the next chunk of text to be lexed, appending it to
1195 L</PL_parser-E<gt>linestr>.  This should be called when lexing code has
1196 looked to the end of the current chunk and wants to know more.  It is
1197 usual, but not necessary, for lexing to have consumed the entirety of
1198 the current chunk at this time.
1199
1200 If L</PL_parser-E<gt>bufptr> is pointing to the very end of the current
1201 chunk (i.e., the current chunk has been entirely consumed), normally the
1202 current chunk will be discarded at the same time that the new chunk is
1203 read in.  If I<flags> includes C<LEX_KEEP_PREVIOUS>, the current chunk
1204 will not be discarded.  If the current chunk has not been entirely
1205 consumed, then it will not be discarded regardless of the flag.
1206
1207 Returns true if some new text was added to the buffer, or false if the
1208 buffer has reached the end of the input text.
1209
1210 =cut
1211 */
1212
1213 #define LEX_FAKE_EOF 0x80000000
1214
1215 bool
1216 Perl_lex_next_chunk(pTHX_ U32 flags)
1217 {
1218     SV *linestr;
1219     char *buf;
1220     STRLEN old_bufend_pos, new_bufend_pos;
1221     STRLEN bufptr_pos, oldbufptr_pos, oldoldbufptr_pos;
1222     STRLEN linestart_pos, last_uni_pos, last_lop_pos;
1223     bool got_some_for_debugger = 0;
1224     bool got_some;
1225     if (flags & ~(LEX_KEEP_PREVIOUS|LEX_FAKE_EOF))
1226         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_next_chunk");
1227     linestr = PL_parser->linestr;
1228     buf = SvPVX(linestr);
1229     if (!(flags & LEX_KEEP_PREVIOUS) &&
1230             PL_parser->bufptr == PL_parser->bufend) {
1231         old_bufend_pos = bufptr_pos = oldbufptr_pos = oldoldbufptr_pos = 0;
1232         linestart_pos = 0;
1233         if (PL_parser->last_uni != PL_parser->bufend)
1234             PL_parser->last_uni = NULL;
1235         if (PL_parser->last_lop != PL_parser->bufend)
1236             PL_parser->last_lop = NULL;
1237         last_uni_pos = last_lop_pos = 0;
1238         *buf = 0;
1239         SvCUR(linestr) = 0;
1240     } else {
1241         old_bufend_pos = PL_parser->bufend - buf;
1242         bufptr_pos = PL_parser->bufptr - buf;
1243         oldbufptr_pos = PL_parser->oldbufptr - buf;
1244         oldoldbufptr_pos = PL_parser->oldoldbufptr - buf;
1245         linestart_pos = PL_parser->linestart - buf;
1246         last_uni_pos = PL_parser->last_uni ? PL_parser->last_uni - buf : 0;
1247         last_lop_pos = PL_parser->last_lop ? PL_parser->last_lop - buf : 0;
1248     }
1249     if (flags & LEX_FAKE_EOF) {
1250         goto eof;
1251     } else if (!PL_parser->rsfp) {
1252         got_some = 0;
1253     } else if (filter_gets(linestr, old_bufend_pos)) {
1254         got_some = 1;
1255         got_some_for_debugger = 1;
1256     } else {
1257         if (!SvPOK(linestr))   /* can get undefined by filter_gets */
1258             sv_setpvs(linestr, "");
1259         eof:
1260         /* End of real input.  Close filehandle (unless it was STDIN),
1261          * then add implicit termination.
1262          */
1263         if ((PerlIO*)PL_parser->rsfp == PerlIO_stdin())
1264             PerlIO_clearerr(PL_parser->rsfp);
1265         else if (PL_parser->rsfp)
1266             (void)PerlIO_close(PL_parser->rsfp);
1267         PL_parser->rsfp = NULL;
1268         PL_parser->in_pod = 0;
1269 #ifdef PERL_MAD
1270         if (PL_madskills && !PL_in_eval && (PL_minus_p || PL_minus_n))
1271             PL_faketokens = 1;
1272 #endif
1273         if (!PL_in_eval && PL_minus_p) {
1274             sv_catpvs(linestr,
1275                 /*{*/";}continue{print or die qq(-p destination: $!\\n);}");
1276             PL_minus_n = PL_minus_p = 0;
1277         } else if (!PL_in_eval && PL_minus_n) {
1278             sv_catpvs(linestr, /*{*/";}");
1279             PL_minus_n = 0;
1280         } else
1281             sv_catpvs(linestr, ";");
1282         got_some = 1;
1283     }
1284     buf = SvPVX(linestr);
1285     new_bufend_pos = SvCUR(linestr);
1286     PL_parser->bufend = buf + new_bufend_pos;
1287     PL_parser->bufptr = buf + bufptr_pos;
1288     PL_parser->oldbufptr = buf + oldbufptr_pos;
1289     PL_parser->oldoldbufptr = buf + oldoldbufptr_pos;
1290     PL_parser->linestart = buf + linestart_pos;
1291     if (PL_parser->last_uni)
1292         PL_parser->last_uni = buf + last_uni_pos;
1293     if (PL_parser->last_lop)
1294         PL_parser->last_lop = buf + last_lop_pos;
1295     if (got_some_for_debugger && (PERLDB_LINE || PERLDB_SAVESRC) &&
1296             PL_curstash != PL_debstash) {
1297         /* debugger active and we're not compiling the debugger code,
1298          * so store the line into the debugger's array of lines
1299          */
1300         update_debugger_info(NULL, buf+old_bufend_pos,
1301             new_bufend_pos-old_bufend_pos);
1302     }
1303     return got_some;
1304 }
1305
1306 /*
1307 =for apidoc Amx|I32|lex_peek_unichar|U32 flags
1308
1309 Looks ahead one (Unicode) character in the text currently being lexed.
1310 Returns the codepoint (unsigned integer value) of the next character,
1311 or -1 if lexing has reached the end of the input text.  To consume the
1312 peeked character, use L</lex_read_unichar>.
1313
1314 If the next character is in (or extends into) the next chunk of input
1315 text, the next chunk will be read in.  Normally the current chunk will be
1316 discarded at the same time, but if I<flags> includes C<LEX_KEEP_PREVIOUS>
1317 then the current chunk will not be discarded.
1318
1319 If the input is being interpreted as UTF-8 and a UTF-8 encoding error
1320 is encountered, an exception is generated.
1321
1322 =cut
1323 */
1324
1325 I32
1326 Perl_lex_peek_unichar(pTHX_ U32 flags)
1327 {
1328     dVAR;
1329     char *s, *bufend;
1330     if (flags & ~(LEX_KEEP_PREVIOUS))
1331         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_peek_unichar");
1332     s = PL_parser->bufptr;
1333     bufend = PL_parser->bufend;
1334     if (UTF) {
1335         U8 head;
1336         I32 unichar;
1337         STRLEN len, retlen;
1338         if (s == bufend) {
1339             if (!lex_next_chunk(flags))
1340                 return -1;
1341             s = PL_parser->bufptr;
1342             bufend = PL_parser->bufend;
1343         }
1344         head = (U8)*s;
1345         if (!(head & 0x80))
1346             return head;
1347         if (head & 0x40) {
1348             len = PL_utf8skip[head];
1349             while ((STRLEN)(bufend-s) < len) {
1350                 if (!lex_next_chunk(flags | LEX_KEEP_PREVIOUS))
1351                     break;
1352                 s = PL_parser->bufptr;
1353                 bufend = PL_parser->bufend;
1354             }
1355         }
1356         unichar = utf8n_to_uvuni((U8*)s, bufend-s, &retlen, UTF8_CHECK_ONLY);
1357         if (retlen == (STRLEN)-1) {
1358             /* malformed UTF-8 */
1359             ENTER;
1360             SAVESPTR(PL_warnhook);
1361             PL_warnhook = PERL_WARNHOOK_FATAL;
1362             utf8n_to_uvuni((U8*)s, bufend-s, NULL, 0);
1363             LEAVE;
1364         }
1365         return unichar;
1366     } else {
1367         if (s == bufend) {
1368             if (!lex_next_chunk(flags))
1369                 return -1;
1370             s = PL_parser->bufptr;
1371         }
1372         return (U8)*s;
1373     }
1374 }
1375
1376 /*
1377 =for apidoc Amx|I32|lex_read_unichar|U32 flags
1378
1379 Reads the next (Unicode) character in the text currently being lexed.
1380 Returns the codepoint (unsigned integer value) of the character read,
1381 and moves L</PL_parser-E<gt>bufptr> past the character, or returns -1
1382 if lexing has reached the end of the input text.  To non-destructively
1383 examine the next character, use L</lex_peek_unichar> instead.
1384
1385 If the next character is in (or extends into) the next chunk of input
1386 text, the next chunk will be read in.  Normally the current chunk will be
1387 discarded at the same time, but if I<flags> includes C<LEX_KEEP_PREVIOUS>
1388 then the current chunk will not be discarded.
1389
1390 If the input is being interpreted as UTF-8 and a UTF-8 encoding error
1391 is encountered, an exception is generated.
1392
1393 =cut
1394 */
1395
1396 I32
1397 Perl_lex_read_unichar(pTHX_ U32 flags)
1398 {
1399     I32 c;
1400     if (flags & ~(LEX_KEEP_PREVIOUS))
1401         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_unichar");
1402     c = lex_peek_unichar(flags);
1403     if (c != -1) {
1404         if (c == '\n')
1405             CopLINE_inc(PL_curcop);
1406         PL_parser->bufptr += UTF8SKIP(PL_parser->bufptr);
1407     }
1408     return c;
1409 }
1410
1411 /*
1412 =for apidoc Amx|void|lex_read_space|U32 flags
1413
1414 Reads optional spaces, in Perl style, in the text currently being
1415 lexed.  The spaces may include ordinary whitespace characters and
1416 Perl-style comments.  C<#line> directives are processed if encountered.
1417 L</PL_parser-E<gt>bufptr> is moved past the spaces, so that it points
1418 at a non-space character (or the end of the input text).
1419
1420 If spaces extend into the next chunk of input text, the next chunk will
1421 be read in.  Normally the current chunk will be discarded at the same
1422 time, but if I<flags> includes C<LEX_KEEP_PREVIOUS> then the current
1423 chunk will not be discarded.
1424
1425 =cut
1426 */
1427
1428 #define LEX_NO_NEXT_CHUNK 0x80000000
1429
1430 void
1431 Perl_lex_read_space(pTHX_ U32 flags)
1432 {
1433     char *s, *bufend;
1434     bool need_incline = 0;
1435     if (flags & ~(LEX_KEEP_PREVIOUS|LEX_NO_NEXT_CHUNK))
1436         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_space");
1437 #ifdef PERL_MAD
1438     if (PL_skipwhite) {
1439         sv_free(PL_skipwhite);
1440         PL_skipwhite = NULL;
1441     }
1442     if (PL_madskills)
1443         PL_skipwhite = newSVpvs("");
1444 #endif /* PERL_MAD */
1445     s = PL_parser->bufptr;
1446     bufend = PL_parser->bufend;
1447     while (1) {
1448         char c = *s;
1449         if (c == '#') {
1450             do {
1451                 c = *++s;
1452             } while (!(c == '\n' || (c == 0 && s == bufend)));
1453         } else if (c == '\n') {
1454             s++;
1455             PL_parser->linestart = s;
1456             if (s == bufend)
1457                 need_incline = 1;
1458             else
1459                 incline(s);
1460         } else if (isSPACE(c)) {
1461             s++;
1462         } else if (c == 0 && s == bufend) {
1463             bool got_more;
1464 #ifdef PERL_MAD
1465             if (PL_madskills)
1466                 sv_catpvn(PL_skipwhite, PL_parser->bufptr, s-PL_parser->bufptr);
1467 #endif /* PERL_MAD */
1468             if (flags & LEX_NO_NEXT_CHUNK)
1469                 break;
1470             PL_parser->bufptr = s;
1471             CopLINE_inc(PL_curcop);
1472             got_more = lex_next_chunk(flags);
1473             CopLINE_dec(PL_curcop);
1474             s = PL_parser->bufptr;
1475             bufend = PL_parser->bufend;
1476             if (!got_more)
1477                 break;
1478             if (need_incline && PL_parser->rsfp) {
1479                 incline(s);
1480                 need_incline = 0;
1481             }
1482         } else {
1483             break;
1484         }
1485     }
1486 #ifdef PERL_MAD
1487     if (PL_madskills)
1488         sv_catpvn(PL_skipwhite, PL_parser->bufptr, s-PL_parser->bufptr);
1489 #endif /* PERL_MAD */
1490     PL_parser->bufptr = s;
1491 }
1492
1493 /*
1494  * S_incline
1495  * This subroutine has nothing to do with tilting, whether at windmills
1496  * or pinball tables.  Its name is short for "increment line".  It
1497  * increments the current line number in CopLINE(PL_curcop) and checks
1498  * to see whether the line starts with a comment of the form
1499  *    # line 500 "foo.pm"
1500  * If so, it sets the current line number and file to the values in the comment.
1501  */
1502
1503 STATIC void
1504 S_incline(pTHX_ const char *s)
1505 {
1506     dVAR;
1507     const char *t;
1508     const char *n;
1509     const char *e;
1510
1511     PERL_ARGS_ASSERT_INCLINE;
1512
1513     CopLINE_inc(PL_curcop);
1514     if (*s++ != '#')
1515         return;
1516     while (SPACE_OR_TAB(*s))
1517         s++;
1518     if (strnEQ(s, "line", 4))
1519         s += 4;
1520     else
1521         return;
1522     if (SPACE_OR_TAB(*s))
1523         s++;
1524     else
1525         return;
1526     while (SPACE_OR_TAB(*s))
1527         s++;
1528     if (!isDIGIT(*s))
1529         return;
1530
1531     n = s;
1532     while (isDIGIT(*s))
1533         s++;
1534     if (!SPACE_OR_TAB(*s) && *s != '\r' && *s != '\n' && *s != '\0')
1535         return;
1536     while (SPACE_OR_TAB(*s))
1537         s++;
1538     if (*s == '"' && (t = strchr(s+1, '"'))) {
1539         s++;
1540         e = t + 1;
1541     }
1542     else {
1543         t = s;
1544         while (!isSPACE(*t))
1545             t++;
1546         e = t;
1547     }
1548     while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
1549         e++;
1550     if (*e != '\n' && *e != '\0')
1551         return;         /* false alarm */
1552
1553     if (t - s > 0) {
1554         const STRLEN len = t - s;
1555 #ifndef USE_ITHREADS
1556         SV *const temp_sv = CopFILESV(PL_curcop);
1557         const char *cf;
1558         STRLEN tmplen;
1559
1560         if (temp_sv) {
1561             cf = SvPVX(temp_sv);
1562             tmplen = SvCUR(temp_sv);
1563         } else {
1564             cf = NULL;
1565             tmplen = 0;
1566         }
1567
1568         if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
1569             /* must copy *{"::_<(eval N)[oldfilename:L]"}
1570              * to *{"::_<newfilename"} */
1571             /* However, the long form of evals is only turned on by the
1572                debugger - usually they're "(eval %lu)" */
1573             char smallbuf[128];
1574             char *tmpbuf;
1575             GV **gvp;
1576             STRLEN tmplen2 = len;
1577             if (tmplen + 2 <= sizeof smallbuf)
1578                 tmpbuf = smallbuf;
1579             else
1580                 Newx(tmpbuf, tmplen + 2, char);
1581             tmpbuf[0] = '_';
1582             tmpbuf[1] = '<';
1583             memcpy(tmpbuf + 2, cf, tmplen);
1584             tmplen += 2;
1585             gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
1586             if (gvp) {
1587                 char *tmpbuf2;
1588                 GV *gv2;
1589
1590                 if (tmplen2 + 2 <= sizeof smallbuf)
1591                     tmpbuf2 = smallbuf;
1592                 else
1593                     Newx(tmpbuf2, tmplen2 + 2, char);
1594
1595                 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
1596                     /* Either they malloc'd it, or we malloc'd it,
1597                        so no prefix is present in ours.  */
1598                     tmpbuf2[0] = '_';
1599                     tmpbuf2[1] = '<';
1600                 }
1601
1602                 memcpy(tmpbuf2 + 2, s, tmplen2);
1603                 tmplen2 += 2;
1604
1605                 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
1606                 if (!isGV(gv2)) {
1607                     gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
1608                     /* adjust ${"::_<newfilename"} to store the new file name */
1609                     GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
1610                     GvHV(gv2) = MUTABLE_HV(SvREFCNT_inc(GvHV(*gvp)));
1611                     GvAV(gv2) = MUTABLE_AV(SvREFCNT_inc(GvAV(*gvp)));
1612                 }
1613
1614                 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
1615             }
1616             if (tmpbuf != smallbuf) Safefree(tmpbuf);
1617         }
1618 #endif
1619         CopFILE_free(PL_curcop);
1620         CopFILE_setn(PL_curcop, s, len);
1621     }
1622     CopLINE_set(PL_curcop, atoi(n)-1);
1623 }
1624
1625 #ifdef PERL_MAD
1626 /* skip space before PL_thistoken */
1627
1628 STATIC char *
1629 S_skipspace0(pTHX_ register char *s)
1630 {
1631     PERL_ARGS_ASSERT_SKIPSPACE0;
1632
1633     s = skipspace(s);
1634     if (!PL_madskills)
1635         return s;
1636     if (PL_skipwhite) {
1637         if (!PL_thiswhite)
1638             PL_thiswhite = newSVpvs("");
1639         sv_catsv(PL_thiswhite, PL_skipwhite);
1640         sv_free(PL_skipwhite);
1641         PL_skipwhite = 0;
1642     }
1643     PL_realtokenstart = s - SvPVX(PL_linestr);
1644     return s;
1645 }
1646
1647 /* skip space after PL_thistoken */
1648
1649 STATIC char *
1650 S_skipspace1(pTHX_ register char *s)
1651 {
1652     const char *start = s;
1653     I32 startoff = start - SvPVX(PL_linestr);
1654
1655     PERL_ARGS_ASSERT_SKIPSPACE1;
1656
1657     s = skipspace(s);
1658     if (!PL_madskills)
1659         return s;
1660     start = SvPVX(PL_linestr) + startoff;
1661     if (!PL_thistoken && PL_realtokenstart >= 0) {
1662         const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
1663         PL_thistoken = newSVpvn(tstart, start - tstart);
1664     }
1665     PL_realtokenstart = -1;
1666     if (PL_skipwhite) {
1667         if (!PL_nextwhite)
1668             PL_nextwhite = newSVpvs("");
1669         sv_catsv(PL_nextwhite, PL_skipwhite);
1670         sv_free(PL_skipwhite);
1671         PL_skipwhite = 0;
1672     }
1673     return s;
1674 }
1675
1676 STATIC char *
1677 S_skipspace2(pTHX_ register char *s, SV **svp)
1678 {
1679     char *start;
1680     const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
1681     const I32 startoff = s - SvPVX(PL_linestr);
1682
1683     PERL_ARGS_ASSERT_SKIPSPACE2;
1684
1685     s = skipspace(s);
1686     PL_bufptr = SvPVX(PL_linestr) + bufptroff;
1687     if (!PL_madskills || !svp)
1688         return s;
1689     start = SvPVX(PL_linestr) + startoff;
1690     if (!PL_thistoken && PL_realtokenstart >= 0) {
1691         char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
1692         PL_thistoken = newSVpvn(tstart, start - tstart);
1693         PL_realtokenstart = -1;
1694     }
1695     if (PL_skipwhite) {
1696         if (!*svp)
1697             *svp = newSVpvs("");
1698         sv_setsv(*svp, PL_skipwhite);
1699         sv_free(PL_skipwhite);
1700         PL_skipwhite = 0;
1701     }
1702     
1703     return s;
1704 }
1705 #endif
1706
1707 STATIC void
1708 S_update_debugger_info(pTHX_ SV *orig_sv, const char *const buf, STRLEN len)
1709 {
1710     AV *av = CopFILEAVx(PL_curcop);
1711     if (av) {
1712         SV * const sv = newSV_type(SVt_PVMG);
1713         if (orig_sv)
1714             sv_setsv(sv, orig_sv);
1715         else
1716             sv_setpvn(sv, buf, len);
1717         (void)SvIOK_on(sv);
1718         SvIV_set(sv, 0);
1719         av_store(av, (I32)CopLINE(PL_curcop), sv);
1720     }
1721 }
1722
1723 /*
1724  * S_skipspace
1725  * Called to gobble the appropriate amount and type of whitespace.
1726  * Skips comments as well.
1727  */
1728
1729 STATIC char *
1730 S_skipspace(pTHX_ register char *s)
1731 {
1732 #ifdef PERL_MAD
1733     char *start = s;
1734 #endif /* PERL_MAD */
1735     PERL_ARGS_ASSERT_SKIPSPACE;
1736 #ifdef PERL_MAD
1737     if (PL_skipwhite) {
1738         sv_free(PL_skipwhite);
1739         PL_skipwhite = NULL;
1740     }
1741 #endif /* PERL_MAD */
1742     if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
1743         while (s < PL_bufend && SPACE_OR_TAB(*s))
1744             s++;
1745     } else {
1746         STRLEN bufptr_pos = PL_bufptr - SvPVX(PL_linestr);
1747         PL_bufptr = s;
1748         lex_read_space(LEX_KEEP_PREVIOUS |
1749                 (PL_sublex_info.sub_inwhat || PL_lex_state == LEX_FORMLINE ?
1750                     LEX_NO_NEXT_CHUNK : 0));
1751         s = PL_bufptr;
1752         PL_bufptr = SvPVX(PL_linestr) + bufptr_pos;
1753         if (PL_linestart > PL_bufptr)
1754             PL_bufptr = PL_linestart;
1755         return s;
1756     }
1757 #ifdef PERL_MAD
1758     if (PL_madskills)
1759         PL_skipwhite = newSVpvn(start, s-start);
1760 #endif /* PERL_MAD */
1761     return s;
1762 }
1763
1764 /*
1765  * S_check_uni
1766  * Check the unary operators to ensure there's no ambiguity in how they're
1767  * used.  An ambiguous piece of code would be:
1768  *     rand + 5
1769  * This doesn't mean rand() + 5.  Because rand() is a unary operator,
1770  * the +5 is its argument.
1771  */
1772
1773 STATIC void
1774 S_check_uni(pTHX)
1775 {
1776     dVAR;
1777     const char *s;
1778     const char *t;
1779
1780     if (PL_oldoldbufptr != PL_last_uni)
1781         return;
1782     while (isSPACE(*PL_last_uni))
1783         PL_last_uni++;
1784     s = PL_last_uni;
1785     while (isALNUM_lazy_if(s,UTF) || *s == '-')
1786         s++;
1787     if ((t = strchr(s, '(')) && t < PL_bufptr)
1788         return;
1789
1790     Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
1791                      "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1792                      (int)(s - PL_last_uni), PL_last_uni);
1793 }
1794
1795 /*
1796  * LOP : macro to build a list operator.  Its behaviour has been replaced
1797  * with a subroutine, S_lop() for which LOP is just another name.
1798  */
1799
1800 #define LOP(f,x) return lop(f,x,s)
1801
1802 /*
1803  * S_lop
1804  * Build a list operator (or something that might be one).  The rules:
1805  *  - if we have a next token, then it's a list operator [why?]
1806  *  - if the next thing is an opening paren, then it's a function
1807  *  - else it's a list operator
1808  */
1809
1810 STATIC I32
1811 S_lop(pTHX_ I32 f, int x, char *s)
1812 {
1813     dVAR;
1814
1815     PERL_ARGS_ASSERT_LOP;
1816
1817     pl_yylval.ival = f;
1818     CLINE;
1819     PL_expect = x;
1820     PL_bufptr = s;
1821     PL_last_lop = PL_oldbufptr;
1822     PL_last_lop_op = (OPCODE)f;
1823 #ifdef PERL_MAD
1824     if (PL_lasttoke)
1825         return REPORT(LSTOP);
1826 #else
1827     if (PL_nexttoke)
1828         return REPORT(LSTOP);
1829 #endif
1830     if (*s == '(')
1831         return REPORT(FUNC);
1832     s = PEEKSPACE(s);
1833     if (*s == '(')
1834         return REPORT(FUNC);
1835     else
1836         return REPORT(LSTOP);
1837 }
1838
1839 #ifdef PERL_MAD
1840  /*
1841  * S_start_force
1842  * Sets up for an eventual force_next().  start_force(0) basically does
1843  * an unshift, while start_force(-1) does a push.  yylex removes items
1844  * on the "pop" end.
1845  */
1846
1847 STATIC void
1848 S_start_force(pTHX_ int where)
1849 {
1850     int i;
1851
1852     if (where < 0)      /* so people can duplicate start_force(PL_curforce) */
1853         where = PL_lasttoke;
1854     assert(PL_curforce < 0 || PL_curforce == where);
1855     if (PL_curforce != where) {
1856         for (i = PL_lasttoke; i > where; --i) {
1857             PL_nexttoke[i] = PL_nexttoke[i-1];
1858         }
1859         PL_lasttoke++;
1860     }
1861     if (PL_curforce < 0)        /* in case of duplicate start_force() */
1862         Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1863     PL_curforce = where;
1864     if (PL_nextwhite) {
1865         if (PL_madskills)
1866             curmad('^', newSVpvs(""));
1867         CURMAD('_', PL_nextwhite);
1868     }
1869 }
1870
1871 STATIC void
1872 S_curmad(pTHX_ char slot, SV *sv)
1873 {
1874     MADPROP **where;
1875
1876     if (!sv)
1877         return;
1878     if (PL_curforce < 0)
1879         where = &PL_thismad;
1880     else
1881         where = &PL_nexttoke[PL_curforce].next_mad;
1882
1883     if (PL_faketokens)
1884         sv_setpvs(sv, "");
1885     else {
1886         if (!IN_BYTES) {
1887             if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1888                 SvUTF8_on(sv);
1889             else if (PL_encoding) {
1890                 sv_recode_to_utf8(sv, PL_encoding);
1891             }
1892         }
1893     }
1894
1895     /* keep a slot open for the head of the list? */
1896     if (slot != '_' && *where && (*where)->mad_key == '^') {
1897         (*where)->mad_key = slot;
1898         sv_free(MUTABLE_SV(((*where)->mad_val)));
1899         (*where)->mad_val = (void*)sv;
1900     }
1901     else
1902         addmad(newMADsv(slot, sv), where, 0);
1903 }
1904 #else
1905 #  define start_force(where)    NOOP
1906 #  define curmad(slot, sv)      NOOP
1907 #endif
1908
1909 /*
1910  * S_force_next
1911  * When the lexer realizes it knows the next token (for instance,
1912  * it is reordering tokens for the parser) then it can call S_force_next
1913  * to know what token to return the next time the lexer is called.  Caller
1914  * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1915  * and possibly PL_expect to ensure the lexer handles the token correctly.
1916  */
1917
1918 STATIC void
1919 S_force_next(pTHX_ I32 type)
1920 {
1921     dVAR;
1922 #ifdef DEBUGGING
1923     if (DEBUG_T_TEST) {
1924         PerlIO_printf(Perl_debug_log, "### forced token:\n");
1925         tokereport(type, &NEXTVAL_NEXTTOKE);
1926     }
1927 #endif
1928 #ifdef PERL_MAD
1929     if (PL_curforce < 0)
1930         start_force(PL_lasttoke);
1931     PL_nexttoke[PL_curforce].next_type = type;
1932     if (PL_lex_state != LEX_KNOWNEXT)
1933         PL_lex_defer = PL_lex_state;
1934     PL_lex_state = LEX_KNOWNEXT;
1935     PL_lex_expect = PL_expect;
1936     PL_curforce = -1;
1937 #else
1938     PL_nexttype[PL_nexttoke] = type;
1939     PL_nexttoke++;
1940     if (PL_lex_state != LEX_KNOWNEXT) {
1941         PL_lex_defer = PL_lex_state;
1942         PL_lex_expect = PL_expect;
1943         PL_lex_state = LEX_KNOWNEXT;
1944     }
1945 #endif
1946 }
1947
1948 void
1949 Perl_yyunlex(pTHX)
1950 {
1951     int yyc = PL_parser->yychar;
1952     if (yyc != YYEMPTY) {
1953         if (yyc) {
1954             start_force(-1);
1955             NEXTVAL_NEXTTOKE = PL_parser->yylval;
1956             if (yyc == '{'/*}*/ || yyc == HASHBRACK || yyc == '['/*]*/) {
1957                 PL_lex_brackets--;
1958                 yyc |= (1<<24) | (PL_lex_brackstack[PL_lex_brackets] << 16);
1959             }
1960             force_next(yyc);
1961         }
1962         PL_parser->yychar = YYEMPTY;
1963     }
1964 }
1965
1966 STATIC SV *
1967 S_newSV_maybe_utf8(pTHX_ const char *const start, STRLEN len)
1968 {
1969     dVAR;
1970     SV * const sv = newSVpvn_utf8(start, len,
1971                                   !IN_BYTES
1972                                   && UTF
1973                                   && !is_ascii_string((const U8*)start, len)
1974                                   && is_utf8_string((const U8*)start, len));
1975     return sv;
1976 }
1977
1978 /*
1979  * S_force_word
1980  * When the lexer knows the next thing is a word (for instance, it has
1981  * just seen -> and it knows that the next char is a word char, then
1982  * it calls S_force_word to stick the next word into the PL_nexttoke/val
1983  * lookahead.
1984  *
1985  * Arguments:
1986  *   char *start : buffer position (must be within PL_linestr)
1987  *   int token   : PL_next* will be this type of bare word (e.g., METHOD,WORD)
1988  *   int check_keyword : if true, Perl checks to make sure the word isn't
1989  *       a keyword (do this if the word is a label, e.g. goto FOO)
1990  *   int allow_pack : if true, : characters will also be allowed (require,
1991  *       use, etc. do this)
1992  *   int allow_initial_tick : used by the "sub" lexer only.
1993  */
1994
1995 STATIC char *
1996 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1997 {
1998     dVAR;
1999     register char *s;
2000     STRLEN len;
2001
2002     PERL_ARGS_ASSERT_FORCE_WORD;
2003
2004     start = SKIPSPACE1(start);
2005     s = start;
2006     if (isIDFIRST_lazy_if(s,UTF) ||
2007         (allow_pack && *s == ':') ||
2008         (allow_initial_tick && *s == '\'') )
2009     {
2010         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
2011         if (check_keyword && keyword(PL_tokenbuf, len, 0))
2012             return start;
2013         start_force(PL_curforce);
2014         if (PL_madskills)
2015             curmad('X', newSVpvn(start,s-start));
2016         if (token == METHOD) {
2017             s = SKIPSPACE1(s);
2018             if (*s == '(')
2019                 PL_expect = XTERM;
2020             else {
2021                 PL_expect = XOPERATOR;
2022             }
2023         }
2024         if (PL_madskills)
2025             curmad('g', newSVpvs( "forced" ));
2026         NEXTVAL_NEXTTOKE.opval
2027             = (OP*)newSVOP(OP_CONST,0,
2028                            S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
2029         NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
2030         force_next(token);
2031     }
2032     return s;
2033 }
2034
2035 /*
2036  * S_force_ident
2037  * Called when the lexer wants $foo *foo &foo etc, but the program
2038  * text only contains the "foo" portion.  The first argument is a pointer
2039  * to the "foo", and the second argument is the type symbol to prefix.
2040  * Forces the next token to be a "WORD".
2041  * Creates the symbol if it didn't already exist (via gv_fetchpv()).
2042  */
2043
2044 STATIC void
2045 S_force_ident(pTHX_ register const char *s, int kind)
2046 {
2047     dVAR;
2048
2049     PERL_ARGS_ASSERT_FORCE_IDENT;
2050
2051     if (*s) {
2052         const STRLEN len = strlen(s);
2053         OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
2054         start_force(PL_curforce);
2055         NEXTVAL_NEXTTOKE.opval = o;
2056         force_next(WORD);
2057         if (kind) {
2058             o->op_private = OPpCONST_ENTERED;
2059             /* XXX see note in pp_entereval() for why we forgo typo
2060                warnings if the symbol must be introduced in an eval.
2061                GSAR 96-10-12 */
2062             gv_fetchpvn_flags(s, len,
2063                               PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
2064                               : GV_ADD,
2065                               kind == '$' ? SVt_PV :
2066                               kind == '@' ? SVt_PVAV :
2067                               kind == '%' ? SVt_PVHV :
2068                               SVt_PVGV
2069                               );
2070         }
2071     }
2072 }
2073
2074 NV
2075 Perl_str_to_version(pTHX_ SV *sv)
2076 {
2077     NV retval = 0.0;
2078     NV nshift = 1.0;
2079     STRLEN len;
2080     const char *start = SvPV_const(sv,len);
2081     const char * const end = start + len;
2082     const bool utf = SvUTF8(sv) ? TRUE : FALSE;
2083
2084     PERL_ARGS_ASSERT_STR_TO_VERSION;
2085
2086     while (start < end) {
2087         STRLEN skip;
2088         UV n;
2089         if (utf)
2090             n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
2091         else {
2092             n = *(U8*)start;
2093             skip = 1;
2094         }
2095         retval += ((NV)n)/nshift;
2096         start += skip;
2097         nshift *= 1000;
2098     }
2099     return retval;
2100 }
2101
2102 /*
2103  * S_force_version
2104  * Forces the next token to be a version number.
2105  * If the next token appears to be an invalid version number, (e.g. "v2b"),
2106  * and if "guessing" is TRUE, then no new token is created (and the caller
2107  * must use an alternative parsing method).
2108  */
2109
2110 STATIC char *
2111 S_force_version(pTHX_ char *s, int guessing)
2112 {
2113     dVAR;
2114     OP *version = NULL;
2115     char *d;
2116 #ifdef PERL_MAD
2117     I32 startoff = s - SvPVX(PL_linestr);
2118 #endif
2119
2120     PERL_ARGS_ASSERT_FORCE_VERSION;
2121
2122     s = SKIPSPACE1(s);
2123
2124     d = s;
2125     if (*d == 'v')
2126         d++;
2127     if (isDIGIT(*d)) {
2128         while (isDIGIT(*d) || *d == '_' || *d == '.')
2129             d++;
2130 #ifdef PERL_MAD
2131         if (PL_madskills) {
2132             start_force(PL_curforce);
2133             curmad('X', newSVpvn(s,d-s));
2134         }
2135 #endif
2136         if (*d == ';' || isSPACE(*d) || *d == '{' || *d == '}' || !*d) {
2137             SV *ver;
2138 #ifdef USE_LOCALE_NUMERIC
2139             char *loc = setlocale(LC_NUMERIC, "C");
2140 #endif
2141             s = scan_num(s, &pl_yylval);
2142 #ifdef USE_LOCALE_NUMERIC
2143             setlocale(LC_NUMERIC, loc);
2144 #endif
2145             version = pl_yylval.opval;
2146             ver = cSVOPx(version)->op_sv;
2147             if (SvPOK(ver) && !SvNIOK(ver)) {
2148                 SvUPGRADE(ver, SVt_PVNV);
2149                 SvNV_set(ver, str_to_version(ver));
2150                 SvNOK_on(ver);          /* hint that it is a version */
2151             }
2152         }
2153         else if (guessing) {
2154 #ifdef PERL_MAD
2155             if (PL_madskills) {
2156                 sv_free(PL_nextwhite);  /* let next token collect whitespace */
2157                 PL_nextwhite = 0;
2158                 s = SvPVX(PL_linestr) + startoff;
2159             }
2160 #endif
2161             return s;
2162         }
2163     }
2164
2165 #ifdef PERL_MAD
2166     if (PL_madskills && !version) {
2167         sv_free(PL_nextwhite);  /* let next token collect whitespace */
2168         PL_nextwhite = 0;
2169         s = SvPVX(PL_linestr) + startoff;
2170     }
2171 #endif
2172     /* NOTE: The parser sees the package name and the VERSION swapped */
2173     start_force(PL_curforce);
2174     NEXTVAL_NEXTTOKE.opval = version;
2175     force_next(WORD);
2176
2177     return s;
2178 }
2179
2180 /*
2181  * S_force_strict_version
2182  * Forces the next token to be a version number using strict syntax rules.
2183  */
2184
2185 STATIC char *
2186 S_force_strict_version(pTHX_ char *s)
2187 {
2188     dVAR;
2189     OP *version = NULL;
2190 #ifdef PERL_MAD
2191     I32 startoff = s - SvPVX(PL_linestr);
2192 #endif
2193     const char *errstr = NULL;
2194
2195     PERL_ARGS_ASSERT_FORCE_STRICT_VERSION;
2196
2197     while (isSPACE(*s)) /* leading whitespace */
2198         s++;
2199
2200     if (is_STRICT_VERSION(s,&errstr)) {
2201         SV *ver = newSV(0);
2202         s = (char *)scan_version(s, ver, 0);
2203         version = newSVOP(OP_CONST, 0, ver);
2204     }
2205     else if ( (*s != ';' && *s != '{' && *s != '}' ) &&
2206             (s = SKIPSPACE1(s), (*s != ';' && *s != '{' && *s != '}' )))
2207     {
2208         PL_bufptr = s;
2209         if (errstr)
2210             yyerror(errstr); /* version required */
2211         return s;
2212     }
2213
2214 #ifdef PERL_MAD
2215     if (PL_madskills && !version) {
2216         sv_free(PL_nextwhite);  /* let next token collect whitespace */
2217         PL_nextwhite = 0;
2218         s = SvPVX(PL_linestr) + startoff;
2219     }
2220 #endif
2221     /* NOTE: The parser sees the package name and the VERSION swapped */
2222     start_force(PL_curforce);
2223     NEXTVAL_NEXTTOKE.opval = version;
2224     force_next(WORD);
2225
2226     return s;
2227 }
2228
2229 /*
2230  * S_tokeq
2231  * Tokenize a quoted string passed in as an SV.  It finds the next
2232  * chunk, up to end of string or a backslash.  It may make a new
2233  * SV containing that chunk (if HINT_NEW_STRING is on).  It also
2234  * turns \\ into \.
2235  */
2236
2237 STATIC SV *
2238 S_tokeq(pTHX_ SV *sv)
2239 {
2240     dVAR;
2241     register char *s;
2242     register char *send;
2243     register char *d;
2244     STRLEN len = 0;
2245     SV *pv = sv;
2246
2247     PERL_ARGS_ASSERT_TOKEQ;
2248
2249     if (!SvLEN(sv))
2250         goto finish;
2251
2252     s = SvPV_force(sv, len);
2253     if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
2254         goto finish;
2255     send = s + len;
2256     /* This is relying on the SV being "well formed" with a trailing '\0'  */
2257     while (s < send && !(*s == '\\' && s[1] == '\\'))
2258         s++;
2259     if (s == send)
2260         goto finish;
2261     d = s;
2262     if ( PL_hints & HINT_NEW_STRING ) {
2263         pv = newSVpvn_flags(SvPVX_const(pv), len, SVs_TEMP | SvUTF8(sv));
2264     }
2265     while (s < send) {
2266         if (*s == '\\') {
2267             if (s + 1 < send && (s[1] == '\\'))
2268                 s++;            /* all that, just for this */
2269         }
2270         *d++ = *s++;
2271     }
2272     *d = '\0';
2273     SvCUR_set(sv, d - SvPVX_const(sv));
2274   finish:
2275     if ( PL_hints & HINT_NEW_STRING )
2276        return new_constant(NULL, 0, "q", sv, pv, "q", 1);
2277     return sv;
2278 }
2279
2280 /*
2281  * Now come three functions related to double-quote context,
2282  * S_sublex_start, S_sublex_push, and S_sublex_done.  They're used when
2283  * converting things like "\u\Lgnat" into ucfirst(lc("gnat")).  They
2284  * interact with PL_lex_state, and create fake ( ... ) argument lists
2285  * to handle functions and concatenation.
2286  * They assume that whoever calls them will be setting up a fake
2287  * join call, because each subthing puts a ',' after it.  This lets
2288  *   "lower \luPpEr"
2289  * become
2290  *  join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
2291  *
2292  * (I'm not sure whether the spurious commas at the end of lcfirst's
2293  * arguments and join's arguments are created or not).
2294  */
2295
2296 /*
2297  * S_sublex_start
2298  * Assumes that pl_yylval.ival is the op we're creating (e.g. OP_LCFIRST).
2299  *
2300  * Pattern matching will set PL_lex_op to the pattern-matching op to
2301  * make (we return THING if pl_yylval.ival is OP_NULL, PMFUNC otherwise).
2302  *
2303  * OP_CONST and OP_READLINE are easy--just make the new op and return.
2304  *
2305  * Everything else becomes a FUNC.
2306  *
2307  * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
2308  * had an OP_CONST or OP_READLINE).  This just sets us up for a
2309  * call to S_sublex_push().
2310  */
2311
2312 STATIC I32
2313 S_sublex_start(pTHX)
2314 {
2315     dVAR;
2316     register const I32 op_type = pl_yylval.ival;
2317
2318     if (op_type == OP_NULL) {
2319         pl_yylval.opval = PL_lex_op;
2320         PL_lex_op = NULL;
2321         return THING;
2322     }
2323     if (op_type == OP_CONST || op_type == OP_READLINE) {
2324         SV *sv = tokeq(PL_lex_stuff);
2325
2326         if (SvTYPE(sv) == SVt_PVIV) {
2327             /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
2328             STRLEN len;
2329             const char * const p = SvPV_const(sv, len);
2330             SV * const nsv = newSVpvn_flags(p, len, SvUTF8(sv));
2331             SvREFCNT_dec(sv);
2332             sv = nsv;
2333         }
2334         pl_yylval.opval = (OP*)newSVOP(op_type, 0, sv);
2335         PL_lex_stuff = NULL;
2336         /* Allow <FH> // "foo" */
2337         if (op_type == OP_READLINE)
2338             PL_expect = XTERMORDORDOR;
2339         return THING;
2340     }
2341     else if (op_type == OP_BACKTICK && PL_lex_op) {
2342         /* readpipe() vas overriden */
2343         cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
2344         pl_yylval.opval = PL_lex_op;
2345         PL_lex_op = NULL;
2346         PL_lex_stuff = NULL;
2347         return THING;
2348     }
2349
2350     PL_sublex_info.super_state = PL_lex_state;
2351     PL_sublex_info.sub_inwhat = (U16)op_type;
2352     PL_sublex_info.sub_op = PL_lex_op;
2353     PL_lex_state = LEX_INTERPPUSH;
2354
2355     PL_expect = XTERM;
2356     if (PL_lex_op) {
2357         pl_yylval.opval = PL_lex_op;
2358         PL_lex_op = NULL;
2359         return PMFUNC;
2360     }
2361     else
2362         return FUNC;
2363 }
2364
2365 /*
2366  * S_sublex_push
2367  * Create a new scope to save the lexing state.  The scope will be
2368  * ended in S_sublex_done.  Returns a '(', starting the function arguments
2369  * to the uc, lc, etc. found before.
2370  * Sets PL_lex_state to LEX_INTERPCONCAT.
2371  */
2372
2373 STATIC I32
2374 S_sublex_push(pTHX)
2375 {
2376     dVAR;
2377     ENTER;
2378
2379     PL_lex_state = PL_sublex_info.super_state;
2380     SAVEBOOL(PL_lex_dojoin);
2381     SAVEI32(PL_lex_brackets);
2382     SAVEI32(PL_lex_casemods);
2383     SAVEI32(PL_lex_starts);
2384     SAVEI8(PL_lex_state);
2385     SAVEVPTR(PL_lex_inpat);
2386     SAVEI16(PL_lex_inwhat);
2387     SAVECOPLINE(PL_curcop);
2388     SAVEPPTR(PL_bufptr);
2389     SAVEPPTR(PL_bufend);
2390     SAVEPPTR(PL_oldbufptr);
2391     SAVEPPTR(PL_oldoldbufptr);
2392     SAVEPPTR(PL_last_lop);
2393     SAVEPPTR(PL_last_uni);
2394     SAVEPPTR(PL_linestart);
2395     SAVESPTR(PL_linestr);
2396     SAVEGENERICPV(PL_lex_brackstack);
2397     SAVEGENERICPV(PL_lex_casestack);
2398
2399     PL_linestr = PL_lex_stuff;
2400     PL_lex_stuff = NULL;
2401
2402     PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
2403         = SvPVX(PL_linestr);
2404     PL_bufend += SvCUR(PL_linestr);
2405     PL_last_lop = PL_last_uni = NULL;
2406     SAVEFREESV(PL_linestr);
2407
2408     PL_lex_dojoin = FALSE;
2409     PL_lex_brackets = 0;
2410     Newx(PL_lex_brackstack, 120, char);
2411     Newx(PL_lex_casestack, 12, char);
2412     PL_lex_casemods = 0;
2413     *PL_lex_casestack = '\0';
2414     PL_lex_starts = 0;
2415     PL_lex_state = LEX_INTERPCONCAT;
2416     CopLINE_set(PL_curcop, (line_t)PL_multi_start);
2417
2418     PL_lex_inwhat = PL_sublex_info.sub_inwhat;
2419     if (PL_lex_inwhat == OP_TRANSR) PL_lex_inwhat = OP_TRANS;
2420     if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
2421         PL_lex_inpat = PL_sublex_info.sub_op;
2422     else
2423         PL_lex_inpat = NULL;
2424
2425     return '(';
2426 }
2427
2428 /*
2429  * S_sublex_done
2430  * Restores lexer state after a S_sublex_push.
2431  */
2432
2433 STATIC I32
2434 S_sublex_done(pTHX)
2435 {
2436     dVAR;
2437     if (!PL_lex_starts++) {
2438         SV * const sv = newSVpvs("");
2439         if (SvUTF8(PL_linestr))
2440             SvUTF8_on(sv);
2441         PL_expect = XOPERATOR;
2442         pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2443         return THING;
2444     }
2445
2446     if (PL_lex_casemods) {              /* oops, we've got some unbalanced parens */
2447         PL_lex_state = LEX_INTERPCASEMOD;
2448         return yylex();
2449     }
2450
2451     /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
2452     assert(PL_lex_inwhat != OP_TRANSR);
2453     if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
2454         PL_linestr = PL_lex_repl;
2455         PL_lex_inpat = 0;
2456         PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
2457         PL_bufend += SvCUR(PL_linestr);
2458         PL_last_lop = PL_last_uni = NULL;
2459         SAVEFREESV(PL_linestr);
2460         PL_lex_dojoin = FALSE;
2461         PL_lex_brackets = 0;
2462         PL_lex_casemods = 0;
2463         *PL_lex_casestack = '\0';
2464         PL_lex_starts = 0;
2465         if (SvEVALED(PL_lex_repl)) {
2466             PL_lex_state = LEX_INTERPNORMAL;
2467             PL_lex_starts++;
2468             /*  we don't clear PL_lex_repl here, so that we can check later
2469                 whether this is an evalled subst; that means we rely on the
2470                 logic to ensure sublex_done() is called again only via the
2471                 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
2472         }
2473         else {
2474             PL_lex_state = LEX_INTERPCONCAT;
2475             PL_lex_repl = NULL;
2476         }
2477         return ',';
2478     }
2479     else {
2480 #ifdef PERL_MAD
2481         if (PL_madskills) {
2482             if (PL_thiswhite) {
2483                 if (!PL_endwhite)
2484                     PL_endwhite = newSVpvs("");
2485                 sv_catsv(PL_endwhite, PL_thiswhite);
2486                 PL_thiswhite = 0;
2487             }
2488             if (PL_thistoken)
2489                 sv_setpvs(PL_thistoken,"");
2490             else
2491                 PL_realtokenstart = -1;
2492         }
2493 #endif
2494         LEAVE;
2495         PL_bufend = SvPVX(PL_linestr);
2496         PL_bufend += SvCUR(PL_linestr);
2497         PL_expect = XOPERATOR;
2498         PL_sublex_info.sub_inwhat = 0;
2499         return ')';
2500     }
2501 }
2502
2503 /*
2504   scan_const
2505
2506   Extracts a pattern, double-quoted string, or transliteration.  This
2507   is terrifying code.
2508
2509   It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
2510   processing a pattern (PL_lex_inpat is true), a transliteration
2511   (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
2512
2513   Returns a pointer to the character scanned up to. If this is
2514   advanced from the start pointer supplied (i.e. if anything was
2515   successfully parsed), will leave an OP for the substring scanned
2516   in pl_yylval. Caller must intuit reason for not parsing further
2517   by looking at the next characters herself.
2518
2519   In patterns:
2520     backslashes:
2521       constants: \N{NAME} only
2522       case and quoting: \U \Q \E
2523     stops on @ and $, but not for $ as tail anchor
2524
2525   In transliterations:
2526     characters are VERY literal, except for - not at the start or end
2527     of the string, which indicates a range. If the range is in bytes,
2528     scan_const expands the range to the full set of intermediate
2529     characters. If the range is in utf8, the hyphen is replaced with
2530     a certain range mark which will be handled by pmtrans() in op.c.
2531
2532   In double-quoted strings:
2533     backslashes:
2534       double-quoted style: \r and \n
2535       constants: \x31, etc.
2536       deprecated backrefs: \1 (in substitution replacements)
2537       case and quoting: \U \Q \E
2538     stops on @ and $
2539
2540   scan_const does *not* construct ops to handle interpolated strings.
2541   It stops processing as soon as it finds an embedded $ or @ variable
2542   and leaves it to the caller to work out what's going on.
2543
2544   embedded arrays (whether in pattern or not) could be:
2545       @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
2546
2547   $ in double-quoted strings must be the symbol of an embedded scalar.
2548
2549   $ in pattern could be $foo or could be tail anchor.  Assumption:
2550   it's a tail anchor if $ is the last thing in the string, or if it's
2551   followed by one of "()| \r\n\t"
2552
2553   \1 (backreferences) are turned into $1
2554
2555   The structure of the code is
2556       while (there's a character to process) {
2557           handle transliteration ranges
2558           skip regexp comments /(?#comment)/ and codes /(?{code})/
2559           skip #-initiated comments in //x patterns
2560           check for embedded arrays
2561           check for embedded scalars
2562           if (backslash) {
2563               deprecate \1 in substitution replacements
2564               handle string-changing backslashes \l \U \Q \E, etc.
2565               switch (what was escaped) {
2566                   handle \- in a transliteration (becomes a literal -)
2567                   if a pattern and not \N{, go treat as regular character
2568                   handle \132 (octal characters)
2569                   handle \x15 and \x{1234} (hex characters)
2570                   handle \N{name} (named characters, also \N{3,5} in a pattern)
2571                   handle \cV (control characters)
2572                   handle printf-style backslashes (\f, \r, \n, etc)
2573               } (end switch)
2574               continue
2575           } (end if backslash)
2576           handle regular character
2577     } (end while character to read)
2578                 
2579 */
2580
2581 STATIC char *
2582 S_scan_const(pTHX_ char *start)
2583 {
2584     dVAR;
2585     register char *send = PL_bufend;            /* end of the constant */
2586     SV *sv = newSV(send - start);               /* sv for the constant.  See
2587                                                    note below on sizing. */
2588     register char *s = start;                   /* start of the constant */
2589     register char *d = SvPVX(sv);               /* destination for copies */
2590     bool dorange = FALSE;                       /* are we in a translit range? */
2591     bool didrange = FALSE;                      /* did we just finish a range? */
2592     I32  has_utf8 = FALSE;                      /* Output constant is UTF8 */
2593     I32  this_utf8 = UTF;                       /* Is the source string assumed
2594                                                    to be UTF8?  But, this can
2595                                                    show as true when the source
2596                                                    isn't utf8, as for example
2597                                                    when it is entirely composed
2598                                                    of hex constants */
2599
2600     /* Note on sizing:  The scanned constant is placed into sv, which is
2601      * initialized by newSV() assuming one byte of output for every byte of
2602      * input.  This routine expects newSV() to allocate an extra byte for a
2603      * trailing NUL, which this routine will append if it gets to the end of
2604      * the input.  There may be more bytes of input than output (eg., \N{LATIN
2605      * CAPITAL LETTER A}), or more output than input if the constant ends up
2606      * recoded to utf8, but each time a construct is found that might increase
2607      * the needed size, SvGROW() is called.  Its size parameter each time is
2608      * based on the best guess estimate at the time, namely the length used so
2609      * far, plus the length the current construct will occupy, plus room for
2610      * the trailing NUL, plus one byte for every input byte still unscanned */ 
2611
2612     UV uv;
2613 #ifdef EBCDIC
2614     UV literal_endpoint = 0;
2615     bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
2616 #endif
2617
2618     PERL_ARGS_ASSERT_SCAN_CONST;
2619
2620     assert(PL_lex_inwhat != OP_TRANSR);
2621     if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2622         /* If we are doing a trans and we know we want UTF8 set expectation */
2623         has_utf8   = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
2624         this_utf8  = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2625     }
2626
2627
2628     while (s < send || dorange) {
2629
2630         /* get transliterations out of the way (they're most literal) */
2631         if (PL_lex_inwhat == OP_TRANS) {
2632             /* expand a range A-Z to the full set of characters.  AIE! */
2633             if (dorange) {
2634                 I32 i;                          /* current expanded character */
2635                 I32 min;                        /* first character in range */
2636                 I32 max;                        /* last character in range */
2637
2638 #ifdef EBCDIC
2639                 UV uvmax = 0;
2640 #endif
2641
2642                 if (has_utf8
2643 #ifdef EBCDIC
2644                     && !native_range
2645 #endif
2646                     ) {
2647                     char * const c = (char*)utf8_hop((U8*)d, -1);
2648                     char *e = d++;
2649                     while (e-- > c)
2650                         *(e + 1) = *e;
2651                     *c = (char)UTF_TO_NATIVE(0xff);
2652                     /* mark the range as done, and continue */
2653                     dorange = FALSE;
2654                     didrange = TRUE;
2655                     continue;
2656                 }
2657
2658                 i = d - SvPVX_const(sv);                /* remember current offset */
2659 #ifdef EBCDIC
2660                 SvGROW(sv,
2661                        SvLEN(sv) + (has_utf8 ?
2662                                     (512 - UTF_CONTINUATION_MARK +
2663                                      UNISKIP(0x100))
2664                                     : 256));
2665                 /* How many two-byte within 0..255: 128 in UTF-8,
2666                  * 96 in UTF-8-mod. */
2667 #else
2668                 SvGROW(sv, SvLEN(sv) + 256);    /* never more than 256 chars in a range */
2669 #endif
2670                 d = SvPVX(sv) + i;              /* refresh d after realloc */
2671 #ifdef EBCDIC
2672                 if (has_utf8) {
2673                     int j;
2674                     for (j = 0; j <= 1; j++) {
2675                         char * const c = (char*)utf8_hop((U8*)d, -1);
2676                         const UV uv    = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
2677                         if (j)
2678                             min = (U8)uv;
2679                         else if (uv < 256)
2680                             max = (U8)uv;
2681                         else {
2682                             max = (U8)0xff; /* only to \xff */
2683                             uvmax = uv; /* \x{100} to uvmax */
2684                         }
2685                         d = c; /* eat endpoint chars */
2686                      }
2687                 }
2688                else {
2689 #endif
2690                    d -= 2;              /* eat the first char and the - */
2691                    min = (U8)*d;        /* first char in range */
2692                    max = (U8)d[1];      /* last char in range  */
2693 #ifdef EBCDIC
2694                }
2695 #endif
2696
2697                 if (min > max) {
2698                     Perl_croak(aTHX_
2699                                "Invalid range \"%c-%c\" in transliteration operator",
2700                                (char)min, (char)max);
2701                 }
2702
2703 #ifdef EBCDIC
2704                 if (literal_endpoint == 2 &&
2705                     ((isLOWER(min) && isLOWER(max)) ||
2706                      (isUPPER(min) && isUPPER(max)))) {
2707                     if (isLOWER(min)) {
2708                         for (i = min; i <= max; i++)
2709                             if (isLOWER(i))
2710                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
2711                     } else {
2712                         for (i = min; i <= max; i++)
2713                             if (isUPPER(i))
2714                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
2715                     }
2716                 }
2717                 else
2718 #endif
2719                     for (i = min; i <= max; i++)
2720 #ifdef EBCDIC
2721                         if (has_utf8) {
2722                             const U8 ch = (U8)NATIVE_TO_UTF(i);
2723                             if (UNI_IS_INVARIANT(ch))
2724                                 *d++ = (U8)i;
2725                             else {
2726                                 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
2727                                 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
2728                             }
2729                         }
2730                         else
2731 #endif
2732                             *d++ = (char)i;
2733  
2734 #ifdef EBCDIC
2735                 if (uvmax) {
2736                     d = (char*)uvchr_to_utf8((U8*)d, 0x100);
2737                     if (uvmax > 0x101)
2738                         *d++ = (char)UTF_TO_NATIVE(0xff);
2739                     if (uvmax > 0x100)
2740                         d = (char*)uvchr_to_utf8((U8*)d, uvmax);
2741                 }
2742 #endif
2743
2744                 /* mark the range as done, and continue */
2745                 dorange = FALSE;
2746                 didrange = TRUE;
2747 #ifdef EBCDIC
2748                 literal_endpoint = 0;
2749 #endif
2750                 continue;
2751             }
2752
2753             /* range begins (ignore - as first or last char) */
2754             else if (*s == '-' && s+1 < send  && s != start) {
2755                 if (didrange) {
2756                     Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
2757                 }
2758                 if (has_utf8
2759 #ifdef EBCDIC
2760                     && !native_range
2761 #endif
2762                     ) {
2763                     *d++ = (char)UTF_TO_NATIVE(0xff);   /* use illegal utf8 byte--see pmtrans */
2764                     s++;
2765                     continue;
2766                 }
2767                 dorange = TRUE;
2768                 s++;
2769             }
2770             else {
2771                 didrange = FALSE;
2772 #ifdef EBCDIC
2773                 literal_endpoint = 0;
2774                 native_range = TRUE;
2775 #endif
2776             }
2777         }
2778
2779         /* if we get here, we're not doing a transliteration */
2780
2781         /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2782            except for the last char, which will be done separately. */
2783         else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
2784             if (s[2] == '#') {
2785                 while (s+1 < send && *s != ')')
2786                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2787             }
2788             else if (s[2] == '{' /* This should match regcomp.c */
2789                     || (s[2] == '?' && s[3] == '{'))
2790             {
2791                 I32 count = 1;
2792                 char *regparse = s + (s[2] == '{' ? 3 : 4);
2793                 char c;
2794
2795                 while (count && (c = *regparse)) {
2796                     if (c == '\\' && regparse[1])
2797                         regparse++;
2798                     else if (c == '{')
2799                         count++;
2800                     else if (c == '}')
2801                         count--;
2802                     regparse++;
2803                 }
2804                 if (*regparse != ')')
2805                     regparse--;         /* Leave one char for continuation. */
2806                 while (s < regparse)
2807                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2808             }
2809         }
2810
2811         /* likewise skip #-initiated comments in //x patterns */
2812         else if (*s == '#' && PL_lex_inpat &&
2813           ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2814             while (s+1 < send && *s != '\n')
2815                 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2816         }
2817
2818         /* check for embedded arrays
2819            (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2820            */
2821         else if (*s == '@' && s[1]) {
2822             if (isALNUM_lazy_if(s+1,UTF))
2823                 break;
2824             if (strchr(":'{$", s[1]))
2825                 break;
2826             if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2827                 break; /* in regexp, neither @+ nor @- are interpolated */
2828         }
2829
2830         /* check for embedded scalars.  only stop if we're sure it's a
2831            variable.
2832         */
2833         else if (*s == '$') {
2834             if (!PL_lex_inpat)  /* not a regexp, so $ must be var */
2835                 break;
2836             if (s + 1 < send && !strchr("()| \r\n\t", s[1])) {
2837                 if (s[1] == '\\') {
2838                     Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
2839                                    "Possible unintended interpolation of $\\ in regex");
2840                 }
2841                 break;          /* in regexp, $ might be tail anchor */
2842             }
2843         }
2844
2845         /* End of else if chain - OP_TRANS rejoin rest */
2846
2847         /* backslashes */
2848         if (*s == '\\' && s+1 < send) {
2849             char* e;    /* Can be used for ending '}', etc. */
2850
2851             s++;
2852
2853             /* warn on \1 - \9 in substitution replacements, but note that \11
2854              * is an octal; and \19 is \1 followed by '9' */
2855             if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2856                 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2857             {
2858                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2859                 *--s = '$';
2860                 break;
2861             }
2862
2863             /* string-change backslash escapes */
2864             if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2865                 --s;
2866                 break;
2867             }
2868             /* In a pattern, process \N, but skip any other backslash escapes.
2869              * This is because we don't want to translate an escape sequence
2870              * into a meta symbol and have the regex compiler use the meta
2871              * symbol meaning, e.g. \x{2E} would be confused with a dot.  But
2872              * in spite of this, we do have to process \N here while the proper
2873              * charnames handler is in scope.  See bugs #56444 and #62056.
2874              * There is a complication because \N in a pattern may also stand
2875              * for 'match a non-nl', and not mean a charname, in which case its
2876              * processing should be deferred to the regex compiler.  To be a
2877              * charname it must be followed immediately by a '{', and not look
2878              * like \N followed by a curly quantifier, i.e., not something like
2879              * \N{3,}.  regcurly returns a boolean indicating if it is a legal
2880              * quantifier */
2881             else if (PL_lex_inpat
2882                     && (*s != 'N'
2883                         || s[1] != '{'
2884                         || regcurly(s + 1)))
2885             {
2886                 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2887                 goto default_action;
2888             }
2889
2890             switch (*s) {
2891
2892             /* quoted - in transliterations */
2893             case '-':
2894                 if (PL_lex_inwhat == OP_TRANS) {
2895                     *d++ = *s++;
2896                     continue;
2897                 }
2898                 /* FALL THROUGH */
2899             default:
2900                 {
2901                     if ((isALPHA(*s) || isDIGIT(*s)))
2902                         Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
2903                                        "Unrecognized escape \\%c passed through",
2904                                        *s);
2905                     /* default action is to copy the quoted character */
2906                     goto default_action;
2907                 }
2908
2909             /* eg. \132 indicates the octal constant 0132 */
2910             case '0': case '1': case '2': case '3':
2911             case '4': case '5': case '6': case '7':
2912                 {
2913                     I32 flags = 0;
2914                     STRLEN len = 3;
2915                     uv = NATIVE_TO_UNI(grok_oct(s, &len, &flags, NULL));
2916                     s += len;
2917                 }
2918                 goto NUM_ESCAPE_INSERT;
2919
2920             /* eg. \o{24} indicates the octal constant \024 */
2921             case 'o':
2922                 {
2923                     STRLEN len;
2924                     const char* error;
2925
2926                     bool valid = grok_bslash_o(s, &uv, &len, &error, 1);
2927                     s += len;
2928                     if (! valid) {
2929                         yyerror(error);
2930                         continue;
2931                     }
2932                     goto NUM_ESCAPE_INSERT;
2933                 }
2934
2935             /* eg. \x24 indicates the hex constant 0x24 */
2936             case 'x':
2937                 ++s;
2938                 if (*s == '{') {
2939                     char* const e = strchr(s, '}');
2940                     I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2941                       PERL_SCAN_DISALLOW_PREFIX;
2942                     STRLEN len;
2943
2944                     ++s;
2945                     if (!e) {
2946                         yyerror("Missing right brace on \\x{}");
2947                         continue;
2948                     }
2949                     len = e - s;
2950                     uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
2951                     s = e + 1;
2952                 }
2953                 else {
2954                     {
2955                         STRLEN len = 2;
2956                         I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2957                         uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
2958                         s += len;
2959                     }
2960                 }
2961
2962               NUM_ESCAPE_INSERT:
2963                 /* Insert oct or hex escaped character.  There will always be
2964                  * enough room in sv since such escapes will be longer than any
2965                  * UTF-8 sequence they can end up as, except if they force us
2966                  * to recode the rest of the string into utf8 */
2967                 
2968                 /* Here uv is the ordinal of the next character being added in
2969                  * unicode (converted from native). */
2970                 if (!UNI_IS_INVARIANT(uv)) {
2971                     if (!has_utf8 && uv > 255) {
2972                         /* Might need to recode whatever we have accumulated so
2973                          * far if it contains any chars variant in utf8 or
2974                          * utf-ebcdic. */
2975                           
2976                         SvCUR_set(sv, d - SvPVX_const(sv));
2977                         SvPOK_on(sv);
2978                         *d = '\0';
2979                         /* See Note on sizing above.  */
2980                         sv_utf8_upgrade_flags_grow(sv,
2981                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2982                                         UNISKIP(uv) + (STRLEN)(send - s) + 1);
2983                         d = SvPVX(sv) + SvCUR(sv);
2984                         has_utf8 = TRUE;
2985                     }
2986
2987                     if (has_utf8) {
2988                         d = (char*)uvuni_to_utf8((U8*)d, uv);
2989                         if (PL_lex_inwhat == OP_TRANS &&
2990                             PL_sublex_info.sub_op) {
2991                             PL_sublex_info.sub_op->op_private |=
2992                                 (PL_lex_repl ? OPpTRANS_FROM_UTF
2993                                              : OPpTRANS_TO_UTF);
2994                         }
2995 #ifdef EBCDIC
2996                         if (uv > 255 && !dorange)
2997                             native_range = FALSE;
2998 #endif
2999                     }
3000                     else {
3001                         *d++ = (char)uv;
3002                     }
3003                 }
3004                 else {
3005                     *d++ = (char) uv;
3006                 }
3007                 continue;
3008
3009             case 'N':
3010                 /* In a non-pattern \N must be a named character, like \N{LATIN
3011                  * SMALL LETTER A} or \N{U+0041}.  For patterns, it also can
3012                  * mean to match a non-newline.  For non-patterns, named
3013                  * characters are converted to their string equivalents. In
3014                  * patterns, named characters are not converted to their
3015                  * ultimate forms for the same reasons that other escapes
3016                  * aren't.  Instead, they are converted to the \N{U+...} form
3017                  * to get the value from the charnames that is in effect right
3018                  * now, while preserving the fact that it was a named character
3019                  * so that the regex compiler knows this */
3020
3021                 /* This section of code doesn't generally use the
3022                  * NATIVE_TO_NEED() macro to transform the input.  I (khw) did
3023                  * a close examination of this macro and determined it is a
3024                  * no-op except on utfebcdic variant characters.  Every
3025                  * character generated by this that would normally need to be
3026                  * enclosed by this macro is invariant, so the macro is not
3027                  * needed, and would complicate use of copy(). There are other
3028                  * parts of this file where the macro is used inconsistently,
3029                  * but are saved by it being a no-op */
3030
3031                 /* The structure of this section of code (besides checking for
3032                  * errors and upgrading to utf8) is:
3033                  *  Further disambiguate between the two meanings of \N, and if
3034                  *      not a charname, go process it elsewhere
3035                  *  If of form \N{U+...}, pass it through if a pattern;
3036                  *      otherwise convert to utf8
3037                  *  Otherwise must be \N{NAME}: convert to \N{U+c1.c2...} if a
3038                  *  pattern; otherwise convert to utf8 */
3039
3040                 /* Here, s points to the 'N'; the test below is guaranteed to
3041                  * succeed if we are being called on a pattern as we already
3042                  * know from a test above that the next character is a '{'.
3043                  * On a non-pattern \N must mean 'named sequence, which
3044                  * requires braces */
3045                 s++;
3046                 if (*s != '{') {
3047                     yyerror("Missing braces on \\N{}"); 
3048                     continue;
3049                 }
3050                 s++;
3051
3052                 /* If there is no matching '}', it is an error. */
3053                 if (! (e = strchr(s, '}'))) {
3054                     if (! PL_lex_inpat) {
3055                         yyerror("Missing right brace on \\N{}");
3056                     } else {
3057                         yyerror("Missing right brace on \\N{} or unescaped left brace after \\N.");
3058                     }
3059                     continue;
3060                 }
3061
3062                 /* Here it looks like a named character */
3063
3064                 if (PL_lex_inpat) {
3065
3066                     /* XXX This block is temporary code.  \N{} implies that the
3067                      * pattern is to have Unicode semantics, and therefore
3068                      * currently has to be encoded in utf8.  By putting it in
3069                      * utf8 now, we save a whole pass in the regular expression
3070                      * compiler.  Once that code is changed so Unicode
3071                      * semantics doesn't necessarily have to be in utf8, this
3072                      * block should be removed */
3073                     if (!has_utf8) {
3074                         SvCUR_set(sv, d - SvPVX_const(sv));
3075                         SvPOK_on(sv);
3076                         *d = '\0';
3077                         /* See Note on sizing above.  */
3078                         sv_utf8_upgrade_flags_grow(sv,
3079                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3080                                         /* 5 = '\N{' + cur char + NUL */
3081                                         (STRLEN)(send - s) + 5);
3082                         d = SvPVX(sv) + SvCUR(sv);
3083                         has_utf8 = TRUE;
3084                     }
3085                 }
3086
3087                 if (*s == 'U' && s[1] == '+') { /* \N{U+...} */
3088                     I32 flags = PERL_SCAN_ALLOW_UNDERSCORES
3089                                 | PERL_SCAN_DISALLOW_PREFIX;
3090                     STRLEN len;
3091
3092                     /* For \N{U+...}, the '...' is a unicode value even on
3093                      * EBCDIC machines */
3094                     s += 2;         /* Skip to next char after the 'U+' */
3095                     len = e - s;
3096                     uv = grok_hex(s, &len, &flags, NULL);
3097                     if (len == 0 || len != (STRLEN)(e - s)) {
3098                         yyerror("Invalid hexadecimal number in \\N{U+...}");
3099                         s = e + 1;
3100                         continue;
3101                     }
3102
3103                     if (PL_lex_inpat) {
3104
3105                         /* Pass through to the regex compiler unchanged.  The
3106                          * reason we evaluated the number above is to make sure
3107                          * there wasn't a syntax error. */
3108                         s -= 5;     /* Include the '\N{U+' */
3109                         Copy(s, d, e - s + 1, char);    /* 1 = include the } */
3110                         d += e - s + 1;
3111                     }
3112                     else {  /* Not a pattern: convert the hex to string */
3113
3114                          /* If destination is not in utf8, unconditionally
3115                           * recode it to be so.  This is because \N{} implies
3116                           * Unicode semantics, and scalars have to be in utf8
3117                           * to guarantee those semantics */
3118                         if (! has_utf8) {
3119                             SvCUR_set(sv, d - SvPVX_const(sv));
3120                             SvPOK_on(sv);
3121                             *d = '\0';
3122                             /* See Note on sizing above.  */
3123                             sv_utf8_upgrade_flags_grow(
3124                                         sv,
3125                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3126                                         UNISKIP(uv) + (STRLEN)(send - e) + 1);
3127                             d = SvPVX(sv) + SvCUR(sv);
3128                             has_utf8 = TRUE;
3129                         }
3130
3131                         /* Add the string to the output */
3132                         if (UNI_IS_INVARIANT(uv)) {
3133                             *d++ = (char) uv;
3134                         }
3135                         else d = (char*)uvuni_to_utf8((U8*)d, uv);
3136                     }
3137                 }
3138                 else { /* Here is \N{NAME} but not \N{U+...}. */
3139
3140                     SV *res;            /* result from charnames */
3141                     const char *str;    /* the string in 'res' */
3142                     STRLEN len;         /* its length */
3143
3144                     /* Get the value for NAME */
3145                     res = newSVpvn(s, e - s);
3146                     res = new_constant( NULL, 0, "charnames",
3147                                         /* includes all of: \N{...} */
3148                                         res, NULL, s - 3, e - s + 4 );
3149
3150                     /* Most likely res will be in utf8 already since the
3151                      * standard charnames uses pack U, but a custom translator
3152                      * can leave it otherwise, so make sure.  XXX This can be
3153                      * revisited to not have charnames use utf8 for characters
3154                      * that don't need it when regexes don't have to be in utf8
3155                      * for Unicode semantics.  If doing so, remember EBCDIC */
3156                     sv_utf8_upgrade(res);
3157                     str = SvPV_const(res, len);
3158
3159                     /* Don't accept malformed input */
3160                     if (! is_utf8_string((U8 *) str, len)) {
3161                         yyerror("Malformed UTF-8 returned by \\N");
3162                     }
3163                     else if (PL_lex_inpat) {
3164
3165                         if (! len) { /* The name resolved to an empty string */
3166                             Copy("\\N{}", d, 4, char);
3167                             d += 4;
3168                         }
3169                         else {
3170                             /* In order to not lose information for the regex
3171                             * compiler, pass the result in the specially made
3172                             * syntax: \N{U+c1.c2.c3...}, where c1 etc. are
3173                             * the code points in hex of each character
3174                             * returned by charnames */
3175
3176                             const char *str_end = str + len;
3177                             STRLEN char_length;     /* cur char's byte length */
3178                             STRLEN output_length;   /* and the number of bytes
3179                                                        after this is translated
3180                                                        into hex digits */
3181                             const STRLEN off = d - SvPVX_const(sv);
3182
3183                             /* 2 hex per byte; 2 chars for '\N'; 2 chars for
3184                              * max('U+', '.'); and 1 for NUL */
3185                             char hex_string[2 * UTF8_MAXBYTES + 5];
3186
3187                             /* Get the first character of the result. */
3188                             U32 uv = utf8n_to_uvuni((U8 *) str,
3189                                                     len,
3190                                                     &char_length,
3191                                                     UTF8_ALLOW_ANYUV);
3192
3193                             /* The call to is_utf8_string() above hopefully
3194                              * guarantees that there won't be an error.  But
3195                              * it's easy here to make sure.  The function just
3196                              * above warns and returns 0 if invalid utf8, but
3197                              * it can also return 0 if the input is validly a
3198                              * NUL. Disambiguate */
3199                             if (uv == 0 && NATIVE_TO_ASCII(*str) != '\0') {
3200                                 uv = UNICODE_REPLACEMENT;
3201                             }
3202
3203                             /* Convert first code point to hex, including the
3204                              * boiler plate before it */
3205                             output_length =
3206                                 my_sprintf(hex_string, "\\N{U+%X", (unsigned int) uv);
3207
3208                             /* Make sure there is enough space to hold it */
3209                             d = off + SvGROW(sv, off
3210                                                  + output_length
3211                                                  + (STRLEN)(send - e)
3212                                                  + 2);  /* '}' + NUL */
3213                             /* And output it */
3214                             Copy(hex_string, d, output_length, char);
3215                             d += output_length;
3216
3217                             /* For each subsequent character, append dot and
3218                              * its ordinal in hex */
3219                             while ((str += char_length) < str_end) {
3220                                 const STRLEN off = d - SvPVX_const(sv);
3221                                 U32 uv = utf8n_to_uvuni((U8 *) str,
3222                                                         str_end - str,
3223                                                         &char_length,
3224                                                         UTF8_ALLOW_ANYUV);
3225                                 if (uv == 0 && NATIVE_TO_ASCII(*str) != '\0') {
3226                                     uv = UNICODE_REPLACEMENT;
3227                                 }
3228
3229                                 output_length =
3230                                     my_sprintf(hex_string, ".%X", (unsigned int) uv);
3231
3232                                 d = off + SvGROW(sv, off
3233                                                      + output_length
3234                                                      + (STRLEN)(send - e)
3235                                                      + 2);      /* '}' +  NUL */
3236                                 Copy(hex_string, d, output_length, char);
3237                                 d += output_length;
3238                             }
3239
3240                             *d++ = '}'; /* Done.  Add the trailing brace */
3241                         }
3242                     }
3243                     else { /* Here, not in a pattern.  Convert the name to a
3244                             * string. */
3245
3246                          /* If destination is not in utf8, unconditionally
3247                           * recode it to be so.  This is because \N{} implies
3248                           * Unicode semantics, and scalars have to be in utf8
3249                           * to guarantee those semantics */
3250                         if (! has_utf8) {
3251                             SvCUR_set(sv, d - SvPVX_const(sv));
3252                             SvPOK_on(sv);
3253                             *d = '\0';
3254                             /* See Note on sizing above.  */
3255                             sv_utf8_upgrade_flags_grow(sv,
3256                                                 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3257                                                 len + (STRLEN)(send - s) + 1);
3258                             d = SvPVX(sv) + SvCUR(sv);
3259                             has_utf8 = TRUE;
3260                         } else if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
3261
3262                             /* See Note on sizing above.  (NOTE: SvCUR() is not
3263                              * set correctly here). */
3264                             const STRLEN off = d - SvPVX_const(sv);
3265                             d = off + SvGROW(sv, off + len + (STRLEN)(send - s) + 1);
3266                         }
3267                         Copy(str, d, len, char);
3268                         d += len;
3269                     }
3270                     SvREFCNT_dec(res);
3271
3272                     /* Deprecate non-approved name syntax */
3273                     if (ckWARN_d(WARN_DEPRECATED)) {
3274                         bool problematic = FALSE;
3275                         char* i = s;
3276
3277                         /* For non-ut8 input, look to see that the first
3278                          * character is an alpha, then loop through the rest
3279                          * checking that each is a continuation */
3280                         if (! this_utf8) {
3281                             if (! isALPHAU(*i)) problematic = TRUE;
3282                             else for (i = s + 1; i < e; i++) {
3283                                 if (isCHARNAME_CONT(*i)) continue;
3284                                 problematic = TRUE;
3285                                 break;
3286                             }
3287                         }
3288                         else {
3289                             /* Similarly for utf8.  For invariants can check
3290                              * directly.  We accept anything above the latin1
3291                              * range because it is immaterial to Perl if it is
3292                              * correct or not, and is expensive to check.  But
3293                              * it is fairly easy in the latin1 range to convert
3294                              * the variants into a single character and check
3295                              * those */
3296                             if (UTF8_IS_INVARIANT(*i)) {
3297                                 if (! isALPHAU(*i)) problematic = TRUE;
3298                             } else if (UTF8_IS_DOWNGRADEABLE_START(*i)) {
3299                                 if (! isALPHAU(UNI_TO_NATIVE(UTF8_ACCUMULATE(*i,
3300                                                                             *(i+1)))))
3301                                 {
3302                                     problematic = TRUE;
3303                                 }
3304                             }
3305                             if (! problematic) for (i = s + UTF8SKIP(s);
3306                                                     i < e;
3307                                                     i+= UTF8SKIP(i))
3308                             {
3309                                 if (UTF8_IS_INVARIANT(*i)) {
3310                                     if (isCHARNAME_CONT(*i)) continue;
3311                                 } else if (! UTF8_IS_DOWNGRADEABLE_START(*i)) {
3312                                     continue;
3313                                 } else if (isCHARNAME_CONT(
3314                                             UNI_TO_NATIVE(
3315                                             UTF8_ACCUMULATE(*i, *(i+1)))))
3316                                 {
3317                                     continue;
3318                                 }
3319                                 problematic = TRUE;
3320                                 break;
3321                             }
3322                         }
3323                         if (problematic) {
3324                             /* The e-i passed to the final %.*s makes sure that
3325                              * should the trailing NUL be missing that this
3326                              * print won't run off the end of the string */
3327                             Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
3328                                         "Deprecated character in \\N{...}; marked by <-- HERE  in \\N{%.*s<-- HERE %.*s",
3329                                         (int)(i - s + 1), s, (int)(e - i), i + 1);
3330                         }
3331                     }
3332                 } /* End \N{NAME} */
3333 #ifdef EBCDIC
3334                 if (!dorange) 
3335                     native_range = FALSE; /* \N{} is defined to be Unicode */
3336 #endif
3337                 s = e + 1;  /* Point to just after the '}' */
3338                 continue;
3339
3340             /* \c is a control character */
3341             case 'c':
3342                 s++;
3343                 if (s < send) {
3344                     *d++ = grok_bslash_c(*s++, 1);
3345                 }
3346                 else {
3347                     yyerror("Missing control char name in \\c");
3348                 }
3349                 continue;
3350
3351             /* printf-style backslashes, formfeeds, newlines, etc */
3352             case 'b':
3353                 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
3354                 break;
3355             case 'n':
3356                 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
3357                 break;
3358             case 'r':
3359                 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
3360                 break;
3361             case 'f':
3362                 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
3363                 break;
3364             case 't':
3365                 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
3366                 break;
3367             case 'e':
3368                 *d++ = ASCII_TO_NEED(has_utf8,'\033');
3369                 break;
3370             case 'a':
3371                 *d++ = ASCII_TO_NEED(has_utf8,'\007');
3372                 break;
3373             } /* end switch */
3374
3375             s++;
3376             continue;
3377         } /* end if (backslash) */
3378 #ifdef EBCDIC
3379         else
3380             literal_endpoint++;
3381 #endif
3382
3383     default_action:
3384         /* If we started with encoded form, or already know we want it,
3385            then encode the next character */
3386         if (! NATIVE_IS_INVARIANT((U8)(*s)) && (this_utf8 || has_utf8)) {
3387             STRLEN len  = 1;
3388
3389
3390             /* One might think that it is wasted effort in the case of the
3391              * source being utf8 (this_utf8 == TRUE) to take the next character
3392              * in the source, convert it to an unsigned value, and then convert
3393              * it back again.  But the source has not been validated here.  The
3394              * routine that does the conversion checks for errors like
3395              * malformed utf8 */
3396
3397             const UV nextuv   = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
3398             const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
3399             if (!has_utf8) {
3400                 SvCUR_set(sv, d - SvPVX_const(sv));
3401                 SvPOK_on(sv);
3402                 *d = '\0';
3403                 /* See Note on sizing above.  */
3404                 sv_utf8_upgrade_flags_grow(sv,
3405                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3406                                         need + (STRLEN)(send - s) + 1);
3407                 d = SvPVX(sv) + SvCUR(sv);
3408                 has_utf8 = TRUE;
3409             } else if (need > len) {
3410                 /* encoded value larger than old, may need extra space (NOTE:
3411                  * SvCUR() is not set correctly here).   See Note on sizing
3412                  * above.  */
3413                 const STRLEN off = d - SvPVX_const(sv);
3414                 d = SvGROW(sv, off + need + (STRLEN)(send - s) + 1) + off;
3415             }
3416             s += len;
3417
3418             d = (char*)uvchr_to_utf8((U8*)d, nextuv);
3419 #ifdef EBCDIC
3420             if (uv > 255 && !dorange)
3421                 native_range = FALSE;
3422 #endif
3423         }
3424         else {
3425             *d++ = NATIVE_TO_NEED(has_utf8,*s++);
3426         }
3427     } /* while loop to process each character */
3428
3429     /* terminate the string and set up the sv */
3430     *d = '\0';
3431     SvCUR_set(sv, d - SvPVX_const(sv));
3432     if (SvCUR(sv) >= SvLEN(sv))
3433         Perl_croak(aTHX_ "panic: constant overflowed allocated space");
3434
3435     SvPOK_on(sv);
3436     if (PL_encoding && !has_utf8) {
3437         sv_recode_to_utf8(sv, PL_encoding);
3438         if (SvUTF8(sv))
3439             has_utf8 = TRUE;
3440     }
3441     if (has_utf8) {
3442         SvUTF8_on(sv);
3443         if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
3444             PL_sublex_info.sub_op->op_private |=
3445                     (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
3446         }
3447     }
3448
3449     /* shrink the sv if we allocated more than we used */
3450     if (SvCUR(sv) + 5 < SvLEN(sv)) {
3451         SvPV_shrink_to_cur(sv);
3452     }
3453
3454     /* return the substring (via pl_yylval) only if we parsed anything */
3455     if (s > PL_bufptr) {
3456         if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) {
3457             const char *const key = PL_lex_inpat ? "qr" : "q";
3458             const STRLEN keylen = PL_lex_inpat ? 2 : 1;
3459             const char *type;
3460             STRLEN typelen;
3461
3462             if (PL_lex_inwhat == OP_TRANS) {
3463                 type = "tr";
3464                 typelen = 2;
3465             } else if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) {
3466                 type = "s";
3467                 typelen = 1;
3468             } else  {
3469                 type = "qq";
3470                 typelen = 2;
3471             }
3472
3473             sv = S_new_constant(aTHX_ start, s - start, key, keylen, sv, NULL,
3474                                 type, typelen);
3475         }
3476         pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3477     } else
3478         SvREFCNT_dec(sv);
3479     return s;
3480 }
3481
3482 /* S_intuit_more
3483  * Returns TRUE if there's more to the expression (e.g., a subscript),
3484  * FALSE otherwise.
3485  *
3486  * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
3487  *
3488  * ->[ and ->{ return TRUE
3489  * { and [ outside a pattern are always subscripts, so return TRUE
3490  * if we're outside a pattern and it's not { or [, then return FALSE
3491  * if we're in a pattern and the first char is a {
3492  *   {4,5} (any digits around the comma) returns FALSE
3493  * if we're in a pattern and the first char is a [
3494  *   [] returns FALSE
3495  *   [SOMETHING] has a funky algorithm to decide whether it's a
3496  *      character class or not.  It has to deal with things like
3497  *      /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
3498  * anything else returns TRUE
3499  */
3500
3501 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
3502
3503 STATIC int
3504 S_intuit_more(pTHX_ register char *s)
3505 {
3506     dVAR;
3507
3508     PERL_ARGS_ASSERT_INTUIT_MORE;
3509
3510     if (PL_lex_brackets)
3511         return TRUE;
3512     if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
3513         return TRUE;
3514     if (*s != '{' && *s != '[')
3515         return FALSE;
3516     if (!PL_lex_inpat)
3517         return TRUE;
3518
3519     /* In a pattern, so maybe we have {n,m}. */
3520     if (*s == '{') {
3521         if (regcurly(s)) {
3522             return FALSE;
3523         }
3524         return TRUE;
3525     }
3526
3527     /* On the other hand, maybe we have a character class */
3528
3529     s++;
3530     if (*s == ']' || *s == '^')
3531         return FALSE;
3532     else {
3533         /* this is terrifying, and it works */
3534         int weight = 2;         /* let's weigh the evidence */
3535         char seen[256];
3536         unsigned char un_char = 255, last_un_char;
3537         const char * const send = strchr(s,']');
3538         char tmpbuf[sizeof PL_tokenbuf * 4];
3539
3540         if (!send)              /* has to be an expression */
3541             return TRUE;
3542
3543         Zero(seen,256,char);
3544         if (*s == '$')
3545             weight -= 3;
3546         else if (isDIGIT(*s)) {
3547             if (s[1] != ']') {
3548                 if (isDIGIT(s[1]) && s[2] == ']')
3549                     weight -= 10;
3550             }
3551             else
3552                 weight -= 100;
3553         }
3554         for (; s < send; s++) {
3555             last_un_char = un_char;
3556             un_char = (unsigned char)*s;
3557             switch (*s) {
3558             case '@':
3559             case '&':
3560             case '$':
3561                 weight -= seen[un_char] * 10;
3562                 if (isALNUM_lazy_if(s+1,UTF)) {
3563                     int len;
3564                     scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
3565                     len = (int)strlen(tmpbuf);
3566                     if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
3567                         weight -= 100;
3568                     else
3569                         weight -= 10;
3570                 }
3571                 else if (*s == '$' && s[1] &&
3572                   strchr("[#!%*<>()-=",s[1])) {
3573                     if (/*{*/ strchr("])} =",s[2]))
3574                         weight -= 10;
3575                     else
3576                         weight -= 1;
3577                 }
3578                 break;
3579             case '\\':
3580                 un_char = 254;
3581                 if (s[1]) {
3582                     if (strchr("wds]",s[1]))
3583                         weight += 100;
3584                     else if (seen[(U8)'\''] || seen[(U8)'"'])
3585                         weight += 1;
3586                     else if (strchr("rnftbxcav",s[1]))
3587                         weight += 40;
3588                     else if (isDIGIT(s[1])) {
3589                         weight += 40;
3590                         while (s[1] && isDIGIT(s[1]))
3591                             s++;
3592                     }
3593                 }
3594                 else
3595                     weight += 100;
3596                 break;
3597             case '-':
3598                 if (s[1] == '\\')
3599                     weight += 50;
3600                 if (strchr("aA01! ",last_un_char))
3601                     weight += 30;
3602                 if (strchr("zZ79~",s[1]))
3603                     weight += 30;
3604                 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
3605                     weight -= 5;        /* cope with negative subscript */
3606                 break;
3607             default:
3608                 if (!isALNUM(last_un_char)
3609                     && !(last_un_char == '$' || last_un_char == '@'
3610                          || last_un_char == '&')
3611                     && isALPHA(*s) && s[1] && isALPHA(s[1])) {
3612                     char *d = tmpbuf;
3613                     while (isALPHA(*s))
3614                         *d++ = *s++;
3615                     *d = '\0';
3616                     if (keyword(tmpbuf, d - tmpbuf, 0))
3617                         weight -= 150;
3618                 }
3619                 if (un_char == last_un_char + 1)
3620                     weight += 5;
3621                 weight -= seen[un_char];
3622                 break;
3623             }
3624             seen[un_char]++;
3625         }
3626         if (weight >= 0)        /* probably a character class */
3627             return FALSE;
3628     }
3629
3630     return TRUE;
3631 }
3632
3633 /*
3634  * S_intuit_method
3635  *
3636  * Does all the checking to disambiguate
3637  *   foo bar
3638  * between foo(bar) and bar->foo.  Returns 0 if not a method, otherwise
3639  * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
3640  *
3641  * First argument is the stuff after the first token, e.g. "bar".
3642  *
3643  * Not a method if bar is a filehandle.
3644  * Not a method if foo is a subroutine prototyped to take a filehandle.
3645  * Not a method if it's really "Foo $bar"
3646  * Method if it's "foo $bar"
3647  * Not a method if it's really "print foo $bar"
3648  * Method if it's really "foo package::" (interpreted as package->foo)
3649  * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
3650  * Not a method if bar is a filehandle or package, but is quoted with
3651  *   =>
3652  */
3653
3654 STATIC int
3655 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
3656 {
3657     dVAR;
3658     char *s = start + (*start == '$');
3659     char tmpbuf[sizeof PL_tokenbuf];
3660     STRLEN len;
3661     GV* indirgv;
3662 #ifdef PERL_MAD
3663     int soff;
3664 #endif
3665
3666     PERL_ARGS_ASSERT_INTUIT_METHOD;
3667
3668     if (gv) {
3669         if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
3670             return 0;
3671         if (cv) {
3672             if (SvPOK(cv)) {
3673                 const char *proto = SvPVX_const(cv);
3674                 if (proto) {
3675                     if (*proto == ';')
3676                         proto++;
3677                     if (*proto == '*')
3678                         return 0;
3679                 }
3680             }
3681         } else
3682             gv = NULL;
3683     }
3684     s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3685     /* start is the beginning of the possible filehandle/object,
3686      * and s is the end of it
3687      * tmpbuf is a copy of it
3688      */
3689
3690     if (*start == '$') {
3691         if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
3692                 isUPPER(*PL_tokenbuf))
3693             return 0;
3694 #ifdef PERL_MAD
3695         len = start - SvPVX(PL_linestr);
3696 #endif
3697         s = PEEKSPACE(s);
3698 #ifdef PERL_MAD
3699         start = SvPVX(PL_linestr) + len;
3700 #endif
3701         PL_bufptr = start;
3702         PL_expect = XREF;
3703         return *s == '(' ? FUNCMETH : METHOD;
3704     }
3705     if (!keyword(tmpbuf, len, 0)) {
3706         if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
3707             len -= 2;
3708             tmpbuf[len] = '\0';
3709 #ifdef PERL_MAD
3710             soff = s - SvPVX(PL_linestr);
3711 #endif
3712             goto bare_package;
3713         }
3714         indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
3715         if (indirgv && GvCVu(indirgv))
3716             return 0;
3717         /* filehandle or package name makes it a method */
3718         if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
3719 #ifdef PERL_MAD
3720             soff = s - SvPVX(PL_linestr);
3721 #endif
3722             s = PEEKSPACE(s);
3723             if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
3724                 return 0;       /* no assumptions -- "=>" quotes bearword */
3725       bare_package:
3726             start_force(PL_curforce);
3727             NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
3728                                                   S_newSV_maybe_utf8(aTHX_ tmpbuf, len));
3729             NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
3730             if (PL_madskills)
3731                 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
3732             PL_expect = XTERM;
3733             force_next(WORD);
3734             PL_bufptr = s;
3735 #ifdef PERL_MAD
3736             PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
3737 #endif
3738             return *s == '(' ? FUNCMETH : METHOD;
3739         }
3740     }
3741     return 0;
3742 }
3743
3744 /* Encoded script support. filter_add() effectively inserts a
3745  * 'pre-processing' function into the current source input stream.
3746  * Note that the filter function only applies to the current source file
3747  * (e.g., it will not affect files 'require'd or 'use'd by this one).
3748  *
3749  * The datasv parameter (which may be NULL) can be used to pass
3750  * private data to this instance of the filter. The filter function
3751  * can recover the SV using the FILTER_DATA macro and use it to
3752  * store private buffers and state information.
3753  *
3754  * The supplied datasv parameter is upgraded to a PVIO type
3755  * and the IoDIRP/IoANY field is used to store the function pointer,
3756  * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
3757  * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
3758  * private use must be set using malloc'd pointers.
3759  */
3760
3761 SV *
3762 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
3763 {
3764     dVAR;
3765     if (!funcp)
3766         return NULL;
3767
3768     if (!PL_parser)
3769         return NULL;
3770
3771     if (!PL_rsfp_filters)
3772         PL_rsfp_filters = newAV();
3773     if (!datasv)
3774         datasv = newSV(0);
3775     SvUPGRADE(datasv, SVt_PVIO);
3776     IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
3777     IoFLAGS(datasv) |= IOf_FAKE_DIRP;
3778     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
3779                           FPTR2DPTR(void *, IoANY(datasv)),
3780                           SvPV_nolen(datasv)));
3781     av_unshift(PL_rsfp_filters, 1);
3782     av_store(PL_rsfp_filters, 0, datasv) ;
3783     return(datasv);
3784 }
3785
3786
3787 /* Delete most recently added instance of this filter function. */
3788 void
3789 Perl_filter_del(pTHX_ filter_t funcp)
3790 {
3791     dVAR;
3792     SV *datasv;
3793
3794     PERL_ARGS_ASSERT_FILTER_DEL;
3795
3796 #ifdef DEBUGGING
3797     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
3798                           FPTR2DPTR(void*, funcp)));
3799 #endif
3800     if (!PL_parser || !PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
3801         return;
3802     /* if filter is on top of stack (usual case) just pop it off */
3803     datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
3804     if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
3805         sv_free(av_pop(PL_rsfp_filters));
3806
3807         return;
3808     }
3809     /* we need to search for the correct entry and clear it     */
3810     Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
3811 }
3812
3813
3814 /* Invoke the idxth filter function for the current rsfp.        */
3815 /* maxlen 0 = read one text line */
3816 I32
3817 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
3818 {
3819     dVAR;
3820     filter_t funcp;
3821     SV *datasv = NULL;
3822     /* This API is bad. It should have been using unsigned int for maxlen.
3823        Not sure if we want to change the API, but if not we should sanity
3824        check the value here.  */
3825     const unsigned int correct_length
3826         = maxlen < 0 ?
3827 #ifdef PERL_MICRO
3828         0x7FFFFFFF
3829 #else
3830         INT_MAX
3831 #endif
3832         : maxlen;
3833
3834     PERL_ARGS_ASSERT_FILTER_READ;
3835
3836     if (!PL_parser || !PL_rsfp_filters)
3837         return -1;
3838     if (idx > AvFILLp(PL_rsfp_filters)) {       /* Any more filters?    */
3839         /* Provide a default input filter to make life easy.    */
3840         /* Note that we append to the line. This is handy.      */
3841         DEBUG_P(PerlIO_printf(Perl_debug_log,
3842                               "filter_read %d: from rsfp\n", idx));
3843         if (correct_length) {
3844             /* Want a block */
3845             int len ;
3846             const int old_len = SvCUR(buf_sv);
3847
3848             /* ensure buf_sv is large enough */
3849             SvGROW(buf_sv, (STRLEN)(old_len + correct_length + 1)) ;
3850             if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
3851                                    correct_length)) <= 0) {
3852                 if (PerlIO_error(PL_rsfp))
3853                     return -1;          /* error */
3854                 else
3855                     return 0 ;          /* end of file */
3856             }
3857             SvCUR_set(buf_sv, old_len + len) ;
3858             SvPVX(buf_sv)[old_len + len] = '\0';
3859         } else {
3860             /* Want a line */
3861             if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
3862                 if (PerlIO_error(PL_rsfp))
3863                     return -1;          /* error */
3864                 else
3865                     return 0 ;          /* end of file */
3866             }
3867         }
3868         return SvCUR(buf_sv);
3869     }
3870     /* Skip this filter slot if filter has been deleted */
3871     if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
3872         DEBUG_P(PerlIO_printf(Perl_debug_log,
3873                               "filter_read %d: skipped (filter deleted)\n",
3874                               idx));
3875         return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
3876     }
3877     /* Get function pointer hidden within datasv        */
3878     funcp = DPTR2FPTR(filter_t, IoANY(datasv));
3879     DEBUG_P(PerlIO_printf(Perl_debug_log,
3880                           "filter_read %d: via function %p (%s)\n",
3881                           idx, (void*)datasv, SvPV_nolen_const(datasv)));
3882     /* Call function. The function is expected to       */
3883     /* call "FILTER_READ(idx+1, buf_sv)" first.         */
3884     /* Return: <0:error, =0:eof, >0:not eof             */
3885     return (*funcp)(aTHX_ idx, buf_sv, correct_length);
3886 }
3887
3888 STATIC char *
3889 S_filter_gets(pTHX_ register SV *sv, STRLEN append)
3890 {
3891     dVAR;
3892
3893     PERL_ARGS_ASSERT_FILTER_GETS;
3894
3895 #ifdef PERL_CR_FILTER
3896     if (!PL_rsfp_filters) {
3897         filter_add(S_cr_textfilter,NULL);
3898     }
3899 #endif
3900     if (PL_rsfp_filters) {
3901         if (!append)
3902             SvCUR_set(sv, 0);   /* start with empty line        */
3903         if (FILTER_READ(0, sv, 0) > 0)
3904             return ( SvPVX(sv) ) ;
3905         else
3906             return NULL ;
3907     }
3908     else
3909         return (sv_gets(sv, PL_rsfp, append));
3910 }
3911
3912 STATIC HV *
3913 S_find_in_my_stash(pTHX_ const char *pkgname, STRLEN len)
3914 {
3915     dVAR;
3916     GV *gv;
3917
3918     PERL_ARGS_ASSERT_FIND_IN_MY_STASH;
3919
3920     if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
3921         return PL_curstash;
3922
3923     if (len > 2 &&
3924         (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
3925         (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
3926     {
3927         return GvHV(gv);                        /* Foo:: */
3928     }
3929
3930     /* use constant CLASS => 'MyClass' */
3931     gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
3932     if (gv && GvCV(gv)) {
3933         SV * const sv = cv_const_sv(GvCV(gv));
3934         if (sv)
3935             pkgname = SvPV_const(sv, len);
3936     }
3937
3938     return gv_stashpvn(pkgname, len, 0);
3939 }
3940
3941 /*
3942  * S_readpipe_override
3943  * Check whether readpipe() is overriden, and generates the appropriate
3944  * optree, provided sublex_start() is called afterwards.
3945  */
3946 STATIC void
3947 S_readpipe_override(pTHX)
3948 {
3949     GV **gvp;
3950     GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
3951     pl_yylval.ival = OP_BACKTICK;
3952     if ((gv_readpipe
3953                 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
3954             ||
3955             ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
3956              && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
3957              && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
3958     {
3959         PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
3960             op_append_elem(OP_LIST,
3961                 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
3962                 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
3963     }
3964 }
3965
3966 #ifdef PERL_MAD 
3967  /*
3968  * Perl_madlex
3969  * The intent of this yylex wrapper is to minimize the changes to the
3970  * tokener when we aren't interested in collecting madprops.  It remains
3971  * to be seen how successful this strategy will be...
3972  */
3973
3974 int
3975 Perl_madlex(pTHX)
3976 {
3977     int optype;
3978     char *s = PL_bufptr;
3979
3980     /* make sure PL_thiswhite is initialized */
3981     PL_thiswhite = 0;
3982     PL_thismad = 0;
3983
3984     /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
3985     if (PL_lex_state != LEX_KNOWNEXT && PL_pending_ident)
3986         return S_pending_ident(aTHX);
3987
3988     /* previous token ate up our whitespace? */
3989     if (!PL_lasttoke && PL_nextwhite) {
3990         PL_thiswhite = PL_nextwhite;
3991         PL_nextwhite = 0;
3992     }
3993
3994     /* isolate the token, and figure out where it is without whitespace */
3995     PL_realtokenstart = -1;
3996     PL_thistoken = 0;
3997     optype = yylex();
3998     s = PL_bufptr;
3999     assert(PL_curforce < 0);
4000
4001     if (!PL_thismad || PL_thismad->mad_key == '^') {    /* not forced already? */
4002         if (!PL_thistoken) {
4003             if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
4004                 PL_thistoken = newSVpvs("");
4005             else {
4006                 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
4007                 PL_thistoken = newSVpvn(tstart, s - tstart);
4008             }
4009         }
4010         if (PL_thismad) /* install head */
4011             CURMAD('X', PL_thistoken);
4012     }
4013
4014     /* last whitespace of a sublex? */
4015     if (optype == ')' && PL_endwhite) {
4016         CURMAD('X', PL_endwhite);
4017     }
4018
4019     if (!PL_thismad) {
4020
4021         /* if no whitespace and we're at EOF, bail.  Otherwise fake EOF below. */
4022         if (!PL_thiswhite && !PL_endwhite && !optype) {
4023             sv_free(PL_thistoken);
4024             PL_thistoken = 0;
4025             return 0;
4026         }
4027
4028         /* put off final whitespace till peg */
4029         if (optype == ';' && !PL_rsfp) {
4030             PL_nextwhite = PL_thiswhite;
4031             PL_thiswhite = 0;
4032         }
4033         else if (PL_thisopen) {
4034             CURMAD('q', PL_thisopen);
4035             if (PL_thistoken)
4036                 sv_free(PL_thistoken);
4037             PL_thistoken = 0;
4038         }
4039         else {
4040             /* Store actual token text as madprop X */
4041             CURMAD('X', PL_thistoken);
4042         }
4043
4044         if (PL_thiswhite) {
4045             /* add preceding whitespace as madprop _ */
4046             CURMAD('_', PL_thiswhite);
4047         }
4048
4049         if (PL_thisstuff) {
4050             /* add quoted material as madprop = */
4051             CURMAD('=', PL_thisstuff);
4052         }
4053
4054         if (PL_thisclose) {
4055             /* add terminating quote as madprop Q */
4056             CURMAD('Q', PL_thisclose);
4057         }
4058     }
4059
4060     /* special processing based on optype */
4061
4062     switch (optype) {
4063
4064     /* opval doesn't need a TOKEN since it can already store mp */
4065     case WORD:
4066     case METHOD:
4067     case FUNCMETH:
4068     case THING:
4069     case PMFUNC:
4070     case PRIVATEREF:
4071     case FUNC0SUB:
4072     case UNIOPSUB:
4073     case LSTOPSUB:
4074         if (pl_yylval.opval)
4075             append_madprops(PL_thismad, pl_yylval.opval, 0);
4076         PL_thismad = 0;
4077         return optype;
4078
4079     /* fake EOF */
4080     case 0:
4081         optype = PEG;
4082         if (PL_endwhite) {
4083             addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
4084             PL_endwhite = 0;
4085         }
4086         break;
4087
4088     case ']':
4089     case '}':
4090         if (PL_faketokens)
4091             break;
4092         /* remember any fake bracket that lexer is about to discard */ 
4093         if (PL_lex_brackets == 1 &&
4094             ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
4095         {
4096             s = PL_bufptr;
4097             while (s < PL_bufend && (*s == ' ' || *s == '\t'))
4098                 s++;
4099             if (*s == '}') {
4100                 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
4101                 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
4102                 PL_thiswhite = 0;
4103                 PL_bufptr = s - 1;
4104                 break;  /* don't bother looking for trailing comment */
4105             }
4106             else
4107                 s = PL_bufptr;
4108         }
4109         if (optype == ']')
4110             break;
4111         /* FALLTHROUGH */
4112
4113     /* attach a trailing comment to its statement instead of next token */
4114     case ';':
4115         if (PL_faketokens)
4116             break;
4117         if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
4118             s = PL_bufptr;
4119             while (s < PL_bufend && (*s == ' ' || *s == '\t'))
4120                 s++;
4121             if (*s == '\n' || *s == '#') {
4122                 while (s < PL_bufend && *s != '\n')
4123                     s++;
4124                 if (s < PL_bufend)
4125                     s++;
4126                 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
4127                 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
4128                 PL_thiswhite = 0;
4129                 PL_bufptr = s;
4130             }
4131         }
4132         break;
4133
4134     /* pval */
4135     case LABEL:
4136         break;
4137
4138     /* ival */
4139     default:
4140         break;
4141
4142     }
4143
4144     /* Create new token struct.  Note: opvals return early above. */
4145     pl_yylval.tkval = newTOKEN(optype, pl_yylval, PL_thismad);
4146     PL_thismad = 0;
4147     return optype;
4148 }
4149 #endif
4150
4151 STATIC char *
4152 S_tokenize_use(pTHX_ int is_use, char *s) {
4153     dVAR;
4154
4155     PERL_ARGS_ASSERT_TOKENIZE_USE;
4156
4157     if (PL_expect != XSTATE)
4158         yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
4159                     is_use ? "use" : "no"));
4160     s = SKIPSPACE1(s);
4161     if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
4162         s = force_version(s, TRUE);
4163         if (*s == ';' || *s == '}'
4164                 || (s = SKIPSPACE1(s), (*s == ';' || *s == '}'))) {
4165             start_force(PL_curforce);
4166             NEXTVAL_NEXTTOKE.opval = NULL;
4167             force_next(WORD);
4168         }
4169         else if (*s == 'v') {
4170             s = force_word(s,WORD,FALSE,TRUE,FALSE);
4171             s = force_version(s, FALSE);
4172         }
4173     }
4174     else {
4175         s = force_word(s,WORD,FALSE,TRUE,FALSE);
4176         s = force_version(s, FALSE);
4177     }
4178     pl_yylval.ival = is_use;
4179     return s;
4180 }
4181 #ifdef DEBUGGING
4182     static const char* const exp_name[] =
4183         { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
4184           "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
4185         };
4186 #endif
4187
4188 #define word_takes_any_delimeter(p,l) S_word_takes_any_delimeter(p,l)
4189 STATIC bool
4190 S_word_takes_any_delimeter(char *p, STRLEN len)
4191 {
4192     return (len == 1 && strchr("msyq", p[0])) ||
4193            (len == 2 && (
4194             (p[0] == 't' && p[1] == 'r') ||
4195             (p[0] == 'q' && strchr("qwxr", p[1]))));
4196 }
4197
4198 /*
4199   yylex
4200
4201   Works out what to call the token just pulled out of the input
4202   stream.  The yacc parser takes care of taking the ops we return and
4203   stitching them into a tree.
4204
4205   Returns:
4206     PRIVATEREF
4207
4208   Structure:
4209       if read an identifier
4210           if we're in a my declaration
4211               croak if they tried to say my($foo::bar)
4212               build the ops for a my() declaration
4213           if it's an access to a my() variable
4214               are we in a sort block?
4215                   croak if my($a); $a <=> $b
4216               build ops for access to a my() variable
4217           if in a dq string, and they've said @foo and we can't find @foo
4218               croak
4219           build ops for a bareword
4220       if we already built the token before, use it.
4221 */
4222
4223
4224 #ifdef __SC__
4225 #pragma segment Perl_yylex
4226 #endif
4227 int
4228 Perl_yylex(pTHX)
4229 {
4230     dVAR;
4231     register char *s = PL_bufptr;
4232     register char *d;
4233     STRLEN len;
4234     bool bof = FALSE;
4235     U32 fake_eof = 0;
4236
4237     /* orig_keyword, gvp, and gv are initialized here because
4238      * jump to the label just_a_word_zero can bypass their
4239      * initialization later. */
4240     I32 orig_keyword = 0;
4241     GV *gv = NULL;
4242     GV **gvp = NULL;
4243
4244     DEBUG_T( {
4245         SV* tmp = newSVpvs("");
4246         PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
4247             (IV)CopLINE(PL_curcop),
4248             lex_state_names[PL_lex_state],
4249             exp_name[PL_expect],
4250             pv_display(tmp, s, strlen(s), 0, 60));
4251         SvREFCNT_dec(tmp);
4252     } );
4253     /* check if there's an identifier for us to look at */
4254     if (PL_lex_state != LEX_KNOWNEXT && PL_pending_ident)
4255         return REPORT(S_pending_ident(aTHX));
4256
4257     /* no identifier pending identification */
4258
4259     switch (PL_lex_state) {
4260 #ifdef COMMENTARY
4261     case LEX_NORMAL:            /* Some compilers will produce faster */
4262     case LEX_INTERPNORMAL:      /* code if we comment these out. */
4263         break;
4264 #endif
4265
4266     /* when we've already built the next token, just pull it out of the queue */
4267     case LEX_KNOWNEXT:
4268 #ifdef PERL_MAD
4269         PL_lasttoke--;
4270         pl_yylval = PL_nexttoke[PL_lasttoke].next_val;
4271         if (PL_madskills) {
4272             PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
4273             PL_nexttoke[PL_lasttoke].next_mad = 0;
4274             if (PL_thismad && PL_thismad->mad_key == '_') {
4275                 PL_thiswhite = MUTABLE_SV(PL_thismad->mad_val);
4276                 PL_thismad->mad_val = 0;
4277                 mad_free(PL_thismad);
4278                 PL_thismad = 0;
4279             }
4280         }
4281         if (!PL_lasttoke) {
4282             PL_lex_state = PL_lex_defer;
4283             PL_expect = PL_lex_expect;
4284             PL_lex_defer = LEX_NORMAL;
4285             if (!PL_nexttoke[PL_lasttoke].next_type)
4286                 return yylex();
4287         }
4288 #else
4289         PL_nexttoke--;
4290         pl_yylval = PL_nextval[PL_nexttoke];
4291         if (!PL_nexttoke) {
4292             PL_lex_state = PL_lex_defer;
4293             PL_expect = PL_lex_expect;
4294             PL_lex_defer = LEX_NORMAL;
4295         }
4296 #endif
4297         {
4298             I32 next_type;
4299 #ifdef PERL_MAD
4300             next_type = PL_nexttoke[PL_lasttoke].next_type;
4301 #else
4302             next_type = PL_nexttype[PL_nexttoke];
4303 #endif
4304             if (next_type & (1<<24)) {
4305                 if (PL_lex_brackets > 100)
4306                     Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4307                 PL_lex_brackstack[PL_lex_brackets++] = (next_type >> 16) & 0xff;
4308                 next_type &= 0xffff;
4309             }
4310 #ifdef PERL_MAD
4311             /* FIXME - can these be merged?  */
4312             return next_type;
4313 #else
4314             return REPORT(next_type);
4315 #endif
4316         }
4317
4318     /* interpolated case modifiers like \L \U, including \Q and \E.
4319        when we get here, PL_bufptr is at the \
4320     */
4321     case LEX_INTERPCASEMOD:
4322 #ifdef DEBUGGING
4323         if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
4324             Perl_croak(aTHX_ "panic: INTERPCASEMOD");
4325 #endif
4326         /* handle \E or end of string */
4327         if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
4328             /* if at a \E */
4329             if (PL_lex_casemods) {
4330                 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
4331                 PL_lex_casestack[PL_lex_casemods] = '\0';
4332
4333                 if (PL_bufptr != PL_bufend
4334                     && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
4335                     PL_bufptr += 2;
4336                     PL_lex_state = LEX_INTERPCONCAT;
4337 #ifdef PERL_MAD
4338                     if (PL_madskills)
4339                         PL_thistoken = newSVpvs("\\E");
4340 #endif
4341                 }
4342                 return REPORT(')');
4343             }
4344 #ifdef PERL_MAD
4345             while (PL_bufptr != PL_bufend &&
4346               PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
4347                 if (!PL_thiswhite)
4348                     PL_thiswhite = newSVpvs("");
4349                 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
4350                 PL_bufptr += 2;
4351             }
4352 #else
4353             if (PL_bufptr != PL_bufend)
4354                 PL_bufptr += 2;
4355 #endif
4356             PL_lex_state = LEX_INTERPCONCAT;
4357             return yylex();
4358         }
4359         else {
4360             DEBUG_T({ PerlIO_printf(Perl_debug_log,
4361               "### Saw case modifier\n"); });
4362             s = PL_bufptr + 1;
4363             if (s[1] == '\\' && s[2] == 'E') {
4364 #ifdef PERL_MAD
4365                 if (!PL_thiswhite)
4366                     PL_thiswhite = newSVpvs("");
4367                 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
4368 #endif
4369                 PL_bufptr = s + 3;
4370                 PL_lex_state = LEX_INTERPCONCAT;
4371                 return yylex();
4372             }
4373             else {
4374                 I32 tmp;
4375                 if (!PL_madskills) /* when just compiling don't need correct */
4376                     if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
4377                         tmp = *s, *s = s[2], s[2] = (char)tmp;  /* misordered... */
4378                 if ((*s == 'L' || *s == 'U') &&
4379                     (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
4380                     PL_lex_casestack[--PL_lex_casemods] = '\0';
4381                     return REPORT(')');
4382                 }
4383                 if (PL_lex_casemods > 10)
4384                     Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
4385                 PL_lex_casestack[PL_lex_casemods++] = *s;
4386                 PL_lex_casestack[PL_lex_casemods] = '\0';
4387                 PL_lex_state = LEX_INTERPCONCAT;
4388                 start_force(PL_curforce);
4389                 NEXTVAL_NEXTTOKE.ival = 0;
4390                 force_next('(');
4391                 start_force(PL_curforce);
4392                 if (*s == 'l')
4393                     NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
4394                 else if (*s == 'u')
4395                     NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
4396                 else if (*s == 'L')
4397                     NEXTVAL_NEXTTOKE.ival = OP_LC;
4398                 else if (*s == 'U')
4399                     NEXTVAL_NEXTTOKE.ival = OP_UC;
4400                 else if (*s == 'Q')
4401                     NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
4402                 else
4403                     Perl_croak(aTHX_ "panic: yylex");
4404                 if (PL_madskills) {
4405                     SV* const tmpsv = newSVpvs("\\ ");
4406                     /* replace the space with the character we want to escape
4407                      */
4408                     SvPVX(tmpsv)[1] = *s;
4409                     curmad('_', tmpsv);
4410                 }
4411                 PL_bufptr = s + 1;
4412             }
4413             force_next(FUNC);
4414             if (PL_lex_starts) {
4415                 s = PL_bufptr;
4416                 PL_lex_starts = 0;
4417 #ifdef PERL_MAD
4418                 if (PL_madskills) {
4419                     if (PL_thistoken)
4420                         sv_free(PL_thistoken);
4421                     PL_thistoken = newSVpvs("");
4422                 }
4423 #endif
4424                 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4425                 if (PL_lex_casemods == 1 && PL_lex_inpat)
4426                     OPERATOR(',');
4427                 else
4428                     Aop(OP_CONCAT);
4429             }
4430             else
4431                 return yylex();
4432         }
4433
4434     case LEX_INTERPPUSH:
4435         return REPORT(sublex_push());
4436
4437     case LEX_INTERPSTART:
4438         if (PL_bufptr == PL_bufend)
4439             return REPORT(sublex_done());
4440         DEBUG_T({ PerlIO_printf(Perl_debug_log,
4441               "### Interpolated variable\n"); });
4442         PL_expect = XTERM;
4443         PL_lex_dojoin = (*PL_bufptr == '@');
4444         PL_lex_state = LEX_INTERPNORMAL;
4445         if (PL_lex_dojoin) {
4446             start_force(PL_curforce);
4447             NEXTVAL_NEXTTOKE.ival = 0;
4448             force_next(',');
4449             start_force(PL_curforce);
4450             force_ident("\"", '$');
4451             start_force(PL_curforce);
4452             NEXTVAL_NEXTTOKE.ival = 0;
4453             force_next('$');
4454             start_force(PL_curforce);
4455             NEXTVAL_NEXTTOKE.ival = 0;
4456             force_next('(');
4457             start_force(PL_curforce);
4458             NEXTVAL_NEXTTOKE.ival = OP_JOIN;    /* emulate join($", ...) */
4459             force_next(FUNC);
4460         }
4461         if (PL_lex_starts++) {
4462             s = PL_bufptr;
4463 #ifdef PERL_MAD
4464             if (PL_madskills) {
4465                 if (PL_thistoken)
4466                     sv_free(PL_thistoken);
4467                 PL_thistoken = newSVpvs("");
4468             }
4469 #endif
4470             /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4471             if (!PL_lex_casemods && PL_lex_inpat)
4472                 OPERATOR(',');
4473             else
4474                 Aop(OP_CONCAT);
4475         }
4476         return yylex();
4477
4478     case LEX_INTERPENDMAYBE:
4479         if (intuit_more(PL_bufptr)) {
4480             PL_lex_state = LEX_INTERPNORMAL;    /* false alarm, more expr */
4481             break;
4482         }
4483         /* FALL THROUGH */
4484
4485     case LEX_INTERPEND:
4486         if (PL_lex_dojoin) {
4487             PL_lex_dojoin = FALSE;
4488             PL_lex_state = LEX_INTERPCONCAT;
4489 #ifdef PERL_MAD
4490             if (PL_madskills) {
4491                 if (PL_thistoken)
4492                     sv_free(PL_thistoken);
4493                 PL_thistoken = newSVpvs("");
4494             }
4495 #endif
4496             return REPORT(')');
4497         }
4498         if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
4499             && SvEVALED(PL_lex_repl))
4500         {
4501             if (PL_bufptr != PL_bufend)
4502                 Perl_croak(aTHX_ "Bad evalled substitution pattern");
4503             PL_lex_repl = NULL;
4504         }
4505         /* FALLTHROUGH */
4506     case LEX_INTERPCONCAT:
4507 #ifdef DEBUGGING
4508         if (PL_lex_brackets)
4509             Perl_croak(aTHX_ "panic: INTERPCONCAT");
4510 #endif
4511         if (PL_bufptr == PL_bufend)
4512             return REPORT(sublex_done());
4513
4514         if (SvIVX(PL_linestr) == '\'') {
4515             SV *sv = newSVsv(PL_linestr);
4516             if (!PL_lex_inpat)
4517                 sv = tokeq(sv);
4518             else if ( PL_hints & HINT_NEW_RE )
4519                 sv = new_constant(NULL, 0, "qr", sv, sv, "q", 1);
4520             pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4521             s = PL_bufend;
4522         }
4523         else {
4524             s = scan_const(PL_bufptr);
4525             if (*s == '\\')
4526                 PL_lex_state = LEX_INTERPCASEMOD;
4527             else
4528                 PL_lex_state = LEX_INTERPSTART;
4529         }
4530
4531         if (s != PL_bufptr) {
4532             start_force(PL_curforce);
4533             if (PL_madskills) {
4534                 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
4535             }
4536             NEXTVAL_NEXTTOKE = pl_yylval;
4537             PL_expect = XTERM;
4538             force_next(THING);
4539             if (PL_lex_starts++) {
4540 #ifdef PERL_MAD
4541                 if (PL_madskills) {
4542                     if (PL_thistoken)
4543                         sv_free(PL_thistoken);
4544                     PL_thistoken = newSVpvs("");
4545                 }
4546 #endif
4547                 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4548                 if (!PL_lex_casemods && PL_lex_inpat)
4549                     OPERATOR(',');
4550                 else
4551                     Aop(OP_CONCAT);
4552             }
4553             else {
4554                 PL_bufptr = s;
4555                 return yylex();
4556             }
4557         }
4558
4559         return yylex();
4560     case LEX_FORMLINE:
4561         PL_lex_state = LEX_NORMAL;
4562         s = scan_formline(PL_bufptr);
4563         if (!PL_lex_formbrack)
4564             goto rightbracket;
4565         OPERATOR(';');
4566     }
4567
4568     s = PL_bufptr;
4569     PL_oldoldbufptr = PL_oldbufptr;
4570     PL_oldbufptr = s;
4571
4572   retry:
4573 #ifdef PERL_MAD
4574     if (PL_thistoken) {
4575         sv_free(PL_thistoken);
4576         PL_thistoken = 0;
4577     }
4578     PL_realtokenstart = s - SvPVX(PL_linestr);  /* assume but undo on ws */
4579 #endif
4580     switch (*s) {
4581     default:
4582         if (isIDFIRST_lazy_if(s,UTF))
4583             goto keylookup;
4584         {
4585         unsigned char c = *s;
4586         len = UTF ? Perl_utf8_length(aTHX_ (U8 *) PL_linestart, (U8 *) s) : (STRLEN) (s - PL_linestart);
4587         if (len > UNRECOGNIZED_PRECEDE_COUNT) {
4588             d = UTF ? (char *) Perl_utf8_hop(aTHX_ (U8 *) s, -UNRECOGNIZED_PRECEDE_COUNT) : s - UNRECOGNIZED_PRECEDE_COUNT;
4589         } else {
4590             d = PL_linestart;
4591         }       
4592         *s = '\0';
4593         Perl_croak(aTHX_ "Unrecognized character \\x%02X; marked by <-- HERE after %s<-- HERE near column %d", c, d, (int) len + 1);
4594     }
4595     case 4:
4596     case 26:
4597         goto fake_eof;                  /* emulate EOF on ^D or ^Z */
4598     case 0:
4599 #ifdef PERL_MAD
4600         if (PL_madskills)
4601             PL_faketokens = 0;
4602 #endif
4603         if (!PL_rsfp) {
4604             PL_last_uni = 0;
4605             PL_last_lop = 0;
4606             if (PL_lex_brackets &&
4607                     PL_lex_brackstack[PL_lex_brackets-1] != XFAKEEOF) {
4608                 yyerror((const char *)
4609                         (PL_lex_formbrack
4610                          ? "Format not terminated"
4611                          : "Missing right curly or square bracket"));
4612             }
4613             DEBUG_T( { PerlIO_printf(Perl_debug_log,
4614                         "### Tokener got EOF\n");
4615             } );
4616             TOKEN(0);
4617         }
4618         if (s++ < PL_bufend)
4619             goto retry;                 /* ignore stray nulls */
4620         PL_last_uni = 0;
4621         PL_last_lop = 0;
4622         if (!PL_in_eval && !PL_preambled) {
4623             PL_preambled = TRUE;
4624 #ifdef PERL_MAD
4625             if (PL_madskills)
4626                 PL_faketokens = 1;
4627 #endif
4628             if (PL_perldb) {
4629                 /* Generate a string of Perl code to load the debugger.
4630                  * If PERL5DB is set, it will return the contents of that,
4631                  * otherwise a compile-time require of perl5db.pl.  */
4632
4633                 const char * const pdb = PerlEnv_getenv("PERL5DB");
4634
4635                 if (pdb) {
4636                     sv_setpv(PL_linestr, pdb);
4637                     sv_catpvs(PL_linestr,";");
4638                 } else {
4639                     SETERRNO(0,SS_NORMAL);
4640                     sv_setpvs(PL_linestr, "BEGIN { require 'perl5db.pl' };");
4641                 }
4642             } else
4643                 sv_setpvs(PL_linestr,"");
4644             if (PL_preambleav) {
4645                 SV **svp = AvARRAY(PL_preambleav);
4646                 SV **const end = svp + AvFILLp(PL_preambleav);
4647                 while(svp <= end) {
4648                     sv_catsv(PL_linestr, *svp);
4649                     ++svp;
4650                     sv_catpvs(PL_linestr, ";");
4651                 }
4652                 sv_free(MUTABLE_SV(PL_preambleav));
4653                 PL_preambleav = NULL;
4654             }
4655             if (PL_minus_E)
4656                 sv_catpvs(PL_linestr,
4657                           "use feature ':5." STRINGIFY(PERL_VERSION) "';");
4658             if (PL_minus_n || PL_minus_p) {
4659                 sv_catpvs(PL_linestr, "LINE: while (<>) {"/*}*/);
4660                 if (PL_minus_l)
4661                     sv_catpvs(PL_linestr,"chomp;");
4662                 if (PL_minus_a) {
4663                     if (PL_minus_F) {
4664                         if ((*PL_splitstr == '/' || *PL_splitstr == '\''
4665                              || *PL_splitstr == '"')
4666                               && strchr(PL_splitstr + 1, *PL_splitstr))
4667                             Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
4668                         else {
4669                             /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
4670                                bytes can be used as quoting characters.  :-) */
4671                             const char *splits = PL_splitstr;
4672                             sv_catpvs(PL_linestr, "our @F=split(q\0");
4673                             do {
4674                                 /* Need to \ \s  */
4675                                 if (*splits == '\\')
4676                                     sv_catpvn(PL_linestr, splits, 1);
4677                                 sv_catpvn(PL_linestr, splits, 1);
4678                             } while (*splits++);
4679                             /* This loop will embed the trailing NUL of
4680                                PL_linestr as the last thing it does before
4681                                terminating.  */
4682                             sv_catpvs(PL_linestr, ");");
4683                         }
4684                     }
4685                     else
4686                         sv_catpvs(PL_linestr,"our @F=split(' ');");
4687                 }
4688             }
4689             sv_catpvs(PL_linestr, "\n");
4690             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4691             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4692             PL_last_lop = PL_last_uni = NULL;
4693             if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
4694                 update_debugger_info(PL_linestr, NULL, 0);
4695             goto retry;
4696         }
4697         do {
4698             fake_eof = 0;
4699             bof = PL_rsfp ? TRUE : FALSE;
4700             if (0) {
4701               fake_eof:
4702                 fake_eof = LEX_FAKE_EOF;
4703             }
4704             PL_bufptr = PL_bufend;
4705             CopLINE_inc(PL_curcop);
4706             if (!lex_next_chunk(fake_eof)) {
4707                 CopLINE_dec(PL_curcop);
4708                 s = PL_bufptr;
4709                 TOKEN(';');     /* not infinite loop because rsfp is NULL now */
4710             }
4711             CopLINE_dec(PL_curcop);
4712 #ifdef PERL_MAD
4713             if (!PL_rsfp)
4714                 PL_realtokenstart = -1;
4715 #endif
4716             s = PL_bufptr;
4717             /* If it looks like the start of a BOM or raw UTF-16,
4718              * check if it in fact is. */
4719             if (bof && PL_rsfp &&
4720                      (*s == 0 ||
4721                       *(U8*)s == 0xEF ||
4722                       *(U8*)s >= 0xFE ||
4723                       s[1] == 0)) {
4724                 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
4725                 if (bof) {
4726                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4727                     s = swallow_bom((U8*)s);
4728                 }
4729             }
4730             if (PL_parser->in_pod) {
4731                 /* Incest with pod. */
4732 #ifdef PERL_MAD
4733                 if (PL_madskills)
4734                     sv_catsv(PL_thiswhite, PL_linestr);
4735 #endif
4736                 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
4737                     sv_setpvs(PL_linestr, "");
4738                     PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4739                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4740                     PL_last_lop = PL_last_uni = NULL;
4741                     PL_parser->in_pod = 0;
4742                 }
4743             }
4744             if (PL_rsfp)
4745                 incline(s);
4746         } while (PL_parser->in_pod);
4747         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
4748         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4749         PL_last_lop = PL_last_uni = NULL;
4750         if (CopLINE(PL_curcop) == 1) {
4751             while (s < PL_bufend && isSPACE(*s))
4752                 s++;
4753             if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
4754                 s++;
4755 #ifdef PERL_MAD
4756             if (PL_madskills)
4757                 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
4758 #endif
4759             d = NULL;
4760             if (!PL_in_eval) {
4761                 if (*s == '#' && *(s+1) == '!')
4762                     d = s + 2;
4763 #ifdef ALTERNATE_SHEBANG
4764                 else {
4765                     static char const as[] = ALTERNATE_SHEBANG;
4766                     if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
4767                         d = s + (sizeof(as) - 1);
4768                 }
4769 #endif /* ALTERNATE_SHEBANG */
4770             }
4771             if (d) {
4772                 char *ipath;
4773                 char *ipathend;
4774
4775                 while (isSPACE(*d))
4776                     d++;
4777                 ipath = d;
4778                 while (*d && !isSPACE(*d))
4779                     d++;
4780                 ipathend = d;
4781
4782 #ifdef ARG_ZERO_IS_SCRIPT
4783                 if (ipathend > ipath) {
4784                     /*
4785                      * HP-UX (at least) sets argv[0] to the script name,
4786                      * which makes $^X incorrect.  And Digital UNIX and Linux,
4787                      * at least, set argv[0] to the basename of the Perl
4788                      * interpreter. So, having found "#!", we'll set it right.
4789                      */
4790                     SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
4791                                                     SVt_PV)); /* $^X */
4792                     assert(SvPOK(x) || SvGMAGICAL(x));
4793                     if (sv_eq(x, CopFILESV(PL_curcop))) {
4794                         sv_setpvn(x, ipath, ipathend - ipath);
4795                         SvSETMAGIC(x);
4796                     }
4797                     else {
4798                         STRLEN blen;
4799                         STRLEN llen;
4800                         const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
4801                         const char * const lstart = SvPV_const(x,llen);
4802                         if (llen < blen) {
4803                             bstart += blen - llen;
4804                             if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
4805                                 sv_setpvn(x, ipath, ipathend - ipath);
4806                                 SvSETMAGIC(x);
4807                             }
4808                         }
4809                     }
4810                     TAINT_NOT;  /* $^X is always tainted, but that's OK */
4811                 }
4812 #endif /* ARG_ZERO_IS_SCRIPT */
4813
4814                 /*
4815                  * Look for options.
4816                  */
4817                 d = instr(s,"perl -");
4818                 if (!d) {
4819                     d = instr(s,"perl");
4820 #if defined(DOSISH)
4821                     /* avoid getting into infinite loops when shebang
4822                      * line contains "Perl" rather than "perl" */
4823                     if (!d) {
4824                         for (d = ipathend-4; d >= ipath; --d) {
4825                             if ((*d == 'p' || *d == 'P')
4826                                 && !ibcmp(d, "perl", 4))
4827                             {
4828                                 break;
4829                             }
4830                         }
4831                         if (d < ipath)
4832                             d = NULL;
4833                     }
4834 #endif
4835                 }
4836 #ifdef ALTERNATE_SHEBANG
4837                 /*
4838                  * If the ALTERNATE_SHEBANG on this system starts with a
4839                  * character that can be part of a Perl expression, then if
4840                  * we see it but not "perl", we're probably looking at the
4841                  * start of Perl code, not a request to hand off to some
4842                  * other interpreter.  Similarly, if "perl" is there, but
4843                  * not in the first 'word' of the line, we assume the line
4844                  * contains the start of the Perl program.
4845                  */
4846                 if (d && *s != '#') {
4847                     const char *c = ipath;
4848                     while (*c && !strchr("; \t\r\n\f\v#", *c))
4849                         c++;
4850                     if (c < d)
4851                         d = NULL;       /* "perl" not in first word; ignore */
4852                     else
4853                         *s = '#';       /* Don't try to parse shebang line */
4854                 }
4855 #endif /* ALTERNATE_SHEBANG */
4856                 if (!d &&
4857                     *s == '#' &&
4858                     ipathend > ipath &&
4859                     !PL_minus_c &&
4860                     !instr(s,"indir") &&
4861                     instr(PL_origargv[0],"perl"))
4862                 {
4863                     dVAR;
4864                     char **newargv;
4865
4866                     *ipathend = '\0';
4867                     s = ipathend + 1;
4868                     while (s < PL_bufend && isSPACE(*s))
4869                         s++;
4870                     if (s < PL_bufend) {
4871                         Newx(newargv,PL_origargc+3,char*);
4872                         newargv[1] = s;
4873                         while (s < PL_bufend && !isSPACE(*s))
4874                             s++;
4875                         *s = '\0';
4876                         Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
4877                     }
4878                     else
4879                         newargv = PL_origargv;
4880                     newargv[0] = ipath;
4881                     PERL_FPU_PRE_EXEC
4882                     PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
4883                     PERL_FPU_POST_EXEC
4884                     Perl_croak(aTHX_ "Can't exec %s", ipath);
4885                 }
4886                 if (d) {
4887                     while (*d && !isSPACE(*d))
4888                         d++;
4889                     while (SPACE_OR_TAB(*d))
4890                         d++;
4891
4892                     if (*d++ == '-') {
4893                         const bool switches_done = PL_doswitches;
4894                         const U32 oldpdb = PL_perldb;
4895                         const bool oldn = PL_minus_n;
4896                         const bool oldp = PL_minus_p;
4897                         const char *d1 = d;
4898
4899                         do {
4900                             bool baduni = FALSE;
4901                             if (*d1 == 'C') {
4902                                 const char *d2 = d1 + 1;
4903                                 if (parse_unicode_opts((const char **)&d2)
4904                                     != PL_unicode)
4905                                     baduni = TRUE;
4906                             }
4907                             if (baduni || *d1 == 'M' || *d1 == 'm') {
4908                                 const char * const m = d1;
4909                                 while (*d1 && !isSPACE(*d1))
4910                                     d1++;
4911                                 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
4912                                       (int)(d1 - m), m);
4913                             }
4914                             d1 = moreswitches(d1);
4915                         } while (d1);
4916                         if (PL_doswitches && !switches_done) {
4917                             int argc = PL_origargc;
4918                             char **argv = PL_origargv;
4919                             do {
4920                                 argc--,argv++;
4921                             } while (argc && argv[0][0] == '-' && argv[0][1]);
4922                             init_argv_symbols(argc,argv);
4923                         }
4924                         if (((PERLDB_LINE || PERLDB_SAVESRC) && !oldpdb) ||
4925                             ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
4926                               /* if we have already added "LINE: while (<>) {",
4927                                  we must not do it again */
4928                         {
4929                             sv_setpvs(PL_linestr, "");
4930                             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4931                             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4932                             PL_last_lop = PL_last_uni = NULL;
4933                             PL_preambled = FALSE;
4934                             if (PERLDB_LINE || PERLDB_SAVESRC)
4935                                 (void)gv_fetchfile(PL_origfilename);
4936                             goto retry;
4937                         }
4938                     }
4939                 }
4940             }
4941         }
4942         if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4943             PL_bufptr = s;
4944             PL_lex_state = LEX_FORMLINE;
4945             return yylex();
4946         }
4947         goto retry;
4948     case '\r':
4949 #ifdef PERL_STRICT_CR
4950         Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
4951         Perl_croak(aTHX_
4952       "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
4953 #endif
4954     case ' ': case '\t': case '\f': case 013:
4955 #ifdef PERL_MAD
4956         PL_realtokenstart = -1;
4957         if (!PL_thiswhite)
4958             PL_thiswhite = newSVpvs("");
4959         sv_catpvn(PL_thiswhite, s, 1);
4960 #endif
4961         s++;
4962         goto retry;
4963     case '#':
4964     case '\n':
4965 #ifdef PERL_MAD
4966         PL_realtokenstart = -1;
4967         if (PL_madskills)
4968             PL_faketokens = 0;
4969 #endif
4970         if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
4971             if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
4972                 /* handle eval qq[#line 1 "foo"\n ...] */
4973                 CopLINE_dec(PL_curcop);
4974                 incline(s);
4975             }
4976             if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
4977                 s = SKIPSPACE0(s);
4978                 if (!PL_in_eval || PL_rsfp)
4979                     incline(s);
4980             }
4981             else {
4982                 d = s;
4983                 while (d < PL_bufend && *d != '\n')
4984                     d++;
4985                 if (d < PL_bufend)
4986                     d++;
4987                 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4988                   Perl_croak(aTHX_ "panic: input overflow");
4989 #ifdef PERL_MAD
4990                 if (PL_madskills)
4991                     PL_thiswhite = newSVpvn(s, d - s);
4992 #endif
4993                 s = d;
4994                 incline(s);
4995             }
4996             if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4997                 PL_bufptr = s;
4998                 PL_lex_state = LEX_FORMLINE;
4999                 return yylex();
5000             }
5001         }
5002         else {
5003 #ifdef PERL_MAD
5004             if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
5005                 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
5006                     PL_faketokens = 0;
5007                     s = SKIPSPACE0(s);
5008                     TOKEN(PEG); /* make sure any #! line is accessible */
5009                 }
5010                 s = SKIPSPACE0(s);
5011             }
5012             else {
5013 /*              if (PL_madskills && PL_lex_formbrack) { */
5014                     d = s;
5015                     while (d < PL_bufend && *d != '\n')
5016                         d++;
5017                     if (d < PL_bufend)
5018                         d++;
5019                     else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
5020                       Perl_croak(aTHX_ "panic: input overflow");
5021                     if (PL_madskills && CopLINE(PL_curcop) >= 1) {
5022                         if (!PL_thiswhite)
5023                             PL_thiswhite = newSVpvs("");
5024                         if (CopLINE(PL_curcop) == 1) {
5025                             sv_setpvs(PL_thiswhite, "");
5026                             PL_faketokens = 0;
5027                         }
5028                         sv_catpvn(PL_thiswhite, s, d - s);
5029                     }
5030                     s = d;
5031 /*              }
5032                 *s = '\0';
5033                 PL_bufend = s; */
5034             }
5035 #else
5036             *s = '\0';
5037             PL_bufend = s;
5038 #endif
5039         }
5040         goto retry;
5041     case '-':
5042         if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
5043             I32 ftst = 0;
5044             char tmp;
5045
5046             s++;
5047             PL_bufptr = s;
5048             tmp = *s++;
5049
5050             while (s < PL_bufend && SPACE_OR_TAB(*s))
5051                 s++;
5052
5053             if (strnEQ(s,"=>",2)) {
5054                 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
5055                 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
5056                 OPERATOR('-');          /* unary minus */
5057             }
5058             PL_last_uni = PL_oldbufptr;
5059             switch (tmp) {
5060             case 'r': ftst = OP_FTEREAD;        break;
5061             case 'w': ftst = OP_FTEWRITE;       break;
5062             case 'x': ftst = OP_FTEEXEC;        break;
5063             case 'o': ftst = OP_FTEOWNED;       break;
5064             case 'R': ftst = OP_FTRREAD;        break;
5065             case 'W': ftst = OP_FTRWRITE;       break;
5066             case 'X': ftst = OP_FTREXEC;        break;
5067             case 'O': ftst = OP_FTROWNED;       break;
5068             case 'e': ftst = OP_FTIS;           break;
5069             case 'z': ftst = OP_FTZERO;         break;
5070             case 's': ftst = OP_FTSIZE;         break;
5071             case 'f': ftst = OP_FTFILE;         break;
5072             case 'd': ftst = OP_FTDIR;          break;
5073             case 'l': ftst = OP_FTLINK;         break;
5074             case 'p': ftst = OP_FTPIPE;         break;
5075             case 'S': ftst = OP_FTSOCK;         break;
5076             case 'u': ftst = OP_FTSUID;         break;
5077             case 'g': ftst = OP_FTSGID;         break;
5078             case 'k': ftst = OP_FTSVTX;         break;
5079             case 'b': ftst = OP_FTBLK;          break;
5080             case 'c': ftst = OP_FTCHR;          break;
5081             case 't': ftst = OP_FTTTY;          break;
5082             case 'T': ftst = OP_FTTEXT;         break;
5083             case 'B': ftst = OP_FTBINARY;       break;
5084             case 'M': case 'A': case 'C':
5085                 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
5086                 switch (tmp) {
5087                 case 'M': ftst = OP_FTMTIME;    break;
5088                 case 'A': ftst = OP_FTATIME;    break;
5089                 case 'C': ftst = OP_FTCTIME;    break;
5090                 default:                        break;
5091                 }
5092                 break;
5093             default:
5094                 break;
5095             }
5096             if (ftst) {
5097                 PL_last_lop_op = (OPCODE)ftst;
5098                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
5099                         "### Saw file test %c\n", (int)tmp);
5100                 } );
5101                 FTST(ftst);
5102             }
5103             else {
5104                 /* Assume it was a minus followed by a one-letter named
5105                  * subroutine call (or a -bareword), then. */
5106                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
5107                         "### '-%c' looked like a file test but was not\n",
5108                         (int) tmp);
5109                 } );
5110                 s = --PL_bufptr;
5111             }
5112         }
5113         {
5114             const char tmp = *s++;
5115             if (*s == tmp) {
5116                 s++;
5117                 if (PL_expect == XOPERATOR)
5118                     TERM(POSTDEC);
5119                 else
5120                     OPERATOR(PREDEC);
5121             }
5122             else if (*s == '>') {
5123                 s++;
5124                 s = SKIPSPACE1(s);
5125                 if (isIDFIRST_lazy_if(s,UTF)) {
5126                     s = force_word(s,METHOD,FALSE,TRUE,FALSE);
5127                     TOKEN(ARROW);
5128                 }
5129                 else if (*s == '$')
5130                     OPERATOR(ARROW);
5131                 else
5132                     TERM(ARROW);
5133             }
5134             if (PL_expect == XOPERATOR)
5135                 Aop(OP_SUBTRACT);
5136             else {
5137                 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
5138                     check_uni();
5139                 OPERATOR('-');          /* unary minus */
5140             }
5141         }
5142
5143     case '+':
5144         {
5145             const char tmp = *s++;
5146             if (*s == tmp) {
5147                 s++;
5148                 if (PL_expect == XOPERATOR)
5149                     TERM(POSTINC);
5150                 else
5151                     OPERATOR(PREINC);
5152             }
5153             if (PL_expect == XOPERATOR)
5154                 Aop(OP_ADD);
5155             else {
5156                 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
5157                     check_uni();
5158                 OPERATOR('+');
5159             }
5160         }
5161
5162     case '*':
5163         if (PL_expect != XOPERATOR) {
5164             s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5165             PL_expect = XOPERATOR;
5166             force_ident(PL_tokenbuf, '*');
5167             if (!*PL_tokenbuf)
5168                 PREREF('*');
5169             TERM('*');
5170         }
5171         s++;
5172         if (*s == '*') {
5173             s++;
5174             PWop(OP_POW);
5175         }
5176         Mop(OP_MULTIPLY);
5177
5178     case '%':
5179         if (PL_expect == XOPERATOR) {
5180             ++s;
5181             Mop(OP_MODULO);
5182         }
5183         PL_tokenbuf[0] = '%';
5184         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
5185                 sizeof PL_tokenbuf - 1, FALSE);
5186         if (!PL_tokenbuf[1]) {
5187             PREREF('%');
5188         }
5189         PL_pending_ident = '%';
5190         TERM('%');
5191
5192     case '^':
5193         s++;
5194         BOop(OP_BIT_XOR);
5195     case '[':
5196         if (PL_lex_brackets > 100)
5197             Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
5198         PL_lex_brackstack[PL_lex_brackets++] = 0;
5199         {
5200             const char tmp = *s++;
5201             OPERATOR(tmp);
5202         }
5203     case '~':
5204         if (s[1] == '~'
5205             && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
5206         {
5207             s += 2;
5208             Eop(OP_SMARTMATCH);
5209         }
5210     case ',':
5211         {
5212             const char tmp = *s++;
5213             OPERATOR(tmp);
5214         }
5215     case ':':
5216         if (s[1] == ':') {
5217             len = 0;
5218             goto just_a_word_zero_gv;
5219         }
5220         s++;
5221         switch (PL_expect) {
5222             OP *attrs;
5223 #ifdef PERL_MAD
5224             I32 stuffstart;
5225 #endif
5226         case XOPERATOR:
5227             if (!PL_in_my || PL_lex_state != LEX_NORMAL)
5228                 break;
5229             PL_bufptr = s;      /* update in case we back off */
5230             if (*s == '=') {
5231                 deprecate(":= for an empty attribute list");
5232             }
5233             goto grabattrs;
5234         case XATTRBLOCK:
5235             PL_expect = XBLOCK;
5236             goto grabattrs;
5237         case XATTRTERM:
5238             PL_expect = XTERMBLOCK;
5239          grabattrs:
5240 #ifdef PERL_MAD
5241             stuffstart = s - SvPVX(PL_linestr) - 1;
5242 #endif
5243             s = PEEKSPACE(s);
5244             attrs = NULL;
5245             while (isIDFIRST_lazy_if(s,UTF)) {
5246                 I32 tmp;
5247                 SV *sv;
5248                 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5249                 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
5250                     if (tmp < 0) tmp = -tmp;
5251                     switch (tmp) {
5252                     case KEY_or:
5253                     case KEY_and:
5254                     case KEY_for:
5255                     case KEY_foreach:
5256                     case KEY_unless:
5257                     case KEY_if:
5258                     case KEY_while:
5259                     case KEY_until:
5260                         goto got_attrs;
5261                     default:
5262                         break;
5263                     }
5264                 }
5265                 sv = newSVpvn(s, len);
5266                 if (*d == '(') {
5267                     d = scan_str(d,TRUE,TRUE);
5268                     if (!d) {
5269                         /* MUST advance bufptr here to avoid bogus
5270                            "at end of line" context messages from yyerror().
5271                          */
5272                         PL_bufptr = s + len;
5273                         yyerror("Unterminated attribute parameter in attribute list");
5274                         if (attrs)
5275                             op_free(attrs);
5276                         sv_free(sv);
5277                         return REPORT(0);       /* EOF indicator */
5278                     }
5279                 }
5280                 if (PL_lex_stuff) {
5281                     sv_catsv(sv, PL_lex_stuff);
5282                     attrs = op_append_elem(OP_LIST, attrs,
5283                                         newSVOP(OP_CONST, 0, sv));
5284                     SvREFCNT_dec(PL_lex_stuff);
5285                     PL_lex_stuff = NULL;
5286                 }
5287                 else {
5288                     if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
5289                         sv_free(sv);
5290                         if (PL_in_my == KEY_our) {
5291                             deprecate(":unique");
5292                         }
5293                         else
5294                             Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
5295                     }
5296
5297                     /* NOTE: any CV attrs applied here need to be part of
5298                        the CVf_BUILTIN_ATTRS define in cv.h! */
5299                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
5300                         sv_free(sv);
5301                         CvLVALUE_on(PL_compcv);
5302                     }
5303                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
5304                         sv_free(sv);
5305                         deprecate(":locked");
5306                     }
5307                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
5308                         sv_free(sv);
5309                         CvMETHOD_on(PL_compcv);
5310                     }
5311                     /* After we've set the flags, it could be argued that
5312                        we don't need to do the attributes.pm-based setting
5313                        process, and shouldn't bother appending recognized
5314                        flags.  To experiment with that, uncomment the
5315                        following "else".  (Note that's already been
5316                        uncommented.  That keeps the above-applied built-in
5317                        attributes from being intercepted (and possibly
5318                        rejected) by a package's attribute routines, but is
5319                        justified by the performance win for the common case
5320                        of applying only built-in attributes.) */
5321                     else
5322                         attrs = op_append_elem(OP_LIST, attrs,
5323                                             newSVOP(OP_CONST, 0,
5324                                                     sv));
5325                 }
5326                 s = PEEKSPACE(d);
5327                 if (*s == ':' && s[1] != ':')
5328                     s = PEEKSPACE(s+1);
5329                 else if (s == d)
5330                     break;      /* require real whitespace or :'s */
5331                 /* XXX losing whitespace on sequential attributes here */
5332             }
5333             {
5334                 const char tmp
5335                     = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
5336                 if (*s != ';' && *s != '}' && *s != tmp
5337                     && (tmp != '=' || *s != ')')) {
5338                     const char q = ((*s == '\'') ? '"' : '\'');
5339                     /* If here for an expression, and parsed no attrs, back
5340                        off. */
5341                     if (tmp == '=' && !attrs) {
5342                         s = PL_bufptr;
5343                         break;
5344                     }
5345                     /* MUST advance bufptr here to avoid bogus "at end of line"
5346                        context messages from yyerror().
5347                     */
5348                     PL_bufptr = s;
5349                     yyerror( (const char *)
5350                              (*s
5351                               ? Perl_form(aTHX_ "Invalid separator character "
5352                                           "%c%c%c in attribute list", q, *s, q)
5353                               : "Unterminated attribute list" ) );
5354                     if (attrs)
5355                         op_free(attrs);
5356                     OPERATOR(':');
5357                 }
5358             }
5359         got_attrs:
5360             if (attrs) {
5361                 start_force(PL_curforce);
5362                 NEXTVAL_NEXTTOKE.opval = attrs;
5363                 CURMAD('_', PL_nextwhite);
5364                 force_next(THING);
5365             }
5366 #ifdef PERL_MAD
5367             if (PL_madskills) {
5368                 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
5369                                      (s - SvPVX(PL_linestr)) - stuffstart);
5370             }
5371 #endif
5372             TOKEN(COLONATTR);
5373         }
5374         OPERATOR(':');
5375     case '(':
5376         s++;
5377         if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
5378             PL_oldbufptr = PL_oldoldbufptr;             /* allow print(STDOUT 123) */
5379         else
5380             PL_expect = XTERM;
5381         s = SKIPSPACE1(s);
5382         TOKEN('(');
5383     case ';':
5384         CLINE;
5385         {
5386             const char tmp = *s++;
5387             OPERATOR(tmp);
5388         }
5389     case ')':
5390         {
5391             const char tmp = *s++;
5392             s = SKIPSPACE1(s);
5393             if (*s == '{')
5394                 PREBLOCK(tmp);
5395             TERM(tmp);
5396         }
5397     case ']':
5398         if (PL_lex_brackets && PL_lex_brackstack[PL_lex_brackets-1] == XFAKEEOF)
5399             TOKEN(0);
5400         s++;
5401         if (PL_lex_brackets <= 0)
5402             yyerror("Unmatched right square bracket");
5403         else
5404             --PL_lex_brackets;
5405         if (PL_lex_state == LEX_INTERPNORMAL) {
5406             if (PL_lex_brackets == 0) {
5407                 if (*s == '-' && s[1] == '>')
5408                     PL_lex_state = LEX_INTERPENDMAYBE;
5409                 else if (*s != '[' && *s != '{')
5410                     PL_lex_state = LEX_INTERPEND;
5411             }
5412         }
5413         TERM(']');
5414     case '{':
5415       leftbracket:
5416         s++;
5417         if (PL_lex_brackets > 100) {
5418             Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
5419         }
5420         switch (PL_expect) {
5421         case XTERM:
5422             if (PL_lex_formbrack) {
5423                 s--;
5424                 PRETERMBLOCK(DO);
5425             }
5426             if (PL_oldoldbufptr == PL_last_lop)
5427                 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
5428             else
5429                 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5430             OPERATOR(HASHBRACK);
5431         case XOPERATOR:
5432             while (s < PL_bufend && SPACE_OR_TAB(*s))
5433                 s++;
5434             d = s;
5435             PL_tokenbuf[0] = '\0';
5436             if (d < PL_bufend && *d == '-') {
5437                 PL_tokenbuf[0] = '-';
5438                 d++;
5439                 while (d < PL_bufend && SPACE_OR_TAB(*d))
5440                     d++;
5441             }
5442             if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
5443                 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
5444                               FALSE, &len);
5445                 while (d < PL_bufend && SPACE_OR_TAB(*d))
5446                     d++;
5447                 if (*d == '}') {
5448                     const char minus = (PL_tokenbuf[0] == '-');
5449                     s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
5450                     if (minus)
5451                         force_next('-');
5452                 }
5453             }
5454             /* FALL THROUGH */
5455         case XATTRBLOCK:
5456         case XBLOCK:
5457             PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
5458             PL_expect = XSTATE;
5459             break;
5460         case XATTRTERM:
5461         case XTERMBLOCK:
5462             PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5463             PL_expect = XSTATE;
5464             break;
5465         default: {
5466                 const char *t;
5467                 if (PL_oldoldbufptr == PL_last_lop)
5468                     PL_lex_brackstack[PL_lex_brackets++] = XTERM;
5469                 else
5470                     PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5471                 s = SKIPSPACE1(s);
5472                 if (*s == '}') {
5473                     if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
5474                         PL_expect = XTERM;
5475                         /* This hack is to get the ${} in the message. */
5476                         PL_bufptr = s+1;
5477                         yyerror("syntax error");
5478                         break;
5479                     }
5480                     OPERATOR(HASHBRACK);
5481                 }
5482                 /* This hack serves to disambiguate a pair of curlies
5483                  * as being a block or an anon hash.  Normally, expectation
5484                  * determines that, but in cases where we're not in a
5485                  * position to expect anything in particular (like inside
5486                  * eval"") we have to resolve the ambiguity.  This code
5487                  * covers the case where the first term in the curlies is a
5488                  * quoted string.  Most other cases need to be explicitly
5489                  * disambiguated by prepending a "+" before the opening
5490                  * curly in order to force resolution as an anon hash.
5491                  *
5492                  * XXX should probably propagate the outer expectation
5493                  * into eval"" to rely less on this hack, but that could
5494                  * potentially break current behavior of eval"".
5495                  * GSAR 97-07-21
5496                  */
5497                 t = s;
5498                 if (*s == '\'' || *s == '"' || *s == '`') {
5499                     /* common case: get past first string, handling escapes */
5500                     for (t++; t < PL_bufend && *t != *s;)
5501                         if (*t++ == '\\' && (*t == '\\' || *t == *s))
5502                             t++;
5503                     t++;
5504                 }
5505                 else if (*s == 'q') {
5506                     if (++t < PL_bufend
5507                         && (!isALNUM(*t)
5508                             || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
5509                                 && !isALNUM(*t))))
5510                     {
5511                         /* skip q//-like construct */
5512                         const char *tmps;
5513                         char open, close, term;
5514                         I32 brackets = 1;
5515
5516                         while (t < PL_bufend && isSPACE(*t))
5517                             t++;
5518                         /* check for q => */
5519                         if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
5520                             OPERATOR(HASHBRACK);
5521                         }
5522                         term = *t;
5523                         open = term;
5524                         if (term && (tmps = strchr("([{< )]}> )]}>",term)))
5525                             term = tmps[5];
5526                         close = term;
5527                         if (open == close)
5528                             for (t++; t < PL_bufend; t++) {
5529                                 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
5530                                     t++;
5531                                 else if (*t == open)
5532                                     break;
5533                             }
5534                         else {
5535                             for (t++; t < PL_bufend; t++) {
5536                                 if (*t == '\\' && t+1 < PL_bufend)
5537                                     t++;
5538                                 else if (*t == close && --brackets <= 0)
5539                                     break;
5540                                 else if (*t == open)
5541                                     brackets++;
5542                             }
5543                         }
5544                         t++;
5545                     }
5546                     else
5547                         /* skip plain q word */
5548                         while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
5549                              t += UTF8SKIP(t);
5550                 }
5551                 else if (isALNUM_lazy_if(t,UTF)) {
5552                     t += UTF8SKIP(t);
5553                     while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
5554                          t += UTF8SKIP(t);
5555                 }
5556                 while (t < PL_bufend && isSPACE(*t))
5557                     t++;
5558                 /* if comma follows first term, call it an anon hash */
5559                 /* XXX it could be a comma expression with loop modifiers */
5560                 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
5561                                    || (*t == '=' && t[1] == '>')))
5562                     OPERATOR(HASHBRACK);
5563                 if (PL_expect == XREF)
5564                     PL_expect = XTERM;
5565                 else {
5566                     PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
5567                     PL_expect = XSTATE;
5568                 }
5569             }
5570             break;
5571         }
5572         pl_yylval.ival = CopLINE(PL_curcop);
5573         if (isSPACE(*s) || *s == '#')
5574             PL_copline = NOLINE;   /* invalidate current command line number */
5575         TOKEN('{');
5576     case '}':
5577         if (PL_lex_brackets && PL_lex_brackstack[PL_lex_brackets-1] == XFAKEEOF)
5578             TOKEN(0);
5579       rightbracket:
5580         s++;
5581         if (PL_lex_brackets <= 0)
5582             yyerror("Unmatched right curly bracket");
5583         else
5584             PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
5585         if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
5586             PL_lex_formbrack = 0;
5587         if (PL_lex_state == LEX_INTERPNORMAL) {
5588             if (PL_lex_brackets == 0) {
5589                 if (PL_expect & XFAKEBRACK) {
5590                     PL_expect &= XENUMMASK;
5591                     PL_lex_state = LEX_INTERPEND;
5592                     PL_bufptr = s;
5593 #if 0
5594                     if (PL_madskills) {
5595                         if (!PL_thiswhite)
5596                             PL_thiswhite = newSVpvs("");
5597                         sv_catpvs(PL_thiswhite,"}");
5598                     }
5599 #endif
5600                     return yylex();     /* ignore fake brackets */
5601                 }
5602                 if (*s == '-' && s[1] == '>')
5603                     PL_lex_state = LEX_INTERPENDMAYBE;
5604                 else if (*s != '[' && *s != '{')
5605                     PL_lex_state = LEX_INTERPEND;
5606             }
5607         }
5608         if (PL_expect & XFAKEBRACK) {
5609             PL_expect &= XENUMMASK;
5610             PL_bufptr = s;
5611             return yylex();             /* ignore fake brackets */
5612         }
5613         start_force(PL_curforce);
5614         if (PL_madskills) {
5615             curmad('X', newSVpvn(s-1,1));
5616             CURMAD('_', PL_thiswhite);
5617         }
5618         force_next('}');
5619 #ifdef PERL_MAD
5620         if (!PL_thistoken)
5621             PL_thistoken = newSVpvs("");
5622 #endif
5623         TOKEN(';');
5624     case '&':
5625         s++;
5626         if (*s++ == '&')
5627             AOPERATOR(ANDAND);
5628         s--;
5629         if (PL_expect == XOPERATOR) {
5630             if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
5631                 && isIDFIRST_lazy_if(s,UTF))
5632             {
5633                 CopLINE_dec(PL_curcop);
5634                 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
5635                 CopLINE_inc(PL_curcop);
5636             }
5637             BAop(OP_BIT_AND);
5638         }
5639
5640         s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5641         if (*PL_tokenbuf) {
5642             PL_expect = XOPERATOR;
5643             force_ident(PL_tokenbuf, '&');
5644         }
5645         else
5646             PREREF('&');
5647         pl_yylval.ival = (OPpENTERSUB_AMPER<<8);
5648         TERM('&');
5649
5650     case '|':
5651         s++;
5652         if (*s++ == '|')
5653             AOPERATOR(OROR);
5654         s--;
5655         BOop(OP_BIT_OR);
5656     case '=':
5657         s++;
5658         {
5659             const char tmp = *s++;
5660             if (tmp == '=')
5661                 Eop(OP_EQ);
5662             if (tmp == '>')
5663                 OPERATOR(',');
5664             if (tmp == '~')
5665                 PMop(OP_MATCH);
5666             if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
5667                 && strchr("+-*/%.^&|<",tmp))
5668                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5669                             "Reversed %c= operator",(int)tmp);
5670             s--;
5671             if (PL_expect == XSTATE && isALPHA(tmp) &&
5672                 (s == PL_linestart+1 || s[-2] == '\n') )
5673                 {
5674                     if (PL_in_eval && !PL_rsfp) {
5675                         d = PL_bufend;
5676                         while (s < d) {
5677                             if (*s++ == '\n') {
5678                                 incline(s);
5679                                 if (strnEQ(s,"=cut",4)) {
5680                                     s = strchr(s,'\n');
5681                                     if (s)
5682                                         s++;
5683                                     else
5684                                         s = d;
5685                                     incline(s);
5686                                     goto retry;
5687                                 }
5688                             }
5689                         }
5690                         goto retry;
5691                     }
5692 #ifdef PERL_MAD
5693                     if (PL_madskills) {
5694                         if (!PL_thiswhite)
5695                             PL_thiswhite = newSVpvs("");
5696                         sv_catpvn(PL_thiswhite, PL_linestart,
5697                                   PL_bufend - PL_linestart);
5698                     }
5699 #endif
5700                     s = PL_bufend;
5701                     PL_parser->in_pod = 1;
5702                     goto retry;
5703                 }
5704         }
5705         if (PL_lex_brackets < PL_lex_formbrack) {
5706             const char *t = s;
5707 #ifdef PERL_STRICT_CR
5708             while (SPACE_OR_TAB(*t))
5709 #else
5710             while (SPACE_OR_TAB(*t) || *t == '\r')
5711 #endif
5712                 t++;
5713             if (*t == '\n' || *t == '#') {
5714                 s--;
5715                 PL_expect = XBLOCK;
5716                 goto leftbracket;
5717             }
5718         }
5719         pl_yylval.ival = 0;
5720         OPERATOR(ASSIGNOP);
5721     case '!':
5722         s++;
5723         {
5724             const char tmp = *s++;
5725             if (tmp == '=') {
5726                 /* was this !=~ where !~ was meant?
5727                  * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
5728
5729                 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
5730                     const char *t = s+1;
5731
5732                     while (t < PL_bufend && isSPACE(*t))
5733                         ++t;
5734
5735                     if (*t == '/' || *t == '?' ||
5736                         ((*t == 'm' || *t == 's' || *t == 'y')
5737                          && !isALNUM(t[1])) ||
5738                         (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
5739                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5740                                     "!=~ should be !~");
5741                 }
5742                 Eop(OP_NE);
5743             }
5744             if (tmp == '~')
5745                 PMop(OP_NOT);
5746         }
5747         s--;
5748         OPERATOR('!');
5749     case '<':
5750         if (PL_expect != XOPERATOR) {
5751             if (s[1] != '<' && !strchr(s,'>'))
5752                 check_uni();
5753             if (s[1] == '<')
5754                 s = scan_heredoc(s);
5755             else
5756                 s = scan_inputsymbol(s);
5757             TERM(sublex_start());
5758         }
5759         s++;
5760         {
5761             char tmp = *s++;
5762             if (tmp == '<')
5763                 SHop(OP_LEFT_SHIFT);
5764             if (tmp == '=') {
5765                 tmp = *s++;
5766                 if (tmp == '>')
5767                     Eop(OP_NCMP);
5768                 s--;
5769                 Rop(OP_LE);
5770             }
5771         }
5772         s--;
5773         Rop(OP_LT);
5774     case '>':
5775         s++;
5776         {
5777             const char tmp = *s++;
5778             if (tmp == '>')
5779                 SHop(OP_RIGHT_SHIFT);
5780             else if (tmp == '=')
5781                 Rop(OP_GE);
5782         }
5783         s--;
5784         Rop(OP_GT);
5785
5786     case '$':
5787         CLINE;
5788
5789         if (PL_expect == XOPERATOR) {
5790             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5791                 return deprecate_commaless_var_list();
5792             }
5793         }
5794
5795         if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-@", s[2]))) {
5796             PL_tokenbuf[0] = '@';
5797             s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
5798                            sizeof PL_tokenbuf - 1, FALSE);
5799             if (PL_expect == XOPERATOR)
5800                 no_op("Array length", s);
5801             if (!PL_tokenbuf[1])
5802                 PREREF(DOLSHARP);
5803             PL_expect = XOPERATOR;
5804             PL_pending_ident = '#';
5805             TOKEN(DOLSHARP);
5806         }
5807
5808         PL_tokenbuf[0] = '$';
5809         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
5810                        sizeof PL_tokenbuf - 1, FALSE);
5811         if (PL_expect == XOPERATOR)
5812             no_op("Scalar", s);
5813         if (!PL_tokenbuf[1]) {
5814             if (s == PL_bufend)
5815                 yyerror("Final $ should be \\$ or $name");
5816             PREREF('$');
5817         }
5818
5819         /* This kludge not intended to be bulletproof. */
5820         if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
5821             pl_yylval.opval = newSVOP(OP_CONST, 0,
5822                                    newSViv(CopARYBASE_get(&PL_compiling)));
5823             pl_yylval.opval->op_private = OPpCONST_ARYBASE;
5824             TERM(THING);
5825         }
5826
5827         d = s;
5828         {
5829             const char tmp = *s;
5830             if (PL_lex_state == LEX_NORMAL || PL_lex_brackets)
5831                 s = SKIPSPACE1(s);
5832
5833             if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
5834                 && intuit_more(s)) {
5835                 if (*s == '[') {
5836                     PL_tokenbuf[0] = '@';
5837                     if (ckWARN(WARN_SYNTAX)) {
5838                         char *t = s+1;
5839
5840                         while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
5841                             t++;
5842                         if (*t++ == ',') {
5843                             PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
5844                             while (t < PL_bufend && *t != ']')
5845                                 t++;
5846                             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5847                                         "Multidimensional syntax %.*s not supported",
5848                                     (int)((t - PL_bufptr) + 1), PL_bufptr);
5849                         }
5850                     }
5851                 }
5852                 else if (*s == '{') {
5853                     char *t;
5854                     PL_tokenbuf[0] = '%';
5855                     if (strEQ(PL_tokenbuf+1, "SIG")  && ckWARN(WARN_SYNTAX)
5856                         && (t = strchr(s, '}')) && (t = strchr(t, '=')))
5857                         {
5858                             char tmpbuf[sizeof PL_tokenbuf];
5859                             do {
5860                                 t++;
5861                             } while (isSPACE(*t));
5862                             if (isIDFIRST_lazy_if(t,UTF)) {
5863                                 STRLEN len;
5864                                 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
5865                                               &len);
5866                                 while (isSPACE(*t))
5867                                     t++;
5868                                 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
5869                                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5870                                                 "You need to quote \"%s\"",
5871                                                 tmpbuf);
5872                             }
5873                         }
5874                 }
5875             }
5876
5877             PL_expect = XOPERATOR;
5878             if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
5879                 const bool islop = (PL_last_lop == PL_oldoldbufptr);
5880                 if (!islop || PL_last_lop_op == OP_GREPSTART)
5881                     PL_expect = XOPERATOR;
5882                 else if (strchr("$@\"'`q", *s))
5883                     PL_expect = XTERM;          /* e.g. print $fh "foo" */
5884                 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
5885                     PL_expect = XTERM;          /* e.g. print $fh &sub */
5886                 else if (isIDFIRST_lazy_if(s,UTF)) {
5887                     char tmpbuf[sizeof PL_tokenbuf];
5888                     int t2;
5889                     scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5890                     if ((t2 = keyword(tmpbuf, len, 0))) {
5891                         /* binary operators exclude handle interpretations */
5892                         switch (t2) {
5893                         case -KEY_x:
5894                         case -KEY_eq:
5895                         case -KEY_ne:
5896                         case -KEY_gt:
5897                         case -KEY_lt:
5898                         case -KEY_ge:
5899                         case -KEY_le:
5900                         case -KEY_cmp:
5901                             break;
5902                         default:
5903                             PL_expect = XTERM;  /* e.g. print $fh length() */
5904                             break;
5905                         }
5906                     }
5907                     else {
5908                         PL_expect = XTERM;      /* e.g. print $fh subr() */
5909                     }
5910                 }
5911                 else if (isDIGIT(*s))
5912                     PL_expect = XTERM;          /* e.g. print $fh 3 */
5913                 else if (*s == '.' && isDIGIT(s[1]))
5914                     PL_expect = XTERM;          /* e.g. print $fh .3 */
5915                 else if ((*s == '?' || *s == '-' || *s == '+')
5916                          && !isSPACE(s[1]) && s[1] != '=')
5917                     PL_expect = XTERM;          /* e.g. print $fh -1 */
5918                 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
5919                          && s[1] != '/')
5920                     PL_expect = XTERM;          /* e.g. print $fh /.../
5921                                                    XXX except DORDOR operator
5922                                                 */
5923                 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
5924                          && s[2] != '=')
5925                     PL_expect = XTERM;          /* print $fh <<"EOF" */
5926             }
5927         }
5928         PL_pending_ident = '$';
5929         TOKEN('$');
5930
5931     case '@':
5932         if (PL_expect == XOPERATOR)
5933             no_op("Array", s);
5934         PL_tokenbuf[0] = '@';
5935         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
5936         if (!PL_tokenbuf[1]) {
5937             PREREF('@');
5938         }
5939         if (PL_lex_state == LEX_NORMAL)
5940             s = SKIPSPACE1(s);
5941         if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
5942             if (*s == '{')
5943                 PL_tokenbuf[0] = '%';
5944
5945             /* Warn about @ where they meant $. */
5946             if (*s == '[' || *s == '{') {
5947                 if (ckWARN(WARN_SYNTAX)) {
5948                     const char *t = s + 1;
5949                     while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
5950                         t++;
5951                     if (*t == '}' || *t == ']') {
5952                         t++;
5953                         PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
5954                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5955                             "Scalar value %.*s better written as $%.*s",
5956                             (int)(t-PL_bufptr), PL_bufptr,
5957                             (int)(t-PL_bufptr-1), PL_bufptr+1);
5958                     }
5959                 }
5960             }
5961         }
5962         PL_pending_ident = '@';
5963         TERM('@');
5964
5965      case '/':                  /* may be division, defined-or, or pattern */
5966         if (PL_expect == XTERMORDORDOR && s[1] == '/') {
5967             s += 2;
5968             AOPERATOR(DORDOR);
5969         }
5970      case '?':                  /* may either be conditional or pattern */
5971         if (PL_expect == XOPERATOR) {
5972              char tmp = *s++;
5973              if(tmp == '?') {
5974                 OPERATOR('?');
5975              }
5976              else {
5977                  tmp = *s++;
5978                  if(tmp == '/') {
5979                      /* A // operator. */
5980                     AOPERATOR(DORDOR);
5981                  }
5982                  else {
5983                      s--;
5984                      Mop(OP_DIVIDE);
5985                  }
5986              }
5987          }
5988          else {
5989              /* Disable warning on "study /blah/" */
5990              if (PL_oldoldbufptr == PL_last_uni
5991               && (*PL_last_uni != 's' || s - PL_last_uni < 5
5992                   || memNE(PL_last_uni, "study", 5)
5993                   || isALNUM_lazy_if(PL_last_uni+5,UTF)
5994               ))
5995                  check_uni();
5996              s = scan_pat(s,OP_MATCH);
5997              TERM(sublex_start());
5998          }
5999
6000     case '.':
6001         if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
6002 #ifdef PERL_STRICT_CR
6003             && s[1] == '\n'
6004 #else
6005             && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
6006 #endif
6007             && (s == PL_linestart || s[-1] == '\n') )
6008         {
6009             PL_lex_formbrack = 0;
6010             PL_expect = XSTATE;
6011             goto rightbracket;
6012         }
6013         if (PL_expect == XSTATE && s[1] == '.' && s[2] == '.') {
6014             s += 3;
6015             OPERATOR(YADAYADA);
6016         }
6017         if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
6018             char tmp = *s++;
6019             if (*s == tmp) {
6020                 s++;
6021                 if (*s == tmp) {
6022                     s++;
6023                     pl_yylval.ival = OPf_SPECIAL;
6024                 }
6025                 else
6026                     pl_yylval.ival = 0;
6027                 OPERATOR(DOTDOT);
6028             }
6029             Aop(OP_CONCAT);
6030         }
6031         /* FALL THROUGH */
6032     case '0': case '1': case '2': case '3': case '4':
6033     case '5': case '6': case '7': case '8': case '9':
6034         s = scan_num(s, &pl_yylval);
6035         DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
6036         if (PL_expect == XOPERATOR)
6037             no_op("Number",s);
6038         TERM(THING);
6039
6040     case '\'':
6041         s = scan_str(s,!!PL_madskills,FALSE);
6042         DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
6043         if (PL_expect == XOPERATOR) {
6044             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
6045                 return deprecate_commaless_var_list();
6046             }
6047             else
6048                 no_op("String",s);
6049         }
6050         if (!s)
6051             missingterm(NULL);
6052         pl_yylval.ival = OP_CONST;
6053         TERM(sublex_start());
6054
6055     case '"':
6056         s = scan_str(s,!!PL_madskills,FALSE);
6057         DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
6058         if (PL_expect == XOPERATOR) {
6059             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
6060                 return deprecate_commaless_var_list();
6061             }
6062             else
6063                 no_op("String",s);
6064         }
6065         if (!s)
6066             missingterm(NULL);
6067         pl_yylval.ival = OP_CONST;
6068         /* FIXME. I think that this can be const if char *d is replaced by
6069            more localised variables.  */
6070         for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
6071             if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
6072                 pl_yylval.ival = OP_STRINGIFY;
6073                 break;
6074             }
6075         }
6076         TERM(sublex_start());
6077
6078     case '`':
6079         s = scan_str(s,!!PL_madskills,FALSE);
6080         DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
6081         if (PL_expect == XOPERATOR)
6082             no_op("Backticks",s);
6083         if (!s)
6084             missingterm(NULL);
6085         readpipe_override();
6086         TERM(sublex_start());
6087
6088     case '\\':
6089         s++;
6090         if (PL_lex_inwhat && isDIGIT(*s))
6091             Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
6092                            *s, *s);
6093         if (PL_expect == XOPERATOR)
6094             no_op("Backslash",s);
6095         OPERATOR(REFGEN);
6096
6097     case 'v':
6098         if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
6099             char *start = s + 2;
6100             while (isDIGIT(*start) || *start == '_')
6101                 start++;
6102             if (*start == '.' && isDIGIT(start[1])) {
6103                 s = scan_num(s, &pl_yylval);
6104                 TERM(THING);
6105             }
6106             /* avoid v123abc() or $h{v1}, allow C<print v10;> */
6107             else if (!isALPHA(*start) && (PL_expect == XTERM
6108                         || PL_expect == XREF || PL_expect == XSTATE
6109                         || PL_expect == XTERMORDORDOR)) {
6110                 GV *const gv = gv_fetchpvn_flags(s, start - s, 0, SVt_PVCV);
6111                 if (!gv) {
6112                     s = scan_num(s, &pl_yylval);
6113                     TERM(THING);
6114                 }
6115             }
6116         }
6117         goto keylookup;
6118     case 'x':
6119         if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
6120             s++;
6121             Mop(OP_REPEAT);
6122         }
6123         goto keylookup;
6124
6125     case '_':
6126     case 'a': case 'A':
6127     case 'b': case 'B':
6128     case 'c': case 'C':
6129     case 'd': case 'D':
6130     case 'e': case 'E':
6131     case 'f': case 'F':
6132     case 'g': case 'G':
6133     case 'h': case 'H':
6134     case 'i': case 'I':
6135     case 'j': case 'J':
6136     case 'k': case 'K':
6137     case 'l': case 'L':
6138     case 'm': case 'M':
6139     case 'n': case 'N':
6140     case 'o': case 'O':
6141     case 'p': case 'P':
6142     case 'q': case 'Q':
6143     case 'r': case 'R':
6144     case 's': case 'S':
6145     case 't': case 'T':
6146     case 'u': case 'U':
6147               case 'V':
6148     case 'w': case 'W':
6149               case 'X':
6150     case 'y': case 'Y':
6151     case 'z': case 'Z':
6152
6153       keylookup: {
6154         bool anydelim;
6155         I32 tmp;
6156
6157         orig_keyword = 0;
6158         gv = NULL;
6159         gvp = NULL;
6160
6161         PL_bufptr = s;
6162         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
6163
6164         /* Some keywords can be followed by any delimiter, including ':' */
6165         anydelim = word_takes_any_delimeter(PL_tokenbuf, len);
6166
6167         /* x::* is just a word, unless x is "CORE" */
6168         if (!anydelim && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
6169             goto just_a_word;
6170
6171         d = s;
6172         while (d < PL_bufend && isSPACE(*d))
6173                 d++;    /* no comments skipped here, or s### is misparsed */
6174
6175         /* Is this a word before a => operator? */
6176         if (*d == '=' && d[1] == '>') {
6177             CLINE;
6178             pl_yylval.opval
6179                 = (OP*)newSVOP(OP_CONST, 0,
6180                                S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
6181             pl_yylval.opval->op_private = OPpCONST_BARE;
6182             TERM(WORD);
6183         }
6184
6185         /* Check for plugged-in keyword */
6186         {
6187             OP *o;
6188             int result;
6189             char *saved_bufptr = PL_bufptr;
6190             PL_bufptr = s;
6191             result = PL_keyword_plugin(aTHX_ PL_tokenbuf, len, &o);
6192             s = PL_bufptr;
6193             if (result == KEYWORD_PLUGIN_DECLINE) {
6194                 /* not a plugged-in keyword */
6195                 PL_bufptr = saved_bufptr;
6196             } else if (result == KEYWORD_PLUGIN_STMT) {
6197                 pl_yylval.opval = o;
6198                 CLINE;
6199                 PL_expect = XSTATE;
6200                 return REPORT(PLUGSTMT);
6201             } else if (result == KEYWORD_PLUGIN_EXPR) {
6202                 pl_yylval.opval = o;
6203                 CLINE;
6204                 PL_expect = XOPERATOR;
6205                 return REPORT(PLUGEXPR);
6206             } else {
6207                 Perl_croak(aTHX_ "Bad plugin affecting keyword '%s'",
6208                                         PL_tokenbuf);
6209             }
6210         }
6211
6212         /* Check for built-in keyword */
6213         tmp = keyword(PL_tokenbuf, len, 0);
6214
6215         /* Is this a label? */
6216         if (!anydelim && PL_expect == XSTATE
6217               && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
6218             s = d + 1;
6219             pl_yylval.pval = CopLABEL_alloc(PL_tokenbuf);
6220             CLINE;
6221             TOKEN(LABEL);
6222         }
6223
6224         if (tmp < 0) {                  /* second-class keyword? */
6225             GV *ogv = NULL;     /* override (winner) */
6226             GV *hgv = NULL;     /* hidden (loser) */
6227             if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
6228                 CV *cv;
6229                 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
6230                     (cv = GvCVu(gv)))
6231                 {
6232                     if (GvIMPORTED_CV(gv))
6233                         ogv = gv;
6234                     else if (! CvMETHOD(cv))
6235                         hgv = gv;
6236                 }
6237                 if (!ogv &&
6238                     (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
6239                     (gv = *gvp) && isGV_with_GP(gv) &&
6240                     GvCVu(gv) && GvIMPORTED_CV(gv))
6241                 {
6242                     ogv = gv;
6243                 }
6244             }
6245             if (ogv) {
6246                 orig_keyword = tmp;
6247                 tmp = 0;                /* overridden by import or by GLOBAL */
6248             }
6249             else if (gv && !gvp
6250                      && -tmp==KEY_lock  /* XXX generalizable kludge */
6251                      && GvCVu(gv))
6252             {
6253                 tmp = 0;                /* any sub overrides "weak" keyword */
6254             }
6255             else {                      /* no override */
6256                 tmp = -tmp;
6257                 if (tmp == KEY_dump) {
6258                     Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
6259                                    "dump() better written as CORE::dump()");
6260                 }
6261                 gv = NULL;
6262                 gvp = 0;
6263                 if (hgv && tmp != KEY_x && tmp != KEY_CORE)     /* never ambiguous */
6264                     Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6265                                    "Ambiguous call resolved as CORE::%s(), "
6266                                    "qualify as such or use &",
6267                                    GvENAME(hgv));
6268             }
6269         }
6270
6271       reserved_word:
6272         switch (tmp) {
6273
6274         default:                        /* not a keyword */
6275             /* Trade off - by using this evil construction we can pull the
6276                variable gv into the block labelled keylookup. If not, then
6277                we have to give it function scope so that the goto from the
6278                earlier ':' case doesn't bypass the initialisation.  */
6279             if (0) {
6280             just_a_word_zero_gv:
6281                 gv = NULL;
6282                 gvp = NULL;
6283                 orig_keyword = 0;
6284             }
6285           just_a_word: {
6286                 SV *sv;
6287                 int pkgname = 0;
6288                 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
6289                 OP *rv2cv_op;
6290                 CV *cv;
6291 #ifdef PERL_MAD
6292                 SV *nextPL_nextwhite = 0;
6293 #endif
6294
6295
6296                 /* Get the rest if it looks like a package qualifier */
6297
6298                 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
6299                     STRLEN morelen;
6300                     s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
6301                                   TRUE, &morelen);
6302                     if (!morelen)
6303                         Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
6304                                 *s == '\'' ? "'" : "::");
6305                     len += morelen;
6306                     pkgname = 1;
6307                 }
6308
6309                 if (PL_expect == XOPERATOR) {
6310                     if (PL_bufptr == PL_linestart) {
6311                         CopLINE_dec(PL_curcop);
6312                         Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
6313                         CopLINE_inc(PL_curcop);
6314                     }
6315                     else
6316                         no_op("Bareword",s);
6317                 }
6318
6319                 /* Look for a subroutine with this name in current package,
6320                    unless name is "Foo::", in which case Foo is a bearword
6321                    (and a package name). */
6322
6323                 if (len > 2 && !PL_madskills &&
6324                     PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
6325                 {
6326                     if (ckWARN(WARN_BAREWORD)
6327                         && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
6328                         Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
6329                             "Bareword \"%s\" refers to nonexistent package",
6330                              PL_tokenbuf);
6331                     len -= 2;
6332                     PL_tokenbuf[len] = '\0';
6333                     gv = NULL;
6334                     gvp = 0;
6335                 }
6336                 else {
6337                     if (!gv) {
6338                         /* Mustn't actually add anything to a symbol table.
6339                            But also don't want to "initialise" any placeholder
6340                            constants that might already be there into full
6341                            blown PVGVs with attached PVCV.  */
6342                         gv = gv_fetchpvn_flags(PL_tokenbuf, len,
6343                                                GV_NOADD_NOINIT, SVt_PVCV);
6344                     }
6345                     len = 0;
6346                 }
6347
6348                 /* if we saw a global override before, get the right name */
6349
6350                 sv = S_newSV_maybe_utf8(aTHX_ PL_tokenbuf,
6351                     len ? len : strlen(PL_tokenbuf));
6352                 if (gvp) {
6353                     SV * const tmp_sv = sv;
6354                     sv = newSVpvs("CORE::GLOBAL::");
6355                     sv_catsv(sv, tmp_sv);
6356                     SvREFCNT_dec(tmp_sv);
6357                 }
6358
6359 #ifdef PERL_MAD
6360                 if (PL_madskills && !PL_thistoken) {
6361                     char *start = SvPVX(PL_linestr) + PL_realtokenstart;
6362                     PL_thistoken = newSVpvn(start,s - start);
6363                     PL_realtokenstart = s - SvPVX(PL_linestr);
6364                 }
6365 #endif
6366
6367                 /* Presume this is going to be a bareword of some sort. */
6368                 CLINE;
6369                 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
6370                 pl_yylval.opval->op_private = OPpCONST_BARE;
6371
6372                 /* And if "Foo::", then that's what it certainly is. */
6373                 if (len)
6374                     goto safe_bareword;
6375
6376                 {
6377                     OP *const_op = newSVOP(OP_CONST, 0, SvREFCNT_inc(sv));
6378                     const_op->op_private = OPpCONST_BARE;
6379                     rv2cv_op = newCVREF(0, const_op);
6380                 }
6381                 cv = rv2cv_op_cv(rv2cv_op, 0);
6382
6383                 /* See if it's the indirect object for a list operator. */
6384
6385                 if (PL_oldoldbufptr &&
6386                     PL_oldoldbufptr < PL_bufptr &&
6387                     (PL_oldoldbufptr == PL_last_lop
6388                      || PL_oldoldbufptr == PL_last_uni) &&
6389                     /* NO SKIPSPACE BEFORE HERE! */
6390                     (PL_expect == XREF ||
6391                      ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
6392                 {
6393                     bool immediate_paren = *s == '(';
6394
6395                     /* (Now we can afford to cross potential line boundary.) */
6396                     s = SKIPSPACE2(s,nextPL_nextwhite);
6397 #ifdef PERL_MAD
6398                     PL_nextwhite = nextPL_nextwhite;    /* assume no & deception */
6399 #endif
6400
6401                     /* Two barewords in a row may indicate method call. */
6402
6403                     if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
6404                         (tmp = intuit_method(s, gv, cv))) {
6405                         op_free(rv2cv_op);
6406                         return REPORT(tmp);
6407                     }
6408
6409                     /* If not a declared subroutine, it's an indirect object. */
6410                     /* (But it's an indir obj regardless for sort.) */
6411                     /* Also, if "_" follows a filetest operator, it's a bareword */
6412
6413                     if (
6414                         ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
6415                          (!cv &&
6416                         (PL_last_lop_op != OP_MAPSTART &&
6417                          PL_last_lop_op != OP_GREPSTART))))
6418                        || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
6419                             && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
6420                        )
6421                     {
6422                         PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
6423                         goto bareword;
6424                     }
6425                 }
6426
6427                 PL_expect = XOPERATOR;
6428 #ifdef PERL_MAD
6429                 if (isSPACE(*s))
6430                     s = SKIPSPACE2(s,nextPL_nextwhite);
6431                 PL_nextwhite = nextPL_nextwhite;
6432 #else
6433                 s = skipspace(s);
6434 #endif
6435
6436                 /* Is this a word before a => operator? */
6437                 if (*s == '=' && s[1] == '>' && !pkgname) {
6438                     op_free(rv2cv_op);
6439                     CLINE;
6440                     sv_setpv(((SVOP*)pl_yylval.opval)->op_sv, PL_tokenbuf);
6441                     if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
6442                       SvUTF8_on(((SVOP*)pl_yylval.opval)->op_sv);
6443                     TERM(WORD);
6444                 }
6445
6446                 /* If followed by a paren, it's certainly a subroutine. */
6447                 if (*s == '(') {
6448                     CLINE;
6449                     if (cv) {
6450                         d = s + 1;
6451                         while (SPACE_OR_TAB(*d))
6452                             d++;
6453                         if (*d == ')' && (sv = cv_const_sv(cv))) {
6454                             s = d + 1;
6455                             goto its_constant;
6456                         }
6457                     }
6458 #ifdef PERL_MAD
6459                     if (PL_madskills) {
6460                         PL_nextwhite = PL_thiswhite;
6461                         PL_thiswhite = 0;
6462                     }
6463                     start_force(PL_curforce);
6464 #endif
6465                     NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6466                     PL_expect = XOPERATOR;
6467 #ifdef PERL_MAD
6468                     if (PL_madskills) {
6469                         PL_nextwhite = nextPL_nextwhite;
6470                         curmad('X', PL_thistoken);
6471                         PL_thistoken = newSVpvs("");
6472                     }
6473 #endif
6474                     op_free(rv2cv_op);
6475                     force_next(WORD);
6476                     pl_yylval.ival = 0;
6477                     TOKEN('&');
6478                 }
6479
6480                 /* If followed by var or block, call it a method (unless sub) */
6481
6482                 if ((*s == '$' || *s == '{') && !cv) {
6483                     op_free(rv2cv_op);
6484                     PL_last_lop = PL_oldbufptr;
6485                     PL_last_lop_op = OP_METHOD;
6486                     PREBLOCK(METHOD);
6487                 }
6488
6489                 /* If followed by a bareword, see if it looks like indir obj. */
6490
6491                 if (!orig_keyword
6492                         && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
6493                         && (tmp = intuit_method(s, gv, cv))) {
6494                     op_free(rv2cv_op);
6495                     return REPORT(tmp);
6496                 }
6497
6498                 /* Not a method, so call it a subroutine (if defined) */
6499
6500                 if (cv) {
6501                     if (lastchar == '-')
6502                         Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
6503                                          "Ambiguous use of -%s resolved as -&%s()",
6504                                          PL_tokenbuf, PL_tokenbuf);
6505                     /* Check for a constant sub */
6506                     if ((sv = cv_const_sv(cv))) {
6507                   its_constant:
6508                         op_free(rv2cv_op);
6509                         SvREFCNT_dec(((SVOP*)pl_yylval.opval)->op_sv);
6510                         ((SVOP*)pl_yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
6511                         pl_yylval.opval->op_private = 0;
6512                         TOKEN(WORD);
6513                     }
6514
6515                     op_free(pl_yylval.opval);
6516                     pl_yylval.opval = rv2cv_op;
6517                     pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
6518                     PL_last_lop = PL_oldbufptr;
6519                     PL_last_lop_op = OP_ENTERSUB;
6520                     /* Is there a prototype? */
6521                     if (
6522 #ifdef PERL_MAD
6523                         cv &&
6524 #endif
6525                         SvPOK(cv))
6526                     {
6527                         STRLEN protolen;
6528                         const char *proto = SvPV_const(MUTABLE_SV(cv), protolen);
6529                         if (!protolen)
6530                             TERM(FUNC0SUB);
6531                         while (*proto == ';')
6532                             proto++;
6533                         if (
6534                             (
6535                                 (
6536                                     *proto == '$' || *proto == '_'
6537                                  || *proto == '*' || *proto == '+'
6538                                 )
6539                              && proto[1] == '\0'
6540                             )
6541                          || (
6542                              *proto == '\\' && proto[1] && proto[2] == '\0'
6543                             )
6544                         )
6545                             OPERATOR(UNIOPSUB);
6546                         if (*proto == '\\' && proto[1] == '[') {
6547                             const char *p = proto + 2;
6548                             while(*p && *p != ']')
6549                                 ++p;
6550                             if(*p == ']' && !p[1]) OPERATOR(UNIOPSUB);
6551                         }
6552                         if (*proto == '&' && *s == '{') {
6553                             if (PL_curstash)
6554                                 sv_setpvs(PL_subname, "__ANON__");
6555                             else
6556                                 sv_setpvs(PL_subname, "__ANON__::__ANON__");
6557                             PREBLOCK(LSTOPSUB);
6558                         }
6559                     }
6560 #ifdef PERL_MAD
6561                     {
6562                         if (PL_madskills) {
6563                             PL_nextwhite = PL_thiswhite;
6564                             PL_thiswhite = 0;
6565                         }
6566                         start_force(PL_curforce);
6567                         NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6568                         PL_expect = XTERM;
6569                         if (PL_madskills) {
6570                             PL_nextwhite = nextPL_nextwhite;
6571                             curmad('X', PL_thistoken);
6572                             PL_thistoken = newSVpvs("");
6573                         }
6574                         force_next(WORD);
6575                         TOKEN(NOAMP);
6576                     }
6577                 }
6578
6579                 /* Guess harder when madskills require "best effort". */
6580                 if (PL_madskills && (!gv || !GvCVu(gv))) {
6581                     int probable_sub = 0;
6582                     if (strchr("\"'`$@%0123456789!*+{[<", *s))
6583                         probable_sub = 1;
6584                     else if (isALPHA(*s)) {
6585                         char tmpbuf[1024];
6586                         STRLEN tmplen;
6587                         d = s;
6588                         d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
6589                         if (!keyword(tmpbuf, tmplen, 0))
6590                             probable_sub = 1;
6591                         else {
6592                             while (d < PL_bufend && isSPACE(*d))
6593                                 d++;
6594                             if (*d == '=' && d[1] == '>')
6595                                 probable_sub = 1;
6596                         }
6597                     }
6598                     if (probable_sub) {
6599                         gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
6600                         op_free(pl_yylval.opval);
6601                         pl_yylval.opval = rv2cv_op;
6602                         pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
6603                         PL_last_lop = PL_oldbufptr;
6604                         PL_last_lop_op = OP_ENTERSUB;
6605                         PL_nextwhite = PL_thiswhite;
6606                         PL_thiswhite = 0;
6607                         start_force(PL_curforce);
6608                         NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6609                         PL_expect = XTERM;
6610                         PL_nextwhite = nextPL_nextwhite;
6611                         curmad('X', PL_thistoken);
6612                         PL_thistoken = newSVpvs("");
6613                         force_next(WORD);
6614                         TOKEN(NOAMP);
6615                     }
6616 #else
6617                     NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6618                     PL_expect = XTERM;
6619                     force_next(WORD);
6620                     TOKEN(NOAMP);
6621 #endif
6622                 }
6623
6624                 /* Call it a bare word */
6625
6626                 if (PL_hints & HINT_STRICT_SUBS)
6627                     pl_yylval.opval->op_private |= OPpCONST_STRICT;
6628                 else {
6629                 bareword:
6630                     /* after "print" and similar functions (corresponding to
6631                      * "F? L" in opcode.pl), whatever wasn't already parsed as
6632                      * a filehandle should be subject to "strict subs".
6633                      * Likewise for the optional indirect-object argument to system
6634                      * or exec, which can't be a bareword */
6635                     if ((PL_last_lop_op == OP_PRINT
6636                             || PL_last_lop_op == OP_PRTF
6637                             || PL_last_lop_op == OP_SAY
6638                             || PL_last_lop_op == OP_SYSTEM
6639                             || PL_last_lop_op == OP_EXEC)
6640                             && (PL_hints & HINT_STRICT_SUBS))
6641                         pl_yylval.opval->op_private |= OPpCONST_STRICT;
6642                     if (lastchar != '-') {
6643                         if (ckWARN(WARN_RESERVED)) {
6644                             d = PL_tokenbuf;
6645                             while (isLOWER(*d))
6646                                 d++;
6647                             if (!*d && !gv_stashpv(PL_tokenbuf, 0))
6648                                 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
6649                                        PL_tokenbuf);
6650                         }
6651                     }
6652                 }
6653                 op_free(rv2cv_op);
6654
6655             safe_bareword:
6656                 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')) {
6657                     Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
6658                                      "Operator or semicolon missing before %c%s",
6659                                      lastchar, PL_tokenbuf);
6660                     Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
6661                                      "Ambiguous use of %c resolved as operator %c",
6662                                      lastchar, lastchar);
6663                 }
6664                 TOKEN(WORD);
6665             }
6666
6667         case KEY___FILE__:
6668             pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
6669                                         newSVpv(CopFILE(PL_curcop),0));
6670             TERM(THING);
6671
6672         case KEY___LINE__:
6673             pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
6674                                     Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
6675             TERM(THING);
6676
6677         case KEY___PACKAGE__:
6678             pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
6679                                         (PL_curstash
6680                                          ? newSVhek(HvNAME_HEK(PL_curstash))
6681                                          : &PL_sv_undef));
6682             TERM(THING);
6683
6684         case KEY___DATA__:
6685         case KEY___END__: {
6686             GV *gv;
6687             if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
6688                 const char *pname = "main";
6689                 if (PL_tokenbuf[2] == 'D')
6690                     pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
6691                 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
6692                                 SVt_PVIO);
6693                 GvMULTI_on(gv);
6694                 if (!GvIO(gv))
6695                     GvIOp(gv) = newIO();
6696                 IoIFP(GvIOp(gv)) = PL_rsfp;
6697 #if defined(HAS_FCNTL) && defined(F_SETFD)
6698                 {
6699                     const int fd = PerlIO_fileno(PL_rsfp);
6700                     fcntl(fd,F_SETFD,fd >= 3);
6701                 }
6702 #endif
6703                 /* Mark this internal pseudo-handle as clean */
6704                 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
6705                 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
6706                     IoTYPE(GvIOp(gv)) = IoTYPE_STD;
6707                 else
6708                     IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
6709 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
6710                 /* if the script was opened in binmode, we need to revert
6711                  * it to text mode for compatibility; but only iff it has CRs
6712                  * XXX this is a questionable hack at best. */
6713                 if (PL_bufend-PL_bufptr > 2
6714                     && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
6715                 {
6716                     Off_t loc = 0;
6717                     if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
6718                         loc = PerlIO_tell(PL_rsfp);
6719                         (void)PerlIO_seek(PL_rsfp, 0L, 0);
6720                     }
6721 #ifdef NETWARE
6722                         if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
6723 #else
6724                     if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
6725 #endif  /* NETWARE */
6726 #ifdef PERLIO_IS_STDIO /* really? */
6727 #  if defined(__BORLANDC__)
6728                         /* XXX see note in do_binmode() */
6729                         ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
6730 #  endif
6731 #endif
6732                         if (loc > 0)
6733                             PerlIO_seek(PL_rsfp, loc, 0);
6734                     }
6735                 }
6736 #endif
6737 #ifdef PERLIO_LAYERS
6738                 if (!IN_BYTES) {
6739                     if (UTF)
6740                         PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
6741                     else if (PL_encoding) {
6742                         SV *name;
6743                         dSP;
6744                         ENTER;
6745                         SAVETMPS;
6746                         PUSHMARK(sp);
6747                         EXTEND(SP, 1);
6748                         XPUSHs(PL_encoding);
6749                         PUTBACK;
6750                         call_method("name", G_SCALAR);
6751                         SPAGAIN;
6752                         name = POPs;
6753                         PUTBACK;
6754                         PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
6755                                             Perl_form(aTHX_ ":encoding(%"SVf")",
6756                                                       SVfARG(name)));
6757                         FREETMPS;
6758                         LEAVE;
6759                     }
6760                 }
6761 #endif
6762 #ifdef PERL_MAD
6763                 if (PL_madskills) {
6764                     if (PL_realtokenstart >= 0) {
6765                         char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6766                         if (!PL_endwhite)
6767                             PL_endwhite = newSVpvs("");
6768                         sv_catsv(PL_endwhite, PL_thiswhite);
6769                         PL_thiswhite = 0;
6770                         sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
6771                         PL_realtokenstart = -1;
6772                     }
6773                     while ((s = filter_gets(PL_endwhite, SvCUR(PL_endwhite)))
6774                            != NULL) ;
6775                 }
6776 #endif
6777                 PL_rsfp = NULL;
6778             }
6779             goto fake_eof;
6780         }
6781
6782         case KEY_AUTOLOAD:
6783         case KEY_DESTROY:
6784         case KEY_BEGIN:
6785         case KEY_UNITCHECK:
6786         case KEY_CHECK:
6787         case KEY_INIT:
6788         case KEY_END:
6789             if (PL_expect == XSTATE) {
6790                 s = PL_bufptr;
6791                 goto really_sub;
6792             }
6793             goto just_a_word;
6794
6795         case KEY_CORE:
6796             if (*s == ':' && s[1] == ':') {
6797                 s += 2;
6798                 d = s;
6799                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
6800                 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
6801                     Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
6802                 if (tmp < 0)
6803                     tmp = -tmp;
6804                 else if (tmp == KEY_require || tmp == KEY_do)
6805                     /* that's a way to remember we saw "CORE::" */
6806                     orig_keyword = tmp;
6807                 goto reserved_word;
6808             }
6809             goto just_a_word;
6810
6811         case KEY_abs:
6812             UNI(OP_ABS);
6813
6814         case KEY_alarm:
6815             UNI(OP_ALARM);
6816
6817         case KEY_accept:
6818             LOP(OP_ACCEPT,XTERM);
6819
6820         case KEY_and:
6821             OPERATOR(ANDOP);
6822
6823         case KEY_atan2:
6824             LOP(OP_ATAN2,XTERM);
6825
6826         case KEY_bind:
6827             LOP(OP_BIND,XTERM);
6828
6829         case KEY_binmode:
6830             LOP(OP_BINMODE,XTERM);
6831
6832         case KEY_bless:
6833             LOP(OP_BLESS,XTERM);
6834
6835         case KEY_break:
6836             FUN0(OP_BREAK);
6837
6838         case KEY_chop:
6839             UNI(OP_CHOP);
6840
6841         case KEY_continue:
6842             /* When 'use switch' is in effect, continue has a dual
6843                life as a control operator. */
6844             {
6845                 if (!FEATURE_IS_ENABLED("switch"))
6846                     PREBLOCK(CONTINUE);
6847                 else {
6848                     /* We have to disambiguate the two senses of
6849                       "continue". If the next token is a '{' then
6850                       treat it as the start of a continue block;
6851                       otherwise treat it as a control operator.
6852                      */
6853                     s = skipspace(s);
6854                     if (*s == '{')
6855             PREBLOCK(CONTINUE);
6856                     else
6857                         FUN0(OP_CONTINUE);
6858                 }
6859             }
6860
6861         case KEY_chdir:
6862             /* may use HOME */
6863             (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
6864             UNI(OP_CHDIR);
6865
6866         case KEY_close:
6867             UNI(OP_CLOSE);
6868
6869         case KEY_closedir:
6870             UNI(OP_CLOSEDIR);
6871
6872         case KEY_cmp:
6873             Eop(OP_SCMP);
6874
6875         case KEY_caller:
6876             UNI(OP_CALLER);
6877
6878         case KEY_crypt:
6879 #ifdef FCRYPT
6880             if (!PL_cryptseen) {
6881                 PL_cryptseen = TRUE;
6882                 init_des();
6883             }
6884 #endif
6885             LOP(OP_CRYPT,XTERM);
6886
6887         case KEY_chmod:
6888             LOP(OP_CHMOD,XTERM);
6889
6890         case KEY_chown:
6891             LOP(OP_CHOWN,XTERM);
6892
6893         case KEY_connect:
6894             LOP(OP_CONNECT,XTERM);
6895
6896         case KEY_chr:
6897             UNI(OP_CHR);
6898
6899         case KEY_cos:
6900             UNI(OP_COS);
6901
6902         case KEY_chroot:
6903             UNI(OP_CHROOT);
6904
6905         case KEY_default:
6906             PREBLOCK(DEFAULT);
6907
6908         case KEY_do:
6909             s = SKIPSPACE1(s);
6910             if (*s == '{')
6911                 PRETERMBLOCK(DO);
6912             if (*s != '\'')
6913                 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6914             if (orig_keyword == KEY_do) {
6915                 orig_keyword = 0;
6916                 pl_yylval.ival = 1;
6917             }
6918             else
6919                 pl_yylval.ival = 0;
6920             OPERATOR(DO);
6921
6922         case KEY_die:
6923             PL_hints |= HINT_BLOCK_SCOPE;
6924             LOP(OP_DIE,XTERM);
6925
6926         case KEY_defined:
6927             UNI(OP_DEFINED);
6928
6929         case KEY_delete:
6930             UNI(OP_DELETE);
6931
6932         case KEY_dbmopen:
6933             Perl_populate_isa(aTHX_ STR_WITH_LEN("AnyDBM_File::ISA"),
6934                               STR_WITH_LEN("NDBM_File::"),
6935                               STR_WITH_LEN("DB_File::"),
6936                               STR_WITH_LEN("GDBM_File::"),
6937                               STR_WITH_LEN("SDBM_File::"),
6938                               STR_WITH_LEN("ODBM_File::"),
6939                               NULL);
6940             LOP(OP_DBMOPEN,XTERM);
6941
6942         case KEY_dbmclose:
6943             UNI(OP_DBMCLOSE);
6944
6945         case KEY_dump:
6946             s = force_word(s,WORD,TRUE,FALSE,FALSE);
6947             LOOPX(OP_DUMP);
6948
6949         case KEY_else:
6950             PREBLOCK(ELSE);
6951
6952         case KEY_elsif:
6953             pl_yylval.ival = CopLINE(PL_curcop);
6954             OPERATOR(ELSIF);
6955
6956         case KEY_eq:
6957             Eop(OP_SEQ);
6958
6959         case KEY_exists:
6960             UNI(OP_EXISTS);
6961         
6962         case KEY_exit:
6963             if (PL_madskills)
6964                 UNI(OP_INT);
6965             UNI(OP_EXIT);
6966
6967         case KEY_eval:
6968             s = SKIPSPACE1(s);
6969             if (*s == '{') { /* block eval */
6970                 PL_expect = XTERMBLOCK;
6971                 UNIBRACK(OP_ENTERTRY);
6972             }
6973             else { /* string eval */
6974                 PL_expect = XTERM;
6975                 UNIBRACK(OP_ENTEREVAL);
6976             }
6977
6978         case KEY_eof:
6979             UNI(OP_EOF);
6980
6981         case KEY_exp:
6982             UNI(OP_EXP);
6983
6984         case KEY_each:
6985             UNI(OP_EACH);
6986
6987         case KEY_exec:
6988             LOP(OP_EXEC,XREF);
6989
6990         case KEY_endhostent:
6991             FUN0(OP_EHOSTENT);
6992
6993         case KEY_endnetent:
6994             FUN0(OP_ENETENT);
6995
6996         case KEY_endservent:
6997             FUN0(OP_ESERVENT);
6998
6999         case KEY_endprotoent:
7000             FUN0(OP_EPROTOENT);
7001
7002         case KEY_endpwent:
7003             FUN0(OP_EPWENT);
7004
7005         case KEY_endgrent:
7006             FUN0(OP_EGRENT);
7007
7008         case KEY_for:
7009         case KEY_foreach:
7010             pl_yylval.ival = CopLINE(PL_curcop);
7011             s = SKIPSPACE1(s);
7012             if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
7013                 char *p = s;
7014 #ifdef PERL_MAD
7015                 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
7016 #endif
7017
7018                 if ((PL_bufend - p) >= 3 &&
7019                     strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
7020                     p += 2;
7021                 else if ((PL_bufend - p) >= 4 &&
7022                     strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
7023                     p += 3;
7024                 p = PEEKSPACE(p);
7025                 if (isIDFIRST_lazy_if(p,UTF)) {
7026                     p = scan_ident(p, PL_bufend,
7027                         PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
7028                     p = PEEKSPACE(p);
7029                 }
7030                 if (*p != '$')
7031                     Perl_croak(aTHX_ "Missing $ on loop variable");
7032 #ifdef PERL_MAD
7033                 s = SvPVX(PL_linestr) + soff;
7034 #endif
7035             }
7036             OPERATOR(FOR);
7037
7038         case KEY_formline:
7039             LOP(OP_FORMLINE,XTERM);
7040
7041         case KEY_fork:
7042             FUN0(OP_FORK);
7043
7044         case KEY_fcntl:
7045             LOP(OP_FCNTL,XTERM);
7046
7047         case KEY_fileno:
7048             UNI(OP_FILENO);
7049
7050         case KEY_flock:
7051             LOP(OP_FLOCK,XTERM);
7052
7053         case KEY_gt:
7054             Rop(OP_SGT);
7055
7056         case KEY_ge:
7057             Rop(OP_SGE);
7058
7059         case KEY_grep:
7060             LOP(OP_GREPSTART, XREF);
7061
7062         case KEY_goto:
7063             s = force_word(s,WORD,TRUE,FALSE,FALSE);
7064             LOOPX(OP_GOTO);
7065
7066         case KEY_gmtime:
7067             UNI(OP_GMTIME);
7068
7069         case KEY_getc:
7070             UNIDOR(OP_GETC);
7071
7072         case KEY_getppid:
7073             FUN0(OP_GETPPID);
7074
7075         case KEY_getpgrp:
7076             UNI(OP_GETPGRP);
7077
7078         case KEY_getpriority:
7079             LOP(OP_GETPRIORITY,XTERM);
7080
7081         case KEY_getprotobyname:
7082             UNI(OP_GPBYNAME);
7083
7084         case KEY_getprotobynumber:
7085             LOP(OP_GPBYNUMBER,XTERM);
7086
7087         case KEY_getprotoent:
7088             FUN0(OP_GPROTOENT);
7089
7090         case KEY_getpwent:
7091             FUN0(OP_GPWENT);
7092
7093         case KEY_getpwnam:
7094             UNI(OP_GPWNAM);
7095
7096         case KEY_getpwuid:
7097             UNI(OP_GPWUID);
7098
7099         case KEY_getpeername:
7100             UNI(OP_GETPEERNAME);
7101
7102         case KEY_gethostbyname:
7103             UNI(OP_GHBYNAME);
7104
7105         case KEY_gethostbyaddr:
7106             LOP(OP_GHBYADDR,XTERM);
7107
7108         case KEY_gethostent:
7109             FUN0(OP_GHOSTENT);
7110
7111         case KEY_getnetbyname:
7112             UNI(OP_GNBYNAME);
7113
7114         case KEY_getnetbyaddr:
7115             LOP(OP_GNBYADDR,XTERM);
7116
7117         case KEY_getnetent:
7118             FUN0(OP_GNETENT);
7119
7120         case KEY_getservbyname:
7121             LOP(OP_GSBYNAME,XTERM);
7122
7123         case KEY_getservbyport:
7124             LOP(OP_GSBYPORT,XTERM);
7125
7126         case KEY_getservent:
7127             FUN0(OP_GSERVENT);
7128
7129         case KEY_getsockname:
7130             UNI(OP_GETSOCKNAME);
7131
7132         case KEY_getsockopt:
7133             LOP(OP_GSOCKOPT,XTERM);
7134
7135         case KEY_getgrent:
7136             FUN0(OP_GGRENT);
7137
7138         case KEY_getgrnam:
7139             UNI(OP_GGRNAM);
7140
7141         case KEY_getgrgid:
7142             UNI(OP_GGRGID);
7143
7144         case KEY_getlogin:
7145             FUN0(OP_GETLOGIN);
7146
7147         case KEY_given:
7148             pl_yylval.ival = CopLINE(PL_curcop);
7149             OPERATOR(GIVEN);
7150
7151         case KEY_glob:
7152             LOP(OP_GLOB,XTERM);
7153
7154         case KEY_hex:
7155             UNI(OP_HEX);
7156
7157         case KEY_if:
7158             pl_yylval.ival = CopLINE(PL_curcop);
7159             OPERATOR(IF);
7160
7161         case KEY_index:
7162             LOP(OP_INDEX,XTERM);
7163
7164         case KEY_int:
7165             UNI(OP_INT);
7166
7167         case KEY_ioctl:
7168             LOP(OP_IOCTL,XTERM);
7169
7170         case KEY_join:
7171             LOP(OP_JOIN,XTERM);
7172
7173         case KEY_keys:
7174             UNI(OP_KEYS);
7175
7176         case KEY_kill:
7177             LOP(OP_KILL,XTERM);
7178
7179         case KEY_last:
7180             s = force_word(s,WORD,TRUE,FALSE,FALSE);
7181             LOOPX(OP_LAST);
7182         
7183         case KEY_lc:
7184             UNI(OP_LC);
7185
7186         case KEY_lcfirst:
7187             UNI(OP_LCFIRST);
7188
7189         case KEY_local:
7190             pl_yylval.ival = 0;
7191             OPERATOR(LOCAL);
7192
7193         case KEY_length:
7194             UNI(OP_LENGTH);
7195
7196         case KEY_lt:
7197             Rop(OP_SLT);
7198
7199         case KEY_le:
7200             Rop(OP_SLE);
7201
7202         case KEY_localtime:
7203             UNI(OP_LOCALTIME);
7204
7205         case KEY_log:
7206             UNI(OP_LOG);
7207
7208         case KEY_link:
7209             LOP(OP_LINK,XTERM);
7210
7211         case KEY_listen:
7212             LOP(OP_LISTEN,XTERM);
7213
7214         case KEY_lock:
7215             UNI(OP_LOCK);
7216
7217         case KEY_lstat:
7218             UNI(OP_LSTAT);
7219
7220         case KEY_m:
7221             s = scan_pat(s,OP_MATCH);
7222             TERM(sublex_start());
7223
7224         case KEY_map:
7225             LOP(OP_MAPSTART, XREF);
7226
7227         case KEY_mkdir:
7228             LOP(OP_MKDIR,XTERM);
7229
7230         case KEY_msgctl:
7231             LOP(OP_MSGCTL,XTERM);
7232
7233         case KEY_msgget:
7234             LOP(OP_MSGGET,XTERM);
7235
7236         case KEY_msgrcv:
7237             LOP(OP_MSGRCV,XTERM);
7238
7239         case KEY_msgsnd:
7240             LOP(OP_MSGSND,XTERM);
7241
7242         case KEY_our:
7243         case KEY_my:
7244         case KEY_state:
7245             PL_in_my = (U16)tmp;
7246             s = SKIPSPACE1(s);
7247             if (isIDFIRST_lazy_if(s,UTF)) {
7248 #ifdef PERL_MAD
7249                 char* start = s;
7250 #endif
7251                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
7252                 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
7253                     goto really_sub;
7254                 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
7255                 if (!PL_in_my_stash) {
7256                     char tmpbuf[1024];
7257                     PL_bufptr = s;
7258                     my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
7259                     yyerror(tmpbuf);
7260                 }
7261 #ifdef PERL_MAD
7262                 if (PL_madskills) {     /* just add type to declarator token */
7263                     sv_catsv(PL_thistoken, PL_nextwhite);
7264                     PL_nextwhite = 0;
7265                     sv_catpvn(PL_thistoken, start, s - start);
7266                 }
7267 #endif
7268             }
7269             pl_yylval.ival = 1;
7270             OPERATOR(MY);
7271
7272         case KEY_next:
7273             s = force_word(s,WORD,TRUE,FALSE,FALSE);
7274             LOOPX(OP_NEXT);
7275
7276         case KEY_ne:
7277             Eop(OP_SNE);
7278
7279         case KEY_no:
7280             s = tokenize_use(0, s);
7281             OPERATOR(USE);
7282
7283         case KEY_not:
7284             if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
7285                 FUN1(OP_NOT);
7286             else
7287                 OPERATOR(NOTOP);
7288
7289         case KEY_open:
7290             s = SKIPSPACE1(s);
7291             if (isIDFIRST_lazy_if(s,UTF)) {
7292                 const char *t;
7293                 for (d = s; isALNUM_lazy_if(d,UTF);)
7294                     d++;
7295                 for (t=d; isSPACE(*t);)
7296                     t++;
7297                 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
7298                     /* [perl #16184] */
7299                     && !(t[0] == '=' && t[1] == '>')
7300                 ) {
7301                     int parms_len = (int)(d-s);
7302                     Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
7303                            "Precedence problem: open %.*s should be open(%.*s)",
7304                             parms_len, s, parms_len, s);
7305                 }
7306             }
7307             LOP(OP_OPEN,XTERM);
7308
7309         case KEY_or:
7310             pl_yylval.ival = OP_OR;
7311             OPERATOR(OROP);
7312
7313         case KEY_ord:
7314             UNI(OP_ORD);
7315
7316         case KEY_oct:
7317             UNI(OP_OCT);
7318
7319         case KEY_opendir:
7320             LOP(OP_OPEN_DIR,XTERM);
7321
7322         case KEY_print:
7323             checkcomma(s,PL_tokenbuf,"filehandle");
7324             LOP(OP_PRINT,XREF);
7325
7326         case KEY_printf:
7327             checkcomma(s,PL_tokenbuf,"filehandle");
7328             LOP(OP_PRTF,XREF);
7329
7330         case KEY_prototype:
7331             UNI(OP_PROTOTYPE);
7332
7333         case KEY_push:
7334             LOP(OP_PUSH,XTERM);
7335
7336         case KEY_pop:
7337             UNIDOR(OP_POP);
7338
7339         case KEY_pos:
7340             UNIDOR(OP_POS);
7341         
7342         case KEY_pack:
7343             LOP(OP_PACK,XTERM);
7344
7345         case KEY_package:
7346             s = force_word(s,WORD,FALSE,TRUE,FALSE);
7347             s = SKIPSPACE1(s);
7348             s = force_strict_version(s);
7349             PL_lex_expect = XBLOCK;
7350             OPERATOR(PACKAGE);
7351
7352         case KEY_pipe:
7353             LOP(OP_PIPE_OP,XTERM);
7354
7355         case KEY_q:
7356             s = scan_str(s,!!PL_madskills,FALSE);
7357             if (!s)
7358                 missingterm(NULL);
7359             pl_yylval.ival = OP_CONST;
7360             TERM(sublex_start());
7361
7362         case KEY_quotemeta:
7363             UNI(OP_QUOTEMETA);
7364
7365         case KEY_qw: {
7366             OP *words = NULL;
7367             s = scan_str(s,!!PL_madskills,FALSE);
7368             if (!s)
7369                 missingterm(NULL);
7370             PL_expect = XOPERATOR;
7371             if (SvCUR(PL_lex_stuff)) {
7372                 int warned = 0;
7373                 d = SvPV_force(PL_lex_stuff, len);
7374                 while (len) {
7375                     for (; isSPACE(*d) && len; --len, ++d)
7376                         /**/;
7377                     if (len) {
7378                         SV *sv;
7379                         const char *b = d;
7380                         if (!warned && ckWARN(WARN_QW)) {
7381                             for (; !isSPACE(*d) && len; --len, ++d) {
7382                                 if (*d == ',') {
7383                                     Perl_warner(aTHX_ packWARN(WARN_QW),
7384                                         "Possible attempt to separate words with commas");
7385                                     ++warned;
7386                                 }
7387                                 else if (*d == '#') {
7388                                     Perl_warner(aTHX_ packWARN(WARN_QW),
7389                                         "Possible attempt to put comments in qw() list");
7390                                     ++warned;
7391                                 }
7392                             }
7393                         }
7394                         else {
7395                             for (; !isSPACE(*d) && len; --len, ++d)
7396                                 /**/;
7397                         }
7398                         sv = newSVpvn_utf8(b, d-b, DO_UTF8(PL_lex_stuff));
7399                         words = op_append_elem(OP_LIST, words,
7400                                             newSVOP(OP_CONST, 0, tokeq(sv)));
7401                     }
7402                 }
7403             }
7404             if (!words)
7405                 words = newNULLLIST();
7406             if (PL_lex_stuff) {
7407                 SvREFCNT_dec(PL_lex_stuff);
7408                 PL_lex_stuff = NULL;
7409             }
7410             PL_expect = XOPERATOR;
7411             pl_yylval.opval = sawparens(words);
7412             TOKEN(QWLIST);
7413         }
7414
7415         case KEY_qq:
7416             s = scan_str(s,!!PL_madskills,FALSE);
7417             if (!s)
7418                 missingterm(NULL);
7419             pl_yylval.ival = OP_STRINGIFY;
7420             if (SvIVX(PL_lex_stuff) == '\'')
7421                 SvIV_set(PL_lex_stuff, 0);      /* qq'$foo' should intepolate */
7422             TERM(sublex_start());
7423
7424         case KEY_qr:
7425             s = scan_pat(s,OP_QR);
7426             TERM(sublex_start());
7427
7428         case KEY_qx:
7429             s = scan_str(s,!!PL_madskills,FALSE);
7430             if (!s)
7431                 missingterm(NULL);
7432             readpipe_override();
7433             TERM(sublex_start());
7434
7435         case KEY_return:
7436             OLDLOP(OP_RETURN);
7437
7438         case KEY_require:
7439             s = SKIPSPACE1(s);
7440             if (isDIGIT(*s)) {
7441                 s = force_version(s, FALSE);
7442             }
7443             else if (*s != 'v' || !isDIGIT(s[1])
7444                     || (s = force_version(s, TRUE), *s == 'v'))
7445             {
7446                 *PL_tokenbuf = '\0';
7447                 s = force_word(s,WORD,TRUE,TRUE,FALSE);
7448                 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
7449                     gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
7450                 else if (*s == '<')
7451                     yyerror("<> should be quotes");
7452             }
7453             if (orig_keyword == KEY_require) {
7454                 orig_keyword = 0;
7455                 pl_yylval.ival = 1;
7456             }
7457             else 
7458                 pl_yylval.ival = 0;
7459             PL_expect = XTERM;
7460             PL_bufptr = s;
7461             PL_last_uni = PL_oldbufptr;
7462             PL_last_lop_op = OP_REQUIRE;
7463             s = skipspace(s);
7464             return REPORT( (int)REQUIRE );
7465
7466         case KEY_reset:
7467             UNI(OP_RESET);
7468
7469         case KEY_redo:
7470             s = force_word(s,WORD,TRUE,FALSE,FALSE);
7471             LOOPX(OP_REDO);
7472
7473         case KEY_rename:
7474             LOP(OP_RENAME,XTERM);
7475
7476         case KEY_rand:
7477             UNI(OP_RAND);
7478
7479         case KEY_rmdir:
7480             UNI(OP_RMDIR);
7481
7482         case KEY_rindex:
7483             LOP(OP_RINDEX,XTERM);
7484
7485         case KEY_read:
7486             LOP(OP_READ,XTERM);
7487
7488         case KEY_readdir:
7489             UNI(OP_READDIR);
7490
7491         case KEY_readline:
7492             UNIDOR(OP_READLINE);
7493
7494         case KEY_readpipe:
7495             UNIDOR(OP_BACKTICK);
7496
7497         case KEY_rewinddir:
7498             UNI(OP_REWINDDIR);
7499
7500         case KEY_recv:
7501             LOP(OP_RECV,XTERM);
7502
7503         case KEY_reverse:
7504             LOP(OP_REVERSE,XTERM);
7505
7506         case KEY_readlink:
7507             UNIDOR(OP_READLINK);
7508
7509         case KEY_ref:
7510             UNI(OP_REF);
7511
7512         case KEY_s:
7513             s = scan_subst(s);
7514             if (pl_yylval.opval)
7515                 TERM(sublex_start());
7516             else
7517                 TOKEN(1);       /* force error */
7518
7519         case KEY_say:
7520             checkcomma(s,PL_tokenbuf,"filehandle");
7521             LOP(OP_SAY,XREF);
7522
7523         case KEY_chomp:
7524             UNI(OP_CHOMP);
7525         
7526         case KEY_scalar:
7527             UNI(OP_SCALAR);
7528
7529         case KEY_select:
7530             LOP(OP_SELECT,XTERM);
7531
7532         case KEY_seek:
7533             LOP(OP_SEEK,XTERM);
7534
7535         case KEY_semctl:
7536             LOP(OP_SEMCTL,XTERM);
7537
7538         case KEY_semget:
7539             LOP(OP_SEMGET,XTERM);
7540
7541         case KEY_semop:
7542             LOP(OP_SEMOP,XTERM);
7543
7544         case KEY_send:
7545             LOP(OP_SEND,XTERM);
7546
7547         case KEY_setpgrp:
7548             LOP(OP_SETPGRP,XTERM);
7549
7550         case KEY_setpriority:
7551             LOP(OP_SETPRIORITY,XTERM);
7552
7553         case KEY_sethostent:
7554             UNI(OP_SHOSTENT);
7555
7556         case KEY_setnetent:
7557             UNI(OP_SNETENT);
7558
7559         case KEY_setservent:
7560             UNI(OP_SSERVENT);
7561
7562         case KEY_setprotoent:
7563             UNI(OP_SPROTOENT);
7564
7565         case KEY_setpwent:
7566             FUN0(OP_SPWENT);
7567
7568         case KEY_setgrent:
7569             FUN0(OP_SGRENT);
7570
7571         case KEY_seekdir:
7572             LOP(OP_SEEKDIR,XTERM);
7573
7574         case KEY_setsockopt:
7575             LOP(OP_SSOCKOPT,XTERM);
7576
7577         case KEY_shift:
7578             UNIDOR(OP_SHIFT);
7579
7580         case KEY_shmctl:
7581             LOP(OP_SHMCTL,XTERM);
7582
7583         case KEY_shmget:
7584             LOP(OP_SHMGET,XTERM);
7585
7586         case KEY_shmread:
7587             LOP(OP_SHMREAD,XTERM);
7588
7589         case KEY_shmwrite:
7590             LOP(OP_SHMWRITE,XTERM);
7591
7592         case KEY_shutdown:
7593             LOP(OP_SHUTDOWN,XTERM);
7594
7595         case KEY_sin:
7596             UNI(OP_SIN);
7597
7598         case KEY_sleep:
7599             UNI(OP_SLEEP);
7600
7601         case KEY_socket:
7602             LOP(OP_SOCKET,XTERM);
7603
7604         case KEY_socketpair:
7605             LOP(OP_SOCKPAIR,XTERM);
7606
7607         case KEY_sort:
7608             checkcomma(s,PL_tokenbuf,"subroutine name");
7609             s = SKIPSPACE1(s);
7610             if (*s == ';' || *s == ')')         /* probably a close */
7611                 Perl_croak(aTHX_ "sort is now a reserved word");
7612             PL_expect = XTERM;
7613             s = force_word(s,WORD,TRUE,TRUE,FALSE);
7614             LOP(OP_SORT,XREF);
7615
7616         case KEY_split:
7617             LOP(OP_SPLIT,XTERM);
7618
7619         case KEY_sprintf:
7620             LOP(OP_SPRINTF,XTERM);
7621
7622         case KEY_splice:
7623             LOP(OP_SPLICE,XTERM);
7624
7625         case KEY_sqrt:
7626             UNI(OP_SQRT);
7627
7628         case KEY_srand:
7629             UNI(OP_SRAND);
7630
7631         case KEY_stat:
7632             UNI(OP_STAT);
7633
7634         case KEY_study:
7635             UNI(OP_STUDY);
7636
7637         case KEY_substr:
7638             LOP(OP_SUBSTR,XTERM);
7639
7640         case KEY_format:
7641         case KEY_sub:
7642           really_sub:
7643             {
7644                 char tmpbuf[sizeof PL_tokenbuf];
7645                 SSize_t tboffset = 0;
7646                 expectation attrful;
7647                 bool have_name, have_proto;
7648                 const int key = tmp;
7649
7650 #ifdef PERL_MAD
7651                 SV *tmpwhite = 0;
7652
7653                 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
7654                 SV *subtoken = newSVpvn(tstart, s - tstart);
7655                 PL_thistoken = 0;
7656
7657                 d = s;
7658                 s = SKIPSPACE2(s,tmpwhite);
7659 #else
7660                 s = skipspace(s);
7661 #endif
7662
7663                 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
7664                     (*s == ':' && s[1] == ':'))
7665                 {
7666 #ifdef PERL_MAD
7667                     SV *nametoke = NULL;
7668 #endif
7669
7670                     PL_expect = XBLOCK;
7671                     attrful = XATTRBLOCK;
7672                     /* remember buffer pos'n for later force_word */
7673                     tboffset = s - PL_oldbufptr;
7674                     d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
7675 #ifdef PERL_MAD
7676                     if (PL_madskills)
7677                         nametoke = newSVpvn(s, d - s);
7678 #endif
7679                     if (memchr(tmpbuf, ':', len))
7680                         sv_setpvn(PL_subname, tmpbuf, len);
7681                     else {
7682                         sv_setsv(PL_subname,PL_curstname);
7683                         sv_catpvs(PL_subname,"::");
7684                         sv_catpvn(PL_subname,tmpbuf,len);
7685                     }
7686                     have_name = TRUE;
7687
7688 #ifdef PERL_MAD
7689
7690                     start_force(0);
7691                     CURMAD('X', nametoke);
7692                     CURMAD('_', tmpwhite);
7693                     (void) force_word(PL_oldbufptr + tboffset, WORD,
7694                                       FALSE, TRUE, TRUE);
7695
7696                     s = SKIPSPACE2(d,tmpwhite);
7697 #else
7698                     s = skipspace(d);
7699 #endif
7700                 }
7701                 else {
7702                     if (key == KEY_my)
7703                         Perl_croak(aTHX_ "Missing name in \"my sub\"");
7704                     PL_expect = XTERMBLOCK;
7705                     attrful = XATTRTERM;
7706                     sv_setpvs(PL_subname,"?");
7707                     have_name = FALSE;
7708                 }
7709
7710                 if (key == KEY_format) {
7711                     if (*s == '=')
7712                         PL_lex_formbrack = PL_lex_brackets + 1;
7713 #ifdef PERL_MAD
7714                     PL_thistoken = subtoken;
7715                     s = d;
7716 #else
7717                     if (have_name)
7718                         (void) force_word(PL_oldbufptr + tboffset, WORD,
7719                                           FALSE, TRUE, TRUE);
7720 #endif
7721                     OPERATOR(FORMAT);
7722                 }
7723
7724                 /* Look for a prototype */
7725                 if (*s == '(') {
7726                     char *p;
7727                     bool bad_proto = FALSE;
7728                     bool in_brackets = FALSE;
7729                     char greedy_proto = ' ';
7730                     bool proto_after_greedy_proto = FALSE;
7731                     bool must_be_last = FALSE;
7732                     bool underscore = FALSE;
7733                     bool seen_underscore = FALSE;
7734                     const bool warnillegalproto = ckWARN(WARN_ILLEGALPROTO);
7735
7736                     s = scan_str(s,!!PL_madskills,FALSE);
7737                     if (!s)
7738                         Perl_croak(aTHX_ "Prototype not terminated");
7739                     /* strip spaces and check for bad characters */
7740                     d = SvPVX(PL_lex_stuff);
7741                     tmp = 0;
7742                     for (p = d; *p; ++p) {
7743                         if (!isSPACE(*p)) {
7744                             d[tmp++] = *p;
7745
7746                             if (warnillegalproto) {
7747                                 if (must_be_last)
7748                                     proto_after_greedy_proto = TRUE;
7749                                 if (!strchr("$@%*;[]&\\_+", *p)) {
7750                                     bad_proto = TRUE;
7751                                 }
7752                                 else {
7753                                     if ( underscore ) {
7754                                         if ( *p != ';' )
7755                                             bad_proto = TRUE;
7756                                         underscore = FALSE;
7757                                     }
7758                                     if ( *p == '[' ) {
7759                                         in_brackets = TRUE;
7760                                     }
7761                                     else if ( *p == ']' ) {
7762                                         in_brackets = FALSE;
7763                                     }
7764                                     else if ( (*p == '@' || *p == '%') &&
7765                                          ( tmp < 2 || d[tmp-2] != '\\' ) &&
7766                                          !in_brackets ) {
7767                                         must_be_last = TRUE;
7768                                         greedy_proto = *p;
7769                                     }
7770                                     else if ( *p == '_' ) {
7771                                         underscore = seen_underscore = TRUE;
7772                                     }
7773                                 }
7774                             }
7775                         }
7776                     }
7777                     d[tmp] = '\0';
7778                     if (proto_after_greedy_proto)
7779                         Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO),
7780                                     "Prototype after '%c' for %"SVf" : %s",
7781                                     greedy_proto, SVfARG(PL_subname), d);
7782                     if (bad_proto)
7783                         Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO),
7784                                     "Illegal character %sin prototype for %"SVf" : %s",
7785                                     seen_underscore ? "after '_' " : "",
7786                                     SVfARG(PL_subname), d);
7787                     SvCUR_set(PL_lex_stuff, tmp);
7788                     have_proto = TRUE;
7789
7790 #ifdef PERL_MAD
7791                     start_force(0);
7792                     CURMAD('q', PL_thisopen);
7793                     CURMAD('_', tmpwhite);
7794                     CURMAD('=', PL_thisstuff);
7795                     CURMAD('Q', PL_thisclose);
7796                     NEXTVAL_NEXTTOKE.opval =
7797                         (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
7798                     PL_lex_stuff = NULL;
7799                     force_next(THING);
7800
7801                     s = SKIPSPACE2(s,tmpwhite);
7802 #else
7803                     s = skipspace(s);
7804 #endif
7805                 }
7806                 else
7807                     have_proto = FALSE;
7808
7809                 if (*s == ':' && s[1] != ':')
7810                     PL_expect = attrful;
7811                 else if (*s != '{' && key == KEY_sub) {
7812                     if (!have_name)
7813                         Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
7814                     else if (*s != ';' && *s != '}')
7815                         Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
7816                 }
7817
7818 #ifdef PERL_MAD
7819                 start_force(0);
7820                 if (tmpwhite) {
7821                     if (PL_madskills)
7822                         curmad('^', newSVpvs(""));
7823                     CURMAD('_', tmpwhite);
7824                 }
7825                 force_next(0);
7826
7827                 PL_thistoken = subtoken;
7828 #else
7829                 if (have_proto) {
7830                     NEXTVAL_NEXTTOKE.opval =
7831                         (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
7832                     PL_lex_stuff = NULL;
7833                     force_next(THING);
7834                 }
7835 #endif
7836                 if (!have_name) {
7837                     if (PL_curstash)
7838                         sv_setpvs(PL_subname, "__ANON__");
7839                     else
7840                         sv_setpvs(PL_subname, "__ANON__::__ANON__");
7841                     TOKEN(ANONSUB);
7842                 }
7843 #ifndef PERL_MAD
7844                 (void) force_word(PL_oldbufptr + tboffset, WORD,
7845                                   FALSE, TRUE, TRUE);
7846 #endif
7847                 if (key == KEY_my)
7848                     TOKEN(MYSUB);
7849                 TOKEN(SUB);
7850             }
7851
7852         case KEY_system:
7853             LOP(OP_SYSTEM,XREF);
7854
7855         case KEY_symlink:
7856             LOP(OP_SYMLINK,XTERM);
7857
7858         case KEY_syscall:
7859             LOP(OP_SYSCALL,XTERM);
7860
7861         case KEY_sysopen:
7862             LOP(OP_SYSOPEN,XTERM);
7863
7864         case KEY_sysseek:
7865             LOP(OP_SYSSEEK,XTERM);
7866
7867         case KEY_sysread:
7868             LOP(OP_SYSREAD,XTERM);
7869
7870         case KEY_syswrite:
7871             LOP(OP_SYSWRITE,XTERM);
7872
7873         case KEY_tr:
7874             s = scan_trans(s);
7875             TERM(sublex_start());
7876
7877         case KEY_tell:
7878             UNI(OP_TELL);
7879
7880         case KEY_telldir:
7881             UNI(OP_TELLDIR);
7882
7883         case KEY_tie:
7884             LOP(OP_TIE,XTERM);
7885
7886         case KEY_tied:
7887             UNI(OP_TIED);
7888
7889         case KEY_time:
7890             FUN0(OP_TIME);
7891
7892         case KEY_times:
7893             FUN0(OP_TMS);
7894
7895         case KEY_truncate:
7896             LOP(OP_TRUNCATE,XTERM);
7897
7898         case KEY_uc:
7899             UNI(OP_UC);
7900
7901         case KEY_ucfirst:
7902             UNI(OP_UCFIRST);
7903
7904         case KEY_untie:
7905             UNI(OP_UNTIE);
7906
7907         case KEY_until:
7908             pl_yylval.ival = CopLINE(PL_curcop);
7909             OPERATOR(UNTIL);
7910
7911         case KEY_unless:
7912             pl_yylval.ival = CopLINE(PL_curcop);
7913             OPERATOR(UNLESS);
7914
7915         case KEY_unlink:
7916             LOP(OP_UNLINK,XTERM);
7917
7918         case KEY_undef:
7919             UNIDOR(OP_UNDEF);
7920
7921         case KEY_unpack:
7922             LOP(OP_UNPACK,XTERM);
7923
7924         case KEY_utime:
7925             LOP(OP_UTIME,XTERM);
7926
7927         case KEY_umask:
7928             UNIDOR(OP_UMASK);
7929
7930         case KEY_unshift:
7931             LOP(OP_UNSHIFT,XTERM);
7932
7933         case KEY_use:
7934             s = tokenize_use(1, s);
7935             OPERATOR(USE);
7936
7937         case KEY_values:
7938             UNI(OP_VALUES);
7939
7940         case KEY_vec:
7941             LOP(OP_VEC,XTERM);
7942
7943         case KEY_when:
7944             pl_yylval.ival = CopLINE(PL_curcop);
7945             OPERATOR(WHEN);
7946
7947         case KEY_while:
7948             pl_yylval.ival = CopLINE(PL_curcop);
7949             OPERATOR(WHILE);
7950
7951         case KEY_warn:
7952             PL_hints |= HINT_BLOCK_SCOPE;
7953             LOP(OP_WARN,XTERM);
7954
7955         case KEY_wait:
7956             FUN0(OP_WAIT);
7957
7958         case KEY_waitpid:
7959             LOP(OP_WAITPID,XTERM);
7960
7961         case KEY_wantarray:
7962             FUN0(OP_WANTARRAY);
7963
7964         case KEY_write:
7965 #ifdef EBCDIC
7966         {
7967             char ctl_l[2];
7968             ctl_l[0] = toCTRL('L');
7969             ctl_l[1] = '\0';
7970             gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
7971         }
7972 #else
7973             /* Make sure $^L is defined */
7974             gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
7975 #endif
7976             UNI(OP_ENTERWRITE);
7977
7978         case KEY_x:
7979             if (PL_expect == XOPERATOR)
7980                 Mop(OP_REPEAT);
7981             check_uni();
7982             goto just_a_word;
7983
7984         case KEY_xor:
7985             pl_yylval.ival = OP_XOR;
7986             OPERATOR(OROP);
7987
7988         case KEY_y:
7989             s = scan_trans(s);
7990             TERM(sublex_start());
7991         }
7992     }}
7993 }
7994 #ifdef __SC__
7995 #pragma segment Main
7996 #endif
7997
7998 static int
7999 S_pending_ident(pTHX)
8000 {
8001     dVAR;
8002     register char *d;
8003     PADOFFSET tmp = 0;
8004     /* pit holds the identifier we read and pending_ident is reset */
8005     char pit = PL_pending_ident;
8006     const STRLEN tokenbuf_len = strlen(PL_tokenbuf);
8007     /* All routes through this function want to know if there is a colon.  */
8008     const char *const has_colon = (const char*) memchr (PL_tokenbuf, ':', tokenbuf_len);
8009     PL_pending_ident = 0;
8010
8011     /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
8012     DEBUG_T({ PerlIO_printf(Perl_debug_log,
8013           "### Pending identifier '%s'\n", PL_tokenbuf); });
8014
8015     /* if we're in a my(), we can't allow dynamics here.
8016        $foo'bar has already been turned into $foo::bar, so
8017        just check for colons.
8018
8019        if it's a legal name, the OP is a PADANY.
8020     */
8021     if (PL_in_my) {
8022         if (PL_in_my == KEY_our) {      /* "our" is merely analogous to "my" */
8023             if (has_colon)
8024                 yyerror(Perl_form(aTHX_ "No package name allowed for "
8025                                   "variable %s in \"our\"",
8026                                   PL_tokenbuf));
8027             tmp = allocmy(PL_tokenbuf, tokenbuf_len, 0);
8028         }
8029         else {
8030             if (has_colon)
8031                 yyerror(Perl_form(aTHX_ PL_no_myglob,
8032                             PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
8033
8034             pl_yylval.opval = newOP(OP_PADANY, 0);
8035             pl_yylval.opval->op_targ = allocmy(PL_tokenbuf, tokenbuf_len, 0);
8036             return PRIVATEREF;
8037         }
8038     }
8039
8040     /*
8041        build the ops for accesses to a my() variable.
8042
8043        Deny my($a) or my($b) in a sort block, *if* $a or $b is
8044        then used in a comparison.  This catches most, but not
8045        all cases.  For instance, it catches
8046            sort { my($a); $a <=> $b }
8047        but not
8048            sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
8049        (although why you'd do that is anyone's guess).
8050     */
8051
8052     if (!has_colon) {
8053         if (!PL_in_my)
8054             tmp = pad_findmy(PL_tokenbuf, tokenbuf_len, 0);
8055         if (tmp != NOT_IN_PAD) {
8056             /* might be an "our" variable" */
8057             if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
8058                 /* build ops for a bareword */
8059                 HV *  const stash = PAD_COMPNAME_OURSTASH(tmp);
8060                 HEK * const stashname = HvNAME_HEK(stash);
8061                 SV *  const sym = newSVhek(stashname);
8062                 sv_catpvs(sym, "::");
8063                 sv_catpvn(sym, PL_tokenbuf+1, tokenbuf_len - 1);
8064                 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
8065                 pl_yylval.opval->op_private = OPpCONST_ENTERED;
8066                 gv_fetchsv(sym,
8067                     (PL_in_eval
8068                         ? (GV_ADDMULTI | GV_ADDINEVAL)
8069                         : GV_ADDMULTI
8070                     ),
8071                     ((PL_tokenbuf[0] == '$') ? SVt_PV
8072                      : (PL_tokenbuf[0] == '@') ? SVt_PVAV
8073                      : SVt_PVHV));
8074                 return WORD;
8075             }
8076
8077             /* if it's a sort block and they're naming $a or $b */
8078             if (PL_last_lop_op == OP_SORT &&
8079                 PL_tokenbuf[0] == '$' &&
8080                 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
8081                 && !PL_tokenbuf[2])
8082             {
8083                 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
8084                      d < PL_bufend && *d != '\n';
8085                      d++)
8086                 {
8087                     if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
8088                         Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
8089                               PL_tokenbuf);
8090                     }
8091                 }
8092             }
8093
8094             pl_yylval.opval = newOP(OP_PADANY, 0);
8095             pl_yylval.opval->op_targ = tmp;
8096             return PRIVATEREF;
8097         }
8098     }
8099
8100     /*
8101        Whine if they've said @foo in a doublequoted string,
8102        and @foo isn't a variable we can find in the symbol
8103        table.
8104     */
8105     if (ckWARN(WARN_AMBIGUOUS) &&
8106         pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
8107         GV *const gv = gv_fetchpvn_flags(PL_tokenbuf + 1, tokenbuf_len - 1, 0,
8108                                          SVt_PVAV);
8109         if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
8110                 /* DO NOT warn for @- and @+ */
8111                 && !( PL_tokenbuf[2] == '\0' &&
8112                     ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
8113            )
8114         {
8115             /* Downgraded from fatal to warning 20000522 mjd */
8116             Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
8117                         "Possible unintended interpolation of %s in string",
8118                         PL_tokenbuf);
8119         }
8120     }
8121
8122     /* build ops for a bareword */
8123     pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpvn(PL_tokenbuf + 1,
8124                                                       tokenbuf_len - 1));
8125     pl_yylval.opval->op_private = OPpCONST_ENTERED;
8126     gv_fetchpvn_flags(PL_tokenbuf+1, tokenbuf_len - 1,
8127                      PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD,
8128                      ((PL_tokenbuf[0] == '$') ? SVt_PV
8129                       : (PL_tokenbuf[0] == '@') ? SVt_PVAV
8130                       : SVt_PVHV));
8131     return WORD;
8132 }
8133
8134 /*
8135  *  The following code was generated by perl_keyword.pl.
8136  */
8137
8138 I32
8139 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
8140 {
8141     dVAR;
8142
8143     PERL_ARGS_ASSERT_KEYWORD;
8144
8145   switch (len)
8146   {
8147     case 1: /* 5 tokens of length 1 */
8148       switch (name[0])
8149       {
8150         case 'm':
8151           {                                       /* m          */
8152             return KEY_m;
8153           }
8154
8155         case 'q':
8156           {                                       /* q          */
8157             return KEY_q;
8158           }
8159
8160         case 's':
8161           {                                       /* s          */
8162             return KEY_s;
8163           }
8164
8165         case 'x':
8166           {                                       /* x          */
8167             return -KEY_x;
8168           }
8169
8170         case 'y':
8171           {                                       /* y          */
8172             return KEY_y;
8173           }
8174
8175         default:
8176           goto unknown;
8177       }
8178
8179     case 2: /* 18 tokens of length 2 */
8180       switch (name[0])
8181       {
8182         case 'd':
8183           if (name[1] == 'o')
8184           {                                       /* do         */
8185             return KEY_do;
8186           }
8187
8188           goto unknown;
8189
8190         case 'e':
8191           if (name[1] == 'q')
8192           {                                       /* eq         */
8193             return -KEY_eq;
8194           }
8195
8196           goto unknown;
8197
8198         case 'g':
8199           switch (name[1])
8200           {
8201             case 'e':
8202               {                                   /* ge         */
8203                 return -KEY_ge;
8204               }
8205
8206             case 't':
8207               {                                   /* gt         */
8208                 return -KEY_gt;
8209               }
8210
8211             default:
8212               goto unknown;
8213           }
8214
8215         case 'i':
8216           if (name[1] == 'f')
8217           {                                       /* if         */
8218             return KEY_if;
8219           }
8220
8221           goto unknown;
8222
8223         case 'l':
8224           switch (name[1])
8225           {
8226             case 'c':
8227               {                                   /* lc         */
8228                 return -KEY_lc;
8229               }
8230
8231             case 'e':
8232               {                                   /* le         */
8233                 return -KEY_le;
8234               }
8235
8236             case 't':
8237               {                                   /* lt         */
8238                 return -KEY_lt;
8239               }
8240
8241             default:
8242               goto unknown;
8243           }
8244
8245         case 'm':
8246           if (name[1] == 'y')
8247           {                                       /* my         */
8248             return KEY_my;
8249           }
8250
8251           goto unknown;
8252
8253         case 'n':
8254           switch (name[1])
8255           {
8256             case 'e':
8257               {                                   /* ne         */
8258                 return -KEY_ne;
8259               }
8260
8261             case 'o':
8262               {                                   /* no         */
8263                 return KEY_no;
8264               }
8265
8266             default:
8267               goto unknown;
8268           }
8269
8270         case 'o':
8271           if (name[1] == 'r')
8272           {                                       /* or         */
8273             return -KEY_or;
8274           }
8275
8276           goto unknown;
8277
8278         case 'q':
8279           switch (name[1])
8280           {
8281             case 'q':
8282               {                                   /* qq         */
8283                 return KEY_qq;
8284               }
8285
8286             case 'r':
8287               {                                   /* qr         */
8288                 return KEY_qr;
8289               }
8290
8291             case 'w':
8292               {                                   /* qw         */
8293                 return KEY_qw;
8294               }
8295
8296             case 'x':
8297               {                                   /* qx         */
8298                 return KEY_qx;
8299               }
8300
8301             default:
8302               goto unknown;
8303           }
8304
8305         case 't':
8306           if (name[1] == 'r')
8307           {                                       /* tr         */
8308             return KEY_tr;
8309           }
8310
8311           goto unknown;
8312
8313         case 'u':
8314           if (name[1] == 'c')
8315           {                                       /* uc         */
8316             return -KEY_uc;
8317           }
8318
8319           goto unknown;
8320
8321         default:
8322           goto unknown;
8323       }
8324
8325     case 3: /* 29 tokens of length 3 */
8326       switch (name[0])
8327       {
8328         case 'E':
8329           if (name[1] == 'N' &&
8330               name[2] == 'D')
8331           {                                       /* END        */
8332             return KEY_END;
8333           }
8334
8335           goto unknown;
8336
8337         case 'a':
8338           switch (name[1])
8339           {
8340             case 'b':
8341               if (name[2] == 's')
8342               {                                   /* abs        */
8343                 return -KEY_abs;
8344               }
8345
8346               goto unknown;
8347
8348             case 'n':
8349               if (name[2] == 'd')
8350               {                                   /* and        */
8351                 return -KEY_and;
8352               }
8353
8354               goto unknown;
8355
8356             default:
8357               goto unknown;
8358           }
8359
8360         case 'c':
8361           switch (name[1])
8362           {
8363             case 'h':
8364               if (name[2] == 'r')
8365               {                                   /* chr        */
8366                 return -KEY_chr;
8367               }
8368
8369               goto unknown;
8370
8371             case 'm':
8372               if (name[2] == 'p')
8373               {                                   /* cmp        */
8374                 return -KEY_cmp;
8375               }
8376
8377               goto unknown;
8378
8379             case 'o':
8380               if (name[2] == 's')
8381               {                                   /* cos        */
8382                 return -KEY_cos;
8383               }
8384
8385               goto unknown;
8386
8387             default:
8388               goto unknown;
8389           }
8390
8391         case 'd':
8392           if (name[1] == 'i' &&
8393               name[2] == 'e')
8394           {                                       /* die        */
8395             return -KEY_die;
8396           }
8397
8398           goto unknown;
8399
8400         case 'e':
8401           switch (name[1])
8402           {
8403             case 'o':
8404               if (name[2] == 'f')
8405               {                                   /* eof        */
8406                 return -KEY_eof;
8407               }
8408
8409               goto unknown;
8410
8411             case 'x':
8412               if (name[2] == 'p')
8413               {                                   /* exp        */
8414                 return -KEY_exp;
8415               }
8416
8417               goto unknown;
8418
8419             default:
8420               goto unknown;
8421           }
8422
8423         case 'f':
8424           if (name[1] == 'o' &&
8425               name[2] == 'r')
8426           {                                       /* for        */
8427             return KEY_for;
8428           }
8429
8430           goto unknown;
8431
8432         case 'h':
8433           if (name[1] == 'e' &&
8434               name[2] == 'x')
8435           {                                       /* hex        */
8436             return -KEY_hex;
8437           }
8438
8439           goto unknown;
8440
8441         case 'i':
8442           if (name[1] == 'n' &&
8443               name[2] == 't')
8444           {                                       /* int        */
8445             return -KEY_int;
8446           }
8447
8448           goto unknown;
8449
8450         case 'l':
8451           if (name[1] == 'o' &&
8452               name[2] == 'g')
8453           {                                       /* log        */
8454             return -KEY_log;
8455           }
8456
8457           goto unknown;
8458
8459         case 'm':
8460           if (name[1] == 'a' &&
8461               name[2] == 'p')
8462           {                                       /* map        */
8463             return KEY_map;
8464           }
8465
8466           goto unknown;
8467
8468         case 'n':
8469           if (name[1] == 'o' &&
8470               name[2] == 't')
8471           {                                       /* not        */
8472             return -KEY_not;
8473           }
8474
8475           goto unknown;
8476
8477         case 'o':
8478           switch (name[1])
8479           {
8480             case 'c':
8481               if (name[2] == 't')
8482               {                                   /* oct        */
8483                 return -KEY_oct;
8484               }
8485
8486               goto unknown;
8487
8488             case 'r':
8489               if (name[2] == 'd')
8490               {                                   /* ord        */
8491                 return -KEY_ord;
8492               }
8493
8494               goto unknown;
8495
8496             case 'u':
8497               if (name[2] == 'r')
8498               {                                   /* our        */
8499                 return KEY_our;
8500               }
8501
8502               goto unknown;
8503
8504             default:
8505               goto unknown;
8506           }
8507
8508         case 'p':
8509           if (name[1] == 'o')
8510           {
8511             switch (name[2])
8512             {
8513               case 'p':
8514                 {                                 /* pop        */
8515                   return -KEY_pop;
8516                 }
8517
8518               case 's':
8519                 {                                 /* pos        */
8520                   return KEY_pos;
8521                 }
8522
8523               default:
8524                 goto unknown;
8525             }
8526           }
8527
8528           goto unknown;
8529
8530         case 'r':
8531           if (name[1] == 'e' &&
8532               name[2] == 'f')
8533           {                                       /* ref        */
8534             return -KEY_ref;
8535           }
8536
8537           goto unknown;
8538
8539         case 's':
8540           switch (name[1])
8541           {
8542             case 'a':
8543               if (name[2] == 'y')
8544               {                                   /* say        */
8545                 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
8546               }
8547
8548               goto unknown;
8549
8550             case 'i':
8551               if (name[2] == 'n')
8552               {                                   /* sin        */
8553                 return -KEY_sin;
8554               }
8555
8556               goto unknown;
8557
8558             case 'u':
8559               if (name[2] == 'b')
8560               {                                   /* sub        */
8561                 return KEY_sub;
8562               }
8563
8564               goto unknown;
8565
8566             default:
8567               goto unknown;
8568           }
8569
8570         case 't':
8571           if (name[1] == 'i' &&
8572               name[2] == 'e')
8573           {                                       /* tie        */
8574             return -KEY_tie;
8575           }
8576
8577           goto unknown;
8578
8579         case 'u':
8580           if (name[1] == 's' &&
8581               name[2] == 'e')
8582           {                                       /* use        */
8583             return KEY_use;
8584           }
8585
8586           goto unknown;
8587
8588         case 'v':
8589           if (name[1] == 'e' &&
8590               name[2] == 'c')
8591           {                                       /* vec        */
8592             return -KEY_vec;
8593           }
8594
8595           goto unknown;
8596
8597         case 'x':
8598           if (name[1] == 'o' &&
8599               name[2] == 'r')
8600           {                                       /* xor        */
8601             return -KEY_xor;
8602           }
8603
8604           goto unknown;
8605
8606         default:
8607           goto unknown;
8608       }
8609
8610     case 4: /* 41 tokens of length 4 */
8611       switch (name[0])
8612       {
8613         case 'C':
8614           if (name[1] == 'O' &&
8615               name[2] == 'R' &&
8616               name[3] == 'E')
8617           {                                       /* CORE       */
8618             return -KEY_CORE;
8619           }
8620
8621           goto unknown;
8622
8623         case 'I':
8624           if (name[1] == 'N' &&
8625               name[2] == 'I' &&
8626               name[3] == 'T')
8627           {                                       /* INIT       */
8628             return KEY_INIT;
8629           }
8630
8631           goto unknown;
8632
8633         case 'b':
8634           if (name[1] == 'i' &&
8635               name[2] == 'n' &&
8636               name[3] == 'd')
8637           {                                       /* bind       */
8638             return -KEY_bind;
8639           }
8640
8641           goto unknown;
8642
8643         case 'c':
8644           if (name[1] == 'h' &&
8645               name[2] == 'o' &&
8646               name[3] == 'p')
8647           {                                       /* chop       */
8648             return -KEY_chop;
8649           }
8650
8651           goto unknown;
8652
8653         case 'd':
8654           if (name[1] == 'u' &&
8655               name[2] == 'm' &&
8656               name[3] == 'p')
8657           {                                       /* dump       */
8658             return -KEY_dump;
8659           }
8660
8661           goto unknown;
8662
8663         case 'e':
8664           switch (name[1])
8665           {
8666             case 'a':
8667               if (name[2] == 'c' &&
8668                   name[3] == 'h')
8669               {                                   /* each       */
8670                 return -KEY_each;
8671               }
8672
8673               goto unknown;
8674
8675             case 'l':
8676               if (name[2] == 's' &&
8677                   name[3] == 'e')
8678               {                                   /* else       */
8679                 return KEY_else;
8680               }
8681
8682               goto unknown;
8683
8684             case 'v':
8685               if (name[2] == 'a' &&
8686                   name[3] == 'l')
8687               {                                   /* eval       */
8688                 return KEY_eval;
8689               }
8690
8691               goto unknown;
8692
8693             case 'x':
8694               switch (name[2])
8695               {
8696                 case 'e':
8697                   if (name[3] == 'c')
8698                   {                               /* exec       */
8699                     return -KEY_exec;
8700                   }
8701
8702                   goto unknown;
8703
8704                 case 'i':
8705                   if (name[3] == 't')
8706                   {                               /* exit       */
8707                     return -KEY_exit;
8708                   }
8709
8710                   goto unknown;
8711
8712                 default:
8713                   goto unknown;
8714               }
8715
8716             default:
8717               goto unknown;
8718           }
8719
8720         case 'f':
8721           if (name[1] == 'o' &&
8722               name[2] == 'r' &&
8723               name[3] == 'k')
8724           {                                       /* fork       */
8725             return -KEY_fork;
8726           }
8727
8728           goto unknown;
8729
8730         case 'g':
8731           switch (name[1])
8732           {
8733             case 'e':
8734               if (name[2] == 't' &&
8735                   name[3] == 'c')
8736               {                                   /* getc       */
8737                 return -KEY_getc;
8738               }
8739
8740               goto unknown;
8741
8742             case 'l':
8743               if (name[2] == 'o' &&
8744                   name[3] == 'b')
8745               {                                   /* glob       */
8746                 return KEY_glob;
8747               }
8748
8749               goto unknown;
8750
8751             case 'o':
8752               if (name[2] == 't' &&
8753                   name[3] == 'o')
8754               {                                   /* goto       */
8755                 return KEY_goto;
8756               }
8757
8758               goto unknown;
8759
8760             case 'r':
8761               if (name[2] == 'e' &&
8762                   name[3] == 'p')
8763               {                                   /* grep       */
8764                 return KEY_grep;
8765               }
8766
8767               goto unknown;
8768
8769             default:
8770               goto unknown;
8771           }
8772
8773         case 'j':
8774           if (name[1] == 'o' &&
8775               name[2] == 'i' &&
8776               name[3] == 'n')
8777           {                                       /* join       */
8778             return -KEY_join;
8779           }
8780
8781           goto unknown;
8782
8783         case 'k':
8784           switch (name[1])
8785           {
8786             case 'e':
8787               if (name[2] == 'y' &&
8788                   name[3] == 's')
8789               {                                   /* keys       */
8790                 return -KEY_keys;
8791               }
8792
8793               goto unknown;
8794
8795             case 'i':
8796               if (name[2] == 'l' &&
8797                   name[3] == 'l')
8798               {                                   /* kill       */
8799                 return -KEY_kill;
8800               }
8801
8802               goto unknown;
8803
8804             default:
8805               goto unknown;
8806           }
8807
8808         case 'l':
8809           switch (name[1])
8810           {
8811             case 'a':
8812               if (name[2] == 's' &&
8813                   name[3] == 't')
8814               {                                   /* last       */
8815                 return KEY_last;
8816               }
8817
8818               goto unknown;
8819
8820             case 'i':
8821               if (name[2] == 'n' &&
8822                   name[3] == 'k')
8823               {                                   /* link       */
8824                 return -KEY_link;
8825               }
8826
8827               goto unknown;
8828
8829             case 'o':
8830               if (name[2] == 'c' &&
8831                   name[3] == 'k')
8832               {                                   /* lock       */
8833                 return -KEY_lock;
8834               }
8835
8836               goto unknown;
8837
8838             default:
8839               goto unknown;
8840           }
8841
8842         case 'n':
8843           if (name[1] == 'e' &&
8844               name[2] == 'x' &&
8845               name[3] == 't')
8846           {                                       /* next       */
8847             return KEY_next;
8848           }
8849
8850           goto unknown;
8851
8852         case 'o':
8853           if (name[1] == 'p' &&
8854               name[2] == 'e' &&
8855               name[3] == 'n')
8856           {                                       /* open       */
8857             return -KEY_open;
8858           }
8859
8860           goto unknown;
8861
8862         case 'p':
8863           switch (name[1])
8864           {
8865             case 'a':
8866               if (name[2] == 'c' &&
8867                   name[3] == 'k')
8868               {                                   /* pack       */
8869                 return -KEY_pack;
8870               }
8871
8872               goto unknown;
8873
8874             case 'i':
8875               if (name[2] == 'p' &&
8876                   name[3] == 'e')
8877               {                                   /* pipe       */
8878                 return -KEY_pipe;
8879               }
8880
8881               goto unknown;
8882
8883             case 'u':
8884               if (name[2] == 's' &&
8885                   name[3] == 'h')
8886               {                                   /* push       */
8887                 return -KEY_push;
8888               }
8889
8890               goto unknown;
8891
8892             default:
8893               goto unknown;
8894           }
8895
8896         case 'r':
8897           switch (name[1])
8898           {
8899             case 'a':
8900               if (name[2] == 'n' &&
8901                   name[3] == 'd')
8902               {                                   /* rand       */
8903                 return -KEY_rand;
8904               }
8905
8906               goto unknown;
8907
8908             case 'e':
8909               switch (name[2])
8910               {
8911                 case 'a':
8912                   if (name[3] == 'd')
8913                   {                               /* read       */
8914                     return -KEY_read;
8915                   }
8916
8917                   goto unknown;
8918
8919                 case 'c':
8920                   if (name[3] == 'v')
8921                   {                               /* recv       */
8922                     return -KEY_recv;
8923                   }
8924
8925                   goto unknown;
8926
8927                 case 'd':
8928                   if (name[3] == 'o')
8929                   {                               /* redo       */
8930                     return KEY_redo;
8931                   }
8932
8933                   goto unknown;
8934
8935                 default:
8936                   goto unknown;
8937               }
8938
8939             default:
8940               goto unknown;
8941           }
8942
8943         case 's':
8944           switch (name[1])
8945           {
8946             case 'e':
8947               switch (name[2])
8948               {
8949                 case 'e':
8950                   if (name[3] == 'k')
8951                   {                               /* seek       */
8952                     return -KEY_seek;
8953                   }
8954
8955                   goto unknown;
8956
8957                 case 'n':
8958                   if (name[3] == 'd')
8959                   {                               /* send       */
8960                     return -KEY_send;
8961                   }
8962
8963                   goto unknown;
8964
8965                 default:
8966                   goto unknown;
8967               }
8968
8969             case 'o':
8970               if (name[2] == 'r' &&
8971                   name[3] == 't')
8972               {                                   /* sort       */
8973                 return KEY_sort;
8974               }
8975
8976               goto unknown;
8977
8978             case 'q':
8979               if (name[2] == 'r' &&
8980                   name[3] == 't')
8981               {                                   /* sqrt       */
8982                 return -KEY_sqrt;
8983               }
8984
8985               goto unknown;
8986
8987             case 't':
8988               if (name[2] == 'a' &&
8989                   name[3] == 't')
8990               {                                   /* stat       */
8991                 return -KEY_stat;
8992               }
8993
8994               goto unknown;
8995
8996             default:
8997               goto unknown;
8998           }
8999
9000         case 't':
9001           switch (name[1])
9002           {
9003             case 'e':
9004               if (name[2] == 'l' &&
9005                   name[3] == 'l')
9006               {                                   /* tell       */
9007                 return -KEY_tell;
9008               }
9009
9010               goto unknown;
9011
9012             case 'i':
9013               switch (name[2])
9014               {
9015                 case 'e':
9016                   if (name[3] == 'd')
9017                   {                               /* tied       */
9018                     return -KEY_tied;
9019                   }
9020
9021                   goto unknown;
9022
9023                 case 'm':
9024                   if (name[3] == 'e')
9025                   {                               /* time       */
9026                     return -KEY_time;
9027                   }
9028
9029                   goto unknown;
9030
9031                 default:
9032                   goto unknown;
9033               }
9034
9035             default:
9036               goto unknown;
9037           }
9038
9039         case 'w':
9040           switch (name[1])
9041           {
9042             case 'a':
9043               switch (name[2])
9044               {
9045                 case 'i':
9046                   if (name[3] == 't')
9047                   {                               /* wait       */
9048                     return -KEY_wait;
9049                   }
9050
9051                   goto unknown;
9052
9053                 case 'r':
9054                   if (name[3] == 'n')
9055                   {                               /* warn       */
9056                     return -KEY_warn;
9057                   }
9058
9059                   goto unknown;
9060
9061                 default:
9062                   goto unknown;
9063               }
9064
9065             case 'h':
9066               if (name[2] == 'e' &&
9067                   name[3] == 'n')
9068               {                                   /* when       */
9069                 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
9070               }
9071
9072               goto unknown;
9073
9074             default:
9075               goto unknown;
9076           }
9077
9078         default:
9079           goto unknown;
9080       }
9081
9082     case 5: /* 39 tokens of length 5 */
9083       switch (name[0])
9084       {
9085         case 'B':
9086           if (name[1] == 'E' &&
9087               name[2] == 'G' &&
9088               name[3] == 'I' &&
9089               name[4] == 'N')
9090           {                                       /* BEGIN      */
9091             return KEY_BEGIN;
9092           }
9093
9094           goto unknown;
9095
9096         case 'C':
9097           if (name[1] == 'H' &&
9098               name[2] == 'E' &&
9099               name[3] == 'C' &&
9100               name[4] == 'K')
9101           {                                       /* CHECK      */
9102             return KEY_CHECK;
9103           }
9104
9105           goto unknown;
9106
9107         case 'a':
9108           switch (name[1])
9109           {
9110             case 'l':
9111               if (name[2] == 'a' &&
9112                   name[3] == 'r' &&
9113                   name[4] == 'm')
9114               {                                   /* alarm      */
9115                 return -KEY_alarm;
9116               }
9117
9118               goto unknown;
9119
9120             case 't':
9121               if (name[2] == 'a' &&
9122                   name[3] == 'n' &&
9123                   name[4] == '2')
9124               {                                   /* atan2      */
9125                 return -KEY_atan2;
9126               }
9127
9128               goto unknown;
9129
9130             default:
9131               goto unknown;
9132           }
9133
9134         case 'b':
9135           switch (name[1])
9136           {
9137             case 'l':
9138               if (name[2] == 'e' &&
9139                   name[3] == 's' &&
9140                   name[4] == 's')
9141               {                                   /* bless      */
9142                 return -KEY_bless;
9143               }
9144
9145               goto unknown;
9146
9147             case 'r':
9148               if (name[2] == 'e' &&
9149                   name[3] == 'a' &&
9150                   name[4] == 'k')
9151               {                                   /* break      */
9152                 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
9153               }
9154
9155               goto unknown;
9156
9157             default:
9158               goto unknown;
9159           }
9160
9161         case 'c':
9162           switch (name[1])
9163           {
9164             case 'h':
9165               switch (name[2])
9166               {
9167                 case 'd':
9168                   if (name[3] == 'i' &&
9169                       name[4] == 'r')
9170                   {                               /* chdir      */
9171                     return -KEY_chdir;
9172                   }
9173
9174                   goto unknown;
9175
9176                 case 'm':
9177                   if (name[3] == 'o' &&
9178                       name[4] == 'd')
9179                   {                               /* chmod      */
9180                     return -KEY_chmod;
9181                   }
9182
9183                   goto unknown;
9184
9185                 case 'o':
9186                   switch (name[3])
9187                   {
9188                     case 'm':
9189                       if (name[4] == 'p')
9190                       {                           /* chomp      */
9191                         return -KEY_chomp;
9192                       }
9193
9194                       goto unknown;
9195
9196                     case 'w':
9197                       if (name[4] == 'n')
9198                       {                           /* chown      */
9199                         return -KEY_chown;
9200                       }
9201
9202                       goto unknown;
9203
9204                     default:
9205                       goto unknown;
9206                   }
9207
9208                 default:
9209                   goto unknown;
9210               }
9211
9212             case 'l':
9213               if (name[2] == 'o' &&
9214                   name[3] == 's' &&
9215                   name[4] == 'e')
9216               {                                   /* close      */
9217                 return -KEY_close;
9218               }
9219
9220               goto unknown;
9221
9222             case 'r':
9223               if (name[2] == 'y' &&
9224                   name[3] == 'p' &&
9225                   name[4] == 't')
9226               {                                   /* crypt      */
9227                 return -KEY_crypt;
9228               }
9229
9230               goto unknown;
9231
9232             default:
9233               goto unknown;
9234           }
9235
9236         case 'e':
9237           if (name[1] == 'l' &&
9238               name[2] == 's' &&
9239               name[3] == 'i' &&
9240               name[4] == 'f')
9241           {                                       /* elsif      */
9242             return KEY_elsif;
9243           }
9244
9245           goto unknown;
9246
9247         case 'f':
9248           switch (name[1])
9249           {
9250             case 'c':
9251               if (name[2] == 'n' &&
9252                   name[3] == 't' &&
9253                   name[4] == 'l')
9254               {                                   /* fcntl      */
9255                 return -KEY_fcntl;
9256               }
9257
9258               goto unknown;
9259
9260             case 'l':
9261               if (name[2] == 'o' &&
9262                   name[3] == 'c' &&
9263                   name[4] == 'k')
9264               {                                   /* flock      */
9265                 return -KEY_flock;
9266               }
9267
9268               goto unknown;
9269
9270             default:
9271               goto unknown;
9272           }
9273
9274         case 'g':
9275           if (name[1] == 'i' &&
9276               name[2] == 'v' &&
9277               name[3] == 'e' &&
9278               name[4] == 'n')
9279           {                                       /* given      */
9280             return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
9281           }
9282
9283           goto unknown;
9284
9285         case 'i':
9286           switch (name[1])
9287           {
9288             case 'n':
9289               if (name[2] == 'd' &&
9290                   name[3] == 'e' &&
9291                   name[4] == 'x')
9292               {                                   /* index      */
9293                 return -KEY_index;
9294               }
9295
9296               goto unknown;
9297
9298             case 'o':
9299               if (name[2] == 'c' &&
9300                   name[3] == 't' &&
9301                   name[4] == 'l')
9302               {                                   /* ioctl      */
9303                 return -KEY_ioctl;
9304               }
9305
9306               goto unknown;
9307
9308             default:
9309               goto unknown;
9310           }
9311
9312         case 'l':
9313           switch (name[1])
9314           {
9315             case 'o':
9316               if (name[2] == 'c' &&
9317                   name[3] == 'a' &&
9318                   name[4] == 'l')
9319               {                                   /* local      */
9320                 return KEY_local;
9321               }
9322
9323               goto unknown;
9324
9325             case 's':
9326               if (name[2] == 't' &&
9327                   name[3] == 'a' &&
9328                   name[4] == 't')
9329               {                                   /* lstat      */
9330                 return -KEY_lstat;
9331               }
9332
9333               goto unknown;
9334
9335             default:
9336               goto unknown;
9337           }
9338
9339         case 'm':
9340           if (name[1] == 'k' &&
9341               name[2] == 'd' &&
9342               name[3] == 'i' &&
9343               name[4] == 'r')
9344           {                                       /* mkdir      */
9345             return -KEY_mkdir;
9346           }
9347
9348           goto unknown;
9349
9350         case 'p':
9351           if (name[1] == 'r' &&
9352               name[2] == 'i' &&
9353               name[3] == 'n' &&
9354               name[4] == 't')
9355           {                                       /* print      */
9356             return KEY_print;
9357           }
9358
9359           goto unknown;
9360
9361         case 'r':
9362           switch (name[1])
9363           {
9364             case 'e':
9365               if (name[2] == 's' &&
9366                   name[3] == 'e' &&
9367                   name[4] == 't')
9368               {                                   /* reset      */
9369                 return -KEY_reset;
9370               }
9371
9372               goto unknown;
9373
9374             case 'm':
9375               if (name[2] == 'd' &&
9376                   name[3] == 'i' &&
9377                   name[4] == 'r')
9378               {                                   /* rmdir      */
9379                 return -KEY_rmdir;
9380               }
9381
9382               goto unknown;
9383
9384             default:
9385               goto unknown;
9386           }
9387
9388         case 's':
9389           switch (name[1])
9390           {
9391             case 'e':
9392               if (name[2] == 'm' &&
9393                   name[3] == 'o' &&
9394                   name[4] == 'p')
9395               {                                   /* semop      */
9396                 return -KEY_semop;
9397               }
9398
9399               goto unknown;
9400
9401             case 'h':
9402               if (name[2] == 'i' &&
9403                   name[3] == 'f' &&
9404                   name[4] == 't')
9405               {                                   /* shift      */
9406                 return -KEY_shift;
9407               }
9408
9409               goto unknown;
9410
9411             case 'l':
9412               if (name[2] == 'e' &&
9413                   name[3] == 'e' &&
9414                   name[4] == 'p')
9415               {                                   /* sleep      */
9416                 return -KEY_sleep;
9417               }
9418
9419               goto unknown;
9420
9421             case 'p':
9422               if (name[2] == 'l' &&
9423                   name[3] == 'i' &&
9424                   name[4] == 't')
9425               {                                   /* split      */
9426                 return KEY_split;
9427               }
9428
9429               goto unknown;
9430
9431             case 'r':
9432               if (name[2] == 'a' &&
9433                   name[3] == 'n' &&
9434                   name[4] == 'd')
9435               {                                   /* srand      */
9436                 return -KEY_srand;
9437               }
9438
9439               goto unknown;
9440
9441             case 't':
9442               switch (name[2])
9443               {
9444                 case 'a':
9445                   if (name[3] == 't' &&
9446                       name[4] == 'e')
9447                   {                               /* state      */
9448                     return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
9449                   }
9450
9451                   goto unknown;
9452
9453                 case 'u':
9454                   if (name[3] == 'd' &&
9455                       name[4] == 'y')
9456                   {                               /* study      */
9457                     return KEY_study;
9458                   }
9459
9460                   goto unknown;
9461
9462                 default:
9463                   goto unknown;
9464               }
9465
9466             default:
9467               goto unknown;
9468           }
9469
9470         case 't':
9471           if (name[1] == 'i' &&
9472               name[2] == 'm' &&
9473               name[3] == 'e' &&
9474               name[4] == 's')
9475           {                                       /* times      */
9476             return -KEY_times;
9477           }
9478
9479           goto unknown;
9480
9481         case 'u':
9482           switch (name[1])
9483           {
9484             case 'm':
9485               if (name[2] == 'a' &&
9486                   name[3] == 's' &&
9487                   name[4] == 'k')
9488               {                                   /* umask      */
9489                 return -KEY_umask;
9490               }
9491
9492               goto unknown;
9493
9494             case 'n':
9495               switch (name[2])
9496               {
9497                 case 'd':
9498                   if (name[3] == 'e' &&
9499                       name[4] == 'f')
9500                   {                               /* undef      */
9501                     return KEY_undef;
9502                   }
9503
9504                   goto unknown;
9505
9506                 case 't':
9507                   if (name[3] == 'i')
9508                   {
9509                     switch (name[4])
9510                     {
9511                       case 'e':
9512                         {                         /* untie      */
9513                           return -KEY_untie;
9514                         }
9515
9516                       case 'l':
9517                         {                         /* until      */
9518                           return KEY_until;
9519                         }
9520
9521                       default:
9522                         goto unknown;
9523                     }
9524                   }
9525
9526                   goto unknown;
9527
9528                 default:
9529                   goto unknown;
9530               }
9531
9532             case 't':
9533               if (name[2] == 'i' &&
9534                   name[3] == 'm' &&
9535                   name[4] == 'e')
9536               {                                   /* utime      */
9537                 return -KEY_utime;
9538               }
9539
9540               goto unknown;
9541
9542             default:
9543               goto unknown;
9544           }
9545
9546         case 'w':
9547           switch (name[1])
9548           {
9549             case 'h':
9550               if (name[2] == 'i' &&
9551                   name[3] == 'l' &&
9552                   name[4] == 'e')
9553               {                                   /* while      */
9554                 return KEY_while;
9555               }
9556
9557               goto unknown;
9558
9559             case 'r':
9560               if (name[2] == 'i' &&
9561                   name[3] == 't' &&
9562                   name[4] == 'e')
9563               {                                   /* write      */
9564                 return -KEY_write;
9565               }
9566
9567               goto unknown;
9568
9569             default:
9570               goto unknown;
9571           }
9572
9573         default:
9574           goto unknown;
9575       }
9576
9577     case 6: /* 33 tokens of length 6 */
9578       switch (name[0])
9579       {
9580         case 'a':
9581           if (name[1] == 'c' &&
9582               name[2] == 'c' &&
9583               name[3] == 'e' &&
9584               name[4] == 'p' &&
9585               name[5] == 't')
9586           {                                       /* accept     */
9587             return -KEY_accept;
9588           }
9589
9590           goto unknown;
9591
9592         case 'c':
9593           switch (name[1])
9594           {
9595             case 'a':
9596               if (name[2] == 'l' &&
9597                   name[3] == 'l' &&
9598                   name[4] == 'e' &&
9599                   name[5] == 'r')
9600               {                                   /* caller     */
9601                 return -KEY_caller;
9602               }
9603
9604               goto unknown;
9605
9606             case 'h':
9607               if (name[2] == 'r' &&
9608                   name[3] == 'o' &&
9609                   name[4] == 'o' &&
9610                   name[5] == 't')
9611               {                                   /* chroot     */
9612                 return -KEY_chroot;
9613               }
9614
9615               goto unknown;
9616
9617             default:
9618               goto unknown;
9619           }
9620
9621         case 'd':
9622           if (name[1] == 'e' &&
9623               name[2] == 'l' &&
9624               name[3] == 'e' &&
9625               name[4] == 't' &&
9626               name[5] == 'e')
9627           {                                       /* delete     */
9628             return KEY_delete;
9629           }
9630
9631           goto unknown;
9632
9633         case 'e':
9634           switch (name[1])
9635           {
9636             case 'l':
9637               if (name[2] == 's' &&
9638                   name[3] == 'e' &&
9639                   name[4] == 'i' &&
9640                   name[5] == 'f')
9641               {                                   /* elseif     */
9642                   Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
9643               }
9644
9645               goto unknown;
9646
9647             case 'x':
9648               if (name[2] == 'i' &&
9649                   name[3] == 's' &&
9650                   name[4] == 't' &&
9651                   name[5] == 's')
9652               {                                   /* exists     */
9653                 return KEY_exists;
9654               }
9655
9656               goto unknown;
9657
9658             default:
9659               goto unknown;
9660           }
9661
9662         case 'f':
9663           switch (name[1])
9664           {
9665             case 'i':
9666               if (name[2] == 'l' &&
9667                   name[3] == 'e' &&
9668                   name[4] == 'n' &&
9669                   name[5] == 'o')
9670               {                                   /* fileno     */
9671                 return -KEY_fileno;
9672               }
9673
9674               goto unknown;
9675
9676             case 'o':
9677               if (name[2] == 'r' &&
9678                   name[3] == 'm' &&
9679                   name[4] == 'a' &&
9680                   name[5] == 't')
9681               {                                   /* format     */
9682                 return KEY_format;
9683               }
9684
9685               goto unknown;
9686
9687             default:
9688               goto unknown;
9689           }
9690
9691         case 'g':
9692           if (name[1] == 'm' &&
9693               name[2] == 't' &&
9694               name[3] == 'i' &&
9695               name[4] == 'm' &&
9696               name[5] == 'e')
9697           {                                       /* gmtime     */
9698             return -KEY_gmtime;
9699           }
9700
9701           goto unknown;
9702
9703         case 'l':
9704           switch (name[1])
9705           {
9706             case 'e':
9707               if (name[2] == 'n' &&
9708                   name[3] == 'g' &&
9709                   name[4] == 't' &&
9710                   name[5] == 'h')
9711               {                                   /* length     */
9712                 return -KEY_length;
9713               }
9714
9715               goto unknown;
9716
9717             case 'i':
9718               if (name[2] == 's' &&
9719                   name[3] == 't' &&
9720                   name[4] == 'e' &&
9721                   name[5] == 'n')
9722               {                                   /* listen     */
9723                 return -KEY_listen;
9724               }
9725
9726               goto unknown;
9727
9728             default:
9729               goto unknown;
9730           }
9731
9732         case 'm':
9733           if (name[1] == 's' &&
9734               name[2] == 'g')
9735           {
9736             switch (name[3])
9737             {
9738               case 'c':
9739                 if (name[4] == 't' &&
9740                     name[5] == 'l')
9741                 {                                 /* msgctl     */
9742                   return -KEY_msgctl;
9743                 }
9744
9745                 goto unknown;
9746
9747               case 'g':
9748                 if (name[4] == 'e' &&
9749                     name[5] == 't')
9750                 {                                 /* msgget     */
9751                   return -KEY_msgget;
9752                 }
9753
9754                 goto unknown;
9755
9756               case 'r':
9757                 if (name[4] == 'c' &&
9758                     name[5] == 'v')
9759                 {                                 /* msgrcv     */
9760                   return -KEY_msgrcv;
9761                 }
9762
9763                 goto unknown;
9764
9765               case 's':
9766                 if (name[4] == 'n' &&
9767                     name[5] == 'd')
9768                 {                                 /* msgsnd     */
9769                   return -KEY_msgsnd;
9770                 }
9771
9772                 goto unknown;
9773
9774               default:
9775                 goto unknown;
9776             }
9777           }
9778
9779           goto unknown;
9780
9781         case 'p':
9782           if (name[1] == 'r' &&
9783               name[2] == 'i' &&
9784               name[3] == 'n' &&
9785               name[4] == 't' &&
9786               name[5] == 'f')
9787           {                                       /* printf     */
9788             return KEY_printf;
9789           }
9790
9791           goto unknown;
9792
9793         case 'r':
9794           switch (name[1])
9795           {
9796             case 'e':
9797               switch (name[2])
9798               {
9799                 case 'n':
9800                   if (name[3] == 'a' &&
9801                       name[4] == 'm' &&
9802                       name[5] == 'e')
9803                   {                               /* rename     */
9804                     return -KEY_rename;
9805                   }
9806
9807                   goto unknown;
9808
9809                 case 't':
9810                   if (name[3] == 'u' &&
9811                       name[4] == 'r' &&
9812                       name[5] == 'n')
9813                   {                               /* return     */
9814                     return KEY_return;
9815                   }
9816
9817                   goto unknown;
9818
9819                 default:
9820                   goto unknown;
9821               }
9822
9823             case 'i':
9824               if (name[2] == 'n' &&
9825                   name[3] == 'd' &&
9826                   name[4] == 'e' &&
9827                   name[5] == 'x')
9828               {                                   /* rindex     */
9829                 return -KEY_rindex;
9830               }
9831
9832               goto unknown;
9833
9834             default:
9835               goto unknown;
9836           }
9837
9838         case 's':
9839           switch (name[1])
9840           {
9841             case 'c':
9842               if (name[2] == 'a' &&
9843                   name[3] == 'l' &&
9844                   name[4] == 'a' &&
9845                   name[5] == 'r')
9846               {                                   /* scalar     */
9847                 return KEY_scalar;
9848               }
9849
9850               goto unknown;
9851
9852             case 'e':
9853               switch (name[2])
9854               {
9855                 case 'l':
9856                   if (name[3] == 'e' &&
9857                       name[4] == 'c' &&
9858                       name[5] == 't')
9859                   {                               /* select     */
9860                     return -KEY_select;
9861                   }
9862
9863                   goto unknown;
9864
9865                 case 'm':
9866                   switch (name[3])
9867                   {
9868                     case 'c':
9869                       if (name[4] == 't' &&
9870                           name[5] == 'l')
9871                       {                           /* semctl     */
9872                         return -KEY_semctl;
9873                       }
9874
9875                       goto unknown;
9876
9877                     case 'g':
9878                       if (name[4] == 'e' &&
9879                           name[5] == 't')
9880                       {                           /* semget     */
9881                         return -KEY_semget;
9882                       }
9883
9884                       goto unknown;
9885
9886                     default:
9887                       goto unknown;
9888                   }
9889
9890                 default:
9891                   goto unknown;
9892               }
9893
9894             case 'h':
9895               if (name[2] == 'm')
9896               {
9897                 switch (name[3])
9898                 {
9899                   case 'c':
9900                     if (name[4] == 't' &&
9901                         name[5] == 'l')
9902                     {                             /* shmctl     */
9903                       return -KEY_shmctl;
9904                     }
9905
9906                     goto unknown;
9907
9908                   case 'g':
9909                     if (name[4] == 'e' &&
9910                         name[5] == 't')
9911                     {                             /* shmget     */
9912                       return -KEY_shmget;
9913                     }
9914
9915                     goto unknown;
9916
9917                   default:
9918                     goto unknown;
9919                 }
9920               }
9921
9922               goto unknown;
9923
9924             case 'o':
9925               if (name[2] == 'c' &&
9926                   name[3] == 'k' &&
9927                   name[4] == 'e' &&
9928                   name[5] == 't')
9929               {                                   /* socket     */
9930                 return -KEY_socket;
9931               }
9932
9933               goto unknown;
9934
9935             case 'p':
9936               if (name[2] == 'l' &&
9937                   name[3] == 'i' &&
9938                   name[4] == 'c' &&
9939                   name[5] == 'e')
9940               {                                   /* splice     */
9941                 return -KEY_splice;
9942               }
9943
9944               goto unknown;
9945
9946             case 'u':
9947               if (name[2] == 'b' &&
9948                   name[3] == 's' &&
9949                   name[4] == 't' &&
9950                   name[5] == 'r')
9951               {                                   /* substr     */
9952                 return -KEY_substr;
9953               }
9954
9955               goto unknown;
9956
9957             case 'y':
9958               if (name[2] == 's' &&
9959                   name[3] == 't' &&
9960                   name[4] == 'e' &&
9961                   name[5] == 'm')
9962               {                                   /* system     */
9963                 return -KEY_system;
9964               }
9965
9966               goto unknown;
9967
9968             default:
9969               goto unknown;
9970           }
9971
9972         case 'u':
9973           if (name[1] == 'n')
9974           {
9975             switch (name[2])
9976             {
9977               case 'l':
9978                 switch (name[3])
9979                 {
9980                   case 'e':
9981                     if (name[4] == 's' &&
9982                         name[5] == 's')
9983                     {                             /* unless     */
9984                       return KEY_unless;
9985                     }
9986
9987                     goto unknown;
9988
9989                   case 'i':
9990                     if (name[4] == 'n' &&
9991                         name[5] == 'k')
9992                     {                             /* unlink     */
9993                       return -KEY_unlink;
9994                     }
9995
9996                     goto unknown;
9997
9998                   default:
9999                     goto unknown;
10000                 }
10001
10002               case 'p':
10003                 if (name[3] == 'a' &&
10004                     name[4] == 'c' &&
10005                     name[5] == 'k')
10006                 {                                 /* unpack     */
10007                   return -KEY_unpack;
10008                 }
10009
10010                 goto unknown;
10011
10012               default:
10013                 goto unknown;
10014             }
10015           }
10016
10017           goto unknown;
10018
10019         case 'v':
10020           if (name[1] == 'a' &&
10021               name[2] == 'l' &&
10022               name[3] == 'u' &&
10023               name[4] == 'e' &&
10024               name[5] == 's')
10025           {                                       /* values     */
10026             return -KEY_values;
10027           }
10028
10029           goto unknown;
10030
10031         default:
10032           goto unknown;
10033       }
10034
10035     case 7: /* 29 tokens of length 7 */
10036       switch (name[0])
10037       {
10038         case 'D':
10039           if (name[1] == 'E' &&
10040               name[2] == 'S' &&
10041               name[3] == 'T' &&
10042               name[4] == 'R' &&
10043               name[5] == 'O' &&
10044               name[6] == 'Y')
10045           {                                       /* DESTROY    */
10046             return KEY_DESTROY;
10047           }
10048
10049           goto unknown;
10050
10051         case '_':
10052           if (name[1] == '_' &&
10053               name[2] == 'E' &&
10054               name[3] == 'N' &&
10055               name[4] == 'D' &&
10056               name[5] == '_' &&
10057               name[6] == '_')
10058           {                                       /* __END__    */
10059             return KEY___END__;
10060           }
10061
10062           goto unknown;
10063
10064         case 'b':
10065           if (name[1] == 'i' &&
10066               name[2] == 'n' &&
10067               name[3] == 'm' &&
10068               name[4] == 'o' &&
10069               name[5] == 'd' &&
10070               name[6] == 'e')
10071           {                                       /* binmode    */
10072             return -KEY_binmode;
10073           }
10074
10075           goto unknown;
10076
10077         case 'c':
10078           if (name[1] == 'o' &&
10079               name[2] == 'n' &&
10080               name[3] == 'n' &&
10081               name[4] == 'e' &&
10082               name[5] == 'c' &&
10083               name[6] == 't')
10084           {                                       /* connect    */
10085             return -KEY_connect;
10086           }
10087
10088           goto unknown;
10089
10090         case 'd':
10091           switch (name[1])
10092           {
10093             case 'b':
10094               if (name[2] == 'm' &&
10095                   name[3] == 'o' &&
10096                   name[4] == 'p' &&
10097                   name[5] == 'e' &&
10098                   name[6] == 'n')
10099               {                                   /* dbmopen    */
10100                 return -KEY_dbmopen;
10101               }
10102
10103               goto unknown;
10104
10105             case 'e':
10106               if (name[2] == 'f')
10107               {
10108                 switch (name[3])
10109                 {
10110                   case 'a':
10111                     if (name[4] == 'u' &&
10112                         name[5] == 'l' &&
10113                         name[6] == 't')
10114                     {                             /* default    */
10115                       return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
10116                     }
10117
10118                     goto unknown;
10119
10120                   case 'i':
10121                     if (name[4] == 'n' &&
10122                         name[5] == 'e' &&
10123                         name[6] == 'd')
10124                     {                             /* defined    */
10125                       return KEY_defined;
10126                     }
10127
10128                     goto unknown;
10129
10130                   default:
10131                     goto unknown;
10132                 }
10133               }
10134
10135               goto unknown;
10136
10137             default:
10138               goto unknown;
10139           }
10140
10141         case 'f':
10142           if (name[1] == 'o' &&
10143               name[2] == 'r' &&
10144               name[3] == 'e' &&
10145               name[4] == 'a' &&
10146               name[5] == 'c' &&
10147               name[6] == 'h')
10148           {                                       /* foreach    */
10149             return KEY_foreach;
10150           }
10151
10152           goto unknown;
10153
10154         case 'g':
10155           if (name[1] == 'e' &&
10156               name[2] == 't' &&
10157               name[3] == 'p')
10158           {
10159             switch (name[4])
10160             {
10161               case 'g':
10162                 if (name[5] == 'r' &&
10163                     name[6] == 'p')
10164                 {                                 /* getpgrp    */
10165                   return -KEY_getpgrp;
10166                 }
10167
10168                 goto unknown;
10169
10170               case 'p':
10171                 if (name[5] == 'i' &&
10172                     name[6] == 'd')
10173                 {                                 /* getppid    */
10174                   return -KEY_getppid;
10175                 }
10176
10177                 goto unknown;
10178
10179               default:
10180                 goto unknown;
10181             }
10182           }
10183
10184           goto unknown;
10185
10186         case 'l':
10187           if (name[1] == 'c' &&
10188               name[2] == 'f' &&
10189               name[3] == 'i' &&
10190               name[4] == 'r' &&
10191               name[5] == 's' &&
10192               name[6] == 't')
10193           {                                       /* lcfirst    */
10194             return -KEY_lcfirst;
10195           }
10196
10197           goto unknown;
10198
10199         case 'o':
10200           if (name[1] == 'p' &&
10201               name[2] == 'e' &&
10202               name[3] == 'n' &&
10203               name[4] == 'd' &&
10204               name[5] == 'i' &&
10205               name[6] == 'r')
10206           {                                       /* opendir    */
10207             return -KEY_opendir;
10208           }
10209
10210           goto unknown;
10211
10212         case 'p':
10213           if (name[1] == 'a' &&
10214               name[2] == 'c' &&
10215               name[3] == 'k' &&
10216               name[4] == 'a' &&
10217               name[5] == 'g' &&
10218               name[6] == 'e')
10219           {                                       /* package    */
10220             return KEY_package;
10221           }
10222
10223           goto unknown;
10224
10225         case 'r':
10226           if (name[1] == 'e')
10227           {
10228             switch (name[2])
10229             {
10230               case 'a':
10231                 if (name[3] == 'd' &&
10232                     name[4] == 'd' &&
10233                     name[5] == 'i' &&
10234                     name[6] == 'r')
10235                 {                                 /* readdir    */
10236                   return -KEY_readdir;
10237                 }
10238
10239                 goto unknown;
10240
10241               case 'q':
10242                 if (name[3] == 'u' &&
10243                     name[4] == 'i' &&
10244                     name[5] == 'r' &&
10245                     name[6] == 'e')
10246                 {                                 /* require    */
10247                   return KEY_require;
10248                 }
10249
10250                 goto unknown;
10251
10252               case 'v':
10253                 if (name[3] == 'e' &&
10254                     name[4] == 'r' &&
10255                     name[5] == 's' &&
10256                     name[6] == 'e')
10257                 {                                 /* reverse    */
10258                   return -KEY_reverse;
10259                 }
10260
10261                 goto unknown;
10262
10263               default:
10264                 goto unknown;
10265             }
10266           }
10267
10268           goto unknown;
10269
10270         case 's':
10271           switch (name[1])
10272           {
10273             case 'e':
10274               switch (name[2])
10275               {
10276                 case 'e':
10277                   if (name[3] == 'k' &&
10278                       name[4] == 'd' &&
10279                       name[5] == 'i' &&
10280                       name[6] == 'r')
10281                   {                               /* seekdir    */
10282                     return -KEY_seekdir;
10283                   }
10284
10285                   goto unknown;
10286
10287                 case 't':
10288                   if (name[3] == 'p' &&
10289                       name[4] == 'g' &&
10290                       name[5] == 'r' &&
10291                       name[6] == 'p')
10292                   {                               /* setpgrp    */
10293                     return -KEY_setpgrp;
10294                   }
10295
10296                   goto unknown;
10297
10298                 default:
10299                   goto unknown;
10300               }
10301
10302             case 'h':
10303               if (name[2] == 'm' &&
10304                   name[3] == 'r' &&
10305                   name[4] == 'e' &&
10306                   name[5] == 'a' &&
10307                   name[6] == 'd')
10308               {                                   /* shmread    */
10309                 return -KEY_shmread;
10310               }
10311
10312               goto unknown;
10313
10314             case 'p':
10315               if (name[2] == 'r' &&
10316                   name[3] == 'i' &&
10317                   name[4] == 'n' &&
10318                   name[5] == 't' &&
10319                   name[6] == 'f')
10320               {                                   /* sprintf    */
10321                 return -KEY_sprintf;
10322               }
10323
10324               goto unknown;
10325
10326             case 'y':
10327               switch (name[2])
10328               {
10329                 case 'm':
10330                   if (name[3] == 'l' &&
10331                       name[4] == 'i' &&
10332                       name[5] == 'n' &&
10333                       name[6] == 'k')
10334                   {                               /* symlink    */
10335                     return -KEY_symlink;
10336                   }
10337
10338                   goto unknown;
10339
10340                 case 's':
10341                   switch (name[3])
10342                   {
10343                     case 'c':
10344                       if (name[4] == 'a' &&
10345                           name[5] == 'l' &&
10346                           name[6] == 'l')
10347                       {                           /* syscall    */
10348                         return -KEY_syscall;
10349                       }
10350
10351                       goto unknown;
10352
10353                     case 'o':
10354                       if (name[4] == 'p' &&
10355                           name[5] == 'e' &&
10356                           name[6] == 'n')
10357                       {                           /* sysopen    */
10358                         return -KEY_sysopen;
10359                       }
10360
10361                       goto unknown;
10362
10363                     case 'r':
10364                       if (name[4] == 'e' &&
10365                           name[5] == 'a' &&
10366                           name[6] == 'd')
10367                       {                           /* sysread    */
10368                         return -KEY_sysread;
10369                       }
10370
10371                       goto unknown;
10372
10373                     case 's':
10374                       if (name[4] == 'e' &&
10375                           name[5] == 'e' &&
10376                           name[6] == 'k')
10377                       {                           /* sysseek    */
10378                         return -KEY_sysseek;
10379                       }
10380
10381                       goto unknown;
10382
10383                     default:
10384                       goto unknown;
10385                   }
10386
10387                 default:
10388                   goto unknown;
10389               }
10390
10391             default:
10392               goto unknown;
10393           }
10394
10395         case 't':
10396           if (name[1] == 'e' &&
10397               name[2] == 'l' &&
10398               name[3] == 'l' &&
10399               name[4] == 'd' &&
10400               name[5] == 'i' &&
10401               name[6] == 'r')
10402           {                                       /* telldir    */
10403             return -KEY_telldir;
10404           }
10405
10406           goto unknown;
10407
10408         case 'u':
10409           switch (name[1])
10410           {
10411             case 'c':
10412               if (name[2] == 'f' &&
10413                   name[3] == 'i' &&
10414                   name[4] == 'r' &&
10415                   name[5] == 's' &&
10416                   name[6] == 't')
10417               {                                   /* ucfirst    */
10418                 return -KEY_ucfirst;
10419               }
10420
10421               goto unknown;
10422
10423             case 'n':
10424               if (name[2] == 's' &&
10425                   name[3] == 'h' &&
10426                   name[4] == 'i' &&
10427                   name[5] == 'f' &&
10428                   name[6] == 't')
10429               {                                   /* unshift    */
10430                 return -KEY_unshift;
10431               }
10432
10433               goto unknown;
10434
10435             default:
10436               goto unknown;
10437           }
10438
10439         case 'w':
10440           if (name[1] == 'a' &&
10441               name[2] == 'i' &&
10442               name[3] == 't' &&
10443               name[4] == 'p' &&
10444               name[5] == 'i' &&
10445               name[6] == 'd')
10446           {                                       /* waitpid    */
10447             return -KEY_waitpid;
10448           }
10449
10450           goto unknown;
10451
10452         default:
10453           goto unknown;
10454       }
10455
10456     case 8: /* 26 tokens of length 8 */
10457       switch (name[0])
10458       {
10459         case 'A':
10460           if (name[1] == 'U' &&
10461               name[2] == 'T' &&
10462               name[3] == 'O' &&
10463               name[4] == 'L' &&
10464               name[5] == 'O' &&
10465               name[6] == 'A' &&
10466               name[7] == 'D')
10467           {                                       /* AUTOLOAD   */
10468             return KEY_AUTOLOAD;
10469           }
10470
10471           goto unknown;
10472
10473         case '_':
10474           if (name[1] == '_')
10475           {
10476             switch (name[2])
10477             {
10478               case 'D':
10479                 if (name[3] == 'A' &&
10480                     name[4] == 'T' &&
10481                     name[5] == 'A' &&
10482                     name[6] == '_' &&
10483                     name[7] == '_')
10484                 {                                 /* __DATA__   */
10485                   return KEY___DATA__;
10486                 }
10487
10488                 goto unknown;
10489
10490               case 'F':
10491                 if (name[3] == 'I' &&
10492                     name[4] == 'L' &&
10493                     name[5] == 'E' &&
10494                     name[6] == '_' &&
10495                     name[7] == '_')
10496                 {                                 /* __FILE__   */
10497                   return -KEY___FILE__;
10498                 }
10499
10500                 goto unknown;
10501
10502               case 'L':
10503                 if (name[3] == 'I' &&
10504                     name[4] == 'N' &&
10505                     name[5] == 'E' &&
10506                     name[6] == '_' &&
10507                     name[7] == '_')
10508                 {                                 /* __LINE__   */
10509                   return -KEY___LINE__;
10510                 }
10511
10512                 goto unknown;
10513
10514               default:
10515                 goto unknown;
10516             }
10517           }
10518
10519           goto unknown;
10520
10521         case 'c':
10522           switch (name[1])
10523           {
10524             case 'l':
10525               if (name[2] == 'o' &&
10526                   name[3] == 's' &&
10527                   name[4] == 'e' &&
10528                   name[5] == 'd' &&
10529                   name[6] == 'i' &&
10530                   name[7] == 'r')
10531               {                                   /* closedir   */
10532                 return -KEY_closedir;
10533               }
10534
10535               goto unknown;
10536
10537             case 'o':
10538               if (name[2] == 'n' &&
10539                   name[3] == 't' &&
10540                   name[4] == 'i' &&
10541                   name[5] == 'n' &&
10542                   name[6] == 'u' &&
10543                   name[7] == 'e')
10544               {                                   /* continue   */
10545                 return -KEY_continue;
10546               }
10547
10548               goto unknown;
10549
10550             default:
10551               goto unknown;
10552           }
10553
10554         case 'd':
10555           if (name[1] == 'b' &&
10556               name[2] == 'm' &&
10557               name[3] == 'c' &&
10558               name[4] == 'l' &&
10559               name[5] == 'o' &&
10560               name[6] == 's' &&
10561               name[7] == 'e')
10562           {                                       /* dbmclose   */
10563             return -KEY_dbmclose;
10564           }
10565
10566           goto unknown;
10567
10568         case 'e':
10569           if (name[1] == 'n' &&
10570               name[2] == 'd')
10571           {
10572             switch (name[3])
10573             {
10574               case 'g':
10575                 if (name[4] == 'r' &&
10576                     name[5] == 'e' &&
10577                     name[6] == 'n' &&
10578                     name[7] == 't')
10579                 {                                 /* endgrent   */
10580                   return -KEY_endgrent;
10581                 }
10582
10583                 goto unknown;
10584
10585               case 'p':
10586                 if (name[4] == 'w' &&
10587                     name[5] == 'e' &&
10588                     name[6] == 'n' &&
10589                     name[7] == 't')
10590                 {                                 /* endpwent   */
10591                   return -KEY_endpwent;
10592                 }
10593
10594                 goto unknown;
10595
10596               default:
10597                 goto unknown;
10598             }
10599           }
10600
10601           goto unknown;
10602
10603         case 'f':
10604           if (name[1] == 'o' &&
10605               name[2] == 'r' &&
10606               name[3] == 'm' &&
10607               name[4] == 'l' &&
10608               name[5] == 'i' &&
10609               name[6] == 'n' &&
10610               name[7] == 'e')
10611           {                                       /* formline   */
10612             return -KEY_formline;
10613           }
10614
10615           goto unknown;
10616
10617         case 'g':
10618           if (name[1] == 'e' &&
10619               name[2] == 't')
10620           {
10621             switch (name[3])
10622             {
10623               case 'g':
10624                 if (name[4] == 'r')
10625                 {
10626                   switch (name[5])
10627                   {
10628                     case 'e':
10629                       if (name[6] == 'n' &&
10630                           name[7] == 't')
10631                       {                           /* getgrent   */
10632                         return -KEY_getgrent;
10633                       }
10634
10635                       goto unknown;
10636
10637                     case 'g':
10638                       if (name[6] == 'i' &&
10639                           name[7] == 'd')
10640                       {                           /* getgrgid   */
10641                         return -KEY_getgrgid;
10642                       }
10643
10644                       goto unknown;
10645
10646                     case 'n':
10647                       if (name[6] == 'a' &&
10648                           name[7] == 'm')
10649                       {                           /* getgrnam   */
10650                         return -KEY_getgrnam;
10651                       }
10652
10653                       goto unknown;
10654
10655                     default:
10656                       goto unknown;
10657                   }
10658                 }
10659
10660                 goto unknown;
10661
10662               case 'l':
10663                 if (name[4] == 'o' &&
10664                     name[5] == 'g' &&
10665                     name[6] == 'i' &&
10666                     name[7] == 'n')
10667                 {                                 /* getlogin   */
10668                   return -KEY_getlogin;
10669                 }
10670
10671                 goto unknown;
10672
10673               case 'p':
10674                 if (name[4] == 'w')
10675                 {
10676                   switch (name[5])
10677                   {
10678                     case 'e':
10679                       if (name[6] == 'n' &&
10680                           name[7] == 't')
10681                       {                           /* getpwent   */
10682                         return -KEY_getpwent;
10683                       }
10684
10685                       goto unknown;
10686
10687                     case 'n':
10688                       if (name[6] == 'a' &&
10689                           name[7] == 'm')
10690                       {                           /* getpwnam   */
10691                         return -KEY_getpwnam;
10692                       }
10693
10694                       goto unknown;
10695
10696                     case 'u':
10697                       if (name[6] == 'i' &&
10698                           name[7] == 'd')
10699                       {                           /* getpwuid   */
10700                         return -KEY_getpwuid;
10701                       }
10702
10703                       goto unknown;
10704
10705                     default:
10706                       goto unknown;
10707                   }
10708                 }
10709
10710                 goto unknown;
10711
10712               default:
10713                 goto unknown;
10714             }
10715           }
10716
10717           goto unknown;
10718
10719         case 'r':
10720           if (name[1] == 'e' &&
10721               name[2] == 'a' &&
10722               name[3] == 'd')
10723           {
10724             switch (name[4])
10725             {
10726               case 'l':
10727                 if (name[5] == 'i' &&
10728                     name[6] == 'n')
10729                 {
10730                   switch (name[7])
10731                   {
10732                     case 'e':
10733                       {                           /* readline   */
10734                         return -KEY_readline;
10735                       }
10736
10737                     case 'k':
10738                       {                           /* readlink   */
10739                         return -KEY_readlink;
10740                       }
10741
10742                     default:
10743                       goto unknown;
10744                   }
10745                 }
10746
10747                 goto unknown;
10748
10749               case 'p':
10750                 if (name[5] == 'i' &&
10751                     name[6] == 'p' &&
10752                     name[7] == 'e')
10753                 {                                 /* readpipe   */
10754                   return -KEY_readpipe;
10755                 }
10756
10757                 goto unknown;
10758
10759               default:
10760                 goto unknown;
10761             }
10762           }
10763
10764           goto unknown;
10765
10766         case 's':
10767           switch (name[1])
10768           {
10769             case 'e':
10770               if (name[2] == 't')
10771               {
10772                 switch (name[3])
10773                 {
10774                   case 'g':
10775                     if (name[4] == 'r' &&
10776                         name[5] == 'e' &&
10777                         name[6] == 'n' &&
10778                         name[7] == 't')
10779                     {                             /* setgrent   */
10780                       return -KEY_setgrent;
10781                     }
10782
10783                     goto unknown;
10784
10785                   case 'p':
10786                     if (name[4] == 'w' &&
10787                         name[5] == 'e' &&
10788                         name[6] == 'n' &&
10789                         name[7] == 't')
10790                     {                             /* setpwent   */
10791                       return -KEY_setpwent;
10792                     }
10793
10794                     goto unknown;
10795
10796                   default:
10797                     goto unknown;
10798                 }
10799               }
10800
10801               goto unknown;
10802
10803             case 'h':
10804               switch (name[2])
10805               {
10806                 case 'm':
10807                   if (name[3] == 'w' &&
10808                       name[4] == 'r' &&
10809                       name[5] == 'i' &&
10810                       name[6] == 't' &&
10811                       name[7] == 'e')
10812                   {                               /* shmwrite   */
10813                     return -KEY_shmwrite;
10814                   }
10815
10816                   goto unknown;
10817
10818                 case 'u':
10819                   if (name[3] == 't' &&
10820                       name[4] == 'd' &&
10821                       name[5] == 'o' &&
10822                       name[6] == 'w' &&
10823                       name[7] == 'n')
10824                   {                               /* shutdown   */
10825                     return -KEY_shutdown;
10826                   }
10827
10828                   goto unknown;
10829
10830                 default:
10831                   goto unknown;
10832               }
10833
10834             case 'y':
10835               if (name[2] == 's' &&
10836                   name[3] == 'w' &&
10837                   name[4] == 'r' &&
10838                   name[5] == 'i' &&
10839                   name[6] == 't' &&
10840                   name[7] == 'e')
10841               {                                   /* syswrite   */
10842                 return -KEY_syswrite;
10843               }
10844
10845               goto unknown;
10846
10847             default:
10848               goto unknown;
10849           }
10850
10851         case 't':
10852           if (name[1] == 'r' &&
10853               name[2] == 'u' &&
10854               name[3] == 'n' &&
10855               name[4] == 'c' &&
10856               name[5] == 'a' &&
10857               name[6] == 't' &&
10858               name[7] == 'e')
10859           {                                       /* truncate   */
10860             return -KEY_truncate;
10861           }
10862
10863           goto unknown;
10864
10865         default:
10866           goto unknown;
10867       }
10868
10869     case 9: /* 9 tokens of length 9 */
10870       switch (name[0])
10871       {
10872         case 'U':
10873           if (name[1] == 'N' &&
10874               name[2] == 'I' &&
10875               name[3] == 'T' &&
10876               name[4] == 'C' &&
10877               name[5] == 'H' &&
10878               name[6] == 'E' &&
10879               name[7] == 'C' &&
10880               name[8] == 'K')
10881           {                                       /* UNITCHECK  */
10882             return KEY_UNITCHECK;
10883           }
10884
10885           goto unknown;
10886
10887         case 'e':
10888           if (name[1] == 'n' &&
10889               name[2] == 'd' &&
10890               name[3] == 'n' &&
10891               name[4] == 'e' &&
10892               name[5] == 't' &&
10893               name[6] == 'e' &&
10894               name[7] == 'n' &&
10895               name[8] == 't')
10896           {                                       /* endnetent  */
10897             return -KEY_endnetent;
10898           }
10899
10900           goto unknown;
10901
10902         case 'g':
10903           if (name[1] == 'e' &&
10904               name[2] == 't' &&
10905               name[3] == 'n' &&
10906               name[4] == 'e' &&
10907               name[5] == 't' &&
10908               name[6] == 'e' &&
10909               name[7] == 'n' &&
10910               name[8] == 't')
10911           {                                       /* getnetent  */
10912             return -KEY_getnetent;
10913           }
10914
10915           goto unknown;
10916
10917         case 'l':
10918           if (name[1] == 'o' &&
10919               name[2] == 'c' &&
10920               name[3] == 'a' &&
10921               name[4] == 'l' &&
10922               name[5] == 't' &&
10923               name[6] == 'i' &&
10924               name[7] == 'm' &&
10925               name[8] == 'e')
10926           {                                       /* localtime  */
10927             return -KEY_localtime;
10928           }
10929
10930           goto unknown;
10931
10932         case 'p':
10933           if (name[1] == 'r' &&
10934               name[2] == 'o' &&
10935               name[3] == 't' &&
10936               name[4] == 'o' &&
10937               name[5] == 't' &&
10938               name[6] == 'y' &&
10939               name[7] == 'p' &&
10940               name[8] == 'e')
10941           {                                       /* prototype  */
10942             return KEY_prototype;
10943           }
10944
10945           goto unknown;
10946
10947         case 'q':
10948           if (name[1] == 'u' &&
10949               name[2] == 'o' &&
10950               name[3] == 't' &&
10951               name[4] == 'e' &&
10952               name[5] == 'm' &&
10953               name[6] == 'e' &&
10954               name[7] == 't' &&
10955               name[8] == 'a')
10956           {                                       /* quotemeta  */
10957             return -KEY_quotemeta;
10958           }
10959
10960           goto unknown;
10961
10962         case 'r':
10963           if (name[1] == 'e' &&
10964               name[2] == 'w' &&
10965               name[3] == 'i' &&
10966               name[4] == 'n' &&
10967               name[5] == 'd' &&
10968               name[6] == 'd' &&
10969               name[7] == 'i' &&
10970               name[8] == 'r')
10971           {                                       /* rewinddir  */
10972             return -KEY_rewinddir;
10973           }
10974
10975           goto unknown;
10976
10977         case 's':
10978           if (name[1] == 'e' &&
10979               name[2] == 't' &&
10980               name[3] == 'n' &&
10981               name[4] == 'e' &&
10982               name[5] == 't' &&
10983               name[6] == 'e' &&
10984               name[7] == 'n' &&
10985               name[8] == 't')
10986           {                                       /* setnetent  */
10987             return -KEY_setnetent;
10988           }
10989
10990           goto unknown;
10991
10992         case 'w':
10993           if (name[1] == 'a' &&
10994               name[2] == 'n' &&
10995               name[3] == 't' &&
10996               name[4] == 'a' &&
10997               name[5] == 'r' &&
10998               name[6] == 'r' &&
10999               name[7] == 'a' &&
11000               name[8] == 'y')
11001           {                                       /* wantarray  */
11002             return -KEY_wantarray;
11003           }
11004
11005           goto unknown;
11006
11007         default:
11008           goto unknown;
11009       }
11010
11011     case 10: /* 9 tokens of length 10 */
11012       switch (name[0])
11013       {
11014         case 'e':
11015           if (name[1] == 'n' &&
11016               name[2] == 'd')
11017           {
11018             switch (name[3])
11019             {
11020               case 'h':
11021                 if (name[4] == 'o' &&
11022                     name[5] == 's' &&
11023                     name[6] == 't' &&
11024                     name[7] == 'e' &&
11025                     name[8] == 'n' &&
11026                     name[9] == 't')
11027                 {                                 /* endhostent */
11028                   return -KEY_endhostent;
11029                 }
11030
11031                 goto unknown;
11032
11033               case 's':
11034                 if (name[4] == 'e' &&
11035                     name[5] == 'r' &&
11036                     name[6] == 'v' &&
11037                     name[7] == 'e' &&
11038                     name[8] == 'n' &&
11039                     name[9] == 't')
11040                 {                                 /* endservent */
11041                   return -KEY_endservent;
11042                 }
11043
11044                 goto unknown;
11045
11046               default:
11047                 goto unknown;
11048             }
11049           }
11050
11051           goto unknown;
11052
11053         case 'g':
11054           if (name[1] == 'e' &&
11055               name[2] == 't')
11056           {
11057             switch (name[3])
11058             {
11059               case 'h':
11060                 if (name[4] == 'o' &&
11061                     name[5] == 's' &&
11062                     name[6] == 't' &&
11063                     name[7] == 'e' &&
11064                     name[8] == 'n' &&
11065                     name[9] == 't')
11066                 {                                 /* gethostent */
11067                   return -KEY_gethostent;
11068                 }
11069
11070                 goto unknown;
11071
11072               case 's':
11073                 switch (name[4])
11074                 {
11075                   case 'e':
11076                     if (name[5] == 'r' &&
11077                         name[6] == 'v' &&
11078                         name[7] == 'e' &&
11079                         name[8] == 'n' &&
11080                         name[9] == 't')
11081                     {                             /* getservent */
11082                       return -KEY_getservent;
11083                     }
11084
11085                     goto unknown;
11086
11087                   case 'o':
11088                     if (name[5] == 'c' &&
11089                         name[6] == 'k' &&
11090                         name[7] == 'o' &&
11091                         name[8] == 'p' &&
11092                         name[9] == 't')
11093                     {                             /* getsockopt */
11094                       return -KEY_getsockopt;
11095                     }
11096
11097                     goto unknown;
11098
11099                   default:
11100                     goto unknown;
11101                 }
11102
11103               default:
11104                 goto unknown;
11105             }
11106           }
11107
11108           goto unknown;
11109
11110         case 's':
11111           switch (name[1])
11112           {
11113             case 'e':
11114               if (name[2] == 't')
11115               {
11116                 switch (name[3])
11117                 {
11118                   case 'h':
11119                     if (name[4] == 'o' &&
11120                         name[5] == 's' &&
11121                         name[6] == 't' &&
11122                         name[7] == 'e' &&
11123                         name[8] == 'n' &&
11124                         name[9] == 't')
11125                     {                             /* sethostent */
11126                       return -KEY_sethostent;
11127                     }
11128
11129                     goto unknown;
11130
11131                   case 's':
11132                     switch (name[4])
11133                     {
11134                       case 'e':
11135                         if (name[5] == 'r' &&
11136                             name[6] == 'v' &&
11137                             name[7] == 'e' &&
11138                             name[8] == 'n' &&
11139                             name[9] == 't')
11140                         {                         /* setservent */
11141                           return -KEY_setservent;
11142                         }
11143
11144                         goto unknown;
11145
11146                       case 'o':
11147                         if (name[5] == 'c' &&
11148                             name[6] == 'k' &&
11149                             name[7] == 'o' &&
11150                             name[8] == 'p' &&
11151                             name[9] == 't')
11152                         {                         /* setsockopt */
11153                           return -KEY_setsockopt;
11154                         }
11155
11156                         goto unknown;
11157
11158                       default:
11159                         goto unknown;
11160                     }
11161
11162                   default:
11163                     goto unknown;
11164                 }
11165               }
11166
11167               goto unknown;
11168
11169             case 'o':
11170               if (name[2] == 'c' &&
11171                   name[3] == 'k' &&
11172                   name[4] == 'e' &&
11173                   name[5] == 't' &&
11174                   name[6] == 'p' &&
11175                   name[7] == 'a' &&
11176                   name[8] == 'i' &&
11177                   name[9] == 'r')
11178               {                                   /* socketpair */
11179                 return -KEY_socketpair;
11180               }
11181
11182               goto unknown;
11183
11184             default:
11185               goto unknown;
11186           }
11187
11188         default:
11189           goto unknown;
11190       }
11191
11192     case 11: /* 8 tokens of length 11 */
11193       switch (name[0])
11194       {
11195         case '_':
11196           if (name[1] == '_' &&
11197               name[2] == 'P' &&
11198               name[3] == 'A' &&
11199               name[4] == 'C' &&
11200               name[5] == 'K' &&
11201               name[6] == 'A' &&
11202               name[7] == 'G' &&
11203               name[8] == 'E' &&
11204               name[9] == '_' &&
11205               name[10] == '_')
11206           {                                       /* __PACKAGE__ */
11207             return -KEY___PACKAGE__;
11208           }
11209
11210           goto unknown;
11211
11212         case 'e':
11213           if (name[1] == 'n' &&
11214               name[2] == 'd' &&
11215               name[3] == 'p' &&
11216               name[4] == 'r' &&
11217               name[5] == 'o' &&
11218               name[6] == 't' &&
11219               name[7] == 'o' &&
11220               name[8] == 'e' &&
11221               name[9] == 'n' &&
11222               name[10] == 't')
11223           {                                       /* endprotoent */
11224             return -KEY_endprotoent;
11225           }
11226
11227           goto unknown;
11228
11229         case 'g':
11230           if (name[1] == 'e' &&
11231               name[2] == 't')
11232           {
11233             switch (name[3])
11234             {
11235               case 'p':
11236                 switch (name[4])
11237                 {
11238                   case 'e':
11239                     if (name[5] == 'e' &&
11240                         name[6] == 'r' &&
11241                         name[7] == 'n' &&
11242                         name[8] == 'a' &&
11243                         name[9] == 'm' &&
11244                         name[10] == 'e')
11245                     {                             /* getpeername */
11246                       return -KEY_getpeername;
11247                     }
11248
11249                     goto unknown;
11250
11251                   case 'r':
11252                     switch (name[5])
11253                     {
11254                       case 'i':
11255                         if (name[6] == 'o' &&
11256                             name[7] == 'r' &&
11257                             name[8] == 'i' &&
11258                             name[9] == 't' &&
11259                             name[10] == 'y')
11260                         {                         /* getpriority */
11261                           return -KEY_getpriority;
11262                         }
11263
11264                         goto unknown;
11265
11266                       case 'o':
11267                         if (name[6] == 't' &&
11268                             name[7] == 'o' &&
11269                             name[8] == 'e' &&
11270                             name[9] == 'n' &&
11271                             name[10] == 't')
11272                         {                         /* getprotoent */
11273                           return -KEY_getprotoent;
11274                         }
11275
11276                         goto unknown;
11277
11278                       default:
11279                         goto unknown;
11280                     }
11281
11282                   default:
11283                     goto unknown;
11284                 }
11285
11286               case 's':
11287                 if (name[4] == 'o' &&
11288                     name[5] == 'c' &&
11289                     name[6] == 'k' &&
11290                     name[7] == 'n' &&
11291                     name[8] == 'a' &&
11292                     name[9] == 'm' &&
11293                     name[10] == 'e')
11294                 {                                 /* getsockname */
11295                   return -KEY_getsockname;
11296                 }
11297
11298                 goto unknown;
11299
11300               default:
11301                 goto unknown;
11302             }
11303           }
11304
11305           goto unknown;
11306
11307         case 's':
11308           if (name[1] == 'e' &&
11309               name[2] == 't' &&
11310               name[3] == 'p' &&
11311               name[4] == 'r')
11312           {
11313             switch (name[5])
11314             {
11315               case 'i':
11316                 if (name[6] == 'o' &&
11317                     name[7] == 'r' &&
11318                     name[8] == 'i' &&
11319                     name[9] == 't' &&
11320                     name[10] == 'y')
11321                 {                                 /* setpriority */
11322                   return -KEY_setpriority;
11323                 }
11324
11325                 goto unknown;
11326
11327               case 'o':
11328                 if (name[6] == 't' &&
11329                     name[7] == 'o' &&
11330                     name[8] == 'e' &&
11331                     name[9] == 'n' &&
11332                     name[10] == 't')
11333                 {                                 /* setprotoent */
11334                   return -KEY_setprotoent;
11335                 }
11336
11337                 goto unknown;
11338
11339               default:
11340                 goto unknown;
11341             }
11342           }
11343
11344           goto unknown;
11345
11346         default:
11347           goto unknown;
11348       }
11349
11350     case 12: /* 2 tokens of length 12 */
11351       if (name[0] == 'g' &&
11352           name[1] == 'e' &&
11353           name[2] == 't' &&
11354           name[3] == 'n' &&
11355           name[4] == 'e' &&
11356           name[5] == 't' &&
11357           name[6] == 'b' &&
11358           name[7] == 'y')
11359       {
11360         switch (name[8])
11361         {
11362           case 'a':
11363             if (name[9] == 'd' &&
11364                 name[10] == 'd' &&
11365                 name[11] == 'r')
11366             {                                     /* getnetbyaddr */
11367               return -KEY_getnetbyaddr;
11368             }
11369
11370             goto unknown;
11371
11372           case 'n':
11373             if (name[9] == 'a' &&
11374                 name[10] == 'm' &&
11375                 name[11] == 'e')
11376             {                                     /* getnetbyname */
11377               return -KEY_getnetbyname;
11378             }
11379
11380             goto unknown;
11381
11382           default:
11383             goto unknown;
11384         }
11385       }
11386
11387       goto unknown;
11388
11389     case 13: /* 4 tokens of length 13 */
11390       if (name[0] == 'g' &&
11391           name[1] == 'e' &&
11392           name[2] == 't')
11393       {
11394         switch (name[3])
11395         {
11396           case 'h':
11397             if (name[4] == 'o' &&
11398                 name[5] == 's' &&
11399                 name[6] == 't' &&
11400                 name[7] == 'b' &&
11401                 name[8] == 'y')
11402             {
11403               switch (name[9])
11404               {
11405                 case 'a':
11406                   if (name[10] == 'd' &&
11407                       name[11] == 'd' &&
11408                       name[12] == 'r')
11409                   {                               /* gethostbyaddr */
11410                     return -KEY_gethostbyaddr;
11411                   }
11412
11413                   goto unknown;
11414
11415                 case 'n':
11416                   if (name[10] == 'a' &&
11417                       name[11] == 'm' &&
11418                       name[12] == 'e')
11419                   {                               /* gethostbyname */
11420                     return -KEY_gethostbyname;
11421                   }
11422
11423                   goto unknown;
11424
11425                 default:
11426                   goto unknown;
11427               }
11428             }
11429
11430             goto unknown;
11431
11432           case 's':
11433             if (name[4] == 'e' &&
11434                 name[5] == 'r' &&
11435                 name[6] == 'v' &&
11436                 name[7] == 'b' &&
11437                 name[8] == 'y')
11438             {
11439               switch (name[9])
11440               {
11441                 case 'n':
11442                   if (name[10] == 'a' &&
11443                       name[11] == 'm' &&
11444                       name[12] == 'e')
11445                   {                               /* getservbyname */
11446                     return -KEY_getservbyname;
11447                   }
11448
11449                   goto unknown;
11450
11451                 case 'p':
11452                   if (name[10] == 'o' &&
11453                       name[11] == 'r' &&
11454                       name[12] == 't')
11455                   {                               /* getservbyport */
11456                     return -KEY_getservbyport;
11457                   }
11458
11459                   goto unknown;
11460
11461                 default:
11462                   goto unknown;
11463               }
11464             }
11465
11466             goto unknown;
11467
11468           default:
11469             goto unknown;
11470         }
11471       }
11472
11473       goto unknown;
11474
11475     case 14: /* 1 tokens of length 14 */
11476       if (name[0] == 'g' &&
11477           name[1] == 'e' &&
11478           name[2] == 't' &&
11479           name[3] == 'p' &&
11480           name[4] == 'r' &&
11481           name[5] == 'o' &&
11482           name[6] == 't' &&
11483           name[7] == 'o' &&
11484           name[8] == 'b' &&
11485           name[9] == 'y' &&
11486           name[10] == 'n' &&
11487           name[11] == 'a' &&
11488           name[12] == 'm' &&
11489           name[13] == 'e')
11490       {                                           /* getprotobyname */
11491         return -KEY_getprotobyname;
11492       }
11493
11494       goto unknown;
11495
11496     case 16: /* 1 tokens of length 16 */
11497       if (name[0] == 'g' &&
11498           name[1] == 'e' &&
11499           name[2] == 't' &&
11500           name[3] == 'p' &&
11501           name[4] == 'r' &&
11502           name[5] == 'o' &&
11503           name[6] == 't' &&
11504           name[7] == 'o' &&
11505           name[8] == 'b' &&
11506           name[9] == 'y' &&
11507           name[10] == 'n' &&
11508           name[11] == 'u' &&
11509           name[12] == 'm' &&
11510           name[13] == 'b' &&
11511           name[14] == 'e' &&
11512           name[15] == 'r')
11513       {                                           /* getprotobynumber */
11514         return -KEY_getprotobynumber;
11515       }
11516
11517       goto unknown;
11518
11519     default:
11520       goto unknown;
11521   }
11522
11523 unknown:
11524   return 0;
11525 }
11526
11527 STATIC void
11528 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
11529 {
11530     dVAR;
11531
11532     PERL_ARGS_ASSERT_CHECKCOMMA;
11533
11534     if (*s == ' ' && s[1] == '(') {     /* XXX gotta be a better way */
11535         if (ckWARN(WARN_SYNTAX)) {
11536             int level = 1;
11537             const char *w;
11538             for (w = s+2; *w && level; w++) {
11539                 if (*w == '(')
11540                     ++level;
11541                 else if (*w == ')')
11542                     --level;
11543             }
11544             while (isSPACE(*w))
11545                 ++w;
11546             /* the list of chars below is for end of statements or
11547              * block / parens, boolean operators (&&, ||, //) and branch
11548              * constructs (or, and, if, until, unless, while, err, for).
11549              * Not a very solid hack... */
11550             if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
11551                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11552                             "%s (...) interpreted as function",name);
11553         }
11554     }
11555     while (s < PL_bufend && isSPACE(*s))
11556         s++;
11557     if (*s == '(')
11558         s++;
11559     while (s < PL_bufend && isSPACE(*s))
11560         s++;
11561     if (isIDFIRST_lazy_if(s,UTF)) {
11562         const char * const w = s++;
11563         while (isALNUM_lazy_if(s,UTF))
11564             s++;
11565         while (s < PL_bufend && isSPACE(*s))
11566             s++;
11567         if (*s == ',') {
11568             GV* gv;
11569             if (keyword(w, s - w, 0))
11570                 return;
11571
11572             gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
11573             if (gv && GvCVu(gv))
11574                 return;
11575             Perl_croak(aTHX_ "No comma allowed after %s", what);
11576         }
11577     }
11578 }
11579
11580 /* Either returns sv, or mortalizes sv and returns a new SV*.
11581    Best used as sv=new_constant(..., sv, ...).
11582    If s, pv are NULL, calls subroutine with one argument,
11583    and type is used with error messages only. */
11584
11585 STATIC SV *
11586 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen,
11587                SV *sv, SV *pv, const char *type, STRLEN typelen)
11588 {
11589     dVAR; dSP;
11590     HV * const table = GvHV(PL_hintgv);          /* ^H */
11591     SV *res;
11592     SV **cvp;
11593     SV *cv, *typesv;
11594     const char *why1 = "", *why2 = "", *why3 = "";
11595
11596     PERL_ARGS_ASSERT_NEW_CONSTANT;
11597
11598     if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
11599         SV *msg;
11600         
11601         why2 = (const char *)
11602             (strEQ(key,"charnames")
11603              ? "(possibly a missing \"use charnames ...\")"
11604              : "");
11605         msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
11606                             (type ? type: "undef"), why2);
11607
11608         /* This is convoluted and evil ("goto considered harmful")
11609          * but I do not understand the intricacies of all the different
11610          * failure modes of %^H in here.  The goal here is to make
11611          * the most probable error message user-friendly. --jhi */
11612
11613         goto msgdone;
11614
11615     report:
11616         msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
11617                             (type ? type: "undef"), why1, why2, why3);
11618     msgdone:
11619         yyerror(SvPVX_const(msg));
11620         SvREFCNT_dec(msg);
11621         return sv;
11622     }
11623
11624     /* charnames doesn't work well if there have been errors found */
11625     if (PL_error_count > 0 && strEQ(key,"charnames"))
11626         return &PL_sv_undef;
11627
11628     cvp = hv_fetch(table, key, keylen, FALSE);
11629     if (!cvp || !SvOK(*cvp)) {
11630         why1 = "$^H{";
11631         why2 = key;
11632         why3 = "} is not defined";
11633         goto report;
11634     }
11635     sv_2mortal(sv);                     /* Parent created it permanently */
11636     cv = *cvp;
11637     if (!pv && s)
11638         pv = newSVpvn_flags(s, len, SVs_TEMP);
11639     if (type && pv)
11640         typesv = newSVpvn_flags(type, typelen, SVs_TEMP);
11641     else
11642         typesv = &PL_sv_undef;
11643
11644     PUSHSTACKi(PERLSI_OVERLOAD);
11645     ENTER ;
11646     SAVETMPS;
11647
11648     PUSHMARK(SP) ;
11649     EXTEND(sp, 3);
11650     if (pv)
11651         PUSHs(pv);
11652     PUSHs(sv);
11653     if (pv)
11654         PUSHs(typesv);
11655     PUTBACK;
11656     call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
11657
11658     SPAGAIN ;
11659
11660     /* Check the eval first */
11661     if (!PL_in_eval && SvTRUE(ERRSV)) {
11662         sv_catpvs(ERRSV, "Propagated");
11663         yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
11664         (void)POPs;
11665         res = SvREFCNT_inc_simple(sv);
11666     }
11667     else {
11668         res = POPs;
11669         SvREFCNT_inc_simple_void(res);
11670     }
11671
11672     PUTBACK ;
11673     FREETMPS ;
11674     LEAVE ;
11675     POPSTACK;
11676
11677     if (!SvOK(res)) {
11678         why1 = "Call to &{$^H{";
11679         why2 = key;
11680         why3 = "}} did not return a defined value";
11681         sv = res;
11682         goto report;
11683     }
11684
11685     return res;
11686 }
11687
11688 /* Returns a NUL terminated string, with the length of the string written to
11689    *slp
11690    */
11691 STATIC char *
11692 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
11693 {
11694     dVAR;
11695     register char *d = dest;
11696     register char * const e = d + destlen - 3;  /* two-character token, ending NUL */
11697
11698     PERL_ARGS_ASSERT_SCAN_WORD;
11699
11700     for (;;) {
11701         if (d >= e)
11702             Perl_croak(aTHX_ ident_too_long);
11703         if (isALNUM(*s))        /* UTF handled below */
11704             *d++ = *s++;
11705         else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
11706             *d++ = ':';
11707             *d++ = ':';
11708             s++;
11709         }
11710         else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
11711             *d++ = *s++;
11712             *d++ = *s++;
11713         }
11714         else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
11715             char *t = s + UTF8SKIP(s);
11716             size_t len;
11717             while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
11718                 t += UTF8SKIP(t);
11719             len = t - s;
11720             if (d + len > e)
11721                 Perl_croak(aTHX_ ident_too_long);
11722             Copy(s, d, len, char);
11723             d += len;
11724             s = t;
11725         }
11726         else {
11727             *d = '\0';
11728             *slp = d - dest;
11729             return s;
11730         }
11731     }
11732 }
11733
11734 STATIC char *
11735 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
11736 {
11737     dVAR;
11738     char *bracket = NULL;
11739     char funny = *s++;
11740     register char *d = dest;
11741     register char * const e = d + destlen - 3;    /* two-character token, ending NUL */
11742
11743     PERL_ARGS_ASSERT_SCAN_IDENT;
11744
11745     if (isSPACE(*s))
11746         s = PEEKSPACE(s);
11747     if (isDIGIT(*s)) {
11748         while (isDIGIT(*s)) {
11749             if (d >= e)
11750                 Perl_croak(aTHX_ ident_too_long);
11751             *d++ = *s++;
11752         }
11753     }
11754     else {
11755         for (;;) {
11756             if (d >= e)
11757                 Perl_croak(aTHX_ ident_too_long);
11758             if (isALNUM(*s))    /* UTF handled below */
11759                 *d++ = *s++;
11760             else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
11761                 *d++ = ':';
11762                 *d++ = ':';
11763                 s++;
11764             }
11765             else if (*s == ':' && s[1] == ':') {
11766                 *d++ = *s++;
11767                 *d++ = *s++;
11768             }
11769             else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
11770                 char *t = s + UTF8SKIP(s);
11771                 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
11772                     t += UTF8SKIP(t);
11773                 if (d + (t - s) > e)
11774                     Perl_croak(aTHX_ ident_too_long);
11775                 Copy(s, d, t - s, char);
11776                 d += t - s;
11777                 s = t;
11778             }
11779             else
11780                 break;
11781         }
11782     }
11783     *d = '\0';
11784     d = dest;
11785     if (*d) {
11786         if (PL_lex_state != LEX_NORMAL)
11787             PL_lex_state = LEX_INTERPENDMAYBE;
11788         return s;
11789     }
11790     if (*s == '$' && s[1] &&
11791         (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
11792     {
11793         return s;
11794     }
11795     if (*s == '{') {
11796         bracket = s;
11797         s++;
11798     }
11799     else if (ck_uni)
11800         check_uni();
11801     if (s < send)
11802         *d = *s++;
11803     d[1] = '\0';
11804     if (*d == '^' && *s && isCONTROLVAR(*s)) {
11805         *d = toCTRL(*s);
11806         s++;
11807     }
11808     if (bracket) {
11809         if (isSPACE(s[-1])) {
11810             while (s < send) {
11811                 const char ch = *s++;
11812                 if (!SPACE_OR_TAB(ch)) {
11813                     *d = ch;
11814                     break;
11815                 }
11816             }
11817         }
11818         if (isIDFIRST_lazy_if(d,UTF)) {
11819             d++;
11820             if (UTF) {
11821                 char *end = s;
11822                 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
11823                     end += UTF8SKIP(end);
11824                     while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
11825                         end += UTF8SKIP(end);
11826                 }
11827                 Copy(s, d, end - s, char);
11828                 d += end - s;
11829                 s = end;
11830             }
11831             else {
11832                 while ((isALNUM(*s) || *s == ':') && d < e)
11833                     *d++ = *s++;
11834                 if (d >= e)
11835                     Perl_croak(aTHX_ ident_too_long);
11836             }
11837             *d = '\0';
11838             while (s < send && SPACE_OR_TAB(*s))
11839                 s++;
11840             if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
11841                 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
11842                     const char * const brack =
11843                         (const char *)
11844                         ((*s == '[') ? "[...]" : "{...}");
11845                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
11846                         "Ambiguous use of %c{%s%s} resolved to %c%s%s",
11847                         funny, dest, brack, funny, dest, brack);
11848                 }
11849                 bracket++;
11850                 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
11851                 return s;
11852             }
11853         }
11854         /* Handle extended ${^Foo} variables
11855          * 1999-02-27 mjd-perl-patch@plover.com */
11856         else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
11857                  && isALNUM(*s))
11858         {
11859             d++;
11860             while (isALNUM(*s) && d < e) {
11861                 *d++ = *s++;
11862             }
11863             if (d >= e)
11864                 Perl_croak(aTHX_ ident_too_long);
11865             *d = '\0';
11866         }
11867         if (*s == '}') {
11868             s++;
11869             if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
11870                 PL_lex_state = LEX_INTERPEND;
11871                 PL_expect = XREF;
11872             }
11873             if (PL_lex_state == LEX_NORMAL) {
11874                 if (ckWARN(WARN_AMBIGUOUS) &&
11875                     (keyword(dest, d - dest, 0)
11876                      || get_cvn_flags(dest, d - dest, 0)))
11877                 {
11878                     if (funny == '#')
11879                         funny = '@';
11880                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
11881                         "Ambiguous use of %c{%s} resolved to %c%s",
11882                         funny, dest, funny, dest);
11883                 }
11884             }
11885         }
11886         else {
11887             s = bracket;                /* let the parser handle it */
11888             *dest = '\0';
11889         }
11890     }
11891     else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
11892         PL_lex_state = LEX_INTERPEND;
11893     return s;
11894 }
11895
11896 static U32
11897 S_pmflag(U32 pmfl, const char ch) {
11898     switch (ch) {
11899         CASE_STD_PMMOD_FLAGS_PARSE_SET(&pmfl);
11900     case GLOBAL_PAT_MOD:      pmfl |= PMf_GLOBAL; break;
11901     case CONTINUE_PAT_MOD:    pmfl |= PMf_CONTINUE; break;
11902     case ONCE_PAT_MOD:        pmfl |= PMf_KEEP; break;
11903     case KEEPCOPY_PAT_MOD:    pmfl |= PMf_KEEPCOPY; break;
11904     case NONDESTRUCT_PAT_MOD: pmfl |= PMf_NONDESTRUCT; break;
11905     }
11906     return pmfl;
11907 }
11908
11909 STATIC char *
11910 S_scan_pat(pTHX_ char *start, I32 type)
11911 {
11912     dVAR;
11913     PMOP *pm;
11914     char *s = scan_str(start,!!PL_madskills,FALSE);
11915     const char * const valid_flags =
11916         (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
11917 #ifdef PERL_MAD
11918     char *modstart;
11919 #endif
11920
11921     PERL_ARGS_ASSERT_SCAN_PAT;
11922
11923     if (!s) {
11924         const char * const delimiter = skipspace(start);
11925         Perl_croak(aTHX_
11926                    (const char *)
11927                    (*delimiter == '?'
11928                     ? "Search pattern not terminated or ternary operator parsed as search pattern"
11929                     : "Search pattern not terminated" ));
11930     }
11931
11932     pm = (PMOP*)newPMOP(type, 0);
11933     if (PL_multi_open == '?') {
11934         /* This is the only point in the code that sets PMf_ONCE:  */
11935         pm->op_pmflags |= PMf_ONCE;
11936
11937         /* Hence it's safe to do this bit of PMOP book-keeping here, which
11938            allows us to restrict the list needed by reset to just the ??
11939            matches.  */
11940         assert(type != OP_TRANS);
11941         if (PL_curstash) {
11942             MAGIC *mg = mg_find((const SV *)PL_curstash, PERL_MAGIC_symtab);
11943             U32 elements;
11944             if (!mg) {
11945                 mg = sv_magicext(MUTABLE_SV(PL_curstash), 0, PERL_MAGIC_symtab, 0, 0,
11946                                  0);
11947             }
11948             elements = mg->mg_len / sizeof(PMOP**);
11949             Renewc(mg->mg_ptr, elements + 1, PMOP*, char);
11950             ((PMOP**)mg->mg_ptr) [elements++] = pm;
11951             mg->mg_len = elements * sizeof(PMOP**);
11952             PmopSTASH_set(pm,PL_curstash);
11953         }
11954     }
11955 #ifdef PERL_MAD
11956     modstart = s;
11957 #endif
11958     while (*s && strchr(valid_flags, *s))
11959         pm->op_pmflags = S_pmflag(pm->op_pmflags, *s++);
11960
11961     if (isALNUM(*s)) {
11962         Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX),
11963             "Having no space between pattern and following word is deprecated");
11964
11965     }
11966 #ifdef PERL_MAD
11967     if (PL_madskills && modstart != s) {
11968         SV* tmptoken = newSVpvn(modstart, s - modstart);
11969         append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
11970     }
11971 #endif
11972     /* issue a warning if /c is specified,but /g is not */
11973     if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
11974     {
11975         Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), 
11976                        "Use of /c modifier is meaningless without /g" );
11977     }
11978
11979     PL_lex_op = (OP*)pm;
11980     pl_yylval.ival = OP_MATCH;
11981     return s;
11982 }
11983
11984 STATIC char *
11985 S_scan_subst(pTHX_ char *start)
11986 {
11987     dVAR;
11988     register char *s;
11989     register PMOP *pm;
11990     I32 first_start;
11991     I32 es = 0;
11992 #ifdef PERL_MAD
11993     char *modstart;
11994 #endif
11995
11996     PERL_ARGS_ASSERT_SCAN_SUBST;
11997
11998     pl_yylval.ival = OP_NULL;
11999
12000     s = scan_str(start,!!PL_madskills,FALSE);
12001
12002     if (!s)
12003         Perl_croak(aTHX_ "Substitution pattern not terminated");
12004
12005     if (s[-1] == PL_multi_open)
12006         s--;
12007 #ifdef PERL_MAD
12008     if (PL_madskills) {
12009         CURMAD('q', PL_thisopen);
12010         CURMAD('_', PL_thiswhite);
12011         CURMAD('E', PL_thisstuff);
12012         CURMAD('Q', PL_thisclose);
12013         PL_realtokenstart = s - SvPVX(PL_linestr);
12014     }
12015 #endif
12016
12017     first_start = PL_multi_start;
12018     s = scan_str(s,!!PL_madskills,FALSE);
12019     if (!s) {
12020         if (PL_lex_stuff) {
12021             SvREFCNT_dec(PL_lex_stuff);
12022             PL_lex_stuff = NULL;
12023         }
12024         Perl_croak(aTHX_ "Substitution replacement not terminated");
12025     }
12026     PL_multi_start = first_start;       /* so whole substitution is taken together */
12027
12028     pm = (PMOP*)newPMOP(OP_SUBST, 0);
12029
12030 #ifdef PERL_MAD
12031     if (PL_madskills) {
12032         CURMAD('z', PL_thisopen);
12033         CURMAD('R', PL_thisstuff);
12034         CURMAD('Z', PL_thisclose);
12035     }
12036     modstart = s;
12037 #endif
12038
12039     while (*s) {
12040         if (*s == EXEC_PAT_MOD) {
12041             s++;
12042             es++;
12043         }
12044         else if (strchr(S_PAT_MODS, *s))
12045             pm->op_pmflags = S_pmflag(pm->op_pmflags, *s++);
12046         else {
12047             if (isALNUM(*s)) {
12048                 Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX),
12049                     "Having no space between pattern and following word is deprecated");
12050
12051             }
12052             break;
12053         }
12054     }
12055
12056 #ifdef PERL_MAD
12057     if (PL_madskills) {
12058         if (modstart != s)
12059             curmad('m', newSVpvn(modstart, s - modstart));
12060         append_madprops(PL_thismad, (OP*)pm, 0);
12061         PL_thismad = 0;
12062     }
12063 #endif
12064     if ((pm->op_pmflags & PMf_CONTINUE)) {
12065         Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
12066     }
12067
12068     if (es) {
12069         SV * const repl = newSVpvs("");
12070
12071         PL_sublex_info.super_bufptr = s;
12072         PL_sublex_info.super_bufend = PL_bufend;
12073         PL_multi_end = 0;
12074         pm->op_pmflags |= PMf_EVAL;
12075         while (es-- > 0) {
12076             if (es)
12077                 sv_catpvs(repl, "eval ");
12078             else
12079                 sv_catpvs(repl, "do ");
12080         }
12081         sv_catpvs(repl, "{");
12082         sv_catsv(repl, PL_lex_repl);
12083         if (strchr(SvPVX(PL_lex_repl), '#'))
12084             sv_catpvs(repl, "\n");
12085         sv_catpvs(repl, "}");
12086         SvEVALED_on(repl);
12087         SvREFCNT_dec(PL_lex_repl);
12088         PL_lex_repl = repl;
12089     }
12090
12091     PL_lex_op = (OP*)pm;
12092     pl_yylval.ival = OP_SUBST;
12093     return s;
12094 }
12095
12096 STATIC char *
12097 S_scan_trans(pTHX_ char *start)
12098 {
12099     dVAR;
12100     register char* s;
12101     OP *o;
12102     short *tbl;
12103     U8 squash;
12104     U8 del;
12105     U8 complement;
12106     bool nondestruct = 0;
12107 #ifdef PERL_MAD
12108     char *modstart;
12109 #endif
12110
12111     PERL_ARGS_ASSERT_SCAN_TRANS;
12112
12113     pl_yylval.ival = OP_NULL;
12114
12115     s = scan_str(start,!!PL_madskills,FALSE);
12116     if (!s)
12117         Perl_croak(aTHX_ "Transliteration pattern not terminated");
12118
12119     if (s[-1] == PL_multi_open)
12120         s--;
12121 #ifdef PERL_MAD
12122     if (PL_madskills) {
12123         CURMAD('q', PL_thisopen);
12124         CURMAD('_', PL_thiswhite);
12125         CURMAD('E', PL_thisstuff);
12126         CURMAD('Q', PL_thisclose);
12127         PL_realtokenstart = s - SvPVX(PL_linestr);
12128     }
12129 #endif
12130
12131     s = scan_str(s,!!PL_madskills,FALSE);
12132     if (!s) {
12133         if (PL_lex_stuff) {
12134             SvREFCNT_dec(PL_lex_stuff);
12135             PL_lex_stuff = NULL;
12136         }
12137         Perl_croak(aTHX_ "Transliteration replacement not terminated");
12138     }
12139     if (PL_madskills) {
12140         CURMAD('z', PL_thisopen);
12141         CURMAD('R', PL_thisstuff);
12142         CURMAD('Z', PL_thisclose);
12143     }
12144
12145     complement = del = squash = 0;
12146 #ifdef PERL_MAD
12147     modstart = s;
12148 #endif
12149     while (1) {
12150         switch (*s) {
12151         case 'c':
12152             complement = OPpTRANS_COMPLEMENT;
12153             break;
12154         case 'd':
12155             del = OPpTRANS_DELETE;
12156             break;
12157         case 's':
12158             squash = OPpTRANS_SQUASH;
12159             break;
12160         case 'r':
12161             nondestruct = 1;
12162             break;
12163         default:
12164             goto no_more;
12165         }
12166         s++;
12167     }
12168   no_more:
12169
12170     tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
12171     o = newPVOP(nondestruct ? OP_TRANSR : OP_TRANS, 0, (char*)tbl);
12172     o->op_private &= ~OPpTRANS_ALL;
12173     o->op_private |= del|squash|complement|
12174       (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
12175       (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF   : 0);
12176
12177     PL_lex_op = o;
12178     pl_yylval.ival = nondestruct ? OP_TRANSR : OP_TRANS;
12179
12180 #ifdef PERL_MAD
12181     if (PL_madskills) {
12182         if (modstart != s)
12183             curmad('m', newSVpvn(modstart, s - modstart));
12184         append_madprops(PL_thismad, o, 0);
12185         PL_thismad = 0;
12186     }
12187 #endif
12188
12189     return s;
12190 }
12191
12192 STATIC char *
12193 S_scan_heredoc(pTHX_ register char *s)
12194 {
12195     dVAR;
12196     SV *herewas;
12197     I32 op_type = OP_SCALAR;
12198     I32 len;
12199     SV *tmpstr;
12200     char term;
12201     const char *found_newline;
12202     register char *d;
12203     register char *e;
12204     char *peek;
12205     const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
12206 #ifdef PERL_MAD
12207     I32 stuffstart = s - SvPVX(PL_linestr);
12208     char *tstart;
12209  
12210     PL_realtokenstart = -1;
12211 #endif
12212
12213     PERL_ARGS_ASSERT_SCAN_HEREDOC;
12214
12215     s += 2;
12216     d = PL_tokenbuf;
12217     e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
12218     if (!outer)
12219         *d++ = '\n';
12220     peek = s;
12221     while (SPACE_OR_TAB(*peek))
12222         peek++;
12223     if (*peek == '`' || *peek == '\'' || *peek =='"') {
12224         s = peek;
12225         term = *s++;
12226         s = delimcpy(d, e, s, PL_bufend, term, &len);
12227         d += len;
12228         if (s < PL_bufend)
12229             s++;
12230     }
12231     else {
12232         if (*s == '\\')
12233             s++, term = '\'';
12234         else
12235             term = '"';
12236         if (!isALNUM_lazy_if(s,UTF))
12237             deprecate("bare << to mean <<\"\"");
12238         for (; isALNUM_lazy_if(s,UTF); s++) {
12239             if (d < e)
12240                 *d++ = *s;
12241         }
12242     }
12243     if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
12244         Perl_croak(aTHX_ "Delimiter for here document is too long");
12245     *d++ = '\n';
12246     *d = '\0';
12247     len = d - PL_tokenbuf;
12248
12249 #ifdef PERL_MAD
12250     if (PL_madskills) {
12251         tstart = PL_tokenbuf + !outer;
12252         PL_thisclose = newSVpvn(tstart, len - !outer);
12253         tstart = SvPVX(PL_linestr) + stuffstart;
12254         PL_thisopen = newSVpvn(tstart, s - tstart);
12255         stuffstart = s - SvPVX(PL_linestr);
12256     }
12257 #endif
12258 #ifndef PERL_STRICT_CR
12259     d = strchr(s, '\r');
12260     if (d) {
12261         char * const olds = s;
12262         s = d;
12263         while (s < PL_bufend) {
12264             if (*s == '\r') {
12265                 *d++ = '\n';
12266                 if (*++s == '\n')
12267                     s++;
12268             }
12269             else if (*s == '\n' && s[1] == '\r') {      /* \015\013 on a mac? */
12270                 *d++ = *s++;
12271                 s++;
12272             }
12273             else
12274                 *d++ = *s++;
12275         }
12276         *d = '\0';
12277         PL_bufend = d;
12278         SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
12279         s = olds;
12280     }
12281 #endif
12282 #ifdef PERL_MAD
12283     found_newline = 0;
12284 #endif
12285     if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
12286         herewas = newSVpvn(s,PL_bufend-s);
12287     }
12288     else {
12289 #ifdef PERL_MAD
12290         herewas = newSVpvn(s-1,found_newline-s+1);
12291 #else
12292         s--;
12293         herewas = newSVpvn(s,found_newline-s);
12294 #endif
12295     }
12296 #ifdef PERL_MAD
12297     if (PL_madskills) {
12298         tstart = SvPVX(PL_linestr) + stuffstart;
12299         if (PL_thisstuff)
12300             sv_catpvn(PL_thisstuff, tstart, s - tstart);
12301         else
12302             PL_thisstuff = newSVpvn(tstart, s - tstart);
12303     }
12304 #endif
12305     s += SvCUR(herewas);
12306
12307 #ifdef PERL_MAD
12308     stuffstart = s - SvPVX(PL_linestr);
12309
12310     if (found_newline)
12311         s--;
12312 #endif
12313
12314     tmpstr = newSV_type(SVt_PVIV);
12315     SvGROW(tmpstr, 80);
12316     if (term == '\'') {
12317         op_type = OP_CONST;
12318         SvIV_set(tmpstr, -1);
12319     }
12320     else if (term == '`') {
12321         op_type = OP_BACKTICK;
12322         SvIV_set(tmpstr, '\\');
12323     }
12324
12325     CLINE;
12326     PL_multi_start = CopLINE(PL_curcop);
12327     PL_multi_open = PL_multi_close = '<';
12328     term = *PL_tokenbuf;
12329     if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
12330         char * const bufptr = PL_sublex_info.super_bufptr;
12331         char * const bufend = PL_sublex_info.super_bufend;
12332         char * const olds = s - SvCUR(herewas);
12333         s = strchr(bufptr, '\n');
12334         if (!s)
12335             s = bufend;
12336         d = s;
12337         while (s < bufend &&
12338           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
12339             if (*s++ == '\n')
12340                 CopLINE_inc(PL_curcop);
12341         }
12342         if (s >= bufend) {
12343             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
12344             missingterm(PL_tokenbuf);
12345         }
12346         sv_setpvn(herewas,bufptr,d-bufptr+1);
12347         sv_setpvn(tmpstr,d+1,s-d);
12348         s += len - 1;
12349         sv_catpvn(herewas,s,bufend-s);
12350         Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
12351
12352         s = olds;
12353         goto retval;
12354     }
12355     else if (!outer) {
12356         d = s;
12357         while (s < PL_bufend &&
12358           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
12359             if (*s++ == '\n')
12360                 CopLINE_inc(PL_curcop);
12361         }
12362         if (s >= PL_bufend) {
12363             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
12364             missingterm(PL_tokenbuf);
12365         }
12366         sv_setpvn(tmpstr,d+1,s-d);
12367 #ifdef PERL_MAD
12368         if (PL_madskills) {
12369             if (PL_thisstuff)
12370                 sv_catpvn(PL_thisstuff, d + 1, s - d);
12371             else
12372                 PL_thisstuff = newSVpvn(d + 1, s - d);
12373             stuffstart = s - SvPVX(PL_linestr);
12374         }
12375 #endif
12376         s += len - 1;
12377         CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
12378
12379         sv_catpvn(herewas,s,PL_bufend-s);
12380         sv_setsv(PL_linestr,herewas);
12381         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
12382         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12383         PL_last_lop = PL_last_uni = NULL;
12384     }
12385     else
12386         sv_setpvs(tmpstr,"");   /* avoid "uninitialized" warning */
12387     while (s >= PL_bufend) {    /* multiple line string? */
12388 #ifdef PERL_MAD
12389         if (PL_madskills) {
12390             tstart = SvPVX(PL_linestr) + stuffstart;
12391             if (PL_thisstuff)
12392                 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
12393             else
12394                 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
12395         }
12396 #endif
12397         PL_bufptr = s;
12398         CopLINE_inc(PL_curcop);
12399         if (!outer || !lex_next_chunk(0)) {
12400             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
12401             missingterm(PL_tokenbuf);
12402         }
12403         CopLINE_dec(PL_curcop);
12404         s = PL_bufptr;
12405 #ifdef PERL_MAD
12406         stuffstart = s - SvPVX(PL_linestr);
12407 #endif
12408         CopLINE_inc(PL_curcop);
12409         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12410         PL_last_lop = PL_last_uni = NULL;
12411 #ifndef PERL_STRICT_CR
12412         if (PL_bufend - PL_linestart >= 2) {
12413             if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
12414                 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
12415             {
12416                 PL_bufend[-2] = '\n';
12417                 PL_bufend--;
12418                 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
12419             }
12420             else if (PL_bufend[-1] == '\r')
12421                 PL_bufend[-1] = '\n';
12422         }
12423         else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
12424             PL_bufend[-1] = '\n';
12425 #endif
12426         if (*s == term && memEQ(s,PL_tokenbuf,len)) {
12427             STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
12428             *(SvPVX(PL_linestr) + off ) = ' ';
12429             sv_catsv(PL_linestr,herewas);
12430             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12431             s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
12432         }
12433         else {
12434             s = PL_bufend;
12435             sv_catsv(tmpstr,PL_linestr);
12436         }
12437     }
12438     s++;
12439 retval:
12440     PL_multi_end = CopLINE(PL_curcop);
12441     if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
12442         SvPV_shrink_to_cur(tmpstr);
12443     }
12444     SvREFCNT_dec(herewas);
12445     if (!IN_BYTES) {
12446         if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
12447             SvUTF8_on(tmpstr);
12448         else if (PL_encoding)
12449             sv_recode_to_utf8(tmpstr, PL_encoding);
12450     }
12451     PL_lex_stuff = tmpstr;
12452     pl_yylval.ival = op_type;
12453     return s;
12454 }
12455
12456 /* scan_inputsymbol
12457    takes: current position in input buffer
12458    returns: new position in input buffer
12459    side-effects: pl_yylval and lex_op are set.
12460
12461    This code handles:
12462
12463    <>           read from ARGV
12464    <FH>         read from filehandle
12465    <pkg::FH>    read from package qualified filehandle
12466    <pkg'FH>     read from package qualified filehandle
12467    <$fh>        read from filehandle in $fh
12468    <*.h>        filename glob
12469
12470 */
12471
12472 STATIC char *
12473 S_scan_inputsymbol(pTHX_ char *start)
12474 {
12475     dVAR;
12476     register char *s = start;           /* current position in buffer */
12477     char *end;
12478     I32 len;
12479     char *d = PL_tokenbuf;                                      /* start of temp holding space */
12480     const char * const e = PL_tokenbuf + sizeof PL_tokenbuf;    /* end of temp holding space */
12481
12482     PERL_ARGS_ASSERT_SCAN_INPUTSYMBOL;
12483
12484     end = strchr(s, '\n');
12485     if (!end)
12486         end = PL_bufend;
12487     s = delimcpy(d, e, s + 1, end, '>', &len);  /* extract until > */
12488
12489     /* die if we didn't have space for the contents of the <>,
12490        or if it didn't end, or if we see a newline
12491     */
12492
12493     if (len >= (I32)sizeof PL_tokenbuf)
12494         Perl_croak(aTHX_ "Excessively long <> operator");
12495     if (s >= end)
12496         Perl_croak(aTHX_ "Unterminated <> operator");
12497
12498     s++;
12499
12500     /* check for <$fh>
12501        Remember, only scalar variables are interpreted as filehandles by
12502        this code.  Anything more complex (e.g., <$fh{$num}>) will be
12503        treated as a glob() call.
12504        This code makes use of the fact that except for the $ at the front,
12505        a scalar variable and a filehandle look the same.
12506     */
12507     if (*d == '$' && d[1]) d++;
12508
12509     /* allow <Pkg'VALUE> or <Pkg::VALUE> */
12510     while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
12511         d++;
12512
12513     /* If we've tried to read what we allow filehandles to look like, and
12514        there's still text left, then it must be a glob() and not a getline.
12515        Use scan_str to pull out the stuff between the <> and treat it
12516        as nothing more than a string.
12517     */
12518
12519     if (d - PL_tokenbuf != len) {
12520         pl_yylval.ival = OP_GLOB;
12521         s = scan_str(start,!!PL_madskills,FALSE);
12522         if (!s)
12523            Perl_croak(aTHX_ "Glob not terminated");
12524         return s;
12525     }
12526     else {
12527         bool readline_overriden = FALSE;
12528         GV *gv_readline;
12529         GV **gvp;
12530         /* we're in a filehandle read situation */
12531         d = PL_tokenbuf;
12532
12533         /* turn <> into <ARGV> */
12534         if (!len)
12535             Copy("ARGV",d,5,char);
12536
12537         /* Check whether readline() is overriden */
12538         gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
12539         if ((gv_readline
12540                 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
12541                 ||
12542                 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
12543                  && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
12544                 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
12545             readline_overriden = TRUE;
12546
12547         /* if <$fh>, create the ops to turn the variable into a
12548            filehandle
12549         */
12550         if (*d == '$') {
12551             /* try to find it in the pad for this block, otherwise find
12552                add symbol table ops
12553             */
12554             const PADOFFSET tmp = pad_findmy(d, len, 0);
12555             if (tmp != NOT_IN_PAD) {
12556                 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
12557                     HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
12558                     HEK * const stashname = HvNAME_HEK(stash);
12559                     SV * const sym = sv_2mortal(newSVhek(stashname));
12560                     sv_catpvs(sym, "::");
12561                     sv_catpv(sym, d+1);
12562                     d = SvPVX(sym);
12563                     goto intro_sym;
12564                 }
12565                 else {
12566                     OP * const o = newOP(OP_PADSV, 0);
12567                     o->op_targ = tmp;
12568                     PL_lex_op = readline_overriden
12569                         ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
12570                                 op_append_elem(OP_LIST, o,
12571                                     newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
12572                         : (OP*)newUNOP(OP_READLINE, 0, o);
12573                 }
12574             }
12575             else {
12576                 GV *gv;
12577                 ++d;
12578 intro_sym:
12579                 gv = gv_fetchpv(d,
12580                                 (PL_in_eval
12581                                  ? (GV_ADDMULTI | GV_ADDINEVAL)
12582                                  : GV_ADDMULTI),
12583                                 SVt_PV);
12584                 PL_lex_op = readline_overriden
12585                     ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
12586                             op_append_elem(OP_LIST,
12587                                 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
12588                                 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
12589                     : (OP*)newUNOP(OP_READLINE, 0,
12590                             newUNOP(OP_RV2SV, 0,
12591                                 newGVOP(OP_GV, 0, gv)));
12592             }
12593             if (!readline_overriden)
12594                 PL_lex_op->op_flags |= OPf_SPECIAL;
12595             /* we created the ops in PL_lex_op, so make pl_yylval.ival a null op */
12596             pl_yylval.ival = OP_NULL;
12597         }
12598
12599         /* If it's none of the above, it must be a literal filehandle
12600            (<Foo::BAR> or <FOO>) so build a simple readline OP */
12601         else {
12602             GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
12603             PL_lex_op = readline_overriden
12604                 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
12605                         op_append_elem(OP_LIST,
12606                             newGVOP(OP_GV, 0, gv),
12607                             newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
12608                 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
12609             pl_yylval.ival = OP_NULL;
12610         }
12611     }
12612
12613     return s;
12614 }
12615
12616
12617 /* scan_str
12618    takes: start position in buffer
12619           keep_quoted preserve \ on the embedded delimiter(s)
12620           keep_delims preserve the delimiters around the string
12621    returns: position to continue reading from buffer
12622    side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
12623         updates the read buffer.
12624
12625    This subroutine pulls a string out of the input.  It is called for:
12626         q               single quotes           q(literal text)
12627         '               single quotes           'literal text'
12628         qq              double quotes           qq(interpolate $here please)
12629         "               double quotes           "interpolate $here please"
12630         qx              backticks               qx(/bin/ls -l)
12631         `               backticks               `/bin/ls -l`
12632         qw              quote words             @EXPORT_OK = qw( func() $spam )
12633         m//             regexp match            m/this/
12634         s///            regexp substitute       s/this/that/
12635         tr///           string transliterate    tr/this/that/
12636         y///            string transliterate    y/this/that/
12637         ($*@)           sub prototypes          sub foo ($)
12638         (stuff)         sub attr parameters     sub foo : attr(stuff)
12639         <>              readline or globs       <FOO>, <>, <$fh>, or <*.c>
12640         
12641    In most of these cases (all but <>, patterns and transliterate)
12642    yylex() calls scan_str().  m// makes yylex() call scan_pat() which
12643    calls scan_str().  s/// makes yylex() call scan_subst() which calls
12644    scan_str().  tr/// and y/// make yylex() call scan_trans() which
12645    calls scan_str().
12646
12647    It skips whitespace before the string starts, and treats the first
12648    character as the delimiter.  If the delimiter is one of ([{< then
12649    the corresponding "close" character )]}> is used as the closing
12650    delimiter.  It allows quoting of delimiters, and if the string has
12651    balanced delimiters ([{<>}]) it allows nesting.
12652
12653    On success, the SV with the resulting string is put into lex_stuff or,
12654    if that is already non-NULL, into lex_repl. The second case occurs only
12655    when parsing the RHS of the special constructs s/// and tr/// (y///).
12656    For convenience, the terminating delimiter character is stuffed into
12657    SvIVX of the SV.
12658 */
12659
12660 STATIC char *
12661 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
12662 {
12663     dVAR;
12664     SV *sv;                             /* scalar value: string */
12665     const char *tmps;                   /* temp string, used for delimiter matching */
12666     register char *s = start;           /* current position in the buffer */
12667     register char term;                 /* terminating character */
12668     register char *to;                  /* current position in the sv's data */
12669     I32 brackets = 1;                   /* bracket nesting level */
12670     bool has_utf8 = FALSE;              /* is there any utf8 content? */
12671     I32 termcode;                       /* terminating char. code */
12672     U8 termstr[UTF8_MAXBYTES];          /* terminating string */
12673     STRLEN termlen;                     /* length of terminating string */
12674     int last_off = 0;                   /* last position for nesting bracket */
12675 #ifdef PERL_MAD
12676     int stuffstart;
12677     char *tstart;
12678 #endif
12679
12680     PERL_ARGS_ASSERT_SCAN_STR;
12681
12682     /* skip space before the delimiter */
12683     if (isSPACE(*s)) {
12684         s = PEEKSPACE(s);
12685     }
12686
12687 #ifdef PERL_MAD
12688     if (PL_realtokenstart >= 0) {
12689         stuffstart = PL_realtokenstart;
12690         PL_realtokenstart = -1;
12691     }
12692     else
12693         stuffstart = start - SvPVX(PL_linestr);
12694 #endif
12695     /* mark where we are, in case we need to report errors */
12696     CLINE;
12697
12698     /* after skipping whitespace, the next character is the terminator */
12699     term = *s;
12700     if (!UTF) {
12701         termcode = termstr[0] = term;
12702         termlen = 1;
12703     }
12704     else {
12705         termcode = utf8_to_uvchr((U8*)s, &termlen);
12706         Copy(s, termstr, termlen, U8);
12707         if (!UTF8_IS_INVARIANT(term))
12708             has_utf8 = TRUE;
12709     }
12710
12711     /* mark where we are */
12712     PL_multi_start = CopLINE(PL_curcop);
12713     PL_multi_open = term;
12714
12715     /* find corresponding closing delimiter */
12716     if (term && (tmps = strchr("([{< )]}> )]}>",term)))
12717         termcode = termstr[0] = term = tmps[5];
12718
12719     PL_multi_close = term;
12720
12721     /* create a new SV to hold the contents.  79 is the SV's initial length.
12722        What a random number. */
12723     sv = newSV_type(SVt_PVIV);
12724     SvGROW(sv, 80);
12725     SvIV_set(sv, termcode);
12726     (void)SvPOK_only(sv);               /* validate pointer */
12727
12728     /* move past delimiter and try to read a complete string */
12729     if (keep_delims)
12730         sv_catpvn(sv, s, termlen);
12731     s += termlen;
12732 #ifdef PERL_MAD
12733     tstart = SvPVX(PL_linestr) + stuffstart;
12734     if (!PL_thisopen && !keep_delims) {
12735         PL_thisopen = newSVpvn(tstart, s - tstart);
12736         stuffstart = s - SvPVX(PL_linestr);
12737     }
12738 #endif
12739     for (;;) {
12740         if (PL_encoding && !UTF) {
12741             bool cont = TRUE;
12742
12743             while (cont) {
12744                 int offset = s - SvPVX_const(PL_linestr);
12745                 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
12746                                            &offset, (char*)termstr, termlen);
12747                 const char * const ns = SvPVX_const(PL_linestr) + offset;
12748                 char * const svlast = SvEND(sv) - 1;
12749
12750                 for (; s < ns; s++) {
12751                     if (*s == '\n' && !PL_rsfp)
12752                         CopLINE_inc(PL_curcop);
12753                 }
12754                 if (!found)
12755                     goto read_more_line;
12756                 else {
12757                     /* handle quoted delimiters */
12758                     if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
12759                         const char *t;
12760                         for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
12761                             t--;
12762                         if ((svlast-1 - t) % 2) {
12763                             if (!keep_quoted) {
12764                                 *(svlast-1) = term;
12765                                 *svlast = '\0';
12766                                 SvCUR_set(sv, SvCUR(sv) - 1);
12767                             }
12768                             continue;
12769                         }
12770                     }
12771                     if (PL_multi_open == PL_multi_close) {
12772                         cont = FALSE;
12773                     }
12774                     else {
12775                         const char *t;
12776                         char *w;
12777                         for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
12778                             /* At here, all closes are "was quoted" one,
12779                                so we don't check PL_multi_close. */
12780                             if (*t == '\\') {
12781                                 if (!keep_quoted && *(t+1) == PL_multi_open)
12782                                     t++;
12783                                 else
12784                                     *w++ = *t++;
12785                             }
12786                             else if (*t == PL_multi_open)
12787                                 brackets++;
12788
12789                             *w = *t;
12790                         }
12791                         if (w < t) {
12792                             *w++ = term;
12793                             *w = '\0';
12794                             SvCUR_set(sv, w - SvPVX_const(sv));
12795                         }
12796                         last_off = w - SvPVX(sv);
12797                         if (--brackets <= 0)
12798                             cont = FALSE;
12799                     }
12800                 }
12801             }
12802             if (!keep_delims) {
12803                 SvCUR_set(sv, SvCUR(sv) - 1);
12804                 *SvEND(sv) = '\0';
12805             }
12806             break;
12807         }
12808
12809         /* extend sv if need be */
12810         SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
12811         /* set 'to' to the next character in the sv's string */
12812         to = SvPVX(sv)+SvCUR(sv);
12813
12814         /* if open delimiter is the close delimiter read unbridle */
12815         if (PL_multi_open == PL_multi_close) {
12816             for (; s < PL_bufend; s++,to++) {
12817                 /* embedded newlines increment the current line number */
12818                 if (*s == '\n' && !PL_rsfp)
12819                     CopLINE_inc(PL_curcop);
12820                 /* handle quoted delimiters */
12821                 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
12822                     if (!keep_quoted && s[1] == term)
12823                         s++;
12824                 /* any other quotes are simply copied straight through */
12825                     else
12826                         *to++ = *s++;
12827                 }
12828                 /* terminate when run out of buffer (the for() condition), or
12829                    have found the terminator */
12830                 else if (*s == term) {
12831                     if (termlen == 1)
12832                         break;
12833                     if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
12834                         break;
12835                 }
12836                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
12837                     has_utf8 = TRUE;
12838                 *to = *s;
12839             }
12840         }
12841         
12842         /* if the terminator isn't the same as the start character (e.g.,
12843            matched brackets), we have to allow more in the quoting, and
12844            be prepared for nested brackets.
12845         */
12846         else {
12847             /* read until we run out of string, or we find the terminator */
12848             for (; s < PL_bufend; s++,to++) {
12849                 /* embedded newlines increment the line count */
12850                 if (*s == '\n' && !PL_rsfp)
12851                     CopLINE_inc(PL_curcop);
12852                 /* backslashes can escape the open or closing characters */
12853                 if (*s == '\\' && s+1 < PL_bufend) {
12854                     if (!keep_quoted &&
12855                         ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
12856                         s++;
12857                     else
12858                         *to++ = *s++;
12859                 }
12860                 /* allow nested opens and closes */
12861                 else if (*s == PL_multi_close && --brackets <= 0)
12862                     break;
12863                 else if (*s == PL_multi_open)
12864                     brackets++;
12865                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
12866                     has_utf8 = TRUE;
12867                 *to = *s;
12868             }
12869         }
12870         /* terminate the copied string and update the sv's end-of-string */
12871         *to = '\0';
12872         SvCUR_set(sv, to - SvPVX_const(sv));
12873
12874         /*
12875          * this next chunk reads more into the buffer if we're not done yet
12876          */
12877
12878         if (s < PL_bufend)
12879             break;              /* handle case where we are done yet :-) */
12880
12881 #ifndef PERL_STRICT_CR
12882         if (to - SvPVX_const(sv) >= 2) {
12883             if ((to[-2] == '\r' && to[-1] == '\n') ||
12884                 (to[-2] == '\n' && to[-1] == '\r'))
12885             {
12886                 to[-2] = '\n';
12887                 to--;
12888                 SvCUR_set(sv, to - SvPVX_const(sv));
12889             }
12890             else if (to[-1] == '\r')
12891                 to[-1] = '\n';
12892         }
12893         else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
12894             to[-1] = '\n';
12895 #endif
12896         
12897      read_more_line:
12898         /* if we're out of file, or a read fails, bail and reset the current
12899            line marker so we can report where the unterminated string began
12900         */
12901 #ifdef PERL_MAD
12902         if (PL_madskills) {
12903             char * const tstart = SvPVX(PL_linestr) + stuffstart;
12904             if (PL_thisstuff)
12905                 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
12906             else
12907                 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
12908         }
12909 #endif
12910         CopLINE_inc(PL_curcop);
12911         PL_bufptr = PL_bufend;
12912         if (!lex_next_chunk(0)) {
12913             sv_free(sv);
12914             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
12915             return NULL;
12916         }
12917         s = PL_bufptr;
12918 #ifdef PERL_MAD
12919         stuffstart = 0;
12920 #endif
12921     }
12922
12923     /* at this point, we have successfully read the delimited string */
12924
12925     if (!PL_encoding || UTF) {
12926 #ifdef PERL_MAD
12927         if (PL_madskills) {
12928             char * const tstart = SvPVX(PL_linestr) + stuffstart;
12929             const int len = s - tstart;
12930             if (PL_thisstuff)
12931                 sv_catpvn(PL_thisstuff, tstart, len);
12932             else
12933                 PL_thisstuff = newSVpvn(tstart, len);
12934             if (!PL_thisclose && !keep_delims)
12935                 PL_thisclose = newSVpvn(s,termlen);
12936         }
12937 #endif
12938
12939         if (keep_delims)
12940             sv_catpvn(sv, s, termlen);
12941         s += termlen;
12942     }
12943 #ifdef PERL_MAD
12944     else {
12945         if (PL_madskills) {
12946             char * const tstart = SvPVX(PL_linestr) + stuffstart;
12947             const int len = s - tstart - termlen;
12948             if (PL_thisstuff)
12949                 sv_catpvn(PL_thisstuff, tstart, len);
12950             else
12951                 PL_thisstuff = newSVpvn(tstart, len);
12952             if (!PL_thisclose && !keep_delims)
12953                 PL_thisclose = newSVpvn(s - termlen,termlen);
12954         }
12955     }
12956 #endif
12957     if (has_utf8 || PL_encoding)
12958         SvUTF8_on(sv);
12959
12960     PL_multi_end = CopLINE(PL_curcop);
12961
12962     /* if we allocated too much space, give some back */
12963     if (SvCUR(sv) + 5 < SvLEN(sv)) {
12964         SvLEN_set(sv, SvCUR(sv) + 1);
12965         SvPV_renew(sv, SvLEN(sv));
12966     }
12967
12968     /* decide whether this is the first or second quoted string we've read
12969        for this op
12970     */
12971
12972     if (PL_lex_stuff)
12973         PL_lex_repl = sv;
12974     else
12975         PL_lex_stuff = sv;
12976     return s;
12977 }
12978
12979 /*
12980   scan_num
12981   takes: pointer to position in buffer
12982   returns: pointer to new position in buffer
12983   side-effects: builds ops for the constant in pl_yylval.op
12984
12985   Read a number in any of the formats that Perl accepts:
12986
12987   \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*)      12 12.34 12.
12988   \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*)                     .34
12989   0b[01](_?[01])*
12990   0[0-7](_?[0-7])*
12991   0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
12992
12993   Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
12994   thing it reads.
12995
12996   If it reads a number without a decimal point or an exponent, it will
12997   try converting the number to an integer and see if it can do so
12998   without loss of precision.
12999 */
13000
13001 char *
13002 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
13003 {
13004     dVAR;
13005     register const char *s = start;     /* current position in buffer */
13006     register char *d;                   /* destination in temp buffer */
13007     register char *e;                   /* end of temp buffer */
13008     NV nv;                              /* number read, as a double */
13009     SV *sv = NULL;                      /* place to put the converted number */
13010     bool floatit;                       /* boolean: int or float? */
13011     const char *lastub = NULL;          /* position of last underbar */
13012     static char const number_too_long[] = "Number too long";
13013
13014     PERL_ARGS_ASSERT_SCAN_NUM;
13015
13016     /* We use the first character to decide what type of number this is */
13017
13018     switch (*s) {
13019     default:
13020       Perl_croak(aTHX_ "panic: scan_num");
13021
13022     /* if it starts with a 0, it could be an octal number, a decimal in
13023        0.13 disguise, or a hexadecimal number, or a binary number. */
13024     case '0':
13025         {
13026           /* variables:
13027              u          holds the "number so far"
13028              shift      the power of 2 of the base
13029                         (hex == 4, octal == 3, binary == 1)
13030              overflowed was the number more than we can hold?
13031
13032              Shift is used when we add a digit.  It also serves as an "are
13033              we in octal/hex/binary?" indicator to disallow hex characters
13034              when in octal mode.
13035            */
13036             NV n = 0.0;
13037             UV u = 0;
13038             I32 shift;
13039             bool overflowed = FALSE;
13040             bool just_zero  = TRUE;     /* just plain 0 or binary number? */
13041             static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
13042             static const char* const bases[5] =
13043               { "", "binary", "", "octal", "hexadecimal" };
13044             static const char* const Bases[5] =
13045               { "", "Binary", "", "Octal", "Hexadecimal" };
13046             static const char* const maxima[5] =
13047               { "",
13048                 "0b11111111111111111111111111111111",
13049                 "",
13050                 "037777777777",
13051                 "0xffffffff" };
13052             const char *base, *Base, *max;
13053
13054             /* check for hex */
13055             if (s[1] == 'x' || s[1] == 'X') {
13056                 shift = 4;
13057                 s += 2;
13058                 just_zero = FALSE;
13059             } else if (s[1] == 'b' || s[1] == 'B') {
13060                 shift = 1;
13061                 s += 2;
13062                 just_zero = FALSE;
13063             }
13064             /* check for a decimal in disguise */
13065             else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
13066                 goto decimal;
13067             /* so it must be octal */
13068             else {
13069                 shift = 3;
13070                 s++;
13071             }
13072
13073             if (*s == '_') {
13074                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13075                                "Misplaced _ in number");
13076                lastub = s++;
13077             }
13078
13079             base = bases[shift];
13080             Base = Bases[shift];
13081             max  = maxima[shift];
13082
13083             /* read the rest of the number */
13084             for (;;) {
13085                 /* x is used in the overflow test,
13086                    b is the digit we're adding on. */
13087                 UV x, b;
13088
13089                 switch (*s) {
13090
13091                 /* if we don't mention it, we're done */
13092                 default:
13093                     goto out;
13094
13095                 /* _ are ignored -- but warned about if consecutive */
13096                 case '_':
13097                     if (lastub && s == lastub + 1)
13098                         Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13099                                        "Misplaced _ in number");
13100                     lastub = s++;
13101                     break;
13102
13103                 /* 8 and 9 are not octal */
13104                 case '8': case '9':
13105                     if (shift == 3)
13106                         yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
13107                     /* FALL THROUGH */
13108
13109                 /* octal digits */
13110                 case '2': case '3': case '4':
13111                 case '5': case '6': case '7':
13112                     if (shift == 1)
13113                         yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
13114                     /* FALL THROUGH */
13115
13116                 case '0': case '1':
13117                     b = *s++ & 15;              /* ASCII digit -> value of digit */
13118                     goto digit;
13119
13120                 /* hex digits */
13121                 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
13122                 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
13123                     /* make sure they said 0x */
13124                     if (shift != 4)
13125                         goto out;
13126                     b = (*s++ & 7) + 9;
13127
13128                     /* Prepare to put the digit we have onto the end
13129                        of the number so far.  We check for overflows.
13130                     */
13131
13132                   digit:
13133                     just_zero = FALSE;
13134                     if (!overflowed) {
13135                         x = u << shift; /* make room for the digit */
13136
13137                         if ((x >> shift) != u
13138                             && !(PL_hints & HINT_NEW_BINARY)) {
13139                             overflowed = TRUE;
13140                             n = (NV) u;
13141                             Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
13142                                              "Integer overflow in %s number",
13143                                              base);
13144                         } else
13145                             u = x | b;          /* add the digit to the end */
13146                     }
13147                     if (overflowed) {
13148                         n *= nvshift[shift];
13149                         /* If an NV has not enough bits in its
13150                          * mantissa to represent an UV this summing of
13151                          * small low-order numbers is a waste of time
13152                          * (because the NV cannot preserve the
13153                          * low-order bits anyway): we could just
13154                          * remember when did we overflow and in the
13155                          * end just multiply n by the right
13156                          * amount. */
13157                         n += (NV) b;
13158                     }
13159                     break;
13160                 }
13161             }
13162
13163           /* if we get here, we had success: make a scalar value from
13164              the number.
13165           */
13166           out:
13167
13168             /* final misplaced underbar check */
13169             if (s[-1] == '_') {
13170                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
13171             }
13172
13173             if (overflowed) {
13174                 if (n > 4294967295.0)
13175                     Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
13176                                    "%s number > %s non-portable",
13177                                    Base, max);
13178                 sv = newSVnv(n);
13179             }
13180             else {
13181 #if UVSIZE > 4
13182                 if (u > 0xffffffff)
13183                     Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
13184                                    "%s number > %s non-portable",
13185                                    Base, max);
13186 #endif
13187                 sv = newSVuv(u);
13188             }
13189             if (just_zero && (PL_hints & HINT_NEW_INTEGER))
13190                 sv = new_constant(start, s - start, "integer",
13191                                   sv, NULL, NULL, 0);
13192             else if (PL_hints & HINT_NEW_BINARY)
13193                 sv = new_constant(start, s - start, "binary", sv, NULL, NULL, 0);
13194         }
13195         break;
13196
13197     /*
13198       handle decimal numbers.
13199       we're also sent here when we read a 0 as the first digit
13200     */
13201     case '1': case '2': case '3': case '4': case '5':
13202     case '6': case '7': case '8': case '9': case '.':
13203       decimal:
13204         d = PL_tokenbuf;
13205         e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
13206         floatit = FALSE;
13207
13208         /* read next group of digits and _ and copy into d */
13209         while (isDIGIT(*s) || *s == '_') {
13210             /* skip underscores, checking for misplaced ones
13211                if -w is on
13212             */
13213             if (*s == '_') {
13214                 if (lastub && s == lastub + 1)
13215                     Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13216                                    "Misplaced _ in number");
13217                 lastub = s++;
13218             }
13219             else {
13220                 /* check for end of fixed-length buffer */
13221                 if (d >= e)
13222                     Perl_croak(aTHX_ number_too_long);
13223                 /* if we're ok, copy the character */
13224                 *d++ = *s++;
13225             }
13226         }
13227
13228         /* final misplaced underbar check */
13229         if (lastub && s == lastub + 1) {
13230             Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
13231         }
13232
13233         /* read a decimal portion if there is one.  avoid
13234            3..5 being interpreted as the number 3. followed
13235            by .5
13236         */
13237         if (*s == '.' && s[1] != '.') {
13238             floatit = TRUE;
13239             *d++ = *s++;
13240
13241             if (*s == '_') {
13242                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13243                                "Misplaced _ in number");
13244                 lastub = s;
13245             }
13246
13247             /* copy, ignoring underbars, until we run out of digits.
13248             */
13249             for (; isDIGIT(*s) || *s == '_'; s++) {
13250                 /* fixed length buffer check */
13251                 if (d >= e)
13252                     Perl_croak(aTHX_ number_too_long);
13253                 if (*s == '_') {
13254                    if (lastub && s == lastub + 1)
13255                        Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13256                                       "Misplaced _ in number");
13257                    lastub = s;
13258                 }
13259                 else
13260                     *d++ = *s;
13261             }
13262             /* fractional part ending in underbar? */
13263             if (s[-1] == '_') {
13264                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13265                                "Misplaced _ in number");
13266             }
13267             if (*s == '.' && isDIGIT(s[1])) {
13268                 /* oops, it's really a v-string, but without the "v" */
13269                 s = start;
13270                 goto vstring;
13271             }
13272         }
13273
13274         /* read exponent part, if present */
13275         if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
13276             floatit = TRUE;
13277             s++;
13278
13279             /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
13280             *d++ = 'e';         /* At least some Mach atof()s don't grok 'E' */
13281
13282             /* stray preinitial _ */
13283             if (*s == '_') {
13284                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13285                                "Misplaced _ in number");
13286                 lastub = s++;
13287             }
13288
13289             /* allow positive or negative exponent */
13290             if (*s == '+' || *s == '-')
13291                 *d++ = *s++;
13292
13293             /* stray initial _ */
13294             if (*s == '_') {
13295                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13296                                "Misplaced _ in number");
13297                 lastub = s++;
13298             }
13299
13300             /* read digits of exponent */
13301             while (isDIGIT(*s) || *s == '_') {
13302                 if (isDIGIT(*s)) {
13303                     if (d >= e)
13304                         Perl_croak(aTHX_ number_too_long);
13305                     *d++ = *s++;
13306                 }
13307                 else {
13308                    if (((lastub && s == lastub + 1) ||
13309                         (!isDIGIT(s[1]) && s[1] != '_')))
13310                        Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13311                                       "Misplaced _ in number");
13312                    lastub = s++;
13313                 }
13314             }
13315         }
13316
13317
13318         /*
13319            We try to do an integer conversion first if no characters
13320            indicating "float" have been found.
13321          */
13322
13323         if (!floatit) {
13324             UV uv;
13325             const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
13326
13327             if (flags == IS_NUMBER_IN_UV) {
13328               if (uv <= IV_MAX)
13329                 sv = newSViv(uv); /* Prefer IVs over UVs. */
13330               else
13331                 sv = newSVuv(uv);
13332             } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
13333               if (uv <= (UV) IV_MIN)
13334                 sv = newSViv(-(IV)uv);
13335               else
13336                 floatit = TRUE;
13337             } else
13338               floatit = TRUE;
13339         }
13340         if (floatit) {
13341             /* terminate the string */
13342             *d = '\0';
13343             nv = Atof(PL_tokenbuf);
13344             sv = newSVnv(nv);
13345         }
13346
13347         if ( floatit
13348              ? (PL_hints & HINT_NEW_FLOAT) : (PL_hints & HINT_NEW_INTEGER) ) {
13349             const char *const key = floatit ? "float" : "integer";
13350             const STRLEN keylen = floatit ? 5 : 7;
13351             sv = S_new_constant(aTHX_ PL_tokenbuf, d - PL_tokenbuf,
13352                                 key, keylen, sv, NULL, NULL, 0);
13353         }
13354         break;
13355
13356     /* if it starts with a v, it could be a v-string */
13357     case 'v':
13358 vstring:
13359                 sv = newSV(5); /* preallocate storage space */
13360                 s = scan_vstring(s, PL_bufend, sv);
13361         break;
13362     }
13363
13364     /* make the op for the constant and return */
13365
13366     if (sv)
13367         lvalp->opval = newSVOP(OP_CONST, 0, sv);
13368     else
13369         lvalp->opval = NULL;
13370
13371     return (char *)s;
13372 }
13373
13374 STATIC char *
13375 S_scan_formline(pTHX_ register char *s)
13376 {
13377     dVAR;
13378     register char *eol;
13379     register char *t;
13380     SV * const stuff = newSVpvs("");
13381     bool needargs = FALSE;
13382     bool eofmt = FALSE;
13383 #ifdef PERL_MAD
13384     char *tokenstart = s;
13385     SV* savewhite = NULL;
13386
13387     if (PL_madskills) {
13388         savewhite = PL_thiswhite;
13389         PL_thiswhite = 0;
13390     }
13391 #endif
13392
13393     PERL_ARGS_ASSERT_SCAN_FORMLINE;
13394
13395     while (!needargs) {
13396         if (*s == '.') {
13397             t = s+1;
13398 #ifdef PERL_STRICT_CR
13399             while (SPACE_OR_TAB(*t))
13400                 t++;
13401 #else
13402             while (SPACE_OR_TAB(*t) || *t == '\r')
13403                 t++;
13404 #endif
13405             if (*t == '\n' || t == PL_bufend) {
13406                 eofmt = TRUE;
13407                 break;
13408             }
13409         }
13410         if (PL_in_eval && !PL_rsfp) {
13411             eol = (char *) memchr(s,'\n',PL_bufend-s);
13412             if (!eol++)
13413                 eol = PL_bufend;
13414         }
13415         else
13416             eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
13417         if (*s != '#') {
13418             for (t = s; t < eol; t++) {
13419                 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
13420                     needargs = FALSE;
13421                     goto enough;        /* ~~ must be first line in formline */
13422                 }
13423                 if (*t == '@' || *t == '^')
13424                     needargs = TRUE;
13425             }
13426             if (eol > s) {
13427                 sv_catpvn(stuff, s, eol-s);
13428 #ifndef PERL_STRICT_CR
13429                 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
13430                     char *end = SvPVX(stuff) + SvCUR(stuff);
13431                     end[-2] = '\n';
13432                     end[-1] = '\0';
13433                     SvCUR_set(stuff, SvCUR(stuff) - 1);
13434                 }
13435 #endif
13436             }
13437             else
13438               break;
13439         }
13440         s = (char*)eol;
13441         if (PL_rsfp) {
13442             bool got_some;
13443 #ifdef PERL_MAD
13444             if (PL_madskills) {
13445                 if (PL_thistoken)
13446                     sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
13447                 else
13448                     PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
13449             }
13450 #endif
13451             PL_bufptr = PL_bufend;
13452             CopLINE_inc(PL_curcop);
13453             got_some = lex_next_chunk(0);
13454             CopLINE_dec(PL_curcop);
13455             s = PL_bufptr;
13456 #ifdef PERL_MAD
13457             tokenstart = PL_bufptr;
13458 #endif
13459             if (!got_some)
13460                 break;
13461         }
13462         incline(s);
13463     }
13464   enough:
13465     if (SvCUR(stuff)) {
13466         PL_expect = XTERM;
13467         if (needargs) {
13468             PL_lex_state = LEX_NORMAL;
13469             start_force(PL_curforce);
13470             NEXTVAL_NEXTTOKE.ival = 0;
13471             force_next(',');
13472         }
13473         else
13474             PL_lex_state = LEX_FORMLINE;
13475         if (!IN_BYTES) {
13476             if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
13477                 SvUTF8_on(stuff);
13478             else if (PL_encoding)
13479                 sv_recode_to_utf8(stuff, PL_encoding);
13480         }
13481         start_force(PL_curforce);
13482         NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
13483         force_next(THING);
13484         start_force(PL_curforce);
13485         NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
13486         force_next(LSTOP);
13487     }
13488     else {
13489         SvREFCNT_dec(stuff);
13490         if (eofmt)
13491             PL_lex_formbrack = 0;
13492         PL_bufptr = s;
13493     }
13494 #ifdef PERL_MAD
13495     if (PL_madskills) {
13496         if (PL_thistoken)
13497             sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
13498         else
13499             PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
13500         PL_thiswhite = savewhite;
13501     }
13502 #endif
13503     return s;
13504 }
13505
13506 I32
13507 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
13508 {
13509     dVAR;
13510     const I32 oldsavestack_ix = PL_savestack_ix;
13511     CV* const outsidecv = PL_compcv;
13512
13513     if (PL_compcv) {
13514         assert(SvTYPE(PL_compcv) == SVt_PVCV);
13515     }
13516     SAVEI32(PL_subline);
13517     save_item(PL_subname);
13518     SAVESPTR(PL_compcv);
13519
13520     PL_compcv = MUTABLE_CV(newSV_type(is_format ? SVt_PVFM : SVt_PVCV));
13521     CvFLAGS(PL_compcv) |= flags;
13522
13523     PL_subline = CopLINE(PL_curcop);
13524     CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
13525     CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv));
13526     CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
13527
13528     return oldsavestack_ix;
13529 }
13530
13531 #ifdef __SC__
13532 #pragma segment Perl_yylex
13533 #endif
13534 static int
13535 S_yywarn(pTHX_ const char *const s)
13536 {
13537     dVAR;
13538
13539     PERL_ARGS_ASSERT_YYWARN;
13540
13541     PL_in_eval |= EVAL_WARNONLY;
13542     yyerror(s);
13543     PL_in_eval &= ~EVAL_WARNONLY;
13544     return 0;
13545 }
13546
13547 int
13548 Perl_yyerror(pTHX_ const char *const s)
13549 {
13550     dVAR;
13551     const char *where = NULL;
13552     const char *context = NULL;
13553     int contlen = -1;
13554     SV *msg;
13555     int yychar  = PL_parser->yychar;
13556
13557     PERL_ARGS_ASSERT_YYERROR;
13558
13559     if (!yychar || (yychar == ';' && !PL_rsfp))
13560         where = "at EOF";
13561     else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
13562       PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
13563       PL_oldbufptr != PL_bufptr) {
13564         /*
13565                 Only for NetWare:
13566                 The code below is removed for NetWare because it abends/crashes on NetWare
13567                 when the script has error such as not having the closing quotes like:
13568                     if ($var eq "value)
13569                 Checking of white spaces is anyway done in NetWare code.
13570         */
13571 #ifndef NETWARE
13572         while (isSPACE(*PL_oldoldbufptr))
13573             PL_oldoldbufptr++;
13574 #endif
13575         context = PL_oldoldbufptr;
13576         contlen = PL_bufptr - PL_oldoldbufptr;
13577     }
13578     else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
13579       PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
13580         /*
13581                 Only for NetWare:
13582                 The code below is removed for NetWare because it abends/crashes on NetWare
13583                 when the script has error such as not having the closing quotes like:
13584                     if ($var eq "value)
13585                 Checking of white spaces is anyway done in NetWare code.
13586         */
13587 #ifndef NETWARE
13588         while (isSPACE(*PL_oldbufptr))
13589             PL_oldbufptr++;
13590 #endif
13591         context = PL_oldbufptr;
13592         contlen = PL_bufptr - PL_oldbufptr;
13593     }
13594     else if (yychar > 255)
13595         where = "next token ???";
13596     else if (yychar == -2) { /* YYEMPTY */
13597         if (PL_lex_state == LEX_NORMAL ||
13598            (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
13599             where = "at end of line";
13600         else if (PL_lex_inpat)
13601             where = "within pattern";
13602         else
13603             where = "within string";
13604     }
13605     else {
13606         SV * const where_sv = newSVpvs_flags("next char ", SVs_TEMP);
13607         if (yychar < 32)
13608             Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
13609         else if (isPRINT_LC(yychar)) {
13610             const char string = yychar;
13611             sv_catpvn(where_sv, &string, 1);
13612         }
13613         else
13614             Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
13615         where = SvPVX_const(where_sv);
13616     }
13617     msg = sv_2mortal(newSVpv(s, 0));
13618     Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
13619         OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
13620     if (context)
13621         Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
13622     else
13623         Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
13624     if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
13625         Perl_sv_catpvf(aTHX_ msg,
13626         "  (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
13627                 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
13628         PL_multi_end = 0;
13629     }
13630     if (PL_in_eval & EVAL_WARNONLY) {
13631         Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
13632     }
13633     else
13634         qerror(msg);
13635     if (PL_error_count >= 10) {
13636         if (PL_in_eval && SvCUR(ERRSV))
13637             Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
13638                        SVfARG(ERRSV), OutCopFILE(PL_curcop));
13639         else
13640             Perl_croak(aTHX_ "%s has too many errors.\n",
13641             OutCopFILE(PL_curcop));
13642     }
13643     PL_in_my = 0;
13644     PL_in_my_stash = NULL;
13645     return 0;
13646 }
13647 #ifdef __SC__
13648 #pragma segment Main
13649 #endif
13650
13651 STATIC char*
13652 S_swallow_bom(pTHX_ U8 *s)
13653 {
13654     dVAR;
13655     const STRLEN slen = SvCUR(PL_linestr);
13656
13657     PERL_ARGS_ASSERT_SWALLOW_BOM;
13658
13659     switch (s[0]) {
13660     case 0xFF:
13661         if (s[1] == 0xFE) {
13662             /* UTF-16 little-endian? (or UTF-32LE?) */
13663             if (s[2] == 0 && s[3] == 0)  /* UTF-32 little-endian */
13664                 Perl_croak(aTHX_ "Unsupported script encoding UTF-32LE");
13665 #ifndef PERL_NO_UTF16_FILTER
13666             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (BOM)\n");
13667             s += 2;
13668             if (PL_bufend > (char*)s) {
13669                 s = add_utf16_textfilter(s, TRUE);
13670             }
13671 #else
13672             Perl_croak(aTHX_ "Unsupported script encoding UTF-16LE");
13673 #endif
13674         }
13675         break;
13676     case 0xFE:
13677         if (s[1] == 0xFF) {   /* UTF-16 big-endian? */
13678 #ifndef PERL_NO_UTF16_FILTER
13679             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
13680             s += 2;
13681             if (PL_bufend > (char *)s) {
13682                 s = add_utf16_textfilter(s, FALSE);
13683             }
13684 #else
13685             Perl_croak(aTHX_ "Unsupported script encoding UTF-16BE");
13686 #endif
13687         }
13688         break;
13689     case 0xEF:
13690         if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
13691             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
13692             s += 3;                      /* UTF-8 */
13693         }
13694         break;
13695     case 0:
13696         if (slen > 3) {
13697              if (s[1] == 0) {
13698                   if (s[2] == 0xFE && s[3] == 0xFF) {
13699                        /* UTF-32 big-endian */
13700                        Perl_croak(aTHX_ "Unsupported script encoding UTF-32BE");
13701                   }
13702              }
13703              else if (s[2] == 0 && s[3] != 0) {
13704                   /* Leading bytes
13705                    * 00 xx 00 xx
13706                    * are a good indicator of UTF-16BE. */
13707 #ifndef PERL_NO_UTF16_FILTER
13708                   if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
13709                   s = add_utf16_textfilter(s, FALSE);
13710 #else
13711                   Perl_croak(aTHX_ "Unsupported script encoding UTF-16BE");
13712 #endif
13713              }
13714         }
13715 #ifdef EBCDIC
13716     case 0xDD:
13717         if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
13718             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
13719             s += 4;                      /* UTF-8 */
13720         }
13721         break;
13722 #endif
13723
13724     default:
13725          if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
13726                   /* Leading bytes
13727                    * xx 00 xx 00
13728                    * are a good indicator of UTF-16LE. */
13729 #ifndef PERL_NO_UTF16_FILTER
13730               if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
13731               s = add_utf16_textfilter(s, TRUE);
13732 #else
13733               Perl_croak(aTHX_ "Unsupported script encoding UTF-16LE");
13734 #endif
13735          }
13736     }
13737     return (char*)s;
13738 }
13739
13740
13741 #ifndef PERL_NO_UTF16_FILTER
13742 static I32
13743 S_utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
13744 {
13745     dVAR;
13746     SV *const filter = FILTER_DATA(idx);
13747     /* We re-use this each time round, throwing the contents away before we
13748        return.  */
13749     SV *const utf16_buffer = MUTABLE_SV(IoTOP_GV(filter));
13750     SV *const utf8_buffer = filter;
13751     IV status = IoPAGE(filter);
13752     const bool reverse = cBOOL(IoLINES(filter));
13753     I32 retval;
13754
13755     PERL_ARGS_ASSERT_UTF16_TEXTFILTER;
13756
13757     /* As we're automatically added, at the lowest level, and hence only called
13758        from this file, we can be sure that we're not called in block mode. Hence
13759        don't bother writing code to deal with block mode.  */
13760     if (maxlen) {
13761         Perl_croak(aTHX_ "panic: utf16_textfilter called in block mode (for %d characters)", maxlen);
13762     }
13763     if (status < 0) {
13764         Perl_croak(aTHX_ "panic: utf16_textfilter called after error (status=%"IVdf")", status);
13765     }
13766     DEBUG_P(PerlIO_printf(Perl_debug_log,
13767                           "utf16_textfilter(%p,%ce): idx=%d maxlen=%d status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n",
13768                           FPTR2DPTR(void *, S_utf16_textfilter),
13769                           reverse ? 'l' : 'b', idx, maxlen, status,
13770                           (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer)));
13771
13772     while (1) {
13773         STRLEN chars;
13774         STRLEN have;
13775         I32 newlen;
13776         U8 *end;
13777         /* First, look in our buffer of existing UTF-8 data:  */
13778         char *nl = (char *)memchr(SvPVX(utf8_buffer), '\n', SvCUR(utf8_buffer));
13779
13780         if (nl) {
13781             ++nl;
13782         } else if (status == 0) {
13783             /* EOF */
13784             IoPAGE(filter) = 0;
13785             nl = SvEND(utf8_buffer);
13786         }
13787         if (nl) {
13788             STRLEN got = nl - SvPVX(utf8_buffer);
13789             /* Did we have anything to append?  */
13790             retval = got != 0;
13791             sv_catpvn(sv, SvPVX(utf8_buffer), got);
13792             /* Everything else in this code works just fine if SVp_POK isn't
13793                set.  This, however, needs it, and we need it to work, else
13794                we loop infinitely because the buffer is never consumed.  */
13795             sv_chop(utf8_buffer, nl);
13796             break;
13797         }
13798
13799         /* OK, not a complete line there, so need to read some more UTF-16.
13800            Read an extra octect if the buffer currently has an odd number. */
13801         while (1) {
13802             if (status <= 0)
13803                 break;
13804             if (SvCUR(utf16_buffer) >= 2) {
13805                 /* Location of the high octet of the last complete code point.
13806                    Gosh, UTF-16 is a pain. All the benefits of variable length,
13807                    *coupled* with all the benefits of partial reads and
13808                    endianness.  */
13809                 const U8 *const last_hi = (U8*)SvPVX(utf16_buffer)
13810                     + ((SvCUR(utf16_buffer) & ~1) - (reverse ? 1 : 2));
13811
13812                 if (*last_hi < 0xd8 || *last_hi > 0xdb) {
13813                     break;
13814                 }
13815
13816                 /* We have the first half of a surrogate. Read more.  */
13817                 DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter partial surrogate detected at %p\n", last_hi));
13818             }
13819
13820             status = FILTER_READ(idx + 1, utf16_buffer,
13821                                  160 + (SvCUR(utf16_buffer) & 1));
13822             DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter status=%"IVdf" SvCUR(sv)=%"UVuf"\n", status, (UV)SvCUR(utf16_buffer)));
13823             DEBUG_P({ sv_dump(utf16_buffer); sv_dump(utf8_buffer);});
13824             if (status < 0) {
13825                 /* Error */
13826                 IoPAGE(filter) = status;
13827                 return status;
13828             }
13829         }
13830
13831         chars = SvCUR(utf16_buffer) >> 1;
13832         have = SvCUR(utf8_buffer);
13833         SvGROW(utf8_buffer, have + chars * 3 + 1);
13834
13835         if (reverse) {
13836             end = utf16_to_utf8_reversed((U8*)SvPVX(utf16_buffer),
13837                                          (U8*)SvPVX_const(utf8_buffer) + have,
13838                                          chars * 2, &newlen);
13839         } else {
13840             end = utf16_to_utf8((U8*)SvPVX(utf16_buffer),
13841                                 (U8*)SvPVX_const(utf8_buffer) + have,
13842                                 chars * 2, &newlen);
13843         }
13844         SvCUR_set(utf8_buffer, have + newlen);
13845         *end = '\0';
13846
13847         /* No need to keep this SV "well-formed" with a '\0' after the end, as
13848            it's private to us, and utf16_to_utf8{,reversed} take a
13849            (pointer,length) pair, rather than a NUL-terminated string.  */
13850         if(SvCUR(utf16_buffer) & 1) {
13851             *SvPVX(utf16_buffer) = SvEND(utf16_buffer)[-1];
13852             SvCUR_set(utf16_buffer, 1);
13853         } else {
13854             SvCUR_set(utf16_buffer, 0);
13855         }
13856     }
13857     DEBUG_P(PerlIO_printf(Perl_debug_log,
13858                           "utf16_textfilter: returns, status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n",
13859                           status,
13860                           (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer)));
13861     DEBUG_P({ sv_dump(utf8_buffer); sv_dump(sv);});
13862     return retval;
13863 }
13864
13865 static U8 *
13866 S_add_utf16_textfilter(pTHX_ U8 *const s, bool reversed)
13867 {
13868     SV *filter = filter_add(S_utf16_textfilter, NULL);
13869
13870     PERL_ARGS_ASSERT_ADD_UTF16_TEXTFILTER;
13871
13872     IoTOP_GV(filter) = MUTABLE_GV(newSVpvn((char *)s, PL_bufend - (char*)s));
13873     sv_setpvs(filter, "");
13874     IoLINES(filter) = reversed;
13875     IoPAGE(filter) = 1; /* Not EOF */
13876
13877     /* Sadly, we have to return a valid pointer, come what may, so we have to
13878        ignore any error return from this.  */
13879     SvCUR_set(PL_linestr, 0);
13880     if (FILTER_READ(0, PL_linestr, 0)) {
13881         SvUTF8_on(PL_linestr);
13882     } else {
13883         SvUTF8_on(PL_linestr);
13884     }
13885     PL_bufend = SvEND(PL_linestr);
13886     return (U8*)SvPVX(PL_linestr);
13887 }
13888 #endif
13889
13890 /*
13891 Returns a pointer to the next character after the parsed
13892 vstring, as well as updating the passed in sv.
13893
13894 Function must be called like
13895
13896         sv = newSV(5);
13897         s = scan_vstring(s,e,sv);
13898
13899 where s and e are the start and end of the string.
13900 The sv should already be large enough to store the vstring
13901 passed in, for performance reasons.
13902
13903 */
13904
13905 char *
13906 Perl_scan_vstring(pTHX_ const char *s, const char *const e, SV *sv)
13907 {
13908     dVAR;
13909     const char *pos = s;
13910     const char *start = s;
13911
13912     PERL_ARGS_ASSERT_SCAN_VSTRING;
13913
13914     if (*pos == 'v') pos++;  /* get past 'v' */
13915     while (pos < e && (isDIGIT(*pos) || *pos == '_'))
13916         pos++;
13917     if ( *pos != '.') {
13918         /* this may not be a v-string if followed by => */
13919         const char *next = pos;
13920         while (next < e && isSPACE(*next))
13921             ++next;
13922         if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
13923             /* return string not v-string */
13924             sv_setpvn(sv,(char *)s,pos-s);
13925             return (char *)pos;
13926         }
13927     }
13928
13929     if (!isALPHA(*pos)) {
13930         U8 tmpbuf[UTF8_MAXBYTES+1];
13931
13932         if (*s == 'v')
13933             s++;  /* get past 'v' */
13934
13935         sv_setpvs(sv, "");
13936
13937         for (;;) {
13938             /* this is atoi() that tolerates underscores */
13939             U8 *tmpend;
13940             UV rev = 0;
13941             const char *end = pos;
13942             UV mult = 1;
13943             while (--end >= s) {
13944                 if (*end != '_') {
13945                     const UV orev = rev;
13946                     rev += (*end - '0') * mult;
13947                     mult *= 10;
13948                     if (orev > rev)
13949                         Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
13950                                          "Integer overflow in decimal number");
13951                 }
13952             }
13953 #ifdef EBCDIC
13954             if (rev > 0x7FFFFFFF)
13955                  Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
13956 #endif
13957             /* Append native character for the rev point */
13958             tmpend = uvchr_to_utf8(tmpbuf, rev);
13959             sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
13960             if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
13961                  SvUTF8_on(sv);
13962             if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
13963                  s = ++pos;
13964             else {
13965                  s = pos;
13966                  break;
13967             }
13968             while (pos < e && (isDIGIT(*pos) || *pos == '_'))
13969                  pos++;
13970         }
13971         SvPOK_on(sv);
13972         sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
13973         SvRMAGICAL_on(sv);
13974     }
13975     return (char *)s;
13976 }
13977
13978 int
13979 Perl_keyword_plugin_standard(pTHX_
13980         char *keyword_ptr, STRLEN keyword_len, OP **op_ptr)
13981 {
13982     PERL_ARGS_ASSERT_KEYWORD_PLUGIN_STANDARD;
13983     PERL_UNUSED_CONTEXT;
13984     PERL_UNUSED_ARG(keyword_ptr);
13985     PERL_UNUSED_ARG(keyword_len);
13986     PERL_UNUSED_ARG(op_ptr);
13987     return KEYWORD_PLUGIN_DECLINE;
13988 }
13989
13990 #define parse_recdescent(g) S_parse_recdescent(aTHX_ g)
13991 static void
13992 S_parse_recdescent(pTHX_ int gramtype)
13993 {
13994     SAVEI32(PL_lex_brackets);
13995     if (PL_lex_brackets > 100)
13996         Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
13997     PL_lex_brackstack[PL_lex_brackets++] = XFAKEEOF;
13998     if(yyparse(gramtype) && !PL_parser->error_count)
13999         qerror(Perl_mess(aTHX_ "Parse error"));
14000 }
14001
14002 #define parse_recdescent_for_op(g) S_parse_recdescent_for_op(aTHX_ g)
14003 static OP *
14004 S_parse_recdescent_for_op(pTHX_ int gramtype)
14005 {
14006     OP *o;
14007     ENTER;
14008     SAVEVPTR(PL_eval_root);
14009     PL_eval_root = NULL;
14010     parse_recdescent(gramtype);
14011     o = PL_eval_root;
14012     LEAVE;
14013     return o;
14014 }
14015
14016 /*
14017 =for apidoc Amx|OP *|parse_block|U32 flags
14018
14019 Parse a single complete Perl code block.  This consists of an opening
14020 brace, a sequence of statements, and a closing brace.  The block
14021 constitutes a lexical scope, so C<my> variables and various compile-time
14022 effects can be contained within it.  It is up to the caller to ensure
14023 that the dynamic parser state (L</PL_parser> et al) is correctly set to
14024 reflect the source of the code to be parsed and the lexical context for
14025 the statement.
14026
14027 The op tree representing the code block is returned.  This is always a
14028 real op, never a null pointer.  It will normally be a C<lineseq> list,
14029 including C<nextstate> or equivalent ops.  No ops to construct any kind
14030 of runtime scope are included by virtue of it being a block.
14031
14032 If an error occurs in parsing or compilation, in most cases a valid op
14033 tree (most likely null) is returned anyway.  The error is reflected in
14034 the parser state, normally resulting in a single exception at the top
14035 level of parsing which covers all the compilation errors that occurred.
14036 Some compilation errors, however, will throw an exception immediately.
14037
14038 The I<flags> parameter is reserved for future use, and must always
14039 be zero.
14040
14041 =cut
14042 */
14043
14044 OP *
14045 Perl_parse_block(pTHX_ U32 flags)
14046 {
14047     if (flags)
14048         Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_block");
14049     return parse_recdescent_for_op(GRAMBLOCK);
14050 }
14051
14052 /*
14053 =for apidoc Amx|OP *|parse_barestmt|U32 flags
14054
14055 Parse a single unadorned Perl statement.  This may be a normal imperative
14056 statement or a declaration that has compile-time effect.  It does not
14057 include any label or other affixture.  It is up to the caller to ensure
14058 that the dynamic parser state (L</PL_parser> et al) is correctly set to
14059 reflect the source of the code to be parsed and the lexical context for
14060 the statement.
14061
14062 The op tree representing the statement is returned.  This may be a
14063 null pointer if the statement is null, for example if it was actually
14064 a subroutine definition (which has compile-time side effects).  If not
14065 null, it will be ops directly implementing the statement, suitable to
14066 pass to L</newSTATEOP>.  It will not normally include a C<nextstate> or
14067 equivalent op (except for those embedded in a scope contained entirely
14068 within the statement).
14069
14070 If an error occurs in parsing or compilation, in most cases a valid op
14071 tree (most likely null) is returned anyway.  The error is reflected in
14072 the parser state, normally resulting in a single exception at the top
14073 level of parsing which covers all the compilation errors that occurred.
14074 Some compilation errors, however, will throw an exception immediately.
14075
14076 The I<flags> parameter is reserved for future use, and must always
14077 be zero.
14078
14079 =cut
14080 */
14081
14082 OP *
14083 Perl_parse_barestmt(pTHX_ U32 flags)
14084 {
14085     if (flags)
14086         Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_barestmt");
14087     return parse_recdescent_for_op(GRAMBARESTMT);
14088 }
14089
14090 /*
14091 =for apidoc Amx|SV *|parse_label|U32 flags
14092
14093 Parse a single label, possibly optional, of the type that may prefix a
14094 Perl statement.  It is up to the caller to ensure that the dynamic parser
14095 state (L</PL_parser> et al) is correctly set to reflect the source of
14096 the code to be parsed.  If I<flags> includes C<PARSE_OPTIONAL> then the
14097 label is optional, otherwise it is mandatory.
14098
14099 The name of the label is returned in the form of a fresh scalar.  If an
14100 optional label is absent, a null pointer is returned.
14101
14102 If an error occurs in parsing, which can only occur if the label is
14103 mandatory, a valid label is returned anyway.  The error is reflected in
14104 the parser state, normally resulting in a single exception at the top
14105 level of parsing which covers all the compilation errors that occurred.
14106
14107 =cut
14108 */
14109
14110 SV *
14111 Perl_parse_label(pTHX_ U32 flags)
14112 {
14113     if (flags & ~PARSE_OPTIONAL)
14114         Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_label");
14115     if (PL_lex_state == LEX_KNOWNEXT) {
14116         PL_parser->yychar = yylex();
14117         if (PL_parser->yychar == LABEL) {
14118             char *lpv = pl_yylval.pval;
14119             STRLEN llen = strlen(lpv);
14120             SV *lsv;
14121             PL_parser->yychar = YYEMPTY;
14122             lsv = newSV_type(SVt_PV);
14123             SvPV_set(lsv, lpv);
14124             SvCUR_set(lsv, llen);
14125             SvLEN_set(lsv, llen+1);
14126             SvPOK_on(lsv);
14127             return lsv;
14128         } else {
14129             yyunlex();
14130             goto no_label;
14131         }
14132     } else {
14133         char *s, *t;
14134         U8 c;
14135         STRLEN wlen, bufptr_pos;
14136         lex_read_space(0);
14137         t = s = PL_bufptr;
14138         c = (U8)*s;
14139         if (!isIDFIRST_A(c))
14140             goto no_label;
14141         do {
14142             c = (U8)*++t;
14143         } while(isWORDCHAR_A(c));
14144         wlen = t - s;
14145         if (word_takes_any_delimeter(s, wlen))
14146             goto no_label;
14147         bufptr_pos = s - SvPVX(PL_linestr);
14148         PL_bufptr = t;
14149         lex_read_space(LEX_KEEP_PREVIOUS);
14150         t = PL_bufptr;
14151         s = SvPVX(PL_linestr) + bufptr_pos;
14152         if (t[0] == ':' && t[1] != ':') {
14153             PL_oldoldbufptr = PL_oldbufptr;
14154             PL_oldbufptr = s;
14155             PL_bufptr = t+1;
14156             return newSVpvn(s, wlen);
14157         } else {
14158             PL_bufptr = s;
14159             no_label:
14160             if (flags & PARSE_OPTIONAL) {
14161                 return NULL;
14162             } else {
14163                 qerror(Perl_mess(aTHX_ "Parse error"));
14164                 return newSVpvs("x");
14165             }
14166         }
14167     }
14168 }
14169
14170 /*
14171 =for apidoc Amx|OP *|parse_fullstmt|U32 flags
14172
14173 Parse a single complete Perl statement.  This may be a normal imperative
14174 statement or a declaration that has compile-time effect, and may include
14175 an optional label.  It is up to the caller to ensure that the dynamic
14176 parser state (L</PL_parser> et al) is correctly set to reflect the source
14177 of the code to be parsed and the lexical context for the statement.
14178
14179 The op tree representing the statement is returned.  This may be a
14180 null pointer if the statement is null, for example if it was actually
14181 a subroutine definition (which has compile-time side effects).  If not
14182 null, it will be the result of a L</newSTATEOP> call, normally including
14183 a C<nextstate> or equivalent op.
14184
14185 If an error occurs in parsing or compilation, in most cases a valid op
14186 tree (most likely null) is returned anyway.  The error is reflected in
14187 the parser state, normally resulting in a single exception at the top
14188 level of parsing which covers all the compilation errors that occurred.
14189 Some compilation errors, however, will throw an exception immediately.
14190
14191 The I<flags> parameter is reserved for future use, and must always
14192 be zero.
14193
14194 =cut
14195 */
14196
14197 OP *
14198 Perl_parse_fullstmt(pTHX_ U32 flags)
14199 {
14200     if (flags)
14201         Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_fullstmt");
14202     return parse_recdescent_for_op(GRAMFULLSTMT);
14203 }
14204
14205 /*
14206 =for apidoc Amx|OP *|parse_stmtseq|U32 flags
14207
14208 Parse a sequence of zero or more Perl statements.  These may be normal
14209 imperative statements, including optional labels, or declarations
14210 that have compile-time effect, or any mixture thereof.  The statement
14211 sequence ends when a closing brace or end-of-file is encountered in a
14212 place where a new statement could have validly started.  It is up to
14213 the caller to ensure that the dynamic parser state (L</PL_parser> et al)
14214 is correctly set to reflect the source of the code to be parsed and the
14215 lexical context for the statements.
14216
14217 The op tree representing the statement sequence is returned.  This may
14218 be a null pointer if the statements were all null, for example if there
14219 were no statements or if there were only subroutine definitions (which
14220 have compile-time side effects).  If not null, it will be a C<lineseq>
14221 list, normally including C<nextstate> or equivalent ops.
14222
14223 If an error occurs in parsing or compilation, in most cases a valid op
14224 tree is returned anyway.  The error is reflected in the parser state,
14225 normally resulting in a single exception at the top level of parsing
14226 which covers all the compilation errors that occurred.  Some compilation
14227 errors, however, will throw an exception immediately.
14228
14229 The I<flags> parameter is reserved for future use, and must always
14230 be zero.
14231
14232 =cut
14233 */
14234
14235 OP *
14236 Perl_parse_stmtseq(pTHX_ U32 flags)
14237 {
14238     OP *stmtseqop;
14239     I32 c;
14240     if (flags)
14241         Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_fullstmt");
14242     stmtseqop = parse_recdescent_for_op(GRAMSTMTSEQ);
14243     c = lex_peek_unichar(0);
14244     if (c != -1 && c != /*{*/'}')
14245         qerror(Perl_mess(aTHX_ "Parse error"));
14246     return stmtseqop;
14247 }
14248
14249 void
14250 Perl_munge_qwlist_to_paren_list(pTHX_ OP *qwlist)
14251 {
14252     PERL_ARGS_ASSERT_MUNGE_QWLIST_TO_PAREN_LIST;
14253     deprecate("qw(...) as parentheses");
14254     force_next(')');
14255     if (qwlist->op_type == OP_STUB) {
14256         op_free(qwlist);
14257     }
14258     else {
14259         start_force(PL_curforce);
14260         NEXTVAL_NEXTTOKE.opval = qwlist;
14261         force_next(THING);
14262     }
14263     force_next('(');
14264 }
14265
14266 /*
14267  * Local variables:
14268  * c-indentation-style: bsd
14269  * c-basic-offset: 4
14270  * indent-tabs-mode: t
14271  * End:
14272  *
14273  * ex: set ts=8 sts=4 sw=4 noet:
14274  */