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