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