Move the code related to deprecate("comma-less variable list") into a function.
[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
104 #ifndef PERL_NO_UTF16_FILTER
105 static I32 utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen);
106 static I32 utf16rev_textfilter(pTHX_ int idx, SV *sv, int maxlen);
107 #endif
108
109 #ifdef PERL_MAD
110 #  define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
111 #  define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
112 #else
113 #  define CURMAD(slot,sv)
114 #  define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
115 #endif
116
117 #define XFAKEBRACK 128
118 #define XENUMMASK 127
119
120 #ifdef USE_UTF8_SCRIPTS
121 #   define UTF (!IN_BYTES)
122 #else
123 #   define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
124 #endif
125
126 /* The maximum number of characters preceding the unrecognized one to display */
127 #define UNRECOGNIZED_PRECEDE_COUNT 10
128
129 /* In variables named $^X, these are the legal values for X.
130  * 1999-02-27 mjd-perl-patch@plover.com */
131 #define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
132
133 #define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
134
135 /* LEX_* are values for PL_lex_state, the state of the lexer.
136  * They are arranged oddly so that the guard on the switch statement
137  * can get by with a single comparison (if the compiler is smart enough).
138  */
139
140 /* #define LEX_NOTPARSING               11 is done in perl.h. */
141
142 #define LEX_NORMAL              10 /* normal code (ie not within "...")     */
143 #define LEX_INTERPNORMAL         9 /* code within a string, eg "$foo[$x+1]" */
144 #define LEX_INTERPCASEMOD        8 /* expecting a \U, \Q or \E etc          */
145 #define LEX_INTERPPUSH           7 /* starting a new sublex parse level     */
146 #define LEX_INTERPSTART          6 /* expecting the start of a $var         */
147
148                                    /* at end of code, eg "$x" followed by:  */
149 #define LEX_INTERPEND            5 /* ... eg not one of [, { or ->          */
150 #define LEX_INTERPENDMAYBE       4 /* ... eg one of [, { or ->              */
151
152 #define LEX_INTERPCONCAT         3 /* expecting anything, eg at start of
153                                         string or after \E, $foo, etc       */
154 #define LEX_INTERPCONST          2 /* NOT USED */
155 #define LEX_FORMLINE             1 /* expecting a format line               */
156 #define LEX_KNOWNEXT             0 /* next token known; just return it      */
157
158
159 #ifdef DEBUGGING
160 static const char* const lex_state_names[] = {
161     "KNOWNEXT",
162     "FORMLINE",
163     "INTERPCONST",
164     "INTERPCONCAT",
165     "INTERPENDMAYBE",
166     "INTERPEND",
167     "INTERPSTART",
168     "INTERPPUSH",
169     "INTERPCASEMOD",
170     "INTERPNORMAL",
171     "NORMAL"
172 };
173 #endif
174
175 #ifdef ff_next
176 #undef ff_next
177 #endif
178
179 #include "keywords.h"
180
181 /* CLINE is a macro that ensures PL_copline has a sane value */
182
183 #ifdef CLINE
184 #undef CLINE
185 #endif
186 #define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
187
188 #ifdef PERL_MAD
189 #  define SKIPSPACE0(s) skipspace0(s)
190 #  define SKIPSPACE1(s) skipspace1(s)
191 #  define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
192 #  define PEEKSPACE(s) skipspace2(s,0)
193 #else
194 #  define SKIPSPACE0(s) skipspace(s)
195 #  define SKIPSPACE1(s) skipspace(s)
196 #  define SKIPSPACE2(s,tsv) skipspace(s)
197 #  define PEEKSPACE(s) skipspace(s)
198 #endif
199
200 /*
201  * Convenience functions to return different tokens and prime the
202  * lexer for the next token.  They all take an argument.
203  *
204  * TOKEN        : generic token (used for '(', DOLSHARP, etc)
205  * OPERATOR     : generic operator
206  * AOPERATOR    : assignment operator
207  * PREBLOCK     : beginning the block after an if, while, foreach, ...
208  * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
209  * PREREF       : *EXPR where EXPR is not a simple identifier
210  * TERM         : expression term
211  * LOOPX        : loop exiting command (goto, last, dump, etc)
212  * FTST         : file test operator
213  * FUN0         : zero-argument function
214  * FUN1         : not used, except for not, which isn't a UNIOP
215  * BOop         : bitwise or or xor
216  * BAop         : bitwise and
217  * SHop         : shift operator
218  * PWop         : power operator
219  * PMop         : pattern-matching operator
220  * Aop          : addition-level operator
221  * Mop          : multiplication-level operator
222  * Eop          : equality-testing operator
223  * Rop          : relational operator <= != gt
224  *
225  * Also see LOP and lop() below.
226  */
227
228 #ifdef DEBUGGING /* Serve -DT. */
229 #   define REPORT(retval) tokereport((I32)retval, &pl_yylval)
230 #else
231 #   define REPORT(retval) (retval)
232 #endif
233
234 #define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
235 #define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
236 #define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
237 #define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
238 #define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
239 #define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
240 #define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
241 #define LOOPX(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
242 #define FTST(f)  return (pl_yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
243 #define FUN0(f)  return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
244 #define FUN1(f)  return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
245 #define BOop(f)  return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
246 #define BAop(f)  return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
247 #define SHop(f)  return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
248 #define PWop(f)  return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
249 #define PMop(f)  return(pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
250 #define Aop(f)   return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
251 #define Mop(f)   return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
252 #define Eop(f)   return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
253 #define Rop(f)   return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
254
255 /* This bit of chicanery makes a unary function followed by
256  * a parenthesis into a function with one argument, highest precedence.
257  * The UNIDOR macro is for unary functions that can be followed by the //
258  * operator (such as C<shift // 0>).
259  */
260 #define UNI2(f,x) { \
261         pl_yylval.ival = f; \
262         PL_expect = x; \
263         PL_bufptr = s; \
264         PL_last_uni = PL_oldbufptr; \
265         PL_last_lop_op = f; \
266         if (*s == '(') \
267             return REPORT( (int)FUNC1 ); \
268         s = PEEKSPACE(s); \
269         return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
270         }
271 #define UNI(f)    UNI2(f,XTERM)
272 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
273
274 #define UNIBRACK(f) { \
275         pl_yylval.ival = f; \
276         PL_bufptr = s; \
277         PL_last_uni = PL_oldbufptr; \
278         if (*s == '(') \
279             return REPORT( (int)FUNC1 ); \
280         s = PEEKSPACE(s); \
281         return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
282         }
283
284 /* grandfather return to old style */
285 #define OLDLOP(f) return(pl_yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
286
287 #ifdef DEBUGGING
288
289 /* how to interpret the pl_yylval associated with the token */
290 enum token_type {
291     TOKENTYPE_NONE,
292     TOKENTYPE_IVAL,
293     TOKENTYPE_OPNUM, /* pl_yylval.ival contains an opcode number */
294     TOKENTYPE_PVAL,
295     TOKENTYPE_OPVAL,
296     TOKENTYPE_GVVAL
297 };
298
299 static struct debug_tokens {
300     const int token;
301     enum token_type type;
302     const char *name;
303 } const debug_tokens[] =
304 {
305     { ADDOP,            TOKENTYPE_OPNUM,        "ADDOP" },
306     { ANDAND,           TOKENTYPE_NONE,         "ANDAND" },
307     { ANDOP,            TOKENTYPE_NONE,         "ANDOP" },
308     { ANONSUB,          TOKENTYPE_IVAL,         "ANONSUB" },
309     { ARROW,            TOKENTYPE_NONE,         "ARROW" },
310     { ASSIGNOP,         TOKENTYPE_OPNUM,        "ASSIGNOP" },
311     { BITANDOP,         TOKENTYPE_OPNUM,        "BITANDOP" },
312     { BITOROP,          TOKENTYPE_OPNUM,        "BITOROP" },
313     { COLONATTR,        TOKENTYPE_NONE,         "COLONATTR" },
314     { CONTINUE,         TOKENTYPE_NONE,         "CONTINUE" },
315     { DEFAULT,          TOKENTYPE_NONE,         "DEFAULT" },
316     { DO,               TOKENTYPE_NONE,         "DO" },
317     { DOLSHARP,         TOKENTYPE_NONE,         "DOLSHARP" },
318     { DORDOR,           TOKENTYPE_NONE,         "DORDOR" },
319     { DOROP,            TOKENTYPE_OPNUM,        "DOROP" },
320     { DOTDOT,           TOKENTYPE_IVAL,         "DOTDOT" },
321     { ELSE,             TOKENTYPE_NONE,         "ELSE" },
322     { ELSIF,            TOKENTYPE_IVAL,         "ELSIF" },
323     { EQOP,             TOKENTYPE_OPNUM,        "EQOP" },
324     { FOR,              TOKENTYPE_IVAL,         "FOR" },
325     { FORMAT,           TOKENTYPE_NONE,         "FORMAT" },
326     { FUNC,             TOKENTYPE_OPNUM,        "FUNC" },
327     { FUNC0,            TOKENTYPE_OPNUM,        "FUNC0" },
328     { FUNC0SUB,         TOKENTYPE_OPVAL,        "FUNC0SUB" },
329     { FUNC1,            TOKENTYPE_OPNUM,        "FUNC1" },
330     { FUNCMETH,         TOKENTYPE_OPVAL,        "FUNCMETH" },
331     { GIVEN,            TOKENTYPE_IVAL,         "GIVEN" },
332     { HASHBRACK,        TOKENTYPE_NONE,         "HASHBRACK" },
333     { IF,               TOKENTYPE_IVAL,         "IF" },
334     { LABEL,            TOKENTYPE_PVAL,         "LABEL" },
335     { LOCAL,            TOKENTYPE_IVAL,         "LOCAL" },
336     { LOOPEX,           TOKENTYPE_OPNUM,        "LOOPEX" },
337     { LSTOP,            TOKENTYPE_OPNUM,        "LSTOP" },
338     { LSTOPSUB,         TOKENTYPE_OPVAL,        "LSTOPSUB" },
339     { MATCHOP,          TOKENTYPE_OPNUM,        "MATCHOP" },
340     { METHOD,           TOKENTYPE_OPVAL,        "METHOD" },
341     { MULOP,            TOKENTYPE_OPNUM,        "MULOP" },
342     { MY,               TOKENTYPE_IVAL,         "MY" },
343     { MYSUB,            TOKENTYPE_NONE,         "MYSUB" },
344     { NOAMP,            TOKENTYPE_NONE,         "NOAMP" },
345     { NOTOP,            TOKENTYPE_NONE,         "NOTOP" },
346     { OROP,             TOKENTYPE_IVAL,         "OROP" },
347     { OROR,             TOKENTYPE_NONE,         "OROR" },
348     { PACKAGE,          TOKENTYPE_NONE,         "PACKAGE" },
349     { PMFUNC,           TOKENTYPE_OPVAL,        "PMFUNC" },
350     { POSTDEC,          TOKENTYPE_NONE,         "POSTDEC" },
351     { POSTINC,          TOKENTYPE_NONE,         "POSTINC" },
352     { POWOP,            TOKENTYPE_OPNUM,        "POWOP" },
353     { PREDEC,           TOKENTYPE_NONE,         "PREDEC" },
354     { PREINC,           TOKENTYPE_NONE,         "PREINC" },
355     { PRIVATEREF,       TOKENTYPE_OPVAL,        "PRIVATEREF" },
356     { REFGEN,           TOKENTYPE_NONE,         "REFGEN" },
357     { RELOP,            TOKENTYPE_OPNUM,        "RELOP" },
358     { SHIFTOP,          TOKENTYPE_OPNUM,        "SHIFTOP" },
359     { SUB,              TOKENTYPE_NONE,         "SUB" },
360     { THING,            TOKENTYPE_OPVAL,        "THING" },
361     { UMINUS,           TOKENTYPE_NONE,         "UMINUS" },
362     { UNIOP,            TOKENTYPE_OPNUM,        "UNIOP" },
363     { UNIOPSUB,         TOKENTYPE_OPVAL,        "UNIOPSUB" },
364     { UNLESS,           TOKENTYPE_IVAL,         "UNLESS" },
365     { UNTIL,            TOKENTYPE_IVAL,         "UNTIL" },
366     { USE,              TOKENTYPE_IVAL,         "USE" },
367     { WHEN,             TOKENTYPE_IVAL,         "WHEN" },
368     { WHILE,            TOKENTYPE_IVAL,         "WHILE" },
369     { WORD,             TOKENTYPE_OPVAL,        "WORD" },
370     { YADAYADA,         TOKENTYPE_IVAL,         "YADAYADA" },
371     { 0,                TOKENTYPE_NONE,         NULL }
372 };
373
374 /* dump the returned token in rv, plus any optional arg in pl_yylval */
375
376 STATIC int
377 S_tokereport(pTHX_ I32 rv, const YYSTYPE* lvalp)
378 {
379     dVAR;
380
381     PERL_ARGS_ASSERT_TOKEREPORT;
382
383     if (DEBUG_T_TEST) {
384         const char *name = NULL;
385         enum token_type type = TOKENTYPE_NONE;
386         const struct debug_tokens *p;
387         SV* const report = newSVpvs("<== ");
388
389         for (p = debug_tokens; p->token; p++) {
390             if (p->token == (int)rv) {
391                 name = p->name;
392                 type = p->type;
393                 break;
394             }
395         }
396         if (name)
397             Perl_sv_catpv(aTHX_ report, name);
398         else if ((char)rv > ' ' && (char)rv < '~')
399             Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
400         else if (!rv)
401             sv_catpvs(report, "EOF");
402         else
403             Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
404         switch (type) {
405         case TOKENTYPE_NONE:
406         case TOKENTYPE_GVVAL: /* doesn't appear to be used */
407             break;
408         case TOKENTYPE_IVAL:
409             Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)lvalp->ival);
410             break;
411         case TOKENTYPE_OPNUM:
412             Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
413                                     PL_op_name[lvalp->ival]);
414             break;
415         case TOKENTYPE_PVAL:
416             Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", lvalp->pval);
417             break;
418         case TOKENTYPE_OPVAL:
419             if (lvalp->opval) {
420                 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
421                                     PL_op_name[lvalp->opval->op_type]);
422                 if (lvalp->opval->op_type == OP_CONST) {
423                     Perl_sv_catpvf(aTHX_ report, " %s",
424                         SvPEEK(cSVOPx_sv(lvalp->opval)));
425                 }
426
427             }
428             else
429                 sv_catpvs(report, "(opval=null)");
430             break;
431         }
432         PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
433     };
434     return (int)rv;
435 }
436
437
438 /* print the buffer with suitable escapes */
439
440 STATIC void
441 S_printbuf(pTHX_ const char *const fmt, const char *const s)
442 {
443     SV* const tmp = newSVpvs("");
444
445     PERL_ARGS_ASSERT_PRINTBUF;
446
447     PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
448     SvREFCNT_dec(tmp);
449 }
450
451 #endif
452
453 static int
454 S_deprecate_commaless_var_list(pTHX) {
455     PL_expect = XTERM;
456     deprecate("comma-less variable list");
457     return REPORT(','); /* grandfather non-comma-format format */
458 }
459
460 /*
461  * S_ao
462  *
463  * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
464  * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
465  */
466
467 STATIC int
468 S_ao(pTHX_ int toketype)
469 {
470     dVAR;
471     if (*PL_bufptr == '=') {
472         PL_bufptr++;
473         if (toketype == ANDAND)
474             pl_yylval.ival = OP_ANDASSIGN;
475         else if (toketype == OROR)
476             pl_yylval.ival = OP_ORASSIGN;
477         else if (toketype == DORDOR)
478             pl_yylval.ival = OP_DORASSIGN;
479         toketype = ASSIGNOP;
480     }
481     return toketype;
482 }
483
484 /*
485  * S_no_op
486  * When Perl expects an operator and finds something else, no_op
487  * prints the warning.  It always prints "<something> found where
488  * operator expected.  It prints "Missing semicolon on previous line?"
489  * if the surprise occurs at the start of the line.  "do you need to
490  * predeclare ..." is printed out for code like "sub bar; foo bar $x"
491  * where the compiler doesn't know if foo is a method call or a function.
492  * It prints "Missing operator before end of line" if there's nothing
493  * after the missing operator, or "... before <...>" if there is something
494  * after the missing operator.
495  */
496
497 STATIC void
498 S_no_op(pTHX_ const char *const what, char *s)
499 {
500     dVAR;
501     char * const oldbp = PL_bufptr;
502     const bool is_first = (PL_oldbufptr == PL_linestart);
503
504     PERL_ARGS_ASSERT_NO_OP;
505
506     if (!s)
507         s = oldbp;
508     else
509         PL_bufptr = s;
510     yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
511     if (ckWARN_d(WARN_SYNTAX)) {
512         if (is_first)
513             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
514                     "\t(Missing semicolon on previous line?)\n");
515         else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
516             const char *t;
517             for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
518                 NOOP;
519             if (t < PL_bufptr && isSPACE(*t))
520                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
521                         "\t(Do you need to predeclare %.*s?)\n",
522                     (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
523         }
524         else {
525             assert(s >= oldbp);
526             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
527                     "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
528         }
529     }
530     PL_bufptr = oldbp;
531 }
532
533 /*
534  * S_missingterm
535  * Complain about missing quote/regexp/heredoc terminator.
536  * If it's called with NULL then it cauterizes the line buffer.
537  * If we're in a delimited string and the delimiter is a control
538  * character, it's reformatted into a two-char sequence like ^C.
539  * This is fatal.
540  */
541
542 STATIC void
543 S_missingterm(pTHX_ char *s)
544 {
545     dVAR;
546     char tmpbuf[3];
547     char q;
548     if (s) {
549         char * const nl = strrchr(s,'\n');
550         if (nl)
551             *nl = '\0';
552     }
553     else if (isCNTRL(PL_multi_close)) {
554         *tmpbuf = '^';
555         tmpbuf[1] = (char)toCTRL(PL_multi_close);
556         tmpbuf[2] = '\0';
557         s = tmpbuf;
558     }
559     else {
560         *tmpbuf = (char)PL_multi_close;
561         tmpbuf[1] = '\0';
562         s = tmpbuf;
563     }
564     q = strchr(s,'"') ? '\'' : '"';
565     Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
566 }
567
568 #define FEATURE_IS_ENABLED(name)                                        \
569         ((0 != (PL_hints & HINT_LOCALIZE_HH))                           \
570             && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
571 /* The longest string we pass in.  */
572 #define MAX_FEATURE_LEN (sizeof("switch")-1)
573
574 /*
575  * S_feature_is_enabled
576  * Check whether the named feature is enabled.
577  */
578 STATIC bool
579 S_feature_is_enabled(pTHX_ const char *const name, STRLEN namelen)
580 {
581     dVAR;
582     HV * const hinthv = GvHV(PL_hintgv);
583     char he_name[8 + MAX_FEATURE_LEN] = "feature_";
584
585     PERL_ARGS_ASSERT_FEATURE_IS_ENABLED;
586
587     assert(namelen <= MAX_FEATURE_LEN);
588     memcpy(&he_name[8], name, namelen);
589
590     return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
591 }
592
593 /*
594  * Perl_deprecate
595  */
596
597 void
598 Perl_deprecate(pTHX_ const char *const s)
599 {
600     PERL_ARGS_ASSERT_DEPRECATE;
601
602     Perl_ck_warner(aTHX_ packWARN(WARN_DEPRECATED), "Use of %s is deprecated", s);
603 }
604
605 /*
606  * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
607  * utf16-to-utf8-reversed.
608  */
609
610 #ifdef PERL_CR_FILTER
611 static void
612 strip_return(SV *sv)
613 {
614     register const char *s = SvPVX_const(sv);
615     register const char * const e = s + SvCUR(sv);
616
617     PERL_ARGS_ASSERT_STRIP_RETURN;
618
619     /* outer loop optimized to do nothing if there are no CR-LFs */
620     while (s < e) {
621         if (*s++ == '\r' && *s == '\n') {
622             /* hit a CR-LF, need to copy the rest */
623             register char *d = s - 1;
624             *d++ = *s++;
625             while (s < e) {
626                 if (*s == '\r' && s[1] == '\n')
627                     s++;
628                 *d++ = *s++;
629             }
630             SvCUR(sv) -= s - d;
631             return;
632         }
633     }
634 }
635
636 STATIC I32
637 S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
638 {
639     const I32 count = FILTER_READ(idx+1, sv, maxlen);
640     if (count > 0 && !maxlen)
641         strip_return(sv);
642     return count;
643 }
644 #endif
645
646
647
648 /*
649  * Perl_lex_start
650  *
651  * Create a parser object and initialise its parser and lexer fields
652  *
653  * rsfp       is the opened file handle to read from (if any),
654  *
655  * line       holds any initial content already read from the file (or in
656  *            the case of no file, such as an eval, the whole contents);
657  *
658  * new_filter indicates that this is a new file and it shouldn't inherit
659  *            the filters from the current parser (ie require).
660  */
661
662 void
663 Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, bool new_filter)
664 {
665     dVAR;
666     const char *s = NULL;
667     STRLEN len;
668     yy_parser *parser, *oparser;
669
670     /* create and initialise a parser */
671
672     Newxz(parser, 1, yy_parser);
673     parser->old_parser = oparser = PL_parser;
674     PL_parser = parser;
675
676     Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
677     parser->ps = parser->stack;
678     parser->stack_size = YYINITDEPTH;
679
680     parser->stack->state = 0;
681     parser->yyerrstatus = 0;
682     parser->yychar = YYEMPTY;           /* Cause a token to be read.  */
683
684     /* on scope exit, free this parser and restore any outer one */
685     SAVEPARSER(parser);
686     parser->saved_curcop = PL_curcop;
687
688     /* initialise lexer state */
689
690 #ifdef PERL_MAD
691     parser->curforce = -1;
692 #else
693     parser->nexttoke = 0;
694 #endif
695     parser->error_count = oparser ? oparser->error_count : 0;
696     parser->copline = NOLINE;
697     parser->lex_state = LEX_NORMAL;
698     parser->expect = XSTATE;
699     parser->rsfp = rsfp;
700     parser->rsfp_filters = (new_filter || !oparser) ? newAV()
701                 : MUTABLE_AV(SvREFCNT_inc(oparser->rsfp_filters));
702
703     Newx(parser->lex_brackstack, 120, char);
704     Newx(parser->lex_casestack, 12, char);
705     *parser->lex_casestack = '\0';
706
707     if (line) {
708         s = SvPV_const(line, len);
709     } else {
710         len = 0;
711     }
712
713     if (!len) {
714         parser->linestr = newSVpvs("\n;");
715     } else if (SvREADONLY(line) || s[len-1] != ';') {
716         parser->linestr = newSVsv(line);
717         if (s[len-1] != ';')
718             sv_catpvs(parser->linestr, "\n;");
719     } else {
720         SvTEMP_off(line);
721         SvREFCNT_inc_simple_void_NN(line);
722         parser->linestr = line;
723     }
724     parser->oldoldbufptr =
725         parser->oldbufptr =
726         parser->bufptr =
727         parser->linestart = SvPVX(parser->linestr);
728     parser->bufend = parser->bufptr + SvCUR(parser->linestr);
729     parser->last_lop = parser->last_uni = NULL;
730 }
731
732
733 /* delete a parser object */
734
735 void
736 Perl_parser_free(pTHX_  const yy_parser *parser)
737 {
738     PERL_ARGS_ASSERT_PARSER_FREE;
739
740     PL_curcop = parser->saved_curcop;
741     SvREFCNT_dec(parser->linestr);
742
743     if (parser->rsfp == PerlIO_stdin())
744         PerlIO_clearerr(parser->rsfp);
745     else if (parser->rsfp && (!parser->old_parser ||
746                 (parser->old_parser && parser->rsfp != parser->old_parser->rsfp)))
747         PerlIO_close(parser->rsfp);
748     SvREFCNT_dec(parser->rsfp_filters);
749
750     Safefree(parser->stack);
751     Safefree(parser->lex_brackstack);
752     Safefree(parser->lex_casestack);
753     PL_parser = parser->old_parser;
754     Safefree(parser);
755 }
756
757
758 /*
759  * Perl_lex_end
760  * Finalizer for lexing operations.  Must be called when the parser is
761  * done with the lexer.
762  */
763
764 void
765 Perl_lex_end(pTHX)
766 {
767     dVAR;
768     PL_doextract = FALSE;
769 }
770
771 /*
772  * S_incline
773  * This subroutine has nothing to do with tilting, whether at windmills
774  * or pinball tables.  Its name is short for "increment line".  It
775  * increments the current line number in CopLINE(PL_curcop) and checks
776  * to see whether the line starts with a comment of the form
777  *    # line 500 "foo.pm"
778  * If so, it sets the current line number and file to the values in the comment.
779  */
780
781 STATIC void
782 S_incline(pTHX_ const char *s)
783 {
784     dVAR;
785     const char *t;
786     const char *n;
787     const char *e;
788
789     PERL_ARGS_ASSERT_INCLINE;
790
791     CopLINE_inc(PL_curcop);
792     if (*s++ != '#')
793         return;
794     while (SPACE_OR_TAB(*s))
795         s++;
796     if (strnEQ(s, "line", 4))
797         s += 4;
798     else
799         return;
800     if (SPACE_OR_TAB(*s))
801         s++;
802     else
803         return;
804     while (SPACE_OR_TAB(*s))
805         s++;
806     if (!isDIGIT(*s))
807         return;
808
809     n = s;
810     while (isDIGIT(*s))
811         s++;
812     if (!SPACE_OR_TAB(*s) && *s != '\r' && *s != '\n' && *s != '\0')
813         return;
814     while (SPACE_OR_TAB(*s))
815         s++;
816     if (*s == '"' && (t = strchr(s+1, '"'))) {
817         s++;
818         e = t + 1;
819     }
820     else {
821         t = s;
822         while (!isSPACE(*t))
823             t++;
824         e = t;
825     }
826     while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
827         e++;
828     if (*e != '\n' && *e != '\0')
829         return;         /* false alarm */
830
831     if (t - s > 0) {
832         const STRLEN len = t - s;
833 #ifndef USE_ITHREADS
834         SV *const temp_sv = CopFILESV(PL_curcop);
835         const char *cf;
836         STRLEN tmplen;
837
838         if (temp_sv) {
839             cf = SvPVX(temp_sv);
840             tmplen = SvCUR(temp_sv);
841         } else {
842             cf = NULL;
843             tmplen = 0;
844         }
845
846         if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
847             /* must copy *{"::_<(eval N)[oldfilename:L]"}
848              * to *{"::_<newfilename"} */
849             /* However, the long form of evals is only turned on by the
850                debugger - usually they're "(eval %lu)" */
851             char smallbuf[128];
852             char *tmpbuf;
853             GV **gvp;
854             STRLEN tmplen2 = len;
855             if (tmplen + 2 <= sizeof smallbuf)
856                 tmpbuf = smallbuf;
857             else
858                 Newx(tmpbuf, tmplen + 2, char);
859             tmpbuf[0] = '_';
860             tmpbuf[1] = '<';
861             memcpy(tmpbuf + 2, cf, tmplen);
862             tmplen += 2;
863             gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
864             if (gvp) {
865                 char *tmpbuf2;
866                 GV *gv2;
867
868                 if (tmplen2 + 2 <= sizeof smallbuf)
869                     tmpbuf2 = smallbuf;
870                 else
871                     Newx(tmpbuf2, tmplen2 + 2, char);
872
873                 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
874                     /* Either they malloc'd it, or we malloc'd it,
875                        so no prefix is present in ours.  */
876                     tmpbuf2[0] = '_';
877                     tmpbuf2[1] = '<';
878                 }
879
880                 memcpy(tmpbuf2 + 2, s, tmplen2);
881                 tmplen2 += 2;
882
883                 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
884                 if (!isGV(gv2)) {
885                     gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
886                     /* adjust ${"::_<newfilename"} to store the new file name */
887                     GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
888                     GvHV(gv2) = MUTABLE_HV(SvREFCNT_inc(GvHV(*gvp)));
889                     GvAV(gv2) = MUTABLE_AV(SvREFCNT_inc(GvAV(*gvp)));
890                 }
891
892                 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
893             }
894             if (tmpbuf != smallbuf) Safefree(tmpbuf);
895         }
896 #endif
897         CopFILE_free(PL_curcop);
898         CopFILE_setn(PL_curcop, s, len);
899     }
900     CopLINE_set(PL_curcop, atoi(n)-1);
901 }
902
903 #ifdef PERL_MAD
904 /* skip space before PL_thistoken */
905
906 STATIC char *
907 S_skipspace0(pTHX_ register char *s)
908 {
909     PERL_ARGS_ASSERT_SKIPSPACE0;
910
911     s = skipspace(s);
912     if (!PL_madskills)
913         return s;
914     if (PL_skipwhite) {
915         if (!PL_thiswhite)
916             PL_thiswhite = newSVpvs("");
917         sv_catsv(PL_thiswhite, PL_skipwhite);
918         sv_free(PL_skipwhite);
919         PL_skipwhite = 0;
920     }
921     PL_realtokenstart = s - SvPVX(PL_linestr);
922     return s;
923 }
924
925 /* skip space after PL_thistoken */
926
927 STATIC char *
928 S_skipspace1(pTHX_ register char *s)
929 {
930     const char *start = s;
931     I32 startoff = start - SvPVX(PL_linestr);
932
933     PERL_ARGS_ASSERT_SKIPSPACE1;
934
935     s = skipspace(s);
936     if (!PL_madskills)
937         return s;
938     start = SvPVX(PL_linestr) + startoff;
939     if (!PL_thistoken && PL_realtokenstart >= 0) {
940         const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
941         PL_thistoken = newSVpvn(tstart, start - tstart);
942     }
943     PL_realtokenstart = -1;
944     if (PL_skipwhite) {
945         if (!PL_nextwhite)
946             PL_nextwhite = newSVpvs("");
947         sv_catsv(PL_nextwhite, PL_skipwhite);
948         sv_free(PL_skipwhite);
949         PL_skipwhite = 0;
950     }
951     return s;
952 }
953
954 STATIC char *
955 S_skipspace2(pTHX_ register char *s, SV **svp)
956 {
957     char *start;
958     const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
959     const I32 startoff = s - SvPVX(PL_linestr);
960
961     PERL_ARGS_ASSERT_SKIPSPACE2;
962
963     s = skipspace(s);
964     PL_bufptr = SvPVX(PL_linestr) + bufptroff;
965     if (!PL_madskills || !svp)
966         return s;
967     start = SvPVX(PL_linestr) + startoff;
968     if (!PL_thistoken && PL_realtokenstart >= 0) {
969         char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
970         PL_thistoken = newSVpvn(tstart, start - tstart);
971         PL_realtokenstart = -1;
972     }
973     if (PL_skipwhite) {
974         if (!*svp)
975             *svp = newSVpvs("");
976         sv_setsv(*svp, PL_skipwhite);
977         sv_free(PL_skipwhite);
978         PL_skipwhite = 0;
979     }
980     
981     return s;
982 }
983 #endif
984
985 STATIC void
986 S_update_debugger_info(pTHX_ SV *orig_sv, const char *const buf, STRLEN len)
987 {
988     AV *av = CopFILEAVx(PL_curcop);
989     if (av) {
990         SV * const sv = newSV_type(SVt_PVMG);
991         if (orig_sv)
992             sv_setsv(sv, orig_sv);
993         else
994             sv_setpvn(sv, buf, len);
995         (void)SvIOK_on(sv);
996         SvIV_set(sv, 0);
997         av_store(av, (I32)CopLINE(PL_curcop), sv);
998     }
999 }
1000
1001 /*
1002  * S_skipspace
1003  * Called to gobble the appropriate amount and type of whitespace.
1004  * Skips comments as well.
1005  */
1006
1007 STATIC char *
1008 S_skipspace(pTHX_ register char *s)
1009 {
1010     dVAR;
1011 #ifdef PERL_MAD
1012     int curoff;
1013     int startoff = s - SvPVX(PL_linestr);
1014
1015     PERL_ARGS_ASSERT_SKIPSPACE;
1016
1017     if (PL_skipwhite) {
1018         sv_free(PL_skipwhite);
1019         PL_skipwhite = 0;
1020     }
1021 #endif
1022     PERL_ARGS_ASSERT_SKIPSPACE;
1023
1024     if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
1025         while (s < PL_bufend && SPACE_OR_TAB(*s))
1026             s++;
1027 #ifdef PERL_MAD
1028         goto done;
1029 #else
1030         return s;
1031 #endif
1032     }
1033     for (;;) {
1034         STRLEN prevlen;
1035         SSize_t oldprevlen, oldoldprevlen;
1036         SSize_t oldloplen = 0, oldunilen = 0;
1037         while (s < PL_bufend && isSPACE(*s)) {
1038             if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
1039                 incline(s);
1040         }
1041
1042         /* comment */
1043         if (s < PL_bufend && *s == '#') {
1044             while (s < PL_bufend && *s != '\n')
1045                 s++;
1046             if (s < PL_bufend) {
1047                 s++;
1048                 if (PL_in_eval && !PL_rsfp) {
1049                     incline(s);
1050                     continue;
1051                 }
1052             }
1053         }
1054
1055         /* only continue to recharge the buffer if we're at the end
1056          * of the buffer, we're not reading from a source filter, and
1057          * we're in normal lexing mode
1058          */
1059         if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
1060                 PL_lex_state == LEX_FORMLINE)
1061 #ifdef PERL_MAD
1062             goto done;
1063 #else
1064             return s;
1065 #endif
1066
1067         /* try to recharge the buffer */
1068 #ifdef PERL_MAD
1069         curoff = s - SvPVX(PL_linestr);
1070 #endif
1071
1072         if ((s = filter_gets(PL_linestr, PL_rsfp,
1073                              (prevlen = SvCUR(PL_linestr)))) == NULL)
1074         {
1075 #ifdef PERL_MAD
1076             if (PL_madskills && curoff != startoff) {
1077                 if (!PL_skipwhite)
1078                     PL_skipwhite = newSVpvs("");
1079                 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1080                                         curoff - startoff);
1081             }
1082
1083             /* mustn't throw out old stuff yet if madpropping */
1084             SvCUR(PL_linestr) = curoff;
1085             s = SvPVX(PL_linestr) + curoff;
1086             *s = 0;
1087             if (curoff && s[-1] == '\n')
1088                 s[-1] = ' ';
1089 #endif
1090
1091             /* end of file.  Add on the -p or -n magic */
1092             /* XXX these shouldn't really be added here, can't set PL_faketokens */
1093             if (PL_minus_p) {
1094 #ifdef PERL_MAD
1095                 sv_catpvs(PL_linestr,
1096                          ";}continue{print or die qq(-p destination: $!\\n);}");
1097 #else
1098                 sv_setpvs(PL_linestr,
1099                          ";}continue{print or die qq(-p destination: $!\\n);}");
1100 #endif
1101                 PL_minus_n = PL_minus_p = 0;
1102             }
1103             else if (PL_minus_n) {
1104 #ifdef PERL_MAD
1105                 sv_catpvs(PL_linestr, ";}");
1106 #else
1107                 sv_setpvs(PL_linestr, ";}");
1108 #endif
1109                 PL_minus_n = 0;
1110             }
1111             else
1112 #ifdef PERL_MAD
1113                 sv_catpvs(PL_linestr,";");
1114 #else
1115                 sv_setpvs(PL_linestr,";");
1116 #endif
1117
1118             /* reset variables for next time we lex */
1119             PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
1120                 = SvPVX(PL_linestr)
1121 #ifdef PERL_MAD
1122                 + curoff
1123 #endif
1124                 ;
1125             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1126             PL_last_lop = PL_last_uni = NULL;
1127
1128             /* Close the filehandle.  Could be from
1129              * STDIN, or a regular file.  If we were reading code from
1130              * STDIN (because the commandline held no -e or filename)
1131              * then we don't close it, we reset it so the code can
1132              * read from STDIN too.
1133              */
1134
1135             if ((PerlIO*)PL_rsfp == PerlIO_stdin())
1136                 PerlIO_clearerr(PL_rsfp);
1137             else
1138                 (void)PerlIO_close(PL_rsfp);
1139             PL_rsfp = NULL;
1140             return s;
1141         }
1142
1143         /* not at end of file, so we only read another line */
1144         /* make corresponding updates to old pointers, for yyerror() */
1145         oldprevlen = PL_oldbufptr - PL_bufend;
1146         oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1147         if (PL_last_uni)
1148             oldunilen = PL_last_uni - PL_bufend;
1149         if (PL_last_lop)
1150             oldloplen = PL_last_lop - PL_bufend;
1151         PL_linestart = PL_bufptr = s + prevlen;
1152         PL_bufend = s + SvCUR(PL_linestr);
1153         s = PL_bufptr;
1154         PL_oldbufptr = s + oldprevlen;
1155         PL_oldoldbufptr = s + oldoldprevlen;
1156         if (PL_last_uni)
1157             PL_last_uni = s + oldunilen;
1158         if (PL_last_lop)
1159             PL_last_lop = s + oldloplen;
1160         incline(s);
1161
1162         /* debugger active and we're not compiling the debugger code,
1163          * so store the line into the debugger's array of lines
1164          */
1165         if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
1166             update_debugger_info(NULL, PL_bufptr, PL_bufend - PL_bufptr);
1167     }
1168
1169 #ifdef PERL_MAD
1170   done:
1171     if (PL_madskills) {
1172         if (!PL_skipwhite)
1173             PL_skipwhite = newSVpvs("");
1174         curoff = s - SvPVX(PL_linestr);
1175         if (curoff - startoff)
1176             sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
1177                                 curoff - startoff);
1178     }
1179     return s;
1180 #endif
1181 }
1182
1183 /*
1184  * S_check_uni
1185  * Check the unary operators to ensure there's no ambiguity in how they're
1186  * used.  An ambiguous piece of code would be:
1187  *     rand + 5
1188  * This doesn't mean rand() + 5.  Because rand() is a unary operator,
1189  * the +5 is its argument.
1190  */
1191
1192 STATIC void
1193 S_check_uni(pTHX)
1194 {
1195     dVAR;
1196     const char *s;
1197     const char *t;
1198
1199     if (PL_oldoldbufptr != PL_last_uni)
1200         return;
1201     while (isSPACE(*PL_last_uni))
1202         PL_last_uni++;
1203     s = PL_last_uni;
1204     while (isALNUM_lazy_if(s,UTF) || *s == '-')
1205         s++;
1206     if ((t = strchr(s, '(')) && t < PL_bufptr)
1207         return;
1208
1209     Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
1210                      "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1211                      (int)(s - PL_last_uni), PL_last_uni);
1212 }
1213
1214 /*
1215  * LOP : macro to build a list operator.  Its behaviour has been replaced
1216  * with a subroutine, S_lop() for which LOP is just another name.
1217  */
1218
1219 #define LOP(f,x) return lop(f,x,s)
1220
1221 /*
1222  * S_lop
1223  * Build a list operator (or something that might be one).  The rules:
1224  *  - if we have a next token, then it's a list operator [why?]
1225  *  - if the next thing is an opening paren, then it's a function
1226  *  - else it's a list operator
1227  */
1228
1229 STATIC I32
1230 S_lop(pTHX_ I32 f, int x, char *s)
1231 {
1232     dVAR;
1233
1234     PERL_ARGS_ASSERT_LOP;
1235
1236     pl_yylval.ival = f;
1237     CLINE;
1238     PL_expect = x;
1239     PL_bufptr = s;
1240     PL_last_lop = PL_oldbufptr;
1241     PL_last_lop_op = (OPCODE)f;
1242 #ifdef PERL_MAD
1243     if (PL_lasttoke)
1244         return REPORT(LSTOP);
1245 #else
1246     if (PL_nexttoke)
1247         return REPORT(LSTOP);
1248 #endif
1249     if (*s == '(')
1250         return REPORT(FUNC);
1251     s = PEEKSPACE(s);
1252     if (*s == '(')
1253         return REPORT(FUNC);
1254     else
1255         return REPORT(LSTOP);
1256 }
1257
1258 #ifdef PERL_MAD
1259  /*
1260  * S_start_force
1261  * Sets up for an eventual force_next().  start_force(0) basically does
1262  * an unshift, while start_force(-1) does a push.  yylex removes items
1263  * on the "pop" end.
1264  */
1265
1266 STATIC void
1267 S_start_force(pTHX_ int where)
1268 {
1269     int i;
1270
1271     if (where < 0)      /* so people can duplicate start_force(PL_curforce) */
1272         where = PL_lasttoke;
1273     assert(PL_curforce < 0 || PL_curforce == where);
1274     if (PL_curforce != where) {
1275         for (i = PL_lasttoke; i > where; --i) {
1276             PL_nexttoke[i] = PL_nexttoke[i-1];
1277         }
1278         PL_lasttoke++;
1279     }
1280     if (PL_curforce < 0)        /* in case of duplicate start_force() */
1281         Zero(&PL_nexttoke[where], 1, NEXTTOKE);
1282     PL_curforce = where;
1283     if (PL_nextwhite) {
1284         if (PL_madskills)
1285             curmad('^', newSVpvs(""));
1286         CURMAD('_', PL_nextwhite);
1287     }
1288 }
1289
1290 STATIC void
1291 S_curmad(pTHX_ char slot, SV *sv)
1292 {
1293     MADPROP **where;
1294
1295     if (!sv)
1296         return;
1297     if (PL_curforce < 0)
1298         where = &PL_thismad;
1299     else
1300         where = &PL_nexttoke[PL_curforce].next_mad;
1301
1302     if (PL_faketokens)
1303         sv_setpvs(sv, "");
1304     else {
1305         if (!IN_BYTES) {
1306             if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1307                 SvUTF8_on(sv);
1308             else if (PL_encoding) {
1309                 sv_recode_to_utf8(sv, PL_encoding);
1310             }
1311         }
1312     }
1313
1314     /* keep a slot open for the head of the list? */
1315     if (slot != '_' && *where && (*where)->mad_key == '^') {
1316         (*where)->mad_key = slot;
1317         sv_free(MUTABLE_SV(((*where)->mad_val)));
1318         (*where)->mad_val = (void*)sv;
1319     }
1320     else
1321         addmad(newMADsv(slot, sv), where, 0);
1322 }
1323 #else
1324 #  define start_force(where)    NOOP
1325 #  define curmad(slot, sv)      NOOP
1326 #endif
1327
1328 /*
1329  * S_force_next
1330  * When the lexer realizes it knows the next token (for instance,
1331  * it is reordering tokens for the parser) then it can call S_force_next
1332  * to know what token to return the next time the lexer is called.  Caller
1333  * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1334  * and possibly PL_expect to ensure the lexer handles the token correctly.
1335  */
1336
1337 STATIC void
1338 S_force_next(pTHX_ I32 type)
1339 {
1340     dVAR;
1341 #ifdef DEBUGGING
1342     if (DEBUG_T_TEST) {
1343         PerlIO_printf(Perl_debug_log, "### forced token:\n");
1344         tokereport(type, &NEXTVAL_NEXTTOKE);
1345     }
1346 #endif
1347 #ifdef PERL_MAD
1348     if (PL_curforce < 0)
1349         start_force(PL_lasttoke);
1350     PL_nexttoke[PL_curforce].next_type = type;
1351     if (PL_lex_state != LEX_KNOWNEXT)
1352         PL_lex_defer = PL_lex_state;
1353     PL_lex_state = LEX_KNOWNEXT;
1354     PL_lex_expect = PL_expect;
1355     PL_curforce = -1;
1356 #else
1357     PL_nexttype[PL_nexttoke] = type;
1358     PL_nexttoke++;
1359     if (PL_lex_state != LEX_KNOWNEXT) {
1360         PL_lex_defer = PL_lex_state;
1361         PL_lex_expect = PL_expect;
1362         PL_lex_state = LEX_KNOWNEXT;
1363     }
1364 #endif
1365 }
1366
1367 STATIC SV *
1368 S_newSV_maybe_utf8(pTHX_ const char *const start, STRLEN len)
1369 {
1370     dVAR;
1371     SV * const sv = newSVpvn_utf8(start, len,
1372                                   !IN_BYTES
1373                                   && UTF
1374                                   && !is_ascii_string((const U8*)start, len)
1375                                   && is_utf8_string((const U8*)start, len));
1376     return sv;
1377 }
1378
1379 /*
1380  * S_force_word
1381  * When the lexer knows the next thing is a word (for instance, it has
1382  * just seen -> and it knows that the next char is a word char, then
1383  * it calls S_force_word to stick the next word into the PL_nexttoke/val
1384  * lookahead.
1385  *
1386  * Arguments:
1387  *   char *start : buffer position (must be within PL_linestr)
1388  *   int token   : PL_next* will be this type of bare word (e.g., METHOD,WORD)
1389  *   int check_keyword : if true, Perl checks to make sure the word isn't
1390  *       a keyword (do this if the word is a label, e.g. goto FOO)
1391  *   int allow_pack : if true, : characters will also be allowed (require,
1392  *       use, etc. do this)
1393  *   int allow_initial_tick : used by the "sub" lexer only.
1394  */
1395
1396 STATIC char *
1397 S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
1398 {
1399     dVAR;
1400     register char *s;
1401     STRLEN len;
1402
1403     PERL_ARGS_ASSERT_FORCE_WORD;
1404
1405     start = SKIPSPACE1(start);
1406     s = start;
1407     if (isIDFIRST_lazy_if(s,UTF) ||
1408         (allow_pack && *s == ':') ||
1409         (allow_initial_tick && *s == '\'') )
1410     {
1411         s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
1412         if (check_keyword && keyword(PL_tokenbuf, len, 0))
1413             return start;
1414         start_force(PL_curforce);
1415         if (PL_madskills)
1416             curmad('X', newSVpvn(start,s-start));
1417         if (token == METHOD) {
1418             s = SKIPSPACE1(s);
1419             if (*s == '(')
1420                 PL_expect = XTERM;
1421             else {
1422                 PL_expect = XOPERATOR;
1423             }
1424         }
1425         if (PL_madskills)
1426             curmad('g', newSVpvs( "forced" ));
1427         NEXTVAL_NEXTTOKE.opval
1428             = (OP*)newSVOP(OP_CONST,0,
1429                            S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
1430         NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
1431         force_next(token);
1432     }
1433     return s;
1434 }
1435
1436 /*
1437  * S_force_ident
1438  * Called when the lexer wants $foo *foo &foo etc, but the program
1439  * text only contains the "foo" portion.  The first argument is a pointer
1440  * to the "foo", and the second argument is the type symbol to prefix.
1441  * Forces the next token to be a "WORD".
1442  * Creates the symbol if it didn't already exist (via gv_fetchpv()).
1443  */
1444
1445 STATIC void
1446 S_force_ident(pTHX_ register const char *s, int kind)
1447 {
1448     dVAR;
1449
1450     PERL_ARGS_ASSERT_FORCE_IDENT;
1451
1452     if (*s) {
1453         const STRLEN len = strlen(s);
1454         OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
1455         start_force(PL_curforce);
1456         NEXTVAL_NEXTTOKE.opval = o;
1457         force_next(WORD);
1458         if (kind) {
1459             o->op_private = OPpCONST_ENTERED;
1460             /* XXX see note in pp_entereval() for why we forgo typo
1461                warnings if the symbol must be introduced in an eval.
1462                GSAR 96-10-12 */
1463             gv_fetchpvn_flags(s, len,
1464                               PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1465                               : GV_ADD,
1466                               kind == '$' ? SVt_PV :
1467                               kind == '@' ? SVt_PVAV :
1468                               kind == '%' ? SVt_PVHV :
1469                               SVt_PVGV
1470                               );
1471         }
1472     }
1473 }
1474
1475 NV
1476 Perl_str_to_version(pTHX_ SV *sv)
1477 {
1478     NV retval = 0.0;
1479     NV nshift = 1.0;
1480     STRLEN len;
1481     const char *start = SvPV_const(sv,len);
1482     const char * const end = start + len;
1483     const bool utf = SvUTF8(sv) ? TRUE : FALSE;
1484
1485     PERL_ARGS_ASSERT_STR_TO_VERSION;
1486
1487     while (start < end) {
1488         STRLEN skip;
1489         UV n;
1490         if (utf)
1491             n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1492         else {
1493             n = *(U8*)start;
1494             skip = 1;
1495         }
1496         retval += ((NV)n)/nshift;
1497         start += skip;
1498         nshift *= 1000;
1499     }
1500     return retval;
1501 }
1502
1503 /*
1504  * S_force_version
1505  * Forces the next token to be a version number.
1506  * If the next token appears to be an invalid version number, (e.g. "v2b"),
1507  * and if "guessing" is TRUE, then no new token is created (and the caller
1508  * must use an alternative parsing method).
1509  */
1510
1511 STATIC char *
1512 S_force_version(pTHX_ char *s, int guessing)
1513 {
1514     dVAR;
1515     OP *version = NULL;
1516     char *d;
1517 #ifdef PERL_MAD
1518     I32 startoff = s - SvPVX(PL_linestr);
1519 #endif
1520
1521     PERL_ARGS_ASSERT_FORCE_VERSION;
1522
1523     s = SKIPSPACE1(s);
1524
1525     d = s;
1526     if (*d == 'v')
1527         d++;
1528     if (isDIGIT(*d)) {
1529         while (isDIGIT(*d) || *d == '_' || *d == '.')
1530             d++;
1531 #ifdef PERL_MAD
1532         if (PL_madskills) {
1533             start_force(PL_curforce);
1534             curmad('X', newSVpvn(s,d-s));
1535         }
1536 #endif
1537         if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
1538             SV *ver;
1539             s = scan_num(s, &pl_yylval);
1540             version = pl_yylval.opval;
1541             ver = cSVOPx(version)->op_sv;
1542             if (SvPOK(ver) && !SvNIOK(ver)) {
1543                 SvUPGRADE(ver, SVt_PVNV);
1544                 SvNV_set(ver, str_to_version(ver));
1545                 SvNOK_on(ver);          /* hint that it is a version */
1546             }
1547         }
1548         else if (guessing) {
1549 #ifdef PERL_MAD
1550             if (PL_madskills) {
1551                 sv_free(PL_nextwhite);  /* let next token collect whitespace */
1552                 PL_nextwhite = 0;
1553                 s = SvPVX(PL_linestr) + startoff;
1554             }
1555 #endif
1556             return s;
1557         }
1558     }
1559
1560 #ifdef PERL_MAD
1561     if (PL_madskills && !version) {
1562         sv_free(PL_nextwhite);  /* let next token collect whitespace */
1563         PL_nextwhite = 0;
1564         s = SvPVX(PL_linestr) + startoff;
1565     }
1566 #endif
1567     /* NOTE: The parser sees the package name and the VERSION swapped */
1568     start_force(PL_curforce);
1569     NEXTVAL_NEXTTOKE.opval = version;
1570     force_next(WORD);
1571
1572     return s;
1573 }
1574
1575 /*
1576  * S_tokeq
1577  * Tokenize a quoted string passed in as an SV.  It finds the next
1578  * chunk, up to end of string or a backslash.  It may make a new
1579  * SV containing that chunk (if HINT_NEW_STRING is on).  It also
1580  * turns \\ into \.
1581  */
1582
1583 STATIC SV *
1584 S_tokeq(pTHX_ SV *sv)
1585 {
1586     dVAR;
1587     register char *s;
1588     register char *send;
1589     register char *d;
1590     STRLEN len = 0;
1591     SV *pv = sv;
1592
1593     PERL_ARGS_ASSERT_TOKEQ;
1594
1595     if (!SvLEN(sv))
1596         goto finish;
1597
1598     s = SvPV_force(sv, len);
1599     if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
1600         goto finish;
1601     send = s + len;
1602     while (s < send && *s != '\\')
1603         s++;
1604     if (s == send)
1605         goto finish;
1606     d = s;
1607     if ( PL_hints & HINT_NEW_STRING ) {
1608         pv = newSVpvn_flags(SvPVX_const(pv), len, SVs_TEMP | SvUTF8(sv));
1609     }
1610     while (s < send) {
1611         if (*s == '\\') {
1612             if (s + 1 < send && (s[1] == '\\'))
1613                 s++;            /* all that, just for this */
1614         }
1615         *d++ = *s++;
1616     }
1617     *d = '\0';
1618     SvCUR_set(sv, d - SvPVX_const(sv));
1619   finish:
1620     if ( PL_hints & HINT_NEW_STRING )
1621        return new_constant(NULL, 0, "q", sv, pv, "q", 1);
1622     return sv;
1623 }
1624
1625 /*
1626  * Now come three functions related to double-quote context,
1627  * S_sublex_start, S_sublex_push, and S_sublex_done.  They're used when
1628  * converting things like "\u\Lgnat" into ucfirst(lc("gnat")).  They
1629  * interact with PL_lex_state, and create fake ( ... ) argument lists
1630  * to handle functions and concatenation.
1631  * They assume that whoever calls them will be setting up a fake
1632  * join call, because each subthing puts a ',' after it.  This lets
1633  *   "lower \luPpEr"
1634  * become
1635  *  join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1636  *
1637  * (I'm not sure whether the spurious commas at the end of lcfirst's
1638  * arguments and join's arguments are created or not).
1639  */
1640
1641 /*
1642  * S_sublex_start
1643  * Assumes that pl_yylval.ival is the op we're creating (e.g. OP_LCFIRST).
1644  *
1645  * Pattern matching will set PL_lex_op to the pattern-matching op to
1646  * make (we return THING if pl_yylval.ival is OP_NULL, PMFUNC otherwise).
1647  *
1648  * OP_CONST and OP_READLINE are easy--just make the new op and return.
1649  *
1650  * Everything else becomes a FUNC.
1651  *
1652  * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1653  * had an OP_CONST or OP_READLINE).  This just sets us up for a
1654  * call to S_sublex_push().
1655  */
1656
1657 STATIC I32
1658 S_sublex_start(pTHX)
1659 {
1660     dVAR;
1661     register const I32 op_type = pl_yylval.ival;
1662
1663     if (op_type == OP_NULL) {
1664         pl_yylval.opval = PL_lex_op;
1665         PL_lex_op = NULL;
1666         return THING;
1667     }
1668     if (op_type == OP_CONST || op_type == OP_READLINE) {
1669         SV *sv = tokeq(PL_lex_stuff);
1670
1671         if (SvTYPE(sv) == SVt_PVIV) {
1672             /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1673             STRLEN len;
1674             const char * const p = SvPV_const(sv, len);
1675             SV * const nsv = newSVpvn_flags(p, len, SvUTF8(sv));
1676             SvREFCNT_dec(sv);
1677             sv = nsv;
1678         }
1679         pl_yylval.opval = (OP*)newSVOP(op_type, 0, sv);
1680         PL_lex_stuff = NULL;
1681         /* Allow <FH> // "foo" */
1682         if (op_type == OP_READLINE)
1683             PL_expect = XTERMORDORDOR;
1684         return THING;
1685     }
1686     else if (op_type == OP_BACKTICK && PL_lex_op) {
1687         /* readpipe() vas overriden */
1688         cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
1689         pl_yylval.opval = PL_lex_op;
1690         PL_lex_op = NULL;
1691         PL_lex_stuff = NULL;
1692         return THING;
1693     }
1694
1695     PL_sublex_info.super_state = PL_lex_state;
1696     PL_sublex_info.sub_inwhat = (U16)op_type;
1697     PL_sublex_info.sub_op = PL_lex_op;
1698     PL_lex_state = LEX_INTERPPUSH;
1699
1700     PL_expect = XTERM;
1701     if (PL_lex_op) {
1702         pl_yylval.opval = PL_lex_op;
1703         PL_lex_op = NULL;
1704         return PMFUNC;
1705     }
1706     else
1707         return FUNC;
1708 }
1709
1710 /*
1711  * S_sublex_push
1712  * Create a new scope to save the lexing state.  The scope will be
1713  * ended in S_sublex_done.  Returns a '(', starting the function arguments
1714  * to the uc, lc, etc. found before.
1715  * Sets PL_lex_state to LEX_INTERPCONCAT.
1716  */
1717
1718 STATIC I32
1719 S_sublex_push(pTHX)
1720 {
1721     dVAR;
1722     ENTER;
1723
1724     PL_lex_state = PL_sublex_info.super_state;
1725     SAVEBOOL(PL_lex_dojoin);
1726     SAVEI32(PL_lex_brackets);
1727     SAVEI32(PL_lex_casemods);
1728     SAVEI32(PL_lex_starts);
1729     SAVEI8(PL_lex_state);
1730     SAVEVPTR(PL_lex_inpat);
1731     SAVEI16(PL_lex_inwhat);
1732     SAVECOPLINE(PL_curcop);
1733     SAVEPPTR(PL_bufptr);
1734     SAVEPPTR(PL_bufend);
1735     SAVEPPTR(PL_oldbufptr);
1736     SAVEPPTR(PL_oldoldbufptr);
1737     SAVEPPTR(PL_last_lop);
1738     SAVEPPTR(PL_last_uni);
1739     SAVEPPTR(PL_linestart);
1740     SAVESPTR(PL_linestr);
1741     SAVEGENERICPV(PL_lex_brackstack);
1742     SAVEGENERICPV(PL_lex_casestack);
1743
1744     PL_linestr = PL_lex_stuff;
1745     PL_lex_stuff = NULL;
1746
1747     PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1748         = SvPVX(PL_linestr);
1749     PL_bufend += SvCUR(PL_linestr);
1750     PL_last_lop = PL_last_uni = NULL;
1751     SAVEFREESV(PL_linestr);
1752
1753     PL_lex_dojoin = FALSE;
1754     PL_lex_brackets = 0;
1755     Newx(PL_lex_brackstack, 120, char);
1756     Newx(PL_lex_casestack, 12, char);
1757     PL_lex_casemods = 0;
1758     *PL_lex_casestack = '\0';
1759     PL_lex_starts = 0;
1760     PL_lex_state = LEX_INTERPCONCAT;
1761     CopLINE_set(PL_curcop, (line_t)PL_multi_start);
1762
1763     PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1764     if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1765         PL_lex_inpat = PL_sublex_info.sub_op;
1766     else
1767         PL_lex_inpat = NULL;
1768
1769     return '(';
1770 }
1771
1772 /*
1773  * S_sublex_done
1774  * Restores lexer state after a S_sublex_push.
1775  */
1776
1777 STATIC I32
1778 S_sublex_done(pTHX)
1779 {
1780     dVAR;
1781     if (!PL_lex_starts++) {
1782         SV * const sv = newSVpvs("");
1783         if (SvUTF8(PL_linestr))
1784             SvUTF8_on(sv);
1785         PL_expect = XOPERATOR;
1786         pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
1787         return THING;
1788     }
1789
1790     if (PL_lex_casemods) {              /* oops, we've got some unbalanced parens */
1791         PL_lex_state = LEX_INTERPCASEMOD;
1792         return yylex();
1793     }
1794
1795     /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
1796     if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1797         PL_linestr = PL_lex_repl;
1798         PL_lex_inpat = 0;
1799         PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1800         PL_bufend += SvCUR(PL_linestr);
1801         PL_last_lop = PL_last_uni = NULL;
1802         SAVEFREESV(PL_linestr);
1803         PL_lex_dojoin = FALSE;
1804         PL_lex_brackets = 0;
1805         PL_lex_casemods = 0;
1806         *PL_lex_casestack = '\0';
1807         PL_lex_starts = 0;
1808         if (SvEVALED(PL_lex_repl)) {
1809             PL_lex_state = LEX_INTERPNORMAL;
1810             PL_lex_starts++;
1811             /*  we don't clear PL_lex_repl here, so that we can check later
1812                 whether this is an evalled subst; that means we rely on the
1813                 logic to ensure sublex_done() is called again only via the
1814                 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
1815         }
1816         else {
1817             PL_lex_state = LEX_INTERPCONCAT;
1818             PL_lex_repl = NULL;
1819         }
1820         return ',';
1821     }
1822     else {
1823 #ifdef PERL_MAD
1824         if (PL_madskills) {
1825             if (PL_thiswhite) {
1826                 if (!PL_endwhite)
1827                     PL_endwhite = newSVpvs("");
1828                 sv_catsv(PL_endwhite, PL_thiswhite);
1829                 PL_thiswhite = 0;
1830             }
1831             if (PL_thistoken)
1832                 sv_setpvs(PL_thistoken,"");
1833             else
1834                 PL_realtokenstart = -1;
1835         }
1836 #endif
1837         LEAVE;
1838         PL_bufend = SvPVX(PL_linestr);
1839         PL_bufend += SvCUR(PL_linestr);
1840         PL_expect = XOPERATOR;
1841         PL_sublex_info.sub_inwhat = 0;
1842         return ')';
1843     }
1844 }
1845
1846 /*
1847   scan_const
1848
1849   Extracts a pattern, double-quoted string, or transliteration.  This
1850   is terrifying code.
1851
1852   It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
1853   processing a pattern (PL_lex_inpat is true), a transliteration
1854   (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
1855
1856   Returns a pointer to the character scanned up to. If this is
1857   advanced from the start pointer supplied (i.e. if anything was
1858   successfully parsed), will leave an OP for the substring scanned
1859   in pl_yylval. Caller must intuit reason for not parsing further
1860   by looking at the next characters herself.
1861
1862   In patterns:
1863     backslashes:
1864       double-quoted style: \r and \n
1865       regexp special ones: \D \s
1866       constants: \x31
1867       backrefs: \1
1868       case and quoting: \U \Q \E
1869     stops on @ and $, but not for $ as tail anchor
1870
1871   In transliterations:
1872     characters are VERY literal, except for - not at the start or end
1873     of the string, which indicates a range. If the range is in bytes,
1874     scan_const expands the range to the full set of intermediate
1875     characters. If the range is in utf8, the hyphen is replaced with
1876     a certain range mark which will be handled by pmtrans() in op.c.
1877
1878   In double-quoted strings:
1879     backslashes:
1880       double-quoted style: \r and \n
1881       constants: \x31
1882       deprecated backrefs: \1 (in substitution replacements)
1883       case and quoting: \U \Q \E
1884     stops on @ and $
1885
1886   scan_const does *not* construct ops to handle interpolated strings.
1887   It stops processing as soon as it finds an embedded $ or @ variable
1888   and leaves it to the caller to work out what's going on.
1889
1890   embedded arrays (whether in pattern or not) could be:
1891       @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1892
1893   $ in double-quoted strings must be the symbol of an embedded scalar.
1894
1895   $ in pattern could be $foo or could be tail anchor.  Assumption:
1896   it's a tail anchor if $ is the last thing in the string, or if it's
1897   followed by one of "()| \r\n\t"
1898
1899   \1 (backreferences) are turned into $1
1900
1901   The structure of the code is
1902       while (there's a character to process) {
1903           handle transliteration ranges
1904           skip regexp comments /(?#comment)/ and codes /(?{code})/
1905           skip #-initiated comments in //x patterns
1906           check for embedded arrays
1907           check for embedded scalars
1908           if (backslash) {
1909               leave intact backslashes from leaveit (below)
1910               deprecate \1 in substitution replacements
1911               handle string-changing backslashes \l \U \Q \E, etc.
1912               switch (what was escaped) {
1913                   handle \- in a transliteration (becomes a literal -)
1914                   handle \132 (octal characters)
1915                   handle \x15 and \x{1234} (hex characters)
1916                   handle \N{name} (named characters)
1917                   handle \cV (control characters)
1918                   handle printf-style backslashes (\f, \r, \n, etc)
1919               } (end switch)
1920               continue
1921           } (end if backslash)
1922           handle regular character
1923     } (end while character to read)
1924                 
1925 */
1926
1927 STATIC char *
1928 S_scan_const(pTHX_ char *start)
1929 {
1930     dVAR;
1931     register char *send = PL_bufend;            /* end of the constant */
1932     SV *sv = newSV(send - start);               /* sv for the constant.  See
1933                                                    note below on sizing. */
1934     register char *s = start;                   /* start of the constant */
1935     register char *d = SvPVX(sv);               /* destination for copies */
1936     bool dorange = FALSE;                       /* are we in a translit range? */
1937     bool didrange = FALSE;                      /* did we just finish a range? */
1938     I32  has_utf8 = FALSE;                      /* Output constant is UTF8 */
1939     I32  this_utf8 = UTF;                       /* Is the source string assumed
1940                                                    to be UTF8?  But, this can
1941                                                    show as true when the source
1942                                                    isn't utf8, as for example
1943                                                    when it is entirely composed
1944                                                    of hex constants */
1945
1946     /* Note on sizing:  The scanned constant is placed into sv, which is
1947      * initialized by newSV() assuming one byte of output for every byte of
1948      * input.  This routine expects newSV() to allocate an extra byte for a
1949      * trailing NUL, which this routine will append if it gets to the end of
1950      * the input.  There may be more bytes of input than output (eg., \N{LATIN
1951      * CAPITAL LETTER A}), or more output than input if the constant ends up
1952      * recoded to utf8, but each time a construct is found that might increase
1953      * the needed size, SvGROW() is called.  Its size parameter each time is
1954      * based on the best guess estimate at the time, namely the length used so
1955      * far, plus the length the current construct will occupy, plus room for
1956      * the trailing NUL, plus one byte for every input byte still unscanned */ 
1957
1958     UV uv;
1959 #ifdef EBCDIC
1960     UV literal_endpoint = 0;
1961     bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
1962 #endif
1963
1964     PERL_ARGS_ASSERT_SCAN_CONST;
1965
1966     if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1967         /* If we are doing a trans and we know we want UTF8 set expectation */
1968         has_utf8   = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1969         this_utf8  = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1970     }
1971
1972
1973     while (s < send || dorange) {
1974         /* get transliterations out of the way (they're most literal) */
1975         if (PL_lex_inwhat == OP_TRANS) {
1976             /* expand a range A-Z to the full set of characters.  AIE! */
1977             if (dorange) {
1978                 I32 i;                          /* current expanded character */
1979                 I32 min;                        /* first character in range */
1980                 I32 max;                        /* last character in range */
1981
1982 #ifdef EBCDIC
1983                 UV uvmax = 0;
1984 #endif
1985
1986                 if (has_utf8
1987 #ifdef EBCDIC
1988                     && !native_range
1989 #endif
1990                     ) {
1991                     char * const c = (char*)utf8_hop((U8*)d, -1);
1992                     char *e = d++;
1993                     while (e-- > c)
1994                         *(e + 1) = *e;
1995                     *c = (char)UTF_TO_NATIVE(0xff);
1996                     /* mark the range as done, and continue */
1997                     dorange = FALSE;
1998                     didrange = TRUE;
1999                     continue;
2000                 }
2001
2002                 i = d - SvPVX_const(sv);                /* remember current offset */
2003 #ifdef EBCDIC
2004                 SvGROW(sv,
2005                        SvLEN(sv) + (has_utf8 ?
2006                                     (512 - UTF_CONTINUATION_MARK +
2007                                      UNISKIP(0x100))
2008                                     : 256));
2009                 /* How many two-byte within 0..255: 128 in UTF-8,
2010                  * 96 in UTF-8-mod. */
2011 #else
2012                 SvGROW(sv, SvLEN(sv) + 256);    /* never more than 256 chars in a range */
2013 #endif
2014                 d = SvPVX(sv) + i;              /* refresh d after realloc */
2015 #ifdef EBCDIC
2016                 if (has_utf8) {
2017                     int j;
2018                     for (j = 0; j <= 1; j++) {
2019                         char * const c = (char*)utf8_hop((U8*)d, -1);
2020                         const UV uv    = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
2021                         if (j)
2022                             min = (U8)uv;
2023                         else if (uv < 256)
2024                             max = (U8)uv;
2025                         else {
2026                             max = (U8)0xff; /* only to \xff */
2027                             uvmax = uv; /* \x{100} to uvmax */
2028                         }
2029                         d = c; /* eat endpoint chars */
2030                      }
2031                 }
2032                else {
2033 #endif
2034                    d -= 2;              /* eat the first char and the - */
2035                    min = (U8)*d;        /* first char in range */
2036                    max = (U8)d[1];      /* last char in range  */
2037 #ifdef EBCDIC
2038                }
2039 #endif
2040
2041                 if (min > max) {
2042                     Perl_croak(aTHX_
2043                                "Invalid range \"%c-%c\" in transliteration operator",
2044                                (char)min, (char)max);
2045                 }
2046
2047 #ifdef EBCDIC
2048                 if (literal_endpoint == 2 &&
2049                     ((isLOWER(min) && isLOWER(max)) ||
2050                      (isUPPER(min) && isUPPER(max)))) {
2051                     if (isLOWER(min)) {
2052                         for (i = min; i <= max; i++)
2053                             if (isLOWER(i))
2054                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
2055                     } else {
2056                         for (i = min; i <= max; i++)
2057                             if (isUPPER(i))
2058                                 *d++ = NATIVE_TO_NEED(has_utf8,i);
2059                     }
2060                 }
2061                 else
2062 #endif
2063                     for (i = min; i <= max; i++)
2064 #ifdef EBCDIC
2065                         if (has_utf8) {
2066                             const U8 ch = (U8)NATIVE_TO_UTF(i);
2067                             if (UNI_IS_INVARIANT(ch))
2068                                 *d++ = (U8)i;
2069                             else {
2070                                 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
2071                                 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
2072                             }
2073                         }
2074                         else
2075 #endif
2076                             *d++ = (char)i;
2077  
2078 #ifdef EBCDIC
2079                 if (uvmax) {
2080                     d = (char*)uvchr_to_utf8((U8*)d, 0x100);
2081                     if (uvmax > 0x101)
2082                         *d++ = (char)UTF_TO_NATIVE(0xff);
2083                     if (uvmax > 0x100)
2084                         d = (char*)uvchr_to_utf8((U8*)d, uvmax);
2085                 }
2086 #endif
2087
2088                 /* mark the range as done, and continue */
2089                 dorange = FALSE;
2090                 didrange = TRUE;
2091 #ifdef EBCDIC
2092                 literal_endpoint = 0;
2093 #endif
2094                 continue;
2095             }
2096
2097             /* range begins (ignore - as first or last char) */
2098             else if (*s == '-' && s+1 < send  && s != start) {
2099                 if (didrange) {
2100                     Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
2101                 }
2102                 if (has_utf8
2103 #ifdef EBCDIC
2104                     && !native_range
2105 #endif
2106                     ) {
2107                     *d++ = (char)UTF_TO_NATIVE(0xff);   /* use illegal utf8 byte--see pmtrans */
2108                     s++;
2109                     continue;
2110                 }
2111                 dorange = TRUE;
2112                 s++;
2113             }
2114             else {
2115                 didrange = FALSE;
2116 #ifdef EBCDIC
2117                 literal_endpoint = 0;
2118                 native_range = TRUE;
2119 #endif
2120             }
2121         }
2122
2123         /* if we get here, we're not doing a transliteration */
2124
2125         /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2126            except for the last char, which will be done separately. */
2127         else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
2128             if (s[2] == '#') {
2129                 while (s+1 < send && *s != ')')
2130                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2131             }
2132             else if (s[2] == '{' /* This should match regcomp.c */
2133                     || (s[2] == '?' && s[3] == '{'))
2134             {
2135                 I32 count = 1;
2136                 char *regparse = s + (s[2] == '{' ? 3 : 4);
2137                 char c;
2138
2139                 while (count && (c = *regparse)) {
2140                     if (c == '\\' && regparse[1])
2141                         regparse++;
2142                     else if (c == '{')
2143                         count++;
2144                     else if (c == '}')
2145                         count--;
2146                     regparse++;
2147                 }
2148                 if (*regparse != ')')
2149                     regparse--;         /* Leave one char for continuation. */
2150                 while (s < regparse)
2151                     *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2152             }
2153         }
2154
2155         /* likewise skip #-initiated comments in //x patterns */
2156         else if (*s == '#' && PL_lex_inpat &&
2157           ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
2158             while (s+1 < send && *s != '\n')
2159                 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2160         }
2161
2162         /* check for embedded arrays
2163            (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
2164            */
2165         else if (*s == '@' && s[1]) {
2166             if (isALNUM_lazy_if(s+1,UTF))
2167                 break;
2168             if (strchr(":'{$", s[1]))
2169                 break;
2170             if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2171                 break; /* in regexp, neither @+ nor @- are interpolated */
2172         }
2173
2174         /* check for embedded scalars.  only stop if we're sure it's a
2175            variable.
2176         */
2177         else if (*s == '$') {
2178             if (!PL_lex_inpat)  /* not a regexp, so $ must be var */
2179                 break;
2180             if (s + 1 < send && !strchr("()| \r\n\t", s[1])) {
2181                 if (s[1] == '\\') {
2182                     Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
2183                                    "Possible unintended interpolation of $\\ in regex");
2184                 }
2185                 break;          /* in regexp, $ might be tail anchor */
2186             }
2187         }
2188
2189         /* End of else if chain - OP_TRANS rejoin rest */
2190
2191         /* backslashes */
2192         if (*s == '\\' && s+1 < send) {
2193             s++;
2194
2195             /* deprecate \1 in strings and substitution replacements */
2196             if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
2197                 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
2198             {
2199                 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
2200                 *--s = '$';
2201                 break;
2202             }
2203
2204             /* string-change backslash escapes */
2205             if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
2206                 --s;
2207                 break;
2208             }
2209             /* skip any other backslash escapes in a pattern */
2210             else if (PL_lex_inpat) {
2211                 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2212                 goto default_action;
2213             }
2214
2215             /* if we get here, it's either a quoted -, or a digit */
2216             switch (*s) {
2217
2218             /* quoted - in transliterations */
2219             case '-':
2220                 if (PL_lex_inwhat == OP_TRANS) {
2221                     *d++ = *s++;
2222                     continue;
2223                 }
2224                 /* FALL THROUGH */
2225             default:
2226                 {
2227                     if ((isALPHA(*s) || isDIGIT(*s)))
2228                         Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
2229                                        "Unrecognized escape \\%c passed through",
2230                                        *s);
2231                     /* default action is to copy the quoted character */
2232                     goto default_action;
2233                 }
2234
2235             /* eg. \132 indicates the octal constant 0x132 */
2236             case '0': case '1': case '2': case '3':
2237             case '4': case '5': case '6': case '7':
2238                 {
2239                     I32 flags = 0;
2240                     STRLEN len = 3;
2241                     uv = NATIVE_TO_UNI(grok_oct(s, &len, &flags, NULL));
2242                     s += len;
2243                 }
2244                 goto NUM_ESCAPE_INSERT;
2245
2246             /* eg. \x24 indicates the hex constant 0x24 */
2247             case 'x':
2248                 ++s;
2249                 if (*s == '{') {
2250                     char* const e = strchr(s, '}');
2251                     I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2252                       PERL_SCAN_DISALLOW_PREFIX;
2253                     STRLEN len;
2254
2255                     ++s;
2256                     if (!e) {
2257                         yyerror("Missing right brace on \\x{}");
2258                         continue;
2259                     }
2260                     len = e - s;
2261                     uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
2262                     s = e + 1;
2263                 }
2264                 else {
2265                     {
2266                         STRLEN len = 2;
2267                         I32 flags = PERL_SCAN_DISALLOW_PREFIX;
2268                         uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
2269                         s += len;
2270                     }
2271                 }
2272
2273               NUM_ESCAPE_INSERT:
2274                 /* Insert oct, hex, or \N{U+...} escaped character.  There will
2275                  * always be enough room in sv since such escapes will be
2276                  * longer than any UTF-8 sequence they can end up as, except if
2277                  * they force us to recode the rest of the string into utf8 */
2278                 
2279                 /* Here uv is the ordinal of the next character being added in
2280                  * unicode (converted from native).  (It has to be done before
2281                  * here because \N is interpreted as unicode, and oct and hex
2282                  * as native.) */
2283                 if (!UNI_IS_INVARIANT(uv)) {
2284                     if (!has_utf8 && uv > 255) {
2285                         /* Might need to recode whatever we have accumulated so
2286                          * far if it contains any chars variant in utf8 or
2287                          * utf-ebcdic. */
2288                           
2289                         SvCUR_set(sv, d - SvPVX_const(sv));
2290                         SvPOK_on(sv);
2291                         *d = '\0';
2292                         /* See Note on sizing above.  */
2293                         sv_utf8_upgrade_flags_grow(sv,
2294                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2295                                         UNISKIP(uv) + (STRLEN)(send - s) + 1);
2296                         d = SvPVX(sv) + SvCUR(sv);
2297                         has_utf8 = TRUE;
2298                     }
2299
2300                     if (has_utf8) {
2301                         d = (char*)uvuni_to_utf8((U8*)d, uv);
2302                         if (PL_lex_inwhat == OP_TRANS &&
2303                             PL_sublex_info.sub_op) {
2304                             PL_sublex_info.sub_op->op_private |=
2305                                 (PL_lex_repl ? OPpTRANS_FROM_UTF
2306                                              : OPpTRANS_TO_UTF);
2307                         }
2308 #ifdef EBCDIC
2309                         if (uv > 255 && !dorange)
2310                             native_range = FALSE;
2311 #endif
2312                     }
2313                     else {
2314                         *d++ = (char)uv;
2315                     }
2316                 }
2317                 else {
2318                     *d++ = (char) uv;
2319                 }
2320                 continue;
2321
2322             /* \N{LATIN SMALL LETTER A} is a named character, and so is
2323              * \N{U+0041} */
2324             case 'N':
2325                 ++s;
2326                 if (*s == '{') {
2327                     char* e = strchr(s, '}');
2328                     SV *res;
2329                     STRLEN len;
2330                     const char *str;
2331
2332                     if (!e) {
2333                         yyerror("Missing right brace on \\N{}");
2334                         e = s - 1;
2335                         goto cont_scan;
2336                     }
2337                     if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
2338                         /* \N{U+...} The ... is a unicode value even on EBCDIC
2339                          * machines */
2340                         I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2341                           PERL_SCAN_DISALLOW_PREFIX;
2342                         s += 3;
2343                         len = e - s;
2344                         uv = grok_hex(s, &len, &flags, NULL);
2345                         if ( e > s && len != (STRLEN)(e - s) ) {
2346                             uv = 0xFFFD;
2347                         }
2348                         s = e + 1;
2349                         goto NUM_ESCAPE_INSERT;
2350                     }
2351                     res = newSVpvn(s + 1, e - s - 1);
2352                     res = new_constant( NULL, 0, "charnames",
2353                                         res, NULL, s - 2, e - s + 3 );
2354                     if (has_utf8)
2355                         sv_utf8_upgrade(res);
2356                     str = SvPV_const(res,len);
2357 #ifdef EBCDIC_NEVER_MIND
2358                     /* charnames uses pack U and that has been
2359                      * recently changed to do the below uni->native
2360                      * mapping, so this would be redundant (and wrong,
2361                      * the code point would be doubly converted).
2362                      * But leave this in just in case the pack U change
2363                      * gets revoked, but the semantics is still
2364                      * desireable for charnames. --jhi */
2365                     {
2366                          UV uv = utf8_to_uvchr((const U8*)str, 0);
2367
2368                          if (uv < 0x100) {
2369                               U8 tmpbuf[UTF8_MAXBYTES+1], *d;
2370
2371                               d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2372                               sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
2373                               str = SvPV_const(res, len);
2374                          }
2375                     }
2376 #endif
2377                     /* If destination is not in utf8 but this new character is,
2378                      * recode the dest to utf8 */
2379                     if (!has_utf8 && SvUTF8(res)) {
2380                         SvCUR_set(sv, d - SvPVX_const(sv));
2381                         SvPOK_on(sv);
2382                         *d = '\0';
2383                         /* See Note on sizing above.  */
2384                         sv_utf8_upgrade_flags_grow(sv,
2385                                             SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2386                                             len + (STRLEN)(send - s) + 1);
2387                         d = SvPVX(sv) + SvCUR(sv);
2388                         has_utf8 = TRUE;
2389                     } else if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
2390
2391                         /* See Note on sizing above.  (NOTE: SvCUR() is not set
2392                          * correctly here). */
2393                         const STRLEN off = d - SvPVX_const(sv);
2394                         d = SvGROW(sv, off + len + (STRLEN)(send - s) + 1) + off;
2395                     }
2396 #ifdef EBCDIC
2397                     if (!dorange)
2398                         native_range = FALSE; /* \N{} is guessed to be Unicode */
2399 #endif
2400                     Copy(str, d, len, char);
2401                     d += len;
2402                     SvREFCNT_dec(res);
2403                   cont_scan:
2404                     s = e + 1;
2405                 }
2406                 else
2407                     yyerror("Missing braces on \\N{}");
2408                 continue;
2409
2410             /* \c is a control character */
2411             case 'c':
2412                 s++;
2413                 if (s < send) {
2414                     U8 c = *s++;
2415 #ifdef EBCDIC
2416                     if (isLOWER(c))
2417                         c = toUPPER(c);
2418 #endif
2419                     *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
2420                 }
2421                 else {
2422                     yyerror("Missing control char name in \\c");
2423                 }
2424                 continue;
2425
2426             /* printf-style backslashes, formfeeds, newlines, etc */
2427             case 'b':
2428                 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
2429                 break;
2430             case 'n':
2431                 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
2432                 break;
2433             case 'r':
2434                 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
2435                 break;
2436             case 'f':
2437                 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
2438                 break;
2439             case 't':
2440                 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
2441                 break;
2442             case 'e':
2443                 *d++ = ASCII_TO_NEED(has_utf8,'\033');
2444                 break;
2445             case 'a':
2446                 *d++ = ASCII_TO_NEED(has_utf8,'\007');
2447                 break;
2448             } /* end switch */
2449
2450             s++;
2451             continue;
2452         } /* end if (backslash) */
2453 #ifdef EBCDIC
2454         else
2455             literal_endpoint++;
2456 #endif
2457
2458     default_action:
2459         /* If we started with encoded form, or already know we want it,
2460            then encode the next character */
2461         if (! NATIVE_IS_INVARIANT((U8)(*s)) && (this_utf8 || has_utf8)) {
2462             STRLEN len  = 1;
2463
2464
2465             /* One might think that it is wasted effort in the case of the
2466              * source being utf8 (this_utf8 == TRUE) to take the next character
2467              * in the source, convert it to an unsigned value, and then convert
2468              * it back again.  But the source has not been validated here.  The
2469              * routine that does the conversion checks for errors like
2470              * malformed utf8 */
2471
2472             const UV nextuv   = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2473             const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
2474             if (!has_utf8) {
2475                 SvCUR_set(sv, d - SvPVX_const(sv));
2476                 SvPOK_on(sv);
2477                 *d = '\0';
2478                 /* See Note on sizing above.  */
2479                 sv_utf8_upgrade_flags_grow(sv,
2480                                         SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2481                                         need + (STRLEN)(send - s) + 1);
2482                 d = SvPVX(sv) + SvCUR(sv);
2483                 has_utf8 = TRUE;
2484             } else if (need > len) {
2485                 /* encoded value larger than old, may need extra space (NOTE:
2486                  * SvCUR() is not set correctly here).   See Note on sizing
2487                  * above.  */
2488                 const STRLEN off = d - SvPVX_const(sv);
2489                 d = SvGROW(sv, off + need + (STRLEN)(send - s) + 1) + off;
2490             }
2491             s += len;
2492
2493             d = (char*)uvchr_to_utf8((U8*)d, nextuv);
2494 #ifdef EBCDIC
2495             if (uv > 255 && !dorange)
2496                 native_range = FALSE;
2497 #endif
2498         }
2499         else {
2500             *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2501         }
2502     } /* while loop to process each character */
2503
2504     /* terminate the string and set up the sv */
2505     *d = '\0';
2506     SvCUR_set(sv, d - SvPVX_const(sv));
2507     if (SvCUR(sv) >= SvLEN(sv))
2508         Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2509
2510     SvPOK_on(sv);
2511     if (PL_encoding && !has_utf8) {
2512         sv_recode_to_utf8(sv, PL_encoding);
2513         if (SvUTF8(sv))
2514             has_utf8 = TRUE;
2515     }
2516     if (has_utf8) {
2517         SvUTF8_on(sv);
2518         if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
2519             PL_sublex_info.sub_op->op_private |=
2520                     (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2521         }
2522     }
2523
2524     /* shrink the sv if we allocated more than we used */
2525     if (SvCUR(sv) + 5 < SvLEN(sv)) {
2526         SvPV_shrink_to_cur(sv);
2527     }
2528
2529     /* return the substring (via pl_yylval) only if we parsed anything */
2530     if (s > PL_bufptr) {
2531         if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) {
2532             const char *const key = PL_lex_inpat ? "qr" : "q";
2533             const STRLEN keylen = PL_lex_inpat ? 2 : 1;
2534             const char *type;
2535             STRLEN typelen;
2536
2537             if (PL_lex_inwhat == OP_TRANS) {
2538                 type = "tr";
2539                 typelen = 2;
2540             } else if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) {
2541                 type = "s";
2542                 typelen = 1;
2543             } else  {
2544                 type = "qq";
2545                 typelen = 2;
2546             }
2547
2548             sv = S_new_constant(aTHX_ start, s - start, key, keylen, sv, NULL,
2549                                 type, typelen);
2550         }
2551         pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
2552     } else
2553         SvREFCNT_dec(sv);
2554     return s;
2555 }
2556
2557 /* S_intuit_more
2558  * Returns TRUE if there's more to the expression (e.g., a subscript),
2559  * FALSE otherwise.
2560  *
2561  * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2562  *
2563  * ->[ and ->{ return TRUE
2564  * { and [ outside a pattern are always subscripts, so return TRUE
2565  * if we're outside a pattern and it's not { or [, then return FALSE
2566  * if we're in a pattern and the first char is a {
2567  *   {4,5} (any digits around the comma) returns FALSE
2568  * if we're in a pattern and the first char is a [
2569  *   [] returns FALSE
2570  *   [SOMETHING] has a funky algorithm to decide whether it's a
2571  *      character class or not.  It has to deal with things like
2572  *      /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2573  * anything else returns TRUE
2574  */
2575
2576 /* This is the one truly awful dwimmer necessary to conflate C and sed. */
2577
2578 STATIC int
2579 S_intuit_more(pTHX_ register char *s)
2580 {
2581     dVAR;
2582
2583     PERL_ARGS_ASSERT_INTUIT_MORE;
2584
2585     if (PL_lex_brackets)
2586         return TRUE;
2587     if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2588         return TRUE;
2589     if (*s != '{' && *s != '[')
2590         return FALSE;
2591     if (!PL_lex_inpat)
2592         return TRUE;
2593
2594     /* In a pattern, so maybe we have {n,m}. */
2595     if (*s == '{') {
2596         s++;
2597         if (!isDIGIT(*s))
2598             return TRUE;
2599         while (isDIGIT(*s))
2600             s++;
2601         if (*s == ',')
2602             s++;
2603         while (isDIGIT(*s))
2604             s++;
2605         if (*s == '}')
2606             return FALSE;
2607         return TRUE;
2608         
2609     }
2610
2611     /* On the other hand, maybe we have a character class */
2612
2613     s++;
2614     if (*s == ']' || *s == '^')
2615         return FALSE;
2616     else {
2617         /* this is terrifying, and it works */
2618         int weight = 2;         /* let's weigh the evidence */
2619         char seen[256];
2620         unsigned char un_char = 255, last_un_char;
2621         const char * const send = strchr(s,']');
2622         char tmpbuf[sizeof PL_tokenbuf * 4];
2623
2624         if (!send)              /* has to be an expression */
2625             return TRUE;
2626
2627         Zero(seen,256,char);
2628         if (*s == '$')
2629             weight -= 3;
2630         else if (isDIGIT(*s)) {
2631             if (s[1] != ']') {
2632                 if (isDIGIT(s[1]) && s[2] == ']')
2633                     weight -= 10;
2634             }
2635             else
2636                 weight -= 100;
2637         }
2638         for (; s < send; s++) {
2639             last_un_char = un_char;
2640             un_char = (unsigned char)*s;
2641             switch (*s) {
2642             case '@':
2643             case '&':
2644             case '$':
2645                 weight -= seen[un_char] * 10;
2646                 if (isALNUM_lazy_if(s+1,UTF)) {
2647                     int len;
2648                     scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
2649                     len = (int)strlen(tmpbuf);
2650                     if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
2651                         weight -= 100;
2652                     else
2653                         weight -= 10;
2654                 }
2655                 else if (*s == '$' && s[1] &&
2656                   strchr("[#!%*<>()-=",s[1])) {
2657                     if (/*{*/ strchr("])} =",s[2]))
2658                         weight -= 10;
2659                     else
2660                         weight -= 1;
2661                 }
2662                 break;
2663             case '\\':
2664                 un_char = 254;
2665                 if (s[1]) {
2666                     if (strchr("wds]",s[1]))
2667                         weight += 100;
2668                     else if (seen[(U8)'\''] || seen[(U8)'"'])
2669                         weight += 1;
2670                     else if (strchr("rnftbxcav",s[1]))
2671                         weight += 40;
2672                     else if (isDIGIT(s[1])) {
2673                         weight += 40;
2674                         while (s[1] && isDIGIT(s[1]))
2675                             s++;
2676                     }
2677                 }
2678                 else
2679                     weight += 100;
2680                 break;
2681             case '-':
2682                 if (s[1] == '\\')
2683                     weight += 50;
2684                 if (strchr("aA01! ",last_un_char))
2685                     weight += 30;
2686                 if (strchr("zZ79~",s[1]))
2687                     weight += 30;
2688                 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2689                     weight -= 5;        /* cope with negative subscript */
2690                 break;
2691             default:
2692                 if (!isALNUM(last_un_char)
2693                     && !(last_un_char == '$' || last_un_char == '@'
2694                          || last_un_char == '&')
2695                     && isALPHA(*s) && s[1] && isALPHA(s[1])) {
2696                     char *d = tmpbuf;
2697                     while (isALPHA(*s))
2698                         *d++ = *s++;
2699                     *d = '\0';
2700                     if (keyword(tmpbuf, d - tmpbuf, 0))
2701                         weight -= 150;
2702                 }
2703                 if (un_char == last_un_char + 1)
2704                     weight += 5;
2705                 weight -= seen[un_char];
2706                 break;
2707             }
2708             seen[un_char]++;
2709         }
2710         if (weight >= 0)        /* probably a character class */
2711             return FALSE;
2712     }
2713
2714     return TRUE;
2715 }
2716
2717 /*
2718  * S_intuit_method
2719  *
2720  * Does all the checking to disambiguate
2721  *   foo bar
2722  * between foo(bar) and bar->foo.  Returns 0 if not a method, otherwise
2723  * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2724  *
2725  * First argument is the stuff after the first token, e.g. "bar".
2726  *
2727  * Not a method if bar is a filehandle.
2728  * Not a method if foo is a subroutine prototyped to take a filehandle.
2729  * Not a method if it's really "Foo $bar"
2730  * Method if it's "foo $bar"
2731  * Not a method if it's really "print foo $bar"
2732  * Method if it's really "foo package::" (interpreted as package->foo)
2733  * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
2734  * Not a method if bar is a filehandle or package, but is quoted with
2735  *   =>
2736  */
2737
2738 STATIC int
2739 S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
2740 {
2741     dVAR;
2742     char *s = start + (*start == '$');
2743     char tmpbuf[sizeof PL_tokenbuf];
2744     STRLEN len;
2745     GV* indirgv;
2746 #ifdef PERL_MAD
2747     int soff;
2748 #endif
2749
2750     PERL_ARGS_ASSERT_INTUIT_METHOD;
2751
2752     if (gv) {
2753         if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
2754             return 0;
2755         if (cv) {
2756             if (SvPOK(cv)) {
2757                 const char *proto = SvPVX_const(cv);
2758                 if (proto) {
2759                     if (*proto == ';')
2760                         proto++;
2761                     if (*proto == '*')
2762                         return 0;
2763                 }
2764             }
2765         } else
2766             gv = NULL;
2767     }
2768     s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
2769     /* start is the beginning of the possible filehandle/object,
2770      * and s is the end of it
2771      * tmpbuf is a copy of it
2772      */
2773
2774     if (*start == '$') {
2775         if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
2776                 isUPPER(*PL_tokenbuf))
2777             return 0;
2778 #ifdef PERL_MAD
2779         len = start - SvPVX(PL_linestr);
2780 #endif
2781         s = PEEKSPACE(s);
2782 #ifdef PERL_MAD
2783         start = SvPVX(PL_linestr) + len;
2784 #endif
2785         PL_bufptr = start;
2786         PL_expect = XREF;
2787         return *s == '(' ? FUNCMETH : METHOD;
2788     }
2789     if (!keyword(tmpbuf, len, 0)) {
2790         if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2791             len -= 2;
2792             tmpbuf[len] = '\0';
2793 #ifdef PERL_MAD
2794             soff = s - SvPVX(PL_linestr);
2795 #endif
2796             goto bare_package;
2797         }
2798         indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
2799         if (indirgv && GvCVu(indirgv))
2800             return 0;
2801         /* filehandle or package name makes it a method */
2802         if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
2803 #ifdef PERL_MAD
2804             soff = s - SvPVX(PL_linestr);
2805 #endif
2806             s = PEEKSPACE(s);
2807             if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
2808                 return 0;       /* no assumptions -- "=>" quotes bearword */
2809       bare_package:
2810             start_force(PL_curforce);
2811             NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
2812                                                   S_newSV_maybe_utf8(aTHX_ tmpbuf, len));
2813             NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
2814             if (PL_madskills)
2815                 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
2816             PL_expect = XTERM;
2817             force_next(WORD);
2818             PL_bufptr = s;
2819 #ifdef PERL_MAD
2820             PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2821 #endif
2822             return *s == '(' ? FUNCMETH : METHOD;
2823         }
2824     }
2825     return 0;
2826 }
2827
2828 /* Encoded script support. filter_add() effectively inserts a
2829  * 'pre-processing' function into the current source input stream.
2830  * Note that the filter function only applies to the current source file
2831  * (e.g., it will not affect files 'require'd or 'use'd by this one).
2832  *
2833  * The datasv parameter (which may be NULL) can be used to pass
2834  * private data to this instance of the filter. The filter function
2835  * can recover the SV using the FILTER_DATA macro and use it to
2836  * store private buffers and state information.
2837  *
2838  * The supplied datasv parameter is upgraded to a PVIO type
2839  * and the IoDIRP/IoANY field is used to store the function pointer,
2840  * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
2841  * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2842  * private use must be set using malloc'd pointers.
2843  */
2844
2845 SV *
2846 Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
2847 {
2848     dVAR;
2849     if (!funcp)
2850         return NULL;
2851
2852     if (!PL_parser)
2853         return NULL;
2854
2855     if (!PL_rsfp_filters)
2856         PL_rsfp_filters = newAV();
2857     if (!datasv)
2858         datasv = newSV(0);
2859     SvUPGRADE(datasv, SVt_PVIO);
2860     IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
2861     IoFLAGS(datasv) |= IOf_FAKE_DIRP;
2862     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
2863                           FPTR2DPTR(void *, IoANY(datasv)),
2864                           SvPV_nolen(datasv)));
2865     av_unshift(PL_rsfp_filters, 1);
2866     av_store(PL_rsfp_filters, 0, datasv) ;
2867     return(datasv);
2868 }
2869
2870
2871 /* Delete most recently added instance of this filter function. */
2872 void
2873 Perl_filter_del(pTHX_ filter_t funcp)
2874 {
2875     dVAR;
2876     SV *datasv;
2877
2878     PERL_ARGS_ASSERT_FILTER_DEL;
2879
2880 #ifdef DEBUGGING
2881     DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2882                           FPTR2DPTR(void*, funcp)));
2883 #endif
2884     if (!PL_parser || !PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
2885         return;
2886     /* if filter is on top of stack (usual case) just pop it off */
2887     datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
2888     if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
2889         IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
2890         IoANY(datasv) = (void *)NULL;
2891         sv_free(av_pop(PL_rsfp_filters));
2892
2893         return;
2894     }
2895     /* we need to search for the correct entry and clear it     */
2896     Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
2897 }
2898
2899
2900 /* Invoke the idxth filter function for the current rsfp.        */
2901 /* maxlen 0 = read one text line */
2902 I32
2903 Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
2904 {
2905     dVAR;
2906     filter_t funcp;
2907     SV *datasv = NULL;
2908     /* This API is bad. It should have been using unsigned int for maxlen.
2909        Not sure if we want to change the API, but if not we should sanity
2910        check the value here.  */
2911     const unsigned int correct_length
2912         = maxlen < 0 ?
2913 #ifdef PERL_MICRO
2914         0x7FFFFFFF
2915 #else
2916         INT_MAX
2917 #endif
2918         : maxlen;
2919
2920     PERL_ARGS_ASSERT_FILTER_READ;
2921
2922     if (!PL_parser || !PL_rsfp_filters)
2923         return -1;
2924     if (idx > AvFILLp(PL_rsfp_filters)) {       /* Any more filters?    */
2925         /* Provide a default input filter to make life easy.    */
2926         /* Note that we append to the line. This is handy.      */
2927         DEBUG_P(PerlIO_printf(Perl_debug_log,
2928                               "filter_read %d: from rsfp\n", idx));
2929         if (correct_length) {
2930             /* Want a block */
2931             int len ;
2932             const int old_len = SvCUR(buf_sv);
2933
2934             /* ensure buf_sv is large enough */
2935             SvGROW(buf_sv, (STRLEN)(old_len + correct_length)) ;
2936             if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2937                                    correct_length)) <= 0) {
2938                 if (PerlIO_error(PL_rsfp))
2939                     return -1;          /* error */
2940                 else
2941                     return 0 ;          /* end of file */
2942             }
2943             SvCUR_set(buf_sv, old_len + len) ;
2944         } else {
2945             /* Want a line */
2946             if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2947                 if (PerlIO_error(PL_rsfp))
2948                     return -1;          /* error */
2949                 else
2950                     return 0 ;          /* end of file */
2951             }
2952         }
2953         return SvCUR(buf_sv);
2954     }
2955     /* Skip this filter slot if filter has been deleted */
2956     if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
2957         DEBUG_P(PerlIO_printf(Perl_debug_log,
2958                               "filter_read %d: skipped (filter deleted)\n",
2959                               idx));
2960         return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
2961     }
2962     /* Get function pointer hidden within datasv        */
2963     funcp = DPTR2FPTR(filter_t, IoANY(datasv));
2964     DEBUG_P(PerlIO_printf(Perl_debug_log,
2965                           "filter_read %d: via function %p (%s)\n",
2966                           idx, (void*)datasv, SvPV_nolen_const(datasv)));
2967     /* Call function. The function is expected to       */
2968     /* call "FILTER_READ(idx+1, buf_sv)" first.         */
2969     /* Return: <0:error, =0:eof, >0:not eof             */
2970     return (*funcp)(aTHX_ idx, buf_sv, correct_length);
2971 }
2972
2973 STATIC char *
2974 S_filter_gets(pTHX_ register SV *sv, register PerlIO *fp, STRLEN append)
2975 {
2976     dVAR;
2977
2978     PERL_ARGS_ASSERT_FILTER_GETS;
2979
2980 #ifdef PERL_CR_FILTER
2981     if (!PL_rsfp_filters) {
2982         filter_add(S_cr_textfilter,NULL);
2983     }
2984 #endif
2985     if (PL_rsfp_filters) {
2986         if (!append)
2987             SvCUR_set(sv, 0);   /* start with empty line        */
2988         if (FILTER_READ(0, sv, 0) > 0)
2989             return ( SvPVX(sv) ) ;
2990         else
2991             return NULL ;
2992     }
2993     else
2994         return (sv_gets(sv, fp, append));
2995 }
2996
2997 STATIC HV *
2998 S_find_in_my_stash(pTHX_ const char *pkgname, STRLEN len)
2999 {
3000     dVAR;
3001     GV *gv;
3002
3003     PERL_ARGS_ASSERT_FIND_IN_MY_STASH;
3004
3005     if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
3006         return PL_curstash;
3007
3008     if (len > 2 &&
3009         (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
3010         (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
3011     {
3012         return GvHV(gv);                        /* Foo:: */
3013     }
3014
3015     /* use constant CLASS => 'MyClass' */
3016     gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
3017     if (gv && GvCV(gv)) {
3018         SV * const sv = cv_const_sv(GvCV(gv));
3019         if (sv)
3020             pkgname = SvPV_const(sv, len);
3021     }
3022
3023     return gv_stashpvn(pkgname, len, 0);
3024 }
3025
3026 /*
3027  * S_readpipe_override
3028  * Check whether readpipe() is overriden, and generates the appropriate
3029  * optree, provided sublex_start() is called afterwards.
3030  */
3031 STATIC void
3032 S_readpipe_override(pTHX)
3033 {
3034     GV **gvp;
3035     GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
3036     pl_yylval.ival = OP_BACKTICK;
3037     if ((gv_readpipe
3038                 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
3039             ||
3040             ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
3041              && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
3042              && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
3043     {
3044         PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
3045             append_elem(OP_LIST,
3046                 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
3047                 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
3048     }
3049 }
3050
3051 #ifdef PERL_MAD 
3052  /*
3053  * Perl_madlex
3054  * The intent of this yylex wrapper is to minimize the changes to the
3055  * tokener when we aren't interested in collecting madprops.  It remains
3056  * to be seen how successful this strategy will be...
3057  */
3058
3059 int
3060 Perl_madlex(pTHX)
3061 {
3062     int optype;
3063     char *s = PL_bufptr;
3064
3065     /* make sure PL_thiswhite is initialized */
3066     PL_thiswhite = 0;
3067     PL_thismad = 0;
3068
3069     /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
3070     if (PL_pending_ident)
3071         return S_pending_ident(aTHX);
3072
3073     /* previous token ate up our whitespace? */
3074     if (!PL_lasttoke && PL_nextwhite) {
3075         PL_thiswhite = PL_nextwhite;
3076         PL_nextwhite = 0;
3077     }
3078
3079     /* isolate the token, and figure out where it is without whitespace */
3080     PL_realtokenstart = -1;
3081     PL_thistoken = 0;
3082     optype = yylex();
3083     s = PL_bufptr;
3084     assert(PL_curforce < 0);
3085
3086     if (!PL_thismad || PL_thismad->mad_key == '^') {    /* not forced already? */
3087         if (!PL_thistoken) {
3088             if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
3089                 PL_thistoken = newSVpvs("");
3090             else {
3091                 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
3092                 PL_thistoken = newSVpvn(tstart, s - tstart);
3093             }
3094         }
3095         if (PL_thismad) /* install head */
3096             CURMAD('X', PL_thistoken);
3097     }
3098
3099     /* last whitespace of a sublex? */
3100     if (optype == ')' && PL_endwhite) {
3101         CURMAD('X', PL_endwhite);
3102     }
3103
3104     if (!PL_thismad) {
3105
3106         /* if no whitespace and we're at EOF, bail.  Otherwise fake EOF below. */
3107         if (!PL_thiswhite && !PL_endwhite && !optype) {
3108             sv_free(PL_thistoken);
3109             PL_thistoken = 0;
3110             return 0;
3111         }
3112
3113         /* put off final whitespace till peg */
3114         if (optype == ';' && !PL_rsfp) {
3115             PL_nextwhite = PL_thiswhite;
3116             PL_thiswhite = 0;
3117         }
3118         else if (PL_thisopen) {
3119             CURMAD('q', PL_thisopen);
3120             if (PL_thistoken)
3121                 sv_free(PL_thistoken);
3122             PL_thistoken = 0;
3123         }
3124         else {
3125             /* Store actual token text as madprop X */
3126             CURMAD('X', PL_thistoken);
3127         }
3128
3129         if (PL_thiswhite) {
3130             /* add preceding whitespace as madprop _ */
3131             CURMAD('_', PL_thiswhite);
3132         }
3133
3134         if (PL_thisstuff) {
3135             /* add quoted material as madprop = */
3136             CURMAD('=', PL_thisstuff);
3137         }
3138
3139         if (PL_thisclose) {
3140             /* add terminating quote as madprop Q */
3141             CURMAD('Q', PL_thisclose);
3142         }
3143     }
3144
3145     /* special processing based on optype */
3146
3147     switch (optype) {
3148
3149     /* opval doesn't need a TOKEN since it can already store mp */
3150     case WORD:
3151     case METHOD:
3152     case FUNCMETH:
3153     case THING:
3154     case PMFUNC:
3155     case PRIVATEREF:
3156     case FUNC0SUB:
3157     case UNIOPSUB:
3158     case LSTOPSUB:
3159         if (pl_yylval.opval)
3160             append_madprops(PL_thismad, pl_yylval.opval, 0);
3161         PL_thismad = 0;
3162         return optype;
3163
3164     /* fake EOF */
3165     case 0:
3166         optype = PEG;
3167         if (PL_endwhite) {
3168             addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3169             PL_endwhite = 0;
3170         }
3171         break;
3172
3173     case ']':
3174     case '}':
3175         if (PL_faketokens)
3176             break;
3177         /* remember any fake bracket that lexer is about to discard */ 
3178         if (PL_lex_brackets == 1 &&
3179             ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3180         {
3181             s = PL_bufptr;
3182             while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3183                 s++;
3184             if (*s == '}') {
3185                 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3186                 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3187                 PL_thiswhite = 0;
3188                 PL_bufptr = s - 1;
3189                 break;  /* don't bother looking for trailing comment */
3190             }
3191             else
3192                 s = PL_bufptr;
3193         }
3194         if (optype == ']')
3195             break;
3196         /* FALLTHROUGH */
3197
3198     /* attach a trailing comment to its statement instead of next token */
3199     case ';':
3200         if (PL_faketokens)
3201             break;
3202         if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3203             s = PL_bufptr;
3204             while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3205                 s++;
3206             if (*s == '\n' || *s == '#') {
3207                 while (s < PL_bufend && *s != '\n')
3208                     s++;
3209                 if (s < PL_bufend)
3210                     s++;
3211                 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3212                 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3213                 PL_thiswhite = 0;
3214                 PL_bufptr = s;
3215             }
3216         }
3217         break;
3218
3219     /* pval */
3220     case LABEL:
3221         break;
3222
3223     /* ival */
3224     default:
3225         break;
3226
3227     }
3228
3229     /* Create new token struct.  Note: opvals return early above. */
3230     pl_yylval.tkval = newTOKEN(optype, pl_yylval, PL_thismad);
3231     PL_thismad = 0;
3232     return optype;
3233 }
3234 #endif
3235
3236 STATIC char *
3237 S_tokenize_use(pTHX_ int is_use, char *s) {
3238     dVAR;
3239
3240     PERL_ARGS_ASSERT_TOKENIZE_USE;
3241
3242     if (PL_expect != XSTATE)
3243         yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3244                     is_use ? "use" : "no"));
3245     s = SKIPSPACE1(s);
3246     if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3247         s = force_version(s, TRUE);
3248         if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
3249             start_force(PL_curforce);
3250             NEXTVAL_NEXTTOKE.opval = NULL;
3251             force_next(WORD);
3252         }
3253         else if (*s == 'v') {
3254             s = force_word(s,WORD,FALSE,TRUE,FALSE);
3255             s = force_version(s, FALSE);
3256         }
3257     }
3258     else {
3259         s = force_word(s,WORD,FALSE,TRUE,FALSE);
3260         s = force_version(s, FALSE);
3261     }
3262     pl_yylval.ival = is_use;
3263     return s;
3264 }
3265 #ifdef DEBUGGING
3266     static const char* const exp_name[] =
3267         { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
3268           "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
3269         };
3270 #endif
3271
3272 /*
3273   yylex
3274
3275   Works out what to call the token just pulled out of the input
3276   stream.  The yacc parser takes care of taking the ops we return and
3277   stitching them into a tree.
3278
3279   Returns:
3280     PRIVATEREF
3281
3282   Structure:
3283       if read an identifier
3284           if we're in a my declaration
3285               croak if they tried to say my($foo::bar)
3286               build the ops for a my() declaration
3287           if it's an access to a my() variable
3288               are we in a sort block?
3289                   croak if my($a); $a <=> $b
3290               build ops for access to a my() variable
3291           if in a dq string, and they've said @foo and we can't find @foo
3292               croak
3293           build ops for a bareword
3294       if we already built the token before, use it.
3295 */
3296
3297
3298 #ifdef __SC__
3299 #pragma segment Perl_yylex
3300 #endif
3301 int
3302 Perl_yylex(pTHX)
3303 {
3304     dVAR;
3305     register char *s = PL_bufptr;
3306     register char *d;
3307     STRLEN len;
3308     bool bof = FALSE;
3309
3310     /* orig_keyword, gvp, and gv are initialized here because
3311      * jump to the label just_a_word_zero can bypass their
3312      * initialization later. */
3313     I32 orig_keyword = 0;
3314     GV *gv = NULL;
3315     GV **gvp = NULL;
3316
3317     DEBUG_T( {
3318         SV* tmp = newSVpvs("");
3319         PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3320             (IV)CopLINE(PL_curcop),
3321             lex_state_names[PL_lex_state],
3322             exp_name[PL_expect],
3323             pv_display(tmp, s, strlen(s), 0, 60));
3324         SvREFCNT_dec(tmp);
3325     } );
3326     /* check if there's an identifier for us to look at */
3327     if (PL_pending_ident)
3328         return REPORT(S_pending_ident(aTHX));
3329
3330     /* no identifier pending identification */
3331
3332     switch (PL_lex_state) {
3333 #ifdef COMMENTARY
3334     case LEX_NORMAL:            /* Some compilers will produce faster */
3335     case LEX_INTERPNORMAL:      /* code if we comment these out. */
3336         break;
3337 #endif
3338
3339     /* when we've already built the next token, just pull it out of the queue */
3340     case LEX_KNOWNEXT:
3341 #ifdef PERL_MAD
3342         PL_lasttoke--;
3343         pl_yylval = PL_nexttoke[PL_lasttoke].next_val;
3344         if (PL_madskills) {
3345             PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
3346             PL_nexttoke[PL_lasttoke].next_mad = 0;
3347             if (PL_thismad && PL_thismad->mad_key == '_') {
3348                 PL_thiswhite = MUTABLE_SV(PL_thismad->mad_val);
3349                 PL_thismad->mad_val = 0;
3350                 mad_free(PL_thismad);
3351                 PL_thismad = 0;
3352             }
3353         }
3354         if (!PL_lasttoke) {
3355             PL_lex_state = PL_lex_defer;
3356             PL_expect = PL_lex_expect;
3357             PL_lex_defer = LEX_NORMAL;
3358             if (!PL_nexttoke[PL_lasttoke].next_type)
3359                 return yylex();
3360         }
3361 #else
3362         PL_nexttoke--;
3363         pl_yylval = PL_nextval[PL_nexttoke];
3364         if (!PL_nexttoke) {
3365             PL_lex_state = PL_lex_defer;
3366             PL_expect = PL_lex_expect;
3367             PL_lex_defer = LEX_NORMAL;
3368         }
3369 #endif
3370 #ifdef PERL_MAD
3371         /* FIXME - can these be merged?  */
3372         return(PL_nexttoke[PL_lasttoke].next_type);
3373 #else
3374         return REPORT(PL_nexttype[PL_nexttoke]);
3375 #endif
3376
3377     /* interpolated case modifiers like \L \U, including \Q and \E.
3378        when we get here, PL_bufptr is at the \
3379     */
3380     case LEX_INTERPCASEMOD:
3381 #ifdef DEBUGGING
3382         if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
3383             Perl_croak(aTHX_ "panic: INTERPCASEMOD");
3384 #endif
3385         /* handle \E or end of string */
3386         if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
3387             /* if at a \E */
3388             if (PL_lex_casemods) {
3389                 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3390                 PL_lex_casestack[PL_lex_casemods] = '\0';
3391
3392                 if (PL_bufptr != PL_bufend
3393                     && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3394                     PL_bufptr += 2;
3395                     PL_lex_state = LEX_INTERPCONCAT;
3396 #ifdef PERL_MAD
3397                     if (PL_madskills)
3398                         PL_thistoken = newSVpvs("\\E");
3399 #endif
3400                 }
3401                 return REPORT(')');
3402             }
3403 #ifdef PERL_MAD
3404             while (PL_bufptr != PL_bufend &&
3405               PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
3406                 if (!PL_thiswhite)
3407                     PL_thiswhite = newSVpvs("");
3408                 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
3409                 PL_bufptr += 2;
3410             }
3411 #else
3412             if (PL_bufptr != PL_bufend)
3413                 PL_bufptr += 2;
3414 #endif
3415             PL_lex_state = LEX_INTERPCONCAT;
3416             return yylex();
3417         }
3418         else {
3419             DEBUG_T({ PerlIO_printf(Perl_debug_log,
3420               "### Saw case modifier\n"); });
3421             s = PL_bufptr + 1;
3422             if (s[1] == '\\' && s[2] == 'E') {
3423 #ifdef PERL_MAD
3424                 if (!PL_thiswhite)
3425                     PL_thiswhite = newSVpvs("");
3426                 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
3427 #endif
3428                 PL_bufptr = s + 3;
3429                 PL_lex_state = LEX_INTERPCONCAT;
3430                 return yylex();
3431             }
3432             else {
3433                 I32 tmp;
3434                 if (!PL_madskills) /* when just compiling don't need correct */
3435                     if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3436                         tmp = *s, *s = s[2], s[2] = (char)tmp;  /* misordered... */
3437                 if ((*s == 'L' || *s == 'U') &&
3438                     (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3439                     PL_lex_casestack[--PL_lex_casemods] = '\0';
3440                     return REPORT(')');
3441                 }
3442                 if (PL_lex_casemods > 10)
3443                     Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3444                 PL_lex_casestack[PL_lex_casemods++] = *s;
3445                 PL_lex_casestack[PL_lex_casemods] = '\0';
3446                 PL_lex_state = LEX_INTERPCONCAT;
3447                 start_force(PL_curforce);
3448                 NEXTVAL_NEXTTOKE.ival = 0;
3449                 force_next('(');
3450                 start_force(PL_curforce);
3451                 if (*s == 'l')
3452                     NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
3453                 else if (*s == 'u')
3454                     NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
3455                 else if (*s == 'L')
3456                     NEXTVAL_NEXTTOKE.ival = OP_LC;
3457                 else if (*s == 'U')
3458                     NEXTVAL_NEXTTOKE.ival = OP_UC;
3459                 else if (*s == 'Q')
3460                     NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
3461                 else
3462                     Perl_croak(aTHX_ "panic: yylex");
3463                 if (PL_madskills) {
3464                     SV* const tmpsv = newSVpvs("\\ ");
3465                     /* replace the space with the character we want to escape
3466                      */
3467                     SvPVX(tmpsv)[1] = *s;
3468                     curmad('_', tmpsv);
3469                 }
3470                 PL_bufptr = s + 1;
3471             }
3472             force_next(FUNC);
3473             if (PL_lex_starts) {
3474                 s = PL_bufptr;
3475                 PL_lex_starts = 0;
3476 #ifdef PERL_MAD
3477                 if (PL_madskills) {
3478                     if (PL_thistoken)
3479                         sv_free(PL_thistoken);
3480                     PL_thistoken = newSVpvs("");
3481                 }
3482 #endif
3483                 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3484                 if (PL_lex_casemods == 1 && PL_lex_inpat)
3485                     OPERATOR(',');
3486                 else
3487                     Aop(OP_CONCAT);
3488             }
3489             else
3490                 return yylex();
3491         }
3492
3493     case LEX_INTERPPUSH:
3494         return REPORT(sublex_push());
3495
3496     case LEX_INTERPSTART:
3497         if (PL_bufptr == PL_bufend)
3498             return REPORT(sublex_done());
3499         DEBUG_T({ PerlIO_printf(Perl_debug_log,
3500               "### Interpolated variable\n"); });
3501         PL_expect = XTERM;
3502         PL_lex_dojoin = (*PL_bufptr == '@');
3503         PL_lex_state = LEX_INTERPNORMAL;
3504         if (PL_lex_dojoin) {
3505             start_force(PL_curforce);
3506             NEXTVAL_NEXTTOKE.ival = 0;
3507             force_next(',');
3508             start_force(PL_curforce);
3509             force_ident("\"", '$');
3510             start_force(PL_curforce);
3511             NEXTVAL_NEXTTOKE.ival = 0;
3512             force_next('$');
3513             start_force(PL_curforce);
3514             NEXTVAL_NEXTTOKE.ival = 0;
3515             force_next('(');
3516             start_force(PL_curforce);
3517             NEXTVAL_NEXTTOKE.ival = OP_JOIN;    /* emulate join($", ...) */
3518             force_next(FUNC);
3519         }
3520         if (PL_lex_starts++) {
3521             s = PL_bufptr;
3522 #ifdef PERL_MAD
3523             if (PL_madskills) {
3524                 if (PL_thistoken)
3525                     sv_free(PL_thistoken);
3526                 PL_thistoken = newSVpvs("");
3527             }
3528 #endif
3529             /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3530             if (!PL_lex_casemods && PL_lex_inpat)
3531                 OPERATOR(',');
3532             else
3533                 Aop(OP_CONCAT);
3534         }
3535         return yylex();
3536
3537     case LEX_INTERPENDMAYBE:
3538         if (intuit_more(PL_bufptr)) {
3539             PL_lex_state = LEX_INTERPNORMAL;    /* false alarm, more expr */
3540             break;
3541         }
3542         /* FALL THROUGH */
3543
3544     case LEX_INTERPEND:
3545         if (PL_lex_dojoin) {
3546             PL_lex_dojoin = FALSE;
3547             PL_lex_state = LEX_INTERPCONCAT;
3548 #ifdef PERL_MAD
3549             if (PL_madskills) {
3550                 if (PL_thistoken)
3551                     sv_free(PL_thistoken);
3552                 PL_thistoken = newSVpvs("");
3553             }
3554 #endif
3555             return REPORT(')');
3556         }
3557         if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
3558             && SvEVALED(PL_lex_repl))
3559         {
3560             if (PL_bufptr != PL_bufend)
3561                 Perl_croak(aTHX_ "Bad evalled substitution pattern");
3562             PL_lex_repl = NULL;
3563         }
3564         /* FALLTHROUGH */
3565     case LEX_INTERPCONCAT:
3566 #ifdef DEBUGGING
3567         if (PL_lex_brackets)
3568             Perl_croak(aTHX_ "panic: INTERPCONCAT");
3569 #endif
3570         if (PL_bufptr == PL_bufend)
3571             return REPORT(sublex_done());
3572
3573         if (SvIVX(PL_linestr) == '\'') {
3574             SV *sv = newSVsv(PL_linestr);
3575             if (!PL_lex_inpat)
3576                 sv = tokeq(sv);
3577             else if ( PL_hints & HINT_NEW_RE )
3578                 sv = new_constant(NULL, 0, "qr", sv, sv, "q", 1);
3579             pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3580             s = PL_bufend;
3581         }
3582         else {
3583             s = scan_const(PL_bufptr);
3584             if (*s == '\\')
3585                 PL_lex_state = LEX_INTERPCASEMOD;
3586             else
3587                 PL_lex_state = LEX_INTERPSTART;
3588         }
3589
3590         if (s != PL_bufptr) {
3591             start_force(PL_curforce);
3592             if (PL_madskills) {
3593                 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3594             }
3595             NEXTVAL_NEXTTOKE = pl_yylval;
3596             PL_expect = XTERM;
3597             force_next(THING);
3598             if (PL_lex_starts++) {
3599 #ifdef PERL_MAD
3600                 if (PL_madskills) {
3601                     if (PL_thistoken)
3602                         sv_free(PL_thistoken);
3603                     PL_thistoken = newSVpvs("");
3604                 }
3605 #endif
3606                 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3607                 if (!PL_lex_casemods && PL_lex_inpat)
3608                     OPERATOR(',');
3609                 else
3610                     Aop(OP_CONCAT);
3611             }
3612             else {
3613                 PL_bufptr = s;
3614                 return yylex();
3615             }
3616         }
3617
3618         return yylex();
3619     case LEX_FORMLINE:
3620         PL_lex_state = LEX_NORMAL;
3621         s = scan_formline(PL_bufptr);
3622         if (!PL_lex_formbrack)
3623             goto rightbracket;
3624         OPERATOR(';');
3625     }
3626
3627     s = PL_bufptr;
3628     PL_oldoldbufptr = PL_oldbufptr;
3629     PL_oldbufptr = s;
3630
3631   retry:
3632 #ifdef PERL_MAD
3633     if (PL_thistoken) {
3634         sv_free(PL_thistoken);
3635         PL_thistoken = 0;
3636     }
3637     PL_realtokenstart = s - SvPVX(PL_linestr);  /* assume but undo on ws */
3638 #endif
3639     switch (*s) {
3640     default:
3641         if (isIDFIRST_lazy_if(s,UTF))
3642             goto keylookup;
3643         {
3644         unsigned char c = *s;
3645         len = UTF ? Perl_utf8_length(aTHX_ (U8 *) PL_linestart, (U8 *) s) : (STRLEN) (s - PL_linestart);
3646         if (len > UNRECOGNIZED_PRECEDE_COUNT) {
3647             d = UTF ? (char *) Perl_utf8_hop(aTHX_ (U8 *) s, -UNRECOGNIZED_PRECEDE_COUNT) : s - UNRECOGNIZED_PRECEDE_COUNT;
3648         } else {
3649             d = PL_linestart;
3650         }       
3651         *s = '\0';
3652         Perl_croak(aTHX_ "Unrecognized character \\x%02X; marked by <-- HERE after %s<-- HERE near column %d", c, d, (int) len + 1);
3653     }
3654     case 4:
3655     case 26:
3656         goto fake_eof;                  /* emulate EOF on ^D or ^Z */
3657     case 0:
3658 #ifdef PERL_MAD
3659         if (PL_madskills)
3660             PL_faketokens = 0;
3661 #endif
3662         if (!PL_rsfp) {
3663             PL_last_uni = 0;
3664             PL_last_lop = 0;
3665             if (PL_lex_brackets) {
3666                 yyerror((const char *)
3667                         (PL_lex_formbrack
3668                          ? "Format not terminated"
3669                          : "Missing right curly or square bracket"));
3670             }
3671             DEBUG_T( { PerlIO_printf(Perl_debug_log,
3672                         "### Tokener got EOF\n");
3673             } );
3674             TOKEN(0);
3675         }
3676         if (s++ < PL_bufend)
3677             goto retry;                 /* ignore stray nulls */
3678         PL_last_uni = 0;
3679         PL_last_lop = 0;
3680         if (!PL_in_eval && !PL_preambled) {
3681             PL_preambled = TRUE;
3682 #ifdef PERL_MAD
3683             if (PL_madskills)
3684                 PL_faketokens = 1;
3685 #endif
3686             if (PL_perldb) {
3687                 /* Generate a string of Perl code to load the debugger.
3688                  * If PERL5DB is set, it will return the contents of that,
3689                  * otherwise a compile-time require of perl5db.pl.  */
3690
3691                 const char * const pdb = PerlEnv_getenv("PERL5DB");
3692
3693                 if (pdb) {
3694                     sv_setpv(PL_linestr, pdb);
3695                     sv_catpvs(PL_linestr,";");
3696                 } else {
3697                     SETERRNO(0,SS_NORMAL);
3698                     sv_setpvs(PL_linestr, "BEGIN { require 'perl5db.pl' };");
3699                 }
3700             } else
3701                 sv_setpvs(PL_linestr,"");
3702             if (PL_preambleav) {
3703                 SV **svp = AvARRAY(PL_preambleav);
3704                 SV **const end = svp + AvFILLp(PL_preambleav);
3705                 while(svp <= end) {
3706                     sv_catsv(PL_linestr, *svp);
3707                     ++svp;
3708                     sv_catpvs(PL_linestr, ";");
3709                 }
3710                 sv_free(MUTABLE_SV(PL_preambleav));
3711                 PL_preambleav = NULL;
3712             }
3713             if (PL_minus_E)
3714                 sv_catpvs(PL_linestr,
3715                           "use feature ':5." STRINGIFY(PERL_VERSION) "';");
3716             if (PL_minus_n || PL_minus_p) {
3717                 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3718                 if (PL_minus_l)
3719                     sv_catpvs(PL_linestr,"chomp;");
3720                 if (PL_minus_a) {
3721                     if (PL_minus_F) {
3722                         if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3723                              || *PL_splitstr == '"')
3724                               && strchr(PL_splitstr + 1, *PL_splitstr))
3725                             Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
3726                         else {
3727                             /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3728                                bytes can be used as quoting characters.  :-) */
3729                             const char *splits = PL_splitstr;
3730                             sv_catpvs(PL_linestr, "our @F=split(q\0");
3731                             do {
3732                                 /* Need to \ \s  */
3733                                 if (*splits == '\\')
3734                                     sv_catpvn(PL_linestr, splits, 1);
3735                                 sv_catpvn(PL_linestr, splits, 1);
3736                             } while (*splits++);
3737                             /* This loop will embed the trailing NUL of
3738                                PL_linestr as the last thing it does before
3739                                terminating.  */
3740                             sv_catpvs(PL_linestr, ");");
3741                         }
3742                     }
3743                     else
3744                         sv_catpvs(PL_linestr,"our @F=split(' ');");
3745                 }
3746             }
3747             sv_catpvs(PL_linestr, "\n");
3748             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3749             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3750             PL_last_lop = PL_last_uni = NULL;
3751             if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
3752                 update_debugger_info(PL_linestr, NULL, 0);
3753             goto retry;
3754         }
3755         do {
3756             bof = PL_rsfp ? TRUE : FALSE;
3757             if ((s = filter_gets(PL_linestr, PL_rsfp, 0)) == NULL) {
3758               fake_eof:
3759 #ifdef PERL_MAD
3760                 PL_realtokenstart = -1;
3761 #endif
3762                 if (PL_rsfp) {
3763                     if ((PerlIO *)PL_rsfp == PerlIO_stdin())
3764                         PerlIO_clearerr(PL_rsfp);
3765                     else
3766                         (void)PerlIO_close(PL_rsfp);
3767                     PL_rsfp = NULL;
3768                     PL_doextract = FALSE;
3769                 }
3770                 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
3771 #ifdef PERL_MAD
3772                     if (PL_madskills)
3773                         PL_faketokens = 1;
3774 #endif
3775                     if (PL_minus_p)
3776                         sv_setpvs(PL_linestr, ";}continue{print;}");
3777                     else
3778                         sv_setpvs(PL_linestr, ";}");
3779                     PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3780                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3781                     PL_last_lop = PL_last_uni = NULL;
3782                     PL_minus_n = PL_minus_p = 0;
3783                     goto retry;
3784                 }
3785                 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3786                 PL_last_lop = PL_last_uni = NULL;
3787                 sv_setpvs(PL_linestr,"");
3788                 TOKEN(';');     /* not infinite loop because rsfp is NULL now */
3789             }
3790             /* If it looks like the start of a BOM or raw UTF-16,
3791              * check if it in fact is. */
3792             else if (bof &&
3793                      (*s == 0 ||
3794                       *(U8*)s == 0xEF ||
3795                       *(U8*)s >= 0xFE ||
3796                       s[1] == 0)) {
3797 #ifdef PERLIO_IS_STDIO
3798 #  ifdef __GNU_LIBRARY__
3799 #    if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
3800 #      define FTELL_FOR_PIPE_IS_BROKEN
3801 #    endif
3802 #  else
3803 #    ifdef __GLIBC__
3804 #      if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3805 #        define FTELL_FOR_PIPE_IS_BROKEN
3806 #      endif
3807 #    endif
3808 #  endif
3809 #endif
3810                 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
3811                 if (bof) {
3812                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3813                     s = swallow_bom((U8*)s);
3814                 }
3815             }
3816             if (PL_doextract) {
3817                 /* Incest with pod. */
3818 #ifdef PERL_MAD
3819                 if (PL_madskills)
3820                     sv_catsv(PL_thiswhite, PL_linestr);
3821 #endif
3822                 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
3823                     sv_setpvs(PL_linestr, "");
3824                     PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3825                     PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3826                     PL_last_lop = PL_last_uni = NULL;
3827                     PL_doextract = FALSE;
3828                 }
3829             }
3830             incline(s);
3831         } while (PL_doextract);
3832         PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
3833         if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
3834             update_debugger_info(PL_linestr, NULL, 0);
3835         PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
3836         PL_last_lop = PL_last_uni = NULL;
3837         if (CopLINE(PL_curcop) == 1) {
3838             while (s < PL_bufend && isSPACE(*s))
3839                 s++;
3840             if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
3841                 s++;
3842 #ifdef PERL_MAD
3843             if (PL_madskills)
3844                 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
3845 #endif
3846             d = NULL;
3847             if (!PL_in_eval) {
3848                 if (*s == '#' && *(s+1) == '!')
3849                     d = s + 2;
3850 #ifdef ALTERNATE_SHEBANG
3851                 else {
3852                     static char const as[] = ALTERNATE_SHEBANG;
3853                     if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3854                         d = s + (sizeof(as) - 1);
3855                 }
3856 #endif /* ALTERNATE_SHEBANG */
3857             }
3858             if (d) {
3859                 char *ipath;
3860                 char *ipathend;
3861
3862                 while (isSPACE(*d))
3863                     d++;
3864                 ipath = d;
3865                 while (*d && !isSPACE(*d))
3866                     d++;
3867                 ipathend = d;
3868
3869 #ifdef ARG_ZERO_IS_SCRIPT
3870                 if (ipathend > ipath) {
3871                     /*
3872                      * HP-UX (at least) sets argv[0] to the script name,
3873                      * which makes $^X incorrect.  And Digital UNIX and Linux,
3874                      * at least, set argv[0] to the basename of the Perl
3875                      * interpreter. So, having found "#!", we'll set it right.
3876                      */
3877                     SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3878                                                     SVt_PV)); /* $^X */
3879                     assert(SvPOK(x) || SvGMAGICAL(x));
3880                     if (sv_eq(x, CopFILESV(PL_curcop))) {
3881                         sv_setpvn(x, ipath, ipathend - ipath);
3882                         SvSETMAGIC(x);
3883                     }
3884                     else {
3885                         STRLEN blen;
3886                         STRLEN llen;
3887                         const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
3888                         const char * const lstart = SvPV_const(x,llen);
3889                         if (llen < blen) {
3890                             bstart += blen - llen;
3891                             if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3892                                 sv_setpvn(x, ipath, ipathend - ipath);
3893                                 SvSETMAGIC(x);
3894                             }
3895                         }
3896                     }
3897                     TAINT_NOT;  /* $^X is always tainted, but that's OK */
3898                 }
3899 #endif /* ARG_ZERO_IS_SCRIPT */
3900
3901                 /*
3902                  * Look for options.
3903                  */
3904                 d = instr(s,"perl -");
3905                 if (!d) {
3906                     d = instr(s,"perl");
3907 #if defined(DOSISH)
3908                     /* avoid getting into infinite loops when shebang
3909                      * line contains "Perl" rather than "perl" */
3910                     if (!d) {
3911                         for (d = ipathend-4; d >= ipath; --d) {
3912                             if ((*d == 'p' || *d == 'P')
3913                                 && !ibcmp(d, "perl", 4))
3914                             {
3915                                 break;
3916                             }
3917                         }
3918                         if (d < ipath)
3919                             d = NULL;
3920                     }
3921 #endif
3922                 }
3923 #ifdef ALTERNATE_SHEBANG
3924                 /*
3925                  * If the ALTERNATE_SHEBANG on this system starts with a
3926                  * character that can be part of a Perl expression, then if
3927                  * we see it but not "perl", we're probably looking at the
3928                  * start of Perl code, not a request to hand off to some
3929                  * other interpreter.  Similarly, if "perl" is there, but
3930                  * not in the first 'word' of the line, we assume the line
3931                  * contains the start of the Perl program.
3932                  */
3933                 if (d && *s != '#') {
3934                     const char *c = ipath;
3935                     while (*c && !strchr("; \t\r\n\f\v#", *c))
3936                         c++;
3937                     if (c < d)
3938                         d = NULL;       /* "perl" not in first word; ignore */
3939                     else
3940                         *s = '#';       /* Don't try to parse shebang line */
3941                 }
3942 #endif /* ALTERNATE_SHEBANG */
3943                 if (!d &&
3944                     *s == '#' &&
3945                     ipathend > ipath &&
3946                     !PL_minus_c &&
3947                     !instr(s,"indir") &&
3948                     instr(PL_origargv[0],"perl"))
3949                 {
3950                     dVAR;
3951                     char **newargv;
3952
3953                     *ipathend = '\0';
3954                     s = ipathend + 1;
3955                     while (s < PL_bufend && isSPACE(*s))
3956                         s++;
3957                     if (s < PL_bufend) {
3958                         Newx(newargv,PL_origargc+3,char*);
3959                         newargv[1] = s;
3960                         while (s < PL_bufend && !isSPACE(*s))
3961                             s++;
3962                         *s = '\0';
3963                         Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
3964                     }
3965                     else
3966                         newargv = PL_origargv;
3967                     newargv[0] = ipath;
3968                     PERL_FPU_PRE_EXEC
3969                     PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
3970                     PERL_FPU_POST_EXEC
3971                     Perl_croak(aTHX_ "Can't exec %s", ipath);
3972                 }
3973                 if (d) {
3974                     while (*d && !isSPACE(*d))
3975                         d++;
3976                     while (SPACE_OR_TAB(*d))
3977                         d++;
3978
3979                     if (*d++ == '-') {
3980                         const bool switches_done = PL_doswitches;
3981                         const U32 oldpdb = PL_perldb;
3982                         const bool oldn = PL_minus_n;
3983                         const bool oldp = PL_minus_p;
3984                         const char *d1 = d;
3985
3986                         do {
3987                             bool baduni = FALSE;
3988                             if (*d1 == 'C') {
3989                                 const char *d2 = d1 + 1;
3990                                 if (parse_unicode_opts((const char **)&d2)
3991                                     != PL_unicode)
3992                                     baduni = TRUE;
3993                             }
3994                             if (baduni || *d1 == 'M' || *d1 == 'm') {
3995                                 const char * const m = d1;
3996                                 while (*d1 && !isSPACE(*d1))
3997                                     d1++;
3998                                 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
3999                                       (int)(d1 - m), m);
4000                             }
4001                             d1 = moreswitches(d1);
4002                         } while (d1);
4003                         if (PL_doswitches && !switches_done) {
4004                             int argc = PL_origargc;
4005                             char **argv = PL_origargv;
4006                             do {
4007                                 argc--,argv++;
4008                             } while (argc && argv[0][0] == '-' && argv[0][1]);
4009                             init_argv_symbols(argc,argv);
4010                         }
4011                         if (((PERLDB_LINE || PERLDB_SAVESRC) && !oldpdb) ||
4012                             ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
4013                               /* if we have already added "LINE: while (<>) {",
4014                                  we must not do it again */
4015                         {
4016                             sv_setpvs(PL_linestr, "");
4017                             PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4018                             PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
4019                             PL_last_lop = PL_last_uni = NULL;
4020                             PL_preambled = FALSE;
4021                             if (PERLDB_LINE || PERLDB_SAVESRC)
4022                                 (void)gv_fetchfile(PL_origfilename);
4023                             goto retry;
4024                         }
4025                     }
4026                 }
4027             }
4028         }
4029         if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4030             PL_bufptr = s;
4031             PL_lex_state = LEX_FORMLINE;
4032             return yylex();
4033         }
4034         goto retry;
4035     case '\r':
4036 #ifdef PERL_STRICT_CR
4037         Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
4038         Perl_croak(aTHX_
4039       "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
4040 #endif
4041     case ' ': case '\t': case '\f': case 013:
4042 #ifdef PERL_MAD
4043         PL_realtokenstart = -1;
4044         if (!PL_thiswhite)
4045             PL_thiswhite = newSVpvs("");
4046         sv_catpvn(PL_thiswhite, s, 1);
4047 #endif
4048         s++;
4049         goto retry;
4050     case '#':
4051     case '\n':
4052 #ifdef PERL_MAD
4053         PL_realtokenstart = -1;
4054         if (PL_madskills)
4055             PL_faketokens = 0;
4056 #endif
4057         if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
4058             if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
4059                 /* handle eval qq[#line 1 "foo"\n ...] */
4060                 CopLINE_dec(PL_curcop);
4061                 incline(s);
4062             }
4063             if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
4064                 s = SKIPSPACE0(s);
4065                 if (!PL_in_eval || PL_rsfp)
4066                     incline(s);
4067             }
4068             else {
4069                 d = s;
4070                 while (d < PL_bufend && *d != '\n')
4071                     d++;
4072                 if (d < PL_bufend)
4073                     d++;
4074                 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4075                   Perl_croak(aTHX_ "panic: input overflow");
4076 #ifdef PERL_MAD
4077                 if (PL_madskills)
4078                     PL_thiswhite = newSVpvn(s, d - s);
4079 #endif
4080                 s = d;
4081                 incline(s);
4082             }
4083             if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4084                 PL_bufptr = s;
4085                 PL_lex_state = LEX_FORMLINE;
4086                 return yylex();
4087             }
4088         }
4089         else {
4090 #ifdef PERL_MAD
4091             if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
4092                 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
4093                     PL_faketokens = 0;
4094                     s = SKIPSPACE0(s);
4095                     TOKEN(PEG); /* make sure any #! line is accessible */
4096                 }
4097                 s = SKIPSPACE0(s);
4098             }
4099             else {
4100 /*              if (PL_madskills && PL_lex_formbrack) { */
4101                     d = s;
4102                     while (d < PL_bufend && *d != '\n')
4103                         d++;
4104                     if (d < PL_bufend)
4105                         d++;
4106                     else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4107                       Perl_croak(aTHX_ "panic: input overflow");
4108                     if (PL_madskills && CopLINE(PL_curcop) >= 1) {
4109                         if (!PL_thiswhite)
4110                             PL_thiswhite = newSVpvs("");
4111                         if (CopLINE(PL_curcop) == 1) {
4112                             sv_setpvs(PL_thiswhite, "");
4113                             PL_faketokens = 0;
4114                         }
4115                         sv_catpvn(PL_thiswhite, s, d - s);
4116                     }
4117                     s = d;
4118 /*              }
4119                 *s = '\0';
4120                 PL_bufend = s; */
4121             }
4122 #else
4123             *s = '\0';
4124             PL_bufend = s;
4125 #endif
4126         }
4127         goto retry;
4128     case '-':
4129         if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
4130             I32 ftst = 0;
4131             char tmp;
4132
4133             s++;
4134             PL_bufptr = s;
4135             tmp = *s++;
4136
4137             while (s < PL_bufend && SPACE_OR_TAB(*s))
4138                 s++;
4139
4140             if (strnEQ(s,"=>",2)) {
4141                 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
4142                 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
4143                 OPERATOR('-');          /* unary minus */
4144             }
4145             PL_last_uni = PL_oldbufptr;
4146             switch (tmp) {
4147             case 'r': ftst = OP_FTEREAD;        break;
4148             case 'w': ftst = OP_FTEWRITE;       break;
4149             case 'x': ftst = OP_FTEEXEC;        break;
4150             case 'o': ftst = OP_FTEOWNED;       break;
4151             case 'R': ftst = OP_FTRREAD;        break;
4152             case 'W': ftst = OP_FTRWRITE;       break;
4153             case 'X': ftst = OP_FTREXEC;        break;
4154             case 'O': ftst = OP_FTROWNED;       break;
4155             case 'e': ftst = OP_FTIS;           break;
4156             case 'z': ftst = OP_FTZERO;         break;
4157             case 's': ftst = OP_FTSIZE;         break;
4158             case 'f': ftst = OP_FTFILE;         break;
4159             case 'd': ftst = OP_FTDIR;          break;
4160             case 'l': ftst = OP_FTLINK;         break;
4161             case 'p': ftst = OP_FTPIPE;         break;
4162             case 'S': ftst = OP_FTSOCK;         break;
4163             case 'u': ftst = OP_FTSUID;         break;
4164             case 'g': ftst = OP_FTSGID;         break;
4165             case 'k': ftst = OP_FTSVTX;         break;
4166             case 'b': ftst = OP_FTBLK;          break;
4167             case 'c': ftst = OP_FTCHR;          break;
4168             case 't': ftst = OP_FTTTY;          break;
4169             case 'T': ftst = OP_FTTEXT;         break;
4170             case 'B': ftst = OP_FTBINARY;       break;
4171             case 'M': case 'A': case 'C':
4172                 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
4173                 switch (tmp) {
4174                 case 'M': ftst = OP_FTMTIME;    break;
4175                 case 'A': ftst = OP_FTATIME;    break;
4176                 case 'C': ftst = OP_FTCTIME;    break;
4177                 default:                        break;
4178                 }
4179                 break;
4180             default:
4181                 break;
4182             }
4183             if (ftst) {
4184                 PL_last_lop_op = (OPCODE)ftst;
4185                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4186                         "### Saw file test %c\n", (int)tmp);
4187                 } );
4188                 FTST(ftst);
4189             }
4190             else {
4191                 /* Assume it was a minus followed by a one-letter named
4192                  * subroutine call (or a -bareword), then. */
4193                 DEBUG_T( { PerlIO_printf(Perl_debug_log,
4194                         "### '-%c' looked like a file test but was not\n",
4195                         (int) tmp);
4196                 } );
4197                 s = --PL_bufptr;
4198             }
4199         }
4200         {
4201             const char tmp = *s++;
4202             if (*s == tmp) {
4203                 s++;
4204                 if (PL_expect == XOPERATOR)
4205                     TERM(POSTDEC);
4206                 else
4207                     OPERATOR(PREDEC);
4208             }
4209             else if (*s == '>') {
4210                 s++;
4211                 s = SKIPSPACE1(s);
4212                 if (isIDFIRST_lazy_if(s,UTF)) {
4213                     s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4214                     TOKEN(ARROW);
4215                 }
4216                 else if (*s == '$')
4217                     OPERATOR(ARROW);
4218                 else
4219                     TERM(ARROW);
4220             }
4221             if (PL_expect == XOPERATOR)
4222                 Aop(OP_SUBTRACT);
4223             else {
4224                 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4225                     check_uni();
4226                 OPERATOR('-');          /* unary minus */
4227             }
4228         }
4229
4230     case '+':
4231         {
4232             const char tmp = *s++;
4233             if (*s == tmp) {
4234                 s++;
4235                 if (PL_expect == XOPERATOR)
4236                     TERM(POSTINC);
4237                 else
4238                     OPERATOR(PREINC);
4239             }
4240             if (PL_expect == XOPERATOR)
4241                 Aop(OP_ADD);
4242             else {
4243                 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4244                     check_uni();
4245                 OPERATOR('+');
4246             }
4247         }
4248
4249     case '*':
4250         if (PL_expect != XOPERATOR) {
4251             s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4252             PL_expect = XOPERATOR;
4253             force_ident(PL_tokenbuf, '*');
4254             if (!*PL_tokenbuf)
4255                 PREREF('*');
4256             TERM('*');
4257         }
4258         s++;
4259         if (*s == '*') {
4260             s++;
4261             PWop(OP_POW);
4262         }
4263         Mop(OP_MULTIPLY);
4264
4265     case '%':
4266         if (PL_expect == XOPERATOR) {
4267             ++s;
4268             Mop(OP_MODULO);
4269         }
4270         PL_tokenbuf[0] = '%';
4271         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4272                 sizeof PL_tokenbuf - 1, FALSE);
4273         if (!PL_tokenbuf[1]) {
4274             PREREF('%');
4275         }
4276         PL_pending_ident = '%';
4277         TERM('%');
4278
4279     case '^':
4280         s++;
4281         BOop(OP_BIT_XOR);
4282     case '[':
4283         PL_lex_brackets++;
4284         {
4285             const char tmp = *s++;
4286             OPERATOR(tmp);
4287         }
4288     case '~':
4289         if (s[1] == '~'
4290             && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
4291         {
4292             s += 2;
4293             Eop(OP_SMARTMATCH);
4294         }
4295     case ',':
4296         {
4297             const char tmp = *s++;
4298             OPERATOR(tmp);
4299         }
4300     case ':':
4301         if (s[1] == ':') {
4302             len = 0;
4303             goto just_a_word_zero_gv;
4304         }
4305         s++;
4306         switch (PL_expect) {
4307             OP *attrs;
4308 #ifdef PERL_MAD
4309             I32 stuffstart;
4310 #endif
4311         case XOPERATOR:
4312             if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4313                 break;
4314             PL_bufptr = s;      /* update in case we back off */
4315             goto grabattrs;
4316         case XATTRBLOCK:
4317             PL_expect = XBLOCK;
4318             goto grabattrs;
4319         case XATTRTERM:
4320             PL_expect = XTERMBLOCK;
4321          grabattrs:
4322 #ifdef PERL_MAD
4323             stuffstart = s - SvPVX(PL_linestr) - 1;
4324 #endif
4325             s = PEEKSPACE(s);
4326             attrs = NULL;
4327             while (isIDFIRST_lazy_if(s,UTF)) {
4328                 I32 tmp;
4329                 SV *sv;
4330                 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
4331                 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
4332                     if (tmp < 0) tmp = -tmp;
4333                     switch (tmp) {
4334                     case KEY_or:
4335                     case KEY_and:
4336                     case KEY_for:
4337                     case KEY_foreach:
4338                     case KEY_unless:
4339                     case KEY_if:
4340                     case KEY_while:
4341                     case KEY_until:
4342                         goto got_attrs;
4343                     default:
4344                         break;
4345                     }
4346                 }
4347                 sv = newSVpvn(s, len);
4348                 if (*d == '(') {
4349                     d = scan_str(d,TRUE,TRUE);
4350                     if (!d) {
4351                         /* MUST advance bufptr here to avoid bogus
4352                            "at end of line" context messages from yyerror().
4353                          */
4354                         PL_bufptr = s + len;
4355                         yyerror("Unterminated attribute parameter in attribute list");
4356                         if (attrs)
4357                             op_free(attrs);
4358                         sv_free(sv);
4359                         return REPORT(0);       /* EOF indicator */
4360                     }
4361                 }
4362                 if (PL_lex_stuff) {
4363                     sv_catsv(sv, PL_lex_stuff);
4364                     attrs = append_elem(OP_LIST, attrs,
4365                                         newSVOP(OP_CONST, 0, sv));
4366                     SvREFCNT_dec(PL_lex_stuff);
4367                     PL_lex_stuff = NULL;
4368                 }
4369                 else {
4370                     if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4371                         sv_free(sv);
4372                         if (PL_in_my == KEY_our) {
4373                             deprecate(":unique");
4374                         }
4375                         else
4376                             Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4377                     }
4378
4379                     /* NOTE: any CV attrs applied here need to be part of
4380                        the CVf_BUILTIN_ATTRS define in cv.h! */
4381                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4382                         sv_free(sv);
4383                         CvLVALUE_on(PL_compcv);
4384                     }
4385                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4386                         sv_free(sv);
4387                         deprecate(":locked");
4388                     }
4389                     else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4390                         sv_free(sv);
4391                         CvMETHOD_on(PL_compcv);
4392                     }
4393                     /* After we've set the flags, it could be argued that
4394                        we don't need to do the attributes.pm-based setting
4395                        process, and shouldn't bother appending recognized
4396                        flags.  To experiment with that, uncomment the
4397                        following "else".  (Note that's already been
4398                        uncommented.  That keeps the above-applied built-in
4399                        attributes from being intercepted (and possibly
4400                        rejected) by a package's attribute routines, but is
4401                        justified by the performance win for the common case
4402                        of applying only built-in attributes.) */
4403                     else
4404                         attrs = append_elem(OP_LIST, attrs,
4405                                             newSVOP(OP_CONST, 0,
4406                                                     sv));
4407                 }
4408                 s = PEEKSPACE(d);
4409                 if (*s == ':' && s[1] != ':')
4410                     s = PEEKSPACE(s+1);
4411                 else if (s == d)
4412                     break;      /* require real whitespace or :'s */
4413                 /* XXX losing whitespace on sequential attributes here */
4414             }
4415             {
4416                 const char tmp
4417                     = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4418                 if (*s != ';' && *s != '}' && *s != tmp
4419                     && (tmp != '=' || *s != ')')) {
4420                     const char q = ((*s == '\'') ? '"' : '\'');
4421                     /* If here for an expression, and parsed no attrs, back
4422                        off. */
4423                     if (tmp == '=' && !attrs) {
4424                         s = PL_bufptr;
4425                         break;
4426                     }
4427                     /* MUST advance bufptr here to avoid bogus "at end of line"
4428                        context messages from yyerror().
4429                     */
4430                     PL_bufptr = s;
4431                     yyerror( (const char *)
4432                              (*s
4433                               ? Perl_form(aTHX_ "Invalid separator character "
4434                                           "%c%c%c in attribute list", q, *s, q)
4435                               : "Unterminated attribute list" ) );
4436                     if (attrs)
4437                         op_free(attrs);
4438                     OPERATOR(':');
4439                 }
4440             }
4441         got_attrs:
4442             if (attrs) {
4443                 start_force(PL_curforce);
4444                 NEXTVAL_NEXTTOKE.opval = attrs;
4445                 CURMAD('_', PL_nextwhite);
4446                 force_next(THING);
4447             }
4448 #ifdef PERL_MAD
4449             if (PL_madskills) {
4450                 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
4451                                      (s - SvPVX(PL_linestr)) - stuffstart);
4452             }
4453 #endif
4454             TOKEN(COLONATTR);
4455         }
4456         OPERATOR(':');
4457     case '(':
4458         s++;
4459         if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4460             PL_oldbufptr = PL_oldoldbufptr;             /* allow print(STDOUT 123) */
4461         else
4462             PL_expect = XTERM;
4463         s = SKIPSPACE1(s);
4464         TOKEN('(');
4465     case ';':
4466         CLINE;
4467         {
4468             const char tmp = *s++;
4469             OPERATOR(tmp);
4470         }
4471     case ')':
4472         {
4473             const char tmp = *s++;
4474             s = SKIPSPACE1(s);
4475             if (*s == '{')
4476                 PREBLOCK(tmp);
4477             TERM(tmp);
4478         }
4479     case ']':
4480         s++;
4481         if (PL_lex_brackets <= 0)
4482             yyerror("Unmatched right square bracket");
4483         else
4484             --PL_lex_brackets;
4485         if (PL_lex_state == LEX_INTERPNORMAL) {
4486             if (PL_lex_brackets == 0) {
4487                 if (*s == '-' && s[1] == '>')
4488                     PL_lex_state = LEX_INTERPENDMAYBE;
4489                 else if (*s != '[' && *s != '{')
4490                     PL_lex_state = LEX_INTERPEND;
4491             }
4492         }
4493         TERM(']');
4494     case '{':
4495       leftbracket:
4496         s++;
4497         if (PL_lex_brackets > 100) {
4498             Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
4499         }
4500         switch (PL_expect) {
4501         case XTERM:
4502             if (PL_lex_formbrack) {
4503                 s--;
4504                 PRETERMBLOCK(DO);
4505             }
4506             if (PL_oldoldbufptr == PL_last_lop)
4507                 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4508             else
4509                 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4510             OPERATOR(HASHBRACK);
4511         case XOPERATOR:
4512             while (s < PL_bufend && SPACE_OR_TAB(*s))
4513                 s++;
4514             d = s;
4515             PL_tokenbuf[0] = '\0';
4516             if (d < PL_bufend && *d == '-') {
4517                 PL_tokenbuf[0] = '-';
4518                 d++;
4519                 while (d < PL_bufend && SPACE_OR_TAB(*d))
4520                     d++;
4521             }
4522             if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
4523                 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
4524                               FALSE, &len);
4525                 while (d < PL_bufend && SPACE_OR_TAB(*d))
4526                     d++;
4527                 if (*d == '}') {
4528                     const char minus = (PL_tokenbuf[0] == '-');
4529                     s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4530                     if (minus)
4531                         force_next('-');
4532                 }
4533             }
4534             /* FALL THROUGH */
4535         case XATTRBLOCK:
4536         case XBLOCK:
4537             PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4538             PL_expect = XSTATE;
4539             break;
4540         case XATTRTERM:
4541         case XTERMBLOCK:
4542             PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4543             PL_expect = XSTATE;
4544             break;
4545         default: {
4546                 const char *t;
4547                 if (PL_oldoldbufptr == PL_last_lop)
4548                     PL_lex_brackstack[PL_lex_brackets++] = XTERM;
4549                 else
4550                     PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4551                 s = SKIPSPACE1(s);
4552                 if (*s == '}') {
4553                     if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4554                         PL_expect = XTERM;
4555                         /* This hack is to get the ${} in the message. */
4556                         PL_bufptr = s+1;
4557                         yyerror("syntax error");
4558                         break;
4559                     }
4560                     OPERATOR(HASHBRACK);
4561                 }
4562                 /* This hack serves to disambiguate a pair of curlies
4563                  * as being a block or an anon hash.  Normally, expectation
4564                  * determines that, but in cases where we're not in a
4565                  * position to expect anything in particular (like inside
4566                  * eval"") we have to resolve the ambiguity.  This code
4567                  * covers the case where the first term in the curlies is a
4568                  * quoted string.  Most other cases need to be explicitly
4569                  * disambiguated by prepending a "+" before the opening
4570                  * curly in order to force resolution as an anon hash.
4571                  *
4572                  * XXX should probably propagate the outer expectation
4573                  * into eval"" to rely less on this hack, but that could
4574                  * potentially break current behavior of eval"".
4575                  * GSAR 97-07-21
4576                  */
4577                 t = s;
4578                 if (*s == '\'' || *s == '"' || *s == '`') {
4579                     /* common case: get past first string, handling escapes */
4580                     for (t++; t < PL_bufend && *t != *s;)
4581                         if (*t++ == '\\' && (*t == '\\' || *t == *s))
4582                             t++;
4583                     t++;
4584                 }
4585                 else if (*s == 'q') {
4586                     if (++t < PL_bufend
4587                         && (!isALNUM(*t)
4588                             || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
4589                                 && !isALNUM(*t))))
4590                     {
4591                         /* skip q//-like construct */
4592                         const char *tmps;
4593                         char open, close, term;
4594                         I32 brackets = 1;
4595
4596                         while (t < PL_bufend && isSPACE(*t))
4597                             t++;
4598                         /* check for q => */
4599                         if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4600                             OPERATOR(HASHBRACK);
4601                         }
4602                         term = *t;
4603                         open = term;
4604                         if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4605                             term = tmps[5];
4606                         close = term;
4607                         if (open == close)
4608                             for (t++; t < PL_bufend; t++) {
4609                                 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
4610                                     t++;
4611                                 else if (*t == open)
4612                                     break;
4613                             }
4614                         else {
4615                             for (t++; t < PL_bufend; t++) {
4616                                 if (*t == '\\' && t+1 < PL_bufend)
4617                                     t++;
4618                                 else if (*t == close && --brackets <= 0)
4619                                     break;
4620                                 else if (*t == open)
4621                                     brackets++;
4622                             }
4623                         }
4624                         t++;
4625                     }
4626                     else
4627                         /* skip plain q word */
4628                         while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4629                              t += UTF8SKIP(t);
4630                 }
4631                 else if (isALNUM_lazy_if(t,UTF)) {
4632                     t += UTF8SKIP(t);
4633                     while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4634                          t += UTF8SKIP(t);
4635                 }
4636                 while (t < PL_bufend && isSPACE(*t))
4637                     t++;
4638                 /* if comma follows first term, call it an anon hash */
4639                 /* XXX it could be a comma expression with loop modifiers */
4640                 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
4641                                    || (*t == '=' && t[1] == '>')))
4642                     OPERATOR(HASHBRACK);
4643                 if (PL_expect == XREF)
4644                     PL_expect = XTERM;
4645                 else {
4646                     PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4647                     PL_expect = XSTATE;
4648                 }
4649             }
4650             break;
4651         }
4652         pl_yylval.ival = CopLINE(PL_curcop);
4653         if (isSPACE(*s) || *s == '#')
4654             PL_copline = NOLINE;   /* invalidate current command line number */
4655         TOKEN('{');
4656     case '}':
4657       rightbracket:
4658         s++;
4659         if (PL_lex_brackets <= 0)
4660             yyerror("Unmatched right curly bracket");
4661         else
4662             PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
4663         if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
4664             PL_lex_formbrack = 0;
4665         if (PL_lex_state == LEX_INTERPNORMAL) {
4666             if (PL_lex_brackets == 0) {
4667                 if (PL_expect & XFAKEBRACK) {
4668                     PL_expect &= XENUMMASK;
4669                     PL_lex_state = LEX_INTERPEND;
4670                     PL_bufptr = s;
4671 #if 0
4672                     if (PL_madskills) {
4673                         if (!PL_thiswhite)
4674                             PL_thiswhite = newSVpvs("");
4675                         sv_catpvs(PL_thiswhite,"}");
4676                     }
4677 #endif
4678                     return yylex();     /* ignore fake brackets */
4679                 }
4680                 if (*s == '-' && s[1] == '>')
4681                     PL_lex_state = LEX_INTERPENDMAYBE;
4682                 else if (*s != '[' && *s != '{')
4683                     PL_lex_state = LEX_INTERPEND;
4684             }
4685         }
4686         if (PL_expect & XFAKEBRACK) {
4687             PL_expect &= XENUMMASK;
4688             PL_bufptr = s;
4689             return yylex();             /* ignore fake brackets */
4690         }
4691         start_force(PL_curforce);
4692         if (PL_madskills) {
4693             curmad('X', newSVpvn(s-1,1));
4694             CURMAD('_', PL_thiswhite);
4695         }
4696         force_next('}');
4697 #ifdef PERL_MAD
4698         if (!PL_thistoken)
4699             PL_thistoken = newSVpvs("");
4700 #endif
4701         TOKEN(';');
4702     case '&':
4703         s++;
4704         if (*s++ == '&')
4705             AOPERATOR(ANDAND);
4706         s--;
4707         if (PL_expect == XOPERATOR) {
4708             if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4709                 && isIDFIRST_lazy_if(s,UTF))
4710             {
4711                 CopLINE_dec(PL_curcop);
4712                 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
4713                 CopLINE_inc(PL_curcop);
4714             }
4715             BAop(OP_BIT_AND);
4716         }
4717
4718         s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4719         if (*PL_tokenbuf) {
4720             PL_expect = XOPERATOR;
4721             force_ident(PL_tokenbuf, '&');
4722         }
4723         else
4724             PREREF('&');
4725         pl_yylval.ival = (OPpENTERSUB_AMPER<<8);
4726         TERM('&');
4727
4728     case '|':
4729         s++;
4730         if (*s++ == '|')
4731             AOPERATOR(OROR);
4732         s--;
4733         BOop(OP_BIT_OR);
4734     case '=':
4735         s++;
4736         {
4737             const char tmp = *s++;
4738             if (tmp == '=')
4739                 Eop(OP_EQ);
4740             if (tmp == '>')
4741                 OPERATOR(',');
4742             if (tmp == '~')
4743                 PMop(OP_MATCH);
4744             if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4745                 && strchr("+-*/%.^&|<",tmp))
4746                 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4747                             "Reversed %c= operator",(int)tmp);
4748             s--;
4749             if (PL_expect == XSTATE && isALPHA(tmp) &&
4750                 (s == PL_linestart+1 || s[-2] == '\n') )
4751                 {
4752                     if (PL_in_eval && !PL_rsfp) {
4753                         d = PL_bufend;
4754                         while (s < d) {
4755                             if (*s++ == '\n') {
4756                                 incline(s);
4757                                 if (strnEQ(s,"=cut",4)) {
4758                                     s = strchr(s,'\n');
4759                                     if (s)
4760                                         s++;
4761                                     else
4762                                         s = d;
4763                                     incline(s);
4764                                     goto retry;
4765                                 }
4766                             }
4767                         }
4768                         goto retry;
4769                     }
4770 #ifdef PERL_MAD
4771                     if (PL_madskills) {
4772                         if (!PL_thiswhite)
4773                             PL_thiswhite = newSVpvs("");
4774                         sv_catpvn(PL_thiswhite, PL_linestart,
4775                                   PL_bufend - PL_linestart);
4776                     }
4777 #endif
4778                     s = PL_bufend;
4779                     PL_doextract = TRUE;
4780                     goto retry;
4781                 }
4782         }
4783         if (PL_lex_brackets < PL_lex_formbrack) {
4784             const char *t = s;
4785 #ifdef PERL_STRICT_CR
4786             while (SPACE_OR_TAB(*t))
4787 #else
4788             while (SPACE_OR_TAB(*t) || *t == '\r')
4789 #endif
4790                 t++;
4791             if (*t == '\n' || *t == '#') {
4792                 s--;
4793                 PL_expect = XBLOCK;
4794                 goto leftbracket;
4795             }
4796         }
4797         pl_yylval.ival = 0;
4798         OPERATOR(ASSIGNOP);
4799     case '!':
4800         s++;
4801         {
4802             const char tmp = *s++;
4803             if (tmp == '=') {
4804                 /* was this !=~ where !~ was meant?
4805                  * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4806
4807                 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4808                     const char *t = s+1;
4809
4810                     while (t < PL_bufend && isSPACE(*t))
4811                         ++t;
4812
4813                     if (*t == '/' || *t == '?' ||
4814                         ((*t == 'm' || *t == 's' || *t == 'y')
4815                          && !isALNUM(t[1])) ||
4816                         (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4817                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4818                                     "!=~ should be !~");
4819                 }
4820                 Eop(OP_NE);
4821             }
4822             if (tmp == '~')
4823                 PMop(OP_NOT);
4824         }
4825         s--;
4826         OPERATOR('!');
4827     case '<':
4828         if (PL_expect != XOPERATOR) {
4829             if (s[1] != '<' && !strchr(s,'>'))
4830                 check_uni();
4831             if (s[1] == '<')
4832                 s = scan_heredoc(s);
4833             else
4834                 s = scan_inputsymbol(s);
4835             TERM(sublex_start());
4836         }
4837         s++;
4838         {
4839             char tmp = *s++;
4840             if (tmp == '<')
4841                 SHop(OP_LEFT_SHIFT);
4842             if (tmp == '=') {
4843                 tmp = *s++;
4844                 if (tmp == '>')
4845                     Eop(OP_NCMP);
4846                 s--;
4847                 Rop(OP_LE);
4848             }
4849         }
4850         s--;
4851         Rop(OP_LT);
4852     case '>':
4853         s++;
4854         {
4855             const char tmp = *s++;
4856             if (tmp == '>')
4857                 SHop(OP_RIGHT_SHIFT);
4858             else if (tmp == '=')
4859                 Rop(OP_GE);
4860         }
4861         s--;
4862         Rop(OP_GT);
4863
4864     case '$':
4865         CLINE;
4866
4867         if (PL_expect == XOPERATOR) {
4868             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
4869                 return deprecate_commaless_var_list();
4870             }
4871         }
4872
4873         if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
4874             PL_tokenbuf[0] = '@';
4875             s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4876                            sizeof PL_tokenbuf - 1, FALSE);
4877             if (PL_expect == XOPERATOR)
4878                 no_op("Array length", s);
4879             if (!PL_tokenbuf[1])
4880                 PREREF(DOLSHARP);
4881             PL_expect = XOPERATOR;
4882             PL_pending_ident = '#';
4883             TOKEN(DOLSHARP);
4884         }
4885
4886         PL_tokenbuf[0] = '$';
4887         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4888                        sizeof PL_tokenbuf - 1, FALSE);
4889         if (PL_expect == XOPERATOR)
4890             no_op("Scalar", s);
4891         if (!PL_tokenbuf[1]) {
4892             if (s == PL_bufend)
4893                 yyerror("Final $ should be \\$ or $name");
4894             PREREF('$');
4895         }
4896
4897         /* This kludge not intended to be bulletproof. */
4898         if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
4899             pl_yylval.opval = newSVOP(OP_CONST, 0,
4900                                    newSViv(CopARYBASE_get(&PL_compiling)));
4901             pl_yylval.opval->op_private = OPpCONST_ARYBASE;
4902             TERM(THING);
4903         }
4904
4905         d = s;
4906         {
4907             const char tmp = *s;
4908             if (PL_lex_state == LEX_NORMAL)
4909                 s = SKIPSPACE1(s);
4910
4911             if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4912                 && intuit_more(s)) {
4913                 if (*s == '[') {
4914                     PL_tokenbuf[0] = '@';
4915                     if (ckWARN(WARN_SYNTAX)) {
4916                         char *t = s+1;
4917
4918                         while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4919                             t++;
4920                         if (*t++ == ',') {
4921                             PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
4922                             while (t < PL_bufend && *t != ']')
4923                                 t++;
4924                             Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4925                                         "Multidimensional syntax %.*s not supported",
4926                                     (int)((t - PL_bufptr) + 1), PL_bufptr);
4927                         }
4928                     }
4929                 }
4930                 else if (*s == '{') {
4931                     char *t;
4932                     PL_tokenbuf[0] = '%';
4933                     if (strEQ(PL_tokenbuf+1, "SIG")  && ckWARN(WARN_SYNTAX)
4934                         && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4935                         {
4936                             char tmpbuf[sizeof PL_tokenbuf];
4937                             do {
4938                                 t++;
4939                             } while (isSPACE(*t));
4940                             if (isIDFIRST_lazy_if(t,UTF)) {
4941                                 STRLEN len;
4942                                 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
4943                                               &len);
4944                                 while (isSPACE(*t))
4945                                     t++;
4946                                 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
4947                                     Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4948                                                 "You need to quote \"%s\"",
4949                                                 tmpbuf);
4950                             }
4951                         }
4952                 }
4953             }
4954
4955             PL_expect = XOPERATOR;
4956             if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4957                 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4958                 if (!islop || PL_last_lop_op == OP_GREPSTART)
4959                     PL_expect = XOPERATOR;
4960                 else if (strchr("$@\"'`q", *s))
4961                     PL_expect = XTERM;          /* e.g. print $fh "foo" */
4962                 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4963                     PL_expect = XTERM;          /* e.g. print $fh &sub */
4964                 else if (isIDFIRST_lazy_if(s,UTF)) {
4965                     char tmpbuf[sizeof PL_tokenbuf];
4966                     int t2;
4967                     scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
4968                     if ((t2 = keyword(tmpbuf, len, 0))) {
4969                         /* binary operators exclude handle interpretations */
4970                         switch (t2) {
4971                         case -KEY_x:
4972                         case -KEY_eq:
4973                         case -KEY_ne:
4974                         case -KEY_gt:
4975                         case -KEY_lt:
4976                         case -KEY_ge:
4977                         case -KEY_le:
4978                         case -KEY_cmp:
4979                             break;
4980                         default:
4981                             PL_expect = XTERM;  /* e.g. print $fh length() */
4982                             break;
4983                         }
4984                     }
4985                     else {
4986                         PL_expect = XTERM;      /* e.g. print $fh subr() */
4987                     }
4988                 }
4989                 else if (isDIGIT(*s))
4990                     PL_expect = XTERM;          /* e.g. print $fh 3 */
4991                 else if (*s == '.' && isDIGIT(s[1]))
4992                     PL_expect = XTERM;          /* e.g. print $fh .3 */
4993                 else if ((*s == '?' || *s == '-' || *s == '+')
4994                          && !isSPACE(s[1]) && s[1] != '=')
4995                     PL_expect = XTERM;          /* e.g. print $fh -1 */
4996                 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4997                          && s[1] != '/')
4998                     PL_expect = XTERM;          /* e.g. print $fh /.../
4999                                                    XXX except DORDOR operator
5000                                                 */
5001                 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
5002                          && s[2] != '=')
5003                     PL_expect = XTERM;          /* print $fh <<"EOF" */
5004             }
5005         }
5006         PL_pending_ident = '$';
5007         TOKEN('$');
5008
5009     case '@':
5010         if (PL_expect == XOPERATOR)
5011             no_op("Array", s);
5012         PL_tokenbuf[0] = '@';
5013         s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
5014         if (!PL_tokenbuf[1]) {
5015             PREREF('@');
5016         }
5017         if (PL_lex_state == LEX_NORMAL)
5018             s = SKIPSPACE1(s);
5019         if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
5020             if (*s == '{')
5021                 PL_tokenbuf[0] = '%';
5022
5023             /* Warn about @ where they meant $. */
5024             if (*s == '[' || *s == '{') {
5025                 if (ckWARN(WARN_SYNTAX)) {
5026                     const char *t = s + 1;
5027                     while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
5028                         t++;
5029                     if (*t == '}' || *t == ']') {
5030                         t++;
5031                         PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
5032                         Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
5033                             "Scalar value %.*s better written as $%.*s",
5034                             (int)(t-PL_bufptr), PL_bufptr,
5035                             (int)(t-PL_bufptr-1), PL_bufptr+1);
5036                     }
5037                 }
5038             }
5039         }
5040         PL_pending_ident = '@';
5041         TERM('@');
5042
5043      case '/':                  /* may be division, defined-or, or pattern */
5044         if (PL_expect == XTERMORDORDOR && s[1] == '/') {
5045             s += 2;
5046             AOPERATOR(DORDOR);
5047         }
5048      case '?':                  /* may either be conditional or pattern */
5049         if (PL_expect == XOPERATOR) {
5050              char tmp = *s++;
5051              if(tmp == '?') {
5052                 OPERATOR('?');
5053              }
5054              else {
5055                  tmp = *s++;
5056                  if(tmp == '/') {
5057                      /* A // operator. */
5058                     AOPERATOR(DORDOR);
5059                  }
5060                  else {
5061                      s--;
5062                      Mop(OP_DIVIDE);
5063                  }
5064              }
5065          }
5066          else {
5067              /* Disable warning on "study /blah/" */
5068              if (PL_oldoldbufptr == PL_last_uni
5069               && (*PL_last_uni != 's' || s - PL_last_uni < 5
5070                   || memNE(PL_last_uni, "study", 5)
5071                   || isALNUM_lazy_if(PL_last_uni+5,UTF)
5072               ))
5073                  check_uni();
5074              s = scan_pat(s,OP_MATCH);
5075              TERM(sublex_start());
5076          }
5077
5078     case '.':
5079         if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
5080 #ifdef PERL_STRICT_CR
5081             && s[1] == '\n'
5082 #else
5083             && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
5084 #endif
5085             && (s == PL_linestart || s[-1] == '\n') )
5086         {
5087             PL_lex_formbrack = 0;
5088             PL_expect = XSTATE;
5089             goto rightbracket;
5090         }
5091         if (PL_expect == XSTATE && s[1] == '.' && s[2] == '.') {
5092             s += 3;
5093             OPERATOR(YADAYADA);
5094         }
5095         if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
5096             char tmp = *s++;
5097             if (*s == tmp) {
5098                 s++;
5099                 if (*s == tmp) {
5100                     s++;
5101                     pl_yylval.ival = OPf_SPECIAL;
5102                 }
5103                 else
5104                     pl_yylval.ival = 0;
5105                 OPERATOR(DOTDOT);
5106             }
5107             if (PL_expect != XOPERATOR)
5108                 check_uni();
5109             Aop(OP_CONCAT);
5110         }
5111         /* FALL THROUGH */
5112     case '0': case '1': case '2': case '3': case '4':
5113     case '5': case '6': case '7': case '8': case '9':
5114         s = scan_num(s, &pl_yylval);
5115         DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
5116         if (PL_expect == XOPERATOR)
5117             no_op("Number",s);
5118         TERM(THING);
5119
5120     case '\'':
5121         s = scan_str(s,!!PL_madskills,FALSE);
5122         DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5123         if (PL_expect == XOPERATOR) {
5124             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5125                 return deprecate_commaless_var_list();
5126             }
5127             else
5128                 no_op("String",s);
5129         }
5130         if (!s)
5131             missingterm(NULL);
5132         pl_yylval.ival = OP_CONST;
5133         TERM(sublex_start());
5134
5135     case '"':
5136         s = scan_str(s,!!PL_madskills,FALSE);
5137         DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
5138         if (PL_expect == XOPERATOR) {
5139             if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
5140                 return deprecate_commaless_var_list();
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  */