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