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