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