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