Avoid returning an undefined SV*
[p5sagit/p5-mst-13.2.git] / toke.c
1 /*    toke.c
2  *
3  *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4  *    2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others
5  *
6  *    You may distribute under the terms of either the GNU General Public
7  *    License or the Artistic License, as specified in the README file.
8  *
9  */
10
11 /*
12  *  'It all comes from here, the stench and the peril.'    --Frodo
13  *
14  *     [p.719 of _The Lord of the Rings_, IV/ix: "Shelob's Lair"]
15  */
16
17 /*
18  * This file is the lexer for Perl.  It's closely linked to the
19  * parser, perly.y.
20  *
21  * The main routine is yylex(), which returns the next token.
22  */
23
24 /*
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
43 #define new_constant(a,b,c,d,e,f,g)     \
44         S_new_constant(aTHX_ a,b,STR_WITH_LEN(c),d,e,f, g)
45
46 #define pl_yylval       (PL_parser->yylval)
47
48 /* YYINITDEPTH -- initial size of the parser's stacks.  */
49 #define YYINITDEPTH 200
50
51 /* XXX temporary backwards compatibility */
52 #define PL_lex_brackets         (PL_parser->lex_brackets)
53 #define PL_lex_brackstack       (PL_parser->lex_brackstack)
54 #define PL_lex_casemods         (PL_parser->lex_casemods)
55 #define PL_lex_casestack        (PL_parser->lex_casestack)
56 #define PL_lex_defer            (PL_parser->lex_defer)
57 #define PL_lex_dojoin           (PL_parser->lex_dojoin)
58 #define PL_lex_expect           (PL_parser->lex_expect)
59 #define PL_lex_formbrack        (PL_parser->lex_formbrack)
60 #define PL_lex_inpat            (PL_parser->lex_inpat)
61 #define PL_lex_inwhat           (PL_parser->lex_inwhat)
62 #define PL_lex_op               (PL_parser->lex_op)
63 #define PL_lex_repl             (PL_parser->lex_repl)
64 #define PL_lex_starts           (PL_parser->lex_starts)
65 #define PL_lex_stuff            (PL_parser->lex_stuff)
66 #define PL_multi_start          (PL_parser->multi_start)
67 #define PL_multi_open           (PL_parser->multi_open)
68 #define PL_multi_close          (PL_parser->multi_close)
69 #define PL_pending_ident        (PL_parser->pending_ident)
70 #define PL_preambled            (PL_parser->preambled)
71 #define PL_sublex_info          (PL_parser->sublex_info)
72 #define PL_linestr              (PL_parser->linestr)
73 #define PL_expect               (PL_parser->expect)
74 #define PL_copline              (PL_parser->copline)
75 #define PL_bufptr               (PL_parser->bufptr)
76 #define PL_oldbufptr            (PL_parser->oldbufptr)
77 #define PL_oldoldbufptr         (PL_parser->oldoldbufptr)
78 #define PL_linestart            (PL_parser->linestart)
79 #define PL_bufend               (PL_parser->bufend)
80 #define PL_last_uni             (PL_parser->last_uni)
81 #define PL_last_lop             (PL_parser->last_lop)
82 #define PL_last_lop_op          (PL_parser->last_lop_op)
83 #define PL_lex_state            (PL_parser->lex_state)
84 #define PL_rsfp                 (PL_parser->rsfp)
85 #define PL_rsfp_filters         (PL_parser->rsfp_filters)
86 #define PL_in_my                (PL_parser->in_my)
87 #define PL_in_my_stash          (PL_parser->in_my_stash)
88 #define PL_tokenbuf             (PL_parser->tokenbuf)
89 #define PL_multi_end            (PL_parser->multi_end)
90 #define PL_error_count          (PL_parser->error_count)
91
92 #ifdef PERL_MAD
93 #  define PL_endwhite           (PL_parser->endwhite)
94 #  define PL_faketokens         (PL_parser->faketokens)
95 #  define PL_lasttoke           (PL_parser->lasttoke)
96 #  define PL_nextwhite          (PL_parser->nextwhite)
97 #  define PL_realtokenstart     (PL_parser->realtokenstart)
98 #  define PL_skipwhite          (PL_parser->skipwhite)
99 #  define PL_thisclose          (PL_parser->thisclose)
100 #  define PL_thismad            (PL_parser->thismad)
101 #  define PL_thisopen           (PL_parser->thisopen)
102 #  define PL_thisstuff          (PL_parser->thisstuff)
103 #  define PL_thistoken          (PL_parser->thistoken)
104 #  define PL_thiswhite          (PL_parser->thiswhite)
105 #  define PL_thiswhite          (PL_parser->thiswhite)
106 #  define PL_nexttoke           (PL_parser->nexttoke)
107 #  define PL_curforce           (PL_parser->curforce)
108 #else
109 #  define PL_nexttoke           (PL_parser->nexttoke)
110 #  define PL_nexttype           (PL_parser->nexttype)
111 #  define PL_nextval            (PL_parser->nextval)
112 #endif
113
114 /* This can't be done with embed.fnc, because struct yy_parser contains a
115    member named pending_ident, which clashes with the generated #define  */
116 static int
117 S_pending_ident(pTHX);
118
119 static const char ident_too_long[] = "Identifier too long";
120
121 #ifdef PERL_MAD
122 #  define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
123 #  define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
124 #else
125 #  define CURMAD(slot,sv)
126 #  define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
127 #endif
128
129 #define XFAKEBRACK 128
130 #define XENUMMASK 127
131
132 #ifdef USE_UTF8_SCRIPTS
133 #   define UTF (!IN_BYTES)
134 #else
135 #   define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
136 #endif
137
138 /* The maximum number of characters preceding the unrecognized one to display */
139 #define UNRECOGNIZED_PRECEDE_COUNT 10
140
141 /* In variables named $^X, these are the legal values for X.
142  * 1999-02-27 mjd-perl-patch@plover.com */
143 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
144
145 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
146
147 /* LEX_* are values for PL_lex_state, the state of the lexer.
148  * They are arranged oddly so that the guard on the switch statement
149  * can get by with a single comparison (if the compiler is smart enough).
150  */
151
152 /* #define LEX_NOTPARSING               11 is done in perl.h. */
153
154 #define LEX_NORMAL              10 /* normal code (ie not within "...")     */
155 #define LEX_INTERPNORMAL         9 /* code within a string, eg "$foo[$x+1]" */
156 #define LEX_INTERPCASEMOD        8 /* expecting a \U, \Q or \E etc          */
157 #define LEX_INTERPPUSH           7 /* starting a new sublex parse level     */
158 #define LEX_INTERPSTART          6 /* expecting the start of a $var         */
159
160                                    /* at end of code, eg "$x" followed by:  */
161 #define LEX_INTERPEND            5 /* ... eg not one of [, { or ->          */
162 #define LEX_INTERPENDMAYBE       4 /* ... eg one of [, { or ->              */
163
164 #define LEX_INTERPCONCAT         3 /* expecting anything, eg at start of
165                                         string or after \E, $foo, etc       */
166 #define LEX_INTERPCONST          2 /* NOT USED */
167 #define LEX_FORMLINE             1 /* expecting a format line               */
168 #define LEX_KNOWNEXT             0 /* next token known; just return it      */
169
170
171 #ifdef DEBUGGING
172 static const char* const lex_state_names[] = {
173     "KNOWNEXT",
174     "FORMLINE",
175     "INTERPCONST",
176     "INTERPCONCAT",
177     "INTERPENDMAYBE",
178     "INTERPEND",
179     "INTERPSTART",
180     "INTERPPUSH",
181     "INTERPCASEMOD",
182     "INTERPNORMAL",
183     "NORMAL"
184 };
185 #endif
186
187 #ifdef ff_next
188 #undef ff_next
189 #endif
190
191 #include "keywords.h"
192
193 /* CLINE is a macro that ensures PL_copline has a sane value */
194
195 #ifdef CLINE
196 #undef CLINE
197 #endif
198 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
199
200 #ifdef PERL_MAD
201 #  define SKIPSPACE0(s) skipspace0(s)
202 #  define SKIPSPACE1(s) skipspace1(s)
203 #  define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
204 #  define PEEKSPACE(s) skipspace2(s,0)
205 #else
206 #  define SKIPSPACE0(s) skipspace(s)
207 #  define SKIPSPACE1(s) skipspace(s)
208 #  define SKIPSPACE2(s,tsv) skipspace(s)
209 #  define PEEKSPACE(s) skipspace(s)
210 #endif
211
212 /*
213  * Convenience functions to return different tokens and prime the
214  * lexer for the next token.  They all take an argument.
215  *
216  * TOKEN        : generic token (used for '(', DOLSHARP, etc)
217  * OPERATOR     : generic operator
218  * AOPERATOR    : assignment operator
219  * PREBLOCK     : beginning the block after an if, while, foreach, ...
220  * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
221  * PREREF       : *EXPR where EXPR is not a simple identifier
222  * TERM         : expression term
223  * LOOPX        : loop exiting command (goto, last, dump, etc)
224  * FTST         : file test operator
225  * FUN0         : zero-argument function
226  * FUN1         : not used, except for not, which isn't a UNIOP
227  * BOop         : bitwise or or xor
228  * BAop         : bitwise and
229  * SHop         : shift operator
230  * PWop         : power operator
231  * PMop         : pattern-matching operator
232  * Aop          : addition-level operator
233  * Mop          : multiplication-level operator
234  * Eop          : equality-testing operator
235  * Rop          : relational operator <= != gt
236  *
237  * Also see LOP and lop() below.
238  */
239
240 #ifdef DEBUGGING /* Serve -DT. */
241 #   define REPORT(retval) tokereport((I32)retval, &pl_yylval)
242 #else
243 #   define REPORT(retval) (retval)
244 #endif
245
246 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
247 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
248 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
249 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
250 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
251 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
252 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
253 #define LOOPX(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
254 #define FTST(f)  return (pl_yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
255 #define FUN0(f)  return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
256 #define FUN1(f)  return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
257 #define BOop(f)  return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
258 #define BAop(f)  return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
259 #define SHop(f)  return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
260 #define PWop(f)  return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
261 #define PMop(f)  return(pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
262 #define Aop(f)   return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
263 #define Mop(f)   return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
264 #define Eop(f)   return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
265 #define Rop(f)   return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
266
267 /* This bit of chicanery makes a unary function followed by
268  * a parenthesis into a function with one argument, highest precedence.
269  * The UNIDOR macro is for unary functions that can be followed by the //
270  * operator (such as C<shift // 0>).
271  */
272 #define UNI2(f,x) { \
273         pl_yylval.ival = f; \
274         PL_expect = x; \
275         PL_bufptr = s; \
276         PL_last_uni = PL_oldbufptr; \
277         PL_last_lop_op = f; \
278         if (*s == '(') \
279             return REPORT( (int)FUNC1 ); \
280         s = PEEKSPACE(s); \
281         return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
282         }
283 #define UNI(f)    UNI2(f,XTERM)
284 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
285
286 #define UNIBRACK(f) { \
287         pl_yylval.ival = f; \
288         PL_bufptr = s; \
289         PL_last_uni = PL_oldbufptr; \
290         if (*s == '(') \
291             return REPORT( (int)FUNC1 ); \
292         s = PEEKSPACE(s); \
293         return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
294         }
295
296 /* grandfather return to old style */
297 #define OLDLOP(f) return(pl_yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
298
299 #ifdef DEBUGGING
300
301 /* how to interpret the pl_yylval associated with the token */
302 enum token_type {
303     TOKENTYPE_NONE,
304     TOKENTYPE_IVAL,
305     TOKENTYPE_OPNUM, /* pl_yylval.ival contains an opcode number */
306     TOKENTYPE_PVAL,
307     TOKENTYPE_OPVAL,
308     TOKENTYPE_GVVAL
309 };
310
311 static struct debug_tokens {
312     const int token;
313     enum token_type type;
314     const char *name;
315 } const debug_tokens[] =
316 {
317     { ADDOP,            TOKENTYPE_OPNUM,        "ADDOP" },
318     { ANDAND,           TOKENTYPE_NONE,         "ANDAND" },
319     { ANDOP,            TOKENTYPE_NONE,         "ANDOP" },
320     { ANONSUB,          TOKENTYPE_IVAL,         "ANONSUB" },
321     { ARROW,            TOKENTYPE_NONE,         "ARROW" },
322     { ASSIGNOP,         TOKENTYPE_OPNUM,        "ASSIGNOP" },
323     { BITANDOP,         TOKENTYPE_OPNUM,        "BITANDOP" },
324     { BITOROP,          TOKENTYPE_OPNUM,        "BITOROP" },
325     { COLONATTR,        TOKENTYPE_NONE,         "COLONATTR" },
326     { CONTINUE,         TOKENTYPE_NONE,         "CONTINUE" },
327     { DEFAULT,          TOKENTYPE_NONE,         "DEFAULT" },
328     { DO,               TOKENTYPE_NONE,         "DO" },
329     { DOLSHARP,         TOKENTYPE_NONE,         "DOLSHARP" },
330     { DORDOR,           TOKENTYPE_NONE,         "DORDOR" },
331     { DOROP,            TOKENTYPE_OPNUM,        "DOROP" },
332     { DOTDOT,           TOKENTYPE_IVAL,         "DOTDOT" },
333     { ELSE,             TOKENTYPE_NONE,         "ELSE" },
334     { ELSIF,            TOKENTYPE_IVAL,         "ELSIF" },
335     { EQOP,             TOKENTYPE_OPNUM,        "EQOP" },
336     { FOR,              TOKENTYPE_IVAL,         "FOR" },
337     { FORMAT,           TOKENTYPE_NONE,         "FORMAT" },
338     { FUNC,             TOKENTYPE_OPNUM,        "FUNC" },
339     { FUNC0,            TOKENTYPE_OPNUM,        "FUNC0" },
340     { FUNC0SUB,         TOKENTYPE_OPVAL,        "FUNC0SUB" },
341     { FUNC1,            TOKENTYPE_OPNUM,        "FUNC1" },
342     { FUNCMETH,         TOKENTYPE_OPVAL,        "FUNCMETH" },
343     { GIVEN,            TOKENTYPE_IVAL,         "GIVEN" },
344     { HASHBRACK,        TOKENTYPE_NONE,         "HASHBRACK" },
345     { IF,               TOKENTYPE_IVAL,         "IF" },
346     { LABEL,            TOKENTYPE_PVAL,         "LABEL" },
347     { LOCAL,            TOKENTYPE_IVAL,         "LOCAL" },
348     { LOOPEX,           TOKENTYPE_OPNUM,        "LOOPEX" },
349     { LSTOP,            TOKENTYPE_OPNUM,        "LSTOP" },
350     { LSTOPSUB,         TOKENTYPE_OPVAL,        "LSTOPSUB" },
351     { MATCHOP,          TOKENTYPE_OPNUM,        "MATCHOP" },
352     { METHOD,           TOKENTYPE_OPVAL,        "METHOD" },
353     { MULOP,            TOKENTYPE_OPNUM,        "MULOP" },
354     { MY,               TOKENTYPE_IVAL,         "MY" },
355     { MYSUB,            TOKENTYPE_NONE,         "MYSUB" },
356     { NOAMP,            TOKENTYPE_NONE,         "NOAMP" },
357     { NOTOP,            TOKENTYPE_NONE,         "NOTOP" },
358     { OROP,             TOKENTYPE_IVAL,         "OROP" },
359     { OROR,             TOKENTYPE_NONE,         "OROR" },
360     { PACKAGE,          TOKENTYPE_NONE,         "PACKAGE" },
361     { PLUGEXPR,         TOKENTYPE_OPVAL,        "PLUGEXPR" },
362     { PLUGSTMT,         TOKENTYPE_OPVAL,        "PLUGSTMT" },
363     { PMFUNC,           TOKENTYPE_OPVAL,        "PMFUNC" },
364     { POSTDEC,          TOKENTYPE_NONE,         "POSTDEC" },
365     { POSTINC,          TOKENTYPE_NONE,         "POSTINC" },
366     { POWOP,            TOKENTYPE_OPNUM,        "POWOP" },
367     { PREDEC,           TOKENTYPE_NONE,         "PREDEC" },
368     { PREINC,           TOKENTYPE_NONE,         "PREINC" },
369     { PRIVATEREF,       TOKENTYPE_OPVAL,        "PRIVATEREF" },
370     { REFGEN,           TOKENTYPE_NONE,         "REFGEN" },
371     { RELOP,            TOKENTYPE_OPNUM,        "RELOP" },
372     { SHIFTOP,          TOKENTYPE_OPNUM,        "SHIFTOP" },
373     { SUB,              TOKENTYPE_NONE,         "SUB" },
374     { THING,            TOKENTYPE_OPVAL,        "THING" },
375     { UMINUS,           TOKENTYPE_NONE,         "UMINUS" },
376     { UNIOP,            TOKENTYPE_OPNUM,        "UNIOP" },
377     { UNIOPSUB,         TOKENTYPE_OPVAL,        "UNIOPSUB" },
378     { UNLESS,           TOKENTYPE_IVAL,         "UNLESS" },
379     { UNTIL,            TOKENTYPE_IVAL,         "UNTIL" },
380     { USE,              TOKENTYPE_IVAL,         "USE" },
381     { WHEN,             TOKENTYPE_IVAL,         "WHEN" },
382     { WHILE,            TOKENTYPE_IVAL,         "WHILE" },
383     { WORD,             TOKENTYPE_OPVAL,        "WORD" },
384     { YADAYADA,         TOKENTYPE_IVAL,         "YADAYADA" },
385     { 0,                TOKENTYPE_NONE,         NULL }
386 };
387
388 /* dump the returned token in rv, plus any optional arg in pl_yylval */
389
390 STATIC int
391 S_tokereport(pTHX_ I32 rv, const YYSTYPE* lvalp)
392 {
393     dVAR;
394
395     PERL_ARGS_ASSERT_TOKEREPORT;
396
397     if (DEBUG_T_TEST) {
398         const char *name = NULL;
399         enum token_type type = TOKENTYPE_NONE;
400         const struct debug_tokens *p;
401         SV* const report = newSVpvs("<== ");
402
403         for (p = debug_tokens; p->token; p++) {
404             if (p->token == (int)rv) {
405                 name = p->name;
406                 type = p->type;
407                 break;
408             }
409         }
410         if (name)
411             Perl_sv_catpv(aTHX_ report, name);
412         else if ((char)rv > ' ' && (char)rv < '~')
413             Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
414         else if (!rv)
415             sv_catpvs(report, "EOF");
416         else
417             Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
418         switch (type) {
419         case TOKENTYPE_NONE:
420         case TOKENTYPE_GVVAL: /* doesn't appear to be used */
421             break;
422         case TOKENTYPE_IVAL:
423             Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)lvalp->ival);
424             break;
425         case TOKENTYPE_OPNUM:
426             Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
427                                     PL_op_name[lvalp->ival]);
428             break;
429         case TOKENTYPE_PVAL:
430             Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", lvalp->pval);
431             break;
432         case TOKENTYPE_OPVAL:
433             if (lvalp->opval) {
434                 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
435                                     PL_op_name[lvalp->opval->op_type]);
436                 if (lvalp->opval->op_type == OP_CONST) {
437                     Perl_sv_catpvf(aTHX_ report, " %s",
438                         SvPEEK(cSVOPx_sv(lvalp->opval)));
439                 }
440
441             }
442             else
443                 sv_catpvs(report, "(opval=null)");
444             break;
445         }
446         PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
447     };
448     return (int)rv;
449 }
450
451
452 /* print the buffer with suitable escapes */
453
454 STATIC void
455 S_printbuf(pTHX_ const char *const fmt, const char *const s)
456 {
457     SV* const tmp = newSVpvs("");
458
459     PERL_ARGS_ASSERT_PRINTBUF;
460
461     PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
462     SvREFCNT_dec(tmp);
463 }
464
465 #endif
466
467 static int
468 S_deprecate_commaless_var_list(pTHX) {
469     PL_expect = XTERM;
470     deprecate("comma-less variable list");
471     return REPORT(','); /* grandfather non-comma-format format */
472 }
473
474 /*
475  * S_ao
476  *
477  * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
478  * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
479  */
480
481 STATIC int
482 S_ao(pTHX_ int toketype)
483 {
484     dVAR;
485     if (*PL_bufptr == '=') {
486         PL_bufptr++;
487         if (toketype == ANDAND)
488             pl_yylval.ival = OP_ANDASSIGN;
489         else if (toketype == OROR)
490             pl_yylval.ival = OP_ORASSIGN;
491         else if (toketype == DORDOR)
492             pl_yylval.ival = OP_DORASSIGN;
493         toketype = ASSIGNOP;
494     }
495     return toketype;
496 }
497
498 /*
499  * S_no_op
500  * When Perl expects an operator and finds something else, no_op
501  * prints the warning.  It always prints "<something> found where
502  * operator expected.  It prints "Missing semicolon on previous line?"
503  * if the surprise occurs at the start of the line.  "do you need to
504  * predeclare ..." is printed out for code like "sub bar; foo bar $x"
505  * where the compiler doesn't know if foo is a method call or a function.
506  * It prints "Missing operator before end of line" if there's nothing
507  * after the missing operator, or "... before <...>" if there is something
508  * after the missing operator.
509  */
510
511 STATIC void
512 S_no_op(pTHX_ const char *const what, char *s)
513 {
514     dVAR;
515     char * const oldbp = PL_bufptr;
516     const bool is_first = (PL_oldbufptr == PL_linestart);
517
518     PERL_ARGS_ASSERT_NO_OP;
519
520     if (!s)
521         s = oldbp;
522     else
523         PL_bufptr = s;
524     yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
525     if (ckWARN_d(WARN_SYNTAX)) {
526         if (is_first)
527             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
528                     "\t(Missing semicolon on previous line?)\n");
529         else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
530             const char *t;
531             for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
532                 NOOP;
533             if (t < PL_bufptr && isSPACE(*t))
534                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
535                         "\t(Do you need to predeclare %.*s?)\n",
536                     (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
537         }
538         else {
539             assert(s >= oldbp);
540             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
541                     "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
542         }
543     }
544     PL_bufptr = oldbp;
545 }
546
547 /*
548  * S_missingterm
549  * Complain about missing quote/regexp/heredoc terminator.
550  * If it's called with NULL then it cauterizes the line buffer.
551  * If we're in a delimited string and the delimiter is a control
552  * character, it's reformatted into a two-char sequence like ^C.
553  * This is fatal.
554  */
555
556 STATIC void
557 S_missingterm(pTHX_ char *s)
558 {
559     dVAR;
560     char tmpbuf[3];
561     char q;
562     if (s) {
563         char * const nl = strrchr(s,'\n');
564         if (nl)
565             *nl = '\0';
566     }
567     else if (isCNTRL(PL_multi_close)) {
568         *tmpbuf = '^';
569         tmpbuf[1] = (char)toCTRL(PL_multi_close);
570         tmpbuf[2] = '\0';
571         s = tmpbuf;
572     }
573     else {
574         *tmpbuf = (char)PL_multi_close;
575         tmpbuf[1] = '\0';
576         s = tmpbuf;
577     }
578     q = strchr(s,'"') ? '\'' : '"';
579     Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
580 }
581
582 #define FEATURE_IS_ENABLED(name)                                        \
583         ((0 != (PL_hints & HINT_LOCALIZE_HH))                           \
584             && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
585 /* The longest string we pass in.  */
586 #define MAX_FEATURE_LEN (sizeof("unicode_strings")-1)
587
588 /*
589  * S_feature_is_enabled
590  * Check whether the named feature is enabled.
591  */
592 STATIC bool
593 S_feature_is_enabled(pTHX_ const char *const name, STRLEN namelen)
594 {
595     dVAR;
596     HV * const hinthv = GvHV(PL_hintgv);
597     char he_name[8 + MAX_FEATURE_LEN] = "feature_";
598
599     PERL_ARGS_ASSERT_FEATURE_IS_ENABLED;
600
601     assert(namelen <= MAX_FEATURE_LEN);
602     memcpy(&he_name[8], name, namelen);
603
604     return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
605 }
606
607 /*
608  * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
609  * utf16-to-utf8-reversed.
610  */
611
612 #ifdef PERL_CR_FILTER
613 static void
614 strip_return(SV *sv)
615 {
616     register const char *s = SvPVX_const(sv);
617     register const char * const e = s + SvCUR(sv);
618
619     PERL_ARGS_ASSERT_STRIP_RETURN;
620
621     /* outer loop optimized to do nothing if there are no CR-LFs */
622     while (s < e) {
623         if (*s++ == '\r' && *s == '\n') {
624             /* hit a CR-LF, need to copy the rest */
625             register char *d = s - 1;
626             *d++ = *s++;
627             while (s < e) {
628                 if (*s == '\r' && s[1] == '\n')
629                     s++;
630                 *d++ = *s++;
631             }
632             SvCUR(sv) -= s - d;
633             return;
634         }
635     }
636 }
637
638 STATIC I32
639 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
640 {
641     const I32 count = FILTER_READ(idx+1, sv, maxlen);
642     if (count > 0 && !maxlen)
643         strip_return(sv);
644     return count;
645 }
646 #endif
647
648
649
650 /*
651  * Perl_lex_start
652  *
653  * Create a parser object and initialise its parser and lexer fields
654  *
655  * rsfp       is the opened file handle to read from (if any),
656  *
657  * line       holds any initial content already read from the file (or in
658  *            the case of no file, such as an eval, the whole contents);
659  *
660  * new_filter indicates that this is a new file and it shouldn't inherit
661  *            the filters from the current parser (ie require).
662  */
663
664 void
665 Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, bool new_filter)
666 {
667     dVAR;
668     const char *s = NULL;
669     STRLEN len;
670     yy_parser *parser, *oparser;
671
672     /* create and initialise a parser */
673
674     Newxz(parser, 1, yy_parser);
675     parser->old_parser = oparser = PL_parser;
676     PL_parser = parser;
677
678     Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
679     parser->ps = parser->stack;
680     parser->stack_size = YYINITDEPTH;
681
682     parser->stack->state = 0;
683     parser->yyerrstatus = 0;
684     parser->yychar = YYEMPTY;           /* Cause a token to be read.  */
685
686     /* on scope exit, free this parser and restore any outer one */
687     SAVEPARSER(parser);
688     parser->saved_curcop = PL_curcop;
689
690     /* initialise lexer state */
691
692 #ifdef PERL_MAD
693     parser->curforce = -1;
694 #else
695     parser->nexttoke = 0;
696 #endif
697     parser->error_count = oparser ? oparser->error_count : 0;
698     parser->copline = NOLINE;
699     parser->lex_state = LEX_NORMAL;
700     parser->expect = XSTATE;
701     parser->rsfp = rsfp;
702     parser->rsfp_filters = (new_filter || !oparser) ? newAV()
703                 : MUTABLE_AV(SvREFCNT_inc(oparser->rsfp_filters));
704
705     Newx(parser->lex_brackstack, 120, char);
706     Newx(parser->lex_casestack, 12, char);
707     *parser->lex_casestack = '\0';
708
709     if (line) {
710         s = SvPV_const(line, len);
711     } else {
712         len = 0;
713     }
714
715     if (!len) {
716         parser->linestr = newSVpvs("\n;");
717     } else if (SvREADONLY(line) || s[len-1] != ';') {
718         parser->linestr = newSVsv(line);
719         if (s[len-1] != ';')
720             sv_catpvs(parser->linestr, "\n;");
721     } else {
722         SvTEMP_off(line);
723         SvREFCNT_inc_simple_void_NN(line);
724         parser->linestr = line;
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
734
735 /* delete a parser object */
736
737 void
738 Perl_parser_free(pTHX_  const yy_parser *parser)
739 {
740     PERL_ARGS_ASSERT_PARSER_FREE;
741
742     PL_curcop = parser->saved_curcop;
743     SvREFCNT_dec(parser->linestr);
744
745     if (parser->rsfp == PerlIO_stdin())
746         PerlIO_clearerr(parser->rsfp);
747     else if (parser->rsfp && (!parser->old_parser ||
748                 (parser->old_parser && parser->rsfp != parser->old_parser->rsfp)))
749         PerlIO_close(parser->rsfp);
750     SvREFCNT_dec(parser->rsfp_filters);
751
752     Safefree(parser->stack);
753     Safefree(parser->lex_brackstack);
754     Safefree(parser->lex_casestack);
755     PL_parser = parser->old_parser;
756     Safefree(parser);
757 }
758
759
760 /*
761  * Perl_lex_end
762  * Finalizer for lexing operations.  Must be called when the parser is
763  * done with the lexer.
764  */
765
766 void
767 Perl_lex_end(pTHX)
768 {
769     dVAR;
770     PL_doextract = FALSE;
771 }
772
773 /*
774 =for apidoc AmxU|SV *|PL_parser-E<gt>linestr
775
776 Buffer scalar containing the chunk currently under consideration of the
777 text currently being lexed.  This is always a plain string scalar (for
778 which C<SvPOK> is true).  It is not intended to be used as a scalar by
779 normal scalar means; instead refer to the buffer directly by the pointer
780 variables described below.
781
782 The lexer maintains various C<char*> pointers to things in the
783 C<PL_parser-E<gt>linestr> buffer.  If C<PL_parser-E<gt>linestr> is ever
784 reallocated, all of these pointers must be updated.  Don't attempt to
785 do this manually, but rather use L</lex_grow_linestr> if you need to
786 reallocate the buffer.
787
788 The content of the text chunk in the buffer is commonly exactly one
789 complete line of input, up to and including a newline terminator,
790 but there are situations where it is otherwise.  The octets of the
791 buffer may be intended to be interpreted as either UTF-8 or Latin-1.
792 The function L</lex_bufutf8> tells you which.  Do not use the C<SvUTF8>
793 flag on this scalar, which may disagree with it.
794
795 For direct examination of the buffer, the variable
796 L</PL_parser-E<gt>bufend> points to the end of the buffer.  The current
797 lexing position is pointed to by L</PL_parser-E<gt>bufptr>.  Direct use
798 of these pointers is usually preferable to examination of the scalar
799 through normal scalar means.
800
801 =for apidoc AmxU|char *|PL_parser-E<gt>bufend
802
803 Direct pointer to the end of the chunk of text currently being lexed, the
804 end of the lexer buffer.  This is equal to C<SvPVX(PL_parser-E<gt>linestr)
805 + SvCUR(PL_parser-E<gt>linestr)>.  A NUL character (zero octet) is
806 always located at the end of the buffer, and does not count as part of
807 the buffer's contents.
808
809 =for apidoc AmxU|char *|PL_parser-E<gt>bufptr
810
811 Points to the current position of lexing inside the lexer buffer.
812 Characters around this point may be freely examined, within
813 the range delimited by C<SvPVX(L</PL_parser-E<gt>linestr>)> and
814 L</PL_parser-E<gt>bufend>.  The octets of the buffer may be intended to be
815 interpreted as either UTF-8 or Latin-1, as indicated by L</lex_bufutf8>.
816
817 Lexing code (whether in the Perl core or not) moves this pointer past
818 the characters that it consumes.  It is also expected to perform some
819 bookkeeping whenever a newline character is consumed.  This movement
820 can be more conveniently performed by the function L</lex_read_to>,
821 which handles newlines appropriately.
822
823 Interpretation of the buffer's octets can be abstracted out by
824 using the slightly higher-level functions L</lex_peek_unichar> and
825 L</lex_read_unichar>.
826
827 =for apidoc AmxU|char *|PL_parser-E<gt>linestart
828
829 Points to the start of the current line inside the lexer buffer.
830 This is useful for indicating at which column an error occurred, and
831 not much else.  This must be updated by any lexing code that consumes
832 a newline; the function L</lex_read_to> handles this detail.
833
834 =cut
835 */
836
837 /*
838 =for apidoc Amx|bool|lex_bufutf8
839
840 Indicates whether the octets in the lexer buffer
841 (L</PL_parser-E<gt>linestr>) should be interpreted as the UTF-8 encoding
842 of Unicode characters.  If not, they should be interpreted as Latin-1
843 characters.  This is analogous to the C<SvUTF8> flag for scalars.
844
845 In UTF-8 mode, it is not guaranteed that the lexer buffer actually
846 contains valid UTF-8.  Lexing code must be robust in the face of invalid
847 encoding.
848
849 The actual C<SvUTF8> flag of the L</PL_parser-E<gt>linestr> scalar
850 is significant, but not the whole story regarding the input character
851 encoding.  Normally, when a file is being read, the scalar contains octets
852 and its C<SvUTF8> flag is off, but the octets should be interpreted as
853 UTF-8 if the C<use utf8> pragma is in effect.  During a string eval,
854 however, the scalar may have the C<SvUTF8> flag on, and in this case its
855 octets should be interpreted as UTF-8 unless the C<use bytes> pragma
856 is in effect.  This logic may change in the future; use this function
857 instead of implementing the logic yourself.
858
859 =cut
860 */
861
862 bool
863 Perl_lex_bufutf8(pTHX)
864 {
865     return UTF;
866 }
867
868 /*
869 =for apidoc Amx|char *|lex_grow_linestr|STRLEN len
870
871 Reallocates the lexer buffer (L</PL_parser-E<gt>linestr>) to accommodate
872 at least I<len> octets (including terminating NUL).  Returns a
873 pointer to the reallocated buffer.  This is necessary before making
874 any direct modification of the buffer that would increase its length.
875 L</lex_stuff_pvn> provides a more convenient way to insert text into
876 the buffer.
877
878 Do not use C<SvGROW> or C<sv_grow> directly on C<PL_parser-E<gt>linestr>;
879 this function updates all of the lexer's variables that point directly
880 into the buffer.
881
882 =cut
883 */
884
885 char *
886 Perl_lex_grow_linestr(pTHX_ STRLEN len)
887 {
888     SV *linestr;
889     char *buf;
890     STRLEN bufend_pos, bufptr_pos, oldbufptr_pos, oldoldbufptr_pos;
891     STRLEN linestart_pos, last_uni_pos, last_lop_pos;
892     linestr = PL_parser->linestr;
893     buf = SvPVX(linestr);
894     if (len <= SvLEN(linestr))
895         return buf;
896     bufend_pos = PL_parser->bufend - buf;
897     bufptr_pos = PL_parser->bufptr - buf;
898     oldbufptr_pos = PL_parser->oldbufptr - buf;
899     oldoldbufptr_pos = PL_parser->oldoldbufptr - buf;
900     linestart_pos = PL_parser->linestart - buf;
901     last_uni_pos = PL_parser->last_uni ? PL_parser->last_uni - buf : 0;
902     last_lop_pos = PL_parser->last_lop ? PL_parser->last_lop - buf : 0;
903     buf = sv_grow(linestr, len);
904     PL_parser->bufend = buf + bufend_pos;
905     PL_parser->bufptr = buf + bufptr_pos;
906     PL_parser->oldbufptr = buf + oldbufptr_pos;
907     PL_parser->oldoldbufptr = buf + oldoldbufptr_pos;
908     PL_parser->linestart = buf + linestart_pos;
909     if (PL_parser->last_uni)
910         PL_parser->last_uni = buf + last_uni_pos;
911     if (PL_parser->last_lop)
912         PL_parser->last_lop = buf + last_lop_pos;
913     return buf;
914 }
915
916 /*
917 =for apidoc Amx|void|lex_stuff_pvn|char *pv|STRLEN len|U32 flags
918
919 Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>),
920 immediately after the current lexing point (L</PL_parser-E<gt>bufptr>),
921 reallocating the buffer if necessary.  This means that lexing code that
922 runs later will see the characters as if they had appeared in the input.
923 It is not recommended to do this as part of normal parsing, and most
924 uses of this facility run the risk of the inserted characters being
925 interpreted in an unintended manner.
926
927 The string to be inserted is represented by I<len> octets starting
928 at I<pv>.  These octets are interpreted as either UTF-8 or Latin-1,
929 according to whether the C<LEX_STUFF_UTF8> flag is set in I<flags>.
930 The characters are recoded for the lexer buffer, according to how the
931 buffer is currently being interpreted (L</lex_bufutf8>).  If a string
932 to be interpreted is available as a Perl scalar, the L</lex_stuff_sv>
933 function is more convenient.
934
935 =cut
936 */
937
938 void
939 Perl_lex_stuff_pvn(pTHX_ char *pv, STRLEN len, U32 flags)
940 {
941     char *bufptr;
942     PERL_ARGS_ASSERT_LEX_STUFF_PVN;
943     if (flags & ~(LEX_STUFF_UTF8))
944         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_stuff_pvn");
945     if (UTF) {
946         if (flags & LEX_STUFF_UTF8) {
947             goto plain_copy;
948         } else {
949             STRLEN highhalf = 0;
950             char *p, *e = pv+len;
951             for (p = pv; p != e; p++)
952                 highhalf += !!(((U8)*p) & 0x80);
953             if (!highhalf)
954                 goto plain_copy;
955             lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len+highhalf);
956             bufptr = PL_parser->bufptr;
957             Move(bufptr, bufptr+len+highhalf, PL_parser->bufend+1-bufptr, char);
958             PL_parser->bufend += len+highhalf;
959             for (p = pv; p != e; p++) {
960                 U8 c = (U8)*p;
961                 if (c & 0x80) {
962                     *bufptr++ = (char)(0xc0 | (c >> 6));
963                     *bufptr++ = (char)(0x80 | (c & 0x3f));
964                 } else {
965                     *bufptr++ = (char)c;
966                 }
967             }
968         }
969     } else {
970         if (flags & LEX_STUFF_UTF8) {
971             STRLEN highhalf = 0;
972             char *p, *e = pv+len;
973             for (p = pv; p != e; p++) {
974                 U8 c = (U8)*p;
975                 if (c >= 0xc4) {
976                     Perl_croak(aTHX_ "Lexing code attempted to stuff "
977                                 "non-Latin-1 character into Latin-1 input");
978                 } else if (c >= 0xc2 && p+1 != e &&
979                             (((U8)p[1]) & 0xc0) == 0x80) {
980                     p++;
981                     highhalf++;
982                 } else if (c >= 0x80) {
983                     /* malformed UTF-8 */
984                     ENTER;
985                     SAVESPTR(PL_warnhook);
986                     PL_warnhook = PERL_WARNHOOK_FATAL;
987                     utf8n_to_uvuni((U8*)p, e-p, NULL, 0);
988                     LEAVE;
989                 }
990             }
991             if (!highhalf)
992                 goto plain_copy;
993             lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len-highhalf);
994             bufptr = PL_parser->bufptr;
995             Move(bufptr, bufptr+len-highhalf, PL_parser->bufend+1-bufptr, char);
996             PL_parser->bufend += len-highhalf;
997             for (p = pv; p != e; p++) {
998                 U8 c = (U8)*p;
999                 if (c & 0x80) {
1000                     *bufptr++ = (char)(((c & 0x3) << 6) | (p[1] & 0x3f));
1001                     p++;
1002                 } else {
1003                     *bufptr++ = (char)c;
1004                 }
1005             }
1006         } else {
1007             plain_copy:
1008             lex_grow_linestr(SvCUR(PL_parser->linestr)+1+len);
1009             bufptr = PL_parser->bufptr;
1010             Move(bufptr, bufptr+len, PL_parser->bufend+1-bufptr, char);
1011             PL_parser->bufend += len;
1012             Copy(pv, bufptr, len, char);
1013         }
1014     }
1015 }
1016
1017 /*
1018 =for apidoc Amx|void|lex_stuff_sv|SV *sv|U32 flags
1019
1020 Insert characters into the lexer buffer (L</PL_parser-E<gt>linestr>),
1021 immediately after the current lexing point (L</PL_parser-E<gt>bufptr>),
1022 reallocating the buffer if necessary.  This means that lexing code that
1023 runs later will see the characters as if they had appeared in the input.
1024 It is not recommended to do this as part of normal parsing, and most
1025 uses of this facility run the risk of the inserted characters being
1026 interpreted in an unintended manner.
1027
1028 The string to be inserted is the string value of I<sv>.  The characters
1029 are recoded for the lexer buffer, according to how the buffer is currently
1030 being interpreted (L</lex_bufutf8>).  If a string to be interpreted is
1031 not already a Perl scalar, the L</lex_stuff_pvn> function avoids the
1032 need to construct a scalar.
1033
1034 =cut
1035 */
1036
1037 void
1038 Perl_lex_stuff_sv(pTHX_ SV *sv, U32 flags)
1039 {
1040     char *pv;
1041     STRLEN len;
1042     PERL_ARGS_ASSERT_LEX_STUFF_SV;
1043     if (flags)
1044         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_stuff_sv");
1045     pv = SvPV(sv, len);
1046     lex_stuff_pvn(pv, len, flags | (SvUTF8(sv) ? LEX_STUFF_UTF8 : 0));
1047 }
1048
1049 /*
1050 =for apidoc Amx|void|lex_unstuff|char *ptr
1051
1052 Discards text about to be lexed, from L</PL_parser-E<gt>bufptr> up to
1053 I<ptr>.  Text following I<ptr> will be moved, and the buffer shortened.
1054 This hides the discarded text from any lexing code that runs later,
1055 as if the text had never appeared.
1056
1057 This is not the normal way to consume lexed text.  For that, use
1058 L</lex_read_to>.
1059
1060 =cut
1061 */
1062
1063 void
1064 Perl_lex_unstuff(pTHX_ char *ptr)
1065 {
1066     char *buf, *bufend;
1067     STRLEN unstuff_len;
1068     PERL_ARGS_ASSERT_LEX_UNSTUFF;
1069     buf = PL_parser->bufptr;
1070     if (ptr < buf)
1071         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_unstuff");
1072     if (ptr == buf)
1073         return;
1074     bufend = PL_parser->bufend;
1075     if (ptr > bufend)
1076         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_unstuff");
1077     unstuff_len = ptr - buf;
1078     Move(ptr, buf, bufend+1-ptr, char);
1079     SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) - unstuff_len);
1080     PL_parser->bufend = bufend - unstuff_len;
1081 }
1082
1083 /*
1084 =for apidoc Amx|void|lex_read_to|char *ptr
1085
1086 Consume text in the lexer buffer, from L</PL_parser-E<gt>bufptr> up
1087 to I<ptr>.  This advances L</PL_parser-E<gt>bufptr> to match I<ptr>,
1088 performing the correct bookkeeping whenever a newline character is passed.
1089 This is the normal way to consume lexed text.
1090
1091 Interpretation of the buffer's octets can be abstracted out by
1092 using the slightly higher-level functions L</lex_peek_unichar> and
1093 L</lex_read_unichar>.
1094
1095 =cut
1096 */
1097
1098 void
1099 Perl_lex_read_to(pTHX_ char *ptr)
1100 {
1101     char *s;
1102     PERL_ARGS_ASSERT_LEX_READ_TO;
1103     s = PL_parser->bufptr;
1104     if (ptr < s || ptr > PL_parser->bufend)
1105         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_to");
1106     for (; s != ptr; s++)
1107         if (*s == '\n') {
1108             CopLINE_inc(PL_curcop);
1109             PL_parser->linestart = s+1;
1110         }
1111     PL_parser->bufptr = ptr;
1112 }
1113
1114 /*
1115 =for apidoc Amx|void|lex_discard_to|char *ptr
1116
1117 Discards the first part of the L</PL_parser-E<gt>linestr> buffer,
1118 up to I<ptr>.  The remaining content of the buffer will be moved, and
1119 all pointers into the buffer updated appropriately.  I<ptr> must not
1120 be later in the buffer than the position of L</PL_parser-E<gt>bufptr>:
1121 it is not permitted to discard text that has yet to be lexed.
1122
1123 Normally it is not necessarily to do this directly, because it suffices to
1124 use the implicit discarding behaviour of L</lex_next_chunk> and things
1125 based on it.  However, if a token stretches across multiple lines,
1126 and the lexing code has kept multiple lines of text in the buffer fof
1127 that purpose, then after completion of the token it would be wise to
1128 explicitly discard the now-unneeded earlier lines, to avoid future
1129 multi-line tokens growing the buffer without bound.
1130
1131 =cut
1132 */
1133
1134 void
1135 Perl_lex_discard_to(pTHX_ char *ptr)
1136 {
1137     char *buf;
1138     STRLEN discard_len;
1139     PERL_ARGS_ASSERT_LEX_DISCARD_TO;
1140     buf = SvPVX(PL_parser->linestr);
1141     if (ptr < buf)
1142         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_discard_to");
1143     if (ptr == buf)
1144         return;
1145     if (ptr > PL_parser->bufptr)
1146         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_discard_to");
1147     discard_len = ptr - buf;
1148     if (PL_parser->oldbufptr < ptr)
1149         PL_parser->oldbufptr = ptr;
1150     if (PL_parser->oldoldbufptr < ptr)
1151         PL_parser->oldoldbufptr = ptr;
1152     if (PL_parser->last_uni && PL_parser->last_uni < ptr)
1153         PL_parser->last_uni = NULL;
1154     if (PL_parser->last_lop && PL_parser->last_lop < ptr)
1155         PL_parser->last_lop = NULL;
1156     Move(ptr, buf, PL_parser->bufend+1-ptr, char);
1157     SvCUR_set(PL_parser->linestr, SvCUR(PL_parser->linestr) - discard_len);
1158     PL_parser->bufend -= discard_len;
1159     PL_parser->bufptr -= discard_len;
1160     PL_parser->oldbufptr -= discard_len;
1161     PL_parser->oldoldbufptr -= discard_len;
1162     if (PL_parser->last_uni)
1163         PL_parser->last_uni -= discard_len;
1164     if (PL_parser->last_lop)
1165         PL_parser->last_lop -= discard_len;
1166 }
1167
1168 /*
1169 =for apidoc Amx|bool|lex_next_chunk|U32 flags
1170
1171 Reads in the next chunk of text to be lexed, appending it to
1172 L</PL_parser-E<gt>linestr>.  This should be called when lexing code has
1173 looked to the end of the current chunk and wants to know more.  It is
1174 usual, but not necessary, for lexing to have consumed the entirety of
1175 the current chunk at this time.
1176
1177 If L</PL_parser-E<gt>bufptr> is pointing to the very end of the current
1178 chunk (i.e., the current chunk has been entirely consumed), normally the
1179 current chunk will be discarded at the same time that the new chunk is
1180 read in.  If I<flags> includes C<LEX_KEEP_PREVIOUS>, the current chunk
1181 will not be discarded.  If the current chunk has not been entirely
1182 consumed, then it will not be discarded regardless of the flag.
1183
1184 Returns true if some new text was added to the buffer, or false if the
1185 buffer has reached the end of the input text.
1186
1187 =cut
1188 */
1189
1190 #define LEX_FAKE_EOF 0x80000000
1191
1192 bool
1193 Perl_lex_next_chunk(pTHX_ U32 flags)
1194 {
1195     SV *linestr;
1196     char *buf;
1197     STRLEN old_bufend_pos, new_bufend_pos;
1198     STRLEN bufptr_pos, oldbufptr_pos, oldoldbufptr_pos;
1199     STRLEN linestart_pos, last_uni_pos, last_lop_pos;
1200     bool got_some_for_debugger = 0;
1201     bool got_some;
1202     if (flags & ~(LEX_KEEP_PREVIOUS|LEX_FAKE_EOF))
1203         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_next_chunk");
1204     linestr = PL_parser->linestr;
1205     buf = SvPVX(linestr);
1206     if (!(flags & LEX_KEEP_PREVIOUS) &&
1207             PL_parser->bufptr == PL_parser->bufend) {
1208         old_bufend_pos = bufptr_pos = oldbufptr_pos = oldoldbufptr_pos = 0;
1209         linestart_pos = 0;
1210         if (PL_parser->last_uni != PL_parser->bufend)
1211             PL_parser->last_uni = NULL;
1212         if (PL_parser->last_lop != PL_parser->bufend)
1213             PL_parser->last_lop = NULL;
1214         last_uni_pos = last_lop_pos = 0;
1215         *buf = 0;
1216         SvCUR(linestr) = 0;
1217     } else {
1218         old_bufend_pos = PL_parser->bufend - buf;
1219         bufptr_pos = PL_parser->bufptr - buf;
1220         oldbufptr_pos = PL_parser->oldbufptr - buf;
1221         oldoldbufptr_pos = PL_parser->oldoldbufptr - buf;
1222         linestart_pos = PL_parser->linestart - buf;
1223         last_uni_pos = PL_parser->last_uni ? PL_parser->last_uni - buf : 0;
1224         last_lop_pos = PL_parser->last_lop ? PL_parser->last_lop - buf : 0;
1225     }
1226     if (flags & LEX_FAKE_EOF) {
1227         goto eof;
1228     } else if (!PL_parser->rsfp) {
1229         got_some = 0;
1230     } else if (filter_gets(linestr, old_bufend_pos)) {
1231         got_some = 1;
1232         got_some_for_debugger = 1;
1233     } else {
1234         if (!SvPOK(linestr))   /* can get undefined by filter_gets */
1235             sv_setpvs(linestr, "");
1236         eof:
1237         /* End of real input.  Close filehandle (unless it was STDIN),
1238          * then add implicit termination.
1239          */
1240         if ((PerlIO*)PL_parser->rsfp == PerlIO_stdin())
1241             PerlIO_clearerr(PL_parser->rsfp);
1242         else if (PL_parser->rsfp)
1243             (void)PerlIO_close(PL_parser->rsfp);
1244         PL_parser->rsfp = NULL;
1245         PL_doextract = FALSE;
1246 #ifdef PERL_MAD
1247         if (PL_madskills && !PL_in_eval && (PL_minus_p || PL_minus_n))
1248             PL_faketokens = 1;
1249 #endif
1250         if (!PL_in_eval && PL_minus_p) {
1251             sv_catpvs(linestr,
1252                 /*{*/";}continue{print or die qq(-p destination: $!\\n);}");
1253             PL_minus_n = PL_minus_p = 0;
1254         } else if (!PL_in_eval && PL_minus_n) {
1255             sv_catpvs(linestr, /*{*/";}");
1256             PL_minus_n = 0;
1257         } else
1258             sv_catpvs(linestr, ";");
1259         got_some = 1;
1260     }
1261     buf = SvPVX(linestr);
1262     new_bufend_pos = SvCUR(linestr);
1263     PL_parser->bufend = buf + new_bufend_pos;
1264     PL_parser->bufptr = buf + bufptr_pos;
1265     PL_parser->oldbufptr = buf + oldbufptr_pos;
1266     PL_parser->oldoldbufptr = buf + oldoldbufptr_pos;
1267     PL_parser->linestart = buf + linestart_pos;
1268     if (PL_parser->last_uni)
1269         PL_parser->last_uni = buf + last_uni_pos;
1270     if (PL_parser->last_lop)
1271         PL_parser->last_lop = buf + last_lop_pos;
1272     if (got_some_for_debugger && (PERLDB_LINE || PERLDB_SAVESRC) &&
1273             PL_curstash != PL_debstash) {
1274         /* debugger active and we're not compiling the debugger code,
1275          * so store the line into the debugger's array of lines
1276          */
1277         update_debugger_info(NULL, buf+old_bufend_pos,
1278             new_bufend_pos-old_bufend_pos);
1279     }
1280     return got_some;
1281 }
1282
1283 /*
1284 =for apidoc Amx|I32|lex_peek_unichar|U32 flags
1285
1286 Looks ahead one (Unicode) character in the text currently being lexed.
1287 Returns the codepoint (unsigned integer value) of the next character,
1288 or -1 if lexing has reached the end of the input text.  To consume the
1289 peeked character, use L</lex_read_unichar>.
1290
1291 If the next character is in (or extends into) the next chunk of input
1292 text, the next chunk will be read in.  Normally the current chunk will be
1293 discarded at the same time, but if I<flags> includes C<LEX_KEEP_PREVIOUS>
1294 then the current chunk will not be discarded.
1295
1296 If the input is being interpreted as UTF-8 and a UTF-8 encoding error
1297 is encountered, an exception is generated.
1298
1299 =cut
1300 */
1301
1302 I32
1303 Perl_lex_peek_unichar(pTHX_ U32 flags)
1304 {
1305     char *s, *bufend;
1306     if (flags & ~(LEX_KEEP_PREVIOUS))
1307         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_peek_unichar");
1308     s = PL_parser->bufptr;
1309     bufend = PL_parser->bufend;
1310     if (UTF) {
1311         U8 head;
1312         I32 unichar;
1313         STRLEN len, retlen;
1314         if (s == bufend) {
1315             if (!lex_next_chunk(flags))
1316                 return -1;
1317             s = PL_parser->bufptr;
1318             bufend = PL_parser->bufend;
1319         }
1320         head = (U8)*s;
1321         if (!(head & 0x80))
1322             return head;
1323         if (head & 0x40) {
1324             len = PL_utf8skip[head];
1325             while ((STRLEN)(bufend-s) < len) {
1326                 if (!lex_next_chunk(flags | LEX_KEEP_PREVIOUS))
1327                     break;
1328                 s = PL_parser->bufptr;
1329                 bufend = PL_parser->bufend;
1330             }
1331         }
1332         unichar = utf8n_to_uvuni((U8*)s, bufend-s, &retlen, UTF8_CHECK_ONLY);
1333         if (retlen == (STRLEN)-1) {
1334             /* malformed UTF-8 */
1335             ENTER;
1336             SAVESPTR(PL_warnhook);
1337             PL_warnhook = PERL_WARNHOOK_FATAL;
1338             utf8n_to_uvuni((U8*)s, bufend-s, NULL, 0);
1339             LEAVE;
1340         }
1341         return unichar;
1342     } else {
1343         if (s == bufend) {
1344             if (!lex_next_chunk(flags))
1345                 return -1;
1346             s = PL_parser->bufptr;
1347         }
1348         return (U8)*s;
1349     }
1350 }
1351
1352 /*
1353 =for apidoc Amx|I32|lex_read_unichar|U32 flags
1354
1355 Reads the next (Unicode) character in the text currently being lexed.
1356 Returns the codepoint (unsigned integer value) of the character read,
1357 and moves L</PL_parser-E<gt>bufptr> past the character, or returns -1
1358 if lexing has reached the end of the input text.  To non-destructively
1359 examine the next character, use L</lex_peek_unichar> instead.
1360
1361 If the next character is in (or extends into) the next chunk of input
1362 text, the next chunk will be read in.  Normally the current chunk will be
1363 discarded at the same time, but if I<flags> includes C<LEX_KEEP_PREVIOUS>
1364 then the current chunk will not be discarded.
1365
1366 If the input is being interpreted as UTF-8 and a UTF-8 encoding error
1367 is encountered, an exception is generated.
1368
1369 =cut
1370 */
1371
1372 I32
1373 Perl_lex_read_unichar(pTHX_ U32 flags)
1374 {
1375     I32 c;
1376     if (flags & ~(LEX_KEEP_PREVIOUS))
1377         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_unichar");
1378     c = lex_peek_unichar(flags);
1379     if (c != -1) {
1380         if (c == '\n')
1381             CopLINE_inc(PL_curcop);
1382         PL_parser->bufptr += UTF8SKIP(PL_parser->bufptr);
1383     }
1384     return c;
1385 }
1386
1387 /*
1388 =for apidoc Amx|void|lex_read_space|U32 flags
1389
1390 Reads optional spaces, in Perl style, in the text currently being
1391 lexed.  The spaces may include ordinary whitespace characters and
1392 Perl-style comments.  C<#line> directives are processed if encountered.
1393 L</PL_parser-E<gt>bufptr> is moved past the spaces, so that it points
1394 at a non-space character (or the end of the input text).
1395
1396 If spaces extend into the next chunk of input text, the next chunk will
1397 be read in.  Normally the current chunk will be discarded at the same
1398 time, but if I<flags> includes C<LEX_KEEP_PREVIOUS> then the current
1399 chunk will not be discarded.
1400
1401 =cut
1402 */
1403
1404 #define LEX_NO_NEXT_CHUNK 0x80000000
1405
1406 void
1407 Perl_lex_read_space(pTHX_ U32 flags)
1408 {
1409     char *s, *bufend;
1410     bool need_incline = 0;
1411     if (flags & ~(LEX_KEEP_PREVIOUS|LEX_NO_NEXT_CHUNK))
1412         Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_read_space");
1413 #ifdef PERL_MAD
1414     if (PL_skipwhite) {
1415         sv_free(PL_skipwhite);
1416         PL_skipwhite = NULL;
1417     }
1418     if (PL_madskills)
1419         PL_skipwhite = newSVpvs("");
1420 #endif /* PERL_MAD */
1421     s = PL_parser->bufptr;
1422     bufend = PL_parser->bufend;
1423     while (1) {
1424         char c = *s;
1425         if (c == '#') {
1426             do {
1427                 c = *++s;
1428             } while (!(c == '\n' || (c == 0 && s == bufend)));
1429         } else if (c == '\n') {
1430             s++;
1431             PL_parser->linestart = s;
1432             if (s == bufend)
1433                 need_incline = 1;
1434             else
1435                 incline(s);
1436         } else if (isSPACE(c)) {
1437             s++;
1438         } else if (c == 0 && s == bufend) {
1439             bool got_more;
1440 #ifdef PERL_MAD
1441             if (PL_madskills)
1442                 sv_catpvn(PL_skipwhite, PL_parser->bufptr, s-PL_parser->bufptr);
1443 #endif /* PERL_MAD */
1444             if (flags & LEX_NO_NEXT_CHUNK)
1445                 break;
1446             PL_parser->bufptr = s;
1447             CopLINE_inc(PL_curcop);
1448             got_more = lex_next_chunk(flags);
1449             CopLINE_dec(PL_curcop);
1450             s = PL_parser->bufptr;
1451             bufend = PL_parser->bufend;
1452             if (!got_more)
1453                 break;
1454             if (need_incline && PL_parser->rsfp) {
1455                 incline(s);
1456                 need_incline = 0;
1457             }
1458         } else {
1459             break;
1460         }
1461     }
1462 #ifdef PERL_MAD
1463     if (PL_madskills)
1464         sv_catpvn(PL_skipwhite, PL_parser->bufptr, s-PL_parser->bufptr);
1465 #endif /* PERL_MAD */
1466     PL_parser->bufptr = s;
1467 }
1468
1469 /*
1470  * S_incline
1471  * This subroutine has nothing to do with tilting, whether at windmills
1472  * or pinball tables.  Its name is short for "increment line".  It
1473  * increments the current line number in CopLINE(PL_curcop) and checks
1474  * to see whether the line starts with a comment of the form
1475  *    # line 500 "foo.pm"
1476  * If so, it sets the current line number and file to the values in the comment.
1477  */
1478
1479 STATIC void
1480 S_incline(pTHX_ const char *s)
1481 {
1482     dVAR;
1483     const char *t;
1484     const char *n;
1485     const char *e;
1486
1487     PERL_ARGS_ASSERT_INCLINE;
1488
1489     CopLINE_inc(PL_curcop);
1490     if (*s++ != '#')
1491         return;
1492     while (SPACE_OR_TAB(*s))
1493         s++;
1494     if (strnEQ(s, "line", 4))
1495         s += 4;
1496     else
1497         return;
1498     if (SPACE_OR_TAB(*s))
1499         s++;
1500     else
1501         return;
1502     while (SPACE_OR_TAB(*s))
1503         s++;
1504     if (!isDIGIT(*s))
1505         return;
1506
1507     n = s;
1508     while (isDIGIT(*s))
1509         s++;
1510     if (!SPACE_OR_TAB(*s) && *s != '\r' && *s != '\n' && *s != '\0')
1511         return;
1512     while (SPACE_OR_TAB(*s))
1513         s++;
1514     if (*s == '"' && (t = strchr(s+1, '"'))) {
1515         s++;
1516         e = t + 1;
1517     }
1518     else {
1519         t = s;
1520         while (!isSPACE(*t))
1521             t++;
1522         e = t;
1523     }
1524     while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
1525         e++;
1526     if (*e != '\n' && *e != '\0')
1527         return;         /* false alarm */
1528
1529     if (t - s > 0) {
1530         const STRLEN len = t - s;
1531 #ifndef USE_ITHREADS
1532         SV *const temp_sv = CopFILESV(PL_curcop);
1533         const char *cf;
1534         STRLEN tmplen;
1535
1536         if (temp_sv) {
1537             cf = SvPVX(temp_sv);
1538             tmplen = SvCUR(temp_sv);
1539         } else {
1540             cf = NULL;
1541             tmplen = 0;
1542         }
1543
1544         if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
1545             /* must copy *{"::_<(eval N)[oldfilename:L]"}
1546              * to *{"::_<newfilename"} */
1547             /* However, the long form of evals is only turned on by the
1548                debugger - usually they're "(eval %lu)" */
1549             char smallbuf[128];
1550             char *tmpbuf;
1551             GV **gvp;
1552             STRLEN tmplen2 = len;
1553             if (tmplen + 2 <= sizeof smallbuf)
1554                 tmpbuf = smallbuf;
1555             else
1556                 Newx(tmpbuf, tmplen + 2, char);
1557             tmpbuf[0] = '_';
1558             tmpbuf[1] = '<';
1559             memcpy(tmpbuf + 2, cf, tmplen);
1560             tmplen += 2;
1561             gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
1562             if (gvp) {
1563                 char *tmpbuf2;
1564                 GV *gv2;
1565
1566                 if (tmplen2 + 2 <= sizeof smallbuf)
1567                     tmpbuf2 = smallbuf;
1568                 else
1569                     Newx(tmpbuf2, tmplen2 + 2, char);
1570
1571                 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
1572                     /* Either they malloc'd it, or we malloc'd it,
1573                        so no prefix is present in ours.  */
1574                     tmpbuf2[0] = '_';
1575                     tmpbuf2[1] = '<';
1576                 }
1577
1578                 memcpy(tmpbuf2 + 2, s, tmplen2);
1579                 tmplen2 += 2;
1580
1581                 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
1582                 if (!isGV(gv2)) {
1583                     gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
1584                     /* adjust ${"::_<newfilename"} to store the new file name */
1585                     GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
1586                     GvHV(gv2) = MUTABLE_HV(SvREFCNT_inc(GvHV(*gvp)));
1587                     GvAV(gv2) = MUTABLE_AV(SvREFCNT_inc(GvAV(*gvp)));
1588                 }
1589
1590                 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
1591             }
1592             if (tmpbuf != smallbuf) Safefree(tmpbuf);
1593         }
1594 #endif
1595         CopFILE_free(PL_curcop);
1596         CopFILE_setn(PL_curcop, s, len);
1597     }
1598     CopLINE_set(PL_curcop, atoi(n)-1);
1599 }
1600
1601 #ifdef PERL_MAD
1602 /* skip space before PL_thistoken */
1603
1604 STATIC char *
1605 S_skipspace0(pTHX_ register char *s)
1606 {
1607     PERL_ARGS_ASSERT_SKIPSPACE0;
1608
1609     s = skipspace(s);
1610     if (!PL_madskills)
1611         return s;
1612     if (PL_skipwhite) {
1613         if (!PL_thiswhite)
1614             PL_thiswhite = newSVpvs("");
1615         sv_catsv(PL_thiswhite, PL_skipwhite);
1616         sv_free(PL_skipwhite);
1617         PL_skipwhite = 0;
1618     }
1619     PL_realtokenstart = s - SvPVX(PL_linestr);
1620     return s;
1621 }
1622
1623 /* skip space after PL_thistoken */
1624
1625 STATIC char *
1626 S_skipspace1(pTHX_ register char *s)
1627 {
1628     const char *start = s;
1629     I32 startoff = start - SvPVX(PL_linestr);
1630
1631     PERL_ARGS_ASSERT_SKIPSPACE1;
1632
1633     s = skipspace(s);
1634     if (!PL_madskills)
1635         return s;
1636     start = SvPVX(PL_linestr) + startoff;
1637     if (!PL_thistoken && PL_realtokenstart >= 0) {
1638         const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
1639         PL_thistoken = newSVpvn(tstart, start - tstart);
1640     }
1641     PL_realtokenstart = -1;
1642     if (PL_skipwhite) {
1643         if (!PL_nextwhite)
1644             PL_nextwhite = newSVpvs("");
1645         sv_catsv(PL_nextwhite, PL_skipwhite);
1646         sv_free(PL_skipwhite);
1647         PL_skipwhite = 0;
1648     }
1649     return s;
1650 }
1651
1652 STATIC char *
1653 S_skipspace2(pTHX_ register char *s, SV **svp)
1654 {
1655     char *start;
1656     const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
1657     const I32 startoff = s - SvPVX(PL_linestr);
1658
1659     PERL_ARGS_ASSERT_SKIPSPACE2;
1660
1661     s = skipspace(s);
1662     PL_bufptr = SvPVX(PL_linestr) + bufptroff;
1663     if (!PL_madskills || !svp)
1664         return s;
1665     start = SvPVX(PL_linestr) + startoff;
1666     if (!PL_thistoken && PL_realtokenstart >= 0) {
1667         char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
1668         PL_thistoken = newSVpvn(tstart, start - tstart);
1669         PL_realtokenstart = -1;
1670     }
1671     if (PL_skipwhite) {
1672         if (!*svp)
1673             *svp = newSVpvs("");
1674         sv_setsv(*svp, PL_skipwhite);
1675         sv_free(PL_skipwhite);
1676         PL_skipwhite = 0;
1677     }
1678     
1679     return s;
1680 }
1681 #endif
1682
1683 STATIC void
1684 S_update_debugger_info(pTHX_ SV *orig_sv, const char *const buf, STRLEN len)
1685 {
1686     AV *av = CopFILEAVx(PL_curcop);
1687     if (av) {
1688         SV * const sv = newSV_type(SVt_PVMG);
1689         if (orig_sv)
1690             sv_setsv(sv, orig_sv);
1691         else
1692             sv_setpvn(sv, buf, len);
1693         (void)SvIOK_on(sv);
1694         SvIV_set(sv, 0);
1695         av_store(av, (I32)CopLINE(PL_curcop), sv);
1696     }
1697 }
1698
1699 /*
1700  * S_skipspace
1701  * Called to gobble the appropriate amount and type of whitespace.
1702  * Skips comments as well.
1703  */
1704
1705 STATIC char *
1706 S_skipspace(pTHX_ register char *s)
1707 {
1708 #ifdef PERL_MAD
1709     char *start = s;
1710 #endif /* PERL_MAD */
1711     PERL_ARGS_ASSERT_SKIPSPACE;
1712 #ifdef PERL_MAD
1713     if (PL_skipwhite) {
1714         sv_free(PL_skipwhite);
1715         PL_skipwhite = NULL;
1716     }
1717 #endif /* PERL_MAD */
1718     if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
1719         while (s < PL_bufend && SPACE_OR_TAB(*s))
1720             s++;
1721     } else {
1722         STRLEN bufptr_pos = PL_bufptr - SvPVX(PL_linestr);
1723         PL_bufptr = s;
1724         lex_read_space(LEX_KEEP_PREVIOUS |
1725                 (PL_sublex_info.sub_inwhat || PL_lex_state == LEX_FORMLINE ?
1726                     LEX_NO_NEXT_CHUNK : 0));
1727         s = PL_bufptr;
1728         PL_bufptr = SvPVX(PL_linestr) + bufptr_pos;
1729         if (PL_linestart > PL_bufptr)
1730             PL_bufptr = PL_linestart;
1731         return s;
1732     }
1733 #ifdef PERL_MAD
1734     if (PL_madskills)
1735         PL_skipwhite = newSVpvn(start, s-start);
1736 #endif /* PERL_MAD */
1737     return s;
1738 }
1739
1740 /*
1741  * S_check_uni
1742  * Check the unary operators to ensure there's no ambiguity in how they're
1743  * used.  An ambiguous piece of code would be:
1744  *     rand + 5
1745  * This doesn't mean rand() + 5.  Because rand() is a unary operator,
1746  * the +5 is its argument.
1747  */
1748
1749 STATIC void
1750 S_check_uni(pTHX)
1751 {
1752     dVAR;
1753     const char *s;
1754     const char *t;
1755
1756     if (PL_oldoldbufptr != PL_last_uni)
1757         return;
1758     while (isSPACE(*PL_last_uni))
1759         PL_last_uni++;
1760     s = PL_last_uni;
1761     while (isALNUM_lazy_if(s,UTF) || *s == '-')
1762         s++;
1763     if ((t = strchr(s, '(')) && t < PL_bufptr)
1764         return;
1765
1766     Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
1767                      "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1768                      (int)(s - PL_last_uni), PL_last_uni);
1769 }
1770
1771 /*
1772  * LOP : macro to build a list operator.  Its behaviour has been replaced
1773  * with a subroutine, S_lop() for which LOP is just another name.
1774  */
1775
1776 #define LOP(f,x) return lop(f,x,s)
1777
1778 /*
1779  * S_lop
1780  * Build a list operator (or something that might be one).  The rules:
1781  *  - if we have a next token, then it's a list operator [why?]
1782  *  - if the next thing is an opening paren, then it's a function
1783  *  - else it's a list operator
1784  */
1785
1786 STATIC I32
1787 S_lop(pTHX_ I32 f, int x, char *s)
1788 {
1789     dVAR;
1790
1791     PERL_ARGS_ASSERT_LOP;
1792
1793     pl_yylval.ival = f;
1794     CLINE;
1795     PL_expect = x;
1796     PL_bufptr = s;
1797     PL_last_lop = PL_oldbufptr;
1798     PL_last_lop_op = (OPCODE)f;
1799 #ifdef PERL_MAD
1800     if (PL_lasttoke)
1801         return REPORT(LSTOP);
1802 #else
1803     if (PL_nexttoke)
1804         return REPORT(LSTOP);
1805 #endif
1806     if (*s == '(')
1807         return REPORT(FUNC);
1808     s = PEEKSPACE(s);
1809     if (*s == '(')
1810         return REPORT(FUNC);
1811     else
1812         return REPORT(LSTOP);
1813 }
1814
1815 #ifdef PERL_MAD
1816  /*
1817  * S_start_force
1818  * Sets up for an eventual force_next().  start_force(0) basically does
1819  * an unshift, while start_force(-1) does a push.  yylex removes items
1820  * on the "pop" end.
1821  */
1822
1823 STATIC void
1824 S_start_force(pTHX_ int where)
1825 {
1826     int i;
1827
1828     if (where < 0)      /* so people can duplicate start_force(PL_curforce) */
1829         where = PL_lasttoke;
1830     assert(PL_curforce < 0 || PL_curforce == where);
1831     if (PL_curforce != where) {
1832         for (i = PL_lasttoke; i > where; --i) {
1833             PL_nexttoke[i] = PL_nexttoke[i-1];
1834         }
1835         PL_lasttoke++;
1836     }
1837     if (PL_curforce < 0)        /* in case of duplicate start_force() */
1838         Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1839     PL_curforce = where;
1840     if (PL_nextwhite) {
1841         if (PL_madskills)
1842             curmad('^', newSVpvs(""));
1843         CURMAD('_', PL_nextwhite);
1844     }
1845 }
1846
1847 STATIC void
1848 S_curmad(pTHX_ char slot, SV *sv)
1849 {
1850     MADPROP **where;
1851
1852     if (!sv)
1853         return;
1854     if (PL_curforce < 0)
1855         where = &PL_thismad;
1856     else
1857         where = &PL_nexttoke[PL_curforce].next_mad;
1858
1859     if (PL_faketokens)
1860         sv_setpvs(sv, "");
1861     else {
1862         if (!IN_BYTES) {
1863             if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1864                 SvUTF8_on(sv);
1865             else if (PL_encoding) {
1866                 sv_recode_to_utf8(sv, PL_encoding);
1867             }
1868         }
1869     }
1870
1871     /* keep a slot open for the head of the list? */
1872     if (slot != '_' && *where && (*where)->mad_key == '^') {
1873         (*where)->mad_key = slot;
1874         sv_free(MUTABLE_SV(((*where)->mad_val)));
1875         (*where)->mad_val = (void*)sv;
1876     }
1877     else
1878         addmad(newMADsv(slot, sv), where, 0);
1879 }
1880 #else
1881 #  define start_force(where)    NOOP
1882 #  define curmad(slot, sv)      NOOP
1883 #endif
1884
1885 /*
1886  * S_force_next
1887  * When the lexer realizes it knows the next token (for instance,
1888  * it is reordering tokens for the parser) then it can call S_force_next
1889  * to know what token to return the next time the lexer is called.  Caller
1890  * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1891  * and possibly PL_expect to ensure the lexer handles the token correctly.
1892  */
1893
1894 STATIC void
1895 S_force_next(pTHX_ I32 type)
1896 {
1897     dVAR;
1898 #ifdef DEBUGGING
1899     if (DEBUG_T_TEST) {
1900         PerlIO_printf(Perl_debug_log, "### forced token:\n");
1901         tokereport(type, &NEXTVAL_NEXTTOKE);
1902     }
1903 #endif
1904 #ifdef PERL_MAD
1905     if (PL_curforce < 0)
1906         start_force(PL_lasttoke);
1907     PL_nexttoke[PL_curforce].next_type = type;
1908     if (PL_lex_state != LEX_KNOWNEXT)
1909         PL_lex_defer = PL_lex_state;
1910     PL_lex_state = LEX_KNOWNEXT;
1911     PL_lex_expect = PL_expect;
1912     PL_curforce = -1;
1913 #else
1914     PL_nexttype[PL_nexttoke] = type;
1915     PL_nexttoke++;
1916     if (PL_lex_state != LEX_KNOWNEXT) {
1917         PL_lex_defer = PL_lex_state;
1918         PL_lex_expect = PL_expect;
1919         PL_lex_state = LEX_KNOWNEXT;
1920     }
1921 #endif
1922 }
1923
1924 STATIC SV *
1925 S_newSV_maybe_utf8(pTHX_ const char *const start, STRLEN len)
1926 {
1927     dVAR;
1928     SV * const sv = newSVpvn_utf8(start, len,
1929                                   !IN_BYTES
1930                                   && UTF
1931                                   && !is_ascii_string((const U8*)start, len)
1932                                   && is_utf8_string((const U8*)start, len));
1933     return sv;
1934 }
1935
1936 /*
1937  * S_force_word
1938  * When the lexer knows the next thing is a word (for instance, it has
1939  * just seen -> and it knows that the next char is a word char, then
1940  * it calls S_force_word to stick the next word into the PL_nexttoke/val
1941  * lookahead.
1942  *
1943  * Arguments:
1944  *   char *start : buffer position (must be within PL_linestr)
1945  *   int token   : PL_next* will be this type of bare word (e.g., METHOD,WORD)
1946  *   int check_keyword : if true, Perl checks to make sure the word isn't
1947  *       a keyword (do this if the word is a label, e.g. goto FOO)
1948  *   int allow_pack : if true, : characters will also be allowed (require,
1949  *       use, etc. do this)
1950  *   int allow_initial_tick : used by the "sub" lexer only.
1951  */
1952
1953 STATIC char *
1954 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1955 {
1956     dVAR;
1957     register char *s;
1958     STRLEN len;
1959
1960     PERL_ARGS_ASSERT_FORCE_WORD;
1961
1962     start = SKIPSPACE1(start);
1963     s = start;
1964     if (isIDFIRST_lazy_if(s,UTF) ||
1965         (allow_pack && *s == ':') ||
1966         (allow_initial_tick && *s == '\'') )
1967     {
1968         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1969         if (check_keyword && keyword(PL_tokenbuf, len, 0))
1970             return start;
1971         start_force(PL_curforce);
1972         if (PL_madskills)
1973             curmad('X', newSVpvn(start,s-start));
1974         if (token == METHOD) {
1975             s = SKIPSPACE1(s);
1976             if (*s == '(')
1977                 PL_expect = XTERM;
1978             else {
1979                 PL_expect = XOPERATOR;
1980             }
1981         }
1982         if (PL_madskills)
1983             curmad('g', newSVpvs( "forced" ));
1984         NEXTVAL_NEXTTOKE.opval
1985             = (OP*)newSVOP(OP_CONST,0,
1986                            S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1987         NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1988         force_next(token);
1989     }
1990     return s;
1991 }
1992
1993 /*
1994  * S_force_ident
1995  * Called when the lexer wants $foo *foo &foo etc, but the program
1996  * text only contains the "foo" portion.  The first argument is a pointer
1997  * to the "foo", and the second argument is the type symbol to prefix.
1998  * Forces the next token to be a "WORD".
1999  * Creates the symbol if it didn't already exist (via gv_fetchpv()).
2000  */
2001
2002 STATIC void
2003 S_force_ident(pTHX_ register const char *s, int kind)
2004 {
2005     dVAR;
2006
2007     PERL_ARGS_ASSERT_FORCE_IDENT;
2008
2009     if (*s) {
2010         const STRLEN len = strlen(s);
2011         OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
2012         start_force(PL_curforce);
2013         NEXTVAL_NEXTTOKE.opval = o;
2014         force_next(WORD);
2015         if (kind) {
2016             o->op_private = OPpCONST_ENTERED;
2017             /* XXX see note in pp_entereval() for why we forgo typo
2018                warnings if the symbol must be introduced in an eval.
2019                GSAR 96-10-12 */
2020             gv_fetchpvn_flags(s, len,
2021                               PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
2022                               : GV_ADD,
2023                               kind == '$' ? SVt_PV :
2024                               kind == '@' ? SVt_PVAV :
2025                               kind == '%' ? SVt_PVHV :
2026                               SVt_PVGV
2027                               );
2028         }
2029     }
2030 }
2031
2032 NV
2033 Perl_str_to_version(pTHX_ SV *sv)
2034 {
2035     NV retval = 0.0;
2036     NV nshift = 1.0;
2037     STRLEN len;
2038     const char *start = SvPV_const(sv,len);
2039     const char * const end = start + len;
2040     const bool utf = SvUTF8(sv) ? TRUE : FALSE;
2041
2042     PERL_ARGS_ASSERT_STR_TO_VERSION;
2043
2044     while (start < end) {
2045         STRLEN skip;
2046         UV n;
2047         if (utf)
2048             n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
2049         else {
2050             n = *(U8*)start;
2051             skip = 1;
2052         }
2053         retval += ((NV)n)/nshift;
2054         start += skip;
2055         nshift *= 1000;
2056     }
2057     return retval;
2058 }
2059
2060 /*
2061  * S_force_version
2062  * Forces the next token to be a version number.
2063  * If the next token appears to be an invalid version number, (e.g. "v2b"),
2064  * and if "guessing" is TRUE, then no new token is created (and the caller
2065  * must use an alternative parsing method).
2066  */
2067
2068 STATIC char *
2069 S_force_version(pTHX_ char *s, int guessing)
2070 {
2071     dVAR;
2072     OP *version = NULL;
2073     char *d;
2074 #ifdef PERL_MAD
2075     I32 startoff = s - SvPVX(PL_linestr);
2076 #endif
2077
2078     PERL_ARGS_ASSERT_FORCE_VERSION;
2079
2080     s = SKIPSPACE1(s);
2081
2082     d = s;
2083     if (*d == 'v')
2084         d++;
2085     if (isDIGIT(*d)) {
2086         while (isDIGIT(*d) || *d == '_' || *d == '.')
2087             d++;
2088 #ifdef PERL_MAD
2089         if (PL_madskills) {
2090             start_force(PL_curforce);
2091             curmad('X', newSVpvn(s,d-s));
2092         }
2093 #endif
2094         if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
2095             SV *ver;
2096 #ifdef USE_LOCALE_NUMERIC
2097             char *loc = setlocale(LC_NUMERIC, "C");
2098 #endif
2099             s = scan_num(s, &pl_yylval);
2100 #ifdef USE_LOCALE_NUMERIC
2101             setlocale(LC_NUMERIC, loc);
2102 #endif
2103             version = pl_yylval.opval;
2104             ver = cSVOPx(version)->op_sv;
2105             if (SvPOK(ver) && !SvNIOK(ver)) {
2106                 SvUPGRADE(ver, SVt_PVNV);
2107                 SvNV_set(ver, str_to_version(ver));
2108                 SvNOK_on(ver);          /* hint that it is a version */
2109             }
2110         }
2111         else if (guessing) {
2112 #ifdef PERL_MAD
2113             if (PL_madskills) {
2114                 sv_free(PL_nextwhite);  /* let next token collect whitespace */
2115                 PL_nextwhite = 0;
2116                 s = SvPVX(PL_linestr) + startoff;
2117             }
2118 #endif
2119             return s;
2120         }
2121     }
2122
2123 #ifdef PERL_MAD
2124     if (PL_madskills && !version) {
2125         sv_free(PL_nextwhite);  /* let next token collect whitespace */
2126         PL_nextwhite = 0;
2127         s = SvPVX(PL_linestr) + startoff;
2128     }
2129 #endif
2130     /* NOTE: The parser sees the package name and the VERSION swapped */
2131     start_force(PL_curforce);
2132     NEXTVAL_NEXTTOKE.opval = version;
2133     force_next(WORD);
2134
2135     return s;
2136 }
2137
2138 /*
2139  * S_force_strict_version
2140  * Forces the next token to be a version number using strict syntax rules.
2141  */
2142
2143 STATIC char *
2144 S_force_strict_version(pTHX_ char *s)
2145 {
2146     dVAR;
2147     OP *version = NULL;
2148 #ifdef PERL_MAD
2149     I32 startoff = s - SvPVX(PL_linestr);
2150 #endif
2151     const char *errstr = NULL;
2152
2153     PERL_ARGS_ASSERT_FORCE_STRICT_VERSION;
2154
2155     while (isSPACE(*s)) /* leading whitespace */
2156         s++;
2157
2158     if (is_STRICT_VERSION(s,&errstr)) {
2159         SV *ver = newSV(0);
2160         s = (char *)scan_version(s, ver, 0);
2161         version = newSVOP(OP_CONST, 0, ver);
2162     }
2163     else if ( (*s != ';' && *s != '}' ) && (s = SKIPSPACE1(s), (*s != ';' && *s !='}' ))) {
2164         PL_bufptr = s;
2165         if (errstr)
2166             yyerror(errstr); /* version required */
2167         return s;
2168     }
2169
2170 #ifdef PERL_MAD
2171     if (PL_madskills && !version) {
2172         sv_free(PL_nextwhite);  /* let next token collect whitespace */
2173         PL_nextwhite = 0;
2174         s = SvPVX(PL_linestr) + startoff;
2175     }
2176 #endif
2177     /* NOTE: The parser sees the package name and the VERSION swapped */
2178     start_force(PL_curforce);
2179     NEXTVAL_NEXTTOKE.opval = version;
2180     force_next(WORD);
2181
2182     return s;
2183 }
2184
2185 /*
2186  * S_tokeq
2187  * Tokenize a quoted string passed in as an SV.  It finds the next
2188  * chunk, up to end of string or a backslash.  It may make a new
2189  * SV containing that chunk (if HINT_NEW_STRING is on).  It also
2190  * turns \\ into \.
2191  */
2192
2193 STATIC SV *
2194 S_tokeq(pTHX_ SV *sv)
2195 {
2196     dVAR;
2197     register char *s;
2198     register char *send;
2199     register char *d;
2200     STRLEN len = 0;
2201     SV *pv = sv;
2202
2203     PERL_ARGS_ASSERT_TOKEQ;
2204
2205     if (!SvLEN(sv))
2206         goto finish;
2207
2208     s = SvPV_force(sv, len);
2209     if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
2210         goto finish;
2211     send = s + len;
2212     while (s < send && *s != '\\')
2213         s++;
2214     if (s == send)
2215         goto finish;
2216     d = s;
2217     if ( PL_hints & HINT_NEW_STRING ) {
2218         pv = newSVpvn_flags(SvPVX_const(pv), len, SVs_TEMP | SvUTF8(sv));
2219     }
2220     while (s < send) {
2221         if (*s == '\\') {
2222             if (s + 1 < send && (s[1] == '\\'))
2223                 s++;            /* all that, just for this */
2224         }
2225         *d++ = *s++;
2226     }
2227     *d = '\0';
2228     SvCUR_set(sv, d - SvPVX_const(sv));
2229   finish:
2230     if ( PL_hints & HINT_NEW_STRING )
2231        return new_constant(NULL, 0, "q", sv, pv, "q", 1);
2232     return sv;
2233 }
2234
2235 /*
2236  * Now come three functions related to double-quote context,
2237  * S_sublex_start, S_sublex_push, and S_sublex_done.  They're used when
2238  * converting things like "\u\Lgnat" into ucfirst(lc("gnat")).  They
2239  * interact with PL_lex_state, and create fake ( ... ) argument lists
2240  * to handle functions and concatenation.
2241  * They assume that whoever calls them will be setting up a fake
2242  * join call, because each subthing puts a ',' after it.  This lets
2243  *   "lower \luPpEr"
2244  * become
2245  *  join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
2246  *
2247  * (I'm not sure whether the spurious commas at the end of lcfirst's
2248  * arguments and join's arguments are created or not).
2249  */
2250
2251 /*
2252  * S_sublex_start
2253  * Assumes that pl_yylval.ival is the op we're creating (e.g. OP_LCFIRST).
2254  *
2255  * Pattern matching will set PL_lex_op to the pattern-matching op to
2256  * make (we return THING if pl_yylval.ival is OP_NULL, PMFUNC otherwise).
2257  *
2258  * OP_CONST and OP_READLINE are easy--just make the new op and return.
2259  *
2260  * Everything else becomes a FUNC.
2261  *
2262  * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
2263  * had an OP_CONST or OP_READLINE).  This just sets us up for a
2264  * call to S_sublex_push().
2265  */
2266
2267 STATIC I32
2268 S_sublex_start(pTHX)
2269 {
2270     dVAR;
2271     register const I32 op_type = pl_yylval.ival;
2272
2273     if (op_type == OP_NULL) {
2274         pl_yylval.opval = PL_lex_op;
2275         PL_lex_op = NULL;
2276         return THING;
2277     }
2278     if (op_type == OP_CONST || op_type == OP_READLINE) {
2279         SV *sv = tokeq(PL_lex_stuff);
2280
2281         if (SvTYPE(sv) == SVt_PVIV) {
2282             /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
2283             STRLEN len;
2284             const char * const p = SvPV_const(sv, len);
2285             SV * const nsv = newSVpvn_flags(p, len, SvUTF8(sv));
2286             SvREFCNT_dec(sv);
2287             sv = nsv;
2288         }
2289         pl_yylval.opval = (OP*)newSVOP(op_type, 0, sv);
2290         PL_lex_stuff = NULL;
2291         /* Allow <FH> // "foo" */
2292         if (op_type == OP_READLINE)
2293             PL_expect = XTERMORDORDOR;
2294         return THING;
2295     }
2296     else if (op_type == OP_BACKTICK && PL_lex_op) {
2297         /* readpipe() vas overriden */
2298         cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
2299         pl_yylval.opval = PL_lex_op;
2300         PL_lex_op = NULL;
2301         PL_lex_stuff = NULL;
2302         return THING;
2303     }
2304
2305     PL_sublex_info.super_state = PL_lex_state;
2306     PL_sublex_info.sub_inwhat = (U16)op_type;
2307     PL_sublex_info.sub_op = PL_lex_op;
2308     PL_lex_state = LEX_INTERPPUSH;
2309
2310     PL_expect = XTERM;
2311     if (PL_lex_op) {
2312         pl_yylval.opval = PL_lex_op;
2313         PL_lex_op = NULL;
2314         return PMFUNC;
2315     }
2316     else
2317         return FUNC;
2318 }
2319
2320 /*
2321  * S_sublex_push
2322  * Create a new scope to save the lexing state.  The scope will be
2323  * ended in S_sublex_done.  Returns a '(', starting the function arguments
2324  * to the uc, lc, etc. found before.
2325  * Sets PL_lex_state to LEX_INTERPCONCAT.
2326  */
2327
2328 STATIC I32
2329 S_sublex_push(pTHX)
2330 {
2331     dVAR;
2332     ENTER;
2333
2334     PL_lex_state = PL_sublex_info.super_state;
2335     SAVEBOOL(PL_lex_dojoin);
2336     SAVEI32(PL_lex_brackets);
2337     SAVEI32(PL_lex_casemods);
2338     SAVEI32(PL_lex_starts);
2339     SAVEI8(PL_lex_state);
2340     SAVEVPTR(PL_lex_inpat);
2341     SAVEI16(PL_lex_inwhat);
2342     SAVECOPLINE(PL_curcop);
2343     SAVEPPTR(PL_bufptr);
2344     SAVEPPTR(PL_bufend);
2345     SAVEPPTR(PL_oldbufptr);
2346     SAVEPPTR(PL_oldoldbufptr);
2347     SAVEPPTR(PL_last_lop);
2348     SAVEPPTR(PL_last_uni);
2349     SAVEPPTR(PL_linestart);
2350     SAVESPTR(PL_linestr);
2351     SAVEGENERICPV(PL_lex_brackstack);
2352     SAVEGENERICPV(PL_lex_casestack);
2353
2354     PL_linestr = PL_lex_stuff;
2355     PL_lex_stuff = NULL;
2356
2357     PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
2358         = SvPVX(PL_linestr);
2359     PL_bufend += SvCUR(PL_linestr);
2360     PL_last_lop = PL_last_uni = NULL;
2361     SAVEFREESV(PL_linestr);
2362
2363     PL_lex_dojoin = FALSE;
2364     PL_lex_brackets = 0;
2365     Newx(PL_lex_brackstack, 120, char);
2366     Newx(PL_lex_casestack, 12, char);
2367     PL_lex_casemods = 0;
2368     *PL_lex_casestack = '\0';
2369     PL_lex_starts = 0;
2370     PL_lex_state = LEX_INTERPCONCAT;
2371     CopLINE_set(PL_curcop, (line_t)PL_multi_start);
2372
2373     PL_lex_inwhat = PL_sublex_info.sub_inwhat;
2374     if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
2375         PL_lex_inpat = PL_sublex_info.sub_op;
2376     else
2377         PL_lex_inpat = NULL;
2378
2379     return '(';
2380 }
2381
2382 /*
2383  * S_sublex_done
2384  * Restores lexer state after a S_sublex_push.
2385  */
2386
2387 STATIC I32
2388 S_sublex_done(pTHX)
2389 {
2390     dVAR;
2391     if (!PL_lex_starts++) {
2392         SV * const sv = newSVpvs("");
2393         if (SvUTF8(PL_linestr))
2394             SvUTF8_on(sv);
2395         PL_expect = XOPERATOR;
2396         pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2397         return THING;
2398     }
2399
2400     if (PL_lex_casemods) {              /* oops, we've got some unbalanced parens */
2401         PL_lex_state = LEX_INTERPCASEMOD;
2402         return yylex();
2403     }
2404
2405     /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
2406     if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
2407         PL_linestr = PL_lex_repl;
2408         PL_lex_inpat = 0;
2409         PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
2410         PL_bufend += SvCUR(PL_linestr);
2411         PL_last_lop = PL_last_uni = NULL;
2412         SAVEFREESV(PL_linestr);
2413         PL_lex_dojoin = FALSE;
2414         PL_lex_brackets = 0;
2415         PL_lex_casemods = 0;
2416         *PL_lex_casestack = '\0';
2417         PL_lex_starts = 0;
2418         if (SvEVALED(PL_lex_repl)) {
2419             PL_lex_state = LEX_INTERPNORMAL;
2420             PL_lex_starts++;
2421             /*  we don't clear PL_lex_repl here, so that we can check later
2422                 whether this is an evalled subst; that means we rely on the
2423                 logic to ensure sublex_done() is called again only via the
2424                 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
2425         }
2426         else {
2427             PL_lex_state = LEX_INTERPCONCAT;
2428             PL_lex_repl = NULL;
2429         }
2430         return ',';
2431     }
2432     else {
2433 #ifdef PERL_MAD
2434         if (PL_madskills) {
2435             if (PL_thiswhite) {
2436                 if (!PL_endwhite)
2437                     PL_endwhite = newSVpvs("");
2438                 sv_catsv(PL_endwhite, PL_thiswhite);
2439                 PL_thiswhite = 0;
2440             }
2441             if (PL_thistoken)
2442                 sv_setpvs(PL_thistoken,"");
2443             else
2444                 PL_realtokenstart = -1;
2445         }
2446 #endif
2447         LEAVE;
2448         PL_bufend = SvPVX(PL_linestr);
2449         PL_bufend += SvCUR(PL_linestr);
2450         PL_expect = XOPERATOR;
2451         PL_sublex_info.sub_inwhat = 0;
2452         return ')';
2453     }
2454 }
2455
2456 /*
2457   scan_const
2458
2459   Extracts a pattern, double-quoted string, or transliteration.  This
2460   is terrifying code.
2461
2462   It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
2463   processing a pattern (PL_lex_inpat is true), a transliteration
2464   (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
2465
2466   Returns a pointer to the character scanned up to. If this is
2467   advanced from the start pointer supplied (i.e. if anything was
2468   successfully parsed), will leave an OP for the substring scanned
2469   in pl_yylval. Caller must intuit reason for not parsing further
2470   by looking at the next characters herself.
2471
2472   In patterns:
2473     backslashes:
2474       constants: \N{NAME} only
2475       case and quoting: \U \Q \E
2476     stops on @ and $, but not for $ as tail anchor
2477
2478   In transliterations:
2479     characters are VERY literal, except for - not at the start or end
2480     of the string, which indicates a range. If the range is in bytes,
2481     scan_const expands the range to the full set of intermediate
2482     characters. If the range is in utf8, the hyphen is replaced with
2483     a certain range mark which will be handled by pmtrans() in op.c.
2484
2485   In double-quoted strings:
2486     backslashes:
2487       double-quoted style: \r and \n
2488       constants: \x31, etc.
2489       deprecated backrefs: \1 (in substitution replacements)
2490       case and quoting: \U \Q \E
2491     stops on @ and $
2492
2493   scan_const does *not* construct ops to handle interpolated strings.
2494   It stops processing as soon as it finds an embedded $ or @ variable
2495   and leaves it to the caller to work out what's going on.
2496
2497   embedded arrays (whether in pattern or not) could be:
2498       @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
2499
2500   $ in double-quoted strings must be the symbol of an embedded scalar.
2501
2502   $ in pattern could be $foo or could be tail anchor.  Assumption:
2503   it's a tail anchor if $ is the last thing in the string, or if it's
2504   followed by one of "()| \r\n\t"
2505
2506   \1 (backreferences) are turned into $1
2507
2508   The structure of the code is
2509       while (there's a character to process) {
2510           handle transliteration ranges
2511           skip regexp comments /(?#comment)/ and codes /(?{code})/
2512           skip #-initiated comments in //x patterns
2513           check for embedded arrays
2514           check for embedded scalars
2515           if (backslash) {
2516               deprecate \1 in substitution replacements
2517               handle string-changing backslashes \l \U \Q \E, etc.
2518               switch (what was escaped) {
2519                   handle \- in a transliteration (becomes a literal -)
2520                   if a pattern and not \N{, go treat as regular character
2521                   handle \132 (octal characters)
2522                   handle \x15 and \x{1234} (hex characters)
2523                   handle \N{name} (named characters, also \N{3,5} in a pattern)
2524                   handle \cV (control characters)
2525                   handle printf-style backslashes (\f, \r, \n, etc)
2526               } (end switch)
2527               continue
2528           } (end if backslash)
2529           handle regular character
2530     } (end while character to read)
2531                 
2532 */
2533
2534 STATIC char *
2535 S_scan_const(pTHX_ char *start)
2536 {
2537     dVAR;
2538     register char *send = PL_bufend;            /* end of the constant */
2539     SV *sv = newSV(send - start);               /* sv for the constant.  See
2540                                                    note below on sizing. */
2541     register char *s = start;                   /* start of the constant */
2542     register char *d = SvPVX(sv);               /* destination for copies */
2543     bool dorange = FALSE;                       /* are we in a translit range? */
2544     bool didrange = FALSE;                      /* did we just finish a range? */
2545     I32  has_utf8 = FALSE;                      /* Output constant is UTF8 */
2546     I32  this_utf8 = UTF;                       /* Is the source string assumed
2547                                                    to be UTF8?  But, this can
2548                                                    show as true when the source
2549                                                    isn't utf8, as for example
2550                                                    when it is entirely composed
2551                                                    of hex constants */
2552
2553     /* Note on sizing:  The scanned constant is placed into sv, which is
2554      * initialized by newSV() assuming one byte of output for every byte of
2555      * input.  This routine expects newSV() to allocate an extra byte for a
2556      * trailing NUL, which this routine will append if it gets to the end of
2557      * the input.  There may be more bytes of input than output (eg., \N{LATIN
2558      * CAPITAL LETTER A}), or more output than input if the constant ends up
2559      * recoded to utf8, but each time a construct is found that might increase
2560      * the needed size, SvGROW() is called.  Its size parameter each time is
2561      * based on the best guess estimate at the time, namely the length used so
2562      * far, plus the length the current construct will occupy, plus room for
2563      * the trailing NUL, plus one byte for every input byte still unscanned */ 
2564
2565     UV uv;
2566 #ifdef EBCDIC
2567     UV literal_endpoint = 0;
2568     bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
2569 #endif
2570
2571     PERL_ARGS_ASSERT_SCAN_CONST;
2572
2573     if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2574         /* If we are doing a trans and we know we want UTF8 set expectation */
2575         has_utf8   = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
2576         this_utf8  = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2577     }
2578
2579
2580     while (s < send || dorange) {
2581
2582         /* get transliterations out of the way (they're most literal) */
2583         if (PL_lex_inwhat == OP_TRANS) {
2584             /* expand a range A-Z to the full set of characters.  AIE! */
2585             if (dorange) {
2586                 I32 i;                          /* current expanded character */
2587                 I32 min;                        /* first character in range */
2588                 I32 max;                        /* last character in range */
2589
2590 #ifdef EBCDIC
2591                 UV uvmax = 0;
2592 #endif
2593
2594                 if (has_utf8
2595 #ifdef EBCDIC
2596                     && !native_range
2597 #endif
2598                     ) {
2599                     char * const c = (char*)utf8_hop((U8*)d, -1);
2600                     char *e = d++;
2601                     while (e-- > c)
2602                         *(e + 1) = *e;
2603                     *c = (char)UTF_TO_NATIVE(0xff);
2604                     /* mark the range as done, and continue */
2605                     dorange = FALSE;
2606                     didrange = TRUE;
2607                     continue;
2608                 }
2609
2610                 i = d - SvPVX_const(sv);                /* remember current offset */
2611 #ifdef EBCDIC
2612                 SvGROW(sv,
2613                        SvLEN(sv) + (has_utf8 ?
2614                                     (512 - UTF_CONTINUATION_MARK +
2615                                      UNISKIP(0x100))
2616                                     : 256));
2617                 /* How many two-byte within 0..255: 128 in UTF-8,
2618                  * 96 in UTF-8-mod. */
2619 #else
2620                 SvGROW(sv, SvLEN(sv) + 256);    /* never more than 256 chars in a range */
2621 #endif
2622                 d = SvPVX(sv) + i;              /* refresh d after realloc */
2623 #ifdef EBCDIC
2624                 if (has_utf8) {
2625                     int j;
2626                     for (j = 0; j <= 1; j++) {
2627                         char * const c = (char*)utf8_hop((U8*)d, -1);
2628                         const UV uv    = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
2629                         if (j)
2630                             min = (U8)uv;
2631                         else if (uv < 256)
2632                             max = (U8)uv;
2633                         else {
2634                             max = (U8)0xff; /* only to \xff */
2635                             uvmax = uv; /* \x{100} to uvmax */
2636                         }
2637                         d = c; /* eat endpoint chars */
2638                      }
2639                 }
2640                else {
2641 #endif
2642                    d -= 2;              /* eat the first char and the - */
2643                    min = (U8)*d;        /* first char in range */
2644                    max = (U8)d[1];      /* last char in range  */
2645 #ifdef EBCDIC
2646                }
2647 #endif
2648
2649                 if (min > max) {
2650                     Perl_croak(aTHX_
2651                                "Invalid range \"%c-%c\" in transliteration operator",
2652                                (char)min, (char)max);
2653                 }
2654
2655 #ifdef EBCDIC
2656                 if (literal_endpoint == 2 &&
2657                     ((isLOWER(min) && isLOWER(max)) ||
2658                      (isUPPER(min) && isUPPER(max)))) {
2659                     if (isLOWER(min)) {
2660                         for (i = min; i <= max; i++)
2661                             if (isLOWER(i))
2662                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
2663                     } else {
2664                         for (i = min; i <= max; i++)
2665                             if (isUPPER(i))
2666                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
2667                     }
2668                 }
2669                 else
2670 #endif
2671                     for (i = min; i <= max; i++)
2672 #ifdef EBCDIC
2673                         if (has_utf8) {
2674                             const U8 ch = (U8)NATIVE_TO_UTF(i);
2675                             if (UNI_IS_INVARIANT(ch))
2676                                 *d++ = (U8)i;
2677                             else {
2678                                 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
2679                                 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
2680                             }
2681                         }
2682                         else
2683 #endif
2684                             *d++ = (char)i;
2685  
2686 #ifdef EBCDIC
2687                 if (uvmax) {
2688                     d = (char*)uvchr_to_utf8((U8*)d, 0x100);
2689                     if (uvmax > 0x101)
2690                         *d++ = (char)UTF_TO_NATIVE(0xff);
2691                     if (uvmax > 0x100)
2692                         d = (char*)uvchr_to_utf8((U8*)d, uvmax);
2693                 }
2694 #endif
2695
2696                 /* mark the range as done, and continue */
2697                 dorange = FALSE;
2698                 didrange = TRUE;
2699 #ifdef EBCDIC
2700                 literal_endpoint = 0;
2701 #endif
2702                 continue;
2703             }
2704
2705             /* range begins (ignore - as first or last char) */
2706             else if (*s == '-' && s+1 < send  && s != start) {
2707                 if (didrange) {
2708                     Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
2709                 }
2710                 if (has_utf8
2711 #ifdef EBCDIC
2712                     && !native_range
2713 #endif
2714                     ) {
2715                     *d++ = (char)UTF_TO_NATIVE(0xff);   /* use illegal utf8 byte--see pmtrans */
2716                     s++;
2717                     continue;
2718                 }
2719                 dorange = TRUE;
2720                 s++;
2721             }
2722             else {
2723                 didrange = FALSE;
2724 #ifdef EBCDIC
2725                 literal_endpoint = 0;
2726                 native_range = TRUE;
2727 #endif
2728             }
2729         }
2730
2731         /* if we get here, we're not doing a transliteration */
2732
2733         /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2734            except for the last char, which will be done separately. */
2735         else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
2736             if (s[2] == '#') {
2737                 while (s+1 < send && *s != ')')
2738                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2739             }
2740             else if (s[2] == '{' /* This should match regcomp.c */
2741                     || (s[2] == '?' && s[3] == '{'))
2742             {
2743                 I32 count = 1;
2744                 char *regparse = s + (s[2] == '{' ? 3 : 4);
2745                 char c;
2746
2747                 while (count && (c = *regparse)) {
2748                     if (c == '\\' && regparse[1])
2749                         regparse++;
2750                     else if (c == '{')
2751                         count++;
2752                     else if (c == '}')
2753                         count--;
2754                     regparse++;
2755                 }
2756                 if (*regparse != ')')
2757                     regparse--;         /* Leave one char for continuation. */
2758                 while (s < regparse)
2759                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2760             }
2761         }
2762
2763         /* likewise skip #-initiated comments in //x patterns */
2764         else if (*s == '#' && PL_lex_inpat &&
2765           ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2766             while (s+1 < send && *s != '\n')
2767                 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2768         }
2769
2770         /* check for embedded arrays
2771            (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2772            */
2773         else if (*s == '@' && s[1]) {
2774             if (isALNUM_lazy_if(s+1,UTF))
2775                 break;
2776             if (strchr(":'{$", s[1]))
2777                 break;
2778             if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2779                 break; /* in regexp, neither @+ nor @- are interpolated */
2780         }
2781
2782         /* check for embedded scalars.  only stop if we're sure it's a
2783            variable.
2784         */
2785         else if (*s == '$') {
2786             if (!PL_lex_inpat)  /* not a regexp, so $ must be var */
2787                 break;
2788             if (s + 1 < send && !strchr("()| \r\n\t", s[1])) {
2789                 if (s[1] == '\\') {
2790                     Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
2791                                    "Possible unintended interpolation of $\\ in regex");
2792                 }
2793                 break;          /* in regexp, $ might be tail anchor */
2794             }
2795         }
2796
2797         /* End of else if chain - OP_TRANS rejoin rest */
2798
2799         /* backslashes */
2800         if (*s == '\\' && s+1 < send) {
2801             char* e;    /* Can be used for ending '}', etc. */
2802
2803             s++;
2804
2805             /* deprecate \1 in strings and substitution replacements */
2806             if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2807                 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2808             {
2809                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2810                 *--s = '$';
2811                 break;
2812             }
2813
2814             /* string-change backslash escapes */
2815             if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2816                 --s;
2817                 break;
2818             }
2819             /* In a pattern, process \N, but skip any other backslash escapes.
2820              * This is because we don't want to translate an escape sequence
2821              * into a meta symbol and have the regex compiler use the meta
2822              * symbol meaning, e.g. \x{2E} would be confused with a dot.  But
2823              * in spite of this, we do have to process \N here while the proper
2824              * charnames handler is in scope.  See bugs #56444 and #62056.
2825              * There is a complication because \N in a pattern may also stand
2826              * for 'match a non-nl', and not mean a charname, in which case its
2827              * processing should be deferred to the regex compiler.  To be a
2828              * charname it must be followed immediately by a '{', and not look
2829              * like \N followed by a curly quantifier, i.e., not something like
2830              * \N{3,}.  regcurly returns a boolean indicating if it is a legal
2831              * quantifier */
2832             else if (PL_lex_inpat
2833                     && (*s != 'N'
2834                         || s[1] != '{'
2835                         || regcurly(s + 1)))
2836             {
2837                 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2838                 goto default_action;
2839             }
2840
2841             switch (*s) {
2842
2843             /* quoted - in transliterations */
2844             case '-':
2845                 if (PL_lex_inwhat == OP_TRANS) {
2846                     *d++ = *s++;
2847                     continue;
2848                 }
2849                 /* FALL THROUGH */
2850             default:
2851                 {
2852                     if ((isALPHA(*s) || isDIGIT(*s)))
2853                         Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
2854                                        "Unrecognized escape \\%c passed through",
2855                                        *s);
2856                     /* default action is to copy the quoted character */
2857                     goto default_action;
2858                 }
2859
2860             /* eg. \132 indicates the octal constant 0x132 */
2861             case '0': case '1': case '2': case '3':
2862             case '4': case '5': case '6': case '7':
2863                 {
2864                     I32 flags = 0;
2865                     STRLEN len = 3;
2866                     uv = NATIVE_TO_UNI(grok_oct(s, &len, &flags, NULL));
2867                     s += len;
2868                 }
2869                 goto NUM_ESCAPE_INSERT;
2870
2871             /* eg. \x24 indicates the hex constant 0x24 */
2872             case 'x':
2873                 ++s;
2874                 if (*s == '{') {
2875                     char* const e = strchr(s, '}');
2876                     I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2877                       PERL_SCAN_DISALLOW_PREFIX;
2878                     STRLEN len;
2879
2880                     ++s;
2881                     if (!e) {
2882                         yyerror("Missing right brace on \\x{}");
2883                         continue;
2884                     }
2885                     len = e - s;
2886                     uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
2887                     s = e + 1;
2888                 }
2889                 else {
2890                     {
2891                         STRLEN len = 2;
2892                         I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2893                         uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
2894                         s += len;
2895                     }
2896                 }
2897
2898               NUM_ESCAPE_INSERT:
2899                 /* Insert oct or hex escaped character.  There will always be
2900                  * enough room in sv since such escapes will be longer than any
2901                  * UTF-8 sequence they can end up as, except if they force us
2902                  * to recode the rest of the string into utf8 */
2903                 
2904                 /* Here uv is the ordinal of the next character being added in
2905                  * unicode (converted from native). */
2906                 if (!UNI_IS_INVARIANT(uv)) {
2907                     if (!has_utf8 && uv > 255) {
2908                         /* Might need to recode whatever we have accumulated so
2909                          * far if it contains any chars variant in utf8 or
2910                          * utf-ebcdic. */
2911                           
2912                         SvCUR_set(sv, d - SvPVX_const(sv));
2913                         SvPOK_on(sv);
2914                         *d = '\0';
2915                         /* See Note on sizing above.  */
2916                         sv_utf8_upgrade_flags_grow(sv,
2917                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2918                                         UNISKIP(uv) + (STRLEN)(send - s) + 1);
2919                         d = SvPVX(sv) + SvCUR(sv);
2920                         has_utf8 = TRUE;
2921                     }
2922
2923                     if (has_utf8) {
2924                         d = (char*)uvuni_to_utf8((U8*)d, uv);
2925                         if (PL_lex_inwhat == OP_TRANS &&
2926                             PL_sublex_info.sub_op) {
2927                             PL_sublex_info.sub_op->op_private |=
2928                                 (PL_lex_repl ? OPpTRANS_FROM_UTF
2929                                              : OPpTRANS_TO_UTF);
2930                         }
2931 #ifdef EBCDIC
2932                         if (uv > 255 && !dorange)
2933                             native_range = FALSE;
2934 #endif
2935                     }
2936                     else {
2937                         *d++ = (char)uv;
2938                     }
2939                 }
2940                 else {
2941                     *d++ = (char) uv;
2942                 }
2943                 continue;
2944
2945             case 'N':
2946                 /* In a non-pattern \N must be a named character, like \N{LATIN
2947                  * SMALL LETTER A} or \N{U+0041}.  For patterns, it also can
2948                  * mean to match a non-newline.  For non-patterns, named
2949                  * characters are converted to their string equivalents. In
2950                  * patterns, named characters are not converted to their
2951                  * ultimate forms for the same reasons that other escapes
2952                  * aren't.  Instead, they are converted to the \N{U+...} form
2953                  * to get the value from the charnames that is in effect right
2954                  * now, while preserving the fact that it was a named character
2955                  * so that the regex compiler knows this */
2956
2957                 /* This section of code doesn't generally use the
2958                  * NATIVE_TO_NEED() macro to transform the input.  I (khw) did
2959                  * a close examination of this macro and determined it is a
2960                  * no-op except on utfebcdic variant characters.  Every
2961                  * character generated by this that would normally need to be
2962                  * enclosed by this macro is invariant, so the macro is not
2963                  * needed, and would complicate use of copy(). There are other
2964                  * parts of this file where the macro is used inconsistently,
2965                  * but are saved by it being a no-op */
2966
2967                 /* The structure of this section of code (besides checking for
2968                  * errors and upgrading to utf8) is:
2969                  *  Further disambiguate between the two meanings of \N, and if
2970                  *      not a charname, go process it elsewhere
2971                  *  If of form \N{U+...}, pass it through if a pattern;
2972                  *      otherwise convert to utf8
2973                  *  Otherwise must be \N{NAME}: convert to \N{U+c1.c2...} if a
2974                  *  pattern; otherwise convert to utf8 */
2975
2976                 /* Here, s points to the 'N'; the test below is guaranteed to
2977                  * succeed if we are being called on a pattern as we already
2978                  * know from a test above that the next character is a '{'.
2979                  * On a non-pattern \N must mean 'named sequence, which
2980                  * requires braces */
2981                 s++;
2982                 if (*s != '{') {
2983                     yyerror("Missing braces on \\N{}"); 
2984                     continue;
2985                 }
2986                 s++;
2987
2988                 /* If there is no matching '}', it is an error. */
2989                 if (! (e = strchr(s, '}'))) {
2990                     if (! PL_lex_inpat) {
2991                         yyerror("Missing right brace on \\N{}");
2992                     } else {
2993                         yyerror("Missing right brace on \\N{} or unescaped left brace after \\N.");
2994                     }
2995                     continue;
2996                 }
2997
2998                 /* Here it looks like a named character */
2999
3000                 if (PL_lex_inpat) {
3001
3002                     /* XXX This block is temporary code.  \N{} implies that the
3003                      * pattern is to have Unicode semantics, and therefore
3004                      * currently has to be encoded in utf8.  By putting it in
3005                      * utf8 now, we save a whole pass in the regular expression
3006                      * compiler.  Once that code is changed so Unicode
3007                      * semantics doesn't necessarily have to be in utf8, this
3008                      * block should be removed */
3009                     if (!has_utf8) {
3010                         SvCUR_set(sv, d - SvPVX_const(sv));
3011                         SvPOK_on(sv);
3012                         *d = '\0';
3013                         /* See Note on sizing above.  */
3014                         sv_utf8_upgrade_flags_grow(sv,
3015                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3016                                         /* 5 = '\N{' + cur char + NUL */
3017                                         (STRLEN)(send - s) + 5);
3018                         d = SvPVX(sv) + SvCUR(sv);
3019                         has_utf8 = TRUE;
3020                     }
3021                 }
3022
3023                 if (*s == 'U' && s[1] == '+') { /* \N{U+...} */
3024                     I32 flags = PERL_SCAN_ALLOW_UNDERSCORES
3025                                 | PERL_SCAN_DISALLOW_PREFIX;
3026                     STRLEN len;
3027
3028                     /* For \N{U+...}, the '...' is a unicode value even on
3029                      * EBCDIC machines */
3030                     s += 2;         /* Skip to next char after the 'U+' */
3031                     len = e - s;
3032                     uv = grok_hex(s, &len, &flags, NULL);
3033                     if (len == 0 || len != (STRLEN)(e - s)) {
3034                         yyerror("Invalid hexadecimal number in \\N{U+...}");
3035                         s = e + 1;
3036                         continue;
3037                     }
3038
3039                     if (PL_lex_inpat) {
3040
3041                         /* Pass through to the regex compiler unchanged.  The
3042                          * reason we evaluated the number above is to make sure
3043                          * there wasn't a syntax error. */
3044                         s -= 5;     /* Include the '\N{U+' */
3045                         Copy(s, d, e - s + 1, char);    /* 1 = include the } */
3046                         d += e - s + 1;
3047                     }
3048                     else {  /* Not a pattern: convert the hex to string */
3049
3050                          /* If destination is not in utf8, unconditionally
3051                           * recode it to be so.  This is because \N{} implies
3052                           * Unicode semantics, and scalars have to be in utf8
3053                           * to guarantee those semantics */
3054                         if (! has_utf8) {
3055                             SvCUR_set(sv, d - SvPVX_const(sv));
3056                             SvPOK_on(sv);
3057                             *d = '\0';
3058                             /* See Note on sizing above.  */
3059                             sv_utf8_upgrade_flags_grow(
3060                                         sv,
3061                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3062                                         UNISKIP(uv) + (STRLEN)(send - e) + 1);
3063                             d = SvPVX(sv) + SvCUR(sv);
3064                             has_utf8 = TRUE;
3065                         }
3066
3067                         /* Add the string to the output */
3068                         if (UNI_IS_INVARIANT(uv)) {
3069                             *d++ = (char) uv;
3070                         }
3071                         else d = (char*)uvuni_to_utf8((U8*)d, uv);
3072                     }
3073                 }
3074                 else { /* Here is \N{NAME} but not \N{U+...}. */
3075
3076                     SV *res;            /* result from charnames */
3077                     const char *str;    /* the string in 'res' */
3078                     STRLEN len;         /* its length */
3079
3080                     /* Get the value for NAME */
3081                     res = newSVpvn(s, e - s);
3082                     res = new_constant( NULL, 0, "charnames",
3083                                         /* includes all of: \N{...} */
3084                                         res, NULL, s - 3, e - s + 4 );
3085
3086                     /* Most likely res will be in utf8 already since the
3087                      * standard charnames uses pack U, but a custom translator
3088                      * can leave it otherwise, so make sure.  XXX This can be
3089                      * revisited to not have charnames use utf8 for characters
3090                      * that don't need it when regexes don't have to be in utf8
3091                      * for Unicode semantics.  If doing so, remember EBCDIC */
3092                     sv_utf8_upgrade(res);
3093                     str = SvPV_const(res, len);
3094
3095                     /* Don't accept malformed input */
3096                     if (! is_utf8_string((U8 *) str, len)) {
3097                         yyerror("Malformed UTF-8 returned by \\N");
3098                     }
3099                     else if (PL_lex_inpat) {
3100
3101                         if (! len) { /* The name resolved to an empty string */
3102                             Copy("\\N{}", d, 4, char);
3103                             d += 4;
3104                         }
3105                         else {
3106                             /* In order to not lose information for the regex
3107                             * compiler, pass the result in the specially made
3108                             * syntax: \N{U+c1.c2.c3...}, where c1 etc. are
3109                             * the code points in hex of each character
3110                             * returned by charnames */
3111
3112                             const char *str_end = str + len;
3113                             STRLEN char_length;     /* cur char's byte length */
3114                             STRLEN output_length;   /* and the number of bytes
3115                                                        after this is translated
3116                                                        into hex digits */
3117                             const STRLEN off = d - SvPVX_const(sv);
3118
3119                             /* 2 hex per byte; 2 chars for '\N'; 2 chars for
3120                              * max('U+', '.'); and 1 for NUL */
3121                             char hex_string[2 * UTF8_MAXBYTES + 5];
3122
3123                             /* Get the first character of the result. */
3124                             U32 uv = utf8n_to_uvuni((U8 *) str,
3125                                                     len,
3126                                                     &char_length,
3127                                                     UTF8_ALLOW_ANYUV);
3128
3129                             /* The call to is_utf8_string() above hopefully
3130                              * guarantees that there won't be an error.  But
3131                              * it's easy here to make sure.  The function just
3132                              * above warns and returns 0 if invalid utf8, but
3133                              * it can also return 0 if the input is validly a
3134                              * NUL. Disambiguate */
3135                             if (uv == 0 && NATIVE_TO_ASCII(*str) != '\0') {
3136                                 uv = UNICODE_REPLACEMENT;
3137                             }
3138
3139                             /* Convert first code point to hex, including the
3140                              * boiler plate before it */
3141                             sprintf(hex_string, "\\N{U+%X", (unsigned int) uv);
3142                             output_length = strlen(hex_string);
3143
3144                             /* Make sure there is enough space to hold it */
3145                             d = off + SvGROW(sv, off
3146                                                  + output_length
3147                                                  + (STRLEN)(send - e)
3148                                                  + 2);  /* '}' + NUL */
3149                             /* And output it */
3150                             Copy(hex_string, d, output_length, char);
3151                             d += output_length;
3152
3153                             /* For each subsequent character, append dot and
3154                              * its ordinal in hex */
3155                             while ((str += char_length) < str_end) {
3156                                 const STRLEN off = d - SvPVX_const(sv);
3157                                 U32 uv = utf8n_to_uvuni((U8 *) str,
3158                                                         str_end - str,
3159                                                         &char_length,
3160                                                         UTF8_ALLOW_ANYUV);
3161                                 if (uv == 0 && NATIVE_TO_ASCII(*str) != '\0') {
3162                                     uv = UNICODE_REPLACEMENT;
3163                                 }
3164
3165                                 sprintf(hex_string, ".%X", (unsigned int) uv);
3166                                 output_length = strlen(hex_string);
3167
3168                                 d = off + SvGROW(sv, off
3169                                                      + output_length
3170                                                      + (STRLEN)(send - e)
3171                                                      + 2);      /* '}' +  NUL */
3172                                 Copy(hex_string, d, output_length, char);
3173                                 d += output_length;
3174                             }
3175
3176                             *d++ = '}'; /* Done.  Add the trailing brace */
3177                         }
3178                     }
3179                     else { /* Here, not in a pattern.  Convert the name to a
3180                             * string. */
3181
3182                          /* If destination is not in utf8, unconditionally
3183                           * recode it to be so.  This is because \N{} implies
3184                           * Unicode semantics, and scalars have to be in utf8
3185                           * to guarantee those semantics */
3186                         if (! has_utf8) {
3187                             SvCUR_set(sv, d - SvPVX_const(sv));
3188                             SvPOK_on(sv);
3189                             *d = '\0';
3190                             /* See Note on sizing above.  */
3191                             sv_utf8_upgrade_flags_grow(sv,
3192                                                 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3193                                                 len + (STRLEN)(send - s) + 1);
3194                             d = SvPVX(sv) + SvCUR(sv);
3195                             has_utf8 = TRUE;
3196                         } else if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
3197
3198                             /* See Note on sizing above.  (NOTE: SvCUR() is not
3199                              * set correctly here). */
3200                             const STRLEN off = d - SvPVX_const(sv);
3201                             d = off + SvGROW(sv, off + len + (STRLEN)(send - s) + 1);
3202                         }
3203                         Copy(str, d, len, char);
3204                         d += len;
3205                     }
3206                     SvREFCNT_dec(res);
3207                 }
3208 #ifdef EBCDIC
3209                 if (!dorange) 
3210                     native_range = FALSE; /* \N{} is defined to be Unicode */
3211 #endif
3212                 s = e + 1;  /* Point to just after the '}' */
3213                 continue;
3214
3215             /* \c is a control character */
3216             case 'c':
3217                 s++;
3218                 if (s < send) {
3219                     U8 c = *s++;
3220 #ifdef EBCDIC
3221                     if (isLOWER(c))
3222                         c = toUPPER(c);
3223 #endif
3224                     *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
3225                 }
3226                 else {
3227                     yyerror("Missing control char name in \\c");
3228                 }
3229                 continue;
3230
3231             /* printf-style backslashes, formfeeds, newlines, etc */
3232             case 'b':
3233                 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
3234                 break;
3235             case 'n':
3236                 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
3237                 break;
3238             case 'r':
3239                 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
3240                 break;
3241             case 'f':
3242                 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
3243                 break;
3244             case 't':
3245                 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
3246                 break;
3247             case 'e':
3248                 *d++ = ASCII_TO_NEED(has_utf8,'\033');
3249                 break;
3250             case 'a':
3251                 *d++ = ASCII_TO_NEED(has_utf8,'\007');
3252                 break;
3253             } /* end switch */
3254
3255             s++;
3256             continue;
3257         } /* end if (backslash) */
3258 #ifdef EBCDIC
3259         else
3260             literal_endpoint++;
3261 #endif
3262
3263     default_action:
3264         /* If we started with encoded form, or already know we want it,
3265            then encode the next character */
3266         if (! NATIVE_IS_INVARIANT((U8)(*s)) && (this_utf8 || has_utf8)) {
3267             STRLEN len  = 1;
3268
3269
3270             /* One might think that it is wasted effort in the case of the
3271              * source being utf8 (this_utf8 == TRUE) to take the next character
3272              * in the source, convert it to an unsigned value, and then convert
3273              * it back again.  But the source has not been validated here.  The
3274              * routine that does the conversion checks for errors like
3275              * malformed utf8 */
3276
3277             const UV nextuv   = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
3278             const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
3279             if (!has_utf8) {
3280                 SvCUR_set(sv, d - SvPVX_const(sv));
3281                 SvPOK_on(sv);
3282                 *d = '\0';
3283                 /* See Note on sizing above.  */
3284                 sv_utf8_upgrade_flags_grow(sv,
3285                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
3286                                         need + (STRLEN)(send - s) + 1);
3287                 d = SvPVX(sv) + SvCUR(sv);
3288                 has_utf8 = TRUE;
3289             } else if (need > len) {
3290                 /* encoded value larger than old, may need extra space (NOTE:
3291                  * SvCUR() is not set correctly here).   See Note on sizing
3292                  * above.  */
3293                 const STRLEN off = d - SvPVX_const(sv);
3294                 d = SvGROW(sv, off + need + (STRLEN)(send - s) + 1) + off;
3295             }
3296             s += len;
3297
3298             d = (char*)uvchr_to_utf8((U8*)d, nextuv);
3299 #ifdef EBCDIC
3300             if (uv > 255 && !dorange)
3301                 native_range = FALSE;
3302 #endif
3303         }
3304         else {
3305             *d++ = NATIVE_TO_NEED(has_utf8,*s++);
3306         }
3307     } /* while loop to process each character */
3308
3309     /* terminate the string and set up the sv */
3310     *d = '\0';
3311     SvCUR_set(sv, d - SvPVX_const(sv));
3312     if (SvCUR(sv) >= SvLEN(sv))
3313         Perl_croak(aTHX_ "panic: constant overflowed allocated space");
3314
3315     SvPOK_on(sv);
3316     if (PL_encoding && !has_utf8) {
3317         sv_recode_to_utf8(sv, PL_encoding);
3318         if (SvUTF8(sv))
3319             has_utf8 = TRUE;
3320     }
3321     if (has_utf8) {
3322         SvUTF8_on(sv);
3323         if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
3324             PL_sublex_info.sub_op->op_private |=
3325                     (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
3326         }
3327     }
3328
3329     /* shrink the sv if we allocated more than we used */
3330     if (SvCUR(sv) + 5 < SvLEN(sv)) {
3331         SvPV_shrink_to_cur(sv);
3332     }
3333
3334     /* return the substring (via pl_yylval) only if we parsed anything */
3335     if (s > PL_bufptr) {
3336         if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) {
3337             const char *const key = PL_lex_inpat ? "qr" : "q";
3338             const STRLEN keylen = PL_lex_inpat ? 2 : 1;
3339             const char *type;
3340             STRLEN typelen;
3341
3342             if (PL_lex_inwhat == OP_TRANS) {
3343                 type = "tr";
3344                 typelen = 2;
3345             } else if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) {
3346                 type = "s";
3347                 typelen = 1;
3348             } else  {
3349                 type = "qq";
3350                 typelen = 2;
3351             }
3352
3353             sv = S_new_constant(aTHX_ start, s - start, key, keylen, sv, NULL,
3354                                 type, typelen);
3355         }
3356         pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3357     } else
3358         SvREFCNT_dec(sv);
3359     return s;
3360 }
3361
3362 /* S_intuit_more
3363  * Returns TRUE if there's more to the expression (e.g., a subscript),
3364  * FALSE otherwise.
3365  *
3366  * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
3367  *
3368  * ->[ and ->{ return TRUE
3369  * { and [ outside a pattern are always subscripts, so return TRUE
3370  * if we're outside a pattern and it's not { or [, then return FALSE
3371  * if we're in a pattern and the first char is a {
3372  *   {4,5} (any digits around the comma) returns FALSE
3373  * if we're in a pattern and the first char is a [
3374  *   [] returns FALSE
3375  *   [SOMETHING] has a funky algorithm to decide whether it's a
3376  *      character class or not.  It has to deal with things like
3377  *      /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
3378  * anything else returns TRUE
3379  */
3380
3381 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
3382
3383 STATIC int
3384 S_intuit_more(pTHX_ register char *s)
3385 {
3386     dVAR;
3387
3388     PERL_ARGS_ASSERT_INTUIT_MORE;
3389
3390     if (PL_lex_brackets)
3391         return TRUE;
3392     if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
3393         return TRUE;
3394     if (*s != '{' && *s != '[')
3395         return FALSE;
3396     if (!PL_lex_inpat)
3397         return TRUE;
3398
3399     /* In a pattern, so maybe we have {n,m}. */
3400     if (*s == '{') {
3401         s++;
3402         if (!isDIGIT(*s))
3403             return TRUE;
3404         while (isDIGIT(*s))
3405             s++;
3406         if (*s == ',')
3407             s++;
3408         while (isDIGIT(*s))
3409             s++;
3410         if (*s == '}')
3411             return FALSE;
3412         return TRUE;
3413         
3414     }
3415
3416     /* On the other hand, maybe we have a character class */
3417
3418     s++;
3419     if (*s == ']' || *s == '^')
3420         return FALSE;
3421     else {
3422         /* this is terrifying, and it works */
3423         int weight = 2;         /* let's weigh the evidence */
3424         char seen[256];
3425         unsigned char un_char = 255, last_un_char;
3426         const char * const send = strchr(s,']');
3427         char tmpbuf[sizeof PL_tokenbuf * 4];
3428
3429         if (!send)              /* has to be an expression */
3430             return TRUE;
3431
3432         Zero(seen,256,char);
3433         if (*s == '$')
3434             weight -= 3;
3435         else if (isDIGIT(*s)) {
3436             if (s[1] != ']') {
3437                 if (isDIGIT(s[1]) && s[2] == ']')
3438                     weight -= 10;
3439             }
3440             else
3441                 weight -= 100;
3442         }
3443         for (; s < send; s++) {
3444             last_un_char = un_char;
3445             un_char = (unsigned char)*s;
3446             switch (*s) {
3447             case '@':
3448             case '&':
3449             case '$':
3450                 weight -= seen[un_char] * 10;
3451                 if (isALNUM_lazy_if(s+1,UTF)) {
3452                     int len;
3453                     scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
3454                     len = (int)strlen(tmpbuf);
3455                     if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
3456                         weight -= 100;
3457                     else
3458                         weight -= 10;
3459                 }
3460                 else if (*s == '$' && s[1] &&
3461                   strchr("[#!%*<>()-=",s[1])) {
3462                     if (/*{*/ strchr("])} =",s[2]))
3463                         weight -= 10;
3464                     else
3465                         weight -= 1;
3466                 }
3467                 break;
3468             case '\\':
3469                 un_char = 254;
3470                 if (s[1]) {
3471                     if (strchr("wds]",s[1]))
3472                         weight += 100;
3473                     else if (seen[(U8)'\''] || seen[(U8)'"'])
3474                         weight += 1;
3475                     else if (strchr("rnftbxcav",s[1]))
3476                         weight += 40;
3477                     else if (isDIGIT(s[1])) {
3478                         weight += 40;
3479                         while (s[1] && isDIGIT(s[1]))
3480                             s++;
3481                     }
3482                 }
3483                 else
3484                     weight += 100;
3485                 break;
3486             case '-':
3487                 if (s[1] == '\\')
3488                     weight += 50;
3489                 if (strchr("aA01! ",last_un_char))
3490                     weight += 30;
3491                 if (strchr("zZ79~",s[1]))
3492                     weight += 30;
3493                 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
3494                     weight -= 5;        /* cope with negative subscript */
3495                 break;
3496             default:
3497                 if (!isALNUM(last_un_char)
3498                     && !(last_un_char == '$' || last_un_char == '@'
3499                          || last_un_char == '&')
3500                     && isALPHA(*s) && s[1] && isALPHA(s[1])) {
3501                     char *d = tmpbuf;
3502                     while (isALPHA(*s))
3503                         *d++ = *s++;
3504                     *d = '\0';
3505                     if (keyword(tmpbuf, d - tmpbuf, 0))
3506                         weight -= 150;
3507                 }
3508                 if (un_char == last_un_char + 1)
3509                     weight += 5;
3510                 weight -= seen[un_char];
3511                 break;
3512             }
3513             seen[un_char]++;
3514         }
3515         if (weight >= 0)        /* probably a character class */
3516             return FALSE;
3517     }
3518
3519     return TRUE;
3520 }
3521
3522 /*
3523  * S_intuit_method
3524  *
3525  * Does all the checking to disambiguate
3526  *   foo bar
3527  * between foo(bar) and bar->foo.  Returns 0 if not a method, otherwise
3528  * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
3529  *
3530  * First argument is the stuff after the first token, e.g. "bar".
3531  *
3532  * Not a method if bar is a filehandle.
3533  * Not a method if foo is a subroutine prototyped to take a filehandle.
3534  * Not a method if it's really "Foo $bar"
3535  * Method if it's "foo $bar"
3536  * Not a method if it's really "print foo $bar"
3537  * Method if it's really "foo package::" (interpreted as package->foo)
3538  * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
3539  * Not a method if bar is a filehandle or package, but is quoted with
3540  *   =>
3541  */
3542
3543 STATIC int
3544 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
3545 {
3546     dVAR;
3547     char *s = start + (*start == '$');
3548     char tmpbuf[sizeof PL_tokenbuf];
3549     STRLEN len;
3550     GV* indirgv;
3551 #ifdef PERL_MAD
3552     int soff;
3553 #endif
3554
3555     PERL_ARGS_ASSERT_INTUIT_METHOD;
3556
3557     if (gv) {
3558         if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
3559             return 0;
3560         if (cv) {
3561             if (SvPOK(cv)) {
3562                 const char *proto = SvPVX_const(cv);
3563                 if (proto) {
3564                     if (*proto == ';')
3565                         proto++;
3566                     if (*proto == '*')
3567                         return 0;
3568                 }
3569             }
3570         } else
3571             gv = NULL;
3572     }
3573     s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
3574     /* start is the beginning of the possible filehandle/object,
3575      * and s is the end of it
3576      * tmpbuf is a copy of it
3577      */
3578
3579     if (*start == '$') {
3580         if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
3581                 isUPPER(*PL_tokenbuf))
3582             return 0;
3583 #ifdef PERL_MAD
3584         len = start - SvPVX(PL_linestr);
3585 #endif
3586         s = PEEKSPACE(s);
3587 #ifdef PERL_MAD
3588         start = SvPVX(PL_linestr) + len;
3589 #endif
3590         PL_bufptr = start;
3591         PL_expect = XREF;
3592         return *s == '(' ? FUNCMETH : METHOD;
3593     }
3594     if (!keyword(tmpbuf, len, 0)) {
3595         if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
3596             len -= 2;
3597             tmpbuf[len] = '\0';
3598 #ifdef PERL_MAD
3599             soff = s - SvPVX(PL_linestr);
3600 #endif
3601             goto bare_package;
3602         }
3603         indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
3604         if (indirgv && GvCVu(indirgv))
3605             return 0;
3606         /* filehandle or package name makes it a method */
3607         if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
3608 #ifdef PERL_MAD
3609             soff = s - SvPVX(PL_linestr);
3610 #endif
3611             s = PEEKSPACE(s);
3612             if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
3613                 return 0;       /* no assumptions -- "=>" quotes bearword */
3614       bare_package:
3615             start_force(PL_curforce);
3616             NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
3617                                                   S_newSV_maybe_utf8(aTHX_ tmpbuf, len));
3618             NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
3619             if (PL_madskills)
3620                 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
3621             PL_expect = XTERM;
3622             force_next(WORD);
3623             PL_bufptr = s;
3624 #ifdef PERL_MAD
3625             PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
3626 #endif
3627             return *s == '(' ? FUNCMETH : METHOD;
3628         }
3629     }
3630     return 0;
3631 }
3632
3633 /* Encoded script support. filter_add() effectively inserts a
3634  * 'pre-processing' function into the current source input stream.
3635  * Note that the filter function only applies to the current source file
3636  * (e.g., it will not affect files 'require'd or 'use'd by this one).
3637  *
3638  * The datasv parameter (which may be NULL) can be used to pass
3639  * private data to this instance of the filter. The filter function
3640  * can recover the SV using the FILTER_DATA macro and use it to
3641  * store private buffers and state information.
3642  *
3643  * The supplied datasv parameter is upgraded to a PVIO type
3644  * and the IoDIRP/IoANY field is used to store the function pointer,
3645  * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
3646  * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
3647  * private use must be set using malloc'd pointers.
3648  */
3649
3650 SV *
3651 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
3652 {
3653     dVAR;
3654     if (!funcp)
3655         return NULL;
3656
3657     if (!PL_parser)
3658         return NULL;
3659
3660     if (!PL_rsfp_filters)
3661         PL_rsfp_filters = newAV();
3662     if (!datasv)
3663         datasv = newSV(0);
3664     SvUPGRADE(datasv, SVt_PVIO);
3665     IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
3666     IoFLAGS(datasv) |= IOf_FAKE_DIRP;
3667     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
3668                           FPTR2DPTR(void *, IoANY(datasv)),
3669                           SvPV_nolen(datasv)));
3670     av_unshift(PL_rsfp_filters, 1);
3671     av_store(PL_rsfp_filters, 0, datasv) ;
3672     return(datasv);
3673 }
3674
3675
3676 /* Delete most recently added instance of this filter function. */
3677 void
3678 Perl_filter_del(pTHX_ filter_t funcp)
3679 {
3680     dVAR;
3681     SV *datasv;
3682
3683     PERL_ARGS_ASSERT_FILTER_DEL;
3684
3685 #ifdef DEBUGGING
3686     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
3687                           FPTR2DPTR(void*, funcp)));
3688 #endif
3689     if (!PL_parser || !PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
3690         return;
3691     /* if filter is on top of stack (usual case) just pop it off */
3692     datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
3693     if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
3694         IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
3695         IoANY(datasv) = (void *)NULL;
3696         sv_free(av_pop(PL_rsfp_filters));
3697
3698         return;
3699     }
3700     /* we need to search for the correct entry and clear it     */
3701     Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
3702 }
3703
3704
3705 /* Invoke the idxth filter function for the current rsfp.        */
3706 /* maxlen 0 = read one text line */
3707 I32
3708 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
3709 {
3710     dVAR;
3711     filter_t funcp;
3712     SV *datasv = NULL;
3713     /* This API is bad. It should have been using unsigned int for maxlen.
3714        Not sure if we want to change the API, but if not we should sanity
3715        check the value here.  */
3716     const unsigned int correct_length
3717         = maxlen < 0 ?
3718 #ifdef PERL_MICRO
3719         0x7FFFFFFF
3720 #else
3721         INT_MAX
3722 #endif
3723         : maxlen;
3724
3725     PERL_ARGS_ASSERT_FILTER_READ;
3726
3727     if (!PL_parser || !PL_rsfp_filters)
3728         return -1;
3729     if (idx > AvFILLp(PL_rsfp_filters)) {       /* Any more filters?    */
3730         /* Provide a default input filter to make life easy.    */
3731         /* Note that we append to the line. This is handy.      */
3732         DEBUG_P(PerlIO_printf(Perl_debug_log,
3733                               "filter_read %d: from rsfp\n", idx));
3734         if (correct_length) {
3735             /* Want a block */
3736             int len ;
3737             const int old_len = SvCUR(buf_sv);
3738
3739             /* ensure buf_sv is large enough */
3740             SvGROW(buf_sv, (STRLEN)(old_len + correct_length + 1)) ;
3741             if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
3742                                    correct_length)) <= 0) {
3743                 if (PerlIO_error(PL_rsfp))
3744                     return -1;          /* error */
3745                 else
3746                     return 0 ;          /* end of file */
3747             }
3748             SvCUR_set(buf_sv, old_len + len) ;
3749             SvPVX(buf_sv)[old_len + len] = '\0';
3750         } else {
3751             /* Want a line */
3752             if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
3753                 if (PerlIO_error(PL_rsfp))
3754                     return -1;          /* error */
3755                 else
3756                     return 0 ;          /* end of file */
3757             }
3758         }
3759         return SvCUR(buf_sv);
3760     }
3761     /* Skip this filter slot if filter has been deleted */
3762     if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
3763         DEBUG_P(PerlIO_printf(Perl_debug_log,
3764                               "filter_read %d: skipped (filter deleted)\n",
3765                               idx));
3766         return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
3767     }
3768     /* Get function pointer hidden within datasv        */
3769     funcp = DPTR2FPTR(filter_t, IoANY(datasv));
3770     DEBUG_P(PerlIO_printf(Perl_debug_log,
3771                           "filter_read %d: via function %p (%s)\n",
3772                           idx, (void*)datasv, SvPV_nolen_const(datasv)));
3773     /* Call function. The function is expected to       */
3774     /* call "FILTER_READ(idx+1, buf_sv)" first.         */
3775     /* Return: <0:error, =0:eof, >0:not eof             */
3776     return (*funcp)(aTHX_ idx, buf_sv, correct_length);
3777 }
3778
3779 STATIC char *
3780 S_filter_gets(pTHX_ register SV *sv, STRLEN append)
3781 {
3782     dVAR;
3783
3784     PERL_ARGS_ASSERT_FILTER_GETS;
3785
3786 #ifdef PERL_CR_FILTER
3787     if (!PL_rsfp_filters) {
3788         filter_add(S_cr_textfilter,NULL);
3789     }
3790 #endif
3791     if (PL_rsfp_filters) {
3792         if (!append)
3793             SvCUR_set(sv, 0);   /* start with empty line        */
3794         if (FILTER_READ(0, sv, 0) > 0)
3795             return ( SvPVX(sv) ) ;
3796         else
3797             return NULL ;
3798     }
3799     else
3800         return (sv_gets(sv, PL_rsfp, append));
3801 }
3802
3803 STATIC HV *
3804 S_find_in_my_stash(pTHX_ const char *pkgname, STRLEN len)
3805 {
3806     dVAR;
3807     GV *gv;
3808
3809     PERL_ARGS_ASSERT_FIND_IN_MY_STASH;
3810
3811     if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
3812         return PL_curstash;
3813
3814     if (len > 2 &&
3815         (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
3816         (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
3817     {
3818         return GvHV(gv);                        /* Foo:: */
3819     }
3820
3821     /* use constant CLASS => 'MyClass' */
3822     gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
3823     if (gv && GvCV(gv)) {
3824         SV * const sv = cv_const_sv(GvCV(gv));
3825         if (sv)
3826             pkgname = SvPV_const(sv, len);
3827     }
3828
3829     return gv_stashpvn(pkgname, len, 0);
3830 }
3831
3832 /*
3833  * S_readpipe_override
3834  * Check whether readpipe() is overriden, and generates the appropriate
3835  * optree, provided sublex_start() is called afterwards.
3836  */
3837 STATIC void
3838 S_readpipe_override(pTHX)
3839 {
3840     GV **gvp;
3841     GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
3842     pl_yylval.ival = OP_BACKTICK;
3843     if ((gv_readpipe
3844                 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
3845             ||
3846             ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
3847              && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
3848              && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
3849     {
3850         PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
3851             append_elem(OP_LIST,
3852                 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
3853                 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
3854     }
3855 }
3856
3857 #ifdef PERL_MAD 
3858  /*
3859  * Perl_madlex
3860  * The intent of this yylex wrapper is to minimize the changes to the
3861  * tokener when we aren't interested in collecting madprops.  It remains
3862  * to be seen how successful this strategy will be...
3863  */
3864
3865 int
3866 Perl_madlex(pTHX)
3867 {
3868     int optype;
3869     char *s = PL_bufptr;
3870
3871     /* make sure PL_thiswhite is initialized */
3872     PL_thiswhite = 0;
3873     PL_thismad = 0;
3874
3875     /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
3876     if (PL_pending_ident)
3877         return S_pending_ident(aTHX);
3878
3879     /* previous token ate up our whitespace? */
3880     if (!PL_lasttoke && PL_nextwhite) {
3881         PL_thiswhite = PL_nextwhite;
3882         PL_nextwhite = 0;
3883     }
3884
3885     /* isolate the token, and figure out where it is without whitespace */
3886     PL_realtokenstart = -1;
3887     PL_thistoken = 0;
3888     optype = yylex();
3889     s = PL_bufptr;
3890     assert(PL_curforce < 0);
3891
3892     if (!PL_thismad || PL_thismad->mad_key == '^') {    /* not forced already? */
3893         if (!PL_thistoken) {
3894             if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
3895                 PL_thistoken = newSVpvs("");
3896             else {
3897                 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
3898                 PL_thistoken = newSVpvn(tstart, s - tstart);
3899             }
3900         }
3901         if (PL_thismad) /* install head */
3902             CURMAD('X', PL_thistoken);
3903     }
3904
3905     /* last whitespace of a sublex? */
3906     if (optype == ')' && PL_endwhite) {
3907         CURMAD('X', PL_endwhite);
3908     }
3909
3910     if (!PL_thismad) {
3911
3912         /* if no whitespace and we're at EOF, bail.  Otherwise fake EOF below. */
3913         if (!PL_thiswhite && !PL_endwhite && !optype) {
3914             sv_free(PL_thistoken);
3915             PL_thistoken = 0;
3916             return 0;
3917         }
3918
3919         /* put off final whitespace till peg */
3920         if (optype == ';' && !PL_rsfp) {
3921             PL_nextwhite = PL_thiswhite;
3922             PL_thiswhite = 0;
3923         }
3924         else if (PL_thisopen) {
3925             CURMAD('q', PL_thisopen);
3926             if (PL_thistoken)
3927                 sv_free(PL_thistoken);
3928             PL_thistoken = 0;
3929         }
3930         else {
3931             /* Store actual token text as madprop X */
3932             CURMAD('X', PL_thistoken);
3933         }
3934
3935         if (PL_thiswhite) {
3936             /* add preceding whitespace as madprop _ */
3937             CURMAD('_', PL_thiswhite);
3938         }
3939
3940         if (PL_thisstuff) {
3941             /* add quoted material as madprop = */
3942             CURMAD('=', PL_thisstuff);
3943         }
3944
3945         if (PL_thisclose) {
3946             /* add terminating quote as madprop Q */
3947             CURMAD('Q', PL_thisclose);
3948         }
3949     }
3950
3951     /* special processing based on optype */
3952
3953     switch (optype) {
3954
3955     /* opval doesn't need a TOKEN since it can already store mp */
3956     case WORD:
3957     case METHOD:
3958     case FUNCMETH:
3959     case THING:
3960     case PMFUNC:
3961     case PRIVATEREF:
3962     case FUNC0SUB:
3963     case UNIOPSUB:
3964     case LSTOPSUB:
3965         if (pl_yylval.opval)
3966             append_madprops(PL_thismad, pl_yylval.opval, 0);
3967         PL_thismad = 0;
3968         return optype;
3969
3970     /* fake EOF */
3971     case 0:
3972         optype = PEG;
3973         if (PL_endwhite) {
3974             addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3975             PL_endwhite = 0;
3976         }
3977         break;
3978
3979     case ']':
3980     case '}':
3981         if (PL_faketokens)
3982             break;
3983         /* remember any fake bracket that lexer is about to discard */ 
3984         if (PL_lex_brackets == 1 &&
3985             ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3986         {
3987             s = PL_bufptr;
3988             while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3989                 s++;
3990             if (*s == '}') {
3991                 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3992                 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3993                 PL_thiswhite = 0;
3994                 PL_bufptr = s - 1;
3995                 break;  /* don't bother looking for trailing comment */
3996             }
3997             else
3998                 s = PL_bufptr;
3999         }
4000         if (optype == ']')
4001             break;
4002         /* FALLTHROUGH */
4003
4004     /* attach a trailing comment to its statement instead of next token */
4005     case ';':
4006         if (PL_faketokens)
4007             break;
4008         if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
4009             s = PL_bufptr;
4010             while (s < PL_bufend && (*s == ' ' || *s == '\t'))
4011                 s++;
4012             if (*s == '\n' || *s == '#') {
4013                 while (s < PL_bufend && *s != '\n')
4014                     s++;
4015                 if (s < PL_bufend)
4016                     s++;
4017                 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
4018                 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
4019                 PL_thiswhite = 0;
4020                 PL_bufptr = s;
4021             }
4022         }
4023         break;
4024
4025     /* pval */
4026     case LABEL:
4027         break;
4028
4029     /* ival */
4030     default:
4031         break;
4032
4033     }
4034
4035     /* Create new token struct.  Note: opvals return early above. */
4036     pl_yylval.tkval = newTOKEN(optype, pl_yylval, PL_thismad);
4037     PL_thismad = 0;
4038     return optype;
4039 }
4040 #endif
4041
4042 STATIC char *
4043 S_tokenize_use(pTHX_ int is_use, char *s) {
4044     dVAR;
4045
4046     PERL_ARGS_ASSERT_TOKENIZE_USE;
4047
4048     if (PL_expect != XSTATE)
4049         yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
4050                     is_use ? "use" : "no"));
4051     s = SKIPSPACE1(s);
4052     if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
4053         s = force_version(s, TRUE);
4054         if (*s == ';' || *s == '}'
4055                 || (s = SKIPSPACE1(s), (*s == ';' || *s == '}'))) {
4056             start_force(PL_curforce);
4057             NEXTVAL_NEXTTOKE.opval = NULL;
4058             force_next(WORD);
4059         }
4060         else if (*s == 'v') {
4061             s = force_word(s,WORD,FALSE,TRUE,FALSE);
4062             s = force_version(s, FALSE);
4063         }
4064     }
4065     else {
4066         s = force_word(s,WORD,FALSE,TRUE,FALSE);
4067         s = force_version(s, FALSE);
4068     }
4069     pl_yylval.ival = is_use;
4070     return s;
4071 }
4072 #ifdef DEBUGGING
4073     static const char* const exp_name[] =
4074         { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
4075           "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
4076         };
4077 #endif
4078
4079 /*
4080   yylex
4081
4082   Works out what to call the token just pulled out of the input
4083   stream.  The yacc parser takes care of taking the ops we return and
4084   stitching them into a tree.
4085
4086   Returns:
4087     PRIVATEREF
4088
4089   Structure:
4090       if read an identifier
4091           if we're in a my declaration
4092               croak if they tried to say my($foo::bar)
4093               build the ops for a my() declaration
4094           if it's an access to a my() variable
4095               are we in a sort block?
4096                   croak if my($a); $a <=> $b
4097               build ops for access to a my() variable
4098           if in a dq string, and they've said @foo and we can't find @foo
4099               croak
4100           build ops for a bareword
4101       if we already built the token before, use it.
4102 */
4103
4104
4105 #ifdef __SC__
4106 #pragma segment Perl_yylex
4107 #endif
4108 int
4109 Perl_yylex(pTHX)
4110 {
4111     dVAR;
4112     register char *s = PL_bufptr;
4113     register char *d;
4114     STRLEN len;
4115     bool bof = FALSE;
4116     U32 fake_eof = 0;
4117
4118     /* orig_keyword, gvp, and gv are initialized here because
4119      * jump to the label just_a_word_zero can bypass their
4120      * initialization later. */
4121     I32 orig_keyword = 0;
4122     GV *gv = NULL;
4123     GV **gvp = NULL;
4124
4125     DEBUG_T( {
4126         SV* tmp = newSVpvs("");
4127         PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
4128             (IV)CopLINE(PL_curcop),
4129             lex_state_names[PL_lex_state],
4130             exp_name[PL_expect],
4131             pv_display(tmp, s, strlen(s), 0, 60));
4132         SvREFCNT_dec(tmp);
4133     } );
4134     /* check if there's an identifier for us to look at */
4135     if (PL_pending_ident)
4136         return REPORT(S_pending_ident(aTHX));
4137
4138     /* no identifier pending identification */
4139
4140     switch (PL_lex_state) {
4141 #ifdef COMMENTARY
4142     case LEX_NORMAL:            /* Some compilers will produce faster */
4143     case LEX_INTERPNORMAL:      /* code if we comment these out. */
4144         break;
4145 #endif
4146
4147     /* when we've already built the next token, just pull it out of the queue */
4148     case LEX_KNOWNEXT:
4149 #ifdef PERL_MAD
4150         PL_lasttoke--;
4151         pl_yylval = PL_nexttoke[PL_lasttoke].next_val;
4152         if (PL_madskills) {
4153             PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
4154             PL_nexttoke[PL_lasttoke].next_mad = 0;
4155             if (PL_thismad && PL_thismad->mad_key == '_') {
4156                 PL_thiswhite = MUTABLE_SV(PL_thismad->mad_val);
4157                 PL_thismad->mad_val = 0;
4158                 mad_free(PL_thismad);
4159                 PL_thismad = 0;
4160             }
4161         }
4162         if (!PL_lasttoke) {
4163             PL_lex_state = PL_lex_defer;
4164             PL_expect = PL_lex_expect;
4165             PL_lex_defer = LEX_NORMAL;
4166             if (!PL_nexttoke[PL_lasttoke].next_type)
4167                 return yylex();
4168         }
4169 #else
4170         PL_nexttoke--;
4171         pl_yylval = PL_nextval[PL_nexttoke];
4172         if (!PL_nexttoke) {
4173             PL_lex_state = PL_lex_defer;
4174             PL_expect = PL_lex_expect;
4175             PL_lex_defer = LEX_NORMAL;
4176         }
4177 #endif
4178 #ifdef PERL_MAD
4179         /* FIXME - can these be merged?  */
4180         return(PL_nexttoke[PL_lasttoke].next_type);
4181 #else
4182         return REPORT(PL_nexttype[PL_nexttoke]);
4183 #endif
4184
4185     /* interpolated case modifiers like \L \U, including \Q and \E.
4186        when we get here, PL_bufptr is at the \
4187     */
4188     case LEX_INTERPCASEMOD:
4189 #ifdef DEBUGGING
4190         if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
4191             Perl_croak(aTHX_ "panic: INTERPCASEMOD");
4192 #endif
4193         /* handle \E or end of string */
4194         if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
4195             /* if at a \E */
4196             if (PL_lex_casemods) {
4197                 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
4198                 PL_lex_casestack[PL_lex_casemods] = '\0';
4199
4200                 if (PL_bufptr != PL_bufend
4201                     && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
4202                     PL_bufptr += 2;
4203                     PL_lex_state = LEX_INTERPCONCAT;
4204 #ifdef PERL_MAD
4205                     if (PL_madskills)
4206                         PL_thistoken = newSVpvs("\\E");
4207 #endif
4208                 }
4209                 return REPORT(')');
4210             }
4211 #ifdef PERL_MAD
4212             while (PL_bufptr != PL_bufend &&
4213               PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
4214                 if (!PL_thiswhite)
4215                     PL_thiswhite = newSVpvs("");
4216                 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
4217                 PL_bufptr += 2;
4218             }
4219 #else
4220             if (PL_bufptr != PL_bufend)
4221                 PL_bufptr += 2;
4222 #endif
4223             PL_lex_state = LEX_INTERPCONCAT;
4224             return yylex();
4225         }
4226         else {
4227             DEBUG_T({ PerlIO_printf(Perl_debug_log,
4228               "### Saw case modifier\n"); });
4229             s = PL_bufptr + 1;
4230             if (s[1] == '\\' && s[2] == 'E') {
4231 #ifdef PERL_MAD
4232                 if (!PL_thiswhite)
4233                     PL_thiswhite = newSVpvs("");
4234                 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
4235 #endif
4236                 PL_bufptr = s + 3;
4237                 PL_lex_state = LEX_INTERPCONCAT;
4238                 return yylex();
4239             }
4240             else {
4241                 I32 tmp;
4242                 if (!PL_madskills) /* when just compiling don't need correct */
4243                     if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
4244                         tmp = *s, *s = s[2], s[2] = (char)tmp;  /* misordered... */
4245                 if ((*s == 'L' || *s == 'U') &&
4246                     (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
4247                     PL_lex_casestack[--PL_lex_casemods] = '\0';
4248                     return REPORT(')');
4249                 }
4250                 if (PL_lex_casemods > 10)
4251                     Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
4252                 PL_lex_casestack[PL_lex_casemods++] = *s;
4253                 PL_lex_casestack[PL_lex_casemods] = '\0';
4254                 PL_lex_state = LEX_INTERPCONCAT;
4255                 start_force(PL_curforce);
4256                 NEXTVAL_NEXTTOKE.ival = 0;
4257                 force_next('(');
4258                 start_force(PL_curforce);
4259                 if (*s == 'l')
4260                     NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
4261                 else if (*s == 'u')
4262                     NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
4263                 else if (*s == 'L')
4264                     NEXTVAL_NEXTTOKE.ival = OP_LC;
4265                 else if (*s == 'U')
4266                     NEXTVAL_NEXTTOKE.ival = OP_UC;
4267                 else if (*s == 'Q')
4268                     NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
4269                 else
4270                     Perl_croak(aTHX_ "panic: yylex");
4271                 if (PL_madskills) {
4272                     SV* const tmpsv = newSVpvs("\\ ");
4273                     /* replace the space with the character we want to escape
4274                      */
4275                     SvPVX(tmpsv)[1] = *s;
4276                     curmad('_', tmpsv);
4277                 }
4278                 PL_bufptr = s + 1;
4279             }
4280             force_next(FUNC);
4281             if (PL_lex_starts) {
4282                 s = PL_bufptr;
4283                 PL_lex_starts = 0;
4284 #ifdef PERL_MAD
4285                 if (PL_madskills) {
4286                     if (PL_thistoken)
4287                         sv_free(PL_thistoken);
4288                     PL_thistoken = newSVpvs("");
4289                 }
4290 #endif
4291                 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4292                 if (PL_lex_casemods == 1 && PL_lex_inpat)
4293                     OPERATOR(',');
4294                 else
4295                     Aop(OP_CONCAT);
4296             }
4297             else
4298                 return yylex();
4299         }
4300
4301     case LEX_INTERPPUSH:
4302         return REPORT(sublex_push());
4303
4304     case LEX_INTERPSTART:
4305         if (PL_bufptr == PL_bufend)
4306             return REPORT(sublex_done());
4307         DEBUG_T({ PerlIO_printf(Perl_debug_log,
4308               "### Interpolated variable\n"); });
4309         PL_expect = XTERM;
4310         PL_lex_dojoin = (*PL_bufptr == '@');
4311         PL_lex_state = LEX_INTERPNORMAL;
4312         if (PL_lex_dojoin) {
4313             start_force(PL_curforce);
4314             NEXTVAL_NEXTTOKE.ival = 0;
4315             force_next(',');
4316             start_force(PL_curforce);
4317             force_ident("\"", '$');
4318             start_force(PL_curforce);
4319             NEXTVAL_NEXTTOKE.ival = 0;
4320             force_next('$');
4321             start_force(PL_curforce);
4322             NEXTVAL_NEXTTOKE.ival = 0;
4323             force_next('(');
4324             start_force(PL_curforce);
4325             NEXTVAL_NEXTTOKE.ival = OP_JOIN;    /* emulate join($", ...) */
4326             force_next(FUNC);
4327         }
4328         if (PL_lex_starts++) {
4329             s = PL_bufptr;
4330 #ifdef PERL_MAD
4331             if (PL_madskills) {
4332                 if (PL_thistoken)
4333                     sv_free(PL_thistoken);
4334                 PL_thistoken = newSVpvs("");
4335             }
4336 #endif
4337             /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4338             if (!PL_lex_casemods && PL_lex_inpat)
4339                 OPERATOR(',');
4340             else
4341                 Aop(OP_CONCAT);
4342         }
4343         return yylex();
4344
4345     case LEX_INTERPENDMAYBE:
4346         if (intuit_more(PL_bufptr)) {
4347             PL_lex_state = LEX_INTERPNORMAL;    /* false alarm, more expr */
4348             break;
4349         }
4350         /* FALL THROUGH */
4351
4352     case LEX_INTERPEND:
4353         if (PL_lex_dojoin) {
4354             PL_lex_dojoin = FALSE;
4355             PL_lex_state = LEX_INTERPCONCAT;
4356 #ifdef PERL_MAD
4357             if (PL_madskills) {
4358                 if (PL_thistoken)
4359                     sv_free(PL_thistoken);
4360                 PL_thistoken = newSVpvs("");
4361             }
4362 #endif
4363             return REPORT(')');
4364         }
4365         if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
4366             && SvEVALED(PL_lex_repl))
4367         {
4368             if (PL_bufptr != PL_bufend)
4369                 Perl_croak(aTHX_ "Bad evalled substitution pattern");
4370             PL_lex_repl = NULL;
4371         }
4372         /* FALLTHROUGH */
4373     case LEX_INTERPCONCAT:
4374 #ifdef DEBUGGING
4375         if (PL_lex_brackets)
4376             Perl_croak(aTHX_ "panic: INTERPCONCAT");
4377 #endif
4378         if (PL_bufptr == PL_bufend)
4379             return REPORT(sublex_done());
4380
4381         if (SvIVX(PL_linestr) == '\'') {
4382             SV *sv = newSVsv(PL_linestr);
4383             if (!PL_lex_inpat)
4384                 sv = tokeq(sv);
4385             else if ( PL_hints & HINT_NEW_RE )
4386                 sv = new_constant(NULL, 0, "qr", sv, sv, "q", 1);
4387             pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
4388             s = PL_bufend;
4389         }
4390         else {
4391             s = scan_const(PL_bufptr);
4392             if (*s == '\\')
4393                 PL_lex_state = LEX_INTERPCASEMOD;
4394             else
4395                 PL_lex_state = LEX_INTERPSTART;
4396         }
4397
4398         if (s != PL_bufptr) {
4399             start_force(PL_curforce);
4400             if (PL_madskills) {
4401                 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
4402             }
4403             NEXTVAL_NEXTTOKE = pl_yylval;
4404             PL_expect = XTERM;
4405             force_next(THING);
4406             if (PL_lex_starts++) {
4407 #ifdef PERL_MAD
4408                 if (PL_madskills) {
4409                     if (PL_thistoken)
4410                         sv_free(PL_thistoken);
4411                     PL_thistoken = newSVpvs("");
4412                 }
4413 #endif
4414                 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
4415                 if (!PL_lex_casemods && PL_lex_inpat)
4416                     OPERATOR(',');
4417                 else
4418                     Aop(OP_CONCAT);
4419             }
4420             else {
4421                 PL_bufptr = s;
4422                 return yylex();
4423             }
4424         }
4425
4426         return yylex();
4427     case LEX_FORMLINE:
4428         PL_lex_state = LEX_NORMAL;
4429         s = scan_formline(PL_bufptr);
4430         if (!PL_lex_formbrack)
4431             goto rightbracket;
4432         OPERATOR(';');
4433     }
4434
4435     s = PL_bufptr;
4436     PL_oldoldbufptr = PL_oldbufptr;
4437     PL_oldbufptr = s;
4438
4439   retry:
4440 #ifdef PERL_MAD
4441     if (PL_thistoken) {
4442         sv_free(PL_thistoken);
4443         PL_thistoken = 0;
4444     }
4445     PL_realtokenstart = s - SvPVX(PL_linestr);  /* assume but undo on ws */
4446 #endif
4447     switch (*s) {
4448     default:
4449         if (isIDFIRST_lazy_if(s,UTF))
4450             goto keylookup;
4451         {
4452         unsigned char c = *s;
4453         len = UTF ? Perl_utf8_length(aTHX_ (U8 *) PL_linestart, (U8 *) s) : (STRLEN) (s - PL_linestart);
4454         if (len > UNRECOGNIZED_PRECEDE_COUNT) {
4455             d = UTF ? (char *) Perl_utf8_hop(aTHX_ (U8 *) s, -UNRECOGNIZED_PRECEDE_COUNT) : s - UNRECOGNIZED_PRECEDE_COUNT;
4456         } else {
4457             d = PL_linestart;
4458         }       
4459         *s = '\0';
4460         Perl_croak(aTHX_ "Unrecognized character \\x%02X; marked by <-- HERE after %s<-- HERE near column %d", c, d, (int) len + 1);
4461     }
4462     case 4:
4463     case 26:
4464         goto fake_eof;                  /* emulate EOF on ^D or ^Z */
4465     case 0:
4466 #ifdef PERL_MAD
4467         if (PL_madskills)
4468             PL_faketokens = 0;
4469 #endif
4470         if (!PL_rsfp) {
4471             PL_last_uni = 0;
4472             PL_last_lop = 0;
4473             if (PL_lex_brackets) {
4474                 yyerror((const char *)
4475                         (PL_lex_formbrack
4476                          ? "Format not terminated"
4477                          : "Missing right curly or square bracket"));
4478             }
4479             DEBUG_T( { PerlIO_printf(Perl_debug_log,
4480                         "### Tokener got EOF\n");
4481             } );
4482             TOKEN(0);
4483         }
4484         if (s++ < PL_bufend)
4485             goto retry;                 /* ignore stray nulls */
4486         PL_last_uni = 0;
4487         PL_last_lop = 0;
4488         if (!PL_in_eval && !PL_preambled) {
4489             PL_preambled = TRUE;
4490 #ifdef PERL_MAD
4491             if (PL_madskills)
4492                 PL_faketokens = 1;
4493 #endif
4494             if (PL_perldb) {
4495                 /* Generate a string of Perl code to load the debugger.
4496                  * If PERL5DB is set, it will return the contents of that,
4497                  * otherwise a compile-time require of perl5db.pl.  */
4498
4499                 const char * const pdb = PerlEnv_getenv("PERL5DB");
4500
4501                 if (pdb) {
4502                     sv_setpv(PL_linestr, pdb);
4503                     sv_catpvs(PL_linestr,";");
4504                 } else {
4505                     SETERRNO(0,SS_NORMAL);
4506                     sv_setpvs(PL_linestr, "BEGIN { require 'perl5db.pl' };");
4507                 }
4508             } else
4509                 sv_setpvs(PL_linestr,"");
4510             if (PL_preambleav) {
4511                 SV **svp = AvARRAY(PL_preambleav);
4512                 SV **const end = svp + AvFILLp(PL_preambleav);
4513                 while(svp <= end) {
4514                     sv_catsv(PL_linestr, *svp);
4515                     ++svp;
4516                     sv_catpvs(PL_linestr, ";");
4517                 }
4518                 sv_free(MUTABLE_SV(PL_preambleav));
4519                 PL_preambleav = NULL;
4520             }
4521             if (PL_minus_E)
4522                 sv_catpvs(PL_linestr,
4523                           "use feature ':5." STRINGIFY(PERL_VERSION) "';");
4524             if (PL_minus_n || PL_minus_p) {
4525                 sv_catpvs(PL_linestr, "LINE: while (<>) {"/*}*/);
4526                 if (PL_minus_l)
4527                     sv_catpvs(PL_linestr,"chomp;");
4528                 if (PL_minus_a) {
4529                     if (PL_minus_F) {
4530                         if ((*PL_splitstr == '/' || *PL_splitstr == '\''
4531                              || *PL_splitstr == '"')
4532                               && strchr(PL_splitstr + 1, *PL_splitstr))
4533                             Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
4534                         else {
4535                             /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
4536                                bytes can be used as quoting characters.  :-) */
4537                             const char *splits = PL_splitstr;
4538                             sv_catpvs(PL_linestr, "our @F=split(q\0");
4539                             do {
4540                                 /* Need to \ \s  */
4541                                 if (*splits == '\\')
4542                                     sv_catpvn(PL_linestr, splits, 1);
4543                                 sv_catpvn(PL_linestr, splits, 1);
4544                             } while (*splits++);
4545                             /* This loop will embed the trailing NUL of
4546                                PL_linestr as the last thing it does before
4547                                terminating.  */
4548                             sv_catpvs(PL_linestr, ");");
4549                         }
4550                     }
4551                     else
4552                         sv_catpvs(PL_linestr,"our @F=split(' ');");
4553                 }
4554             }
4555             sv_catpvs(PL_linestr, "\n");
4556             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4557             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4558             PL_last_lop = PL_last_uni = NULL;
4559             if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
4560                 update_debugger_info(PL_linestr, NULL, 0);
4561             goto retry;
4562         }
4563         do {
4564             fake_eof = 0;
4565             bof = PL_rsfp ? TRUE : FALSE;
4566             if (0) {
4567               fake_eof:
4568                 fake_eof = LEX_FAKE_EOF;
4569             }
4570             PL_bufptr = PL_bufend;
4571             CopLINE_inc(PL_curcop);
4572             if (!lex_next_chunk(fake_eof)) {
4573                 CopLINE_dec(PL_curcop);
4574                 s = PL_bufptr;
4575                 TOKEN(';');     /* not infinite loop because rsfp is NULL now */
4576             }
4577             CopLINE_dec(PL_curcop);
4578 #ifdef PERL_MAD
4579             if (!PL_rsfp)
4580                 PL_realtokenstart = -1;
4581 #endif
4582             s = PL_bufptr;
4583             /* If it looks like the start of a BOM or raw UTF-16,
4584              * check if it in fact is. */
4585             if (bof && PL_rsfp &&
4586                      (*s == 0 ||
4587                       *(U8*)s == 0xEF ||
4588                       *(U8*)s >= 0xFE ||
4589                       s[1] == 0)) {
4590                 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
4591                 if (bof) {
4592                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4593                     s = swallow_bom((U8*)s);
4594                 }
4595             }
4596             if (PL_doextract) {
4597                 /* Incest with pod. */
4598 #ifdef PERL_MAD
4599                 if (PL_madskills)
4600                     sv_catsv(PL_thiswhite, PL_linestr);
4601 #endif
4602                 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
4603                     sv_setpvs(PL_linestr, "");
4604                     PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4605                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4606                     PL_last_lop = PL_last_uni = NULL;
4607                     PL_doextract = FALSE;
4608                 }
4609             }
4610             if (PL_rsfp)
4611                 incline(s);
4612         } while (PL_doextract);
4613         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
4614         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4615         PL_last_lop = PL_last_uni = NULL;
4616         if (CopLINE(PL_curcop) == 1) {
4617             while (s < PL_bufend && isSPACE(*s))
4618                 s++;
4619             if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
4620                 s++;
4621 #ifdef PERL_MAD
4622             if (PL_madskills)
4623                 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
4624 #endif
4625             d = NULL;
4626             if (!PL_in_eval) {
4627                 if (*s == '#' && *(s+1) == '!')
4628                     d = s + 2;
4629 #ifdef ALTERNATE_SHEBANG
4630                 else {
4631                     static char const as[] = ALTERNATE_SHEBANG;
4632                     if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
4633                         d = s + (sizeof(as) - 1);
4634                 }
4635 #endif /* ALTERNATE_SHEBANG */
4636             }
4637             if (d) {
4638                 char *ipath;
4639                 char *ipathend;
4640
4641                 while (isSPACE(*d))
4642                     d++;
4643                 ipath = d;
4644                 while (*d && !isSPACE(*d))
4645                     d++;
4646                 ipathend = d;
4647
4648 #ifdef ARG_ZERO_IS_SCRIPT
4649                 if (ipathend > ipath) {
4650                     /*
4651                      * HP-UX (at least) sets argv[0] to the script name,
4652                      * which makes $^X incorrect.  And Digital UNIX and Linux,
4653                      * at least, set argv[0] to the basename of the Perl
4654                      * interpreter. So, having found "#!", we'll set it right.
4655                      */
4656                     SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
4657                                                     SVt_PV)); /* $^X */
4658                     assert(SvPOK(x) || SvGMAGICAL(x));
4659                     if (sv_eq(x, CopFILESV(PL_curcop))) {
4660                         sv_setpvn(x, ipath, ipathend - ipath);
4661                         SvSETMAGIC(x);
4662                     }
4663                     else {
4664                         STRLEN blen;
4665                         STRLEN llen;
4666                         const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
4667                         const char * const lstart = SvPV_const(x,llen);
4668                         if (llen < blen) {
4669                             bstart += blen - llen;
4670                             if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
4671                                 sv_setpvn(x, ipath, ipathend - ipath);
4672                                 SvSETMAGIC(x);
4673                             }
4674                         }
4675                     }
4676                     TAINT_NOT;  /* $^X is always tainted, but that's OK */
4677                 }
4678 #endif /* ARG_ZERO_IS_SCRIPT */
4679
4680                 /*
4681                  * Look for options.
4682                  */
4683                 d = instr(s,"perl -");
4684                 if (!d) {
4685                     d = instr(s,"perl");
4686 #if defined(DOSISH)
4687                     /* avoid getting into infinite loops when shebang
4688                      * line contains "Perl" rather than "perl" */
4689                     if (!d) {
4690                         for (d = ipathend-4; d >= ipath; --d) {
4691                             if ((*d == 'p' || *d == 'P')
4692                                 && !ibcmp(d, "perl", 4))
4693                             {
4694                                 break;
4695                             }
4696                         }
4697                         if (d < ipath)
4698                             d = NULL;
4699                     }
4700 #endif
4701                 }
4702 #ifdef ALTERNATE_SHEBANG
4703                 /*
4704                  * If the ALTERNATE_SHEBANG on this system starts with a
4705                  * character that can be part of a Perl expression, then if
4706                  * we see it but not "perl", we're probably looking at the
4707                  * start of Perl code, not a request to hand off to some
4708                  * other interpreter.  Similarly, if "perl" is there, but
4709                  * not in the first 'word' of the line, we assume the line
4710                  * contains the start of the Perl program.
4711                  */
4712                 if (d && *s != '#') {
4713                     const char *c = ipath;
4714                     while (*c && !strchr("; \t\r\n\f\v#", *c))
4715                         c++;
4716                     if (c < d)
4717                         d = NULL;       /* "perl" not in first word; ignore */
4718                     else
4719                         *s = '#';       /* Don't try to parse shebang line */
4720                 }
4721 #endif /* ALTERNATE_SHEBANG */
4722                 if (!d &&
4723                     *s == '#' &&
4724                     ipathend > ipath &&
4725                     !PL_minus_c &&
4726                     !instr(s,"indir") &&
4727                     instr(PL_origargv[0],"perl"))
4728                 {
4729                     dVAR;
4730                     char **newargv;
4731
4732                     *ipathend = '\0';
4733                     s = ipathend + 1;
4734                     while (s < PL_bufend && isSPACE(*s))
4735                         s++;
4736                     if (s < PL_bufend) {
4737                         Newx(newargv,PL_origargc+3,char*);
4738                         newargv[1] = s;
4739                         while (s < PL_bufend && !isSPACE(*s))
4740                             s++;
4741                         *s = '\0';
4742                         Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
4743                     }
4744                     else
4745                         newargv = PL_origargv;
4746                     newargv[0] = ipath;
4747                     PERL_FPU_PRE_EXEC
4748                     PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
4749                     PERL_FPU_POST_EXEC
4750                     Perl_croak(aTHX_ "Can't exec %s", ipath);
4751                 }
4752                 if (d) {
4753                     while (*d && !isSPACE(*d))
4754                         d++;
4755                     while (SPACE_OR_TAB(*d))
4756                         d++;
4757
4758                     if (*d++ == '-') {
4759                         const bool switches_done = PL_doswitches;
4760                         const U32 oldpdb = PL_perldb;
4761                         const bool oldn = PL_minus_n;
4762                         const bool oldp = PL_minus_p;
4763                         const char *d1 = d;
4764
4765                         do {
4766                             bool baduni = FALSE;
4767                             if (*d1 == 'C') {
4768                                 const char *d2 = d1 + 1;
4769                                 if (parse_unicode_opts((const char **)&d2)
4770                                     != PL_unicode)
4771                                     baduni = TRUE;
4772                             }
4773                             if (baduni || *d1 == 'M' || *d1 == 'm') {
4774                                 const char * const m = d1;
4775                                 while (*d1 && !isSPACE(*d1))
4776                                     d1++;
4777                                 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
4778                                       (int)(d1 - m), m);
4779                             }
4780                             d1 = moreswitches(d1);
4781                         } while (d1);
4782                         if (PL_doswitches && !switches_done) {
4783                             int argc = PL_origargc;
4784                             char **argv = PL_origargv;
4785                             do {
4786                                 argc--,argv++;
4787                             } while (argc && argv[0][0] == '-' && argv[0][1]);
4788                             init_argv_symbols(argc,argv);
4789                         }
4790                         if (((PERLDB_LINE || PERLDB_SAVESRC) && !oldpdb) ||
4791                             ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
4792                               /* if we have already added "LINE: while (<>) {",
4793                                  we must not do it again */
4794                         {
4795                             sv_setpvs(PL_linestr, "");
4796                             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4797                             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4798                             PL_last_lop = PL_last_uni = NULL;
4799                             PL_preambled = FALSE;
4800                             if (PERLDB_LINE || PERLDB_SAVESRC)
4801                                 (void)gv_fetchfile(PL_origfilename);
4802                             goto retry;
4803                         }
4804                     }
4805                 }
4806             }
4807         }
4808         if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4809             PL_bufptr = s;
4810             PL_lex_state = LEX_FORMLINE;
4811             return yylex();
4812         }
4813         goto retry;
4814     case '\r':
4815 #ifdef PERL_STRICT_CR
4816         Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
4817         Perl_croak(aTHX_
4818       "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
4819 #endif
4820     case ' ': case '\t': case '\f': case 013:
4821 #ifdef PERL_MAD
4822         PL_realtokenstart = -1;
4823         if (!PL_thiswhite)
4824             PL_thiswhite = newSVpvs("");
4825         sv_catpvn(PL_thiswhite, s, 1);
4826 #endif
4827         s++;
4828         goto retry;
4829     case '#':
4830     case '\n':
4831 #ifdef PERL_MAD
4832         PL_realtokenstart = -1;
4833         if (PL_madskills)
4834             PL_faketokens = 0;
4835 #endif
4836         if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
4837             if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
4838                 /* handle eval qq[#line 1 "foo"\n ...] */
4839                 CopLINE_dec(PL_curcop);
4840                 incline(s);
4841             }
4842             if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
4843                 s = SKIPSPACE0(s);
4844                 if (!PL_in_eval || PL_rsfp)
4845                     incline(s);
4846             }
4847             else {
4848                 d = s;
4849                 while (d < PL_bufend && *d != '\n')
4850                     d++;
4851                 if (d < PL_bufend)
4852                     d++;
4853                 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4854                   Perl_croak(aTHX_ "panic: input overflow");
4855 #ifdef PERL_MAD
4856                 if (PL_madskills)
4857                     PL_thiswhite = newSVpvn(s, d - s);
4858 #endif
4859                 s = d;
4860                 incline(s);
4861             }
4862             if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4863                 PL_bufptr = s;
4864                 PL_lex_state = LEX_FORMLINE;
4865                 return yylex();
4866             }
4867         }
4868         else {
4869 #ifdef PERL_MAD
4870             if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
4871                 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
4872                     PL_faketokens = 0;
4873                     s = SKIPSPACE0(s);
4874                     TOKEN(PEG); /* make sure any #! line is accessible */
4875                 }
4876                 s = SKIPSPACE0(s);
4877             }
4878             else {
4879 /*              if (PL_madskills && PL_lex_formbrack) { */
4880                     d = s;
4881                     while (d < PL_bufend && *d != '\n')
4882                         d++;
4883                     if (d < PL_bufend)
4884                         d++;
4885                     else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4886                       Perl_croak(aTHX_ "panic: input overflow");
4887                     if (PL_madskills && CopLINE(PL_curcop) >= 1) {
4888                         if (!PL_thiswhite)
4889                             PL_thiswhite = newSVpvs("");
4890                         if (CopLINE(PL_curcop) == 1) {
4891                             sv_setpvs(PL_thiswhite, "");
4892                             PL_faketokens = 0;
4893                         }
4894                         sv_catpvn(PL_thiswhite, s, d - s);
4895                     }
4896                     s = d;
4897 /*              }
4898                 *s = '\0';
4899                 PL_bufend = s; */
4900             }
4901 #else
4902             *s = '\0';
4903             PL_bufend = s;
4904 #endif
4905         }
4906         goto retry;
4907     case '-':
4908         if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
4909             I32 ftst = 0;
4910             char tmp;
4911
4912             s++;
4913             PL_bufptr = s;
4914             tmp = *s++;
4915
4916             while (s < PL_bufend && SPACE_OR_TAB(*s))
4917                 s++;
4918
4919             if (strnEQ(s,"=>",2)) {
4920                 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
4921                 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
4922                 OPERATOR('-');          /* unary minus */
4923             }
4924             PL_last_uni = PL_oldbufptr;
4925             switch (tmp) {
4926             case 'r': ftst = OP_FTEREAD;        break;
4927             case 'w': ftst = OP_FTEWRITE;       break;
4928             case 'x': ftst = OP_FTEEXEC;        break;
4929             case 'o': ftst = OP_FTEOWNED;       break;
4930             case 'R': ftst = OP_FTRREAD;        break;
4931             case 'W': ftst = OP_FTRWRITE;       break;
4932             case 'X': ftst = OP_FTREXEC;        break;
4933             case 'O': ftst = OP_FTROWNED;       break;
4934             case 'e': ftst = OP_FTIS;           break;
4935             case 'z': ftst = OP_FTZERO;         break;
4936             case 's': ftst = OP_FTSIZE;         break;
4937             case 'f': ftst = OP_FTFILE;         break;
4938             case 'd': ftst = OP_FTDIR;          break;
4939             case 'l': ftst = OP_FTLINK;         break;
4940             case 'p': ftst = OP_FTPIPE;         break;
4941             case 'S': ftst = OP_FTSOCK;         break;
4942             case 'u': ftst = OP_FTSUID;         break;
4943             case 'g': ftst = OP_FTSGID;         break;
4944             case 'k': ftst = OP_FTSVTX;         break;
4945             case 'b': ftst = OP_FTBLK;          break;
4946             case 'c': ftst = OP_FTCHR;          break;
4947             case 't': ftst = OP_FTTTY;          break;
4948             case 'T': ftst = OP_FTTEXT;         break;
4949             case 'B': ftst = OP_FTBINARY;       break;
4950             case 'M': case 'A': case 'C':
4951                 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
4952                 switch (tmp) {
4953                 case 'M': ftst = OP_FTMTIME;    break;
4954                 case 'A': ftst = OP_FTATIME;    break;
4955                 case 'C': ftst = OP_FTCTIME;    break;
4956                 default:                        break;
4957                 }
4958                 break;
4959             default:
4960                 break;
4961             }
4962             if (ftst) {
4963                 PL_last_lop_op = (OPCODE)ftst;
4964                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4965                         "### Saw file test %c\n", (int)tmp);
4966                 } );
4967                 FTST(ftst);
4968             }
4969             else {
4970                 /* Assume it was a minus followed by a one-letter named
4971                  * subroutine call (or a -bareword), then. */
4972                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4973                         "### '-%c' looked like a file test but was not\n",
4974                         (int) tmp);
4975                 } );
4976                 s = --PL_bufptr;
4977             }
4978         }
4979         {
4980             const char tmp = *s++;
4981             if (*s == tmp) {
4982                 s++;
4983                 if (PL_expect == XOPERATOR)
4984                     TERM(POSTDEC);
4985                 else
4986                     OPERATOR(PREDEC);
4987             }
4988             else if (*s == '>') {
4989                 s++;
4990                 s = SKIPSPACE1(s);
4991                 if (isIDFIRST_lazy_if(s,UTF)) {
4992                     s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4993                     TOKEN(ARROW);
4994                 }
4995                 else if (*s == '$')
4996                     OPERATOR(ARROW);
4997                 else
4998                     TERM(ARROW);
4999             }
5000             if (PL_expect == XOPERATOR)
5001                 Aop(OP_SUBTRACT);
5002             else {
5003                 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
5004                     check_uni();
5005                 OPERATOR('-');          /* unary minus */
5006             }
5007         }
5008
5009     case '+':
5010         {
5011             const char tmp = *s++;
5012             if (*s == tmp) {
5013                 s++;
5014                 if (PL_expect == XOPERATOR)
5015                     TERM(POSTINC);
5016                 else
5017                     OPERATOR(PREINC);
5018             }
5019             if (PL_expect == XOPERATOR)
5020                 Aop(OP_ADD);
5021             else {
5022                 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
5023                     check_uni();
5024                 OPERATOR('+');
5025             }
5026         }
5027
5028     case '*':
5029         if (PL_expect != XOPERATOR) {
5030             s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5031             PL_expect = XOPERATOR;
5032             force_ident(PL_tokenbuf, '*');
5033             if (!*PL_tokenbuf)
5034                 PREREF('*');
5035             TERM('*');
5036         }
5037         s++;
5038         if (*s == '*') {
5039             s++;
5040             PWop(OP_POW);
5041         }
5042         Mop(OP_MULTIPLY);
5043
5044     case '%':
5045         if (PL_expect == XOPERATOR) {
5046             ++s;
5047             Mop(OP_MODULO);
5048         }
5049         PL_tokenbuf[0] = '%';
5050         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
5051                 sizeof PL_tokenbuf - 1, FALSE);
5052         if (!PL_tokenbuf[1]) {
5053             PREREF('%');
5054         }
5055         PL_pending_ident = '%';
5056         TERM('%');
5057
5058     case '^':
5059         s++;
5060         BOop(OP_BIT_XOR);
5061     case '[':
5062         PL_lex_brackets++;
5063         {
5064             const char tmp = *s++;
5065             OPERATOR(tmp);
5066         }
5067     case '~':
5068         if (s[1] == '~'
5069             && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
5070         {
5071             s += 2;
5072             Eop(OP_SMARTMATCH);
5073         }
5074     case ',':
5075         {
5076             const char tmp = *s++;
5077             OPERATOR(tmp);
5078         }
5079     case ':':
5080         if (s[1] == ':') {
5081             len = 0;
5082             goto just_a_word_zero_gv;
5083         }
5084         s++;
5085         switch (PL_expect) {
5086             OP *attrs;
5087 #ifdef PERL_MAD
5088             I32 stuffstart;
5089 #endif
5090         case XOPERATOR:
5091             if (!PL_in_my || PL_lex_state != LEX_NORMAL)
5092                 break;
5093             PL_bufptr = s;      /* update in case we back off */
5094             if (*s == '=') {
5095                 deprecate(":= for an empty attribute list");
5096             }
5097             goto grabattrs;
5098         case XATTRBLOCK:
5099             PL_expect = XBLOCK;
5100             goto grabattrs;
5101         case XATTRTERM:
5102             PL_expect = XTERMBLOCK;
5103          grabattrs:
5104 #ifdef PERL_MAD
5105             stuffstart = s - SvPVX(PL_linestr) - 1;
5106 #endif
5107             s = PEEKSPACE(s);
5108             attrs = NULL;
5109             while (isIDFIRST_lazy_if(s,UTF)) {
5110                 I32 tmp;
5111                 SV *sv;
5112                 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5113                 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
5114                     if (tmp < 0) tmp = -tmp;
5115                     switch (tmp) {
5116                     case KEY_or:
5117                     case KEY_and:
5118                     case KEY_for:
5119                     case KEY_foreach:
5120                     case KEY_unless:
5121                     case KEY_if:
5122                     case KEY_while:
5123                     case KEY_until:
5124                         goto got_attrs;
5125                     default:
5126                         break;
5127                     }
5128                 }
5129                 sv = newSVpvn(s, len);
5130                 if (*d == '(') {
5131                     d = scan_str(d,TRUE,TRUE);
5132                     if (!d) {
5133                         /* MUST advance bufptr here to avoid bogus
5134                            "at end of line" context messages from yyerror().
5135                          */
5136                         PL_bufptr = s + len;
5137                         yyerror("Unterminated attribute parameter in attribute list");
5138                         if (attrs)
5139                             op_free(attrs);
5140                         sv_free(sv);
5141                         return REPORT(0);       /* EOF indicator */
5142                     }
5143                 }
5144                 if (PL_lex_stuff) {
5145                     sv_catsv(sv, PL_lex_stuff);
5146                     attrs = append_elem(OP_LIST, attrs,
5147                                         newSVOP(OP_CONST, 0, sv));
5148                     SvREFCNT_dec(PL_lex_stuff);
5149                     PL_lex_stuff = NULL;
5150                 }
5151                 else {
5152                     if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
5153                         sv_free(sv);
5154                         if (PL_in_my == KEY_our) {
5155                             deprecate(":unique");
5156                         }
5157                         else
5158                             Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
5159                     }
5160
5161                     /* NOTE: any CV attrs applied here need to be part of
5162                        the CVf_BUILTIN_ATTRS define in cv.h! */
5163                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
5164                         sv_free(sv);
5165                         CvLVALUE_on(PL_compcv);
5166                     }
5167                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
5168                         sv_free(sv);
5169                         deprecate(":locked");
5170                     }
5171                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
5172                         sv_free(sv);
5173                         CvMETHOD_on(PL_compcv);
5174                     }
5175                     /* After we've set the flags, it could be argued that
5176                        we don't need to do the attributes.pm-based setting
5177                        process, and shouldn't bother appending recognized
5178                        flags.  To experiment with that, uncomment the
5179                        following "else".  (Note that's already been
5180                        uncommented.  That keeps the above-applied built-in
5181                        attributes from being intercepted (and possibly
5182                        rejected) by a package's attribute routines, but is
5183                        justified by the performance win for the common case
5184                        of applying only built-in attributes.) */
5185                     else
5186                         attrs = append_elem(OP_LIST, attrs,
5187                                             newSVOP(OP_CONST, 0,
5188                                                     sv));
5189                 }
5190                 s = PEEKSPACE(d);
5191                 if (*s == ':' && s[1] != ':')
5192                     s = PEEKSPACE(s+1);
5193                 else if (s == d)
5194                     break;      /* require real whitespace or :'s */
5195                 /* XXX losing whitespace on sequential attributes here */
5196             }
5197             {
5198                 const char tmp
5199                     = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
5200                 if (*s != ';' && *s != '}' && *s != tmp
5201                     && (tmp != '=' || *s != ')')) {
5202                     const char q = ((*s == '\'') ? '"' : '\'');
5203                     /* If here for an expression, and parsed no attrs, back
5204                        off. */
5205                     if (tmp == '=' && !attrs) {
5206                         s = PL_bufptr;
5207                         break;
5208                     }
5209                     /* MUST advance bufptr here to avoid bogus "at end of line"
5210                        context messages from yyerror().
5211                     */
5212                     PL_bufptr = s;
5213                     yyerror( (const char *)
5214                              (*s
5215                               ? Perl_form(aTHX_ "Invalid separator character "
5216                                           "%c%c%c in attribute list", q, *s, q)
5217                               : "Unterminated attribute list" ) );
5218                     if (attrs)
5219                         op_free(attrs);
5220                     OPERATOR(':');
5221                 }
5222             }
5223         got_attrs:
5224             if (attrs) {
5225                 start_force(PL_curforce);
5226                 NEXTVAL_NEXTTOKE.opval = attrs;
5227                 CURMAD('_', PL_nextwhite);
5228                 force_next(THING);
5229             }
5230 #ifdef PERL_MAD
5231             if (PL_madskills) {
5232                 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
5233                                      (s - SvPVX(PL_linestr)) - stuffstart);
5234             }
5235 #endif
5236             TOKEN(COLONATTR);
5237         }
5238         OPERATOR(':');
5239     case '(':
5240         s++;
5241         if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
5242             PL_oldbufptr = PL_oldoldbufptr;             /* allow print(STDOUT 123) */
5243         else
5244             PL_expect = XTERM;
5245         s = SKIPSPACE1(s);
5246         TOKEN('(');
5247     case ';':
5248         CLINE;
5249         {
5250             const char tmp = *s++;
5251             OPERATOR(tmp);
5252         }
5253     case ')':
5254         {
5255             const char tmp = *s++;
5256             s = SKIPSPACE1(s);
5257             if (*s == '{')
5258                 PREBLOCK(tmp);
5259             TERM(tmp);
5260         }
5261     case ']':
5262         s++;
5263         if (PL_lex_brackets <= 0)
5264             yyerror("Unmatched right square bracket");
5265         else
5266             --PL_lex_brackets;
5267         if (PL_lex_state == LEX_INTERPNORMAL) {
5268             if (PL_lex_brackets == 0) {
5269                 if (*s == '-' && s[1] == '>')
5270                     PL_lex_state = LEX_INTERPENDMAYBE;
5271                 else if (*s != '[' && *s != '{')
5272                     PL_lex_state = LEX_INTERPEND;
5273             }
5274         }
5275         TERM(']');
5276     case '{':
5277       leftbracket:
5278         s++;
5279         if (PL_lex_brackets > 100) {
5280             Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
5281         }
5282         switch (PL_expect) {
5283         case XTERM:
5284             if (PL_lex_formbrack) {
5285                 s--;
5286                 PRETERMBLOCK(DO);
5287             }
5288             if (PL_oldoldbufptr == PL_last_lop)
5289                 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
5290             else
5291                 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5292             OPERATOR(HASHBRACK);
5293         case XOPERATOR:
5294             while (s < PL_bufend && SPACE_OR_TAB(*s))
5295                 s++;
5296             d = s;
5297             PL_tokenbuf[0] = '\0';
5298             if (d < PL_bufend && *d == '-') {
5299                 PL_tokenbuf[0] = '-';
5300                 d++;
5301                 while (d < PL_bufend && SPACE_OR_TAB(*d))
5302                     d++;
5303             }
5304             if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
5305                 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
5306                               FALSE, &len);
5307                 while (d < PL_bufend && SPACE_OR_TAB(*d))
5308                     d++;
5309                 if (*d == '}') {
5310                     const char minus = (PL_tokenbuf[0] == '-');
5311                     s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
5312                     if (minus)
5313                         force_next('-');
5314                 }
5315             }
5316             /* FALL THROUGH */
5317         case XATTRBLOCK:
5318         case XBLOCK:
5319             PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
5320             PL_expect = XSTATE;
5321             break;
5322         case XATTRTERM:
5323         case XTERMBLOCK:
5324             PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5325             PL_expect = XSTATE;
5326             break;
5327         default: {
5328                 const char *t;
5329                 if (PL_oldoldbufptr == PL_last_lop)
5330                     PL_lex_brackstack[PL_lex_brackets++] = XTERM;
5331                 else
5332                     PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
5333                 s = SKIPSPACE1(s);
5334                 if (*s == '}') {
5335                     if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
5336                         PL_expect = XTERM;
5337                         /* This hack is to get the ${} in the message. */
5338                         PL_bufptr = s+1;
5339                         yyerror("syntax error");
5340                         break;
5341                     }
5342                     OPERATOR(HASHBRACK);
5343                 }
5344                 /* This hack serves to disambiguate a pair of curlies
5345                  * as being a block or an anon hash.  Normally, expectation
5346                  * determines that, but in cases where we're not in a
5347                  * position to expect anything in particular (like inside
5348                  * eval"") we have to resolve the ambiguity.  This code
5349                  * covers the case where the first term in the curlies is a
5350                  * quoted string.  Most other cases need to be explicitly
5351                  * disambiguated by prepending a "+" before the opening
5352                  * curly in order to force resolution as an anon hash.
5353                  *
5354                  * XXX should probably propagate the outer expectation
5355                  * into eval"" to rely less on this hack, but that could
5356                  * potentially break current behavior of eval"".
5357                  * GSAR 97-07-21
5358                  */
5359                 t = s;
5360                 if (*s == '\'' || *s == '"' || *s == '`') {
5361                     /* common case: get past first string, handling escapes */
5362                     for (t++; t < PL_bufend && *t != *s;)
5363                         if (*t++ == '\\' && (*t == '\\' || *t == *s))
5364                             t++;
5365                     t++;
5366                 }
5367                 else if (*s == 'q') {
5368                     if (++t < PL_bufend
5369                         && (!isALNUM(*t)
5370                             || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
5371                                 && !isALNUM(*t))))
5372                     {
5373                         /* skip q//-like construct */
5374                         const char *tmps;
5375                         char open, close, term;
5376                         I32 brackets = 1;
5377
5378                         while (t < PL_bufend && isSPACE(*t))
5379                             t++;
5380                         /* check for q => */
5381                         if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
5382                             OPERATOR(HASHBRACK);
5383                         }
5384                         term = *t;
5385                         open = term;
5386                         if (term && (tmps = strchr("([{< )]}> )]}>",term)))
5387                             term = tmps[5];
5388                         close = term;
5389                         if (open == close)
5390                             for (t++; t < PL_bufend; t++) {
5391                                 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
5392                                     t++;
5393                                 else if (*t == open)
5394                                     break;
5395                             }
5396                         else {
5397                             for (t++; t < PL_bufend; t++) {
5398                                 if (*t == '\\' && t+1 < PL_bufend)
5399                                     t++;
5400                                 else if (*t == close && --brackets <= 0)
5401                                     break;
5402                                 else if (*t == open)
5403                                     brackets++;
5404                             }
5405                         }
5406                         t++;
5407                     }
5408                     else
5409                         /* skip plain q word */
5410                         while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
5411                              t += UTF8SKIP(t);
5412                 }
5413                 else if (isALNUM_lazy_if(t,UTF)) {
5414                     t += UTF8SKIP(t);
5415                     while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
5416                          t += UTF8SKIP(t);
5417                 }
5418                 while (t < PL_bufend && isSPACE(*t))
5419                     t++;
5420                 /* if comma follows first term, call it an anon hash */
5421                 /* XXX it could be a comma expression with loop modifiers */
5422                 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
5423                                    || (*t == '=' && t[1] == '>')))
5424                     OPERATOR(HASHBRACK);
5425                 if (PL_expect == XREF)
5426                     PL_expect = XTERM;
5427                 else {
5428                     PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
5429                     PL_expect = XSTATE;
5430                 }
5431             }
5432             break;
5433         }
5434         pl_yylval.ival = CopLINE(PL_curcop);
5435         if (isSPACE(*s) || *s == '#')
5436             PL_copline = NOLINE;   /* invalidate current command line number */
5437         TOKEN('{');
5438     case '}':
5439       rightbracket:
5440         s++;
5441         if (PL_lex_brackets <= 0)
5442             yyerror("Unmatched right curly bracket");
5443         else
5444             PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
5445         if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
5446             PL_lex_formbrack = 0;
5447         if (PL_lex_state == LEX_INTERPNORMAL) {
5448             if (PL_lex_brackets == 0) {
5449                 if (PL_expect & XFAKEBRACK) {
5450                     PL_expect &= XENUMMASK;
5451                     PL_lex_state = LEX_INTERPEND;
5452                     PL_bufptr = s;
5453 #if 0
5454                     if (PL_madskills) {
5455                         if (!PL_thiswhite)
5456                             PL_thiswhite = newSVpvs("");
5457                         sv_catpvs(PL_thiswhite,"}");
5458                     }
5459 #endif
5460                     return yylex();     /* ignore fake brackets */
5461                 }
5462                 if (*s == '-' && s[1] == '>')
5463                     PL_lex_state = LEX_INTERPENDMAYBE;
5464                 else if (*s != '[' && *s != '{')
5465                     PL_lex_state = LEX_INTERPEND;
5466             }
5467         }
5468         if (PL_expect & XFAKEBRACK) {
5469             PL_expect &= XENUMMASK;
5470             PL_bufptr = s;
5471             return yylex();             /* ignore fake brackets */
5472         }
5473         start_force(PL_curforce);
5474         if (PL_madskills) {
5475             curmad('X', newSVpvn(s-1,1));
5476             CURMAD('_', PL_thiswhite);
5477         }
5478         force_next('}');
5479 #ifdef PERL_MAD
5480         if (!PL_thistoken)
5481             PL_thistoken = newSVpvs("");
5482 #endif
5483         TOKEN(';');
5484     case '&':
5485         s++;
5486         if (*s++ == '&')
5487             AOPERATOR(ANDAND);
5488         s--;
5489         if (PL_expect == XOPERATOR) {
5490             if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
5491                 && isIDFIRST_lazy_if(s,UTF))
5492             {
5493                 CopLINE_dec(PL_curcop);
5494                 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
5495                 CopLINE_inc(PL_curcop);
5496             }
5497             BAop(OP_BIT_AND);
5498         }
5499
5500         s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
5501         if (*PL_tokenbuf) {
5502             PL_expect = XOPERATOR;
5503             force_ident(PL_tokenbuf, '&');
5504         }
5505         else
5506             PREREF('&');
5507         pl_yylval.ival = (OPpENTERSUB_AMPER<<8);
5508         TERM('&');
5509
5510     case '|':
5511         s++;
5512         if (*s++ == '|')
5513             AOPERATOR(OROR);
5514         s--;
5515         BOop(OP_BIT_OR);
5516     case '=':
5517         s++;
5518         {
5519             const char tmp = *s++;
5520             if (tmp == '=')
5521                 Eop(OP_EQ);
5522             if (tmp == '>')
5523                 OPERATOR(',');
5524             if (tmp == '~')
5525                 PMop(OP_MATCH);
5526             if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
5527                 && strchr("+-*/%.^&|<",tmp))
5528                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5529                             "Reversed %c= operator",(int)tmp);
5530             s--;
5531             if (PL_expect == XSTATE && isALPHA(tmp) &&
5532                 (s == PL_linestart+1 || s[-2] == '\n') )
5533                 {
5534                     if (PL_in_eval && !PL_rsfp) {
5535                         d = PL_bufend;
5536                         while (s < d) {
5537                             if (*s++ == '\n') {
5538                                 incline(s);
5539                                 if (strnEQ(s,"=cut",4)) {
5540                                     s = strchr(s,'\n');
5541                                     if (s)
5542                                         s++;
5543                                     else
5544                                         s = d;
5545                                     incline(s);
5546                                     goto retry;
5547                                 }
5548                             }
5549                         }
5550                         goto retry;
5551                     }
5552 #ifdef PERL_MAD
5553                     if (PL_madskills) {
5554                         if (!PL_thiswhite)
5555                             PL_thiswhite = newSVpvs("");
5556                         sv_catpvn(PL_thiswhite, PL_linestart,
5557                                   PL_bufend - PL_linestart);
5558                     }
5559 #endif
5560                     s = PL_bufend;
5561                     PL_doextract = TRUE;
5562                     goto retry;
5563                 }
5564         }
5565         if (PL_lex_brackets < PL_lex_formbrack) {
5566             const char *t = s;
5567 #ifdef PERL_STRICT_CR
5568             while (SPACE_OR_TAB(*t))
5569 #else
5570             while (SPACE_OR_TAB(*t) || *t == '\r')
5571 #endif
5572                 t++;
5573             if (*t == '\n' || *t == '#') {
5574                 s--;
5575                 PL_expect = XBLOCK;
5576                 goto leftbracket;
5577             }
5578         }
5579         pl_yylval.ival = 0;
5580         OPERATOR(ASSIGNOP);
5581     case '!':
5582         s++;
5583         {
5584             const char tmp = *s++;
5585             if (tmp == '=') {
5586                 /* was this !=~ where !~ was meant?
5587                  * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
5588
5589                 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
5590                     const char *t = s+1;
5591
5592                     while (t < PL_bufend && isSPACE(*t))
5593                         ++t;
5594
5595                     if (*t == '/' || *t == '?' ||
5596                         ((*t == 'm' || *t == 's' || *t == 'y')
5597                          && !isALNUM(t[1])) ||
5598                         (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
5599                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5600                                     "!=~ should be !~");
5601                 }
5602                 Eop(OP_NE);
5603             }
5604             if (tmp == '~')
5605                 PMop(OP_NOT);
5606         }
5607         s--;
5608         OPERATOR('!');
5609     case '<':
5610         if (PL_expect != XOPERATOR) {
5611             if (s[1] != '<' && !strchr(s,'>'))
5612                 check_uni();
5613             if (s[1] == '<')
5614                 s = scan_heredoc(s);
5615             else
5616                 s = scan_inputsymbol(s);
5617             TERM(sublex_start());
5618         }
5619         s++;
5620         {
5621             char tmp = *s++;
5622             if (tmp == '<')
5623                 SHop(OP_LEFT_SHIFT);
5624             if (tmp == '=') {
5625                 tmp = *s++;
5626                 if (tmp == '>')
5627                     Eop(OP_NCMP);
5628                 s--;
5629                 Rop(OP_LE);
5630             }
5631         }
5632         s--;
5633         Rop(OP_LT);
5634     case '>':
5635         s++;
5636         {
5637             const char tmp = *s++;
5638             if (tmp == '>')
5639                 SHop(OP_RIGHT_SHIFT);
5640             else if (tmp == '=')
5641                 Rop(OP_GE);
5642         }
5643         s--;
5644         Rop(OP_GT);
5645
5646     case '$':
5647         CLINE;
5648
5649         if (PL_expect == XOPERATOR) {
5650             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5651                 return deprecate_commaless_var_list();
5652             }
5653         }
5654
5655         if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
5656             PL_tokenbuf[0] = '@';
5657             s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
5658                            sizeof PL_tokenbuf - 1, FALSE);
5659             if (PL_expect == XOPERATOR)
5660                 no_op("Array length", s);
5661             if (!PL_tokenbuf[1])
5662                 PREREF(DOLSHARP);
5663             PL_expect = XOPERATOR;
5664             PL_pending_ident = '#';
5665             TOKEN(DOLSHARP);
5666         }
5667
5668         PL_tokenbuf[0] = '$';
5669         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
5670                        sizeof PL_tokenbuf - 1, FALSE);
5671         if (PL_expect == XOPERATOR)
5672             no_op("Scalar", s);
5673         if (!PL_tokenbuf[1]) {
5674             if (s == PL_bufend)
5675                 yyerror("Final $ should be \\$ or $name");
5676             PREREF('$');
5677         }
5678
5679         /* This kludge not intended to be bulletproof. */
5680         if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
5681             pl_yylval.opval = newSVOP(OP_CONST, 0,
5682                                    newSViv(CopARYBASE_get(&PL_compiling)));
5683             pl_yylval.opval->op_private = OPpCONST_ARYBASE;
5684             TERM(THING);
5685         }
5686
5687         d = s;
5688         {
5689             const char tmp = *s;
5690             if (PL_lex_state == LEX_NORMAL || PL_lex_brackets)
5691                 s = SKIPSPACE1(s);
5692
5693             if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
5694                 && intuit_more(s)) {
5695                 if (*s == '[') {
5696                     PL_tokenbuf[0] = '@';
5697                     if (ckWARN(WARN_SYNTAX)) {
5698                         char *t = s+1;
5699
5700                         while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
5701                             t++;
5702                         if (*t++ == ',') {
5703                             PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
5704                             while (t < PL_bufend && *t != ']')
5705                                 t++;
5706                             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5707                                         "Multidimensional syntax %.*s not supported",
5708                                     (int)((t - PL_bufptr) + 1), PL_bufptr);
5709                         }
5710                     }
5711                 }
5712                 else if (*s == '{') {
5713                     char *t;
5714                     PL_tokenbuf[0] = '%';
5715                     if (strEQ(PL_tokenbuf+1, "SIG")  && ckWARN(WARN_SYNTAX)
5716                         && (t = strchr(s, '}')) && (t = strchr(t, '=')))
5717                         {
5718                             char tmpbuf[sizeof PL_tokenbuf];
5719                             do {
5720                                 t++;
5721                             } while (isSPACE(*t));
5722                             if (isIDFIRST_lazy_if(t,UTF)) {
5723                                 STRLEN len;
5724                                 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
5725                                               &len);
5726                                 while (isSPACE(*t))
5727                                     t++;
5728                                 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
5729                                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5730                                                 "You need to quote \"%s\"",
5731                                                 tmpbuf);
5732                             }
5733                         }
5734                 }
5735             }
5736
5737             PL_expect = XOPERATOR;
5738             if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
5739                 const bool islop = (PL_last_lop == PL_oldoldbufptr);
5740                 if (!islop || PL_last_lop_op == OP_GREPSTART)
5741                     PL_expect = XOPERATOR;
5742                 else if (strchr("$@\"'`q", *s))
5743                     PL_expect = XTERM;          /* e.g. print $fh "foo" */
5744                 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
5745                     PL_expect = XTERM;          /* e.g. print $fh &sub */
5746                 else if (isIDFIRST_lazy_if(s,UTF)) {
5747                     char tmpbuf[sizeof PL_tokenbuf];
5748                     int t2;
5749                     scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5750                     if ((t2 = keyword(tmpbuf, len, 0))) {
5751                         /* binary operators exclude handle interpretations */
5752                         switch (t2) {
5753                         case -KEY_x:
5754                         case -KEY_eq:
5755                         case -KEY_ne:
5756                         case -KEY_gt:
5757                         case -KEY_lt:
5758                         case -KEY_ge:
5759                         case -KEY_le:
5760                         case -KEY_cmp:
5761                             break;
5762                         default:
5763                             PL_expect = XTERM;  /* e.g. print $fh length() */
5764                             break;
5765                         }
5766                     }
5767                     else {
5768                         PL_expect = XTERM;      /* e.g. print $fh subr() */
5769                     }
5770                 }
5771                 else if (isDIGIT(*s))
5772                     PL_expect = XTERM;          /* e.g. print $fh 3 */
5773                 else if (*s == '.' && isDIGIT(s[1]))
5774                     PL_expect = XTERM;          /* e.g. print $fh .3 */
5775                 else if ((*s == '?' || *s == '-' || *s == '+')
5776                          && !isSPACE(s[1]) && s[1] != '=')
5777                     PL_expect = XTERM;          /* e.g. print $fh -1 */
5778                 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
5779                          && s[1] != '/')
5780                     PL_expect = XTERM;          /* e.g. print $fh /.../
5781                                                    XXX except DORDOR operator
5782                                                 */
5783                 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
5784                          && s[2] != '=')
5785                     PL_expect = XTERM;          /* print $fh <<"EOF" */
5786             }
5787         }
5788         PL_pending_ident = '$';
5789         TOKEN('$');
5790
5791     case '@':
5792         if (PL_expect == XOPERATOR)
5793             no_op("Array", s);
5794         PL_tokenbuf[0] = '@';
5795         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
5796         if (!PL_tokenbuf[1]) {
5797             PREREF('@');
5798         }
5799         if (PL_lex_state == LEX_NORMAL)
5800             s = SKIPSPACE1(s);
5801         if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
5802             if (*s == '{')
5803                 PL_tokenbuf[0] = '%';
5804
5805             /* Warn about @ where they meant $. */
5806             if (*s == '[' || *s == '{') {
5807                 if (ckWARN(WARN_SYNTAX)) {
5808                     const char *t = s + 1;
5809                     while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
5810                         t++;
5811                     if (*t == '}' || *t == ']') {
5812                         t++;
5813                         PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
5814                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5815                             "Scalar value %.*s better written as $%.*s",
5816                             (int)(t-PL_bufptr), PL_bufptr,
5817                             (int)(t-PL_bufptr-1), PL_bufptr+1);
5818                     }
5819                 }
5820             }
5821         }
5822         PL_pending_ident = '@';
5823         TERM('@');
5824
5825      case '/':                  /* may be division, defined-or, or pattern */
5826         if (PL_expect == XTERMORDORDOR && s[1] == '/') {
5827             s += 2;
5828             AOPERATOR(DORDOR);
5829         }
5830      case '?':                  /* may either be conditional or pattern */
5831         if (PL_expect == XOPERATOR) {
5832              char tmp = *s++;
5833              if(tmp == '?') {
5834                 OPERATOR('?');
5835              }
5836              else {
5837                  tmp = *s++;
5838                  if(tmp == '/') {
5839                      /* A // operator. */
5840                     AOPERATOR(DORDOR);
5841                  }
5842                  else {
5843                      s--;
5844                      Mop(OP_DIVIDE);
5845                  }
5846              }
5847          }
5848          else {
5849              /* Disable warning on "study /blah/" */
5850              if (PL_oldoldbufptr == PL_last_uni
5851               && (*PL_last_uni != 's' || s - PL_last_uni < 5
5852                   || memNE(PL_last_uni, "study", 5)
5853                   || isALNUM_lazy_if(PL_last_uni+5,UTF)
5854               ))
5855                  check_uni();
5856              s = scan_pat(s,OP_MATCH);
5857              TERM(sublex_start());
5858          }
5859
5860     case '.':
5861         if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
5862 #ifdef PERL_STRICT_CR
5863             && s[1] == '\n'
5864 #else
5865             && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
5866 #endif
5867             && (s == PL_linestart || s[-1] == '\n') )
5868         {
5869             PL_lex_formbrack = 0;
5870             PL_expect = XSTATE;
5871             goto rightbracket;
5872         }
5873         if (PL_expect == XSTATE && s[1] == '.' && s[2] == '.') {
5874             s += 3;
5875             OPERATOR(YADAYADA);
5876         }
5877         if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
5878             char tmp = *s++;
5879             if (*s == tmp) {
5880                 s++;
5881                 if (*s == tmp) {
5882                     s++;
5883                     pl_yylval.ival = OPf_SPECIAL;
5884                 }
5885                 else
5886                     pl_yylval.ival = 0;
5887                 OPERATOR(DOTDOT);
5888             }
5889             Aop(OP_CONCAT);
5890         }
5891         /* FALL THROUGH */
5892     case '0': case '1': case '2': case '3': case '4':
5893     case '5': case '6': case '7': case '8': case '9':
5894         s = scan_num(s, &pl_yylval);
5895         DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
5896         if (PL_expect == XOPERATOR)
5897             no_op("Number",s);
5898         TERM(THING);
5899
5900     case '\'':
5901         s = scan_str(s,!!PL_madskills,FALSE);
5902         DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5903         if (PL_expect == XOPERATOR) {
5904             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5905                 return deprecate_commaless_var_list();
5906             }
5907             else
5908                 no_op("String",s);
5909         }
5910         if (!s)
5911             missingterm(NULL);
5912         pl_yylval.ival = OP_CONST;
5913         TERM(sublex_start());
5914
5915     case '"':
5916         s = scan_str(s,!!PL_madskills,FALSE);
5917         DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5918         if (PL_expect == XOPERATOR) {
5919             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5920                 return deprecate_commaless_var_list();
5921             }
5922             else
5923                 no_op("String",s);
5924         }
5925         if (!s)
5926             missingterm(NULL);
5927         pl_yylval.ival = OP_CONST;
5928         /* FIXME. I think that this can be const if char *d is replaced by
5929            more localised variables.  */
5930         for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
5931             if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
5932                 pl_yylval.ival = OP_STRINGIFY;
5933                 break;
5934             }
5935         }
5936         TERM(sublex_start());
5937
5938     case '`':
5939         s = scan_str(s,!!PL_madskills,FALSE);
5940         DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
5941         if (PL_expect == XOPERATOR)
5942             no_op("Backticks",s);
5943         if (!s)
5944             missingterm(NULL);
5945         readpipe_override();
5946         TERM(sublex_start());
5947
5948     case '\\':
5949         s++;
5950         if (PL_lex_inwhat && isDIGIT(*s))
5951             Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5952                            *s, *s);
5953         if (PL_expect == XOPERATOR)
5954             no_op("Backslash",s);
5955         OPERATOR(REFGEN);
5956
5957     case 'v':
5958         if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
5959             char *start = s + 2;
5960             while (isDIGIT(*start) || *start == '_')
5961                 start++;
5962             if (*start == '.' && isDIGIT(start[1])) {
5963                 s = scan_num(s, &pl_yylval);
5964                 TERM(THING);
5965             }
5966             /* avoid v123abc() or $h{v1}, allow C<print v10;> */
5967             else if (!isALPHA(*start) && (PL_expect == XTERM
5968                         || PL_expect == XREF || PL_expect == XSTATE
5969                         || PL_expect == XTERMORDORDOR)) {
5970                 GV *const gv = gv_fetchpvn_flags(s, start - s, 0, SVt_PVCV);
5971                 if (!gv) {
5972                     s = scan_num(s, &pl_yylval);
5973                     TERM(THING);
5974                 }
5975             }
5976         }
5977         goto keylookup;
5978     case 'x':
5979         if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
5980             s++;
5981             Mop(OP_REPEAT);
5982         }
5983         goto keylookup;
5984
5985     case '_':
5986     case 'a': case 'A':
5987     case 'b': case 'B':
5988     case 'c': case 'C':
5989     case 'd': case 'D':
5990     case 'e': case 'E':
5991     case 'f': case 'F':
5992     case 'g': case 'G':
5993     case 'h': case 'H':
5994     case 'i': case 'I':
5995     case 'j': case 'J':
5996     case 'k': case 'K':
5997     case 'l': case 'L':
5998     case 'm': case 'M':
5999     case 'n': case 'N':
6000     case 'o': case 'O':
6001     case 'p': case 'P':
6002     case 'q': case 'Q':
6003     case 'r': case 'R':
6004     case 's': case 'S':
6005     case 't': case 'T':
6006     case 'u': case 'U':
6007               case 'V':
6008     case 'w': case 'W':
6009               case 'X':
6010     case 'y': case 'Y':
6011     case 'z': case 'Z':
6012
6013       keylookup: {
6014         bool anydelim;
6015         I32 tmp;
6016
6017         orig_keyword = 0;
6018         gv = NULL;
6019         gvp = NULL;
6020
6021         PL_bufptr = s;
6022         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
6023
6024         /* Some keywords can be followed by any delimiter, including ':' */
6025         anydelim = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
6026                (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
6027                              (PL_tokenbuf[0] == 'q' &&
6028                               strchr("qwxr", PL_tokenbuf[1])))));
6029
6030         /* x::* is just a word, unless x is "CORE" */
6031         if (!anydelim && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
6032             goto just_a_word;
6033
6034         d = s;
6035         while (d < PL_bufend && isSPACE(*d))
6036                 d++;    /* no comments skipped here, or s### is misparsed */
6037
6038         /* Is this a word before a => operator? */
6039         if (*d == '=' && d[1] == '>') {
6040             CLINE;
6041             pl_yylval.opval
6042                 = (OP*)newSVOP(OP_CONST, 0,
6043                                S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
6044             pl_yylval.opval->op_private = OPpCONST_BARE;
6045             TERM(WORD);
6046         }
6047
6048         /* Check for plugged-in keyword */
6049         {
6050             OP *o;
6051             int result;
6052             char *saved_bufptr = PL_bufptr;
6053             PL_bufptr = s;
6054             result = CALL_FPTR(PL_keyword_plugin)(aTHX_ PL_tokenbuf, len, &o);
6055             s = PL_bufptr;
6056             if (result == KEYWORD_PLUGIN_DECLINE) {
6057                 /* not a plugged-in keyword */
6058                 PL_bufptr = saved_bufptr;
6059             } else if (result == KEYWORD_PLUGIN_STMT) {
6060                 pl_yylval.opval = o;
6061                 CLINE;
6062                 PL_expect = XSTATE;
6063                 return REPORT(PLUGSTMT);
6064             } else if (result == KEYWORD_PLUGIN_EXPR) {
6065                 pl_yylval.opval = o;
6066                 CLINE;
6067                 PL_expect = XOPERATOR;
6068                 return REPORT(PLUGEXPR);
6069             } else {
6070                 Perl_croak(aTHX_ "Bad plugin affecting keyword '%s'",
6071                                         PL_tokenbuf);
6072             }
6073         }
6074
6075         /* Check for built-in keyword */
6076         tmp = keyword(PL_tokenbuf, len, 0);
6077
6078         /* Is this a label? */
6079         if (!anydelim && PL_expect == XSTATE
6080               && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
6081             if (tmp)
6082                 Perl_croak(aTHX_ "Can't use keyword '%s' as a label", PL_tokenbuf);
6083             s = d + 1;
6084             pl_yylval.pval = CopLABEL_alloc(PL_tokenbuf);
6085             CLINE;
6086             TOKEN(LABEL);
6087         }
6088
6089         if (tmp < 0) {                  /* second-class keyword? */
6090             GV *ogv = NULL;     /* override (winner) */
6091             GV *hgv = NULL;     /* hidden (loser) */
6092             if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
6093                 CV *cv;
6094                 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
6095                     (cv = GvCVu(gv)))
6096                 {
6097                     if (GvIMPORTED_CV(gv))
6098                         ogv = gv;
6099                     else if (! CvMETHOD(cv))
6100                         hgv = gv;
6101                 }
6102                 if (!ogv &&
6103                     (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
6104                     (gv = *gvp) && isGV_with_GP(gv) &&
6105                     GvCVu(gv) && GvIMPORTED_CV(gv))
6106                 {
6107                     ogv = gv;
6108                 }
6109             }
6110             if (ogv) {
6111                 orig_keyword = tmp;
6112                 tmp = 0;                /* overridden by import or by GLOBAL */
6113             }
6114             else if (gv && !gvp
6115                      && -tmp==KEY_lock  /* XXX generalizable kludge */
6116                      && GvCVu(gv))
6117             {
6118                 tmp = 0;                /* any sub overrides "weak" keyword */
6119             }
6120             else {                      /* no override */
6121                 tmp = -tmp;
6122                 if (tmp == KEY_dump) {
6123                     Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
6124                                    "dump() better written as CORE::dump()");
6125                 }
6126                 gv = NULL;
6127                 gvp = 0;
6128                 if (hgv && tmp != KEY_x && tmp != KEY_CORE)     /* never ambiguous */
6129                     Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
6130                                    "Ambiguous call resolved as CORE::%s(), %s",
6131                                    GvENAME(hgv), "qualify as such or use &");
6132             }
6133         }
6134
6135       reserved_word:
6136         switch (tmp) {
6137
6138         default:                        /* not a keyword */
6139             /* Trade off - by using this evil construction we can pull the
6140                variable gv into the block labelled keylookup. If not, then
6141                we have to give it function scope so that the goto from the
6142                earlier ':' case doesn't bypass the initialisation.  */
6143             if (0) {
6144             just_a_word_zero_gv:
6145                 gv = NULL;
6146                 gvp = NULL;
6147                 orig_keyword = 0;
6148             }
6149           just_a_word: {
6150                 SV *sv;
6151                 int pkgname = 0;
6152                 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
6153                 OP *rv2cv_op;
6154                 CV *cv;
6155 #ifdef PERL_MAD
6156                 SV *nextPL_nextwhite = 0;
6157 #endif
6158
6159
6160                 /* Get the rest if it looks like a package qualifier */
6161
6162                 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
6163                     STRLEN morelen;
6164                     s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
6165                                   TRUE, &morelen);
6166                     if (!morelen)
6167                         Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
6168                                 *s == '\'' ? "'" : "::");
6169                     len += morelen;
6170                     pkgname = 1;
6171                 }
6172
6173                 if (PL_expect == XOPERATOR) {
6174                     if (PL_bufptr == PL_linestart) {
6175                         CopLINE_dec(PL_curcop);
6176                         Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
6177                         CopLINE_inc(PL_curcop);
6178                     }
6179                     else
6180                         no_op("Bareword",s);
6181                 }
6182
6183                 /* Look for a subroutine with this name in current package,
6184                    unless name is "Foo::", in which case Foo is a bearword
6185                    (and a package name). */
6186
6187                 if (len > 2 && !PL_madskills &&
6188                     PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
6189                 {
6190                     if (ckWARN(WARN_BAREWORD)
6191                         && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
6192                         Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
6193                             "Bareword \"%s\" refers to nonexistent package",
6194                              PL_tokenbuf);
6195                     len -= 2;
6196                     PL_tokenbuf[len] = '\0';
6197                     gv = NULL;
6198                     gvp = 0;
6199                 }
6200                 else {
6201                     if (!gv) {
6202                         /* Mustn't actually add anything to a symbol table.
6203                            But also don't want to "initialise" any placeholder
6204                            constants that might already be there into full
6205                            blown PVGVs with attached PVCV.  */
6206                         gv = gv_fetchpvn_flags(PL_tokenbuf, len,
6207                                                GV_NOADD_NOINIT, SVt_PVCV);
6208                     }
6209                     len = 0;
6210                 }
6211
6212                 /* if we saw a global override before, get the right name */
6213
6214                 if (gvp) {
6215                     sv = newSVpvs("CORE::GLOBAL::");
6216                     sv_catpv(sv,PL_tokenbuf);
6217                 }
6218                 else {
6219                     /* If len is 0, newSVpv does strlen(), which is correct.
6220                        If len is non-zero, then it will be the true length,
6221                        and so the scalar will be created correctly.  */
6222                     sv = newSVpv(PL_tokenbuf,len);
6223                 }
6224 #ifdef PERL_MAD
6225                 if (PL_madskills && !PL_thistoken) {
6226                     char *start = SvPVX(PL_linestr) + PL_realtokenstart;
6227                     PL_thistoken = newSVpvn(start,s - start);
6228                     PL_realtokenstart = s - SvPVX(PL_linestr);
6229                 }
6230 #endif
6231
6232                 /* Presume this is going to be a bareword of some sort. */
6233
6234                 CLINE;
6235                 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
6236                 pl_yylval.opval->op_private = OPpCONST_BARE;
6237                 /* UTF-8 package name? */
6238                 if (UTF && !IN_BYTES &&
6239                     is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
6240                     SvUTF8_on(sv);
6241
6242                 /* And if "Foo::", then that's what it certainly is. */
6243
6244                 if (len)
6245                     goto safe_bareword;
6246
6247                 cv = NULL;
6248                 {
6249                     OP *const_op = newSVOP(OP_CONST, 0, SvREFCNT_inc(sv));
6250                     const_op->op_private = OPpCONST_BARE;
6251                     rv2cv_op = newCVREF(0, const_op);
6252                 }
6253                 if (rv2cv_op->op_type == OP_RV2CV &&
6254                         (rv2cv_op->op_flags & OPf_KIDS)) {
6255                     OP *rv_op = cUNOPx(rv2cv_op)->op_first;
6256                     switch (rv_op->op_type) {
6257                         case OP_CONST: {
6258                             SV *sv = cSVOPx_sv(rv_op);
6259                             if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV)
6260                                 cv = (CV*)SvRV(sv);
6261                         } break;
6262                         case OP_GV: {
6263                             GV *gv = cGVOPx_gv(rv_op);
6264                             CV *maybe_cv = GvCVu(gv);
6265                             if (maybe_cv && SvTYPE((SV*)maybe_cv) == SVt_PVCV)
6266                                 cv = maybe_cv;
6267                         } break;
6268                     }
6269                 }
6270
6271                 /* See if it's the indirect object for a list operator. */
6272
6273                 if (PL_oldoldbufptr &&
6274                     PL_oldoldbufptr < PL_bufptr &&
6275                     (PL_oldoldbufptr == PL_last_lop
6276                      || PL_oldoldbufptr == PL_last_uni) &&
6277                     /* NO SKIPSPACE BEFORE HERE! */
6278                     (PL_expect == XREF ||
6279                      ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
6280                 {
6281                     bool immediate_paren = *s == '(';
6282
6283                     /* (Now we can afford to cross potential line boundary.) */
6284                     s = SKIPSPACE2(s,nextPL_nextwhite);
6285 #ifdef PERL_MAD
6286                     PL_nextwhite = nextPL_nextwhite;    /* assume no & deception */
6287 #endif
6288
6289                     /* Two barewords in a row may indicate method call. */
6290
6291                     if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
6292                         (tmp = intuit_method(s, gv, cv))) {
6293                         op_free(rv2cv_op);
6294                         return REPORT(tmp);
6295                     }
6296
6297                     /* If not a declared subroutine, it's an indirect object. */
6298                     /* (But it's an indir obj regardless for sort.) */
6299                     /* Also, if "_" follows a filetest operator, it's a bareword */
6300
6301                     if (
6302                         ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
6303                          (!cv &&
6304                         (PL_last_lop_op != OP_MAPSTART &&
6305                          PL_last_lop_op != OP_GREPSTART))))
6306                        || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
6307                             && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
6308                        )
6309                     {
6310                         PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
6311                         goto bareword;
6312                     }
6313                 }
6314
6315                 PL_expect = XOPERATOR;
6316 #ifdef PERL_MAD
6317                 if (isSPACE(*s))
6318                     s = SKIPSPACE2(s,nextPL_nextwhite);
6319                 PL_nextwhite = nextPL_nextwhite;
6320 #else
6321                 s = skipspace(s);
6322 #endif
6323
6324                 /* Is this a word before a => operator? */
6325                 if (*s == '=' && s[1] == '>' && !pkgname) {
6326                     op_free(rv2cv_op);
6327                     CLINE;
6328                     sv_setpv(((SVOP*)pl_yylval.opval)->op_sv, PL_tokenbuf);
6329                     if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
6330                       SvUTF8_on(((SVOP*)pl_yylval.opval)->op_sv);
6331                     TERM(WORD);
6332                 }
6333
6334                 /* If followed by a paren, it's certainly a subroutine. */
6335                 if (*s == '(') {
6336                     CLINE;
6337                     if (cv) {
6338                         d = s + 1;
6339                         while (SPACE_OR_TAB(*d))
6340                             d++;
6341                         if (*d == ')' && (sv = cv_const_sv(cv))) {
6342                             s = d + 1;
6343                             goto its_constant;
6344                         }
6345                     }
6346 #ifdef PERL_MAD
6347                     if (PL_madskills) {
6348                         PL_nextwhite = PL_thiswhite;
6349                         PL_thiswhite = 0;
6350                     }
6351                     start_force(PL_curforce);
6352 #endif
6353                     NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6354                     PL_expect = XOPERATOR;
6355 #ifdef PERL_MAD
6356                     if (PL_madskills) {
6357                         PL_nextwhite = nextPL_nextwhite;
6358                         curmad('X', PL_thistoken);
6359                         PL_thistoken = newSVpvs("");
6360                     }
6361 #endif
6362                     op_free(rv2cv_op);
6363                     force_next(WORD);
6364                     pl_yylval.ival = 0;
6365                     TOKEN('&');
6366                 }
6367
6368                 /* If followed by var or block, call it a method (unless sub) */
6369
6370                 if ((*s == '$' || *s == '{') && !cv) {
6371                     op_free(rv2cv_op);
6372                     PL_last_lop = PL_oldbufptr;
6373                     PL_last_lop_op = OP_METHOD;
6374                     PREBLOCK(METHOD);
6375                 }
6376
6377                 /* If followed by a bareword, see if it looks like indir obj. */
6378
6379                 if (!orig_keyword
6380                         && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
6381                         && (tmp = intuit_method(s, gv, cv))) {
6382                     op_free(rv2cv_op);
6383                     return REPORT(tmp);
6384                 }
6385
6386                 /* Not a method, so call it a subroutine (if defined) */
6387
6388                 if (cv) {
6389                     if (lastchar == '-')
6390                         Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
6391                                          "Ambiguous use of -%s resolved as -&%s()",
6392                                          PL_tokenbuf, PL_tokenbuf);
6393                     /* Check for a constant sub */
6394                     if ((sv = cv_const_sv(cv))) {
6395                   its_constant:
6396                         op_free(rv2cv_op);
6397                         SvREFCNT_dec(((SVOP*)pl_yylval.opval)->op_sv);
6398                         ((SVOP*)pl_yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
6399                         pl_yylval.opval->op_private = 0;
6400                         TOKEN(WORD);
6401                     }
6402
6403                     op_free(pl_yylval.opval);
6404                     pl_yylval.opval = rv2cv_op;
6405                     pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
6406                     PL_last_lop = PL_oldbufptr;
6407                     PL_last_lop_op = OP_ENTERSUB;
6408                     /* Is there a prototype? */
6409                     if (
6410 #ifdef PERL_MAD
6411                         cv &&
6412 #endif
6413                         SvPOK(cv))
6414                     {
6415                         STRLEN protolen;
6416                         const char *proto = SvPV_const(MUTABLE_SV(cv), protolen);
6417                         if (!protolen)
6418                             TERM(FUNC0SUB);
6419                         if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
6420                             OPERATOR(UNIOPSUB);
6421                         while (*proto == ';')
6422                             proto++;
6423                         if (*proto == '&' && *s == '{') {
6424                             if (PL_curstash)
6425                                 sv_setpvs(PL_subname, "__ANON__");
6426                             else
6427                                 sv_setpvs(PL_subname, "__ANON__::__ANON__");
6428                             PREBLOCK(LSTOPSUB);
6429                         }
6430                     }
6431 #ifdef PERL_MAD
6432                     {
6433                         if (PL_madskills) {
6434                             PL_nextwhite = PL_thiswhite;
6435                             PL_thiswhite = 0;
6436                         }
6437                         start_force(PL_curforce);
6438                         NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6439                         PL_expect = XTERM;
6440                         if (PL_madskills) {
6441                             PL_nextwhite = nextPL_nextwhite;
6442                             curmad('X', PL_thistoken);
6443                             PL_thistoken = newSVpvs("");
6444                         }
6445                         force_next(WORD);
6446                         TOKEN(NOAMP);
6447                     }
6448                 }
6449
6450                 /* Guess harder when madskills require "best effort". */
6451                 if (PL_madskills && (!gv || !GvCVu(gv))) {
6452                     int probable_sub = 0;
6453                     if (strchr("\"'`$@%0123456789!*+{[<", *s))
6454                         probable_sub = 1;
6455                     else if (isALPHA(*s)) {
6456                         char tmpbuf[1024];
6457                         STRLEN tmplen;
6458                         d = s;
6459                         d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
6460                         if (!keyword(tmpbuf, tmplen, 0))
6461                             probable_sub = 1;
6462                         else {
6463                             while (d < PL_bufend && isSPACE(*d))
6464                                 d++;
6465                             if (*d == '=' && d[1] == '>')
6466                                 probable_sub = 1;
6467                         }
6468                     }
6469                     if (probable_sub) {
6470                         gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
6471                         op_free(pl_yylval.opval);
6472                         pl_yylval.opval = rv2cv_op;
6473                         pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
6474                         PL_last_lop = PL_oldbufptr;
6475                         PL_last_lop_op = OP_ENTERSUB;
6476                         PL_nextwhite = PL_thiswhite;
6477                         PL_thiswhite = 0;
6478                         start_force(PL_curforce);
6479                         NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6480                         PL_expect = XTERM;
6481                         PL_nextwhite = nextPL_nextwhite;
6482                         curmad('X', PL_thistoken);
6483                         PL_thistoken = newSVpvs("");
6484                         force_next(WORD);
6485                         TOKEN(NOAMP);
6486                     }
6487 #else
6488                     NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
6489                     PL_expect = XTERM;
6490                     force_next(WORD);
6491                     TOKEN(NOAMP);
6492 #endif
6493                 }
6494
6495                 /* Call it a bare word */
6496
6497                 if (PL_hints & HINT_STRICT_SUBS)
6498                     pl_yylval.opval->op_private |= OPpCONST_STRICT;
6499                 else {
6500                 bareword:
6501                     /* after "print" and similar functions (corresponding to
6502                      * "F? L" in opcode.pl), whatever wasn't already parsed as
6503                      * a filehandle should be subject to "strict subs".
6504                      * Likewise for the optional indirect-object argument to system
6505                      * or exec, which can't be a bareword */
6506                     if ((PL_last_lop_op == OP_PRINT
6507                             || PL_last_lop_op == OP_PRTF
6508                             || PL_last_lop_op == OP_SAY
6509                             || PL_last_lop_op == OP_SYSTEM
6510                             || PL_last_lop_op == OP_EXEC)
6511                             && (PL_hints & HINT_STRICT_SUBS))
6512                         pl_yylval.opval->op_private |= OPpCONST_STRICT;
6513                     if (lastchar != '-') {
6514                         if (ckWARN(WARN_RESERVED)) {
6515                             d = PL_tokenbuf;
6516                             while (isLOWER(*d))
6517                                 d++;
6518                             if (!*d && !gv_stashpv(PL_tokenbuf, 0))
6519                                 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
6520                                        PL_tokenbuf);
6521                         }
6522                     }
6523                 }
6524                 op_free(rv2cv_op);
6525
6526             safe_bareword:
6527                 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')) {
6528                     Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
6529                                      "Operator or semicolon missing before %c%s",
6530                                      lastchar, PL_tokenbuf);
6531                     Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
6532                                      "Ambiguous use of %c resolved as operator %c",
6533                                      lastchar, lastchar);
6534                 }
6535                 TOKEN(WORD);
6536             }
6537
6538         case KEY___FILE__:
6539             pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
6540                                         newSVpv(CopFILE(PL_curcop),0));
6541             TERM(THING);
6542
6543         case KEY___LINE__:
6544             pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
6545                                     Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
6546             TERM(THING);
6547
6548         case KEY___PACKAGE__:
6549             pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
6550                                         (PL_curstash
6551                                          ? newSVhek(HvNAME_HEK(PL_curstash))
6552                                          : &PL_sv_undef));
6553             TERM(THING);
6554
6555         case KEY___DATA__:
6556         case KEY___END__: {
6557             GV *gv;
6558             if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
6559                 const char *pname = "main";
6560                 if (PL_tokenbuf[2] == 'D')
6561                     pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
6562                 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
6563                                 SVt_PVIO);
6564                 GvMULTI_on(gv);
6565                 if (!GvIO(gv))
6566                     GvIOp(gv) = newIO();
6567                 IoIFP(GvIOp(gv)) = PL_rsfp;
6568 #if defined(HAS_FCNTL) && defined(F_SETFD)
6569                 {
6570                     const int fd = PerlIO_fileno(PL_rsfp);
6571                     fcntl(fd,F_SETFD,fd >= 3);
6572                 }
6573 #endif
6574                 /* Mark this internal pseudo-handle as clean */
6575                 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
6576                 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
6577                     IoTYPE(GvIOp(gv)) = IoTYPE_STD;
6578                 else
6579                     IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
6580 #if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
6581                 /* if the script was opened in binmode, we need to revert
6582                  * it to text mode for compatibility; but only iff it has CRs
6583                  * XXX this is a questionable hack at best. */
6584                 if (PL_bufend-PL_bufptr > 2
6585                     && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
6586                 {
6587                     Off_t loc = 0;
6588                     if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
6589                         loc = PerlIO_tell(PL_rsfp);
6590                         (void)PerlIO_seek(PL_rsfp, 0L, 0);
6591                     }
6592 #ifdef NETWARE
6593                         if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
6594 #else
6595                     if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
6596 #endif  /* NETWARE */
6597 #ifdef PERLIO_IS_STDIO /* really? */
6598 #  if defined(__BORLANDC__)
6599                         /* XXX see note in do_binmode() */
6600                         ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
6601 #  endif
6602 #endif
6603                         if (loc > 0)
6604                             PerlIO_seek(PL_rsfp, loc, 0);
6605                     }
6606                 }
6607 #endif
6608 #ifdef PERLIO_LAYERS
6609                 if (!IN_BYTES) {
6610                     if (UTF)
6611                         PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
6612                     else if (PL_encoding) {
6613                         SV *name;
6614                         dSP;
6615                         ENTER;
6616                         SAVETMPS;
6617                         PUSHMARK(sp);
6618                         EXTEND(SP, 1);
6619                         XPUSHs(PL_encoding);
6620                         PUTBACK;
6621                         call_method("name", G_SCALAR);
6622                         SPAGAIN;
6623                         name = POPs;
6624                         PUTBACK;
6625                         PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
6626                                             Perl_form(aTHX_ ":encoding(%"SVf")",
6627                                                       SVfARG(name)));
6628                         FREETMPS;
6629                         LEAVE;
6630                     }
6631                 }
6632 #endif
6633 #ifdef PERL_MAD
6634                 if (PL_madskills) {
6635                     if (PL_realtokenstart >= 0) {
6636                         char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
6637                         if (!PL_endwhite)
6638                             PL_endwhite = newSVpvs("");
6639                         sv_catsv(PL_endwhite, PL_thiswhite);
6640                         PL_thiswhite = 0;
6641                         sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
6642                         PL_realtokenstart = -1;
6643                     }
6644                     while ((s = filter_gets(PL_endwhite, SvCUR(PL_endwhite)))
6645                            != NULL) ;
6646                 }
6647 #endif
6648                 PL_rsfp = NULL;
6649             }
6650             goto fake_eof;
6651         }
6652
6653         case KEY_AUTOLOAD:
6654         case KEY_DESTROY:
6655         case KEY_BEGIN:
6656         case KEY_UNITCHECK:
6657         case KEY_CHECK:
6658         case KEY_INIT:
6659         case KEY_END:
6660             if (PL_expect == XSTATE) {
6661                 s = PL_bufptr;
6662                 goto really_sub;
6663             }
6664             goto just_a_word;
6665
6666         case KEY_CORE:
6667             if (*s == ':' && s[1] == ':') {
6668                 s += 2;
6669                 d = s;
6670                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
6671                 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
6672                     Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
6673                 if (tmp < 0)
6674                     tmp = -tmp;
6675                 else if (tmp == KEY_require || tmp == KEY_do)
6676                     /* that's a way to remember we saw "CORE::" */
6677                     orig_keyword = tmp;
6678                 goto reserved_word;
6679             }
6680             goto just_a_word;
6681
6682         case KEY_abs:
6683             UNI(OP_ABS);
6684
6685         case KEY_alarm:
6686             UNI(OP_ALARM);
6687
6688         case KEY_accept:
6689             LOP(OP_ACCEPT,XTERM);
6690
6691         case KEY_and:
6692             OPERATOR(ANDOP);
6693
6694         case KEY_atan2:
6695             LOP(OP_ATAN2,XTERM);
6696
6697         case KEY_bind:
6698             LOP(OP_BIND,XTERM);
6699
6700         case KEY_binmode:
6701             LOP(OP_BINMODE,XTERM);
6702
6703         case KEY_bless:
6704             LOP(OP_BLESS,XTERM);
6705
6706         case KEY_break:
6707             FUN0(OP_BREAK);
6708
6709         case KEY_chop:
6710             UNI(OP_CHOP);
6711
6712         case KEY_continue:
6713             /* When 'use switch' is in effect, continue has a dual
6714                life as a control operator. */
6715             {
6716                 if (!FEATURE_IS_ENABLED("switch"))
6717                     PREBLOCK(CONTINUE);
6718                 else {
6719                     /* We have to disambiguate the two senses of
6720                       "continue". If the next token is a '{' then
6721                       treat it as the start of a continue block;
6722                       otherwise treat it as a control operator.
6723                      */
6724                     s = skipspace(s);
6725                     if (*s == '{')
6726             PREBLOCK(CONTINUE);
6727                     else
6728                         FUN0(OP_CONTINUE);
6729                 }
6730             }
6731
6732         case KEY_chdir:
6733             /* may use HOME */
6734             (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
6735             UNI(OP_CHDIR);
6736
6737         case KEY_close:
6738             UNI(OP_CLOSE);
6739
6740         case KEY_closedir:
6741             UNI(OP_CLOSEDIR);
6742
6743         case KEY_cmp:
6744             Eop(OP_SCMP);
6745
6746         case KEY_caller:
6747             UNI(OP_CALLER);
6748
6749         case KEY_crypt:
6750 #ifdef FCRYPT
6751             if (!PL_cryptseen) {
6752                 PL_cryptseen = TRUE;
6753                 init_des();
6754             }
6755 #endif
6756             LOP(OP_CRYPT,XTERM);
6757
6758         case KEY_chmod:
6759             LOP(OP_CHMOD,XTERM);
6760
6761         case KEY_chown:
6762             LOP(OP_CHOWN,XTERM);
6763
6764         case KEY_connect:
6765             LOP(OP_CONNECT,XTERM);
6766
6767         case KEY_chr:
6768             UNI(OP_CHR);
6769
6770         case KEY_cos:
6771             UNI(OP_COS);
6772
6773         case KEY_chroot:
6774             UNI(OP_CHROOT);
6775
6776         case KEY_default:
6777             PREBLOCK(DEFAULT);
6778
6779         case KEY_do:
6780             s = SKIPSPACE1(s);
6781             if (*s == '{')
6782                 PRETERMBLOCK(DO);
6783             if (*s != '\'')
6784                 s = force_word(s,WORD,TRUE,TRUE,FALSE);
6785             if (orig_keyword == KEY_do) {
6786                 orig_keyword = 0;
6787                 pl_yylval.ival = 1;
6788             }
6789             else
6790                 pl_yylval.ival = 0;
6791             OPERATOR(DO);
6792
6793         case KEY_die:
6794             PL_hints |= HINT_BLOCK_SCOPE;
6795             LOP(OP_DIE,XTERM);
6796
6797         case KEY_defined:
6798             UNI(OP_DEFINED);
6799
6800         case KEY_delete:
6801             UNI(OP_DELETE);
6802
6803         case KEY_dbmopen:
6804             gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
6805             LOP(OP_DBMOPEN,XTERM);
6806
6807         case KEY_dbmclose:
6808             UNI(OP_DBMCLOSE);
6809
6810         case KEY_dump:
6811             s = force_word(s,WORD,TRUE,FALSE,FALSE);
6812             LOOPX(OP_DUMP);
6813
6814         case KEY_else:
6815             PREBLOCK(ELSE);
6816
6817         case KEY_elsif:
6818             pl_yylval.ival = CopLINE(PL_curcop);
6819             OPERATOR(ELSIF);
6820
6821         case KEY_eq:
6822             Eop(OP_SEQ);
6823
6824         case KEY_exists:
6825             UNI(OP_EXISTS);
6826         
6827         case KEY_exit:
6828             if (PL_madskills)
6829                 UNI(OP_INT);
6830             UNI(OP_EXIT);
6831
6832         case KEY_eval:
6833             s = SKIPSPACE1(s);
6834             if (*s == '{') { /* block eval */
6835                 PL_expect = XTERMBLOCK;
6836                 UNIBRACK(OP_ENTERTRY);
6837             }
6838             else { /* string eval */
6839                 PL_expect = XTERM;
6840                 UNIBRACK(OP_ENTEREVAL);
6841             }
6842
6843         case KEY_eof:
6844             UNI(OP_EOF);
6845
6846         case KEY_exp:
6847             UNI(OP_EXP);
6848
6849         case KEY_each:
6850             UNI(OP_EACH);
6851
6852         case KEY_exec:
6853             LOP(OP_EXEC,XREF);
6854
6855         case KEY_endhostent:
6856             FUN0(OP_EHOSTENT);
6857
6858         case KEY_endnetent:
6859             FUN0(OP_ENETENT);
6860
6861         case KEY_endservent:
6862             FUN0(OP_ESERVENT);
6863
6864         case KEY_endprotoent:
6865             FUN0(OP_EPROTOENT);
6866
6867         case KEY_endpwent:
6868             FUN0(OP_EPWENT);
6869
6870         case KEY_endgrent:
6871             FUN0(OP_EGRENT);
6872
6873         case KEY_for:
6874         case KEY_foreach:
6875             pl_yylval.ival = CopLINE(PL_curcop);
6876             s = SKIPSPACE1(s);
6877             if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
6878                 char *p = s;
6879 #ifdef PERL_MAD
6880                 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
6881 #endif
6882
6883                 if ((PL_bufend - p) >= 3 &&
6884                     strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
6885                     p += 2;
6886                 else if ((PL_bufend - p) >= 4 &&
6887                     strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
6888                     p += 3;
6889                 p = PEEKSPACE(p);
6890                 if (isIDFIRST_lazy_if(p,UTF)) {
6891                     p = scan_ident(p, PL_bufend,
6892                         PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
6893                     p = PEEKSPACE(p);
6894                 }
6895                 if (*p != '$')
6896                     Perl_croak(aTHX_ "Missing $ on loop variable");
6897 #ifdef PERL_MAD
6898                 s = SvPVX(PL_linestr) + soff;
6899 #endif
6900             }
6901             OPERATOR(FOR);
6902
6903         case KEY_formline:
6904             LOP(OP_FORMLINE,XTERM);
6905
6906         case KEY_fork:
6907             FUN0(OP_FORK);
6908
6909         case KEY_fcntl:
6910             LOP(OP_FCNTL,XTERM);
6911
6912         case KEY_fileno:
6913             UNI(OP_FILENO);
6914
6915         case KEY_flock:
6916             LOP(OP_FLOCK,XTERM);
6917
6918         case KEY_gt:
6919             Rop(OP_SGT);
6920
6921         case KEY_ge:
6922             Rop(OP_SGE);
6923
6924         case KEY_grep:
6925             LOP(OP_GREPSTART, XREF);
6926
6927         case KEY_goto:
6928             s = force_word(s,WORD,TRUE,FALSE,FALSE);
6929             LOOPX(OP_GOTO);
6930
6931         case KEY_gmtime:
6932             UNI(OP_GMTIME);
6933
6934         case KEY_getc:
6935             UNIDOR(OP_GETC);
6936
6937         case KEY_getppid:
6938             FUN0(OP_GETPPID);
6939
6940         case KEY_getpgrp:
6941             UNI(OP_GETPGRP);
6942
6943         case KEY_getpriority:
6944             LOP(OP_GETPRIORITY,XTERM);
6945
6946         case KEY_getprotobyname:
6947             UNI(OP_GPBYNAME);
6948
6949         case KEY_getprotobynumber:
6950             LOP(OP_GPBYNUMBER,XTERM);
6951
6952         case KEY_getprotoent:
6953             FUN0(OP_GPROTOENT);
6954
6955         case KEY_getpwent:
6956             FUN0(OP_GPWENT);
6957
6958         case KEY_getpwnam:
6959             UNI(OP_GPWNAM);
6960
6961         case KEY_getpwuid:
6962             UNI(OP_GPWUID);
6963
6964         case KEY_getpeername:
6965             UNI(OP_GETPEERNAME);
6966
6967         case KEY_gethostbyname:
6968             UNI(OP_GHBYNAME);
6969
6970         case KEY_gethostbyaddr:
6971             LOP(OP_GHBYADDR,XTERM);
6972
6973         case KEY_gethostent:
6974             FUN0(OP_GHOSTENT);
6975
6976         case KEY_getnetbyname:
6977             UNI(OP_GNBYNAME);
6978
6979         case KEY_getnetbyaddr:
6980             LOP(OP_GNBYADDR,XTERM);
6981
6982         case KEY_getnetent:
6983             FUN0(OP_GNETENT);
6984
6985         case KEY_getservbyname:
6986             LOP(OP_GSBYNAME,XTERM);
6987
6988         case KEY_getservbyport:
6989             LOP(OP_GSBYPORT,XTERM);
6990
6991         case KEY_getservent:
6992             FUN0(OP_GSERVENT);
6993
6994         case KEY_getsockname:
6995             UNI(OP_GETSOCKNAME);
6996
6997         case KEY_getsockopt:
6998             LOP(OP_GSOCKOPT,XTERM);
6999
7000         case KEY_getgrent:
7001             FUN0(OP_GGRENT);
7002
7003         case KEY_getgrnam:
7004             UNI(OP_GGRNAM);
7005
7006         case KEY_getgrgid:
7007             UNI(OP_GGRGID);
7008
7009         case KEY_getlogin:
7010             FUN0(OP_GETLOGIN);
7011
7012         case KEY_given:
7013             pl_yylval.ival = CopLINE(PL_curcop);
7014             OPERATOR(GIVEN);
7015
7016         case KEY_glob:
7017             LOP(OP_GLOB,XTERM);
7018
7019         case KEY_hex:
7020             UNI(OP_HEX);
7021
7022         case KEY_if:
7023             pl_yylval.ival = CopLINE(PL_curcop);
7024             OPERATOR(IF);
7025
7026         case KEY_index:
7027             LOP(OP_INDEX,XTERM);
7028
7029         case KEY_int:
7030             UNI(OP_INT);
7031
7032         case KEY_ioctl:
7033             LOP(OP_IOCTL,XTERM);
7034
7035         case KEY_join:
7036             LOP(OP_JOIN,XTERM);
7037
7038         case KEY_keys:
7039             UNI(OP_KEYS);
7040
7041         case KEY_kill:
7042             LOP(OP_KILL,XTERM);
7043
7044         case KEY_last:
7045             s = force_word(s,WORD,TRUE,FALSE,FALSE);
7046             LOOPX(OP_LAST);
7047         
7048         case KEY_lc:
7049             UNI(OP_LC);
7050
7051         case KEY_lcfirst:
7052             UNI(OP_LCFIRST);
7053
7054         case KEY_local:
7055             pl_yylval.ival = 0;
7056             OPERATOR(LOCAL);
7057
7058         case KEY_length:
7059             UNI(OP_LENGTH);
7060
7061         case KEY_lt:
7062             Rop(OP_SLT);
7063
7064         case KEY_le:
7065             Rop(OP_SLE);
7066
7067         case KEY_localtime:
7068             UNI(OP_LOCALTIME);
7069
7070         case KEY_log:
7071             UNI(OP_LOG);
7072
7073         case KEY_link:
7074             LOP(OP_LINK,XTERM);
7075
7076         case KEY_listen:
7077             LOP(OP_LISTEN,XTERM);
7078
7079         case KEY_lock:
7080             UNI(OP_LOCK);
7081
7082         case KEY_lstat:
7083             UNI(OP_LSTAT);
7084
7085         case KEY_m:
7086             s = scan_pat(s,OP_MATCH);
7087             TERM(sublex_start());
7088
7089         case KEY_map:
7090             LOP(OP_MAPSTART, XREF);
7091
7092         case KEY_mkdir:
7093             LOP(OP_MKDIR,XTERM);
7094
7095         case KEY_msgctl:
7096             LOP(OP_MSGCTL,XTERM);
7097
7098         case KEY_msgget:
7099             LOP(OP_MSGGET,XTERM);
7100
7101         case KEY_msgrcv:
7102             LOP(OP_MSGRCV,XTERM);
7103
7104         case KEY_msgsnd:
7105             LOP(OP_MSGSND,XTERM);
7106
7107         case KEY_our:
7108         case KEY_my:
7109         case KEY_state:
7110             PL_in_my = (U16)tmp;
7111             s = SKIPSPACE1(s);
7112             if (isIDFIRST_lazy_if(s,UTF)) {
7113 #ifdef PERL_MAD
7114                 char* start = s;
7115 #endif
7116                 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
7117                 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
7118                     goto really_sub;
7119                 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
7120                 if (!PL_in_my_stash) {
7121                     char tmpbuf[1024];
7122                     PL_bufptr = s;
7123                     my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
7124                     yyerror(tmpbuf);
7125                 }
7126 #ifdef PERL_MAD
7127                 if (PL_madskills) {     /* just add type to declarator token */
7128                     sv_catsv(PL_thistoken, PL_nextwhite);
7129                     PL_nextwhite = 0;
7130                     sv_catpvn(PL_thistoken, start, s - start);
7131                 }
7132 #endif
7133             }
7134             pl_yylval.ival = 1;
7135             OPERATOR(MY);
7136
7137         case KEY_next:
7138             s = force_word(s,WORD,TRUE,FALSE,FALSE);
7139             LOOPX(OP_NEXT);
7140
7141         case KEY_ne:
7142             Eop(OP_SNE);
7143
7144         case KEY_no:
7145             s = tokenize_use(0, s);
7146             OPERATOR(USE);
7147
7148         case KEY_not:
7149             if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
7150                 FUN1(OP_NOT);
7151             else
7152                 OPERATOR(NOTOP);
7153
7154         case KEY_open:
7155             s = SKIPSPACE1(s);
7156             if (isIDFIRST_lazy_if(s,UTF)) {
7157                 const char *t;
7158                 for (d = s; isALNUM_lazy_if(d,UTF);)
7159                     d++;
7160                 for (t=d; isSPACE(*t);)
7161                     t++;
7162                 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
7163                     /* [perl #16184] */
7164                     && !(t[0] == '=' && t[1] == '>')
7165                 ) {
7166                     int parms_len = (int)(d-s);
7167                     Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
7168                            "Precedence problem: open %.*s should be open(%.*s)",
7169                             parms_len, s, parms_len, s);
7170                 }
7171             }
7172             LOP(OP_OPEN,XTERM);
7173
7174         case KEY_or:
7175             pl_yylval.ival = OP_OR;
7176             OPERATOR(OROP);
7177
7178         case KEY_ord:
7179             UNI(OP_ORD);
7180
7181         case KEY_oct:
7182             UNI(OP_OCT);
7183
7184         case KEY_opendir:
7185             LOP(OP_OPEN_DIR,XTERM);
7186
7187         case KEY_print:
7188             checkcomma(s,PL_tokenbuf,"filehandle");
7189             LOP(OP_PRINT,XREF);
7190
7191         case KEY_printf:
7192             checkcomma(s,PL_tokenbuf,"filehandle");
7193             LOP(OP_PRTF,XREF);
7194
7195         case KEY_prototype:
7196             UNI(OP_PROTOTYPE);
7197
7198         case KEY_push:
7199             LOP(OP_PUSH,XTERM);
7200
7201         case KEY_pop:
7202             UNIDOR(OP_POP);
7203
7204         case KEY_pos:
7205             UNIDOR(OP_POS);
7206         
7207         case KEY_pack:
7208             LOP(OP_PACK,XTERM);
7209
7210         case KEY_package:
7211             s = force_word(s,WORD,FALSE,TRUE,FALSE);
7212             s = SKIPSPACE1(s);
7213             s = force_strict_version(s);
7214             OPERATOR(PACKAGE);
7215
7216         case KEY_pipe:
7217             LOP(OP_PIPE_OP,XTERM);
7218
7219         case KEY_q:
7220             s = scan_str(s,!!PL_madskills,FALSE);
7221             if (!s)
7222                 missingterm(NULL);
7223             pl_yylval.ival = OP_CONST;
7224             TERM(sublex_start());
7225
7226         case KEY_quotemeta:
7227             UNI(OP_QUOTEMETA);
7228
7229         case KEY_qw:
7230             s = scan_str(s,!!PL_madskills,FALSE);
7231             if (!s)
7232                 missingterm(NULL);
7233             PL_expect = XOPERATOR;
7234             force_next(')');
7235             if (SvCUR(PL_lex_stuff)) {
7236                 OP *words = NULL;
7237                 int warned = 0;
7238                 d = SvPV_force(PL_lex_stuff, len);
7239                 while (len) {
7240                     for (; isSPACE(*d) && len; --len, ++d)
7241                         /**/;
7242                     if (len) {
7243                         SV *sv;
7244                         const char *b = d;
7245                         if (!warned && ckWARN(WARN_QW)) {
7246                             for (; !isSPACE(*d) && len; --len, ++d) {
7247                                 if (*d == ',') {
7248                                     Perl_warner(aTHX_ packWARN(WARN_QW),
7249                                         "Possible attempt to separate words with commas");
7250                                     ++warned;
7251                                 }
7252                                 else if (*d == '#') {
7253                                     Perl_warner(aTHX_ packWARN(WARN_QW),
7254                                         "Possible attempt to put comments in qw() list");
7255                                     ++warned;
7256                                 }
7257                             }
7258                         }
7259                         else {
7260                             for (; !isSPACE(*d) && len; --len, ++d)
7261                                 /**/;
7262                         }
7263                         sv = newSVpvn_utf8(b, d-b, DO_UTF8(PL_lex_stuff));
7264                         words = append_elem(OP_LIST, words,
7265                                             newSVOP(OP_CONST, 0, tokeq(sv)));
7266                     }
7267                 }
7268                 if (words) {
7269                     start_force(PL_curforce);
7270                     NEXTVAL_NEXTTOKE.opval = words;
7271                     force_next(THING);
7272                 }
7273             }
7274             if (PL_lex_stuff) {
7275                 SvREFCNT_dec(PL_lex_stuff);
7276                 PL_lex_stuff = NULL;
7277             }
7278             PL_expect = XTERM;
7279             TOKEN('(');
7280
7281         case KEY_qq:
7282             s = scan_str(s,!!PL_madskills,FALSE);
7283             if (!s)
7284                 missingterm(NULL);
7285             pl_yylval.ival = OP_STRINGIFY;
7286             if (SvIVX(PL_lex_stuff) == '\'')
7287                 SvIV_set(PL_lex_stuff, 0);      /* qq'$foo' should intepolate */
7288             TERM(sublex_start());
7289
7290         case KEY_qr:
7291             s = scan_pat(s,OP_QR);
7292             TERM(sublex_start());
7293
7294         case KEY_qx:
7295             s = scan_str(s,!!PL_madskills,FALSE);
7296             if (!s)
7297                 missingterm(NULL);
7298             readpipe_override();
7299             TERM(sublex_start());
7300
7301         case KEY_return:
7302             OLDLOP(OP_RETURN);
7303
7304         case KEY_require:
7305             s = SKIPSPACE1(s);
7306             if (isDIGIT(*s)) {
7307                 s = force_version(s, FALSE);
7308             }
7309             else if (*s != 'v' || !isDIGIT(s[1])
7310                     || (s = force_version(s, TRUE), *s == 'v'))
7311             {
7312                 *PL_tokenbuf = '\0';
7313                 s = force_word(s,WORD,TRUE,TRUE,FALSE);
7314                 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
7315                     gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
7316                 else if (*s == '<')
7317                     yyerror("<> should be quotes");
7318             }
7319             if (orig_keyword == KEY_require) {
7320                 orig_keyword = 0;
7321                 pl_yylval.ival = 1;
7322             }
7323             else 
7324                 pl_yylval.ival = 0;
7325             PL_expect = XTERM;
7326             PL_bufptr = s;
7327             PL_last_uni = PL_oldbufptr;
7328             PL_last_lop_op = OP_REQUIRE;
7329             s = skipspace(s);
7330             return REPORT( (int)REQUIRE );
7331
7332         case KEY_reset:
7333             UNI(OP_RESET);
7334
7335         case KEY_redo:
7336             s = force_word(s,WORD,TRUE,FALSE,FALSE);
7337             LOOPX(OP_REDO);
7338
7339         case KEY_rename:
7340             LOP(OP_RENAME,XTERM);
7341
7342         case KEY_rand:
7343             UNI(OP_RAND);
7344
7345         case KEY_rmdir:
7346             UNI(OP_RMDIR);
7347
7348         case KEY_rindex:
7349             LOP(OP_RINDEX,XTERM);
7350
7351         case KEY_read:
7352             LOP(OP_READ,XTERM);
7353
7354         case KEY_readdir:
7355             UNI(OP_READDIR);
7356
7357         case KEY_readline:
7358             UNIDOR(OP_READLINE);
7359
7360         case KEY_readpipe:
7361             UNIDOR(OP_BACKTICK);
7362
7363         case KEY_rewinddir:
7364             UNI(OP_REWINDDIR);
7365
7366         case KEY_recv:
7367             LOP(OP_RECV,XTERM);
7368
7369         case KEY_reverse:
7370             LOP(OP_REVERSE,XTERM);
7371
7372         case KEY_readlink:
7373             UNIDOR(OP_READLINK);
7374
7375         case KEY_ref:
7376             UNI(OP_REF);
7377
7378         case KEY_s:
7379             s = scan_subst(s);
7380             if (pl_yylval.opval)
7381                 TERM(sublex_start());
7382             else
7383                 TOKEN(1);       /* force error */
7384
7385         case KEY_say:
7386             checkcomma(s,PL_tokenbuf,"filehandle");
7387             LOP(OP_SAY,XREF);
7388
7389         case KEY_chomp:
7390             UNI(OP_CHOMP);
7391         
7392         case KEY_scalar:
7393             UNI(OP_SCALAR);
7394
7395         case KEY_select:
7396             LOP(OP_SELECT,XTERM);
7397
7398         case KEY_seek:
7399             LOP(OP_SEEK,XTERM);
7400
7401         case KEY_semctl:
7402             LOP(OP_SEMCTL,XTERM);
7403
7404         case KEY_semget:
7405             LOP(OP_SEMGET,XTERM);
7406
7407         case KEY_semop:
7408             LOP(OP_SEMOP,XTERM);
7409
7410         case KEY_send:
7411             LOP(OP_SEND,XTERM);
7412
7413         case KEY_setpgrp:
7414             LOP(OP_SETPGRP,XTERM);
7415
7416         case KEY_setpriority:
7417             LOP(OP_SETPRIORITY,XTERM);
7418
7419         case KEY_sethostent:
7420             UNI(OP_SHOSTENT);
7421
7422         case KEY_setnetent:
7423             UNI(OP_SNETENT);
7424
7425         case KEY_setservent:
7426             UNI(OP_SSERVENT);
7427
7428         case KEY_setprotoent:
7429             UNI(OP_SPROTOENT);
7430
7431         case KEY_setpwent:
7432             FUN0(OP_SPWENT);
7433
7434         case KEY_setgrent:
7435             FUN0(OP_SGRENT);
7436
7437         case KEY_seekdir:
7438             LOP(OP_SEEKDIR,XTERM);
7439
7440         case KEY_setsockopt:
7441             LOP(OP_SSOCKOPT,XTERM);
7442
7443         case KEY_shift:
7444             UNIDOR(OP_SHIFT);
7445
7446         case KEY_shmctl:
7447             LOP(OP_SHMCTL,XTERM);
7448
7449         case KEY_shmget:
7450             LOP(OP_SHMGET,XTERM);
7451
7452         case KEY_shmread:
7453             LOP(OP_SHMREAD,XTERM);
7454
7455         case KEY_shmwrite:
7456             LOP(OP_SHMWRITE,XTERM);
7457
7458         case KEY_shutdown:
7459             LOP(OP_SHUTDOWN,XTERM);
7460
7461         case KEY_sin:
7462             UNI(OP_SIN);
7463
7464         case KEY_sleep:
7465             UNI(OP_SLEEP);
7466
7467         case KEY_socket:
7468             LOP(OP_SOCKET,XTERM);
7469
7470         case KEY_socketpair:
7471             LOP(OP_SOCKPAIR,XTERM);
7472
7473         case KEY_sort:
7474             checkcomma(s,PL_tokenbuf,"subroutine name");
7475             s = SKIPSPACE1(s);
7476             if (*s == ';' || *s == ')')         /* probably a close */
7477                 Perl_croak(aTHX_ "sort is now a reserved word");
7478             PL_expect = XTERM;
7479             s = force_word(s,WORD,TRUE,TRUE,FALSE);
7480             LOP(OP_SORT,XREF);
7481
7482         case KEY_split:
7483             LOP(OP_SPLIT,XTERM);
7484
7485         case KEY_sprintf:
7486             LOP(OP_SPRINTF,XTERM);
7487
7488         case KEY_splice:
7489             LOP(OP_SPLICE,XTERM);
7490
7491         case KEY_sqrt:
7492             UNI(OP_SQRT);
7493
7494         case KEY_srand:
7495             UNI(OP_SRAND);
7496
7497         case KEY_stat:
7498             UNI(OP_STAT);
7499
7500         case KEY_study:
7501             UNI(OP_STUDY);
7502
7503         case KEY_substr:
7504             LOP(OP_SUBSTR,XTERM);
7505
7506         case KEY_format:
7507         case KEY_sub:
7508           really_sub:
7509             {
7510                 char tmpbuf[sizeof PL_tokenbuf];
7511                 SSize_t tboffset = 0;
7512                 expectation attrful;
7513                 bool have_name, have_proto;
7514                 const int key = tmp;
7515
7516 #ifdef PERL_MAD
7517                 SV *tmpwhite = 0;
7518
7519                 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
7520                 SV *subtoken = newSVpvn(tstart, s - tstart);
7521                 PL_thistoken = 0;
7522
7523                 d = s;
7524                 s = SKIPSPACE2(s,tmpwhite);
7525 #else
7526                 s = skipspace(s);
7527 #endif
7528
7529                 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
7530                     (*s == ':' && s[1] == ':'))
7531                 {
7532 #ifdef PERL_MAD
7533                     SV *nametoke = NULL;
7534 #endif
7535
7536                     PL_expect = XBLOCK;
7537                     attrful = XATTRBLOCK;
7538                     /* remember buffer pos'n for later force_word */
7539                     tboffset = s - PL_oldbufptr;
7540                     d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
7541 #ifdef PERL_MAD
7542                     if (PL_madskills)
7543                         nametoke = newSVpvn(s, d - s);
7544 #endif
7545                     if (memchr(tmpbuf, ':', len))
7546                         sv_setpvn(PL_subname, tmpbuf, len);
7547                     else {
7548                         sv_setsv(PL_subname,PL_curstname);
7549                         sv_catpvs(PL_subname,"::");
7550                         sv_catpvn(PL_subname,tmpbuf,len);
7551                     }
7552                     have_name = TRUE;
7553
7554 #ifdef PERL_MAD
7555
7556                     start_force(0);
7557                     CURMAD('X', nametoke);
7558                     CURMAD('_', tmpwhite);
7559                     (void) force_word(PL_oldbufptr + tboffset, WORD,
7560                                       FALSE, TRUE, TRUE);
7561
7562                     s = SKIPSPACE2(d,tmpwhite);
7563 #else
7564                     s = skipspace(d);
7565 #endif
7566                 }
7567                 else {
7568                     if (key == KEY_my)
7569                         Perl_croak(aTHX_ "Missing name in \"my sub\"");
7570                     PL_expect = XTERMBLOCK;
7571                     attrful = XATTRTERM;
7572                     sv_setpvs(PL_subname,"?");
7573                     have_name = FALSE;
7574                 }
7575
7576                 if (key == KEY_format) {
7577                     if (*s == '=')
7578                         PL_lex_formbrack = PL_lex_brackets + 1;
7579 #ifdef PERL_MAD
7580                     PL_thistoken = subtoken;
7581                     s = d;
7582 #else
7583                     if (have_name)
7584                         (void) force_word(PL_oldbufptr + tboffset, WORD,
7585                                           FALSE, TRUE, TRUE);
7586 #endif
7587                     OPERATOR(FORMAT);
7588                 }
7589
7590                 /* Look for a prototype */
7591                 if (*s == '(') {
7592                     char *p;
7593                     bool bad_proto = FALSE;
7594                     bool in_brackets = FALSE;
7595                     char greedy_proto = ' ';
7596                     bool proto_after_greedy_proto = FALSE;
7597                     bool must_be_last = FALSE;
7598                     bool underscore = FALSE;
7599                     bool seen_underscore = FALSE;
7600                     const bool warnillegalproto = ckWARN(WARN_ILLEGALPROTO);
7601
7602                     s = scan_str(s,!!PL_madskills,FALSE);
7603                     if (!s)
7604                         Perl_croak(aTHX_ "Prototype not terminated");
7605                     /* strip spaces and check for bad characters */
7606                     d = SvPVX(PL_lex_stuff);
7607                     tmp = 0;
7608                     for (p = d; *p; ++p) {
7609                         if (!isSPACE(*p)) {
7610                             d[tmp++] = *p;
7611
7612                             if (warnillegalproto) {
7613                                 if (must_be_last)
7614                                     proto_after_greedy_proto = TRUE;
7615                                 if (!strchr("$@%*;[]&\\_", *p)) {
7616                                     bad_proto = TRUE;
7617                                 }
7618                                 else {
7619                                     if ( underscore ) {
7620                                         if ( *p != ';' )
7621                                             bad_proto = TRUE;
7622                                         underscore = FALSE;
7623                                     }
7624                                     if ( *p == '[' ) {
7625                                         in_brackets = TRUE;
7626                                     }
7627                                     else if ( *p == ']' ) {
7628                                         in_brackets = FALSE;
7629                                     }
7630                                     else if ( (*p == '@' || *p == '%') &&
7631                                          ( tmp < 2 || d[tmp-2] != '\\' ) &&
7632                                          !in_brackets ) {
7633                                         must_be_last = TRUE;
7634                                         greedy_proto = *p;
7635                                     }
7636                                     else if ( *p == '_' ) {
7637                                         underscore = seen_underscore = TRUE;
7638                                     }
7639                                 }
7640                             }
7641                         }
7642                     }
7643                     d[tmp] = '\0';
7644                     if (proto_after_greedy_proto)
7645                         Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO),
7646                                     "Prototype after '%c' for %"SVf" : %s",
7647                                     greedy_proto, SVfARG(PL_subname), d);
7648                     if (bad_proto)
7649                         Perl_warner(aTHX_ packWARN(WARN_ILLEGALPROTO),
7650                                     "Illegal character %sin prototype for %"SVf" : %s",
7651                                     seen_underscore ? "after '_' " : "",
7652                                     SVfARG(PL_subname), d);
7653                     SvCUR_set(PL_lex_stuff, tmp);
7654                     have_proto = TRUE;
7655
7656 #ifdef PERL_MAD
7657                     start_force(0);
7658                     CURMAD('q', PL_thisopen);
7659                     CURMAD('_', tmpwhite);
7660                     CURMAD('=', PL_thisstuff);
7661                     CURMAD('Q', PL_thisclose);
7662                     NEXTVAL_NEXTTOKE.opval =
7663                         (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
7664                     PL_lex_stuff = NULL;
7665                     force_next(THING);
7666
7667                     s = SKIPSPACE2(s,tmpwhite);
7668 #else
7669                     s = skipspace(s);
7670 #endif
7671                 }
7672                 else
7673                     have_proto = FALSE;
7674
7675                 if (*s == ':' && s[1] != ':')
7676                     PL_expect = attrful;
7677                 else if (*s != '{' && key == KEY_sub) {
7678                     if (!have_name)
7679                         Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
7680                     else if (*s != ';' && *s != '}')
7681                         Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
7682                 }
7683
7684 #ifdef PERL_MAD
7685                 start_force(0);
7686                 if (tmpwhite) {
7687                     if (PL_madskills)
7688                         curmad('^', newSVpvs(""));
7689                     CURMAD('_', tmpwhite);
7690                 }
7691                 force_next(0);
7692
7693                 PL_thistoken = subtoken;
7694 #else
7695                 if (have_proto) {
7696                     NEXTVAL_NEXTTOKE.opval =
7697                         (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
7698                     PL_lex_stuff = NULL;
7699                     force_next(THING);
7700                 }
7701 #endif
7702                 if (!have_name) {
7703                     if (PL_curstash)
7704                         sv_setpvs(PL_subname, "__ANON__");
7705                     else
7706                         sv_setpvs(PL_subname, "__ANON__::__ANON__");
7707                     TOKEN(ANONSUB);
7708                 }
7709 #ifndef PERL_MAD
7710                 (void) force_word(PL_oldbufptr + tboffset, WORD,
7711                                   FALSE, TRUE, TRUE);
7712 #endif
7713                 if (key == KEY_my)
7714                     TOKEN(MYSUB);
7715                 TOKEN(SUB);
7716             }
7717
7718         case KEY_system:
7719             LOP(OP_SYSTEM,XREF);
7720
7721         case KEY_symlink:
7722             LOP(OP_SYMLINK,XTERM);
7723
7724         case KEY_syscall:
7725             LOP(OP_SYSCALL,XTERM);
7726
7727         case KEY_sysopen:
7728             LOP(OP_SYSOPEN,XTERM);
7729
7730         case KEY_sysseek:
7731             LOP(OP_SYSSEEK,XTERM);
7732
7733         case KEY_sysread:
7734             LOP(OP_SYSREAD,XTERM);
7735
7736         case KEY_syswrite:
7737             LOP(OP_SYSWRITE,XTERM);
7738
7739         case KEY_tr:
7740             s = scan_trans(s);
7741             TERM(sublex_start());
7742
7743         case KEY_tell:
7744             UNI(OP_TELL);
7745
7746         case KEY_telldir:
7747             UNI(OP_TELLDIR);
7748
7749         case KEY_tie:
7750             LOP(OP_TIE,XTERM);
7751
7752         case KEY_tied:
7753             UNI(OP_TIED);
7754
7755         case KEY_time:
7756             FUN0(OP_TIME);
7757
7758         case KEY_times:
7759             FUN0(OP_TMS);
7760
7761         case KEY_truncate:
7762             LOP(OP_TRUNCATE,XTERM);
7763
7764         case KEY_uc:
7765             UNI(OP_UC);
7766
7767         case KEY_ucfirst:
7768             UNI(OP_UCFIRST);
7769
7770         case KEY_untie:
7771             UNI(OP_UNTIE);
7772
7773         case KEY_until:
7774             pl_yylval.ival = CopLINE(PL_curcop);
7775             OPERATOR(UNTIL);
7776
7777         case KEY_unless:
7778             pl_yylval.ival = CopLINE(PL_curcop);
7779             OPERATOR(UNLESS);
7780
7781         case KEY_unlink:
7782             LOP(OP_UNLINK,XTERM);
7783
7784         case KEY_undef:
7785             UNIDOR(OP_UNDEF);
7786
7787         case KEY_unpack:
7788             LOP(OP_UNPACK,XTERM);
7789
7790         case KEY_utime:
7791             LOP(OP_UTIME,XTERM);
7792
7793         case KEY_umask:
7794             UNIDOR(OP_UMASK);
7795
7796         case KEY_unshift:
7797             LOP(OP_UNSHIFT,XTERM);
7798
7799         case KEY_use:
7800             s = tokenize_use(1, s);
7801             OPERATOR(USE);
7802
7803         case KEY_values:
7804             UNI(OP_VALUES);
7805
7806         case KEY_vec:
7807             LOP(OP_VEC,XTERM);
7808
7809         case KEY_when:
7810             pl_yylval.ival = CopLINE(PL_curcop);
7811             OPERATOR(WHEN);
7812
7813         case KEY_while:
7814             pl_yylval.ival = CopLINE(PL_curcop);
7815             OPERATOR(WHILE);
7816
7817         case KEY_warn:
7818             PL_hints |= HINT_BLOCK_SCOPE;
7819             LOP(OP_WARN,XTERM);
7820
7821         case KEY_wait:
7822             FUN0(OP_WAIT);
7823
7824         case KEY_waitpid:
7825             LOP(OP_WAITPID,XTERM);
7826
7827         case KEY_wantarray:
7828             FUN0(OP_WANTARRAY);
7829
7830         case KEY_write:
7831 #ifdef EBCDIC
7832         {
7833             char ctl_l[2];
7834             ctl_l[0] = toCTRL('L');
7835             ctl_l[1] = '\0';
7836             gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
7837         }
7838 #else
7839             /* Make sure $^L is defined */
7840             gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
7841 #endif
7842             UNI(OP_ENTERWRITE);
7843
7844         case KEY_x:
7845             if (PL_expect == XOPERATOR)
7846                 Mop(OP_REPEAT);
7847             check_uni();
7848             goto just_a_word;
7849
7850         case KEY_xor:
7851             pl_yylval.ival = OP_XOR;
7852             OPERATOR(OROP);
7853
7854         case KEY_y:
7855             s = scan_trans(s);
7856             TERM(sublex_start());
7857         }
7858     }}
7859 }
7860 #ifdef __SC__
7861 #pragma segment Main
7862 #endif
7863
7864 static int
7865 S_pending_ident(pTHX)
7866 {
7867     dVAR;
7868     register char *d;
7869     PADOFFSET tmp = 0;
7870     /* pit holds the identifier we read and pending_ident is reset */
7871     char pit = PL_pending_ident;
7872     const STRLEN tokenbuf_len = strlen(PL_tokenbuf);
7873     /* All routes through this function want to know if there is a colon.  */
7874     const char *const has_colon = (const char*) memchr (PL_tokenbuf, ':', tokenbuf_len);
7875     PL_pending_ident = 0;
7876
7877     /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
7878     DEBUG_T({ PerlIO_printf(Perl_debug_log,
7879           "### Pending identifier '%s'\n", PL_tokenbuf); });
7880
7881     /* if we're in a my(), we can't allow dynamics here.
7882        $foo'bar has already been turned into $foo::bar, so
7883        just check for colons.
7884
7885        if it's a legal name, the OP is a PADANY.
7886     */
7887     if (PL_in_my) {
7888         if (PL_in_my == KEY_our) {      /* "our" is merely analogous to "my" */
7889             if (has_colon)
7890                 yyerror(Perl_form(aTHX_ "No package name allowed for "
7891                                   "variable %s in \"our\"",
7892                                   PL_tokenbuf));
7893             tmp = allocmy(PL_tokenbuf, tokenbuf_len, 0);
7894         }
7895         else {
7896             if (has_colon)
7897                 yyerror(Perl_form(aTHX_ PL_no_myglob,
7898                             PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
7899
7900             pl_yylval.opval = newOP(OP_PADANY, 0);
7901             pl_yylval.opval->op_targ = allocmy(PL_tokenbuf, tokenbuf_len, 0);
7902             return PRIVATEREF;
7903         }
7904     }
7905
7906     /*
7907        build the ops for accesses to a my() variable.
7908
7909        Deny my($a) or my($b) in a sort block, *if* $a or $b is
7910        then used in a comparison.  This catches most, but not
7911        all cases.  For instance, it catches
7912            sort { my($a); $a <=> $b }
7913        but not
7914            sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
7915        (although why you'd do that is anyone's guess).
7916     */
7917
7918     if (!has_colon) {
7919         if (!PL_in_my)
7920             tmp = pad_findmy(PL_tokenbuf, tokenbuf_len, 0);
7921         if (tmp != NOT_IN_PAD) {
7922             /* might be an "our" variable" */
7923             if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
7924                 /* build ops for a bareword */
7925                 HV *  const stash = PAD_COMPNAME_OURSTASH(tmp);
7926                 HEK * const stashname = HvNAME_HEK(stash);
7927                 SV *  const sym = newSVhek(stashname);
7928                 sv_catpvs(sym, "::");
7929                 sv_catpvn(sym, PL_tokenbuf+1, tokenbuf_len - 1);
7930                 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
7931                 pl_yylval.opval->op_private = OPpCONST_ENTERED;
7932                 gv_fetchsv(sym,
7933                     (PL_in_eval
7934                         ? (GV_ADDMULTI | GV_ADDINEVAL)
7935                         : GV_ADDMULTI
7936                     ),
7937                     ((PL_tokenbuf[0] == '$') ? SVt_PV
7938                      : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7939                      : SVt_PVHV));
7940                 return WORD;
7941             }
7942
7943             /* if it's a sort block and they're naming $a or $b */
7944             if (PL_last_lop_op == OP_SORT &&
7945                 PL_tokenbuf[0] == '$' &&
7946                 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
7947                 && !PL_tokenbuf[2])
7948             {
7949                 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
7950                      d < PL_bufend && *d != '\n';
7951                      d++)
7952                 {
7953                     if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
7954                         Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
7955                               PL_tokenbuf);
7956                     }
7957                 }
7958             }
7959
7960             pl_yylval.opval = newOP(OP_PADANY, 0);
7961             pl_yylval.opval->op_targ = tmp;
7962             return PRIVATEREF;
7963         }
7964     }
7965
7966     /*
7967        Whine if they've said @foo in a doublequoted string,
7968        and @foo isn't a variable we can find in the symbol
7969        table.
7970     */
7971     if (ckWARN(WARN_AMBIGUOUS) &&
7972         pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
7973         GV *const gv = gv_fetchpvn_flags(PL_tokenbuf + 1, tokenbuf_len - 1, 0,
7974                                          SVt_PVAV);
7975         if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
7976                 /* DO NOT warn for @- and @+ */
7977                 && !( PL_tokenbuf[2] == '\0' &&
7978                     ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
7979            )
7980         {
7981             /* Downgraded from fatal to warning 20000522 mjd */
7982             Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
7983                         "Possible unintended interpolation of %s in string",
7984                         PL_tokenbuf);
7985         }
7986     }
7987
7988     /* build ops for a bareword */
7989     pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpvn(PL_tokenbuf + 1,
7990                                                       tokenbuf_len - 1));
7991     pl_yylval.opval->op_private = OPpCONST_ENTERED;
7992     gv_fetchpvn_flags(
7993             PL_tokenbuf + 1, tokenbuf_len - 1,
7994             /* If the identifier refers to a stash, don't autovivify it.
7995              * Change 24660 had the side effect of causing symbol table
7996              * hashes to always be defined, even if they were freshly
7997              * created and the only reference in the entire program was
7998              * the single statement with the defined %foo::bar:: test.
7999              * It appears that all code in the wild doing this actually
8000              * wants to know whether sub-packages have been loaded, so
8001              * by avoiding auto-vivifying symbol tables, we ensure that
8002              * defined %foo::bar:: continues to be false, and the existing
8003              * tests still give the expected answers, even though what
8004              * they're actually testing has now changed subtly.
8005              */
8006             (*PL_tokenbuf == '%'
8007              && *(d = PL_tokenbuf + tokenbuf_len - 1) == ':'
8008              && d[-1] == ':'
8009              ? 0
8010              : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
8011             ((PL_tokenbuf[0] == '$') ? SVt_PV
8012              : (PL_tokenbuf[0] == '@') ? SVt_PVAV
8013              : SVt_PVHV));
8014     return WORD;
8015 }
8016
8017 /*
8018  *  The following code was generated by perl_keyword.pl.
8019  */
8020
8021 I32
8022 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
8023 {
8024     dVAR;
8025
8026     PERL_ARGS_ASSERT_KEYWORD;
8027
8028   switch (len)
8029   {
8030     case 1: /* 5 tokens of length 1 */
8031       switch (name[0])
8032       {
8033         case 'm':
8034           {                                       /* m          */
8035             return KEY_m;
8036           }
8037
8038         case 'q':
8039           {                                       /* q          */
8040             return KEY_q;
8041           }
8042
8043         case 's':
8044           {                                       /* s          */
8045             return KEY_s;
8046           }
8047
8048         case 'x':
8049           {                                       /* x          */
8050             return -KEY_x;
8051           }
8052
8053         case 'y':
8054           {                                       /* y          */
8055             return KEY_y;
8056           }
8057
8058         default:
8059           goto unknown;
8060       }
8061
8062     case 2: /* 18 tokens of length 2 */
8063       switch (name[0])
8064       {
8065         case 'd':
8066           if (name[1] == 'o')
8067           {                                       /* do         */
8068             return KEY_do;
8069           }
8070
8071           goto unknown;
8072
8073         case 'e':
8074           if (name[1] == 'q')
8075           {                                       /* eq         */
8076             return -KEY_eq;
8077           }
8078
8079           goto unknown;
8080
8081         case 'g':
8082           switch (name[1])
8083           {
8084             case 'e':
8085               {                                   /* ge         */
8086                 return -KEY_ge;
8087               }
8088
8089             case 't':
8090               {                                   /* gt         */
8091                 return -KEY_gt;
8092               }
8093
8094             default:
8095               goto unknown;
8096           }
8097
8098         case 'i':
8099           if (name[1] == 'f')
8100           {                                       /* if         */
8101             return KEY_if;
8102           }
8103
8104           goto unknown;
8105
8106         case 'l':
8107           switch (name[1])
8108           {
8109             case 'c':
8110               {                                   /* lc         */
8111                 return -KEY_lc;
8112               }
8113
8114             case 'e':
8115               {                                   /* le         */
8116                 return -KEY_le;
8117               }
8118
8119             case 't':
8120               {                                   /* lt         */
8121                 return -KEY_lt;
8122               }
8123
8124             default:
8125               goto unknown;
8126           }
8127
8128         case 'm':
8129           if (name[1] == 'y')
8130           {                                       /* my         */
8131             return KEY_my;
8132           }
8133
8134           goto unknown;
8135
8136         case 'n':
8137           switch (name[1])
8138           {
8139             case 'e':
8140               {                                   /* ne         */
8141                 return -KEY_ne;
8142               }
8143
8144             case 'o':
8145               {                                   /* no         */
8146                 return KEY_no;
8147               }
8148
8149             default:
8150               goto unknown;
8151           }
8152
8153         case 'o':
8154           if (name[1] == 'r')
8155           {                                       /* or         */
8156             return -KEY_or;
8157           }
8158
8159           goto unknown;
8160
8161         case 'q':
8162           switch (name[1])
8163           {
8164             case 'q':
8165               {                                   /* qq         */
8166                 return KEY_qq;
8167               }
8168
8169             case 'r':
8170               {                                   /* qr         */
8171                 return KEY_qr;
8172               }
8173
8174             case 'w':
8175               {                                   /* qw         */
8176                 return KEY_qw;
8177               }
8178
8179             case 'x':
8180               {                                   /* qx         */
8181                 return KEY_qx;
8182               }
8183
8184             default:
8185               goto unknown;
8186           }
8187
8188         case 't':
8189           if (name[1] == 'r')
8190           {                                       /* tr         */
8191             return KEY_tr;
8192           }
8193
8194           goto unknown;
8195
8196         case 'u':
8197           if (name[1] == 'c')
8198           {                                       /* uc         */
8199             return -KEY_uc;
8200           }
8201
8202           goto unknown;
8203
8204         default:
8205           goto unknown;
8206       }
8207
8208     case 3: /* 29 tokens of length 3 */
8209       switch (name[0])
8210       {
8211         case 'E':
8212           if (name[1] == 'N' &&
8213               name[2] == 'D')
8214           {                                       /* END        */
8215             return KEY_END;
8216           }
8217
8218           goto unknown;
8219
8220         case 'a':
8221           switch (name[1])
8222           {
8223             case 'b':
8224               if (name[2] == 's')
8225               {                                   /* abs        */
8226                 return -KEY_abs;
8227               }
8228
8229               goto unknown;
8230
8231             case 'n':
8232               if (name[2] == 'd')
8233               {                                   /* and        */
8234                 return -KEY_and;
8235               }
8236
8237               goto unknown;
8238
8239             default:
8240               goto unknown;
8241           }
8242
8243         case 'c':
8244           switch (name[1])
8245           {
8246             case 'h':
8247               if (name[2] == 'r')
8248               {                                   /* chr        */
8249                 return -KEY_chr;
8250               }
8251
8252               goto unknown;
8253
8254             case 'm':
8255               if (name[2] == 'p')
8256               {                                   /* cmp        */
8257                 return -KEY_cmp;
8258               }
8259
8260               goto unknown;
8261
8262             case 'o':
8263               if (name[2] == 's')
8264               {                                   /* cos        */
8265                 return -KEY_cos;
8266               }
8267
8268               goto unknown;
8269
8270             default:
8271               goto unknown;
8272           }
8273
8274         case 'd':
8275           if (name[1] == 'i' &&
8276               name[2] == 'e')
8277           {                                       /* die        */
8278             return -KEY_die;
8279           }
8280
8281           goto unknown;
8282
8283         case 'e':
8284           switch (name[1])
8285           {
8286             case 'o':
8287               if (name[2] == 'f')
8288               {                                   /* eof        */
8289                 return -KEY_eof;
8290               }
8291
8292               goto unknown;
8293
8294             case 'x':
8295               if (name[2] == 'p')
8296               {                                   /* exp        */
8297                 return -KEY_exp;
8298               }
8299
8300               goto unknown;
8301
8302             default:
8303               goto unknown;
8304           }
8305
8306         case 'f':
8307           if (name[1] == 'o' &&
8308               name[2] == 'r')
8309           {                                       /* for        */
8310             return KEY_for;
8311           }
8312
8313           goto unknown;
8314
8315         case 'h':
8316           if (name[1] == 'e' &&
8317               name[2] == 'x')
8318           {                                       /* hex        */
8319             return -KEY_hex;
8320           }
8321
8322           goto unknown;
8323
8324         case 'i':
8325           if (name[1] == 'n' &&
8326               name[2] == 't')
8327           {                                       /* int        */
8328             return -KEY_int;
8329           }
8330
8331           goto unknown;
8332
8333         case 'l':
8334           if (name[1] == 'o' &&
8335               name[2] == 'g')
8336           {                                       /* log        */
8337             return -KEY_log;
8338           }
8339
8340           goto unknown;
8341
8342         case 'm':
8343           if (name[1] == 'a' &&
8344               name[2] == 'p')
8345           {                                       /* map        */
8346             return KEY_map;
8347           }
8348
8349           goto unknown;
8350
8351         case 'n':
8352           if (name[1] == 'o' &&
8353               name[2] == 't')
8354           {                                       /* not        */
8355             return -KEY_not;
8356           }
8357
8358           goto unknown;
8359
8360         case 'o':
8361           switch (name[1])
8362           {
8363             case 'c':
8364               if (name[2] == 't')
8365               {                                   /* oct        */
8366                 return -KEY_oct;
8367               }
8368
8369               goto unknown;
8370
8371             case 'r':
8372               if (name[2] == 'd')
8373               {                                   /* ord        */
8374                 return -KEY_ord;
8375               }
8376
8377               goto unknown;
8378
8379             case 'u':
8380               if (name[2] == 'r')
8381               {                                   /* our        */
8382                 return KEY_our;
8383               }
8384
8385               goto unknown;
8386
8387             default:
8388               goto unknown;
8389           }
8390
8391         case 'p':
8392           if (name[1] == 'o')
8393           {
8394             switch (name[2])
8395             {
8396               case 'p':
8397                 {                                 /* pop        */
8398                   return -KEY_pop;
8399                 }
8400
8401               case 's':
8402                 {                                 /* pos        */
8403                   return KEY_pos;
8404                 }
8405
8406               default:
8407                 goto unknown;
8408             }
8409           }
8410
8411           goto unknown;
8412
8413         case 'r':
8414           if (name[1] == 'e' &&
8415               name[2] == 'f')
8416           {                                       /* ref        */
8417             return -KEY_ref;
8418           }
8419
8420           goto unknown;
8421
8422         case 's':
8423           switch (name[1])
8424           {
8425             case 'a':
8426               if (name[2] == 'y')
8427               {                                   /* say        */
8428                 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
8429               }
8430
8431               goto unknown;
8432
8433             case 'i':
8434               if (name[2] == 'n')
8435               {                                   /* sin        */
8436                 return -KEY_sin;
8437               }
8438
8439               goto unknown;
8440
8441             case 'u':
8442               if (name[2] == 'b')
8443               {                                   /* sub        */
8444                 return KEY_sub;
8445               }
8446
8447               goto unknown;
8448
8449             default:
8450               goto unknown;
8451           }
8452
8453         case 't':
8454           if (name[1] == 'i' &&
8455               name[2] == 'e')
8456           {                                       /* tie        */
8457             return KEY_tie;
8458           }
8459
8460           goto unknown;
8461
8462         case 'u':
8463           if (name[1] == 's' &&
8464               name[2] == 'e')
8465           {                                       /* use        */
8466             return KEY_use;
8467           }
8468
8469           goto unknown;
8470
8471         case 'v':
8472           if (name[1] == 'e' &&
8473               name[2] == 'c')
8474           {                                       /* vec        */
8475             return -KEY_vec;
8476           }
8477
8478           goto unknown;
8479
8480         case 'x':
8481           if (name[1] == 'o' &&
8482               name[2] == 'r')
8483           {                                       /* xor        */
8484             return -KEY_xor;
8485           }
8486
8487           goto unknown;
8488
8489         default:
8490           goto unknown;
8491       }
8492
8493     case 4: /* 41 tokens of length 4 */
8494       switch (name[0])
8495       {
8496         case 'C':
8497           if (name[1] == 'O' &&
8498               name[2] == 'R' &&
8499               name[3] == 'E')
8500           {                                       /* CORE       */
8501             return -KEY_CORE;
8502           }
8503
8504           goto unknown;
8505
8506         case 'I':
8507           if (name[1] == 'N' &&
8508               name[2] == 'I' &&
8509               name[3] == 'T')
8510           {                                       /* INIT       */
8511             return KEY_INIT;
8512           }
8513
8514           goto unknown;
8515
8516         case 'b':
8517           if (name[1] == 'i' &&
8518               name[2] == 'n' &&
8519               name[3] == 'd')
8520           {                                       /* bind       */
8521             return -KEY_bind;
8522           }
8523
8524           goto unknown;
8525
8526         case 'c':
8527           if (name[1] == 'h' &&
8528               name[2] == 'o' &&
8529               name[3] == 'p')
8530           {                                       /* chop       */
8531             return -KEY_chop;
8532           }
8533
8534           goto unknown;
8535
8536         case 'd':
8537           if (name[1] == 'u' &&
8538               name[2] == 'm' &&
8539               name[3] == 'p')
8540           {                                       /* dump       */
8541             return -KEY_dump;
8542           }
8543
8544           goto unknown;
8545
8546         case 'e':
8547           switch (name[1])
8548           {
8549             case 'a':
8550               if (name[2] == 'c' &&
8551                   name[3] == 'h')
8552               {                                   /* each       */
8553                 return -KEY_each;
8554               }
8555
8556               goto unknown;
8557
8558             case 'l':
8559               if (name[2] == 's' &&
8560                   name[3] == 'e')
8561               {                                   /* else       */
8562                 return KEY_else;
8563               }
8564
8565               goto unknown;
8566
8567             case 'v':
8568               if (name[2] == 'a' &&
8569                   name[3] == 'l')
8570               {                                   /* eval       */
8571                 return KEY_eval;
8572               }
8573
8574               goto unknown;
8575
8576             case 'x':
8577               switch (name[2])
8578               {
8579                 case 'e':
8580                   if (name[3] == 'c')
8581                   {                               /* exec       */
8582                     return -KEY_exec;
8583                   }
8584
8585                   goto unknown;
8586
8587                 case 'i':
8588                   if (name[3] == 't')
8589                   {                               /* exit       */
8590                     return -KEY_exit;
8591                   }
8592
8593                   goto unknown;
8594
8595                 default:
8596                   goto unknown;
8597               }
8598
8599             default:
8600               goto unknown;
8601           }
8602
8603         case 'f':
8604           if (name[1] == 'o' &&
8605               name[2] == 'r' &&
8606               name[3] == 'k')
8607           {                                       /* fork       */
8608             return -KEY_fork;
8609           }
8610
8611           goto unknown;
8612
8613         case 'g':
8614           switch (name[1])
8615           {
8616             case 'e':
8617               if (name[2] == 't' &&
8618                   name[3] == 'c')
8619               {                                   /* getc       */
8620                 return -KEY_getc;
8621               }
8622
8623               goto unknown;
8624
8625             case 'l':
8626               if (name[2] == 'o' &&
8627                   name[3] == 'b')
8628               {                                   /* glob       */
8629                 return KEY_glob;
8630               }
8631
8632               goto unknown;
8633
8634             case 'o':
8635               if (name[2] == 't' &&
8636                   name[3] == 'o')
8637               {                                   /* goto       */
8638                 return KEY_goto;
8639               }
8640
8641               goto unknown;
8642
8643             case 'r':
8644               if (name[2] == 'e' &&
8645                   name[3] == 'p')
8646               {                                   /* grep       */
8647                 return KEY_grep;
8648               }
8649
8650               goto unknown;
8651
8652             default:
8653               goto unknown;
8654           }
8655
8656         case 'j':
8657           if (name[1] == 'o' &&
8658               name[2] == 'i' &&
8659               name[3] == 'n')
8660           {                                       /* join       */
8661             return -KEY_join;
8662           }
8663
8664           goto unknown;
8665
8666         case 'k':
8667           switch (name[1])
8668           {
8669             case 'e':
8670               if (name[2] == 'y' &&
8671                   name[3] == 's')
8672               {                                   /* keys       */
8673                 return -KEY_keys;
8674               }
8675
8676               goto unknown;
8677
8678             case 'i':
8679               if (name[2] == 'l' &&
8680                   name[3] == 'l')
8681               {                                   /* kill       */
8682                 return -KEY_kill;
8683               }
8684
8685               goto unknown;
8686
8687             default:
8688               goto unknown;
8689           }
8690
8691         case 'l':
8692           switch (name[1])
8693           {
8694             case 'a':
8695               if (name[2] == 's' &&
8696                   name[3] == 't')
8697               {                                   /* last       */
8698                 return KEY_last;
8699               }
8700
8701               goto unknown;
8702
8703             case 'i':
8704               if (name[2] == 'n' &&
8705                   name[3] == 'k')
8706               {                                   /* link       */
8707                 return -KEY_link;
8708               }
8709
8710               goto unknown;
8711
8712             case 'o':
8713               if (name[2] == 'c' &&
8714                   name[3] == 'k')
8715               {                                   /* lock       */
8716                 return -KEY_lock;
8717               }
8718
8719               goto unknown;
8720
8721             default:
8722               goto unknown;
8723           }
8724
8725         case 'n':
8726           if (name[1] == 'e' &&
8727               name[2] == 'x' &&
8728               name[3] == 't')
8729           {                                       /* next       */
8730             return KEY_next;
8731           }
8732
8733           goto unknown;
8734
8735         case 'o':
8736           if (name[1] == 'p' &&
8737               name[2] == 'e' &&
8738               name[3] == 'n')
8739           {                                       /* open       */
8740             return -KEY_open;
8741           }
8742
8743           goto unknown;
8744
8745         case 'p':
8746           switch (name[1])
8747           {
8748             case 'a':
8749               if (name[2] == 'c' &&
8750                   name[3] == 'k')
8751               {                                   /* pack       */
8752                 return -KEY_pack;
8753               }
8754
8755               goto unknown;
8756
8757             case 'i':
8758               if (name[2] == 'p' &&
8759                   name[3] == 'e')
8760               {                                   /* pipe       */
8761                 return -KEY_pipe;
8762               }
8763
8764               goto unknown;
8765
8766             case 'u':
8767               if (name[2] == 's' &&
8768                   name[3] == 'h')
8769               {                                   /* push       */
8770                 return -KEY_push;
8771               }
8772
8773               goto unknown;
8774
8775             default:
8776               goto unknown;
8777           }
8778
8779         case 'r':
8780           switch (name[1])
8781           {
8782             case 'a':
8783               if (name[2] == 'n' &&
8784                   name[3] == 'd')
8785               {                                   /* rand       */
8786                 return -KEY_rand;
8787               }
8788
8789               goto unknown;
8790
8791             case 'e':
8792               switch (name[2])
8793               {
8794                 case 'a':
8795                   if (name[3] == 'd')
8796                   {                               /* read       */
8797                     return -KEY_read;
8798                   }
8799
8800                   goto unknown;
8801
8802                 case 'c':
8803                   if (name[3] == 'v')
8804                   {                               /* recv       */
8805                     return -KEY_recv;
8806                   }
8807
8808                   goto unknown;
8809
8810                 case 'd':
8811                   if (name[3] == 'o')
8812                   {                               /* redo       */
8813                     return KEY_redo;
8814                   }
8815
8816                   goto unknown;
8817
8818                 default:
8819                   goto unknown;
8820               }
8821
8822             default:
8823               goto unknown;
8824           }
8825
8826         case 's':
8827           switch (name[1])
8828           {
8829             case 'e':
8830               switch (name[2])
8831               {
8832                 case 'e':
8833                   if (name[3] == 'k')
8834                   {                               /* seek       */
8835                     return -KEY_seek;
8836                   }
8837
8838                   goto unknown;
8839
8840                 case 'n':
8841                   if (name[3] == 'd')
8842                   {                               /* send       */
8843                     return -KEY_send;
8844                   }
8845
8846                   goto unknown;
8847
8848                 default:
8849                   goto unknown;
8850               }
8851
8852             case 'o':
8853               if (name[2] == 'r' &&
8854                   name[3] == 't')
8855               {                                   /* sort       */
8856                 return KEY_sort;
8857               }
8858
8859               goto unknown;
8860
8861             case 'q':
8862               if (name[2] == 'r' &&
8863                   name[3] == 't')
8864               {                                   /* sqrt       */
8865                 return -KEY_sqrt;
8866               }
8867
8868               goto unknown;
8869
8870             case 't':
8871               if (name[2] == 'a' &&
8872                   name[3] == 't')
8873               {                                   /* stat       */
8874                 return -KEY_stat;
8875               }
8876
8877               goto unknown;
8878
8879             default:
8880               goto unknown;
8881           }
8882
8883         case 't':
8884           switch (name[1])
8885           {
8886             case 'e':
8887               if (name[2] == 'l' &&
8888                   name[3] == 'l')
8889               {                                   /* tell       */
8890                 return -KEY_tell;
8891               }
8892
8893               goto unknown;
8894
8895             case 'i':
8896               switch (name[2])
8897               {
8898                 case 'e':
8899                   if (name[3] == 'd')
8900                   {                               /* tied       */
8901                     return KEY_tied;
8902                   }
8903
8904                   goto unknown;
8905
8906                 case 'm':
8907                   if (name[3] == 'e')
8908                   {                               /* time       */
8909                     return -KEY_time;
8910                   }
8911
8912                   goto unknown;
8913
8914                 default:
8915                   goto unknown;
8916               }
8917
8918             default:
8919               goto unknown;
8920           }
8921
8922         case 'w':
8923           switch (name[1])
8924           {
8925             case 'a':
8926               switch (name[2])
8927               {
8928                 case 'i':
8929                   if (name[3] == 't')
8930                   {                               /* wait       */
8931                     return -KEY_wait;
8932                   }
8933
8934                   goto unknown;
8935
8936                 case 'r':
8937                   if (name[3] == 'n')
8938                   {                               /* warn       */
8939                     return -KEY_warn;
8940                   }
8941
8942                   goto unknown;
8943
8944                 default:
8945                   goto unknown;
8946               }
8947
8948             case 'h':
8949               if (name[2] == 'e' &&
8950                   name[3] == 'n')
8951               {                                   /* when       */
8952                 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
8953               }
8954
8955               goto unknown;
8956
8957             default:
8958               goto unknown;
8959           }
8960
8961         default:
8962           goto unknown;
8963       }
8964
8965     case 5: /* 39 tokens of length 5 */
8966       switch (name[0])
8967       {
8968         case 'B':
8969           if (name[1] == 'E' &&
8970               name[2] == 'G' &&
8971               name[3] == 'I' &&
8972               name[4] == 'N')
8973           {                                       /* BEGIN      */
8974             return KEY_BEGIN;
8975           }
8976
8977           goto unknown;
8978
8979         case 'C':
8980           if (name[1] == 'H' &&
8981               name[2] == 'E' &&
8982               name[3] == 'C' &&
8983               name[4] == 'K')
8984           {                                       /* CHECK      */
8985             return KEY_CHECK;
8986           }
8987
8988           goto unknown;
8989
8990         case 'a':
8991           switch (name[1])
8992           {
8993             case 'l':
8994               if (name[2] == 'a' &&
8995                   name[3] == 'r' &&
8996                   name[4] == 'm')
8997               {                                   /* alarm      */
8998                 return -KEY_alarm;
8999               }
9000
9001               goto unknown;
9002
9003             case 't':
9004               if (name[2] == 'a' &&
9005                   name[3] == 'n' &&
9006                   name[4] == '2')
9007               {                                   /* atan2      */
9008                 return -KEY_atan2;
9009               }
9010
9011               goto unknown;
9012
9013             default:
9014               goto unknown;
9015           }
9016
9017         case 'b':
9018           switch (name[1])
9019           {
9020             case 'l':
9021               if (name[2] == 'e' &&
9022                   name[3] == 's' &&
9023                   name[4] == 's')
9024               {                                   /* bless      */
9025                 return -KEY_bless;
9026               }
9027
9028               goto unknown;
9029
9030             case 'r':
9031               if (name[2] == 'e' &&
9032                   name[3] == 'a' &&
9033                   name[4] == 'k')
9034               {                                   /* break      */
9035                 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
9036               }
9037
9038               goto unknown;
9039
9040             default:
9041               goto unknown;
9042           }
9043
9044         case 'c':
9045           switch (name[1])
9046           {
9047             case 'h':
9048               switch (name[2])
9049               {
9050                 case 'd':
9051                   if (name[3] == 'i' &&
9052                       name[4] == 'r')
9053                   {                               /* chdir      */
9054                     return -KEY_chdir;
9055                   }
9056
9057                   goto unknown;
9058
9059                 case 'm':
9060                   if (name[3] == 'o' &&
9061                       name[4] == 'd')
9062                   {                               /* chmod      */
9063                     return -KEY_chmod;
9064                   }
9065
9066                   goto unknown;
9067
9068                 case 'o':
9069                   switch (name[3])
9070                   {
9071                     case 'm':
9072                       if (name[4] == 'p')
9073                       {                           /* chomp      */
9074                         return -KEY_chomp;
9075                       }
9076
9077                       goto unknown;
9078
9079                     case 'w':
9080                       if (name[4] == 'n')
9081                       {                           /* chown      */
9082                         return -KEY_chown;
9083                       }
9084
9085                       goto unknown;
9086
9087                     default:
9088                       goto unknown;
9089                   }
9090
9091                 default:
9092                   goto unknown;
9093               }
9094
9095             case 'l':
9096               if (name[2] == 'o' &&
9097                   name[3] == 's' &&
9098                   name[4] == 'e')
9099               {                                   /* close      */
9100                 return -KEY_close;
9101               }
9102
9103               goto unknown;
9104
9105             case 'r':
9106               if (name[2] == 'y' &&
9107                   name[3] == 'p' &&
9108                   name[4] == 't')
9109               {                                   /* crypt      */
9110                 return -KEY_crypt;
9111               }
9112
9113               goto unknown;
9114
9115             default:
9116               goto unknown;
9117           }
9118
9119         case 'e':
9120           if (name[1] == 'l' &&
9121               name[2] == 's' &&
9122               name[3] == 'i' &&
9123               name[4] == 'f')
9124           {                                       /* elsif      */
9125             return KEY_elsif;
9126           }
9127
9128           goto unknown;
9129
9130         case 'f':
9131           switch (name[1])
9132           {
9133             case 'c':
9134               if (name[2] == 'n' &&
9135                   name[3] == 't' &&
9136                   name[4] == 'l')
9137               {                                   /* fcntl      */
9138                 return -KEY_fcntl;
9139               }
9140
9141               goto unknown;
9142
9143             case 'l':
9144               if (name[2] == 'o' &&
9145                   name[3] == 'c' &&
9146                   name[4] == 'k')
9147               {                                   /* flock      */
9148                 return -KEY_flock;
9149               }
9150
9151               goto unknown;
9152
9153             default:
9154               goto unknown;
9155           }
9156
9157         case 'g':
9158           if (name[1] == 'i' &&
9159               name[2] == 'v' &&
9160               name[3] == 'e' &&
9161               name[4] == 'n')
9162           {                                       /* given      */
9163             return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
9164           }
9165
9166           goto unknown;
9167
9168         case 'i':
9169           switch (name[1])
9170           {
9171             case 'n':
9172               if (name[2] == 'd' &&
9173                   name[3] == 'e' &&
9174                   name[4] == 'x')
9175               {                                   /* index      */
9176                 return -KEY_index;
9177               }
9178
9179               goto unknown;
9180
9181             case 'o':
9182               if (name[2] == 'c' &&
9183                   name[3] == 't' &&
9184                   name[4] == 'l')
9185               {                                   /* ioctl      */
9186                 return -KEY_ioctl;
9187               }
9188
9189               goto unknown;
9190
9191             default:
9192               goto unknown;
9193           }
9194
9195         case 'l':
9196           switch (name[1])
9197           {
9198             case 'o':
9199               if (name[2] == 'c' &&
9200                   name[3] == 'a' &&
9201                   name[4] == 'l')
9202               {                                   /* local      */
9203                 return KEY_local;
9204               }
9205
9206               goto unknown;
9207
9208             case 's':
9209               if (name[2] == 't' &&
9210                   name[3] == 'a' &&
9211                   name[4] == 't')
9212               {                                   /* lstat      */
9213                 return -KEY_lstat;
9214               }
9215
9216               goto unknown;
9217
9218             default:
9219               goto unknown;
9220           }
9221
9222         case 'm':
9223           if (name[1] == 'k' &&
9224               name[2] == 'd' &&
9225               name[3] == 'i' &&
9226               name[4] == 'r')
9227           {                                       /* mkdir      */
9228             return -KEY_mkdir;
9229           }
9230
9231           goto unknown;
9232
9233         case 'p':
9234           if (name[1] == 'r' &&
9235               name[2] == 'i' &&
9236               name[3] == 'n' &&
9237               name[4] == 't')
9238           {                                       /* print      */
9239             return KEY_print;
9240           }
9241
9242           goto unknown;
9243
9244         case 'r':
9245           switch (name[1])
9246           {
9247             case 'e':
9248               if (name[2] == 's' &&
9249                   name[3] == 'e' &&
9250                   name[4] == 't')
9251               {                                   /* reset      */
9252                 return -KEY_reset;
9253               }
9254
9255               goto unknown;
9256
9257             case 'm':
9258               if (name[2] == 'd' &&
9259                   name[3] == 'i' &&
9260                   name[4] == 'r')
9261               {                                   /* rmdir      */
9262                 return -KEY_rmdir;
9263               }
9264
9265               goto unknown;
9266
9267             default:
9268               goto unknown;
9269           }
9270
9271         case 's':
9272           switch (name[1])
9273           {
9274             case 'e':
9275               if (name[2] == 'm' &&
9276                   name[3] == 'o' &&
9277                   name[4] == 'p')
9278               {                                   /* semop      */
9279                 return -KEY_semop;
9280               }
9281
9282               goto unknown;
9283
9284             case 'h':
9285               if (name[2] == 'i' &&
9286                   name[3] == 'f' &&
9287                   name[4] == 't')
9288               {                                   /* shift      */
9289                 return -KEY_shift;
9290               }
9291
9292               goto unknown;
9293
9294             case 'l':
9295               if (name[2] == 'e' &&
9296                   name[3] == 'e' &&
9297                   name[4] == 'p')
9298               {                                   /* sleep      */
9299                 return -KEY_sleep;
9300               }
9301
9302               goto unknown;
9303
9304             case 'p':
9305               if (name[2] == 'l' &&
9306                   name[3] == 'i' &&
9307                   name[4] == 't')
9308               {                                   /* split      */
9309                 return KEY_split;
9310               }
9311
9312               goto unknown;
9313
9314             case 'r':
9315               if (name[2] == 'a' &&
9316                   name[3] == 'n' &&
9317                   name[4] == 'd')
9318               {                                   /* srand      */
9319                 return -KEY_srand;
9320               }
9321
9322               goto unknown;
9323
9324             case 't':
9325               switch (name[2])
9326               {
9327                 case 'a':
9328                   if (name[3] == 't' &&
9329                       name[4] == 'e')
9330                   {                               /* state      */
9331                     return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
9332                   }
9333
9334                   goto unknown;
9335
9336                 case 'u':
9337                   if (name[3] == 'd' &&
9338                       name[4] == 'y')
9339                   {                               /* study      */
9340                     return KEY_study;
9341                   }
9342
9343                   goto unknown;
9344
9345                 default:
9346                   goto unknown;
9347               }
9348
9349             default:
9350               goto unknown;
9351           }
9352
9353         case 't':
9354           if (name[1] == 'i' &&
9355               name[2] == 'm' &&
9356               name[3] == 'e' &&
9357               name[4] == 's')
9358           {                                       /* times      */
9359             return -KEY_times;
9360           }
9361
9362           goto unknown;
9363
9364         case 'u':
9365           switch (name[1])
9366           {
9367             case 'm':
9368               if (name[2] == 'a' &&
9369                   name[3] == 's' &&
9370                   name[4] == 'k')
9371               {                                   /* umask      */
9372                 return -KEY_umask;
9373               }
9374
9375               goto unknown;
9376
9377             case 'n':
9378               switch (name[2])
9379               {
9380                 case 'd':
9381                   if (name[3] == 'e' &&
9382                       name[4] == 'f')
9383                   {                               /* undef      */
9384                     return KEY_undef;
9385                   }
9386
9387                   goto unknown;
9388
9389                 case 't':
9390                   if (name[3] == 'i')
9391                   {
9392                     switch (name[4])
9393                     {
9394                       case 'e':
9395                         {                         /* untie      */
9396                           return KEY_untie;
9397                         }
9398
9399                       case 'l':
9400                         {                         /* until      */
9401                           return KEY_until;
9402                         }
9403
9404                       default:
9405                         goto unknown;
9406                     }
9407                   }
9408
9409                   goto unknown;
9410
9411                 default:
9412                   goto unknown;
9413               }
9414
9415             case 't':
9416               if (name[2] == 'i' &&
9417                   name[3] == 'm' &&
9418                   name[4] == 'e')
9419               {                                   /* utime      */
9420                 return -KEY_utime;
9421               }
9422
9423               goto unknown;
9424
9425             default:
9426               goto unknown;
9427           }
9428
9429         case 'w':
9430           switch (name[1])
9431           {
9432             case 'h':
9433               if (name[2] == 'i' &&
9434                   name[3] == 'l' &&
9435                   name[4] == 'e')
9436               {                                   /* while      */
9437                 return KEY_while;
9438               }
9439
9440               goto unknown;
9441
9442             case 'r':
9443               if (name[2] == 'i' &&
9444                   name[3] == 't' &&
9445                   name[4] == 'e')
9446               {                                   /* write      */
9447                 return -KEY_write;
9448               }
9449
9450               goto unknown;
9451
9452             default:
9453               goto unknown;
9454           }
9455
9456         default:
9457           goto unknown;
9458       }
9459
9460     case 6: /* 33 tokens of length 6 */
9461       switch (name[0])
9462       {
9463         case 'a':
9464           if (name[1] == 'c' &&
9465               name[2] == 'c' &&
9466               name[3] == 'e' &&
9467               name[4] == 'p' &&
9468               name[5] == 't')
9469           {                                       /* accept     */
9470             return -KEY_accept;
9471           }
9472
9473           goto unknown;
9474
9475         case 'c':
9476           switch (name[1])
9477           {
9478             case 'a':
9479               if (name[2] == 'l' &&
9480                   name[3] == 'l' &&
9481                   name[4] == 'e' &&
9482                   name[5] == 'r')
9483               {                                   /* caller     */
9484                 return -KEY_caller;
9485               }
9486
9487               goto unknown;
9488
9489             case 'h':
9490               if (name[2] == 'r' &&
9491                   name[3] == 'o' &&
9492                   name[4] == 'o' &&
9493                   name[5] == 't')
9494               {                                   /* chroot     */
9495                 return -KEY_chroot;
9496               }
9497
9498               goto unknown;
9499
9500             default:
9501               goto unknown;
9502           }
9503
9504         case 'd':
9505           if (name[1] == 'e' &&
9506               name[2] == 'l' &&
9507               name[3] == 'e' &&
9508               name[4] == 't' &&
9509               name[5] == 'e')
9510           {                                       /* delete     */
9511             return KEY_delete;
9512           }
9513
9514           goto unknown;
9515
9516         case 'e':
9517           switch (name[1])
9518           {
9519             case 'l':
9520               if (name[2] == 's' &&
9521                   name[3] == 'e' &&
9522                   name[4] == 'i' &&
9523                   name[5] == 'f')
9524               {                                   /* elseif     */
9525                   Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
9526               }
9527
9528               goto unknown;
9529
9530             case 'x':
9531               if (name[2] == 'i' &&
9532                   name[3] == 's' &&
9533                   name[4] == 't' &&
9534                   name[5] == 's')
9535               {                                   /* exists     */
9536                 return KEY_exists;
9537               }
9538
9539               goto unknown;
9540
9541             default:
9542               goto unknown;
9543           }
9544
9545         case 'f':
9546           switch (name[1])
9547           {
9548             case 'i':
9549               if (name[2] == 'l' &&
9550                   name[3] == 'e' &&
9551                   name[4] == 'n' &&
9552                   name[5] == 'o')
9553               {                                   /* fileno     */
9554                 return -KEY_fileno;
9555               }
9556
9557               goto unknown;
9558
9559             case 'o':
9560               if (name[2] == 'r' &&
9561                   name[3] == 'm' &&
9562                   name[4] == 'a' &&
9563                   name[5] == 't')
9564               {                                   /* format     */
9565                 return KEY_format;
9566               }
9567
9568               goto unknown;
9569
9570             default:
9571               goto unknown;
9572           }
9573
9574         case 'g':
9575           if (name[1] == 'm' &&
9576               name[2] == 't' &&
9577               name[3] == 'i' &&
9578               name[4] == 'm' &&
9579               name[5] == 'e')
9580           {                                       /* gmtime     */
9581             return -KEY_gmtime;
9582           }
9583
9584           goto unknown;
9585
9586         case 'l':
9587           switch (name[1])
9588           {
9589             case 'e':
9590               if (name[2] == 'n' &&
9591                   name[3] == 'g' &&
9592                   name[4] == 't' &&
9593                   name[5] == 'h')
9594               {                                   /* length     */
9595                 return -KEY_length;
9596               }
9597
9598               goto unknown;
9599
9600             case 'i':
9601               if (name[2] == 's' &&
9602                   name[3] == 't' &&
9603                   name[4] == 'e' &&
9604                   name[5] == 'n')
9605               {                                   /* listen     */
9606                 return -KEY_listen;
9607               }
9608
9609               goto unknown;
9610
9611             default:
9612               goto unknown;
9613           }
9614
9615         case 'm':
9616           if (name[1] == 's' &&
9617               name[2] == 'g')
9618           {
9619             switch (name[3])
9620             {
9621               case 'c':
9622                 if (name[4] == 't' &&
9623                     name[5] == 'l')
9624                 {                                 /* msgctl     */
9625                   return -KEY_msgctl;
9626                 }
9627
9628                 goto unknown;
9629
9630               case 'g':
9631                 if (name[4] == 'e' &&
9632                     name[5] == 't')
9633                 {                                 /* msgget     */
9634                   return -KEY_msgget;
9635                 }
9636
9637                 goto unknown;
9638
9639               case 'r':
9640                 if (name[4] == 'c' &&
9641                     name[5] == 'v')
9642                 {                                 /* msgrcv     */
9643                   return -KEY_msgrcv;
9644                 }
9645
9646                 goto unknown;
9647
9648               case 's':
9649                 if (name[4] == 'n' &&
9650                     name[5] == 'd')
9651                 {                                 /* msgsnd     */
9652                   return -KEY_msgsnd;
9653                 }
9654
9655                 goto unknown;
9656
9657               default:
9658                 goto unknown;
9659             }
9660           }
9661
9662           goto unknown;
9663
9664         case 'p':
9665           if (name[1] == 'r' &&
9666               name[2] == 'i' &&
9667               name[3] == 'n' &&
9668               name[4] == 't' &&
9669               name[5] == 'f')
9670           {                                       /* printf     */
9671             return KEY_printf;
9672           }
9673
9674           goto unknown;
9675
9676         case 'r':
9677           switch (name[1])
9678           {
9679             case 'e':
9680               switch (name[2])
9681               {
9682                 case 'n':
9683                   if (name[3] == 'a' &&
9684                       name[4] == 'm' &&
9685                       name[5] == 'e')
9686                   {                               /* rename     */
9687                     return -KEY_rename;
9688                   }
9689
9690                   goto unknown;
9691
9692                 case 't':
9693                   if (name[3] == 'u' &&
9694                       name[4] == 'r' &&
9695                       name[5] == 'n')
9696                   {                               /* return     */
9697                     return KEY_return;
9698                   }
9699
9700                   goto unknown;
9701
9702                 default:
9703                   goto unknown;
9704               }
9705
9706             case 'i':
9707               if (name[2] == 'n' &&
9708                   name[3] == 'd' &&
9709                   name[4] == 'e' &&
9710                   name[5] == 'x')
9711               {                                   /* rindex     */
9712                 return -KEY_rindex;
9713               }
9714
9715               goto unknown;
9716
9717             default:
9718               goto unknown;
9719           }
9720
9721         case 's':
9722           switch (name[1])
9723           {
9724             case 'c':
9725               if (name[2] == 'a' &&
9726                   name[3] == 'l' &&
9727                   name[4] == 'a' &&
9728                   name[5] == 'r')
9729               {                                   /* scalar     */
9730                 return KEY_scalar;
9731               }
9732
9733               goto unknown;
9734
9735             case 'e':
9736               switch (name[2])
9737               {
9738                 case 'l':
9739                   if (name[3] == 'e' &&
9740                       name[4] == 'c' &&
9741                       name[5] == 't')
9742                   {                               /* select     */
9743                     return -KEY_select;
9744                   }
9745
9746                   goto unknown;
9747
9748                 case 'm':
9749                   switch (name[3])
9750                   {
9751                     case 'c':
9752                       if (name[4] == 't' &&
9753                           name[5] == 'l')
9754                       {                           /* semctl     */
9755                         return -KEY_semctl;
9756                       }
9757
9758                       goto unknown;
9759
9760                     case 'g':
9761                       if (name[4] == 'e' &&
9762                           name[5] == 't')
9763                       {                           /* semget     */
9764                         return -KEY_semget;
9765                       }
9766
9767                       goto unknown;
9768
9769                     default:
9770                       goto unknown;
9771                   }
9772
9773                 default:
9774                   goto unknown;
9775               }
9776
9777             case 'h':
9778               if (name[2] == 'm')
9779               {
9780                 switch (name[3])
9781                 {
9782                   case 'c':
9783                     if (name[4] == 't' &&
9784                         name[5] == 'l')
9785                     {                             /* shmctl     */
9786                       return -KEY_shmctl;
9787                     }
9788
9789                     goto unknown;
9790
9791                   case 'g':
9792                     if (name[4] == 'e' &&
9793                         name[5] == 't')
9794                     {                             /* shmget     */
9795                       return -KEY_shmget;
9796                     }
9797
9798                     goto unknown;
9799
9800                   default:
9801                     goto unknown;
9802                 }
9803               }
9804
9805               goto unknown;
9806
9807             case 'o':
9808               if (name[2] == 'c' &&
9809                   name[3] == 'k' &&
9810                   name[4] == 'e' &&
9811                   name[5] == 't')
9812               {                                   /* socket     */
9813                 return -KEY_socket;
9814               }
9815
9816               goto unknown;
9817
9818             case 'p':
9819               if (name[2] == 'l' &&
9820                   name[3] == 'i' &&
9821                   name[4] == 'c' &&
9822                   name[5] == 'e')
9823               {                                   /* splice     */
9824                 return -KEY_splice;
9825               }
9826
9827               goto unknown;
9828
9829             case 'u':
9830               if (name[2] == 'b' &&
9831                   name[3] == 's' &&
9832                   name[4] == 't' &&
9833                   name[5] == 'r')
9834               {                                   /* substr     */
9835                 return -KEY_substr;
9836               }
9837
9838               goto unknown;
9839
9840             case 'y':
9841               if (name[2] == 's' &&
9842                   name[3] == 't' &&
9843                   name[4] == 'e' &&
9844                   name[5] == 'm')
9845               {                                   /* system     */
9846                 return -KEY_system;
9847               }
9848
9849               goto unknown;
9850
9851             default:
9852               goto unknown;
9853           }
9854
9855         case 'u':
9856           if (name[1] == 'n')
9857           {
9858             switch (name[2])
9859             {
9860               case 'l':
9861                 switch (name[3])
9862                 {
9863                   case 'e':
9864                     if (name[4] == 's' &&
9865                         name[5] == 's')
9866                     {                             /* unless     */
9867                       return KEY_unless;
9868                     }
9869
9870                     goto unknown;
9871
9872                   case 'i':
9873                     if (name[4] == 'n' &&
9874                         name[5] == 'k')
9875                     {                             /* unlink     */
9876                       return -KEY_unlink;
9877                     }
9878
9879                     goto unknown;
9880
9881                   default:
9882                     goto unknown;
9883                 }
9884
9885               case 'p':
9886                 if (name[3] == 'a' &&
9887                     name[4] == 'c' &&
9888                     name[5] == 'k')
9889                 {                                 /* unpack     */
9890                   return -KEY_unpack;
9891                 }
9892
9893                 goto unknown;
9894
9895               default:
9896                 goto unknown;
9897             }
9898           }
9899
9900           goto unknown;
9901
9902         case 'v':
9903           if (name[1] == 'a' &&
9904               name[2] == 'l' &&
9905               name[3] == 'u' &&
9906               name[4] == 'e' &&
9907               name[5] == 's')
9908           {                                       /* values     */
9909             return -KEY_values;
9910           }
9911
9912           goto unknown;
9913
9914         default:
9915           goto unknown;
9916       }
9917
9918     case 7: /* 29 tokens of length 7 */
9919       switch (name[0])
9920       {
9921         case 'D':
9922           if (name[1] == 'E' &&
9923               name[2] == 'S' &&
9924               name[3] == 'T' &&
9925               name[4] == 'R' &&
9926               name[5] == 'O' &&
9927               name[6] == 'Y')
9928           {                                       /* DESTROY    */
9929             return KEY_DESTROY;
9930           }
9931
9932           goto unknown;
9933
9934         case '_':
9935           if (name[1] == '_' &&
9936               name[2] == 'E' &&
9937               name[3] == 'N' &&
9938               name[4] == 'D' &&
9939               name[5] == '_' &&
9940               name[6] == '_')
9941           {                                       /* __END__    */
9942             return KEY___END__;
9943           }
9944
9945           goto unknown;
9946
9947         case 'b':
9948           if (name[1] == 'i' &&
9949               name[2] == 'n' &&
9950               name[3] == 'm' &&
9951               name[4] == 'o' &&
9952               name[5] == 'd' &&
9953               name[6] == 'e')
9954           {                                       /* binmode    */
9955             return -KEY_binmode;
9956           }
9957
9958           goto unknown;
9959
9960         case 'c':
9961           if (name[1] == 'o' &&
9962               name[2] == 'n' &&
9963               name[3] == 'n' &&
9964               name[4] == 'e' &&
9965               name[5] == 'c' &&
9966               name[6] == 't')
9967           {                                       /* connect    */
9968             return -KEY_connect;
9969           }
9970
9971           goto unknown;
9972
9973         case 'd':
9974           switch (name[1])
9975           {
9976             case 'b':
9977               if (name[2] == 'm' &&
9978                   name[3] == 'o' &&
9979                   name[4] == 'p' &&
9980                   name[5] == 'e' &&
9981                   name[6] == 'n')
9982               {                                   /* dbmopen    */
9983                 return -KEY_dbmopen;
9984               }
9985
9986               goto unknown;
9987
9988             case 'e':
9989               if (name[2] == 'f')
9990               {
9991                 switch (name[3])
9992                 {
9993                   case 'a':
9994                     if (name[4] == 'u' &&
9995                         name[5] == 'l' &&
9996                         name[6] == 't')
9997                     {                             /* default    */
9998                       return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
9999                     }
10000
10001                     goto unknown;
10002
10003                   case 'i':
10004                     if (name[4] == 'n' &&
10005                         name[5] == 'e' &&
10006                         name[6] == 'd')
10007                     {                             /* defined    */
10008                       return KEY_defined;
10009                     }
10010
10011                     goto unknown;
10012
10013                   default:
10014                     goto unknown;
10015                 }
10016               }
10017
10018               goto unknown;
10019
10020             default:
10021               goto unknown;
10022           }
10023
10024         case 'f':
10025           if (name[1] == 'o' &&
10026               name[2] == 'r' &&
10027               name[3] == 'e' &&
10028               name[4] == 'a' &&
10029               name[5] == 'c' &&
10030               name[6] == 'h')
10031           {                                       /* foreach    */
10032             return KEY_foreach;
10033           }
10034
10035           goto unknown;
10036
10037         case 'g':
10038           if (name[1] == 'e' &&
10039               name[2] == 't' &&
10040               name[3] == 'p')
10041           {
10042             switch (name[4])
10043             {
10044               case 'g':
10045                 if (name[5] == 'r' &&
10046                     name[6] == 'p')
10047                 {                                 /* getpgrp    */
10048                   return -KEY_getpgrp;
10049                 }
10050
10051                 goto unknown;
10052
10053               case 'p':
10054                 if (name[5] == 'i' &&
10055                     name[6] == 'd')
10056                 {                                 /* getppid    */
10057                   return -KEY_getppid;
10058                 }
10059
10060                 goto unknown;
10061
10062               default:
10063                 goto unknown;
10064             }
10065           }
10066
10067           goto unknown;
10068
10069         case 'l':
10070           if (name[1] == 'c' &&
10071               name[2] == 'f' &&
10072               name[3] == 'i' &&
10073               name[4] == 'r' &&
10074               name[5] == 's' &&
10075               name[6] == 't')
10076           {                                       /* lcfirst    */
10077             return -KEY_lcfirst;
10078           }
10079
10080           goto unknown;
10081
10082         case 'o':
10083           if (name[1] == 'p' &&
10084               name[2] == 'e' &&
10085               name[3] == 'n' &&
10086               name[4] == 'd' &&
10087               name[5] == 'i' &&
10088               name[6] == 'r')
10089           {                                       /* opendir    */
10090             return -KEY_opendir;
10091           }
10092
10093           goto unknown;
10094
10095         case 'p':
10096           if (name[1] == 'a' &&
10097               name[2] == 'c' &&
10098               name[3] == 'k' &&
10099               name[4] == 'a' &&
10100               name[5] == 'g' &&
10101               name[6] == 'e')
10102           {                                       /* package    */
10103             return KEY_package;
10104           }
10105
10106           goto unknown;
10107
10108         case 'r':
10109           if (name[1] == 'e')
10110           {
10111             switch (name[2])
10112             {
10113               case 'a':
10114                 if (name[3] == 'd' &&
10115                     name[4] == 'd' &&
10116                     name[5] == 'i' &&
10117                     name[6] == 'r')
10118                 {                                 /* readdir    */
10119                   return -KEY_readdir;
10120                 }
10121
10122                 goto unknown;
10123
10124               case 'q':
10125                 if (name[3] == 'u' &&
10126                     name[4] == 'i' &&
10127                     name[5] == 'r' &&
10128                     name[6] == 'e')
10129                 {                                 /* require    */
10130                   return KEY_require;
10131                 }
10132
10133                 goto unknown;
10134
10135               case 'v':
10136                 if (name[3] == 'e' &&
10137                     name[4] == 'r' &&
10138                     name[5] == 's' &&
10139                     name[6] == 'e')
10140                 {                                 /* reverse    */
10141                   return -KEY_reverse;
10142                 }
10143
10144                 goto unknown;
10145
10146               default:
10147                 goto unknown;
10148             }
10149           }
10150
10151           goto unknown;
10152
10153         case 's':
10154           switch (name[1])
10155           {
10156             case 'e':
10157               switch (name[2])
10158               {
10159                 case 'e':
10160                   if (name[3] == 'k' &&
10161                       name[4] == 'd' &&
10162                       name[5] == 'i' &&
10163                       name[6] == 'r')
10164                   {                               /* seekdir    */
10165                     return -KEY_seekdir;
10166                   }
10167
10168                   goto unknown;
10169
10170                 case 't':
10171                   if (name[3] == 'p' &&
10172                       name[4] == 'g' &&
10173                       name[5] == 'r' &&
10174                       name[6] == 'p')
10175                   {                               /* setpgrp    */
10176                     return -KEY_setpgrp;
10177                   }
10178
10179                   goto unknown;
10180
10181                 default:
10182                   goto unknown;
10183               }
10184
10185             case 'h':
10186               if (name[2] == 'm' &&
10187                   name[3] == 'r' &&
10188                   name[4] == 'e' &&
10189                   name[5] == 'a' &&
10190                   name[6] == 'd')
10191               {                                   /* shmread    */
10192                 return -KEY_shmread;
10193               }
10194
10195               goto unknown;
10196
10197             case 'p':
10198               if (name[2] == 'r' &&
10199                   name[3] == 'i' &&
10200                   name[4] == 'n' &&
10201                   name[5] == 't' &&
10202                   name[6] == 'f')
10203               {                                   /* sprintf    */
10204                 return -KEY_sprintf;
10205               }
10206
10207               goto unknown;
10208
10209             case 'y':
10210               switch (name[2])
10211               {
10212                 case 'm':
10213                   if (name[3] == 'l' &&
10214                       name[4] == 'i' &&
10215                       name[5] == 'n' &&
10216                       name[6] == 'k')
10217                   {                               /* symlink    */
10218                     return -KEY_symlink;
10219                   }
10220
10221                   goto unknown;
10222
10223                 case 's':
10224                   switch (name[3])
10225                   {
10226                     case 'c':
10227                       if (name[4] == 'a' &&
10228                           name[5] == 'l' &&
10229                           name[6] == 'l')
10230                       {                           /* syscall    */
10231                         return -KEY_syscall;
10232                       }
10233
10234                       goto unknown;
10235
10236                     case 'o':
10237                       if (name[4] == 'p' &&
10238                           name[5] == 'e' &&
10239                           name[6] == 'n')
10240                       {                           /* sysopen    */
10241                         return -KEY_sysopen;
10242                       }
10243
10244                       goto unknown;
10245
10246                     case 'r':
10247                       if (name[4] == 'e' &&
10248                           name[5] == 'a' &&
10249                           name[6] == 'd')
10250                       {                           /* sysread    */
10251                         return -KEY_sysread;
10252                       }
10253
10254                       goto unknown;
10255
10256                     case 's':
10257                       if (name[4] == 'e' &&
10258                           name[5] == 'e' &&
10259                           name[6] == 'k')
10260                       {                           /* sysseek    */
10261                         return -KEY_sysseek;
10262                       }
10263
10264                       goto unknown;
10265
10266                     default:
10267                       goto unknown;
10268                   }
10269
10270                 default:
10271                   goto unknown;
10272               }
10273
10274             default:
10275               goto unknown;
10276           }
10277
10278         case 't':
10279           if (name[1] == 'e' &&
10280               name[2] == 'l' &&
10281               name[3] == 'l' &&
10282               name[4] == 'd' &&
10283               name[5] == 'i' &&
10284               name[6] == 'r')
10285           {                                       /* telldir    */
10286             return -KEY_telldir;
10287           }
10288
10289           goto unknown;
10290
10291         case 'u':
10292           switch (name[1])
10293           {
10294             case 'c':
10295               if (name[2] == 'f' &&
10296                   name[3] == 'i' &&
10297                   name[4] == 'r' &&
10298                   name[5] == 's' &&
10299                   name[6] == 't')
10300               {                                   /* ucfirst    */
10301                 return -KEY_ucfirst;
10302               }
10303
10304               goto unknown;
10305
10306             case 'n':
10307               if (name[2] == 's' &&
10308                   name[3] == 'h' &&
10309                   name[4] == 'i' &&
10310                   name[5] == 'f' &&
10311                   name[6] == 't')
10312               {                                   /* unshift    */
10313                 return -KEY_unshift;
10314               }
10315
10316               goto unknown;
10317
10318             default:
10319               goto unknown;
10320           }
10321
10322         case 'w':
10323           if (name[1] == 'a' &&
10324               name[2] == 'i' &&
10325               name[3] == 't' &&
10326               name[4] == 'p' &&
10327               name[5] == 'i' &&
10328               name[6] == 'd')
10329           {                                       /* waitpid    */
10330             return -KEY_waitpid;
10331           }
10332
10333           goto unknown;
10334
10335         default:
10336           goto unknown;
10337       }
10338
10339     case 8: /* 26 tokens of length 8 */
10340       switch (name[0])
10341       {
10342         case 'A':
10343           if (name[1] == 'U' &&
10344               name[2] == 'T' &&
10345               name[3] == 'O' &&
10346               name[4] == 'L' &&
10347               name[5] == 'O' &&
10348               name[6] == 'A' &&
10349               name[7] == 'D')
10350           {                                       /* AUTOLOAD   */
10351             return KEY_AUTOLOAD;
10352           }
10353
10354           goto unknown;
10355
10356         case '_':
10357           if (name[1] == '_')
10358           {
10359             switch (name[2])
10360             {
10361               case 'D':
10362                 if (name[3] == 'A' &&
10363                     name[4] == 'T' &&
10364                     name[5] == 'A' &&
10365                     name[6] == '_' &&
10366                     name[7] == '_')
10367                 {                                 /* __DATA__   */
10368                   return KEY___DATA__;
10369                 }
10370
10371                 goto unknown;
10372
10373               case 'F':
10374                 if (name[3] == 'I' &&
10375                     name[4] == 'L' &&
10376                     name[5] == 'E' &&
10377                     name[6] == '_' &&
10378                     name[7] == '_')
10379                 {                                 /* __FILE__   */
10380                   return -KEY___FILE__;
10381                 }
10382
10383                 goto unknown;
10384
10385               case 'L':
10386                 if (name[3] == 'I' &&
10387                     name[4] == 'N' &&
10388                     name[5] == 'E' &&
10389                     name[6] == '_' &&
10390                     name[7] == '_')
10391                 {                                 /* __LINE__   */
10392                   return -KEY___LINE__;
10393                 }
10394
10395                 goto unknown;
10396
10397               default:
10398                 goto unknown;
10399             }
10400           }
10401
10402           goto unknown;
10403
10404         case 'c':
10405           switch (name[1])
10406           {
10407             case 'l':
10408               if (name[2] == 'o' &&
10409                   name[3] == 's' &&
10410                   name[4] == 'e' &&
10411                   name[5] == 'd' &&
10412                   name[6] == 'i' &&
10413                   name[7] == 'r')
10414               {                                   /* closedir   */
10415                 return -KEY_closedir;
10416               }
10417
10418               goto unknown;
10419
10420             case 'o':
10421               if (name[2] == 'n' &&
10422                   name[3] == 't' &&
10423                   name[4] == 'i' &&
10424                   name[5] == 'n' &&
10425                   name[6] == 'u' &&
10426                   name[7] == 'e')
10427               {                                   /* continue   */
10428                 return -KEY_continue;
10429               }
10430
10431               goto unknown;
10432
10433             default:
10434               goto unknown;
10435           }
10436
10437         case 'd':
10438           if (name[1] == 'b' &&
10439               name[2] == 'm' &&
10440               name[3] == 'c' &&
10441               name[4] == 'l' &&
10442               name[5] == 'o' &&
10443               name[6] == 's' &&
10444               name[7] == 'e')
10445           {                                       /* dbmclose   */
10446             return -KEY_dbmclose;
10447           }
10448
10449           goto unknown;
10450
10451         case 'e':
10452           if (name[1] == 'n' &&
10453               name[2] == 'd')
10454           {
10455             switch (name[3])
10456             {
10457               case 'g':
10458                 if (name[4] == 'r' &&
10459                     name[5] == 'e' &&
10460                     name[6] == 'n' &&
10461                     name[7] == 't')
10462                 {                                 /* endgrent   */
10463                   return -KEY_endgrent;
10464                 }
10465
10466                 goto unknown;
10467
10468               case 'p':
10469                 if (name[4] == 'w' &&
10470                     name[5] == 'e' &&
10471                     name[6] == 'n' &&
10472                     name[7] == 't')
10473                 {                                 /* endpwent   */
10474                   return -KEY_endpwent;
10475                 }
10476
10477                 goto unknown;
10478
10479               default:
10480                 goto unknown;
10481             }
10482           }
10483
10484           goto unknown;
10485
10486         case 'f':
10487           if (name[1] == 'o' &&
10488               name[2] == 'r' &&
10489               name[3] == 'm' &&
10490               name[4] == 'l' &&
10491               name[5] == 'i' &&
10492               name[6] == 'n' &&
10493               name[7] == 'e')
10494           {                                       /* formline   */
10495             return -KEY_formline;
10496           }
10497
10498           goto unknown;
10499
10500         case 'g':
10501           if (name[1] == 'e' &&
10502               name[2] == 't')
10503           {
10504             switch (name[3])
10505             {
10506               case 'g':
10507                 if (name[4] == 'r')
10508                 {
10509                   switch (name[5])
10510                   {
10511                     case 'e':
10512                       if (name[6] == 'n' &&
10513                           name[7] == 't')
10514                       {                           /* getgrent   */
10515                         return -KEY_getgrent;
10516                       }
10517
10518                       goto unknown;
10519
10520                     case 'g':
10521                       if (name[6] == 'i' &&
10522                           name[7] == 'd')
10523                       {                           /* getgrgid   */
10524                         return -KEY_getgrgid;
10525                       }
10526
10527                       goto unknown;
10528
10529                     case 'n':
10530                       if (name[6] == 'a' &&
10531                           name[7] == 'm')
10532                       {                           /* getgrnam   */
10533                         return -KEY_getgrnam;
10534                       }
10535
10536                       goto unknown;
10537
10538                     default:
10539                       goto unknown;
10540                   }
10541                 }
10542
10543                 goto unknown;
10544
10545               case 'l':
10546                 if (name[4] == 'o' &&
10547                     name[5] == 'g' &&
10548                     name[6] == 'i' &&
10549                     name[7] == 'n')
10550                 {                                 /* getlogin   */
10551                   return -KEY_getlogin;
10552                 }
10553
10554                 goto unknown;
10555
10556               case 'p':
10557                 if (name[4] == 'w')
10558                 {
10559                   switch (name[5])
10560                   {
10561                     case 'e':
10562                       if (name[6] == 'n' &&
10563                           name[7] == 't')
10564                       {                           /* getpwent   */
10565                         return -KEY_getpwent;
10566                       }
10567
10568                       goto unknown;
10569
10570                     case 'n':
10571                       if (name[6] == 'a' &&
10572                           name[7] == 'm')
10573                       {                           /* getpwnam   */
10574                         return -KEY_getpwnam;
10575                       }
10576
10577                       goto unknown;
10578
10579                     case 'u':
10580                       if (name[6] == 'i' &&
10581                           name[7] == 'd')
10582                       {                           /* getpwuid   */
10583                         return -KEY_getpwuid;
10584                       }
10585
10586                       goto unknown;
10587
10588                     default:
10589                       goto unknown;
10590                   }
10591                 }
10592
10593                 goto unknown;
10594
10595               default:
10596                 goto unknown;
10597             }
10598           }
10599
10600           goto unknown;
10601
10602         case 'r':
10603           if (name[1] == 'e' &&
10604               name[2] == 'a' &&
10605               name[3] == 'd')
10606           {
10607             switch (name[4])
10608             {
10609               case 'l':
10610                 if (name[5] == 'i' &&
10611                     name[6] == 'n')
10612                 {
10613                   switch (name[7])
10614                   {
10615                     case 'e':
10616                       {                           /* readline   */
10617                         return -KEY_readline;
10618                       }
10619
10620                     case 'k':
10621                       {                           /* readlink   */
10622                         return -KEY_readlink;
10623                       }
10624
10625                     default:
10626                       goto unknown;
10627                   }
10628                 }
10629
10630                 goto unknown;
10631
10632               case 'p':
10633                 if (name[5] == 'i' &&
10634                     name[6] == 'p' &&
10635                     name[7] == 'e')
10636                 {                                 /* readpipe   */
10637                   return -KEY_readpipe;
10638                 }
10639
10640                 goto unknown;
10641
10642               default:
10643                 goto unknown;
10644             }
10645           }
10646
10647           goto unknown;
10648
10649         case 's':
10650           switch (name[1])
10651           {
10652             case 'e':
10653               if (name[2] == 't')
10654               {
10655                 switch (name[3])
10656                 {
10657                   case 'g':
10658                     if (name[4] == 'r' &&
10659                         name[5] == 'e' &&
10660                         name[6] == 'n' &&
10661                         name[7] == 't')
10662                     {                             /* setgrent   */
10663                       return -KEY_setgrent;
10664                     }
10665
10666                     goto unknown;
10667
10668                   case 'p':
10669                     if (name[4] == 'w' &&
10670                         name[5] == 'e' &&
10671                         name[6] == 'n' &&
10672                         name[7] == 't')
10673                     {                             /* setpwent   */
10674                       return -KEY_setpwent;
10675                     }
10676
10677                     goto unknown;
10678
10679                   default:
10680                     goto unknown;
10681                 }
10682               }
10683
10684               goto unknown;
10685
10686             case 'h':
10687               switch (name[2])
10688               {
10689                 case 'm':
10690                   if (name[3] == 'w' &&
10691                       name[4] == 'r' &&
10692                       name[5] == 'i' &&
10693                       name[6] == 't' &&
10694                       name[7] == 'e')
10695                   {                               /* shmwrite   */
10696                     return -KEY_shmwrite;
10697                   }
10698
10699                   goto unknown;
10700
10701                 case 'u':
10702                   if (name[3] == 't' &&
10703                       name[4] == 'd' &&
10704                       name[5] == 'o' &&
10705                       name[6] == 'w' &&
10706                       name[7] == 'n')
10707                   {                               /* shutdown   */
10708                     return -KEY_shutdown;
10709                   }
10710
10711                   goto unknown;
10712
10713                 default:
10714                   goto unknown;
10715               }
10716
10717             case 'y':
10718               if (name[2] == 's' &&
10719                   name[3] == 'w' &&
10720                   name[4] == 'r' &&
10721                   name[5] == 'i' &&
10722                   name[6] == 't' &&
10723                   name[7] == 'e')
10724               {                                   /* syswrite   */
10725                 return -KEY_syswrite;
10726               }
10727
10728               goto unknown;
10729
10730             default:
10731               goto unknown;
10732           }
10733
10734         case 't':
10735           if (name[1] == 'r' &&
10736               name[2] == 'u' &&
10737               name[3] == 'n' &&
10738               name[4] == 'c' &&
10739               name[5] == 'a' &&
10740               name[6] == 't' &&
10741               name[7] == 'e')
10742           {                                       /* truncate   */
10743             return -KEY_truncate;
10744           }
10745
10746           goto unknown;
10747
10748         default:
10749           goto unknown;
10750       }
10751
10752     case 9: /* 9 tokens of length 9 */
10753       switch (name[0])
10754       {
10755         case 'U':
10756           if (name[1] == 'N' &&
10757               name[2] == 'I' &&
10758               name[3] == 'T' &&
10759               name[4] == 'C' &&
10760               name[5] == 'H' &&
10761               name[6] == 'E' &&
10762               name[7] == 'C' &&
10763               name[8] == 'K')
10764           {                                       /* UNITCHECK  */
10765             return KEY_UNITCHECK;
10766           }
10767
10768           goto unknown;
10769
10770         case 'e':
10771           if (name[1] == 'n' &&
10772               name[2] == 'd' &&
10773               name[3] == 'n' &&
10774               name[4] == 'e' &&
10775               name[5] == 't' &&
10776               name[6] == 'e' &&
10777               name[7] == 'n' &&
10778               name[8] == 't')
10779           {                                       /* endnetent  */
10780             return -KEY_endnetent;
10781           }
10782
10783           goto unknown;
10784
10785         case 'g':
10786           if (name[1] == 'e' &&
10787               name[2] == 't' &&
10788               name[3] == 'n' &&
10789               name[4] == 'e' &&
10790               name[5] == 't' &&
10791               name[6] == 'e' &&
10792               name[7] == 'n' &&
10793               name[8] == 't')
10794           {                                       /* getnetent  */
10795             return -KEY_getnetent;
10796           }
10797
10798           goto unknown;
10799
10800         case 'l':
10801           if (name[1] == 'o' &&
10802               name[2] == 'c' &&
10803               name[3] == 'a' &&
10804               name[4] == 'l' &&
10805               name[5] == 't' &&
10806               name[6] == 'i' &&
10807               name[7] == 'm' &&
10808               name[8] == 'e')
10809           {                                       /* localtime  */
10810             return -KEY_localtime;
10811           }
10812
10813           goto unknown;
10814
10815         case 'p':
10816           if (name[1] == 'r' &&
10817               name[2] == 'o' &&
10818               name[3] == 't' &&
10819               name[4] == 'o' &&
10820               name[5] == 't' &&
10821               name[6] == 'y' &&
10822               name[7] == 'p' &&
10823               name[8] == 'e')
10824           {                                       /* prototype  */
10825             return KEY_prototype;
10826           }
10827
10828           goto unknown;
10829
10830         case 'q':
10831           if (name[1] == 'u' &&
10832               name[2] == 'o' &&
10833               name[3] == 't' &&
10834               name[4] == 'e' &&
10835               name[5] == 'm' &&
10836               name[6] == 'e' &&
10837               name[7] == 't' &&
10838               name[8] == 'a')
10839           {                                       /* quotemeta  */
10840             return -KEY_quotemeta;
10841           }
10842
10843           goto unknown;
10844
10845         case 'r':
10846           if (name[1] == 'e' &&
10847               name[2] == 'w' &&
10848               name[3] == 'i' &&
10849               name[4] == 'n' &&
10850               name[5] == 'd' &&
10851               name[6] == 'd' &&
10852               name[7] == 'i' &&
10853               name[8] == 'r')
10854           {                                       /* rewinddir  */
10855             return -KEY_rewinddir;
10856           }
10857
10858           goto unknown;
10859
10860         case 's':
10861           if (name[1] == 'e' &&
10862               name[2] == 't' &&
10863               name[3] == 'n' &&
10864               name[4] == 'e' &&
10865               name[5] == 't' &&
10866               name[6] == 'e' &&
10867               name[7] == 'n' &&
10868               name[8] == 't')
10869           {                                       /* setnetent  */
10870             return -KEY_setnetent;
10871           }
10872
10873           goto unknown;
10874
10875         case 'w':
10876           if (name[1] == 'a' &&
10877               name[2] == 'n' &&
10878               name[3] == 't' &&
10879               name[4] == 'a' &&
10880               name[5] == 'r' &&
10881               name[6] == 'r' &&
10882               name[7] == 'a' &&
10883               name[8] == 'y')
10884           {                                       /* wantarray  */
10885             return -KEY_wantarray;
10886           }
10887
10888           goto unknown;
10889
10890         default:
10891           goto unknown;
10892       }
10893
10894     case 10: /* 9 tokens of length 10 */
10895       switch (name[0])
10896       {
10897         case 'e':
10898           if (name[1] == 'n' &&
10899               name[2] == 'd')
10900           {
10901             switch (name[3])
10902             {
10903               case 'h':
10904                 if (name[4] == 'o' &&
10905                     name[5] == 's' &&
10906                     name[6] == 't' &&
10907                     name[7] == 'e' &&
10908                     name[8] == 'n' &&
10909                     name[9] == 't')
10910                 {                                 /* endhostent */
10911                   return -KEY_endhostent;
10912                 }
10913
10914                 goto unknown;
10915
10916               case 's':
10917                 if (name[4] == 'e' &&
10918                     name[5] == 'r' &&
10919                     name[6] == 'v' &&
10920                     name[7] == 'e' &&
10921                     name[8] == 'n' &&
10922                     name[9] == 't')
10923                 {                                 /* endservent */
10924                   return -KEY_endservent;
10925                 }
10926
10927                 goto unknown;
10928
10929               default:
10930                 goto unknown;
10931             }
10932           }
10933
10934           goto unknown;
10935
10936         case 'g':
10937           if (name[1] == 'e' &&
10938               name[2] == 't')
10939           {
10940             switch (name[3])
10941             {
10942               case 'h':
10943                 if (name[4] == 'o' &&
10944                     name[5] == 's' &&
10945                     name[6] == 't' &&
10946                     name[7] == 'e' &&
10947                     name[8] == 'n' &&
10948                     name[9] == 't')
10949                 {                                 /* gethostent */
10950                   return -KEY_gethostent;
10951                 }
10952
10953                 goto unknown;
10954
10955               case 's':
10956                 switch (name[4])
10957                 {
10958                   case 'e':
10959                     if (name[5] == 'r' &&
10960                         name[6] == 'v' &&
10961                         name[7] == 'e' &&
10962                         name[8] == 'n' &&
10963                         name[9] == 't')
10964                     {                             /* getservent */
10965                       return -KEY_getservent;
10966                     }
10967
10968                     goto unknown;
10969
10970                   case 'o':
10971                     if (name[5] == 'c' &&
10972                         name[6] == 'k' &&
10973                         name[7] == 'o' &&
10974                         name[8] == 'p' &&
10975                         name[9] == 't')
10976                     {                             /* getsockopt */
10977                       return -KEY_getsockopt;
10978                     }
10979
10980                     goto unknown;
10981
10982                   default:
10983                     goto unknown;
10984                 }
10985
10986               default:
10987                 goto unknown;
10988             }
10989           }
10990
10991           goto unknown;
10992
10993         case 's':
10994           switch (name[1])
10995           {
10996             case 'e':
10997               if (name[2] == 't')
10998               {
10999                 switch (name[3])
11000                 {
11001                   case 'h':
11002                     if (name[4] == 'o' &&
11003                         name[5] == 's' &&
11004                         name[6] == 't' &&
11005                         name[7] == 'e' &&
11006                         name[8] == 'n' &&
11007                         name[9] == 't')
11008                     {                             /* sethostent */
11009                       return -KEY_sethostent;
11010                     }
11011
11012                     goto unknown;
11013
11014                   case 's':
11015                     switch (name[4])
11016                     {
11017                       case 'e':
11018                         if (name[5] == 'r' &&
11019                             name[6] == 'v' &&
11020                             name[7] == 'e' &&
11021                             name[8] == 'n' &&
11022                             name[9] == 't')
11023                         {                         /* setservent */
11024                           return -KEY_setservent;
11025                         }
11026
11027                         goto unknown;
11028
11029                       case 'o':
11030                         if (name[5] == 'c' &&
11031                             name[6] == 'k' &&
11032                             name[7] == 'o' &&
11033                             name[8] == 'p' &&
11034                             name[9] == 't')
11035                         {                         /* setsockopt */
11036                           return -KEY_setsockopt;
11037                         }
11038
11039                         goto unknown;
11040
11041                       default:
11042                         goto unknown;
11043                     }
11044
11045                   default:
11046                     goto unknown;
11047                 }
11048               }
11049
11050               goto unknown;
11051
11052             case 'o':
11053               if (name[2] == 'c' &&
11054                   name[3] == 'k' &&
11055                   name[4] == 'e' &&
11056                   name[5] == 't' &&
11057                   name[6] == 'p' &&
11058                   name[7] == 'a' &&
11059                   name[8] == 'i' &&
11060                   name[9] == 'r')
11061               {                                   /* socketpair */
11062                 return -KEY_socketpair;
11063               }
11064
11065               goto unknown;
11066
11067             default:
11068               goto unknown;
11069           }
11070
11071         default:
11072           goto unknown;
11073       }
11074
11075     case 11: /* 8 tokens of length 11 */
11076       switch (name[0])
11077       {
11078         case '_':
11079           if (name[1] == '_' &&
11080               name[2] == 'P' &&
11081               name[3] == 'A' &&
11082               name[4] == 'C' &&
11083               name[5] == 'K' &&
11084               name[6] == 'A' &&
11085               name[7] == 'G' &&
11086               name[8] == 'E' &&
11087               name[9] == '_' &&
11088               name[10] == '_')
11089           {                                       /* __PACKAGE__ */
11090             return -KEY___PACKAGE__;
11091           }
11092
11093           goto unknown;
11094
11095         case 'e':
11096           if (name[1] == 'n' &&
11097               name[2] == 'd' &&
11098               name[3] == 'p' &&
11099               name[4] == 'r' &&
11100               name[5] == 'o' &&
11101               name[6] == 't' &&
11102               name[7] == 'o' &&
11103               name[8] == 'e' &&
11104               name[9] == 'n' &&
11105               name[10] == 't')
11106           {                                       /* endprotoent */
11107             return -KEY_endprotoent;
11108           }
11109
11110           goto unknown;
11111
11112         case 'g':
11113           if (name[1] == 'e' &&
11114               name[2] == 't')
11115           {
11116             switch (name[3])
11117             {
11118               case 'p':
11119                 switch (name[4])
11120                 {
11121                   case 'e':
11122                     if (name[5] == 'e' &&
11123                         name[6] == 'r' &&
11124                         name[7] == 'n' &&
11125                         name[8] == 'a' &&
11126                         name[9] == 'm' &&
11127                         name[10] == 'e')
11128                     {                             /* getpeername */
11129                       return -KEY_getpeername;
11130                     }
11131
11132                     goto unknown;
11133
11134                   case 'r':
11135                     switch (name[5])
11136                     {
11137                       case 'i':
11138                         if (name[6] == 'o' &&
11139                             name[7] == 'r' &&
11140                             name[8] == 'i' &&
11141                             name[9] == 't' &&
11142                             name[10] == 'y')
11143                         {                         /* getpriority */
11144                           return -KEY_getpriority;
11145                         }
11146
11147                         goto unknown;
11148
11149                       case 'o':
11150                         if (name[6] == 't' &&
11151                             name[7] == 'o' &&
11152                             name[8] == 'e' &&
11153                             name[9] == 'n' &&
11154                             name[10] == 't')
11155                         {                         /* getprotoent */
11156                           return -KEY_getprotoent;
11157                         }
11158
11159                         goto unknown;
11160
11161                       default:
11162                         goto unknown;
11163                     }
11164
11165                   default:
11166                     goto unknown;
11167                 }
11168
11169               case 's':
11170                 if (name[4] == 'o' &&
11171                     name[5] == 'c' &&
11172                     name[6] == 'k' &&
11173                     name[7] == 'n' &&
11174                     name[8] == 'a' &&
11175                     name[9] == 'm' &&
11176                     name[10] == 'e')
11177                 {                                 /* getsockname */
11178                   return -KEY_getsockname;
11179                 }
11180
11181                 goto unknown;
11182
11183               default:
11184                 goto unknown;
11185             }
11186           }
11187
11188           goto unknown;
11189
11190         case 's':
11191           if (name[1] == 'e' &&
11192               name[2] == 't' &&
11193               name[3] == 'p' &&
11194               name[4] == 'r')
11195           {
11196             switch (name[5])
11197             {
11198               case 'i':
11199                 if (name[6] == 'o' &&
11200                     name[7] == 'r' &&
11201                     name[8] == 'i' &&
11202                     name[9] == 't' &&
11203                     name[10] == 'y')
11204                 {                                 /* setpriority */
11205                   return -KEY_setpriority;
11206                 }
11207
11208                 goto unknown;
11209
11210               case 'o':
11211                 if (name[6] == 't' &&
11212                     name[7] == 'o' &&
11213                     name[8] == 'e' &&
11214                     name[9] == 'n' &&
11215                     name[10] == 't')
11216                 {                                 /* setprotoent */
11217                   return -KEY_setprotoent;
11218                 }
11219
11220                 goto unknown;
11221
11222               default:
11223                 goto unknown;
11224             }
11225           }
11226
11227           goto unknown;
11228
11229         default:
11230           goto unknown;
11231       }
11232
11233     case 12: /* 2 tokens of length 12 */
11234       if (name[0] == 'g' &&
11235           name[1] == 'e' &&
11236           name[2] == 't' &&
11237           name[3] == 'n' &&
11238           name[4] == 'e' &&
11239           name[5] == 't' &&
11240           name[6] == 'b' &&
11241           name[7] == 'y')
11242       {
11243         switch (name[8])
11244         {
11245           case 'a':
11246             if (name[9] == 'd' &&
11247                 name[10] == 'd' &&
11248                 name[11] == 'r')
11249             {                                     /* getnetbyaddr */
11250               return -KEY_getnetbyaddr;
11251             }
11252
11253             goto unknown;
11254
11255           case 'n':
11256             if (name[9] == 'a' &&
11257                 name[10] == 'm' &&
11258                 name[11] == 'e')
11259             {                                     /* getnetbyname */
11260               return -KEY_getnetbyname;
11261             }
11262
11263             goto unknown;
11264
11265           default:
11266             goto unknown;
11267         }
11268       }
11269
11270       goto unknown;
11271
11272     case 13: /* 4 tokens of length 13 */
11273       if (name[0] == 'g' &&
11274           name[1] == 'e' &&
11275           name[2] == 't')
11276       {
11277         switch (name[3])
11278         {
11279           case 'h':
11280             if (name[4] == 'o' &&
11281                 name[5] == 's' &&
11282                 name[6] == 't' &&
11283                 name[7] == 'b' &&
11284                 name[8] == 'y')
11285             {
11286               switch (name[9])
11287               {
11288                 case 'a':
11289                   if (name[10] == 'd' &&
11290                       name[11] == 'd' &&
11291                       name[12] == 'r')
11292                   {                               /* gethostbyaddr */
11293                     return -KEY_gethostbyaddr;
11294                   }
11295
11296                   goto unknown;
11297
11298                 case 'n':
11299                   if (name[10] == 'a' &&
11300                       name[11] == 'm' &&
11301                       name[12] == 'e')
11302                   {                               /* gethostbyname */
11303                     return -KEY_gethostbyname;
11304                   }
11305
11306                   goto unknown;
11307
11308                 default:
11309                   goto unknown;
11310               }
11311             }
11312
11313             goto unknown;
11314
11315           case 's':
11316             if (name[4] == 'e' &&
11317                 name[5] == 'r' &&
11318                 name[6] == 'v' &&
11319                 name[7] == 'b' &&
11320                 name[8] == 'y')
11321             {
11322               switch (name[9])
11323               {
11324                 case 'n':
11325                   if (name[10] == 'a' &&
11326                       name[11] == 'm' &&
11327                       name[12] == 'e')
11328                   {                               /* getservbyname */
11329                     return -KEY_getservbyname;
11330                   }
11331
11332                   goto unknown;
11333
11334                 case 'p':
11335                   if (name[10] == 'o' &&
11336                       name[11] == 'r' &&
11337                       name[12] == 't')
11338                   {                               /* getservbyport */
11339                     return -KEY_getservbyport;
11340                   }
11341
11342                   goto unknown;
11343
11344                 default:
11345                   goto unknown;
11346               }
11347             }
11348
11349             goto unknown;
11350
11351           default:
11352             goto unknown;
11353         }
11354       }
11355
11356       goto unknown;
11357
11358     case 14: /* 1 tokens of length 14 */
11359       if (name[0] == 'g' &&
11360           name[1] == 'e' &&
11361           name[2] == 't' &&
11362           name[3] == 'p' &&
11363           name[4] == 'r' &&
11364           name[5] == 'o' &&
11365           name[6] == 't' &&
11366           name[7] == 'o' &&
11367           name[8] == 'b' &&
11368           name[9] == 'y' &&
11369           name[10] == 'n' &&
11370           name[11] == 'a' &&
11371           name[12] == 'm' &&
11372           name[13] == 'e')
11373       {                                           /* getprotobyname */
11374         return -KEY_getprotobyname;
11375       }
11376
11377       goto unknown;
11378
11379     case 16: /* 1 tokens of length 16 */
11380       if (name[0] == 'g' &&
11381           name[1] == 'e' &&
11382           name[2] == 't' &&
11383           name[3] == 'p' &&
11384           name[4] == 'r' &&
11385           name[5] == 'o' &&
11386           name[6] == 't' &&
11387           name[7] == 'o' &&
11388           name[8] == 'b' &&
11389           name[9] == 'y' &&
11390           name[10] == 'n' &&
11391           name[11] == 'u' &&
11392           name[12] == 'm' &&
11393           name[13] == 'b' &&
11394           name[14] == 'e' &&
11395           name[15] == 'r')
11396       {                                           /* getprotobynumber */
11397         return -KEY_getprotobynumber;
11398       }
11399
11400       goto unknown;
11401
11402     default:
11403       goto unknown;
11404   }
11405
11406 unknown:
11407   return 0;
11408 }
11409
11410 STATIC void
11411 S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
11412 {
11413     dVAR;
11414
11415     PERL_ARGS_ASSERT_CHECKCOMMA;
11416
11417     if (*s == ' ' && s[1] == '(') {     /* XXX gotta be a better way */
11418         if (ckWARN(WARN_SYNTAX)) {
11419             int level = 1;
11420             const char *w;
11421             for (w = s+2; *w && level; w++) {
11422                 if (*w == '(')
11423                     ++level;
11424                 else if (*w == ')')
11425                     --level;
11426             }
11427             while (isSPACE(*w))
11428                 ++w;
11429             /* the list of chars below is for end of statements or
11430              * block / parens, boolean operators (&&, ||, //) and branch
11431              * constructs (or, and, if, until, unless, while, err, for).
11432              * Not a very solid hack... */
11433             if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
11434                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
11435                             "%s (...) interpreted as function",name);
11436         }
11437     }
11438     while (s < PL_bufend && isSPACE(*s))
11439         s++;
11440     if (*s == '(')
11441         s++;
11442     while (s < PL_bufend && isSPACE(*s))
11443         s++;
11444     if (isIDFIRST_lazy_if(s,UTF)) {
11445         const char * const w = s++;
11446         while (isALNUM_lazy_if(s,UTF))
11447             s++;
11448         while (s < PL_bufend && isSPACE(*s))
11449             s++;
11450         if (*s == ',') {
11451             GV* gv;
11452             if (keyword(w, s - w, 0))
11453                 return;
11454
11455             gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
11456             if (gv && GvCVu(gv))
11457                 return;
11458             Perl_croak(aTHX_ "No comma allowed after %s", what);
11459         }
11460     }
11461 }
11462
11463 /* Either returns sv, or mortalizes sv and returns a new SV*.
11464    Best used as sv=new_constant(..., sv, ...).
11465    If s, pv are NULL, calls subroutine with one argument,
11466    and type is used with error messages only. */
11467
11468 STATIC SV *
11469 S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen,
11470                SV *sv, SV *pv, const char *type, STRLEN typelen)
11471 {
11472     dVAR; dSP;
11473     HV * const table = GvHV(PL_hintgv);          /* ^H */
11474     SV *res;
11475     SV **cvp;
11476     SV *cv, *typesv;
11477     const char *why1 = "", *why2 = "", *why3 = "";
11478
11479     PERL_ARGS_ASSERT_NEW_CONSTANT;
11480
11481     if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
11482         SV *msg;
11483         
11484         why2 = (const char *)
11485             (strEQ(key,"charnames")
11486              ? "(possibly a missing \"use charnames ...\")"
11487              : "");
11488         msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
11489                             (type ? type: "undef"), why2);
11490
11491         /* This is convoluted and evil ("goto considered harmful")
11492          * but I do not understand the intricacies of all the different
11493          * failure modes of %^H in here.  The goal here is to make
11494          * the most probable error message user-friendly. --jhi */
11495
11496         goto msgdone;
11497
11498     report:
11499         msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
11500                             (type ? type: "undef"), why1, why2, why3);
11501     msgdone:
11502         yyerror(SvPVX_const(msg));
11503         SvREFCNT_dec(msg);
11504         return sv;
11505     }
11506
11507     /* charnames doesn't work well if there have been errors found */
11508     if (PL_error_count > 0 && strEQ(key,"charnames"))
11509         return &PL_sv_undef;
11510
11511     cvp = hv_fetch(table, key, keylen, FALSE);
11512     if (!cvp || !SvOK(*cvp)) {
11513         why1 = "$^H{";
11514         why2 = key;
11515         why3 = "} is not defined";
11516         goto report;
11517     }
11518     sv_2mortal(sv);                     /* Parent created it permanently */
11519     cv = *cvp;
11520     if (!pv && s)
11521         pv = newSVpvn_flags(s, len, SVs_TEMP);
11522     if (type && pv)
11523         typesv = newSVpvn_flags(type, typelen, SVs_TEMP);
11524     else
11525         typesv = &PL_sv_undef;
11526
11527     PUSHSTACKi(PERLSI_OVERLOAD);
11528     ENTER ;
11529     SAVETMPS;
11530
11531     PUSHMARK(SP) ;
11532     EXTEND(sp, 3);
11533     if (pv)
11534         PUSHs(pv);
11535     PUSHs(sv);
11536     if (pv)
11537         PUSHs(typesv);
11538     PUTBACK;
11539     call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
11540
11541     SPAGAIN ;
11542
11543     /* Check the eval first */
11544     if (!PL_in_eval && SvTRUE(ERRSV)) {
11545         sv_catpvs(ERRSV, "Propagated");
11546         yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
11547         (void)POPs;
11548         res = SvREFCNT_inc_simple(sv);
11549     }
11550     else {
11551         res = POPs;
11552         SvREFCNT_inc_simple_void(res);
11553     }
11554
11555     PUTBACK ;
11556     FREETMPS ;
11557     LEAVE ;
11558     POPSTACK;
11559
11560     if (!SvOK(res)) {
11561         why1 = "Call to &{$^H{";
11562         why2 = key;
11563         why3 = "}} did not return a defined value";
11564         sv = res;
11565         goto report;
11566     }
11567
11568     return res;
11569 }
11570
11571 /* Returns a NUL terminated string, with the length of the string written to
11572    *slp
11573    */
11574 STATIC char *
11575 S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
11576 {
11577     dVAR;
11578     register char *d = dest;
11579     register char * const e = d + destlen - 3;  /* two-character token, ending NUL */
11580
11581     PERL_ARGS_ASSERT_SCAN_WORD;
11582
11583     for (;;) {
11584         if (d >= e)
11585             Perl_croak(aTHX_ ident_too_long);
11586         if (isALNUM(*s))        /* UTF handled below */
11587             *d++ = *s++;
11588         else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
11589             *d++ = ':';
11590             *d++ = ':';
11591             s++;
11592         }
11593         else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
11594             *d++ = *s++;
11595             *d++ = *s++;
11596         }
11597         else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
11598             char *t = s + UTF8SKIP(s);
11599             size_t len;
11600             while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
11601                 t += UTF8SKIP(t);
11602             len = t - s;
11603             if (d + len > e)
11604                 Perl_croak(aTHX_ ident_too_long);
11605             Copy(s, d, len, char);
11606             d += len;
11607             s = t;
11608         }
11609         else {
11610             *d = '\0';
11611             *slp = d - dest;
11612             return s;
11613         }
11614     }
11615 }
11616
11617 STATIC char *
11618 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
11619 {
11620     dVAR;
11621     char *bracket = NULL;
11622     char funny = *s++;
11623     register char *d = dest;
11624     register char * const e = d + destlen - 3;    /* two-character token, ending NUL */
11625
11626     PERL_ARGS_ASSERT_SCAN_IDENT;
11627
11628     if (isSPACE(*s))
11629         s = PEEKSPACE(s);
11630     if (isDIGIT(*s)) {
11631         while (isDIGIT(*s)) {
11632             if (d >= e)
11633                 Perl_croak(aTHX_ ident_too_long);
11634             *d++ = *s++;
11635         }
11636     }
11637     else {
11638         for (;;) {
11639             if (d >= e)
11640                 Perl_croak(aTHX_ ident_too_long);
11641             if (isALNUM(*s))    /* UTF handled below */
11642                 *d++ = *s++;
11643             else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
11644                 *d++ = ':';
11645                 *d++ = ':';
11646                 s++;
11647             }
11648             else if (*s == ':' && s[1] == ':') {
11649                 *d++ = *s++;
11650                 *d++ = *s++;
11651             }
11652             else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
11653                 char *t = s + UTF8SKIP(s);
11654                 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
11655                     t += UTF8SKIP(t);
11656                 if (d + (t - s) > e)
11657                     Perl_croak(aTHX_ ident_too_long);
11658                 Copy(s, d, t - s, char);
11659                 d += t - s;
11660                 s = t;
11661             }
11662             else
11663                 break;
11664         }
11665     }
11666     *d = '\0';
11667     d = dest;
11668     if (*d) {
11669         if (PL_lex_state != LEX_NORMAL)
11670             PL_lex_state = LEX_INTERPENDMAYBE;
11671         return s;
11672     }
11673     if (*s == '$' && s[1] &&
11674         (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
11675     {
11676         return s;
11677     }
11678     if (*s == '{') {
11679         bracket = s;
11680         s++;
11681     }
11682     else if (ck_uni)
11683         check_uni();
11684     if (s < send)
11685         *d = *s++;
11686     d[1] = '\0';
11687     if (*d == '^' && *s && isCONTROLVAR(*s)) {
11688         *d = toCTRL(*s);
11689         s++;
11690     }
11691     if (bracket) {
11692         if (isSPACE(s[-1])) {
11693             while (s < send) {
11694                 const char ch = *s++;
11695                 if (!SPACE_OR_TAB(ch)) {
11696                     *d = ch;
11697                     break;
11698                 }
11699             }
11700         }
11701         if (isIDFIRST_lazy_if(d,UTF)) {
11702             d++;
11703             if (UTF) {
11704                 char *end = s;
11705                 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
11706                     end += UTF8SKIP(end);
11707                     while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
11708                         end += UTF8SKIP(end);
11709                 }
11710                 Copy(s, d, end - s, char);
11711                 d += end - s;
11712                 s = end;
11713             }
11714             else {
11715                 while ((isALNUM(*s) || *s == ':') && d < e)
11716                     *d++ = *s++;
11717                 if (d >= e)
11718                     Perl_croak(aTHX_ ident_too_long);
11719             }
11720             *d = '\0';
11721             while (s < send && SPACE_OR_TAB(*s))
11722                 s++;
11723             if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
11724                 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
11725                     const char * const brack =
11726                         (const char *)
11727                         ((*s == '[') ? "[...]" : "{...}");
11728                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
11729                         "Ambiguous use of %c{%s%s} resolved to %c%s%s",
11730                         funny, dest, brack, funny, dest, brack);
11731                 }
11732                 bracket++;
11733                 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
11734                 return s;
11735             }
11736         }
11737         /* Handle extended ${^Foo} variables
11738          * 1999-02-27 mjd-perl-patch@plover.com */
11739         else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
11740                  && isALNUM(*s))
11741         {
11742             d++;
11743             while (isALNUM(*s) && d < e) {
11744                 *d++ = *s++;
11745             }
11746             if (d >= e)
11747                 Perl_croak(aTHX_ ident_too_long);
11748             *d = '\0';
11749         }
11750         if (*s == '}') {
11751             s++;
11752             if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
11753                 PL_lex_state = LEX_INTERPEND;
11754                 PL_expect = XREF;
11755             }
11756             if (PL_lex_state == LEX_NORMAL) {
11757                 if (ckWARN(WARN_AMBIGUOUS) &&
11758                     (keyword(dest, d - dest, 0)
11759                      || get_cvn_flags(dest, d - dest, 0)))
11760                 {
11761                     if (funny == '#')
11762                         funny = '@';
11763                     Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
11764                         "Ambiguous use of %c{%s} resolved to %c%s",
11765                         funny, dest, funny, dest);
11766                 }
11767             }
11768         }
11769         else {
11770             s = bracket;                /* let the parser handle it */
11771             *dest = '\0';
11772         }
11773     }
11774     else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
11775         PL_lex_state = LEX_INTERPEND;
11776     return s;
11777 }
11778
11779 static U32
11780 S_pmflag(U32 pmfl, const char ch) {
11781     switch (ch) {
11782         CASE_STD_PMMOD_FLAGS_PARSE_SET(&pmfl);
11783     case GLOBAL_PAT_MOD:    pmfl |= PMf_GLOBAL; break;
11784     case CONTINUE_PAT_MOD:  pmfl |= PMf_CONTINUE; break;
11785     case ONCE_PAT_MOD:      pmfl |= PMf_KEEP; break;
11786     case KEEPCOPY_PAT_MOD:  pmfl |= PMf_KEEPCOPY; break;
11787     }
11788     return pmfl;
11789 }
11790
11791 void
11792 Perl_pmflag(pTHX_ U32* pmfl, int ch)
11793 {
11794     PERL_ARGS_ASSERT_PMFLAG;
11795
11796     Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED),
11797                      "Perl_pmflag() is deprecated, and will be removed from the XS API");
11798
11799     if (ch<256) {
11800         *pmfl = S_pmflag(*pmfl, (char)ch);
11801     }
11802 }
11803
11804 STATIC char *
11805 S_scan_pat(pTHX_ char *start, I32 type)
11806 {
11807     dVAR;
11808     PMOP *pm;
11809     char *s = scan_str(start,!!PL_madskills,FALSE);
11810     const char * const valid_flags =
11811         (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
11812 #ifdef PERL_MAD
11813     char *modstart;
11814 #endif
11815
11816     PERL_ARGS_ASSERT_SCAN_PAT;
11817
11818     if (!s) {
11819         const char * const delimiter = skipspace(start);
11820         Perl_croak(aTHX_
11821                    (const char *)
11822                    (*delimiter == '?'
11823                     ? "Search pattern not terminated or ternary operator parsed as search pattern"
11824                     : "Search pattern not terminated" ));
11825     }
11826
11827     pm = (PMOP*)newPMOP(type, 0);
11828     if (PL_multi_open == '?') {
11829         /* This is the only point in the code that sets PMf_ONCE:  */
11830         pm->op_pmflags |= PMf_ONCE;
11831
11832         /* Hence it's safe to do this bit of PMOP book-keeping here, which
11833            allows us to restrict the list needed by reset to just the ??
11834            matches.  */
11835         assert(type != OP_TRANS);
11836         if (PL_curstash) {
11837             MAGIC *mg = mg_find((const SV *)PL_curstash, PERL_MAGIC_symtab);
11838             U32 elements;
11839             if (!mg) {
11840                 mg = sv_magicext(MUTABLE_SV(PL_curstash), 0, PERL_MAGIC_symtab, 0, 0,
11841                                  0);
11842             }
11843             elements = mg->mg_len / sizeof(PMOP**);
11844             Renewc(mg->mg_ptr, elements + 1, PMOP*, char);
11845             ((PMOP**)mg->mg_ptr) [elements++] = pm;
11846             mg->mg_len = elements * sizeof(PMOP**);
11847             PmopSTASH_set(pm,PL_curstash);
11848         }
11849     }
11850 #ifdef PERL_MAD
11851     modstart = s;
11852 #endif
11853     while (*s && strchr(valid_flags, *s))
11854         pm->op_pmflags = S_pmflag(pm->op_pmflags, *s++);
11855 #ifdef PERL_MAD
11856     if (PL_madskills && modstart != s) {
11857         SV* tmptoken = newSVpvn(modstart, s - modstart);
11858         append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
11859     }
11860 #endif
11861     /* issue a warning if /c is specified,but /g is not */
11862     if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
11863     {
11864         Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), 
11865                        "Use of /c modifier is meaningless without /g" );
11866     }
11867
11868     PL_lex_op = (OP*)pm;
11869     pl_yylval.ival = OP_MATCH;
11870     return s;
11871 }
11872
11873 STATIC char *
11874 S_scan_subst(pTHX_ char *start)
11875 {
11876     dVAR;
11877     register char *s;
11878     register PMOP *pm;
11879     I32 first_start;
11880     I32 es = 0;
11881 #ifdef PERL_MAD
11882     char *modstart;
11883 #endif
11884
11885     PERL_ARGS_ASSERT_SCAN_SUBST;
11886
11887     pl_yylval.ival = OP_NULL;
11888
11889     s = scan_str(start,!!PL_madskills,FALSE);
11890
11891     if (!s)
11892         Perl_croak(aTHX_ "Substitution pattern not terminated");
11893
11894     if (s[-1] == PL_multi_open)
11895         s--;
11896 #ifdef PERL_MAD
11897     if (PL_madskills) {
11898         CURMAD('q', PL_thisopen);
11899         CURMAD('_', PL_thiswhite);
11900         CURMAD('E', PL_thisstuff);
11901         CURMAD('Q', PL_thisclose);
11902         PL_realtokenstart = s - SvPVX(PL_linestr);
11903     }
11904 #endif
11905
11906     first_start = PL_multi_start;
11907     s = scan_str(s,!!PL_madskills,FALSE);
11908     if (!s) {
11909         if (PL_lex_stuff) {
11910             SvREFCNT_dec(PL_lex_stuff);
11911             PL_lex_stuff = NULL;
11912         }
11913         Perl_croak(aTHX_ "Substitution replacement not terminated");
11914     }
11915     PL_multi_start = first_start;       /* so whole substitution is taken together */
11916
11917     pm = (PMOP*)newPMOP(OP_SUBST, 0);
11918
11919 #ifdef PERL_MAD
11920     if (PL_madskills) {
11921         CURMAD('z', PL_thisopen);
11922         CURMAD('R', PL_thisstuff);
11923         CURMAD('Z', PL_thisclose);
11924     }
11925     modstart = s;
11926 #endif
11927
11928     while (*s) {
11929         if (*s == EXEC_PAT_MOD) {
11930             s++;
11931             es++;
11932         }
11933         else if (strchr(S_PAT_MODS, *s))
11934             pm->op_pmflags = S_pmflag(pm->op_pmflags, *s++);
11935         else
11936             break;
11937     }
11938
11939 #ifdef PERL_MAD
11940     if (PL_madskills) {
11941         if (modstart != s)
11942             curmad('m', newSVpvn(modstart, s - modstart));
11943         append_madprops(PL_thismad, (OP*)pm, 0);
11944         PL_thismad = 0;
11945     }
11946 #endif
11947     if ((pm->op_pmflags & PMf_CONTINUE)) {
11948         Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
11949     }
11950
11951     if (es) {
11952         SV * const repl = newSVpvs("");
11953
11954         PL_sublex_info.super_bufptr = s;
11955         PL_sublex_info.super_bufend = PL_bufend;
11956         PL_multi_end = 0;
11957         pm->op_pmflags |= PMf_EVAL;
11958         while (es-- > 0) {
11959             if (es)
11960                 sv_catpvs(repl, "eval ");
11961             else
11962                 sv_catpvs(repl, "do ");
11963         }
11964         sv_catpvs(repl, "{");
11965         sv_catsv(repl, PL_lex_repl);
11966         if (strchr(SvPVX(PL_lex_repl), '#'))
11967             sv_catpvs(repl, "\n");
11968         sv_catpvs(repl, "}");
11969         SvEVALED_on(repl);
11970         SvREFCNT_dec(PL_lex_repl);
11971         PL_lex_repl = repl;
11972     }
11973
11974     PL_lex_op = (OP*)pm;
11975     pl_yylval.ival = OP_SUBST;
11976     return s;
11977 }
11978
11979 STATIC char *
11980 S_scan_trans(pTHX_ char *start)
11981 {
11982     dVAR;
11983     register char* s;
11984     OP *o;
11985     short *tbl;
11986     U8 squash;
11987     U8 del;
11988     U8 complement;
11989 #ifdef PERL_MAD
11990     char *modstart;
11991 #endif
11992
11993     PERL_ARGS_ASSERT_SCAN_TRANS;
11994
11995     pl_yylval.ival = OP_NULL;
11996
11997     s = scan_str(start,!!PL_madskills,FALSE);
11998     if (!s)
11999         Perl_croak(aTHX_ "Transliteration pattern not terminated");
12000
12001     if (s[-1] == PL_multi_open)
12002         s--;
12003 #ifdef PERL_MAD
12004     if (PL_madskills) {
12005         CURMAD('q', PL_thisopen);
12006         CURMAD('_', PL_thiswhite);
12007         CURMAD('E', PL_thisstuff);
12008         CURMAD('Q', PL_thisclose);
12009         PL_realtokenstart = s - SvPVX(PL_linestr);
12010     }
12011 #endif
12012
12013     s = scan_str(s,!!PL_madskills,FALSE);
12014     if (!s) {
12015         if (PL_lex_stuff) {
12016             SvREFCNT_dec(PL_lex_stuff);
12017             PL_lex_stuff = NULL;
12018         }
12019         Perl_croak(aTHX_ "Transliteration replacement not terminated");
12020     }
12021     if (PL_madskills) {
12022         CURMAD('z', PL_thisopen);
12023         CURMAD('R', PL_thisstuff);
12024         CURMAD('Z', PL_thisclose);
12025     }
12026
12027     complement = del = squash = 0;
12028 #ifdef PERL_MAD
12029     modstart = s;
12030 #endif
12031     while (1) {
12032         switch (*s) {
12033         case 'c':
12034             complement = OPpTRANS_COMPLEMENT;
12035             break;
12036         case 'd':
12037             del = OPpTRANS_DELETE;
12038             break;
12039         case 's':
12040             squash = OPpTRANS_SQUASH;
12041             break;
12042         default:
12043             goto no_more;
12044         }
12045         s++;
12046     }
12047   no_more:
12048
12049     tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
12050     o = newPVOP(OP_TRANS, 0, (char*)tbl);
12051     o->op_private &= ~OPpTRANS_ALL;
12052     o->op_private |= del|squash|complement|
12053       (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
12054       (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF   : 0);
12055
12056     PL_lex_op = o;
12057     pl_yylval.ival = OP_TRANS;
12058
12059 #ifdef PERL_MAD
12060     if (PL_madskills) {
12061         if (modstart != s)
12062             curmad('m', newSVpvn(modstart, s - modstart));
12063         append_madprops(PL_thismad, o, 0);
12064         PL_thismad = 0;
12065     }
12066 #endif
12067
12068     return s;
12069 }
12070
12071 STATIC char *
12072 S_scan_heredoc(pTHX_ register char *s)
12073 {
12074     dVAR;
12075     SV *herewas;
12076     I32 op_type = OP_SCALAR;
12077     I32 len;
12078     SV *tmpstr;
12079     char term;
12080     const char *found_newline;
12081     register char *d;
12082     register char *e;
12083     char *peek;
12084     const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
12085 #ifdef PERL_MAD
12086     I32 stuffstart = s - SvPVX(PL_linestr);
12087     char *tstart;
12088  
12089     PL_realtokenstart = -1;
12090 #endif
12091
12092     PERL_ARGS_ASSERT_SCAN_HEREDOC;
12093
12094     s += 2;
12095     d = PL_tokenbuf;
12096     e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
12097     if (!outer)
12098         *d++ = '\n';
12099     peek = s;
12100     while (SPACE_OR_TAB(*peek))
12101         peek++;
12102     if (*peek == '`' || *peek == '\'' || *peek =='"') {
12103         s = peek;
12104         term = *s++;
12105         s = delimcpy(d, e, s, PL_bufend, term, &len);
12106         d += len;
12107         if (s < PL_bufend)
12108             s++;
12109     }
12110     else {
12111         if (*s == '\\')
12112             s++, term = '\'';
12113         else
12114             term = '"';
12115         if (!isALNUM_lazy_if(s,UTF))
12116             deprecate("bare << to mean <<\"\"");
12117         for (; isALNUM_lazy_if(s,UTF); s++) {
12118             if (d < e)
12119                 *d++ = *s;
12120         }
12121     }
12122     if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
12123         Perl_croak(aTHX_ "Delimiter for here document is too long");
12124     *d++ = '\n';
12125     *d = '\0';
12126     len = d - PL_tokenbuf;
12127
12128 #ifdef PERL_MAD
12129     if (PL_madskills) {
12130         tstart = PL_tokenbuf + !outer;
12131         PL_thisclose = newSVpvn(tstart, len - !outer);
12132         tstart = SvPVX(PL_linestr) + stuffstart;
12133         PL_thisopen = newSVpvn(tstart, s - tstart);
12134         stuffstart = s - SvPVX(PL_linestr);
12135     }
12136 #endif
12137 #ifndef PERL_STRICT_CR
12138     d = strchr(s, '\r');
12139     if (d) {
12140         char * const olds = s;
12141         s = d;
12142         while (s < PL_bufend) {
12143             if (*s == '\r') {
12144                 *d++ = '\n';
12145                 if (*++s == '\n')
12146                     s++;
12147             }
12148             else if (*s == '\n' && s[1] == '\r') {      /* \015\013 on a mac? */
12149                 *d++ = *s++;
12150                 s++;
12151             }
12152             else
12153                 *d++ = *s++;
12154         }
12155         *d = '\0';
12156         PL_bufend = d;
12157         SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
12158         s = olds;
12159     }
12160 #endif
12161 #ifdef PERL_MAD
12162     found_newline = 0;
12163 #endif
12164     if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
12165         herewas = newSVpvn(s,PL_bufend-s);
12166     }
12167     else {
12168 #ifdef PERL_MAD
12169         herewas = newSVpvn(s-1,found_newline-s+1);
12170 #else
12171         s--;
12172         herewas = newSVpvn(s,found_newline-s);
12173 #endif
12174     }
12175 #ifdef PERL_MAD
12176     if (PL_madskills) {
12177         tstart = SvPVX(PL_linestr) + stuffstart;
12178         if (PL_thisstuff)
12179             sv_catpvn(PL_thisstuff, tstart, s - tstart);
12180         else
12181             PL_thisstuff = newSVpvn(tstart, s - tstart);
12182     }
12183 #endif
12184     s += SvCUR(herewas);
12185
12186 #ifdef PERL_MAD
12187     stuffstart = s - SvPVX(PL_linestr);
12188
12189     if (found_newline)
12190         s--;
12191 #endif
12192
12193     tmpstr = newSV_type(SVt_PVIV);
12194     SvGROW(tmpstr, 80);
12195     if (term == '\'') {
12196         op_type = OP_CONST;
12197         SvIV_set(tmpstr, -1);
12198     }
12199     else if (term == '`') {
12200         op_type = OP_BACKTICK;
12201         SvIV_set(tmpstr, '\\');
12202     }
12203
12204     CLINE;
12205     PL_multi_start = CopLINE(PL_curcop);
12206     PL_multi_open = PL_multi_close = '<';
12207     term = *PL_tokenbuf;
12208     if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
12209         char * const bufptr = PL_sublex_info.super_bufptr;
12210         char * const bufend = PL_sublex_info.super_bufend;
12211         char * const olds = s - SvCUR(herewas);
12212         s = strchr(bufptr, '\n');
12213         if (!s)
12214             s = bufend;
12215         d = s;
12216         while (s < bufend &&
12217           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
12218             if (*s++ == '\n')
12219                 CopLINE_inc(PL_curcop);
12220         }
12221         if (s >= bufend) {
12222             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
12223             missingterm(PL_tokenbuf);
12224         }
12225         sv_setpvn(herewas,bufptr,d-bufptr+1);
12226         sv_setpvn(tmpstr,d+1,s-d);
12227         s += len - 1;
12228         sv_catpvn(herewas,s,bufend-s);
12229         Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
12230
12231         s = olds;
12232         goto retval;
12233     }
12234     else if (!outer) {
12235         d = s;
12236         while (s < PL_bufend &&
12237           (*s != term || memNE(s,PL_tokenbuf,len)) ) {
12238             if (*s++ == '\n')
12239                 CopLINE_inc(PL_curcop);
12240         }
12241         if (s >= PL_bufend) {
12242             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
12243             missingterm(PL_tokenbuf);
12244         }
12245         sv_setpvn(tmpstr,d+1,s-d);
12246 #ifdef PERL_MAD
12247         if (PL_madskills) {
12248             if (PL_thisstuff)
12249                 sv_catpvn(PL_thisstuff, d + 1, s - d);
12250             else
12251                 PL_thisstuff = newSVpvn(d + 1, s - d);
12252             stuffstart = s - SvPVX(PL_linestr);
12253         }
12254 #endif
12255         s += len - 1;
12256         CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
12257
12258         sv_catpvn(herewas,s,PL_bufend-s);
12259         sv_setsv(PL_linestr,herewas);
12260         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
12261         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12262         PL_last_lop = PL_last_uni = NULL;
12263     }
12264     else
12265         sv_setpvs(tmpstr,"");   /* avoid "uninitialized" warning */
12266     while (s >= PL_bufend) {    /* multiple line string? */
12267 #ifdef PERL_MAD
12268         if (PL_madskills) {
12269             tstart = SvPVX(PL_linestr) + stuffstart;
12270             if (PL_thisstuff)
12271                 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
12272             else
12273                 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
12274         }
12275 #endif
12276         PL_bufptr = s;
12277         CopLINE_inc(PL_curcop);
12278         if (!outer || !lex_next_chunk(0)) {
12279             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
12280             missingterm(PL_tokenbuf);
12281         }
12282         CopLINE_dec(PL_curcop);
12283         s = PL_bufptr;
12284 #ifdef PERL_MAD
12285         stuffstart = s - SvPVX(PL_linestr);
12286 #endif
12287         CopLINE_inc(PL_curcop);
12288         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12289         PL_last_lop = PL_last_uni = NULL;
12290 #ifndef PERL_STRICT_CR
12291         if (PL_bufend - PL_linestart >= 2) {
12292             if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
12293                 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
12294             {
12295                 PL_bufend[-2] = '\n';
12296                 PL_bufend--;
12297                 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
12298             }
12299             else if (PL_bufend[-1] == '\r')
12300                 PL_bufend[-1] = '\n';
12301         }
12302         else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
12303             PL_bufend[-1] = '\n';
12304 #endif
12305         if (*s == term && memEQ(s,PL_tokenbuf,len)) {
12306             STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
12307             *(SvPVX(PL_linestr) + off ) = ' ';
12308             sv_catsv(PL_linestr,herewas);
12309             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
12310             s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
12311         }
12312         else {
12313             s = PL_bufend;
12314             sv_catsv(tmpstr,PL_linestr);
12315         }
12316     }
12317     s++;
12318 retval:
12319     PL_multi_end = CopLINE(PL_curcop);
12320     if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
12321         SvPV_shrink_to_cur(tmpstr);
12322     }
12323     SvREFCNT_dec(herewas);
12324     if (!IN_BYTES) {
12325         if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
12326             SvUTF8_on(tmpstr);
12327         else if (PL_encoding)
12328             sv_recode_to_utf8(tmpstr, PL_encoding);
12329     }
12330     PL_lex_stuff = tmpstr;
12331     pl_yylval.ival = op_type;
12332     return s;
12333 }
12334
12335 /* scan_inputsymbol
12336    takes: current position in input buffer
12337    returns: new position in input buffer
12338    side-effects: pl_yylval and lex_op are set.
12339
12340    This code handles:
12341
12342    <>           read from ARGV
12343    <FH>         read from filehandle
12344    <pkg::FH>    read from package qualified filehandle
12345    <pkg'FH>     read from package qualified filehandle
12346    <$fh>        read from filehandle in $fh
12347    <*.h>        filename glob
12348
12349 */
12350
12351 STATIC char *
12352 S_scan_inputsymbol(pTHX_ char *start)
12353 {
12354     dVAR;
12355     register char *s = start;           /* current position in buffer */
12356     char *end;
12357     I32 len;
12358     char *d = PL_tokenbuf;                                      /* start of temp holding space */
12359     const char * const e = PL_tokenbuf + sizeof PL_tokenbuf;    /* end of temp holding space */
12360
12361     PERL_ARGS_ASSERT_SCAN_INPUTSYMBOL;
12362
12363     end = strchr(s, '\n');
12364     if (!end)
12365         end = PL_bufend;
12366     s = delimcpy(d, e, s + 1, end, '>', &len);  /* extract until > */
12367
12368     /* die if we didn't have space for the contents of the <>,
12369        or if it didn't end, or if we see a newline
12370     */
12371
12372     if (len >= (I32)sizeof PL_tokenbuf)
12373         Perl_croak(aTHX_ "Excessively long <> operator");
12374     if (s >= end)
12375         Perl_croak(aTHX_ "Unterminated <> operator");
12376
12377     s++;
12378
12379     /* check for <$fh>
12380        Remember, only scalar variables are interpreted as filehandles by
12381        this code.  Anything more complex (e.g., <$fh{$num}>) will be
12382        treated as a glob() call.
12383        This code makes use of the fact that except for the $ at the front,
12384        a scalar variable and a filehandle look the same.
12385     */
12386     if (*d == '$' && d[1]) d++;
12387
12388     /* allow <Pkg'VALUE> or <Pkg::VALUE> */
12389     while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
12390         d++;
12391
12392     /* If we've tried to read what we allow filehandles to look like, and
12393        there's still text left, then it must be a glob() and not a getline.
12394        Use scan_str to pull out the stuff between the <> and treat it
12395        as nothing more than a string.
12396     */
12397
12398     if (d - PL_tokenbuf != len) {
12399         pl_yylval.ival = OP_GLOB;
12400         s = scan_str(start,!!PL_madskills,FALSE);
12401         if (!s)
12402            Perl_croak(aTHX_ "Glob not terminated");
12403         return s;
12404     }
12405     else {
12406         bool readline_overriden = FALSE;
12407         GV *gv_readline;
12408         GV **gvp;
12409         /* we're in a filehandle read situation */
12410         d = PL_tokenbuf;
12411
12412         /* turn <> into <ARGV> */
12413         if (!len)
12414             Copy("ARGV",d,5,char);
12415
12416         /* Check whether readline() is overriden */
12417         gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
12418         if ((gv_readline
12419                 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
12420                 ||
12421                 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
12422                  && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
12423                 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
12424             readline_overriden = TRUE;
12425
12426         /* if <$fh>, create the ops to turn the variable into a
12427            filehandle
12428         */
12429         if (*d == '$') {
12430             /* try to find it in the pad for this block, otherwise find
12431                add symbol table ops
12432             */
12433             const PADOFFSET tmp = pad_findmy(d, len, 0);
12434             if (tmp != NOT_IN_PAD) {
12435                 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
12436                     HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
12437                     HEK * const stashname = HvNAME_HEK(stash);
12438                     SV * const sym = sv_2mortal(newSVhek(stashname));
12439                     sv_catpvs(sym, "::");
12440                     sv_catpv(sym, d+1);
12441                     d = SvPVX(sym);
12442                     goto intro_sym;
12443                 }
12444                 else {
12445                     OP * const o = newOP(OP_PADSV, 0);
12446                     o->op_targ = tmp;
12447                     PL_lex_op = readline_overriden
12448                         ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
12449                                 append_elem(OP_LIST, o,
12450                                     newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
12451                         : (OP*)newUNOP(OP_READLINE, 0, o);
12452                 }
12453             }
12454             else {
12455                 GV *gv;
12456                 ++d;
12457 intro_sym:
12458                 gv = gv_fetchpv(d,
12459                                 (PL_in_eval
12460                                  ? (GV_ADDMULTI | GV_ADDINEVAL)
12461                                  : GV_ADDMULTI),
12462                                 SVt_PV);
12463                 PL_lex_op = readline_overriden
12464                     ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
12465                             append_elem(OP_LIST,
12466                                 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
12467                                 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
12468                     : (OP*)newUNOP(OP_READLINE, 0,
12469                             newUNOP(OP_RV2SV, 0,
12470                                 newGVOP(OP_GV, 0, gv)));
12471             }
12472             if (!readline_overriden)
12473                 PL_lex_op->op_flags |= OPf_SPECIAL;
12474             /* we created the ops in PL_lex_op, so make pl_yylval.ival a null op */
12475             pl_yylval.ival = OP_NULL;
12476         }
12477
12478         /* If it's none of the above, it must be a literal filehandle
12479            (<Foo::BAR> or <FOO>) so build a simple readline OP */
12480         else {
12481             GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
12482             PL_lex_op = readline_overriden
12483                 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
12484                         append_elem(OP_LIST,
12485                             newGVOP(OP_GV, 0, gv),
12486                             newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
12487                 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
12488             pl_yylval.ival = OP_NULL;
12489         }
12490     }
12491
12492     return s;
12493 }
12494
12495
12496 /* scan_str
12497    takes: start position in buffer
12498           keep_quoted preserve \ on the embedded delimiter(s)
12499           keep_delims preserve the delimiters around the string
12500    returns: position to continue reading from buffer
12501    side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
12502         updates the read buffer.
12503
12504    This subroutine pulls a string out of the input.  It is called for:
12505         q               single quotes           q(literal text)
12506         '               single quotes           'literal text'
12507         qq              double quotes           qq(interpolate $here please)
12508         "               double quotes           "interpolate $here please"
12509         qx              backticks               qx(/bin/ls -l)
12510         `               backticks               `/bin/ls -l`
12511         qw              quote words             @EXPORT_OK = qw( func() $spam )
12512         m//             regexp match            m/this/
12513         s///            regexp substitute       s/this/that/
12514         tr///           string transliterate    tr/this/that/
12515         y///            string transliterate    y/this/that/
12516         ($*@)           sub prototypes          sub foo ($)
12517         (stuff)         sub attr parameters     sub foo : attr(stuff)
12518         <>              readline or globs       <FOO>, <>, <$fh>, or <*.c>
12519         
12520    In most of these cases (all but <>, patterns and transliterate)
12521    yylex() calls scan_str().  m// makes yylex() call scan_pat() which
12522    calls scan_str().  s/// makes yylex() call scan_subst() which calls
12523    scan_str().  tr/// and y/// make yylex() call scan_trans() which
12524    calls scan_str().
12525
12526    It skips whitespace before the string starts, and treats the first
12527    character as the delimiter.  If the delimiter is one of ([{< then
12528    the corresponding "close" character )]}> is used as the closing
12529    delimiter.  It allows quoting of delimiters, and if the string has
12530    balanced delimiters ([{<>}]) it allows nesting.
12531
12532    On success, the SV with the resulting string is put into lex_stuff or,
12533    if that is already non-NULL, into lex_repl. The second case occurs only
12534    when parsing the RHS of the special constructs s/// and tr/// (y///).
12535    For convenience, the terminating delimiter character is stuffed into
12536    SvIVX of the SV.
12537 */
12538
12539 STATIC char *
12540 S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
12541 {
12542     dVAR;
12543     SV *sv;                             /* scalar value: string */
12544     const char *tmps;                   /* temp string, used for delimiter matching */
12545     register char *s = start;           /* current position in the buffer */
12546     register char term;                 /* terminating character */
12547     register char *to;                  /* current position in the sv's data */
12548     I32 brackets = 1;                   /* bracket nesting level */
12549     bool has_utf8 = FALSE;              /* is there any utf8 content? */
12550     I32 termcode;                       /* terminating char. code */
12551     U8 termstr[UTF8_MAXBYTES];          /* terminating string */
12552     STRLEN termlen;                     /* length of terminating string */
12553     int last_off = 0;                   /* last position for nesting bracket */
12554 #ifdef PERL_MAD
12555     int stuffstart;
12556     char *tstart;
12557 #endif
12558
12559     PERL_ARGS_ASSERT_SCAN_STR;
12560
12561     /* skip space before the delimiter */
12562     if (isSPACE(*s)) {
12563         s = PEEKSPACE(s);
12564     }
12565
12566 #ifdef PERL_MAD
12567     if (PL_realtokenstart >= 0) {
12568         stuffstart = PL_realtokenstart;
12569         PL_realtokenstart = -1;
12570     }
12571     else
12572         stuffstart = start - SvPVX(PL_linestr);
12573 #endif
12574     /* mark where we are, in case we need to report errors */
12575     CLINE;
12576
12577     /* after skipping whitespace, the next character is the terminator */
12578     term = *s;
12579     if (!UTF) {
12580         termcode = termstr[0] = term;
12581         termlen = 1;
12582     }
12583     else {
12584         termcode = utf8_to_uvchr((U8*)s, &termlen);
12585         Copy(s, termstr, termlen, U8);
12586         if (!UTF8_IS_INVARIANT(term))
12587             has_utf8 = TRUE;
12588     }
12589
12590     /* mark where we are */
12591     PL_multi_start = CopLINE(PL_curcop);
12592     PL_multi_open = term;
12593
12594     /* find corresponding closing delimiter */
12595     if (term && (tmps = strchr("([{< )]}> )]}>",term)))
12596         termcode = termstr[0] = term = tmps[5];
12597
12598     PL_multi_close = term;
12599
12600     /* create a new SV to hold the contents.  79 is the SV's initial length.
12601        What a random number. */
12602     sv = newSV_type(SVt_PVIV);
12603     SvGROW(sv, 80);
12604     SvIV_set(sv, termcode);
12605     (void)SvPOK_only(sv);               /* validate pointer */
12606
12607     /* move past delimiter and try to read a complete string */
12608     if (keep_delims)
12609         sv_catpvn(sv, s, termlen);
12610     s += termlen;
12611 #ifdef PERL_MAD
12612     tstart = SvPVX(PL_linestr) + stuffstart;
12613     if (!PL_thisopen && !keep_delims) {
12614         PL_thisopen = newSVpvn(tstart, s - tstart);
12615         stuffstart = s - SvPVX(PL_linestr);
12616     }
12617 #endif
12618     for (;;) {
12619         if (PL_encoding && !UTF) {
12620             bool cont = TRUE;
12621
12622             while (cont) {
12623                 int offset = s - SvPVX_const(PL_linestr);
12624                 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
12625                                            &offset, (char*)termstr, termlen);
12626                 const char * const ns = SvPVX_const(PL_linestr) + offset;
12627                 char * const svlast = SvEND(sv) - 1;
12628
12629                 for (; s < ns; s++) {
12630                     if (*s == '\n' && !PL_rsfp)
12631                         CopLINE_inc(PL_curcop);
12632                 }
12633                 if (!found)
12634                     goto read_more_line;
12635                 else {
12636                     /* handle quoted delimiters */
12637                     if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
12638                         const char *t;
12639                         for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
12640                             t--;
12641                         if ((svlast-1 - t) % 2) {
12642                             if (!keep_quoted) {
12643                                 *(svlast-1) = term;
12644                                 *svlast = '\0';
12645                                 SvCUR_set(sv, SvCUR(sv) - 1);
12646                             }
12647                             continue;
12648                         }
12649                     }
12650                     if (PL_multi_open == PL_multi_close) {
12651                         cont = FALSE;
12652                     }
12653                     else {
12654                         const char *t;
12655                         char *w;
12656                         for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
12657                             /* At here, all closes are "was quoted" one,
12658                                so we don't check PL_multi_close. */
12659                             if (*t == '\\') {
12660                                 if (!keep_quoted && *(t+1) == PL_multi_open)
12661                                     t++;
12662                                 else
12663                                     *w++ = *t++;
12664                             }
12665                             else if (*t == PL_multi_open)
12666                                 brackets++;
12667
12668                             *w = *t;
12669                         }
12670                         if (w < t) {
12671                             *w++ = term;
12672                             *w = '\0';
12673                             SvCUR_set(sv, w - SvPVX_const(sv));
12674                         }
12675                         last_off = w - SvPVX(sv);
12676                         if (--brackets <= 0)
12677                             cont = FALSE;
12678                     }
12679                 }
12680             }
12681             if (!keep_delims) {
12682                 SvCUR_set(sv, SvCUR(sv) - 1);
12683                 *SvEND(sv) = '\0';
12684             }
12685             break;
12686         }
12687
12688         /* extend sv if need be */
12689         SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
12690         /* set 'to' to the next character in the sv's string */
12691         to = SvPVX(sv)+SvCUR(sv);
12692
12693         /* if open delimiter is the close delimiter read unbridle */
12694         if (PL_multi_open == PL_multi_close) {
12695             for (; s < PL_bufend; s++,to++) {
12696                 /* embedded newlines increment the current line number */
12697                 if (*s == '\n' && !PL_rsfp)
12698                     CopLINE_inc(PL_curcop);
12699                 /* handle quoted delimiters */
12700                 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
12701                     if (!keep_quoted && s[1] == term)
12702                         s++;
12703                 /* any other quotes are simply copied straight through */
12704                     else
12705                         *to++ = *s++;
12706                 }
12707                 /* terminate when run out of buffer (the for() condition), or
12708                    have found the terminator */
12709                 else if (*s == term) {
12710                     if (termlen == 1)
12711                         break;
12712                     if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
12713                         break;
12714                 }
12715                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
12716                     has_utf8 = TRUE;
12717                 *to = *s;
12718             }
12719         }
12720         
12721         /* if the terminator isn't the same as the start character (e.g.,
12722            matched brackets), we have to allow more in the quoting, and
12723            be prepared for nested brackets.
12724         */
12725         else {
12726             /* read until we run out of string, or we find the terminator */
12727             for (; s < PL_bufend; s++,to++) {
12728                 /* embedded newlines increment the line count */
12729                 if (*s == '\n' && !PL_rsfp)
12730                     CopLINE_inc(PL_curcop);
12731                 /* backslashes can escape the open or closing characters */
12732                 if (*s == '\\' && s+1 < PL_bufend) {
12733                     if (!keep_quoted &&
12734                         ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
12735                         s++;
12736                     else
12737                         *to++ = *s++;
12738                 }
12739                 /* allow nested opens and closes */
12740                 else if (*s == PL_multi_close && --brackets <= 0)
12741                     break;
12742                 else if (*s == PL_multi_open)
12743                     brackets++;
12744                 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
12745                     has_utf8 = TRUE;
12746                 *to = *s;
12747             }
12748         }
12749         /* terminate the copied string and update the sv's end-of-string */
12750         *to = '\0';
12751         SvCUR_set(sv, to - SvPVX_const(sv));
12752
12753         /*
12754          * this next chunk reads more into the buffer if we're not done yet
12755          */
12756
12757         if (s < PL_bufend)
12758             break;              /* handle case where we are done yet :-) */
12759
12760 #ifndef PERL_STRICT_CR
12761         if (to - SvPVX_const(sv) >= 2) {
12762             if ((to[-2] == '\r' && to[-1] == '\n') ||
12763                 (to[-2] == '\n' && to[-1] == '\r'))
12764             {
12765                 to[-2] = '\n';
12766                 to--;
12767                 SvCUR_set(sv, to - SvPVX_const(sv));
12768             }
12769             else if (to[-1] == '\r')
12770                 to[-1] = '\n';
12771         }
12772         else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
12773             to[-1] = '\n';
12774 #endif
12775         
12776      read_more_line:
12777         /* if we're out of file, or a read fails, bail and reset the current
12778            line marker so we can report where the unterminated string began
12779         */
12780 #ifdef PERL_MAD
12781         if (PL_madskills) {
12782             char * const tstart = SvPVX(PL_linestr) + stuffstart;
12783             if (PL_thisstuff)
12784                 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
12785             else
12786                 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
12787         }
12788 #endif
12789         CopLINE_inc(PL_curcop);
12790         PL_bufptr = PL_bufend;
12791         if (!lex_next_chunk(0)) {
12792             sv_free(sv);
12793             CopLINE_set(PL_curcop, (line_t)PL_multi_start);
12794             return NULL;
12795         }
12796         s = PL_bufptr;
12797 #ifdef PERL_MAD
12798         stuffstart = 0;
12799 #endif
12800     }
12801
12802     /* at this point, we have successfully read the delimited string */
12803
12804     if (!PL_encoding || UTF) {
12805 #ifdef PERL_MAD
12806         if (PL_madskills) {
12807             char * const tstart = SvPVX(PL_linestr) + stuffstart;
12808             const int len = s - tstart;
12809             if (PL_thisstuff)
12810                 sv_catpvn(PL_thisstuff, tstart, len);
12811             else
12812                 PL_thisstuff = newSVpvn(tstart, len);
12813             if (!PL_thisclose && !keep_delims)
12814                 PL_thisclose = newSVpvn(s,termlen);
12815         }
12816 #endif
12817
12818         if (keep_delims)
12819             sv_catpvn(sv, s, termlen);
12820         s += termlen;
12821     }
12822 #ifdef PERL_MAD
12823     else {
12824         if (PL_madskills) {
12825             char * const tstart = SvPVX(PL_linestr) + stuffstart;
12826             const int len = s - tstart - termlen;
12827             if (PL_thisstuff)
12828                 sv_catpvn(PL_thisstuff, tstart, len);
12829             else
12830                 PL_thisstuff = newSVpvn(tstart, len);
12831             if (!PL_thisclose && !keep_delims)
12832                 PL_thisclose = newSVpvn(s - termlen,termlen);
12833         }
12834     }
12835 #endif
12836     if (has_utf8 || PL_encoding)
12837         SvUTF8_on(sv);
12838
12839     PL_multi_end = CopLINE(PL_curcop);
12840
12841     /* if we allocated too much space, give some back */
12842     if (SvCUR(sv) + 5 < SvLEN(sv)) {
12843         SvLEN_set(sv, SvCUR(sv) + 1);
12844         SvPV_renew(sv, SvLEN(sv));
12845     }
12846
12847     /* decide whether this is the first or second quoted string we've read
12848        for this op
12849     */
12850
12851     if (PL_lex_stuff)
12852         PL_lex_repl = sv;
12853     else
12854         PL_lex_stuff = sv;
12855     return s;
12856 }
12857
12858 /*
12859   scan_num
12860   takes: pointer to position in buffer
12861   returns: pointer to new position in buffer
12862   side-effects: builds ops for the constant in pl_yylval.op
12863
12864   Read a number in any of the formats that Perl accepts:
12865
12866   \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*)      12 12.34 12.
12867   \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*)                     .34
12868   0b[01](_?[01])*
12869   0[0-7](_?[0-7])*
12870   0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
12871
12872   Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
12873   thing it reads.
12874
12875   If it reads a number without a decimal point or an exponent, it will
12876   try converting the number to an integer and see if it can do so
12877   without loss of precision.
12878 */
12879
12880 char *
12881 Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
12882 {
12883     dVAR;
12884     register const char *s = start;     /* current position in buffer */
12885     register char *d;                   /* destination in temp buffer */
12886     register char *e;                   /* end of temp buffer */
12887     NV nv;                              /* number read, as a double */
12888     SV *sv = NULL;                      /* place to put the converted number */
12889     bool floatit;                       /* boolean: int or float? */
12890     const char *lastub = NULL;          /* position of last underbar */
12891     static char const number_too_long[] = "Number too long";
12892
12893     PERL_ARGS_ASSERT_SCAN_NUM;
12894
12895     /* We use the first character to decide what type of number this is */
12896
12897     switch (*s) {
12898     default:
12899       Perl_croak(aTHX_ "panic: scan_num");
12900
12901     /* if it starts with a 0, it could be an octal number, a decimal in
12902        0.13 disguise, or a hexadecimal number, or a binary number. */
12903     case '0':
12904         {
12905           /* variables:
12906              u          holds the "number so far"
12907              shift      the power of 2 of the base
12908                         (hex == 4, octal == 3, binary == 1)
12909              overflowed was the number more than we can hold?
12910
12911              Shift is used when we add a digit.  It also serves as an "are
12912              we in octal/hex/binary?" indicator to disallow hex characters
12913              when in octal mode.
12914            */
12915             NV n = 0.0;
12916             UV u = 0;
12917             I32 shift;
12918             bool overflowed = FALSE;
12919             bool just_zero  = TRUE;     /* just plain 0 or binary number? */
12920             static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
12921             static const char* const bases[5] =
12922               { "", "binary", "", "octal", "hexadecimal" };
12923             static const char* const Bases[5] =
12924               { "", "Binary", "", "Octal", "Hexadecimal" };
12925             static const char* const maxima[5] =
12926               { "",
12927                 "0b11111111111111111111111111111111",
12928                 "",
12929                 "037777777777",
12930                 "0xffffffff" };
12931             const char *base, *Base, *max;
12932
12933             /* check for hex */
12934             if (s[1] == 'x') {
12935                 shift = 4;
12936                 s += 2;
12937                 just_zero = FALSE;
12938             } else if (s[1] == 'b') {
12939                 shift = 1;
12940                 s += 2;
12941                 just_zero = FALSE;
12942             }
12943             /* check for a decimal in disguise */
12944             else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
12945                 goto decimal;
12946             /* so it must be octal */
12947             else {
12948                 shift = 3;
12949                 s++;
12950             }
12951
12952             if (*s == '_') {
12953                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12954                                "Misplaced _ in number");
12955                lastub = s++;
12956             }
12957
12958             base = bases[shift];
12959             Base = Bases[shift];
12960             max  = maxima[shift];
12961
12962             /* read the rest of the number */
12963             for (;;) {
12964                 /* x is used in the overflow test,
12965                    b is the digit we're adding on. */
12966                 UV x, b;
12967
12968                 switch (*s) {
12969
12970                 /* if we don't mention it, we're done */
12971                 default:
12972                     goto out;
12973
12974                 /* _ are ignored -- but warned about if consecutive */
12975                 case '_':
12976                     if (lastub && s == lastub + 1)
12977                         Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12978                                        "Misplaced _ in number");
12979                     lastub = s++;
12980                     break;
12981
12982                 /* 8 and 9 are not octal */
12983                 case '8': case '9':
12984                     if (shift == 3)
12985                         yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
12986                     /* FALL THROUGH */
12987
12988                 /* octal digits */
12989                 case '2': case '3': case '4':
12990                 case '5': case '6': case '7':
12991                     if (shift == 1)
12992                         yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
12993                     /* FALL THROUGH */
12994
12995                 case '0': case '1':
12996                     b = *s++ & 15;              /* ASCII digit -> value of digit */
12997                     goto digit;
12998
12999                 /* hex digits */
13000                 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
13001                 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
13002                     /* make sure they said 0x */
13003                     if (shift != 4)
13004                         goto out;
13005                     b = (*s++ & 7) + 9;
13006
13007                     /* Prepare to put the digit we have onto the end
13008                        of the number so far.  We check for overflows.
13009                     */
13010
13011                   digit:
13012                     just_zero = FALSE;
13013                     if (!overflowed) {
13014                         x = u << shift; /* make room for the digit */
13015
13016                         if ((x >> shift) != u
13017                             && !(PL_hints & HINT_NEW_BINARY)) {
13018                             overflowed = TRUE;
13019                             n = (NV) u;
13020                             Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
13021                                              "Integer overflow in %s number",
13022                                              base);
13023                         } else
13024                             u = x | b;          /* add the digit to the end */
13025                     }
13026                     if (overflowed) {
13027                         n *= nvshift[shift];
13028                         /* If an NV has not enough bits in its
13029                          * mantissa to represent an UV this summing of
13030                          * small low-order numbers is a waste of time
13031                          * (because the NV cannot preserve the
13032                          * low-order bits anyway): we could just
13033                          * remember when did we overflow and in the
13034                          * end just multiply n by the right
13035                          * amount. */
13036                         n += (NV) b;
13037                     }
13038                     break;
13039                 }
13040             }
13041
13042           /* if we get here, we had success: make a scalar value from
13043              the number.
13044           */
13045           out:
13046
13047             /* final misplaced underbar check */
13048             if (s[-1] == '_') {
13049                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
13050             }
13051
13052             sv = newSV(0);
13053             if (overflowed) {
13054                 if (n > 4294967295.0)
13055                     Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
13056                                    "%s number > %s non-portable",
13057                                    Base, max);
13058                 sv_setnv(sv, n);
13059             }
13060             else {
13061 #if UVSIZE > 4
13062                 if (u > 0xffffffff)
13063                     Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
13064                                    "%s number > %s non-portable",
13065                                    Base, max);
13066 #endif
13067                 sv_setuv(sv, u);
13068             }
13069             if (just_zero && (PL_hints & HINT_NEW_INTEGER))
13070                 sv = new_constant(start, s - start, "integer",
13071                                   sv, NULL, NULL, 0);
13072             else if (PL_hints & HINT_NEW_BINARY)
13073                 sv = new_constant(start, s - start, "binary", sv, NULL, NULL, 0);
13074         }
13075         break;
13076
13077     /*
13078       handle decimal numbers.
13079       we're also sent here when we read a 0 as the first digit
13080     */
13081     case '1': case '2': case '3': case '4': case '5':
13082     case '6': case '7': case '8': case '9': case '.':
13083       decimal:
13084         d = PL_tokenbuf;
13085         e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
13086         floatit = FALSE;
13087
13088         /* read next group of digits and _ and copy into d */
13089         while (isDIGIT(*s) || *s == '_') {
13090             /* skip underscores, checking for misplaced ones
13091                if -w is on
13092             */
13093             if (*s == '_') {
13094                 if (lastub && s == lastub + 1)
13095                     Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13096                                    "Misplaced _ in number");
13097                 lastub = s++;
13098             }
13099             else {
13100                 /* check for end of fixed-length buffer */
13101                 if (d >= e)
13102                     Perl_croak(aTHX_ number_too_long);
13103                 /* if we're ok, copy the character */
13104                 *d++ = *s++;
13105             }
13106         }
13107
13108         /* final misplaced underbar check */
13109         if (lastub && s == lastub + 1) {
13110             Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
13111         }
13112
13113         /* read a decimal portion if there is one.  avoid
13114            3..5 being interpreted as the number 3. followed
13115            by .5
13116         */
13117         if (*s == '.' && s[1] != '.') {
13118             floatit = TRUE;
13119             *d++ = *s++;
13120
13121             if (*s == '_') {
13122                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13123                                "Misplaced _ in number");
13124                 lastub = s;
13125             }
13126
13127             /* copy, ignoring underbars, until we run out of digits.
13128             */
13129             for (; isDIGIT(*s) || *s == '_'; s++) {
13130                 /* fixed length buffer check */
13131                 if (d >= e)
13132                     Perl_croak(aTHX_ number_too_long);
13133                 if (*s == '_') {
13134                    if (lastub && s == lastub + 1)
13135                        Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13136                                       "Misplaced _ in number");
13137                    lastub = s;
13138                 }
13139                 else
13140                     *d++ = *s;
13141             }
13142             /* fractional part ending in underbar? */
13143             if (s[-1] == '_') {
13144                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13145                                "Misplaced _ in number");
13146             }
13147             if (*s == '.' && isDIGIT(s[1])) {
13148                 /* oops, it's really a v-string, but without the "v" */
13149                 s = start;
13150                 goto vstring;
13151             }
13152         }
13153
13154         /* read exponent part, if present */
13155         if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
13156             floatit = TRUE;
13157             s++;
13158
13159             /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
13160             *d++ = 'e';         /* At least some Mach atof()s don't grok 'E' */
13161
13162             /* stray preinitial _ */
13163             if (*s == '_') {
13164                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13165                                "Misplaced _ in number");
13166                 lastub = s++;
13167             }
13168
13169             /* allow positive or negative exponent */
13170             if (*s == '+' || *s == '-')
13171                 *d++ = *s++;
13172
13173             /* stray initial _ */
13174             if (*s == '_') {
13175                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13176                                "Misplaced _ in number");
13177                 lastub = s++;
13178             }
13179
13180             /* read digits of exponent */
13181             while (isDIGIT(*s) || *s == '_') {
13182                 if (isDIGIT(*s)) {
13183                     if (d >= e)
13184                         Perl_croak(aTHX_ number_too_long);
13185                     *d++ = *s++;
13186                 }
13187                 else {
13188                    if (((lastub && s == lastub + 1) ||
13189                         (!isDIGIT(s[1]) && s[1] != '_')))
13190                        Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
13191                                       "Misplaced _ in number");
13192                    lastub = s++;
13193                 }
13194             }
13195         }
13196
13197
13198         /* make an sv from the string */
13199         sv = newSV(0);
13200
13201         /*
13202            We try to do an integer conversion first if no characters
13203            indicating "float" have been found.
13204          */
13205
13206         if (!floatit) {
13207             UV uv;
13208             const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
13209
13210             if (flags == IS_NUMBER_IN_UV) {
13211               if (uv <= IV_MAX)
13212                 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
13213               else
13214                 sv_setuv(sv, uv);
13215             } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
13216               if (uv <= (UV) IV_MIN)
13217                 sv_setiv(sv, -(IV)uv);
13218               else
13219                 floatit = TRUE;
13220             } else
13221               floatit = TRUE;
13222         }
13223         if (floatit) {
13224             /* terminate the string */
13225             *d = '\0';
13226             nv = Atof(PL_tokenbuf);
13227             sv_setnv(sv, nv);
13228         }
13229
13230         if ( floatit
13231              ? (PL_hints & HINT_NEW_FLOAT) : (PL_hints & HINT_NEW_INTEGER) ) {
13232             const char *const key = floatit ? "float" : "integer";
13233             const STRLEN keylen = floatit ? 5 : 7;
13234             sv = S_new_constant(aTHX_ PL_tokenbuf, d - PL_tokenbuf,
13235                                 key, keylen, sv, NULL, NULL, 0);
13236         }
13237         break;
13238
13239     /* if it starts with a v, it could be a v-string */
13240     case 'v':
13241 vstring:
13242                 sv = newSV(5); /* preallocate storage space */
13243                 s = scan_vstring(s, PL_bufend, sv);
13244         break;
13245     }
13246
13247     /* make the op for the constant and return */
13248
13249     if (sv)
13250         lvalp->opval = newSVOP(OP_CONST, 0, sv);
13251     else
13252         lvalp->opval = NULL;
13253
13254     return (char *)s;
13255 }
13256
13257 STATIC char *
13258 S_scan_formline(pTHX_ register char *s)
13259 {
13260     dVAR;
13261     register char *eol;
13262     register char *t;
13263     SV * const stuff = newSVpvs("");
13264     bool needargs = FALSE;
13265     bool eofmt = FALSE;
13266 #ifdef PERL_MAD
13267     char *tokenstart = s;
13268     SV* savewhite = NULL;
13269
13270     if (PL_madskills) {
13271         savewhite = PL_thiswhite;
13272         PL_thiswhite = 0;
13273     }
13274 #endif
13275
13276     PERL_ARGS_ASSERT_SCAN_FORMLINE;
13277
13278     while (!needargs) {
13279         if (*s == '.') {
13280             t = s+1;
13281 #ifdef PERL_STRICT_CR
13282             while (SPACE_OR_TAB(*t))
13283                 t++;
13284 #else
13285             while (SPACE_OR_TAB(*t) || *t == '\r')
13286                 t++;
13287 #endif
13288             if (*t == '\n' || t == PL_bufend) {
13289                 eofmt = TRUE;
13290                 break;
13291             }
13292         }
13293         if (PL_in_eval && !PL_rsfp) {
13294             eol = (char *) memchr(s,'\n',PL_bufend-s);
13295             if (!eol++)
13296                 eol = PL_bufend;
13297         }
13298         else
13299             eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
13300         if (*s != '#') {
13301             for (t = s; t < eol; t++) {
13302                 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
13303                     needargs = FALSE;
13304                     goto enough;        /* ~~ must be first line in formline */
13305                 }
13306                 if (*t == '@' || *t == '^')
13307                     needargs = TRUE;
13308             }
13309             if (eol > s) {
13310                 sv_catpvn(stuff, s, eol-s);
13311 #ifndef PERL_STRICT_CR
13312                 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
13313                     char *end = SvPVX(stuff) + SvCUR(stuff);
13314                     end[-2] = '\n';
13315                     end[-1] = '\0';
13316                     SvCUR_set(stuff, SvCUR(stuff) - 1);
13317                 }
13318 #endif
13319             }
13320             else
13321               break;
13322         }
13323         s = (char*)eol;
13324         if (PL_rsfp) {
13325             bool got_some;
13326 #ifdef PERL_MAD
13327             if (PL_madskills) {
13328                 if (PL_thistoken)
13329                     sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
13330                 else
13331                     PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
13332             }
13333 #endif
13334             PL_bufptr = PL_bufend;
13335             CopLINE_inc(PL_curcop);
13336             got_some = lex_next_chunk(0);
13337             CopLINE_dec(PL_curcop);
13338             s = PL_bufptr;
13339 #ifdef PERL_MAD
13340             tokenstart = PL_bufptr;
13341 #endif
13342             if (!got_some)
13343                 break;
13344         }
13345         incline(s);
13346     }
13347   enough:
13348     if (SvCUR(stuff)) {
13349         PL_expect = XTERM;
13350         if (needargs) {
13351             PL_lex_state = LEX_NORMAL;
13352             start_force(PL_curforce);
13353             NEXTVAL_NEXTTOKE.ival = 0;
13354             force_next(',');
13355         }
13356         else
13357             PL_lex_state = LEX_FORMLINE;
13358         if (!IN_BYTES) {
13359             if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
13360                 SvUTF8_on(stuff);
13361             else if (PL_encoding)
13362                 sv_recode_to_utf8(stuff, PL_encoding);
13363         }
13364         start_force(PL_curforce);
13365         NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
13366         force_next(THING);
13367         start_force(PL_curforce);
13368         NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
13369         force_next(LSTOP);
13370     }
13371     else {
13372         SvREFCNT_dec(stuff);
13373         if (eofmt)
13374             PL_lex_formbrack = 0;
13375         PL_bufptr = s;
13376     }
13377 #ifdef PERL_MAD
13378     if (PL_madskills) {
13379         if (PL_thistoken)
13380             sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
13381         else
13382             PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
13383         PL_thiswhite = savewhite;
13384     }
13385 #endif
13386     return s;
13387 }
13388
13389 I32
13390 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
13391 {
13392     dVAR;
13393     const I32 oldsavestack_ix = PL_savestack_ix;
13394     CV* const outsidecv = PL_compcv;
13395
13396     if (PL_compcv) {
13397         assert(SvTYPE(PL_compcv) == SVt_PVCV);
13398     }
13399     SAVEI32(PL_subline);
13400     save_item(PL_subname);
13401     SAVESPTR(PL_compcv);
13402
13403     PL_compcv = MUTABLE_CV(newSV_type(is_format ? SVt_PVFM : SVt_PVCV));
13404     CvFLAGS(PL_compcv) |= flags;
13405
13406     PL_subline = CopLINE(PL_curcop);
13407     CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
13408     CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv));
13409     CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
13410
13411     return oldsavestack_ix;
13412 }
13413
13414 #ifdef __SC__
13415 #pragma segment Perl_yylex
13416 #endif
13417 static int
13418 S_yywarn(pTHX_ const char *const s)
13419 {
13420     dVAR;
13421
13422     PERL_ARGS_ASSERT_YYWARN;
13423
13424     PL_in_eval |= EVAL_WARNONLY;
13425     yyerror(s);
13426     PL_in_eval &= ~EVAL_WARNONLY;
13427     return 0;
13428 }
13429
13430 int
13431 Perl_yyerror(pTHX_ const char *const s)
13432 {
13433     dVAR;
13434     const char *where = NULL;
13435     const char *context = NULL;
13436     int contlen = -1;
13437     SV *msg;
13438     int yychar  = PL_parser->yychar;
13439
13440     PERL_ARGS_ASSERT_YYERROR;
13441
13442     if (!yychar || (yychar == ';' && !PL_rsfp))
13443         where = "at EOF";
13444     else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
13445       PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
13446       PL_oldbufptr != PL_bufptr) {
13447         /*
13448                 Only for NetWare:
13449                 The code below is removed for NetWare because it abends/crashes on NetWare
13450                 when the script has error such as not having the closing quotes like:
13451                     if ($var eq "value)
13452                 Checking of white spaces is anyway done in NetWare code.
13453         */
13454 #ifndef NETWARE
13455         while (isSPACE(*PL_oldoldbufptr))
13456             PL_oldoldbufptr++;
13457 #endif
13458         context = PL_oldoldbufptr;
13459         contlen = PL_bufptr - PL_oldoldbufptr;
13460     }
13461     else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
13462       PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
13463         /*
13464                 Only for NetWare:
13465                 The code below is removed for NetWare because it abends/crashes on NetWare
13466                 when the script has error such as not having the closing quotes like:
13467                     if ($var eq "value)
13468                 Checking of white spaces is anyway done in NetWare code.
13469         */
13470 #ifndef NETWARE
13471         while (isSPACE(*PL_oldbufptr))
13472             PL_oldbufptr++;
13473 #endif
13474         context = PL_oldbufptr;
13475         contlen = PL_bufptr - PL_oldbufptr;
13476     }
13477     else if (yychar > 255)
13478         where = "next token ???";
13479     else if (yychar == -2) { /* YYEMPTY */
13480         if (PL_lex_state == LEX_NORMAL ||
13481            (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
13482             where = "at end of line";
13483         else if (PL_lex_inpat)
13484             where = "within pattern";
13485         else
13486             where = "within string";
13487     }
13488     else {
13489         SV * const where_sv = newSVpvs_flags("next char ", SVs_TEMP);
13490         if (yychar < 32)
13491             Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
13492         else if (isPRINT_LC(yychar)) {
13493             const char string = yychar;
13494             sv_catpvn(where_sv, &string, 1);
13495         }
13496         else
13497             Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
13498         where = SvPVX_const(where_sv);
13499     }
13500     msg = sv_2mortal(newSVpv(s, 0));
13501     Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
13502         OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
13503     if (context)
13504         Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
13505     else
13506         Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
13507     if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
13508         Perl_sv_catpvf(aTHX_ msg,
13509         "  (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
13510                 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
13511         PL_multi_end = 0;
13512     }
13513     if (PL_in_eval & EVAL_WARNONLY) {
13514         Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
13515     }
13516     else
13517         qerror(msg);
13518     if (PL_error_count >= 10) {
13519         if (PL_in_eval && SvCUR(ERRSV))
13520             Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
13521                        SVfARG(ERRSV), OutCopFILE(PL_curcop));
13522         else
13523             Perl_croak(aTHX_ "%s has too many errors.\n",
13524             OutCopFILE(PL_curcop));
13525     }
13526     PL_in_my = 0;
13527     PL_in_my_stash = NULL;
13528     return 0;
13529 }
13530 #ifdef __SC__
13531 #pragma segment Main
13532 #endif
13533
13534 STATIC char*
13535 S_swallow_bom(pTHX_ U8 *s)
13536 {
13537     dVAR;
13538     const STRLEN slen = SvCUR(PL_linestr);
13539
13540     PERL_ARGS_ASSERT_SWALLOW_BOM;
13541
13542     switch (s[0]) {
13543     case 0xFF:
13544         if (s[1] == 0xFE) {
13545             /* UTF-16 little-endian? (or UTF-32LE?) */
13546             if (s[2] == 0 && s[3] == 0)  /* UTF-32 little-endian */
13547                 Perl_croak(aTHX_ "Unsupported script encoding UTF-32LE");
13548 #ifndef PERL_NO_UTF16_FILTER
13549             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (BOM)\n");
13550             s += 2;
13551             if (PL_bufend > (char*)s) {
13552                 s = add_utf16_textfilter(s, TRUE);
13553             }
13554 #else
13555             Perl_croak(aTHX_ "Unsupported script encoding UTF-16LE");
13556 #endif
13557         }
13558         break;
13559     case 0xFE:
13560         if (s[1] == 0xFF) {   /* UTF-16 big-endian? */
13561 #ifndef PERL_NO_UTF16_FILTER
13562             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
13563             s += 2;
13564             if (PL_bufend > (char *)s) {
13565                 s = add_utf16_textfilter(s, FALSE);
13566             }
13567 #else
13568             Perl_croak(aTHX_ "Unsupported script encoding UTF-16BE");
13569 #endif
13570         }
13571         break;
13572     case 0xEF:
13573         if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
13574             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
13575             s += 3;                      /* UTF-8 */
13576         }
13577         break;
13578     case 0:
13579         if (slen > 3) {
13580              if (s[1] == 0) {
13581                   if (s[2] == 0xFE && s[3] == 0xFF) {
13582                        /* UTF-32 big-endian */
13583                        Perl_croak(aTHX_ "Unsupported script encoding UTF-32BE");
13584                   }
13585              }
13586              else if (s[2] == 0 && s[3] != 0) {
13587                   /* Leading bytes
13588                    * 00 xx 00 xx
13589                    * are a good indicator of UTF-16BE. */
13590 #ifndef PERL_NO_UTF16_FILTER
13591                   if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
13592                   s = add_utf16_textfilter(s, FALSE);
13593 #else
13594                   Perl_croak(aTHX_ "Unsupported script encoding UTF-16BE");
13595 #endif
13596              }
13597         }
13598 #ifdef EBCDIC
13599     case 0xDD:
13600         if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
13601             if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
13602             s += 4;                      /* UTF-8 */
13603         }
13604         break;
13605 #endif
13606
13607     default:
13608          if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
13609                   /* Leading bytes
13610                    * xx 00 xx 00
13611                    * are a good indicator of UTF-16LE. */
13612 #ifndef PERL_NO_UTF16_FILTER
13613               if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
13614               s = add_utf16_textfilter(s, TRUE);
13615 #else
13616               Perl_croak(aTHX_ "Unsupported script encoding UTF-16LE");
13617 #endif
13618          }
13619     }
13620     return (char*)s;
13621 }
13622
13623
13624 #ifndef PERL_NO_UTF16_FILTER
13625 static I32
13626 S_utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
13627 {
13628     dVAR;
13629     SV *const filter = FILTER_DATA(idx);
13630     /* We re-use this each time round, throwing the contents away before we
13631        return.  */
13632     SV *const utf16_buffer = MUTABLE_SV(IoTOP_GV(filter));
13633     SV *const utf8_buffer = filter;
13634     IV status = IoPAGE(filter);
13635     const bool reverse = (bool) IoLINES(filter);
13636     I32 retval;
13637
13638     /* As we're automatically added, at the lowest level, and hence only called
13639        from this file, we can be sure that we're not called in block mode. Hence
13640        don't bother writing code to deal with block mode.  */
13641     if (maxlen) {
13642         Perl_croak(aTHX_ "panic: utf16_textfilter called in block mode (for %d characters)", maxlen);
13643     }
13644     if (status < 0) {
13645         Perl_croak(aTHX_ "panic: utf16_textfilter called after error (status=%"IVdf")", status);
13646     }
13647     DEBUG_P(PerlIO_printf(Perl_debug_log,
13648                           "utf16_textfilter(%p,%ce): idx=%d maxlen=%d status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n",
13649                           FPTR2DPTR(void *, S_utf16_textfilter),
13650                           reverse ? 'l' : 'b', idx, maxlen, status,
13651                           (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer)));
13652
13653     while (1) {
13654         STRLEN chars;
13655         STRLEN have;
13656         I32 newlen;
13657         U8 *end;
13658         /* First, look in our buffer of existing UTF-8 data:  */
13659         char *nl = (char *)memchr(SvPVX(utf8_buffer), '\n', SvCUR(utf8_buffer));
13660
13661         if (nl) {
13662             ++nl;
13663         } else if (status == 0) {
13664             /* EOF */
13665             IoPAGE(filter) = 0;
13666             nl = SvEND(utf8_buffer);
13667         }
13668         if (nl) {
13669             STRLEN got = nl - SvPVX(utf8_buffer);
13670             /* Did we have anything to append?  */
13671             retval = got != 0;
13672             sv_catpvn(sv, SvPVX(utf8_buffer), got);
13673             /* Everything else in this code works just fine if SVp_POK isn't
13674                set.  This, however, needs it, and we need it to work, else
13675                we loop infinitely because the buffer is never consumed.  */
13676             sv_chop(utf8_buffer, nl);
13677             break;
13678         }
13679
13680         /* OK, not a complete line there, so need to read some more UTF-16.
13681            Read an extra octect if the buffer currently has an odd number. */
13682         while (1) {
13683             if (status <= 0)
13684                 break;
13685             if (SvCUR(utf16_buffer) >= 2) {
13686                 /* Location of the high octet of the last complete code point.
13687                    Gosh, UTF-16 is a pain. All the benefits of variable length,
13688                    *coupled* with all the benefits of partial reads and
13689                    endianness.  */
13690                 const U8 *const last_hi = (U8*)SvPVX(utf16_buffer)
13691                     + ((SvCUR(utf16_buffer) & ~1) - (reverse ? 1 : 2));
13692
13693                 if (*last_hi < 0xd8 || *last_hi > 0xdb) {
13694                     break;
13695                 }
13696
13697                 /* We have the first half of a surrogate. Read more.  */
13698                 DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter partial surrogate detected at %p\n", last_hi));
13699             }
13700
13701             status = FILTER_READ(idx + 1, utf16_buffer,
13702                                  160 + (SvCUR(utf16_buffer) & 1));
13703             DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter status=%"IVdf" SvCUR(sv)=%"UVuf"\n", status, (UV)SvCUR(utf16_buffer)));
13704             DEBUG_P({ sv_dump(utf16_buffer); sv_dump(utf8_buffer);});
13705             if (status < 0) {
13706                 /* Error */
13707                 IoPAGE(filter) = status;
13708                 return status;
13709             }
13710         }
13711
13712         chars = SvCUR(utf16_buffer) >> 1;
13713         have = SvCUR(utf8_buffer);
13714         SvGROW(utf8_buffer, have + chars * 3 + 1);
13715
13716         if (reverse) {
13717             end = utf16_to_utf8_reversed((U8*)SvPVX(utf16_buffer),
13718                                          (U8*)SvPVX_const(utf8_buffer) + have,
13719                                          chars * 2, &newlen);
13720         } else {
13721             end = utf16_to_utf8((U8*)SvPVX(utf16_buffer),
13722                                 (U8*)SvPVX_const(utf8_buffer) + have,
13723                                 chars * 2, &newlen);
13724         }
13725         SvCUR_set(utf8_buffer, have + newlen);
13726         *end = '\0';
13727
13728         /* No need to keep this SV "well-formed" with a '\0' after the end, as
13729            it's private to us, and utf16_to_utf8{,reversed} take a
13730            (pointer,length) pair, rather than a NUL-terminated string.  */
13731         if(SvCUR(utf16_buffer) & 1) {
13732             *SvPVX(utf16_buffer) = SvEND(utf16_buffer)[-1];
13733             SvCUR_set(utf16_buffer, 1);
13734         } else {
13735             SvCUR_set(utf16_buffer, 0);
13736         }
13737     }
13738     DEBUG_P(PerlIO_printf(Perl_debug_log,
13739                           "utf16_textfilter: returns, status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n",
13740                           status,
13741                           (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer)));
13742     DEBUG_P({ sv_dump(utf8_buffer); sv_dump(sv);});
13743     return retval;
13744 }
13745
13746 static U8 *
13747 S_add_utf16_textfilter(pTHX_ U8 *const s, bool reversed)
13748 {
13749     SV *filter = filter_add(S_utf16_textfilter, NULL);
13750
13751     IoTOP_GV(filter) = MUTABLE_GV(newSVpvn((char *)s, PL_bufend - (char*)s));
13752     sv_setpvs(filter, "");
13753     IoLINES(filter) = reversed;
13754     IoPAGE(filter) = 1; /* Not EOF */
13755
13756     /* Sadly, we have to return a valid pointer, come what may, so we have to
13757        ignore any error return from this.  */
13758     SvCUR_set(PL_linestr, 0);
13759     if (FILTER_READ(0, PL_linestr, 0)) {
13760         SvUTF8_on(PL_linestr);
13761     } else {
13762         SvUTF8_on(PL_linestr);
13763     }
13764     PL_bufend = SvEND(PL_linestr);
13765     return (U8*)SvPVX(PL_linestr);
13766 }
13767 #endif
13768
13769 /*
13770 Returns a pointer to the next character after the parsed
13771 vstring, as well as updating the passed in sv.
13772
13773 Function must be called like
13774
13775         sv = newSV(5);
13776         s = scan_vstring(s,e,sv);
13777
13778 where s and e are the start and end of the string.
13779 The sv should already be large enough to store the vstring
13780 passed in, for performance reasons.
13781
13782 */
13783
13784 char *
13785 Perl_scan_vstring(pTHX_ const char *s, const char *const e, SV *sv)
13786 {
13787     dVAR;
13788     const char *pos = s;
13789     const char *start = s;
13790
13791     PERL_ARGS_ASSERT_SCAN_VSTRING;
13792
13793     if (*pos == 'v') pos++;  /* get past 'v' */
13794     while (pos < e && (isDIGIT(*pos) || *pos == '_'))
13795         pos++;
13796     if ( *pos != '.') {
13797         /* this may not be a v-string if followed by => */
13798         const char *next = pos;
13799         while (next < e && isSPACE(*next))
13800             ++next;
13801         if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
13802             /* return string not v-string */
13803             sv_setpvn(sv,(char *)s,pos-s);
13804             return (char *)pos;
13805         }
13806     }
13807
13808     if (!isALPHA(*pos)) {
13809         U8 tmpbuf[UTF8_MAXBYTES+1];
13810
13811         if (*s == 'v')
13812             s++;  /* get past 'v' */
13813
13814         sv_setpvs(sv, "");
13815
13816         for (;;) {
13817             /* this is atoi() that tolerates underscores */
13818             U8 *tmpend;
13819             UV rev = 0;
13820             const char *end = pos;
13821             UV mult = 1;
13822             while (--end >= s) {
13823                 if (*end != '_') {
13824                     const UV orev = rev;
13825                     rev += (*end - '0') * mult;
13826                     mult *= 10;
13827                     if (orev > rev)
13828                         Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
13829                                          "Integer overflow in decimal number");
13830                 }
13831             }
13832 #ifdef EBCDIC
13833             if (rev > 0x7FFFFFFF)
13834                  Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
13835 #endif
13836             /* Append native character for the rev point */
13837             tmpend = uvchr_to_utf8(tmpbuf, rev);
13838             sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
13839             if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
13840                  SvUTF8_on(sv);
13841             if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
13842                  s = ++pos;
13843             else {
13844                  s = pos;
13845                  break;
13846             }
13847             while (pos < e && (isDIGIT(*pos) || *pos == '_'))
13848                  pos++;
13849         }
13850         SvPOK_on(sv);
13851         sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
13852         SvRMAGICAL_on(sv);
13853     }
13854     return (char *)s;
13855 }
13856
13857 int
13858 Perl_keyword_plugin_standard(pTHX_
13859         char *keyword_ptr, STRLEN keyword_len, OP **op_ptr)
13860 {
13861     PERL_ARGS_ASSERT_KEYWORD_PLUGIN_STANDARD;
13862     PERL_UNUSED_CONTEXT;
13863     PERL_UNUSED_ARG(keyword_ptr);
13864     PERL_UNUSED_ARG(keyword_len);
13865     PERL_UNUSED_ARG(op_ptr);
13866     return KEYWORD_PLUGIN_DECLINE;
13867 }
13868
13869 /*
13870  * Local variables:
13871  * c-indentation-style: bsd
13872  * c-basic-offset: 4
13873  * indent-tabs-mode: t
13874  * End:
13875  *
13876  * ex: set ts=8 sts=4 sw=4 noet:
13877  */