This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add length and flags arguments to Perl_pad_add_name().
[perl5.git] / toke.c
CommitLineData
a0d0e21e 1/* toke.c
a687059c 2 *
1129b882
NC
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
a687059c 5 *
d48672a2
LW
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.
378cc40b 8 *
a0d0e21e
LW
9 */
10
11/*
4ac71550
TC
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"]
378cc40b
LW
15 */
16
9cbb5ea2
GS
17/*
18 * This file is the lexer for Perl. It's closely linked to the
4e553d73 19 * parser, perly.y.
ffb4593c
NT
20 *
21 * The main routine is yylex(), which returns the next token.
22 */
23
378cc40b 24#include "EXTERN.h"
864dbfa3 25#define PERL_IN_TOKE_C
378cc40b 26#include "perl.h"
378cc40b 27
eb0d8d16
NC
28#define new_constant(a,b,c,d,e,f,g) \
29 S_new_constant(aTHX_ a,b,STR_WITH_LEN(c),d,e,f, g)
30
6154021b 31#define pl_yylval (PL_parser->yylval)
d3b6f988 32
acdf0a21
DM
33/* YYINITDEPTH -- initial size of the parser's stacks. */
34#define YYINITDEPTH 200
35
199e78b7
DM
36/* XXX temporary backwards compatibility */
37#define PL_lex_brackets (PL_parser->lex_brackets)
38#define PL_lex_brackstack (PL_parser->lex_brackstack)
39#define PL_lex_casemods (PL_parser->lex_casemods)
40#define PL_lex_casestack (PL_parser->lex_casestack)
41#define PL_lex_defer (PL_parser->lex_defer)
42#define PL_lex_dojoin (PL_parser->lex_dojoin)
43#define PL_lex_expect (PL_parser->lex_expect)
44#define PL_lex_formbrack (PL_parser->lex_formbrack)
45#define PL_lex_inpat (PL_parser->lex_inpat)
46#define PL_lex_inwhat (PL_parser->lex_inwhat)
47#define PL_lex_op (PL_parser->lex_op)
48#define PL_lex_repl (PL_parser->lex_repl)
49#define PL_lex_starts (PL_parser->lex_starts)
50#define PL_lex_stuff (PL_parser->lex_stuff)
51#define PL_multi_start (PL_parser->multi_start)
52#define PL_multi_open (PL_parser->multi_open)
53#define PL_multi_close (PL_parser->multi_close)
54#define PL_pending_ident (PL_parser->pending_ident)
55#define PL_preambled (PL_parser->preambled)
56#define PL_sublex_info (PL_parser->sublex_info)
bdc0bf6f 57#define PL_linestr (PL_parser->linestr)
c2598295
DM
58#define PL_expect (PL_parser->expect)
59#define PL_copline (PL_parser->copline)
f06b5848
DM
60#define PL_bufptr (PL_parser->bufptr)
61#define PL_oldbufptr (PL_parser->oldbufptr)
62#define PL_oldoldbufptr (PL_parser->oldoldbufptr)
63#define PL_linestart (PL_parser->linestart)
64#define PL_bufend (PL_parser->bufend)
65#define PL_last_uni (PL_parser->last_uni)
66#define PL_last_lop (PL_parser->last_lop)
67#define PL_last_lop_op (PL_parser->last_lop_op)
bc177e6b 68#define PL_lex_state (PL_parser->lex_state)
2f9285f8 69#define PL_rsfp (PL_parser->rsfp)
5486870f 70#define PL_rsfp_filters (PL_parser->rsfp_filters)
12bd6ede
DM
71#define PL_in_my (PL_parser->in_my)
72#define PL_in_my_stash (PL_parser->in_my_stash)
14047fc9 73#define PL_tokenbuf (PL_parser->tokenbuf)
670a9cb2 74#define PL_multi_end (PL_parser->multi_end)
13765c85 75#define PL_error_count (PL_parser->error_count)
199e78b7
DM
76
77#ifdef PERL_MAD
78# define PL_endwhite (PL_parser->endwhite)
79# define PL_faketokens (PL_parser->faketokens)
80# define PL_lasttoke (PL_parser->lasttoke)
81# define PL_nextwhite (PL_parser->nextwhite)
82# define PL_realtokenstart (PL_parser->realtokenstart)
83# define PL_skipwhite (PL_parser->skipwhite)
84# define PL_thisclose (PL_parser->thisclose)
85# define PL_thismad (PL_parser->thismad)
86# define PL_thisopen (PL_parser->thisopen)
87# define PL_thisstuff (PL_parser->thisstuff)
88# define PL_thistoken (PL_parser->thistoken)
89# define PL_thiswhite (PL_parser->thiswhite)
fb205e7a
DM
90# define PL_thiswhite (PL_parser->thiswhite)
91# define PL_nexttoke (PL_parser->nexttoke)
92# define PL_curforce (PL_parser->curforce)
93#else
94# define PL_nexttoke (PL_parser->nexttoke)
95# define PL_nexttype (PL_parser->nexttype)
96# define PL_nextval (PL_parser->nextval)
199e78b7
DM
97#endif
98
16173588
NC
99/* This can't be done with embed.fnc, because struct yy_parser contains a
100 member named pending_ident, which clashes with the generated #define */
3cbf51f5
DM
101static int
102S_pending_ident(pTHX);
199e78b7 103
0bd48802 104static const char ident_too_long[] = "Identifier too long";
8903cb82 105
29595ff2 106#ifdef PERL_MAD
29595ff2 107# define CURMAD(slot,sv) if (PL_madskills) { curmad(slot,sv); sv = 0; }
cd81e915 108# define NEXTVAL_NEXTTOKE PL_nexttoke[PL_curforce].next_val
9ded7720 109#else
5db06880 110# define CURMAD(slot,sv)
9ded7720 111# define NEXTVAL_NEXTTOKE PL_nextval[PL_nexttoke]
29595ff2
NC
112#endif
113
9059aa12
LW
114#define XFAKEBRACK 128
115#define XENUMMASK 127
116
39e02b42
JH
117#ifdef USE_UTF8_SCRIPTS
118# define UTF (!IN_BYTES)
2b9d42f0 119#else
746b446a 120# define UTF ((PL_linestr && DO_UTF8(PL_linestr)) || (PL_hints & HINT_UTF8))
2b9d42f0 121#endif
a0ed51b3 122
b1fc3636
CJ
123/* The maximum number of characters preceding the unrecognized one to display */
124#define UNRECOGNIZED_PRECEDE_COUNT 10
125
61f0cdd9 126/* In variables named $^X, these are the legal values for X.
2b92dfce
GS
127 * 1999-02-27 mjd-perl-patch@plover.com */
128#define isCONTROLVAR(x) (isUPPER(x) || strchr("[\\]^_?", (x)))
129
bf4acbe4 130#define SPACE_OR_TAB(c) ((c)==' '||(c)=='\t')
bf4acbe4 131
ffb4593c
NT
132/* LEX_* are values for PL_lex_state, the state of the lexer.
133 * They are arranged oddly so that the guard on the switch statement
79072805
LW
134 * can get by with a single comparison (if the compiler is smart enough).
135 */
136
fb73857a 137/* #define LEX_NOTPARSING 11 is done in perl.h. */
138
b6007c36
DM
139#define LEX_NORMAL 10 /* normal code (ie not within "...") */
140#define LEX_INTERPNORMAL 9 /* code within a string, eg "$foo[$x+1]" */
141#define LEX_INTERPCASEMOD 8 /* expecting a \U, \Q or \E etc */
142#define LEX_INTERPPUSH 7 /* starting a new sublex parse level */
143#define LEX_INTERPSTART 6 /* expecting the start of a $var */
144
145 /* at end of code, eg "$x" followed by: */
146#define LEX_INTERPEND 5 /* ... eg not one of [, { or -> */
147#define LEX_INTERPENDMAYBE 4 /* ... eg one of [, { or -> */
148
149#define LEX_INTERPCONCAT 3 /* expecting anything, eg at start of
150 string or after \E, $foo, etc */
151#define LEX_INTERPCONST 2 /* NOT USED */
152#define LEX_FORMLINE 1 /* expecting a format line */
153#define LEX_KNOWNEXT 0 /* next token known; just return it */
154
79072805 155
bbf60fe6 156#ifdef DEBUGGING
27da23d5 157static const char* const lex_state_names[] = {
bbf60fe6
DM
158 "KNOWNEXT",
159 "FORMLINE",
160 "INTERPCONST",
161 "INTERPCONCAT",
162 "INTERPENDMAYBE",
163 "INTERPEND",
164 "INTERPSTART",
165 "INTERPPUSH",
166 "INTERPCASEMOD",
167 "INTERPNORMAL",
168 "NORMAL"
169};
170#endif
171
79072805
LW
172#ifdef ff_next
173#undef ff_next
d48672a2
LW
174#endif
175
79072805 176#include "keywords.h"
fe14fcc3 177
ffb4593c
NT
178/* CLINE is a macro that ensures PL_copline has a sane value */
179
ae986130
LW
180#ifdef CLINE
181#undef CLINE
182#endif
57843af0 183#define CLINE (PL_copline = (CopLINE(PL_curcop) < PL_copline ? CopLINE(PL_curcop) : PL_copline))
3280af22 184
5db06880 185#ifdef PERL_MAD
29595ff2
NC
186# define SKIPSPACE0(s) skipspace0(s)
187# define SKIPSPACE1(s) skipspace1(s)
188# define SKIPSPACE2(s,tsv) skipspace2(s,&tsv)
189# define PEEKSPACE(s) skipspace2(s,0)
190#else
191# define SKIPSPACE0(s) skipspace(s)
192# define SKIPSPACE1(s) skipspace(s)
193# define SKIPSPACE2(s,tsv) skipspace(s)
194# define PEEKSPACE(s) skipspace(s)
195#endif
196
ffb4593c
NT
197/*
198 * Convenience functions to return different tokens and prime the
9cbb5ea2 199 * lexer for the next token. They all take an argument.
ffb4593c
NT
200 *
201 * TOKEN : generic token (used for '(', DOLSHARP, etc)
202 * OPERATOR : generic operator
203 * AOPERATOR : assignment operator
204 * PREBLOCK : beginning the block after an if, while, foreach, ...
205 * PRETERMBLOCK : beginning a non-code-defining {} block (eg, hash ref)
206 * PREREF : *EXPR where EXPR is not a simple identifier
207 * TERM : expression term
208 * LOOPX : loop exiting command (goto, last, dump, etc)
209 * FTST : file test operator
210 * FUN0 : zero-argument function
2d2e263d 211 * FUN1 : not used, except for not, which isn't a UNIOP
ffb4593c
NT
212 * BOop : bitwise or or xor
213 * BAop : bitwise and
214 * SHop : shift operator
215 * PWop : power operator
9cbb5ea2 216 * PMop : pattern-matching operator
ffb4593c
NT
217 * Aop : addition-level operator
218 * Mop : multiplication-level operator
219 * Eop : equality-testing operator
e5edeb50 220 * Rop : relational operator <= != gt
ffb4593c
NT
221 *
222 * Also see LOP and lop() below.
223 */
224
998054bd 225#ifdef DEBUGGING /* Serve -DT. */
704d4215 226# define REPORT(retval) tokereport((I32)retval, &pl_yylval)
998054bd 227#else
bbf60fe6 228# define REPORT(retval) (retval)
998054bd
SC
229#endif
230
bbf60fe6
DM
231#define TOKEN(retval) return ( PL_bufptr = s, REPORT(retval))
232#define OPERATOR(retval) return (PL_expect = XTERM, PL_bufptr = s, REPORT(retval))
233#define AOPERATOR(retval) return ao((PL_expect = XTERM, PL_bufptr = s, REPORT(retval)))
234#define PREBLOCK(retval) return (PL_expect = XBLOCK,PL_bufptr = s, REPORT(retval))
235#define PRETERMBLOCK(retval) return (PL_expect = XTERMBLOCK,PL_bufptr = s, REPORT(retval))
236#define PREREF(retval) return (PL_expect = XREF,PL_bufptr = s, REPORT(retval))
237#define TERM(retval) return (CLINE, PL_expect = XOPERATOR, PL_bufptr = s, REPORT(retval))
6154021b
RGS
238#define LOOPX(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)LOOPEX))
239#define FTST(f) return (pl_yylval.ival=f, PL_expect=XTERMORDORDOR, PL_bufptr=s, REPORT((int)UNIOP))
240#define FUN0(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC0))
241#define FUN1(f) return (pl_yylval.ival=f, PL_expect=XOPERATOR, PL_bufptr=s, REPORT((int)FUNC1))
242#define BOop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITOROP)))
243#define BAop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)BITANDOP)))
244#define SHop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)SHIFTOP)))
245#define PWop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)POWOP)))
246#define PMop(f) return(pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MATCHOP))
247#define Aop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)ADDOP)))
248#define Mop(f) return ao((pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)MULOP)))
249#define Eop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)EQOP))
250#define Rop(f) return (pl_yylval.ival=f, PL_expect=XTERM, PL_bufptr=s, REPORT((int)RELOP))
2f3197b3 251
a687059c
LW
252/* This bit of chicanery makes a unary function followed by
253 * a parenthesis into a function with one argument, highest precedence.
6f33ba73
RGS
254 * The UNIDOR macro is for unary functions that can be followed by the //
255 * operator (such as C<shift // 0>).
a687059c 256 */
376fcdbf 257#define UNI2(f,x) { \
6154021b 258 pl_yylval.ival = f; \
376fcdbf
AL
259 PL_expect = x; \
260 PL_bufptr = s; \
261 PL_last_uni = PL_oldbufptr; \
262 PL_last_lop_op = f; \
263 if (*s == '(') \
264 return REPORT( (int)FUNC1 ); \
29595ff2 265 s = PEEKSPACE(s); \
376fcdbf
AL
266 return REPORT( *s=='(' ? (int)FUNC1 : (int)UNIOP ); \
267 }
6f33ba73
RGS
268#define UNI(f) UNI2(f,XTERM)
269#define UNIDOR(f) UNI2(f,XTERMORDORDOR)
a687059c 270
376fcdbf 271#define UNIBRACK(f) { \
6154021b 272 pl_yylval.ival = f; \
376fcdbf
AL
273 PL_bufptr = s; \
274 PL_last_uni = PL_oldbufptr; \
275 if (*s == '(') \
276 return REPORT( (int)FUNC1 ); \
29595ff2 277 s = PEEKSPACE(s); \
376fcdbf
AL
278 return REPORT( (*s == '(') ? (int)FUNC1 : (int)UNIOP ); \
279 }
79072805 280
9f68db38 281/* grandfather return to old style */
6154021b 282#define OLDLOP(f) return(pl_yylval.ival=f,PL_expect = XTERM,PL_bufptr = s,(int)LSTOP)
79072805 283
8fa7f367
JH
284#ifdef DEBUGGING
285
6154021b 286/* how to interpret the pl_yylval associated with the token */
bbf60fe6
DM
287enum token_type {
288 TOKENTYPE_NONE,
289 TOKENTYPE_IVAL,
6154021b 290 TOKENTYPE_OPNUM, /* pl_yylval.ival contains an opcode number */
bbf60fe6
DM
291 TOKENTYPE_PVAL,
292 TOKENTYPE_OPVAL,
293 TOKENTYPE_GVVAL
294};
295
6d4a66ac
NC
296static struct debug_tokens {
297 const int token;
298 enum token_type type;
299 const char *name;
300} const debug_tokens[] =
9041c2e3 301{
bbf60fe6
DM
302 { ADDOP, TOKENTYPE_OPNUM, "ADDOP" },
303 { ANDAND, TOKENTYPE_NONE, "ANDAND" },
304 { ANDOP, TOKENTYPE_NONE, "ANDOP" },
305 { ANONSUB, TOKENTYPE_IVAL, "ANONSUB" },
306 { ARROW, TOKENTYPE_NONE, "ARROW" },
307 { ASSIGNOP, TOKENTYPE_OPNUM, "ASSIGNOP" },
308 { BITANDOP, TOKENTYPE_OPNUM, "BITANDOP" },
309 { BITOROP, TOKENTYPE_OPNUM, "BITOROP" },
310 { COLONATTR, TOKENTYPE_NONE, "COLONATTR" },
311 { CONTINUE, TOKENTYPE_NONE, "CONTINUE" },
0d863452 312 { DEFAULT, TOKENTYPE_NONE, "DEFAULT" },
bbf60fe6
DM
313 { DO, TOKENTYPE_NONE, "DO" },
314 { DOLSHARP, TOKENTYPE_NONE, "DOLSHARP" },
315 { DORDOR, TOKENTYPE_NONE, "DORDOR" },
316 { DOROP, TOKENTYPE_OPNUM, "DOROP" },
317 { DOTDOT, TOKENTYPE_IVAL, "DOTDOT" },
318 { ELSE, TOKENTYPE_NONE, "ELSE" },
319 { ELSIF, TOKENTYPE_IVAL, "ELSIF" },
320 { EQOP, TOKENTYPE_OPNUM, "EQOP" },
321 { FOR, TOKENTYPE_IVAL, "FOR" },
322 { FORMAT, TOKENTYPE_NONE, "FORMAT" },
323 { FUNC, TOKENTYPE_OPNUM, "FUNC" },
324 { FUNC0, TOKENTYPE_OPNUM, "FUNC0" },
325 { FUNC0SUB, TOKENTYPE_OPVAL, "FUNC0SUB" },
326 { FUNC1, TOKENTYPE_OPNUM, "FUNC1" },
327 { FUNCMETH, TOKENTYPE_OPVAL, "FUNCMETH" },
0d863452 328 { GIVEN, TOKENTYPE_IVAL, "GIVEN" },
bbf60fe6
DM
329 { HASHBRACK, TOKENTYPE_NONE, "HASHBRACK" },
330 { IF, TOKENTYPE_IVAL, "IF" },
331 { LABEL, TOKENTYPE_PVAL, "LABEL" },
332 { LOCAL, TOKENTYPE_IVAL, "LOCAL" },
333 { LOOPEX, TOKENTYPE_OPNUM, "LOOPEX" },
334 { LSTOP, TOKENTYPE_OPNUM, "LSTOP" },
335 { LSTOPSUB, TOKENTYPE_OPVAL, "LSTOPSUB" },
336 { MATCHOP, TOKENTYPE_OPNUM, "MATCHOP" },
337 { METHOD, TOKENTYPE_OPVAL, "METHOD" },
338 { MULOP, TOKENTYPE_OPNUM, "MULOP" },
339 { MY, TOKENTYPE_IVAL, "MY" },
340 { MYSUB, TOKENTYPE_NONE, "MYSUB" },
341 { NOAMP, TOKENTYPE_NONE, "NOAMP" },
342 { NOTOP, TOKENTYPE_NONE, "NOTOP" },
343 { OROP, TOKENTYPE_IVAL, "OROP" },
344 { OROR, TOKENTYPE_NONE, "OROR" },
345 { PACKAGE, TOKENTYPE_NONE, "PACKAGE" },
88e1f1a2
JV
346 { PLUGEXPR, TOKENTYPE_OPVAL, "PLUGEXPR" },
347 { PLUGSTMT, TOKENTYPE_OPVAL, "PLUGSTMT" },
bbf60fe6
DM
348 { PMFUNC, TOKENTYPE_OPVAL, "PMFUNC" },
349 { POSTDEC, TOKENTYPE_NONE, "POSTDEC" },
350 { POSTINC, TOKENTYPE_NONE, "POSTINC" },
351 { POWOP, TOKENTYPE_OPNUM, "POWOP" },
352 { PREDEC, TOKENTYPE_NONE, "PREDEC" },
353 { PREINC, TOKENTYPE_NONE, "PREINC" },
354 { PRIVATEREF, TOKENTYPE_OPVAL, "PRIVATEREF" },
355 { REFGEN, TOKENTYPE_NONE, "REFGEN" },
356 { RELOP, TOKENTYPE_OPNUM, "RELOP" },
357 { SHIFTOP, TOKENTYPE_OPNUM, "SHIFTOP" },
358 { SUB, TOKENTYPE_NONE, "SUB" },
359 { THING, TOKENTYPE_OPVAL, "THING" },
360 { UMINUS, TOKENTYPE_NONE, "UMINUS" },
361 { UNIOP, TOKENTYPE_OPNUM, "UNIOP" },
362 { UNIOPSUB, TOKENTYPE_OPVAL, "UNIOPSUB" },
363 { UNLESS, TOKENTYPE_IVAL, "UNLESS" },
364 { UNTIL, TOKENTYPE_IVAL, "UNTIL" },
365 { USE, TOKENTYPE_IVAL, "USE" },
0d863452 366 { WHEN, TOKENTYPE_IVAL, "WHEN" },
bbf60fe6
DM
367 { WHILE, TOKENTYPE_IVAL, "WHILE" },
368 { WORD, TOKENTYPE_OPVAL, "WORD" },
be25f609 369 { YADAYADA, TOKENTYPE_IVAL, "YADAYADA" },
c35e046a 370 { 0, TOKENTYPE_NONE, NULL }
bbf60fe6
DM
371};
372
6154021b 373/* dump the returned token in rv, plus any optional arg in pl_yylval */
998054bd 374
bbf60fe6 375STATIC int
704d4215 376S_tokereport(pTHX_ I32 rv, const YYSTYPE* lvalp)
bbf60fe6 377{
97aff369 378 dVAR;
7918f24d
NC
379
380 PERL_ARGS_ASSERT_TOKEREPORT;
381
bbf60fe6 382 if (DEBUG_T_TEST) {
bd61b366 383 const char *name = NULL;
bbf60fe6 384 enum token_type type = TOKENTYPE_NONE;
f54cb97a 385 const struct debug_tokens *p;
396482e1 386 SV* const report = newSVpvs("<== ");
bbf60fe6 387
f54cb97a 388 for (p = debug_tokens; p->token; p++) {
bbf60fe6
DM
389 if (p->token == (int)rv) {
390 name = p->name;
391 type = p->type;
392 break;
393 }
394 }
395 if (name)
54667de8 396 Perl_sv_catpv(aTHX_ report, name);
bbf60fe6
DM
397 else if ((char)rv > ' ' && (char)rv < '~')
398 Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
399 else if (!rv)
396482e1 400 sv_catpvs(report, "EOF");
bbf60fe6
DM
401 else
402 Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
403 switch (type) {
404 case TOKENTYPE_NONE:
405 case TOKENTYPE_GVVAL: /* doesn't appear to be used */
406 break;
407 case TOKENTYPE_IVAL:
704d4215 408 Perl_sv_catpvf(aTHX_ report, "(ival=%"IVdf")", (IV)lvalp->ival);
bbf60fe6
DM
409 break;
410 case TOKENTYPE_OPNUM:
411 Perl_sv_catpvf(aTHX_ report, "(ival=op_%s)",
704d4215 412 PL_op_name[lvalp->ival]);
bbf60fe6
DM
413 break;
414 case TOKENTYPE_PVAL:
704d4215 415 Perl_sv_catpvf(aTHX_ report, "(pval=\"%s\")", lvalp->pval);
bbf60fe6
DM
416 break;
417 case TOKENTYPE_OPVAL:
704d4215 418 if (lvalp->opval) {
401441c0 419 Perl_sv_catpvf(aTHX_ report, "(opval=op_%s)",
704d4215
GG
420 PL_op_name[lvalp->opval->op_type]);
421 if (lvalp->opval->op_type == OP_CONST) {
b6007c36 422 Perl_sv_catpvf(aTHX_ report, " %s",
704d4215 423 SvPEEK(cSVOPx_sv(lvalp->opval)));
b6007c36
DM
424 }
425
426 }
401441c0 427 else
396482e1 428 sv_catpvs(report, "(opval=null)");
bbf60fe6
DM
429 break;
430 }
b6007c36 431 PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
bbf60fe6
DM
432 };
433 return (int)rv;
998054bd
SC
434}
435
b6007c36
DM
436
437/* print the buffer with suitable escapes */
438
439STATIC void
15f169a1 440S_printbuf(pTHX_ const char *const fmt, const char *const s)
b6007c36 441{
396482e1 442 SV* const tmp = newSVpvs("");
7918f24d
NC
443
444 PERL_ARGS_ASSERT_PRINTBUF;
445
b6007c36
DM
446 PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60));
447 SvREFCNT_dec(tmp);
448}
449
8fa7f367
JH
450#endif
451
8290c323
NC
452static int
453S_deprecate_commaless_var_list(pTHX) {
454 PL_expect = XTERM;
455 deprecate("comma-less variable list");
456 return REPORT(','); /* grandfather non-comma-format format */
457}
458
ffb4593c
NT
459/*
460 * S_ao
461 *
c963b151
BD
462 * This subroutine detects &&=, ||=, and //= and turns an ANDAND, OROR or DORDOR
463 * into an OP_ANDASSIGN, OP_ORASSIGN, or OP_DORASSIGN
ffb4593c
NT
464 */
465
76e3520e 466STATIC int
cea2e8a9 467S_ao(pTHX_ int toketype)
a0d0e21e 468{
97aff369 469 dVAR;
3280af22
NIS
470 if (*PL_bufptr == '=') {
471 PL_bufptr++;
a0d0e21e 472 if (toketype == ANDAND)
6154021b 473 pl_yylval.ival = OP_ANDASSIGN;
a0d0e21e 474 else if (toketype == OROR)
6154021b 475 pl_yylval.ival = OP_ORASSIGN;
c963b151 476 else if (toketype == DORDOR)
6154021b 477 pl_yylval.ival = OP_DORASSIGN;
a0d0e21e
LW
478 toketype = ASSIGNOP;
479 }
480 return toketype;
481}
482
ffb4593c
NT
483/*
484 * S_no_op
485 * When Perl expects an operator and finds something else, no_op
486 * prints the warning. It always prints "<something> found where
487 * operator expected. It prints "Missing semicolon on previous line?"
488 * if the surprise occurs at the start of the line. "do you need to
489 * predeclare ..." is printed out for code like "sub bar; foo bar $x"
490 * where the compiler doesn't know if foo is a method call or a function.
491 * It prints "Missing operator before end of line" if there's nothing
492 * after the missing operator, or "... before <...>" if there is something
493 * after the missing operator.
494 */
495
76e3520e 496STATIC void
15f169a1 497S_no_op(pTHX_ const char *const what, char *s)
463ee0b2 498{
97aff369 499 dVAR;
9d4ba2ae
AL
500 char * const oldbp = PL_bufptr;
501 const bool is_first = (PL_oldbufptr == PL_linestart);
68dc0745 502
7918f24d
NC
503 PERL_ARGS_ASSERT_NO_OP;
504
1189a94a
GS
505 if (!s)
506 s = oldbp;
07c798fb 507 else
1189a94a 508 PL_bufptr = s;
cea2e8a9 509 yywarn(Perl_form(aTHX_ "%s found where operator expected", what));
56da5a46
RGS
510 if (ckWARN_d(WARN_SYNTAX)) {
511 if (is_first)
512 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
513 "\t(Missing semicolon on previous line?)\n");
514 else if (PL_oldoldbufptr && isIDFIRST_lazy_if(PL_oldoldbufptr,UTF)) {
f54cb97a 515 const char *t;
c35e046a
AL
516 for (t = PL_oldoldbufptr; (isALNUM_lazy_if(t,UTF) || *t == ':'); t++)
517 NOOP;
56da5a46
RGS
518 if (t < PL_bufptr && isSPACE(*t))
519 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
520 "\t(Do you need to predeclare %.*s?)\n",
551405c4 521 (int)(t - PL_oldoldbufptr), PL_oldoldbufptr);
56da5a46
RGS
522 }
523 else {
524 assert(s >= oldbp);
525 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
551405c4 526 "\t(Missing operator before %.*s?)\n", (int)(s - oldbp), oldbp);
56da5a46 527 }
07c798fb 528 }
3280af22 529 PL_bufptr = oldbp;
8990e307
LW
530}
531
ffb4593c
NT
532/*
533 * S_missingterm
534 * Complain about missing quote/regexp/heredoc terminator.
d4c19fe8 535 * If it's called with NULL then it cauterizes the line buffer.
ffb4593c
NT
536 * If we're in a delimited string and the delimiter is a control
537 * character, it's reformatted into a two-char sequence like ^C.
538 * This is fatal.
539 */
540
76e3520e 541STATIC void
cea2e8a9 542S_missingterm(pTHX_ char *s)
8990e307 543{
97aff369 544 dVAR;
8990e307
LW
545 char tmpbuf[3];
546 char q;
547 if (s) {
9d4ba2ae 548 char * const nl = strrchr(s,'\n');
d2719217 549 if (nl)
8990e307
LW
550 *nl = '\0';
551 }
463559e7 552 else if (isCNTRL(PL_multi_close)) {
8990e307 553 *tmpbuf = '^';
585ec06d 554 tmpbuf[1] = (char)toCTRL(PL_multi_close);
8990e307
LW
555 tmpbuf[2] = '\0';
556 s = tmpbuf;
557 }
558 else {
eb160463 559 *tmpbuf = (char)PL_multi_close;
8990e307
LW
560 tmpbuf[1] = '\0';
561 s = tmpbuf;
562 }
563 q = strchr(s,'"') ? '\'' : '"';
cea2e8a9 564 Perl_croak(aTHX_ "Can't find string terminator %c%s%c anywhere before EOF",q,s,q);
463ee0b2 565}
79072805 566
ef89dcc3 567#define FEATURE_IS_ENABLED(name) \
0d863452 568 ((0 != (PL_hints & HINT_LOCALIZE_HH)) \
89529cee 569 && S_feature_is_enabled(aTHX_ STR_WITH_LEN(name)))
4a731d7b
NC
570/* The longest string we pass in. */
571#define MAX_FEATURE_LEN (sizeof("switch")-1)
572
0d863452
RH
573/*
574 * S_feature_is_enabled
575 * Check whether the named feature is enabled.
576 */
577STATIC bool
15f169a1 578S_feature_is_enabled(pTHX_ const char *const name, STRLEN namelen)
0d863452 579{
97aff369 580 dVAR;
0d863452 581 HV * const hinthv = GvHV(PL_hintgv);
4a731d7b 582 char he_name[8 + MAX_FEATURE_LEN] = "feature_";
7918f24d
NC
583
584 PERL_ARGS_ASSERT_FEATURE_IS_ENABLED;
585
4a731d7b
NC
586 assert(namelen <= MAX_FEATURE_LEN);
587 memcpy(&he_name[8], name, namelen);
d4c19fe8 588
7b9ef140 589 return (hinthv && hv_exists(hinthv, he_name, 8 + namelen));
0d863452
RH
590}
591
ffb4593c 592/*
9cbb5ea2
GS
593 * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
594 * utf16-to-utf8-reversed.
ffb4593c
NT
595 */
596
c39cd008
GS
597#ifdef PERL_CR_FILTER
598static void
599strip_return(SV *sv)
600{
95a20fc0 601 register const char *s = SvPVX_const(sv);
9d4ba2ae 602 register const char * const e = s + SvCUR(sv);
7918f24d
NC
603
604 PERL_ARGS_ASSERT_STRIP_RETURN;
605
c39cd008
GS
606 /* outer loop optimized to do nothing if there are no CR-LFs */
607 while (s < e) {
608 if (*s++ == '\r' && *s == '\n') {
609 /* hit a CR-LF, need to copy the rest */
610 register char *d = s - 1;
611 *d++ = *s++;
612 while (s < e) {
613 if (*s == '\r' && s[1] == '\n')
614 s++;
615 *d++ = *s++;
616 }
617 SvCUR(sv) -= s - d;
618 return;
619 }
620 }
621}
a868473f 622
76e3520e 623STATIC I32
c39cd008 624S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen)
a868473f 625{
f54cb97a 626 const I32 count = FILTER_READ(idx+1, sv, maxlen);
c39cd008
GS
627 if (count > 0 && !maxlen)
628 strip_return(sv);
629 return count;
a868473f
NIS
630}
631#endif
632
199e78b7
DM
633
634
ffb4593c
NT
635/*
636 * Perl_lex_start
5486870f 637 *
e3abe207 638 * Create a parser object and initialise its parser and lexer fields
5486870f
DM
639 *
640 * rsfp is the opened file handle to read from (if any),
641 *
642 * line holds any initial content already read from the file (or in
643 * the case of no file, such as an eval, the whole contents);
644 *
645 * new_filter indicates that this is a new file and it shouldn't inherit
646 * the filters from the current parser (ie require).
ffb4593c
NT
647 */
648
a0d0e21e 649void
5486870f 650Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, bool new_filter)
79072805 651{
97aff369 652 dVAR;
6ef55633 653 const char *s = NULL;
8990e307 654 STRLEN len;
5486870f 655 yy_parser *parser, *oparser;
acdf0a21
DM
656
657 /* create and initialise a parser */
658
199e78b7 659 Newxz(parser, 1, yy_parser);
5486870f 660 parser->old_parser = oparser = PL_parser;
acdf0a21
DM
661 PL_parser = parser;
662
663 Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
664 parser->ps = parser->stack;
665 parser->stack_size = YYINITDEPTH;
666
667 parser->stack->state = 0;
668 parser->yyerrstatus = 0;
669 parser->yychar = YYEMPTY; /* Cause a token to be read. */
670
e3abe207
DM
671 /* on scope exit, free this parser and restore any outer one */
672 SAVEPARSER(parser);
7c4baf47 673 parser->saved_curcop = PL_curcop;
e3abe207 674
acdf0a21 675 /* initialise lexer state */
8990e307 676
fb205e7a
DM
677#ifdef PERL_MAD
678 parser->curforce = -1;
679#else
680 parser->nexttoke = 0;
681#endif
ca4cfd28 682 parser->error_count = oparser ? oparser->error_count : 0;
c2598295 683 parser->copline = NOLINE;
5afb0a62 684 parser->lex_state = LEX_NORMAL;
c2598295 685 parser->expect = XSTATE;
2f9285f8 686 parser->rsfp = rsfp;
56b27c9a 687 parser->rsfp_filters = (new_filter || !oparser) ? newAV()
502c6561 688 : MUTABLE_AV(SvREFCNT_inc(oparser->rsfp_filters));
2f9285f8 689
199e78b7
DM
690 Newx(parser->lex_brackstack, 120, char);
691 Newx(parser->lex_casestack, 12, char);
692 *parser->lex_casestack = '\0';
02b34bbe 693
10efb74f
NC
694 if (line) {
695 s = SvPV_const(line, len);
696 } else {
697 len = 0;
698 }
bdc0bf6f 699
10efb74f 700 if (!len) {
bdc0bf6f 701 parser->linestr = newSVpvs("\n;");
10efb74f 702 } else if (SvREADONLY(line) || s[len-1] != ';') {
bdc0bf6f 703 parser->linestr = newSVsv(line);
10efb74f 704 if (s[len-1] != ';')
bdc0bf6f 705 sv_catpvs(parser->linestr, "\n;");
6c5ce11d
NC
706 } else {
707 SvTEMP_off(line);
708 SvREFCNT_inc_simple_void_NN(line);
bdc0bf6f 709 parser->linestr = line;
8990e307 710 }
f06b5848
DM
711 parser->oldoldbufptr =
712 parser->oldbufptr =
713 parser->bufptr =
714 parser->linestart = SvPVX(parser->linestr);
715 parser->bufend = parser->bufptr + SvCUR(parser->linestr);
716 parser->last_lop = parser->last_uni = NULL;
79072805 717}
a687059c 718
e3abe207
DM
719
720/* delete a parser object */
721
722void
723Perl_parser_free(pTHX_ const yy_parser *parser)
724{
7918f24d
NC
725 PERL_ARGS_ASSERT_PARSER_FREE;
726
7c4baf47 727 PL_curcop = parser->saved_curcop;
bdc0bf6f
DM
728 SvREFCNT_dec(parser->linestr);
729
2f9285f8
DM
730 if (parser->rsfp == PerlIO_stdin())
731 PerlIO_clearerr(parser->rsfp);
799361c3
SH
732 else if (parser->rsfp && (!parser->old_parser ||
733 (parser->old_parser && parser->rsfp != parser->old_parser->rsfp)))
2f9285f8 734 PerlIO_close(parser->rsfp);
5486870f 735 SvREFCNT_dec(parser->rsfp_filters);
2f9285f8 736
e3abe207
DM
737 Safefree(parser->stack);
738 Safefree(parser->lex_brackstack);
739 Safefree(parser->lex_casestack);
740 PL_parser = parser->old_parser;
741 Safefree(parser);
742}
743
744
ffb4593c
NT
745/*
746 * Perl_lex_end
9cbb5ea2
GS
747 * Finalizer for lexing operations. Must be called when the parser is
748 * done with the lexer.
ffb4593c
NT
749 */
750
463ee0b2 751void
864dbfa3 752Perl_lex_end(pTHX)
463ee0b2 753{
97aff369 754 dVAR;
3280af22 755 PL_doextract = FALSE;
463ee0b2
LW
756}
757
ffb4593c
NT
758/*
759 * S_incline
760 * This subroutine has nothing to do with tilting, whether at windmills
761 * or pinball tables. Its name is short for "increment line". It
57843af0 762 * increments the current line number in CopLINE(PL_curcop) and checks
ffb4593c 763 * to see whether the line starts with a comment of the form
9cbb5ea2
GS
764 * # line 500 "foo.pm"
765 * If so, it sets the current line number and file to the values in the comment.
ffb4593c
NT
766 */
767
76e3520e 768STATIC void
d9095cec 769S_incline(pTHX_ const char *s)
463ee0b2 770{
97aff369 771 dVAR;
d9095cec
NC
772 const char *t;
773 const char *n;
774 const char *e;
463ee0b2 775
7918f24d
NC
776 PERL_ARGS_ASSERT_INCLINE;
777
57843af0 778 CopLINE_inc(PL_curcop);
463ee0b2
LW
779 if (*s++ != '#')
780 return;
d4c19fe8
AL
781 while (SPACE_OR_TAB(*s))
782 s++;
73659bf1
GS
783 if (strnEQ(s, "line", 4))
784 s += 4;
785 else
786 return;
084592ab 787 if (SPACE_OR_TAB(*s))
73659bf1 788 s++;
4e553d73 789 else
73659bf1 790 return;
d4c19fe8
AL
791 while (SPACE_OR_TAB(*s))
792 s++;
463ee0b2
LW
793 if (!isDIGIT(*s))
794 return;
d4c19fe8 795
463ee0b2
LW
796 n = s;
797 while (isDIGIT(*s))
798 s++;
07714eb4 799 if (!SPACE_OR_TAB(*s) && *s != '\r' && *s != '\n' && *s != '\0')
26b6dc3f 800 return;
bf4acbe4 801 while (SPACE_OR_TAB(*s))
463ee0b2 802 s++;
73659bf1 803 if (*s == '"' && (t = strchr(s+1, '"'))) {
463ee0b2 804 s++;
73659bf1
GS
805 e = t + 1;
806 }
463ee0b2 807 else {
c35e046a
AL
808 t = s;
809 while (!isSPACE(*t))
810 t++;
73659bf1 811 e = t;
463ee0b2 812 }
bf4acbe4 813 while (SPACE_OR_TAB(*e) || *e == '\r' || *e == '\f')
73659bf1
GS
814 e++;
815 if (*e != '\n' && *e != '\0')
816 return; /* false alarm */
817
f4dd75d9 818 if (t - s > 0) {
d9095cec 819 const STRLEN len = t - s;
8a5ee598 820#ifndef USE_ITHREADS
19bad673
NC
821 SV *const temp_sv = CopFILESV(PL_curcop);
822 const char *cf;
823 STRLEN tmplen;
824
825 if (temp_sv) {
826 cf = SvPVX(temp_sv);
827 tmplen = SvCUR(temp_sv);
828 } else {
829 cf = NULL;
830 tmplen = 0;
831 }
832
42d9b98d 833 if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) {
e66cf94c
RGS
834 /* must copy *{"::_<(eval N)[oldfilename:L]"}
835 * to *{"::_<newfilename"} */
44867030
NC
836 /* However, the long form of evals is only turned on by the
837 debugger - usually they're "(eval %lu)" */
838 char smallbuf[128];
839 char *tmpbuf;
840 GV **gvp;
d9095cec 841 STRLEN tmplen2 = len;
798b63bc 842 if (tmplen + 2 <= sizeof smallbuf)
e66cf94c
RGS
843 tmpbuf = smallbuf;
844 else
2ae0db35 845 Newx(tmpbuf, tmplen + 2, char);
44867030
NC
846 tmpbuf[0] = '_';
847 tmpbuf[1] = '<';
2ae0db35 848 memcpy(tmpbuf + 2, cf, tmplen);
44867030 849 tmplen += 2;
8a5ee598
RGS
850 gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
851 if (gvp) {
44867030
NC
852 char *tmpbuf2;
853 GV *gv2;
854
855 if (tmplen2 + 2 <= sizeof smallbuf)
856 tmpbuf2 = smallbuf;
857 else
858 Newx(tmpbuf2, tmplen2 + 2, char);
859
860 if (tmpbuf2 != smallbuf || tmpbuf != smallbuf) {
861 /* Either they malloc'd it, or we malloc'd it,
862 so no prefix is present in ours. */
863 tmpbuf2[0] = '_';
864 tmpbuf2[1] = '<';
865 }
866
867 memcpy(tmpbuf2 + 2, s, tmplen2);
868 tmplen2 += 2;
869
8a5ee598 870 gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
e5527e4b 871 if (!isGV(gv2)) {
8a5ee598 872 gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
e5527e4b
RGS
873 /* adjust ${"::_<newfilename"} to store the new file name */
874 GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
3cb1dbc6
NC
875 GvHV(gv2) = MUTABLE_HV(SvREFCNT_inc(GvHV(*gvp)));
876 GvAV(gv2) = MUTABLE_AV(SvREFCNT_inc(GvAV(*gvp)));
e5527e4b 877 }
44867030
NC
878
879 if (tmpbuf2 != smallbuf) Safefree(tmpbuf2);
8a5ee598 880 }
e66cf94c 881 if (tmpbuf != smallbuf) Safefree(tmpbuf);
e66cf94c 882 }
8a5ee598 883#endif
05ec9bb3 884 CopFILE_free(PL_curcop);
d9095cec 885 CopFILE_setn(PL_curcop, s, len);
f4dd75d9 886 }
57843af0 887 CopLINE_set(PL_curcop, atoi(n)-1);
463ee0b2
LW
888}
889
29595ff2 890#ifdef PERL_MAD
cd81e915 891/* skip space before PL_thistoken */
29595ff2
NC
892
893STATIC char *
894S_skipspace0(pTHX_ register char *s)
895{
7918f24d
NC
896 PERL_ARGS_ASSERT_SKIPSPACE0;
897
29595ff2
NC
898 s = skipspace(s);
899 if (!PL_madskills)
900 return s;
cd81e915
NC
901 if (PL_skipwhite) {
902 if (!PL_thiswhite)
6b29d1f5 903 PL_thiswhite = newSVpvs("");
cd81e915
NC
904 sv_catsv(PL_thiswhite, PL_skipwhite);
905 sv_free(PL_skipwhite);
906 PL_skipwhite = 0;
907 }
908 PL_realtokenstart = s - SvPVX(PL_linestr);
29595ff2
NC
909 return s;
910}
911
cd81e915 912/* skip space after PL_thistoken */
29595ff2
NC
913
914STATIC char *
915S_skipspace1(pTHX_ register char *s)
916{
d4c19fe8 917 const char *start = s;
29595ff2
NC
918 I32 startoff = start - SvPVX(PL_linestr);
919
7918f24d
NC
920 PERL_ARGS_ASSERT_SKIPSPACE1;
921
29595ff2
NC
922 s = skipspace(s);
923 if (!PL_madskills)
924 return s;
925 start = SvPVX(PL_linestr) + startoff;
cd81e915 926 if (!PL_thistoken && PL_realtokenstart >= 0) {
d4c19fe8 927 const char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915
NC
928 PL_thistoken = newSVpvn(tstart, start - tstart);
929 }
930 PL_realtokenstart = -1;
931 if (PL_skipwhite) {
932 if (!PL_nextwhite)
6b29d1f5 933 PL_nextwhite = newSVpvs("");
cd81e915
NC
934 sv_catsv(PL_nextwhite, PL_skipwhite);
935 sv_free(PL_skipwhite);
936 PL_skipwhite = 0;
29595ff2
NC
937 }
938 return s;
939}
940
941STATIC char *
942S_skipspace2(pTHX_ register char *s, SV **svp)
943{
c35e046a
AL
944 char *start;
945 const I32 bufptroff = PL_bufptr - SvPVX(PL_linestr);
946 const I32 startoff = s - SvPVX(PL_linestr);
947
7918f24d
NC
948 PERL_ARGS_ASSERT_SKIPSPACE2;
949
29595ff2
NC
950 s = skipspace(s);
951 PL_bufptr = SvPVX(PL_linestr) + bufptroff;
952 if (!PL_madskills || !svp)
953 return s;
954 start = SvPVX(PL_linestr) + startoff;
cd81e915 955 if (!PL_thistoken && PL_realtokenstart >= 0) {
d4c19fe8 956 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915
NC
957 PL_thistoken = newSVpvn(tstart, start - tstart);
958 PL_realtokenstart = -1;
29595ff2 959 }
cd81e915 960 if (PL_skipwhite) {
29595ff2 961 if (!*svp)
6b29d1f5 962 *svp = newSVpvs("");
cd81e915
NC
963 sv_setsv(*svp, PL_skipwhite);
964 sv_free(PL_skipwhite);
965 PL_skipwhite = 0;
29595ff2
NC
966 }
967
968 return s;
969}
970#endif
971
80a702cd 972STATIC void
15f169a1 973S_update_debugger_info(pTHX_ SV *orig_sv, const char *const buf, STRLEN len)
80a702cd
RGS
974{
975 AV *av = CopFILEAVx(PL_curcop);
976 if (av) {
b9f83d2f 977 SV * const sv = newSV_type(SVt_PVMG);
5fa550fb
NC
978 if (orig_sv)
979 sv_setsv(sv, orig_sv);
980 else
981 sv_setpvn(sv, buf, len);
80a702cd
RGS
982 (void)SvIOK_on(sv);
983 SvIV_set(sv, 0);
984 av_store(av, (I32)CopLINE(PL_curcop), sv);
985 }
986}
987
ffb4593c
NT
988/*
989 * S_skipspace
990 * Called to gobble the appropriate amount and type of whitespace.
991 * Skips comments as well.
992 */
993
76e3520e 994STATIC char *
cea2e8a9 995S_skipspace(pTHX_ register char *s)
a687059c 996{
97aff369 997 dVAR;
5db06880
NC
998#ifdef PERL_MAD
999 int curoff;
1000 int startoff = s - SvPVX(PL_linestr);
1001
7918f24d
NC
1002 PERL_ARGS_ASSERT_SKIPSPACE;
1003
cd81e915
NC
1004 if (PL_skipwhite) {
1005 sv_free(PL_skipwhite);
1006 PL_skipwhite = 0;
5db06880
NC
1007 }
1008#endif
7918f24d 1009 PERL_ARGS_ASSERT_SKIPSPACE;
5db06880 1010
3280af22 1011 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
bf4acbe4 1012 while (s < PL_bufend && SPACE_OR_TAB(*s))
463ee0b2 1013 s++;
5db06880
NC
1014#ifdef PERL_MAD
1015 goto done;
1016#else
463ee0b2 1017 return s;
5db06880 1018#endif
463ee0b2
LW
1019 }
1020 for (;;) {
fd049845 1021 STRLEN prevlen;
09bef843 1022 SSize_t oldprevlen, oldoldprevlen;
9c5ffd7c 1023 SSize_t oldloplen = 0, oldunilen = 0;
60e6418e
GS
1024 while (s < PL_bufend && isSPACE(*s)) {
1025 if (*s++ == '\n' && PL_in_eval && !PL_rsfp)
1026 incline(s);
1027 }
ffb4593c
NT
1028
1029 /* comment */
3280af22
NIS
1030 if (s < PL_bufend && *s == '#') {
1031 while (s < PL_bufend && *s != '\n')
463ee0b2 1032 s++;
60e6418e 1033 if (s < PL_bufend) {
463ee0b2 1034 s++;
60e6418e
GS
1035 if (PL_in_eval && !PL_rsfp) {
1036 incline(s);
1037 continue;
1038 }
1039 }
463ee0b2 1040 }
ffb4593c
NT
1041
1042 /* only continue to recharge the buffer if we're at the end
1043 * of the buffer, we're not reading from a source filter, and
1044 * we're in normal lexing mode
1045 */
09bef843
SB
1046 if (s < PL_bufend || !PL_rsfp || PL_sublex_info.sub_inwhat ||
1047 PL_lex_state == LEX_FORMLINE)
5db06880
NC
1048#ifdef PERL_MAD
1049 goto done;
1050#else
463ee0b2 1051 return s;
5db06880 1052#endif
ffb4593c
NT
1053
1054 /* try to recharge the buffer */
5db06880
NC
1055#ifdef PERL_MAD
1056 curoff = s - SvPVX(PL_linestr);
1057#endif
1058
5cc814fd
NC
1059 if ((s = filter_gets(PL_linestr, (prevlen = SvCUR(PL_linestr))))
1060 == NULL)
9cbb5ea2 1061 {
5db06880
NC
1062#ifdef PERL_MAD
1063 if (PL_madskills && curoff != startoff) {
cd81e915 1064 if (!PL_skipwhite)
6b29d1f5 1065 PL_skipwhite = newSVpvs("");
cd81e915 1066 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
5db06880
NC
1067 curoff - startoff);
1068 }
1069
1070 /* mustn't throw out old stuff yet if madpropping */
1071 SvCUR(PL_linestr) = curoff;
1072 s = SvPVX(PL_linestr) + curoff;
1073 *s = 0;
1074 if (curoff && s[-1] == '\n')
1075 s[-1] = ' ';
1076#endif
1077
9cbb5ea2 1078 /* end of file. Add on the -p or -n magic */
cd81e915 1079 /* XXX these shouldn't really be added here, can't set PL_faketokens */
01a19ab0 1080 if (PL_minus_p) {
5db06880 1081#ifdef PERL_MAD
6502358f 1082 sv_catpvs(PL_linestr,
5db06880
NC
1083 ";}continue{print or die qq(-p destination: $!\\n);}");
1084#else
6502358f 1085 sv_setpvs(PL_linestr,
01a19ab0 1086 ";}continue{print or die qq(-p destination: $!\\n);}");
5db06880 1087#endif
3280af22 1088 PL_minus_n = PL_minus_p = 0;
a0d0e21e 1089 }
01a19ab0 1090 else if (PL_minus_n) {
5db06880 1091#ifdef PERL_MAD
76f68e9b 1092 sv_catpvs(PL_linestr, ";}");
5db06880 1093#else
76f68e9b 1094 sv_setpvs(PL_linestr, ";}");
5db06880 1095#endif
01a19ab0
NC
1096 PL_minus_n = 0;
1097 }
a0d0e21e 1098 else
5db06880 1099#ifdef PERL_MAD
76f68e9b 1100 sv_catpvs(PL_linestr,";");
5db06880 1101#else
76f68e9b 1102 sv_setpvs(PL_linestr,";");
5db06880 1103#endif
ffb4593c
NT
1104
1105 /* reset variables for next time we lex */
9cbb5ea2 1106 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart
89122651
NC
1107 = SvPVX(PL_linestr)
1108#ifdef PERL_MAD
1109 + curoff
1110#endif
1111 ;
3280af22 1112 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 1113 PL_last_lop = PL_last_uni = NULL;
ffb4593c 1114
4c84d7f2 1115 /* Close the filehandle. Could be from
ffb4593c
NT
1116 * STDIN, or a regular file. If we were reading code from
1117 * STDIN (because the commandline held no -e or filename)
1118 * then we don't close it, we reset it so the code can
1119 * read from STDIN too.
1120 */
1121
4c84d7f2 1122 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
3280af22 1123 PerlIO_clearerr(PL_rsfp);
8990e307 1124 else
3280af22 1125 (void)PerlIO_close(PL_rsfp);
4608196e 1126 PL_rsfp = NULL;
463ee0b2
LW
1127 return s;
1128 }
ffb4593c
NT
1129
1130 /* not at end of file, so we only read another line */
09bef843
SB
1131 /* make corresponding updates to old pointers, for yyerror() */
1132 oldprevlen = PL_oldbufptr - PL_bufend;
1133 oldoldprevlen = PL_oldoldbufptr - PL_bufend;
1134 if (PL_last_uni)
1135 oldunilen = PL_last_uni - PL_bufend;
1136 if (PL_last_lop)
1137 oldloplen = PL_last_lop - PL_bufend;
3280af22
NIS
1138 PL_linestart = PL_bufptr = s + prevlen;
1139 PL_bufend = s + SvCUR(PL_linestr);
1140 s = PL_bufptr;
09bef843
SB
1141 PL_oldbufptr = s + oldprevlen;
1142 PL_oldoldbufptr = s + oldoldprevlen;
1143 if (PL_last_uni)
1144 PL_last_uni = s + oldunilen;
1145 if (PL_last_lop)
1146 PL_last_lop = s + oldloplen;
a0d0e21e 1147 incline(s);
ffb4593c
NT
1148
1149 /* debugger active and we're not compiling the debugger code,
1150 * so store the line into the debugger's array of lines
1151 */
65269a95 1152 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 1153 update_debugger_info(NULL, PL_bufptr, PL_bufend - PL_bufptr);
463ee0b2 1154 }
5db06880
NC
1155
1156#ifdef PERL_MAD
1157 done:
1158 if (PL_madskills) {
cd81e915 1159 if (!PL_skipwhite)
6b29d1f5 1160 PL_skipwhite = newSVpvs("");
5db06880
NC
1161 curoff = s - SvPVX(PL_linestr);
1162 if (curoff - startoff)
cd81e915 1163 sv_catpvn(PL_skipwhite, SvPVX(PL_linestr) + startoff,
5db06880
NC
1164 curoff - startoff);
1165 }
1166 return s;
1167#endif
a687059c 1168}
378cc40b 1169
ffb4593c
NT
1170/*
1171 * S_check_uni
1172 * Check the unary operators to ensure there's no ambiguity in how they're
1173 * used. An ambiguous piece of code would be:
1174 * rand + 5
1175 * This doesn't mean rand() + 5. Because rand() is a unary operator,
1176 * the +5 is its argument.
1177 */
1178
76e3520e 1179STATIC void
cea2e8a9 1180S_check_uni(pTHX)
ba106d47 1181{
97aff369 1182 dVAR;
d4c19fe8
AL
1183 const char *s;
1184 const char *t;
2f3197b3 1185
3280af22 1186 if (PL_oldoldbufptr != PL_last_uni)
2f3197b3 1187 return;
3280af22
NIS
1188 while (isSPACE(*PL_last_uni))
1189 PL_last_uni++;
c35e046a
AL
1190 s = PL_last_uni;
1191 while (isALNUM_lazy_if(s,UTF) || *s == '-')
1192 s++;
3280af22 1193 if ((t = strchr(s, '(')) && t < PL_bufptr)
a0d0e21e 1194 return;
6136c704 1195
9b387841
NC
1196 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
1197 "Warning: Use of \"%.*s\" without parentheses is ambiguous",
1198 (int)(s - PL_last_uni), PL_last_uni);
2f3197b3
LW
1199}
1200
ffb4593c
NT
1201/*
1202 * LOP : macro to build a list operator. Its behaviour has been replaced
1203 * with a subroutine, S_lop() for which LOP is just another name.
1204 */
1205
a0d0e21e
LW
1206#define LOP(f,x) return lop(f,x,s)
1207
ffb4593c
NT
1208/*
1209 * S_lop
1210 * Build a list operator (or something that might be one). The rules:
1211 * - if we have a next token, then it's a list operator [why?]
1212 * - if the next thing is an opening paren, then it's a function
1213 * - else it's a list operator
1214 */
1215
76e3520e 1216STATIC I32
a0be28da 1217S_lop(pTHX_ I32 f, int x, char *s)
ffed7fef 1218{
97aff369 1219 dVAR;
7918f24d
NC
1220
1221 PERL_ARGS_ASSERT_LOP;
1222
6154021b 1223 pl_yylval.ival = f;
35c8bce7 1224 CLINE;
3280af22
NIS
1225 PL_expect = x;
1226 PL_bufptr = s;
1227 PL_last_lop = PL_oldbufptr;
eb160463 1228 PL_last_lop_op = (OPCODE)f;
5db06880
NC
1229#ifdef PERL_MAD
1230 if (PL_lasttoke)
1231 return REPORT(LSTOP);
1232#else
3280af22 1233 if (PL_nexttoke)
bbf60fe6 1234 return REPORT(LSTOP);
5db06880 1235#endif
79072805 1236 if (*s == '(')
bbf60fe6 1237 return REPORT(FUNC);
29595ff2 1238 s = PEEKSPACE(s);
79072805 1239 if (*s == '(')
bbf60fe6 1240 return REPORT(FUNC);
79072805 1241 else
bbf60fe6 1242 return REPORT(LSTOP);
79072805
LW
1243}
1244
5db06880
NC
1245#ifdef PERL_MAD
1246 /*
1247 * S_start_force
1248 * Sets up for an eventual force_next(). start_force(0) basically does
1249 * an unshift, while start_force(-1) does a push. yylex removes items
1250 * on the "pop" end.
1251 */
1252
1253STATIC void
1254S_start_force(pTHX_ int where)
1255{
1256 int i;
1257
cd81e915 1258 if (where < 0) /* so people can duplicate start_force(PL_curforce) */
5db06880 1259 where = PL_lasttoke;
cd81e915
NC
1260 assert(PL_curforce < 0 || PL_curforce == where);
1261 if (PL_curforce != where) {
5db06880
NC
1262 for (i = PL_lasttoke; i > where; --i) {
1263 PL_nexttoke[i] = PL_nexttoke[i-1];
1264 }
1265 PL_lasttoke++;
1266 }
cd81e915 1267 if (PL_curforce < 0) /* in case of duplicate start_force() */
5db06880 1268 Zero(&PL_nexttoke[where], 1, NEXTTOKE);
cd81e915
NC
1269 PL_curforce = where;
1270 if (PL_nextwhite) {
5db06880 1271 if (PL_madskills)
6b29d1f5 1272 curmad('^', newSVpvs(""));
cd81e915 1273 CURMAD('_', PL_nextwhite);
5db06880
NC
1274 }
1275}
1276
1277STATIC void
1278S_curmad(pTHX_ char slot, SV *sv)
1279{
1280 MADPROP **where;
1281
1282 if (!sv)
1283 return;
cd81e915
NC
1284 if (PL_curforce < 0)
1285 where = &PL_thismad;
5db06880 1286 else
cd81e915 1287 where = &PL_nexttoke[PL_curforce].next_mad;
5db06880 1288
cd81e915 1289 if (PL_faketokens)
76f68e9b 1290 sv_setpvs(sv, "");
5db06880
NC
1291 else {
1292 if (!IN_BYTES) {
1293 if (UTF && is_utf8_string((U8*)SvPVX(sv), SvCUR(sv)))
1294 SvUTF8_on(sv);
1295 else if (PL_encoding) {
1296 sv_recode_to_utf8(sv, PL_encoding);
1297 }
1298 }
1299 }
1300
1301 /* keep a slot open for the head of the list? */
1302 if (slot != '_' && *where && (*where)->mad_key == '^') {
1303 (*where)->mad_key = slot;
daba3364 1304 sv_free(MUTABLE_SV(((*where)->mad_val)));
5db06880
NC
1305 (*where)->mad_val = (void*)sv;
1306 }
1307 else
1308 addmad(newMADsv(slot, sv), where, 0);
1309}
1310#else
b3f24c00
MHM
1311# define start_force(where) NOOP
1312# define curmad(slot, sv) NOOP
5db06880
NC
1313#endif
1314
ffb4593c
NT
1315/*
1316 * S_force_next
9cbb5ea2 1317 * When the lexer realizes it knows the next token (for instance,
ffb4593c 1318 * it is reordering tokens for the parser) then it can call S_force_next
9cbb5ea2 1319 * to know what token to return the next time the lexer is called. Caller
5db06880
NC
1320 * will need to set PL_nextval[] (or PL_nexttoke[].next_val with PERL_MAD),
1321 * and possibly PL_expect to ensure the lexer handles the token correctly.
ffb4593c
NT
1322 */
1323
4e553d73 1324STATIC void
cea2e8a9 1325S_force_next(pTHX_ I32 type)
79072805 1326{
97aff369 1327 dVAR;
704d4215
GG
1328#ifdef DEBUGGING
1329 if (DEBUG_T_TEST) {
1330 PerlIO_printf(Perl_debug_log, "### forced token:\n");
f05d7009 1331 tokereport(type, &NEXTVAL_NEXTTOKE);
704d4215
GG
1332 }
1333#endif
5db06880 1334#ifdef PERL_MAD
cd81e915 1335 if (PL_curforce < 0)
5db06880 1336 start_force(PL_lasttoke);
cd81e915 1337 PL_nexttoke[PL_curforce].next_type = type;
5db06880
NC
1338 if (PL_lex_state != LEX_KNOWNEXT)
1339 PL_lex_defer = PL_lex_state;
1340 PL_lex_state = LEX_KNOWNEXT;
1341 PL_lex_expect = PL_expect;
cd81e915 1342 PL_curforce = -1;
5db06880 1343#else
3280af22
NIS
1344 PL_nexttype[PL_nexttoke] = type;
1345 PL_nexttoke++;
1346 if (PL_lex_state != LEX_KNOWNEXT) {
1347 PL_lex_defer = PL_lex_state;
1348 PL_lex_expect = PL_expect;
1349 PL_lex_state = LEX_KNOWNEXT;
79072805 1350 }
5db06880 1351#endif
79072805
LW
1352}
1353
d0a148a6 1354STATIC SV *
15f169a1 1355S_newSV_maybe_utf8(pTHX_ const char *const start, STRLEN len)
d0a148a6 1356{
97aff369 1357 dVAR;
740cce10 1358 SV * const sv = newSVpvn_utf8(start, len,
eaf7a4d2
CS
1359 !IN_BYTES
1360 && UTF
1361 && !is_ascii_string((const U8*)start, len)
740cce10 1362 && is_utf8_string((const U8*)start, len));
d0a148a6
NC
1363 return sv;
1364}
1365
ffb4593c
NT
1366/*
1367 * S_force_word
1368 * When the lexer knows the next thing is a word (for instance, it has
1369 * just seen -> and it knows that the next char is a word char, then
02b34bbe
DM
1370 * it calls S_force_word to stick the next word into the PL_nexttoke/val
1371 * lookahead.
ffb4593c
NT
1372 *
1373 * Arguments:
b1b65b59 1374 * char *start : buffer position (must be within PL_linestr)
02b34bbe 1375 * int token : PL_next* will be this type of bare word (e.g., METHOD,WORD)
ffb4593c
NT
1376 * int check_keyword : if true, Perl checks to make sure the word isn't
1377 * a keyword (do this if the word is a label, e.g. goto FOO)
1378 * int allow_pack : if true, : characters will also be allowed (require,
1379 * use, etc. do this)
9cbb5ea2 1380 * int allow_initial_tick : used by the "sub" lexer only.
ffb4593c
NT
1381 */
1382
76e3520e 1383STATIC char *
cea2e8a9 1384S_force_word(pTHX_ register char *start, int token, int check_keyword, int allow_pack, int allow_initial_tick)
79072805 1385{
97aff369 1386 dVAR;
463ee0b2
LW
1387 register char *s;
1388 STRLEN len;
4e553d73 1389
7918f24d
NC
1390 PERL_ARGS_ASSERT_FORCE_WORD;
1391
29595ff2 1392 start = SKIPSPACE1(start);
463ee0b2 1393 s = start;
7e2040f0 1394 if (isIDFIRST_lazy_if(s,UTF) ||
a0d0e21e 1395 (allow_pack && *s == ':') ||
15f0808c 1396 (allow_initial_tick && *s == '\'') )
a0d0e21e 1397 {
3280af22 1398 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, allow_pack, &len);
5458a98a 1399 if (check_keyword && keyword(PL_tokenbuf, len, 0))
463ee0b2 1400 return start;
cd81e915 1401 start_force(PL_curforce);
5db06880
NC
1402 if (PL_madskills)
1403 curmad('X', newSVpvn(start,s-start));
463ee0b2 1404 if (token == METHOD) {
29595ff2 1405 s = SKIPSPACE1(s);
463ee0b2 1406 if (*s == '(')
3280af22 1407 PL_expect = XTERM;
463ee0b2 1408 else {
3280af22 1409 PL_expect = XOPERATOR;
463ee0b2 1410 }
79072805 1411 }
e74e6b3d 1412 if (PL_madskills)
63575281 1413 curmad('g', newSVpvs( "forced" ));
9ded7720 1414 NEXTVAL_NEXTTOKE.opval
d0a148a6
NC
1415 = (OP*)newSVOP(OP_CONST,0,
1416 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
9ded7720 1417 NEXTVAL_NEXTTOKE.opval->op_private |= OPpCONST_BARE;
79072805
LW
1418 force_next(token);
1419 }
1420 return s;
1421}
1422
ffb4593c
NT
1423/*
1424 * S_force_ident
9cbb5ea2 1425 * Called when the lexer wants $foo *foo &foo etc, but the program
ffb4593c
NT
1426 * text only contains the "foo" portion. The first argument is a pointer
1427 * to the "foo", and the second argument is the type symbol to prefix.
1428 * Forces the next token to be a "WORD".
9cbb5ea2 1429 * Creates the symbol if it didn't already exist (via gv_fetchpv()).
ffb4593c
NT
1430 */
1431
76e3520e 1432STATIC void
bfed75c6 1433S_force_ident(pTHX_ register const char *s, int kind)
79072805 1434{
97aff369 1435 dVAR;
7918f24d
NC
1436
1437 PERL_ARGS_ASSERT_FORCE_IDENT;
1438
c35e046a 1439 if (*s) {
90e5519e
NC
1440 const STRLEN len = strlen(s);
1441 OP* const o = (OP*)newSVOP(OP_CONST, 0, newSVpvn(s, len));
cd81e915 1442 start_force(PL_curforce);
9ded7720 1443 NEXTVAL_NEXTTOKE.opval = o;
79072805 1444 force_next(WORD);
748a9306 1445 if (kind) {
11343788 1446 o->op_private = OPpCONST_ENTERED;
55497cff 1447 /* XXX see note in pp_entereval() for why we forgo typo
1448 warnings if the symbol must be introduced in an eval.
1449 GSAR 96-10-12 */
90e5519e
NC
1450 gv_fetchpvn_flags(s, len,
1451 PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL)
1452 : GV_ADD,
1453 kind == '$' ? SVt_PV :
1454 kind == '@' ? SVt_PVAV :
1455 kind == '%' ? SVt_PVHV :
a0d0e21e 1456 SVt_PVGV
90e5519e 1457 );
748a9306 1458 }
79072805
LW
1459 }
1460}
1461
1571675a
GS
1462NV
1463Perl_str_to_version(pTHX_ SV *sv)
1464{
1465 NV retval = 0.0;
1466 NV nshift = 1.0;
1467 STRLEN len;
cfd0369c 1468 const char *start = SvPV_const(sv,len);
9d4ba2ae 1469 const char * const end = start + len;
504618e9 1470 const bool utf = SvUTF8(sv) ? TRUE : FALSE;
7918f24d
NC
1471
1472 PERL_ARGS_ASSERT_STR_TO_VERSION;
1473
1571675a 1474 while (start < end) {
ba210ebe 1475 STRLEN skip;
1571675a
GS
1476 UV n;
1477 if (utf)
9041c2e3 1478 n = utf8n_to_uvchr((U8*)start, len, &skip, 0);
1571675a
GS
1479 else {
1480 n = *(U8*)start;
1481 skip = 1;
1482 }
1483 retval += ((NV)n)/nshift;
1484 start += skip;
1485 nshift *= 1000;
1486 }
1487 return retval;
1488}
1489
4e553d73 1490/*
ffb4593c
NT
1491 * S_force_version
1492 * Forces the next token to be a version number.
e759cc13
RGS
1493 * If the next token appears to be an invalid version number, (e.g. "v2b"),
1494 * and if "guessing" is TRUE, then no new token is created (and the caller
1495 * must use an alternative parsing method).
ffb4593c
NT
1496 */
1497
76e3520e 1498STATIC char *
e759cc13 1499S_force_version(pTHX_ char *s, int guessing)
89bfa8cd 1500{
97aff369 1501 dVAR;
5f66b61c 1502 OP *version = NULL;
44dcb63b 1503 char *d;
5db06880
NC
1504#ifdef PERL_MAD
1505 I32 startoff = s - SvPVX(PL_linestr);
1506#endif
89bfa8cd 1507
7918f24d
NC
1508 PERL_ARGS_ASSERT_FORCE_VERSION;
1509
29595ff2 1510 s = SKIPSPACE1(s);
89bfa8cd 1511
44dcb63b 1512 d = s;
dd629d5b 1513 if (*d == 'v')
44dcb63b 1514 d++;
44dcb63b 1515 if (isDIGIT(*d)) {
e759cc13
RGS
1516 while (isDIGIT(*d) || *d == '_' || *d == '.')
1517 d++;
5db06880
NC
1518#ifdef PERL_MAD
1519 if (PL_madskills) {
cd81e915 1520 start_force(PL_curforce);
5db06880
NC
1521 curmad('X', newSVpvn(s,d-s));
1522 }
1523#endif
9f3d182e 1524 if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
dd629d5b 1525 SV *ver;
6154021b
RGS
1526 s = scan_num(s, &pl_yylval);
1527 version = pl_yylval.opval;
dd629d5b
GS
1528 ver = cSVOPx(version)->op_sv;
1529 if (SvPOK(ver) && !SvNIOK(ver)) {
862a34c6 1530 SvUPGRADE(ver, SVt_PVNV);
9d6ce603 1531 SvNV_set(ver, str_to_version(ver));
1571675a 1532 SvNOK_on(ver); /* hint that it is a version */
44dcb63b 1533 }
89bfa8cd 1534 }
5db06880
NC
1535 else if (guessing) {
1536#ifdef PERL_MAD
1537 if (PL_madskills) {
cd81e915
NC
1538 sv_free(PL_nextwhite); /* let next token collect whitespace */
1539 PL_nextwhite = 0;
5db06880
NC
1540 s = SvPVX(PL_linestr) + startoff;
1541 }
1542#endif
e759cc13 1543 return s;
5db06880 1544 }
89bfa8cd 1545 }
1546
5db06880
NC
1547#ifdef PERL_MAD
1548 if (PL_madskills && !version) {
cd81e915
NC
1549 sv_free(PL_nextwhite); /* let next token collect whitespace */
1550 PL_nextwhite = 0;
5db06880
NC
1551 s = SvPVX(PL_linestr) + startoff;
1552 }
1553#endif
89bfa8cd 1554 /* NOTE: The parser sees the package name and the VERSION swapped */
cd81e915 1555 start_force(PL_curforce);
9ded7720 1556 NEXTVAL_NEXTTOKE.opval = version;
4e553d73 1557 force_next(WORD);
89bfa8cd 1558
e759cc13 1559 return s;
89bfa8cd 1560}
1561
ffb4593c
NT
1562/*
1563 * S_tokeq
1564 * Tokenize a quoted string passed in as an SV. It finds the next
1565 * chunk, up to end of string or a backslash. It may make a new
1566 * SV containing that chunk (if HINT_NEW_STRING is on). It also
1567 * turns \\ into \.
1568 */
1569
76e3520e 1570STATIC SV *
cea2e8a9 1571S_tokeq(pTHX_ SV *sv)
79072805 1572{
97aff369 1573 dVAR;
79072805
LW
1574 register char *s;
1575 register char *send;
1576 register char *d;
b3ac6de7
IZ
1577 STRLEN len = 0;
1578 SV *pv = sv;
79072805 1579
7918f24d
NC
1580 PERL_ARGS_ASSERT_TOKEQ;
1581
79072805 1582 if (!SvLEN(sv))
b3ac6de7 1583 goto finish;
79072805 1584
a0d0e21e 1585 s = SvPV_force(sv, len);
21a311ee 1586 if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
b3ac6de7 1587 goto finish;
463ee0b2 1588 send = s + len;
79072805
LW
1589 while (s < send && *s != '\\')
1590 s++;
1591 if (s == send)
b3ac6de7 1592 goto finish;
79072805 1593 d = s;
be4731d2 1594 if ( PL_hints & HINT_NEW_STRING ) {
59cd0e26 1595 pv = newSVpvn_flags(SvPVX_const(pv), len, SVs_TEMP | SvUTF8(sv));
be4731d2 1596 }
79072805
LW
1597 while (s < send) {
1598 if (*s == '\\') {
a0d0e21e 1599 if (s + 1 < send && (s[1] == '\\'))
79072805
LW
1600 s++; /* all that, just for this */
1601 }
1602 *d++ = *s++;
1603 }
1604 *d = '\0';
95a20fc0 1605 SvCUR_set(sv, d - SvPVX_const(sv));
b3ac6de7 1606 finish:
3280af22 1607 if ( PL_hints & HINT_NEW_STRING )
eb0d8d16 1608 return new_constant(NULL, 0, "q", sv, pv, "q", 1);
79072805
LW
1609 return sv;
1610}
1611
ffb4593c
NT
1612/*
1613 * Now come three functions related to double-quote context,
1614 * S_sublex_start, S_sublex_push, and S_sublex_done. They're used when
1615 * converting things like "\u\Lgnat" into ucfirst(lc("gnat")). They
1616 * interact with PL_lex_state, and create fake ( ... ) argument lists
1617 * to handle functions and concatenation.
1618 * They assume that whoever calls them will be setting up a fake
1619 * join call, because each subthing puts a ',' after it. This lets
1620 * "lower \luPpEr"
1621 * become
1622 * join($, , 'lower ', lcfirst( 'uPpEr', ) ,)
1623 *
1624 * (I'm not sure whether the spurious commas at the end of lcfirst's
1625 * arguments and join's arguments are created or not).
1626 */
1627
1628/*
1629 * S_sublex_start
6154021b 1630 * Assumes that pl_yylval.ival is the op we're creating (e.g. OP_LCFIRST).
ffb4593c
NT
1631 *
1632 * Pattern matching will set PL_lex_op to the pattern-matching op to
6154021b 1633 * make (we return THING if pl_yylval.ival is OP_NULL, PMFUNC otherwise).
ffb4593c
NT
1634 *
1635 * OP_CONST and OP_READLINE are easy--just make the new op and return.
1636 *
1637 * Everything else becomes a FUNC.
1638 *
1639 * Sets PL_lex_state to LEX_INTERPPUSH unless (ival was OP_NULL or we
1640 * had an OP_CONST or OP_READLINE). This just sets us up for a
1641 * call to S_sublex_push().
1642 */
1643
76e3520e 1644STATIC I32
cea2e8a9 1645S_sublex_start(pTHX)
79072805 1646{
97aff369 1647 dVAR;
6154021b 1648 register const I32 op_type = pl_yylval.ival;
79072805
LW
1649
1650 if (op_type == OP_NULL) {
6154021b 1651 pl_yylval.opval = PL_lex_op;
5f66b61c 1652 PL_lex_op = NULL;
79072805
LW
1653 return THING;
1654 }
1655 if (op_type == OP_CONST || op_type == OP_READLINE) {
3280af22 1656 SV *sv = tokeq(PL_lex_stuff);
b3ac6de7
IZ
1657
1658 if (SvTYPE(sv) == SVt_PVIV) {
1659 /* Overloaded constants, nothing fancy: Convert to SVt_PV: */
1660 STRLEN len;
96a5add6 1661 const char * const p = SvPV_const(sv, len);
740cce10 1662 SV * const nsv = newSVpvn_flags(p, len, SvUTF8(sv));
b3ac6de7
IZ
1663 SvREFCNT_dec(sv);
1664 sv = nsv;
4e553d73 1665 }
6154021b 1666 pl_yylval.opval = (OP*)newSVOP(op_type, 0, sv);
a0714e2c 1667 PL_lex_stuff = NULL;
6f33ba73
RGS
1668 /* Allow <FH> // "foo" */
1669 if (op_type == OP_READLINE)
1670 PL_expect = XTERMORDORDOR;
79072805
LW
1671 return THING;
1672 }
e3f73d4e
RGS
1673 else if (op_type == OP_BACKTICK && PL_lex_op) {
1674 /* readpipe() vas overriden */
1675 cSVOPx(cLISTOPx(cUNOPx(PL_lex_op)->op_first)->op_first->op_sibling)->op_sv = tokeq(PL_lex_stuff);
6154021b 1676 pl_yylval.opval = PL_lex_op;
9b201d7d 1677 PL_lex_op = NULL;
e3f73d4e
RGS
1678 PL_lex_stuff = NULL;
1679 return THING;
1680 }
79072805 1681
3280af22 1682 PL_sublex_info.super_state = PL_lex_state;
eac04b2e 1683 PL_sublex_info.sub_inwhat = (U16)op_type;
3280af22
NIS
1684 PL_sublex_info.sub_op = PL_lex_op;
1685 PL_lex_state = LEX_INTERPPUSH;
55497cff 1686
3280af22
NIS
1687 PL_expect = XTERM;
1688 if (PL_lex_op) {
6154021b 1689 pl_yylval.opval = PL_lex_op;
5f66b61c 1690 PL_lex_op = NULL;
55497cff 1691 return PMFUNC;
1692 }
1693 else
1694 return FUNC;
1695}
1696
ffb4593c
NT
1697/*
1698 * S_sublex_push
1699 * Create a new scope to save the lexing state. The scope will be
1700 * ended in S_sublex_done. Returns a '(', starting the function arguments
1701 * to the uc, lc, etc. found before.
1702 * Sets PL_lex_state to LEX_INTERPCONCAT.
1703 */
1704
76e3520e 1705STATIC I32
cea2e8a9 1706S_sublex_push(pTHX)
55497cff 1707{
27da23d5 1708 dVAR;
f46d017c 1709 ENTER;
55497cff 1710
3280af22 1711 PL_lex_state = PL_sublex_info.super_state;
651b5b28 1712 SAVEBOOL(PL_lex_dojoin);
3280af22 1713 SAVEI32(PL_lex_brackets);
3280af22
NIS
1714 SAVEI32(PL_lex_casemods);
1715 SAVEI32(PL_lex_starts);
651b5b28 1716 SAVEI8(PL_lex_state);
7766f137 1717 SAVEVPTR(PL_lex_inpat);
98246f1e 1718 SAVEI16(PL_lex_inwhat);
57843af0 1719 SAVECOPLINE(PL_curcop);
3280af22 1720 SAVEPPTR(PL_bufptr);
8452ff4b 1721 SAVEPPTR(PL_bufend);
3280af22
NIS
1722 SAVEPPTR(PL_oldbufptr);
1723 SAVEPPTR(PL_oldoldbufptr);
207e3d1a
JH
1724 SAVEPPTR(PL_last_lop);
1725 SAVEPPTR(PL_last_uni);
3280af22
NIS
1726 SAVEPPTR(PL_linestart);
1727 SAVESPTR(PL_linestr);
8edd5f42
RGS
1728 SAVEGENERICPV(PL_lex_brackstack);
1729 SAVEGENERICPV(PL_lex_casestack);
3280af22
NIS
1730
1731 PL_linestr = PL_lex_stuff;
a0714e2c 1732 PL_lex_stuff = NULL;
3280af22 1733
9cbb5ea2
GS
1734 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart
1735 = SvPVX(PL_linestr);
3280af22 1736 PL_bufend += SvCUR(PL_linestr);
bd61b366 1737 PL_last_lop = PL_last_uni = NULL;
3280af22
NIS
1738 SAVEFREESV(PL_linestr);
1739
1740 PL_lex_dojoin = FALSE;
1741 PL_lex_brackets = 0;
a02a5408
JC
1742 Newx(PL_lex_brackstack, 120, char);
1743 Newx(PL_lex_casestack, 12, char);
3280af22
NIS
1744 PL_lex_casemods = 0;
1745 *PL_lex_casestack = '\0';
1746 PL_lex_starts = 0;
1747 PL_lex_state = LEX_INTERPCONCAT;
eb160463 1748 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22
NIS
1749
1750 PL_lex_inwhat = PL_sublex_info.sub_inwhat;
1751 if (PL_lex_inwhat == OP_MATCH || PL_lex_inwhat == OP_QR || PL_lex_inwhat == OP_SUBST)
1752 PL_lex_inpat = PL_sublex_info.sub_op;
79072805 1753 else
5f66b61c 1754 PL_lex_inpat = NULL;
79072805 1755
55497cff 1756 return '(';
79072805
LW
1757}
1758
ffb4593c
NT
1759/*
1760 * S_sublex_done
1761 * Restores lexer state after a S_sublex_push.
1762 */
1763
76e3520e 1764STATIC I32
cea2e8a9 1765S_sublex_done(pTHX)
79072805 1766{
27da23d5 1767 dVAR;
3280af22 1768 if (!PL_lex_starts++) {
396482e1 1769 SV * const sv = newSVpvs("");
9aa983d2
JH
1770 if (SvUTF8(PL_linestr))
1771 SvUTF8_on(sv);
3280af22 1772 PL_expect = XOPERATOR;
6154021b 1773 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
79072805
LW
1774 return THING;
1775 }
1776
3280af22
NIS
1777 if (PL_lex_casemods) { /* oops, we've got some unbalanced parens */
1778 PL_lex_state = LEX_INTERPCASEMOD;
cea2e8a9 1779 return yylex();
79072805
LW
1780 }
1781
ffb4593c 1782 /* Is there a right-hand side to take care of? (s//RHS/ or tr//RHS/) */
3280af22
NIS
1783 if (PL_lex_repl && (PL_lex_inwhat == OP_SUBST || PL_lex_inwhat == OP_TRANS)) {
1784 PL_linestr = PL_lex_repl;
1785 PL_lex_inpat = 0;
1786 PL_bufend = PL_bufptr = PL_oldbufptr = PL_oldoldbufptr = PL_linestart = SvPVX(PL_linestr);
1787 PL_bufend += SvCUR(PL_linestr);
bd61b366 1788 PL_last_lop = PL_last_uni = NULL;
3280af22
NIS
1789 SAVEFREESV(PL_linestr);
1790 PL_lex_dojoin = FALSE;
1791 PL_lex_brackets = 0;
3280af22
NIS
1792 PL_lex_casemods = 0;
1793 *PL_lex_casestack = '\0';
1794 PL_lex_starts = 0;
25da4f38 1795 if (SvEVALED(PL_lex_repl)) {
3280af22
NIS
1796 PL_lex_state = LEX_INTERPNORMAL;
1797 PL_lex_starts++;
e9fa98b2
HS
1798 /* we don't clear PL_lex_repl here, so that we can check later
1799 whether this is an evalled subst; that means we rely on the
1800 logic to ensure sublex_done() is called again only via the
1801 branch (in yylex()) that clears PL_lex_repl, else we'll loop */
79072805 1802 }
e9fa98b2 1803 else {
3280af22 1804 PL_lex_state = LEX_INTERPCONCAT;
a0714e2c 1805 PL_lex_repl = NULL;
e9fa98b2 1806 }
79072805 1807 return ',';
ffed7fef
LW
1808 }
1809 else {
5db06880
NC
1810#ifdef PERL_MAD
1811 if (PL_madskills) {
cd81e915
NC
1812 if (PL_thiswhite) {
1813 if (!PL_endwhite)
6b29d1f5 1814 PL_endwhite = newSVpvs("");
cd81e915
NC
1815 sv_catsv(PL_endwhite, PL_thiswhite);
1816 PL_thiswhite = 0;
1817 }
1818 if (PL_thistoken)
76f68e9b 1819 sv_setpvs(PL_thistoken,"");
5db06880 1820 else
cd81e915 1821 PL_realtokenstart = -1;
5db06880
NC
1822 }
1823#endif
f46d017c 1824 LEAVE;
3280af22
NIS
1825 PL_bufend = SvPVX(PL_linestr);
1826 PL_bufend += SvCUR(PL_linestr);
1827 PL_expect = XOPERATOR;
09bef843 1828 PL_sublex_info.sub_inwhat = 0;
79072805 1829 return ')';
ffed7fef
LW
1830 }
1831}
1832
02aa26ce
NT
1833/*
1834 scan_const
1835
1836 Extracts a pattern, double-quoted string, or transliteration. This
1837 is terrifying code.
1838
94def140 1839 It looks at PL_lex_inwhat and PL_lex_inpat to find out whether it's
3280af22 1840 processing a pattern (PL_lex_inpat is true), a transliteration
94def140 1841 (PL_lex_inwhat == OP_TRANS is true), or a double-quoted string.
02aa26ce 1842
94def140
TS
1843 Returns a pointer to the character scanned up to. If this is
1844 advanced from the start pointer supplied (i.e. if anything was
9b599b2a 1845 successfully parsed), will leave an OP for the substring scanned
6154021b 1846 in pl_yylval. Caller must intuit reason for not parsing further
9b599b2a
GS
1847 by looking at the next characters herself.
1848
02aa26ce
NT
1849 In patterns:
1850 backslashes:
1851 double-quoted style: \r and \n
1852 regexp special ones: \D \s
94def140
TS
1853 constants: \x31
1854 backrefs: \1
02aa26ce
NT
1855 case and quoting: \U \Q \E
1856 stops on @ and $, but not for $ as tail anchor
1857
1858 In transliterations:
1859 characters are VERY literal, except for - not at the start or end
94def140
TS
1860 of the string, which indicates a range. If the range is in bytes,
1861 scan_const expands the range to the full set of intermediate
1862 characters. If the range is in utf8, the hyphen is replaced with
1863 a certain range mark which will be handled by pmtrans() in op.c.
02aa26ce
NT
1864
1865 In double-quoted strings:
1866 backslashes:
1867 double-quoted style: \r and \n
94def140
TS
1868 constants: \x31
1869 deprecated backrefs: \1 (in substitution replacements)
02aa26ce
NT
1870 case and quoting: \U \Q \E
1871 stops on @ and $
1872
1873 scan_const does *not* construct ops to handle interpolated strings.
1874 It stops processing as soon as it finds an embedded $ or @ variable
1875 and leaves it to the caller to work out what's going on.
1876
94def140
TS
1877 embedded arrays (whether in pattern or not) could be:
1878 @foo, @::foo, @'foo, @{foo}, @$foo, @+, @-.
1879
1880 $ in double-quoted strings must be the symbol of an embedded scalar.
02aa26ce
NT
1881
1882 $ in pattern could be $foo or could be tail anchor. Assumption:
1883 it's a tail anchor if $ is the last thing in the string, or if it's
94def140 1884 followed by one of "()| \r\n\t"
02aa26ce
NT
1885
1886 \1 (backreferences) are turned into $1
1887
1888 The structure of the code is
1889 while (there's a character to process) {
94def140
TS
1890 handle transliteration ranges
1891 skip regexp comments /(?#comment)/ and codes /(?{code})/
1892 skip #-initiated comments in //x patterns
1893 check for embedded arrays
02aa26ce
NT
1894 check for embedded scalars
1895 if (backslash) {
94def140
TS
1896 leave intact backslashes from leaveit (below)
1897 deprecate \1 in substitution replacements
02aa26ce
NT
1898 handle string-changing backslashes \l \U \Q \E, etc.
1899 switch (what was escaped) {
94def140
TS
1900 handle \- in a transliteration (becomes a literal -)
1901 handle \132 (octal characters)
1902 handle \x15 and \x{1234} (hex characters)
1903 handle \N{name} (named characters)
1904 handle \cV (control characters)
1905 handle printf-style backslashes (\f, \r, \n, etc)
02aa26ce 1906 } (end switch)
77a135fe 1907 continue
02aa26ce 1908 } (end if backslash)
77a135fe 1909 handle regular character
02aa26ce 1910 } (end while character to read)
4e553d73 1911
02aa26ce
NT
1912*/
1913
76e3520e 1914STATIC char *
cea2e8a9 1915S_scan_const(pTHX_ char *start)
79072805 1916{
97aff369 1917 dVAR;
3280af22 1918 register char *send = PL_bufend; /* end of the constant */
77a135fe
KW
1919 SV *sv = newSV(send - start); /* sv for the constant. See
1920 note below on sizing. */
02aa26ce
NT
1921 register char *s = start; /* start of the constant */
1922 register char *d = SvPVX(sv); /* destination for copies */
1923 bool dorange = FALSE; /* are we in a translit range? */
c2e66d9e 1924 bool didrange = FALSE; /* did we just finish a range? */
2b9d42f0 1925 I32 has_utf8 = FALSE; /* Output constant is UTF8 */
77a135fe
KW
1926 I32 this_utf8 = UTF; /* Is the source string assumed
1927 to be UTF8? But, this can
1928 show as true when the source
1929 isn't utf8, as for example
1930 when it is entirely composed
1931 of hex constants */
1932
1933 /* Note on sizing: The scanned constant is placed into sv, which is
1934 * initialized by newSV() assuming one byte of output for every byte of
1935 * input. This routine expects newSV() to allocate an extra byte for a
1936 * trailing NUL, which this routine will append if it gets to the end of
1937 * the input. There may be more bytes of input than output (eg., \N{LATIN
1938 * CAPITAL LETTER A}), or more output than input if the constant ends up
1939 * recoded to utf8, but each time a construct is found that might increase
1940 * the needed size, SvGROW() is called. Its size parameter each time is
1941 * based on the best guess estimate at the time, namely the length used so
1942 * far, plus the length the current construct will occupy, plus room for
1943 * the trailing NUL, plus one byte for every input byte still unscanned */
1944
012bcf8d 1945 UV uv;
4c3a8340
TS
1946#ifdef EBCDIC
1947 UV literal_endpoint = 0;
e294cc5d 1948 bool native_range = TRUE; /* turned to FALSE if the first endpoint is Unicode. */
4c3a8340 1949#endif
012bcf8d 1950
7918f24d
NC
1951 PERL_ARGS_ASSERT_SCAN_CONST;
1952
2b9d42f0
NIS
1953 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
1954 /* If we are doing a trans and we know we want UTF8 set expectation */
1955 has_utf8 = PL_sublex_info.sub_op->op_private & (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF);
1956 this_utf8 = PL_sublex_info.sub_op->op_private & (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
1957 }
1958
1959
79072805 1960 while (s < send || dorange) {
02aa26ce 1961 /* get transliterations out of the way (they're most literal) */
3280af22 1962 if (PL_lex_inwhat == OP_TRANS) {
02aa26ce 1963 /* expand a range A-Z to the full set of characters. AIE! */
79072805 1964 if (dorange) {
1ba5c669
JH
1965 I32 i; /* current expanded character */
1966 I32 min; /* first character in range */
1967 I32 max; /* last character in range */
02aa26ce 1968
e294cc5d
JH
1969#ifdef EBCDIC
1970 UV uvmax = 0;
1971#endif
1972
1973 if (has_utf8
1974#ifdef EBCDIC
1975 && !native_range
1976#endif
1977 ) {
9d4ba2ae 1978 char * const c = (char*)utf8_hop((U8*)d, -1);
8973db79
JH
1979 char *e = d++;
1980 while (e-- > c)
1981 *(e + 1) = *e;
25716404 1982 *c = (char)UTF_TO_NATIVE(0xff);
8973db79
JH
1983 /* mark the range as done, and continue */
1984 dorange = FALSE;
1985 didrange = TRUE;
1986 continue;
1987 }
2b9d42f0 1988
95a20fc0 1989 i = d - SvPVX_const(sv); /* remember current offset */
e294cc5d
JH
1990#ifdef EBCDIC
1991 SvGROW(sv,
1992 SvLEN(sv) + (has_utf8 ?
1993 (512 - UTF_CONTINUATION_MARK +
1994 UNISKIP(0x100))
1995 : 256));
1996 /* How many two-byte within 0..255: 128 in UTF-8,
1997 * 96 in UTF-8-mod. */
1998#else
9cbb5ea2 1999 SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */
e294cc5d 2000#endif
9cbb5ea2 2001 d = SvPVX(sv) + i; /* refresh d after realloc */
e294cc5d
JH
2002#ifdef EBCDIC
2003 if (has_utf8) {
2004 int j;
2005 for (j = 0; j <= 1; j++) {
2006 char * const c = (char*)utf8_hop((U8*)d, -1);
2007 const UV uv = utf8n_to_uvchr((U8*)c, d - c, NULL, 0);
2008 if (j)
2009 min = (U8)uv;
2010 else if (uv < 256)
2011 max = (U8)uv;
2012 else {
2013 max = (U8)0xff; /* only to \xff */
2014 uvmax = uv; /* \x{100} to uvmax */
2015 }
2016 d = c; /* eat endpoint chars */
2017 }
2018 }
2019 else {
2020#endif
2021 d -= 2; /* eat the first char and the - */
2022 min = (U8)*d; /* first char in range */
2023 max = (U8)d[1]; /* last char in range */
2024#ifdef EBCDIC
2025 }
2026#endif
8ada0baa 2027
c2e66d9e 2028 if (min > max) {
01ec43d0 2029 Perl_croak(aTHX_
d1573ac7 2030 "Invalid range \"%c-%c\" in transliteration operator",
1ba5c669 2031 (char)min, (char)max);
c2e66d9e
GS
2032 }
2033
c7f1f016 2034#ifdef EBCDIC
4c3a8340
TS
2035 if (literal_endpoint == 2 &&
2036 ((isLOWER(min) && isLOWER(max)) ||
2037 (isUPPER(min) && isUPPER(max)))) {
8ada0baa
JH
2038 if (isLOWER(min)) {
2039 for (i = min; i <= max; i++)
2040 if (isLOWER(i))
db42d148 2041 *d++ = NATIVE_TO_NEED(has_utf8,i);
8ada0baa
JH
2042 } else {
2043 for (i = min; i <= max; i++)
2044 if (isUPPER(i))
db42d148 2045 *d++ = NATIVE_TO_NEED(has_utf8,i);
8ada0baa
JH
2046 }
2047 }
2048 else
2049#endif
2050 for (i = min; i <= max; i++)
e294cc5d
JH
2051#ifdef EBCDIC
2052 if (has_utf8) {
2053 const U8 ch = (U8)NATIVE_TO_UTF(i);
2054 if (UNI_IS_INVARIANT(ch))
2055 *d++ = (U8)i;
2056 else {
2057 *d++ = (U8)UTF8_EIGHT_BIT_HI(ch);
2058 *d++ = (U8)UTF8_EIGHT_BIT_LO(ch);
2059 }
2060 }
2061 else
2062#endif
2063 *d++ = (char)i;
2064
2065#ifdef EBCDIC
2066 if (uvmax) {
2067 d = (char*)uvchr_to_utf8((U8*)d, 0x100);
2068 if (uvmax > 0x101)
2069 *d++ = (char)UTF_TO_NATIVE(0xff);
2070 if (uvmax > 0x100)
2071 d = (char*)uvchr_to_utf8((U8*)d, uvmax);
2072 }
2073#endif
02aa26ce
NT
2074
2075 /* mark the range as done, and continue */
79072805 2076 dorange = FALSE;
01ec43d0 2077 didrange = TRUE;
4c3a8340
TS
2078#ifdef EBCDIC
2079 literal_endpoint = 0;
2080#endif
79072805 2081 continue;
4e553d73 2082 }
02aa26ce
NT
2083
2084 /* range begins (ignore - as first or last char) */
79072805 2085 else if (*s == '-' && s+1 < send && s != start) {
4e553d73 2086 if (didrange) {
1fafa243 2087 Perl_croak(aTHX_ "Ambiguous range in transliteration operator");
01ec43d0 2088 }
e294cc5d
JH
2089 if (has_utf8
2090#ifdef EBCDIC
2091 && !native_range
2092#endif
2093 ) {
25716404 2094 *d++ = (char)UTF_TO_NATIVE(0xff); /* use illegal utf8 byte--see pmtrans */
a0ed51b3
LW
2095 s++;
2096 continue;
2097 }
79072805
LW
2098 dorange = TRUE;
2099 s++;
01ec43d0
GS
2100 }
2101 else {
2102 didrange = FALSE;
4c3a8340
TS
2103#ifdef EBCDIC
2104 literal_endpoint = 0;
e294cc5d 2105 native_range = TRUE;
4c3a8340 2106#endif
01ec43d0 2107 }
79072805 2108 }
02aa26ce
NT
2109
2110 /* if we get here, we're not doing a transliteration */
2111
0f5d15d6
IZ
2112 /* skip for regexp comments /(?#comment)/ and code /(?{code})/,
2113 except for the last char, which will be done separately. */
3280af22 2114 else if (*s == '(' && PL_lex_inpat && s[1] == '?') {
cc6b7395 2115 if (s[2] == '#') {
e994fd66 2116 while (s+1 < send && *s != ')')
db42d148 2117 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
155aba94
GS
2118 }
2119 else if (s[2] == '{' /* This should match regcomp.c */
67edc0c9 2120 || (s[2] == '?' && s[3] == '{'))
155aba94 2121 {
cc6b7395 2122 I32 count = 1;
0f5d15d6 2123 char *regparse = s + (s[2] == '{' ? 3 : 4);
cc6b7395
IZ
2124 char c;
2125
d9f97599
GS
2126 while (count && (c = *regparse)) {
2127 if (c == '\\' && regparse[1])
2128 regparse++;
4e553d73 2129 else if (c == '{')
cc6b7395 2130 count++;
4e553d73 2131 else if (c == '}')
cc6b7395 2132 count--;
d9f97599 2133 regparse++;
cc6b7395 2134 }
e994fd66 2135 if (*regparse != ')')
5bdf89e7 2136 regparse--; /* Leave one char for continuation. */
0f5d15d6 2137 while (s < regparse)
db42d148 2138 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
cc6b7395 2139 }
748a9306 2140 }
02aa26ce
NT
2141
2142 /* likewise skip #-initiated comments in //x patterns */
3280af22
NIS
2143 else if (*s == '#' && PL_lex_inpat &&
2144 ((PMOP*)PL_lex_inpat)->op_pmflags & PMf_EXTENDED) {
748a9306 2145 while (s+1 < send && *s != '\n')
db42d148 2146 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
748a9306 2147 }
02aa26ce 2148
5d1d4326 2149 /* check for embedded arrays
da6eedaa 2150 (@foo, @::foo, @'foo, @{foo}, @$foo, @+, @-)
5d1d4326 2151 */
1749ea0d
TS
2152 else if (*s == '@' && s[1]) {
2153 if (isALNUM_lazy_if(s+1,UTF))
2154 break;
2155 if (strchr(":'{$", s[1]))
2156 break;
2157 if (!PL_lex_inpat && (s[1] == '+' || s[1] == '-'))
2158 break; /* in regexp, neither @+ nor @- are interpolated */
2159 }
02aa26ce
NT
2160
2161 /* check for embedded scalars. only stop if we're sure it's a
2162 variable.
2163 */
79072805 2164 else if (*s == '$') {
3280af22 2165 if (!PL_lex_inpat) /* not a regexp, so $ must be var */
79072805 2166 break;
77772344 2167 if (s + 1 < send && !strchr("()| \r\n\t", s[1])) {
a2a5de95
NC
2168 if (s[1] == '\\') {
2169 Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
2170 "Possible unintended interpolation of $\\ in regex");
77772344 2171 }
79072805 2172 break; /* in regexp, $ might be tail anchor */
77772344 2173 }
79072805 2174 }
02aa26ce 2175
2b9d42f0
NIS
2176 /* End of else if chain - OP_TRANS rejoin rest */
2177
02aa26ce 2178 /* backslashes */
79072805
LW
2179 if (*s == '\\' && s+1 < send) {
2180 s++;
02aa26ce 2181
02aa26ce 2182 /* deprecate \1 in strings and substitution replacements */
3280af22 2183 if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat &&
a0d0e21e 2184 isDIGIT(*s) && *s != '0' && !isDIGIT(s[1]))
79072805 2185 {
a2a5de95 2186 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s);
79072805
LW
2187 *--s = '$';
2188 break;
2189 }
02aa26ce
NT
2190
2191 /* string-change backslash escapes */
3280af22 2192 if (PL_lex_inwhat != OP_TRANS && *s && strchr("lLuUEQ", *s)) {
79072805
LW
2193 --s;
2194 break;
2195 }
cc74c5bd
TS
2196 /* skip any other backslash escapes in a pattern */
2197 else if (PL_lex_inpat) {
2198 *d++ = NATIVE_TO_NEED(has_utf8,'\\');
2199 goto default_action;
2200 }
02aa26ce
NT
2201
2202 /* if we get here, it's either a quoted -, or a digit */
79072805 2203 switch (*s) {
02aa26ce
NT
2204
2205 /* quoted - in transliterations */
79072805 2206 case '-':
3280af22 2207 if (PL_lex_inwhat == OP_TRANS) {
79072805
LW
2208 *d++ = *s++;
2209 continue;
2210 }
2211 /* FALL THROUGH */
2212 default:
11b8faa4 2213 {
a2a5de95
NC
2214 if ((isALPHA(*s) || isDIGIT(*s)))
2215 Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
2216 "Unrecognized escape \\%c passed through",
2217 *s);
11b8faa4 2218 /* default action is to copy the quoted character */
f9a63242 2219 goto default_action;
11b8faa4 2220 }
02aa26ce 2221
77a135fe 2222 /* eg. \132 indicates the octal constant 0x132 */
79072805
LW
2223 case '0': case '1': case '2': case '3':
2224 case '4': case '5': case '6': case '7':
ba210ebe 2225 {
53305cf1
NC
2226 I32 flags = 0;
2227 STRLEN len = 3;
77a135fe 2228 uv = NATIVE_TO_UNI(grok_oct(s, &len, &flags, NULL));
ba210ebe
JH
2229 s += len;
2230 }
012bcf8d 2231 goto NUM_ESCAPE_INSERT;
02aa26ce 2232
77a135fe 2233 /* eg. \x24 indicates the hex constant 0x24 */
79072805 2234 case 'x':
a0ed51b3
LW
2235 ++s;
2236 if (*s == '{') {
9d4ba2ae 2237 char* const e = strchr(s, '}');
a4c04bdc
NC
2238 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2239 PERL_SCAN_DISALLOW_PREFIX;
53305cf1 2240 STRLEN len;
355860ce 2241
53305cf1 2242 ++s;
adaeee49 2243 if (!e) {
a0ed51b3 2244 yyerror("Missing right brace on \\x{}");
355860ce 2245 continue;
ba210ebe 2246 }
53305cf1 2247 len = e - s;
77a135fe 2248 uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
ba210ebe 2249 s = e + 1;
a0ed51b3
LW
2250 }
2251 else {
ba210ebe 2252 {
53305cf1 2253 STRLEN len = 2;
a4c04bdc 2254 I32 flags = PERL_SCAN_DISALLOW_PREFIX;
77a135fe 2255 uv = NATIVE_TO_UNI(grok_hex(s, &len, &flags, NULL));
ba210ebe
JH
2256 s += len;
2257 }
012bcf8d
GS
2258 }
2259
2260 NUM_ESCAPE_INSERT:
77a135fe
KW
2261 /* Insert oct, hex, or \N{U+...} escaped character. There will
2262 * always be enough room in sv since such escapes will be
2263 * longer than any UTF-8 sequence they can end up as, except if
2264 * they force us to recode the rest of the string into utf8 */
ba7cea30 2265
77a135fe
KW
2266 /* Here uv is the ordinal of the next character being added in
2267 * unicode (converted from native). (It has to be done before
2268 * here because \N is interpreted as unicode, and oct and hex
2269 * as native.) */
2270 if (!UNI_IS_INVARIANT(uv)) {
9aa983d2 2271 if (!has_utf8 && uv > 255) {
77a135fe
KW
2272 /* Might need to recode whatever we have accumulated so
2273 * far if it contains any chars variant in utf8 or
2274 * utf-ebcdic. */
2275
2276 SvCUR_set(sv, d - SvPVX_const(sv));
2277 SvPOK_on(sv);
2278 *d = '\0';
77a135fe 2279 /* See Note on sizing above. */
7bf79863
KW
2280 sv_utf8_upgrade_flags_grow(sv,
2281 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2282 UNISKIP(uv) + (STRLEN)(send - s) + 1);
77a135fe
KW
2283 d = SvPVX(sv) + SvCUR(sv);
2284 has_utf8 = TRUE;
012bcf8d
GS
2285 }
2286
77a135fe
KW
2287 if (has_utf8) {
2288 d = (char*)uvuni_to_utf8((U8*)d, uv);
f9a63242
JH
2289 if (PL_lex_inwhat == OP_TRANS &&
2290 PL_sublex_info.sub_op) {
2291 PL_sublex_info.sub_op->op_private |=
2292 (PL_lex_repl ? OPpTRANS_FROM_UTF
2293 : OPpTRANS_TO_UTF);
f9a63242 2294 }
e294cc5d
JH
2295#ifdef EBCDIC
2296 if (uv > 255 && !dorange)
2297 native_range = FALSE;
2298#endif
012bcf8d 2299 }
a0ed51b3 2300 else {
012bcf8d 2301 *d++ = (char)uv;
a0ed51b3 2302 }
012bcf8d
GS
2303 }
2304 else {
c4d5f83a 2305 *d++ = (char) uv;
a0ed51b3 2306 }
79072805 2307 continue;
02aa26ce 2308
77a135fe
KW
2309 /* \N{LATIN SMALL LETTER A} is a named character, and so is
2310 * \N{U+0041} */
4a2d328f 2311 case 'N':
55eda711 2312 ++s;
423cee85
JH
2313 if (*s == '{') {
2314 char* e = strchr(s, '}');
155aba94 2315 SV *res;
423cee85 2316 STRLEN len;
cfd0369c 2317 const char *str;
4e553d73 2318
423cee85 2319 if (!e) {
5777a3f7 2320 yyerror("Missing right brace on \\N{}");
423cee85
JH
2321 e = s - 1;
2322 goto cont_scan;
2323 }
dbc0d4f2 2324 if (e > s + 2 && s[1] == 'U' && s[2] == '+') {
77a135fe
KW
2325 /* \N{U+...} The ... is a unicode value even on EBCDIC
2326 * machines */
dbc0d4f2
JH
2327 I32 flags = PERL_SCAN_ALLOW_UNDERSCORES |
2328 PERL_SCAN_DISALLOW_PREFIX;
2329 s += 3;
2330 len = e - s;
2331 uv = grok_hex(s, &len, &flags, NULL);
b57a0404
JH
2332 if ( e > s && len != (STRLEN)(e - s) ) {
2333 uv = 0xFFFD;
fc8cd66c 2334 }
dbc0d4f2
JH
2335 s = e + 1;
2336 goto NUM_ESCAPE_INSERT;
2337 }
55eda711 2338 res = newSVpvn(s + 1, e - s - 1);
bd61b366 2339 res = new_constant( NULL, 0, "charnames",
eb0d8d16 2340 res, NULL, s - 2, e - s + 3 );
f9a63242
JH
2341 if (has_utf8)
2342 sv_utf8_upgrade(res);
cfd0369c 2343 str = SvPV_const(res,len);
1c47067b
JH
2344#ifdef EBCDIC_NEVER_MIND
2345 /* charnames uses pack U and that has been
2346 * recently changed to do the below uni->native
2347 * mapping, so this would be redundant (and wrong,
2348 * the code point would be doubly converted).
2349 * But leave this in just in case the pack U change
2350 * gets revoked, but the semantics is still
2351 * desireable for charnames. --jhi */
cddc7ef4 2352 {
cfd0369c 2353 UV uv = utf8_to_uvchr((const U8*)str, 0);
cddc7ef4
JH
2354
2355 if (uv < 0x100) {
89ebb4a3 2356 U8 tmpbuf[UTF8_MAXBYTES+1], *d;
cddc7ef4
JH
2357
2358 d = uvchr_to_utf8(tmpbuf, UNI_TO_NATIVE(uv));
2359 sv_setpvn(res, (char *)tmpbuf, d - tmpbuf);
cfd0369c 2360 str = SvPV_const(res, len);
cddc7ef4
JH
2361 }
2362 }
2363#endif
77a135fe
KW
2364 /* If destination is not in utf8 but this new character is,
2365 * recode the dest to utf8 */
89491803 2366 if (!has_utf8 && SvUTF8(res)) {
77a135fe 2367 SvCUR_set(sv, d - SvPVX_const(sv));
f08d6ad9 2368 SvPOK_on(sv);
e4f3eed8 2369 *d = '\0';
77a135fe 2370 /* See Note on sizing above. */
7bf79863
KW
2371 sv_utf8_upgrade_flags_grow(sv,
2372 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2373 len + (STRLEN)(send - s) + 1);
f08d6ad9 2374 d = SvPVX(sv) + SvCUR(sv);
89491803 2375 has_utf8 = TRUE;
77a135fe 2376 } else if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */
423cee85 2377
77a135fe
KW
2378 /* See Note on sizing above. (NOTE: SvCUR() is not set
2379 * correctly here). */
2380 const STRLEN off = d - SvPVX_const(sv);
2381 d = SvGROW(sv, off + len + (STRLEN)(send - s) + 1) + off;
423cee85 2382 }
e294cc5d
JH
2383#ifdef EBCDIC
2384 if (!dorange)
2385 native_range = FALSE; /* \N{} is guessed to be Unicode */
2386#endif
423cee85
JH
2387 Copy(str, d, len, char);
2388 d += len;
2389 SvREFCNT_dec(res);
2390 cont_scan:
2391 s = e + 1;
2392 }
2393 else
5777a3f7 2394 yyerror("Missing braces on \\N{}");
423cee85
JH
2395 continue;
2396
02aa26ce 2397 /* \c is a control character */
79072805
LW
2398 case 'c':
2399 s++;
961ce445 2400 if (s < send) {
ba210ebe 2401 U8 c = *s++;
c7f1f016
NIS
2402#ifdef EBCDIC
2403 if (isLOWER(c))
2404 c = toUPPER(c);
2405#endif
db42d148 2406 *d++ = NATIVE_TO_NEED(has_utf8,toCTRL(c));
ba210ebe 2407 }
961ce445
RGS
2408 else {
2409 yyerror("Missing control char name in \\c");
2410 }
79072805 2411 continue;
02aa26ce
NT
2412
2413 /* printf-style backslashes, formfeeds, newlines, etc */
79072805 2414 case 'b':
db42d148 2415 *d++ = NATIVE_TO_NEED(has_utf8,'\b');
79072805
LW
2416 break;
2417 case 'n':
db42d148 2418 *d++ = NATIVE_TO_NEED(has_utf8,'\n');
79072805
LW
2419 break;
2420 case 'r':
db42d148 2421 *d++ = NATIVE_TO_NEED(has_utf8,'\r');
79072805
LW
2422 break;
2423 case 'f':
db42d148 2424 *d++ = NATIVE_TO_NEED(has_utf8,'\f');
79072805
LW
2425 break;
2426 case 't':
db42d148 2427 *d++ = NATIVE_TO_NEED(has_utf8,'\t');
79072805 2428 break;
34a3fe2a 2429 case 'e':
db42d148 2430 *d++ = ASCII_TO_NEED(has_utf8,'\033');
34a3fe2a
PP
2431 break;
2432 case 'a':
db42d148 2433 *d++ = ASCII_TO_NEED(has_utf8,'\007');
79072805 2434 break;
02aa26ce
NT
2435 } /* end switch */
2436
79072805
LW
2437 s++;
2438 continue;
02aa26ce 2439 } /* end if (backslash) */
4c3a8340
TS
2440#ifdef EBCDIC
2441 else
2442 literal_endpoint++;
2443#endif
02aa26ce 2444
f9a63242 2445 default_action:
77a135fe
KW
2446 /* If we started with encoded form, or already know we want it,
2447 then encode the next character */
2448 if (! NATIVE_IS_INVARIANT((U8)(*s)) && (this_utf8 || has_utf8)) {
2b9d42f0 2449 STRLEN len = 1;
77a135fe
KW
2450
2451
2452 /* One might think that it is wasted effort in the case of the
2453 * source being utf8 (this_utf8 == TRUE) to take the next character
2454 * in the source, convert it to an unsigned value, and then convert
2455 * it back again. But the source has not been validated here. The
2456 * routine that does the conversion checks for errors like
2457 * malformed utf8 */
2458
5f66b61c
AL
2459 const UV nextuv = (this_utf8) ? utf8n_to_uvchr((U8*)s, send - s, &len, 0) : (UV) ((U8) *s);
2460 const STRLEN need = UNISKIP(NATIVE_TO_UNI(nextuv));
77a135fe
KW
2461 if (!has_utf8) {
2462 SvCUR_set(sv, d - SvPVX_const(sv));
2463 SvPOK_on(sv);
2464 *d = '\0';
77a135fe 2465 /* See Note on sizing above. */
7bf79863
KW
2466 sv_utf8_upgrade_flags_grow(sv,
2467 SV_GMAGIC|SV_FORCE_UTF8_UPGRADE,
2468 need + (STRLEN)(send - s) + 1);
77a135fe
KW
2469 d = SvPVX(sv) + SvCUR(sv);
2470 has_utf8 = TRUE;
2471 } else if (need > len) {
2472 /* encoded value larger than old, may need extra space (NOTE:
2473 * SvCUR() is not set correctly here). See Note on sizing
2474 * above. */
9d4ba2ae 2475 const STRLEN off = d - SvPVX_const(sv);
77a135fe 2476 d = SvGROW(sv, off + need + (STRLEN)(send - s) + 1) + off;
2b9d42f0 2477 }
77a135fe
KW
2478 s += len;
2479
5f66b61c 2480 d = (char*)uvchr_to_utf8((U8*)d, nextuv);
e294cc5d
JH
2481#ifdef EBCDIC
2482 if (uv > 255 && !dorange)
2483 native_range = FALSE;
2484#endif
2b9d42f0
NIS
2485 }
2486 else {
2487 *d++ = NATIVE_TO_NEED(has_utf8,*s++);
2488 }
02aa26ce
NT
2489 } /* while loop to process each character */
2490
2491 /* terminate the string and set up the sv */
79072805 2492 *d = '\0';
95a20fc0 2493 SvCUR_set(sv, d - SvPVX_const(sv));
2b9d42f0 2494 if (SvCUR(sv) >= SvLEN(sv))
d0063567 2495 Perl_croak(aTHX_ "panic: constant overflowed allocated space");
2b9d42f0 2496
79072805 2497 SvPOK_on(sv);
9f4817db 2498 if (PL_encoding && !has_utf8) {
d0063567
DK
2499 sv_recode_to_utf8(sv, PL_encoding);
2500 if (SvUTF8(sv))
2501 has_utf8 = TRUE;
9f4817db 2502 }
2b9d42f0 2503 if (has_utf8) {
7e2040f0 2504 SvUTF8_on(sv);
2b9d42f0 2505 if (PL_lex_inwhat == OP_TRANS && PL_sublex_info.sub_op) {
d0063567 2506 PL_sublex_info.sub_op->op_private |=
2b9d42f0
NIS
2507 (PL_lex_repl ? OPpTRANS_FROM_UTF : OPpTRANS_TO_UTF);
2508 }
2509 }
79072805 2510
02aa26ce 2511 /* shrink the sv if we allocated more than we used */
79072805 2512 if (SvCUR(sv) + 5 < SvLEN(sv)) {
1da4ca5f 2513 SvPV_shrink_to_cur(sv);
79072805 2514 }
02aa26ce 2515
6154021b 2516 /* return the substring (via pl_yylval) only if we parsed anything */
3280af22 2517 if (s > PL_bufptr) {
eb0d8d16
NC
2518 if ( PL_hints & ( PL_lex_inpat ? HINT_NEW_RE : HINT_NEW_STRING ) ) {
2519 const char *const key = PL_lex_inpat ? "qr" : "q";
2520 const STRLEN keylen = PL_lex_inpat ? 2 : 1;
2521 const char *type;
2522 STRLEN typelen;
2523
2524 if (PL_lex_inwhat == OP_TRANS) {
2525 type = "tr";
2526 typelen = 2;
2527 } else if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat) {
2528 type = "s";
2529 typelen = 1;
2530 } else {
2531 type = "qq";
2532 typelen = 2;
2533 }
2534
2535 sv = S_new_constant(aTHX_ start, s - start, key, keylen, sv, NULL,
2536 type, typelen);
2537 }
6154021b 2538 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
b3ac6de7 2539 } else
8990e307 2540 SvREFCNT_dec(sv);
79072805
LW
2541 return s;
2542}
2543
ffb4593c
NT
2544/* S_intuit_more
2545 * Returns TRUE if there's more to the expression (e.g., a subscript),
2546 * FALSE otherwise.
ffb4593c
NT
2547 *
2548 * It deals with "$foo[3]" and /$foo[3]/ and /$foo[0123456789$]+/
2549 *
2550 * ->[ and ->{ return TRUE
2551 * { and [ outside a pattern are always subscripts, so return TRUE
2552 * if we're outside a pattern and it's not { or [, then return FALSE
2553 * if we're in a pattern and the first char is a {
2554 * {4,5} (any digits around the comma) returns FALSE
2555 * if we're in a pattern and the first char is a [
2556 * [] returns FALSE
2557 * [SOMETHING] has a funky algorithm to decide whether it's a
2558 * character class or not. It has to deal with things like
2559 * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/
2560 * anything else returns TRUE
2561 */
2562
9cbb5ea2
GS
2563/* This is the one truly awful dwimmer necessary to conflate C and sed. */
2564
76e3520e 2565STATIC int
cea2e8a9 2566S_intuit_more(pTHX_ register char *s)
79072805 2567{
97aff369 2568 dVAR;
7918f24d
NC
2569
2570 PERL_ARGS_ASSERT_INTUIT_MORE;
2571
3280af22 2572 if (PL_lex_brackets)
79072805
LW
2573 return TRUE;
2574 if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{'))
2575 return TRUE;
2576 if (*s != '{' && *s != '[')
2577 return FALSE;
3280af22 2578 if (!PL_lex_inpat)
79072805
LW
2579 return TRUE;
2580
2581 /* In a pattern, so maybe we have {n,m}. */
2582 if (*s == '{') {
2583 s++;
2584 if (!isDIGIT(*s))
2585 return TRUE;
2586 while (isDIGIT(*s))
2587 s++;
2588 if (*s == ',')
2589 s++;
2590 while (isDIGIT(*s))
2591 s++;
2592 if (*s == '}')
2593 return FALSE;
2594 return TRUE;
2595
2596 }
2597
2598 /* On the other hand, maybe we have a character class */
2599
2600 s++;
2601 if (*s == ']' || *s == '^')
2602 return FALSE;
2603 else {
ffb4593c 2604 /* this is terrifying, and it works */
79072805
LW
2605 int weight = 2; /* let's weigh the evidence */
2606 char seen[256];
f27ffc4a 2607 unsigned char un_char = 255, last_un_char;
9d4ba2ae 2608 const char * const send = strchr(s,']');
3280af22 2609 char tmpbuf[sizeof PL_tokenbuf * 4];
79072805
LW
2610
2611 if (!send) /* has to be an expression */
2612 return TRUE;
2613
2614 Zero(seen,256,char);
2615 if (*s == '$')
2616 weight -= 3;
2617 else if (isDIGIT(*s)) {
2618 if (s[1] != ']') {
2619 if (isDIGIT(s[1]) && s[2] == ']')
2620 weight -= 10;
2621 }
2622 else
2623 weight -= 100;
2624 }
2625 for (; s < send; s++) {
2626 last_un_char = un_char;
2627 un_char = (unsigned char)*s;
2628 switch (*s) {
2629 case '@':
2630 case '&':
2631 case '$':
2632 weight -= seen[un_char] * 10;
7e2040f0 2633 if (isALNUM_lazy_if(s+1,UTF)) {
90e5519e 2634 int len;
8903cb82 2635 scan_ident(s, send, tmpbuf, sizeof tmpbuf, FALSE);
90e5519e
NC
2636 len = (int)strlen(tmpbuf);
2637 if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PV))
79072805
LW
2638 weight -= 100;
2639 else
2640 weight -= 10;
2641 }
2642 else if (*s == '$' && s[1] &&
93a17b20
LW
2643 strchr("[#!%*<>()-=",s[1])) {
2644 if (/*{*/ strchr("])} =",s[2]))
79072805
LW
2645 weight -= 10;
2646 else
2647 weight -= 1;
2648 }
2649 break;
2650 case '\\':
2651 un_char = 254;
2652 if (s[1]) {
93a17b20 2653 if (strchr("wds]",s[1]))
79072805 2654 weight += 100;
10edeb5d 2655 else if (seen[(U8)'\''] || seen[(U8)'"'])
79072805 2656 weight += 1;
93a17b20 2657 else if (strchr("rnftbxcav",s[1]))
79072805
LW
2658 weight += 40;
2659 else if (isDIGIT(s[1])) {
2660 weight += 40;
2661 while (s[1] && isDIGIT(s[1]))
2662 s++;
2663 }
2664 }
2665 else
2666 weight += 100;
2667 break;
2668 case '-':
2669 if (s[1] == '\\')
2670 weight += 50;
93a17b20 2671 if (strchr("aA01! ",last_un_char))
79072805 2672 weight += 30;
93a17b20 2673 if (strchr("zZ79~",s[1]))
79072805 2674 weight += 30;
f27ffc4a
GS
2675 if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$'))
2676 weight -= 5; /* cope with negative subscript */
79072805
LW
2677 break;
2678 default:
3792a11b
NC
2679 if (!isALNUM(last_un_char)
2680 && !(last_un_char == '$' || last_un_char == '@'
2681 || last_un_char == '&')
2682 && isALPHA(*s) && s[1] && isALPHA(s[1])) {
79072805
LW
2683 char *d = tmpbuf;
2684 while (isALPHA(*s))
2685 *d++ = *s++;
2686 *d = '\0';
5458a98a 2687 if (keyword(tmpbuf, d - tmpbuf, 0))
79072805
LW
2688 weight -= 150;
2689 }
2690 if (un_char == last_un_char + 1)
2691 weight += 5;
2692 weight -= seen[un_char];
2693 break;
2694 }
2695 seen[un_char]++;
2696 }
2697 if (weight >= 0) /* probably a character class */
2698 return FALSE;
2699 }
2700
2701 return TRUE;
2702}
ffed7fef 2703
ffb4593c
NT
2704/*
2705 * S_intuit_method
2706 *
2707 * Does all the checking to disambiguate
2708 * foo bar
2709 * between foo(bar) and bar->foo. Returns 0 if not a method, otherwise
2710 * FUNCMETH (bar->foo(args)) or METHOD (bar->foo args).
2711 *
2712 * First argument is the stuff after the first token, e.g. "bar".
2713 *
2714 * Not a method if bar is a filehandle.
2715 * Not a method if foo is a subroutine prototyped to take a filehandle.
2716 * Not a method if it's really "Foo $bar"
2717 * Method if it's "foo $bar"
2718 * Not a method if it's really "print foo $bar"
2719 * Method if it's really "foo package::" (interpreted as package->foo)
8f8cf39c 2720 * Not a method if bar is known to be a subroutine ("sub bar; foo bar")
3cb0bbe5 2721 * Not a method if bar is a filehandle or package, but is quoted with
ffb4593c
NT
2722 * =>
2723 */
2724
76e3520e 2725STATIC int
62d55b22 2726S_intuit_method(pTHX_ char *start, GV *gv, CV *cv)
a0d0e21e 2727{
97aff369 2728 dVAR;
a0d0e21e 2729 char *s = start + (*start == '$');
3280af22 2730 char tmpbuf[sizeof PL_tokenbuf];
a0d0e21e
LW
2731 STRLEN len;
2732 GV* indirgv;
5db06880
NC
2733#ifdef PERL_MAD
2734 int soff;
2735#endif
a0d0e21e 2736
7918f24d
NC
2737 PERL_ARGS_ASSERT_INTUIT_METHOD;
2738
a0d0e21e 2739 if (gv) {
62d55b22 2740 if (SvTYPE(gv) == SVt_PVGV && GvIO(gv))
a0d0e21e 2741 return 0;
62d55b22
NC
2742 if (cv) {
2743 if (SvPOK(cv)) {
2744 const char *proto = SvPVX_const(cv);
2745 if (proto) {
2746 if (*proto == ';')
2747 proto++;
2748 if (*proto == '*')
2749 return 0;
2750 }
b6c543e3
IZ
2751 }
2752 } else
c35e046a 2753 gv = NULL;
a0d0e21e 2754 }
8903cb82 2755 s = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
ffb4593c
NT
2756 /* start is the beginning of the possible filehandle/object,
2757 * and s is the end of it
2758 * tmpbuf is a copy of it
2759 */
2760
a0d0e21e 2761 if (*start == '$') {
3ef1310e
RGS
2762 if (gv || PL_last_lop_op == OP_PRINT || PL_last_lop_op == OP_SAY ||
2763 isUPPER(*PL_tokenbuf))
a0d0e21e 2764 return 0;
5db06880
NC
2765#ifdef PERL_MAD
2766 len = start - SvPVX(PL_linestr);
2767#endif
29595ff2 2768 s = PEEKSPACE(s);
f0092767 2769#ifdef PERL_MAD
5db06880
NC
2770 start = SvPVX(PL_linestr) + len;
2771#endif
3280af22
NIS
2772 PL_bufptr = start;
2773 PL_expect = XREF;
a0d0e21e
LW
2774 return *s == '(' ? FUNCMETH : METHOD;
2775 }
5458a98a 2776 if (!keyword(tmpbuf, len, 0)) {
c3e0f903
GS
2777 if (len > 2 && tmpbuf[len - 2] == ':' && tmpbuf[len - 1] == ':') {
2778 len -= 2;
2779 tmpbuf[len] = '\0';
5db06880
NC
2780#ifdef PERL_MAD
2781 soff = s - SvPVX(PL_linestr);
2782#endif
c3e0f903
GS
2783 goto bare_package;
2784 }
90e5519e 2785 indirgv = gv_fetchpvn_flags(tmpbuf, len, 0, SVt_PVCV);
8ebc5c01 2786 if (indirgv && GvCVu(indirgv))
a0d0e21e
LW
2787 return 0;
2788 /* filehandle or package name makes it a method */
da51bb9b 2789 if (!gv || GvIO(indirgv) || gv_stashpvn(tmpbuf, len, 0)) {
5db06880
NC
2790#ifdef PERL_MAD
2791 soff = s - SvPVX(PL_linestr);
2792#endif
29595ff2 2793 s = PEEKSPACE(s);
3280af22 2794 if ((PL_bufend - s) >= 2 && *s == '=' && *(s+1) == '>')
55497cff 2795 return 0; /* no assumptions -- "=>" quotes bearword */
c3e0f903 2796 bare_package:
cd81e915 2797 start_force(PL_curforce);
9ded7720 2798 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0,
64142370 2799 S_newSV_maybe_utf8(aTHX_ tmpbuf, len));
9ded7720 2800 NEXTVAL_NEXTTOKE.opval->op_private = OPpCONST_BARE;
5db06880
NC
2801 if (PL_madskills)
2802 curmad('X', newSVpvn(start,SvPVX(PL_linestr) + soff - start));
3280af22 2803 PL_expect = XTERM;
a0d0e21e 2804 force_next(WORD);
3280af22 2805 PL_bufptr = s;
5db06880
NC
2806#ifdef PERL_MAD
2807 PL_bufptr = SvPVX(PL_linestr) + soff; /* restart before space */
2808#endif
a0d0e21e
LW
2809 return *s == '(' ? FUNCMETH : METHOD;
2810 }
2811 }
2812 return 0;
2813}
2814
16d20bd9 2815/* Encoded script support. filter_add() effectively inserts a
4e553d73 2816 * 'pre-processing' function into the current source input stream.
16d20bd9
AD
2817 * Note that the filter function only applies to the current source file
2818 * (e.g., it will not affect files 'require'd or 'use'd by this one).
2819 *
2820 * The datasv parameter (which may be NULL) can be used to pass
2821 * private data to this instance of the filter. The filter function
2822 * can recover the SV using the FILTER_DATA macro and use it to
2823 * store private buffers and state information.
2824 *
2825 * The supplied datasv parameter is upgraded to a PVIO type
4755096e 2826 * and the IoDIRP/IoANY field is used to store the function pointer,
e0c19803 2827 * and IOf_FAKE_DIRP is enabled on datasv to mark this as such.
16d20bd9
AD
2828 * Note that IoTOP_NAME, IoFMT_NAME, IoBOTTOM_NAME, if set for
2829 * private use must be set using malloc'd pointers.
2830 */
16d20bd9
AD
2831
2832SV *
864dbfa3 2833Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
16d20bd9 2834{
97aff369 2835 dVAR;
f4c556ac 2836 if (!funcp)
a0714e2c 2837 return NULL;
f4c556ac 2838
5486870f
DM
2839 if (!PL_parser)
2840 return NULL;
2841
3280af22
NIS
2842 if (!PL_rsfp_filters)
2843 PL_rsfp_filters = newAV();
16d20bd9 2844 if (!datasv)
561b68a9 2845 datasv = newSV(0);
862a34c6 2846 SvUPGRADE(datasv, SVt_PVIO);
8141890a 2847 IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
e0c19803 2848 IoFLAGS(datasv) |= IOf_FAKE_DIRP;
f4c556ac 2849 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_add func %p (%s)\n",
55662e27
JH
2850 FPTR2DPTR(void *, IoANY(datasv)),
2851 SvPV_nolen(datasv)));
3280af22
NIS
2852 av_unshift(PL_rsfp_filters, 1);
2853 av_store(PL_rsfp_filters, 0, datasv) ;
16d20bd9
AD
2854 return(datasv);
2855}
4e553d73 2856
16d20bd9
AD
2857
2858/* Delete most recently added instance of this filter function. */
a0d0e21e 2859void
864dbfa3 2860Perl_filter_del(pTHX_ filter_t funcp)
16d20bd9 2861{
97aff369 2862 dVAR;
e0c19803 2863 SV *datasv;
24801a4b 2864
7918f24d
NC
2865 PERL_ARGS_ASSERT_FILTER_DEL;
2866
33073adb 2867#ifdef DEBUGGING
55662e27
JH
2868 DEBUG_P(PerlIO_printf(Perl_debug_log, "filter_del func %p",
2869 FPTR2DPTR(void*, funcp)));
33073adb 2870#endif
5486870f 2871 if (!PL_parser || !PL_rsfp_filters || AvFILLp(PL_rsfp_filters)<0)
16d20bd9
AD
2872 return;
2873 /* if filter is on top of stack (usual case) just pop it off */
e0c19803 2874 datasv = FILTER_DATA(AvFILLp(PL_rsfp_filters));
8141890a 2875 if (IoANY(datasv) == FPTR2DPTR(void *, funcp)) {
e0c19803 2876 IoFLAGS(datasv) &= ~IOf_FAKE_DIRP;
4755096e 2877 IoANY(datasv) = (void *)NULL;
3280af22 2878 sv_free(av_pop(PL_rsfp_filters));
e50aee73 2879
16d20bd9
AD
2880 return;
2881 }
2882 /* we need to search for the correct entry and clear it */
cea2e8a9 2883 Perl_die(aTHX_ "filter_del can only delete in reverse order (currently)");
16d20bd9
AD
2884}
2885
2886
1de9afcd
RGS
2887/* Invoke the idxth filter function for the current rsfp. */
2888/* maxlen 0 = read one text line */
16d20bd9 2889I32
864dbfa3 2890Perl_filter_read(pTHX_ int idx, SV *buf_sv, int maxlen)
a0d0e21e 2891{
97aff369 2892 dVAR;
16d20bd9
AD
2893 filter_t funcp;
2894 SV *datasv = NULL;
f482118e
NC
2895 /* This API is bad. It should have been using unsigned int for maxlen.
2896 Not sure if we want to change the API, but if not we should sanity
2897 check the value here. */
39cd7a59
NC
2898 const unsigned int correct_length
2899 = maxlen < 0 ?
2900#ifdef PERL_MICRO
2901 0x7FFFFFFF
2902#else
2903 INT_MAX
2904#endif
2905 : maxlen;
e50aee73 2906
7918f24d
NC
2907 PERL_ARGS_ASSERT_FILTER_READ;
2908
5486870f 2909 if (!PL_parser || !PL_rsfp_filters)
16d20bd9 2910 return -1;
1de9afcd 2911 if (idx > AvFILLp(PL_rsfp_filters)) { /* Any more filters? */
16d20bd9
AD
2912 /* Provide a default input filter to make life easy. */
2913 /* Note that we append to the line. This is handy. */
f4c556ac
GS
2914 DEBUG_P(PerlIO_printf(Perl_debug_log,
2915 "filter_read %d: from rsfp\n", idx));
f482118e 2916 if (correct_length) {
16d20bd9
AD
2917 /* Want a block */
2918 int len ;
f54cb97a 2919 const int old_len = SvCUR(buf_sv);
16d20bd9
AD
2920
2921 /* ensure buf_sv is large enough */
881d8f0a 2922 SvGROW(buf_sv, (STRLEN)(old_len + correct_length + 1)) ;
f482118e
NC
2923 if ((len = PerlIO_read(PL_rsfp, SvPVX(buf_sv) + old_len,
2924 correct_length)) <= 0) {
3280af22 2925 if (PerlIO_error(PL_rsfp))
37120919
AD
2926 return -1; /* error */
2927 else
2928 return 0 ; /* end of file */
2929 }
16d20bd9 2930 SvCUR_set(buf_sv, old_len + len) ;
881d8f0a 2931 SvPVX(buf_sv)[old_len + len] = '\0';
16d20bd9
AD
2932 } else {
2933 /* Want a line */
3280af22
NIS
2934 if (sv_gets(buf_sv, PL_rsfp, SvCUR(buf_sv)) == NULL) {
2935 if (PerlIO_error(PL_rsfp))
37120919
AD
2936 return -1; /* error */
2937 else
2938 return 0 ; /* end of file */
2939 }
16d20bd9
AD
2940 }
2941 return SvCUR(buf_sv);
2942 }
2943 /* Skip this filter slot if filter has been deleted */
1de9afcd 2944 if ( (datasv = FILTER_DATA(idx)) == &PL_sv_undef) {
f4c556ac
GS
2945 DEBUG_P(PerlIO_printf(Perl_debug_log,
2946 "filter_read %d: skipped (filter deleted)\n",
2947 idx));
f482118e 2948 return FILTER_READ(idx+1, buf_sv, correct_length); /* recurse */
16d20bd9
AD
2949 }
2950 /* Get function pointer hidden within datasv */
8141890a 2951 funcp = DPTR2FPTR(filter_t, IoANY(datasv));
f4c556ac
GS
2952 DEBUG_P(PerlIO_printf(Perl_debug_log,
2953 "filter_read %d: via function %p (%s)\n",
ca0270c4 2954 idx, (void*)datasv, SvPV_nolen_const(datasv)));
16d20bd9
AD
2955 /* Call function. The function is expected to */
2956 /* call "FILTER_READ(idx+1, buf_sv)" first. */
37120919 2957 /* Return: <0:error, =0:eof, >0:not eof */
f482118e 2958 return (*funcp)(aTHX_ idx, buf_sv, correct_length);
16d20bd9
AD
2959}
2960
76e3520e 2961STATIC char *
5cc814fd 2962S_filter_gets(pTHX_ register SV *sv, STRLEN append)
16d20bd9 2963{
97aff369 2964 dVAR;
7918f24d
NC
2965
2966 PERL_ARGS_ASSERT_FILTER_GETS;
2967
c39cd008 2968#ifdef PERL_CR_FILTER
3280af22 2969 if (!PL_rsfp_filters) {
c39cd008 2970 filter_add(S_cr_textfilter,NULL);
a868473f
NIS
2971 }
2972#endif
3280af22 2973 if (PL_rsfp_filters) {
55497cff 2974 if (!append)
2975 SvCUR_set(sv, 0); /* start with empty line */
16d20bd9
AD
2976 if (FILTER_READ(0, sv, 0) > 0)
2977 return ( SvPVX(sv) ) ;
2978 else
bd61b366 2979 return NULL ;
16d20bd9 2980 }
9d116dd7 2981 else
5cc814fd 2982 return (sv_gets(sv, PL_rsfp, append));
a0d0e21e
LW
2983}
2984
01ec43d0 2985STATIC HV *
9bde8eb0 2986S_find_in_my_stash(pTHX_ const char *pkgname, STRLEN len)
def3634b 2987{
97aff369 2988 dVAR;
def3634b
GS
2989 GV *gv;
2990
7918f24d
NC
2991 PERL_ARGS_ASSERT_FIND_IN_MY_STASH;
2992
01ec43d0 2993 if (len == 11 && *pkgname == '_' && strEQ(pkgname, "__PACKAGE__"))
def3634b
GS
2994 return PL_curstash;
2995
2996 if (len > 2 &&
2997 (pkgname[len - 2] == ':' && pkgname[len - 1] == ':') &&
90e5519e 2998 (gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVHV)))
01ec43d0
GS
2999 {
3000 return GvHV(gv); /* Foo:: */
def3634b
GS
3001 }
3002
3003 /* use constant CLASS => 'MyClass' */
c35e046a
AL
3004 gv = gv_fetchpvn_flags(pkgname, len, 0, SVt_PVCV);
3005 if (gv && GvCV(gv)) {
3006 SV * const sv = cv_const_sv(GvCV(gv));
3007 if (sv)
9bde8eb0 3008 pkgname = SvPV_const(sv, len);
def3634b
GS
3009 }
3010
9bde8eb0 3011 return gv_stashpvn(pkgname, len, 0);
def3634b 3012}
a0d0e21e 3013
e3f73d4e
RGS
3014/*
3015 * S_readpipe_override
3016 * Check whether readpipe() is overriden, and generates the appropriate
3017 * optree, provided sublex_start() is called afterwards.
3018 */
3019STATIC void
1d51329b 3020S_readpipe_override(pTHX)
e3f73d4e
RGS
3021{
3022 GV **gvp;
3023 GV *gv_readpipe = gv_fetchpvs("readpipe", GV_NOTQUAL, SVt_PVCV);
6154021b 3024 pl_yylval.ival = OP_BACKTICK;
e3f73d4e
RGS
3025 if ((gv_readpipe
3026 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe))
3027 ||
3028 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readpipe", FALSE))
d5e716f5 3029 && (gv_readpipe = *gvp) && isGV_with_GP(gv_readpipe)
e3f73d4e
RGS
3030 && GvCVu(gv_readpipe) && GvIMPORTED_CV(gv_readpipe)))
3031 {
3032 PL_lex_op = (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
3033 append_elem(OP_LIST,
3034 newSVOP(OP_CONST, 0, &PL_sv_undef), /* value will be read later */
3035 newCVREF(0, newGVOP(OP_GV, 0, gv_readpipe))));
3036 }
e3f73d4e
RGS
3037}
3038
5db06880
NC
3039#ifdef PERL_MAD
3040 /*
3041 * Perl_madlex
3042 * The intent of this yylex wrapper is to minimize the changes to the
3043 * tokener when we aren't interested in collecting madprops. It remains
3044 * to be seen how successful this strategy will be...
3045 */
3046
3047int
3048Perl_madlex(pTHX)
3049{
3050 int optype;
3051 char *s = PL_bufptr;
3052
cd81e915
NC
3053 /* make sure PL_thiswhite is initialized */
3054 PL_thiswhite = 0;
3055 PL_thismad = 0;
5db06880 3056
cd81e915 3057 /* just do what yylex would do on pending identifier; leave PL_thiswhite alone */
5db06880
NC
3058 if (PL_pending_ident)
3059 return S_pending_ident(aTHX);
3060
3061 /* previous token ate up our whitespace? */
cd81e915
NC
3062 if (!PL_lasttoke && PL_nextwhite) {
3063 PL_thiswhite = PL_nextwhite;
3064 PL_nextwhite = 0;
5db06880
NC
3065 }
3066
3067 /* isolate the token, and figure out where it is without whitespace */
cd81e915
NC
3068 PL_realtokenstart = -1;
3069 PL_thistoken = 0;
5db06880
NC
3070 optype = yylex();
3071 s = PL_bufptr;
cd81e915 3072 assert(PL_curforce < 0);
5db06880 3073
cd81e915
NC
3074 if (!PL_thismad || PL_thismad->mad_key == '^') { /* not forced already? */
3075 if (!PL_thistoken) {
3076 if (PL_realtokenstart < 0 || !CopLINE(PL_curcop))
6b29d1f5 3077 PL_thistoken = newSVpvs("");
5db06880 3078 else {
c35e046a 3079 char * const tstart = SvPVX(PL_linestr) + PL_realtokenstart;
cd81e915 3080 PL_thistoken = newSVpvn(tstart, s - tstart);
5db06880
NC
3081 }
3082 }
cd81e915
NC
3083 if (PL_thismad) /* install head */
3084 CURMAD('X', PL_thistoken);
5db06880
NC
3085 }
3086
3087 /* last whitespace of a sublex? */
cd81e915
NC
3088 if (optype == ')' && PL_endwhite) {
3089 CURMAD('X', PL_endwhite);
5db06880
NC
3090 }
3091
cd81e915 3092 if (!PL_thismad) {
5db06880
NC
3093
3094 /* if no whitespace and we're at EOF, bail. Otherwise fake EOF below. */
cd81e915
NC
3095 if (!PL_thiswhite && !PL_endwhite && !optype) {
3096 sv_free(PL_thistoken);
3097 PL_thistoken = 0;
5db06880
NC
3098 return 0;
3099 }
3100
3101 /* put off final whitespace till peg */
3102 if (optype == ';' && !PL_rsfp) {
cd81e915
NC
3103 PL_nextwhite = PL_thiswhite;
3104 PL_thiswhite = 0;
5db06880 3105 }
cd81e915
NC
3106 else if (PL_thisopen) {
3107 CURMAD('q', PL_thisopen);
3108 if (PL_thistoken)
3109 sv_free(PL_thistoken);
3110 PL_thistoken = 0;
5db06880
NC
3111 }
3112 else {
3113 /* Store actual token text as madprop X */
cd81e915 3114 CURMAD('X', PL_thistoken);
5db06880
NC
3115 }
3116
cd81e915 3117 if (PL_thiswhite) {
5db06880 3118 /* add preceding whitespace as madprop _ */
cd81e915 3119 CURMAD('_', PL_thiswhite);
5db06880
NC
3120 }
3121
cd81e915 3122 if (PL_thisstuff) {
5db06880 3123 /* add quoted material as madprop = */
cd81e915 3124 CURMAD('=', PL_thisstuff);
5db06880
NC
3125 }
3126
cd81e915 3127 if (PL_thisclose) {
5db06880 3128 /* add terminating quote as madprop Q */
cd81e915 3129 CURMAD('Q', PL_thisclose);
5db06880
NC
3130 }
3131 }
3132
3133 /* special processing based on optype */
3134
3135 switch (optype) {
3136
3137 /* opval doesn't need a TOKEN since it can already store mp */
3138 case WORD:
3139 case METHOD:
3140 case FUNCMETH:
3141 case THING:
3142 case PMFUNC:
3143 case PRIVATEREF:
3144 case FUNC0SUB:
3145 case UNIOPSUB:
3146 case LSTOPSUB:
6154021b
RGS
3147 if (pl_yylval.opval)
3148 append_madprops(PL_thismad, pl_yylval.opval, 0);
cd81e915 3149 PL_thismad = 0;
5db06880
NC
3150 return optype;
3151
3152 /* fake EOF */
3153 case 0:
3154 optype = PEG;
cd81e915
NC
3155 if (PL_endwhite) {
3156 addmad(newMADsv('p', PL_endwhite), &PL_thismad, 0);
3157 PL_endwhite = 0;
5db06880
NC
3158 }
3159 break;
3160
3161 case ']':
3162 case '}':
cd81e915 3163 if (PL_faketokens)
5db06880
NC
3164 break;
3165 /* remember any fake bracket that lexer is about to discard */
3166 if (PL_lex_brackets == 1 &&
3167 ((expectation)PL_lex_brackstack[0] & XFAKEBRACK))
3168 {
3169 s = PL_bufptr;
3170 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3171 s++;
3172 if (*s == '}') {
cd81e915
NC
3173 PL_thiswhite = newSVpvn(PL_bufptr, ++s - PL_bufptr);
3174 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3175 PL_thiswhite = 0;
5db06880
NC
3176 PL_bufptr = s - 1;
3177 break; /* don't bother looking for trailing comment */
3178 }
3179 else
3180 s = PL_bufptr;
3181 }
3182 if (optype == ']')
3183 break;
3184 /* FALLTHROUGH */
3185
3186 /* attach a trailing comment to its statement instead of next token */
3187 case ';':
cd81e915 3188 if (PL_faketokens)
5db06880
NC
3189 break;
3190 if (PL_bufptr > PL_oldbufptr && PL_bufptr[-1] == optype) {
3191 s = PL_bufptr;
3192 while (s < PL_bufend && (*s == ' ' || *s == '\t'))
3193 s++;
3194 if (*s == '\n' || *s == '#') {
3195 while (s < PL_bufend && *s != '\n')
3196 s++;
3197 if (s < PL_bufend)
3198 s++;
cd81e915
NC
3199 PL_thiswhite = newSVpvn(PL_bufptr, s - PL_bufptr);
3200 addmad(newMADsv('#', PL_thiswhite), &PL_thismad, 0);
3201 PL_thiswhite = 0;
5db06880
NC
3202 PL_bufptr = s;
3203 }
3204 }
3205 break;
3206
3207 /* pval */
3208 case LABEL:
3209 break;
3210
3211 /* ival */
3212 default:
3213 break;
3214
3215 }
3216
3217 /* Create new token struct. Note: opvals return early above. */
6154021b 3218 pl_yylval.tkval = newTOKEN(optype, pl_yylval, PL_thismad);
cd81e915 3219 PL_thismad = 0;
5db06880
NC
3220 return optype;
3221}
3222#endif
3223
468aa647 3224STATIC char *
cc6ed77d 3225S_tokenize_use(pTHX_ int is_use, char *s) {
97aff369 3226 dVAR;
7918f24d
NC
3227
3228 PERL_ARGS_ASSERT_TOKENIZE_USE;
3229
468aa647
RGS
3230 if (PL_expect != XSTATE)
3231 yyerror(Perl_form(aTHX_ "\"%s\" not allowed in expression",
3232 is_use ? "use" : "no"));
29595ff2 3233 s = SKIPSPACE1(s);
468aa647
RGS
3234 if (isDIGIT(*s) || (*s == 'v' && isDIGIT(s[1]))) {
3235 s = force_version(s, TRUE);
29595ff2 3236 if (*s == ';' || (s = SKIPSPACE1(s), *s == ';')) {
cd81e915 3237 start_force(PL_curforce);
9ded7720 3238 NEXTVAL_NEXTTOKE.opval = NULL;
468aa647
RGS
3239 force_next(WORD);
3240 }
3241 else if (*s == 'v') {
3242 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3243 s = force_version(s, FALSE);
3244 }
3245 }
3246 else {
3247 s = force_word(s,WORD,FALSE,TRUE,FALSE);
3248 s = force_version(s, FALSE);
3249 }
6154021b 3250 pl_yylval.ival = is_use;
468aa647
RGS
3251 return s;
3252}
748a9306 3253#ifdef DEBUGGING
27da23d5 3254 static const char* const exp_name[] =
09bef843 3255 { "OPERATOR", "TERM", "REF", "STATE", "BLOCK", "ATTRBLOCK",
27308ded 3256 "ATTRTERM", "TERMBLOCK", "TERMORDORDOR"
09bef843 3257 };
748a9306 3258#endif
463ee0b2 3259
02aa26ce
NT
3260/*
3261 yylex
3262
3263 Works out what to call the token just pulled out of the input
3264 stream. The yacc parser takes care of taking the ops we return and
3265 stitching them into a tree.
3266
3267 Returns:
3268 PRIVATEREF
3269
3270 Structure:
3271 if read an identifier
3272 if we're in a my declaration
3273 croak if they tried to say my($foo::bar)
3274 build the ops for a my() declaration
3275 if it's an access to a my() variable
3276 are we in a sort block?
3277 croak if my($a); $a <=> $b
3278 build ops for access to a my() variable
3279 if in a dq string, and they've said @foo and we can't find @foo
3280 croak
3281 build ops for a bareword
3282 if we already built the token before, use it.
3283*/
3284
20141f0e 3285
dba4d153
JH
3286#ifdef __SC__
3287#pragma segment Perl_yylex
3288#endif
dba4d153 3289int
dba4d153 3290Perl_yylex(pTHX)
20141f0e 3291{
97aff369 3292 dVAR;
3afc138a 3293 register char *s = PL_bufptr;
378cc40b 3294 register char *d;
463ee0b2 3295 STRLEN len;
aa7440fb 3296 bool bof = FALSE;
a687059c 3297
10edeb5d
JH
3298 /* orig_keyword, gvp, and gv are initialized here because
3299 * jump to the label just_a_word_zero can bypass their
3300 * initialization later. */
3301 I32 orig_keyword = 0;
3302 GV *gv = NULL;
3303 GV **gvp = NULL;
3304
bbf60fe6 3305 DEBUG_T( {
396482e1 3306 SV* tmp = newSVpvs("");
b6007c36
DM
3307 PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
3308 (IV)CopLINE(PL_curcop),
3309 lex_state_names[PL_lex_state],
3310 exp_name[PL_expect],
3311 pv_display(tmp, s, strlen(s), 0, 60));
3312 SvREFCNT_dec(tmp);
bbf60fe6 3313 } );
02aa26ce 3314 /* check if there's an identifier for us to look at */
ba979b31 3315 if (PL_pending_ident)
bbf60fe6 3316 return REPORT(S_pending_ident(aTHX));
bbce6d69 3317
02aa26ce
NT
3318 /* no identifier pending identification */
3319
3280af22 3320 switch (PL_lex_state) {
79072805
LW
3321#ifdef COMMENTARY
3322 case LEX_NORMAL: /* Some compilers will produce faster */
3323 case LEX_INTERPNORMAL: /* code if we comment these out. */
3324 break;
3325#endif
3326
09bef843 3327 /* when we've already built the next token, just pull it out of the queue */
79072805 3328 case LEX_KNOWNEXT:
5db06880
NC
3329#ifdef PERL_MAD
3330 PL_lasttoke--;
6154021b 3331 pl_yylval = PL_nexttoke[PL_lasttoke].next_val;
5db06880 3332 if (PL_madskills) {
cd81e915 3333 PL_thismad = PL_nexttoke[PL_lasttoke].next_mad;
5db06880 3334 PL_nexttoke[PL_lasttoke].next_mad = 0;
cd81e915 3335 if (PL_thismad && PL_thismad->mad_key == '_') {
daba3364 3336 PL_thiswhite = MUTABLE_SV(PL_thismad->mad_val);
cd81e915
NC
3337 PL_thismad->mad_val = 0;
3338 mad_free(PL_thismad);
3339 PL_thismad = 0;
5db06880
NC
3340 }
3341 }
3342 if (!PL_lasttoke) {
3343 PL_lex_state = PL_lex_defer;
3344 PL_expect = PL_lex_expect;
3345 PL_lex_defer = LEX_NORMAL;
3346 if (!PL_nexttoke[PL_lasttoke].next_type)
3347 return yylex();
3348 }
3349#else
3280af22 3350 PL_nexttoke--;
6154021b 3351 pl_yylval = PL_nextval[PL_nexttoke];
3280af22
NIS
3352 if (!PL_nexttoke) {
3353 PL_lex_state = PL_lex_defer;
3354 PL_expect = PL_lex_expect;
3355 PL_lex_defer = LEX_NORMAL;
463ee0b2 3356 }
5db06880
NC
3357#endif
3358#ifdef PERL_MAD
3359 /* FIXME - can these be merged? */
3360 return(PL_nexttoke[PL_lasttoke].next_type);
3361#else
bbf60fe6 3362 return REPORT(PL_nexttype[PL_nexttoke]);
5db06880 3363#endif
79072805 3364
02aa26ce 3365 /* interpolated case modifiers like \L \U, including \Q and \E.
3280af22 3366 when we get here, PL_bufptr is at the \
02aa26ce 3367 */
79072805
LW
3368 case LEX_INTERPCASEMOD:
3369#ifdef DEBUGGING
3280af22 3370 if (PL_bufptr != PL_bufend && *PL_bufptr != '\\')
cea2e8a9 3371 Perl_croak(aTHX_ "panic: INTERPCASEMOD");
79072805 3372#endif
02aa26ce 3373 /* handle \E or end of string */
3280af22 3374 if (PL_bufptr == PL_bufend || PL_bufptr[1] == 'E') {
02aa26ce 3375 /* if at a \E */
3280af22 3376 if (PL_lex_casemods) {
f54cb97a 3377 const char oldmod = PL_lex_casestack[--PL_lex_casemods];
3280af22 3378 PL_lex_casestack[PL_lex_casemods] = '\0';
02aa26ce 3379
3792a11b
NC
3380 if (PL_bufptr != PL_bufend
3381 && (oldmod == 'L' || oldmod == 'U' || oldmod == 'Q')) {
3280af22
NIS
3382 PL_bufptr += 2;
3383 PL_lex_state = LEX_INTERPCONCAT;
5db06880
NC
3384#ifdef PERL_MAD
3385 if (PL_madskills)
6b29d1f5 3386 PL_thistoken = newSVpvs("\\E");
5db06880 3387#endif
a0d0e21e 3388 }
bbf60fe6 3389 return REPORT(')');
79072805 3390 }
5db06880
NC
3391#ifdef PERL_MAD
3392 while (PL_bufptr != PL_bufend &&
3393 PL_bufptr[0] == '\\' && PL_bufptr[1] == 'E') {
cd81e915 3394 if (!PL_thiswhite)
6b29d1f5 3395 PL_thiswhite = newSVpvs("");
cd81e915 3396 sv_catpvn(PL_thiswhite, PL_bufptr, 2);
5db06880
NC
3397 PL_bufptr += 2;
3398 }
3399#else
3280af22
NIS
3400 if (PL_bufptr != PL_bufend)
3401 PL_bufptr += 2;
5db06880 3402#endif
3280af22 3403 PL_lex_state = LEX_INTERPCONCAT;
cea2e8a9 3404 return yylex();
79072805
LW
3405 }
3406 else {
607df283 3407 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 3408 "### Saw case modifier\n"); });
3280af22 3409 s = PL_bufptr + 1;
6e909404 3410 if (s[1] == '\\' && s[2] == 'E') {
5db06880 3411#ifdef PERL_MAD
cd81e915 3412 if (!PL_thiswhite)
6b29d1f5 3413 PL_thiswhite = newSVpvs("");
cd81e915 3414 sv_catpvn(PL_thiswhite, PL_bufptr, 4);
5db06880 3415#endif
89122651 3416 PL_bufptr = s + 3;
6e909404
JH
3417 PL_lex_state = LEX_INTERPCONCAT;
3418 return yylex();
a0d0e21e 3419 }
6e909404 3420 else {
90771dc0 3421 I32 tmp;
5db06880
NC
3422 if (!PL_madskills) /* when just compiling don't need correct */
3423 if (strnEQ(s, "L\\u", 3) || strnEQ(s, "U\\l", 3))
3424 tmp = *s, *s = s[2], s[2] = (char)tmp; /* misordered... */
3792a11b 3425 if ((*s == 'L' || *s == 'U') &&
6e909404
JH
3426 (strchr(PL_lex_casestack, 'L') || strchr(PL_lex_casestack, 'U'))) {
3427 PL_lex_casestack[--PL_lex_casemods] = '\0';
bbf60fe6 3428 return REPORT(')');
6e909404
JH
3429 }
3430 if (PL_lex_casemods > 10)
3431 Renew(PL_lex_casestack, PL_lex_casemods + 2, char);
3432 PL_lex_casestack[PL_lex_casemods++] = *s;
3433 PL_lex_casestack[PL_lex_casemods] = '\0';
3434 PL_lex_state = LEX_INTERPCONCAT;
cd81e915 3435 start_force(PL_curforce);
9ded7720 3436 NEXTVAL_NEXTTOKE.ival = 0;
6e909404 3437 force_next('(');
cd81e915 3438 start_force(PL_curforce);
6e909404 3439 if (*s == 'l')
9ded7720 3440 NEXTVAL_NEXTTOKE.ival = OP_LCFIRST;
6e909404 3441 else if (*s == 'u')
9ded7720 3442 NEXTVAL_NEXTTOKE.ival = OP_UCFIRST;
6e909404 3443 else if (*s == 'L')
9ded7720 3444 NEXTVAL_NEXTTOKE.ival = OP_LC;
6e909404 3445 else if (*s == 'U')
9ded7720 3446 NEXTVAL_NEXTTOKE.ival = OP_UC;
6e909404 3447 else if (*s == 'Q')
9ded7720 3448 NEXTVAL_NEXTTOKE.ival = OP_QUOTEMETA;
6e909404
JH
3449 else
3450 Perl_croak(aTHX_ "panic: yylex");
5db06880 3451 if (PL_madskills) {
a5849ce5
NC
3452 SV* const tmpsv = newSVpvs("\\ ");
3453 /* replace the space with the character we want to escape
3454 */
3455 SvPVX(tmpsv)[1] = *s;
5db06880
NC
3456 curmad('_', tmpsv);
3457 }
6e909404 3458 PL_bufptr = s + 1;
a0d0e21e 3459 }
79072805 3460 force_next(FUNC);
3280af22
NIS
3461 if (PL_lex_starts) {
3462 s = PL_bufptr;
3463 PL_lex_starts = 0;
5db06880
NC
3464#ifdef PERL_MAD
3465 if (PL_madskills) {
cd81e915
NC
3466 if (PL_thistoken)
3467 sv_free(PL_thistoken);
6b29d1f5 3468 PL_thistoken = newSVpvs("");
5db06880
NC
3469 }
3470#endif
131b3ad0
DM
3471 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3472 if (PL_lex_casemods == 1 && PL_lex_inpat)
3473 OPERATOR(',');
3474 else
3475 Aop(OP_CONCAT);
79072805
LW
3476 }
3477 else
cea2e8a9 3478 return yylex();
79072805
LW
3479 }
3480
55497cff 3481 case LEX_INTERPPUSH:
bbf60fe6 3482 return REPORT(sublex_push());
55497cff 3483
79072805 3484 case LEX_INTERPSTART:
3280af22 3485 if (PL_bufptr == PL_bufend)
bbf60fe6 3486 return REPORT(sublex_done());
607df283 3487 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 3488 "### Interpolated variable\n"); });
3280af22
NIS
3489 PL_expect = XTERM;
3490 PL_lex_dojoin = (*PL_bufptr == '@');
3491 PL_lex_state = LEX_INTERPNORMAL;
3492 if (PL_lex_dojoin) {
cd81e915 3493 start_force(PL_curforce);
9ded7720 3494 NEXTVAL_NEXTTOKE.ival = 0;
79072805 3495 force_next(',');
cd81e915 3496 start_force(PL_curforce);
a0d0e21e 3497 force_ident("\"", '$');
cd81e915 3498 start_force(PL_curforce);
9ded7720 3499 NEXTVAL_NEXTTOKE.ival = 0;
79072805 3500 force_next('$');
cd81e915 3501 start_force(PL_curforce);
9ded7720 3502 NEXTVAL_NEXTTOKE.ival = 0;
79072805 3503 force_next('(');
cd81e915 3504 start_force(PL_curforce);
9ded7720 3505 NEXTVAL_NEXTTOKE.ival = OP_JOIN; /* emulate join($", ...) */
79072805
LW
3506 force_next(FUNC);
3507 }
3280af22
NIS
3508 if (PL_lex_starts++) {
3509 s = PL_bufptr;
5db06880
NC
3510#ifdef PERL_MAD
3511 if (PL_madskills) {
cd81e915
NC
3512 if (PL_thistoken)
3513 sv_free(PL_thistoken);
6b29d1f5 3514 PL_thistoken = newSVpvs("");
5db06880
NC
3515 }
3516#endif
131b3ad0
DM
3517 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3518 if (!PL_lex_casemods && PL_lex_inpat)
3519 OPERATOR(',');
3520 else
3521 Aop(OP_CONCAT);
79072805 3522 }
cea2e8a9 3523 return yylex();
79072805
LW
3524
3525 case LEX_INTERPENDMAYBE:
3280af22
NIS
3526 if (intuit_more(PL_bufptr)) {
3527 PL_lex_state = LEX_INTERPNORMAL; /* false alarm, more expr */
79072805
LW
3528 break;
3529 }
3530 /* FALL THROUGH */
3531
3532 case LEX_INTERPEND:
3280af22
NIS
3533 if (PL_lex_dojoin) {
3534 PL_lex_dojoin = FALSE;
3535 PL_lex_state = LEX_INTERPCONCAT;
5db06880
NC
3536#ifdef PERL_MAD
3537 if (PL_madskills) {
cd81e915
NC
3538 if (PL_thistoken)
3539 sv_free(PL_thistoken);
6b29d1f5 3540 PL_thistoken = newSVpvs("");
5db06880
NC
3541 }
3542#endif
bbf60fe6 3543 return REPORT(')');
79072805 3544 }
43a16006 3545 if (PL_lex_inwhat == OP_SUBST && PL_linestr == PL_lex_repl
25da4f38 3546 && SvEVALED(PL_lex_repl))
43a16006 3547 {
e9fa98b2 3548 if (PL_bufptr != PL_bufend)
cea2e8a9 3549 Perl_croak(aTHX_ "Bad evalled substitution pattern");
a0714e2c 3550 PL_lex_repl = NULL;
e9fa98b2 3551 }
79072805
LW
3552 /* FALLTHROUGH */
3553 case LEX_INTERPCONCAT:
3554#ifdef DEBUGGING
3280af22 3555 if (PL_lex_brackets)
cea2e8a9 3556 Perl_croak(aTHX_ "panic: INTERPCONCAT");
79072805 3557#endif
3280af22 3558 if (PL_bufptr == PL_bufend)
bbf60fe6 3559 return REPORT(sublex_done());
79072805 3560
3280af22
NIS
3561 if (SvIVX(PL_linestr) == '\'') {
3562 SV *sv = newSVsv(PL_linestr);
3563 if (!PL_lex_inpat)
76e3520e 3564 sv = tokeq(sv);
3280af22 3565 else if ( PL_hints & HINT_NEW_RE )
eb0d8d16 3566 sv = new_constant(NULL, 0, "qr", sv, sv, "q", 1);
6154021b 3567 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
3280af22 3568 s = PL_bufend;
79072805
LW
3569 }
3570 else {
3280af22 3571 s = scan_const(PL_bufptr);
79072805 3572 if (*s == '\\')
3280af22 3573 PL_lex_state = LEX_INTERPCASEMOD;
79072805 3574 else
3280af22 3575 PL_lex_state = LEX_INTERPSTART;
79072805
LW
3576 }
3577
3280af22 3578 if (s != PL_bufptr) {
cd81e915 3579 start_force(PL_curforce);
5db06880
NC
3580 if (PL_madskills) {
3581 curmad('X', newSVpvn(PL_bufptr,s-PL_bufptr));
3582 }
6154021b 3583 NEXTVAL_NEXTTOKE = pl_yylval;
3280af22 3584 PL_expect = XTERM;
79072805 3585 force_next(THING);
131b3ad0 3586 if (PL_lex_starts++) {
5db06880
NC
3587#ifdef PERL_MAD
3588 if (PL_madskills) {
cd81e915
NC
3589 if (PL_thistoken)
3590 sv_free(PL_thistoken);
6b29d1f5 3591 PL_thistoken = newSVpvs("");
5db06880
NC
3592 }
3593#endif
131b3ad0
DM
3594 /* commas only at base level: /$a\Ub$c/ => ($a,uc(b.$c)) */
3595 if (!PL_lex_casemods && PL_lex_inpat)
3596 OPERATOR(',');
3597 else
3598 Aop(OP_CONCAT);
3599 }
79072805 3600 else {
3280af22 3601 PL_bufptr = s;
cea2e8a9 3602 return yylex();
79072805
LW
3603 }
3604 }
3605
cea2e8a9 3606 return yylex();
a0d0e21e 3607 case LEX_FORMLINE:
3280af22
NIS
3608 PL_lex_state = LEX_NORMAL;
3609 s = scan_formline(PL_bufptr);
3610 if (!PL_lex_formbrack)
a0d0e21e
LW
3611 goto rightbracket;
3612 OPERATOR(';');
79072805
LW
3613 }
3614
3280af22
NIS
3615 s = PL_bufptr;
3616 PL_oldoldbufptr = PL_oldbufptr;
3617 PL_oldbufptr = s;
463ee0b2
LW
3618
3619 retry:
5db06880 3620#ifdef PERL_MAD
cd81e915
NC
3621 if (PL_thistoken) {
3622 sv_free(PL_thistoken);
3623 PL_thistoken = 0;
5db06880 3624 }
cd81e915 3625 PL_realtokenstart = s - SvPVX(PL_linestr); /* assume but undo on ws */
5db06880 3626#endif
378cc40b
LW
3627 switch (*s) {
3628 default:
7e2040f0 3629 if (isIDFIRST_lazy_if(s,UTF))
834a4ddd 3630 goto keylookup;
b1fc3636
CJ
3631 {
3632 unsigned char c = *s;
3633 len = UTF ? Perl_utf8_length(aTHX_ (U8 *) PL_linestart, (U8 *) s) : (STRLEN) (s - PL_linestart);
3634 if (len > UNRECOGNIZED_PRECEDE_COUNT) {
3635 d = UTF ? (char *) Perl_utf8_hop(aTHX_ (U8 *) s, -UNRECOGNIZED_PRECEDE_COUNT) : s - UNRECOGNIZED_PRECEDE_COUNT;
3636 } else {
3637 d = PL_linestart;
3638 }
3639 *s = '\0';
3640 Perl_croak(aTHX_ "Unrecognized character \\x%02X; marked by <-- HERE after %s<-- HERE near column %d", c, d, (int) len + 1);
3641 }
e929a76b
LW
3642 case 4:
3643 case 26:
3644 goto fake_eof; /* emulate EOF on ^D or ^Z */
378cc40b 3645 case 0:
5db06880
NC
3646#ifdef PERL_MAD
3647 if (PL_madskills)
cd81e915 3648 PL_faketokens = 0;
5db06880 3649#endif
3280af22
NIS
3650 if (!PL_rsfp) {
3651 PL_last_uni = 0;
3652 PL_last_lop = 0;
c5ee2135 3653 if (PL_lex_brackets) {
10edeb5d
JH
3654 yyerror((const char *)
3655 (PL_lex_formbrack
3656 ? "Format not terminated"
3657 : "Missing right curly or square bracket"));
c5ee2135 3658 }
4e553d73 3659 DEBUG_T( { PerlIO_printf(Perl_debug_log,
607df283 3660 "### Tokener got EOF\n");
5f80b19c 3661 } );
79072805 3662 TOKEN(0);
463ee0b2 3663 }
3280af22 3664 if (s++ < PL_bufend)
a687059c 3665 goto retry; /* ignore stray nulls */
3280af22
NIS
3666 PL_last_uni = 0;
3667 PL_last_lop = 0;
3668 if (!PL_in_eval && !PL_preambled) {
3669 PL_preambled = TRUE;
5db06880
NC
3670#ifdef PERL_MAD
3671 if (PL_madskills)
cd81e915 3672 PL_faketokens = 1;
5db06880 3673#endif
5ab7ff98
NC
3674 if (PL_perldb) {
3675 /* Generate a string of Perl code to load the debugger.
3676 * If PERL5DB is set, it will return the contents of that,
3677 * otherwise a compile-time require of perl5db.pl. */
3678
3679 const char * const pdb = PerlEnv_getenv("PERL5DB");
3680
3681 if (pdb) {
3682 sv_setpv(PL_linestr, pdb);
3683 sv_catpvs(PL_linestr,";");
3684 } else {
3685 SETERRNO(0,SS_NORMAL);
3686 sv_setpvs(PL_linestr, "BEGIN { require 'perl5db.pl' };");
3687 }
3688 } else
3689 sv_setpvs(PL_linestr,"");
c62eb204
NC
3690 if (PL_preambleav) {
3691 SV **svp = AvARRAY(PL_preambleav);
3692 SV **const end = svp + AvFILLp(PL_preambleav);
3693 while(svp <= end) {
3694 sv_catsv(PL_linestr, *svp);
3695 ++svp;
396482e1 3696 sv_catpvs(PL_linestr, ";");
91b7def8 3697 }
daba3364 3698 sv_free(MUTABLE_SV(PL_preambleav));
3280af22 3699 PL_preambleav = NULL;
91b7def8 3700 }
9f639728
FR
3701 if (PL_minus_E)
3702 sv_catpvs(PL_linestr,
3703 "use feature ':5." STRINGIFY(PERL_VERSION) "';");
3280af22 3704 if (PL_minus_n || PL_minus_p) {
396482e1 3705 sv_catpvs(PL_linestr, "LINE: while (<>) {");
3280af22 3706 if (PL_minus_l)
396482e1 3707 sv_catpvs(PL_linestr,"chomp;");
3280af22 3708 if (PL_minus_a) {
3280af22 3709 if (PL_minus_F) {
3792a11b
NC
3710 if ((*PL_splitstr == '/' || *PL_splitstr == '\''
3711 || *PL_splitstr == '"')
3280af22 3712 && strchr(PL_splitstr + 1, *PL_splitstr))
3db68c4c 3713 Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
54310121 3714 else {
c8ef6a4b
NC
3715 /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
3716 bytes can be used as quoting characters. :-) */
dd374669 3717 const char *splits = PL_splitstr;
91d456ae 3718 sv_catpvs(PL_linestr, "our @F=split(q\0");
48c4c863
NC
3719 do {
3720 /* Need to \ \s */
dd374669
AL
3721 if (*splits == '\\')
3722 sv_catpvn(PL_linestr, splits, 1);
3723 sv_catpvn(PL_linestr, splits, 1);
3724 } while (*splits++);
48c4c863
NC
3725 /* This loop will embed the trailing NUL of
3726 PL_linestr as the last thing it does before
3727 terminating. */
396482e1 3728 sv_catpvs(PL_linestr, ");");
54310121 3729 }
2304df62
AD
3730 }
3731 else
396482e1 3732 sv_catpvs(PL_linestr,"our @F=split(' ');");
2304df62 3733 }
79072805 3734 }
396482e1 3735 sv_catpvs(PL_linestr, "\n");
3280af22
NIS
3736 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3737 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3738 PL_last_lop = PL_last_uni = NULL;
65269a95 3739 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 3740 update_debugger_info(PL_linestr, NULL, 0);
79072805 3741 goto retry;
a687059c 3742 }
e929a76b 3743 do {
aa7440fb 3744 bof = PL_rsfp ? TRUE : FALSE;
5cc814fd 3745 if ((s = filter_gets(PL_linestr, 0)) == NULL) {
7e28d3af 3746 fake_eof:
5db06880 3747#ifdef PERL_MAD
cd81e915 3748 PL_realtokenstart = -1;
5db06880 3749#endif
7e28d3af 3750 if (PL_rsfp) {
4c84d7f2 3751 if ((PerlIO *)PL_rsfp == PerlIO_stdin())
7e28d3af
JH
3752 PerlIO_clearerr(PL_rsfp);
3753 else
3754 (void)PerlIO_close(PL_rsfp);
4608196e 3755 PL_rsfp = NULL;
7e28d3af
JH
3756 PL_doextract = FALSE;
3757 }
3758 if (!PL_in_eval && (PL_minus_n || PL_minus_p)) {
5db06880
NC
3759#ifdef PERL_MAD
3760 if (PL_madskills)
cd81e915 3761 PL_faketokens = 1;
5db06880 3762#endif
49a54bbe
NC
3763 if (PL_minus_p)
3764 sv_setpvs(PL_linestr, ";}continue{print;}");
3765 else
3766 sv_setpvs(PL_linestr, ";}");
7e28d3af
JH
3767 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3768 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3769 PL_last_lop = PL_last_uni = NULL;
7e28d3af
JH
3770 PL_minus_n = PL_minus_p = 0;
3771 goto retry;
3772 }
3773 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
bd61b366 3774 PL_last_lop = PL_last_uni = NULL;
76f68e9b 3775 sv_setpvs(PL_linestr,"");
7e28d3af
JH
3776 TOKEN(';'); /* not infinite loop because rsfp is NULL now */
3777 }
7aa207d6
JH
3778 /* If it looks like the start of a BOM or raw UTF-16,
3779 * check if it in fact is. */
3780 else if (bof &&
3781 (*s == 0 ||
3782 *(U8*)s == 0xEF ||
3783 *(U8*)s >= 0xFE ||
3784 s[1] == 0)) {
226017aa 3785#ifdef PERLIO_IS_STDIO
e3f494f1
JH
3786# ifdef __GNU_LIBRARY__
3787# if __GNU_LIBRARY__ == 1 /* Linux glibc5 */
226017aa
DD
3788# define FTELL_FOR_PIPE_IS_BROKEN
3789# endif
e3f494f1
JH
3790# else
3791# ifdef __GLIBC__
3792# if __GLIBC__ == 1 /* maybe some glibc5 release had it like this? */
3793# define FTELL_FOR_PIPE_IS_BROKEN
3794# endif
3795# endif
226017aa
DD
3796# endif
3797#endif
eb160463 3798 bof = PerlIO_tell(PL_rsfp) == (Off_t)SvCUR(PL_linestr);
7e28d3af 3799 if (bof) {
3280af22 3800 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
7e28d3af 3801 s = swallow_bom((U8*)s);
e929a76b 3802 }
378cc40b 3803 }
3280af22 3804 if (PL_doextract) {
a0d0e21e 3805 /* Incest with pod. */
5db06880
NC
3806#ifdef PERL_MAD
3807 if (PL_madskills)
cd81e915 3808 sv_catsv(PL_thiswhite, PL_linestr);
5db06880 3809#endif
01a57ef7 3810 if (*s == '=' && strnEQ(s, "=cut", 4) && !isALPHA(s[4])) {
76f68e9b 3811 sv_setpvs(PL_linestr, "");
3280af22
NIS
3812 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
3813 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3814 PL_last_lop = PL_last_uni = NULL;
3280af22 3815 PL_doextract = FALSE;
a0d0e21e 3816 }
4e553d73 3817 }
463ee0b2 3818 incline(s);
3280af22
NIS
3819 } while (PL_doextract);
3820 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
65269a95 3821 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 3822 update_debugger_info(PL_linestr, NULL, 0);
3280af22 3823 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 3824 PL_last_lop = PL_last_uni = NULL;
57843af0 3825 if (CopLINE(PL_curcop) == 1) {
3280af22 3826 while (s < PL_bufend && isSPACE(*s))
79072805 3827 s++;
a0d0e21e 3828 if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
79072805 3829 s++;
5db06880
NC
3830#ifdef PERL_MAD
3831 if (PL_madskills)
cd81e915 3832 PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
5db06880 3833#endif
bd61b366 3834 d = NULL;
3280af22 3835 if (!PL_in_eval) {
44a8e56a 3836 if (*s == '#' && *(s+1) == '!')
3837 d = s + 2;
3838#ifdef ALTERNATE_SHEBANG
3839 else {
bfed75c6 3840 static char const as[] = ALTERNATE_SHEBANG;
44a8e56a 3841 if (*s == as[0] && strnEQ(s, as, sizeof(as) - 1))
3842 d = s + (sizeof(as) - 1);
3843 }
3844#endif /* ALTERNATE_SHEBANG */
3845 }
3846 if (d) {
b8378b72 3847 char *ipath;
774d564b 3848 char *ipathend;
b8378b72 3849
774d564b 3850 while (isSPACE(*d))
b8378b72
CS
3851 d++;
3852 ipath = d;
774d564b 3853 while (*d && !isSPACE(*d))
3854 d++;
3855 ipathend = d;
3856
3857#ifdef ARG_ZERO_IS_SCRIPT
3858 if (ipathend > ipath) {
3859 /*
3860 * HP-UX (at least) sets argv[0] to the script name,
3861 * which makes $^X incorrect. And Digital UNIX and Linux,
3862 * at least, set argv[0] to the basename of the Perl
3863 * interpreter. So, having found "#!", we'll set it right.
3864 */
fafc274c
NC
3865 SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
3866 SVt_PV)); /* $^X */
774d564b 3867 assert(SvPOK(x) || SvGMAGICAL(x));
cc49e20b 3868 if (sv_eq(x, CopFILESV(PL_curcop))) {
774d564b 3869 sv_setpvn(x, ipath, ipathend - ipath);
9607fc9c 3870 SvSETMAGIC(x);
3871 }
556c1dec
JH
3872 else {
3873 STRLEN blen;
3874 STRLEN llen;
cfd0369c 3875 const char *bstart = SvPV_const(CopFILESV(PL_curcop),blen);
9d4ba2ae 3876 const char * const lstart = SvPV_const(x,llen);
556c1dec
JH
3877 if (llen < blen) {
3878 bstart += blen - llen;
3879 if (strnEQ(bstart, lstart, llen) && bstart[-1] == '/') {
3880 sv_setpvn(x, ipath, ipathend - ipath);
3881 SvSETMAGIC(x);
3882 }
3883 }
3884 }
774d564b 3885 TAINT_NOT; /* $^X is always tainted, but that's OK */
8ebc5c01 3886 }
774d564b 3887#endif /* ARG_ZERO_IS_SCRIPT */
b8378b72
CS
3888
3889 /*
3890 * Look for options.
3891 */
748a9306 3892 d = instr(s,"perl -");
84e30d1a 3893 if (!d) {
748a9306 3894 d = instr(s,"perl");
84e30d1a
GS
3895#if defined(DOSISH)
3896 /* avoid getting into infinite loops when shebang
3897 * line contains "Perl" rather than "perl" */
3898 if (!d) {
3899 for (d = ipathend-4; d >= ipath; --d) {
3900 if ((*d == 'p' || *d == 'P')
3901 && !ibcmp(d, "perl", 4))
3902 {
3903 break;
3904 }
3905 }
3906 if (d < ipath)
bd61b366 3907 d = NULL;
84e30d1a
GS
3908 }
3909#endif
3910 }
44a8e56a 3911#ifdef ALTERNATE_SHEBANG
3912 /*
3913 * If the ALTERNATE_SHEBANG on this system starts with a
3914 * character that can be part of a Perl expression, then if
3915 * we see it but not "perl", we're probably looking at the
3916 * start of Perl code, not a request to hand off to some
3917 * other interpreter. Similarly, if "perl" is there, but
3918 * not in the first 'word' of the line, we assume the line
3919 * contains the start of the Perl program.
44a8e56a 3920 */
3921 if (d && *s != '#') {
f54cb97a 3922 const char *c = ipath;
44a8e56a 3923 while (*c && !strchr("; \t\r\n\f\v#", *c))
3924 c++;
3925 if (c < d)
bd61b366 3926 d = NULL; /* "perl" not in first word; ignore */
44a8e56a 3927 else
3928 *s = '#'; /* Don't try to parse shebang line */
3929 }
774d564b 3930#endif /* ALTERNATE_SHEBANG */
748a9306 3931 if (!d &&
44a8e56a 3932 *s == '#' &&
774d564b 3933 ipathend > ipath &&
3280af22 3934 !PL_minus_c &&
748a9306 3935 !instr(s,"indir") &&
3280af22 3936 instr(PL_origargv[0],"perl"))
748a9306 3937 {
27da23d5 3938 dVAR;
9f68db38 3939 char **newargv;
9f68db38 3940
774d564b 3941 *ipathend = '\0';
3942 s = ipathend + 1;
3280af22 3943 while (s < PL_bufend && isSPACE(*s))
9f68db38 3944 s++;
3280af22 3945 if (s < PL_bufend) {
d85f917e 3946 Newx(newargv,PL_origargc+3,char*);
9f68db38 3947 newargv[1] = s;
3280af22 3948 while (s < PL_bufend && !isSPACE(*s))
9f68db38
LW
3949 s++;
3950 *s = '\0';
3280af22 3951 Copy(PL_origargv+1, newargv+2, PL_origargc+1, char*);
9f68db38
LW
3952 }
3953 else
3280af22 3954 newargv = PL_origargv;
774d564b 3955 newargv[0] = ipath;
b35112e7 3956 PERL_FPU_PRE_EXEC
b4748376 3957 PerlProc_execv(ipath, EXEC_ARGV_CAST(newargv));
b35112e7 3958 PERL_FPU_POST_EXEC
cea2e8a9 3959 Perl_croak(aTHX_ "Can't exec %s", ipath);
9f68db38 3960 }
748a9306 3961 if (d) {
c35e046a
AL
3962 while (*d && !isSPACE(*d))
3963 d++;
3964 while (SPACE_OR_TAB(*d))
3965 d++;
748a9306
LW
3966
3967 if (*d++ == '-') {
f54cb97a 3968 const bool switches_done = PL_doswitches;
fb993905
GA
3969 const U32 oldpdb = PL_perldb;
3970 const bool oldn = PL_minus_n;
3971 const bool oldp = PL_minus_p;
c7030b81 3972 const char *d1 = d;
fb993905 3973
8cc95fdb 3974 do {
4ba71d51
FC
3975 bool baduni = FALSE;
3976 if (*d1 == 'C') {
bd0ab00d
NC
3977 const char *d2 = d1 + 1;
3978 if (parse_unicode_opts((const char **)&d2)
3979 != PL_unicode)
3980 baduni = TRUE;
4ba71d51
FC
3981 }
3982 if (baduni || *d1 == 'M' || *d1 == 'm') {
c7030b81
NC
3983 const char * const m = d1;
3984 while (*d1 && !isSPACE(*d1))
3985 d1++;
cea2e8a9 3986 Perl_croak(aTHX_ "Too late for \"-%.*s\" option",
c7030b81 3987 (int)(d1 - m), m);
8cc95fdb 3988 }
c7030b81
NC
3989 d1 = moreswitches(d1);
3990 } while (d1);
f0b2cf55
YST
3991 if (PL_doswitches && !switches_done) {
3992 int argc = PL_origargc;
3993 char **argv = PL_origargv;
3994 do {
3995 argc--,argv++;
3996 } while (argc && argv[0][0] == '-' && argv[0][1]);
3997 init_argv_symbols(argc,argv);
3998 }
65269a95 3999 if (((PERLDB_LINE || PERLDB_SAVESRC) && !oldpdb) ||
155aba94 4000 ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
b084f20b 4001 /* if we have already added "LINE: while (<>) {",
4002 we must not do it again */
748a9306 4003 {
76f68e9b 4004 sv_setpvs(PL_linestr, "");
3280af22
NIS
4005 PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
4006 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 4007 PL_last_lop = PL_last_uni = NULL;
3280af22 4008 PL_preambled = FALSE;
65269a95 4009 if (PERLDB_LINE || PERLDB_SAVESRC)
3280af22 4010 (void)gv_fetchfile(PL_origfilename);
748a9306
LW
4011 goto retry;
4012 }
a0d0e21e 4013 }
79072805 4014 }
9f68db38 4015 }
79072805 4016 }
3280af22
NIS
4017 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4018 PL_bufptr = s;
4019 PL_lex_state = LEX_FORMLINE;
cea2e8a9 4020 return yylex();
ae986130 4021 }
378cc40b 4022 goto retry;
4fdae800 4023 case '\r':
6a27c188 4024#ifdef PERL_STRICT_CR
cea2e8a9 4025 Perl_warn(aTHX_ "Illegal character \\%03o (carriage return)", '\r');
4e553d73 4026 Perl_croak(aTHX_
cc507455 4027 "\t(Maybe you didn't strip carriage returns after a network transfer?)\n");
a868473f 4028#endif
4fdae800 4029 case ' ': case '\t': case '\f': case 013:
5db06880 4030#ifdef PERL_MAD
cd81e915 4031 PL_realtokenstart = -1;
ac372eb8
RD
4032 if (!PL_thiswhite)
4033 PL_thiswhite = newSVpvs("");
4034 sv_catpvn(PL_thiswhite, s, 1);
5db06880 4035#endif
ac372eb8 4036 s++;
378cc40b 4037 goto retry;
378cc40b 4038 case '#':
e929a76b 4039 case '\n':
5db06880 4040#ifdef PERL_MAD
cd81e915 4041 PL_realtokenstart = -1;
5db06880 4042 if (PL_madskills)
cd81e915 4043 PL_faketokens = 0;
5db06880 4044#endif
3280af22 4045 if (PL_lex_state != LEX_NORMAL || (PL_in_eval && !PL_rsfp)) {
df0deb90
GS
4046 if (*s == '#' && s == PL_linestart && PL_in_eval && !PL_rsfp) {
4047 /* handle eval qq[#line 1 "foo"\n ...] */
4048 CopLINE_dec(PL_curcop);
4049 incline(s);
4050 }
5db06880
NC
4051 if (PL_madskills && !PL_lex_formbrack && !PL_in_eval) {
4052 s = SKIPSPACE0(s);
4053 if (!PL_in_eval || PL_rsfp)
4054 incline(s);
4055 }
4056 else {
4057 d = s;
4058 while (d < PL_bufend && *d != '\n')
4059 d++;
4060 if (d < PL_bufend)
4061 d++;
4062 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4063 Perl_croak(aTHX_ "panic: input overflow");
4064#ifdef PERL_MAD
4065 if (PL_madskills)
cd81e915 4066 PL_thiswhite = newSVpvn(s, d - s);
5db06880
NC
4067#endif
4068 s = d;
4069 incline(s);
4070 }
3280af22
NIS
4071 if (PL_lex_formbrack && PL_lex_brackets <= PL_lex_formbrack) {
4072 PL_bufptr = s;
4073 PL_lex_state = LEX_FORMLINE;
cea2e8a9 4074 return yylex();
a687059c 4075 }
378cc40b 4076 }
a687059c 4077 else {
5db06880
NC
4078#ifdef PERL_MAD
4079 if (PL_madskills && CopLINE(PL_curcop) >= 1 && !PL_lex_formbrack) {
4080 if (CopLINE(PL_curcop) == 1 && s[0] == '#' && s[1] == '!') {
cd81e915 4081 PL_faketokens = 0;
5db06880
NC
4082 s = SKIPSPACE0(s);
4083 TOKEN(PEG); /* make sure any #! line is accessible */
4084 }
4085 s = SKIPSPACE0(s);
4086 }
4087 else {
4088/* if (PL_madskills && PL_lex_formbrack) { */
4089 d = s;
4090 while (d < PL_bufend && *d != '\n')
4091 d++;
4092 if (d < PL_bufend)
4093 d++;
4094 else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
4095 Perl_croak(aTHX_ "panic: input overflow");
4096 if (PL_madskills && CopLINE(PL_curcop) >= 1) {
cd81e915 4097 if (!PL_thiswhite)
6b29d1f5 4098 PL_thiswhite = newSVpvs("");
5db06880 4099 if (CopLINE(PL_curcop) == 1) {
76f68e9b 4100 sv_setpvs(PL_thiswhite, "");
cd81e915 4101 PL_faketokens = 0;
5db06880 4102 }
cd81e915 4103 sv_catpvn(PL_thiswhite, s, d - s);
5db06880
NC
4104 }
4105 s = d;
4106/* }
4107 *s = '\0';
4108 PL_bufend = s; */
4109 }
4110#else
378cc40b 4111 *s = '\0';
3280af22 4112 PL_bufend = s;
5db06880 4113#endif
a687059c 4114 }
378cc40b
LW
4115 goto retry;
4116 case '-':
79072805 4117 if (s[1] && isALPHA(s[1]) && !isALNUM(s[2])) {
e5edeb50 4118 I32 ftst = 0;
90771dc0 4119 char tmp;
e5edeb50 4120
378cc40b 4121 s++;
3280af22 4122 PL_bufptr = s;
748a9306
LW
4123 tmp = *s++;
4124
bf4acbe4 4125 while (s < PL_bufend && SPACE_OR_TAB(*s))
748a9306
LW
4126 s++;
4127
4128 if (strnEQ(s,"=>",2)) {
3280af22 4129 s = force_word(PL_bufptr,WORD,FALSE,FALSE,FALSE);
931e0695 4130 DEBUG_T( { printbuf("### Saw unary minus before =>, forcing word %s\n", s); } );
748a9306
LW
4131 OPERATOR('-'); /* unary minus */
4132 }
3280af22 4133 PL_last_uni = PL_oldbufptr;
748a9306 4134 switch (tmp) {
e5edeb50
JH
4135 case 'r': ftst = OP_FTEREAD; break;
4136 case 'w': ftst = OP_FTEWRITE; break;
4137 case 'x': ftst = OP_FTEEXEC; break;
4138 case 'o': ftst = OP_FTEOWNED; break;
4139 case 'R': ftst = OP_FTRREAD; break;
4140 case 'W': ftst = OP_FTRWRITE; break;
4141 case 'X': ftst = OP_FTREXEC; break;
4142 case 'O': ftst = OP_FTROWNED; break;
4143 case 'e': ftst = OP_FTIS; break;
4144 case 'z': ftst = OP_FTZERO; break;
4145 case 's': ftst = OP_FTSIZE; break;
4146 case 'f': ftst = OP_FTFILE; break;
4147 case 'd': ftst = OP_FTDIR; break;
4148 case 'l': ftst = OP_FTLINK; break;
4149 case 'p': ftst = OP_FTPIPE; break;
4150 case 'S': ftst = OP_FTSOCK; break;
4151 case 'u': ftst = OP_FTSUID; break;
4152 case 'g': ftst = OP_FTSGID; break;
4153 case 'k': ftst = OP_FTSVTX; break;
4154 case 'b': ftst = OP_FTBLK; break;
4155 case 'c': ftst = OP_FTCHR; break;
4156 case 't': ftst = OP_FTTTY; break;
4157 case 'T': ftst = OP_FTTEXT; break;
4158 case 'B': ftst = OP_FTBINARY; break;
4159 case 'M': case 'A': case 'C':
fafc274c 4160 gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
e5edeb50
JH
4161 switch (tmp) {
4162 case 'M': ftst = OP_FTMTIME; break;
4163 case 'A': ftst = OP_FTATIME; break;
4164 case 'C': ftst = OP_FTCTIME; break;
4165 default: break;
4166 }
4167 break;
378cc40b 4168 default:
378cc40b
LW
4169 break;
4170 }
e5edeb50 4171 if (ftst) {
eb160463 4172 PL_last_lop_op = (OPCODE)ftst;
4e553d73 4173 DEBUG_T( { PerlIO_printf(Perl_debug_log,
a18d764d 4174 "### Saw file test %c\n", (int)tmp);
5f80b19c 4175 } );
e5edeb50
JH
4176 FTST(ftst);
4177 }
4178 else {
4179 /* Assume it was a minus followed by a one-letter named
4180 * subroutine call (or a -bareword), then. */
95c31fe3 4181 DEBUG_T( { PerlIO_printf(Perl_debug_log,
17ad61e0 4182 "### '-%c' looked like a file test but was not\n",
4fccd7c6 4183 (int) tmp);
5f80b19c 4184 } );
3cf7b4c4 4185 s = --PL_bufptr;
e5edeb50 4186 }
378cc40b 4187 }
90771dc0
NC
4188 {
4189 const char tmp = *s++;
4190 if (*s == tmp) {
4191 s++;
4192 if (PL_expect == XOPERATOR)
4193 TERM(POSTDEC);
4194 else
4195 OPERATOR(PREDEC);
4196 }
4197 else if (*s == '>') {
4198 s++;
29595ff2 4199 s = SKIPSPACE1(s);
90771dc0
NC
4200 if (isIDFIRST_lazy_if(s,UTF)) {
4201 s = force_word(s,METHOD,FALSE,TRUE,FALSE);
4202 TOKEN(ARROW);
4203 }
4204 else if (*s == '$')
4205 OPERATOR(ARROW);
4206 else
4207 TERM(ARROW);
4208 }
3280af22 4209 if (PL_expect == XOPERATOR)
90771dc0
NC
4210 Aop(OP_SUBTRACT);
4211 else {
4212 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4213 check_uni();
4214 OPERATOR('-'); /* unary minus */
79072805 4215 }
2f3197b3 4216 }
79072805 4217
378cc40b 4218 case '+':
90771dc0
NC
4219 {
4220 const char tmp = *s++;
4221 if (*s == tmp) {
4222 s++;
4223 if (PL_expect == XOPERATOR)
4224 TERM(POSTINC);
4225 else
4226 OPERATOR(PREINC);
4227 }
3280af22 4228 if (PL_expect == XOPERATOR)
90771dc0
NC
4229 Aop(OP_ADD);
4230 else {
4231 if (isSPACE(*s) || !isSPACE(*PL_bufptr))
4232 check_uni();
4233 OPERATOR('+');
4234 }
2f3197b3 4235 }
a687059c 4236
378cc40b 4237 case '*':
3280af22
NIS
4238 if (PL_expect != XOPERATOR) {
4239 s = scan_ident(s, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4240 PL_expect = XOPERATOR;
4241 force_ident(PL_tokenbuf, '*');
4242 if (!*PL_tokenbuf)
a0d0e21e 4243 PREREF('*');
79072805 4244 TERM('*');
a687059c 4245 }
79072805
LW
4246 s++;
4247 if (*s == '*') {
a687059c 4248 s++;
79072805 4249 PWop(OP_POW);
a687059c 4250 }
79072805
LW
4251 Mop(OP_MULTIPLY);
4252
378cc40b 4253 case '%':
3280af22 4254 if (PL_expect == XOPERATOR) {
bbce6d69 4255 ++s;
4256 Mop(OP_MODULO);
a687059c 4257 }
3280af22 4258 PL_tokenbuf[0] = '%';
e8ae98db
RGS
4259 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4260 sizeof PL_tokenbuf - 1, FALSE);
3280af22 4261 if (!PL_tokenbuf[1]) {
bbce6d69 4262 PREREF('%');
a687059c 4263 }
3280af22 4264 PL_pending_ident = '%';
bbce6d69 4265 TERM('%');
a687059c 4266
378cc40b 4267 case '^':
79072805 4268 s++;
a0d0e21e 4269 BOop(OP_BIT_XOR);
79072805 4270 case '[':
3280af22 4271 PL_lex_brackets++;
df3467db
IG
4272 {
4273 const char tmp = *s++;
4274 OPERATOR(tmp);
4275 }
378cc40b 4276 case '~':
0d863452 4277 if (s[1] == '~'
3e7dd34d 4278 && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))
0d863452
RH
4279 {
4280 s += 2;
4281 Eop(OP_SMARTMATCH);
4282 }
378cc40b 4283 case ',':
90771dc0
NC
4284 {
4285 const char tmp = *s++;
4286 OPERATOR(tmp);
4287 }
a0d0e21e
LW
4288 case ':':
4289 if (s[1] == ':') {
4290 len = 0;
0bfa2a8a 4291 goto just_a_word_zero_gv;
a0d0e21e
LW
4292 }
4293 s++;
09bef843
SB
4294 switch (PL_expect) {
4295 OP *attrs;
5db06880
NC
4296#ifdef PERL_MAD
4297 I32 stuffstart;
4298#endif
09bef843
SB
4299 case XOPERATOR:
4300 if (!PL_in_my || PL_lex_state != LEX_NORMAL)
4301 break;
4302 PL_bufptr = s; /* update in case we back off */
d83f38d8
NC
4303 if (*s == '=') {
4304 deprecate(":= for an empty attribute list");
4305 }
09bef843
SB
4306 goto grabattrs;
4307 case XATTRBLOCK:
4308 PL_expect = XBLOCK;
4309 goto grabattrs;
4310 case XATTRTERM:
4311 PL_expect = XTERMBLOCK;
4312 grabattrs:
5db06880
NC
4313#ifdef PERL_MAD
4314 stuffstart = s - SvPVX(PL_linestr) - 1;
4315#endif
29595ff2 4316 s = PEEKSPACE(s);
5f66b61c 4317 attrs = NULL;
7e2040f0 4318 while (isIDFIRST_lazy_if(s,UTF)) {
90771dc0 4319 I32 tmp;
5cc237b8 4320 SV *sv;
09bef843 4321 d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5458a98a 4322 if (isLOWER(*s) && (tmp = keyword(PL_tokenbuf, len, 0))) {
f9829d6b
GS
4323 if (tmp < 0) tmp = -tmp;
4324 switch (tmp) {
4325 case KEY_or:
4326 case KEY_and:
4327 case KEY_for:
11baf631 4328 case KEY_foreach:
f9829d6b
GS
4329 case KEY_unless:
4330 case KEY_if:
4331 case KEY_while:
4332 case KEY_until:
4333 goto got_attrs;
4334 default:
4335 break;
4336 }
4337 }
5cc237b8 4338 sv = newSVpvn(s, len);
09bef843
SB
4339 if (*d == '(') {
4340 d = scan_str(d,TRUE,TRUE);
4341 if (!d) {
09bef843
SB
4342 /* MUST advance bufptr here to avoid bogus
4343 "at end of line" context messages from yyerror().
4344 */
4345 PL_bufptr = s + len;
4346 yyerror("Unterminated attribute parameter in attribute list");
4347 if (attrs)
4348 op_free(attrs);
5cc237b8 4349 sv_free(sv);
bbf60fe6 4350 return REPORT(0); /* EOF indicator */
09bef843
SB
4351 }
4352 }
4353 if (PL_lex_stuff) {
09bef843
SB
4354 sv_catsv(sv, PL_lex_stuff);
4355 attrs = append_elem(OP_LIST, attrs,
4356 newSVOP(OP_CONST, 0, sv));
4357 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 4358 PL_lex_stuff = NULL;
09bef843
SB
4359 }
4360 else {
5cc237b8
BS
4361 if (len == 6 && strnEQ(SvPVX(sv), "unique", len)) {
4362 sv_free(sv);
1108974d 4363 if (PL_in_my == KEY_our) {
df9a6019 4364 deprecate(":unique");
1108974d 4365 }
bfed75c6 4366 else
371fce9b
DM
4367 Perl_croak(aTHX_ "The 'unique' attribute may only be applied to 'our' variables");
4368 }
4369
d3cea301
SB
4370 /* NOTE: any CV attrs applied here need to be part of
4371 the CVf_BUILTIN_ATTRS define in cv.h! */
5cc237b8
BS
4372 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "lvalue", len)) {
4373 sv_free(sv);
78f9721b 4374 CvLVALUE_on(PL_compcv);
5cc237b8
BS
4375 }
4376 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "locked", len)) {
4377 sv_free(sv);
8e5dadda 4378 deprecate(":locked");
5cc237b8
BS
4379 }
4380 else if (!PL_in_my && len == 6 && strnEQ(SvPVX(sv), "method", len)) {
4381 sv_free(sv);
78f9721b 4382 CvMETHOD_on(PL_compcv);
5cc237b8 4383 }
78f9721b
SM
4384 /* After we've set the flags, it could be argued that
4385 we don't need to do the attributes.pm-based setting
4386 process, and shouldn't bother appending recognized
d3cea301
SB
4387 flags. To experiment with that, uncomment the
4388 following "else". (Note that's already been
4389 uncommented. That keeps the above-applied built-in
4390 attributes from being intercepted (and possibly
4391 rejected) by a package's attribute routines, but is
4392 justified by the performance win for the common case
4393 of applying only built-in attributes.) */
0256094b 4394 else
78f9721b
SM
4395 attrs = append_elem(OP_LIST, attrs,
4396 newSVOP(OP_CONST, 0,
5cc237b8 4397 sv));
09bef843 4398 }
29595ff2 4399 s = PEEKSPACE(d);
0120eecf 4400 if (*s == ':' && s[1] != ':')
29595ff2 4401 s = PEEKSPACE(s+1);
0120eecf
GS
4402 else if (s == d)
4403 break; /* require real whitespace or :'s */
29595ff2 4404 /* XXX losing whitespace on sequential attributes here */
09bef843 4405 }
90771dc0
NC
4406 {
4407 const char tmp
4408 = (PL_expect == XOPERATOR ? '=' : '{'); /*'}(' for vi */
4409 if (*s != ';' && *s != '}' && *s != tmp
4410 && (tmp != '=' || *s != ')')) {
4411 const char q = ((*s == '\'') ? '"' : '\'');
4412 /* If here for an expression, and parsed no attrs, back
4413 off. */
4414 if (tmp == '=' && !attrs) {
4415 s = PL_bufptr;
4416 break;
4417 }
4418 /* MUST advance bufptr here to avoid bogus "at end of line"
4419 context messages from yyerror().
4420 */
4421 PL_bufptr = s;
10edeb5d
JH
4422 yyerror( (const char *)
4423 (*s
4424 ? Perl_form(aTHX_ "Invalid separator character "
4425 "%c%c%c in attribute list", q, *s, q)
4426 : "Unterminated attribute list" ) );
90771dc0
NC
4427 if (attrs)
4428 op_free(attrs);
4429 OPERATOR(':');
09bef843 4430 }
09bef843 4431 }
f9829d6b 4432 got_attrs:
09bef843 4433 if (attrs) {
cd81e915 4434 start_force(PL_curforce);
9ded7720 4435 NEXTVAL_NEXTTOKE.opval = attrs;
cd81e915 4436 CURMAD('_', PL_nextwhite);
89122651 4437 force_next(THING);
5db06880
NC
4438 }
4439#ifdef PERL_MAD
4440 if (PL_madskills) {
cd81e915 4441 PL_thistoken = newSVpvn(SvPVX(PL_linestr) + stuffstart,
5db06880 4442 (s - SvPVX(PL_linestr)) - stuffstart);
09bef843 4443 }
5db06880 4444#endif
09bef843
SB
4445 TOKEN(COLONATTR);
4446 }
a0d0e21e 4447 OPERATOR(':');
8990e307
LW
4448 case '(':
4449 s++;
3280af22
NIS
4450 if (PL_last_lop == PL_oldoldbufptr || PL_last_uni == PL_oldoldbufptr)
4451 PL_oldbufptr = PL_oldoldbufptr; /* allow print(STDOUT 123) */
a0d0e21e 4452 else
3280af22 4453 PL_expect = XTERM;
29595ff2 4454 s = SKIPSPACE1(s);
a0d0e21e 4455 TOKEN('(');
378cc40b 4456 case ';':
f4dd75d9 4457 CLINE;
90771dc0
NC
4458 {
4459 const char tmp = *s++;
4460 OPERATOR(tmp);
4461 }
378cc40b 4462 case ')':
90771dc0
NC
4463 {
4464 const char tmp = *s++;
29595ff2 4465 s = SKIPSPACE1(s);
90771dc0
NC
4466 if (*s == '{')
4467 PREBLOCK(tmp);
4468 TERM(tmp);
4469 }
79072805
LW
4470 case ']':
4471 s++;
3280af22 4472 if (PL_lex_brackets <= 0)
d98d5fff 4473 yyerror("Unmatched right square bracket");
463ee0b2 4474 else
3280af22
NIS
4475 --PL_lex_brackets;
4476 if (PL_lex_state == LEX_INTERPNORMAL) {
4477 if (PL_lex_brackets == 0) {
02255c60
FC
4478 if (*s == '-' && s[1] == '>')
4479 PL_lex_state = LEX_INTERPENDMAYBE;
4480 else if (*s != '[' && *s != '{')
3280af22 4481 PL_lex_state = LEX_INTERPEND;
79072805
LW
4482 }
4483 }
4633a7c4 4484 TERM(']');
79072805
LW
4485 case '{':
4486 leftbracket:
79072805 4487 s++;
3280af22 4488 if (PL_lex_brackets > 100) {
8edd5f42 4489 Renew(PL_lex_brackstack, PL_lex_brackets + 10, char);
8990e307 4490 }
3280af22 4491 switch (PL_expect) {
a0d0e21e 4492 case XTERM:
3280af22 4493 if (PL_lex_formbrack) {
a0d0e21e
LW
4494 s--;
4495 PRETERMBLOCK(DO);
4496 }
3280af22
NIS
4497 if (PL_oldoldbufptr == PL_last_lop)
4498 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
a0d0e21e 4499 else
3280af22 4500 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
79072805 4501 OPERATOR(HASHBRACK);
a0d0e21e 4502 case XOPERATOR:
bf4acbe4 4503 while (s < PL_bufend && SPACE_OR_TAB(*s))
748a9306 4504 s++;
44a8e56a 4505 d = s;
3280af22
NIS
4506 PL_tokenbuf[0] = '\0';
4507 if (d < PL_bufend && *d == '-') {
4508 PL_tokenbuf[0] = '-';
44a8e56a 4509 d++;
bf4acbe4 4510 while (d < PL_bufend && SPACE_OR_TAB(*d))
44a8e56a 4511 d++;
4512 }
7e2040f0 4513 if (d < PL_bufend && isIDFIRST_lazy_if(d,UTF)) {
3280af22 4514 d = scan_word(d, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1,
8903cb82 4515 FALSE, &len);
bf4acbe4 4516 while (d < PL_bufend && SPACE_OR_TAB(*d))
748a9306
LW
4517 d++;
4518 if (*d == '}') {
f54cb97a 4519 const char minus = (PL_tokenbuf[0] == '-');
44a8e56a 4520 s = force_word(s + minus, WORD, FALSE, TRUE, FALSE);
4521 if (minus)
4522 force_next('-');
748a9306
LW
4523 }
4524 }
4525 /* FALL THROUGH */
09bef843 4526 case XATTRBLOCK:
748a9306 4527 case XBLOCK:
3280af22
NIS
4528 PL_lex_brackstack[PL_lex_brackets++] = XSTATE;
4529 PL_expect = XSTATE;
a0d0e21e 4530 break;
09bef843 4531 case XATTRTERM:
a0d0e21e 4532 case XTERMBLOCK:
3280af22
NIS
4533 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
4534 PL_expect = XSTATE;
a0d0e21e
LW
4535 break;
4536 default: {
f54cb97a 4537 const char *t;
3280af22
NIS
4538 if (PL_oldoldbufptr == PL_last_lop)
4539 PL_lex_brackstack[PL_lex_brackets++] = XTERM;
a0d0e21e 4540 else
3280af22 4541 PL_lex_brackstack[PL_lex_brackets++] = XOPERATOR;
29595ff2 4542 s = SKIPSPACE1(s);
8452ff4b
SB
4543 if (*s == '}') {
4544 if (PL_expect == XREF && PL_lex_state == LEX_INTERPNORMAL) {
4545 PL_expect = XTERM;
4546 /* This hack is to get the ${} in the message. */
4547 PL_bufptr = s+1;
4548 yyerror("syntax error");
4549 break;
4550 }
a0d0e21e 4551 OPERATOR(HASHBRACK);
8452ff4b 4552 }
b8a4b1be
GS
4553 /* This hack serves to disambiguate a pair of curlies
4554 * as being a block or an anon hash. Normally, expectation
4555 * determines that, but in cases where we're not in a
4556 * position to expect anything in particular (like inside
4557 * eval"") we have to resolve the ambiguity. This code
4558 * covers the case where the first term in the curlies is a
4559 * quoted string. Most other cases need to be explicitly
a0288114 4560 * disambiguated by prepending a "+" before the opening
b8a4b1be
GS
4561 * curly in order to force resolution as an anon hash.
4562 *
4563 * XXX should probably propagate the outer expectation
4564 * into eval"" to rely less on this hack, but that could
4565 * potentially break current behavior of eval"".
4566 * GSAR 97-07-21
4567 */
4568 t = s;
4569 if (*s == '\'' || *s == '"' || *s == '`') {
4570 /* common case: get past first string, handling escapes */
3280af22 4571 for (t++; t < PL_bufend && *t != *s;)
b8a4b1be
GS
4572 if (*t++ == '\\' && (*t == '\\' || *t == *s))
4573 t++;
4574 t++;
a0d0e21e 4575 }
b8a4b1be 4576 else if (*s == 'q') {
3280af22 4577 if (++t < PL_bufend
b8a4b1be 4578 && (!isALNUM(*t)
3280af22 4579 || ((*t == 'q' || *t == 'x') && ++t < PL_bufend
0505442f
GS
4580 && !isALNUM(*t))))
4581 {
abc667d1 4582 /* skip q//-like construct */
f54cb97a 4583 const char *tmps;
b8a4b1be
GS
4584 char open, close, term;
4585 I32 brackets = 1;
4586
3280af22 4587 while (t < PL_bufend && isSPACE(*t))
b8a4b1be 4588 t++;
abc667d1
DM
4589 /* check for q => */
4590 if (t+1 < PL_bufend && t[0] == '=' && t[1] == '>') {
4591 OPERATOR(HASHBRACK);
4592 }
b8a4b1be
GS
4593 term = *t;
4594 open = term;
4595 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
4596 term = tmps[5];
4597 close = term;
4598 if (open == close)
3280af22
NIS
4599 for (t++; t < PL_bufend; t++) {
4600 if (*t == '\\' && t+1 < PL_bufend && open != '\\')
b8a4b1be 4601 t++;
6d07e5e9 4602 else if (*t == open)
b8a4b1be
GS
4603 break;
4604 }
abc667d1 4605 else {
3280af22
NIS
4606 for (t++; t < PL_bufend; t++) {
4607 if (*t == '\\' && t+1 < PL_bufend)
b8a4b1be 4608 t++;
6d07e5e9 4609 else if (*t == close && --brackets <= 0)
b8a4b1be
GS
4610 break;
4611 else if (*t == open)
4612 brackets++;
4613 }
abc667d1
DM
4614 }
4615 t++;
b8a4b1be 4616 }
abc667d1
DM
4617 else
4618 /* skip plain q word */
4619 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
4620 t += UTF8SKIP(t);
a0d0e21e 4621 }
7e2040f0 4622 else if (isALNUM_lazy_if(t,UTF)) {
0505442f 4623 t += UTF8SKIP(t);
7e2040f0 4624 while (t < PL_bufend && isALNUM_lazy_if(t,UTF))
0505442f 4625 t += UTF8SKIP(t);
a0d0e21e 4626 }
3280af22 4627 while (t < PL_bufend && isSPACE(*t))
a0d0e21e 4628 t++;
b8a4b1be
GS
4629 /* if comma follows first term, call it an anon hash */
4630 /* XXX it could be a comma expression with loop modifiers */
3280af22 4631 if (t < PL_bufend && ((*t == ',' && (*s == 'q' || !isLOWER(*s)))
b8a4b1be 4632 || (*t == '=' && t[1] == '>')))
a0d0e21e 4633 OPERATOR(HASHBRACK);
3280af22 4634 if (PL_expect == XREF)
4e4e412b 4635 PL_expect = XTERM;
a0d0e21e 4636 else {
3280af22
NIS
4637 PL_lex_brackstack[PL_lex_brackets-1] = XSTATE;
4638 PL_expect = XSTATE;
a0d0e21e 4639 }
8990e307 4640 }
a0d0e21e 4641 break;
463ee0b2 4642 }
6154021b 4643 pl_yylval.ival = CopLINE(PL_curcop);
79072805 4644 if (isSPACE(*s) || *s == '#')
3280af22 4645 PL_copline = NOLINE; /* invalidate current command line number */
79072805 4646 TOKEN('{');
378cc40b 4647 case '}':
79072805
LW
4648 rightbracket:
4649 s++;
3280af22 4650 if (PL_lex_brackets <= 0)
d98d5fff 4651 yyerror("Unmatched right curly bracket");
463ee0b2 4652 else
3280af22 4653 PL_expect = (expectation)PL_lex_brackstack[--PL_lex_brackets];
c2e66d9e 4654 if (PL_lex_brackets < PL_lex_formbrack && PL_lex_state != LEX_INTERPNORMAL)
3280af22
NIS
4655 PL_lex_formbrack = 0;
4656 if (PL_lex_state == LEX_INTERPNORMAL) {
4657 if (PL_lex_brackets == 0) {
9059aa12
LW
4658 if (PL_expect & XFAKEBRACK) {
4659 PL_expect &= XENUMMASK;
3280af22
NIS
4660 PL_lex_state = LEX_INTERPEND;
4661 PL_bufptr = s;
5db06880
NC
4662#if 0
4663 if (PL_madskills) {
cd81e915 4664 if (!PL_thiswhite)
6b29d1f5 4665 PL_thiswhite = newSVpvs("");
76f68e9b 4666 sv_catpvs(PL_thiswhite,"}");
5db06880
NC
4667 }
4668#endif
cea2e8a9 4669 return yylex(); /* ignore fake brackets */
79072805 4670 }
fa83b5b6 4671 if (*s == '-' && s[1] == '>')
3280af22 4672 PL_lex_state = LEX_INTERPENDMAYBE;
fa83b5b6 4673 else if (*s != '[' && *s != '{')
3280af22 4674 PL_lex_state = LEX_INTERPEND;
79072805
LW
4675 }
4676 }
9059aa12
LW
4677 if (PL_expect & XFAKEBRACK) {
4678 PL_expect &= XENUMMASK;
3280af22 4679 PL_bufptr = s;
cea2e8a9 4680 return yylex(); /* ignore fake brackets */
748a9306 4681 }
cd81e915 4682 start_force(PL_curforce);
5db06880
NC
4683 if (PL_madskills) {
4684 curmad('X', newSVpvn(s-1,1));
cd81e915 4685 CURMAD('_', PL_thiswhite);
5db06880 4686 }
79072805 4687 force_next('}');
5db06880 4688#ifdef PERL_MAD
cd81e915 4689 if (!PL_thistoken)
6b29d1f5 4690 PL_thistoken = newSVpvs("");
5db06880 4691#endif
79072805 4692 TOKEN(';');
378cc40b
LW
4693 case '&':
4694 s++;
90771dc0 4695 if (*s++ == '&')
a0d0e21e 4696 AOPERATOR(ANDAND);
378cc40b 4697 s--;
3280af22 4698 if (PL_expect == XOPERATOR) {
041457d9
DM
4699 if (PL_bufptr == PL_linestart && ckWARN(WARN_SEMICOLON)
4700 && isIDFIRST_lazy_if(s,UTF))
7e2040f0 4701 {
57843af0 4702 CopLINE_dec(PL_curcop);
f1f66076 4703 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
57843af0 4704 CopLINE_inc(PL_curcop);
463ee0b2 4705 }
79072805 4706 BAop(OP_BIT_AND);
463ee0b2 4707 }
79072805 4708
3280af22
NIS
4709 s = scan_ident(s - 1, PL_bufend, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
4710 if (*PL_tokenbuf) {
4711 PL_expect = XOPERATOR;
4712 force_ident(PL_tokenbuf, '&');
463ee0b2 4713 }
79072805
LW
4714 else
4715 PREREF('&');
6154021b 4716 pl_yylval.ival = (OPpENTERSUB_AMPER<<8);
79072805
LW
4717 TERM('&');
4718
378cc40b
LW
4719 case '|':
4720 s++;
90771dc0 4721 if (*s++ == '|')
a0d0e21e 4722 AOPERATOR(OROR);
378cc40b 4723 s--;
79072805 4724 BOop(OP_BIT_OR);
378cc40b
LW
4725 case '=':
4726 s++;
748a9306 4727 {
90771dc0
NC
4728 const char tmp = *s++;
4729 if (tmp == '=')
4730 Eop(OP_EQ);
4731 if (tmp == '>')
4732 OPERATOR(',');
4733 if (tmp == '~')
4734 PMop(OP_MATCH);
4735 if (tmp && isSPACE(*s) && ckWARN(WARN_SYNTAX)
4736 && strchr("+-*/%.^&|<",tmp))
4737 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4738 "Reversed %c= operator",(int)tmp);
4739 s--;
4740 if (PL_expect == XSTATE && isALPHA(tmp) &&
4741 (s == PL_linestart+1 || s[-2] == '\n') )
4742 {
4743 if (PL_in_eval && !PL_rsfp) {
4744 d = PL_bufend;
4745 while (s < d) {
4746 if (*s++ == '\n') {
4747 incline(s);
4748 if (strnEQ(s,"=cut",4)) {
4749 s = strchr(s,'\n');
4750 if (s)
4751 s++;
4752 else
4753 s = d;
4754 incline(s);
4755 goto retry;
4756 }
4757 }
a5f75d66 4758 }
90771dc0 4759 goto retry;
a5f75d66 4760 }
5db06880
NC
4761#ifdef PERL_MAD
4762 if (PL_madskills) {
cd81e915 4763 if (!PL_thiswhite)
6b29d1f5 4764 PL_thiswhite = newSVpvs("");
cd81e915 4765 sv_catpvn(PL_thiswhite, PL_linestart,
5db06880
NC
4766 PL_bufend - PL_linestart);
4767 }
4768#endif
90771dc0
NC
4769 s = PL_bufend;
4770 PL_doextract = TRUE;
4771 goto retry;
a5f75d66 4772 }
a0d0e21e 4773 }
3280af22 4774 if (PL_lex_brackets < PL_lex_formbrack) {
c35e046a 4775 const char *t = s;
51882d45 4776#ifdef PERL_STRICT_CR
c35e046a 4777 while (SPACE_OR_TAB(*t))
51882d45 4778#else
c35e046a 4779 while (SPACE_OR_TAB(*t) || *t == '\r')
51882d45 4780#endif
c35e046a 4781 t++;
a0d0e21e
LW
4782 if (*t == '\n' || *t == '#') {
4783 s--;
3280af22 4784 PL_expect = XBLOCK;
a0d0e21e
LW
4785 goto leftbracket;
4786 }
79072805 4787 }
6154021b 4788 pl_yylval.ival = 0;
a0d0e21e 4789 OPERATOR(ASSIGNOP);
378cc40b
LW
4790 case '!':
4791 s++;
90771dc0
NC
4792 {
4793 const char tmp = *s++;
4794 if (tmp == '=') {
4795 /* was this !=~ where !~ was meant?
4796 * warn on m:!=~\s+([/?]|[msy]\W|tr\W): */
4797
4798 if (*s == '~' && ckWARN(WARN_SYNTAX)) {
4799 const char *t = s+1;
4800
4801 while (t < PL_bufend && isSPACE(*t))
4802 ++t;
4803
4804 if (*t == '/' || *t == '?' ||
4805 ((*t == 'm' || *t == 's' || *t == 'y')
4806 && !isALNUM(t[1])) ||
4807 (*t == 't' && t[1] == 'r' && !isALNUM(t[2])))
4808 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4809 "!=~ should be !~");
4810 }
4811 Eop(OP_NE);
4812 }
4813 if (tmp == '~')
4814 PMop(OP_NOT);
4815 }
378cc40b
LW
4816 s--;
4817 OPERATOR('!');
4818 case '<':
3280af22 4819 if (PL_expect != XOPERATOR) {
93a17b20 4820 if (s[1] != '<' && !strchr(s,'>'))
2f3197b3 4821 check_uni();
79072805
LW
4822 if (s[1] == '<')
4823 s = scan_heredoc(s);
4824 else
4825 s = scan_inputsymbol(s);
4826 TERM(sublex_start());
378cc40b
LW
4827 }
4828 s++;
90771dc0
NC
4829 {
4830 char tmp = *s++;
4831 if (tmp == '<')
4832 SHop(OP_LEFT_SHIFT);
4833 if (tmp == '=') {
4834 tmp = *s++;
4835 if (tmp == '>')
4836 Eop(OP_NCMP);
4837 s--;
4838 Rop(OP_LE);
4839 }
395c3793 4840 }
378cc40b 4841 s--;
79072805 4842 Rop(OP_LT);
378cc40b
LW
4843 case '>':
4844 s++;
90771dc0
NC
4845 {
4846 const char tmp = *s++;
4847 if (tmp == '>')
4848 SHop(OP_RIGHT_SHIFT);
d4c19fe8 4849 else if (tmp == '=')
90771dc0
NC
4850 Rop(OP_GE);
4851 }
378cc40b 4852 s--;
79072805 4853 Rop(OP_GT);
378cc40b
LW
4854
4855 case '$':
bbce6d69 4856 CLINE;
4857
3280af22
NIS
4858 if (PL_expect == XOPERATOR) {
4859 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
8290c323 4860 return deprecate_commaless_var_list();
a0d0e21e 4861 }
8990e307 4862 }
a0d0e21e 4863
7e2040f0 4864 if (s[1] == '#' && (isIDFIRST_lazy_if(s+2,UTF) || strchr("{$:+-", s[2]))) {
3280af22 4865 PL_tokenbuf[0] = '@';
376b8730
SM
4866 s = scan_ident(s + 1, PL_bufend, PL_tokenbuf + 1,
4867 sizeof PL_tokenbuf - 1, FALSE);
4868 if (PL_expect == XOPERATOR)
4869 no_op("Array length", s);
3280af22 4870 if (!PL_tokenbuf[1])
a0d0e21e 4871 PREREF(DOLSHARP);
3280af22
NIS
4872 PL_expect = XOPERATOR;
4873 PL_pending_ident = '#';
463ee0b2 4874 TOKEN(DOLSHARP);
79072805 4875 }
bbce6d69 4876
3280af22 4877 PL_tokenbuf[0] = '$';
376b8730
SM
4878 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1,
4879 sizeof PL_tokenbuf - 1, FALSE);
4880 if (PL_expect == XOPERATOR)
4881 no_op("Scalar", s);
3280af22
NIS
4882 if (!PL_tokenbuf[1]) {
4883 if (s == PL_bufend)
bbce6d69 4884 yyerror("Final $ should be \\$ or $name");
4885 PREREF('$');
8990e307 4886 }
a0d0e21e 4887
bbce6d69 4888 /* This kludge not intended to be bulletproof. */
3280af22 4889 if (PL_tokenbuf[1] == '[' && !PL_tokenbuf[2]) {
6154021b 4890 pl_yylval.opval = newSVOP(OP_CONST, 0,
fc15ae8f 4891 newSViv(CopARYBASE_get(&PL_compiling)));
6154021b 4892 pl_yylval.opval->op_private = OPpCONST_ARYBASE;
bbce6d69 4893 TERM(THING);
4894 }
4895
ff68c719 4896 d = s;
90771dc0
NC
4897 {
4898 const char tmp = *s;
4899 if (PL_lex_state == LEX_NORMAL)
29595ff2 4900 s = SKIPSPACE1(s);
ff68c719 4901
90771dc0
NC
4902 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop)
4903 && intuit_more(s)) {
4904 if (*s == '[') {
4905 PL_tokenbuf[0] = '@';
4906 if (ckWARN(WARN_SYNTAX)) {
c35e046a
AL
4907 char *t = s+1;
4908
4909 while (isSPACE(*t) || isALNUM_lazy_if(t,UTF) || *t == '$')
4910 t++;
90771dc0 4911 if (*t++ == ',') {
29595ff2 4912 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
90771dc0
NC
4913 while (t < PL_bufend && *t != ']')
4914 t++;
9014280d 4915 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
90771dc0 4916 "Multidimensional syntax %.*s not supported",
36c7798d 4917 (int)((t - PL_bufptr) + 1), PL_bufptr);
90771dc0 4918 }
748a9306 4919 }
93a17b20 4920 }
90771dc0
NC
4921 else if (*s == '{') {
4922 char *t;
4923 PL_tokenbuf[0] = '%';
4924 if (strEQ(PL_tokenbuf+1, "SIG") && ckWARN(WARN_SYNTAX)
4925 && (t = strchr(s, '}')) && (t = strchr(t, '=')))
4926 {
4927 char tmpbuf[sizeof PL_tokenbuf];
c35e046a
AL
4928 do {
4929 t++;
4930 } while (isSPACE(*t));
90771dc0 4931 if (isIDFIRST_lazy_if(t,UTF)) {
780a5241 4932 STRLEN len;
90771dc0 4933 t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE,
780a5241 4934 &len);
c35e046a
AL
4935 while (isSPACE(*t))
4936 t++;
780a5241 4937 if (*t == ';' && get_cvn_flags(tmpbuf, len, 0))
90771dc0
NC
4938 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
4939 "You need to quote \"%s\"",
4940 tmpbuf);
4941 }
4942 }
4943 }
93a17b20 4944 }
bbce6d69 4945
90771dc0
NC
4946 PL_expect = XOPERATOR;
4947 if (PL_lex_state == LEX_NORMAL && isSPACE((char)tmp)) {
4948 const bool islop = (PL_last_lop == PL_oldoldbufptr);
4949 if (!islop || PL_last_lop_op == OP_GREPSTART)
4950 PL_expect = XOPERATOR;
4951 else if (strchr("$@\"'`q", *s))
4952 PL_expect = XTERM; /* e.g. print $fh "foo" */
4953 else if (strchr("&*<%", *s) && isIDFIRST_lazy_if(s+1,UTF))
4954 PL_expect = XTERM; /* e.g. print $fh &sub */
4955 else if (isIDFIRST_lazy_if(s,UTF)) {
4956 char tmpbuf[sizeof PL_tokenbuf];
4957 int t2;
4958 scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5458a98a 4959 if ((t2 = keyword(tmpbuf, len, 0))) {
90771dc0
NC
4960 /* binary operators exclude handle interpretations */
4961 switch (t2) {
4962 case -KEY_x:
4963 case -KEY_eq:
4964 case -KEY_ne:
4965 case -KEY_gt:
4966 case -KEY_lt:
4967 case -KEY_ge:
4968 case -KEY_le:
4969 case -KEY_cmp:
4970 break;
4971 default:
4972 PL_expect = XTERM; /* e.g. print $fh length() */
4973 break;
4974 }
4975 }
4976 else {
4977 PL_expect = XTERM; /* e.g. print $fh subr() */
84902520
TB
4978 }
4979 }
90771dc0
NC
4980 else if (isDIGIT(*s))
4981 PL_expect = XTERM; /* e.g. print $fh 3 */
4982 else if (*s == '.' && isDIGIT(s[1]))
4983 PL_expect = XTERM; /* e.g. print $fh .3 */
4984 else if ((*s == '?' || *s == '-' || *s == '+')
4985 && !isSPACE(s[1]) && s[1] != '=')
4986 PL_expect = XTERM; /* e.g. print $fh -1 */
4987 else if (*s == '/' && !isSPACE(s[1]) && s[1] != '='
4988 && s[1] != '/')
4989 PL_expect = XTERM; /* e.g. print $fh /.../
4990 XXX except DORDOR operator
4991 */
4992 else if (*s == '<' && s[1] == '<' && !isSPACE(s[2])
4993 && s[2] != '=')
4994 PL_expect = XTERM; /* print $fh <<"EOF" */
93a17b20 4995 }
bbce6d69 4996 }
3280af22 4997 PL_pending_ident = '$';
79072805 4998 TOKEN('$');
378cc40b
LW
4999
5000 case '@':
3280af22 5001 if (PL_expect == XOPERATOR)
bbce6d69 5002 no_op("Array", s);
3280af22
NIS
5003 PL_tokenbuf[0] = '@';
5004 s = scan_ident(s, PL_bufend, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
5005 if (!PL_tokenbuf[1]) {
bbce6d69 5006 PREREF('@');
5007 }
3280af22 5008 if (PL_lex_state == LEX_NORMAL)
29595ff2 5009 s = SKIPSPACE1(s);
3280af22 5010 if ((PL_expect != XREF || PL_oldoldbufptr == PL_last_lop) && intuit_more(s)) {
bbce6d69 5011 if (*s == '{')
3280af22 5012 PL_tokenbuf[0] = '%';
a0d0e21e
LW
5013
5014 /* Warn about @ where they meant $. */
041457d9
DM
5015 if (*s == '[' || *s == '{') {
5016 if (ckWARN(WARN_SYNTAX)) {
f54cb97a 5017 const char *t = s + 1;
7e2040f0 5018 while (*t && (isALNUM_lazy_if(t,UTF) || strchr(" \t$#+-'\"", *t)))
a0d0e21e
LW
5019 t++;
5020 if (*t == '}' || *t == ']') {
5021 t++;
29595ff2 5022 PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */
9014280d 5023 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
599cee73 5024 "Scalar value %.*s better written as $%.*s",
36c7798d
DM
5025 (int)(t-PL_bufptr), PL_bufptr,
5026 (int)(t-PL_bufptr-1), PL_bufptr+1);
a0d0e21e 5027 }
93a17b20
LW
5028 }
5029 }
463ee0b2 5030 }
3280af22 5031 PL_pending_ident = '@';
79072805 5032 TERM('@');
378cc40b 5033
c963b151 5034 case '/': /* may be division, defined-or, or pattern */
6f33ba73
RGS
5035 if (PL_expect == XTERMORDORDOR && s[1] == '/') {
5036 s += 2;
5037 AOPERATOR(DORDOR);
5038 }
c963b151 5039 case '?': /* may either be conditional or pattern */
be25f609 5040 if (PL_expect == XOPERATOR) {
90771dc0 5041 char tmp = *s++;
c963b151 5042 if(tmp == '?') {
be25f609 5043 OPERATOR('?');
c963b151
BD
5044 }
5045 else {
5046 tmp = *s++;
5047 if(tmp == '/') {
5048 /* A // operator. */
5049 AOPERATOR(DORDOR);
5050 }
5051 else {
5052 s--;
5053 Mop(OP_DIVIDE);
5054 }
5055 }
5056 }
5057 else {
5058 /* Disable warning on "study /blah/" */
5059 if (PL_oldoldbufptr == PL_last_uni
5060 && (*PL_last_uni != 's' || s - PL_last_uni < 5
5061 || memNE(PL_last_uni, "study", 5)
5062 || isALNUM_lazy_if(PL_last_uni+5,UTF)
5063 ))
5064 check_uni();
5065 s = scan_pat(s,OP_MATCH);
5066 TERM(sublex_start());
5067 }
378cc40b
LW
5068
5069 case '.':
51882d45
GS
5070 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack
5071#ifdef PERL_STRICT_CR
5072 && s[1] == '\n'
5073#else
5074 && (s[1] == '\n' || (s[1] == '\r' && s[2] == '\n'))
5075#endif
5076 && (s == PL_linestart || s[-1] == '\n') )
5077 {
3280af22
NIS
5078 PL_lex_formbrack = 0;
5079 PL_expect = XSTATE;
79072805
LW
5080 goto rightbracket;
5081 }
be25f609 5082 if (PL_expect == XSTATE && s[1] == '.' && s[2] == '.') {
5083 s += 3;
5084 OPERATOR(YADAYADA);
5085 }
3280af22 5086 if (PL_expect == XOPERATOR || !isDIGIT(s[1])) {
90771dc0 5087 char tmp = *s++;
a687059c
LW
5088 if (*s == tmp) {
5089 s++;
2f3197b3
LW
5090 if (*s == tmp) {
5091 s++;
6154021b 5092 pl_yylval.ival = OPf_SPECIAL;
2f3197b3
LW
5093 }
5094 else
6154021b 5095 pl_yylval.ival = 0;
378cc40b 5096 OPERATOR(DOTDOT);
a687059c 5097 }
3280af22 5098 if (PL_expect != XOPERATOR)
2f3197b3 5099 check_uni();
79072805 5100 Aop(OP_CONCAT);
378cc40b
LW
5101 }
5102 /* FALL THROUGH */
5103 case '0': case '1': case '2': case '3': case '4':
5104 case '5': case '6': case '7': case '8': case '9':
6154021b 5105 s = scan_num(s, &pl_yylval);
931e0695 5106 DEBUG_T( { printbuf("### Saw number in %s\n", s); } );
3280af22 5107 if (PL_expect == XOPERATOR)
8990e307 5108 no_op("Number",s);
79072805
LW
5109 TERM(THING);
5110
5111 case '\'':
5db06880 5112 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 5113 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
3280af22
NIS
5114 if (PL_expect == XOPERATOR) {
5115 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
8290c323 5116 return deprecate_commaless_var_list();
a0d0e21e 5117 }
463ee0b2 5118 else
8990e307 5119 no_op("String",s);
463ee0b2 5120 }
79072805 5121 if (!s)
d4c19fe8 5122 missingterm(NULL);
6154021b 5123 pl_yylval.ival = OP_CONST;
79072805
LW
5124 TERM(sublex_start());
5125
5126 case '"':
5db06880 5127 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 5128 DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
3280af22
NIS
5129 if (PL_expect == XOPERATOR) {
5130 if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
8290c323 5131 return deprecate_commaless_var_list();
a0d0e21e 5132 }
463ee0b2 5133 else
8990e307 5134 no_op("String",s);
463ee0b2 5135 }
79072805 5136 if (!s)
d4c19fe8 5137 missingterm(NULL);
6154021b 5138 pl_yylval.ival = OP_CONST;
cfd0369c
NC
5139 /* FIXME. I think that this can be const if char *d is replaced by
5140 more localised variables. */
3280af22 5141 for (d = SvPV(PL_lex_stuff, len); len; len--, d++) {
63cd0674 5142 if (*d == '$' || *d == '@' || *d == '\\' || !UTF8_IS_INVARIANT((U8)*d)) {
6154021b 5143 pl_yylval.ival = OP_STRINGIFY;
4633a7c4
LW
5144 break;
5145 }
5146 }
79072805
LW
5147 TERM(sublex_start());
5148
5149 case '`':
5db06880 5150 s = scan_str(s,!!PL_madskills,FALSE);
931e0695 5151 DEBUG_T( { printbuf("### Saw backtick string before %s\n", s); } );
3280af22 5152 if (PL_expect == XOPERATOR)
8990e307 5153 no_op("Backticks",s);
79072805 5154 if (!s)
d4c19fe8 5155 missingterm(NULL);
9b201d7d 5156 readpipe_override();
79072805
LW
5157 TERM(sublex_start());
5158
5159 case '\\':
5160 s++;
a2a5de95
NC
5161 if (PL_lex_inwhat && isDIGIT(*s))
5162 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),"Can't use \\%c to mean $%c in expression",
5163 *s, *s);
3280af22 5164 if (PL_expect == XOPERATOR)
8990e307 5165 no_op("Backslash",s);
79072805
LW
5166 OPERATOR(REFGEN);
5167
a7cb1f99 5168 case 'v':
e526c9e6 5169 if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
f54cb97a 5170 char *start = s + 2;
dd629d5b 5171 while (isDIGIT(*start) || *start == '_')
a7cb1f99
GS
5172 start++;
5173 if (*start == '.' && isDIGIT(start[1])) {
6154021b 5174 s = scan_num(s, &pl_yylval);
a7cb1f99
GS
5175 TERM(THING);
5176 }
e526c9e6 5177 /* avoid v123abc() or $h{v1}, allow C<print v10;> */
6f33ba73
RGS
5178 else if (!isALPHA(*start) && (PL_expect == XTERM
5179 || PL_expect == XREF || PL_expect == XSTATE
5180 || PL_expect == XTERMORDORDOR)) {
9bde8eb0 5181 GV *const gv = gv_fetchpvn_flags(s, start - s, 0, SVt_PVCV);
e526c9e6 5182 if (!gv) {
6154021b 5183 s = scan_num(s, &pl_yylval);
e526c9e6
GS
5184 TERM(THING);
5185 }
5186 }
a7cb1f99
GS
5187 }
5188 goto keylookup;
79072805 5189 case 'x':
3280af22 5190 if (isDIGIT(s[1]) && PL_expect == XOPERATOR) {
79072805
LW
5191 s++;
5192 Mop(OP_REPEAT);
2f3197b3 5193 }
79072805
LW
5194 goto keylookup;
5195
378cc40b 5196 case '_':
79072805
LW
5197 case 'a': case 'A':
5198 case 'b': case 'B':
5199 case 'c': case 'C':
5200 case 'd': case 'D':
5201 case 'e': case 'E':
5202 case 'f': case 'F':
5203 case 'g': case 'G':
5204 case 'h': case 'H':
5205 case 'i': case 'I':
5206 case 'j': case 'J':
5207 case 'k': case 'K':
5208 case 'l': case 'L':
5209 case 'm': case 'M':
5210 case 'n': case 'N':
5211 case 'o': case 'O':
5212 case 'p': case 'P':
5213 case 'q': case 'Q':
5214 case 'r': case 'R':
5215 case 's': case 'S':
5216 case 't': case 'T':
5217 case 'u': case 'U':
a7cb1f99 5218 case 'V':
79072805
LW
5219 case 'w': case 'W':
5220 case 'X':
5221 case 'y': case 'Y':
5222 case 'z': case 'Z':
5223
49dc05e3 5224 keylookup: {
88e1f1a2 5225 bool anydelim;
90771dc0 5226 I32 tmp;
10edeb5d
JH
5227
5228 orig_keyword = 0;
5229 gv = NULL;
5230 gvp = NULL;
49dc05e3 5231
3280af22
NIS
5232 PL_bufptr = s;
5233 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
8ebc5c01 5234
5235 /* Some keywords can be followed by any delimiter, including ':' */
88e1f1a2 5236 anydelim = ((len == 1 && strchr("msyq", PL_tokenbuf[0])) ||
155aba94
GS
5237 (len == 2 && ((PL_tokenbuf[0] == 't' && PL_tokenbuf[1] == 'r') ||
5238 (PL_tokenbuf[0] == 'q' &&
5239 strchr("qwxr", PL_tokenbuf[1])))));
8ebc5c01 5240
5241 /* x::* is just a word, unless x is "CORE" */
88e1f1a2 5242 if (!anydelim && *s == ':' && s[1] == ':' && strNE(PL_tokenbuf, "CORE"))
4633a7c4
LW
5243 goto just_a_word;
5244
3643fb5f 5245 d = s;
3280af22 5246 while (d < PL_bufend && isSPACE(*d))
3643fb5f
CS
5247 d++; /* no comments skipped here, or s### is misparsed */
5248
748a9306 5249 /* Is this a word before a => operator? */
1c3923b3 5250 if (*d == '=' && d[1] == '>') {
748a9306 5251 CLINE;
6154021b 5252 pl_yylval.opval
d0a148a6
NC
5253 = (OP*)newSVOP(OP_CONST, 0,
5254 S_newSV_maybe_utf8(aTHX_ PL_tokenbuf, len));
6154021b 5255 pl_yylval.opval->op_private = OPpCONST_BARE;
748a9306
LW
5256 TERM(WORD);
5257 }
5258
88e1f1a2
JV
5259 /* Check for plugged-in keyword */
5260 {
5261 OP *o;
5262 int result;
5263 char *saved_bufptr = PL_bufptr;
5264 PL_bufptr = s;
5265 result = CALL_FPTR(PL_keyword_plugin)(aTHX_ PL_tokenbuf, len, &o);
5266 s = PL_bufptr;
5267 if (result == KEYWORD_PLUGIN_DECLINE) {
5268 /* not a plugged-in keyword */
5269 PL_bufptr = saved_bufptr;
5270 } else if (result == KEYWORD_PLUGIN_STMT) {
5271 pl_yylval.opval = o;
5272 CLINE;
5273 PL_expect = XSTATE;
5274 return REPORT(PLUGSTMT);
5275 } else if (result == KEYWORD_PLUGIN_EXPR) {
5276 pl_yylval.opval = o;
5277 CLINE;
5278 PL_expect = XOPERATOR;
5279 return REPORT(PLUGEXPR);
5280 } else {
5281 Perl_croak(aTHX_ "Bad plugin affecting keyword '%s'",
5282 PL_tokenbuf);
5283 }
5284 }
5285
5286 /* Check for built-in keyword */
5287 tmp = keyword(PL_tokenbuf, len, 0);
5288
5289 /* Is this a label? */
5290 if (!anydelim && PL_expect == XSTATE
5291 && d < PL_bufend && *d == ':' && *(d + 1) != ':') {
5292 if (tmp)
5293 Perl_croak(aTHX_ "Can't use keyword '%s' as a label", PL_tokenbuf);
5294 s = d + 1;
5295 pl_yylval.pval = CopLABEL_alloc(PL_tokenbuf);
5296 CLINE;
5297 TOKEN(LABEL);
5298 }
5299
a0d0e21e 5300 if (tmp < 0) { /* second-class keyword? */
cbbf8932
AL
5301 GV *ogv = NULL; /* override (winner) */
5302 GV *hgv = NULL; /* hidden (loser) */
3280af22 5303 if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
56f7f34b 5304 CV *cv;
90e5519e 5305 if ((gv = gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVCV)) &&
56f7f34b
CS
5306 (cv = GvCVu(gv)))
5307 {
5308 if (GvIMPORTED_CV(gv))
5309 ogv = gv;
5310 else if (! CvMETHOD(cv))
5311 hgv = gv;
5312 }
5313 if (!ogv &&
3280af22 5314 (gvp = (GV**)hv_fetch(PL_globalstash,PL_tokenbuf,len,FALSE)) &&
9e0d86f8 5315 (gv = *gvp) && isGV_with_GP(gv) &&
56f7f34b
CS
5316 GvCVu(gv) && GvIMPORTED_CV(gv))
5317 {
5318 ogv = gv;
5319 }
5320 }
5321 if (ogv) {
30fe34ed 5322 orig_keyword = tmp;
56f7f34b 5323 tmp = 0; /* overridden by import or by GLOBAL */
6e7b2336
GS
5324 }
5325 else if (gv && !gvp
5326 && -tmp==KEY_lock /* XXX generalizable kludge */
47f9f84c 5327 && GvCVu(gv))
6e7b2336
GS
5328 {
5329 tmp = 0; /* any sub overrides "weak" keyword */
a0d0e21e 5330 }
56f7f34b
CS
5331 else { /* no override */
5332 tmp = -tmp;
a2a5de95
NC
5333 if (tmp == KEY_dump) {
5334 Perl_ck_warner(aTHX_ packWARN(WARN_MISC),
5335 "dump() better written as CORE::dump()");
ac206dc8 5336 }
a0714e2c 5337 gv = NULL;
56f7f34b 5338 gvp = 0;
a2a5de95
NC
5339 if (hgv && tmp != KEY_x && tmp != KEY_CORE) /* never ambiguous */
5340 Perl_ck_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
5341 "Ambiguous call resolved as CORE::%s(), %s",
5342 GvENAME(hgv), "qualify as such or use &");
49dc05e3 5343 }
a0d0e21e
LW
5344 }
5345
5346 reserved_word:
5347 switch (tmp) {
79072805
LW
5348
5349 default: /* not a keyword */
0bfa2a8a
NC
5350 /* Trade off - by using this evil construction we can pull the
5351 variable gv into the block labelled keylookup. If not, then
5352 we have to give it function scope so that the goto from the
5353 earlier ':' case doesn't bypass the initialisation. */
5354 if (0) {
5355 just_a_word_zero_gv:
5356 gv = NULL;
5357 gvp = NULL;
8bee0991 5358 orig_keyword = 0;
0bfa2a8a 5359 }
93a17b20 5360 just_a_word: {
96e4d5b1 5361 SV *sv;
ce29ac45 5362 int pkgname = 0;
f54cb97a 5363 const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : PL_bufptr[-1]);
f7461760 5364 OP *rv2cv_op;
5069cc75 5365 CV *cv;
5db06880 5366#ifdef PERL_MAD
cd81e915 5367 SV *nextPL_nextwhite = 0;
5db06880
NC
5368#endif
5369
8990e307
LW
5370
5371 /* Get the rest if it looks like a package qualifier */
5372
155aba94 5373 if (*s == '\'' || (*s == ':' && s[1] == ':')) {
c3e0f903 5374 STRLEN morelen;
3280af22 5375 s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - len,
c3e0f903
GS
5376 TRUE, &morelen);
5377 if (!morelen)
cea2e8a9 5378 Perl_croak(aTHX_ "Bad name after %s%s", PL_tokenbuf,
ec2ab091 5379 *s == '\'' ? "'" : "::");
c3e0f903 5380 len += morelen;
ce29ac45 5381 pkgname = 1;
a0d0e21e 5382 }
8990e307 5383
3280af22
NIS
5384 if (PL_expect == XOPERATOR) {
5385 if (PL_bufptr == PL_linestart) {
57843af0 5386 CopLINE_dec(PL_curcop);
f1f66076 5387 Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", PL_warn_nosemi);
57843af0 5388 CopLINE_inc(PL_curcop);
463ee0b2
LW
5389 }
5390 else
54310121 5391 no_op("Bareword",s);
463ee0b2 5392 }
8990e307 5393
c3e0f903
GS
5394 /* Look for a subroutine with this name in current package,
5395 unless name is "Foo::", in which case Foo is a bearword
5396 (and a package name). */
5397
5db06880 5398 if (len > 2 && !PL_madskills &&
3280af22 5399 PL_tokenbuf[len - 2] == ':' && PL_tokenbuf[len - 1] == ':')
c3e0f903 5400 {
f776e3cd 5401 if (ckWARN(WARN_BAREWORD)
90e5519e 5402 && ! gv_fetchpvn_flags(PL_tokenbuf, len, 0, SVt_PVHV))
9014280d 5403 Perl_warner(aTHX_ packWARN(WARN_BAREWORD),
599cee73 5404 "Bareword \"%s\" refers to nonexistent package",
3280af22 5405 PL_tokenbuf);
c3e0f903 5406 len -= 2;
3280af22 5407 PL_tokenbuf[len] = '\0';
a0714e2c 5408 gv = NULL;
c3e0f903
GS
5409 gvp = 0;
5410 }
5411 else {
62d55b22
NC
5412 if (!gv) {
5413 /* Mustn't actually add anything to a symbol table.
5414 But also don't want to "initialise" any placeholder
5415 constants that might already be there into full
5416 blown PVGVs with attached PVCV. */
90e5519e
NC
5417 gv = gv_fetchpvn_flags(PL_tokenbuf, len,
5418 GV_NOADD_NOINIT, SVt_PVCV);
62d55b22 5419 }
b3d904f3 5420 len = 0;
c3e0f903
GS
5421 }
5422
5423 /* if we saw a global override before, get the right name */
8990e307 5424
49dc05e3 5425 if (gvp) {
396482e1 5426 sv = newSVpvs("CORE::GLOBAL::");
3280af22 5427 sv_catpv(sv,PL_tokenbuf);
49dc05e3 5428 }
8a7a129d
NC
5429 else {
5430 /* If len is 0, newSVpv does strlen(), which is correct.
5431 If len is non-zero, then it will be the true length,
5432 and so the scalar will be created correctly. */
5433 sv = newSVpv(PL_tokenbuf,len);
5434 }
5db06880 5435#ifdef PERL_MAD
cd81e915
NC
5436 if (PL_madskills && !PL_thistoken) {
5437 char *start = SvPVX(PL_linestr) + PL_realtokenstart;
9ff8e806 5438 PL_thistoken = newSVpvn(start,s - start);
cd81e915 5439 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
5440 }
5441#endif
8990e307 5442
a0d0e21e
LW
5443 /* Presume this is going to be a bareword of some sort. */
5444
5445 CLINE;
6154021b
RGS
5446 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sv);
5447 pl_yylval.opval->op_private = OPpCONST_BARE;
8f8cf39c
JH
5448 /* UTF-8 package name? */
5449 if (UTF && !IN_BYTES &&
95a20fc0 5450 is_utf8_string((U8*)SvPVX_const(sv), SvCUR(sv)))
8f8cf39c 5451 SvUTF8_on(sv);
a0d0e21e 5452
c3e0f903
GS
5453 /* And if "Foo::", then that's what it certainly is. */
5454
5455 if (len)
5456 goto safe_bareword;
5457
f7461760
Z
5458 cv = NULL;
5459 {
5460 OP *const_op = newSVOP(OP_CONST, 0, SvREFCNT_inc(sv));
5461 const_op->op_private = OPpCONST_BARE;
5462 rv2cv_op = newCVREF(0, const_op);
5463 }
5464 if (rv2cv_op->op_type == OP_RV2CV &&
5465 (rv2cv_op->op_flags & OPf_KIDS)) {
5466 OP *rv_op = cUNOPx(rv2cv_op)->op_first;
5467 switch (rv_op->op_type) {
5468 case OP_CONST: {
5469 SV *sv = cSVOPx_sv(rv_op);
5470 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV)
5471 cv = (CV*)SvRV(sv);
5472 } break;
5473 case OP_GV: {
5474 GV *gv = cGVOPx_gv(rv_op);
5475 CV *maybe_cv = GvCVu(gv);
5476 if (maybe_cv && SvTYPE((SV*)maybe_cv) == SVt_PVCV)
5477 cv = maybe_cv;
5478 } break;
5479 }
5480 }
5069cc75 5481
8990e307
LW
5482 /* See if it's the indirect object for a list operator. */
5483
3280af22
NIS
5484 if (PL_oldoldbufptr &&
5485 PL_oldoldbufptr < PL_bufptr &&
65cec589
GS
5486 (PL_oldoldbufptr == PL_last_lop
5487 || PL_oldoldbufptr == PL_last_uni) &&
a0d0e21e 5488 /* NO SKIPSPACE BEFORE HERE! */
a9ef352a
GS
5489 (PL_expect == XREF ||
5490 ((PL_opargs[PL_last_lop_op] >> OASHIFT)& 7) == OA_FILEREF))
a0d0e21e 5491 {
748a9306
LW
5492 bool immediate_paren = *s == '(';
5493
a0d0e21e 5494 /* (Now we can afford to cross potential line boundary.) */
cd81e915 5495 s = SKIPSPACE2(s,nextPL_nextwhite);
5db06880 5496#ifdef PERL_MAD
cd81e915 5497 PL_nextwhite = nextPL_nextwhite; /* assume no & deception */
5db06880 5498#endif
a0d0e21e
LW
5499
5500 /* Two barewords in a row may indicate method call. */
5501
62d55b22 5502 if ((isIDFIRST_lazy_if(s,UTF) || *s == '$') &&
f7461760
Z
5503 (tmp = intuit_method(s, gv, cv))) {
5504 op_free(rv2cv_op);
bbf60fe6 5505 return REPORT(tmp);
f7461760 5506 }
a0d0e21e
LW
5507
5508 /* If not a declared subroutine, it's an indirect object. */
5509 /* (But it's an indir obj regardless for sort.) */
7294df96 5510 /* Also, if "_" follows a filetest operator, it's a bareword */
a0d0e21e 5511
7294df96
RGS
5512 if (
5513 ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
f7461760 5514 (!cv &&
a9ef352a 5515 (PL_last_lop_op != OP_MAPSTART &&
f0670693 5516 PL_last_lop_op != OP_GREPSTART))))
7294df96
RGS
5517 || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
5518 && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
5519 )
a9ef352a 5520 {
3280af22 5521 PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
748a9306 5522 goto bareword;
93a17b20
LW
5523 }
5524 }
8990e307 5525
3280af22 5526 PL_expect = XOPERATOR;
5db06880
NC
5527#ifdef PERL_MAD
5528 if (isSPACE(*s))
cd81e915
NC
5529 s = SKIPSPACE2(s,nextPL_nextwhite);
5530 PL_nextwhite = nextPL_nextwhite;
5db06880 5531#else
8990e307 5532 s = skipspace(s);
5db06880 5533#endif
1c3923b3
GS
5534
5535 /* Is this a word before a => operator? */
ce29ac45 5536 if (*s == '=' && s[1] == '>' && !pkgname) {
f7461760 5537 op_free(rv2cv_op);
1c3923b3 5538 CLINE;
6154021b 5539 sv_setpv(((SVOP*)pl_yylval.opval)->op_sv, PL_tokenbuf);
0064a8a9 5540 if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
6154021b 5541 SvUTF8_on(((SVOP*)pl_yylval.opval)->op_sv);
1c3923b3
GS
5542 TERM(WORD);
5543 }
5544
5545 /* If followed by a paren, it's certainly a subroutine. */
93a17b20 5546 if (*s == '(') {
79072805 5547 CLINE;
5069cc75 5548 if (cv) {
c35e046a
AL
5549 d = s + 1;
5550 while (SPACE_OR_TAB(*d))
5551 d++;
f7461760 5552 if (*d == ')' && (sv = cv_const_sv(cv))) {
96e4d5b1 5553 s = d + 1;
c631f32b 5554 goto its_constant;
96e4d5b1 5555 }
5556 }
5db06880
NC
5557#ifdef PERL_MAD
5558 if (PL_madskills) {
cd81e915
NC
5559 PL_nextwhite = PL_thiswhite;
5560 PL_thiswhite = 0;
5db06880 5561 }
cd81e915 5562 start_force(PL_curforce);
5db06880 5563#endif
6154021b 5564 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
3280af22 5565 PL_expect = XOPERATOR;
5db06880
NC
5566#ifdef PERL_MAD
5567 if (PL_madskills) {
cd81e915
NC
5568 PL_nextwhite = nextPL_nextwhite;
5569 curmad('X', PL_thistoken);
6b29d1f5 5570 PL_thistoken = newSVpvs("");
5db06880
NC
5571 }
5572#endif
f7461760 5573 op_free(rv2cv_op);
93a17b20 5574 force_next(WORD);
6154021b 5575 pl_yylval.ival = 0;
463ee0b2 5576 TOKEN('&');
79072805 5577 }
93a17b20 5578
a0d0e21e 5579 /* If followed by var or block, call it a method (unless sub) */
8990e307 5580
f7461760
Z
5581 if ((*s == '$' || *s == '{') && !cv) {
5582 op_free(rv2cv_op);
3280af22
NIS
5583 PL_last_lop = PL_oldbufptr;
5584 PL_last_lop_op = OP_METHOD;
93a17b20 5585 PREBLOCK(METHOD);
463ee0b2
LW
5586 }
5587
8990e307
LW
5588 /* If followed by a bareword, see if it looks like indir obj. */
5589
30fe34ed
RGS
5590 if (!orig_keyword
5591 && (isIDFIRST_lazy_if(s,UTF) || *s == '$')
f7461760
Z
5592 && (tmp = intuit_method(s, gv, cv))) {
5593 op_free(rv2cv_op);
bbf60fe6 5594 return REPORT(tmp);
f7461760 5595 }
93a17b20 5596
8990e307
LW
5597 /* Not a method, so call it a subroutine (if defined) */
5598
5069cc75 5599 if (cv) {
9b387841
NC
5600 if (lastchar == '-')
5601 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
5602 "Ambiguous use of -%s resolved as -&%s()",
5603 PL_tokenbuf, PL_tokenbuf);
89bfa8cd 5604 /* Check for a constant sub */
f7461760 5605 if ((sv = cv_const_sv(cv))) {
96e4d5b1 5606 its_constant:
f7461760 5607 op_free(rv2cv_op);
6154021b
RGS
5608 SvREFCNT_dec(((SVOP*)pl_yylval.opval)->op_sv);
5609 ((SVOP*)pl_yylval.opval)->op_sv = SvREFCNT_inc_simple(sv);
5610 pl_yylval.opval->op_private = 0;
96e4d5b1 5611 TOKEN(WORD);
89bfa8cd 5612 }
5613
6154021b 5614 op_free(pl_yylval.opval);
f7461760 5615 pl_yylval.opval = rv2cv_op;
6154021b 5616 pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
7a52d87a 5617 PL_last_lop = PL_oldbufptr;
bf848113 5618 PL_last_lop_op = OP_ENTERSUB;
4633a7c4 5619 /* Is there a prototype? */
5db06880
NC
5620 if (
5621#ifdef PERL_MAD
5622 cv &&
5623#endif
d9f2850e
RGS
5624 SvPOK(cv))
5625 {
5f66b61c 5626 STRLEN protolen;
daba3364 5627 const char *proto = SvPV_const(MUTABLE_SV(cv), protolen);
5f66b61c 5628 if (!protolen)
4633a7c4 5629 TERM(FUNC0SUB);
8c28b960 5630 if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
4633a7c4 5631 OPERATOR(UNIOPSUB);
0f5d0394
AE
5632 while (*proto == ';')
5633 proto++;
7a52d87a 5634 if (*proto == '&' && *s == '{') {
49a54bbe
NC
5635 if (PL_curstash)
5636 sv_setpvs(PL_subname, "__ANON__");
5637 else
5638 sv_setpvs(PL_subname, "__ANON__::__ANON__");
4633a7c4
LW
5639 PREBLOCK(LSTOPSUB);
5640 }
a9ef352a 5641 }
5db06880
NC
5642#ifdef PERL_MAD
5643 {
5644 if (PL_madskills) {
cd81e915
NC
5645 PL_nextwhite = PL_thiswhite;
5646 PL_thiswhite = 0;
5db06880 5647 }
cd81e915 5648 start_force(PL_curforce);
6154021b 5649 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5db06880
NC
5650 PL_expect = XTERM;
5651 if (PL_madskills) {
cd81e915
NC
5652 PL_nextwhite = nextPL_nextwhite;
5653 curmad('X', PL_thistoken);
6b29d1f5 5654 PL_thistoken = newSVpvs("");
5db06880
NC
5655 }
5656 force_next(WORD);
5657 TOKEN(NOAMP);
5658 }
5659 }
5660
5661 /* Guess harder when madskills require "best effort". */
5662 if (PL_madskills && (!gv || !GvCVu(gv))) {
5663 int probable_sub = 0;
5664 if (strchr("\"'`$@%0123456789!*+{[<", *s))
5665 probable_sub = 1;
5666 else if (isALPHA(*s)) {
5667 char tmpbuf[1024];
5668 STRLEN tmplen;
5669 d = s;
5670 d = scan_word(d, tmpbuf, sizeof tmpbuf, TRUE, &tmplen);
5458a98a 5671 if (!keyword(tmpbuf, tmplen, 0))
5db06880
NC
5672 probable_sub = 1;
5673 else {
5674 while (d < PL_bufend && isSPACE(*d))
5675 d++;
5676 if (*d == '=' && d[1] == '>')
5677 probable_sub = 1;
5678 }
5679 }
5680 if (probable_sub) {
7a6d04f4 5681 gv = gv_fetchpv(PL_tokenbuf, GV_ADD, SVt_PVCV);
6154021b 5682 op_free(pl_yylval.opval);
f7461760 5683 pl_yylval.opval = rv2cv_op;
6154021b 5684 pl_yylval.opval->op_private |= OPpENTERSUB_NOPAREN;
5db06880
NC
5685 PL_last_lop = PL_oldbufptr;
5686 PL_last_lop_op = OP_ENTERSUB;
cd81e915
NC
5687 PL_nextwhite = PL_thiswhite;
5688 PL_thiswhite = 0;
5689 start_force(PL_curforce);
6154021b 5690 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
5db06880 5691 PL_expect = XTERM;
cd81e915
NC
5692 PL_nextwhite = nextPL_nextwhite;
5693 curmad('X', PL_thistoken);
6b29d1f5 5694 PL_thistoken = newSVpvs("");
5db06880
NC
5695 force_next(WORD);
5696 TOKEN(NOAMP);
5697 }
5698#else
6154021b 5699 NEXTVAL_NEXTTOKE.opval = pl_yylval.opval;
3280af22 5700 PL_expect = XTERM;
8990e307
LW
5701 force_next(WORD);
5702 TOKEN(NOAMP);
5db06880 5703#endif
8990e307 5704 }
748a9306 5705
8990e307
LW
5706 /* Call it a bare word */
5707
5603f27d 5708 if (PL_hints & HINT_STRICT_SUBS)
6154021b 5709 pl_yylval.opval->op_private |= OPpCONST_STRICT;
5603f27d 5710 else {
9a073a1d
RGS
5711 bareword:
5712 /* after "print" and similar functions (corresponding to
5713 * "F? L" in opcode.pl), whatever wasn't already parsed as
5714 * a filehandle should be subject to "strict subs".
5715 * Likewise for the optional indirect-object argument to system
5716 * or exec, which can't be a bareword */
5717 if ((PL_last_lop_op == OP_PRINT
5718 || PL_last_lop_op == OP_PRTF
5719 || PL_last_lop_op == OP_SAY
5720 || PL_last_lop_op == OP_SYSTEM
5721 || PL_last_lop_op == OP_EXEC)
5722 && (PL_hints & HINT_STRICT_SUBS))
5723 pl_yylval.opval->op_private |= OPpCONST_STRICT;
041457d9
DM
5724 if (lastchar != '-') {
5725 if (ckWARN(WARN_RESERVED)) {
c35e046a
AL
5726 d = PL_tokenbuf;
5727 while (isLOWER(*d))
5728 d++;
da51bb9b 5729 if (!*d && !gv_stashpv(PL_tokenbuf, 0))
9014280d 5730 Perl_warner(aTHX_ packWARN(WARN_RESERVED), PL_warn_reserved,
5603f27d
GS
5731 PL_tokenbuf);
5732 }
748a9306
LW
5733 }
5734 }
f7461760 5735 op_free(rv2cv_op);
c3e0f903
GS
5736
5737 safe_bareword:
9b387841
NC
5738 if ((lastchar == '*' || lastchar == '%' || lastchar == '&')) {
5739 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
5740 "Operator or semicolon missing before %c%s",
5741 lastchar, PL_tokenbuf);
5742 Perl_ck_warner_d(aTHX_ packWARN(WARN_AMBIGUOUS),
5743 "Ambiguous use of %c resolved as operator %c",
5744 lastchar, lastchar);
748a9306 5745 }
93a17b20 5746 TOKEN(WORD);
79072805 5747 }
79072805 5748
68dc0745 5749 case KEY___FILE__:
6154021b 5750 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
ed094faf 5751 newSVpv(CopFILE(PL_curcop),0));
46fc3d4c 5752 TERM(THING);
5753
79072805 5754 case KEY___LINE__:
6154021b 5755 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
57843af0 5756 Perl_newSVpvf(aTHX_ "%"IVdf, (IV)CopLINE(PL_curcop)));
79072805 5757 TERM(THING);
68dc0745 5758
5759 case KEY___PACKAGE__:
6154021b 5760 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0,
3280af22 5761 (PL_curstash
5aaec2b4 5762 ? newSVhek(HvNAME_HEK(PL_curstash))
3280af22 5763 : &PL_sv_undef));
79072805 5764 TERM(THING);
79072805 5765
e50aee73 5766 case KEY___DATA__:
79072805
LW
5767 case KEY___END__: {
5768 GV *gv;
3280af22 5769 if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
bfed75c6 5770 const char *pname = "main";
3280af22 5771 if (PL_tokenbuf[2] == 'D')
bfcb3514 5772 pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
f776e3cd
NC
5773 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
5774 SVt_PVIO);
a5f75d66 5775 GvMULTI_on(gv);
79072805 5776 if (!GvIO(gv))
a0d0e21e 5777 GvIOp(gv) = newIO();
3280af22 5778 IoIFP(GvIOp(gv)) = PL_rsfp;
a0d0e21e
LW
5779#if defined(HAS_FCNTL) && defined(F_SETFD)
5780 {
f54cb97a 5781 const int fd = PerlIO_fileno(PL_rsfp);
a0d0e21e
LW
5782 fcntl(fd,F_SETFD,fd >= 3);
5783 }
79072805 5784#endif
fd049845 5785 /* Mark this internal pseudo-handle as clean */
5786 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT;
4c84d7f2 5787 if ((PerlIO*)PL_rsfp == PerlIO_stdin())
50952442 5788 IoTYPE(GvIOp(gv)) = IoTYPE_STD;
79072805 5789 else
50952442 5790 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY;
c39cd008
GS
5791#if defined(WIN32) && !defined(PERL_TEXTMODE_SCRIPTS)
5792 /* if the script was opened in binmode, we need to revert
53129d29 5793 * it to text mode for compatibility; but only iff it has CRs
c39cd008 5794 * XXX this is a questionable hack at best. */
53129d29
GS
5795 if (PL_bufend-PL_bufptr > 2
5796 && PL_bufend[-1] == '\n' && PL_bufend[-2] == '\r')
c39cd008
GS
5797 {
5798 Off_t loc = 0;
50952442 5799 if (IoTYPE(GvIOp(gv)) == IoTYPE_RDONLY) {
c39cd008
GS
5800 loc = PerlIO_tell(PL_rsfp);
5801 (void)PerlIO_seek(PL_rsfp, 0L, 0);
5802 }
2986a63f
JH
5803#ifdef NETWARE
5804 if (PerlLIO_setmode(PL_rsfp, O_TEXT) != -1) {
5805#else
c39cd008 5806 if (PerlLIO_setmode(PerlIO_fileno(PL_rsfp), O_TEXT) != -1) {
2986a63f 5807#endif /* NETWARE */
1143fce0
JH
5808#ifdef PERLIO_IS_STDIO /* really? */
5809# if defined(__BORLANDC__)
cb359b41
JH
5810 /* XXX see note in do_binmode() */
5811 ((FILE*)PL_rsfp)->flags &= ~_F_BIN;
1143fce0
JH
5812# endif
5813#endif
c39cd008
GS
5814 if (loc > 0)
5815 PerlIO_seek(PL_rsfp, loc, 0);
5816 }
5817 }
5818#endif
7948272d 5819#ifdef PERLIO_LAYERS
52d2e0f4
JH
5820 if (!IN_BYTES) {
5821 if (UTF)
5822 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
5823 else if (PL_encoding) {
5824 SV *name;
5825 dSP;
5826 ENTER;
5827 SAVETMPS;
5828 PUSHMARK(sp);
5829 EXTEND(SP, 1);
5830 XPUSHs(PL_encoding);
5831 PUTBACK;
5832 call_method("name", G_SCALAR);
5833 SPAGAIN;
5834 name = POPs;
5835 PUTBACK;
bfed75c6 5836 PerlIO_apply_layers(aTHX_ PL_rsfp, NULL,
52d2e0f4 5837 Perl_form(aTHX_ ":encoding(%"SVf")",
be2597df 5838 SVfARG(name)));
52d2e0f4
JH
5839 FREETMPS;
5840 LEAVE;
5841 }
5842 }
7948272d 5843#endif
5db06880
NC
5844#ifdef PERL_MAD
5845 if (PL_madskills) {
cd81e915
NC
5846 if (PL_realtokenstart >= 0) {
5847 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5848 if (!PL_endwhite)
6b29d1f5 5849 PL_endwhite = newSVpvs("");
cd81e915
NC
5850 sv_catsv(PL_endwhite, PL_thiswhite);
5851 PL_thiswhite = 0;
5852 sv_catpvn(PL_endwhite, tstart, PL_bufend - tstart);
5853 PL_realtokenstart = -1;
5db06880 5854 }
5cc814fd
NC
5855 while ((s = filter_gets(PL_endwhite, SvCUR(PL_endwhite)))
5856 != NULL) ;
5db06880
NC
5857 }
5858#endif
4608196e 5859 PL_rsfp = NULL;
79072805
LW
5860 }
5861 goto fake_eof;
e929a76b 5862 }
de3bb511 5863
8990e307 5864 case KEY_AUTOLOAD:
ed6116ce 5865 case KEY_DESTROY:
79072805 5866 case KEY_BEGIN:
3c10abe3 5867 case KEY_UNITCHECK:
7d30b5c4 5868 case KEY_CHECK:
7d07dbc2 5869 case KEY_INIT:
7d30b5c4 5870 case KEY_END:
3280af22
NIS
5871 if (PL_expect == XSTATE) {
5872 s = PL_bufptr;
93a17b20 5873 goto really_sub;
79072805
LW
5874 }
5875 goto just_a_word;
5876
a0d0e21e
LW
5877 case KEY_CORE:
5878 if (*s == ':' && s[1] == ':') {
5879 s += 2;
748a9306 5880 d = s;
3280af22 5881 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
5458a98a 5882 if (!(tmp = keyword(PL_tokenbuf, len, 0)))
6798c92b 5883 Perl_croak(aTHX_ "CORE::%s is not a keyword", PL_tokenbuf);
a0d0e21e
LW
5884 if (tmp < 0)
5885 tmp = -tmp;
850e8516 5886 else if (tmp == KEY_require || tmp == KEY_do)
a72a1c8b 5887 /* that's a way to remember we saw "CORE::" */
850e8516 5888 orig_keyword = tmp;
a0d0e21e
LW
5889 goto reserved_word;
5890 }
5891 goto just_a_word;
5892
463ee0b2
LW
5893 case KEY_abs:
5894 UNI(OP_ABS);
5895
79072805
LW
5896 case KEY_alarm:
5897 UNI(OP_ALARM);
5898
5899 case KEY_accept:
a0d0e21e 5900 LOP(OP_ACCEPT,XTERM);
79072805 5901
463ee0b2
LW
5902 case KEY_and:
5903 OPERATOR(ANDOP);
5904
79072805 5905 case KEY_atan2:
a0d0e21e 5906 LOP(OP_ATAN2,XTERM);
85e6fe83 5907
79072805 5908 case KEY_bind:
a0d0e21e 5909 LOP(OP_BIND,XTERM);
79072805
LW
5910
5911 case KEY_binmode:
1c1fc3ea 5912 LOP(OP_BINMODE,XTERM);
79072805
LW
5913
5914 case KEY_bless:
a0d0e21e 5915 LOP(OP_BLESS,XTERM);
79072805 5916
0d863452
RH
5917 case KEY_break:
5918 FUN0(OP_BREAK);
5919
79072805
LW
5920 case KEY_chop:
5921 UNI(OP_CHOP);
5922
5923 case KEY_continue:
0d863452
RH
5924 /* When 'use switch' is in effect, continue has a dual
5925 life as a control operator. */
5926 {
ef89dcc3 5927 if (!FEATURE_IS_ENABLED("switch"))
0d863452
RH
5928 PREBLOCK(CONTINUE);
5929 else {
5930 /* We have to disambiguate the two senses of
5931 "continue". If the next token is a '{' then
5932 treat it as the start of a continue block;
5933 otherwise treat it as a control operator.
5934 */
5935 s = skipspace(s);
5936 if (*s == '{')
79072805 5937 PREBLOCK(CONTINUE);
0d863452
RH
5938 else
5939 FUN0(OP_CONTINUE);
5940 }
5941 }
79072805
LW
5942
5943 case KEY_chdir:
fafc274c
NC
5944 /* may use HOME */
5945 (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
79072805
LW
5946 UNI(OP_CHDIR);
5947
5948 case KEY_close:
5949 UNI(OP_CLOSE);
5950
5951 case KEY_closedir:
5952 UNI(OP_CLOSEDIR);
5953
5954 case KEY_cmp:
5955 Eop(OP_SCMP);
5956
5957 case KEY_caller:
5958 UNI(OP_CALLER);
5959
5960 case KEY_crypt:
5961#ifdef FCRYPT
f4c556ac
GS
5962 if (!PL_cryptseen) {
5963 PL_cryptseen = TRUE;
de3bb511 5964 init_des();
f4c556ac 5965 }
a687059c 5966#endif
a0d0e21e 5967 LOP(OP_CRYPT,XTERM);
79072805
LW
5968
5969 case KEY_chmod:
a0d0e21e 5970 LOP(OP_CHMOD,XTERM);
79072805
LW
5971
5972 case KEY_chown:
a0d0e21e 5973 LOP(OP_CHOWN,XTERM);
79072805
LW
5974
5975 case KEY_connect:
a0d0e21e 5976 LOP(OP_CONNECT,XTERM);
79072805 5977
463ee0b2
LW
5978 case KEY_chr:
5979 UNI(OP_CHR);
5980
79072805
LW
5981 case KEY_cos:
5982 UNI(OP_COS);
5983
5984 case KEY_chroot:
5985 UNI(OP_CHROOT);
5986
0d863452
RH
5987 case KEY_default:
5988 PREBLOCK(DEFAULT);
5989
79072805 5990 case KEY_do:
29595ff2 5991 s = SKIPSPACE1(s);
79072805 5992 if (*s == '{')
a0d0e21e 5993 PRETERMBLOCK(DO);
79072805 5994 if (*s != '\'')
89c5585f 5995 s = force_word(s,WORD,TRUE,TRUE,FALSE);
850e8516
RGS
5996 if (orig_keyword == KEY_do) {
5997 orig_keyword = 0;
6154021b 5998 pl_yylval.ival = 1;
850e8516
RGS
5999 }
6000 else
6154021b 6001 pl_yylval.ival = 0;
378cc40b 6002 OPERATOR(DO);
79072805
LW
6003
6004 case KEY_die:
3280af22 6005 PL_hints |= HINT_BLOCK_SCOPE;
a0d0e21e 6006 LOP(OP_DIE,XTERM);
79072805
LW
6007
6008 case KEY_defined:
6009 UNI(OP_DEFINED);
6010
6011 case KEY_delete:
a0d0e21e 6012 UNI(OP_DELETE);
79072805
LW
6013
6014 case KEY_dbmopen:
5c1737d1 6015 gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
a0d0e21e 6016 LOP(OP_DBMOPEN,XTERM);
79072805
LW
6017
6018 case KEY_dbmclose:
6019 UNI(OP_DBMCLOSE);
6020
6021 case KEY_dump:
a0d0e21e 6022 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6023 LOOPX(OP_DUMP);
6024
6025 case KEY_else:
6026 PREBLOCK(ELSE);
6027
6028 case KEY_elsif:
6154021b 6029 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
6030 OPERATOR(ELSIF);
6031
6032 case KEY_eq:
6033 Eop(OP_SEQ);
6034
a0d0e21e
LW
6035 case KEY_exists:
6036 UNI(OP_EXISTS);
4e553d73 6037
79072805 6038 case KEY_exit:
5db06880
NC
6039 if (PL_madskills)
6040 UNI(OP_INT);
79072805
LW
6041 UNI(OP_EXIT);
6042
6043 case KEY_eval:
29595ff2 6044 s = SKIPSPACE1(s);
3280af22 6045 PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
463ee0b2 6046 UNIBRACK(OP_ENTEREVAL);
79072805
LW
6047
6048 case KEY_eof:
6049 UNI(OP_EOF);
6050
6051 case KEY_exp:
6052 UNI(OP_EXP);
6053
6054 case KEY_each:
6055 UNI(OP_EACH);
6056
6057 case KEY_exec:
a0d0e21e 6058 LOP(OP_EXEC,XREF);
79072805
LW
6059
6060 case KEY_endhostent:
6061 FUN0(OP_EHOSTENT);
6062
6063 case KEY_endnetent:
6064 FUN0(OP_ENETENT);
6065
6066 case KEY_endservent:
6067 FUN0(OP_ESERVENT);
6068
6069 case KEY_endprotoent:
6070 FUN0(OP_EPROTOENT);
6071
6072 case KEY_endpwent:
6073 FUN0(OP_EPWENT);
6074
6075 case KEY_endgrent:
6076 FUN0(OP_EGRENT);
6077
6078 case KEY_for:
6079 case KEY_foreach:
6154021b 6080 pl_yylval.ival = CopLINE(PL_curcop);
29595ff2 6081 s = SKIPSPACE1(s);
7e2040f0 6082 if (PL_expect == XSTATE && isIDFIRST_lazy_if(s,UTF)) {
55497cff 6083 char *p = s;
5db06880
NC
6084#ifdef PERL_MAD
6085 int soff = s - SvPVX(PL_linestr); /* for skipspace realloc */
6086#endif
6087
3280af22 6088 if ((PL_bufend - p) >= 3 &&
55497cff 6089 strnEQ(p, "my", 2) && isSPACE(*(p + 2)))
6090 p += 2;
77ca0c92
LW
6091 else if ((PL_bufend - p) >= 4 &&
6092 strnEQ(p, "our", 3) && isSPACE(*(p + 3)))
6093 p += 3;
29595ff2 6094 p = PEEKSPACE(p);
7e2040f0 6095 if (isIDFIRST_lazy_if(p,UTF)) {
77ca0c92
LW
6096 p = scan_ident(p, PL_bufend,
6097 PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
29595ff2 6098 p = PEEKSPACE(p);
77ca0c92
LW
6099 }
6100 if (*p != '$')
cea2e8a9 6101 Perl_croak(aTHX_ "Missing $ on loop variable");
5db06880
NC
6102#ifdef PERL_MAD
6103 s = SvPVX(PL_linestr) + soff;
6104#endif
55497cff 6105 }
79072805
LW
6106 OPERATOR(FOR);
6107
6108 case KEY_formline:
a0d0e21e 6109 LOP(OP_FORMLINE,XTERM);
79072805
LW
6110
6111 case KEY_fork:
6112 FUN0(OP_FORK);
6113
6114 case KEY_fcntl:
a0d0e21e 6115 LOP(OP_FCNTL,XTERM);
79072805
LW
6116
6117 case KEY_fileno:
6118 UNI(OP_FILENO);
6119
6120 case KEY_flock:
a0d0e21e 6121 LOP(OP_FLOCK,XTERM);
79072805
LW
6122
6123 case KEY_gt:
6124 Rop(OP_SGT);
6125
6126 case KEY_ge:
6127 Rop(OP_SGE);
6128
6129 case KEY_grep:
2c38e13d 6130 LOP(OP_GREPSTART, XREF);
79072805
LW
6131
6132 case KEY_goto:
a0d0e21e 6133 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6134 LOOPX(OP_GOTO);
6135
6136 case KEY_gmtime:
6137 UNI(OP_GMTIME);
6138
6139 case KEY_getc:
6f33ba73 6140 UNIDOR(OP_GETC);
79072805
LW
6141
6142 case KEY_getppid:
6143 FUN0(OP_GETPPID);
6144
6145 case KEY_getpgrp:
6146 UNI(OP_GETPGRP);
6147
6148 case KEY_getpriority:
a0d0e21e 6149 LOP(OP_GETPRIORITY,XTERM);
79072805
LW
6150
6151 case KEY_getprotobyname:
6152 UNI(OP_GPBYNAME);
6153
6154 case KEY_getprotobynumber:
a0d0e21e 6155 LOP(OP_GPBYNUMBER,XTERM);
79072805
LW
6156
6157 case KEY_getprotoent:
6158 FUN0(OP_GPROTOENT);
6159
6160 case KEY_getpwent:
6161 FUN0(OP_GPWENT);
6162
6163 case KEY_getpwnam:
ff68c719 6164 UNI(OP_GPWNAM);
79072805
LW
6165
6166 case KEY_getpwuid:
ff68c719 6167 UNI(OP_GPWUID);
79072805
LW
6168
6169 case KEY_getpeername:
6170 UNI(OP_GETPEERNAME);
6171
6172 case KEY_gethostbyname:
6173 UNI(OP_GHBYNAME);
6174
6175 case KEY_gethostbyaddr:
a0d0e21e 6176 LOP(OP_GHBYADDR,XTERM);
79072805
LW
6177
6178 case KEY_gethostent:
6179 FUN0(OP_GHOSTENT);
6180
6181 case KEY_getnetbyname:
6182 UNI(OP_GNBYNAME);
6183
6184 case KEY_getnetbyaddr:
a0d0e21e 6185 LOP(OP_GNBYADDR,XTERM);
79072805
LW
6186
6187 case KEY_getnetent:
6188 FUN0(OP_GNETENT);
6189
6190 case KEY_getservbyname:
a0d0e21e 6191 LOP(OP_GSBYNAME,XTERM);
79072805
LW
6192
6193 case KEY_getservbyport:
a0d0e21e 6194 LOP(OP_GSBYPORT,XTERM);
79072805
LW
6195
6196 case KEY_getservent:
6197 FUN0(OP_GSERVENT);
6198
6199 case KEY_getsockname:
6200 UNI(OP_GETSOCKNAME);
6201
6202 case KEY_getsockopt:
a0d0e21e 6203 LOP(OP_GSOCKOPT,XTERM);
79072805
LW
6204
6205 case KEY_getgrent:
6206 FUN0(OP_GGRENT);
6207
6208 case KEY_getgrnam:
ff68c719 6209 UNI(OP_GGRNAM);
79072805
LW
6210
6211 case KEY_getgrgid:
ff68c719 6212 UNI(OP_GGRGID);
79072805
LW
6213
6214 case KEY_getlogin:
6215 FUN0(OP_GETLOGIN);
6216
0d863452 6217 case KEY_given:
6154021b 6218 pl_yylval.ival = CopLINE(PL_curcop);
0d863452
RH
6219 OPERATOR(GIVEN);
6220
93a17b20 6221 case KEY_glob:
a0d0e21e 6222 LOP(OP_GLOB,XTERM);
93a17b20 6223
79072805
LW
6224 case KEY_hex:
6225 UNI(OP_HEX);
6226
6227 case KEY_if:
6154021b 6228 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
6229 OPERATOR(IF);
6230
6231 case KEY_index:
a0d0e21e 6232 LOP(OP_INDEX,XTERM);
79072805
LW
6233
6234 case KEY_int:
6235 UNI(OP_INT);
6236
6237 case KEY_ioctl:
a0d0e21e 6238 LOP(OP_IOCTL,XTERM);
79072805
LW
6239
6240 case KEY_join:
a0d0e21e 6241 LOP(OP_JOIN,XTERM);
79072805
LW
6242
6243 case KEY_keys:
6244 UNI(OP_KEYS);
6245
6246 case KEY_kill:
a0d0e21e 6247 LOP(OP_KILL,XTERM);
79072805
LW
6248
6249 case KEY_last:
a0d0e21e 6250 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805 6251 LOOPX(OP_LAST);
4e553d73 6252
79072805
LW
6253 case KEY_lc:
6254 UNI(OP_LC);
6255
6256 case KEY_lcfirst:
6257 UNI(OP_LCFIRST);
6258
6259 case KEY_local:
6154021b 6260 pl_yylval.ival = 0;
79072805
LW
6261 OPERATOR(LOCAL);
6262
6263 case KEY_length:
6264 UNI(OP_LENGTH);
6265
6266 case KEY_lt:
6267 Rop(OP_SLT);
6268
6269 case KEY_le:
6270 Rop(OP_SLE);
6271
6272 case KEY_localtime:
6273 UNI(OP_LOCALTIME);
6274
6275 case KEY_log:
6276 UNI(OP_LOG);
6277
6278 case KEY_link:
a0d0e21e 6279 LOP(OP_LINK,XTERM);
79072805
LW
6280
6281 case KEY_listen:
a0d0e21e 6282 LOP(OP_LISTEN,XTERM);
79072805 6283
c0329465
MB
6284 case KEY_lock:
6285 UNI(OP_LOCK);
6286
79072805
LW
6287 case KEY_lstat:
6288 UNI(OP_LSTAT);
6289
6290 case KEY_m:
8782bef2 6291 s = scan_pat(s,OP_MATCH);
79072805
LW
6292 TERM(sublex_start());
6293
a0d0e21e 6294 case KEY_map:
2c38e13d 6295 LOP(OP_MAPSTART, XREF);
4e4e412b 6296
79072805 6297 case KEY_mkdir:
a0d0e21e 6298 LOP(OP_MKDIR,XTERM);
79072805
LW
6299
6300 case KEY_msgctl:
a0d0e21e 6301 LOP(OP_MSGCTL,XTERM);
79072805
LW
6302
6303 case KEY_msgget:
a0d0e21e 6304 LOP(OP_MSGGET,XTERM);
79072805
LW
6305
6306 case KEY_msgrcv:
a0d0e21e 6307 LOP(OP_MSGRCV,XTERM);
79072805
LW
6308
6309 case KEY_msgsnd:
a0d0e21e 6310 LOP(OP_MSGSND,XTERM);
79072805 6311
77ca0c92 6312 case KEY_our:
93a17b20 6313 case KEY_my:
952306ac 6314 case KEY_state:
eac04b2e 6315 PL_in_my = (U16)tmp;
29595ff2 6316 s = SKIPSPACE1(s);
7e2040f0 6317 if (isIDFIRST_lazy_if(s,UTF)) {
5db06880
NC
6318#ifdef PERL_MAD
6319 char* start = s;
6320#endif
3280af22 6321 s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
09bef843
SB
6322 if (len == 3 && strnEQ(PL_tokenbuf, "sub", 3))
6323 goto really_sub;
def3634b 6324 PL_in_my_stash = find_in_my_stash(PL_tokenbuf, len);
3280af22 6325 if (!PL_in_my_stash) {
c750a3ec 6326 char tmpbuf[1024];
3280af22 6327 PL_bufptr = s;
d9fad198 6328 my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
c750a3ec
MB
6329 yyerror(tmpbuf);
6330 }
5db06880
NC
6331#ifdef PERL_MAD
6332 if (PL_madskills) { /* just add type to declarator token */
cd81e915
NC
6333 sv_catsv(PL_thistoken, PL_nextwhite);
6334 PL_nextwhite = 0;
6335 sv_catpvn(PL_thistoken, start, s - start);
5db06880
NC
6336 }
6337#endif
c750a3ec 6338 }
6154021b 6339 pl_yylval.ival = 1;
55497cff 6340 OPERATOR(MY);
93a17b20 6341
79072805 6342 case KEY_next:
a0d0e21e 6343 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6344 LOOPX(OP_NEXT);
6345
6346 case KEY_ne:
6347 Eop(OP_SNE);
6348
a0d0e21e 6349 case KEY_no:
468aa647 6350 s = tokenize_use(0, s);
a0d0e21e
LW
6351 OPERATOR(USE);
6352
6353 case KEY_not:
29595ff2 6354 if (*s == '(' || (s = SKIPSPACE1(s), *s == '('))
2d2e263d
LW
6355 FUN1(OP_NOT);
6356 else
6357 OPERATOR(NOTOP);
a0d0e21e 6358
79072805 6359 case KEY_open:
29595ff2 6360 s = SKIPSPACE1(s);
7e2040f0 6361 if (isIDFIRST_lazy_if(s,UTF)) {
f54cb97a 6362 const char *t;
c35e046a
AL
6363 for (d = s; isALNUM_lazy_if(d,UTF);)
6364 d++;
6365 for (t=d; isSPACE(*t);)
6366 t++;
e2ab214b 6367 if ( *t && strchr("|&*+-=!?:.", *t) && ckWARN_d(WARN_PRECEDENCE)
66fbe8fb
HS
6368 /* [perl #16184] */
6369 && !(t[0] == '=' && t[1] == '>')
6370 ) {
5f66b61c 6371 int parms_len = (int)(d-s);
9014280d 6372 Perl_warner(aTHX_ packWARN(WARN_PRECEDENCE),
0453d815 6373 "Precedence problem: open %.*s should be open(%.*s)",
5f66b61c 6374 parms_len, s, parms_len, s);
66fbe8fb 6375 }
93a17b20 6376 }
a0d0e21e 6377 LOP(OP_OPEN,XTERM);
79072805 6378
463ee0b2 6379 case KEY_or:
6154021b 6380 pl_yylval.ival = OP_OR;
463ee0b2
LW
6381 OPERATOR(OROP);
6382
79072805
LW
6383 case KEY_ord:
6384 UNI(OP_ORD);
6385
6386 case KEY_oct:
6387 UNI(OP_OCT);
6388
6389 case KEY_opendir:
a0d0e21e 6390 LOP(OP_OPEN_DIR,XTERM);
79072805
LW
6391
6392 case KEY_print:
3280af22 6393 checkcomma(s,PL_tokenbuf,"filehandle");
a0d0e21e 6394 LOP(OP_PRINT,XREF);
79072805
LW
6395
6396 case KEY_printf:
3280af22 6397 checkcomma(s,PL_tokenbuf,"filehandle");
a0d0e21e 6398 LOP(OP_PRTF,XREF);
79072805 6399
c07a80fd 6400 case KEY_prototype:
6401 UNI(OP_PROTOTYPE);
6402
79072805 6403 case KEY_push:
a0d0e21e 6404 LOP(OP_PUSH,XTERM);
79072805
LW
6405
6406 case KEY_pop:
6f33ba73 6407 UNIDOR(OP_POP);
79072805 6408
a0d0e21e 6409 case KEY_pos:
6f33ba73 6410 UNIDOR(OP_POS);
4e553d73 6411
79072805 6412 case KEY_pack:
a0d0e21e 6413 LOP(OP_PACK,XTERM);
79072805
LW
6414
6415 case KEY_package:
a0d0e21e 6416 s = force_word(s,WORD,FALSE,TRUE,FALSE);
6fa4d285 6417 s = force_version(s, FALSE);
79072805
LW
6418 OPERATOR(PACKAGE);
6419
6420 case KEY_pipe:
a0d0e21e 6421 LOP(OP_PIPE_OP,XTERM);
79072805
LW
6422
6423 case KEY_q:
5db06880 6424 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6425 if (!s)
d4c19fe8 6426 missingterm(NULL);
6154021b 6427 pl_yylval.ival = OP_CONST;
79072805
LW
6428 TERM(sublex_start());
6429
a0d0e21e
LW
6430 case KEY_quotemeta:
6431 UNI(OP_QUOTEMETA);
6432
8990e307 6433 case KEY_qw:
5db06880 6434 s = scan_str(s,!!PL_madskills,FALSE);
8990e307 6435 if (!s)
d4c19fe8 6436 missingterm(NULL);
3480a8d2 6437 PL_expect = XOPERATOR;
8127e0e3
GS
6438 force_next(')');
6439 if (SvCUR(PL_lex_stuff)) {
5f66b61c 6440 OP *words = NULL;
8127e0e3 6441 int warned = 0;
3280af22 6442 d = SvPV_force(PL_lex_stuff, len);
8127e0e3 6443 while (len) {
d4c19fe8
AL
6444 for (; isSPACE(*d) && len; --len, ++d)
6445 /**/;
8127e0e3 6446 if (len) {
d4c19fe8 6447 SV *sv;
f54cb97a 6448 const char *b = d;
e476b1b5 6449 if (!warned && ckWARN(WARN_QW)) {
8127e0e3
GS
6450 for (; !isSPACE(*d) && len; --len, ++d) {
6451 if (*d == ',') {
9014280d 6452 Perl_warner(aTHX_ packWARN(WARN_QW),
8127e0e3
GS
6453 "Possible attempt to separate words with commas");
6454 ++warned;
6455 }
6456 else if (*d == '#') {
9014280d 6457 Perl_warner(aTHX_ packWARN(WARN_QW),
8127e0e3
GS
6458 "Possible attempt to put comments in qw() list");
6459 ++warned;
6460 }
6461 }
6462 }
6463 else {
d4c19fe8
AL
6464 for (; !isSPACE(*d) && len; --len, ++d)
6465 /**/;
8127e0e3 6466 }
740cce10 6467 sv = newSVpvn_utf8(b, d-b, DO_UTF8(PL_lex_stuff));
8127e0e3 6468 words = append_elem(OP_LIST, words,
7948272d 6469 newSVOP(OP_CONST, 0, tokeq(sv)));
55497cff 6470 }
6471 }
8127e0e3 6472 if (words) {
cd81e915 6473 start_force(PL_curforce);
9ded7720 6474 NEXTVAL_NEXTTOKE.opval = words;
8127e0e3
GS
6475 force_next(THING);
6476 }
55497cff 6477 }
37fd879b 6478 if (PL_lex_stuff) {
8127e0e3 6479 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 6480 PL_lex_stuff = NULL;
37fd879b 6481 }
3280af22 6482 PL_expect = XTERM;
8127e0e3 6483 TOKEN('(');
8990e307 6484
79072805 6485 case KEY_qq:
5db06880 6486 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6487 if (!s)
d4c19fe8 6488 missingterm(NULL);
6154021b 6489 pl_yylval.ival = OP_STRINGIFY;
3280af22 6490 if (SvIVX(PL_lex_stuff) == '\'')
45977657 6491 SvIV_set(PL_lex_stuff, 0); /* qq'$foo' should intepolate */
79072805
LW
6492 TERM(sublex_start());
6493
8782bef2
GB
6494 case KEY_qr:
6495 s = scan_pat(s,OP_QR);
6496 TERM(sublex_start());
6497
79072805 6498 case KEY_qx:
5db06880 6499 s = scan_str(s,!!PL_madskills,FALSE);
79072805 6500 if (!s)
d4c19fe8 6501 missingterm(NULL);
9b201d7d 6502 readpipe_override();
79072805
LW
6503 TERM(sublex_start());
6504
6505 case KEY_return:
6506 OLDLOP(OP_RETURN);
6507
6508 case KEY_require:
29595ff2 6509 s = SKIPSPACE1(s);
e759cc13
RGS
6510 if (isDIGIT(*s)) {
6511 s = force_version(s, FALSE);
a7cb1f99 6512 }
e759cc13
RGS
6513 else if (*s != 'v' || !isDIGIT(s[1])
6514 || (s = force_version(s, TRUE), *s == 'v'))
6515 {
a7cb1f99
GS
6516 *PL_tokenbuf = '\0';
6517 s = force_word(s,WORD,TRUE,TRUE,FALSE);
7e2040f0 6518 if (isIDFIRST_lazy_if(PL_tokenbuf,UTF))
da51bb9b 6519 gv_stashpvn(PL_tokenbuf, strlen(PL_tokenbuf), GV_ADD);
a7cb1f99
GS
6520 else if (*s == '<')
6521 yyerror("<> should be quotes");
6522 }
a72a1c8b
RGS
6523 if (orig_keyword == KEY_require) {
6524 orig_keyword = 0;
6154021b 6525 pl_yylval.ival = 1;
a72a1c8b
RGS
6526 }
6527 else
6154021b 6528 pl_yylval.ival = 0;
a72a1c8b
RGS
6529 PL_expect = XTERM;
6530 PL_bufptr = s;
6531 PL_last_uni = PL_oldbufptr;
6532 PL_last_lop_op = OP_REQUIRE;
6533 s = skipspace(s);
6534 return REPORT( (int)REQUIRE );
79072805
LW
6535
6536 case KEY_reset:
6537 UNI(OP_RESET);
6538
6539 case KEY_redo:
a0d0e21e 6540 s = force_word(s,WORD,TRUE,FALSE,FALSE);
79072805
LW
6541 LOOPX(OP_REDO);
6542
6543 case KEY_rename:
a0d0e21e 6544 LOP(OP_RENAME,XTERM);
79072805
LW
6545
6546 case KEY_rand:
6547 UNI(OP_RAND);
6548
6549 case KEY_rmdir:
6550 UNI(OP_RMDIR);
6551
6552 case KEY_rindex:
a0d0e21e 6553 LOP(OP_RINDEX,XTERM);
79072805
LW
6554
6555 case KEY_read:
a0d0e21e 6556 LOP(OP_READ,XTERM);
79072805
LW
6557
6558 case KEY_readdir:
6559 UNI(OP_READDIR);
6560
93a17b20 6561 case KEY_readline:
6f33ba73 6562 UNIDOR(OP_READLINE);
93a17b20
LW
6563
6564 case KEY_readpipe:
0858480c 6565 UNIDOR(OP_BACKTICK);
93a17b20 6566
79072805
LW
6567 case KEY_rewinddir:
6568 UNI(OP_REWINDDIR);
6569
6570 case KEY_recv:
a0d0e21e 6571 LOP(OP_RECV,XTERM);
79072805
LW
6572
6573 case KEY_reverse:
a0d0e21e 6574 LOP(OP_REVERSE,XTERM);
79072805
LW
6575
6576 case KEY_readlink:
6f33ba73 6577 UNIDOR(OP_READLINK);
79072805
LW
6578
6579 case KEY_ref:
6580 UNI(OP_REF);
6581
6582 case KEY_s:
6583 s = scan_subst(s);
6154021b 6584 if (pl_yylval.opval)
79072805
LW
6585 TERM(sublex_start());
6586 else
6587 TOKEN(1); /* force error */
6588
0d863452
RH
6589 case KEY_say:
6590 checkcomma(s,PL_tokenbuf,"filehandle");
6591 LOP(OP_SAY,XREF);
6592
a0d0e21e
LW
6593 case KEY_chomp:
6594 UNI(OP_CHOMP);
4e553d73 6595
79072805
LW
6596 case KEY_scalar:
6597 UNI(OP_SCALAR);
6598
6599 case KEY_select:
a0d0e21e 6600 LOP(OP_SELECT,XTERM);
79072805
LW
6601
6602 case KEY_seek:
a0d0e21e 6603 LOP(OP_SEEK,XTERM);
79072805
LW
6604
6605 case KEY_semctl:
a0d0e21e 6606 LOP(OP_SEMCTL,XTERM);
79072805
LW
6607
6608 case KEY_semget:
a0d0e21e 6609 LOP(OP_SEMGET,XTERM);
79072805
LW
6610
6611 case KEY_semop:
a0d0e21e 6612 LOP(OP_SEMOP,XTERM);
79072805
LW
6613
6614 case KEY_send:
a0d0e21e 6615 LOP(OP_SEND,XTERM);
79072805
LW
6616
6617 case KEY_setpgrp:
a0d0e21e 6618 LOP(OP_SETPGRP,XTERM);
79072805
LW
6619
6620 case KEY_setpriority:
a0d0e21e 6621 LOP(OP_SETPRIORITY,XTERM);
79072805
LW
6622
6623 case KEY_sethostent:
ff68c719 6624 UNI(OP_SHOSTENT);
79072805
LW
6625
6626 case KEY_setnetent:
ff68c719 6627 UNI(OP_SNETENT);
79072805
LW
6628
6629 case KEY_setservent:
ff68c719 6630 UNI(OP_SSERVENT);
79072805
LW
6631
6632 case KEY_setprotoent:
ff68c719 6633 UNI(OP_SPROTOENT);
79072805
LW
6634
6635 case KEY_setpwent:
6636 FUN0(OP_SPWENT);
6637
6638 case KEY_setgrent:
6639 FUN0(OP_SGRENT);
6640
6641 case KEY_seekdir:
a0d0e21e 6642 LOP(OP_SEEKDIR,XTERM);
79072805
LW
6643
6644 case KEY_setsockopt:
a0d0e21e 6645 LOP(OP_SSOCKOPT,XTERM);
79072805
LW
6646
6647 case KEY_shift:
6f33ba73 6648 UNIDOR(OP_SHIFT);
79072805
LW
6649
6650 case KEY_shmctl:
a0d0e21e 6651 LOP(OP_SHMCTL,XTERM);
79072805
LW
6652
6653 case KEY_shmget:
a0d0e21e 6654 LOP(OP_SHMGET,XTERM);
79072805
LW
6655
6656 case KEY_shmread:
a0d0e21e 6657 LOP(OP_SHMREAD,XTERM);
79072805
LW
6658
6659 case KEY_shmwrite:
a0d0e21e 6660 LOP(OP_SHMWRITE,XTERM);
79072805
LW
6661
6662 case KEY_shutdown:
a0d0e21e 6663 LOP(OP_SHUTDOWN,XTERM);
79072805
LW
6664
6665 case KEY_sin:
6666 UNI(OP_SIN);
6667
6668 case KEY_sleep:
6669 UNI(OP_SLEEP);
6670
6671 case KEY_socket:
a0d0e21e 6672 LOP(OP_SOCKET,XTERM);
79072805
LW
6673
6674 case KEY_socketpair:
a0d0e21e 6675 LOP(OP_SOCKPAIR,XTERM);
79072805
LW
6676
6677 case KEY_sort:
3280af22 6678 checkcomma(s,PL_tokenbuf,"subroutine name");
29595ff2 6679 s = SKIPSPACE1(s);
79072805 6680 if (*s == ';' || *s == ')') /* probably a close */
cea2e8a9 6681 Perl_croak(aTHX_ "sort is now a reserved word");
3280af22 6682 PL_expect = XTERM;
15f0808c 6683 s = force_word(s,WORD,TRUE,TRUE,FALSE);
a0d0e21e 6684 LOP(OP_SORT,XREF);
79072805
LW
6685
6686 case KEY_split:
a0d0e21e 6687 LOP(OP_SPLIT,XTERM);
79072805
LW
6688
6689 case KEY_sprintf:
a0d0e21e 6690 LOP(OP_SPRINTF,XTERM);
79072805
LW
6691
6692 case KEY_splice:
a0d0e21e 6693 LOP(OP_SPLICE,XTERM);
79072805
LW
6694
6695 case KEY_sqrt:
6696 UNI(OP_SQRT);
6697
6698 case KEY_srand:
6699 UNI(OP_SRAND);
6700
6701 case KEY_stat:
6702 UNI(OP_STAT);
6703
6704 case KEY_study:
79072805
LW
6705 UNI(OP_STUDY);
6706
6707 case KEY_substr:
a0d0e21e 6708 LOP(OP_SUBSTR,XTERM);
79072805
LW
6709
6710 case KEY_format:
6711 case KEY_sub:
93a17b20 6712 really_sub:
09bef843 6713 {
3280af22 6714 char tmpbuf[sizeof PL_tokenbuf];
9c5ffd7c 6715 SSize_t tboffset = 0;
09bef843 6716 expectation attrful;
28cc6278 6717 bool have_name, have_proto;
f54cb97a 6718 const int key = tmp;
09bef843 6719
5db06880
NC
6720#ifdef PERL_MAD
6721 SV *tmpwhite = 0;
6722
cd81e915 6723 char *tstart = SvPVX(PL_linestr) + PL_realtokenstart;
5db06880 6724 SV *subtoken = newSVpvn(tstart, s - tstart);
cd81e915 6725 PL_thistoken = 0;
5db06880
NC
6726
6727 d = s;
6728 s = SKIPSPACE2(s,tmpwhite);
6729#else
09bef843 6730 s = skipspace(s);
5db06880 6731#endif
09bef843 6732
7e2040f0 6733 if (isIDFIRST_lazy_if(s,UTF) || *s == '\'' ||
09bef843
SB
6734 (*s == ':' && s[1] == ':'))
6735 {
5db06880 6736#ifdef PERL_MAD
4f61fd4b 6737 SV *nametoke = NULL;
5db06880
NC
6738#endif
6739
09bef843
SB
6740 PL_expect = XBLOCK;
6741 attrful = XATTRBLOCK;
b1b65b59
JH
6742 /* remember buffer pos'n for later force_word */
6743 tboffset = s - PL_oldbufptr;
09bef843 6744 d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
5db06880
NC
6745#ifdef PERL_MAD
6746 if (PL_madskills)
6747 nametoke = newSVpvn(s, d - s);
6748#endif
6502358f
NC
6749 if (memchr(tmpbuf, ':', len))
6750 sv_setpvn(PL_subname, tmpbuf, len);
09bef843
SB
6751 else {
6752 sv_setsv(PL_subname,PL_curstname);
396482e1 6753 sv_catpvs(PL_subname,"::");
09bef843
SB
6754 sv_catpvn(PL_subname,tmpbuf,len);
6755 }
09bef843 6756 have_name = TRUE;
5db06880
NC
6757
6758#ifdef PERL_MAD
6759
6760 start_force(0);
6761 CURMAD('X', nametoke);
6762 CURMAD('_', tmpwhite);
6763 (void) force_word(PL_oldbufptr + tboffset, WORD,
6764 FALSE, TRUE, TRUE);
6765
6766 s = SKIPSPACE2(d,tmpwhite);
6767#else
6768 s = skipspace(d);
6769#endif
09bef843 6770 }
463ee0b2 6771 else {
09bef843
SB
6772 if (key == KEY_my)
6773 Perl_croak(aTHX_ "Missing name in \"my sub\"");
6774 PL_expect = XTERMBLOCK;
6775 attrful = XATTRTERM;
76f68e9b 6776 sv_setpvs(PL_subname,"?");
09bef843 6777 have_name = FALSE;
463ee0b2 6778 }
4633a7c4 6779
09bef843
SB
6780 if (key == KEY_format) {
6781 if (*s == '=')
6782 PL_lex_formbrack = PL_lex_brackets + 1;
5db06880 6783#ifdef PERL_MAD
cd81e915 6784 PL_thistoken = subtoken;
5db06880
NC
6785 s = d;
6786#else
09bef843 6787 if (have_name)
b1b65b59
JH
6788 (void) force_word(PL_oldbufptr + tboffset, WORD,
6789 FALSE, TRUE, TRUE);
5db06880 6790#endif
09bef843
SB
6791 OPERATOR(FORMAT);
6792 }
79072805 6793
09bef843
SB
6794 /* Look for a prototype */
6795 if (*s == '(') {
d9f2850e
RGS
6796 char *p;
6797 bool bad_proto = FALSE;
9e8d7757
RB
6798 bool in_brackets = FALSE;
6799 char greedy_proto = ' ';
6800 bool proto_after_greedy_proto = FALSE;
6801 bool must_be_last = FALSE;
6802 bool underscore = FALSE;
aef2a98a 6803 bool seen_underscore = FALSE;
d9f2850e 6804 const bool warnsyntax = ckWARN(WARN_SYNTAX);
09bef843 6805
5db06880 6806 s = scan_str(s,!!PL_madskills,FALSE);
37fd879b 6807 if (!s)
09bef843 6808 Perl_croak(aTHX_ "Prototype not terminated");
2f758a16 6809 /* strip spaces and check for bad characters */
09bef843
SB
6810 d = SvPVX(PL_lex_stuff);
6811 tmp = 0;
d9f2850e
RGS
6812 for (p = d; *p; ++p) {
6813 if (!isSPACE(*p)) {
6814 d[tmp++] = *p;
9e8d7757
RB
6815
6816 if (warnsyntax) {
6817 if (must_be_last)
6818 proto_after_greedy_proto = TRUE;
6819 if (!strchr("$@%*;[]&\\_", *p)) {
6820 bad_proto = TRUE;
6821 }
6822 else {
6823 if ( underscore ) {
6824 if ( *p != ';' )
6825 bad_proto = TRUE;
6826 underscore = FALSE;
6827 }
6828 if ( *p == '[' ) {
6829 in_brackets = TRUE;
6830 }
6831 else if ( *p == ']' ) {
6832 in_brackets = FALSE;
6833 }
6834 else if ( (*p == '@' || *p == '%') &&
6835 ( tmp < 2 || d[tmp-2] != '\\' ) &&
6836 !in_brackets ) {
6837 must_be_last = TRUE;
6838 greedy_proto = *p;
6839 }
6840 else if ( *p == '_' ) {
aef2a98a 6841 underscore = seen_underscore = TRUE;
9e8d7757
RB
6842 }
6843 }
6844 }
d37a9538 6845 }
09bef843 6846 }
d9f2850e 6847 d[tmp] = '\0';
9e8d7757
RB
6848 if (proto_after_greedy_proto)
6849 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
6850 "Prototype after '%c' for %"SVf" : %s",
6851 greedy_proto, SVfARG(PL_subname), d);
d9f2850e
RGS
6852 if (bad_proto)
6853 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
aef2a98a
RGS
6854 "Illegal character %sin prototype for %"SVf" : %s",
6855 seen_underscore ? "after '_' " : "",
be2597df 6856 SVfARG(PL_subname), d);
b162af07 6857 SvCUR_set(PL_lex_stuff, tmp);
09bef843 6858 have_proto = TRUE;
68dc0745 6859
5db06880
NC
6860#ifdef PERL_MAD
6861 start_force(0);
cd81e915 6862 CURMAD('q', PL_thisopen);
5db06880 6863 CURMAD('_', tmpwhite);
cd81e915
NC
6864 CURMAD('=', PL_thisstuff);
6865 CURMAD('Q', PL_thisclose);
5db06880
NC
6866 NEXTVAL_NEXTTOKE.opval =
6867 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
1a9a51d4 6868 PL_lex_stuff = NULL;
5db06880
NC
6869 force_next(THING);
6870
6871 s = SKIPSPACE2(s,tmpwhite);
6872#else
09bef843 6873 s = skipspace(s);
5db06880 6874#endif
4633a7c4 6875 }
09bef843
SB
6876 else
6877 have_proto = FALSE;
6878
6879 if (*s == ':' && s[1] != ':')
6880 PL_expect = attrful;
8e742a20
MHM
6881 else if (*s != '{' && key == KEY_sub) {
6882 if (!have_name)
6883 Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
6884 else if (*s != ';')
be2597df 6885 Perl_croak(aTHX_ "Illegal declaration of subroutine %"SVf, SVfARG(PL_subname));
8e742a20 6886 }
09bef843 6887
5db06880
NC
6888#ifdef PERL_MAD
6889 start_force(0);
6890 if (tmpwhite) {
6891 if (PL_madskills)
6b29d1f5 6892 curmad('^', newSVpvs(""));
5db06880
NC
6893 CURMAD('_', tmpwhite);
6894 }
6895 force_next(0);
6896
cd81e915 6897 PL_thistoken = subtoken;
5db06880 6898#else
09bef843 6899 if (have_proto) {
9ded7720 6900 NEXTVAL_NEXTTOKE.opval =
b1b65b59 6901 (OP*)newSVOP(OP_CONST, 0, PL_lex_stuff);
a0714e2c 6902 PL_lex_stuff = NULL;
09bef843 6903 force_next(THING);
68dc0745 6904 }
5db06880 6905#endif
09bef843 6906 if (!have_name) {
49a54bbe
NC
6907 if (PL_curstash)
6908 sv_setpvs(PL_subname, "__ANON__");
6909 else
6910 sv_setpvs(PL_subname, "__ANON__::__ANON__");
09bef843 6911 TOKEN(ANONSUB);
4633a7c4 6912 }
5db06880 6913#ifndef PERL_MAD
b1b65b59
JH
6914 (void) force_word(PL_oldbufptr + tboffset, WORD,
6915 FALSE, TRUE, TRUE);
5db06880 6916#endif
09bef843
SB
6917 if (key == KEY_my)
6918 TOKEN(MYSUB);
6919 TOKEN(SUB);
4633a7c4 6920 }
79072805
LW
6921
6922 case KEY_system:
a0d0e21e 6923 LOP(OP_SYSTEM,XREF);
79072805
LW
6924
6925 case KEY_symlink:
a0d0e21e 6926 LOP(OP_SYMLINK,XTERM);
79072805
LW
6927
6928 case KEY_syscall:
a0d0e21e 6929 LOP(OP_SYSCALL,XTERM);
79072805 6930
c07a80fd 6931 case KEY_sysopen:
6932 LOP(OP_SYSOPEN,XTERM);
6933
137443ea 6934 case KEY_sysseek:
6935 LOP(OP_SYSSEEK,XTERM);
6936
79072805 6937 case KEY_sysread:
a0d0e21e 6938 LOP(OP_SYSREAD,XTERM);
79072805
LW
6939
6940 case KEY_syswrite:
a0d0e21e 6941 LOP(OP_SYSWRITE,XTERM);
79072805
LW
6942
6943 case KEY_tr:
6944 s = scan_trans(s);
6945 TERM(sublex_start());
6946
6947 case KEY_tell:
6948 UNI(OP_TELL);
6949
6950 case KEY_telldir:
6951 UNI(OP_TELLDIR);
6952
463ee0b2 6953 case KEY_tie:
a0d0e21e 6954 LOP(OP_TIE,XTERM);
463ee0b2 6955
c07a80fd 6956 case KEY_tied:
6957 UNI(OP_TIED);
6958
79072805
LW
6959 case KEY_time:
6960 FUN0(OP_TIME);
6961
6962 case KEY_times:
6963 FUN0(OP_TMS);
6964
6965 case KEY_truncate:
a0d0e21e 6966 LOP(OP_TRUNCATE,XTERM);
79072805
LW
6967
6968 case KEY_uc:
6969 UNI(OP_UC);
6970
6971 case KEY_ucfirst:
6972 UNI(OP_UCFIRST);
6973
463ee0b2
LW
6974 case KEY_untie:
6975 UNI(OP_UNTIE);
6976
79072805 6977 case KEY_until:
6154021b 6978 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
6979 OPERATOR(UNTIL);
6980
6981 case KEY_unless:
6154021b 6982 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
6983 OPERATOR(UNLESS);
6984
6985 case KEY_unlink:
a0d0e21e 6986 LOP(OP_UNLINK,XTERM);
79072805
LW
6987
6988 case KEY_undef:
6f33ba73 6989 UNIDOR(OP_UNDEF);
79072805
LW
6990
6991 case KEY_unpack:
a0d0e21e 6992 LOP(OP_UNPACK,XTERM);
79072805
LW
6993
6994 case KEY_utime:
a0d0e21e 6995 LOP(OP_UTIME,XTERM);
79072805
LW
6996
6997 case KEY_umask:
6f33ba73 6998 UNIDOR(OP_UMASK);
79072805
LW
6999
7000 case KEY_unshift:
a0d0e21e
LW
7001 LOP(OP_UNSHIFT,XTERM);
7002
7003 case KEY_use:
468aa647 7004 s = tokenize_use(1, s);
a0d0e21e 7005 OPERATOR(USE);
79072805
LW
7006
7007 case KEY_values:
7008 UNI(OP_VALUES);
7009
7010 case KEY_vec:
a0d0e21e 7011 LOP(OP_VEC,XTERM);
79072805 7012
0d863452 7013 case KEY_when:
6154021b 7014 pl_yylval.ival = CopLINE(PL_curcop);
0d863452
RH
7015 OPERATOR(WHEN);
7016
79072805 7017 case KEY_while:
6154021b 7018 pl_yylval.ival = CopLINE(PL_curcop);
79072805
LW
7019 OPERATOR(WHILE);
7020
7021 case KEY_warn:
3280af22 7022 PL_hints |= HINT_BLOCK_SCOPE;
a0d0e21e 7023 LOP(OP_WARN,XTERM);
79072805
LW
7024
7025 case KEY_wait:
7026 FUN0(OP_WAIT);
7027
7028 case KEY_waitpid:
a0d0e21e 7029 LOP(OP_WAITPID,XTERM);
79072805
LW
7030
7031 case KEY_wantarray:
7032 FUN0(OP_WANTARRAY);
7033
7034 case KEY_write:
9d116dd7
JH
7035#ifdef EBCDIC
7036 {
df3728a2
JH
7037 char ctl_l[2];
7038 ctl_l[0] = toCTRL('L');
7039 ctl_l[1] = '\0';
fafc274c 7040 gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
9d116dd7
JH
7041 }
7042#else
fafc274c
NC
7043 /* Make sure $^L is defined */
7044 gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
9d116dd7 7045#endif
79072805
LW
7046 UNI(OP_ENTERWRITE);
7047
7048 case KEY_x:
3280af22 7049 if (PL_expect == XOPERATOR)
79072805
LW
7050 Mop(OP_REPEAT);
7051 check_uni();
7052 goto just_a_word;
7053
a0d0e21e 7054 case KEY_xor:
6154021b 7055 pl_yylval.ival = OP_XOR;
a0d0e21e
LW
7056 OPERATOR(OROP);
7057
79072805
LW
7058 case KEY_y:
7059 s = scan_trans(s);
7060 TERM(sublex_start());
7061 }
49dc05e3 7062 }}
79072805 7063}
bf4acbe4
GS
7064#ifdef __SC__
7065#pragma segment Main
7066#endif
79072805 7067
e930465f
JH
7068static int
7069S_pending_ident(pTHX)
8eceec63 7070{
97aff369 7071 dVAR;
8eceec63 7072 register char *d;
bbd11bfc 7073 PADOFFSET tmp = 0;
8eceec63
SC
7074 /* pit holds the identifier we read and pending_ident is reset */
7075 char pit = PL_pending_ident;
9bde8eb0
NC
7076 const STRLEN tokenbuf_len = strlen(PL_tokenbuf);
7077 /* All routes through this function want to know if there is a colon. */
c099d646 7078 const char *const has_colon = (const char*) memchr (PL_tokenbuf, ':', tokenbuf_len);
8eceec63
SC
7079 PL_pending_ident = 0;
7080
cd81e915 7081 /* PL_realtokenstart = realtokenend = PL_bufptr - SvPVX(PL_linestr); */
8eceec63 7082 DEBUG_T({ PerlIO_printf(Perl_debug_log,
b6007c36 7083 "### Pending identifier '%s'\n", PL_tokenbuf); });
8eceec63
SC
7084
7085 /* if we're in a my(), we can't allow dynamics here.
7086 $foo'bar has already been turned into $foo::bar, so
7087 just check for colons.
7088
7089 if it's a legal name, the OP is a PADANY.
7090 */
7091 if (PL_in_my) {
7092 if (PL_in_my == KEY_our) { /* "our" is merely analogous to "my" */
9bde8eb0 7093 if (has_colon)
8eceec63
SC
7094 yyerror(Perl_form(aTHX_ "No package name allowed for "
7095 "variable %s in \"our\"",
7096 PL_tokenbuf));
d6447115 7097 tmp = allocmy(PL_tokenbuf, tokenbuf_len, 0);
8eceec63
SC
7098 }
7099 else {
9bde8eb0 7100 if (has_colon)
952306ac
RGS
7101 yyerror(Perl_form(aTHX_ PL_no_myglob,
7102 PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf));
8eceec63 7103
6154021b 7104 pl_yylval.opval = newOP(OP_PADANY, 0);
d6447115 7105 pl_yylval.opval->op_targ = allocmy(PL_tokenbuf, tokenbuf_len, 0);
8eceec63
SC
7106 return PRIVATEREF;
7107 }
7108 }
7109
7110 /*
7111 build the ops for accesses to a my() variable.
7112
7113 Deny my($a) or my($b) in a sort block, *if* $a or $b is
7114 then used in a comparison. This catches most, but not
7115 all cases. For instance, it catches
7116 sort { my($a); $a <=> $b }
7117 but not
7118 sort { my($a); $a < $b ? -1 : $a == $b ? 0 : 1; }
7119 (although why you'd do that is anyone's guess).
7120 */
7121
9bde8eb0 7122 if (!has_colon) {
8716503d 7123 if (!PL_in_my)
f8f98e0a 7124 tmp = pad_findmy(PL_tokenbuf, tokenbuf_len, 0);
8716503d 7125 if (tmp != NOT_IN_PAD) {
8eceec63 7126 /* might be an "our" variable" */
00b1698f 7127 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
8eceec63 7128 /* build ops for a bareword */
b64e5050
AL
7129 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
7130 HEK * const stashname = HvNAME_HEK(stash);
7131 SV * const sym = newSVhek(stashname);
396482e1 7132 sv_catpvs(sym, "::");
9bde8eb0 7133 sv_catpvn(sym, PL_tokenbuf+1, tokenbuf_len - 1);
6154021b
RGS
7134 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
7135 pl_yylval.opval->op_private = OPpCONST_ENTERED;
7a5fd60d 7136 gv_fetchsv(sym,
8eceec63
SC
7137 (PL_in_eval
7138 ? (GV_ADDMULTI | GV_ADDINEVAL)
700078d2 7139 : GV_ADDMULTI
8eceec63
SC
7140 ),
7141 ((PL_tokenbuf[0] == '$') ? SVt_PV
7142 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7143 : SVt_PVHV));
7144 return WORD;
7145 }
7146
7147 /* if it's a sort block and they're naming $a or $b */
7148 if (PL_last_lop_op == OP_SORT &&
7149 PL_tokenbuf[0] == '$' &&
7150 (PL_tokenbuf[1] == 'a' || PL_tokenbuf[1] == 'b')
7151 && !PL_tokenbuf[2])
7152 {
7153 for (d = PL_in_eval ? PL_oldoldbufptr : PL_linestart;
7154 d < PL_bufend && *d != '\n';
7155 d++)
7156 {
7157 if (strnEQ(d,"<=>",3) || strnEQ(d,"cmp",3)) {
7158 Perl_croak(aTHX_ "Can't use \"my %s\" in sort comparison",
7159 PL_tokenbuf);
7160 }
7161 }
7162 }
7163
6154021b
RGS
7164 pl_yylval.opval = newOP(OP_PADANY, 0);
7165 pl_yylval.opval->op_targ = tmp;
8eceec63
SC
7166 return PRIVATEREF;
7167 }
7168 }
7169
7170 /*
7171 Whine if they've said @foo in a doublequoted string,
7172 and @foo isn't a variable we can find in the symbol
7173 table.
7174 */
d824713b
NC
7175 if (ckWARN(WARN_AMBIGUOUS) &&
7176 pit == '@' && PL_lex_state != LEX_NORMAL && !PL_lex_brackets) {
9bde8eb0
NC
7177 GV *const gv = gv_fetchpvn_flags(PL_tokenbuf + 1, tokenbuf_len - 1, 0,
7178 SVt_PVAV);
8eceec63 7179 if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
e879d94f
RGS
7180 /* DO NOT warn for @- and @+ */
7181 && !( PL_tokenbuf[2] == '\0' &&
7182 ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
7183 )
8eceec63
SC
7184 {
7185 /* Downgraded from fatal to warning 20000522 mjd */
d824713b
NC
7186 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
7187 "Possible unintended interpolation of %s in string",
7188 PL_tokenbuf);
8eceec63
SC
7189 }
7190 }
7191
7192 /* build ops for a bareword */
6154021b 7193 pl_yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpvn(PL_tokenbuf + 1,
9bde8eb0 7194 tokenbuf_len - 1));
6154021b 7195 pl_yylval.opval->op_private = OPpCONST_ENTERED;
9bde8eb0
NC
7196 gv_fetchpvn_flags(
7197 PL_tokenbuf + 1, tokenbuf_len - 1,
d6069db2
RGS
7198 /* If the identifier refers to a stash, don't autovivify it.
7199 * Change 24660 had the side effect of causing symbol table
7200 * hashes to always be defined, even if they were freshly
7201 * created and the only reference in the entire program was
7202 * the single statement with the defined %foo::bar:: test.
7203 * It appears that all code in the wild doing this actually
7204 * wants to know whether sub-packages have been loaded, so
7205 * by avoiding auto-vivifying symbol tables, we ensure that
7206 * defined %foo::bar:: continues to be false, and the existing
7207 * tests still give the expected answers, even though what
7208 * they're actually testing has now changed subtly.
7209 */
9bde8eb0
NC
7210 (*PL_tokenbuf == '%'
7211 && *(d = PL_tokenbuf + tokenbuf_len - 1) == ':'
7212 && d[-1] == ':'
d6069db2
RGS
7213 ? 0
7214 : PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : GV_ADD),
adc51b97
RGS
7215 ((PL_tokenbuf[0] == '$') ? SVt_PV
7216 : (PL_tokenbuf[0] == '@') ? SVt_PVAV
7217 : SVt_PVHV));
8eceec63
SC
7218 return WORD;
7219}
7220
4c3bbe0f
MHM
7221/*
7222 * The following code was generated by perl_keyword.pl.
7223 */
e2e1dd5a 7224
79072805 7225I32
5458a98a 7226Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
4c3bbe0f 7227{
952306ac 7228 dVAR;
7918f24d
NC
7229
7230 PERL_ARGS_ASSERT_KEYWORD;
7231
4c3bbe0f
MHM
7232 switch (len)
7233 {
7234 case 1: /* 5 tokens of length 1 */
7235 switch (name[0])
e2e1dd5a 7236 {
4c3bbe0f
MHM
7237 case 'm':
7238 { /* m */
7239 return KEY_m;
7240 }
7241
4c3bbe0f
MHM
7242 case 'q':
7243 { /* q */
7244 return KEY_q;
7245 }
7246
4c3bbe0f
MHM
7247 case 's':
7248 { /* s */
7249 return KEY_s;
7250 }
7251
4c3bbe0f
MHM
7252 case 'x':
7253 { /* x */
7254 return -KEY_x;
7255 }
7256
4c3bbe0f
MHM
7257 case 'y':
7258 { /* y */
7259 return KEY_y;
7260 }
7261
4c3bbe0f
MHM
7262 default:
7263 goto unknown;
e2e1dd5a 7264 }
4c3bbe0f
MHM
7265
7266 case 2: /* 18 tokens of length 2 */
7267 switch (name[0])
e2e1dd5a 7268 {
4c3bbe0f
MHM
7269 case 'd':
7270 if (name[1] == 'o')
7271 { /* do */
7272 return KEY_do;
7273 }
7274
7275 goto unknown;
7276
7277 case 'e':
7278 if (name[1] == 'q')
7279 { /* eq */
7280 return -KEY_eq;
7281 }
7282
7283 goto unknown;
7284
7285 case 'g':
7286 switch (name[1])
7287 {
7288 case 'e':
7289 { /* ge */
7290 return -KEY_ge;
7291 }
7292
4c3bbe0f
MHM
7293 case 't':
7294 { /* gt */
7295 return -KEY_gt;
7296 }
7297
4c3bbe0f
MHM
7298 default:
7299 goto unknown;
7300 }
7301
7302 case 'i':
7303 if (name[1] == 'f')
7304 { /* if */
7305 return KEY_if;
7306 }
7307
7308 goto unknown;
7309
7310 case 'l':
7311 switch (name[1])
7312 {
7313 case 'c':
7314 { /* lc */
7315 return -KEY_lc;
7316 }
7317
4c3bbe0f
MHM
7318 case 'e':
7319 { /* le */
7320 return -KEY_le;
7321 }
7322
4c3bbe0f
MHM
7323 case 't':
7324 { /* lt */
7325 return -KEY_lt;
7326 }
7327
4c3bbe0f
MHM
7328 default:
7329 goto unknown;
7330 }
7331
7332 case 'm':
7333 if (name[1] == 'y')
7334 { /* my */
7335 return KEY_my;
7336 }
7337
7338 goto unknown;
7339
7340 case 'n':
7341 switch (name[1])
7342 {
7343 case 'e':
7344 { /* ne */
7345 return -KEY_ne;
7346 }
7347
4c3bbe0f
MHM
7348 case 'o':
7349 { /* no */
7350 return KEY_no;
7351 }
7352
4c3bbe0f
MHM
7353 default:
7354 goto unknown;
7355 }
7356
7357 case 'o':
7358 if (name[1] == 'r')
7359 { /* or */
7360 return -KEY_or;
7361 }
7362
7363 goto unknown;
7364
7365 case 'q':
7366 switch (name[1])
7367 {
7368 case 'q':
7369 { /* qq */
7370 return KEY_qq;
7371 }
7372
4c3bbe0f
MHM
7373 case 'r':
7374 { /* qr */
7375 return KEY_qr;
7376 }
7377
4c3bbe0f
MHM
7378 case 'w':
7379 { /* qw */
7380 return KEY_qw;
7381 }
7382
4c3bbe0f
MHM
7383 case 'x':
7384 { /* qx */
7385 return KEY_qx;
7386 }
7387
4c3bbe0f
MHM
7388 default:
7389 goto unknown;
7390 }
7391
7392 case 't':
7393 if (name[1] == 'r')
7394 { /* tr */
7395 return KEY_tr;
7396 }
7397
7398 goto unknown;
7399
7400 case 'u':
7401 if (name[1] == 'c')
7402 { /* uc */
7403 return -KEY_uc;
7404 }
7405
7406 goto unknown;
7407
7408 default:
7409 goto unknown;
e2e1dd5a 7410 }
4c3bbe0f 7411
0d863452 7412 case 3: /* 29 tokens of length 3 */
4c3bbe0f 7413 switch (name[0])
e2e1dd5a 7414 {
4c3bbe0f
MHM
7415 case 'E':
7416 if (name[1] == 'N' &&
7417 name[2] == 'D')
7418 { /* END */
7419 return KEY_END;
7420 }
7421
7422 goto unknown;
7423
7424 case 'a':
7425 switch (name[1])
7426 {
7427 case 'b':
7428 if (name[2] == 's')
7429 { /* abs */
7430 return -KEY_abs;
7431 }
7432
7433 goto unknown;
7434
7435 case 'n':
7436 if (name[2] == 'd')
7437 { /* and */
7438 return -KEY_and;
7439 }
7440
7441 goto unknown;
7442
7443 default:
7444 goto unknown;
7445 }
7446
7447 case 'c':
7448 switch (name[1])
7449 {
7450 case 'h':
7451 if (name[2] == 'r')
7452 { /* chr */
7453 return -KEY_chr;
7454 }
7455
7456 goto unknown;
7457
7458 case 'm':
7459 if (name[2] == 'p')
7460 { /* cmp */
7461 return -KEY_cmp;
7462 }
7463
7464 goto unknown;
7465
7466 case 'o':
7467 if (name[2] == 's')
7468 { /* cos */
7469 return -KEY_cos;
7470 }
7471
7472 goto unknown;
7473
7474 default:
7475 goto unknown;
7476 }
7477
7478 case 'd':
7479 if (name[1] == 'i' &&
7480 name[2] == 'e')
7481 { /* die */
7482 return -KEY_die;
7483 }
7484
7485 goto unknown;
7486
7487 case 'e':
7488 switch (name[1])
7489 {
7490 case 'o':
7491 if (name[2] == 'f')
7492 { /* eof */
7493 return -KEY_eof;
7494 }
7495
7496 goto unknown;
7497
4c3bbe0f
MHM
7498 case 'x':
7499 if (name[2] == 'p')
7500 { /* exp */
7501 return -KEY_exp;
7502 }
7503
7504 goto unknown;
7505
7506 default:
7507 goto unknown;
7508 }
7509
7510 case 'f':
7511 if (name[1] == 'o' &&
7512 name[2] == 'r')
7513 { /* for */
7514 return KEY_for;
7515 }
7516
7517 goto unknown;
7518
7519 case 'h':
7520 if (name[1] == 'e' &&
7521 name[2] == 'x')
7522 { /* hex */
7523 return -KEY_hex;
7524 }
7525
7526 goto unknown;
7527
7528 case 'i':
7529 if (name[1] == 'n' &&
7530 name[2] == 't')
7531 { /* int */
7532 return -KEY_int;
7533 }
7534
7535 goto unknown;
7536
7537 case 'l':
7538 if (name[1] == 'o' &&
7539 name[2] == 'g')
7540 { /* log */
7541 return -KEY_log;
7542 }
7543
7544 goto unknown;
7545
7546 case 'm':
7547 if (name[1] == 'a' &&
7548 name[2] == 'p')
7549 { /* map */
7550 return KEY_map;
7551 }
7552
7553 goto unknown;
7554
7555 case 'n':
7556 if (name[1] == 'o' &&
7557 name[2] == 't')
7558 { /* not */
7559 return -KEY_not;
7560 }
7561
7562 goto unknown;
7563
7564 case 'o':
7565 switch (name[1])
7566 {
7567 case 'c':
7568 if (name[2] == 't')
7569 { /* oct */
7570 return -KEY_oct;
7571 }
7572
7573 goto unknown;
7574
7575 case 'r':
7576 if (name[2] == 'd')
7577 { /* ord */
7578 return -KEY_ord;
7579 }
7580
7581 goto unknown;
7582
7583 case 'u':
7584 if (name[2] == 'r')
7585 { /* our */
7586 return KEY_our;
7587 }
7588
7589 goto unknown;
7590
7591 default:
7592 goto unknown;
7593 }
7594
7595 case 'p':
7596 if (name[1] == 'o')
7597 {
7598 switch (name[2])
7599 {
7600 case 'p':
7601 { /* pop */
7602 return -KEY_pop;
7603 }
7604
4c3bbe0f
MHM
7605 case 's':
7606 { /* pos */
7607 return KEY_pos;
7608 }
7609
4c3bbe0f
MHM
7610 default:
7611 goto unknown;
7612 }
7613 }
7614
7615 goto unknown;
7616
7617 case 'r':
7618 if (name[1] == 'e' &&
7619 name[2] == 'f')
7620 { /* ref */
7621 return -KEY_ref;
7622 }
7623
7624 goto unknown;
7625
7626 case 's':
7627 switch (name[1])
7628 {
0d863452
RH
7629 case 'a':
7630 if (name[2] == 'y')
7631 { /* say */
e3e804c9 7632 return (all_keywords || FEATURE_IS_ENABLED("say") ? KEY_say : 0);
0d863452
RH
7633 }
7634
7635 goto unknown;
7636
4c3bbe0f
MHM
7637 case 'i':
7638 if (name[2] == 'n')
7639 { /* sin */
7640 return -KEY_sin;
7641 }
7642
7643 goto unknown;
7644
7645 case 'u':
7646 if (name[2] == 'b')
7647 { /* sub */
7648 return KEY_sub;
7649 }
7650
7651 goto unknown;
7652
7653 default:
7654 goto unknown;
7655 }
7656
7657 case 't':
7658 if (name[1] == 'i' &&
7659 name[2] == 'e')
7660 { /* tie */
7661 return KEY_tie;
7662 }
7663
7664 goto unknown;
7665
7666 case 'u':
7667 if (name[1] == 's' &&
7668 name[2] == 'e')
7669 { /* use */
7670 return KEY_use;
7671 }
7672
7673 goto unknown;
7674
7675 case 'v':
7676 if (name[1] == 'e' &&
7677 name[2] == 'c')
7678 { /* vec */
7679 return -KEY_vec;
7680 }
7681
7682 goto unknown;
7683
7684 case 'x':
7685 if (name[1] == 'o' &&
7686 name[2] == 'r')
7687 { /* xor */
7688 return -KEY_xor;
7689 }
7690
7691 goto unknown;
7692
7693 default:
7694 goto unknown;
e2e1dd5a 7695 }
4c3bbe0f 7696
0d863452 7697 case 4: /* 41 tokens of length 4 */
4c3bbe0f 7698 switch (name[0])
e2e1dd5a 7699 {
4c3bbe0f
MHM
7700 case 'C':
7701 if (name[1] == 'O' &&
7702 name[2] == 'R' &&
7703 name[3] == 'E')
7704 { /* CORE */
7705 return -KEY_CORE;
7706 }
7707
7708 goto unknown;
7709
7710 case 'I':
7711 if (name[1] == 'N' &&
7712 name[2] == 'I' &&
7713 name[3] == 'T')
7714 { /* INIT */
7715 return KEY_INIT;
7716 }
7717
7718 goto unknown;
7719
7720 case 'b':
7721 if (name[1] == 'i' &&
7722 name[2] == 'n' &&
7723 name[3] == 'd')
7724 { /* bind */
7725 return -KEY_bind;
7726 }
7727
7728 goto unknown;
7729
7730 case 'c':
7731 if (name[1] == 'h' &&
7732 name[2] == 'o' &&
7733 name[3] == 'p')
7734 { /* chop */
7735 return -KEY_chop;
7736 }
7737
7738 goto unknown;
7739
7740 case 'd':
7741 if (name[1] == 'u' &&
7742 name[2] == 'm' &&
7743 name[3] == 'p')
7744 { /* dump */
7745 return -KEY_dump;
7746 }
7747
7748 goto unknown;
7749
7750 case 'e':
7751 switch (name[1])
7752 {
7753 case 'a':
7754 if (name[2] == 'c' &&
7755 name[3] == 'h')
7756 { /* each */
7757 return -KEY_each;
7758 }
7759
7760 goto unknown;
7761
7762 case 'l':
7763 if (name[2] == 's' &&
7764 name[3] == 'e')
7765 { /* else */
7766 return KEY_else;
7767 }
7768
7769 goto unknown;
7770
7771 case 'v':
7772 if (name[2] == 'a' &&
7773 name[3] == 'l')
7774 { /* eval */
7775 return KEY_eval;
7776 }
7777
7778 goto unknown;
7779
7780 case 'x':
7781 switch (name[2])
7782 {
7783 case 'e':
7784 if (name[3] == 'c')
7785 { /* exec */
7786 return -KEY_exec;
7787 }
7788
7789 goto unknown;
7790
7791 case 'i':
7792 if (name[3] == 't')
7793 { /* exit */
7794 return -KEY_exit;
7795 }
7796
7797 goto unknown;
7798
7799 default:
7800 goto unknown;
7801 }
7802
7803 default:
7804 goto unknown;
7805 }
7806
7807 case 'f':
7808 if (name[1] == 'o' &&
7809 name[2] == 'r' &&
7810 name[3] == 'k')
7811 { /* fork */
7812 return -KEY_fork;
7813 }
7814
7815 goto unknown;
7816
7817 case 'g':
7818 switch (name[1])
7819 {
7820 case 'e':
7821 if (name[2] == 't' &&
7822 name[3] == 'c')
7823 { /* getc */
7824 return -KEY_getc;
7825 }
7826
7827 goto unknown;
7828
7829 case 'l':
7830 if (name[2] == 'o' &&
7831 name[3] == 'b')
7832 { /* glob */
7833 return KEY_glob;
7834 }
7835
7836 goto unknown;
7837
7838 case 'o':
7839 if (name[2] == 't' &&
7840 name[3] == 'o')
7841 { /* goto */
7842 return KEY_goto;
7843 }
7844
7845 goto unknown;
7846
7847 case 'r':
7848 if (name[2] == 'e' &&
7849 name[3] == 'p')
7850 { /* grep */
7851 return KEY_grep;
7852 }
7853
7854 goto unknown;
7855
7856 default:
7857 goto unknown;
7858 }
7859
7860 case 'j':
7861 if (name[1] == 'o' &&
7862 name[2] == 'i' &&
7863 name[3] == 'n')
7864 { /* join */
7865 return -KEY_join;
7866 }
7867
7868 goto unknown;
7869
7870 case 'k':
7871 switch (name[1])
7872 {
7873 case 'e':
7874 if (name[2] == 'y' &&
7875 name[3] == 's')
7876 { /* keys */
7877 return -KEY_keys;
7878 }
7879
7880 goto unknown;
7881
7882 case 'i':
7883 if (name[2] == 'l' &&
7884 name[3] == 'l')
7885 { /* kill */
7886 return -KEY_kill;
7887 }
7888
7889 goto unknown;
7890
7891 default:
7892 goto unknown;
7893 }
7894
7895 case 'l':
7896 switch (name[1])
7897 {
7898 case 'a':
7899 if (name[2] == 's' &&
7900 name[3] == 't')
7901 { /* last */
7902 return KEY_last;
7903 }
7904
7905 goto unknown;
7906
7907 case 'i':
7908 if (name[2] == 'n' &&
7909 name[3] == 'k')
7910 { /* link */
7911 return -KEY_link;
7912 }
7913
7914 goto unknown;
7915
7916 case 'o':
7917 if (name[2] == 'c' &&
7918 name[3] == 'k')
7919 { /* lock */
7920 return -KEY_lock;
7921 }
7922
7923 goto unknown;
7924
7925 default:
7926 goto unknown;
7927 }
7928
7929 case 'n':
7930 if (name[1] == 'e' &&
7931 name[2] == 'x' &&
7932 name[3] == 't')
7933 { /* next */
7934 return KEY_next;
7935 }
7936
7937 goto unknown;
7938
7939 case 'o':
7940 if (name[1] == 'p' &&
7941 name[2] == 'e' &&
7942 name[3] == 'n')
7943 { /* open */
7944 return -KEY_open;
7945 }
7946
7947 goto unknown;
7948
7949 case 'p':
7950 switch (name[1])
7951 {
7952 case 'a':
7953 if (name[2] == 'c' &&
7954 name[3] == 'k')
7955 { /* pack */
7956 return -KEY_pack;
7957 }
7958
7959 goto unknown;
7960
7961 case 'i':
7962 if (name[2] == 'p' &&
7963 name[3] == 'e')
7964 { /* pipe */
7965 return -KEY_pipe;
7966 }
7967
7968 goto unknown;
7969
7970 case 'u':
7971 if (name[2] == 's' &&
7972 name[3] == 'h')
7973 { /* push */
7974 return -KEY_push;
7975 }
7976
7977 goto unknown;
7978
7979 default:
7980 goto unknown;
7981 }
7982
7983 case 'r':
7984 switch (name[1])
7985 {
7986 case 'a':
7987 if (name[2] == 'n' &&
7988 name[3] == 'd')
7989 { /* rand */
7990 return -KEY_rand;
7991 }
7992
7993 goto unknown;
7994
7995 case 'e':
7996 switch (name[2])
7997 {
7998 case 'a':
7999 if (name[3] == 'd')
8000 { /* read */
8001 return -KEY_read;
8002 }
8003
8004 goto unknown;
8005
8006 case 'c':
8007 if (name[3] == 'v')
8008 { /* recv */
8009 return -KEY_recv;
8010 }
8011
8012 goto unknown;
8013
8014 case 'd':
8015 if (name[3] == 'o')
8016 { /* redo */
8017 return KEY_redo;
8018 }
8019
8020 goto unknown;
8021
8022 default:
8023 goto unknown;
8024 }
8025
8026 default:
8027 goto unknown;
8028 }
8029
8030 case 's':
8031 switch (name[1])
8032 {
8033 case 'e':
8034 switch (name[2])
8035 {
8036 case 'e':
8037 if (name[3] == 'k')
8038 { /* seek */
8039 return -KEY_seek;
8040 }
8041
8042 goto unknown;
8043
8044 case 'n':
8045 if (name[3] == 'd')
8046 { /* send */
8047 return -KEY_send;
8048 }
8049
8050 goto unknown;
8051
8052 default:
8053 goto unknown;
8054 }
8055
8056 case 'o':
8057 if (name[2] == 'r' &&
8058 name[3] == 't')
8059 { /* sort */
8060 return KEY_sort;
8061 }
8062
8063 goto unknown;
8064
8065 case 'q':
8066 if (name[2] == 'r' &&
8067 name[3] == 't')
8068 { /* sqrt */
8069 return -KEY_sqrt;
8070 }
8071
8072 goto unknown;
8073
8074 case 't':
8075 if (name[2] == 'a' &&
8076 name[3] == 't')
8077 { /* stat */
8078 return -KEY_stat;
8079 }
8080
8081 goto unknown;
8082
8083 default:
8084 goto unknown;
8085 }
8086
8087 case 't':
8088 switch (name[1])
8089 {
8090 case 'e':
8091 if (name[2] == 'l' &&
8092 name[3] == 'l')
8093 { /* tell */
8094 return -KEY_tell;
8095 }
8096
8097 goto unknown;
8098
8099 case 'i':
8100 switch (name[2])
8101 {
8102 case 'e':
8103 if (name[3] == 'd')
8104 { /* tied */
8105 return KEY_tied;
8106 }
8107
8108 goto unknown;
8109
8110 case 'm':
8111 if (name[3] == 'e')
8112 { /* time */
8113 return -KEY_time;
8114 }
8115
8116 goto unknown;
8117
8118 default:
8119 goto unknown;
8120 }
8121
8122 default:
8123 goto unknown;
8124 }
8125
8126 case 'w':
0d863452 8127 switch (name[1])
4c3bbe0f 8128 {
0d863452 8129 case 'a':
952306ac
RGS
8130 switch (name[2])
8131 {
8132 case 'i':
8133 if (name[3] == 't')
8134 { /* wait */
8135 return -KEY_wait;
8136 }
4c3bbe0f 8137
952306ac 8138 goto unknown;
4c3bbe0f 8139
952306ac
RGS
8140 case 'r':
8141 if (name[3] == 'n')
8142 { /* warn */
8143 return -KEY_warn;
8144 }
4c3bbe0f 8145
952306ac 8146 goto unknown;
4c3bbe0f 8147
952306ac
RGS
8148 default:
8149 goto unknown;
8150 }
0d863452
RH
8151
8152 case 'h':
8153 if (name[2] == 'e' &&
8154 name[3] == 'n')
8155 { /* when */
5458a98a 8156 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_when : 0);
952306ac 8157 }
4c3bbe0f 8158
952306ac 8159 goto unknown;
4c3bbe0f 8160
952306ac
RGS
8161 default:
8162 goto unknown;
8163 }
4c3bbe0f 8164
0d863452
RH
8165 default:
8166 goto unknown;
8167 }
8168
952306ac 8169 case 5: /* 39 tokens of length 5 */
4c3bbe0f 8170 switch (name[0])
e2e1dd5a 8171 {
4c3bbe0f
MHM
8172 case 'B':
8173 if (name[1] == 'E' &&
8174 name[2] == 'G' &&
8175 name[3] == 'I' &&
8176 name[4] == 'N')
8177 { /* BEGIN */
8178 return KEY_BEGIN;
8179 }
8180
8181 goto unknown;
8182
8183 case 'C':
8184 if (name[1] == 'H' &&
8185 name[2] == 'E' &&
8186 name[3] == 'C' &&
8187 name[4] == 'K')
8188 { /* CHECK */
8189 return KEY_CHECK;
8190 }
8191
8192 goto unknown;
8193
8194 case 'a':
8195 switch (name[1])
8196 {
8197 case 'l':
8198 if (name[2] == 'a' &&
8199 name[3] == 'r' &&
8200 name[4] == 'm')
8201 { /* alarm */
8202 return -KEY_alarm;
8203 }
8204
8205 goto unknown;
8206
8207 case 't':
8208 if (name[2] == 'a' &&
8209 name[3] == 'n' &&
8210 name[4] == '2')
8211 { /* atan2 */
8212 return -KEY_atan2;
8213 }
8214
8215 goto unknown;
8216
8217 default:
8218 goto unknown;
8219 }
8220
8221 case 'b':
0d863452
RH
8222 switch (name[1])
8223 {
8224 case 'l':
8225 if (name[2] == 'e' &&
952306ac
RGS
8226 name[3] == 's' &&
8227 name[4] == 's')
8228 { /* bless */
8229 return -KEY_bless;
8230 }
4c3bbe0f 8231
952306ac 8232 goto unknown;
4c3bbe0f 8233
0d863452
RH
8234 case 'r':
8235 if (name[2] == 'e' &&
8236 name[3] == 'a' &&
8237 name[4] == 'k')
8238 { /* break */
5458a98a 8239 return (all_keywords || FEATURE_IS_ENABLED("switch") ? -KEY_break : 0);
0d863452
RH
8240 }
8241
8242 goto unknown;
8243
8244 default:
8245 goto unknown;
8246 }
8247
4c3bbe0f
MHM
8248 case 'c':
8249 switch (name[1])
8250 {
8251 case 'h':
8252 switch (name[2])
8253 {
8254 case 'd':
8255 if (name[3] == 'i' &&
8256 name[4] == 'r')
8257 { /* chdir */
8258 return -KEY_chdir;
8259 }
8260
8261 goto unknown;
8262
8263 case 'm':
8264 if (name[3] == 'o' &&
8265 name[4] == 'd')
8266 { /* chmod */
8267 return -KEY_chmod;
8268 }
8269
8270 goto unknown;
8271
8272 case 'o':
8273 switch (name[3])
8274 {
8275 case 'm':
8276 if (name[4] == 'p')
8277 { /* chomp */
8278 return -KEY_chomp;
8279 }
8280
8281 goto unknown;
8282
8283 case 'w':
8284 if (name[4] == 'n')
8285 { /* chown */
8286 return -KEY_chown;
8287 }
8288
8289 goto unknown;
8290
8291 default:
8292 goto unknown;
8293 }
8294
8295 default:
8296 goto unknown;
8297 }
8298
8299 case 'l':
8300 if (name[2] == 'o' &&
8301 name[3] == 's' &&
8302 name[4] == 'e')
8303 { /* close */
8304 return -KEY_close;
8305 }
8306
8307 goto unknown;
8308
8309 case 'r':
8310 if (name[2] == 'y' &&
8311 name[3] == 'p' &&
8312 name[4] == 't')
8313 { /* crypt */
8314 return -KEY_crypt;
8315 }
8316
8317 goto unknown;
8318
8319 default:
8320 goto unknown;
8321 }
8322
8323 case 'e':
8324 if (name[1] == 'l' &&
8325 name[2] == 's' &&
8326 name[3] == 'i' &&
8327 name[4] == 'f')
8328 { /* elsif */
8329 return KEY_elsif;
8330 }
8331
8332 goto unknown;
8333
8334 case 'f':
8335 switch (name[1])
8336 {
8337 case 'c':
8338 if (name[2] == 'n' &&
8339 name[3] == 't' &&
8340 name[4] == 'l')
8341 { /* fcntl */
8342 return -KEY_fcntl;
8343 }
8344
8345 goto unknown;
8346
8347 case 'l':
8348 if (name[2] == 'o' &&
8349 name[3] == 'c' &&
8350 name[4] == 'k')
8351 { /* flock */
8352 return -KEY_flock;
8353 }
8354
8355 goto unknown;
8356
8357 default:
8358 goto unknown;
8359 }
8360
0d863452
RH
8361 case 'g':
8362 if (name[1] == 'i' &&
8363 name[2] == 'v' &&
8364 name[3] == 'e' &&
8365 name[4] == 'n')
8366 { /* given */
5458a98a 8367 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_given : 0);
0d863452
RH
8368 }
8369
8370 goto unknown;
8371
4c3bbe0f
MHM
8372 case 'i':
8373 switch (name[1])
8374 {
8375 case 'n':
8376 if (name[2] == 'd' &&
8377 name[3] == 'e' &&
8378 name[4] == 'x')
8379 { /* index */
8380 return -KEY_index;
8381 }
8382
8383 goto unknown;
8384
8385 case 'o':
8386 if (name[2] == 'c' &&
8387 name[3] == 't' &&
8388 name[4] == 'l')
8389 { /* ioctl */
8390 return -KEY_ioctl;
8391 }
8392
8393 goto unknown;
8394
8395 default:
8396 goto unknown;
8397 }
8398
8399 case 'l':
8400 switch (name[1])
8401 {
8402 case 'o':
8403 if (name[2] == 'c' &&
8404 name[3] == 'a' &&
8405 name[4] == 'l')
8406 { /* local */
8407 return KEY_local;
8408 }
8409
8410 goto unknown;
8411
8412 case 's':
8413 if (name[2] == 't' &&
8414 name[3] == 'a' &&
8415 name[4] == 't')
8416 { /* lstat */
8417 return -KEY_lstat;
8418 }
8419
8420 goto unknown;
8421
8422 default:
8423 goto unknown;
8424 }
8425
8426 case 'm':
8427 if (name[1] == 'k' &&
8428 name[2] == 'd' &&
8429 name[3] == 'i' &&
8430 name[4] == 'r')
8431 { /* mkdir */
8432 return -KEY_mkdir;
8433 }
8434
8435 goto unknown;
8436
8437 case 'p':
8438 if (name[1] == 'r' &&
8439 name[2] == 'i' &&
8440 name[3] == 'n' &&
8441 name[4] == 't')
8442 { /* print */
8443 return KEY_print;
8444 }
8445
8446 goto unknown;
8447
8448 case 'r':
8449 switch (name[1])
8450 {
8451 case 'e':
8452 if (name[2] == 's' &&
8453 name[3] == 'e' &&
8454 name[4] == 't')
8455 { /* reset */
8456 return -KEY_reset;
8457 }
8458
8459 goto unknown;
8460
8461 case 'm':
8462 if (name[2] == 'd' &&
8463 name[3] == 'i' &&
8464 name[4] == 'r')
8465 { /* rmdir */
8466 return -KEY_rmdir;
8467 }
8468
8469 goto unknown;
8470
8471 default:
8472 goto unknown;
8473 }
8474
8475 case 's':
8476 switch (name[1])
8477 {
8478 case 'e':
8479 if (name[2] == 'm' &&
8480 name[3] == 'o' &&
8481 name[4] == 'p')
8482 { /* semop */
8483 return -KEY_semop;
8484 }
8485
8486 goto unknown;
8487
8488 case 'h':
8489 if (name[2] == 'i' &&
8490 name[3] == 'f' &&
8491 name[4] == 't')
8492 { /* shift */
8493 return -KEY_shift;
8494 }
8495
8496 goto unknown;
8497
8498 case 'l':
8499 if (name[2] == 'e' &&
8500 name[3] == 'e' &&
8501 name[4] == 'p')
8502 { /* sleep */
8503 return -KEY_sleep;
8504 }
8505
8506 goto unknown;
8507
8508 case 'p':
8509 if (name[2] == 'l' &&
8510 name[3] == 'i' &&
8511 name[4] == 't')
8512 { /* split */
8513 return KEY_split;
8514 }
8515
8516 goto unknown;
8517
8518 case 'r':
8519 if (name[2] == 'a' &&
8520 name[3] == 'n' &&
8521 name[4] == 'd')
8522 { /* srand */
8523 return -KEY_srand;
8524 }
8525
8526 goto unknown;
8527
8528 case 't':
952306ac
RGS
8529 switch (name[2])
8530 {
8531 case 'a':
8532 if (name[3] == 't' &&
8533 name[4] == 'e')
8534 { /* state */
5458a98a 8535 return (all_keywords || FEATURE_IS_ENABLED("state") ? KEY_state : 0);
952306ac 8536 }
4c3bbe0f 8537
952306ac
RGS
8538 goto unknown;
8539
8540 case 'u':
8541 if (name[3] == 'd' &&
8542 name[4] == 'y')
8543 { /* study */
8544 return KEY_study;
8545 }
8546
8547 goto unknown;
8548
8549 default:
8550 goto unknown;
8551 }
4c3bbe0f
MHM
8552
8553 default:
8554 goto unknown;
8555 }
8556
8557 case 't':
8558 if (name[1] == 'i' &&
8559 name[2] == 'm' &&
8560 name[3] == 'e' &&
8561 name[4] == 's')
8562 { /* times */
8563 return -KEY_times;
8564 }
8565
8566 goto unknown;
8567
8568 case 'u':
8569 switch (name[1])
8570 {
8571 case 'm':
8572 if (name[2] == 'a' &&
8573 name[3] == 's' &&
8574 name[4] == 'k')
8575 { /* umask */
8576 return -KEY_umask;
8577 }
8578
8579 goto unknown;
8580
8581 case 'n':
8582 switch (name[2])
8583 {
8584 case 'd':
8585 if (name[3] == 'e' &&
8586 name[4] == 'f')
8587 { /* undef */
8588 return KEY_undef;
8589 }
8590
8591 goto unknown;
8592
8593 case 't':
8594 if (name[3] == 'i')
8595 {
8596 switch (name[4])
8597 {
8598 case 'e':
8599 { /* untie */
8600 return KEY_untie;
8601 }
8602
4c3bbe0f
MHM
8603 case 'l':
8604 { /* until */
8605 return KEY_until;
8606 }
8607
4c3bbe0f
MHM
8608 default:
8609 goto unknown;
8610 }
8611 }
8612
8613 goto unknown;
8614
8615 default:
8616 goto unknown;
8617 }
8618
8619 case 't':
8620 if (name[2] == 'i' &&
8621 name[3] == 'm' &&
8622 name[4] == 'e')
8623 { /* utime */
8624 return -KEY_utime;
8625 }
8626
8627 goto unknown;
8628
8629 default:
8630 goto unknown;
8631 }
8632
8633 case 'w':
8634 switch (name[1])
8635 {
8636 case 'h':
8637 if (name[2] == 'i' &&
8638 name[3] == 'l' &&
8639 name[4] == 'e')
8640 { /* while */
8641 return KEY_while;
8642 }
8643
8644 goto unknown;
8645
8646 case 'r':
8647 if (name[2] == 'i' &&
8648 name[3] == 't' &&
8649 name[4] == 'e')
8650 { /* write */
8651 return -KEY_write;
8652 }
8653
8654 goto unknown;
8655
8656 default:
8657 goto unknown;
8658 }
8659
8660 default:
8661 goto unknown;
e2e1dd5a 8662 }
4c3bbe0f
MHM
8663
8664 case 6: /* 33 tokens of length 6 */
8665 switch (name[0])
8666 {
8667 case 'a':
8668 if (name[1] == 'c' &&
8669 name[2] == 'c' &&
8670 name[3] == 'e' &&
8671 name[4] == 'p' &&
8672 name[5] == 't')
8673 { /* accept */
8674 return -KEY_accept;
8675 }
8676
8677 goto unknown;
8678
8679 case 'c':
8680 switch (name[1])
8681 {
8682 case 'a':
8683 if (name[2] == 'l' &&
8684 name[3] == 'l' &&
8685 name[4] == 'e' &&
8686 name[5] == 'r')
8687 { /* caller */
8688 return -KEY_caller;
8689 }
8690
8691 goto unknown;
8692
8693 case 'h':
8694 if (name[2] == 'r' &&
8695 name[3] == 'o' &&
8696 name[4] == 'o' &&
8697 name[5] == 't')
8698 { /* chroot */
8699 return -KEY_chroot;
8700 }
8701
8702 goto unknown;
8703
8704 default:
8705 goto unknown;
8706 }
8707
8708 case 'd':
8709 if (name[1] == 'e' &&
8710 name[2] == 'l' &&
8711 name[3] == 'e' &&
8712 name[4] == 't' &&
8713 name[5] == 'e')
8714 { /* delete */
8715 return KEY_delete;
8716 }
8717
8718 goto unknown;
8719
8720 case 'e':
8721 switch (name[1])
8722 {
8723 case 'l':
8724 if (name[2] == 's' &&
8725 name[3] == 'e' &&
8726 name[4] == 'i' &&
8727 name[5] == 'f')
8728 { /* elseif */
9b387841 8729 Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
4c3bbe0f
MHM
8730 }
8731
8732 goto unknown;
8733
8734 case 'x':
8735 if (name[2] == 'i' &&
8736 name[3] == 's' &&
8737 name[4] == 't' &&
8738 name[5] == 's')
8739 { /* exists */
8740 return KEY_exists;
8741 }
8742
8743 goto unknown;
8744
8745 default:
8746 goto unknown;
8747 }
8748
8749 case 'f':
8750 switch (name[1])
8751 {
8752 case 'i':
8753 if (name[2] == 'l' &&
8754 name[3] == 'e' &&
8755 name[4] == 'n' &&
8756 name[5] == 'o')
8757 { /* fileno */
8758 return -KEY_fileno;
8759 }
8760
8761 goto unknown;
8762
8763 case 'o':
8764 if (name[2] == 'r' &&
8765 name[3] == 'm' &&
8766 name[4] == 'a' &&
8767 name[5] == 't')
8768 { /* format */
8769 return KEY_format;
8770 }
8771
8772 goto unknown;
8773
8774 default:
8775 goto unknown;
8776 }
8777
8778 case 'g':
8779 if (name[1] == 'm' &&
8780 name[2] == 't' &&
8781 name[3] == 'i' &&
8782 name[4] == 'm' &&
8783 name[5] == 'e')
8784 { /* gmtime */
8785 return -KEY_gmtime;
8786 }
8787
8788 goto unknown;
8789
8790 case 'l':
8791 switch (name[1])
8792 {
8793 case 'e':
8794 if (name[2] == 'n' &&
8795 name[3] == 'g' &&
8796 name[4] == 't' &&
8797 name[5] == 'h')
8798 { /* length */
8799 return -KEY_length;
8800 }
8801
8802 goto unknown;
8803
8804 case 'i':
8805 if (name[2] == 's' &&
8806 name[3] == 't' &&
8807 name[4] == 'e' &&
8808 name[5] == 'n')
8809 { /* listen */
8810 return -KEY_listen;
8811 }
8812
8813 goto unknown;
8814
8815 default:
8816 goto unknown;
8817 }
8818
8819 case 'm':
8820 if (name[1] == 's' &&
8821 name[2] == 'g')
8822 {
8823 switch (name[3])
8824 {
8825 case 'c':
8826 if (name[4] == 't' &&
8827 name[5] == 'l')
8828 { /* msgctl */
8829 return -KEY_msgctl;
8830 }
8831
8832 goto unknown;
8833
8834 case 'g':
8835 if (name[4] == 'e' &&
8836 name[5] == 't')
8837 { /* msgget */
8838 return -KEY_msgget;
8839 }
8840
8841 goto unknown;
8842
8843 case 'r':
8844 if (name[4] == 'c' &&
8845 name[5] == 'v')
8846 { /* msgrcv */
8847 return -KEY_msgrcv;
8848 }
8849
8850 goto unknown;
8851
8852 case 's':
8853 if (name[4] == 'n' &&
8854 name[5] == 'd')
8855 { /* msgsnd */
8856 return -KEY_msgsnd;
8857 }
8858
8859 goto unknown;
8860
8861 default:
8862 goto unknown;
8863 }
8864 }
8865
8866 goto unknown;
8867
8868 case 'p':
8869 if (name[1] == 'r' &&
8870 name[2] == 'i' &&
8871 name[3] == 'n' &&
8872 name[4] == 't' &&
8873 name[5] == 'f')
8874 { /* printf */
8875 return KEY_printf;
8876 }
8877
8878 goto unknown;
8879
8880 case 'r':
8881 switch (name[1])
8882 {
8883 case 'e':
8884 switch (name[2])
8885 {
8886 case 'n':
8887 if (name[3] == 'a' &&
8888 name[4] == 'm' &&
8889 name[5] == 'e')
8890 { /* rename */
8891 return -KEY_rename;
8892 }
8893
8894 goto unknown;
8895
8896 case 't':
8897 if (name[3] == 'u' &&
8898 name[4] == 'r' &&
8899 name[5] == 'n')
8900 { /* return */
8901 return KEY_return;
8902 }
8903
8904 goto unknown;
8905
8906 default:
8907 goto unknown;
8908 }
8909
8910 case 'i':
8911 if (name[2] == 'n' &&
8912 name[3] == 'd' &&
8913 name[4] == 'e' &&
8914 name[5] == 'x')
8915 { /* rindex */
8916 return -KEY_rindex;
8917 }
8918
8919 goto unknown;
8920
8921 default:
8922 goto unknown;
8923 }
8924
8925 case 's':
8926 switch (name[1])
8927 {
8928 case 'c':
8929 if (name[2] == 'a' &&
8930 name[3] == 'l' &&
8931 name[4] == 'a' &&
8932 name[5] == 'r')
8933 { /* scalar */
8934 return KEY_scalar;
8935 }
8936
8937 goto unknown;
8938
8939 case 'e':
8940 switch (name[2])
8941 {
8942 case 'l':
8943 if (name[3] == 'e' &&
8944 name[4] == 'c' &&
8945 name[5] == 't')
8946 { /* select */
8947 return -KEY_select;
8948 }
8949
8950 goto unknown;
8951
8952 case 'm':
8953 switch (name[3])
8954 {
8955 case 'c':
8956 if (name[4] == 't' &&
8957 name[5] == 'l')
8958 { /* semctl */
8959 return -KEY_semctl;
8960 }
8961
8962 goto unknown;
8963
8964 case 'g':
8965 if (name[4] == 'e' &&
8966 name[5] == 't')
8967 { /* semget */
8968 return -KEY_semget;
8969 }
8970
8971 goto unknown;
8972
8973 default:
8974 goto unknown;
8975 }
8976
8977 default:
8978 goto unknown;
8979 }
8980
8981 case 'h':
8982 if (name[2] == 'm')
8983 {
8984 switch (name[3])
8985 {
8986 case 'c':
8987 if (name[4] == 't' &&
8988 name[5] == 'l')
8989 { /* shmctl */
8990 return -KEY_shmctl;
8991 }
8992
8993 goto unknown;
8994
8995 case 'g':
8996 if (name[4] == 'e' &&
8997 name[5] == 't')
8998 { /* shmget */
8999 return -KEY_shmget;
9000 }
9001
9002 goto unknown;
9003
9004 default:
9005 goto unknown;
9006 }
9007 }
9008
9009 goto unknown;
9010
9011 case 'o':
9012 if (name[2] == 'c' &&
9013 name[3] == 'k' &&
9014 name[4] == 'e' &&
9015 name[5] == 't')
9016 { /* socket */
9017 return -KEY_socket;
9018 }
9019
9020 goto unknown;
9021
9022 case 'p':
9023 if (name[2] == 'l' &&
9024 name[3] == 'i' &&
9025 name[4] == 'c' &&
9026 name[5] == 'e')
9027 { /* splice */
9028 return -KEY_splice;
9029 }
9030
9031 goto unknown;
9032
9033 case 'u':
9034 if (name[2] == 'b' &&
9035 name[3] == 's' &&
9036 name[4] == 't' &&
9037 name[5] == 'r')
9038 { /* substr */
9039 return -KEY_substr;
9040 }
9041
9042 goto unknown;
9043
9044 case 'y':
9045 if (name[2] == 's' &&
9046 name[3] == 't' &&
9047 name[4] == 'e' &&
9048 name[5] == 'm')
9049 { /* system */
9050 return -KEY_system;
9051 }
9052
9053 goto unknown;
9054
9055 default:
9056 goto unknown;
9057 }
9058
9059 case 'u':
9060 if (name[1] == 'n')
9061 {
9062 switch (name[2])
9063 {
9064 case 'l':
9065 switch (name[3])
9066 {
9067 case 'e':
9068 if (name[4] == 's' &&
9069 name[5] == 's')
9070 { /* unless */
9071 return KEY_unless;
9072 }
9073
9074 goto unknown;
9075
9076 case 'i':
9077 if (name[4] == 'n' &&
9078 name[5] == 'k')
9079 { /* unlink */
9080 return -KEY_unlink;
9081 }
9082
9083 goto unknown;
9084
9085 default:
9086 goto unknown;
9087 }
9088
9089 case 'p':
9090 if (name[3] == 'a' &&
9091 name[4] == 'c' &&
9092 name[5] == 'k')
9093 { /* unpack */
9094 return -KEY_unpack;
9095 }
9096
9097 goto unknown;
9098
9099 default:
9100 goto unknown;
9101 }
9102 }
9103
9104 goto unknown;
9105
9106 case 'v':
9107 if (name[1] == 'a' &&
9108 name[2] == 'l' &&
9109 name[3] == 'u' &&
9110 name[4] == 'e' &&
9111 name[5] == 's')
9112 { /* values */
9113 return -KEY_values;
9114 }
9115
9116 goto unknown;
9117
9118 default:
9119 goto unknown;
e2e1dd5a 9120 }
4c3bbe0f 9121
0d863452 9122 case 7: /* 29 tokens of length 7 */
4c3bbe0f
MHM
9123 switch (name[0])
9124 {
9125 case 'D':
9126 if (name[1] == 'E' &&
9127 name[2] == 'S' &&
9128 name[3] == 'T' &&
9129 name[4] == 'R' &&
9130 name[5] == 'O' &&
9131 name[6] == 'Y')
9132 { /* DESTROY */
9133 return KEY_DESTROY;
9134 }
9135
9136 goto unknown;
9137
9138 case '_':
9139 if (name[1] == '_' &&
9140 name[2] == 'E' &&
9141 name[3] == 'N' &&
9142 name[4] == 'D' &&
9143 name[5] == '_' &&
9144 name[6] == '_')
9145 { /* __END__ */
9146 return KEY___END__;
9147 }
9148
9149 goto unknown;
9150
9151 case 'b':
9152 if (name[1] == 'i' &&
9153 name[2] == 'n' &&
9154 name[3] == 'm' &&
9155 name[4] == 'o' &&
9156 name[5] == 'd' &&
9157 name[6] == 'e')
9158 { /* binmode */
9159 return -KEY_binmode;
9160 }
9161
9162 goto unknown;
9163
9164 case 'c':
9165 if (name[1] == 'o' &&
9166 name[2] == 'n' &&
9167 name[3] == 'n' &&
9168 name[4] == 'e' &&
9169 name[5] == 'c' &&
9170 name[6] == 't')
9171 { /* connect */
9172 return -KEY_connect;
9173 }
9174
9175 goto unknown;
9176
9177 case 'd':
9178 switch (name[1])
9179 {
9180 case 'b':
9181 if (name[2] == 'm' &&
9182 name[3] == 'o' &&
9183 name[4] == 'p' &&
9184 name[5] == 'e' &&
9185 name[6] == 'n')
9186 { /* dbmopen */
9187 return -KEY_dbmopen;
9188 }
9189
9190 goto unknown;
9191
9192 case 'e':
0d863452
RH
9193 if (name[2] == 'f')
9194 {
9195 switch (name[3])
9196 {
9197 case 'a':
9198 if (name[4] == 'u' &&
9199 name[5] == 'l' &&
9200 name[6] == 't')
9201 { /* default */
5458a98a 9202 return (all_keywords || FEATURE_IS_ENABLED("switch") ? KEY_default : 0);
0d863452
RH
9203 }
9204
9205 goto unknown;
9206
9207 case 'i':
9208 if (name[4] == 'n' &&
952306ac
RGS
9209 name[5] == 'e' &&
9210 name[6] == 'd')
9211 { /* defined */
9212 return KEY_defined;
9213 }
4c3bbe0f 9214
952306ac 9215 goto unknown;
4c3bbe0f 9216
952306ac
RGS
9217 default:
9218 goto unknown;
9219 }
0d863452
RH
9220 }
9221
9222 goto unknown;
9223
9224 default:
9225 goto unknown;
9226 }
4c3bbe0f
MHM
9227
9228 case 'f':
9229 if (name[1] == 'o' &&
9230 name[2] == 'r' &&
9231 name[3] == 'e' &&
9232 name[4] == 'a' &&
9233 name[5] == 'c' &&
9234 name[6] == 'h')
9235 { /* foreach */
9236 return KEY_foreach;
9237 }
9238
9239 goto unknown;
9240
9241 case 'g':
9242 if (name[1] == 'e' &&
9243 name[2] == 't' &&
9244 name[3] == 'p')
9245 {
9246 switch (name[4])
9247 {
9248 case 'g':
9249 if (name[5] == 'r' &&
9250 name[6] == 'p')
9251 { /* getpgrp */
9252 return -KEY_getpgrp;
9253 }
9254
9255 goto unknown;
9256
9257 case 'p':
9258 if (name[5] == 'i' &&
9259 name[6] == 'd')
9260 { /* getppid */
9261 return -KEY_getppid;
9262 }
9263
9264 goto unknown;
9265
9266 default:
9267 goto unknown;
9268 }
9269 }
9270
9271 goto unknown;
9272
9273 case 'l':
9274 if (name[1] == 'c' &&
9275 name[2] == 'f' &&
9276 name[3] == 'i' &&
9277 name[4] == 'r' &&
9278 name[5] == 's' &&
9279 name[6] == 't')
9280 { /* lcfirst */
9281 return -KEY_lcfirst;
9282 }
9283
9284 goto unknown;
9285
9286 case 'o':
9287 if (name[1] == 'p' &&
9288 name[2] == 'e' &&
9289 name[3] == 'n' &&
9290 name[4] == 'd' &&
9291 name[5] == 'i' &&
9292 name[6] == 'r')
9293 { /* opendir */
9294 return -KEY_opendir;
9295 }
9296
9297 goto unknown;
9298
9299 case 'p':
9300 if (name[1] == 'a' &&
9301 name[2] == 'c' &&
9302 name[3] == 'k' &&
9303 name[4] == 'a' &&
9304 name[5] == 'g' &&
9305 name[6] == 'e')
9306 { /* package */
9307 return KEY_package;
9308 }
9309
9310 goto unknown;
9311
9312 case 'r':
9313 if (name[1] == 'e')
9314 {
9315 switch (name[2])
9316 {
9317 case 'a':
9318 if (name[3] == 'd' &&
9319 name[4] == 'd' &&
9320 name[5] == 'i' &&
9321 name[6] == 'r')
9322 { /* readdir */
9323 return -KEY_readdir;
9324 }
9325
9326 goto unknown;
9327
9328 case 'q':
9329 if (name[3] == 'u' &&
9330 name[4] == 'i' &&
9331 name[5] == 'r' &&
9332 name[6] == 'e')
9333 { /* require */
9334 return KEY_require;
9335 }
9336
9337 goto unknown;
9338
9339 case 'v':
9340 if (name[3] == 'e' &&
9341 name[4] == 'r' &&
9342 name[5] == 's' &&
9343 name[6] == 'e')
9344 { /* reverse */
9345 return -KEY_reverse;
9346 }
9347
9348 goto unknown;
9349
9350 default:
9351 goto unknown;
9352 }
9353 }
9354
9355 goto unknown;
9356
9357 case 's':
9358 switch (name[1])
9359 {
9360 case 'e':
9361 switch (name[2])
9362 {
9363 case 'e':
9364 if (name[3] == 'k' &&
9365 name[4] == 'd' &&
9366 name[5] == 'i' &&
9367 name[6] == 'r')
9368 { /* seekdir */
9369 return -KEY_seekdir;
9370 }
9371
9372 goto unknown;
9373
9374 case 't':
9375 if (name[3] == 'p' &&
9376 name[4] == 'g' &&
9377 name[5] == 'r' &&
9378 name[6] == 'p')
9379 { /* setpgrp */
9380 return -KEY_setpgrp;
9381 }
9382
9383 goto unknown;
9384
9385 default:
9386 goto unknown;
9387 }
9388
9389 case 'h':
9390 if (name[2] == 'm' &&
9391 name[3] == 'r' &&
9392 name[4] == 'e' &&
9393 name[5] == 'a' &&
9394 name[6] == 'd')
9395 { /* shmread */
9396 return -KEY_shmread;
9397 }
9398
9399 goto unknown;
9400
9401 case 'p':
9402 if (name[2] == 'r' &&
9403 name[3] == 'i' &&
9404 name[4] == 'n' &&
9405 name[5] == 't' &&
9406 name[6] == 'f')
9407 { /* sprintf */
9408 return -KEY_sprintf;
9409 }
9410
9411 goto unknown;
9412
9413 case 'y':
9414 switch (name[2])
9415 {
9416 case 'm':
9417 if (name[3] == 'l' &&
9418 name[4] == 'i' &&
9419 name[5] == 'n' &&
9420 name[6] == 'k')
9421 { /* symlink */
9422 return -KEY_symlink;
9423 }
9424
9425 goto unknown;
9426
9427 case 's':
9428 switch (name[3])
9429 {
9430 case 'c':
9431 if (name[4] == 'a' &&
9432 name[5] == 'l' &&
9433 name[6] == 'l')
9434 { /* syscall */
9435 return -KEY_syscall;
9436 }
9437
9438 goto unknown;
9439
9440 case 'o':
9441 if (name[4] == 'p' &&
9442 name[5] == 'e' &&
9443 name[6] == 'n')
9444 { /* sysopen */
9445 return -KEY_sysopen;
9446 }
9447
9448 goto unknown;
9449
9450 case 'r':
9451 if (name[4] == 'e' &&
9452 name[5] == 'a' &&
9453 name[6] == 'd')
9454 { /* sysread */
9455 return -KEY_sysread;
9456 }
9457
9458 goto unknown;
9459
9460 case 's':
9461 if (name[4] == 'e' &&
9462 name[5] == 'e' &&
9463 name[6] == 'k')
9464 { /* sysseek */
9465 return -KEY_sysseek;
9466 }
9467
9468 goto unknown;
9469
9470 default:
9471 goto unknown;
9472 }
9473
9474 default:
9475 goto unknown;
9476 }
9477
9478 default:
9479 goto unknown;
9480 }
9481
9482 case 't':
9483 if (name[1] == 'e' &&
9484 name[2] == 'l' &&
9485 name[3] == 'l' &&
9486 name[4] == 'd' &&
9487 name[5] == 'i' &&
9488 name[6] == 'r')
9489 { /* telldir */
9490 return -KEY_telldir;
9491 }
9492
9493 goto unknown;
9494
9495 case 'u':
9496 switch (name[1])
9497 {
9498 case 'c':
9499 if (name[2] == 'f' &&
9500 name[3] == 'i' &&
9501 name[4] == 'r' &&
9502 name[5] == 's' &&
9503 name[6] == 't')
9504 { /* ucfirst */
9505 return -KEY_ucfirst;
9506 }
9507
9508 goto unknown;
9509
9510 case 'n':
9511 if (name[2] == 's' &&
9512 name[3] == 'h' &&
9513 name[4] == 'i' &&
9514 name[5] == 'f' &&
9515 name[6] == 't')
9516 { /* unshift */
9517 return -KEY_unshift;
9518 }
9519
9520 goto unknown;
9521
9522 default:
9523 goto unknown;
9524 }
9525
9526 case 'w':
9527 if (name[1] == 'a' &&
9528 name[2] == 'i' &&
9529 name[3] == 't' &&
9530 name[4] == 'p' &&
9531 name[5] == 'i' &&
9532 name[6] == 'd')
9533 { /* waitpid */
9534 return -KEY_waitpid;
9535 }
9536
9537 goto unknown;
9538
9539 default:
9540 goto unknown;
9541 }
9542
9543 case 8: /* 26 tokens of length 8 */
9544 switch (name[0])
9545 {
9546 case 'A':
9547 if (name[1] == 'U' &&
9548 name[2] == 'T' &&
9549 name[3] == 'O' &&
9550 name[4] == 'L' &&
9551 name[5] == 'O' &&
9552 name[6] == 'A' &&
9553 name[7] == 'D')
9554 { /* AUTOLOAD */
9555 return KEY_AUTOLOAD;
9556 }
9557
9558 goto unknown;
9559
9560 case '_':
9561 if (name[1] == '_')
9562 {
9563 switch (name[2])
9564 {
9565 case 'D':
9566 if (name[3] == 'A' &&
9567 name[4] == 'T' &&
9568 name[5] == 'A' &&
9569 name[6] == '_' &&
9570 name[7] == '_')
9571 { /* __DATA__ */
9572 return KEY___DATA__;
9573 }
9574
9575 goto unknown;
9576
9577 case 'F':
9578 if (name[3] == 'I' &&
9579 name[4] == 'L' &&
9580 name[5] == 'E' &&
9581 name[6] == '_' &&
9582 name[7] == '_')
9583 { /* __FILE__ */
9584 return -KEY___FILE__;
9585 }
9586
9587 goto unknown;
9588
9589 case 'L':
9590 if (name[3] == 'I' &&
9591 name[4] == 'N' &&
9592 name[5] == 'E' &&
9593 name[6] == '_' &&
9594 name[7] == '_')
9595 { /* __LINE__ */
9596 return -KEY___LINE__;
9597 }
9598
9599 goto unknown;
9600
9601 default:
9602 goto unknown;
9603 }
9604 }
9605
9606 goto unknown;
9607
9608 case 'c':
9609 switch (name[1])
9610 {
9611 case 'l':
9612 if (name[2] == 'o' &&
9613 name[3] == 's' &&
9614 name[4] == 'e' &&
9615 name[5] == 'd' &&
9616 name[6] == 'i' &&
9617 name[7] == 'r')
9618 { /* closedir */
9619 return -KEY_closedir;
9620 }
9621
9622 goto unknown;
9623
9624 case 'o':
9625 if (name[2] == 'n' &&
9626 name[3] == 't' &&
9627 name[4] == 'i' &&
9628 name[5] == 'n' &&
9629 name[6] == 'u' &&
9630 name[7] == 'e')
9631 { /* continue */
9632 return -KEY_continue;
9633 }
9634
9635 goto unknown;
9636
9637 default:
9638 goto unknown;
9639 }
9640
9641 case 'd':
9642 if (name[1] == 'b' &&
9643 name[2] == 'm' &&
9644 name[3] == 'c' &&
9645 name[4] == 'l' &&
9646 name[5] == 'o' &&
9647 name[6] == 's' &&
9648 name[7] == 'e')
9649 { /* dbmclose */
9650 return -KEY_dbmclose;
9651 }
9652
9653 goto unknown;
9654
9655 case 'e':
9656 if (name[1] == 'n' &&
9657 name[2] == 'd')
9658 {
9659 switch (name[3])
9660 {
9661 case 'g':
9662 if (name[4] == 'r' &&
9663 name[5] == 'e' &&
9664 name[6] == 'n' &&
9665 name[7] == 't')
9666 { /* endgrent */
9667 return -KEY_endgrent;
9668 }
9669
9670 goto unknown;
9671
9672 case 'p':
9673 if (name[4] == 'w' &&
9674 name[5] == 'e' &&
9675 name[6] == 'n' &&
9676 name[7] == 't')
9677 { /* endpwent */
9678 return -KEY_endpwent;
9679 }
9680
9681 goto unknown;
9682
9683 default:
9684 goto unknown;
9685 }
9686 }
9687
9688 goto unknown;
9689
9690 case 'f':
9691 if (name[1] == 'o' &&
9692 name[2] == 'r' &&
9693 name[3] == 'm' &&
9694 name[4] == 'l' &&
9695 name[5] == 'i' &&
9696 name[6] == 'n' &&
9697 name[7] == 'e')
9698 { /* formline */
9699 return -KEY_formline;
9700 }
9701
9702 goto unknown;
9703
9704 case 'g':
9705 if (name[1] == 'e' &&
9706 name[2] == 't')
9707 {
9708 switch (name[3])
9709 {
9710 case 'g':
9711 if (name[4] == 'r')
9712 {
9713 switch (name[5])
9714 {
9715 case 'e':
9716 if (name[6] == 'n' &&
9717 name[7] == 't')
9718 { /* getgrent */
9719 return -KEY_getgrent;
9720 }
9721
9722 goto unknown;
9723
9724 case 'g':
9725 if (name[6] == 'i' &&
9726 name[7] == 'd')
9727 { /* getgrgid */
9728 return -KEY_getgrgid;
9729 }
9730
9731 goto unknown;
9732
9733 case 'n':
9734 if (name[6] == 'a' &&
9735 name[7] == 'm')
9736 { /* getgrnam */
9737 return -KEY_getgrnam;
9738 }
9739
9740 goto unknown;
9741
9742 default:
9743 goto unknown;
9744 }
9745 }
9746
9747 goto unknown;
9748
9749 case 'l':
9750 if (name[4] == 'o' &&
9751 name[5] == 'g' &&
9752 name[6] == 'i' &&
9753 name[7] == 'n')
9754 { /* getlogin */
9755 return -KEY_getlogin;
9756 }
9757
9758 goto unknown;
9759
9760 case 'p':
9761 if (name[4] == 'w')
9762 {
9763 switch (name[5])
9764 {
9765 case 'e':
9766 if (name[6] == 'n' &&
9767 name[7] == 't')
9768 { /* getpwent */
9769 return -KEY_getpwent;
9770 }
9771
9772 goto unknown;
9773
9774 case 'n':
9775 if (name[6] == 'a' &&
9776 name[7] == 'm')
9777 { /* getpwnam */
9778 return -KEY_getpwnam;
9779 }
9780
9781 goto unknown;
9782
9783 case 'u':
9784 if (name[6] == 'i' &&
9785 name[7] == 'd')
9786 { /* getpwuid */
9787 return -KEY_getpwuid;
9788 }
9789
9790 goto unknown;
9791
9792 default:
9793 goto unknown;
9794 }
9795 }
9796
9797 goto unknown;
9798
9799 default:
9800 goto unknown;
9801 }
9802 }
9803
9804 goto unknown;
9805
9806 case 'r':
9807 if (name[1] == 'e' &&
9808 name[2] == 'a' &&
9809 name[3] == 'd')
9810 {
9811 switch (name[4])
9812 {
9813 case 'l':
9814 if (name[5] == 'i' &&
9815 name[6] == 'n')
9816 {
9817 switch (name[7])
9818 {
9819 case 'e':
9820 { /* readline */
9821 return -KEY_readline;
9822 }
9823
4c3bbe0f
MHM
9824 case 'k':
9825 { /* readlink */
9826 return -KEY_readlink;
9827 }
9828
4c3bbe0f
MHM
9829 default:
9830 goto unknown;
9831 }
9832 }
9833
9834 goto unknown;
9835
9836 case 'p':
9837 if (name[5] == 'i' &&
9838 name[6] == 'p' &&
9839 name[7] == 'e')
9840 { /* readpipe */
9841 return -KEY_readpipe;
9842 }
9843
9844 goto unknown;
9845
9846 default:
9847 goto unknown;
9848 }
9849 }
9850
9851 goto unknown;
9852
9853 case 's':
9854 switch (name[1])
9855 {
9856 case 'e':
9857 if (name[2] == 't')
9858 {
9859 switch (name[3])
9860 {
9861 case 'g':
9862 if (name[4] == 'r' &&
9863 name[5] == 'e' &&
9864 name[6] == 'n' &&
9865 name[7] == 't')
9866 { /* setgrent */
9867 return -KEY_setgrent;
9868 }
9869
9870 goto unknown;
9871
9872 case 'p':
9873 if (name[4] == 'w' &&
9874 name[5] == 'e' &&
9875 name[6] == 'n' &&
9876 name[7] == 't')
9877 { /* setpwent */
9878 return -KEY_setpwent;
9879 }
9880
9881 goto unknown;
9882
9883 default:
9884 goto unknown;
9885 }
9886 }
9887
9888 goto unknown;
9889
9890 case 'h':
9891 switch (name[2])
9892 {
9893 case 'm':
9894 if (name[3] == 'w' &&
9895 name[4] == 'r' &&
9896 name[5] == 'i' &&
9897 name[6] == 't' &&
9898 name[7] == 'e')
9899 { /* shmwrite */
9900 return -KEY_shmwrite;
9901 }
9902
9903 goto unknown;
9904
9905 case 'u':
9906 if (name[3] == 't' &&
9907 name[4] == 'd' &&
9908 name[5] == 'o' &&
9909 name[6] == 'w' &&
9910 name[7] == 'n')
9911 { /* shutdown */
9912 return -KEY_shutdown;
9913 }
9914
9915 goto unknown;
9916
9917 default:
9918 goto unknown;
9919 }
9920
9921 case 'y':
9922 if (name[2] == 's' &&
9923 name[3] == 'w' &&
9924 name[4] == 'r' &&
9925 name[5] == 'i' &&
9926 name[6] == 't' &&
9927 name[7] == 'e')
9928 { /* syswrite */
9929 return -KEY_syswrite;
9930 }
9931
9932 goto unknown;
9933
9934 default:
9935 goto unknown;
9936 }
9937
9938 case 't':
9939 if (name[1] == 'r' &&
9940 name[2] == 'u' &&
9941 name[3] == 'n' &&
9942 name[4] == 'c' &&
9943 name[5] == 'a' &&
9944 name[6] == 't' &&
9945 name[7] == 'e')
9946 { /* truncate */
9947 return -KEY_truncate;
9948 }
9949
9950 goto unknown;
9951
9952 default:
9953 goto unknown;
9954 }
9955
3c10abe3 9956 case 9: /* 9 tokens of length 9 */
4c3bbe0f
MHM
9957 switch (name[0])
9958 {
3c10abe3
AG
9959 case 'U':
9960 if (name[1] == 'N' &&
9961 name[2] == 'I' &&
9962 name[3] == 'T' &&
9963 name[4] == 'C' &&
9964 name[5] == 'H' &&
9965 name[6] == 'E' &&
9966 name[7] == 'C' &&
9967 name[8] == 'K')
9968 { /* UNITCHECK */
9969 return KEY_UNITCHECK;
9970 }
9971
9972 goto unknown;
9973
4c3bbe0f
MHM
9974 case 'e':
9975 if (name[1] == 'n' &&
9976 name[2] == 'd' &&
9977 name[3] == 'n' &&
9978 name[4] == 'e' &&
9979 name[5] == 't' &&
9980 name[6] == 'e' &&
9981 name[7] == 'n' &&
9982 name[8] == 't')
9983 { /* endnetent */
9984 return -KEY_endnetent;
9985 }
9986
9987 goto unknown;
9988
9989 case 'g':
9990 if (name[1] == 'e' &&
9991 name[2] == 't' &&
9992 name[3] == 'n' &&
9993 name[4] == 'e' &&
9994 name[5] == 't' &&
9995 name[6] == 'e' &&
9996 name[7] == 'n' &&
9997 name[8] == 't')
9998 { /* getnetent */
9999 return -KEY_getnetent;
10000 }
10001
10002 goto unknown;
10003
10004 case 'l':
10005 if (name[1] == 'o' &&
10006 name[2] == 'c' &&
10007 name[3] == 'a' &&
10008 name[4] == 'l' &&
10009 name[5] == 't' &&
10010 name[6] == 'i' &&
10011 name[7] == 'm' &&
10012 name[8] == 'e')
10013 { /* localtime */
10014 return -KEY_localtime;
10015 }
10016
10017 goto unknown;
10018
10019 case 'p':
10020 if (name[1] == 'r' &&
10021 name[2] == 'o' &&
10022 name[3] == 't' &&
10023 name[4] == 'o' &&
10024 name[5] == 't' &&
10025 name[6] == 'y' &&
10026 name[7] == 'p' &&
10027 name[8] == 'e')
10028 { /* prototype */
10029 return KEY_prototype;
10030 }
10031
10032 goto unknown;
10033
10034 case 'q':
10035 if (name[1] == 'u' &&
10036 name[2] == 'o' &&
10037 name[3] == 't' &&
10038 name[4] == 'e' &&
10039 name[5] == 'm' &&
10040 name[6] == 'e' &&
10041 name[7] == 't' &&
10042 name[8] == 'a')
10043 { /* quotemeta */
10044 return -KEY_quotemeta;
10045 }
10046
10047 goto unknown;
10048
10049 case 'r':
10050 if (name[1] == 'e' &&
10051 name[2] == 'w' &&
10052 name[3] == 'i' &&
10053 name[4] == 'n' &&
10054 name[5] == 'd' &&
10055 name[6] == 'd' &&
10056 name[7] == 'i' &&
10057 name[8] == 'r')
10058 { /* rewinddir */
10059 return -KEY_rewinddir;
10060 }
10061
10062 goto unknown;
10063
10064 case 's':
10065 if (name[1] == 'e' &&
10066 name[2] == 't' &&
10067 name[3] == 'n' &&
10068 name[4] == 'e' &&
10069 name[5] == 't' &&
10070 name[6] == 'e' &&
10071 name[7] == 'n' &&
10072 name[8] == 't')
10073 { /* setnetent */
10074 return -KEY_setnetent;
10075 }
10076
10077 goto unknown;
10078
10079 case 'w':
10080 if (name[1] == 'a' &&
10081 name[2] == 'n' &&
10082 name[3] == 't' &&
10083 name[4] == 'a' &&
10084 name[5] == 'r' &&
10085 name[6] == 'r' &&
10086 name[7] == 'a' &&
10087 name[8] == 'y')
10088 { /* wantarray */
10089 return -KEY_wantarray;
10090 }
10091
10092 goto unknown;
10093
10094 default:
10095 goto unknown;
10096 }
10097
10098 case 10: /* 9 tokens of length 10 */
10099 switch (name[0])
10100 {
10101 case 'e':
10102 if (name[1] == 'n' &&
10103 name[2] == 'd')
10104 {
10105 switch (name[3])
10106 {
10107 case 'h':
10108 if (name[4] == 'o' &&
10109 name[5] == 's' &&
10110 name[6] == 't' &&
10111 name[7] == 'e' &&
10112 name[8] == 'n' &&
10113 name[9] == 't')
10114 { /* endhostent */
10115 return -KEY_endhostent;
10116 }
10117
10118 goto unknown;
10119
10120 case 's':
10121 if (name[4] == 'e' &&
10122 name[5] == 'r' &&
10123 name[6] == 'v' &&
10124 name[7] == 'e' &&
10125 name[8] == 'n' &&
10126 name[9] == 't')
10127 { /* endservent */
10128 return -KEY_endservent;
10129 }
10130
10131 goto unknown;
10132
10133 default:
10134 goto unknown;
10135 }
10136 }
10137
10138 goto unknown;
10139
10140 case 'g':
10141 if (name[1] == 'e' &&
10142 name[2] == 't')
10143 {
10144 switch (name[3])
10145 {
10146 case 'h':
10147 if (name[4] == 'o' &&
10148 name[5] == 's' &&
10149 name[6] == 't' &&
10150 name[7] == 'e' &&
10151 name[8] == 'n' &&
10152 name[9] == 't')
10153 { /* gethostent */
10154 return -KEY_gethostent;
10155 }
10156
10157 goto unknown;
10158
10159 case 's':
10160 switch (name[4])
10161 {
10162 case 'e':
10163 if (name[5] == 'r' &&
10164 name[6] == 'v' &&
10165 name[7] == 'e' &&
10166 name[8] == 'n' &&
10167 name[9] == 't')
10168 { /* getservent */
10169 return -KEY_getservent;
10170 }
10171
10172 goto unknown;
10173
10174 case 'o':
10175 if (name[5] == 'c' &&
10176 name[6] == 'k' &&
10177 name[7] == 'o' &&
10178 name[8] == 'p' &&
10179 name[9] == 't')
10180 { /* getsockopt */
10181 return -KEY_getsockopt;
10182 }
10183
10184 goto unknown;
10185
10186 default:
10187 goto unknown;
10188 }
10189
10190 default:
10191 goto unknown;
10192 }
10193 }
10194
10195 goto unknown;
10196
10197 case 's':
10198 switch (name[1])
10199 {
10200 case 'e':
10201 if (name[2] == 't')
10202 {
10203 switch (name[3])
10204 {
10205 case 'h':
10206 if (name[4] == 'o' &&
10207 name[5] == 's' &&
10208 name[6] == 't' &&
10209 name[7] == 'e' &&
10210 name[8] == 'n' &&
10211 name[9] == 't')
10212 { /* sethostent */
10213 return -KEY_sethostent;
10214 }
10215
10216 goto unknown;
10217
10218 case 's':
10219 switch (name[4])
10220 {
10221 case 'e':
10222 if (name[5] == 'r' &&
10223 name[6] == 'v' &&
10224 name[7] == 'e' &&
10225 name[8] == 'n' &&
10226 name[9] == 't')
10227 { /* setservent */
10228 return -KEY_setservent;
10229 }
10230
10231 goto unknown;
10232
10233 case 'o':
10234 if (name[5] == 'c' &&
10235 name[6] == 'k' &&
10236 name[7] == 'o' &&
10237 name[8] == 'p' &&
10238 name[9] == 't')
10239 { /* setsockopt */
10240 return -KEY_setsockopt;
10241 }
10242
10243 goto unknown;
10244
10245 default:
10246 goto unknown;
10247 }
10248
10249 default:
10250 goto unknown;
10251 }
10252 }
10253
10254 goto unknown;
10255
10256 case 'o':
10257 if (name[2] == 'c' &&
10258 name[3] == 'k' &&
10259 name[4] == 'e' &&
10260 name[5] == 't' &&
10261 name[6] == 'p' &&
10262 name[7] == 'a' &&
10263 name[8] == 'i' &&
10264 name[9] == 'r')
10265 { /* socketpair */
10266 return -KEY_socketpair;
10267 }
10268
10269 goto unknown;
10270
10271 default:
10272 goto unknown;
10273 }
10274
10275 default:
10276 goto unknown;
e2e1dd5a 10277 }
4c3bbe0f
MHM
10278
10279 case 11: /* 8 tokens of length 11 */
10280 switch (name[0])
10281 {
10282 case '_':
10283 if (name[1] == '_' &&
10284 name[2] == 'P' &&
10285 name[3] == 'A' &&
10286 name[4] == 'C' &&
10287 name[5] == 'K' &&
10288 name[6] == 'A' &&
10289 name[7] == 'G' &&
10290 name[8] == 'E' &&
10291 name[9] == '_' &&
10292 name[10] == '_')
10293 { /* __PACKAGE__ */
10294 return -KEY___PACKAGE__;
10295 }
10296
10297 goto unknown;
10298
10299 case 'e':
10300 if (name[1] == 'n' &&
10301 name[2] == 'd' &&
10302 name[3] == 'p' &&
10303 name[4] == 'r' &&
10304 name[5] == 'o' &&
10305 name[6] == 't' &&
10306 name[7] == 'o' &&
10307 name[8] == 'e' &&
10308 name[9] == 'n' &&
10309 name[10] == 't')
10310 { /* endprotoent */
10311 return -KEY_endprotoent;
10312 }
10313
10314 goto unknown;
10315
10316 case 'g':
10317 if (name[1] == 'e' &&
10318 name[2] == 't')
10319 {
10320 switch (name[3])
10321 {
10322 case 'p':
10323 switch (name[4])
10324 {
10325 case 'e':
10326 if (name[5] == 'e' &&
10327 name[6] == 'r' &&
10328 name[7] == 'n' &&
10329 name[8] == 'a' &&
10330 name[9] == 'm' &&
10331 name[10] == 'e')
10332 { /* getpeername */
10333 return -KEY_getpeername;
10334 }
10335
10336 goto unknown;
10337
10338 case 'r':
10339 switch (name[5])
10340 {
10341 case 'i':
10342 if (name[6] == 'o' &&
10343 name[7] == 'r' &&
10344 name[8] == 'i' &&
10345 name[9] == 't' &&
10346 name[10] == 'y')
10347 { /* getpriority */
10348 return -KEY_getpriority;
10349 }
10350
10351 goto unknown;
10352
10353 case 'o':
10354 if (name[6] == 't' &&
10355 name[7] == 'o' &&
10356 name[8] == 'e' &&
10357 name[9] == 'n' &&
10358 name[10] == 't')
10359 { /* getprotoent */
10360 return -KEY_getprotoent;
10361 }
10362
10363 goto unknown;
10364
10365 default:
10366 goto unknown;
10367 }
10368
10369 default:
10370 goto unknown;
10371 }
10372
10373 case 's':
10374 if (name[4] == 'o' &&
10375 name[5] == 'c' &&
10376 name[6] == 'k' &&
10377 name[7] == 'n' &&
10378 name[8] == 'a' &&
10379 name[9] == 'm' &&
10380 name[10] == 'e')
10381 { /* getsockname */
10382 return -KEY_getsockname;
10383 }
10384
10385 goto unknown;
10386
10387 default:
10388 goto unknown;
10389 }
10390 }
10391
10392 goto unknown;
10393
10394 case 's':
10395 if (name[1] == 'e' &&
10396 name[2] == 't' &&
10397 name[3] == 'p' &&
10398 name[4] == 'r')
10399 {
10400 switch (name[5])
10401 {
10402 case 'i':
10403 if (name[6] == 'o' &&
10404 name[7] == 'r' &&
10405 name[8] == 'i' &&
10406 name[9] == 't' &&
10407 name[10] == 'y')
10408 { /* setpriority */
10409 return -KEY_setpriority;
10410 }
10411
10412 goto unknown;
10413
10414 case 'o':
10415 if (name[6] == 't' &&
10416 name[7] == 'o' &&
10417 name[8] == 'e' &&
10418 name[9] == 'n' &&
10419 name[10] == 't')
10420 { /* setprotoent */
10421 return -KEY_setprotoent;
10422 }
10423
10424 goto unknown;
10425
10426 default:
10427 goto unknown;
10428 }
10429 }
10430
10431 goto unknown;
10432
10433 default:
10434 goto unknown;
e2e1dd5a 10435 }
4c3bbe0f
MHM
10436
10437 case 12: /* 2 tokens of length 12 */
10438 if (name[0] == 'g' &&
10439 name[1] == 'e' &&
10440 name[2] == 't' &&
10441 name[3] == 'n' &&
10442 name[4] == 'e' &&
10443 name[5] == 't' &&
10444 name[6] == 'b' &&
10445 name[7] == 'y')
10446 {
10447 switch (name[8])
10448 {
10449 case 'a':
10450 if (name[9] == 'd' &&
10451 name[10] == 'd' &&
10452 name[11] == 'r')
10453 { /* getnetbyaddr */
10454 return -KEY_getnetbyaddr;
10455 }
10456
10457 goto unknown;
10458
10459 case 'n':
10460 if (name[9] == 'a' &&
10461 name[10] == 'm' &&
10462 name[11] == 'e')
10463 { /* getnetbyname */
10464 return -KEY_getnetbyname;
10465 }
10466
10467 goto unknown;
10468
10469 default:
10470 goto unknown;
10471 }
e2e1dd5a 10472 }
4c3bbe0f
MHM
10473
10474 goto unknown;
10475
10476 case 13: /* 4 tokens of length 13 */
10477 if (name[0] == 'g' &&
10478 name[1] == 'e' &&
10479 name[2] == 't')
10480 {
10481 switch (name[3])
10482 {
10483 case 'h':
10484 if (name[4] == 'o' &&
10485 name[5] == 's' &&
10486 name[6] == 't' &&
10487 name[7] == 'b' &&
10488 name[8] == 'y')
10489 {
10490 switch (name[9])
10491 {
10492 case 'a':
10493 if (name[10] == 'd' &&
10494 name[11] == 'd' &&
10495 name[12] == 'r')
10496 { /* gethostbyaddr */
10497 return -KEY_gethostbyaddr;
10498 }
10499
10500 goto unknown;
10501
10502 case 'n':
10503 if (name[10] == 'a' &&
10504 name[11] == 'm' &&
10505 name[12] == 'e')
10506 { /* gethostbyname */
10507 return -KEY_gethostbyname;
10508 }
10509
10510 goto unknown;
10511
10512 default:
10513 goto unknown;
10514 }
10515 }
10516
10517 goto unknown;
10518
10519 case 's':
10520 if (name[4] == 'e' &&
10521 name[5] == 'r' &&
10522 name[6] == 'v' &&
10523 name[7] == 'b' &&
10524 name[8] == 'y')
10525 {
10526 switch (name[9])
10527 {
10528 case 'n':
10529 if (name[10] == 'a' &&
10530 name[11] == 'm' &&
10531 name[12] == 'e')
10532 { /* getservbyname */
10533 return -KEY_getservbyname;
10534 }
10535
10536 goto unknown;
10537
10538 case 'p':
10539 if (name[10] == 'o' &&
10540 name[11] == 'r' &&
10541 name[12] == 't')
10542 { /* getservbyport */
10543 return -KEY_getservbyport;
10544 }
10545
10546 goto unknown;
10547
10548 default:
10549 goto unknown;
10550 }
10551 }
10552
10553 goto unknown;
10554
10555 default:
10556 goto unknown;
10557 }
e2e1dd5a 10558 }
4c3bbe0f
MHM
10559
10560 goto unknown;
10561
10562 case 14: /* 1 tokens of length 14 */
10563 if (name[0] == 'g' &&
10564 name[1] == 'e' &&
10565 name[2] == 't' &&
10566 name[3] == 'p' &&
10567 name[4] == 'r' &&
10568 name[5] == 'o' &&
10569 name[6] == 't' &&
10570 name[7] == 'o' &&
10571 name[8] == 'b' &&
10572 name[9] == 'y' &&
10573 name[10] == 'n' &&
10574 name[11] == 'a' &&
10575 name[12] == 'm' &&
10576 name[13] == 'e')
10577 { /* getprotobyname */
10578 return -KEY_getprotobyname;
10579 }
10580
10581 goto unknown;
10582
10583 case 16: /* 1 tokens of length 16 */
10584 if (name[0] == 'g' &&
10585 name[1] == 'e' &&
10586 name[2] == 't' &&
10587 name[3] == 'p' &&
10588 name[4] == 'r' &&
10589 name[5] == 'o' &&
10590 name[6] == 't' &&
10591 name[7] == 'o' &&
10592 name[8] == 'b' &&
10593 name[9] == 'y' &&
10594 name[10] == 'n' &&
10595 name[11] == 'u' &&
10596 name[12] == 'm' &&
10597 name[13] == 'b' &&
10598 name[14] == 'e' &&
10599 name[15] == 'r')
10600 { /* getprotobynumber */
10601 return -KEY_getprotobynumber;
10602 }
10603
10604 goto unknown;
10605
10606 default:
10607 goto unknown;
e2e1dd5a 10608 }
4c3bbe0f
MHM
10609
10610unknown:
e2e1dd5a 10611 return 0;
a687059c
LW
10612}
10613
76e3520e 10614STATIC void
c94115d8 10615S_checkcomma(pTHX_ const char *s, const char *name, const char *what)
a687059c 10616{
97aff369 10617 dVAR;
2f3197b3 10618
7918f24d
NC
10619 PERL_ARGS_ASSERT_CHECKCOMMA;
10620
d008e5eb 10621 if (*s == ' ' && s[1] == '(') { /* XXX gotta be a better way */
d008e5eb
GS
10622 if (ckWARN(WARN_SYNTAX)) {
10623 int level = 1;
26ff0806 10624 const char *w;
d008e5eb
GS
10625 for (w = s+2; *w && level; w++) {
10626 if (*w == '(')
10627 ++level;
10628 else if (*w == ')')
10629 --level;
10630 }
888fea98
NC
10631 while (isSPACE(*w))
10632 ++w;
b1439985
RGS
10633 /* the list of chars below is for end of statements or
10634 * block / parens, boolean operators (&&, ||, //) and branch
10635 * constructs (or, and, if, until, unless, while, err, for).
10636 * Not a very solid hack... */
10637 if (!*w || !strchr(";&/|})]oaiuwef!=", *w))
9014280d 10638 Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
65cec589 10639 "%s (...) interpreted as function",name);
d008e5eb 10640 }
2f3197b3 10641 }
3280af22 10642 while (s < PL_bufend && isSPACE(*s))
2f3197b3 10643 s++;
a687059c
LW
10644 if (*s == '(')
10645 s++;
3280af22 10646 while (s < PL_bufend && isSPACE(*s))
a687059c 10647 s++;
7e2040f0 10648 if (isIDFIRST_lazy_if(s,UTF)) {
26ff0806 10649 const char * const w = s++;
7e2040f0 10650 while (isALNUM_lazy_if(s,UTF))
a687059c 10651 s++;
3280af22 10652 while (s < PL_bufend && isSPACE(*s))
a687059c 10653 s++;
e929a76b 10654 if (*s == ',') {
c94115d8 10655 GV* gv;
5458a98a 10656 if (keyword(w, s - w, 0))
e929a76b 10657 return;
c94115d8
NC
10658
10659 gv = gv_fetchpvn_flags(w, s - w, 0, SVt_PVCV);
10660 if (gv && GvCVu(gv))
abbb3198 10661 return;
cea2e8a9 10662 Perl_croak(aTHX_ "No comma allowed after %s", what);
463ee0b2
LW
10663 }
10664 }
10665}
10666
423cee85
JH
10667/* Either returns sv, or mortalizes sv and returns a new SV*.
10668 Best used as sv=new_constant(..., sv, ...).
10669 If s, pv are NULL, calls subroutine with one argument,
10670 and type is used with error messages only. */
10671
b3ac6de7 10672STATIC SV *
eb0d8d16
NC
10673S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, STRLEN keylen,
10674 SV *sv, SV *pv, const char *type, STRLEN typelen)
b3ac6de7 10675{
27da23d5 10676 dVAR; dSP;
890ce7af 10677 HV * const table = GvHV(PL_hintgv); /* ^H */
b3ac6de7 10678 SV *res;
b3ac6de7
IZ
10679 SV **cvp;
10680 SV *cv, *typesv;
89e33a05 10681 const char *why1 = "", *why2 = "", *why3 = "";
4e553d73 10682
7918f24d
NC
10683 PERL_ARGS_ASSERT_NEW_CONSTANT;
10684
f0af216f 10685 if (!table || !(PL_hints & HINT_LOCALIZE_HH)) {
423cee85
JH
10686 SV *msg;
10687
10edeb5d
JH
10688 why2 = (const char *)
10689 (strEQ(key,"charnames")
10690 ? "(possibly a missing \"use charnames ...\")"
10691 : "");
4e553d73 10692 msg = Perl_newSVpvf(aTHX_ "Constant(%s) unknown: %s",
41ab332f
JH
10693 (type ? type: "undef"), why2);
10694
10695 /* This is convoluted and evil ("goto considered harmful")
10696 * but I do not understand the intricacies of all the different
10697 * failure modes of %^H in here. The goal here is to make
10698 * the most probable error message user-friendly. --jhi */
10699
10700 goto msgdone;
10701
423cee85 10702 report:
4e553d73 10703 msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s",
f0af216f 10704 (type ? type: "undef"), why1, why2, why3);
41ab332f 10705 msgdone:
95a20fc0 10706 yyerror(SvPVX_const(msg));
423cee85
JH
10707 SvREFCNT_dec(msg);
10708 return sv;
10709 }
eb0d8d16 10710 cvp = hv_fetch(table, key, keylen, FALSE);
b3ac6de7 10711 if (!cvp || !SvOK(*cvp)) {
423cee85
JH
10712 why1 = "$^H{";
10713 why2 = key;
f0af216f 10714 why3 = "} is not defined";
423cee85 10715 goto report;
b3ac6de7
IZ
10716 }
10717 sv_2mortal(sv); /* Parent created it permanently */
10718 cv = *cvp;
423cee85 10719 if (!pv && s)
59cd0e26 10720 pv = newSVpvn_flags(s, len, SVs_TEMP);
423cee85 10721 if (type && pv)
59cd0e26 10722 typesv = newSVpvn_flags(type, typelen, SVs_TEMP);
b3ac6de7 10723 else
423cee85 10724 typesv = &PL_sv_undef;
4e553d73 10725
e788e7d3 10726 PUSHSTACKi(PERLSI_OVERLOAD);
423cee85
JH
10727 ENTER ;
10728 SAVETMPS;
4e553d73 10729
423cee85 10730 PUSHMARK(SP) ;
a5845cb7 10731 EXTEND(sp, 3);
423cee85
JH
10732 if (pv)
10733 PUSHs(pv);
b3ac6de7 10734 PUSHs(sv);
423cee85
JH
10735 if (pv)
10736 PUSHs(typesv);
b3ac6de7 10737 PUTBACK;
423cee85 10738 call_sv(cv, G_SCALAR | ( PL_in_eval ? 0 : G_EVAL));
4e553d73 10739
423cee85 10740 SPAGAIN ;
4e553d73 10741
423cee85 10742 /* Check the eval first */
9b0e499b 10743 if (!PL_in_eval && SvTRUE(ERRSV)) {
396482e1 10744 sv_catpvs(ERRSV, "Propagated");
8b6b16e7 10745 yyerror(SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
e1f15930 10746 (void)POPs;
b37c2d43 10747 res = SvREFCNT_inc_simple(sv);
423cee85
JH
10748 }
10749 else {
10750 res = POPs;
b37c2d43 10751 SvREFCNT_inc_simple_void(res);
423cee85 10752 }
4e553d73 10753
423cee85
JH
10754 PUTBACK ;
10755 FREETMPS ;
10756 LEAVE ;
b3ac6de7 10757 POPSTACK;
4e553d73 10758
b3ac6de7 10759 if (!SvOK(res)) {
423cee85
JH
10760 why1 = "Call to &{$^H{";
10761 why2 = key;
f0af216f 10762 why3 = "}} did not return a defined value";
423cee85
JH
10763 sv = res;
10764 goto report;
9b0e499b 10765 }
423cee85 10766
9b0e499b 10767 return res;
b3ac6de7 10768}
4e553d73 10769
d0a148a6
NC
10770/* Returns a NUL terminated string, with the length of the string written to
10771 *slp
10772 */
76e3520e 10773STATIC char *
cea2e8a9 10774S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_package, STRLEN *slp)
463ee0b2 10775{
97aff369 10776 dVAR;
463ee0b2 10777 register char *d = dest;
890ce7af 10778 register char * const e = d + destlen - 3; /* two-character token, ending NUL */
7918f24d
NC
10779
10780 PERL_ARGS_ASSERT_SCAN_WORD;
10781
463ee0b2 10782 for (;;) {
8903cb82 10783 if (d >= e)
cea2e8a9 10784 Perl_croak(aTHX_ ident_too_long);
834a4ddd 10785 if (isALNUM(*s)) /* UTF handled below */
463ee0b2 10786 *d++ = *s++;
c35e046a 10787 else if (allow_package && (*s == '\'') && isIDFIRST_lazy_if(s+1,UTF)) {
463ee0b2
LW
10788 *d++ = ':';
10789 *d++ = ':';
10790 s++;
10791 }
c35e046a 10792 else if (allow_package && (s[0] == ':') && (s[1] == ':') && (s[2] != '$')) {
463ee0b2
LW
10793 *d++ = *s++;
10794 *d++ = *s++;
10795 }
fd400ab9 10796 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
a0ed51b3 10797 char *t = s + UTF8SKIP(s);
c35e046a 10798 size_t len;
fd400ab9 10799 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
a0ed51b3 10800 t += UTF8SKIP(t);
c35e046a
AL
10801 len = t - s;
10802 if (d + len > e)
cea2e8a9 10803 Perl_croak(aTHX_ ident_too_long);
c35e046a
AL
10804 Copy(s, d, len, char);
10805 d += len;
a0ed51b3
LW
10806 s = t;
10807 }
463ee0b2
LW
10808 else {
10809 *d = '\0';
10810 *slp = d - dest;
10811 return s;
e929a76b 10812 }
378cc40b
LW
10813 }
10814}
10815
76e3520e 10816STATIC char *
f54cb97a 10817S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
378cc40b 10818{
97aff369 10819 dVAR;
6136c704 10820 char *bracket = NULL;
748a9306 10821 char funny = *s++;
6136c704
AL
10822 register char *d = dest;
10823 register char * const e = d + destlen + 3; /* two-character token, ending NUL */
378cc40b 10824
7918f24d
NC
10825 PERL_ARGS_ASSERT_SCAN_IDENT;
10826
a0d0e21e 10827 if (isSPACE(*s))
29595ff2 10828 s = PEEKSPACE(s);
de3bb511 10829 if (isDIGIT(*s)) {
8903cb82 10830 while (isDIGIT(*s)) {
10831 if (d >= e)
cea2e8a9 10832 Perl_croak(aTHX_ ident_too_long);
378cc40b 10833 *d++ = *s++;
8903cb82 10834 }
378cc40b
LW
10835 }
10836 else {
463ee0b2 10837 for (;;) {
8903cb82 10838 if (d >= e)
cea2e8a9 10839 Perl_croak(aTHX_ ident_too_long);
834a4ddd 10840 if (isALNUM(*s)) /* UTF handled below */
463ee0b2 10841 *d++ = *s++;
7e2040f0 10842 else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
463ee0b2
LW
10843 *d++ = ':';
10844 *d++ = ':';
10845 s++;
10846 }
a0d0e21e 10847 else if (*s == ':' && s[1] == ':') {
463ee0b2
LW
10848 *d++ = *s++;
10849 *d++ = *s++;
10850 }
fd400ab9 10851 else if (UTF && UTF8_IS_START(*s) && isALNUM_utf8((U8*)s)) {
a0ed51b3 10852 char *t = s + UTF8SKIP(s);
fd400ab9 10853 while (UTF8_IS_CONTINUED(*t) && is_utf8_mark((U8*)t))
a0ed51b3
LW
10854 t += UTF8SKIP(t);
10855 if (d + (t - s) > e)
cea2e8a9 10856 Perl_croak(aTHX_ ident_too_long);
a0ed51b3
LW
10857 Copy(s, d, t - s, char);
10858 d += t - s;
10859 s = t;
10860 }
463ee0b2
LW
10861 else
10862 break;
10863 }
378cc40b
LW
10864 }
10865 *d = '\0';
10866 d = dest;
79072805 10867 if (*d) {
3280af22
NIS
10868 if (PL_lex_state != LEX_NORMAL)
10869 PL_lex_state = LEX_INTERPENDMAYBE;
79072805 10870 return s;
378cc40b 10871 }
748a9306 10872 if (*s == '$' && s[1] &&
3792a11b 10873 (isALNUM_lazy_if(s+1,UTF) || s[1] == '$' || s[1] == '{' || strnEQ(s+1,"::",2)) )
5cd24f17 10874 {
4810e5ec 10875 return s;
5cd24f17 10876 }
79072805
LW
10877 if (*s == '{') {
10878 bracket = s;
10879 s++;
10880 }
10881 else if (ck_uni)
10882 check_uni();
93a17b20 10883 if (s < send)
79072805
LW
10884 *d = *s++;
10885 d[1] = '\0';
2b92dfce 10886 if (*d == '^' && *s && isCONTROLVAR(*s)) {
bbce6d69 10887 *d = toCTRL(*s);
10888 s++;
de3bb511 10889 }
79072805 10890 if (bracket) {
748a9306 10891 if (isSPACE(s[-1])) {
fa83b5b6 10892 while (s < send) {
f54cb97a 10893 const char ch = *s++;
bf4acbe4 10894 if (!SPACE_OR_TAB(ch)) {
fa83b5b6 10895 *d = ch;
10896 break;
10897 }
10898 }
748a9306 10899 }
7e2040f0 10900 if (isIDFIRST_lazy_if(d,UTF)) {
79072805 10901 d++;
a0ed51b3 10902 if (UTF) {
6136c704
AL
10903 char *end = s;
10904 while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
10905 end += UTF8SKIP(end);
10906 while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
10907 end += UTF8SKIP(end);
a0ed51b3 10908 }
6136c704
AL
10909 Copy(s, d, end - s, char);
10910 d += end - s;
10911 s = end;
a0ed51b3
LW
10912 }
10913 else {
2b92dfce 10914 while ((isALNUM(*s) || *s == ':') && d < e)
a0ed51b3 10915 *d++ = *s++;
2b92dfce 10916 if (d >= e)
cea2e8a9 10917 Perl_croak(aTHX_ ident_too_long);
a0ed51b3 10918 }
79072805 10919 *d = '\0';
c35e046a
AL
10920 while (s < send && SPACE_OR_TAB(*s))
10921 s++;
ff68c719 10922 if ((*s == '[' || (*s == '{' && strNE(dest, "sub")))) {
5458a98a 10923 if (ckWARN(WARN_AMBIGUOUS) && keyword(dest, d - dest, 0)) {
10edeb5d
JH
10924 const char * const brack =
10925 (const char *)
10926 ((*s == '[') ? "[...]" : "{...}");
9014280d 10927 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
599cee73 10928 "Ambiguous use of %c{%s%s} resolved to %c%s%s",
748a9306
LW
10929 funny, dest, brack, funny, dest, brack);
10930 }
79072805 10931 bracket++;
a0be28da 10932 PL_lex_brackstack[PL_lex_brackets++] = (char)(XOPERATOR | XFAKEBRACK);
79072805
LW
10933 return s;
10934 }
4e553d73
NIS
10935 }
10936 /* Handle extended ${^Foo} variables
2b92dfce
GS
10937 * 1999-02-27 mjd-perl-patch@plover.com */
10938 else if (!isALNUM(*d) && !isPRINT(*d) /* isCTRL(d) */
10939 && isALNUM(*s))
10940 {
10941 d++;
10942 while (isALNUM(*s) && d < e) {
10943 *d++ = *s++;
10944 }
10945 if (d >= e)
cea2e8a9 10946 Perl_croak(aTHX_ ident_too_long);
2b92dfce 10947 *d = '\0';
79072805
LW
10948 }
10949 if (*s == '}') {
10950 s++;
7df0d042 10951 if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets) {
3280af22 10952 PL_lex_state = LEX_INTERPEND;
7df0d042
AE
10953 PL_expect = XREF;
10954 }
d008e5eb 10955 if (PL_lex_state == LEX_NORMAL) {
d008e5eb 10956 if (ckWARN(WARN_AMBIGUOUS) &&
780a5241
NC
10957 (keyword(dest, d - dest, 0)
10958 || get_cvn_flags(dest, d - dest, 0)))
d008e5eb 10959 {
c35e046a
AL
10960 if (funny == '#')
10961 funny = '@';
9014280d 10962 Perl_warner(aTHX_ packWARN(WARN_AMBIGUOUS),
d008e5eb
GS
10963 "Ambiguous use of %c{%s} resolved to %c%s",
10964 funny, dest, funny, dest);
10965 }
10966 }
79072805
LW
10967 }
10968 else {
10969 s = bracket; /* let the parser handle it */
93a17b20 10970 *dest = '\0';
79072805
LW
10971 }
10972 }
3280af22
NIS
10973 else if (PL_lex_state == LEX_INTERPNORMAL && !PL_lex_brackets && !intuit_more(s))
10974 PL_lex_state = LEX_INTERPEND;
378cc40b
LW
10975 return s;
10976}
10977
879d0c72
NC
10978static U32
10979S_pmflag(U32 pmfl, const char ch) {
10980 switch (ch) {
10981 CASE_STD_PMMOD_FLAGS_PARSE_SET(&pmfl);
10982 case GLOBAL_PAT_MOD: pmfl |= PMf_GLOBAL; break;
10983 case CONTINUE_PAT_MOD: pmfl |= PMf_CONTINUE; break;
10984 case ONCE_PAT_MOD: pmfl |= PMf_KEEP; break;
10985 case KEEPCOPY_PAT_MOD: pmfl |= PMf_KEEPCOPY; break;
10986 }
10987 return pmfl;
10988}
10989
cea2e8a9 10990void
2b36a5a0 10991Perl_pmflag(pTHX_ U32* pmfl, int ch)
a0d0e21e 10992{
7918f24d
NC
10993 PERL_ARGS_ASSERT_PMFLAG;
10994
879d0c72
NC
10995 Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED),
10996 "Perl_pmflag() is deprecated, and will be removed from the XS API");
10997
cde0cee5 10998 if (ch<256) {
879d0c72 10999 *pmfl = S_pmflag(*pmfl, (char)ch);
cde0cee5 11000 }
a0d0e21e 11001}
378cc40b 11002
76e3520e 11003STATIC char *
cea2e8a9 11004S_scan_pat(pTHX_ char *start, I32 type)
378cc40b 11005{
97aff369 11006 dVAR;
79072805 11007 PMOP *pm;
5db06880 11008 char *s = scan_str(start,!!PL_madskills,FALSE);
10edeb5d 11009 const char * const valid_flags =
a20207d7 11010 (const char *)((type == OP_QR) ? QR_PAT_MODS : M_PAT_MODS);
5db06880
NC
11011#ifdef PERL_MAD
11012 char *modstart;
11013#endif
11014
7918f24d 11015 PERL_ARGS_ASSERT_SCAN_PAT;
378cc40b 11016
25c09cbf 11017 if (!s) {
6136c704 11018 const char * const delimiter = skipspace(start);
10edeb5d
JH
11019 Perl_croak(aTHX_
11020 (const char *)
11021 (*delimiter == '?'
11022 ? "Search pattern not terminated or ternary operator parsed as search pattern"
11023 : "Search pattern not terminated" ));
25c09cbf 11024 }
bbce6d69 11025
8782bef2 11026 pm = (PMOP*)newPMOP(type, 0);
ad639bfb
NC
11027 if (PL_multi_open == '?') {
11028 /* This is the only point in the code that sets PMf_ONCE: */
79072805 11029 pm->op_pmflags |= PMf_ONCE;
ad639bfb
NC
11030
11031 /* Hence it's safe to do this bit of PMOP book-keeping here, which
11032 allows us to restrict the list needed by reset to just the ??
11033 matches. */
11034 assert(type != OP_TRANS);
11035 if (PL_curstash) {
daba3364 11036 MAGIC *mg = mg_find((const SV *)PL_curstash, PERL_MAGIC_symtab);
ad639bfb
NC
11037 U32 elements;
11038 if (!mg) {
daba3364 11039 mg = sv_magicext(MUTABLE_SV(PL_curstash), 0, PERL_MAGIC_symtab, 0, 0,
ad639bfb
NC
11040 0);
11041 }
11042 elements = mg->mg_len / sizeof(PMOP**);
11043 Renewc(mg->mg_ptr, elements + 1, PMOP*, char);
11044 ((PMOP**)mg->mg_ptr) [elements++] = pm;
11045 mg->mg_len = elements * sizeof(PMOP**);
11046 PmopSTASH_set(pm,PL_curstash);
11047 }
11048 }
5db06880
NC
11049#ifdef PERL_MAD
11050 modstart = s;
11051#endif
6136c704 11052 while (*s && strchr(valid_flags, *s))
879d0c72 11053 pm->op_pmflags = S_pmflag(pm->op_pmflags, *s++);
5db06880
NC
11054#ifdef PERL_MAD
11055 if (PL_madskills && modstart != s) {
11056 SV* tmptoken = newSVpvn(modstart, s - modstart);
11057 append_madprops(newMADPROP('m', MAD_SV, tmptoken, 0), (OP*)pm, 0);
11058 }
11059#endif
4ac733c9 11060 /* issue a warning if /c is specified,but /g is not */
a2a5de95 11061 if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL))
4ac733c9 11062 {
a2a5de95
NC
11063 Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP),
11064 "Use of /c modifier is meaningless without /g" );
4ac733c9
MJD
11065 }
11066
3280af22 11067 PL_lex_op = (OP*)pm;
6154021b 11068 pl_yylval.ival = OP_MATCH;
378cc40b
LW
11069 return s;
11070}
11071
76e3520e 11072STATIC char *
cea2e8a9 11073S_scan_subst(pTHX_ char *start)
79072805 11074{
27da23d5 11075 dVAR;
a0d0e21e 11076 register char *s;
79072805 11077 register PMOP *pm;
4fdae800 11078 I32 first_start;
79072805 11079 I32 es = 0;
5db06880
NC
11080#ifdef PERL_MAD
11081 char *modstart;
11082#endif
79072805 11083
7918f24d
NC
11084 PERL_ARGS_ASSERT_SCAN_SUBST;
11085
6154021b 11086 pl_yylval.ival = OP_NULL;
79072805 11087
5db06880 11088 s = scan_str(start,!!PL_madskills,FALSE);
79072805 11089
37fd879b 11090 if (!s)
cea2e8a9 11091 Perl_croak(aTHX_ "Substitution pattern not terminated");
79072805 11092
3280af22 11093 if (s[-1] == PL_multi_open)
79072805 11094 s--;
5db06880
NC
11095#ifdef PERL_MAD
11096 if (PL_madskills) {
cd81e915
NC
11097 CURMAD('q', PL_thisopen);
11098 CURMAD('_', PL_thiswhite);
11099 CURMAD('E', PL_thisstuff);
11100 CURMAD('Q', PL_thisclose);
11101 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
11102 }
11103#endif
79072805 11104
3280af22 11105 first_start = PL_multi_start;
5db06880 11106 s = scan_str(s,!!PL_madskills,FALSE);
79072805 11107 if (!s) {
37fd879b 11108 if (PL_lex_stuff) {
3280af22 11109 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 11110 PL_lex_stuff = NULL;
37fd879b 11111 }
cea2e8a9 11112 Perl_croak(aTHX_ "Substitution replacement not terminated");
a687059c 11113 }
3280af22 11114 PL_multi_start = first_start; /* so whole substitution is taken together */
2f3197b3 11115
79072805 11116 pm = (PMOP*)newPMOP(OP_SUBST, 0);
5db06880
NC
11117
11118#ifdef PERL_MAD
11119 if (PL_madskills) {
cd81e915
NC
11120 CURMAD('z', PL_thisopen);
11121 CURMAD('R', PL_thisstuff);
11122 CURMAD('Z', PL_thisclose);
5db06880
NC
11123 }
11124 modstart = s;
11125#endif
11126
48c036b1 11127 while (*s) {
a20207d7 11128 if (*s == EXEC_PAT_MOD) {
a687059c 11129 s++;
2f3197b3 11130 es++;
a687059c 11131 }
a20207d7 11132 else if (strchr(S_PAT_MODS, *s))
879d0c72 11133 pm->op_pmflags = S_pmflag(pm->op_pmflags, *s++);
48c036b1
GS
11134 else
11135 break;
378cc40b 11136 }
79072805 11137
5db06880
NC
11138#ifdef PERL_MAD
11139 if (PL_madskills) {
11140 if (modstart != s)
11141 curmad('m', newSVpvn(modstart, s - modstart));
cd81e915
NC
11142 append_madprops(PL_thismad, (OP*)pm, 0);
11143 PL_thismad = 0;
5db06880
NC
11144 }
11145#endif
a2a5de95
NC
11146 if ((pm->op_pmflags & PMf_CONTINUE)) {
11147 Perl_ck_warner(aTHX_ packWARN(WARN_REGEXP), "Use of /c modifier is meaningless in s///" );
4ac733c9
MJD
11148 }
11149
79072805 11150 if (es) {
6136c704
AL
11151 SV * const repl = newSVpvs("");
11152
0244c3a4
GS
11153 PL_sublex_info.super_bufptr = s;
11154 PL_sublex_info.super_bufend = PL_bufend;
11155 PL_multi_end = 0;
79072805 11156 pm->op_pmflags |= PMf_EVAL;
a5849ce5
NC
11157 while (es-- > 0) {
11158 if (es)
11159 sv_catpvs(repl, "eval ");
11160 else
11161 sv_catpvs(repl, "do ");
11162 }
6f43d98f 11163 sv_catpvs(repl, "{");
3280af22 11164 sv_catsv(repl, PL_lex_repl);
9badc361
RGS
11165 if (strchr(SvPVX(PL_lex_repl), '#'))
11166 sv_catpvs(repl, "\n");
11167 sv_catpvs(repl, "}");
25da4f38 11168 SvEVALED_on(repl);
3280af22
NIS
11169 SvREFCNT_dec(PL_lex_repl);
11170 PL_lex_repl = repl;
378cc40b 11171 }
79072805 11172
3280af22 11173 PL_lex_op = (OP*)pm;
6154021b 11174 pl_yylval.ival = OP_SUBST;
378cc40b
LW
11175 return s;
11176}
11177
76e3520e 11178STATIC char *
cea2e8a9 11179S_scan_trans(pTHX_ char *start)
378cc40b 11180{
97aff369 11181 dVAR;
a0d0e21e 11182 register char* s;
11343788 11183 OP *o;
79072805 11184 short *tbl;
b84c11c8
NC
11185 U8 squash;
11186 U8 del;
11187 U8 complement;
5db06880
NC
11188#ifdef PERL_MAD
11189 char *modstart;
11190#endif
79072805 11191
7918f24d
NC
11192 PERL_ARGS_ASSERT_SCAN_TRANS;
11193
6154021b 11194 pl_yylval.ival = OP_NULL;
79072805 11195
5db06880 11196 s = scan_str(start,!!PL_madskills,FALSE);
37fd879b 11197 if (!s)
cea2e8a9 11198 Perl_croak(aTHX_ "Transliteration pattern not terminated");
5db06880 11199
3280af22 11200 if (s[-1] == PL_multi_open)
2f3197b3 11201 s--;
5db06880
NC
11202#ifdef PERL_MAD
11203 if (PL_madskills) {
cd81e915
NC
11204 CURMAD('q', PL_thisopen);
11205 CURMAD('_', PL_thiswhite);
11206 CURMAD('E', PL_thisstuff);
11207 CURMAD('Q', PL_thisclose);
11208 PL_realtokenstart = s - SvPVX(PL_linestr);
5db06880
NC
11209 }
11210#endif
2f3197b3 11211
5db06880 11212 s = scan_str(s,!!PL_madskills,FALSE);
79072805 11213 if (!s) {
37fd879b 11214 if (PL_lex_stuff) {
3280af22 11215 SvREFCNT_dec(PL_lex_stuff);
a0714e2c 11216 PL_lex_stuff = NULL;
37fd879b 11217 }
cea2e8a9 11218 Perl_croak(aTHX_ "Transliteration replacement not terminated");
a687059c 11219 }
5db06880 11220 if (PL_madskills) {
cd81e915
NC
11221 CURMAD('z', PL_thisopen);
11222 CURMAD('R', PL_thisstuff);
11223 CURMAD('Z', PL_thisclose);
5db06880 11224 }
79072805 11225
a0ed51b3 11226 complement = del = squash = 0;
5db06880
NC
11227#ifdef PERL_MAD
11228 modstart = s;
11229#endif
7a1e2023
NC
11230 while (1) {
11231 switch (*s) {
11232 case 'c':
79072805 11233 complement = OPpTRANS_COMPLEMENT;
7a1e2023
NC
11234 break;
11235 case 'd':
a0ed51b3 11236 del = OPpTRANS_DELETE;
7a1e2023
NC
11237 break;
11238 case 's':
79072805 11239 squash = OPpTRANS_SQUASH;
7a1e2023
NC
11240 break;
11241 default:
11242 goto no_more;
11243 }
395c3793
LW
11244 s++;
11245 }
7a1e2023 11246 no_more:
8973db79 11247
aa1f7c5b 11248 tbl = (short *)PerlMemShared_calloc(complement&&!del?258:256, sizeof(short));
8973db79 11249 o = newPVOP(OP_TRANS, 0, (char*)tbl);
59f00321
RGS
11250 o->op_private &= ~OPpTRANS_ALL;
11251 o->op_private |= del|squash|complement|
7948272d
NIS
11252 (DO_UTF8(PL_lex_stuff)? OPpTRANS_FROM_UTF : 0)|
11253 (DO_UTF8(PL_lex_repl) ? OPpTRANS_TO_UTF : 0);
79072805 11254
3280af22 11255 PL_lex_op = o;
6154021b 11256 pl_yylval.ival = OP_TRANS;
5db06880
NC
11257
11258#ifdef PERL_MAD
11259 if (PL_madskills) {
11260 if (modstart != s)
11261 curmad('m', newSVpvn(modstart, s - modstart));
cd81e915
NC
11262 append_madprops(PL_thismad, o, 0);
11263 PL_thismad = 0;
5db06880
NC
11264 }
11265#endif
11266
79072805
LW
11267 return s;
11268}
11269
76e3520e 11270STATIC char *
cea2e8a9 11271S_scan_heredoc(pTHX_ register char *s)
79072805 11272{
97aff369 11273 dVAR;
79072805
LW
11274 SV *herewas;
11275 I32 op_type = OP_SCALAR;
11276 I32 len;
11277 SV *tmpstr;
11278 char term;
73d840c0 11279 const char *found_newline;
79072805 11280 register char *d;
fc36a67e 11281 register char *e;
4633a7c4 11282 char *peek;
f54cb97a 11283 const int outer = (PL_rsfp && !(PL_lex_inwhat == OP_SCALAR));
5db06880
NC
11284#ifdef PERL_MAD
11285 I32 stuffstart = s - SvPVX(PL_linestr);
11286 char *tstart;
11287
cd81e915 11288 PL_realtokenstart = -1;
5db06880 11289#endif
79072805 11290
7918f24d
NC
11291 PERL_ARGS_ASSERT_SCAN_HEREDOC;
11292
79072805 11293 s += 2;
3280af22
NIS
11294 d = PL_tokenbuf;
11295 e = PL_tokenbuf + sizeof PL_tokenbuf - 1;
fd2d0953 11296 if (!outer)
79072805 11297 *d++ = '\n';
c35e046a
AL
11298 peek = s;
11299 while (SPACE_OR_TAB(*peek))
11300 peek++;
3792a11b 11301 if (*peek == '`' || *peek == '\'' || *peek =='"') {
4633a7c4 11302 s = peek;
79072805 11303 term = *s++;
3280af22 11304 s = delimcpy(d, e, s, PL_bufend, term, &len);
fc36a67e 11305 d += len;
3280af22 11306 if (s < PL_bufend)
79072805 11307 s++;
79072805
LW
11308 }
11309 else {
11310 if (*s == '\\')
11311 s++, term = '\'';
11312 else
11313 term = '"';
7e2040f0 11314 if (!isALNUM_lazy_if(s,UTF))
8ab8f082 11315 deprecate("bare << to mean <<\"\"");
7e2040f0 11316 for (; isALNUM_lazy_if(s,UTF); s++) {
fc36a67e 11317 if (d < e)
11318 *d++ = *s;
11319 }
11320 }
3280af22 11321 if (d >= PL_tokenbuf + sizeof PL_tokenbuf - 1)
cea2e8a9 11322 Perl_croak(aTHX_ "Delimiter for here document is too long");
79072805
LW
11323 *d++ = '\n';
11324 *d = '\0';
3280af22 11325 len = d - PL_tokenbuf;
5db06880
NC
11326
11327#ifdef PERL_MAD
11328 if (PL_madskills) {
11329 tstart = PL_tokenbuf + !outer;
cd81e915 11330 PL_thisclose = newSVpvn(tstart, len - !outer);
5db06880 11331 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915 11332 PL_thisopen = newSVpvn(tstart, s - tstart);
5db06880
NC
11333 stuffstart = s - SvPVX(PL_linestr);
11334 }
11335#endif
6a27c188 11336#ifndef PERL_STRICT_CR
f63a84b2
LW
11337 d = strchr(s, '\r');
11338 if (d) {
b464bac0 11339 char * const olds = s;
f63a84b2 11340 s = d;
3280af22 11341 while (s < PL_bufend) {
f63a84b2
LW
11342 if (*s == '\r') {
11343 *d++ = '\n';
11344 if (*++s == '\n')
11345 s++;
11346 }
11347 else if (*s == '\n' && s[1] == '\r') { /* \015\013 on a mac? */
11348 *d++ = *s++;
11349 s++;
11350 }
11351 else
11352 *d++ = *s++;
11353 }
11354 *d = '\0';
3280af22 11355 PL_bufend = d;
95a20fc0 11356 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
f63a84b2
LW
11357 s = olds;
11358 }
11359#endif
5db06880
NC
11360#ifdef PERL_MAD
11361 found_newline = 0;
11362#endif
10edeb5d 11363 if ( outer || !(found_newline = (char*)memchr((void*)s, '\n', PL_bufend - s)) ) {
73d840c0
AL
11364 herewas = newSVpvn(s,PL_bufend-s);
11365 }
11366 else {
5db06880
NC
11367#ifdef PERL_MAD
11368 herewas = newSVpvn(s-1,found_newline-s+1);
11369#else
73d840c0
AL
11370 s--;
11371 herewas = newSVpvn(s,found_newline-s);
5db06880 11372#endif
73d840c0 11373 }
5db06880
NC
11374#ifdef PERL_MAD
11375 if (PL_madskills) {
11376 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11377 if (PL_thisstuff)
11378 sv_catpvn(PL_thisstuff, tstart, s - tstart);
5db06880 11379 else
cd81e915 11380 PL_thisstuff = newSVpvn(tstart, s - tstart);
5db06880
NC
11381 }
11382#endif
79072805 11383 s += SvCUR(herewas);
748a9306 11384
5db06880
NC
11385#ifdef PERL_MAD
11386 stuffstart = s - SvPVX(PL_linestr);
11387
11388 if (found_newline)
11389 s--;
11390#endif
11391
7d0a29fe
NC
11392 tmpstr = newSV_type(SVt_PVIV);
11393 SvGROW(tmpstr, 80);
748a9306 11394 if (term == '\'') {
79072805 11395 op_type = OP_CONST;
45977657 11396 SvIV_set(tmpstr, -1);
748a9306
LW
11397 }
11398 else if (term == '`') {
79072805 11399 op_type = OP_BACKTICK;
45977657 11400 SvIV_set(tmpstr, '\\');
748a9306 11401 }
79072805
LW
11402
11403 CLINE;
57843af0 11404 PL_multi_start = CopLINE(PL_curcop);
3280af22
NIS
11405 PL_multi_open = PL_multi_close = '<';
11406 term = *PL_tokenbuf;
0244c3a4 11407 if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
6136c704
AL
11408 char * const bufptr = PL_sublex_info.super_bufptr;
11409 char * const bufend = PL_sublex_info.super_bufend;
b464bac0 11410 char * const olds = s - SvCUR(herewas);
0244c3a4
GS
11411 s = strchr(bufptr, '\n');
11412 if (!s)
11413 s = bufend;
11414 d = s;
11415 while (s < bufend &&
11416 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
11417 if (*s++ == '\n')
57843af0 11418 CopLINE_inc(PL_curcop);
0244c3a4
GS
11419 }
11420 if (s >= bufend) {
eb160463 11421 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
0244c3a4
GS
11422 missingterm(PL_tokenbuf);
11423 }
11424 sv_setpvn(herewas,bufptr,d-bufptr+1);
11425 sv_setpvn(tmpstr,d+1,s-d);
11426 s += len - 1;
11427 sv_catpvn(herewas,s,bufend-s);
95a20fc0 11428 Copy(SvPVX_const(herewas),bufptr,SvCUR(herewas) + 1,char);
0244c3a4
GS
11429
11430 s = olds;
11431 goto retval;
11432 }
11433 else if (!outer) {
79072805 11434 d = s;
3280af22
NIS
11435 while (s < PL_bufend &&
11436 (*s != term || memNE(s,PL_tokenbuf,len)) ) {
79072805 11437 if (*s++ == '\n')
57843af0 11438 CopLINE_inc(PL_curcop);
79072805 11439 }
3280af22 11440 if (s >= PL_bufend) {
eb160463 11441 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22 11442 missingterm(PL_tokenbuf);
79072805
LW
11443 }
11444 sv_setpvn(tmpstr,d+1,s-d);
5db06880
NC
11445#ifdef PERL_MAD
11446 if (PL_madskills) {
cd81e915
NC
11447 if (PL_thisstuff)
11448 sv_catpvn(PL_thisstuff, d + 1, s - d);
5db06880 11449 else
cd81e915 11450 PL_thisstuff = newSVpvn(d + 1, s - d);
5db06880
NC
11451 stuffstart = s - SvPVX(PL_linestr);
11452 }
11453#endif
79072805 11454 s += len - 1;
57843af0 11455 CopLINE_inc(PL_curcop); /* the preceding stmt passes a newline */
49d8d3a1 11456
3280af22
NIS
11457 sv_catpvn(herewas,s,PL_bufend-s);
11458 sv_setsv(PL_linestr,herewas);
11459 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = s = PL_linestart = SvPVX(PL_linestr);
11460 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11461 PL_last_lop = PL_last_uni = NULL;
79072805
LW
11462 }
11463 else
76f68e9b 11464 sv_setpvs(tmpstr,""); /* avoid "uninitialized" warning */
3280af22 11465 while (s >= PL_bufend) { /* multiple line string? */
5db06880
NC
11466#ifdef PERL_MAD
11467 if (PL_madskills) {
11468 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11469 if (PL_thisstuff)
11470 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
5db06880 11471 else
cd81e915 11472 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
5db06880
NC
11473 }
11474#endif
fd2d0953 11475 if (!outer ||
5cc814fd
NC
11476 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart
11477 = filter_gets(PL_linestr, 0))) {
eb160463 11478 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
3280af22 11479 missingterm(PL_tokenbuf);
79072805 11480 }
5db06880
NC
11481#ifdef PERL_MAD
11482 stuffstart = s - SvPVX(PL_linestr);
11483#endif
57843af0 11484 CopLINE_inc(PL_curcop);
3280af22 11485 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 11486 PL_last_lop = PL_last_uni = NULL;
6a27c188 11487#ifndef PERL_STRICT_CR
3280af22 11488 if (PL_bufend - PL_linestart >= 2) {
a1529941
NIS
11489 if ((PL_bufend[-2] == '\r' && PL_bufend[-1] == '\n') ||
11490 (PL_bufend[-2] == '\n' && PL_bufend[-1] == '\r'))
c6f14548 11491 {
3280af22
NIS
11492 PL_bufend[-2] = '\n';
11493 PL_bufend--;
95a20fc0 11494 SvCUR_set(PL_linestr, PL_bufend - SvPVX_const(PL_linestr));
f63a84b2 11495 }
3280af22
NIS
11496 else if (PL_bufend[-1] == '\r')
11497 PL_bufend[-1] = '\n';
f63a84b2 11498 }
3280af22
NIS
11499 else if (PL_bufend - PL_linestart == 1 && PL_bufend[-1] == '\r')
11500 PL_bufend[-1] = '\n';
f63a84b2 11501#endif
65269a95 11502 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 11503 update_debugger_info(PL_linestr, NULL, 0);
3280af22 11504 if (*s == term && memEQ(s,PL_tokenbuf,len)) {
95a20fc0 11505 STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
1de9afcd 11506 *(SvPVX(PL_linestr) + off ) = ' ';
3280af22
NIS
11507 sv_catsv(PL_linestr,herewas);
11508 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
1de9afcd 11509 s = SvPVX(PL_linestr) + off; /* In case PV of PL_linestr moved. */
79072805
LW
11510 }
11511 else {
3280af22
NIS
11512 s = PL_bufend;
11513 sv_catsv(tmpstr,PL_linestr);
395c3793
LW
11514 }
11515 }
79072805 11516 s++;
0244c3a4 11517retval:
57843af0 11518 PL_multi_end = CopLINE(PL_curcop);
79072805 11519 if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) {
1da4ca5f 11520 SvPV_shrink_to_cur(tmpstr);
79072805 11521 }
8990e307 11522 SvREFCNT_dec(herewas);
2f31ce75 11523 if (!IN_BYTES) {
95a20fc0 11524 if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
2f31ce75
JH
11525 SvUTF8_on(tmpstr);
11526 else if (PL_encoding)
11527 sv_recode_to_utf8(tmpstr, PL_encoding);
11528 }
3280af22 11529 PL_lex_stuff = tmpstr;
6154021b 11530 pl_yylval.ival = op_type;
79072805
LW
11531 return s;
11532}
11533
02aa26ce
NT
11534/* scan_inputsymbol
11535 takes: current position in input buffer
11536 returns: new position in input buffer
6154021b 11537 side-effects: pl_yylval and lex_op are set.
02aa26ce
NT
11538
11539 This code handles:
11540
11541 <> read from ARGV
11542 <FH> read from filehandle
11543 <pkg::FH> read from package qualified filehandle
11544 <pkg'FH> read from package qualified filehandle
11545 <$fh> read from filehandle in $fh
11546 <*.h> filename glob
11547
11548*/
11549
76e3520e 11550STATIC char *
cea2e8a9 11551S_scan_inputsymbol(pTHX_ char *start)
79072805 11552{
97aff369 11553 dVAR;
02aa26ce 11554 register char *s = start; /* current position in buffer */
1b420867 11555 char *end;
79072805 11556 I32 len;
6136c704
AL
11557 char *d = PL_tokenbuf; /* start of temp holding space */
11558 const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */
11559
7918f24d
NC
11560 PERL_ARGS_ASSERT_SCAN_INPUTSYMBOL;
11561
1b420867
GS
11562 end = strchr(s, '\n');
11563 if (!end)
11564 end = PL_bufend;
11565 s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */
02aa26ce
NT
11566
11567 /* die if we didn't have space for the contents of the <>,
1b420867 11568 or if it didn't end, or if we see a newline
02aa26ce
NT
11569 */
11570
bb7a0f54 11571 if (len >= (I32)sizeof PL_tokenbuf)
cea2e8a9 11572 Perl_croak(aTHX_ "Excessively long <> operator");
1b420867 11573 if (s >= end)
cea2e8a9 11574 Perl_croak(aTHX_ "Unterminated <> operator");
02aa26ce 11575
fc36a67e 11576 s++;
02aa26ce
NT
11577
11578 /* check for <$fh>
11579 Remember, only scalar variables are interpreted as filehandles by
11580 this code. Anything more complex (e.g., <$fh{$num}>) will be
11581 treated as a glob() call.
11582 This code makes use of the fact that except for the $ at the front,
11583 a scalar variable and a filehandle look the same.
11584 */
4633a7c4 11585 if (*d == '$' && d[1]) d++;
02aa26ce
NT
11586
11587 /* allow <Pkg'VALUE> or <Pkg::VALUE> */
7e2040f0 11588 while (*d && (isALNUM_lazy_if(d,UTF) || *d == '\'' || *d == ':'))
79072805 11589 d++;
02aa26ce
NT
11590
11591 /* If we've tried to read what we allow filehandles to look like, and
11592 there's still text left, then it must be a glob() and not a getline.
11593 Use scan_str to pull out the stuff between the <> and treat it
11594 as nothing more than a string.
11595 */
11596
3280af22 11597 if (d - PL_tokenbuf != len) {
6154021b 11598 pl_yylval.ival = OP_GLOB;
5db06880 11599 s = scan_str(start,!!PL_madskills,FALSE);
79072805 11600 if (!s)
cea2e8a9 11601 Perl_croak(aTHX_ "Glob not terminated");
79072805
LW
11602 return s;
11603 }
395c3793 11604 else {
9b3023bc 11605 bool readline_overriden = FALSE;
6136c704 11606 GV *gv_readline;
9b3023bc 11607 GV **gvp;
02aa26ce 11608 /* we're in a filehandle read situation */
3280af22 11609 d = PL_tokenbuf;
02aa26ce
NT
11610
11611 /* turn <> into <ARGV> */
79072805 11612 if (!len)
689badd5 11613 Copy("ARGV",d,5,char);
02aa26ce 11614
9b3023bc 11615 /* Check whether readline() is overriden */
fafc274c 11616 gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
6136c704 11617 if ((gv_readline
ba979b31 11618 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
9b3023bc 11619 ||
017a3ce5 11620 ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
9e0d86f8 11621 && (gv_readline = *gvp) && isGV_with_GP(gv_readline)
ba979b31 11622 && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
9b3023bc
RGS
11623 readline_overriden = TRUE;
11624
02aa26ce
NT
11625 /* if <$fh>, create the ops to turn the variable into a
11626 filehandle
11627 */
79072805 11628 if (*d == '$') {
02aa26ce
NT
11629 /* try to find it in the pad for this block, otherwise find
11630 add symbol table ops
11631 */
f8f98e0a 11632 const PADOFFSET tmp = pad_findmy(d, len, 0);
bbd11bfc 11633 if (tmp != NOT_IN_PAD) {
00b1698f 11634 if (PAD_COMPNAME_FLAGS_isOUR(tmp)) {
6136c704
AL
11635 HV * const stash = PAD_COMPNAME_OURSTASH(tmp);
11636 HEK * const stashname = HvNAME_HEK(stash);
11637 SV * const sym = sv_2mortal(newSVhek(stashname));
396482e1 11638 sv_catpvs(sym, "::");
f558d5af
JH
11639 sv_catpv(sym, d+1);
11640 d = SvPVX(sym);
11641 goto intro_sym;
11642 }
11643 else {
6136c704 11644 OP * const o = newOP(OP_PADSV, 0);
f558d5af 11645 o->op_targ = tmp;
9b3023bc
RGS
11646 PL_lex_op = readline_overriden
11647 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11648 append_elem(OP_LIST, o,
11649 newCVREF(0, newGVOP(OP_GV,0,gv_readline))))
11650 : (OP*)newUNOP(OP_READLINE, 0, o);
f558d5af 11651 }
a0d0e21e
LW
11652 }
11653 else {
f558d5af
JH
11654 GV *gv;
11655 ++d;
11656intro_sym:
11657 gv = gv_fetchpv(d,
11658 (PL_in_eval
11659 ? (GV_ADDMULTI | GV_ADDINEVAL)
bea70d1e 11660 : GV_ADDMULTI),
f558d5af 11661 SVt_PV);
9b3023bc
RGS
11662 PL_lex_op = readline_overriden
11663 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11664 append_elem(OP_LIST,
11665 newUNOP(OP_RV2SV, 0, newGVOP(OP_GV, 0, gv)),
11666 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11667 : (OP*)newUNOP(OP_READLINE, 0,
11668 newUNOP(OP_RV2SV, 0,
11669 newGVOP(OP_GV, 0, gv)));
a0d0e21e 11670 }
7c6fadd6
RGS
11671 if (!readline_overriden)
11672 PL_lex_op->op_flags |= OPf_SPECIAL;
6154021b
RGS
11673 /* we created the ops in PL_lex_op, so make pl_yylval.ival a null op */
11674 pl_yylval.ival = OP_NULL;
79072805 11675 }
02aa26ce
NT
11676
11677 /* If it's none of the above, it must be a literal filehandle
11678 (<Foo::BAR> or <FOO>) so build a simple readline OP */
79072805 11679 else {
6136c704 11680 GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
9b3023bc
RGS
11681 PL_lex_op = readline_overriden
11682 ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
11683 append_elem(OP_LIST,
11684 newGVOP(OP_GV, 0, gv),
11685 newCVREF(0, newGVOP(OP_GV, 0, gv_readline))))
11686 : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv));
6154021b 11687 pl_yylval.ival = OP_NULL;
79072805
LW
11688 }
11689 }
02aa26ce 11690
79072805
LW
11691 return s;
11692}
11693
02aa26ce
NT
11694
11695/* scan_str
11696 takes: start position in buffer
09bef843
SB
11697 keep_quoted preserve \ on the embedded delimiter(s)
11698 keep_delims preserve the delimiters around the string
02aa26ce
NT
11699 returns: position to continue reading from buffer
11700 side-effects: multi_start, multi_close, lex_repl or lex_stuff, and
11701 updates the read buffer.
11702
11703 This subroutine pulls a string out of the input. It is called for:
11704 q single quotes q(literal text)
11705 ' single quotes 'literal text'
11706 qq double quotes qq(interpolate $here please)
11707 " double quotes "interpolate $here please"
11708 qx backticks qx(/bin/ls -l)
11709 ` backticks `/bin/ls -l`
11710 qw quote words @EXPORT_OK = qw( func() $spam )
11711 m// regexp match m/this/
11712 s/// regexp substitute s/this/that/
11713 tr/// string transliterate tr/this/that/
11714 y/// string transliterate y/this/that/
11715 ($*@) sub prototypes sub foo ($)
09bef843 11716 (stuff) sub attr parameters sub foo : attr(stuff)
02aa26ce
NT
11717 <> readline or globs <FOO>, <>, <$fh>, or <*.c>
11718
11719 In most of these cases (all but <>, patterns and transliterate)
11720 yylex() calls scan_str(). m// makes yylex() call scan_pat() which
11721 calls scan_str(). s/// makes yylex() call scan_subst() which calls
11722 scan_str(). tr/// and y/// make yylex() call scan_trans() which
11723 calls scan_str().
4e553d73 11724
02aa26ce
NT
11725 It skips whitespace before the string starts, and treats the first
11726 character as the delimiter. If the delimiter is one of ([{< then
11727 the corresponding "close" character )]}> is used as the closing
11728 delimiter. It allows quoting of delimiters, and if the string has
11729 balanced delimiters ([{<>}]) it allows nesting.
11730
37fd879b
HS
11731 On success, the SV with the resulting string is put into lex_stuff or,
11732 if that is already non-NULL, into lex_repl. The second case occurs only
11733 when parsing the RHS of the special constructs s/// and tr/// (y///).
11734 For convenience, the terminating delimiter character is stuffed into
11735 SvIVX of the SV.
02aa26ce
NT
11736*/
11737
76e3520e 11738STATIC char *
09bef843 11739S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
79072805 11740{
97aff369 11741 dVAR;
02aa26ce 11742 SV *sv; /* scalar value: string */
d3fcec1f 11743 const char *tmps; /* temp string, used for delimiter matching */
02aa26ce
NT
11744 register char *s = start; /* current position in the buffer */
11745 register char term; /* terminating character */
11746 register char *to; /* current position in the sv's data */
11747 I32 brackets = 1; /* bracket nesting level */
89491803 11748 bool has_utf8 = FALSE; /* is there any utf8 content? */
220e2d4e 11749 I32 termcode; /* terminating char. code */
89ebb4a3 11750 U8 termstr[UTF8_MAXBYTES]; /* terminating string */
220e2d4e 11751 STRLEN termlen; /* length of terminating string */
0331ef07 11752 int last_off = 0; /* last position for nesting bracket */
5db06880
NC
11753#ifdef PERL_MAD
11754 int stuffstart;
11755 char *tstart;
11756#endif
02aa26ce 11757
7918f24d
NC
11758 PERL_ARGS_ASSERT_SCAN_STR;
11759
02aa26ce 11760 /* skip space before the delimiter */
29595ff2
NC
11761 if (isSPACE(*s)) {
11762 s = PEEKSPACE(s);
11763 }
02aa26ce 11764
5db06880 11765#ifdef PERL_MAD
cd81e915
NC
11766 if (PL_realtokenstart >= 0) {
11767 stuffstart = PL_realtokenstart;
11768 PL_realtokenstart = -1;
5db06880
NC
11769 }
11770 else
11771 stuffstart = start - SvPVX(PL_linestr);
11772#endif
02aa26ce 11773 /* mark where we are, in case we need to report errors */
79072805 11774 CLINE;
02aa26ce
NT
11775
11776 /* after skipping whitespace, the next character is the terminator */
a0d0e21e 11777 term = *s;
220e2d4e
IH
11778 if (!UTF) {
11779 termcode = termstr[0] = term;
11780 termlen = 1;
11781 }
11782 else {
f3b9ce0f 11783 termcode = utf8_to_uvchr((U8*)s, &termlen);
220e2d4e
IH
11784 Copy(s, termstr, termlen, U8);
11785 if (!UTF8_IS_INVARIANT(term))
11786 has_utf8 = TRUE;
11787 }
b1c7b182 11788
02aa26ce 11789 /* mark where we are */
57843af0 11790 PL_multi_start = CopLINE(PL_curcop);
3280af22 11791 PL_multi_open = term;
02aa26ce
NT
11792
11793 /* find corresponding closing delimiter */
93a17b20 11794 if (term && (tmps = strchr("([{< )]}> )]}>",term)))
220e2d4e
IH
11795 termcode = termstr[0] = term = tmps[5];
11796
3280af22 11797 PL_multi_close = term;
79072805 11798
561b68a9
SH
11799 /* create a new SV to hold the contents. 79 is the SV's initial length.
11800 What a random number. */
7d0a29fe
NC
11801 sv = newSV_type(SVt_PVIV);
11802 SvGROW(sv, 80);
45977657 11803 SvIV_set(sv, termcode);
a0d0e21e 11804 (void)SvPOK_only(sv); /* validate pointer */
02aa26ce
NT
11805
11806 /* move past delimiter and try to read a complete string */
09bef843 11807 if (keep_delims)
220e2d4e
IH
11808 sv_catpvn(sv, s, termlen);
11809 s += termlen;
5db06880
NC
11810#ifdef PERL_MAD
11811 tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11812 if (!PL_thisopen && !keep_delims) {
11813 PL_thisopen = newSVpvn(tstart, s - tstart);
5db06880
NC
11814 stuffstart = s - SvPVX(PL_linestr);
11815 }
11816#endif
93a17b20 11817 for (;;) {
220e2d4e
IH
11818 if (PL_encoding && !UTF) {
11819 bool cont = TRUE;
11820
11821 while (cont) {
95a20fc0 11822 int offset = s - SvPVX_const(PL_linestr);
66a1b24b 11823 const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
f3b9ce0f 11824 &offset, (char*)termstr, termlen);
6136c704
AL
11825 const char * const ns = SvPVX_const(PL_linestr) + offset;
11826 char * const svlast = SvEND(sv) - 1;
220e2d4e
IH
11827
11828 for (; s < ns; s++) {
11829 if (*s == '\n' && !PL_rsfp)
11830 CopLINE_inc(PL_curcop);
11831 }
11832 if (!found)
11833 goto read_more_line;
11834 else {
11835 /* handle quoted delimiters */
52327caf 11836 if (SvCUR(sv) > 1 && *(svlast-1) == '\\') {
f54cb97a 11837 const char *t;
95a20fc0 11838 for (t = svlast-2; t >= SvPVX_const(sv) && *t == '\\';)
220e2d4e
IH
11839 t--;
11840 if ((svlast-1 - t) % 2) {
11841 if (!keep_quoted) {
11842 *(svlast-1) = term;
11843 *svlast = '\0';
11844 SvCUR_set(sv, SvCUR(sv) - 1);
11845 }
11846 continue;
11847 }
11848 }
11849 if (PL_multi_open == PL_multi_close) {
11850 cont = FALSE;
11851 }
11852 else {
f54cb97a
AL
11853 const char *t;
11854 char *w;
0331ef07 11855 for (t = w = SvPVX(sv)+last_off; t < svlast; w++, t++) {
220e2d4e
IH
11856 /* At here, all closes are "was quoted" one,
11857 so we don't check PL_multi_close. */
11858 if (*t == '\\') {
11859 if (!keep_quoted && *(t+1) == PL_multi_open)
11860 t++;
11861 else
11862 *w++ = *t++;
11863 }
11864 else if (*t == PL_multi_open)
11865 brackets++;
11866
11867 *w = *t;
11868 }
11869 if (w < t) {
11870 *w++ = term;
11871 *w = '\0';
95a20fc0 11872 SvCUR_set(sv, w - SvPVX_const(sv));
220e2d4e 11873 }
0331ef07 11874 last_off = w - SvPVX(sv);
220e2d4e
IH
11875 if (--brackets <= 0)
11876 cont = FALSE;
11877 }
11878 }
11879 }
11880 if (!keep_delims) {
11881 SvCUR_set(sv, SvCUR(sv) - 1);
11882 *SvEND(sv) = '\0';
11883 }
11884 break;
11885 }
11886
02aa26ce 11887 /* extend sv if need be */
3280af22 11888 SvGROW(sv, SvCUR(sv) + (PL_bufend - s) + 1);
02aa26ce 11889 /* set 'to' to the next character in the sv's string */
463ee0b2 11890 to = SvPVX(sv)+SvCUR(sv);
09bef843 11891
02aa26ce 11892 /* if open delimiter is the close delimiter read unbridle */
3280af22
NIS
11893 if (PL_multi_open == PL_multi_close) {
11894 for (; s < PL_bufend; s++,to++) {
02aa26ce 11895 /* embedded newlines increment the current line number */
3280af22 11896 if (*s == '\n' && !PL_rsfp)
57843af0 11897 CopLINE_inc(PL_curcop);
02aa26ce 11898 /* handle quoted delimiters */
3280af22 11899 if (*s == '\\' && s+1 < PL_bufend && term != '\\') {
09bef843 11900 if (!keep_quoted && s[1] == term)
a0d0e21e 11901 s++;
02aa26ce 11902 /* any other quotes are simply copied straight through */
a0d0e21e
LW
11903 else
11904 *to++ = *s++;
11905 }
02aa26ce
NT
11906 /* terminate when run out of buffer (the for() condition), or
11907 have found the terminator */
220e2d4e
IH
11908 else if (*s == term) {
11909 if (termlen == 1)
11910 break;
f3b9ce0f 11911 if (s+termlen <= PL_bufend && memEQ(s, (char*)termstr, termlen))
220e2d4e
IH
11912 break;
11913 }
63cd0674 11914 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
89491803 11915 has_utf8 = TRUE;
93a17b20
LW
11916 *to = *s;
11917 }
11918 }
02aa26ce
NT
11919
11920 /* if the terminator isn't the same as the start character (e.g.,
11921 matched brackets), we have to allow more in the quoting, and
11922 be prepared for nested brackets.
11923 */
93a17b20 11924 else {
02aa26ce 11925 /* read until we run out of string, or we find the terminator */
3280af22 11926 for (; s < PL_bufend; s++,to++) {
02aa26ce 11927 /* embedded newlines increment the line count */
3280af22 11928 if (*s == '\n' && !PL_rsfp)
57843af0 11929 CopLINE_inc(PL_curcop);
02aa26ce 11930 /* backslashes can escape the open or closing characters */
3280af22 11931 if (*s == '\\' && s+1 < PL_bufend) {
09bef843
SB
11932 if (!keep_quoted &&
11933 ((s[1] == PL_multi_open) || (s[1] == PL_multi_close)))
a0d0e21e
LW
11934 s++;
11935 else
11936 *to++ = *s++;
11937 }
02aa26ce 11938 /* allow nested opens and closes */
3280af22 11939 else if (*s == PL_multi_close && --brackets <= 0)
93a17b20 11940 break;
3280af22 11941 else if (*s == PL_multi_open)
93a17b20 11942 brackets++;
63cd0674 11943 else if (!has_utf8 && !UTF8_IS_INVARIANT((U8)*s) && UTF)
89491803 11944 has_utf8 = TRUE;
93a17b20
LW
11945 *to = *s;
11946 }
11947 }
02aa26ce 11948 /* terminate the copied string and update the sv's end-of-string */
93a17b20 11949 *to = '\0';
95a20fc0 11950 SvCUR_set(sv, to - SvPVX_const(sv));
93a17b20 11951
02aa26ce
NT
11952 /*
11953 * this next chunk reads more into the buffer if we're not done yet
11954 */
11955
b1c7b182
GS
11956 if (s < PL_bufend)
11957 break; /* handle case where we are done yet :-) */
79072805 11958
6a27c188 11959#ifndef PERL_STRICT_CR
95a20fc0 11960 if (to - SvPVX_const(sv) >= 2) {
c6f14548
GS
11961 if ((to[-2] == '\r' && to[-1] == '\n') ||
11962 (to[-2] == '\n' && to[-1] == '\r'))
11963 {
f63a84b2
LW
11964 to[-2] = '\n';
11965 to--;
95a20fc0 11966 SvCUR_set(sv, to - SvPVX_const(sv));
f63a84b2
LW
11967 }
11968 else if (to[-1] == '\r')
11969 to[-1] = '\n';
11970 }
95a20fc0 11971 else if (to - SvPVX_const(sv) == 1 && to[-1] == '\r')
f63a84b2
LW
11972 to[-1] = '\n';
11973#endif
11974
220e2d4e 11975 read_more_line:
02aa26ce
NT
11976 /* if we're out of file, or a read fails, bail and reset the current
11977 line marker so we can report where the unterminated string began
11978 */
5db06880
NC
11979#ifdef PERL_MAD
11980 if (PL_madskills) {
c35e046a 11981 char * const tstart = SvPVX(PL_linestr) + stuffstart;
cd81e915
NC
11982 if (PL_thisstuff)
11983 sv_catpvn(PL_thisstuff, tstart, PL_bufend - tstart);
5db06880 11984 else
cd81e915 11985 PL_thisstuff = newSVpvn(tstart, PL_bufend - tstart);
5db06880
NC
11986 }
11987#endif
3280af22 11988 if (!PL_rsfp ||
5cc814fd
NC
11989 !(PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart
11990 = filter_gets(PL_linestr, 0))) {
c07a80fd 11991 sv_free(sv);
eb160463 11992 CopLINE_set(PL_curcop, (line_t)PL_multi_start);
bd61b366 11993 return NULL;
79072805 11994 }
5db06880
NC
11995#ifdef PERL_MAD
11996 stuffstart = 0;
11997#endif
02aa26ce 11998 /* we read a line, so increment our line counter */
57843af0 11999 CopLINE_inc(PL_curcop);
a0ed51b3 12000
02aa26ce 12001 /* update debugger info */
65269a95 12002 if ((PERLDB_LINE || PERLDB_SAVESRC) && PL_curstash != PL_debstash)
5fa550fb 12003 update_debugger_info(PL_linestr, NULL, 0);
a0ed51b3 12004
3280af22
NIS
12005 /* having changed the buffer, we must update PL_bufend */
12006 PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
bd61b366 12007 PL_last_lop = PL_last_uni = NULL;
378cc40b 12008 }
4e553d73 12009
02aa26ce
NT
12010 /* at this point, we have successfully read the delimited string */
12011
220e2d4e 12012 if (!PL_encoding || UTF) {
5db06880
NC
12013#ifdef PERL_MAD
12014 if (PL_madskills) {
c35e046a 12015 char * const tstart = SvPVX(PL_linestr) + stuffstart;
29522234 12016 const int len = s - tstart;
cd81e915 12017 if (PL_thisstuff)
c35e046a 12018 sv_catpvn(PL_thisstuff, tstart, len);
5db06880 12019 else
c35e046a 12020 PL_thisstuff = newSVpvn(tstart, len);
cd81e915
NC
12021 if (!PL_thisclose && !keep_delims)
12022 PL_thisclose = newSVpvn(s,termlen);
5db06880
NC
12023 }
12024#endif
12025
220e2d4e
IH
12026 if (keep_delims)
12027 sv_catpvn(sv, s, termlen);
12028 s += termlen;
12029 }
5db06880
NC
12030#ifdef PERL_MAD
12031 else {
12032 if (PL_madskills) {
c35e046a
AL
12033 char * const tstart = SvPVX(PL_linestr) + stuffstart;
12034 const int len = s - tstart - termlen;
cd81e915 12035 if (PL_thisstuff)
c35e046a 12036 sv_catpvn(PL_thisstuff, tstart, len);
5db06880 12037 else
c35e046a 12038 PL_thisstuff = newSVpvn(tstart, len);
cd81e915
NC
12039 if (!PL_thisclose && !keep_delims)
12040 PL_thisclose = newSVpvn(s - termlen,termlen);
5db06880
NC
12041 }
12042 }
12043#endif
220e2d4e 12044 if (has_utf8 || PL_encoding)
b1c7b182 12045 SvUTF8_on(sv);
d0063567 12046
57843af0 12047 PL_multi_end = CopLINE(PL_curcop);
02aa26ce
NT
12048
12049 /* if we allocated too much space, give some back */
93a17b20
LW
12050 if (SvCUR(sv) + 5 < SvLEN(sv)) {
12051 SvLEN_set(sv, SvCUR(sv) + 1);
b7e9a5c2 12052 SvPV_renew(sv, SvLEN(sv));
79072805 12053 }
02aa26ce
NT
12054
12055 /* decide whether this is the first or second quoted string we've read
12056 for this op
12057 */
4e553d73 12058
3280af22
NIS
12059 if (PL_lex_stuff)
12060 PL_lex_repl = sv;
79072805 12061 else
3280af22 12062 PL_lex_stuff = sv;
378cc40b
LW
12063 return s;
12064}
12065
02aa26ce
NT
12066/*
12067 scan_num
12068 takes: pointer to position in buffer
12069 returns: pointer to new position in buffer
6154021b 12070 side-effects: builds ops for the constant in pl_yylval.op
02aa26ce
NT
12071
12072 Read a number in any of the formats that Perl accepts:
12073
7fd134d9
JH
12074 \d(_?\d)*(\.(\d(_?\d)*)?)?[Ee][\+\-]?(\d(_?\d)*) 12 12.34 12.
12075 \.\d(_?\d)*[Ee][\+\-]?(\d(_?\d)*) .34
24138b49
JH
12076 0b[01](_?[01])*
12077 0[0-7](_?[0-7])*
12078 0x[0-9A-Fa-f](_?[0-9A-Fa-f])*
02aa26ce 12079
3280af22 12080 Like most scan_ routines, it uses the PL_tokenbuf buffer to hold the
02aa26ce
NT
12081 thing it reads.
12082
12083 If it reads a number without a decimal point or an exponent, it will
12084 try converting the number to an integer and see if it can do so
12085 without loss of precision.
12086*/
4e553d73 12087
378cc40b 12088char *
bfed75c6 12089Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
378cc40b 12090{
97aff369 12091 dVAR;
bfed75c6 12092 register const char *s = start; /* current position in buffer */
02aa26ce
NT
12093 register char *d; /* destination in temp buffer */
12094 register char *e; /* end of temp buffer */
86554af2 12095 NV nv; /* number read, as a double */
a0714e2c 12096 SV *sv = NULL; /* place to put the converted number */
a86a20aa 12097 bool floatit; /* boolean: int or float? */
cbbf8932 12098 const char *lastub = NULL; /* position of last underbar */
bfed75c6 12099 static char const number_too_long[] = "Number too long";
378cc40b 12100
7918f24d
NC
12101 PERL_ARGS_ASSERT_SCAN_NUM;
12102
02aa26ce
NT
12103 /* We use the first character to decide what type of number this is */
12104
378cc40b 12105 switch (*s) {
79072805 12106 default:
cea2e8a9 12107 Perl_croak(aTHX_ "panic: scan_num");
4e553d73 12108
02aa26ce 12109 /* if it starts with a 0, it could be an octal number, a decimal in
a7cb1f99 12110 0.13 disguise, or a hexadecimal number, or a binary number. */
378cc40b
LW
12111 case '0':
12112 {
02aa26ce
NT
12113 /* variables:
12114 u holds the "number so far"
4f19785b
WSI
12115 shift the power of 2 of the base
12116 (hex == 4, octal == 3, binary == 1)
02aa26ce
NT
12117 overflowed was the number more than we can hold?
12118
12119 Shift is used when we add a digit. It also serves as an "are
4f19785b
WSI
12120 we in octal/hex/binary?" indicator to disallow hex characters
12121 when in octal mode.
02aa26ce 12122 */
9e24b6e2
JH
12123 NV n = 0.0;
12124 UV u = 0;
79072805 12125 I32 shift;
9e24b6e2 12126 bool overflowed = FALSE;
61f33854 12127 bool just_zero = TRUE; /* just plain 0 or binary number? */
27da23d5
JH
12128 static const NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
12129 static const char* const bases[5] =
12130 { "", "binary", "", "octal", "hexadecimal" };
12131 static const char* const Bases[5] =
12132 { "", "Binary", "", "Octal", "Hexadecimal" };
12133 static const char* const maxima[5] =
12134 { "",
12135 "0b11111111111111111111111111111111",
12136 "",
12137 "037777777777",
12138 "0xffffffff" };
bfed75c6 12139 const char *base, *Base, *max;
378cc40b 12140
02aa26ce 12141 /* check for hex */
378cc40b
LW
12142 if (s[1] == 'x') {
12143 shift = 4;
12144 s += 2;
61f33854 12145 just_zero = FALSE;
4f19785b
WSI
12146 } else if (s[1] == 'b') {
12147 shift = 1;
12148 s += 2;
61f33854 12149 just_zero = FALSE;
378cc40b 12150 }
02aa26ce 12151 /* check for a decimal in disguise */
b78218b7 12152 else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
378cc40b 12153 goto decimal;
02aa26ce 12154 /* so it must be octal */
928753ea 12155 else {
378cc40b 12156 shift = 3;
928753ea
JH
12157 s++;
12158 }
12159
12160 if (*s == '_') {
a2a5de95 12161 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
928753ea
JH
12162 "Misplaced _ in number");
12163 lastub = s++;
12164 }
9e24b6e2
JH
12165
12166 base = bases[shift];
12167 Base = Bases[shift];
12168 max = maxima[shift];
02aa26ce 12169
4f19785b 12170 /* read the rest of the number */
378cc40b 12171 for (;;) {
9e24b6e2 12172 /* x is used in the overflow test,
893fe2c2 12173 b is the digit we're adding on. */
9e24b6e2 12174 UV x, b;
55497cff 12175
378cc40b 12176 switch (*s) {
02aa26ce
NT
12177
12178 /* if we don't mention it, we're done */
378cc40b
LW
12179 default:
12180 goto out;
02aa26ce 12181
928753ea 12182 /* _ are ignored -- but warned about if consecutive */
de3bb511 12183 case '_':
a2a5de95
NC
12184 if (lastub && s == lastub + 1)
12185 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12186 "Misplaced _ in number");
928753ea 12187 lastub = s++;
de3bb511 12188 break;
02aa26ce
NT
12189
12190 /* 8 and 9 are not octal */
378cc40b 12191 case '8': case '9':
4f19785b 12192 if (shift == 3)
cea2e8a9 12193 yyerror(Perl_form(aTHX_ "Illegal octal digit '%c'", *s));
378cc40b 12194 /* FALL THROUGH */
02aa26ce
NT
12195
12196 /* octal digits */
4f19785b 12197 case '2': case '3': case '4':
378cc40b 12198 case '5': case '6': case '7':
4f19785b 12199 if (shift == 1)
cea2e8a9 12200 yyerror(Perl_form(aTHX_ "Illegal binary digit '%c'", *s));
4f19785b
WSI
12201 /* FALL THROUGH */
12202
12203 case '0': case '1':
02aa26ce 12204 b = *s++ & 15; /* ASCII digit -> value of digit */
55497cff 12205 goto digit;
02aa26ce
NT
12206
12207 /* hex digits */
378cc40b
LW
12208 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
12209 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
02aa26ce 12210 /* make sure they said 0x */
378cc40b
LW
12211 if (shift != 4)
12212 goto out;
55497cff 12213 b = (*s++ & 7) + 9;
02aa26ce
NT
12214
12215 /* Prepare to put the digit we have onto the end
12216 of the number so far. We check for overflows.
12217 */
12218
55497cff 12219 digit:
61f33854 12220 just_zero = FALSE;
9e24b6e2
JH
12221 if (!overflowed) {
12222 x = u << shift; /* make room for the digit */
12223
12224 if ((x >> shift) != u
12225 && !(PL_hints & HINT_NEW_BINARY)) {
9e24b6e2
JH
12226 overflowed = TRUE;
12227 n = (NV) u;
9b387841
NC
12228 Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
12229 "Integer overflow in %s number",
12230 base);
9e24b6e2
JH
12231 } else
12232 u = x | b; /* add the digit to the end */
12233 }
12234 if (overflowed) {
12235 n *= nvshift[shift];
12236 /* If an NV has not enough bits in its
12237 * mantissa to represent an UV this summing of
12238 * small low-order numbers is a waste of time
12239 * (because the NV cannot preserve the
12240 * low-order bits anyway): we could just
12241 * remember when did we overflow and in the
12242 * end just multiply n by the right
12243 * amount. */
12244 n += (NV) b;
55497cff 12245 }
378cc40b
LW
12246 break;
12247 }
12248 }
02aa26ce
NT
12249
12250 /* if we get here, we had success: make a scalar value from
12251 the number.
12252 */
378cc40b 12253 out:
928753ea
JH
12254
12255 /* final misplaced underbar check */
12256 if (s[-1] == '_') {
a2a5de95 12257 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
928753ea
JH
12258 }
12259
561b68a9 12260 sv = newSV(0);
9e24b6e2 12261 if (overflowed) {
a2a5de95
NC
12262 if (n > 4294967295.0)
12263 Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
12264 "%s number > %s non-portable",
12265 Base, max);
9e24b6e2
JH
12266 sv_setnv(sv, n);
12267 }
12268 else {
15041a67 12269#if UVSIZE > 4
a2a5de95
NC
12270 if (u > 0xffffffff)
12271 Perl_ck_warner(aTHX_ packWARN(WARN_PORTABLE),
12272 "%s number > %s non-portable",
12273 Base, max);
2cc4c2dc 12274#endif
9e24b6e2
JH
12275 sv_setuv(sv, u);
12276 }
61f33854 12277 if (just_zero && (PL_hints & HINT_NEW_INTEGER))
bfed75c6 12278 sv = new_constant(start, s - start, "integer",
eb0d8d16 12279 sv, NULL, NULL, 0);
61f33854 12280 else if (PL_hints & HINT_NEW_BINARY)
eb0d8d16 12281 sv = new_constant(start, s - start, "binary", sv, NULL, NULL, 0);
378cc40b
LW
12282 }
12283 break;
02aa26ce
NT
12284
12285 /*
12286 handle decimal numbers.
12287 we're also sent here when we read a 0 as the first digit
12288 */
378cc40b
LW
12289 case '1': case '2': case '3': case '4': case '5':
12290 case '6': case '7': case '8': case '9': case '.':
12291 decimal:
3280af22
NIS
12292 d = PL_tokenbuf;
12293 e = PL_tokenbuf + sizeof PL_tokenbuf - 6; /* room for various punctuation */
79072805 12294 floatit = FALSE;
02aa26ce
NT
12295
12296 /* read next group of digits and _ and copy into d */
de3bb511 12297 while (isDIGIT(*s) || *s == '_') {
4e553d73 12298 /* skip underscores, checking for misplaced ones
02aa26ce
NT
12299 if -w is on
12300 */
93a17b20 12301 if (*s == '_') {
a2a5de95
NC
12302 if (lastub && s == lastub + 1)
12303 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12304 "Misplaced _ in number");
928753ea 12305 lastub = s++;
93a17b20 12306 }
fc36a67e 12307 else {
02aa26ce 12308 /* check for end of fixed-length buffer */
fc36a67e 12309 if (d >= e)
cea2e8a9 12310 Perl_croak(aTHX_ number_too_long);
02aa26ce 12311 /* if we're ok, copy the character */
378cc40b 12312 *d++ = *s++;
fc36a67e 12313 }
378cc40b 12314 }
02aa26ce
NT
12315
12316 /* final misplaced underbar check */
928753ea 12317 if (lastub && s == lastub + 1) {
a2a5de95 12318 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
d008e5eb 12319 }
02aa26ce
NT
12320
12321 /* read a decimal portion if there is one. avoid
12322 3..5 being interpreted as the number 3. followed
12323 by .5
12324 */
2f3197b3 12325 if (*s == '.' && s[1] != '.') {
79072805 12326 floatit = TRUE;
378cc40b 12327 *d++ = *s++;
02aa26ce 12328
928753ea 12329 if (*s == '_') {
a2a5de95
NC
12330 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12331 "Misplaced _ in number");
928753ea
JH
12332 lastub = s;
12333 }
12334
12335 /* copy, ignoring underbars, until we run out of digits.
02aa26ce 12336 */
fc36a67e 12337 for (; isDIGIT(*s) || *s == '_'; s++) {
02aa26ce 12338 /* fixed length buffer check */
fc36a67e 12339 if (d >= e)
cea2e8a9 12340 Perl_croak(aTHX_ number_too_long);
928753ea 12341 if (*s == '_') {
a2a5de95
NC
12342 if (lastub && s == lastub + 1)
12343 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12344 "Misplaced _ in number");
928753ea
JH
12345 lastub = s;
12346 }
12347 else
fc36a67e 12348 *d++ = *s;
378cc40b 12349 }
928753ea
JH
12350 /* fractional part ending in underbar? */
12351 if (s[-1] == '_') {
a2a5de95
NC
12352 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12353 "Misplaced _ in number");
928753ea 12354 }
dd629d5b
GS
12355 if (*s == '.' && isDIGIT(s[1])) {
12356 /* oops, it's really a v-string, but without the "v" */
f4758303 12357 s = start;
dd629d5b
GS
12358 goto vstring;
12359 }
378cc40b 12360 }
02aa26ce
NT
12361
12362 /* read exponent part, if present */
3792a11b 12363 if ((*s == 'e' || *s == 'E') && strchr("+-0123456789_", s[1])) {
79072805
LW
12364 floatit = TRUE;
12365 s++;
02aa26ce
NT
12366
12367 /* regardless of whether user said 3E5 or 3e5, use lower 'e' */
79072805 12368 *d++ = 'e'; /* At least some Mach atof()s don't grok 'E' */
02aa26ce 12369
7fd134d9
JH
12370 /* stray preinitial _ */
12371 if (*s == '_') {
a2a5de95
NC
12372 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12373 "Misplaced _ in number");
7fd134d9
JH
12374 lastub = s++;
12375 }
12376
02aa26ce 12377 /* allow positive or negative exponent */
378cc40b
LW
12378 if (*s == '+' || *s == '-')
12379 *d++ = *s++;
02aa26ce 12380
7fd134d9
JH
12381 /* stray initial _ */
12382 if (*s == '_') {
a2a5de95
NC
12383 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12384 "Misplaced _ in number");
7fd134d9
JH
12385 lastub = s++;
12386 }
12387
7fd134d9
JH
12388 /* read digits of exponent */
12389 while (isDIGIT(*s) || *s == '_') {
12390 if (isDIGIT(*s)) {
12391 if (d >= e)
12392 Perl_croak(aTHX_ number_too_long);
b3b48e3e 12393 *d++ = *s++;
7fd134d9
JH
12394 }
12395 else {
041457d9 12396 if (((lastub && s == lastub + 1) ||
a2a5de95
NC
12397 (!isDIGIT(s[1]) && s[1] != '_')))
12398 Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
12399 "Misplaced _ in number");
b3b48e3e 12400 lastub = s++;
7fd134d9 12401 }
7fd134d9 12402 }
378cc40b 12403 }
02aa26ce 12404
02aa26ce
NT
12405
12406 /* make an sv from the string */
561b68a9 12407 sv = newSV(0);
097ee67d 12408
0b7fceb9 12409 /*
58bb9ec3
NC
12410 We try to do an integer conversion first if no characters
12411 indicating "float" have been found.
0b7fceb9
MU
12412 */
12413
12414 if (!floatit) {
58bb9ec3 12415 UV uv;
6136c704 12416 const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
58bb9ec3
NC
12417
12418 if (flags == IS_NUMBER_IN_UV) {
12419 if (uv <= IV_MAX)
86554af2 12420 sv_setiv(sv, uv); /* Prefer IVs over UVs. */
58bb9ec3 12421 else
c239479b 12422 sv_setuv(sv, uv);
58bb9ec3
NC
12423 } else if (flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) {
12424 if (uv <= (UV) IV_MIN)
12425 sv_setiv(sv, -(IV)uv);
12426 else
12427 floatit = TRUE;
12428 } else
12429 floatit = TRUE;
12430 }
0b7fceb9 12431 if (floatit) {
58bb9ec3
NC
12432 /* terminate the string */
12433 *d = '\0';
86554af2
JH
12434 nv = Atof(PL_tokenbuf);
12435 sv_setnv(sv, nv);
12436 }
86554af2 12437
eb0d8d16
NC
12438 if ( floatit
12439 ? (PL_hints & HINT_NEW_FLOAT) : (PL_hints & HINT_NEW_INTEGER) ) {
12440 const char *const key = floatit ? "float" : "integer";
12441 const STRLEN keylen = floatit ? 5 : 7;
12442 sv = S_new_constant(aTHX_ PL_tokenbuf, d - PL_tokenbuf,
12443 key, keylen, sv, NULL, NULL, 0);
12444 }
378cc40b 12445 break;
0b7fceb9 12446
e312add1 12447 /* if it starts with a v, it could be a v-string */
a7cb1f99 12448 case 'v':
dd629d5b 12449vstring:
561b68a9 12450 sv = newSV(5); /* preallocate storage space */
65b06e02 12451 s = scan_vstring(s, PL_bufend, sv);
a7cb1f99 12452 break;
79072805 12453 }
a687059c 12454
02aa26ce
NT
12455 /* make the op for the constant and return */
12456
a86a20aa 12457 if (sv)
b73d6f50 12458 lvalp->opval = newSVOP(OP_CONST, 0, sv);
a7cb1f99 12459 else
5f66b61c 12460 lvalp->opval = NULL;
a687059c 12461
73d840c0 12462 return (char *)s;
378cc40b
LW
12463}
12464
76e3520e 12465STATIC char *
cea2e8a9 12466S_scan_formline(pTHX_ register char *s)
378cc40b 12467{
97aff369 12468 dVAR;
79072805 12469 register char *eol;
378cc40b 12470 register char *t;
6136c704 12471 SV * const stuff = newSVpvs("");
79072805 12472 bool needargs = FALSE;
c5ee2135 12473 bool eofmt = FALSE;
5db06880
NC
12474#ifdef PERL_MAD
12475 char *tokenstart = s;
4f61fd4b
JC
12476 SV* savewhite = NULL;
12477
5db06880 12478 if (PL_madskills) {
cd81e915
NC
12479 savewhite = PL_thiswhite;
12480 PL_thiswhite = 0;
5db06880
NC
12481 }
12482#endif
378cc40b 12483
7918f24d
NC
12484 PERL_ARGS_ASSERT_SCAN_FORMLINE;
12485
79072805 12486 while (!needargs) {
a1b95068 12487 if (*s == '.') {
c35e046a 12488 t = s+1;
51882d45 12489#ifdef PERL_STRICT_CR
c35e046a
AL
12490 while (SPACE_OR_TAB(*t))
12491 t++;
51882d45 12492#else
c35e046a
AL
12493 while (SPACE_OR_TAB(*t) || *t == '\r')
12494 t++;
51882d45 12495#endif
c5ee2135
WL
12496 if (*t == '\n' || t == PL_bufend) {
12497 eofmt = TRUE;
79072805 12498 break;
c5ee2135 12499 }
79072805 12500 }
3280af22 12501 if (PL_in_eval && !PL_rsfp) {
07409e01 12502 eol = (char *) memchr(s,'\n',PL_bufend-s);
0f85fab0 12503 if (!eol++)
3280af22 12504 eol = PL_bufend;
0f85fab0
LW
12505 }
12506 else
3280af22 12507 eol = PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
79072805 12508 if (*s != '#') {
a0d0e21e
LW
12509 for (t = s; t < eol; t++) {
12510 if (*t == '~' && t[1] == '~' && SvCUR(stuff)) {
12511 needargs = FALSE;
12512 goto enough; /* ~~ must be first line in formline */
378cc40b 12513 }
a0d0e21e
LW
12514 if (*t == '@' || *t == '^')
12515 needargs = TRUE;
378cc40b 12516 }
7121b347
MG
12517 if (eol > s) {
12518 sv_catpvn(stuff, s, eol-s);
2dc4c65b 12519#ifndef PERL_STRICT_CR
7121b347
MG
12520 if (eol-s > 1 && eol[-2] == '\r' && eol[-1] == '\n') {
12521 char *end = SvPVX(stuff) + SvCUR(stuff);
12522 end[-2] = '\n';
12523 end[-1] = '\0';
b162af07 12524 SvCUR_set(stuff, SvCUR(stuff) - 1);
7121b347 12525 }
2dc4c65b 12526#endif
7121b347
MG
12527 }
12528 else
12529 break;
79072805 12530 }
95a20fc0 12531 s = (char*)eol;
3280af22 12532 if (PL_rsfp) {
5db06880
NC
12533#ifdef PERL_MAD
12534 if (PL_madskills) {
cd81e915
NC
12535 if (PL_thistoken)
12536 sv_catpvn(PL_thistoken, tokenstart, PL_bufend - tokenstart);
5db06880 12537 else
cd81e915 12538 PL_thistoken = newSVpvn(tokenstart, PL_bufend - tokenstart);
5db06880
NC
12539 }
12540#endif
5cc814fd 12541 s = filter_gets(PL_linestr, 0);
5db06880
NC
12542#ifdef PERL_MAD
12543 tokenstart = PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
12544#else
3280af22 12545 PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
5db06880 12546#endif
3280af22 12547 PL_bufend = PL_bufptr + SvCUR(PL_linestr);
bd61b366 12548 PL_last_lop = PL_last_uni = NULL;
79072805 12549 if (!s) {
3280af22 12550 s = PL_bufptr;
378cc40b
LW
12551 break;
12552 }
378cc40b 12553 }
463ee0b2 12554 incline(s);
79072805 12555 }
a0d0e21e
LW
12556 enough:
12557 if (SvCUR(stuff)) {
3280af22 12558 PL_expect = XTERM;
79072805 12559 if (needargs) {
3280af22 12560 PL_lex_state = LEX_NORMAL;
cd81e915 12561 start_force(PL_curforce);
9ded7720 12562 NEXTVAL_NEXTTOKE.ival = 0;
79072805
LW
12563 force_next(',');
12564 }
a0d0e21e 12565 else
3280af22 12566 PL_lex_state = LEX_FORMLINE;
1bd51a4c 12567 if (!IN_BYTES) {
95a20fc0 12568 if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
1bd51a4c
IH
12569 SvUTF8_on(stuff);
12570 else if (PL_encoding)
12571 sv_recode_to_utf8(stuff, PL_encoding);
12572 }
cd81e915 12573 start_force(PL_curforce);
9ded7720 12574 NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);
79072805 12575 force_next(THING);
cd81e915 12576 start_force(PL_curforce);
9ded7720 12577 NEXTVAL_NEXTTOKE.ival = OP_FORMLINE;
79072805 12578 force_next(LSTOP);
378cc40b 12579 }
79072805 12580 else {
8990e307 12581 SvREFCNT_dec(stuff);
c5ee2135
WL
12582 if (eofmt)
12583 PL_lex_formbrack = 0;
3280af22 12584 PL_bufptr = s;
79072805 12585 }
5db06880
NC
12586#ifdef PERL_MAD
12587 if (PL_madskills) {
cd81e915
NC
12588 if (PL_thistoken)
12589 sv_catpvn(PL_thistoken, tokenstart, s - tokenstart);
5db06880 12590 else
cd81e915
NC
12591 PL_thistoken = newSVpvn(tokenstart, s - tokenstart);
12592 PL_thiswhite = savewhite;
5db06880
NC
12593 }
12594#endif
79072805 12595 return s;
378cc40b 12596}
a687059c 12597
ba6d6ac9 12598I32
864dbfa3 12599Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
8990e307 12600{
97aff369 12601 dVAR;
a3b680e6 12602 const I32 oldsavestack_ix = PL_savestack_ix;
6136c704 12603 CV* const outsidecv = PL_compcv;
8990e307 12604
3280af22
NIS
12605 if (PL_compcv) {
12606 assert(SvTYPE(PL_compcv) == SVt_PVCV);
e9a444f0 12607 }
7766f137 12608 SAVEI32(PL_subline);
3280af22 12609 save_item(PL_subname);
3280af22 12610 SAVESPTR(PL_compcv);
3280af22 12611
ea726b52 12612 PL_compcv = MUTABLE_CV(newSV_type(is_format ? SVt_PVFM : SVt_PVCV));
3280af22
NIS
12613 CvFLAGS(PL_compcv) |= flags;
12614
57843af0 12615 PL_subline = CopLINE(PL_curcop);
dd2155a4 12616 CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
ea726b52 12617 CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv));
a3985cdc 12618 CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
748a9306 12619
8990e307
LW
12620 return oldsavestack_ix;
12621}
12622
084592ab
CN
12623#ifdef __SC__
12624#pragma segment Perl_yylex
12625#endif
af41e527
NC
12626static int
12627S_yywarn(pTHX_ const char *const s)
8990e307 12628{
97aff369 12629 dVAR;
7918f24d
NC
12630
12631 PERL_ARGS_ASSERT_YYWARN;
12632
faef0170 12633 PL_in_eval |= EVAL_WARNONLY;
748a9306 12634 yyerror(s);
faef0170 12635 PL_in_eval &= ~EVAL_WARNONLY;
748a9306 12636 return 0;
8990e307
LW
12637}
12638
12639int
15f169a1 12640Perl_yyerror(pTHX_ const char *const s)
463ee0b2 12641{
97aff369 12642 dVAR;
bfed75c6
AL
12643 const char *where = NULL;
12644 const char *context = NULL;
68dc0745 12645 int contlen = -1;
46fc3d4c 12646 SV *msg;
5912531f 12647 int yychar = PL_parser->yychar;
463ee0b2 12648
7918f24d
NC
12649 PERL_ARGS_ASSERT_YYERROR;
12650
3280af22 12651 if (!yychar || (yychar == ';' && !PL_rsfp))
54310121 12652 where = "at EOF";
8bcfe651
TM
12653 else if (PL_oldoldbufptr && PL_bufptr > PL_oldoldbufptr &&
12654 PL_bufptr - PL_oldoldbufptr < 200 && PL_oldoldbufptr != PL_oldbufptr &&
12655 PL_oldbufptr != PL_bufptr) {
f355267c
JH
12656 /*
12657 Only for NetWare:
12658 The code below is removed for NetWare because it abends/crashes on NetWare
12659 when the script has error such as not having the closing quotes like:
12660 if ($var eq "value)
12661 Checking of white spaces is anyway done in NetWare code.
12662 */
12663#ifndef NETWARE
3280af22
NIS
12664 while (isSPACE(*PL_oldoldbufptr))
12665 PL_oldoldbufptr++;
f355267c 12666#endif
3280af22
NIS
12667 context = PL_oldoldbufptr;
12668 contlen = PL_bufptr - PL_oldoldbufptr;
463ee0b2 12669 }
8bcfe651
TM
12670 else if (PL_oldbufptr && PL_bufptr > PL_oldbufptr &&
12671 PL_bufptr - PL_oldbufptr < 200 && PL_oldbufptr != PL_bufptr) {
f355267c
JH
12672 /*
12673 Only for NetWare:
12674 The code below is removed for NetWare because it abends/crashes on NetWare
12675 when the script has error such as not having the closing quotes like:
12676 if ($var eq "value)
12677 Checking of white spaces is anyway done in NetWare code.
12678 */
12679#ifndef NETWARE
3280af22
NIS
12680 while (isSPACE(*PL_oldbufptr))
12681 PL_oldbufptr++;
f355267c 12682#endif
3280af22
NIS
12683 context = PL_oldbufptr;
12684 contlen = PL_bufptr - PL_oldbufptr;
463ee0b2
LW
12685 }
12686 else if (yychar > 255)
68dc0745 12687 where = "next token ???";
12fbd33b 12688 else if (yychar == -2) { /* YYEMPTY */
3280af22
NIS
12689 if (PL_lex_state == LEX_NORMAL ||
12690 (PL_lex_state == LEX_KNOWNEXT && PL_lex_defer == LEX_NORMAL))
68dc0745 12691 where = "at end of line";
3280af22 12692 else if (PL_lex_inpat)
68dc0745 12693 where = "within pattern";
463ee0b2 12694 else
68dc0745 12695 where = "within string";
463ee0b2 12696 }
46fc3d4c 12697 else {
84bafc02 12698 SV * const where_sv = newSVpvs_flags("next char ", SVs_TEMP);
46fc3d4c 12699 if (yychar < 32)
cea2e8a9 12700 Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
5e7aa789 12701 else if (isPRINT_LC(yychar)) {
88c9ea1e 12702 const char string = yychar;
5e7aa789
NC
12703 sv_catpvn(where_sv, &string, 1);
12704 }
463ee0b2 12705 else
cea2e8a9 12706 Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255);
95a20fc0 12707 where = SvPVX_const(where_sv);
463ee0b2 12708 }
46fc3d4c 12709 msg = sv_2mortal(newSVpv(s, 0));
ed094faf 12710 Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ",
248c2a4d 12711 OutCopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
68dc0745 12712 if (context)
cea2e8a9 12713 Perl_sv_catpvf(aTHX_ msg, "near \"%.*s\"\n", contlen, context);
463ee0b2 12714 else
cea2e8a9 12715 Perl_sv_catpvf(aTHX_ msg, "%s\n", where);
57843af0 12716 if (PL_multi_start < PL_multi_end && (U32)(CopLINE(PL_curcop) - PL_multi_end) <= 1) {
cf2093f6 12717 Perl_sv_catpvf(aTHX_ msg,
57def98f 12718 " (Might be a runaway multi-line %c%c string starting on line %"IVdf")\n",
cf2093f6 12719 (int)PL_multi_open,(int)PL_multi_close,(IV)PL_multi_start);
3280af22 12720 PL_multi_end = 0;
a0d0e21e 12721 }
500960a6 12722 if (PL_in_eval & EVAL_WARNONLY) {
9b387841 12723 Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
500960a6 12724 }
463ee0b2 12725 else
5a844595 12726 qerror(msg);
c7d6bfb2
GS
12727 if (PL_error_count >= 10) {
12728 if (PL_in_eval && SvCUR(ERRSV))
d2560b70 12729 Perl_croak(aTHX_ "%"SVf"%s has too many errors.\n",
be2597df 12730 SVfARG(ERRSV), OutCopFILE(PL_curcop));
c7d6bfb2
GS
12731 else
12732 Perl_croak(aTHX_ "%s has too many errors.\n",
248c2a4d 12733 OutCopFILE(PL_curcop));
c7d6bfb2 12734 }
3280af22 12735 PL_in_my = 0;
5c284bb0 12736 PL_in_my_stash = NULL;
463ee0b2
LW
12737 return 0;
12738}
084592ab
CN
12739#ifdef __SC__
12740#pragma segment Main
12741#endif
4e35701f 12742
b250498f 12743STATIC char*
3ae08724 12744S_swallow_bom(pTHX_ U8 *s)
01ec43d0 12745{
97aff369 12746 dVAR;
f54cb97a 12747 const STRLEN slen = SvCUR(PL_linestr);
7918f24d
NC
12748
12749 PERL_ARGS_ASSERT_SWALLOW_BOM;
12750
7aa207d6 12751 switch (s[0]) {
4e553d73
NIS
12752 case 0xFF:
12753 if (s[1] == 0xFE) {
7aa207d6 12754 /* UTF-16 little-endian? (or UTF32-LE?) */
3ae08724 12755 if (s[2] == 0 && s[3] == 0) /* UTF-32 little-endian */
7aa207d6 12756 Perl_croak(aTHX_ "Unsupported script encoding UTF32-LE");
01ec43d0 12757#ifndef PERL_NO_UTF16_FILTER
7aa207d6 12758 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF16-LE script encoding (BOM)\n");
3ae08724 12759 s += 2;
dea0fc0b 12760 if (PL_bufend > (char*)s) {
81a923f4 12761 s = add_utf16_textfilter(s, TRUE);
dea0fc0b 12762 }
b250498f 12763#else
7aa207d6 12764 Perl_croak(aTHX_ "Unsupported script encoding UTF16-LE");
b250498f 12765#endif
01ec43d0
GS
12766 }
12767 break;
78ae23f5 12768 case 0xFE:
7aa207d6 12769 if (s[1] == 0xFF) { /* UTF-16 big-endian? */
01ec43d0 12770#ifndef PERL_NO_UTF16_FILTER
7aa207d6 12771 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (BOM)\n");
dea0fc0b
JH
12772 s += 2;
12773 if (PL_bufend > (char *)s) {
81a923f4 12774 s = add_utf16_textfilter(s, FALSE);
dea0fc0b 12775 }
b250498f 12776#else
7aa207d6 12777 Perl_croak(aTHX_ "Unsupported script encoding UTF16-BE");
b250498f 12778#endif
01ec43d0
GS
12779 }
12780 break;
3ae08724
GS
12781 case 0xEF:
12782 if (slen > 2 && s[1] == 0xBB && s[2] == 0xBF) {
7aa207d6 12783 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
01ec43d0
GS
12784 s += 3; /* UTF-8 */
12785 }
12786 break;
12787 case 0:
7aa207d6
JH
12788 if (slen > 3) {
12789 if (s[1] == 0) {
12790 if (s[2] == 0xFE && s[3] == 0xFF) {
12791 /* UTF-32 big-endian */
12792 Perl_croak(aTHX_ "Unsupported script encoding UTF32-BE");
12793 }
12794 }
12795 else if (s[2] == 0 && s[3] != 0) {
12796 /* Leading bytes
12797 * 00 xx 00 xx
12798 * are a good indicator of UTF-16BE. */
12799 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16BE script encoding (no BOM)\n");
81a923f4 12800 s = add_utf16_textfilter(s, FALSE);
7aa207d6 12801 }
01ec43d0 12802 }
e294cc5d
JH
12803#ifdef EBCDIC
12804 case 0xDD:
12805 if (slen > 3 && s[1] == 0x73 && s[2] == 0x66 && s[3] == 0x73) {
12806 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-8 script encoding (BOM)\n");
12807 s += 4; /* UTF-8 */
12808 }
12809 break;
12810#endif
12811
7aa207d6
JH
12812 default:
12813 if (slen > 3 && s[1] == 0 && s[2] != 0 && s[3] == 0) {
12814 /* Leading bytes
12815 * xx 00 xx 00
12816 * are a good indicator of UTF-16LE. */
12817 if (DEBUG_p_TEST || DEBUG_T_TEST) PerlIO_printf(Perl_debug_log, "UTF-16LE script encoding (no BOM)\n");
81a923f4 12818 s = add_utf16_textfilter(s, TRUE);
7aa207d6 12819 }
01ec43d0 12820 }
b8f84bb2 12821 return (char*)s;
b250498f 12822}
4755096e 12823
6e3aabd6
GS
12824
12825#ifndef PERL_NO_UTF16_FILTER
12826static I32
a28af015 12827S_utf16_textfilter(pTHX_ int idx, SV *sv, int maxlen)
6e3aabd6 12828{
97aff369 12829 dVAR;
f3040f2c 12830 SV *const filter = FILTER_DATA(idx);
2a773401
NC
12831 /* We re-use this each time round, throwing the contents away before we
12832 return. */
2a773401 12833 SV *const utf16_buffer = MUTABLE_SV(IoTOP_GV(filter));
f3040f2c 12834 SV *const utf8_buffer = filter;
c28d6105 12835 IV status = IoPAGE(filter);
eda4663d 12836 const bool reverse = (bool) IoLINES(filter);
d2d1d4de 12837 I32 retval;
c8b0cbae
NC
12838
12839 /* As we're automatically added, at the lowest level, and hence only called
12840 from this file, we can be sure that we're not called in block mode. Hence
12841 don't bother writing code to deal with block mode. */
12842 if (maxlen) {
12843 Perl_croak(aTHX_ "panic: utf16_textfilter called in block mode (for %d characters)", maxlen);
12844 }
c28d6105
NC
12845 if (status < 0) {
12846 Perl_croak(aTHX_ "panic: utf16_textfilter called after error (status=%"IVdf")", status);
12847 }
1de9afcd 12848 DEBUG_P(PerlIO_printf(Perl_debug_log,
c28d6105 12849 "utf16_textfilter(%p,%ce): idx=%d maxlen=%d status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n",
a28af015 12850 FPTR2DPTR(void *, S_utf16_textfilter),
c28d6105
NC
12851 reverse ? 'l' : 'b', idx, maxlen, status,
12852 (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer)));
12853
12854 while (1) {
12855 STRLEN chars;
12856 STRLEN have;
dea0fc0b 12857 I32 newlen;
2a773401 12858 U8 *end;
c28d6105
NC
12859 /* First, look in our buffer of existing UTF-8 data: */
12860 char *nl = (char *)memchr(SvPVX(utf8_buffer), '\n', SvCUR(utf8_buffer));
12861
12862 if (nl) {
12863 ++nl;
12864 } else if (status == 0) {
12865 /* EOF */
12866 IoPAGE(filter) = 0;
12867 nl = SvEND(utf8_buffer);
12868 }
12869 if (nl) {
d2d1d4de
NC
12870 STRLEN got = nl - SvPVX(utf8_buffer);
12871 /* Did we have anything to append? */
12872 retval = got != 0;
12873 sv_catpvn(sv, SvPVX(utf8_buffer), got);
c28d6105
NC
12874 /* Everything else in this code works just fine if SVp_POK isn't
12875 set. This, however, needs it, and we need it to work, else
12876 we loop infinitely because the buffer is never consumed. */
12877 sv_chop(utf8_buffer, nl);
12878 break;
12879 }
ba77e4cc 12880
c28d6105
NC
12881 /* OK, not a complete line there, so need to read some more UTF-16.
12882 Read an extra octect if the buffer currently has an odd number. */
ba77e4cc
NC
12883 while (1) {
12884 if (status <= 0)
12885 break;
12886 if (SvCUR(utf16_buffer) >= 2) {
12887 /* Location of the high octet of the last complete code point.
12888 Gosh, UTF-16 is a pain. All the benefits of variable length,
12889 *coupled* with all the benefits of partial reads and
12890 endianness. */
12891 const U8 *const last_hi = (U8*)SvPVX(utf16_buffer)
12892 + ((SvCUR(utf16_buffer) & ~1) - (reverse ? 1 : 2));
12893
12894 if (*last_hi < 0xd8 || *last_hi > 0xdb) {
12895 break;
12896 }
12897
12898 /* We have the first half of a surrogate. Read more. */
12899 DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter partial surrogate detected at %p\n", last_hi));
12900 }
c28d6105 12901
c28d6105
NC
12902 status = FILTER_READ(idx + 1, utf16_buffer,
12903 160 + (SvCUR(utf16_buffer) & 1));
12904 DEBUG_P(PerlIO_printf(Perl_debug_log, "utf16_textfilter status=%"IVdf" SvCUR(sv)=%"UVuf"\n", status, (UV)SvCUR(utf16_buffer)));
ba77e4cc 12905 DEBUG_P({ sv_dump(utf16_buffer); sv_dump(utf8_buffer);});
c28d6105
NC
12906 if (status < 0) {
12907 /* Error */
12908 IoPAGE(filter) = status;
12909 return status;
12910 }
12911 }
12912
12913 chars = SvCUR(utf16_buffer) >> 1;
12914 have = SvCUR(utf8_buffer);
12915 SvGROW(utf8_buffer, have + chars * 3 + 1);
2a773401 12916
aa6dbd60 12917 if (reverse) {
c28d6105
NC
12918 end = utf16_to_utf8_reversed((U8*)SvPVX(utf16_buffer),
12919 (U8*)SvPVX_const(utf8_buffer) + have,
12920 chars * 2, &newlen);
aa6dbd60 12921 } else {
2a773401 12922 end = utf16_to_utf8((U8*)SvPVX(utf16_buffer),
c28d6105
NC
12923 (U8*)SvPVX_const(utf8_buffer) + have,
12924 chars * 2, &newlen);
2a773401 12925 }
c28d6105 12926 SvCUR_set(utf8_buffer, have + newlen);
2a773401 12927 *end = '\0';
c28d6105 12928
e07286ed
NC
12929 /* No need to keep this SV "well-formed" with a '\0' after the end, as
12930 it's private to us, and utf16_to_utf8{,reversed} take a
12931 (pointer,length) pair, rather than a NUL-terminated string. */
12932 if(SvCUR(utf16_buffer) & 1) {
12933 *SvPVX(utf16_buffer) = SvEND(utf16_buffer)[-1];
12934 SvCUR_set(utf16_buffer, 1);
12935 } else {
12936 SvCUR_set(utf16_buffer, 0);
12937 }
2a773401 12938 }
c28d6105
NC
12939 DEBUG_P(PerlIO_printf(Perl_debug_log,
12940 "utf16_textfilter: returns, status=%"IVdf" utf16=%"UVuf" utf8=%"UVuf"\n",
12941 status,
12942 (UV)SvCUR(utf16_buffer), (UV)SvCUR(utf8_buffer)));
12943 DEBUG_P({ sv_dump(utf8_buffer); sv_dump(sv);});
d2d1d4de 12944 return retval;
6e3aabd6 12945}
81a923f4
NC
12946
12947static U8 *
12948S_add_utf16_textfilter(pTHX_ U8 *const s, bool reversed)
12949{
2a773401 12950 SV *filter = filter_add(S_utf16_textfilter, NULL);
81a923f4 12951
c28d6105 12952 IoTOP_GV(filter) = MUTABLE_GV(newSVpvn((char *)s, PL_bufend - (char*)s));
f3040f2c 12953 sv_setpvs(filter, "");
2a773401 12954 IoLINES(filter) = reversed;
c28d6105
NC
12955 IoPAGE(filter) = 1; /* Not EOF */
12956
12957 /* Sadly, we have to return a valid pointer, come what may, so we have to
12958 ignore any error return from this. */
12959 SvCUR_set(PL_linestr, 0);
12960 if (FILTER_READ(0, PL_linestr, 0)) {
12961 SvUTF8_on(PL_linestr);
81a923f4 12962 } else {
c28d6105 12963 SvUTF8_on(PL_linestr);
81a923f4 12964 }
c28d6105 12965 PL_bufend = SvEND(PL_linestr);
81a923f4
NC
12966 return (U8*)SvPVX(PL_linestr);
12967}
6e3aabd6 12968#endif
9f4817db 12969
f333445c
JP
12970/*
12971Returns a pointer to the next character after the parsed
12972vstring, as well as updating the passed in sv.
12973
12974Function must be called like
12975
561b68a9 12976 sv = newSV(5);
65b06e02 12977 s = scan_vstring(s,e,sv);
f333445c 12978
65b06e02 12979where s and e are the start and end of the string.
f333445c
JP
12980The sv should already be large enough to store the vstring
12981passed in, for performance reasons.
12982
12983*/
12984
12985char *
15f169a1 12986Perl_scan_vstring(pTHX_ const char *s, const char *const e, SV *sv)
f333445c 12987{
97aff369 12988 dVAR;
bfed75c6
AL
12989 const char *pos = s;
12990 const char *start = s;
7918f24d
NC
12991
12992 PERL_ARGS_ASSERT_SCAN_VSTRING;
12993
f333445c 12994 if (*pos == 'v') pos++; /* get past 'v' */
65b06e02 12995 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
3e884cbf 12996 pos++;
f333445c
JP
12997 if ( *pos != '.') {
12998 /* this may not be a v-string if followed by => */
bfed75c6 12999 const char *next = pos;
65b06e02 13000 while (next < e && isSPACE(*next))
8fc7bb1c 13001 ++next;
65b06e02 13002 if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
f333445c
JP
13003 /* return string not v-string */
13004 sv_setpvn(sv,(char *)s,pos-s);
73d840c0 13005 return (char *)pos;
f333445c
JP
13006 }
13007 }
13008
13009 if (!isALPHA(*pos)) {
89ebb4a3 13010 U8 tmpbuf[UTF8_MAXBYTES+1];
f333445c 13011
d4c19fe8
AL
13012 if (*s == 'v')
13013 s++; /* get past 'v' */
f333445c 13014
76f68e9b 13015 sv_setpvs(sv, "");
f333445c
JP
13016
13017 for (;;) {
d4c19fe8 13018 /* this is atoi() that tolerates underscores */
0bd48802
AL
13019 U8 *tmpend;
13020 UV rev = 0;
d4c19fe8
AL
13021 const char *end = pos;
13022 UV mult = 1;
13023 while (--end >= s) {
13024 if (*end != '_') {
13025 const UV orev = rev;
f333445c
JP
13026 rev += (*end - '0') * mult;
13027 mult *= 10;
9b387841
NC
13028 if (orev > rev)
13029 Perl_ck_warner_d(aTHX_ packWARN(WARN_OVERFLOW),
13030 "Integer overflow in decimal number");
f333445c
JP
13031 }
13032 }
13033#ifdef EBCDIC
13034 if (rev > 0x7FFFFFFF)
13035 Perl_croak(aTHX_ "In EBCDIC the v-string components cannot exceed 2147483647");
13036#endif
13037 /* Append native character for the rev point */
13038 tmpend = uvchr_to_utf8(tmpbuf, rev);
13039 sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
13040 if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
13041 SvUTF8_on(sv);
65b06e02 13042 if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
f333445c
JP
13043 s = ++pos;
13044 else {
13045 s = pos;
13046 break;
13047 }
65b06e02 13048 while (pos < e && (isDIGIT(*pos) || *pos == '_'))
f333445c
JP
13049 pos++;
13050 }
13051 SvPOK_on(sv);
13052 sv_magic(sv,NULL,PERL_MAGIC_vstring,(const char*)start, pos-start);
13053 SvRMAGICAL_on(sv);
13054 }
73d840c0 13055 return (char *)s;
f333445c
JP
13056}
13057
88e1f1a2
JV
13058int
13059Perl_keyword_plugin_standard(pTHX_
13060 char *keyword_ptr, STRLEN keyword_len, OP **op_ptr)
13061{
13062 PERL_ARGS_ASSERT_KEYWORD_PLUGIN_STANDARD;
13063 PERL_UNUSED_CONTEXT;
13064 PERL_UNUSED_ARG(keyword_ptr);
13065 PERL_UNUSED_ARG(keyword_len);
13066 PERL_UNUSED_ARG(op_ptr);
13067 return KEYWORD_PLUGIN_DECLINE;
13068}
13069
1da4ca5f
NC
13070/*
13071 * Local variables:
13072 * c-indentation-style: bsd
13073 * c-basic-offset: 4
13074 * indent-tabs-mode: t
13075 * End:
13076 *
37442d52
RGS
13077 * ex: set ts=8 sts=4 sw=4 noet:
13078 */