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