This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Correct the return type for B::MAGIC::MOREMAGIC.
[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_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
2420         PL_lex_inpat = PL_sublex_info.sub_op;
2421     else
2422         PL_lex_inpat = NULL;
2423
2424     return '(';
2425 }
2426
2427 /*
2428  * S_sublex_done
2429  * Restores lexer state after a S_sublex_push.
2430  */
2431
2432 STATIC I32
2433 S_sublex_done(pTHX)
2434 {
2435     dVAR;
2436     if (!PL_lex_starts++) {
2437         SV * const sv = newSVpvs("");
2438         if (SvUTF8(PL_linestr))
2439             SvUTF8_on(sv);
2440         PL_expect = XOPERATOR;
2441         pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2442         return THING;
2443     }
2444
2445     if (PL_lex_casemods) {              /* oops, we've got some unbalanced parens */
2446         PL_lex_state = LEX_INTERPCASEMOD;
2447         return yylex();
2448     }
2449
2450     /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
2451     if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
2452         PL_linestr = PL_lex_repl;
2453         PL_lex_inpat = 0;
2454         PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
2455         PL_bufend += SvCUR(PL_linestr);
2456         PL_last_lop = PL_last_uni = NULL;
2457         SAVEFREESV(PL_linestr);
2458         PL_lex_dojoin = FALSE;
2459         PL_lex_brackets = 0;
2460         PL_lex_casemods = 0;
2461         *PL_lex_casestack = '\0';
2462         PL_lex_starts = 0;
2463         if (SvEVALED(PL_lex_repl)) {
2464             PL_lex_state = LEX_INTERPNORMAL;
2465             PL_lex_starts++;
2466             /*  we don't clear PL_lex_repl here, so that we can check later
2467                 whether this is an evalled subst; that means we rely on the
2468                 logic to ensure sublex_done() is called again only via the
2469                 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
2470         }
2471         else {
2472             PL_lex_state = LEX_INTERPCONCAT;
2473             PL_lex_repl = NULL;
2474         }
2475         return ',';
2476     }
2477     else {
2478 #ifdef PERL_MAD
2479         if (PL_madskills) {
2480             if (PL_thiswhite) {
2481                 if (!PL_endwhite)
2482                     PL_endwhite = newSVpvs("");
2483                 sv_catsv(PL_endwhite, PL_thiswhite);
2484                 PL_thiswhite = 0;
2485             }
2486             if (PL_thistoken)
2487                 sv_setpvs(PL_thistoken,"");
2488             else
2489                 PL_realtokenstart = -1;
2490         }
2491 #endif
2492         LEAVE;
2493         PL_bufend = SvPVX(PL_linestr);
2494         PL_bufend += SvCUR(PL_linestr);
2495         PL_expect = XOPERATOR;
2496         PL_sublex_info.sub_inwhat = 0;
2497         return ')';
2498     }
2499 }
2500
2501 /*
2502   scan_const
2503
2504   Extracts a pattern, double-quoted string, or transliteration.  This
2505   is terrifying code.
2506
2507   It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
2508   processing a pattern (PL_lex_inpat is true), a transliteration
2509   (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
2510
2511   Returns a pointer to the character scanned up to. If this is
2512   advanced from the start pointer supplied (i.e. if anything was
2513   successfully parsed), will leave an OP for the substring scanned
2514   in pl_yylval. Caller must intuit reason for not parsing further
2515   by looking at the next characters herself.
2516
2517   In patterns:
2518     backslashes:
2519       constants: \N{NAME} only
2520       case and quoting: \U \Q \E
2521     stops on @ and $, but not for $ as tail anchor
2522
2523   In transliterations:
2524     characters are VERY literal, except for - not at the start or end
2525     of the string, which indicates a range. If the range is in bytes,
2526     scan_const expands the range to the full set of intermediate
2527     characters. If the range is in utf8, the hyphen is replaced with
2528     a certain range mark which will be handled by pmtrans() in op.c.
2529
2530   In double-quoted strings:
2531     backslashes:
2532       double-quoted style: \r and \n
2533       constants: \x31, etc.
2534       deprecated backrefs: \1 (in substitution replacements)
2535       case and quoting: \U \Q \E
2536     stops on @ and $
2537
2538   scan_const does *not* construct ops to handle interpolated strings.
2539   It stops processing as soon as it finds an embedded $ or @ variable
2540   and leaves it to the caller to work out what's going on.
2541
2542   embedded arrays (whether in pattern or not) could be:
2543       @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
2544
2545   $ in double-quoted strings must be the symbol of an embedded scalar.
2546
2547   $ in pattern could be $foo or could be tail anchor.  Assumption:
2548   it's a tail anchor if $ is the last thing in the string, or if it's
2549   followed by one of "()| \r\n\t"
2550
2551   \1 (backreferences) are turned into $1
2552
2553   The structure of the code is
2554       while (there's a character to process) {
2555           handle transliteration ranges
2556           skip regexp comments /(?#comment)/ and codes /(?{code})/
2557           skip #-initiated comments in //x patterns
2558           check for embedded arrays
2559           check for embedded scalars
2560           if (backslash) {
2561               deprecate \1 in substitution replacements
2562               handle string-changing backslashes \l \U \Q \E, etc.
2563               switch (what was escaped) {
2564                   handle \- in a transliteration (becomes a literal -)
2565                   if a pattern and not \N{, go treat as regular character
2566                   handle \132 (octal characters)
2567                   handle \x15 and \x{1234} (hex characters)
2568                   handle \N{name} (named characters, also \N{3,5} in a pattern)
2569                   handle \cV (control characters)
2570                   handle printf-style backslashes (\f, \r, \n, etc)
2571               } (end switch)
2572               continue
2573           } (end if backslash)
2574           handle regular character
2575     } (end while character to read)
2576                 
2577 */
2578
2579 STATIC char *
2580 S_scan_const(pTHX_ char *start)
2581 {
2582     dVAR;
2583     register char *send = PL_bufend;            /* end of the constant */
2584     SV *sv = newSV(send - start);               /* sv for the constant.  See
2585                                                    note below on sizing. */
2586     register char *s = start;                   /* start of the constant */
2587     register char *d = SvPVX(sv);               /* destination for copies */
2588     bool dorange = FALSE;                       /* are we in a translit range? */
2589     bool didrange = FALSE;                      /* did we just finish a range? */
2590     I32  has_utf8 = FALSE;                      /* Output constant is UTF8 */
2591     I32  this_utf8 = UTF;                       /* Is the source string assumed
2592                                                    to be UTF8?  But, this can
2593                                                    show as true when the source
2594                                                    isn't utf8, as for example
2595                                                    when it is entirely composed
2596                                                    of hex constants */
2597
2598     /* Note on sizing:  The scanned constant is placed into sv, which is
2599      * initialized by newSV() assuming one byte of output for every byte of
2600      * input.  This routine expects newSV() to allocate an extra byte for a
2601      * trailing NUL, which this routine will append if it gets to the end of
2602      * the input.  There may be more bytes of input than output (eg., \N{LATIN
2603      * CAPITAL LETTER A}), or more output than input if the constant ends up
2604      * recoded to utf8, but each time a construct is found that might increase
2605      * the needed size, SvGROW() is called.  Its size parameter each time is
2606      * based on the best guess estimate at the time, namely the length used so
2607      * far, plus the length the current construct will occupy, plus room for
2608      * the trailing NUL, plus one byte for every input byte still unscanned */ 
2609
2610     UV uv;
2611 #ifdef EBCDIC
2612     UV literal_endpoint = 0;
2613     bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
2614 #endif
2615
2616     PERL_ARGS_ASSERT_SCAN_CONST;
2617
2618     if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2619         /* If we are doing a trans and we know we want UTF8 set expectation */
2620         has_utf8   = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
2621         this_utf8  = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2622     }
2623
2624
2625     while (s < send || dorange) {
2626
2627         /* get transliterations out of the way (they're most literal) */
2628         if (PL_lex_inwhat == OP_TRANS) {
2629             /* expand a range A-Z to the full set of characters.  AIE! */
2630             if (dorange) {
2631                 I32 i;                          /* current expanded character */
2632                 I32 min;                        /* first character in range */
2633                 I32 max;                        /* last character in range */
2634
2635 #ifdef EBCDIC
2636                 UV uvmax = 0;
2637 #endif
2638
2639                 if (has_utf8
2640 #ifdef EBCDIC
2641                     && !native_range
2642 #endif
2643                     ) {
2644                     char * const c = (char*)utf8_hop((U8*)d, -1);
2645                     char *e = d++;
2646                     while (e-- > c)
2647                         *(e + 1) = *e;
2648                     *c = (char)UTF_TO_NATIVE(0xff);
2649                     /* mark the range as done, and continue */
2650                     dorange = FALSE;
2651                     didrange = TRUE;
2652                     continue;
2653                 }
2654
2655                 i = d - SvPVX_const(sv);                /* remember current offset */
2656 #ifdef EBCDIC
2657                 SvGROW(sv,
2658                        SvLEN(sv) + (has_utf8 ?
2659                                     (512 - UTF_CONTINUATION_MARK +
2660                                      UNISKIP(0x100))
2661                                     : 256));
2662                 /* How many two-byte within 0..255: 128 in UTF-8,
2663                  * 96 in UTF-8-mod. */
2664 #else
2665                 SvGROW(sv, SvLEN(sv) + 256);    /* never more than 256 chars in a range */
2666 #endif
2667                 d = SvPVX(sv) + i;              /* refresh d after realloc */
2668 #ifdef EBCDIC
2669                 if (has_utf8) {
2670                     int j;
2671                     for (j = 0; j <= 1; j++) {
2672                         char * const c = (char*)utf8_hop((U8*)d, -1);
2673                         const UV uv    = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
2674                         if (j)
2675                             min = (U8)uv;
2676                         else if (uv < 256)
2677                             max = (U8)uv;
2678                         else {
2679                             max = (U8)0xff; /* only to \xff */
2680                             uvmax = uv; /* \x{100} to uvmax */
2681                         }
2682                         d = c; /* eat endpoint chars */
2683                      }
2684                 }
2685                else {
2686 #endif
2687                    d -= 2;              /* eat the first char and the - */
2688                    min = (U8)*d;        /* first char in range */
2689                    max = (U8)d[1];      /* last char in range  */
2690 #ifdef EBCDIC
2691                }
2692 #endif
2693
2694                 if (min > max) {
2695                     Perl_croak(aTHX_
2696                                "Invalid range \"%c-%c\" in transliteration operator",
2697                                (char)min, (char)max);
2698                 }
2699
2700 #ifdef EBCDIC
2701                 if (literal_endpoint == 2 &&
2702                     ((isLOWER(min) && isLOWER(max)) ||
2703                      (isUPPER(min) && isUPPER(max)))) {
2704                     if (isLOWER(min)) {
2705                         for (i = min; i <= max; i++)
2706                             if (isLOWER(i))
2707                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
2708                     } else {
2709                         for (i = min; i <= max; i++)
2710                             if (isUPPER(i))
2711                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
2712                     }
2713                 }
2714                 else
2715 #endif
2716                     for (i = min; i <= max; i++)
2717 #ifdef EBCDIC
2718                         if (has_utf8) {
2719                             const U8 ch = (U8)NATIVE_TO_UTF(i);
2720                             if (UNI_IS_INVARIANT(ch))
2721                                 *d++ = (U8)i;
2722                             else {
2723                                 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
2724                                 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
2725                             }
2726                         }
2727                         else
2728 #endif
2729                             *d++ = (char)i;
2730  
2731 #ifdef EBCDIC
2732                 if (uvmax) {
2733                     d = (char*)uvchr_to_utf8((U8*)d, 0x100);
2734                     if (uvmax > 0x101)
2735                         *d++ = (char)UTF_TO_NATIVE(0xff);
2736                     if (uvmax > 0x100)
2737                         d = (char*)uvchr_to_utf8((U8*)d, uvmax);
2738                 }
2739 #endif
2740
2741                 /* mark the range as done, and continue */
2742                 dorange = FALSE;
2743                 didrange = TRUE;
2744 #ifdef EBCDIC
2745                 literal_endpoint = 0;
2746 #endif
2747                 continue;
2748             }
2749
2750             /* range begins (ignore - as first or last char) */
2751             else if (*s == '-' && s+1 < send  && s != start) {
2752                 if (didrange) {
2753                     Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
2754                 }
2755                 if (has_utf8
2756 #ifdef EBCDIC
2757                     && !native_range
2758 #endif
2759                     ) {
2760                     *d++ = (char)UTF_TO_NATIVE(0xff);   /* use illegal utf8 byte--see pmtrans */
2761                     s++;
2762                     continue;
2763                 }
2764                 dorange = TRUE;
2765                 s++;
2766             }
2767             else {
2768                 didrange = FALSE;
2769 #ifdef EBCDIC
2770                 literal_endpoint = 0;
2771                 native_range = TRUE;
2772 #endif
2773             }
2774         }
2775
2776         /* if we get here, we're not doing a transliteration */
2777
2778         /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2779            except for the last char, which will be done separately. */
2780         else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
2781             if (s[2] == '#') {
2782                 while (s+1 < send && *s != ')')
2783                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2784             }
2785             else if (s[2] == '{' /* This should match regcomp.c */
2786                     || (s[2] == '?' && s[3] == '{'))
2787             {
2788                 I32 count = 1;
2789                 char *regparse = s + (s[2] == '{' ? 3 : 4);
2790                 char c;
2791
2792                 while (count && (c = *regparse)) {
2793                     if (c == '\\' && regparse[1])
2794                         regparse++;
2795                     else if (c == '{')
2796                         count++;
2797                     else if (c == '}')
2798                         count--;
2799                     regparse++;
2800                 }
2801                 if (*regparse != ')')
2802                     regparse--;         /* Leave one char for continuation. */
2803                 while (s < regparse)
2804                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2805             }
2806         }
2807
2808         /* likewise skip #-initiated comments in //x patterns */
2809         else if (*s == '#' && PL_lex_inpat &&
2810           ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2811             while (s+1 < send && *s != '\n')
2812                 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2813         }
2814
2815         /* check for embedded arrays
2816            (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2817            */
2818         else if (*s == '@' && s[1]) {
2819             if (isALNUM_lazy_if(s+1,UTF))
2820                 break;
2821             if (strchr(":'{$", s[1]))
2822                 break;
2823             if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2824                 break; /* in regexp, neither @+ nor @- are interpolated */
2825         }
2826
2827         /* check for embedded scalars.  only stop if we're sure it's a
2828            variable.
2829         */
2830         else if (*s == '$') {
2831             if (!PL_lex_inpat)  /* not a regexp, so $ must be var */
2832                 break;
2833             if (s + 1 < send && !strchr("()| \r\n\t", s[1])) {
2834                 if (s[1] == '\\') {
2835                     Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
2836                                    "Possible unintended interpolation of $\\ in regex");
2837                 }
2838                 break;          /* in regexp, $ might be tail anchor */
2839             }
2840         }
2841
2842         /* End of else if chain - OP_TRANS rejoin rest */
2843
2844         /* backslashes */
2845         if (*s == '\\' && s+1 < send) {
2846             char* e;    /* Can be used for ending '}', etc. */
2847
2848             s++;
2849
2850             /* warn on \1 - \9 in substitution replacements, but note that \11
2851              * is an octal; and \19 is \1 followed by '9' */
2852             if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2853                 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2854             {
2855                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2856                 *--s = '$';
2857                 break;
2858             }
2859
2860             /* string-change backslash escapes */
2861             if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2862                 --s;
2863                 break;
2864             }
2865             /* In a pattern, process \N, but skip any other backslash escapes.
2866              * This is because we don't want to translate an escape sequence
2867              * into a meta symbol and have the regex compiler use the meta
2868              * symbol meaning, e.g. \x{2E} would be confused with a dot.  But
2869              * in spite of this, we do have to process \N here while the proper
2870              * charnames handler is in scope.  See bugs #56444 and #62056.
2871              * There is a complication because \N in a pattern may also stand
2872              * for 'match a non-nl', and not mean a charname, in which case its
2873              * processing should be deferred to the regex compiler.  To be a
2874              * charname it must be followed immediately by a '{', and not look
2875              * like \N followed by a curly quantifier, i.e., not something like
2876              * \N{3,}.  regcurly returns a boolean indicating if it is a legal
2877              * quantifier */
2878             else if (PL_lex_inpat
2879                     && (*s != 'N'
2880                         || s[1] != '{'
2881                         || regcurly(s + 1)))
2882             {
2883                 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2884                 goto default_action;
2885             }
2886
2887             switch (*s) {
2888
2889             /* quoted - in transliterations */
2890             case '-':
2891                 if (PL_lex_inwhat == OP_TRANS) {
2892                     *d++ = *s++;
2893                     continue;
2894                 }
2895                 /* FALL THROUGH */
2896             default:
2897                 {
2898                     if ((isALPHA(*s) || isDIGIT(*s)))
2899                         Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
2900                                        "Unrecognized escape \\%c passed through",
2901                                        *s);
2902                     /* default action is to copy the quoted character */
2903                     goto default_action;
2904                 }
2905
2906             /* eg. \132 indicates the octal constant 0132 */
2907             case '0': case '1': case '2': case '3':
2908             case '4': case '5': case '6': case '7':
2909                 {
2910                     I32 flags = 0;
2911                     STRLEN len = 3;
2912                     uv = NATIVE_TO_UNI(grok_oct(s, &len, &flags, NULL));
2913                     s += len;
2914                 }
2915                 goto NUM_ESCAPE_INSERT;
2916
2917             /* eg. \o{24} indicates the octal constant \024 */
2918             case 'o':
2919                 {
2920                     STRLEN len;
2921                     const char* error;
2922
2923                     bool valid = grok_bslash_o(s, &uv, &len, &error, 1);
2924                     s += len;
2925                     if (! valid) {
2926                         yyerror(error);
2927                         continue;
2928                     }
2929                     goto NUM_ESCAPE_INSERT;
2930                 }
2931
2932             /* eg. \x24 indicates the hex constant 0x24 */
2933             case 'x':
2934                 ++s;
2935                 if (*s == '{') {
2936                     char* const e = strchr(s, '}');
2937                     I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2938                       PERL_SCAN_DISALLOW_PREFIX;
2939                     STRLEN len;
2940
2941                     ++s;
2942                     if (!e) {
2943                         yyerror("Missing right brace on \\x{}");
2944                         continue;
2945                     }
2946                     len = e - s;
2947                     uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
2948                     s = e + 1;
2949                 }
2950                 else {
2951                     {
2952                         STRLEN len = 2;
2953                         I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2954                         uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
2955                         s += len;
2956                     }
2957                 }
2958
2959               NUM_ESCAPE_INSERT:
2960                 /* Insert oct or hex escaped character.  There will always be
2961                  * enough room in sv since such escapes will be longer than any
2962                  * UTF-8 sequence they can end up as, except if they force us
2963                  * to recode the rest of the string into utf8 */
2964                 
2965                 /* Here uv is the ordinal of the next character being added in
2966                  * unicode (converted from native). */
2967                 if (!UNI_IS_INVARIANT(uv)) {
2968                     if (!has_utf8 && uv > 255) {
2969                         /* Might need to recode whatever we have accumulated so
2970                          * far if it contains any chars variant in utf8 or
2971                          * utf-ebcdic. */
2972                           
2973                         SvCUR_set(sv, d - SvPVX_const(sv));
2974                         SvPOK_on(sv);
2975                         *d = '\0';
2976                         /* See Note on sizing above.  */
2977                         sv_utf8_upgrade_flags_grow(sv,
2978                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2979                                         UNISKIP(uv) + (STRLEN)(send - s) + 1);
2980                         d = SvPVX(sv) + SvCUR(sv);
2981                         has_utf8 = TRUE;
2982                     }
2983
2984                     if (has_utf8) {
2985                         d = (char*)uvuni_to_utf8((U8*)d, uv);
2986                         if (PL_lex_inwhat == OP_TRANS &&
2987                             PL_sublex_info.sub_op) {
2988                             PL_sublex_info.sub_op->op_private |=
2989                                 (PL_lex_repl ? OPpTRANS_FROM_UTF
2990                                              : OPpTRANS_TO_UTF);
2991                         }
2992 #ifdef EBCDIC
2993                         if (uv > 255 && !dorange)
2994                             native_range = FALSE;
2995 #endif
2996                     }
2997                     else {
2998                         *d++ = (char)uv;
2999                     }
3000                 }
3001                 else {
3002                     *d++ = (char) uv;
3003                 }
3004                 continue;
3005
3006             case 'N':
3007                 /* In a non-pattern \N must be a named character, like \N{LATIN
3008                  * SMALL LETTER A} or \N{U+0041}.  For patterns, it also can
3009                  * mean to match a non-newline.  For non-patterns, named
3010                  * characters are converted to their string equivalents. In
3011                  * patterns, named characters are not converted to their
3012                  * ultimate forms for the same reasons that other escapes
3013                  * aren't.  Instead, they are converted to the \N{U+...} form
3014                  * to get the value from the charnames that is in effect right
3015                  * now, while preserving the fact that it was a named character
3016                  * so that the regex compiler knows this */
3017
3018                 /* This section of code doesn't generally use the
3019                  * NATIVE_TO_NEED() macro to transform the input.  I (khw) did
3020                  * a close examination of this macro and determined it is a
3021                  * no-op except on utfebcdic variant characters.  Every
3022                  * character generated by this that would normally need to be
3023                  * enclosed by this macro is invariant, so the macro is not
3024                  * needed, and would complicate use of copy(). There are other
3025                  * parts of this file where the macro is used inconsistently,
3026                  * but are saved by it being a no-op */
3027
3028                 /* The structure of this section of code (besides checking for
3029                  * errors and upgrading to utf8) is:
3030                  *  Further disambiguate between the two meanings of \N, and if
3031                  *      not a charname, go process it elsewhere
3032                  *  If of form \N{U+...}, pass it through if a pattern;
3033                  *      otherwise convert to utf8
3034                  *  Otherwise must be \N{NAME}: convert to \N{U+c1.c2...} if a
3035                  *  pattern; otherwise convert to utf8 */
3036
3037                 /* Here, s points to the 'N'; the test below is guaranteed to
3038                  * succeed if we are being called on a pattern as we already
3039                  * know from a test above that the next character is a '{'.
3040                  * On a non-pattern \N must mean 'named sequence, which
3041                  * requires braces */
3042                 s++;
3043                 if (*s != '{') {
3044                     yyerror("Missing braces on \\N{}"); 
3045                     continue;
3046                 }
3047                 s++;
3048
3049                 /* If there is no matching '}', it is an error. */
3050                 if (! (e = strchr(s, '}'))) {
3051                     if (! PL_lex_inpat) {
3052                         yyerror("Missing right brace on \\N{}");
3053                     } else {
3054                         yyerror("Missing right brace on \\N{} or unescaped left brace after \\N.");
3055                     }
3056                     continue;
3057                 }
3058
3059                 /* Here it looks like a named character */
3060
3061                 if (PL_lex_inpat) {
3062
3063                     /* XXX This block is temporary code.  \N{} implies that the
3064                      * pattern is to have Unicode semantics, and therefore
3065                      * currently has to be encoded in utf8.  By putting it in
3066                      * utf8 now, we save a whole pass in the regular expression
3067                      * compiler.  Once that code is changed so Unicode
3068                      * semantics doesn't necessarily have to be in utf8, this
3069                      * block should be removed */
3070                     if (!has_utf8) {
3071                         SvCUR_set(sv, d - SvPVX_const(sv));
3072                         SvPOK_on(sv);
3073                         *d = '\0';
3074                         /* See Note on sizing above.  */
3075                         sv_utf8_upgrade_flags_grow(sv,
3076                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3077                                         /* 5 = '\N{' + cur char + NUL */
3078                                         (STRLEN)(send - s) + 5);
3079                         d = SvPVX(sv) + SvCUR(sv);
3080                         has_utf8 = TRUE;
3081                     }
3082                 }
3083
3084                 if (*s == 'U' && s[1] == '+') { /* \N{U+...} */
3085                     I32 flags = PERL_SCAN_ALLOW_UNDERSCORES
3086                                 | PERL_SCAN_DISALLOW_PREFIX;
3087                     STRLEN len;
3088
3089                     /* For \N{U+...}, the '...' is a unicode value even on
3090                      * EBCDIC machines */
3091                     s += 2;         /* Skip to next char after the 'U+' */
3092                     len = e - s;
3093                     uv = grok_hex(s, &len, &flags, NULL);
3094                     if (len == 0 || len != (STRLEN)(e - s)) {
3095                         yyerror("Invalid hexadecimal number in \\N{U+...}");
3096                         s = e + 1;
3097                         continue;
3098                     }
3099
3100                     if (PL_lex_inpat) {
3101
3102                         /* Pass through to the regex compiler unchanged.  The
3103                          * reason we evaluated the number above is to make sure
3104                          * there wasn't a syntax error. */
3105                         s -= 5;     /* Include the '\N{U+' */
3106                         Copy(s, d, e - s + 1, char);    /* 1 = include the } */
3107                         d += e - s + 1;
3108                     }
3109                     else {  /* Not a pattern: convert the hex to string */
3110
3111                          /* If destination is not in utf8, unconditionally
3112                           * recode it to be so.  This is because \N{} implies
3113                           * Unicode semantics, and scalars have to be in utf8
3114                           * to guarantee those semantics */
3115                         if (! has_utf8) {
3116                             SvCUR_set(sv, d - SvPVX_const(sv));
3117                             SvPOK_on(sv);
3118                             *d = '\0';
3119                             /* See Note on sizing above.  */
3120                             sv_utf8_upgrade_flags_grow(
3121                                         sv,
3122                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3123                                         UNISKIP(uv) + (STRLEN)(send - e) + 1);
3124                             d = SvPVX(sv) + SvCUR(sv);
3125                             has_utf8 = TRUE;
3126                         }
3127
3128                         /* Add the string to the output */
3129                         if (UNI_IS_INVARIANT(uv)) {
3130                             *d++ = (char) uv;
3131                         }
3132                         else d = (char*)uvuni_to_utf8((U8*)d, uv);
3133                     }
3134                 }
3135                 else { /* Here is \N{NAME} but not \N{U+...}. */
3136
3137                     SV *res;            /* result from charnames */
3138                     const char *str;    /* the string in 'res' */
3139                     STRLEN len;         /* its length */
3140
3141                     /* Get the value for NAME */
3142                     res = newSVpvn(s, e - s);
3143                     res = new_constant( NULL, 0, "charnames",
3144                                         /* includes all of: \N{...} */
3145                                         res, NULL, s - 3, e - s + 4 );
3146
3147                     /* Most likely res will be in utf8 already since the
3148                      * standard charnames uses pack U, but a custom translator
3149                      * can leave it otherwise, so make sure.  XXX This can be
3150                      * revisited to not have charnames use utf8 for characters
3151                      * that don't need it when regexes don't have to be in utf8
3152                      * for Unicode semantics.  If doing so, remember EBCDIC */
3153                     sv_utf8_upgrade(res);
3154                     str = SvPV_const(res, len);
3155
3156                     /* Don't accept malformed input */
3157                     if (! is_utf8_string((U8 *) str, len)) {
3158                         yyerror("Malformed UTF-8 returned by \\N");
3159                     }
3160                     else if (PL_lex_inpat) {
3161
3162                         if (! len) { /* The name resolved to an empty string */
3163                             Copy("\\N{}", d, 4, char);
3164                             d += 4;
3165                         }
3166                         else {
3167                             /* In order to not lose information for the regex
3168                             * compiler, pass the result in the specially made
3169                             * syntax: \N{U+c1.c2.c3...}, where c1 etc. are
3170                             * the code points in hex of each character
3171                             * returned by charnames */
3172
3173                             const char *str_end = str + len;
3174                             STRLEN char_length;     /* cur char's byte length */
3175                             STRLEN output_length;   /* and the number of bytes
3176                                                        after this is translated
3177                                                        into hex digits */
3178                             const STRLEN off = d - SvPVX_const(sv);
3179
3180                             /* 2 hex per byte; 2 chars for '\N'; 2 chars for
3181                              * max('U+', '.'); and 1 for NUL */
3182                             char hex_string[2 * UTF8_MAXBYTES + 5];
3183
3184                             /* Get the first character of the result. */
3185                             U32 uv = utf8n_to_uvuni((U8 *) str,
3186                                                     len,
3187                                                     &char_length,
3188                                                     UTF8_ALLOW_ANYUV);
3189
3190                             /* The call to is_utf8_string() above hopefully
3191                              * guarantees that there won't be an error.  But
3192                              * it's easy here to make sure.  The function just
3193                              * above warns and returns 0 if invalid utf8, but
3194                              * it can also return 0 if the input is validly a
3195                              * NUL. Disambiguate */
3196                             if (uv == 0 && NATIVE_TO_ASCII(*str) != '\0') {
3197                                 uv = UNICODE_REPLACEMENT;
3198                             }
3199
3200                             /* Convert first code point to hex, including the
3201                              * boiler plate before it */
3202                             output_length =
3203                                 my_sprintf(hex_string, "\\N{U+%X", (unsigned int) uv);
3204
3205                             /* Make sure there is enough space to hold it */
3206                             d = off + SvGROW(sv, off
3207                                                  + output_length
3208                                                  + (STRLEN)(send - e)
3209                                                  + 2);  /* '}' + NUL */
3210                             /* And output it */
3211                             Copy(hex_string, d, output_length, char);
3212                             d += output_length;
3213
3214                             /* For each subsequent character, append dot and
3215                              * its ordinal in hex */
3216                             while ((str += char_length) < str_end) {
3217                                 const STRLEN off = d - SvPVX_const(sv);
3218                                 U32 uv = utf8n_to_uvuni((U8 *) str,
3219                                                         str_end - str,
3220                                                         &char_length,
3221                                                         UTF8_ALLOW_ANYUV);
3222                                 if (uv == 0 && NATIVE_TO_ASCII(*str) != '\0') {
3223                                     uv = UNICODE_REPLACEMENT;
3224                                 }
3225
3226                                 output_length =
3227                                     my_sprintf(hex_string, ".%X", (unsigned int) uv);
3228
3229                                 d = off + SvGROW(sv, off
3230                                                      + output_length
3231                                                      + (STRLEN)(send - e)
3232                                                      + 2);      /* '}' +  NUL */
3233                                 Copy(hex_string, d, output_length, char);
3234                                 d += output_length;
3235                             }
3236
3237                             *d++ = '}'; /* Done.  Add the trailing brace */
3238                         }
3239                     }
3240                     else { /* Here, not in a pattern.  Convert the name to a
3241                             * string. */
3242
3243                          /* If destination is not in utf8, unconditionally
3244                           * recode it to be so.  This is because \N{} implies
3245                           * Unicode semantics, and scalars have to be in utf8
3246                           * to guarantee those semantics */
3247                         if (! has_utf8) {
3248                             SvCUR_set(sv, d - SvPVX_const(sv));
3249                             SvPOK_on(sv);
3250                             *d = '\0';
3251                             /* See Note on sizing above.  */
3252                             sv_utf8_upgrade_flags_grow(sv,
3253                                                 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3254                                                 len + (STRLEN)(send - s) + 1);
3255                             d = SvPVX(sv) + SvCUR(sv);
3256                             has_utf8 = TRUE;
3257                         } else if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
3258
3259                             /* See Note on sizing above.  (NOTE: SvCUR() is not
3260                              * set correctly here). */
3261                             const STRLEN off = d - SvPVX_const(sv);
3262                             d = off + SvGROW(sv, off + len + (STRLEN)(send - s) + 1);
3263                         }
3264                         Copy(str, d, len, char);
3265                         d += len;
3266                     }
3267                     SvREFCNT_dec(res);
3268
3269                     /* Deprecate non-approved name syntax */
3270                     if (ckWARN_d(WARN_DEPRECATED)) {
3271                         bool problematic = FALSE;
3272                         char* i = s;
3273
3274                         /* For non-ut8 input, look to see that the first
3275                          * character is an alpha, then loop through the rest
3276                          * checking that each is a continuation */
3277                         if (! this_utf8) {
3278                             if (! isALPHAU(*i)) problematic = TRUE;
3279                             else for (i = s + 1; i < e; i++) {
3280                                 if (isCHARNAME_CONT(*i)) continue;
3281                                 problematic = TRUE;
3282                                 break;
3283                             }
3284                         }
3285                         else {
3286                             /* Similarly for utf8.  For invariants can check
3287                              * directly.  We accept anything above the latin1
3288                              * range because it is immaterial to Perl if it is
3289                              * correct or not, and is expensive to check.  But
3290                              * it is fairly easy in the latin1 range to convert
3291                              * the variants into a single character and check
3292                              * those */
3293                             if (UTF8_IS_INVARIANT(*i)) {
3294                                 if (! isALPHAU(*i)) problematic = TRUE;
3295                             } else if (UTF8_IS_DOWNGRADEABLE_START(*i)) {
3296                                 if (! isALPHAU(UNI_TO_NATIVE(UTF8_ACCUMULATE(*i,
3297                                                                             *(i+1)))))
3298                                 {
3299                                     problematic = TRUE;
3300                                 }
3301                             }
3302                             if (! problematic) for (i = s + UTF8SKIP(s);
3303                                                     i < e;
3304                                                     i+= UTF8SKIP(i))
3305                             {
3306                                 if (UTF8_IS_INVARIANT(*i)) {
3307                                     if (isCHARNAME_CONT(*i)) continue;
3308                                 } else if (! UTF8_IS_DOWNGRADEABLE_START(*i)) {
3309                                     continue;
3310                                 } else if (isCHARNAME_CONT(
3311                                             UNI_TO_NATIVE(
3312                                             UTF8_ACCUMULATE(*i, *(i+1)))))
3313                                 {
3314                                     continue;
3315                                 }
3316                                 problematic = TRUE;
3317                                 break;
3318                             }
3319                         }
3320                         if (problematic) {
3321                             /* The e-i passed to the final %.*s makes sure that
3322                              * should the trailing NUL be missing that this
3323                              * print won't run off the end of the string */
3324                             Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
3325                                         "Deprecated character in \\N{...}; marked by <-- HERE  in \\N{%.*s<-- HERE %.*s",
3326                                         (int)(i - s + 1), s, (int)(e - i), i + 1);
3327                         }
3328                     }
3329                 } /* End \N{NAME} */
3330 #ifdef EBCDIC
3331                 if (!dorange) 
3332                     native_range = FALSE; /* \N{} is defined to be Unicode */
3333 #endif
3334                 s = e + 1;  /* Point to just after the '}' */
3335                 continue;
3336
3337             /* \c is a control character */
3338             case 'c':
3339                 s++;
3340                 if (s < send) {
3341                     *d++ = grok_bslash_c(*s++, 1);
3342                 }
3343                 else {
3344                     yyerror("Missing control char name in \\c");
3345                 }
3346                 continue;
3347
3348             /* printf-style backslashes, formfeeds, newlines, etc */
3349             case 'b':
3350                 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
3351                 break;
3352             case 'n':
3353                 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
3354                 break;
3355             case 'r':
3356                 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
3357                 break;
3358             case 'f':
3359                 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
3360                 break;
3361             case 't':
3362                 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
3363                 break;
3364             case 'e':
3365                 *d++ = ASCII_TO_NEED(has_utf8,'\033');
3366                 break;
3367             case 'a':
3368                 *d++ = ASCII_TO_NEED(has_utf8,'\007');
3369                 break;
3370             } /* end switch */
3371
3372             s++;
3373             continue;
3374         } /* end if (backslash) */
3375 #ifdef EBCDIC
3376         else
3377             literal_endpoint++;
3378 #endif
3379
3380     default_action:
3381         /* If we started with encoded form, or already know we want it,
3382            then encode the next character */
3383         if (! NATIVE_IS_INVARIANT((U8)(*s)) && (this_utf8 || has_utf8)) {
3384             STRLEN len  = 1;
3385
3386
3387             /* One might think that it is wasted effort in the case of the
3388              * source being utf8 (this_utf8 == TRUE) to take the next character
3389              * in the source, convert it to an unsigned value, and then convert
3390              * it back again.  But the source has not been validated here.  The
3391              * routine that does the conversion checks for errors like
3392              * malformed utf8 */
3393
3394             const UV nextuv   = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
3395             const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
3396             if (!has_utf8) {
3397                 SvCUR_set(sv, d - SvPVX_const(sv));
3398                 SvPOK_on(sv);
3399                 *d = '\0';
3400                 /* See Note on sizing above.  */
3401                 sv_utf8_upgrade_flags_grow(sv,
3402                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3403                                         need + (STRLEN)(send - s) + 1);
3404                 d = SvPVX(sv) + SvCUR(sv);
3405                 has_utf8 = TRUE;
3406             } else if (need > len) {
3407                 /* encoded value larger than old, may need extra space (NOTE:
3408                  * SvCUR() is not set correctly here).   See Note on sizing
3409                  * above.  */
3410                 const STRLEN off = d - SvPVX_const(sv);
3411                 d = SvGROW(sv, off + need + (STRLEN)(send - s) + 1) + off;
3412             }
3413             s += len;
3414
3415             d = (char*)uvchr_to_utf8((U8*)d, nextuv);
3416 #ifdef EBCDIC
3417             if (uv > 255 && !dorange)
3418                 native_range = FALSE;
3419 #endif
3420         }
3421         else {
3422             *d++ = NATIVE_TO_NEED(has_utf8,*s++);
3423         }
3424     } /* while loop to process each character */
3425
3426     /* terminate the string and set up the sv */
3427     *d = '\0';
3428     SvCUR_set(sv, d - SvPVX_const(sv));
3429     if (SvCUR(sv) >= SvLEN(sv))
3430         Perl_croak(aTHX_ "panic: constant overflowed allocated space");
3431
3432     SvPOK_on(sv);
3433     if (PL_encoding && !has_utf8) {
3434         sv_recode_to_utf8(sv, PL_encoding);
3435         if (SvUTF8(sv))
3436             has_utf8 = TRUE;
3437     }
3438     if (has_utf8) {
3439         SvUTF8_on(sv);
3440         if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
3441             PL_sublex_info.sub_op->op_private |=
3442                     (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
3443         }
3444     }
3445
3446     /* shrink the sv if we allocated more than we used */
3447     if (SvCUR(sv) + 5 < SvLEN(sv)) {
3448         SvPV_shrink_to_cur(sv);
3449     }
3450
3451     /* return the substring (via pl_yylval) only if we parsed anything */
3452     if (s > PL_bufptr) {
3453         if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) {
3454             const char *const key = PL_lex_inpat ? "qr" : "q";
3455             const STRLEN keylen = PL_lex_inpat ? 2 : 1;
3456             const char *type;
3457             STRLEN typelen;
3458
3459             if (PL_lex_inwhat == OP_TRANS) {
3460                 type = "tr";
3461                 typelen = 2;
3462             } else if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) {
3463                 type = "s";
3464                 typelen = 1;
3465             } else  {
3466                 type = "qq";
3467                 typelen = 2;
3468             }
3469
3470             sv = S_new_constant(aTHX_ start, s - start, key, keylen, sv, NULL,
3471                                 type, typelen);
3472         }
3473         pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3474     } else
3475         SvREFCNT_dec(sv);
3476     return s;
3477 }
3478
3479 /* S_intuit_more
3480  * Returns TRUE if there's more to the expression (e.g., a subscript),
3481  * FALSE otherwise.
3482  *
3483  * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
3484  *
3485  * ->[ and ->{ return TRUE
3486  * { and [ outside a pattern are always subscripts, so return TRUE
3487  * if we're outside a pattern and it's not { or [, then return FALSE
3488  * if we're in a pattern and the first char is a {
3489  *   {4,5} (any digits around the comma) returns FALSE
3490  * if we're in a pattern and the first char is a [
3491  *   [] returns FALSE
3492  *   [SOMETHING] has a funky algorithm to decide whether it's a
3493  *      character class or not.  It has to deal with things like
3494  *      /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
3495  * anything else returns TRUE
3496  */
3497
3498 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
3499
3500 STATIC int
3501 S_intuit_more(pTHX_ register char *s)
3502 {
3503     dVAR;
3504
3505     PERL_ARGS_ASSERT_INTUIT_MORE;
3506
3507     if (PL_lex_brackets)
3508         return TRUE;
3509     if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
3510         return TRUE;
3511     if (*s != '{' && *s != '[')
3512         return FALSE;
3513     if (!PL_lex_inpat)
3514         return TRUE;
3515
3516     /* In a pattern, so maybe we have {n,m}. */
3517     if (*s == '{') {
3518         if (regcurly(s)) {
3519             return FALSE;
3520         }
3521         return TRUE;
3522     }
3523
3524     /* On the other hand, maybe we have a character class */
3525
3526     s++;
3527     if (*s == ']' || *s == '^')
3528         return FALSE;
3529     else {
3530         /* this is terrifying, and it works */
3531         int weight = 2;         /* let's weigh the evidence */
3532         char seen[256];
3533         unsigned char un_char = 255, last_un_char;
3534         const char * const send = strchr(s,']');
3535         char tmpbuf[sizeof PL_tokenbuf * 4];
3536
3537         if (!send)              /* has to be an expression */
3538             return TRUE;
3539
3540         Zero(seen,256,char);
3541         if (*s == '$')
3542             weight -= 3;
3543         else if (isDIGIT(*s)) {
3544             if (s[1] != ']') {
3545                 if (isDIGIT(s[1]) && s[2] == ']')
3546                     weight -= 10;
3547             }
3548             else
3549                 weight -= 100;
3550         }
3551         for (; s < send; s++) {
3552             last_un_char = un_char;
3553             un_char = (unsigned char)*s;
3554             switch (*s) {
3555             case '@':
3556             case '&':
3557             case '$':
3558                 weight -= seen[un_char] * 10;
3559                 if (isALNUM_lazy_if(s+1,UTF)) {
3560                     int len;
3561                     scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
3562                     len = (int)strlen(tmpbuf);
3563                     if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
3564                         weight -= 100;
3565                     else
3566                         weight -= 10;
3567                 }
3568                 else if (*s == '$' && s[1] &&
3569                   strchr("[#!%*<>()-=",s[1])) {
3570                     if (/*{*/ strchr("])} =",s[2]))
3571                         weight -= 10;
3572                     else
3573                         weight -= 1;
3574                 }
3575                 break;
3576             case '\\':
3577                 un_char = 254;
3578                 if (s[1]) {
3579                     if (strchr("wds]",s[1]))
3580                         weight += 100;
3581                     else if (seen[(U8)'\''] || seen[(U8)'"'])
3582                         weight += 1;
3583                     else if (strchr("rnftbxcav",s[1]))
3584                         weight += 40;
3585                     else if (isDIGIT(s[1])) {
3586                         weight += 40;
3587                         while (s[1] && isDIGIT(s[1]))
3588                             s++;
3589                     }
3590                 }
3591                 else
3592                     weight += 100;
3593                 break;
3594             case '-':
3595                 if (s[1] == '\\')
3596                     weight += 50;
3597                 if (strchr("aA01! ",last_un_char))
3598                     weight += 30;
3599                 if (strchr("zZ79~",s[1]))
3600                     weight += 30;
3601                 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
3602                     weight -= 5;        /* cope with negative subscript */
3603                 break;
3604             default:
3605                 if (!isALNUM(last_un_char)
3606                     && !(last_un_char == '$' || last_un_char == '@'
3607                          || last_un_char == '&')
3608                     && isALPHA(*s) && s[1] && isALPHA(s[1])) {
3609                     char *d = tmpbuf;
3610                     while (isALPHA(*s))
3611                         *d++ = *s++;
3612                     *d = '\0';
3613                     if (keyword(tmpbuf, d - tmpbuf, 0))
3614                         weight -= 150;
3615                 }
3616                 if (un_char == last_un_char + 1)
3617                     weight += 5;
3618                 weight -= seen[un_char];
3619                 break;
3620             }
3621             seen[un_char]++;
3622         }
3623         if (weight >= 0)        /* probably a character class */
3624             return FALSE;
3625     }
3626
3627     return TRUE;
3628 }
3629
3630 /*
3631  * S_intuit_method
3632  *
3633  * Does all the checking to disambiguate
3634  *   foo bar
3635  * between foo(bar) and bar->foo.  Returns 0 if not a method, otherwise
3636  * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
3637  *
3638  * First argument is the stuff after the first token, e.g. "bar".
3639  *
3640  * Not a method if bar is a filehandle.
3641  * Not a method if foo is a subroutine prototyped to take a filehandle.
3642  * Not a method if it's really "Foo $bar"
3643  * Method if it's "foo $bar"
3644  * Not a method if it's really "print foo $bar"
3645  * Method if it's really "foo package::" (interpreted as package->foo)
3646  * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
3647  * Not a method if bar is a filehandle or package, but is quoted with
3648  *   =>
3649  */
3650
3651 STATIC int
3652 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
3653 {
3654     dVAR;
3655     char *s = start + (*start == '$');
3656     char tmpbuf[sizeof PL_tokenbuf];
3657     STRLEN len;
3658     GV* indirgv;
3659 #ifdef PERL_MAD
3660     int soff;
3661 #endif
3662
3663     PERL_ARGS_ASSERT_INTUIT_METHOD;
3664
3665     if (gv) {
3666         if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
3667             return 0;
3668         if (cv) {
3669             if (SvPOK(cv)) {
3670                 const char *proto = SvPVX_const(cv);
3671                 if (proto) {
3672                     if (*proto == ';')
3673                         proto++;
3674                     if (*proto == '*')
3675                         return 0;
3676                 }
3677             }
3678         } else
3679             gv = NULL;
3680     }
3681     s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3682     /* start is the beginning of the possible filehandle/object,
3683      * and s is the end of it
3684      * tmpbuf is a copy of it
3685      */
3686
3687     if (*start == '$') {
3688         if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
3689                 isUPPER(*PL_tokenbuf))
3690             return 0;
3691 #ifdef PERL_MAD
3692         len = start - SvPVX(PL_linestr);
3693 #endif
3694         s = PEEKSPACE(s);
3695 #ifdef PERL_MAD
3696         start = SvPVX(PL_linestr) + len;
3697 #endif
3698         PL_bufptr = start;
3699         PL_expect = XREF;
3700         return *s == '(' ? FUNCMETH : METHOD;
3701     }
3702     if (!keyword(tmpbuf, len, 0)) {
3703         if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
3704             len -= 2;
3705             tmpbuf[len] = '\0';
3706 #ifdef PERL_MAD
3707             soff = s - SvPVX(PL_linestr);
3708 #endif
3709             goto bare_package;
3710         }
3711         indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
3712         if (indirgv && GvCVu(indirgv))
3713             return 0;
3714         /* filehandle or package name makes it a method */
3715         if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
3716 #ifdef PERL_MAD
3717             soff = s - SvPVX(PL_linestr);
3718 #endif
3719             s = PEEKSPACE(s);
3720             if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
3721                 return 0;       /* no assumptions -- "=>" quotes bearword */
3722       bare_package:
3723             start_force(PL_curforce);
3724             NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
3725                                                   S_newSV_maybe_utf8(aTHX_ tmpbuf, len));
3726             NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
3727             if (PL_madskills)
3728                 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
3729             PL_expect = XTERM;
3730             force_next(WORD);
3731             PL_bufptr = s;
3732 #ifdef PERL_MAD
3733             PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
3734 #endif
3735             return *s == '(' ? FUNCMETH : METHOD;
3736         }
3737     }
3738     return 0;
3739 }
3740
3741 /* Encoded script support. filter_add() effectively inserts a
3742  * 'pre-processing' function into the current source input stream.
3743  * Note that the filter function only applies to the current source file
3744  * (e.g., it will not affect files 'require'd or 'use'd by this one).
3745  *
3746  * The datasv parameter (which may be NULL) can be used to pass
3747  * private data to this instance of the filter. The filter function
3748  * can recover the SV using the FILTER_DATA macro and use it to
3749  * store private buffers and state information.
3750  *
3751  * The supplied datasv parameter is upgraded to a PVIO type
3752  * and the IoDIRP/IoANY field is used to store the function pointer,
3753  * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
3754  * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
3755  * private use must be set using malloc'd pointers.
3756  */
3757
3758 SV *
3759 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
3760 {
3761     dVAR;
3762     if (!funcp)
3763         return NULL;
3764
3765     if (!PL_parser)
3766         return NULL;
3767
3768     if (!PL_rsfp_filters)
3769         PL_rsfp_filters = newAV();
3770     if (!datasv)
3771         datasv = newSV(0);
3772     SvUPGRADE(datasv, SVt_PVIO);
3773     IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
3774     IoFLAGS(datasv) |= IOf_FAKE_DIRP;
3775     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
3776                           FPTR2DPTR(void *, IoANY(datasv)),
3777                           SvPV_nolen(datasv)));
3778     av_unshift(PL_rsfp_filters, 1);
3779     av_store(PL_rsfp_filters, 0, datasv) ;
3780     return(datasv);
3781 }
3782
3783
3784 /* Delete most recently added instance of this filter function. */
3785 void
3786 Perl_filter_del(pTHX_ filter_t funcp)
3787 {
3788     dVAR;
3789     SV *datasv;
3790
3791     PERL_ARGS_ASSERT_FILTER_DEL;
3792
3793 #ifdef DEBUGGING
3794     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
3795                           FPTR2DPTR(void*, funcp)));
3796 #endif
3797     if (!PL_parser || !PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
3798         return;
3799     /* if filter is on top of stack (usual case) just pop it off */
3800     datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
3801     if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
3802         sv_free(av_pop(PL_rsfp_filters));
3803
3804         return;
3805     }
3806     /* we need to search for the correct entry and clear it     */
3807     Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
3808 }
3809
3810
3811 /* Invoke the idxth filter function for the current rsfp.        */
3812 /* maxlen 0 = read one text line */
3813 I32
3814 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
3815 {
3816     dVAR;
3817     filter_t funcp;
3818     SV *datasv = NULL;
3819     /* This API is bad. It should have been using unsigned int for maxlen.
3820        Not sure if we want to change the API, but if not we should sanity
3821        check the value here.  */
3822     const unsigned int correct_length
3823         = maxlen < 0 ?
3824 #ifdef PERL_MICRO
3825         0x7FFFFFFF
3826 #else
3827         INT_MAX
3828 #endif
3829         : maxlen;
3830
3831     PERL_ARGS_ASSERT_FILTER_READ;
3832
3833     if (!PL_parser || !PL_rsfp_filters)
3834         return -1;
3835     if (idx > AvFILLp(PL_rsfp_filters)) {       /* Any more filters?    */
3836         /* Provide a default input filter to make life easy.    */
3837         /* Note that we append to the line. This is handy.      */
3838         DEBUG_P(PerlIO_printf(Perl_debug_log,
3839                               "filter_read %d: from rsfp\n", idx));
3840         if (correct_length) {
3841             /* Want a block */
3842             int len ;
3843             const int old_len = SvCUR(buf_sv);
3844
3845             /* ensure buf_sv is large enough */
3846             SvGROW(buf_sv, (STRLEN)(old_len + correct_length + 1)) ;
3847             if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
3848                                    correct_length)) <= 0) {
3849                 if (PerlIO_error(PL_rsfp))
3850                     return -1;          /* error */
3851                 else
3852                     return 0 ;          /* end of file */
3853             }
3854             SvCUR_set(buf_sv, old_len + len) ;
3855             SvPVX(buf_sv)[old_len + len] = '\0';
3856         } else {
3857             /* Want a line */
3858             if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
3859                 if (PerlIO_error(PL_rsfp))
3860                     return -1;          /* error */
3861                 else
3862                     return 0 ;          /* end of file */
3863             }
3864         }
3865         return SvCUR(buf_sv);
3866     }
3867     /* Skip this filter slot if filter has been deleted */
3868     if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
3869         DEBUG_P(PerlIO_printf(Perl_debug_log,
3870                               "filter_read %d: skipped (filter deleted)\n",
3871                               idx));
3872         return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
3873     }
3874     /* Get function pointer hidden within datasv        */
3875     funcp = DPTR2FPTR(filter_t, IoANY(datasv));
3876     DEBUG_P(PerlIO_printf(Perl_debug_log,
3877                           "filter_read %d: via function %p (%s)\n",
3878                           idx, (void*)datasv, SvPV_nolen_const(datasv)));
3879     /* Call function. The function is expected to       */
3880     /* call "FILTER_READ(idx+1, buf_sv)" first.         */
3881     /* Return: <0:error, =0:eof, >0:not eof             */
3882     return (*funcp)(aTHX_ idx, buf_sv, correct_length);
3883 }
3884
3885 STATIC char *
3886 S_filter_gets(pTHX_ register SV *sv, STRLEN append)
3887 {
3888     dVAR;
3889
3890     PERL_ARGS_ASSERT_FILTER_GETS;
3891
3892 #ifdef PERL_CR_FILTER
3893     if (!PL_rsfp_filters) {
3894         filter_add(S_cr_textfilter,NULL);
3895     }
3896 #endif
3897     if (PL_rsfp_filters) {
3898         if (!append)
3899             SvCUR_set(sv, 0);   /* start with empty line        */
3900         if (FILTER_READ(0, sv, 0) > 0)
3901             return ( SvPVX(sv) ) ;
3902         else
3903             return NULL ;
3904     }
3905     else
3906         return (sv_gets(sv, PL_rsfp, append));
3907 }
3908
3909 STATIC HV *
3910 S_find_in_my_stash(pTHX_ const char *pkgname, STRLEN len)
3911 {
3912     dVAR;
3913     GV *gv;
3914
3915     PERL_ARGS_ASSERT_FIND_IN_MY_STASH;
3916
3917     if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
3918         return PL_curstash;
3919
3920     if (len > 2 &&
3921         (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
3922         (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
3923     {
3924         return GvHV(gv);                        /* Foo:: */
3925     }
3926
3927     /* use constant CLASS => 'MyClass' */
3928     gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
3929     if (gv && GvCV(gv)) {
3930         SV * const sv = cv_const_sv(GvCV(gv));
3931         if (sv)
3932             pkgname = SvPV_const(sv, len);
3933     }
3934
3935     return gv_stashpvn(pkgname, len, 0);
3936 }
3937
3938 /*
3939  * S_readpipe_override
3940  * Check whether readpipe() is overriden, and generates the appropriate
3941  * optree, provided sublex_start() is called afterwards.
3942  */
3943 STATIC void
3944 S_readpipe_override(pTHX)
3945 {
3946     GV **gvp;
3947     GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
3948     pl_yylval.ival = OP_BACKTICK;
3949     if ((gv_readpipe
3950                 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
3951             ||
3952             ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
3953              && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
3954              && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
3955     {
3956         PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
3957             op_append_elem(OP_LIST,
3958                 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
3959                 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
3960     }
3961 }
3962
3963 #ifdef PERL_MAD 
3964  /*
3965  * Perl_madlex
3966  * The intent of this yylex wrapper is to minimize the changes to the
3967  * tokener when we aren't interested in collecting madprops.  It remains
3968  * to be seen how successful this strategy will be...
3969  */
3970
3971 int
3972 Perl_madlex(pTHX)
3973 {
3974     int optype;
3975     char *s = PL_bufptr;
3976
3977     /* make sure PL_thiswhite is initialized */
3978     PL_thiswhite = 0;
3979     PL_thismad = 0;
3980
3981     /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
3982     if (PL_lex_state != LEX_KNOWNEXT && PL_pending_ident)
3983         return S_pending_ident(aTHX);
3984
3985     /* previous token ate up our whitespace? */
3986     if (!PL_lasttoke && PL_nextwhite) {
3987         PL_thiswhite = PL_nextwhite;
3988         PL_nextwhite = 0;
3989     }
3990
3991     /* isolate the token, and figure out where it is without whitespace */
3992     PL_realtokenstart = -1;
3993     PL_thistoken = 0;
3994     optype = yylex();
3995     s = PL_bufptr;
3996     assert(PL_curforce < 0);
3997
3998     if (!PL_thismad || PL_thismad->mad_key == '^') {    /* not forced already? */
3999         if (!PL_thistoken) {
4000             if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
4001                 PL_thistoken = newSVpvs("");
4002             else {
4003                 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
4004                 PL_thistoken = newSVpvn(tstart, s - tstart);
4005             }
4006         }
4007         if (PL_thismad) /* install head */
4008             CURMAD('X', PL_thistoken);
4009     }
4010
4011     /* last whitespace of a sublex? */
4012     if (optype == ')' && PL_endwhite) {
4013         CURMAD('X', PL_endwhite);
4014     }
4015
4016     if (!PL_thismad) {
4017
4018         /* if no whitespace and we're at EOF, bail.  Otherwise fake EOF below. */
4019         if (!PL_thiswhite && !PL_endwhite && !optype) {
4020             sv_free(PL_thistoken);
4021             PL_thistoken = 0;
4022             return 0;
4023         }
4024
4025         /* put off final whitespace till peg */
4026         if (optype == ';' && !PL_rsfp) {
4027             PL_nextwhite = PL_thiswhite;
4028             PL_thiswhite = 0;
4029         }
4030         else if (PL_thisopen) {
4031             CURMAD('q', PL_thisopen);
4032             if (PL_thistoken)
4033                 sv_free(PL_thistoken);
4034             PL_thistoken = 0;
4035         }
4036         else {
4037             /* Store actual token text as madprop X */
4038             CURMAD('X', PL_thistoken);
4039         }
4040
4041         if (PL_thiswhite) {
4042             /* add preceding whitespace as madprop _ */
4043             CURMAD('_', PL_thiswhite);
4044         }
4045
4046         if (PL_thisstuff) {
4047             /* add quoted material as madprop = */
4048             CURMAD('=', PL_thisstuff);
4049         }
4050
4051         if (PL_thisclose) {
4052             /* add terminating quote as madprop Q */
4053             CURMAD('Q', PL_thisclose);
4054         }
4055     }
4056
4057     /* special processing based on optype */
4058
4059     switch (optype) {
4060
4061     /* opval doesn't need a TOKEN since it can already store mp */
4062     case WORD:
4063     case METHOD:
4064     case FUNCMETH:
4065     case THING:
4066     case PMFUNC:
4067     case PRIVATEREF:
4068     case FUNC0SUB:
4069     case UNIOPSUB:
4070     case LSTOPSUB:
4071         if (pl_yylval.opval)
4072             append_madprops(PL_thismad, pl_yylval.opval, 0);
4073         PL_thismad = 0;
4074         return optype;
4075
4076     /* fake EOF */
4077     case 0:
4078         optype = PEG;
4079         if (PL_endwhite) {
4080             addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
4081             PL_endwhite = 0;
4082         }
4083         break;
4084
4085     case ']':
4086     case '}':
4087         if (PL_faketokens)
4088             break;
4089         /* remember any fake bracket that lexer is about to discard */ 
4090         if (PL_lex_brackets == 1 &&
4091             ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
4092         {
4093             s = PL_bufptr;
4094             while (s < PL_bufend && (*s == ' ' || *s == '\t'))
4095                 s++;
4096             if (*s == '}') {
4097                 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
4098                 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
4099                 PL_thiswhite = 0;
4100                 PL_bufptr = s - 1;
4101                 break;  /* don't bother looking for trailing comment */
4102             }
4103             else
4104                 s = PL_bufptr;
4105         }
4106         if (optype == ']')
4107             break;
4108         /* FALLTHROUGH */
4109
4110     /* attach a trailing comment to its statement instead of next token */
4111     case ';':
4112         if (PL_faketokens)
4113             break;
4114         if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
4115             s = PL_bufptr;
4116             while (s < PL_bufend && (*s == ' ' || *s == '\t'))
4117                 s++;
4118             if (*s == '\n' || *s == '#') {
4119                 while (s < PL_bufend && *s != '\n')
4120                     s++;
4121                 if (s < PL_bufend)
4122                     s++;
4123                 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
4124                 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
4125                 PL_thiswhite = 0;
4126                 PL_bufptr = s;
4127             }
4128         }
4129         break;
4130
4131     /* pval */
4132     case LABEL:
4133         break;
4134
4135     /* ival */
4136     default:
4137         break;
4138
4139     }
4140
4141     /* Create new token struct.  Note: opvals return early above. */
4142     pl_yylval.tkval = newTOKEN(optype, pl_yylval, PL_thismad);
4143     PL_thismad = 0;
4144     return optype;
4145 }
4146 #endif
4147
4148 STATIC char *
4149 S_tokenize_use(pTHX_ int is_use, char *s) {
4150     dVAR;
4151
4152     PERL_ARGS_ASSERT_TOKENIZE_USE;
4153
4154     if (PL_expect != XSTATE)
4155         yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
4156                     is_use ? "use" : "no"));
4157     s = SKIPSPACE1(s);
4158     if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
4159         s = force_version(s, TRUE);
4160         if (*s == ';' || *s == '}'
4161                 || (s = SKIPSPACE1(s), (*s == ';' || *s == '}'))) {
4162             start_force(PL_curforce);
4163             NEXTVAL_NEXTTOKE.opval = NULL;
4164             force_next(WORD);
4165         }
4166         else if (*s == 'v') {
4167             s = force_word(s,WORD,FALSE,TRUE,FALSE);
4168             s = force_version(s, FALSE);
4169         }
4170     }
4171     else {
4172         s = force_word(s,WORD,FALSE,TRUE,FALSE);
4173         s = force_version(s, FALSE);
4174     }
4175     pl_yylval.ival = is_use;
4176     return s;
4177 }
4178 #ifdef DEBUGGING
4179     static const char* const exp_name[] =
4180         { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
4181           "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
4182         };
4183 #endif
4184
4185 #define word_takes_any_delimeter(p,l) S_word_takes_any_delimeter(p,l)
4186 STATIC bool
4187 S_word_takes_any_delimeter(char *p, STRLEN len)
4188 {
4189     return (len == 1 && strchr("msyq", p[0])) ||
4190            (len == 2 && (
4191             (p[0] == 't' && p[1] == 'r') ||
4192             (p[0] == 'q' && strchr("qwxr", p[1]))));
4193 }
4194
4195 /*
4196   yylex
4197
4198   Works out what to call the token just pulled out of the input
4199   stream.  The yacc parser takes care of taking the ops we return and
4200   stitching them into a tree.
4201
4202   Returns:
4203     PRIVATEREF
4204
4205   Structure:
4206       if read an identifier
4207           if we're in a my declaration
4208               croak if they tried to say my($foo::bar)
4209               build the ops for a my() declaration
4210           if it's an access to a my() variable
4211               are we in a sort block?
4212                   croak if my($a); $a <=> $b
4213               build ops for access to a my() variable
4214           if in a dq string, and they've said @foo and we can't find @foo
4215               croak
4216           build ops for a bareword
4217       if we already built the token before, use it.
4218 */
4219
4220
4221 #ifdef __SC__
4222 #pragma segment Perl_yylex
4223 #endif
4224 int
4225 Perl_yylex(pTHX)
4226 {
4227     dVAR;
4228     register char *s = PL_bufptr;
4229     register char *d;
4230     STRLEN len;
4231     bool bof = FALSE;
4232     U32 fake_eof = 0;
4233
4234     /* orig_keyword, gvp, and gv are initialized here because
4235      * jump to the label just_a_word_zero can bypass their
4236      * initialization later. */
4237     I32 orig_keyword = 0;
4238     GV *gv = NULL;
4239     GV **gvp = NULL;
4240
4241     DEBUG_T( {
4242         SV* tmp = newSVpvs("");
4243         PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
4244             (IV)CopLINE(PL_curcop),
4245             lex_state_names[PL_lex_state],
4246             exp_name[PL_expect],
4247             pv_display(tmp, s, strlen(s), 0, 60));
4248         SvREFCNT_dec(tmp);
4249     } );
4250     /* check if there's an identifier for us to look at */
4251     if (PL_lex_state != LEX_KNOWNEXT && PL_pending_ident)
4252         return REPORT(S_pending_ident(aTHX));
4253
4254     /* no identifier pending identification */
4255
4256     switch (PL_lex_state) {
4257 #ifdef COMMENTARY
4258     case LEX_NORMAL:            /* Some compilers will produce faster */
4259     case LEX_INTERPNORMAL:      /* code if we comment these out. */
4260         break;
4261 #endif
4262
4263     /* when we've already built the next token, just pull it out of the queue */
4264     case LEX_KNOWNEXT:
4265 #ifdef PERL_MAD
4266         PL_lasttoke--;
4267         pl_yylval = PL_nexttoke[PL_lasttoke].next_val;
4268         if (PL_madskills) {
4269             PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
4270             PL_nexttoke[PL_lasttoke].next_mad = 0;
4271             if (PL_thismad && PL_thismad->mad_key == '_') {
4272                 PL_thiswhite = MUTABLE_SV(PL_thismad->mad_val);
4273                 PL_thismad->mad_val = 0;
4274                 mad_free(PL_thismad);
4275                 PL_thismad = 0;
4276             }
4277         }
4278         if (!PL_lasttoke) {
4279             PL_lex_state = PL_lex_defer;
4280             PL_expect = PL_lex_expect;
4281             PL_lex_defer = LEX_NORMAL;
4282             if (!PL_nexttoke[PL_lasttoke].next_type)
4283                 return yylex();
4284         }
4285 #else
4286         PL_nexttoke--;
4287         pl_yylval = PL_nextval[PL_nexttoke];
4288         if (!PL_nexttoke) {
4289             PL_lex_state = PL_lex_defer;
4290             PL_expect = PL_lex_expect;
4291             PL_lex_defer = LEX_NORMAL;
4292         }
4293 #endif
4294         {
4295             I32 next_type;
4296 #ifdef PERL_MAD
4297             next_type = PL_nexttoke[PL_lasttoke].next_type;
4298 #else
4299             next_type = PL_nexttype[PL_nexttoke];
4300 #endif
4301             if (next_type & (1<<24)) {
4302                 if (PL_lex_brackets > 100)
4303                     Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4304                 PL_lex_brackstack[PL_lex_brackets++] = (next_type >> 16) & 0xff;
4305                 next_type &= 0xffff;
4306             }
4307 #ifdef PERL_MAD
4308             /* FIXME - can these be merged?  */
4309             return next_type;
4310 #else
4311             return REPORT(next_type);
4312 #endif
4313         }
4314
4315     /* interpolated case modifiers like \L \U, including \Q and \E.
4316        when we get here, PL_bufptr is at the \
4317     */
4318     case LEX_INTERPCASEMOD:
4319 #ifdef DEBUGGING
4320         if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
4321             Perl_croak(aTHX_ "panic: INTERPCASEMOD");
4322 #endif
4323         /* handle \E or end of string */
4324         if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
4325             /* if at a \E */
4326             if (PL_lex_casemods) {
4327                 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
4328                 PL_lex_casestack[PL_lex_casemods] = '\0';
4329
4330                 if (PL_bufptr != PL_bufend
4331                     && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
4332                     PL_bufptr += 2;
4333                     PL_lex_state = LEX_INTERPCONCAT;
4334 #ifdef PERL_MAD
4335                     if (PL_madskills)
4336                         PL_thistoken = newSVpvs("\\E");
4337 #endif
4338                 }
4339                 return REPORT(')');
4340             }
4341 #ifdef PERL_MAD
4342             while (PL_bufptr != PL_bufend &&
4343               PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
4344                 if (!PL_thiswhite)
4345                     PL_thiswhite = newSVpvs("");
4346                 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
4347                 PL_bufptr += 2;
4348             }
4349 #else
4350             if (PL_bufptr != PL_bufend)
4351                 PL_bufptr += 2;
4352 #endif
4353             PL_lex_state = LEX_INTERPCONCAT;
4354             return yylex();
4355         }
4356         else {
4357             DEBUG_T({ PerlIO_printf(Perl_debug_log,
4358               "### Saw case modifier\n"); });
4359             s = PL_bufptr + 1;
4360             if (s[1] == '\\' && s[2] == 'E') {
4361 #ifdef PERL_MAD
4362                 if (!PL_thiswhite)
4363                     PL_thiswhite = newSVpvs("");
4364                 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
4365 #endif
4366                 PL_bufptr = s + 3;
4367                 PL_lex_state = LEX_INTERPCONCAT;
4368                 return yylex();
4369             }
4370             else {
4371                 I32 tmp;
4372                 if (!PL_madskills) /* when just compiling don't need correct */
4373                     if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
4374                         tmp = *s, *s = s[2], s[2] = (char)tmp;  /* misordered... */
4375                 if ((*s == 'L' || *s == 'U') &&
4376                     (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
4377                     PL_lex_casestack[--PL_lex_casemods] = '\0';
4378                     return REPORT(')');
4379                 }
4380                 if (PL_lex_casemods > 10)
4381                     Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
4382                 PL_lex_casestack[PL_lex_casemods++] = *s;
4383                 PL_lex_casestack[PL_lex_casemods] = '\0';
4384                 PL_lex_state = LEX_INTERPCONCAT;
4385                 start_force(PL_curforce);
4386                 NEXTVAL_NEXTTOKE.ival = 0;
4387                 force_next('(');
4388                 start_force(PL_curforce);
4389                 if (*s == 'l')
4390                     NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
4391                 else if (*s == 'u')
4392                     NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
4393                 else if (*s == 'L')
4394                     NEXTVAL_NEXTTOKE.ival = OP_LC;
4395                 else if (*s == 'U')
4396                     NEXTVAL_NEXTTOKE.ival = OP_UC;
4397                 else if (*s == 'Q')
4398                     NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
4399                 else
4400                     Perl_croak(aTHX_ "panic: yylex");
4401                 if (PL_madskills) {
4402                     SV* const tmpsv = newSVpvs("\\ ");
4403                     /* replace the space with the character we want to escape
4404                      */
4405                     SvPVX(tmpsv)[1] = *s;
4406                     curmad('_', tmpsv);
4407                 }
4408                 PL_bufptr = s + 1;
4409             }
4410             force_next(FUNC);
4411             if (PL_lex_starts) {
4412                 s = PL_bufptr;
4413                 PL_lex_starts = 0;
4414 #ifdef PERL_MAD
4415                 if (PL_madskills) {
4416                     if (PL_thistoken)
4417                         sv_free(PL_thistoken);
4418                     PL_thistoken = newSVpvs("");
4419                 }
4420 #endif
4421                 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4422                 if (PL_lex_casemods == 1 && PL_lex_inpat)
4423                     OPERATOR(',');
4424                 else
4425                     Aop(OP_CONCAT);
4426             }
4427             else
4428                 return yylex();
4429         }
4430
4431     case LEX_INTERPPUSH:
4432         return REPORT(sublex_push());
4433
4434     case LEX_INTERPSTART:
4435         if (PL_bufptr == PL_bufend)
4436             return REPORT(sublex_done());
4437         DEBUG_T({ PerlIO_printf(Perl_debug_log,
4438               "### Interpolated variable\n"); });
4439         PL_expect = XTERM;
4440         PL_lex_dojoin = (*PL_bufptr == '@');
4441         PL_lex_state = LEX_INTERPNORMAL;
4442         if (PL_lex_dojoin) {
4443             start_force(PL_curforce);
4444             NEXTVAL_NEXTTOKE.ival = 0;
4445             force_next(',');
4446             start_force(PL_curforce);
4447             force_ident("\"", '$');
4448             start_force(PL_curforce);
4449             NEXTVAL_NEXTTOKE.ival = 0;
4450             force_next('$');
4451             start_force(PL_curforce);
4452             NEXTVAL_NEXTTOKE.ival = 0;
4453             force_next('(');
4454             start_force(PL_curforce);
4455             NEXTVAL_NEXTTOKE.ival = OP_JOIN;    /* emulate join($", ...) */
4456             force_next(FUNC);
4457         }
4458         if (PL_lex_starts++) {
4459             s = PL_bufptr;
4460 #ifdef PERL_MAD
4461             if (PL_madskills) {
4462                 if (PL_thistoken)
4463                     sv_free(PL_thistoken);
4464                 PL_thistoken = newSVpvs("");
4465             }
4466 #endif
4467             /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4468             if (!PL_lex_casemods && PL_lex_inpat)
4469                 OPERATOR(',');
4470             else
4471                 Aop(OP_CONCAT);
4472         }
4473         return yylex();
4474
4475     case LEX_INTERPENDMAYBE:
4476         if (intuit_more(PL_bufptr)) {
4477             PL_lex_state = LEX_INTERPNORMAL;    /* false alarm, more expr */
4478             break;
4479         }
4480         /* FALL THROUGH */
4481
4482     case LEX_INTERPEND:
4483         if (PL_lex_dojoin) {
4484             PL_lex_dojoin = FALSE;
4485             PL_lex_state = LEX_INTERPCONCAT;
4486 #ifdef PERL_MAD
4487             if (PL_madskills) {
4488                 if (PL_thistoken)
4489                     sv_free(PL_thistoken);
4490                 PL_thistoken = newSVpvs("");
4491             }
4492 #endif
4493             return REPORT(')');
4494         }
4495         if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
4496             && SvEVALED(PL_lex_repl))
4497         {
4498             if (PL_bufptr != PL_bufend)
4499                 Perl_croak(aTHX_ "Bad evalled substitution pattern");
4500             PL_lex_repl = NULL;
4501         }
4502         /* FALLTHROUGH */
4503     case LEX_INTERPCONCAT:
4504 #ifdef DEBUGGING
4505         if (PL_lex_brackets)
4506             Perl_croak(aTHX_ "panic: INTERPCONCAT");
4507 #endif
4508         if (PL_bufptr == PL_bufend)
4509             return REPORT(sublex_done());
4510
4511         if (SvIVX(PL_linestr) == '\'') {
4512             SV *sv = newSVsv(PL_linestr);
4513             if (!PL_lex_inpat)
4514                 sv = tokeq(sv);
4515             else if ( PL_hints & HINT_NEW_RE )
4516                 sv = new_constant(NULL, 0, "qr", sv, sv, "q", 1);
4517             pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4518             s = PL_bufend;
4519         }
4520         else {
4521             s = scan_const(PL_bufptr);
4522             if (*s == '\\')
4523                 PL_lex_state = LEX_INTERPCASEMOD;
4524             else
4525                 PL_lex_state = LEX_INTERPSTART;
4526         }
4527
4528         if (s != PL_bufptr) {
4529             start_force(PL_curforce);
4530             if (PL_madskills) {
4531                 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
4532             }
4533             NEXTVAL_NEXTTOKE = pl_yylval;
4534             PL_expect = XTERM;
4535             force_next(THING);
4536             if (PL_lex_starts++) {
4537 #ifdef PERL_MAD
4538                 if (PL_madskills) {
4539                     if (PL_thistoken)
4540                         sv_free(PL_thistoken);
4541                     PL_thistoken = newSVpvs("");
4542                 }
4543 #endif
4544                 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4545                 if (!PL_lex_casemods && PL_lex_inpat)
4546                     OPERATOR(',');
4547                 else
4548                     Aop(OP_CONCAT);
4549             }
4550             else {
4551                 PL_bufptr = s;
4552                 return yylex();
4553             }
4554         }
4555
4556         return yylex();
4557     case LEX_FORMLINE:
4558         PL_lex_state = LEX_NORMAL;
4559         s = scan_formline(PL_bufptr);
4560         if (!PL_lex_formbrack)
4561             goto rightbracket;
4562         OPERATOR(';');
4563     }
4564
4565     s = PL_bufptr;
4566     PL_oldoldbufptr = PL_oldbufptr;
4567     PL_oldbufptr = s;
4568
4569   retry:
4570 #ifdef PERL_MAD
4571     if (PL_thistoken) {
4572         sv_free(PL_thistoken);
4573         PL_thistoken = 0;
4574     }
4575     PL_realtokenstart = s - SvPVX(PL_linestr);  /* assume but undo on ws */
4576 #endif
4577     switch (*s) {
4578     default:
4579         if (isIDFIRST_lazy_if(s,UTF))
4580             goto keylookup;
4581         {
4582         unsigned char c = *s;
4583         len = UTF ? Perl_utf8_length(aTHX_ (U8 *) PL_linestart, (U8 *) s) : (STRLEN) (s - PL_linestart);
4584         if (len > UNRECOGNIZED_PRECEDE_COUNT) {
4585             d = UTF ? (char *) Perl_utf8_hop(aTHX_ (U8 *) s, -UNRECOGNIZED_PRECEDE_COUNT) : s - UNRECOGNIZED_PRECEDE_COUNT;
4586         } else {
4587             d = PL_linestart;
4588         }       
4589         *s = '\0';
4590         Perl_croak(aTHX_ "Unrecognized character \\x%02X; marked by <-- HERE after %s<-- HERE near column %d", c, d, (int) len + 1);
4591     }
4592     case 4:
4593     case 26:
4594         goto fake_eof;                  /* emulate EOF on ^D or ^Z */
4595     case 0:
4596 #ifdef PERL_MAD
4597         if (PL_madskills)
4598             PL_faketokens = 0;
4599 #endif
4600         if (!PL_rsfp) {
4601             PL_last_uni = 0;
4602             PL_last_lop = 0;
4603             if (PL_lex_brackets &&
4604                     PL_lex_brackstack[PL_lex_brackets-1] != XFAKEEOF) {
4605                 yyerror((const char *)
4606                         (PL_lex_formbrack
4607                          ? "Format not terminated"
4608                          : "Missing right curly or square bracket"));
4609             }
4610             DEBUG_T( { PerlIO_printf(Perl_debug_log,
4611                         "### Tokener got EOF\n");
4612             } );
4613             TOKEN(0);
4614         }
4615         if (s++ < PL_bufend)
4616             goto retry;                 /* ignore stray nulls */
4617         PL_last_uni = 0;
4618         PL_last_lop = 0;
4619         if (!PL_in_eval && !PL_preambled) {
4620             PL_preambled = TRUE;
4621 #ifdef PERL_MAD
4622             if (PL_madskills)
4623                 PL_faketokens = 1;
4624 #endif
4625             if (PL_perldb) {
4626                 /* Generate a string of Perl code to load the debugger.
4627                  * If PERL5DB is set, it will return the contents of that,
4628                  * otherwise a compile-time require of perl5db.pl.  */
4629
4630                 const char * const pdb = PerlEnv_getenv("PERL5DB");
4631
4632                 if (pdb) {
4633                     sv_setpv(PL_linestr, pdb);
4634                     sv_catpvs(PL_linestr,";");
4635                 } else {
4636                     SETERRNO(0,SS_NORMAL);
4637                     sv_setpvs(PL_linestr, "BEGIN { require 'perl5db.pl' };");
4638                 }
4639             } else
4640                 sv_setpvs(PL_linestr,"");
4641             if (PL_preambleav) {
4642                 SV **svp = AvARRAY(PL_preambleav);
4643                 SV **const end = svp + AvFILLp(PL_preambleav);
4644                 while(svp <= end) {
4645                     sv_catsv(PL_linestr, *svp);
4646                     ++svp;
4647                     sv_catpvs(PL_linestr, ";");
4648                 }
4649                 sv_free(MUTABLE_SV(PL_preambleav));
4650                 PL_preambleav = NULL;
4651             }
4652             if (PL_minus_E)
4653                 sv_catpvs(PL_linestr,
4654                           "use feature ':5." STRINGIFY(PERL_VERSION) "';");
4655             if (PL_minus_n || PL_minus_p) {
4656                 sv_catpvs(PL_linestr, "LINE: while (<>) {"/*}*/);
4657                 if (PL_minus_l)
4658                     sv_catpvs(PL_linestr,"chomp;");
4659                 if (PL_minus_a) {
4660                     if (PL_minus_F) {
4661                         if ((*PL_splitstr == '/' || *PL_splitstr == '\''
4662                              || *PL_splitstr == '"')
4663                               && strchr(PL_splitstr + 1, *PL_splitstr))
4664                             Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
4665                         else {
4666                             /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
4667                                bytes can be used as quoting characters.  :-) */
4668                             const char *splits = PL_splitstr;
4669                             sv_catpvs(PL_linestr, "our @F=split(q\0");
4670                             do {
4671                                 /* Need to \ \s  */
4672                                 if (*splits == '\\')
4673                                     sv_catpvn(PL_linestr, splits, 1);
4674                                 sv_catpvn(PL_linestr, splits, 1);
4675                             } while (*splits++);
4676                             /* This loop will embed the trailing NUL of
4677                                PL_linestr as the last thing it does before
4678                                terminating.  */
4679                             sv_catpvs(PL_linestr, ");");
4680                         }
4681                     }
4682                     else
4683                         sv_catpvs(PL_linestr,"our @F=split(' ');");
4684                 }
4685             }
4686             sv_catpvs(PL_linestr, "\n");
4687             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4688             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4689             PL_last_lop = PL_last_uni = NULL;
4690             if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
4691                 update_debugger_info(PL_linestr, NULL, 0);
4692             goto retry;
4693         }
4694         do {
4695             fake_eof = 0;
4696             bof = PL_rsfp ? TRUE : FALSE;
4697             if (0) {
4698               fake_eof:
4699                 fake_eof = LEX_FAKE_EOF;
4700             }
4701             PL_bufptr = PL_bufend;
4702             CopLINE_inc(PL_curcop);
4703             if (!lex_next_chunk(fake_eof)) {
4704                 CopLINE_dec(PL_curcop);
4705                 s = PL_bufptr;
4706                 TOKEN(';');     /* not infinite loop because rsfp is NULL now */
4707             }
4708             CopLINE_dec(PL_curcop);
4709 #ifdef PERL_MAD
4710             if (!PL_rsfp)
4711                 PL_realtokenstart = -1;
4712 #endif
4713             s = PL_bufptr;
4714             /* If it looks like the start of a BOM or raw UTF-16,
4715              * check if it in fact is. */
4716             if (bof && PL_rsfp &&
4717                      (*s == 0 ||
4718                       *(U8*)s == 0xEF ||
4719                       *(U8*)s >= 0xFE ||
4720                       s[1] == 0)) {
4721                 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
4722                 if (bof) {
4723                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4724                     s = swallow_bom((U8*)s);
4725                 }
4726             }
4727             if (PL_parser->in_pod) {
4728                 /* Incest with pod. */
4729 #ifdef PERL_MAD
4730                 if (PL_madskills)
4731                     sv_catsv(PL_thiswhite, PL_linestr);
4732 #endif
4733                 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
4734                     sv_setpvs(PL_linestr, "");
4735                     PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4736                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4737                     PL_last_lop = PL_last_uni = NULL;
4738                     PL_parser->in_pod = 0;
4739                 }
4740             }
4741             if (PL_rsfp)
4742                 incline(s);
4743         } while (PL_parser->in_pod);
4744         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
4745         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4746         PL_last_lop = PL_last_uni = NULL;
4747         if (CopLINE(PL_curcop) == 1) {
4748             while (s < PL_bufend && isSPACE(*s))
4749                 s++;
4750             if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
4751                 s++;
4752 #ifdef PERL_MAD
4753             if (PL_madskills)
4754                 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
4755 #endif
4756             d = NULL;
4757             if (!PL_in_eval) {
4758                 if (*s == '#' && *(s+1) == '!')
4759                     d = s + 2;
4760 #ifdef ALTERNATE_SHEBANG
4761                 else {
4762                     static char const as[] = ALTERNATE_SHEBANG;
4763                     if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
4764                         d = s + (sizeof(as) - 1);
4765                 }
4766 #endif /* ALTERNATE_SHEBANG */
4767             }
4768             if (d) {
4769                 char *ipath;
4770                 char *ipathend;
4771
4772                 while (isSPACE(*d))
4773                     d++;
4774                 ipath = d;
4775                 while (*d && !isSPACE(*d))
4776                     d++;
4777                 ipathend = d;
4778
4779 #ifdef ARG_ZERO_IS_SCRIPT
4780                 if (ipathend > ipath) {
4781                     /*
4782                      * HP-UX (at least) sets argv[0] to the script name,
4783                      * which makes $^X incorrect.  And Digital UNIX and Linux,
4784                      * at least, set argv[0] to the basename of the Perl
4785                      * interpreter. So, having found "#!", we'll set it right.
4786                      */
4787                     SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
4788                                                     SVt_PV)); /* $^X */
4789                     assert(SvPOK(x) || SvGMAGICAL(x));
4790                     if (sv_eq(x, CopFILESV(PL_curcop))) {
4791                         sv_setpvn(x, ipath, ipathend - ipath);
4792                         SvSETMAGIC(x);
4793                     }
4794                     else {
4795                         STRLEN blen;
4796                         STRLEN llen;
4797                         const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
4798                         const char * const lstart = SvPV_const(x,llen);
4799                         if (llen < blen) {
4800                             bstart += blen - llen;
4801                             if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
4802                                 sv_setpvn(x, ipath, ipathend - ipath);
4803                                 SvSETMAGIC(x);
4804                             }
4805                         }
4806                     }
4807                     TAINT_NOT;  /* $^X is always tainted, but that's OK */
4808                 }
4809 #endif /* ARG_ZERO_IS_SCRIPT */
4810
4811                 /*
4812                  * Look for options.
4813                  */
4814                 d = instr(s,"perl -");
4815                 if (!d) {
4816                     d = instr(s,"perl");
4817 #if defined(DOSISH)
4818                     /* avoid getting into infinite loops when shebang
4819                      * line contains "Perl" rather than "perl" */
4820                     if (!d) {
4821                         for (d = ipathend-4; d >= ipath; --d) {
4822                             if ((*d == 'p' || *d == 'P')
4823                                 && !ibcmp(d, "perl", 4))
4824                             {
4825                                 break;
4826                             }
4827                         }
4828                         if (d < ipath)
4829                             d = NULL;
4830                     }
4831 #endif
4832                 }
4833 #ifdef ALTERNATE_SHEBANG
4834                 /*
4835                  * If the ALTERNATE_SHEBANG on this system starts with a
4836                  * character that can be part of a Perl expression, then if
4837                  * we see it but not "perl", we're probably looking at the
4838                  * start of Perl code, not a request to hand off to some
4839                  * other interpreter.  Similarly, if "perl" is there, but
4840                  * not in the first 'word' of the line, we assume the line
4841                  * contains the start of the Perl program.
4842                  */
4843                 if (d && *s != '#') {
4844                     const char *c = ipath;
4845                     while (*c && !strchr("; \t\r\n\f\v#", *c))
4846                         c++;
4847                     if (c < d)
4848                         d = NULL;       /* "perl" not in first word; ignore */
4849                     else
4850                         *s = '#';       /* Don't try to parse shebang line */
4851                 }
4852 #endif /* ALTERNATE_SHEBANG */
4853                 if (!d &&
4854                     *s == '#' &&
4855                     ipathend > ipath &&
4856                     !PL_minus_c &&
4857                     !instr(s,"indir") &&
4858                     instr(PL_origargv[0],"perl"))
4859                 {
4860                     dVAR;
4861                     char **newargv;
4862
4863                     *ipathend = '\0';
4864                     s = ipathend + 1;
4865                     while (s < PL_bufend && isSPACE(*s))
4866                         s++;
4867                     if (s < PL_bufend) {
4868                         Newx(newargv,PL_origargc+3,char*);
4869                         newargv[1] = s;
4870                         while (s < PL_bufend && !isSPACE(*s))
4871                             s++;
4872                         *s = '\0';
4873                         Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
4874                     }
4875                     else
4876                         newargv = PL_origargv;
4877                     newargv[0] = ipath;
4878                     PERL_FPU_PRE_EXEC
4879                     PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
4880                     PERL_FPU_POST_EXEC
4881                     Perl_croak(aTHX_ "Can't exec %s", ipath);
4882                 }
4883                 if (d) {
4884                     while (*d && !isSPACE(*d))
4885                         d++;
4886                     while (SPACE_OR_TAB(*d))
4887                         d++;
4888
4889                     if (*d++ == '-') {
4890                         const bool switches_done = PL_doswitches;
4891                         const U32 oldpdb = PL_perldb;
4892                         const bool oldn = PL_minus_n;
4893                         const bool oldp = PL_minus_p;
4894                         const char *d1 = d;
4895
4896                         do {
4897                             bool baduni = FALSE;
4898                             if (*d1 == 'C') {
4899                                 const char *d2 = d1 + 1;
4900                                 if (parse_unicode_opts((const char **)&d2)
4901                                     != PL_unicode)
4902                                     baduni = TRUE;
4903                             }
4904                             if (baduni || *d1 == 'M' || *d1 == 'm') {
4905                                 const char * const m = d1;
4906                                 while (*d1 && !isSPACE(*d1))
4907                                     d1++;
4908                                 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
4909                                       (int)(d1 - m), m);
4910                             }
4911                             d1 = moreswitches(d1);
4912                         } while (d1);
4913                         if (PL_doswitches && !switches_done) {
4914                             int argc = PL_origargc;
4915                             char **argv = PL_origargv;
4916                             do {
4917                                 argc--,argv++;
4918                             } while (argc && argv[0][0] == '-' && argv[0][1]);
4919                             init_argv_symbols(argc,argv);
4920                         }
4921                         if (((PERLDB_LINE || PERLDB_SAVESRC) && !oldpdb) ||
4922                             ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
4923                               /* if we have already added "LINE: while (<>) {",
4924                                  we must not do it again */
4925                         {
4926                             sv_setpvs(PL_linestr, "");
4927                             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4928                             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4929                             PL_last_lop = PL_last_uni = NULL;
4930                             PL_preambled = FALSE;
4931                             if (PERLDB_LINE || PERLDB_SAVESRC)
4932                                 (void)gv_fetchfile(PL_origfilename);
4933                             goto retry;
4934                         }
4935                     }
4936                 }
4937             }
4938         }
4939         if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4940             PL_bufptr = s;
4941             PL_lex_state = LEX_FORMLINE;
4942             return yylex();
4943         }
4944         goto retry;
4945     case '\r':
4946 #ifdef PERL_STRICT_CR
4947         Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
4948         Perl_croak(aTHX_
4949       "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
4950 #endif
4951     case ' ': case '\t': case '\f': case 013:
4952 #ifdef PERL_MAD
4953         PL_realtokenstart = -1;
4954         if (!PL_thiswhite)
4955             PL_thiswhite = newSVpvs("");
4956         sv_catpvn(PL_thiswhite, s, 1);
4957 #endif
4958         s++;
4959         goto retry;
4960     case '#':
4961     case '\n':
4962 #ifdef PERL_MAD
4963         PL_realtokenstart = -1;
4964         if (PL_madskills)
4965             PL_faketokens = 0;
4966 #endif
4967         if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
4968             if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
4969                 /* handle eval qq[#line 1 "foo"\n ...] */
4970                 CopLINE_dec(PL_curcop);
4971                 incline(s);
4972             }
4973             if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
4974                 s = SKIPSPACE0(s);
4975                 if (!PL_in_eval || PL_rsfp)
4976                     incline(s);
4977             }
4978             else {
4979                 d = s;
4980                 while (d < PL_bufend && *d != '\n')
4981                     d++;
4982                 if (d < PL_bufend)
4983                     d++;
4984                 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4985                   Perl_croak(aTHX_ "panic: input overflow");
4986 #ifdef PERL_MAD
4987                 if (PL_madskills)
4988                     PL_thiswhite = newSVpvn(s, d - s);
4989 #endif
4990                 s = d;
4991                 incline(s);
4992             }
4993             if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4994                 PL_bufptr = s;
4995                 PL_lex_state = LEX_FORMLINE;
4996                 return yylex();
4997             }
4998         }
4999         else {
5000 #ifdef PERL_MAD
5001             if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
5002                 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
5003                     PL_faketokens = 0;
5004                     s = SKIPSPACE0(s);
5005                     TOKEN(PEG); /* make sure any #! line is accessible */
5006                 }
5007                 s = SKIPSPACE0(s);
5008             }
5009             else {
5010 /*              if (PL_madskills && PL_lex_formbrack) { */
5011                     d = s;
5012                     while (d < PL_bufend && *d != '\n')
5013                         d++;
5014                     if (d < PL_bufend)
5015                         d++;
5016                     else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
5017                       Perl_croak(aTHX_ "panic: input overflow");
5018                     if (PL_madskills && CopLINE(PL_curcop) >= 1) {
5019                         if (!PL_thiswhite)
5020                             PL_thiswhite = newSVpvs("");
5021                         if (CopLINE(PL_curcop) == 1) {
5022                             sv_setpvs(PL_thiswhite, "");
5023                             PL_faketokens = 0;
5024                         }
5025                         sv_catpvn(PL_thiswhite, s, d - s);
5026                     }
5027                     s = d;
5028 /*              }
5029                 *s = '\0';
5030                 PL_bufend = s; */
5031             }
5032 #else
5033             *s = '\0';
5034             PL_bufend = s;
5035 #endif
5036         }
5037         goto retry;
5038     case '-':
5039         if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
5040             I32 ftst = 0;
5041             char tmp;
5042
5043             s++;
5044             PL_bufptr = s;
5045             tmp = *s++;
5046
5047             while (s < PL_bufend && SPACE_OR_TAB(*s))
5048                 s++;
5049
5050             if (strnEQ(s,"=>",2)) {
5051                 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
5052                 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
5053                 OPERATOR('-');          /* unary minus */
5054             }
5055             PL_last_uni = PL_oldbufptr;
5056             switch (tmp) {
5057             case 'r': ftst = OP_FTEREAD;        break;
5058             case 'w': ftst = OP_FTEWRITE;       break;
5059             case 'x': ftst = OP_FTEEXEC;        break;
5060             case 'o': ftst = OP_FTEOWNED;       break;
5061             case 'R': ftst = OP_FTRREAD;        break;
5062             case 'W': ftst = OP_FTRWRITE;       break;
5063             case 'X': ftst = OP_FTREXEC;        break;
5064             case 'O': ftst = OP_FTROWNED;       break;
5065             case 'e': ftst = OP_FTIS;           break;
5066             case 'z': ftst = OP_FTZERO;         break;
5067             case 's': ftst = OP_FTSIZE;         break;
5068             case 'f': ftst = OP_FTFILE;         break;
5069             case 'd': ftst = OP_FTDIR;          break;
5070             case 'l': ftst = OP_FTLINK;         break;
5071             case 'p': ftst = OP_FTPIPE;         break;
5072             case 'S': ftst = OP_FTSOCK;         break;
5073             case 'u': ftst = OP_FTSUID;         break;
5074             case 'g': ftst = OP_FTSGID;         break;
5075             case 'k': ftst = OP_FTSVTX;         break;
5076             case 'b': ftst = OP_FTBLK;          break;
5077             case 'c': ftst = OP_FTCHR;          break;
5078             case 't': ftst = OP_FTTTY;          break;
5079             case 'T': ftst = OP_FTTEXT;         break;
5080             case 'B': ftst = OP_FTBINARY;       break;
5081             case 'M': case 'A': case 'C':
5082                 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
5083                 switch (tmp) {
5084                 case 'M': ftst = OP_FTMTIME;    break;
5085                 case 'A': ftst = OP_FTATIME;    break;
5086                 case 'C': ftst = OP_FTCTIME;    break;
5087                 default:                        break;
5088                 }
5089                 break;
5090             default:
5091                 break;
5092             }
5093             if (ftst) {
5094                 PL_last_lop_op = (OPCODE)ftst;
5095                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
5096                         "### Saw file test %c\n", (int)tmp);
5097                 } );
5098                 FTST(ftst);
5099             }
5100             else {
5101                 /* Assume it was a minus followed by a one-letter named
5102                  * subroutine call (or a -bareword), then. */
5103                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
5104                         "### '-%c' looked like a file test but was not\n",
5105                         (int) tmp);
5106                 } );
5107                 s = --PL_bufptr;
5108             }
5109         }
5110         {
5111             const char tmp = *s++;
5112             if (*s == tmp) {
5113                 s++;
5114                 if (PL_expect == XOPERATOR)
5115                     TERM(POSTDEC);
5116                 else
5117                     OPERATOR(PREDEC);
5118             }
5119             else if (*s == '>') {
5120                 s++;
5121                 s = SKIPSPACE1(s);
5122                 if (isIDFIRST_lazy_if(s,UTF)) {
5123                     s = force_word(s,METHOD,FALSE,TRUE,FALSE);
5124                     TOKEN(ARROW);
5125                 }
5126                 else if (*s == '$')
5127                     OPERATOR(ARROW);
5128                 else
5129                     TERM(ARROW);
5130             }
5131             if (PL_expect == XOPERATOR)
5132                 Aop(OP_SUBTRACT);
5133             else {
5134                 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
5135                     check_uni();
5136                 OPERATOR('-');          /* unary minus */
5137             }
5138         }
5139
5140     case '+':
5141         {
5142             const char tmp = *s++;
5143             if (*s == tmp) {
5144                 s++;
5145                 if (PL_expect == XOPERATOR)
5146                     TERM(POSTINC);
5147                 else
5148                     OPERATOR(PREINC);
5149             }
5150             if (PL_expect == XOPERATOR)
5151                 Aop(OP_ADD);
5152             else {
5153                 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
5154                     check_uni();
5155                 OPERATOR('+');
5156             }
5157         }
5158
5159     case '*':
5160         if (PL_expect != XOPERATOR) {
5161             s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5162             PL_expect = XOPERATOR;
5163             force_ident(PL_tokenbuf, '*');
5164             if (!*PL_tokenbuf)
5165                 PREREF('*');
5166             TERM('*');
5167         }
5168         s++;
5169         if (*s == '*') {
5170             s++;
5171             PWop(OP_POW);
5172         }
5173         Mop(OP_MULTIPLY);
5174
5175     case '%':
5176         if (PL_expect == XOPERATOR) {
5177             ++s;
5178             Mop(OP_MODULO);
5179         }
5180         PL_tokenbuf[0] = '%';
5181         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
5182                 sizeof PL_tokenbuf - 1, FALSE);
5183         if (!PL_tokenbuf[1]) {
5184             PREREF('%');
5185         }
5186         PL_pending_ident = '%';
5187         TERM('%');
5188
5189     case '^':
5190         s++;
5191         BOop(OP_BIT_XOR);
5192     case '[':
5193         if (PL_lex_brackets > 100)
5194             Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
5195         PL_lex_brackstack[PL_lex_brackets++] = 0;
5196         {
5197             const char tmp = *s++;
5198             OPERATOR(tmp);
5199         }
5200     case '~':
5201         if (s[1] == '~'
5202             && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
5203         {
5204             s += 2;
5205             Eop(OP_SMARTMATCH);
5206         }
5207     case ',':
5208         {
5209             const char tmp = *s++;
5210             OPERATOR(tmp);
5211         }
5212     case ':':
5213         if (s[1] == ':') {
5214             len = 0;
5215             goto just_a_word_zero_gv;
5216         }
5217         s++;
5218         switch (PL_expect) {
5219             OP *attrs;
5220 #ifdef PERL_MAD
5221             I32 stuffstart;
5222 #endif
5223         case XOPERATOR:
5224             if (!PL_in_my || PL_lex_state != LEX_NORMAL)
5225                 break;
5226             PL_bufptr = s;      /* update in case we back off */
5227             if (*s == '=') {
5228                 deprecate(":= for an empty attribute list");
5229             }
5230             goto grabattrs;
5231         case XATTRBLOCK:
5232             PL_expect = XBLOCK;
5233             goto grabattrs;
5234         case XATTRTERM:
5235             PL_expect = XTERMBLOCK;
5236          grabattrs:
5237 #ifdef PERL_MAD
5238             stuffstart = s - SvPVX(PL_linestr) - 1;
5239 #endif
5240             s = PEEKSPACE(s);
5241             attrs = NULL;
5242             while (isIDFIRST_lazy_if(s,UTF)) {
5243                 I32 tmp;
5244                 SV *sv;
5245                 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5246                 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
5247                     if (tmp < 0) tmp = -tmp;
5248                     switch (tmp) {
5249                     case KEY_or:
5250                     case KEY_and:
5251                     case KEY_for:
5252                     case KEY_foreach:
5253                     case KEY_unless:
5254                     case KEY_if:
5255                     case KEY_while:
5256                     case KEY_until:
5257                         goto got_attrs;
5258                     default:
5259                         break;
5260                     }
5261                 }
5262                 sv = newSVpvn(s, len);
5263                 if (*d == '(') {
5264                     d = scan_str(d,TRUE,TRUE);
5265                     if (!d) {
5266                         /* MUST advance bufptr here to avoid bogus
5267                            "at end of line" context messages from yyerror().
5268                          */
5269                         PL_bufptr = s + len;
5270                         yyerror("Unterminated attribute parameter in attribute list");
5271                         if (attrs)
5272                             op_free(attrs);
5273                         sv_free(sv);
5274                         return REPORT(0);       /* EOF indicator */
5275                     }
5276                 }
5277                 if (PL_lex_stuff) {
5278                     sv_catsv(sv, PL_lex_stuff);
5279                     attrs = op_append_elem(OP_LIST, attrs,
5280                                         newSVOP(OP_CONST, 0, sv));
5281                     SvREFCNT_dec(PL_lex_stuff);
5282                     PL_lex_stuff = NULL;
5283                 }
5284                 else {
5285                     if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
5286                         sv_free(sv);
5287                         if (PL_in_my == KEY_our) {
5288                             deprecate(":unique");
5289                         }
5290                         else
5291                             Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
5292                     }
5293
5294                     /* NOTE: any CV attrs applied here need to be part of
5295                        the CVf_BUILTIN_ATTRS define in cv.h! */
5296                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
5297                         sv_free(sv);
5298                         CvLVALUE_on(PL_compcv);
5299                     }
5300                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
5301                         sv_free(sv);
5302                         deprecate(":locked");
5303                     }
5304                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
5305                         sv_free(sv);
5306                         CvMETHOD_on(PL_compcv);
5307                     }
5308                     /* After we've set the flags, it could be argued that
5309                        we don't need to do the attributes.pm-based setting
5310                        process, and shouldn't bother appending recognized
5311                        flags.  To experiment with that, uncomment the
5312                        following "else".  (Note that's already been
5313                        uncommented.  That keeps the above-applied built-in
5314                        attributes from being intercepted (and possibly
5315                        rejected) by a package's attribute routines, but is
5316                        justified by the performance win for the common case
5317                        of applying only built-in attributes.) */
5318                     else
5319                         attrs = op_append_elem(OP_LIST, attrs,
5320                                             newSVOP(OP_CONST, 0,
5321                                                     sv));
5322                 }
5323                 s = PEEKSPACE(d);
5324                 if (*s == ':' && s[1] != ':')
5325                     s = PEEKSPACE(s+1);
5326                 else if (s == d)
5327                     break;      /* require real whitespace or :'s */
5328                 /* XXX losing whitespace on sequential attributes here */
5329             }
5330             {
5331                 const char tmp
5332                     = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
5333                 if (*s != ';' && *s != '}' && *s != tmp
5334                     && (tmp != '=' || *s != ')')) {
5335                     const char q = ((*s == '\'') ? '"' : '\'');
5336                     /* If here for an expression, and parsed no attrs, back
5337                        off. */
5338                     if (tmp == '=' && !attrs) {
5339                         s = PL_bufptr;
5340                         break;
5341                     }
5342                     /* MUST advance bufptr here to avoid bogus "at end of line"
5343                        context messages from yyerror().
5344                     */
5345                     PL_bufptr = s;
5346                     yyerror( (const char *)
5347                              (*s
5348                               ? Perl_form(aTHX_ "Invalid separator character "
5349                                           "%c%c%c in attribute list", q, *s, q)
5350                               : "Unterminated attribute list" ) );
5351                     if (attrs)
5352                         op_free(attrs);
5353                     OPERATOR(':');
5354                 }
5355             }
5356         got_attrs:
5357             if (attrs) {
5358                 start_force(PL_curforce);
5359                 NEXTVAL_NEXTTOKE.opval = attrs;
5360                 CURMAD('_', PL_nextwhite);
5361                 force_next(THING);
5362             }
5363 #ifdef PERL_MAD
5364             if (PL_madskills) {
5365                 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
5366                                      (s - SvPVX(PL_linestr)) - stuffstart);
5367             }
5368 #endif
5369             TOKEN(COLONATTR);
5370         }
5371         OPERATOR(':');
5372     case '(':
5373         s++;
5374         if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
5375             PL_oldbufptr = PL_oldoldbufptr;             /* allow print(STDOUT 123) */
5376         else
5377             PL_expect = XTERM;
5378         s = SKIPSPACE1(s);
5379         TOKEN('(');
5380     case ';':
5381         CLINE;
5382         {
5383             const char tmp = *s++;
5384             OPERATOR(tmp);
5385         }
5386     case ')':
5387         {
5388             const char tmp = *s++;
5389             s = SKIPSPACE1(s);
5390             if (*s == '{')
5391                 PREBLOCK(tmp);
5392             TERM(tmp);
5393         }
5394     case ']':
5395         if (PL_lex_brackets && PL_lex_brackstack[PL_lex_brackets-1] == XFAKEEOF)
5396             TOKEN(0);
5397         s++;
5398         if (PL_lex_brackets <= 0)
5399             yyerror("Unmatched right square bracket");
5400         else
5401             --PL_lex_brackets;
5402         if (PL_lex_state == LEX_INTERPNORMAL) {
5403             if (PL_lex_brackets == 0) {
5404                 if (*s == '-' && s[1] == '>')
5405                     PL_lex_state = LEX_INTERPENDMAYBE;
5406                 else if (*s != '[' && *s != '{')
5407                     PL_lex_state = LEX_INTERPEND;
5408             }
5409         }
5410         TERM(']');
5411     case '{':
5412       leftbracket:
5413         s++;
5414         if (PL_lex_brackets > 100) {
5415             Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
5416         }
5417         switch (PL_expect) {
5418         case XTERM:
5419             if (PL_lex_formbrack) {
5420                 s--;
5421                 PRETERMBLOCK(DO);
5422             }
5423             if (PL_oldoldbufptr == PL_last_lop)
5424                 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
5425             else
5426                 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5427             OPERATOR(HASHBRACK);
5428         case XOPERATOR:
5429             while (s < PL_bufend && SPACE_OR_TAB(*s))
5430                 s++;
5431             d = s;
5432             PL_tokenbuf[0] = '\0';
5433             if (d < PL_bufend && *d == '-') {
5434                 PL_tokenbuf[0] = '-';
5435                 d++;
5436                 while (d < PL_bufend && SPACE_OR_TAB(*d))
5437                     d++;
5438             }
5439             if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
5440                 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
5441                               FALSE, &len);
5442                 while (d < PL_bufend && SPACE_OR_TAB(*d))
5443                     d++;
5444                 if (*d == '}') {
5445                     const char minus = (PL_tokenbuf[0] == '-');
5446                     s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
5447                     if (minus)
5448                         force_next('-');
5449                 }
5450             }
5451             /* FALL THROUGH */
5452         case XATTRBLOCK:
5453         case XBLOCK:
5454             PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
5455             PL_expect = XSTATE;
5456             break;
5457         case XATTRTERM:
5458         case XTERMBLOCK:
5459             PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5460             PL_expect = XSTATE;
5461             break;
5462         default: {
5463                 const char *t;
5464                 if (PL_oldoldbufptr == PL_last_lop)
5465                     PL_lex_brackstack[PL_lex_brackets++] = XTERM;
5466                 else
5467                     PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5468                 s = SKIPSPACE1(s);
5469                 if (*s == '}') {
5470                     if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
5471                         PL_expect = XTERM;
5472                         /* This hack is to get the ${} in the message. */
5473                         PL_bufptr = s+1;
5474                         yyerror("syntax error");
5475                         break;
5476                     }
5477                     OPERATOR(HASHBRACK);
5478                 }
5479                 /* This hack serves to disambiguate a pair of curlies
5480                  * as being a block or an anon hash.  Normally, expectation
5481                  * determines that, but in cases where we're not in a
5482                  * position to expect anything in particular (like inside
5483                  * eval"") we have to resolve the ambiguity.  This code
5484                  * covers the case where the first term in the curlies is a
5485                  * quoted string.  Most other cases need to be explicitly
5486                  * disambiguated by prepending a "+" before the opening
5487                  * curly in order to force resolution as an anon hash.
5488                  *
5489                  * XXX should probably propagate the outer expectation
5490                  * into eval"" to rely less on this hack, but that could
5491                  * potentially break current behavior of eval"".
5492                  * GSAR 97-07-21
5493                  */
5494                 t = s;
5495                 if (*s == '\'' || *s == '"' || *s == '`') {
5496                     /* common case: get past first string, handling escapes */
5497                     for (t++; t < PL_bufend && *t != *s;)
5498                         if (*t++ == '\\' && (*t == '\\' || *t == *s))
5499                             t++;
5500                     t++;
5501                 }
5502                 else if (*s == 'q') {
5503                     if (++t < PL_bufend
5504                         && (!isALNUM(*t)
5505                             || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
5506                                 && !isALNUM(*t))))
5507                     {
5508                         /* skip q//-like construct */
5509                         const char *tmps;
5510                         char open, close, term;
5511                         I32 brackets = 1;
5512
5513                         while (t < PL_bufend && isSPACE(*t))
5514                             t++;
5515                         /* check for q => */
5516                         if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
5517                             OPERATOR(HASHBRACK);
5518                         }
5519                         term = *t;
5520                         open = term;
5521                         if (term && (tmps = strchr("([{< )]}> )]}>",term)))
5522                             term = tmps[5];
5523                         close = term;
5524                         if (open == close)
5525                             for (t++; t < PL_bufend; t++) {
5526                                 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
5527                                     t++;
5528                                 else if (*t == open)
5529                                     break;
5530                             }
5531                         else {
5532                             for (t++; t < PL_bufend; t++) {
5533                                 if (*t == '\\' && t+1 < PL_bufend)
5534                                     t++;
5535                                 else if (*t == close && --brackets <= 0)
5536                                     break;
5537                                 else if (*t == open)
5538                                     brackets++;
5539                             }
5540                         }
5541                         t++;
5542                     }
5543                     else
5544                         /* skip plain q word */
5545                         while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
5546                              t += UTF8SKIP(t);
5547                 }
5548                 else if (isALNUM_lazy_if(t,UTF)) {
5549                     t += UTF8SKIP(t);
5550                     while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
5551                          t += UTF8SKIP(t);
5552                 }
5553                 while (t < PL_bufend && isSPACE(*t))
5554                     t++;
5555                 /* if comma follows first term, call it an anon hash */
5556                 /* XXX it could be a comma expression with loop modifiers */
5557                 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
5558                                    || (*t == '=' && t[1] == '>')))
5559                     OPERATOR(HASHBRACK);
5560                 if (PL_expect == XREF)
5561                     PL_expect = XTERM;
5562                 else {
5563                     PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
5564                     PL_expect = XSTATE;
5565                 }
5566             }
5567             break;
5568         }
5569         pl_yylval.ival = CopLINE(PL_curcop);
5570         if (isSPACE(*s) || *s == '#')
5571             PL_copline = NOLINE;   /* invalidate current command line number */
5572         TOKEN('{');
5573     case '}':
5574         if (PL_lex_brackets && PL_lex_brackstack[PL_lex_brackets-1] == XFAKEEOF)
5575             TOKEN(0);
5576       rightbracket:
5577         s++;
5578         if (PL_lex_brackets <= 0)
5579             yyerror("Unmatched right curly bracket");
5580         else
5581             PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
5582         if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
5583             PL_lex_formbrack = 0;
5584         if (PL_lex_state == LEX_INTERPNORMAL) {
5585             if (PL_lex_brackets == 0) {
5586                 if (PL_expect & XFAKEBRACK) {
5587                     PL_expect &= XENUMMASK;
5588                     PL_lex_state = LEX_INTERPEND;
5589                     PL_bufptr = s;
5590 #if 0
5591                     if (PL_madskills) {
5592                         if (!PL_thiswhite)
5593                             PL_thiswhite = newSVpvs("");
5594                         sv_catpvs(PL_thiswhite,"}");
5595                     }
5596 #endif
5597                     return yylex();     /* ignore fake brackets */
5598                 }
5599                 if (*s == '-' && s[1] == '>')
5600                     PL_lex_state = LEX_INTERPENDMAYBE;
5601                 else if (*s != '[' && *s != '{')
5602                     PL_lex_state = LEX_INTERPEND;
5603             }
5604         }
5605         if (PL_expect & XFAKEBRACK) {
5606             PL_expect &= XENUMMASK;
5607             PL_bufptr = s;
5608             return yylex();             /* ignore fake brackets */
5609         }
5610         start_force(PL_curforce);
5611         if (PL_madskills) {
5612             curmad('X', newSVpvn(s-1,1));
5613             CURMAD('_', PL_thiswhite);
5614         }
5615         force_next('}');
5616 #ifdef PERL_MAD
5617         if (!PL_thistoken)
5618             PL_thistoken = newSVpvs("");
5619 #endif
5620         TOKEN(';');
5621     case '&':
5622         s++;
5623         if (*s++ == '&')
5624             AOPERATOR(ANDAND);
5625         s--;
5626         if (PL_expect == XOPERATOR) {
5627             if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
5628                 && isIDFIRST_lazy_if(s,UTF))
5629             {
5630                 CopLINE_dec(PL_curcop);
5631                 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
5632                 CopLINE_inc(PL_curcop);
5633             }
5634             BAop(OP_BIT_AND);
5635         }
5636
5637         s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5638         if (*PL_tokenbuf) {
5639             PL_expect = XOPERATOR;
5640             force_ident(PL_tokenbuf, '&');
5641         }
5642         else
5643             PREREF('&');
5644         pl_yylval.ival = (OPpENTERSUB_AMPER<<8);
5645         TERM('&');
5646
5647     case '|':
5648         s++;
5649         if (*s++ == '|')
5650             AOPERATOR(OROR);
5651         s--;
5652         BOop(OP_BIT_OR);
5653     case '=':
5654         s++;
5655         {
5656             const char tmp = *s++;
5657             if (tmp == '=')
5658                 Eop(OP_EQ);
5659             if (tmp == '>')
5660                 OPERATOR(',');
5661             if (tmp == '~')
5662                 PMop(OP_MATCH);
5663             if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
5664                 && strchr("+-*/%.^&|<",tmp))
5665                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5666                             "Reversed %c= operator",(int)tmp);
5667             s--;
5668             if (PL_expect == XSTATE && isALPHA(tmp) &&
5669                 (s == PL_linestart+1 || s[-2] == '\n') )
5670                 {
5671                     if (PL_in_eval && !PL_rsfp) {
5672                         d = PL_bufend;
5673                         while (s < d) {
5674                             if (*s++ == '\n') {
5675                                 incline(s);
5676                                 if (strnEQ(s,"=cut",4)) {
5677                                     s = strchr(s,'\n');
5678                                     if (s)
5679                                         s++;
5680                                     else
5681                                         s = d;
5682                                     incline(s);
5683                                     goto retry;
5684                                 }
5685                             }
5686                         }
5687                         goto retry;
5688                     }
5689 #ifdef PERL_MAD
5690                     if (PL_madskills) {
5691                         if (!PL_thiswhite)
5692                             PL_thiswhite = newSVpvs("");
5693                         sv_catpvn(PL_thiswhite, PL_linestart,
5694                                   PL_bufend - PL_linestart);
5695                     }
5696 #endif
5697                     s = PL_bufend;
5698                     PL_parser->in_pod = 1;
5699                     goto retry;
5700                 }
5701         }
5702         if (PL_lex_brackets < PL_lex_formbrack) {
5703             const char *t = s;
5704 #ifdef PERL_STRICT_CR
5705             while (SPACE_OR_TAB(*t))
5706 #else
5707             while (SPACE_OR_TAB(*t) || *t == '\r')
5708 #endif
5709                 t++;
5710             if (*t == '\n' || *t == '#') {
5711                 s--;
5712                 PL_expect = XBLOCK;
5713                 goto leftbracket;
5714             }
5715         }
5716         pl_yylval.ival = 0;
5717         OPERATOR(ASSIGNOP);
5718     case '!':
5719         s++;
5720         {
5721             const char tmp = *s++;
5722             if (tmp == '=') {
5723                 /* was this !=~ where !~ was meant?
5724                  * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
5725
5726                 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
5727                     const char *t = s+1;
5728
5729                     while (t < PL_bufend && isSPACE(*t))
5730                         ++t;
5731
5732                     if (*t == '/' || *t == '?' ||
5733                         ((*t == 'm' || *t == 's' || *t == 'y')
5734                          && !isALNUM(t[1])) ||
5735                         (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
5736                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5737                                     "!=~ should be !~");
5738                 }
5739                 Eop(OP_NE);
5740             }
5741             if (tmp == '~')
5742                 PMop(OP_NOT);
5743         }
5744         s--;
5745         OPERATOR('!');
5746     case '<':
5747         if (PL_expect != XOPERATOR) {
5748             if (s[1] != '<' && !strchr(s,'>'))
5749                 check_uni();
5750             if (s[1] == '<')
5751                 s = scan_heredoc(s);
5752             else
5753                 s = scan_inputsymbol(s);
5754             TERM(sublex_start());
5755         }
5756         s++;
5757         {
5758             char tmp = *s++;
5759             if (tmp == '<')
5760                 SHop(OP_LEFT_SHIFT);
5761             if (tmp == '=') {
5762                 tmp = *s++;
5763                 if (tmp == '>')
5764                     Eop(OP_NCMP);
5765                 s--;
5766                 Rop(OP_LE);
5767             }
5768         }
5769         s--;
5770         Rop(OP_LT);
5771     case '>':
5772         s++;
5773         {
5774             const char tmp = *s++;
5775             if (tmp == '>')
5776                 SHop(OP_RIGHT_SHIFT);
5777             else if (tmp == '=')
5778                 Rop(OP_GE);
5779         }
5780         s--;
5781         Rop(OP_GT);
5782
5783     case '$':
5784         CLINE;
5785
5786         if (PL_expect == XOPERATOR) {
5787             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5788                 return deprecate_commaless_var_list();
5789             }
5790         }
5791
5792         if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-@", s[2]))) {
5793             PL_tokenbuf[0] = '@';
5794             s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
5795                            sizeof PL_tokenbuf - 1, FALSE);
5796             if (PL_expect == XOPERATOR)
5797                 no_op("Array length", s);
5798             if (!PL_tokenbuf[1])
5799                 PREREF(DOLSHARP);
5800             PL_expect = XOPERATOR;
5801             PL_pending_ident = '#';
5802             TOKEN(DOLSHARP);
5803         }
5804
5805         PL_tokenbuf[0] = '$';
5806         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
5807                        sizeof PL_tokenbuf - 1, FALSE);
5808         if (PL_expect == XOPERATOR)
5809             no_op("Scalar", s);
5810         if (!PL_tokenbuf[1]) {
5811             if (s == PL_bufend)
5812                 yyerror("Final $ should be \\$ or $name");
5813             PREREF('$');
5814         }
5815
5816         /* This kludge not intended to be bulletproof. */
5817         if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
5818             pl_yylval.opval = newSVOP(OP_CONST, 0,
5819                                    newSViv(CopARYBASE_get(&PL_compiling)));
5820             pl_yylval.opval->op_private = OPpCONST_ARYBASE;
5821             TERM(THING);
5822         }
5823
5824         d = s;
5825         {
5826             const char tmp = *s;
5827             if (PL_lex_state == LEX_NORMAL || PL_lex_brackets)
5828                 s = SKIPSPACE1(s);
5829
5830             if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
5831                 && intuit_more(s)) {
5832                 if (*s == '[') {
5833                     PL_tokenbuf[0] = '@';
5834                     if (ckWARN(WARN_SYNTAX)) {
5835                         char *t = s+1;
5836
5837                         while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
5838                             t++;
5839                         if (*t++ == ',') {
5840                             PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
5841                             while (t < PL_bufend && *t != ']')
5842                                 t++;
5843                             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5844                                         "Multidimensional syntax %.*s not supported",
5845                                     (int)((t - PL_bufptr) + 1), PL_bufptr);
5846                         }
5847                     }
5848                 }
5849                 else if (*s == '{') {
5850                     char *t;
5851                     PL_tokenbuf[0] = '%';
5852                     if (strEQ(PL_tokenbuf+1, "SIG")  && ckWARN(WARN_SYNTAX)
5853                         && (t = strchr(s, '}')) && (t = strchr(t, '=')))
5854                         {
5855                             char tmpbuf[sizeof PL_tokenbuf];
5856                             do {
5857                                 t++;
5858                             } while (isSPACE(*t));
5859                             if (isIDFIRST_lazy_if(t,UTF)) {
5860                                 STRLEN len;
5861                                 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
5862                                               &len);
5863                                 while (isSPACE(*t))
5864                                     t++;
5865                                 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
5866                                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5867                                                 "You need to quote \"%s\"",
5868                                                 tmpbuf);
5869                             }
5870                         }
5871                 }
5872             }
5873
5874             PL_expect = XOPERATOR;
5875             if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
5876                 const bool islop = (PL_last_lop == PL_oldoldbufptr);
5877                 if (!islop || PL_last_lop_op == OP_GREPSTART)
5878                     PL_expect = XOPERATOR;
5879                 else if (strchr("$@\"'`q", *s))
5880                     PL_expect = XTERM;          /* e.g. print $fh "foo" */
5881                 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
5882                     PL_expect = XTERM;          /* e.g. print $fh &sub */
5883                 else if (isIDFIRST_lazy_if(s,UTF)) {
5884                     char tmpbuf[sizeof PL_tokenbuf];
5885                     int t2;
5886                     scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5887                     if ((t2 = keyword(tmpbuf, len, 0))) {
5888                         /* binary operators exclude handle interpretations */
5889                         switch (t2) {
5890                         case -KEY_x:
5891                         case -KEY_eq:
5892                         case -KEY_ne:
5893                         case -KEY_gt:
5894                         case -KEY_lt:
5895                         case -KEY_ge:
5896                         case -KEY_le:
5897                         case -KEY_cmp:
5898                             break;
5899                         default:
5900                             PL_expect = XTERM;  /* e.g. print $fh length() */
5901                             break;
5902                         }
5903                     }
5904                     else {
5905                         PL_expect = XTERM;      /* e.g. print $fh subr() */
5906                     }
5907                 }
5908                 else if (isDIGIT(*s))
5909                     PL_expect = XTERM;          /* e.g. print $fh 3 */
5910                 else if (*s == '.' && isDIGIT(s[1]))
5911                     PL_expect = XTERM;          /* e.g. print $fh .3 */
5912                 else if ((*s == '?' || *s == '-' || *s == '+')
5913                          && !isSPACE(s[1]) && s[1] != '=')
5914                     PL_expect = XTERM;          /* e.g. print $fh -1 */
5915                 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
5916                          && s[1] != '/')
5917                     PL_expect = XTERM;          /* e.g. print $fh /.../
5918                                                    XXX except DORDOR operator
5919                                                 */
5920                 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
5921                          && s[2] != '=')
5922                     PL_expect = XTERM;          /* print $fh <<"EOF" */
5923             }
5924         }
5925         PL_pending_ident = '$';
5926         TOKEN('$');
5927
5928     case '@':
5929         if (PL_expect == XOPERATOR)
5930             no_op("Array", s);
5931         PL_tokenbuf[0] = '@';
5932         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
5933         if (!PL_tokenbuf[1]) {
5934             PREREF('@');
5935         }
5936         if (PL_lex_state == LEX_NORMAL)
5937             s = SKIPSPACE1(s);
5938         if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
5939             if (*s == '{')
5940                 PL_tokenbuf[0] = '%';
5941
5942             /* Warn about @ where they meant $. */
5943             if (*s == '[' || *s == '{') {
5944                 if (ckWARN(WARN_SYNTAX)) {
5945                     const char *t = s + 1;
5946                     while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
5947                         t++;
5948                     if (*t == '}' || *t == ']') {
5949                         t++;
5950                         PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
5951                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5952                             "Scalar value %.*s better written as $%.*s",
5953                             (int)(t-PL_bufptr), PL_bufptr,
5954                             (int)(t-PL_bufptr-1), PL_bufptr+1);
5955                     }
5956                 }
5957             }
5958         }
5959         PL_pending_ident = '@';
5960         TERM('@');
5961
5962      case '/':                  /* may be division, defined-or, or pattern */
5963         if (PL_expect == XTERMORDORDOR && s[1] == '/') {
5964             s += 2;
5965             AOPERATOR(DORDOR);
5966         }
5967      case '?':                  /* may either be conditional or pattern */
5968         if (PL_expect == XOPERATOR) {
5969              char tmp = *s++;
5970              if(tmp == '?') {
5971                 OPERATOR('?');
5972              }
5973              else {
5974                  tmp = *s++;
5975                  if(tmp == '/') {
5976                      /* A // operator. */
5977                     AOPERATOR(DORDOR);
5978                  }
5979                  else {
5980                      s--;
5981                      Mop(OP_DIVIDE);
5982                  }
5983              }
5984          }
5985          else {
5986              /* Disable warning on "study /blah/" */
5987              if (PL_oldoldbufptr == PL_last_uni
5988               && (*PL_last_uni != 's' || s - PL_last_uni < 5
5989                   || memNE(PL_last_uni, "study", 5)
5990                   || isALNUM_lazy_if(PL_last_uni+5,UTF)
5991               ))
5992                  check_uni();
5993              s = scan_pat(s,OP_MATCH);
5994              TERM(sublex_start());
5995          }
5996
5997     case '.':
5998         if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
5999 #ifdef PERL_STRICT_CR
6000             && s[1] == '\n'
6001 #else
6002             && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
6003 #endif
6004             && (s == PL_linestart || s[-1] == '\n') )
6005         {
6006             PL_lex_formbrack = 0;
6007             PL_expect = XSTATE;
6008             goto rightbracket;
6009         }
6010         if (PL_expect == XSTATE && s[1] == '.' && s[2] == '.') {
6011             s += 3;
6012             OPERATOR(YADAYADA);
6013         }
6014         if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
6015             char tmp = *s++;
6016             if (*s == tmp) {
6017                 s++;
6018                 if (*s == tmp) {
6019                     s++;
6020                     pl_yylval.ival = OPf_SPECIAL;
6021                 }
6022                 else
6023                     pl_yylval.ival = 0;
6024                 OPERATOR(DOTDOT);
6025             }
6026             Aop(OP_CONCAT);
6027         }
6028         /* FALL THROUGH */
6029     case '0': case '1': case '2': case '3': case '4':
6030     case '5': case '6': case '7': case '8': case '9':
6031         s = scan_num(s, &pl_yylval);
6032         DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
6033         if (PL_expect == XOPERATOR)
6034             no_op("Number",s);
6035         TERM(THING);
6036
6037     case '\'':
6038         s = scan_str(s,!!PL_madskills,FALSE);
6039         DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
6040         if (PL_expect == XOPERATOR) {
6041             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
6042                 return deprecate_commaless_var_list();
6043             }
6044             else
6045                 no_op("String",s);
6046         }
6047         if (!s)
6048             missingterm(NULL);
6049         pl_yylval.ival = OP_CONST;
6050         TERM(sublex_start());
6051
6052     case '"':
6053         s = scan_str(s,!!PL_madskills,FALSE);
6054         DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
6055         if (PL_expect == XOPERATOR) {
6056             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
6057                 return deprecate_commaless_var_list();
6058             }
6059             else
6060                 no_op("String",s);
6061         }
6062         if (!s)
6063             missingterm(NULL);
6064         pl_yylval.ival = OP_CONST;
6065         /* FIXME. I think that this can be const if char *d is replaced by
6066            more localised variables.  */
6067         for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
6068             if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
6069                 pl_yylval.ival = OP_STRINGIFY;
6070                 break;
6071             }
6072         }
6073         TERM(sublex_start());
6074
6075     case '`':
6076         s = scan_str(s,!!PL_madskills,FALSE);
6077         DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
6078         if (PL_expect == XOPERATOR)
6079             no_op("Backticks",s);
6080         if (!s)
6081             missingterm(NULL);
6082         readpipe_override();
6083         TERM(sublex_start());
6084
6085     case '\\':
6086         s++;
6087         if (PL_lex_inwhat && isDIGIT(*s))
6088             Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
6089                            *s, *s);
6090         if (PL_expect == XOPERATOR)
6091             no_op("Backslash",s);
6092         OPERATOR(REFGEN);
6093
6094     case 'v':
6095         if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
6096             char *start = s + 2;
6097             while (isDIGIT(*start) || *start == '_')
6098                 start++;
6099             if (*start == '.' && isDIGIT(start[1])) {
6100                 s = scan_num(s, &pl_yylval);
6101                 TERM(THING);
6102             }
6103             /* avoid v123abc() or $h{v1}, allow C<print v10;> */
6104             else if (!isALPHA(*start) && (PL_expect == XTERM
6105                         || PL_expect == XREF || PL_expect == XSTATE
6106                         || PL_expect == XTERMORDORDOR)) {
6107                 GV *const gv = gv_fetchpvn_flags(s, start - s, 0, SVt_PVCV);
6108                 if (!gv) {
6109                     s = scan_num(s, &pl_yylval);
6110                     TERM(THING);
6111                 }
6112             }
6113         }
6114         goto keylookup;
6115     case 'x':
6116         if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
6117             s++;
6118             Mop(OP_REPEAT);
6119         }
6120         goto keylookup;
6121
6122     case '_':
6123     case 'a': case 'A':
6124     case 'b': case 'B':
6125     case 'c': case 'C':
6126     case 'd': case 'D':
6127     case 'e': case 'E':
6128     case 'f': case 'F':
6129     case 'g': case 'G':
6130     case 'h': case 'H':
6131     case 'i': case 'I':
6132     case 'j': case 'J':
6133     case 'k': case 'K':
6134     case 'l': case 'L':
6135     case 'm': case 'M':
6136     case 'n': case 'N':
6137     case 'o': case 'O':
6138     case 'p': case 'P':
6139     case 'q': case 'Q':
6140     case 'r': case 'R':
6141     case 's': case 'S':
6142     case 't': case 'T':
6143     case 'u': case 'U':
6144               case 'V':
6145     case 'w': case 'W':
6146               case 'X':
6147     case 'y': case 'Y':
6148     case 'z': case 'Z':
6149
6150       keylookup: {
6151         bool anydelim;
6152         I32 tmp;
6153
6154         orig_keyword = 0;
6155         gv = NULL;
6156         gvp = NULL;
6157
6158         PL_bufptr = s;
6159         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
6160
6161         /* Some keywords can be followed by any delimiter, including ':' */
6162         anydelim = word_takes_any_delimeter(PL_tokenbuf, len);
6163
6164         /* x::* is just a word, unless x is "CORE" */
6165         if (!anydelim && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
6166             goto just_a_word;
6167
6168         d = s;
6169         while (d < PL_bufend && isSPACE(*d))
6170                 d++;    /* no comments skipped here, or s### is misparsed */
6171
6172         /* Is this a word before a => operator? */
6173         if (*d == '=' && d[1] == '>') {
6174             CLINE;
6175             pl_yylval.opval
6176                 = (OP*)newSVOP(OP_CONST, 0,
6177                                S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
6178             pl_yylval.opval->op_private = OPpCONST_BARE;
6179             TERM(WORD);
6180         }
6181
6182         /* Check for plugged-in keyword */
6183         {
6184             OP *o;
6185             int result;
6186             char *saved_bufptr = PL_bufptr;
6187             PL_bufptr = s;
6188             result = PL_keyword_plugin(aTHX_ PL_tokenbuf, len, &o);
6189             s = PL_bufptr;
6190             if (result == KEYWORD_PLUGIN_DECLINE) {
6191                 /* not a plugged-in keyword */
6192                 PL_bufptr = saved_bufptr;
6193             } else if (result == KEYWORD_PLUGIN_STMT) {
6194                 pl_yylval.opval = o;
6195                 CLINE;
6196                 PL_expect = XSTATE;
6197                 return REPORT(PLUGSTMT);
6198             } else if (result == KEYWORD_PLUGIN_EXPR) {
6199                 pl_yylval.opval = o;
6200                 CLINE;
6201                 PL_expect = XOPERATOR;
6202                 return REPORT(PLUGEXPR);
6203             } else {
6204                 Perl_croak(aTHX_ "Bad plugin affecting keyword '%s'",
6205                                         PL_tokenbuf);
6206             }
6207         }
6208
6209         /* Check for built-in keyword */
6210         tmp = keyword(PL_tokenbuf, len, 0);
6211
6212         /* Is this a label? */
6213         if (!anydelim && PL_expect == XSTATE
6214               && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
6215             s = d + 1;
6216             pl_yylval.pval = CopLABEL_alloc(PL_tokenbuf);
6217             CLINE;
6218             TOKEN(LABEL);
6219         }
6220
6221         if (tmp < 0) {                  /* second-class keyword? */
6222             GV *ogv = NULL;     /* override (winner) */
6223             GV *hgv = NULL;     /* hidden (loser) */
6224             if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
6225                 CV *cv;
6226                 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
6227                     (cv = GvCVu(gv)))
6228                 {
6229                     if (GvIMPORTED_CV(gv))
6230                         ogv = gv;
6231                     else if (! CvMETHOD(cv))
6232                         hgv = gv;
6233                 }
6234                 if (!ogv &&
6235                     (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
6236                     (gv = *gvp) && isGV_with_GP(gv) &&
6237                     GvCVu(gv) && GvIMPORTED_CV(gv))
6238                 {
6239                     ogv = gv;
6240                 }
6241             }
6242             if (ogv) {
6243                 orig_keyword = tmp;
6244                 tmp = 0;                /* overridden by import or by GLOBAL */
6245             }
6246             else if (gv && !gvp
6247                      && -tmp==KEY_lock  /* XXX generalizable kludge */
6248                      && GvCVu(gv))
6249             {
6250                 tmp = 0;                /* any sub overrides "weak" keyword */
6251             }
6252             else {                      /* no override */
6253                 tmp = -tmp;
6254                 if (tmp == KEY_dump) {
6255                     Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
6256                                    "dump() better written as CORE::dump()");
6257                 }
6258                 gv = NULL;
6259                 gvp = 0;
6260                 if (hgv && tmp != KEY_x && tmp != KEY_CORE)     /* never ambiguous */
6261                     Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6262                                    "Ambiguous call resolved as CORE::%s(), "
6263                                    "qualify as such or use &",
6264                                    GvENAME(hgv));
6265             }
6266         }
6267
6268       reserved_word:
6269         switch (tmp) {
6270
6271         default:                        /* not a keyword */
6272             /* Trade off - by using this evil construction we can pull the
6273                variable gv into the block labelled keylookup. If not, then
6274                we have to give it function scope so that the goto from the
6275                earlier ':' case doesn't bypass the initialisation.  */
6276             if (0) {
6277             just_a_word_zero_gv:
6278                 gv = NULL;
6279                 gvp = NULL;
6280                 orig_keyword = 0;
6281             }
6282           just_a_word: {
6283                 SV *sv;
6284                 int pkgname = 0;
6285                 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
6286                 OP *rv2cv_op;
6287                 CV *cv;
6288 #ifdef PERL_MAD
6289                 SV *nextPL_nextwhite = 0;
6290 #endif
6291
6292
6293                 /* Get the rest if it looks like a package qualifier */
6294
6295                 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
6296                     STRLEN morelen;
6297                     s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
6298                                   TRUE, &morelen);
6299                     if (!morelen)
6300                         Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
6301                                 *s == '\'' ? "'" : "::");
6302                     len += morelen;
6303                     pkgname = 1;
6304                 }
6305
6306                 if (PL_expect == XOPERATOR) {
6307                     if (PL_bufptr == PL_linestart) {
6308                         CopLINE_dec(PL_curcop);
6309                         Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
6310                         CopLINE_inc(PL_curcop);
6311                     }
6312                     else
6313                         no_op("Bareword",s);
6314                 }
6315
6316                 /* Look for a subroutine with this name in current package,
6317                    unless name is "Foo::", in which case Foo is a bearword
6318                    (and a package name). */
6319
6320                 if (len > 2 && !PL_madskills &&
6321                     PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
6322                 {
6323                     if (ckWARN(WARN_BAREWORD)
6324                         && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
6325                         Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
6326                             "Bareword \"%s\" refers to nonexistent package",
6327                              PL_tokenbuf);
6328                     len -= 2;
6329                     PL_tokenbuf[len] = '\0';
6330                     gv = NULL;
6331                     gvp = 0;
6332                 }
6333                 else {
6334                     if (!gv) {
6335                         /* Mustn't actually add anything to a symbol table.
6336                            But also don't want to "initialise" any placeholder
6337                            constants that might already be there into full
6338                            blown PVGVs with attached PVCV.  */
6339                         gv = gv_fetchpvn_flags(PL_tokenbuf, len,
6340                                                GV_NOADD_NOINIT, SVt_PVCV);
6341                     }
6342                     len = 0;
6343                 }
6344
6345                 /* if we saw a global override before, get the right name */
6346
6347                 sv = S_newSV_maybe_utf8(aTHX_ PL_tokenbuf,
6348                     len ? len : strlen(PL_tokenbuf));
6349                 if (gvp) {
6350                     SV * const tmp_sv = sv;
6351                     sv = newSVpvs("CORE::GLOBAL::");
6352                     sv_catsv(sv, tmp_sv);
6353                     SvREFCNT_dec(tmp_sv);
6354                 }
6355
6356 #ifdef PERL_MAD
6357                 if (PL_madskills && !PL_thistoken) {
6358                     char *start = SvPVX(PL_linestr) + PL_realtokenstart;
6359                     PL_thistoken = newSVpvn(start,s - start);
6360                     PL_realtokenstart = s - SvPVX(PL_linestr);
6361                 }
6362 #endif
6363
6364                 /* Presume this is going to be a bareword of some sort. */
6365                 CLINE;
6366                 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
6367                 pl_yylval.opval->op_private = OPpCONST_BARE;
6368
6369                 /* And if "Foo::", then that's what it certainly is. */
6370                 if (len)
6371                     goto safe_bareword;
6372
6373                 {
6374                     OP *const_op = newSVOP(OP_CONST, 0, SvREFCNT_inc(sv));
6375                     const_op->op_private = OPpCONST_BARE;
6376                     rv2cv_op = newCVREF(0, const_op);
6377                 }
6378                 cv = rv2cv_op_cv(rv2cv_op, 0);
6379
6380                 /* See if it's the indirect object for a list operator. */
6381
6382                 if (PL_oldoldbufptr &&
6383                     PL_oldoldbufptr < PL_bufptr &&
6384                     (PL_oldoldbufptr == PL_last_lop
6385                      || PL_oldoldbufptr == PL_last_uni) &&
6386                     /* NO SKIPSPACE BEFORE HERE! */
6387                     (PL_expect == XREF ||
6388                      ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
6389                 {
6390                     bool immediate_paren = *s == '(';
6391
6392                     /* (Now we can afford to cross potential line boundary.) */
6393                     s = SKIPSPACE2(s,nextPL_nextwhite);
6394 #ifdef PERL_MAD
6395                     PL_nextwhite = nextPL_nextwhite;    /* assume no & deception */
6396 #endif
6397
6398                     /* Two barewords in a row may indicate method call. */
6399
6400                     if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
6401                         (tmp = intuit_method(s, gv, cv))) {
6402                         op_free(rv2cv_op);
6403                         return REPORT(tmp);
6404                     }
6405
6406                     /* If not a declared subroutine, it's an indirect object. */
6407                     /* (But it's an indir obj regardless for sort.) */
6408                     /* Also, if "_" follows a filetest operator, it's a bareword */
6409
6410                     if (
6411                         ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
6412                          (!cv &&
6413                         (PL_last_lop_op != OP_MAPSTART &&
6414                          PL_last_lop_op != OP_GREPSTART))))
6415                        || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
6416                             && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
6417                        )
6418                     {
6419                         PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
6420                         goto bareword;
6421                     }
6422                 }
6423
6424                 PL_expect = XOPERATOR;
6425 #ifdef PERL_MAD
6426                 if (isSPACE(*s))
6427                     s = SKIPSPACE2(s,nextPL_nextwhite);
6428                 PL_nextwhite = nextPL_nextwhite;
6429 #else
6430                 s = skipspace(s);
6431 #endif
6432
6433                 /* Is this a word before a => operator? */
6434                 if (*s == '=' && s[1] == '>' && !pkgname) {
6435                     op_free(rv2cv_op);
6436                     CLINE;
6437                     sv_setpv(((SVOP*)pl_yylval.opval)->op_sv, PL_tokenbuf);
6438                     if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
6439                       SvUTF8_on(((SVOP*)pl_yylval.opval)->op_sv);
6440                     TERM(WORD);
6441                 }
6442
6443                 /* If followed by a paren, it's certainly a subroutine. */
6444                 if (*s == '(') {
6445                     CLINE;
6446                     if (cv) {
6447                         d = s + 1;
6448                         while (SPACE_OR_TAB(*d))
6449                             d++;
6450                         if (*d == ')' && (sv = cv_const_sv(cv))) {
6451                             s = d + 1;
6452                             goto its_constant;
6453                         }
6454                     }
6455 #ifdef PERL_MAD
6456                     if (PL_madskills) {
6457                         PL_nextwhite = PL_thiswhite;
6458                         PL_thiswhite = 0;
6459                     }
6460                     start_force(PL_curforce);
6461 #endif
6462                     NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6463                     PL_expect = XOPERATOR;
6464 #ifdef PERL_MAD
6465                     if (PL_madskills) {
6466                         PL_nextwhite = nextPL_nextwhite;
6467                         curmad('X', PL_thistoken);
6468                         PL_thistoken = newSVpvs("");
6469                     }
6470 #endif
6471                     op_free(rv2cv_op);
6472                     force_next(WORD);
6473                     pl_yylval.ival = 0;
6474                     TOKEN('&');
6475                 }
6476
6477                 /* If followed by var or block, call it a method (unless sub) */
6478
6479                 if ((*s == '$' || *s == '{') && !cv) {
6480                     op_free(rv2cv_op);
6481                     PL_last_lop = PL_oldbufptr;
6482                     PL_last_lop_op = OP_METHOD;
6483                     PREBLOCK(METHOD);
6484                 }
6485
6486                 /* If followed by a bareword, see if it looks like indir obj. */
6487
6488                 if (!orig_keyword
6489                         && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
6490                         && (tmp = intuit_method(s, gv, cv))) {
6491                     op_free(rv2cv_op);
6492                     return REPORT(tmp);
6493                 }
6494
6495                 /* Not a method, so call it a subroutine (if defined) */
6496
6497                 if (cv) {
6498                     if (lastchar == '-')
6499                         Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
6500                                          "Ambiguous use of -%s resolved as -&%s()",
6501                                          PL_tokenbuf, PL_tokenbuf);
6502                     /* Check for a constant sub */
6503                     if ((sv = cv_const_sv(cv))) {
6504                   its_constant:
6505                         op_free(rv2cv_op);
6506                         SvREFCNT_dec(((SVOP*)pl_yylval.opval)->op_sv);
6507                         ((SVOP*)pl_yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
6508                         pl_yylval.opval->op_private = 0;
6509                         TOKEN(WORD);
6510                     }
6511
6512                     op_free(pl_yylval.opval);
6513                     pl_yylval.opval = rv2cv_op;
6514                     pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
6515                     PL_last_lop = PL_oldbufptr;
6516                     PL_last_lop_op = OP_ENTERSUB;
6517                     /* Is there a prototype? */
6518                     if (
6519 #ifdef PERL_MAD
6520                         cv &&
6521 #endif
6522                         SvPOK(cv))
6523                     {
6524                         STRLEN protolen;
6525                         const char *proto = SvPV_const(MUTABLE_SV(cv), protolen);
6526                         if (!protolen)
6527                             TERM(FUNC0SUB);
6528                         while (*proto == ';')
6529                             proto++;
6530                         if (
6531                             (
6532                                 (
6533                                     *proto == '$' || *proto == '_'
6534                                  || *proto == '*' || *proto == '+'
6535                                 )
6536                              && proto[1] == '\0'
6537                             )
6538                          || (
6539                              *proto == '\\' && proto[1] && proto[2] == '\0'
6540                             )
6541                         )
6542                             OPERATOR(UNIOPSUB);
6543                         if (*proto == '\\' && proto[1] == '[') {
6544                             const char *p = proto + 2;
6545                             while(*p && *p != ']')
6546                                 ++p;
6547                             if(*p == ']' && !p[1]) OPERATOR(UNIOPSUB);
6548                         }
6549                         if (*proto == '&' && *s == '{') {
6550                             if (PL_curstash)
6551                                 sv_setpvs(PL_subname, "__ANON__");
6552                             else
6553                                 sv_setpvs(PL_subname, "__ANON__::__ANON__");
6554                             PREBLOCK(LSTOPSUB);
6555                         }
6556                     }
6557 #ifdef PERL_MAD
6558                     {
6559                         if (PL_madskills) {
6560                             PL_nextwhite = PL_thiswhite;
6561                             PL_thiswhite = 0;
6562                         }
6563                         start_force(PL_curforce);
6564                         NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6565                         PL_expect = XTERM;
6566                         if (PL_madskills) {
6567                             PL_nextwhite = nextPL_nextwhite;
6568                             curmad('X', PL_thistoken);
6569                             PL_thistoken = newSVpvs("");
6570                         }
6571                         force_next(WORD);
6572                         TOKEN(NOAMP);
6573                     }
6574                 }
6575
6576                 /* Guess harder when madskills require "best effort". */
6577                 if (PL_madskills && (!gv || !GvCVu(gv))) {
6578                     int probable_sub = 0;
6579                     if (strchr("\"'`$@%0123456789!*+{[<", *s))
6580                         probable_sub = 1;
6581                     else if (isALPHA(*s)) {
6582                         char tmpbuf[1024];
6583                         STRLEN tmplen;
6584                         d = s;
6585                         d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
6586                         if (!keyword(tmpbuf, tmplen, 0))
6587                             probable_sub = 1;
6588                         else {
6589                             while (d < PL_bufend && isSPACE(*d))
6590                                 d++;
6591                             if (*d == '=' && d[1] == '>')
6592                                 probable_sub = 1;
6593                         }
6594                     }
6595                     if (probable_sub) {
6596                         gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
6597                         op_free(pl_yylval.opval);
6598                         pl_yylval.opval = rv2cv_op;
6599                         pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
6600                         PL_last_lop = PL_oldbufptr;
6601                         PL_last_lop_op = OP_ENTERSUB;
6602                         PL_nextwhite = PL_thiswhite;
6603                         PL_thiswhite = 0;
6604                         start_force(PL_curforce);
6605                         NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6606                         PL_expect = XTERM;
6607                         PL_nextwhite = nextPL_nextwhite;
6608                         curmad('X', PL_thistoken);
6609                         PL_thistoken = newSVpvs("");
6610                         force_next(WORD);
6611                         TOKEN(NOAMP);
6612                     }
6613 #else
6614                     NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6615                     PL_expect = XTERM;
6616                     force_next(WORD);
6617                     TOKEN(NOAMP);
6618 #endif
6619                 }
6620
6621                 /* Call it a bare word */
6622
6623                 if (PL_hints & HINT_STRICT_SUBS)
6624                     pl_yylval.opval->op_private |= OPpCONST_STRICT;
6625                 else {
6626                 bareword:
6627                     /* after "print" and similar functions (corresponding to
6628                      * "F? L" in opcode.pl), whatever wasn't already parsed as
6629                      * a filehandle should be subject to "strict subs".
6630                      * Likewise for the optional indirect-object argument to system
6631                      * or exec, which can't be a bareword */
6632                     if ((PL_last_lop_op == OP_PRINT
6633                             || PL_last_lop_op == OP_PRTF
6634                             || PL_last_lop_op == OP_SAY
6635                             || PL_last_lop_op == OP_SYSTEM
6636                             || PL_last_lop_op == OP_EXEC)
6637                             && (PL_hints & HINT_STRICT_SUBS))
6638                         pl_yylval.opval->op_private |= OPpCONST_STRICT;
6639                     if (lastchar != '-') {
6640                         if (ckWARN(WARN_RESERVED)) {
6641                             d = PL_tokenbuf;
6642                             while (isLOWER(*d))
6643                                 d++;
6644                             if (!*d && !gv_stashpv(PL_tokenbuf, 0))
6645                                 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
6646                                        PL_tokenbuf);
6647                         }
6648                     }
6649                 }
6650                 op_free(rv2cv_op);
6651
6652             safe_bareword:
6653                 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')) {
6654                     Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
6655                                      "Operator or semicolon missing before %c%s",
6656                                      lastchar, PL_tokenbuf);
6657                     Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
6658                                      "Ambiguous use of %c resolved as operator %c",
6659                                      lastchar, lastchar);
6660                 }
6661                 TOKEN(WORD);
6662             }
6663
6664         case KEY___FILE__:
6665             pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
6666                                         newSVpv(CopFILE(PL_curcop),0));
6667             TERM(THING);
6668
6669         case KEY___LINE__:
6670             pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
6671                                     Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
6672             TERM(THING);
6673
6674         case KEY___PACKAGE__:
6675             pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
6676                                         (PL_curstash
6677                                          ? newSVhek(HvNAME_HEK(PL_curstash))
6678                                          : &PL_sv_undef));
6679             TERM(THING);
6680
6681         case KEY___DATA__:
6682         case KEY___END__: {
6683             GV *gv;
6684             if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
6685                 const char *pname = "main";
6686                 if (PL_tokenbuf[2] == 'D')
6687                     pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
6688                 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
6689                                 SVt_PVIO);
6690                 GvMULTI_on(gv);
6691                 if (!GvIO(gv))
6692                     GvIOp(gv) = newIO();
6693                 IoIFP(GvIOp(gv)) = PL_rsfp;
6694 #if defined(HAS_FCNTL) && defined(F_SETFD)
6695                 {
6696                     const int fd = PerlIO_fileno(PL_rsfp);
6697                     fcntl(fd,F_SETFD,fd >= 3);
6698                 }
6699 #endif
6700                 /* Mark this internal pseudo-handle as clean */
6701                 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
6702                 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
6703                     IoTYPE(GvIOp(gv)) = IoTYPE_STD;
6704                 else
6705                     IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
6706 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
6707                 /* if the script was opened in binmode, we need to revert
6708                  * it to text mode for compatibility; but only iff it has CRs
6709                  * XXX this is a questionable hack at best. */
6710                 if (PL_bufend-PL_bufptr > 2
6711                     && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
6712                 {
6713                     Off_t loc = 0;
6714                     if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
6715                         loc = PerlIO_tell(PL_rsfp);
6716                         (void)PerlIO_seek(PL_rsfp, 0L, 0);
6717                     }
6718 #ifdef NETWARE
6719                         if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
6720 #else
6721                     if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
6722 #endif  /* NETWARE */
6723 #ifdef PERLIO_IS_STDIO /* really? */
6724 #  if defined(__BORLANDC__)
6725                         /* XXX see note in do_binmode() */
6726                         ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
6727 #  endif
6728 #endif
6729                         if (loc > 0)
6730                             PerlIO_seek(PL_rsfp, loc, 0);
6731                     }
6732                 }
6733 #endif
6734 #ifdef PERLIO_LAYERS
6735                 if (!IN_BYTES) {
6736                     if (UTF)
6737                         PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
6738                     else if (PL_encoding) {
6739                         SV *name;
6740                         dSP;
6741                         ENTER;
6742                         SAVETMPS;
6743                         PUSHMARK(sp);
6744                         EXTEND(SP, 1);
6745                         XPUSHs(PL_encoding);
6746                         PUTBACK;
6747                         call_method("name", G_SCALAR);
6748                         SPAGAIN;
6749                         name = POPs;
6750                         PUTBACK;
6751                         PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
6752                                             Perl_form(aTHX_ ":encoding(%"SVf")",
6753                                                       SVfARG(name)));
6754                         FREETMPS;
6755                         LEAVE;
6756                     }
6757                 }
6758 #endif
6759 #ifdef PERL_MAD
6760                 if (PL_madskills) {
6761                     if (PL_realtokenstart >= 0) {
6762                         char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6763                         if (!PL_endwhite)
6764                             PL_endwhite = newSVpvs("");
6765                         sv_catsv(PL_endwhite, PL_thiswhite);
6766                         PL_thiswhite = 0;
6767                         sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
6768                         PL_realtokenstart = -1;
6769                     }
6770                     while ((s = filter_gets(PL_endwhite, SvCUR(PL_endwhite)))
6771                            != NULL) ;
6772                 }
6773 #endif
6774                 PL_rsfp = NULL;
6775             }
6776             goto fake_eof;
6777         }
6778
6779         case KEY_AUTOLOAD:
6780         case KEY_DESTROY:
6781         case KEY_BEGIN:
6782         case KEY_UNITCHECK:
6783         case KEY_CHECK:
6784         case KEY_INIT:
6785         case KEY_END:
6786             if (PL_expect == XSTATE) {
6787                 s = PL_bufptr;
6788                 goto really_sub;
6789             }
6790             goto just_a_word;
6791
6792         case KEY_CORE:
6793             if (*s == ':' && s[1] == ':') {
6794                 s += 2;
6795                 d = s;
6796                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
6797                 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
6798                     Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
6799                 if (tmp < 0)
6800                     tmp = -tmp;
6801                 else if (tmp == KEY_require || tmp == KEY_do)
6802                     /* that's a way to remember we saw "CORE::" */
6803                     orig_keyword = tmp;
6804                 goto reserved_word;
6805             }
6806             goto just_a_word;
6807
6808         case KEY_abs:
6809             UNI(OP_ABS);
6810
6811         case KEY_alarm:
6812             UNI(OP_ALARM);
6813
6814         case KEY_accept:
6815             LOP(OP_ACCEPT,XTERM);
6816
6817         case KEY_and:
6818             OPERATOR(ANDOP);
6819
6820         case KEY_atan2:
6821             LOP(OP_ATAN2,XTERM);
6822
6823         case KEY_bind:
6824             LOP(OP_BIND,XTERM);
6825
6826         case KEY_binmode:
6827             LOP(OP_BINMODE,XTERM);
6828
6829         case KEY_bless:
6830             LOP(OP_BLESS,XTERM);
6831
6832         case KEY_break:
6833             FUN0(OP_BREAK);
6834
6835         case KEY_chop:
6836             UNI(OP_CHOP);
6837
6838         case KEY_continue:
6839             /* When 'use switch' is in effect, continue has a dual
6840                life as a control operator. */
6841             {
6842                 if (!FEATURE_IS_ENABLED("switch"))
6843                     PREBLOCK(CONTINUE);
6844                 else {
6845                     /* We have to disambiguate the two senses of
6846                       "continue". If the next token is a '{' then
6847                       treat it as the start of a continue block;
6848                       otherwise treat it as a control operator.
6849                      */
6850                     s = skipspace(s);
6851                     if (*s == '{')
6852             PREBLOCK(CONTINUE);
6853                     else
6854                         FUN0(OP_CONTINUE);
6855                 }
6856             }
6857
6858         case KEY_chdir:
6859             /* may use HOME */
6860             (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
6861             UNI(OP_CHDIR);
6862
6863         case KEY_close:
6864             UNI(OP_CLOSE);
6865
6866         case KEY_closedir:
6867             UNI(OP_CLOSEDIR);
6868
6869         case KEY_cmp:
6870             Eop(OP_SCMP);
6871
6872         case KEY_caller:
6873             UNI(OP_CALLER);
6874
6875         case KEY_crypt:
6876 #ifdef FCRYPT
6877             if (!PL_cryptseen) {
6878                 PL_cryptseen = TRUE;
6879                 init_des();
6880             }
6881 #endif
6882             LOP(OP_CRYPT,XTERM);
6883
6884         case KEY_chmod:
6885             LOP(OP_CHMOD,XTERM);
6886
6887         case KEY_chown:
6888             LOP(OP_CHOWN,XTERM);
6889
6890         case KEY_connect:
6891             LOP(OP_CONNECT,XTERM);
6892
6893         case KEY_chr:
6894             UNI(OP_CHR);
6895
6896         case KEY_cos:
6897             UNI(OP_COS);
6898
6899         case KEY_chroot:
6900             UNI(OP_CHROOT);
6901
6902         case KEY_default:
6903             PREBLOCK(DEFAULT);
6904
6905         case KEY_do:
6906             s = SKIPSPACE1(s);
6907             if (*s == '{')
6908                 PRETERMBLOCK(DO);
6909             if (*s != '\'')
6910                 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6911             if (orig_keyword == KEY_do) {
6912                 orig_keyword = 0;
6913                 pl_yylval.ival = 1;
6914             }
6915             else
6916                 pl_yylval.ival = 0;
6917             OPERATOR(DO);
6918
6919         case KEY_die:
6920             PL_hints |= HINT_BLOCK_SCOPE;
6921             LOP(OP_DIE,XTERM);
6922
6923         case KEY_defined:
6924             UNI(OP_DEFINED);
6925
6926         case KEY_delete:
6927             UNI(OP_DELETE);
6928
6929         case KEY_dbmopen:
6930             Perl_populate_isa(aTHX_ STR_WITH_LEN("AnyDBM_File::ISA"),
6931                               STR_WITH_LEN("NDBM_File::"),
6932                               STR_WITH_LEN("DB_File::"),
6933                               STR_WITH_LEN("GDBM_File::"),
6934                               STR_WITH_LEN("SDBM_File::"),
6935                               STR_WITH_LEN("ODBM_File::"),
6936                               NULL);
6937             LOP(OP_DBMOPEN,XTERM);
6938
6939         case KEY_dbmclose:
6940             UNI(OP_DBMCLOSE);
6941
6942         case KEY_dump:
6943             s = force_word(s,WORD,TRUE,FALSE,FALSE);
6944             LOOPX(OP_DUMP);
6945
6946         case KEY_else:
6947             PREBLOCK(ELSE);
6948
6949         case KEY_elsif:
6950             pl_yylval.ival = CopLINE(PL_curcop);
6951             OPERATOR(ELSIF);
6952
6953         case KEY_eq:
6954             Eop(OP_SEQ);
6955
6956         case KEY_exists:
6957             UNI(OP_EXISTS);
6958         
6959         case KEY_exit:
6960             if (PL_madskills)
6961                 UNI(OP_INT);
6962             UNI(OP_EXIT);
6963
6964         case KEY_eval:
6965             s = SKIPSPACE1(s);
6966             if (*s == '{') { /* block eval */
6967                 PL_expect = XTERMBLOCK;
6968                 UNIBRACK(OP_ENTERTRY);
6969             }
6970             else { /* string eval */
6971                 PL_expect = XTERM;
6972                 UNIBRACK(OP_ENTEREVAL);
6973             }
6974
6975         case KEY_eof:
6976             UNI(OP_EOF);
6977
6978         case KEY_exp:
6979             UNI(OP_EXP);
6980
6981         case KEY_each:
6982             UNI(OP_EACH);
6983
6984         case KEY_exec:
6985             LOP(OP_EXEC,XREF);
6986
6987         case KEY_endhostent:
6988             FUN0(OP_EHOSTENT);
6989
6990         case KEY_endnetent:
6991             FUN0(OP_ENETENT);
6992
6993         case KEY_endservent:
6994             FUN0(OP_ESERVENT);
6995
6996         case KEY_endprotoent:
6997             FUN0(OP_EPROTOENT);
6998
6999         case KEY_endpwent:
7000             FUN0(OP_EPWENT);
7001
7002         case KEY_endgrent:
7003             FUN0(OP_EGRENT);
7004
7005         case KEY_for:
7006         case KEY_foreach:
7007             pl_yylval.ival = CopLINE(PL_curcop);
7008             s = SKIPSPACE1(s);
7009             if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
7010                 char *p = s;
7011 #ifdef PERL_MAD
7012                 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
7013 #endif
7014
7015                 if ((PL_bufend - p) >= 3 &&
7016                     strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
7017                     p += 2;
7018                 else if ((PL_bufend - p) >= 4 &&
7019                     strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
7020                     p += 3;
7021                 p = PEEKSPACE(p);
7022                 if (isIDFIRST_lazy_if(p,UTF)) {
7023                     p = scan_ident(p, PL_bufend,
7024                         PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
7025                     p = PEEKSPACE(p);
7026                 }
7027                 if (*p != '$')
7028                     Perl_croak(aTHX_ "Missing $ on loop variable");
7029 #ifdef PERL_MAD
7030                 s = SvPVX(PL_linestr) + soff;
7031 #endif
7032             }
7033             OPERATOR(FOR);
7034
7035         case KEY_formline:
7036             LOP(OP_FORMLINE,XTERM);
7037
7038         case KEY_fork:
7039             FUN0(OP_FORK);
7040
7041         case KEY_fcntl:
7042             LOP(OP_FCNTL,XTERM);
7043
7044         case KEY_fileno:
7045             UNI(OP_FILENO);
7046
7047         case KEY_flock:
7048             LOP(OP_FLOCK,XTERM);
7049
7050         case KEY_gt:
7051             Rop(OP_SGT);
7052
7053         case KEY_ge:
7054             Rop(OP_SGE);
7055
7056         case KEY_grep:
7057             LOP(OP_GREPSTART, XREF);
7058
7059         case KEY_goto:
7060             s = force_word(s,WORD,TRUE,FALSE,FALSE);
7061             LOOPX(OP_GOTO);
7062
7063         case KEY_gmtime:
7064             UNI(OP_GMTIME);
7065
7066         case KEY_getc:
7067             UNIDOR(OP_GETC);
7068
7069         case KEY_getppid:
7070             FUN0(OP_GETPPID);
7071
7072         case KEY_getpgrp:
7073             UNI(OP_GETPGRP);
7074
7075         case KEY_getpriority:
7076             LOP(OP_GETPRIORITY,XTERM);
7077
7078         case KEY_getprotobyname:
7079             UNI(OP_GPBYNAME);
7080
7081         case KEY_getprotobynumber:
7082             LOP(OP_GPBYNUMBER,XTERM);
7083
7084         case KEY_getprotoent:
7085             FUN0(OP_GPROTOENT);
7086
7087         case KEY_getpwent:
7088             FUN0(OP_GPWENT);
7089
7090         case KEY_getpwnam:
7091             UNI(OP_GPWNAM);
7092
7093         case KEY_getpwuid:
7094             UNI(OP_GPWUID);
7095
7096         case KEY_getpeername:
7097             UNI(OP_GETPEERNAME);
7098
7099         case KEY_gethostbyname:
7100             UNI(OP_GHBYNAME);
7101
7102         case KEY_gethostbyaddr:
7103             LOP(OP_GHBYADDR,XTERM);
7104
7105         case KEY_gethostent:
7106             FUN0(OP_GHOSTENT);
7107
7108         case KEY_getnetbyname:
7109             UNI(OP_GNBYNAME);
7110
7111         case KEY_getnetbyaddr:
7112             LOP(OP_GNBYADDR,XTERM);
7113
7114         case KEY_getnetent:
7115             FUN0(OP_GNETENT);
7116
7117         case KEY_getservbyname:
7118             LOP(OP_GSBYNAME,XTERM);
7119
7120         case KEY_getservbyport:
7121             LOP(OP_GSBYPORT,XTERM);
7122
7123         case KEY_getservent:
7124             FUN0(OP_GSERVENT);
7125
7126         case KEY_getsockname:
7127             UNI(OP_GETSOCKNAME);
7128
7129         case KEY_getsockopt:
7130             LOP(OP_GSOCKOPT,XTERM);
7131
7132         case KEY_getgrent:
7133             FUN0(OP_GGRENT);
7134
7135         case KEY_getgrnam:
7136             UNI(OP_GGRNAM);
7137
7138         case KEY_getgrgid:
7139             UNI(OP_GGRGID);
7140
7141         case KEY_getlogin:
7142             FUN0(OP_GETLOGIN);
7143
7144         case KEY_given:
7145             pl_yylval.ival = CopLINE(PL_curcop);
7146             OPERATOR(GIVEN);
7147
7148         case KEY_glob:
7149             LOP(OP_GLOB,XTERM);
7150
7151         case KEY_hex:
7152             UNI(OP_HEX);
7153
7154         case KEY_if:
7155             pl_yylval.ival = CopLINE(PL_curcop);
7156             OPERATOR(IF);
7157
7158         case KEY_index:
7159             LOP(OP_INDEX,XTERM);
7160
7161         case KEY_int:
7162             UNI(OP_INT);
7163
7164         case KEY_ioctl:
7165             LOP(OP_IOCTL,XTERM);
7166
7167         case KEY_join:
7168             LOP(OP_JOIN,XTERM);
7169
7170         case KEY_keys:
7171             UNI(OP_KEYS);
7172
7173         case KEY_kill:
7174             LOP(OP_KILL,XTERM);
7175
7176         case KEY_last:
7177             s = force_word(s,WORD,TRUE,FALSE,FALSE);
7178             LOOPX(OP_LAST);
7179         
7180         case KEY_lc:
7181             UNI(OP_LC);
7182
7183         case KEY_lcfirst:
7184             UNI(OP_LCFIRST);
7185
7186         case KEY_local:
7187             pl_yylval.ival = 0;
7188             OPERATOR(LOCAL);
7189
7190         case KEY_length:
7191             UNI(OP_LENGTH);
7192
7193         case KEY_lt:
7194             Rop(OP_SLT);
7195
7196         case KEY_le:
7197             Rop(OP_SLE);
7198
7199         case KEY_localtime:
7200             UNI(OP_LOCALTIME);
7201
7202         case KEY_log:
7203             UNI(OP_LOG);
7204
7205         case KEY_link:
7206             LOP(OP_LINK,XTERM);
7207
7208         case KEY_listen:
7209             LOP(OP_LISTEN,XTERM);
7210
7211         case KEY_lock:
7212             UNI(OP_LOCK);
7213
7214         case KEY_lstat:
7215             UNI(OP_LSTAT);
7216
7217         case KEY_m:
7218             s = scan_pat(s,OP_MATCH);
7219             TERM(sublex_start());
7220
7221         case KEY_map:
7222             LOP(OP_MAPSTART, XREF);
7223
7224         case KEY_mkdir:
7225             LOP(OP_MKDIR,XTERM);
7226
7227         case KEY_msgctl:
7228             LOP(OP_MSGCTL,XTERM);
7229
7230         case KEY_msgget:
7231             LOP(OP_MSGGET,XTERM);
7232
7233         case KEY_msgrcv:
7234             LOP(OP_MSGRCV,XTERM);
7235
7236         case KEY_msgsnd:
7237             LOP(OP_MSGSND,XTERM);
7238
7239         case KEY_our:
7240         case KEY_my:
7241         case KEY_state:
7242             PL_in_my = (U16)tmp;
7243             s = SKIPSPACE1(s);
7244             if (isIDFIRST_lazy_if(s,UTF)) {
7245 #ifdef PERL_MAD
7246                 char* start = s;
7247 #endif
7248                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
7249                 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
7250                     goto really_sub;
7251                 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
7252                 if (!PL_in_my_stash) {
7253                     char tmpbuf[1024];
7254                     PL_bufptr = s;
7255                     my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
7256                     yyerror(tmpbuf);
7257                 }
7258 #ifdef PERL_MAD
7259                 if (PL_madskills) {     /* just add type to declarator token */
7260                     sv_catsv(PL_thistoken, PL_nextwhite);
7261                     PL_nextwhite = 0;
7262                     sv_catpvn(PL_thistoken, start, s - start);
7263                 }
7264 #endif
7265             }
7266             pl_yylval.ival = 1;
7267             OPERATOR(MY);
7268
7269         case KEY_next:
7270             s = force_word(s,WORD,TRUE,FALSE,FALSE);
7271             LOOPX(OP_NEXT);
7272
7273         case KEY_ne:
7274             Eop(OP_SNE);
7275
7276         case KEY_no:
7277             s = tokenize_use(0, s);
7278             OPERATOR(USE);
7279
7280         case KEY_not:
7281             if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
7282                 FUN1(OP_NOT);
7283             else
7284                 OPERATOR(NOTOP);
7285
7286         case KEY_open:
7287             s = SKIPSPACE1(s);
7288             if (isIDFIRST_lazy_if(s,UTF)) {
7289                 const char *t;
7290                 for (d = s; isALNUM_lazy_if(d,UTF);)
7291                     d++;
7292                 for (t=d; isSPACE(*t);)
7293                     t++;
7294                 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
7295                     /* [perl #16184] */
7296                     && !(t[0] == '=' && t[1] == '>')
7297                 ) {
7298                     int parms_len = (int)(d-s);
7299                     Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
7300                            "Precedence problem: open %.*s should be open(%.*s)",
7301                             parms_len, s, parms_len, s);
7302                 }
7303             }
7304             LOP(OP_OPEN,XTERM);
7305
7306         case KEY_or:
7307             pl_yylval.ival = OP_OR;
7308             OPERATOR(OROP);
7309
7310         case KEY_ord:
7311             UNI(OP_ORD);
7312
7313         case KEY_oct:
7314             UNI(OP_OCT);
7315
7316         case KEY_opendir:
7317             LOP(OP_OPEN_DIR,XTERM);
7318
7319         case KEY_print:
7320             checkcomma(s,PL_tokenbuf,"filehandle");
7321             LOP(OP_PRINT,XREF);
7322
7323         case KEY_printf:
7324             checkcomma(s,PL_tokenbuf,"filehandle");
7325             LOP(OP_PRTF,XREF);
7326
7327         case KEY_prototype:
7328             UNI(OP_PROTOTYPE);
7329
7330         case KEY_push:
7331             LOP(OP_PUSH,XTERM);
7332
7333         case KEY_pop:
7334             UNIDOR(OP_POP);
7335
7336         case KEY_pos:
7337             UNIDOR(OP_POS);
7338         
7339         case KEY_pack:
7340             LOP(OP_PACK,XTERM);
7341
7342         case KEY_package:
7343             s = force_word(s,WORD,FALSE,TRUE,FALSE);
7344             s = SKIPSPACE1(s);
7345             s = force_strict_version(s);
7346             PL_lex_expect = XBLOCK;
7347             OPERATOR(PACKAGE);
7348
7349         case KEY_pipe:
7350             LOP(OP_PIPE_OP,XTERM);
7351
7352         case KEY_q:
7353             s = scan_str(s,!!PL_madskills,FALSE);
7354             if (!s)
7355                 missingterm(NULL);
7356             pl_yylval.ival = OP_CONST;
7357             TERM(sublex_start());
7358
7359         case KEY_quotemeta:
7360             UNI(OP_QUOTEMETA);
7361
7362         case KEY_qw: {
7363             OP *words = NULL;
7364             s = scan_str(s,!!PL_madskills,FALSE);
7365             if (!s)
7366                 missingterm(NULL);
7367             PL_expect = XOPERATOR;
7368             if (SvCUR(PL_lex_stuff)) {
7369                 int warned = 0;
7370                 d = SvPV_force(PL_lex_stuff, len);
7371                 while (len) {
7372                     for (; isSPACE(*d) && len; --len, ++d)
7373                         /**/;
7374                     if (len) {
7375                         SV *sv;
7376                         const char *b = d;
7377                         if (!warned && ckWARN(WARN_QW)) {
7378                             for (; !isSPACE(*d) && len; --len, ++d) {
7379                                 if (*d == ',') {
7380                                     Perl_warner(aTHX_ packWARN(WARN_QW),
7381                                         "Possible attempt to separate words with commas");
7382                                     ++warned;
7383                                 }
7384                                 else if (*d == '#') {
7385                                     Perl_warner(aTHX_ packWARN(WARN_QW),
7386                                         "Possible attempt to put comments in qw() list");
7387                                     ++warned;
7388                                 }
7389                             }
7390                         }
7391                         else {
7392                             for (; !isSPACE(*d) && len; --len, ++d)
7393                                 /**/;
7394                         }
7395                         sv = newSVpvn_utf8(b, d-b, DO_UTF8(PL_lex_stuff));
7396                         words = op_append_elem(OP_LIST, words,
7397                                             newSVOP(OP_CONST, 0, tokeq(sv)));
7398                     }
7399                 }
7400             }
7401             if (!words)
7402                 words = newNULLLIST();
7403             if (PL_lex_stuff) {
7404                 SvREFCNT_dec(PL_lex_stuff);
7405                 PL_lex_stuff = NULL;
7406             }
7407             PL_expect = XOPERATOR;
7408             pl_yylval.opval = sawparens(words);
7409             TOKEN(QWLIST);
7410         }
7411
7412         case KEY_qq:
7413             s = scan_str(s,!!PL_madskills,FALSE);
7414             if (!s)
7415                 missingterm(NULL);
7416             pl_yylval.ival = OP_STRINGIFY;
7417             if (SvIVX(PL_lex_stuff) == '\'')
7418                 SvIV_set(PL_lex_stuff, 0);      /* qq'$foo' should intepolate */
7419             TERM(sublex_start());
7420
7421         case KEY_qr:
7422             s = scan_pat(s,OP_QR);
7423             TERM(sublex_start());
7424
7425         case KEY_qx:
7426             s = scan_str(s,!!PL_madskills,FALSE);
7427             if (!s)
7428                 missingterm(NULL);
7429             readpipe_override();
7430             TERM(sublex_start());
7431
7432         case KEY_return:
7433             OLDLOP(OP_RETURN);
7434
7435         case KEY_require:
7436             s = SKIPSPACE1(s);
7437             if (isDIGIT(*s)) {
7438                 s = force_version(s, FALSE);
7439             }
7440             else if (*s != 'v' || !isDIGIT(s[1])
7441                     || (s = force_version(s, TRUE), *s == 'v'))
7442             {
7443                 *PL_tokenbuf = '\0';
7444                 s = force_word(s,WORD,TRUE,TRUE,FALSE);
7445                 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
7446                     gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
7447                 else if (*s == '<')
7448                     yyerror("<> should be quotes");
7449             }
7450             if (orig_keyword == KEY_require) {
7451                 orig_keyword = 0;
7452                 pl_yylval.ival = 1;
7453             }
7454             else 
7455                 pl_yylval.ival = 0;
7456             PL_expect = XTERM;
7457             PL_bufptr = s;
7458             PL_last_uni = PL_oldbufptr;
7459             PL_last_lop_op = OP_REQUIRE;
7460             s = skipspace(s);
7461             return REPORT( (int)REQUIRE );
7462
7463         case KEY_reset:
7464             UNI(OP_RESET);
7465
7466         case KEY_redo:
7467             s = force_word(s,WORD,TRUE,FALSE,FALSE);
7468             LOOPX(OP_REDO);
7469
7470         case KEY_rename:
7471             LOP(OP_RENAME,XTERM);
7472
7473         case KEY_rand:
7474             UNI(OP_RAND);
7475
7476         case KEY_rmdir:
7477             UNI(OP_RMDIR);
7478
7479         case KEY_rindex:
7480             LOP(OP_RINDEX,XTERM);
7481
7482         case KEY_read:
7483             LOP(OP_READ,XTERM);
7484
7485         case KEY_readdir:
7486             UNI(OP_READDIR);
7487
7488         case KEY_readline:
7489             UNIDOR(OP_READLINE);
7490
7491         case KEY_readpipe:
7492             UNIDOR(OP_BACKTICK);
7493
7494         case KEY_rewinddir:
7495             UNI(OP_REWINDDIR);
7496
7497         case KEY_recv:
7498             LOP(OP_RECV,XTERM);
7499
7500         case KEY_reverse:
7501             LOP(OP_REVERSE,XTERM);
7502
7503         case KEY_readlink:
7504             UNIDOR(OP_READLINK);
7505
7506         case KEY_ref:
7507             UNI(OP_REF);
7508
7509         case KEY_s:
7510             s = scan_subst(s);
7511             if (pl_yylval.opval)
7512                 TERM(sublex_start());
7513             else
7514                 TOKEN(1);       /* force error */
7515
7516         case KEY_say:
7517             checkcomma(s,PL_tokenbuf,"filehandle");
7518             LOP(OP_SAY,XREF);
7519
7520         case KEY_chomp:
7521             UNI(OP_CHOMP);
7522         
7523         case KEY_scalar:
7524             UNI(OP_SCALAR);
7525
7526         case KEY_select:
7527             LOP(OP_SELECT,XTERM);
7528
7529         case KEY_seek:
7530             LOP(OP_SEEK,XTERM);
7531
7532         case KEY_semctl:
7533             LOP(OP_SEMCTL,XTERM);
7534
7535         case KEY_semget:
7536             LOP(OP_SEMGET,XTERM);
7537
7538         case KEY_semop:
7539             LOP(OP_SEMOP,XTERM);
7540
7541         case KEY_send:
7542             LOP(OP_SEND,XTERM);
7543
7544         case KEY_setpgrp:
7545             LOP(OP_SETPGRP,XTERM);
7546
7547         case KEY_setpriority:
7548             LOP(OP_SETPRIORITY,XTERM);
7549
7550         case KEY_sethostent:
7551             UNI(OP_SHOSTENT);
7552
7553         case KEY_setnetent:
7554             UNI(OP_SNETENT);
7555
7556         case KEY_setservent:
7557             UNI(OP_SSERVENT);
7558
7559         case KEY_setprotoent:
7560             UNI(OP_SPROTOENT);
7561
7562         case KEY_setpwent:
7563             FUN0(OP_SPWENT);
7564
7565         case KEY_setgrent:
7566             FUN0(OP_SGRENT);
7567
7568         case KEY_seekdir:
7569             LOP(OP_SEEKDIR,XTERM);
7570
7571         case KEY_setsockopt:
7572             LOP(OP_SSOCKOPT,XTERM);
7573
7574         case KEY_shift:
7575             UNIDOR(OP_SHIFT);
7576
7577         case KEY_shmctl:
7578             LOP(OP_SHMCTL,XTERM);
7579
7580         case KEY_shmget:
7581             LOP(OP_SHMGET,XTERM);
7582
7583         case KEY_shmread:
7584             LOP(OP_SHMREAD,XTERM);
7585
7586         case KEY_shmwrite:
7587             LOP(OP_SHMWRITE,XTERM);
7588
7589         case KEY_shutdown:
7590             LOP(OP_SHUTDOWN,XTERM);
7591
7592         case KEY_sin:
7593             UNI(OP_SIN);
7594
7595         case KEY_sleep:
7596             UNI(OP_SLEEP);
7597
7598         case KEY_socket:
7599             LOP(OP_SOCKET,XTERM);
7600
7601         case KEY_socketpair:
7602             LOP(OP_SOCKPAIR,XTERM);
7603
7604         case KEY_sort:
7605             checkcomma(s,PL_tokenbuf,"subroutine name");
7606             s = SKIPSPACE1(s);
7607             if (*s == ';' || *s == ')')         /* probably a close */
7608                 Perl_croak(aTHX_ "sort is now a reserved word");
7609             PL_expect = XTERM;
7610             s = force_word(s,WORD,TRUE,TRUE,FALSE);
7611             LOP(OP_SORT,XREF);
7612
7613         case KEY_split:
7614             LOP(OP_SPLIT,XTERM);
7615
7616         case KEY_sprintf:
7617             LOP(OP_SPRINTF,XTERM);
7618
7619         case KEY_splice:
7620             LOP(OP_SPLICE,XTERM);
7621
7622         case KEY_sqrt:
7623             UNI(OP_SQRT);
7624
7625         case KEY_srand:
7626             UNI(OP_SRAND);
7627
7628         case KEY_stat:
7629             UNI(OP_STAT);
7630
7631         case KEY_study:
7632             UNI(OP_STUDY);
7633
7634         case KEY_substr:
7635             LOP(OP_SUBSTR,XTERM);
7636
7637         case KEY_format:
7638         case KEY_sub:
7639           really_sub:
7640             {
7641                 char tmpbuf[sizeof PL_tokenbuf];
7642                 SSize_t tboffset = 0;
7643                 expectation attrful;
7644                 bool have_name, have_proto;
7645                 const int key = tmp;
7646
7647 #ifdef PERL_MAD
7648                 SV *tmpwhite = 0;
7649
7650                 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
7651                 SV *subtoken = newSVpvn(tstart, s - tstart);
7652                 PL_thistoken = 0;
7653
7654                 d = s;
7655                 s = SKIPSPACE2(s,tmpwhite);
7656 #else
7657                 s = skipspace(s);
7658 #endif
7659
7660                 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
7661                     (*s == ':' && s[1] == ':'))
7662                 {
7663 #ifdef PERL_MAD
7664                     SV *nametoke = NULL;
7665 #endif
7666
7667                     PL_expect = XBLOCK;
7668                     attrful = XATTRBLOCK;
7669                     /* remember buffer pos'n for later force_word */
7670                     tboffset = s - PL_oldbufptr;
7671                     d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
7672 #ifdef PERL_MAD
7673                     if (PL_madskills)
7674                         nametoke = newSVpvn(s, d - s);
7675 #endif
7676                     if (memchr(tmpbuf, ':', len))
7677                         sv_setpvn(PL_subname, tmpbuf, len);
7678                     else {
7679                         sv_setsv(PL_subname,PL_curstname);
7680                         sv_catpvs(PL_subname,"::");
7681                         sv_catpvn(PL_subname,tmpbuf,len);
7682                     }
7683                     have_name = TRUE;
7684
7685 #ifdef PERL_MAD
7686
7687                     start_force(0);
7688                     CURMAD('X', nametoke);
7689                     CURMAD('_', tmpwhite);
7690                     (void) force_word(PL_oldbufptr + tboffset, WORD,
7691                                       FALSE, TRUE, TRUE);
7692
7693                     s = SKIPSPACE2(d,tmpwhite);
7694 #else
7695                     s = skipspace(d);
7696 #endif
7697                 }
7698                 else {
7699                     if (key == KEY_my)
7700                         Perl_croak(aTHX_ "Missing name in \"my sub\"");
7701                     PL_expect = XTERMBLOCK;
7702                     attrful = XATTRTERM;
7703                     sv_setpvs(PL_subname,"?");
7704                     have_name = FALSE;
7705                 }
7706
7707                 if (key == KEY_format) {
7708                     if (*s == '=')
7709                         PL_lex_formbrack = PL_lex_brackets + 1;
7710 #ifdef PERL_MAD
7711                     PL_thistoken = subtoken;
7712                     s = d;
7713 #else
7714                     if (have_name)
7715                         (void) force_word(PL_oldbufptr + tboffset, WORD,
7716                                           FALSE, TRUE, TRUE);
7717 #endif
7718                     OPERATOR(FORMAT);
7719                 }
7720
7721                 /* Look for a prototype */
7722                 if (*s == '(') {
7723                     char *p;
7724                     bool bad_proto = FALSE;
7725                     bool in_brackets = FALSE;
7726                     char greedy_proto = ' ';
7727                     bool proto_after_greedy_proto = FALSE;
7728                     bool must_be_last = FALSE;
7729                     bool underscore = FALSE;
7730                     bool seen_underscore = FALSE;
7731                     const bool warnillegalproto = ckWARN(WARN_ILLEGALPROTO);
7732
7733                     s = scan_str(s,!!PL_madskills,FALSE);
7734                     if (!s)
7735                         Perl_croak(aTHX_ "Prototype not terminated");
7736                     /* strip spaces and check for bad characters */
7737                     d = SvPVX(PL_lex_stuff);
7738                     tmp = 0;
7739                     for (p = d; *p; ++p) {
7740                         if (!isSPACE(*p)) {
7741                             d[tmp++] = *p;
7742
7743                             if (warnillegalproto) {
7744                                 if (must_be_last)
7745                                     proto_after_greedy_proto = TRUE;
7746                                 if (!strchr("$@%*;[]&\\_+", *p)) {
7747                                     bad_proto = TRUE;
7748                                 }
7749                                 else {
7750                                     if ( underscore ) {
7751                                         if ( *p != ';' )
7752                                             bad_proto = TRUE;
7753                                         underscore = FALSE;
7754                                     }
7755                                     if ( *p == '[' ) {
7756                                         in_brackets = TRUE;
7757                                     }
7758                                     else if ( *p == ']' ) {
7759                                         in_brackets = FALSE;
7760                                     }
7761                                     else if ( (*p == '@' || *p == '%') &&
7762                                          ( tmp < 2 || d[tmp-2] != '\\' ) &&
7763                                          !in_brackets ) {
7764                                         must_be_last = TRUE;
7765                                         greedy_proto = *p;
7766                                     }
7767                                     else if ( *p == '_' ) {
7768                                         underscore = seen_underscore = TRUE;
7769                                     }
7770                                 }
7771                             }
7772                         }
7773                     }
7774                     d[tmp] = '\0';
7775                     if (proto_after_greedy_proto)
7776                         Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO),
7777                                     "Prototype after '%c' for %"SVf" : %s",
7778                                     greedy_proto, SVfARG(PL_subname), d);
7779                     if (bad_proto)
7780                         Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO),
7781                                     "Illegal character %sin prototype for %"SVf" : %s",
7782                                     seen_underscore ? "after '_' " : "",
7783                                     SVfARG(PL_subname), d);
7784                     SvCUR_set(PL_lex_stuff, tmp);
7785                     have_proto = TRUE;
7786
7787 #ifdef PERL_MAD
7788                     start_force(0);
7789                     CURMAD('q', PL_thisopen);
7790                     CURMAD('_', tmpwhite);
7791                     CURMAD('=', PL_thisstuff);
7792                     CURMAD('Q', PL_thisclose);
7793                     NEXTVAL_NEXTTOKE.opval =
7794                         (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
7795                     PL_lex_stuff = NULL;
7796                     force_next(THING);
7797
7798                     s = SKIPSPACE2(s,tmpwhite);
7799 #else
7800                     s = skipspace(s);
7801 #endif
7802                 }
7803                 else
7804                     have_proto = FALSE;
7805
7806                 if (*s == ':' && s[1] != ':')
7807                     PL_expect = attrful;
7808                 else if (*s != '{' && key == KEY_sub) {
7809                     if (!have_name)
7810                         Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
7811                     else if (*s != ';' && *s != '}')
7812                         Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
7813                 }
7814
7815 #ifdef PERL_MAD
7816                 start_force(0);
7817                 if (tmpwhite) {
7818                     if (PL_madskills)
7819                         curmad('^', newSVpvs(""));
7820                     CURMAD('_', tmpwhite);
7821                 }
7822                 force_next(0);
7823
7824                 PL_thistoken = subtoken;
7825 #else
7826                 if (have_proto) {
7827                     NEXTVAL_NEXTTOKE.opval =
7828                         (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
7829                     PL_lex_stuff = NULL;
7830                     force_next(THING);
7831                 }
7832 #endif
7833                 if (!have_name) {
7834                     if (PL_curstash)
7835                         sv_setpvs(PL_subname, "__ANON__");
7836                     else
7837                         sv_setpvs(PL_subname, "__ANON__::__ANON__");
7838                     TOKEN(ANONSUB);
7839                 }
7840 #ifndef PERL_MAD
7841                 (void) force_word(PL_oldbufptr + tboffset, WORD,
7842                                   FALSE, TRUE, TRUE);
7843 #endif
7844                 if (key == KEY_my)
7845                     TOKEN(MYSUB);
7846                 TOKEN(SUB);
7847             }
7848
7849         case KEY_system:
7850             LOP(OP_SYSTEM,XREF);
7851
7852         case KEY_symlink:
7853             LOP(OP_SYMLINK,XTERM);
7854
7855         case KEY_syscall:
7856             LOP(OP_SYSCALL,XTERM);
7857
7858         case KEY_sysopen:
7859             LOP(OP_SYSOPEN,XTERM);
7860
7861         case KEY_sysseek:
7862             LOP(OP_SYSSEEK,XTERM);
7863
7864         case KEY_sysread:
7865             LOP(OP_SYSREAD,XTERM);
7866
7867         case KEY_syswrite:
7868             LOP(OP_SYSWRITE,XTERM);
7869
7870         case KEY_tr:
7871             s = scan_trans(s);
7872             TERM(sublex_start());
7873
7874         case KEY_tell:
7875             UNI(OP_TELL);
7876
7877         case KEY_telldir:
7878             UNI(OP_TELLDIR);
7879
7880         case KEY_tie:
7881             LOP(OP_TIE,XTERM);
7882
7883         case KEY_tied:
7884             UNI(OP_TIED);
7885
7886         case KEY_time:
7887             FUN0(OP_TIME);
7888
7889         case KEY_times:
7890             FUN0(OP_TMS);
7891
7892         case KEY_truncate:
7893             LOP(OP_TRUNCATE,XTERM);
7894
7895         case KEY_uc:
7896             UNI(OP_UC);
7897
7898         case KEY_ucfirst:
7899             UNI(OP_UCFIRST);
7900
7901         case KEY_untie:
7902             UNI(OP_UNTIE);
7903
7904         case KEY_until:
7905             pl_yylval.ival = CopLINE(PL_curcop);
7906             OPERATOR(UNTIL);
7907
7908         case KEY_unless:
7909             pl_yylval.ival = CopLINE(PL_curcop);
7910             OPERATOR(UNLESS);
7911
7912         case KEY_unlink:
7913             LOP(OP_UNLINK,XTERM);
7914
7915         case KEY_undef:
7916             UNIDOR(OP_UNDEF);
7917
7918         case KEY_unpack:
7919             LOP(OP_UNPACK,XTERM);
7920
7921         case KEY_utime:
7922             LOP(OP_UTIME,XTERM);
7923
7924         case KEY_umask:
7925             UNIDOR(OP_UMASK);
7926
7927         case KEY_unshift:
7928             LOP(OP_UNSHIFT,XTERM);
7929
7930         case KEY_use:
7931             s = tokenize_use(1, s);
7932             OPERATOR(USE);
7933
7934         case KEY_values:
7935             UNI(OP_VALUES);
7936
7937         case KEY_vec:
7938             LOP(OP_VEC,XTERM);
7939
7940         case KEY_when:
7941             pl_yylval.ival = CopLINE(PL_curcop);
7942             OPERATOR(WHEN);
7943
7944         case KEY_while:
7945             pl_yylval.ival = CopLINE(PL_curcop);
7946             OPERATOR(WHILE);
7947
7948         case KEY_warn:
7949             PL_hints |= HINT_BLOCK_SCOPE;
7950             LOP(OP_WARN,XTERM);
7951
7952         case KEY_wait:
7953             FUN0(OP_WAIT);
7954
7955         case KEY_waitpid:
7956             LOP(OP_WAITPID,XTERM);
7957
7958         case KEY_wantarray:
7959             FUN0(OP_WANTARRAY);
7960
7961         case KEY_write:
7962 #ifdef EBCDIC
7963         {
7964             char ctl_l[2];
7965             ctl_l[0] = toCTRL('L');
7966             ctl_l[1] = '\0';
7967             gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
7968         }
7969 #else
7970             /* Make sure $^L is defined */
7971             gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
7972 #endif
7973             UNI(OP_ENTERWRITE);
7974
7975         case KEY_x:
7976             if (PL_expect == XOPERATOR)
7977                 Mop(OP_REPEAT);
7978             check_uni();
7979             goto just_a_word;
7980
7981         case KEY_xor:
7982             pl_yylval.ival = OP_XOR;
7983             OPERATOR(OROP);
7984
7985         case KEY_y:
7986             s = scan_trans(s);
7987             TERM(sublex_start());
7988         }
7989     }}
7990 }
7991 #ifdef __SC__
7992 #pragma segment Main
7993 #endif
7994
7995 static int
7996 S_pending_ident(pTHX)
7997 {
7998     dVAR;
7999     register char *d;
8000     PADOFFSET tmp = 0;
8001     /* pit holds the identifier we read and pending_ident is reset */
8002     char pit = PL_pending_ident;
8003     const STRLEN tokenbuf_len = strlen(PL_tokenbuf);
8004     /* All routes through this function want to know if there is a colon.  */
8005     const char *const has_colon = (const char*) memchr (PL_tokenbuf, ':', tokenbuf_len);
8006     PL_pending_ident = 0;
8007
8008     /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
8009     DEBUG_T({ PerlIO_printf(Perl_debug_log,
8010           "### Pending identifier '%s'\n", PL_tokenbuf); });
8011
8012     /* if we're in a my(), we can't allow dynamics here.
8013        $foo'bar has already been turned into $foo::bar, so
8014        just check for colons.
8015
8016        if it's a legal name, the OP is a PADANY.
8017     */
8018     if (PL_in_my) {
8019         if (PL_in_my == KEY_our) {      /* "our" is merely analogous to "my" */
8020             if (has_colon)
8021                 yyerror(Perl_form(aTHX_ "No package name allowed for "
8022                                   "variable %s in \"our\"",
8023                                   PL_tokenbuf));
8024             tmp = allocmy(PL_tokenbuf, tokenbuf_len, 0);
8025         }
8026         else {
8027             if (has_colon)
8028                 yyerror(Perl_form(aTHX_ PL_no_myglob,
8029                             PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
8030
8031             pl_yylval.opval = newOP(OP_PADANY, 0);
8032             pl_yylval.opval->op_targ = allocmy(PL_tokenbuf, tokenbuf_len, 0);
8033             return PRIVATEREF;
8034         }
8035     }
8036
8037     /*
8038        build the ops for accesses to a my() variable.
8039
8040        Deny my($a) or my($b) in a sort block, *if* $a or $b is
8041        then used in a comparison.  This catches most, but not
8042        all cases.  For instance, it catches
8043            sort { my($a); $a <=> $b }
8044        but not
8045            sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
8046        (although why you'd do that is anyone's guess).
8047     */
8048
8049     if (!has_colon) {
8050         if (!PL_in_my)
8051             tmp = pad_findmy(PL_tokenbuf, tokenbuf_len, 0);
8052         if (tmp != NOT_IN_PAD) {
8053             /* might be an "our" variable" */
8054             if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
8055                 /* build ops for a bareword */
8056                 HV *  const stash = PAD_COMPNAME_OURSTASH(tmp);
8057                 HEK * const stashname = HvNAME_HEK(stash);
8058                 SV *  const sym = newSVhek(stashname);
8059                 sv_catpvs(sym, "::");
8060                 sv_catpvn(sym, PL_tokenbuf+1, tokenbuf_len - 1);
8061                 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
8062                 pl_yylval.opval->op_private = OPpCONST_ENTERED;
8063                 gv_fetchsv(sym,
8064                     (PL_in_eval
8065                         ? (GV_ADDMULTI | GV_ADDINEVAL)
8066                         : GV_ADDMULTI
8067                     ),
8068                     ((PL_tokenbuf[0] == '$') ? SVt_PV
8069                      : (PL_tokenbuf[0] == '@') ? SVt_PVAV
8070                      : SVt_PVHV));
8071                 return WORD;
8072             }
8073
8074             /* if it's a sort block and they're naming $a or $b */
8075             if (PL_last_lop_op == OP_SORT &&
8076                 PL_tokenbuf[0] == '$' &&
8077                 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
8078                 && !PL_tokenbuf[2])
8079             {
8080                 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
8081                      d < PL_bufend && *d != '\n';
8082                      d++)
8083                 {
8084                     if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
8085                         Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
8086                               PL_tokenbuf);
8087                     }
8088                 }
8089             }
8090
8091             pl_yylval.opval = newOP(OP_PADANY, 0);
8092             pl_yylval.opval->op_targ = tmp;
8093             return PRIVATEREF;
8094         }
8095     }
8096
8097     /*
8098        Whine if they've said @foo in a doublequoted string,
8099        and @foo isn't a variable we can find in the symbol
8100        table.
8101     */
8102     if (ckWARN(WARN_AMBIGUOUS) &&
8103         pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
8104         GV *const gv = gv_fetchpvn_flags(PL_tokenbuf + 1, tokenbuf_len - 1, 0,
8105                                          SVt_PVAV);
8106         if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
8107                 /* DO NOT warn for @- and @+ */
8108                 && !( PL_tokenbuf[2] == '\0' &&
8109                     ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
8110            )
8111         {
8112             /* Downgraded from fatal to warning 20000522 mjd */
8113             Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
8114                         "Possible unintended interpolation of %s in string",
8115                         PL_tokenbuf);
8116         }
8117     }
8118
8119     /* build ops for a bareword */
8120     pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpvn(PL_tokenbuf + 1,
8121                                                       tokenbuf_len - 1));
8122     pl_yylval.opval->op_private = OPpCONST_ENTERED;
8123     gv_fetchpvn_flags(PL_tokenbuf+1, tokenbuf_len - 1,
8124                      PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD,
8125                      ((PL_tokenbuf[0] == '$') ? SVt_PV
8126                       : (PL_tokenbuf[0] == '@') ? SVt_PVAV
8127                       : SVt_PVHV));
8128     return WORD;
8129 }
8130
8131 /*
8132  *  The following code was generated by perl_keyword.pl.
8133  */
8134
8135 I32
8136 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
8137 {
8138     dVAR;
8139
8140     PERL_ARGS_ASSERT_KEYWORD;
8141
8142   switch (len)
8143   {
8144     case 1: /* 5 tokens of length 1 */
8145       switch (name[0])
8146       {
8147         case 'm':
8148           {                                       /* m          */
8149             return KEY_m;
8150           }
8151
8152         case 'q':
8153           {                                       /* q          */
8154             return KEY_q;
8155           }
8156
8157         case 's':
8158           {                                       /* s          */
8159             return KEY_s;
8160           }
8161
8162         case 'x':
8163           {                                       /* x          */
8164             return -KEY_x;
8165           }
8166
8167         case 'y':
8168           {                                       /* y          */
8169             return KEY_y;
8170           }
8171
8172         default:
8173           goto unknown;
8174       }
8175
8176     case 2: /* 18 tokens of length 2 */
8177       switch (name[0])
8178       {
8179         case 'd':
8180           if (name[1] == 'o')
8181           {                                       /* do         */
8182             return KEY_do;
8183           }
8184
8185           goto unknown;
8186
8187         case 'e':
8188           if (name[1] == 'q')
8189           {                                       /* eq         */
8190             return -KEY_eq;
8191           }
8192
8193           goto unknown;
8194
8195         case 'g':
8196           switch (name[1])
8197           {
8198             case 'e':
8199               {                                   /* ge         */
8200                 return -KEY_ge;
8201               }
8202
8203             case 't':
8204               {                                   /* gt         */
8205                 return -KEY_gt;
8206               }
8207
8208             default:
8209               goto unknown;
8210           }
8211
8212         case 'i':
8213           if (name[1] == 'f')
8214           {                                       /* if         */
8215             return KEY_if;
8216           }
8217
8218           goto unknown;
8219
8220         case 'l':
8221           switch (name[1])
8222           {
8223             case 'c':
8224               {                                   /* lc         */
8225                 return -KEY_lc;
8226               }
8227
8228             case 'e':
8229               {                                   /* le         */
8230                 return -KEY_le;
8231               }
8232
8233             case 't':
8234               {                                   /* lt         */
8235                 return -KEY_lt;
8236               }
8237
8238             default:
8239               goto unknown;
8240           }
8241
8242         case 'm':
8243           if (name[1] == 'y')
8244           {                                       /* my         */
8245             return KEY_my;
8246           }
8247
8248           goto unknown;
8249
8250         case 'n':
8251           switch (name[1])
8252           {
8253             case 'e':
8254               {                                   /* ne         */
8255                 return -KEY_ne;
8256               }
8257
8258             case 'o':
8259               {                                   /* no         */
8260                 return KEY_no;
8261               }
8262
8263             default:
8264               goto unknown;
8265           }
8266
8267         case 'o':
8268           if (name[1] == 'r')
8269           {                                       /* or         */
8270             return -KEY_or;
8271           }
8272
8273           goto unknown;
8274
8275         case 'q':
8276           switch (name[1])
8277           {
8278             case 'q':
8279               {                                   /* qq         */
8280                 return KEY_qq;
8281               }
8282
8283             case 'r':
8284               {                                   /* qr         */
8285                 return KEY_qr;
8286               }
8287
8288             case 'w':
8289               {                                   /* qw         */
8290                 return KEY_qw;
8291               }
8292
8293             case 'x':
8294               {                                   /* qx         */
8295                 return KEY_qx;
8296               }
8297
8298             default:
8299               goto unknown;
8300           }
8301
8302         case 't':
8303           if (name[1] == 'r')
8304           {                                       /* tr         */
8305             return KEY_tr;
8306           }
8307
8308           goto unknown;
8309
8310         case 'u':
8311           if (name[1] == 'c')
8312           {                                       /* uc         */
8313             return -KEY_uc;
8314           }
8315
8316           goto unknown;
8317
8318         default:
8319           goto unknown;
8320       }
8321
8322     case 3: /* 29 tokens of length 3 */
8323       switch (name[0])
8324       {
8325         case 'E':
8326           if (name[1] == 'N' &&
8327               name[2] == 'D')
8328           {                                       /* END        */
8329             return KEY_END;
8330           }
8331
8332           goto unknown;
8333
8334         case 'a':
8335           switch (name[1])
8336           {
8337             case 'b':
8338               if (name[2] == 's')
8339               {                                   /* abs        */
8340                 return -KEY_abs;
8341               }
8342
8343               goto unknown;
8344
8345             case 'n':
8346               if (name[2] == 'd')
8347               {                                   /* and        */
8348                 return -KEY_and;
8349               }
8350
8351               goto unknown;
8352
8353             default:
8354               goto unknown;
8355           }
8356
8357         case 'c':
8358           switch (name[1])
8359           {
8360             case 'h':
8361               if (name[2] == 'r')
8362               {                                   /* chr        */
8363                 return -KEY_chr;
8364               }
8365
8366               goto unknown;
8367
8368             case 'm':
8369               if (name[2] == 'p')
8370               {                                   /* cmp        */
8371                 return -KEY_cmp;
8372               }
8373
8374               goto unknown;
8375
8376             case 'o':
8377               if (name[2] == 's')
8378               {                                   /* cos        */
8379                 return -KEY_cos;
8380               }
8381
8382               goto unknown;
8383
8384             default:
8385               goto unknown;
8386           }
8387
8388         case 'd':
8389           if (name[1] == 'i' &&
8390               name[2] == 'e')
8391           {                                       /* die        */
8392             return -KEY_die;
8393           }
8394
8395           goto unknown;
8396
8397         case 'e':
8398           switch (name[1])
8399           {
8400             case 'o':
8401               if (name[2] == 'f')
8402               {                                   /* eof        */
8403                 return -KEY_eof;
8404               }
8405
8406               goto unknown;
8407
8408             case 'x':
8409               if (name[2] == 'p')
8410               {                                   /* exp        */
8411                 return -KEY_exp;
8412               }
8413
8414               goto unknown;
8415
8416             default:
8417               goto unknown;
8418           }
8419
8420         case 'f':
8421           if (name[1] == 'o' &&
8422               name[2] == 'r')
8423           {                                       /* for        */
8424             return KEY_for;
8425           }
8426
8427           goto unknown;
8428
8429         case 'h':
8430           if (name[1] == 'e' &&
8431               name[2] == 'x')
8432           {                                       /* hex        */
8433             return -KEY_hex;
8434           }
8435
8436           goto unknown;
8437
8438         case 'i':
8439           if (name[1] == 'n' &&
8440               name[2] == 't')
8441           {                                       /* int        */
8442             return -KEY_int;
8443           }
8444
8445           goto unknown;
8446
8447         case 'l':
8448           if (name[1] == 'o' &&
8449               name[2] == 'g')
8450           {                                       /* log        */
8451             return -KEY_log;
8452           }
8453
8454           goto unknown;
8455
8456         case 'm':
8457           if (name[1] == 'a' &&
8458               name[2] == 'p')
8459           {                                       /* map        */
8460             return KEY_map;
8461           }
8462
8463           goto unknown;
8464
8465         case 'n':
8466           if (name[1] == 'o' &&
8467               name[2] == 't')
8468           {                                       /* not        */
8469             return -KEY_not;
8470           }
8471
8472           goto unknown;
8473
8474         case 'o':
8475           switch (name[1])
8476           {
8477             case 'c':
8478               if (name[2] == 't')
8479               {                                   /* oct        */
8480                 return -KEY_oct;
8481               }
8482
8483               goto unknown;
8484
8485             case 'r':
8486               if (name[2] == 'd')
8487               {                                   /* ord        */
8488                 return -KEY_ord;
8489               }
8490
8491               goto unknown;
8492
8493             case 'u':
8494               if (name[2] == 'r')
8495               {                                   /* our        */
8496                 return KEY_our;
8497               }
8498
8499               goto unknown;
8500
8501             default:
8502               goto unknown;
8503           }
8504
8505         case 'p':
8506           if (name[1] == 'o')
8507           {
8508             switch (name[2])
8509             {
8510               case 'p':
8511                 {                                 /* pop        */
8512                   return -KEY_pop;
8513                 }
8514
8515               case 's':
8516                 {                                 /* pos        */
8517                   return KEY_pos;
8518                 }
8519
8520               default:
8521                 goto unknown;
8522             }
8523           }
8524
8525           goto unknown;
8526
8527         case 'r':
8528           if (name[1] == 'e' &&
8529               name[2] == 'f')
8530           {                                       /* ref        */
8531             return -KEY_ref;
8532           }
8533
8534           goto unknown;
8535
8536         case 's':
8537           switch (name[1])
8538           {
8539             case 'a':
8540               if (name[2] == 'y')
8541               {                                   /* say        */
8542                 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
8543               }
8544
8545               goto unknown;
8546
8547             case 'i':
8548               if (name[2] == 'n')
8549               {                                   /* sin        */
8550                 return -KEY_sin;
8551               }
8552
8553               goto unknown;
8554
8555             case 'u':
8556               if (name[2] == 'b')
8557               {                                   /* sub        */
8558                 return KEY_sub;
8559               }
8560
8561               goto unknown;
8562
8563             default:
8564               goto unknown;
8565           }
8566
8567         case 't':
8568           if (name[1] == 'i' &&
8569               name[2] == 'e')
8570           {                                       /* tie        */
8571             return -KEY_tie;
8572           }
8573
8574           goto unknown;
8575
8576         case 'u':
8577           if (name[1] == 's' &&
8578               name[2] == 'e')
8579           {                                       /* use        */
8580             return KEY_use;
8581           }
8582
8583           goto unknown;
8584
8585         case 'v':
8586           if (name[1] == 'e' &&
8587               name[2] == 'c')
8588           {                                       /* vec        */
8589             return -KEY_vec;
8590           }
8591
8592           goto unknown;
8593
8594         case 'x':
8595           if (name[1] == 'o' &&
8596               name[2] == 'r')
8597           {                                       /* xor        */
8598             return -KEY_xor;
8599           }
8600
8601           goto unknown;
8602
8603         default:
8604           goto unknown;
8605       }
8606
8607     case 4: /* 41 tokens of length 4 */
8608       switch (name[0])
8609       {
8610         case 'C':
8611           if (name[1] == 'O' &&
8612               name[2] == 'R' &&
8613               name[3] == 'E')
8614           {                                       /* CORE       */
8615             return -KEY_CORE;
8616           }
8617
8618           goto unknown;
8619
8620         case 'I':
8621           if (name[1] == 'N' &&
8622               name[2] == 'I' &&
8623               name[3] == 'T')
8624           {                                       /* INIT       */
8625             return KEY_INIT;
8626           }
8627
8628           goto unknown;
8629
8630         case 'b':
8631           if (name[1] == 'i' &&
8632               name[2] == 'n' &&
8633               name[3] == 'd')
8634           {                                       /* bind       */
8635             return -KEY_bind;
8636           }
8637
8638           goto unknown;
8639
8640         case 'c':
8641           if (name[1] == 'h' &&
8642               name[2] == 'o' &&
8643               name[3] == 'p')
8644           {                                       /* chop       */
8645             return -KEY_chop;
8646           }
8647
8648           goto unknown;
8649
8650         case 'd':
8651           if (name[1] == 'u' &&
8652               name[2] == 'm' &&
8653               name[3] == 'p')
8654           {                                       /* dump       */
8655             return -KEY_dump;
8656           }
8657
8658           goto unknown;
8659
8660         case 'e':
8661           switch (name[1])
8662           {
8663             case 'a':
8664               if (name[2] == 'c' &&
8665                   name[3] == 'h')
8666               {                                   /* each       */
8667                 return -KEY_each;
8668               }
8669
8670               goto unknown;
8671
8672             case 'l':
8673               if (name[2] == 's' &&
8674                   name[3] == 'e')
8675               {                                   /* else       */
8676                 return KEY_else;
8677               }
8678
8679               goto unknown;
8680
8681             case 'v':
8682               if (name[2] == 'a' &&
8683                   name[3] == 'l')
8684               {                                   /* eval       */
8685                 return KEY_eval;
8686               }
8687
8688               goto unknown;
8689
8690             case 'x':
8691               switch (name[2])
8692               {
8693                 case 'e':
8694                   if (name[3] == 'c')
8695                   {                               /* exec       */
8696                     return -KEY_exec;
8697                   }
8698
8699                   goto unknown;
8700
8701                 case 'i':
8702                   if (name[3] == 't')
8703                   {                               /* exit       */
8704                     return -KEY_exit;
8705                   }
8706
8707                   goto unknown;
8708
8709                 default:
8710                   goto unknown;
8711               }
8712
8713             default:
8714               goto unknown;
8715           }
8716
8717         case 'f':
8718           if (name[1] == 'o' &&
8719               name[2] == 'r' &&
8720               name[3] == 'k')
8721           {                                       /* fork       */
8722             return -KEY_fork;
8723           }
8724
8725           goto unknown;
8726
8727         case 'g':
8728           switch (name[1])
8729           {
8730             case 'e':
8731               if (name[2] == 't' &&
8732                   name[3] == 'c')
8733               {                                   /* getc       */
8734                 return -KEY_getc;
8735               }
8736
8737               goto unknown;
8738
8739             case 'l':
8740               if (name[2] == 'o' &&
8741                   name[3] == 'b')
8742               {                                   /* glob       */
8743                 return KEY_glob;
8744               }
8745
8746               goto unknown;
8747
8748             case 'o':
8749               if (name[2] == 't' &&
8750                   name[3] == 'o')
8751               {                                   /* goto       */
8752                 return KEY_goto;
8753               }
8754
8755               goto unknown;
8756
8757             case 'r':
8758               if (name[2] == 'e' &&
8759                   name[3] == 'p')
8760               {                                   /* grep       */
8761                 return KEY_grep;
8762               }
8763
8764               goto unknown;
8765
8766             default:
8767               goto unknown;
8768           }
8769
8770         case 'j':
8771           if (name[1] == 'o' &&
8772               name[2] == 'i' &&
8773               name[3] == 'n')
8774           {                                       /* join       */
8775             return -KEY_join;
8776           }
8777
8778           goto unknown;
8779
8780         case 'k':
8781           switch (name[1])
8782           {
8783             case 'e':
8784               if (name[2] == 'y' &&
8785                   name[3] == 's')
8786               {                                   /* keys       */
8787                 return -KEY_keys;
8788               }
8789
8790               goto unknown;
8791
8792             case 'i':
8793               if (name[2] == 'l' &&
8794                   name[3] == 'l')
8795               {                                   /* kill       */
8796                 return -KEY_kill;
8797               }
8798
8799               goto unknown;
8800
8801             default:
8802               goto unknown;
8803           }
8804
8805         case 'l':
8806           switch (name[1])
8807           {
8808             case 'a':
8809               if (name[2] == 's' &&
8810                   name[3] == 't')
8811               {                                   /* last       */
8812                 return KEY_last;
8813               }
8814
8815               goto unknown;
8816
8817             case 'i':
8818               if (name[2] == 'n' &&
8819                   name[3] == 'k')
8820               {                                   /* link       */
8821                 return -KEY_link;
8822               }
8823
8824               goto unknown;
8825
8826             case 'o':
8827               if (name[2] == 'c' &&
8828                   name[3] == 'k')
8829               {                                   /* lock       */
8830                 return -KEY_lock;
8831               }
8832
8833               goto unknown;
8834
8835             default:
8836               goto unknown;
8837           }
8838
8839         case 'n':
8840           if (name[1] == 'e' &&
8841               name[2] == 'x' &&
8842               name[3] == 't')
8843           {                                       /* next       */
8844             return KEY_next;
8845           }
8846
8847           goto unknown;
8848
8849         case 'o':
8850           if (name[1] == 'p' &&
8851               name[2] == 'e' &&
8852               name[3] == 'n')
8853           {                                       /* open       */
8854             return -KEY_open;
8855           }
8856
8857           goto unknown;
8858
8859         case 'p':
8860           switch (name[1])
8861           {
8862             case 'a':
8863               if (name[2] == 'c' &&
8864                   name[3] == 'k')
8865               {                                   /* pack       */
8866                 return -KEY_pack;
8867               }
8868
8869               goto unknown;
8870
8871             case 'i':
8872               if (name[2] == 'p' &&
8873                   name[3] == 'e')
8874               {                                   /* pipe       */
8875                 return -KEY_pipe;
8876               }
8877
8878               goto unknown;
8879
8880             case 'u':
8881               if (name[2] == 's' &&
8882                   name[3] == 'h')
8883               {                                   /* push       */
8884                 return -KEY_push;
8885               }
8886
8887               goto unknown;
8888
8889             default:
8890               goto unknown;
8891           }
8892
8893         case 'r':
8894           switch (name[1])
8895           {
8896             case 'a':
8897               if (name[2] == 'n' &&
8898                   name[3] == 'd')
8899               {                                   /* rand       */
8900                 return -KEY_rand;
8901               }
8902
8903               goto unknown;
8904
8905             case 'e':
8906               switch (name[2])
8907               {
8908                 case 'a':
8909                   if (name[3] == 'd')
8910                   {                               /* read       */
8911                     return -KEY_read;
8912                   }
8913
8914                   goto unknown;
8915
8916                 case 'c':
8917                   if (name[3] == 'v')
8918                   {                               /* recv       */
8919                     return -KEY_recv;
8920                   }
8921
8922                   goto unknown;
8923
8924                 case 'd':
8925                   if (name[3] == 'o')
8926                   {                               /* redo       */
8927                     return KEY_redo;
8928                   }
8929
8930                   goto unknown;
8931
8932                 default:
8933                   goto unknown;
8934               }
8935
8936             default:
8937               goto unknown;
8938           }
8939
8940         case 's':
8941           switch (name[1])
8942           {
8943             case 'e':
8944               switch (name[2])
8945               {
8946                 case 'e':
8947                   if (name[3] == 'k')
8948                   {                               /* seek       */
8949                     return -KEY_seek;
8950                   }
8951
8952                   goto unknown;
8953
8954                 case 'n':
8955                   if (name[3] == 'd')
8956                   {                               /* send       */
8957                     return -KEY_send;
8958                   }
8959
8960                   goto unknown;
8961
8962                 default:
8963                   goto unknown;
8964               }
8965
8966             case 'o':
8967               if (name[2] == 'r' &&
8968                   name[3] == 't')
8969               {                                   /* sort       */
8970                 return KEY_sort;
8971               }
8972
8973               goto unknown;
8974
8975             case 'q':
8976               if (name[2] == 'r' &&
8977                   name[3] == 't')
8978               {                                   /* sqrt       */
8979                 return -KEY_sqrt;
8980               }
8981
8982               goto unknown;
8983
8984             case 't':
8985               if (name[2] == 'a' &&
8986                   name[3] == 't')
8987               {                                   /* stat       */
8988                 return -KEY_stat;
8989               }
8990
8991               goto unknown;
8992
8993             default:
8994               goto unknown;
8995           }
8996
8997         case 't':
8998           switch (name[1])
8999           {
9000             case 'e':
9001               if (name[2] == 'l' &&
9002                   name[3] == 'l')
9003               {                                   /* tell       */
9004                 return -KEY_tell;
9005               }
9006
9007               goto unknown;
9008
9009             case 'i':
9010               switch (name[2])
9011               {
9012                 case 'e':
9013                   if (name[3] == 'd')
9014                   {                               /* tied       */
9015                     return -KEY_tied;
9016                   }
9017
9018                   goto unknown;
9019
9020                 case 'm':
9021                   if (name[3] == 'e')
9022                   {                               /* time       */
9023                     return -KEY_time;
9024                   }
9025
9026                   goto unknown;
9027
9028                 default:
9029                   goto unknown;
9030               }
9031
9032             default:
9033               goto unknown;
9034           }
9035
9036         case 'w':
9037           switch (name[1])
9038           {
9039             case 'a':
9040               switch (name[2])
9041               {
9042                 case 'i':
9043                   if (name[3] == 't')
9044                   {                               /* wait       */
9045                     return -KEY_wait;
9046                   }
9047
9048                   goto unknown;
9049
9050                 case 'r':
9051                   if (name[3] == 'n')
9052                   {                               /* warn       */
9053                     return -KEY_warn;
9054                   }
9055
9056                   goto unknown;
9057
9058                 default:
9059                   goto unknown;
9060               }
9061
9062             case 'h':
9063               if (name[2] == 'e' &&
9064                   name[3] == 'n')
9065               {                                   /* when       */
9066                 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
9067               }
9068
9069               goto unknown;
9070
9071             default:
9072               goto unknown;
9073           }
9074
9075         default:
9076           goto unknown;
9077       }
9078
9079     case 5: /* 39 tokens of length 5 */
9080       switch (name[0])
9081       {
9082         case 'B':
9083           if (name[1] == 'E' &&
9084               name[2] == 'G' &&
9085               name[3] == 'I' &&
9086               name[4] == 'N')
9087           {                                       /* BEGIN      */
9088             return KEY_BEGIN;
9089           }
9090
9091           goto unknown;
9092
9093         case 'C':
9094           if (name[1] == 'H' &&
9095               name[2] == 'E' &&
9096               name[3] == 'C' &&
9097               name[4] == 'K')
9098           {                                       /* CHECK      */
9099             return KEY_CHECK;
9100           }
9101
9102           goto unknown;
9103
9104         case 'a':
9105           switch (name[1])
9106           {
9107             case 'l':
9108               if (name[2] == 'a' &&
9109                   name[3] == 'r' &&
9110                   name[4] == 'm')
9111               {                                   /* alarm      */
9112                 return -KEY_alarm;
9113               }
9114
9115               goto unknown;
9116
9117             case 't':
9118               if (name[2] == 'a' &&
9119                   name[3] == 'n' &&
9120                   name[4] == '2')
9121               {                                   /* atan2      */
9122                 return -KEY_atan2;
9123               }
9124
9125               goto unknown;
9126
9127             default:
9128               goto unknown;
9129           }
9130
9131         case 'b':
9132           switch (name[1])
9133           {
9134             case 'l':
9135               if (name[2] == 'e' &&
9136                   name[3] == 's' &&
9137                   name[4] == 's')
9138               {                                   /* bless      */
9139                 return -KEY_bless;
9140               }
9141
9142               goto unknown;
9143
9144             case 'r':
9145               if (name[2] == 'e' &&
9146                   name[3] == 'a' &&
9147                   name[4] == 'k')
9148               {                                   /* break      */
9149                 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
9150               }
9151
9152               goto unknown;
9153
9154             default:
9155               goto unknown;
9156           }
9157
9158         case 'c':
9159           switch (name[1])
9160           {
9161             case 'h':
9162               switch (name[2])
9163               {
9164                 case 'd':
9165                   if (name[3] == 'i' &&
9166                       name[4] == 'r')
9167                   {                               /* chdir      */
9168                     return -KEY_chdir;
9169                   }
9170
9171                   goto unknown;
9172
9173                 case 'm':
9174                   if (name[3] == 'o' &&
9175                       name[4] == 'd')
9176                   {                               /* chmod      */
9177                     return -KEY_chmod;
9178                   }
9179
9180                   goto unknown;
9181
9182                 case 'o':
9183                   switch (name[3])
9184                   {
9185                     case 'm':
9186                       if (name[4] == 'p')
9187                       {                           /* chomp      */
9188                         return -KEY_chomp;
9189                       }
9190
9191                       goto unknown;
9192
9193                     case 'w':
9194                       if (name[4] == 'n')
9195                       {                           /* chown      */
9196                         return -KEY_chown;
9197                       }
9198
9199                       goto unknown;
9200
9201                     default:
9202                       goto unknown;
9203                   }
9204
9205                 default:
9206                   goto unknown;
9207               }
9208
9209             case 'l':
9210               if (name[2] == 'o' &&
9211                   name[3] == 's' &&
9212                   name[4] == 'e')
9213               {                                   /* close      */
9214                 return -KEY_close;
9215               }
9216
9217               goto unknown;
9218
9219             case 'r':
9220               if (name[2] == 'y' &&
9221                   name[3] == 'p' &&
9222                   name[4] == 't')
9223               {                                   /* crypt      */
9224                 return -KEY_crypt;
9225               }
9226
9227               goto unknown;
9228
9229             default:
9230               goto unknown;
9231           }
9232
9233         case 'e':
9234           if (name[1] == 'l' &&
9235               name[2] == 's' &&
9236               name[3] == 'i' &&
9237               name[4] == 'f')
9238           {                                       /* elsif      */
9239             return KEY_elsif;
9240           }
9241
9242           goto unknown;
9243
9244         case 'f':
9245           switch (name[1])
9246           {
9247             case 'c':
9248               if (name[2] == 'n' &&
9249                   name[3] == 't' &&
9250                   name[4] == 'l')
9251               {                                   /* fcntl      */
9252                 return -KEY_fcntl;
9253               }
9254
9255               goto unknown;
9256
9257             case 'l':
9258               if (name[2] == 'o' &&
9259                   name[3] == 'c' &&
9260                   name[4] == 'k')
9261               {                                   /* flock      */
9262                 return -KEY_flock;
9263               }
9264
9265               goto unknown;
9266
9267             default:
9268               goto unknown;
9269           }
9270
9271         case 'g':
9272           if (name[1] == 'i' &&
9273               name[2] == 'v' &&
9274               name[3] == 'e' &&
9275               name[4] == 'n')
9276           {                                       /* given      */
9277             return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
9278           }
9279
9280           goto unknown;
9281
9282         case 'i':
9283           switch (name[1])
9284           {
9285             case 'n':
9286               if (name[2] == 'd' &&
9287                   name[3] == 'e' &&
9288                   name[4] == 'x')
9289               {                                   /* index      */
9290                 return -KEY_index;
9291               }
9292
9293               goto unknown;
9294
9295             case 'o':
9296               if (name[2] == 'c' &&
9297                   name[3] == 't' &&
9298                   name[4] == 'l')
9299               {                                   /* ioctl      */
9300                 return -KEY_ioctl;
9301               }
9302
9303               goto unknown;
9304
9305             default:
9306               goto unknown;
9307           }
9308
9309         case 'l':
9310           switch (name[1])
9311           {
9312             case 'o':
9313               if (name[2] == 'c' &&
9314                   name[3] == 'a' &&
9315                   name[4] == 'l')
9316               {                                   /* local      */
9317                 return KEY_local;
9318               }
9319
9320               goto unknown;
9321
9322             case 's':
9323               if (name[2] == 't' &&
9324                   name[3] == 'a' &&
9325                   name[4] == 't')
9326               {                                   /* lstat      */
9327                 return -KEY_lstat;
9328               }
9329
9330               goto unknown;
9331
9332             default:
9333               goto unknown;
9334           }
9335
9336         case 'm':
9337           if (name[1] == 'k' &&
9338               name[2] == 'd' &&
9339               name[3] == 'i' &&
9340               name[4] == 'r')
9341           {                                       /* mkdir      */
9342             return -KEY_mkdir;
9343           }
9344
9345           goto unknown;
9346
9347         case 'p':
9348           if (name[1] == 'r' &&
9349               name[2] == 'i' &&
9350               name[3] == 'n' &&
9351               name[4] == 't')
9352           {                                       /* print      */
9353             return KEY_print;
9354           }
9355
9356           goto unknown;
9357
9358         case 'r':
9359           switch (name[1])
9360           {
9361             case 'e':
9362               if (name[2] == 's' &&
9363                   name[3] == 'e' &&
9364                   name[4] == 't')
9365               {                                   /* reset      */
9366                 return -KEY_reset;
9367               }
9368
9369               goto unknown;
9370
9371             case 'm':
9372               if (name[2] == 'd' &&
9373                   name[3] == 'i' &&
9374                   name[4] == 'r')
9375               {                                   /* rmdir      */
9376                 return -KEY_rmdir;
9377               }
9378
9379               goto unknown;
9380
9381             default:
9382               goto unknown;
9383           }
9384
9385         case 's':
9386           switch (name[1])
9387           {
9388             case 'e':
9389               if (name[2] == 'm' &&
9390                   name[3] == 'o' &&
9391                   name[4] == 'p')
9392               {                                   /* semop      */
9393                 return -KEY_semop;
9394               }
9395
9396               goto unknown;
9397
9398             case 'h':
9399               if (name[2] == 'i' &&
9400                   name[3] == 'f' &&
9401                   name[4] == 't')
9402               {                                   /* shift      */
9403                 return -KEY_shift;
9404               }
9405
9406               goto unknown;
9407
9408             case 'l':
9409               if (name[2] == 'e' &&
9410                   name[3] == 'e' &&
9411                   name[4] == 'p')
9412               {                                   /* sleep      */
9413                 return -KEY_sleep;
9414               }
9415
9416               goto unknown;
9417
9418             case 'p':
9419               if (name[2] == 'l' &&
9420                   name[3] == 'i' &&
9421                   name[4] == 't')
9422               {                                   /* split      */
9423                 return KEY_split;
9424               }
9425
9426               goto unknown;
9427
9428             case 'r':
9429               if (name[2] == 'a' &&
9430                   name[3] == 'n' &&
9431                   name[4] == 'd')
9432               {                                   /* srand      */
9433                 return -KEY_srand;
9434               }
9435
9436               goto unknown;
9437
9438             case 't':
9439               switch (name[2])
9440               {
9441                 case 'a':
9442                   if (name[3] == 't' &&
9443                       name[4] == 'e')
9444                   {                               /* state      */
9445                     return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
9446                   }
9447
9448                   goto unknown;
9449
9450                 case 'u':
9451                   if (name[3] == 'd' &&
9452                       name[4] == 'y')
9453                   {                               /* study      */
9454                     return KEY_study;
9455                   }
9456
9457                   goto unknown;
9458
9459                 default:
9460                   goto unknown;
9461               }
9462
9463             default:
9464               goto unknown;
9465           }
9466
9467         case 't':
9468           if (name[1] == 'i' &&
9469               name[2] == 'm' &&
9470               name[3] == 'e' &&
9471               name[4] == 's')
9472           {                                       /* times      */
9473             return -KEY_times;
9474           }
9475
9476           goto unknown;
9477
9478         case 'u':
9479           switch (name[1])
9480           {
9481             case 'm':
9482               if (name[2] == 'a' &&
9483                   name[3] == 's' &&
9484                   name[4] == 'k')
9485               {                                   /* umask      */
9486                 return -KEY_umask;
9487               }
9488
9489               goto unknown;
9490
9491             case 'n':
9492               switch (name[2])
9493               {
9494                 case 'd':
9495                   if (name[3] == 'e' &&
9496                       name[4] == 'f')
9497                   {                               /* undef      */
9498                     return KEY_undef;
9499                   }
9500
9501                   goto unknown;
9502
9503                 case 't':
9504                   if (name[3] == 'i')
9505                   {
9506                     switch (name[4])
9507                     {
9508                       case 'e':
9509                         {                         /* untie      */
9510                           return -KEY_untie;
9511                         }
9512
9513                       case 'l':
9514                         {                         /* until      */
9515                           return KEY_until;
9516                         }
9517
9518                       default:
9519                         goto unknown;
9520                     }
9521                   }
9522
9523                   goto unknown;
9524
9525                 default:
9526                   goto unknown;
9527               }
9528
9529             case 't':
9530               if (name[2] == 'i' &&
9531                   name[3] == 'm' &&
9532                   name[4] == 'e')
9533               {                                   /* utime      */
9534                 return -KEY_utime;
9535               }
9536
9537               goto unknown;
9538
9539             default:
9540               goto unknown;
9541           }
9542
9543         case 'w':
9544           switch (name[1])
9545           {
9546             case 'h':
9547               if (name[2] == 'i' &&
9548                   name[3] == 'l' &&
9549                   name[4] == 'e')
9550               {                                   /* while      */
9551                 return KEY_while;
9552               }
9553
9554               goto unknown;
9555
9556             case 'r':
9557               if (name[2] == 'i' &&
9558                   name[3] == 't' &&
9559                   name[4] == 'e')
9560               {                                   /* write      */
9561                 return -KEY_write;
9562               }
9563
9564               goto unknown;
9565
9566             default:
9567               goto unknown;
9568           }
9569
9570         default:
9571           goto unknown;
9572       }
9573
9574     case 6: /* 33 tokens of length 6 */
9575       switch (name[0])
9576       {
9577         case 'a':
9578           if (name[1] == 'c' &&
9579               name[2] == 'c' &&
9580               name[3] == 'e' &&
9581               name[4] == 'p' &&
9582               name[5] == 't')
9583           {                                       /* accept     */
9584             return -KEY_accept;
9585           }
9586
9587           goto unknown;
9588
9589         case 'c':
9590           switch (name[1])
9591           {
9592             case 'a':
9593               if (name[2] == 'l' &&
9594                   name[3] == 'l' &&
9595                   name[4] == 'e' &&
9596                   name[5] == 'r')
9597               {                                   /* caller     */
9598                 return -KEY_caller;
9599               }
9600
9601               goto unknown;
9602
9603             case 'h':
9604               if (name[2] == 'r' &&
9605                   name[3] == 'o' &&
9606                   name[4] == 'o' &&
9607                   name[5] == 't')
9608               {                                   /* chroot     */
9609                 return -KEY_chroot;
9610               }
9611
9612               goto unknown;
9613
9614             default:
9615               goto unknown;
9616           }
9617
9618         case 'd':
9619           if (name[1] == 'e' &&
9620               name[2] == 'l' &&
9621               name[3] == 'e' &&
9622               name[4] == 't' &&
9623               name[5] == 'e')
9624           {                                       /* delete     */
9625             return KEY_delete;
9626           }
9627
9628           goto unknown;
9629
9630         case 'e':
9631           switch (name[1])
9632           {
9633             case 'l':
9634               if (name[2] == 's' &&
9635                   name[3] == 'e' &&
9636                   name[4] == 'i' &&
9637                   name[5] == 'f')
9638               {                                   /* elseif     */
9639                   Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
9640               }
9641
9642               goto unknown;
9643
9644             case 'x':
9645               if (name[2] == 'i' &&
9646                   name[3] == 's' &&
9647                   name[4] == 't' &&
9648                   name[5] == 's')
9649               {                                   /* exists     */
9650                 return KEY_exists;
9651               }
9652
9653               goto unknown;
9654
9655             default:
9656               goto unknown;
9657           }
9658
9659         case 'f':
9660           switch (name[1])
9661           {
9662             case 'i':
9663               if (name[2] == 'l' &&
9664                   name[3] == 'e' &&
9665                   name[4] == 'n' &&
9666                   name[5] == 'o')
9667               {                                   /* fileno     */
9668                 return -KEY_fileno;
9669               }
9670
9671               goto unknown;
9672
9673             case 'o':
9674               if (name[2] == 'r' &&
9675                   name[3] == 'm' &&
9676                   name[4] == 'a' &&
9677                   name[5] == 't')
9678               {                                   /* format     */
9679                 return KEY_format;
9680               }
9681
9682               goto unknown;
9683
9684             default:
9685               goto unknown;
9686           }
9687
9688         case 'g':
9689           if (name[1] == 'm' &&
9690               name[2] == 't' &&
9691               name[3] == 'i' &&
9692               name[4] == 'm' &&
9693               name[5] == 'e')
9694           {                                       /* gmtime     */
9695             return -KEY_gmtime;
9696           }
9697
9698           goto unknown;
9699
9700         case 'l':
9701           switch (name[1])
9702           {
9703             case 'e':
9704               if (name[2] == 'n' &&
9705                   name[3] == 'g' &&
9706                   name[4] == 't' &&
9707                   name[5] == 'h')
9708               {                                   /* length     */
9709                 return -KEY_length;
9710               }
9711
9712               goto unknown;
9713
9714             case 'i':
9715               if (name[2] == 's' &&
9716                   name[3] == 't' &&
9717                   name[4] == 'e' &&
9718                   name[5] == 'n')
9719               {                                   /* listen     */
9720                 return -KEY_listen;
9721               }
9722
9723               goto unknown;
9724
9725             default:
9726               goto unknown;
9727           }
9728
9729         case 'm':
9730           if (name[1] == 's' &&
9731               name[2] == 'g')
9732           {
9733             switch (name[3])
9734             {
9735               case 'c':
9736                 if (name[4] == 't' &&
9737                     name[5] == 'l')
9738                 {                                 /* msgctl     */
9739                   return -KEY_msgctl;
9740                 }
9741
9742                 goto unknown;
9743
9744               case 'g':
9745                 if (name[4] == 'e' &&
9746                     name[5] == 't')
9747                 {                                 /* msgget     */
9748                   return -KEY_msgget;
9749                 }
9750
9751                 goto unknown;
9752
9753               case 'r':
9754                 if (name[4] == 'c' &&
9755                     name[5] == 'v')
9756                 {                                 /* msgrcv     */
9757                   return -KEY_msgrcv;
9758                 }
9759
9760                 goto unknown;
9761
9762               case 's':
9763                 if (name[4] == 'n' &&
9764                     name[5] == 'd')
9765                 {                                 /* msgsnd     */
9766                   return -KEY_msgsnd;
9767                 }
9768
9769                 goto unknown;
9770
9771               default:
9772                 goto unknown;
9773             }
9774           }
9775
9776           goto unknown;
9777
9778         case 'p':
9779           if (name[1] == 'r' &&
9780               name[2] == 'i' &&
9781               name[3] == 'n' &&
9782               name[4] == 't' &&
9783               name[5] == 'f')
9784           {                                       /* printf     */
9785             return KEY_printf;
9786           }
9787
9788           goto unknown;
9789
9790         case 'r':
9791           switch (name[1])
9792           {
9793             case 'e':
9794               switch (name[2])
9795               {
9796                 case 'n':
9797                   if (name[3] == 'a' &&
9798                       name[4] == 'm' &&
9799                       name[5] == 'e')
9800                   {                               /* rename     */
9801                     return -KEY_rename;
9802                   }
9803
9804                   goto unknown;
9805
9806                 case 't':
9807                   if (name[3] == 'u' &&
9808                       name[4] == 'r' &&
9809                       name[5] == 'n')
9810                   {                               /* return     */
9811                     return KEY_return;
9812                   }
9813
9814                   goto unknown;
9815
9816                 default:
9817                   goto unknown;
9818               }
9819
9820             case 'i':
9821               if (name[2] == 'n' &&
9822                   name[3] == 'd' &&
9823                   name[4] == 'e' &&
9824                   name[5] == 'x')
9825               {                                   /* rindex     */
9826                 return -KEY_rindex;
9827               }
9828
9829               goto unknown;
9830
9831             default:
9832               goto unknown;
9833           }
9834
9835         case 's':
9836           switch (name[1])
9837           {
9838             case 'c':
9839               if (name[2] == 'a' &&
9840                   name[3] == 'l' &&
9841                   name[4] == 'a' &&
9842                   name[5] == 'r')
9843               {                                   /* scalar     */
9844                 return KEY_scalar;
9845               }
9846
9847               goto unknown;
9848
9849             case 'e':
9850               switch (name[2])
9851               {
9852                 case 'l':
9853                   if (name[3] == 'e' &&
9854                       name[4] == 'c' &&
9855                       name[5] == 't')
9856                   {                               /* select     */
9857                     return -KEY_select;
9858                   }
9859
9860                   goto unknown;
9861
9862                 case 'm':
9863                   switch (name[3])
9864                   {
9865                     case 'c':
9866                       if (name[4] == 't' &&
9867                           name[5] == 'l')
9868                       {                           /* semctl     */
9869                         return -KEY_semctl;
9870                       }
9871
9872                       goto unknown;
9873
9874                     case 'g':
9875                       if (name[4] == 'e' &&
9876                           name[5] == 't')
9877                       {                           /* semget     */
9878                         return -KEY_semget;
9879                       }
9880
9881                       goto unknown;
9882
9883                     default:
9884                       goto unknown;
9885                   }
9886
9887                 default:
9888                   goto unknown;
9889               }
9890
9891             case 'h':
9892               if (name[2] == 'm')
9893               {
9894                 switch (name[3])
9895                 {
9896                   case 'c':
9897                     if (name[4] == 't' &&
9898                         name[5] == 'l')
9899                     {                             /* shmctl     */
9900                       return -KEY_shmctl;
9901                     }
9902
9903                     goto unknown;
9904
9905                   case 'g':
9906                     if (name[4] == 'e' &&
9907                         name[5] == 't')
9908                     {                             /* shmget     */
9909                       return -KEY_shmget;
9910                     }
9911
9912                     goto unknown;
9913
9914                   default:
9915                     goto unknown;
9916                 }
9917               }
9918
9919               goto unknown;
9920
9921             case 'o':
9922               if (name[2] == 'c' &&
9923                   name[3] == 'k' &&
9924                   name[4] == 'e' &&
9925                   name[5] == 't')
9926               {                                   /* socket     */
9927                 return -KEY_socket;
9928               }
9929
9930               goto unknown;
9931
9932             case 'p':
9933               if (name[2] == 'l' &&
9934                   name[3] == 'i' &&
9935                   name[4] == 'c' &&
9936                   name[5] == 'e')
9937               {                                   /* splice     */
9938                 return -KEY_splice;
9939               }
9940
9941               goto unknown;
9942
9943             case 'u':
9944               if (name[2] == 'b' &&
9945                   name[3] == 's' &&
9946                   name[4] == 't' &&
9947                   name[5] == 'r')
9948               {                                   /* substr     */
9949                 return -KEY_substr;
9950               }
9951
9952               goto unknown;
9953
9954             case 'y':
9955               if (name[2] == 's' &&
9956                   name[3] == 't' &&
9957                   name[4] == 'e' &&
9958                   name[5] == 'm')
9959               {                                   /* system     */
9960                 return -KEY_system;
9961               }
9962
9963               goto unknown;
9964
9965             default:
9966               goto unknown;
9967           }
9968
9969         case 'u':
9970           if (name[1] == 'n')
9971           {
9972             switch (name[2])
9973             {
9974               case 'l':
9975                 switch (name[3])
9976                 {
9977                   case 'e':
9978                     if (name[4] == 's' &&
9979                         name[5] == 's')
9980                     {                             /* unless     */
9981                       return KEY_unless;
9982                     }
9983
9984                     goto unknown;
9985
9986                   case 'i':
9987                     if (name[4] == 'n' &&
9988                         name[5] == 'k')
9989                     {                             /* unlink     */
9990                       return -KEY_unlink;
9991                     }
9992
9993                     goto unknown;
9994
9995                   default:
9996                     goto unknown;
9997                 }
9998
9999               case 'p':
10000                 if (name[3] == 'a' &&
10001                     name[4] == 'c' &&
10002                     name[5] == 'k')
10003                 {                                 /* unpack     */
10004                   return -KEY_unpack;
10005                 }
10006
10007                 goto unknown;
10008
10009               default:
10010                 goto unknown;
10011             }
10012           }
10013
10014           goto unknown;
10015
10016         case 'v':
10017           if (name[1] == 'a' &&
10018               name[2] == 'l' &&
10019               name[3] == 'u' &&
10020               name[4] == 'e' &&
10021               name[5] == 's')
10022           {                                       /* values     */
10023             return -KEY_values;
10024           }
10025
10026           goto unknown;
10027
10028         default:
10029           goto unknown;
10030       }
10031
10032     case 7: /* 29 tokens of length 7 */
10033       switch (name[0])
10034       {
10035         case 'D':
10036           if (name[1] == 'E' &&
10037               name[2] == 'S' &&
10038               name[3] == 'T' &&
10039               name[4] == 'R' &&
10040               name[5] == 'O' &&
10041               name[6] == 'Y')
10042           {                                       /* DESTROY    */
10043             return KEY_DESTROY;
10044           }
10045
10046           goto unknown;
10047
10048         case '_':
10049           if (name[1] == '_' &&
10050               name[2] == 'E' &&
10051               name[3] == 'N' &&
10052               name[4] == 'D' &&
10053               name[5] == '_' &&
10054               name[6] == '_')
10055           {                                       /* __END__    */
10056             return KEY___END__;
10057           }
10058
10059           goto unknown;
10060
10061         case 'b':
10062           if (name[1] == 'i' &&
10063               name[2] == 'n' &&
10064               name[3] == 'm' &&
10065               name[4] == 'o' &&
10066               name[5] == 'd' &&
10067               name[6] == 'e')
10068           {                                       /* binmode    */
10069             return -KEY_binmode;
10070           }
10071
10072           goto unknown;
10073
10074         case 'c':
10075           if (name[1] == 'o' &&
10076               name[2] == 'n' &&
10077               name[3] == 'n' &&
10078               name[4] == 'e' &&
10079               name[5] == 'c' &&
10080               name[6] == 't')
10081           {                                       /* connect    */
10082             return -KEY_connect;
10083           }
10084
10085           goto unknown;
10086
10087         case 'd':
10088           switch (name[1])
10089           {
10090             case 'b':
10091               if (name[2] == 'm' &&
10092                   name[3] == 'o' &&
10093                   name[4] == 'p' &&
10094                   name[5] == 'e' &&
10095                   name[6] == 'n')
10096               {                                   /* dbmopen    */
10097                 return -KEY_dbmopen;
10098               }
10099
10100               goto unknown;
10101
10102             case 'e':
10103               if (name[2] == 'f')
10104               {
10105                 switch (name[3])
10106                 {
10107                   case 'a':
10108                     if (name[4] == 'u' &&
10109                         name[5] == 'l' &&
10110                         name[6] == 't')
10111                     {                             /* default    */
10112                       return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
10113                     }
10114
10115                     goto unknown;
10116
10117                   case 'i':
10118                     if (name[4] == 'n' &&
10119                         name[5] == 'e' &&
10120                         name[6] == 'd')
10121                     {                             /* defined    */
10122                       return KEY_defined;
10123                     }
10124
10125                     goto unknown;
10126
10127                   default:
10128                     goto unknown;
10129                 }
10130               }
10131
10132               goto unknown;
10133
10134             default:
10135               goto unknown;
10136           }
10137
10138         case 'f':
10139           if (name[1] == 'o' &&
10140               name[2] == 'r' &&
10141               name[3] == 'e' &&
10142               name[4] == 'a' &&
10143               name[5] == 'c' &&
10144               name[6] == 'h')
10145           {                                       /* foreach    */
10146             return KEY_foreach;
10147           }
10148
10149           goto unknown;
10150
10151         case 'g':
10152           if (name[1] == 'e' &&
10153               name[2] == 't' &&
10154               name[3] == 'p')
10155           {
10156             switch (name[4])
10157             {
10158               case 'g':
10159                 if (name[5] == 'r' &&
10160                     name[6] == 'p')
10161                 {                                 /* getpgrp    */
10162                   return -KEY_getpgrp;
10163                 }
10164
10165                 goto unknown;
10166
10167               case 'p':
10168                 if (name[5] == 'i' &&
10169                     name[6] == 'd')
10170                 {                                 /* getppid    */
10171                   return -KEY_getppid;
10172                 }
10173
10174                 goto unknown;
10175
10176               default:
10177                 goto unknown;
10178             }
10179           }
10180
10181           goto unknown;
10182
10183         case 'l':
10184           if (name[1] == 'c' &&
10185               name[2] == 'f' &&
10186               name[3] == 'i' &&
10187               name[4] == 'r' &&
10188               name[5] == 's' &&
10189               name[6] == 't')
10190           {                                       /* lcfirst    */
10191             return -KEY_lcfirst;
10192           }
10193
10194           goto unknown;
10195
10196         case 'o':
10197           if (name[1] == 'p' &&
10198               name[2] == 'e' &&
10199               name[3] == 'n' &&
10200               name[4] == 'd' &&
10201               name[5] == 'i' &&
10202               name[6] == 'r')
10203           {                                       /* opendir    */
10204             return -KEY_opendir;
10205           }
10206
10207           goto unknown;
10208
10209         case 'p':
10210           if (name[1] == 'a' &&
10211               name[2] == 'c' &&
10212               name[3] == 'k' &&
10213               name[4] == 'a' &&
10214               name[5] == 'g' &&
10215               name[6] == 'e')
10216           {                                       /* package    */
10217             return KEY_package;
10218           }
10219
10220           goto unknown;
10221
10222         case 'r':
10223           if (name[1] == 'e')
10224           {
10225             switch (name[2])
10226             {
10227               case 'a':
10228                 if (name[3] == 'd' &&
10229                     name[4] == 'd' &&
10230                     name[5] == 'i' &&
10231                     name[6] == 'r')
10232                 {                                 /* readdir    */
10233                   return -KEY_readdir;
10234                 }
10235
10236                 goto unknown;
10237
10238               case 'q':
10239                 if (name[3] == 'u' &&
10240                     name[4] == 'i' &&
10241                     name[5] == 'r' &&
10242                     name[6] == 'e')
10243                 {                                 /* require    */
10244                   return KEY_require;
10245                 }
10246
10247                 goto unknown;
10248
10249               case 'v':
10250                 if (name[3] == 'e' &&
10251                     name[4] == 'r' &&
10252                     name[5] == 's' &&
10253                     name[6] == 'e')
10254                 {                                 /* reverse    */
10255                   return -KEY_reverse;
10256                 }
10257
10258                 goto unknown;
10259
10260               default:
10261                 goto unknown;
10262             }
10263           }
10264
10265           goto unknown;
10266
10267         case 's':
10268           switch (name[1])
10269           {
10270             case 'e':
10271               switch (name[2])
10272               {
10273                 case 'e':
10274                   if (name[3] == 'k' &&
10275                       name[4] == 'd' &&
10276                       name[5] == 'i' &&
10277                       name[6] == 'r')
10278                   {                               /* seekdir    */
10279                     return -KEY_seekdir;
10280                   }
10281
10282                   goto unknown;
10283
10284                 case 't':
10285                   if (name[3] == 'p' &&
10286                       name[4] == 'g' &&
10287                       name[5] == 'r' &&
10288                       name[6] == 'p')
10289                   {                               /* setpgrp    */
10290                     return -KEY_setpgrp;
10291                   }
10292
10293                   goto unknown;
10294
10295                 default:
10296                   goto unknown;
10297               }
10298
10299             case 'h':
10300               if (name[2] == 'm' &&
10301                   name[3] == 'r' &&
10302                   name[4] == 'e' &&
10303                   name[5] == 'a' &&
10304                   name[6] == 'd')
10305               {                                   /* shmread    */
10306                 return -KEY_shmread;
10307               }
10308
10309               goto unknown;
10310
10311             case 'p':
10312               if (name[2] == 'r' &&
10313                   name[3] == 'i' &&
10314                   name[4] == 'n' &&
10315                   name[5] == 't' &&
10316                   name[6] == 'f')
10317               {                                   /* sprintf    */
10318                 return -KEY_sprintf;
10319               }
10320
10321               goto unknown;
10322
10323             case 'y':
10324               switch (name[2])
10325               {
10326                 case 'm':
10327                   if (name[3] == 'l' &&
10328                       name[4] == 'i' &&
10329                       name[5] == 'n' &&
10330                       name[6] == 'k')
10331                   {                               /* symlink    */
10332                     return -KEY_symlink;
10333                   }
10334
10335                   goto unknown;
10336
10337                 case 's':
10338                   switch (name[3])
10339                   {
10340                     case 'c':
10341                       if (name[4] == 'a' &&
10342                           name[5] == 'l' &&
10343                           name[6] == 'l')
10344                       {                           /* syscall    */
10345                         return -KEY_syscall;
10346                       }
10347
10348                       goto unknown;
10349
10350                     case 'o':
10351                       if (name[4] == 'p' &&
10352                           name[5] == 'e' &&
10353                           name[6] == 'n')
10354                       {                           /* sysopen    */
10355                         return -KEY_sysopen;
10356                       }
10357
10358                       goto unknown;
10359
10360                     case 'r':
10361                       if (name[4] == 'e' &&
10362                           name[5] == 'a' &&
10363                           name[6] == 'd')
10364                       {                           /* sysread    */
10365                         return -KEY_sysread;
10366                       }
10367
10368                       goto unknown;
10369
10370                     case 's':
10371                       if (name[4] == 'e' &&
10372                           name[5] == 'e' &&
10373                           name[6] == 'k')
10374                       {                           /* sysseek    */
10375                         return -KEY_sysseek;
10376                       }
10377
10378                       goto unknown;
10379
10380                     default:
10381                       goto unknown;
10382                   }
10383
10384                 default:
10385                   goto unknown;
10386               }
10387
10388             default:
10389               goto unknown;
10390           }
10391
10392         case 't':
10393           if (name[1] == 'e' &&
10394               name[2] == 'l' &&
10395               name[3] == 'l' &&
10396               name[4] == 'd' &&
10397               name[5] == 'i' &&
10398               name[6] == 'r')
10399           {                                       /* telldir    */
10400             return -KEY_telldir;
10401           }
10402
10403           goto unknown;
10404
10405         case 'u':
10406           switch (name[1])
10407           {
10408             case 'c':
10409               if (name[2] == 'f' &&
10410                   name[3] == 'i' &&
10411                   name[4] == 'r' &&
10412                   name[5] == 's' &&
10413                   name[6] == 't')
10414               {                                   /* ucfirst    */
10415                 return -KEY_ucfirst;
10416               }
10417
10418               goto unknown;
10419
10420             case 'n':
10421               if (name[2] == 's' &&
10422                   name[3] == 'h' &&
10423                   name[4] == 'i' &&
10424                   name[5] == 'f' &&
10425                   name[6] == 't')
10426               {                                   /* unshift    */
10427                 return -KEY_unshift;
10428               }
10429
10430               goto unknown;
10431
10432             default:
10433               goto unknown;
10434           }
10435
10436         case 'w':
10437           if (name[1] == 'a' &&
10438               name[2] == 'i' &&
10439               name[3] == 't' &&
10440               name[4] == 'p' &&
10441               name[5] == 'i' &&
10442               name[6] == 'd')
10443           {                                       /* waitpid    */
10444             return -KEY_waitpid;
10445           }
10446
10447           goto unknown;
10448
10449         default:
10450           goto unknown;
10451       }
10452
10453     case 8: /* 26 tokens of length 8 */
10454       switch (name[0])
10455       {
10456         case 'A':
10457           if (name[1] == 'U' &&
10458               name[2] == 'T' &&
10459               name[3] == 'O' &&
10460               name[4] == 'L' &&
10461               name[5] == 'O' &&
10462               name[6] == 'A' &&
10463               name[7] == 'D')
10464           {                                       /* AUTOLOAD   */
10465             return KEY_AUTOLOAD;
10466           }
10467
10468           goto unknown;
10469
10470         case '_':
10471           if (name[1] == '_')
10472           {
10473             switch (name[2])
10474             {
10475               case 'D':
10476                 if (name[3] == 'A' &&
10477                     name[4] == 'T' &&
10478                     name[5] == 'A' &&
10479                     name[6] == '_' &&
10480                     name[7] == '_')
10481                 {                                 /* __DATA__   */
10482                   return KEY___DATA__;
10483                 }
10484
10485                 goto unknown;
10486
10487               case 'F':
10488                 if (name[3] == 'I' &&
10489                     name[4] == 'L' &&
10490                     name[5] == 'E' &&
10491                     name[6] == '_' &&
10492                     name[7] == '_')
10493                 {                                 /* __FILE__   */
10494                   return -KEY___FILE__;
10495                 }
10496
10497                 goto unknown;
10498
10499               case 'L':
10500                 if (name[3] == 'I' &&
10501                     name[4] == 'N' &&
10502                     name[5] == 'E' &&
10503                     name[6] == '_' &&
10504                     name[7] == '_')
10505                 {                                 /* __LINE__   */
10506                   return -KEY___LINE__;
10507                 }
10508
10509                 goto unknown;
10510
10511               default:
10512                 goto unknown;
10513             }
10514           }
10515
10516           goto unknown;
10517
10518         case 'c':
10519           switch (name[1])
10520           {
10521             case 'l':
10522               if (name[2] == 'o' &&
10523                   name[3] == 's' &&
10524                   name[4] == 'e' &&
10525                   name[5] == 'd' &&
10526                   name[6] == 'i' &&
10527                   name[7] == 'r')
10528               {                                   /* closedir   */
10529                 return -KEY_closedir;
10530               }
10531
10532               goto unknown;
10533
10534             case 'o':
10535               if (name[2] == 'n' &&
10536                   name[3] == 't' &&
10537                   name[4] == 'i' &&
10538                   name[5] == 'n' &&
10539                   name[6] == 'u' &&
10540                   name[7] == 'e')
10541               {                                   /* continue   */
10542                 return -KEY_continue;
10543               }
10544
10545               goto unknown;
10546
10547             default:
10548               goto unknown;
10549           }
10550
10551         case 'd':
10552           if (name[1] == 'b' &&
10553               name[2] == 'm' &&
10554               name[3] == 'c' &&
10555               name[4] == 'l' &&
10556               name[5] == 'o' &&
10557               name[6] == 's' &&
10558               name[7] == 'e')
10559           {                                       /* dbmclose   */
10560             return -KEY_dbmclose;
10561           }
10562
10563           goto unknown;
10564
10565         case 'e':
10566           if (name[1] == 'n' &&
10567               name[2] == 'd')
10568           {
10569             switch (name[3])
10570             {
10571               case 'g':
10572                 if (name[4] == 'r' &&
10573                     name[5] == 'e' &&
10574                     name[6] == 'n' &&
10575                     name[7] == 't')
10576                 {                                 /* endgrent   */
10577                   return -KEY_endgrent;
10578                 }
10579
10580                 goto unknown;
10581
10582               case 'p':
10583                 if (name[4] == 'w' &&
10584                     name[5] == 'e' &&
10585                     name[6] == 'n' &&
10586                     name[7] == 't')
10587                 {                                 /* endpwent   */
10588                   return -KEY_endpwent;
10589                 }
10590
10591                 goto unknown;
10592
10593               default:
10594                 goto unknown;
10595             }
10596           }
10597
10598           goto unknown;
10599
10600         case 'f':
10601           if (name[1] == 'o' &&
10602               name[2] == 'r' &&
10603               name[3] == 'm' &&
10604               name[4] == 'l' &&
10605               name[5] == 'i' &&
10606               name[6] == 'n' &&
10607               name[7] == 'e')
10608           {                                       /* formline   */
10609             return -KEY_formline;
10610           }
10611
10612           goto unknown;
10613
10614         case 'g':
10615           if (name[1] == 'e' &&
10616               name[2] == 't')
10617           {
10618             switch (name[3])
10619             {
10620               case 'g':
10621                 if (name[4] == 'r')
10622                 {
10623                   switch (name[5])
10624                   {
10625                     case 'e':
10626                       if (name[6] == 'n' &&
10627                           name[7] == 't')
10628                       {                           /* getgrent   */
10629                         return -KEY_getgrent;
10630                       }
10631
10632                       goto unknown;
10633
10634                     case 'g':
10635                       if (name[6] == 'i' &&
10636                           name[7] == 'd')
10637                       {                           /* getgrgid   */
10638                         return -KEY_getgrgid;
10639                       }
10640
10641                       goto unknown;
10642
10643                     case 'n':
10644                       if (name[6] == 'a' &&
10645                           name[7] == 'm')
10646                       {                           /* getgrnam   */
10647                         return -KEY_getgrnam;
10648                       }
10649
10650                       goto unknown;
10651
10652                     default:
10653                       goto unknown;
10654                   }
10655                 }
10656
10657                 goto unknown;
10658
10659               case 'l':
10660                 if (name[4] == 'o' &&
10661                     name[5] == 'g' &&
10662                     name[6] == 'i' &&
10663                     name[7] == 'n')
10664                 {                                 /* getlogin   */
10665                   return -KEY_getlogin;
10666                 }
10667
10668                 goto unknown;
10669
10670               case 'p':
10671                 if (name[4] == 'w')
10672                 {
10673                   switch (name[5])
10674                   {
10675                     case 'e':
10676                       if (name[6] == 'n' &&
10677                           name[7] == 't')
10678                       {                           /* getpwent   */
10679                         return -KEY_getpwent;
10680                       }
10681
10682                       goto unknown;
10683
10684                     case 'n':
10685                       if (name[6] == 'a' &&
10686                           name[7] == 'm')
10687                       {                           /* getpwnam   */
10688                         return -KEY_getpwnam;
10689                       }
10690
10691                       goto unknown;
10692
10693                     case 'u':
10694                       if (name[6] == 'i' &&
10695                           name[7] == 'd')
10696                       {                           /* getpwuid   */
10697                         return -KEY_getpwuid;
10698                       }
10699
10700                       goto unknown;
10701
10702                     default:
10703                       goto unknown;
10704                   }
10705                 }
10706
10707                 goto unknown;
10708
10709               default:
10710                 goto unknown;
10711             }
10712           }
10713
10714           goto unknown;
10715
10716         case 'r':
10717           if (name[1] == 'e' &&
10718               name[2] == 'a' &&
10719               name[3] == 'd')
10720           {
10721             switch (name[4])
10722             {
10723               case 'l':
10724                 if (name[5] == 'i' &&
10725                     name[6] == 'n')
10726                 {
10727                   switch (name[7])
10728                   {
10729                     case 'e':
10730                       {                           /* readline   */
10731                         return -KEY_readline;
10732                       }
10733
10734                     case 'k':
10735                       {                           /* readlink   */
10736                         return -KEY_readlink;
10737                       }
10738
10739                     default:
10740                       goto unknown;
10741                   }
10742                 }
10743
10744                 goto unknown;
10745
10746               case 'p':
10747                 if (name[5] == 'i' &&
10748                     name[6] == 'p' &&
10749                     name[7] == 'e')
10750                 {                                 /* readpipe   */
10751                   return -KEY_readpipe;
10752                 }
10753
10754                 goto unknown;
10755
10756               default:
10757                 goto unknown;
10758             }
10759           }
10760
10761           goto unknown;
10762
10763         case 's':
10764           switch (name[1])
10765           {
10766             case 'e':
10767               if (name[2] == 't')
10768               {
10769                 switch (name[3])
10770                 {
10771                   case 'g':
10772                     if (name[4] == 'r' &&
10773                         name[5] == 'e' &&
10774                         name[6] == 'n' &&
10775                         name[7] == 't')
10776                     {                             /* setgrent   */
10777                       return -KEY_setgrent;
10778                     }
10779
10780                     goto unknown;
10781
10782                   case 'p':
10783                     if (name[4] == 'w' &&
10784                         name[5] == 'e' &&
10785                         name[6] == 'n' &&
10786                         name[7] == 't')
10787                     {                             /* setpwent   */
10788                       return -KEY_setpwent;
10789                     }
10790
10791                     goto unknown;
10792
10793                   default:
10794                     goto unknown;
10795                 }
10796               }
10797
10798               goto unknown;
10799
10800             case 'h':
10801               switch (name[2])
10802               {
10803                 case 'm':
10804                   if (name[3] == 'w' &&
10805                       name[4] == 'r' &&
10806                       name[5] == 'i' &&
10807                       name[6] == 't' &&
10808                       name[7] == 'e')
10809                   {                               /* shmwrite   */
10810                     return -KEY_shmwrite;
10811                   }
10812
10813                   goto unknown;
10814
10815                 case 'u':
10816                   if (name[3] == 't' &&
10817                       name[4] == 'd' &&
10818                       name[5] == 'o' &&
10819                       name[6] == 'w' &&
10820                       name[7] == 'n')
10821                   {                               /* shutdown   */
10822                     return -KEY_shutdown;
10823                   }
10824
10825                   goto unknown;
10826
10827                 default:
10828                   goto unknown;
10829               }
10830
10831             case 'y':
10832               if (name[2] == 's' &&
10833                   name[3] == 'w' &&
10834                   name[4] == 'r' &&
10835                   name[5] == 'i' &&
10836                   name[6] == 't' &&
10837                   name[7] == 'e')
10838               {                                   /* syswrite   */
10839                 return -KEY_syswrite;
10840               }
10841
10842               goto unknown;
10843
10844             default:
10845               goto unknown;
10846           }
10847
10848         case 't':
10849           if (name[1] == 'r' &&
10850               name[2] == 'u' &&
10851               name[3] == 'n' &&
10852               name[4] == 'c' &&
10853               name[5] == 'a' &&
10854               name[6] == 't' &&
10855               name[7] == 'e')
10856           {                                       /* truncate   */
10857             return -KEY_truncate;
10858           }
10859
10860           goto unknown;
10861
10862         default:
10863           goto unknown;
10864       }
10865
10866     case 9: /* 9 tokens of length 9 */
10867       switch (name[0])
10868       {
10869         case 'U':
10870           if (name[1] == 'N' &&
10871               name[2] == 'I' &&
10872               name[3] == 'T' &&
10873               name[4] == 'C' &&
10874               name[5] == 'H' &&
10875               name[6] == 'E' &&
10876               name[7] == 'C' &&
10877               name[8] == 'K')
10878           {                                       /* UNITCHECK  */
10879             return KEY_UNITCHECK;
10880           }
10881
10882           goto unknown;
10883
10884         case 'e':
10885           if (name[1] == 'n' &&
10886               name[2] == 'd' &&
10887               name[3] == 'n' &&
10888               name[4] == 'e' &&
10889               name[5] == 't' &&
10890               name[6] == 'e' &&
10891               name[7] == 'n' &&
10892               name[8] == 't')
10893           {                                       /* endnetent  */
10894             return -KEY_endnetent;
10895           }
10896
10897           goto unknown;
10898
10899         case 'g':
10900           if (name[1] == 'e' &&
10901               name[2] == 't' &&
10902               name[3] == 'n' &&
10903               name[4] == 'e' &&
10904               name[5] == 't' &&
10905               name[6] == 'e' &&
10906               name[7] == 'n' &&
10907               name[8] == 't')
10908           {                                       /* getnetent  */
10909             return -KEY_getnetent;
10910           }
10911
10912           goto unknown;
10913
10914         case 'l':
10915           if (name[1] == 'o' &&
10916               name[2] == 'c' &&
10917               name[3] == 'a' &&
10918               name[4] == 'l' &&
10919               name[5] == 't' &&
10920               name[6] == 'i' &&
10921               name[7] == 'm' &&
10922               name[8] == 'e')
10923           {                                       /* localtime  */
10924             return -KEY_localtime;
10925           }
10926
10927           goto unknown;
10928
10929         case 'p':
10930           if (name[1] == 'r' &&
10931               name[2] == 'o' &&
10932               name[3] == 't' &&
10933               name[4] == 'o' &&
10934               name[5] == 't' &&
10935               name[6] == 'y' &&
10936               name[7] == 'p' &&
10937               name[8] == 'e')
10938           {                                       /* prototype  */
10939             return KEY_prototype;
10940           }
10941
10942           goto unknown;
10943
10944         case 'q':
10945           if (name[1] == 'u' &&
10946               name[2] == 'o' &&
10947               name[3] == 't' &&
10948               name[4] == 'e' &&
10949               name[5] == 'm' &&
10950               name[6] == 'e' &&
10951               name[7] == 't' &&
10952               name[8] == 'a')
10953           {                                       /* quotemeta  */
10954             return -KEY_quotemeta;
10955           }
10956
10957           goto unknown;
10958
10959         case 'r':
10960           if (name[1] == 'e' &&
10961               name[2] == 'w' &&
10962               name[3] == 'i' &&
10963               name[4] == 'n' &&
10964               name[5] == 'd' &&
10965               name[6] == 'd' &&
10966               name[7] == 'i' &&
10967               name[8] == 'r')
10968           {                                       /* rewinddir  */
10969             return -KEY_rewinddir;
10970           }
10971
10972           goto unknown;
10973
10974         case 's':
10975           if (name[1] == 'e' &&
10976               name[2] == 't' &&
10977               name[3] == 'n' &&
10978               name[4] == 'e' &&
10979               name[5] == 't' &&
10980               name[6] == 'e' &&
10981               name[7] == 'n' &&
10982               name[8] == 't')
10983           {                                       /* setnetent  */
10984             return -KEY_setnetent;
10985           }
10986
10987           goto unknown;
10988
10989         case 'w':
10990           if (name[1] == 'a' &&
10991               name[2] == 'n' &&
10992               name[3] == 't' &&
10993               name[4] == 'a' &&
10994               name[5] == 'r' &&
10995               name[6] == 'r' &&
10996               name[7] == 'a' &&
10997               name[8] == 'y')
10998           {                                       /* wantarray  */
10999             return -KEY_wantarray;
11000           }
11001
11002           goto unknown;
11003
11004         default:
11005           goto unknown;
11006       }
11007
11008     case 10: /* 9 tokens of length 10 */
11009       switch (name[0])
11010       {
11011         case 'e':
11012           if (name[1] == 'n' &&
11013               name[2] == 'd')
11014           {
11015             switch (name[3])
11016             {
11017               case 'h':
11018                 if (name[4] == 'o' &&
11019                     name[5] == 's' &&
11020                     name[6] == 't' &&
11021                     name[7] == 'e' &&
11022                     name[8] == 'n' &&
11023                     name[9] == 't')
11024                 {                                 /* endhostent */
11025                   return -KEY_endhostent;
11026                 }
11027
11028                 goto unknown;
11029
11030               case 's':
11031                 if (name[4] == 'e' &&
11032                     name[5] == 'r' &&
11033                     name[6] == 'v' &&
11034                     name[7] == 'e' &&
11035                     name[8] == 'n' &&
11036                     name[9] == 't')
11037                 {                                 /* endservent */
11038                   return -KEY_endservent;
11039                 }
11040
11041                 goto unknown;
11042
11043               default:
11044                 goto unknown;
11045             }
11046           }
11047
11048           goto unknown;
11049
11050         case 'g':
11051           if (name[1] == 'e' &&
11052               name[2] == 't')
11053           {
11054             switch (name[3])
11055             {
11056               case 'h':
11057                 if (name[4] == 'o' &&
11058                     name[5] == 's' &&
11059                     name[6] == 't' &&
11060                     name[7] == 'e' &&
11061                     name[8] == 'n' &&
11062                     name[9] == 't')
11063                 {                                 /* gethostent */
11064                   return -KEY_gethostent;
11065                 }
11066
11067                 goto unknown;
11068
11069               case 's':
11070                 switch (name[4])
11071                 {
11072                   case 'e':
11073                     if (name[5] == 'r' &&
11074                         name[6] == 'v' &&
11075                         name[7] == 'e' &&
11076                         name[8] == 'n' &&
11077                         name[9] == 't')
11078                     {                             /* getservent */
11079                       return -KEY_getservent;
11080                     }
11081
11082                     goto unknown;
11083
11084                   case 'o':
11085                     if (name[5] == 'c' &&
11086                         name[6] == 'k' &&
11087                         name[7] == 'o' &&
11088                         name[8] == 'p' &&
11089                         name[9] == 't')
11090                     {                             /* getsockopt */
11091                       return -KEY_getsockopt;
11092                     }
11093
11094                     goto unknown;
11095
11096                   default:
11097                     goto unknown;
11098                 }
11099
11100               default:
11101                 goto unknown;
11102             }
11103           }
11104
11105           goto unknown;
11106
11107         case 's':
11108           switch (name[1])
11109           {
11110             case 'e':
11111               if (name[2] == 't')
11112               {
11113                 switch (name[3])
11114                 {
11115                   case 'h':
11116                     if (name[4] == 'o' &&
11117                         name[5] == 's' &&
11118                         name[6] == 't' &&
11119                         name[7] == 'e' &&
11120                         name[8] == 'n' &&
11121                         name[9] == 't')
11122                     {                             /* sethostent */
11123                       return -KEY_sethostent;
11124                     }
11125
11126                     goto unknown;
11127
11128                   case 's':
11129                     switch (name[4])
11130                     {
11131                       case 'e':
11132                         if (name[5] == 'r' &&
11133                             name[6] == 'v' &&
11134                             name[7] == 'e' &&
11135                             name[8] == 'n' &&
11136                             name[9] == 't')
11137                         {                         /* setservent */
11138                           return -KEY_setservent;
11139                         }
11140
11141                         goto unknown;
11142
11143                       case 'o':
11144                         if (name[5] == 'c' &&
11145                             name[6] == 'k' &&
11146                             name[7] == 'o' &&
11147                             name[8] == 'p' &&
11148                             name[9] == 't')
11149                         {                         /* setsockopt */
11150                           return -KEY_setsockopt;
11151                         }
11152
11153                         goto unknown;
11154
11155                       default:
11156                         goto unknown;
11157                     }
11158
11159                   default:
11160                     goto unknown;
11161                 }
11162               }
11163
11164               goto unknown;
11165
11166             case 'o':
11167               if (name[2] == 'c' &&
11168                   name[3] == 'k' &&
11169                   name[4] == 'e' &&
11170                   name[5] == 't' &&
11171                   name[6] == 'p' &&
11172                   name[7] == 'a' &&
11173                   name[8] == 'i' &&
11174                   name[9] == 'r')
11175               {                                   /* socketpair */
11176                 return -KEY_socketpair;
11177               }
11178
11179               goto unknown;
11180
11181             default:
11182               goto unknown;
11183           }
11184
11185         default:
11186           goto unknown;
11187       }
11188
11189     case 11: /* 8 tokens of length 11 */
11190       switch (name[0])
11191       {
11192         case '_':
11193           if (name[1] == '_' &&
11194               name[2] == 'P' &&
11195               name[3] == 'A' &&
11196               name[4] == 'C' &&
11197               name[5] == 'K' &&
11198               name[6] == 'A' &&
11199               name[7] == 'G' &&
11200               name[8] == 'E' &&
11201               name[9] == '_' &&
11202               name[10] == '_')
11203           {                                       /* __PACKAGE__ */
11204             return -KEY___PACKAGE__;
11205           }
11206
11207           goto unknown;
11208
11209         case 'e':
11210           if (name[1] == 'n' &&
11211               name[2] == 'd' &&
11212               name[3] == 'p' &&
11213               name[4] == 'r' &&
11214               name[5] == 'o' &&
11215               name[6] == 't' &&
11216               name[7] == 'o' &&
11217               name[8] == 'e' &&
11218               name[9] == 'n' &&
11219               name[10] == 't')
11220           {                                       /* endprotoent */
11221             return -KEY_endprotoent;
11222           }
11223
11224           goto unknown;
11225
11226         case 'g':
11227           if (name[1] == 'e' &&
11228               name[2] == 't')
11229           {
11230             switch (name[3])
11231             {
11232               case 'p':
11233                 switch (name[4])
11234                 {
11235                   case 'e':
11236                     if (name[5] == 'e' &&
11237                         name[6] == 'r' &&
11238                         name[7] == 'n' &&
11239                         name[8] == 'a' &&
11240                         name[9] == 'm' &&
11241                         name[10] == 'e')
11242                     {                             /* getpeername */
11243                       return -KEY_getpeername;
11244                     }
11245
11246                     goto unknown;
11247
11248                   case 'r':
11249                     switch (name[5])
11250                     {
11251                       case 'i':
11252                         if (name[6] == 'o' &&
11253                             name[7] == 'r' &&
11254                             name[8] == 'i' &&
11255                             name[9] == 't' &&
11256                             name[10] == 'y')
11257                         {                         /* getpriority */
11258                           return -KEY_getpriority;
11259                         }
11260
11261                         goto unknown;
11262
11263                       case 'o':
11264                         if (name[6] == 't' &&
11265                             name[7] == 'o' &&
11266                             name[8] == 'e' &&
11267                             name[9] == 'n' &&
11268                             name[10] == 't')
11269                         {                         /* getprotoent */
11270                           return -KEY_getprotoent;
11271                         }
11272
11273                         goto unknown;
11274
11275                       default:
11276                         goto unknown;
11277                     }
11278
11279                   default:
11280                     goto unknown;
11281                 }
11282
11283               case 's':
11284                 if (name[4] == 'o' &&
11285                     name[5] == 'c' &&
11286                     name[6] == 'k' &&
11287                     name[7] == 'n' &&
11288                     name[8] == 'a' &&
11289                     name[9] == 'm' &&
11290                     name[10] == 'e')
11291                 {                                 /* getsockname */
11292                   return -KEY_getsockname;
11293                 }
11294
11295                 goto unknown;
11296
11297               default:
11298                 goto unknown;
11299             }
11300           }
11301
11302           goto unknown;
11303
11304         case 's':
11305           if (name[1] == 'e' &&
11306               name[2] == 't' &&
11307               name[3] == 'p' &&
11308               name[4] == 'r')
11309           {
11310             switch (name[5])
11311             {
11312               case 'i':
11313                 if (name[6] == 'o' &&
11314                     name[7] == 'r' &&
11315                     name[8] == 'i' &&
11316                     name[9] == 't' &&
11317                     name[10] == 'y')
11318                 {                                 /* setpriority */
11319                   return -KEY_setpriority;
11320                 }
11321
11322                 goto unknown;
11323
11324               case 'o':
11325                 if (name[6] == 't' &&
11326                     name[7] == 'o' &&
11327                     name[8] == 'e' &&
11328                     name[9] == 'n' &&
11329                     name[10] == 't')
11330                 {                                 /* setprotoent */
11331                   return -KEY_setprotoent;
11332                 }
11333
11334                 goto unknown;
11335
11336               default:
11337                 goto unknown;
11338             }
11339           }
11340
11341           goto unknown;
11342
11343         default:
11344           goto unknown;
11345       }
11346
11347     case 12: /* 2 tokens of length 12 */
11348       if (name[0] == 'g' &&
11349           name[1] == 'e' &&
11350           name[2] == 't' &&
11351           name[3] == 'n' &&
11352           name[4] == 'e' &&
11353           name[5] == 't' &&
11354           name[6] == 'b' &&
11355           name[7] == 'y')
11356       {
11357         switch (name[8])
11358         {
11359           case 'a':
11360             if (name[9] == 'd' &&
11361                 name[10] == 'd' &&
11362                 name[11] == 'r')
11363             {                                     /* getnetbyaddr */
11364               return -KEY_getnetbyaddr;
11365             }
11366
11367             goto unknown;
11368
11369           case 'n':
11370             if (name[9] == 'a' &&
11371                 name[10] == 'm' &&
11372                 name[11] == 'e')
11373             {                                     /* getnetbyname */
11374               return -KEY_getnetbyname;
11375             }
11376
11377             goto unknown;
11378
11379           default:
11380             goto unknown;
11381         }
11382       }
11383
11384       goto unknown;
11385
11386     case 13: /* 4 tokens of length 13 */
11387       if (name[0] == 'g' &&
11388           name[1] == 'e' &&
11389           name[2] == 't')
11390       {
11391         switch (name[3])
11392         {
11393           case 'h':
11394             if (name[4] == 'o' &&
11395                 name[5] == 's' &&
11396                 name[6] == 't' &&
11397                 name[7] == 'b' &&
11398                 name[8] == 'y')
11399             {
11400               switch (name[9])
11401               {
11402                 case 'a':
11403                   if (name[10] == 'd' &&
11404                       name[11] == 'd' &&
11405                       name[12] == 'r')
11406                   {                               /* gethostbyaddr */
11407                     return -KEY_gethostbyaddr;
11408                   }
11409
11410                   goto unknown;
11411
11412                 case 'n':
11413                   if (name[10] == 'a' &&
11414                       name[11] == 'm' &&
11415                       name[12] == 'e')
11416                   {                               /* gethostbyname */
11417                     return -KEY_gethostbyname;
11418                   }
11419
11420                   goto unknown;
11421
11422                 default:
11423                   goto unknown;
11424               }
11425             }
11426
11427             goto unknown;
11428
11429           case 's':
11430             if (name[4] == 'e' &&
11431                 name[5] == 'r' &&
11432                 name[6] == 'v' &&
11433                 name[7] == 'b' &&
11434                 name[8] == 'y')
11435             {
11436               switch (name[9])
11437               {
11438                 case 'n':
11439                   if (name[10] == 'a' &&
11440                       name[11] == 'm' &&
11441                       name[12] == 'e')
11442                   {                               /* getservbyname */
11443                     return -KEY_getservbyname;
11444                   }
11445
11446                   goto unknown;
11447
11448                 case 'p':
11449                   if (name[10] == 'o' &&
11450                       name[11] == 'r' &&
11451                       name[12] == 't')
11452                   {                               /* getservbyport */
11453                     return -KEY_getservbyport;
11454                   }
11455
11456                   goto unknown;
11457
11458                 default:
11459                   goto unknown;
11460               }
11461             }
11462
11463             goto unknown;
11464
11465           default:
11466             goto unknown;
11467         }
11468       }
11469
11470       goto unknown;
11471
11472     case 14: /* 1 tokens of length 14 */
11473       if (name[0] == 'g' &&
11474           name[1] == 'e' &&
11475           name[2] == 't' &&
11476           name[3] == 'p' &&
11477           name[4] == 'r' &&
11478           name[5] == 'o' &&
11479           name[6] == 't' &&
11480           name[7] == 'o' &&
11481           name[8] == 'b' &&
11482           name[9] == 'y' &&
11483           name[10] == 'n' &&
11484           name[11] == 'a' &&
11485           name[12] == 'm' &&
11486           name[13] == 'e')
11487       {                                           /* getprotobyname */
11488         return -KEY_getprotobyname;
11489       }
11490
11491       goto unknown;
11492
11493     case 16: /* 1 tokens of length 16 */
11494       if (name[0] == 'g' &&
11495           name[1] == 'e' &&
11496           name[2] == 't' &&
11497           name[3] == 'p' &&
11498           name[4] == 'r' &&
11499           name[5] == 'o' &&
11500           name[6] == 't' &&
11501           name[7] == 'o' &&
11502           name[8] == 'b' &&
11503           name[9] == 'y' &&
11504           name[10] == 'n' &&
11505           name[11] == 'u' &&
11506           name[12] == 'm' &&
11507           name[13] == 'b' &&
11508           name[14] == 'e' &&
11509           name[15] == 'r')
11510       {                                           /* getprotobynumber */
11511         return -KEY_getprotobynumber;
11512       }
11513
11514       goto unknown;
11515
11516     default:
11517       goto unknown;
11518   }
11519
11520 unknown:
11521   return 0;
11522 }
11523
11524 STATIC void
11525 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
11526 {
11527     dVAR;
11528
11529     PERL_ARGS_ASSERT_CHECKCOMMA;
11530
11531     if (*s == ' ' && s[1] == '(') {     /* XXX gotta be a better way */
11532         if (ckWARN(WARN_SYNTAX)) {
11533             int level = 1;
11534             const char *w;
11535             for (w = s+2; *w && level; w++) {
11536                 if (*w == '(')
11537                     ++level;
11538                 else if (*w == ')')
11539                     --level;
11540             }
11541             while (isSPACE(*w))
11542                 ++w;
11543             /* the list of chars below is for end of statements or
11544              * block / parens, boolean operators (&&, ||, //) and branch
11545              * constructs (or, and, if, until, unless, while, err, for).
11546              * Not a very solid hack... */
11547             if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
11548                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11549                             "%s (...) interpreted as function",name);
11550         }
11551     }
11552     while (s < PL_bufend && isSPACE(*s))
11553         s++;
11554     if (*s == '(')
11555         s++;
11556     while (s < PL_bufend && isSPACE(*s))
11557         s++;
11558     if (isIDFIRST_lazy_if(s,UTF)) {
11559         const char * const w = s++;
11560         while (isALNUM_lazy_if(s,UTF))
11561             s++;
11562         while (s < PL_bufend && isSPACE(*s))
11563             s++;
11564         if (*s == ',') {
11565             GV* gv;
11566             if (keyword(w, s - w, 0))
11567                 return;
11568
11569             gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
11570             if (gv && GvCVu(gv))
11571                 return;
11572             Perl_croak(aTHX_ "No comma allowed after %s", what);
11573         }
11574     }
11575 }
11576
11577 /* Either returns sv, or mortalizes sv and returns a new SV*.
11578    Best used as sv=new_constant(..., sv, ...).
11579    If s, pv are NULL, calls subroutine with one argument,
11580    and type is used with error messages only. */
11581
11582 STATIC SV *
11583 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen,
11584                SV *sv, SV *pv, const char *type, STRLEN typelen)
11585 {
11586     dVAR; dSP;
11587     HV * const table = GvHV(PL_hintgv);          /* ^H */
11588     SV *res;
11589     SV **cvp;
11590     SV *cv, *typesv;
11591     const char *why1 = "", *why2 = "", *why3 = "";
11592
11593     PERL_ARGS_ASSERT_NEW_CONSTANT;
11594
11595     if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
11596         SV *msg;
11597         
11598         why2 = (const char *)
11599             (strEQ(key,"charnames")
11600              ? "(possibly a missing \"use charnames ...\")"
11601              : "");
11602         msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
11603                             (type ? type: "undef"), why2);
11604
11605         /* This is convoluted and evil ("goto considered harmful")
11606          * but I do not understand the intricacies of all the different
11607          * failure modes of %^H in here.  The goal here is to make
11608          * the most probable error message user-friendly. --jhi */
11609
11610         goto msgdone;
11611
11612     report:
11613         msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
11614                             (type ? type: "undef"), why1, why2, why3);
11615     msgdone:
11616         yyerror(SvPVX_const(msg));
11617         SvREFCNT_dec(msg);
11618         return sv;
11619     }
11620
11621     /* charnames doesn't work well if there have been errors found */
11622     if (PL_error_count > 0 && strEQ(key,"charnames"))
11623         return &PL_sv_undef;
11624
11625     cvp = hv_fetch(table, key, keylen, FALSE);
11626     if (!cvp || !SvOK(*cvp)) {
11627         why1 = "$^H{";
11628         why2 = key;
11629         why3 = "} is not defined";
11630         goto report;
11631     }
11632     sv_2mortal(sv);                     /* Parent created it permanently */
11633     cv = *cvp;
11634     if (!pv && s)
11635         pv = newSVpvn_flags(s, len, SVs_TEMP);
11636     if (type && pv)
11637         typesv = newSVpvn_flags(type, typelen, SVs_TEMP);
11638     else
11639         typesv = &PL_sv_undef;
11640
11641     PUSHSTACKi(PERLSI_OVERLOAD);
11642     ENTER ;
11643     SAVETMPS;
11644
11645     PUSHMARK(SP) ;
11646     EXTEND(sp, 3);
11647     if (pv)
11648         PUSHs(pv);
11649     PUSHs(sv);
11650     if (pv)
11651         PUSHs(typesv);
11652     PUTBACK;
11653     call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
11654
11655     SPAGAIN ;
11656
11657     /* Check the eval first */
11658     if (!PL_in_eval && SvTRUE(ERRSV)) {
11659         sv_catpvs(ERRSV, "Propagated");
11660         yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
11661         (void)POPs;
11662         res = SvREFCNT_inc_simple(sv);
11663     }
11664     else {
11665         res = POPs;
11666         SvREFCNT_inc_simple_void(res);
11667     }
11668
11669     PUTBACK ;
11670     FREETMPS ;
11671     LEAVE ;
11672     POPSTACK;
11673
11674     if (!SvOK(res)) {
11675         why1 = "Call to &{$^H{";
11676         why2 = key;
11677         why3 = "}} did not return a defined value";
11678         sv = res;
11679         goto report;
11680     }
11681
11682     return res;
11683 }
11684
11685 /* Returns a NUL terminated string, with the length of the string written to
11686    *slp
11687    */
11688 STATIC char *
11689 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
11690 {
11691     dVAR;
11692     register char *d = dest;
11693     register char * const e = d + destlen - 3;  /* two-character token, ending NUL */
11694
11695     PERL_ARGS_ASSERT_SCAN_WORD;
11696
11697     for (;;) {
11698         if (d >= e)
11699             Perl_croak(aTHX_ ident_too_long);
11700         if (isALNUM(*s))        /* UTF handled below */
11701             *d++ = *s++;
11702         else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
11703             *d++ = ':';
11704             *d++ = ':';
11705             s++;
11706         }
11707         else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
11708             *d++ = *s++;
11709             *d++ = *s++;
11710         }
11711         else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
11712             char *t = s + UTF8SKIP(s);
11713             size_t len;
11714             while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
11715                 t += UTF8SKIP(t);
11716             len = t - s;
11717             if (d + len > e)
11718                 Perl_croak(aTHX_ ident_too_long);
11719             Copy(s, d, len, char);
11720             d += len;
11721             s = t;
11722         }
11723         else {
11724             *d = '\0';
11725             *slp = d - dest;
11726             return s;
11727         }
11728     }
11729 }
11730
11731 STATIC char *
11732 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
11733 {
11734     dVAR;
11735     char *bracket = NULL;
11736     char funny = *s++;
11737     register char *d = dest;
11738     register char * const e = d + destlen - 3;    /* two-character token, ending NUL */
11739
11740     PERL_ARGS_ASSERT_SCAN_IDENT;
11741
11742     if (isSPACE(*s))
11743         s = PEEKSPACE(s);
11744     if (isDIGIT(*s)) {
11745         while (isDIGIT(*s)) {
11746             if (d >= e)
11747                 Perl_croak(aTHX_ ident_too_long);
11748             *d++ = *s++;
11749         }
11750     }
11751     else {
11752         for (;;) {
11753             if (d >= e)
11754                 Perl_croak(aTHX_ ident_too_long);
11755             if (isALNUM(*s))    /* UTF handled below */
11756                 *d++ = *s++;
11757             else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
11758                 *d++ = ':';
11759                 *d++ = ':';
11760                 s++;
11761             }
11762             else if (*s == ':' && s[1] == ':') {
11763                 *d++ = *s++;
11764                 *d++ = *s++;
11765             }
11766             else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
11767                 char *t = s + UTF8SKIP(s);
11768                 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
11769                     t += UTF8SKIP(t);
11770                 if (d + (t - s) > e)
11771                     Perl_croak(aTHX_ ident_too_long);
11772                 Copy(s, d, t - s, char);
11773                 d += t - s;
11774                 s = t;
11775             }
11776             else
11777                 break;
11778         }
11779     }
11780     *d = '\0';
11781     d = dest;
11782     if (*d) {
11783         if (PL_lex_state != LEX_NORMAL)
11784             PL_lex_state = LEX_INTERPENDMAYBE;
11785         return s;
11786     }
11787     if (*s == '$' && s[1] &&
11788         (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
11789     {
11790         return s;
11791     }
11792     if (*s == '{') {
11793         bracket = s;
11794         s++;
11795     }
11796     else if (ck_uni)
11797         check_uni();
11798     if (s < send)
11799         *d = *s++;
11800     d[1] = '\0';
11801     if (*d == '^' && *s && isCONTROLVAR(*s)) {
11802         *d = toCTRL(*s);
11803         s++;
11804     }
11805     if (bracket) {
11806         if (isSPACE(s[-1])) {
11807             while (s < send) {
11808                 const char ch = *s++;
11809                 if (!SPACE_OR_TAB(ch)) {
11810                     *d = ch;
11811                     break;
11812                 }
11813             }
11814         }
11815         if (isIDFIRST_lazy_if(d,UTF)) {
11816             d++;
11817             if (UTF) {
11818                 char *end = s;
11819                 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
11820                     end += UTF8SKIP(end);
11821                     while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
11822                         end += UTF8SKIP(end);
11823                 }
11824                 Copy(s, d, end - s, char);
11825                 d += end - s;
11826                 s = end;
11827             }
11828             else {
11829                 while ((isALNUM(*s) || *s == ':') && d < e)
11830                     *d++ = *s++;
11831                 if (d >= e)
11832                     Perl_croak(aTHX_ ident_too_long);
11833             }
11834             *d = '\0';
11835             while (s < send && SPACE_OR_TAB(*s))
11836                 s++;
11837             if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
11838                 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
11839                     const char * const brack =
11840                         (const char *)
11841                         ((*s == '[') ? "[...]" : "{...}");
11842                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
11843                         "Ambiguous use of %c{%s%s} resolved to %c%s%s",
11844                         funny, dest, brack, funny, dest, brack);
11845                 }
11846                 bracket++;
11847                 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
11848                 return s;
11849             }
11850         }
11851         /* Handle extended ${^Foo} variables
11852          * 1999-02-27 mjd-perl-patch@plover.com */
11853         else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
11854                  && isALNUM(*s))
11855         {
11856             d++;
11857             while (isALNUM(*s) && d < e) {
11858                 *d++ = *s++;
11859             }
11860             if (d >= e)
11861                 Perl_croak(aTHX_ ident_too_long);
11862             *d = '\0';
11863         }
11864         if (*s == '}') {
11865             s++;
11866             if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
11867                 PL_lex_state = LEX_INTERPEND;
11868                 PL_expect = XREF;
11869             }
11870             if (PL_lex_state == LEX_NORMAL) {
11871                 if (ckWARN(WARN_AMBIGUOUS) &&
11872                     (keyword(dest, d - dest, 0)
11873                      || get_cvn_flags(dest, d - dest, 0)))
11874                 {
11875                     if (funny == '#')
11876                         funny = '@';
11877                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
11878                         "Ambiguous use of %c{%s} resolved to %c%s",
11879                         funny, dest, funny, dest);
11880                 }
11881             }
11882         }
11883         else {
11884             s = bracket;                /* let the parser handle it */
11885             *dest = '\0';
11886         }
11887     }
11888     else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
11889         PL_lex_state = LEX_INTERPEND;
11890     return s;
11891 }
11892
11893 static U32
11894 S_pmflag(U32 pmfl, const char ch) {
11895     switch (ch) {
11896         CASE_STD_PMMOD_FLAGS_PARSE_SET(&pmfl);
11897     case GLOBAL_PAT_MOD:      pmfl |= PMf_GLOBAL; break;
11898     case CONTINUE_PAT_MOD:    pmfl |= PMf_CONTINUE; break;
11899     case ONCE_PAT_MOD:        pmfl |= PMf_KEEP; break;
11900     case KEEPCOPY_PAT_MOD:    pmfl |= PMf_KEEPCOPY; break;
11901     case NONDESTRUCT_PAT_MOD: pmfl |= PMf_NONDESTRUCT; break;
11902     }
11903     return pmfl;
11904 }
11905
11906 STATIC char *
11907 S_scan_pat(pTHX_ char *start, I32 type)
11908 {
11909     dVAR;
11910     PMOP *pm;
11911     char *s = scan_str(start,!!PL_madskills,FALSE);
11912     const char * const valid_flags =
11913         (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
11914 #ifdef PERL_MAD
11915     char *modstart;
11916 #endif
11917
11918     PERL_ARGS_ASSERT_SCAN_PAT;
11919
11920     if (!s) {
11921         const char * const delimiter = skipspace(start);
11922         Perl_croak(aTHX_
11923                    (const char *)
11924                    (*delimiter == '?'
11925                     ? "Search pattern not terminated or ternary operator parsed as search pattern"
11926                     : "Search pattern not terminated" ));
11927     }
11928
11929     pm = (PMOP*)newPMOP(type, 0);
11930     if (PL_multi_open == '?') {
11931         /* This is the only point in the code that sets PMf_ONCE:  */
11932         pm->op_pmflags |= PMf_ONCE;
11933
11934         /* Hence it's safe to do this bit of PMOP book-keeping here, which
11935            allows us to restrict the list needed by reset to just the ??
11936            matches.  */
11937         assert(type != OP_TRANS);
11938         if (PL_curstash) {
11939             MAGIC *mg = mg_find((const SV *)PL_curstash, PERL_MAGIC_symtab);
11940             U32 elements;
11941             if (!mg) {
11942                 mg = sv_magicext(MUTABLE_SV(PL_curstash), 0, PERL_MAGIC_symtab, 0, 0,
11943                                  0);
11944             }
11945             elements = mg->mg_len / sizeof(PMOP**);
11946             Renewc(mg->mg_ptr, elements + 1, PMOP*, char);
11947             ((PMOP**)mg->mg_ptr) [elements++] = pm;
11948             mg->mg_len = elements * sizeof(PMOP**);
11949             PmopSTASH_set(pm,PL_curstash);
11950         }
11951     }
11952 #ifdef PERL_MAD
11953     modstart = s;
11954 #endif
11955     while (*s && strchr(valid_flags, *s))
11956         pm->op_pmflags = S_pmflag(pm->op_pmflags, *s++);
11957
11958     if (isALNUM(*s)) {
11959         Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX),
11960             "Having no space between pattern and following word is deprecated");
11961
11962     }
11963 #ifdef PERL_MAD
11964     if (PL_madskills && modstart != s) {
11965         SV* tmptoken = newSVpvn(modstart, s - modstart);
11966         append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
11967     }
11968 #endif
11969     /* issue a warning if /c is specified,but /g is not */
11970     if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
11971     {
11972         Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), 
11973                        "Use of /c modifier is meaningless without /g" );
11974     }
11975
11976     PL_lex_op = (OP*)pm;
11977     pl_yylval.ival = OP_MATCH;
11978     return s;
11979 }
11980
11981 STATIC char *
11982 S_scan_subst(pTHX_ char *start)
11983 {
11984     dVAR;
11985     register char *s;
11986     register PMOP *pm;
11987     I32 first_start;
11988     I32 es = 0;
11989 #ifdef PERL_MAD
11990     char *modstart;
11991 #endif
11992
11993     PERL_ARGS_ASSERT_SCAN_SUBST;
11994
11995     pl_yylval.ival = OP_NULL;
11996
11997     s = scan_str(start,!!PL_madskills,FALSE);
11998
11999     if (!s)
12000         Perl_croak(aTHX_ "Substitution pattern not terminated");
12001
12002     if (s[-1] == PL_multi_open)
12003         s--;
12004 #ifdef PERL_MAD
12005     if (PL_madskills) {
12006         CURMAD('q', PL_thisopen);
12007         CURMAD('_', PL_thiswhite);
12008         CURMAD('E', PL_thisstuff);
12009         CURMAD('Q', PL_thisclose);
12010         PL_realtokenstart = s - SvPVX(PL_linestr);
12011     }
12012 #endif
12013
12014     first_start = PL_multi_start;
12015     s = scan_str(s,!!PL_madskills,FALSE);
12016     if (!s) {
12017         if (PL_lex_stuff) {
12018             SvREFCNT_dec(PL_lex_stuff);
12019             PL_lex_stuff = NULL;
12020         }
12021         Perl_croak(aTHX_ "Substitution replacement not terminated");
12022     }
12023     PL_multi_start = first_start;       /* so whole substitution is taken together */
12024
12025     pm = (PMOP*)newPMOP(OP_SUBST, 0);
12026
12027 #ifdef PERL_MAD
12028     if (PL_madskills) {
12029         CURMAD('z', PL_thisopen);
12030         CURMAD('R', PL_thisstuff);
12031         CURMAD('Z', PL_thisclose);
12032     }
12033     modstart = s;
12034 #endif
12035
12036     while (*s) {
12037         if (*s == EXEC_PAT_MOD) {
12038             s++;
12039             es++;
12040         }
12041         else if (strchr(S_PAT_MODS, *s))
12042             pm->op_pmflags = S_pmflag(pm->op_pmflags, *s++);
12043         else {
12044             if (isALNUM(*s)) {
12045                 Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX),
12046                     "Having no space between pattern and following word is deprecated");
12047
12048             }
12049             break;
12050         }
12051     }
12052
12053 #ifdef PERL_MAD
12054     if (PL_madskills) {
12055         if (modstart != s)
12056             curmad('m', newSVpvn(modstart, s - modstart));
12057         append_madprops(PL_thismad, (OP*)pm, 0);
12058         PL_thismad = 0;
12059     }
12060 #endif
12061     if ((pm->op_pmflags & PMf_CONTINUE)) {
12062         Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
12063     }
12064
12065     if (es) {
12066         SV * const repl = newSVpvs("");
12067
12068         PL_sublex_info.super_bufptr = s;
12069         PL_sublex_info.super_bufend = PL_bufend;
12070         PL_multi_end = 0;
12071         pm->op_pmflags |= PMf_EVAL;
12072         while (es-- > 0) {
12073             if (es)
12074                 sv_catpvs(repl, "eval ");
12075             else
12076                 sv_catpvs(repl, "do ");
12077         }
12078         sv_catpvs(repl, "{");
12079         sv_catsv(repl, PL_lex_repl);
12080         if (strchr(SvPVX(PL_lex_repl), '#'))
12081             sv_catpvs(repl, "\n");
12082         sv_catpvs(repl, "}");
12083         SvEVALED_on(repl);
12084         SvREFCNT_dec(PL_lex_repl);
12085         PL_lex_repl = repl;
12086     }
12087
12088     PL_lex_op = (OP*)pm;
12089     pl_yylval.ival = OP_SUBST;
12090     return s;
12091 }
12092
12093 STATIC char *
12094 S_scan_trans(pTHX_ char *start)
12095 {
12096     dVAR;
12097     register char* s;
12098     OP *o;
12099     short *tbl;
12100     U8 squash;
12101     U8 del;
12102     U8 complement;
12103 #ifdef PERL_MAD
12104     char *modstart;
12105 #endif
12106
12107     PERL_ARGS_ASSERT_SCAN_TRANS;
12108
12109     pl_yylval.ival = OP_NULL;
12110
12111     s = scan_str(start,!!PL_madskills,FALSE);
12112     if (!s)
12113         Perl_croak(aTHX_ "Transliteration pattern not terminated");
12114
12115     if (s[-1] == PL_multi_open)
12116         s--;
12117 #ifdef PERL_MAD
12118     if (PL_madskills) {
12119         CURMAD('q', PL_thisopen);
12120         CURMAD('_', PL_thiswhite);
12121         CURMAD('E', PL_thisstuff);
12122         CURMAD('Q', PL_thisclose);
12123         PL_realtokenstart = s - SvPVX(PL_linestr);
12124     }
12125 #endif
12126
12127     s = scan_str(s,!!PL_madskills,FALSE);
12128     if (!s) {
12129         if (PL_lex_stuff) {
12130             SvREFCNT_dec(PL_lex_stuff);
12131             PL_lex_stuff = NULL;
12132         }
12133         Perl_croak(aTHX_ "Transliteration replacement not terminated");
12134     }
12135     if (PL_madskills) {
12136         CURMAD('z', PL_thisopen);
12137         CURMAD('R', PL_thisstuff);
12138         CURMAD('Z', PL_thisclose);
12139     }
12140
12141     complement = del = squash = 0;
12142 #ifdef PERL_MAD
12143     modstart = s;
12144 #endif
12145     while (1) {
12146         switch (*s) {
12147         case 'c':
12148             complement = OPpTRANS_COMPLEMENT;
12149             break;
12150         case 'd':
12151             del = OPpTRANS_DELETE;
12152             break;
12153         case 's':
12154             squash = OPpTRANS_SQUASH;
12155             break;
12156         default:
12157             goto no_more;
12158         }
12159         s++;
12160     }
12161   no_more:
12162
12163     tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
12164     o = newPVOP(OP_TRANS, 0, (char*)tbl);
12165     o->op_private &= ~OPpTRANS_ALL;
12166     o->op_private |= del|squash|complement|
12167       (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
12168       (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF   : 0);
12169
12170     PL_lex_op = o;
12171     pl_yylval.ival = OP_TRANS;
12172
12173 #ifdef PERL_MAD
12174     if (PL_madskills) {
12175         if (modstart != s)
12176             curmad('m', newSVpvn(modstart, s - modstart));
12177         append_madprops(PL_thismad, o, 0);
12178         PL_thismad = 0;
12179     }
12180 #endif
12181
12182     return s;
12183 }
12184
12185 STATIC char *
12186 S_scan_heredoc(pTHX_ register char *s)
12187 {
12188     dVAR;
12189     SV *herewas;
12190     I32 op_type = OP_SCALAR;
12191     I32 len;
12192     SV *tmpstr;
12193     char term;
12194     const char *found_newline;
12195     register char *d;
12196     register char *e;
12197     char *peek;
12198     const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
12199 #ifdef PERL_MAD
12200     I32 stuffstart = s - SvPVX(PL_linestr);
12201     char *tstart;
12202  
12203     PL_realtokenstart = -1;
12204 #endif
12205
12206     PERL_ARGS_ASSERT_SCAN_HEREDOC;
12207
12208     s += 2;
12209     d = PL_tokenbuf;
12210     e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
12211     if (!outer)
12212         *d++ = '\n';
12213     peek = s;
12214     while (SPACE_OR_TAB(*peek))
12215         peek++;
12216     if (*peek == '`' || *peek == '\'' || *peek =='"') {
12217         s = peek;
12218         term = *s++;
12219         s = delimcpy(d, e, s, PL_bufend, term, &len);
12220         d += len;
12221         if (s < PL_bufend)
12222             s++;
12223     }
12224     else {
12225         if (*s == '\\')
12226             s++, term = '\'';
12227         else
12228             term = '"';
12229         if (!isALNUM_lazy_if(s,UTF))
12230             deprecate("bare << to mean <<\"\"");
12231         for (; isALNUM_lazy_if(s,UTF); s++) {
12232             if (d < e)
12233                 *d++ = *s;
12234         }
12235     }
12236     if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
12237         Perl_croak(aTHX_ "Delimiter for here document is too long");
12238     *d++ = '\n';
12239     *d = '\0';
12240     len = d - PL_tokenbuf;
12241
12242 #ifdef PERL_MAD
12243     if (PL_madskills) {
12244         tstart = PL_tokenbuf + !outer;
12245         PL_thisclose = newSVpvn(tstart, len - !outer);
12246         tstart = SvPVX(PL_linestr) + stuffstart;
12247         PL_thisopen = newSVpvn(tstart, s - tstart);
12248         stuffstart = s - SvPVX(PL_linestr);
12249     }
12250 #endif
12251 #ifndef PERL_STRICT_CR
12252     d = strchr(s, '\r');
12253     if (d) {
12254         char * const olds = s;
12255         s = d;
12256         while (s < PL_bufend) {
12257             if (*s == '\r') {
12258                 *d++ = '\n';
12259                 if (*++s == '\n')
12260                     s++;
12261             }
12262             else if (*s == '\n' && s[1] == '\r') {      /* \015\013 on a mac? */
12263                 *d++ = *s++;
12264                 s++;
12265             }
12266             else
12267                 *d++ = *s++;
12268         }
12269         *d = '\0';
12270         PL_bufend = d;
12271         SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
12272         s = olds;
12273     }
12274 #endif
12275 #ifdef PERL_MAD
12276     found_newline = 0;
12277 #endif
12278     if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
12279         herewas = newSVpvn(s,PL_bufend-s);
12280     }
12281     else {
12282 #ifdef PERL_MAD
12283         herewas = newSVpvn(s-1,found_newline-s+1);
12284 #else
12285         s--;
12286         herewas = newSVpvn(s,found_newline-s);
12287 #endif
12288     }
12289 #ifdef PERL_MAD
12290     if (PL_madskills) {
12291         tstart = SvPVX(PL_linestr) + stuffstart;
12292         if (PL_thisstuff)
12293             sv_catpvn(PL_thisstuff, tstart, s - tstart);
12294         else
12295             PL_thisstuff = newSVpvn(tstart, s - tstart);
12296     }
12297 #endif
12298     s += SvCUR(herewas);
12299
12300 #ifdef PERL_MAD
12301     stuffstart = s - SvPVX(PL_linestr);
12302
12303     if (found_newline)
12304         s--;
12305 #endif
12306
12307     tmpstr = newSV_type(SVt_PVIV);
12308     SvGROW(tmpstr, 80);
12309     if (term == '\'') {
12310         op_type = OP_CONST;
12311         SvIV_set(tmpstr, -1);
12312     }
12313     else if (term == '`') {
12314         op_type = OP_BACKTICK;
12315         SvIV_set(tmpstr, '\\');
12316     }
12317
12318     CLINE;
12319     PL_multi_start = CopLINE(PL_curcop);
12320     PL_multi_open = PL_multi_close = '<';
12321     term = *PL_tokenbuf;
12322     if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
12323         char * const bufptr = PL_sublex_info.super_bufptr;
12324         char * const bufend = PL_sublex_info.super_bufend;
12325         char * const olds = s - SvCUR(herewas);
12326         s = strchr(bufptr, '\n');
12327         if (!s)
12328             s = bufend;
12329         d = s;
12330         while (s < bufend &&
12331           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
12332             if (*s++ == '\n')
12333                 CopLINE_inc(PL_curcop);
12334         }
12335         if (s >= bufend) {
12336             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
12337             missingterm(PL_tokenbuf);
12338         }
12339         sv_setpvn(herewas,bufptr,d-bufptr+1);
12340         sv_setpvn(tmpstr,d+1,s-d);
12341         s += len - 1;
12342         sv_catpvn(herewas,s,bufend-s);
12343         Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
12344
12345         s = olds;
12346         goto retval;
12347     }
12348     else if (!outer) {
12349         d = s;
12350         while (s < PL_bufend &&
12351           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
12352             if (*s++ == '\n')
12353                 CopLINE_inc(PL_curcop);
12354         }
12355         if (s >= PL_bufend) {
12356             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
12357             missingterm(PL_tokenbuf);
12358         }
12359         sv_setpvn(tmpstr,d+1,s-d);
12360 #ifdef PERL_MAD
12361         if (PL_madskills) {
12362             if (PL_thisstuff)
12363                 sv_catpvn(PL_thisstuff, d + 1, s - d);
12364             else
12365                 PL_thisstuff = newSVpvn(d + 1, s - d);
12366             stuffstart = s - SvPVX(PL_linestr);
12367         }
12368 #endif
12369         s += len - 1;
12370         CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
12371
12372         sv_catpvn(herewas,s,PL_bufend-s);
12373         sv_setsv(PL_linestr,herewas);
12374         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
12375         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12376         PL_last_lop = PL_last_uni = NULL;
12377     }
12378     else
12379         sv_setpvs(tmpstr,"");   /* avoid "uninitialized" warning */
12380     while (s >= PL_bufend) {    /* multiple line string? */
12381 #ifdef PERL_MAD
12382         if (PL_madskills) {
12383             tstart = SvPVX(PL_linestr) + stuffstart;
12384             if (PL_thisstuff)
12385                 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
12386             else
12387                 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
12388         }
12389 #endif
12390         PL_bufptr = s;
12391         CopLINE_inc(PL_curcop);
12392         if (!outer || !lex_next_chunk(0)) {
12393             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
12394             missingterm(PL_tokenbuf);
12395         }
12396         CopLINE_dec(PL_curcop);
12397         s = PL_bufptr;
12398 #ifdef PERL_MAD
12399         stuffstart = s - SvPVX(PL_linestr);
12400 #endif
12401         CopLINE_inc(PL_curcop);
12402         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12403         PL_last_lop = PL_last_uni = NULL;
12404 #ifndef PERL_STRICT_CR
12405         if (PL_bufend - PL_linestart >= 2) {
12406             if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
12407                 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
12408             {
12409                 PL_bufend[-2] = '\n';
12410                 PL_bufend--;
12411                 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
12412             }
12413             else if (PL_bufend[-1] == '\r')
12414                 PL_bufend[-1] = '\n';
12415         }
12416         else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
12417             PL_bufend[-1] = '\n';
12418 #endif
12419         if (*s == term && memEQ(s,PL_tokenbuf,len)) {
12420             STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
12421             *(SvPVX(PL_linestr) + off ) = ' ';
12422             sv_catsv(PL_linestr,herewas);
12423             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12424             s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
12425         }
12426         else {
12427             s = PL_bufend;
12428             sv_catsv(tmpstr,PL_linestr);
12429         }
12430     }
12431     s++;
12432 retval:
12433     PL_multi_end = CopLINE(PL_curcop);
12434     if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
12435         SvPV_shrink_to_cur(tmpstr);
12436     }
12437     SvREFCNT_dec(herewas);
12438     if (!IN_BYTES) {
12439         if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
12440             SvUTF8_on(tmpstr);
12441         else if (PL_encoding)
12442             sv_recode_to_utf8(tmpstr, PL_encoding);
12443     }
12444     PL_lex_stuff = tmpstr;
12445     pl_yylval.ival = op_type;
12446     return s;
12447 }
12448
12449 /* scan_inputsymbol
12450    takes: current position in input buffer
12451    returns: new position in input buffer
12452    side-effects: pl_yylval and lex_op are set.
12453
12454    This code handles:
12455
12456    <>           read from ARGV
12457    <FH>         read from filehandle
12458    <pkg::FH>    read from package qualified filehandle
12459    <pkg'FH>     read from package qualified filehandle
12460    <$fh>        read from filehandle in $fh
12461    <*.h>        filename glob
12462
12463 */
12464
12465 STATIC char *
12466 S_scan_inputsymbol(pTHX_ char *start)
12467 {
12468     dVAR;
12469     register char *s = start;           /* current position in buffer */
12470     char *end;
12471     I32 len;
12472     char *d = PL_tokenbuf;                                      /* start of temp holding space */
12473     const char * const e = PL_tokenbuf + sizeof PL_tokenbuf;    /* end of temp holding space */
12474
12475     PERL_ARGS_ASSERT_SCAN_INPUTSYMBOL;
12476
12477     end = strchr(s, '\n');
12478     if (!end)
12479         end = PL_bufend;
12480     s = delimcpy(d, e, s + 1, end, '>', &len);  /* extract until > */
12481
12482     /* die if we didn't have space for the contents of the <>,
12483        or if it didn't end, or if we see a newline
12484     */
12485
12486     if (len >= (I32)sizeof PL_tokenbuf)
12487         Perl_croak(aTHX_ "Excessively long <> operator");
12488     if (s >= end)
12489         Perl_croak(aTHX_ "Unterminated <> operator");
12490
12491     s++;
12492
12493     /* check for <$fh>
12494        Remember, only scalar variables are interpreted as filehandles by
12495        this code.  Anything more complex (e.g., <$fh{$num}>) will be
12496        treated as a glob() call.
12497        This code makes use of the fact that except for the $ at the front,
12498        a scalar variable and a filehandle look the same.
12499     */
12500     if (*d == '$' && d[1]) d++;
12501
12502     /* allow <Pkg'VALUE> or <Pkg::VALUE> */
12503     while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
12504         d++;
12505
12506     /* If we've tried to read what we allow filehandles to look like, and
12507        there's still text left, then it must be a glob() and not a getline.
12508        Use scan_str to pull out the stuff between the <> and treat it
12509        as nothing more than a string.
12510     */
12511
12512     if (d - PL_tokenbuf != len) {
12513         pl_yylval.ival = OP_GLOB;
12514         s = scan_str(start,!!PL_madskills,FALSE);
12515         if (!s)
12516            Perl_croak(aTHX_ "Glob not terminated");
12517         return s;
12518     }
12519     else {
12520         bool readline_overriden = FALSE;
12521         GV *gv_readline;
12522         GV **gvp;
12523         /* we're in a filehandle read situation */
12524         d = PL_tokenbuf;
12525
12526         /* turn <> into <ARGV> */
12527         if (!len)
12528             Copy("ARGV",d,5,char);
12529
12530         /* Check whether readline() is overriden */
12531         gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
12532         if ((gv_readline
12533                 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
12534                 ||
12535                 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
12536                  && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
12537                 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
12538             readline_overriden = TRUE;
12539
12540         /* if <$fh>, create the ops to turn the variable into a
12541            filehandle
12542         */
12543         if (*d == '$') {
12544             /* try to find it in the pad for this block, otherwise find
12545                add symbol table ops
12546             */
12547             const PADOFFSET tmp = pad_findmy(d, len, 0);
12548             if (tmp != NOT_IN_PAD) {
12549                 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
12550                     HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
12551                     HEK * const stashname = HvNAME_HEK(stash);
12552                     SV * const sym = sv_2mortal(newSVhek(stashname));
12553                     sv_catpvs(sym, "::");
12554                     sv_catpv(sym, d+1);
12555                     d = SvPVX(sym);
12556                     goto intro_sym;
12557                 }
12558                 else {
12559                     OP * const o = newOP(OP_PADSV, 0);
12560                     o->op_targ = tmp;
12561                     PL_lex_op = readline_overriden
12562                         ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
12563                                 op_append_elem(OP_LIST, o,
12564                                     newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
12565                         : (OP*)newUNOP(OP_READLINE, 0, o);
12566                 }
12567             }
12568             else {
12569                 GV *gv;
12570                 ++d;
12571 intro_sym:
12572                 gv = gv_fetchpv(d,
12573                                 (PL_in_eval
12574                                  ? (GV_ADDMULTI | GV_ADDINEVAL)
12575                                  : GV_ADDMULTI),
12576                                 SVt_PV);
12577                 PL_lex_op = readline_overriden
12578                     ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
12579                             op_append_elem(OP_LIST,
12580                                 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
12581                                 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
12582                     : (OP*)newUNOP(OP_READLINE, 0,
12583                             newUNOP(OP_RV2SV, 0,
12584                                 newGVOP(OP_GV, 0, gv)));
12585             }
12586             if (!readline_overriden)
12587                 PL_lex_op->op_flags |= OPf_SPECIAL;
12588             /* we created the ops in PL_lex_op, so make pl_yylval.ival a null op */
12589             pl_yylval.ival = OP_NULL;
12590         }
12591
12592         /* If it's none of the above, it must be a literal filehandle
12593            (<Foo::BAR> or <FOO>) so build a simple readline OP */
12594         else {
12595             GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
12596             PL_lex_op = readline_overriden
12597                 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
12598                         op_append_elem(OP_LIST,
12599                             newGVOP(OP_GV, 0, gv),
12600                             newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
12601                 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
12602             pl_yylval.ival = OP_NULL;
12603         }
12604     }
12605
12606     return s;
12607 }
12608
12609
12610 /* scan_str
12611    takes: start position in buffer
12612           keep_quoted preserve \ on the embedded delimiter(s)
12613           keep_delims preserve the delimiters around the string
12614    returns: position to continue reading from buffer
12615    side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
12616         updates the read buffer.
12617
12618    This subroutine pulls a string out of the input.  It is called for:
12619         q               single quotes           q(literal text)
12620         '               single quotes           'literal text'
12621         qq              double quotes           qq(interpolate $here please)
12622         "               double quotes           "interpolate $here please"
12623         qx              backticks               qx(/bin/ls -l)
12624         `               backticks               `/bin/ls -l`
12625         qw              quote words             @EXPORT_OK = qw( func() $spam )
12626         m//             regexp match            m/this/
12627         s///            regexp substitute       s/this/that/
12628         tr///           string transliterate    tr/this/that/
12629         y///            string transliterate    y/this/that/
12630         ($*@)           sub prototypes          sub foo ($)
12631         (stuff)         sub attr parameters     sub foo : attr(stuff)
12632         <>              readline or globs       <FOO>, <>, <$fh>, or <*.c>
12633         
12634    In most of these cases (all but <>, patterns and transliterate)
12635    yylex() calls scan_str().  m// makes yylex() call scan_pat() which
12636    calls scan_str().  s/// makes yylex() call scan_subst() which calls
12637    scan_str().  tr/// and y/// make yylex() call scan_trans() which
12638    calls scan_str().
12639
12640    It skips whitespace before the string starts, and treats the first
12641    character as the delimiter.  If the delimiter is one of ([{< then
12642    the corresponding "close" character )]}> is used as the closing
12643    delimiter.  It allows quoting of delimiters, and if the string has
12644    balanced delimiters ([{<>}]) it allows nesting.
12645
12646    On success, the SV with the resulting string is put into lex_stuff or,
12647    if that is already non-NULL, into lex_repl. The second case occurs only
12648    when parsing the RHS of the special constructs s/// and tr/// (y///).
12649    For convenience, the terminating delimiter character is stuffed into
12650    SvIVX of the SV.
12651 */
12652
12653 STATIC char *
12654 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
12655 {
12656     dVAR;
12657     SV *sv;                             /* scalar value: string */
12658     const char *tmps;                   /* temp string, used for delimiter matching */
12659     register char *s = start;           /* current position in the buffer */
12660     register char term;                 /* terminating character */
12661     register char *to;                  /* current position in the sv's data */
12662     I32 brackets = 1;                   /* bracket nesting level */
12663     bool has_utf8 = FALSE;              /* is there any utf8 content? */
12664     I32 termcode;                       /* terminating char. code */
12665     U8 termstr[UTF8_MAXBYTES];          /* terminating string */
12666     STRLEN termlen;                     /* length of terminating string */
12667     int last_off = 0;                   /* last position for nesting bracket */
12668 #ifdef PERL_MAD
12669     int stuffstart;
12670     char *tstart;
12671 #endif
12672
12673     PERL_ARGS_ASSERT_SCAN_STR;
12674
12675     /* skip space before the delimiter */
12676     if (isSPACE(*s)) {
12677         s = PEEKSPACE(s);
12678     }
12679
12680 #ifdef PERL_MAD
12681     if (PL_realtokenstart >= 0) {
12682         stuffstart = PL_realtokenstart;
12683         PL_realtokenstart = -1;
12684     }
12685     else
12686         stuffstart = start - SvPVX(PL_linestr);
12687 #endif
12688     /* mark where we are, in case we need to report errors */
12689     CLINE;
12690
12691     /* after skipping whitespace, the next character is the terminator */
12692     term = *s;
12693     if (!UTF) {
12694         termcode = termstr[0] = term;
12695         termlen = 1;
12696     }
12697     else {
12698         termcode = utf8_to_uvchr((U8*)s, &termlen);
12699         Copy(s, termstr, termlen, U8);
12700         if (!UTF8_IS_INVARIANT(term))
12701             has_utf8 = TRUE;
12702     }
12703
12704     /* mark where we are */
12705     PL_multi_start = CopLINE(PL_curcop);
12706     PL_multi_open = term;
12707
12708     /* find corresponding closing delimiter */
12709     if (term && (tmps = strchr("([{< )]}> )]}>",term)))
12710         termcode = termstr[0] = term = tmps[5];
12711
12712     PL_multi_close = term;
12713
12714     /* create a new SV to hold the contents.  79 is the SV's initial length.
12715        What a random number. */
12716     sv = newSV_type(SVt_PVIV);
12717     SvGROW(sv, 80);
12718     SvIV_set(sv, termcode);
12719     (void)SvPOK_only(sv);               /* validate pointer */
12720
12721     /* move past delimiter and try to read a complete string */
12722     if (keep_delims)
12723         sv_catpvn(sv, s, termlen);
12724     s += termlen;
12725 #ifdef PERL_MAD
12726     tstart = SvPVX(PL_linestr) + stuffstart;
12727     if (!PL_thisopen && !keep_delims) {
12728         PL_thisopen = newSVpvn(tstart, s - tstart);
12729         stuffstart = s - SvPVX(PL_linestr);
12730     }
12731 #endif
12732     for (;;) {
12733         if (PL_encoding && !UTF) {
12734             bool cont = TRUE;
12735
12736             while (cont) {
12737                 int offset = s - SvPVX_const(PL_linestr);
12738                 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
12739                                            &offset, (char*)termstr, termlen);
12740                 const char * const ns = SvPVX_const(PL_linestr) + offset;
12741                 char * const svlast = SvEND(sv) - 1;
12742
12743                 for (; s < ns; s++) {
12744                     if (*s == '\n' && !PL_rsfp)
12745                         CopLINE_inc(PL_curcop);
12746                 }
12747                 if (!found)
12748                     goto read_more_line;
12749                 else {
12750                     /* handle quoted delimiters */
12751                     if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
12752                         const char *t;
12753                         for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
12754                             t--;
12755                         if ((svlast-1 - t) % 2) {
12756                             if (!keep_quoted) {
12757                                 *(svlast-1) = term;
12758                                 *svlast = '\0';
12759                                 SvCUR_set(sv, SvCUR(sv) - 1);
12760                             }
12761                             continue;
12762                         }
12763                     }
12764                     if (PL_multi_open == PL_multi_close) {
12765                         cont = FALSE;
12766                     }
12767                     else {
12768                         const char *t;
12769                         char *w;
12770                         for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
12771                             /* At here, all closes are "was quoted" one,
12772                                so we don't check PL_multi_close. */
12773                             if (*t == '\\') {
12774                                 if (!keep_quoted && *(t+1) == PL_multi_open)
12775                                     t++;
12776                                 else
12777                                     *w++ = *t++;
12778                             }
12779                             else if (*t == PL_multi_open)
12780                                 brackets++;
12781
12782                             *w = *t;
12783                         }
12784                         if (w < t) {
12785                             *w++ = term;
12786                             *w = '\0';
12787                             SvCUR_set(sv, w - SvPVX_const(sv));
12788                         }
12789                         last_off = w - SvPVX(sv);
12790                         if (--brackets <= 0)
12791                             cont = FALSE;
12792                     }
12793                 }
12794             }
12795             if (!keep_delims) {
12796                 SvCUR_set(sv, SvCUR(sv) - 1);
12797                 *SvEND(sv) = '\0';
12798             }
12799             break;
12800         }
12801
12802         /* extend sv if need be */
12803         SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
12804         /* set 'to' to the next character in the sv's string */
12805         to = SvPVX(sv)+SvCUR(sv);
12806
12807         /* if open delimiter is the close delimiter read unbridle */
12808         if (PL_multi_open == PL_multi_close) {
12809             for (; s < PL_bufend; s++,to++) {
12810                 /* embedded newlines increment the current line number */
12811                 if (*s == '\n' && !PL_rsfp)
12812                     CopLINE_inc(PL_curcop);
12813                 /* handle quoted delimiters */
12814                 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
12815                     if (!keep_quoted && s[1] == term)
12816                         s++;
12817                 /* any other quotes are simply copied straight through */
12818                     else
12819                         *to++ = *s++;
12820                 }
12821                 /* terminate when run out of buffer (the for() condition), or
12822                    have found the terminator */
12823                 else if (*s == term) {
12824                     if (termlen == 1)
12825                         break;
12826                     if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
12827                         break;
12828                 }
12829                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
12830                     has_utf8 = TRUE;
12831                 *to = *s;
12832             }
12833         }
12834         
12835         /* if the terminator isn't the same as the start character (e.g.,
12836            matched brackets), we have to allow more in the quoting, and
12837            be prepared for nested brackets.
12838         */
12839         else {
12840             /* read until we run out of string, or we find the terminator */
12841             for (; s < PL_bufend; s++,to++) {
12842                 /* embedded newlines increment the line count */
12843                 if (*s == '\n' && !PL_rsfp)
12844                     CopLINE_inc(PL_curcop);
12845                 /* backslashes can escape the open or closing characters */
12846                 if (*s == '\\' && s+1 < PL_bufend) {
12847                     if (!keep_quoted &&
12848                         ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
12849                         s++;
12850                     else
12851                         *to++ = *s++;
12852                 }
12853                 /* allow nested opens and closes */
12854                 else if (*s == PL_multi_close && --brackets <= 0)
12855                     break;
12856                 else if (*s == PL_multi_open)
12857                     brackets++;
12858                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
12859                     has_utf8 = TRUE;
12860                 *to = *s;
12861             }
12862         }
12863         /* terminate the copied string and update the sv's end-of-string */
12864         *to = '\0';
12865         SvCUR_set(sv, to - SvPVX_const(sv));
12866
12867         /*
12868          * this next chunk reads more into the buffer if we're not done yet
12869          */
12870
12871         if (s < PL_bufend)
12872             break;              /* handle case where we are done yet :-) */
12873
12874 #ifndef PERL_STRICT_CR
12875         if (to - SvPVX_const(sv) >= 2) {
12876             if ((to[-2] == '\r' && to[-1] == '\n') ||
12877                 (to[-2] == '\n' && to[-1] == '\r'))
12878             {
12879                 to[-2] = '\n';
12880                 to--;
12881                 SvCUR_set(sv, to - SvPVX_const(sv));
12882             }
12883             else if (to[-1] == '\r')
12884                 to[-1] = '\n';
12885         }
12886         else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
12887             to[-1] = '\n';
12888 #endif
12889         
12890      read_more_line:
12891         /* if we're out of file, or a read fails, bail and reset the current
12892            line marker so we can report where the unterminated string began
12893         */
12894 #ifdef PERL_MAD
12895         if (PL_madskills) {
12896             char * const tstart = SvPVX(PL_linestr) + stuffstart;
12897             if (PL_thisstuff)
12898                 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
12899             else
12900                 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
12901         }
12902 #endif
12903         CopLINE_inc(PL_curcop);
12904         PL_bufptr = PL_bufend;
12905         if (!lex_next_chunk(0)) {
12906             sv_free(sv);
12907             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
12908             return NULL;
12909         }
12910         s = PL_bufptr;
12911 #ifdef PERL_MAD
12912         stuffstart = 0;
12913 #endif
12914     }
12915
12916     /* at this point, we have successfully read the delimited string */
12917
12918     if (!PL_encoding || UTF) {
12919 #ifdef PERL_MAD
12920         if (PL_madskills) {
12921             char * const tstart = SvPVX(PL_linestr) + stuffstart;
12922             const int len = s - tstart;
12923             if (PL_thisstuff)
12924                 sv_catpvn(PL_thisstuff, tstart, len);
12925             else
12926                 PL_thisstuff = newSVpvn(tstart, len);
12927             if (!PL_thisclose && !keep_delims)
12928                 PL_thisclose = newSVpvn(s,termlen);
12929         }
12930 #endif
12931
12932         if (keep_delims)
12933             sv_catpvn(sv, s, termlen);
12934         s += termlen;
12935     }
12936 #ifdef PERL_MAD
12937     else {
12938         if (PL_madskills) {
12939             char * const tstart = SvPVX(PL_linestr) + stuffstart;
12940             const int len = s - tstart - termlen;
12941             if (PL_thisstuff)
12942                 sv_catpvn(PL_thisstuff, tstart, len);
12943             else
12944                 PL_thisstuff = newSVpvn(tstart, len);
12945             if (!PL_thisclose && !keep_delims)
12946                 PL_thisclose = newSVpvn(s - termlen,termlen);
12947         }
12948     }
12949 #endif
12950     if (has_utf8 || PL_encoding)
12951         SvUTF8_on(sv);
12952
12953     PL_multi_end = CopLINE(PL_curcop);
12954
12955     /* if we allocated too much space, give some back */
12956     if (SvCUR(sv) + 5 < SvLEN(sv)) {
12957         SvLEN_set(sv, SvCUR(sv) + 1);
12958         SvPV_renew(sv, SvLEN(sv));
12959     }
12960
12961     /* decide whether this is the first or second quoted string we've read
12962        for this op
12963     */
12964
12965     if (PL_lex_stuff)
12966         PL_lex_repl = sv;
12967     else
12968         PL_lex_stuff = sv;
12969     return s;
12970 }
12971
12972 /*
12973   scan_num
12974   takes: pointer to position in buffer
12975   returns: pointer to new position in buffer
12976   side-effects: builds ops for the constant in pl_yylval.op
12977
12978   Read a number in any of the formats that Perl accepts:
12979
12980   \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*)      12 12.34 12.
12981   \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*)                     .34
12982   0b[01](_?[01])*
12983   0[0-7](_?[0-7])*
12984   0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
12985
12986   Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
12987   thing it reads.
12988
12989   If it reads a number without a decimal point or an exponent, it will
12990   try converting the number to an integer and see if it can do so
12991   without loss of precision.
12992 */
12993
12994 char *
12995 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
12996 {
12997     dVAR;
12998     register const char *s = start;     /* current position in buffer */
12999     register char *d;                   /* destination in temp buffer */
13000     register char *e;                   /* end of temp buffer */
13001     NV nv;                              /* number read, as a double */
13002     SV *sv = NULL;                      /* place to put the converted number */
13003     bool floatit;                       /* boolean: int or float? */
13004     const char *lastub = NULL;          /* position of last underbar */
13005     static char const number_too_long[] = "Number too long";
13006
13007     PERL_ARGS_ASSERT_SCAN_NUM;
13008
13009     /* We use the first character to decide what type of number this is */
13010
13011     switch (*s) {
13012     default:
13013       Perl_croak(aTHX_ "panic: scan_num");
13014
13015     /* if it starts with a 0, it could be an octal number, a decimal in
13016        0.13 disguise, or a hexadecimal number, or a binary number. */
13017     case '0':
13018         {
13019           /* variables:
13020              u          holds the "number so far"
13021              shift      the power of 2 of the base
13022                         (hex == 4, octal == 3, binary == 1)
13023              overflowed was the number more than we can hold?
13024
13025              Shift is used when we add a digit.  It also serves as an "are
13026              we in octal/hex/binary?" indicator to disallow hex characters
13027              when in octal mode.
13028            */
13029             NV n = 0.0;
13030             UV u = 0;
13031             I32 shift;
13032             bool overflowed = FALSE;
13033             bool just_zero  = TRUE;     /* just plain 0 or binary number? */
13034             static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
13035             static const char* const bases[5] =
13036               { "", "binary", "", "octal", "hexadecimal" };
13037             static const char* const Bases[5] =
13038               { "", "Binary", "", "Octal", "Hexadecimal" };
13039             static const char* const maxima[5] =
13040               { "",
13041                 "0b11111111111111111111111111111111",
13042                 "",
13043                 "037777777777",
13044                 "0xffffffff" };
13045             const char *base, *Base, *max;
13046
13047             /* check for hex */
13048             if (s[1] == 'x' || s[1] == 'X') {
13049                 shift = 4;
13050                 s += 2;
13051                 just_zero = FALSE;
13052             } else if (s[1] == 'b' || s[1] == 'B') {
13053                 shift = 1;
13054                 s += 2;
13055                 just_zero = FALSE;
13056             }
13057             /* check for a decimal in disguise */
13058             else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
13059                 goto decimal;
13060             /* so it must be octal */
13061             else {
13062                 shift = 3;
13063                 s++;
13064             }
13065
13066             if (*s == '_') {
13067                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13068                                "Misplaced _ in number");
13069                lastub = s++;
13070             }
13071
13072             base = bases[shift];
13073             Base = Bases[shift];
13074             max  = maxima[shift];
13075
13076             /* read the rest of the number */
13077             for (;;) {
13078                 /* x is used in the overflow test,
13079                    b is the digit we're adding on. */
13080                 UV x, b;
13081
13082                 switch (*s) {
13083
13084                 /* if we don't mention it, we're done */
13085                 default:
13086                     goto out;
13087
13088                 /* _ are ignored -- but warned about if consecutive */
13089                 case '_':
13090                     if (lastub && s == lastub + 1)
13091                         Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13092                                        "Misplaced _ in number");
13093                     lastub = s++;
13094                     break;
13095
13096                 /* 8 and 9 are not octal */
13097                 case '8': case '9':
13098                     if (shift == 3)
13099                         yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
13100                     /* FALL THROUGH */
13101
13102                 /* octal digits */
13103                 case '2': case '3': case '4':
13104                 case '5': case '6': case '7':
13105                     if (shift == 1)
13106                         yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
13107                     /* FALL THROUGH */
13108
13109                 case '0': case '1':
13110                     b = *s++ & 15;              /* ASCII digit -> value of digit */
13111                     goto digit;
13112
13113                 /* hex digits */
13114                 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
13115                 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
13116                     /* make sure they said 0x */
13117                     if (shift != 4)
13118                         goto out;
13119                     b = (*s++ & 7) + 9;
13120
13121                     /* Prepare to put the digit we have onto the end
13122                        of the number so far.  We check for overflows.
13123                     */
13124
13125                   digit:
13126                     just_zero = FALSE;
13127                     if (!overflowed) {
13128                         x = u << shift; /* make room for the digit */
13129
13130                         if ((x >> shift) != u
13131                             && !(PL_hints & HINT_NEW_BINARY)) {
13132                             overflowed = TRUE;
13133                             n = (NV) u;
13134                             Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
13135                                              "Integer overflow in %s number",
13136                                              base);
13137                         } else
13138                             u = x | b;          /* add the digit to the end */
13139                     }
13140                     if (overflowed) {
13141                         n *= nvshift[shift];
13142                         /* If an NV has not enough bits in its
13143                          * mantissa to represent an UV this summing of
13144                          * small low-order numbers is a waste of time
13145                          * (because the NV cannot preserve the
13146                          * low-order bits anyway): we could just
13147                          * remember when did we overflow and in the
13148                          * end just multiply n by the right
13149                          * amount. */
13150                         n += (NV) b;
13151                     }
13152                     break;
13153                 }
13154             }
13155
13156           /* if we get here, we had success: make a scalar value from
13157              the number.
13158           */
13159           out:
13160
13161             /* final misplaced underbar check */
13162             if (s[-1] == '_') {
13163                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
13164             }
13165
13166             if (overflowed) {
13167                 if (n > 4294967295.0)
13168                     Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
13169                                    "%s number > %s non-portable",
13170                                    Base, max);
13171                 sv = newSVnv(n);
13172             }
13173             else {
13174 #if UVSIZE > 4
13175                 if (u > 0xffffffff)
13176                     Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
13177                                    "%s number > %s non-portable",
13178                                    Base, max);
13179 #endif
13180                 sv = newSVuv(u);
13181             }
13182             if (just_zero && (PL_hints & HINT_NEW_INTEGER))
13183                 sv = new_constant(start, s - start, "integer",
13184                                   sv, NULL, NULL, 0);
13185             else if (PL_hints & HINT_NEW_BINARY)
13186                 sv = new_constant(start, s - start, "binary", sv, NULL, NULL, 0);
13187         }
13188         break;
13189
13190     /*
13191       handle decimal numbers.
13192       we're also sent here when we read a 0 as the first digit
13193     */
13194     case '1': case '2': case '3': case '4': case '5':
13195     case '6': case '7': case '8': case '9': case '.':
13196       decimal:
13197         d = PL_tokenbuf;
13198         e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
13199         floatit = FALSE;
13200
13201         /* read next group of digits and _ and copy into d */
13202         while (isDIGIT(*s) || *s == '_') {
13203             /* skip underscores, checking for misplaced ones
13204                if -w is on
13205             */
13206             if (*s == '_') {
13207                 if (lastub && s == lastub + 1)
13208                     Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13209                                    "Misplaced _ in number");
13210                 lastub = s++;
13211             }
13212             else {
13213                 /* check for end of fixed-length buffer */
13214                 if (d >= e)
13215                     Perl_croak(aTHX_ number_too_long);
13216                 /* if we're ok, copy the character */
13217                 *d++ = *s++;
13218             }
13219         }
13220
13221         /* final misplaced underbar check */
13222         if (lastub && s == lastub + 1) {
13223             Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
13224         }
13225
13226         /* read a decimal portion if there is one.  avoid
13227            3..5 being interpreted as the number 3. followed
13228            by .5
13229         */
13230         if (*s == '.' && s[1] != '.') {
13231             floatit = TRUE;
13232             *d++ = *s++;
13233
13234             if (*s == '_') {
13235                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13236                                "Misplaced _ in number");
13237                 lastub = s;
13238             }
13239
13240             /* copy, ignoring underbars, until we run out of digits.
13241             */
13242             for (; isDIGIT(*s) || *s == '_'; s++) {
13243                 /* fixed length buffer check */
13244                 if (d >= e)
13245                     Perl_croak(aTHX_ number_too_long);
13246                 if (*s == '_') {
13247                    if (lastub && s == lastub + 1)
13248                        Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13249                                       "Misplaced _ in number");
13250                    lastub = s;
13251                 }
13252                 else
13253                     *d++ = *s;
13254             }
13255             /* fractional part ending in underbar? */
13256             if (s[-1] == '_') {
13257                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13258                                "Misplaced _ in number");
13259             }
13260             if (*s == '.' && isDIGIT(s[1])) {
13261                 /* oops, it's really a v-string, but without the "v" */
13262                 s = start;
13263                 goto vstring;
13264             }
13265         }
13266
13267         /* read exponent part, if present */
13268         if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
13269             floatit = TRUE;
13270             s++;
13271
13272             /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
13273             *d++ = 'e';         /* At least some Mach atof()s don't grok 'E' */
13274
13275             /* stray preinitial _ */
13276             if (*s == '_') {
13277                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13278                                "Misplaced _ in number");
13279                 lastub = s++;
13280             }
13281
13282             /* allow positive or negative exponent */
13283             if (*s == '+' || *s == '-')
13284                 *d++ = *s++;
13285
13286             /* stray initial _ */
13287             if (*s == '_') {
13288                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13289                                "Misplaced _ in number");
13290                 lastub = s++;
13291             }
13292
13293             /* read digits of exponent */
13294             while (isDIGIT(*s) || *s == '_') {
13295                 if (isDIGIT(*s)) {
13296                     if (d >= e)
13297                         Perl_croak(aTHX_ number_too_long);
13298                     *d++ = *s++;
13299                 }
13300                 else {
13301                    if (((lastub && s == lastub + 1) ||
13302                         (!isDIGIT(s[1]) && s[1] != '_')))
13303                        Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13304                                       "Misplaced _ in number");
13305                    lastub = s++;
13306                 }
13307             }
13308         }
13309
13310
13311         /*
13312            We try to do an integer conversion first if no characters
13313            indicating "float" have been found.
13314          */
13315
13316         if (!floatit) {
13317             UV uv;
13318             const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
13319
13320             if (flags == IS_NUMBER_IN_UV) {
13321               if (uv <= IV_MAX)
13322                 sv = newSViv(uv); /* Prefer IVs over UVs. */
13323               else
13324                 sv = newSVuv(uv);
13325             } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
13326               if (uv <= (UV) IV_MIN)
13327                 sv = newSViv(-(IV)uv);
13328               else
13329                 floatit = TRUE;
13330             } else
13331               floatit = TRUE;
13332         }
13333         if (floatit) {
13334             /* terminate the string */
13335             *d = '\0';
13336             nv = Atof(PL_tokenbuf);
13337             sv = newSVnv(nv);
13338         }
13339
13340         if ( floatit
13341              ? (PL_hints & HINT_NEW_FLOAT) : (PL_hints & HINT_NEW_INTEGER) ) {
13342             const char *const key = floatit ? "float" : "integer";
13343             const STRLEN keylen = floatit ? 5 : 7;
13344             sv = S_new_constant(aTHX_ PL_tokenbuf, d - PL_tokenbuf,
13345                                 key, keylen, sv, NULL, NULL, 0);
13346         }
13347         break;
13348
13349     /* if it starts with a v, it could be a v-string */
13350     case 'v':
13351 vstring:
13352                 sv = newSV(5); /* preallocate storage space */
13353                 s = scan_vstring(s, PL_bufend, sv);
13354         break;
13355     }
13356
13357     /* make the op for the constant and return */
13358
13359     if (sv)
13360         lvalp->opval = newSVOP(OP_CONST, 0, sv);
13361     else
13362         lvalp->opval = NULL;
13363
13364     return (char *)s;
13365 }
13366
13367 STATIC char *
13368 S_scan_formline(pTHX_ register char *s)
13369 {
13370     dVAR;
13371     register char *eol;
13372     register char *t;
13373     SV * const stuff = newSVpvs("");
13374     bool needargs = FALSE;
13375     bool eofmt = FALSE;
13376 #ifdef PERL_MAD
13377     char *tokenstart = s;
13378     SV* savewhite = NULL;
13379
13380     if (PL_madskills) {
13381         savewhite = PL_thiswhite;
13382         PL_thiswhite = 0;
13383     }
13384 #endif
13385
13386     PERL_ARGS_ASSERT_SCAN_FORMLINE;
13387
13388     while (!needargs) {
13389         if (*s == '.') {
13390             t = s+1;
13391 #ifdef PERL_STRICT_CR
13392             while (SPACE_OR_TAB(*t))
13393                 t++;
13394 #else
13395             while (SPACE_OR_TAB(*t) || *t == '\r')
13396                 t++;
13397 #endif
13398             if (*t == '\n' || t == PL_bufend) {
13399                 eofmt = TRUE;
13400                 break;
13401             }
13402         }
13403         if (PL_in_eval && !PL_rsfp) {
13404             eol = (char *) memchr(s,'\n',PL_bufend-s);
13405             if (!eol++)
13406                 eol = PL_bufend;
13407         }
13408         else
13409             eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
13410         if (*s != '#') {
13411             for (t = s; t < eol; t++) {
13412                 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
13413                     needargs = FALSE;
13414                     goto enough;        /* ~~ must be first line in formline */
13415                 }
13416                 if (*t == '@' || *t == '^')
13417                     needargs = TRUE;
13418             }
13419             if (eol > s) {
13420                 sv_catpvn(stuff, s, eol-s);
13421 #ifndef PERL_STRICT_CR
13422                 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
13423                     char *end = SvPVX(stuff) + SvCUR(stuff);
13424                     end[-2] = '\n';
13425                     end[-1] = '\0';
13426                     SvCUR_set(stuff, SvCUR(stuff) - 1);
13427                 }
13428 #endif
13429             }
13430             else
13431               break;
13432         }
13433         s = (char*)eol;
13434         if (PL_rsfp) {
13435             bool got_some;
13436 #ifdef PERL_MAD
13437             if (PL_madskills) {
13438                 if (PL_thistoken)
13439                     sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
13440                 else
13441                     PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
13442             }
13443 #endif
13444             PL_bufptr = PL_bufend;
13445             CopLINE_inc(PL_curcop);
13446             got_some = lex_next_chunk(0);
13447             CopLINE_dec(PL_curcop);
13448             s = PL_bufptr;
13449 #ifdef PERL_MAD
13450             tokenstart = PL_bufptr;
13451 #endif
13452             if (!got_some)
13453                 break;
13454         }
13455         incline(s);
13456     }
13457   enough:
13458     if (SvCUR(stuff)) {
13459         PL_expect = XTERM;
13460         if (needargs) {
13461             PL_lex_state = LEX_NORMAL;
13462             start_force(PL_curforce);
13463             NEXTVAL_NEXTTOKE.ival = 0;
13464             force_next(',');
13465         }
13466         else
13467             PL_lex_state = LEX_FORMLINE;
13468         if (!IN_BYTES) {
13469             if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
13470                 SvUTF8_on(stuff);
13471             else if (PL_encoding)
13472                 sv_recode_to_utf8(stuff, PL_encoding);
13473         }
13474         start_force(PL_curforce);
13475         NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
13476         force_next(THING);
13477         start_force(PL_curforce);
13478         NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
13479         force_next(LSTOP);
13480     }
13481     else {
13482         SvREFCNT_dec(stuff);
13483         if (eofmt)
13484             PL_lex_formbrack = 0;
13485         PL_bufptr = s;
13486     }
13487 #ifdef PERL_MAD
13488     if (PL_madskills) {
13489         if (PL_thistoken)
13490             sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
13491         else
13492             PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
13493         PL_thiswhite = savewhite;
13494     }
13495 #endif
13496     return s;
13497 }
13498
13499 I32
13500 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
13501 {
13502     dVAR;
13503     const I32 oldsavestack_ix = PL_savestack_ix;
13504     CV* const outsidecv = PL_compcv;
13505
13506     if (PL_compcv) {
13507         assert(SvTYPE(PL_compcv) == SVt_PVCV);
13508     }
13509     SAVEI32(PL_subline);
13510     save_item(PL_subname);
13511     SAVESPTR(PL_compcv);
13512
13513     PL_compcv = MUTABLE_CV(newSV_type(is_format ? SVt_PVFM : SVt_PVCV));
13514     CvFLAGS(PL_compcv) |= flags;
13515
13516     PL_subline = CopLINE(PL_curcop);
13517     CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
13518     CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv));
13519     CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
13520
13521     return oldsavestack_ix;
13522 }
13523
13524 #ifdef __SC__
13525 #pragma segment Perl_yylex
13526 #endif
13527 static int
13528 S_yywarn(pTHX_ const char *const s)
13529 {
13530     dVAR;
13531
13532     PERL_ARGS_ASSERT_YYWARN;
13533
13534     PL_in_eval |= EVAL_WARNONLY;
13535     yyerror(s);
13536     PL_in_eval &= ~EVAL_WARNONLY;
13537     return 0;
13538 }
13539
13540 int
13541 Perl_yyerror(pTHX_ const char *const s)
13542 {
13543     dVAR;
13544     const char *where = NULL;
13545     const char *context = NULL;
13546     int contlen = -1;
13547     SV *msg;
13548     int yychar  = PL_parser->yychar;
13549
13550     PERL_ARGS_ASSERT_YYERROR;
13551
13552     if (!yychar || (yychar == ';' && !PL_rsfp))
13553         where = "at EOF";
13554     else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
13555       PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
13556       PL_oldbufptr != PL_bufptr) {
13557         /*
13558                 Only for NetWare:
13559                 The code below is removed for NetWare because it abends/crashes on NetWare
13560                 when the script has error such as not having the closing quotes like:
13561                     if ($var eq "value)
13562                 Checking of white spaces is anyway done in NetWare code.
13563         */
13564 #ifndef NETWARE
13565         while (isSPACE(*PL_oldoldbufptr))
13566             PL_oldoldbufptr++;
13567 #endif
13568         context = PL_oldoldbufptr;
13569         contlen = PL_bufptr - PL_oldoldbufptr;
13570     }
13571     else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
13572       PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
13573         /*
13574                 Only for NetWare:
13575                 The code below is removed for NetWare because it abends/crashes on NetWare
13576                 when the script has error such as not having the closing quotes like:
13577                     if ($var eq "value)
13578                 Checking of white spaces is anyway done in NetWare code.
13579         */
13580 #ifndef NETWARE
13581         while (isSPACE(*PL_oldbufptr))
13582             PL_oldbufptr++;
13583 #endif
13584         context = PL_oldbufptr;
13585         contlen = PL_bufptr - PL_oldbufptr;
13586     }
13587     else if (yychar > 255)
13588         where = "next token ???";
13589     else if (yychar == -2) { /* YYEMPTY */
13590         if (PL_lex_state == LEX_NORMAL ||
13591            (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
13592             where = "at end of line";
13593         else if (PL_lex_inpat)
13594             where = "within pattern";
13595         else
13596             where = "within string";
13597     }
13598     else {
13599         SV * const where_sv = newSVpvs_flags("next char ", SVs_TEMP);
13600         if (yychar < 32)
13601             Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
13602         else if (isPRINT_LC(yychar)) {
13603             const char string = yychar;
13604             sv_catpvn(where_sv, &string, 1);
13605         }
13606         else
13607             Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
13608         where = SvPVX_const(where_sv);
13609     }
13610     msg = sv_2mortal(newSVpv(s, 0));
13611     Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
13612         OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
13613     if (context)
13614         Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
13615     else
13616         Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
13617     if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
13618         Perl_sv_catpvf(aTHX_ msg,
13619         "  (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
13620                 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
13621         PL_multi_end = 0;
13622     }
13623     if (PL_in_eval & EVAL_WARNONLY) {
13624         Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
13625     }
13626     else
13627         qerror(msg);
13628     if (PL_error_count >= 10) {
13629         if (PL_in_eval && SvCUR(ERRSV))
13630             Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
13631                        SVfARG(ERRSV), OutCopFILE(PL_curcop));
13632         else
13633             Perl_croak(aTHX_ "%s has too many errors.\n",
13634             OutCopFILE(PL_curcop));
13635     }
13636     PL_in_my = 0;
13637     PL_in_my_stash = NULL;
13638     return 0;
13639 }
13640 #ifdef __SC__
13641 #pragma segment Main
13642 #endif
13643
13644 STATIC char*
13645 S_swallow_bom(pTHX_ U8 *s)
13646 {
13647     dVAR;
13648     const STRLEN slen = SvCUR(PL_linestr);
13649
13650     PERL_ARGS_ASSERT_SWALLOW_BOM;
13651
13652     switch (s[0]) {
13653     case 0xFF:
13654         if (s[1] == 0xFE) {
13655             /* UTF-16 little-endian? (or UTF-32LE?) */
13656             if (s[2] == 0 && s[3] == 0)  /* UTF-32 little-endian */
13657                 Perl_croak(aTHX_ "Unsupported script encoding UTF-32LE");
13658 #ifndef PERL_NO_UTF16_FILTER
13659             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (BOM)\n");
13660             s += 2;
13661             if (PL_bufend > (char*)s) {
13662                 s = add_utf16_textfilter(s, TRUE);
13663             }
13664 #else
13665             Perl_croak(aTHX_ "Unsupported script encoding UTF-16LE");
13666 #endif
13667         }
13668         break;
13669     case 0xFE:
13670         if (s[1] == 0xFF) {   /* UTF-16 big-endian? */
13671 #ifndef PERL_NO_UTF16_FILTER
13672             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
13673             s += 2;
13674             if (PL_bufend > (char *)s) {
13675                 s = add_utf16_textfilter(s, FALSE);
13676             }
13677 #else
13678             Perl_croak(aTHX_ "Unsupported script encoding UTF-16BE");
13679 #endif
13680         }
13681         break;
13682     case 0xEF:
13683         if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
13684             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
13685             s += 3;                      /* UTF-8 */
13686         }
13687         break;
13688     case 0:
13689         if (slen > 3) {
13690              if (s[1] == 0) {
13691                   if (s[2] == 0xFE && s[3] == 0xFF) {
13692                        /* UTF-32 big-endian */
13693                        Perl_croak(aTHX_ "Unsupported script encoding UTF-32BE");
13694                   }
13695              }
13696              else if (s[2] == 0 && s[3] != 0) {
13697                   /* Leading bytes
13698                    * 00 xx 00 xx
13699                    * are a good indicator of UTF-16BE. */
13700 #ifndef PERL_NO_UTF16_FILTER
13701                   if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
13702                   s = add_utf16_textfilter(s, FALSE);
13703 #else
13704                   Perl_croak(aTHX_ "Unsupported script encoding UTF-16BE");
13705 #endif
13706              }
13707         }
13708 #ifdef EBCDIC
13709     case 0xDD:
13710         if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
13711             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
13712             s += 4;                      /* UTF-8 */
13713         }
13714         break;
13715 #endif
13716
13717     default:
13718          if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
13719                   /* Leading bytes
13720                    * xx 00 xx 00
13721                    * are a good indicator of UTF-16LE. */
13722 #ifndef PERL_NO_UTF16_FILTER
13723               if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
13724               s = add_utf16_textfilter(s, TRUE);
13725 #else
13726               Perl_croak(aTHX_ "Unsupported script encoding UTF-16LE");
13727 #endif
13728          }
13729     }
13730     return (char*)s;
13731 }
13732
13733
13734 #ifndef PERL_NO_UTF16_FILTER
13735 static I32
13736 S_utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
13737 {
13738     dVAR;
13739     SV *const filter = FILTER_DATA(idx);
13740     /* We re-use this each time round, throwing the contents away before we
13741        return.  */
13742     SV *const utf16_buffer = MUTABLE_SV(IoTOP_GV(filter));
13743     SV *const utf8_buffer = filter;
13744     IV status = IoPAGE(filter);
13745     const bool reverse = cBOOL(IoLINES(filter));
13746     I32 retval;
13747
13748     PERL_ARGS_ASSERT_UTF16_TEXTFILTER;
13749
13750     /* As we're automatically added, at the lowest level, and hence only called
13751        from this file, we can be sure that we're not called in block mode. Hence
13752        don't bother writing code to deal with block mode.  */
13753     if (maxlen) {
13754         Perl_croak(aTHX_ "panic: utf16_textfilter called in block mode (for %d characters)", maxlen);
13755     }
13756     if (status < 0) {
13757         Perl_croak(aTHX_ "panic: utf16_textfilter called after error (status=%"IVdf")", status);
13758     }
13759     DEBUG_P(PerlIO_printf(Perl_debug_log,
13760                           "utf16_textfilter(%p,%ce): idx=%d maxlen=%d status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n",
13761                           FPTR2DPTR(void *, S_utf16_textfilter),
13762                           reverse ? 'l' : 'b', idx, maxlen, status,
13763                           (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer)));
13764
13765     while (1) {
13766         STRLEN chars;
13767         STRLEN have;
13768         I32 newlen;
13769         U8 *end;
13770         /* First, look in our buffer of existing UTF-8 data:  */
13771         char *nl = (char *)memchr(SvPVX(utf8_buffer), '\n', SvCUR(utf8_buffer));
13772
13773         if (nl) {
13774             ++nl;
13775         } else if (status == 0) {
13776             /* EOF */
13777             IoPAGE(filter) = 0;
13778             nl = SvEND(utf8_buffer);
13779         }
13780         if (nl) {
13781             STRLEN got = nl - SvPVX(utf8_buffer);
13782             /* Did we have anything to append?  */
13783             retval = got != 0;
13784             sv_catpvn(sv, SvPVX(utf8_buffer), got);
13785             /* Everything else in this code works just fine if SVp_POK isn't
13786                set.  This, however, needs it, and we need it to work, else
13787                we loop infinitely because the buffer is never consumed.  */
13788             sv_chop(utf8_buffer, nl);
13789             break;
13790         }
13791
13792         /* OK, not a complete line there, so need to read some more UTF-16.
13793            Read an extra octect if the buffer currently has an odd number. */
13794         while (1) {
13795             if (status <= 0)
13796                 break;
13797             if (SvCUR(utf16_buffer) >= 2) {
13798                 /* Location of the high octet of the last complete code point.
13799                    Gosh, UTF-16 is a pain. All the benefits of variable length,
13800                    *coupled* with all the benefits of partial reads and
13801                    endianness.  */
13802                 const U8 *const last_hi = (U8*)SvPVX(utf16_buffer)
13803                     + ((SvCUR(utf16_buffer) & ~1) - (reverse ? 1 : 2));
13804
13805                 if (*last_hi < 0xd8 || *last_hi > 0xdb) {
13806                     break;
13807                 }
13808
13809                 /* We have the first half of a surrogate. Read more.  */
13810                 DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter partial surrogate detected at %p\n", last_hi));
13811             }
13812
13813             status = FILTER_READ(idx + 1, utf16_buffer,
13814                                  160 + (SvCUR(utf16_buffer) & 1));
13815             DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter status=%"IVdf" SvCUR(sv)=%"UVuf"\n", status, (UV)SvCUR(utf16_buffer)));
13816             DEBUG_P({ sv_dump(utf16_buffer); sv_dump(utf8_buffer);});
13817             if (status < 0) {
13818                 /* Error */
13819                 IoPAGE(filter) = status;
13820                 return status;
13821             }
13822         }
13823
13824         chars = SvCUR(utf16_buffer) >> 1;
13825         have = SvCUR(utf8_buffer);
13826         SvGROW(utf8_buffer, have + chars * 3 + 1);
13827
13828         if (reverse) {
13829             end = utf16_to_utf8_reversed((U8*)SvPVX(utf16_buffer),
13830                                          (U8*)SvPVX_const(utf8_buffer) + have,
13831                                          chars * 2, &newlen);
13832         } else {
13833             end = utf16_to_utf8((U8*)SvPVX(utf16_buffer),
13834                                 (U8*)SvPVX_const(utf8_buffer) + have,
13835                                 chars * 2, &newlen);
13836         }
13837         SvCUR_set(utf8_buffer, have + newlen);
13838         *end = '\0';
13839
13840         /* No need to keep this SV "well-formed" with a '\0' after the end, as
13841            it's private to us, and utf16_to_utf8{,reversed} take a
13842            (pointer,length) pair, rather than a NUL-terminated string.  */
13843         if(SvCUR(utf16_buffer) & 1) {
13844             *SvPVX(utf16_buffer) = SvEND(utf16_buffer)[-1];
13845             SvCUR_set(utf16_buffer, 1);
13846         } else {
13847             SvCUR_set(utf16_buffer, 0);
13848         }
13849     }
13850     DEBUG_P(PerlIO_printf(Perl_debug_log,
13851                           "utf16_textfilter: returns, status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n",
13852                           status,
13853                           (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer)));
13854     DEBUG_P({ sv_dump(utf8_buffer); sv_dump(sv);});
13855     return retval;
13856 }
13857
13858 static U8 *
13859 S_add_utf16_textfilter(pTHX_ U8 *const s, bool reversed)
13860 {
13861     SV *filter = filter_add(S_utf16_textfilter, NULL);
13862
13863     PERL_ARGS_ASSERT_ADD_UTF16_TEXTFILTER;
13864
13865     IoTOP_GV(filter) = MUTABLE_GV(newSVpvn((char *)s, PL_bufend - (char*)s));
13866     sv_setpvs(filter, "");
13867     IoLINES(filter) = reversed;
13868     IoPAGE(filter) = 1; /* Not EOF */
13869
13870     /* Sadly, we have to return a valid pointer, come what may, so we have to
13871        ignore any error return from this.  */
13872     SvCUR_set(PL_linestr, 0);
13873     if (FILTER_READ(0, PL_linestr, 0)) {
13874         SvUTF8_on(PL_linestr);
13875     } else {
13876         SvUTF8_on(PL_linestr);
13877     }
13878     PL_bufend = SvEND(PL_linestr);
13879     return (U8*)SvPVX(PL_linestr);
13880 }
13881 #endif
13882
13883 /*
13884 Returns a pointer to the next character after the parsed
13885 vstring, as well as updating the passed in sv.
13886
13887 Function must be called like
13888
13889         sv = newSV(5);
13890         s = scan_vstring(s,e,sv);
13891
13892 where s and e are the start and end of the string.
13893 The sv should already be large enough to store the vstring
13894 passed in, for performance reasons.
13895
13896 */
13897
13898 char *
13899 Perl_scan_vstring(pTHX_ const char *s, const char *const e, SV *sv)
13900 {
13901     dVAR;
13902     const char *pos = s;
13903     const char *start = s;
13904
13905     PERL_ARGS_ASSERT_SCAN_VSTRING;
13906
13907     if (*pos == 'v') pos++;  /* get past 'v' */
13908     while (pos < e && (isDIGIT(*pos) || *pos == '_'))
13909         pos++;
13910     if ( *pos != '.') {
13911         /* this may not be a v-string if followed by => */
13912         const char *next = pos;
13913         while (next < e && isSPACE(*next))
13914             ++next;
13915         if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
13916             /* return string not v-string */
13917             sv_setpvn(sv,(char *)s,pos-s);
13918             return (char *)pos;
13919         }
13920     }
13921
13922     if (!isALPHA(*pos)) {
13923         U8 tmpbuf[UTF8_MAXBYTES+1];
13924
13925         if (*s == 'v')
13926             s++;  /* get past 'v' */
13927
13928         sv_setpvs(sv, "");
13929
13930         for (;;) {
13931             /* this is atoi() that tolerates underscores */
13932             U8 *tmpend;
13933             UV rev = 0;
13934             const char *end = pos;
13935             UV mult = 1;
13936             while (--end >= s) {
13937                 if (*end != '_') {
13938                     const UV orev = rev;
13939                     rev += (*end - '0') * mult;
13940                     mult *= 10;
13941                     if (orev > rev)
13942                         Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
13943                                          "Integer overflow in decimal number");
13944                 }
13945             }
13946 #ifdef EBCDIC
13947             if (rev > 0x7FFFFFFF)
13948                  Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
13949 #endif
13950             /* Append native character for the rev point */
13951             tmpend = uvchr_to_utf8(tmpbuf, rev);
13952             sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
13953             if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
13954                  SvUTF8_on(sv);
13955             if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
13956                  s = ++pos;
13957             else {
13958                  s = pos;
13959                  break;
13960             }
13961             while (pos < e && (isDIGIT(*pos) || *pos == '_'))
13962                  pos++;
13963         }
13964         SvPOK_on(sv);
13965         sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
13966         SvRMAGICAL_on(sv);
13967     }
13968     return (char *)s;
13969 }
13970
13971 int
13972 Perl_keyword_plugin_standard(pTHX_
13973         char *keyword_ptr, STRLEN keyword_len, OP **op_ptr)
13974 {
13975     PERL_ARGS_ASSERT_KEYWORD_PLUGIN_STANDARD;
13976     PERL_UNUSED_CONTEXT;
13977     PERL_UNUSED_ARG(keyword_ptr);
13978     PERL_UNUSED_ARG(keyword_len);
13979     PERL_UNUSED_ARG(op_ptr);
13980     return KEYWORD_PLUGIN_DECLINE;
13981 }
13982
13983 #define parse_recdescent(g) S_parse_recdescent(aTHX_ g)
13984 static void
13985 S_parse_recdescent(pTHX_ int gramtype)
13986 {
13987     SAVEI32(PL_lex_brackets);
13988     if (PL_lex_brackets > 100)
13989         Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
13990     PL_lex_brackstack[PL_lex_brackets++] = XFAKEEOF;
13991     if(yyparse(gramtype) && !PL_parser->error_count)
13992         qerror(Perl_mess(aTHX_ "Parse error"));
13993 }
13994
13995 #define parse_recdescent_for_op(g) S_parse_recdescent_for_op(aTHX_ g)
13996 static OP *
13997 S_parse_recdescent_for_op(pTHX_ int gramtype)
13998 {
13999     OP *o;
14000     ENTER;
14001     SAVEVPTR(PL_eval_root);
14002     PL_eval_root = NULL;
14003     parse_recdescent(gramtype);
14004     o = PL_eval_root;
14005     LEAVE;
14006     return o;
14007 }
14008
14009 /*
14010 =for apidoc Amx|OP *|parse_block|U32 flags
14011
14012 Parse a single complete Perl code block.  This consists of an opening
14013 brace, a sequence of statements, and a closing brace.  The block
14014 constitutes a lexical scope, so C<my> variables and various compile-time
14015 effects can be contained within it.  It is up to the caller to ensure
14016 that the dynamic parser state (L</PL_parser> et al) is correctly set to
14017 reflect the source of the code to be parsed and the lexical context for
14018 the statement.
14019
14020 The op tree representing the code block is returned.  This is always a
14021 real op, never a null pointer.  It will normally be a C<lineseq> list,
14022 including C<nextstate> or equivalent ops.  No ops to construct any kind
14023 of runtime scope are included by virtue of it being a block.
14024
14025 If an error occurs in parsing or compilation, in most cases a valid op
14026 tree (most likely null) is returned anyway.  The error is reflected in
14027 the parser state, normally resulting in a single exception at the top
14028 level of parsing which covers all the compilation errors that occurred.
14029 Some compilation errors, however, will throw an exception immediately.
14030
14031 The I<flags> parameter is reserved for future use, and must always
14032 be zero.
14033
14034 =cut
14035 */
14036
14037 OP *
14038 Perl_parse_block(pTHX_ U32 flags)
14039 {
14040     if (flags)
14041         Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_block");
14042     return parse_recdescent_for_op(GRAMBLOCK);
14043 }
14044
14045 /*
14046 =for apidoc Amx|OP *|parse_barestmt|U32 flags
14047
14048 Parse a single unadorned Perl statement.  This may be a normal imperative
14049 statement or a declaration that has compile-time effect.  It does not
14050 include any label or other affixture.  It is up to the caller to ensure
14051 that the dynamic parser state (L</PL_parser> et al) is correctly set to
14052 reflect the source of the code to be parsed and the lexical context for
14053 the statement.
14054
14055 The op tree representing the statement is returned.  This may be a
14056 null pointer if the statement is null, for example if it was actually
14057 a subroutine definition (which has compile-time side effects).  If not
14058 null, it will be ops directly implementing the statement, suitable to
14059 pass to L</newSTATEOP>.  It will not normally include a C<nextstate> or
14060 equivalent op (except for those embedded in a scope contained entirely
14061 within the statement).
14062
14063 If an error occurs in parsing or compilation, in most cases a valid op
14064 tree (most likely null) is returned anyway.  The error is reflected in
14065 the parser state, normally resulting in a single exception at the top
14066 level of parsing which covers all the compilation errors that occurred.
14067 Some compilation errors, however, will throw an exception immediately.
14068
14069 The I<flags> parameter is reserved for future use, and must always
14070 be zero.
14071
14072 =cut
14073 */
14074
14075 OP *
14076 Perl_parse_barestmt(pTHX_ U32 flags)
14077 {
14078     if (flags)
14079         Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_barestmt");
14080     return parse_recdescent_for_op(GRAMBARESTMT);
14081 }
14082
14083 /*
14084 =for apidoc Amx|SV *|parse_label|U32 flags
14085
14086 Parse a single label, possibly optional, of the type that may prefix a
14087 Perl statement.  It is up to the caller to ensure that the dynamic parser
14088 state (L</PL_parser> et al) is correctly set to reflect the source of
14089 the code to be parsed.  If I<flags> includes C<PARSE_OPTIONAL> then the
14090 label is optional, otherwise it is mandatory.
14091
14092 The name of the label is returned in the form of a fresh scalar.  If an
14093 optional label is absent, a null pointer is returned.
14094
14095 If an error occurs in parsing, which can only occur if the label is
14096 mandatory, a valid label is returned anyway.  The error is reflected in
14097 the parser state, normally resulting in a single exception at the top
14098 level of parsing which covers all the compilation errors that occurred.
14099
14100 =cut
14101 */
14102
14103 SV *
14104 Perl_parse_label(pTHX_ U32 flags)
14105 {
14106     if (flags & ~PARSE_OPTIONAL)
14107         Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_label");
14108     if (PL_lex_state == LEX_KNOWNEXT) {
14109         PL_parser->yychar = yylex();
14110         if (PL_parser->yychar == LABEL) {
14111             char *lpv = pl_yylval.pval;
14112             STRLEN llen = strlen(lpv);
14113             SV *lsv;
14114             PL_parser->yychar = YYEMPTY;
14115             lsv = newSV_type(SVt_PV);
14116             SvPV_set(lsv, lpv);
14117             SvCUR_set(lsv, llen);
14118             SvLEN_set(lsv, llen+1);
14119             SvPOK_on(lsv);
14120             return lsv;
14121         } else {
14122             yyunlex();
14123             goto no_label;
14124         }
14125     } else {
14126         char *s, *t;
14127         U8 c;
14128         STRLEN wlen, bufptr_pos;
14129         lex_read_space(0);
14130         t = s = PL_bufptr;
14131         c = (U8)*s;
14132         if (!isIDFIRST_A(c))
14133             goto no_label;
14134         do {
14135             c = (U8)*++t;
14136         } while(isWORDCHAR_A(c));
14137         wlen = t - s;
14138         if (word_takes_any_delimeter(s, wlen))
14139             goto no_label;
14140         bufptr_pos = s - SvPVX(PL_linestr);
14141         PL_bufptr = t;
14142         lex_read_space(LEX_KEEP_PREVIOUS);
14143         t = PL_bufptr;
14144         s = SvPVX(PL_linestr) + bufptr_pos;
14145         if (t[0] == ':' && t[1] != ':') {
14146             PL_oldoldbufptr = PL_oldbufptr;
14147             PL_oldbufptr = s;
14148             PL_bufptr = t+1;
14149             return newSVpvn(s, wlen);
14150         } else {
14151             PL_bufptr = s;
14152             no_label:
14153             if (flags & PARSE_OPTIONAL) {
14154                 return NULL;
14155             } else {
14156                 qerror(Perl_mess(aTHX_ "Parse error"));
14157                 return newSVpvs("x");
14158             }
14159         }
14160     }
14161 }
14162
14163 /*
14164 =for apidoc Amx|OP *|parse_fullstmt|U32 flags
14165
14166 Parse a single complete Perl statement.  This may be a normal imperative
14167 statement or a declaration that has compile-time effect, and may include
14168 an optional label.  It is up to the caller to ensure that the dynamic
14169 parser state (L</PL_parser> et al) is correctly set to reflect the source
14170 of the code to be parsed and the lexical context for the statement.
14171
14172 The op tree representing the statement is returned.  This may be a
14173 null pointer if the statement is null, for example if it was actually
14174 a subroutine definition (which has compile-time side effects).  If not
14175 null, it will be the result of a L</newSTATEOP> call, normally including
14176 a C<nextstate> or equivalent op.
14177
14178 If an error occurs in parsing or compilation, in most cases a valid op
14179 tree (most likely null) is returned anyway.  The error is reflected in
14180 the parser state, normally resulting in a single exception at the top
14181 level of parsing which covers all the compilation errors that occurred.
14182 Some compilation errors, however, will throw an exception immediately.
14183
14184 The I<flags> parameter is reserved for future use, and must always
14185 be zero.
14186
14187 =cut
14188 */
14189
14190 OP *
14191 Perl_parse_fullstmt(pTHX_ U32 flags)
14192 {
14193     if (flags)
14194         Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_fullstmt");
14195     return parse_recdescent_for_op(GRAMFULLSTMT);
14196 }
14197
14198 /*
14199 =for apidoc Amx|OP *|parse_stmtseq|U32 flags
14200
14201 Parse a sequence of zero or more Perl statements.  These may be normal
14202 imperative statements, including optional labels, or declarations
14203 that have compile-time effect, or any mixture thereof.  The statement
14204 sequence ends when a closing brace or end-of-file is encountered in a
14205 place where a new statement could have validly started.  It is up to
14206 the caller to ensure that the dynamic parser state (L</PL_parser> et al)
14207 is correctly set to reflect the source of the code to be parsed and the
14208 lexical context for the statements.
14209
14210 The op tree representing the statement sequence is returned.  This may
14211 be a null pointer if the statements were all null, for example if there
14212 were no statements or if there were only subroutine definitions (which
14213 have compile-time side effects).  If not null, it will be a C<lineseq>
14214 list, normally including C<nextstate> or equivalent ops.
14215
14216 If an error occurs in parsing or compilation, in most cases a valid op
14217 tree is returned anyway.  The error is reflected in the parser state,
14218 normally resulting in a single exception at the top level of parsing
14219 which covers all the compilation errors that occurred.  Some compilation
14220 errors, however, will throw an exception immediately.
14221
14222 The I<flags> parameter is reserved for future use, and must always
14223 be zero.
14224
14225 =cut
14226 */
14227
14228 OP *
14229 Perl_parse_stmtseq(pTHX_ U32 flags)
14230 {
14231     OP *stmtseqop;
14232     I32 c;
14233     if (flags)
14234         Perl_croak(aTHX_ "Parsing code internal error (%s)", "parse_fullstmt");
14235     stmtseqop = parse_recdescent_for_op(GRAMSTMTSEQ);
14236     c = lex_peek_unichar(0);
14237     if (c != -1 && c != /*{*/'}')
14238         qerror(Perl_mess(aTHX_ "Parse error"));
14239     return stmtseqop;
14240 }
14241
14242 void
14243 Perl_munge_qwlist_to_paren_list(pTHX_ OP *qwlist)
14244 {
14245     PERL_ARGS_ASSERT_MUNGE_QWLIST_TO_PAREN_LIST;
14246     deprecate("qw(...) as parentheses");
14247     force_next(')');
14248     if (qwlist->op_type == OP_STUB) {
14249         op_free(qwlist);
14250     }
14251     else {
14252         start_force(PL_curforce);
14253         NEXTVAL_NEXTTOKE.opval = qwlist;
14254         force_next(THING);
14255     }
14256     force_next('(');
14257 }
14258
14259 /*
14260  * Local variables:
14261  * c-indentation-style: bsd
14262  * c-basic-offset: 4
14263  * indent-tabs-mode: t
14264  * End:
14265  *
14266  * ex: set ts=8 sts=4 sw=4 noet:
14267  */